From t_ciorba at yahoo.com Sun Nov 1 03:23:15 2015 From: t_ciorba at yahoo.com (t_ciorba at yahoo.com) Date: Sun, 1 Nov 2015 10:23:15 +0200 Subject: installer user interface glitch ? Message-ID: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> hi, i am not sure what is wrong, but after launching the installer for windows XPsp3 python-3.5.0.exe i couldnt see what i have to select, it was a white board and the only button on it was "cancel". here is a screen of it: when i click on random points of this empty board, i get random stuff, like sending me to "optional features" (where i can finally see what i can choose from), either the installer starts installing it. -- Sent via EmailTray, my personal email concierge. Get yours at http://www.emailtray.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 3yn21.JPG Type: image/jpeg Size: 35447 bytes Desc: not available URL: From rosuav at gmail.com Sun Nov 1 04:43:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Nov 2015 20:43:14 +1100 Subject: Python 2 vs Python 3 for teaching Message-ID: I'm proud to say that a Python tutoring company has just converted its course over from teaching Python 2.7 to teaching 3.x. For the naysayers out there, it actually wasn't much of a transition; putting parentheses around all print calls, plus changing the way virtual environments get created, pretty much covered it. The difference between well-written 2.7 code and well-written 3.4 code is really not huge. Interestingly, the bytes/unicode distinction wasn't much of an issue. Under 2.7, a lot of functions return Unicode strings, and their reprs show a u prefix, which disappears under Py3. In both cases, a Unicode string returned from a library will compare equal to a simple double-quoted string: >>> import json >>> json.loads('["Hello", "World"]') [u'Hello', u'World'] >>> _[0] == "Hello" True The bulk of the changes were actually just changing displayed output to match a change to some object's repr (eg "" becomes "", and "set([1])" becomes "{1}"), or the exact text of an exception (the TypeError from evaluating None[0] looks different, but it's still a TypeError). Who out there is currently teaching/tutoring/training using Python 2? Push to the common subset (parenthesized single string prints, never assuming int/int yields int, etc), with a view to migration - it's easier than you might think! (This isn't meant to be an ad for a specific company, so much as a general recommendation to push to Py3, but they deserve a bit of a shout-out anyway. The company is Thinkful, www.thinkful.com.) ChrisA From schweiger.gerald at gmail.com Sun Nov 1 05:04:49 2015 From: schweiger.gerald at gmail.com (gers antifx) Date: Sun, 1 Nov 2015 02:04:49 -0800 (PST) Subject: LU decomposition Message-ID: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> Hey, I have to write a LU-decomposition. My Code worked so far but (I want to become better:) ) I want to ask you, if I could write this LU-decomposition in a better way? def LU(x): L = np.eye((x.shape[0])) n = x.shape[0] for ii in range(n-1): for ll in range(1+ii,n): factor = float(x[ll,ii])/x[ii,ii] L[ll,ii] = factor for kk in range(0+ii,n): x[ll,kk] = x[ll,kk] - faktor*x[ii,kk] LU = np.dot(L,x) Thanks From kwpolska at gmail.com Sun Nov 1 05:06:36 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 1 Nov 2015 11:06:36 +0100 Subject: installer user interface glitch ? In-Reply-To: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> Message-ID: On 1 November 2015 at 09:23, t_ciorba--- via Python-list wrote: > > hi, > i am not sure what is wrong, but after launching the installer for windows XPsp3 python-3.5.0.exe i couldnt see what i have to select, it was a white board and the only button on it was "cancel". here is a screen of it: Windows XP is not supported. Please upgrade to a modern version of Windows, or switch to Linux. (you could also use 3.4.3, but Windows XP is insecure, and more apps will follow suit.) -- Chris Warrick PGP: 5EAAEA16 From rosuav at gmail.com Sun Nov 1 05:08:47 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Nov 2015 21:08:47 +1100 Subject: installer user interface glitch ? In-Reply-To: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> Message-ID: On Sun, Nov 1, 2015 at 7:23 PM, t_ciorba--- via Python-list wrote: > > i am not sure what is wrong, but after launching the installer for windows XPsp3 python-3.5.0.exe i couldnt see what i have to select, it was a white board and the only button on it was "cancel". > Yep. The installer isn't very polite at the moment, but when 3.5.1 gets released, it'll be a little clearer in telling you what's going on - namely, that Python 3.5 does not support Windows XP. You can get a newer version of Windows (7, 8, 10), or an older version of Python (3.4), and it should be fine. Windows XP has now been around for twelve years. It's had its support run out as many times as Voyager has left the solar system, and if you really MUST keep using it, one of the costs is going to be that you also have to use older versions of some software - including Python. This is going to be increasingly the case. I recommend either switching to a Unix-based OS (Linux, Mac OS, *BSD, etc) and using Wine or virtualization to run critical Windows programs, or upgrading to a newer version of Windows. ChrisA From __peter__ at web.de Sun Nov 1 05:13:51 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Nov 2015 11:13:51 +0100 Subject: Puzzled References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> Message-ID: Robinson, Wendy wrote: > Hi there, > I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic > programs successfully. > This morning I rebooted my computer and can't get a single one to work. > The interpreter seems to be fine and the environment variables look > correct. But every py file I try to run at the >>> prompt gives me a > NameError. > > I tried running the Repair installation, but that did not help. > > Any suggestions? If you want to run a python script you have to invoke it on the commandline, not inside the interactive interpreter, i. e. if you have a script myscript.py containing the line print("Hello world!") Wrong: C:\> python3 >>> myscript.py Traceback (most recent call last): File "", line 1, in NameError: name 'myscript' is not defined Here python looks for a variable "myscript" which of course isn't defined. (If it were the next step would be to look for an attribute "py" and you'd probably get an AttributeError) Right: C:\> python3 myscript.py Hello world! Here python runs the script and exits. If you have a function defined in a module that you want to use from the interactive interpreter you have to import the module. Assuming mymodule.py contains the function def say_hello(): print("Hello world!") C:\> python3 >>> import mymodule >>> mymodule.say_hello() Hello world! From rosuav at gmail.com Sun Nov 1 05:18:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Nov 2015 21:18:37 +1100 Subject: LU decomposition In-Reply-To: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> References: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> Message-ID: On Sun, Nov 1, 2015 at 9:04 PM, gers antifx wrote: > I have to write a LU-decomposition. My Code worked so far but (I want to become better:) ) I want to ask you, if I could write this LU-decomposition in a better way? > > def LU(x): > L = np.eye((x.shape[0])) > n = x.shape[0] > for ii in range(n-1): > for ll in range(1+ii,n): > factor = float(x[ll,ii])/x[ii,ii] > L[ll,ii] = factor > for kk in range(0+ii,n): > x[ll,kk] = x[ll,kk] - faktor*x[ii,kk] > LU = np.dot(L,x) For a start, I would recommend being careful with your variable names. You have 'factor' all except one, where you have 'faktor' - transcription error, or nearly-identical global and local names? And all your other names are fairly opaque; can they be better named? I'm particularly looking at this line: x[ll,kk] = x[ll,kk] - faktor*x[ii,kk] It is *extremely not obvious* that the first two are using 'll' and the last one is using 'ii'. (Though I would write this as "x[ll,kk] -= faktor*x[ii,kk]", which at least cuts down the duplication, so it's less glitchy to have one out of three that's different.) I was going to ask if you had some reason for not inverting the factor and simply using "x[ll,kk] *= factor", till I read it again and saw the difference. I'm seeing here a lot of iteration over ranges, then subscripting with that. Is it possible to iterate over the numpy array itself instead? That's generally a more Pythonic way to do things. Assigning to the local name LU at the end of the function seems odd. Did you intend to return the dot-product? Beyond that, I'd need a better comprehension of the mathematics behind this, to evaluate what it's doing. So I'll let the actual experts dive in :) ChrisA From nulla.epistola at web.de Sun Nov 1 05:19:47 2015 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sun, 1 Nov 2015 11:19:47 +0100 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> Message-ID: <5635E743.9010607@web.de> Am 30.10.2015 um 17:20 schrieb Robinson, Wendy: > Hi there, > > I installed Python 3.5.0 64-bit for Windows yesterday and tried some > basic programs successfully. > > This morning I rebooted my computer and can?t get a single one to work. > The interpreter seems to be fine and the environment variables look > correct. But every py file I try to run at the >>> prompt gives me a > NameError. > Did you try the exact same things yesterday and this morning? The >>> prompt isn't made for running py files, but for directly entering statements and executing them. Running py files from a windows command prompt (probably after changing into the right directory) should work. Importing py files at the >>> prompt and using their content should work (again, if Python can find them). So, what exactly did you do yesterday and what exactly did you do today? HTH Sibylle From nulla.epistola at web.de Sun Nov 1 05:19:47 2015 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sun, 1 Nov 2015 11:19:47 +0100 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> Message-ID: <5635E743.9010607@web.de> Am 30.10.2015 um 17:20 schrieb Robinson, Wendy: > Hi there, > > I installed Python 3.5.0 64-bit for Windows yesterday and tried some > basic programs successfully. > > This morning I rebooted my computer and can?t get a single one to work. > The interpreter seems to be fine and the environment variables look > correct. But every py file I try to run at the >>> prompt gives me a > NameError. > Did you try the exact same things yesterday and this morning? The >>> prompt isn't made for running py files, but for directly entering statements and executing them. Running py files from a windows command prompt (probably after changing into the right directory) should work. Importing py files at the >>> prompt and using their content should work (again, if Python can find them). So, what exactly did you do yesterday and what exactly did you do today? HTH Sibylle From lac at openend.se Sun Nov 1 05:20:34 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 11:20:34 +0100 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> Message-ID: <201511011020.tA1AKYAM004182@fido.openend.se> In a message of Fri, 30 Oct 2015 09:20:23 -0700, "Robinson, Wendy" writes: >Hi there, >I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic programs successfully. >This morning I rebooted my computer and can't get a single one to work. The interpreter seems to be fine and the environment variables look correct. But every py file I try to run at the >>> prompt gives me a NameError. > >I tried running the Repair installation, but that did not help. > >Any suggestions? > >Thank you > >Wendy Robinson >Audit Analyst >(916) 566-4994 phone Paste in the Full traceback you get from the console. Also check and see that the console is actually running the 3.5 you installed, and not some other python, like 2.7 you might have lying around. Laura From lac at openend.se Sun Nov 1 05:24:55 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 11:24:55 +0100 Subject: installer user interface glitch ? In-Reply-To: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> Message-ID: <201511011024.tA1AOt1a004552@fido.openend.se> In a message of Sun, 01 Nov 2015 10:23:15 +0200, t_ciorba--- via Python-list wr ites: >hi, >i am not sure what is wrong, but after launching the installer for windows XPsp3 python-3.5.0.exe i couldnt see what i have to select, it was a white board and the only button on it was "cancel". here is a screen of it: > > >when i click on random points of this empty board, i get random stuff, like sending me to "optional features" (where i can finally see what i can choose from), either the installer starts installing it. >-- >Sent via EmailTray, my personal email concierge. >Get yours at http://www.emailtray.com What version of Windows are you running? If you are on Windows XP, alas, it is not supported and you will need to get a newer OS. If you do not know what version you are running, this may help http://ramblings.timgolden.me.uk/2015/10/08/what-windows-version-am-i-running/ Laura From lac at openend.se Sun Nov 1 05:27:25 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 11:27:25 +0100 Subject: installer user interface glitch ? In-Reply-To: <201511011024.tA1AOt1a004552@fido.openend.se> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <201511011024.tA1AOt1a004552@fido.openend.se> Message-ID: <201511011027.tA1ARPPM004866@fido.openend.se> In a message of Sun, 01 Nov 2015 11:24:55 +0100, Laura Creighton writes: >In a message of Sun, 01 Nov 2015 10:23:15 +0200, t_ciorba--- via Python-list wr >ites: >>hi, >>i am not sure what is wrong, but after launching the installer for windows XPsp3 python-3.5.0.exe i couldnt see what i have to select, it was a white board and the only button on it was "cancel". here is a screen of it: >> >> >>when i click on random points of this empty board, i get random stuff, like sending me to "optional features" (where i can finally see what i can choose from), either the installer starts installing it. >>-- >>Sent via EmailTray, my personal email concierge. >>Get yours at http://www.emailtray.com > >What version of Windows are you running? > >If you are on Windows XP, alas, it is not supported and you will need to >get a newer OS. > >If you do not know what version you are running, this may help >http://ramblings.timgolden.me.uk/2015/10/08/what-windows-version-am-i-running/ > >Laura Ooops, you did say XP, so I just cannot read this morning. Sorry about that. (goes to get more caffeine) Laura From __peter__ at web.de Sun Nov 1 06:55:50 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Nov 2015 12:55:50 +0100 Subject: LU decomposition References: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> Message-ID: gers antifx wrote: > I have to write a LU-decomposition. My Code worked so far but (I want to > become better:) ) I want to ask you, if I could write this > LU-decomposition in a better way? > > def LU(x): > L = np.eye((x.shape[0])) > n = x.shape[0] > for ii in range(n-1): > for ll in range(1+ii,n): > factor = float(x[ll,ii])/x[ii,ii] > L[ll,ii] = factor > for kk in range(0+ii,n): > x[ll,kk] = x[ll,kk] - faktor*x[ii,kk] > LU = np.dot(L,x) You want to become better? A good way to find the problems Chris pointed out quickly is to write unit tests similar to import unittest ... from mymodule import LU class LUTest(unittest.TestCase): def test_LU(self): matrix = ... expected_result = ... self.assertEqual(LU(matrix), expected_result) if __name__ == "__main__": unittest.main() There's no point making stylistic changes or tweaks to improve performance on code that doesn't work and doesn't have a well-defined interface yet, but as a rule of thumb for efficient number-crunching you should try to replace for loops with numpy's array operations if at all possible. Google found me http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.linalg.lu.html but it's hard to learn from that code as the real meat is a few levels down and implemented in C. From vindhyachal.takniki at gmail.com Sun Nov 1 09:05:58 2015 From: vindhyachal.takniki at gmail.com (Vindhyachal Takniki) Date: Sun, 1 Nov 2015 06:05:58 -0800 (PST) Subject: Multithreading python,two tkinter windows Message-ID: <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com> I have made a python code & using multithreading in it. this is very basic code, not using queues & other stuff. 1. Task is to create two independent Tkinter windows 2. Code has four files: main.py:creates individual thread analog.py: generate random values every 1 sec & 10 sec screen.py: Tkinter file, screen keeps on updating every 1 sec scree2.py: Tkinter file, screen keeps on updating every 10 sec 3. My code never run on gives anything. However if in main.py, I disable, one of either screen thread, another screen works fine. i.e they don't work together main.py [code]import thread import time import analog import screen import screen2 thread.start_new_thread(analog.get_analog_1 , ("Thread-1",)) thread.start_new_thread(analog.get_analog_2 , ("Thread-2",)) thread.start_new_thread(screen.display , ("Thread-3",)) thread.start_new_thread(screen2.display , ("Thread-4",)) while 1: pass [/code] analog.py [code]import time from random import randint current_time_1 = time.time(); current_time_2 = time.time(); read_ok_1 = 0 read_ok_2 = 0 analog_1 = 0 analog_2 = 0 #get reading at every 1 second def get_analog_1(thread_name): global read_ok_1, current_time_1,analog_1 while True: if((time.time() - current_time_1) > 1): if(0 == read_ok_1): current_time_1 = time.time(); read_ok_1 = 1; analog_1 = randint(0,100) #get reading on update def read_update_analog_1(): global read_ok_1,analog_1 data1 = 0 val1 = 0 if(1 == read_ok_1): read_ok_1 = 0; data1 = 1; val1 = analog_1 return data1,val1 #get reading at every 10 second def get_analog_2(thread_name): global read_ok_2, current_time_2,analog_2 while True: if((time.time() - current_time_2) > 10): if(0 == read_ok_2): current_time_2 = time.time(); read_ok_2 = 1; analog_2 = randint(0,100) #get reading on update def read_update_analog_2(): global read_ok_2,analog_2 data2 = 0 val2 = 0 if(1 == read_ok_2): read_ok_2 = 0; data2 = 1; val2 = analog_2 return data2,val2 [/code] screen.py [code] from Tkinter import * import analog import thread import time class App(): def __init__(self, master): self.master = master frame = Frame(master) frame.pack() label = Label(frame , text = "Analog" , font = ("Helvetica",32)) label.grid(row = 0) self.reading_label = Label(frame, text = '0.0' , font = ("Helvetica",70)) self.reading_label.grid(row = 1) self.update_reading() def update_reading(self): data1,val1 = analog.read_update_analog_1() if(1 == data1): reading_str = "{:.1f}".format(val1) self.reading_label.configure(text = reading_str) self.master.after(100 , self.update_reading) def display(threadName): root = Tk() root.wm_title("Ammeter") app = App(root) root.geometry("480x320") root.mainloop() [/code] screen2.py [code]from Tkinter import * import analog import thread import time class App(): def __init__(self, master): self.master = master frame = Frame(master) frame.pack() label = Label(frame , text = "Analog" , font = ("Helvetica",32)) label.grid(row = 0) self.reading_label = Label(frame, text = '0.0' , font = ("Helvetica",70)) self.reading_label.grid(row = 1) self.update_reading() def update_reading(self): data1,val1 = analog.read_update_analog_2() if(1 == data1): reading_str = "{:.1f}".format(val1) self.reading_label.configure(text = reading_str) self.master.after(1000 , self.update_reading) def display(threadName): root = Tk() root.wm_title("Voltmeter") app = App(root) root.geometry("480x320") root.mainloop() [/code] From paul.hermeneutic at gmail.com Sun Nov 1 09:11:03 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sun, 1 Nov 2015 07:11:03 -0700 Subject: Python 2 vs Python 3 for teaching In-Reply-To: References: Message-ID: On Nov 1, 2015 2:45 AM, "Chris Angelico" wrote: > > I'm proud to say that a Python tutoring company has just converted its > course over from teaching Python 2.7 to teaching 3.x. For the > naysayers out there, it actually wasn't much of a transition; This would make an excellent opportunity to develop a curriculum to teach students how to maintain a 2.x and 3.x code base using 2to3. 2.x is not going away as fast as some would like. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Sun Nov 1 09:26:52 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 15:26:52 +0100 Subject: Multithreading python,two tkinter windows In-Reply-To: <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com> References: <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com> Message-ID: <201511011426.tA1EQqfW022464@fido.openend.se> In a message of Sun, 01 Nov 2015 06:05:58 -0800, Vindhyachal Takniki writes: >I have made a python code & using multithreading in it. this is very basic code, not using queues & other stuff. This is your problem. The code that uses queues is more basic. For tkinter you cannot use threads like you do. You must have one controlling thread, and several worker threads. The best way to do this is using a queue. http://code.activestate.com/recipes/82965-threads-tkinter-and-asynchronous-io/ (written by a freind of mine, wandering around in the next room) outlines how to set this up for all your tkinter tasks. Laura From steve at pearwood.info Sun Nov 1 09:27:23 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 02 Nov 2015 01:27:23 +1100 Subject: UNABLE TO GET IDLE TO RUN References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> Message-ID: <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> On Sun, 1 Nov 2015 12:45 pm, Michiel Overtoom wrote: > >> On 31 Oct 2015, at 06:59, Terry Reedy wrote: >> This is a different issue than IDLE avoiding clashes. I opened >> https://bugs.python.org/issue25522 > > Terry, thanks for recording this into the issue tracker. > > I'd go even a step further. I think IDLE should not only warn, but > completely prevent saving a file which shadows a stdlib module, which will > effectively render Python unusable. Really? [steve at ando ~]$ touch collections.py [steve at ando ~]$ python -c "import math; print math.sin(1.25)" 0.948984619356 Looks like Python is still usable to me. > I remember from a few weeks back, a > teacher with the same problem posted this on the mailinglist. Eventually > she had a technician coming in to reinstall Windows, just to fix this > problem ;-) What an overkill... If that is true, that's really sad. Were we really unable to tell this teacher to delete the shadowing file? Or was there more to the problem than that? -- Steven From rosuav at gmail.com Sun Nov 1 09:27:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 01:27:24 +1100 Subject: Python 2 vs Python 3 for teaching In-Reply-To: References: Message-ID: On Mon, Nov 2, 2015 at 1:11 AM, wrote: > On Nov 1, 2015 2:45 AM, "Chris Angelico" wrote: >> >> I'm proud to say that a Python tutoring company has just converted its >> course over from teaching Python 2.7 to teaching 3.x. For the >> naysayers out there, it actually wasn't much of a transition; > > This would make an excellent opportunity to develop a curriculum to teach > students how to maintain a 2.x and 3.x code base using 2to3. > > 2.x is not going away as fast as some would like. I'd rather not use 2to3 there. If you want to maintain a library that can be used from 2.x and 3.x, it's much better to aim for the compatible middle - u prefixes on all Unicode strings, b prefixes on all byte strings, stick to ASCII where possible, etc, etc. Much easier than writing code for one branch and then converting to the other. We do have a few mentions in the course of "here's how Python 2 is different", but we're not teaching people to write libraries, so the notion of one program that can be run on multiple branches of Python isn't all that significant. If you're going to maintain a 2.x codebase, there's no knowing what kinds of coding styles it'll use - you can't depend on it being written for 2.7 - which makes it nearly impossible to try to teach in a generic way. The task of supporting a legacy codebase is always one of "learn the language, then learn the codebase"; why bother teaching things like "except ValueError, e:" or (worse) the old style of string exceptions, just in case someone runs into them somewhere? No. We teach 3.4 (because that's what's available on the Ubuntu VMs that we're recommending; anything 3.2+ will probably work just the same), and that's it. ChrisA From rosuav at gmail.com Sun Nov 1 09:31:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 01:31:35 +1100 Subject: Multithreading python,two tkinter windows In-Reply-To: <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com> References: <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com> Message-ID: On Mon, Nov 2, 2015 at 1:05 AM, Vindhyachal Takniki wrote: > #get reading at every 1 second > def get_analog_1(thread_name): > global read_ok_1, current_time_1,analog_1 > while True: > if((time.time() - current_time_1) > 1): > if(0 == read_ok_1): > current_time_1 = time.time(); > read_ok_1 = 1; > analog_1 = randint(0,100) Never do this. It's called a "busy-wait", and not only does it saturate your Python thread, it also saturates your entire system - this is going to keep one CPU core permanently busy going "are we there yet? are we there yet?" about the one-second delay. Instead, use time.sleep(), which will delay your thread by one second, allowing other threads to run. Better still, think about your code in terms of events. Most GUI libraries these days are built around an event-driven model, and the notion of "make this event happen 1 second from now" or "10 seconds from now" is a very common one. ChrisA From steve at pearwood.info Sun Nov 1 09:41:10 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 02 Nov 2015 01:41:10 +1100 Subject: UNABLE TO GET IDLE TO RUN References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> Message-ID: <56362487$0$1611$c3e8da3$5496439d@news.astraweb.com> On Sun, 1 Nov 2015 01:50 pm, Terry Reedy wrote: > On 10/31/2015 9:45 PM, Michiel Overtoom wrote: >> I'd go even a step further. I think IDLE should not only warn, but > > The warning will require a choice, with the default (if one just hits > ) being to reject the duplicate and go back to the Save-as > dialog. Please add yourself as nosy on the issue so you can comment on > the message whenever I get around to adding a patch. Users are inclined to ignore alerts, dialogs and error messages, and applications try very, very hard to reinforce that tendency. http://ux.stackexchange.com/questions/4518/should-alert-boxes-be-avoided-at-any-cost Good to see that IDLE is going to continue that fine old tradition of degrading usability for the sake of a quick and easy non-solution to a problem. :-( -- Steven From lac at openend.se Sun Nov 1 09:49:37 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 15:49:37 +0100 Subject: Python 2 vs Python 3 for teaching In-Reply-To: References: Message-ID: <201511011449.tA1Enbbp024177@fido.openend.se> In a message of Mon, 02 Nov 2015 01:27:24 +1100, Chris Angelico writes: >On Mon, Nov 2, 2015 at 1:11 AM, wrote: >> On Nov 1, 2015 2:45 AM, "Chris Angelico" wrote: >>> >>> I'm proud to say that a Python tutoring company has just converted its >>> course over from teaching Python 2.7 to teaching 3.x. For the >>> naysayers out there, it actually wasn't much of a transition; >> >> This would make an excellent opportunity to develop a curriculum to teach >> students how to maintain a 2.x and 3.x code base using 2to3. >> >> 2.x is not going away as fast as some would like. >I'd rather not use 2to3 there. If you want to maintain a library that >can be used from 2.x and 3.x, it's much better to aim for the >compatible middle - u prefixes on all Unicode strings, b prefixes on >all byte strings, stick to ASCII where possible, etc, etc. Much easier >than writing code for one branch and then converting to the other. How about using six, same idea with the curriculum? Laura From rosuav at gmail.com Sun Nov 1 09:52:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 01:52:43 +1100 Subject: Python 2 vs Python 3 for teaching In-Reply-To: <201511011449.tA1Enbbp024177@fido.openend.se> References: <201511011449.tA1Enbbp024177@fido.openend.se> Message-ID: On Mon, Nov 2, 2015 at 1:49 AM, Laura Creighton wrote: >>I'd rather not use 2to3 there. If you want to maintain a library that >>can be used from 2.x and 3.x, it's much better to aim for the >>compatible middle - u prefixes on all Unicode strings, b prefixes on >>all byte strings, stick to ASCII where possible, etc, etc. Much easier >>than writing code for one branch and then converting to the other. > > How about using six, same idea with the curriculum? If we were building libraries, then yes, six would be the way to go. But there's really no reason to bother - we're building applications from scratch (or from templates that are under our control), so it's easy to stipulate that Python 3.x is a prerequisite. ChrisA From mail at timgolden.me.uk Sun Nov 1 10:01:00 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 1 Nov 2015 15:01:00 +0000 Subject: UNABLE TO GET IDLE TO RUN In-Reply-To: <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5636292C.6090603@timgolden.me.uk> On 01/11/2015 14:27, Steven D'Aprano wrote: >> I remember from a few weeks back, a >> teacher with the same problem posted this on the mailinglist. Eventually >> she had a technician coming in to reinstall Windows, just to fix this >> problem ;-) What an overkill... > > If that is true, that's really sad. Were we really unable to tell this > teacher to delete the shadowing file? Or was there more to the problem than > that? We tried, over the course of several days. It looked like a simple "delete this and try again" problem. After a couple of iterations she and her tech support obviously decided that re-imaging the lab machines was a better use of their time to achieve their goal (get the thing working) than further distance-learning diagnostics. TJG From rurpy at yahoo.com Sun Nov 1 10:43:34 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 1 Nov 2015 07:43:34 -0800 (PST) Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> Message-ID: <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> On 11/01/2015 03:06 AM, Chris Warrick wrote: > On 1 November 2015 at 09:23, t_ciorba--- via Python-list > wrote: >> >> hi, i am not sure what is wrong, but after launching the installer >> for windows XPsp3 python-3.5.0.exe i couldnt see what i have to >> select, it was a white board and the only button on it was >> "cancel". here is a screen of it: > > Windows XP is not supported. Please upgrade to a modern version of > Windows, or switch to Linux. (you could also use 3.4.3, but Windows > XP is insecure, and more apps will follow suit.) Why, oh why, do the python.org front page and other pages that offer a Windows download not say a word about it not running on Windows XP? Even if one is anal enough to go to the page about the 3.5 release. https://www.python.org/downloads/release/python-350/ a page with a lot of Windows-specific info, there is not a word about XP. Or perhaps the number of posts to this list are declining and having people download Python-3.5, have it fail, and then ask why here is part of a secret plan to increase list volume? From rosuav at gmail.com Sun Nov 1 10:52:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 02:52:27 +1100 Subject: installer user interface glitch ? In-Reply-To: <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> Message-ID: On Mon, Nov 2, 2015 at 2:43 AM, rurpy--- via Python-list wrote: > Why, oh why, do the python.org front page and other pages that offer > a Windows download not say a word about it not running on Windows XP? > > Even if one is anal enough to go to the page about the 3.5 release. > https://www.python.org/downloads/release/python-350/ > a page with a lot of Windows-specific info, there is not a word > about XP. A partial answer to that is in PEP 11: https://www.python.org/dev/peps/pep-0011/#microsoft-windows Windows XP isn't special here. There's no mention of Python 2.7 not working on Windows 95, because it's simply an unsupported operating system. The only reason that people keep coming asking about XP and not (say) Win2K is that there are a lot more XP boxes out there. Do the other download pages need to stipulate which versions of which OSes they support, or should that be left up to the installer? There *is* a plan to have the installer give a better error message for this situation. But I don't think the web site necessarily has to have noise about old versions of OSes. Where would you draw the line? ChrisA From motoom at xs4all.nl Sun Nov 1 10:54:45 2015 From: motoom at xs4all.nl (Michiel Overtoom) Date: Sun, 1 Nov 2015 16:54:45 +0100 Subject: installer user interface glitch ? In-Reply-To: <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> Message-ID: > On 01 Nov 2015, at 16:43, rurpy--- via Python-list wrote: > > Why, oh why, do the python.org front page and other pages that offer > a Windows download not say a word about it not running on Windows XP? I'm also curious why Python 3.5 won't run on Windows XP. Which features does it use that require Windows 7 or higher? Or is the decision to not support Windows XP based on Microsoft ending the product support lifecycle for XP? Greetings, From lac at openend.se Sun Nov 1 11:17:31 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 17:17:31 +0100 Subject: UNABLE TO GET IDLE TO RUN In-Reply-To: <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201511011617.tA1GHVKE030820@fido.openend.se> I managed to delete the real mail I would like to reply to. This is, at least in the same thread .... In a message of Mon, 02 Nov 2015 01:27:23 +1100, "Steven D'Aprano" writes a reply to Michael Overtoon: > Users are inclined to ignore alerts, dialogs and error messages, and > applications try very, very hard to reinforce that tendency. http://ux.stackexchange.com/questions/4518/should-alert-boxes-be-avoided-at-any-cost (ok posting of question.) > Good to see that IDLE is going to continue that fine old tradition of > degrading usability for the sake of a quick and easy non-solution to a > problem. I think you owe Michael an apology. Winning an argument on 'I should I get it my way because I can come up with a pithy and condescending way to phrase my objection to what you want to do' seems morally bankrupt to me. Ditto on the idea of bashing him just because he is handy and the world is a bad place for you right now. It hardly counts as a technical reason for or against the issuing of warnings in idle, or the more severe 'not allowing you to save'. I have a professional carreer based on saying 'do not blather useless error/warning messages' at people. I am pretty much always on your side of the argument. But, here we are, first time in 22 years, and I am here arguing in _favour_ of a warning message. :) I very much want to convince Michael that my warning will be sufficient, thus preventing people from writing out strings.py is unnecessary. It's going to be damn hard to do so if he is stung by your non-constructive (however brilliant) remark. Laura From rurpy at yahoo.com Sun Nov 1 11:24:22 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 1 Nov 2015 08:24:22 -0800 (PST) Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> Message-ID: <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> On Sunday, November 1, 2015 at 8:52:55 AM UTC-7, Chris Angelico wrote: > On Mon, Nov 2, 2015 at 2:43 AM, rurpy--- via Python-list wrote: > > Why, oh why, do the python.org front page and other pages that offer > > a Windows download not say a word about it not running on Windows XP? > > > > Even if one is anal enough to go to the page about the 3.5 release. > > https://www.python.org/downloads/release/python-350/ > > a page with a lot of Windows-specific info, there is not a word > > about XP. > > A partial answer to that is in PEP 11: > > https://www.python.org/dev/peps/pep-0011/#microsoft-windows > > Windows XP isn't special here. There's no mention of Python 2.7 not > working on Windows 95, because it's simply an unsupported operating > system. The only reason that people keep coming asking about XP and > not (say) Win2K is that there are a lot more XP boxes out there. Do > the other download pages need to stipulate which versions of which > OSes they support, or should that be left up to the installer? I dont recall seeing anyone posting asking why they could not get Python to install on Windows 95 recently. I only read this group intermittently but I have seen *many* posts asking why they couldnt install on XP. You acknowledge yourself: "there are a lot more XP boxes out there." > There *is* a plan to have the installer give a better error message > for this situation. A better message from the installer is necessary but not sufficient. Don't make people go through the effort to download the whole thing, do their planning and preparations for using or upgrading Python only to discover at the last moment it wont work. That is really shitty customer relations. The reality is that people trying install Python-3.5 on XP *is* a problem. Telling them they should have read some obscure release notes is not a solution. > But I don't think the web site necessarily has to > have noise about old versions of OSes. Where would you draw the line? I think my responses above answer that. From torriem at gmail.com Sun Nov 1 11:39:00 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 01 Nov 2015 09:39:00 -0700 Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> Message-ID: <56364024.10707@gmail.com> On 11/01/2015 03:08 AM, Chris Angelico wrote: > Windows XP has now been around for twelve years. It's older than that. Release date was August 1, 2001. More than 14 years ago. My how the time flies. Though more recent versions of Windows have added features (which Python now takes advantage of), it doesn't seem to me that we've gained much in all that time in overall usability terms, from an end-user persepective. If it weren't for security issues, I'm sure Windows XP would work just fine indefinitely for some tasks. But they will have to stick with unmaintained software and any problems that entails. From rosuav at gmail.com Sun Nov 1 11:43:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 03:43:28 +1100 Subject: installer user interface glitch ? In-Reply-To: <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> Message-ID: On Mon, Nov 2, 2015 at 3:24 AM, rurpy--- via Python-list wrote: > I dont recall seeing anyone posting asking why they could not get > Python to install on Windows 95 recently. I only read this group > intermittently but I have seen *many* posts asking why they couldnt > install on XP. > > You acknowledge yourself: "there are a lot more XP boxes out there." Yes, there are. This is not a customer base; they are not paying me, nor (as far as I know) the PSF, to support them. >> There *is* a plan to have the installer give a better error message >> for this situation. > > A better message from the installer is necessary but not sufficient. > Don't make people go through the effort to download the whole thing, > do their planning and preparations for using or upgrading Python > only to discover at the last moment it wont work. The largest installer [1] is 30MB, which might have been considered large a decade ago, but on today's connections, that's probably going to download in less time than it takes people to search for "python", find python.org, and decide to click the download link. The web installer is less than one megabyte. If you can't afford to download a single meg of executable to find out whether something works on your system, you probably can't afford to download the page with the info telling you not to bother downloading the binary. > That is really shitty customer relations. See above, and define 'customer'. > The reality is that people trying install Python-3.5 on XP *is* a > problem. Telling them they should have read some obscure release > notes is not a solution. Nor is telling them they should have read the web site that they downloaded it from. Remember, people can click a direct download link *on the python.org front page* and be immediately downloading Python 2 or 3 for the OS that the browser announces. Where would you put the big fat noisy warning? >> But I don't think the web site necessarily has to >> have noise about old versions of OSes. Where would you draw the line? > > I think my responses above answer that. Not really, no. There are currently a large number of XP boxes out there, for some definition of 'large'. Presumably that number is dropping. At what point will it be appropriate to ditch the warning? And what about older versions of non-Windows OSes - if there are a large number of people still running an old Mac OS, should we include something on the front page that warns everyone about a lack of support? How large is large? I say again: Where would you draw the line? ChrisA [1] Based on the file sizes here: https://www.python.org/downloads/release/python-350/ From rosuav at gmail.com Sun Nov 1 12:01:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 04:01:41 +1100 Subject: installer user interface glitch ? In-Reply-To: <56364024.10707@gmail.com> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <56364024.10707@gmail.com> Message-ID: On Mon, Nov 2, 2015 at 3:39 AM, Michael Torrie wrote: > On 11/01/2015 03:08 AM, Chris Angelico wrote: >> Windows XP has now been around for twelve years. > > It's older than that. Release date was August 1, 2001. More than 14 > years ago. My how the time flies. > > Though more recent versions of Windows have added features (which Python > now takes advantage of), it doesn't seem to me that we've gained much in > all that time in overall usability terms, from an end-user persepective. > If it weren't for security issues, I'm sure Windows XP would work just > fine indefinitely for some tasks. But they will have to stick with > unmaintained software and any problems that entails. Hmm. I had a mental notion of XP as a 2003 release. So, it's even more so: it's been around for fourteen years, and XPSP3 came out seven years ago, so it's been that long since a major upgrade of any sort. That's approximately the age of RHEL 5 - and a base XP is slightly older than RHEL 2.1, the oldest that I can find dates for. If we're really generous, then, we can accept that XP SP3 is about on par with a Linux that's shipping Python 2.4. The fact that 2.7 and 3.4 both run on XP is a tribute to the extensive support that XP *does* have. ChrisA From lac at openend.se Sun Nov 1 12:25:21 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 18:25:21 +0100 Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <56364024.10707@gmail.com> Message-ID: <201511011725.tA1HPL1S003700@fido.openend.se> The important thing is that, numbers-wise, windowsXP was the version of computer a whole lot of people got when they got their first computer. The notion of, not it "wearing out" but that the whole world "wore out" or "advanced beyond" them is foreign to them. They aren't computer-hobbyists -- they are early adopters of the web browser and internet search, if anything. The whole message of 'get a newer os' is decidedly hard for them. "It works fine, like my 2004 Ford car" they want to tell you. Laura From invalid at invalid.invalid Sun Nov 1 12:56:33 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 1 Nov 2015 17:56:33 +0000 (UTC) Subject: installer user interface glitch ? References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <56364024.10707@gmail.com> Message-ID: On 2015-11-01, Laura Creighton wrote: > The whole message of 'get a newer os' is decidedly hard for them. > "It works fine, like my 2004 Ford car" they want to tell you. Except it _doesn't_ work fine, or they wouldn't be complaining. If you want to run Python 3.5, then XP just doesn't work. Why they think it's Python's fault is the question... -- Grant From lac at openend.se Sun Nov 1 13:08:40 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 19:08:40 +0100 Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <56364024.10707@gmail.com> Message-ID: <201511011808.tA1I8eSt006945@fido.openend.se> In a message of Sun, 01 Nov 2015 17:56:33 +0000, Grant Edwards writes: >On 2015-11-01, Laura Creighton wrote: > >> The whole message of 'get a newer os' is decidedly hard for them. >> "It works fine, like my 2004 Ford car" they want to tell you. > >Except it _doesn't_ work fine, or they wouldn't be complaining. > >If you want to run Python 3.5, then XP just doesn't work. Why they >think it's Python's fault is the question... > >-- >Grant :) Actually, the people I talk to are to be forgiven for not understanding that 3.5 does not work for them given that the installer does not spit them out with a fail message at the start. It's the next step. "Why can you not make a product for my perfectly working system!" that I was thinking about. And, to be fair, lots of them are grandparents who want to be able to see their grandchildren's turtle programs .... Not the usual case for 'need to download python', to be sure Laura From rurpy at yahoo.com Sun Nov 1 14:41:42 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 1 Nov 2015 11:41:42 -0800 (PST) Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> Message-ID: <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> On 11/01/2015 09:43 AM, Chris Angelico wrote: > On Mon, Nov 2, 2015 at 3:24 AM, rurpy--- via Python-list wrote: >> I dont recall seeing anyone posting asking why they could not get >> Python to install on Windows 95 recently. I only read this group >> intermittently but I have seen *many* posts asking why they couldnt >> install on XP. >> >> You acknowledge yourself: "there are a lot more XP boxes out there." > > Yes, there are. This is not a customer base; they are not paying me, > nor (as far as I know) the PSF, to support them. I wasn't asking *you* to do anything. And I wasn't asking for python to support XP. I'm not sure how you have possibly got that idea. In fact I wasn't *asking* anyone to do anything. I was pointing out (the obvious) that there was a problem with people not understanding that Python-3.5 will not run on XP and suggesting a low-cost way to reduce that problem. >>> There *is* a plan to have the installer give a better error message >>> for this situation. >> >> A better message from the installer is necessary but not sufficient. >> Don't make people go through the effort to download the whole thing, >> do their planning and preparations for using or upgrading Python >> only to discover at the last moment it wont work. > > The largest installer [1] is 30MB, which might have been considered > large a decade ago, but on today's connections, that's probably going > to download in less time than it takes people to search for "python", > find python.org, and decide to click the download link. The web > installer is less than one megabyte. If you can't afford to download a > single meg of executable to find out whether something works on your > system, you probably can't afford to download the page with the info > telling you not to bother downloading the binary. As I said it is not solely the number of minutes needed to download something. And not everyone in the world has high-speed reliable connection. It wasn't that long ago my internet connection was a modem. And even today with screaming fast 100KB/s (sometimes) connection I often have to babysit a download to get it to complete or deal with long outages. There are plenty of places much less connected than I am. And of course those are the same places where people are more likely to still be using XP. >> That is really shitty customer relations. > > See above, and define 'customer'. customer: the people to whom you are providing a product or service. Of course, unless the PSF has a charter that imposes some legal requirements, PSF/Python development community has no legal obligation to do anything for anyone. They could add spam-ware to the installer, make backward incompatible changes on a whim, release software that crashes when started. Now could we return to reality please? >> The reality is that people trying install Python-3.5 on XP *is* a >> problem. Telling them they should have read some obscure release >> notes is not a solution. > > Nor is telling them they should have read the web site that they > downloaded it from. Remember, people can click a direct download link > *on the python.org front page* and be immediately downloading Python 2 > or 3 for the OS that the browser announces. Where is that? I didn't see anything that wasn't accompanied with text that could accommodate a windows xp warning. But then I was looking at it from a Linux machine. And even if it is impossibly awkward to provide in one case (though I doubt that's the case), there certainly should be a warning on the windows specific pages. AFAIK, the only place where dropping XP support is mentioned in the docs is way down the bottom of What's New. PEP-11 doesn't count -- it unrealistic in the extreme to expect a Windows user who wants to try Python to read (or even know about) the PEPs, or that one of them describes supported OSes. > Where would you put the > big fat noisy warning? I would not put a "big fat noisy warning" anywhere. I would put a minimally sized but clear notice where the windows version of python-3.5 can be downloaded. >>> But I don't think the web site necessarily has to >>> have noise about old versions of OSes. Where would you draw the line? What noise? Providing basic useful information to a significant number of customers/clients/users, information that is not provided elsewhere in the normal course of their actions, is not "noise". If you want to get rid of noise, how about ditching corporate-style PR like "Success Stories", or a big graphic of fibonacci numbers in python? It's really sad to see open source projects taken over by marketing wanna-bees who think PR fluff is more important that actual actionable information. >> I think my responses above answer that. > > Not really, no. There are currently a large number of XP boxes out > there, for some definition of 'large'. Presumably that number is > dropping. At what point will it be appropriate to ditch the warning? > And what about older versions of non-Windows OSes - if there are a > large number of people still running an old Mac OS, should we include > something on the front page that warns everyone about a lack of > support? Why don't you try answering that question yourself? Start by asking how many posts to this list asking why the poster couldn't install Python-3.5 on an old MacOS system you've seen. > How large is large? I say again: Where would you draw the > line? If you insist on a concrete number (I presume so you can pick nits with it rather than the general proposition), 5 years. Then reevaluate. Once someone has actually adds a note dispute about whether it should be there will fade into nothingness and removing it after xp truly is insignificant will be contentious. From no.email at nospam.invalid Sun Nov 1 14:47:37 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 01 Nov 2015 11:47:37 -0800 Subject: Python 2 vs Python 3 for teaching References: Message-ID: <87y4ehzeli.fsf@nightsong.com> Chris Angelico writes: > We teach 3.4 (because that's what's available on the Ubuntu VMs that > we're recommending; anything 3.2+ will probably work just the same), > and that's it. The async keyword seems like one of Py3's bigger improvements and it makes its appearance in 3.5, iirc. From python at mrabarnett.plus.com Sun Nov 1 15:46:18 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 1 Nov 2015 20:46:18 +0000 Subject: installer user interface glitch ? In-Reply-To: <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> Message-ID: <56367A1A.7020007@mrabarnett.plus.com> On 2015-11-01 19:41, rurpy--- via Python-list wrote: > On 11/01/2015 09:43 AM, Chris Angelico wrote: >> On Mon, Nov 2, 2015 at 3:24 AM, rurpy--- via Python-list wrote: [snip] >>> That is really shitty customer relations. >> >> See above, and define 'customer'. > > customer: the people to whom you are providing a product or service. > A customer is someone who receives goods or services in return for some kind of monetary or other payment. The PSF makes Python available as-is, gratis. Those who are downloading Python from the PSF are not "customers". [snip] From luisjosenovoa at gmail.com Sun Nov 1 16:27:27 2015 From: luisjosenovoa at gmail.com (LJ) Date: Sun, 1 Nov 2015 13:27:27 -0800 (PST) Subject: PyPy subprocess Message-ID: <37cd1025-2b18-48bf-a3cc-e792cce11b58@googlegroups.com> Hi All. I hope you're having a good weekend. Im working on a large scale optimization problem which invokes the Gurobi solver from python. Before invoking the solver I use pure python to solve five subproblems in parallel using the multiprocessing module. These subproblems are the bottleneck of my procedure. Im wondering if there is a way in which I can use PyPy to solve the just subproblems in parallel, and return to CPython for the overall routines. The reason behind this, is that Gurobipy (python interface for the Gurobi optimization solver) is not compatible with PyPy, and Im seeing savings of 50% in time when using PyPy to somve the subproblems. Any help would be highly appreciated. Lj. From luisjosenovoa at gmail.com Sun Nov 1 16:29:01 2015 From: luisjosenovoa at gmail.com (LJ) Date: Sun, 1 Nov 2015 13:29:01 -0800 (PST) Subject: PyPy subprocess In-Reply-To: <37cd1025-2b18-48bf-a3cc-e792cce11b58@googlegroups.com> References: <37cd1025-2b18-48bf-a3cc-e792cce11b58@googlegroups.com> Message-ID: <22453b31-465e-4da2-8ac9-28dbe7f4bbc7@googlegroups.com> By the way, Im using python 2.7. Thanks From lac at openend.se Sun Nov 1 16:48:28 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 01 Nov 2015 22:48:28 +0100 Subject: installer user interface glitch ? In-Reply-To: <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> Message-ID: <201511012148.tA1LmSop023373@fido.openend.se> Actually, adding the XP - do not look here -- message for several webpages has been on the pydotorg todo list for more than a week now. Not sure why it hasn't happened. Thank you for the reminder. Laura From rosuav at gmail.com Sun Nov 1 17:03:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 09:03:19 +1100 Subject: Python 2 vs Python 3 for teaching In-Reply-To: <87y4ehzeli.fsf@nightsong.com> References: <87y4ehzeli.fsf@nightsong.com> Message-ID: On Mon, Nov 2, 2015 at 6:47 AM, Paul Rubin wrote: > Chris Angelico writes: >> We teach 3.4 (because that's what's available on the Ubuntu VMs that >> we're recommending; anything 3.2+ will probably work just the same), >> and that's it. > > The async keyword seems like one of Py3's bigger improvements and it > makes its appearance in 3.5, iirc. Yeah. Not currently available to us, since we're recommending (for consistency) that students use the Cloud 9 browser-based IDE, but I'm sure when Ubuntu's next LTS comes out, it'll include 3.5 (or maybe 3.6), so we'll start using that then. Taking advantage of new features can be done as we decide they're safe to use, without needing any backward compatibility breaks (apart from, of course, the async/await code not working on older Pythons). Hmm. Maybe this should be a workshop... that could be fun. ChrisA From rosuav at gmail.com Sun Nov 1 17:11:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 09:11:55 +1100 Subject: PyPy subprocess In-Reply-To: <37cd1025-2b18-48bf-a3cc-e792cce11b58@googlegroups.com> References: <37cd1025-2b18-48bf-a3cc-e792cce11b58@googlegroups.com> Message-ID: On Mon, Nov 2, 2015 at 8:27 AM, LJ wrote: > Im wondering if there is a way in which I can use PyPy to solve the just subproblems in parallel, and return to CPython for the overall routines. > You could. What you'd have would be a setup where the subprocess is utterly independent of the parent; the fact that they both happen to be written in Python is almost immaterial. Figure out some way of telling the subprocess what it needs to do (eg command-line parameters coming through into sys.argv), and getting a response back (eg writing something to stdout before terminating), and then you can use the subprocess module to spin off the pypy processes, then (maybe after doing some other work) wait for each of them to finish. The subproblem solver could be written in any language at all, here; there's complete decoupling. If you need to pass a lot of info down into them, or up and out again, you'll need to serialize it all into JSON and use stdin/stdout, or something like that. Takes some care, but it works beautifully... I once had a "Python in Python" setup like that to make my Python-based web site trigger something in a newer version of Python than was shipped with my OS (think of a 2.7 invoking a 3.5 script - I don't remember the actual versions but it was something like that). ChrisA From robertvstepp at gmail.com Sun Nov 1 17:28:00 2015 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 1 Nov 2015 16:28:00 -0600 Subject: installer user interface glitch ? In-Reply-To: <201511012148.tA1LmSop023373@fido.openend.se> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> <201511012148.tA1LmSop023373@fido.openend.se> Message-ID: On Sun, Nov 1, 2015 at 3:48 PM, Laura Creighton wrote: > Actually, adding the XP - do not look here -- > message for several webpages has been on the pydotorg > todo list for more than a week now. > > Not sure why it hasn't happened. > > Thank you for the reminder. I have to confess I do not understand all of the hullabaloo generated in this thread, but I think it would be helpful if there were an obviously placed minimum requirements note for the download page. Something like "Requires Windows Vista or greater ...", etc. I imagine many people are like myself, just trying to learn Python and want the latest version, etc. Many software products include a minimum requirements statement on their download page, so--at least to me--it does not seem unreasonable for the Python folks to do the same. If nothing else it might reduce the number of recent XP users from asking the same questions over, and, ..., and over. Of course if such people would only type in their issue into their favorite search engine... But that is a different issue--heavy sigh! -- boB From rosuav at gmail.com Sun Nov 1 17:38:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 09:38:10 +1100 Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> <201511012148.tA1LmSop023373@fido.openend.se> Message-ID: On Mon, Nov 2, 2015 at 9:28 AM, boB Stepp wrote: > Of course if such > people would only type in their issue into their favorite search > engine... But that is a different issue--heavy sigh! In their defense, "the installer for Python has a blank window" isn't nearly as internet-searchable as an actual text error message - plus the problem exhibits itself in a number of different ways (probably relating to exactly what parts of XP are available, or something). Once there's a clear error message saying that this Python doesn't work on this Windows, it'll be easy for people to look up info on it, and then find a fully-supported Python 3.4 installer. ChrisA From ben+python at benfinney.id.au Sun Nov 1 17:48:42 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2015 09:48:42 +1100 Subject: Python 2 vs Python 3 for teaching References: Message-ID: <854mh5mj3p.fsf@benfinney.id.au> writes: > This would make an excellent opportunity to develop a curriculum to > teach students how to maintain a 2.x and 3.x code base using 2to3. The advice today reflects the great progress that has been made over many years of migrating projects and organisations to Python 3. Instead of ?2to3?, the best advice today is: write new code targeting Python 3 directly, and only if necessary back-port to Python 2. > 2.x is not going away as fast as some would like. Likewise, Python 3 as a primary development target is not as difficult as some would fear. Python 2 is unarguably a legacy platform, but it has good support for receiving code carefully targeting both Python 2 and Python 3. So it's best to target Python 3 primarily, and back-port code to Python 2 only as and when needed. -- \ ?We jealously reserve the right to be mistaken in our view of | `\ what exists, given that theories often change under pressure | _o__) from further investigation.? ?Thomas W. Clark, 2009 | Ben Finney From tjreedy at udel.edu Sun Nov 1 18:12:27 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Nov 2015 18:12:27 -0500 Subject: Multithreading python,two tkinter windows In-Reply-To: <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com> References: <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com> Message-ID: On 11/1/2015 9:05 AM, Vindhyachal Takniki wrote: > I have made a python code & using multithreading in it. this is very basic code, not using queues & other stuff. You can run multiple windows, or one window with multiple panes, in one thread with one event loop. Best to do gui stuff in the main thread and only use other threads for things that would block. I see that you already know how to use .after to loop. You can have multiple .after loops, with different delays, in one thread. -- Terry Jan Reedy From tjreedy at udel.edu Sun Nov 1 19:07:38 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Nov 2015 19:07:38 -0500 Subject: UNABLE TO GET IDLE TO RUN In-Reply-To: <201511011617.tA1GHVKE030820@fido.openend.se> References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> <201511011617.tA1GHVKE030820@fido.openend.se> Message-ID: On 11/1/2015 11:17 AM, Laura Creighton wrote: > In a message of Mon, 02 Nov 2015 01:27:23 +1100, "Steven D'Aprano" writes > a reply to Michael Overtoon: He was actually responding to my proposal to warn about duplicating stdlib names when saving-as. >> Users are inclined to ignore alerts, dialogs and error messages, and >> applications try very, very hard to reinforce that tendency. > > http://ux.stackexchange.com/questions/4518/should-alert-boxes-be-avoided-at-any-cost I read this and at least some of the concerns do not apply. * IDLE does not spam users with alerts. And I may move some of the rare ones to a new 'log' window. The only one I see with any regularity is 'Save work before close?' and that I appreciate. * 'Save-as' is not part of the regular workflow. It is done once per file. Experienced users who know to avoid stdlib names will not see the messages unless they accidentally duplicate one -- which is possible because there are now so many. I personally would like being warned. * The target of the message is naive beginners who have not read any docs and who may not yet even know about the stdlib and imports. The *need* the info and may not be so jaded about alert messages. One person suggested something I thought about: make the 'right thing' box bigger than the 'dangerous thing' box. >> Good to see that IDLE is going to continue that fine old tradition of >> degrading usability for the sake of a quick and easy non-solution to a >> problem. Doing nothing is also a non-solution. > I have a professional carreer based on saying 'do not blather useless > error/warning messages' at people. I am pretty much always on your > side of the argument. But, here we are, first time in 22 years, and > I am here arguing in _favour_ of a warning message. :) Knowing that you are not a fan of such things makes your request stronger. > I very much want to convince Michael that my warning will be > sufficient, If the message works half the time, I would consider it successful. > thus preventing people from writing out strings.py is unnecessary. I will not absolutely prevent duplicate names unless Guido says to do so. -- Terry Jan Reedy From danieljoffe at comcast.net Sun Nov 1 19:08:44 2015 From: danieljoffe at comcast.net (Daniel Joffe) Date: Sun, 1 Nov 2015 18:08:44 -0600 Subject: python doesn't install Message-ID: <5636A98C.6030203@comcast.net> WinXP...32 bits...professional I keep getting message note also that there is no place on the install box to start...you just click somewhere, and the install started. From no.email at nospam.invalid Sun Nov 1 19:50:04 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 01 Nov 2015 16:50:04 -0800 Subject: UNABLE TO GET IDLE TO RUN References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> <201511011617.tA1GHVKE030820@fido.openend.se> Message-ID: <87twp5z0lf.fsf@nightsong.com> Terry Reedy writes: > * 'Save-as' is not part of the regular workflow. It is done once per > file. Experienced users who know to avoid stdlib names will not see > the messages unless they accidentally duplicate one -- which is > possible because there are now so many. I personally would like being > warned. I think there is something to be said for this. I've gotten confused a few times by accidentally re-using a stdlib name, and I'm experienced. One thing I wish in IDLE is for ctrl-N (or some alternate) to prompt for a filename immediately: opening a new window, then writing code in it, and then using Save-as seems unnatural to me. That would also be a good time to validate the filename, by searching sys.path or whatever. From tjreedy at udel.edu Sun Nov 1 19:50:38 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Nov 2015 19:50:38 -0500 Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> <201511012148.tA1LmSop023373@fido.openend.se> Message-ID: On 11/1/2015 5:28 PM, boB Stepp wrote: > On Sun, Nov 1, 2015 at 3:48 PM, Laura Creighton wrote: >> Actually, adding the XP - do not look here -- >> message for several webpages has been on the pydotorg >> todo list for more than a week now. >> >> Not sure why it hasn't happened. >> >> Thank you for the reminder. > > I have to confess I do not understand all of the hullabaloo generated > in this thread, but I think it would be helpful if there were an > obviously placed minimum requirements note for the download page. > Something like "Requires Windows Vista or greater ...", etc. I agree. A Minimum Requirements box is pretty standard on both boxes and web pages. For Python, a sentence suffices. -- Terry Jan Reedy From steve at pearwood.info Sun Nov 1 19:54:45 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 02 Nov 2015 11:54:45 +1100 Subject: UNABLE TO GET IDLE TO RUN References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5636b458$0$1622$c3e8da3$5496439d@news.astraweb.com> On Mon, 2 Nov 2015 03:17 am, Laura Creighton wrote: > I managed to delete the real mail I would like to reply to. > This is, at least in the same thread .... > > In a message of Mon, 02 Nov 2015 01:27:23 +1100, "Steven D'Aprano" writes > a reply to Michael Overtoon: Actually it's a reply to Terry. >> Users are inclined to ignore alerts, dialogs and error messages, and >> applications try very, very hard to reinforce that tendency. > > http://ux.stackexchange.com/questions/4518/should-alert-boxes-be-avoided-at-any-cost > > (ok posting of question.) > >> Good to see that IDLE is going to continue that fine old tradition of >> degrading usability for the sake of a quick and easy non-solution to a >> problem. > > I think you owe Michael an apology. I can't imagine why you think I owe Michael an apology. An apology for what? > Winning an argument on 'I should I get it my way because I can come up > with a pithy and condescending way to phrase my objection to what you > want to do' seems morally bankrupt to me. Ditto on the idea of bashing > him just because he is handy and the world is a bad place for you right > now. "Bashing" him? Really? A touch of sarcasm ("Good to see") about a technical decision is bashing the author and "morally bankrupt"? Laura, with respect, perhaps it isn't me who is writing from "a bad place" right now. > It hardly counts as a technical reason for or against the issuing > of warnings in idle, or the more severe 'not allowing you to save'. There is a technical reason against the issuing of warnings in IDLE, namely that their target audience is disinclined to read warnings, not well suited to understand these specific warnings, and likely to click on whatever random buttons it takes to make the warnings go away and let them save their file under their chosen name. > I have a professional carreer based on saying 'do not blather useless > error/warning messages' at people. I am pretty much always on your > side of the argument. But, here we are, first time in 22 years, and > I am here arguing in _favour_ of a warning message. :) I get that, I truly do, and believe me when I say I respect your expertise. But it seems to me that you're falling for the fallacy "we must do something, this is something, therefore we must do it". I completely agree that accidental shadowing is a problem, especially for beginners. I too would like to fix that, and (as you know, but others may not) I've proposed a solution on the Python-Ideas mailing list. But just because there is a problem doesn't mean that the first thing we think of is the solution. I haven't come across anyone, not one person, willing to dispute the conventional wisdom that users don't read alert messages. We agree that users don't read warnings, but you're expecting them to read *this* warning. What makes this proposed warning different from all the other useless blatherings that users don't read? Why will they read this one? It is 2015, nearly 2016, and surely there isn't a professional developer alive who hasn't come across the truism that users don't read warnings, and that they should avoid putting up modal dialogs with a warning. And yet they still do it. Why? They're not all idiots. I don't believe either you or Terry are idiots. I expect that, like you and Terry, they have fallen into the trap of believing that *this one case is special*. This issue is important enough that we have to do something, and users might not read all those other blathering error messages, but they'll read this one, because it is important that they do. Otherwise, how can you justify this warning? Users won't read it. It will just reinforce their tendency to ignore errors and warnings, and as an educator surely you don't want that. If they click on the OK/Cancel button at random, as UI studies suggest people tend to do, then 50% will end up shadowing the file regardless, and 50% will have a second chance to pick a better name -- which they may not do. And most shadowing is harmless. If I name my script code.py, or this.py, it will still run fine unless I directly or indirectly import `code` or `this`. It is true that shadowing *can* leave Python effectively unusable (try shadowing `os` and see how many things break) but most of the time shadowing doesn't hurt. So most of the time, these warnings will be exactly the pointless blatherings that you usually oppose. -- Steven From tjreedy at udel.edu Sun Nov 1 20:02:30 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Nov 2015 20:02:30 -0500 Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> Message-ID: On 11/1/2015 10:54 AM, Michiel Overtoom wrote: > >> On 01 Nov 2015, at 16:43, rurpy--- via Python-list >> wrote: >> >> Why, oh why, do the python.org front page and other pages that >> offer a Windows download not say a word about it not running on >> Windows XP? > > I'm also curious why Python 3.5 won't run on Windows XP. Which > features does it use that require Windows 7 or higher? The initial issue was some system functions that are new in Vista. Then came MS's new-with-Win10 toolset that does not support XP. > Or is the > decision to not support Windows XP based on Microsoft ending the > product support lifecycle for XP? As I explained in another message, it was the other way around, in a sense. As long as MS supported XP, Windows CPython devs either refrained from using new not-in-xp features or maintained old workarounds. The has been more or less the same policy for other versions of Windows. -- Terry Jan Reedy From steve at pearwood.info Sun Nov 1 20:19:57 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 02 Nov 2015 12:19:57 +1100 Subject: UNABLE TO GET IDLE TO RUN References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> <201511011617.tA1GHVKE030820@fido.openend.se> Message-ID: <5636ba40$0$1600$c3e8da3$5496439d@news.astraweb.com> On Mon, 2 Nov 2015 11:07 am, Terry Reedy wrote: > On 11/1/2015 11:17 AM, Laura Creighton wrote: > >> In a message of Mon, 02 Nov 2015 01:27:23 +1100, "Steven D'Aprano" writes >> a reply to Michael Overtoon: > > He was actually responding to my proposal to warn about duplicating > stdlib names when saving-as. > >>> Users are inclined to ignore alerts, dialogs and error messages, and >>> applications try very, very hard to reinforce that tendency. >> >> http://ux.stackexchange.com/questions/4518/should-alert-boxes-be-avoided-at-any-cost > > I read this and at least some of the concerns do not apply. > > * IDLE does not spam users with alerts. IDLE might not, but they will be using a computer that does. And frankly, I don't believe that users don't read alerts because they are spammed by them. I've seen far too many new computer users who have not had time to get jaded by excessive alerts click through without reading. Certainly the excessive use of warnings makes the problem worse, teaching even experienced users to ignore them. But that's not where the problem starts. We all agree on the nature of the problem, we all agree that the evidence from systematic UI testing is that the general solution proposed ("put up a warning dialog") is likely to be pointless, and yet some of us are sure that the evidence doesn't apply in this case, this case is special. I don't believe it is. [...] >>> Good to see that IDLE is going to continue that fine old tradition of >>> degrading usability for the sake of a quick and easy non-solution to a >>> problem. > > Doing nothing is also a non-solution. Some people may argue that Python has survived for over two decades with this problem, so that "do nothing" is a perfectly valid thing to do. But I haven't argued for "do nothing". I've offered two solutions: - Python as a whole should move "" from the start of sys.path to the end (or at least the middle, after the stdlib) so as to avoid accidental shadowing. - Even if Python doesn't do this, IDLE could do it, and could do it immediately, without waiting for a new point release. IDLE is an application, an IDE, not the Python interpreter, and like IPython or any other IDE, it is perfectly entitled to behave differently from the vanilla Python interpreter. I argue that IDLE is entitled to do anything which the site module or PYTHONSTARTUP file could do, such as pre-import the most common modules, or change the order of sys.path. As maintainer, you're entitled to reject my solution. But it is a potential solution, and I believe it will come closer to an actual fix for the shadowing issue than raising warnings. -- Steven From steve at pearwood.info Sun Nov 1 20:32:23 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 02 Nov 2015 12:32:23 +1100 Subject: installer user interface glitch ? References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> Message-ID: <5636bd2a$0$1616$c3e8da3$5496439d@news.astraweb.com> On Mon, 2 Nov 2015 03:43 am, Chris Angelico wrote: > Remember, people can click a direct download link > *on the python.org front page* and be immediately downloading Python 2 > or 3 for the OS that the browser announces. Where would you put the > big fat noisy warning? Maybe the website shouldn't do that then. Seriously, if the browser announces Windows XP, it's probably not a good idea to download a version which is known not to work with XP... -- Steven From rosuav at gmail.com Sun Nov 1 20:50:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 12:50:42 +1100 Subject: installer user interface glitch ? In-Reply-To: <5636bd2a$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> <5636bd2a$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Nov 2, 2015 at 12:32 PM, Steven D'Aprano wrote: > On Mon, 2 Nov 2015 03:43 am, Chris Angelico wrote: > >> Remember, people can click a direct download link >> *on the python.org front page* and be immediately downloading Python 2 >> or 3 for the OS that the browser announces. Where would you put the >> big fat noisy warning? > > Maybe the website shouldn't do that then. > > Seriously, if the browser announces Windows XP, it's probably not a good > idea to download a version which is known not to work with XP... Maybe Laura would know how plausible this is, but... I expect most people who go to the front page are looking for the "one most obvious download". (Okay, we have two - 2.7 and 3.x - but leaving that aside.) There's detection of what your OS is, which then selects an appropriate download file; it'd be really cool if a browser UA that represents XP would cause the link to point to 3.4 instead of 3.5. Or would that cause more confusion than it solves? ChrisA From rosuav at gmail.com Sun Nov 1 21:08:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Nov 2015 13:08:10 +1100 Subject: UNABLE TO GET IDLE TO RUN In-Reply-To: <5636ba40$0$1600$c3e8da3$5496439d@news.astraweb.com> References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <201510230905.t9N95FPe025528@fido.openend.se> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> <201511011617.tA1GHVKE030820@fido.openend.se> <5636ba40$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Nov 2, 2015 at 12:19 PM, Steven D'Aprano wrote: > - Python as a whole should move "" from the start of sys.path to the end (or > at least the middle, after the stdlib) so as to avoid accidental shadowing. > > - Even if Python doesn't do this, IDLE could do it, and could do it > immediately, without waiting for a new point release. IDLE is an > application, an IDE, not the Python interpreter, and like IPython or any > other IDE, it is perfectly entitled to behave differently from the vanilla > Python interpreter. IDLE consists of two things: its own code, and a means of running user code. Conceptually, they're entirely separate - it's almost a coincidence that they happen to be using the same language. If the IDE wants to protect itself against running unexpected userland modules, it is absolutely allowed to do that, same as any other application is; it can remove "" from sys.path, or reposition it, or add traps to see where some_module.__file__ is, or anything at all. But when it's running user code, it should be semantically as close as possible to the command-line interpreter as it can be. If I type "import foo" into IDLE's interactive mode, or if I type "import foo" into IDLE's editor and hit Run, or if I type "import foo" into the standard command-line interactive interpreter, I expect that they'll all find the same module, and if they don't, it's an extra debugging hassle. When I'm debugging a script, I'll often try some parts of it in an interactive interpreter, and it should not matter whether I pick "python", or Idle, or ipython in a terminal window, or the in-browser ipython notebook, etc, etc, etc. I want to be able to keep the differences *in my head*. There are already a few; interactive interpreters... * Can't have blank lines in class/function definitions; * Automatically print non-None expression results; * Recover from exceptions by returning to the main loop, rather than bombing the whole module load * Warnings are enabled by default AFAIK, all of these are consistent across _all_ interactive Python interpreters. (The second one is configurable, but it's always the default.) I do *not* want to have to add "Local modules do not shadow stdlib modules" as an additional difference, particularly not in one specific interface and not others. So yes, technically IDLE is allowed to behave differently. But I would hope this is extremely rare and VERY solidly justified (eg "Python 3.6 will do it this way, and IDLE is a bit ahead of the curve"). ChrisA From chris at simplistix.co.uk Sun Nov 1 23:08:46 2015 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 1 Nov 2015 22:08:46 -0600 Subject: testfixtures 4.4.0 Released! Message-ID: <5636E1CE.7080500@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 4.4.0. This is a feature release that adds the following: - Add support for labelling the arguments passed to compare(). - Allow expected and actual keyword parameters to be passed to compare(). - Fix "TypeError: unorderable types" when compare() found multiple differences in sets and dictionaries on Python 3. - Add official support for Python 3.5. - Drop official support for Python 2.6. Thanks to Daniel Fortunov for the initial ideas for explicit expected and actual support in compare(). The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: 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 -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From amnaee at gmail.com Mon Nov 2 00:30:19 2015 From: amnaee at gmail.com (amnaee at gmail.com) Date: Sun, 1 Nov 2015 21:30:19 -0800 (PST) Subject: Problem in implementing Romania Map using Paython Script Message-ID: <24e4a4ca-59d1-433e-a0ed-fa04fc23041d@googlegroups.com> Dear all; I want to code algorithm in Python for driving from Arad to Bucharest as quickly as possible. I formulated the problem in python as following : 1- States : Various cities. 2- Actions : Drive distances between different cities. 3- Goal : To be in Bucharest. class Problem: def __init__(self, initial, goal=None): self.initial = initial self.goal = goal def goalTest(self, state): return state == self.goal But the problem now is with Roaming and Node classifications : class RoamingProblem(Problem): def successors(self, state): Q1 : How I can complete the class RoamingProblem (Problem) and include action costs. I think its related in some how in using a new city map ????... And how I can return the cost next state ????... list of tuples [(action1,[(action1, successor-state1, cost1, action2, successor-state2, cost2 ...)] Q2 : For the class node class Node: def __init__(self, state, parent=None, action=None, pathCost=0): self.state = state self.parent = parent self.action = action self.pathCost = pathCost update(state,parent,action,pathcost,depth) def expand(self, problem): return [Node(next,self,action,problem,....]. THE last line How I can return : list of Node objects, one for each successor state, parent of the created nodes is self ????.... I need a help in completing the Class Roaming problem using Euclidean function , Completing the Class Node ..... And def treesearch and graph search problem ????? Waiting for reply ???? From ben+python at benfinney.id.au Mon Nov 2 00:45:50 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2015 16:45:50 +1100 Subject: Problem in implementing Romania Map using Paython Script References: <24e4a4ca-59d1-433e-a0ed-fa04fc23041d@googlegroups.com> Message-ID: <85ziyxkl81.fsf@benfinney.id.au> amnaee at gmail.com writes: > I need a help in completing the Class Roaming problem using Euclidean > function , Completing the Class Node ..... I think you need to research how to solve this algorithm, and only *then* think about how to code it in Python. Is this a homework assignment? > And def treesearch and graph search problem ????? > > Waiting for reply ???? You may not intend it, but adding multiple question marks communicates urgent insistence, and is rather rude in a request to a community of volunteers. -- \ ?I may disagree with what you say, but I will defend to the | `\ death your right to mis-attribute this quote to Voltaire.? | _o__) ?Avram Grumer, rec.arts.sf.written, 2000-05-30 | Ben Finney From mail at timgolden.me.uk Mon Nov 2 01:16:25 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 2 Nov 2015 06:16:25 +0000 Subject: python doesn't install In-Reply-To: <5636A98C.6030203@comcast.net> References: <5636A98C.6030203@comcast.net> Message-ID: <5636FFB9.8040703@timgolden.me.uk> On 02/11/2015 00:08, Daniel Joffe wrote: > WinXP...32 bits...professional > > I keep getting message > > > note also that there is no place on the install box to start...you just > click somewhere, and the install started. > I'm afraid you've been bitten by the fact that we no longer support Windows XP and haven't communicated this very well. We have a new version of the installer almost ready for release which indicates this much earlier (and more obviously). I'm afraid if you're on XP you're limited to Python 3.4 and earlier, all of which are perfectly usable I'm happy to say! TJG From auriocus at gmx.de Mon Nov 2 01:45:32 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 2 Nov 2015 07:45:32 +0100 Subject: Problem in implementing Romania Map using Paython Script In-Reply-To: <24e4a4ca-59d1-433e-a0ed-fa04fc23041d@googlegroups.com> References: <24e4a4ca-59d1-433e-a0ed-fa04fc23041d@googlegroups.com> Message-ID: Am 02.11.15 um 06:30 schrieb amnaee at gmail.com: > Dear all; > > I want to code algorithm in Python for driving from Arad to Bucharest as quickly as possible. > It sounds a lot like a homework problem. If so, look into your notes for "Dijkstra algorithm", or "A* algorithm". If not, look for a library that does routing or make an API call to graphhopper, Google maps or similar. Routing (esp. fast routing) is a non-trivial problem. Christian From tjreedy at udel.edu Mon Nov 2 02:46:45 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Nov 2015 02:46:45 -0500 Subject: UNABLE TO GET IDLE TO RUN In-Reply-To: <87twp5z0lf.fsf@nightsong.com> References: <1501485483.555358.1445441061800.JavaMail.yahoo@mail.yahoo.com> <56310743.3070708@gmail.com> <563180CB.5080303@gmail.com> <201510290753.t9T7rZqR032272@fido.openend.se> <5A7F323C-ED4A-4CCA-A392-2C6F64EA6A6F@xs4all.nl> <201510301629.t9UGTY2i013568@fido.openend.se> <5636214b$0$1617$c3e8da3$5496439d@news.astraweb.com> <201511011617.tA1GHVKE030820@fido.openend.se> <87twp5z0lf.fsf@nightsong.com> Message-ID: On 11/1/2015 7:50 PM, Paul Rubin wrote: > Terry Reedy writes: >> * 'Save-as' is not part of the regular workflow. It is done once per >> file. Experienced users who know to avoid stdlib names will not see >> the messages unless they accidentally duplicate one -- which is >> possible because there are now so many. I personally would like being >> warned. > > I think there is something to be said for this. I've gotten confused a > few times by accidentally re-using a stdlib name, and I'm experienced. > > One thing I wish in IDLE is for ctrl-N (or some alternate) to prompt > for a filename immediately: opening a new window, then writing code in > it, and then using Save-as seems unnatural to me. That would also be > a good time to validate the filename, by searching sys.path or whatever. Given that one has to save-as before running, this seems somewhat sensible. There is also request to be able to run 'Untitled' windows. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon Nov 2 02:52:55 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 02 Nov 2015 18:52:55 +1100 Subject: Unbuffered stderr in Python 3 Message-ID: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> In Python 2, stderr is unbuffered. In most other environments (the shell, C...) stderr is unbuffered. It is usually considered a bad, bad thing for stderr to be buffered. What happens if your application is killed before the buffer fills up? The errors in the buffer will be lost. So how come Python 3 has line buffered stderr? And more importantly, how can I turn buffering off? I don't want to use the -u unbuffered command line switch, because that effects stdout as well. I'm happy for stdout to remain buffered. Here is the function I'm using to test this in in the interactive interpreter: import sys, time def test(): # Simulate a slow calculation that prints status and/or error # messages to stderr. for i in range(10): print(i, file=sys.stderr, end="") time.sleep(2) print("", file=sys.stderr) Running it pauses for 20 seconds, then displays "0123456789" in one go. What I expect is to see the digits arrive individually. I tried this: py> sys.stderr.line_buffering = False Traceback (most recent call last): File "", line 1, in AttributeError: readonly attribute Next I tried this: py> sys.stderr.buffer.line_buffering = False which succeeded, but has no effect on print: it still buffers. -- Steve From df at see.replyto.invalid Mon Nov 2 03:28:58 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Mon, 02 Nov 2015 08:28:58 +0000 Subject: python doesn't install References: <5636A98C.6030203@comcast.net> Message-ID: Tim Golden wrote: >I'm afraid you've been bitten by the fact that we no longer support >Windows XP and haven't communicated this very well. We have a new >version of the installer almost ready for release which indicates this >much earlier (and more obviously). I'm afraid if you're on XP you're >limited to Python 3.4 and earlier, all of which are perfectly usable I'm >happy to say! I've been reading the comments about Python and XP on this group -- and I must say that I'm thinking: Doesn't pretty much every other Windows software package tell you the minimum requirements -- because that's the first thing you'd want to know? So I've Googled for "python 3.5 minimum requirements": 1st hit: "Using Python on Windows -- Python 3.5.0 documentation" and a few paragraphs down that page there's: "Python on XP -- 7 Minutes to Hello World by Richard Dooling, 2006" which says how easy it is to install on XP. 2nd hit: "Download Python -- Python.org" There's download links but nothing about XP, but there's a link for "Information about specific ports" -- so click on "Windows" and no information actually, just more download links. 3rd hit: "Welcome to Python.org" There's download links and no info about minimum requirements. And so on down the page of Google hits. Yes, I've read the justifications. Why list all the non-supported OSs? And the explanation about each version of Python being supported just for the supported versions of Windows upon its release is in the documentation -- somewhere. But it still seems to me that stating the minimum requirements in a place that people would tend to look for it is a... minimum requirement. If the developers really are determined not to mention specific versions of Windows (If it was me, I'd have probably mentioned that the most recent version required Vista somewhere on the download page), then maybe adding the comment about matching the release date of Python to the supported versions of Windows to the download pages would give people some sort of clue as to what's going on. From mail at timgolden.me.uk Mon Nov 2 03:32:46 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 2 Nov 2015 08:32:46 +0000 Subject: python doesn't install In-Reply-To: <5636FFB9.8040703@timgolden.me.uk> References: <5636A98C.6030203@comcast.net> <5636FFB9.8040703@timgolden.me.uk> Message-ID: <56371FAE.4080903@timgolden.me.uk> On 02/11/2015 06:16, Tim Golden wrote: > On 02/11/2015 00:08, Daniel Joffe wrote: >> WinXP...32 bits...professional >> >> I keep getting message >> >> >> note also that there is no place on the install box to start...you just >> click somewhere, and the install started. >> > > I'm afraid you've been bitten by the fact that we no longer support > Windows XP and haven't communicated this very well. We have a new > version of the installer almost ready for release which indicates this > much earlier (and more obviously). I'm afraid if you're on XP you're > limited to Python 3.4 and earlier, all of which are perfectly usable I'm > happy to say! Sorry, I omitted to say that you can download the latest Python 3.4 from here: https://www.python.org/downloads/release/python-343/ TJG From kwpolska at gmail.com Mon Nov 2 04:03:31 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Mon, 2 Nov 2015 10:03:31 +0100 Subject: python doesn't install In-Reply-To: References: <5636A98C.6030203@comcast.net> Message-ID: On 2 November 2015 at 09:28, Dave Farrance wrote: > Yes, I've read the justifications. Why list all the non-supported OSs? > And the explanation about each version of Python being supported just > for the supported versions of Windows upon its release is in the > documentation -- somewhere. But it still seems to me that stating the > minimum requirements in a place that people would tend to look for it is > a... minimum requirement. > > If the developers really are determined not to mention specific versions > of Windows (If it was me, I'd have probably mentioned that the most > recent version required Vista somewhere on the download page), then > maybe adding the comment about matching the release date of Python to > the supported versions of Windows to the download pages would give > people some sort of clue as to what's going on. > -- > https://mail.python.org/mailman/listinfo/python-list This could be resolved in one line of HTML or reST. Windows XP is still in use, and it was supported one minor version ago. Surely it wouldn?t hurt to add a ?Warning: Windows XP is ancient, and Python 3.5 does not support it ? upgrade to a newer OS or use 3.4.3 instead? notice to the download page? -- Chris Warrick PGP: 5EAAEA16 From wolfgang.maier at biologie.uni-freiburg.de Mon Nov 2 05:48:32 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 2 Nov 2015 11:48:32 +0100 Subject: Unbuffered stderr in Python 3 In-Reply-To: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02.11.2015 08:52, Steven D'Aprano wrote: > In Python 2, stderr is unbuffered. > > In most other environments (the shell, C...) stderr is unbuffered. > > It is usually considered a bad, bad thing for stderr to be buffered. What > happens if your application is killed before the buffer fills up? The errors > in the buffer will be lost. > > So how come Python 3 has line buffered stderr? And more importantly, how can > I turn buffering off? > I cannot comment on your first question, but unbuffered writing to sys.stderr is possible just like for any other buffered file object. You just call its flush method after writing. Since Python3.3, the print function has a flush keyword argument that accepts a boolean and lets you do just this. Rewrite your example as: import sys, time def test(): # Simulate a slow calculation that prints status and/or error # messages to stderr. for i in range(10): _print(i, file=sys.stderr, end="", flush=True) time.sleep(2) print("", file=sys.stderr) and it should do what you want. Before Python 3.3, if I needed an unbuffered print function, I used a wrapper to call flush for me, so instead of: > > import sys, time > > def test(): > # Simulate a slow calculation that prints status and/or error > # messages to stderr. > for i in range(10): > print(i, file=sys.stderr, end="") > time.sleep(2) > print("", file=sys.stderr) > I'd use (and still do this if I need compatibility with 3.2): import sys, time def _print (*args, **kwargs): file = kwargs.get('file', sys.stdout) print(*args, **kwargs) file.flush() def test(): # Simulate a slow calculation that prints status and/or error # messages to stderr. for i in range(10): _print(i, file=sys.stderr, end="") time.sleep(2) print("", file=sys.stderr) Best, Wolfgang From wolfgang.maier at biologie.uni-freiburg.de Mon Nov 2 05:54:44 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 2 Nov 2015 11:54:44 +0100 Subject: Unbuffered stderr in Python 3 In-Reply-To: References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02.11.2015 11:48, Wolfgang Maier wrote: > > Since Python3.3, the print function has a flush keyword argument that > accepts a boolean and lets you do just this. Rewrite your example as: > > import sys, time > > def test(): > # Simulate a slow calculation that prints status and/or error > # messages to stderr. > for i in range(10): > _print(i, file=sys.stderr, end="", flush=True) > time.sleep(2) > print("", file=sys.stderr) > > and it should do what you want. sorry for this mess (copy pasted from the wrong source). The code should be: def test(): # Simulate a slow calculation that prints status and/or error # messages to stderr. for i in range(10): print(i, file=sys.stderr, end="", flush=True) time.sleep(2) print("", file=sys.stderr) From tjreedy at udel.edu Mon Nov 2 06:08:31 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Nov 2015 06:08:31 -0500 Subject: Problem in implementing Romania Map using Paython Script In-Reply-To: <85ziyxkl81.fsf@benfinney.id.au> References: <24e4a4ca-59d1-433e-a0ed-fa04fc23041d@googlegroups.com> <85ziyxkl81.fsf@benfinney.id.au> Message-ID: On 11/2/2015 12:45 AM, Ben Finney wrote: > amnaee at gmail.com writes: > >> I need a help in completing the Class Roaming problem using Euclidean >> function , Completing the Class Node ..... > > I think you need to research how to solve this algorithm, and only > *then* think about how to code it in Python. > > Is this a homework assignment? Norquist's AI book uses the Romania map to illustrate search problems. Whether this is a class assignment is a different matter, but OP should mention it either way. -- Terry Jan Reedy From danieljoffe at comcast.net Mon Nov 2 07:35:52 2015 From: danieljoffe at comcast.net (Daniel Joffe) Date: Mon, 2 Nov 2015 06:35:52 -0600 Subject: same problem even after repair Message-ID: <563758A8.7010207@comcast.net> From beliavsky at aol.com Mon Nov 2 08:15:17 2015 From: beliavsky at aol.com (beliavsky at aol.com) Date: Mon, 2 Nov 2015 05:15:17 -0800 (PST) Subject: Python 2 vs Python 3 for teaching In-Reply-To: References: Message-ID: I think Python 2.x is still used more than Python 3.x in scientific computing. The Python books I have in this area, such as "Python for Finance: Analyze Big Financial Data" and "Python for Data Analysis", still use Python 2.x . An aspiring computational scientist, data scientist, or financial quant may still be better off learning Python 2.x but using print(x) rather than print x and doing other things to future-proof his code. From input/ldompeling at casema.nl Mon Nov 2 08:29:04 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Mon, 02 Nov 2015 13:29:04 GMT Subject: GoPiGo script References: Message-ID: I tried to use def loop(): now for to restart the script. but its only restart "fwd()" print ("forward 1x") and then stop. It does not look further for the if function. Is there another way to restart this script ? I also tried with (while True:) but that does nothing. Thanks ------------------------------------------------------------------------------- from gopigo import * import time set_right_speed(150) set_left_speed(105) enable_servo mindist = 80 servo(90) def loop(): fwd() print ("forward 1x") time.sleep(2) stop() if mindist > us_dist(15): bwd() print ("backward 1x",us_dist(15)) time.sleep(2) left_rot() print("left rot",us_dist(15)) time.sleep(3) stop() if mindist < us_dist(15): fwd() print("forward 2x",us_dist(15)) time.sleep(2) stop() #for x in range(3): if mindist > us_dist(15): bwd() print("backward 2x",us_dist(15)) time.sleep(2) stop() right() else: fwd() print("forward else",us_dist(15)) time.sleep(4) stop() if mindist > us_dist(15): bwd() print("backward 3x") time.sleep(2) stop() left_rot() print("left rot") time.sleep(1) stop() mindist = 80 loop() In reply to "Peter Pearson" who wrote the following: > On Fri, 30 Oct 2015 16:58:16 GMT, input/ldompeling at casema.nl wrote: > > The GoPiGo is a little robot on wheels. > > > > I want that this script restart when its ends. > > I tried with "while True"and"return"and also "continue" > > But those functions gives me errors. > > What for function else can I use to restart this script. > > > [snip] > > > > from gopigo import * > > import time > > > > > > set_right_speed(150) > > set_left_speed(105) > > > > while True: > > Is this the "while True" that gave you errors? I think it > should, since a "while" should be followed by an indented block > of code. Perhaps you should use this "while True" to replace > the "for x in range(3)" near the bottom. > > > #def test(): > > enable_servo() > > mindist = 80 > > servo(90) > > fwd()#wheels go forward > > print ("forward1x") > > #time.sleep(5) > > #stop() > > > > if mindist > us_dist(15): > > #enc_tgt(1,1,72) > > bwd()#wheels go backward > > print ("backward1x",us_dist(15)) > > time.sleep(2) > > left_rot()#wheels rotate left > > print("left rot",us_dist(15)) > > time.sleep(3) > > stop() > > > > if mindist < us_dist(15): > > #enc_tgt(1,1,72) > > fwd()#wheels go forward > > print("forward2x",us_dist(15)) > > time.sleep(2) > > stop() > > > > for x in range(3): > > > > if mindist > us_dist(15): > > bwd()#wheels go backward > > print("backward2x",us_dist(15)) > > In future questions, it might help if you explained which of these > print statements you would like to see executed how many times. > > -- > To email me, substitute nowhere->runbox, invalid->com. -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From hakugin.gin at gmail.com Mon Nov 2 08:45:09 2015 From: hakugin.gin at gmail.com (hakugin.gin at gmail.com) Date: Mon, 2 Nov 2015 05:45:09 -0800 (PST) Subject: GoPiGo script In-Reply-To: References: Message-ID: <7bcb9d61-e610-47e3-9cba-35eba075e993@googlegroups.com> On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld... at casema.nl wrote: > I tried to use def loop(): now for to restart the script. > but its only restart "fwd()" print ("forward 1x") and then stop. > It does not look further for the if function. > Is there another way to restart this script ? > I also tried with (while True:) but that does nothing. > > Thanks Try this: (hopefully the indentation is preserved) from gopigo import * from time import sleep # Boolean variable for the "while" loop KEEP_GOING = True enable_servo() mindist = 80 servo(90) set_right_speed(150) set_left_speed(105) def MainLoop(): # A check statement can be added to set KEEP_GOING to False # and allow the function to end while KEEP_GOING: mindist = 90 server(90) fwd() print("forward1x") if mindist > us_dist(15): bwd() print("backward1x",us_dist(15) sleep(2) left_rot() print("left rot",us_dist(15)) sleep(3) stop() if mindist < us_dist(15): fwd() print("forward2x",us_dist(15)) time.sleep(2) stop() # This is a simple check to determine if the script was run by itself # or if it was imported by another script. If it was imported it will # fail this check and not run the code but will allow access to the # function defined above. if __name__ == '__main__': MainLoop() - Mike From hakugin.gin at gmail.com Mon Nov 2 08:49:27 2015 From: hakugin.gin at gmail.com (hakugin.gin at gmail.com) Date: Mon, 2 Nov 2015 05:49:27 -0800 (PST) Subject: GoPiGo script In-Reply-To: <7bcb9d61-e610-47e3-9cba-35eba075e993@googlegroups.com> References: <7bcb9d61-e610-47e3-9cba-35eba075e993@googlegroups.com> Message-ID: <197fe872-0501-4ce8-a273-5220d4527c1f@googlegroups.com> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug... at gmail.com wrote: > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld... at casema.nl wrote: > > I tried to use def loop(): now for to restart the script. > > but its only restart "fwd()" print ("forward 1x") and then stop. > > It does not look further for the if function. > > Is there another way to restart this script ? > > I also tried with (while True:) but that does nothing. > > > > Thanks > > > Ignore that last suggestion... between auto correct and other things there are some issues with it. Try this instead: from gopigo import * from time import sleep # Boolean variable for the "while" loop KEEP_GOING = True enable_servo() mindist = 80 servo(90) set_right_speed(150) set_left_speed(105) def MainLoop(): # A check statement can be added to set KEEP_GOING to False # and allow the function to end while KEEP_GOING: fwd() print("forward1x") if mindist > us_dist(15): bwd() print("backward1x",us_dist(15) sleep(2) left_rot() print("left rot",us_dist(15)) sleep(3) stop() if mindist < us_dist(15): fwd() print("forward2x",us_dist(15)) time.sleep(2) stop() # This is a simple check to determine if the script was run by itself # or if it was imported by another script. If it was imported it will # fail this check and not run the code but will allow access to the # function defined above. if __name__ == '__main__': MainLoop() - Mike From rosuav at gmail.com Mon Nov 2 09:10:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Nov 2015 01:10:19 +1100 Subject: Python 2 vs Python 3 for teaching In-Reply-To: References: Message-ID: On Tue, Nov 3, 2015 at 12:15 AM, beliavsky--- via Python-list wrote: > I think Python 2.x is still used more than Python 3.x in scientific computing. The Python books I have in this area, such as "Python for Finance: Analyze Big Financial Data" and "Python for Data Analysis", still use Python 2.x . An aspiring computational scientist, data scientist, or financial quant may still be better off learning Python 2.x but using print(x) rather than print x and doing other things to future-proof his code. > That doesn't mean that Python 3 *can't* be used. Far as I know, all the key libraries (numpy, pandas, statsmodels, scipy) are available for Python 3 as well. Recommending the use of Python 2 simply because all the books you have teach Python 2 is a purely circular argument. But yes. If you're going to use Py2, aim for the common subset. Good Py2 code is a lot more similar to good Py3 code than an enumeration of language-level differences would suggest. ChrisA From input/ldompeling at casema.nl Mon Nov 2 09:28:17 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Mon, 02 Nov 2015 14:28:17 GMT Subject: GoPiGo script References: <197fe872-0501-4ce8-a273-5220d4527c1f@googlegroups.com> Message-ID: <5qKZx.1282$u_1.105@fx05.am1> He mike, Thank you or making this script. Only I get errors for sleep. I also tried to change it to time.sleep() but that also gives errors. File "test05.py", line 23 sleep(2) ^ SyntaxError: invalid syntax ------------------------------------------------------------------------------- In reply to "hakugin.gin at gmail.com" who wrote the following: > On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug... at gmail.com wrote: > > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld... at casema.nl > > wrote: > > > I tried to use def loop(): now for to restart the script. > > > but its only restart "fwd()" print ("forward 1x") and then stop. > > > It does not look further for the if function. > > > Is there another way to restart this script ? > > > I also tried with (while True:) but that does nothing. > > > > > > Thanks > > > > > > > > Ignore that last suggestion... between auto correct and other things there are > some issues with it. > > Try this instead: > > from gopigo import * > from time import sleep > > # Boolean variable for the "while" loop > KEEP_GOING = True > > enable_servo() > mindist = 80 > servo(90) > > set_right_speed(150) > set_left_speed(105) > > def MainLoop(): > # A check statement can be added to set KEEP_GOING to False > # and allow the function to end > while KEEP_GOING: > fwd() > print("forward1x") > if mindist > us_dist(15): > bwd() > print("backward1x",us_dist(15) > sleep(2) > left_rot() > print("left rot",us_dist(15)) > sleep(3) > stop() > if mindist < us_dist(15): > fwd() > print("forward2x",us_dist(15)) > time.sleep(2) > stop() > > # This is a simple check to determine if the script was run by itself > # or if it was imported by another script. If it was imported it will > # fail this check and not run the code but will allow access to the > # function defined above. > if __name__ == '__main__': > MainLoop() > > - Mike -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From arimfrexdrapuse at gmail.com Mon Nov 2 09:28:37 2015 From: arimfrexdrapuse at gmail.com (Gabe Clark) Date: Mon, 2 Nov 2015 09:28:37 -0500 Subject: help Message-ID: i am currently running python 3.5 in my programming class and when ever i go to open one of my saved files or a file saved by some one else this new tab pops up and says modify, repair, or uninstall i have uninstalled and repaired it multiple times to no success please help From nulla.epistola at web.de Mon Nov 2 09:32:43 2015 From: nulla.epistola at web.de (Sibylle Koczian) Date: Mon, 2 Nov 2015 15:32:43 +0100 Subject: same problem even after repair In-Reply-To: <563758A8.7010207@comcast.net> References: <563758A8.7010207@comcast.net> Message-ID: <5637740B.6070104@web.de> Am 02.11.2015 um 13:35 schrieb Daniel Joffe: > Didn't you see the answers to your first posting? All of them earlier than this. Sibylle From nulla.epistola at web.de Mon Nov 2 09:32:43 2015 From: nulla.epistola at web.de (Sibylle Koczian) Date: Mon, 2 Nov 2015 15:32:43 +0100 Subject: same problem even after repair In-Reply-To: <563758A8.7010207@comcast.net> References: <563758A8.7010207@comcast.net> Message-ID: <5637740B.6070104@web.de> Am 02.11.2015 um 13:35 schrieb Daniel Joffe: > Didn't you see the answers to your first posting? All of them earlier than this. Sibylle From input/ldompeling at casema.nl Mon Nov 2 09:32:57 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Mon, 02 Nov 2015 14:32:57 GMT Subject: GoPiGo script References: Message-ID: Thank you for the explanation for it. I must tell you that i yust beginning with python. I bought the book beginning programming with python. In reply to "Dennis Lee Bieber" who wrote the following: > On Mon, 02 Nov 2015 13:29:04 GMT, input/ldompeling at casema.nl declaimed the > following: > > > I tried to use def loop(): now for to restart the script. > > but its only restart "fwd()" print ("forward 1x") and then stop. > > > def loop(): > > fwd() > > print ("forward 1x") > > time.sleep(2) > > stop() > > > > if mindist > us_dist(15): > > Which is exactly what you told it to do. You have defined a function > containing four statements: fwd(), print(), sleep(), and stop(); after > executing the stop the function will return to where it was called -- the > end of your program. > > All of your"if" statements will be executed after "loop" is defined > (but not executed) and before the call to "loop" at the bottom. They are > NOT part of "loop". Please reread the Python language reference manual, > focusing on the part that describes indentation and block structuring. > > > > loop() > > > > Also, just calling something "loop" does not make it a loop. This > function will be called just one time and then the program will exit. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From ian.g.kelly at gmail.com Mon Nov 2 09:49:23 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Nov 2015 07:49:23 -0700 Subject: help In-Reply-To: References: Message-ID: On Nov 2, 2015 7:31 AM, "Gabe Clark" wrote: > > i am currently running python 3.5 in my programming class and when ever i > go to open one of my saved files or a file saved by some one else this new > tab pops up and says modify, repair, or uninstall i have uninstalled and > repaired it multiple times to no success please help Check the Windows file association for .py files (you are saving your files with the .py extension, right?). From the description it sounds like .py has somehow become associated with the Python installer rather than the Python interpreter. If you're familiar with the command line, you can run the script by running Python specifically and passing the script as a command-line argument. From hakugin.gin at gmail.com Mon Nov 2 10:19:09 2015 From: hakugin.gin at gmail.com (hakugin.gin at gmail.com) Date: Mon, 2 Nov 2015 07:19:09 -0800 (PST) Subject: GoPiGo script In-Reply-To: <5qKZx.1282$u_1.105@fx05.am1> References: <197fe872-0501-4ce8-a273-5220d4527c1f@googlegroups.com> <5qKZx.1282$u_1.105@fx05.am1> Message-ID: On Monday, November 2, 2015 at 9:28:35 AM UTC-5, input/ld... at casema.nl wrote: > He mike, > > Thank you or making this script. > Only I get errors for sleep. > I also tried to change it to time.sleep() but that also gives errors. > > File "test05.py", line 23 > sleep(2) > ^ > SyntaxError: invalid syntax > ------------------------------------------------------------------------------- > And this is why I shouldn't code while tired hahaha... I reviewed the code I submitted and found a couple of other errors. If you are changing the "sleep()" lines to "time.sleep()" you will need to change the line "from time import sleep" to "import time", otherwise you will most likely encounter something like: Traceback (most recent call last): File "", line 1, in NameError: name 'time' is not defined Since you are just beginning with Python I would suggest reading various entry level books such as Python 101 by Mike Driscoll, which I have read and own. I am not Mike Driscoll, but his book and blog, http://www.blog.pythonlibrary.org/ have been extremely helpful. There are MANY resources available for learning the Python programming language out there, including https://wiki.python.org/moin/BeginnersGuide From python at mrabarnett.plus.com Mon Nov 2 10:21:16 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 2 Nov 2015 15:21:16 +0000 Subject: GoPiGo script In-Reply-To: <5qKZx.1282$u_1.105@fx05.am1> References: <197fe872-0501-4ce8-a273-5220d4527c1f@googlegroups.com> <5qKZx.1282$u_1.105@fx05.am1> Message-ID: <56377F6C.1040309@mrabarnett.plus.com> On 2015-11-02 14:28, input/ldompeling at casema.nl wrote: > He mike, > > Thank you or making this script. > Only I get errors for sleep. > I also tried to change it to time.sleep() but that also gives errors. > > File "test05.py", line 23 > sleep(2) > ^ > SyntaxError: invalid syntax > ------------------------------------------------------------------------------- > The previous line is missing a ")"; it should end with two of them, not just one. > In reply to "hakugin.gin at gmail.com" who wrote the following: > >> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug... at gmail.com wrote: >> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld... at casema.nl >> > wrote: >> > > I tried to use def loop(): now for to restart the script. >> > > but its only restart "fwd()" print ("forward 1x") and then stop. >> > > It does not look further for the if function. >> > > Is there another way to restart this script ? >> > > I also tried with (while True:) but that does nothing. >> > > >> > > Thanks >> > >> > >> > >> >> Ignore that last suggestion... between auto correct and other things there > are >> some issues with it. >> >> Try this instead: >> >> from gopigo import * >> from time import sleep >> >> # Boolean variable for the "while" loop >> KEEP_GOING = True >> >> enable_servo() >> mindist = 80 >> servo(90) >> >> set_right_speed(150) >> set_left_speed(105) >> >> def MainLoop(): >> # A check statement can be added to set KEEP_GOING to False >> # and allow the function to end >> while KEEP_GOING: >> fwd() >> print("forward1x") >> if mindist > us_dist(15): >> bwd() >> print("backward1x",us_dist(15) >> sleep(2) >> left_rot() >> print("left rot",us_dist(15)) >> sleep(3) >> stop() >> if mindist < us_dist(15): >> fwd() >> print("forward2x",us_dist(15)) >> time.sleep(2) >> stop() >> >> # This is a simple check to determine if the script was run by itself >> # or if it was imported by another script. If it was imported it will >> # fail this check and not run the code but will allow access to the >> # function defined above. >> if __name__ == '__main__': >> MainLoop() >> From hakugin.gin at gmail.com Mon Nov 2 10:30:48 2015 From: hakugin.gin at gmail.com (hakugin.gin at gmail.com) Date: Mon, 2 Nov 2015 07:30:48 -0800 (PST) Subject: GoPiGo script In-Reply-To: References: <197fe872-0501-4ce8-a273-5220d4527c1f@googlegroups.com> <5qKZx.1282$u_1.105@fx05.am1> Message-ID: <5fb9577c-175f-402a-9307-3d9e7f448cc7@googlegroups.com> On Monday, November 2, 2015 at 10:21:46 AM UTC-5, MRAB wrote: > On 2015-11-02 14:28, input/ldom... at casema.nl wrote: > > He mike, > > > > Thank you or making this script. > > Only I get errors for sleep. > > I also tried to change it to time.sleep() but that also gives errors. > > > > File "test05.py", line 23 > > sleep(2) > > ^ > > SyntaxError: invalid syntax > > ------------------------------------------------------------------------------- > > > The previous line is missing a ")"; it should end with two of them, not > just one. > Yep, I shouldn't code while tired... I also forgot to change line 31 from "time.sleep(2)" to "sleep(2)". > > In reply to "haku... at gmail.com" who wrote the following: > > > >> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug... at gmail.com wrote: > >> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld... at casema.nl > >> > wrote: > >> > > I tried to use def loop(): now for to restart the script. > >> > > but its only restart "fwd()" print ("forward 1x") and then stop. > >> > > It does not look further for the if function. > >> > > Is there another way to restart this script ? > >> > > I also tried with (while True:) but that does nothing. > >> > > > >> > > Thanks > >> > > >> > > >> > > >> > >> Ignore that last suggestion... between auto correct and other things there > > are > >> some issues with it. > >> > >> Try this instead: > >> > >> from gopigo import * > >> from time import sleep > >> > >> # Boolean variable for the "while" loop > >> KEEP_GOING = True > >> > >> enable_servo() > >> mindist = 80 > >> servo(90) > >> > >> set_right_speed(150) > >> set_left_speed(105) > >> > >> def MainLoop(): > >> # A check statement can be added to set KEEP_GOING to False > >> # and allow the function to end > >> while KEEP_GOING: > >> fwd() > >> print("forward1x") > >> if mindist > us_dist(15): > >> bwd() > >> print("backward1x",us_dist(15) > >> sleep(2) > >> left_rot() > >> print("left rot",us_dist(15)) > >> sleep(3) > >> stop() > >> if mindist < us_dist(15): > >> fwd() > >> print("forward2x",us_dist(15)) > >> time.sleep(2) > >> stop() > >> > >> # This is a simple check to determine if the script was run by itself > >> # or if it was imported by another script. If it was imported it will > >> # fail this check and not run the code but will allow access to the > >> # function defined above. > >> if __name__ == '__main__': > >> MainLoop() > >> From RobinsW1 at sutterhealth.org Mon Nov 2 10:52:07 2015 From: RobinsW1 at sutterhealth.org (Robinson, Wendy) Date: Mon, 2 Nov 2015 07:52:07 -0800 Subject: Puzzled In-Reply-To: <201511011020.tA1AKYAM004182@fido.openend.se> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> Message-ID: <4CFEDC132D44AC49BA0E91FBEB947119084A742DCC@DCBL123VX.root.sutterhealth.org> [cid:image001.png at 01D11543.5ED11D50] Wendy Robinson Audit Analyst (916) 566-4994 phone NOTICE OF CONFIDENTIALITY: This email is for the sole use of the intended recipient and may contain material that is confidential and protected by state and federal regulations. If you are not the intended recipient please immediately delete it and contact the sender. -----Original Message----- From: Laura Creighton [mailto:lac at openend.se] Sent: Sunday, November 01, 2015 2:21 AM To: Robinson, Wendy Cc: 'python-list at python.org'; lac at openend.se Subject: Re: Puzzled In a message of Fri, 30 Oct 2015 09:20:23 -0700, "Robinson, Wendy" writes: >Hi there, >I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic programs successfully. >This morning I rebooted my computer and can't get a single one to work. The interpreter seems to be fine and the environment variables look correct. But every py file I try to run at the >>> prompt gives me a NameError. > >I tried running the Repair installation, but that did not help. > >Any suggestions? > >Thank you > >Wendy Robinson >Audit Analyst >(916) 566-4994 phone Paste in the Full traceback you get from the console. Also check and see that the console is actually running the 3.5 you installed, and not some other python, like 2.7 you might have lying around. Laura From rurpy at yahoo.com Mon Nov 2 10:53:22 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 2 Nov 2015 07:53:22 -0800 (PST) Subject: installer user interface glitch ? In-Reply-To: References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> <641afbd8-b0b3-4d6b-969f-13cf19c25043@googlegroups.com> Message-ID: <95f13f37-52ec-4aaa-9ece-4e8057148217@googlegroups.com> On Sunday, November 1, 2015 at 2:48:58 PM UTC-7, Laura Creighton wrote: > Actually, adding the XP - do not look here -- > message for several webpages has been on the pydotorg > todo list for more than a week now. > > Not sure why it hasn't happened. > > Thank you for the reminder. You're welcome. And thanks for the reasonable response. Everytime I post to this list it is like stepping into Alice's Wonderland so it is a nice change. From teamprimalforce at gmail.com Mon Nov 2 13:35:55 2015 From: teamprimalforce at gmail.com (Lee Bradley) Date: Mon, 2 Nov 2015 10:35:55 -0800 (PST) Subject: need help understanding a python program Message-ID: http://pastebin.com/ndDYjYe1 The above link takes you to a very interesting way of solving the classic game of Bulls and Cows. It uses an entropy-based decision algorithm. I realize this is asking a lot but I am not yet proficient enough in python to follow some of the methods. There is a fair amount on the internet on both the game and on entropy-based machine learning. I will provide further information if anyone is interested. For now I am looking for someone who can dig into this code and explain what's going on. I understand a lot of it but not enough to really *get it*. From ben+python at benfinney.id.au Mon Nov 2 13:45:15 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2015 05:45:15 +1100 Subject: need help understanding a python program References: Message-ID: <85vb9kkzpg.fsf@benfinney.id.au> Lee Bradley writes: > http://pastebin.com/ndDYjYe1 We much prefer to discuss code in the context of plain text messages right here, because this forum is archived longer than the expected lifetime of content hosted on other services. > For now I am looking for someone who can dig into this code and > explain what's going on. I understand a lot of it but not enough to > really *get it*. Could you discuss your own impressions of it so far, with (parts of) the code pasted here as plain text for context of your commentary? -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From zljubisic at gmail.com Mon Nov 2 14:24:36 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 2 Nov 2015 11:24:36 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? Message-ID: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Let's say that I have the following simple function: def get_html(url): wpage = requests.get(url) return wpage.text How to handle exceptions properly that can arise during execution of the requests.get(url)? If I call this function with try: html = get_html('www.abc.com/index.html') except ConnectionError: service_exception else: continue_with_the_code and ConnectionError exception happens I can handle the exception with service_exception part of the code. I could also put some try/except block in get_html function, but the only purpose why should I do it, is to log the url and re rise the error. Is there any other reason why should I do this? def get_html(url): try: wpage = requests.get(url) except ConnectionError: flog('warning', 'ConnectionError exception', log_except=True) raise return Anyway, whenever I am calling the get_html function I should put it in the try/except block and handle all exceptions. Now which exceptions? Can I know them in advance or I should wait for one to happened and then put it in caller except block? Let's say that I have called get_html function hundred times in try/except block with ConnectionError part, and now I found a new exception that can happen during execution of the requests.get(url) command. What should I do now? Should I put the same except block that handles that new exception in every and each of these hundred calls? I could also handle all exceptions in get_html function, and in case that I am not able to get the html, I can return None. def get_html(url): try: wpage = requests.get(url) except ConnectionError: flog('warning', 'ConnectionError exception', log_except=True) raise except Exception as e: flog("warning", "{0} [wpage = requests.get(url) {1}]".format(e, url), log_except=True) raise else: if wpage.status_code == requests.codes.ok: flog('debug', 'wpage.status_code = %s' % wpage.status_code) html = wpage.text else: flog('debug', 'url = %s' % url) html = None return html Now caller should only check if function has returned something other than None. Caller doesn't need try/except block anymore. Something like this: if get_html('www.abc.com/index.html') is not None: I_am_sure_that_html_has_been_downloaded_correctly Now if I want to catch a new exception, I can catch it in get_html function, which is the only change in the program. I have read some articles that returning None is not a good approach, so I am confused. How to handle exceptions properly in a pythonic way? Regards. From robin.koch at t-online.de Mon Nov 2 14:31:29 2015 From: robin.koch at t-online.de (Robin Koch) Date: Mon, 2 Nov 2015 20:31:29 +0100 Subject: GoPiGo script In-Reply-To: References: Message-ID: Am 02.11.2015 um 15:32 schrieb input/ldompeling at casema.nl: > Thank you for the explanation for it. > I must tell you that i yust beginning with python. > I bought the book beginning programming with python. Have you programming experience with other languages? Well, the very first thing you should have learned is the basic syntax of Python. (That's how a program has to be written to work properly.) And one of those first things is that python code is structured not by braces (like many other programming languages), but by intendation (as mentioned by others before). That means that everything "depending" of a line somehow has to be intended deeper than that line. Those lines are typically lines starting with "if", "for", "while", "def" or other keywords and end with a colon. In your code the ifs and fors (and the following lines) are correctly intended. But you are using the "while" and "def" kind of wrong. Let me give an example (note that the line numbers are only for this posting to prevent funny formating business and to talk about the single lines!): 01 for i in [1,2,3]: 02 print('A') 03 print('B') 04 print('C') The first line (01) starts a loop. (Starting with a for, ending with a colon.) For every entry in the given list "something" is supposed to be repeated. But what is repeated and what isn't? Easy: All following *intended* lines (02-03) are repeated. Line 04 isn't intended and marks the point where the loop ends. The output of the above is: A B A B A B C If we change the code just a tiny bit: 01 for i in [1,2,3]: 02 print('A') 03 print('B') 04 print('C') (Notice, that the only change is the removed whitespace in line 03.) only line 02 is repeated: A A A B C That works also for if and while: 01 if False: 02 print("This isn't printed.") 03 print("This neigther.") 03 print("But this is!") 01 c = 1 02 while c < 10: 03 print(c) 04 c = c*2 05 print("done") prints 1 2 4 8 done And of course those are mixable: 01 for a in [3,5,7]: 02 b = 1 03 while a*b < 10: 04 if a*b % 2 != 0: 05 print(a*b) 06 b = b+1 07 print("Next a") 08 print("done") prints: 3 9 Next a 5 Next a 7 Next a done And this is where your problems seems to be. You start with "while True:" which does start an endless loop. But: As explained it only repeats the lines theat follow and are intended! In your original post the next line isn't intended at all, which is considered an error. In your second attempt you intended only the first 5 lines. So those (and only those) are repeated. The next line ("if mindist > us_dist(15):") wasn't intended and therefore *not* repeated. If you just learning programming with Python you migth want to start with smaller examples to understand the syntax better. Do you understand what the script is supposed to do in every line? -- Robin Koch From gordon at panix.com Mon Nov 2 15:05:36 2015 From: gordon at panix.com (John Gordon) Date: Mon, 2 Nov 2015 20:05:36 +0000 (UTC) Subject: How to handle exceptions properly in a pythonic way? References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: In <4b303213-62e2-42d4-b2f6-4fc1f6025944 at googlegroups.com> zljubisic at gmail.com writes: > Let's say that I have the following simple function: > def get_html(url): > wpage = requests.get(url) > > return wpage.text > How to handle exceptions properly that can arise during execution of the > requests.get(url)? The best way is probably to do nothing at all, and let the caller handle any exceptions. -- 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 ian.g.kelly at gmail.com Mon Nov 2 15:58:39 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Nov 2015 13:58:39 -0700 Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: On Mon, Nov 2, 2015 at 12:24 PM, wrote: > I have read some articles that returning None is not a good approach, so I am confused. > > How to handle exceptions properly in a pythonic way? I'm having a hard time understanding what question you're asking. You have a lot of discussion about where to handle exceptions, but the examples that you show are of logging the the exception and re-raising it, which is a good practice but distinct from handling the exception. Then you seem to be asking about the practice of returning None as an alternative to propagating the exception, but the example you show only returns None in a case where no exception was raised in the first place. None is arguably reasonable to return when it makes sense as a non-exceptional value in the context. For example, if you're looking up a policy that may or may not exist, then your get_policy function might return None to indicate no value. If get_policy fails because of an RPC timeout however, then it needs to raise an exception rather than possibly incorrectly returning "no policy". In comparison, if you're returning something that should always have a value, then you should never return None. In such a case, None would indicate that something went wrong, but it lacks any information about *what* went wrong. An exception, on the other hand, is ideal for carrying that sort of information. Returning None in such a scenario is also risky in that the caller may not be expecting None and may try to treat it as a normal value. In some cases this may even appear to work until something breaks in a completely different part of the code. In the example given, the case where None is returned is clearly an exceptional case (non-success) even though no exception was raised by requests.get. You should raise an exception there instead of returning None to allow the caller better control over the situation. From orgnut at yahoo.com Mon Nov 2 16:06:43 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 2 Nov 2015 13:06:43 -0800 Subject: GoPiGo script In-Reply-To: References: Message-ID: On 11/02/2015 11:31 AM, Robin Koch wrote: > Am 02.11.2015 um 15:32 schrieb input/ldompeling at casema.nl: > >> Thank you for the explanation for it. >> I must tell you that i yust beginning with python. >> I bought the book beginning programming with python. > > Have you programming experience with other languages? > > Well, the very first thing you should have learned is the basic syntax of Python. (That's how a > program has to be written to work properly.) > > And one of those first things is that python code is structured not by braces (like many other > programming languages), but by intendation (as mentioned by others before). ^^^^^^^^^^^ [snip a lot of text, also using the word intend...] The word you want is indent not intend. Intend means something entirely different, and is not a Python term. -=- Larry -=- From lorenzofsutton at gmail.com Mon Nov 2 18:29:51 2015 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Tue, 3 Nov 2015 00:29:51 +0100 Subject: Detection of a specific sound In-Reply-To: References: Message-ID: <5637F1EF.2030505@gmail.com> On 26/10/15 01:17, Montana Burr wrote: > I'm looking for a library that will allow Python to listen for the > shriek of a smoke alarm. Once it detects this shriek, it is to notify > someone. Ideally, specificity can be adjusted for the user's > environment. For example, I expect to need moderate specificity as I > live in a quiet neighborhood, but an apartment dweller might need more. > > I'm thinking of recording a smoke alarm and having the program try to > find the recorded sound in the stream from the microphone. > > Any help is greatly appreciated! > It would really be helpful if you could explain the (hardware) setting in more detail. When you say "Python to listen" I assume you mean a microphone connected to a computer where your python programme will be running. How many smoke allarms and in what radius should be detected? Or is it only a specific one? This could range from a simple programme triggered by an amplitude change (e.g. a piezo attached to the single alarm in question) to a complex audio fingerprinting one... Lorenzo. From robin.koch at t-online.de Mon Nov 2 19:45:23 2015 From: robin.koch at t-online.de (Robin Koch) Date: Tue, 3 Nov 2015 01:45:23 +0100 Subject: GoPiGo script In-Reply-To: References: Message-ID: Am 02.11.2015 um 22:06 schrieb Larry Hudson: > [snip a lot of text, also using the word intend...] > > The word you want is indent not intend. Oops. Of course you are right. You might have noticed, english isn't my native language. Not an excuse, but an explanation. ;-) I can only hope, that Loek does understand what I meant. > Intend means something entirely different, > and is not a Python term. Yes, I know the difference. I just didn't pay enough attention to it. Ironically enough I wrote actually another post about Android-intends earlier. -- Robin Koch From Seymore4Head at Hotmail.invalid Mon Nov 2 20:09:02 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 02 Nov 2015 20:09:02 -0500 Subject: Regular expressions Message-ID: <662g3blobme52hfoududj27err185v2npm@4ax.com> How do I make a regular expression that returns true if the end of the line is an asterisk From python at mrabarnett.plus.com Mon Nov 2 20:19:34 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 3 Nov 2015 01:19:34 +0000 Subject: Regular expressions In-Reply-To: <662g3blobme52hfoududj27err185v2npm@4ax.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <56380BA6.20500@mrabarnett.plus.com> On 2015-11-03 01:09, Seymore4Head wrote: > How do I make a regular expression that returns true if the end of the > line is an asterisk > To match an asterisk: \* To match the end of a line: $ To match an asterisk at the end of a line: \*$ From python.list at tim.thechases.com Mon Nov 2 21:42:37 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 2 Nov 2015 20:42:37 -0600 Subject: Regular expressions In-Reply-To: <662g3blobme52hfoududj27err185v2npm@4ax.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <20151102204237.6a78abdf@bigbox.christie.dr> On 2015-11-02 20:09, Seymore4Head wrote: > How do I make a regular expression that returns true if the end of > the line is an asterisk Why use a regular expression? if line[-1] == '*': yep(line) else: nope(line) -tkc From Seymore4Head at Hotmail.invalid Mon Nov 2 22:17:49 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 02 Nov 2015 22:17:49 -0500 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase wrote: >On 2015-11-02 20:09, Seymore4Head wrote: >> How do I make a regular expression that returns true if the end of >> the line is an asterisk > >Why use a regular expression? > > if line[-1] == '*': > yep(line) > else: > nope(line) > >-tkc > > Because that is the part of Python I am trying to learn at the moment. Thanks From Seymore4Head at Hotmail.invalid Mon Nov 2 22:17:59 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 02 Nov 2015 22:17:59 -0500 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <1r9g3bd89q1mp36l7bioasgmsrhsb8c7fg@4ax.com> On Tue, 3 Nov 2015 01:19:34 +0000, MRAB wrote: >On 2015-11-03 01:09, Seymore4Head wrote: >> How do I make a regular expression that returns true if the end of the >> line is an asterisk >> >To match an asterisk: \* > >To match the end of a line: $ > >To match an asterisk at the end of a line: \*$ Thanks From torriem at gmail.com Mon Nov 2 22:49:03 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Nov 2015 20:49:03 -0700 Subject: Detection of a specific sound In-Reply-To: References: Message-ID: <56382EAF.2000407@gmail.com> On 10/25/2015 06:17 PM, Montana Burr wrote: > I'm looking for a library that will allow Python to listen for the shriek > of a smoke alarm. Once it detects this shriek, it is to notify someone. > Ideally, specificity can be adjusted for the user's environment. For > example, I expect to need moderate specificity as I live in a quiet > neighborhood, but an apartment dweller might need more. > > I'm thinking of recording a smoke alarm and having the program try to find > the recorded sound in the stream from the microphone. > > Any help is greatly appreciated! At this point, from what you say, your problem is not a python one. It's a more general problem that you have to tackle. In other words how are you going to identify this one sound amongst background noise? Once you know that, then you can apply Python to the problem. I suggest you spend some time exploring how you would actually go about recognizing a particular sound algorithmically. Relevant tops of research include: digital signal processing and fourier analysis. A quick google search reveals some info that may point you in the right direction: https://blog.adafruit.com/2015/01/12/think-dsp-introduction-to-signal-processing-using-python/ http://samcarcagno.altervista.org/blog/basic-sound-processing-python/ I know very little about the subject, but if it were me, my naive approach would be to do fourier analysis on the sound you are trying to identify to pick out the sound's fingerprint (certain component waveforms that stand out), and then do the same analysis on your audio stream, looking for this footprint. From torriem at gmail.com Mon Nov 2 22:51:15 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Nov 2015 20:51:15 -0700 Subject: Regular expressions In-Reply-To: <20151102204237.6a78abdf@bigbox.christie.dr> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> Message-ID: <56382F33.8050905@gmail.com> On 11/02/2015 07:42 PM, Tim Chase wrote: > On 2015-11-02 20:09, Seymore4Head wrote: >> How do I make a regular expression that returns true if the end of >> the line is an asterisk > > Why use a regular expression? > > if line[-1] == '*': > yep(line) > else: > nope(line) Indeed, sometimes Jamie Zawinski's is often quite appropriate: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. From joel.goldstick at gmail.com Mon Nov 2 22:58:22 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Nov 2015 22:58:22 -0500 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head wrote: > On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase > wrote: > > >On 2015-11-02 20:09, Seymore4Head wrote: > >> How do I make a regular expression that returns true if the end of > >> the line is an asterisk > > > >Why use a regular expression? > > > > if line[-1] == '*': > > yep(line) > > else: > > nope(line) > > > >-tkc > > > > > Because that is the part of Python I am trying to learn at the moment. > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > My completely unsolicited advice is that regular expressions shouldn't be very high on the list of things to learn. They are very useful, and very tricky and prone many problems that can and should be learned to be resolved with much simpler methods. If you really want to learn regular expressions, that's great but the problem you posed is not one for which they are the best solution. Remember simpler is better than complex. -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From rurpy at yahoo.com Mon Nov 2 23:23:15 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 2 Nov 2015 20:23:15 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> Message-ID: <0cb3abb6-ec1e-4357-ab0f-b018d0c688fa@googlegroups.com> On 11/02/2015 08:51 PM, Michael Torrie wrote: >[...] > Indeed, sometimes Jamie Zawinski's is often quite appropriate: > > Some people, when confronted with a problem, think "I know, I'll use > regular expressions." Now they have two problems. Or its sometimes heard paraphrase: Some people, when confronted with a problem, think "I know, I'll use Python." Now they have two problems The point being it's a cute and memorable aphorism but not very meaningful because it can be applied to anything one wishes to denigrate. Of course there are people who misuse regexes. But I am quite sure, especially in the Python community, there are just as many who fail to use them when they are appropriate which is just as bad. From rurpy at yahoo.com Mon Nov 2 23:23:48 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 2 Nov 2015 20:23:48 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Monday, November 2, 2015 at 8:58:45 PM UTC-7, Joel Goldstick wrote: > On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head > wrote: > > > On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase > > wrote: > > > > >On 2015-11-02 20:09, Seymore4Head wrote: > > >> How do I make a regular expression that returns true if the end of > > >> the line is an asterisk > > > > > >Why use a regular expression? > > > > > > if line[-1] == '*': > > > yep(line) > > > else: > > > nope(line) > > > > > >-tkc > > > > > > > > Because that is the part of Python I am trying to learn at the moment. > > Thanks > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > My completely unsolicited advice is that regular expressions shouldn't be > very high on the list of things to learn. They are very useful, and very > tricky and prone many problems that can and should be learned to be > resolved with much simpler methods. If you really want to learn regular > expressions, that's great but the problem you posed is not one for which > they are the best solution. Remember simpler is better than complex. Regular expressions should be learned by every programmer or by anyone who wants to use computers as a tool. They are a fundamental part of computer science and are used in all sorts of matching and searching from compilers down to your work-a-day text editor. Not knowing how to use them is like an auto mechanic not knowing how to use a socket wrench. From torriem at gmail.com Mon Nov 2 23:33:50 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Nov 2015 21:33:50 -0700 Subject: Regular expressions In-Reply-To: <0cb3abb6-ec1e-4357-ab0f-b018d0c688fa@googlegroups.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <0cb3abb6-ec1e-4357-ab0f-b018d0c688fa@googlegroups.com> Message-ID: <5638392E.8080308@gmail.com> On 11/02/2015 09:23 PM, rurpy--- via Python-list wrote: > On 11/02/2015 08:51 PM, Michael Torrie wrote: >> [...] >> Indeed, sometimes Jamie Zawinski's is often quite appropriate: >> >> Some people, when confronted with a problem, think "I know, I'll use >> regular expressions." Now they have two problems. > > Or its sometimes heard paraphrase: > Some people, when confronted with a problem, think "I know, I'll use > Python." Now they have two problems > The point being it's a cute and memorable aphorism but not very meaningful > because it can be applied to anything one wishes to denigrate. > > Of course there are people who misuse regexes. But I am quite sure, > especially in the Python community, there are just as many who fail to > use them when they are appropriate which is just as bad. Judging by a few posts on the list lately, I'd say it is highly relevant to Python itself. Too many people have only a vague notion of a problem they'd like to solve and although they don't really understand the problem, they've heard Python is a good language to learn, so they ask how they can solve that problem with Python. Now, this certainly can work for a person who's already experienced in several languages and who already understands the problem. For others, it's very much now two intractable problems. From torriem at gmail.com Mon Nov 2 23:38:04 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Nov 2015 21:38:04 -0700 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <56383A2C.1020202@gmail.com> On 11/02/2015 09:23 PM, rurpy--- via Python-list wrote: >> My completely unsolicited advice is that regular expressions shouldn't be >> very high on the list of things to learn. They are very useful, and very >> tricky and prone many problems that can and should be learned to be >> resolved with much simpler methods. If you really want to learn regular >> expressions, that's great but the problem you posed is not one for which >> they are the best solution. Remember simpler is better than complex. > > Regular expressions should be learned by every programmer or by anyone > who wants to use computers as a tool. They are a fundamental part of > computer science and are used in all sorts of matching and searching > from compilers down to your work-a-day text editor. > > Not knowing how to use them is like an auto mechanic not knowing how to > use a socket wrench. Not quite. Core language concepts like ifs, loops, functions, variables, slicing, etc are the socket wrenches of the programmer's toolbox. Regexs are like an electric impact socket wrench. You can do the same work without it, but in many cases it's slower. But you have to learn the other hand tools first in order to really use the electric driver properly (understanding torques, direction of threads, etc), lest you wonder why you're breaking off so many bolts with the torque of the impact drive. From torriem at gmail.com Mon Nov 2 23:46:17 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Nov 2015 21:46:17 -0700 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084A742DCC@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A742DCC@DCBL123VX.root.sutterhealth.org> Message-ID: <56383C19.8080607@gmail.com> On 11/02/2015 08:52 AM, Robinson, Wendy wrote: > [cid:image001.png at 01D11543.5ED11D50] Just FYI this mailing list group is tied with with a system called USENET which is plain text only, so most of us can't see your attachment. This may help you copy the text to your messages in plain text form: http://www.howtogeek.com/howto/windows-vista/copy-to-the-clipboard-from-the-windows-command-prompt/ Did you read what Peter Otten said in reply to your original message and did that not work? Sometimes on Windows you can double-click a python file and it will run. However many python programs don't display graphical elements so you'll just see a black console window flash and disappear. That's why it's probably important while learning Python to become comfortable with the command prompt. Alternatively use the IDLE program that comes with Python to edit and run your programs in a graphical environment. I think if you are on Windows and are unfamiliar with the command prompt I would recommend this course of action. Should be in the Start menu. From steve at pearwood.info Tue Nov 3 01:47:33 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 03 Nov 2015 17:47:33 +1100 Subject: Modern recommended exception handling practices? References: <52739457-5f7a-48ea-8835-9fc8934174f9@googlegroups.com> Message-ID: <56385887$0$1598$c3e8da3$5496439d@news.astraweb.com> Hi Vasudev, and welcome. Sorry for the delay in replying to your questions. My answers inline, below. On Fri, 30 Oct 2015 04:43 am, vasudevram wrote: > Are there any modern (i.e. for current versions of Python 2 and 3) > recommended exception handling practices? When you say "modern", it sounds like you want to contrast them with "old fashioned and obsolete" exception-handling practices. I don't know if there are any obsolete exception-handling practices in Python. I would follow these rules, as best I am able to: (1) Remember that, in general, exception catching is very course-grained. You can catch a particular kind of exception, but you don't know which specific line of code or expression caused it, the reason why, or where in the `try` block it was raised. The entire `try` clause is as fine-grained as you get. One consequence is that it is easy to write exceptional handling code which is wrong and buggy: http://blogs.msdn.com/b/oldnewthing/archive/2004/04/22/118161.aspx http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/352949.aspx To avoid this, the `try` block should cover the least amount of code possible. For example, suppose you have this: try: result = calculate(mylist.index(x), func(key)) except ValueError: # thrown by mylist.index if x is not found result = "x not found" That code is probably unsafe, because you can't be sure that either func(key) or calculate(...) itself might not throw a ValueError. Unless you can guarantee that there are no circumstances where that might happen, or if it doesn't matter which of the three expressions throws the ValueError, you are better off writing this: try: idx = mylist.index(x) except ValueError: result = "x not found" else: result = calculate(idx, func(key)) (2) Catch only the exceptions that you expect and can genuinely recover from. Don't use `try...except` as a way to cover up and hide the fact that an error occurred. One of my favourite quotes about programming is this one: "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 In context of Python, "crash" means "raise an exception". Exceptions are your best friend: they show you were your bugs are. How can you fix bugs if you don't know where they are? You should only catch the exceptions that you expect to occur, and can recover from. Everything else should be allowed to raise an exception, so you can *see* that something is broken. Now you know that something in your code has a bug, and needs to be fixed. Consequently, you should never (well, *almost* never) be tempted to write a bare `except` clause, or even `except Exception`. They are almost always too broad, and catch too much. Bare `except` clauses are very possibly *literally the worst* thing that you can write in Python: https://realpython.com/blog/python/the-most-diabolical-python-antipattern/ (3) One exception to rule (2) is that sometimes it is useful to surround your entire main program with a `try...except`, for the purposes of logging errors and presenting a nice clean error message to your users: try: main() except Exception as err: # Catch any and all unexpected exceptions. log(err) alert("A serious problem has occurred and MyApplication must quit. " "Please contact the help desk on 999-999-999.") sys.exit(1) (4) Remember that Python matches exceptions from top down, so more specific exceptions (subclasses of a less specific exception) need to come first. So if we write this: try: ... except Exception: print("something unexpected occurred") except TypeError: print("this is expected") the TypeError will be caught by the first except clause, and treated as something unexpected. Swap the order of the except clauses, and you will be fine: try: ... except TypeError: print("this is expected") except Exception: print("something unexpected occurred") (5) Remember that often you can avoid exceptions instead of catching them. "Look Before You Leap" (LBYL) may be a perfectly good alternative: if item in mylist: idx = mylist.index(item) process(idx) else: result = "not found" but be sensitive to the amount of work done. The above code searches the list twice instead of just once. (6) In general, you can consider setting up a "try" block to be practically free in Python (which is the opposite to Java, where exception handling is always expensive). If no exception occurs, there is virtually no difference in speed between: func(x) and try: func(x) except: pass but if an exception does occur, actually catching it is quite costly. This idiom is usually called "Easier to Ask for Forgiveness than Permission" (EAFP). (7) So which is faster, LBYL or catching the exception? That is extremely sensitive to not just the specific operations being performed, but how often the exceptional cases occur. In general, you must measure your code to know. But as a very rough rule of thumb, consider looking up a key in a dict: if key in mydict: result = mydict[key] versus try: result = mydict[key] except KeyError: pass In my experience, catching the KeyError is about ten times more costly than testing for the key's presence. So if your keys are missing more than one time in ten, it's probably better to use LBYL. (8) Remember that this is called *exception handling*, not "error handling". In Python, exceptions are not just for errors. For example, Python extensively uses StopIteration for flow-control. When an iterator runs out of items, it raises an exception, which the Python interpreter catches to recognise the end of the iterator. You can do the same in your own code, invent your own protocols that use exceptions to signal exceptional cases. Some very highly respected people like Joel Spolsky and Raymond Chen dislike exceptions as flow-control, calling them just a thinly disguised GOTO: http://www.joelonsoftware.com/items/2003/10/13.html http://blogs.msdn.com/b/oldnewthing/archive/2005/01/06/347666.aspx and while it is true that exceptions are a kind of GOTO, that doesn't mean much. For-loops, and if-elif-else are a kind of GOTO too, and we don't worry about them. (For example, you can't use an exception to jump *into* a function, only out of one.) See also: http://c2.com/cgi/wiki?AvoidExceptionsWheneverPossible http://c2.com/cgi/wiki?ExceptionsAreOurFriends [...] > I realize that there may not be any recommended standard practices for > this, or they may be more than one set, because of differences of opinion. > For example, several years back, there was a somewhat controversial thread > about, IIRC, checked vs. unchecked Java exceptions, maybe triggered by > some post on Elliot Rusty Harold's site (he used to write a lot about > Java, both blog posts and books). Java is, as far as I know, the only language with checked exceptions. Certainly Python doesn't have them. I know that checked exceptions are very controversial in the Java community, but I understand that Java's creator James Gosling eventually came out to say that they were a mistake. In Python's case, you should document what exceptions you expect your functions to raise, but you must not assume that such documentation is ever complete. For example, consider the operator "+". We know that + will raise a TypeError: py> 2 + "2" Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' but if one of the operands is a custom type, it could raise *anything*: py> class X: ... def __add__(self, other): ... raise OSError ... py> X() + 2 Traceback (most recent call last): File "", line 1, in File "", line 3, in __add__ OSError Does this mean you should *catch* everything? No. See Rule (2) above. Unless you are expecting an X instance in your code, the presence of one is probably a bug. The *unexpected* OSError will be the exception that reveals this bug, and allows you to fix it. -- Steven From nobody at nowhere.invalid Tue Nov 3 02:10:58 2015 From: nobody at nowhere.invalid (Nobody) Date: Tue, 03 Nov 2015 07:10:58 +0000 Subject: Unbuffered stderr in Python 3 References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote: > In Python 2, stderr is unbuffered. > > In most other environments (the shell, C...) stderr is unbuffered. > > It is usually considered a bad, bad thing for stderr to be buffered. What > happens if your application is killed before the buffer fills up? The > errors in the buffer will be lost. > > So how come Python 3 has line buffered stderr? And more importantly, how > can I turn buffering off? It's probably related to the fact that std{in,out,err} are Unicode streams. > type(sys.stderr) > type(sys.stderr.buffer) > type(sys.stderr.buffer.raw) It appears that you can turn it off with: sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw) or: sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach()) This results in a sys.stderr which appears to work and whose .line_buffering property is False. From steve at pearwood.info Tue Nov 3 02:15:06 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 03 Nov 2015 18:15:06 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <56385efc$0$1598$c3e8da3$5496439d@news.astraweb.com> On Tue, 3 Nov 2015 03:23 pm, rurpy at yahoo.com wrote: > Regular expressions should be learned by every programmer or by anyone > who wants to use computers as a tool. ?They are a fundamental part of > computer science and are used in all sorts of matching and searching > from compilers down to your work-a-day text editor. You are absolutely right. If only regular expressions weren't such an overly-terse, cryptic mini-language, with all but no debugging capabilities, they would be great. If only there wasn't an extensive culture of regular expression abuse within programming communities, they would be fine. All technologies are open to abuse. But we don't say: Some people, when confronted with a problem, think "I know, I'll use arithmetic." Now they have two problems. because abuse of arithmetic is rare. It's hard to misuse it, and while arithmetic can be complicated, it's rare for programmers to abuse it. But the same cannot be said for regexes -- they are regularly misused, abused, and down-right hard to use right even when you have a good reason for using them: http://www.thedailywtf.com/articles/Irregular_Expression http://blog.codinghorror.com/regex-use-vs-regex-abuse/ http://psung.blogspot.com.au/2008/01/wonderful-abuse-of-regular-expressions.html If there is one person who has done more to create a regex culture, it is Larry Wall, inventor of Perl. Even Larry Wall says that regexes are overused and their syntax is harmful, and he has recreated them for Perl 6: http://www.perl.com/pub/2002/06/04/apo5.html Oh, and the icing on the cake, regexes can be a security vulnerability too: https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS -- Steven From steve at pearwood.info Tue Nov 3 02:15:06 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 03 Nov 2015 18:15:06 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <56385efc$0$1598$c3e8da3$5496439d@news.astraweb.com> On Tue, 3 Nov 2015 03:23 pm, rurpy at yahoo.com wrote: > Regular expressions should be learned by every programmer or by anyone > who wants to use computers as a tool. ?They are a fundamental part of > computer science and are used in all sorts of matching and searching > from compilers down to your work-a-day text editor. You are absolutely right. If only regular expressions weren't such an overly-terse, cryptic mini-language, with all but no debugging capabilities, they would be great. If only there wasn't an extensive culture of regular expression abuse within programming communities, they would be fine. All technologies are open to abuse. But we don't say: Some people, when confronted with a problem, think "I know, I'll use arithmetic." Now they have two problems. because abuse of arithmetic is rare. It's hard to misuse it, and while arithmetic can be complicated, it's rare for programmers to abuse it. But the same cannot be said for regexes -- they are regularly misused, abused, and down-right hard to use right even when you have a good reason for using them: http://www.thedailywtf.com/articles/Irregular_Expression http://blog.codinghorror.com/regex-use-vs-regex-abuse/ http://psung.blogspot.com.au/2008/01/wonderful-abuse-of-regular-expressions.html If there is one person who has done more to create a regex culture, it is Larry Wall, inventor of Perl. Even Larry Wall says that regexes are overused and their syntax is harmful, and he has recreated them for Perl 6: http://www.perl.com/pub/2002/06/04/apo5.html Oh, and the icing on the cake, regexes can be a security vulnerability too: https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS -- Steven From rosuav at gmail.com Tue Nov 3 02:16:18 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Nov 2015 18:16:18 +1100 Subject: Modern recommended exception handling practices? In-Reply-To: <56385887$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <52739457-5f7a-48ea-8835-9fc8934174f9@googlegroups.com> <56385887$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Nov 3, 2015 at 5:47 PM, Steven D'Aprano wrote: > On Fri, 30 Oct 2015 04:43 am, vasudevram wrote: > >> Are there any modern (i.e. for current versions of Python 2 and 3) >> recommended exception handling practices? > > When you say "modern", it sounds like you want to contrast them with "old > fashioned and obsolete" exception-handling practices. I don't know if there > are any obsolete exception-handling practices in Python. Aside from string exceptions and the "except Type, e:" syntax, I would agree with you. Actually, I can't think of any "obsolete exception-handling practices" in any language. Exception handling is pretty straight-forward: you raise an exception in one place, and you catch it in another. > Bare `except` clauses are very possibly *literally the worst* thing that you > can write in Python: > > https://realpython.com/blog/python/the-most-diabolical-python-antipattern/ I would actually like to disallow the bare except, in the same way that I would disallow the Py2 input() function. In the rare cases where you really do want to catch *every* exception (eg at a boundary between a web server and a request handler, where you would log the exception and return a 500), it should be spelled "except BaseException [as e]:", same as you should use "eval(raw_input())" in those extremely rare cases where you actually want to take keyboard input and evaluate it. But more generally, the over-broad exception handler is a nasty anti-pattern. > (5) Remember that often you can avoid exceptions instead of catching > them. "Look Before You Leap" (LBYL) may be a perfectly good alternative: > > if item in mylist: > idx = mylist.index(item) > process(idx) > else: > result = "not found" > > > but be sensitive to the amount of work done. The above code searches the > list twice instead of just once. Not to mention having race condition possibilities. There are a few places where this is useful, though: start_time = time() work_done = do_some_work() time_spent = time()-start_time or 1 print(f"Did {work_done} jobs in {time_spent} secs: {work_done/time_spent} j/s") The "or 1" is a quick check that means we don't divide by zero. The performance figure becomes meaningless, but if this is a rare case, that's probably fine. > (7) So which is faster, LBYL or catching the exception? That is extremely > sensitive to not just the specific operations being performed, but how > often the exceptional cases occur. In general, you must measure your code > to know. > > But as a very rough rule of thumb, consider looking up a key in a dict: > > if key in mydict: > result = mydict[key] > > versus > > try: > result = mydict[key] > except KeyError: > pass > > > In my experience, catching the KeyError is about ten times more costly than > testing for the key's presence. So if your keys are missing more than one > time in ten, it's probably better to use LBYL. This is actually a tribute to dict performance for key lookup (since that's one of the important operations in a hashtable). It's NOT the case for a list. Exceptions are the "other way" to return something. In a function that always returns a string, returning None is distinguishable (in the same way that a C function can return a NULL pointer); in a function that returns absolutely any object, the only way to signal "no object to return" is to raise an exception. That's why StopIteration exists, for instance. Exceptions are a normal part of program flow - they signal an "exceptional condition" in some small area, but it's normal to cope with exceptional conditions. ChrisA From steve at pearwood.info Tue Nov 3 02:22:30 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 03 Nov 2015 18:22:30 +1100 Subject: Modern recommended exception handling practices? References: <52739457-5f7a-48ea-8835-9fc8934174f9@googlegroups.com> <56385887$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <563860b9$0$1589$c3e8da3$5496439d@news.astraweb.com> On Tue, 3 Nov 2015 06:16 pm, Chris Angelico wrote: > Not to mention having race condition possibilities. Arrggghhh! I knew there was something else I wanted to say. You're right. Sometimes you *have* to use exception handling code. Take this for example: if os.path.exists(pathname): f = open(pathname) That might be good enough for a quick and dirty script, but it's wrong, because there's a race condition between the time you check whether the file exists and the time you actually try to open it. (There are other problems too: just because the file exists doesn't mean you have read permission to it.) A lot can happen in the few microseconds between checking for the existence of the file and actually opening it -- the file could be renamed or deleted. https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use -- Steven From rosuav at gmail.com Tue Nov 3 02:52:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Nov 2015 18:52:27 +1100 Subject: Modern recommended exception handling practices? In-Reply-To: <563860b9$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <52739457-5f7a-48ea-8835-9fc8934174f9@googlegroups.com> <56385887$0$1598$c3e8da3$5496439d@news.astraweb.com> <563860b9$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Nov 3, 2015 at 6:22 PM, Steven D'Aprano wrote: > A lot can happen in the few microseconds between > checking for the existence of the file and actually opening it -- the file > could be renamed or deleted. And a lot of microseconds can happen between two opcodes, too. Even inside a Python script, it's possible for threads or other arbitrary code execution to get in your way: if "foo" in counters: # context switch here! process(counters["foo"]) Garbage collection can happen at any time. Here's an (admittedly arbitrary) example of how the above could be broken: >>> class X: ... def __init__(self, name, dict): ... self.dict = dict; self.name = name ... self.dict[self.name] = 0 ... def frob(self): ... self.dict[self.name] += 1 ... def __del__(self): ... del self.dict[self.name] ... >>> counters = {} >>> x = X("foo", counters) >>> x.refcycle = x >>> counters {'foo': 0} >>> del x >>> counters {'foo': 0} >>> gc.collect() 10 >>> counters {} If the cycle-detecting garbage collector happens to be called immediately after the 'if', you'll get an exception. So I suppose what you might do is this: try: # Optimization: Since a lot of these names won't be # in the dict, we check first rather than relying on the # exception. Since counters get removed in the __del__ # method, we can't depend 100% on the 'in' check, # but an unnecessary try block is cheap. if "foo" in counters: process(counters["foo"]) except KeyError: pass But any time you need a block comment to justify your code, you'd better be REALLY sure the performance benefit is worth the complexity. For reliability, expect exceptions. ChrisA From nick.a.sarbicki at gmail.com Tue Nov 3 03:43:10 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Tue, 3 Nov 2015 08:43:10 +0000 Subject: Regular expressions In-Reply-To: <56385efc$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56385efc$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Nov 3, 2015 at 7:15 AM, Steven D'Aprano wrote: > On Tue, 3 Nov 2015 03:23 pm, rurpy at yahoo.com wrote: > > > Regular expressions should be learned by every programmer or by anyone > > who wants to use computers as a tool. They are a fundamental part of > > computer science and are used in all sorts of matching and searching > > from compilers down to your work-a-day text editor. > > You are absolutely right. > > If only regular expressions weren't such an overly-terse, cryptic > mini-language, with all but no debugging capabilities, they would be great. > > If only there wasn't an extensive culture of regular expression abuse > within > programming communities, they would be fine. > > All technologies are open to abuse. But we don't say: > > Some people, when confronted with a problem, think "I know, I'll use > arithmetic." Now they have two problems. > > because abuse of arithmetic is rare. It's hard to misuse it, and while > arithmetic can be complicated, it's rare for programmers to abuse it. But > the same cannot be said for regexes -- they are regularly misused, abused, > and down-right hard to use right even when you have a good reason for using > them: > > http://www.thedailywtf.com/articles/Irregular_Expression > > http://blog.codinghorror.com/regex-use-vs-regex-abuse/ > > > http://psung.blogspot.com.au/2008/01/wonderful-abuse-of-regular-expressions.html > > > If there is one person who has done more to create a regex culture, it is > Larry Wall, inventor of Perl. Even Larry Wall says that regexes are > overused and their syntax is harmful, and he has recreated them for Perl 6: > > http://www.perl.com/pub/2002/06/04/apo5.html > > Oh, and the icing on the cake, regexes can be a security vulnerability too: > > > https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > +1 I agree that regex is an entirely necessary part of a programmers toolkit, but dear god some people need to be taught restraint. The majority of people I talk about regex to have no idea when and where it shouldn't be used. As an example part of my job is bringing our legacy Python code into the modern day, and one of the largest roadblocks is the amount of regex used. Some is necessary. Some can be replaced by an `if word in str` or something similarly basic. Some spans hundreds of lines and causes acute alopecia. Just yesterday I found a colleague trying to parse HTML with regex. So yes, teach regex, but teach it after the basics, and please emphasise when it is appropriate to use it. Yes I am bitter. - Nick. From alister.nospam.ware at ntlworld.com Tue Nov 3 03:50:34 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 3 Nov 2015 08:50:34 +0000 (UTC) Subject: Detection of a specific sound References: Message-ID: On Mon, 02 Nov 2015 20:49:03 -0700, Michael Torrie wrote: > On 10/25/2015 06:17 PM, Montana Burr wrote: >> I'm looking for a library that will allow Python to listen for the >> shriek of a smoke alarm. Once it detects this shriek, it is to notify >> someone. Ideally, specificity can be adjusted for the user's >> environment. For example, I expect to need moderate specificity as I >> live in a quiet neighborhood, but an apartment dweller might need more. >> >> I'm thinking of recording a smoke alarm and having the program try to >> find the recorded sound in the stream from the microphone. >> >> Any help is greatly appreciated! > > At this point, from what you say, your problem is not a python one. It's > a more general problem that you have to tackle. In other words how are > you going to identify this one sound amongst background noise? Once you > know that, then you can apply Python to the problem. > > I suggest you spend some time exploring how you would actually go about > recognizing a particular sound algorithmically. Relevant tops of > research include: digital signal processing and fourier analysis. > > A quick google search reveals some info that may point you in the right > direction: > > https://blog.adafruit.com/2015/01/12/think-dsp-introduction-to-signal- processing-using-python/ > http://samcarcagno.altervista.org/blog/basic-sound-processing-python/ > > I know very little about the subject, but if it were me, my naive > approach would be to do fourier analysis on the sound you are trying to > identify to pick out the sound's fingerprint (certain component > waveforms that stand out), and then do the same analysis on your audio > stream, looking for this footprint. Personally I would forget trying to analyse sound & see if there is any way to get an input signal direct from the alarm (even if that is as crude as taking a tap from the siren feed wires) This application sounds far to critical for anything else. -- ______________________________________ / "Can't you just gesture hypnotically \ | and make him disappear?" | | | | "It does not work that way. RUN!" -- | | Hadji on metaphyics and Mandrake in | \ "Johnny Quest" / -------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/ From alister.nospam.ware at ntlworld.com Tue Nov 3 04:04:20 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 3 Nov 2015 09:04:20 +0000 (UTC) Subject: installer user interface glitch ? References: <20151101081401312.7CB171092D5B3FA6@griff-18f062b3e> <5cf3c8b2-4095-4e73-98bf-dcc8d776005d@googlegroups.com> <1e5939df-d2c3-4e08-ab26-36c81b0218c5@googlegroups.com> Message-ID: On Sun, 01 Nov 2015 08:24:22 -0800, rurpy wrote: > On Sunday, November 1, 2015 at 8:52:55 AM UTC-7, Chris Angelico wrote: >> On Mon, Nov 2, 2015 at 2:43 AM, rurpy--- via Python-list >> wrote: >> > Why, oh why, do the python.org front page and other pages that offer >> > a Windows download not say a word about it not running on Windows XP? >> > >> > Even if one is anal enough to go to the page about the 3.5 release. >> > https://www.python.org/downloads/release/python-350/ >> > a page with a lot of Windows-specific info, there is not a word about >> > XP. >> >> A partial answer to that is in PEP 11: >> >> https://www.python.org/dev/peps/pep-0011/#microsoft-windows >> >> Windows XP isn't special here. There's no mention of Python 2.7 not >> working on Windows 95, because it's simply an unsupported operating >> system. The only reason that people keep coming asking about XP and not >> (say) Win2K is that there are a lot more XP boxes out there. Do the >> other download pages need to stipulate which versions of which OSes >> they support, or should that be left up to the installer? > > I dont recall seeing anyone posting asking why they could not get Python > to install on Windows 95 recently. I only read this group > intermittently but I have seen *many* posts asking why they couldnt > install on XP. > > You acknowledge yourself: "there are a lot more XP boxes out there." > >> There *is* a plan to have the installer give a better error message for >> this situation. > > A better message from the installer is necessary but not sufficient. > Don't make people go through the effort to download the whole thing, do > their planning and preparations for using or upgrading Python only to > discover at the last moment it wont work. > > That is really shitty customer relations. > > The reality is that people trying install Python-3.5 on XP *is* a > problem. Telling them they should have read some obscure release notes > is not a solution. > >> But I don't think the web site necessarily has to have noise about old >> versions of OSes. Where would you draw the line? > > I think my responses above answer that. I would have to agree, at least in general 1) The web page should always list the Versions of Windows that ARE supported. 2) As support for Win XP has only just ceased it should be specifically mentioned for V3.5, I would see no need to continue with this for V3.6 + Likewise Win95 2000 etc. should have been mentioned at the release when support was dropped & no further As adding a "Not supported on Win XP or Win 7 Minimum" notice is such a minimal "Bug Fix" I don't see the issue. -- _____________________ < U.S. Postal Service > --------------------- \ \ .--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/ From __peter__ at web.de Tue Nov 3 04:25:26 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Nov 2015 10:25:26 +0100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> Message-ID: Michael Torrie wrote: > On 11/02/2015 07:42 PM, Tim Chase wrote: >> On 2015-11-02 20:09, Seymore4Head wrote: >>> How do I make a regular expression that returns true if the end of >>> the line is an asterisk >> >> Why use a regular expression? >> >> if line[-1] == '*': >> yep(line) >> else: >> nope(line) > > Indeed, sometimes Jamie Zawinski's is often quite appropriate: > > Some people, when confronted with a problem, think "I know, I'll use > regular expressions." Now they have two problems. Incidentally the code example has two "problems", too. - What about the empty string? - What about lines with a trailing "\n", i. e. as they are usually delivered when iterating over a file? Below is a comparison of some of your options. The "one obvious way" line.rstrip("\n").endswith("*") is not included ;) $ cat starry_table.py import re def show_table(data, header): rows = [header] rows.extend([str(c) for c in row] for row in data) widths = [max(len(row[i]) for row in rows) for i in range(len(header))] template = " ".join("{:%d}" % w for w in widths) for row in rows: print(template.format(*row)) def compare(sample_lines): for line in sample_lines: got_re = bool(re.compile("\*$").search(line)) got_re_M = bool(re.compile("\*$", re.M).search(line)) got_endswith = line.endswith("*") got_endswith2 = line.endswith(("*", "*\n")) got_substring = line[-1:] == "*" try: got_char = line[-1] == "*" except IndexError: got_char = "#exception" results = ( got_re, got_re_M, got_endswith, got_endswith2, got_substring, got_char) yield ( ["", "X"][len(set(results)) > 1], repr(line)) + results SAMPLE = ["", "\n", "foo\n", "*\n", "*", "foo*", "foo*\n", "foo*\nbar"] HEADER = [ "", "line", "regex", "re.M", "endswith", 'endswith(("*", "*\\n"))', "substring", "char"] if __name__ == "__main__": show_table(compare(SAMPLE), HEADER) $ python3 starry_table.py line regex re.M endswith endswith(("*", "*\n")) substring char X '' False False False False False #exception '\n' False False False False False False 'foo\n' False False False False False False X '*\n' True True False True False False '*' True True True True True True 'foo*' True True True True True True X 'foo*\n' True True False True False False X 'foo*\nbar' False True False False False False From motoom at xs4all.nl Tue Nov 3 04:39:46 2015 From: motoom at xs4all.nl (Michiel Overtoom) Date: Tue, 3 Nov 2015 10:39:46 +0100 Subject: Puzzled In-Reply-To: <56383C19.8080607@gmail.com> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A742DCC@DCBL123VX.root.sutterhealth.org> <56383C19.8080607@gmail.com> Message-ID: <2E07C1E1-82C0-4919-BF9E-C9BF2EB0B3D4@xs4all.nl> > On 03 Nov 2015, at 05:46, Michael Torrie wrote: > Sometimes on Windows you can double-click a python file and it will run. The first thing I do on Windows after installing Python: edit the registry so that the 'open' key is changed to 'run', and 'edit with IDLE' becomes 'open'. I like to see my scripts in IDLE before I run them ;-) Greetings, From nicholas.cole at gmail.com Tue Nov 3 05:32:33 2015 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Tue, 3 Nov 2015 10:32:33 +0000 Subject: venv issues Message-ID: I'm using python3.5 (installed from binaries) on the latest OS X. I have a curious issue with virtual environments on this machine (but not on my other machine). $ python3.5 -m venv testenv $ source testenv/bin/activate (testenv)$ python -m pip /private/tmp/testenv/bin/python: No module named pip $ Logging in as a different user and creating a venv works perfectly, so it's clearly a config issue somewhere, but I've tried removing ~/.bashrc and ~/.bash_profile and that doesn't help. The sys.path for that venv is: ['', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', '/private/tmp/testenv/lib/python3.5/site-packages'] I'm sure I'm overlooking something obvious, but can anyone suggest what? Nicholas From python.list at tim.thechases.com Tue Nov 3 06:50:18 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 3 Nov 2015 05:50:18 -0600 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> Message-ID: <20151103055018.535e3e42@bigbox.christie.dr> On 2015-11-03 10:25, Peter Otten wrote: > >>> How do I make a regular expression that returns true if the end > >>> of the line is an asterisk > >> > >> Why use a regular expression? > >> > >> if line[-1] == '*': > >> yep(line) > >> else: > >> nope(line) > > Incidentally the code example has two "problems", too. > > - What about the empty string? Good catch: .endswith() works better. > - What about lines with a trailing "\n", i. e. as they are usually > delivered when iterating over a file? Then your string *doesn't* end with a "*", but rather with a newline. ;-) Though according to the OP's specs, the following function would work too: def ends_in_asterisk(s): return True It *does* return True if the line ends in an asterisk (no requirement to make the function return False under any other conditions). -tkc From python.list at tim.thechases.com Tue Nov 3 06:53:39 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 3 Nov 2015 05:53:39 -0600 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <20151103055339.247c5230@bigbox.christie.dr> On 2015-11-02 22:17, Seymore4Head wrote: > On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase > wrote: > > >On 2015-11-02 20:09, Seymore4Head wrote: > >> How do I make a regular expression that returns true if the end > >> of the line is an asterisk > > > >Why use a regular expression? > > > Because that is the part of Python I am trying to learn at the > moment. Thanks Ah, well that's an entirely different problem-space, so then you would want to use MRAB's answer r = re.compile(r"\*$") -tkc From arsh840 at gmail.com Tue Nov 3 06:54:30 2015 From: arsh840 at gmail.com (Arshpreet Singh) Date: Tue, 3 Nov 2015 03:54:30 -0800 (PST) Subject: Python PNG Viewer(Browser Based) Message-ID: <9c24559b-17a4-41fc-80a2-9258fd84c9f1@googlegroups.com> Hello Everyone, I am looking for Browser-based PNG file viewer written in Python.(Flask framework preferably) Following project(Flask-Based) provides many things(File manager as well as file viewer) but it does not support PNG files. https://github.com/vmi356/filemanager Any idea if I have to write my own browser based PNG viewer from scratch(Using PIL or other required library) On the other side if I have to write only Desktop-based only two lines are enough to do many things: Like, from PIL import Image f = Image.open("file.png").show() But I am not getting right sense that how to make possible using Python+Flask. Hope I am able to tell my problem? From wolfgang.maier at biologie.uni-freiburg.de Tue Nov 3 07:27:14 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 3 Nov 2015 13:27:14 +0100 Subject: venv issues In-Reply-To: References: Message-ID: On 03.11.2015 11:32, Nicholas Cole wrote: > I'm using python3.5 (installed from binaries) on the latest OS X. > > I have a curious issue with virtual environments on this machine (but > not on my other machine). > > > $ python3.5 -m venv testenv > $ source testenv/bin/activate > (testenv)$ python -m pip > /private/tmp/testenv/bin/python: No module named pip > $ > > Logging in as a different user and creating a venv works perfectly, so > it's clearly a config issue somewhere, but I've tried removing > ~/.bashrc and ~/.bash_profile and that doesn't help. > > The sys.path for that venv is: ['', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', > '/private/tmp/testenv/lib/python3.5/site-packages'] > Is there something special about your /private/tmp folder? In other words, do things work if you create a venv in a different place. If you go to /private/tmp/testenv/lib/python3.5/site-packages is there a pip folder and what are its permission settings? From denismfmcmahon at gmail.com Tue Nov 3 07:38:12 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 3 Nov 2015 12:38:12 -0000 (UTC) Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Mon, 02 Nov 2015 22:17:49 -0500, Seymore4Head wrote: > On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase > wrote: > >>On 2015-11-02 20:09, Seymore4Head wrote: >>> How do I make a regular expression that returns true if the end of the >>> line is an asterisk >>Why use a regular expression? > Because that is the part of Python I am trying to learn at the moment. The most important thing to learn about regular expressions is when to use them and when not to use them. Returning true if the last character in a string is an asterisk is almost certainly a brilliant example of when not to use a regular expression. Here are some timings I tested: #!/usr/bin/python import re import timeit patt = re.compile("\*$") start_time = timeit.default_timer() for i in range(1000000): x = re.match("\*$", "test 1") elapsed = timeit.default_timer() - start_time print "re, false", elapsed start_time = timeit.default_timer() for i in range(1000000): x = re.match("\*$", "test *") elapsed = timeit.default_timer() - start_time print "re, true", elapsed start_time = timeit.default_timer() for i in range(1000000): x = patt.match("test 1") elapsed = timeit.default_timer() - start_time print "compiled re, false", elapsed start_time = timeit.default_timer() for i in range(1000000): x = patt.match("test *") elapsed = timeit.default_timer() - start_time print "compiled re, true", elapsed start_time = timeit.default_timer() for i in range(1000000): x = "test 1"[-1] == "*" elapsed = timeit.default_timer() - start_time print "char compare, false", elapsed start_time = timeit.default_timer() for i in range(1000000): x = "test *"[-1] == "*" elapsed = timeit.default_timer() - start_time print "char compare, true", elapsed RESULTS: re, false 2.4701731205 re, true 2.42048001289 compiled re, false 0.875837087631 compiled re, true 0.876382112503 char compare, false 0.26283121109 char compare, true 0.263465881348 The compiled re is about 3 times as fast as the uncompiled re. The character comparison is about 3 times as fast as the compiled re. -- Denis McMahon, denismfmcmahon at gmail.com From ruudvnrooijen at gmail.com Tue Nov 3 08:07:37 2015 From: ruudvnrooijen at gmail.com (Ruud van Rooijen) Date: Tue, 3 Nov 2015 14:07:37 +0100 Subject: python error Message-ID: my code: from tkinter import * window = Tk() label = Label(window, text="miniproject A1") label.pack() window.mainloop() given error: C:\Users\Ruud\Python35\Scripts\python.exe C:/Users/Ruud/PycharmProjects/School/project.py Traceback (most recent call last): File "C:/Users/Ruud/PycharmProjects/School/project.py", line 3, in window = Tk() File "C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32\Lib\tkinter\__init__.py", line 1867, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: Can't find a usable init.tcl in the following directories: C:/Users/Ruud/AppData/Local/Programs/Python/Python35-32/lib/tcl8.6 C:/Users/Ruud/Python35/lib/tcl8.6 C:/Users/Ruud/lib/tcl8.6 C:/Users/Ruud/Python35/library C:/Users/Ruud/library C:/Users/Ruud/tcl8.6.4/library C:/Users/tcl8.6.4/library This probably means that Tcl wasn't installed properly. i have repaired python several times and i can't find an answer online... please help Ruud From tjreedy at udel.edu Tue Nov 3 08:34:35 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 3 Nov 2015 08:34:35 -0500 Subject: python error In-Reply-To: References: Message-ID: On 11/3/2015 8:07 AM, Ruud van Rooijen wrote: > my code: > > from tkinter import * > > window = Tk() > label = Label(window, text="miniproject A1") > label.pack() > window.mainloop() > > > given error: > > C:\Users\Ruud\Python35\Scripts\python.exe Based on the below, python.exe should be in C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32 _tkinter should then be in C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32\DLLs If you moved it, that is your problem. If you have two python installations, with a second one in C:\Users\Ruud\Python35, then python.exe should be in that directory, NOT scripts. > C:/Users/Ruud/PycharmProjects/School/project.py I know essentially nothing about PyCharm, even if it is compatible with tkinter. > Traceback (most recent call last): > > File "C:/Users/Ruud/PycharmProjects/School/project.py", line 3, in > > window = Tk() > > File "C:\Users\Ruud\AppData\Local\Programs\Python\Python35-32\Lib\tkinter\__init__.py", > line 1867, in __init__ > > self.tk = _tkinter.create(screenName, baseName, className, > interactive, wantobjects, useTk, sync, use) > > _tkinter.TclError: Can't find a usable init.tcl in the following directories: > > C:/Users/Ruud/AppData/Local/Programs/Python/Python35-32/lib/tcl8.6 > C:/Users/Ruud/Python35/lib/tcl8.6 C:/Users/Ruud/lib/tcl8.6 > C:/Users/Ruud/Python35/library C:/Users/Ruud/library > C:/Users/Ruud/tcl8.6.4/library C:/Users/tcl8.6.4/library With a screwed up installation, or pair of installations, it looks 'everyplace' but the right place. > This probably means that Tcl wasn't installed properly. > i have repaired python several times and i can't find an answer online... > please help python.exe in scripts is not properly installed. -- Terry Jan Reedy From nicholas.cole at gmail.com Tue Nov 3 08:47:47 2015 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Tue, 3 Nov 2015 13:47:47 +0000 Subject: venv issues In-Reply-To: References: Message-ID: On Tue, Nov 3, 2015 at 12:27 PM, Wolfgang Maier wrote: > On 03.11.2015 11:32, Nicholas Cole wrote: >> >> I'm using python3.5 (installed from binaries) on the latest OS X. >> >> I have a curious issue with virtual environments on this machine (but >> not on my other machine). >> >> >> $ python3.5 -m venv testenv >> $ source testenv/bin/activate >> (testenv)$ python -m pip >> /private/tmp/testenv/bin/python: No module named pip >> $ >> >> Logging in as a different user and creating a venv works perfectly, so >> it's clearly a config issue somewhere, but I've tried removing >> ~/.bashrc and ~/.bash_profile and that doesn't help. >> >> The sys.path for that venv is: ['', >> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', >> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', >> >> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', >> >> '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', >> '/private/tmp/testenv/lib/python3.5/site-packages'] >> > > Is there something special about your /private/tmp folder? In other words, > do things work if you create a venv in a different place. > If you go to /private/tmp/testenv/lib/python3.5/site-packages is there a pip > folder and what are its permission settings? /private/tmp/testenv/lib/python3.5/site-packages is completely empty. There's nothing special about that folder, though. The problem exists everywhere. From rosuav at gmail.com Tue Nov 3 08:59:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Nov 2015 00:59:38 +1100 Subject: venv issues In-Reply-To: References: Message-ID: On Tue, Nov 3, 2015 at 9:32 PM, Nicholas Cole wrote: > Logging in as a different user and creating a venv works perfectly, so > it's clearly a config issue somewhere, but I've tried removing > ~/.bashrc and ~/.bash_profile and that doesn't help. What happens if you create a brand new user, then copy in all dot-files and directories from your current one? Does it exhibit the same problem? ChrisA From __peter__ at web.de Tue Nov 3 09:00:48 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Nov 2015 15:00:48 +0100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> Message-ID: Tim Chase wrote: > On 2015-11-03 10:25, Peter Otten wrote: >> >>> How do I make a regular expression that returns true if the end >> >>> of the line is an asterisk >> >> >> >> Why use a regular expression? >> >> >> >> if line[-1] == '*': >> >> yep(line) >> >> else: >> >> nope(line) >> >> Incidentally the code example has two "problems", too. >> >> - What about the empty string? > > Good catch: .endswith() works better. > >> - What about lines with a trailing "\n", i. e. as they are usually >> delivered when iterating over a file? > > Then your string *doesn't* end with a "*", but rather with a > newline. ;-) > > Though according to the OP's specs, the following function would work > too: > > def ends_in_asterisk(s): > return True > > It *does* return True if the line ends in an asterisk (no requirement > to make the function return False under any other conditions). If a "line" is defined as a string that ends with a newline def ends_in_asterisk(line): return False would also satisfy the requirement. Lies, damned lies, and specs ;) From __peter__ at web.de Tue Nov 3 09:04:27 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Nov 2015 15:04:27 +0100 Subject: venv issues References: Message-ID: Nicholas Cole wrote: > I'm using python3.5 (installed from binaries) on the latest OS X. > > I have a curious issue with virtual environments on this machine (but > not on my other machine). > > > $ python3.5 -m venv testenv > $ source testenv/bin/activate > (testenv)$ python -m pip > /private/tmp/testenv/bin/python: No module named pip > $ > > Logging in as a different user and creating a venv works perfectly, so > it's clearly a config issue somewhere, but I've tried removing > ~/.bashrc and ~/.bash_profile and that doesn't help. Does $ which python3.5 (before sourcing bin/activate) point to the same python for both users? > > The sys.path for that venv is: ['', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat- darwin', > '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib- dynload', > '/private/tmp/testenv/lib/python3.5/site-packages'] > > I'm sure I'm overlooking something obvious, but can anyone suggest what? > > Nicholas From nicholas.cole at gmail.com Tue Nov 3 09:06:24 2015 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Tue, 3 Nov 2015 14:06:24 +0000 Subject: venv issues In-Reply-To: References: Message-ID: On Tue, Nov 3, 2015 at 1:59 PM, Chris Angelico wrote: > On Tue, Nov 3, 2015 at 9:32 PM, Nicholas Cole wrote: >> Logging in as a different user and creating a venv works perfectly, so >> it's clearly a config issue somewhere, but I've tried removing >> ~/.bashrc and ~/.bash_profile and that doesn't help. > > What happens if you create a brand new user, then copy in all > dot-files and directories from your current one? Does it exhibit the > same problem? No. And that helped me find the problem. I had an old .pydistutils.cfg file with a line: install_lib = ~/Library/Python/$py_version_short/lib/python/site-packages That completely upset the venv. (whether it should have done or not, I don't know. I would have expected venv to ignore pydistutils.cfg) Thank you both for your help! Best, N. From wrw at mac.com Tue Nov 3 09:45:29 2015 From: wrw at mac.com (William Ray Wing) Date: Tue, 03 Nov 2015 09:45:29 -0500 Subject: Detection of a specific sound In-Reply-To: References: Message-ID: > On Oct 25, 2015, at 8:17 PM, Montana Burr wrote: > > I'm looking for a library that will allow Python to listen for the shriek of a smoke alarm. Once it detects this shriek, it is to notify someone. Ideally, specificity can be adjusted for the user's environment. For example, I expect to need moderate specificity as I live in a quiet neighborhood, but an apartment dweller might need more. > > I'm thinking of recording a smoke alarm and having the program try to find the recorded sound in the stream from the microphone. > I?ve been watching this thread and finally decided to jump in. First off, we REALLY need to know a bit more about what you are trying to accomplish, in what sort of environment, and under what constraints (legal and otherwise). That last bit is crucial. Is this simply a heads up e-mail message to be sent or is it a way of notifying a backup (second tier) monitoring service. Is it for your personal use, or do you expect to sell it (again crucial). Does the computer you expect to run this on have a good UPS system (in a typical fire, AC power frequently fails early, sometimes it is the *cause* of the fire). How are you going to get that notification out? Does your network have battery backup? Are you going to buy a station-service cell phone transmitter? If you are thinking of sending a cell phone msg, how do you guarantee the receiver is on? LOTS of issues here. Then, having said that, and in no particular order: 1) the sounders in most smoke alarms use over-driven pizeo-electric annunciators, their output has a VERY complex frequency spectrum with LOTS of harmonics. Spectral analysis (combined with threshold analysis) MIGHT be a good way to go, but doing so in real time with Python would consume most, if not all the resources of the host computer; 2) You would (personal opinion), be much better off using hardwired or semi-hardwired detection. There are several ways to go, including a detector microphone and transmitter such as is used to run a remote doorbell system (mount the microphone next to the smoke detector, then tap into the doorbell receiver box). These have adjustable sensitivity and would basically be a threshold detector. Alternatively, almost all smoke detectors these days are designed to be chained to each other via three-wire (plus ground) AC wiring. Two of the wires carry power, the third triggers all the detectors in the system to sound when if of them sound. Don?t try to tap the signal wire (liability issues), but you could add another detector to the system which would act as your monitor if you tap *its* driver output. 3) Finally, how do you guarantee the computer on which the program is to run will be up at all times? Does it auto-restart after a power failure, does the program auto-reload as part of the boot-up sequence, and finally, is the program going to have absolutely bullet proof error recovery? -Bill > Any help is greatly appreciated! > -- > https://mail.python.org/mailman/listinfo/python-list From alister.nospam.ware at ntlworld.com Tue Nov 3 09:49:58 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 3 Nov 2015 14:49:58 +0000 (UTC) Subject: Detection of a specific sound References: Message-ID: On Tue, 03 Nov 2015 09:03:14 -0500, Dennis Lee Bieber wrote: > On Tue, 3 Nov 2015 08:50:34 +0000 (UTC), alister > declaimed the following: > >>Personally I would forget trying to analyse sound & see if there is any >>way to get an input signal direct from the alarm (even if that is as >>crude as taking a tap from the siren feed wires) >> >>This application sounds far to critical for anything else. > > A direct line is what I'd recommend too -- but I'm going to be paranoid > today: > > If a fire did occur, and the inspectors find traces of wiring going > into what was supposed to be a stand-alone detector there is a risk that > it will be concluded that the detector had been tampered with and may > not have been functional... And that could lead to all sorts of > liability problems. > > I don't know if anyone makes a model that falls between (common) > stand-alone and full monitored (tied to burglar alarm system with a > service provider responding to triggers). Something of a monitored type > (hence designed to be wired to central panel) but without the outside > monitoring agency. > > > Barring that... if the detectors are all close in pitch, a PLL circuit > fed from the microphone, using the "locked" signal to indicate when the > alarm is chirping -- gives a simple on/off digital signal for the > computer (the computer may be needed to ensure the chirps are at an > expected rate and not stray whistles). Beyond that, FFT to look for > spectral signature of chirps. I would hope that most fire alarm systems (except domestic type smoke detectors) would have some relay outputs or telephone dialler options which would be legitimate locations to connect extra equipment. The op probably needs to provide more information on the exact set-up intended. -- ______________________________ / Gold's Law: \ | | \ If the shoe fits, it's ugly. / ------------------------------ \ \ .--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/ From invalid at invalid.invalid Tue Nov 3 09:56:00 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 Nov 2015 14:56:00 +0000 (UTC) Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On 2015-11-03, Tim Chase wrote: > On 2015-11-02 20:09, Seymore4Head wrote: >> How do I make a regular expression that returns true if the end of >> the line is an asterisk > > Why use a regular expression? > > if line[-1] == '*': Why use a negative index and then a compare? if line.endswith('*'): If you want to know if a string ends with something, just ask it! ;) -- Grant Edwards grant.b.edwards Yow! RELATIVES!! at gmail.com From random832 at fastmail.com Tue Nov 3 09:57:34 2015 From: random832 at fastmail.com (Random832) Date: Tue, 03 Nov 2015 09:57:34 -0500 Subject: Detection of a specific sound References: Message-ID: <878u6f9llt.fsf@fastmail.com> Dennis Lee Bieber writes: > If a fire did occur, and the inspectors find traces of wiring > going into what was supposed to be a stand-alone detector there is > a risk that it will be concluded that the detector had been > tampered with and may not have been functional... And that could > lead to all sorts of liability problems. What about a *second* smoke detector? From random832 at fastmail.com Tue Nov 3 10:00:33 2015 From: random832 at fastmail.com (Random832) Date: Tue, 03 Nov 2015 10:00:33 -0500 Subject: Unbuffered stderr in Python 3 References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874mh39lgu.fsf@fastmail.com> Nobody writes: > It's probably related to the fact that std{in,out,err} are Unicode > streams. There's no fundamental reason a Unicode stream should have to be line buffered. If it's "related", it's only in that an oversight was made in the course of making that change. From harvesting at makes.email.invalid Tue Nov 3 10:12:28 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Tue, 03 Nov 2015 17:12:28 +0200 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> Message-ID: Peter Otten writes: > If a "line" is defined as a string that ends with a newline > > def ends_in_asterisk(line): > return False > > would also satisfy the requirement. Lies, damned lies, and specs ;) Even if a "line" is defined as a string that comes from reading something like a file with default options, a line may end in an asterisk. >>> [ line.endswith('*') for line in StringIO('rivi*\nrivi*\nrivi*') ] [False, False, True] From joel.goldstick at gmail.com Tue Nov 3 10:34:12 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 3 Nov 2015 10:34:12 -0500 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head wrote: > On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase > wrote: > > >On 2015-11-02 20:09, Seymore4Head wrote: > >> How do I make a regular expression that returns true if the end of > >> the line is an asterisk > > > >Why use a regular expression? > > > > if line[-1] == '*': > > yep(line) > > else: > > nope(line) > > > >-tkc > > > > > Because that is the part of Python I am trying to learn at the moment. > Are we to infer that you were aware of doing the if line[-1] == '*': ... , but just wanted to learn how to do the same thing with regex? Or that you heard about regexes and thought that would be the way to solve your puzzle? > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From __peter__ at web.de Tue Nov 3 10:35:22 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Nov 2015 16:35:22 +0100 Subject: Irregular last line in a text file, was Re: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> Message-ID: Jussi Piitulainen wrote: > Peter Otten writes: > >> If a "line" is defined as a string that ends with a newline >> >> def ends_in_asterisk(line): >> return False >> >> would also satisfy the requirement. Lies, damned lies, and specs ;) > > Even if a "line" is defined as a string that comes from reading > something like a file with default options, a line may end in > an asterisk. Note that the last line from the file is not a line as defined by me in the above post ;) >>>> [ line.endswith('*') for line in StringIO('rivi*\nrivi*\nrivi*') ] > [False, False, True] I wish there were a way to prohibit such files. Maybe a special value with open(..., newline="normalize") f: assert all(line.endswith("\n") for line in f) to ensure that all lines end with "\n"? From rosuav at gmail.com Tue Nov 3 10:42:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Nov 2015 02:42:19 +1100 Subject: Unbuffered stderr in Python 3 In-Reply-To: <874mh39lgu.fsf@fastmail.com> References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> Message-ID: On Wed, Nov 4, 2015 at 2:00 AM, Random832 wrote: > Nobody writes: > >> It's probably related to the fact that std{in,out,err} are Unicode >> streams. > > There's no fundamental reason a Unicode stream should have to be line > buffered. If it's "related", it's only in that an oversight was made in > the course of making that change. Yep. Unicode *input* streams need to be buffered, but *output* can always be insta-flushed. The only significance of Unicode to output is that a single character may cause multiple bytes to be output; and since output can block for even a single byte, it should be no different. +1 for making sys.stderr unbuffered. ChrisA From oscar.j.benjamin at gmail.com Tue Nov 3 10:52:27 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 3 Nov 2015 15:52:27 +0000 Subject: LU decomposition In-Reply-To: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> References: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> Message-ID: On 1 November 2015 at 10:04, gers antifx wrote: > > I have to write a LU-decomposition. My Code worked so far but (I want to become better:) ) I want to ask you, if I could write this LU-decomposition in a better way? > > def LU(x): > L = np.eye((x.shape[0])) > n = x.shape[0] > for ii in range(n-1): > for ll in range(1+ii,n): > factor = float(x[ll,ii])/x[ii,ii] > L[ll,ii] = factor > for kk in range(0+ii,n): > x[ll,kk] = x[ll,kk] - faktor*x[ii,kk] > LU = np.dot(L,x) You're using ii and ll, kk etc. This is common practise in Matlab code because Matlab uses i as sqrt(-1) but this is spelled 1j in Python so we don't have that problem. In this sort of context it would be more natural to use simply i, j, k in Python. Another is that you're not checking for divide by zero in float(x[ll,ii])/x[ii,ii]. Are you sure that it will not be zero? What happens if e.g. x[0, 0] is zero? This is where you'll need to use pivoting which complicates the algorithm a bit. -- Oscar From kwpolska at gmail.com Tue Nov 3 11:01:42 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Tue, 3 Nov 2015 17:01:42 +0100 Subject: Python PNG Viewer(Browser Based) In-Reply-To: <9c24559b-17a4-41fc-80a2-9258fd84c9f1@googlegroups.com> References: <9c24559b-17a4-41fc-80a2-9258fd84c9f1@googlegroups.com> Message-ID: On 3 November 2015 at 12:54, Arshpreet Singh wrote: > Hello Everyone, > > I am looking for Browser-based PNG file viewer written in > Python.(Flask framework preferably) > > Following project(Flask-Based) provides many things(File manager as > well as file viewer) but it does not support PNG files. > > https://github.com/vmi356/filemanager > > Any idea if I have to write my own browser based PNG viewer from > scratch(Using PIL or other required library) > > On the other side if I have to write only Desktop-based only two lines > are enough to do many things: > > Like, > > from PIL import Image > f = Image.open("file.png").show() > > > But I am not getting right sense that how to make possible using Python+Flask. > > Hope I am able to tell my problem? > -- > https://mail.python.org/mailman/listinfo/python-list Your problem is lack of basic understanding of the Internet. Because EVERY graphical web browser supports PNG files NATIVELY. With a single tag. Just figure out where to add the PNG handler code and read any random ?how to add images to a webpage? tutorial. You might need a new template and some code that is aware of the file being an image. But absolutely no PNG viewer is necessary. -- Chris Warrick PGP: 5EAAEA16 From Seymore4Head at Hotmail.invalid Tue Nov 3 11:10:20 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 03 Nov 2015 11:10:20 -0500 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Tue, 3 Nov 2015 10:34:12 -0500, Joel Goldstick wrote: >On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head >wrote: > >> On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase >> wrote: >> >> >On 2015-11-02 20:09, Seymore4Head wrote: >> >> How do I make a regular expression that returns true if the end of >> >> the line is an asterisk >> > >> >Why use a regular expression? >> > >> > if line[-1] == '*': >> > yep(line) >> > else: >> > nope(line) >> > >> >-tkc >> > >> > >> Because that is the part of Python I am trying to learn at the moment. >> > >Are we to infer that you were aware of doing the if line[-1] == '*': ... >, but just wanted to learn how to do the same thing with regex? Or that you >heard about regexes and thought that would be the way to solve your puzzle? > >> Thanks >> -- >> https://mail.python.org/mailman/listinfo/python-list >> Yes I knew that -1 represents the end character. It is not a question of trying to accomplish anything. I was just practicing with regex and wasn't sure how to express a * since it was one of the instructions. From rosuav at gmail.com Tue Nov 3 11:20:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Nov 2015 03:20:04 +1100 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Wed, Nov 4, 2015 at 3:10 AM, Seymore4Head wrote: > Yes I knew that -1 represents the end character. It is not a question > of trying to accomplish anything. I was just practicing with regex > and wasn't sure how to express a * since it was one of the > instructions. In that case, it's nothing to do with ending a string. What you really want to know is: How do you match a '*' using a regular expression? Which is what MRAB answered, courtesy of a working crystal ball: You use '\*'. Everything about the end of the string is irrelevant. (So, too, are all the comments about using [-1] or string methods. But we weren't to know that.) ChrisA From ian.g.kelly at gmail.com Tue Nov 3 11:23:46 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Nov 2015 09:23:46 -0700 Subject: Detection of a specific sound In-Reply-To: References: Message-ID: On Tue, Nov 3, 2015 at 7:45 AM, William Ray Wing wrote: > >> On Oct 25, 2015, at 8:17 PM, Montana Burr wrote: >> >> I'm looking for a library that will allow Python to listen for the shriek of a smoke alarm. Once it detects this shriek, it is to notify someone. Ideally, specificity can be adjusted for the user's environment. For example, I expect to need moderate specificity as I live in a quiet neighborhood, but an apartment dweller might need more. >> >> I'm thinking of recording a smoke alarm and having the program try to find the recorded sound in the stream from the microphone. >> > > I?ve been watching this thread and finally decided to jump in. I love how in the past 24 hours five more people have piled onto this thread even though the OP hasn't posted any followup since the original question nine days ago. From marco.nawijn at colosso.nl Tue Nov 3 11:25:45 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Tue, 3 Nov 2015 08:25:45 -0800 (PST) Subject: Python PNG Viewer(Browser Based) In-Reply-To: <9c24559b-17a4-41fc-80a2-9258fd84c9f1@googlegroups.com> References: <9c24559b-17a4-41fc-80a2-9258fd84c9f1@googlegroups.com> Message-ID: <5732e5a4-23d4-43df-8af7-41be14ab37dc@googlegroups.com> On Tuesday, November 3, 2015 at 12:55:09 PM UTC+1, Arshpreet Singh wrote: > Hello Everyone, > > I am looking for Browser-based PNG file viewer written in > Python.(Flask framework preferably) > > Following project(Flask-Based) provides many things(File manager as > well as file viewer) but it does not support PNG files. > > https://github.com/vmi356/filemanager > > Any idea if I have to write my own browser based PNG viewer from > scratch(Using PIL or other required library) > > On the other side if I have to write only Desktop-based only two lines > are enough to do many things: > > Like, > > from PIL import Image > f = Image.open("file.png").show() > > > But I am not getting right sense that how to make possible using Python+Flask. > > Hope I am able to tell my problem? Well, if you only want to open the PNG file in the webbrowser (in contrast of serving them over the internet), you can do it in two lines too: import webbrowser webbrowser.open('file.png') But this is probably not what you want. M. From harvesting at makes.email.invalid Tue Nov 3 11:42:20 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Tue, 03 Nov 2015 18:42:20 +0200 Subject: Irregular last line in a text file, was Re: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> Message-ID: Peter Otten writes: > Jussi Piitulainen wrote: >> Peter Otten writes: >> >>> If a "line" is defined as a string that ends with a newline >>> >>> def ends_in_asterisk(line): >>> return False >>> >>> would also satisfy the requirement. Lies, damned lies, and specs ;) >> >> Even if a "line" is defined as a string that comes from reading >> something like a file with default options, a line may end in >> an asterisk. > > Note that the last line from the file is not a line as defined by me > in the above post ;) Noted. >>>>> [ line.endswith('*') for line in StringIO('rivi*\nrivi*\nrivi*') ] >> [False, False, True] > > I wish there were a way to prohibit such files. Maybe a special value > > with open(..., newline="normalize") f: > assert all(line.endswith("\n") for line in f) > > to ensure that all lines end with "\n"? I'd like that. It should be the default. From joel.goldstick at gmail.com Tue Nov 3 11:55:53 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 3 Nov 2015 11:55:53 -0500 Subject: Detection of a specific sound In-Reply-To: References: Message-ID: On Tue, Nov 3, 2015 at 11:23 AM, Ian Kelly wrote: > On Tue, Nov 3, 2015 at 7:45 AM, William Ray Wing wrote: > > > >> On Oct 25, 2015, at 8:17 PM, Montana Burr > wrote: > >> > >> I'm looking for a library that will allow Python to listen for the > shriek of a smoke alarm. Once it detects this shriek, it is to notify > someone. Ideally, specificity can be adjusted for the user's environment. > For example, I expect to need moderate specificity as I live in a quiet > neighborhood, but an apartment dweller might need more. > >> > >> I'm thinking of recording a smoke alarm and having the program try to > find the recorded sound in the stream from the microphone. > >> > > > > I?ve been watching this thread and finally decided to jump in. > > I love how in the past 24 hours five more people have piled onto this > thread even though the OP hasn't posted any followup since the > original question nine days ago. > -- > https://mail.python.org/mailman/listinfo/python-list > Sometimes (maybe most times) the follow on discussion goes off on insightful tangents that may have little to do with the OP. -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From python.list at tim.thechases.com Tue Nov 3 11:56:53 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 3 Nov 2015 10:56:53 -0600 Subject: Irregular last line in a text file, was Re: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> Message-ID: <20151103105653.622d5e34@bigbox.christie.dr> On 2015-11-03 16:35, Peter Otten wrote: > I wish there were a way to prohibit such files. Maybe a special > value > > with open(..., newline="normalize") f: > assert all(line.endswith("\n") for line in f) > > to ensure that all lines end with "\n"? Or even more valuable to me: with open(..., newline="strip") as f: assert all(not line.endswith(("\n", "\r")) for line in f) because I have countless loops that look something like with open(...) as f: for line in f: line = line.rstrip('\r\n') process(line) -tkc From israel at ravnalaska.net Tue Nov 3 12:05:19 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Tue, 3 Nov 2015 08:05:19 -0900 Subject: CherryPy cpstats and ws4py Message-ID: I posted this to the CherryPy and ws4py mailing lists, but in the week since I did that I've only gotten two or three views on each list, and no responses, so as a last-ditch effort I thought I'd post here. Maybe someone with more general python knowledge than me can figure out the traceback and from there a solution. Is it possible to use ws4py in conjunction with the cpstats CherryPy tool? I have a CherryPy (3.8.0) web app that uses web sockets via ws4py. Tested and working. I am now trying to get a little more visibility into the functioning of the server, so to that end I enabled the cpstats tool by adding the following line to my '/' configuration: tools.cpstats.on=True Unfortunately, as soon as I do that, attempts to connect a web socket start failing with the following traceback: [28/Oct/2015:08:18:48] Traceback (most recent call last): File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 104, in run hook() File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 63, in __call__ return self.callback(**self.kwargs) File "build/bdist.macosx-10.10-intel/egg/ws4py/server/cherrypyserver.py", line 200, in upgrade ws_conn = get_connection(request.rfile.rfile) File "build/bdist.macosx-10.10-intel/egg/ws4py/compat.py", line 43, in get_connection return fileobj._sock AttributeError: 'KnownLengthRFile' object has no attribute '_sock' [28/Oct/2015:08:18:48] HTTP Request Headers: PRAGMA: no-cache COOKIE: autoTabEnabled=true; fleetStatusFilterCompany=7H; fleetStatusFilterLocation=ALL; fleetStatusRefreshInterval=5; inputNumLegs=5; session_id=5c8303896aff419c175c79dfadbfdc9d75e6c45a UPGRADE: websocket HOST: flbubble.ravnalaska.net:8088 ORIGIN: http://flbubble.ravnalaska.net CONNECTION: Upgrade CACHE-CONTROL: no-cache SEC-WEBSOCKET-VERSION: 13 SEC-WEBSOCKET-EXTENSIONS: x-webkit-deflate-frame USER-AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7 SEC-WEBSOCKET-KEY: Szh6Uoe+WzqKR1DgW8JcXA== Remote-Addr: 10.9.1.59 [28/Oct/2015:08:18:48] HTTP Traceback (most recent call last): File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 661, in respond self.hooks.run('before_request_body') File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 114, in run raise exc AttributeError: 'KnownLengthRFile' object has no attribute '_sock' Disable tools.cpstats.on, and the sockets start working again. Is there some way I can fix this so I can use sockets as well as gather stats from my application? Thanks. ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- From gandalf at shopzeus.com Tue Nov 3 12:35:43 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Tue, 3 Nov 2015 18:35:43 +0100 Subject: pybabel extraction mess Message-ID: <5638F06F.4010902@shopzeus.com> If I have a large project with multiple directories, then I may want to assign different translation domains for different subpackages. Suppose I have this directory structure: main | |--- sub1 | |--- sub2 | |---- sub2.1 | |---- sub2.2 There are python source files in subpackages, and also at upper level packages. Some examples: main/test1.py main/sub1/test2.py main/sub2/test3.py main/sub2/sub2.1/test4.py main/sub2/sub2.2/test5.py .... I cannot find out how to run pybabel so that messages from different subdirectories gets extracted into different catalog files. The main problem is that pybabel expects a directory. Let's say that I want to have a different domain for main/sub2/sub2.1, and another domain for everything else. I can extract messages from main/sub/sub2.1 with "pybabel extract main/sub/sub2.1", but I'm not able to extract all the others into a different pot file. Simply because "pybabel extract main" will extract all messages from main/sub2/sub2.1 again. There is no way to extract from a list of files. Just from directories. It does not seem possible to specify disjunct sets of files for message catalogs. For a small project, this is not a problem. If I have at least one file at the main level, then all other files MUST be bound to the same domain, because the top level file can only be extracted by giving the top directory to pybabel, but that will also extract everything else from the whole project. I would really like to divide messages into different domains. But how? Is there a way to run pybabel programatically on a list of source files? Thanks, Laszlo From __peter__ at web.de Tue Nov 3 12:44:36 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Nov 2015 18:44:36 +0100 Subject: Irregular last line in a text file, was Re: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> <20151103105653.622d5e34@bigbox.christie.dr> Message-ID: Tim Chase wrote: > On 2015-11-03 16:35, Peter Otten wrote: >> I wish there were a way to prohibit such files. Maybe a special >> value >> >> with open(..., newline="normalize") f: >> assert all(line.endswith("\n") for line in f) >> >> to ensure that all lines end with "\n"? > > Or even more valuable to me: > > with open(..., newline="strip") as f: > assert all(not line.endswith(("\n", "\r")) for line in f) > > because I have countless loops that look something like > > with open(...) as f: > for line in f: > line = line.rstrip('\r\n') > process(line) Indeed. It's obvious now you're saying it... From george.trojan at noaa.gov Tue Nov 3 13:03:51 2015 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 03 Nov 2015 18:03:51 +0000 Subject: Unbuffered stderr in Python 3 In-Reply-To: References: Message-ID: <5638F707.90309@noaa.gov> On 11/03/2015 05:00 PM, python-list-request at python.org wrote: > On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote: > >> In Python 2, stderr is unbuffered. >> >> In most other environments (the shell, C...) stderr is unbuffered. >> >> It is usually considered a bad, bad thing for stderr to be buffered. What >> happens if your application is killed before the buffer fills up? The >> errors in the buffer will be lost. >> >> So how come Python 3 has line buffered stderr? And more importantly, how >> can I turn buffering off? > It's probably related to the fact that std{in,out,err} are Unicode > streams. > > > type(sys.stderr) > > > type(sys.stderr.buffer) > > > type(sys.stderr.buffer.raw) > > > It appears that you can turn it off with: > > sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw) > or: > sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach()) > > This results in a sys.stderr which appears to work and whose > .line_buffering property is False. > > This does set line buffering, but does not change the behaviour: (devenv-3.4.1) dilbert at gtrojan> cat x.py import sys import time if sys.version>'3': import io sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach()) #sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw) print(sys.stderr.line_buffering) sys.stderr.write('a') time.sleep(10) This is python2.7.5. a is printed before ^C. (devenv-3.4.1) dilbert at gtrojan> /bin/python x.py a^CTraceback (most recent call last): Here buffer is flushed on close, after typing ^C. (devenv-3.4.1) dilbert at gtrojan> python x.py False ^CaTraceback (most recent call last): George From esawiek at gmail.com Tue Nov 3 13:18:49 2015 From: esawiek at gmail.com (Ek Esawi) Date: Tue, 3 Nov 2015 13:18:49 -0500 Subject: cvxopt install problem Message-ID: Hi All? I needed to install cvxopt on a 64 bit W7. I found out that cvxopt is incompatible with a 64 bit. It only compatible with a 32 bit which can be installed on a 64 bit computer and it works. I stumbled on this on another discussion group posting. The suggestion was to install python 32 bit on a 64 bit computer, then download cvxopt and install it via conda. Here is the suggestion from the posting [If you are using Windows, an easy solution could be the Anaconda distribution (http://continuum.io/downloads). Select and install the 32 bit version. It will be easier to install the cvxopt package. Search it in the binstar repository ( https://binstar.org/search?q=cvxopt). Open a console terminal and install it (e. g. "conda install -chttps://conda.binstar.org/omnia cvxopt").?] I did everything except the last command to install cvxopt, that?s ?conda install -chttps://conda.binstar.org/omnia cvxopt". Here is the command I used: conda install c:/Users/eesawi0001/Downloads/cvxopt-1.1.7-py34.tar I kept getting invalid syntax Any help is greatly appreciated. EKE From gandalf at shopzeus.com Tue Nov 3 13:21:33 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Tue, 3 Nov 2015 19:21:33 +0100 Subject: LU decomposition In-Reply-To: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> References: <1e6c4ce1-885c-43ac-b0a5-054f46d4c96e@googlegroups.com> Message-ID: <5638FB2D.3060307@shopzeus.com> > Hey, > > I have to write a LU-decomposition. My Code worked so far but (I want to become better:) ) I want to ask you, if I could write this LU-decomposition in a better way? Why can't you just use scipy for this? http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.linalg.lu.html Do you really need to reinvent the wheel? From george.trojan at noaa.gov Tue Nov 3 13:31:32 2015 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 03 Nov 2015 18:31:32 +0000 Subject: Unbuffered stderr in Python 3 In-Reply-To: <5638F707.90309@noaa.gov> References: <5638F707.90309@noaa.gov> Message-ID: <5638FD84.3060402@noaa.gov> -------- Forwarded Message -------- Subject: Re: Unbuffered stderr in Python 3 Date: Tue, 03 Nov 2015 18:03:51 +0000 From: George Trojan To: python-list at python.org On 11/03/2015 05:00 PM, python-list-request at python.org wrote: > On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote: > >> In Python 2, stderr is unbuffered. >> >> In most other environments (the shell, C...) stderr is unbuffered. >> >> It is usually considered a bad, bad thing for stderr to be buffered. What >> happens if your application is killed before the buffer fills up? The >> errors in the buffer will be lost. >> >> So how come Python 3 has line buffered stderr? And more importantly, how >> can I turn buffering off? > It's probably related to the fact that std{in,out,err} are Unicode > streams. > > > type(sys.stderr) > > > type(sys.stderr.buffer) > > > type(sys.stderr.buffer.raw) > > > It appears that you can turn it off with: > > sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw) > or: > sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach()) > > This results in a sys.stderr which appears to work and whose > .line_buffering property is False. > > This does set line buffering, but does not change the behaviour: (devenv-3.4.1) dilbert at gtrojan> cat x.py import sys import time if sys.version>'3': import io sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach()) #sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw) print(sys.stderr.line_buffering) sys.stderr.write('a') time.sleep(10) This is python2.7.5. a is printed before ^C. (devenv-3.4.1) dilbert at gtrojan> /bin/python x.py a^CTraceback (most recent call last): Here buffer is flushed on close, after typing ^C.// (devenv-3.4.1) dilbert at gtrojan> python x.py False ^CaTraceback (most recent call last): George Found it. write_through must be set to True. (devenv-3.4.1) dilbert at gtrojan> cat x.py import sys import time if sys.version>'3': import io sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach(), write_through=True) #sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw) print(sys.stderr.line_buffering) sys.stderr.write('a') time.sleep(10) (devenv-3.4.1) dilbert at gtrojan> python x.py False a^CTraceback (most recent call last): / / From ian.g.kelly at gmail.com Tue Nov 3 13:33:55 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Nov 2015 11:33:55 -0700 Subject: Irregular last line in a text file, was Re: Regular expressions In-Reply-To: <20151103105653.622d5e34@bigbox.christie.dr> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> <20151103105653.622d5e34@bigbox.christie.dr> Message-ID: On Tue, Nov 3, 2015 at 9:56 AM, Tim Chase wrote: > On 2015-11-03 16:35, Peter Otten wrote: >> I wish there were a way to prohibit such files. Maybe a special >> value >> >> with open(..., newline="normalize") f: >> assert all(line.endswith("\n") for line in f) >> >> to ensure that all lines end with "\n"? > > Or even more valuable to me: > > with open(..., newline="strip") as f: > assert all(not line.endswith(("\n", "\r")) for line in f) > > because I have countless loops that look something like > > with open(...) as f: > for line in f: > line = line.rstrip('\r\n') > process(line) What would happen if you read a file opened like this without iterating over lines? From ian.g.kelly at gmail.com Tue Nov 3 13:39:32 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Nov 2015 11:39:32 -0700 Subject: Irregular last line in a text file, was Re: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> <20151103105653.622d5e34@bigbox.christie.dr> Message-ID: On Tue, Nov 3, 2015 at 11:33 AM, Ian Kelly wrote: > On Tue, Nov 3, 2015 at 9:56 AM, Tim Chase wrote: >> Or even more valuable to me: >> >> with open(..., newline="strip") as f: >> assert all(not line.endswith(("\n", "\r")) for line in f) >> >> because I have countless loops that look something like >> >> with open(...) as f: >> for line in f: >> line = line.rstrip('\r\n') >> process(line) > > What would happen if you read a file opened like this without > iterating over lines? I think I'd go with this: >>> def strip_newlines(iterable): ... for line in iterable: ... yield line.rstrip('\r\n') ... >>> list(strip_newlines(['one\n', 'two\r', 'three'])) ['one', 'two', 'three'] Or if I care about optimizing the for loop (but we're talking about file I/O, so probably not), this might be faster: >>> import operator >>> def strip_newlines(iterable): ... return map(operator.methodcaller('rstrip', '\r\n'), iterable) ... >>> list(strip_newlines(['one\n', 'two\r', 'three'])) ['one', 'two', 'three'] Then the iteration is just: for line in strip_newlines(f): From anthony at cajuntechie.org Tue Nov 3 14:09:06 2015 From: anthony at cajuntechie.org (Anthony Papillion) Date: Tue, 03 Nov 2015 13:09:06 -0600 Subject: Creating PST files using Python Message-ID: <873907D8-7E21-4F08-AF07-A83F766802BA@cajuntechie.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 Does anyone know of a module that allows the wiring of Outlook PST files using Python? I'm working on a project that will require me to migrate 60gb of maildir mail (multiple accounts) to Outlook. Thanks Anthony - -- Sent from my Android device with K-9 Mail. Please excuse my brevity. -----BEGIN PGP SIGNATURE----- Version: APG v1.1.1 iQJJBAEBCgAzBQJWOQZSLBxBbnRob255IFBhcGlsbGlvbiA8YW50aG9ueUBjYWp1 bnRlY2hpZS5vcmc+AAoJEAKK33RTsEsVwdgP/1f15VCI0GKkM54ram8oL3Bh2e5s PqxhS/qe+9pYwYZrt+Dj2EENtpdwVQxIin67WxsruE1hOYcrrZiURiCaav8aL//3 zMiBwtEIHrYZ+0s54rfQTx1eltlET3c9O/Hehh69TtuLWiCYp1fKUW7pJEV2ZnqV jLoGLeQ1BkXCukVeRVm8W8q7aBycF9jLP/Hg7r7p7g1RUYoIfUCOd0833AAHrbb4 CpSgvsztUfK7mJR9yxcWl4QPFTq3wpZA9MnXqnS/+UxqLSVRJp66omYn31w1AqQA 7XTuP3TQ4GjhPJC6uGiQUNQslBWj5FYRUQxlH/CzUFMeLpbK+ruG8K3QyNG8tFpj TdUNxeWeRl+Sf5elgDYDe4Farn82ZborOlZmMspy/S87tENDgs1rND9/wIgnXtrt g7sK3eVkmbBXkIqA9xXwkmx5GyHn3+o5a8JhFihePy5XnvlfAsnhjzsogTN3pYdO YSKqR76cTTLzYuOjiF61DIgY1R/HqUsiloGiVXjfghV+ADcFLhADIJGa7wKwSItv TjZmUKjF2U7CaNqn6mTR83VdtOymeoQyTZw9sB0WmsVVjVinOuExyy3qa9D3E07D yfaa/RVgGLw6ygq/8JTXQx8B8xJ5lOl7KBxVNqaS9Kwx14F3aQdrDqvZRDCpU7U5 X/FC8f6YIksLIX7y =254i -----END PGP SIGNATURE----- From random832 at fastmail.com Tue Nov 3 14:45:11 2015 From: random832 at fastmail.com (Random832) Date: Tue, 03 Nov 2015 14:45:11 -0500 Subject: Unbuffered stderr in Python 3 References: <5638F707.90309@noaa.gov> Message-ID: <87pozqvpdk.fsf@fastmail.com> George Trojan writes: > This does set line buffering, but does not change the behaviour: The opposite of line buffering is not no buffering, but full (i.e. block) buffering, that doesn't get flushed until it runs out of space. TextIOWrapper has its own internal buffer, and its design apparently doesn't contemplate the possibility of using it with a raw FileIO object (which may mean that the posted code isn't guaranteed to work) or disabling buffering. From python.list at tim.thechases.com Tue Nov 3 14:45:47 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 3 Nov 2015 13:45:47 -0600 Subject: Irregular last line in a text file, was Re: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> <20151103105653.622d5e34@bigbox.christie.dr> Message-ID: <20151103134547.3556cc74@bigbox.christie.dr> On 2015-11-03 11:39, Ian Kelly wrote: > >> because I have countless loops that look something like > >> > >> with open(...) as f: > >> for line in f: > >> line = line.rstrip('\r\n') > >> process(line) > > > > What would happen if you read a file opened like this without > > iterating over lines? > > I think I'd go with this: > > >>> def strip_newlines(iterable): > ... for line in iterable: > ... yield line.rstrip('\r\n') > ... Behind the scenes, this is what I usually end up doing, but the effective logic is the same. I just like the notion of being able to tell open() that I want iteratation to happen over the *content* of the lines, ignoring the new-line delimiters. I can't think of more than 1-2 times in my last 10+ years of Pythoning that I've actually had potential use for the newlines, usually on account of simply feeding the entire line back into some filelike.write() method where I wanted the newlines in the resulting file. But even in those cases, I seem to recall stripping off the arbitrary newlines (LF vs. CR/LF) and then adding my own known line delimiter. -tkc From no.email at nospam.invalid Tue Nov 3 14:59:24 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 03 Nov 2015 11:59:24 -0800 Subject: Modern recommended exception handling practices? References: <52739457-5f7a-48ea-8835-9fc8934174f9@googlegroups.com> <56385887$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87h9l2yhur.fsf@nightsong.com> Chris Angelico writes: > Aside from string exceptions and the "except Type, e:" syntax, I would > agree with you. Actually, I can't think of any "obsolete > exception-handling practices" in any language. I'd say that context managers are a big recent improvement in Python over dealing with a lot of exceptions explicitly. From rosuav at gmail.com Tue Nov 3 17:12:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Nov 2015 09:12:45 +1100 Subject: Creating PST files using Python In-Reply-To: <873907D8-7E21-4F08-AF07-A83F766802BA@cajuntechie.org> References: <873907D8-7E21-4F08-AF07-A83F766802BA@cajuntechie.org> Message-ID: On Wed, Nov 4, 2015 at 6:09 AM, Anthony Papillion wrote: > Does anyone know of a module that allows the wiring of Outlook PST files using Python? I'm working on a project that will require me to migrate 60gb of maildir mail (multiple accounts) to Outlook. > *wince* I don't, but if there is such a thing, it'll probably be mentioned here: https://pypi.python.org But be careful. My gut feeling is that the format will be different in every version of Outlook, so you'll need something exactly matching it. Since you're migrating your mail *to* Outlook, I'd look for some means of importing mail. Worst case, you could create a bunch of files in the maildir layout, spin up an off-the-shelf POP3 server, and tell Outlook to read it all. Personally, though, I'd refuse the job altogether. Creating a 60GB blob of mail is going to cause nothing but pain. That might even be beyond Outlook's current hard limit - I don't know. Bad, bad idea. ChrisA From invalid at invalid.invalid Tue Nov 3 17:15:58 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 Nov 2015 22:15:58 +0000 (UTC) Subject: Irregular last line in a text file, was Re: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> <20151103105653.622d5e34@bigbox.christie.dr> Message-ID: On 2015-11-03, Tim Chase wrote: [re. iterating over lines in a file] > I can't think of more than 1-2 times in my last 10+ years of > Pythoning that I've actually had potential use for the newlines, If you can think of 1-2 times when you've been interating over the lines in a file and wanted to see the EOL markers, then that's 1-2 times more than I've ever wanted to see them since I started using Python 16 years ago... -- Grant Edwards grant.b.edwards Yow! ! Up ahead! It's a at DONUT HUT!! gmail.com From tjreedy at udel.edu Tue Nov 3 17:25:55 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 3 Nov 2015 17:25:55 -0500 Subject: Unbuffered stderr in Python 3 In-Reply-To: References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> Message-ID: On 11/3/2015 10:42 AM, Chris Angelico wrote: > On Wed, Nov 4, 2015 at 2:00 AM, Random832 wrote: >> Nobody writes: >> >>> It's probably related to the fact that std{in,out,err} are Unicode >>> streams. >> >> There's no fundamental reason a Unicode stream should have to be line >> buffered. If it's "related", it's only in that an oversight was made in >> the course of making that change. The current behavior is not an 'oversight'. I was considered, decided, and revisited in https://bugs.python.org/issue13601. Guido: "Line-buffering should be good enough since in practice errors messages are always terminated by a newline." If not, print(part_line, file=sys.stderr, flush=True) works for the unusual case. > Yep. Unicode *input* streams need to be buffered, but *output* can > always be insta-flushed. The only significance of Unicode to output is > that a single character may cause multiple bytes to be output; and > since output can block for even a single byte, it should be no > different. > > +1 for making sys.stderr unbuffered. - Terry Jan Reedy From robin.koch at t-online.de Tue Nov 3 17:58:33 2015 From: robin.koch at t-online.de (Robin Koch) Date: Tue, 3 Nov 2015 23:58:33 +0100 Subject: Regular expressions In-Reply-To: <0cb3abb6-ec1e-4357-ab0f-b018d0c688fa@googlegroups.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <0cb3abb6-ec1e-4357-ab0f-b018d0c688fa@googlegroups.com> Message-ID: Am 03.11.2015 um 05:23 schrieb rurpy at yahoo.com: > Of course there are people who misuse regexes. /^1?$|^(11+?)\1+$/ There are? 0:-) -- Robin Koch From cs at zip.com.au Tue Nov 3 19:10:23 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Nov 2015 11:10:23 +1100 Subject: Creating PST files using Python In-Reply-To: References: Message-ID: <20151104001023.GA79983@cskk.homeip.net> On 04Nov2015 09:12, Chris Angelico wrote: >On Wed, Nov 4, 2015 at 6:09 AM, Anthony Papillion > wrote: >> Does anyone know of a module that allows the wiring of Outlook PST files using Python? I'm working on a project that will require me to migrate 60gb of maildir mail (multiple accounts) to Outlook. > >*wince* > >I don't, but if there is such a thing, it'll probably be mentioned here: >https://pypi.python.org > >But be careful. My gut feeling is that the format will be different in >every version of Outlook, so you'll need something exactly matching >it. Microsoft have a page here: https://msdn.microsoft.com/en-us/library/ff385210%28v=office.12%29.aspx which purports to document the PST format. There are links to the document sections and also to PDFs. It seems to be a simple and understandable format of a mere 190 pages. Yes, I am joking, though not about the page count; it seems like an obscene and totally nuts way to store email. IIRC, M$ LookOut! doesn't even use Message-IDs, but some proprietry scheme. >Since you're migrating your mail *to* Outlook, I'd look for some means >of importing mail. Worst case, you could create a bunch of files in >the maildir layout, The OP has these I think. >spin up an off-the-shelf POP3 server, and tell >Outlook to read it all. > >Personally, though, I'd refuse the job altogether. Creating a 60GB >blob of mail is going to cause nothing but pain. That might even be >beyond Outlook's current hard limit - I don't know. Bad, bad idea. It is a very strange request. But very corporate/government in mindset. Alas, I cannot help to the with any tools or module for his task. Cheers, Cameron Simpson Microsoft Mail: as far from RFC-822 as you can get and still pretend to care. - Abby Franquemont-Guillory From rurpy at yahoo.com Tue Nov 3 19:22:53 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 3 Nov 2015 16:22:53 -0800 (PST) Subject: Regular expressions In-Reply-To: <56385efc$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56385efc$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <455b6498-5104-491a-98c2-6f7e48142496@googlegroups.com> On 11/03/2015 12:15 AM, Steven D'Aprano wrote: > On Tue, 3 Nov 2015 03:23 pm, rurpy wrote: > >> Regular expressions should be learned by every programmer or by anyone >> who wants to use computers as a tool. They are a fundamental part of >> computer science and are used in all sorts of matching and searching >> from compilers down to your work-a-day text editor. > > You are absolutely right. > > If only regular expressions weren't such an overly-terse, cryptic > mini-language, with all but no debugging capabilities, they would be great. > > If only there wasn't an extensive culture of regular expression abuse within > programming communities, they would be fine. > > All technologies are open to abuse. But we don't say: > > Some people, when confronted with a problem, think "I know, I'll use > arithmetic." Now they have two problems. > > because abuse of arithmetic is rare. It's hard to misuse it, and while > arithmetic can be complicated, it's rare for programmers to abuse it. But > the same cannot be said for regexes -- they are regularly misused, abused, > and down-right hard to use right even when you have a good reason for using > them: > > http://www.thedailywtf.com/articles/Irregular_Expression > > http://blog.codinghorror.com/regex-use-vs-regex-abuse/ > > http://psung.blogspot.com.au/2008/01/wonderful-abuse-of-regular-expressions.html Thanks for pointing out three cases of misuse of regexes out of the approximately 375000000 [*] uses of regexes in the wild. I hope you're not dumb enough to think that constitutes significant evidence. Even worse, of the three only one was a real example. One of the others was machine-generated code, the other was a "look what you can do with regexes" example, not serious code. Here is an example of "abusing" python https://benkurtovic.com/2014/06/01/obfuscating-hello-world.html I wouldn't use this as evidence that Python is to be avoided. > If there is one person who has done more to create a regex culture, it is > Larry Wall, inventor of Perl. Even Larry Wall says that regexes are > overused and their syntax is harmful, and he has recreated them for Perl 6: > > http://www.perl.com/pub/2002/06/04/apo5.html You really should have read beyond the first paragraph. He proposes fixing regexes by adding even more special character combinations and making regexes even *more* powerful. (He turned them into full-blown parsers.) Nowhere does he advocate not using, or avoiding if possible, regexes as is the mantra in this list. Here is Larry's "recreation" that you are touting: http://design.perl6.org/S05.html Please explain to us how you think this "fix" addresses the complaints you and other Python anti-regexers have about regexes. I hope you also noted Larry's tongue-in-cheek writing style. Right after pointing out that some claim Perl is hard to read due largely to regex syntax, he writes: "Funny that other languages have been borrowing Perl's regular expressions as fast as they can..." So I don't think you can claim Larry Wall as a supporter of this list's anti-regex attitude beyond some superficial verbiage taken out of context. > Oh, and the icing on the cake, regexes can be a security vulnerability too: > https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS And here is a list of CVEs involving Python. There are (at time of writing) 190 of them. http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=python So if a security vulnerability is reason not to use regexes, we should all be *running* from Python. I sure you'll point out that most have been fixed. But you failed to point out that same is true of regex engines. From your source: "Notice, that not all algorithms are na?ve, and actually Regex algorithms can be written in an efficient way." And in fact, again, had you looked beyond a headline that suited your purpose, you could have tried the "Evil Regexes" noted in that source and discovered none of them are a DoS in Python. Even were that not true, normal practice applies: if the input is untrusted then sanitize it, or mitigate the threat by imposing a timeout, etc. Not exactly a problem or solution unique to regexes. And common sense should tell you that since there are a lot of "try a regex" web sites, this is not a problem without a solution. And *certainly* not a reason not to use them in the *far* more common case when they *are* trusted because you are in control of them, Finally, preemptively, I'll repeat I acknowledge regexs are not the the optimum solution in every case where they could be used. But they are very useful when one passes the border of the trivial; and they are nowhere near as bad as routinely portrayed here. ---- [*] Yes, I made that number up. From rurpy at yahoo.com Tue Nov 3 19:33:17 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 3 Nov 2015 16:33:17 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Monday, November 2, 2015 at 9:38:24 PM UTC-7, Michael Torrie wrote: > On 11/02/2015 09:23 PM, rurpy--- via Python-list wrote: > >> My completely unsolicited advice is that regular expressions shouldn't be > >> very high on the list of things to learn. They are very useful, and very > >> tricky and prone many problems that can and should be learned to be > >> resolved with much simpler methods. If you really want to learn regular > >> expressions, that's great but the problem you posed is not one for which > >> they are the best solution. Remember simpler is better than complex. > > > > Regular expressions should be learned by every programmer or by anyone > > who wants to use computers as a tool. They are a fundamental part of > > computer science and are used in all sorts of matching and searching > > from compilers down to your work-a-day text editor. > > > > Not knowing how to use them is like an auto mechanic not knowing how to > > use a socket wrench. > > Not quite. Core language concepts like ifs, loops, functions, > variables, slicing, etc are the socket wrenches of the programmer's > toolbox. Regexs are like an electric impact socket wrench. You can do > the same work without it, but in many cases it's slower. But you have to > learn the other hand tools first in order to really use the electric > driver properly (understanding torques, direction of threads, etc), lest > you wonder why you're breaking off so many bolts with the torque of the > impact drive. I consider regexs more fundemental. One need not even be a programmer to use them: consider grep, sed, a zillion editors, database query languages, etc. When there is a mini-language explicitly developed for describing string patterns, why, except is very simple cases, would one not take advantage of it? Beyond trivial operations a regex, although terse (overly perhaps), is still likely to be more understandable more maintainable than bunch of ad-hoc code. And the relative ease of expressing complex patterns means one is more likely to create more specific patterns, resulting in detecting unexpected input earlier than with ad-hoc code. From rurpy at yahoo.com Tue Nov 3 19:46:21 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 3 Nov 2015 16:46:21 -0800 (PST) Subject: Creating PST files using Python In-Reply-To: References: Message-ID: <0ba52316-7f52-4314-a454-0a5d369feed6@googlegroups.com> On 11/03/2015 12:09 PM, Anthony Papillion wrote: > Does anyone know of a module that allows the wiring of Outlook PST > files using Python? I'm working on a project that will require me to > migrate 60gb of maildir mail (multiple accounts) to Outlook. I used libpst (http://www.five-ten-sg.com/libpst/) a few years ago successfully but I was going in the other direction (outlook -> maildir) so not sure if it does writing of pst files. At the time I also looked into libpff which (from my notes, I don't remember much of this work) was newer but the documentation was pretty thin and it wasn't worth the time to figure out how to use it. Of course things may have changed since then... From dpantele at dpantele.com Tue Nov 3 20:24:04 2015 From: dpantele at dpantele.com (Dmitry Panteleev) Date: Tue, 3 Nov 2015 20:24:04 -0500 Subject: Bugfixing python 3.5 asyncio Message-ID: Hello, There is a bug in asyncio.Queue (https://github.com/python/asyncio/issues/268), which makes it unusable for us. It is fixed in master now. What is the easiest way to patch the asyncio bundled with python if I have to distribute it among 5 colleagues? It is used in our private module. I can think of: 1. Copy asyncio.queues into our package so it has a different name 2. Override sys.path Both look really strange. Is there anything else? Thanks, Dmitry Panteleev From rurpy at yahoo.com Tue Nov 3 20:32:11 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 3 Nov 2015 17:32:11 -0800 (PST) Subject: Creating PST files using Python In-Reply-To: <0ba52316-7f52-4314-a454-0a5d369feed6@googlegroups.com> References: <0ba52316-7f52-4314-a454-0a5d369feed6@googlegroups.com> Message-ID: I should have checked the web site before posting, it appears that both libpst and libpff only read pst files, no write. Sorry for the noise. From torriem at gmail.com Tue Nov 3 21:04:23 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 03 Nov 2015 19:04:23 -0700 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <563967A7.4060308@gmail.com> On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote: > I consider regexs more fundemental. One need not even be a programmer > to use them: consider grep, sed, a zillion editors, database query > languages, etc. Grep can use regular expressions (and I do so with it regularly), but it's default mode is certainly not regular expressions, and it is still very powerful. I've never used regular expressions in a database query language; until this moment I didn't know any supported such things in their queries. Good to know. How you would index for regular expressions in queries I don't know. > When there is a mini-language explicitly developed for describing > string patterns, why, except is very simple cases, would one not > take advantage of it? Mainly because the programming language itself often can do it just as cleanly and just as fast (slicing, string methods, etc). I certainly programmed for many years without needing regular expressions in my small projects. In fact, REs are a bit of a pain to use in, say, C or C++, requiring a library. With Python they are much more readily accessible so I use them much more. But honestly it wasn't until college when I learned about finite state automata that I really grasped what regular expressions were and how to use them. > Beyond trivial operations a regex, although > terse (overly perhaps), is still likely to be more understandable > more maintainable than bunch of ad-hoc code. And the relative ease > of expressing complex patterns means one is more likely to create > more specific patterns, resulting in detecting unexpected input > earlier than with ad-hoc code. Maybe, maybe not. Using Python string class methods is probably more clear when such methods are sufficient. From dan at tombstonezero.net Tue Nov 3 21:55:12 2015 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 4 Nov 2015 02:55:12 -0000 (UTC) Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: On Tue, 03 Nov 2015 19:04:23 -0700, Michael Torrie wrote: > On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote: >> I consider regexs more fundemental. One need not even be a programmer >> to use them: consider grep, sed, a zillion editors, database query >> languages, etc. > > Grep can use regular expressions (and I do so with it regularly), but > it's default mode is certainly not regular expressions ... Its very name indicates that its default mode most certainly is regular expressions. Dan From python.list at tim.thechases.com Tue Nov 3 22:12:08 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 3 Nov 2015 21:12:08 -0600 Subject: Regular expressions In-Reply-To: <563967A7.4060308@gmail.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <563967A7.4060308@gmail.com> Message-ID: <20151103211208.2a7ec561@bigbox.christie.dr> On 2015-11-03 19:04, Michael Torrie wrote: > Grep can use regular expressions (and I do so with it regularly), > but it's default mode is certainly not regular expressions, and it > is still very powerful. I suspect you're thinking of `fgrep` (AKA "grep -F") which uses fixed strings rather than regular expressions. By default, `grep` certainly does use regular expressions: tim at linux$ seq 5 | grep "1*" tim at bsd$ jot 5 | grep "1*" will output the entire input, not just lines containing a "1" followed by an asterisk. > I've never used regular expressions in a database query language; > until this moment I didn't know any supported such things in their > queries. Good to know. How you would index for regular > expressions in queries I don't know. At least PostgreSQL allows for creating indexes on a particular regular expression. E.g. (shooting from the hip so I might have missed something): CREATE TABLE contacts ( -- ... phonenumber VARCHAR(15), -- ... ) CREATE INDEX contacts_just_phone_digits_idx ON contacts((regexp_replace(phonenumber, '[^0-9]', ''))); INSERT INTO contacts(..., phonenumber, ...) VALUES (..., '800-555-1212', ...) SELECT * FROM contacts WHERE -- should use contacts_just_phone_digits_idx regexp_replace(phonenumber, '[^0-9]', '') = '8005551212'; It's not as helpful as one might hope because you're stuck using a fixed regexp rather than an arbitrary regexp, but if you have a particular regexp you search for frequently, you can index it. Otherwise, you'd be doing full table-scans (or at least a full scan of whatever subset the active non-regexp'ed index yields) which can be pretty killer on performance. You'd have to research on other DB engines. -tkc From steve+comp.lang.python at pearwood.info Tue Nov 3 22:18:55 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 04 Nov 2015 14:18:55 +1100 Subject: Unbuffered stderr in Python 3 References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> Message-ID: <56397921$0$11094$c3e8da3@news.astraweb.com> On Wednesday 04 November 2015 09:25, Terry Reedy wrote: > On 11/3/2015 10:42 AM, Chris Angelico wrote: >> On Wed, Nov 4, 2015 at 2:00 AM, Random832 wrote: >>> Nobody writes: >>> >>>> It's probably related to the fact that std{in,out,err} are Unicode >>>> streams. >>> >>> There's no fundamental reason a Unicode stream should have to be line >>> buffered. If it's "related", it's only in that an oversight was made in >>> the course of making that change. > > The current behavior is not an 'oversight'. I was considered, decided, > and revisited in https://bugs.python.org/issue13601. Guido: > "Line-buffering should be good enough since in practice errors messages > are always terminated by a newline." If not, print(part_line, > file=sys.stderr, flush=True) works for the unusual case. This is one of the offending line from our code base: print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr) So that ought to be terminated by a newline. And yet, the stderr output doesn't show up until the program exits. -- Steve From steve+comp.lang.python at pearwood.info Tue Nov 3 22:23:04 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 04 Nov 2015 14:23:04 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <56397a18$0$11094$c3e8da3@news.astraweb.com> On Wednesday 04 November 2015 13:55, Dan Sommers wrote: > On Tue, 03 Nov 2015 19:04:23 -0700, Michael Torrie wrote: > >> On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote: >>> I consider regexs more fundemental. One need not even be a programmer >>> to use them: consider grep, sed, a zillion editors, database query >>> languages, etc. >> >> Grep can use regular expressions (and I do so with it regularly), but >> it's default mode is certainly not regular expressions ... > > Its very name indicates that its default mode most certainly is regular > expressions. I don't even know what grep stands for. But I think what Michael may mean is that if you "grep foo", no regex magic takes place since "foo" contains no metacharacters. -- Steven From rosuav at gmail.com Tue Nov 3 22:26:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Nov 2015 14:26:42 +1100 Subject: Regular expressions In-Reply-To: <20151103211208.2a7ec561@bigbox.christie.dr> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <563967A7.4060308@gmail.com> <20151103211208.2a7ec561@bigbox.christie.dr> Message-ID: On Wed, Nov 4, 2015 at 2:12 PM, Tim Chase wrote: > It's not as helpful as one might hope because you're stuck using a > fixed regexp rather than an arbitrary regexp, but if you have a > particular regexp you search for frequently, you can index it. > Otherwise, you'd be doing full table-scans (or at least a full scan > of whatever subset the active non-regexp'ed index yields) which can > be pretty killer on performance. If the regex anchors the start of the string, you can generally use an index to save at least some effort. Otherwise, you're relying on some kind of alternate indexing style, such as: http://www.postgresql.org/docs/current/static/pgtrgm.html which specifically mentions regex searches as being indexable. Some more info, including 'explain' results: http://www.depesz.com/2013/04/10/waiting-for-9-3-support-indexing-of-regular-expression-searches-in-contribpg_trgm/ But this kind of thing isn't widely supported across databases. ChrisA From steve+comp.lang.python at pearwood.info Tue Nov 3 22:35:23 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 04 Nov 2015 14:35:23 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <56397cfd$0$1601$c3e8da3$5496439d@news.astraweb.com> On Wednesday 04 November 2015 03:20, Chris Angelico wrote: > On Wed, Nov 4, 2015 at 3:10 AM, Seymore4Head > wrote: >> Yes I knew that -1 represents the end character. It is not a question >> of trying to accomplish anything. I was just practicing with regex >> and wasn't sure how to express a * since it was one of the >> instructions. > > In that case, it's nothing to do with ending a string. Seymore never said anything about ending a string. > What you really > want to know is: How do you match a '*' using a regular expression? He may want to know that too, but that's not what he asked for. He asked how to match an asterisk at the end of the line. > Which is what MRAB answered, courtesy of a working crystal ball: You > use '\*'. Everything about the end of the string is irrelevant. Not at all -- matching "\*" will find lines *beginning* with an asterisk if you use re.match, and lines containing an asterisk *anywhere* in the line if you use re.search. I say "line" because the most common use for re.match and re.search is to match against a single line of text, but of course regexes can operate on multiline blocks of text, with or without multiline mode turned on. And calling it "a working crystal ball" is somewhat of an exaggeration. The plain English meaning of Seymore's plain English question is easily understood: he wants to know how to match an asterisk at the end of the line, just like he said :-P > (So, > too, are all the comments about using [-1] or string methods. But we > weren't to know that.) If MRAB could understand what he wanted, I'm sure most others could have too. -- Steve From steve+comp.lang.python at pearwood.info Tue Nov 3 22:39:04 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 04 Nov 2015 14:39:04 +1100 Subject: Irregular last line in a text file, was Re: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> Message-ID: <56397dd9$0$1601$c3e8da3$5496439d@news.astraweb.com> On Wednesday 04 November 2015 03:56, Tim Chase wrote: > Or even more valuable to me: > > with open(..., newline="strip") as f: > assert all(not line.endswith(("\n", "\r")) for line in f) # Works only on Windows text files. def chomp(lines): for line in lines: yield line.rstrip('\r\n') Better would be this: def chomp(lines): for line in lines: yield line.rstrip() # remove all trailing whitespace with open(...) as f: for line in chomp(f): ... -- Steve From torriem at gmail.com Tue Nov 3 22:47:18 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 03 Nov 2015 20:47:18 -0700 Subject: Regular expressions In-Reply-To: <56397a18$0$11094$c3e8da3@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: <56397FC6.9040700@gmail.com> On 11/03/2015 08:23 PM, Steven D'Aprano wrote: >>> Grep can use regular expressions (and I do so with it regularly), but >>> it's default mode is certainly not regular expressions ... >> >> Its very name indicates that its default mode most certainly is regular >> expressions. > > I don't even know what grep stands for. > > But I think what Michael may mean is that if you "grep foo", no regex magic > takes place since "foo" contains no metacharacters. More likely I just don't know what I'm talking about. I must have been thinking about something else (shell globbing perhaps). Certainly most of the times I've seen grep used, it's to look for a word with no special metacharacters, as you say. Still a valid RE of course. But I have learned to night I don't need to resort to grep -e to use regular expressions. At least with GNU grep, that's the default. From steve+comp.lang.python at pearwood.info Tue Nov 3 22:48:21 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 04 Nov 2015 14:48:21 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Message-ID: <56398006$0$11100$c3e8da3@news.astraweb.com> On Wednesday 04 November 2015 11:33, rurpy at yahoo.com wrote: >> Not quite. Core language concepts like ifs, loops, functions, >> variables, slicing, etc are the socket wrenches of the programmer's >> toolbox. Regexs are like an electric impact socket wrench. You can do >> the same work without it, but in many cases it's slower. But you have to >> learn the other hand tools first in order to really use the electric >> driver properly (understanding torques, direction of threads, etc), lest >> you wonder why you're breaking off so many bolts with the torque of the >> impact drive. > > I consider regexs more fundemental I'm sure that there are people who consider the International Space Station more fundamental than the lever, the wedge and the hammer, but they would be wrong too. Given primitives for branching, loops and variables, you can build support for regexes. Given regexes, how would you build support for variables? Of course, you could easily prove me wrong. All you would need to do to demonstrate that regexes are more fundamental than branching, loops and variables would be to demonstrate that the primitive operations available in commonly used CPUs are regular expressions, and that (for example) C's for loop and if...else are implemented in machine code as regular expressions, rather than the other way around. -- Steve From nobody at nowhere.invalid Wed Nov 4 00:05:53 2015 From: nobody at nowhere.invalid (Nobody) Date: Wed, 04 Nov 2015 05:05:53 +0000 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On Wed, 04 Nov 2015 14:23:04 +1100, Steven D'Aprano wrote: >> Its very name indicates that its default mode most certainly is regular >> expressions. > > I don't even know what grep stands for. >From the ed command "g /re/p" (where "re" is a placeholder for an arbitrary regular expression). Tests all lines ("g" for global) against the specified regexp and prints ("p") any which match. > But I think what Michael may mean is that if you "grep foo", no regex > magic takes place since "foo" contains no metacharacters. At least the GNU version will treat the input as a regexp regardless of whether it contains only literal characters. I.e. "grep foo" and "grep [f][o][o]" will both construct the same state machine then process the input with it. You need to actually use -F to change the matching algorithm. From arsh840 at gmail.com Wed Nov 4 01:27:51 2015 From: arsh840 at gmail.com (Arshpreet Singh) Date: Tue, 3 Nov 2015 22:27:51 -0800 (PST) Subject: Python PNG Viewer(Browser Based) In-Reply-To: References: <9c24559b-17a4-41fc-80a2-9258fd84c9f1@googlegroups.com> Message-ID: On Tuesday, 3 November 2015 21:32:03 UTC+5:30, Chris Warrick wrote: > On 3 November 2015 at 12:54, Arshpreet Singh wrote: > > Hello Everyone, > > > > I am looking for Browser-based PNG file viewer written in > > Python.(Flask framework preferably) > > > > Following project(Flask-Based) provides many things(File manager as > > well as file viewer) but it does not support PNG files. > > > > https://github.com/vmi356/filemanager > > > > Any idea if I have to write my own browser based PNG viewer from > > scratch(Using PIL or other required library) > > > > On the other side if I have to write only Desktop-based only two lines > > are enough to do many things: > > > > Like, > > > > from PIL import Image > > f = Image.open("file.png").show() > > > > > > But I am not getting right sense that how to make possible using Python+Flask. > > > > Hope I am able to tell my problem? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Your problem is lack of basic understanding of the Internet. Yes That's true at some level. >Because > EVERY graphical web browser supports PNG files NATIVELY. With a single > tag. That is easily understandable. > Just figure out where to add the PNG handler code and read any random > "how to add images to a webpage" tutorial. > You might need a new template and some code that is aware of the file > being an image. But absolutely no PNG viewer is necessary. My present working system shows me list of all files (PNGs, JPGs, txt, SVGs) in browser, when I click on file it opens it and show contents of it. but PNG and JPGs are not working. Surely handling one PNG file is easy but no idea how to solve multiple file situation. From auriocus at gmx.de Wed Nov 4 02:21:45 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 4 Nov 2015 08:21:45 +0100 Subject: Regular expressions In-Reply-To: <56398006$0$11100$c3e8da3@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> Message-ID: Am 04.11.15 um 04:48 schrieb Steven D'Aprano: > On Wednesday 04 November 2015 11:33, rurpy at yahoo.com wrote: > >>> Not quite. Core language concepts like ifs, loops, functions, >>> variables, slicing, etc are the socket wrenches of the programmer's >>> toolbox. Regexs are like an electric impact socket wrench. You can do >>> the same work without it, but in many cases it's slower. But you have to >>> learn the other hand tools first in order to really use the electric >>> driver properly (understanding torques, direction of threads, etc), lest >>> you wonder why you're breaking off so many bolts with the torque of the >>> impact drive. >> >> I consider regexs more fundemental > > I'm sure that there are people who consider the International Space Station > more fundamental than the lever, the wedge and the hammer, but they would be > wrong too. > > Given primitives for branching, loops and variables, you can build support > for regexes. Given regexes, how would you build support for variables? > > Of course, you could easily prove me wrong. You *know* that they are not equivalent, I assume? regexes are equivalent to finite state machines, which are less powerful than Turing machines, and even less powerful than stack machines. You can't even construct a regexp which validates, if parentheses are balanced. What rurpy meant, was that regexes can surface to a computer user earlier than variables and branches; a user who does not go into the depth to actually program the machine, might still encounter them in a text editor or database engine. Even some web forms allow some limited form, like e.g. the DVD rental here or Google. Christian From ben+python at benfinney.id.au Wed Nov 4 02:23:53 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2015 18:23:53 +1100 Subject: Python PNG Viewer(Browser Based) References: <9c24559b-17a4-41fc-80a2-9258fd84c9f1@googlegroups.com> Message-ID: <85bnbakz1y.fsf@benfinney.id.au> Arshpreet Singh writes: > On Tuesday, 3 November 2015 21:32:03 UTC+5:30, Chris Warrick wrote: > > Your problem is lack of basic understanding of the Internet. > > Yes That's true at some level. More specifically, your problem is not ?how do I do this with Python?? but rather ?what is a web page??. So, the research you need to do is not Python-specific, instead you need to learn about the structure of web pages and web applications. > My present working system shows me list of all files (PNGs, JPGs, txt, > SVGs) in browser, when I click on file it opens it and show contents > of it. You are directing your web browser to visit a folder on your local file system. It is obliging you by presenting a directory of local files. Instead, you need to learn how to author web pages. There are countless resources for learning about generating a web page from scratch. You could learn a lot from the Wikibooks project . You'll also need to appreciate that developing web pages is a *very* extensive topic. You might need nothing more than to create simple static pages; you don't need Python at all for that. You might need a powerful Web programming framework, Python has excellent support for that . Without you learning the very basics of web sites, though, you won't get much use from Python-specific knowledge about web frameworks. Good hunting! -- \ ?Ridicule is the only weapon which can be used against | `\ unintelligible propositions.? ?Thomas Jefferson, 1816-07-30 | _o__) | Ben Finney From wolfgang.maier at biologie.uni-freiburg.de Wed Nov 4 03:19:42 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 4 Nov 2015 09:19:42 +0100 Subject: Unbuffered stderr in Python 3 In-Reply-To: <56397921$0$11094$c3e8da3@news.astraweb.com> References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> <56397921$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 04.11.2015 04:18, Steven D'Aprano wrote: > On Wednesday 04 November 2015 09:25, Terry Reedy wrote: > >> On 11/3/2015 10:42 AM, Chris Angelico wrote: >>> On Wed, Nov 4, 2015 at 2:00 AM, Random832 wrote: >>>> Nobody writes: >>>> >>>>> It's probably related to the fact that std{in,out,err} are Unicode >>>>> streams. >>>> >>>> There's no fundamental reason a Unicode stream should have to be line >>>> buffered. If it's "related", it's only in that an oversight was made in >>>> the course of making that change. >> >> The current behavior is not an 'oversight'. I was considered, decided, >> and revisited in https://bugs.python.org/issue13601. Guido: >> "Line-buffering should be good enough since in practice errors messages >> are always terminated by a newline." If not, print(part_line, >> file=sys.stderr, flush=True) works for the unusual case. > > This is one of the offending line from our code base: > > print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr) > > So that ought to be terminated by a newline. And yet, the stderr output > doesn't show up until the program exits. > For me, that prints immediately. Where is your output going? Console, file, ...? From fabien.maussion at gmail.com Wed Nov 4 03:39:09 2015 From: fabien.maussion at gmail.com (Fabien) Date: Wed, 4 Nov 2015 09:39:09 +0100 Subject: Is it ok to install python binaries on a network drive? References: <56320bf9$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/29/2015 01:07 PM, Steven D'Aprano wrote: >> My question is: what will happen when about 20 students will do the same >> >at the same time? I know too little about what's going under the hood >> >with an "import X" command to be able to predict problems that might >> >occur. > I think it should be fine. Dear all, I just wanted to report that everything worked fine. It wasn't even too slow. I find it a quite elegant solution after all for all the students to have the same working environment. Thanks! Fabien From steve+comp.lang.python at pearwood.info Wed Nov 4 03:47:58 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 04 Nov 2015 19:47:58 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> Message-ID: <5639c63f$0$2897$c3e8da3$76491128@news.astraweb.com> On Wednesday 04 November 2015 18:21, Christian Gollwitzer wrote: > What rurpy meant, was that regexes can surface to a computer user > earlier than variables and branches; a user who does not go into the > depth to actually program the machine, might still encounter them in a > text editor or database engine. Even some web forms allow some limited > form, like e.g. the DVD rental here or Google. What Rurpy meant, only Rurpy can say, but I doubt that is what he is talking about. By that logic, a full-screen high-def 3D first-person shooter game with an advanced AI is "more fundamental" than an assembly language branch operation, because there are people who play computer games without doing assembly programming. In context, Michael suggested that programmers should learn the basic fundamentals of their chosen language, such as variables, for-loops and branching, before regexes -- which Rurpy then disagreed with, claiming that regexes are more fundamental than those basic operations. What *I* think that Rurpy means is that one can construct a mathematical system based on pattern matching which is Turing complete, and therefore in principle any problem you can solve using a program written in (say) Python, C, Lisp, Smalltalk, etc, or execute on a CPU (or simulate in your head!) could be written as a sufficiently complex regular expression. I think he is *technically wrong*, if by "regex" we mean actual regular expressions. Perl, and Python, regexes are strictly more powerful than regular expressions (despite the name). I know that Perl regexes are Turing complete (mainly because they can call out to the Perl interpreter), I'm not sure about Python regexes. But I also think that Rurpy is *not even wrong* if he means Perl or Python regexes. The (entirely theoretical) ability to solve a problem like "What is pi to the power of the first prime number larger than 97531000?" using a regex doesn't make regexes more fundamental than variables, branches and loops. It just makes them an alternative computing paradigm -- one which is *exponentially* more difficult to use than the standard paradigms of functional, procedural, OOP, etc. for anything except the limited subset of pattern matching problems they were created for. -- Steve From __peter__ at web.de Wed Nov 4 03:57:02 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Nov 2015 09:57:02 +0100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> Message-ID: Michael Torrie wrote: > On 11/03/2015 08:23 PM, Steven D'Aprano wrote: >>>> Grep can use regular expressions (and I do so with it regularly), but >>>> it's default mode is certainly not regular expressions ... >>> >>> Its very name indicates that its default mode most certainly is regular >>> expressions. >> >> I don't even know what grep stands for. >> >> But I think what Michael may mean is that if you "grep foo", no regex >> magic takes place since "foo" contains no metacharacters. > > More likely I just don't know what I'm talking about. I must have been > thinking about something else (shell globbing perhaps). > > Certainly most of the times I've seen grep used, it's to look for a word > with no special metacharacters, as you say. Still a valid RE of course. > But I have learned to night I don't need to resort to grep -e to use > regular expressions. At least with GNU grep, that's the default. Well, I didn't know that grep uses regular expressions by default. I tried Tim's example $ seq 5 | grep '1*' 1 2 3 4 5 $ which surprised me because I remembered that there usually weren't any matching lines when I invoked grep instead of egrep by mistake. So I tried another one $ seq 5 | grep '[1-3]+' $ and then headed for the man page. Apparently there is a subset called "basic regular expressions": """ Basic vs Extended Regular Expressions In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \). """ From oscar.j.benjamin at gmail.com Wed Nov 4 05:07:14 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 4 Nov 2015 10:07:14 +0000 Subject: Irregular last line in a text file, was Re: Regular expressions In-Reply-To: <56397dd9$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> <56397dd9$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4 November 2015 at 03:39, Steven D'Aprano wrote: > > Better would be this: > > def chomp(lines): > for line in lines: > yield line.rstrip() # remove all trailing whitespace > > > with open(...) as f: > for line in chomp(f): ... with open(...) as f: for line in map(str.rstrip, f): ... -- Oscar From mail at timgolden.me.uk Wed Nov 4 05:08:41 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 4 Nov 2015 10:08:41 +0000 Subject: Creating PST files using Python In-Reply-To: References: <873907D8-7E21-4F08-AF07-A83F766802BA@cajuntechie.org> Message-ID: <5639D929.3050506@timgolden.me.uk> On 03/11/2015 22:12, Chris Angelico wrote: > On Wed, Nov 4, 2015 at 6:09 AM, Anthony Papillion > wrote: >> Does anyone know of a module that allows the wiring of Outlook PST >> files using Python? I'm working on a project that will require me >> to migrate 60gb of maildir mail (multiple accounts) to Outlook. I don't know if this is quite what you were after but, if automating Outlook is an option (ie using its COM object model), the code below is an *extremely* Q&D approach to adding a PST and copying the messages in a mbox one by one. Obviously I've done just enough to show that it's viable, and none of the more complicated work around conversation ids, multipart messages etc. TJG #!python3 import os, sys import gzip import mailbox import urllib.request import win32com.client dispatch = win32com.client.gencache.EnsureDispatch const = win32com.client.constants PST_FILEPATH = os.path.abspath(os.path.join(os.path.expandvars("%APPDATA%"), "scratch.pst")) if os.path.exists(PST_FILEPATH): os.remove(PST_FILEPATH) ARCHIVE_URL = "https://mail.python.org/pipermail/python-list/2015-November.txt.gz" MBOX_FILEPATH = "archive.mbox" def download_archive(url, local_mbox): with gzip.open(urllib.request.urlopen(url)) as archive: with open(local_mbox, "wb") as f: print("Writing %s to %s" % (url, local_mbox)) f.write(archive.read()) def copy_archive_to_pst(mbox_filepath, pst_folder): archive = mailbox.mbox(mbox_filepath) for message in archive: print(message.get("Subject")) pst_message = pst_folder.Items.Add() pst_message.Subject = message.get("Subject") pst_message.Sender = message.get("From") pst_message.Body = message.get_payload() pst_message.Move(pst_folder) pst_message.Save() def find_pst_folder(namespace, pst_filepath): for store in dispatch(mapi.Stores): if store.IsDataFileStore and store.FilePath == PST_FILEPATH: return store.GetRootFolder() download_archive(ARCHIVE_URL, MBOX_FILEPATH) outlook = dispatch("Outlook.Application") mapi = outlook.GetNamespace("MAPI") pst_folder = find_pst_folder(mapi, PST_FILEPATH) if not pst_folder: mapi.AddStoreEx(PST_FILEPATH, const.olStoreDefault) pst_folder = find_pst_folder(mapi, PST_FILEPATH) if not pst_folder: raise RuntimeError("Can't find PST folder at %s" % PST_FILEPATH) copy_archive_to_pst(MBOX_FILEPATH, pst_folder) From steve at pearwood.info Wed Nov 4 05:24:29 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 04 Nov 2015 21:24:29 +1100 Subject: Unbuffered stderr in Python 3 References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> <56397921$0$11094$c3e8da3@news.astraweb.com> Message-ID: <5639dcdf$0$1620$c3e8da3$5496439d@news.astraweb.com> On Wed, 4 Nov 2015 07:19 pm, Wolfgang Maier wrote: > On 04.11.2015 04:18, Steven D'Aprano wrote: >> On Wednesday 04 November 2015 09:25, Terry Reedy wrote: >> >>> On 11/3/2015 10:42 AM, Chris Angelico wrote: >>>> On Wed, Nov 4, 2015 at 2:00 AM, Random832 >>>> wrote: >>>>> Nobody writes: >>>>> >>>>>> It's probably related to the fact that std{in,out,err} are Unicode >>>>>> streams. >>>>> >>>>> There's no fundamental reason a Unicode stream should have to be line >>>>> buffered. If it's "related", it's only in that an oversight was made >>>>> in the course of making that change. >>> >>> The current behavior is not an 'oversight'. I was considered, decided, >>> and revisited in https://bugs.python.org/issue13601. Guido: >>> "Line-buffering should be good enough since in practice errors messages >>> are always terminated by a newline." If not, print(part_line, >>> file=sys.stderr, flush=True) works for the unusual case. >> >> This is one of the offending line from our code base: >> >> print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr) >> >> So that ought to be terminated by a newline. And yet, the stderr output >> doesn't show up until the program exits. >> > > For me, that prints immediately. Where is your output going? Console, > file, ...? Going to stderr, like the whole thread is about :-) The output does eventually show up written to the console, but only after Python exits. -- Steven From wolfgang.maier at biologie.uni-freiburg.de Wed Nov 4 05:43:18 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 4 Nov 2015 11:43:18 +0100 Subject: Unbuffered stderr in Python 3 In-Reply-To: <5639dcdf$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> <56397921$0$11094$c3e8da3@news.astraweb.com> <5639dcdf$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04.11.2015 11:24, Steven D'Aprano wrote: > On Wed, 4 Nov 2015 07:19 pm, Wolfgang Maier wrote: > >> On 04.11.2015 04:18, Steven D'Aprano wrote: >>> >>> This is one of the offending line from our code base: >>> >>> print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr) >>> >>> So that ought to be terminated by a newline. And yet, the stderr output >>> doesn't show up until the program exits. >>> >> >> For me, that prints immediately. Where is your output going? Console, >> file, ...? > > Going to stderr, like the whole thread is about :-) > I see :), but seriously, what I meant was: is it going to the console directly or is your code base redirecting sys.stderr to another buffered object first? > > The output does eventually show up written to the console, but only after > Python exits. > > > From antoon.pardon at rece.vub.ac.be Wed Nov 4 06:41:23 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 04 Nov 2015 12:41:23 +0100 Subject: Regular expressions In-Reply-To: <56397cfd$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397cfd$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5639EEE3.10703@rece.vub.ac.be> Op 04-11-15 om 04:35 schreef Steven D'Aprano: > On Wednesday 04 November 2015 03:20, Chris Angelico wrote: > >> (So, >> too, are all the comments about using [-1] or string methods. But we >> weren't to know that.) > If MRAB could understand what he wanted, I'm sure most others could have > too. Yes, they were just to busy to try pushing the OP in an other direction, for them to answer the question. -- Antoon Pardon From wolfgang.maier at biologie.uni-freiburg.de Wed Nov 4 06:49:49 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 4 Nov 2015 12:49:49 +0100 Subject: Unbuffered stderr in Python 3 In-Reply-To: References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> <56397921$0$11094$c3e8da3@news.astraweb.com> <5639dcdf$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04.11.2015 11:43, Wolfgang Maier wrote: > On 04.11.2015 11:24, Steven D'Aprano wrote: >> On Wed, 4 Nov 2015 07:19 pm, Wolfgang Maier wrote: >> >>> On 04.11.2015 04:18, Steven D'Aprano wrote: >>>> >>>> This is one of the offending line from our code base: >>>> >>>> print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr) >>>> >>>> So that ought to be terminated by a newline. And yet, the stderr output >>>> doesn't show up until the program exits. >>>> >>> >>> For me, that prints immediately. Where is your output going? Console, >>> file, ...? >> >> Going to stderr, like the whole thread is about :-) >> > > I see :), but seriously, what I meant was: is it going to the console > directly or is your code base redirecting sys.stderr to another buffered > object first? > Standard I/O streams are line-buffered only if interactive (i.e., connected to a console), but block-buffered otherwise. What does sys.stderr.isatty() return? From c.zallmann at web.de Wed Nov 4 07:41:00 2015 From: c.zallmann at web.de (Christoph Zallmann) Date: Wed, 4 Nov 2015 13:41:00 +0100 Subject: pycrypto Message-ID: <003501d116fe$0f502570$2df07050$@web.de> Hey there, i tried using Python 3.5.0 in combination with pycrypto and everything i got was crap. Really. I tried so many things, how to solve my problem - using environment variables, vs 2015 and many more. With python 2.7 or even 3.4 i heard it was no problem but using 3.5 all i got was one error message that leads to the next error message. Can you tell me how to install python 3.5 on Windows 10 with a working pycrpto on it? As well pip as easy_install threw the same errors e.g. "No matching distribution found for pycrypto" or error: Setup script exyited with error: Unable to find vcvarsall.bat Can u give me a suited solution that simply works for me? Thanks and greetings, Chris From invalid at invalid.invalid Wed Nov 4 08:27:45 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 Nov 2015 13:27:45 +0000 (UTC) Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 2015-11-04, Michael Torrie wrote: > On 11/03/2015 08:23 PM, Steven D'Aprano wrote: >> >>>> Grep can use regular expressions (and I do so with it regularly), but >>>> it's default mode is certainly not regular expressions ... >>> >>> Its very name indicates that its default mode most certainly is >>> regular expressions. >> >> I don't even know what grep stands for. General Regular Expression Parser (or somesuch) >> But I think what Michael may mean is that if you "grep foo", no regex >> magic takes place since "foo" contains no metacharacters. > > More likely I just don't know what I'm talking about. I must have > been thinking about something else (shell globbing perhaps). > > Certainly most of the times I've seen grep used, it's to look for a > word with no special metacharacters, as you say. Still a valid RE of > course. But I have learned to night I don't need to resort to grep -e > to use regular expressions. The -e turns on "enhanced" regexes which add a few more features to the regex language it parses. I've never been entirely sure if the -e regex language is backwards compatible with the default one or not... > At least with GNU grep, that's the default. Grep has always by default parsed its first command line argument (at least since v7 and Sys5). If you didn't want it treated as a regex, you had to specify -f. -- Grant Edwards grant.b.edwards Yow! I like your SNOOPY at POSTER!! gmail.com From random832 at fastmail.com Wed Nov 4 08:43:56 2015 From: random832 at fastmail.com (Random832) Date: Wed, 04 Nov 2015 08:43:56 -0500 Subject: Unbuffered stderr in Python 3 References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> <56397921$0$11094$c3e8da3@news.astraweb.com> <5639dcdf$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twp1op5v.fsf@fastmail.com> Wolfgang Maier writes: > Standard I/O streams are line-buffered only if interactive (i.e., > connected to a console), but block-buffered otherwise. That's not appropriate for stderr, nor is it justified by the argument that Terry Reedy cited earlier. I had assumed he was making an implicit claim that stderr is _always_ line-buffered, _even if_ it is not interactive. > What does sys.stderr.isatty() return? There are many situations in which a nominally interactive process might not have a "tty" for stderr on MS Windows. In an Emacs M-x shell buffer, in a cygwin terminal (for a non-cygwin python), etc. From rurpy at yahoo.com Wed Nov 4 09:38:19 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 06:38:19 -0800 (PST) Subject: Regular expressions In-Reply-To: <56398006$0$11100$c3e8da3@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> Message-ID: <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> On 11/03/2015 08:48 PM, Steven D'Aprano wrote: > On Wednesday 04 November 2015 11:33, rurpy wrote: > >>> Not quite. Core language concepts like ifs, loops, functions, >>> variables, slicing, etc are the socket wrenches of the programmer's >>> toolbox. Regexs are like an electric impact socket wrench. You can do >>> the same work without it, but in many cases it's slower. But you have to >>> learn the other hand tools first in order to really use the electric >>> driver properly (understanding torques, direction of threads, etc), lest >>> you wonder why you're breaking off so many bolts with the torque of the >>> impact drive. >> >> I consider regexs more fundemental > > I'm sure that there are people who consider the International Space Station > more fundamental than the lever, the wedge and the hammer, but they would be > wrong too. > > Given primitives for branching, loops and variables, you can build support > for regexes. Given regexes, how would you build support for variables? > > Of course, you could easily prove me wrong. All you would need to do to > demonstrate that regexes are more fundamental than branching, loops and > variables would be to demonstrate that the primitive operations available in > commonly used CPUs are regular expressions, and that (for example) C's for > loop and if...else are implemented in machine code as regular expressions, > rather than the other way around. I'm afraid you are making a category error but perhaps that's in part because I wasn't clear. I was not talking about computer science. I was talking about human beings learning about computers. Most people I know consider programming to be a higher level activity than "using" a computer: editing, sending email etc. Many computer users (not programmers) learn to use regular expressions as part of using a computer without knowing anything about programming. It was on that basis I called them more fundamental -- something learned earlier which is expanded on and added to later. But you have a bit of a point, perhaps "fundamental" was not the best choice of word to communicate that. Here is what I wrote: > I consider regexs more fundemental. One need not even be a programmer > to use them: consider grep, sed, a zillion editors, database query > languages, etc. I thought the context, which you removed even to the point cutting text from the very same line you quoted, made that clear but perhaps not. Indeed it is quite eye-opening when one does learn a little CS and discovers these things that were just a useful "feature" actually have a deep and profound theoretical basis. From rurpy at yahoo.com Wed Nov 4 09:43:19 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 06:43:19 -0800 (PST) Subject: Regular expressions In-Reply-To: <5639c63f$0$2897$c3e8da3$76491128@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <5639c63f$0$2897$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wednesday, November 4, 2015 at 1:52:31 AM UTC-7, Steven D'Aprano wrote: > On Wednesday 04 November 2015 18:21, Christian Gollwitzer wrote: > > > What rurpy meant, was that regexes can surface to a computer user > > earlier than variables and branches; a user who does not go into the > > depth to actually program the machine, might still encounter them in a > > text editor or database engine. Even some web forms allow some limited > > form, like e.g. the DVD rental here or Google. > [...] > What *I* think that Rurpy means is that one can construct a mathematical > system based on pattern matching which is Turing complete, and therefore in > principle any problem you can solve using a program written in (say) Python, > C, Lisp, Smalltalk, etc, or execute on a CPU (or simulate in your head!) > could be written as a sufficiently complex regular expression. No, Christian was correct. From rosuav at gmail.com Wed Nov 4 09:52:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 01:52:08 +1100 Subject: Regular expressions In-Reply-To: <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> Message-ID: On Thu, Nov 5, 2015 at 1:38 AM, rurpy--- via Python-list wrote: > I'm afraid you are making a category error but perhaps that's in > part because I wasn't clear. I was not talking about computer > science. I was talking about human beings learning about computers. > Most people I know consider programming to be a higher level activity > than "using" a computer: editing, sending email etc. Many computer > users (not programmers) learn to use regular expressions as part > of using a computer without knowing anything about programming. > It was on that basis I called them more fundamental -- something > learned earlier which is expanded on and added to later. But you > have a bit of a point, perhaps "fundamental" was not the best choice > of word to communicate that. The "fundamentals" of something are its most basic functions, not its most basic uses. The most common use of a computer might be to browse the web, but the fundamental functionality is arithmetic and logic. Setting aside the choice of word, though, I still don't think regular expressions are a more basic use of computing than loops and conditionals. A regex can't be used for anything other than string matching; they exist for one purpose, and one purpose only: to answer the question "Does this string match this pattern?". Sure, you can abuse that into a primality check and other forms of crazy arithmetic, but it's not what they truly do. I also would not teach regexes to people as part of an "introduction to computing" course, any more than I would teach the use of Microsoft Excel, which some such courses have been known to do. (And no, it's not because of the Microsoftness. I wouldn't teach LibreOffice Calc either.) You don't need to know how to work a spreadsheet as part of the basics of computer usage, and you definitely don't need an advanced form of text search. ChrisA From torriem at gmail.com Wed Nov 4 10:13:51 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 04 Nov 2015 08:13:51 -0700 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> Message-ID: <563A20AF.1070002@gmail.com> On 11/04/2015 01:57 AM, Peter Otten wrote: > and then headed for the man page. Apparently there is a subset > called "basic regular expressions": > > """> Basic vs Extended Regular Expressions > In basic regular expressions the meta-characters ?, +, {, |, (, > and ) lose their special meaning; instead use the backslashed > versions \?, \+, \{, \|, \(, and \). > """ Good catch. I think this must have been what my brain was thinking when I commented about grep and regular expressions earlier. I checked the man page but didn't read down far enough. I was still technically wrong though. It's neat to learn so much on these tangents that the python list goes on frequently. Hope the OP is still lurking, reading all these comments, though I suspect he's not. From python.list at tim.thechases.com Wed Nov 4 10:33:02 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Nov 2015 09:33:02 -0600 Subject: Irregular last line in a text file, was Re: Regular expressions In-Reply-To: <56397dd9$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <20151102204237.6a78abdf@bigbox.christie.dr> <56382F33.8050905@gmail.com> <20151103055018.535e3e42@bigbox.christie.dr> <56397dd9$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20151104093302.12186ee1@bigbox.christie.dr> On 2015-11-04 14:39, Steven D'Aprano wrote: > On Wednesday 04 November 2015 03:56, Tim Chase wrote: >> Or even more valuable to me: >> >> with open(..., newline="strip") as f: >> assert all(not line.endswith(("\n", "\r")) for line in f) > > # Works only on Windows text files. > def chomp(lines): > for line in lines: > yield line.rstrip('\r\n') .rstrip() takes a string that is a set of characters, so it will remove any \r or \n at the end of the string (so it works with both Windows & *nix line-endings) whereas just using .rstrip() without a parameter can throw away data you might want: >>> "hello \r\n\r\r\n\n\n".rstrip("\r\n") 'hello ' >>> "hello \r\n\r\r\n\n\n".rstrip() 'hello' -tkc From python.list at tim.thechases.com Wed Nov 4 10:42:16 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Nov 2015 09:42:16 -0600 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> Message-ID: <20151104094216.3f7e3006@bigbox.christie.dr> On 2015-11-04 09:57, Peter Otten wrote: > Well, I didn't know that grep uses regular expressions by default. It doesn't help that grep(1) comes in multiple flavors: grep: should use BRE (Basic REs) fgrep: same as "grep -F"; uses fixed strings, no REs egrep: same as "grep -E"; uses ERE (Extended REs) grep -P: a GNUism to use PCREs (Perl Compatible REs) there's also an "rgrep" which is just "grep -r" which I find kinda silly/redundant. Though frankly I feel the same way about fgrep/egrep since they just activate a command-line switch. You get even crazier when you start adding zgrep/zegrep/zfgrep. -tkc From df at see.replyto.invalid Wed Nov 4 10:55:12 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Wed, 04 Nov 2015 15:55:12 +0000 Subject: Unbuffered stderr in Python 3 References: <5638F707.90309@noaa.gov> Message-ID: Random832 wrote: >The opposite of line buffering is not no buffering, but full >(i.e. block) buffering, that doesn't get flushed until it runs >out of space. TextIOWrapper has its own internal buffer, and its >design apparently doesn't contemplate the possibility of using >it with a raw FileIO object (which may mean that the posted code >isn't guaranteed to work) or disabling buffering. Hmmm. That even seems to cause trouble for sys.stderr.write (in Python3 with a non-tty e.g. a piped output): $ python2 -c 'import sys;sys.stderr.write("1\n");print("2")' 2>&1 | tee 1 2 $ python3 -c 'import sys;sys.stderr.write("1\n");print("2")' 2>&1 | tee 2 1 From ian.g.kelly at gmail.com Wed Nov 4 10:56:56 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Nov 2015 08:56:56 -0700 Subject: pycrypto In-Reply-To: <003501d116fe$0f502570$2df07050$@web.de> References: <003501d116fe$0f502570$2df07050$@web.de> Message-ID: On Wed, Nov 4, 2015 at 5:41 AM, Christoph Zallmann wrote: > Hey there, > > > > i tried using Python 3.5.0 in combination with pycrypto and everything i got > was crap. Really. I tried so many things, how to solve my problem - using > environment variables, vs 2015 and many more. With python 2.7 or even 3.4 i > heard it was no problem but using 3.5 all i got was one error message that > leads to the next error message. Can you tell me how to install python 3.5 > on Windows 10 with a working pycrpto on it? As well pip as easy_install > threw the same errors e.g. "No matching distribution found for pycrypto" or > > error: Setup script exyited with error: Unable to find vcvarsall.bat > > > > Can u give me a suited solution that simply works for me? http://stackoverflow.com/questions/11405549/how-do-i-install-pycrypto-on-windows From geneva.storey at fultonind.kyschools.us Wed Nov 4 13:18:30 2015 From: geneva.storey at fultonind.kyschools.us (Storey, Geneva) Date: Wed, 4 Nov 2015 18:18:30 +0000 Subject: teacher need help! In-Reply-To: References: <5623397C.40205@timgolden.me.uk> , <5624AC43.3080105@timgolden.me.uk>, Message-ID: I am having the same problem that we experienced earlier (see below). This student was exploring random numbers in Python. She named her program random which caused confusion for her computer. We deleted the file, but still had the problem. I removed Python from the machine. When I tried to reinstall, I got the attached error message. Now it won't even install. Any suggestions would be greatly appreciated! Thanks, Geneva Geneva Storey Fulton High School Spanish, Mathematics Bulldog Academy ________________________________________ From: Storey, Geneva Sent: Tuesday, October 20, 2015 11:25 AM To: Tim Golden Cc: python-list at python.org Subject: Re: teacher need help! FYI-We formatted the machines, reinstalling everything, including Python. I works with no problems now. Confusing that this would happen on 3 out of 13 machines. Just letting you know, all is well. Thank you for your help! Geneva Geneva Storey Fulton High School Spanish, Mathematics Bulldog Academy ________________________________________ From: Tim Golden Sent: Monday, October 19, 2015 3:39 AM To: Storey, Geneva Cc: python-list at python.org Subject: Re: teacher need help! On 19/10/2015 02:32, Storey, Geneva wrote: > Same issue! See attached. > Thanks! Geneva -- please try to post text, not pictures. Just use the mouse to cut-and-paste the entirety of the text from that window into an email. Otherwise some of the people who are trying to help you can't actually see what the problem is! [ Traceback show the same error coming from: c:\windows\system32\turtle.py ] This is a bit more tricky than it appears. If you're running on 64-bit Windows (which I can't tell from your screenshot) but your Python installation is 32-bit (which it is) then the folder which Python sees as "c:\windows\system32" is not the same folder which the normal Windows Explorer sees as "c:\windows\system32". Can you try going to this folder in Explorer: C:\windows\SysWOW64 and see if there's a turtle.py file there? If there is, move or delete it and try again. If that still doesn't work, can you tell us which version of Windows you're running, and whether it's 32 or 64-bit, please? If you're not sure how to get that information, try following the instructions here: http://ramblings.timgolden.me.uk/2015/10/08/what-windows-version-am-i-running/ TJG From ben+python at benfinney.id.au Wed Nov 4 13:24:03 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Nov 2015 05:24:03 +1100 Subject: What does =?utf-8?B?4oCcZ3JlcOKAnQ==?= stand for? (was: Regular expressions) References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: <85wptxk4ho.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > On Wednesday 04 November 2015 13:55, Dan Sommers wrote: > > > Its very name indicates that its default mode most certainly is > > regular expressions. > > I don't even know what grep stands for. ?grep? stands for ?g/RE/p?. The name is a mnemonic for a compound command in ?ed? [0], a text editor that pre-dates extravagant luxuries like ?presenting a full screen of text at one time?. In an ?ed? session, the user is obliged to keep mental track of the current line in the text buffer, and even what that text contains during the session. Single-letter commands, with various terse parameters such as the range of lines or some text to insert, are issued at a command prompt one after another. For these reasons, the manual page describes ?ed? as a ?line-oriented text editor?. Everything is done by specifying lines, blindly, to commands which then operate on those lines. The name of the ?vi? editor means ?visual interface (to a text editor)?, to proudly declare the innovation of a full screen of text that updates content during the editing session. That was not available for users of ?ed?. A very common command to issue, then, is ?actually show me the line of text I just specified?; the ?p? (for ?print?) command. Another very common command is ?find the text matching this pattern and perform these commands on it?, which is ?g? (for ?global?). The ?g? command addresses text matching a regular expression pattern, delimited by slashes ?/?. So, for users with feeble human brains incapable of remembering perfectly the entire content of the text while it changes and therefore not always knowing exactly which lines they wanted to operate on without seeing them all the time, a very frequent combination command is: g/RE/p meaning ?find lines forward from here that match the regular expression pattern ?RE?, and do nothing to those lines except print them to standard output?. Wikipedia has useful pages on both ?grep? and ?ed? . You can see a full specification of how the ?ed? interface is to behave as part of the ?Open Group Base Specifications Issue 7?, which is the specification for Unix. See the manual for GNU ed which includes an example session to appreciate just how far things have come. Of course, if you yearn for the days of minimalist purity, nothing beats Ed, man! !man ed [0] The standard text editor. -- \ ?If you can't annoy somebody there is little point in writing.? | `\ ?Kingsley Amis | _o__) | Ben Finney From gandalf at shopzeus.com Wed Nov 4 13:31:37 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Wed, 4 Nov 2015 19:31:37 +0100 Subject: pycrypto In-Reply-To: References: <003501d116fe$0f502570$2df07050$@web.de> Message-ID: <563A4F09.2030206@shopzeus.com> Can u give me a suited solution that simply works for me? > http://stackoverflow.com/questions/11405549/how-do-i-install-pycrypto-on-windows Voidspace only has Python 3.3. They are usually behind some minor versions. The only good way to do this is to compile it from sources. Unfortunately, not everbody has an MSVC license... I find it **very** annoying that every time I need to download binary PyCrypto for the latest CPython, I have to search for it on the net. Sometimes it cannot be found for a week. :-( For the OP's question, here is the relevant stackoverflow question: http://stackoverflow.com/questions/32800336/pycrypto-on-python-3-5 And here are some compiled versions that can be downloaded and installed with PIP: https://github.com/sfbahr/PyCrypto-Wheels Why don't we have binary packages for PyCrypto, uploaded to PyPi? It seems that there are persons who can compile it, but there are no official packagers. I would happily do it for others, but I don't have an MSVC license. :-( From python.list at tim.thechases.com Wed Nov 4 14:05:48 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Nov 2015 13:05:48 -0600 Subject: What does =?UTF-8?B?4oCcZ3JlcOKAnQ==?= stand for? (was: Regular expressions) In-Reply-To: <85wptxk4ho.fsf_-_@benfinney.id.au> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <85wptxk4ho.fsf_-_@benfinney.id.au> Message-ID: <20151104130548.0b6a2947@bigbox.christie.dr> On 2015-11-05 05:24, Ben Finney wrote: > A very common command to issue, then, is ?actually show me the line > of text I just specified?; the ?p? (for ?print?) command. > > Another very common command is ?find the text matching this pattern > and perform these commands on it?, which is ?g? (for ?global?). The > ?g? command addresses text matching a regular expression pattern, > delimited by slashes ?/?. > > So, for users with feeble human brains incapable of remembering > perfectly the entire content of the text while it changes and > therefore not always knowing exactly which lines they wanted to > operate on without seeing them all the time, a very frequent > combination command is: > > g/RE/p Though since the default action for g/ is to print the line, I've always wondered why the utility wasn't named just "gre" $ ed myfile.txt g/re [matching lines follow] q $ -tkc (the goofball behind https://twitter.com/ed1conf ) From femtv123 at gmail.com Wed Nov 4 14:38:00 2015 From: femtv123 at gmail.com (alperen) Date: Wed, 4 Nov 2015 11:38:00 -0800 (PST) Subject: any practise site about python? Message-ID: <4b7392fb-8639-49d2-a09d-a06bbbcbcff7@googlegroups.com> hi guys. i am computer engineering student and i want to practise the lectures that i saw at school. for example dictionaries tuples or some other topics. i know eulerproject but it is hard for starting. do you know any exercise sites for students or beginners From auriocus at gmx.de Wed Nov 4 14:38:21 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 4 Nov 2015 20:38:21 +0100 Subject: =?UTF-8?B?UmU6IFdoYXQgZG9lcyDigJxncmVw4oCdIHN0YW5kIGZvcj8=?= In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: Am 04.11.15 um 19:24 schrieb Ben Finney: > The name is a mnemonic for a compound command in ?ed? [0], a text editor > that pre-dates extravagant luxuries like ?presenting a full screen of > text at one time?. > > [... lots of fun facts ...] Here is another fun fact: The convincing UI of ed was actually so widely applied, that even Microsoft included a similar editor into MSDOS, called EDLIN. EDLIN, of course, was a bastardized version of ed that could do much less and also lacked regular expressions. Needless to say that the mighty "VIsual" editor was out 5 years before MSDOS shipped EDLIN as the only editor... In contrast to ed, the stream editor "sed" is used multiple times avery day in a typical Unix session inside shell scripts to perform automated text processing tasks, including regex replacement. Christian From israel at ravnalaska.net Wed Nov 4 15:13:00 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Wed, 4 Nov 2015 11:13:00 -0900 Subject: CherryPy cpstats and ws4py In-Reply-To: References: Message-ID: Ok, let me ask a different question: the impression I have gotten when trying to find help with CherryPy in general and ws4py specifically is that these frameworks are not widely used or well supported. Is that a fair assessment, or do I just have issues that are outside the realm of experience for other users? If it is a fair assessment, should I be looking at a different product for my next project? I know there are a number of options, CherryPy was simply the first one suggested to me, and ws4py is what is listed in their docs as the framework to use for Web Sockets. Thanks for any feedback that can be provided. ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- -------------- next part -------------- > On Nov 3, 2015, at 8:05 AM, Israel Brewster wrote: > > I posted this to the CherryPy and ws4py mailing lists, but in the week since I did that I've only gotten two or three views on each list, and no responses, so as a last-ditch effort I thought I'd post here. Maybe someone with more general python knowledge than me can figure out the traceback and from there a solution. > > Is it possible to use ws4py in conjunction with the cpstats CherryPy tool? I have a CherryPy (3.8.0) web app that uses web sockets via ws4py. Tested and working. I am now trying to get a little more visibility into the functioning of the server, so to that end I enabled the cpstats tool by adding the following line to my '/' configuration: > > tools.cpstats.on=True > > Unfortunately, as soon as I do that, attempts to connect a web socket start failing with the following traceback: > > [28/Oct/2015:08:18:48] > Traceback (most recent call last): > File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 104, in run > hook() > File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 63, in __call__ > return self.callback(**self.kwargs) > File "build/bdist.macosx-10.10-intel/egg/ws4py/server/cherrypyserver.py", line 200, in upgrade > ws_conn = get_connection(request.rfile.rfile) > File "build/bdist.macosx-10.10-intel/egg/ws4py/compat.py", line 43, in get_connection > return fileobj._sock > AttributeError: 'KnownLengthRFile' object has no attribute '_sock' > [28/Oct/2015:08:18:48] HTTP > Request Headers: > PRAGMA: no-cache > COOKIE: autoTabEnabled=true; fleetStatusFilterCompany=7H; fleetStatusFilterLocation=ALL; fleetStatusRefreshInterval=5; inputNumLegs=5; session_id=5c8303896aff419c175c79dfadbfdc9d75e6c45a > UPGRADE: websocket > HOST: flbubble.ravnalaska.net:8088 > ORIGIN: http://flbubble.ravnalaska.net > CONNECTION: Upgrade > CACHE-CONTROL: no-cache > SEC-WEBSOCKET-VERSION: 13 > SEC-WEBSOCKET-EXTENSIONS: x-webkit-deflate-frame > USER-AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7 > SEC-WEBSOCKET-KEY: Szh6Uoe+WzqKR1DgW8JcXA== > Remote-Addr: 10.9.1.59 > [28/Oct/2015:08:18:48] HTTP > Traceback (most recent call last): > File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 661, in respond > self.hooks.run('before_request_body') > File "/Library/Python/2.7/site-packages/CherryPy-3.8.0-py2.7.egg/cherrypy/_cprequest.py", line 114, in run > raise exc > AttributeError: 'KnownLengthRFile' object has no attribute '_sock' > > Disable tools.cpstats.on, and the sockets start working again. Is there some way I can fix this so I can use sockets as well as gather stats from my application? Thanks. > > ----------------------------------------------- > Israel Brewster > Systems Analyst II > Ravn Alaska > 5245 Airport Industrial Rd > Fairbanks, AK 99709 > (907) 450-7293 > ----------------------------------------------- > > -- > https://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Wed Nov 4 16:31:05 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Nov 2015 14:31:05 -0700 Subject: teacher need help! In-Reply-To: References: <5623397C.40205@timgolden.me.uk> <5624AC43.3080105@timgolden.me.uk> Message-ID: On Wed, Nov 4, 2015 at 11:18 AM, Storey, Geneva wrote: > > > > > I am having the same problem that we experienced earlier (see below). This student was exploring random numbers in Python. She named her program random which caused confusion for her computer. We deleted the file, but still had the problem. Was there a lingering .pyc file? The following transcript is from Linux but still illustrative of the probable cause. $ echo 'print("Oops!")' > random.py $ ls random.* random.py $ python -c "import random" Oops! $ ls random.* random.py random.pyc $ rm random.py $ python -c "import random" Oops! $ rm random.pyc $ python -c "import random" > I removed Python from the machine. When I tried to reinstall, I got the attached error message. Now it won't even install. Any suggestions would be greatly appreciated! Unfortunately the attachment doesn't seem to have made it through. Also, many of the subscribers here read this mailing list as a Usenet group and wouldn't be able to see the attachment anyway. Please copy and paste the error instead. From input/ldompeling at casema.nl Wed Nov 4 16:44:45 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Wed, 04 Nov 2015 21:44:45 GMT Subject: raw_input and break Message-ID: I have an continues loop with "while True:" Now I want to use "raw_input" and when I press "s" on the keybord that it will "break" the continues loop. I tried: choices = raw_input if choises == s: break But even when I not press "s" it "break" I want that I not press "s" the script continues. Any ideas ? Thanks -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From ian.g.kelly at gmail.com Wed Nov 4 16:54:36 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Nov 2015 14:54:36 -0700 Subject: raw_input and break In-Reply-To: References: Message-ID: On Wed, Nov 4, 2015 at 2:44 PM, wrote: > I have an continues loop with "while True:" > Now I want to use "raw_input" and when I press "s" on the keybord that it will > "break" the continues loop. > > I tried: > choices = raw_input This doesn't call raw_input. For that you need to write raw_input(), where the parentheses indicate a function call. All the above does is find the raw_input function and assign that function to the name "choices". > if choises == s: Strings in Python are delimited with quotes: "s", not just s. The latter is going to try to look up a variable named s, not denote a string. Also, it's important to spell the variable here in the same way that you did above. Above you have a c where here there is an s. I'm assuming that this isn't exactly what you ran, because you most likely would have gotten a NameError here. Please copy and paste exactly the code that you're trying to run rather than retyping it. > break This needs to be indented. Not indenting it would be a SyntaxError, so again I'm guessing that this isn't actually what you ran. From joel.goldstick at gmail.com Wed Nov 4 16:56:40 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 4 Nov 2015 16:56:40 -0500 Subject: raw_input and break In-Reply-To: References: Message-ID: On Wed, Nov 4, 2015 at 4:44 PM, wrote: > I have an continues loop with "while True:" > Now I want to use "raw_input" and when I press "s" on the keybord that it > will > "break" the continues loop. > > I tried: > choices = raw_input > if choises == s: > break > > But even when I not press "s" it "break" > I want that I not press "s" the script continues. > > Any ideas ? > You need to quote the s: if choices == 's' you need to check your spelling -- you have choices and choises You need to indent break 4 spaces > > Thanks > > > > -- > --------------------------------- --- -- - > Posted with NewsLeecher v7.0 Beta 2 > Web @ http://www.newsleecher.com/?usenet > ------------------- ----- ---- -- - > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From input/ldompeling at casema.nl Wed Nov 4 17:37:21 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Wed, 04 Nov 2015 22:37:21 GMT Subject: raw_input and break References: Message-ID: In reply to "Joel Goldstick" who wrote the following: > On Wed, Nov 4, 2015 at 4:44 PM, wrote: > > > I have an continues loop with "while True:" > > Now I want to use "raw_input" and when I press "s" on the keybord that it > > will > > "break" the continues loop. > > > > I tried: > > choices = raw_input > > if choises == s: > > break > > You need to quote the s: > if choices == 's' I quote the s, but its still break even when I not press the s. -------------------------------------------------------------- >But even when I not press "s" it "break" > > I want that I not press "s" the script continues. > > > > Any ideas ? > > > > You need to quote the s: > if choices == 's' > > you need to check your spelling -- you have choices and choises > > You need to indent break 4 spaces > > > > > Thanks > > > > > > > > -- > > --------------------------------- --- -- - > > Posted with NewsLeecher v7.0 Beta 2 > > Web @ http://www.newsleecher.com/?usenet > > ------------------- ----- ---- -- - > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > -- > Joel Goldstick > http://joelgoldstick.com/stats/birthdays -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From tjreedy at udel.edu Wed Nov 4 17:52:30 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 4 Nov 2015 17:52:30 -0500 Subject: Bugfixing python 3.5 asyncio In-Reply-To: References: Message-ID: On 11/3/2015 8:24 PM, Dmitry Panteleev wrote: > Hello, > > There is a bug in asyncio.Queue > (https://github.com/python/asyncio/issues/268), which makes it > unusable for us. It is fixed in master now. I presume that the fix has been merged into the CPython repository (you could check). If so, it should be included when 3.5.1 is released in about a month+. > What is the easiest way to > patch the asyncio bundled with python if I have to distribute it among > 5 colleagues? It is used in our private module. The cleanest way -- in my opinion -- would be to patch your 3.5.0 installations, making them '3.5.0+'. For 5 installations, > I can think of: > 1. Copy asyncio.queues into our package so it has a different name this would be easiest, but then I would retest and presumably revise and redistribute after 3.5.1 is out > 2. Override sys.path > > Both look really strange. Is there anything else? What I said above. -- Terry Jan Reedy From emile at fenx.com Wed Nov 4 17:59:43 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 4 Nov 2015 14:59:43 -0800 Subject: any practise site about python? In-Reply-To: <4b7392fb-8639-49d2-a09d-a06bbbcbcff7@googlegroups.com> References: <4b7392fb-8639-49d2-a09d-a06bbbcbcff7@googlegroups.com> Message-ID: On 11/4/2015 11:38 AM, alperen wrote: > hi guys. > i am computer engineering student and i want to practise the lectures that i saw at school. for example dictionaries tuples or some other topics. i know eulerproject but it is hard for starting. do you know any exercise sites for students or beginners > Any of the top four hits googling 'getting started with python' should provide you a thread to pull on. Emile From Seymore4Head at Hotmail.invalid Wed Nov 4 18:00:12 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 04 Nov 2015 18:00:12 -0500 Subject: Regular expressions References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> Message-ID: <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> On Wed, 04 Nov 2015 08:13:51 -0700, Michael Torrie wrote: >On 11/04/2015 01:57 AM, Peter Otten wrote: >> and then headed for the man page. Apparently there is a subset >> called "basic regular expressions": >> >> """> Basic vs Extended Regular Expressions >> In basic regular expressions the meta-characters ?, +, {, |, (, >> and ) lose their special meaning; instead use the backslashed >> versions \?, \+, \{, \|, \(, and \). >> """ > >Good catch. I think this must have been what my brain was thinking when >I commented about grep and regular expressions earlier. I checked the >man page but didn't read down far enough. > >I was still technically wrong though. > >It's neat to learn so much on these tangents that the python list goes >on frequently. Hope the OP is still lurking, reading all these comments, >though I suspect he's not. > I am still here, but I have to admit I am not picking up too much. From tjreedy at udel.edu Wed Nov 4 18:00:22 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 4 Nov 2015 18:00:22 -0500 Subject: Unbuffered stderr in Python 3 In-Reply-To: <56397921$0$11094$c3e8da3@news.astraweb.com> References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> <874mh39lgu.fsf@fastmail.com> <56397921$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 11/3/2015 10:18 PM, Steven D'Aprano wrote: > On Wednesday 04 November 2015 09:25, Terry Reedy wrote: > >> On 11/3/2015 10:42 AM, Chris Angelico wrote: >>> On Wed, Nov 4, 2015 at 2:00 AM, Random832 wrote: >>>> Nobody writes: >>>> >>>>> It's probably related to the fact that std{in,out,err} are Unicode >>>>> streams. >>>> >>>> There's no fundamental reason a Unicode stream should have to be line >>>> buffered. If it's "related", it's only in that an oversight was made in >>>> the course of making that change. >> >> The current behavior is not an 'oversight'. I was considered, decided, >> and revisited in https://bugs.python.org/issue13601. Guido: >> "Line-buffering should be good enough since in practice errors messages >> are always terminated by a newline." If not, print(part_line, >> file=sys.stderr, flush=True) works for the unusual case. > > This is one of the offending line from our code base: > > print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr) > > So that ought to be terminated by a newline. Or include 'flush=True' if you really want that to be a partial line. -- Terry Jan Reedy From Seymore4Head at Hotmail.invalid Wed Nov 4 18:02:40 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 04 Nov 2015 18:02:40 -0500 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> Message-ID: <1i3l3b9836hatsuoopak5gtg2c38g49kb1@4ax.com> On Wed, 04 Nov 2015 14:48:21 +1100, Steven D'Aprano wrote: >On Wednesday 04 November 2015 11:33, rurpy at yahoo.com wrote: > >>> Not quite. Core language concepts like ifs, loops, functions, >>> variables, slicing, etc are the socket wrenches of the programmer's >>> toolbox. Regexs are like an electric impact socket wrench. You can do >>> the same work without it, but in many cases it's slower. But you have to >>> learn the other hand tools first in order to really use the electric >>> driver properly (understanding torques, direction of threads, etc), lest >>> you wonder why you're breaking off so many bolts with the torque of the >>> impact drive. >> >> I consider regexs more fundemental > >I'm sure that there are people who consider the International Space Station >more fundamental than the lever, the wedge and the hammer, but they would be >wrong too. > >Given primitives for branching, loops and variables, you can build support >for regexes. Given regexes, how would you build support for variables? > >Of course, you could easily prove me wrong. All you would need to do to >demonstrate that regexes are more fundamental than branching, loops and >variables would be to demonstrate that the primitive operations available in >commonly used CPUs are regular expressions, and that (for example) C's for >loop and if...else are implemented in machine code as regular expressions, >rather than the other way around. So far the only use I have for regex is to replace slicing, but I think it is an improvement. From dpantele at dpantele.com Wed Nov 4 18:08:41 2015 From: dpantele at dpantele.com (Dmitry Panteleev) Date: Wed, 4 Nov 2015 18:08:41 -0500 Subject: Bugfixing python 3.5 asyncio In-Reply-To: References: Message-ID: Hello, Yes, the fix has been merged. If 3.5.1 gets released in a month, it should not be a problem. And looks like it dpends on http://bugs.python.org/issue25446 . Thank you for the information. Dmitry On Wed, Nov 4, 2015 at 5:52 PM, Terry Reedy wrote: > On 11/3/2015 8:24 PM, Dmitry Panteleev wrote: >> >> Hello, >> >> There is a bug in asyncio.Queue >> (https://github.com/python/asyncio/issues/268), which makes it >> unusable for us. It is fixed in master now. > > > I presume that the fix has been merged into the CPython repository (you > could check). If so, it should be included when 3.5.1 is released in about > a month+. > >> What is the easiest way to >> patch the asyncio bundled with python if I have to distribute it among >> 5 colleagues? It is used in our private module. > > > The cleanest way -- in my opinion -- would be to patch your 3.5.0 > installations, making them '3.5.0+'. For 5 installations, > >> I can think of: >> 1. Copy asyncio.queues into our package so it has a different name > > > this would be easiest, but then I would retest and presumably revise and > redistribute after 3.5.1 is out > >> 2. Override sys.path >> >> Both look really strange. Is there anything else? > > > What I said above. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list -- Best Regards, Dmitry Panteleev From tjreedy at udel.edu Wed Nov 4 18:08:51 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 4 Nov 2015 18:08:51 -0500 Subject: Regular expressions In-Reply-To: <56397a18$0$11094$c3e8da3@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 11/3/2015 10:23 PM, Steven D'Aprano wrote: > I don't even know what grep stands for. Get Regular Expression & Print -- Terry Jan Reedy From joel.goldstick at gmail.com Wed Nov 4 18:24:43 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 4 Nov 2015 18:24:43 -0500 Subject: any practise site about python? In-Reply-To: References: <4b7392fb-8639-49d2-a09d-a06bbbcbcff7@googlegroups.com> Message-ID: On Wed, Nov 4, 2015 at 5:59 PM, Emile van Sebille wrote: > On 11/4/2015 11:38 AM, alperen wrote: > >> hi guys. >> i am computer engineering student and i want to practise the lectures >> that i saw at school. for example dictionaries tuples or some other topics. >> i know eulerproject but it is hard for starting. do you know any exercise >> sites for students or beginners >> >> > Any of the top four hits googling 'getting started with python' should > provide you a thread to pull on. > > Emile > > > -- > https://mail.python.org/mailman/listinfo/python-list > The python tutorial at python.org is good. Also, python the hard way is good. -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From Seymore4Head at Hotmail.invalid Wed Nov 4 18:29:51 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 04 Nov 2015 18:29:51 -0500 Subject: Regular expressions References: <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On Wed, 4 Nov 2015 18:08:51 -0500, Terry Reedy wrote: >On 11/3/2015 10:23 PM, Steven D'Aprano wrote: > >> I don't even know what grep stands for. > >Get Regular Expression & Print Thanks, I may get around to that eventually. From Seymore4Head at Hotmail.invalid Wed Nov 4 18:30:23 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Wed, 04 Nov 2015 18:30:23 -0500 Subject: OT ish History Channel - The Invention of the Internet Message-ID: https://www.youtube.com/watch?v=M9ebkjWU6Z4 From rurpy at yahoo.com Wed Nov 4 19:13:58 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 16:13:58 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> Message-ID: <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> On 11/04/2015 07:52 AM, Chris Angelico wrote: > On Thu, Nov 5, 2015 at 1:38 AM, rurpy wrote: >> I'm afraid you are making a category error but perhaps that's in >> part because I wasn't clear. I was not talking about computer >> science. I was talking about human beings learning about computers. >> Most people I know consider programming to be a higher level activity >> than "using" a computer: editing, sending email etc. Many computer >> users (not programmers) learn to use regular expressions as part >> of using a computer without knowing anything about programming. >> It was on that basis I called them more fundamental -- something >> learned earlier which is expanded on and added to later. But you >> have a bit of a point, perhaps "fundamental" was not the best choice >> of word to communicate that. > > The "fundamentals" of something are its most basic functions, not its > most basic uses. The most common use of a computer might be to browse > the web, but the fundamental functionality is arithmetic and logic. If one accepted that then one would have to reject the term "fundamental use" as meaningless. A quick trip to google shows that's not true. > Setting aside the choice of word, though, I still don't think regular > expressions are a more basic use of computing than loops and > conditionals. A regex can't be used for anything other than string > matching; they exist for one purpose, and one purpose only: to answer > the question "Does this string match this pattern?". But string matching *is* a fundamental problem that arises frequently in many aspects of CS, programming and, as I mentioned, day-to-day computer use. Saying its "only" for pattern matching is like saying floating point numbers are "only" for doing non-integer arithmetic, or unicode is "only" for representing text. (Neither of those is a good analogy because both lack the important theoretical underpinnings that regular expressions have [*]). There would be far fewer computer languages, and they would be much more primitive if regular expressions (and the fundamental concepts that they express) did not exist. To be sure, I did gloss over Michael Torries' point that there are other concepts that are more basic in the context of learning programming, he was correct about that. But that does not negate the fact that regexes are important and fundamental. They are both very useful in a practical sense (they are even available in Microsoft Excel) and important in a theoretical sense. You are not well rounded as a programmer if you decline to learn about regular expressions because "they are too cryptic", or "I can do in code anything they do". I think the constant negative reception the posters receive here when they ask about regexes does them a great disservice. By all means point out that python offers a number of functions that can avoid the need for using regexes in simple cases. Even point out that you (the plural you) don't like them and prefer other solutions (like writing code that does the same thing in a more half-assed bug ridden way, the posts in this thread being a case in point.) But I really wish every mention of regexes here wasn't reflexively greeted with a barrage of negative comments and that lame "two problems" quote, especially without an answer to the poster's regex question. > Sure, you can > abuse that into a primality check and other forms of crazy arithmetic, > but it's not what they truly do. I also would not teach regexes to > people as part of an "introduction to computing" course, any more than > I would teach the use of Microsoft Excel, which some such courses have > been known to do. (And no, it's not because of the Microsoftness. I > wouldn't teach LibreOffice Calc either.) You don't need to know how to > work a spreadsheet as part of the basics of computer usage, and you > definitely don't need an advanced form of text search. Seems to me that clearly depends on the intent of the class, the students goal's, what they'll be studying after the class, what their current level of knowledge is, etc. Your scenario seems way too under-specified to say anything definitive. And further, the pedagogy of CS (or of any subject of education) is not "settled science" and that kind of question almost never has a clear right/wrong answer. This list is not a class. If someone comes here with a question about Python's regexes they deserve an answer and not be bombarded with reasons why they shouldn't be using regexes beyond mentioning some of the alternatives in a "oh, by the way" way. (And yes, I recognize in this case the OP did get a good answer from MRAB early on.) ---- [*] yes, I know there is a lot of CS theory underlying floating point. I don't think it is as deep or as important as that underlying regexes, automata and language. From rurpy at yahoo.com Wed Nov 4 19:24:27 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 16:24:27 -0800 (PST) Subject: Regular expressions In-Reply-To: <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> Message-ID: <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> On Wednesday, November 4, 2015 at 4:05:06 PM UTC-7, Seymore4Head wrote: >[...] > I am still here, but I have to admit I am not picking up too much. The "take away" I recommend is: the folks here are often way overly negative regarding regular expressions and that you not ignore them, but take them with a BIG grain of salt and continue learning about and using regexs. You will find they are an indispensable tool, not just in Python programming but in many aspects of computer use. From rosuav at gmail.com Wed Nov 4 19:33:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 11:33:45 +1100 Subject: Regular expressions In-Reply-To: <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> Message-ID: On Thu, Nov 5, 2015 at 11:13 AM, rurpy--- via Python-list wrote: > On 11/04/2015 07:52 AM, Chris Angelico wrote: >> On Thu, Nov 5, 2015 at 1:38 AM, rurpy wrote: >>> I'm afraid you are making a category error but perhaps that's in >>> part because I wasn't clear. I was not talking about computer >>> science. I was talking about human beings learning about computers. >>> Most people I know consider programming to be a higher level activity >>> than "using" a computer: editing, sending email etc. Many computer >>> users (not programmers) learn to use regular expressions as part >>> of using a computer without knowing anything about programming. >>> It was on that basis I called them more fundamental -- something >>> learned earlier which is expanded on and added to later. But you >>> have a bit of a point, perhaps "fundamental" was not the best choice >>> of word to communicate that. >> >> The "fundamentals" of something are its most basic functions, not its >> most basic uses. The most common use of a computer might be to browse >> the web, but the fundamental functionality is arithmetic and logic. > > If one accepted that then one would have to reject the term "fundamental > use" as meaningless. A quick trip to google shows that's not true. A quick trip to Google showed me that there are a number of uses of the phrase, mostly in scientific papers and such. I've no idea how that helps your argument. > But string matching *is* a fundamental problem that arises frequently > in many aspects of CS, programming and, as I mentioned, day-to-day > computer use. Saying its "only" for pattern matching is like saying > floating point numbers are "only" for doing non-integer arithmetic, > or unicode is "only" for representing text. (Neither of those is a > good analogy because both lack the important theoretical underpinnings > that regular expressions have [*]). String matching does happen a lot. How often do you actually need pattern matching? Most of the time, you're doing equality checks - or prefix/suffix checks, at best. > There would be far fewer computer languages, and they would be much > more primitive if regular expressions (and the fundamental concepts > that they express) did not exist. So? There would also be far fewer computer languages if braces didn't exist, because we wouldn't have the interminable arguments about whether they're good or not. > To be sure, I did gloss over Michael Torries' point that there are > other concepts that are more basic in the context of learning > programming, he was correct about that. > > But that does not negate the fact that regexes are important and > fundamental. They are both very useful in a practical sense (they > are even available in Microsoft Excel) and important in a theoretical > sense. You are not well rounded as a programmer if you decline to > learn about regular expressions because "they are too cryptic", or > "I can do in code anything they do". You've proven that they are important, but in no way have you proven them fundamental. A regular expression library is the ideal solution to the problem "I want to let my users search for patterns of their own choosing". That's great, but it's only one specific class of problem. > I think the constant negative reception the posters receive here when > they ask about regexes does them a great disservice. > > By all means point out that python offers a number of functions that > can avoid the need for using regexes in simple cases. Even point out > that you (the plural you) don't like them and prefer other solutions > (like writing code that does the same thing in a more half-assed bug > ridden way, the posts in this thread being a case in point.) > > But I really wish every mention of regexes here wasn't reflexively > greeted with a barrage of negative comments and that lame "two problems" > quote, especially without an answer to the poster's regex question. When has that happened? Usually there'll be at least two answers - one that uses a regex and one that doesn't - and people get to read both. >> Sure, you can >> abuse that into a primality check and other forms of crazy arithmetic, >> but it's not what they truly do. I also would not teach regexes to >> people as part of an "introduction to computing" course, any more than >> I would teach the use of Microsoft Excel, which some such courses have >> been known to do. (And no, it's not because of the Microsoftness. I >> wouldn't teach LibreOffice Calc either.) You don't need to know how to >> work a spreadsheet as part of the basics of computer usage, and you >> definitely don't need an advanced form of text search. > > Seems to me that clearly depends on the intent of the class, the students > goal's, what they'll be studying after the class, what their current > level of knowledge is, etc. Your scenario seems way too under-specified > to say anything definitive. And further, the pedagogy of CS (or of any > subject of education) is not "settled science" and that kind of question > almost never has a clear right/wrong answer. Uhh, "introduction to computing". What's the current level of knowledge? Close to zero. That's the whole point of an introductory class. It's a place where you teach the basics. > This list is not a class. If someone comes here with a question about > Python's regexes they deserve an answer and not be bombarded with reasons > why they shouldn't be using regexes beyond mentioning some of the alternatives > in a "oh, by the way" way. (And yes, I recognize in this case the OP did > get a good answer from MRAB early on.) "I want to swim from Sydney to Los Angeles, but my gloves keep wearing out half way across the Pacific. How can I make my gloves strong enough to get me to LA?" Response 1: "If you use industrial-strength gloves and go via Papua New Guinea, you can double up the gloves and swim to LA." Response 2: "Swimming across the Pacific is a bad idea. Have you considered taking a boat or plane instead?" Which is the more helpful response? You can go ahead and assume the OP always knows best; I'm going to at least offer some alternatives. ChrisA From rosuav at gmail.com Wed Nov 4 19:34:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 11:34:26 +1100 Subject: Regular expressions In-Reply-To: <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> Message-ID: On Thu, Nov 5, 2015 at 11:24 AM, rurpy--- via Python-list wrote: > On Wednesday, November 4, 2015 at 4:05:06 PM UTC-7, Seymore4Head wrote: >>[...] >> I am still here, but I have to admit I am not picking up too much. > > The "take away" I recommend is: the folks here are often way > overly negative regarding regular expressions and that you not > ignore them, but take them with a BIG grain of salt and continue > learning about and using regexs. > > You will find they are an indispensable tool, not just in Python > programming but in many aspects of computer use. The "take away" that I recommend is: Rurpy loves to argue in favour of regular expressions, but as you can see from the other posts, there are alternatives, which are often FAR superior. ChrisA From rosuav at gmail.com Wed Nov 4 19:42:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 11:42:41 +1100 Subject: =?UTF-8?B?UmU6IFdoYXQgZG9lcyDigJxncmVw4oCdIHN0YW5kIGZvcj8=?= In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On Thu, Nov 5, 2015 at 6:38 AM, Christian Gollwitzer wrote: > Am 04.11.15 um 19:24 schrieb Ben Finney: >> >> The name is a mnemonic for a compound command in ?ed? [0], a text editor >> that pre-dates extravagant luxuries like ?presenting a full screen of >> text at one time?. >> >> [... lots of fun facts ...] > > > Here is another fun fact: The convincing UI of ed was actually so widely > applied, that even Microsoft included a similar editor into MSDOS, called > EDLIN. EDLIN, of course, was a bastardized version of ed that could do much > less and also lacked regular expressions. Needless to say that the mighty > "VIsual" editor was out 5 years before MSDOS shipped EDLIN as the only > editor... > > In contrast to ed, the stream editor "sed" is used multiple times avery day > in a typical Unix session inside shell scripts to perform automated text > processing tasks, including regex replacement. As someone who grew up on MS-DOS, I'd like to mention that EDLIN's value wasn't in the obvious places. There were two features it had that most other editors didn't: firstly, it would read only as much of the file as it needed, so you could edit a file larger than available memory; and secondly, all commands came from stdin, which could be redirected - making it a poor man's 'sed'. Using EDLIN for regular file editing was never the normal thing. Fast forward a decade or two, and I'm working on a MUD server for a friend. It incorporates an editor that can be used on a dumb telnet connection - and it's line based again. So there's clearly some value here :) Visual editors get the lion's share of actual editing work, but in special circumstances, it is nice to have a quick little ed-like program around. ChrisA From steve at pearwood.info Wed Nov 4 19:44:39 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 05 Nov 2015 11:44:39 +1100 Subject: raw_input and break References: Message-ID: <563aa679$0$1608$c3e8da3$5496439d@news.astraweb.com> On Thu, 5 Nov 2015 09:37 am, input/ldompeling at casema.nl wrote: > I quote the s, but its still break even when I not press the s. The code you have shown us is so full of bugs and typos that you cannot possibly be running that code. Unfortunately, we do not have magical powers. We cannot see the code you *actually* run, only the code you show us. So if you want help, you need to show us the code you actually run. COPY AND PASTE -- do not retype from memory -- the while loop from your code. Make sure it will run on its own. If you can't run the code, because it lacks variables or something else, neither can we. Help us to help you. We cannot help you unless you show us the code you are running. -- Steven From steve at pearwood.info Wed Nov 4 19:54:20 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 05 Nov 2015 11:54:20 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <1i3l3b9836hatsuoopak5gtg2c38g49kb1@4ax.com> Message-ID: <563aa8be$0$1596$c3e8da3$5496439d@news.astraweb.com> On Thu, 5 Nov 2015 10:02 am, Seymore4Head wrote: > So far the only use I have for regex is to replace slicing, but I > think it is an improvement. I don't understand this. This is like saying "so far the only use I have for a sandwich press is to replace my coffee pot". Regular expressions and slicing do very different things. Slicing extracts substrings, given known starting and ending positions: py> the_str = "Now is the time for all good men..." py> the_str[7:12] 'the t' Regular expressions don't extract substrings with known start/end positions. They *find* matching text, giving a search string with metacharacters. (If there are no metacharacters in your search string, you shouldn't use a regex. str.find will be significantly faster and more convenient.) Slicing is not about finding text, it is about extracting text once you've already found it. So they are complementary, not alternatives. -- Steven From steve at pearwood.info Wed Nov 4 21:24:25 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 05 Nov 2015 13:24:25 +1100 Subject: Regular expressions References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> Message-ID: <563abdda$0$1614$c3e8da3$5496439d@news.astraweb.com> On Thu, 5 Nov 2015 11:24 am, rurpy at yahoo.com wrote: > You will find they are an indispensable tool, not just in Python > programming but in many aspects of computer use. You will find them a useful tool, but not indispensable by any means. Hint: - How many languages make arithmetic a built-in part of the language? Almost all of them. I don't know of any language that doesn't let you express something like "1 + 1" using built-in functions or syntax. Arithmetic is much closer to indispensable. - How many languages make regular expressions a built-in part of the language? Almost none of them. There's Perl, obviously, and its predecessors sed and awk, and probably a few others, but most languages relegate regular expressions to a library. - How many useful programs can be written with regexes? Clearly there are many. Some of them would even be quite difficult without regexes. (In effect, you would have to invent your own pattern-matching code.) - How many useful programs can be written without regexes? Clearly there are also many. Every time you write a Python program and fail to import re, you've written one. Can you call yourself a well-rounded programmer without at least a basic understanding of some regex library? Well, probably not. But that's part of the problem with regexes. They have, to some degree, driven out potentially better -- or at least differently bad -- pattern matching solutions, such as (E)BNF grammars, SNOBOL pattern matching, or lowly globbing patterns. Or even alternative idioms, like Hypercard's "chunking" idioms. When all you have is a hammer, everything looks like a nail. -- Steven From steve at pearwood.info Wed Nov 4 21:26:55 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 05 Nov 2015 13:26:55 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> Message-ID: <563abe6f$0$1614$c3e8da3$5496439d@news.astraweb.com> On Thu, 5 Nov 2015 11:13 am, rurpy at yahoo.com wrote: > There would be far fewer computer languages, and they would be much > more primitive if regular expressions (and the fundamental concepts > that they express) did not exist. Well, that's certainly true. But only because contra-factual statements can imply the truth of anything. If squares had seven sides, then Joseph Stalin would have been the first woman to go to the moon on horseback. I can't imagine a world where pattern matching doesn't exist. That's like trying to imagine a world where arithmetic doesn't exist. But I think we can safely say that, had nobody thought of the idea of searching for patterns ('find me all the lines with "green" in them'), there would be far fewer regex libraries in existence. I doubt that there would be "far fewer" programming languages. With the possible exception of Perl, sed and awk, I'm not aware of any languages which were specifically inspired by, and exist primarily to apply, regular expressions, nor any languages which *require* regexes in their implementation. Most languages are built on parsers, not regular expressions. > But I really wish every mention of regexes here wasn't reflexively > greeted with a barrage of negative comments and that lame "two problems" > quote, especially without an answer to the poster's regex question. I don't disagree with this. Certainly we should accept questions from people who are simply trying to learn how to use regexes without bombarding them with admonitions to do something different. Yes yes, I know that regexes aren't the only tool in my tool box, but *right now* I want to learn how to use regexes. -- Steven From steve at pearwood.info Wed Nov 4 21:28:49 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 05 Nov 2015 13:28:49 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> Message-ID: <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: > I tried Tim's example > > $ seq 5 | grep '1*' > 1 > 2 > 3 > 4 > 5 > $ I don't understand this. What on earth is grep matching? How does "4" match "1*"? > which surprised me because I remembered that there usually weren't any > matching lines when I invoked grep instead of egrep by mistake. So I tried > another one > > $ seq 5 | grep '[1-3]+' > $ > > and then headed for the man page. Apparently there is a subset called > "basic regular expressions": > > """ > Basic vs Extended Regular Expressions > In basic regular expressions the meta-characters ?, +, {, |, (, > and ) lose their special meaning; instead use the backslashed > versions \?, \+, \{, \|, \(, and \). > """ None of this appears relevant, as the metacharacter * is not listed. So what's going on? -- Steven From python.list at tim.thechases.com Wed Nov 4 21:48:15 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Nov 2015 20:48:15 -0600 Subject: Regular expressions In-Reply-To: <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20151104204815.4263e11c@bigbox.christie.dr> On 2015-11-05 13:28, Steven D'Aprano wrote: > > I tried Tim's example > > > > $ seq 5 | grep '1*' > > 1 > > 2 > > 3 > > 4 > > 5 > > $ > > I don't understand this. What on earth is grep matching? How does > "4" match "1*"? The line with "4" matches "zero or more 1s". If it was searching for a literal "1*" (as would happen with fgrep or "grep -F"), it would return no results: $ seq 5 | fgrep '1*' $ -tkc From ben+python at benfinney.id.au Wed Nov 4 22:03:45 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Nov 2015 14:03:45 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85pozpjgfi.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: > > > I tried Tim's example > > > > $ seq 5 | grep '1*' > > 1 > > 2 > > 3 > > 4 > > 5 > > $ > > I don't understand this. What on earth is grep matching? How does "4" > match "1*"? You can experiment with regular expressions to find out. Here's a link to the RegExr tool for the above pattern . Matching patterns can include specifications meaning ?match some number of the preceding segment?, with the ?{n,m}? notation. That means ?match at least n, and at most m, occurrences of the preceding segment?. Either ?n? or ?m? can be omitted, meaning ?at least 0? and ?no maximum? respectively. Those are quite useful, so there are shortcuts for the most common cases: ??? is a short cut for ?{0,1}?, ?*? is a short cut for ?{0,}?, and ?+? is a short cut for ?{1,}?. In this case, ?*? is a short cut for ?{0,}? meaning ?match 0 or more occurences of the preceding segment?. The segment here is the atom ?1?. Since ?1*? is the entirety of the pattern, the pattern can match zero characters, anywhere within any string. So, it matches every possible string. To match (some atom) 1 or more times, ?+? is a short cut for ?(1,}? meaning ?match 1 or more occurrences of the preceding segment?. -- \ ?????????????? (To study and not think is a waste. | `\ To think and not study is dangerous.) | _o__) ???? Confucius (551 BCE ? 479 BCE) | Ben Finney From ben+python at benfinney.id.au Wed Nov 4 22:07:16 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Nov 2015 14:07:16 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> <563abe6f$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85lhadjg9n.fsf@benfinney.id.au> Steven D'Aprano writes: > Yes yes, I know that regexes aren't the only tool in my tool box, but > *right now* I want to learn how to use regexes. I'll gently suggest this isn't a particularly good forum to do so. Learn them with a tool like and a tutorial or something longer. -- \ ?Fascism is capitalism plus murder.? ?Upton Sinclair | `\ | _o__) | Ben Finney From zljubisic at gmail.com Wed Nov 4 22:41:38 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 4 Nov 2015 19:41:38 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: > The best way is probably to do nothing at all, and let the caller handle > any exceptions. In that case every call of the get_html function has to be in the try/except block with many exceptions. Sometimes, it is enough just to know whether I managed to get the html or not. In that case, I could for example, in get_html have try/except block which will as result raise let's say NoHtml custom exception or return some special value. Raising an exception forces me to put every call of the get_html function in try/except block. If I am returning a special value, than I can call get_html and then test the value. I am not sure which approach is better. From rosuav at gmail.com Wed Nov 4 22:58:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 14:58:33 +1100 Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: On Thu, Nov 5, 2015 at 2:41 PM, wrote: > Raising an exception forces me to put every call of the get_html function in try/except block. > If I am returning a special value, than I can call get_html and then test the value. > > I am not sure which approach is better. Raising an exception means that if you fail to put it in a try/except, you get a traceback that walks you through the exact location of the problem. Returning a special value means that if you fail to test the value, you either get an exception further on (if you get back None and try to treat it as a string, for instance), or get incorrect results, with no indication of the actual cause of the problem. Which would you prefer? ChrisA From zljubisic at gmail.com Wed Nov 4 23:11:38 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 4 Nov 2015 20:11:38 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: On Monday, 2 November 2015 21:59:45 UTC+1, Ian wrote: > I'm having a hard time understanding what question you're asking. :) I am really having a hard time to explain the problem as English is not my first language. > You > have a lot of discussion about where to handle exceptions, That's right. I am not sure where to handle exceptions and at the same time to have the code clean as possible. For example John from the previous post suggested raising exceptions in the get_html procedure. That would mean that I should put every call of get_html function to the try/except block. In this particular example, I would like just to know whether I managed to get_html or not. In case I am experiencing some problems inside of the get_html function I could maybe retry several times, but this function should return the html or inform the caller that it is unable to get the html. For caller, the reason why get_html function couldn't get the html is not important. For now, I am thinking that maybe I should use an approach in which I will have except block in get_html that will be responsible for several exceptions, something like this: def get_html(url): try: wpage = requests.get(url) except ConnectionError, exception_a, exceptionb...: flog('warning', 'ConnectionError exception', log_except=True) raise NoHtml return In that way the caller can put get_html function in try/except block but just paying an attention to the NoHtml exception which is much clearer than to have except ConnectionError except exception_a except exceptionb...: in every call of the get_html. > but the > examples that you show are of logging the the exception and re-raising > it, which is a good practice but distinct from handling the exception. I mentioned logging in get_html because I don't know what else I should do with an exception in get_html function. > Then you seem to be asking about the practice of returning None as an > alternative to propagating the exception, but the example you show > only returns None in a case where no exception was raised in the first > place. I returned None based of the wpage.status_code == requests.codes.ok. I assume that if this condition is true, everything went well. Otherwise, I could forget to put some explicit exceptions in the except block so try block will pass even if certain exception has happened. I read that catching all exception with except Exception as e: is not a good option. > None is arguably reasonable to return when it makes sense as a > non-exceptional value in the context. For example, if you're looking > up a policy that may or may not exist, then your get_policy function > might return None to indicate no value. If get_policy fails because of > an RPC timeout however, then it needs to raise an exception rather > than possibly incorrectly returning "no policy". If I understood correctly, in my case I could ask for getting the html from non existent web page or I can have communication (network) problem. In any of these two cases if I return None I will newer know that web page doesn't exist. Good point. > In comparison, if you're returning something that should always have a > value, then you should never return None. In such a case, None would > indicate that something went wrong, but it lacks any information about > *what* went wrong. An exception, on the other hand, is ideal for > carrying that sort of information. Returning None in such a scenario > is also risky in that the caller may not be expecting None and may try > to treat it as a normal value. In some cases this may even appear to > work until something breaks in a completely different part of the > code. So my get_html function should never return None in that case. > In the example given, the case where None is returned is clearly an > exceptional case (non-success) even though no exception was raised by > requests.get. You should raise an exception there instead of returning > None to allow the caller better control over the situation. I am kind of getting the philosophy of exceptions but I still have some dilemmas as you could see above. Thank you very much for your comments. Regards. From zljubisic at gmail.com Wed Nov 4 23:18:20 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 4 Nov 2015 20:18:20 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: <4cb51da8-9331-4efe-87d3-dfe9c2ae0f8e@googlegroups.com> > Which would you prefer? So if I am just checking for the ConnectionError in get_html and a new exception arises, I will have traceback to the get_html function showing that unhandled exception has happened. Now I have to put additional exception block for managing the new exception in the get_html function and I am covered. Is that what you wanted to say? From rosuav at gmail.com Wed Nov 4 23:51:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 15:51:41 +1100 Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: <4cb51da8-9331-4efe-87d3-dfe9c2ae0f8e@googlegroups.com> References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> <4cb51da8-9331-4efe-87d3-dfe9c2ae0f8e@googlegroups.com> Message-ID: On Thu, Nov 5, 2015 at 3:18 PM, wrote: >> Which would you prefer? > > So if I am just checking for the ConnectionError in get_html and a new exception arises, I will have traceback to the get_html function showing that unhandled exception has happened. > Now I have to put additional exception block for managing the new exception in the get_html function and I am covered. > > Is that what you wanted to say? Yep. I would definitely recommend having get_html raise an exception on any problem; here's the structure I'd use: def get_html(...): try: ... actually go get the info return info except (ConnectionError, OSError, SocketError) as e: raise ContentNotFoundError from e This means there are three possibilities: 1) Everything works correctly, and get_html returns something useful. 2) An exception occurs of a type that you expect - the server didn't respond, or the OS threw back a failure, or whatever. (You'd decide what set of exceptions this represents.) In this case, you get a single exception that wraps that up and summarizes the problem as "Content Not Found". The original exception is retained in the __cause__ of the ContentNotFoundError, so no information is lost. 3) An unexpected exception occurs - your script runs out of memory, or there's a bug in your code, or anything else. The exception will simply bubble up, and be dealt with somewhere else. To use this code, what you'd do is: try: data = get_html(...) except ContentNotFoundError: # deal with the case of not having anything to work with Omitting the try/except is a perfectly reasonable way of working, too. Just call get_html, and if ever it can't get a result, the exception continues to propagate. It's easy, it's straight-forward, and it's unambiguous - any problem you don't expect becomes an exception. ChrisA From tian.su.yale at gmail.com Thu Nov 5 00:02:07 2015 From: tian.su.yale at gmail.com (tian.su.yale at gmail.com) Date: Wed, 4 Nov 2015 21:02:07 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: <4cb51da8-9331-4efe-87d3-dfe9c2ae0f8e@googlegroups.com> References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> <4cb51da8-9331-4efe-87d3-dfe9c2ae0f8e@googlegroups.com> Message-ID: <7ab19923-54e9-49b8-a982-a4b2c2e9c874@googlegroups.com> ? 2015?11?4???? UTC-6??10:18:33?zlju... at gmail.com??? > > Which would you prefer? > > So if I am just checking for the ConnectionError in get_html and a new exception arises, I will have traceback to the get_html function showing that unhandled exception has happened. > Now I have to put additional exception block for managing the new exception in the get_html function and I am covered. > > Is that what you wanted to say? Hi, If I may, I feel you are trying to address a few separate questions, although they do relate to each other. 1. Coding Design: with the try/except block inside or outside the function 2. Exception Handling: What to do with new un-anticipated exceptions 3. How to record the exception for reference: logging or special value My feeling is: 1. Personally prefer to put try/except block outside the function, to keep the code clean and easy to follow. 2. I would suggest follow the Test Driven Development (TDD) approach. You are not able to anticipate all types of possible exceptions. However, I'm sure you have a pretty good idea about what exceptions are more likely to happen and cause you problem. In that case, just develop your code to pass these tests, and refactor it in the future if really needed. Not necessary to push your code to be perfect, able to handle every possible exception. 3. Kind of personal choice here, since no matter which way you go, you do need to follow it up and deal with them. Probably I would log it just for record keeping purpose. As long as you follow up and trace back to the root cause, they seem to serve the same goal. Hope this helps... All the best, Tian From tian.su.yale at gmail.com Thu Nov 5 00:15:38 2015 From: tian.su.yale at gmail.com (tian.su.yale at gmail.com) Date: Wed, 4 Nov 2015 21:15:38 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: Hi, If I may, I feel you are tying to address a few questions at the same time, although they are related 1. Where to put the try/except block, inside or outside the function 2. How to deal with un-anticipated exceptions 3. How to keep record My personal feelings are: 1. Kind of prefer try/except block outside the function though. This way it looks clean and easy to follow. In terms of logging the url, since you pass it to the function anyway, there should be ways to keep this option, even with the block written outside the function. 2. From code development perspective, would suggest you follow Test Driven Development (TDD) approach. Nobody can anticipate all of the possible outcomes, but I'm sure you have a pretty good idea about the most likely scenarios, and just make sure that your code is suitable for these scenarios. When future new exceptions arise, you can always refactor your code as needed. 3. Feel it's a personal choice here as being pointed out earlier. No mater which way you go, you just have to follow it up and deal with it, trace it back to the root cause. I kind of prefer logging, so to keep a good record for myself, and you can make it very informative. Hope this helps. All the best, Tian From tian.su.yale at gmail.com Thu Nov 5 00:39:16 2015 From: tian.su.yale at gmail.com (tian.su.yale at gmail.com) Date: Wed, 4 Nov 2015 21:39:16 -0800 (PST) Subject: raw_input and break In-Reply-To: References: Message-ID: <4270fade-5f09-4935-a99a-f2be344202b2@googlegroups.com> ? 2015?11?4???? UTC-6??3:45:09?input/ld... at casema.nl??? > I have an continues loop with "while True:" > Now I want to use "raw_input" and when I press "s" on the keybord that it will > "break" the continues loop. > > I tried: > choices = raw_input > if choises == s: > break > > But even when I not press "s" it "break" > I want that I not press "s" the script continues. > > Any ideas ? > > Thanks > > > > -- > --------------------------------- --- -- - > Posted with NewsLeecher v7.0 Beta 2 > Web @ http://www.newsleecher.com/?usenet > ------------------- ----- ---- -- - while True: inp = input("Enter whatever you want, letter 's' to stop: ") if inp == 's': print("Program stopped.") break print("You just entered:", inp) Is this along the line that you are thinking? As pointed out earlier, it will be much easier for people to help if you can share the exact code you put into and the error messages as well. Thanks and good luck! All the best, Tian From rurpy at yahoo.com Thu Nov 5 00:42:16 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 21:42:16 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> Message-ID: On 11/04/2015 05:33 PM, Chris Angelico wrote: > On Thu, Nov 5, 2015 at 11:13 AM, rurpy--- via Python-list > wrote: >> On 11/04/2015 07:52 AM, Chris Angelico wrote: >>> On Thu, Nov 5, 2015 at 1:38 AM, rurpy wrote: >>>> I'm afraid you are making a category error but perhaps that's in >>>> part because I wasn't clear. I was not talking about computer >>>> science. I was talking about human beings learning about computers. >>>> Most people I know consider programming to be a higher level activity >>>> than "using" a computer: editing, sending email etc. Many computer >>>> users (not programmers) learn to use regular expressions as part >>>> of using a computer without knowing anything about programming. >>>> It was on that basis I called them more fundamental -- something >>>> learned earlier which is expanded on and added to later. But you >>>> have a bit of a point, perhaps "fundamental" was not the best choice >>>> of word to communicate that. >>> >>> The "fundamentals" of something are its most basic functions, not its >>> most basic uses. The most common use of a computer might be to browse >>> the web, but the fundamental functionality is arithmetic and logic. >> >> If one accepted that then one would have to reject the term "fundamental >> use" as meaningless. A quick trip to google shows that's not true. > > A quick trip to Google showed me that there are a number of uses of > the phrase, mostly in scientific papers and such. I've no idea how > that helps your argument. I was showing that your objection to my use of "fundamental" on the grounds it does not apply to "use" is patently silly. From Google: interferes with B's more fundamental use because fundamental use of english The fundamental use of testing Fundamental Use of the Michigan Terminal System negotiate a fundamental use and exchange of power the most fundamental use of pointers makes fundamental use of statistical theory This is what I meant in a recent post when I referred to the Alice- in-Wonderland nature of this group. I'm afraid I don't have the time or interest to discuss basic english with you. If you want to maintain that "fundamental" does apply to "use" please go right ahead, it's your credibility at risk. >> But string matching *is* a fundamental problem that arises frequently >> in many aspects of CS, programming and, as I mentioned, day-to-day >> computer use. Saying its "only" for pattern matching is like saying >> floating point numbers are "only" for doing non-integer arithmetic, >> or unicode is "only" for representing text. (Neither of those is a >> good analogy because both lack the important theoretical underpinnings >> that regular expressions have [*]). > > String matching does happen a lot. How often do you actually need > pattern matching? Most of the time, you're doing equality checks - or > prefix/suffix checks, at best. > >> There would be far fewer computer languages, and they would be much >> more primitive if regular expressions (and the fundamental concepts >> that they express) did not exist. > > So? There would also be far fewer computer languages if braces didn't > exist, because we wouldn't have the interminable arguments about > whether they're good or not. Sorry, that makes no sense to me. >> To be sure, I did gloss over Michael Torries' point that there are >> other concepts that are more basic in the context of learning >> programming, he was correct about that. >> >> But that does not negate the fact that regexes are important and >> fundamental. They are both very useful in a practical sense (they >> are even available in Microsoft Excel) and important in a theoretical >> sense. You are not well rounded as a programmer if you decline to >> learn about regular expressions because "they are too cryptic", or >> "I can do in code anything they do". > > You've proven that they are important, but in no way have you proven > them fundamental. A regular expression library is the ideal solution > to the problem "I want to let my users search for patterns of their > own choosing". That's great, but it's only one specific class of > problem. If you think that is the sole use of pattern matching or even the most important use, I can understand why you find regexes fairly useless. Lexing (tokenization) and simple parsing are often done with regular expressions. Many dozens of times a year I write programs to extract or munge data in text files. Three days ago I had to extract data from a 500MB log file for insertion in a database that used many regexes, even some that could have been replaced by python methods. But mixing the two approaches would have been less clear than using regexs consistently. Text recognition and modification is an *extremely* common need, not some niche application as you suggest. >> I think the constant negative reception the posters receive here when >> they ask about regexes does them a great disservice. >> >> By all means point out that python offers a number of functions that >> can avoid the need for using regexes in simple cases. Even point out >> that you (the plural you) don't like them and prefer other solutions >> (like writing code that does the same thing in a more half-assed bug >> ridden way, the posts in this thread being a case in point.) >> >> But I really wish every mention of regexes here wasn't reflexively >> greeted with a barrage of negative comments and that lame "two problems" >> quote, especially without an answer to the poster's regex question. > > When has that happened? Usually there'll be at least two answers - one > that uses a regex and one that doesn't - and people get to read both. No, usually there is one answer with a regex, five advising against regexes, and two with the silly "two problems" quote. The impression one is left with is that regexs are bad and to be avoided. Rarely to never does one see a response encouraging a poster to learn about and use regular expressions which is why I spoke up this time. >>> Sure, you can >>> abuse that into a primality check and other forms of crazy arithmetic, >>> but it's not what they truly do. I also would not teach regexes to >>> people as part of an "introduction to computing" course, any more than >>> I would teach the use of Microsoft Excel, which some such courses have >>> been known to do. (And no, it's not because of the Microsoftness. I >>> wouldn't teach LibreOffice Calc either.) You don't need to know how to >>> work a spreadsheet as part of the basics of computer usage, and you >>> definitely don't need an advanced form of text search. >> >> Seems to me that clearly depends on the intent of the class, the students >> goal's, what they'll be studying after the class, what their current >> level of knowledge is, etc. Your scenario seems way too under-specified >> to say anything definitive. And further, the pedagogy of CS (or of any >> subject of education) is not "settled science" and that kind of question >> almost never has a clear right/wrong answer. > > Uhh, "introduction to computing". What's the current level of > knowledge? Close to zero. That's the whole point of an introductory > class. It's a place where you teach the basics. "Introduction to computing" covers everything from teaching unemployed people how to use word and excel to a first "algorithms and data structures" for AP high-school kids to programming with a heavy dose of hardware architecture. What "the basics" are is, as far as I know, still the subject of debate and research among professional educators. >> This list is not a class. If someone comes here with a question about >> Python's regexes they deserve an answer and not be bombarded with reasons >> why they shouldn't be using regexes beyond mentioning some of the alternatives >> in a "oh, by the way" way. (And yes, I recognize in this case the OP did >> get a good answer from MRAB early on.) > > "I want to swim from Sydney to Los Angeles, but my gloves keep wearing > out half way across the Pacific. How can I make my gloves strong > enough to get me to LA?" > > Response 1: "If you use industrial-strength gloves and go via Papua > New Guinea, you can double up the gloves and swim to LA." > > Response 2: "Swimming across the Pacific is a bad idea. Have you > considered taking a boat or plane instead?" > > Which is the more helpful response? You can go ahead and assume the OP > always knows best; I'm going to at least offer some alternatives. Using a regular expression (even when there are other alternatives) is not analogous to "Swimming across the Pacific". (Back in Wonderland again.) Using a regex is *not* a life threatening situation. I've said repeatedly that pointing out alternatives is fine. Pointing out there is no need for a regex when searching for a constant string is fine. And similar... But the responses here often go well beyond that in negativity. My own theory is that regexes are associated with Perl in the minds of many participants here and thus provoke an automatic immune reaction. From rurpy at yahoo.com Thu Nov 5 00:54:29 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 21:54:29 -0800 (PST) Subject: Regular expressions In-Reply-To: <563abe6f$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> <563abe6f$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8d2e4d8d-dead-4ffd-b6fd-00d16cd0c26c@googlegroups.com> On Wednesday, November 4, 2015 at 7:31:34 PM UTC-7, Steven D'Aprano wrote: > On Thu, 5 Nov 2015 11:13 am, rurpy wrote: > > > There would be far fewer computer languages, and they would be much > > more primitive if regular expressions (and the fundamental concepts > > that they express) did not exist. > > Well, that's certainly true. But only because contra-factual statements can > imply the truth of anything. If squares had seven sides, then Joseph Stalin > would have been the first woman to go to the moon on horseback. Yes, thank you for that profoundly insightful comment. From rurpy at yahoo.com Thu Nov 5 00:59:51 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 21:59:51 -0800 (PST) Subject: Regular expressions In-Reply-To: <563abdda$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> <563abdda$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2fd7d161-b1cb-4274-b8dc-0157916413f1@googlegroups.com> On 11/04/2015 07:24 PM, Steven D'Aprano wrote: > On Thu, 5 Nov 2015 11:24 am, wrote: > >> You will find they are an indispensable tool, not just in Python >> programming but in many aspects of computer use. > > You will find them a useful tool, but not indispensable by any means. > > Hint: > > - How many languages make arithmetic a built-in part of the language? Almost > all of them. I don't know of any language that doesn't let you express > something like "1 + 1" using built-in functions or syntax. Arithmetic is > much closer to indispensable. By my count there are 2377. That's counting rpn languages where it is 1 1 +. If you don't count them it is 2250. > - How many languages make regular expressions a built-in part of the > language? Almost none of them. There's Perl, obviously, and its > predecessors sed and awk, and probably a few others, but most languages > relegate regular expressions to a library. Yes, like python relegates io to a library. Clearly useful but not indispensable, after all who *really* needs anything beyond print() and input(). And that stuff in math like sin() and exp(). How many programs use that geeky trig stuff? Definitely not indispensable. In fact, now that you pointed it out to me, clearly all that stdlib stuff is dispensable, all one really needs to write "real programmer" programs is just core python. Who the hell needs "sys"! > - How many useful programs can be written with regexes? Clearly there are > many. Some of them would even be quite difficult without regexes. (In > effect, you would have to invent your own pattern-matching code.) Lucky for me then that there are regexes. > - How many useful programs can be written without regexes? Clearly there are > also many. Every time you write a Python program and fail to import re, > you've written one. By golly, you're right. Not every program I write uses regexes. Who would have thought?! However, you failed to establish that the programs I write without re are useful. > Can you call yourself a well-rounded programmer without at least a basic > understanding of some regex library? Well, probably not. But that's part of > the problem with regexes. They have, to some degree, driven out potentially > better -- or at least differently bad -- pattern matching solutions, such > as (E)BNF grammars, SNOBOL pattern matching, or lowly globbing patterns. Or > even alternative idioms, like Hypercard's "chunking" idioms. Hmm, very good point. I wonder why all those "potentially better" solutions have not been more widely adopted? A conspiracy by a secret regex cabal? > When all you have is a hammer, everything looks like a nail. Lucky for us then, that we have more than just hammers! Sorry for the flippant response (well, not really) but I find your arguments pedantic beyond the point of absurdity. For me, regular expressions are indispensable in that if they were not available in Python I would not use Python. The same is true of a number of other stdlib modules. I don't give a rat's ass whether they are in a "library" that has to be explicitly requested with import or a "library" that is automatically loaded at startup. From rurpy at yahoo.com Thu Nov 5 01:27:46 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 4 Nov 2015 22:27:46 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> Message-ID: <7ffc8ea8-6445-4c59-b3b6-611edfbf4f62@googlegroups.com> On Wednesday, November 4, 2015 at 7:46:24 PM UTC-7, Chris Angelico wrote: > On Thu, Nov 5, 2015 at 11:24 AM, rurpy wrote: > The "take away" that I recommend is: Rurpy loves to argue in favour of > regular expressions, No, I don't love it, I quite dislike it. > but as you can see from the other posts, there > are alternatives, which are often FAR superior. No, not FAR superior, just preferable and just in the simple cases, regexes generally being better in anything beyond simple. From greg.ewing at canterbury.ac.nz Thu Nov 5 01:39:10 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 Nov 2015 19:39:10 +1300 Subject: Detection of a specific sound In-Reply-To: References: Message-ID: Joel Goldstick wrote: > Sometimes (maybe most times) the follow on discussion goes off on > insightful tangents that may have little to do with the OP. And then someone mentions a Monty Python sketch about Hitler, thereby both bring the discussion back on-topic *and* invoking Godwin's Law at the same time. Don't-mention-the-war-ly, Greg From auriocus at gmx.de Thu Nov 5 02:32:21 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 5 Nov 2015 08:32:21 +0100 Subject: =?UTF-8?B?UmU6IFdoYXQgZG9lcyDigJxncmVw4oCdIHN0YW5kIGZvcj8=?= In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: Am 05.11.15 um 01:42 schrieb Chris Angelico: > On Thu, Nov 5, 2015 at 6:38 AM, Christian Gollwitzer wrote: > As someone who grew up on MS-DOS, I'd like to mention that EDLIN's > value wasn't in the obvious places. There were two features it had > that most other editors didn't: firstly, it would read only as much of > the file as it needed, so you could edit a file larger than available > memory; and secondly, all commands came from stdin, which could be > redirected - making it a poor man's 'sed'. Using EDLIN for regular > file editing was never the normal thing. I also grew up with MSDOS, albeit some later version (3.0 was the first, I think I remember). I knew that EDLIN existed, but never ever have used it. On my first "own" (actually my father's) machine, the Amstrad PC1512, there was a preinstalled GUI working environment called GEM from Digital Research. The DOS commandline was used for configuring and booting the system, but never for editing files. I had used copy con: to create a file. If I'm not mistaken, DR shipped some "visual" editor for DOS with it as an addition. The point I'm so amused is, that MS has not felt the need to ship a real editor, and also cut back on most of the other tools that make computing, even on commandlines, a pleasant experience. Readline? Tab-Completion? I read a magazine called "DOS", where they scripted the hell out of .BAT-files. When they first showed an article about bash programming, I was really jealous that the people on these strange, exotic OSes had such a complete programming language at their disposal. Now I can't imagine giving it back ever. > > Fast forward a decade or two, and I'm working on a MUD server for a > friend. It incorporates an editor that can be used on a dumb telnet > connection - and it's line based again. So there's clearly some value > here :) Visual editors get the lion's share of actual editing work, > but in special circumstances, it is nice to have a quick little > ed-like program around. In this case I'd copy the file to the local machine and sync it using rsync or git. It's almost as terse in terms of bandwidth as the manual editing commands, but a lot more comfortable. Christian From vmt.eiz at gmail.com Thu Nov 5 02:36:01 2015 From: vmt.eiz at gmail.com (Akshat Tripathi) Date: Wed, 4 Nov 2015 23:36:01 -0800 (PST) Subject: Unable to make http request to django server using twisted.web.client.AGENT Message-ID: I have written a basic tcp server factory, server client and a service using twisted. The tcp server acts as the middleware between a django server and an another program (let's call it client program). What I want to achieve - 1.client requests the middleware tcp server; 2.it sends a string as the request body; 3.the middleware tcp server deserializes information from the request. 4.middleware furthers the serialized information to the django server. 5.The django server then responds to the middleware server which furthers the response to the client after serializing the response. I am able to reach till step 3, but am unable to make any http request to the django server. The following is my middleware.py from twisted.internet.protocol import ServerFactory from twisted.internet.protocol import Protocol from test_service import MyService class TCPServerProtocol(Protocol): data = '' def connectionMade(self): self.deferred = self.factory.service.deferred self.deferred.addCallback(self.factory.service.s) self.deferred.addCallback(self.transport.write) self.deferred.addBoth(lambda r: self.transport.loseConnection) def dataReceived(self, data): self.data += data def connectionLost(self, reason): self.forward(self.data) def forward(self, data): if self.deferred is not None: d, self.deferred = self.deferred, None d.callback(data) class TCPServerFactory(ServerFactory): protocol = TCPServerProtocol def __init__(self, service): self.service = service def runserver(ip, port): iface = {'home': '192.168.0.104', 'work': '127.0.0.1'} service = MyService() factory = TCPServerFactory(service) from twisted.internet import reactor reactor.listenTCP(port=port, factory=factory, interface=iface[ip]) reactor.run() if __name__ == '__main__': import sys ip = sys.argv[1] port = int(sys.argv[2]) runserver(ip, port) The following is test_service.py from twisted.internet.defer import Deferred from test_http_client import HTTPClientFactory class MyService(object): def __init__(self): self.deferred = Deferred() def s(self, data): kwargs = {} kwargs['url'] = b'http://127.0.0.1:8000/some/end/point' kwargs['url'] = kwargs['url'].encode('latin-1') kwargs['method'] = 'POST' kwargs['data'] = data client = HTTPClientFactory(**kwargs) d = client.deferred return d The following is test_http_client.py from StringIO import StringIO import json from twisted.internet.protocol import Protocol from twisted.internet.defer import Deferred from twisted.web.client import Agent, FileBodyProducer from twisted.web.http_headers import Headers class HTTPClientProtocol(Protocol): def __init__(self, finished): self.finished = finished self.data = '' def dataReceived(self, data): print '----------Data Received by HTTPClientProtocol----------' print data self.data += data def connectionLost(self, reason): print '----------HTTP Client connection Lost----------' print reason.getErrorMessage() if self.finished is not None: print 'finished is not None' f, self.finished = self.finished, None f.callback(self.data) class HTTPClientFactory(object): """ Class handling communication with HTTP server. """ def __init__(self, **kwargs): data = kwargs['data'] try: body = FileBodyProducer(StringIO(json.dumps(data))) print '----------Request body object created----------' except Exception as e: print '----------Request body object creation FAILURE----------' print e return e url = kwargs.get('url', None) method = kwargs.get('method', None) from twisted.internet import reactor agent = Agent(reactor) if not data: body = None self.deferred = agent.request(method, url, Headers({'Content-Type': ['application/json']}), bodyProducer=body) self.deferred.addCallback(self.get_response) def get_response(self, response): print 'Response received' finished = Deferred() response.deliverBody(HTTPClientProtocol(finished)) return finished From greg.ewing at canterbury.ac.nz Thu Nov 5 02:55:54 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 Nov 2015 20:55:54 +1300 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> Message-ID: Tim Chase wrote: > You get even crazier when you start adding zgrep/zegrep/zfgrep. It's fitting somehow that we should need an RE to describe all the possible names of the grep command. -- Greg From rosuav at gmail.com Thu Nov 5 03:00:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 19:00:13 +1100 Subject: =?UTF-8?B?UmU6IFdoYXQgZG9lcyDigJxncmVw4oCdIHN0YW5kIGZvcj8=?= In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On Thu, Nov 5, 2015 at 6:32 PM, Christian Gollwitzer wrote: > The point I'm so amused is, that MS has not felt the need to ship a real > editor, and also cut back on most of the other tools that make computing, > even on commandlines, a pleasant experience. Readline? Tab-Completion? I > read a magazine called "DOS", where they scripted the hell out of > .BAT-files. When they first showed an article about bash programming, I was > really jealous that the people on these strange, exotic OSes had such a > complete programming language at their disposal. Now I can't imagine giving > it back ever. I don't remember whether DOS 3.x had it, but we upgraded to MS-DOS 5.0 fairly early in my life, and that's most of what I remember. In that version, we had a thing called DOSKey, which gave you command history and some editing keys (not nearly as rich as readline, of course, but good enough for a lot of work); tab completion was an astonishing new feature when I first met a bash-derived shell. And yes, astonishing. I'd thought that GUIs had this advantage over command lines in that long file names (especially with spaces and such) didn't cost you anything, since you simply click to select; I somewhat resented them for it. And then, wow, tab completion! You type the beginning of the name and it fills in the rest! >> Fast forward a decade or two, and I'm working on a MUD server for a >> friend. It incorporates an editor that can be used on a dumb telnet >> connection - and it's line based again. So there's clearly some value >> here :) Visual editors get the lion's share of actual editing work, >> but in special circumstances, it is nice to have a quick little >> ed-like program around. > > In this case I'd copy the file to the local machine and sync it using rsync > or git. It's almost as terse in terms of bandwidth as the manual editing > commands, but a lot more comfortable. That server didn't allow rsync/git; I think they didn't use git, and rsync probably would have meant setting up duplicate Unix accounts for everyone that paralleled the permissions they had on the MUD itself. On my own server, I don't have any fine-grained permissions (either you're allowed to edit files, or you're not), so I have a much simpler system: you type "edit some_file_name" and it sends you the contents of the file in a way that makes the client pop up an editor. Hit Save in the editor, and it sends the file back. Pretty easy. But still, there _are_ good uses for a line-based editor, even if they are rare. ChrisA From rosuav at gmail.com Thu Nov 5 03:06:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Nov 2015 19:06:21 +1100 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> Message-ID: On Thu, Nov 5, 2015 at 6:55 PM, Gregory Ewing wrote: > Tim Chase wrote: > >> You get even crazier when you start adding zgrep/zegrep/zfgrep. > > > It's fitting somehow that we should need an RE > to describe all the possible names of the grep > command. Regex engine golf: Find the shortest regex that matches the names of all GNU commands which accept regular expressions, and no other commands! ChrisA From auriocus at gmx.de Thu Nov 5 03:18:58 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 5 Nov 2015 09:18:58 +0100 Subject: Regular expressions In-Reply-To: <2fd7d161-b1cb-4274-b8dc-0157916413f1@googlegroups.com> References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> <563abdda$0$1614$c3e8da3$5496439d@news.astraweb.com> <2fd7d161-b1cb-4274-b8dc-0157916413f1@googlegroups.com> Message-ID: Am 05.11.15 um 06:59 schrieb rurpy at yahoo.com: >> Can you call yourself a well-rounded programmer without at least a basic >> understanding of some regex library? Well, probably not. But that's part of >> the problem with regexes. They have, to some degree, driven out potentially >> better -- or at least differently bad -- pattern matching solutions, such >> as (E)BNF grammars, SNOBOL pattern matching, or lowly globbing patterns. Or >> even alternative idioms, like Hypercard's "chunking" idioms. > > Hmm, very good point. I wonder why all those "potentially better" > solutions have not been more widely adopted? A conspiracy by a > secret regex cabal? I'm mostly on the pro-side of the regex discussion, but this IS a valid point. regexes are not always a good way to express a pattern, even if the pattern is regular. The point is, that you can't build them up easily piece-by-piece. Say, you want a regex like "first an international phone number, then a name, then a second phone number" - you will have to *repeat* the pattern for phone number twice. In more complex cases this can become a nightmare, like the monster that was mentioned before to validate an email. A better alternative, then, is PEG for example. You can easily write pattern <- phone_number name phone_number phone_number <- '+' [0-9]+ ( '-' [0-9]+ )* name <- [[:alpha:]]+ or something similar using a PEG parser. It has almost the same quantifiers as a Regex, is much more readable, runs in linear time over all inputs and can parse languages with the approximately the same complexity as the Knuth style parsers (LR(k) etc.), but without ambiguity. I'm really astonished that PEG parsing is not better supported in the world of computing, instead most people choose to stick to the lexer+scanner combination Finally, an anecdote from my "early" life of computing. In 1990, when I was 12 years old, I participated in an annual competition of computer science for high school students. I was learning how to program without formal training, and solved one problem where a grammar was depicted as a flowchart and the task was to write parser for it, to check the validity of input strings. The grammar is depicted here (problem 1): http://www.auriocus.de/StringKurs/RegEx/uebungen1.pdf As a 12 year old, not knowing anything about pattern recognition, but thinking I was the king, as is usual for boys in that age, I sat down and manually constructed a recursive descent parser in a BASIC like language. It had 1000 lines and took me a few weeks to get it correct. Finally the solution was accepted as working, but my participation was rejected because the solutions lacked documentation. 16 years later I used the problem for a course on string processing (that's what the PDF is for), and asked the students to solve it using regexes. My own solution consists of 67 characters, and it took me5 minutes to write it down. Admittedly, this problem is constructed, but solving similar tasks by regexes is still something that I need to do on a daily basis, when I get data from other scientists in odd formats and I need to preprocess them. I know people who use a spreadsheet and copy/paste millions of datapoints manually becasue they lack the knowledge of using such tools. Christian From __peter__ at web.de Thu Nov 5 03:33:39 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Nov 2015 09:33:39 +0100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: > >> I tried Tim's example >> >> $ seq 5 | grep '1*' >> 1 >> 2 >> 3 >> 4 >> 5 >> $ > > I don't understand this. What on earth is grep matching? How does "4" > match "1*"? Look for zero or more "1". Written in Python: for line in sys.stdin: if re.compile("1*").search(line): print(line, end="") >> which surprised me because I remembered that there usually weren't any >> matching lines when I invoked grep instead of egrep by mistake. So I >> tried another one >> >> $ seq 5 | grep '[1-3]+' >> $ >> >> and then headed for the man page. Apparently there is a subset called >> "basic regular expressions": >> >> """ >> Basic vs Extended Regular Expressions >> In basic regular expressions the meta-characters ?, +, {, |, (, >> and ) lose their special meaning; instead use the backslashed >> versions \?, \+, \{, \|, \(, and \). >> """ > > None of this appears relevant, as the metacharacter * is not listed. That's the very point. > So what's going on? Most special characters are not working with grep, but * is. The quote explains why many regular expressions like "[1-3]+" that you may know from Python's re don't work, but a small subset including the ominous "1*" do. From antoon.pardon at rece.vub.ac.be Thu Nov 5 04:14:19 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 05 Nov 2015 10:14:19 +0100 Subject: Regular expressions In-Reply-To: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56398006$0$11100$c3e8da3@news.astraweb.com> <89a2a4a7-f483-4e94-9f68-ba77ce4b7598@googlegroups.com> <74351250-2c5b-439d-abc9-65e3480cd930@googlegroups.com> Message-ID: <563B1DEB.5000704@rece.vub.ac.be> Op 05-11-15 om 01:33 schreef Chris Angelico: > "I want to swim from Sydney to Los Angeles, but my gloves keep wearing > out half way across the Pacific. How can I make my gloves strong > enough to get me to LA?" > > Response 1: "If you use industrial-strength gloves and go via Papua > New Guinea, you can double up the gloves and swim to LA." > > Response 2: "Swimming across the Pacific is a bad idea. Have you > considered taking a boat or plane instead?" > > Which is the more helpful response? You can go ahead and assume the OP > always knows best; I'm going to at least offer some alternatives. What I see often enough doesn't look like offering an alternative but more like strong argumentation against the direction the OP is going. I have nothing against offering an alternative. There is the possibilty that there are better methods to solve the original problem and there is nothing wrong with suggesting this possibility. But there is also the possibility that the direction the OP is heading is the correct one, even if you can't see it. Take the original question on how to recognize a line that ends with a '*' with a regular expression. What almost noone seems to have considered is that the real problem might have been more involved and an excellent example of a problem you can solve with regular expressions but that there was this subproblem of recognizing a '*' at the end of the line that was troublesome for the OP. This is a possibility that is all too often ignored by the members on this list. We advise people here to just show to most bare code that still shows the problem, yet we ignore that this effects the part of the problem we get to see and often enough people then insist on a better alternative to deal with the problem totally ignoring that this better alternative may be totally useless in the original context. -- Antoon Pardon From input/ldompeling at casema.nl Thu Nov 5 04:22:14 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Thu, 05 Nov 2015 09:22:14 GMT Subject: raw_input and break References: <4270fade-5f09-4935-a99a-f2be344202b2@googlegroups.com> Message-ID: In reply to "tian.su.yale at gmail.com" who wrote the following: > =E5=9C=A8 2015=E5=B9=B411=E6=9C=884=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC= > -6=E4=B8=8B=E5=8D=883:45:09=EF=BC=8Cinput/ld... at casema.nl=E5=86=99=E9=81=93= > =EF=BC=9A > > I have an continues loop with "while True:" > > Now I want to use "raw_input" and when I press "s" on the keybord that it= > will=20 > > "break" the continues loop. In this script it always break even when I not press 's' I want that this script go's to if mindist > us_dist(15): And when I press 's' its stop. Any ideas ? -------------------------------------------------------- while True: enable_servo() servo(90) mindist = 80 choices = input("letter s to stop:") if choices == 's': print ("stop") break if mindist > us_dist(15): bwd() print ("backward 1x") > > =20 > > I tried: > > choices =3D raw_input > > if choises =3D=3D s: > > break > > =20 > > But even when I not press "s" it "break" > > I want that I not press "s" the script continues. > > =20 > > Any ideas ? > > =20 > > Thanks > > =20 > > =20 > > =20 > > --=20 > > --------------------------------- --- -- - > > Posted with NewsLeecher v7.0 Beta 2 > > Web @ http://www.newsleecher.com/?usenet > > ------------------- ----- ---- -- - > > while True: > inp =3D input("Enter whatever you want, letter 's' to stop: ") > if inp =3D=3D 's': > print("Program stopped.") > break > print("You just entered:", inp) > > Is this along the line that you are thinking? As pointed out earlier, it wi= > ll be much easier for people to help if you can share the exact code you pu= > t into and the error messages as well. Thanks and good luck! > All the best, > Tian -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From __peter__ at web.de Thu Nov 5 05:01:45 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Nov 2015 11:01:45 +0100 Subject: raw_input and break References: <4270fade-5f09-4935-a99a-f2be344202b2@googlegroups.com> Message-ID: input/ldompeling at casema.nl wrote: > while True: > enable_servo() > servo(90) > mindist = 80 > choices = input("letter s to stop:") > if choices == 's': > print ("stop") > break > if mindist > us_dist(15): > bwd() > print ("backward 1x") > In this script it always break even when I not press 's' > I want that this script go's to if mindist > us_dist(15): > And when I press 's' its stop. > > Any ideas ? Does it print something like Traceback (most recent call last): File "", line 1, in File "", line 0 ^ SyntaxError: unexpected EOF while parsing when it stops? This is called a "traceback" and you should always include it in your post when you need help with an error in your script. In this particular case the problem is that you are using Python 2 where input() tries to execute the text the user enters as Python code. Tian's example code assumes Python 3. To fix your problem replace the line choices = input("letter s to stop:") in your script with choices = raw_input("letter s to stop:") From input/ldompeling at casema.nl Thu Nov 5 05:40:23 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Thu, 05 Nov 2015 10:40:23 GMT Subject: raw_input and break References: Message-ID: In reply to "Peter Otten" who wrote the following: > input/ldompeling at casema.nl wrote: > > > while True: > > enable_servo() > > servo(90) > > mindist = 80 > > choices = input("letter s to stop:") > > if choices == 's': > > print ("stop") > > break > > if mindist > us_dist(15): >In this particular case the problem is that you are using Python 2 where >input() tries to execute the text the user enters as Python code. >Tian's example code assumes Python 3. >To fix your problem replace the line > choices = input("letter s to stop:") >in your script with > choices = raw_input("letter s to stop:") Oh no, this is not what I want. Now it is waiting for input when its go further with the script. Because I have an while True: so I want that the script go's continue only when I press a key then it must stop the script. Thanks -------------------------------------------------------------------------------------------------------------------------- > > bwd() > > print ("backward 1x") > > > In this script it always break even when I not press 's' > > I want that this script go's to if mindist > us_dist(15): > > And when I press 's' its stop. > > > > Any ideas ? > > Does it print something like > > Traceback (most recent call last): > File "", line 1, in > File "", line 0 > > ^ > SyntaxError: unexpected EOF while parsing > > when it stops? This is called a "traceback" and you should always include it > in your post when you need help with an error in your script. > > In this particular case the problem is that you are using Python 2 where > input() tries to execute the text the user enters as Python code. > > Tian's example code assumes Python 3. > > To fix your problem replace the line > > choices = input("letter s to stop:") > > in your script with > > choices = raw_input("letter s to stop:") -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From __peter__ at web.de Thu Nov 5 06:38:05 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Nov 2015 12:38:05 +0100 Subject: raw_input and break References: Message-ID: input/ldompeling at casema.nl wrote: > > choices = raw_input("letter s to stop:") > > Oh no, this is not what I want. Now it is waiting for input when its go > further with the script. Because I have an while True: so I want that the > script go's continue only when I press a key then it must stop the script. Solutions to that problem are OS-dependent. For Unix terminals https://docs.python.org/2/faq/library.html#how-do-i-get-a-single-keypress-at-a-time shows one way which I used to write the contextmanager below: $ cat capture_key.py import termios, fcntl, sys, os from contextlib import contextmanager @contextmanager def nonblocking(stdin=None): if stdin is None: stdin = sys.stdin fd = sys.stdin.fileno() oldterm = termios.tcgetattr(fd) newattr = termios.tcgetattr(fd) newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO termios.tcsetattr(fd, termios.TCSANOW, newattr) oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK) def read(n): try: return stdin.read(n) except IOError: return "" try: yield read finally: termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags) Put the capture_key.py module into the same folder as your script and use it like in the demo below: from capture_key import nonblocking # put your code here with nonblocking() as read: print("letter s to stop:") while True: enable_servo() servo(90) mindist = 80 choices = read(1) if choices == 's': print("stop") break if mindist > us_dist(15): bwd() print("backward 1x") From steve at pearwood.info Thu Nov 5 07:05:12 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 05 Nov 2015 23:05:12 +1100 Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <563b45fa$0$1593$c3e8da3$5496439d@news.astraweb.com> On Thu, 5 Nov 2015 07:33 pm, Peter Otten wrote: > Steven D'Aprano wrote: > >> On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: >> >>> I tried Tim's example >>> >>> $ seq 5 | grep '1*' >>> 1 >>> 2 >>> 3 >>> 4 >>> 5 >>> $ >> >> I don't understand this. What on earth is grep matching? How does "4" >> match "1*"? > > Look for zero or more "1". Doh! Oh the shame, I knew that. Somehow I tangled myself in a knot, thinking that it had to be 1 *followed by* zero or more characters. But of course it's not a glob, it's a regex. -- Steven From input/ldompeling at casema.nl Thu Nov 5 07:59:40 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Thu, 05 Nov 2015 12:59:40 GMT Subject: raw_input and break References: Message-ID: <0pI_x.14172$aq1.6942@fe58.am1> In reply to "Peter Otten" who wrote the following: > input/ldompeling at casema.nl wrote: > > > > choices = raw_input("letter s to stop:") > > > > Oh no, this is not what I want. Now it is waiting for input when its go > > further with the script. Because I have an while True: so I want that the > > script go's continue only when I press a key then it must stop the script. > > Solutions to that problem are OS-dependent. For Unix terminals > > https://docs.python.org/2/faq/ > library.html#how-do-i-get-a-single-keypress-at-a-time > > shows one way which I used to write the contextmanager below: > > $ cat capture_key.py > import termios, fcntl, sys, os > > from contextlib import contextmanager > > > @contextmanager > def nonblocking(stdin=None): > if stdin is None: > stdin = sys.stdin > > fd = sys.stdin.fileno() > > oldterm = termios.tcgetattr(fd) > newattr = termios.tcgetattr(fd) > newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO > termios.tcsetattr(fd, termios.TCSANOW, newattr) > > oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) Thanks for the reply. Is there no easy way to do so in python ? I am using the raspberry pi with Wheezy and for the robot the GoPiGo which is connected on the raspberry pi. The GoPiGo board has his own code like: fwd()="forward" bwd()="backward" right()="right" left="left" and so on. I am just a dummie with python. Thanks ---------------------------------------------------------- > fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK) > def read(n): > try: > return stdin.read(n) > except IOError: > return "" > try: > yield read > finally: > termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) > fcntl.fcntl(fd, fcntl.F_SETFL, oldflags) > > > Put the capture_key.py module into the same folder as your script and use it > like in the demo below: > > from capture_key import nonblocking > > # put your code here > > with nonblocking() as read: > print("letter s to stop:") > while True: > enable_servo() > servo(90) > mindist = 80 > choices = read(1) > if choices == 's': > print("stop") > break > if mindist > us_dist(15): > bwd() > print("backward 1x") -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From albert at spenarnc.xs4all.nl Thu Nov 5 08:39:52 2015 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 05 Nov 2015 13:39:52 GMT Subject: Regular expressions References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <563b5c28$0$23757$e4fe514c@news.xs4all.nl> Steven D'Aprano writes: >On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: >> I tried Tim's example >> >> $ seq 5 | grep '1*' >> 1 >> 2 >> 3 >> 4 >> 5 >> $ >I don't understand this. What on earth is grep matching? How does "4" >match "1*"? >> which surprised me because I remembered that there usually weren't any >> matching lines when I invoked grep instead of egrep by mistake. So I tried >> another one >> >> $ seq 5 | grep '[1-3]+' >> $ >> >> and then headed for the man page. Apparently there is a subset called >> "basic regular expressions": >> >> """ >> Basic vs Extended Regular Expressions >> In basic regular expressions the meta-characters ?, +, {, |, (, >> and ) lose their special meaning; instead use the backslashed >> versions \?, \+, \{, \|, \(, and \). >> """ >None of this appears relevant, as the metacharacter * is not listed. So >what's going on? * is so fundamental that it never looses it special meaning. Same for [ . * means zero more of the preceeding char. This makes + superfluous (a mere convenience) as [1-3]+ can be expressed as [1-3][1-3]* Note that [1-3]* matches the empty string. This happens a lot. Groetjes Albert >-- >Steven -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From python.list at tim.thechases.com Thu Nov 5 09:00:00 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 5 Nov 2015 08:00:00 -0600 Subject: Regular expressions In-Reply-To: <563b45fa$0$1593$c3e8da3$5496439d@news.astraweb.com> References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <563abee1$0$1614$c3e8da3$5496439d@news.astraweb.com> <563b45fa$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20151105080000.6da70056@bigbox.christie.dr> On 2015-11-05 23:05, Steven D'Aprano wrote: > Oh the shame, I knew that. Somehow I tangled myself in a knot, > thinking that it had to be 1 *followed by* zero or more characters. > But of course it's not a glob, it's a regex. But that's a good reminder of fnmatch/glob modules too. Sometimes all you need is to express a simple glob, in which case using a regexp can cloud the clarity. The overarching principle is to go for clarity & simplicity, rather than favoring built-ins/glob/regex/parser modules all the time. Want to test for presence in a string? Just use the builtin "a in b" test. At the beginning/end? Use .startswith()/.endswith() for clarity. Need to check if a string is purely digits/alpha/alphanumerics/etc? Use the string .is{alnum,alpha,decimal,digit,identifier,lower,numeric,printable,space,title,upper} methods on the string. For simple wild-carding, use the fnmatch module to do simple globbing. For more complex pattern matching, you've got regexps. Finally, for occasions when you're searching for repeated/nested structures, using an add-on module like pyparsing will give you clearer code. Oh, and with regexps, people should be less afraid of verbose multi-line strings with commenting r = re.compile(r""" ^ # start of the string (?P\d{4}) # capture 4 digits - # a literal dash (?P\d{1,2}) # capture 1-2 digits - # another literal dash (?P\d{1,2}) # capture 1-2 digits _ # a literal underscore (?P # capture the account-number [A-Z]{1,3} # 1-3 letters \d+ # followed by 1+ digits ) \.txt # the extension of the file (ignored) $ # the end of the string """, re.VERBOSE) They are a LOT easier to come back to if you haven't touched the code for a year. -tkc From mahanmarwat at gmail.com Thu Nov 5 09:01:51 2015 From: mahanmarwat at gmail.com (Mahan Marwat) Date: Thu, 5 Nov 2015 06:01:51 -0800 (PST) Subject: Python Hidden Code Message-ID: Repo `that` (Python Hidden Code) purpose is to collect all of the Python Easter Eggs, Idioms etc... in one place. If you have something to contribute, please send PR. Check it here: https://github.com/mahanmarwat/that From mahanmarwat at gmail.com Thu Nov 5 09:08:31 2015 From: mahanmarwat at gmail.com (Mahan Marwat) Date: Thu, 5 Nov 2015 06:08:31 -0800 (PST) Subject: =?UTF-8?B?U25ha2UgRXJyb3Ig8J+QjQ==?= Message-ID: <7c531168-539c-45ef-bb1d-bca713c383cc@googlegroups.com> When I am trying to paste this ? in Python 3.5.0 IDLE. It crashes. Found it on this page: http://www.fileformat.info/info/unicode/char/1f40d/index.htm Does Python have any problem with other snakes? From rosuav at gmail.com Thu Nov 5 09:15:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Nov 2015 01:15:53 +1100 Subject: Python Hidden Code In-Reply-To: References: Message-ID: On Fri, Nov 6, 2015 at 1:01 AM, Mahan Marwat wrote: > Repo `that` (Python Hidden Code) purpose is to collect all of the Python Easter Eggs, Idioms etc... in one place. > If you have something to contribute, please send PR. > Check it here: https://github.com/mahanmarwat/that Cool! I've sent you a few PRs with small clarifications. ChrisA From __peter__ at web.de Thu Nov 5 09:16:23 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Nov 2015 15:16:23 +0100 Subject: raw_input and break References: <0pI_x.14172$aq1.6942@fe58.am1> Message-ID: input/ldompeling at casema.nl wrote: > In reply to "Peter Otten" who wrote the following: > >> input/ldompeling at casema.nl wrote: >> >> > > choices = raw_input("letter s to stop:") >> > >> > Oh no, this is not what I want. Now it is waiting for input when its go >> > further with the script. Because I have an while True: so I want that >> > the script go's continue only when I press a key then it must stop the >> > script. >> >> Solutions to that problem are OS-dependent. For Unix terminals >> >> https://docs.python.org/2/faq/ >> library.html#how-do-i-get-a-single-keypress-at-a-time >> >> shows one way which I used to write the contextmanager below: >> >> $ cat capture_key.py >> import termios, fcntl, sys, os >> >> from contextlib import contextmanager >> >> >> @contextmanager >> def nonblocking(stdin=None): >> if stdin is None: >> stdin = sys.stdin >> >> fd = sys.stdin.fileno() >> >> oldterm = termios.tcgetattr(fd) >> newattr = termios.tcgetattr(fd) >> newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO >> termios.tcsetattr(fd, termios.TCSANOW, newattr) >> >> oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) > Thanks for the reply. Is there no easy way to do so in python ? If you are asking for a ready-made function in the standard library, I don't know one and I don't think there is one (there are recipes that work on top of curses though). > I am using the raspberry pi with Wheezy and for the robot the GoPiGo which > is connected on the raspberry pi. The GoPiGo board has his own code like: > fwd()="forward" bwd()="backward" right()="right" left="left" and so on. I > am just a dummie with python. The code in capture_key.py may look a bit scary, but just as I took it without bothering the details you can take the resulting module without caring about the code in it. Alternatively you can search https://pypi.python.org for a solution that you prefer. From rosuav at gmail.com Thu Nov 5 09:18:23 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Nov 2015 01:18:23 +1100 Subject: =?UTF-8?B?UmU6IFNuYWtlIEVycm9yIPCfkI0=?= In-Reply-To: <7c531168-539c-45ef-bb1d-bca713c383cc@googlegroups.com> References: <7c531168-539c-45ef-bb1d-bca713c383cc@googlegroups.com> Message-ID: On Fri, Nov 6, 2015 at 1:08 AM, Mahan Marwat wrote: > When I am trying to paste this ? in Python 3.5.0 IDLE. It crashes. > Found it on this page: http://www.fileformat.info/info/unicode/char/1f40d/index.htm > Does Python have any problem with other snakes? Was this on Windows? The Windows builds of Tk have a problem with astral characters, so you may not be able to use them there. Try it on Linux, or try using a character with a four-digit codepoint. Other GUI toolkits may do better (I've used Gtk on Windows with astral characters, though not from Python), and it should be fine on any modern Linux system. ChrisA From mahanmarwat at gmail.com Thu Nov 5 09:31:29 2015 From: mahanmarwat at gmail.com (Mahan Marwat) Date: Thu, 5 Nov 2015 06:31:29 -0800 (PST) Subject: =?UTF-8?B?UmU6IFNuYWtlIEVycm9yIPCfkI0=?= In-Reply-To: References: <7c531168-539c-45ef-bb1d-bca713c383cc@googlegroups.com> Message-ID: <16d52451-d661-48c3-b03a-b2e013d9d01c@googlegroups.com> > Was this on Windows? Yeh, Window 10. From input/ldompeling at casema.nl Thu Nov 5 09:34:27 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Thu, 05 Nov 2015 14:34:27 GMT Subject: raw_input and break References: Message-ID: >The code in capture_key.py may look a bit scary, but just as I took it >without bothering the details you can take the resulting module without >caring about the code in it. Alternatively you can search >https://pypi.python.org Thanks for the link. I realy appreciate it. Can you also tell me what I am looking for in https://pypi.python.org for a result. Thanks In reply to "Peter Otten" who wrote the following: > input/ldompeling at casema.nl wrote: > > > In reply to "Peter Otten" who wrote the following: > > > > > input/ldompeling at casema.nl wrote: > > > > > > > > choices = raw_input("letter s to stop:") > > > > > > > > Oh no, this is not what I want. Now it is waiting for input when its go > > > > further with the script. Because I have an while True: so I want that > > > > the script go's continue only when I press a key then it must stop the > > > > script. > > > > > > Solutions to that problem are OS-dependent. For Unix terminals > > > > > > https://docs.python.org/2/faq/ > > > library.html#how-do-i-get-a-single-keypress-at-a-time > > > > > > shows one way which I used to write the contextmanager below: > > > > > > $ cat capture_key.py > > > import termios, fcntl, sys, os > > > > > > from contextlib import contextmanager > > > > > > @contextmanager > > > def nonblocking(stdin=None): > > > if stdin is None: > > > stdin = sys.stdin > > > > > > fd = sys.stdin.fileno() > > > > > > oldterm = termios.tcgetattr(fd) > > > newattr = termios.tcgetattr(fd) > > > newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO > > > termios.tcsetattr(fd, termios.TCSANOW, newattr) > > > > > > oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) > > Thanks for the reply. Is there no easy way to do so in python ? > > If you are asking for a ready-made function in the standard library, I don't > know one and I don't think there is one (there are recipes that work on top > of curses though). > > > I am using the raspberry pi with Wheezy and for the robot the GoPiGo which > > is connected on the raspberry pi. The GoPiGo board has his own code like: > > fwd()="forward" bwd()="backward" right()="right" left="left" and so on. I > > am just a dummie with python. > > The code in capture_key.py may look a bit scary, but just as I took it > without bothering the details you can take the resulting module without > caring about the code in it. Alternatively you can search > > https://pypi.python.org > > for a solution that you prefer. -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From Seymore4Head at Hotmail.invalid Thu Nov 5 10:07:06 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Thu, 05 Nov 2015 10:07:06 -0500 Subject: Regular expressions References: <56398006$0$11100$c3e8da3@news.astraweb.com> <1i3l3b9836hatsuoopak5gtg2c38g49kb1@4ax.com> <563aa8be$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 05 Nov 2015 11:54:20 +1100, Steven D'Aprano wrote: >On Thu, 5 Nov 2015 10:02 am, Seymore4Head wrote: > >> So far the only use I have for regex is to replace slicing, but I >> think it is an improvement. > >I don't understand this. This is like saying "so far the only use I have for >a sandwich press is to replace my coffee pot". Regular expressions and >slicing do very different things. > >Slicing extracts substrings, given known starting and ending positions: > > >py> the_str = "Now is the time for all good men..." >py> the_str[7:12] >'the t' > > >Regular expressions don't extract substrings with known start/end positions. >They *find* matching text, giving a search string with metacharacters. (If >there are no metacharacters in your search string, you shouldn't use a >regex. str.find will be significantly faster and more convenient.) > >Slicing is not about finding text, it is about extracting text once you've >already found it. So they are complementary, not alternatives. Here is an example of the text we are slicing apart. >From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 Return-Path: Received: from murder (mail.umich.edu [141.211.14.90]) by frankenstein.mail.umich.edu (Cyrus v2.3.8) with LMTPA; Sat, 05 Jan 2008 09:14:16 -0500 X-Sieve: CMU Sieve 2.3 Received: from murder ([unix socket]) by mail.umich.edu (Cyrus v2.2.12) with LMTPA; Sat, 05 Jan 2008 09:14:16 -0500 Received: from holes.mr.itd.umich.edu (holes.mr.itd.umich.edu [141.211.14.79]) by flawless.mail.umich.edu () with ESMTP id m05EEFR1013674; Sat, 5 Jan 2008 09:14:15 -0500 Received: FROM paploo.uhi.ac.uk (app1.prod.collab.uhi.ac.uk [194.35.219.184]) BY holes.mr.itd.umich.edu ID 477F90B0.2DB2F.12494 ; 5 Jan 2008 09:14:10 -0500 Received: from paploo.uhi.ac.uk (localhost [127.0.0.1]) by paploo.uhi.ac.uk (Postfix) with ESMTP id 5F919BC2F2; Sat, 5 Jan 2008 14:10:05 +0000 (GMT) Message-ID: <200801051412.m05ECIaH010327 at nakamura.uits.iupui.edu> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Received: from prod.collab.uhi.ac.uk ([194.35.219.182]) by paploo.uhi.ac.uk (JAMES SMTP Server 2.1.3) with SMTP ID 899 for ; Sat, 5 Jan 2008 14:09:50 +0000 (GMT) Received: from nakamura.uits.iupui.edu (nakamura.uits.iupui.edu [134.68.220.122]) by shmi.uhi.ac.uk (Postfix) with ESMTP id A215243002 for ; Sat, 5 Jan 2008 14:13:33 +0000 (GMT) Received: from nakamura.uits.iupui.edu (localhost [127.0.0.1]) by nakamura.uits.iupui.edu (8.12.11.20060308/8.12.11) with ESMTP id m05ECJVp010329 for ; Sat, 5 Jan 2008 09:12:19 -0500 Received: (from apache at localhost) by nakamura.uits.iupui.edu (8.12.11.20060308/8.12.11/Submit) id m05ECIaH010327 for source at collab.sakaiproject.org; Sat, 5 Jan 2008 09:12:18 -0500 Date: Sat, 5 Jan 2008 09:12:18 -0500 X-Authentication-Warning: nakamura.uits.iupui.edu: apache set sender to stephen.marquard at uct.ac.za using -f To: source at collab.sakaiproject.org From: stephen.marquard at uct.ac.za The practice problems are something like pull out all the email addresses or pull out the days of the week and give the most common. From random832 at fastmail.com Thu Nov 5 10:19:05 2015 From: random832 at fastmail.com (Random832) Date: Thu, 05 Nov 2015 10:19:05 -0500 Subject: What does =?utf-8?B?4oCcZ3JlcOKAnQ==?= stand for? References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: <87pozotqxi.fsf@fastmail.com> Chris Angelico writes: > As someone who grew up on MS-DOS, I'd like to mention that EDLIN's > value wasn't in the obvious places. There were two features it had > that most other editors didn't: firstly, it would read only as much of > the file as it needed, so you could edit a file larger than available > memory; and secondly, all commands came from stdin, which could be > redirected - making it a poor man's 'sed'. Using EDLIN for regular > file editing was never the normal thing. Of course, both of those things are also true of ed. And I found it a bit interesting that use in scripts was mentioned as a contrast between sed and ed, when the original way patches were distributed (and diff still has an option to generate these) was as ed scripts. From olivier.adret02 at gmail.com Thu Nov 5 10:24:38 2015 From: olivier.adret02 at gmail.com (olivier) Date: Thu, 5 Nov 2015 16:24:38 +0100 Subject: Olivier Adret Message-ID: <563B74B6.80402@gmail.com> Je vais essayer de programmer en python. On verra bien ! From robin at reportlab.com Thu Nov 5 11:56:19 2015 From: robin at reportlab.com (Robin Becker) Date: Thu, 5 Nov 2015 16:56:19 +0000 Subject: llewellynBH@gmail.com Message-ID: <563B8A33.2010305@chamonix.reportlab.co.uk> Hi, did you find your phone? -- Robin Becker From __peter__ at web.de Thu Nov 5 12:06:31 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Nov 2015 18:06:31 +0100 Subject: raw_input and break References: Message-ID: input/ldompeling at casema.nl wrote: >>The code in capture_key.py may look a bit scary, but just as I took it >>without bothering the details you can take the resulting module without >>caring about the code in it. Alternatively you can search > >>https://pypi.python.org > > Thanks for the link. I realy appreciate it. > Can you also tell me what I am looking for in https://pypi.python.org for > a result. I didn't have a particular module in mind. Pypy, or the "Python Package Index", is a repository for all kinds of modules and libraries. If you don't yet feel comfortable looking around (peferrably using the search engine of your choice) and experimenting a bit I recommend that you try the piece of code I posted (or wait for someone else to chime in with a better suggestion). From __peter__ at web.de Thu Nov 5 12:15:12 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Nov 2015 18:15:12 +0100 Subject: llewellynBH@gmail.com References: <563B8A33.2010305@chamonix.reportlab.co.uk> Message-ID: Robin Becker wrote: > Hi, > > did you find your phone? If not -- it's probably on comp.lang.perl.misc Glad to be of help ;) From input/ldompeling at casema.nl Thu Nov 5 12:28:36 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Thu, 05 Nov 2015 17:28:36 GMT Subject: raw_input and break References: Message-ID: <8lM_x.24516$cf7.4240@fx02.am1> Oke, lets try your code.Can you help me with that. This is my code: ------------------------------------------------- from gopigo import * import time set_right_speed(150) set_left_speed(105) enable_servo() fwd() print("forward 1x") time.sleep(4) stop() while True: servo(90) mindist = 80 if mindist > us_dist(15): bwd() print ("backward 1x") time.sleep(2) stop() right() time.sleep(1) stop() print("right 1x") time.sleep(2) stop() fwd() print("forward 2x") time.sleep(3) stop() left() time.sleep(1) print("left 1x") stop() fwd() print("forward 3x") time.sleep(2) stop() ------------------------------------------------------ In reply to "Peter Otten" who wrote the following: > input/ldompeling at casema.nl wrote: > > > > The code in capture_key.py may look a bit scary, but just as I took it > > > without bothering the details you can take the resulting module without > > > caring about the code in it. Alternatively you can search > > > > > https://pypi.python.org > > > > Thanks for the link. I realy appreciate it. > > Can you also tell me what I am looking for in https://pypi.python.org for > > a result. > > I didn't have a particular module in mind. Pypy, or the "Python Package > Index", is a repository for all kinds of modules and libraries. If you don't > yet feel comfortable looking around (peferrably using the search engine of > your choice) and experimenting a bit I recommend that you try the piece of > code I posted (or wait for someone else to chime in with a better > suggestion). -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From mdaglow at daglowconsulting.com Thu Nov 5 12:39:26 2015 From: mdaglow at daglowconsulting.com (Marta Daglow) Date: Thu, 5 Nov 2015 09:39:26 -0800 Subject: Top Engineers Message-ID: <883ad76fb70512dfaec55696045dfe5f@mail.gmail.com> Hi, I'm working closely with co-founders of a top startup in SoMa. We are in the client services space and have created innovative solutions in optimizing the first time user experience for small through large enterprise companies. We already have a strong client list of household names. We are looking for smart and amazing engineers who are creative thinkers, fascinated by mobile technology, enjoy working in teams of smart and accomplished people, and are meticulous in coding. We would consider some remote work. Whether you are right out of college or have lots of engineering experience we'd like to talk with you. Pay from $80K - $240K (plus stock with a co that has not needed VC funds to get started). Top leaders. Top culture. Career defining role. Please email me at mdaglow at daglowconsulting.com to set up a time to talk. From robin at reportlab.com Thu Nov 5 12:56:20 2015 From: robin at reportlab.com (Robin Becker) Date: Thu, 5 Nov 2015 17:56:20 +0000 Subject: llewellynBH@gmail.com In-Reply-To: References: <563B8A33.2010305@chamonix.reportlab.co.uk> Message-ID: <563B9844.4040601@chamonix.reportlab.co.uk> On 05/11/2015 17:15, Peter Otten wrote: > Robin Becker wrote: > >> Hi, >> >> did you find your phone? > > If not -- it's probably on comp.lang.perl.misc > > Glad to be of help ;) > weird no idea why this ended up here; thunderbird is a bit strange today -mis-guidedly yrs- Robin Becker From robin at reportlab.com Thu Nov 5 12:56:20 2015 From: robin at reportlab.com (Robin Becker) Date: Thu, 5 Nov 2015 17:56:20 +0000 Subject: llewellynBH@gmail.com In-Reply-To: References: <563B8A33.2010305@chamonix.reportlab.co.uk> Message-ID: <563B9844.4040601@chamonix.reportlab.co.uk> On 05/11/2015 17:15, Peter Otten wrote: > Robin Becker wrote: > >> Hi, >> >> did you find your phone? > > If not -- it's probably on comp.lang.perl.misc > > Glad to be of help ;) > weird no idea why this ended up here; thunderbird is a bit strange today -mis-guidedly yrs- Robin Becker From lac at openend.se Thu Nov 5 13:02:49 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 05 Nov 2015 19:02:49 +0100 Subject: Top Engineers In-Reply-To: <883ad76fb70512dfaec55696045dfe5f@mail.gmail.com> References: <883ad76fb70512dfaec55696045dfe5f@mail.gmail.com> Message-ID: <201511051802.tA5I2nC2002323@fido.openend.se> In a message of Thu, 05 Nov 2015 09:39:26 -0800, Marta Daglow writes: It is extremely unprofessional to spam an international mailing list with a large readership with such things. And very parochial -- do you have any idea how many neighbourhoods there are in the world that get called 'SoMa', precisely because they are South of some large Street whose name begins with 'Ma'? If you are trying to find people, we have a jobs board for that. https://www.python.org/jobs/ Use it. Stop damaging your reputation by posting things here. Laura Creighton From invalid at invalid.invalid Thu Nov 5 13:29:50 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 Nov 2015 18:29:50 +0000 (UTC) Subject: What does =?UTF-8?Q?=E2=80=9Cgrep=E2=80=9D?= stand for? References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 2015-11-05, Random832 wrote: > Chris Angelico writes: >> As someone who grew up on MS-DOS, I'd like to mention that EDLIN's >> value wasn't in the obvious places. There were two features it had >> that most other editors didn't: firstly, it would read only as much >> of the file as it needed, so you could edit a file larger than >> available memory; and secondly, all commands came from stdin, which >> could be redirected - making it a poor man's 'sed'. Using EDLIN for >> regular file editing was never the normal thing. > > Of course, both of those things are also true of ed. Well, maybe not for you. I knew people who (yonks ago) used 'ed' for regular file editing. And I remember using the VMS line-editor for regular file editing for a couple years before before a full-screen editor was available. -- Grant Edwards grant.b.edwards Yow! I always have fun at because I'm out of my gmail.com mind!!! From random832 at fastmail.com Thu Nov 5 14:56:14 2015 From: random832 at fastmail.com (Random832) Date: Thu, 05 Nov 2015 14:56:14 -0500 Subject: What does =?utf-8?B?4oCcZ3JlcOKAnQ==?= stand for? References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: <87oaf8fcf5.fsf@fastmail.com> Grant Edwards writes: > On 2015-11-05, Random832 wrote: >> Of course, both of those things are also true of ed. > > Well, maybe not for you. I knew people who (yonks ago) used 'ed' for > regular file editing. And I remember using the VMS line-editor for > regular file editing for a couple years before before a full-screen > editor was available. Er, I think my quoting was unclear. I meant the two features he mentioned (not loading the whole file in memory, and accepting commands from a redirected input file) applied. Of course, AIUI ed had always _also_ been used for scripts. But I never meant to imply that it wasn't used as an interactive editor, at least before vi came around. From auriocus at gmx.de Thu Nov 5 15:02:15 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 5 Nov 2015 21:02:15 +0100 Subject: =?UTF-8?Q?Re:_Snake_Error_=f0=9f=90=8d?= In-Reply-To: References: <7c531168-539c-45ef-bb1d-bca713c383cc@googlegroups.com> Message-ID: Am 05.11.15 um 15:18 schrieb Chris Angelico: > On Fri, Nov 6, 2015 at 1:08 AM, Mahan Marwat wrote: >> When I am trying to paste this ? in Python 3.5.0 IDLE. It crashes. >> Found it on this page: http://www.fileformat.info/info/unicode/char/1f40d/index.htm >> Does Python have any problem with other snakes? > > Was this on Windows? The Windows builds of Tk have a problem with > astral characters, so you may not be able to use them there. Try it on > Linux Tk does only handle BMP characters. It's a restriction deep inside the codebase of Tcl 8, which will be lifted only in (the future) Tcl 9. Howver, it should not crash, rather paste a U+FFFD character. X-Post to comp.lang.tcl. Can you check the Tk version you use? Try: import tkinter tkinter.Tk().eval("info patchlevel") Christian From invalid at invalid.invalid Thu Nov 5 15:19:39 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 Nov 2015 20:19:39 +0000 (UTC) Subject: What does =?UTF-8?Q?=E2=80=9Cgrep=E2=80=9D?= stand for? References: <662g3blobme52hfoududj27err185v2npm@4ax.com> <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 2015-11-05, Random832 wrote: > Grant Edwards writes: >> On 2015-11-05, Random832 wrote: >>> Of course, both of those things are also true of ed. >> >> Well, maybe not for you. I knew people who (yonks ago) used 'ed' for >> regular file editing. And I remember using the VMS line-editor for >> regular file editing for a couple years before before a full-screen >> editor was available. > > Er, I think my quoting was unclear. I think it was more a case of my reading being unclear. It's pretty clear upon re-reading what you wrote that you didn't mean that nobody used 'ed' for regular file editing. Though I used a line-editor for a while on VMS, I was never very good at it, and abanded it for a full-screen editor at he first opportunity. But, if you ever get a chance to watching somebody who _is_ good at 'ed', it's something you'll remember... -- Grant Edwards grant.b.edwards Yow! I want a VEGETARIAN at BURRITO to go ... with gmail.com EXTRA MSG!! From RobinsW1 at sutterhealth.org Thu Nov 5 15:48:11 2015 From: RobinsW1 at sutterhealth.org (Robinson, Wendy) Date: Thu, 5 Nov 2015 12:48:11 -0800 Subject: Puzzled In-Reply-To: <201511011020.tA1AKYAM004182@fido.openend.se> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> Message-ID: <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> Well... I still can't get this to work. I guess I'll just uninstall it. It's a bummer that there's no help on basic startup like this. Wendy Robinson Audit Analyst (916)?566-4994 phone NOTICE OF CONFIDENTIALITY: This email is for the sole use of the intended recipient and may contain material that is confidential and protected by state and federal regulations.? If you are not the intended recipient please immediately delete it and contact the sender. -----Original Message----- From: Laura Creighton [mailto:lac at openend.se] Sent: Sunday, November 01, 2015 2:21 AM To: Robinson, Wendy Cc: 'python-list at python.org'; lac at openend.se Subject: Re: Puzzled In a message of Fri, 30 Oct 2015 09:20:23 -0700, "Robinson, Wendy" writes: >Hi there, >I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic programs successfully. >This morning I rebooted my computer and can't get a single one to work. The interpreter seems to be fine and the environment variables look correct. But every py file I try to run at the >>> prompt gives me a NameError. > >I tried running the Repair installation, but that did not help. > >Any suggestions? > >Thank you > >Wendy Robinson >Audit Analyst >(916) 566-4994 phone Paste in the Full traceback you get from the console. Also check and see that the console is actually running the 3.5 you installed, and not some other python, like 2.7 you might have lying around. Laura From breamoreboy at yahoo.co.uk Thu Nov 5 16:52:24 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 5 Nov 2015 21:52:24 +0000 Subject: llewellynBH@gmail.com In-Reply-To: <563B8A33.2010305@chamonix.reportlab.co.uk> References: <563B8A33.2010305@chamonix.reportlab.co.uk> Message-ID: On 05/11/2015 16:56, Robin Becker wrote: > Hi, > > did you find your phone? Same answer as to the question "Is Vic there?", no :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Thu Nov 5 18:10:45 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 06 Nov 2015 00:10:45 +0100 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> Message-ID: <201511052310.tA5NAjAk026602@fido.openend.se> In a message of Thu, 05 Nov 2015 12:48:11 -0800, "Robinson, Wendy" writes: >Well... I still can't get this to work. I guess I'll just uninstall it. >It's a bummer that there's no help on basic startup like this. > >Wendy Robinson >Audit Analyst >(916)?566-4994 phone There is enormous amount of help available. But we need to know more about what your problem is, and how it presents itself before we can start tracking down what your problem is, which is why I wanted a traceback. >>Hi there, >>I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic programs successfully. >>This morning I rebooted my computer and can't get a single one to work. The interpreter seems to be fine and the environment variables look correct. But every py file I try to run at the >>> prompt gives me a NameError. See, this is where your problem is. There is a conceptual problem in understanding what you meant by 'tried some basic programs successfully' versus 'running py files at the >>> prompt'. Either you didn't use the Python console -- the thing that is showing you the '>>>' yesterday, and thus the programs that were working yesterday are now working every bit as well as they did then, and your problem is that you do not know how to use the python console. Or you did use the console before, and they worked there, and now you have NameErrors. I think the problem is the first sort. I think that you opened up the python console and then typed in something like 'myprogram.py' expecting the console to run the myprogram. Instead you got something like this: Python 3.5.0rc1 (default, Aug 12 2015, 14:57:46) [GCC 5.2.1 20150808] on linux Type "help", "copyright", "credits" or "license" for more information. >>> myprogram.py Traceback (most recent call last): File "", line 1, in NameError: name 'myprogram' is not defined >>> If this is what happened then your python is fine. You just do not know how the interactive console works. It doesn't run files like this. See:https://docs.python.org/3.5/tutorial/introduction.html You type code at the console and get responses back. If, on the other hand, this is not your problem, then we need a traceback --- and what I posted above was a traceback -- so that we can see what caused the NameError. Laura From RobinsW1 at sutterhealth.org Thu Nov 5 19:04:35 2015 From: RobinsW1 at sutterhealth.org (Robinson, Wendy) Date: Thu, 5 Nov 2015 16:04:35 -0800 Subject: Puzzled In-Reply-To: <201511052310.tA5NAjAk026602@fido.openend.se> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> <201511052310.tA5NAjAk026602@fido.openend.se> Message-ID: <4CFEDC132D44AC49BA0E91FBEB947119084A8D60B8@DCBL123VX.root.sutterhealth.org> Hmmm... fair enough. I sent the traceback though, on Monday. I'll give the intro a read again. I've probably missed something basic. Wendy Robinson Audit Analyst (916)?566-4994 phone NOTICE OF CONFIDENTIALITY: This email is for the sole use of the intended recipient and may contain material that is confidential and protected by state and federal regulations.? If you are not the intended recipient please immediately delete it and contact the sender. -----Original Message----- From: Laura Creighton [mailto:lac at openend.se] Sent: Thursday, November 05, 2015 3:11 PM To: Robinson, Wendy Cc: 'Laura Creighton'; 'python-list at python.org'; lac at openend.se Subject: Re: Puzzled In a message of Thu, 05 Nov 2015 12:48:11 -0800, "Robinson, Wendy" writes: >Well... I still can't get this to work. I guess I'll just uninstall it. >It's a bummer that there's no help on basic startup like this. > >Wendy Robinson >Audit Analyst >(916)?566-4994 phone There is enormous amount of help available. But we need to know more about what your problem is, and how it presents itself before we can start tracking down what your problem is, which is why I wanted a traceback. >>Hi there, >>I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic programs successfully. >>This morning I rebooted my computer and can't get a single one to work. The interpreter seems to be fine and the environment variables look correct. But every py file I try to run at the >>> prompt gives me a NameError. See, this is where your problem is. There is a conceptual problem in understanding what you meant by 'tried some basic programs successfully' versus 'running py files at the >>> prompt'. Either you didn't use the Python console -- the thing that is showing you the '>>>' yesterday, and thus the programs that were working yesterday are now working every bit as well as they did then, and your problem is that you do not know how to use the python console. Or you did use the console before, and they worked there, and now you have NameErrors. I think the problem is the first sort. I think that you opened up the python console and then typed in something like 'myprogram.py' expecting the console to run the myprogram. Instead you got something like this: Python 3.5.0rc1 (default, Aug 12 2015, 14:57:46) [GCC 5.2.1 20150808] on linux Type "help", "copyright", "credits" or "license" for more information. >>> myprogram.py Traceback (most recent call last): File "", line 1, in NameError: name 'myprogram' is not defined >>> If this is what happened then your python is fine. You just do not know how the interactive console works. It doesn't run files like this. See:https://docs.python.org/3.5/tutorial/introduction.html You type code at the console and get responses back. If, on the other hand, this is not your problem, then we need a traceback --- and what I posted above was a traceback -- so that we can see what caused the NameError. Laura From torriem at gmail.com Thu Nov 5 20:35:33 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 05 Nov 2015 18:35:33 -0700 Subject: Puzzled In-Reply-To: <201511052310.tA5NAjAk026602@fido.openend.se> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> <201511052310.tA5NAjAk026602@fido.openend.se> Message-ID: <563C03E5.3010608@gmail.com> On 11/05/2015 04:10 PM, Laura Creighton wrote: > In a message of Thu, 05 Nov 2015 12:48:11 -0800, "Robinson, Wendy" writes: >> Well... I still can't get this to work. I guess I'll just uninstall it. >> It's a bummer that there's no help on basic startup like this. >> >> Wendy Robinson >> Audit Analyst >> (916) 566-4994 phone > > There is enormous amount of help available. But we need to know more > about what your problem is, and how it presents itself before we can > start tracking down what your problem is, which is why I wanted a > traceback. Indeed there was quite a lot of help given to her on this list but she didn't reply to any of those suggestions. Pretty discouraging to those who want to help out. From wangq at travelsky.com Thu Nov 5 21:33:58 2015 From: wangq at travelsky.com (wangq at travelsky.com) Date: Fri, 6 Nov 2015 10:33:58 +0800 Subject: Question about math.pi is mutable Message-ID: <201511061033583772468@travelsky.com> Hello, python-list guys: I am a newbie of python from Beijing. China. I have a question about "math.pi". As you can see in the attachment, why i can modify "math.pi"? (in "mathmodule.c" "pi" is a "static const double") Thank you in advance! Best Wishes? From tjreedy at udel.edu Thu Nov 5 22:18:34 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 5 Nov 2015 22:18:34 -0500 Subject: =?UTF-8?Q?Re:_Snake_Error_=f0=9f=90=8d?= In-Reply-To: <7c531168-539c-45ef-bb1d-bca713c383cc@googlegroups.com> References: <7c531168-539c-45ef-bb1d-bca713c383cc@googlegroups.com> Message-ID: On 11/5/2015 9:08 AM, Mahan Marwat wrote: > When I am trying to paste this ? in Python 3.5.0 IDLE. It crashes. https://bugs.python.org/issue13153 If you run 'python -m idlelib' from command line, you will see a traceback. -- Terry Jan Reedy From orgnut at yahoo.com Thu Nov 5 22:36:11 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 5 Nov 2015 19:36:11 -0800 Subject: =?UTF-8?B?UmU6IFdoYXQgZG9lcyDigJxncmVw4oCdIHN0YW5kIGZvcj8=?= In-Reply-To: References: <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 11/05/2015 05:18 PM, Dennis Lee Bieber wrote: > On Thu, 5 Nov 2015 20:19:39 +0000 (UTC), Grant Edwards > declaimed the following: > >> Though I used a line-editor for a while on VMS, I was never very good >> at it, and abanded it for a full-screen editor at he first >> opportunity. But, if you ever get a chance to watching somebody who >> _is_ good at 'ed', it's something you'll remember... > > I didn't convert to EDT until DEC dropped SOS... And then shortly later > I keymapped the Blaise ([Alcor] Pascal) editor on the TRS-80 Mod-III to > replicate EDT (as much as possible, given only three function keys on the > numeric pad) > > The Amiga used to have two standard editors -- a screen editor and a > line editor; as I recall the line editor supported a file window, so one > could edit large files by making a single direction pass using a smaller > window and a script. Later the screen editor gained ARexx support, so one > could script it using ARexx. (And by then they also included a form of > microEMACS, my C compiler had a look-alike vi editor... and a later C > compiler had another editor integrated to the compiler so that error > message reports could trigger the editor to open the file and move to the > error position) > Anyone besides me remember the CP/M editor Mince (Mince Is Not Complete EMACS)? It was an emacs-like editor, without any e-Lisp or other way of extending it. I believe it was my first exposure to a screen-oriented editor. I quite liked it at that time (but that was a looonnng time ago!) -=- Larry -=- From abhishek.mallela at gmail.com Thu Nov 5 22:54:01 2015 From: abhishek.mallela at gmail.com (Abhishek) Date: Thu, 5 Nov 2015 19:54:01 -0800 (PST) Subject: RuntimeError: The size of the array returned by func does not match the size of y0 Message-ID: <3ef62cda-560c-4eb9-87f0-f91a3f4d653b@googlegroups.com> I have recently switched from programming heavily in MATLAB to programming in Python. Hence I am having some issues running the Python code that I have written. I am using IPython with Anaconda2 on Windows 7 and using numPy and SciPy to integrate a system of ordinary differential equations. I have generalized the system of ODEs for any number 'N' of them. I have two versions of code that do the same thing, and give the same error message. One version uses 'exec' and 'eval' heavily, and the other uses arrays heavily. Here is my code for the array version: ---------------------------------------------------------------------- import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint #Constants and parameters N = 2 K00 = np.logspace(0,3,101,10) len1 = len(K00) epsilon = 0.01 y0 = [0]*(3*N/2+3) u1 = 0 u2 = 0 u3 = 0 Kplot = np.zeros((len1,1)) Pplot = np.zeros((len1,1)) S = [np.zeros((len1,1)) for kkkk in range(N/2+1)] KS = [np.zeros((len1,1)) for kkkk in range(N/2+1)] PS = [np.zeros((len1,1)) for kkkk in range(N/2+1)] Splot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] KSplot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] PSplot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] for series in range(0,len1): K0 = K00[series] Q = 10 r1 = 0.0001 r2 = 0.001 a = 0.001 d = 0.001 k = 0.999 S10 = 1e5 P0 = 1 tfvec = np.tile(1e10,(1,5)) tf = tfvec[0,0] time = np.linspace(0,tf,len1) #Defining dy/dt's def f(y,t): for alpha in range(0,(N/2+1)): S[alpha] = y[alpha] for beta in range((N/2)+1,N+1): KS[beta-N/2-1] = y[beta] for gamma in range(N+1,3*N/2+1): PS[gamma-N] = y[gamma] K = y[3*N/2+1] P = y[3*N/2+2] # The model equations ydot = np.zeros((3*N/2+3,1)) B = range((N/2)+1,N+1) G = range(N+1,3*N/2+1) runsumPS = 0 runsum1 = 0 runsumKS = 0 runsum2 = 0 for m in range(0,N/2): runsumPS = runsumPS + PS[m+1] runsum1 = runsum1 + S[m+1] runsumKS = runsumKS + KS[m] runsum2 = runsum2 + S[m] ydot[B[m]] = a*K*S[m]-(d+k+r1)*KS[m] for i in range(0,N/2-1): ydot[G[i]] = a*P*S[i+1]-(d+k+r1)*PS[i+1] for p in range(1,N/2): ydot[p] = -S[p]*(r1+a*K+a*P)+k*KS[p-1]+ \ d*(PS[p]+KS[p]) ydot[0] = Q-(r1+a*K)*S[0]+d*KS[0]+k*runsumPS ydot[N/2] = k*KS[N/2-1]-(r2+a*P)*S[N/2]+ \ d*PS[N/2] ydot[G[N/2-1]] = a*P*S[N/2]-(d+k+r2)*PS[N/2] ydot[3*N/2+1] = (d+k+r1)*runsumKS-a*K*runsum2 ydot[3*N/2+2] = (d+k+r1)*(runsumPS-PS[N/2])- \ a*P*runsum1+(d+k+r2)*PS[N/2] for j in range(0,3*N/2+3): return ydot[j] # Initial conditions y0[0] = S10 for i in range(1,3*N/2+1): y0[i] = 0 y0[3*N/2+1] = K0 y0[3*N/2+2] = P0 # Solve the DEs soln = odeint(f,y0,time,mxstep = 5000) for alpha in range(0,(N/2+1)): S[alpha] = soln[:,alpha] for beta in range((N/2)+1,N+1): KS[beta-N/2-1] = soln[:,beta] for gamma in range(N+1,3*N/2+1): PS[gamma-N] = soln[:,gamma] for alpha in range(0,(N/2+1)): Splot[alpha][series] = soln[len1-1,alpha] for beta in range((N/2)+1,N+1): KSplot[beta-N/2-1][series] = soln[len1-1,beta] for gamma in range(N+1,3*N/2+1): PSplot[gamma-N][series] = soln[len1-1,gamma] for alpha in range(0,(N/2+1)): u1 = u1 + Splot[alpha] for beta in range((N/2)+1,N+1): u2 = u2 + KSplot[beta-N/2-1] for gamma in range(N+1,3*N/2+1): u3 = u3 + PSplot[gamma-N] K = soln[:,3*N/2+1] P = soln[:,3*N/2+2] Kplot[series] = soln[len1-1,3*N/2+1] Pplot[series] = soln[len1-1,3*N/2+2] utot = u1+u2+u3 #Plot plt.plot(np.log10(K00),utot[:,0]) plt.show() ---------------------------------------------------------------------- ERROR MESSAGE: RuntimeError: The size of the array returned by func (1) does not match the size of y0 (6). ---------------------------------------------------------------------- I am facing a RuntimeError in the ODE integrator step. Please help me resolve this. Thanks in advance. From input/ldompeling at casema.nl Fri Nov 6 00:08:59 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Fri, 06 Nov 2015 05:08:59 GMT Subject: raw_input and break References: Message-ID: He, Thank you for making some time for it. Is this your code ? I am also using python 3 I got an error with execute the scipt: ----------------------------------------------------------------------- Enter command> Traceback (most recent call last): File "test06.py", line 44, in for (dir, tm) in SEQUENCE: NameError: name 'SEQUENCE' is not defined ----------------------------------------------------------------------- import time import threading set_right_speed(150) set_left_speed(105) def cmdHandler(): global notDone while True: cmd = raw_input("Enter command> ").lower() if cmd.startswith("s"): notDone = False break else: print ("Unimplemented command: %s") % cmd cmdThread = threading.Thread(target=cmdHandler) cmdThread.start() def move(drct, dly): if drct == FORWARD: fwd() print ("Forward") elif drct == BACKWARD: bwd() print ("Backward") elif drct == LEFT: left() print ("Left") elif drct == RIGHT: right() print ("Right") else: print ("Invalid command: %s") % drct time.sleep(dly) stop() notDone = True servo(90) mindist = 80 while notDone: if mindist > us_dist(15): for (dir, tm) in SEQUENCE: move(dir, tm) --------------------------------------------------------------------------------------------- In reply to "Dennis Lee Bieber" who wrote the following: > On Thu, 05 Nov 2015 17:28:36 GMT, input/ldompeling at casema.nl declaimed the > following: > > > Oke, lets try your code.Can you help me with that. > > This is my code: > > ------------------------------------------------- > > from gopigo import * > > import time > > > > set_right_speed(150) > > set_left_speed(105) > > Is there a typo there? If those are setting rotation speeds for > independent drive wheels, you will have a slow left turn enabled. > > > enable_servo() > > fwd() > > print("forward 1x") > > time.sleep(4) > > stop() > > > > while True: > > servo(90) > > mindist = 80 > > > > if mindist > us_dist(15): > > "mindist" will always be 80 -- there is no code shown below that ever > changes it (so the above assignment can be put before the "while" > statement). That means your us_dist() function must somewhere return a > value greater than 80. > > > bwd() > > print ("backward 1x") > > time.sleep(2) > > stop() > > right() > > time.sleep(1) > > stop() > > print("right 1x") > > time.sleep(2) > > You stopped the right() call before ever doing any output > > > stop() > > fwd() > > print("forward 2x") > > time.sleep(3) > > stop() > > left() > > time.sleep(1) > > print("left 1x") > > stop() > > fwd() > > print("forward 3x") > > time.sleep(2) > > stop() > > ------------------------------------------------------ > > Off-hand, I'd try to get rid of a lot of that redundancy by defining > functions to encapsulate your sequence... (Python 2.x syntax -- not tested) > > > (FORWARD, BACKWARD, LEFT, RIGHT) = (1, 2, 3, 4) > SEQUENCE = [ (BACKWARD, 2), > (RIGHT, 1), > (FORWARD, 3), > (LEFT, 1), > (FORWARD, 2) ] > > def move(drct, dly): > if drct == FORWARD: > fwd() > print "Forward" > elif drct == BACKWARD: > bwd() > print "Backward" > elif drct == LEFT: > left() > print "Left" > elif drct == RIGHT: > right() > print "Right" > else: > print "Invalid command: %s" % drct > time.sleep(dly) > stop() > > notDone = True > servo(90) > mindist = 80 > > while notDone: > if mindist > us_dist(15): > for (dir, tm) in SEQUENCE: > move(dir, tm) > > -=-=-=-=- > > Now, if you don't mind having to also press the key, you could > use the threading module to handle the keyboard shutdown command instead of > using system specific modules to do raw keystroke input. You'd add > something before the while loop (and this is really pseudo-code, barely any > attempt at Python): > > import threading > > def cmdHandler(): > global notDone > while True: > cmd = raw_input("Enter command> ").lower() > if cmd.startswith("s"): > notDone = False > break > else: > print "Unimplemented command: %s" % cmd > > cmdThread = threading.Thread(target=cmdHandler) > cmdThread.start() > > This concept doesn't require changes if the underlying OS changes, and > does open things up to having more complex commands (one could have > commands with arguments since the input is line oriented). > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From avinash3003 at yahoo.co.in Fri Nov 6 00:30:08 2015 From: avinash3003 at yahoo.co.in (avinash ramu) Date: Thu, 5 Nov 2015 23:30:08 -0600 Subject: RuntimeError: The size of the array returned by func does not match the size of y0 In-Reply-To: <3ef62cda-560c-4eb9-87f0-f91a3f4d653b@googlegroups.com> References: <3ef62cda-560c-4eb9-87f0-f91a3f4d653b@googlegroups.com> Message-ID: Hi, The number of elements returned by the function f() needs to match the number of elements in the initial condition y0. The problem seems to be in this part of the code, ``` for j in range(0,3*N/2+3): return ydot[j] ``` It is returning the first element instead of the list. I modified your code to use a temporary list(ydot_new), I then add elements to this new list using the `for` statement and return the list. This seems to work fine! See below, 79 ydot_new = [] 80 for j in range(0,3*N/2+3): 81 ydot_new.extend(ydot[j]) 82 return ydot_new (I'm not an expert on ODE, so I'm not sure how to verify the correctness!) Cheers, Avi On Thu, Nov 5, 2015 at 9:54 PM, Abhishek wrote: > I have recently switched from programming heavily in MATLAB to programming > in Python. Hence I am having some issues running the Python code that I > have written. I am using IPython with Anaconda2 on Windows 7 and using > numPy and SciPy to integrate a system of ordinary differential equations. I > have generalized the system of ODEs for any number 'N' of them. > > I have two versions of code that do the same thing, and give the same > error message. One version uses 'exec' and 'eval' heavily, and the other > uses arrays heavily. Here is my code for the array version: > > ---------------------------------------------------------------------- > import numpy as np > import matplotlib.pyplot as plt > from scipy.integrate import odeint > > #Constants and parameters > N = 2 > K00 = np.logspace(0,3,101,10) > len1 = len(K00) > epsilon = 0.01 > y0 = [0]*(3*N/2+3) > u1 = 0 > u2 = 0 > u3 = 0 > Kplot = np.zeros((len1,1)) > Pplot = np.zeros((len1,1)) > S = [np.zeros((len1,1)) for kkkk in range(N/2+1)] > KS = [np.zeros((len1,1)) for kkkk in range(N/2+1)] > PS = [np.zeros((len1,1)) for kkkk in range(N/2+1)] > Splot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] > KSplot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] > PSplot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] > > for series in range(0,len1): > K0 = K00[series] > Q = 10 > r1 = 0.0001 > r2 = 0.001 > a = 0.001 > d = 0.001 > k = 0.999 > S10 = 1e5 > P0 = 1 > tfvec = np.tile(1e10,(1,5)) > tf = tfvec[0,0] > time = np.linspace(0,tf,len1) > > #Defining dy/dt's > def f(y,t): > for alpha in range(0,(N/2+1)): > S[alpha] = y[alpha] > for beta in range((N/2)+1,N+1): > KS[beta-N/2-1] = y[beta] > for gamma in range(N+1,3*N/2+1): > PS[gamma-N] = y[gamma] > K = y[3*N/2+1] > P = y[3*N/2+2] > > # The model equations > ydot = np.zeros((3*N/2+3,1)) > B = range((N/2)+1,N+1) > G = range(N+1,3*N/2+1) > runsumPS = 0 > runsum1 = 0 > runsumKS = 0 > runsum2 = 0 > > for m in range(0,N/2): > runsumPS = runsumPS + PS[m+1] > runsum1 = runsum1 + S[m+1] > runsumKS = runsumKS + KS[m] > runsum2 = runsum2 + S[m] > ydot[B[m]] = a*K*S[m]-(d+k+r1)*KS[m] > > for i in range(0,N/2-1): > ydot[G[i]] = a*P*S[i+1]-(d+k+r1)*PS[i+1] > > for p in range(1,N/2): > ydot[p] = -S[p]*(r1+a*K+a*P)+k*KS[p-1]+ \ > d*(PS[p]+KS[p]) > > ydot[0] = Q-(r1+a*K)*S[0]+d*KS[0]+k*runsumPS > ydot[N/2] = k*KS[N/2-1]-(r2+a*P)*S[N/2]+ \ > d*PS[N/2] > ydot[G[N/2-1]] = a*P*S[N/2]-(d+k+r2)*PS[N/2] > ydot[3*N/2+1] = (d+k+r1)*runsumKS-a*K*runsum2 > ydot[3*N/2+2] = (d+k+r1)*(runsumPS-PS[N/2])- \ > a*P*runsum1+(d+k+r2)*PS[N/2] > > for j in range(0,3*N/2+3): > return ydot[j] > > # Initial conditions > y0[0] = S10 > for i in range(1,3*N/2+1): > y0[i] = 0 > y0[3*N/2+1] = K0 > y0[3*N/2+2] = P0 > > # Solve the DEs > soln = odeint(f,y0,time,mxstep = 5000) > for alpha in range(0,(N/2+1)): > S[alpha] = soln[:,alpha] > for beta in range((N/2)+1,N+1): > KS[beta-N/2-1] = soln[:,beta] > for gamma in range(N+1,3*N/2+1): > PS[gamma-N] = soln[:,gamma] > > for alpha in range(0,(N/2+1)): > Splot[alpha][series] = soln[len1-1,alpha] > for beta in range((N/2)+1,N+1): > KSplot[beta-N/2-1][series] = soln[len1-1,beta] > for gamma in range(N+1,3*N/2+1): > PSplot[gamma-N][series] = soln[len1-1,gamma] > > for alpha in range(0,(N/2+1)): > u1 = u1 + Splot[alpha] > for beta in range((N/2)+1,N+1): > u2 = u2 + KSplot[beta-N/2-1] > for gamma in range(N+1,3*N/2+1): > u3 = u3 + PSplot[gamma-N] > > K = soln[:,3*N/2+1] > P = soln[:,3*N/2+2] > Kplot[series] = soln[len1-1,3*N/2+1] > Pplot[series] = soln[len1-1,3*N/2+2] > utot = u1+u2+u3 > > #Plot > plt.plot(np.log10(K00),utot[:,0]) > plt.show() > ---------------------------------------------------------------------- > ERROR MESSAGE: > RuntimeError: The size of the array returned by func (1) does not match > the size of y0 (6). > ---------------------------------------------------------------------- > > I am facing a RuntimeError in the ODE integrator step. Please help me > resolve this. Thanks in advance. > -- > https://mail.python.org/mailman/listinfo/python-list > From dan at tombstonezero.net Fri Nov 6 00:31:25 2015 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 6 Nov 2015 05:31:25 -0000 (UTC) Subject: What does =?iso-8859-13?B?tGdyZXCh?= stand for? References: <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On Thu, 05 Nov 2015 19:36:11 -0800, Larry Hudson wrote: > Anyone besides me remember the CP/M editor Mince (Mince Is Not > Complete EMACS)? It was an emacs-like editor, without any e-Lisp or > other way of extending it. I believe it was my first exposure to a > screen-oriented editor. I quite liked it at that time (but that was a > looonnng time ago!) I remember CP/M, but not Mince. Some of the CP/M boxes I used came with editors tied to their specific video boards; otherwise, it was ed (which I'm sure was based on the Unix command of the same name) or MicroPro WordMaster. Around that same time frame was Programma Improved Editor on an Apple?II. (Apple PIE. Get it?) old'ly yours, Dan From srinath.nathan at gmail.com Fri Nov 6 01:13:09 2015 From: srinath.nathan at gmail.com (srinath.nathan at gmail.com) Date: Thu, 5 Nov 2015 22:13:09 -0800 (PST) Subject: Python dashboard tutorials/frameworks for interactive, D3.js graphs in IPython Notebooks In-Reply-To: References: Message-ID: <907b76a1-5c28-471e-b9c4-fc66ac281184@googlegroups.com> On Thursday, July 9, 2015 at 8:10:16 PM UTC-4, Matt Sundquist wrote: > Hi all, > > I'm part of Plotly, and we've just finished a few releases I thought I'd pass along. > > These tools make it easy to craft interactive graphs and dashboards with D3.js using Python. We're especially drawn towards matplotlib, pandas, and IPython. We're still early in building, so any and all feedback and help is much appreciated. > > First, here is an overview of some of our dashboard capabilities: > > http://blog.plot.ly/post/123617968702/online-dashboards-eight-helpful-tips-you-should > > For more background, refer to our Python docs: https://plot.ly/python/, our Python framework for making dashboards: https://github.com/plotly/dash, our data science blog: http://moderndata.plot.ly/, or these 21 IPython Notebooks: https://plot.ly/python/ipython-notebooks/. > > Feedback and suggestions are welcome! > > M You guys are so expensive - not even worth looking into your product. Absolutely retarded. Srinath From zbin1986 at gmail.com Fri Nov 6 01:34:50 2015 From: zbin1986 at gmail.com (zbin1986 at gmail.com) Date: Thu, 5 Nov 2015 22:34:50 -0800 (PST) Subject: Script to extract text from PDF files In-Reply-To: References: Message-ID: <2710bad0-39f0-45f3-afbb-dc98016cb6d5@googlegroups.com> you can try this free online pdf text extractor http://www.online-code.net/pdf-to-word.html to extract text from pdf free online. From zbin1986 at gmail.com Fri Nov 6 02:08:15 2015 From: zbin1986 at gmail.com (zbin1986 at gmail.com) Date: Thu, 5 Nov 2015 23:08:15 -0800 (PST) Subject: Using python to convert PDF document to MSWord documents In-Reply-To: References: <20040928161317.88987.qmail@web8401.mail.in.yahoo.com> Message-ID: I'm not a developer, i always use this free online pdf to word converter http://www.online-code.net/pdf-to-word.html to convert pdf to ms doc online. From rosuav at gmail.com Fri Nov 6 03:38:11 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Nov 2015 19:38:11 +1100 Subject: Python dashboard tutorials/frameworks for interactive, D3.js graphs in IPython Notebooks In-Reply-To: <907b76a1-5c28-471e-b9c4-fc66ac281184@googlegroups.com> References: <907b76a1-5c28-471e-b9c4-fc66ac281184@googlegroups.com> Message-ID: On Fri, Nov 6, 2015 at 5:13 PM, wrote: > On Thursday, July 9, 2015 at 8:10:16 PM UTC-4, Matt Sundquist wrote: >> For more background, refer to our Python docs: https://plot.ly/python/, our Python framework for making dashboards: https://github.com/plotly/dash, our data science blog: http://moderndata.plot.ly/, or these 21 IPython Notebooks: https://plot.ly/python/ipython-notebooks/. >> > > You guys are so expensive - not even worth looking into your product. Absolutely retarded. > Srinath No need to be so rude as you complain about people getting paid for their work. I'm not even sure your complaint is accurate; where did you see ridiculously high prices? I started with the first link I quoted above (the Python docs), and up the top is this note: "plotly is free for unlimited public use". Then there's a zero-dollar option (though that might be the same as the previous note), and a $20/mo option called "professional". If professional usage is only $20 per month, I don't think it's fair to call it "absolutely retarded". Yes, there's also an on-premise option for ten grand a year, but that's some serious top-end privacy stuff... if you think you have to pay that just to make use of their services, then yes, I can see that you'd complain about the pricing! Or was this a deliberate troll to make people go look at the pricing in more detail? ChrisA From amit.ramon at gmail.com Fri Nov 6 05:07:43 2015 From: amit.ramon at gmail.com (Amit Ramon) Date: Fri, 6 Nov 2015 12:07:43 +0200 Subject: argparse: use of double dash to separate options and positional arguments Message-ID: <20151106100743.GN3685@isis.luna> Hello, I'm trying to use argparse in a program that gets some options and positional arguments. I want to collect all the positional arguments in a single argument using the REMAINDER option to add_argument() as shown bellow: parser = argparse.ArgumentParser(description='Test argparse') parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('cmd_args', nargs=argparse.REMAINDER) print parser.parse_args() This works well unless the first positional argument starts with a '-'. For example, with the above code my_prog -v hello world works well, but my_prog -v -x hello world Fails with an error message 'error: unrecognized arguments: -x'. If I invoke the program with a '--' at the end of the options (as I understand is a common standard and a POSIX recommendation), as in: my_prog -v -- -x hello world It works well again. However, a few questions remain: Firstly, as far as I can tell the use of '--' is not documented in the argparse documentation (but the code of argparse clearly shows that it is a feature). Secondly, when using '--', this string itself is inserted into the list of the collected positional arguments (in the above example in the cmd_args variable): $ ./my_prog -v -- -x hello world Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True) It's quiet easy to check for it and remove it if it exists, but it still seems like it shouldn't be there - it is not really an argument, just a delimiter. Am I doing anything wrong, or is this a bug? I hope someone here can shed some light on this. Thanks, Amit -- From rosuav at gmail.com Fri Nov 6 05:30:16 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Nov 2015 21:30:16 +1100 Subject: Question about math.pi is mutable In-Reply-To: <201511061033583772468@travelsky.com> References: <201511061033583772468@travelsky.com> Message-ID: On Fri, Nov 6, 2015 at 1:33 PM, wangq at travelsky.com wrote: > Hello, python-list guys: > > I am a newbie of python from Beijing. China. > I have a question about "math.pi". > As you can see in the attachment, why i can modify "math.pi"? > (in "mathmodule.c" "pi" is a "static const double") > > Thank you in advance! > > Best Wishes? Simply because, in Python, virtually everything can be changed. You're welcome to go in and say "math.pi = 3" if you like... and then you accept the consequences of that. There are times when you want to change these sorts of 'constants'. For example, math.pi is a float; but if you're working with decimal.Decimal everywhere, it might be useful to replace it with a corresponding Decimal value: math.pi = decimal.Decimal("3.14159265358979323") And that's perfectly legal. ChrisA From rosuav at gmail.com Fri Nov 6 05:34:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Nov 2015 21:34:00 +1100 Subject: Olivier Adret In-Reply-To: <563B74B6.80402@gmail.com> References: <563B74B6.80402@gmail.com> Message-ID: On Fri, Nov 6, 2015 at 2:24 AM, olivier wrote: > Je vais essayer de programmer en python. On verra bien ! Hello Olivier! This is a mostly English language mailing list/newsgroup, and there aren't many people who are fluent in French. There is, however, a corresponding French newsgroup, fr.comp.lang.python; you may find that you're more comfortable communicating there. My apologies for not responding in French, but I'm not very familiar with it, and all I would do is put my text through an online translation tool. Chris Angelico From ian.g.kelly at gmail.com Fri Nov 6 05:38:10 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Nov 2015 03:38:10 -0700 Subject: Question about math.pi is mutable In-Reply-To: <201511061033583772468@travelsky.com> References: <201511061033583772468@travelsky.com> Message-ID: On Nov 6, 2015 3:20 AM, "wangq at travelsky.com" wrote: > > Hello, python-list guys: > > I am a newbie of python from Beijing. China. > I have a question about "math.pi". > As you can see in the attachment, why i can modify "math.pi"? > (in "mathmodule.c" "pi" is a "static const double") Like all floats, math.pi is immutable. However, the *name* pi in the math module is not special and can be rebound to a new value, like (almost) any other name. So yes, you can assign 3 to math.pi. You can also assign 3 to math.sqrt, or os.urandom, or float. From __peter__ at web.de Fri Nov 6 05:57:06 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Nov 2015 11:57:06 +0100 Subject: argparse: use of double dash to separate options and positional arguments References: <20151106100743.GN3685@isis.luna> Message-ID: Amit Ramon wrote: > Hello, > > I'm trying to use argparse in a program that gets some options and > positional arguments. I want to collect all the positional arguments > in a single argument using the REMAINDER option to add_argument() as > shown bellow: > > parser = argparse.ArgumentParser(description='Test argparse') > parser.add_argument('-v', '--verbose', action='store_true') > parser.add_argument('cmd_args', nargs=argparse.REMAINDER) > print parser.parse_args() > > This works well unless the first positional argument starts with a > '-'. > > For example, with the above code > > my_prog -v hello world > > works well, but > > my_prog -v -x hello world > > Fails with an error message 'error: unrecognized arguments: -x'. This looks like a bug to me. Please report it on bug.python.org. > If I invoke the program with a '--' at the end of the options (as I > understand is a common standard and a POSIX recommendation), as in: > > my_prog -v -- -x hello world > > It works well again. > > However, a few questions remain: > > Firstly, as far as I can tell the use of '--' is not documented in the > argparse documentation (but the code of argparse clearly shows that it > is a feature). > > Secondly, when using '--', this string itself is inserted into the > list of the collected positional arguments (in the above example in > the cmd_args variable): > > $ ./my_prog -v -- -x hello world > Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True) > > It's quiet easy to check for it and remove it if it exists, but it > still seems like it shouldn't be there - it is not really an argument, > just a delimiter. I'm not sure about this one; one purpose of REMAINDER is to pass on the unprocessed arguments to another program/script, and this might follow the same convention. Should parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('cmd_args', nargs=argparse.REMAINDER) args = parser.parse_args() subprocess.call(["rm"] + args.cmd_args) $ my_prog -v -- -r foo attempt to delete two files "-r" and "foo" or remove the "foo" directory? The first is the safer alternative, and as you say stripping the "--" is easy. > Am I doing anything wrong, or is this a bug? I hope someone here can > shed some light on this. From amit.ramon at gmail.com Fri Nov 6 06:44:59 2015 From: amit.ramon at gmail.com (Amit Ramon) Date: Fri, 6 Nov 2015 13:44:59 +0200 Subject: argparse: use of double dash to separate options and positional arguments In-Reply-To: References: <20151106100743.GN3685@isis.luna> Message-ID: <20151106114459.GO3685@isis.luna> Peter Otten <__peter__ at web.de> [2015-11-06 11:57 +0100]: >> >> For example, with the above code >> >> my_prog -v hello world >> >> works well, but >> >> my_prog -v -x hello world >> >> Fails with an error message 'error: unrecognized arguments: -x'. > >This looks like a bug to me. Please report it on bug.python.org. Why does it looks like a bug? To me it seems okay - argparse expects that an argument that starts with '-' is an option, and it also expects to be told about all possible options, so it complains on encountering an unrecognized 'option'. This is why a special delimiter is needed to mark the 'end of options'. > >> If I invoke the program with a '--' at the end of the options (as I >> understand is a common standard and a POSIX recommendation), as in: >> >> my_prog -v -- -x hello world >> >> It works well again. >> >> However, a few questions remain: >> >> Firstly, as far as I can tell the use of '--' is not documented in the >> argparse documentation (but the code of argparse clearly shows that it >> is a feature). >> >> Secondly, when using '--', this string itself is inserted into the >> list of the collected positional arguments (in the above example in >> the cmd_args variable): >> >> $ ./my_prog -v -- -x hello world >> Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True) >> >> It's quiet easy to check for it and remove it if it exists, but it >> still seems like it shouldn't be there - it is not really an argument, >> just a delimiter. > >I'm not sure about this one; one purpose of REMAINDER is to pass on the >unprocessed arguments to another program/script, and this might follow the >same convention. Should > >parser.add_argument('-v', '--verbose', action='store_true') >parser.add_argument('cmd_args', nargs=argparse.REMAINDER) >args = parser.parse_args() >subprocess.call(["rm"] + args.cmd_args) > >$ my_prog -v -- -r foo > >attempt to delete two files "-r" and "foo" or remove the "foo" directory? >The first is the safer alternative, and as you say stripping the "--" is >easy. I'm using the REMAINDER exactly for passing on arguments to another program, as in your example. I would expect that everything after the '--' should be passed on as is - it should be up to the other program to decide what to do with the arguments it receives (So in your examples, rm would actually try to remove the "foo" directory). And although stripping the '--' is easy, why should the user of argparse need to handle it? Still unclear to me. Cheers, Amit From input/ldompeling at casema.nl Fri Nov 6 06:50:50 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Fri, 06 Nov 2015 11:50:50 GMT Subject: raw_input and break References: Message-ID: Hi, I tried to define SEQUENCE with: The script is working now, exept that I do'nt get a menu in terminal for "s" to stop. --------------------------------------------------------------------------------- def SEQUENCE(): while notDone: if mindist > us_dist(15): for (dir, tm) in SEQUENCE: move(dir, tm) --------------------------------------------------------------------------------- In reply to "input/ldompeling at casema.nl" who wrote the following: > He, > Thank you for making some time for it. > Is this your code ? > I am also using python 3 > > I got an error with execute the scipt: > ----------------------------------------------------------------------- > > Enter command> Traceback (most recent call last): > File "test06.py", line 44, in > for (dir, tm) in SEQUENCE: > NameError: name 'SEQUENCE' is not defined > ----------------------------------------------------------------------- > > import time > import threading > > set_right_speed(150) > set_left_speed(105) > > def cmdHandler(): > global notDone > while True: > cmd = raw_input("Enter command> ").lower() > if cmd.startswith("s"): > notDone = False > break > else: > print ("Unimplemented command: %s") % cmd > > cmdThread = threading.Thread(target=cmdHandler) > cmdThread.start() > def move(drct, dly): > if drct == FORWARD: > fwd() > print ("Forward") > elif drct == BACKWARD: > bwd() > print ("Backward") > elif drct == LEFT: > left() > print ("Left") > elif drct == RIGHT: > right() > print ("Right") > else: > print ("Invalid command: %s") % drct > time.sleep(dly) > stop() > > notDone = True > > servo(90) > mindist = 80 > > while notDone: > if mindist > us_dist(15): > for (dir, tm) in SEQUENCE: > move(dir, tm) > > ------------------------------------------------------------------------------ > --------------- > In reply to "Dennis Lee Bieber" who wrote the following: > > > On Thu, 05 Nov 2015 17:28:36 GMT, input/ldompeling at casema.nl declaimed the > > following: > > > > > Oke, lets try your code.Can you help me with that. > > > This is my code: > > > ------------------------------------------------- > > > from gopigo import * > > > import time > > > > > > set_right_speed(150) > > > set_left_speed(105) > > > > Is there a typo there? If those are setting rotation speeds for > > independent drive wheels, you will have a slow left turn enabled. > > > > > enable_servo() > > > fwd() > > > print("forward 1x") > > > time.sleep(4) > > > stop() > > > > > > while True: > > > servo(90) > > > mindist = 80 > > > > > > if mindist > us_dist(15): > > > > "mindist" will always be 80 -- there is no code shown below that ever > > changes it (so the above assignment can be put before the "while" > > statement). That means your us_dist() function must somewhere return a > > value greater than 80. > > > > > bwd() > > > print ("backward 1x") > > > time.sleep(2) > > > stop() > > > right() > > > time.sleep(1) > > > stop() > > > print("right 1x") > > > time.sleep(2) > > > > You stopped the right() call before ever doing any output > > > > > stop() > > > fwd() > > > print("forward 2x") > > > time.sleep(3) > > > stop() > > > left() > > > time.sleep(1) > > > print("left 1x") > > > stop() > > > fwd() > > > print("forward 3x") > > > time.sleep(2) > > > stop() > > > ------------------------------------------------------ > > > > Off-hand, I'd try to get rid of a lot of that redundancy by defining > > functions to encapsulate your sequence... (Python 2.x syntax -- not tested) > > > > > > (FORWARD, BACKWARD, LEFT, RIGHT) = (1, 2, 3, 4) > > SEQUENCE = [ (BACKWARD, 2), > > (RIGHT, 1), > > (FORWARD, 3), > > (LEFT, 1), > > (FORWARD, 2) ] > > > > def move(drct, dly): > > if drct == FORWARD: > > fwd() > > print "Forward" > > elif drct == BACKWARD: > > bwd() > > print "Backward" > > elif drct == LEFT: > > left() > > print "Left" > > elif drct == RIGHT: > > right() > > print "Right" > > else: > > print "Invalid command: %s" % drct > > time.sleep(dly) > > stop() > > > > notDone = True > > servo(90) > > mindist = 80 > > > > while notDone: > > if mindist > us_dist(15): > > for (dir, tm) in SEQUENCE: > > move(dir, tm) > > > > -=-=-=-=- > > > > Now, if you don't mind having to also press the key, you could > > use the threading module to handle the keyboard shutdown command instead of > > using system specific modules to do raw keystroke input. You'd add > > something before the while loop (and this is really pseudo-code, barely any > > attempt at Python): > > > > import threading > > > > def cmdHandler(): > > global notDone > > while True: > > cmd = raw_input("Enter command> ").lower() > > if cmd.startswith("s"): > > notDone = False > > break > > else: > > print "Unimplemented command: %s" % cmd > > > > cmdThread = threading.Thread(target=cmdHandler) > > cmdThread.start() > > > > This concept doesn't require changes if the underlying OS changes, and > > does open things up to having more complex commands (one could have > > commands with arguments since the input is line oriented). > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > > > -- > --------------------------------- --- -- - > Posted with NewsLeecher v7.0 Beta 2 > Web @ http://www.newsleecher.com/?usenet > ------------------- ----- ---- -- - -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From vs at it.uu.se Fri Nov 6 06:53:43 2015 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 6 Nov 2015 12:53:43 +0100 Subject: Questions on Pickle and Shelve Message-ID: <563C94C7.8030805@it.uu.se> Here is snippet of Python (vers. 2.7.10) code that bothers me. import cPickle as pickle print "Pickle lists:" dogs = ['Rover','King','Spot','Rufus'] cats = ['Mimi','Misty','Sasha'] with open('pickle.dat', 'wb') as pfile: pickle.dump(dogs, pfile) pickle.dump(cats,pfile) del(dogs); del(cats) with open('pickle.dat', 'rb') as pfile: dogs = pickle.load(pfile) cats = pickle.load(pfile) print dogs, '\n', cats, '\n' import shelve # Note! __exit__ attribute undefined for shelve sfile = shelve.open('shelve.dat') sfile['dogs'] = dogs sfile['cats'] = cats sfile.close() print "Shelve entries:" del(cats); del(dogs) sfile = shelve.open('shelve.dat') #print sfile for key in sfile.keys(): print key,' - ',sfile[key] sfile.close() 1) Which (the pickle or shelve code) takes less total RAM, if dogs and cats were very large? 2) When the last shelve.open is given, is the entire contents of shelve.data transferred to RAM? Note, if the print sfile is uncommented then the entire contents of shelve.data is printed out. I was under the impression that the entire contents of a shelved file was not transferred to RAM when it was opened. From bc at freeuk.com Fri Nov 6 07:30:29 2015 From: bc at freeuk.com (Bartc) Date: Fri, 6 Nov 2015 12:30:29 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: On 06/11/2015 02:33, wangq at travelsky.com wrote: > Hello, python-list guys: > > I am a newbie of python from Beijing. China. > I have a question about "math.pi". > As you can see in the attachment, why i can modify "math.pi"? > (in "mathmodule.c" "pi" is a "static const double") Python isn't C. Your attachment isn't visible, but it can be demonstrated easily: import math math.pi=0 print (math.pi) In Python, presumably 'pi' is just another variable, and variables can be written to. (Perhaps math.pi would be better off as a function.) -- Bartc From marko at pacujo.net Fri Nov 6 07:55:00 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 06 Nov 2015 14:55:00 +0200 Subject: Question about math.pi is mutable References: <201511061033583772468@travelsky.com> Message-ID: <87k2pvi8yj.fsf@elektro.pacujo.net> Chris Angelico : > Simply because, in Python, virtually everything can be changed. You're > welcome to go in and say "math.pi = 3" if you like... and then you > accept the consequences of that. How far cosmology would have evolved by now if Albert Einstein had had Python at his disposal. He could simply have been able to experiment with different values of the Cosmological Constant and seen the effects around him in the room. Marko From gheskett at wdtv.com Fri Nov 6 08:21:42 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 6 Nov 2015 08:21:42 -0500 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084A8D60B8@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511052310.tA5NAjAk026602@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A8D60B8@DCBL123VX.root.sutterhealth.org> Message-ID: <201511060821.42877.gheskett@wdtv.com> On Thursday 05 November 2015 19:04:35 Robinson, Wendy wrote: > Hmmm... fair enough. I sent the traceback though, on Monday. If you sent a traceback on Monday, it wasn't seen by this list. Do not 'attach' it to the message, but include it as the list server might have stripped an attachment. > I'll give the intro a read again. I've probably missed something > basic. > > Wendy Robinson > Audit Analyst > (916)?566-4994 phone > > > > NOTICE OF CONFIDENTIALITY: This email is for the sole use of the > intended recipient and may contain material that is confidential and > protected by state and federal regulations.? If you are not the > intended recipient please immediately delete it and contact the > sender. This is a public list Wendy, so this has no meaning. There are those, who on seeing such a message, will not reply even if they could help. > -----Original Message----- > From: Laura Creighton [mailto:lac at openend.se] > Sent: Thursday, November 05, 2015 3:11 PM > To: Robinson, Wendy > Cc: 'Laura Creighton'; 'python-list at python.org'; lac at openend.se > Subject: Re: Puzzled > > In a message of Thu, 05 Nov 2015 12:48:11 -0800, "Robinson, Wendy" writes: > >Well... I still can't get this to work. I guess I'll just uninstall > > it. It's a bummer that there's no help on basic startup like this. > > > >Wendy Robinson > >Audit Analyst > >(916)?566-4994 phone > > There is enormous amount of help available. But we need to know more > about what your problem is, and how it presents itself before we can > start tracking down what your problem is, which is why I wanted a > traceback. > > >>Hi there, > >>I installed Python 3.5.0 64-bit for Windows yesterday and tried some > >> basic programs successfully. This morning I rebooted my computer > >> and can't get a single one to work. The interpreter seems to be > >> fine and the environment variables look correct. But every py file > >> I try to run at the >>> prompt gives me a NameError. > > See, this is where your problem is. There is a conceptual problem in > understanding what you meant by 'tried some basic programs > successfully' versus 'running py files at the >>> prompt'. > > Either you didn't use the Python console -- the thing that is showing > you the '>>>' yesterday, and thus the programs that were working > yesterday are now working every bit as well as they did then, and your > problem is that you do not know how to use the python console. > > Or you did use the console before, and they worked there, and now you > have NameErrors. > > I think the problem is the first sort. > I think that you opened up the python console and then typed in > something like 'myprogram.py' expecting the console to run the > myprogram. Instead you got something like this: > > Python 3.5.0rc1 (default, Aug 12 2015, 14:57:46) [GCC 5.2.1 20150808] > on linux Type "help", "copyright", "credits" or "license" for more > information. > > >>> myprogram.py > > Traceback (most recent call last): > File "", line 1, in > NameError: name 'myprogram' is not defined >>> > > If this is what happened then your python is fine. You just do not > know how the interactive console works. It doesn't run files like > this. > > See:https://docs.python.org/3.5/tutorial/introduction.html > > You type code at the console and get responses back. > > If, on the other hand, this is not your problem, then we need a > traceback --- and what I posted above was a traceback -- so that we > can see what caused the NameError. > > Laura 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 wrw at mac.com Fri Nov 6 08:25:09 2015 From: wrw at mac.com (William Ray Wing) Date: Fri, 06 Nov 2015 08:25:09 -0500 Subject: =?utf-8?Q?Re=3A_What_does_=E2=80=9Cgrep=E2=80=9D_stand_for=3F?= In-Reply-To: References: <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: > On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list wrote: > > On 11/05/2015 05:18 PM, Dennis Lee Bieber wrote: >> On Thu, 5 Nov 2015 20:19:39 +0000 (UTC), Grant Edwards >> declaimed the following: >> >>> Though I used a line-editor for a while on VMS, I was never very good >>> at it, and abanded it for a full-screen editor at he first >>> opportunity. But, if you ever get a chance to watching somebody who >>> _is_ good at 'ed', it's something you'll remember... >> >> I didn't convert to EDT until DEC dropped SOS... And then shortly later >> I keymapped the Blaise ([Alcor] Pascal) editor on the TRS-80 Mod-III to >> replicate EDT (as much as possible, given only three function keys on the >> numeric pad) >> >> The Amiga used to have two standard editors -- a screen editor and a >> line editor; as I recall the line editor supported a file window, so one >> could edit large files by making a single direction pass using a smaller >> window and a script. Later the screen editor gained ARexx support, so one >> could script it using ARexx. (And by then they also included a form of >> microEMACS, my C compiler had a look-alike vi editor... and a later C >> compiler had another editor integrated to the compiler so that error >> message reports could trigger the editor to open the file and move to the >> error position) >> > Anyone besides me remember the CP/M editor Mince (Mince Is Not Complete EMACS)? > It was an emacs-like editor, without any e-Lisp or other way of extending it. I believe it was my first exposure to a screen-oriented editor. I quite liked it at that time (but that was a looonnng time ago!) > > -=- Larry -=- > > -- > https://mail.python.org/mailman/listinfo/python-list You?re not REALLY an old timer unless you?ve used TECO. -Bill From mr.eightnoteight at gmail.com Fri Nov 6 08:40:07 2015 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Fri, 6 Nov 2015 19:10:07 +0530 Subject: Unbuffered stderr in Python 3 In-Reply-To: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> References: <5637165b$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Nov 2, 2015 at 1:22 PM, Steven D'Aprano wrote: > > So how come Python 3 has line buffered stderr? And more importantly, how can > I turn buffering off? > > I don't want to use the -u unbuffered command line switch, because that > effects stdout as well. I'm happy for stdout to remain buffered. > you can simply turn buffering off for stderr by redefining the print function or declaring a new print function like from functools import partial print = partial(print, flush=True) # or from functools import partial import sys printerr = partial(print, flush=True, file=sys.stderr) From chris at gonnerman.org Fri Nov 6 08:40:29 2015 From: chris at gonnerman.org (Chris Gonnerman) Date: Fri, 6 Nov 2015 07:40:29 -0600 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> Message-ID: <563CADCD.8070307@gonnerman.org> Wendy said: > I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic programs successfully. > This morning I rebooted my computer and can't get a single one to work. The interpreter seems to be fine and the environment variables look correct. But every py file I try to run at the >>> prompt gives me a NameError. But that's not how the Python interpreter works. You say you are trying to run "py files" at the >>> prompt. If what you are doing is this: >>> test.py Well, no, that's not going to work. If you want to run "test.py" as a script, from the CMD prompt you type: python test.py If test.py is a module meant to be imported, then from the Python prompt you do this: import test Hope this helps. -- Chris. From invalid at invalid.invalid Fri Nov 6 09:15:43 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 6 Nov 2015 14:15:43 +0000 (UTC) Subject: What does ???grep??? stand for? References: <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 2015-11-06, Dennis Lee Bieber wrote: > On Thu, 5 Nov 2015 20:19:39 +0000 (UTC), Grant Edwards > declaimed the following: > >>Though I used a line-editor for a while on VMS, I was never very good >>at it, and abanded it for a full-screen editor at he first >>opportunity. But, if you ever get a chance to watching somebody who >>_is_ good at 'ed', it's something you'll remember... > > I didn't convert to EDT until DEC dropped SOS... Yes! Son of Stopgap! I had completely forgotten the name... And then I think Eve came after EDT. That was about where I switched to Unix. -- Grant From __peter__ at web.de Fri Nov 6 10:13:11 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Nov 2015 16:13:11 +0100 Subject: argparse: use of double dash to separate options and positional arguments References: <20151106100743.GN3685@isis.luna> <20151106114459.GO3685@isis.luna> Message-ID: Amit Ramon wrote: > Peter Otten <__peter__ at web.de> [2015-11-06 11:57 +0100]: > > >>> >>> For example, with the above code >>> >>> my_prog -v hello world >>> >>> works well, but >>> >>> my_prog -v -x hello world >>> >>> Fails with an error message 'error: unrecognized arguments: -x'. >> >>This looks like a bug to me. Please report it on bug.python.org. > > Why does it looks like a bug? To me it seems okay - argparse expects > that an argument that starts with '-' is an option, and it also expects > to be told about all possible options, so it complains on > encountering an unrecognized 'option'. This is why a special delimiter > is needed to mark the 'end of options'. > > >> >>> If I invoke the program with a '--' at the end of the options (as I >>> understand is a common standard and a POSIX recommendation), as in: >>> >>> my_prog -v -- -x hello world >>> >>> It works well again. >>> >>> However, a few questions remain: >>> >>> Firstly, as far as I can tell the use of '--' is not documented in the >>> argparse documentation (but the code of argparse clearly shows that it >>> is a feature). >>> >>> Secondly, when using '--', this string itself is inserted into the >>> list of the collected positional arguments (in the above example in >>> the cmd_args variable): >>> >>> $ ./my_prog -v -- -x hello world >>> Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True) >>> >>> It's quiet easy to check for it and remove it if it exists, but it >>> still seems like it shouldn't be there - it is not really an argument, >>> just a delimiter. >> >>I'm not sure about this one; one purpose of REMAINDER is to pass on the >>unprocessed arguments to another program/script, and this might follow the >>same convention. Should >> >>parser.add_argument('-v', '--verbose', action='store_true') >>parser.add_argument('cmd_args', nargs=argparse.REMAINDER) >>args = parser.parse_args() >>subprocess.call(["rm"] + args.cmd_args) >> >>$ my_prog -v -- -r foo >> >>attempt to delete two files "-r" and "foo" or remove the "foo" directory? >>The first is the safer alternative, and as you say stripping the "--" is >>easy. > > I'm using the REMAINDER exactly for passing on arguments to another > program, as in your example. I would expect that everything after > the '--' should be passed on as is - it should be up to the other > program to decide what to do with the arguments it receives (So in > your examples, rm would actually try to remove the "foo" directory). > > And although stripping the '--' is easy, why should the user of > argparse need to handle it? Still unclear to me. My interpretation was that REMAINDER should give you the rest of the commandline args, no matter what special meaning these args might have for argparse. From courseforum at gmail.com Fri Nov 6 10:45:54 2015 From: courseforum at gmail.com (Mark Roseman) Date: Fri, 6 Nov 2015 07:45:54 -0800 (PST) Subject: Modernizing IDLE Message-ID: <0c616344-06ab-43ed-a570-79c60aa41137@googlegroups.com> Wanted to pass along a case study of some work being done to improve the look and feel of IDLE. This is a work-in-progress, gradually being integrated into the Python codebase. Given that, it's a great opportunity to get involved, provide some feedback, and make it even better! http://www.tkdocs.com/tutorial/idle.html As you can tell from the URL, it's part of a broader tutorial on modernizing the appearance of Tkinter based programs. Mark From lorenzofsutton at gmail.com Fri Nov 6 11:12:07 2015 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Fri, 6 Nov 2015 17:12:07 +0100 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: <563CD157.7060105@gmail.com> On 06/11/2015 13:30, Bartc wrote: > On 06/11/2015 02:33, wangq at travelsky.com wrote: >> Hello, python-list guys: >> >> I am a newbie of python from Beijing. China. >> I have a question about "math.pi". >> As you can see in the attachment, why i can modify "math.pi"? >> (in "mathmodule.c" "pi" is a "static const double") > > Python isn't C. > > Your attachment isn't visible, but it can be demonstrated easily: > > import math > > math.pi=0 > > print (math.pi) > > In Python, presumably 'pi' is just another variable, and variables can > be written to. > > (Perhaps math.pi would be better off as a function.) Still nothing stops you from doing: math.sin = 0 If you really want to? From kwpolska at gmail.com Fri Nov 6 11:43:17 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Fri, 6 Nov 2015 17:43:17 +0100 Subject: Questions on Pickle and Shelve In-Reply-To: <563C94C7.8030805@it.uu.se> References: <563C94C7.8030805@it.uu.se> Message-ID: On 6 November 2015 at 12:53, Virgil Stokes wrote: > Here is snippet of Python (vers. 2.7.10) code that bothers me. > > [snip bad code] > > 1) Which (the pickle or shelve code) takes less total RAM, if dogs and cats > were very large? > 2) When the last shelve.open is given, is the entire contents of > shelve.data transferred to RAM? Note, if the print sfile is uncommented > then the entire contents of shelve.data is printed out. > > I was under the impression that the entire contents of a shelved file was > not transferred to RAM when it was opened. > > > -- > https://mail.python.org/mailman/listinfo/python-list 1) That does not matter. I do know that shelve files can grow larger over time though. 2) Shelve files are pickles in disguise. Which means they need to be loaded into memory, executing *arbitrary code*. Here?s a question for you: 3) Why are you using either? Both are unsafe and can lead to issues if you take untrusted files. Use JSON. -- Chris Warrick PGP: 5EAAEA16 From __peter__ at web.de Fri Nov 6 13:15:56 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Nov 2015 19:15:56 +0100 Subject: Questions on Pickle and Shelve References: <563C94C7.8030805@it.uu.se> Message-ID: Virgil Stokes wrote: > Here is snippet of Python (vers. 2.7.10) code that bothers me. > > import cPickle as pickle > > print "Pickle lists:" > dogs = ['Rover','King','Spot','Rufus'] > cats = ['Mimi','Misty','Sasha'] > > with open('pickle.dat', 'wb') as pfile: > pickle.dump(dogs, pfile) > pickle.dump(cats,pfile) > > del(dogs); del(cats) > with open('pickle.dat', 'rb') as pfile: > dogs = pickle.load(pfile) > cats = pickle.load(pfile) > print dogs, '\n', cats, '\n' > > import shelve > > # Note! __exit__ attribute undefined for shelve > sfile = shelve.open('shelve.dat') > sfile['dogs'] = dogs > sfile['cats'] = cats > sfile.close() > > print "Shelve entries:" > del(cats); del(dogs) > sfile = shelve.open('shelve.dat') > #print sfile > for key in sfile.keys(): > print key,' - ',sfile[key] > sfile.close() > > 1) Which (the pickle or shelve code) takes less total RAM, if dogs and > cats were very large? I think this is the wrong question. shelve is built on top of a key-value store. It can hold more cats and dogs than fit into memory, and lookup of a cat or dog should be efficient when you store one animal per key: db = shelve.open(...) db["Rover"] = Dog(...) db["King"] = Dog(...) db["Misty"] = Cat(...) If you put all dogs in a big list to store them in the shelve and there are only a few such lists there is no advantage over plain pickle. > 2) When the last shelve.open is given, is the entire contents of > shelve.data > transferred to RAM? Note, if the print sfile is uncommented then the > entire contents of shelve.data is printed out. That is due to a careless implementation. Lookup is good, but everything else will only work for debugging, with small data samples. > I was under the impression that the entire contents of a shelved file was > not transferred to RAM when it was opened. They aren't. The details vary depending on what database is used. From D.Strohl at F5.com Fri Nov 6 13:21:23 2015 From: D.Strohl at F5.com (Dan Strohl) Date: Fri, 6 Nov 2015 18:21:23 +0000 Subject: python PEP suggestion Message-ID: All, I wanted to run the following thought past the list as a possible PEP enhancement suggestion to see if it feels like something that is worth proposing. I know it is not in the PEP format at this point, I can, and will, clean it up if needed, I am just trying to throw it against the wall at this point to see if it resonates... (or if it falls flat and goes "splat" ). Thoughts? Dan Strohl New special method name to allow for more flexible object type casting/access, and extend type() to cast objects using this special method name. Overview: Have a new special method name that would allow a given objects to request information from another object in a given type, or to cast an object into a different type, and extend the built in type() function to use this. Rationale: There is currently __str__, __int__, and __bool__ that allow me to tell an object how it should reply to a request for these types of basic data types. However if I want to access a copy of the objet in dict form, or as a list, or if I am trying to convert something using json, there is no standard way of doing that for a custom object (I know I can do __getitem__ and/or __iter__, but I many processes don't try these if the object is not a subclass of dict or list/tuple) Proposal: What I am proposing is something like: object.__cast__(self, to_class): """ to_class: the class type that you wish to return. """ -and- Class type(object, to_class): """ With two arguments, will attempt to cast "object" into "to_class" if possible. This would be done by something like the following: (with 1 and 3 arguments, will work as currently designed) """ Type(object, to_class): If isinstance(to_class, (int, str, bool)): Return to_class(object) Else: Try: Return object.__cast__(to_class): Except AttributeError: # yes, I know this should be more readable! Raise TypeError('object x could not be converted to type y") This allows for more customization on how a developer would want to return this object in various forms, and if, for example, the custom object was passed to something like json.dumps, it could try converting the object to something it recognizes first, or even try doing something like type(custom_object, json) and see what returned. So, in implementation I might do something like: def __conv__(self, to_class): if isinstance(to_class, (json, dict)): return self._data_dict elif isinstance(to_class, ElementTree): return self._get_xml_dict() else: raise TypeError('could not convert object to class') This allows for developers of classes that operate on data passed to be able to define a process that they would use to accept unknown objects, without having to worry about handling all of the different potential object types, and pass the responsibility for how to structure the information to the developer of the custom object. From bc at freeuk.com Fri Nov 6 14:30:54 2015 From: bc at freeuk.com (Bartc) Date: Fri, 6 Nov 2015 19:30:54 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: On 06/11/2015 16:12, Lorenzo Sutton wrote: > > > On 06/11/2015 13:30, Bartc wrote: >> On 06/11/2015 02:33, wangq at travelsky.com wrote: >>> Hello, python-list guys: >>> >>> I am a newbie of python from Beijing. China. >>> I have a question about "math.pi". >>> As you can see in the attachment, why i can modify "math.pi"? >>> (in "mathmodule.c" "pi" is a "static const double") >> >> Python isn't C. >> >> Your attachment isn't visible, but it can be demonstrated easily: >> >> import math >> >> math.pi=0 >> >> print (math.pi) >> >> In Python, presumably 'pi' is just another variable, and variables can >> be written to. >> >> (Perhaps math.pi would be better off as a function.) > > Still nothing stops you from doing: > > math.sin = 0 > > If you really want to? Well, you might notice something is wrong when you try and do math.sin(x)! But I see your point. Even a function can be set to another function, or to one that returns a nonsense value. Is there no way then in Python to declare: pi = 3.141519 # etc and make it impossible to override? -- Bartc From rosuav at gmail.com Fri Nov 6 14:40:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Nov 2015 06:40:38 +1100 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: On Sat, Nov 7, 2015 at 6:30 AM, Bartc wrote: > Is there no way then in Python to declare: > > pi = 3.141519 # etc > > and make it impossible to override? Nope. Even in C++, where classes can define certain things as const, private, and other such restrictions, you can always get around them by manipulating pointers appropriately. In Python, there's a *convention* that a leading underscore means "private", but the language doesn't enforce anything about it. ChrisA From rurpy at yahoo.com Fri Nov 6 14:52:33 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 6 Nov 2015 11:52:33 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> <563abdda$0$1614$c3e8da3$5496439d@news.astraweb.com> <2fd7d161-b1cb-4274-b8dc-0157916413f1@googlegroups.com> Message-ID: On 11/05/2015 01:18 AM, Christian Gollwitzer wrote: > Am 05.11.15 um 06:59 schrieb rurpy: >>> Can you call yourself a well-rounded programmer without at least >>> a basic understanding of some regex library? Well, probably not. >>> But that's part of the problem with regexes. They have, to some >>> degree, driven out potentially better -- or at least differently >>> bad -- pattern matching solutions, such as (E)BNF grammars, >>> SNOBOL pattern matching, or lowly globbing patterns. Or even >>> alternative idioms, like Hypercard's "chunking" idioms. >> >> Hmm, very good point. I wonder why all those "potentially better" >> solutions have not been more widely adopted? A conspiracy by a >> secret regex cabal? > > I'm mostly on the pro-side of the regex discussion, but this IS a > valid point. regexes are not always a good way to express a pattern, > even if the pattern is regular. The point is, that you can't build > them up easily piece-by-piece. Say, you want a regex like "first an > international phone number, then a name, then a second phone number" > - you will have to *repeat* the pattern for phone number twice. In > more complex cases this can become a nightmare, like the monster that > was mentioned before to validate an email. > > A better alternative, then, is PEG for example. You can easily write > [...] That is the solution adopted by Perl 6. I have always thought lexing and parsing solutions for Python were a weak spot in the Python eco- system and I was about to write that I would love to see a PEG parser for python when I saw this: http://fdik.org/pyPEG/ Unfortunately it suffers from the same problem that Pyparsing, Ply and the rest suffer from: they use Python syntax to express the parsing rules rather than using a dedicated problem-specific syntax such as you used to illustrate peg parsing: > pattern <- phone_number name phone_number phone_number <- '+' [0-9]+ > ( '-' [0-9]+ )* name <- [[:alpha:]]+ Some here have complained about excessive brevity of regexs but I much prefer using problem-specific syntax like "(a*)" to having to express a pattern using python with something like star = RegexMatchAny() a_group = RegexGroup('a' + star) ... and I don't want to have to do something similar with PEG (or Ply or Pyparsing) to formulate their rules. >[...] > As a 12 year old, not knowing anything about pattern recognition, but > thinking I was the king, as is usual for boys in that age, I sat down > and manually constructed a recursive descent parser in a BASIC like > language. It had 1000 lines and took me a few weeks to get it > correct. Finally the solution was accepted as working, but my > participation was rejected because the solutions lacked > documentation. 16 years later I used the problem for a course on > string processing (that's what the PDF is for), and asked the > students to solve it using regexes. My own solution consists of 67 > characters, and it took me5 minutes to write it down. > > Admittedly, this problem is constructed, but solving similar tasks by > regexes is still something that I need to do on a daily basis, when I > get data from other scientists in odd formats and I need to > preprocess them. I know people who use a spreadsheet and copy/paste > millions of datapoints manually becasue they lack the knowledge of > using such tools. I think in many cases those most hostile to regexes are the also those who use them (or need to use them) the least. While my use of regexes are limited to fairly simple ones they are complicated enough that I'm sure it would take orders of magnitude longer to get the same effect in python. From jana1972 at centrum.cz Fri Nov 6 14:55:34 2015 From: jana1972 at centrum.cz (Jahn) Date: Fri, 06 Nov 2015 20:55:34 +0100 Subject: PIL module for 64bit Python 2.7 Message-ID: <563D05B6.18050.1A20E27@jana1972.centrum.cz> Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ? I found for 32 bit Python 2.7 only and the installation ended with an error that the Python 2.7 was not found in registers. Thank you --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From auriocus at gmx.de Fri Nov 6 14:59:57 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 6 Nov 2015 20:59:57 +0100 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: Am 06.11.15 um 20:40 schrieb Chris Angelico: > On Sat, Nov 7, 2015 at 6:30 AM, Bartc wrote: >> Is there no way then in Python to declare: >> >> pi = 3.141519 # etc >> >> and make it impossible to override? > > Nope. Even in C++, where classes can define certain things as const, > private, and other such restrictions, you can always get around them > by manipulating pointers appropriately. No, that is not right. If you cast away the constness from a pointer to a constant, you can technically write to that memory, but the behaviour is undefined - another way of saying that the program is illegal. In many cases, the compiler will inline the constant - because you promised, that it can't change - and the update to the constant will not change in all parts of the program: apfelkiste:Tests chris$ cat constub.cpp #include void call_by_ref(const double &v) { std::cout<<"In function: v="<(&pi); *errptr= 0.0; std::cout<<"Now pi is "< References: <563D05B6.18050.1A20E27@jana1972.centrum.cz> Message-ID: <78DD98F8-C454-48D1-8F6C-9F4BC48BB132@wirtel.be> You can install Pillow, the API is the same. and normally will compile for your architecture. On 6 Nov 2015, at 14:55, Jahn wrote: > Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ? > I found for 32 bit Python 2.7 only and the installation ended with an error that the > Python 2.7 was not found in registers. > Thank you > > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > -- > https://mail.python.org/mailman/listinfo/python-list -- St?phane Wirtel - http://wirtel.be - @matrixise -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From kliateni at gmail.com Fri Nov 6 15:34:42 2015 From: kliateni at gmail.com (Karim) Date: Fri, 6 Nov 2015 21:34:42 +0100 Subject: Olivier Adret In-Reply-To: References: <563B74B6.80402@gmail.com> Message-ID: <563D0EE2.4060207@gmail.com> On 06/11/2015 11:34, Chris Angelico wrote: > On Fri, Nov 6, 2015 at 2:24 AM, olivier wrote: >> Je vais essayer de programmer en python. On verra bien ! > Hello Olivier! > > This is a mostly English language mailing list/newsgroup, and there > aren't many people who are fluent in French. There is, however, a > corresponding French newsgroup, fr.comp.lang.python; you may find that > you're more comfortable communicating there. > > My apologies for not responding in French, but I'm not very familiar > with it, and all I would do is put my text through an online > translation tool. > > Chris Angelico Comme dit Chris, cette mailing liste est en anglais et tu peux aller sur le news group fr.comp.lang.python pour du support en fran?ais. Mais je suppose que tu avais compris mais au cas o?. Cordialement Karim From auriocus at gmx.de Fri Nov 6 15:36:26 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 6 Nov 2015 21:36:26 +0100 Subject: Regular expressions In-Reply-To: References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> <563abdda$0$1614$c3e8da3$5496439d@news.astraweb.com> <2fd7d161-b1cb-4274-b8dc-0157916413f1@googlegroups.com> Message-ID: Am 06.11.15 um 20:52 schrieb rurpy at yahoo.com: > I have always thought lexing > and parsing solutions for Python were a weak spot in the Python eco- > system and I was about to write that I would love to see a PEG parser > for python when I saw this: > > http://fdik.org/pyPEG/ > > Unfortunately it suffers from the same problem that Pyparsing, Ply > and the rest suffer from: they use Python syntax to express the > parsing rules rather than using a dedicated problem-specific syntax > such as you used to illustrate peg parsing: > >> pattern <- phone_number name phone_number >> phone_number <- '+' [0-9]+ ( '-' [0-9]+ )* >> name <- [[:alpha:]]+ That is actually real syntax of a parser generator used by me for another language (Tcl). A calculator example using this package can be found here: http://wiki.tcl.tk/39011 (actually it is a retargetable compiler in a few lines - very impressive) And exactly as you say, it is working well exactly because it doesn't try to abuse function composition in the frontend to construct the parser. Looking through the parser generators listed at http://bford.info/packrat/ it seems that waxeye could be interesting http://waxeye.org/manual.html#_using_waxeye - however I'm not sure the Python backend works with Python 3, maybe there will be unicode issues. Another bonus would be a compilable backend, like Cython or similar. The pt package mentioned above allows to generate a C module with an interface for Tcl. Compiled parsers are approximately 100x faster. I would expect a similar speedup for Python parsers. > Some here have complained about excessive brevity of regexs but I > much prefer using problem-specific syntax like "(a*)" to having to > express a pattern using python with something like > > star = RegexMatchAny() > a_group = RegexGroup('a' + star) > ... Yeah that is nonsense. Mechanical verbosity never leads to clarity (XML anyone?) > I think in many cases those most hostile to regexes are the also > those who use them (or need to use them) the least. While my use > of regexes are limited to fairly simple ones they are complicated > enough that I'm sure it would take orders of magnitude longer > to get the same effect in python. That's also my impression. The "two problems quote" was lame already for the first time. If you are satisfied with simple string functions, then either you do not have problems where you need regexps/other formal parsing tools, or you are very masochistic. Christian From larry.martell at gmail.com Fri Nov 6 15:42:47 2015 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 6 Nov 2015 15:42:47 -0500 Subject: Regular expressions In-Reply-To: References: <56397a18$0$11094$c3e8da3@news.astraweb.com> <56397FC6.9040700@gmail.com> <3f3l3bpm478nbnsec6c9tr6rre0aontkq1@4ax.com> <5e15df62-00b1-4746-83f8-c0821514d20b@googlegroups.com> <563abdda$0$1614$c3e8da3$5496439d@news.astraweb.com> <2fd7d161-b1cb-4274-b8dc-0157916413f1@googlegroups.com> Message-ID: On Fri, Nov 6, 2015 at 3:36 PM, Christian Gollwitzer wrote: > Am 06.11.15 um 20:52 schrieb rurpy at yahoo.com: >> >> I have always thought lexing >> and parsing solutions for Python were a weak spot in the Python eco- >> system and I was about to write that I would love to see a PEG parser >> for python when I saw this: >> >> http://fdik.org/pyPEG/ >> >> Unfortunately it suffers from the same problem that Pyparsing, Ply >> and the rest suffer from: they use Python syntax to express the >> parsing rules rather than using a dedicated problem-specific syntax >> such as you used to illustrate peg parsing: >> >>> pattern <- phone_number name phone_number > >>> phone_number <- '+' [0-9]+ ( '-' [0-9]+ )* >>> name <- [[:alpha:]]+ > > That is actually real syntax of a parser generator used by me for another > language (Tcl). A calculator example using this package can be found here: > http://wiki.tcl.tk/39011 > (actually it is a retargetable compiler in a few lines - very impressive) Ah, Tcl - I wrote many a Tcl script back in the 80s to login to BBSs. From rurpy at yahoo.com Fri Nov 6 15:46:25 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 6 Nov 2015 12:46:25 -0800 (PST) Subject: Regular expressions In-Reply-To: References: <56398006$0$11100$c3e8da3@news.astraweb.com> <1i3l3b9836hatsuoopak5gtg2c38g49kb1@4ax.com> <563aa8be$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, November 5, 2015 at 8:12:22 AM UTC-7, Seymore4Head wrote: > On Thu, 05 Nov 2015 11:54:20 +1100, Steven D'Aprano wrote: > >On Thu, 5 Nov 2015 10:02 am, Seymore4Head wrote: > >> So far the only use I have for regex is to replace slicing, but I > >> think it is an improvement. > > > >I don't understand this. This is like saying "so far the only use I have for > >a sandwich press is to replace my coffee pot". Regular expressions and > >slicing do very different things. > >[...] > > Here is an example of the text we are slicing apart. > >[...email headers...] > > The practice problems are something like pull out all the email > addresses or pull out the days of the week and give the most common. Yes, that is a perfectly appropriate use of regexes. As Steven mentioned though, the term "slicing" is also used with a very specific and different meaning in Python, specifically referring to a part of a list using a syntax like "alist[a:b]". I can't seem to get to python.org at the moment but if you look in the Python docs index under "slicing" you'll find more info. From RobinsW1 at sutterhealth.org Fri Nov 6 16:36:00 2015 From: RobinsW1 at sutterhealth.org (Robinson, Wendy) Date: Fri, 6 Nov 2015 13:36:00 -0800 Subject: Puzzled In-Reply-To: <563CADCD.8070307@gonnerman.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> <563CADCD.8070307@gonnerman.org> Message-ID: <4CFEDC132D44AC49BA0E91FBEB947119084AAD2A1E@DCBL123VX.root.sutterhealth.org> Ah, ok.... I get it now. Thanks both! Wendy Robinson Audit Analyst -----Original Message----- From: Chris Gonnerman [mailto:chris at gonnerman.org] Sent: Friday, November 06, 2015 5:40 AM To: python-list at python.org Cc: Robinson, Wendy Subject: Re: Puzzled Wendy said: > I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic programs successfully. > This morning I rebooted my computer and can't get a single one to work. The interpreter seems to be fine and the environment variables look correct. But every py file I try to run at the >>> prompt gives me a NameError. But that's not how the Python interpreter works. You say you are trying to run "py files" at the >>> prompt. If what you are doing is this: >>> test.py Well, no, that's not going to work. If you want to run "test.py" as a script, from the CMD prompt you type: python test.py If test.py is a module meant to be imported, then from the Python prompt you do this: import test Hope this helps. -- Chris. From lac at openend.se Fri Nov 6 16:37:58 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 06 Nov 2015 22:37:58 +0100 Subject: PIL module for 64bit Python 2.7 In-Reply-To: <563D05B6.18050.1A20E27@jana1972.centrum.cz> References: <563D05B6.18050.1A20E27@jana1972.centrum.cz> Message-ID: <201511062137.tA6LbwcY027485@fido.openend.se> In a message of Fri, 06 Nov 2015 20:55:34 +0100, "Jahn" writes: >Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ? > I found for 32 bit Python 2.7 only and the installation ended with an error that the >Python 2.7 was not found in registers. >Thank you The Modern Fork of PIL is Pillow. hhttps://pypi.python.org/pypi/Pillow/3.0.0 Laura From stephane at wirtel.be Fri Nov 6 16:40:49 2015 From: stephane at wirtel.be (=?utf-8?q?St=C3=A9phane?= Wirtel) Date: Fri, 06 Nov 2015 16:40:49 -0500 Subject: PIL module for 64bit Python 2.7 In-Reply-To: <201511062137.tA6LbwcY027485@fido.openend.se> References: <563D05B6.18050.1A20E27@jana1972.centrum.cz> <201511062137.tA6LbwcY027485@fido.openend.se> Message-ID: <4D43805F-873A-4D8C-9507-3B63B5CD3FF3@wirtel.be> Really strange, I have sent the same answer, there is one hour. Did you receive it ? I am not but maybe I have a problem with my email. On 6 Nov 2015, at 16:37, Laura Creighton wrote: > In a message of Fri, 06 Nov 2015 20:55:34 +0100, "Jahn" writes: >> Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ? >> I found for 32 bit Python 2.7 only and the installation ended with an error that the >> Python 2.7 was not found in registers. >> Thank you > > The Modern Fork of PIL is Pillow. > hhttps://pypi.python.org/pypi/Pillow/3.0.0 > > Laura > > -- > https://mail.python.org/mailman/listinfo/python-list -- St?phane Wirtel - http://wirtel.be - @matrixise -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From random832 at fastmail.com Fri Nov 6 16:56:50 2015 From: random832 at fastmail.com (Random832) Date: Fri, 06 Nov 2015 16:56:50 -0500 Subject: argparse: use of double dash to separate options and positional arguments References: <20151106100743.GN3685@isis.luna> Message-ID: <87vb9eeqql.fsf@fastmail.com> Peter Otten <__peter__ at web.de> writes: > I'm not sure about this one; one purpose of REMAINDER is to pass on the > unprocessed arguments to another program/script, and this might follow the > same convention. Should > > parser.add_argument('-v', '--verbose', action='store_true') > parser.add_argument('cmd_args', nargs=argparse.REMAINDER) > args = parser.parse_args() > subprocess.call(["rm"] + args.cmd_args) > > $ my_prog -v -- -r foo > > attempt to delete two files "-r" and "foo" or remove the "foo" directory? > The first is the safer alternative, and as you say stripping the "--" is > easy. I think it should be the second. If the caller wants it to be treated as a list of files rather than a list of arguments, it should be using subprocess.call(["rm", "--"] + args.cmd_args). The purpose is, as you said, to pass the *unprocessed* argument. -- has been processed by being interpreted as a terminator for the argument list. I have a script (it's a shell script, not a python script) where I actually do something similar... it does some setup, then calls ssh. If I want to pass some options directly to ssh, I call it as: "scriptname -script-option -- -ssh-option remote-command" From abhishek.mallela at gmail.com Fri Nov 6 17:01:08 2015 From: abhishek.mallela at gmail.com (Abhishek) Date: Fri, 6 Nov 2015 14:01:08 -0800 (PST) Subject: Scipy odeint (LSODA) gives inaccurate results; same code fine in MATLAB ode15s/ode23s Message-ID: <942d2bd0-6322-4733-a6dd-ceeed40368cb@googlegroups.com> I have code that runs perfectly well in MATLAB (using ode15s or ode23s) but falters with Scipy odeint. The MATLAB code is for a specific case of the generalized Python code. Here I have tried to reproduce the specific case in Python. The logic in the code is airtight and the algorithm is sound. I have also specified small rtol and atol values, as well as a large mxstep. My code is below: import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint #Constants and parameters N = 2 K00 = np.logspace(0,3,101,10) len1 = len(K00) epsilon = 0.01 y0 = [0]*(3*N/2+3) u1 = 0 u2 = 0 u3 = 0 Kplot = np.zeros((len1,1)) Pplot = np.zeros((len1,1)) S = [np.zeros((len1,1)) for kkkk in range(N/2+1)] KS = [np.zeros((len1,1)) for kkkk in range(N/2+1)] PS = [np.zeros((len1,1)) for kkkk in range(N/2+1)] Splot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] KSplot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] PSplot = [np.zeros((len1,1)) for kkkk in range(N/2+1)] for series in range(0,len1): K0 = K00[series] Q = 10 r1 = 0.0001 r2 = 0.001 a = 0.001 d = 0.001 k = 0.999 S10 = 1e5 P0 = 1 tfvec = np.tile(1e10,(1,5)) tf = tfvec[0,0] time = np.linspace(0,tf,len1) #Defining dy/dt's def f(y,t): for alpha in range(0,(N/2+1)): S[alpha] = y[alpha] for beta in range((N/2)+1,N+1): KS[beta-N/2-1] = y[beta] for gamma in range(N+1,3*N/2+1): PS[gamma-N] = y[gamma] K = y[3*N/2+1] P = y[3*N/2+2] # The model equations ydot = np.zeros((3*N/2+3,1)) B = range((N/2)+1,N+1) G = range(N+1,3*N/2+1) runsumPS = 0 runsum1 = 0 runsumKS = 0 runsum2 = 0 for m in range(0,N/2): runsumPS = runsumPS + PS[m+1] runsum1 = runsum1 + S[m+1] runsumKS = runsumKS + KS[m] runsum2 = runsum2 + S[m] ydot[B[m]] = a*K*S[m]-(d+k+r1)*KS[m] for i in range(0,N/2-1): ydot[G[i]] = a*P*S[i+1]-(d+k+r1)*PS[i+1] for p in range(1,N/2): ydot[p] = -S[p]*(r1+a*K+a*P)+k*KS[p-1]+ \ d*(PS[p]+KS[p]) ydot[0] = Q-(r1+a*K)*S[0]+d*KS[0]+k*runsumPS ydot[N/2] = k*KS[N/2-1]-(r2+a*P)*S[N/2]+ \ d*PS[N/2] ydot[G[N/2-1]] = a*P*S[N/2]-(d+k+r2)*PS[N/2] ydot[3*N/2+1] = (d+k+r1)*runsumKS-a*K*runsum2 ydot[3*N/2+2] = (d+k+r1)*(runsumPS-PS[N/2])- \ a*P*runsum1+(d+k+r2)*PS[N/2] ydot_new = [] for j in range(0,3*N/2+3): ydot_new.extend(ydot[j]) return ydot_new # Initial conditions y0[0] = S10 for i in range(1,3*N/2+1): y0[i] = 0 y0[3*N/2+1] = K0 y0[3*N/2+2] = P0 # Solve the DEs soln = odeint(f,y0,time,rtol = 1e-12, atol = 1e-14, mxstep = 50000000) for alpha in range(0,(N/2+1)): S[alpha] = soln[:,alpha] for beta in range((N/2)+1,N+1): KS[beta-N/2-1] = soln[:,beta] for gamma in range(N+1,3*N/2+1): PS[gamma-N] = soln[:,gamma] for alpha in range(0,(N/2+1)): Splot[alpha][series] = soln[len1-1,alpha] for beta in range((N/2)+1,N+1): KSplot[beta-N/2-1][series] = soln[len1-1,beta] for gamma in range(N+1,3*N/2+1): PSplot[gamma-N][series] = soln[len1-1,gamma] for alpha in range(0,(N/2+1)): u1 = u1 + Splot[alpha] for beta in range((N/2)+1,N+1): u2 = u2 + KSplot[beta-N/2-1] for gamma in range(N+1,3*N/2+1): u3 = u3 + PSplot[gamma-N] K = soln[:,3*N/2+1] P = soln[:,3*N/2+2] Kplot[series] = soln[len1-1,3*N/2+1] Pplot[series] = soln[len1-1,3*N/2+2] utot = u1+u2+u3 #Plot plt.plot(np.log10(K00),utot[:,0]) plt.show() Why am I getting a "stiff-looking" graph in Python (http://i.stack.imgur.com/UGWSH.png), when MATLAB gives me a proper one (http://i.stack.imgur.com/F2jzd.jpg)? I would like to understand where the problem lies and how to solve it. Thanks in advance for any help. From PointedEars at web.de Fri Nov 6 17:19:42 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 06 Nov 2015 23:19:42 +0100 Subject: Question about math.pi is mutable References: Message-ID: <1521937.lCYGF7V2BE@PointedEars.de> Chris Angelico wrote: > On Sat, Nov 7, 2015 at 6:30 AM, Bartc wrote: >> Is there no way then in Python to declare: >> >> pi = 3.141519 # etc >> >> and make it impossible to override? > > Nope. Even in C++, where classes can define certain things as const, > private, and other such restrictions, you can always get around them > by manipulating pointers appropriately. In Python, there's a > *convention* that a leading underscore means "private", but the > language doesn't enforce anything about it. It is certainly possible for attributes of (instances of) new-style classes (starting with Python 3.2 at the latest) to be read-only by declaring them a property that does not have a setter, or one that has a setter that throws a specific exception (here: the former): #-------------------------- class SafeMath(object): def __init__ (self): from math import pi self._pi = pi @property def pi (self): return self._pi #-------------------------- | >>> math = SafeMath() | >>> math.pi | 3.141592653589793 | >>> math.pi = 42 | Traceback (most recent call last): | File "", line 1, in | AttributeError: can't set attribute (Or you can use ?pi = property(?)? within the class declaration.) In theory, it should be possible to substitute ?math? with a reference to an object that acts as a proxy for the original ?math? module object but whose base class declares the attributes for all the constants read-only. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Fri Nov 6 17:26:49 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 06 Nov 2015 23:26:49 +0100 Subject: Question about math.pi is mutable References: Message-ID: <1590467.kktH0DaBsW@PointedEars.de> Bartc wrote: ^^^^^ Please fix. > On 06/11/2015 02:33, wangq at travelsky.com wrote: >> As you can see in the attachment, why i can modify "math.pi"? >> (in "mathmodule.c" "pi" is a "static const double") > > Python isn't C. > > Your attachment isn't visible, but it can be demonstrated easily: > > import math > > math.pi=0 > > print (math.pi) > > In Python, presumably 'pi' is just another variable, and variables can > be written to. ?pi? is the name of an attribute of the module object referred to by ?math?. > (Perhaps math.pi would be better off as a function.) Perhaps not. Calling a function includes an overhead that one does not want in already costly floating-point calculations. In my opinion, mathematical constants should be implemented as constants (non-overwritable, non-deletable, throwing exceptions when attempting to do either) but apparently the authors of math.py disagree. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From scott.werner.vt at gmail.com Fri Nov 6 17:29:57 2015 From: scott.werner.vt at gmail.com (Scott Werner) Date: Fri, 6 Nov 2015 14:29:57 -0800 (PST) Subject: Script to extract text from PDF files In-Reply-To: References: Message-ID: On Tuesday, September 25, 2007 at 1:41:56 PM UTC-4, brad wrote: > I have a very crude Python script that extracts text from some (and I > emphasize some) PDF documents. On many PDF docs, I cannot extract text, > but this is because I'm doing something wrong. The PDF spec is large and > complex and there are various ways in which to store and encode text. I > wanted to post here and ask if anyone is interested in helping make the > script better which means it should accurately extract text from most > any pdf file... not just some. > > I know the topic of reading/extracting the text from a PDF document > natively in Python comes up every now and then on comp.lang.python... > I've posted about it in the past myself. After searching for other > solutions, I've resorted to attempting this on my own in my spare time. > Using apps external to Python (pdftotext, etc.) is not really an option > for me. If someone knows of a free native Python app that does this now, > let me know and I'll use that instead! > > So, if other more experienced programmer are interested in helping make > the script better, please let me know. I can host a website and the > latest revision and do all of the grunt work. > > Thanks, > > Brad As mentioned before, extracting plain text from a PDF document can be hit or miss. I have tried all the following applications (free/open source) on Arch Linux. Note, I would execute the commands with subprocess and capture stdout or read plain text file created by the application. * textract (uses pdftotext) - https://github.com/deanmalmgren/textract * pdftotext - http://poppler.freedesktop.org/ - cmd: pdftotext -layout "/path/to/document.pdf" - - cmd: pdftotext "/path/to/document.pdf" - * Calibre - http://calibre-ebook.com/ - cmd: ebook-convert "/path/to/document.pdf" "/path/to/plain.txt" --no-chapters-in-toc * AbiWord - http://www.abiword.org/ - cmd: abiword --to-name=fd://1 --to-TXT "/path/to/document.pdf" * Apache Tika - https://tika.apache.org/ - cmd: "/usr/bin/java" -jar "/path/to/standalone/tika-app-1.10.jar" --text-main "/path/to/document.pdf" For my application, I saw the best results using Apache Tika. However, I do still encounter strange encoding or extraction issues, e.g. S P A C E D O U T H E A D E R S" and "\nBroken \nHeader\n". I ended up writing a lot of repairing/cleaning methods. I welcome an improved solution that has some intelligence like comparing the extract plain text order to a snapshot of the pdf page using OCR. From D.Strohl at F5.com Fri Nov 6 17:46:01 2015 From: D.Strohl at F5.com (Dan Strohl) Date: Fri, 6 Nov 2015 22:46:01 +0000 Subject: Script to extract text from PDF files In-Reply-To: References: Message-ID: <40c22d28dbb546a6959fae9129493bfa@seaexchmbx03.olympus.F5Net.com> Its possible (likely) that I came into this in the middle, so sorry if this was already thrown out... but have you looked at any of the following suggestions? https://pypi.python.org/pypi?%3Aaction=search&term=pdf+convert&submit=search http://stackoverflow.com/questions/6413441/python-pdf-library https://www.binpress.com/tutorial/manipulating-pdfs-with-python/167 -----Original Message----- From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] On Behalf Of Scott Werner Sent: Friday, November 06, 2015 2:30 PM To: python-list at python.org Subject: Re: Script to extract text from PDF files On Tuesday, September 25, 2007 at 1:41:56 PM UTC-4, brad wrote: > I have a very crude Python script that extracts text from some (and I > emphasize some) PDF documents. On many PDF docs, I cannot extract > text, but this is because I'm doing something wrong. The PDF spec is > large and complex and there are various ways in which to store and > encode text. I wanted to post here and ask if anyone is interested in > helping make the script better which means it should accurately > extract text from most any pdf file... not just some. > > I know the topic of reading/extracting the text from a PDF document > natively in Python comes up every now and then on comp.lang.python... > I've posted about it in the past myself. After searching for other > solutions, I've resorted to attempting this on my own in my spare time. > Using apps external to Python (pdftotext, etc.) is not really an > option for me. If someone knows of a free native Python app that does > this now, let me know and I'll use that instead! > > So, if other more experienced programmer are interested in helping > make the script better, please let me know. I can host a website and > the latest revision and do all of the grunt work. > > Thanks, > > Brad As mentioned before, extracting plain text from a PDF document can be hit or miss. I have tried all the following applications (free/open source) on Arch Linux. Note, I would execute the commands with subprocess and capture stdout or read plain text file created by the application. * textract (uses pdftotext) - https://github.com/deanmalmgren/textract * pdftotext - http://poppler.freedesktop.org/ - cmd: pdftotext -layout "/path/to/document.pdf" - - cmd: pdftotext "/path/to/document.pdf" - * Calibre - http://calibre-ebook.com/ - cmd: ebook-convert "/path/to/document.pdf" "/path/to/plain.txt" --no-chapters-in-toc * AbiWord - http://www.abiword.org/ - cmd: abiword --to-name=fd://1 --to-TXT "/path/to/document.pdf" * Apache Tika - https://tika.apache.org/ - cmd: "/usr/bin/java" -jar "/path/to/standalone/tika-app-1.10.jar" --text-main "/path/to/document.pdf" For my application, I saw the best results using Apache Tika. However, I do still encounter strange encoding or extraction issues, e.g. S P A C E D O U T H E A D E R S" and "\nBroken \nHeader\n". I ended up writing a lot of repairing/cleaning methods. I welcome an improved solution that has some intelligence like comparing the extract plain text order to a snapshot of the pdf page using OCR. -- https://mail.python.org/mailman/listinfo/python-list From PointedEars at web.de Fri Nov 6 18:48:40 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 07 Nov 2015 00:48:40 +0100 Subject: Question about math.pi is mutable References: <1521937.lCYGF7V2BE@PointedEars.de> Message-ID: <11393078.50naPz65Nn@PointedEars.de> Thomas 'PointedEars' Lahn wrote: > In theory, it should be possible to substitute ?math? with a reference to > an object that acts as a proxy for the original ?math? module object but > whose base class declares the attributes for all the constants read-only. #!/usr/bin/env python3 #--------------------------------------------------------------------------- import importlib class MyMath(object): def getter_factory (prop): def getter (self): return getattr(importlib.__import__("math", globals(), locals(), [prop], 0), prop) return getter pi = property(getter_factory("pi"), lambda self, val: None, lambda self: None) e = property(getter_factory("e"), lambda self, val: None, lambda self: None) inf = property(getter_factory("inf"), lambda self, val: None, lambda self: None) nan = property(getter_factory("nan"), lambda self, val: None, lambda self: None) def __getattr__ (self, name): return getattr(importlib.__import__("math", globals(), locals(), [name], 0), name, None) math = MyMath() print(math.pi, math.e, math.inf, math.nan) math.pi = 42 math.e = 42 math.inf = 42 math.nan = 42 print(math.pi, math.e, math.inf, math.nan) print(math.ceil(2.41)) #--------------------------------------------------------------------------- Using property() instead of decorators here was intended to achieve DRY by using a loop, but I could not find a way to define class attributes dynamically. Suggestions? -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From tjreedy at udel.edu Fri Nov 6 20:49:17 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 6 Nov 2015 20:49:17 -0500 Subject: Question about math.pi is mutable In-Reply-To: <1590467.kktH0DaBsW@PointedEars.de> References: <1590467.kktH0DaBsW@PointedEars.de> Message-ID: On 11/6/2015 5:26 PM, Thomas 'PointedEars' Lahn wrote: > Bartc wrote: >> import math >> >> math.pi=0 >> >> print (math.pi) >> >> In Python, presumably 'pi' is just another variable, and variables can >> be written to. > > ?pi? is the name of an attribute of the module object referred to by ?math?. > >> (Perhaps math.pi would be better off as a function.) > > Perhaps not. Calling a function includes an overhead that one does not want > in already costly floating-point calculations. > > In my opinion, mathematical constants should be implemented as constants > (non-overwritable, non-deletable, throwing exceptions when attempting to do > either) but apparently the authors of math.py disagree. One of multiple discussions of the 'constants' idea. bugs.python.org/issue1465406 It is mostly about speed. -- Terry Jan Reedy From steve at pearwood.info Fri Nov 6 21:00:31 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 07 Nov 2015 13:00:31 +1100 Subject: Question about math.pi is mutable References: <1521937.lCYGF7V2BE@PointedEars.de> Message-ID: <563d5b41$0$1585$c3e8da3$5496439d@news.astraweb.com> On Sat, 7 Nov 2015 09:19 am, Thomas 'PointedEars' Lahn wrote: > It is certainly possible for attributes of (instances of) new-style > classes (starting with Python 3.2 at the latest) to be read-only by > declaring them a property that does not have a setter, or one that has a > setter that throws a specific exception (here: the former): > > #-------------------------- > class SafeMath(object): > def __init__ (self): > from math import pi > self._pi = pi > > @property > def pi (self): > return self._pi The obvious problem with that is that it is trivially easy for the coder to set self._pi to change the value of self.pi. Here's a version that at first seems promising: py> def builder(): ... from math import pi as PI ... def pi(self): ... return PI ... return pi ... py> class MathLib(object): ... pi = property(builder()) ... py> mathlib = MathLib() py> mathlib.pi 3.141592653589793 py> mathlib.pi = 3.12 Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute There's no _pi accessible that somebody might change. If you dig into the property object itself, you eventually get to the cell object containing the value for pi: py> MathLib.pi.fget.__closure__[0] but there doesn't appear to be any way to manipulate the cell internals to change the value. But you don't need to: py> MathLib.pi = property(lambda self: 4.2) py> mathlib.pi 4.2 A determined coder can change nearly anything done in pure Python code. *Personally*, I too would like Python to have some equivalent of (say) Pascal `const`, names which cannot be rebound once assigned to the first time. Not to prevent determined coders from changing things, but to avoid *accidental* changes done in error. -- Steven From steve at pearwood.info Fri Nov 6 21:06:07 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 07 Nov 2015 13:06:07 +1100 Subject: Question about math.pi is mutable References: <1590467.kktH0DaBsW@PointedEars.de> Message-ID: <563d5c90$0$1599$c3e8da3$5496439d@news.astraweb.com> On Sat, 7 Nov 2015 09:26 am, Thomas 'PointedEars' Lahn wrote: ....................................^^^^^^^^^^^^^ > Bartc wrote: > ^^^^^ > Please fix. Why? There's nothing wrong with somebody signing their posts "Bartc". It is no more silly than somebody calling themselves "PointedEars". Please stop trying to enforce non-existent rules about internet identities on others. -- Steven From orgnut at yahoo.com Fri Nov 6 22:21:32 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 6 Nov 2015 19:21:32 -0800 Subject: =?UTF-8?B?UmU6IFdoYXQgZG9lcyDigJxncmVw4oCdIHN0YW5kIGZvcj8=?= In-Reply-To: References: <56397a18$0$11094$c3e8da3@news.astraweb.com> Message-ID: On 11/06/2015 05:25 AM, William Ray Wing wrote: > >> On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list wrote: >> [snip] > You?re not REALLY an old timer unless you?ve used TECO. > > -Bill > Agreed. I'm not really and old-timer, just old (I'm 78). My first exposure to computers was the MITS Altair, (around late '75) and my computer use has always been hobby-oriented, never professional. I only know of TECO by reputation, not experience. :-) -=- Larry -=- From ben+python at benfinney.id.au Fri Nov 6 22:43:44 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 07 Nov 2015 14:43:44 +1100 Subject: Question about math.pi is mutable References: Message-ID: <857flujwy7.fsf@benfinney.id.au> Bartc writes: > Is there no way then in Python to declare: > > pi = 3.141519 # etc > > and make it impossible to override? No, and it would be a bad thing if that were something a library author could forbid. Python assumes the programmers using it are consenting adults. Doing harmful things is difficult but not forbidden. Notably, the author of a library should not be forbidding the Pythonic ability to change name bindings as needed. If you want to have a different value bound to the name ?math.pi?, and you go ahead and explicitly ask to change that binding, the library author has no business forbidding that. -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From baruchel at no.spam.gmx.dot.com Sat Nov 7 01:53:27 2015 From: baruchel at no.spam.gmx.dot.com (Th. Baruchel) Date: 07 Nov 2015 06:53:27 GMT Subject: Version 1.1 of the tco module (tail-calls, recursion, call/cc) Message-ID: <563d9fe7$0$3054$426a74cc@news.free.fr> The version 1.1 of the tco module is released. It is much more owerful since it now allows nested systems of continuations. The most important is probably rather that I took the time to write a very detailed presentation of the module on my blog: http://baruchel.github.io/ Regards, tb. From auriocus at gmx.de Sat Nov 7 01:54:48 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 7 Nov 2015 07:54:48 +0100 Subject: Scipy odeint (LSODA) gives inaccurate results; same code fine in MATLAB ode15s/ode23s In-Reply-To: <942d2bd0-6322-4733-a6dd-ceeed40368cb@googlegroups.com> References: <942d2bd0-6322-4733-a6dd-ceeed40368cb@googlegroups.com> Message-ID: Am 06.11.15 um 23:01 schrieb Abhishek: > I have code that runs perfectly well in MATLAB (using ode15s or > ode23s) but falters with Scipy odeint. The MATLAB code is for a > specific case of the generalized Python code. Here I have tried to > reproduce the specific case in Python. The logic in the code is > airtight and the algorithm is sound. I have also specified small rtol > and atol values, as well as a large mxstep. > > My code is below: > > [...Python code...] > > Why am I getting a "stiff-looking" graph in Python What does "stiff-looking" mean? I only know stiff differential equations, but this leads to noisy results. Your plots are smooth. > (http://i.stack.imgur.com/UGWSH.png), when MATLAB gives me a proper > one (http://i.stack.imgur.com/F2jzd.jpg)? I would like to understand > where the problem lies and how to solve it. It is very hard to analyze such a problem, unless you also post the Matlab code and plot both solutions into a single graph. What I can see at first is that the initial conditions can't be the same. Your Python graph starts around 10^7, while the Matlab graph starts at 10^5. WHat happens if you integrate a simpler system - say does it make sense to set some of the coefficients to zero and if you still get the same difference, can you simplify the program to expose the problem? How do you know that the Matlab code produces the correct answer? Christian From bc at freeuk.com Sat Nov 7 06:23:59 2015 From: bc at freeuk.com (Bartc) Date: Sat, 7 Nov 2015 11:23:59 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: On 07/11/2015 03:43, Ben Finney wrote: > Bartc writes: > >> Is there no way then in Python to declare: >> >> pi = 3.141519 # etc >> >> and make it impossible to override? > > No, and it would be a bad thing if that were something a library author > could forbid. > > Python assumes the programmers using it are consenting adults. Doing > harmful things is difficult but not forbidden. But surely it can't hurt to ensure certain values can't be changed accidentally or maliciously? Some dynamic languages (OK, I'm thinking of mine) simply allow you to write: const pi = 3.14159 Then this can't be changed, because it would be the equivalent of writing: 3.14159 = 0 What would be the harm in this? It's a very simple idea, yet many people and languages either don't like it or can't grasp it. Not even C has the feature, if you don't count using the crude #define for the purpose. In the case of Python, it could have allowed 'constant folding', so that math.pi*2 need not be evaluated at runtime. (Python however does make it quite difficult to add features like this. Mostly because such names are not visible across modules when compiling. Also it is still possible to write math = some_other_module.) -- Bartc From ben+python at benfinney.id.au Sat Nov 7 06:35:05 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 07 Nov 2015 22:35:05 +1100 Subject: Question about math.pi is mutable References: Message-ID: <85y4eahwk6.fsf@benfinney.id.au> Bartc writes: > On 07/11/2015 03:43, Ben Finney wrote: > > Bartc writes: > > > >> Is there no way then in Python to declare: > >> > >> pi = 3.141519 # etc > >> > >> and make it impossible to override? > > > > No, and it would be a bad thing if that were something a library author > > could forbid. > > > > Python assumes the programmers using it are consenting adults. Doing > > harmful things is difficult but not forbidden. > > But surely it can't hurt to ensure certain values can't be changed > accidentally or maliciously? The value ?3.141519? (in your example above) can't be changed. That value will always be exactly the same, as long as the program is running. What I think you mean is ?surely it can't hurt to ensure certain names can never be bound to any value but their initial binding?. On that I strongly disagree, for the reasons already discussed in this thread: it arrogates to the library author the power to forbid patching the library, which cripples extending, debugging, introspection, and a host of other useful activities. -- \ ?I object to doing things that computers can do.? ?Olin Shivers | `\ | _o__) | Ben Finney From bc at freeuk.com Sat Nov 7 06:57:16 2015 From: bc at freeuk.com (Bartc) Date: Sat, 7 Nov 2015 11:57:16 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: On 07/11/2015 11:35, Ben Finney wrote: > Bartc writes: > >> On 07/11/2015 03:43, Ben Finney wrote: >>> Bartc writes: >>> >>>> Is there no way then in Python to declare: >>>> >>>> pi = 3.141519 # etc >>>> >>>> and make it impossible to override? >>> >>> No, and it would be a bad thing if that were something a library author >>> could forbid. >>> >>> Python assumes the programmers using it are consenting adults. Doing >>> harmful things is difficult but not forbidden. >> >> But surely it can't hurt to ensure certain values can't be changed >> accidentally or maliciously? > > The value ?3.141519? (in your example above) can't be changed. That > value will always be exactly the same, as long as the program is > running. > > What I think you mean is ?surely it can't hurt to ensure certain names > can never be bound to any value but their initial binding?. > > On that I strongly disagree, for the reasons already discussed in this > thread: it arrogates to the library author the power to forbid patching > the library, which cripples extending, debugging, introspection, and a > host of other useful activities. Why would it stop introspection? If the source is available, why would it stop anyone extending a library? To my mind, Python allows far too much freedom in being able to change anything at any time. Imagine if the interfaces to Win32 API or to the Linux kernel could be turned upside down from one microsecond to the next, while programs are still running. Take a simple function like thousands of others: def dull(x,y,z); ..... ..... 99.9999% of the time, the name 'dull' is not going to be bound to anything else, and it would just be called like this: dull(10,20,30) Yet Python has to assume 100% of the time that it could have been changed. Think of the opportunities for optimising if the probability was 0%. Perhaps if library authors want people tinkering with their code at runtime, they should mark it as such ('var', 'volatile' etc). Because most of us are quite happy with a boring, static library that is not likely to morph into something else! -- Bartc From ben+python at benfinney.id.au Sat Nov 7 07:15:32 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 07 Nov 2015 23:15:32 +1100 Subject: Question about math.pi is mutable References: Message-ID: <85twoyhuor.fsf@benfinney.id.au> Bartc writes: > To my mind, Python allows far too much freedom in being able to change > anything at any time. You're welcome to that opinion. I don't see you present a reason why it should affect anyone else's opinion of Python, though. > Yet Python has to assume 100% of the time that it could have been > changed. Think of the opportunities for optimising if the probability > was 0%. Such a pity that Python is missing all those opportunities for widespread adoption, by not hewing closer to your preferences. -- \ ?That's the essence of science: Ask an impertinent question, | `\ and you're on the way to the pertinent answer.? ?Jacob | _o__) Bronowski, _The Ascent of Man_, 1973 | Ben Finney From bc at freeuk.com Sat Nov 7 08:00:37 2015 From: bc at freeuk.com (Bartc) Date: Sat, 7 Nov 2015 13:00:37 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: On 07/11/2015 12:15, Ben Finney wrote: > Bartc writes: > >> To my mind, Python allows far too much freedom in being able to change >> anything at any time. > > You're welcome to that opinion. I don't see you present a reason why it > should affect anyone else's opinion of Python, though. Not just my option. From this 2010 paper for example ('High performance implementation of Python for CLI ...' by Antonio Cuni): "As a language, Python is very hard to implement efficiently: the presence of highly dynamic constructs makes static analysis of programs extremely difficult, thus preventing ahead of time (AOT) compilers to generate efficient target code." >> Yet Python has to assume 100% of the time that it could have been >> changed. Think of the opportunities for optimising if the probability >> was 0%. > > Such a pity that Python is missing all those opportunities for > widespread adoption, by not hewing closer to your preferences. Plenty of other people working on faster Pythons appear to have trouble with its being so dynamic. (Earlier this year, I was upgrading my own language to be much more Python-like in its internal workings. But I gave it up because I was losing so many nice features that also made it easy to implement efficiently. As one example of many, named constants (the 'const' feature earlier in the thread), were used for 'switch' statements. Without 'const', then I couldn't have a fast 'switch'.) I suppose my coding style is just different from people who write Python. When I define a function f(), then it's always going to be function f and is never going to change. A call to such a function can therefore be streamlined. If I ever need it to be dynamic, then I use a function pointer: g=f f is still the static function, g is a now a reference to it, and is a little slower to call. But the /vast majority/ of function calls are going to be static. -- Bartc From yueyoum at gmail.com Sat Nov 7 08:23:51 2015 From: yueyoum at gmail.com (yueyoum) Date: Sat, 07 Nov 2015 21:23:51 +0800 Subject: =?US-ASCII?Q?how_to_copy_PyObject_*_memory_d?= =?US-ASCII?Q?ata_to_another_memory_address=3F=0A=0A?= Message-ID: <1446902615952.dslp41enande24vd1gfb0x4r@android.mail.163.com> I'm working on a C program that has Python embedded. The host program is multi processes, which communicate via shared memory (mmap). I create a Python object (e.g., PyDict_New) in one process. How can I copy this data to shared memory so that the other process can obtain this data and convert to Python Object? ???????? From lac at openend.se Sat Nov 7 09:09:35 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 07 Nov 2015 15:09:35 +0100 Subject: Question about math.pi is mutable In-Reply-To: References: Message-ID: <201511071409.tA7E9ZXL005204@fido.openend.se> In a message of Sat, 07 Nov 2015 13:00:37 +0000, Bartc writes: >Not just my option. From this 2010 paper for example ('High performance >implementation of Python for CLI ...' by Antonio Cuni): > >"As a language, Python is very hard to implement efficiently: the >presence of highly dynamic constructs makes static analysis of programs >extremely difficult, thus preventing ahead of time (AOT) compilers to >generate efficient target code." Recall that my friend Anto is discussing 'why my phd thesis was hard stuff, as I did this for PyPy' and not 'Python would be better if it were easier to write fast compilers for it'. :) Anto loves the dynamic nature of python. It just makes pypy hard. Laura From marko at pacujo.net Sat Nov 7 09:23:50 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Nov 2015 16:23:50 +0200 Subject: Question about math.pi is mutable References: Message-ID: <87d1vlzy4p.fsf@elektro.pacujo.net> Bartc : > Not just my option. From this 2010 paper for example ('High performance > implementation of Python for CLI ...' by Antonio Cuni): > > "As a language, Python is very hard to implement efficiently: the > presence of highly dynamic constructs makes static analysis of > programs extremely difficult, thus preventing ahead of time (AOT) > compilers to generate efficient target code." Correct. That's not Python's fault, however. Python should not try to placate the performance computing people. (Alas, it is now trying to do just that with the introduction of static typing annotation.) > Plenty of other people working on faster Pythons appear to have > trouble with its being so dynamic. That's, literally, their problem. > As one example of many, named constants (the 'const' feature earlier > in the thread), were used for 'switch' statements. Without 'const', > then I couldn't have a fast 'switch'.) Fast, fast, fast. We have plenty of fast programming languages. Python should *not* sacrifice its dynamism (which the fast languages don't have) for speed. Python is already fast enough for most programming tasks. In my work, I currently use bash, Python and C. For many, many tasks, bash is superior to Python. For others, Python can't compete with C. Yet the vast gap between bash and C is nicely filled with Python. Those three golf clubs are all I need in my bag. Java, C#, go, C++ have great merits. However, I really don't ever miss them. (The one club I have special sentiments for is Scheme. I don't use it professionally for, though, because its ecosystem is not quite developed enough yet.) > I suppose my coding style is just different from people who write > Python. When I define a function f(), then it's always going to be > function f and is never going to change. A call to such a function can > therefore be streamlined. Your point of view is really down-to-earth. It's slightly analogous to protesting against Unicode because you only ever need ASCII. You would be right in that Python programs hardly ever make use of or directly depend on the degrees of freedom Python affords. They are used every here and there, however, and, most imporantly, they make it possible to define the semantics of the programming language in a sound, concise manner. That way it is easier to implement Python, learn Python and use Python correctly. Imagine there was a national standard that defined that you could only sell hatchets that split wood in a downward movement. You might argue that hardly anyone swung a hatchet sideways, and it would be dangerous anyway. However, that kind of a standard would make it very difficult to manufacture the simple concept of a hatchet. The contraption would be expensive, fragile, heavy and difficult to use even for the intended up-down splitting purpose. I wouldn't like Python to turn into such a contraption. Marko From marko at pacujo.net Sat Nov 7 09:28:31 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Nov 2015 16:28:31 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> Message-ID: <878u69zxww.fsf@elektro.pacujo.net> Marko Rauhamaa : > In my work, I currently use bash, Python and C. For many, many tasks, > bash is superior to Python. For others, Python can't compete with C. > Yet the vast gap between bash and C is nicely filled with Python. And, by the way, the introduction of the "const" keyword was maybe the biggest mistake the C standardizers ever made. It turned out to be about as useful as a mosquito buzzing at your ear, and equally persistent and annoying. Marko From leonardmesiera at gmail.com Sat Nov 7 09:44:51 2015 From: leonardmesiera at gmail.com (leonardmesiera at gmail.com) Date: Sat, 7 Nov 2015 06:44:51 -0800 (PST) Subject: Guide in Deskop Application Development in Python for newbies Message-ID: <436bfe7e-ece3-454d-b0c7-81de0fe82acb@googlegroups.com> How do you start building a desktop application in python? I mean where do I start? Besides installing python on your windows what else do I need, and any suggestion on how do I accomplish this project. Right now I really want to finish this beauty pageant judging system which requires to have a client and a server, client would be for the judges and a server that computes the scores from all the categories, (i do hope you get I want mean by that project). I just finished reading Headfirst Python and I really loving this language, so any help from all the great programmers here would be so great. From bc at freeuk.com Sat Nov 7 10:01:34 2015 From: bc at freeuk.com (Bartc) Date: Sat, 7 Nov 2015 15:01:34 +0000 Subject: Question about math.pi is mutable In-Reply-To: <878u69zxww.fsf@elektro.pacujo.net> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> Message-ID: On 07/11/2015 14:28, Marko Rauhamaa wrote: > Marko Rauhamaa : > >> In my work, I currently use bash, Python and C. For many, many tasks, >> bash is superior to Python. For others, Python can't compete with C. >> Yet the vast gap between bash and C is nicely filled with Python. > > And, by the way, the introduction of the "const" keyword was maybe the > biggest mistake the C standardizers ever made. It turned out to be about > as useful as a mosquito buzzing at your ear, and equally persistent and > annoying. (Yes, 'const' in C is a waste of time, and half the people using it don't appear to know what it means. Some people also like to use it practically everywhere so that you can no longer make out the actual code. The version in C++ is a more complicated form even further away from what people really want. Neither have the simplicity of concept of Pascal's 'const', which is just a named value. Not a variable that won't change once initialised, not a parameter that won't be changed nor any addressable location.) -- Bartc From bc at freeuk.com Sat Nov 7 10:19:36 2015 From: bc at freeuk.com (Bartc) Date: Sat, 7 Nov 2015 15:19:36 +0000 Subject: Question about math.pi is mutable In-Reply-To: <87d1vlzy4p.fsf@elektro.pacujo.net> References: <87d1vlzy4p.fsf@elektro.pacujo.net> Message-ID: On 07/11/2015 14:23, Marko Rauhamaa wrote: > Bartc : > In my work, I currently use bash, Python and C. For many, many tasks, > bash is superior to Python. For others, Python can't compete with C. Yet > the vast gap between bash and C is nicely filled with Python. The gap between Python and C is still pretty big! -- Bartc From torriem at gmail.com Sat Nov 7 10:45:25 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Nov 2015 08:45:25 -0700 Subject: Guide in Deskop Application Development in Python for newbies In-Reply-To: <436bfe7e-ece3-454d-b0c7-81de0fe82acb@googlegroups.com> References: <436bfe7e-ece3-454d-b0c7-81de0fe82acb@googlegroups.com> Message-ID: <563E1C95.7030609@gmail.com> On 11/07/2015 07:44 AM, leonardmesiera at gmail.com wrote: > How do you start building a desktop application in python? I mean > where do I start? Besides installing python on your windows what else > do I need, and any suggestion on how do I accomplish this project. > > Right now I really want to finish this beauty pageant judging system > which requires to have a client and a server, client would be for the > judges and a server that computes the scores from all the categories, > (i do hope you get I want mean by that project). I just finished > reading Headfirst Python and I really loving this language, so any > help from all the great programmers here would be so great. Usually one starts by picking a GUI toolkit, of which there are several. For example, there's the famous and very nice Qt toolkit (use PyQt or PySide[1] in Python), there's GTK+ (PyGObject[2]), wxWidgets (wxPython), Tkinter[3], or Kivy[4]. Of these, Tkinter is baked into Python and could be a quick way to get started. Kivy is also very interesting and potentially can target other platforms like Android. Personally I prefer Qt right now. Many of these toolkits contain tools for graphically laying out a GUI, although doing layout in code is actually pretty easy. Another good option, given your project's architecture, is to build a frontend that works in the browser. There are numerous web application frameworks to choose from as well, varying in complexity. Either way you cut it, you will find a bit of a learning curve, and if you haven't done GUI development in any language before, there's some new concepts to understand, like event-driven programming. Hope this helps. If you search the list archives, you can find many discussions on what toolkits people like to use and why. Example links, you can google for many others: [1] https://wiki.qt.io/PySideDocumentation http://it.toolbox.com/blogs/enlightenment/pyside-tutorial-using-qt-designer-with-pyside-66012 https://wiki.qt.io/PySide_Video_Tutorials [2] https://python-gtk-3-tutorial.readthedocs.org/en/latest/ https://python-gtk-3-tutorial.readthedocs.org/en/latest/builder.html [3] http://www.python-course.eu/python_tkinter.php [4] http://kivy.org/#home From torriem at gmail.com Sat Nov 7 10:47:38 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Nov 2015 08:47:38 -0700 Subject: Scipy odeint (LSODA) gives inaccurate results; same code fine in MATLAB ode15s/ode23s In-Reply-To: References: <942d2bd0-6322-4733-a6dd-ceeed40368cb@googlegroups.com> Message-ID: <563E1D1A.7010305@gmail.com> On 11/06/2015 11:54 PM, Christian Gollwitzer wrote: > It is very hard to analyze such a problem, unless you also post the > Matlab code and plot both solutions into a single graph. Also he may have a quicker response posting to the scipy list, where scientists and mathematicians regularly use and talk about scipy: http://www.scipy.org/scipylib/mailing-lists.html From invalid at invalid.invalid Sat Nov 7 11:16:33 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 7 Nov 2015 16:16:33 +0000 (UTC) Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> Message-ID: On 2015-11-07, Marko Rauhamaa wrote: > Marko Rauhamaa : > >> In my work, I currently use bash, Python and C. For many, many tasks, >> bash is superior to Python. For others, Python can't compete with C. >> Yet the vast gap between bash and C is nicely filled with Python. > > And, by the way, the introduction of the "const" keyword was maybe the > biggest mistake the C standardizers ever made. It turned out to be about > as useful as a mosquito buzzing at your ear, and equally persistent and > annoying. I take it you don't write embedded code that runs from ROM? I do. The const keyword is the most valuable addition to the C language since the function prototype. Without it, you used to have to jump through all sorts of hoops to get read-only data placed into read-only memory. -- Grant From marko at pacujo.net Sat Nov 7 12:46:23 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Nov 2015 19:46:23 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> Message-ID: <8737whzor4.fsf@elektro.pacujo.net> Bartc : > (Yes, 'const' in C is a waste of time, and half the people using it > don't appear to know what it means. It cannot mean anything meaningful; it's completely useless. For example, what could one think of standard library functions whose prototypes are: char *strstr(const char *haystack, const char *needle); int execve(const char *filename, char *const argv[], char *const envp[]); Ok, enough of C. Marko From marko at pacujo.net Sat Nov 7 13:00:29 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Nov 2015 20:00:29 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> Message-ID: <87y4e9y9j6.fsf@elektro.pacujo.net> Grant Edwards : > I take it you don't write embedded code that runs from ROM? I do. The > const keyword is the most valuable addition to the C language since > the function prototype. Without it, you used to have to jump through > all sorts of hoops to get read-only data placed into read-only memory. If all you need is a linker directive that places data in a read-only section, "const" is a very ineffective tool that clutters the code and forces you to sprinkle type casts around your code. Marko From input/ldompeling at casema.nl Sat Nov 7 16:27:06 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Sat, 07 Nov 2015 21:27:06 GMT Subject: time module Message-ID: hi, I like to have a function that prints time in seconds. I am looking for something for example that seconds count from zero. I search the internet for time module in python but could not found anathing usefull. Has someone an example for it. Thanks -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From cs at zip.com.au Sat Nov 7 16:47:07 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 8 Nov 2015 08:47:07 +1100 Subject: time module In-Reply-To: References: Message-ID: <20151107214707.GA89395@cskk.homeip.net> On 07Nov2015 21:27, input/ldompeling at casema.nl wrote: >I like to have a function that prints time in seconds. >I am looking for something for example that seconds count from zero. >I search the internet for time module in python but could not found anathing usefull. Here: https://docs.python.org/3/library/time.html#time.time Cheers, Cameron Simpson From pmiscml at gmail.com Sat Nov 7 18:00:59 2015 From: pmiscml at gmail.com (Paul Sokolovsky) Date: Sun, 8 Nov 2015 02:00:59 +0300 Subject: [ANN] MicroPython 1.5 Message-ID: <20151108020059.54a36344@x230> Hello, MicroPython is a lean and efficient Python implementation for microcontrollers, embedded, and mobile systems (which also runs just as fine on desktops of course). https://github.com/micropython/micropython Recent 1.5 release is an important milestone for the project, major changes including: 1. Advanced REPL support with smart auto-indent and auto-completion for comfortable interactive typing pf Python code, easily switchable to paste mode to copy pre-made code snippets. 2. Support for client SSL connections. 3. upip, MicroPython builtin package manager, is now fully standalone thanks to SSL support. 4. There's new, elaborated API to access hardware features ("machine" module). 5. There're now 2 well-supported microcontroller boards for MicroPython, and dozen(s) community-supported ones. 6. MicroPython was selected as one of the languages supported for BBC micro:bit initiative: http://ntoll.org/article/story-micropython-on-microbit 7. There's work on native efficient JNI bridge, inspired by Kivy's PyJNIus module, included into growing Android port. More detailed changelog for this version is at https://github.com/micropython/micropython/releases/tag/v1.5 MicroPython supports growing subset of Python3 standard library (including simplified asyncio package) - not included by default with an executable, but easily installable per-module using builtin "upip" package manager: https://github.com/micropython/micropython-lib -- Best regards, Paul mailto:pmiscml at gmail.com From bc at freeuk.com Sat Nov 7 18:02:24 2015 From: bc at freeuk.com (Bartc) Date: Sat, 7 Nov 2015 23:02:24 +0000 Subject: Question about math.pi is mutable In-Reply-To: <1590467.kktH0DaBsW@PointedEars.de> References: <1590467.kktH0DaBsW@PointedEars.de> Message-ID: On 06/11/2015 22:26, Thomas 'PointedEars' Lahn wrote: > Bartc wrote: > ^^^^^ > Please fix. What's the problem? From breamoreboy at yahoo.co.uk Sat Nov 7 18:27:28 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 7 Nov 2015 23:27:28 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: <1590467.kktH0DaBsW@PointedEars.de> Message-ID: On 07/11/2015 23:02, Bartc wrote: > On 06/11/2015 22:26, Thomas 'PointedEars' Lahn wrote: >> Bartc wrote: >> ^^^^^ >> Please fix. > > What's the problem? > > He is the problem. I assume it's because he thinks he's a dog, cat or some other animal. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Sat Nov 7 18:32:33 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Nov 2015 10:32:33 +1100 Subject: Question about math.pi is mutable References: <1590467.kktH0DaBsW@PointedEars.de> Message-ID: <85pozlidwu.fsf@benfinney.id.au> Bartc writes: > On 06/11/2015 22:26, Thomas 'PointedEars' Lahn wrote: > > Bartc wrote: > > ^^^^^ > > Please fix. > > What's the problem? As far as I can tell, you're being asked to change that to your ?real? name, whatever that is supposed to mean. I recommend you ignore that request; ?Bartc? is fine as a name here, IMO. -- \ ?Your [government] representative owes you, not his industry | `\ only, but his judgment; and he betrays, instead of serving you, | _o__) if he sacrifices it to your opinion.? ?Edmund Burke, 1774 | Ben Finney From Cecil at decebal.nl Sat Nov 7 18:40:11 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 08 Nov 2015 00:40:11 +0100 Subject: Problems connecting to PostgreSQL Message-ID: <87wptt5qg4.fsf@Equus.decebal.nl> I followed http://zetcode.com/db/postgresqlpythontutorial/. I used: sudo -u postgres createuser stressTest this create the role, but also gave: could not change directory to "/root": Permission denied and I did not get the questions. Then I used: sudo -u postgres createdb stressTest -O stressTest This gave also: could not change directory to "/root": Permission denied The database is created, but when I execute: conn = psycopg2.connect(database = postgres_database, user = 'stressTest') I get: psycopg2.OperationalError: FATAL: Peer authentication failed for user "stressTest" What do I need to do to get things working? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Sat Nov 7 18:52:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Nov 2015 10:52:41 +1100 Subject: Question about math.pi is mutable In-Reply-To: <85pozlidwu.fsf@benfinney.id.au> References: <1590467.kktH0DaBsW@PointedEars.de> <85pozlidwu.fsf@benfinney.id.au> Message-ID: On Sun, Nov 8, 2015 at 10:32 AM, Ben Finney wrote: > I recommend you ignore that request; ?Bartc? is fine as a name here, > IMO. Given that LARTC means Linux Advanced Routing and Traffic Control, I'm guessing Bartc is all about *BSD networking? :) ChrisA From rosuav at gmail.com Sat Nov 7 18:54:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Nov 2015 10:54:49 +1100 Subject: Problems connecting to PostgreSQL In-Reply-To: <87wptt5qg4.fsf@Equus.decebal.nl> References: <87wptt5qg4.fsf@Equus.decebal.nl> Message-ID: On Sun, Nov 8, 2015 at 10:40 AM, Cecil Westerhof wrote: > I used: > sudo -u postgres createuser stressTest > this create the role, but also gave: > could not change directory to "/root": Permission denied > and I did not get the questions. > You might need to become root before you can become another user - it depends on your sudoers file. Try this: sudo sudo -u postgres createuser stressTest Note that this isn't a Python question, but a PostgreSQL and system administration one. You may find good results by searching the web for your issue and omitting all reference to Python. ChrisA From torriem at gmail.com Sat Nov 7 20:50:32 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Nov 2015 18:50:32 -0700 Subject: Guide in Deskop Application Development in Python for newbies In-Reply-To: References: <436bfe7e-ece3-454d-b0c7-81de0fe82acb@googlegroups.com> <563E1C95.7030609@gmail.com> Message-ID: <563EAA68.6080906@gmail.com> On 11/07/2015 12:15 PM, paul.hermeneutic at gmail.com wrote: > Where would you say that web2py fits into this mix > of tools? I am not familiar with it but I know it's supposed to be a lightweight framework for developing web-based sites and applications. Could be an excellent tool for the OP to use to build his user interface. From phamtony33 at gmail.com Sat Nov 7 21:11:15 2015 From: phamtony33 at gmail.com (phamtony33 at gmail.com) Date: Sat, 7 Nov 2015 18:11:15 -0800 (PST) Subject: Converting a string into a float that includes the negative Message-ID: <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> I am having issue with converting the string into a float because there is a negative, so only end up with "ValueError: invalid literal for float(): 81.4]" def contains_words(word,msg): if word in msg: return true else: return false def get_tweet(tweet_line): part_list = tweet_line.split('\t') tweet = part_list[3] return tweet def get_longitude(tweet_line): part_list = tweet_line.split('\t') gps = part_list[0] gps_list = gps.split(', ') long = gps_list[1] long1 = long[1:] longitude = float(long1) return longitude a = get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!") print a the answer should be get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!") ? -81.4 From contact at stridebird.com Sat Nov 7 21:39:00 2015 From: contact at stridebird.com (Pete Dowdell) Date: Sun, 8 Nov 2015 09:39:00 +0700 Subject: Converting a string into a float that includes the negative In-Reply-To: <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> References: <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> Message-ID: <563EB5C4.4040206@stridebird.com> On 08/11/15 09:11, phamtony33 at gmail.com wrote: > I am having issue with converting the string into a float because there is a negative, so only end up with "ValueError: invalid literal for float(): 81.4]"81.4] The error is right there in the exception: you are trying to cast '81.4]' - that's a square bracket in the string. You are also removing the negative sign from your number before casting with your slice this will fix it - change line: long1 = long[1:] to: long1 = long[:-1] test: >>> TXT="[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!" >>> float( TXT.split('\t')[0].split(', ')[1][:-1] ) -81.4 pd From python at mrabarnett.plus.com Sat Nov 7 21:40:24 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 8 Nov 2015 02:40:24 +0000 Subject: Converting a string into a float that includes the negative In-Reply-To: <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> References: <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> Message-ID: <563EB618.8060908@mrabarnett.plus.com> On 2015-11-08 02:11, phamtony33 at gmail.com wrote: > I am having issue with converting the string into a float because there is a negative, so only end up with "ValueError: invalid literal for float(): 81.4]" > > def contains_words(word,msg): > if word in msg: > return true > else: > return false > > def get_tweet(tweet_line): > part_list = tweet_line.split('\t') > tweet = part_list[3] > return tweet > > def get_longitude(tweet_line): > part_list = tweet_line.split('\t') > gps = part_list[0] > gps_list = gps.split(', ') > long = gps_list[1] > long1 = long[1:] > longitude = float(long1) > return longitude > > a = get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!") > print a > > the answer should be > get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!") ? -81.4 > You're slicing the wrong end off 'long'. You have '-81.4]'. You want '-81.4'. You should be doing long[ : -1]. From phamtony33 at gmail.com Sat Nov 7 21:44:25 2015 From: phamtony33 at gmail.com (phamtony33 at gmail.com) Date: Sat, 7 Nov 2015 18:44:25 -0800 (PST) Subject: Converting a string into a float that includes the negative In-Reply-To: References: <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> Message-ID: <9c6f5cf7-bb48-4014-8e4b-ab653c56f24c@googlegroups.com> On Saturday, November 7, 2015 at 9:40:49 PM UTC-5, MRAB wrote: > On 2015-11-08 02:11, phamtony33 at gmail.com wrote: > > I am having issue with converting the string into a float because there is a negative, so only end up with "ValueError: invalid literal for float(): 81.4]" > > > > def contains_words(word,msg): > > if word in msg: > > return true > > else: > > return false > > > > def get_tweet(tweet_line): > > part_list = tweet_line.split('\t') > > tweet = part_list[3] > > return tweet > > > > def get_longitude(tweet_line): > > part_list = tweet_line.split('\t') > > gps = part_list[0] > > gps_list = gps.split(', ') > > long = gps_list[1] > > long1 = long[1:] > > longitude = float(long1) > > return longitude > > > > a = get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!") > > print a > > > > the answer should be > > get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!") ? -81.4 > > > You're slicing the wrong end off 'long'. > > You have '-81.4]'. You want '-81.4'. You should be doing long[ : -1]. Ah! Thank you so much! From steve at pearwood.info Sat Nov 7 21:59:16 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 08 Nov 2015 13:59:16 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> Message-ID: <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> On Sun, 8 Nov 2015 02:01 am, Bartc wrote: > Neither have the simplicity of concept of Pascal's 'const', which is > just a named value. Not a variable that won't change once initialised, > not a parameter that won't be changed nor any addressable location.) Unfortunately the concept of "named value" doesn't match well with Python's design. That implies a separate compilation step which doesn't fit well with Python's runtime semantics. Very little happens at compile-time in Python that *must* happen at compile-time. I'm also not sure what difference you think there is between "named value" and "variable that won't change once initialised". Python has a convention for "constants" -- all UPPERCASE names. The fact that the convention exists is enough to prove that the concept of "constant" is a useful one. The difference between Python's pseudo-constants and (say) Pascal's actual constants is that in Python, the burden of ensuring that neither you, nor any of the libraries you call, modifies the "constant" falls on you, the user, whereas in Pascal the compiler or interpreter performs that checking for you. Besides, the Python convention is honoured more in theory than in practice. We have math.pi, not math.PI. -- Steven From steve at pearwood.info Sat Nov 7 22:07:15 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 08 Nov 2015 14:07:15 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <8737whzor4.fsf@elektro.pacujo.net> Message-ID: <563ebc64$0$1614$c3e8da3$5496439d@news.astraweb.com> On Sun, 8 Nov 2015 04:46 am, Marko Rauhamaa wrote: > Bartc : > >> (Yes, 'const' in C is a waste of time, and half the people using it >> don't appear to know what it means. > > It cannot mean anything meaningful; it's completely useless. > > For example, what could one think of standard library functions whose > prototypes are: > > char *strstr(const char *haystack, const char *needle); > > int execve(const char *filename, char *const argv[], > char *const envp[]); Surely that is obvious? I don't speak much C, but I would expect that inside the functions, const parameters can be read, but not assigned to. "*const" is a mystery to me though. > Ok, enough of C. Amen to that. If I had a dollar for every crime against computing committed because of C, or enabled due to C's design decisions, I would be rich beyond the dreams of avarice. Fortunately, C is not the only other computer language, and we are by no means limited to the two choices of the status quo (no constants in Python) and what C does. -- Steven From adiamond1978 at gmail.com Sat Nov 7 22:13:12 2015 From: adiamond1978 at gmail.com (Andrew Diamond) Date: Sat, 7 Nov 2015 19:13:12 -0800 (PST) Subject: [Ubuntu] PyQt5 Message-ID: Hi! I'm fairly new to Python, and installed pyqt5 and began working through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ However, whenever I click one of the buttons or menus in the example apps I run that is supposed to quit the application, it locks up. This happens with all the examples I installed that handle code to quit the app. Running Ubuntu 15.10, and installed pyqt5 via: sudo apt-get install python3-pyqt5 sudo apt-get install qtcreator Thank you in advance for any assistance! From invalid at invalid.invalid Sat Nov 7 22:31:59 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 8 Nov 2015 03:31:59 +0000 (UTC) Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <87y4e9y9j6.fsf@elektro.pacujo.net> Message-ID: On 2015-11-07, Marko Rauhamaa wrote: > Grant Edwards : > >> I take it you don't write embedded code that runs from ROM? I do. The >> const keyword is the most valuable addition to the C language since >> the function prototype. Without it, you used to have to jump through >> all sorts of hoops to get read-only data placed into read-only memory. > > If all you need is a linker directive that places data in a read-only > section, "const" is a very ineffective tool that clutters the code and > forces you to sprinkle type casts around your code. But it allows the compiler to warn you if you pass a pointer to a read-only data to a function that expects a pointer to writable data. For those of us who occasionally make mistakes, such compiler warnings are very useful. -- Grant From steve at pearwood.info Sat Nov 7 22:50:04 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 08 Nov 2015 14:50:04 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> Message-ID: <563ec66d$0$1614$c3e8da3$5496439d@news.astraweb.com> On Sun, 8 Nov 2015 01:23 am, Marko Rauhamaa wrote: > Bartc : > >> Not just my option. From this 2010 paper for example ('High performance >> implementation of Python for CLI ...' by Antonio Cuni): >> >> "As a language, Python is very hard to implement efficiently: the >> presence of highly dynamic constructs makes static analysis of >> programs extremely difficult, thus preventing ahead of time (AOT) >> compilers to generate efficient target code." > > Correct. That's not Python's fault, however. Python should not try to > placate the performance computing people. (Alas, it is now trying to do > just that with the introduction of static typing annotation.) That is factually incorrect. The motive behind the introduction of typing annotations is not "speed", but "correctness". Guido has expressed skepticism that typing annotations can be used to improve the speed of Python programs, and has suggested that the future of optimization is JIT compilers like PyPy rather than static compilers like Nuitka. [Aside: I have to disagree with Guido's thoughts on compilers. Even if JIT compilers are ultimately faster for long-running code, they don't help much for short-running code, and surely there is a lot of low-hanging fruit that an optimizing compiler can perform. Victor Skinner is experimenting with a version of CPython which, among other things, detects when built-ins have not been modified, and can inline them for speed.] If type annotations lead to faster code, that's a bonus, but it isn't why they are being added to the language. They are added to improve correctness and documentation, to enable type-checks to be performed by linters and compile-time type-checkers. >> Plenty of other people working on faster Pythons appear to have >> trouble with its being so dynamic. > > That's, literally, their problem. > >> As one example of many, named constants (the 'const' feature earlier >> in the thread), were used for 'switch' statements. Without 'const', >> then I couldn't have a fast 'switch'.) > > Fast, fast, fast. We have plenty of fast programming languages. Yeah, but most of them suck. Why can't we have a fast programming language that is as nice to use as Python? Why can't Python be fast? > Python > should *not* sacrifice its dynamism (which the fast languages don't > have) for speed. Python is already fast enough for most programming > tasks. Well, I don't know about anyone else, but I personally always want my scripts and programs to run slower. I can't tell you how annoyed I was when new-style classes became as fast or faster than old-style classes. *wink* [...] >> I suppose my coding style is just different from people who write >> Python. When I define a function f(), then it's always going to be >> function f and is never going to change. A call to such a function can >> therefore be streamlined. > > Your point of view is really down-to-earth. It's slightly analogous to > protesting against Unicode because you only ever need ASCII. I don't think so, but in any case, Bart is *way* oversimplifying the potential optimizations available. Function inlining depends on the function being small enough that inlining it does more good than harm, but it doesn't require that f never changes. Perhaps Laura can confirm this, but I understand that PyPy can inline functions. Simplified: The compiler builds a fast path and a slow path, and a guard. If the function is the one you expect, the interpreter takes the fast path, which includes the inlined function. But if the function has been rebound, the guard triggers, and the interpreter takes the slow path, which follows the slow, dynamic implementation. In pseudo-code: def spam(): result = eggs(x) will compile as if it were written like this: def spam(): if eggs is EXPECTED_EGGS: # inline code do_this() do_that() result = another_thing(x) else: result = eggs(x) The compiler manages all the book-keeping for you, automatically, and as functions grow and shrink in complexity, it will automatically decide which ones can be inlined and which cannot. You write the simplest, most obvious code which is easy to maintain, and the compiler managers the ugly optimizations. > You would be right in that Python programs hardly ever make use of or > directly depend on the degrees of freedom Python affords. That's certainly true. Every Python program pays a significant speed penalty (perhaps as much as 10 x slower than it need be) for features which are used by probably less than 1% of code. The choice is not between "dynamic language" and "fast language". You can have both. Smalltalk proves it. Javascript proves it. You just need smarter compilers which can optimize the usual, non-dynamic cases while still allowing dynamic code to work. We often say that the reason Python is anything up to a factor of 100 times slower than languages like Java is because Python is so dynamic, but that's not true. Python is so slow because *Python compilers aren't smart enough*. CPython is a relatively simple reference implementation which applies hardly any optimizations. Even such simple things as constant folding are slightly controversial! If you go back to older versions of Python, code like this: x = 1 + 1 actually performed the addition at runtime, instead of being compiled to: x = 2 Believe it or not, even something as simple as that remains controversial, with some folks (including Guido) expressing doubt that constant-folding is worthwhile. But PyPy proves that Python compilers can be smarter, and optimize more, without sacrificing dynamicism. > They are used > every here and there, however, and, most imporantly, they make it > possible to define the semantics of the programming language in a sound, > concise manner. That way it is easier to implement Python, learn > Python and use Python correctly. > > Imagine there was a national standard that defined that you could only > sell hatchets that split wood in a downward movement. You might argue > that hardly anyone swung a hatchet sideways, and it would be dangerous > anyway. However, that kind of a standard would make it very difficult to > manufacture the simple concept of a hatchet. The contraption would be > expensive, fragile, heavy and difficult to use even for the intended > up-down splitting purpose. I don't think that's a good analogy. A better analogy is, imagine that Ford built a car that allowed you to swap out the radio, the doors, the tyres, even the engine, while the car was moving. You could unplug the engine while driving down the road, and plug in a new one, and the car would just keep going. As a consequence, the car is significantly bigger and slower than most other cars, and occasionally it is useful (when you get a flat tyre, you don't have to stop, you just swap into place a new tyre and keep going) but generally it's not used much (who swaps out the seat that they are sitting on?). Ford call this car "Python". > I wouldn't like Python to turn into such a contraption. -- Steven From vincent.vande.vyvre at telenet.be Sun Nov 8 00:36:26 2015 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sun, 8 Nov 2015 06:36:26 +0100 Subject: [Ubuntu] PyQt5 In-Reply-To: References: Message-ID: <563EDF5A.6040403@telenet.be> Le 08/11/2015 04:13, Andrew Diamond a ?crit : > Hi! > > I'm fairly new to Python, and installed pyqt5 and began working through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ However, whenever I click one of the buttons or menus in the example apps I run that is supposed to quit the application, it locks up. This happens with all the examples I installed that handle code to quit the app. > > Running Ubuntu 15.10, and installed pyqt5 via: > > sudo apt-get install python3-pyqt5 > sudo apt-get install qtcreator > > Thank you in advance for any assistance! Works fine for me on 15.04. I've tested the first example with the menuBar. Have you a message into the terminal? Maybe an error? Vincent From flebber.crue at gmail.com Sun Nov 8 00:55:32 2015 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 7 Nov 2015 21:55:32 -0800 (PST) Subject: Is there an archive of the gohlke python binaries on windows Message-ID: Just wondering if there is an archive mirror for these binaries available. i was looking for lxml 3.4.1 and the current version is the latest on the page at 3.4.4 being on windows I cannot build it. http://www.lfd.uci.edu/~gohlke/pythonlibs/ Thanks Sayth From random832 at fastmail.com Sun Nov 8 01:29:11 2015 From: random832 at fastmail.com (Random832) Date: Sun, 08 Nov 2015 01:29:11 -0500 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <8737whzor4.fsf@elektro.pacujo.net> <563ebc64$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > Surely that is obvious? I don't speak much C, but I would expect that inside > the functions, const parameters can be read, but not assigned to. "*const" > is a mystery to me though. There's a program (and now a website) called cdecl that can decode these: char *const envp[] declare envp as array of const pointer to char In other words, the pointers in the array are const, but the array itself (which is really a pointer, and it's generally regarded as nonsense to make const first-level function arguments anyway, but enough of that) is not, nor are the characters that the pointers point to. There are various reasons I don't fully understand and are beyond the scope of this argument regarding why it's not possible to assign a pointer-to-pointer-to-char to a pointer-to-pointer-to-const-char, so the argument isn't declared with the latter. Unfortunately, while it handles simple function arguments, it (the version on the website at least) apparently can't handle named or const function arguments, otherwise you could paste the whole thing. From marko at pacujo.net Sun Nov 8 02:45:55 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 09:45:55 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <87y4e9y9j6.fsf@elektro.pacujo.net> Message-ID: <87d1vlx7bg.fsf@elektro.pacujo.net> Grant Edwards : > On 2015-11-07, Marko Rauhamaa wrote: >> "const" is a very ineffective tool that clutters the code and forces >> you to sprinkle type casts around your code. > > But it allows the compiler to warn you if you pass a pointer to a > read-only data to a function that expects a pointer to writable data. Unfortunately, it doesn't: ======================================================================== #include #include int main() { const char name[] = "Tom"; char *p = strstr(name, "Tom"); strcpy(p, "Bob"); printf("name = %s\n", name); return 0; } ======================================================================== $ cc -o prog prog.c $ ./prog Bob No warning. Point is, the consequences of "proper" use of const are so annoying even standard library functions would rather grossly abuse it than tolerate compiler warnings everywhere. Marko From auriocus at gmx.de Sun Nov 8 03:00:27 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 8 Nov 2015 09:00:27 +0100 Subject: Question about math.pi is mutable In-Reply-To: <87d1vlx7bg.fsf@elektro.pacujo.net> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <87y4e9y9j6.fsf@elektro.pacujo.net> <87d1vlx7bg.fsf@elektro.pacujo.net> Message-ID: Am 08.11.15 um 08:45 schrieb Marko Rauhamaa: > Grant Edwards : > >> On 2015-11-07, Marko Rauhamaa wrote: >>> "const" is a very ineffective tool that clutters the code and forces >>> you to sprinkle type casts around your code. >> >> But it allows the compiler to warn you if you pass a pointer to a >> read-only data to a function that expects a pointer to writable data. > > Unfortunately, it doesn't: > > ======================================================================== > #include > #include > > int main() > { > const char name[] = "Tom"; > char *p = strstr(name, "Tom"); > strcpy(p, "Bob"); > printf("name = %s\n", name); > return 0; > } > ======================================================================== > > $ cc -o prog prog.c > $ ./prog > Bob > > No warning. > That is strange. In C, I can see thet problem here, because it is impossible to define a const correct strstr. But in C++ I have expected that according to the overload, the const version of strstr would be selected (http://www.cplusplus.com/reference/cstring/strstr/ ) . Still: apfelkiste:Tests chris$ cat prog.cpp #include #include int main() { const char name[] = "Tom"; char *p = strstr(name, "Tom"); // this line should be an error strcpy(p, "Bob"); printf("name = %s\n", name); return 0; } apfelkiste:Tests chris$ g++ -Wall prog.cpp apfelkiste:Tests chris$ ./a.out Bus error: 10 It segfaults because on OSX, const can be stored in write-only memory. apfelkiste:Tests chris$ g++ --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin12.6.0 Thread model: posix Christian From no.email at nospam.invalid Sun Nov 8 03:08:28 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 08 Nov 2015 00:08:28 -0800 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <87y4e9y9j6.fsf@elektro.pacujo.net> <87d1vlx7bg.fsf@elektro.pacujo.net> Message-ID: <87h9kwvrpf.fsf@nightsong.com> Marko Rauhamaa writes: > Point is, the consequences of "proper" use of const are so annoying even > standard library functions would rather grossly abuse it than tolerate > compiler warnings everywhere. I'm not sure what the C standard says about that example, but C++ is much stricter about those conversions, and g++ does flag an error if you compile that code with it. From kwpolska at gmail.com Sun Nov 8 03:36:38 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 8 Nov 2015 09:36:38 +0100 Subject: Problems connecting to PostgreSQL In-Reply-To: <87wptt5qg4.fsf@Equus.decebal.nl> References: <87wptt5qg4.fsf@Equus.decebal.nl> Message-ID: On 8 November 2015 at 00:40, Cecil Westerhof wrote: > I followed http://zetcode.com/db/postgresqlpythontutorial/. > > I used: > sudo -u postgres createuser stressTest > this create the role, but also gave: > could not change directory to "/root": Permission denied > and I did not get the questions. This is not an error, just a warning ? and it comes from sudo, postgres doesn?t care. To silence it, you need to work from a different directory than /root. The commands actually worked just fine. > Then I used: > sudo -u postgres createdb stressTest -O stressTest > This gave also: > could not change directory to "/root": Permission denied > > The database is created, but when I execute: > conn = psycopg2.connect(database = postgres_database, user = 'stressTest') > I get: > psycopg2.OperationalError: FATAL: Peer authentication failed for user "stressTest" > > What do I need to do to get things working? You need to configure your PostgreSQL database to use md5 authentication, and set a password for your user. # cd / # sudo -u postgres psql postgres=# ALTER ROLE stressTest WITH PASSWORD 'swordfish'; postgres=# \q # vim /var/lib/postgres/data/pg_hba.conf Change host settings to look like this: # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 Then you can connect using: conn = psycopg2.connect(database='stressTest', user='stressTest', password='swordfish', host='localhost') Documentation: http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html http://www.postgresql.org/docs/current/static/auth-methods.html http://www.postgresql.org/docs/current/static/sql-alterrole.html (basically, the default peer authentication checks your Unix user name to see if it matches 'stressTest', and fails) -- Chris Warrick PGP: 5EAAEA16 From kwpolska at gmail.com Sun Nov 8 04:22:01 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 8 Nov 2015 10:22:01 +0100 Subject: Guide in Deskop Application Development in Python for newbies In-Reply-To: <563EAA68.6080906@gmail.com> References: <436bfe7e-ece3-454d-b0c7-81de0fe82acb@googlegroups.com> <563E1C95.7030609@gmail.com> <563EAA68.6080906@gmail.com> Message-ID: On 7 November 2015 at 15:44, wrote: > How do you start building a desktop application in python? I mean where do I start? Besides installing python on your windows what else do I need, and any suggestion on how do I accomplish this project. > > Right now I really want to finish this beauty pageant judging system which requires to have a client and a server, client would be for the judges and a server that computes the scores from all the categories, (i do hope you get I want mean by that project). I just finished reading Headfirst Python and I really loving this language, so any help from all the great programmers here would be so great. > -- > https://mail.python.org/mailman/listinfo/python-list This project requires two very different components, or one monolithic server. The first one is the server. It basically needs to talk to clients (via HTTP) and to a database. This is a trivial app to write in your favorite web framework, eg. Django [0]. Come up with a good database structure (read the excellent tutorial and documentation, should get you there), write some models. But you can?t write your views just yet. Because the views you write depend strictly on the client. For the client, you basically have two choices: (a) write a web application in Django; (b) use a GUI framework and make a standalone desktop application. If you choose option (a), you need to learn HTML/CSS and write the views for your Django application (or use a ready-made front-end framework, eg. Bootstrap [1]). This is the simplest choice, and it takes a lot of work away from you. Your users will use their favorite web browser to access the voting system, log in, and make their votes, and there is no special setup for them (apart from giving them credentials to access your app). Your Django views will use the built-in Django templating, forms, and is relatively simple to do (might even be doable in a weekend). Route (b) is much more complicated. To follow this route, you need to pick a GUI framework. There are also multiple options, I personally recommend PySide, but you could also try wxWidgets, pygobject or kivy. The web app side of things will require serializing data to JSON and writing a RESTful API, but there are ready-made solutions for many web frameworks [2]. But most of those come with a catch: they usually make you produce ugly code, because they are wrappers around ugly C++ APIs. And then you need to write code to talk to your HTTP server. You can?t use the beautiful requests library, because it will block ? so there?s more work ahead, unless you want your app to be unresponsive every time you talk to the server. For example, in Qt, you would need to use Qt networking capabilities (which work asynchronously within the event loop), or some other implementation that you can use asynchronously (eg. Twisted, but then you lock yourself to Python 2, which is bad, or threading, which has its limitations?) And then you need to distribute your app to your users. Which is already hard, because you need to coordinate Python, your GUI framework, and your app. Are your users on Windows, Linux, or OS X? If you have at least one person on a platform, you will need some sort of testing environment? And no matter which route you choose, you can?t do much without a Linux server, so there?s more learning to do. Sadly, developing big things is hard and requires a lot of knowledge ? especially if you?re a one-man-band. Here?s a short list of skills you need, with a subjectively suggested implementation and ease of implementation: * understanding of the HTTP protocol (*) * web application development (Django *) * database schema writing (planning out the structure + Django ORM **) * app server setup (uWSGI + nginx + Linux ***) * database setup (PostgreSQL *** or something simpler[3]) * Route A: * HTML/CSS skills; a front-end framework (Bootstrap **) * Route B: * RESTful APIs (Django REST Framework ***/***** if you use OAuth) * GUI framework (PyQt ****) * talking to your server from within the framework (****/*****) [0]: https://www.djangoproject.com/ [1]: http://getbootstrap.com/ [2]: http://www.django-rest-framework.org/ [3]: If this is going to be VERY small, you could go with a sqlite database, which requires zero setup, but which is not suited for anything more serious. Other learning materials: https://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html http://www.fullstackpython.com/ http://deploypython.com/ On 8 November 2015 at 02:50, Michael Torrie wrote: > On 11/07/2015 12:15 PM, paul.hermeneutic at gmail.com wrote: >> Where would you say that web2py fits into this mix >> of tools? > > I am not familiar with it but I know it's supposed to be a lightweight > framework for developing web-based sites and applications. Could be an > excellent tool for the OP to use to build his user interface. > > -- > https://mail.python.org/mailman/listinfo/python-list web2py is weird, Django is more fun. -- Chris Warrick PGP: 5EAAEA16 From kwpolska at gmail.com Sun Nov 8 04:43:41 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 8 Nov 2015 10:43:41 +0100 Subject: Is there an archive of the gohlke python binaries on windows In-Reply-To: References: Message-ID: On 8 November 2015 at 06:55, Sayth Renshaw wrote: > Just wondering if there is an archive mirror for these binaries available. i was looking for lxml 3.4.1 and the current version is the latest on the page at 3.4.4 being on windows I cannot build it. > > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > Thanks > > Sayth > -- > https://mail.python.org/mailman/listinfo/python-list Why do you need an old version? There should be no reason to use an old version? Why can?t you use lxml 3.4.4? If you are a fan of old software, you are probably on Python 2.x, too, and you can get a binary from here: https://pypi.python.org/pypi/lxml/3.4.1 Also, those binaries are built by someone USING Windows. You can certainly build C extensions, if you install Visual Studio in the correct version. -- Chris Warrick PGP: 5EAAEA16 From marko at pacujo.net Sun Nov 8 04:44:01 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 11:44:01 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <563ec66d$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878u68ygf2.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 8 Nov 2015 01:23 am, Marko Rauhamaa wrote: >> Correct. That's not Python's fault, however. Python should not try to >> placate the performance computing people. (Alas, it is now trying to >> do just that with the introduction of static typing annotation.) > > That is factually incorrect. > > The motive behind the introduction of typing annotations is not "speed", > but "correctness". Oh, then I'm even more disappointed with type annotation. Marko From marko at pacujo.net Sun Nov 8 04:49:12 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 11:49:12 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <87y4e9y9j6.fsf@elektro.pacujo.net> <87d1vlx7bg.fsf@elektro.pacujo.net> <87h9kwvrpf.fsf@nightsong.com> Message-ID: <874mgwyg6f.fsf@elektro.pacujo.net> Paul Rubin : > Marko Rauhamaa writes: >> Point is, the consequences of "proper" use of const are so annoying even >> standard library functions would rather grossly abuse it than tolerate >> compiler warnings everywhere. > > I'm not sure what the C standard says about that example, but C++ is > much stricter about those conversions, [...] C++ gets const even more wrong than C, and const is the least of C++'s problems. Marko From lac at openend.se Sun Nov 8 05:20:12 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 08 Nov 2015 11:20:12 +0100 Subject: [Ubuntu] PyQt5 In-Reply-To: <563EDF5A.6040403@telenet.be> References: <563EDF5A.6040403@telenet.be> Message-ID: <201511081020.tA8AKCn5029601@fido.openend.se> In a message of Sun, 08 Nov 2015 06:36:26 +0100, Vincent Vande Vyvre writes: >Le 08/11/2015 04:13, Andrew Diamond a ?crit : >> Hi! >> >> I'm fairly new to Python, and installed pyqt5 and began working through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ However, whenever I click one of the buttons or menus in the example apps I run that is supposed to quit the application, it locks up. This happens with all the examples I installed that handle code to quit the app. >> >> Running Ubuntu 15.10, and installed pyqt5 via: >> >> sudo apt-get install python3-pyqt5 >> sudo apt-get install qtcreator >> >> Thank you in advance for any assistance! >Works fine for me on 15.04. > >I've tested the first example with the menuBar. > >Have you a message into the terminal? Maybe an error? > >Vincent A suggestion: When I get the 'it locks up when I want to quit' behaviour in PyQt4 it is because I have messed up something with my threading. PyQt4 wants there to be one, main control thread (that handles, among other things, shutting down) and lots of worker threads which do the gui-stuff, i.e. all the work that the program really needs to do. If you manage to structure things so that your control ends up in a worker thread, then when it is told to quit, your app sits around and waits for the main control thread to come back and deal with things, but your main control thread is dead, and therefore isn't coming. I assume you can get problems like this with Qt5 as well. Did quitting work properly with the earlier exercises of this tutorial, or did you try to start learning from the middle? Laura From flebber.crue at gmail.com Sun Nov 8 05:21:40 2015 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 8 Nov 2015 02:21:40 -0800 (PST) Subject: Is there an archive of the gohlke python binaries on windows In-Reply-To: References: Message-ID: <7a919b0a-205b-49c7-8a36-903f63be3497@googlegroups.com> On Sunday, 8 November 2015 20:44:02 UTC+11, Chris Warrick wrote: > On 8 November 2015 at 06:55, Sayth Renshaw wrote: > > Just wondering if there is an archive mirror for these binaries available. i was looking for lxml 3.4.1 and the current version is the latest on the page at 3.4.4 being on windows I cannot build it. > > > > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > > > Thanks > > > > Sayth > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Why do you need an old version? There should be no reason to use an > old version... Why can't you use lxml 3.4.4? > > If you are a fan of old software, you are probably on Python 2.x, too, > and you can get a binary from here: > https://pypi.python.org/pypi/lxml/3.4.1 > > Also, those binaries are built by someone USING Windows. You can > certainly build C extensions, if you install Visual Studio in the > correct version. > > -- > Chris Warrick > PGP: 5EAAEA16 I want to use lxml 3.4.1 because it is the required version in portia current version Sayth From input/ldompeling at casema.nl Sun Nov 8 05:25:28 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Sun, 08 Nov 2015 10:25:28 GMT Subject: time module References: Message-ID: > Ambiguous requirement: any normal counter starts from zero... But what > "zero" represents may differ... Seconds since Jan 1 1970? Seconds since > midnight? Seconds since start of program? Thanks for the reply Yes, I would like seconds since start of program. Can I not doing something like time()=0 only this gives an error. Thanks ------------------------------------------------------------------------ In reply to "Dennis Lee Bieber" who wrote the following: > On Sat, 07 Nov 2015 21:27:06 GMT, input/ldompeling at casema.nl declaimed the > following: > > > hi, > > > > I like to have a function that prints time in seconds. > > I am looking for something for example that seconds count from zero. > > I search the internet for time module in python but could not found anathing > > usefull. > > > > Ambiguous requirement: any normal counter starts from zero... But what > "zero" represents may differ... Seconds since Jan 1 1970? Seconds since > midnight? Seconds since start of program? > > > > > import time > > > > t0 = time.time() > > > > t0 > 1446941608.052 > > > > t0 / 60.0 > 24115693.467533335 > > > > t0 / 60.0 / 60.0 > 401928.22445888893 > > > > t0 / 60.0 / 60.0 / 24.0 > 16747.009352453704 > > > > t0 / 60.0 / 60.0 / 24.0 / 365.25 > 45.850812737724034 > > > > > > Almost 46 years worth of seconds. > > > > > tStart = time.time() > > > > for x in range(10): > ... time.sleep(x) > ... print time.time() - tStart > ... > 36.5020000935 > 37.5040001869 > 39.5090000629 > 42.5099999905 > 46.5170001984 > 51.5190000534 > 57.5200002193 > 64.5210001469 > 72.5230000019 > 81.5230000019 > > > > > > Okay, I'm not the fastest typist (35 seconds from tStart to finishing the > loop code) > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From lac at openend.se Sun Nov 8 05:30:30 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 08 Nov 2015 11:30:30 +0100 Subject: Is there an archive of the gohlke python binaries on windows In-Reply-To: References: Message-ID: <201511081030.tA8AUU9D030343@fido.openend.se> In a message of Sat, 07 Nov 2015 21:55:32 -0800, Sayth Renshaw writes: >Just wondering if there is an archive mirror for these binaries available. i was looking for lxml 3.4.1 and the current version is the latest on the page at 3.4.4 being on windows I cannot build it. > >http://www.lfd.uci.edu/~gohlke/pythonlibs/ > >Thanks > >Sayth https://pypi.python.org/pypi/lxml/3.4.1 Laura From bc at freeuk.com Sun Nov 8 05:40:19 2015 From: bc at freeuk.com (Bartc) Date: Sun, 8 Nov 2015 10:40:19 +0000 Subject: Question about math.pi is mutable In-Reply-To: <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/11/2015 02:59, Steven D'Aprano wrote: > On Sun, 8 Nov 2015 02:01 am, Bartc wrote: > >> Neither have the simplicity of concept of Pascal's 'const', which is >> just a named value. Not a variable that won't change once initialised, >> not a parameter that won't be changed nor any addressable location.) > > Unfortunately the concept of "named value" doesn't match well with Python's > design. That implies a separate compilation step which doesn't fit well > with Python's runtime semantics. Very little happens at compile-time in > Python that *must* happen at compile-time. > > I'm also not sure what difference you think there is between "named value" > and "variable that won't change once initialised". This is what I mean about people not understanding it! In NASM terms, a named constant is like: daysinweek equ 7 ; definition mov rax, daysinweek ; using it, as immediate value mov rbx, daysinweek*2 ; an a 'compile-term' expression ; mov daysinweek,8 ; can't be done! Illegal syntax While a 'const' variable, C style, might be: segment .rodata monthsinyear: ; definition dd 12 mov rax,[monthsinyear] ; using it, as memory access ; mov rbx,[monthsinyear*10] ; can't be done! mov [monthsinyear],6 ; can be done, but might give memory ; access errors if actually stored in ; protected memory. Usually in C, ; it isn't So in native code, a named value is not much different to a literal such as 7, or 3.14159. (But unlike C's #define, the name is a proper symbol with normal scope rules, and a type). The distinction at the machine level can be blurred with some instructions sets where there might not be an immediate data option for some data widths or types. Also where named constants are applied to things such as strings, which necessarily use storage. In the language however, you will not be able to use the named constant as an lvalue, and you will usually be able to use it for compile-time constant folding and for dimensioning fixed-bound arrays and such.) > Python has a convention for "constants" -- all UPPERCASE names. The fact > that the convention exists is enough to prove that the concept > of "constant" is a useful one. The difference between Python's > pseudo-constants and (say) Pascal's actual constants is that in Python, the > burden of ensuring that neither you, nor any of the libraries you call, > modifies the "constant" falls on you, the user, whereas in Pascal the > compiler or interpreter performs that checking for you. With a real named constant the check can always be done at compile-time. Unless you have a pure interpreter or some more elaborate way of executing source code. (In the case of Python, the main obstacle is that a constant name from inside an imported module is not visible when this module is compiled to byte-code. So it has to assume it can be anything.) -- BartC From marko at pacujo.net Sun Nov 8 06:02:20 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 13:02:20 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ziyowy83.fsf@elektro.pacujo.net> Bartc : > (In the case of Python, the main obstacle is that a constant name from > inside an imported module is not visible when this module is compiled > to byte-code. So it has to assume it can be anything.) Which it can. Optimizing for naive floating-point constants could be done but has barely any significance in most Python code. Numeric computations are carried out in separate native plugins. Most Python code deals with encapsulated objects whose innards are hidden and whose only semantics are defined by the access methods. New implementations or derived objects can be plugged in transparently. A case in point are the so-called file-like objects. They are a simple, elegant concept. I can come up with new file-like objects without any common pedigree with some predefined classes and incorporate them with a lot of utility classes. That elegant dynamism comes at a cost: method lookup is not a constant memory offset. Rather, it is a dictionary lookup. Marko From marko at pacujo.net Sun Nov 8 06:05:02 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 13:05:02 +0200 Subject: time module References: Message-ID: <87vb9cwy3l.fsf@elektro.pacujo.net> input/ldompeling at casema.nl: > Yes, I would like seconds since start of program. > Can I not doing something like time()=0 only this gives an error. Here: class MyReckoning: def __init__(self): self.the_beginning = time.time() def time(self): return time.time() - self.the_beginning reckoning = MyReckoning() print(reckoning.time()) Marko From bc at freeuk.com Sun Nov 8 06:06:27 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 11:06:27 +0000 Subject: Question about math.pi is mutable In-Reply-To: <563ec66d$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <563ec66d$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/11/2015 03:50, Steven D'Aprano wrote: > On Sun, 8 Nov 2015 01:23 am, Marko Rauhamaa wrote: >> Your point of view is really down-to-earth. It's slightly analogous to >> protesting against Unicode because you only ever need ASCII. > > I don't think so, but in any case, Bart is *way* oversimplifying the > potential optimizations available. Function inlining depends on the > function being small enough that inlining it does more good than harm, but > it doesn't require that f never changes. I didn't really have function in-lining in mind (although once you are sure a specific function will always be called, that is a possibility for the compiler). There are plenty of optimisations available if you know you are calling a function, and the compiler can 'see' the source code: * You don't need to check that 'f' in 'f(a,b,c)' is a function; it will be. * You will know whether the number of arguments provided is correct or not, and make adjustments at compile-time if not * Where keyword parameters are used, this can also all be sorted out at compile-time, rather than at runtime * (And does Python still need to do a lookup for the name 'f'? I don't know; the CPython sources are hard to follow. But in my interpreters, this is never necessary at runtime.) However, most functions will not be visible to the compiler because they are in imported modules. A certain amount of work can be done when a module is loaded, but this now starts to get complicated. > Even such simple things as constant folding are slightly controversial! If > you go back to older versions of Python, code like this: > > x = 1 + 1 > > actually performed the addition at runtime, instead of being compiled to: > > x = 2 > > Believe it or not, even something as simple as that remains controversial, Actually, it's not so simple! If floating point expressions are involved, the results can be different between compiler and runtime, if the compilation is done on a separate machine. But this is only a problem is byte-code is distributed rather than sources. -- BartC From steve at pearwood.info Sun Nov 8 06:11:20 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 08 Nov 2015 22:11:20 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <563ec66d$0$1614$c3e8da3$5496439d@news.astraweb.com> <878u68ygf2.fsf@elektro.pacujo.net> Message-ID: <563f2dda$0$1602$c3e8da3$5496439d@news.astraweb.com> On Sun, 8 Nov 2015 08:44 pm, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Sun, 8 Nov 2015 01:23 am, Marko Rauhamaa wrote: >>> Correct. That's not Python's fault, however. Python should not try to >>> placate the performance computing people. (Alas, it is now trying to >>> do just that with the introduction of static typing annotation.) >> >> That is factually incorrect. >> >> The motive behind the introduction of typing annotations is not "speed", >> but "correctness". > > Oh, then I'm even more disappointed with type annotation. /me does a double-take Wait a minute, you've just spent a bunch of paragraphs explaining that Python is plenty fast enough (for you), that you don't need it to be faster. Okay. Now you're saying that you're *even more* disappointed that type annotations will be used to make code *more correct* and *less buggy*. So... you have no need for Python to be fast, and even less need for Python code to be correct... Or perhaps you mean that you don't need help writing correct code, because your code is perfect... It is moments like this I wonder if you are trolling. -- Steven From bc at freeuk.com Sun Nov 8 06:19:50 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 11:19:50 +0000 Subject: Question about math.pi is mutable In-Reply-To: <87ziyowy83.fsf@elektro.pacujo.net> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On 08/11/2015 11:02, Marko Rauhamaa wrote: > Bartc : > >> (In the case of Python, the main obstacle is that a constant name from >> inside an imported module is not visible when this module is compiled >> to byte-code. So it has to assume it can be anything.) > > Which it can. .... > That elegant dynamism comes at a cost: method lookup is not a constant > memory offset. Rather, it is a dictionary lookup. I've never understood why this seems to be necessary in Python. Why do names have to be looked up? (I'm assuming this is searching by name in some sort of table.) When a module is compiled, while the compiler can't see the definitions inside the imported modules, it /will/ know all the names that appear in this module, so it can organise them into fixed tables. Then the names can be referred to by index. (I think LOAD_FAST does this.) Or is eval() the culprit here by making most optimisations impossible? -- Bartc From marko at pacujo.net Sun Nov 8 06:25:21 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 13:25:21 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <563ec66d$0$1614$c3e8da3$5496439d@news.astraweb.com> <878u68ygf2.fsf@elektro.pacujo.net> <563f2dda$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r3k0wx5q.fsf@elektro.pacujo.net> Steven D'Aprano : > So... you have no need for Python to be fast, and even less need for > Python code to be correct... Correct. If I didn't think so, I'd still be using Java instead of Python. > Or perhaps you mean that you don't need help writing correct code, > because your code is perfect... Python's noise-free syntax does more for code quality than compile-time type checking. Marko From steve at pearwood.info Sun Nov 8 06:30:03 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 08 Nov 2015 22:30:03 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <563f323d$0$1586$c3e8da3$5496439d@news.astraweb.com> On Sun, 8 Nov 2015 09:40 pm, Bartc wrote: > On 08/11/2015 02:59, Steven D'Aprano wrote: >> On Sun, 8 Nov 2015 02:01 am, Bartc wrote: >> >>> Neither have the simplicity of concept of Pascal's 'const', which is >>> just a named value. Not a variable that won't change once initialised, >>> not a parameter that won't be changed nor any addressable location.) >> >> Unfortunately the concept of "named value" doesn't match well with >> Python's design. That implies a separate compilation step which doesn't >> fit well with Python's runtime semantics. Very little happens at >> compile-time in Python that *must* happen at compile-time. >> >> I'm also not sure what difference you think there is between "named >> value" and "variable that won't change once initialised". > > This is what I mean about people not understanding it! I'm pretty sure I understand what *I* mean by constant, and what Pascal means by it, and why the Pascal meaning doesn't quite match what Python can do. I'm not sure I understand what *you* mean, or why you think a "variable that won't change" isn't good enough. > In NASM terms, a named constant is like: > > daysinweek equ 7 ; definition > > mov rax, daysinweek ; using it, as immediate value > mov rbx, daysinweek*2 ; an a 'compile-term' expression > ; mov daysinweek,8 ; can't be done! Illegal syntax In pseudo-Python, we have: const daysinweek = 7 # let's just pretend it exists x = daysinweek + 1 # this is fine daysinweek = 8 # an error Apart from the difference between compile-time and run-time, why would this not be satisfactory? Oh, and just to satisfy Ben, the determined monkey-patcher can write: globals()['daysinweek'] = 8 if they really want to defeat the compiler. The idea is to avoid *accidental* bindings. > While a 'const' variable, C style, might be: [...] Why does your C code look like assembler? > So in native code, a named value is not much different to a literal such > as 7, or 3.14159. (But unlike C's #define, the name is a proper symbol > with normal scope rules, and a type). > > The distinction at the machine level can be blurred with some > instructions sets where there might not be an immediate data option for > some data widths or types. Also where named constants are applied to > things such as strings, which necessarily use storage. I am not interested in the limitations of low-level machine languages. They have very little to say about what Python can or should do. > In the language however, you will not be able to use the named constant > as an lvalue, and you will usually be able to use it for compile-time > constant folding and for dimensioning fixed-bound arrays and such.) We're talking about Python, and how the concept of "const" might apply to a Python-like language. Compile-time constant folding is not part of it, because the constant itself might not exist at compile-time: const START = time.time() Fixed-bound arrays are irrelevant (neither lists nor arrays are fixed-bounds; tuples are, but they are constructed at runtime, not compile time). >> Python has a convention for "constants" -- all UPPERCASE names. The fact >> that the convention exists is enough to prove that the concept >> of "constant" is a useful one. The difference between Python's >> pseudo-constants and (say) Pascal's actual constants is that in Python, >> the burden of ensuring that neither you, nor any of the libraries you >> call, modifies the "constant" falls on you, the user, whereas in Pascal >> the compiler or interpreter performs that checking for you. > > With a real named constant the check can always be done at compile-time. > Unless you have a pure interpreter or some more elaborate way of > executing source code. Python has such a "more elaborate way" of executing source code: exec(""" if condition: import time const START = time.time() x = START + 1 """) -- Steven From marko at pacujo.net Sun Nov 8 06:50:35 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 13:50:35 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: <87mvuowvzo.fsf@elektro.pacujo.net> BartC : > On 08/11/2015 11:02, Marko Rauhamaa wrote: >> That elegant dynamism comes at a cost: method lookup is not a constant >> memory offset. Rather, it is a dictionary lookup. > > I've never understood why this seems to be necessary in Python. Why do > names have to be looked up? (I'm assuming this is searching by name in > some sort of table.) > > When a module is compiled, while the compiler can't see the > definitions inside the imported modules, it /will/ know all the names > that appear in this module, so it can organise them into fixed tables. > Then the names can be referred to by index. (I think LOAD_FAST does > this.) Modules are not the issue. Barely any functions are invoked from the modules. Rather, almost all invocations are object methods. (Of course, modules are objects, too.) Methods belong to objects that can be literally anything. Consider, for example, shutil.copyfileobj(src, dst[, length]) The shutil module has absolutely no idea what kind of objects src and dst are. An example program: ======================================================================== import shutil class Source: def __init__(self): self.remaining = "hello world" def read(self, count): if count <= 0: return "" chunk, self.remaining = self.remaining[:count], self.remaining[count:] return chunk class Dest: def write(self, stuff): print("<{}>".format(stuff)) shutil.copyfileobj(Source(), Dest()) ======================================================================== Marko From bc at freeuk.com Sun Nov 8 07:24:19 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 12:24:19 +0000 Subject: Question about math.pi is mutable In-Reply-To: <563f323d$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <563f323d$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/11/2015 11:30, Steven D'Aprano wrote: > On Sun, 8 Nov 2015 09:40 pm, Bartc wrote: >> This is what I mean about people not understanding it! > > I'm pretty sure I understand what *I* mean by constant, and what Pascal > means by it, and why the Pascal meaning doesn't quite match what Python can > do. I'm not sure I understand what *you* mean, or why you think a "variable > that won't change" isn't good enough. I showed you what I mean. A named constant is a just a value - with a label. That value doesn't need to be stored in a 'box' anywhere, in exactly the same manner as values that can be written to (and therefore at risk of being overwritten). But let me turn it around: why is it so important to use variables for this purpose? >> In NASM terms, a named constant is like: >> >> daysinweek equ 7 ; definition >> >> mov rax, daysinweek ; using it, as immediate value >> mov rbx, daysinweek*2 ; an a 'compile-term' expression >> ; mov daysinweek,8 ; can't be done! Illegal syntax > > In pseudo-Python, we have: > > const daysinweek = 7 # let's just pretend it exists > x = daysinweek + 1 # this is fine > daysinweek = 8 # an error > > Apart from the difference between compile-time and run-time, why would this > not be satisfactory? If that's all that's possible, that it will have to do. And might solve the OP's problem. But for a true named constant, there is no actual assignment. It really is not necessary. 'daysinweek' is just a synonym for '7'. > >> While a 'const' variable, C style, might be: > [...] > > Why does your C code look like assembler? I mean the 'const' is C style. The assembly code is to highlight the difference between what C calls a const, and what I call a named constant. > I am not interested in the limitations of low-level machine languages. They > have very little to say about what Python can or should do. OK, let's take a higher level one: const a = 2 var b = 3 c = a+b which might generate a byte-code like this: push_ci 2 push_m [b] add pop_m [c] Now apply this to Python byte-code. Can you not see the advantage of not having to deal with variable names, reference counts, garbage collection and all that? I don't know what you had in mind for implementing the pretend 'const' in your Python example above. But if it takes the form of an extra runtime attribute, then all variable accesses will be slowed then if it is has to be checked for every assignment, and 'const' names won't be any faster. >> In the language however, you will not be able to use the named constant >> as an lvalue, and you will usually be able to use it for compile-time >> constant folding and for dimensioning fixed-bound arrays and such.) > > We're talking about Python, and how the concept of "const" might apply to a > Python-like language. Compile-time constant folding is not part of it, > because the constant itself might not exist at compile-time: > > const START = time.time() You're thinking in C terms again. The C 'const' really means 'read-only' and applies to ordinary variables. It has nothing to do with my named constants which are always known at compile-time (That's if the definitions are visible. If not, then they will be known at the time the module they're in is compiled. Linking these is one of the problems in a Python implementation.) > Fixed-bound arrays are irrelevant (neither lists nor arrays are > fixed-bounds; tuples are, but they are constructed at runtime, not compile > time). Think of a possible 'switch' statement then, and the values for its case labels. > Python has such a "more elaborate way" of executing source code: > > > exec(""" > if condition: > import time > const START = time.time() > x = START + 1 > """) (1) That is not a const but a variable with a read-only attribute. The expression after the "=" should itself be a constant expression or a literal value. (No reason why Python shouldn't have such an attribute, but that's different from what I'm talking about.) (2) I assume that the contents of the string passed to exec() are first compiled to byte-code. Then that's the same as a normal compile, with the same problems of visibility and imparting its constant definitions to code that is compiled separately. (If the use 'exec' is more subtle, then we might as well give up!) -- BartC From rosuav at gmail.com Sun Nov 8 07:28:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Nov 2015 23:28:00 +1100 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On Sun, Nov 8, 2015 at 10:19 PM, BartC wrote: > I've never understood why this seems to be necessary in Python. Why do names > have to be looked up? (I'm assuming this is searching by name in some sort > of table.) Yes, if by "searching" you include hash-table lookup. A CPython dictionary is a *highly* optimized data structure, specifically because it's used virtually everywhere (I understand Lua's "table" type has similar optimizations for the same reason). In the common case, where your names come from literal text in the module, the strings used for the lookup will be interned constants, and their hashes will have been precalculated and stored, so the lookup is pretty easy. So it's a constant-time operation, and while that constant may be larger than a simple offset-and-fetch, it's still pretty fast in the overall scheme of things. ChrisA From benak.tomas at gmail.com Sun Nov 8 07:34:22 2015 From: benak.tomas at gmail.com (=?UTF-8?B?VG9tw6HFoSBCZcWIw6Fr?=) Date: Sun, 8 Nov 2015 13:34:22 +0100 Subject: Python 3.5.0: python.exe is not a valid Windows 32 application Message-ID: Hi, I have downloaded the Python 3.5.0 installer for x86 ( https://www.python.org/ftp/python/3.5.0/python-3.5.0.exe) and have installed it on my Windows XP SP3. The installer run to a successful end, but when I try to run python.exe, it ends with an error saying that python.exe is not a valid Windows 32 application. Is this a bug? Is my Windows XP a problem? Should I try another release of Python? Could you provide me with the link? Thank you. Best regards Tom?? Be??k From bc at freeuk.com Sun Nov 8 07:39:50 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 12:39:50 +0000 Subject: Question about math.pi is mutable In-Reply-To: <87mvuowvzo.fsf@elektro.pacujo.net> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <87mvuowvzo.fsf@elektro.pacujo.net> Message-ID: On 08/11/2015 11:50, Marko Rauhamaa wrote: > BartC : > >> On 08/11/2015 11:02, Marko Rauhamaa wrote: >>> That elegant dynamism comes at a cost: method lookup is not a constant >>> memory offset. Rather, it is a dictionary lookup. >> >> I've never understood why this seems to be necessary in Python. Why do >> names have to be looked up? (I'm assuming this is searching by name in >> some sort of table.) >> >> When a module is compiled, while the compiler can't see the >> definitions inside the imported modules, it /will/ know all the names >> that appear in this module, so it can organise them into fixed tables. >> Then the names can be referred to by index. (I think LOAD_FAST does >> this.) > > Modules are not the issue. Barely any functions are invoked from the > modules. Rather, almost all invocations are object methods. (Of course, > modules are objects, too.) Methods belong to objects that can be > literally anything. > > Consider, for example, > > shutil.copyfileobj(src, dst[, length]) > > The shutil module has absolutely no idea what kind of objects src and > dst are. An example program: > > ======================================================================== > import shutil > > class Source: > def __init__(self): > self.remaining = "hello world" > > def read(self, count): > if count <= 0: > return "" > chunk, self.remaining = self.remaining[:count], self.remaining[count:] > return chunk > > class Dest: > def write(self, stuff): > print("<{}>".format(stuff)) > > shutil.copyfileobj(Source(), Dest()) > ======================================================================== OK, so here, it is necessary to resolve "copyfileobj" by seeing if "shutil" is something that contains a name "copyfileobj" that happens to be a method. Is this the lookup you're talking about, and is it done using the actual string "copyfileobj"? If so, does it need to be done every single time this line is executed? It would extraordinarily inefficient if that was the case. -- Bartc From marko at pacujo.net Sun Nov 8 07:43:37 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 14:43:37 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <87mvuowvzo.fsf@elektro.pacujo.net> Message-ID: <87io5cwtja.fsf@elektro.pacujo.net> BartC : > On 08/11/2015 11:50, Marko Rauhamaa wrote: >> ======================================================================== >> import shutil >> >> class Source: >> def __init__(self): >> self.remaining = "hello world" >> >> def read(self, count): >> if count <= 0: >> return "" >> chunk, self.remaining = self.remaining[:count], self.remaining[count:] >> return chunk >> >> class Dest: >> def write(self, stuff): >> print("<{}>".format(stuff)) >> >> shutil.copyfileobj(Source(), Dest()) >> ======================================================================== > > OK, so here, it is necessary to resolve "copyfileobj" by seeing if > "shutil" is something that contains a name "copyfileobj" that happens > to be a method. > > Is this the lookup you're talking about, and is it done using the > actual string "copyfileobj"? If so, does it need to be done every > single time this line is executed? It would extraordinarily > inefficient if that was the case. No, what I'm talking about is that copyfileobj calls src.read() and dst.write() without having any idea what kinds of objects src and dst are. Thus, it will be difficult for a performance optimizer to get rid of the dictionary lookups. Marko From bc at freeuk.com Sun Nov 8 08:42:51 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 13:42:51 +0000 Subject: Question about math.pi is mutable In-Reply-To: <87io5cwtja.fsf@elektro.pacujo.net> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <87mvuowvzo.fsf@elektro.pacujo.net> <87io5cwtja.fsf@elektro.pacujo.net> Message-ID: On 08/11/2015 12:43, Marko Rauhamaa wrote: > BartC : > >> On 08/11/2015 11:50, Marko Rauhamaa wrote: >>> ======================================================================== >>> import shutil >>> >>> class Source: >>> def __init__(self): >>> self.remaining = "hello world" >>> >>> def read(self, count): >>> if count <= 0: >>> return "" >>> chunk, self.remaining = self.remaining[:count], self.remaining[count:] >>> return chunk >>> >>> class Dest: >>> def write(self, stuff): >>> print("<{}>".format(stuff)) >>> >>> shutil.copyfileobj(Source(), Dest()) >>> ======================================================================== >> >> OK, so here, it is necessary to resolve "copyfileobj" by seeing if >> "shutil" is something that contains a name "copyfileobj" that happens >> to be a method. >> >> Is this the lookup you're talking about, and is it done using the >> actual string "copyfileobj"? If so, does it need to be done every >> single time this line is executed? It would extraordinarily >> inefficient if that was the case. > > No, what I'm talking about is that copyfileobj calls src.read() and > dst.write() without having any idea what kinds of objects src and dst > are. Thus, it will be difficult for a performance optimizer to get rid > of the dictionary lookups. Sorry, you'll have to assume I'm very stupid. What exactly is being looked up, and in what? From what I can understand in your example: * You are calling shutil.copyfileobj with two arguments, which happen to be instances of classes Source and Dest. * Let's say these are known as src and dst inside .copyfileobj. * .copyfileobj then calls methods src.read() dst.write(). * Each of these method calls has the form A.B() which seems to me to be little different from shutil.copyfileobj(). So to get back to what I was saying, does this lookup involving searching for method B in object A, and if so, does it actually do a search by name? (Someone mentioned a precalculated hash, of "A", or of "src" or "dst", use used, but still, it's looking something up in a table, and a hash table lookup I believe still requires an string compare to check if you've got the right entry.) -- Bartc From ainoags02 at outlook.es Sun Nov 8 09:07:24 2015 From: ainoags02 at outlook.es (=?utf-8?B?QWlub2EgR3V0acOpcnJleiBTdcOhcmV6?=) Date: Sun, 8 Nov 2015 14:07:24 +0000 Subject: No subject Message-ID: it doesn?twork the entry to Python. Enviado desde Correo de Windows From marko at pacujo.net Sun Nov 8 09:33:00 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Nov 2015 16:33:00 +0200 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <87mvuowvzo.fsf@elektro.pacujo.net> <87io5cwtja.fsf@elektro.pacujo.net> Message-ID: <87egg0wogz.fsf@elektro.pacujo.net> BartC : >>> On 08/11/2015 11:50, Marko Rauhamaa wrote: >>>> ======================================================================== >>>> import shutil >>>> >>>> class Source: >>>> def __init__(self): >>>> self.remaining = "hello world" >>>> >>>> def read(self, count): >>>> if count <= 0: >>>> return "" >>>> chunk, self.remaining = self.remaining[:count], self.remaining[count:] >>>> return chunk >>>> >>>> class Dest: >>>> def write(self, stuff): >>>> print("<{}>".format(stuff)) >>>> >>>> shutil.copyfileobj(Source(), Dest()) >>>> ======================================================================== > > What exactly is being looked up, and in what? > > [...] > > So to get back to what I was saying, does this lookup involving > searching for method B in object A, and if so, does it actually do a > search by name? Yes, finding Source.read and Dest.write involves hash table lookups. In fact, it's even a bit more involved: each method fetch consists of *two* hash table lookups. First you have to check if the object has a match in its individual lookup table and next if there is a match in the class's lookup table. Marko From rosuav at gmail.com Sun Nov 8 10:11:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 02:11:26 +1100 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <87mvuowvzo.fsf@elektro.pacujo.net> <87io5cwtja.fsf@elektro.pacujo.net> Message-ID: On Mon, Nov 9, 2015 at 12:42 AM, BartC wrote: > Sorry, you'll have to assume I'm very stupid. > > What exactly is being looked up, and in what? > > From what I can understand in your example: > > * You are calling shutil.copyfileobj with two arguments, which happen to be > instances of classes Source and Dest. > > * Let's say these are known as src and dst inside .copyfileobj. > > * .copyfileobj then calls methods src.read() dst.write(). > > * Each of these method calls has the form A.B() which seems to me to be > little different from shutil.copyfileobj(). > > So to get back to what I was saying, does this lookup involving searching > for method B in object A, and if so, does it actually do a search by name? > > (Someone mentioned a precalculated hash, of "A", or of "src" or "dst", use > used, but still, it's looking something up in a table, and a hash table > lookup I believe still requires an string compare to check if you've got the > right entry.) The lookups I'm talking about happen pretty much anywhere. Firstly, this function: def f(): shutil.copyfileobj(src, dst) looks up the global name 'shutil' (that's one dict lookup - module globals are a dictionary), then performs an attribute lookup on the resulting object with the name 'copyfileobj', then looks up the two global names 'src' and 'dst'. In fact[1], those strings can be found in f.__code__.co_names, and the byte-code identifies them by their indices in that tuple. These are str objects (note that this means they can be any legal Unicode string; "?????.???????????(???, ???)" is just as valid), and their hashes will normally be precomputed to save time. Now, things are a bit different with function-locals; the compiler always knows which names they are, and it can compile things differently. Compare: def f(src): shutil.copyfileobj(src, dst) Instead of looking up a global name 'src', this now looks up a local name. They're identified by slot positions, so the compiler simply knows that "src" is in slot #0, and instead of looking anything up, simply says "load the thing in slot #0". There can also be other levels of indirection, such as __getattr__ and __getattribute__, which affect how stuff gets looked up. But otherwise, name lookups generally involve poking a dict with a string and taking what comes back (possibly replacing KeyError with NameError or AttributeError as the case may be). ChrisA [1] Assuming we're using CPython, or something which uses the same byte-code; this is NOT a language requirement - none of this is. From torriem at gmail.com Sun Nov 8 10:59:59 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 08 Nov 2015 08:59:59 -0700 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: <563F717F.3010007@gmail.com> On 11/08/2015 04:19 AM, BartC wrote: >> That elegant dynamism comes at a cost: method lookup is not a constant >> memory offset. Rather, it is a dictionary lookup. > > I've never understood why this seems to be necessary in Python. Why do > names have to be looked up? (I'm assuming this is searching by name in > some sort of table.) > > When a module is compiled, while the compiler can't see the definitions > inside the imported modules, it /will/ know all the names that appear in > this module, so it can organise them into fixed tables. Then the names > can be referred to by index. (I think LOAD_FAST does this.) > > Or is eval() the culprit here by making most optimisations impossible? Perhaps I'm misunderstanding what you're saying, here, but the reason a lookup has to be performed is because python variables are not like C variables. They aren't boxes per se. They are names bound to objects. so doing something like a += 1 Actually assigns the name "a" to an entirely new object than the one it had before, which, from the interpreters point of view, is in an entirely different memory location. Whereas in C, a variable is a box that's always at the same location, so the name is simply not important, and at runtime variables have no names. Python is not like this. names are important at runtime. There may be certain circumstances where the Python compiler could optimize certain types of variable access (say if the variable was bound to integers only) into C-style variables under the hood. But I don't think the benefit would be that great. From adiamond1978 at gmail.com Sun Nov 8 11:03:44 2015 From: adiamond1978 at gmail.com (Andrew Diamond) Date: Sun, 8 Nov 2015 08:03:44 -0800 (PST) Subject: [Ubuntu] PyQt5 In-Reply-To: References: Message-ID: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> On Saturday, November 7, 2015 at 10:13:25 PM UTC-5, Andrew Diamond wrote: > Hi! > > I'm fairly new to Python, and installed pyqt5 and began working through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ However, whenever I click one of the buttons or menus in the example apps I run that is supposed to quit the application, it locks up. This happens with all the examples I installed that handle code to quit the app. > > Running Ubuntu 15.10, and installed pyqt5 via: > > sudo apt-get install python3-pyqt5 > sudo apt-get install qtcreator > > Thank you in advance for any assistance! I just read somewhere that the issue could be because I was trying to run these examples from within Idle. However, when I try to run them from the terminal, I run into another snag: andrew at andrew-Satellite-P755:~/Programming/Python$ python tut8.py Traceback (most recent call last): File "tut8.py", line 16, in from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication ImportError: No module named PyQt5.QtWidgets ...a path issue? From rosuav at gmail.com Sun Nov 8 11:10:25 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 03:10:25 +1100 Subject: Python 3.5.0: python.exe is not a valid Windows 32 application In-Reply-To: References: Message-ID: On Sun, Nov 8, 2015 at 11:34 PM, Tom?? Be??k wrote: > I have downloaded the Python 3.5.0 installer for x86 ( > https://www.python.org/ftp/python/3.5.0/python-3.5.0.exe) and have > installed it on my Windows XP SP3. The installer run to a successful end, > but when I try to run python.exe, it ends with an error saying that > python.exe is not a valid Windows 32 application. > Is this a bug? Is my Windows XP a problem? Should I try another release of > Python? Could you provide me with the link? Your Windows XP is a problem. You have a couple of options: either upgrade to Vista/7/8/10, or downgrade your Python to 3.4, which does support XP. There is also a bug, which is that the installer appears to run successfully. When Python 3.5.1 is released (currently scheduled for early December), the installer should detect XP early on and save you the confusion. ChrisA From lac at openend.se Sun Nov 8 11:15:18 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 08 Nov 2015 17:15:18 +0100 Subject: Python 3.5.0: python.exe is not a valid Windows 32 application In-Reply-To: References: Message-ID: <201511081615.tA8GFItB025380@fido.openend.se> In a message of Sun, 08 Nov 2015 13:34:22 +0100, Tom?? Be??k writes: >Hi, > >I have downloaded the Python 3.5.0 installer for x86 ( >https://www.python.org/ftp/python/3.5.0/python-3.5.0.exe) and have >installed it on my Windows XP SP3. The installer run to a successful end, >but when I try to run python.exe, it ends with an error saying that >python.exe is not a valid Windows 32 application. >Is this a bug? Is my Windows XP a problem? Should I try another release of >Python? Could you provide me with the link? >Thank you. > >Best regards >Tom?? Be??k This is an XP problem. XP is not supported for 3.5 and later. The latest you can run is 3.4.3 https://www.python.org/downloads/release/python-343/ Laura From rosuav at gmail.com Sun Nov 8 11:17:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 03:17:02 +1100 Subject: how to copy PyObject * memory data to another memory address? In-Reply-To: <1446902615952.dslp41enande24vd1gfb0x4r@android.mail.163.com> References: <1446902615952.dslp41enande24vd1gfb0x4r@android.mail.163.com> Message-ID: On Sun, Nov 8, 2015 at 12:23 AM, yueyoum wrote: > I'm working on a C program that has Python embedded. The host program is multi processes, which communicate via shared memory (mmap). I create a Python object (e.g., PyDict_New) in one process. How can I copy this data to shared memory so that the other process can obtain this data and convert to Python Object? ???????? > The best way to do this would be to serialize it in some format - JSON is a good choice, if all your data can fit into that format; otherwise, consider the Pickle format. Python objects consist of lots of references to other objects, so it's difficult to transfer them from one to another as they are. JSON will serve you well. ChrisA From rosuav at gmail.com Sun Nov 8 11:22:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 03:22:07 +1100 Subject: [Ubuntu] PyQt5 In-Reply-To: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> References: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> Message-ID: On Mon, Nov 9, 2015 at 3:03 AM, Andrew Diamond wrote: > On Saturday, November 7, 2015 at 10:13:25 PM UTC-5, Andrew Diamond wrote: >> Hi! >> >> I'm fairly new to Python, and installed pyqt5 and began working through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ However, whenever I click one of the buttons or menus in the example apps I run that is supposed to quit the application, it locks up. This happens with all the examples I installed that handle code to quit the app. >> >> Running Ubuntu 15.10, and installed pyqt5 via: >> >> sudo apt-get install python3-pyqt5 >> sudo apt-get install qtcreator >> >> Thank you in advance for any assistance! > > I just read somewhere that the issue could be because I was trying to run these examples from within Idle. However, when I try to run them from the terminal, I run into another snag: > > andrew at andrew-Satellite-P755:~/Programming/Python$ python tut8.py > Traceback (most recent call last): > File "tut8.py", line 16, in > from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication > ImportError: No module named PyQt5.QtWidgets > > ...a path issue? If you installed "python3-pyqt5", you probably want to run "python3 tut8.py". There are potentially two completely separate Python interpreters installed - version 2.7, and the latest available version 3.x (probably 3.4 or 3.5). You've installed a package for Python 3, but haven't installed the corresponding Python 2 package, so it won't run under the Python 2 interpreter. Compare these: $ python --version $ python3 --version I suspect that "python3 tut8.py" should work. If it doesn't, post some more info about your Idle installation; it might give a hint as to what's going on. ChrisA From adiamond1978 at gmail.com Sun Nov 8 11:27:16 2015 From: adiamond1978 at gmail.com (Andrew Diamond) Date: Sun, 8 Nov 2015 08:27:16 -0800 (PST) Subject: [Ubuntu] PyQt5 In-Reply-To: References: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> Message-ID: <5c057628-f45a-4734-bdda-8472c9ad9632@googlegroups.com> On Sunday, November 8, 2015 at 11:22:30 AM UTC-5, Chris Angelico wrote: > On Mon, Nov 9, 2015 at 3:03 AM, Andrew Diamond wrote: > > On Saturday, November 7, 2015 at 10:13:25 PM UTC-5, Andrew Diamond wrote: > >> Hi! > >> > >> I'm fairly new to Python, and installed pyqt5 and began working through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ However, whenever I click one of the buttons or menus in the example apps I run that is supposed to quit the application, it locks up. This happens with all the examples I installed that handle code to quit the app. > >> > >> Running Ubuntu 15.10, and installed pyqt5 via: > >> > >> sudo apt-get install python3-pyqt5 > >> sudo apt-get install qtcreator > >> > >> Thank you in advance for any assistance! > > > > I just read somewhere that the issue could be because I was trying to run these examples from within Idle. However, when I try to run them from the terminal, I run into another snag: > > > > andrew at andrew-Satellite-P755:~/Programming/Python$ python tut8.py > > Traceback (most recent call last): > > File "tut8.py", line 16, in > > from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication > > ImportError: No module named PyQt5.QtWidgets > > > > ...a path issue? > > If you installed "python3-pyqt5", you probably want to run "python3 > tut8.py". There are potentially two completely separate Python > interpreters installed - version 2.7, and the latest available version > 3.x (probably 3.4 or 3.5). You've installed a package for Python 3, > but haven't installed the corresponding Python 2 package, so it won't > run under the Python 2 interpreter. Compare these: > > $ python --version > $ python3 --version > > I suspect that "python3 tut8.py" should work. If it doesn't, post some > more info about your Idle installation; it might give a hint as to > what's going on. > > ChrisA You were absolutely correct! $ python3 tut8.py ...worked great, thanks!! From lac at openend.se Sun Nov 8 11:57:04 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 08 Nov 2015 17:57:04 +0100 Subject: =?US-ASCII?Q?how_to_copy_PyObject_*_memory_d?= =?US-ASCII?Q?ata_to_another_memory_address=3F=0A=0A?= In-Reply-To: <1446902615952.dslp41enande24vd1gfb0x4r@android.mail.163.com> References: <1446902615952.dslp41enande24vd1gfb0x4r@android.mail.163.com> Message-ID: <201511081657.tA8Gv4dL028917@fido.openend.se> In a message of Sat, 07 Nov 2015 21:23:51 +0800, yueyoum writes: >I'm working on a C program that has Python embedded. The host program is multi processes, which communicate via shared memory (mmap). I create a Python object (e.g., PyDict_New) in one process. How can I copy this data to shared memory so that the other process can obtain this data and convert to Python Object? ???????? >-- >https://mail.python.org/mailman/listinfo/python-list It is not clear that what you want to do can be done in the general sense. See Alex Martelli's explanation here: tackoverflow.com/questions/1268252/python-possible-to-share-in-memory-data-between-2-separate-processes/1269055#1269055 Any chance that instead of trying to share a PyDict you could share an array? If so, multiprocessing will work for you. Or the last reference there is to some lower level inter process communication things you can use in Python. I have never tried them, so have no idea how well written the code is. Laura From torriem at gmail.com Sun Nov 8 12:04:06 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 08 Nov 2015 10:04:06 -0700 Subject: Puzzled In-Reply-To: <4CFEDC132D44AC49BA0E91FBEB947119084AAD2A1E@DCBL123VX.root.sutterhealth.org> References: <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> <201511011020.tA1AKYAM004182@fido.openend.se> <4CFEDC132D44AC49BA0E91FBEB947119084A8D5E6C@DCBL123VX.root.sutterhealth.org> <563CADCD.8070307@gonnerman.org> <4CFEDC132D44AC49BA0E91FBEB947119084AAD2A1E@DCBL123VX.root.sutterhealth.org> Message-ID: <563F8086.7010302@gmail.com> On 11/06/2015 02:36 PM, Robinson, Wendy wrote: > Ah, ok.... I get it now. > Thanks both! Glad you got it! Thanks for letting us know, too. From bc at freeuk.com Sun Nov 8 12:54:57 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 17:54:57 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On 08/11/2015 15:59, Michael Torrie wrote: > On 11/08/2015 04:19 AM, BartC wrote: > >>> That elegant dynamism comes at a cost: method lookup is not a constant >>> memory offset. Rather, it is a dictionary lookup. >> >> I've never understood why this seems to be necessary in Python. Why do >> names have to be looked up? (I'm assuming this is searching by name in >> some sort of table.) >> >> When a module is compiled, while the compiler can't see the definitions >> inside the imported modules, it /will/ know all the names that appear in >> this module, so it can organise them into fixed tables. Then the names >> can be referred to by index. (I think LOAD_FAST does this.) >> >> Or is eval() the culprit here by making most optimisations impossible? > > Perhaps I'm misunderstanding what you're saying, here, but the reason a > lookup has to be performed is because python variables are not like C > variables. They aren't boxes per se. They are names bound to objects. > so doing something like > > a += 1 > > Actually assigns the name "a" to an entirely new object than the one it > had before, which, from the interpreters point of view, is in an > entirely different memory location. That would be true for locals as well. But as far as I can tell from the CPython source code, byte-codes uses an index to represent a local, which represents an entry into a linear table. I can't quite see why that can't be done for global names and for attributes too (ie. the names that follow a "."). Attributes are a more difficult because there can be multiple instances of each name, and Python won't know which one is meant, so it needs to be resolved at each use. So in the case of A.B(), Python apparently looks up "B" in the names associated with object A (and also, someone said, with the class of which A is an instance if the first lookup fails). I had in mind a different approach, where a table exists for each different attribute, which contains an entry for each owner class. Usually this table will be small, or will have just one entry, so is quick to search. However, another feature of Python makes that impractical: the ability of any instance of a class to have arbitrary sets of attributes. There could be millions of such instances, all named "B". Now, if methods could only be part of a class definition, then with A.B() rather than A.B, there will be a limited number of classes that could have a method "B", so the short table idea could work. But then, A.B could be assigned the name of a function, which is then called using A.B(), the same as method-calling syntax! So it looks like Python is stuck with its name lookups. -- Bartc From rosuav at gmail.com Sun Nov 8 13:01:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 05:01:21 +1100 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On Mon, Nov 9, 2015 at 4:54 AM, BartC wrote: > That would be true for locals as well. But as far as I can tell from the > CPython source code, byte-codes uses an index to represent a local, which > represents an entry into a linear table. > > I can't quite see why that can't be done for global names and for attributes > too (ie. the names that follow a "."). At compilation time, the set of local names is locked in permanently. That's not true of any other namespace (except nonlocals, which are still locals, just not yours). Attributes and global names (which are attributes of the current module) can be added and removed dynamically, so they can't be assigned to slots; attributes can even be simulated via __getattr__ and __getattribute__. ChrisA From no.email at nospam.invalid Sun Nov 8 13:28:24 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 08 Nov 2015 10:28:24 -0800 Subject: [ANN] MicroPython 1.5 References: Message-ID: <87ziyotkfr.fsf@nightsong.com> Paul Sokolovsky writes: > Recent 1.5 release is an important milestone for the project, major > changes including: Thanks for posting this. We don't hear enough about MicroPython on this newsgroup so it's good to get these announcements. Is the language still Python 3.4? Will it implement 3.5 sometime soon? > 1. Advanced REPL support with smart auto-indent and auto-completion Hmm does this make the code footprint significantly bigger? > 2. Support for client SSL connections. Nice. Does it check the server certificate? Is it based on TLSLite by any chance? > 5. There're now 2 well-supported microcontroller boards for > MicroPython, and dozen(s) community-supported ones. The PyBoard is very nice, but what is the other one? I don't see anything about it on the MicroPython web site. (Hmm, maybe you mean the Micro Bit). Btw, I notice that the "store" page doesn't show any products under my normal adblock settings. It's probably best to make it a normal page instead of an AJAX one. > MicroPython supports growing subset of Python3 standard library > (including simplified asyncio package) This would look much nicer with the new Python 3.5 syntax. From bc at freeuk.com Sun Nov 8 13:58:36 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 18:58:36 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On 08/11/2015 18:01, Chris Angelico wrote: > On Mon, Nov 9, 2015 at 4:54 AM, BartC wrote: >> That would be true for locals as well. But as far as I can tell from the >> CPython source code, byte-codes uses an index to represent a local, which >> represents an entry into a linear table. >> >> I can't quite see why that can't be done for global names and for attributes >> too (ie. the names that follow a "."). > > At compilation time, the set of local names is locked in permanently. > That's not true of any other namespace (except nonlocals, which are > still locals, just not yours). Attributes and global names (which are > attributes of the current module) can be added and removed > dynamically, so they can't be assigned to slots; attributes can even > be simulated via __getattr__ and __getattribute__. Yes, that's yet another way that the language design makes things difficult (for those who want to streamline its implementation). For most purposes, the set of attribute names that can follow a dot are limited and fixed, by the occurrences of such names in a source file. So they can be assigned a slot. But then, you say that additional attributes, potentially millions of different ones, can be invented at runtime. Although I don't see how it can remove names that are part of the source code: if "A.B" is in the file, then surely "A" and "B" always have to be present in some table or other. -- Bartc From paul.hermeneutic at gmail.com Sun Nov 8 14:08:20 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sun, 8 Nov 2015 12:08:20 -0700 Subject: [ANN] MicroPython 1.5 In-Reply-To: <87ziyotkfr.fsf@nightsong.com> References: <87ziyotkfr.fsf@nightsong.com> Message-ID: What is the possibility that MicroPython could be another build from the base python.org sources? Python already gets built for a variety of architectures. Could a MicroPython be another one? In that way, it would always be up to date on language changes. On Sun, Nov 8, 2015 at 11:28 AM, Paul Rubin wrote: > Paul Sokolovsky writes: > > Recent 1.5 release is an important milestone for the project, major > > changes including: > > Thanks for posting this. We don't hear enough about MicroPython on > this newsgroup so it's good to get these announcements. > > Is the language still Python 3.4? Will it implement 3.5 sometime soon? > > > 1. Advanced REPL support with smart auto-indent and auto-completion > > Hmm does this make the code footprint significantly bigger? > > > 2. Support for client SSL connections. > > Nice. Does it check the server certificate? Is it based on TLSLite by > any chance? > > > 5. There're now 2 well-supported microcontroller boards for > > MicroPython, and dozen(s) community-supported ones. > > The PyBoard is very nice, but what is the other one? I don't see > anything about it on the MicroPython web site. (Hmm, maybe you mean the > Micro Bit). > > Btw, I notice that the "store" page doesn't show any products under my > normal adblock settings. It's probably best to make it a normal page > instead of an AJAX one. > > > MicroPython supports growing subset of Python3 standard library > > (including simplified asyncio package) > > This would look much nicer with the new Python 3.5 syntax. > -- > https://mail.python.org/mailman/listinfo/python-list > From ian.g.kelly at gmail.com Sun Nov 8 14:51:03 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 8 Nov 2015 12:51:03 -0700 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On Nov 8, 2015 12:01 PM, "BartC" wrote: > > But then, you say that additional attributes, potentially millions of different ones, can be invented at runtime. Although I don't see how it can remove names that are part of the source code: if "A.B" is in the file, then surely "A" and "B" always have to be present in some table or other. Gratuitous example: def factory(name): class inner: # stuff inner.__name__ = name return inner One = factory('One') Two = factory('Two') # factory is no longer needed, so remove it from globals. del factory From pmiscml at gmail.com Sun Nov 8 15:27:58 2015 From: pmiscml at gmail.com (Paul Sokolovsky) Date: Sun, 8 Nov 2015 22:27:58 +0200 Subject: [ANN] MicroPython 1.5 In-Reply-To: <87ziyotkfr.fsf@nightsong.com> References: <87ziyotkfr.fsf@nightsong.com> Message-ID: <20151108222758.67e86320@x230> Hello, On Sun, 08 Nov 2015 10:28:24 -0800 Paul Rubin wrote: > Paul Sokolovsky writes: > > Recent 1.5 release is an important milestone for the project, major > > changes including: > > Thanks for posting this. We don't hear enough about MicroPython on > this newsgroup so it's good to get these announcements. > > Is the language still Python 3.4? Will it implement 3.5 sometime > soon? Yes, we already implement the most important 3.5 feature - ability to format bytes: b"foo%s" % b"bar" ;-). > > 1. Advanced REPL support with smart auto-indent and auto-completion > > Hmm does this make the code footprint significantly bigger? No, as everything else in MicroPython, code implementing this feature is well-optimized, it did cost few hundreds of bytes to implement. > > 2. Support for client SSL connections. > > Nice. Does it check the server certificate? The driving force for adding SSL was being able to download package from PyPI (for builtin upip package manager). Unfortunately, PyPI forces SSL, so previously we had to fallback to wget for downloads, which limited upip to unix-like systems. So, the way we use SSL is as bloated plain HTTP, just to workaround PyPI's maintainers' decision to raise the bar too high to access it. Consequently, nobody yet worked on certificate checking and other stuff. > Is it based on TLSLite by any chance? I had an idea to port TLSLite and even submitted couple of patches to it, I had an idea to write a module titled "insecureSSL" which would just emulate SSL by doing as little as possible processing and using static session keys, etc. - just to prove the point that there can't be security without both parties consenting, and mis-applied "security" is nothing but a denial-of-service. But I gave up in the end, deciding to take that productively and add generic SSL client support using axTLS library (which was also optimized to meet MicroPython code size standards). (You see, these questions touched ranty feelings - thanks for asking ;-) ). > > 5. There're now 2 well-supported microcontroller boards for > > MicroPython, and dozen(s) community-supported ones. > > The PyBoard is very nice, but what is the other one? I don't see > anything about it on the MicroPython web site. (Hmm, maybe you mean > the Micro Bit). It's WiPy, http://wipy.io/ , WiFi-enabled board which had successful kickstarter in the spring and last month shipped ready boards. Micro Bit would take some time before general availability of course. > Btw, I notice that the "store" page doesn't show any products under my > normal adblock settings. It's probably best to make it a normal page > instead of an AJAX one. > > > MicroPython supports growing subset of Python3 standard library > > (including simplified asyncio package) > > This would look much nicer with the new Python 3.5 syntax. There was initial patch to add initial async/await support a week within corresponding PEP was initially posted. But we decided not to haste with it, or we can add feature which nobody really uses (while we have bunch of features which almost everyone would use, but which aren't yet there). So, we decided yo do our homework, and let asyncio/async-await people do theirs on popularizing it (every 10th Python programmer using it seems like good target, now it's probably every 10,000th if not 100,000th). Thanks for the feedback! -- Best regards, Paul mailto:pmiscml at gmail.com From pmiscml at gmail.com Sun Nov 8 15:53:33 2015 From: pmiscml at gmail.com (Paul Sokolovsky) Date: Sun, 8 Nov 2015 22:53:33 +0200 Subject: [ANN] MicroPython 1.5 In-Reply-To: References: <87ziyotkfr.fsf@nightsong.com> Message-ID: <20151108225333.776b9ee0@x230> Hello, On Sun, 8 Nov 2015 12:08:20 -0700 paul.hermeneutic at gmail.com wrote: > What is the possibility that MicroPython could be another build from > the base python.org sources? Python already gets built for a variety > of architectures. Could a MicroPython be another one? In that way, it > would always be up to date on language changes. There's zero possibility for this - MicroPython is from-scratch implementation carefully optimized for code size and memory usage, that's how it's up to 50 times smaller than CPython and can run with ~1000 times less RAM than CPython usually runs with. Support for the latest features is not the aim of MicroPython, instead it's being able to use the same great language on systems where CPython simply could never run. That necessitates being on a diet and leaving out not just the latest lesser-known features, but even quite a few of old more widely known ones. That said, the core of the language is there and any Python programmer should feel straight at home. And it's Python*3*, so it's pretty fresh anyway, knowing that half of our community still sits on Python2 and never tried Python3. (Hacking on MicroPython is how I get to use Python3 myself, on my dayjob we still use Python2). [] -- Best regards, Paul mailto:pmiscml at gmail.com From ben+python at benfinney.id.au Sun Nov 8 16:00:34 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2015 08:00:34 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: <85lha8i4ul.fsf@benfinney.id.au> BartC writes: > I've never understood why this seems to be necessary in Python. Why do > names have to be looked up? (I'm assuming this is searching by name in > some sort of table.) No, it is literally looking the name up as a key in a namespace dictionary ? which is just like any other Python dictionary, but nominated internally for use as the namespace dictionary. The distinction is important, because like any other dictionary it can change at run-time and the bindings between name and value can change, can be added, and can be removed. > When a module is compiled, while the compiler can't see the > definitions inside the imported modules, it /will/ know all the names > that appear in this module, so it can organise them into fixed tables. Not true. The namespace can change dynamically, which is another way of what people have been trying to tell you all through this thread. The compiler *cannot* know what the names will be at every single point they'll be looked un in the namespace dictionary. This dynamism of each namespace is a Python feature. -- \ ?It is ? incumbent upon us to recognize that it is | `\ inappropriate for religion to play any role in issues of state | _o__) [of] a modern democracy.? ?Lawrence M. Krauss, 2012-05-28 | Ben Finney From kent at z-sverige.nu Sun Nov 8 16:27:06 2015 From: kent at z-sverige.nu (kent nyberg) Date: Sun, 8 Nov 2015 16:27:06 -0500 Subject: using binary in python Message-ID: <20151108212706.GA29701@z-sverige.nu> Hi there, Lets say I want to play around with binary files in python. Opening and using files in python is something that I think I've sort of got the hang of. The thing im wondering about is binary files. While searching for binary and python I started reading about bin(). I can use bin() to convert integers to binary. Now, I thought.. some way it should be possible to write "binary" files. That is, non ascii-files. For example, on Linux, if I run the command 'less' on a binary; for example /bin/ls, then the command asks me if I really want to do it, since its a binary file. I know why, since the non ascii-stuff messes up the terminal, and most likely since you rarely want to look at a binary file with less. Well, lets assume I want to write and read binary. How is it done? The built in bin() function only converts integers to binary but the variable or return is still just letters right? Converting the integer '1' to binary with bin() return 0b1. Which is ok. Its the binary representation of integer 1. But since.. there is files which contains data that is not representable as ascii, then I assume it can be written. But can it by Python? Ok, I get the feeling now that its hard to understand my question. I assume in the C language its just matter of writing a complex struct with strange variables and just write it to a file. But in python..? Can some one give a short explenation of a python write to file, that makes it a binary file? Thanks alot, and forgive me for my stupid questions. :) /Kent Nyberg From rosuav at gmail.com Sun Nov 8 16:47:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 08:47:38 +1100 Subject: [ANN] MicroPython 1.5 In-Reply-To: <20151108225333.776b9ee0@x230> References: <87ziyotkfr.fsf@nightsong.com> <20151108225333.776b9ee0@x230> Message-ID: On Mon, Nov 9, 2015 at 7:53 AM, Paul Sokolovsky wrote: > On Sun, 8 Nov 2015 12:08:20 -0700 > paul.hermeneutic at gmail.com wrote: > >> What is the possibility that MicroPython could be another build from >> the base python.org sources? Python already gets built for a variety >> of architectures. Could a MicroPython be another one? In that way, it >> would always be up to date on language changes. > > There's zero possibility for this - MicroPython is from-scratch > implementation carefully optimized for code size and memory usage, > that's how it's up to 50 times smaller than CPython and can run with > ~1000 times less RAM than CPython usually runs with. Putting this another way: MicroPython is a *different implementation* of Python, which just happens to be in the same language as CPython. A number of Python implementations are listed here: https://wiki.python.org/moin/PythonImplementations Each one is a distinct implementation of (some version of) the same language spec called "Python", which is different from a build target of CPython. For example, there are several implementations designed to run inside a web browser, and while it's theoretically possible to port some other Python implementation to JavaScript (which is what PyPyJS did with PyPy), it's usually easier to instead implement something specifically in/for JS (eg Brython). There's no way to say "CPython, go build yourself for the platform known as Mozilla Firefox", because that would be hopelessly inefficient. ChrisA From andre.roberge at gmail.com Sun Nov 8 17:02:39 2015 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Sun, 8 Nov 2015 14:02:39 -0800 (PST) Subject: python PEP suggestion In-Reply-To: References: Message-ID: On Sunday, 8 November 2015 11:35:32 UTC-4, Dan Strohl wrote: > All, > > I wanted to run the following thought past the list as a possible PEP enhancement suggestion to see if it feels like something that is worth proposing. I know it is not in the PEP format at this point, I can, and will, clean it up if needed, I am just trying to throw it against the wall at this point to see if it resonates... (or if it falls flat and goes "splat" ). > > Thoughts? > > Dan Strohl > Snip You might want to post this to the python-ideas list. Andr? From tjreedy at udel.edu Sun Nov 8 17:26:36 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 8 Nov 2015 17:26:36 -0500 Subject: python PEP suggestion In-Reply-To: References: Message-ID: On 11/6/2015 1:21 PM, Dan Strohl wrote: > All, > > I wanted to run the following thought past the list as a possible PEP enhancement suggestion to see if it feels like something that is worth proposing. I know it is not in the PEP format at this point, I can, and will, clean it up if needed, I am just trying to throw it against the wall at this point to see if it resonates... (or if it falls flat and goes "splat" ). > > Thoughts? At first glance, plausible, but I am not sure needed, and it seems a bit contrary to how Python currently works. > New special method name to allow for more flexible object type casting/access, and extend type() to cast objects using this special method name. > > Overview: > > Have a new special method name that would allow a given objects to request information from another object in a given type, or to cast an object into a different type, and extend the built in type() function to use this. > > Rationale: > There is currently __str__, __int__, and __bool__ that allow me to tell an object how it should reply to a request for these types of basic data types. However if I want to access a copy of the objet in dict form, or as a list, or if I am trying to convert something using json, there is no standard way of doing that for a custom object (I know I can do __getitem__ and/or __iter__, but I many processes don't try these if the object is not a subclass of dict or list/tuple) Conditional execution, indexing (__index__), numeric conversions (__float__ also), and displaying are special cases related to syntax operations. Functions that unnecessarily restrict inputs to subclasses of list or dict will not be solved by this. You have left out the use of abstract base classes. An iterable that can be used as a mapping can register itself as a mapping. Json could check whether something is a sequence or mapping and iterate to get values or pairs of values. Of course, the tranformation would be unidirectional. > Proposal: > What I am proposing is something like: > > object.__cast__(self, to_class): > """ > to_class: the class type that you wish to return. > """ The excessive indents of 31 and 15 spaces make the rest of this post unnecessarily hard to read. -- Terry Jan Reedy From bc at freeuk.com Sun Nov 8 17:35:06 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 22:35:06 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On 08/11/2015 21:00, Ben Finney wrote: > BartC writes: > >> I've never understood why this seems to be necessary in Python. Why do >> names have to be looked up? (I'm assuming this is searching by name in >> some sort of table.) > > No, it is literally looking the name up as a key in a namespace > dictionary ? which is just like any other Python dictionary, but > nominated internally for use as the namespace dictionary. > > The distinction is important, because like any other dictionary it can > change at run-time and the bindings between name and value can change, > can be added, and can be removed. That part is not a problem. >> When a module is compiled, while the compiler can't see the >> definitions inside the imported modules, it /will/ know all the names >> that appear in this module, so it can organise them into fixed tables. > > Not true. The namespace can change dynamically, which is another way of > what people have been trying to tell you all through this thread. > > The compiler *cannot* know what the names will be at every single point > they'll be looked un in the namespace dictionary. This dynamism of each > namespace is a Python feature. Suppose this is the python program: import m a=10 b=20 c=30 m.f() The set of global names the compiler knows will be ("m","a","b","c"). I don't believe code can remove these names (that would cause problems). You say the set of global names can be added to - after this lot, but I can't see that the first four are going to change. Therefore these names could be referred to by index. Attributes are harder because they are more of a free-for-all, but suppose you do have m.f(). "m" is easy, it's entry 0 in the global table for this module, so no lookup-by-name is needed. You examine it, and it's a module. It's now necessary to find f within the global table for m. This is where it gets tricky if you want to avoid a lookup. And I expect you will say that any code can randomly add names within the global table of m. But bear with me. Suppose the interpreter were to maintain a table for each static (not runtime) attribute encountered in the source code. The compile can produce empty tables for the attributes it's seen. In this case the table for "f" would be empty: (). The compiler will also produce a list of such tables for all attributes. Here there is only one, and the "f" table will have index 0, which is what can be used within the byte-code. The hard part would be in building and maintaining that table. When module m is loaded, let's say it defines function "f". Now that can be used to create the first entry in the attribute table for "f": ($m, $m.f). Here, $m is some internal reference to m, and $m.f is some internal reference to m.f(). Now back to resolving m.f(): we know the "m" part is module $m. For "f", it looks through its attribute table (remember it's index 0, so instant access), and there is only one entry. We're lucky as that entry's owner matches the "m." part of this access. So we know it refers to $m.f. No lookups by name needed in this case. However not all random attributes will be neatly defined somewhere as functions or classes that will be listed in these little tables. So sometimes, an actual lookup will still be needed. -- Bart C From ben+python at benfinney.id.au Sun Nov 8 17:54:20 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2015 09:54:20 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: <857flshzkz.fsf@benfinney.id.au> BartC writes: > On 08/11/2015 21:00, Ben Finney wrote: > > The namespace can change dynamically, which is another way of what > > people have been trying to tell you all through this thread. > > > > The compiler *cannot* know what the names will be at every single > > point they'll be looked un in the namespace dictionary. This > > dynamism of each namespace is a Python feature. > > Suppose this is the python program: > > import m > a=10 > b=20 > c=30 > m.f() > > The set of global names the compiler knows will be ("m","a","b","c"). > > I don't believe code can remove these names (that would cause > problems). It may indeed cause problems. Those names can nevertheless be changed. Names at module level are simply attributes on the module object. The module can gain attributes, lose attributes, and its attributes can chage; its namespace is just as mutable as any other object's namespace. > You say the set of global names can be added to - after this lot, but > I can't see that the first four are going to change. You have not yet learned enough about the Python data model: A module object has a namespace implemented by a dictionary object (this is the dictionary referenced by the __globals__ attribute of functions defined in the module). Attribute references are translated to lookups in this dictionary, e.g., m.x is equivalent to m.__dict__["x"]. A module object does not contain the code object used to initialize the module (since it isn?t needed once the initialization is done). Any name can be deleted, just like any other reference, with the ?del? statement. Any reference (including names) can be added or changed in a module namespace like any other object's namespace. > Attributes are harder because they are more of a free-for-all Please understand that a module *is* an object, and a name in a module's namespace *is* an attribute on that module. Also, please *learn about* the way Python works; you have certainly been here long enough to know how to look up answers in the documentation instead of making ignorant assertions here. -- \ ?What I resent is that the range of your vision should be the | `\ limit of my action.? ?Henry James | _o__) | Ben Finney From tjreedy at udel.edu Sun Nov 8 18:05:32 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 8 Nov 2015 18:05:32 -0500 Subject: [Ubuntu] PyQt5 In-Reply-To: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> References: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> Message-ID: On 11/8/2015 11:03 AM, Andrew Diamond wrote: > On Saturday, November 7, 2015 at 10:13:25 PM UTC-5, Andrew Diamond > wrote: >> Hi! >> >> I'm fairly new to Python, and installed pyqt5 and began working >> through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ >> However, whenever I click one of the buttons or menus in the >> example apps I run that is supposed to quit the application, it >> locks up. What is 'it'? And what does 'lock up' mean? Did the gui freeze and not disappear? Or did IDLE itself freeze, and even the menu quit working? >> This happens with all the examples I installed that >> handle code to quit the app. >> >> Running Ubuntu 15.10, and installed pyqt5 via: >> >> sudo apt-get install python3-pyqt5 sudo apt-get install qtcreator > I just read somewhere that the issue could be because I was trying to > run these examples from within Idle. I am an IDLE maintainer. Am I to take it that everything ran fine before you tried to quit? If not, I would want to know why and try to fix. If you run tut.py from an IDLE editor, IDLE tries to run it the same as if you ran it at a console in the tut.py directory with 'python3 -i tut.py'. I can imagine that there might be a problem with the transition from gui mode to interactive shell mode, though it works for tkinter apps. You said 'python3 tut.py' works. What happens if you add the '-i' option? I'd like to know if the transition problem is in (Py)qt5 or in IDLE's simulation of '-i'. -- Terry Jan Reedy From bc at freeuk.com Sun Nov 8 18:54:15 2015 From: bc at freeuk.com (BartC) Date: Sun, 8 Nov 2015 23:54:15 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On 08/11/2015 23:13, Dennis Lee Bieber wrote: > On Sun, 8 Nov 2015 18:58:36 +0000, BartC declaimed the > following: > >> But then, you say that additional attributes, potentially millions of >> different ones, can be invented at runtime. Although I don't see how it >> can remove names that are part of the source code: if "A.B" is in the >> file, then surely "A" and "B" always have to be present in some table or >> other. > > -=-=-=-=- module.py > > class Something(object): > def __init__(self): > pass > > -=-=-=-=- main.py > > import module > > module.remote = module.Something() > nonremote = module.remote > nonremote.x = "Looky here" > print module.remote.x > module.remote.x = 3.14 > print nonremote.x > module.remote = None > print nonremote.x > print module.remote.x Is this typical Python code? Creating global objects in other modules (or writing all over essential data structures in a library module). If most code is going to be more sensible, then I mentioned an approach in my other post just over an hour ago. The idea there was to optimise attribute lookups when code is written with more restraint. (So defining functions, classes and attributes within classes in a boring manner.) > Where do you propose to "tableize" remote, nonremote, and x. "remote" > doesn't exist inside module.py until one executes main.py -- so it can't be In your example, only attributes "remote" and "x" exist. But the tables for those will be empty as it is not practical to add in runtime-created attributes. Then, a conventional lookup would be needed. > optimized to when the compiler parses module.py (creating, in most cases a > bytecode module.pyc). You can't optimize it to main.py since (not shown in > my example) there may be another imported package that also imports module > and references module.remote -- and could even replace it with a new object > (in which case nonremote is still associated with the old object, not the > new one) The tables would reflect the static layout of the attributes as defined in the source code. Since the source code is finite, the tables will be also (unlike runtime when a billion attributes could be created). If your module.py code is tweaked like this: class Something(object): x=0 def __init__(self): pass remote=0 Then 'x' and 'remote' become static attributes that can now added to tables for fast lookup. Although this does require that these two are effectively 'declared'. -- Bartc From ben+python at benfinney.id.au Sun Nov 8 19:00:08 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2015 11:00:08 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: <8537wghwjb.fsf@benfinney.id.au> BartC writes: > Is this typical Python code? Creating global objects in other modules > (or writing all over essential data structures in a library module). Not ?creating global objects?, but changing the referent of a name in some other module. Yes, that's quite a common technique. Does that surprise you? If it surprises you, hopefully you can learn some more Python with this new knowledge. -- \ ?We can't depend for the long run on distinguishing one | `\ bitstream from another in order to figure out which rules | _o__) apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | Ben Finney From rosuav at gmail.com Sun Nov 8 19:04:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 11:04:26 +1100 Subject: Question about math.pi is mutable In-Reply-To: <8537wghwjb.fsf@benfinney.id.au> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> Message-ID: On Mon, Nov 9, 2015 at 11:00 AM, Ben Finney wrote: > BartC writes: > >> Is this typical Python code? Creating global objects in other modules >> (or writing all over essential data structures in a library module). > > Not ?creating global objects?, but changing the referent of a name in > some other module. Yes, that's quite a common technique. Does that > surprise you? Changing the referent of an existing name, definitely. Creating new names, not so much. You don't often reach into another module and create a new attribute. Testing/mocking is a completely separate consideration (eg you can inject a shadow for a built-in name); if some Python implementation has a fast path that gets defeated by "module.int = MagicInt", and it causes the tests to run slower, so be it. Other than that, I can't think of many cases (actually, can't think of any, off hand) where you inject names into other modules. ChrisA From bc at freeuk.com Sun Nov 8 19:11:58 2015 From: bc at freeuk.com (BartC) Date: Mon, 9 Nov 2015 00:11:58 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: On 09/11/2015 00:00, Ben Finney wrote: > BartC writes: > >> Is this typical Python code? Creating global objects in other modules >> (or writing all over essential data structures in a library module). > > Not ?creating global objects?, but changing the referent of a name in > some other module. Yes, that's quite a common technique. Does that > surprise you? Changing the referent (I assume that just means assigning to it or updating the associated value) wouldn't be a problem. Provided the name was defined in that other module, because then it is a name the compiler would know about. (And, more importantly, someone reading the code in that module would know about.) > If it surprises you, hopefully you can learn some more Python with this > new knowledge. Yes, that it's more of a crazy language than it looks at first; I can write a simple module like this: pass which looks like an empty module, yet for all I know will end up contain hundreds of variables by the time it's run. (I normally use my own language, that I call 'dynamic', but compared with Python it might as well be carved in stone!) -- Bartc From flebber.crue at gmail.com Sun Nov 8 19:24:30 2015 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 8 Nov 2015 16:24:30 -0800 (PST) Subject: Is there an archive of the gohlke python binaries on windows In-Reply-To: References: Message-ID: <563752c4-1426-4b8b-ac83-02278f460123@googlegroups.com> On Sunday, 8 November 2015 21:30:59 UTC+11, Laura Creighton wrote: > In a message of Sat, 07 Nov 2015 21:55:32 -0800, Sayth Renshaw writes: > >Just wondering if there is an archive mirror for these binaries available. i was looking for lxml 3.4.1 and the current version is the latest on the page at 3.4.4 being on windows I cannot build it. > > > >http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > > >Thanks > > > >Sayth > > https://pypi.python.org/pypi/lxml/3.4.1 > > Laura Thanks Laura but that fails to install because I uninstalled visual studio and its compiler. Sayth From ben+python at benfinney.id.au Sun Nov 8 19:26:08 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2015 11:26:08 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> Message-ID: <85y4e8ggrj.fsf@benfinney.id.au> Chris Angelico writes: > Testing/mocking is a completely separate consideration (eg you can > inject a shadow for a built-in name) Not for the purpose of making compiler optimisations, as BartC is advocating. The compiler definitely should not treat ?is this code part of a test suite?? as a relevant criterion for deciding what optimisation. We should certainly not have a compiler that makes needless difference to code behaviour under test conditions versus non-test conditions. So, since those optimisations would cripple perfectly normal test code, that should be sufficient to quash the desire to make them. -- \ ?If you define cowardice as running away at the first sign of | `\ danger, screaming and tripping and begging for mercy, then yes, | _o__) Mr. Brave man, I guess I'm a coward.? ?Jack Handey | Ben Finney From flebber.crue at gmail.com Sun Nov 8 19:33:12 2015 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 8 Nov 2015 16:33:12 -0800 (PST) Subject: Python version of Ruby devkit - Advice On library compilation Message-ID: <0fa52e1f-4983-4238-95a2-4b0558fb9738@googlegroups.com> Hi I was wondering if there is a reason that we on windows with python do not have a version of Ruby devkit for python. Is it just for historical reason of life before pip became the package manager and released with python? I can't find the actual post in SO it came off this discussion http://stackoverflow.com/a/13445719/461887 regarding vcvarsall and related python packaging queries. I know it wouldn't solve all pain points as I don't believe(could be wrong here) it would be unable to include Atlas compilation for some scientific libraries but it would be able to compile most targets and reduce the need for alternate implementations, like conda. Not that there is anything wrong with conda at all except you need to rebuild most of the libraries in binstar to use them, but its virtualenv feature is nice and if you use R its good to. Someone more windows and library build savvy is this something easily achievable for windows and would it help? Cheers Sayth From steve at pearwood.info Sun Nov 8 19:35:04 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 09 Nov 2015 11:35:04 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: <563fea3a$0$1614$c3e8da3$5496439d@news.astraweb.com> On Sun, 8 Nov 2015 11:28 pm, Chris Angelico wrote: > On Sun, Nov 8, 2015 at 10:19 PM, BartC wrote: >> I've never understood why this seems to be necessary in Python. Why do >> names have to be looked up? (I'm assuming this is searching by name in >> some sort of table.) > > Yes, if by "searching" you include hash-table lookup. A CPython > dictionary is a *highly* optimized data structure, specifically > because it's used virtually everywhere (I understand Lua's "table" > type has similar optimizations for the same reason). In the common > case, where your names come from literal text in the module, the > strings used for the lookup will be interned constants, and their > hashes will have been precalculated and stored, so the lookup is > pretty easy. So it's a constant-time operation, and while that > constant may be larger than a simple offset-and-fetch, it's still > pretty fast in the overall scheme of things. *Usually*. There are pathological cases -- if you're unlucky enough, or malicious enough, to have a whole lot of names with the same hash value, the look-up degrades to a linear search. More importantly, consider the case of a function referring to a variable named "spam". In principle, at least, it may need to: - search the local namespace; - search the namespace of one or more enclosing functions; - search the global namespace; - search the built-in namespace; before locating the variable's value. In practice, most Python implementations will provide at least one optimization: local variables are recognised and searched using an offset-and-fetch model. Similarly for method calls: spam.eggs needs to: - search the instance dict and slots; - search the class dict; - search the dict for each additional superclass; where searching involves more than just a hash table lookup. It also involves checking the classes for __getattribute__ and __getattr__ methods, checking for descriptors, and more. The whole lookup process is quite complicated, and little of it can be done at compile time. -- Steven From rosuav at gmail.com Sun Nov 8 19:36:23 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 11:36:23 +1100 Subject: Question about math.pi is mutable In-Reply-To: <85y4e8ggrj.fsf@benfinney.id.au> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> Message-ID: On Mon, Nov 9, 2015 at 11:26 AM, Ben Finney wrote: > Chris Angelico writes: > >> Testing/mocking is a completely separate consideration (eg you can >> inject a shadow for a built-in name) > > Not for the purpose of making compiler optimisations, as BartC is > advocating. > > The compiler definitely should not treat ?is this code part of a test > suite?? as a relevant criterion for deciding what optimisation. We > should certainly not have a compiler that makes needless difference to > code behaviour under test conditions versus non-test conditions. > > So, since those optimisations would cripple perfectly normal test code, > that should be sufficient to quash the desire to make them. But I distinguish between crippling *performance* and crippling *functionality*. If the compiler optimizations are defeated, so the test suite falls back on the slow path, that means your tests run slower. Unless you're testing the optimizer itself, this shouldn't be a problem. This is broadly the same kinds of optimizations that Fat Python is playing with. Effectively, what it says is "I think that 'len' is this object", and then it guards the fast path with a quick check for validity. So if you go in and change something, the result is that the slow path gets used instead. The question then is whether it's worth the optimization effort. Will the slow path be penalized more than the fast path gains? Will the code complexity introduce more bugs? The same consideration comes up in JavaScript/ECMAScript (where object attributes can also be created dynamically), and I know some interpreters have been written to do a slot-based lookup, so the concept does have at least some merit. Personally, I'm dubious about the value of this in CPython; but I'm willing to be persuaded. ChrisA From rosuav at gmail.com Sun Nov 8 19:37:12 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 11:37:12 +1100 Subject: Python version of Ruby devkit - Advice On library compilation In-Reply-To: <0fa52e1f-4983-4238-95a2-4b0558fb9738@googlegroups.com> References: <0fa52e1f-4983-4238-95a2-4b0558fb9738@googlegroups.com> Message-ID: On Mon, Nov 9, 2015 at 11:33 AM, Sayth Renshaw wrote: > I was wondering if there is a reason that we on windows with python do not have a version of Ruby devkit for python. > Many of us here don't use Ruby. Can you elaborate on what "devkit" does, please? ChrisA From ben+python at benfinney.id.au Sun Nov 8 19:50:57 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2015 11:50:57 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> Message-ID: <85twowgfm6.fsf@benfinney.id.au> Chris Angelico writes: > On Mon, Nov 9, 2015 at 11:26 AM, Ben Finney wrote: > > Chris Angelico writes: > > > >> Testing/mocking is a completely separate consideration (eg you can > >> inject a shadow for a built-in name) > > > > Not for the purpose of making compiler optimisations, as BartC is > > advocating. [?] since those optimisations would cripple perfectly > > normal test code, that should be sufficient to quash the desire to > > make them. > > But I distinguish between crippling *performance* and crippling > *functionality*. If the compiler optimizations are defeated, so the > test suite falls back on the slow path, that means your tests run > slower. Unless you're testing the optimizer itself, this shouldn't be > a problem. You misunderstand me. I'm not saying the optimisations would be crippled. I am saying that, in order to achieve those optimisations, the *test code* would be crippled. I am pointing out that the assumption necessary for the optimisation BartC is advocating ? the optimisation of module attributes to be immutable after compilation ? depends on crippling the *functionality* needed for many uses, including test code uses. Since the compiler should not be in the position of deciding whether code is test code or not, it cannot use that criterion to decide whether to enable or disable the optimisation. So either the optimisation should never be enabled (my perference), or test code will unwittingly be crippled by the assumptions needed for that optimisation. -- \ ?We are all agreed that your theory is crazy. The question that | `\ divides us is whether it is crazy enough to have a chance of | _o__) being correct.? ?Niels Bohr (to Wolfgang Pauli), 1958 | Ben Finney From wangq at travelsky.com Sun Nov 8 19:52:42 2015 From: wangq at travelsky.com (wangq at travelsky.com) Date: Mon, 9 Nov 2015 08:52:42 +0800 Subject: Question about math.pi is mutable References: <201511061033583772468@travelsky.com>, Message-ID: <201511090852416321002@travelsky.com> Hi, Chris Angelico , Thank you for your help ! :-) From: Chris Angelico Date: 2015-11-06 18:30 To: wangq at travelsky.com CC: python-list Subject: Re: Question about math.pi is mutable On Fri, Nov 6, 2015 at 1:33 PM, wangq at travelsky.com wrote: > Hello, python-list guys: > > I am a newbie of python from Beijing. China. > I have a question about "math.pi". > As you can see in the attachment, why i can modify "math.pi"? > (in "mathmodule.c" "pi" is a "static const double") > > Thank you in advance! > > Best Wishes? Simply because, in Python, virtually everything can be changed. You're welcome to go in and say "math.pi = 3" if you like... and then you accept the consequences of that. There are times when you want to change these sorts of 'constants'. For example, math.pi is a float; but if you're working with decimal.Decimal everywhere, it might be useful to replace it with a corresponding Decimal value: math.pi = decimal.Decimal("3.14159265358979323") And that's perfectly legal. ChrisA From rosuav at gmail.com Sun Nov 8 19:56:39 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 11:56:39 +1100 Subject: Question about math.pi is mutable In-Reply-To: <85twowgfm6.fsf@benfinney.id.au> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> Message-ID: On Mon, Nov 9, 2015 at 11:50 AM, Ben Finney wrote: > You misunderstand me. I'm not saying the optimisations would be > crippled. I am saying that, in order to achieve those optimisations, the > *test code* would be crippled. > > I am pointing out that the assumption necessary for the optimisation > BartC is advocating ? the optimisation of module attributes to be > immutable after compilation ? depends on crippling the *functionality* > needed for many uses, including test code uses. > > Since the compiler should not be in the position of deciding whether > code is test code or not, it cannot use that criterion to decide whether > to enable or disable the optimisation. > > So either the optimisation should never be enabled (my perference), or > test code will unwittingly be crippled by the assumptions needed for > that optimisation. Hmm, then I was misunderstanding what BartC was advocating. I didn't think it would *fail* in the presence of dynamic attributes, but merely *perform suboptimally* (and presumably worse than current CPython). If it does indeed require crippling the functionality, then I agree, this is a bad idea. ChrisA From steve at pearwood.info Sun Nov 8 19:58:11 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 09 Nov 2015 11:58:11 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <87mvuowvzo.fsf@elektro.pacujo.net> Message-ID: <563fefa6$0$1595$c3e8da3$5496439d@news.astraweb.com> On Sun, 8 Nov 2015 11:39 pm, BartC wrote: >> shutil.copyfileobj(Source(), Dest()) >> ======================================================================== > > OK, so here, it is necessary to resolve "copyfileobj" by seeing if > "shutil" is something that contains a name "copyfileobj" that happens to > be a method. Correct. > Is this the lookup you're talking about, and is it done using the actual > string "copyfileobj"? If so, does it need to be done every single time > this line is executed? It would extraordinarily inefficient if that was > the case. That's not what Marko was referring to, but you are correct, it is done using the string "copyfileobj". And it has to be done every single time, since you cannot be sure that the lookup will always return the same object, or even whether it will always succeed. For example, here is a self-destructing method: class X: counter = 0 def method(self): self.counter += 1 if self.counter == 3: del X.method msg = "This method will self-destruct in %d calls." return msg % (3 - self.counter) But you are wrong to describe this as "extraordinarily inefficient". It is certainly efficient enough to be practical: inefficient or not, Python is used for many thousands of practical applications. It is only about a factor of 100 times slower than C or Java, and the PyPy optimizing compiler averages ten times faster (and, occasionally, approaches or even exceeds the speed of similar C or Java code). When performance is critical, you can often locate the bottlenecks and turn that into C or Fortran code. Ruby, which is even more flexible than Python in some ways, is even slower, and yet even Ruby is still fast enough to be practical for many tasks. And remember too that some of the speed of Java (and especially C) is gained at the expense of: - prohibiting the developer from doing certain things; - restricting the range of values you can use; - making significant assumptions about correctness; - avoiding actually checking those assumptions; - and in the case of C, by outright *ignoring the code you write* if you inadvertently violate those assumptions. -- Steven From ben+python at benfinney.id.au Sun Nov 8 20:04:55 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2015 12:04:55 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> Message-ID: <85pozkgeyw.fsf@benfinney.id.au> Chris Angelico writes: > Hmm, then I was misunderstanding what BartC was advocating. I didn't > think it would *fail* in the presence of dynamic attributes, but > merely *perform suboptimally* (and presumably worse than current > CPython). There isn't a way for the compiler to *know*, in all cases, whether module attributes will be updated during the lifetime of the program (short of, as pointed out elsewhere, running the entire program under all possible conditions). So the optimisation can't be applied by the compiler without risking breaking perfectly valid code. That is enough, IMO, to kill the proposal; if the compiler could break *any* valid code, it's no longer a Python compiler. -- \ ?If [a technology company] has confidence in their future | `\ ability to innovate, the importance they place on protecting | _o__) their past innovations really should decline.? ?Gary Barnett | Ben Finney From steve at pearwood.info Sun Nov 8 21:23:06 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 09 Nov 2015 13:23:06 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Message-ID: <5640038b$0$1612$c3e8da3$5496439d@news.astraweb.com> On Mon, 9 Nov 2015 09:35 am, BartC wrote: > Suppose this is the python program: > > import m > a=10 > b=20 > c=30 > m.f() > > The set of global names the compiler knows will be ("m","a","b","c"). Wrong. Up to the line "c=30", the set of names the compiler can infer are m, a, b and c. Once the line "m.f()" executes, *all bets are off*. The compiler can no longer infer *anything* about those names. In principle, m.f may have reached into the globals and deleted *any* of the names, including itself. > I don't believe code can remove these names (that would cause problems). Of course names can be removed. There's even a built-in statement to do so: "del". Deleting names from namespaces is a moderately common thing to do. > You say the set of global names can be added to - after this lot, but I > can't see that the first four are going to change. Of course they can change. > Therefore these names could be referred to by index. Perhaps. But that adds significant complexity to the compiler, and the performance benefits *in practice* may not be as good as you imagine. After all, there is usually far more to real programs than just getting and setting names. Nevertheless, such indexed name lookups do have the potential to save time, and in fact that's what CPython already does with local variables. We can get a *rough* indication of how big a difference this micro-optimization makes by disabling it. Unfortunately, this only works in Python 2 -- in Python 3, you can no longer defeat the local variable optimization. def unopt(): from math import * # Defeats the local variable optimization. x = sin; x = cos; x = tan; x = exp; x = pi x = e; x = trunc; x = log; x = hypot; x = sqrt return def opt(): from math import sin, cos, tan, exp, pi, e, trunc, log, hypot, sqrt x = sin; x = cos; x = tan; x = exp; x = pi x = e; x = trunc; x = log; x = hypot; x = sqrt return from timeit import Timer t1 = Timer("unopt()", setup="from __main__ import unopt") t2 = Timer("opt()", setup="from __main__ import opt") # Best of five trials of 1,000,000 calls each. print min(t1.repeat(repeat=5)) print min(t2.repeat(repeat=5)) When I run this code, I get 16.5607659817 seconds for unopt, and 3.58955097198 seconds for opt. That's a significant difference. But remember that not all of that difference is due to the name lookups (unopt also imports more stuff), and also remember that this is a pretty unrealistic benchmark. Real functions do more than just look up a variable name over and over. > Attributes are harder because they are more of a free-for-all, but > suppose you do have m.f(). > > "m" is easy, it's entry 0 in the global table for this module, so no > lookup-by-name is needed. You examine it, and it's a module. > > It's now necessary to find f within the global table for m. This is > where it gets tricky if you want to avoid a lookup. And I expect you > will say that any code can randomly add names within the global table of > m. Of course it can. It can even add names to builtins. Oh, and you don't know that m is a module until you inspect it at runtime. It could be any object. > But bear with me. Suppose the interpreter were to maintain a table for > each static (not runtime) attribute encountered in the source code. The > compile can produce empty tables for the attributes it's seen. In this > case the table for "f" would be empty: (). The compiler will also > produce a list of such tables for all attributes. I have no idea how well this implementation would work. My guess is that if you look at, say, Nuitka, it may perform optimizations like this. (The aim of Nuitka is to be a static optimizing compiler.) PyPy may do things like this too, using a JIT optimizing compiler. PyPy is capable of far more than such simple optimizations. As I have argued all along, it is certainly not true that Python's dynamicism prevents all such optimizations. It just makes them harder. -- Steven From lac at openend.se Sun Nov 8 21:41:07 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 09 Nov 2015 03:41:07 +0100 Subject: [Ubuntu] PyQt5 In-Reply-To: References: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> Message-ID: <201511090241.tA92f7jZ008906@fido.openend.se> In a message of Sun, 08 Nov 2015 18:05:32 -0500, Terry Reedy writes: >On 11/8/2015 11:03 AM, Andrew Diamond wrote: >> On Saturday, November 7, 2015 at 10:13:25 PM UTC-5, Andrew Diamond >> wrote: >>> Hi! >>> >>> I'm fairly new to Python, and installed pyqt5 and began working >>> through the examples at http://zetcode.com/gui/pyqt5/menustoolbars/ >>> However, whenever I click one of the buttons or menus in the >>> example apps I run that is supposed to quit the application, it >>> locks up. > >What is 'it'? And what does 'lock up' mean? Did the gui freeze and not >disappear? Or did IDLE itself freeze, and even the menu quit working? > >>> This happens with all the examples I installed that >>> handle code to quit the app. >>> >>> Running Ubuntu 15.10, and installed pyqt5 via: >>> >>> sudo apt-get install python3-pyqt5 sudo apt-get install qtcreator > >> I just read somewhere that the issue could be because I was trying to >> run these examples from within Idle. > >I am an IDLE maintainer. Am I to take it that everything ran fine >before you tried to quit? If not, I would want to know why and try to fix. > >If you run tut.py from an IDLE editor, IDLE tries to run it the same as >if you ran it at a console in the tut.py directory with 'python3 -i >tut.py'. I can imagine that there might be a problem with the >transition from gui mode to interactive shell mode, though it works for >tkinter apps. You said 'python3 tut.py' works. What happens if you add >the '-i' option? I'd like to know if the transition problem is in >(Py)qt5 or in IDLE's simulation of '-i'. > >-- >Terry Jan Reedy I suspect that Qt and Idle are disagreeing as to who gets to have the main thread around here. Laura From flebber.crue at gmail.com Sun Nov 8 23:00:24 2015 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 8 Nov 2015 20:00:24 -0800 (PST) Subject: Python version of Ruby devkit - Advice On library compilation In-Reply-To: References: <0fa52e1f-4983-4238-95a2-4b0558fb9738@googlegroups.com> Message-ID: <5e8b9af2-bf8f-4cb4-be24-3b74c20e99e4@googlegroups.com> This is an exert DevKit Overview The DevKit is a toolkit that makes it easy to build and use native C/C++ extensions such as RDiscount and RedCloth for Ruby on Windows. Because on Windows with python libraries like lxml will fail with a vcvarsall error based on different c++ compilers. Sayth From rosuav at gmail.com Sun Nov 8 23:21:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 15:21:43 +1100 Subject: Python version of Ruby devkit - Advice On library compilation In-Reply-To: <5e8b9af2-bf8f-4cb4-be24-3b74c20e99e4@googlegroups.com> References: <0fa52e1f-4983-4238-95a2-4b0558fb9738@googlegroups.com> <5e8b9af2-bf8f-4cb4-be24-3b74c20e99e4@googlegroups.com> Message-ID: On Mon, Nov 9, 2015 at 3:00 PM, Sayth Renshaw wrote: > This is an exert > > DevKit Overview > The DevKit is a toolkit that makes it easy to build and use native C/C++ extensions such as RDiscount and RedCloth for Ruby on Windows. > > Because on Windows with python libraries like lxml will fail with a vcvarsall error based on different c++ compilers. Ah okay. The normal way to install Python extensions on Windows is to get a precompiled binary. That way, you don't have to worry about compilers at all. In the case of lxml, you can get them straight off PyPI: https://pypi.python.org/pypi/lxml/3.4.4 I don't have a Windows system to test with, but 'pip' should be able to go fetch them for you. There does seem to be a bit of a hole, though: there's an installer that targets CPython 3.2, but nothing newer. Fortunately, there's another good place to find Windows binaries - this unofficial (but fairly trustworthy) site: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Binaries targeting CPython 2.7, 3.3, 3.4, and 3.5 are all there. Download the appropriate one (due to compiler differences, you MUST pick the one for your CPython version, or it won't work), and use easy_install on the egg file. Actually installing a build chain on Windows is such a pain that it's usually easier to fiddle around with binaries than to build from source. That's probably why there's no Python DevKit - even with that kind of thing, getting all your deps right would be a pain. ChrisA From greg.ewing at canterbury.ac.nz Mon Nov 9 03:29:39 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 09 Nov 2015 21:29:39 +1300 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > We > should certainly not have a compiler that makes needless difference to > code behaviour under test conditions versus non-test conditions. Indeed. Volkswagen tried a version of that recently, and it didn't end well... -- Greg From Lim_Ee_Hai at ite.edu.sg Mon Nov 9 04:17:08 2015 From: Lim_Ee_Hai at ite.edu.sg (Lim_Ee_Hai at ite.edu.sg) Date: Mon, 9 Nov 2015 17:17:08 +0800 Subject: Probelm with installing Python 3.5.0 Message-ID: Dear Python organisation staff, The Python 3.5.0 was successfully installed. But encountered missing dll upon running the program. My computer is running on Win 7. Any advise to resolve this issue? Rgds LIM Ee Hai Senior Lecturer / Electronics Engineering, School of Electronics & Info-Comm Technology ITE College Central, 2 Ang Mo Kio Drive, Singapore 567720 Tel: +65 68797886 | Fax: +65 6580 5300 | Website: www.ite.edu.sg Confidentiality Caution: If you are not the intended recipient of this communication, please do not retain, use, disclose, disseminate, distribute or copy the contents to any person, as it may be unlawful. From harvesting at makes.email.invalid Mon Nov 9 04:58:10 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Mon, 09 Nov 2015 11:58:10 +0200 Subject: using binary in python References: Message-ID: kent nyberg writes: [- -] > Well, lets assume I want to write and read binary. How is it done? [- -] You open the file with mode "wb" (to write binary) or "rb" (to read binary), and then you write or read bytes (eight-bit units). >>> data = '"bin??ridataa"\n'.encode('utf-8') >>> f = open('roska.txt', 'wb') >>> f.write(data) 17 >>> f.close() The .encode methods produced a bytestring, which Python likes to display as ASCII characters where it can and in hexadecimal where it cannot: >>> data b'"bin\xc3\xa4\xc3\xa4ridataa"\n' An "octal dump" in characters (where ASCII, otherwise apparently octal) and the corresponding hexadecimal shows that it is, indeed, these bytes that ended up in the file: $ od -t cx1 roska.txt 0000000 " b i n 303 244 303 244 r i d a t a a " 22 62 69 6e c3 a4 c3 a4 72 69 64 61 74 61 61 22 0000020 \n 0a 0000021 In UTF-8, the letter '?' is encoded as the two bytes c3 a4 (aka 303 244, and you are welcome to work them out in binary, or even in decimal though that is less transparent when what you want to see is bits). In other encodings, there might be just one byte for that letter, and there are even encodings where the ASCII letters would be different bytes. Fixed-sized numbers (32-bit, 64-bit integers and floating point numbers have conventional representations as groups of four or eight bytes). You could interpret parts of the above text as such instead. From tjreedy at udel.edu Mon Nov 9 05:24:43 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 9 Nov 2015 05:24:43 -0500 Subject: [Ubuntu] PyQt5 In-Reply-To: <201511090241.tA92f7jZ008906@fido.openend.se> References: <7056c802-308b-4d5c-961d-052ef2671633@googlegroups.com> <201511090241.tA92f7jZ008906@fido.openend.se> Message-ID: On 11/8/2015 9:41 PM, Laura Creighton wrote: > In a message of Sun, 08 Nov 2015 18:05:32 -0500, Terry Reedy writes: >>> I just read somewhere that the issue could be because I was trying to >>> run these examples from within Idle. First let me note that a) IDLE is meant for learning Python and developing Python programs, and b) IDLE using tkinter/tcl/tk and programs that introspect too deeply or interact with hardware can interfere with each other. I recently added https://docs.python.org/3/library/idle.html#idle-console-differences to document some differences from console python. Can IDLE be used for developing GUI programs? In the case of tkinter, yes. For 3.x, at least, I believe there are advantages over plain editors. For other gui packages, I would like to know what limitations or problems there are so I can warn people against trying to do things that will not work. Hence the questions below. >> I am an IDLE maintainer. Am I to take it that everything ran fine >> before you tried to quit? If not, I would want to know why and try to fix. >> >> If you run tut.py from an IDLE editor, IDLE tries to run it the same as >> if you ran it at a console in the tut.py directory with 'python3 -i >> tut.py'. I can imagine that there might be a problem with the >> transition from gui mode to interactive shell mode, though it works for >> tkinter apps. You said 'python3 tut.py' works. What happens if you add >> the '-i' option? I'd like to know if the transition problem is in >> (Py)qt5 or in IDLE's simulation of '-i'. > I suspect that Qt and Idle are disagreeing as to who gets to have the > main thread around here. I doubt this is the specific problem because user code, here invoking pyqt and qt, are run in a separate process. While it is running, I believe the only Idle code that would run is in the substitute stdin/out/err, which are only used if the user code calls input, print, or .write() or raises. Instead of > python3 -i mypyqt.py at a console prompt, IDLE starts a subprocess with > python -m idlelib.run mypyqt.py The latter sets up socket communication, a locals namespace that imitates __main__, and a few other things and then runs exec(open(mypyqt.py).read(), locals). I can imagine a few different ways things could get messed up, which is why I asked the specific questions I did. For instance, if a program rebinds the standard stream but does not restore them, because it assumes that exiting the program mean exiting the process (as would normally be the case with a gui program), then the '-i' option and the IDLE simulation thereof may not work. In thinking about this, I realized that I could test that idlelib.run at least works with all stdlib modules by running the entire CPython test suite in the execution process. I already run idle tests in IDLE while developing them, but had never thought about the fact that I was testing the run module also. -- Terry Jan Reedy From motoom at xs4all.nl Mon Nov 9 05:40:20 2015 From: motoom at xs4all.nl (Michiel Overtoom) Date: Mon, 9 Nov 2015 11:40:20 +0100 Subject: using binary in python In-Reply-To: <20151108212706.GA29701@z-sverige.nu> References: <20151108212706.GA29701@z-sverige.nu> Message-ID: > On 08 Nov 2015, at 22:27, kent nyberg wrote: > > Well, lets assume I want to write and read binary. How is it done? With the functions 'open()' and 'read()' and 'write()'. If you're on Windows, don't forget to include a 'b' in the mode string of the open() call, otherwise Python will assume that you're opening a text file. You also might want to look into the 'struct' module, functions 'pack()' and 'unpack()'. They convert python values to their binary representation which is used in binary files. Greetings, From marko at pacujo.net Mon Nov 9 05:56:08 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 09 Nov 2015 12:56:08 +0200 Subject: using binary in python References: <20151108212706.GA29701@z-sverige.nu> Message-ID: <87d1vjigqf.fsf@elektro.pacujo.net> Michiel Overtoom : > If you're on Windows, don't forget to include a 'b' in the mode string > of the open() call, otherwise Python will assume that you're opening a > text file. Python has brought that blessing to other operating systems, as well. One of the principal UNIX innovations was to see files as simple byte sequences. The operating system would place no semantics on the meaning or structure of the bytes. Python presents a different concept of a file; Python files are either text files or binary files. The dichotomy is built on top of the UNIX file system. However, the Python model "leaks" in that nothing prevents you from opening a binary file as a text file or vice versa. Marko From rosuav at gmail.com Mon Nov 9 06:04:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 22:04:26 +1100 Subject: using binary in python In-Reply-To: <87d1vjigqf.fsf@elektro.pacujo.net> References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> Message-ID: On Mon, Nov 9, 2015 at 9:56 PM, Marko Rauhamaa wrote: > One of the principal UNIX innovations was to see files as simple byte > sequences. The operating system would place no semantics on the meaning > or structure of the bytes. And you also want to see those files as containing "plain text", right? Unfortunately, those two goals are in conflict. Either a file is nothing but bytes, or it contains text in some encoding. From the file system and operating system's points of view, the files are indeed nothing but bytes; but from the application's point of view, text is text and bytes is bytes. In Python, a text file is opened with a specific encoding, and Python handles the encode/decode steps. ChrisA From steve at pearwood.info Mon Nov 9 06:22:13 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 09 Nov 2015 22:22:13 +1100 Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> Message-ID: <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> On Mon, 9 Nov 2015 12:04 pm, Ben Finney wrote: > There isn't a way for the compiler to *know*, in all cases, whether > module attributes will be updated during the lifetime of the program > (short of, as pointed out elsewhere, running the entire program under > all possible conditions). > > So the optimisation can't be applied by the compiler without risking > breaking perfectly valid code. It's not 1980 any more, compiler technology has come a long way since the Dragon Book. In the words of Steve Yegge, describing the attitudes of C++ developers who insist that no other language (and especially dynamic languages) can be sufficiently fast: "And so, you know, their whole argument is based on these fallacious, you know, sort of almost pseudo-religious... and often it's the case that they're actually based on things that used to be true, but they're not really true anymore" http://steve-yegge.blogspot.com.au/2008/05/dynamic-languages-strike-back.html The compiler doesn't need to decide in advance whether or not the module attributes have been changed. It can decide that at runtime, just before actually looking up the attribute. In pseudo-code: if attribute might have changed: use the slow path just like today else: use the optimized fast path The PyPy FAQs suggest that PyPy is capable of fast, optimized attribute access in this fashion, using a guard to ensure the fast path is taken only when ?this class attribute was not modified?. I'm not a compiler expert, but I would expect that this sort of technology could be adapted to do the same for module attributes. http://doc.pypy.org/en/latest/faq.html Such optimizations don't come for free: PyPy has taken a lot of development effort, and some funding from the EU. And PyPy is more memory-hungry than CPython. But that's just the same old trade-off that programmers have been doing since time immemorial: you can save time, or you can save space, but you can rarely save both together. Other dynamic languages also have proven fast implementations: for decades, Lisp (dynamic) and Fortran (static) were the two fastest languages around. If Lisp has fallen behind, it is not because it is dynamic, but because nobody is working on optimizing it. What was optimal in 1975 may not be optimal on today's hardware. Javascript and PHP also have extremely fast versions. Javascript's V8 compiler is actually two compilers in one, and it automatically swaps over to the optimizing compiler when it is appropriate: http://jayconrod.com/posts/54/a-tour-of-v8-crankshaft-the-optimizing-compiler When Crankshaft's assumptions are violated, the compiler automatically swaps back to running the unoptimized code. Facebook took a different approach with HipHop, using a JIT language translator that takes PHP and outputs compiled C++ code: https://www.facebook.com/notes/facebook-engineering/hiphop-for-php-move-fast/280583813919 HipHop is perhaps not the best example, as it does give up some of the most dynamic features of PHP, such as eval. The post above isn't clear whether using such features is prohibited, or merely falls back on the slow, regular PHP interpreter when you use them. -- Steven From artyprog at gmail.com Mon Nov 9 07:21:14 2015 From: artyprog at gmail.com (Salvatore DI DIO) Date: Mon, 9 Nov 2015 04:21:14 -0800 (PST) Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite Message-ID: Hello, I was trying to show that this limit was 'e' But when I try large numbers I get errors def lim(p): return math.pow(1 + 1.0 / p , p) >>> lim(500000000) 2.718281748862504 >>> lim(900000000) 2.7182820518605446 !!!! What am i doing wrong ? Regards From bc at freeuk.com Mon Nov 9 07:22:22 2015 From: bc at freeuk.com (BartC) Date: Mon, 9 Nov 2015 12:22:22 +0000 Subject: Question about math.pi is mutable In-Reply-To: <5640038b$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <5640038b$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/11/2015 02:23, Steven D'Aprano wrote: > On Mon, 9 Nov 2015 09:35 am, BartC wrote: >> import m >> a=10 >> b=20 >> c=30 >> m.f() >> >> The set of global names the compiler knows will be ("m","a","b","c"). > > Wrong. Up to the line "c=30", the set of names the compiler can infer are m, > a, b and c. Once the line "m.f()" executes, *all bets are off*. The > compiler can no longer infer *anything* about those names. In principle, > m.f may have reached into the globals and deleted *any* of the names, > including itself. > > >> I don't believe code can remove these names (that would cause problems). > > Of course names can be removed. There's even a built-in statement to do > so: "del". I tried this code: a=10 print (a) del a #print (a) a=20 print (a) That sort of confirms what you are saying: that names don't even come into existence until the first time they are encountered. They don't just contain None, or some other value which means the name itself exists, but it hasn't been initialised to anything. And that del removes the name completely from the set that are known. That makes Python unlike any other language I've used. On the other hand, if I put the above code into a function and then call the function, attempting to print a just after it's been deleted results in: UnboundLocalError: local variable 'a' referenced before assignment So while local names can presumably be manipulated just like globals, that doesn't stop being implemented via a fixed slot in a table. >> Therefore these names could be referred to by index. > > Perhaps. But that adds significant complexity to the compiler, It would mean that each name needs a flag indicating whether or not it has yet been brought into existence by an assignment in the program, or has been banished by the use of del. > and the > performance benefits *in practice* may not be as good as you imagine. After > all, there is usually far more to real programs than just getting and > setting names. Any programs will consist largely of pushing names and constants (LOAD ops), performing some operations on them, and then sometimes popping values (STORE ops). If the names represent complex data, then doing the work on the data will dominate the timings. But often it's the 'little' variables that hold indices, counts, flags etc that are being frequently loaded and stored. > def unopt(): > from math import * # Defeats the local variable optimization. > x = sin; x = cos; x = tan; x = exp; x = pi > x = e; x = trunc; x = log; x = hypot; x = sqrt > return > > def opt(): > from math import sin, cos, tan, exp, pi, e, trunc, log, hypot, sqrt > x = sin; x = cos; x = tan; x = exp; x = pi > x = e; x = trunc; x = log; x = hypot; x = sqrt > return > When I run this code, I get > > 16.5607659817 seconds for unopt, and 3.58955097198 seconds for opt. That's a > significant difference. The optimisation means the code can use LOAD_FAST instead of LOAD_NAME. It still uses STORE_FAST instead of STORE_NAME, so perhaps the difference could be even more if the unoptimised version had to use STORE_NAME. -- Bartc From rosuav at gmail.com Mon Nov 9 07:36:54 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 23:36:54 +1100 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <5640038b$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Nov 9, 2015 at 11:22 PM, BartC wrote: > I tried this code: > > a=10 > print (a) > > del a > #print (a) > > a=20 > print (a) > > That sort of confirms what you are saying: that names don't even come into > existence until the first time they are encountered. They don't just contain > None, or some other value which means the name itself exists, but it hasn't > been initialised to anything. And that del removes the name completely from > the set that are known. > > That makes Python unlike any other language I've used. It's a direct consequence of the dynamic namespacing. You'll find similar results in JavaScript/ECMAScript if you play around with prototype-based inheritance, which has a similar rule ("if the property isn't here, look at the prototype") to the Python namespacing rule ("if the name isn't in this namespace, look at the next one outward"). And you're absolutely correct. Unused names do not "contain None" in any sense - they utterly do not exist. When you 'del' a name, that name utterly ceases to exist. > On the other hand, if I put the above code into a function and then call the > function, attempting to print a just after it's been deleted results in: > > UnboundLocalError: local variable 'a' referenced before assignment That's a special case of NameError that was added to make it a bit easier to track down certain types of bug. > So while local names can presumably be manipulated just like globals, that > doesn't stop being implemented via a fixed slot in a table. > Global names are simply module attributes, so they can be manipulated in many ways. Function locals are not; there's no way to say "current_stack_frame.foo = 2", so there's no need to hack around with name lookups. (The locals() dictionary isn't meant to be modified, and changes may or may not have effect on actual local name bindings.) ChrisA From harirammanohar159 at gmail.com Mon Nov 9 07:37:24 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Mon, 9 Nov 2015 04:37:24 -0800 (PST) Subject: help in pexpect multiprocessing Message-ID: Hi, I am using multiprocessing with pexpect, issue is whenever i call a function which is having expect(), its throwing error which is genuine as multiple threads are processing it same time (i/o prompt same time by multiple processes..so issues in picture...), so i want to use lock for that section alone to avoid it, but still fails in implementing it...can you help me username = input('Enter your username: ') password = getpass.getpass() s = pxssh.pxssh() s.login ('host','username','password') s.sendline ('ps -ef|grep java') s.prompt(timeout=1) Try 1: if condition == 'met': np = len(list1) p = multiprocessing.Pool(np) p.map(stop, [(ds) for ds in list1]) def stop(ds): s.sendline ('cd /usr') if condition: lock = threading.Lock() lock.acquire() s.expect('Enter username:') s.sendline ('user') s.expect('Enter password:*') s.sendline('pass') lock.release() s.prompt(timeout=200) print('stopped ds...') Try 2: if condition == 'met': lock = Lock() for ds in list1: Process(target=stop, args=(ds,lock)).start() def stop(ds,l): s.sendline ('cd /usr') if condition: l.acquire() s.expect('Enter username:') s.sendline ('user') s.expect('Enter password:*') s.sendline('pass') l.release() s.prompt(timeout=200) print('stopped ds...') Both are giving me same trace.. pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? Thanks in Advance From rosuav at gmail.com Mon Nov 9 07:45:01 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Nov 2015 23:45:01 +1100 Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite In-Reply-To: References: Message-ID: On Mon, Nov 9, 2015 at 11:21 PM, Salvatore DI DIO wrote: > I was trying to show that this limit was 'e' > But when I try large numbers I get errors > > def lim(p): > return math.pow(1 + 1.0 / p , p) > >>>> lim(500000000) > 2.718281748862504 >>>> lim(900000000) > 2.7182820518605446 !!!! > > > What am i doing wrong ? > Floating point error is going to start becoming a major problem here. Eventually, 1.0/p will underflow to zero, and you'll simply get a result of 1.0: >>> lim(900000000000000000000) 1.0 You could try using decimal.Decimal instead; that can give you rather more precision. Or if you have a lot of patience, fractions.Fraction. >>> def lim(p): return (1 + decimal.Decimal(1) / p) ** p >>> lim(500000000) Decimal('2.718281825740763411884758912') >>> lim(900000000) Decimal('2.718281826948888665260445479') >>> lim(900000000000000000000) Decimal('2.718281556630875980862943027') Definitely not perfect yet... but let's crank up the precision. >>> decimal.getcontext().prec=200 >>> lim(500000000) Decimal('2.7182818257407634118847589119866382434352189174535941028176465917058364010909850212743201574998148959449308935216863472501568773422911827403060031110458945666576132256505421665510943751730347310393611') >>> lim(900000000) Decimal('2.7182818269488886655322736616533366198705073189604924113513719666470682138645212144697520852594221964992741852547403862053248620085931699038380869918694830598723560639286551799819233225160142059050076') >>> lim(900000000000000000000) Decimal('2.7182818284590452353587773147812963615153818054494196724217932791045775211554493949916225628968841872263472976692247791433837657091684393783360159727396877123886624050885921242672885287748600658242797') Now we're starting to get pretty close to the actual value of e. You can push the precision further if you like; it'll take longer to calculate, and dump a bigger pile of digits onto your screen, but it'll be more accurate. I don't recommend using fractions.Fraction unless you have a really fast computer and a LOT of patience. It'll take three parts of forever to get a result... but that result _will_ be perfectly accurate :) ChrisA From oscar.j.benjamin at gmail.com Mon Nov 9 07:50:34 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 9 Nov 2015 12:50:34 +0000 Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite In-Reply-To: References: Message-ID: On 9 November 2015 at 12:21, Salvatore DI DIO wrote: > I was trying to show that this limit was 'e' > But when I try large numbers I get errors > > def lim(p): > return math.pow(1 + 1.0 / p , p) > >>>> lim(500000000) > 2.718281748862504 >>>> lim(900000000) > 2.7182820518605446 !!!! > > > What am i doing wrong ? You're performing a floating point calculation and expecting exact results. Try this: >>> lim(10 ** 17) 1.0 Why does this happen? Well in this case that number is 10**17 and it turns out that >>> 1 + 1.0 / 10**17 1.0 This is because there aren't enough digits in double precision floating point to represent the difference between 1 and 1+1e-17. As p gets larger the addition 1+1.0/p because less and less accurate. The error in computing that is amplified by raising to a large power p. You can use more digits by using the decimal module: >>> from decimal import Decimal, localcontext >>> def lim(p): ... return (1 + 1 / Decimal(p)) ** p ... >>> with localcontext() as ctx: ... ctx.prec = 100 ... lim(10**17) ... Decimal('2.718281828459045221768878329057436445543726874642885850945607978722364313911964199165598158907225076') You can also install sympy and find this result symbolically: >>> from sympy import Symbol, limit, oo >>> p = Symbol('p', integer=True) >>> limit((1 + 1/p)**p, p, oo) E -- Oscar From Cecil at decebal.nl Mon Nov 9 07:59:01 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 09 Nov 2015 13:59:01 +0100 Subject: Problems connecting to PostgreSQL References: <87wptt5qg4.fsf@Equus.decebal.nl> Message-ID: <87pozj5nxm.fsf@Equus.decebal.nl> On Sunday 8 Nov 2015 09:36 CET, Chris Warrick wrote: > On 8 November 2015 at 00:40, Cecil Westerhof wrote: >> I followed http://zetcode.com/db/postgresqlpythontutorial/. >> >> I used: >> sudo -u postgres createuser stressTest >> this create the role, but also gave: >> could not change directory to "/root": Permission denied >> and I did not get the questions. > > This is not an error, just a warning ? and it comes from sudo, > postgres doesn?t care. To silence it, you need to work from a > different directory than /root. The commands actually worked just > fine. > >> Then I used: >> sudo -u postgres createdb stressTest -O stressTest >> This gave also: >> could not change directory to "/root": Permission denied >> >> The database is created, but when I execute: conn = >> psycopg2.connect(database = postgres_database, user = 'stressTest') >> I get: psycopg2.OperationalError: FATAL: Peer authentication failed >> for user "stressTest" >> >> What do I need to do to get things working? > > You need to configure your PostgreSQL database to use md5 > authentication, and set a password for your user. > > # cd / > # sudo -u postgres psql > postgres=# ALTER ROLE stressTest WITH PASSWORD 'swordfish'; > postgres=# \q > # vim /var/lib/postgres/data/pg_hba.conf > > Change host settings to look like this: > # IPv4 local connections: > host all all 127.0.0.1/32 md5 > # IPv6 local connections: > host all all ::1/128 md5 > > Then you can connect using: > > conn = psycopg2.connect(database='stressTest', user='stressTest', > password='swordfish', host='localhost') Thanks. The file to edit on my system is: /var/lib/pgsql/data/pg_hba.conf and it also looks like I cannot use mixed case. But at the moment I have it working. I will delve deeper into it later. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From marko at pacujo.net Mon Nov 9 08:25:55 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 09 Nov 2015 15:25:55 +0200 Subject: using binary in python References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> Message-ID: <8737wfi9ss.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Nov 9, 2015 at 9:56 PM, Marko Rauhamaa wrote: >> One of the principal UNIX innovations was to see files as simple byte >> sequences. The operating system would place no semantics on the >> meaning or structure of the bytes. > > And you also want to see those files as containing "plain text", > right? Unfortunately, those two goals are in conflict. Either a file > is nothing but bytes, or it contains text in some encoding. From the > file system and operating system's points of view, the files are > indeed nothing but bytes; but from the application's point of view, > text is text and bytes is bytes. In Python, a text file is opened with > a specific encoding, and Python handles the encode/decode steps. So we have this stack: +-------------+ | Application | +-------------+ | Python | +-------------+ | UNIX | +-------------+ The question is, does Python want to be "just a programming language" that exposes UNIX to the application program? Or does Python want to present an abstraction different than UNIX? IOW, is the dividing line between the application and the operating system above or below Python? It is evident that Python3 has intentionally moved away from the "just a programming language" view toward Java's write-once-run-everywhere ideal. You would be correct that the original UNIX file system model was based on somewhat of a naive falsity, namely text=ASCII. No matter how you view it, there is a conflict of sorts. Python3 is trying to pave over the conflict, but personally I would prefer the programming language just give me the OS, warts and all. Marko From Cecil at decebal.nl Mon Nov 9 08:40:00 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 09 Nov 2015 14:40:00 +0100 Subject: Using tuple as parameter to a function Message-ID: <87io5b5m1b.fsf@Equus.decebal.nl> At the moment I have the following calls: do_stress_test( 1, 100) do_stress_test( 2, 100) do_stress_test( 5, 100) do_stress_test( 10, 100) do_stress_test( 20, 100) do_stress_test( 40, 100) In principal I want to change it to something like: do_stress_test('sqlite', 1, 100) do_stress_test('postgres', 1, 100) do_stress_test('sqlite', 2, 100) do_stress_test('postgres', 2, 100) do_stress_test('sqlite', 5, 100) do_stress_test('postgres', 5, 100) do_stress_test('sqlite', 10, 100) do_stress_test('postgres', 10, 100) do_stress_test('sqlite', 20, 100) do_stress_test('postgres', 20, 100) do_stress_test('sqlite', 40, 100) do_stress_test('postgres', 40, 100) But that would not be very dry. I was thinking about something like: values = (( 1, 100), ( 2, 100), ( 5, 100), 10, 100), (20, 100), (40, 100)) for value in values: do_stress_test('sqlite', ???) do_stress_test('postgres', ???) Is this possible? If so: what do I put at the place of the '???'? I could change the second and third parameter to a tuple as the second parameter, but I prefer three parameters if that would be possible. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Mon Nov 9 08:52:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Nov 2015 00:52:13 +1100 Subject: using binary in python In-Reply-To: <8737wfi9ss.fsf@elektro.pacujo.net> References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> <8737wfi9ss.fsf@elektro.pacujo.net> Message-ID: On Tue, Nov 10, 2015 at 12:25 AM, Marko Rauhamaa wrote: > So we have this stack: > > +-------------+ > | Application | > +-------------+ > | Python | > +-------------+ > | UNIX | > +-------------+ > > The question is, does Python want to be "just a programming language" > that exposes UNIX to the application program? Or does Python want to > present an abstraction different than UNIX? IOW, is the dividing line > between the application and the operating system above or below Python? > > It is evident that Python3 has intentionally moved away from the "just a > programming language" view toward Java's write-once-run-everywhere > ideal. > > > You would be correct that the original UNIX file system model was based > on somewhat of a naive falsity, namely text=ASCII. No matter how you > view it, there is a conflict of sorts. Python3 is trying to pave over > the conflict, but personally I would prefer the programming language > just give me the OS, warts and all. Then you don't want Python. The point of Python is to give you data types like "list", "dict", "int" (not a machine word but a bignum), and so on. It's NOT meant to be a thin wrapper around what your OS offers. Python's string is a Unicode string, not a series of bytes (as is C's char* type), because human text is better represented as Unicode than as bytes; so it stands to reason that Python's files should be able to contain text, since it's the one most obvious substrate for data storage other than bytes. You get two easy options (bytes and text), and for everything else you can use a library that's built on one of those (pickle, json, etc) or a database. I expect to be able to write idiomatic Python code and have it run on Windows, Unix, Mac OS, OS/2, or Mozilla Firefox, and do the same thing. Since those platforms are so very different, supporting all five is going to mean restricting myself to only those operations that are common to them all, but I expect those operations to be spelled the same way and have the same semantics. I do NOT expect that multiplying 123456 by 654321 will return 80779853376 on some platforms and 3470442048 on others, nor do I expect "?" to render as a micro sign on some systems, a box drawing character "?" on others, and as a capital A with acute "?" on the rest. (Examples not chosen at random.) Obviously this is an ideal that sometimes can't be achieved perfectly (Windows vs Unix file system rules, for instance), but it's definitely part of Python's goal. If you want C, you know where to get it. Though even C does quite a bit of papering-over, so maybe you want to be writing assembly code. ChrisA From rosuav at gmail.com Mon Nov 9 08:58:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Nov 2015 00:58:04 +1100 Subject: Using tuple as parameter to a function In-Reply-To: <87io5b5m1b.fsf@Equus.decebal.nl> References: <87io5b5m1b.fsf@Equus.decebal.nl> Message-ID: On Tue, Nov 10, 2015 at 12:40 AM, Cecil Westerhof wrote: > I was thinking about something like: > values = (( 1, 100), ( 2, 100), ( 5, 100), > 10, 100), (20, 100), (40, 100)) > for value in values: > do_stress_test('sqlite', ???) > do_stress_test('postgres', ???) > > Is this possible? If so: what do I put at the place of the '???'? > > I could change the second and third parameter to a tuple as the second > parameter, but I prefer three parameters if that would be possible. Easy! Just unpack the tuple. Two options: # Unpack in the loop for count, size in values: do_stress_test('sqlite', count, size) do_stress_test('postgres', count, size) # Unpack in the function call for value in values: do_stress_test('sqlite', *value) do_stress_test('postgres', *value) Either will work. For what you're doing here, I'd be inclined to the first option, so you can give the values appropriate names (I'm completely guessing here that they might be some sort of iteration count and pool size; use names that make sense to your program); the other option looks uglier in this particular instance, though it's a more direct answer to your question. This is one of Python's best-kept secrets, I think. It's not easy to stumble on it, but it's so handy once you know about it. ChrisA From lac at openend.se Mon Nov 9 09:27:02 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 09 Nov 2015 15:27:02 +0100 Subject: Probelm with installing Python 3.5.0 In-Reply-To: References: Message-ID: <201511091427.tA9ER2PU000988@fido.openend.se> In a message of Mon, 09 Nov 2015 17:17:08 +0800, Lim_Ee_Hai at ite.edu.sg writes: >Dear Python organisation staff, > > The Python 3.5.0 was successfully installed. But encountered missing dll >upon running the program. > > > >My computer is running on Win 7. > >Any advise to resolve this issue? > >Rgds Which DLL was missing? I am going to guess wildly and say it was this one: http://www.microsoft.com/en-us/download/details.aspx?id=48234 because others have reported running into this. If you are another one, then installing this should make everything work. But if that isn't the missing one, we need to know what was missing before we can help you with how to fix it. Laura From lac at openend.se Mon Nov 9 09:31:44 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 09 Nov 2015 15:31:44 +0100 Subject: No subject In-Reply-To: References: Message-ID: <201511091431.tA9EViXw001459@fido.openend.se> In a message of Sun, 08 Nov 2015 14:07:24 +0000, Ainoa Guti?rrez Su?rez writes: >it doesn?twork the entry to Python. > > > > > > >Enviado desde Correo de Windows I know it is very difficult trying to communicate in a language that is not your mother tongue, but we need a lot more information about what it was that 'didn't work' before we can help you. Also, you might find it easier to write to a Spanish Languge Python mailing list, like this one. https://lists.es.python.org/listinfo/general Laura Creighton From marko at pacujo.net Mon Nov 9 09:32:28 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 09 Nov 2015 16:32:28 +0200 Subject: using binary in python References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> <8737wfi9ss.fsf@elektro.pacujo.net> Message-ID: <87si4fgs5f.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Nov 10, 2015 at 12:25 AM, Marko Rauhamaa wrote: >> but personally I would prefer the programming language >> just give me the OS, warts and all. > > Then you don't want Python. The point of Python is to give you data > types like "list", "dict", "int" (not a machine word but a bignum), > and so on. Those examples are out of the scope of the OS abstraction. > It's NOT meant to be a thin wrapper around what your OS > offers. Thankfully, Python hasn't yet taken that away. I can do a lot of nice things with socket.* and os.* that are unavailable in, say, Java. > Python's string is a Unicode string, not a series of bytes (as is C's > char* type), because human text is better represented as Unicode than > as bytes; No problem there, either. > so it stands to reason that Python's files should be able to contain > text, Yes, and lists and dicts and ints and objects and all. No problem there. However, when filenames and sys.stdin deal with text, things are getting iffy. Marko From invalid at invalid.invalid Mon Nov 9 09:49:15 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 9 Nov 2015 14:49:15 +0000 (UTC) Subject: Question about math.pi is mutable References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <87y4e9y9j6.fsf@elektro.pacujo.net> <87d1vlx7bg.fsf@elektro.pacujo.net> Message-ID: On 2015-11-08, Marko Rauhamaa wrote: > Grant Edwards : > >> On 2015-11-07, Marko Rauhamaa wrote: >>> "const" is a very ineffective tool that clutters the code and forces >>> you to sprinkle type casts around your code. >> >> But it allows the compiler to warn you if you pass a pointer to a >> read-only data to a function that expects a pointer to writable data. > > Unfortunately, it doesn't: > >======================================================================== > #include > #include > > int main() > { > const char name[] = "Tom"; > char *p = strstr(name, "Tom"); > strcpy(p, "Bob"); > printf("name = %s\n", name); > return 0; > } >======================================================================== > > $ cc -o prog prog.c > $ ./prog > Bob > > No warning. Yes, there are ways to fool the compiler by converting a const char* to a plain char* like you did with strstr(). But in my experience there are plenty of cases where it will generate a useful warning. > Point is, the consequences of "proper" use of const are so annoying > even standard library functions would rather grossly abuse it than > tolerate compiler warnings everywhere. That's your opinion. My differs: _I_ find it useful. I don't have that many problems with it. If you don't like it, don't use it -- nobody is forcing you to declare 'const' variables. -- Grant From antoon.pardon at rece.vub.ac.be Mon Nov 9 09:49:48 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Nov 2015 15:49:48 +0100 Subject: Question about math.pi is mutable In-Reply-To: <857flujwy7.fsf@benfinney.id.au> References: <857flujwy7.fsf@benfinney.id.au> Message-ID: <5640B28C.6050408@rece.vub.ac.be> Op 07-11-15 om 04:43 schreef Ben Finney: > Bartc writes: > >> Is there no way then in Python to declare: >> >> pi = 3.141519 # etc >> >> and make it impossible to override? > No, and it would be a bad thing if that were something a library author > could forbid. > > Python assumes the programmers using it are consenting adults. Doing > harmful things is difficult but not forbidden. I find that to be contradictory. Why should you make something difficult if you are consenting adults? I also find it important that consenting adults can choose in how far they can consent. This whole idea of python assuming we are consenting adults and thus making it impossible to not consent seems weird. > Notably, the author of a library should not be forbidding the Pythonic > ability to change name bindings as needed. If the author of a library doesn't wish to consent to this I don't see what is wrong with that. > If you want to have a different value bound to the name ?math.pi?, and > you go ahead and explicitly ask to change that binding, the library > author has no business forbidding that. I disagree. Maybe the author is willing to freely give support but only on the condition that the user used the library as it was largely intended. I see no more reason to allow math.pi to be rebound to another value as to allow True, False or None to be rebound. So why should we allow the language designers to forbid the latter but library authors not the former? From marco.nawijn at colosso.nl Mon Nov 9 09:57:39 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Mon, 9 Nov 2015 06:57:39 -0800 (PST) Subject: Using tuple as parameter to a function In-Reply-To: References: <87io5b5m1b.fsf@Equus.decebal.nl> Message-ID: On Monday, November 9, 2015 at 2:58:21 PM UTC+1, Chris Angelico wrote: > On Tue, Nov 10, 2015 at 12:40 AM, Cecil Westerhof wrote: > > I was thinking about something like: > > values = (( 1, 100), ( 2, 100), ( 5, 100), > > 10, 100), (20, 100), (40, 100)) > > for value in values: > > do_stress_test('sqlite', ???) > > do_stress_test('postgres', ???) > > > > Is this possible? If so: what do I put at the place of the '???'? > > > > I could change the second and third parameter to a tuple as the second > > parameter, but I prefer three parameters if that would be possible. > > Easy! Just unpack the tuple. Two options: > > # Unpack in the loop > for count, size in values: > do_stress_test('sqlite', count, size) > do_stress_test('postgres', count, size) > > # Unpack in the function call > for value in values: > do_stress_test('sqlite', *value) > do_stress_test('postgres', *value) > > Either will work. For what you're doing here, I'd be inclined to the > first option, so you can give the values appropriate names (I'm > completely guessing here that they might be some sort of iteration > count and pool size; use names that make sense to your program); the > other option looks uglier in this particular instance, though it's a > more direct answer to your question. > > This is one of Python's best-kept secrets, I think. It's not easy to > stumble on it, but it's so handy once you know about it. > > ChrisA If the two numbers are actually conceptually connected, you could consider passing them as a namedtuple. The function would then receive two parameters instead of three. Something like the following (expanding on ChrisA's example): from collections import namedtuple StressParameters = namedtuple('StressParameters', ('count', 'size')) def do_stress_test(db_backend, stress_parameters): # Some useful stuff... count = stress_parameters.count size = stress_parameters.size # More useful stuff parameters = [StressParameters(1, 100), StressParameters(2,100)] for p in parameters: do_stress_test('sqlite', p) do_stress_test('postgres', p) From Cecil at decebal.nl Mon Nov 9 10:01:14 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 09 Nov 2015 16:01:14 +0100 Subject: Using tuple as parameter to a function References: <87io5b5m1b.fsf@Equus.decebal.nl> Message-ID: <87egfz5i9x.fsf@Equus.decebal.nl> On Monday 9 Nov 2015 14:58 CET, Chris Angelico wrote: > On Tue, Nov 10, 2015 at 12:40 AM, Cecil Westerhof wrote: >> I was thinking about something like: >> values = (( 1, 100), ( 2, 100), ( 5, 100), >> 10, 100), (20, 100), (40, 100)) >> for value in values: >> do_stress_test('sqlite', ???) >> do_stress_test('postgres', ???) >> >> Is this possible? If so: what do I put at the place of the '???'? >> >> I could change the second and third parameter to a tuple as the >> second parameter, but I prefer three parameters if that would be >> possible. > > Easy! Just unpack the tuple. Two options: > > # Unpack in the loop > for count, size in values: > do_stress_test('sqlite', count, size) > do_stress_test('postgres', count, size) > > # Unpack in the function call > for value in values: > do_stress_test('sqlite', *value) > do_stress_test('postgres', *value) > > Either will work. For what you're doing here, I'd be inclined to the > first option, so you can give the values appropriate names (I'm > completely guessing here that they might be some sort of iteration > count and pool size; use names that make sense to your program); the > other option looks uglier in this particular instance, though it's a > more direct answer to your question. > > This is one of Python's best-kept secrets, I think. It's not easy to > stumble on it, but it's so handy once you know about it. I remembered the second one, but did not know how it was done. That was why I asked about it. But the first option is even better. I now use: values = (( 1, 100), ( 2, 100), ( 5, 100), ( 10, 100), ( 20, 100), ( 40, 100), #( 80, 100), (160, 100), #(160, 200), (160, 400), (160, 800), ) for no_of_threads, no_of_records in values: do_stress_test('postgres', no_of_threads, no_of_records) do_stress_test('sqlite', no_of_threads, no_of_records) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From artyprog at gmail.com Mon Nov 9 10:13:00 2015 From: artyprog at gmail.com (Salvatore DI DIO) Date: Mon, 9 Nov 2015 07:13:00 -0800 (PST) Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite In-Reply-To: References: Message-ID: <0679c4f1-0e38-4b46-9224-59c95ff6bb44@googlegroups.com> Thank you very much Chris From artyprog at gmail.com Mon Nov 9 10:13:59 2015 From: artyprog at gmail.com (Salvatore DI DIO) Date: Mon, 9 Nov 2015 07:13:59 -0800 (PST) Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite In-Reply-To: References: Message-ID: <2e5327a5-2aa4-4dde-ad37-1d1e97cd9944@googlegroups.com> Thank you very much Oscar,I was considerind using Mapple :-) From artyprog at gmail.com Mon Nov 9 10:15:17 2015 From: artyprog at gmail.com (Salvatore DI DIO) Date: Mon, 9 Nov 2015 07:15:17 -0800 (PST) Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite In-Reply-To: References: Message-ID: <616e255d-80cf-436a-859d-6f400f61183b@googlegroups.com> Thank you very much Oscar, I was considering using Mapple :-) From rosuav at gmail.com Mon Nov 9 10:17:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Nov 2015 02:17:59 +1100 Subject: using binary in python In-Reply-To: <87si4fgs5f.fsf@elektro.pacujo.net> References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> <8737wfi9ss.fsf@elektro.pacujo.net> <87si4fgs5f.fsf@elektro.pacujo.net> Message-ID: On Tue, Nov 10, 2015 at 1:32 AM, Marko Rauhamaa wrote: > Yes, and lists and dicts and ints and objects and all. No problem there. > > However, when filenames and sys.stdin deal with text, things are getting > iffy. So where do you mark the boundary between the human and the OS? If I create a GUI, I should be able to put an entry field down that accepts Unicode text. And if I make a web form and an HTTP server, a user should be able to type Unicode text into an field and send that along. Either way, my program should get a Unicode string. Why shouldn't I be able to do the same with input()? And why, if a user enters a plausible file name, should that not be able to be opened as a file? At what point do you say "this is for humans, this is for machines"? Isn't it Python's job to spare us that hassle? ChrisA From rosuav at gmail.com Mon Nov 9 10:24:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Nov 2015 02:24:53 +1100 Subject: Using tuple as parameter to a function In-Reply-To: <87egfz5i9x.fsf@Equus.decebal.nl> References: <87io5b5m1b.fsf@Equus.decebal.nl> <87egfz5i9x.fsf@Equus.decebal.nl> Message-ID: On Tue, Nov 10, 2015 at 2:01 AM, Cecil Westerhof wrote: > for no_of_threads, no_of_records in values: Beautiful! Though I'd shorten the names to just "threads" and "records"; saying "number of X" isn't usually necessary, plus, the general principle of Huffman coding your names recommends using something shorter for a short-lived iteration variable. But otherwise, that's exactly what I'd be looking at - descriptive and clear. ChrisA From random832 at fastmail.com Mon Nov 9 10:32:17 2015 From: random832 at fastmail.com (Random832) Date: Mon, 09 Nov 2015 10:32:17 -0500 Subject: Question about math.pi is mutable References: <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87egfzgpdq.fsf@fastmail.com> Steven D'Aprano writes: > The compiler doesn't need to decide in advance whether or not the module > attributes have been changed. It can decide that at runtime, just before > actually looking up the attribute. In pseudo-code: > > if attribute might have changed: > use the slow path just like today > else: > use the optimized fast path if attribute might have changed: check if attribute really did change if it didn't: reset means of determining if it might have changed goto the optimized fast path else: use the slow path and/or maybe make a new fast path else: use the optimized fast path And what if your optimization depends on _two_ things that might change? Do you create one really fast path and two sort of fast paths? From Cecil at decebal.nl Mon Nov 9 10:44:33 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 09 Nov 2015 16:44:33 +0100 Subject: Commit: postgres on cursor and sqlite on connection Message-ID: <878u675g9q.fsf@Equus.decebal.nl> I have written some code I like to use with several databases. At the moment sqlite and postgres. It looks like with progres I can use: cursor.execute('COMMIT;') but that with sqlite I need to use: conn.commit() Is this true, or am I doing something wrong? When I use cursor.execute('COMMIT;') with sqlite, I get: sqlite3.OperationalError: cannot commit - no transaction is active While conn.commit() does what it should do. Before I do my statements I use: cursor.execute(BEGIN TRANSACTION;') -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From marko at pacujo.net Mon Nov 9 10:46:13 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 09 Nov 2015 17:46:13 +0200 Subject: using binary in python References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> <8737wfi9ss.fsf@elektro.pacujo.net> <87si4fgs5f.fsf@elektro.pacujo.net> Message-ID: <87lha7goqi.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Nov 10, 2015 at 1:32 AM, Marko Rauhamaa wrote: >> Yes, and lists and dicts and ints and objects and all. No problem >> there. >> >> However, when filenames and sys.stdin deal with text, things are >> getting iffy. > > So where do you mark the boundary between the human and the OS? If I > create a GUI, I should be able to put an entry field down that accepts > Unicode text. And if I make a web form and an HTTP server, a user > should be able to type Unicode text into an field and send > that along. Either way, my program should get a Unicode string. Why > shouldn't I be able to do the same with input()? And why, if a user > enters a plausible file name, should that not be able to be opened as > a file? sys.stdin is not (primarily) a human interface. It is the canonical channel to relay the input data to the program. The results of the computation are emitted through sys.stdout. The input data could well be, say, UTF-8-encoded plain text, or a PDF file, or a Zip file, or a music recording. As for file names, even UTF-8 Linux environments often contain filenames that are illegal UTF-8. Using surrogate characters is a clever trick, but might even lead to security risks when more than one pathname can map to the same surrogate encoding. > At what point do you say "this is for humans, this is for machines"? > Isn't it Python's job to spare us that hassle? Python is certainly trying to do that. Flik: I was just trying to help. Mr. Soil: Then help us; *don't* help us. I program for Linux. I use different programming languages, but the target is Linux. The systems I build and deal with consist of different components written in different programming languages but they all follow Linux-y conventions to work harmoniously together. I don't in any way benefit from a smoke screen a programming language offers to place in front of the operating system. Marko From rosuav at gmail.com Mon Nov 9 10:57:01 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Nov 2015 02:57:01 +1100 Subject: using binary in python In-Reply-To: <87lha7goqi.fsf@elektro.pacujo.net> References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> <8737wfi9ss.fsf@elektro.pacujo.net> <87si4fgs5f.fsf@elektro.pacujo.net> <87lha7goqi.fsf@elektro.pacujo.net> Message-ID: On Tue, Nov 10, 2015 at 2:46 AM, Marko Rauhamaa wrote: > I program for Linux. I use different programming languages, but the > target is Linux. The systems I build and deal with consist of different > components written in different programming languages but they all > follow Linux-y conventions to work harmoniously together. I don't in any > way benefit from a smoke screen a programming language offers to place > in front of the operating system. Then, as I said before: You do not want Python. Go use something else that lets you get closer to the OS - possibly C, but possibly not. I'm going to keep using a language that lets me write for humans, because they are my target. Not Linux. People. ChrisA From zljubisic at gmail.com Mon Nov 9 11:12:12 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 9 Nov 2015 08:12:12 -0800 (PST) Subject: Getting response by email reply message Message-ID: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> Hi, I know how to send an email, but I would like to be able to receive a reply and act accordingly. Mail reply should contain yes/no answer. I don't know whether email is appropriate for such function. Maybe better idea would be to have links in email body, one for yes, another for no that will execute something on the server. Anyway, what are my options? Regards. From marko at pacujo.net Mon Nov 9 11:17:13 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 09 Nov 2015 18:17:13 +0200 Subject: using binary in python References: <20151108212706.GA29701@z-sverige.nu> <87d1vjigqf.fsf@elektro.pacujo.net> <8737wfi9ss.fsf@elektro.pacujo.net> <87si4fgs5f.fsf@elektro.pacujo.net> <87lha7goqi.fsf@elektro.pacujo.net> Message-ID: <87h9kvgnau.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Nov 10, 2015 at 2:46 AM, Marko Rauhamaa wrote: >> I program for Linux. I use different programming languages, but the >> target is Linux. The systems I build and deal with consist of >> different components written in different programming languages but >> they all follow Linux-y conventions to work harmoniously together. I >> don't in any way benefit from a smoke screen a programming language >> offers to place in front of the operating system. > > Then, as I said before: You do not want Python. Go use something else > that lets you get closer to the OS Python still offers almost all of the system programming facilities. Python3 is slowly drifting away, but it's still all there, thankfully. Marko From joel.goldstick at gmail.com Mon Nov 9 11:21:06 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 9 Nov 2015 11:21:06 -0500 Subject: Getting response by email reply message In-Reply-To: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> Message-ID: On Mon, Nov 9, 2015 at 11:12 AM, wrote: > Hi, > > I know how to send an email, but I would like to be able to receive a > reply and act accordingly. > Mail reply should contain yes/no answer. > > I don't know whether email is appropriate for such function. > Maybe better idea would be to have links in email body, one for yes, > another for no that will execute something on the server. > > Anyway, what are my options? > > Regards. > -- > https://mail.python.org/mailman/listinfo/python-list > I'm assuming this is a website. If so, why not use a form with a checkbox? -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From bc at freeuk.com Mon Nov 9 11:54:21 2015 From: bc at freeuk.com (BartC) Date: Mon, 9 Nov 2015 16:54:21 +0000 Subject: Question about math.pi is mutable In-Reply-To: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> Message-ID: On 09/11/2015 01:04, Ben Finney wrote: > Chris Angelico writes: > >> Hmm, then I was misunderstanding what BartC was advocating. I didn't >> think it would *fail* in the presence of dynamic attributes, but >> merely *perform suboptimally* (and presumably worse than current >> CPython). > > There isn't a way for the compiler to *know*, in all cases, whether > module attributes will be updated during the lifetime of the program In what way can an attribute be updated, other than deleting it altogether? (Moving or renaming can be done in terms of creation and deletion. For the purposes of trying to avoid a lookup, we're not that interested in much else.) -- Bart C. From ian.g.kelly at gmail.com Mon Nov 9 12:46:24 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Nov 2015 10:46:24 -0700 Subject: Commit: postgres on cursor and sqlite on connection In-Reply-To: <878u675g9q.fsf@Equus.decebal.nl> References: <878u675g9q.fsf@Equus.decebal.nl> Message-ID: On Mon, Nov 9, 2015 at 8:44 AM, Cecil Westerhof wrote: > I have written some code I like to use with several databases. At the > moment sqlite and postgres. It looks like with progres I can use: > cursor.execute('COMMIT;') > but that with sqlite I need to use: > conn.commit() > > Is this true, or am I doing something wrong? > > When I use > cursor.execute('COMMIT;') > with sqlite, I get: > sqlite3.OperationalError: cannot commit - no transaction is active > While > conn.commit() > does what it should do. > > Before I do my statements I use: > cursor.execute(BEGIN TRANSACTION;') This looks like it answers your question: http://stackoverflow.com/questions/9773200/python-sqlite3-cannot-commit-no-transaction-is-active From pkpearson at nowhere.invalid Mon Nov 9 12:51:34 2015 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 9 Nov 2015 17:51:34 GMT Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite References: Message-ID: On Mon, 9 Nov 2015 04:21:14 -0800 (PST), Salvatore DI DIO wrote: > > I was trying to show that this limit was 'e' > But when I try large numbers I get errors > > def lim(p): > return math.pow(1 + 1.0 / p , p) > >>>> lim(500000000) > 2.718281748862504 >>>> lim(900000000) > 2.7182820518605446 !!!! Python floats have close to 16 decimal digits of precision. When you compute 1+1/p with large p, the result will be close to 1, so digits of 1/p beyond the 16th place will be damaged by rounding. For p of 900000000, the first nearly-9 digits of 1/p are zero, so the first "significant" digit is the 10th, and beyond the 16th digit -- the 7th significant digit -- they're damaged, so you can only expect about 16-9 = 7 significant digits to be accurate. And as it turns out, 2.7182820518605446 is good to about 7 significant figures. It takes longer to explain than to see: roundoff limits you to ... (digits of p) + (good digits in the result) = 16 (approximately) -- To email me, substitute nowhere->runbox, invalid->com. From Cecil at decebal.nl Mon Nov 9 12:54:26 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 09 Nov 2015 18:54:26 +0100 Subject: Using tuple as parameter to a function References: <87io5b5m1b.fsf@Equus.decebal.nl> <87egfz5i9x.fsf@Equus.decebal.nl> Message-ID: <874mgv5a99.fsf@Equus.decebal.nl> On Monday 9 Nov 2015 16:24 CET, Chris Angelico wrote: > On Tue, Nov 10, 2015 at 2:01 AM, Cecil Westerhof wrote: >> for no_of_threads, no_of_records in values: > > Beautiful! Though I'd shorten the names to just "threads" and > "records"; saying "number of X" isn't usually necessary, plus, the > general principle of Huffman coding your names recommends using > something shorter for a short-lived iteration variable. Done. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From python.list at tim.thechases.com Mon Nov 9 13:15:29 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 9 Nov 2015 12:15:29 -0600 Subject: Getting response by email reply message In-Reply-To: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> Message-ID: <20151109121529.2a3e7c03@bigbox.christie.dr> On 2015-11-09 08:12, zljubisic at gmail.com wrote: > I know how to send an email, but I would like to be able to receive > a reply and act accordingly. Mail reply should contain yes/no > answer. You have a couple options that occur to me: 1) set up an SMTP server somewhere (or use the existing one you're receiving this email at in the event you're getting it as mail rather than reading it via NNTP or a web interface) to receive the mail, then create a Python script to poll that inbox (usually POP3 or IMAP) for messages addressed. The mails can be extracted, parsed, and deleted 2) similar to above, set up an SMTP server, but use server processing scripts (e.g. procmail scripts) to launch some script when matching emails are received. It would save you from polling (reducing server load) and most scripting frameworks pipe the message in on stdin so you don't have to muck with POP3/IMAP logins. 3) write your own STMP daemon that would do listen and react when appropriate messages come in. In most cases, I'd expect that #2 is the easiest/best solution. The biggest exception being if you have a mail server that doesn't play well with external tools that expect stdin/stdout processing (coughexchangecough). -tkc From ben+python at benfinney.id.au Mon Nov 9 14:45:40 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Nov 2015 06:45:40 +1100 Subject: Question about math.pi is mutable References: <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85fv0fgdnf.fsf@benfinney.id.au> Steven D'Aprano writes: > The compiler doesn't need to decide in advance whether or not the > module attributes have been changed. It can decide that at runtime, > just before actually looking up the attribute. In pseudo-code: > > if attribute might have changed: > use the slow path just like today > else: > use the optimized fast path As you have pointed out earlier, the ?attribute might have changed? condition is set by *any* non-trivial code ? notably, a function call, though that doesn't exhaust the ways of setting that condition. So the remaining space of code that is safe for the proposed optimisation is trivially small. Why bother with such optimisations, if the only code that can benefit is *already* small and simple? I'm not asking you (Steven) to defend the proposal, I'm pointing out that the ?problem? being addressed is essentially the dynamism of Python. The proposal is misguided. -- \ ?Truth would quickly cease to become stranger than fiction, | `\ once we got as used to it.? ?Henry L. Mencken | _o__) | Ben Finney From ben+python at benfinney.id.au Mon Nov 9 14:52:07 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Nov 2015 06:52:07 +1100 Subject: Question about math.pi is mutable References: <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> Message-ID: <85bnb3gdco.fsf@benfinney.id.au> BartC writes: > On 09/11/2015 01:04, Ben Finney wrote: > > There isn't a way for the compiler to *know*, in all cases, whether > > module attributes will be updated during the lifetime of the program > > In what way can an attribute be updated, other than deleting it > altogether? * Bind a new name to a value. * Re-bind an existing name to a different value. * Delete an existing name. Any of those can be done at run-time, in any module's namespace, by arbitrary code somewhere in the program. -- \ ?Sane people have an appropriate perspective on the relative | `\ importance of foodstuffs and human beings. Crazy people can't | _o__) tell the difference.? ?Paul Z. Myers, 2010-04-18 | Ben Finney From lac at openend.se Mon Nov 9 15:07:56 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 09 Nov 2015 21:07:56 +0100 Subject: Question about math.pi is mutable In-Reply-To: <85fv0fgdnf.fsf@benfinney.id.au> References: <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <85fv0fgdnf.fsf@benfinney.id.au> Message-ID: <201511092007.tA9K7vbW000701@fido.openend.se> In a message of Tue, 10 Nov 2015 06:45:40 +1100, Ben Finney writes: >So the remaining space of code that is safe for the proposed >optimisation is trivially small. Why bother with such optimisations, if >the only code that can benefit is *already* small and simple? You have things backwards. The reason that you want to optimise this is that it is small, simple, and slow_slow_slow_slow_slow. It is the things that are complicated and large that usually aren't worth optimising. You don't call them often enough for it to be worth it to optimise them. Your analysis and set up overhead will be more than the speed gains you realise. If you can find something that is small, simple, and ubiquitous -- that's the place to look for performance gains. PyPy gets most of its speed by optimising loops. Most loops in Python run perfectly well without making use of any of the dynanism that is potentially available -- "it's nice to have the ability to do something that, as a matter of fact, I am not going to do right now". But the overhead for checking to see if I have made use of it is huge, which is why 'set things up so that if it is never used, we can go pretty much as fast as C' is a win. After you have paid for your setup costs for making the fast and the slow path, you get enough fast path activity that you come out way ahead. Laura From zljubisic at gmail.com Mon Nov 9 16:36:47 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 9 Nov 2015 13:36:47 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> Message-ID: Hi, You are right. I am trying to address a few questions at the same time. As English is not my first language, I can only say that you have addressed them very well. Thanks. 1. Where to put the try/except block, inside or outside the function 2. How to deal with un-anticipated exceptions 3. How to keep record 1. If try/except block is outside the function, I have to always put function call in try/except block, even for logging. From my point of view, I could put at least logging in the function and then re raise the error. 2. I have just read what TDD is. I should write my first unit test to get a grip. Anyway, I have a program in which I am looping through several of records. If something happens I would like to put the warning in the log. In that case I need to put for loop in try/except Exception as e: block in order to log an unknown exception 3. For me, logging is necessary. Every script (only few of them) I have done, has a underlying log. Thanks. Regards. From zljubisic at gmail.com Mon Nov 9 16:43:42 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 9 Nov 2015 13:43:42 -0800 (PST) Subject: How to handle exceptions properly in a pythonic way? In-Reply-To: References: <4b303213-62e2-42d4-b2f6-4fc1f6025944@googlegroups.com> <4cb51da8-9331-4efe-87d3-dfe9c2ae0f8e@googlegroups.com> Message-ID: <70b30688-2558-4974-bdb8-e579f4ffa6fa@googlegroups.com> Hi, > def get_html(...): > try: > ... actually go get the info > return info > except (ConnectionError, OSError, SocketError) as e: > raise ContentNotFoundError from e Personally, I never liked "early returns". I would rather used a variable and the last line in the function would be return variable. Anyway, I got the point. > To use this code, what you'd do is: > > try: > data = get_html(...) > except ContentNotFoundError: > # deal with the case of not having anything to work with I got a picture. Thanks. I have to rethink now about two approaches. One would be as you have suggested in this mail - raising ContentNotFoundError, and another one would be not to mask root exceptions and deal with them instead of ContentNotFoundError. You have clarified to me the concept. Thanks. Regards. From zljubisic at gmail.com Mon Nov 9 16:45:32 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 9 Nov 2015 13:45:32 -0800 (PST) Subject: Getting response by email reply message In-Reply-To: References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> Message-ID: <83cc2194-ca24-4c44-b5a0-ee6e7b0a8077@googlegroups.com> > I'm assuming this is a website. If so, why not use a form with a checkbox? One of ideas is to put two url's in the email, one for yes and the other one for no. I am also thinking about reading/parsing the reply mail. Regards. From zljubisic at gmail.com Mon Nov 9 16:53:24 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 9 Nov 2015 13:53:24 -0800 (PST) Subject: Getting response by email reply message In-Reply-To: References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> Message-ID: > You have a couple options that occur to me: > > 1) set up an SMTP server somewhere (or use the existing one you're > receiving this email at in the event you're getting it as mail > rather than reading it via NNTP or a web interface) to receive the > mail, then create a Python script to poll that inbox (usually POP3 or > IMAP) for messages addressed. The mails can be extracted, parsed, > and deleted Why should I setup the SMTP server? If my email is on gmail server, I can read the messages from there from time to time. > 2) similar to above, set up an SMTP server, but use server processing > scripts (e.g. procmail scripts) to launch some script when matching > emails are received. It would save you from polling (reducing server > load) and most scripting frameworks pipe the message in on stdin so > you don't have to muck with POP3/IMAP logins. That would be nice but I don't have an access to the server processing scripts. > 3) write your own STMP daemon that would do listen and react when > appropriate messages come in. For now, I could set some time interval, let's say every five minutes for mail checking. I could parse the mail, but at the moment I am not sure how mail body should look like in order to be sure that I have parsed the information correctly. I agree, #2 is the best approach because you are doing something when the mail arrives. In this case you don't have to pull mail server from time to time. Regards. From denismfmcmahon at gmail.com Mon Nov 9 17:14:54 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 9 Nov 2015 22:14:54 -0000 (UTC) Subject: Getting response by email reply message References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> Message-ID: On Mon, 09 Nov 2015 13:53:24 -0800, zljubisic wrote: >> You have a couple options that occur to me: >> >> 1) set up an SMTP server somewhere (or use the existing one you're >> receiving this email at in the event you're getting it as mail rather >> than reading it via NNTP or a web interface) to receive the mail, then >> create a Python script to poll that inbox (usually POP3 or IMAP) for >> messages addressed. The mails can be extracted, parsed, and deleted > > Why should I setup the SMTP server? If my email is on gmail server, I > can read the messages from there from time to time. Read more carefully! The earlier poster suggested options that would work if you set up your own server, or already had one. You can poll your gmail server using pop3 as the earlier reply suggested. You may need to configure some options in your gmail account to allow pop3 access. -- Denis McMahon, denismfmcmahon at gmail.com From ian.g.kelly at gmail.com Mon Nov 9 17:30:51 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Nov 2015 15:30:51 -0700 Subject: Getting response by email reply message In-Reply-To: <20151109121529.2a3e7c03@bigbox.christie.dr> References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> <20151109121529.2a3e7c03@bigbox.christie.dr> Message-ID: On Mon, Nov 9, 2015 at 11:15 AM, Tim Chase wrote: > On 2015-11-09 08:12, zljubisic at gmail.com wrote: >> I know how to send an email, but I would like to be able to receive >> a reply and act accordingly. Mail reply should contain yes/no >> answer. > > You have a couple options that occur to me: > > 1) set up an SMTP server somewhere (or use the existing one you're > receiving this email at in the event you're getting it as mail > rather than reading it via NNTP or a web interface) to receive the > mail, then create a Python script to poll that inbox (usually POP3 or > IMAP) for messages addressed. The mails can be extracted, parsed, > and deleted > > 2) similar to above, set up an SMTP server, but use server processing > scripts (e.g. procmail scripts) to launch some script when matching > emails are received. It would save you from polling (reducing server > load) and most scripting frameworks pipe the message in on stdin so > you don't have to muck with POP3/IMAP logins. > > 3) write your own STMP daemon that would do listen and react when > appropriate messages come in. > > In most cases, I'd expect that #2 is the easiest/best solution. The > biggest exception being if you have a mail server that doesn't play > well with external tools that expect stdin/stdout processing > (coughexchangecough). I'd agree with that provided that the SMTP server is already set up somewhere and you're able to to just add a procmail script to it. I wouldn't suggest trying to set up an SMTP server without a strong reason, however. These things are surprisingly tricky to configure so that your server doesn't get used for spam forwarding, and if you don't play nicely with the SMTP community then you'll find your domain and mail server getting added to various blacklists. If you don't already have an SMTP server to use, better IMO to just use hosted email like Gmail or Zoho. The need to poll it may be an inconvenience, but you'll likely avoid some headaches in the long run. From rosuav at gmail.com Mon Nov 9 17:37:40 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Nov 2015 09:37:40 +1100 Subject: Getting response by email reply message In-Reply-To: References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> <20151109121529.2a3e7c03@bigbox.christie.dr> Message-ID: On Tue, Nov 10, 2015 at 9:30 AM, Ian Kelly wrote: > I wouldn't suggest trying to set up an SMTP server without a strong > reason, however. These things are surprisingly tricky to configure so > that your server doesn't get used for spam forwarding, and if you > don't play nicely with the SMTP community then you'll find your domain > and mail server getting added to various blacklists. Easiest way to prevent it from forwarding spam is to make it incoming-only. But yes, you do need to know a bit about how the internet works; if all you want to do is poll for mail every X minutes, a POP3 or IMAP connection is far simpler. ChrisA From marko at pacujo.net Mon Nov 9 17:43:57 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 10 Nov 2015 00:43:57 +0200 Subject: Getting response by email reply message References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> <20151109121529.2a3e7c03@bigbox.christie.dr> Message-ID: <87k2pqvln6.fsf@elektro.pacujo.net> Ian Kelly : > I wouldn't suggest trying to set up an SMTP server without a strong > reason, however. These things are surprisingly tricky to configure so > that your server doesn't get used for spam forwarding, and if you > don't play nicely with the SMTP community then you'll find your domain > and mail server getting added to various blacklists. That's the reason I ended up writing my own SMTP server (in Python3): I just never could figure out how to configure Postfix to my liking. For once I appreciated the tons of spam arriving at my mail address. I didn't have to come up with test material because every few minutes a fresh spam message came knocking on my door. Marko From python.list at tim.thechases.com Mon Nov 9 17:45:20 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 9 Nov 2015 16:45:20 -0600 Subject: Getting response by email reply message In-Reply-To: References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> Message-ID: <20151109164520.2d0b1615@bigbox.christie.dr> On 2015-11-09 13:53, zljubisic at gmail.com wrote: > > You have a couple options that occur to me: > > > > 1) set up an SMTP server somewhere (or use the existing one you're > > receiving this email at in the event you're getting it as mail > > rather than reading it via NNTP or a web interface) to receive the > > mail, then create a Python script to poll that inbox (usually > > POP3 or IMAP) for messages addressed. The mails can be > > extracted, parsed, and deleted > > Why should I setup the SMTP server? If my email is on gmail server, > I can read the messages from there from time to time. Thus my suggestion "or use the existing one you're receiving this email at") Once you have an SMTP+IMAP server like Gmail, you can use "imaplib" (or "poplib") from the stdlib to log into your Gmail account, pull down the messages (I presume you identify them somehow, either by tag, sorting them into a given folder, or something in the Subject line), and process the message body. > For now, I could set some time interval, let's say every five > minutes for mail checking. I could parse the mail, but at the > moment I am not sure how mail body should look like in order to be > sure that I have parsed the information correctly. With imaplib/poplib, you get email.message items back. You can .walk() through the mime-tree extracting each part and then searching it for whatever expression you need to determine whether the vote was a Yes or No. Check out the docs on https://docs.python.org/2/library/email.message.html -tkc From ben+python at benfinney.id.au Mon Nov 9 18:21:05 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Nov 2015 10:21:05 +1100 Subject: Question about math.pi is mutable References: <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <85fv0fgdnf.fsf@benfinney.id.au> <201511092007.tA9K7vbW000701@fido.openend.se> Message-ID: <85d1vig3oe.fsf@benfinney.id.au> Laura Creighton writes: > In a message of Tue, 10 Nov 2015 06:45:40 +1100, Ben Finney writes: > >So the remaining space of code that is safe for the proposed > >optimisation is trivially small. Why bother with such optimisations, if > >the only code that can benefit is *already* small and simple? > > You have things backwards. > The reason that you want to optimise this is that it is small, simple, > and slow_slow_slow_slow_slow. > > It is the things that are complicated and large that usually aren't > worth optimising. You don't call them often enough for it to be worth > it to optimise them. I appreciate you making the the distinction explicit between a small and simple *code unit* (e.g. an small, simple, often-called function), versus a large and complex *code unit* (e.g. a large, complex, infrequently-called class definition). I'm pointing out an orthogonal issue: The only code to which the proposed optimisation could apply is *module-level* (infrequently called) code, which *has no complications* (i.e. not a code unit). The simplicitly of the small section of code is not the issue; the dynamism of the entire program is what negates the applicability of the optimisation. If the simple, predictable-by-the-compiler segment of code were actually isolated in a simple unit, then yes, such optimisations might be considered. But, as already discussed, the optimisation is not intended to apply to such code units. So that is moot in this case. Instead, we're talking about optimisations proposed *only* for module-level code (i.e. not isolated); and what negates their applicability is *any* dynamism (i.e. not simple), anywhere in the program (i.e. not a code unit). The space of applicability for the proposed optimisation shrinks to irrelevance, AFAICT. -- \ ?If the arguments in favor of atheism upset you, explain why | `\ they?re wrong. If you can?t do that, that?s your problem.? | _o__) ?Amanda Marcotte, 2015-02-13 | Ben Finney From ben+python at benfinney.id.au Mon Nov 9 18:29:59 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Nov 2015 10:29:59 +1100 Subject: Question about math.pi is mutable References: <857flujwy7.fsf@benfinney.id.au> <5640B28C.6050408@rece.vub.ac.be> Message-ID: <858u66g39k.fsf@benfinney.id.au> Antoon Pardon writes: > Op 07-11-15 om 04:43 schreef Ben Finney: > > Python assumes the programmers using it are consenting adults. Doing > > harmful things is difficult but not forbidden. > > I find that to be contradictory. Why should you make something difficult > if you are consenting adults? It's no more contradictory than the fact Python makes it difficult for consenting adults to exchange hard-to-follow code indentation. The principle that There Should Be (Preferably Only) One Obvious Way To Do It directly implies that other ways should be difficult. That's not a contradiction with treating Python programmers as consenting adults. > This whole idea of python assuming we are consenting adults and thus > making it impossible to not consent seems weird. You misunderstand the implication: I'm saying that because Python assumes we are consenting adults, that such actions remain possible. > > Notably, the author of a library should not be forbidding the Pythonic > > ability to change name bindings as needed. > > If the author of a library doesn't wish to consent to this I don't see > what is wrong with that. Who is doing what to whom? The user of the library isn't doing anything to the library author, so what is it the library author would consent to? Instead, you seem to be trying to assert a *power* of the library author to restrict the library user. Such a power is not granted by Python. Instead, the library author is obliged to treat the library user as an adult who consents to the freedoms inherent to Python's design, and to not restrict their use of the library needlessly. -- \ ?Facts are stubborn things; and whatever may be our wishes, our | `\ inclinations, or the dictates of our passion, they cannot alter | _o__) the state of facts and evidence.? ?John Adams, 1770-12-04 | Ben Finney From bjlazlo at gmail.com Mon Nov 9 18:52:45 2015 From: bjlazlo at gmail.com (Bernie Lazlo) Date: Mon, 9 Nov 2015 15:52:45 -0800 (PST) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 Message-ID: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] ======================== The student scores need to be summed. ======================== import json import urllib url = "http://www.wickson.net/geography_assignment.json" response = urllib.urlopen(url) data = json.loads(response.read()) lst1 = list(data.items()) print lst1 From python at mrabarnett.plus.com Mon Nov 9 19:29:50 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2015 00:29:50 +0000 Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: <56413A7E.9090102@mrabarnett.plus.com> On 2015-11-09 23:52, Bernie Lazlo wrote: > This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] > ======================== > The student scores need to be summed. > ======================== > import json > import urllib > url = "http://www.wickson.net/geography_assignment.json" > response = urllib.urlopen(url) > data = json.loads(response.read()) > lst1 = list(data.items()) > print lst1 > Do it a step at a time. It's a list, so start with indexing. From makamisato at yahoo.com Mon Nov 9 19:34:23 2015 From: makamisato at yahoo.com (M. Kamisato) Date: Tue, 10 Nov 2015 00:34:23 +0000 (UTC) Subject: Python.exe is not a valid Win32 application error message References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> I am running python on Windows XP SP3 and download version 3.5xx. ?I got the above error message and could not run the program. I have downloaded Python version 2.7xx and it runs fine. Is there any way I can get version 3.5xx to run on my computer? Mel KamisatoBuena Park, CA From makamisato at yahoo.com Mon Nov 9 19:34:23 2015 From: makamisato at yahoo.com (M. Kamisato) Date: Tue, 10 Nov 2015 00:34:23 +0000 (UTC) Subject: Python.exe is not a valid Win32 application error message References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> I am running python on Windows XP SP3 and download version 3.5xx. ?I got the above error message and could not run the program. I have downloaded Python version 2.7xx and it runs fine. Is there any way I can get version 3.5xx to run on my computer? Mel KamisatoBuena Park, CA From bjlazlo at gmail.com Mon Nov 9 20:12:35 2015 From: bjlazlo at gmail.com (Bernie Lazlo) Date: Mon, 9 Nov 2015 17:12:35 -0800 (PST) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: On Monday, 9 November 2015 19:30:23 UTC-5, MRAB wrote: > On 2015-11-09 23:52, Bernie Lazlo wrote: > > This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] > > ======================== > > The student scores need to be summed. > > ======================== > > import json > > import urllib > > url = "http://www.wickson.net/geography_assignment.json" > > response = urllib.urlopen(url) > > data = json.loads(response.read()) > > lst1 = list(data.items()) > > print lst1 > > > Do it a step at a time. > > It's a list, so start with indexing. MRAB: I think of the file as two lists. The second list appears to be a list of tuples containing "names" and "scores". How would you index or extract those. From python at mrabarnett.plus.com Mon Nov 9 20:31:23 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2015 01:31:23 +0000 Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: <564148EB.7060507@mrabarnett.plus.com> On 2015-11-10 01:12, Bernie Lazlo wrote: > On Monday, 9 November 2015 19:30:23 UTC-5, MRAB wrote: >> On 2015-11-09 23:52, Bernie Lazlo wrote: >> > This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] >> > ======================== >> > The student scores need to be summed. >> > ======================== >> > import json >> > import urllib >> > url = "http://www.wickson.net/geography_assignment.json" >> > response = urllib.urlopen(url) >> > data = json.loads(response.read()) >> > lst1 = list(data.items()) >> > print lst1 >> > >> Do it a step at a time. >> >> It's a list, so start with indexing. > > MRAB: > > I think of the file as two lists. The second list appears to be a list of tuples containing "names" and "scores". How would you index or extract those. > Right, so lst1[1] gets you closer to what you want. Further indexing will get you even closer. From bjlazlo at gmail.com Mon Nov 9 20:53:27 2015 From: bjlazlo at gmail.com (Bernie Lazlo) Date: Mon, 9 Nov 2015 17:53:27 -0800 (PST) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: On Monday, 9 November 2015 20:31:52 UTC-5, MRAB wrote: > On 2015-11-10 01:12, Bernie Lazlo wrote: > > On Monday, 9 November 2015 19:30:23 UTC-5, MRAB wrote: > >> On 2015-11-09 23:52, Bernie Lazlo wrote: > >> > This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] > >> > ======================== > >> > The student scores need to be summed. > >> > ======================== > >> > import json > >> > import urllib > >> > url = "http://www.wickson.net/geography_assignment.json" > >> > response = urllib.urlopen(url) > >> > data = json.loads(response.read()) > >> > lst1 = list(data.items()) > >> > print lst1 > >> > > >> Do it a step at a time. > >> > >> It's a list, so start with indexing. > > > > MRAB: > > > > I think of the file as two lists. The second list appears to be a list of tuples containing "names" and "scores". How would you index or extract those. > > > Right, so lst1[1] gets you closer to what you want. > > Further indexing will get you even closer. =========== lst2 = lst1[1] removes first line of instructions printing lst2[1:2] produces essentially the list of students and scores ?? ([{u'student ': u'Hannah', u'score': 77}, {u'student ': u'Emily', u'score': 57}, {u'student ': u'Olivia', u'score': 80}, {u'student ': u'Nora', u'score': 70}, From python at mrabarnett.plus.com Mon Nov 9 21:13:00 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2015 02:13:00 +0000 Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: <564152AC.8010905@mrabarnett.plus.com> On 2015-11-10 01:53, Bernie Lazlo wrote: > On Monday, 9 November 2015 20:31:52 UTC-5, MRAB wrote: >> On 2015-11-10 01:12, Bernie Lazlo wrote: >> > On Monday, 9 November 2015 19:30:23 UTC-5, MRAB wrote: >> >> On 2015-11-09 23:52, Bernie Lazlo wrote: >> >> > This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] >> >> > ======================== >> >> > The student scores need to be summed. >> >> > ======================== >> >> > import json >> >> > import urllib >> >> > url = "http://www.wickson.net/geography_assignment.json" >> >> > response = urllib.urlopen(url) >> >> > data = json.loads(response.read()) >> >> > lst1 = list(data.items()) >> >> > print lst1 >> >> > >> >> Do it a step at a time. >> >> >> >> It's a list, so start with indexing. >> > >> > MRAB: >> > >> > I think of the file as two lists. The second list appears to be a list of tuples containing "names" and "scores". How would you index or extract those. >> > >> Right, so lst1[1] gets you closer to what you want. >> >> Further indexing will get you even closer. > =========== > lst2 = lst1[1] removes first line of instructions > > printing lst2[1:2] produces essentially the list of students and scores ?? > > ([{u'student ': u'Hannah', u'score': 77}, {u'student ': u'Emily', u'score': 57}, {u'student ': u'Olivia', u'score': 80}, {u'student ': u'Nora', u'score': 70}, > lst1 is 1 list of 2 items, both of which are tuples. lst1[1] gives you the second tuple. That tuple contains 2 items, the first a string and the second a list. You want the second item, so that's lst1[1][1]. Each of the items in that list is a dict. From hpiwowar at gmail.com Mon Nov 9 21:36:13 2015 From: hpiwowar at gmail.com (Heather Piwowar) Date: Mon, 9 Nov 2015 18:36:13 -0800 (PST) Subject: find which Python libraries are most influential in scientific research Message-ID: <06e7d84d-7e49-4160-b42e-a6911640d9e8@googlegroups.com> Today's scientists often turn to Python to run analysis, simulation, and other sciency tasks. That makes us wonder: which Python libraries are most influential in scientific research? We just released a tool (built in Python, of course) to answer that question. It's called Depsy [1], it's funded by the US National Science Foundation, and we'd love your comments. For more information, see our blog post [2] and paper [3]. The scientific/engineering tag is a great place to start exploring [4]. Heather Piwowar and Jason Priem 1. http://depsy.org 2. http://blog.impactstory.org/introducing-depsy 3. https://github.com/Impactstory/depsy-research/blob/master/introducing_depsy.md 4. http://depsy.org/tag/scientific%252Fengineering From steve at pearwood.info Mon Nov 9 21:37:38 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 10 Nov 2015 13:37:38 +1100 Subject: Question about math.pi is mutable References: <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Nov 2015 06:45 am, Ben Finney wrote: > Steven D'Aprano writes: > >> The compiler doesn't need to decide in advance whether or not the >> module attributes have been changed. It can decide that at runtime, >> just before actually looking up the attribute. In pseudo-code: >> >> if attribute might have changed: >> use the slow path just like today >> else: >> use the optimized fast path > > As you have pointed out earlier, the ?attribute might have changed? > condition is set by *any* non-trivial code ? notably, a function > call, though that doesn't exhaust the ways of setting that condition. Ben, I fear that you are not paying attention to me :-) The compiler doesn't need to decide *in advance* whether the attribute might have changed. It knows whether it has changed or not *at runtime*. I'm not a compiler writer, but I pretend to be one on Usenet *wink* so don't take this as gospel. Treat it as a simple-minded illustration of what sort of thing a JIT compiler could do. It's one thing to say that *in principle* any function might modify or shadow builtins. That's true, because we don't know what's inside the function. But the compiler knows, because it actually executes the code inside the function and can see what happens when it does. It doesn't have to predict in advance whether or not calling `func(x)` shadows the builtin `len` function, *it can see for itself* whether it did or not. At compile time, `func(x)` might do anything. But at runtime, we know exactly what it did, because it just did it. Imagine that the compiler keeps track of whether or not builtins has been modified. Think of it as a simple "dirty" flag that says "yes, builtins is still pristine" or "no, something may have shadowed or modified the builtins". That's fairly straight-forward: builtins is a dict, and the compiler can tell whether or not __setitem__ etc has been called on that dict. Likewise, it can keep track of whether or not a global has been created that shadows builtins: some of that can be done statically, at compile-time, but most of it needs to be done dynamically, at runtime. If the flag is set, the compiler knows that the optimization is unsafe and it has to follow the standard name lookup, and you lose nothing: the standard Python semantics are still followed. But if the flag is clear, the compiler knows that nothing has shadowed or modified builtins, and a whole class of optimizations are safe. It can replace a call to (say) len(x) with a fast jump, avoiding an unnecessary name lookup in globals, and another unnecessary name lookup in builtins. Or it might even inline the call to len. Since *most* code doesn't play tricks with builtins, the overhead of tracking these changes pays off *most* of the time -- and when it doesn't, the penalty is very small. Depending on how smart the compiler is, there are all sorts of things it can do. The state of the art (not bleeding edge) for JIT compilers is pretty smart these days. CPython is a simple-minded, dumb compiler, and that's the way Guido likes it (its the reference implementation, not the fastest or most memory efficient implementation). But PyPy can approach the speed of statically optimized C, at least sometimes, and certainly can beat CPython by an order of magnitude. Likewise Javascript's V8 compiler. > So the remaining space of code that is safe for the proposed > optimisation is trivially small. Why bother with such optimisations, if > the only code that can benefit is *already* small and simple? That is absolutely not correct. -- Steven From contact at stridebird.com Mon Nov 9 21:38:15 2015 From: contact at stridebird.com (Pete Dowdell) Date: Tue, 10 Nov 2015 09:38:15 +0700 Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: <56415897.5030502@stridebird.com> On 10/11/15 08:12, Bernie Lazlo wrote: > > > import json > > >import urllib > > >url ="http://www.wickson.net/geography_assignment.json" > > >response = urllib.urlopen(url) > > >data = json.loads(response.read()) All good up to data. Now: # make a list of scores scores = [d['score'] for d in data['comments'] if isinstance(d['score'], int) ] # analysis total_scores = sum(scores) average_score= total_scores/float(len(scores)) min_score, max_score = min(scores), max(scores) pd From bjlazlo at gmail.com Mon Nov 9 22:21:10 2015 From: bjlazlo at gmail.com (Bernie Lazlo) Date: Mon, 9 Nov 2015 19:21:10 -0800 (PST) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: On Monday, 9 November 2015 18:53:06 UTC-5, Bernie Lazlo wrote: > This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] > ======================== > The student scores need to be summed. > ======================== > import json > import urllib > url = "http://www.wickson.net/geography_assignment.json" > response = urllib.urlopen(url) > data = json.loads(response.read()) > lst1 = list(data.items()) > print lst1 ========================== Many thanks, MRAB! :-) From denismfmcmahon at gmail.com Mon Nov 9 22:25:09 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 10 Nov 2015 03:25:09 -0000 (UTC) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: On Mon, 09 Nov 2015 15:52:45 -0800, Bernie Lazlo wrote: > This should be a simple problem but I have wasted hours on it. Any help > would be appreciated. [I have taken my code back to almost the very > beginning.] > ======================== > The student scores need to be summed. > ======================== > import json import urllib url = > "http://www.wickson.net/geography_assignment.json" > response = urllib.urlopen(url) > data = json.loads(response.read()) > lst1 = list(data.items()) > print lst1 I find that pprint.pprint is useful for looking at data structures. Having looked at the data, and then using appropriate substitutions for and in the following: sumscore = 0 students = 0 for dic in : sumscore = sumscore + dic[] students += 1 print 'Sum of', students, 'scores is', sumscore print 'Average of', students, 'scores is', sumscore / students It was trivial to generate: Sum of 50 scores is 3028 Average of 50 scores is 60 -- Denis McMahon, denismfmcmahon at gmail.com From wayne.wickson at gmail.com Mon Nov 9 22:53:38 2015 From: wayne.wickson at gmail.com (wayne.wickson at gmail.com) Date: Mon, 9 Nov 2015 19:53:38 -0800 (PST) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: <9a9e1664-7b36-473d-bebf-3de7c7d13b94@googlegroups.com> On Monday, 9 November 2015 22:27:40 UTC-5, Denis McMahon wrote: > On Mon, 09 Nov 2015 15:52:45 -0800, Bernie Lazlo wrote: > > > This should be a simple problem but I have wasted hours on it. Any help > > would be appreciated. [I have taken my code back to almost the very > > beginning.] > > ======================== > > The student scores need to be summed. > > ======================== > > import json import urllib url = > > "http://www.wickson.net/geography_assignment.json" > > response = urllib.urlopen(url) > > data = json.loads(response.read()) > > lst1 = list(data.items()) > > print lst1 > > I find that pprint.pprint is useful for looking at data structures. > > Having looked at the data, and then using appropriate substitutions for > and in the following: > > sumscore = 0 > students = 0 > > for dic in : > sumscore = sumscore + dic[] > students += 1 > > print 'Sum of', students, 'scores is', sumscore > print 'Average of', students, 'scores is', sumscore / students > > It was trivial to generate: > > Sum of 50 scores is 3028 > Average of 50 scores is 60 > > -- > Denis McMahon ========================================= Thanks for the reply, Denis. I hope this comes as easily to me some day. :-) From lac at openend.se Tue Nov 10 00:42:04 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 10 Nov 2015 06:42:04 +0100 Subject: Getting response by email reply message In-Reply-To: <83cc2194-ca24-4c44-b5a0-ee6e7b0a8077@googlegroups.com> References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> <83cc2194-ca24-4c44-b5a0-ee6e7b0a8077@googlegroups.com> Message-ID: <201511100542.tAA5g4ii011082@fido.openend.se> In a message of Mon, 09 Nov 2015 13:45:32 -0800, zljubisic at gmail.com writes: >> I'm assuming this is a website. If so, why not use a form with a checkbox? > >One of ideas is to put two url's in the email, one for yes and the other one for no. > >I am also thinking about reading/parsing the reply mail. > >Regards. If what you really need is a voting application, you can look at https://github.com/mdipierro/evote which the PSF uses for its elections. Laura From ben+python at benfinney.id.au Tue Nov 10 01:10:09 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Nov 2015 17:10:09 +1100 Subject: Question about math.pi is mutable References: <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <854mgufkqm.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben, I fear that you are not paying attention to me :-) Possibly, though I also think there's miscommunication in this thread. You speak of ?compile time? and ?run time?. You also speak of what the compiler can do, at run time. I am a Bear of Little Brain, but: Isn't anything that the *compiler* does, by definition done at *compile* time? The run-time behaviour of the program is, of course, *affected* by what the compiler has done in the past. But the compiler acts only at compile time, and its compile-time behaviour can't be determined by what's happening at run time. If that's not true, I fear we're not talking about the same things. > At compile time, `func(x)` might do anything. But at runtime, we know > exactly what it did, because it just did it. Sure. All my statements about compile-time optimisations are those that can be applied at compile time (which I intend to be synonymous with ?when the compiler is doing its job?), and so can't be informed by what happens at run time. If the proposal is to make optimisations that must be informed by the run-time state of the running program, we're surely talking about not just the compiler any more. No? -- \ ?Any sufficiently advanced bug is indistinguishable from a | `\ feature.? ?Rich Kulawiec | _o__) | Ben Finney From orgnut at yahoo.com Tue Nov 10 01:20:25 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 9 Nov 2015 22:20:25 -0800 Subject: using binary in python In-Reply-To: References: Message-ID: Your questions are somewhat difficult to answer because you misunderstand binary. The key is that EVERYTHING in a computer is binary. There are NO EXCEPTIONS, it's all binary ALL the time. The difference comes about in how this binary data is displayed and manipulated. I want to emphasize, ALL the DATA is binary. On 11/08/2015 01:27 PM, kent nyberg wrote: > Hi there, > Lets say I want to play around with binary files in python. > Opening and using files in python is something that I think I've sort of got the hang of. > The thing im wondering about is binary files. > While searching for binary and python I started reading about bin(). > I can use bin() to convert integers to binary. No. It doesn't convert anything. It takes the integer data (which is internally binary) and gives you a _string_ representing that value in a binary format. The same with hex() and oct() which give _strings_ of text corresponding to those formats. The original integer data is unchanged -- and is still internally binary data. > Now, I thought.. some way it should be possible to write "binary" files. > That is, non ascii-files. For example, on Linux, if I run the command 'less' on a binary; > for example /bin/ls, then the command asks me if I really want to do it, since its a binary file. > I know why, since the non ascii-stuff messes up the terminal, and most likely since you rarely want to > look at a binary file with less. Not so much that it's rare, it's just that the less (and similar) commands expect the _binary data_ that it is given represents text encoded in ascii, utf-8, whatever... And ls is a executable program not text. So less (or the like) tries to display that data as text, and of course, the result is garbage. (GIGO) If you really want to look at a non-text file this way, there are utilities to do this properly, like hexdump. > Well, lets assume I want to write and read binary. How is it done? > The built in bin() function only converts integers to binary but the variable or return is still just letters right? > Converting the integer '1' to binary with bin() return 0b1. Which is ok. Its the binary representation of integer 1. > But since.. there is files which contains data that is not representable as ascii, then I assume it can be written. > But can it by Python? Of course it can. The only difference a text file and a binary file is the way it's opened. Text files are opened with 'r' or 'w', while binary files are opened with 'rb' or 'wb'. Being different modes, the reading/writing is handled differently. One obvious difference, the lines of a text file are marked by ending them with a newline character, so it's easy to read/write the text line-by-line. But the data in a binary file is completely arbitrary and is much trickier to handle (is an individual piece of data 1 byte, two bytes, 12,428 bytes or...) Once again I'll emphasize that the _data_ in a text file is binary, it's just that these binary data values represent text codes. The data in a binary file can represent anything, a program, a .jpg picture, .mp3 music, a company Personnel record, or anything else. BTW, I talk about text codes as a generic term -- there are many choices of how text is encoded. > Ok, I get the feeling now that its hard to understand my question. I assume in the C language its just matter of > writing a complex struct with strange variables and just write it to a file. But in python..? There is no essential difference between how C and Python handle binary files. The principles are the same, only the details differ. You can ignore comparing to C here. > Can some one give a short explenation of a python write to file, that makes it a binary file? A short explanation, probably not in a newsgroup post. Try searching the web for Python binary files, or similar search terms. Then sit down and play! ;-) > Thanks alot, and forgive me for my stupid questions. :) > /Kent Nyberg It's not a stupid question, but is is based on your misunderstanding of binary. Don't give up, you'll get it! Just keep in mind that _ALL_ the underlying _DATA_ is binary, it is just how this data is displayed and manipulated that makes the differences. And it is important that you understand the difference between the actual (binary) data and the way it is displayed -- these are two entirely different things. Sorry that I'm not more specific on the 'how' to use binary files, but the subject is more complex than a simple explanation can properly give. -- Larry -=- From dieter at handshake.de Tue Nov 10 01:53:56 2015 From: dieter at handshake.de (dieter) Date: Tue, 10 Nov 2015 07:53:56 +0100 Subject: Commit: postgres on cursor and sqlite on connection References: <878u675g9q.fsf@Equus.decebal.nl> Message-ID: <87h9ku1h17.fsf@handshake.de> Cecil Westerhof writes: > I have written some code I like to use with several databases. At the > moment sqlite and postgres. It looks like with progres I can use: > cursor.execute('COMMIT;') > but that with sqlite I need to use: > conn.commit() > > Is this true, or am I doing something wrong? There might be differences between various database interface libraries. I am using "psycopg" to interface with Postgres - and which it, you can also use "conn.commit" (as with "sqlite"). From zljubisic at gmail.com Tue Nov 10 02:09:50 2015 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 9 Nov 2015 23:09:50 -0800 (PST) Subject: Getting response by email reply message In-Reply-To: References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> <83cc2194-ca24-4c44-b5a0-ee6e7b0a8077@googlegroups.com> Message-ID: <82415229-a6b3-44ff-bae0-0e847dbd9d13@googlegroups.com> > If what you really need is a voting application, you can look at > https://github.com/mdipierro/evote which the PSF uses for its elections. It is not a voting application (I will have more than yes/no answers). I just want to keep an example simple. Anyway, I will look into voting application you have suggested in order to see the way how they do it. Thanks. Regards. From artyprog at gmail.com Tue Nov 10 03:26:13 2015 From: artyprog at gmail.com (Salvatore DI DIO) Date: Tue, 10 Nov 2015 00:26:13 -0800 (PST) Subject: Calulation in lim (1 + 1 /n) ^n when n -> infinite In-Reply-To: References: Message-ID: <11f5750f-9ffb-464c-b2d2-71baa7e26ba3@googlegroups.com> Thank you very much Peter From tjreedy at udel.edu Tue Nov 10 03:30:05 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Nov 2015 03:30:05 -0500 Subject: Question about math.pi is mutable In-Reply-To: <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/9/2015 9:37 PM, Steven D'Aprano wrote: > The compiler doesn't need to decide *in advance* whether the attribute might > have changed. It knows whether it has changed or not *at runtime*. You are using 'compiler' when you should, to avoid confusion, use 'interpreter'. > It's one thing to say that *in principle* any function might modify or > shadow builtins. That's true, because we don't know what's inside the > function. But the compiler knows, because it actually executes the code 'interpreter' > inside the function and can see what happens when it does. It doesn't have > to predict in advance whether or not calling `func(x)` shadows the builtin > `len` function, *it can see for itself* whether it did or not. > > At compile time, `func(x)` might do anything. But at runtime, we know > exactly what it did, because it just did it. > > Imagine that the compiler keeps track of whether or not builtins has been /compiler/code compiled by the compiler and interpreted by the interpreter (which could be the CPU)/ > modified. Think of it as a simple "dirty" flag that says "yes, builtins is > still pristine" or "no, something may have shadowed or modified the > builtins". That's fairly straight-forward: builtins is a dict, and the > compiler can tell whether or not __setitem__ etc has been called on that > dict. Likewise, it can keep track of whether or not a global has been > created that shadows builtins: some of that can be done statically, at > compile-time, but most of it needs to be done dynamically, at runtime. This is more or less Victor Stinner's proposal, and he has a working prototype that runs nearly all the test suite. He now plans to refine it and measure changes in space and time usage. > If the flag is set, the compiler knows that the optimization is unsafe and > it has to follow the standard name lookup, and you lose nothing: the > standard Python semantics are still followed. But if the flag is clear, the > compiler knows that nothing has shadowed or modified builtins, and a whole > class of optimizations are safe. It can replace a call to (say) len(x) with > a fast jump, avoiding an unnecessary name lookup in globals, and another > unnecessary name lookup in builtins. Or it might even inline the call to > len. Since *most* code doesn't play tricks with builtins, the overhead of > tracking these changes pays off *most* of the time -- and when it doesn't, > the penalty is very small. -- Terry Jan Reedy From antoon.pardon at rece.vub.ac.be Tue Nov 10 05:03:24 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 10 Nov 2015 11:03:24 +0100 Subject: Question about math.pi is mutable In-Reply-To: <858u66g39k.fsf@benfinney.id.au> References: <857flujwy7.fsf@benfinney.id.au> <5640B28C.6050408@rece.vub.ac.be> <858u66g39k.fsf@benfinney.id.au> Message-ID: <5641C0EC.8010905@rece.vub.ac.be> Op 10-11-15 om 00:29 schreef Ben Finney: > > Who is doing what to whom? The user of the library isn't doing anything > to the library author, so what is it the library author would consent > to? Instead, you seem to be trying to assert a *power* of the library > author to restrict the library user. Such a power is not granted by > Python. Python is not at liberty to grant or deny such a power. Python is just a vehicle in which code is written. The author of a library can restrict its use anyway he sees fit. > Instead, the library author is obliged to treat the library user as an > adult who consents to the freedoms inherent to Python's design, and to > not restrict their use of the library needlessly. There is no such obligation. And if it was an obligation, you can hardly talk about consenting. Consenting adults mean that either party can decide on conditions. Once one party is obligated it is no longer consenting. -- Antoon Pardon From harirammanohar159 at gmail.com Tue Nov 10 05:16:34 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Tue, 10 Nov 2015 02:16:34 -0800 (PST) Subject: help in pexpect multiprocessing In-Reply-To: References: Message-ID: On Monday, 9 November 2015 18:07:36 UTC+5:30, hariramm... at gmail.com wrote: > Hi, > > I am using multiprocessing with pexpect, issue is whenever i call a function which is having expect(), its throwing error which is genuine as multiple threads are processing it same time (i/o prompt same time by multiple processes..so issues in picture...), so i want to use lock for that section alone to avoid it, but still fails in implementing it...can you help me > > username = input('Enter your username: ') > password = getpass.getpass() > > s = pxssh.pxssh() > s.login ('host','username','password') > s.sendline ('ps -ef|grep java') > s.prompt(timeout=1) > > Try 1: > > if condition == 'met': > np = len(list1) > p = multiprocessing.Pool(np) > p.map(stop, [(ds) for ds in list1]) > > def stop(ds): > s.sendline ('cd /usr') > if condition: > lock = threading.Lock() > lock.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > lock.release() > s.prompt(timeout=200) > print('stopped ds...') > > Try 2: > > if condition == 'met': > lock = Lock() > for ds in list1: > Process(target=stop, args=(ds,lock)).start() > > def stop(ds,l): > s.sendline ('cd /usr') > if condition: > l.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > l.release() > s.prompt(timeout=200) > print('stopped ds...') > > Both are giving me same trace.. > > pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? > > Thanks in Advance Hi, can any one check it out From lac at openend.se Tue Nov 10 05:23:21 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 10 Nov 2015 11:23:21 +0100 Subject: Getting response by email reply message In-Reply-To: <82415229-a6b3-44ff-bae0-0e847dbd9d13@googlegroups.com> References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> <83cc2194-ca24-4c44-b5a0-ee6e7b0a8077@googlegroups.com> <82415229-a6b3-44ff-bae0-0e847dbd9d13@googlegroups.com> Message-ID: <201511101023.tAAANLUH000336@fido.openend.se> In a message of Mon, 09 Nov 2015 23:09:50 -0800, zljubisic at gmail.com writes: >> If what you really need is a voting application, you can look at >> https://github.com/mdipierro/evote which the PSF uses for its elections. > >It is not a voting application (I will have more than yes/no answers). >I just want to keep an example simple. > >Anyway, I will look into voting application you have suggested in order to see the way how they do it. Thanks. Their is no demand for 'yes/no answers' -- you can typically vote for 7 people out of 15 candidates for the board, for instance. But, once you get to the website you can serve up webpages, using web2py which presents the voters with a webpage full of whatever you want to render, including text boxes that let you do arbitrary submissions. The hard problem being solved here is that only a select list of people (whom you reach through email) can vote, they can do so during some arbitrary period of time (your election period) but they do not have to all be on-line at the same time, everybody who is legally allowed to vote can change their minds about whom to vote for and re-submit a vote again, invalidating the earlier one, and anonymity -- even the election commissioner who holds the election does not know who it was that any voter voted for, only that they voted. And it also keeps track of vote totals. There are also things to enable you to present the candidates in different orders for different sets of voters, as the order in which a list is dished up seems to effect the outcome, with implications for 'election fairness'. Thus the whole app is about accountablity. The tiny web page you serve up to the people is a tiny bag you bolt into its side. :) Which makes the whole thing way, way, way to heavy-weight for most purposes. However, if accountability is what you need, then it would probably be easier to adapt the election app to do what you want then to reinvent all this stuff. Laura From lac at openend.se Tue Nov 10 05:33:34 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 10 Nov 2015 11:33:34 +0100 Subject: Question about math.pi is mutable In-Reply-To: <854mgufkqm.fsf@benfinney.id.au> References: <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <854mgufkqm.fsf@benfinney.id.au> Message-ID: <201511101033.tAAAXYZP001340@fido.openend.se> In a message of Tue, 10 Nov 2015 17:10:09 +1100, Ben Finney writes: >Steven D'Aprano writes: > >> Ben, I fear that you are not paying attention to me :-) > >Possibly, though I also think there's miscommunication in this thread. > >You speak of ?compile time? and ?run time?. You also speak of what the >compiler can do, at run time. > >I am a Bear of Little Brain, but: Isn't anything that the *compiler* >does, by definition done at *compile* time? No. We used to have a pretty strict defintion about what a compiler was, and what an interpreter was. You did the compile things at compile time, and then you the the interpreter things at runtime. No more. We have Just in Time compilers. They do their compiling at run time. Or perhaps 'there is no such thing as compile time any more'. Laura From lac at openend.se Tue Nov 10 05:37:12 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 10 Nov 2015 11:37:12 +0100 Subject: Getting response by email reply message In-Reply-To: <201511101023.tAAANLUH000336@fido.openend.se> References: <79f2c622-e626-43ae-bcec-f85d394ce575@googlegroups.com> <83cc2194-ca24-4c44-b5a0-ee6e7b0a8077@googlegroups.com> <82415229-a6b3-44ff-bae0-0e847dbd9d13@googlegroups.com> <201511101023.tAAANLUH000336@fido.openend.se> Message-ID: <201511101037.tAAAbCCl001678@fido.openend.se> In a message of Tue, 10 Nov 2015 11:23:21 +0100, Laura Creighton writes: >Their is no demand for 'yes/no answers' -- you can typically vote for s/Their/There/ ... >the whole thing way, way, way to heavy-weight for most purposes. s/to/too/ also s/heavy-weight/heavyweight/ depending on where in the world you live, out of scope for this correction. Sorry about that. I need more caffeine. Laura From trindadegoncalves at gmail.com Tue Nov 10 05:46:40 2015 From: trindadegoncalves at gmail.com (trindadegoncalves at gmail.com) Date: Tue, 10 Nov 2015 02:46:40 -0800 (PST) Subject: IDLE quits unexpectedly when about to open or creat a new file Message-ID: Hello, I need help to find out what's going on. I did some research, but I couldn't find anything to solve this problem: - I open the IDLE program; - I go to the 'File' menu; - I select the 'New File' option - IDLE quits. I run the IDLE version 3.3.3 on Windows 8.1 Pro. Should I install the most recent version? Thanks! From rosuav at gmail.com Tue Nov 10 06:01:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Nov 2015 22:01:17 +1100 Subject: IDLE quits unexpectedly when about to open or creat a new file In-Reply-To: References: Message-ID: On Tue, Nov 10, 2015 at 9:46 PM, wrote: > I need help to find out what's going on. I did some research, but I couldn't find anything to solve this problem: > > - I open the IDLE program; > - I go to the 'File' menu; > - I select the 'New File' option > - IDLE quits. > > I run the IDLE version 3.3.3 on Windows 8.1 Pro. > Should I install the most recent version? > That sounds like a very interesting problem. Can you try running it from the command line, please? I'm not sure how to open one up from Win 8, but it should be in the Start menu somewhere, or possibly press Windows+R and type "cmd". With that up, type this: python -m idlelib.idle That should open up the same IDLE window that you know and recognize. Do the exact same thing that caused the unexpected termination, and then you should go back to the command prompt - hopefully with some sort of error message. Copy and paste that message (as text, please, not an image) into an email; that information could be very helpful. ChrisA From steve at pearwood.info Tue Nov 10 06:34:16 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 10 Nov 2015 22:34:16 +1100 Subject: Question about math.pi is mutable References: <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5641d63a$0$1603$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Nov 2015 05:10 pm, Ben Finney wrote: > Steven D'Aprano writes: > >> Ben, I fear that you are not paying attention to me :-) > > Possibly, though I also think there's miscommunication in this thread. > > You speak of ?compile time? and ?run time?. You also speak of what the > compiler can do, at run time. > > I am a Bear of Little Brain, but: Isn't anything that the *compiler* > does, by definition done at *compile* time? In a manner of speaking, yes, of course. But you've missed the critical issue: when is compile time? If you're like most people, you probably are thinking about an execution model where the compiler analyses the source code statically, using nothing but what can be seen in the source code, then hands over some sort of compiled byte code to be run by an interpreter or machine code that is executed by the CPU. The compiler and interpreter are completely distinct. If so, you're stuck with an obsolete model of computation, like somebody trying to understand modern chemistry based on the "planetary orbit" model of the atom. So when is compile time? Of course, in some languages (like C, or Pascal) compilation occurs as a distinct stage before you can run the code. But that's not necessarily true for all compilers. "Just In Time" compilers operate while the program is running, compiling code just before it is executed. The distinction between compiler and interpreter is gone, or at least weakened. Python -- yes, even CPython -- has a runtime compiler. When you import a module, it is compiled (if needed) just before the import. Likewise, when you call the `compile`, `eval` or `exec` built-ins, the compiler operates. I'm not calling this a JIT compiler, because the simple-minded compilation performed by `compile` etc doesn't use any run-time information. It just statically compiles the code to byte-code. But the fact that it happens *at runtime* is significant, because in principle there is a lot more information available to the compiler, if it were intelligent enough to make use of it. For example, suppose you execute this Python snippet: result = x + 2 At static compile time, looking just at the source, you may not know what value x is, or even whether or not x actually exists, so you're forced to go through the standard Python semantics to determine what the result is: py> from dis import dis py> dis("result = x + 1") 1 0 LOAD_NAME 0 (x) 3 LOAD_CONST 0 (1) 6 BINARY_ADD 7 STORE_NAME 1 (result) 10 LOAD_CONST 1 (None) 13 RETURN_VALUE But a JIT compiler gets to compile code right before that line is due to execute. By the time the JIT compiler gets to see that line of code, it can already know whether or not name "x" exists, and if so, which namespace it is in. It knows what value "x" has. The compiler can choose what byte code, or even machine code, to generate, using information available just before that code is needed. Suppose it knows that "x" is bound to an float. Then it can cast the int 1 to the machine floating point double 1.0 and generate code that adds that to a float. That's likely to be tens of times faster than the BINARY_ADD op-code, which has to do a whole lot of type-checking, method calling, and creating and disposing of objects to add the two values. Only if "x" is unknown, or if it is some type that doesn't have a convenient optimization, does the JIT compiler generate the standard (but unoptimized) BINARY_ADD op-code. Provided that, on average, the book-keeping needed by the JIT compiler is outweighed by the gains, the whole process counts as a win. Now, CPython doesn't include a JIT compiler. But PyPy does, and it is much more sophisticated than anything I could explain. I'm not the only one: https://glyph.twistedmatrix.com/2012/02/this-isnt-how-pypy-works-but-it-might.html If you remember Psycho, that might help. Psycho (according to its creator) isn't a "true" JIT compiler, but it's close enough. Psycho would generate machine code -- actual low level code running in the CPU or FPU, not byte code -- for certain Python operations, plus guard code that ensured the machine code was only called when it was safe to do so. So this is long proven technology. More about JIT compilation on Wikipedia: https://en.wikipedia.org/wiki/Just-in-time_compilation -- Steven From bjlazlo at gmail.com Tue Nov 10 07:14:00 2015 From: bjlazlo at gmail.com (Bernie Lazlo) Date: Tue, 10 Nov 2015 04:14:00 -0800 (PST) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: <9a9e1664-7b36-473d-bebf-3de7c7d13b94@googlegroups.com> References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> <9a9e1664-7b36-473d-bebf-3de7c7d13b94@googlegroups.com> Message-ID: On Monday, 9 November 2015 22:54:05 UTC-5, wayne.... at gmail.com wrote: > On Monday, 9 November 2015 22:27:40 UTC-5, Denis McMahon wrote: > > On Mon, 09 Nov 2015 15:52:45 -0800, Bernie Lazlo wrote: > > > > > This should be a simple problem but I have wasted hours on it. Any help > > > would be appreciated. [I have taken my code back to almost the very > > > beginning.] > > > ======================== > > > The student scores need to be summed. > > > ======================== > > > import json import urllib url = > > > "http://www.wickson.net/geography_assignment.json" > > > response = urllib.urlopen(url) > > > data = json.loads(response.read()) > > > lst1 = list(data.items()) > > > print lst1 > > > > I find that pprint.pprint is useful for looking at data structures. > > > > Having looked at the data, and then using appropriate substitutions for > > and in the following: > > > > sumscore = 0 > > students = 0 > > > > for dic in : > > sumscore = sumscore + dic[] > > students += 1 > > > > print 'Sum of', students, 'scores is', sumscore > > print 'Average of', students, 'scores is', sumscore / students > > > > It was trivial to generate: > > > > Sum of 50 scores is 3028 > > Average of 50 scores is 60 > > > > -- > > Denis McMahon > ========================================= Thanks for the reply, Denis. I hope this comes as easily to me some day. :-) From ben+python at benfinney.id.au Tue Nov 10 07:14:19 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Nov 2015 23:14:19 +1100 Subject: Question about math.pi is mutable References: <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <854mgufkqm.fsf@benfinney.id.au> <201511101033.tAAAXYZP001340@fido.openend.se> Message-ID: <85ziymdpb8.fsf@benfinney.id.au> Laura Creighton writes: > In a message of Tue, 10 Nov 2015 17:10:09 +1100, Ben Finney writes: > >I am a Bear of Little Brain, but: Isn't anything that the *compiler* > >does, by definition done at *compile* time? > > No. > > We used to have a pretty strict defintion about what a compiler was, > and what an interpreter was. You did the compile things at compile > time, and then you the the interpreter things at runtime. > > No more. We have Just in Time compilers. They do their compiling at > run time. Or perhaps 'there is no such thing as compile time any > more'. Very well. I argued on the basis of what could be determined at the time Steven refers to as ?compile time?, i.e. before any part of the module begins to run. Steven D'Aprano writes: > Python -- yes, even CPython -- has a runtime compiler. When you import > a module, it is compiled (if needed) just before the import. Likewise, > when you call the `compile`, `eval` or `exec` built-ins, the compiler > operates. > > I'm not calling this a JIT compiler, because the simple-minded > compilation performed by `compile` etc doesn't use any run-time > information. It just statically compiles the code to byte-code. That's what I though. I'm aware of JIT compilers, and was pretty sure Python doesn't have them. What's more, if it operates at a whole-module level, and not later than when the module is imported. Under those conditions, I maintain my objection to the proposed optimisation. The proposal is explicitly for optimisations made by the Python compiler. As proposed, it only seems to be worthwhile once Python no longer has a distinct ?compiler? and ?interpreter? is dissolved. Until then, it seems pointless. -- \ ?There is something wonderful in seeing a wrong-headed majority | `\ assailed by truth.? ?John Kenneth Galbraith, 1989-07-28 | _o__) | Ben Finney From bjlazlo at gmail.com Tue Nov 10 07:16:46 2015 From: bjlazlo at gmail.com (Bernie Lazlo) Date: Tue, 10 Nov 2015 04:16:46 -0800 (PST) Subject: Extracting and summing student scores from a JSON file using Python 2.7.10 In-Reply-To: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> References: <1d1610e5-d401-48f2-b5ee-3af91b9e485f@googlegroups.com> Message-ID: <2c0e7cc9-c675-4f65-9aea-bf4c7ee13e64@googlegroups.com> On Monday, 9 November 2015 18:53:06 UTC-5, Bernie Lazlo wrote: > This should be a simple problem but I have wasted hours on it. Any help would be appreciated. [I have taken my code back to almost the very beginning.] > ======================== > The student scores need to be summed. > ======================== > import json > import urllib > url = "http://www.wickson.net/geography_assignment.json" > response = urllib.urlopen(url) > data = json.loads(response.read()) > lst1 = list(data.items()) > print lst1 Pete, thanks for the input. Sometimes it just takes a suggestion to break past the "brick wall". From harirammanohar159 at gmail.com Tue Nov 10 07:22:49 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Tue, 10 Nov 2015 04:22:49 -0800 (PST) Subject: help in pexpect multiprocessing In-Reply-To: References: Message-ID: On Monday, 9 November 2015 18:07:36 UTC+5:30, hariramm... at gmail.com wrote: > Hi, > > I am using multiprocessing with pexpect, issue is whenever i call a function which is having expect(), its throwing error which is genuine as multiple threads are processing it same time (i/o prompt same time by multiple processes..so issues in picture...), so i want to use lock for that section alone to avoid it, but still fails in implementing it...can you help me > > username = input('Enter your username: ') > password = getpass.getpass() > > s = pxssh.pxssh() > s.login ('host','username','password') > s.sendline ('ps -ef|grep java') > s.prompt(timeout=1) > > Try 1: > > if condition == 'met': > np = len(list1) > p = multiprocessing.Pool(np) > p.map(stop, [(ds) for ds in list1]) > > def stop(ds): > s.sendline ('cd /usr') > if condition: > lock = threading.Lock() > lock.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > lock.release() > s.prompt(timeout=200) > print('stopped ds...') > > Try 2: > > if condition == 'met': > lock = Lock() > for ds in list1: > Process(target=stop, args=(ds,lock)).start() > > def stop(ds,l): > s.sendline ('cd /usr') > if condition: > l.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > l.release() > s.prompt(timeout=200) > print('stopped ds...') > > Both are giving me same trace.. > > pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? > > Thanks in Advance Hi, I am able to manage it by using process queues, thank you From plucena24 at gmail.com Tue Nov 10 07:42:02 2015 From: plucena24 at gmail.com (Pablo Lucena) Date: Tue, 10 Nov 2015 07:42:02 -0500 Subject: help in pexpect multiprocessing In-Reply-To: References: Message-ID: I think the problem is that you cannot pass around an open socket via pickle. Whats the error message you are getting? Try adding the session establishment code to the stop function, so that each new process opens a session to the server and executes the command. def stop(ds): s = pxssh.pxssh() ? ? s.login ('host','username','password') s.sendline ('ps -ef|grep java') s.prompt(timeout=1) s.sendline ('cd /usr') if condition: lock = threading.Lock() lock.acquire() s.expect('Enter username:') s.sendline ('user') s.expect('Enter password:*') s.sendline('pass') lock.release() s.prompt(timeout=200) print('stopped ds...') if condition == 'met': np = len(list1) p = multiprocessing.Pool(np) p.map(stop, [(ds) for ds in list1]) On Mon, Nov 9, 2015 at 7:37 AM, wrote: > Hi, > > I am using multiprocessing with pexpect, issue is whenever i call a > function which is having expect(), its throwing error which is genuine as > multiple threads are processing it same time (i/o prompt same time by > multiple processes..so issues in picture...), so i want to use lock for > that section alone to avoid it, but still fails in implementing it...can > you help me > > username = input('Enter your username: ') > password = getpass.getpass() > > s = pxssh.pxssh() > s.login ('host','username','password') > s.sendline ('ps -ef|grep java') > s.prompt(timeout=1) > > Try 1: > > if condition == 'met': > np = len(list1) > p = multiprocessing.Pool(np) > p.map(stop, [(ds) for ds in list1]) > > def stop(ds): > s.sendline ('cd /usr') > if condition: > lock = threading.Lock() > lock.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > lock.release() > s.prompt(timeout=200) > print('stopped ds...') > > Try 2: > > if condition == 'met': > lock = Lock() > for ds in list1: > Process(target=stop, args=(ds,lock)).start() > > def stop(ds,l): > s.sendline ('cd /usr') > if condition: > l.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > l.release() > s.prompt(timeout=200) > print('stopped ds...') > > Both are giving me same trace.. > > pexpect.ExceptionPexpect: isalive() encountered condition where > "terminated" is 0, but there was no child process. Did someone else call > waitpid() on our process? > > Thanks in Advance > -- > https://mail.python.org/mailman/listinfo/python-list > -- *Pablo Lucena* From framstag at rus.uni-stuttgart.de Tue Nov 10 08:08:18 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Tue, 10 Nov 2015 13:08:18 +0000 (UTC) Subject: corrupt download with urllib2 Message-ID: I am currently developing a program which should run on Linux and Windows. Later it shall be compiled with PyInstaller. Therefore I am using Python 2.7 My program must download http://fex.belwue.de/download/7za.exe I am using this code: sz = path.join(fexhome,'7za.exe') szurl = "http://fex.belwue.de/download/7za.exe" try: szo = open(sz,'w') except (IOError,OSError) as e: die('cannot write %s - %s' % (sz,e.strerror)) import urllib2 printf("\ndownloading %s\n",szurl) try: req = urllib2.Request(szurl) req.add_header('User-Agent',useragent) u = urllib2.urlopen(req) except urllib2.URLError as e: die('cannot get %s - %s' % (szurl,e.reason)) except urllib2.HTTPError as e: die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason)) if u.getcode() == 200: print(u.read(),file=szo,end='') szo.close() else: die('cannot get %s - server reply: %d' % (szurl,u.getcode())) It works with Linux, but not with Windows 7, where the downloaded 7za.exe is corrupt: it has the wrong size, 589044 instead of 587776 Bytes. Where is my error? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From __peter__ at web.de Tue Nov 10 08:20:29 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Nov 2015 14:20:29 +0100 Subject: corrupt download with urllib2 References: Message-ID: Ulli Horlacher wrote: > I am currently developing a program which should run on Linux and Windows. > Later it shall be compiled with PyInstaller. Therefore I am using Python > 2.7 > > My program must download http://fex.belwue.de/download/7za.exe > > I am using this code: > It works with Linux, but not with Windows 7, where the downloaded 7za.exe > is corrupt: it has the wrong size, 589044 instead of 587776 Bytes. > > Where is my error? > sz = path.join(fexhome,'7za.exe') > szurl = "http://fex.belwue.de/download/7za.exe" > > try: > szo = open(sz,'w') Open the file in binary mode to avoid the translation of "\n" into "\r\n": szo = open(sz, 'wb') > except (IOError,OSError) as e: > die('cannot write %s - %s' % (sz,e.strerror)) Unrelated, but I recommend that you let the exceptions bubble up for easier debugging. Python is not Perl ;) > import urllib2 > printf("\ndownloading %s\n",szurl) > try: > req = urllib2.Request(szurl) > req.add_header('User-Agent',useragent) > u = urllib2.urlopen(req) > except urllib2.URLError as e: > die('cannot get %s - %s' % (szurl,e.reason)) > except urllib2.HTTPError as e: > die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason)) > if u.getcode() == 200: > print(u.read(),file=szo,end='') > szo.close() > else: > die('cannot get %s - server reply: %d' % (szurl,u.getcode())) > From bc at freeuk.com Tue Nov 10 08:26:53 2015 From: bc at freeuk.com (BartC) Date: Tue, 10 Nov 2015 13:26:53 +0000 Subject: Question about math.pi is mutable In-Reply-To: <5641d63a$0$1603$c3e8da3$5496439d@news.astraweb.com> References: <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <5641d63a$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/11/2015 11:34, Steven D'Aprano wrote: > On Tue, 10 Nov 2015 05:10 pm, Ben Finney wrote: > >> I am a Bear of Little Brain, but: Isn't anything that the *compiler* >> does, by definition done at *compile* time? > > In a manner of speaking, yes, of course. But you've missed the critical > issue: when is compile time? > > If you're like most people, you probably are thinking about an execution > model where the compiler analyses the source code statically, using nothing > but what can be seen in the source code, then hands over some sort of > compiled byte code to be run by an interpreter or machine code that is > executed by the CPU. The compiler and interpreter are completely distinct. Does the Python language specify how it is to be compiled and executed? If not, then you can use any interpretation you like, provided the program gives the expected results. That includes using a static compilation pass that generates byte-code, even if it is only done immediately before running the main module, or just before performing an import operation on another. > If so, you're stuck with an obsolete model of computation, like somebody > trying to understand modern chemistry based on the "planetary orbit" model > of the atom. > > So when is compile time? Of course, in some languages (like C, or Pascal) > compilation occurs as a distinct stage before you can run the code. But > that's not necessarily true for all compilers. C can also be interpreted from source as you go along, although it can be very difficult (but probably not as difficult as implementing PyPy). Anything is possible. But the chances are that if you are running CPython, then it will probably include a discrete byte-code compiler. > execute > this Python snippet: > > result = x + 2 > > At static compile time, looking just at the source, you may not know what > value x is, or even whether or not x actually exists, so you're forced to > go through the standard Python semantics to determine what the result is: > > py> from dis import dis > py> dis("result = x + 1") > 1 0 LOAD_NAME 0 (x) > 3 LOAD_CONST 0 (1) > 6 BINARY_ADD > 7 STORE_NAME 1 (result) > 10 LOAD_CONST 1 (None) > 13 RETURN_VALUE > > > But a JIT compiler gets to compile code right before that line is due to > execute. By the time the JIT compiler gets to see that line of code, it can > already know whether or not name "x" exists, and if so, which namespace it > is in. It knows what value "x" has. How does it do that? How is the 'x+1' even stored in the machine? Suppose the preceding lines are: if random+bit()==1: x=920.5 else: x=[8,5,4,9,1,7,6,3,2] or: if some_condition: del x it will probably know as much about x as the static compiler does! And a static compiler can still do a surprising bit of analysis, such as transforming the the first if-statement above, followed by your return statement, into: if random_bit()==1: return 922.5 else: raise_error() But we're trying to find ways of avoiding a dictionary lookup, ie a LOAD_GLOBAL or LOAD_NAME. If static analysis of the entire source can yield fixed tables of such names as 'x', even if subject to runtime alterations, then why not do that if it means possible faster access. > More about JIT compilation on Wikipedia: > > https://en.wikipedia.org/wiki/Just-in-time_compilation JIT covers a lot including straightforward translation of byte-code for a statically language, into native code. In a language like Python, it's rather more elaborate. And PyPy, as you hinted, is complelely different. I don't think it even attempts to JIT compile your example, it JIT compiles some repeatedly executed pathways in a program some way removed from the Python code or even its interpreter. Or something like that... Whatever it is, it's more like magic. But what I started discussing here are ways of making a regular Python interpreter more efficient. I think that with projects such as PyPy, people are less interested with speeding up CPython, for one thing because it is not going to speed things up by ten times, so there seems little point. -- BartC From __peter__ at web.de Tue Nov 10 08:40:59 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Nov 2015 14:40:59 +0100 Subject: corrupt download with urllib2 References: Message-ID: Ulli Horlacher wrote: > if u.getcode() == 200: > print(u.read(),file=szo,end='') > szo.close() > else: > die('cannot get %s - server reply: %d' % (szurl,u.getcode())) More random remarks: - print() gives the impression that you are dealing with text, and using it with binary strings will produce surprising results when you migrate to Python 3: Python 2: >>> from __future__ import print_function >>> print(b"foo") foo Python 3: >>> print(b"foo") b'foo' - with open(...) ensures that the file is closed when an exception occurs. It doesn't matter here as your script is going to die() anyway, but using with is a got habit to get into. - consider shutil.copyfileobj to limit memory usage when dealing with data of arbitrary size. Putting it together: with open(sz, "wb") as szo: shutil.copyfileobj(u, szo) From framstag at rus.uni-stuttgart.de Tue Nov 10 08:43:11 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Tue, 10 Nov 2015 13:43:11 +0000 (UTC) Subject: corrupt download with urllib2 References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > > It works with Linux, but not with Windows 7, where the downloaded 7za.exe > > is corrupt: it has the wrong size, 589044 instead of 587776 Bytes. > > > > Where is my error? > > > sz = path.join(fexhome,'7za.exe') > > szurl = "http://fex.belwue.de/download/7za.exe" > > > > try: > > szo = open(sz,'w') > > Open the file in binary mode to avoid the translation of "\n" into "\r\n": > > szo = open(sz, 'wb') Damn.. I should have known this! Ok, now it works like on Linux. Windows is such a *BEEEP* *CENSORED* > > except (IOError,OSError) as e: > > die('cannot write %s - %s' % (sz,e.strerror)) > > Unrelated, but I recommend that you let the exceptions bubble up for easier > debugging. die() is my debugging function :-) > Python is not Perl ;) *sigh* This is the problem ;-) I am a Perl programmer for more than 25 years... -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From framstag at rus.uni-stuttgart.de Tue Nov 10 08:59:45 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Tue, 10 Nov 2015 13:59:45 +0000 (UTC) Subject: corrupt download with urllib2 References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > Ulli Horlacher wrote: > > > if u.getcode() == 200: > > print(u.read(),file=szo,end='') > > szo.close() > > else: > > die('cannot get %s - server reply: %d' % (szurl,u.getcode())) > > More random remarks: Always welcome - I am here to learn :-) > - print() gives the impression that you are dealing with text, and using it > with binary strings will produce surprising results when you migrate to > Python 3: > > Python 2: > > >>> from __future__ import print_function I already have this in my code, to make a later transition to Python 3 easier. > >>> print(b"foo") > foo > > Python 3: > > >>> print(b"foo") > b'foo' Bad. Is there a better alternative to write arbitrary binary data? > - with open(...) ensures that the file is closed when an exception occurs. > It doesn't matter here as your script is going to die() anyway, but using > with is a got habit to get into. When an error occurs I do want to write more data, anyway. > - consider shutil.copyfileobj to limit memory usage when dealing with data > of arbitrary size. > > Putting it together: > > with open(sz, "wb") as szo: > shutil.copyfileobj(u, szo) This writes the http stream binary to the file. without handling it manually chunk by chunk? Great. This would be my next task! You are answering my questions, before I ask them! :-) Background: I am rewriting my Perl program fexsend in Python. fexsend transfers files up to TB range, see: http://fex.rus.uni-stuttgart.de/ -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From D.Strohl at F5.com Tue Nov 10 10:06:54 2015 From: D.Strohl at F5.com (Dan Strohl) Date: Tue, 10 Nov 2015 15:06:54 +0000 Subject: python PEP suggestion In-Reply-To: References: Message-ID: You mentioned that it is a bit contrary to how Python currently works, I am not sure I understand that, can you elaborate a bit? "Conditional execution, indexing (__index__), numeric conversions (__float__ also), and displaying are special cases related to syntax operations. You have left out the use of abstract base classes. An iterable that can be used as a mapping can register itself as a mapping. Json could check whether something is a sequence or mapping and iterate to get values or pairs of values." All of the above is true, and all of the above are various tools that can work (and I have used most of them from time to time). However, there is a limit to how many different types of special methods that should be built in, built in, what if I want to build an object that would return a datetime or bytearray object as needed, or something more esoteric, or if I wanted to provide different types of data depending on the calling object? What I thinking about is something that allows the called object to return information based on the calling object, (or at least based on what the calling object wants to ask for) in a manner that makes the most sense. This _seems_ like it fits pretty well with Python's module / library / orientation... the library authors often do not know anything about the ones using their objects (and should not have to). With something like this, it allows the library author to have a "standard" way of saying, "I want data in this format". That could be simply saying "I am json and want data that will work for me", or it could be saying "I want a datetime from you". Then, even if the called / passed object is not mappable, or is a subclass of something totally different, the called object has the ability to respond in a way that the author of the called object chooses. If, for example, I choose to implement an object as a mapping object (using __getitem__, subclassing userdict, using collections.abc.Mapping, or whatever), I am in general only going to be able to answer a call to object[key] one way. I could certainly do a custom method or property but then we get back to both authors needing to coordinate more. Functions that unnecessarily restrict inputs to subclasses of list or dict will not be solved by this. Yup, it doesn't solve everything, it just provides another tool that people *could* use to write interoperable libraries and objects. Of course, the tranformation would be unidirectional. Again, yup, just like if I implemented "MyObject.__str__()", it does not guarantee that I did "MyObject('a_string')" it would work (and often doesn't). The excessive indents of 31 and 15 spaces make the rest of this post unnecessarily hard to read. Sorry about that, damn outlook tabs being expanded to stupid numbers I guess. I will do better next time.. Does any of that help? Dan -----Original Message----- From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org] On Behalf Of Terry Reedy Sent: Sunday, November 08, 2015 2:27 PM To: python-list at python.org Subject: Re: python PEP suggestion On 11/6/2015 1:21 PM, Dan Strohl wrote: > All, > > I wanted to run the following thought past the list as a possible PEP enhancement suggestion to see if it feels like something that is worth proposing. I know it is not in the PEP format at this point, I can, and will, clean it up if needed, I am just trying to throw it against the wall at this point to see if it resonates... (or if it falls flat and goes "splat" ). > > Thoughts? At first glance, plausible, but I am not sure needed, and it seems a bit contrary to how Python currently works. > New special method name to allow for more flexible object type casting/access, and extend type() to cast objects using this special method name. > > Overview: > > Have a new special method name that would allow a given objects to request information from another object in a given type, or to cast an object into a different type, and extend the built in type() function to use this. > > Rationale: > There is currently __str__, __int__, and __bool__ that allow me to > tell an object how it should reply to a request for these types of > basic data types. However if I want to access a copy of the objet in > dict form, or as a list, or if I am trying to convert something using > json, there is no standard way of doing that for a custom object (I > know I can do __getitem__ and/or __iter__, but I many processes don't > try these if the object is not a subclass of dict or list/tuple) Conditional execution, indexing (__index__), numeric conversions (__float__ also), and displaying are special cases related to syntax operations. Functions that unnecessarily restrict inputs to subclasses of list or dict will not be solved by this. You have left out the use of abstract base classes. An iterable that can be used as a mapping can register itself as a mapping. Json could check whether something is a sequence or mapping and iterate to get values or pairs of values. Of course, the tranformation would be unidirectional. > Proposal: > What I am proposing is something like: > > object.__cast__(self, to_class): > """ > to_class: the class type that you wish to return. > """ The excessive indents of 31 and 15 spaces make the rest of this post unnecessarily hard to read. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list From framstag at rus.uni-stuttgart.de Tue Nov 10 10:51:05 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Tue, 10 Nov 2015 15:51:05 +0000 (UTC) Subject: corrupt download with urllib2 References: Message-ID: Ulli Horlacher wrote: > Peter Otten <__peter__ at web.de> wrote: > > - consider shutil.copyfileobj to limit memory usage when dealing with data > > of arbitrary size. > > > > Putting it together: > > > > with open(sz, "wb") as szo: > > shutil.copyfileobj(u, szo) > > This writes the http stream binary to the file. without handling it > manually chunk by chunk? I have a problem with it: There is no feedback for the user about the progress of the transfer, which can last several hours. For small files shutil.copyfileobj() is a good idea, but not for huge ones. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From __peter__ at web.de Tue Nov 10 11:48:48 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Nov 2015 17:48:48 +0100 Subject: corrupt download with urllib2 References: Message-ID: Ulli Horlacher wrote: > Ulli Horlacher wrote: >> Peter Otten <__peter__ at web.de> wrote: > >> > - consider shutil.copyfileobj to limit memory usage when dealing with >> > data >> > of arbitrary size. >> > >> > Putting it together: >> > >> > with open(sz, "wb") as szo: >> > shutil.copyfileobj(u, szo) >> >> This writes the http stream binary to the file. without handling it >> manually chunk by chunk? > > I have a problem with it: There is no feedback for the user about the > progress of the transfer, which can last several hours. > > For small files shutil.copyfileobj() is a good idea, but not for huge > ones. Indeed. Have a look at the source code: def copyfileobj(fsrc, fdst, length=16*1024): """copy data from file-like object fsrc to file-like object fdst""" while 1: buf = fsrc.read(length) if not buf: break fdst.write(buf) As simple as can be. I suggested the function as an alternative to writing the loop yourself when your example code basically showed dest.write(source.read()) For the huge downloads that you intend to cater to you probably want your script not just to print a dot on every iteration, you need expected remaining time, checksums, ability to stop and resume a download and whatnot. Does the Perl code offer that? Then why rewrite? Or are there Python libraries that do that out of the box? Can you reuse them? From framstag at rus.uni-stuttgart.de Tue Nov 10 12:21:24 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Tue, 10 Nov 2015 17:21:24 +0000 (UTC) Subject: corrupt download with urllib2 References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > > I have a problem with it: There is no feedback for the user about the > > progress of the transfer, which can last several hours. > > > > For small files shutil.copyfileobj() is a good idea, but not for huge > > ones. > > Indeed. Have a look at the source code: > > def copyfileobj(fsrc, fdst, length=16*1024): > """copy data from file-like object fsrc to file-like object fdst""" > while 1: > buf = fsrc.read(length) > if not buf: > break > fdst.write(buf) > > As simple as can be Oooops - that's all?! > I suggested the function as an alternative to writing > the loop yourself when your example code basically showed Good idea :-) > For the huge downloads that you intend to cater to you probably want your > script not just to print a dot on every iteration, you need expected > remaining time, checksums, ability to stop and resume a download and > whatnot. > > Does the Perl code offer that? Of course, yes. For download AND upload. > Then why rewrite? There is no more a Perl compiler for windows which supports https. > Or are there Python libraries that do that out of the box? No. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From tjreedy at udel.edu Tue Nov 10 12:49:19 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Nov 2015 12:49:19 -0500 Subject: IDLE quits unexpectedly when about to open or creat a new file In-Reply-To: References: Message-ID: On 11/10/2015 6:01 AM, Chris Angelico wrote: > On Tue, Nov 10, 2015 at 9:46 PM, wrote: >> I need help to find out what's going on. I did some research, but I couldn't find anything to solve this problem: >> >> - I open the IDLE program; From the Start menu icon, let us presume. >> - I go to the 'File' menu; Of the shell window, I presume. >> - I select the 'New File' option This should create an empty EditorWindow instance. >> - IDLE quits. Puzzling. The shell window is a subclass of EditorWindow, so EditorWindow.__init__ has already run once -- without the extra stuff added by the subclass. >> I run the IDLE version 3.3.3 on Windows 8.1 Pro. >> Should I install the most recent version? That would be a good idea in general. But first try what Chris suggested below. I am about half sure that the specific problem is on your system. It is possible that you need to delete something in HOMEDIR/.idlerc/ but lets see what the error message is. Have you been using IDLE a while, or just started? > That sounds like a very interesting problem. Can you try running it > from the command line, please? I'm not sure how to open one up from > Win 8, but it should be in the Start menu somewhere, or possibly press > Windows+R and type "cmd". With that up, type this: > > python -m idlelib.idle > > That should open up the same IDLE window that you know and recognize. > Do the exact same thing that caused the unexpected termination, and > then you should go back to the command prompt - hopefully with some > sort of error message. Copy and paste that message (as text, please, > not an image) into an email; that information could be very helpful. -- Terry Jan Reedy From none at mailinator.com Tue Nov 10 15:36:52 2015 From: none at mailinator.com (mm0fmf) Date: Tue, 10 Nov 2015 20:36:52 +0000 Subject: using binary in python In-Reply-To: References: Message-ID: On 10/11/2015 20:14, Dennis Lee Bieber wrote: > The Ada language defines the end of Text file to consist of It is 15 years this month since I last worked in place that used Ada. I think that calls for a wee dram to celebrate ;-) From random832 at fastmail.com Tue Nov 10 15:44:38 2015 From: random832 at fastmail.com (Random832) Date: Tue, 10 Nov 2015 15:44:38 -0500 Subject: using binary in python References: Message-ID: <8737wda8jt.fsf@fastmail.com> Dennis Lee Bieber writes: > To be strict -- a text file has system defined means of marking > line endings. UNIX/Linux uses just a character; Windows uses the pair > . TRS-DOS used just for end of line. Some operating systems > may have used count-delimited formats (and then there is the VMS FORTRAN > segmented records with start and end segment bits). Another possibility would be fixed-length records. The ANSI C standard permits a maximum line length (no less than 254) and for trailing spaces to be ignored. From breamoreboy at yahoo.co.uk Tue Nov 10 16:22:08 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 10 Nov 2015 21:22:08 +0000 Subject: using binary in python In-Reply-To: References: Message-ID: On 10/11/2015 20:36, mm0fmf via Python-list wrote: > On 10/11/2015 20:14, Dennis Lee Bieber wrote: >> The Ada language defines the end of Text file to consist of > > It is 15 years this month since I last worked in place that used Ada. I > think that calls for a wee dram to celebrate ;-) Followed by a chorus or two of the Ian Dury song about Ada to put the icing on the cake. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From kent at z-sverige.nu Tue Nov 10 16:29:01 2015 From: kent at z-sverige.nu (kent nyberg) Date: Tue, 10 Nov 2015 16:29:01 -0500 Subject: using binary in python In-Reply-To: References: Message-ID: <20151110212901.GA18609@z-sverige.nu> On Mon, Nov 09, 2015 at 10:20:25PM -0800, Larry Hudson via Python-list wrote: > Your questions are somewhat difficult to answer because you misunderstand > binary. The key is that EVERYTHING in a computer is binary. There are NO > EXCEPTIONS, it's all binary ALL the time. The difference comes about in how > this binary data is displayed and manipulated. I want to emphasize, ALL the > DATA is binary. > Thanks alot for taking the time. I get it now. I sort of, but not fully, misunderstood the conecpt of binary files. The thing I was after; and the thing Im playing with now after a more succesfull time with google, is writing more specific things to a file than just strings. English is not my native language so please forgive me, but I wanted to write specifc 16bit codes, and read them. And later play with bitwise operations on them. Sort of. It might not make sense at all, but hey.. it doesnt have to. Thanks anyway. :) From none at mailinator.com Tue Nov 10 17:17:37 2015 From: none at mailinator.com (mm0fmf) Date: Tue, 10 Nov 2015 22:17:37 +0000 Subject: OT: Re: using binary in python In-Reply-To: References: Message-ID: <82u0y.114989$bA1.105280@fx41.am4> On 10/11/2015 21:02, Dennis Lee Bieber wrote: > On Tue, 10 Nov 2015 20:36:52 +0000, mm0fmf via Python-list > declaimed the following: > >> On 10/11/2015 20:14, Dennis Lee Bieber wrote: >>> The Ada language defines the end of Text file to consist of >> >> It is 15 years this month since I last worked in place that used Ada. I >> think that calls for a wee dram to celebrate ;-) > > Given that a dram is 1/8 of a "fluid ounce" that leads to the > conclusion that a "wee dram" is based on US standard fluid once, vs British > standard fluid ounce... > > > My language preferences do tend to be the extremes: Python for quick > throw-away stuff, Ada for more formal stuff (since it has a much more > rigorous syntax than Pascal, Modula-2, C/C++, Java -- no optional block > delimiters, no dangling else, etc.) > > Unfortunately, as a hobbyist dabbler at home, I can't justify the time > to port an Ada compiler to Arduino, TIVA, Propeller, Beaglebone (though the > latter may just be a case of porting the hardware access). So... I'm stuck > with variants of C for those devices (again, excluding the Linux based > Beaglebone) > I escaped having to produce new code in Ada, I merely had to run some scripts that added the compiled C binaries into the Ada gloop! C user since 1983, C++ user since 2002, Python and C# since 2010. I regularly pinch myself that it seems to be painfully easy to be productive using Python compared to the other langauges! From kent at z-sverige.nu Tue Nov 10 17:27:21 2015 From: kent at z-sverige.nu (kent nyberg) Date: Tue, 10 Nov 2015 17:27:21 -0500 Subject: bitwise operator, bits dont go into bitbucket..? Message-ID: <20151110222721.GA18905@z-sverige.nu> Im reading about bitwise operators and is it true to say they dont work 100% as in C? bitwise operators in C seem to result in bits going to the so called bitbucket. For example, 0b00000001. Shifting it >> 1 in C it seems to add on zero to the left and the 1 to the right gets throwned away. But doing it in python just adds one more bit, from the left. That is, 0b00000001 >> 1 = 0b000000001. Bitwise operators in C (when reading examples,) gives some time code that check specific bits by shifting the bits left and right to make every bit but the specific one to zeros. As I understand bitwise operators in python, this is not possible then? From rosuav at gmail.com Tue Nov 10 17:33:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Nov 2015 09:33:38 +1100 Subject: bitwise operator, bits dont go into bitbucket..? In-Reply-To: <20151110222721.GA18905@z-sverige.nu> References: <20151110222721.GA18905@z-sverige.nu> Message-ID: On Wed, Nov 11, 2015 at 9:27 AM, kent nyberg wrote: > Im reading about bitwise operators and is it true to say they dont work 100% as in C? > bitwise operators in C seem to result in bits going to the so called bitbucket. > For example, 0b00000001. Shifting it >> 1 in C it seems to add on zero to the left and the 1 to the right gets throwned away. > > But doing it in python just adds one more bit, from the left. > That is, 0b00000001 >> 1 = 0b000000001. I'm not sure what you're expecting Python to do here, but right-shifting the integer 1 results in the integer 0: >>> 0b000001 >> 1 0 > Bitwise operators in C (when reading examples,) gives some time code that check specific bits by > shifting the bits left and right to make every bit but the specific one to zeros. > As I understand bitwise operators in python, this is not possible then? If you want to check specific bits (in C or Python, either way), it's much more common to use bitwise AND than bit shifts: >>> 0b100011011101010110 & 0b000000010000 16 >>> print(bin(_)) 0b10000 This will be either the same number as the right hand side (if the bit had been set) or zero (if it hadn't). ChrisA From plucena24 at gmail.com Tue Nov 10 17:36:04 2015 From: plucena24 at gmail.com (Pablo Lucena) Date: Tue, 10 Nov 2015 17:36:04 -0500 Subject: Keeping context-manager object alive through function calls Message-ID: I am running into a bit of an issue with keeping a context manager open through function calls. Here is what I mean: There is a context-manager defined in a module which I use to open SSH connections to network devices. The "setup" code handles opening the SSH sessions and handling any issues, and the teardown code deals with gracefully closing the SSH session. I normally use it as follows: from manager import manager def do_stuff(device): with manager(device) as conn: output = conn.send_command("show ip route") #process output... return processed_output In order to keep the SSH session open and not have to re-establish it across function calls, I would like to do add an argument to "do_stuff" which can optionally return the SSH session along with the data returned from the SSH session, as follows: def do_stuff(device, return_handle=False): with manager(device) as conn: output = conn.send_command("show ip route") #process output... if return_handle: return (processed_output, conn) else: return processed_output I would like to be able to call this function "do_stuff" from another function, as follows, such that it signals to "do_stuff" that the SSH handle should be returned along with the output. def do_more_stuff(device): data, conn = do_stuff(device, return_handle=True) output = conn.send_command("show users") #process output... return processed_output However the issue that I am running into is that the SSH session is closed, due to the do_stuff function "returning" and triggering the teardown code in the context-manager (which gracefully closes the SSH session). I have tried converting "do_stuff" into a generator, such that its state is suspended and perhaps causing the context-manager to stay open: def do_stuff(device, return_handle=False): with manager(device) as conn: output = conn.send_command("show ip route") #process output... if return_handle: yield (processed_output, conn) else: yield processed_output And calling it as such: def do_more_stuff(device): gen = do_stuff(device, return_handle=True) data, conn = next(gen) output = conn.send_command("show users") #process output... return processed_output However this approach does not seem to be working in my case, as the context-manager gets closed, and I get back a closed socket. Is there a better way to approach this problem? Maybe my generator needs some more work...I think using a generator to hold state is the most "obvious" way that comes to mind, but overall should I be looking into another way of keeping the session open across function calls? Thanks -- *Pablo Lucena* From ben+python at benfinney.id.au Tue Nov 10 17:47:09 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Nov 2015 09:47:09 +1100 Subject: Keeping context-manager object alive through function calls References: Message-ID: <85twoteaky.fsf@benfinney.id.au> Pablo Lucena writes: > In order to keep the SSH session open and not have to re-establish it > across function calls, I would like to do add an argument to > "do_stuff" which can optionally return the SSH session along with the > data returned from the SSH session, as follows: > > def do_stuff(device, return_handle=False): > with manager(device) as conn: > output = conn.send_command("show ip route") > #process output... > if return_handle: > return (processed_output, conn) > else: > return processed_output Since you're making it the caller's responsibility to deal with the context manager, why not require the caller to *provide* the context manager in the first place:: def do_stuff(conn): """ Do stuff via the device connection `conn`. :param conn: The context manager for the device connection. :return: The processed output. """ with conn: output = conn.send_command("show ip route") #process output... return processed_output Also, note that if you just unconditionally want to return the output, do it *outside* the ?with? block. Then your caller is the one responsible for creating the connection manager, and has the option of interrogating it further if it needs to:: bsu5000_conn = make_connection("bsu5000") gen = do_stuff(bsu5000_conn) do_more_things_with(bsu5000_conn) -- \ ?I don't know anything about music. In my line you don't have | `\ to.? ?Elvis Aaron Presley (1935?1977) | _o__) | Ben Finney From tim at akwebsoft.com Tue Nov 10 17:47:56 2015 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 10 Nov 2015 13:47:56 -0900 Subject: Using subprocess to capture a progress line Message-ID: <20151110224756.GA1944@mail.akwebsoft.com> Using python 2.7.6 on ubuntu 14.04 The application in question is run with bash and gnome-terminal : I've written a command-line "wrapper" for youtube-dl, executing youtube-dl as a subprocess. ------------------------------------------------------------------ youtube-dl reports download progress on one line. I.E. the line is overwritten numerous times with no carriage return until the downloading is finished. ------------------------------------------------------------------ The following code runs the youtube-dl command and reports each line as output by youtube-dl ########### p = subprocess.Popen(list(args), stderr=subprocess.STDOUT, stdout=subprocess.PIPE) while True: line = p.stdout.readline() if not line: break tmp = line.strip() print tmp ########### However this method not does show the download progress _until_ the download is complete. To clarify : follows is output from my app running youtube-dl. I've annotated the line in question with '###' [youtube] ZIgnHPqp0Dk: Downloading webpage [youtube] ZIgnHPqp0Dk: Downloading video info webpage [youtube] ZIgnHPqp0Dk: Extracting video information [youtube] ZIgnHPqp0Dk: Downloading js player en_US-vfljDEtYP [youtube] ZIgnHPqp0Dk: Downloading DASH manifest [download] Destination: Someday Soon - Judy Collins 1969.avi.m4a ### the line below is not seen until download is finished. [download] 100% of 7.58MiB in 00:12.85KiB/s ETA 00:00 [ffmpeg] Correcting container in "Someday Soon - Judy Collins 1969.avi.m4a" [ffmpeg] Destination: Someday Soon - Judy Collins 1969.avi.mp3 Deleting original file Someday Soon - Judy Collins 1969.avi.m4a (pass -k to keep) Is there a way to code subprocess so the the progress is being shown? In my case lines being output aren't being shown unless a newline is sent, or so I understand it. FYI : the need for this function in this case is trivial, but the solution will be enlightening for me and have other uses, I'll bet. thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com From rosuav at gmail.com Tue Nov 10 17:53:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Nov 2015 09:53:43 +1100 Subject: Keeping context-manager object alive through function calls In-Reply-To: References: Message-ID: On Wed, Nov 11, 2015 at 9:36 AM, Pablo Lucena wrote: > And calling it as such: > > def do_more_stuff(device): > gen = do_stuff(device, return_handle=True) > data, conn = next(gen) > output = conn.send_command("show users") > #process output... > return processed_output The first question needs to be: When *is* conn to be closed? What you've done here is abandon all of the benefit of the context manager, because it's no longer clear when you're done with the connection. Here's an alternative: Turn your generator into another context manager. from contextlib import contextmanager @contextmanager def do_stuff(device): with manager(device) as conn: output = conn.send_command("show ip route") #process output... yield (processed_output, conn) def do_stuff_now(device): with do_stuff(device) as (out, conn): return out This forces you to separate the return_handle=True and return_handle=False modes into two separate functions, but since one is defined in terms of the other, you don't have a massive maintenance burden. (Backward compatibility might have you call the first one do_stuff_with_handle and the second one gets the name do_stuff. Or whatever names make sense. Handwave.) So now you can use do_stuff_now() the way you were using do_stuff(), and if you want to keep using the handle afterward, you use it like this: def do_more_stuff(device): with do_stuff(device) as (data, conn): output = conn.send_command("show users") #process output... return processed_output This guarantees that the device will be closed as you depart do_more_stuff. There are other ways, but this is an easy way to build context managers on top of context managers. ChrisA From kent at z-sverige.nu Tue Nov 10 17:56:27 2015 From: kent at z-sverige.nu (kent nyberg) Date: Tue, 10 Nov 2015 17:56:27 -0500 Subject: bitwise operator, bits dont go into bitbucket..? In-Reply-To: References: <20151110222721.GA18905@z-sverige.nu> Message-ID: <20151110225627.GA19339@z-sverige.nu> On Wed, Nov 11, 2015 at 09:33:38AM +1100, Chris Angelico wrote: > On Wed, Nov 11, 2015 at 9:27 AM, kent nyberg wrote: > > If you want to check specific bits (in C or Python, either way), it's > much more common to use bitwise AND than bit shifts: > > >>> 0b100011011101010110 & 0b000000010000 > 16 > >>> print(bin(_)) > 0b10000 > So, to check if 0b010[this one bit]010 is set, i do & 0b0001000 That is, I set just that one to 1 in the other and then the & operator will make it return 0 if its not set. Since every other is zero, the return will be zero if its not. Since & operator sets 0 if not both are 1. Right? Id so, Thanks. My misunderstanding was that 0b01000 (for example,) first could be shifted left. To become 0b10000. And then shifted right to become 0b00001. The shifting would turn every other digit to 0 and leave only the wanted one untouched. That way, I could check if its 0 or 1. If you understand my own logic of how it works. But I got it wrong, and I think I know how to do it with & operator. > This will be either the same number as the right hand side (if the bit > had been set) or zero (if it hadn't). > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Nov 10 18:16:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Nov 2015 10:16:17 +1100 Subject: bitwise operator, bits dont go into bitbucket..? In-Reply-To: <20151110225627.GA19339@z-sverige.nu> References: <20151110222721.GA18905@z-sverige.nu> <20151110225627.GA19339@z-sverige.nu> Message-ID: On Wed, Nov 11, 2015 at 9:56 AM, kent nyberg wrote: > So, to check if 0b010[this one bit]010 is set, i do & 0b0001000 > > That is, I set just that one to 1 in the other and then the & operator will make it return > 0 if its not set. Since every other is zero, the return will be zero if its not. Since & operator sets 0 > if not both are 1. Right? > > Id so, Thanks. Exactly! It's common to have named constants for things that matter to you; for example, you can find out if a file/directory is world-writable like this: >>> import stat >>> os.stat("/").st_mode & stat.S_IWOTH 0 >>> os.stat("/tmp").st_mode & stat.S_IWOTH 2 So my root directory is not world writable (result of zero), and the /tmp directory is. (This is not surprising.) The S_IWOTH constant is simply the integer 2, but giving it a name makes it a bit easier to see what's going on in the code. (Not that the name is abundantly clear... it could be improved on. But it's better than just '2'.) > My misunderstanding was that > 0b01000 (for example,) first could be shifted left. To become 0b10000. > And then shifted right to become 0b00001. > The shifting would turn every other digit to 0 and leave only the wanted one untouched. > That way, I could check if its 0 or 1. If you understand my own logic of how it works. > But I got it wrong, and I think I know how to do it with & operator. That's true of right shifting, but when you left shift, you're depending on a specific word size. Even in C, it's possible to get burned by that (eg when you move from 32-bit to 64-bit), and in Python, integers have infinite size. If you definitely want that behaviour, you can do this: (0b01000 << 1) & 0b11111 which will mask off your result to just five bits, giving you the "drop the top bit" effect. But for bit testing and manipulation, it's way easier to use AND/OR/XOR than shifts. The one place you might want to use bit shifts is in _creating_ those constants. For instance: STYLE_FOO = 1 << 0 STYLE_BAR = 1 << 1 STYLE_BAZ = 1 << 2 STYLE_ABC = 1 << 3 STYLE_QWE = 1 << 4 STYLE_XYZ = 1 << 5 >From this table, it's obvious that they've been assigned successive bits. You can do the same with an enumeration: >>> class Style(enum.IntEnum): ... FOO = 1 << 0 ... BAR = 1 << 1 ... BAZ = 1 << 2 ... ABC = 1 << 3 ... QWE = 1 << 4 ... XYZ = 1 << 5 ... >>> Style.BAR >>> Style.QWE And then you can test to see if some style was chosen: >>> widget = Style.FOO | Style.QWE >>> widget & Style.ABC 0 >>> widget & Style.QWE 16 Does that make things a bit easier to read? ChrisA From rosuav at gmail.com Tue Nov 10 18:28:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Nov 2015 10:28:26 +1100 Subject: Using subprocess to capture a progress line In-Reply-To: <20151110224756.GA1944@mail.akwebsoft.com> References: <20151110224756.GA1944@mail.akwebsoft.com> Message-ID: On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson wrote: > I've written a command-line "wrapper" for youtube-dl, executing > youtube-dl as a subprocess. > > ------------------------------------------------------------------ > youtube-dl reports download progress on one line. I.E. the line is > overwritten numerous times with no carriage return until the > downloading is finished. > ------------------------------------------------------------------ > Sounds to me like a possible buffering problem. But since youtube-dl is implemented in Python, you might find it easier to "pip install youtube_dl" and work with the methods directly: >>> import youtube_dl >>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"]) Should be possible to manipulate around the outside of that. ChrisA From tim at akwebsoft.com Tue Nov 10 18:51:02 2015 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 10 Nov 2015 14:51:02 -0900 Subject: Using subprocess to capture a progress line In-Reply-To: References: <20151110224756.GA1944@mail.akwebsoft.com> Message-ID: <20151110235102.GB1944@mail.akwebsoft.com> * Chris Angelico [151110 14:35]: > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson wrote: > > I've written a command-line "wrapper" for youtube-dl, executing > > youtube-dl as a subprocess. > > > > ------------------------------------------------------------------ > > youtube-dl reports download progress on one line. I.E. the line is > > overwritten numerous times with no carriage return until the > > downloading is finished. > > ------------------------------------------------------------------ > > > > Sounds to me like a possible buffering problem. But since youtube-dl > is implemented in Python, you might find it easier to "pip install > youtube_dl" and work with the methods directly: > > >>> import youtube_dl > >>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"]) Frankly, I'd prefer - in the long run - to use youtube_dl (the module). But, when I do as you have suggested (and have tried previously) I get the following: youtube_dl.utils.DownloadError: ERROR: no suitable InfoExtractor I've briefly researched the error and so far haven't come up with an solution - guessing that other setup code is needed ... As for the buffering issue, at this point, I'll try using a lower-level function like sys.stdout.write when the line tests for '[download]' and 'ETA'. :) more elegant solutions welcome. I do intend to investigate using youtube_dl, once subprocess has been dealt with. thanks for the quick reply -- Tim http://www.akwebsoft.com, http://www.tj49.com From random832 at fastmail.com Tue Nov 10 19:03:55 2015 From: random832 at fastmail.com (Random832) Date: Tue, 10 Nov 2015 19:03:55 -0500 Subject: using binary in python References: Message-ID: <87ziylfllg.fsf@fastmail.com> Dennis Lee Bieber writes: > > Given that a dram is 1/8 of a "fluid ounce" that leads to the > conclusion that a "wee dram" is based on US standard fluid once, 29.6 ml > vs British standard fluid ounce... 28.4 ml It's our _pints_ that are smaller than yours, not our ounces. From random832 at fastmail.com Tue Nov 10 19:04:16 2015 From: random832 at fastmail.com (Random832) Date: Tue, 10 Nov 2015 19:04:16 -0500 Subject: using binary in python References: Message-ID: <87y4e5flkv.fsf@fastmail.com> Dennis Lee Bieber writes: > Given that a dram is 1/8 of a "fluid ounce" that leads to the > conclusion that a "wee dram" is based on US standard fluid once, 29.6 ml > vs British standard fluid ounce... 28.4 ml It's our _pints_ that are smaller than yours, not our ounces. From tim at akwebsoft.com Tue Nov 10 19:14:36 2015 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 10 Nov 2015 15:14:36 -0900 Subject: Using subprocess to capture a progress line In-Reply-To: <20151110235102.GB1944@mail.akwebsoft.com> References: <20151110224756.GA1944@mail.akwebsoft.com> <20151110235102.GB1944@mail.akwebsoft.com> Message-ID: <20151111001436.GC1944@mail.akwebsoft.com> * Tim Johnson [151110 14:55]: > * Chris Angelico [151110 14:35]: > > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson wrote: > > > I've written a command-line "wrapper" for youtube-dl, executing > > > youtube-dl as a subprocess. > > > > > > ------------------------------------------------------------------ > > > youtube-dl reports download progress on one line. I.E. the line is > > > overwritten numerous times with no carriage return until the > > > downloading is finished. > > > ------------------------------------------------------------------ > > > > > > > Sounds to me like a possible buffering problem. But since youtube-dl > > is implemented in Python, you might find it easier to "pip install > > youtube_dl" and work with the methods directly: > > As for the buffering issue, at this point, I'll try using a > lower-level function like sys.stdout.write when the line > tests for '[download]' and 'ETA'. That method doesn't work ... so far. Oh well. -- Tim http://www.akwebsoft.com, http://www.tj49.com From torriem at gmail.com Tue Nov 10 19:19:14 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 10 Nov 2015 17:19:14 -0700 Subject: using binary in python In-Reply-To: <20151110212901.GA18609@z-sverige.nu> References: <20151110212901.GA18609@z-sverige.nu> Message-ID: <56428982.9010205@gmail.com> On 11/10/2015 02:29 PM, kent nyberg wrote: > On Mon, Nov 09, 2015 at 10:20:25PM -0800, Larry Hudson via Python-list wrote: >> Your questions are somewhat difficult to answer because you misunderstand >> binary. The key is that EVERYTHING in a computer is binary. There are NO >> EXCEPTIONS, it's all binary ALL the time. The difference comes about in how >> this binary data is displayed and manipulated. I want to emphasize, ALL the >> DATA is binary. >> > > Thanks alot for taking the time. > I get it now. I sort of, but not fully, misunderstood the conecpt of binary files. > The thing I was after; and the thing Im playing with now after a more succesfull time with google, > is writing more specific things to a file than just strings. > English is not my native language so please forgive me, but > I wanted to write specifc 16bit codes, and read them. And later play with bitwise operations on them. Sort of. > It might not make sense at all, but hey.. it doesnt have to. > Thanks anyway. :) You're correct; it doesn't make that much sense. If it were me I'd write out my numbers in text format to the file. You can always read them back in and covert them to a number. Just a quick couple of notes on "binary" vs "text". In the old days on Windows, the difference between "binary" and "ascii" when it came to file reading was simply the interpretation of the end-of-line marker. Whenever you wrote out a \n, it got silently converted to two bytes, 0x0d 0x0a. If you were trying to write a jpeg file, for example, this would corrupt things as you well know. In the Unix world, we never worried about such things because the end-of-line marker was simple 0x0a. It was never translated and never was expanded silently. So when it came to how we worked with files, there was no difference between binary and ascii modes as far as the C library open() was concerned. Now with Python 3, we now again do have to think about the distinction between "text" and "binary" when working with files. If we want to open a text file, we have to open it while specifying the expected text encoding, whether that is UTF-8, UCS-2, UTF-16, or some other old and esoteric encoding. That is to say when Python reads from a text file, there is always going to be a decoding process going on where text file bytes are read in, and then converted into unicode characters. When writing a text file out, unicode characters have to be encoded into a series of bytes. If Python knows what encoding we want, then it can do this automatically as we write to the file. In Python 3 opening a file for binary will read in raw bytes and you can manipulate them however you wish. From tim at akwebsoft.com Tue Nov 10 19:31:21 2015 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 10 Nov 2015 15:31:21 -0900 Subject: Using subprocess to capture a progress line In-Reply-To: <20151110235102.GB1944@mail.akwebsoft.com> References: <20151110224756.GA1944@mail.akwebsoft.com> <20151110235102.GB1944@mail.akwebsoft.com> Message-ID: <20151111003121.GD1944@mail.akwebsoft.com> * Tim Johnson [151110 14:55]: > * Chris Angelico [151110 14:35]: > > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson wrote: > > > I've written a command-line "wrapper" for youtube-dl, executing > > is implemented in Python, you might find it easier to "pip install > > youtube_dl" and work with the methods directly: <<...> > > > >>> import youtube_dl > > >>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"]) > > Frankly, I'd prefer - in the long run - to use youtube_dl (the > module). > > But, when I do as you have suggested (and have tried previously) I > get the following: > > youtube_dl.utils.DownloadError: ERROR: no suitable InfoExtractor > It looks as if the developers are constantly upgrading. I just upgraded youtube_dl sudo pip install --upgrade youtube_dl And ran the code which is provided under the topic "EMBEDDING YOUTUBE-DL" at https://github.com/rg3/youtube-dl/blob/master/README.md At I got a successful download, AFAICS -- Tim http://www.akwebsoft.com, http://www.tj49.com From shriphanip at gmail.com Tue Nov 10 20:09:37 2015 From: shriphanip at gmail.com (shriphanip at gmail.com) Date: Tue, 10 Nov 2015 17:09:37 -0800 (PST) Subject: Swig + Numpy.i with a const int16_t pointer Message-ID: <05ae95fa-68f0-43ca-8b36-04a827c5d878@googlegroups.com> I am trying to wrap the following function with SWIG so I can call it from Python. The signature is: ``` int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame, size_t frame_length); ``` I have the following SWIG file: https://gist.github.com/shriphani/92c587ea4c32bafc9d97 At the end of this, I get the following error: webrtc_vad.i:22: Warning 453: Can't apply (int16_t const *IN_ARRAY1,unsigned int DIM1). No typemaps are defined. If I drop the unsigned bit in the signature, then it compiles fine but the function signature is carried as-is (i.e. the function expects an int pointer and all that business). Does anyone have a solution? Regards, Shriphani From steve at pearwood.info Tue Nov 10 20:10:56 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 11 Nov 2015 12:10:56 +1100 Subject: Question about math.pi is mutable References: <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <854mgufkqm.fsf@benfinney.id.au> <201511101033.tAAAXYZP001340@fido.openend.se> Message-ID: <564295a3$0$1585$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Nov 2015 11:14 pm, Ben Finney wrote: >> Python -- yes, even CPython -- has a runtime compiler. When you import >> a module, it is compiled (if needed) just before the import. Likewise, >> when you call the `compile`, `eval` or `exec` built-ins, the compiler >> operates. >> >> I'm not calling this a JIT compiler, because the simple-minded >> compilation performed by `compile` etc doesn't use any run-time >> information. It just statically compiles the code to byte-code. > > That's what I though. I'm aware of JIT compilers, and was pretty sure > Python doesn't have them. What do you think PyPy is then? CPython is intentionally a pretty simple-minded compiler. Even no-brainer constant folding is mildly controversial among some Python devs. But CPython isn't "Python", it is just the reference implementation. Nuitka aims to be an optimized AOT (Ahead Of Time) Python compiler, and PyPy is already a state of the art (if not cutting edge) JIT Python compiler. And if Victor Skinner's experimental FAT Python works out, even CPython itself will gain some simple JIT techniques, rather similar to what Psycho was doing ten years ago. > What's more, if it operates at a whole-module > level, and not later than when the module is imported. Now you're getting into implementation details of the JIT compiler. Can it track entities across modules? How exactly does it operate? PyPy is a "tracing JIT", which (if I have understood correctly) means it actually analyses the code as it runs, using knowledge gained at runtime to dynamically decide what to compile. This means that PyPy is best suited to code that has long-running loops, and not well suited to scripts that don't run for a long time. But another (hypothetical) JIT compiler might be more like Psycho. > Under those conditions, I maintain my objection to the proposed > optimisation. > > The proposal is explicitly for optimisations made by the Python > compiler. As proposed, it only seems to be worthwhile once Python no > longer has a distinct ?compiler? and ?interpreter? is dissolved. Until > then, it seems pointless. Python has not had a distinct "compiler" and "interpreter" since about version 0.1. The execution module of Python as a dynamic byte-code compiled, interpreted language with eval and exec *depends* on the compiler being available during the execution phase, i.e. at runtime. Some of the things I've suggested already exist, and have proven that they work: Psycho and PyPy, to say nothing of similar technologies for other equally dynamic languages such as Javascript and Smalltalk. Others are state of the art compiler techniques -- they might not have been applied to *Python* but that's only because nobody has got around to it, not because it can't be done. I daresay that there are implementation challenges to making Python faster than it is without compromising on the semantics of the language, but there is nothing fundamentally impossible about the idea. Ben, I know that the IT crowd is rather conservative, and the Python community even more so, but at the point where you are denying the possibility of technologies which *already exist* I think that things have got a bit out of hand. It's a bit like somebody getting on Twitter to tweet "A globally interconnected communication network allowing computers all over the world to communicate? Impossible! And even if it were possible, nobody would use it." ;-) -- Steven From orgnut at yahoo.com Tue Nov 10 22:53:18 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 10 Nov 2015 19:53:18 -0800 Subject: using binary in python In-Reply-To: References: Message-ID: On 11/10/2015 12:14 PM, Dennis Lee Bieber wrote: > On Mon, 9 Nov 2015 22:20:25 -0800, Larry Hudson via Python-list > declaimed the following: > >> Of course it can. The only difference a text file and a binary file is the way it's opened. >> Text files are opened with 'r' or 'w', while binary files are opened with 'rb' or 'wb'. Being >> different modes, the reading/writing is handled differently. One obvious difference, the lines >> of a text file are marked by ending them with a newline character, so it's easy to read/write >> the text line-by-line. But the data in a binary file is completely arbitrary and is much > > To be strict -- a text file has system defined means of marking > line endings. UNIX/Linux uses just a character; Windows uses the pair > . TRS-DOS used just for end of line. Some operating systems > may have used count-delimited formats (and then there is the VMS FORTRAN > segmented records with start and end segment bits). > The main purpose of my message was to get across the idea of separating the actual data (as binary values) and the way this data is displayed (to the user/programmer). They are two entirely different concepts, and the OP was obviously confused about this. But of course, you're right -- I was careless/imprecise in some of my descriptions. -=- Larry -=- From steve+comp.lang.python at pearwood.info Wed Nov 11 02:18:59 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 11 Nov 2015 18:18:59 +1100 Subject: Keeping context-manager object alive through function calls References: Message-ID: <5642ebe7$0$1516$c3e8da3$5496439d@news.astraweb.com> On Wednesday 11 November 2015 09:36, Pablo Lucena wrote: > I am running into a bit of an issue with keeping a context manager open > through function calls. Here is what I mean: [...] > In order to keep the SSH session open and not have to re-establish it > across function calls, I would like to do add an argument to "do_stuff" > which can optionally return the SSH session along with the data returned > from the SSH session, as follows: That won't work. The whole point of the "with" statement is to automatically close the context manager when you leave the with statement. If you don't want it automatically closed, *don't use with*. There's nothing wrong with manually opening and closing the connection, if that's what you need. Open the ssh connection, pass it to your various functions, and close it only when you are done with it. Or, and this might be a better solution, move the with block up a level. Instead of putting it in "do_stuff" and the assorted other functions, open the connection *before* you call these functions: def main(): setup() with manager(device) as conn: do_stuff(conn) do_more_stuff(conn) do_even_more_stuff(conn) # Now we're finally done. sys.exit(0) [...] > I have tried converting "do_stuff" into a generator, such that its state > is suspended and perhaps causing the context-manager to stay open: [...] > However this approach does not seem to be working in my case, as the > context-manager gets closed, and I get back a closed socket. > > Is there a better way to approach this problem? Maybe my generator needs > some more work...I think using a generator to hold state is the most > "obvious" way that comes to mind, but overall should I be looking into > another way of keeping the session open across function calls? You might be able to get some awful hack using generators working, but it will be ugly, confusing and fragile. This is a sign you are abusing the context manager and using it in a way that goes against the design of the feature. Consider some future maintainer (perhaps even yourself, in six months or a year), reading the code, and completely puzzled why the SSH connection isn't closed when the with block is exited. -- Steve From steve+comp.lang.python at pearwood.info Wed Nov 11 02:38:30 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 11 Nov 2015 18:38:30 +1100 Subject: Question about math.pi is mutable References: <87ziyowy83.fsf@elektro.pacujo.net> <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <5641d63a$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5642f079$0$1527$c3e8da3$5496439d@news.astraweb.com> On Wednesday 11 November 2015 00:26, BartC wrote: > Does the Python language specify how it is to be compiled and executed? Not in so many words, but there are limitations on what you can do based on the specified semantics of Python. But so long as you meet those semantics, you can implement them any reasonable way you like: - CPython uses one specific implementation written in C; - PyPy uses a powerful tracing JIT compiler written in an intermediate language RPython; - IronPython uses the .Net CLR virtual machine; - Jython uses the Java virtual machine; - there was an experimental version of Python using the Parrot virtual machine; etc. Those implementations will naturally perform differently. For example, I believe that IronPython *generally* is faster than CPython, with some exceptions. > If not, then you can use any interpretation you like, provided the > program gives the expected results. Precisely. > That includes using a static compilation pass that generates byte-code, > even if it is only done immediately before running the main module, or > just before performing an import operation on another. That's what CPython already does. > Anything is possible. But the chances are that if you are running > CPython, then it will probably include a discrete byte-code compiler. Since compile, eval and exec are Python built-ins, if it doesn't include a byte-code compiler, it isn't Python. It's just a subset of Python. >> execute this Python snippet: >> >> result = x + 2 [...] >> But a JIT compiler gets to compile code right before that line is due to >> execute. By the time the JIT compiler gets to see that line of code, it >> can already know whether or not name "x" exists, and if so, which >> namespace it is in. It knows what value "x" has. > > How does it do that? How is the 'x+1' even stored in the machine? That depends entirely on the implementation of the compiler. > Suppose the preceding lines are: > > if random+bit()==1: > x=920.5 > else: > x=[8,5,4,9,1,7,6,3,2] > > or: > > if some_condition: del x > > it will probably know as much about x as the static compiler does! Not at all. The difference is, having called rand_bit() and tested whether it is 1, the compiler takes a branch: - it binds 920.5 to x - or it binds [8, 5, 4, ...] to x The compiler knows which branch it just took, *because it just took it*. If it doesn't know which branch it just took, it isn't a JIT compiler! It's just a classic, old-fashioned interpreter with no smarts. So, having just bound some value to x, the compiler knows that x is a float (or a list), and can optimize the next instruction, which is "x + 1". CPython can't do that, because it doesn't have the infrastructure to perform the necessary book-keeping. And it probably never will do that, because Guido likes the fact that CPython is simple enough for him to understand. He's happy for PyPy and other third-party implementations to do the clever stuff. -- Steven From marko at pacujo.net Wed Nov 11 03:30:41 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 11 Nov 2015 10:30:41 +0200 Subject: Question about math.pi is mutable References: <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <5641d63a$0$1603$c3e8da3$5496439d@news.astraweb.com> <5642f079$0$1527$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wptpey4u.fsf@elektro.pacujo.net> Steven D'Aprano : > Since compile, eval and exec are Python built-ins, if it doesn't > include a byte-code compiler, it isn't Python. It's just a subset of > Python. compile() can be implemented trivially, or in any other manner. It simply needs to return a "code object." I suspect even a string might work as a code object. Marko From marko at pacujo.net Wed Nov 11 03:30:41 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 11 Nov 2015 10:30:41 +0200 Subject: Question about math.pi is mutable References: <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <5641d63a$0$1603$c3e8da3$5496439d@news.astraweb.com> <5642f079$0$1527$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wptpey4u.fsf@elektro.pacujo.net> Steven D'Aprano : > Since compile, eval and exec are Python built-ins, if it doesn't > include a byte-code compiler, it isn't Python. It's just a subset of > Python. compile() can be implemented trivially, or in any other manner. It simply needs to return a "code object." I suspect even a string might work as a code object. Marko From kwpolska at gmail.com Wed Nov 11 04:48:03 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Wed, 11 Nov 2015 10:48:03 +0100 Subject: Using subprocess to capture a progress line In-Reply-To: <20151110224756.GA1944@mail.akwebsoft.com> References: <20151110224756.GA1944@mail.akwebsoft.com> Message-ID: On 10 November 2015 at 23:47, Tim Johnson wrote: > Using python 2.7.6 on ubuntu 14.04 > The application in question is run with bash and gnome-terminal : > > I've written a command-line "wrapper" for youtube-dl, executing > youtube-dl as a subprocess. > > ------------------------------------------------------------------ > youtube-dl reports download progress on one line. I.E. the line is > overwritten numerous times with no carriage return until the > downloading is finished. > ------------------------------------------------------------------ > > The following code runs the youtube-dl command and reports each line > as output by youtube-dl > ########### > p = subprocess.Popen(list(args), stderr=subprocess.STDOUT, > stdout=subprocess.PIPE) > while True: > line = p.stdout.readline() > if not line: > break > tmp = line.strip() > print tmp > ########### > > However this method not does show the download progress _until_ the > download is complete. There is no \n character at the end ? which means that p.stdout.readline() cannot return. In fact, if you printed repr() of the line you read, you would get this: b'\r[download] 54.9% of 2.73MiB at 26.73KiB/s ETA 00:47\r[download] 55.0% of 2.73MiB at 79.33KiB/s ETA 00:15\r?snip?\r[download] 100% of 2.73MiB in 00:01\n' The download line is implemented using \r, which is the carriage return character (return to the first character), and then by overwriting characters that were already printed. The solution? There are numerous. I?ll help you by obscuring the worst one. (1) [recommended] figure out how to make youtube_dl work as a library, read its main file to figure out the problem. Don?t mess with subprocess. (2) [don?t do it] do you need to intercept the lines? If you don?t set stderr= and stdout=, things will print just fine. (3) [DON?T DO IT] .ernq() punenpgre ol punenpgre naq znxr n zrff. PS. Thank you for setting a sensible Reply-To header on your messages. Which is something the list should be doing. -- Chris Warrick PGP: 5EAAEA16 From steve at pearwood.info Wed Nov 11 06:20:26 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 11 Nov 2015 22:20:26 +1100 Subject: Question about math.pi is mutable References: <8537wghwjb.fsf@benfinney.id.au> <85y4e8ggrj.fsf@benfinney.id.au> <85twowgfm6.fsf@benfinney.id.au> <564081e7$0$1592$c3e8da3$5496439d@news.astraweb.com> <56415873$0$1614$c3e8da3$5496439d@news.astraweb.com> <5641d63a$0$1603$c3e8da3$5496439d@news.astraweb.com> <5642f079$0$1527$c3e8da3$5496439d@news.astraweb.com> <87wptpey4u.fsf@elektro.pacujo.net> Message-ID: <5643247b$0$1598$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Nov 2015 07:30 pm, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Since compile, eval and exec are Python built-ins, if it doesn't >> include a byte-code compiler, it isn't Python. It's just a subset of >> Python. > > compile() can be implemented trivially, or in any other manner. It > simply needs to return a "code object." I suspect even a string might > work as a code object. Sure. That's just quality of implementation. In principle, a Python interpreter might even operate without any byte-code at all, parsing each line of code before executing it. Nevertheless, whatever quality of implementation compile/eval/exec offer, they *must* be available at runtime, otherwise the language is just a subset of Python. -- Steven From leonardmesiera at gmail.com Wed Nov 11 07:38:02 2015 From: leonardmesiera at gmail.com (Leonard Andrew Mesiera) Date: Wed, 11 Nov 2015 20:38:02 +0800 Subject: Guide in Deskop Application Development in Python for newbies In-Reply-To: References: <436bfe7e-ece3-454d-b0c7-81de0fe82acb@googlegroups.com> <563E1C95.7030609@gmail.com> <563EAA68.6080906@gmail.com> Message-ID: Thank you sir @Chris Warrick for your great suggestion, even though I really got overwhelmed by the things that I need to study to get this project done. I'm really new to programming so I havent heard or even tried DJANGO, but on your suggestion, if thats what I need to get my project done, that would I do. It would really take alot of time for me to finish this project, but thank you man, I really appreciate your help On Sun, Nov 8, 2015 at 5:22 PM, Chris Warrick wrote: > On 7 November 2015 at 15:44, wrote: > > How do you start building a desktop application in python? I mean where > do I start? Besides installing python on your windows what else do I need, > and any suggestion on how do I accomplish this project. > > > > Right now I really want to finish this beauty pageant judging system > which requires to have a client and a server, client would be for the > judges and a server that computes the scores from all the categories, (i do > hope you get I want mean by that project). I just finished reading > Headfirst Python and I really loving this language, so any help from all > the great programmers here would be so great. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > This project requires two very different components, or one monolithic > server. > > The first one is the server. It basically needs to talk to clients > (via HTTP) and to a database. This is a trivial app to write in your > favorite web framework, eg. Django [0]. Come up with a good database > structure (read the excellent tutorial and documentation, should get > you there), write some models. But you can?t write your views just > yet. Because the views you write depend strictly on the client. > > For the client, you basically have two choices: > (a) write a web application in Django; > (b) use a GUI framework and make a standalone desktop application. > > If you choose option (a), you need to learn HTML/CSS and write the > views for your Django application (or use a ready-made front-end > framework, eg. Bootstrap [1]). This is the simplest choice, and it > takes a lot of work away from you. Your users will use their favorite > web browser to access the voting system, log in, and make their votes, > and there is no special setup for them (apart from giving them > credentials to access your app). Your Django views will use the > built-in Django templating, forms, and is relatively simple to do > (might even be doable in a weekend). > > Route (b) is much more complicated. To follow this route, you need to > pick a GUI framework. There are also multiple options, I personally > recommend PySide, but you could also try wxWidgets, pygobject or kivy. > The web app side of things will require serializing data to JSON and > writing a RESTful API, but there are ready-made solutions for many web > frameworks [2]. > But most of those come with a catch: they usually make you produce > ugly code, because they are wrappers around ugly C++ APIs. And then > you need to write code to talk to your HTTP server. You can?t use the > beautiful requests library, because it will block ? so there?s more > work ahead, unless you want your app to be unresponsive every time you > talk to the server. For example, in Qt, you would need to use Qt > networking capabilities (which work asynchronously within the event > loop), or some other implementation that you can use asynchronously > (eg. Twisted, but then you lock yourself to Python 2, which is bad, or > threading, which has its limitations?) > And then you need to distribute your app to your users. Which is > already hard, because you need to coordinate Python, your GUI > framework, and your app. Are your users on Windows, Linux, or OS X? If > you have at least one person on a platform, you will need some sort of > testing environment? > > And no matter which route you choose, you can?t do much without a > Linux server, so there?s more learning to do. > > Sadly, developing big things is hard and requires a lot of knowledge ? > especially if you?re a one-man-band. > Here?s a short list of skills you need, with a subjectively suggested > implementation and ease of implementation: > > * understanding of the HTTP protocol (*) > * web application development (Django *) > * database schema writing (planning out the structure + Django ORM **) > * app server setup (uWSGI + nginx + Linux ***) > * database setup (PostgreSQL *** or something simpler[3]) > * Route A: > * HTML/CSS skills; a front-end framework (Bootstrap **) > * Route B: > * RESTful APIs (Django REST Framework ***/***** if you use OAuth) > * GUI framework (PyQt ****) > * talking to your server from within the framework (****/*****) > > [0]: https://www.djangoproject.com/ > [1]: http://getbootstrap.com/ > [2]: http://www.django-rest-framework.org/ > [3]: If this is going to be VERY small, you could go with a sqlite > database, which requires zero setup, but which is not suited for > anything more serious. > > Other learning materials: > > > https://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html > http://www.fullstackpython.com/ > http://deploypython.com/ > > On 8 November 2015 at 02:50, Michael Torrie wrote: > > On 11/07/2015 12:15 PM, paul.hermeneutic at gmail.com wrote: > >> Where would you say that web2py fits into > this mix > >> of tools? > > > > I am not familiar with it but I know it's supposed to be a lightweight > > framework for developing web-based sites and applications. Could be an > > excellent tool for the OP to use to build his user interface. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > web2py is weird, Django is more fun. > > -- > Chris Warrick > PGP: 5EAAEA16 > From leonardmesiera at gmail.com Wed Nov 11 07:39:40 2015 From: leonardmesiera at gmail.com (Leonard Andrew Mesiera) Date: Wed, 11 Nov 2015 20:39:40 +0800 Subject: Guide in Deskop Application Development in Python for newbies In-Reply-To: References: <436bfe7e-ece3-454d-b0c7-81de0fe82acb@googlegroups.com> <563E1C95.7030609@gmail.com> <563EAA68.6080906@gmail.com> Message-ID: Thank you sir @Chris Warrick for your great suggestion, even though I really got overwhelmed by the things that I need to study to get this project done. I'm really new to programming so I havent heard or even tried DJANGO, but on your suggestion, if thats what I need to get my project done, that would I do. It would really take alot of time for me to finish this project, but thank you man, I really appreciate your help On Wed, Nov 11, 2015 at 8:38 PM, Leonard Andrew Mesiera < leonardmesiera at gmail.com> wrote: > Thank you sir @Chris Warrick for your great suggestion, even though I > really got overwhelmed by the things that I need to study to get this > project done. I'm really new to programming so I havent heard or even > tried DJANGO, but on your suggestion, if thats what I need to get my > project done, that would I do. It would really take alot of time for me to > finish this project, but thank you man, I really appreciate your help > > > On Sun, Nov 8, 2015 at 5:22 PM, Chris Warrick wrote: > >> On 7 November 2015 at 15:44, wrote: >> > How do you start building a desktop application in python? I mean where >> do I start? Besides installing python on your windows what else do I need, >> and any suggestion on how do I accomplish this project. >> > >> > Right now I really want to finish this beauty pageant judging system >> which requires to have a client and a server, client would be for the >> judges and a server that computes the scores from all the categories, (i do >> hope you get I want mean by that project). I just finished reading >> Headfirst Python and I really loving this language, so any help from all >> the great programmers here would be so great. >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> This project requires two very different components, or one monolithic >> server. >> >> The first one is the server. It basically needs to talk to clients >> (via HTTP) and to a database. This is a trivial app to write in your >> favorite web framework, eg. Django [0]. Come up with a good database >> structure (read the excellent tutorial and documentation, should get >> you there), write some models. But you can?t write your views just >> yet. Because the views you write depend strictly on the client. >> >> For the client, you basically have two choices: >> (a) write a web application in Django; >> (b) use a GUI framework and make a standalone desktop application. >> >> If you choose option (a), you need to learn HTML/CSS and write the >> views for your Django application (or use a ready-made front-end >> framework, eg. Bootstrap [1]). This is the simplest choice, and it >> takes a lot of work away from you. Your users will use their favorite >> web browser to access the voting system, log in, and make their votes, >> and there is no special setup for them (apart from giving them >> credentials to access your app). Your Django views will use the >> built-in Django templating, forms, and is relatively simple to do >> (might even be doable in a weekend). >> >> Route (b) is much more complicated. To follow this route, you need to >> pick a GUI framework. There are also multiple options, I personally >> recommend PySide, but you could also try wxWidgets, pygobject or kivy. >> The web app side of things will require serializing data to JSON and >> writing a RESTful API, but there are ready-made solutions for many web >> frameworks [2]. >> But most of those come with a catch: they usually make you produce >> ugly code, because they are wrappers around ugly C++ APIs. And then >> you need to write code to talk to your HTTP server. You can?t use the >> beautiful requests library, because it will block ? so there?s more >> work ahead, unless you want your app to be unresponsive every time you >> talk to the server. For example, in Qt, you would need to use Qt >> networking capabilities (which work asynchronously within the event >> loop), or some other implementation that you can use asynchronously >> (eg. Twisted, but then you lock yourself to Python 2, which is bad, or >> threading, which has its limitations?) >> And then you need to distribute your app to your users. Which is >> already hard, because you need to coordinate Python, your GUI >> framework, and your app. Are your users on Windows, Linux, or OS X? If >> you have at least one person on a platform, you will need some sort of >> testing environment? >> >> And no matter which route you choose, you can?t do much without a >> Linux server, so there?s more learning to do. >> >> Sadly, developing big things is hard and requires a lot of knowledge ? >> especially if you?re a one-man-band. >> Here?s a short list of skills you need, with a subjectively suggested >> implementation and ease of implementation: >> >> * understanding of the HTTP protocol (*) >> * web application development (Django *) >> * database schema writing (planning out the structure + Django ORM **) >> * app server setup (uWSGI + nginx + Linux ***) >> * database setup (PostgreSQL *** or something simpler[3]) >> * Route A: >> * HTML/CSS skills; a front-end framework (Bootstrap **) >> * Route B: >> * RESTful APIs (Django REST Framework ***/***** if you use OAuth) >> * GUI framework (PyQt ****) >> * talking to your server from within the framework (****/*****) >> >> [0]: https://www.djangoproject.com/ >> [1]: http://getbootstrap.com/ >> [2]: http://www.django-rest-framework.org/ >> [3]: If this is going to be VERY small, you could go with a sqlite >> database, which requires zero setup, but which is not suited for >> anything more serious. >> >> Other learning materials: >> >> >> https://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html >> http://www.fullstackpython.com/ >> http://deploypython.com/ >> >> On 8 November 2015 at 02:50, Michael Torrie wrote: >> > On 11/07/2015 12:15 PM, paul.hermeneutic at gmail.com wrote: >> >> Where would you say that web2py fits into >> this mix >> >> of tools? >> > >> > I am not familiar with it but I know it's supposed to be a lightweight >> > framework for developing web-based sites and applications. Could be an >> > excellent tool for the OP to use to build his user interface. >> > >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> web2py is weird, Django is more fun. >> >> -- >> Chris Warrick >> PGP: 5EAAEA16 >> > > From rosuav at gmail.com Wed Nov 11 08:13:29 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Nov 2015 00:13:29 +1100 Subject: Python.exe is not a valid Win32 application error message In-Reply-To: <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Tue, Nov 10, 2015 at 11:34 AM, M. Kamisato via Python-list wrote: > I am running python on Windows XP SP3 and download version 3.5xx. I got the above error message and could not run the program. > I have downloaded Python version 2.7xx and it runs fine. > Is there any way I can get version 3.5xx to run on my computer? > Mel KamisatoBuena Park, CA You can't get 3.5 to run on XP, no; your options are: 1) Install Python 3.4, which does support XP 2) Upgrade to a newer version of Windows (anything from Vista onward will run 3.5; to save having to do this in future, jump straight to 7 or 10) 3) Make the jump to Linux or FreeBSD or some other OS. When 3.5.1 is released (currently scheduled for early December), you'll get a clear and simple error when you try to install, rather than strange issues about it not being a valid program. That won't change the platform support, but at least it won't be as confusing. ChrisA From torriem at gmail.com Wed Nov 11 10:28:11 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Nov 2015 08:28:11 -0700 Subject: Python.exe is not a valid Win32 application error message In-Reply-To: References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> Message-ID: <56435E8B.10103@gmail.com> On 11/11/2015 06:13 AM, Chris Angelico wrote: > On Tue, Nov 10, 2015 at 11:34 AM, M. Kamisato via Python-list > wrote: >> I am running python on Windows XP SP3 and download version 3.5xx. I got the above error message and could not run the program. >> I have downloaded Python version 2.7xx and it runs fine. >> Is there any way I can get version 3.5xx to run on my computer? >> Mel KamisatoBuena Park, CA > > You can't get 3.5 to run on XP, no; your options are: > > 1) Install Python 3.4, which does support XP > 2) Upgrade to a newer version of Windows (anything from Vista onward > will run 3.5; to save having to do this in future, jump straight to 7 > or 10) > 3) Make the jump to Linux or FreeBSD or some other OS. > > When 3.5.1 is released (currently scheduled for early December), > you'll get a clear and simple error when you try to install, rather > than strange issues about it not being a valid program. That won't > change the platform support, but at least it won't be as confusing. The Python website is looking very professional and polished these days. But we still don't have a simple message on the download page telling people Windows XP is no longer supported. Given the number of people posting lately (several each week), I would think even with the limited time and resources of the python.org webmaster a little warning message would be in order. Even when the installer is fixed, it would still be nice to have basic OS requirements listed before the download is ever clicked. From framstag at rus.uni-stuttgart.de Wed Nov 11 11:16:35 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 11 Nov 2015 16:16:35 +0000 (UTC) Subject: cross platform alternative for signal.SIGALRM? Message-ID: I am rewriting a Perl program into Python (2.7). It must run on Linux and Windows. With Linux I have no problems, but Windows... :-( The current show stopper is signal.SIGALRM which is not available on Windows: File "fexit.py", line 674, in formdata_post signal.signal(signal.SIGALRM,timeout_handler) AttributeError: 'module' object has no attribute 'SIGALRM' https://docs.python.org/2/library/signal.html signal.alarm(time) (...) Availability: Unix. Perl for Windows has had SIGALRM support (or some kind of emulation). Ok, I have to redesign this part of my code: def timeout_handler(sig,frame): raise ValueError("timeout!") signal.signal(signal.SIGALRM,timeout_handler) while True: chunk = fileo.read(bs) sock.sendall(chunk) (...) What is the best practise for a cross platform timeout handler? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From tim at akwebsoft.com Wed Nov 11 11:16:57 2015 From: tim at akwebsoft.com (Tim Johnson) Date: Wed, 11 Nov 2015 07:16:57 -0900 Subject: Using subprocess to capture a progress line In-Reply-To: References: <20151110224756.GA1944@mail.akwebsoft.com> Message-ID: <20151111161657.GE1944@mail.akwebsoft.com> * Chris Warrick [151111 00:55]: > On 10 November 2015 at 23:47, Tim Johnson wrote: > > Using python 2.7.6 on ubuntu 14.04 <..> > There is no \n character at the end ? which means that > p.stdout.readline() cannot return. In fact, if you printed repr() of > the line you read, you would get this: > > b'\r[download] 54.9% of 2.73MiB at 26.73KiB/s ETA 00:47\r[download] > 55.0% of 2.73MiB at 79.33KiB/s ETA 00:15\r?snip?\r[download] 100% of > 2.73MiB in 00:01\n' > > The download line is implemented using \r, which is the carriage > return character (return to the first character), and then by > overwriting characters that were already printed. > > The solution? There are numerous. I?ll help you by obscuring the worst one. > > (1) [recommended] figure out how to make youtube_dl work as a library, > read its main file to figure out the problem. Don?t mess with > subprocess. Was my first goal, had some problems, but I have solved them in part by finding the good documentation of the developers. I.E., the subprocess method _is_ going away and I will be using the youtube_dl module. > (2) [don?t do it] do you need to intercept the lines? If you don?t set > stderr= and stdout=, things will print just fine. Got to try that before using the module, just for edification. > (3) [DON?T DO IT] .ernq() punenpgre ol punenpgre naq znxr n zrff. > > PS. Thank you for setting a sensible Reply-To header on your messages. > Which is something the list should be doing. LOL! Glad to help :) Thanks for the reply and the further education. Cheers -- Tim http://www.akwebsoft.com, http://www.tj49.com From marko at pacujo.net Wed Nov 11 11:30:23 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 11 Nov 2015 18:30:23 +0200 Subject: cross platform alternative for signal.SIGALRM? References: Message-ID: <87si4cts68.fsf@elektro.pacujo.net> Ulli Horlacher : > What is the best practise for a cross platform timeout handler? Here's the simplest answer: https://docs.python.org/3/library/threading.html#threading.Timer (Also available in Python 2.) Marko From anas.belemlih at gmail.com Wed Nov 11 11:34:30 2015 From: anas.belemlih at gmail.com (Anas Belemlih) Date: Wed, 11 Nov 2015 08:34:30 -0800 (PST) Subject: new to python, help please !! Message-ID: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> i am a beginning programmer, i am trying to write a simple code to compare two character sets in 2 seperate files. ( 2 hash value files basically) idea is: open both files, measure the length of the loop on. if the length doesn't match, == files do not match if length matchs, loop while comparing each character from each file if they match. please tell me what i am doing wrong ? i am using python 2.7 ********************************** hash1= open ("file1.md5", "r") line1 =hash1.read() hash2 = open("file2.md5","r") line2= hash2.read() number1 = len(line1) number2 = len(line2) #************************** i=0 s1=line1[i] s2=line2[i] count = 0 if number1 != number2: print " hash table not the same size" else: while count < number1: if s1 == s2: print " character", line1[i]," matchs" i=i+1 count=count+1 else print "Hash values corrupt" From kwpolska at gmail.com Wed Nov 11 11:48:56 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Wed, 11 Nov 2015 17:48:56 +0100 Subject: Using subprocess to capture a progress line In-Reply-To: <20151111161657.GE1944@mail.akwebsoft.com> References: <20151110224756.GA1944@mail.akwebsoft.com> <20151111161657.GE1944@mail.akwebsoft.com> Message-ID: On 11 November 2015 at 17:16, Tim Johnson wrote: >> (2) [don?t do it] do you need to intercept the lines? If you don?t set >> stderr= and stdout=, things will print just fine. > Got to try that before using the module, just for edification. At which point your initial code sample will become: ########### p = subprocess.Popen(list(args)) ########### (is list(args) really necessary? Wouldn?t plain Popen(args) just work?) -- Chris Warrick PGP: 5EAAEA16 From gordon at panix.com Wed Nov 11 11:58:22 2015 From: gordon at panix.com (John Gordon) Date: Wed, 11 Nov 2015 16:58:22 +0000 (UTC) Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> Message-ID: In <93aef8e5-3d6f-41f4-a625-cd3c2007686e at googlegroups.com> Anas Belemlih writes: > i=0 > s1=line1[i] > s2=line2[i] > count = 0 > if number1 != number2: > print " hash table not the same size" > else: > while count < number1: > if s1 == s2: > print " character", line1[i]," matchs" > i=i+1 > count=count+1 > else > print "Hash values corrupt" It looks like you're expecting s1 and s2 to automatically update their values when i gets incremented, but it doesn't work like that. When you increment i, you also have to reassign s1 and s2. -- 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 framstag at rus.uni-stuttgart.de Wed Nov 11 12:06:46 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 11 Nov 2015 17:06:46 +0000 (UTC) Subject: cross platform alternative for signal.SIGALRM? References: <87si4cts68.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Ulli Horlacher : > > > What is the best practise for a cross platform timeout handler? > > Here's the simplest answer: > > https://docs.python.org/3/library/threading.html#threading.Timer > > (Also available in Python 2.) Hmmm... not so simple for me. My test code: from time import * import threading import sys def hello(): raise ValueError("hello!!!") t = threading.Timer(3.0,hello) t.start() try: print "start" sleep(5) print "end" except ValueError as e: print e.args[0] sys.exit(1) gives: start Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 759, in run self.function(*self.args, **self.kwargs) File "x.py", line 7, in hello def hello(): raise ValueError("hello!!!") ValueError: hello!!! end -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From python.list at tim.thechases.com Wed Nov 11 12:06:55 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 11 Nov 2015 11:06:55 -0600 Subject: new to python, help please !! In-Reply-To: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> Message-ID: <20151111110655.7293d3b7@bigbox.christie.dr> On 2015-11-11 08:34, Anas Belemlih wrote: > i am a beginning programmer, i am trying to write a simple code > to compare two character sets in 2 seperate files. ( 2 hash value > files basically) idea is: open both files, measure the length of > the loop on. > > if the length doesn't match, == files do not match > > if length matchs, loop while comparing each character from each > file if they match. please tell me what i am doing wrong ? i am > using python 2.7 > > ********************************** > hash1= open ("file1.md5", "r") > line1 =hash1.read() > hash2 = open("file2.md5","r") > line2= hash2.read() > > number1 = len(line1) > number2 = len(line2) > > #************************** > i=0 > s1=line1[i] > s2=line2[i] > count = 0 > > if number1 != number2: > print " hash table not the same size" > else: > while count < number1: > if s1 == s2: > print " character", line1[i]," matchs" > i=i+1 > count=count+1 > else > print "Hash values corrupt" Well, the immediate answer is that you don't update s1 or s2 inside your loop. Also, the indent on "count=count+1" is wrong. Finally, if the hashes don't match, you don't break out of your while loop. That said, the pythonesque way of writing this would likely look something much more like with open("file1.md5") as a, open("file2.md5") as b: for s1, s2 in zip(a, b): if s1 != s2: print("Files differ") You can compare the strings to get the actual offset if you want, or check the lengths if you really want a more verbatim translation of your code: with open("file1.md5") as a, open("file2.md5") as b: for s1, s2 in zip(a, b): if len(s1) != len(s2): print("not the same size") else: for i, (c1, c2) in enumerate(zip(s1, s2)): if c1 == c2: print(" character %s matches" % c1) else: print(" %r and %r differ at position %i" % (s1, s2, i)) -tkc From ben+python at benfinney.id.au Wed Nov 11 12:16:21 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Nov 2015 04:16:21 +1100 Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> Message-ID: <85pozge9sq.fsf@benfinney.id.au> Anas Belemlih writes: > i am a beginning programmer, i am trying to write a simple code to > compare two character sets in 2 seperate files. ( 2 hash value files > basically) Welcome, and congratulations on arriving at Python for your programming! As a beginning programmer, you will benefit from joining the ?tutor? forum , which is much better suited to collaborative teaching of newcomers. -- \ ?As scarce as truth is, the supply has always been in excess of | `\ the demand.? ?Josh Billings | _o__) | Ben Finney From torriem at gmail.com Wed Nov 11 12:31:06 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Nov 2015 10:31:06 -0700 Subject: Python.exe is not a valid Win32 application error message In-Reply-To: References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <56437B5A.6080802@gmail.com> On 11/11/2015 10:21 AM, Quivis wrote: > On Tue, 10 Nov 2015 00:34:23 +0000, M. Kamisato wrote: > >> I am running python on Windows XP SP3 and download version 3.5xx. I got >> the above error message and could not run the program. >> I have downloaded Python version 2.7xx and it runs fine. >> Is there any way I can get version 3.5xx to run on my computer? >> Mel KamisatoBuena Park, CA > > > Did you DL the 64-bit version...? In this case, it would not matter; Windows XP is simply too old to run Python 3.5, but the web page neglects to mention that, and the installer does not yet warn the user, though it will in the next minor version release. From cameron.houliston at hotmail.com Wed Nov 11 12:35:45 2015 From: cameron.houliston at hotmail.com (Cameron Houliston) Date: Wed, 11 Nov 2015 17:35:45 +0000 Subject: Hi Message-ID: Can I have a link to use python Sent from Mail for Windows 10 From marko at pacujo.net Wed Nov 11 13:03:12 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 11 Nov 2015 20:03:12 +0200 Subject: cross platform alternative for signal.SIGALRM? References: <87si4cts68.fsf@elektro.pacujo.net> Message-ID: <87oaf0tnvj.fsf@elektro.pacujo.net> Ulli Horlacher : > Hmmm... not so simple for me. My test code: > > from time import * > import threading > import sys > > def hello(): > raise ValueError("hello!!!") > > t = threading.Timer(3.0,hello) > t.start() > try: > print "start" > sleep(5) > print "end" > except ValueError as e: > print e.args[0] > sys.exit(1) Correct. The timer callback function (hello) would be called in a separate thread. An exception raised in one thread cannot be caught in the main thread. In general, there is no way for a thread to interrupt a sibling thread that is in a blocking function call. Marko From tim at akwebsoft.com Wed Nov 11 13:52:19 2015 From: tim at akwebsoft.com (Tim Johnson) Date: Wed, 11 Nov 2015 09:52:19 -0900 Subject: Using subprocess to capture a progress line In-Reply-To: References: <20151110224756.GA1944@mail.akwebsoft.com> <20151111161657.GE1944@mail.akwebsoft.com> Message-ID: <20151111185219.GF1944@mail.akwebsoft.com> * Chris Warrick [151111 07:54]: > On 11 November 2015 at 17:16, Tim Johnson wrote: > >> (2) [don?t do it] do you need to intercept the lines? If you don?t set > >> stderr= and stdout=, things will print just fine. > > Got to try that before using the module, just for edification. > > At which point your initial code sample will become: > ########### > p = subprocess.Popen(list(args)) > ########### > Yeah, 'list is redundant. Progress is now showing, but I forgot to say that I've lost the original intent, and that was to examine each line so that I could pull out the title. No matter. I'm on the way to make the youtube_dl module working. cheers -- Tim http://www.akwebsoft.com, http://www.tj49.com From kaifmahmood2000 at hotmail.co.uk Wed Nov 11 15:01:46 2015 From: kaifmahmood2000 at hotmail.co.uk (Kaif Mahmood) Date: Wed, 11 Nov 2015 20:01:46 +0000 Subject: =?utf-8?Q?Python_Trouble?= Message-ID: I downloaded the recent version of Python and after it downloaded I tried IDLE. But when I tried to load it, it didn?t load and just acted as if nothing happened. All of the other features work fine, it?s just IDLE not working. I tried different versions but I encounter the same problem. The only way I managed to load it was by right clicking on previous files and clicking edit with IDLE; IDLE loaded but when I clicked run, it just froze and closed. Please help. Sent from Windows Mail From auriocus at gmx.de Wed Nov 11 16:32:18 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 11 Nov 2015 22:32:18 +0100 Subject: using binary in python In-Reply-To: References: Message-ID: Am 10.11.15 um 22:29 schrieb kent nyberg: > On Mon, Nov 09, 2015 at 10:20:25PM -0800, Larry Hudson via Python-list wrote: >> Your questions are somewhat difficult to answer because you misunderstand >> binary. The key is that EVERYTHING in a computer is binary. There are NO >> EXCEPTIONS, it's all binary ALL the time. The difference comes about in how >> this binary data is displayed and manipulated. I want to emphasize, ALL the >> DATA is binary. >> > > Thanks alot for taking the time. > I get it now. I sort of, but not fully, misunderstood the conecpt of binary files. > The thing I was after; and the thing Im playing with now after a more succesfull time with google, > is writing more specific things to a file than just strings. > English is not my native language so please forgive me, but > I wanted to write specifc 16bit codes, and read them. And later play with bitwise operations on them. Sort of. > It might not make sense at all, but hey.. it doesnt have to I think I understand what you want. Look at the struct module: https://docs.python.org/2/library/struct.html You can write/read binary data from files with standard means. Using struct, you can interpret or format integer values into a specific binary format. That would allow to create a reader or writer for a given binary format in Python. Christian From framstag at rus.uni-stuttgart.de Wed Nov 11 17:42:28 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 11 Nov 2015 22:42:28 +0000 (UTC) Subject: cross platform alternative for signal.SIGALRM? References: <87si4cts68.fsf@elektro.pacujo.net> <87oaf0tnvj.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Correct. The timer callback function (hello) would be called in a > separate thread. An exception raised in one thread cannot be caught in > the main thread. In general, there is no way for a thread to interrupt a > sibling thread that is in a blocking function call. Then threading.Timer is not a solution for my problem. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From tjreedy at udel.edu Wed Nov 11 20:37:34 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2015 20:37:34 -0500 Subject: cross platform alternative for signal.SIGALRM? In-Reply-To: References: Message-ID: On 11/11/2015 11:16 AM, Ulli Horlacher wrote: > I am rewriting a Perl program into Python (2.7). I recommend using 3.4+ if you possibly can. > It must run on Linux and Windows. > With Linux I have no problems, but Windows... :-( > > The current show stopper is signal.SIGALRM which is not available on > Windows: > Perl for Windows has had SIGALRM support (or some kind of emulation). > > Ok, I have to redesign this part of my code: > > def timeout_handler(sig,frame): > raise ValueError("timeout!") > > signal.signal(signal.SIGALRM,timeout_handler) > > while True: > chunk = fileo.read(bs) > sock.sendall(chunk) > (...) > > What is the best practise for a cross platform timeout handler? The cross-platform 3.4 asyncio module has some functions with timeouts. (3.5 has new 'async' syntac which supposedly makes it easier to use. I have not looked at this yet.) For instance: coroutine asyncio.wait(futures, *, loop=None, timeout=None, return_when=ALL_COMPLETED) Wait for the Futures and coroutine objects given by the sequence futures to complete. Coroutines will be wrapped in Tasks. Returns two sets of Future: (done, pending). ... Usage: done, pending = yield from asyncio.wait(fs) I believe the backport on pypi.python.org, called tulip, works on 2.7. In the example above, the read/send would be a task. Wait on the task, and when it returns, cancel the task if in pending. -- Terry Jan Reedy From tundraBOGUS at tundraware.com Wed Nov 11 20:52:38 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Wed, 11 Nov 2015 19:52:38 -0600 Subject: More tkinter Madness Message-ID: <708dhc-3pf1.ln1@oceanview.tundraware.com> I am the author of twander (https://www.tundraware.com/Software/twander). This code has run flawlessly for years on FreeBSD, Linux, MacOS and Windows. Some months ago, I put it on a couple of VPS servers (FreeBSD and Linux) and BOOM, it doesn't run. I asked around here and got some suggestions and then did some homework. I see the error being thrown by using the trace module, but it's not terribly meaningful to me. Any ideas of what this means - again, I emphasize this is only happening on VPS hosts: --- modulename: Tkinter, funcname: _cnfmerge Tkinter.py(76): if type(cnfs) is DictionaryType: Tkinter.py(77): return cnfs Tkinter.py(1046): res = () Tkinter.py(1047): for k, v in cnf.items(): Tkinter.py(1048): if v is not None: Tkinter.py(1049): if k[-1] == '_': k = k[:-1] Tkinter.py(1050): if callable(v): Tkinter.py(1052): elif isinstance(v, (tuple, list)): Tkinter.py(1064): res = res + ('-'+k, v) Tkinter.py(1047): for k, v in cnf.items(): Tkinter.py(1048): if v is not None: Tkinter.py(1049): if k[-1] == '_': k = k[:-1] Tkinter.py(1050): if callable(v): Tkinter.py(1052): elif isinstance(v, (tuple, list)): Tkinter.py(1064): res = res + ('-'+k, v) Tkinter.py(1047): for k, v in cnf.items(): Tkinter.py(1048): if v is not None: Tkinter.py(1049): if k[-1] == '_': k = k[:-1] Tkinter.py(1050): if callable(v): Tkinter.py(1052): elif isinstance(v, (tuple, list)): Tkinter.py(1064): res = res + ('-'+k, v) Tkinter.py(1047): for k, v in cnf.items(): Tkinter.py(1065): return res Traceback (most recent call last): File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code exec code in run_globals File "/usr/lib64/python2.6/trace.py", line 823, in main() File "/usr/lib64/python2.6/trace.py", line 811, in main t.runctx(code, globs, globs) File "/usr/lib64/python2.6/trace.py", line 512, in runctx exec cmd in globals, locals File "/local/TundraWare/bin/twander.py", line 5464, in UI = twanderUI(UIroot) File "/local/TundraWare/bin/twander.py", line 2152, in __init__ self.CmdBtn = Menubutton(self.mBar, text=COMMANDMENU, underline=0, state=DISABLED) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 2710, in __init__ Widget.__init__(self, master, 'menubutton', cnf, kw) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1932, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError From no.email at nospam.invalid Wed Nov 11 21:12:42 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 11 Nov 2015 18:12:42 -0800 Subject: More tkinter Madness References: <708dhc-3pf1.ln1@oceanview.tundraware.com> Message-ID: <87oaf0q82t.fsf@nightsong.com> Tim Daneliuk writes: > Some months ago, I put it on a couple of VPS servers (FreeBSD > and Linux) and BOOM, it doesn't run. I asked around here and got some > suggestions and then did some homework. I'd expect a VPS server to have no display--is it an X client forward to your workstation? Are all the proper X libraries installed? Note that X port forwarding over the internet is generally unusable even if your internet connection is pretty fast. It's kind of ok over a LAN. From rosuav at gmail.com Wed Nov 11 21:25:56 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Nov 2015 13:25:56 +1100 Subject: More tkinter Madness In-Reply-To: <708dhc-3pf1.ln1@oceanview.tundraware.com> References: <708dhc-3pf1.ln1@oceanview.tundraware.com> Message-ID: On Thu, Nov 12, 2015 at 12:52 PM, Tim Daneliuk wrote: > I am the author of twander (https://www.tundraware.com/Software/twander). > This code has run flawlessly for years on FreeBSD, Linux, MacOS and > Windows. Some months ago, I put it on a couple of VPS servers (FreeBSD > and Linux) and BOOM, it doesn't run. I asked around here and got some > suggestions and then did some homework. > > Traceback (most recent call last): > File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main It's running here under Python 2.6. Sorry if this is a question you've already been asked, but were you successfully running under 2.6 elsewhere? Might be a versioning issue. ChrisA From steve+comp.lang.python at pearwood.info Wed Nov 11 21:58:35 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 12 Nov 2015 13:58:35 +1100 Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> Message-ID: <5644005e$0$2932$c3e8da3$76491128@news.astraweb.com> On Thursday 12 November 2015 04:48, Quivis wrote: > On Wed, 11 Nov 2015 08:34:30 -0800, Anas Belemlih wrote: > >> md5 > > If those are md5 values stored inside files, wouldn't it be easier to > just hash them? > > import hashlib > > m1 = hashlib.sha224(open('f1').read()).hexdigest() > m2 = hashlib.sha224(open('f2').read()).hexdigest() I presume that the purpose of the exercise is to learn basic Python skills like looping. Also, using sha224 when all you want is a simple "different"/"equal" is horribly inefficient. Sha224 needs to read the entire file, every single byte, *and* perform a bunch of expensive cryptographic operations. Consider reading two five GB files, the first starting with byte \x30 and the second starting with byte \x60. The two bytes are different, so we know the files differ, but sha224 still needs to do a massive amount of work. -- Steve From rxjwg98 at gmail.com Wed Nov 11 22:04:36 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 11 Nov 2015 19:04:36 -0800 (PST) Subject: How to get 'od' run? Message-ID: <24ed2ddb-aaea-455e-bf45-10e1cd8e8376@googlegroups.com> Hi, I am learning python. I see a previous post has such code: >>> data = '"bin??ridataa"\n'.encode('utf-8') >>> f = open('roska.txt', 'wb') >>> f.write(data) 17 >>> f.close() The .encode methods produced a bytestring, which Python likes to display as ASCII characters where it can and in hexadecimal where it cannot: >>> data b'"bin\xc3\xa4\xc3\xa4ridataa"\n' An "octal dump" in characters (where ASCII, otherwise apparently octal) and the corresponding hexadecimal shows that it is, indeed, these bytes that ended up in the file: $ od -t cx1 roska.txt When I run the above line with python 2.7, it does not recognize 'od'. Is it from a package? Or some internal function? Thanks, From torriem at gmail.com Wed Nov 11 22:21:08 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Nov 2015 20:21:08 -0700 Subject: How to get 'od' run? In-Reply-To: <24ed2ddb-aaea-455e-bf45-10e1cd8e8376@googlegroups.com> References: <24ed2ddb-aaea-455e-bf45-10e1cd8e8376@googlegroups.com> Message-ID: <564405A4.2060300@gmail.com> On 11/11/2015 08:04 PM, fl wrote: > Hi, > > I am learning python. I see a previous post has such code: > > > > > > >>> data = '"bin??ridataa"\n'.encode('utf-8') > >>> f = open('roska.txt', 'wb') > >>> f.write(data) > 17 > >>> f.close() > > The .encode methods produced a bytestring, which Python likes to display > as ASCII characters where it can and in hexadecimal where it cannot: > > >>> data > b'"bin\xc3\xa4\xc3\xa4ridataa"\n' > > An "octal dump" in characters (where ASCII, otherwise apparently octal) > and the corresponding hexadecimal shows that it is, indeed, these bytes > that ended up in the file: > > $ od -t cx1 roska.txt ^^^ This is most likely a bash prompt. Therefore "od" is a program on your computer. Nothing to do with Python at all. To get Python to display \x## hex codes for non-ascii characters in a byte stream, you can print out the repr() of the byte string. For example: print (repr(my_unicode_string.encode('utf-8'))) From torriem at gmail.com Wed Nov 11 22:34:49 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Nov 2015 20:34:49 -0700 Subject: How to get 'od' run? In-Reply-To: <564405A4.2060300@gmail.com> References: <24ed2ddb-aaea-455e-bf45-10e1cd8e8376@googlegroups.com> <564405A4.2060300@gmail.com> Message-ID: <564408D9.5040303@gmail.com> On 11/11/2015 08:21 PM, Michael Torrie wrote: > On 11/11/2015 08:04 PM, fl wrote: >> Hi, >> >> I am learning python. I see a previous post has such code: >> >> >> >> >> >> >>> data = '"bin??ridataa"\n'.encode('utf-8') >> >>> f = open('roska.txt', 'wb') >> >>> f.write(data) >> 17 >> >>> f.close() >> >> The .encode methods produced a bytestring, which Python likes to display >> as ASCII characters where it can and in hexadecimal where it cannot: >> >> >>> data >> b'"bin\xc3\xa4\xc3\xa4ridataa"\n' >> >> An "octal dump" in characters (where ASCII, otherwise apparently octal) >> and the corresponding hexadecimal shows that it is, indeed, these bytes >> that ended up in the file: >> >> $ od -t cx1 roska.txt > ^^^ > This is most likely a bash prompt. Therefore "od" is a program on your > computer. Nothing to do with Python at all. > > To get Python to display \x## hex codes for non-ascii characters in a > byte stream, you can print out the repr() of the byte string. For example: > > print (repr(my_unicode_string.encode('utf-8'))) Also there are numerous recipes for doing standard hex dumps out there. For example, http://code.activestate.com/recipes/142812-hex-dumper/ From hayesstw at telkomsa.net Wed Nov 11 23:43:44 2015 From: hayesstw at telkomsa.net (Steve Hayes) Date: Thu, 12 Nov 2015 06:43:44 +0200 Subject: Python.exe is not a valid Win32 application error message References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> Message-ID: <53684bd0ecp0krft87qlerlkobh8kjp575@4ax.com> On Thu, 12 Nov 2015 00:13:29 +1100, Chris Angelico wrote: >On Tue, Nov 10, 2015 at 11:34 AM, M. Kamisato via Python-list > wrote: >> I am running python on Windows XP SP3 and download version 3.5xx. I got the above error message and could not run the program. >> I have downloaded Python version 2.7xx and it runs fine. >> Is there any way I can get version 3.5xx to run on my computer? >> Mel KamisatoBuena Park, CA > >You can't get 3.5 to run on XP, no; your options are: > >1) Install Python 3.4, which does support XP >2) Upgrade to a newer version of Windows (anything from Vista onward >will run 3.5; to save having to do this in future, jump straight to 7 >or 10) >3) Make the jump to Linux or FreeBSD or some other OS. That is useful to know. I get messages (from Glary Utilities) that some of my programs (including Python) need to be updated, but when I've downloaded and updated them, the update hasn't worked. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From hayesstw at telkomsa.net Wed Nov 11 23:44:38 2015 From: hayesstw at telkomsa.net (Steve Hayes) Date: Thu, 12 Nov 2015 06:44:38 +0200 Subject: Python.exe is not a valid Win32 application error message References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Wed, 11 Nov 2015 08:39:21 -0500, Dennis Lee Bieber wrote: >On Tue, 10 Nov 2015 00:34:23 +0000 (UTC), "M. Kamisato via Python-list" > declaimed the following: > >>I am running python on Windows XP SP3 and download version 3.5xx. ?I got the above error message and could not run the program. >>I have downloaded Python version 2.7xx and it runs fine. >>Is there any way I can get version 3.5xx to run on my computer? >>Mel KamisatoBuena Park, CA > > Install Windows Vista, 7, 8.1, or 10. > > Windows XP is not a supported OS for Python 3.5+ Or revert to an earlier version of Python that does work. -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From cs at zip.com.au Thu Nov 12 00:20:46 2015 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 12 Nov 2015 16:20:46 +1100 Subject: cross platform alternative for signal.SIGALRM? In-Reply-To: References: Message-ID: <20151112052046.GA35372@cskk.homeip.net> On 11Nov2015 16:16, Ulli Horlacher wrote: >I am rewriting a Perl program into Python (2.7). >It must run on Linux and Windows. >With Linux I have no problems, but Windows... :-( > >The current show stopper is signal.SIGALRM which is not available on >Windows: > > File "fexit.py", line 674, in formdata_post > signal.signal(signal.SIGALRM,timeout_handler) > AttributeError: 'module' object has no attribute 'SIGALRM' > > https://docs.python.org/2/library/signal.html > > signal.alarm(time) (...) Availability: Unix. > >Perl for Windows has had SIGALRM support (or some kind of emulation). > >Ok, I have to redesign this part of my code: > > def timeout_handler(sig,frame): > raise ValueError("timeout!") > > signal.signal(signal.SIGALRM,timeout_handler) > > while True: > chunk = fileo.read(bs) > sock.sendall(chunk) > (...) > >What is the best practise for a cross platform timeout handler? I suggest you look at the socket.settimeout function. Avoid SIGALRM altogether. Then (untested): import socket ... socket.settimeout(timeout_in_seconds) ... while True: ... chunk = fileo.read(bs) try: sock.sendall(chunk) except socket.timeout as e: ... complain about timeout, reciting "e" in the message ... Cheers, Cameron Simpson I think you're confusing "recognizing" and "understanding" with "caring". The net is cruel, sometimes, but always fair. - Rick Gordon From marko at pacujo.net Thu Nov 12 01:14:48 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 12 Nov 2015 08:14:48 +0200 Subject: cross platform alternative for signal.SIGALRM? References: Message-ID: <877flnu4kn.fsf@elektro.pacujo.net> Terry Reedy : > The cross-platform 3.4 asyncio module has some functions with > timeouts. Even that doesn't forcefully interrupt an obnoxious blocking function call like time.sleep(10000) The original question claimed signal.alarm() would do the trick in Linux. However, even that cannot be relied on as "man alarm" states: sleep(3) may be implemented using SIGALRM; mixing calls to alarm() and sleep(3) is a bad idea. I'm thinking the only portable way is to run a watchdog process with subprocess or multiprocessing. Marko From marko at pacujo.net Thu Nov 12 01:21:14 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 12 Nov 2015 08:21:14 +0200 Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <5644005e$0$2932$c3e8da3$76491128@news.astraweb.com> Message-ID: <8737wbu49x.fsf@elektro.pacujo.net> Steven D'Aprano : > On Thursday 12 November 2015 04:48, Quivis wrote: > >> On Wed, 11 Nov 2015 08:34:30 -0800, Anas Belemlih wrote: >> >>> md5 >> >> If those are md5 values stored inside files, wouldn't it be easier to >> just hash them? >> >> import hashlib >> >> m1 = hashlib.sha224(open('f1').read()).hexdigest() >> m2 = hashlib.sha224(open('f2').read()).hexdigest() > > I presume that the purpose of the exercise is to learn basic Python > skills like looping. And if you really wanted to compare two files that are known to contain MD5 checksums, the simplest way is: with open('f1.md5') as f1, open('f2.md5') as f2: if f1.read() == f2.read(): ... else: ... Marko From auriocus at gmx.de Thu Nov 12 01:43:57 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 12 Nov 2015 07:43:57 +0100 Subject: cross platform alternative for signal.SIGALRM? In-Reply-To: <877flnu4kn.fsf@elektro.pacujo.net> References: <877flnu4kn.fsf@elektro.pacujo.net> Message-ID: Am 12.11.15 um 07:14 schrieb Marko Rauhamaa: > Terry Reedy : > >> The cross-platform 3.4 asyncio module has some functions with >> timeouts. > > Even that doesn't forcefully interrupt an obnoxious blocking function > call like > > time.sleep(10000) A blocking call - granted. But what happens in a blocking loop, i.e. for i in range(10000000000000000000000000): pass ? My understanding of async is that it creates an event loop. In which case the loop has no chance to run within a block of code that computes anything, is that correct? Or does it hook into the interpreter and is able to interrupt the program between bytecodes? > I'm thinking the only portable way is to run a watchdog process with > subprocess or multiprocessing. What about a thread which calls exit() after the timeout? Does that forcefully kill the whole process? Christian From framstag at rus.uni-stuttgart.de Thu Nov 12 01:58:33 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 12 Nov 2015 06:58:33 +0000 (UTC) Subject: cross platform alternative for signal.SIGALRM? References: Message-ID: Terry Reedy wrote: > On 11/11/2015 11:16 AM, Ulli Horlacher wrote: > > I am rewriting a Perl program into Python (2.7). > > I recommend using 3.4+ if you possibly can. It is not possible. The main target platform offers only python 2.7 -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From framstag at rus.uni-stuttgart.de Thu Nov 12 02:22:18 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 12 Nov 2015 07:22:18 +0000 (UTC) Subject: cross platform alternative for signal.SIGALRM? References: <877flnu4kn.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > I'm thinking the only portable way is to run a watchdog process with > subprocess or multiprocessing. How can a subprocess interrupt a function in another process? For example: waiting for user input with a timeout. raw_input("Hit ENTER to continue or wait 10 s") -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From rosuav at gmail.com Thu Nov 12 02:37:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Nov 2015 18:37:02 +1100 Subject: cross platform alternative for signal.SIGALRM? In-Reply-To: References: <877flnu4kn.fsf@elektro.pacujo.net> Message-ID: On Thu, Nov 12, 2015 at 5:43 PM, Christian Gollwitzer wrote: > My understanding of async is that it creates an event loop. In which case > the loop has no chance to run within a block of code that computes anything, > is that correct? This is correct. At its simplest, asynchronous code is an abstraction over the select() call, which basically says "Hey system, tell me when (a) I can read from here, (b) I can write to here, or (c) I've been waiting this long". The most common use is sockets; a web server has its main listening socket (it becomes readable when someone connects), any clients that haven't finished sending their requests yet (they become readable when more data arrives), any clients that you're still sending to (they become writeable when there's room in their output buffers), and maybe some sort of periodic checks ("every hour, do maintenance"). Whenever you finish a bit of processing (reading from a client, sending to a client, whatever), you return to the "event loop", which in this case would be select(). An async library makes all this look a lot cleaner in your code, but ultimately, it's not preemptive. You still have to make sure the processing doesn't take too long. ChrisA From 18518281186 at 126.com Thu Nov 12 03:05:09 2015 From: 18518281186 at 126.com (Xiang Zhang) Date: Thu, 12 Nov 2015 16:05:09 +0800 Subject: What is the meaning of Py_INCREF a static PyTypeObject? Message-ID: <56444835.5020803@126.com> Recently I am learning Python C API. When I read the tutorial , defining new types, I feel confused. After PyType_Ready(&noddy_NoddyType) comes Py_INCREF(&noddy_NoddyType). Actually noddy_NoddyType is a static struct so I don't understand why I need to Py_INCREF it. Since it's Py_INCREFed, does it mean sometimes we also need to Py_DECREF it? But then it seems that type_dealloc will be invoked and it will fail assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); I haven't read the typeobject.c source code totally so I think I must have missed something. But I am quite confused. Hope someone can give me some hints. Thanks in advance. From marko at pacujo.net Thu Nov 12 03:15:48 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 12 Nov 2015 10:15:48 +0200 Subject: cross platform alternative for signal.SIGALRM? References: <877flnu4kn.fsf@elektro.pacujo.net> Message-ID: <87vb97skej.fsf@elektro.pacujo.net> Ulli Horlacher : > Marko Rauhamaa wrote: > >> I'm thinking the only portable way is to run a watchdog process with >> subprocess or multiprocessing. > > How can a subprocess interrupt a function in another process? > > For example: waiting for user input with a timeout. > > raw_input("Hit ENTER to continue or wait 10 s") By sending the parent a signal with os.kill(). Now, signal handling in Python is brittle so you must be careful: There is no way to ?block? signals temporarily from critical sections Marko From auriocus at gmx.de Thu Nov 12 03:46:10 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 12 Nov 2015 09:46:10 +0100 Subject: Swig + Numpy.i with a const int16_t pointer In-Reply-To: <05ae95fa-68f0-43ca-8b36-04a827c5d878@googlegroups.com> References: <05ae95fa-68f0-43ca-8b36-04a827c5d878@googlegroups.com> Message-ID: Am 11.11.15 um 02:09 schrieb shriphanip at gmail.com: > I am trying to wrap the following function with SWIG so I can call it from Python. The signature is: > > ``` > int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame, size_t frame_length); > ``` This is thing is an array of 16 bit unsigned integers for input. The closest object in Python is a numpy array. There is a numpy.i available for Python, I'm not sure if it handles this case correctly. If you are unlucky, you need to write your own typemap. Christian From auriocus at gmx.de Thu Nov 12 04:16:35 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 12 Nov 2015 10:16:35 +0100 Subject: Swig + Numpy.i with a const int16_t pointer In-Reply-To: References: <05ae95fa-68f0-43ca-8b36-04a827c5d878@googlegroups.com> Message-ID: Am 12.11.15 um 09:46 schrieb Christian Gollwitzer: > Am 11.11.15 um 02:09 schrieb shriphanip at gmail.com: >> I am trying to wrap the following function with SWIG so I can call it >> from Python. The signature is: >> >> ``` >> int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* >> audio_frame, size_t frame_length); >> ``` > > This is thing is an array of 16 bit unsigned integers for input. The > closest object in Python is a numpy array. There is a numpy.i available > for Python, I'm not sure if it handles this case correctly. If you are > unlucky, you need to write your own typemap. http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html It seems that you can create your own typemap easily using the macros provided by numpy.i; something like %numpy_typemaps(int16_t, NPY_UINT16, int) should be sufficient. Christian From auriocus at gmx.de Thu Nov 12 04:17:38 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 12 Nov 2015 10:17:38 +0100 Subject: Swig + Numpy.i with a const int16_t pointer In-Reply-To: References: <05ae95fa-68f0-43ca-8b36-04a827c5d878@googlegroups.com> Message-ID: Am 12.11.15 um 10:16 schrieb Christian Gollwitzer: > Am 12.11.15 um 09:46 schrieb Christian Gollwitzer: >> Am 11.11.15 um 02:09 schrieb shriphanip at gmail.com: >>> I am trying to wrap the following function with SWIG so I can call it >>> from Python. The signature is: >>> >>> ``` >>> int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* >>> audio_frame, size_t frame_length); >>> ``` >> >> This is thing is an array of 16 bit unsigned integers for input. The >> closest object in Python is a numpy array. There is a numpy.i available >> for Python, I'm not sure if it handles this case correctly. If you are >> unlucky, you need to write your own typemap. > > http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html > > It seems that you can create your own typemap easily using the macros > provided by numpy.i; something like > > %numpy_typemaps(int16_t, NPY_UINT16, int) > > should be sufficient. That should be %numpy_typemaps(int16_t, NPY_INT16, int) of course. From breamoreboy at yahoo.co.uk Thu Nov 12 04:32:22 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 12 Nov 2015 09:32:22 +0000 Subject: Hi In-Reply-To: References: Message-ID: On 11/11/2015 17:35, Cameron Houliston wrote: > Can I have a link to use python > > Sent from Mail for Windows 10 > I usually start with www.google.co.uk. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Thu Nov 12 04:50:25 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 12 Nov 2015 10:50:25 +0100 Subject: Python.exe is not a valid Win32 application error message In-Reply-To: <56435E8B.10103@gmail.com> References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> <56435E8B.10103@gmail.com> Message-ID: <201511120950.tAC9oP4c026463@fido.openend.se> In a message of Wed, 11 Nov 2015 08:28:11 -0700, Michael Torrie writes: >The Python website is looking very professional and polished these days. > But we still don't have a simple message on the download page telling >people Windows XP is no longer supported. Given the number of people >posting lately (several each week), I would think even with the limited >time and resources of the python.org webmaster a little warning message >would be in order. Even when the installer is fixed, it would still be >nice to have basic OS requirements listed before the download is ever >clicked. It's not webmaster, who is receiving as many of these requests as python-list, but the pydotorg team. There is a request in to get this changed, it just hasn?t happened yet. Laura From tjreedy at udel.edu Thu Nov 12 05:10:18 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2015 05:10:18 -0500 Subject: Python Trouble In-Reply-To: References: Message-ID: On 11/11/2015 3:01 PM, Kaif Mahmood wrote: > I downloaded the recent version of Python and after it downloaded I tried IDLE. But when I tried to load it, it didn?t load and just acted as if nothing happened. All of the other features work fine, it?s just IDLE not working. I tried different versions but I encounter the same problem. The only way I managed to load it was by right clicking on previous files and clicking edit with IDLE; IDLE loaded but when I clicked run, it just froze and closed. Please help. At a command line enter 'python -m idlelib' or 'python3 ...' on *nix. You should see some error message. -- Terry Jan Reedy From lac at openend.se Thu Nov 12 05:14:56 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 12 Nov 2015 11:14:56 +0100 Subject: =?utf-8?Q?Python_Trouble?= In-Reply-To: References: Message-ID: <201511121014.tACAEuxb029629@fido.openend.se> In a message of Wed, 11 Nov 2015 20:01:46 +0000, Kaif Mahmood writes: >I downloaded the recent version of Python and after it downloaded I tried IDLE. But when I tried to load it, it didn?t load and just acted as if nothing happened. All of the other features work fine, it?s just IDLE not working. I tried different versions but I encounter the same problem. The only way I managed to load it was by right clicking on previous files and clicking edit with IDLE; IDLE loaded but when I clicked run, it just froze and closed. Please help. At the command line, run python -m idlelib.idle or python3 -m idlelib.idle and then reply here with that information. Also what version of Python you are trying to run on what OS. (i.e 3.5 on Windows Vista) Laura From tjreedy at udel.edu Thu Nov 12 05:15:52 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2015 05:15:52 -0500 Subject: cross platform alternative for signal.SIGALRM? In-Reply-To: References: <877flnu4kn.fsf@elektro.pacujo.net> Message-ID: On 11/12/2015 2:37 AM, Chris Angelico wrote: > On Thu, Nov 12, 2015 at 5:43 PM, Christian Gollwitzer wrote: >> My understanding of async is that it creates an event loop. In which case >> the loop has no chance to run within a block of code that computes anything, >> is that correct? > > This is correct. At its simplest, asynchronous code is an abstraction > over the select() call, True on Unix-derived systems, where 'select' includes the various derivatives. It is also an abstraction over the Windows completion calls, which are quite different. The latter is why one must generally use a different event loop on Windows. The point is that asyncio provides an *abstraction* such that after choosing the event loop, the rest of one's code is os-agnostic. -- Terry Jan Reedy From jongiddy at gmail.com Thu Nov 12 06:03:51 2015 From: jongiddy at gmail.com (jongiddy) Date: Thu, 12 Nov 2015 03:03:51 -0800 (PST) Subject: Classic OOP in Python In-Reply-To: <01adfef5-7edf-447c-9397-853c4fd65e53@googlegroups.com> References: <23b2fae3-91d5-486b-9898-78b34bee486f@googlegroups.com> <16dc8c92-50e3-4fc8-ae25-cbc5b13e8971@googlegroups.com> <01adfef5-7edf-447c-9397-853c4fd65e53@googlegroups.com> Message-ID: <6b0d08b3-5599-4952-85d2-a43c72ee71b2@googlegroups.com> On Thursday, 18 June 2015 12:21:29 UTC+1, Jason P. wrote: > > I'm aware of duck typing. The point in using interfaces is to be explicit about the boundaries of a system. > > Quite a red "Growing Object-Oriented Software, Guided by Tests", by the way. In fact interfaces are key components in the style of building software they propose, in good company with TDD. > > Thx! Late to the party, but I have added a package `jute` to PyPI which provides interface checking closer to the model used in Java (and other compiled OO languages). See https://github.com/jongiddy/jute From rosuav at gmail.com Thu Nov 12 06:38:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Nov 2015 22:38:49 +1100 Subject: cross platform alternative for signal.SIGALRM? In-Reply-To: References: <877flnu4kn.fsf@elektro.pacujo.net> Message-ID: On Thu, Nov 12, 2015 at 9:15 PM, Terry Reedy wrote: > On 11/12/2015 2:37 AM, Chris Angelico wrote: >> >> On Thu, Nov 12, 2015 at 5:43 PM, Christian Gollwitzer >> wrote: >>> >>> My understanding of async is that it creates an event loop. In which case >>> the loop has no chance to run within a block of code that computes >>> anything, >>> is that correct? >> >> >> This is correct. At its simplest, asynchronous code is an abstraction >> over the select() call, > > > True on Unix-derived systems, where 'select' includes the various > derivatives. It is also an abstraction over the Windows completion calls, > which are quite different. The latter is why one must generally use a > different event loop on Windows. The point is that asyncio provides an > *abstraction* such that after choosing the event loop, the rest of one's > code is os-agnostic. I've never done that kind of thing on Windows, so I'm not sure how it works; it's still broadly based on I/O availability, right? And ultimately, it comes down to "go back to the event loop so others can run". ChrisA From python.list at tim.thechases.com Thu Nov 12 06:48:12 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 12 Nov 2015 05:48:12 -0600 Subject: new to python, help please !! In-Reply-To: <8737wbu49x.fsf@elektro.pacujo.net> References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <5644005e$0$2932$c3e8da3$76491128@news.astraweb.com> <8737wbu49x.fsf@elektro.pacujo.net> Message-ID: <20151112054812.3603d4de@bigbox.christie.dr> On 2015-11-12 08:21, Marko Rauhamaa wrote: > And if you really wanted to compare two files that are known to > contain MD5 checksums, the simplest way is: > > with open('f1.md5') as f1, open('f2.md5') as f2: > if f1.read() == f2.read(): > ... > else: > ... Though that suffers if the files are large. Might try CHUNK_SIZE = 4 * 1024 # read 4k chunks # chunk_offset = 0 with open('f1.md5') as f1, open('f2.md5') as f2: while True: c1 = f1.read(CHUNK_SIZE) c2 = f2.read(CHUNK_SIZE) if c1 or c2: # chunk_offset += 1 if c1 != c2: not_the_same(c1, c2) # not_the_same(chunk_offset * CHUNK_SIZE, c1, c2) break else: # EOF the_same() break which should perform better if the files are huge -tkc From rxjwg98 at gmail.com Thu Nov 12 08:57:53 2015 From: rxjwg98 at gmail.com (fl) Date: Thu, 12 Nov 2015 05:57:53 -0800 (PST) Subject: What is wrong in this example code? Message-ID: <1b204966-46c6-4890-a5a5-8addd20343a1@googlegroups.com> Hi, I run a code snippet from link: http://www.python-course.eu/inheritance_example.php It is found that there is an error in this loop: for i in xrange(10000): x.tick() print(x) SyntaxError: invalid syntax I have modified it to: for i in x range(10000): x.tick() print(x) SyntaxError: invalid syntax it still has an error. What could be wrong? Thanks, .... class Clock(object): def __init__(self,hours=0, minutes=0, seconds=0): self.__hours = hours self.__minutes = minutes self.__seconds = seconds def set(self,hours, minutes, seconds=0): self.__hours = hours self.__minutes = minutes self.__seconds = seconds def tick(self): """ Time will be advanced by one second """ if self.__seconds == 59: self.__seconds = 0 if (self.__minutes == 59): self.__minutes = 0 self.__hours = 0 if self.__hours==23 else self.__hours+1 else: self.__minutes += 1; else: self.__seconds += 1; def display(self): print("%d:%d:%d" % (self.__hours, self.__minutes, self.__seconds)) def __str__(self): return "%2d:%2d:%2d" % (self.__hours, self.__minutes, self.__seconds) x = Clock() print(x) for i in xrange(10000): x.tick() print(x) From tjreedy at udel.edu Thu Nov 12 09:01:40 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2015 09:01:40 -0500 Subject: cross platform alternative for signal.SIGALRM? In-Reply-To: References: <877flnu4kn.fsf@elektro.pacujo.net> Message-ID: On 11/12/2015 6:38 AM, Chris Angelico wrote: > On Thu, Nov 12, 2015 at 9:15 PM, Terry Reedy wrote: >> On 11/12/2015 2:37 AM, Chris Angelico wrote: >>> >>> On Thu, Nov 12, 2015 at 5:43 PM, Christian Gollwitzer >>> wrote: >>>> >>>> My understanding of async is that it creates an event loop. In which case >>>> the loop has no chance to run within a block of code that computes >>>> anything, >>>> is that correct? >>> >>> >>> This is correct. At its simplest, asynchronous code is an abstraction >>> over the select() call, >> >> >> True on Unix-derived systems, where 'select' includes the various >> derivatives. It is also an abstraction over the Windows completion calls, >> which are quite different. The latter is why one must generally use a >> different event loop on Windows. The point is that asyncio provides an >> *abstraction* such that after choosing the event loop, the rest of one's >> code is os-agnostic. > > I've never done that kind of thing on Windows, so I'm not sure how it > works; it's still broadly based on I/O availability, right? That is the general abstraction. But there was something in the design discussion about a difference between 'edge' versus 'level' triggering that made it a challenge to get something more detailed that covers both implementations. > ultimately, it comes down to "go back to the event loop so others can > run". -- Terry Jan Reedy From rxjwg98 at gmail.com Thu Nov 12 09:07:45 2015 From: rxjwg98 at gmail.com (fl) Date: Thu, 12 Nov 2015 06:07:45 -0800 (PST) Subject: What is wrong in this example code? In-Reply-To: <1b204966-46c6-4890-a5a5-8addd20343a1@googlegroups.com> References: <1b204966-46c6-4890-a5a5-8addd20343a1@googlegroups.com> Message-ID: <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> On Thursday, November 12, 2015 at 8:58:33 AM UTC-5, fl wrote: > Hi, > > I run a code snippet from link: > http://www.python-course.eu/inheritance_example.php > > It is found that there is an error in this loop: > > for i in xrange(10000): > x.tick() > print(x) > SyntaxError: invalid syntax > > > I have modified it to: > for i in x range(10000): > x.tick() > print(x) > SyntaxError: invalid syntax > > it still has an error. What could be wrong? > > Thanks, > > > .... > class Clock(object): > > def __init__(self,hours=0, minutes=0, seconds=0): > self.__hours = hours > self.__minutes = minutes > self.__seconds = seconds > > def set(self,hours, minutes, seconds=0): > self.__hours = hours > self.__minutes = minutes > self.__seconds = seconds > > def tick(self): > """ Time will be advanced by one second """ > if self.__seconds == 59: > self.__seconds = 0 > if (self.__minutes == 59): > self.__minutes = 0 > self.__hours = 0 if self.__hours==23 else self.__hours+1 > else: > self.__minutes += 1; > else: > self.__seconds += 1; > > def display(self): > print("%d:%d:%d" % (self.__hours, self.__minutes, self.__seconds)) > > def __str__(self): > return "%2d:%2d:%2d" % (self.__hours, self.__minutes, self.__seconds) > > x = Clock() > print(x) > for i in xrange(10000): > x.tick() > print(x) Solved it by this: print(x) for i in range(1, 10000): x.tick() print(x) Thanks, From paul.hermeneutic at gmail.com Thu Nov 12 09:27:29 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Thu, 12 Nov 2015 07:27:29 -0700 Subject: new to python, help please !! In-Reply-To: <20151112054812.3603d4de@bigbox.christie.dr> References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <5644005e$0$2932$c3e8da3$76491128@news.astraweb.com> <8737wbu49x.fsf@elektro.pacujo.net> <20151112054812.3603d4de@bigbox.christie.dr> Message-ID: Would some form of subprocess.Popen() on cmp or fc /b be easier? On Nov 12, 2015 7:13 AM, "Tim Chase" wrote: > On 2015-11-12 08:21, Marko Rauhamaa wrote: > > And if you really wanted to compare two files that are known to > > contain MD5 checksums, the simplest way is: > > > > with open('f1.md5') as f1, open('f2.md5') as f2: > > if f1.read() == f2.read(): > > ... > > else: > > ... > > Though that suffers if the files are large. Might try > > CHUNK_SIZE = 4 * 1024 # read 4k chunks > # chunk_offset = 0 > with open('f1.md5') as f1, open('f2.md5') as f2: > while True: > c1 = f1.read(CHUNK_SIZE) > c2 = f2.read(CHUNK_SIZE) > if c1 or c2: > # chunk_offset += 1 > if c1 != c2: > not_the_same(c1, c2) > # not_the_same(chunk_offset * CHUNK_SIZE, c1, c2) > break > else: # EOF > the_same() > break > > which should perform better if the files are huge > > -tkc > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu Nov 12 09:56:40 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Nov 2015 15:56:40 +0100 Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <20151111110655.7293d3b7@bigbox.christie.dr> Message-ID: Tim Chase wrote: > with open("file1.md5") as a, open("file2.md5") as b: > for s1, s2 in zip(a, b): > if s1 != s2: > print("Files differ") Note that this will not detect extra lines in one of the files. I recommend that you use itertools.zip_longest (izip_longest in Python 2) instead of the built-in zip(). From python.list at tim.thechases.com Thu Nov 12 10:00:58 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 12 Nov 2015 09:00:58 -0600 Subject: new to python, help please !! In-Reply-To: References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <20151111110655.7293d3b7@bigbox.christie.dr> Message-ID: <20151112090058.0834a645@bigbox.christie.dr> On 2015-11-12 15:56, Peter Otten wrote: > Tim Chase wrote: > > > with open("file1.md5") as a, open("file2.md5") as b: > > for s1, s2 in zip(a, b): > > if s1 != s2: > > print("Files differ") > > Note that this will not detect extra lines in one of the files. > I recommend that you use itertools.zip_longest (izip_longest in > Python 2) instead of the built-in zip(). Yeah, I noticed that after pushing but then posted a later version that just read chunks of the file which should catch that file-size difference. Or, as in that other message, prefix it with an fstat() check to compare file-sizes so that you don't even have to open the files if the sizes differ. -tkc From gokoproject at gmail.com Thu Nov 12 10:10:06 2015 From: gokoproject at gmail.com (John Wong) Date: Thu, 12 Nov 2015 10:10:06 -0500 Subject: What is wrong in this example code? In-Reply-To: <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> References: <1b204966-46c6-4890-a5a5-8addd20343a1@googlegroups.com> <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> Message-ID: If you are using Python 3 you will need to change xrange to range, but the error shouldn't be invalid syntax. I remember it should just name name not found/not defined. So if you are not using Python 3, range and xrange do still in Python 2 and they have different use case. So i am really curious how you fixed it. It sounds more like some issue with space rather, but still glad you solved it somehow. On Thu, Nov 12, 2015 at 9:07 AM, fl wrote: > On Thursday, November 12, 2015 at 8:58:33 AM UTC-5, fl wrote: > > Hi, > > > > I run a code snippet from link: > > http://www.python-course.eu/inheritance_example.php > > > > It is found that there is an error in this loop: > > > > for i in xrange(10000): > > x.tick() > > print(x) > > SyntaxError: invalid syntax > > > > > > I have modified it to: > > for i in x range(10000): > > x.tick() > > print(x) > > SyntaxError: invalid syntax > > > > it still has an error. What could be wrong? > > > > Thanks, > > > > > > .... > > class Clock(object): > > > > def __init__(self,hours=0, minutes=0, seconds=0): > > self.__hours = hours > > self.__minutes = minutes > > self.__seconds = seconds > > > > def set(self,hours, minutes, seconds=0): > > self.__hours = hours > > self.__minutes = minutes > > self.__seconds = seconds > > > > def tick(self): > > """ Time will be advanced by one second """ > > if self.__seconds == 59: > > self.__seconds = 0 > > if (self.__minutes == 59): > > self.__minutes = 0 > > self.__hours = 0 if self.__hours==23 else self.__hours+1 > > else: > > self.__minutes += 1; > > else: > > self.__seconds += 1; > > > > def display(self): > > print("%d:%d:%d" % (self.__hours, self.__minutes, > self.__seconds)) > > > > def __str__(self): > > return "%2d:%2d:%2d" % (self.__hours, self.__minutes, > self.__seconds) > > > > x = Clock() > > print(x) > > for i in xrange(10000): > > x.tick() > > print(x) > > Solved it by this: > print(x) > for i in range(1, 10000): > x.tick() > print(x) > > Thanks, > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu Nov 12 10:41:33 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Nov 2015 16:41:33 +0100 Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <20151111110655.7293d3b7@bigbox.christie.dr> <20151112090058.0834a645@bigbox.christie.dr> Message-ID: Tim Chase wrote: > On 2015-11-12 15:56, Peter Otten wrote: >> Tim Chase wrote: >> >> > with open("file1.md5") as a, open("file2.md5") as b: >> > for s1, s2 in zip(a, b): >> > if s1 != s2: >> > print("Files differ") >> >> Note that this will not detect extra lines in one of the files. >> I recommend that you use itertools.zip_longest (izip_longest in >> Python 2) instead of the built-in zip(). > > Yeah, I noticed that after pushing but then posted a later > version that just read chunks of the file which should catch that > file-size difference. Or, as in that other message, prefix it with > an fstat() check to compare file-sizes so that you don't even have to > open the files if the sizes differ. > > -tkc >>> os.path.getsize("file1.md5") 10 >>> os.path.getsize("file2.md5") 10 >>> with open("file1.md5") as a, open("file2.md5") as b: ... for s, t in zip(a, b): ... if s != t: print("different") ... >>> from itertools import zip_longest >>> with open("file1.md5") as a, open("file2.md5") as b: ... for s, t in zip_longest(a, b): ... if s != t: print("different") ... different I admit I cheated and used Python 3 ;) From johnzzhao at gmail.com Thu Nov 12 10:47:55 2015 From: johnzzhao at gmail.com (John Zhao) Date: Thu, 12 Nov 2015 07:47:55 -0800 (PST) Subject: can ConfigParser deal with repeating section header? Message-ID: <95dc81c4-31eb-4f45-8b9c-20a03b2f0caa@googlegroups.com> I have a configuration file with repeating sections, for example, [INSTANCE] Name=a [INSTANCE] Name=b I hope I can use ConfigParser to read the file and store the configuration settings in arrays. Is that possible? Thanks a lot. John From mjoerg.phone at gmail.com Thu Nov 12 10:57:51 2015 From: mjoerg.phone at gmail.com (PythonDude) Date: Thu, 12 Nov 2015 07:57:51 -0800 (PST) Subject: don't understand matrix-multiplication should be reversed in python? Message-ID: Hi all, I've come around a webpage with python-tutorial/description for obtaining something and I'll solve this: R = p^T w where R is a vector and p^T is the transpose of another vector. ... p is a Nx1 column vector, so p^T turns into a 1xN row vector which can be multiplied with the Nx1 weight (column) vector w to give a scalar result. This is equivalent to the dot product used in the code. Keep in mind that Python has a reversed definition of rows and columns and the accurate NumPy version of the previous equation would be R = w * p.T ... (source: http://blog.quantopian.com/markowitz-portfolio-optimization-2/ ) I don't understand this: "Keep in mind that Python has a reversed definition of rows and columns and the accurate NumPy version of the previous equation would be R = w * p.T" Not true for numpy, is it? This page: http://mathesaurus.sourceforge.net/matlab-numpy.html says it python and matlab looks quite similar... Anyone could please explain or elaborate on exactly this (quote): "Keep in mind that Python has a reversed definition of rows and columns"??? That I don't understand - thank you for any hints/guidance/explanations/ideas/suggestions etc! From python.list at tim.thechases.com Thu Nov 12 10:59:54 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 12 Nov 2015 09:59:54 -0600 Subject: can ConfigParser deal with repeating section header? In-Reply-To: <95dc81c4-31eb-4f45-8b9c-20a03b2f0caa@googlegroups.com> References: <95dc81c4-31eb-4f45-8b9c-20a03b2f0caa@googlegroups.com> Message-ID: <20151112095954.4438eb5b@bigbox.christie.dr> On 2015-11-12 07:47, John Zhao wrote: > I have a configuration file with repeating sections, for example, > > [INSTANCE] > Name=a > > [INSTANCE] > Name=b > > I hope I can use ConfigParser to read the file and store the > configuration settings in arrays. > > Is that possible? Not with the standard library's ConfigParser: >>> from cStringIO import StringIO >>> from ConfigParser import ConfigParser >>> ini = StringIO("""[INSTANCE] ... Name=a ... ... [INSTANCE] ... Name=b ... """) >>> cp = ConfigParser() >>> cp.readfp(ini) >>> cp.sections() # note: only one section ['INSTANCE'] >>> cp.get("INSTANCE", "Name") # note: only the last value 'b' It also fails to catch multiple values with the same key: [INSTANCE] Name=a Name=b doesn't give you cp.get("INSTANCE", "Name") == ["a", "b"] -tkc From ian.g.kelly at gmail.com Thu Nov 12 11:34:33 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 12 Nov 2015 09:34:33 -0700 Subject: don't understand matrix-multiplication should be reversed in python? In-Reply-To: References: Message-ID: On Thu, Nov 12, 2015 at 8:57 AM, PythonDude wrote: > Hi all, > > I've come around a webpage with python-tutorial/description for obtaining something and I'll solve this: > > R = p^T w > > where R is a vector and p^T is the transpose of another vector. > > ... > p is a Nx1 column vector, so p^T turns into a 1xN row vector which can be multiplied with the > Nx1 weight (column) vector w to give a scalar result. This is equivalent to the dot > product used in the code. Keep in mind that Python has a reversed definition of > rows and columns and the accurate NumPy version of the previous equation would > be R = w * p.T > ... > > (source: http://blog.quantopian.com/markowitz-portfolio-optimization-2/ ) > > I don't understand this: "Keep in mind that Python has a reversed definition of > rows and columns and the accurate NumPy version of the previous equation would > be R = w * p.T" > > Not true for numpy, is it? This page: http://mathesaurus.sourceforge.net/matlab-numpy.html says it python and matlab looks quite similar... > > Anyone could please explain or elaborate on exactly this (quote): "Keep in mind that Python has a reversed definition of rows and columns"??? > > That I don't understand - thank you for any hints/guidance/explanations/ideas/suggestions etc! py> import numpy py> p = numpy.reshape(range(5), (5,1)) py> p array([[0], [1], [2], [3], [4]]) py> p.T array([[0, 1, 2, 3, 4]]) py> p.dot(p.T) array([[ 0, 0, 0, 0, 0], [ 0, 1, 2, 3, 4], [ 0, 2, 4, 6, 8], [ 0, 3, 6, 9, 12], [ 0, 4, 8, 12, 16]]) py> p.T.dot(p) array([[30]]) py> m = numpy.asmatrix(p) py> m matrix([[0], [1], [2], [3], [4]]) py> m.T matrix([[0, 1, 2, 3, 4]]) py> m * m.T matrix([[ 0, 0, 0, 0, 0], [ 0, 1, 2, 3, 4], [ 0, 2, 4, 6, 8], [ 0, 3, 6, 9, 12], [ 0, 4, 8, 12, 16]]) py> m.T * m matrix([[30]]) Yeah, I don't know what that person is talking about either. It looks correct to me. From torriem at gmail.com Thu Nov 12 11:47:56 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 12 Nov 2015 09:47:56 -0700 Subject: Python.exe is not a valid Win32 application error message In-Reply-To: <53684bd0ecp0krft87qlerlkobh8kjp575@4ax.com> References: <1913826683.1878058.1447115663273.JavaMail.yahoo.ref@mail.yahoo.com> <1913826683.1878058.1447115663273.JavaMail.yahoo@mail.yahoo.com> <53684bd0ecp0krft87qlerlkobh8kjp575@4ax.com> Message-ID: <5644C2BC.8010809@gmail.com> On 11/11/2015 09:43 PM, Steve Hayes wrote: > That is useful to know. > > I get messages (from Glary Utilities) that some of my programs > (including Python) need to be updated, but when I've downloaded and > updated them, the update hasn't worked. Such utilities seem to cause more trouble than they're worth. From rxjwg98 at gmail.com Thu Nov 12 12:20:02 2015 From: rxjwg98 at gmail.com (fl) Date: Thu, 12 Nov 2015 09:20:02 -0800 (PST) Subject: Why does 'as' not recognized? Message-ID: <8ddbc8fd-ebdb-4cd2-8e3b-b0e1f5142e76@googlegroups.com> Hi, When I try the following, python does not know 'as'. Why doesn't it? Thanks, >>> cats = ['Tom', 'Snappy', 'Kitty', 'Jessie', 'Chester'] >>> >>> type(cats) >>> cats[2] 'Kitty' >>> as=cats[2] SyntaxError: invalid syntax >>> as=cats SyntaxError: invalid syntax >>> as SyntaxError: invalid syntax From gordon at panix.com Thu Nov 12 12:24:32 2015 From: gordon at panix.com (John Gordon) Date: Thu, 12 Nov 2015 17:24:32 +0000 (UTC) Subject: Why does 'as' not recognized? References: <8ddbc8fd-ebdb-4cd2-8e3b-b0e1f5142e76@googlegroups.com> Message-ID: In <8ddbc8fd-ebdb-4cd2-8e3b-b0e1f5142e76 at googlegroups.com> fl writes: > >>> cats = ['Tom', 'Snappy', 'Kitty', 'Jessie', 'Chester'] > >>> > >>> type(cats) > > >>> cats[2] > 'Kitty' > >>> as=cats[2] > SyntaxError: invalid syntax > >>> as=cats > SyntaxError: invalid syntax > >>> as > SyntaxError: invalid syntax 'as' is a python language keyword, and cannot be used for variable names. -- 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 jason.swails at gmail.com Thu Nov 12 13:52:10 2015 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 12 Nov 2015 13:52:10 -0500 Subject: What is the meaning of Py_INCREF a static PyTypeObject? In-Reply-To: <56444835.5020803@126.com> References: <56444835.5020803@126.com> Message-ID: On Thu, Nov 12, 2015 at 3:05 AM, Xiang Zhang <18518281186 at 126.com> wrote: > Recently I am learning Python C API. > > When I read the tutorial < > https://docs.python.org/3/extending/newtypes.html#the-basics>, defining > new types, I feel confused. After PyType_Ready(&noddy_NoddyType) comes > Py_INCREF(&noddy_NoddyType). Actually noddy_NoddyType is a static struct so > I don't understand why I need to Py_INCREF it. Since it's Py_INCREFed, does > it mean sometimes we also need to Py_DECREF it? But then it seems that > type_dealloc will be invoked and it will fail assert(type->tp_flags & > Py_TPFLAGS_HEAPTYPE); > ?It is a module attribute, so when the module is imported it has to have a single reference (the reference *in* the module). If you don't INCREF it, then it will have a refcount of 0, and immediately be ready for garbage collection. So if you try to use the type from the module, you could get a segfault because it's trying to use an object (type definition) that was already destroyed. Note that you don't *always* have to INCREF objects after you create them in C. Some macros and function do that for you. And in some cases, all you want or need is a borrowed reference. In those cases, Py_INCREF is unnecessary. The DECREF will be done when it's normally done in Python. If you do something like import noddy del noddy.NoddyType ?All that's really doing is removing NoddyType from the noddy namespace and Py_DECREFing it. Alternatively, doing import noddy noddy.NoddyType = 10 # rebind the name Then the original object NoddyType was pointing to will be DECREFed and NoddyType will point to an object taking the value of 10. HTH, Jason From amorawski at magna-power.com Thu Nov 12 14:38:14 2015 From: amorawski at magna-power.com (amorawski at magna-power.com) Date: Thu, 12 Nov 2015 11:38:14 -0800 (PST) Subject: can ConfigParser deal with repeating section header? In-Reply-To: <95dc81c4-31eb-4f45-8b9c-20a03b2f0caa@googlegroups.com> References: <95dc81c4-31eb-4f45-8b9c-20a03b2f0caa@googlegroups.com> Message-ID: On Thursday, November 12, 2015 at 10:48:11 AM UTC-5, John Zhao wrote: > I have a configuration file with repeating sections, for example, > > [INSTANCE] > Name=a > > [INSTANCE] > Name=b > > > I hope I can use ConfigParser to read the file and store the configuration settings in arrays. > > Is that possible? > > Thanks a lot. > > John Here is one of possible solutions: http://stackoverflow.com/questions/9876059/parsing-configure-file-with-same-section-name-in-python From denismfmcmahon at gmail.com Thu Nov 12 14:49:54 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 12 Nov 2015 19:49:54 -0000 (UTC) Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <5644005e$0$2932$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, 12 Nov 2015 17:55:33 +0000, Quivis wrote: > On Thu, 12 Nov 2015 13:58:35 +1100, Steven D'Aprano wrote: > >> horribly inefficient > > Assuming it was md5 values, who cares? Those are small. A file of 160 million md5 hashes as 32 character hex strings is a huge file. Your method calculates the hash over both files to test whether the contents are different. If the input files are both lists of 160 million md5 hashes, you're calculating the hash of two 5 gigabyte files. In your method the size of the lines of data is irrelevant to the execution time, the execution time varies with the size of the datafiles. -- Denis McMahon, denismfmcmahon at gmail.com From PointedEars at web.de Thu Nov 12 15:40:12 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 12 Nov 2015 21:40:12 +0100 Subject: Question about math.pi is mutable References: <1590467.kktH0DaBsW@PointedEars.de> <85pozlidwu.fsf@benfinney.id.au> Message-ID: <10882952.phYABH7ckh@PointedEars.de> Chris Angelico wrote: > [?] Ben Finney [?] wrote: >> I recommend you ignore that request; ?Bartc? is fine as a name here, >> IMO. > > Given that LARTC means Linux Advanced Routing and Traffic Control, I'm > guessing Bartc is all about *BSD networking? :) I thought LART were the Luser Attitude Readjustment Tool ;-) And on GABELNs [1] it is considered polite to post using your real name. Lack of politeness towards the people whom would otherwise be willing to help you may cause you to be ignored by them instead. You have been warned. BTW, it?s attribution *line*, _not_ attribution novel. [1] {Group Area Board Echo List Newsgroup}s -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From torriem at gmail.com Thu Nov 12 15:40:22 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 12 Nov 2015 13:40:22 -0700 Subject: Hi In-Reply-To: References: Message-ID: <5644F936.8040402@gmail.com> On 11/12/2015 02:32 AM, Mark Lawrence wrote: > On 11/11/2015 17:35, Cameron Houliston wrote: >> Can I have a link to use python >> >> Sent from Mail for Windows 10 >> > > I usually start with www.google.co.uk. I think Windows 10 blocks Google. :) And of course the official home of Python is https://www.python.org/ From denismfmcmahon at gmail.com Thu Nov 12 16:24:17 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 12 Nov 2015 21:24:17 -0000 (UTC) Subject: new to python, help please !! References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> Message-ID: On Wed, 11 Nov 2015 08:34:30 -0800, Anas Belemlih wrote: > i am a beginning programmer, i am trying to write a simple code to > compare two character sets in 2 seperate files. ( 2 hash value files > basically) Why? If you simply wish to compare two files, most operating systems provide executable tools at the OS level which are more efficient than anything you will write in a scripting language. Lesson 1 of computing. Use the right tool for the job. Writing a new program is not always the right tool. -- Denis McMahon, denismfmcmahon at gmail.com From rxjwg98 at gmail.com Thu Nov 12 16:34:58 2015 From: rxjwg98 at gmail.com (fl) Date: Thu, 12 Nov 2015 13:34:58 -0800 (PST) Subject: Is it useful for re.M in this example? Message-ID: Hi, I follow a web site on learning Python re. I have read the function description of re.m, as below. re.M Makes $ match the end of a line (not just the end of the string) and makes ^ match the start of any line (not just the start of the string). But I don't see the reason to put re.M in the example project: #!/usr/bin/python import re line = "Cats are smarter than dogs"; matchObj = re.match( r'dogs', line, re.M|re.I) if matchObj: print "match --> matchObj.group() : ", matchObj.group() else: print "No match!!" The tutorial (http://www.tutorialspoint.com/python/python_reg_expressions.htm) is for a beginner as I. Is there something I don't see in the example? Thanks, From robert.kern at gmail.com Thu Nov 12 16:56:51 2015 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 12 Nov 2015 21:56:51 +0000 Subject: don't understand matrix-multiplication should be reversed in python? In-Reply-To: References: Message-ID: On 2015-11-12 15:57, PythonDude wrote: > Hi all, > > I've come around a webpage with python-tutorial/description for obtaining something and I'll solve this: > > R = p^T w > > where R is a vector and p^T is the transpose of another vector. > > ... > p is a Nx1 column vector, so p^T turns into a 1xN row vector which can be multiplied with the > Nx1 weight (column) vector w to give a scalar result. This is equivalent to the dot > product used in the code. Keep in mind that Python has a reversed definition of > rows and columns and the accurate NumPy version of the previous equation would > be R = w * p.T > ... > > (source: http://blog.quantopian.com/markowitz-portfolio-optimization-2/ ) > > I don't understand this: "Keep in mind that Python has a reversed definition of > rows and columns and the accurate NumPy version of the previous equation would > be R = w * p.T" > > Not true for numpy, is it? This page: http://mathesaurus.sourceforge.net/matlab-numpy.html says it python and matlab looks quite similar... > > Anyone could please explain or elaborate on exactly this (quote): "Keep in mind that Python has a reversed definition of rows and columns"??? He's wrong, simply put. There is no "reversed definition of rows and columns". He simply instantiated the two vectors as row-vectors instead of column-vectors, which he could have easily done, so he had to flip the matrix expression. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From gordon at panix.com Thu Nov 12 17:00:32 2015 From: gordon at panix.com (John Gordon) Date: Thu, 12 Nov 2015 22:00:32 +0000 (UTC) Subject: Is it useful for re.M in this example? References: Message-ID: In fl writes: > re.M Makes $ match the end of a line (not just the end of the string) and > makes ^ match the start of any line (not just the start of the string). > But I don't see the reason to put re.M in the example project: That's because your sample string does not contain newline characters. If it did, you would see the effect of re.M. -- 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 steve at pearwood.info Thu Nov 12 17:04:54 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 13 Nov 2015 09:04:54 +1100 Subject: Question about math.pi is mutable References: <1590467.kktH0DaBsW@PointedEars.de> <85pozlidwu.fsf@benfinney.id.au> <10882952.phYABH7ckh@PointedEars.de> Message-ID: <56450d07$0$1584$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote: > And on GABELNs [1] it is considered polite to post using your real name. Falsehoods programmers believe about names: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ > You have been warned. And you should consider the irony, and hypocrisy, of somebody who signs his posts "PointedEars" bitching about supposed "real names". How do you propose to tell the difference between "real" names and "fake" names? If BartC signed his posts "Engelbert Humperdinck", "Cher", "Thomas Lahn" or "Bartholomew Roberts" how would you decide whether it was "real" or "fake"? Petty bigotry over "real" names is no better than any other sort of bigotry. -- Steven From bc at freeuk.com Thu Nov 12 17:19:59 2015 From: bc at freeuk.com (BartC) Date: Thu, 12 Nov 2015 22:19:59 +0000 Subject: Question about math.pi is mutable In-Reply-To: <10882952.phYABH7ckh@PointedEars.de> References: <1590467.kktH0DaBsW@PointedEars.de> <85pozlidwu.fsf@benfinney.id.au> <10882952.phYABH7ckh@PointedEars.de> Message-ID: On 12/11/2015 20:40, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> [?] Ben Finney [?] wrote: >>> I recommend you ignore that request; ?Bartc? is fine as a name here, >>> IMO. >> >> Given that LARTC means Linux Advanced Routing and Traffic Control, I'm >> guessing Bartc is all about *BSD networking? :) > > I thought LART were the Luser Attitude Readjustment Tool ;-) > > And on GABELNs [1] it is considered polite to post using your real name. > Lack of politeness towards the people whom would otherwise be willing to > help you may cause you to be ignored by them instead. You have been warned. I'm reading this 'list' on usenet. No-one else in many thousands of posts has ever complained before about my user-name. But I guess you haven't been on that many forums. Few people use their full names or anything that looks like a real name. Partly, so they don't have someone who violently disagrees with them causing problems (like discovering their address and coming round). Mostly people use names that are wacky, funny, or just meaningless. (FWIW, my real first name is Bart and C is the initial of my last name. Very dull I know.) -- bart c From rosuav at gmail.com Thu Nov 12 17:52:16 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Nov 2015 09:52:16 +1100 Subject: Question about math.pi is mutable In-Reply-To: References: <1590467.kktH0DaBsW@PointedEars.de> <85pozlidwu.fsf@benfinney.id.au> <10882952.phYABH7ckh@PointedEars.de> Message-ID: On Fri, Nov 13, 2015 at 9:19 AM, BartC wrote: > (FWIW, my real first name is Bart and C is the initial of my last name. Very > dull I know.) That's a common way of signing emails. I sign most of mine "ChrisA", which (as you'll see from my headers) is constructed the same way. So did the late Dave Angel (DaveA). Although I suppose I'm going to get in trouble with PointedEars for not using my *full* name, but abbreviating it to just "Chris". ChrisA From orgnut at yahoo.com Thu Nov 12 18:59:33 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 12 Nov 2015 15:59:33 -0800 Subject: What is wrong in this example code? In-Reply-To: <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> References: <1b204966-46c6-4890-a5a5-8addd20343a1@googlegroups.com> <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> Message-ID: On 11/12/2015 06:07 AM, fl wrote: > On Thursday, November 12, 2015 at 8:58:33 AM UTC-5, fl wrote: >> Hi, >> >> def tick(self): >> """ Time will be advanced by one second """ >> if self.__seconds == 59: >> self.__seconds = 0 >> if (self.__minutes == 59): >> self.__minutes = 0 >> self.__hours = 0 if self.__hours==23 else self.__hours+1 >> else: >> self.__minutes += 1; >> else: >> self.__seconds += 1; Nothing to do with your original question, just a trivial suggestion which you are free to ignore. You can shorten this tick() method by using the divmod() function. It does a division and returns both the quotient AND the remainder. IOW, given divmod(x, y) it returns the tuple (x/y, x%y). It is a very useful function. Try this: def tick(self): xtra, self._seconds = divmod(self._seconds + 1, 60) xtra, self._minutes = divmod(self._minutes + xtra, 60) self._hours += xtra Explanation: (to shorten this, I'm leaving off the leading "self._" from the actual code.) The first divmod() sets xtra = (seconds+1) / 60, which is the 'overflow' if any, from the division by 60, and seconds is the updated seconds limited to 0-59 (the result of (seconds+1) % 60). The second divmod() does the same thing to update minutes (if xtra != 0) and xtra is set to the 'overflow' from that division, which is then added to hours. More confusing perhaps, but definitely shorter. As I said above, use it if you want or ignore it if it's too confusing. -=- Larry -=- From nhilterbrand at gmail.com Thu Nov 12 19:24:23 2015 From: nhilterbrand at gmail.com (Nathan Hilterbrand) Date: Thu, 12 Nov 2015 19:24:23 -0500 Subject: What is wrong in this example code? In-Reply-To: References: <1b204966-46c6-4890-a5a5-8addd20343a1@googlegroups.com> <383401eb-f8be-4f7a-bd63-3520eedc069e@googlegroups.com> Message-ID: On Thu, Nov 12, 2015 at 6:59 PM, Larry Hudson via Python-list < python-list at python.org> wrote: Nothing to do with your original question, just a trivial suggestion which > you are free to ignore. You can shorten this tick() method by using the > divmod() function. It does a division and returns both the quotient AND > the remainder. IOW, given divmod(x, y) it returns the tuple (x/y, x%y). > It is a very useful function. Try this: > > def tick(self): > xtra, self._seconds = divmod(self._seconds + 1, 60) > xtra, self._minutes = divmod(self._minutes + xtra, 60) > self._hours += xtra > > Explanation: (to shorten this, I'm leaving off the leading "self._" from > the actual code.) > The first divmod() sets xtra = (seconds+1) / 60, which is the 'overflow' > if any, from the division by 60, and seconds is the updated seconds limited > to 0-59 (the result of (seconds+1) % 60). The second divmod() does the > same thing to update minutes (if xtra != 0) and xtra is set to the > 'overflow' from that division, which is then added to hours. > > More confusing perhaps, but definitely shorter. > As I said above, use it if you want or ignore it if it's too confusing. > > -=- Larry -=- > > -- > https://mail.python.org/mailman/listinfo/python-list > Beat me to the punch. I was about to suggest something similar, but I thought that since one using this class would probably be "tick()-ing" more than "str()-ing", It might also be better to store the value in seconds, and convert to HH:MM:SS upon stringification; again using divmod: class Clock(object): def __init__(self,hours=0,minutes=0,seconds=0): self.set(hours,minutes,seconds) def tick(self): self.__secs+=1 def set(self,hours, minutes, seconds): self.__secs = seconds + (minutes*60) + (hours*60*60) def __str__(self): rest, seconds = divmod(self.__secs, 60) hours, minutes = divmod(rest, 60) return "%02d:%02d:%02d" % (hours, minutes, seconds) def display(self): print(str(self)) if __name__ == "__main__": x = Clock() print("Default construction, no parameters, Before ticks: {}".format(x)) for i in range(10000): x.tick() print("After ticks: {}".format(x)) x = Clock(hours=2, minutes=20, seconds=5) print("\nConstructor with hours=2, minutes=20, seconds=5: {}".format(x)) print("Test of display() method: ",end=' ') x.display() This is my first post here, and I am a Python n00b (coming from that four-letter word language "p***"), so if I broke some top/bottom posting or formatting rules, I apologize, and would appreciate any posting pointers Nathan H. From tundraBOGUS at tundraware.com Thu Nov 12 19:25:35 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Thu, 12 Nov 2015 18:25:35 -0600 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> Message-ID: On 11/11/2015 08:25 PM, Chris Angelico wrote: > On Thu, Nov 12, 2015 at 12:52 PM, Tim Daneliuk > wrote: >> I am the author of twander (https://www.tundraware.com/Software/twander). >> This code has run flawlessly for years on FreeBSD, Linux, MacOS and >> Windows. Some months ago, I put it on a couple of VPS servers (FreeBSD >> and Linux) and BOOM, it doesn't run. I asked around here and got some >> suggestions and then did some homework. >> >> Traceback (most recent call last): >> File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main > > It's running here under Python 2.6. Sorry if this is a question you've > already been asked, but were you successfully running under 2.6 > elsewhere? Might be a versioning issue. > > ChrisA > It always ran OK on every previous version of Python from about 2.4 forward on VMs, physicals, *nix, OSX, Windows, etc. From tundraBOGUS at tundraware.com Thu Nov 12 19:26:42 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Thu, 12 Nov 2015 18:26:42 -0600 Subject: More tkinter Madness In-Reply-To: <87oaf0q82t.fsf@nightsong.com> References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <87oaf0q82t.fsf@nightsong.com> Message-ID: <2bnfhc-epd2.ln1@oceanview.tundraware.com> On 11/11/2015 08:12 PM, Paul Rubin wrote: > Tim Daneliuk writes: >> Some months ago, I put it on a couple of VPS servers (FreeBSD >> and Linux) and BOOM, it doesn't run. I asked around here and got some >> suggestions and then did some homework. > > I'd expect a VPS server to have no display--is it an X client forward to > your workstation? Are all the proper X libraries installed? Note that > X port forwarding over the internet is generally unusable even if your > internet connection is pretty fast. It's kind of ok over a LAN. > twander is a very, very ligthweight file browser with minimal GUI load. It's always worked well even with X forwarded over an ssh session over the open internet. I will further investigate the X libs matter. From abhishek.mallela at gmail.com Thu Nov 12 20:54:28 2015 From: abhishek.mallela at gmail.com (Abhishek) Date: Thu, 12 Nov 2015 17:54:28 -0800 (PST) Subject: Matplotlib error: Value Error: x and y must have same first dimension Message-ID: <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> I am trying to run some Python code for the last few hours. How can I achieve the effect of "dot divide" from Matlab, in the following code? I am having trouble working with list comprehension and numpy arrays and getting the following error: Traceback (most recent call last): File "Thurs.py", line 128, in plt.plot(np.array(range(1,N/2+2)), Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50)) ValueError: x and y must have same first dimension Code: import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from scipy.integrate import odeint N = 2 K00 = np.logspace(3,5,101,10) len1 = len(K00) Qvec = np.logspace(-2,2,2,10) S10vec = np.logspace(2,6,2,10) len2 = len(Qvec) y0 = [0]*(3*N/2+3) Kplot = np.zeros((len1,len2)) Pplot = np.zeros((len1,len2)) S = [np.zeros((len1,len2)) for kkkk in range(N/2+1)] KS = [np.zeros((len1,len2)) for kkkk in range(N/2)] PS = [np.zeros((len1,len2)) for kkkk in range(N/2)] Splot = [np.zeros((len1,len2)) for kkkk in range(N/2+1)] KSplot = [np.zeros((len1,len2)) for kkkk in range(N/2)] PSplot = [np.zeros((len1,len2)) for kkkk in range(N/2)] for val in range(0,len2): for series in range(0,len1): K0 = K00[series] Q = Qvec[val] S10 = S10vec[val] r1 = 0.0001 r2 = 0.001 a = 0.001 d = 0.001 k = 0.999 P0 = 1 tfvec = [1e7, 1e10] tf = tfvec[val] time = np.linspace(0,tf,1001) def f(y,t): for alpha in range(0,(N/2+1)): S[alpha] = y[alpha] for beta in range((N/2)+1,N+1): KS[beta-N/2-1] = y[beta] for gamma in range(N+1,3*N/2+1): PS[gamma-N-1] = y[gamma] K = y[3*N/2+1] P = y[3*N/2+2] ydot = np.zeros((3*N/2+3,1)) B = range((N/2)+1,N+1) G = range(N+1,3*N/2+1) runsumPS = 0 runsum1 = 0 runsumKS = 0 runsum2 = 0 for m in range(0,N/2): runsumPS = runsumPS + PS[m] runsum1 = runsum1 + S[m+1] runsumKS = runsumKS + KS[m] runsum2 = runsum2 + S[m] ydot[B[m]] = a*K*S[m]-(d+k+r1)*KS[m] for i in range(0,N/2-1): ydot[G[i]] = a*P*S[i+1]-(d+k+r1)*PS[i] for p in range(1,N/2): ydot[p] = -S[p]*(r1+a*K+a*P)+k*KS[p-1]+d*(PS[p-1]+KS[p]) ydot[0] = Q-(r1+a*K)*S[0]+d*KS[0]+k*runsumPS ydot[N/2] = k*KS[N/2-1]-(r2+a*P)*S[N/2]+d*PS[N/2-1] ydot[G[N/2-1]] = a*P*S[N/2]-(d+k+r2)*PS[N/2-1] ydot[3*N/2+1] = (d+k+r1)*runsumKS-a*K*runsum2 ydot[3*N/2+2] = (d+k+r1)*(runsumPS-PS[N/2-1])- \ a*P*runsum1+(d+k+r2)*PS[N/2-1] ydot_new = [] for j in range(0,3*N/2+3): ydot_new.extend(ydot[j]) return ydot_new y0[0] = S10 for i in range(1,3*N/2+1): y0[i] = 0 y0[3*N/2+1] = K0 y0[3*N/2+2] = P0 soln = odeint(f,y0,time, mxstep = 5000) for alpha in range(0,(N/2+1)): S[alpha] = soln[:,alpha] for beta in range((N/2)+1,N+1): KS[beta-N/2-1] = soln[:,beta] for gamma in range(N+1,3*N/2+1): PS[gamma-N-1] = soln[:,gamma] for alpha in range(0,(N/2+1)): Splot[alpha][series,val] = soln[len(time)-1,alpha] for beta in range((N/2)+1,N+1): KSplot[beta-N/2-1][series,val] = soln[len(time)-1,beta] for gamma in range(N+1,3*N/2+1): PSplot[gamma-N-1][series,val] = soln[len(time)-1,gamma] u1 = 0 u2 = 0 u3 = 0 for alpha in range(0,(N/2+1)): u1 = u1 + Splot[alpha] for beta in range((N/2)+1,N+1): u2 = u2 + KSplot[beta-N/2-1] for gamma in range(N+1,3*N/2+1): u3 = u3 + PSplot[gamma-N-1] K = soln[:,3*N/2+1] P = soln[:,3*N/2+2] Kplot[series] = soln[len1-1,3*N/2+1] Pplot[series] = soln[len1-1,3*N/2+2] utot = u1+u2+u3 plt.figure(val) cmap = mpl.cm.autumn for iii in range(0,100,50): for alpha in range(0,(N/2+1)): plt.plot(np.array(range(1,N/2+2)), Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50)) plt.xlabel('i') plt.ylabel(r'$\frac{S_i}{S_{tot}}$ (nM)') plt.title('N = 20: Behavior at [S](0) = 10^' + str(log10(Qvec[val]) + 4) + '(nM)', fontsize=20) plt.show() At the very least, can I extract the values that I need just for the plot? From 18518281186 at 126.com Thu Nov 12 22:08:27 2015 From: 18518281186 at 126.com (Xiang Zhang) Date: Fri, 13 Nov 2015 11:08:27 +0800 Subject: What is the meaning of Py_INCREF a static PyTypeObject? In-Reply-To: References: <56444835.5020803@126.com> Message-ID: <5645542B.9070602@126.com> Thanks for your reply jason. Your reply does give me hints and then I read more code and find maybe you are wrong in some points. I think the meaning of Py_INCREF a static type object is to prevent it from being deallocated when it is Py_DECREFed somehow later. Just as you said, it may be somehow deallocated when using. NoddyType is a static struct so I don't think it lives on Python's heap and deallocating it is a wrong action. Just as I mentioned, type_dealloc seems to only deallocated HEAPTYPE. And by the way, when NoddyType is created, it has a reference count 1 with PyVarObject_HEAD_INIT. So if I don't Py_INCREF it, when it is somehow Py_DECREDed later, it will reach reference count 0 and fail the assert in type_dealloc. If it is Py_INCREFed, just like the module holds a reference to it, it will at least have a reference count 1 and never reach 0. On 11/13/2015 02:52 AM, Jason Swails wrote: > > > On Thu, Nov 12, 2015 at 3:05 AM, Xiang Zhang <18518281186 at 126.com > > wrote: > > Recently I am learning Python C API. > > When I read the tutorial > , > defining new types, I feel confused. After > PyType_Ready(&noddy_NoddyType) comes Py_INCREF(&noddy_NoddyType). > Actually noddy_NoddyType is a static struct so I don't understand > why I need to Py_INCREF it. Since it's Py_INCREFed, does it mean > sometimes we also need to Py_DECREF it? But then it seems that > type_dealloc will be invoked and it will fail > assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); > > > ?It is a module attribute, so when the module is imported it has to > have a single reference (the reference *in* the module). If you don't > INCREF it, then it will have a refcount of 0, and immediately be ready > for garbage collection. So if you try to use the type from the > module, you could get a segfault because it's trying to use an object > (type definition) that was already destroyed. > > Note that you don't *always* have to INCREF objects after you create > them in C. Some macros and function do that for you. And in some > cases, all you want or need is a borrowed reference. In those cases, > Py_INCREF is unnecessary. > > The DECREF will be done when it's normally done in Python. If you do > something like > > import noddy > del noddy.NoddyType > > ?All that's really doing is removing NoddyType from the noddy > namespace and Py_DECREFing it. Alternatively, doing > > import noddy > noddy.NoddyType = 10 # rebind the name > > Then the original object NoddyType was pointing to will be DECREFed > and NoddyType will point to an object taking the value of 10. > > HTH, > Jason From tjreedy at udel.edu Thu Nov 12 22:32:35 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2015 22:32:35 -0500 Subject: Is it useful for re.M in this example? In-Reply-To: References: Message-ID: On 11/12/2015 4:34 PM, fl wrote: > I follow a web site on learning Python re. I have read the function > description of re.m, as below. > re.M Makes $ match the end of a line (not just the end of the string) and > makes ^ match the start of any line (not just the start of the string). > > But I don't see the reason to put re.M in the example project: > > #!/usr/bin/python > import re > > line = "Cats are smarter than dogs"; > > matchObj = re.match( r'dogs', line, re.M|re.I) > if matchObj: > print "match --> matchObj.group() : ", matchObj.group() > else: > print "No match!!" > > The tutorial (http://www.tutorialspoint.com/python/python_reg_expressions.htm) > is for a beginner as I. Is there something I don't see in the example? No. The use of re.M in the examples is doubly irrelevant since there is no \n in line and no $ in the pattern. Re.I is also not relevant since there is no case-insensitive matchin. It appears that the author routinely uses flags=re.M|re.I. For a tutorial, I would have omitted either omitted them or explained them as routine boilerplate. -- Terry Jan Reedy From torriem at gmail.com Thu Nov 12 23:46:18 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 12 Nov 2015 21:46:18 -0700 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> Message-ID: <56456B1A.6080503@gmail.com> On 11/12/2015 05:25 PM, Tim Daneliuk wrote: > On 11/11/2015 08:25 PM, Chris Angelico wrote: >> On Thu, Nov 12, 2015 at 12:52 PM, Tim Daneliuk >> wrote: >>> I am the author of twander (https://www.tundraware.com/Software/twander). >>> This code has run flawlessly for years on FreeBSD, Linux, MacOS and >>> Windows. Some months ago, I put it on a couple of VPS servers (FreeBSD >>> and Linux) and BOOM, it doesn't run. I asked around here and got some >>> suggestions and then did some homework. >>> >>> Traceback (most recent call last): >>> File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main >> >> It's running here under Python 2.6. Sorry if this is a question you've >> already been asked, but were you successfully running under 2.6 >> elsewhere? Might be a versioning issue. >> >> ChrisA >> > > It always ran OK on every previous version of Python from about 2.4 forward > on VMs, physicals, *nix, OSX, Windows, etc. And other X11 apps are working fine on the test VPS where your app crashes? Other Tk apps? Other Python Tk apps? Your app runs fine on my VPS (Linode), running CentOS 7, Python 2.7. Also runs fine on my CentOS 6 VM (also Linode), Python 2.6.6. I also verified that if X11 forwarding is not working, Python reports an exception "_tkinter.TclError: no display name and no $DISPLAY environment variable" immediately, so that's definitely not your problem. From karthik.sharma at gmail.com Fri Nov 13 00:27:58 2015 From: karthik.sharma at gmail.com (Karthik Sharma) Date: Thu, 12 Nov 2015 21:27:58 -0800 (PST) Subject: Plotting timeseries from a csv file using matplotlib Message-ID: I have some csv data in the following format. Ln Dr Tag Lab 0:01 0:02 0:03 0:04 0:05 0:06 0:07 0:08 0:09 L0 St vT 4R 0 0 0 0 0 0 0 0 0 L2 Tx st 4R 8 8 8 8 8 8 8 8 8 L2 Tx ss 4R 1 1 9 6 1 0 0 6 7 I want to plot a timeseries graph using the columns (`Ln` , `Dr`, `Tg`,`Lab`) as the keys and the `0:0n ` field as values on a timeseries graph.I want all the timeseries to be plotted on a single timeseries? I have the following code. #!/usr/bin/env python import matplotlib.pyplot as plt import datetime import numpy as np import csv import sys with open("test.csv", 'r', newline='') as fin: reader = csv.DictReader(fin) for row in reader: key = (row['Ln'], row['Dr'], row['Tg'],row['Lab']) #code to extract the values and plot a timeseries. ~ How do I extract all the values in columns `0:0n` without induviduall specifying each one of them. From tundraBOGUS at tundraware.com Fri Nov 13 00:42:38 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Thu, 12 Nov 2015 23:42:38 -0600 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> Message-ID: On 11/12/2015 10:46 PM, Michael Torrie wrote: > On 11/12/2015 05:25 PM, Tim Daneliuk wrote: >> On 11/11/2015 08:25 PM, Chris Angelico wrote: >>> On Thu, Nov 12, 2015 at 12:52 PM, Tim Daneliuk >>> wrote: >>>> I am the author of twander (https://www.tundraware.com/Software/twander). >>>> This code has run flawlessly for years on FreeBSD, Linux, MacOS and >>>> Windows. Some months ago, I put it on a couple of VPS servers (FreeBSD >>>> and Linux) and BOOM, it doesn't run. I asked around here and got some >>>> suggestions and then did some homework. >>>> >>>> Traceback (most recent call last): >>>> File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main >>> >>> It's running here under Python 2.6. Sorry if this is a question you've >>> already been asked, but were you successfully running under 2.6 >>> elsewhere? Might be a versioning issue. >>> >>> ChrisA >>> >> >> It always ran OK on every previous version of Python from about 2.4 forward >> on VMs, physicals, *nix, OSX, Windows, etc. > > And other X11 apps are working fine on the test VPS where your app > crashes? Other Tk apps? Other Python Tk apps? > > Your app runs fine on my VPS (Linode), running CentOS 7, Python 2.7. > Also runs fine on my CentOS 6 VM (also Linode), Python 2.6.6. > > I also verified that if X11 forwarding is not working, Python reports an > exception "_tkinter.TclError: no display name and no $DISPLAY > environment variable" immediately, so that's definitely not your problem. > > > Curioser and curioser. Yes, xterm works fine. Dunno about any other tk apps. Hmmmm.. From auriocus at gmx.de Fri Nov 13 01:32:08 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 13 Nov 2015 07:32:08 +0100 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> Message-ID: Am 13.11.15 um 06:42 schrieb Tim Daneliuk: > > Curioser and curioser. Yes, xterm works fine. Dunno about any other tk apps. Hello world Tk is like this: Apfelkiste:Sources chris$ wish % pack [button .b -text Hello -command exit] % Apfelkiste:Sources chris$ Upon starting wish, an empty window should appear. The single line makes a button, which exits the program when pressed. It is very strange in your Traceback, that the TclError is not accompanyied by an actual error. This indicates that something more fundamental is going wrong. It seems to crash upon "import tkinter"; can you try reinstalling all related packages? Christian From lac at openend.se Fri Nov 13 03:34:23 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 13 Nov 2015 09:34:23 +0100 Subject: Matplotlib error: Value Error: x and y must have same first dimension In-Reply-To: <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> References: <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> Message-ID: <201511130834.tAD8YNra005833@fido.openend.se> In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes: >I am trying to run some Python code for the last few hours. How can I achieve the effect of "dot divide" from Matlab, in the following code? I am having trouble working with list comprehension and numpy arrays and getting the following error: > > Traceback (most recent call last): > File "Thurs.py", line 128, in > plt.plot(np.array(range(1,N/2+2)), Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50)) > > ValueError: x and y must have same first dimension Splot is a list. matplotlib wants 2 numpy arrays. You have to cast it with np.array() too. no guarantees that the rest of the code works -- it is not plotting for me -- but that gets rid of that error at any rate. Laura From mjoerg.phone at gmail.com Fri Nov 13 03:56:03 2015 From: mjoerg.phone at gmail.com (PythonDude) Date: Fri, 13 Nov 2015 00:56:03 -0800 (PST) Subject: don't understand matrix-multiplication should be reversed in python? In-Reply-To: References: Message-ID: On Thursday, 12 November 2015 17:35:39 UTC+1, Ian wrote: > On Thu, Nov 12, 2015 at 8:57 AM, PythonDude wrote: > > Hi all, > > Anyone could please explain or elaborate on exactly this (quote): "Keep in mind that Python has a reversed definition of rows and columns"??? > > > > That I don't understand - thank you for any hints/guidance/explanations/ideas/suggestions etc! > > py> import numpy > py> p = numpy.reshape(range(5), (5,1)) > py> p > array([[0], > [1], > [2], > [3], > [4]]) > py> p.T > array([[0, 1, 2, 3, 4]]) > py> p.dot(p.T) > array([[ 0, 0, 0, 0, 0], > [ 0, 1, 2, 3, 4], > [ 0, 2, 4, 6, 8], > [ 0, 3, 6, 9, 12], > [ 0, 4, 8, 12, 16]]) > py> p.T.dot(p) > array([[30]]) > py> m = numpy.asmatrix(p) > py> m > matrix([[0], > [1], > [2], > [3], > [4]]) > py> m.T > matrix([[0, 1, 2, 3, 4]]) > py> m * m.T > matrix([[ 0, 0, 0, 0, 0], > [ 0, 1, 2, 3, 4], > [ 0, 2, 4, 6, 8], > [ 0, 3, 6, 9, 12], > [ 0, 4, 8, 12, 16]]) > py> m.T * m > matrix([[30]]) > > Yeah, I don't know what that person is talking about either. It looks > correct to me. Thank you very much, Ian - just had to be sure about this - I would also be very disappointed in Python, if this author was right about this non-intuitive interpretation of how to do matrix multiplication :-) From mjoerg.phone at gmail.com Fri Nov 13 03:57:06 2015 From: mjoerg.phone at gmail.com (PythonDude) Date: Fri, 13 Nov 2015 00:57:06 -0800 (PST) Subject: don't understand matrix-multiplication should be reversed in python? In-Reply-To: References: Message-ID: <11344ffd-f594-4059-8c41-6bacbdb66f10@googlegroups.com> On Thursday, 12 November 2015 22:57:21 UTC+1, Robert Kern wrote: > On 2015-11-12 15:57, PythonDude wrote: > > Hi all, > > > > I've come around a webpage with python-tutorial/description for obtaining something and I'll solve this: > > > > R = p^T w > > > > where R is a vector and p^T is the transpose of another vector. > > > > ... > > p is a Nx1 column vector, so p^T turns into a 1xN row vector which can be multiplied with the > > Nx1 weight (column) vector w to give a scalar result. This is equivalent to the dot > > product used in the code. Keep in mind that Python has a reversed definition of > > rows and columns and the accurate NumPy version of the previous equation would > > be R = w * p.T > > ... > > > > (source: http://blog.quantopian.com/markowitz-portfolio-optimization-2/ ) > > > > I don't understand this: "Keep in mind that Python has a reversed definition of > > rows and columns and the accurate NumPy version of the previous equation would > > be R = w * p.T" > > > > Not true for numpy, is it? This page: http://mathesaurus.sourceforge.net/matlab-numpy.html says it python and matlab looks quite similar... > > > > Anyone could please explain or elaborate on exactly this (quote): "Keep in mind that Python has a reversed definition of rows and columns"??? > > He's wrong, simply put. There is no "reversed definition of rows and columns". Great, thank... > He simply instantiated the two vectors as row-vectors instead of column-vectors, > which he could have easily done, so he had to flip the matrix expression. Thank you very much Robert - I just had to be sure about it :-) From animsri13 at gmail.com Fri Nov 13 04:17:12 2015 From: animsri13 at gmail.com (Animesh Srivastava) Date: Fri, 13 Nov 2015 14:47:12 +0530 Subject: No subject Message-ID: Whenever i install python 3.5.0 compiler It gives me error 0x000007b Can u please resolve it From denismfmcmahon at gmail.com Fri Nov 13 04:19:32 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 13 Nov 2015 09:19:32 -0000 (UTC) Subject: Question about math.pi is mutable References: <1590467.kktH0DaBsW@PointedEars.de> <85pozlidwu.fsf@benfinney.id.au> <10882952.phYABH7ckh@PointedEars.de> <56450d07$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 13 Nov 2015 09:04:54 +1100, Steven D'Aprano wrote: > On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote: > > [crap I expect] > And you should consider the irony, and hypocrisy, of somebody who signs > his posts "PointedEars" bitching about supposed "real names". TPEL has been trolling html, php and javascript newsgroups for years, recently he seems to have discovered python newsgroups. :( -- Denis McMahon, denismfmcmahon at gmail.com From chris at chrullrich.net Fri Nov 13 05:52:01 2015 From: chris at chrullrich.net (Christian Ullrich) Date: Fri, 13 Nov 2015 11:52:01 +0100 Subject: Running latest 32-bit Python on 64-bit system Message-ID: Hello, I have a problem with using the (otherwise nice) Python launcher. How can I get it to run the highest 32-bit Python on my 64-bit system? This is on Windows, but I think it applies to other OSes as well. My application runs (unmodified) with Python 3.[345], but only with the 32-bit version because it loads a DLL that has no 64-bit version available. I would like to run it on any system that has *any* suitable Python installed. However, with the shebang syntax supported by the launcher, I can only demand a 32-bit version if I also specify the Python minor version I want, and I don't necessarily know that in advance. I can code around that, of course, but I don't want to. If Python can select the 64-bit version to run by itself, it should also be able to for the 32-bit version, right? Thanks, -- Christian From fabien.maussion at gmail.com Fri Nov 13 06:51:45 2015 From: fabien.maussion at gmail.com (Fabien) Date: Fri, 13 Nov 2015 12:51:45 +0100 Subject: Plotting timeseries from a csv file using matplotlib References: Message-ID: On 11/13/2015 06:27 AM, Karthik Sharma wrote: > How do I extract all the values in columns Have a look at pandas: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html From vmt.eiz at gmail.com Fri Nov 13 07:23:41 2015 From: vmt.eiz at gmail.com (Akshat Tripathi) Date: Fri, 13 Nov 2015 04:23:41 -0800 (PST) Subject: Unable to make http request to django server using twisted.web.client.AGENT In-Reply-To: References: Message-ID: <64221fbe-7c1a-4994-843a-abc1a21c5dab@googlegroups.com> On Thursday, 5 November 2015 13:06:13 UTC+5:30, Akshat Tripathi wrote: > I have written a basic tcp server factory, server client and a service using twisted. The tcp server acts as the middleware between a django server and an another program (let's call it client program). > > What I want to achieve - > > 1.client requests the middleware tcp server; > > 2.it sends a string as the request body; > > 3.the middleware tcp server deserializes information from the request. > > 4.middleware furthers the serialized information to the django server. > > 5.The django server then responds to the middleware server which furthers the response to the client after serializing the response. > > I am able to reach till step 3, but am unable to make any http request to the django server. > > > > > The following is my middleware.py > > from twisted.internet.protocol import ServerFactory > from twisted.internet.protocol import Protocol > > from test_service import MyService > > > class TCPServerProtocol(Protocol): > data = '' > > def connectionMade(self): > self.deferred = self.factory.service.deferred > self.deferred.addCallback(self.factory.service.s) > self.deferred.addCallback(self.transport.write) > self.deferred.addBoth(lambda r: self.transport.loseConnection) > > def dataReceived(self, data): > self.data += data > > def connectionLost(self, reason): > self.forward(self.data) > > def forward(self, data): > if self.deferred is not None: > d, self.deferred = self.deferred, None > d.callback(data) > > class TCPServerFactory(ServerFactory): > > protocol = TCPServerProtocol > > def __init__(self, service): > self.service = service > > def runserver(ip, port): > iface = {'home': '192.168.0.104', 'work': '127.0.0.1'} > service = MyService() > factory = TCPServerFactory(service) > from twisted.internet import reactor > reactor.listenTCP(port=port, factory=factory, interface=iface[ip]) > reactor.run() > > if __name__ == '__main__': > import sys > ip = sys.argv[1] > port = int(sys.argv[2]) > runserver(ip, port) > > > > > The following is test_service.py > > from twisted.internet.defer import Deferred > > from test_http_client import HTTPClientFactory > > class MyService(object): > def __init__(self): > self.deferred = Deferred() > > def s(self, data): > kwargs = {} > kwargs['url'] = b'http://127.0.0.1:8000/some/end/point' > kwargs['url'] = kwargs['url'].encode('latin-1') > kwargs['method'] = 'POST' > kwargs['data'] = data > > client = HTTPClientFactory(**kwargs) > d = client.deferred > return d > > > The following is test_http_client.py > > from StringIO import StringIO > import json > > from twisted.internet.protocol import Protocol > from twisted.internet.defer import Deferred > from twisted.web.client import Agent, FileBodyProducer > from twisted.web.http_headers import Headers > > > class HTTPClientProtocol(Protocol): > def __init__(self, finished): > self.finished = finished > self.data = '' > > def dataReceived(self, data): > print '----------Data Received by HTTPClientProtocol----------' > print data > self.data += data > > def connectionLost(self, reason): > print '----------HTTP Client connection Lost----------' > print reason.getErrorMessage() > if self.finished is not None: > print 'finished is not None' > f, self.finished = self.finished, None > f.callback(self.data) > > class HTTPClientFactory(object): > > """ > Class handling communication with HTTP server. > """ > > def __init__(self, **kwargs): > data = kwargs['data'] > try: > body = FileBodyProducer(StringIO(json.dumps(data))) > print '----------Request body object created----------' > except Exception as e: > print '----------Request body object creation FAILURE----------' > print e > return e > url = kwargs.get('url', None) > method = kwargs.get('method', None) > > from twisted.internet import reactor > agent = Agent(reactor) > if not data: > body = None > > self.deferred = agent.request(method, > url, > Headers({'Content-Type': ['application/json']}), > bodyProducer=body) > > self.deferred.addCallback(self.get_response) > > def get_response(self, response): > print 'Response received' > finished = Deferred() > response.deliverBody(HTTPClientProtocol(finished)) > return finished Found the bug. Below is the corrected code. class TCPServerProtocol(Protocol): # data = '' def connectionMade(self): self.deferred = self.factory.service.deferred self.deferred.addCallback(self.factory.service.s) self.deferred.addCallback(self.transport.write) self.deferred.addBoth(lambda r: self.transport.loseConnection) def dataReceived(self, data): self.data = data # instead of self.data += data self.forward(self.data) # this is the right place to call this method which in turn fires the callback through which the request is made to the server. def connectionLost(self, reason): pass # this will not be called until the connection from client is ended. # self.forward(self.data) def forward(self, data): if self.deferred is not None: d, self.deferred = self.deferred, None d.callback(data) From rosuav at gmail.com Fri Nov 13 08:17:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Nov 2015 00:17:03 +1100 Subject: No subject In-Reply-To: References: Message-ID: On Fri, Nov 13, 2015 at 8:17 PM, Animesh Srivastava wrote: > Whenever i install python 3.5.0 compiler > It gives me error 0x000007b > Can u please resolve it Is this Windows XP? You have three options: 1) Install Python 3.4 instead 2) Upgrade to a newer Windows 3) Upgrade to a better operating system Is this not Windows XP? You have three options: 1) Read about newsgroup postings and subject lines 2) Resolve the issue yourself, with the skills you have 3) Tell us a *lot* more information about what's going on, what OS you're using (including the version), the error message you're getting, etc, etc. In each case, the third option is the best by far, and is recommended. ChrisA From rxjwg98 at gmail.com Fri Nov 13 08:50:19 2015 From: rxjwg98 at gmail.com (fl) Date: Fri, 13 Nov 2015 05:50:19 -0800 (PST) Subject: Can Canopy Express (Free) allow install a new package (PyBayes) to it? Message-ID: <9d801f2d-06d3-41c7-9f56-d029567b912a@googlegroups.com> I am using Canopy Express (Free) version. I want to install PyBayes package, but I don't see it in Package Manager of Canopy. Can I install PyBayes to Canopy? Now, Canopy is the default Python on my Windows 7 PC. If Canopy does not allow to install PyBayes into it, can I install PyBayes to the plain Python 2.7 (downloaded from Python website, which was installed before I installed Canopy), and use Python 2.7 IDLE with PyBayes? (I am concern about Canopy makes the Windows Python 2.7 not the same way as before? Thanks, From oscar.j.benjamin at gmail.com Fri Nov 13 09:04:01 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 13 Nov 2015 14:04:01 +0000 Subject: Matplotlib error: Value Error: x and y must have same first dimension In-Reply-To: <201511130834.tAD8YNra005833@fido.openend.se> References: <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> <201511130834.tAD8YNra005833@fido.openend.se> Message-ID: On 13 November 2015 at 08:34, Laura Creighton wrote: > In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes: >>I am trying to run some Python code for the last few hours. How can I achieve the effect of "dot divide" from Matlab, in the following code? I am having trouble working with list comprehension and numpy arrays and getting the following error: >> >> Traceback (most recent call last): >> File "Thurs.py", line 128, in >> plt.plot(np.array(range(1,N/2+2)), Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50)) >> >> ValueError: x and y must have same first dimension > > Splot is a list. matplotlib wants 2 numpy arrays. You have to cast > it with np.array() too. Actually the plot command is perfectly happy converting lists or lists of lists etc. to arrays (by calling np.array internally) so you don't need to convert any of your inputs. By the way: np.arange(1, N/2+2) would be the usual way to create a numpy array that is a range. The error here comes because (after both arguments are converted to arrays) they have incompatible sizes. In other words: len(range(1,N/2+2)) != len(Splot[alpha][iii,val]/utot[iii,val]) I'm not sure what the solution is as the code is too complex for me to spend time trying to guess what it's trying to do. -- Oscar From denismfmcmahon at gmail.com Fri Nov 13 09:32:38 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 13 Nov 2015 14:32:38 -0000 (UTC) Subject: Plotting timeseries from a csv file using matplotlib References: Message-ID: On Thu, 12 Nov 2015 21:27:58 -0800, Karthik Sharma wrote: > I have some csv data in the following format. ...... Does the following idea help? Create a key from the key fields, remove the key fields from the row dic (so now it's a dic of just the data fields), and save that in the plotdata dict keyed by the key. import csv keybits = ["Ln","Dr","Tag","Lab"] plotdata = {} with open("lab.csv", 'r') as fin: reader = csv.DictReader(fin) for row in reader: key = tuple([row[k] for k in keybits]) for k in keybits: del row[k] plotdata[key] = row This generates a dictionary (plotdata) keyed by the key tuples where the value for each key is a dictionary of 0:0n : value -- Denis McMahon, denismfmcmahon at gmail.com From oscar.j.benjamin at gmail.com Fri Nov 13 09:59:41 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 13 Nov 2015 14:59:41 +0000 Subject: What is the meaning of Py_INCREF a static PyTypeObject? In-Reply-To: <5645542B.9070602@126.com> References: <56444835.5020803@126.com> <5645542B.9070602@126.com> Message-ID: On 13 November 2015 at 03:08, Xiang Zhang <18518281186 at 126.com> wrote: > I think the meaning of Py_INCREF a static type object is to prevent it from > being deallocated when it is Py_DECREFed somehow later. Just as you said, it > may be somehow deallocated when using. > > NoddyType is a static struct so I don't think it lives on Python's heap and > deallocating it is a wrong action. Just as I mentioned, type_dealloc seems > to only deallocated HEAPTYPE. And by the way, when NoddyType is created, it > has a reference count 1 with PyVarObject_HEAD_INIT. So if I don't Py_INCREF > it, when it is somehow Py_DECREDed later, it will reach reference count 0 > and fail the assert in type_dealloc. If it is Py_INCREFed, just like the > module holds a reference to it, it will at least have a reference count 1 > and never reach 0. Other code shouldn't Py_DECREF it unless it owns a reference meaning that it has first called Py_INCREF. The only exception I can think is possibly that someone would do: >>> import noddy >>> del noddy.Noddy For that to work properly I guess that Noddy needs a reference count of 2: one for being a module attribute and an extra one to prevent it from ever being deallocated. -- Oscar From mjoerg.phone at gmail.com Fri Nov 13 10:37:55 2015 From: mjoerg.phone at gmail.com (PythonDude) Date: Fri, 13 Nov 2015 07:37:55 -0800 (PST) Subject: numpy column_stack - why does this work? Message-ID: <0b4725a8-a040-4bfb-b046-81c2e529447a@googlegroups.com> Hi all, Just a quick question about this code-piece (it works, I've tested it): means, stds = np.column_stack([ getMuSigma_from_PF(return_vec) for _ in xrange(n_portfolios) ]) 1) I understand column_stack does this (assembles vectors vertically, side-by-side): >>> a = np.array((1,2,3)) # NB: a is row-vector: {1 2 3} >>> b = np.array((2,3,4)) # NB: b is also a row-vector... >>> np.column_stack((a,b)) array([[1, 2], [2, 3], [3, 4]]) 2) I understand the underscore is just a "dummy variable" in the last line "for _ in xrange(n_portfolios)" - this also looked a bit confusing to me, at first... 3) I DON'T understand why the code doesn't look like this: means, stds = np.column_stack([ for _ in xrange(n_portfolios): getMuSigma_from_PF(return_vec) ]) ??? Any comments/advice/hints, I would appreciate from you, thank you! From lac at openend.se Fri Nov 13 10:40:02 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 13 Nov 2015 16:40:02 +0100 Subject: No subject In-Reply-To: References: Message-ID: <201511131540.tADFe2n2006181@fido.openend.se> In a message of Fri, 13 Nov 2015 14:47:12 +0530, Animesh Srivastava writes: >Whenever i install python 3.5.0 compiler >It gives me error 0x000007b >Can u please resolve it >-- >https://mail.python.org/mailman/listinfo/python-list Maybe this is your problem http://www.bitdefender.com/support/how-to-solve-error-message-%22the-application-was-unable-to-start-correctly-%280x000007b%29-click-ok-to-close-the-application%22-1106.html Laura From lac at openend.se Fri Nov 13 10:43:54 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 13 Nov 2015 16:43:54 +0100 Subject: Matplotlib error: Value Error: x and y must have same first dimension In-Reply-To: References: <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> <201511130834.tAD8YNra005833@fido.openend.se> Message-ID: <201511131543.tADFhsvL006539@fido.openend.se> In a message of Fri, 13 Nov 2015 14:04:01 +0000, Oscar Benjamin writes: >On 13 November 2015 at 08:34, Laura Creighton wrote: >> In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes: >>>I am trying to run some Python code for the last few hours. How can I achieve the effect of "dot divide" from Matlab, in the following code? I am having trouble working with list comprehension and numpy arrays and getting the following error: >>> >>> Traceback (most recent call last): >>> File "Thurs.py", line 128, in >>> plt.plot(np.array(range(1,N/2+2)), Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50)) >>> >>> ValueError: x and y must have same first dimension >> >> Splot is a list. matplotlib wants 2 numpy arrays. You have to cast >> it with np.array() too. > >Actually the plot command is perfectly happy converting lists or lists >of lists etc. to arrays (by calling np.array internally) so you don't >need to convert any of your inputs. By the way: np.arange(1, N/2+2) >would be the usual way to create a numpy array that is a range. > >The error here comes because (after both arguments are converted to >arrays) they have incompatible sizes. In other words: > > len(range(1,N/2+2)) != len(Splot[alpha][iii,val]/utot[iii,val]) > >I'm not sure what the solution is as the code is too complex for me to >spend time trying to guess what it's trying to do. > >-- >Oscar I am sorry for the bad information. Thank you Oscar. Laura From Cecil at decebal.nl Fri Nov 13 11:33:06 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 13 Nov 2015 17:33:06 +0100 Subject: Trying out Kivy Message-ID: <871tbt3lml.fsf@Equus.decebal.nl> I tried out the ?standard? Kivy application: ============================================================ from kivy.app import App from kivy.uix.button import Button class TestApp(App): def build(self): return Button(text='Hello World') TestApp().run() ============================================================ When using python2 I see some exceptions and OSErrors, but it runs. When using python3 I get: [CRITICAL ] [Text ] Unable to find any valuable Text provider at all! pygame - ImportError: No module named 'pygame' File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib fromlist=[modulename], level=0) File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pygame.py", line 12, in import pygame pil - ImportError: No module named 'PIL' File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib fromlist=[modulename], level=0) File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pil.py", line 8, in from PIL import Image, ImageFont, ImageDraw [CRITICAL ] [App ] Unable to get a Text provider, abort. I tried to install pygame and PIL with pip3, but that did not find anything. Is there another way to install those dependencies? But more importantly: can I develop with python3 for the Android? Because the primary reason to use Kivy is to develop applications for Android. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From df at see.replyto.invalid Fri Nov 13 11:35:56 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Fri, 13 Nov 2015 16:35:56 +0000 Subject: don't understand matrix-multiplication should be reversed in python? References: <11344ffd-f594-4059-8c41-6bacbdb66f10@googlegroups.com> Message-ID: PythonDude wrote: >On Thursday, 12 November 2015 22:57:21 UTC+1, Robert Kern wrote: >> He simply instantiated the two vectors as row-vectors instead of column-vectors, >> which he could have easily done, so he had to flip the matrix expression. > >Thank you very much Robert - I just had to be sure about it :-) Yep, he's evidently used to the Matlab/Octave way of defining "vectors" which is somewhat easier for a math-oriented interactive environment. It's just a *bit* more laborious to append columns in numpy. >>> from numpy import * >>> v1=vstack([0,1,2]) >>> v2=vstack([3,4,5]) >>> c_[v1,v2] array([[0, 3], [1, 4], [2, 5]]) >>> append(v1,v2,axis=1) array([[0, 3], [1, 4], [2, 5]]) >>> v3=mat('4;5;6') >>> v4=mat('7;8;9') >>> c_[v3,v4] matrix([[4, 7], [5, 8], [6, 9]]) From ian.g.kelly at gmail.com Fri Nov 13 12:16:49 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 10:16:49 -0700 Subject: numpy column_stack - why does this work? In-Reply-To: <0b4725a8-a040-4bfb-b046-81c2e529447a@googlegroups.com> References: <0b4725a8-a040-4bfb-b046-81c2e529447a@googlegroups.com> Message-ID: On Fri, Nov 13, 2015 at 8:37 AM, PythonDude wrote: > Hi all, > > Just a quick question about this code-piece (it works, I've tested it): > > means, stds = np.column_stack([ > getMuSigma_from_PF(return_vec) > for _ in xrange(n_portfolios) ]) > > > 1) I understand column_stack does this (assembles vectors vertically, side-by-side): > >>>> a = np.array((1,2,3)) # NB: a is row-vector: {1 2 3} >>>> b = np.array((2,3,4)) # NB: b is also a row-vector... >>>> np.column_stack((a,b)) > array([[1, 2], > [2, 3], > [3, 4]]) > > 2) I understand the underscore is just a "dummy variable" in the last line "for _ in xrange(n_portfolios)" - this also looked a bit confusing to me, at first... > > 3) I DON'T understand why the code doesn't look like this: > > means, stds = np.column_stack([ > for _ in xrange(n_portfolios): > getMuSigma_from_PF(return_vec) ]) Because that would be invalid syntax; you can't put a for loop inside an expression like that. Your question is not about numpy.column_stack at all, but about list comprehensions. I suggest you start by reading this: https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions Then if you're still confused, come back and ask further questions. From torriem at gmail.com Fri Nov 13 12:21:33 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 13 Nov 2015 10:21:33 -0700 Subject: Trying out Kivy In-Reply-To: <871tbt3lml.fsf@Equus.decebal.nl> References: <871tbt3lml.fsf@Equus.decebal.nl> Message-ID: <56461C1D.9060903@gmail.com> On 11/13/2015 09:33 AM, Cecil Westerhof wrote: > I tried to install pygame and PIL with pip3, but that did not find > anything. The replacement for PIL is called Pillow. I'm not sure if it's a drop-in replacement or not. If it's not, then you'd have to modify Kivy to import from Pillow. Pillow does support Python3. > Is there another way to install those dependencies? Did you do a search to find out a) if PyGame supports Python3 (it does) and b) where to go to download the source code for it? (their home page)? PyPi is nice, but it's not the only place you can get useful Python modules from. > But more importantly: can I develop with python3 for the Android? > Because the primary reason to use Kivy is to develop applications for Android. Again, did you do a quick Google search? From tjreedy at udel.edu Fri Nov 13 12:23:45 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Nov 2015 12:23:45 -0500 Subject: Trying out Kivy In-Reply-To: <871tbt3lml.fsf@Equus.decebal.nl> References: <871tbt3lml.fsf@Equus.decebal.nl> Message-ID: On 11/13/2015 11:33 AM, Cecil Westerhof wrote: > I tried out the ?standard? Kivy application: > ============================================================ > from kivy.app import App > from kivy.uix.button import Button > > class TestApp(App): > def build(self): > return Button(text='Hello World') > > TestApp().run() > ============================================================ > > When using python2 I see some exceptions and OSErrors, but it runs. > > When using python3 I get: > [CRITICAL ] [Text ] Unable to find any valuable Text provider at all! > pygame - ImportError: No module named 'pygame' > File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib > fromlist=[modulename], level=0) > File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pygame.py", line 12, in > import pygame > > pil - ImportError: No module named 'PIL' > File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib > fromlist=[modulename], level=0) > File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pil.py", line 8, in > from PIL import Image, ImageFont, ImageDraw > > [CRITICAL ] [App ] Unable to get a Text provider, abort. > > I tried to install pygame and PIL with pip3, but that did not find Use pillow rather than PIL. API is same. Don't know about rest of your question. > anything. Is there another way to install those dependencies? > > But more importantly: can I develop with python3 for the Android? > Because the primary reason to use Kivy is to develop applications for Android. > -- Terry Jan Reedy From abhishek.mallela at gmail.com Fri Nov 13 12:44:04 2015 From: abhishek.mallela at gmail.com (Abhishek Mallela) Date: Fri, 13 Nov 2015 11:44:04 -0600 Subject: Matplotlib error: Value Error: x and y must have same first dimension In-Reply-To: <201511131543.tADFhsvL006539@fido.openend.se> References: <40964e99-cd31-4daa-8f5f-069b09816b3d@googlegroups.com> <201511130834.tAD8YNra005833@fido.openend.se> <201511131543.tADFhsvL006539@fido.openend.se> Message-ID: Thank you Laura and Oscar. Abhishek From wabayang at gmail.com Fri Nov 13 12:50:52 2015 From: wabayang at gmail.com (bayang) Date: Fri, 13 Nov 2015 18:50:52 +0100 Subject: Trying out Kivy In-Reply-To: References: <871tbt3lml.fsf@Equus.decebal.nl> Message-ID: <564622FC.4020208@gmail.com> Le 13/11/2015 18:23, Terry Reedy a ?crit : > On 11/13/2015 11:33 AM, Cecil Westerhof wrote: >> I tried out the ?standard? Kivy application: >> ============================================================ >> from kivy.app import App >> from kivy.uix.button import Button >> >> class TestApp(App): >> def build(self): >> return Button(text='Hello World') >> >> TestApp().run() >> ============================================================ >> >> When using python2 I see some exceptions and OSErrors, but it runs. >> >> When using python3 I get: >> [CRITICAL ] [Text ] Unable to find any valuable >> Text provider at all! >> pygame - ImportError: No module named 'pygame' >> File >> "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, >> in core_select_lib >> fromlist=[modulename], level=0) >> File >> "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pygame.py", >> line 12, in >> import pygame >> >> pil - ImportError: No module named 'PIL' >> File >> "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, >> in core_select_lib >> fromlist=[modulename], level=0) >> File >> "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pil.py", line >> 8, in >> from PIL import Image, ImageFont, ImageDraw >> >> [CRITICAL ] [App ] Unable to get a Text >> provider, abort. >> >> I tried to install pygame and PIL with pip3, but that did not find > > Use pillow rather than PIL. API is same. Don't know about rest of > your question. > >> anything. Is there another way to install those dependencies? >> >> But more importantly: can I develop with python3 for the Android? >> Because the primary reason to use Kivy is to develop applications for >> Android. >> > > Got the same issue a few days ago with python3. Installed pygame dependencies, installed pygame, installed pillow and everything went fine (using pip in virtualenv) From Cecil at decebal.nl Fri Nov 13 13:30:00 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 13 Nov 2015 19:30:00 +0100 Subject: Trying out Kivy References: <871tbt3lml.fsf@Equus.decebal.nl> Message-ID: <87pozd21nb.fsf@Equus.decebal.nl> On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote: > On 11/13/2015 09:33 AM, Cecil Westerhof wrote: >> I tried to install pygame and PIL with pip3, but that did not find >> anything. > > The replacement for PIL is called Pillow. I'm not sure if it's a > drop-in replacement or not. If it's not, then you'd have to modify > Kivy to import from Pillow. Pillow does support Python3. After installing Pillow the error about PIL disappeared, but I got new errors about bcm and x11. >> Is there another way to install those dependencies? > > Did you do a search to find out a) if PyGame supports Python3 (it > does) and b) where to go to download the source code for it? (their > home page)? > > PyPi is nice, but it's not the only place you can get useful Python > modules from. > >> But more importantly: can I develop with python3 for the Android? >> Because the primary reason to use Kivy is to develop applications >> for Android. > > Again, did you do a quick Google search? I did. But I did not find specifics about the version of Python. Well, maybe I should first play a bit with Kivy and if it is the way to go, I delve into the python3 bit. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From tundraBOGUS at tundraware.com Fri Nov 13 14:14:08 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Fri, 13 Nov 2015 13:14:08 -0600 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> Message-ID: <0dphhc-ntf.ln1@oceanview.tundraware.com> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: > Apfelkiste:Sources chris$ Well, I get window and when I do this: pack [button .b -text Hello -command exit] Nothing appears. tkinter appears borked I have reinstalled once already, will try again From kent at z-sverige.nu Fri Nov 13 14:20:45 2015 From: kent at z-sverige.nu (kent nyberg) Date: Fri, 13 Nov 2015 14:20:45 -0500 Subject: Problems using struct pack/unpack in files, and reading them. Message-ID: <20151113192045.GA9913@z-sverige.nu> Hi there, Im deeply sorry for yet another question to this list. I have come across a problem to which google seems not to eager to supply the anwser. The problem is the following. First I do this: def setup_drive(): test = pack('>HH', 0b1000000000000000, 0b1000000100000001) file = open('drive.bin', 'wb') for x in range(640000): file.write(test) file.close() I have a pack, which I fill the file with. The data is not of interrest right now. This all works great. Then I do this: def LoadCommandAndReact(place_to_read): global RegisterAX tmp = place_to_read.read()[RegisterAX:calcsize('HH')] klar = unpack('>HH', tmp) if place_to_read.closed: print("Drive error. Drive closed.") else: pass if checkfirstbit(klar[RegisterAX]): print("First bit is set. Move Cmd.") if (klar[0] & 0b0111111111111111): print("Cmd ERROR: Multiple commands is set.") pass else: #Here something to do with mv command. print("Adress to read to, from the offset of the command") print(klar[RegisterAX+1]) #Variable is always Offset+1 else: print("First bit is not set.") #Change RegisterAX offset+2bytes, RegisterAX=+2 #We read two bytes per cycle. Becaus command is first, and variables are second. This all works If I run the LoadCommand.. only once. But when I run it for the second time, it complains: Traceback (most recent call last): File "core.py", line 98, in LoadCommandAndReact(readfile) File "core.py", line 30, in LoadCommandAndReact klar = unpack('>HH', tmp) struct.error: unpack requires a string argument of length 4 Im having trouble understanding the error. unpack requires a string argument of length 4. I have filled the file with data that should be readable, and is readable by the function when I run it for the first time. And since the file is filled with duplicates; should it not be readable the second time aswell? I change the RegisterAX =+2. The amount I add should not matter, Its just my "offset" of where to read in the file. The problem seems that the second time, unpack doesnt get the size of '>HH' to read. But surely .read()[RegisterAX:calcsize('HH')] should assure that its fed with correct data? I have filled the file with data of size '>HH' and first command reads that. So next read should read the next duplicate of that data that has been written to the file? I understand its hard to read, and a long email. So well, its just a cry out in the dark evening. If some one can share some light.. I would be much happy about it. /Kent. From ian.g.kelly at gmail.com Fri Nov 13 14:36:22 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 12:36:22 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <20151113192045.GA9913@z-sverige.nu> References: <20151113192045.GA9913@z-sverige.nu> Message-ID: On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg wrote: > def LoadCommandAndReact(place_to_read): > global RegisterAX > > tmp = place_to_read.read()[RegisterAX:calcsize('HH')] It looks like you're trying to get a slice of length 4 here, starting at the value of RegisterAX. What you're actually getting is a slice starting at the value of RegisterAX and ending at 4. You probably want this instead: tmp = place_to_read.read()[RegisterAX:RegisterAX + calcsize('HH')] From ian.g.kelly at gmail.com Fri Nov 13 14:45:42 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 12:45:42 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <20151113192045.GA9913@z-sverige.nu> References: <20151113192045.GA9913@z-sverige.nu> Message-ID: As long as I'm replying to this, I see a few more issues to comment on: On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg wrote: > if place_to_read.closed: > print("Drive error. Drive closed.") You probably also want to break or return here. Even better: raise an exception instead of printing. That said, why would this ever be closed here, since you just read from it two lines prior (which would have raised an exception if the file were closed), and you haven't closed it in the meantime? > if checkfirstbit(klar[RegisterAX]): > print("First bit is set. Move Cmd.") > if (klar[0] & 0b0111111111111111): > print("Cmd ERROR: Multiple commands is set.") Why do you pass the commands in a bit field if you're not going to allow multiple commands to be set? Also, see above about break/return/exception. > pass Unnecessary. > #Change RegisterAX offset+2bytes, > RegisterAX=+2 #We read two bytes per cycle. Becaus command is first, and variables are second. This sets RegisterAX to 2. Specifically, positive 2. If you want to *add* 2, you probably meant to write: RegisterAX += 2 This also points out a good reason for using spaces around operators, as "RegisterAX =+ 2" would have caused a SyntaxError and been more easily detectable. From torriem at gmail.com Fri Nov 13 14:53:50 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 13 Nov 2015 12:53:50 -0700 Subject: Trying out Kivy In-Reply-To: <87pozd21nb.fsf@Equus.decebal.nl> References: <871tbt3lml.fsf@Equus.decebal.nl> <87pozd21nb.fsf@Equus.decebal.nl> Message-ID: <56463FCE.3030107@gmail.com> On 11/13/2015 11:30 AM, Cecil Westerhof wrote: > On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote: > >> On 11/13/2015 09:33 AM, Cecil Westerhof wrote: >>> I tried to install pygame and PIL with pip3, but that did not find >>> anything. >> >> The replacement for PIL is called Pillow. I'm not sure if it's a >> drop-in replacement or not. If it's not, then you'd have to modify >> Kivy to import from Pillow. Pillow does support Python3. > > After installing Pillow the error about PIL disappeared, but I got new > errors about bcm and x11. Traceback? From lac at openend.se Fri Nov 13 14:56:00 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 13 Nov 2015 20:56:00 +0100 Subject: More tkinter Madness In-Reply-To: <0dphhc-ntf.ln1@oceanview.tundraware.com> References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <0dphhc-ntf.ln1@oceanview.tundraware.com> Message-ID: <201511131956.tADJu0fb026608@fido.openend.se> In a message of Fri, 13 Nov 2015 13:14:08 -0600, Tim Daneliuk writes: >On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: >> Apfelkiste:Sources chris$ > >Well, I get window and when I do this: > >pack [button .b -text Hello -command exit] > >Nothing appears. > >tkinter appears borked > >I have reinstalled once already, will try again Next idea. Try to run a basic Tk app and a basic Tcl one. See if they work or not. Laura From torriem at gmail.com Fri Nov 13 14:58:00 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 13 Nov 2015 12:58:00 -0700 Subject: More tkinter Madness In-Reply-To: <0dphhc-ntf.ln1@oceanview.tundraware.com> References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <0dphhc-ntf.ln1@oceanview.tundraware.com> Message-ID: <564640C8.1090608@gmail.com> On 11/13/2015 12:14 PM, Tim Daneliuk wrote: > On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: >> Apfelkiste:Sources chris$ > > Well, I get window and when I do this: > > pack [button .b -text Hello -command exit] > > Nothing appears. > > tkinter appears borked > > I have reinstalled once already, will try again Tkinter is the name of the Python package for using Tk, but Tk itself is usually called Tk (package on Fedora and RHEL is tk). On my CentOS installs, in /usr/share/tk8.5/demos, there are a number of Tcl/Tk demos you can run. If Tcl and Tk are working, then I would move to reinstalling tkinter. From Cecil at decebal.nl Fri Nov 13 15:10:55 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 13 Nov 2015 21:10:55 +0100 Subject: Trying out Kivy References: <871tbt3lml.fsf@Equus.decebal.nl> <87pozd21nb.fsf@Equus.decebal.nl> Message-ID: <87lha11wz4.fsf@Equus.decebal.nl> On Friday 13 Nov 2015 20:53 CET, Michael Torrie wrote: > On 11/13/2015 11:30 AM, Cecil Westerhof wrote: >> On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote: >> >>> On 11/13/2015 09:33 AM, Cecil Westerhof wrote: >>>> I tried to install pygame and PIL with pip3, but that did not >>>> find anything. >>> >>> The replacement for PIL is called Pillow. I'm not sure if it's a >>> drop-in replacement or not. If it's not, then you'd have to modify >>> Kivy to import from Pillow. Pillow does support Python3. >> >> After installing Pillow the error about PIL disappeared, but I got >> new errors about bcm and x11. > > Traceback? Purge log fired. Analysing... Purge finished! [INFO ] [Logger ] Record log in /home/cecil/.kivy/logs/kivy_15-11-13_28.txt [INFO ] [Kivy ] v1.9.0 [INFO ] [Python ] v3.4.1 (default, May 23 2014, 17:48:28) [GCC] [INFO ] [Factory ] 173 symbols loaded [INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_pil (img_pygame, img_ffpyplayer ignored) [INFO ] [Text ] Provider: pil(['text_pygame'] ignored) [CRITICAL ] [Window ] Unable to find any valuable Window provider at all! egl_rpi - ImportError: cannot import name 'bcm' File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib fromlist=[modulename], level=0) File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", line 12, in from kivy.lib.vidcore_lite import bcm, egl pygame - ImportError: No module named 'pygame' File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib fromlist=[modulename], level=0) File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_pygame.py", line 8, in import pygame x11 - ImportError: No module named 'kivy.core.window.window_x11' File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib fromlist=[modulename], level=0) [CRITICAL ] [App ] Unable to get a Window, abort. Exception ignored in: 'kivy.properties.dpi2px' Traceback (most recent call last): File "/usr/lib64/python3.4/site-packages/kivy/utils.py", line 360, in __get__ retval = self.func(inst) File "/usr/lib64/python3.4/site-packages/kivy/metrics.py", line 169, in dpi EventLoop.ensure_window() File "/usr/lib64/python3.4/site-packages/kivy/base.py", line 126, in ensure_window sys.exit(1) SystemExit: 1 [CRITICAL ] [App ] Unable to get a Window, abort. I see a difference with python2. (Did not notice it before.) With python3 v1.9.0 is installed, but with python2 v1.8.0. [INFO ] Kivy v1.8.0 Maybe that is the problem? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From kent at z-sverige.nu Fri Nov 13 15:15:10 2015 From: kent at z-sverige.nu (kent nyberg) Date: Fri, 13 Nov 2015 15:15:10 -0500 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> Message-ID: <20151113201510.GA10107@z-sverige.nu> On Fri, Nov 13, 2015 at 12:36:22PM -0700, Ian Kelly wrote: > On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg wrote: > > def LoadCommandAndReact(place_to_read): > > global RegisterAX > > > > tmp = place_to_read.read()[RegisterAX:calcsize('HH')] > > It looks like you're trying to get a slice of length 4 here, starting > at the value of RegisterAX. What you're actually getting is a slice > starting at the value of RegisterAX and ending at 4. You probably want > this instead: > > tmp = place_to_read.read()[RegisterAX:RegisterAX + calcsize('HH')] > -- > https://mail.python.org/mailman/listinfo/python-list Even with that, it still gets wrong. I also tried .read()[RegisterAX:RegisterAX+4] As for the other suggestions you had in the second reply, I can comment on them later. For now though, I just want to be able to loop this specific function. I do appriciate that you took the time. :) What bothers me, is the error that says unpack requires a string argument of 4 bytes. Im thinking in the line of arguments? Does unpack look at the 4 bytes it has read, and tell for some reason say that unpacking needs an argument of 4 bytes? I know that I can set the arguments for unpack. I have done that. It is: unpack('>HH', tmp). So either '>HH' or tmp is wrong. Since '>HH' worked for the first run of the function, I assume its correct. And as far as I know, doing .read()[RegisterAX:RegisterAX:+4] should read the following 4 bytes. I have even tried doing .read(4), since then python should manage where to start and read 4? Still it complains? From lac at openend.se Fri Nov 13 15:15:23 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 13 Nov 2015 21:15:23 +0100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <20151113192045.GA9913@z-sverige.nu> References: <20151113192045.GA9913@z-sverige.nu> Message-ID: <201511132015.tADKFNA5028148@fido.openend.se> In a message of Fri, 13 Nov 2015 14:20:45 -0500, kent nyberg writes: >Hi there, >Im deeply sorry for yet another question to this list. I have come across a problem to which google seems not >to eager to supply the anwser. > >The problem is the following. >First I do this: > >def setup_drive(): > test = pack('>HH', 0b1000000000000000, 0b1000000100000001) > file = open('drive.bin', 'wb') > for x in range(640000): > file.write(test) > file.close() > > >I have a pack, which I fill the file with. The data is not of interrest right now. > >This all works great. >Then I do this: > > >def LoadCommandAndReact(place_to_read): > global RegisterAX > > tmp = place_to_read.read()[RegisterAX:calcsize('HH')] > klar = unpack('>HH', tmp) > > if place_to_read.closed: > print("Drive error. Drive closed.") > else: > pass > > if checkfirstbit(klar[RegisterAX]): > print("First bit is set. Move Cmd.") > if (klar[0] & 0b0111111111111111): > print("Cmd ERROR: Multiple commands is set.") > pass > else: > #Here something to do with mv command. > print("Adress to read to, from the offset of the command") > print(klar[RegisterAX+1]) #Variable is always Offset+1 > else: > print("First bit is not set.") > #Change RegisterAX offset+2bytes, > RegisterAX=+2 #We read two bytes per cycle. Becaus command is first, and variables are second. > > > > >This all works If I run the LoadCommand.. only once. >But when I run it for the second time, it complains: > >Traceback (most recent call last): > File "core.py", line 98, in > LoadCommandAndReact(readfile) > File "core.py", line 30, in LoadCommandAndReact > klar = unpack('>HH', tmp) >struct.error: unpack requires a string argument of length 4 > > > >Im having trouble understanding the error. unpack requires a string argument of length 4. >I have filled the file with data that should be readable, and is readable by the function >when I run it for the first time. And since the file is filled with duplicates; should it not be readable the second >time aswell? I change the RegisterAX =+2. The amount I add should not matter, Its just my "offset" of where to read in the file. >The problem seems that the second time, unpack doesnt get the size of '>HH' to read. But surely >.read()[RegisterAX:calcsize('HH')] should assure that its fed with correct data? > >I have filled the file with data of size '>HH' and first command reads that. So next read should read the next >duplicate of that data that has been written to the file? > > >I understand its hard to read, and a long email. So well, its just a cry out in the dark evening. If some one can >share some light.. I would be much happy about it. > >/Kent. >-- >https://mail.python.org/mailman/listinfo/python-list struct wants to know exactly how many of those things you have. You only told it about one of them .... i.e. If you want to unpack 999 elements from binary data data = struct.unpack("999H", B) Laura From lac at openend.se Fri Nov 13 15:17:31 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 13 Nov 2015 21:17:31 +0100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <20151113192045.GA9913@z-sverige.nu> References: <20151113192045.GA9913@z-sverige.nu> Message-ID: <201511132017.tADKHVw6028340@fido.openend.se> I forgot to add. You get this wretched error message if your data is shorter than expected, and you ask struct to read more than you have, as well. most annoying. Laura From ian.g.kelly at gmail.com Fri Nov 13 16:00:36 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 14:00:36 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <20151113201510.GA10107@z-sverige.nu> References: <20151113192045.GA9913@z-sverige.nu> <20151113201510.GA10107@z-sverige.nu> Message-ID: On Fri, Nov 13, 2015 at 1:15 PM, kent nyberg wrote: > Even with that, it still gets wrong. > I also tried .read()[RegisterAX:RegisterAX+4] When you call read for the second time, are you just reading the same file again without closing or seeking it in the interim? If that's the case, then you would get an empty string the second time, which would explain your error. Either retain the read data between calls, or call seek(0) before reading it again. From ian.g.kelly at gmail.com Fri Nov 13 16:05:04 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 14:05:04 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <20151113201510.GA10107@z-sverige.nu> References: <20151113192045.GA9913@z-sverige.nu> <20151113201510.GA10107@z-sverige.nu> Message-ID: On Fri, Nov 13, 2015 at 1:15 PM, kent nyberg wrote: > What bothers me, is the error that says > unpack requires a string argument of 4 bytes. > Im thinking in the line of arguments? Does unpack look at the 4 bytes it has read, and tell for some > reason say that unpacking needs an argument of 4 bytes? I know that I can set the arguments > for unpack. I have done that. It is: unpack('>HH', tmp). > So either '>HH' or tmp is wrong. Since '>HH' worked for the first run of the function, I assume its correct. > And as far as I know, doing .read()[RegisterAX:RegisterAX:+4] should read the following > 4 bytes. By the way, I would strongly suggest that you print or log the value of repr(tmp) so that you *know* what you're passing to unpack rather than having to speculate about it. From wabayang at gmail.com Fri Nov 13 16:11:35 2015 From: wabayang at gmail.com (bayang) Date: Fri, 13 Nov 2015 22:11:35 +0100 Subject: Trying out Kivy In-Reply-To: <87lha11wz4.fsf@Equus.decebal.nl> References: <871tbt3lml.fsf@Equus.decebal.nl> <87pozd21nb.fsf@Equus.decebal.nl> <87lha11wz4.fsf@Equus.decebal.nl> Message-ID: <56465207.1030002@gmail.com> Le 13/11/2015 21:10, Cecil Westerhof a ?crit : > Purge log fired. Analysing... > Purge finished! > [INFO ] [Logger ] Record log in /home/cecil/.kivy/logs/kivy_15-11-13_28.txt > [INFO ] [Kivy ] v1.9.0 > [INFO ] [Python ] v3.4.1 (default, May 23 2014, 17:48:28) [GCC] > [INFO ] [Factory ] 173 symbols loaded > [INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_pil (img_pygame, img_ffpyplayer ignored) > [INFO ] [Text ] Provider: pil(['text_pygame'] ignored) > [CRITICAL ] [Window ] Unable to find any valuable Window provider at all! > egl_rpi - ImportError: cannot import name 'bcm' > File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib > fromlist=[modulename], level=0) > File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", line 12, in > from kivy.lib.vidcore_lite import bcm, egl > > pygame - ImportError: No module named 'pygame' > File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib > fromlist=[modulename], level=0) > File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_pygame.py", line 8, in > import pygame > > x11 - ImportError: No module named 'kivy.core.window.window_x11' > File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib > fromlist=[modulename], level=0) > > [CRITICAL ] [App ] Unable to get a Window, abort. > Exception ignored in: 'kivy.properties.dpi2px' > Traceback (most recent call last): > File "/usr/lib64/python3.4/site-packages/kivy/utils.py", line 360, in __get__ > retval = self.func(inst) > File "/usr/lib64/python3.4/site-packages/kivy/metrics.py", line 169, in dpi > EventLoop.ensure_window() > File "/usr/lib64/python3.4/site-packages/kivy/base.py", line 126, in ensure_window > sys.exit(1) > SystemExit: 1 > [CRITICAL ] [App ] Unable to get a Window, abort. > > > I see a difference with python2. (Did not notice it before.) With > python3 v1.9.0 is installed, but with python2 v1.8.0. > [INFO ] Kivy v1.8.0 > > Maybe that is the problem? > Pygame doesn't seem to be correctly installed. check this : http://www.pygame.org/wiki/CompileUbuntu#Python_3.x in "installing pygame with pip" part. Install dependencies first, then pip install hg+http://bitbucket.org/pygame/pygame From invalid at invalid.invalid Fri Nov 13 16:17:59 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 13 Nov 2015 21:17:59 +0000 (UTC) Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <20151113201510.GA10107@z-sverige.nu> Message-ID: On 2015-11-13, Ian Kelly wrote: > Either retain the read data between calls, or call seek(0) before > reading it again. It has always saddened me that Python files don't have a rewind() method. On Unix, calling rewind() is the same as calling seek(0), so it's utterly pointless except as an amusing anachronistic name: it always made me smile when called rewind() on a file in a filesystem on a hard-drive. Interestingly, you can't you can't (and never could) use rewind() to rewind a tape. You use an ioctl() system call for that. -- Grant Edwards grant.b.edwards Yow! HUGH BEAUMONT died at in 1982!! gmail.com From auriocus at gmx.de Fri Nov 13 16:30:47 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 13 Nov 2015 22:30:47 +0100 Subject: More tkinter Madness In-Reply-To: <0dphhc-ntf.ln1@oceanview.tundraware.com> References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <0dphhc-ntf.ln1@oceanview.tundraware.com> Message-ID: Am 13.11.15 um 20:14 schrieb Tim Daneliuk: > On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: >> Apfelkiste:Sources chris$ > > Well, I get window and when I do this: > > pack [button .b -text Hello -command exit] > > Nothing appears. No error, nothing? Just to be sure, you haven't closed the empty window, that appeared when you typed "wish"? and copied the command into the wish prompt? > tkinter appears borked > I have reinstalled once already, will try again This is using pure Tcl/Tk. If it is not working, reinstall the corresponding packages in your distro. tkinter is merely the Python interface to those. Christian From kent at z-sverige.nu Fri Nov 13 16:34:50 2015 From: kent at z-sverige.nu (kent nyberg) Date: Fri, 13 Nov 2015 16:34:50 -0500 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <20151113201510.GA10107@z-sverige.nu> Message-ID: <20151113213450.GA11001@z-sverige.nu> The main problem was that I forgot to do seek(0). Thanks alot people. Though, as many times before, the problem was due to misunderstanding of how python works. I assumed file.read()[xx:yy] was to be understood as, in the file, read from index xx to place yy. That is, [10:20] was the same as, read from 10th char to 20th. Sort of. Is it true then to say that every .read of a file, places an index-offset (?) from where the next read starts? That is, I need to rewind the file, or else the read will start from where the last read stopped? From invalid at invalid.invalid Fri Nov 13 16:44:49 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 13 Nov 2015 21:44:49 +0000 (UTC) Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <20151113201510.GA10107@z-sverige.nu> Message-ID: On 2015-11-13, kent nyberg wrote: > Though, as many times before, the problem was due to misunderstanding > of how python works. I assumed file.read()[xx:yy] was to be > understood as, in the file, read from index xx to place yy. Nope. First, the 'file.read()' part is evaluated. That returns the entire contents of the file. Next, the '[xx:yy]' slice operation is done on the entire contents returned in the first step. The slice operation retuns bytes xx through yy-1 (inclusive), and discards the rest of the data. > Is it true then to say that every .read of a file, places an > index-offset (?) from where the next read starts? Yes. a file object has a current index. A read() operation always starts at that index. When you open the file, that index is 0. Each time you read from the file, the index is advanced past the data that was read. The seek() method sets that index to whatever you want. > That is, I need to rewind the file, or else the read will start from > where the last read stopped? Exactly. -- Grant Edwards grant.b.edwards Yow! Mr and Mrs PED, can I at borrow 26.7% of the RAYON gmail.com TEXTILE production of the INDONESIAN archipelago? From tundraBOGUS at tundraware.com Fri Nov 13 17:09:46 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Fri, 13 Nov 2015 16:09:46 -0600 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <0dphhc-ntf.ln1@oceanview.tundraware.com> Message-ID: <56465FAA.5060809@tundraware.com> On 11/13/2015 01:58 PM, Michael Torrie wrote: > On 11/13/2015 12:14 PM, Tim Daneliuk wrote: >> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: >>> Apfelkiste:Sources chris$ >> >> Well, I get window and when I do this: >> >> pack [button .b -text Hello -command exit] >> >> Nothing appears. >> >> tkinter appears borked >> >> I have reinstalled once already, will try again > > Tkinter is the name of the Python package for using Tk, but Tk itself is > usually called Tk (package on Fedora and RHEL is tk). > > On my CentOS installs, in /usr/share/tk8.5/demos, there are a number of > Tcl/Tk demos you can run. If Tcl and Tk are working, then I would move > to reinstalling tkinter. > Yep, tcl/tk is borked. That would explain why pure X apps like xterm work, but not tkinter apps. Reinstalling tcl/tk has not helped at all. Now I am really curious what the interaction is between VPS and tk... Sigh. (Thanks) From tundraBOGUS at tundraware.com Fri Nov 13 17:10:08 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Fri, 13 Nov 2015 16:10:08 -0600 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <0dphhc-ntf.ln1@oceanview.tundraware.com> Message-ID: <56465FC0.9040608@tundraware.com> On 11/13/2015 01:56 PM, Laura Creighton wrote: > In a message of Fri, 13 Nov 2015 13:14:08 -0600, Tim Daneliuk writes: >> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: >>> Apfelkiste:Sources chris$ >> >> Well, I get window and when I do this: >> >> pack [button .b -text Hello -command exit] >> >> Nothing appears. >> >> tkinter appears borked >> >> I have reinstalled once already, will try again > > Next idea. > > Try to run a basic Tk app and a basic Tcl one. See if they work or not. > > Laura > Looks like tcl/tk is hosed for some reason. From tundraBOGUS at tundraware.com Fri Nov 13 17:10:42 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Fri, 13 Nov 2015 16:10:42 -0600 Subject: More tkinter Madness In-Reply-To: References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <0dphhc-ntf.ln1@oceanview.tundraware.com> Message-ID: <56465FE2.40701@tundraware.com> On 11/13/2015 03:30 PM, Christian Gollwitzer wrote: > Am 13.11.15 um 20:14 schrieb Tim Daneliuk: >> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: >>> Apfelkiste:Sources chris$ >> >> Well, I get window and when I do this: >> >> pack [button .b -text Hello -command exit] >> >> Nothing appears. > > No error, nothing? Just to be sure, you haven't closed the empty window, that appeared when you typed "wish"? and copied the command into the wish prompt? > >> tkinter appears borked >> I have reinstalled once already, will try again > > This is using pure Tcl/Tk. If it is not working, reinstall the corresponding packages in your distro. tkinter is merely the Python interface to those. > > Christian Yep tcl/tk is the culprit, but reinstalling has not helped. From rosuav at gmail.com Fri Nov 13 17:42:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Nov 2015 09:42:10 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> Message-ID: On Sat, Nov 14, 2015 at 6:45 AM, Ian Kelly wrote: > This sets RegisterAX to 2. Specifically, positive 2. If you want to > *add* 2, you probably meant to write: > > RegisterAX += 2 > > This also points out a good reason for using spaces around operators, > as "RegisterAX =+ 2" would have caused a SyntaxError and been more > easily detectable. Err, no. Even with spaces, it works just fine, because unary plus is allowed to be separated from its operand with spaces: >>> x=1 >>> x =+ 2 >>> x = + 3 >>> x 3 However, this is a reasonable call for the abolition of unary plus... ChrisA From rxjwg98 at gmail.com Fri Nov 13 18:04:20 2015 From: rxjwg98 at gmail.com (fl) Date: Fri, 13 Nov 2015 15:04:20 -0800 (PST) Subject: What is '@' for Message-ID: Hi, I read the following code snippet. A question is here about '@'. I don't find the answer online yet. What function is it here? BTW, below is for printing out? """theta = logit^{-1}(a+b)""" but I don't see it is printed when the following could have been called. Are you sure it would be printed out? Thanks, ................. import pymc import numpy as np n = 5*np.ones(4,dtype=int) x = np.array([-.86,-.3,-.05,.73]) alpha = pymc.Normal('alpha',mu=0,tau=.01) beta = pymc.Normal('beta',mu=0,tau=.01) @pymc.deterministic def theta(a=alpha, b=beta): """theta = logit^{-1}(a+b)""" return pymc.invlogit(a+b*x) d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\ observed=True) From rosuav at gmail.com Fri Nov 13 18:14:11 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Nov 2015 10:14:11 +1100 Subject: What is '@' for In-Reply-To: References: Message-ID: On Sat, Nov 14, 2015 at 10:04 AM, fl wrote: > I read the following code snippet. A question is here about '@'. > I don't find the answer online yet. > > What function is it here? > > > @pymc.deterministic > def theta(a=alpha, b=beta): > """theta = logit^{-1}(a+b)""" > return pymc.invlogit(a+b*x) That's called a "function decorator". And now that you know the name, you'll be able to find what it is online; as well as the Python docs, there are a number of blog posts and other articles about it. ChrisA From tundraBOGUS at tundraware.com Fri Nov 13 18:43:15 2015 From: tundraBOGUS at tundraware.com (Tim Daneliuk) Date: Fri, 13 Nov 2015 17:43:15 -0600 Subject: What is '@' for In-Reply-To: References: Message-ID: <56467593.9060304@tundraware.com> On 11/13/2015 05:14 PM, Chris Angelico wrote: > On Sat, Nov 14, 2015 at 10:04 AM, fl wrote: >> I read the following code snippet. A question is here about '@'. >> I don't find the answer online yet. >> >> What function is it here? >> >> >> @pymc.deterministic >> def theta(a=alpha, b=beta): >> """theta = logit^{-1}(a+b)""" >> return pymc.invlogit(a+b*x) > > That's called a "function decorator". And now that you know the name, > you'll be able to find what it is online; as well as the Python docs, > there are a number of blog posts and other articles about it. > > ChrisA > One small point of order ... if you want to be precise, "@pymc.deterministic" is a *function decoration*. The "decorator" is the function pymc.deterministic(). I know this is a fussy point, but this distinction is helpful when first learning the concept. From tjreedy at udel.edu Fri Nov 13 18:43:28 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Nov 2015 18:43:28 -0500 Subject: What is '@' for In-Reply-To: References: Message-ID: On 11/13/2015 6:04 PM, fl wrote: > I read the following code snippet. A question is here about '@'. > I don't find the answer online yet. Start with the index of the fine docs, which includes symbols. https://docs.python.org/3/genindex-Symbols.html '@' is near the end of the page. > @pymc.deterministic > def theta(a=alpha, b=beta): -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Fri Nov 13 19:12:24 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 Nov 2015 13:12:24 +1300 Subject: don't understand matrix-multiplication should be reversed in python? In-Reply-To: References: <11344ffd-f594-4059-8c41-6bacbdb66f10@googlegroups.com> Message-ID: Dave Farrance wrote: > Yep, he's evidently used to the Matlab/Octave way of defining "vectors" > which is somewhat easier for a math-oriented interactive environment. > > It's just a *bit* more laborious to append columns in numpy. Yes, that's probably the main reason to do things that way. A collection of vectors is most conveniently represented as a 2D array where the first index selects one of the vectors. But then to apply a transformation matrix to all the vectors, you need to transpose the matrix and multiply it on the right. -- Greg From vjp2.at at at.BioStrategist.dot.dot.com Fri Nov 13 20:35:05 2015 From: vjp2.at at at.BioStrategist.dot.dot.com (vjp2.at at at.BioStrategist.dot.dot.com) Date: Sat, 14 Nov 2015 01:35:05 +0000 (UTC) Subject: Jython standalone Message-ID: I click jython.org standalone jar and it just does a wait cycle. What does it need to give me a prompt? - = - Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist http://www.panix.com/~vjp2/vasos.htm ---{Nothing herein constitutes advice. Everything fully disclaimed.}--- [Homeland Security means private firearms not lazy obstructive guards] [Urb sprawl confounds terror] [Phooey on GUI: Windows for subprime Bimbos] From orgnut at yahoo.com Fri Nov 13 21:30:33 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 13 Nov 2015 18:30:33 -0800 Subject: Question about math.pi is mutable In-Reply-To: References: <1590467.kktH0DaBsW@PointedEars.de> <85pozlidwu.fsf@benfinney.id.au> <10882952.phYABH7ckh@PointedEars.de> <56450d07$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/13/2015 01:19 AM, Denis McMahon wrote: > On Fri, 13 Nov 2015 09:04:54 +1100, Steven D'Aprano wrote: > >> On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote: > >>> [crap I expect] > >> And you should consider the irony, and hypocrisy, of somebody who signs >> his posts "PointedEars" bitching about supposed "real names". > > TPEL has been trolling html, php and javascript newsgroups for years, > recently he seems to have discovered python newsgroups. :( > I found that TPEL post to be particularly amusing/ironic (hilarious, really) when he continued by talking about a group that ignores posts by people who don't use real names! :-) I generally ignore his posts as well. -=- Larry -=- <-- My real name, which is NOT Lawrence (or anything similar)! From steve at pearwood.info Fri Nov 13 21:35:26 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Nov 2015 13:35:26 +1100 Subject: Jython standalone References: Message-ID: <56469dee$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Nov 2015 12:35 pm, vjp2.at at at.BioStrategist.dot.dot.com wrote: > I click jython.org standalone jar and it just does a wait cycle. I'm afraid I can't completely understand the problem you are having, since you haven't really described it with sufficient detail. But my *guess* (and this really is just a wild guess) is that you have clicked on a program icon, and then nothing happens, so you think it is waiting. In most operating systems, you need to *double-click*, not just click, to run the program. Try double-clicking instead of single-clicking, and see if that solves your problem. If this is not your problem, please try explaining your problem. Help us to help you, by giving us more information about your situation. Otherwise we're just guessing. What is "jython.org standalone jar", and where did it come from? Is this code you wrote yourself, or code you downloaded? Where did you download it from? What is it supposed to do? What does it actually do? What's a "wait cycle"? How long does it wait, and then what happens? What operating system are you using? Windows, OS X, Linux, something else? Version number? Do you have Java installed? Are .jar files associated with the correct Java executable? > What does it need to give me a prompt? What sort of prompt to you expect? A Python prompt, DOS prompt, something else? -- Steven From steve at pearwood.info Fri Nov 13 21:40:19 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Nov 2015 13:40:19 +1100 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> Message-ID: <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote: > However, this is a reasonable call for the abolition of unary plus... The only way you'll take unary plus out of Python is by prying it from my cold, dead hands. BTW, unary minus suffers from the same "problem": x =- y # oops, meant x -= y If anything, this is an argument against the augmented assignment short-cuts, rather than the operators. -- Steven From rosuav at gmail.com Fri Nov 13 22:01:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Nov 2015 14:01:41 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano wrote: > On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote: > >> However, this is a reasonable call for the abolition of unary plus... > > The only way you'll take unary plus out of Python is by prying it from my > cold, dead hands. > > > BTW, unary minus suffers from the same "problem": > > x =- y # oops, meant x -= y > > If anything, this is an argument against the augmented assignment > short-cuts, rather than the operators. Yes, unary minus has the same issue - but it's a lot more important than unary plus is. In ECMAScript, unary plus means "force this to be a number"; what's its purpose in Python? ChrisA From torriem at gmail.com Fri Nov 13 22:11:47 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 13 Nov 2015 20:11:47 -0700 Subject: Question about math.pi is mutable In-Reply-To: <5641C0EC.8010905@rece.vub.ac.be> References: <857flujwy7.fsf@benfinney.id.au> <5640B28C.6050408@rece.vub.ac.be> <858u66g39k.fsf@benfinney.id.au> <5641C0EC.8010905@rece.vub.ac.be> Message-ID: <5646A673.2060201@gmail.com> On 11/10/2015 03:03 AM, Antoon Pardon wrote: > Op 10-11-15 om 00:29 schreef Ben Finney: >> >> Who is doing what to whom? The user of the library isn't doing anything >> to the library author, so what is it the library author would consent >> to? Instead, you seem to be trying to assert a *power* of the library >> author to restrict the library user. Such a power is not granted by >> Python. > > Python is not at liberty to grant or deny such a power. Python is just > a vehicle in which code is written. The author of a library can restrict > its use anyway he sees fit. No he cannot, outside the bounds of copyright law. Why would you think otherwise? The only document that binds the end user in any way is the copyright license, unless some other formal contract has been arranged. >> Instead, the library author is obliged to treat the library user as an >> adult who consents to the freedoms inherent to Python's design, and to >> not restrict their use of the library needlessly. > > There is no such obligation. And if it was an obligation, you can hardly > talk about consenting. Consenting adults mean that either party can > decide on conditions. Once one party is obligated it is no longer consenting. You are correct there is no obligation, but nor does Python empower the library developer. He may attempt obfuscation or other means to control the use of his library of course, but only copyright grants him legal authority of any kind. From ian.g.kelly at gmail.com Fri Nov 13 22:45:31 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 20:45:31 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 13, 2015 8:03 PM, "Chris Angelico" wrote: > > On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano wrote: > > On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote: > > > >> However, this is a reasonable call for the abolition of unary plus... > > > > The only way you'll take unary plus out of Python is by prying it from my > > cold, dead hands. > > > > > > BTW, unary minus suffers from the same "problem": > > > > x =- y # oops, meant x -= y > > > > If anything, this is an argument against the augmented assignment > > short-cuts, rather than the operators. > > Yes, unary minus has the same issue - but it's a lot more important > than unary plus is. In ECMAScript, unary plus means "force this to be > a number"; what's its purpose in Python? It forces a Counter to contain only positive counts? From ian.g.kelly at gmail.com Fri Nov 13 22:48:50 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 20:48:50 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 13, 2015 8:03 PM, "Chris Angelico" wrote: > > On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano wrote: > > On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote: > > > >> However, this is a reasonable call for the abolition of unary plus... > > > > The only way you'll take unary plus out of Python is by prying it from my > > cold, dead hands. > > > > > > BTW, unary minus suffers from the same "problem": > > > > x =- y # oops, meant x -= y > > > > If anything, this is an argument against the augmented assignment > > short-cuts, rather than the operators. > > Yes, unary minus has the same issue - but it's a lot more important > than unary plus is. In ECMAScript, unary plus means "force this to be > a number"; what's its purpose in Python? I'm not sure "force this to be a number" is really a justification. Without it you could just use - - (but be careful not to write that as --) in the manner of using !! as "force to boolean". Or just call Number(). From rosuav at gmail.com Fri Nov 13 22:56:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Nov 2015 14:56:36 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Nov 14, 2015 at 2:45 PM, Ian Kelly wrote: >> Yes, unary minus has the same issue - but it's a lot more important >> than unary plus is. In ECMAScript, unary plus means "force this to be >> a number"; what's its purpose in Python? > > It forces a Counter to contain only positive counts? Did not know that, and would not have gone looking for it. If Python hadn't had a unary plus operator, Counter would have managed in some other way, without being materially impacted by it. ChrisA From rosuav at gmail.com Fri Nov 13 22:57:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Nov 2015 14:57:43 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Nov 14, 2015 at 2:48 PM, Ian Kelly wrote: >> Yes, unary minus has the same issue - but it's a lot more important >> than unary plus is. In ECMAScript, unary plus means "force this to be >> a number"; what's its purpose in Python? > > I'm not sure "force this to be a number" is really a justification. Without > it you could just use - - (but be careful not to write that as --) in the > manner of using !! as "force to boolean". Or just call Number(). I don't use it myself, but I saw something about asm.js that demonstrated the use of "x = +x;" to mean "x is a number", and "x = x|0;" to mean "x is an integer". ChrisA From ian.g.kelly at gmail.com Fri Nov 13 22:58:04 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 13 Nov 2015 20:58:04 -0700 Subject: find which Python libraries are most influential in scientific research In-Reply-To: <06e7d84d-7e49-4160-b42e-a6911640d9e8@googlegroups.com> References: <06e7d84d-7e49-4160-b42e-a6911640d9e8@googlegroups.com> Message-ID: On Nov 9, 2015 7:41 PM, "Heather Piwowar" wrote: > > Today's scientists often turn to Python to run analysis, simulation, and other sciency tasks. > > That makes us wonder: which Python libraries are most influential in scientific research? > > We just released a tool (built in Python, of course) to answer that question. It's called Depsy [1], it's funded by the US National Science Foundation, and we'd love your comments. > > For more information, see our blog post [2] and paper [3]. The scientific/engineering tag is a great place to start exploring [4]. > > Heather Piwowar and Jason Priem > > 1. http://depsy.org > 2. http://blog.impactstory.org/introducing-depsy > 3. https://github.com/Impactstory/depsy-research/blob/master/introducing_depsy.md > 4. http://depsy.org/tag/scientific%252Fengineering FYI, the depsy.org site is completely unusable on my Android phone. From tjreedy at udel.edu Sat Nov 14 00:38:41 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2015 00:38:41 -0500 Subject: find which Python libraries are most influential in scientific research In-Reply-To: References: <06e7d84d-7e49-4160-b42e-a6911640d9e8@googlegroups.com> Message-ID: On 11/13/2015 10:58 PM, Ian Kelly wrote: > On Nov 9, 2015 7:41 PM, "Heather Piwowar" wrote: >> >> Today's scientists often turn to Python to run analysis, simulation, and > other sciency tasks. >> >> That makes us wonder: which Python libraries are most influential in > scientific research? Numpy, scipy, ?, ?, ?, ... >> We just released a tool (built in Python, of course) to answer that > question. It's called Depsy [1], it's funded by the US National Science > Foundation, and we'd love your comments. >> >> For more information, see our blog post [2] and paper [3]. The > scientific/engineering tag is a great place to start exploring [4]. >> >> Heather Piwowar and Jason Priem >> >> 1. http://depsy.org >> 2. http://blog.impactstory.org/introducing-depsy >> 3. > https://github.com/Impactstory/depsy-research/blob/master/introducing_depsy.md >> 4. http://depsy.org/tag/scientific%252Fengineering > > FYI, the depsy.org site is completely unusable on my Android phone. Ditto Win10, Firefox. -- Terry Jan Reedy From steve at pearwood.info Sat Nov 14 00:40:41 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Nov 2015 16:40:41 +1100 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Nov 2015 02:01 pm, Chris Angelico wrote: > On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano > wrote: >> On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote: >> >>> However, this is a reasonable call for the abolition of unary plus... >> >> The only way you'll take unary plus out of Python is by prying it from my >> cold, dead hands. >> >> >> BTW, unary minus suffers from the same "problem": >> >> x =- y # oops, meant x -= y >> >> If anything, this is an argument against the augmented assignment >> short-cuts, rather than the operators. > > Yes, unary minus has the same issue - but it's a lot more important > than unary plus is. In ECMAScript, unary plus means "force this to be > a number"; what's its purpose in Python? Python has operator overloading, so it can be anything you want it to be. E.g. you might have a DSL where +feature turns something on and -feature turns it off. Decimal uses it to force the current precision and rounding, regardless of what the number was initiated to: py> from decimal import * py> setcontext(Context(prec=5)) py> d = Decimal("12.34567890") py> print(d, +d) 12.34567890 12.346 Counter uses it to strip zero and negative counts: py> from collections import Counter py> d = Counter(a=3, b=-3) py> print(d) Counter({'a': 3, 'b': -3}) py> print(+d) Counter({'a': 3}) I would expect that symbolic maths software like Sympy probably has use of a unary plus operator, but I'm not sure. It's probably too late now, but if I had designed the Fraction class, I would have made it inherit from a pure Rational class that didn't automatically normalise (there are interesting operations that rely on distinguishing fractions like 1/2 and 2/4), and have + perform normalisation: x = Rational(2, 4) print(x, +x) => prints 2/4 1/2 Likewise one might use unary plus to normalise polar or cylindrical coordinates, etc. I might consider stealing an idea from Perl and Javascript, and have unary plus convert strings to a number: +"123" => returns int 123 +"1.23" => returns float 1.23 -- Steven From steve at pearwood.info Sat Nov 14 01:05:43 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Nov 2015 17:05:43 +1100 Subject: find which Python libraries are most influential in scientific research References: <06e7d84d-7e49-4160-b42e-a6911640d9e8@googlegroups.com> Message-ID: <5646cf39$0$1610$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Nov 2015 02:58 pm, Ian Kelly wrote: > FYI, the depsy.org site is completely unusable on my Android phone. On Firefox under Linux, the page comes up blank. If I use the NoScript plugin to allow Javascript from the despy.org site, the page now takes twice as long to load, and still comes up blank. If I then tell NoScript to allow Javascript from angular-io.github.io, it eventually loads an extremely garish, multi-coloured page with no dynamic content. As far as I can see, everything is static text and links, with a very few GIANT icons, which makes the dependency on Javascript *completely* unnecessary and quite obnoxious. For the record, the page contains just under 350 words, and loading it requires 21 web requests for 947.40 KB of data, or equivalent to approximately 2700 bytes per word. Between the difficulty of getting the page to display, and the unfortunate look of the page once it actually does (it looks like it was designed for an audience of five year olds, with brightly coloured purple, red, blue, green, yellow backgrounds and giant-sized text), I wouldn't be in a rush to explore the project any further. I wish the authors good luck with the project, but they're not doing themselves (or us) any favours with the design of the webpage. -- Steven From lac at openend.se Sat Nov 14 02:37:50 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 14 Nov 2015 08:37:50 +0100 Subject: find which Python libraries are most influential in scientific research In-Reply-To: References: <06e7d84d-7e49-4160-b42e-a6911640d9e8@googlegroups.com> Message-ID: <201511140737.tAE7bpC5016573@fido.openend.se> In a message of Sat, 14 Nov 2015 00:38:41 -0500, Terry Reedy writes: >On 11/13/2015 10:58 PM, Ian Kelly wrote: >> On Nov 9, 2015 7:41 PM, "Heather Piwowar" wrote: >>> >>> Today's scientists often turn to Python to run analysis, simulation, and >> other sciency tasks. >>> >>> That makes us wonder: which Python libraries are most influential in >> scientific research? > >Numpy, scipy, ?, ?, ?, ... I'd put money on matplotlib pandas >>> We just released a tool (built in Python, of course) to answer that >> question. It's called Depsy [1], it's funded by the US National Science >> Foundation, and we'd love your comments. >>> >>> For more information, see our blog post [2] and paper [3]. The >> scientific/engineering tag is a great place to start exploring [4]. >>> >>> Heather Piwowar and Jason Priem >>> >>> 1. http://depsy.org >>> 2. http://blog.impactstory.org/introducing-depsy >>> 3. >> https://github.com/Impactstory/depsy-research/blob/master/introducing_depsy.md >>> 4. http://depsy.org/tag/scientific%252Fengineering >> >> FYI, the depsy.org site is completely unusable on my Android phone. > >Ditto Win10, Firefox. Not looking good under FF here with debian unstable and a smallish laptop screen, either. Laura >-- >Terry Jan Reedy From auriocus at gmx.de Sat Nov 14 03:14:09 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 14 Nov 2015 09:14:09 +0100 Subject: More tkinter Madness In-Reply-To: <56465FE2.40701@tundraware.com> References: <708dhc-3pf1.ln1@oceanview.tundraware.com> <0dphhc-ntf.ln1@oceanview.tundraware.com> <56465FE2.40701@tundraware.com> Message-ID: Am 13.11.15 um 23:10 schrieb Tim Daneliuk: > On 11/13/2015 03:30 PM, Christian Gollwitzer wrote: >> Am 13.11.15 um 20:14 schrieb Tim Daneliuk: >>> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote: >>>> Apfelkiste:Sources chris$ >>> >>> Well, I get window and when I do this: >>> >>> pack [button .b -text Hello -command exit] >>> >>> Nothing appears. >> >> No error, nothing? Just to be sure, you haven't closed the empty >> window, that appeared when you typed "wish"? and copied the command >> into the wish prompt? >> >>> tkinter appears borked I have reinstalled once already, will try >>> again >> >> This is using pure Tcl/Tk. If it is not working, reinstall the >> corresponding packages in your distro. tkinter is merely the Python >> interface to those. >> >> Christian > > Yep tcl/tk is the culprit, but reinstalling has not helped. I am still not understanding, what actually happened. Does the wish shell crash, does it simply exit, or hang? Is there no error message? You can try if a different/newer version works for your setup. For example, you could download a copy of a tclkit from here: http://tclkits.rkeene.org/fossil/wiki/Downloads presumably the 8.6.3 version for RHEL5, and try if it runs a script like this # the next line should make an empty window appear package require Tk # this line should create the button in it pack [button .b -text Hello -command exit] If this does work, then installing Tcl/Tk from scratch (i.e. copmiling yourself) might work. (Unfortunately, you cannot make tkinter work with a Tclkit) Christian From cs at zip.com.au Sat Nov 14 03:59:34 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 14 Nov 2015 19:59:34 +1100 Subject: find which Python libraries are most influential in scientific research In-Reply-To: <201511140737.tAE7bpC5016573@fido.openend.se> References: <201511140737.tAE7bpC5016573@fido.openend.se> Message-ID: <20151114085934.GA82128@cskk.homeip.net> On 14Nov2015 08:37, Laura Creighton wrote: >In a message of Sat, 14 Nov 2015 00:38:41 -0500, Terry Reedy writes: >>On 11/13/2015 10:58 PM, Ian Kelly wrote: >>> On Nov 9, 2015 7:41 PM, "Heather Piwowar" wrote: >>>> 4. http://depsy.org/tag/scientific%252Fengineering >>> >>> FYI, the depsy.org site is completely unusable on my Android phone. >> >>Ditto Win10, Firefox. > >Not looking good under FF here with debian unstable and a smallish >laptop screen, either. Ditto FF on Mac OSX. Totally blank. Renders ok on Safari. If I enable several sites' JavaScript it loads in Firefox, but there's nothing on the page that looks like it should need any JavaScript (hmm, some mouseovers but I'm pretty sure that can be mediated entirely in CSS, perhaps less "smoothly"). There does seems to be a nice long list of relevant Python packages listed there though. Cheers, Cameron Simpson From df at see.replyto.invalid Sat Nov 14 04:14:10 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Sat, 14 Nov 2015 09:14:10 +0000 Subject: What is '@' for References: Message-ID: fl wrote: >I read the following code snippet. A question is here about '@'. >I don't find the answer online yet. I recommend this: "Understanding Python Decorators in 12 Easy Steps!" http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ From Cecil at decebal.nl Sat Nov 14 06:51:38 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 14 Nov 2015 12:51:38 +0100 Subject: Trying out Kivy References: <871tbt3lml.fsf@Equus.decebal.nl> <87pozd21nb.fsf@Equus.decebal.nl> <87lha11wz4.fsf@Equus.decebal.nl> Message-ID: <87d1vc23zp.fsf@Equus.decebal.nl> On Friday 13 Nov 2015 21:10 CET, Cecil Westerhof wrote: > On Friday 13 Nov 2015 20:53 CET, Michael Torrie wrote: > >> On 11/13/2015 11:30 AM, Cecil Westerhof wrote: >>> On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote: >>> >>>> On 11/13/2015 09:33 AM, Cecil Westerhof wrote: >>>>> I tried to install pygame and PIL with pip3, but that did not >>>>> find anything. >>>> >>>> The replacement for PIL is called Pillow. I'm not sure if it's a >>>> drop-in replacement or not. If it's not, then you'd have to >>>> modify Kivy to import from Pillow. Pillow does support Python3. >>> >>> After installing Pillow the error about PIL disappeared, but I got >>> new errors about bcm and x11. >> >> Traceback? > > Purge log fired. Analysing... Purge finished! [INFO ] [Logger ] > Record log in /home/cecil/.kivy/logs/kivy_15-11-13_28.txt [INFO ] > [Kivy ] v1.9.0 [INFO ] [Python ] v3.4.1 (default, May 23 2014, > 17:48:28) [GCC] [INFO ] [Factory ] 173 symbols loaded [INFO ] [Image > ] Providers: img_tex, img_dds, img_gif, img_pil (img_pygame, > img_ffpyplayer ignored) [INFO ] [Text ] Provider: > pil(['text_pygame'] ignored) [CRITICAL ] [Window ] Unable to find > any valuable Window provider at all! egl_rpi - ImportError: cannot > import name 'bcm' File > "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, > in core_select_lib fromlist=[modulename], level=0) File > "/usr/lib64/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", > line 12, in from kivy.lib.vidcore_lite import bcm, egl > > pygame - ImportError: No module named 'pygame' File > "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, > in core_select_lib fromlist=[modulename], level=0) File > "/usr/lib64/python3.4/site-packages/kivy/core/window/window_pygame.py", > line 8, in import pygame > > x11 - ImportError: No module named 'kivy.core.window.window_x11' > File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", > line 57, in core_select_lib fromlist=[modulename], level=0) > > [CRITICAL ] [App ] Unable to get a Window, abort. Exception ignored > in: 'kivy.properties.dpi2px' Traceback (most recent call last): File > "/usr/lib64/python3.4/site-packages/kivy/utils.py", line 360, in > __get__ retval = self.func(inst) File > "/usr/lib64/python3.4/site-packages/kivy/metrics.py", line 169, in > dpi EventLoop.ensure_window() File > "/usr/lib64/python3.4/site-packages/kivy/base.py", line 126, in > ensure_window sys.exit(1) SystemExit: 1 [CRITICAL ] [App ] Unable to > get a Window, abort. > > > I see a difference with python2. (Did not notice it before.) With > python3 v1.9.0 is installed, but with python2 v1.8.0. > [INFO ] Kivy v1.8.0 > > Maybe that is the problem? I tried to install v1.8.0 with: pip3 install -I kivy==1.8.0 But that gives: building 'kivy.graphics.shader' extension gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python3.4m -c /tmp/pip_build_root/kivy/kivy/graphics/shader.c -o build/temp.linux-x86_64-3.4/tmp/pip_build_root/kivy/kivy/graphics/shader.o /tmp/pip_build_root/kivy/kivy/graphics/shader.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation. #error Do not use this file, it is the result of a failed Cython compilation. ^ Error compiling Cython file: ------------------------------------------------------------ ... vertex_format.last_shader = self for i in xrange(vertex_format.vattr_count): attr = &vertex_format.vattr[i] if attr.per_vertex == 0: continue attr.index = glGetAttribLocation(self.program, attr.name) ^ ------------------------------------------------------------ kivy/graphics/shader.pyx:448:63: Casting temporary Python object to non-numeric non-Python type error: command 'gcc' failed with exit status 1 ---------------------------------------- Cleaning up... Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/kivy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hvd8j0e_-record/install-rec -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rxjwg98 at gmail.com Sat Nov 14 07:10:33 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 04:10:33 -0800 (PST) Subject: Where is decorator in this example code? Message-ID: <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> Hi, I am learning decorator following this link: http://thecodeship.com/patterns/guide-to-python-function-decorators/ When I read decorator on class, I don't see decorator taking in effect. In the following code snippet, there is the same print out if I comment out two lines 'def p_decorate(func):' and '@p_decorate'. Can you tell me what role of decorator in this code? Thanks, ...... def p_decorate(func): def func_wrapper(self): return "

{0}

".format(func(self)) return func_wrapper class Person(object): def __init__(self): self.name = "John" self.family = "Doe" @p_decorate def get_fullname(self): return self.name+" "+self.family my_person = Person() print my_person.get_fullname() From rxjwg98 at gmail.com Sat Nov 14 07:13:19 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 04:13:19 -0800 (PST) Subject: Where is decorator in this example code? In-Reply-To: <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> References: <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> Message-ID: On Saturday, November 14, 2015 at 7:11:11 AM UTC-5, fl wrote: > Hi, > > I am learning decorator following this link: > > http://thecodeship.com/patterns/guide-to-python-function-decorators/ > > When I read decorator on class, I don't see decorator taking in effect. > In the following code snippet, there is the same print out if I comment out > two lines 'def p_decorate(func):' and '@p_decorate'. > > Can you tell me what role of decorator in this code? > > > Thanks, > > ...... > def p_decorate(func): > def func_wrapper(self): > return "

{0}

".format(func(self)) > return func_wrapper > > class Person(object): > def __init__(self): > self.name = "John" > self.family = "Doe" > > @p_decorate > def get_fullname(self): > return self.name+" "+self.family > > my_person = Person() > print my_person.get_fullname() My OP may not be clear enough. Here is the key question. After the function definition, there is no obvious decorator application in the function call: my_person = Person() print my_person.get_fullname() Where is the difference between the non-decorator and decorator in this example? Thanks, From kwpolska at gmail.com Sat Nov 14 07:37:44 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sat, 14 Nov 2015 13:37:44 +0100 Subject: Where is decorator in this example code? In-Reply-To: References: <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> Message-ID: On 14 November 2015 at 13:13, fl wrote: > On Saturday, November 14, 2015 at 7:11:11 AM UTC-5, fl wrote: >> Hi, >> >> I am learning decorator following this link: >> >> http://thecodeship.com/patterns/guide-to-python-function-decorators/ >> >> When I read decorator on class, I don't see decorator taking in effect. >> In the following code snippet, there is the same print out if I comment out >> two lines 'def p_decorate(func):' and '@p_decorate'. >> >> Can you tell me what role of decorator in this code? [snip code] > > My OP may not be clear enough. Here is the key question. After the function > definition, there is no obvious decorator application in the function call: > > my_person = Person() > print my_person.get_fullname() > > Where is the difference between the non-decorator and decorator in this > example? > > Thanks, > -- > https://mail.python.org/mailman/listinfo/python-list Have you tried executing the code with and without the decorator? $ python2 without-decorator.py John Doe $ python2 with-decorator.py

John Doe

Basically, the decorator wraps the output of your get_fullname function with HTML

tags. (Running code examples is a great way to understand them.) -- Chris Warrick PGP: 5EAAEA16 From wabayang at gmail.com Sat Nov 14 07:42:57 2015 From: wabayang at gmail.com (bayang) Date: Sat, 14 Nov 2015 13:42:57 +0100 Subject: Trying out Kivy In-Reply-To: <87d1vc23zp.fsf@Equus.decebal.nl> References: <871tbt3lml.fsf@Equus.decebal.nl> <87pozd21nb.fsf@Equus.decebal.nl> <87lha11wz4.fsf@Equus.decebal.nl> <87d1vc23zp.fsf@Equus.decebal.nl> Message-ID: Le 14 nov. 2015 13:00, "Cecil Westerhof" a ?crit : > > On Friday 13 Nov 2015 21:10 CET, Cecil Westerhof wrote: > > > On Friday 13 Nov 2015 20:53 CET, Michael Torrie wrote: > > > >> On 11/13/2015 11:30 AM, Cecil Westerhof wrote: > >>> On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote: > >>> > >>>> On 11/13/2015 09:33 AM, Cecil Westerhof wrote: > >>>>> I tried to install pygame and PIL with pip3, but that did not > >>>>> find anything. > >>>> > >>>> The replacement for PIL is called Pillow. I'm not sure if it's a > >>>> drop-in replacement or not. If it's not, then you'd have to > >>>> modify Kivy to import from Pillow. Pillow does support Python3. > >>> > >>> After installing Pillow the error about PIL disappeared, but I got > >>> new errors about bcm and x11. > >> > >> Traceback? > > > > Purge log fired. Analysing... Purge finished! [INFO ] [Logger ] > > Record log in /home/cecil/.kivy/logs/kivy_15-11-13_28.txt [INFO ] > > [Kivy ] v1.9.0 [INFO ] [Python ] v3.4.1 (default, May 23 2014, > > 17:48:28) [GCC] [INFO ] [Factory ] 173 symbols loaded [INFO ] [Image > > ] Providers: img_tex, img_dds, img_gif, img_pil (img_pygame, > > img_ffpyplayer ignored) [INFO ] [Text ] Provider: > > pil(['text_pygame'] ignored) [CRITICAL ] [Window ] Unable to find > > any valuable Window provider at all! egl_rpi - ImportError: cannot > > import name 'bcm' File > > "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, > > in core_select_lib fromlist=[modulename], level=0) File > > "/usr/lib64/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", > > line 12, in from kivy.lib.vidcore_lite import bcm, egl > > > > pygame - ImportError: No module named 'pygame' File > > "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, > > in core_select_lib fromlist=[modulename], level=0) File > > "/usr/lib64/python3.4/site-packages/kivy/core/window/window_pygame.py", > > line 8, in import pygame > > > > x11 - ImportError: No module named 'kivy.core.window.window_x11' > > File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", > > line 57, in core_select_lib fromlist=[modulename], level=0) > > > > [CRITICAL ] [App ] Unable to get a Window, abort. Exception ignored > > in: 'kivy.properties.dpi2px' Traceback (most recent call last): File > > "/usr/lib64/python3.4/site-packages/kivy/utils.py", line 360, in > > __get__ retval = self.func(inst) File > > "/usr/lib64/python3.4/site-packages/kivy/metrics.py", line 169, in > > dpi EventLoop.ensure_window() File > > "/usr/lib64/python3.4/site-packages/kivy/base.py", line 126, in > > ensure_window sys.exit(1) SystemExit: 1 [CRITICAL ] [App ] Unable to > > get a Window, abort. > > > > > > I see a difference with python2. (Did not notice it before.) With > > python3 v1.9.0 is installed, but with python2 v1.8.0. > > [INFO ] Kivy v1.8.0 > > > > Maybe that is the problem? > > I tried to install v1.8.0 with: > pip3 install -I kivy==1.8.0 > > But that gives: > building 'kivy.graphics.shader' extension > > gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python3.4m -c /tmp/pip_build_root/kivy/kivy/graphics/shader.c -o build/temp.linux-x86_64-3.4/tmp/pip_build_root/kivy/kivy/graphics/shader.o > > /tmp/pip_build_root/kivy/kivy/graphics/shader.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation. > > #error Do not use this file, it is the result of a failed Cython compilation. > > ^ > > > > Error compiling Cython file: > > ------------------------------------------------------------ > > ... > > vertex_format.last_shader = self > > for i in xrange(vertex_format.vattr_count): > > attr = &vertex_format.vattr[i] > > if attr.per_vertex == 0: > > continue > > attr.index = glGetAttribLocation(self.program, attr.name) > > ^ > > ------------------------------------------------------------ > > > > kivy/graphics/shader.pyx:448:63: Casting temporary Python object to non-numeric non-Python type > > error: command 'gcc' failed with exit status 1 > > ---------------------------------------- > Cleaning up... > Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/kivy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hvd8j0e_-record/install-rec > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof > -- > https://mail.python.org/mailman/listinfo/python-list The latest cython version is for kivy 1.9. For kivy 1.8 you must use an older cython version. Check kivy website. That's why you get compiling errors From johnzzhao at gmail.com Sat Nov 14 09:26:29 2015 From: johnzzhao at gmail.com (John Zhao) Date: Sat, 14 Nov 2015 06:26:29 -0800 (PST) Subject: Persist objects in a LIST Message-ID: <0cb1bcda-54d5-4cc7-bd23-f86f7f10ee28@googlegroups.com> I am new to Python, and just learned that Python list is just a container of object reference. In the example below, bDict needs to be just a temporary object, constructed at run time and then be added to aList. At the end, aList will contain n objects. Is there a clean way to do that? Many thanks, John $ ipython WARNING: IPython History requires SQLite, your history will not be saved WARNING: Readline services not available or not loaded. WARNING: The auto-indent feature requires the readline library Python 2.7.9 (default, Sep 5 2015, 07:20:36) Type "copyright", "credits" or "license" for more information. IPython 4.0.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: aList = [] In [2]: bDict = {} In [3]: bDict['instance_name']='SERVER_TIER' In [4]: aList.append(bDict) In [5]: print aList [{'instance_name': 'SERVER_TIER'}] In [6]: bDict.clear() In [7]: print aList [{}] From rxjwg98 at gmail.com Sat Nov 14 09:46:16 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 06:46:16 -0800 (PST) Subject: Where is decorator in this example code? In-Reply-To: References: <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> Message-ID: On Saturday, November 14, 2015 at 7:38:09 AM UTC-5, Chris Warrick wrote: > On 14 November 2015 at 13:13, fl wrote: > > On Saturday, November 14, 2015 at 7:11:11 AM UTC-5, fl wrote: > >> Hi, > >> > >> I am learning decorator following this link: > >> > >> http://thecodeship.com/patterns/guide-to-python-function-decorators/ > >> > >> When I read decorator on class, I don't see decorator taking in effect. > >> In the following code snippet, there is the same print out if I comment out > >> two lines 'def p_decorate(func):' and '@p_decorate'. > >> > >> Can you tell me what role of decorator in this code? > [snip code] > > > > My OP may not be clear enough. Here is the key question. After the function > > definition, there is no obvious decorator application in the function call: > > > > my_person = Person() > > print my_person.get_fullname() > > > > Where is the difference between the non-decorator and decorator in this > > example? > > > > Thanks, > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Have you tried executing the code with and without the decorator? > > $ python2 without-decorator.py > John Doe > $ python2 with-decorator.py >

John Doe

> > Basically, the decorator wraps the output of your get_fullname > function with HTML

tags. > > (Running code examples is a great way to understand them.) > > -- > Chris Warrick > PGP: 5EAAEA16 Thanks. I did run the code, but I did not check the difference carefully between them. A following problem now is about the args in class decorate. I do not see args and kwargs are transferred by get_fullname(self). If I change return "

{0}

".format(func(*args, **kwargs)) to return "

{0}

".format(func(*args)) The outputs are the same. But it is quite different if it is changed to: return "

{0}

".format(func) What roles are args and kwargs? I know C language. For Python here, I don't see some rules on the args. Thanks again. ///////////// def p_decorate(func): def func_wrapper(*args, **kwargs): return "

{0}

".format(func(*args, **kwargs)) return func_wrapper class Person(object): def __init__(self): self.name = "John" self.family = "Doe" @p_decorate def get_fullname(self): return self.name+" "+self.family my_person = Person() print my_person.get_fullname() From antoon.pardon at rece.vub.ac.be Sat Nov 14 10:02:00 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 14 Nov 2015 16:02:00 +0100 Subject: Question about math.pi is mutable In-Reply-To: <5646A673.2060201@gmail.com> References: <857flujwy7.fsf@benfinney.id.au> <5640B28C.6050408@rece.vub.ac.be> <858u66g39k.fsf@benfinney.id.au> <5641C0EC.8010905@rece.vub.ac.be> <5646A673.2060201@gmail.com> Message-ID: <56474CE8.7020908@rece.vub.ac.be> Op 14-11-15 om 04:11 schreef Michael Torrie: > On 11/10/2015 03:03 AM, Antoon Pardon wrote: >> Op 10-11-15 om 00:29 schreef Ben Finney: >>> >>> Who is doing what to whom? The user of the library isn't doing anything >>> to the library author, so what is it the library author would consent >>> to? Instead, you seem to be trying to assert a *power* of the library >>> author to restrict the library user. Such a power is not granted by >>> Python. >> >> Python is not at liberty to grant or deny such a power. Python is just >> a vehicle in which code is written. The author of a library can restrict >> its use anyway he sees fit. > > No he cannot, outside the bounds of copyright law. Why would you think > otherwise? The only document that binds the end user in any way is the > copyright license, unless some other formal contract has been arranged. You haven't contradicted me in any way. What you are talking about here is in what form those restrictions must be published. I am talking about the restrictions the author can put in a license. -- Antoon Pardon From johnzzhao at gmail.com Sat Nov 14 10:02:41 2015 From: johnzzhao at gmail.com (John Zhao) Date: Sat, 14 Nov 2015 07:02:41 -0800 (PST) Subject: Persist objects in a LIST In-Reply-To: <0cb1bcda-54d5-4cc7-bd23-f86f7f10ee28@googlegroups.com> References: <0cb1bcda-54d5-4cc7-bd23-f86f7f10ee28@googlegroups.com> Message-ID: <15f9fdeb-f4b4-4404-bccb-2e67a26035ed@googlegroups.com> I found a solution. replace bDict.clear() with bDict = {} thanks, John From ian.g.kelly at gmail.com Sat Nov 14 10:43:13 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 Nov 2015 08:43:13 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 13, 2015 at 10:40 PM, Steven D'Aprano wrote: > Python has operator overloading, so it can be anything you want it to be. > E.g. you might have a DSL where +feature turns something on and -feature > turns it off. By that argument we should also have operators ~, !, $, \, ? because some hypothetical DSL might someday want to use them for something. > Decimal uses it to force the current precision and rounding, regardless of > what the number was initiated to: > > Counter uses it to strip zero and negative counts: > > I would expect that symbolic maths software like Sympy probably has use of a > unary plus operator, but I'm not sure. Unary plus as normalization does not strike me as being very intuitive. I never would have known about any of these if I hadn't read the Counter case in the docs, and then I only remembered it because it because it seemed janky. Unary minus on Counters is even weirder, by the way: it first negates the signs of all the values, and *then* normalizes by removing non-positive values. Who has ever needed that? For somebody reading one of these uses of unary plus in real code, I imagine it would be a bit of a WTF moment if it's the first time they've encountered it. I don't recall ever seeing any code that actually used this, though. > I might consider stealing an idea from Perl and Javascript, and have unary > plus convert strings to a number: > > +"123" > => returns int 123 > +"1.23" > => returns float 1.23 Eww. From torriem at gmail.com Sat Nov 14 10:43:30 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 14 Nov 2015 08:43:30 -0700 Subject: Trying out Kivy In-Reply-To: <87d1vc23zp.fsf@Equus.decebal.nl> References: <871tbt3lml.fsf@Equus.decebal.nl> <87pozd21nb.fsf@Equus.decebal.nl> <87lha11wz4.fsf@Equus.decebal.nl> <87d1vc23zp.fsf@Equus.decebal.nl> Message-ID: <564756A2.2080609@gmail.com> On 11/14/2015 04:51 AM, Cecil Westerhof wrote: > I tried to install v1.8.0 with: > pip3 install -I kivy==1.8.0 Why are you trying to install the non-current version of kivy? Did you install pygame successfully? From ian.g.kelly at gmail.com Sat Nov 14 11:08:33 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 Nov 2015 09:08:33 -0700 Subject: Where is decorator in this example code? In-Reply-To: References: <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> Message-ID: On Sat, Nov 14, 2015 at 7:46 AM, fl wrote: > A following problem now is about the args in class decorate. I do not see > args and kwargs are transferred by get_fullname(self). > > > If I change > > return "

{0}

".format(func(*args, **kwargs)) > > to > > return "

{0}

".format(func(*args)) > > The outputs are the same. > > But it is quite different if it is changed to: > > return "

{0}

".format(func) In this case you're not even calling the function, so the thing that you're formatting in the string is the function object itself. > What roles are args and kwargs? I know C language. > For Python here, I don't see some rules on the args. They are Python's version of "varargs" or variadic arguments. If a function parameter declaration is prefixed with *, then that parameter will collect all the remaining positional arguments. For example, with the function declaration "def f(a, b, *c):", f may be called with two or more arguments. The first two arguments will be assigned to a and b, and c will be a tuple containing all the remaining arguments. It is customary but not necessary to name this parameter "args". You can also do the inverse when calling a function. If x is a list or tuple, then calling f(x) will pass the sequence x to f as a single argument, while calling f(*x) will pass the contents of x as individual arguments. Similarly, if a function parameter declaration is prefixed with **, then that parameter will collect all the keyword arguments that have not been assigned to other parameters, in a dict. It is customary but not necessary to name this parameter "kwargs". And again you can also do the inverse when calling a function: if x is a dict, then calling f(x) will pass along the dict as a single argument, while calling f(**x) will pass the contents of the dict as individual keyword arguments. So if you have a function like this: def f(*args, **kwargs): return g(*args, **kwargs) This collects all the arguments that were passed to f, and passes them along to g in the same manner they were supplied to f. In your example, removing **kwargs appeared to do nothing because no keyword arguments were actually passed in. From vincent.vande.vyvre at telenet.be Sat Nov 14 11:33:59 2015 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sat, 14 Nov 2015 17:33:59 +0100 Subject: Persist objects in a LIST In-Reply-To: References: <0cb1bcda-54d5-4cc7-bd23-f86f7f10ee28@googlegroups.com> <15f9fdeb-f4b4-4404-bccb-2e67a26035ed@googlegroups.com> Message-ID: <56476277.9010605@telenet.be> Le 14/11/2015 16:39, Dennis Lee Bieber a ?crit : > On Sat, 14 Nov 2015 07:02:41 -0800 (PST), John Zhao > declaimed the following: > >> I found a solution. replace bDict.clear() with bDict = {} >> > Which is creating a second, empty, dictionary and binding the name > "bDict" to that new one. > > If all you want is to get rid of the name > > del bDict > > should suffice. Not exactly. >>> l = [] >>> d = {'key': 'val'} >>> l.append(d) >>> l [{'key': 'val'}] >>> del d >>> l [{'key': 'val'}] >>> del l[0] >>> l [] >>> Vince From marko at pacujo.net Sat Nov 14 11:52:56 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Nov 2015 18:52:56 +0200 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vb94ikuv.fsf@elektro.pacujo.net> Ian Kelly : > For somebody reading one of these uses of unary plus in real code, I > imagine it would be a bit of a WTF moment if it's the first time > they've encountered it. I don't recall ever seeing any code that > actually used this, though. What I don't understand is why there is a unary + but no unary /: -x ? 0 - x +x ? 0 + x /x ? 1 / x //x ? 1 // x *x ? 1 * x You could write: r = //(//r1 + //r2 + //r3) for r = 1 // (1//r1 + 1//r2 + 1//r3) Actually, the real question is, is the unary - *really* so useful that it merits existence or is it just something that was mindlessly copied into programming languages from elementary school arithmetics? BTW, Scheme's got the whole set: (- 3) => -3 (- 3 2) => 1 (- 3 2 1) => 0 (/ 3) => 1/3 (* 3) => 3 (*) => 1 However, there's a tricky discontinuity: (apply - 3 '(2 1)) => 0 (apply - 3 '(2)) => 1 (apply - 3 '()) => -3 Marko From rosuav at gmail.com Sat Nov 14 11:59:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Nov 2015 03:59:57 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Nov 15, 2015 at 2:43 AM, Ian Kelly wrote: > On Fri, Nov 13, 2015 at 10:40 PM, Steven D'Aprano wrote: >> Python has operator overloading, so it can be anything you want it to be. >> E.g. you might have a DSL where +feature turns something on and -feature >> turns it off. > > By that argument we should also have operators ~, !, $, \, ? because > some hypothetical DSL might someday want to use them for something. Unary tilde does, doing bitwise negation on integers. Backslash probably never will, due to confusion with line continuation and stuff. But let's look at the parallel-universe Python in which unary plus never existed (but unary minus did). The PEP preamble for its inclusion says: Abstract This PEP proposes a new unary version of the binary + operator. Specification A new unary operator is added to the Python language: ======= ========================= =========== Op Precedence/associativity Method ======= ========================= =========== ``+`` Same as unary ``-`` ``__pos__`` ======= ========================= =========== No implementations of this methods is added to the builtin or standard library types. However, we foresee that Domain-Specific Languages can make use of this parallel to unary minus; see Intended usage details below for details. Okay. I've done my bit, stealing text from PEP 465. Now Steven, you can write the Motivation section. There's a lot of similarities here (Python's built-in types do not need @ or unary + for anything), but the big push for 465 was that there have been calls for the new operator for years. So... where would the "please add unary plus" calls come from? ChrisA From rosuav at gmail.com Sat Nov 14 12:04:18 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Nov 2015 04:04:18 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <87vb94ikuv.fsf@elektro.pacujo.net> References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: On Sun, Nov 15, 2015 at 3:52 AM, Marko Rauhamaa wrote: > What I don't understand is why there is a unary + but no unary /: > > -x ? 0 - x > +x ? 0 + x > /x ? 1 / x > //x ? 1 // x > *x ? 1 * x > > You could write: > > r = //(//r1 + //r2 + //r3) > > for > > r = 1 // (1//r1 + 1//r2 + 1//r3) Small problem: Since we have / and // operators, it's impossible to have a unary / operator: 1 // x 1 / (/x) But leaving that aside, the number of times you'd want this are far fewer than the times you want unary minus. > Actually, the real question is, is the unary - *really* so useful that > it merits existence or is it just something that was mindlessly copied > into programming languages from elementary school arithmetics? More likely, copied from C. But that's why I made my other post. ChrisA From ian.g.kelly at gmail.com Sat Nov 14 12:04:36 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 Nov 2015 10:04:36 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <87vb94ikuv.fsf@elektro.pacujo.net> References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: On Nov 14, 2015 9:56 AM, "Marko Rauhamaa" wrote: > > Ian Kelly : > > > For somebody reading one of these uses of unary plus in real code, I > > imagine it would be a bit of a WTF moment if it's the first time > > they've encountered it. I don't recall ever seeing any code that > > actually used this, though. > > What I don't understand is why there is a unary + but no unary /: > > -x ? 0 - x > +x ? 0 + x > /x ? 1 / x > //x ? 1 // x > *x ? 1 * x > > You could write: > > r = //(//r1 + //r2 + //r3) > > for > > r = 1 // (1//r1 + 1//r2 + 1//r3) Unary integer division seems pretty silly since the only possible results would be 0, 1 or -1. From ian.g.kelly at gmail.com Sat Nov 14 12:13:18 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 Nov 2015 10:13:18 -0700 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: On Nov 14, 2015 10:10 AM, "Chris Angelico" wrote: > > On Sun, Nov 15, 2015 at 4:04 AM, Ian Kelly wrote: > > Unary integer division seems pretty silly since the only possible results > > would be 0, 1 or -1. > > 1, -1, or ZeroDivisionError. The zero's on the other side. But yes. // 42 == 1 // 42 == 0 From rxjwg98 at gmail.com Sat Nov 14 12:23:33 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 09:23:33 -0800 (PST) Subject: What is wrong this wrapper (decorator)? Message-ID: Hi, I follow a tutorial to learn decorator: http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ I use Enthought Canopy to run the following code. It is really strange that the wrapper does not take effect. In fact, I go back to the basic way (not with @): wrapper(sub(two, one)) Out[38]: When I use the non-wrapper mode, it has Coord print out. If I use wrapper, it has nothing to print out. Due to no debug mode help, I don't see anything wrong yet. (add(two, one)) # nothing print out (sub(two, three)) Out[43]: Coord:-- {'y': 300, 'x': 400} # correct is here Anyone can help? Thanks, ............ class Coordinate(object): def __init__(self, y, x): self.y = y self.x = x def __repr__(self): return "Coord:-- " + str(self.__dict__) def add(a, b): return Coordinate(a.x + b.x, a.y + b.y) def sub(a, b): return Coordinate(a.x - b.x, a.y - b.y) def wrapper(func): def checker(a, b): # 1 if a.x < 0 or a.y < 0: a = Coordinate(a.x if a.x > 0 else 0, a.y if a.y > 0 else 0) if b.x < 0 or b.y < 0: b = Coordinate(b.x if b.x > 0 else 0, b.y if b.y > 0 else 0) ret = func(a, b) if ret.x < 0 or ret.y < 0: ret = Coordinate(ret.x if ret.x > 0 else 0, ret.y if ret.y > 0 else 0) return ret return checker one = Coordinate(100, 200) two = Coordinate(300, 200) three = Coordinate(-100, -100) add = wrapper(add) #sub = wrapper(sub) From rxjwg98 at gmail.com Sat Nov 14 12:29:31 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 09:29:31 -0800 (PST) Subject: What is wrong this wrapper (decorator)? In-Reply-To: References: Message-ID: On Saturday, November 14, 2015 at 12:23:50 PM UTC-5, fl wrote: > Hi, > > I follow a tutorial to learn decorator: > > http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ > > I use Enthought Canopy to run the following code. > It is really strange that the wrapper does not take effect. > In fact, I go back to the basic way (not with @): > > wrapper(sub(two, one)) > Out[38]: > > > When I use the non-wrapper mode, it has Coord print out. > If I use wrapper, it has nothing to print out. > Due to no debug mode help, I don't see anything wrong yet. > > > (add(two, one)) > # nothing print out > (sub(two, three)) > Out[43]: Coord:-- {'y': 300, 'x': 400} # correct is here > > > Anyone can help? > Thanks, > > > > ............ > class Coordinate(object): > def __init__(self, y, x): > self.y = y > self.x = x > def __repr__(self): > return "Coord:-- " + str(self.__dict__) > > def add(a, b): > return Coordinate(a.x + b.x, a.y + b.y) > > def sub(a, b): > return Coordinate(a.x - b.x, a.y - b.y) > > def wrapper(func): > def checker(a, b): # 1 > if a.x < 0 or a.y < 0: > a = Coordinate(a.x if a.x > 0 else 0, a.y if a.y > 0 else 0) > if b.x < 0 or b.y < 0: > b = Coordinate(b.x if b.x > 0 else 0, b.y if b.y > 0 else 0) > ret = func(a, b) > if ret.x < 0 or ret.y < 0: > ret = Coordinate(ret.x if ret.x > 0 else 0, ret.y if ret.y > 0 else 0) > return ret > return checker > > one = Coordinate(100, 200) > two = Coordinate(300, 200) > three = Coordinate(-100, -100) > > add = wrapper(add) > #sub = wrapper(sub) Excuse me. I just realize that the indent made the logic incorrect. It is different from other language. Thanks. From gengyangcai at gmail.com Sat Nov 14 12:34:22 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 14 Nov 2015 09:34:22 -0800 (PST) Subject: A Program that prints the numbers from 1 to 100 Message-ID: I want to write a program in Python that does this ---- "Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz"." How do I go about doing it ? From joel.goldstick at gmail.com Sat Nov 14 12:49:51 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 14 Nov 2015 12:49:51 -0500 Subject: A Program that prints the numbers from 1 to 100 In-Reply-To: References: Message-ID: On Sat, Nov 14, 2015 at 12:34 PM, Cai Gengyang wrote: > I want to write a program in Python that does this ---- > > "Write a program that prints the numbers from 1 to 100. But for multiples > of three print "Fizz" instead of the number and for the multiples of five > print "Buzz". For numbers which are multiples of both three and five print > "FizzBuzz"." > > How do I go about doing it ? > -- > https://mail.python.org/mailman/listinfo/python-list > You could google fizzbuzz and find lots of solutions. But, to give you a hint, use a for loop with range to get the numbers, use if n % 3 and n % 5 to pick out 3 and 5 multiples, print accordingly -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From bc at freeuk.com Sat Nov 14 13:18:18 2015 From: bc at freeuk.com (BartC) Date: Sat, 14 Nov 2015 18:18:18 +0000 Subject: A Program that prints the numbers from 1 to 100 In-Reply-To: References: Message-ID: On 14/11/2015 17:34, Cai Gengyang wrote: > I want to write a program in Python that does this ---- > > "Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz"." > > How do I go about doing it ? Here's one way, although you're probably expected to use a loop: print (1) print (2) print ("Fizz") print (4) print ("Buzz") print ("Fizz") print (7) print (8) print ("Fizz") print ("Buzz") print (11) print ("Fizz") print (13) print (14) print ("FizzBuzz") print (16) print (17) print ("Fizz") print (19) print ("Buzz") print ("Fizz") print (22) print (23) print ("Fizz") print ("Buzz") print (26) print ("Fizz") print (28) print (29) print ("FizzBuzz") print (31) print (32) print ("Fizz") print (34) print ("Buzz") print ("Fizz") print (37) print (38) print ("Fizz") print ("Buzz") print (41) print ("Fizz") print (43) print (44) print ("FizzBuzz") print (46) print (47) print ("Fizz") print (49) print ("Buzz") print ("Fizz") print (52) print (53) print ("Fizz") print ("Buzz") print (56) print ("Fizz") print (58) print (59) print ("FizzBuzz") print (61) print (62) print ("Fizz") print (64) print ("Buzz") print ("Fizz") print (67) print (68) print ("Fizz") print ("Buzz") print (71) print ("Fizz") print (73) print (74) print ("FizzBuzz") print (76) print (77) print ("Fizz") print (79) print ("Buzz") print ("Fizz") print (82) print (83) print ("Fizz") print ("Buzz") print (86) print ("Fizz") print (88) print (89) print ("FizzBuzz") print (91) print (92) print ("Fizz") print (94) print ("Buzz") print ("Fizz") print (97) print (98) print ("Fizz") print ("Buzz") -- Bartc From breamoreboy at yahoo.co.uk Sat Nov 14 13:25:04 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Nov 2015 18:25:04 +0000 Subject: A Program that prints the numbers from 1 to 100 In-Reply-To: References: Message-ID: On 14/11/2015 17:34, Cai Gengyang wrote: > I want to write a program in Python that does this ---- > > "Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz"." > > How do I go about doing it ? > This homework problem has been asked repeatedly over the years. Just use your favourite search engine and there will be numerous answers. However if you actually want to learn you'll have to try writing your own code at some point, so see https://docs.python.org/3/library/functions.html#func-range and https://docs.python.org/3/library/stdtypes.html#index-14 operation "x % y". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rxjwg98 at gmail.com Sat Nov 14 15:00:22 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 12:00:22 -0800 (PST) Subject: What is the right way to import a package? Message-ID: <8e325d88-6ad1-46e3-a1fb-ef8c28dc50a8@googlegroups.com> Hi, I want to use a code snippet found on-line. It has such content: from numpy import * dt = 0.1 # Initialization of state matrices X = array([[0.0], [0.0], [0.1], [0.1]]) # Measurement matrices Y = array([[X[0,0] + abs(randn(1)[0])], [X[1,0] + abs(randn(1)[0])]]) When the above content is inside a .py document and running, there will be an error: ---> 15 Y = array([[X[0,0] + abs(randn(1)[0])], [X[1,0] + abs(randn(1)[0])]]) 16 #Y = ([[X[0,0]], [X[1,0] + 0]]) NameError: name 'randn' is not defined But when I run the above line by line at the console (Canopy), there will be no error for the above line. My question is: The import and the following are wrong. X = array([[0.0], [0.0], [0.1], [0.1]]) It should be: import numpy as np ... Y = np.array([[X[0,0] + abs(np.randn(1)[0])], [X[1,0] + abs(np.randn(1)[0])]]) This looks like the code I once saw. But the file when running has such error: ---> 15 Y = np.array([[X[0,0] + abs(np.randn(1)[0])], [X[1,0] + abs(np.randn(1)[0])]]) AttributeError: 'module' object has no attribute 'randn' When it is run line by line at the console, it has the same error. It is strange that the same content has errors depends on inside a file, or at CLI console. What is missing I don't realize? Thanks, From marko at pacujo.net Sat Nov 14 16:53:36 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Nov 2015 23:53:36 +0200 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: <87a8qgi6xr.fsf@elektro.pacujo.net> Ian Kelly : > On Nov 14, 2015 9:56 AM, "Marko Rauhamaa" wrote: >> r = //(//r1 + //r2 + //r3) > > Unary integer division seems pretty silly since the only possible > results would be 0, 1 or -1. Yep, mixed them up. Marko From auriocus at gmx.de Sat Nov 14 16:59:11 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 14 Nov 2015 22:59:11 +0100 Subject: What is the right way to import a package? In-Reply-To: <8e325d88-6ad1-46e3-a1fb-ef8c28dc50a8@googlegroups.com> References: <8e325d88-6ad1-46e3-a1fb-ef8c28dc50a8@googlegroups.com> Message-ID: Am 14.11.15 um 21:00 schrieb fl: > from numpy import * > dt = 0.1 > # Initialization of state matrices > X = array([[0.0], [0.0], [0.1], [0.1]]) > > # Measurement matrices > Y = array([[X[0,0] + abs(randn(1)[0])], [X[1,0] + abs(randn(1)[0])]]) > > When the above content is inside a .py document and running, there will be > an error: > > ---> 15 Y = array([[X[0,0] + abs(randn(1)[0])], [X[1,0] + abs(randn(1)[0])]]) > 16 #Y = ([[X[0,0]], [X[1,0] + 0]]) > > NameError: name 'randn' is not defined > > But when I run the above line by line at the console (Canopy), there will be > no error for the above line. Maybe Canopy is doing a from pylab import * for you? Christian From random832 at fastmail.com Sat Nov 14 17:53:54 2015 From: random832 at fastmail.com (Random832) Date: Sat, 14 Nov 2015 17:53:54 -0500 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Actually, the real question is, is the unary - *really* so useful that > it merits existence or is it just something that was mindlessly copied > into programming languages from elementary school arithmetics? The alternative, if you want to be able to specify negative numbers at all, is to put - in the literal syntax. So what's "x-1"? I suppose you could use some *different* symbol in the literal syntax for negative numbers. I had a calculator once that used a different symbol (looked like a small superscript minus sign) for it. But Python is limited to ASCII for basic syntax elements for good reasons. From marko at pacujo.net Sat Nov 14 19:12:28 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Nov 2015 02:12:28 +0200 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: <876114i0ib.fsf@elektro.pacujo.net> Random832 : > Marko Rauhamaa writes: >> Actually, the real question is, is the unary - *really* so useful >> that it merits existence or is it just something that was mindlessly >> copied into programming languages from elementary school arithmetics? > > The alternative, if you want to be able to specify negative numbers at > all, is to put - in the literal syntax. So what's "x-1"? Yes, it would have to be part of the literal syntax. Or, you could do without! >>> 7 - 8 (0-1) After all, we already have: >>> 1 + 3j (1+3j) Marko From vjp2.at at at.BioStrategist.dot.dot.com Sat Nov 14 19:35:49 2015 From: vjp2.at at at.BioStrategist.dot.dot.com (vjp2.at at at.BioStrategist.dot.dot.com) Date: Sun, 15 Nov 2015 00:35:49 +0000 (UTC) Subject: Jython standalone References: <56469dee$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: Jython is python in java at jython.org. I tried clicking and double clicking. I does a wait cycle (rotating arrow) then returns to attention. I'm trying to run RDKIT, an app written for jython. THen I realised jython wasn't working at all. I've had same problem with some java jars. I only keep java jars that respond. If they don't respond, I assume they don't work. But now I'm wondering. - = - Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist http://www.panix.com/~vjp2/vasos.htm ---{Nothing herein constitutes advice. Everything fully disclaimed.}--- [Homeland Security means private firearms not lazy obstructive guards] [Urb sprawl confounds terror] [Phooey on GUI: Windows for subprime Bimbos] From python at mrabarnett.plus.com Sat Nov 14 19:49:33 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 15 Nov 2015 00:49:33 +0000 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: <5647D69D.4070406@mrabarnett.plus.com> On 2015-11-14 22:53, Random832 wrote: > Marko Rauhamaa writes: >> Actually, the real question is, is the unary - *really* so useful that >> it merits existence or is it just something that was mindlessly copied >> into programming languages from elementary school arithmetics? > > The alternative, if you want to be able to specify negative numbers at > all, is to put - in the literal syntax. So what's "x-1"? > > I suppose you could use some *different* symbol in the literal syntax > for negative numbers. I had a calculator once that used a different > symbol (looked like a small superscript minus sign) for it. But Python > is limited to ASCII for basic syntax elements for good reasons. > APL uses "?" ('\N{MACRON}'), e.g. "?1". From james at imagewebdesign.co.uk Sat Nov 14 20:00:59 2015 From: james at imagewebdesign.co.uk (james at imagewebdesign.co.uk) Date: Sat, 14 Nov 2015 17:00:59 -0800 (PST) Subject: pygtk beginner script not working Message-ID: <5b6f7b3f-a132-4305-8ab7-a256b9dbf40f@googlegroups.com> Hi guys I'm new to Python so please bare with me :) I'm using python 2.7.10 as advised (more tools apparently over 3.x) Trying to use this script [CODE] #!/usr/bin/env python # example base.py import pygtk pygtk.require('2.0') import gtk class Base: def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.show() def main(self): gtk.main() print __name__ if __name__ == "__main__": base = Base() base.main() [/CODE] But get this error: [i]File "C:\Users\CMDEV\Desktop\Py\pygtk_1.py", line 5, in import pygtk ImportError: No module named pygtk[/i] I've check the install and everything reports its installed right: Here's a grab of the CLI [CODE] C:\Python27>easy_install -U pygtk Searching for pygtk Reading https://pypi.python.org/simple/pygtk/ Reading http://ftp.acc.umu.se/pub/gnome/binaries/win32/pygtk/2.24/ Reading http://www.daa.com.au/~james/pygtk/ Reading http://www.daa.com.au/~james/software/pygtk/ Reading http://www.pygtk.org Reading http://www.pygtk.org/ Best match: pygtk 2.24.0 Processing pygtk-2.24.0-py2.7-win32.egg pygtk 2.24.0 is already the active version in easy-install.pth Installing pygtk_postinstall.py script to C:\Python27\Scripts Installing pygtk_postinstall.pyc script to C:\Python27\Scripts Using c:\python27\lib\site-packages\pygtk-2.24.0-py2.7-win32.egg Processing dependencies for pygtk Finished processing dependencies for pygtk C:\Python27>python C:\Users\CMDEV\Desktop\Py\pygtk_1.py Traceback (most recent call last): File "C:\Users\CMDEV\Desktop\Py\pygtk_1.py", line 5, in import pygtk ImportError: No module named pygtk [/CODE] (not used google groups before to post on so not sure if BB code works here... also there doesn't seem to be a preview button so no idea how this turns out) Cheers From steve at pearwood.info Sat Nov 14 20:14:45 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Nov 2015 12:14:45 +1100 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: <5647dc88$0$1592$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Nov 2015 09:53 am, Random832 wrote: > Marko Rauhamaa writes: >> Actually, the real question is, is the unary - *really* so useful that >> it merits existence or is it just something that was mindlessly copied >> into programming languages from elementary school arithmetics? > > The alternative, if you want to be able to specify negative numbers at > all, is to put - in the literal syntax. So what's "x-1"? > > I suppose you could use some *different* symbol in the literal syntax > for negative numbers. I had a calculator once that used a different > symbol (looked like a small superscript minus sign) for it. But Python > is limited to ASCII for basic syntax elements for good reasons. I have a textbook for Pascal programming which includes a project to write an "arithmetic evaluator". It uses ~ for unary minus and - for binary subtraction, and doesn't include unary plus. The reason was to simplify the parser, so that every symbol had exactly one meaning. So in an alternate universe where Guido was less influenced by C, or where he wasn't as good as writing parsers as the real GvR is, we may have ended up with ~ for unary minus and no unary plus. -- Steven From steve at pearwood.info Sat Nov 14 20:34:46 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Nov 2015 12:34:46 +1100 Subject: Jython standalone References: <56469dee$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5647e139$0$1593$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Nov 2015 11:35 am, vjp2.at at at.BioStrategist.dot.dot.com wrote: > Jython is python in java at jython.org. > > I tried clicking and double clicking. Hi Vanos, I am perfectly aware of what Jython is, what I don't know is what you are "clicking and double-clicking". While we are very smart and will surely be able to help you, we are not mind-readers, and we cannot see what is on your computer. You have to help us to help you. That means you have to be *precise and exact* about what you are doing, not vague. I asked you a set of questions, and you have ignored every single one of them. How do you expect us to know what you are doing? We do not have a magic crystal ball. > I does a wait cycle (rotating arrow) > then returns to attention. I am going to GUESS that you are trying to run the Jython installer that you got from here: http://www.jython.org/downloads.html My GUESS is that you have downloaded the installer to your desktop. Since you haven't told me what operating system you are using, I am going to GUESS that you are using Linux, since that is what I am most familiar with. I assume you are using a desktop manager, right-click on the desktop background and select the command to open a terminal or console. In TDE or KDE 3, that will probably be called "Konsole". Or use the Start menu to open a terminal, the menu could be: Start > System > Terminal or Start > Accessories > Terminal or similar, depending on which desktop manager you are using. (If you are using Windows or OS X, there will be some other way to get a terminal or console, but I don't now it.) At the terminal window, you should see a prompt that looks like $ (dollar sign). At the prompt, type: cd ~/Desktop and then press the Enter key. The space between "cd" and the tilde ~ is important. Now type: java -jar jython_installer-2.7.0.jar and press Enter. Again, spaces between words are important. If everything works correctly, the Jython installer GUI will run, and you can install Jython. But if the installer doesn't run, you will probably get a bunch of error messages printed to the terminal window. COPY and PASTE those error messages, and send them to us here. Don't re-type them, and don't try to summarise. We need to see the EXACT messages. -- Steven From steve at pearwood.info Sat Nov 14 20:39:20 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Nov 2015 12:39:20 +1100 Subject: A Program that prints the numbers from 1 to 100 References: Message-ID: <5647e24a$0$1593$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Nov 2015 04:34 am, Cai Gengyang wrote: > I want to write a program in Python that does this ---- > > "Write a program that prints the numbers from 1 to 100. But for multiples > of three print "Fizz" instead of the number and for the multiples of five > print "Buzz". For numbers which are multiples of both three and five print > "FizzBuzz"." > > How do I go about doing it ? Start by writing a program that prints the numbers from 1 to 100. Hint: # Program to print the numbers from 1 to 10. for i in range(1, 11): print(i) One you get that far, you will need to decide which numbers are multiples of 3, which are multiples of 5, and which are multiples of both 3 and 5. Hint: # Multiples of 7. for i in range(1, 11): print(i) if i % 7 == 0: print("multiple of seven") If you need more help, show us the code you have written. -- Steven From rxjwg98 at gmail.com Sat Nov 14 20:54:48 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 17:54:48 -0800 (PST) Subject: What meaning is of '#!python'? Message-ID: Hi, I see an example Python code has such a line at the file beginning: #!python Is there some meaning about it? Thanks, From rosuav at gmail.com Sat Nov 14 20:58:39 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Nov 2015 12:58:39 +1100 Subject: What meaning is of '#!python'? In-Reply-To: References: Message-ID: On Sun, Nov 15, 2015 at 12:54 PM, fl wrote: > I see an example Python code has such a line at the file beginning: > > #!python > > > Is there some meaning about it? It probably didn't look exactly like that. Please, when you're asking questions, COPY AND PASTE rather than retyping some approximation of what you saw. As it happens, I can tell what you're asking about - it's called a shebang - but I very much doubt that it was exactly what you wrote. ChrisA From steve at pearwood.info Sat Nov 14 21:08:11 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Nov 2015 13:08:11 +1100 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5647e90c$0$1588$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Nov 2015 02:43 am, Ian Kelly wrote: > On Fri, Nov 13, 2015 at 10:40 PM, Steven D'Aprano > wrote: >> Python has operator overloading, so it can be anything you want it to be. >> E.g. you might have a DSL where +feature turns something on and -feature >> turns it off. > > By that argument we should also have operators ~, !, $, \, ? because > some hypothetical DSL might someday want to use them for something. No, I'm not saying that. I'm saying that since Python *already* has unary plus, it can be overloaded to do anything you want. I'm not saying that hypothetical DSLs are a good reason to add a bunch of arbitrary new do-nothing-by-default operators. (By the way, Python already has the ~ bitwise not operator.) >> Decimal uses it to force the current precision and rounding, regardless >> of what the number was initiated to: >> >> Counter uses it to strip zero and negative counts: >> >> I would expect that symbolic maths software like Sympy probably has use >> of a unary plus operator, but I'm not sure. > > Unary plus as normalization does not strike me as being very > intuitive. Well, in truth the only truly intuitive interface is the nipple, but using + for normalisation works for me. It's no more weird than ** for raising to the power, % for remainder after division, or != for not equal. >> I might consider stealing an idea from Perl and Javascript, and have >> unary plus convert strings to a number: >> >> +"123" >> => returns int 123 >> +"1.23" >> => returns float 1.23 > > Eww. Well of course it's "eww" when you write it as a literal, but you wouldn't do that except to illustrate the concept, that's just silly. But compare: number = +raw_input("enter a number: ") versus: text = raw_input("enter a number: ") try: number = float(text) except ValueError: number = int(text) Or worse, people who don't think of try...except will probably try parsing the string by hand. text = raw_input("enter a number: ").strip() if text.isdigit() or text.startswith("-") and text[1:].isdigit(): number = int(text) else: # Floats are allowed a leading - or +, no more than one decimal point, # no more than one exponent starting with E or e, and an optional # leading + or - sign in the exponent. Everything else must be digits. mantissa, exponent = number.upper().split("E", 1) ... And that's about the point where I stopped because correctly parsing floats by hand is complicated. But the point is that there was a time in my life as a Python programmer where I absolutely would have done that, rather than thinking of try...except. -- Steven From rxjwg98 at gmail.com Sat Nov 14 21:13:04 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 18:13:04 -0800 (PST) Subject: What meaning is of '#!python'? In-Reply-To: References: Message-ID: <3aa2f352-ea19-4252-9a09-c884887cf810@googlegroups.com> On Saturday, November 14, 2015 at 8:58:57 PM UTC-5, Chris Angelico wrote: > On Sun, Nov 15, 2015 at 12:54 PM, fl wrote: > > I see an example Python code has such a line at the file beginning: > > > > #!python > > > > > > Is there some meaning about it? > > It probably didn't look exactly like that. Please, when you're asking > questions, COPY AND PASTE rather than retyping some approximation of > what you saw. > > As it happens, I can tell what you're asking about - it's called a > shebang - but I very much doubt that it was exactly what you wrote. > > ChrisA Excuse me. Below is copied from the .py file: #!python from numpy import * from numpy.random import * def resample(weights): n = len(weights) indices = [] Thanks, From rosuav at gmail.com Sat Nov 14 21:18:30 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Nov 2015 13:18:30 +1100 Subject: What meaning is of '#!python'? In-Reply-To: <3aa2f352-ea19-4252-9a09-c884887cf810@googlegroups.com> References: <3aa2f352-ea19-4252-9a09-c884887cf810@googlegroups.com> Message-ID: On Sun, Nov 15, 2015 at 1:13 PM, fl wrote: > Excuse me. Below is copied from the .py file: > > #!python > from numpy import * > from numpy.random import * > Then someone doesn't know how to use a shebang (or is deliberately abusing it), and you can ignore it. It starts with a hash, ergo it's a comment. ChrisA From rxjwg98 at gmail.com Sat Nov 14 21:23:53 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 18:23:53 -0800 (PST) Subject: What function is 'u0, j = random(), 0'? Message-ID: Hi, When I read the below code, I cannot make the last line (with ######) out. def res(weights): n = len(weights) indices = [] C = [0.] + [sum(weights[:i+1]) for i in range(n)] u0, j = random(), 0 ###### If I run below code on console, it will say an error. uu, 0.1, 0 What difference is between these two example lines? Thanks, From rosuav at gmail.com Sat Nov 14 21:23:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Nov 2015 13:23:59 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <5647e90c$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <5647e90c$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Nov 15, 2015 at 1:08 PM, Steven D'Aprano wrote: > number = +raw_input("enter a number: ") > > versus: > > text = raw_input("enter a number: ") > try: > number = float(text) > except ValueError: > number = int(text) What kinds of strings can float() not handle but int() can, and in a program that's going to group floats and ints together as "numbers", will they ever be useful? I'd be more likely to write this as simply: number = float(input("Enter a number: ")) (Also, I use Python 3. No raw. But same diff.) ChrisA From zachary.ware+pylist at gmail.com Sat Nov 14 21:26:50 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Sat, 14 Nov 2015 20:26:50 -0600 Subject: What meaning is of '#!python'? In-Reply-To: References: Message-ID: On Sat, Nov 14, 2015 at 7:58 PM, Chris Angelico wrote: > On Sun, Nov 15, 2015 at 12:54 PM, fl wrote: >> I see an example Python code has such a line at the file beginning: >> >> #!python >> >> >> Is there some meaning about it? > > It probably didn't look exactly like that. Please, when you're asking > questions, COPY AND PASTE rather than retyping some approximation of > what you saw. "#!python" is a valid shebang for the Python Launcher for Windows. It's also a not-too-terrible placeholder for a Unix shebang meaning "whichever Python you want it to be". The better choice for use with both platforms would be "#!/usr/bin/env python", though. -- Zach From torriem at gmail.com Sat Nov 14 21:28:19 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 14 Nov 2015 19:28:19 -0700 Subject: What meaning is of '#!python'? In-Reply-To: References: Message-ID: <5647EDC3.1030606@gmail.com> On 11/14/2015 06:54 PM, fl wrote: > Hi, > > I see an example Python code has such a line at the file beginning: > > #!python > > > Is there some meaning about it? Supposed to be, yes, but the line you've pasted there wouldn't work on any system I know of. https://en.wikipedia.org/wiki/Shebang_%28Unix%29 From rxjwg98 at gmail.com Sat Nov 14 21:37:33 2015 From: rxjwg98 at gmail.com (fl) Date: Sat, 14 Nov 2015 18:37:33 -0800 (PST) Subject: Question about yield Message-ID: Hi, I have read a couple of tutorial on yield. The following code snippet still gives me a shock. I am told yield is a little like return. I only see one yield in the tutorial examples. Here it has two yields. And there are three variables following keyword yield. I have not tried debug function to get the running states yet. Could you give me some explanation on this yield usage? Or are there some high relevant tutorial on this? Thanks, def pfr(sequence, pos, stepsize, n): seq = iter(sequence) x = ones((n, 2), int) * pos # position f0 = seq.next()[tuple(pos)] * ones(n) # model yield pos, x, ones(n)/n # weights for im in seq: x += uniform(-stepsize, stepsize, x.shape) # x = x.clip(zeros(2), array(im.shape)-1).astype(int) # f = im[tuple(x.T)] # s w = 1./(1. + (f0-f)**2) # distance w /= sum(w) # w yield sum(x.T*w, axis=1), x, w # weights if 1./sum(w**2) < n/2.: # degenerate: x = x[res(w),:] # to weights From rosuav at gmail.com Sat Nov 14 21:43:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Nov 2015 13:43:41 +1100 Subject: Question about yield In-Reply-To: References: Message-ID: On Sun, Nov 15, 2015 at 1:37 PM, fl wrote: > Or are there some high relevant tutorial on this? > Start here: https://docs.python.org/3/tutorial/index.html ChrisA From zachary.ware+pylist at gmail.com Sat Nov 14 21:47:15 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Sat, 14 Nov 2015 20:47:15 -0600 Subject: What function is 'u0, j = random(), 0'? In-Reply-To: References: Message-ID: Hi, On Sat, Nov 14, 2015 at 8:23 PM, fl wrote: > Hi, > > When I read the below code, I cannot make the last line (with ######) out. > > > > def res(weights): > n = len(weights) > indices = [] > C = [0.] + [sum(weights[:i+1]) for i in range(n)] > u0, j = random(), 0 ###### > > > If I run below code on console, it will say an error. > > uu, 0.1, 0 > > > What difference is between these two example lines? I've noticed you sending a lot of questions in the past day or two, many at a fairly basic level. I think you would be well-served to read through the tutorial at https://docs.python.org/3/tutorial. It's been a while since I last read it, but I believe this question is covered there. To give to an answer anyway, the two lines ("u0, j = random(), 0" and "uu, 0.1, 0") are very different. The first is a tuple unpacking assignment. The right side (everything right of the equal sign) creates a tuple (comma creates a tuple, not parentheses) of the result of calling the 'random', and 0. The left side the equal sign is a list of names to which the right side values are assigned; the result of random() is assigned to the name 'u0', and 0 is assigned to 'j'. The same result could be achieved by the following two lines: u0 = random() j = 0 The second line attempts to make a tuple out of the value assigned to the name 'uu', the float 0.1, and the int 0, and throw it away. I'm assuming the error you got was a NameError because nothing was assigned to 'uu', but I could be wrong. For future questions, you should copy and paste the full traceback, which gives *a lot* more information than "there was an error". Hope this helps, -- Zach From ben+python at benfinney.id.au Sat Nov 14 22:03:46 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 Nov 2015 14:03:46 +1100 Subject: Learning Python from the tutorial (was: What function is 'u0, j = random(), 0'?) References: Message-ID: <854mgodkvh.fsf_-_@benfinney.id.au> Zachary Ware writes: > I've noticed you sending a lot of questions in the past day or two, > many at a fairly basic level. I think you would be well-served to > read through the tutorial at https://docs.python.org/3/tutorial. Better than merely reading through it: Anyone who wants to learn Python from the official tutorial should *work through* the tutorial. Run each example, read the tutorial to get an explanation, experiment to test whether you understand. Only then, continue on. -- \ ?I bought some powdered water, but I don't know what to add.? | `\ ?Steven Wright | _o__) | Ben Finney From rhills at medimorphosis.com.au Sat Nov 14 22:10:54 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Sun, 15 Nov 2015 11:10:54 +0800 Subject: What meaning is of '#!python'? In-Reply-To: References: <3aa2f352-ea19-4252-9a09-c884887cf810@googlegroups.com> Message-ID: <5647F7BE.902@medimorphosis.com.au> On 15/11/15 10:18, Chris Angelico wrote: > On Sun, Nov 15, 2015 at 1:13 PM, fl wrote: >> Excuse me. Below is copied from the .py file: >> >> #!python >> from numpy import * >> from numpy.random import * >> > Then someone doesn't know how to use a shebang (or is deliberately > abusing it), and you can ignore it. It starts with a hash, ergo it's a > comment. > > ChrisA Looks like the author of the script file has tried to create a Python Shell script. This link describes them in detail: http://www.dreamsyssoft.com/python-scripting-tutorial/intro-tutorial.php Not sure whether the example originally quoted would work, I imagine it might on some 'nix operating systems. The more common first line is: #!/usr/bin/env python If you start a script file with this line and make the file executable, you can then run the script from the command line without having to preface it with a reference to your Python executable. Eg: my-script.py versus python my-script.py HTH, -- Rob Hills Waikiki, Western Australia From eryksun at gmail.com Sun Nov 15 00:57:47 2015 From: eryksun at gmail.com (eryksun) Date: Sat, 14 Nov 2015 23:57:47 -0600 Subject: What meaning is of '#!python'? In-Reply-To: References: Message-ID: On Sat, Nov 14, 2015 at 8:26 PM, Zachary Ware wrote: > > "#!python" is a valid shebang for the Python Launcher for Windows. > It's also a not-too-terrible placeholder for a Unix shebang meaning > "whichever Python you want it to be". The better choice for use with > both platforms would be "#!/usr/bin/env python", though. The "/usr/bin/env python" virtual command searches the directories in PATH, trying each file extension from PATHEXT such as "python.COM", "python.EXE", and so on. You can also search for other programs such as "pypy". Note that qualifying "python" (but not other names) as "python2" or "python3.5" makes the launcher use the registry instead of searching PATH. "#!/usr/bin/python" may be better in some cases. This defaults to the latest installed version of 2.x (or 3.x if no 2.x is installed) that's configured in the Windows registry. Or specify "python2" or "python3" to use the latest 2.x or 3.x. These commands can be configured to use a particular major[.minor[-32]] version via the environment variables PY_PYTHON, PY_PYTHON2, and PY_PYTHON3. Or you can configure them instead by setting the "python", "python2" and "python3" keys in the [defaults] section of the configuration file "%LOCALAPPDATA%\py.ini". Note that the environment variable overrides the corresponding py.ini key. When portability isn't a concern you can use a Windows path in the shebang such as "#!C:\pypy40\pypy.exe". https://docs.python.org/3/using/windows.html#shebang-lines From auriocus at gmx.de Sun Nov 15 03:33:40 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 15 Nov 2015 09:33:40 +0100 Subject: Jython standalone In-Reply-To: References: <56469dee$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 15.11.15 um 01:35 schrieb vjp2.at at at.BioStrategist.dot.dot.com: > Jython is python in java at jython.org. > > I tried clicking and double clicking. > > I does a wait cycle (rotating arrow) > then returns to attention. I think you are describing the Windows mouse cursor that displays a rotating wheel to indicate "busy". Aren't you? From looking at the jython website, it states: Download Jython 2.7.0 - Standalone Jar : For embedding Jython in Java applications "embedding Jython in Java applications" means, that you can integrate it into a Java program that you are writing. You will not be able to double click and run this jar; it is a library, not an application. Try the installer instead. Christian From lokotraktor at email.cz Sun Nov 15 04:19:07 2015 From: lokotraktor at email.cz (lokotraktor at email.cz) Date: Sun, 15 Nov 2015 10:19:07 +0100 (CET) Subject: WinXP invalid python 3.5 installation Message-ID: Dear all, Would you be so kind and help me to find a fix of my trouble? I have had installed python 2.7 already. I have downloaded the https://www.python.org/ftp/python/3.5.0/python-3.5.0.exe and have installed it on Windows XP Home Edition Version 2002 SP3 (I am the administrator, which is on czech laguage the word "Spravce".) Please see kindly attachements: python_3,5_empty_installer_window.png .. First I saw the incomplete python installer window. Clicking just in the "empty middle" the installation process of the Python 3.5.0 started and succesfully (?)? finished. Trying to launche the newly installed python I encounter troubles depicted at: python_3,5_not_valid_app_of_win32_type.png .. python.exe is not valid application of Win32 type. python_3,5_not_valid_app_of_win32_type_2.png .. (The "Pristup byl odepren." means Acces denied.) After a little bit googling I have find depends.exe to get know the python installation was complete or not. The finding of depends is not good. See kindly the python_3,5_depends_s_finding.png Finaly I tried to uninstall python 3.5. using Control panels, Add or Remove Programs, Python, Uninstall (everything on czech language so that I do not know propper english wnidows terms). As I see the "incomplete python installer window" I tried to click in the middle of empty area. Another fail appeared to me: python_3.5_unable_to_remove.png python-unistal-log.txt Is something I can fix to obtain fully working upgrade of Python 3.5 on my Windows XP? Please, feel free to ask me for more detailled information. Best regards, Jiri Fajmon -------------- next part -------------- ?[17C0:17D4][2015-11-15T10:07:17]i001: Burn v3.10.0.1823, Windows v5.1 (Build 2600: Service Pack 3), path: C:\Documents and Settings\Spravce\Local Settings\Data aplikac?\Package Cache\{1197d2bb-6cf8-488a-b994-d5bf6d7efe7b}\python-3.5.0.exe [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'ActionLikeInstalling' to value 'Installing' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'ActionLikeInstallation' to value 'Setup' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'ShortVersion' to value '3.5' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'ShortVersionNoDot' to value '35' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'InstallAllUsers' to value '0' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'InstallLauncherAllUsers' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'TargetDir' to value '' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'DefaultAllUsersTargetDir' to value '[ProgramFilesFolder]Python [ShortVersion]' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'TargetPlatform' to value 'x86' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'DefaultJustForMeTargetDir' to value '[LocalAppDataFolder]Programs\Python\Python[ShortVersionNoDot]-32' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'OptionalFeaturesRegistryKey' to value 'Software\Python\PythonCore\[ShortVersion]-32\InstalledFeatures' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'TargetDirRegistryKey' to value 'Software\Python\PythonCore\[ShortVersion]-32\InstallPath' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'DefaultCustomTargetDir' to value '' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'InstallAllUsersState' to value 'enabled' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'InstallLauncherAllUsersState' to value 'enabled' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'CustomInstallLauncherAllUsersState' to value '[InstallLauncherAllUsersState]' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'TargetDirState' to value 'enabled' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'CustomBrowseButtonState' to value 'enabled' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_core' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_exe' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_dev' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_lib' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_test' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_doc' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_tools' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_tcltk' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_pip' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_launcher' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_symbols' to value '0' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Include_debug' to value '0' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'LauncherOnly' to value '0' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'AssociateFiles' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'Shortcuts' to value '1' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'PrependPath' to value '0' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'CompileAll' to value '0' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing numeric variable 'SimpleInstall' to value '0' [17C0:17D4][2015-11-15T10:07:17]i000: Initializing string variable 'SimpleInstallDescription' to value '' [17C0:17D4][2015-11-15T10:07:17]i009: Command Line: '/modify' [17C0:17D4][2015-11-15T10:07:17]i000: Setting string variable 'WixBundleLog' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717.log' [17C0:17D4][2015-11-15T10:07:17]i000: Setting string variable 'WixBundleManufacturer' to value 'Python Software Foundation' [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'CRTInstalled' to value 0 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_debug' to value 0 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_symbols' to value 0 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_dev' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_doc' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_exe' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_lib' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'PrependPath' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_pip' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_tcltk' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_test' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Include_tools' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting numeric variable 'Shortcuts' to value 1 [17C0:17D4][2015-11-15T10:07:18]i000: Setting string variable 'InstallAllUsersState' to value 'disable' [17C0:17D4][2015-11-15T10:07:18]i000: Setting string variable 'TargetDir' to value 'C:\Documents and Settings\Spravce\Local Settings\Data aplikac?\Programs\Python\Python35-32\' [17C0:09B8][2015-11-15T10:07:18]i000: Did not find j:\dokumenty\install\Nstroje\python35\unattend.xml [17C0:09B8][2015-11-15T10:07:18]i000: Setting string variable 'ActionLikeInstalling' to value 'Updating' [17C0:09B8][2015-11-15T10:07:18]i000: Setting string variable 'ActionLikeInstallation' to value 'Modify' [17C0:09B8][2015-11-15T10:07:18]i000: Setting version variable 'WixBundleFileVersion' to value '3.5.150.0' [17C0:17D4][2015-11-15T10:07:18]i100: Detect begin, 54 packages [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.0_x86, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.0_x64, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.1_x86, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.1_x64, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.2_x86, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.2_x64, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.3_x86, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: crt_14.0_v6.3_x64, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: core_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: core_AllUsers_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: core_AllUsers_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: core_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: core_JustForMe_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: core_JustForMe_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: dev_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: dev_AllUsers_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: dev_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: dev_JustForMe_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: exe_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: exe_AllUsers, feature: DefaultFeature, state: Absent [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: exe_AllUsers, feature: Shortcuts, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: exe_AllUsers_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: exe_AllUsers_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: exe_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: exe_JustForMe, feature: DefaultFeature, state: Local [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: exe_JustForMe, feature: Shortcuts, state: Local [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: exe_JustForMe_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: exe_JustForMe_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: lib_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: lib_AllUsers_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: lib_AllUsers_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: lib_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: lib_JustForMe_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: lib_JustForMe_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: test_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: test_AllUsers_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: test_AllUsers_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: test_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: test_JustForMe_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: test_JustForMe_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: doc_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: doc_AllUsers, feature: DefaultFeature, state: Absent [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: doc_AllUsers, feature: Shortcuts, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: doc_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: doc_JustForMe, feature: DefaultFeature, state: Local [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: doc_JustForMe, feature: Shortcuts, state: Local [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tools_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tools_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tcltk_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_AllUsers, feature: DefaultFeature, state: Absent [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_AllUsers, feature: AssociateFiles, state: Absent [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_AllUsers, feature: Shortcuts, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tcltk_AllUsers_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_AllUsers_pdb, feature: Symbols, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tcltk_AllUsers_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_AllUsers_d, feature: DebugBinaries, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tcltk_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_JustForMe, feature: DefaultFeature, state: Local [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_JustForMe, feature: AssociateFiles, state: Local [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_JustForMe, feature: Shortcuts, state: Local [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tcltk_JustForMe_pdb, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_JustForMe_pdb, feature: Symbols, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: tcltk_JustForMe_d, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: tcltk_JustForMe_d, feature: DebugBinaries, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: launcher_AllUsers, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: launcher_AllUsers, feature: DefaultFeature, state: Local [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: launcher_AllUsers, feature: AssociateFiles, state: Local [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: launcher_JustForMe, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: launcher_JustForMe, feature: DefaultFeature, state: Absent [17C0:17D4][2015-11-15T10:07:18]i104: Detected package: launcher_JustForMe, feature: AssociateFiles, state: Absent [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: pip_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: pip_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: path_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: path_JustForMe, state: Present, cached: Complete [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: compileall_AllUsers, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i101: Detected package: compileall_JustForMe, state: Absent, cached: None [17C0:17D4][2015-11-15T10:07:18]i199: Detect complete, result: 0x0 [17C0:09B8][2015-11-15T10:07:22]i000: Setting string variable 'ActionLikeInstalling' to value 'Repairing' [17C0:09B8][2015-11-15T10:07:22]i000: Setting string variable 'ActionLikeInstallation' to value 'Repair' [17C0:17D4][2015-11-15T10:07:22]i200: Plan begin, 54 packages, action: Repair [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT = v6.0 and not VersionNT64 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.0_x86 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT64 = v6.0 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.0_x64 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT = v6.1 and not VersionNT64 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.1_x86 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT64 = v6.1 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.1_x64 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT = v6.2 and not VersionNT64 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.2_x86 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT64 = v6.2 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.2_x64 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT = v6.3 and not VersionNT64 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.3_x86 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not CRTInstalled and VersionNT64 = v6.3 and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: crt_14.0_v6.3_x64 [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: core_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and (Include_core or Include_exe or Include_launcher or Include_pip) and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: core_AllUsers_pdb, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and (Include_core or Include_exe or Include_launcher or Include_pip) and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: core_AllUsers_d, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and (Include_core or Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_core_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_000_core_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and (Include_core or Include_exe or Include_launcher or Include_pip) and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and (Include_core or Include_exe or Include_launcher or Include_pip) and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_dev and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: dev_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_dev and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: dev_AllUsers_d, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_dev and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_dev_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_001_dev_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_dev and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and (Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 2 msi features for package: exe_AllUsers [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Shortcuts, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: exe_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and (Include_exe or Include_launcher or Include_pip) and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: exe_AllUsers_pdb, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and (Include_exe or Include_launcher or Include_pip) and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: exe_AllUsers_d, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and (Include_exe or Include_launcher or Include_pip) and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 2 msi features for package: exe_JustForMe [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Shortcuts, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_exe_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_002_exe_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and (Include_exe or Include_launcher or Include_pip) and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and (Include_exe or Include_launcher or Include_pip) and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_lib and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: lib_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_lib and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: lib_AllUsers_pdb, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_lib and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: lib_AllUsers_d, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_lib and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_lib_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_003_lib_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_lib and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_lib and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_test and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: test_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_test and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: test_AllUsers_pdb, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_test and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: test_AllUsers_d, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_test and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_test_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_004_test_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_test and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_test and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_doc and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 2 msi features for package: doc_AllUsers [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Shortcuts, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: doc_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_doc and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 2 msi features for package: doc_JustForMe [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Shortcuts, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_doc_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_005_doc_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_tools and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: tools_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_tools and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_tools_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_006_tools_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_tcltk and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 3 msi features for package: tcltk_AllUsers [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: AssociateFiles, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Shortcuts, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: tcltk_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_tcltk and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 1 msi features for package: tcltk_AllUsers_pdb [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Symbols, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: tcltk_AllUsers_pdb, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_tcltk and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 1 msi features for package: tcltk_AllUsers_d [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DebugBinaries, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: tcltk_AllUsers_d, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_tcltk and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 3 msi features for package: tcltk_JustForMe [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: AssociateFiles, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Shortcuts, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_tcltk_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_007_tcltk_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_tcltk and Include_symbols and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 1 msi features for package: tcltk_JustForMe_pdb [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: Symbols, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_tcltk and Include_debug and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 1 msi features for package: tcltk_JustForMe_d [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DebugBinaries, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i052: Condition '(InstallAllUsers or InstallLauncherAllUsers) and Include_launcher' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 2 msi features for package: launcher_AllUsers [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: AssociateFiles, state: Local, default requested: Unknown, ba requested: Local, execute action: Reinstall, rollback action: None [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: launcher_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_launcher_AllUsers' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_008_launcher_AllUsers.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not (InstallAllUsers or InstallLauncherAllUsers) and Include_launcher' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]i204: Plan 2 msi features for package: launcher_JustForMe [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: DefaultFeature, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i203: Planned feature: AssociateFiles, state: Absent, default requested: Unknown, ba requested: Local, execute action: AddLocal, rollback action: Remove [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and Include_pip and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: pip_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and Include_pip and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_pip_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_009_pip_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and PrependPath and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w322: Skipping cross-scope dependency registration on package: path_AllUsers, bundle scope: PerUser, package scope: PerMachine [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and PrependPath and not LauncherOnly' evaluates to true. [17C0:17D4][2015-11-15T10:07:22]i000: Setting string variable 'WixBundleLog_path_JustForMe' to value 'C:\DOCUME~1\Spravce\LOCALS~1\Temp\Python 3.5.0 (32-bit)_20151115100717_010_path_JustForMe.log' [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'InstallAllUsers and CompileAll and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: compileall_AllUsers [17C0:17D4][2015-11-15T10:07:22]i052: Condition 'not InstallAllUsers and CompileAll and not LauncherOnly' evaluates to false. [17C0:17D4][2015-11-15T10:07:22]w321: Skipping dependency registration on package with no dependency providers: compileall_JustForMe [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.0_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.0_x64, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.1_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.1_x64, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.2_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.2_x64, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.3_x86, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: crt_14.0_v6.3_x64, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: core_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: core_AllUsers_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: core_AllUsers_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: core_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: core_JustForMe_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: core_JustForMe_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: dev_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: dev_AllUsers_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: dev_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: dev_JustForMe_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: exe_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: exe_AllUsers_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: exe_AllUsers_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: exe_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: exe_JustForMe_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: exe_JustForMe_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: lib_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: lib_AllUsers_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: lib_AllUsers_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: lib_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: lib_JustForMe_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: lib_JustForMe_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: test_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: test_AllUsers_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: test_AllUsers_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: test_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: test_JustForMe_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: test_JustForMe_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: doc_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: doc_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tools_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tools_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tcltk_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tcltk_AllUsers_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tcltk_AllUsers_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tcltk_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tcltk_JustForMe_pdb, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: tcltk_JustForMe_d, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: launcher_AllUsers, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: launcher_JustForMe, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: pip_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: pip_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: path_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: path_JustForMe, state: Present, default requested: Repair, ba requested: Repair, execute: Repair, rollback: None, cache: No, uncache: No, dependency: Register [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: compileall_AllUsers, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i201: Planned package: compileall_JustForMe, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None [17C0:17D4][2015-11-15T10:07:22]i299: Plan complete, result: 0x0 [17C0:17D4][2015-11-15T10:07:22]i300: Apply begin [17C0:17D4][2015-11-15T10:08:24]i399: Apply complete, result: 0x8007015e, restart: Required, ba requested restart: No From adrien.georges.louis.viala at gmail.com Sun Nov 15 06:31:06 2015 From: adrien.georges.louis.viala at gmail.com (Adrien Viala) Date: Sun, 15 Nov 2015 11:31:06 +0000 Subject: uninstall 3.5 Message-ID: Hello, Thank you for your work. Just discovering python. My issue steps were : - 3.5 installed - friend codes in 2.7 - server scripts can t run on my laptop (cant find module 0o) - whatever, must be 3.5 / 2.7 issues - let's try virtualenv - can t download virtualenvwrapper-powershell : error X that i can t find info about on googl - whatever let's uninstall 3.5 :/ From adrien.georges.louis.viala at gmail.com Sun Nov 15 06:46:05 2015 From: adrien.georges.louis.viala at gmail.com (Adrien Viala) Date: Sun, 15 Nov 2015 11:46:05 +0000 Subject: uninstall 3.5 In-Reply-To: References: Message-ID: Hi again, Correct guess, virtualenvwrapper-powershell correctly installed under 2.7 :) On Sun, 15 Nov 2015 at 12:31 Adrien Viala < adrien.georges.louis.viala at gmail.com> wrote: > Hello, > > Thank you for your work. Just discovering python. > > My issue steps were : > - 3.5 installed > - friend codes in 2.7 > - server scripts can t run on my laptop (cant find module 0o) > - whatever, must be 3.5 / 2.7 issues > - let's try virtualenv > - can t download virtualenvwrapper-powershell : error X that i can t find > info about on googl > - whatever let's uninstall 3.5 > > :/ > > > From kent at z-sverige.nu Sun Nov 15 07:38:25 2015 From: kent at z-sverige.nu (kent nyberg) Date: Sun, 15 Nov 2015 07:38:25 -0500 Subject: pygtk beginner script not working In-Reply-To: <5b6f7b3f-a132-4305-8ab7-a256b9dbf40f@googlegroups.com> References: <5b6f7b3f-a132-4305-8ab7-a256b9dbf40f@googlegroups.com> Message-ID: <20151115123825.GA24284@z-sverige.nu> On Sat, Nov 14, 2015 at 05:00:59PM -0800, james at imagewebdesign.co.uk wrote: > Hi guys > > I'm new to Python so please bare with me :) > > I'm using python 2.7.10 as advised (more tools apparently over 3.x) > > Trying to use this script > > [CODE] > #!/usr/bin/env python > > # example base.py > > import pygtk It makes most sense to use gtk3 and not gtk2. The most recenst version of gtk3 is used with gi package. Read this for example: http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html From Seymore4Head at Hotmail.invalid Sun Nov 15 12:30:49 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 15 Nov 2015 12:30:49 -0500 Subject: Format numbers Message-ID: Just screwing around making up practice problems. I can't get the format right. I am trying to learn how to get a output line to line up neatly. import random lo=1 hi=10000 # I am adding or subtracting 0s from this input number fm=len(str(hi)) # This counts the digits of the input number print fm a=random.randrange(lo,hi+1) count=0 guess=0 while guess != a: guess=random.randrange(lo,hi + 1) print "guess =", print "{:8d}".format(guess), #what I would like to do is use the variable fm instead of the number 8 here so the number of fields are the same as the input number. count+=1 if guess==a: print " The hidden number was",a print print "You guessed right in ", if guess >a: print " Guess Lower" hi=guess if guess < a: lo=guess print " Guess Higher" print count print " turns" From python at mrabarnett.plus.com Sun Nov 15 14:00:42 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 15 Nov 2015 19:00:42 +0000 Subject: Format numbers In-Reply-To: References: Message-ID: <5648D65A.50900@mrabarnett.plus.com> On 2015-11-15 17:30, Seymore4Head wrote: > Just screwing around making up practice problems. I can't get the > format right. I am trying to learn how to get a output line to line > up neatly. > > import random > lo=1 > hi=10000 # I am adding or subtracting 0s from this input number > fm=len(str(hi)) # This counts the digits of the input number > print fm > a=random.randrange(lo,hi+1) > count=0 > guess=0 > > while guess != a: > guess=random.randrange(lo,hi + 1) > print "guess =", > > print "{:8d}".format(guess), #what I would like to do is use > the variable fm instead of the number 8 here so the number of fields > are the same as the input number. > > count+=1 > if guess==a: > print " The hidden number was",a > print > print "You guessed right in ", > if guess >a: > print " Guess Lower" > hi=guess > if guess < a: > lo=guess > print " Guess Higher" > print count > print " turns" > The part of the format placeholder that specifies the width can also be placeholder, like this: print "{:{}d}".format(guess, fm) From Seymore4Head at Hotmail.invalid Sun Nov 15 14:07:12 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Sun, 15 Nov 2015 14:07:12 -0500 Subject: Format numbers References: Message-ID: On Sun, 15 Nov 2015 19:00:42 +0000, MRAB wrote: >On 2015-11-15 17:30, Seymore4Head wrote: >> Just screwing around making up practice problems. I can't get the >> format right. I am trying to learn how to get a output line to line >> up neatly. >> >> import random >> lo=1 >> hi=10000 # I am adding or subtracting 0s from this input number >> fm=len(str(hi)) # This counts the digits of the input number >> print fm >> a=random.randrange(lo,hi+1) >> count=0 >> guess=0 >> >> while guess != a: >> guess=random.randrange(lo,hi + 1) >> print "guess =", >> >> print "{:8d}".format(guess), #what I would like to do is use >> the variable fm instead of the number 8 here so the number of fields >> are the same as the input number. >> >> count+=1 >> if guess==a: >> print " The hidden number was",a >> print >> print "You guessed right in ", >> if guess >a: >> print " Guess Lower" >> hi=guess >> if guess < a: >> lo=guess >> print " Guess Higher" >> print count >> print " turns" >> >The part of the format placeholder that specifies the width can also be >placeholder, like this: > > print "{:{}d}".format(guess, fm) That works Thanks From j.bak36 at gmail.com Sun Nov 15 15:38:40 2015 From: j.bak36 at gmail.com (jbak36) Date: Sun, 15 Nov 2015 12:38:40 -0800 (PST) Subject: Why won't this run? Message-ID: Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> #this program says hello and asks for my name >>> print:('Hello world!') Hello world! >>> print:('What is your name?') #ask for their name What is your name? >>> myName = input() print:('It is good to meet you,'+myName) >>> print:('The length of your name is:') The length of your name is: >>> print:(len(myName)) 39 >>> print:('What is your age?')#ask for their age What is your age? >>> myAge=input() print:('You will be ' + str(int(myAge)+1)'in a year.') >>> From gherron at digipen.edu Sun Nov 15 15:50:12 2015 From: gherron at digipen.edu (Gary Herron) Date: Sun, 15 Nov 2015 12:50:12 -0800 Subject: Why won't this run? In-Reply-To: References: Message-ID: <5648F004.6080101@digipen.edu> On 11/15/2015 12:38 PM, jbak36 wrote: > Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> #this program says hello and asks for my name >>>> print:('Hello world!') > Hello world! > You are lying to us somehow. That attempt to print (as you've written it) does not produce the the line of output you've indicated. Instead it produces a syntax error, because Python does not use a colon in that situation. So change your print:(...) lines to print(...) (without the colon) and try again. If there is further trouble, ask another question, but please cut and paste the actual and *exact* results into the email. Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From python.list at tim.thechases.com Sun Nov 15 15:55:45 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 15 Nov 2015 14:55:45 -0600 Subject: Why won't this run? In-Reply-To: References: Message-ID: <20151115145545.3fe779ac@bigbox.christie.dr> On 2015-11-15 12:38, jbak36 wrote: > Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC > v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or > "license()" for more information. > >>> #this program says hello and asks for my name > >>> print:('Hello world!') > Hello world! Well, for starters, you're almost certainly not copy/pasting from the shell session as the colon after the "print" is a syntax error: Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print:('hellow world!') File "", line 1 print:('hellow world!') ^ SyntaxError: invalid syntax -tkc From rxjwg98 at gmail.com Sun Nov 15 19:27:03 2015 From: rxjwg98 at gmail.com (fl) Date: Sun, 15 Nov 2015 16:27:03 -0800 (PST) Subject: What meaning is 'a[0:10:2]'? Message-ID: <237d9a48-6db3-48aa-89b4-66730cdced7d@googlegroups.com> hi, When I learn slice, I have a new question on the help file. If I set: pp=a[0:10:2] pp is array([1, 3]) I don't know how a[0:10:2] gives array([1, 3]). I know matlab a lot, but here it seems quite different. Could you tell me what meaning a[0:10:2] is? Thanks, class slice(object) | slice(stop) | slice(start, stop[, step]) | | Create a slice object. This is used for extended slicing (e.g. a[0:10:2]). From ben+python at benfinney.id.au Sun Nov 15 19:46:19 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 16 Nov 2015 11:46:19 +1100 Subject: What meaning is 'a[0:10:2]'? References: <237d9a48-6db3-48aa-89b4-66730cdced7d@googlegroups.com> Message-ID: <85ziyedb50.fsf@benfinney.id.au> (Please set a ?From? address that has a name for you as an individual; ?fl? is rather anonymous and doesn't help us to identify you in these conversations.) fl writes: > When I learn slice Are you working through the Python tutorial ? These are Python concepts that you will learn by working through the tutorial, from beginning to end. If you want to engage with a community dedicated to teaching Python newcomers, you should join the Python ?tutor? forum . -- \ ?Philosophy is questions that may never be answered. Religion | `\ is answers that may never be questioned.? ?anonymous | _o__) | Ben Finney From python.list at tim.thechases.com Sun Nov 15 19:48:04 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 15 Nov 2015 18:48:04 -0600 Subject: What meaning is 'a[0:10:2]'? In-Reply-To: <237d9a48-6db3-48aa-89b4-66730cdced7d@googlegroups.com> References: <237d9a48-6db3-48aa-89b4-66730cdced7d@googlegroups.com> Message-ID: <20151115184804.7e89625b@bigbox.christie.dr> On 2015-11-15 16:27, fl wrote: > When I learn slice, I have a new question on the help file. If I > set: > > pp=a[0:10:2] > > pp is array([1, 3]) > > I don't know how a[0:10:2] gives array([1, 3]). > > I know matlab a lot, but here it seems quite different. Could you > tell me what meaning a[0:10:2] is? Well, if it a matlab.array was a well-behaved object it would just give you "0". As your copy/paste on the help for a slice stated, the first number is where it starts (0), the second number is where it ends (10, exclusive), and the 3rd number (2) is the stride. To demonstrate: >>> a = list(range(20)) >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> a[0:10:2] [0, 2, 4, 6, 8] >>> a[:10:2] [0, 2, 4, 6, 8] >>> a[0:10] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] So note that the stride of 2 provides every other one while a stride of three provides every 3rd value >>> a[0:10:3] [0, 3, 6, 9] -tkc From paul.hermeneutic at gmail.com Sun Nov 15 23:54:41 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sun, 15 Nov 2015 21:54:41 -0700 Subject: What meaning is of '#!python'? In-Reply-To: References: Message-ID: The installer of some applications will replace the shebang to refer to a specific version of Python. By doing so, it avoids problems when someone upgrades the default Python version in the PATH. On Nov 14, 2015 11:00 PM, "eryksun" wrote: > On Sat, Nov 14, 2015 at 8:26 PM, Zachary Ware > wrote: > > > > "#!python" is a valid shebang for the Python Launcher for Windows. > > It's also a not-too-terrible placeholder for a Unix shebang meaning > > "whichever Python you want it to be". The better choice for use with > > both platforms would be "#!/usr/bin/env python", though. > > The "/usr/bin/env python" virtual command searches the directories in > PATH, trying each file extension from PATHEXT such as "python.COM", > "python.EXE", and so on. You can also search for other programs such > as "pypy". Note that qualifying "python" (but not other names) as > "python2" or "python3.5" makes the launcher use the registry instead > of searching PATH. > > "#!/usr/bin/python" may be better in some cases. This defaults to the > latest installed version of 2.x (or 3.x if no 2.x is installed) that's > configured in the Windows registry. Or specify "python2" or "python3" > to use the latest 2.x or 3.x. These commands can be configured to use > a particular major[.minor[-32]] version via the environment variables > PY_PYTHON, PY_PYTHON2, and PY_PYTHON3. Or you can configure them > instead by setting the "python", "python2" and "python3" keys in the > [defaults] section of the configuration file "%LOCALAPPDATA%\py.ini". > Note that the environment variable overrides the corresponding py.ini > key. > > When portability isn't a concern you can use a Windows path in the > shebang such as "#!C:\pypy40\pypy.exe". > > https://docs.python.org/3/using/windows.html#shebang-lines > -- > https://mail.python.org/mailman/listinfo/python-list > From greg.ewing at canterbury.ac.nz Mon Nov 16 01:11:13 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 16 Nov 2015 19:11:13 +1300 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> <5647dc88$0$1592$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > And we'd be left looking for a symbol for bitwise inversion. Who needs negation when you have bitwise inversion? minusx = ~x + 1 I know, it doesn't work for floats, but that's just a simple matter of defining ~ on floats appropriately... -- Greg From greg.ewing at canterbury.ac.nz Mon Nov 16 01:15:23 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 16 Nov 2015 19:15:23 +1300 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: Ian Kelly wrote: > Unary integer division seems pretty silly since the only possible results > would be 0, 1 or -1. Ints are not the only thing that // can be applied to: >>> 1.0//0.01 99.0 -- Greg From greg.ewing at canterbury.ac.nz Mon Nov 16 01:19:39 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 16 Nov 2015 19:19:39 +1300 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > Small problem: Since we have / and // operators, it's impossible to > have a unary / operator: No, it's not -- '//' is already recognised as a single token distinct from '/ /'. You would just have to leave a space or use parens in some cases. -- Greg From greg.ewing at canterbury.ac.nz Mon Nov 16 01:30:54 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 16 Nov 2015 19:30:54 +1300 Subject: What is wrong this wrapper (decorator)? In-Reply-To: References: Message-ID: fl wrote: > wrapper(sub(two, one)) > Out[38]: This doesn't do what you probably meant it to do. It first calls sub() with arguments one and two, and then passes the result of that (a Coordinate, if sub is working properly) to wrapper(). Since wrapper() expects a function, not a Coordinate, that won't do anything useful. What you probably meant to do is: wrapper(sub)(one, two) This passes the function sub to wrapper, which returns another function; that function is then called with arguments one and two. -- Greg From mjoerg.phone at gmail.com Mon Nov 16 03:02:09 2015 From: mjoerg.phone at gmail.com (PythonDude) Date: Mon, 16 Nov 2015 00:02:09 -0800 (PST) Subject: numpy column_stack - why does this work? In-Reply-To: References: <0b4725a8-a040-4bfb-b046-81c2e529447a@googlegroups.com> Message-ID: <96d95669-5cf5-4a33-ba51-878edd975e48@googlegroups.com> On Friday, 13 November 2015 18:17:59 UTC+1, Ian wrote: > On Fri, Nov 13, 2015 at 8:37 AM, PythonDude wrote: > > 3) I DON'T understand why the code doesn't look like this: > > > > means, stds = np.column_stack([ > > for _ in xrange(n_portfolios): > > getMuSigma_from_PF(return_vec) ]) > > Because that would be invalid syntax; you can't put a for loop inside > an expression like that. Your question is not about numpy.column_stack > at all, but about list comprehensions. I suggest you start by reading > this: > > https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions > > Then if you're still confused, come back and ask further questions. Thank you very much, I'll look careful into that before asking again :-) From ammammata at tiscalinet.it Mon Nov 16 06:12:02 2015 From: ammammata at tiscalinet.it (Ammammata) Date: Mon, 16 Nov 2015 11:12:02 +0000 (UTC) Subject: A Program that prints the numbers from 1 to 100 References: Message-ID: Il giorno Sat 14 Nov 2015 07:18:18p, *BartC* inviava su comp.lang.python il messaggio news:n27tp6$ec5$1 at dont-email.me. Vediamo cosa scrisse: > Here's one way +1 :) -- /-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\ -=- -=- -=- -=- -=- -=- -=- -=- - -=- >>>>> http://www.bb2002.it :) <<<<< ........... [ al lavoro ] ........... From harirammanohar159 at gmail.com Mon Nov 16 06:40:27 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Mon, 16 Nov 2015 03:40:27 -0800 (PST) Subject: help in pexpect multiprocessing In-Reply-To: References: Message-ID: <73aaf275-3d2c-4148-8a43-204bd2cd128e@googlegroups.com> On Monday, 9 November 2015 18:07:36 UTC+5:30, hariramm... at gmail.com wrote: > Hi, > > I am using multiprocessing with pexpect, issue is whenever i call a function which is having expect(), its throwing error which is genuine as multiple threads are processing it same time (i/o prompt same time by multiple processes..so issues in picture...), so i want to use lock for that section alone to avoid it, but still fails in implementing it...can you help me > > username = input('Enter your username: ') > password = getpass.getpass() > > s = pxssh.pxssh() > s.login ('host','username','password') > s.sendline ('ps -ef|grep java') > s.prompt(timeout=1) > > Try 1: > > if condition == 'met': > np = len(list1) > p = multiprocessing.Pool(np) > p.map(stop, [(ds) for ds in list1]) > > def stop(ds): > s.sendline ('cd /usr') > if condition: > lock = threading.Lock() > lock.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > lock.release() > s.prompt(timeout=200) > print('stopped ds...') > > Try 2: > > if condition == 'met': > lock = Lock() > for ds in list1: > Process(target=stop, args=(ds,lock)).start() > > def stop(ds,l): > s.sendline ('cd /usr') > if condition: > l.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > l.release() > s.prompt(timeout=200) > print('stopped ds...') > > Both are giving me same trace.. > > pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? > > Thanks in Advance Hey Lucena, Thank you for suggestion, yeah process queues doing the samething, creating new sesssion for each process and executing simulatenously.. requirement is served.. but still i want to tackle the situation with locks, but not able to as throwing the below error. pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? From snailcoder at retrosite.invalid Mon Nov 16 06:53:07 2015 From: snailcoder at retrosite.invalid (Grobu) Date: Mon, 16 Nov 2015 12:53:07 +0100 Subject: What is the right way to import a package? In-Reply-To: <8e325d88-6ad1-46e3-a1fb-ef8c28dc50a8@googlegroups.com> References: <8e325d88-6ad1-46e3-a1fb-ef8c28dc50a8@googlegroups.com> Message-ID: On 14/11/15 21:00, fl wrote: > Hi, > > I want to use a code snippet found on-line. It has such content: > > from numpy import * > dt = 0.1 > # Initialization of state matrices > X = array([[0.0], [0.0], [0.1], [0.1]]) > > # Measurement matrices > Y = array([[X[0,0] + abs(randn(1)[0])], [X[1,0] + abs(randn(1)[0])]]) > > > > When the above content is inside a .py document and running, there will be > an error: > > ---> 15 Y = array([[X[0,0] + abs(randn(1)[0])], [X[1,0] + abs(randn(1)[0])]]) > 16 #Y = ([[X[0,0]], [X[1,0] + 0]]) > > NameError: name 'randn' is not defined > > > But when I run the above line by line at the console (Canopy), there will be > no error for the above line. > > My question is: > > The import and the following are wrong. > > X = array([[0.0], [0.0], [0.1], [0.1]]) > > It should be: > > import numpy as np > ... > Y = np.array([[X[0,0] + abs(np.randn(1)[0])], [X[1,0] + abs(np.randn(1)[0])]]) > > This looks like the code I once saw. But the file when running has such > error: > > ---> 15 Y = np.array([[X[0,0] + abs(np.randn(1)[0])], [X[1,0] + abs(np.randn(1)[0])]]) > > AttributeError: 'module' object has no attribute 'randn' > > When it is run line by line at the console, it has the same error. > > It is strange that the same content has errors depends on inside a file, or > at CLI console. > > What is missing I don't realize? Thanks, > > You can try : from numpy import * from numpy.random import * HTH, - Grobu - From harirammanohar159 at gmail.com Mon Nov 16 06:57:04 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Mon, 16 Nov 2015 03:57:04 -0800 (PST) Subject: A Program that prints the numbers from 1 to 100 In-Reply-To: References: Message-ID: <85eea326-406d-4454-8c3a-859f1e464cfc@googlegroups.com> On Saturday, 14 November 2015 23:04:40 UTC+5:30, Cai Gengyang wrote: > I want to write a program in Python that does this ---- > > "Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz"." > > How do I go about doing it ? This would help, but try to write on your own to improve, else you cant make this going long.... i = 1 while i <= 100: if multipleof_3 and multipleof_5: print("FizzBuzz") ++i elif multipleof_3: print("Fizz") ++i elif multipleof_5: print("Buzz") ++i else: print(number) ++i From steve at pearwood.info Mon Nov 16 07:11:49 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 16 Nov 2015 23:11:49 +1100 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> Message-ID: <5649c807$0$1615$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Nov 2015 05:15 pm, Gregory Ewing wrote: > Ian Kelly wrote: >> Unary integer division seems pretty silly since the only possible results >> would be 0, 1 or -1. > > Ints are not the only thing that // can be applied to: > > >>> 1.0//0.01 > 99.0 Good catch! -- Steven From steve at pearwood.info Mon Nov 16 07:29:08 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 16 Nov 2015 23:29:08 +1100 Subject: What meaning is 'a[0:10:2]'? References: <237d9a48-6db3-48aa-89b4-66730cdced7d@googlegroups.com> Message-ID: <5649cc16$0$1592$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Nov 2015 11:27 am, fl wrote: > hi, > > When I learn slice, I have a new question on the help file. If I set: > > pp=a[0:10:2] > > pp is array([1, 3]) Really? How do you get that answer? What is `a`? > I don't know how a[0:10:2] gives array([1, 3]). Neither do I, because you have not told us what `a` is. But I know what `a[0:10:2]` *should* be: it takes a copy of elements from a, starting at position 0, ending just before position 10, and taking every second one. py> a = list(range(100, 121)) py> print(a) [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120] py> print(a[0:10]) [100, 101, 102, 103, 104, 105, 106, 107, 108, 109] py> print(a[0:10:2]) [100, 102, 104, 106, 108] py> print(a[0:10:3]) [100, 103, 106, 109] By default, the first item is automatically 0, so these two slices are the same: a[0:10:2] a[:10:2] If the start or end position are out of range, the slice will only include positions that actually exist: py> a[:10000:5] [100, 105, 110, 115, 120] -- Steven From rosuav at gmail.com Mon Nov 16 07:35:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Nov 2015 23:35:37 +1100 Subject: A Program that prints the numbers from 1 to 100 In-Reply-To: <85eea326-406d-4454-8c3a-859f1e464cfc@googlegroups.com> References: <85eea326-406d-4454-8c3a-859f1e464cfc@googlegroups.com> Message-ID: On Mon, Nov 16, 2015 at 10:57 PM, wrote: > This would help, but try to write on your own to improve, else you cant make this going long.... > Here's another version, but with a deliberate bug in it. You may use this code if and only if your comprehension is sufficient to detect and correct that bug. next(filter(None,(print(next(filter(None,reversed(x)))) for x in enumerate(itertools.islice(itertools.cycle(("Fizzbuzz",0,"","Fizz",not "Fuzz","Buzz","Fizz",(),bytes(),"Fizz","Buzz",{},"Fizz",False,globals().get(math.pi))),1,101)))),None) Actually... you know what, I think debugging THAT is a malicious prank to pull on an experienced Python programmer; plus, if you're caught submitting that for your project, you deserve all the shame you get. Trust me, this is NOT good code. Here's the corrected version. It works, but you do not want to use this. next(filter(None,(print(next(filter(None,reversed(x)))) for x in itertools.islice(enumerate(itertools.cycle(("Fizzbuzz",0,"","Fizz",not "Fuzz","Buzz","Fizz",(),bytes(),"Fizz","Buzz",{},"Fizz",False,globals().get(math.pi)))),1,101))),None) Enjoy! ChrisA From steve at pearwood.info Mon Nov 16 07:57:31 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 16 Nov 2015 23:57:31 +1100 Subject: Names [was Re: What meaning is 'a[0:10:2]'?] References: <237d9a48-6db3-48aa-89b4-66730cdced7d@googlegroups.com> Message-ID: <5649d2bd$0$1613$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Nov 2015 11:46 am, Ben Finney wrote: > (Please set a ?From? address that has a name for you as an individual; > ?fl? is rather anonymous and doesn't help us to identify you in these > conversations.) As far as I know, there's only one "fl" who posts here. And "fl" as a cognomen is no worse than such well-known examples as: J.R. https://en.wikipedia.org/wiki/JR_(artist) and https://en.wikipedia.org/wiki/Who_shot_J.R.%3F M.J. https://en.wikipedia.org/wiki/Mary_Jane_Watson djk (who you worked with for a number of years *wink*) T.I. https://en.wikipedia.org/wiki/T.I. not to mention many famous people who are frequently, but not exclusively, known by initials: JMS https://en.wikipedia.org/wiki/J._Michael_Straczynski MLK https://en.wikipedia.org/wiki/Martin_Luther_King,_Jr. JFK https://en.wikipedia.org/wiki/John_F._Kennedy On-the-internet-nobody-can-tell-if-your-name-really-is-Mxyzptlk-ly yr's, -- Steven From steve at pearwood.info Mon Nov 16 08:10:20 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 17 Nov 2015 00:10:20 +1100 Subject: Question about yield References: Message-ID: <5649d5bf$0$1605$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Nov 2015 01:37 pm, fl wrote: > Hi, > I have read a couple of tutorial on yield. The following code snippet > still gives me a shock. I am told yield is a little like return. I only > see one yield in the tutorial examples. Here it has two yields. And there > are three variables following keyword yield. Correct. `yield` exits the running function, but unlike `return`, the function doesn't close down, it just pauses, ready to start up again when you call next() on it. Here is an example of an ordinary function: py> def function(): ... return 1 ... return 2 ... return 3 ... py> function() 1 py> function() 1 Each time you call the function, it starts again at the beginning, and exits after the first `return`. So the lines `return 2` and `return 3` are dead code that never gets run. Here is an example of a generator function with yield. Calling generators is a bit different from calling a function: first you have to initialise them by calling the function to create a "generator object", then you call the next() function to advance to the next `yield` statement, and finally they raise an exception when there are no more `yields`. An example might help: py> def generator(): ... yield 1 ... yield 2 ... yield 3 ... py> gen = generator() py> next(gen) 1 py> next(gen) 2 py> next(gen) 3 py> next(gen) Traceback (most recent call last): File "", line 1, in StopIteration To start the generator from the beginning again, you have to create a new generator object by calling the function: gen = generator() Calling next() many times is often inconvenient. Normally you will iterate over the generator: for x in gen: print(x) or you call collect all the items using list(). See example below. Here is a generator which takes a list as argument, and returns a running sum of the list values: def running_sum(alist): total = 0 for value in alist: total += value yield total And here is an example of using it: py> gen = running_sum(data) py> list(gen) [1, 3, 6, 16, 18, 18, 23] -- Steven From rosuav at gmail.com Mon Nov 16 08:17:40 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Nov 2015 00:17:40 +1100 Subject: WinXP invalid python 3.5 installation In-Reply-To: References: Message-ID: On Sun, Nov 15, 2015 at 8:19 PM, wrote: > I have downloaded the > https://www.python.org/ftp/python/3.5.0/python-3.5.0.exe > and have installed it on Windows XP Home Edition Version 2002 SP3 (I am the > administrator, which is on czech laguage the word "Spravce".) You're not going to be able to install Python 3.5 on Windows XP - the latest Python doesn't support the old Windows. You can upgrade to Windows 7 or 8 or 10, or downgrade to Python 3.4, or jump across to Linux or some other OS. The installer for 3.5 currently isn't very clear about the problem, but that's going to be changed in a couple of weeks, so you'll know what your options are. ChrisA From steve at pearwood.info Mon Nov 16 08:17:43 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 17 Nov 2015 00:17:43 +1100 Subject: Problems using struct pack/unpack in files, and reading them. References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <5647e90c$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5649d77a$0$1585$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Nov 2015 01:23 pm, Chris Angelico wrote: > On Sun, Nov 15, 2015 at 1:08 PM, Steven D'Aprano > wrote: >> number = +raw_input("enter a number: ") >> >> versus: >> >> text = raw_input("enter a number: ") >> try: >> number = float(text) >> except ValueError: >> number = int(text) > > What kinds of strings can float() not handle but int() can, Heh, I think I got the order of them backwards. You should try to convert to int first, and if that fails, try float. > and in a > program that's going to group floats and ints together as "numbers", > will they ever be useful? I'd be more likely to write this as simply: Obviously this code assumes you want to distinguish between ints and floats for some reason. In Python, unlike Lua, Javascript and a few others, we do distinguish between ints and floats. Since they have different capabilities, that may sometimes be useful: py> 10.0 ** 400 Traceback (most recent call last): File "", line 1, in OverflowError: (34, 'Numerical result out of range') py> 10 ** 400 1000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000 -- Steven From rosuav at gmail.com Mon Nov 16 08:27:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Nov 2015 00:27:55 +1100 Subject: Problems using struct pack/unpack in files, and reading them. In-Reply-To: <5649d77a$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <5647e90c$0$1588$c3e8da3$5496439d@news.astraweb.com> <5649d77a$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Nov 17, 2015 at 12:17 AM, Steven D'Aprano wrote: > On Sun, 15 Nov 2015 01:23 pm, Chris Angelico wrote: > >> On Sun, Nov 15, 2015 at 1:08 PM, Steven D'Aprano >> wrote: >>> number = +raw_input("enter a number: ") >>> >>> versus: >>> >>> text = raw_input("enter a number: ") >>> try: >>> number = float(text) >>> except ValueError: >>> number = int(text) >> >> What kinds of strings can float() not handle but int() can, > > Heh, I think I got the order of them backwards. You should try to convert to > int first, and if that fails, try float. Ah! Yes, that makes sense then. I assumed this... >> and in a >> program that's going to group floats and ints together as "numbers", >> will they ever be useful? I'd be more likely to write this as simply: ... on the basis of the "float first" check. > Obviously this code assumes you want to distinguish between ints and floats > for some reason. In Python, unlike Lua, Javascript and a few others, we do > distinguish between ints and floats. Since they have different > capabilities, that may sometimes be useful: > > > py> 10.0 ** 400 > Traceback (most recent call last): > File "", line 1, in > OverflowError: (34, 'Numerical result out of range') > py> 10 ** 400 > 1000000000000000000000000000000000000000000000000000000000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000 > 000000000000000000000000000000000000 Right. If you check int() first and then float(), you can make use of this. But if the user enters that string and you try to float() it, it will work: >>> float(str(int(10**400))) inf Hence my confusion. :) With that small change, your code makes fine sense. ChrisA From harvesting at is.invalid Mon Nov 16 08:39:50 2015 From: harvesting at is.invalid (Jussi Piitulainen) Date: Mon, 16 Nov 2015 15:39:50 +0200 Subject: A Program that prints the numbers from 1 to 100 References: <85eea326-406d-4454-8c3a-859f1e464cfc@googlegroups.com> Message-ID: Chris Angelico writes: > > Here's another version, but with a deliberate bug in it. [- -] This one recycles fish in a way that looks a bit worrying but it seems to work. If there's a bug, it's not deliberate. Except stopping at 15 is deliberate. from contextlib import contextmanager as fish from collections import defaultdict as fowl @fish def fish(fish): chip = fowl(str) chip.update(((fowl(int)[fish],fish),)) yield chip with fish("Fish") as f, fish("Bush") as b: print(*("{}{}".format(f[k%3],b[k%5]) or k for k in range(1,16))) # prints: 1 2 Fish 4 Bush Fish 7 8 Fish Bush 11 Fish 13 14 FishBush From rosuav at gmail.com Mon Nov 16 08:43:29 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Nov 2015 00:43:29 +1100 Subject: A Program that prints the numbers from 1 to 100 In-Reply-To: References: <85eea326-406d-4454-8c3a-859f1e464cfc@googlegroups.com> Message-ID: On Tue, Nov 17, 2015 at 12:39 AM, Jussi Piitulainen wrote: > This one recycles fish in a way that looks a bit worrying but it seems > to work. Recycles fish? http://www.saigan.com/kidscorner/comics/unhfulb.jpg ChrisA From lynto28 at gmail.com Mon Nov 16 08:43:44 2015 From: lynto28 at gmail.com (Didymus) Date: Mon, 16 Nov 2015 05:43:44 -0800 (PST) Subject: pexpect matching? Message-ID: <6b2adb7a-7f2f-48ba-afa7-28e597bb9948@googlegroups.com> Greetings, I have the following code: import pexpect child = pexpect.spawn('/bin/bash') i = child.expect_exact('bash-3.2$ ') child.sendline("rpm -q --queryformat '%{VERSION}\\n' glibc") i = child.expect (['2', '2.5', '2.52.5', pexpect.TIMEOUT]) print child.before print '---' print child.after if i == 0: print 'We got 2' elif i == 1: print 'We got 2.5' elif i == 2: print ' We got 7' elif i == 3: print 'Timed Out!' else: print 'What happened?' The output of the commandline is: % rpm -q --queryformat '%{VERSION}\n' glibc 2.5 2.5 I've tried to use "\b", "^", "$" around the return stings and even expect_exact, but end up with it printing "We got 2". It's just mathcing the first character and not the entire string. rpm -q --queryformat '%{VERSION}\n' glibc --- 2 We got 2 What am I doing wrong here? What do I need to tell the expect line to grab the entire line back to check against? Thanks Tom From ian.g.kelly at gmail.com Mon Nov 16 09:50:30 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 16 Nov 2015 07:50:30 -0700 Subject: uninstall 3.5 In-Reply-To: References: Message-ID: On Nov 16, 2015 6:10 AM, "Adrien Viala" < adrien.georges.louis.viala at gmail.com> wrote: > > Hello, > > Thank you for your work. Just discovering python. > > My issue steps were : > - 3.5 installed > - friend codes in 2.7 > - server scripts can t run on my laptop (cant find module 0o) > - whatever, must be 3.5 / 2.7 issues > - let's try virtualenv > - can t download virtualenvwrapper-powershell : error X that i can t find > info about on googl > - whatever let's uninstall 3.5 If your friend is writing code for 2.7 and not writing for 2/3 compatibility, then you're not going to be able to run that code in Python 3. A virtual env won't help with that, because it's still Python 3. Get your friend to upgrade to Python 3, or to write compatible code (there are tools to help with this), or install Python 2.7. From zachary.ware+pylist at gmail.com Mon Nov 16 11:42:29 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 16 Nov 2015 10:42:29 -0600 Subject: Running latest 32-bit Python on 64-bit system In-Reply-To: References: Message-ID: On Fri, Nov 13, 2015 at 4:52 AM, Christian Ullrich wrote: > Hello, > > I have a problem with using the (otherwise nice) Python launcher. How can I > get it to run the highest 32-bit Python on my 64-bit system? This is on > Windows, but I think it applies to other OSes as well. > > My application runs (unmodified) with Python 3.[345], but only with the > 32-bit version because it loads a DLL that has no 64-bit version available. > I would like to run it on any system that has *any* suitable Python > installed. > > However, with the shebang syntax supported by the launcher, I can only > demand a 32-bit version if I also specify the Python minor version I want, > and I don't necessarily know that in advance. > > I can code around that, of course, but I don't want to. If Python can select > the 64-bit version to run by itself, it should also be able to for the > 32-bit version, right? I don't think there's currently a way to do what you want, but it seems like a reasonable thing to do. Would you mind raising an enhancement request on bugs.python.org? About the closest you could come currently would be to specify the full path to the interpreter, but of course that may vary by machine. -- Zach From input/ldompeling at casema.nl Mon Nov 16 12:12:12 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Mon, 16 Nov 2015 17:12:12 GMT Subject: import module pyttsx in windows IDLE failed Message-ID: When I try to run this module in Windows IDLE I get this message: How can I solve this problem. Thanks Traceback (most recent call last): File "C:\raspberrypi\recipe-578839-1.py", line 1, in import pyttsx ImportError: No module named 'pyttsx' This is what I found on the internet: ------------------------------------------------------------------- import pyttsx engine = pyttsx.init() engine.setProperty('rate', 70) voices = engine.getProperty('voices') for voice in voices: print ("Using voice:"), repr(voice) engine.setProperty('voice', voice.id) engine.say("Hi there, how's you ?") engine.say("A B C D E F G H I J K L M") engine.say("N O P Q R S T U V W X Y Z") engine.say("0 1 2 3 4 5 6 7 8 9") engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday") engine.say("Violet Indigo Blue Green Yellow Orange Red") engine.say("Apple Banana Cherry Date Guava") engine.runAndWait() -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From syedmwaliullah at gmail.com Mon Nov 16 12:14:43 2015 From: syedmwaliullah at gmail.com (syedmwaliullah at gmail.com) Date: Mon, 16 Nov 2015 09:14:43 -0800 (PST) Subject: write data in Excel using python Message-ID: <3267f6a3-a047-4abf-80bf-8fdba3659223@googlegroups.com> hi, I am trying to write Excel file suing output from another software where the output comes as myturnlist.Show() The first part is for the output from the software which is saved in the clipboard. The big middle part works to open Excel and save the data into excel file called "TurnData.xlsx". For some reason it doesn't save the file. Any idea? Thanks in advance. import VisumPy.excel # Write to Excel myturnlist.Show() turnData = myturnlist.SaveToClipboard(59,0) excel = win32com.client.Dispatch("Excel.Application") wb = excel.Workbooks.Add() exce.Visible = True wb.WorkSheets[0].Paste() excel.activeWorkbook.SaveAs ("c:\TurnData.xlsx") myturnlist.Close() From recruiter.venkat36 at gmail.com Mon Nov 16 12:21:01 2015 From: recruiter.venkat36 at gmail.com (recruiter.venkat36 at gmail.com) Date: Mon, 16 Nov 2015 09:21:01 -0800 (PST) Subject: Immediate Requirement for IIB/APM Administrator at Orlando, FL. Message-ID: <669ddee7-0e76-45d2-95de-a126d304b4a4@googlegroups.com> Hi , Hope you are doing Good, We have Immediate Requirement for IIB/APM Administrator, Kindly go through the Job Description Below and If interested Please Respond to this Mail. Job Description: Title: IIB/APM Administrator Location: - Orlando, FL Duration: - 3 Months IBM Technical expert is needed to automate the installation and configuration of IIB in multiple environments. Automate the installation and configuration of IBM's APM and APM agents products as well. Job Requirements: * Expertise in installation, configuration and implementation of IBM Products: IIB, APM * Hands-on expertise in jython, wsadmin, msqi and bash shell. * Multi-node on-premise configuration experience with the above products. Consultant will automate the following: * the install and configuration of IIB * the install and configuration of APM * the install and configuration of APM agents 1. Scope Various efforts underway to launch and use IBM's IIB and APM in our environment. Before and/or at the start of this engagement, we expect one manual install of these products to have taken place in a non-production environment. This scope of this position is to perform all work related to automating the install and configuration of these products for subsequent deployments, based on the installation and configuration performed during our initial manual install. 2. Detailed Description of the Services: Consultant will act on behalf of Build Services team performing the following: o Perform all design and development activities around the automation stated above using provided frameworks. Scripting is expected to use jython, wsadmin, mqsi, and bash shell as applicable. o Ensure all developed automation is aligned to and works with build and continuous integration frameworks. o Automation must cover both the initial install and configuration of each product, in addition to providing a framework to make incremental configuration changes over time. o Automation must cover the ability to configure different environments, for example development, testing, etc. Automation should not have to be updated for each environment; instead the automation and scripting should be able to read configuration parameters from the environment and/or a configuration file. o Perform all validation and documentation activities relation to the developed automation, working with applicable teams as required. o Perform development activities relating to the automation of component validation. o Support troubleshooting in relation to execution of using the automation for official environment builds. o Use provided toolsets and procedures for defect tracking. o Perform and participate in reviews, inspections, and turnover procedures to build stakeholders. The client will assist with the following functions during the duration of this project: The Integration and Middleware Technical Lead(s) will perform the following: o Provide final approval design for all automation and continuous integration presented by consultant. o Provide functional subject matter resources for consultants to work with during all project phases. o Provide virtual workstations with VPN connectivity for design and development activities. o Provide an R&D environment that can be used to test automation. o Provide licenses for applicable development and build tools. o Provide incident and defect tracking toolsets. o Frameworks to work within for build, deployment, and continuous integration deliverables. o Participate in reviews, inspections, and turnovers. o Provide information on architecture vision and artifacts. o Provide functional information about the applicable application environments. o Assist in problem resolution. o Approve technical specifications and manual install documentation referencing the initial environment install of which the automation should be based. o Provide information on existing configuration management tools. o Provide content in existing Best Practice Library o Provide functional information about the existing application environment. o Assist in problem resolution. o Provide review, inspection, and turnover process and procedures. Awaiting for your reply Thanks in Anticipation, Val | IT Division Inc.| Direct: 678-740-6997| Val at itdivisioninc.com |www.ITDivisionInc.com| Disclaimer: To be removed from our mailing lists please reply back with the"REMOVE" in subject line. Sorry for any inconvenience. From python at mrabarnett.plus.com Mon Nov 16 12:28:09 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2015 17:28:09 +0000 Subject: import module pyttsx in windows IDLE failed In-Reply-To: References: Message-ID: <564A1229.4040504@mrabarnett.plus.com> On 2015-11-16 17:12, input/ldompeling at casema.nl wrote: > When I try to run this module in Windows IDLE I get this message: > How can I solve this problem. > > Thanks > > Traceback (most recent call last): > File "C:\raspberrypi\recipe-578839-1.py", line 1, in > import pyttsx > ImportError: No module named 'pyttsx' > > This is what I found on the internet: > ------------------------------------------------------------------- > import pyttsx > engine = pyttsx.init() > engine.setProperty('rate', 70) > > voices = engine.getProperty('voices') > for voice in voices: > print ("Using voice:"), repr(voice) > engine.setProperty('voice', voice.id) > engine.say("Hi there, how's you ?") > engine.say("A B C D E F G H I J K L M") > engine.say("N O P Q R S T U V W X Y Z") > engine.say("0 1 2 3 4 5 6 7 8 9") > engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday") > engine.say("Violet Indigo Blue Green Yellow Orange Red") > engine.say("Apple Banana Cherry Date Guava") > engine.runAndWait() > > Have you installed pyttsx? From input/ldompeling at casema.nl Mon Nov 16 12:45:01 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Mon, 16 Nov 2015 17:45:01 GMT Subject: import module pyttsx in windows IDLE failed References: Message-ID: In reply to "MRAB" who wrote the following: Have you installed pyttsx? No, I did not. Where can I find pyttsx to install ? Thanks --------------------------------------------------------------------- > On 2015-11-16 17:12, input/ldompeling at casema.nl wrote: > > When I try to run this module in Windows IDLE I get this message: > > How can I solve this problem. > > > > Thanks > > > > Traceback (most recent call last): > > File "C:\raspberrypi\recipe-578839-1.py", line 1, in > > import pyttsx > > ImportError: No module named 'pyttsx' > > > > This is what I found on the internet: > > ------------------------------------------------------------------- > > import pyttsx > > engine = pyttsx.init() > > engine.setProperty('rate', 70) > > > > voices = engine.getProperty('voices') > > for voice in voices: > > print ("Using voice:"), repr(voice) > > engine.setProperty('voice', voice.id) > > engine.say("Hi there, how's you ?") > > engine.say("A B C D E F G H I J K L M") > > engine.say("N O P Q R S T U V W X Y Z") > > engine.say("0 1 2 3 4 5 6 7 8 9") > > engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday") > > engine.say("Violet Indigo Blue Green Yellow Orange Red") > > engine.say("Apple Banana Cherry Date Guava") > > engine.runAndWait() > > > > > Have you installed pyttsx? -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From vindhyachal.takniki at gmail.com Mon Nov 16 12:58:06 2015 From: vindhyachal.takniki at gmail.com (Vindhyachal Takniki) Date: Mon, 16 Nov 2015 09:58:06 -0800 (PST) Subject: Getting started Image processing python Message-ID: <42aecae4-f219-425f-be6c-97e6cf059546@googlegroups.com> 1. I want to learn basic image processing in python. (working on raspberry pi 2 board) 2. I have a image with different color dots like red,white, etc.After taking image, need to identify how many are red,white etc. I am looking for free image processing libs for that. Which one is better for begineers : http://scikit-image.org/download.html or http://opencv-python-tutroals.readthedocs.org/en/latest/index.html ? From python at mrabarnett.plus.com Mon Nov 16 13:12:51 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2015 18:12:51 +0000 Subject: import module pyttsx in windows IDLE failed In-Reply-To: References: Message-ID: <564A1CA3.3000002@mrabarnett.plus.com> On 2015-11-16 17:45, input/ldompeling at casema.nl wrote: > In reply to "MRAB" who wrote the following: > Have you installed pyttsx? > > No, I did not. > Where can I find pyttsx to install ? > The first place to look is PyPI. It's here: https://pypi.python.org/pypi/pyttsx You might want to look at the links for the homepage and documentation. That mentions a later version. > Thanks > --------------------------------------------------------------------- >> On 2015-11-16 17:12, input/ldompeling at casema.nl wrote: >> > When I try to run this module in Windows IDLE I get this message: >> > How can I solve this problem. >> > >> > Thanks >> > >> > Traceback (most recent call last): >> > File "C:\raspberrypi\recipe-578839-1.py", line 1, in >> > import pyttsx >> > ImportError: No module named 'pyttsx' >> > >> > This is what I found on the internet: >> > ------------------------------------------------------------------- >> > import pyttsx >> > engine = pyttsx.init() >> > engine.setProperty('rate', 70) >> > >> > voices = engine.getProperty('voices') >> > for voice in voices: >> > print ("Using voice:"), repr(voice) >> > engine.setProperty('voice', voice.id) >> > engine.say("Hi there, how's you ?") >> > engine.say("A B C D E F G H I J K L M") >> > engine.say("N O P Q R S T U V W X Y Z") >> > engine.say("0 1 2 3 4 5 6 7 8 9") >> > engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday") >> > engine.say("Violet Indigo Blue Green Yellow Orange Red") >> > engine.say("Apple Banana Cherry Date Guava") >> > engine.runAndWait() >> > >> > >> Have you installed pyttsx? > From tjreedy at udel.edu Mon Nov 16 13:20:28 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2015 13:20:28 -0500 Subject: import module pyttsx in windows IDLE failed In-Reply-To: References: Message-ID: On 11/16/2015 12:45 PM, input/ldompeling at casema.nl wrote: > In reply to "MRAB" who wrote the following: > Have you installed pyttsx? > > No, I did not. > Where can I find pyttsx to install ? Let pip find it (its on pypi). On a command line, enter 'pip install pyttsx' -- Terry Jan Reedy From motoom at xs4all.nl Mon Nov 16 13:20:59 2015 From: motoom at xs4all.nl (Michiel Overtoom) Date: Mon, 16 Nov 2015 19:20:59 +0100 Subject: write data in Excel using python In-Reply-To: <3267f6a3-a047-4abf-80bf-8fdba3659223@googlegroups.com> References: <3267f6a3-a047-4abf-80bf-8fdba3659223@googlegroups.com> Message-ID: <9559B3D4-FF2F-4CCA-8C52-BF0D1988755E@xs4all.nl> Hi, > On 16 Nov 2015, at 18:14, syedmwaliullah at gmail.com wrote: > For some reason it doesn't save the file. Did you get an error message? > excel.activeWorkbook.SaveAs ("c:\TurnData.xlsx") When you use backslashes in strings, don't forget to escape them: > excel.activeWorkbook.SaveAs("c:\\TurnData.xlsx") or use raw strings: > excel.activeWorkbook.SaveAs(r"c:\TurnData.xlsx") Greetings, From chris at chrullrich.net Mon Nov 16 13:38:09 2015 From: chris at chrullrich.net (Christian Ullrich) Date: Mon, 16 Nov 2015 19:38:09 +0100 Subject: Running latest 32-bit Python on 64-bit system In-Reply-To: References: Message-ID: * Zachary Ware wrote: > On Fri, Nov 13, 2015 at 4:52 AM, Christian Ullrich wrote: >> However, with the shebang syntax supported by the launcher, I can only >> demand a 32-bit version if I also specify the Python minor version I want, >> and I don't necessarily know that in advance. >> >> I can code around that, of course, but I don't want to. If Python can select >> the 64-bit version to run by itself, it should also be able to for the >> 32-bit version, right? > > I don't think there's currently a way to do what you want, but it > seems like a reasonable thing to do. Would you mind raising an > enhancement request on bugs.python.org? . Crossing my fingers ... > About the closest you could come currently would be to specify the > full path to the interpreter, but of course that may vary by machine. And it would include the version number in either the path (Windows) or the file name (elsewhere) again, rather defeating the purpose. Thanks for your help, -- Christian From input/ldompeling at casema.nl Mon Nov 16 15:03:30 2015 From: input/ldompeling at casema.nl (input/ldompeling at casema.nl) Date: Mon, 16 Nov 2015 20:03:30 GMT Subject: import module pyttsx in windows IDLE failed References: Message-ID: Now I get this error: Traceback (most recent call last): File "C:\raspberrypi\recipe-578839-1.py", line 1, in import pyttsx File "C:\Users\loek\AppData\Local\Programs\Python\Python35\lib\site-packages\pyttsx\__init__.py", line 18, in from engine import Engine ImportError: No module named 'engine' =========================================================================================================================== In reply to "Terry Reedy" who wrote the following: > On 11/16/2015 12:45 PM, input/ldompeling at casema.nl wrote: > > In reply to "MRAB" who wrote the following: > > Have you installed pyttsx? > > > > No, I did not. > > Where can I find pyttsx to install ? > > Let pip find it (its on pypi). > On a command line, enter 'pip install pyttsx' > > -- > Terry Jan Reedy -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From acropolis7844 at yahoo.com Mon Nov 16 16:08:33 2015 From: acropolis7844 at yahoo.com (Robert Ziomkowski) Date: Mon, 16 Nov 2015 21:08:33 +0000 (UTC) Subject: Trouble installing Python 3.5.0 References: <1479749727.6211494.1447708113131.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1479749727.6211494.1447708113131.JavaMail.yahoo@mail.yahoo.com> Hello, I installed 3.5, "successfully" as the installer indicated, yet the program wouldn't run, with the following error message: "...failed to start because api-ms-win-crt-runtime-I1-1-0.dll was not found. Re-installing the application may fix this problem." I reinstalled, but no luck. I noticed during installation that all the files were 64-bit (as my computer is), except one: the Launcher appears as 32-bit. Could that be the source of the problem? (The error occurs during launch, after all.) The installer I used is "python-3.5.0-amd64.exe" downloaded from Python.org directly. Could you have accidentally shipped the 32-bit Launcher with the 64-bit exe? There was one other wrinkle. When I first installed Python 3.5, I accidentally installed the 32-bit version, because it is what came up when I pressed the big yellow button for 3.5 on your site (next to the other yellow button for Python 2.7.10). In a moment of forgetfulness I didn't check for the 64-bit version. Could this have messed things up? I uninstalled a couple times, so it should have cleared things up. But maybe not? I found the 64-bit version later, but it was a bit hard to find. Why are you putting the 32-bit version out front and center, and not offering an option for the 64-bit right next to it? Best wishes, Robert Z. P.S. I'm running Vista, so my PC is a bit old, but it is in fact 64-bit, and Python 3.2 still runs fine on it. From ian.g.kelly at gmail.com Mon Nov 16 19:22:39 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 16 Nov 2015 17:22:39 -0700 Subject: write data in Excel using python In-Reply-To: <9559B3D4-FF2F-4CCA-8C52-BF0D1988755E@xs4all.nl> References: <3267f6a3-a047-4abf-80bf-8fdba3659223@googlegroups.com> <9559B3D4-FF2F-4CCA-8C52-BF0D1988755E@xs4all.nl> Message-ID: On Mon, Nov 16, 2015 at 11:20 AM, Michiel Overtoom wrote: > > Hi, > >> On 16 Nov 2015, at 18:14, syedmwaliullah at gmail.com wrote: >> For some reason it doesn't save the file. > > Did you get an error message? > >> excel.activeWorkbook.SaveAs ("c:\TurnData.xlsx") > > When you use backslashes in strings, don't forget to escape them: > >> excel.activeWorkbook.SaveAs("c:\\TurnData.xlsx") > > or use raw strings: > >> excel.activeWorkbook.SaveAs(r"c:\TurnData.xlsx") You can also just use a forward slash: excel.activeWorkbook.SaveAs("c:/TurnData.xlsx") Windows happily accepts this. From tdsperth at gmail.com Mon Nov 16 20:43:18 2015 From: tdsperth at gmail.com (tdsperth at gmail.com) Date: Mon, 16 Nov 2015 17:43:18 -0800 (PST) Subject: write data in Excel using python In-Reply-To: <3267f6a3-a047-4abf-80bf-8fdba3659223@googlegroups.com> References: <3267f6a3-a047-4abf-80bf-8fdba3659223@googlegroups.com> Message-ID: <317940a3-ac2f-4d0a-8ed5-9395cca9835b@googlegroups.com> On Tuesday, November 17, 2015 at 1:14:56 AM UTC+8, SW wrote: > hi, > I am trying to write Excel file suing output from another software where the output comes as myturnlist.Show() > > The first part is for the output from the software which is saved in the clipboard. > > The big middle part works to open Excel and save the data into excel file called "TurnData.xlsx". > > For some reason it doesn't save the file. > > Any idea? > > Thanks in advance. > > > import VisumPy.excel > > # Write to Excel > > myturnlist.Show() > turnData = myturnlist.SaveToClipboard(59,0) > > excel = win32com.client.Dispatch("Excel.Application") > wb = excel.Workbooks.Add() > exce.Visible = True > wb.WorkSheets[0].Paste() > excel.activeWorkbook.SaveAs ("c:\TurnData.xlsx") > > myturnlist.Close() Take out exce.Visible = True ( which I believe is atypo) Colin From Seymore4Head at Hotmail.invalid Mon Nov 16 23:29:01 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 16 Nov 2015 23:29:01 -0500 Subject: palindrome Message-ID: http://www.practicepython.org/exercise/2014/03/12/06-string-lists.html Here is my answers. What would make it better? import random str1="" letcount=4 count=0 abc='abcdefghijklmnopqrstuvwxyz' while True: for i in range(letcount): a=random.choice(abc) str1+=a print str1 count+=1 if str1==str1[::-1]: break else: str1="" print "Tries= ",count print str1 From abhi.darkness at gmail.com Mon Nov 16 23:39:27 2015 From: abhi.darkness at gmail.com (Abhiram R) Date: Tue, 17 Nov 2015 10:09:27 +0530 Subject: palindrome In-Reply-To: References: Message-ID: On Tue, Nov 17, 2015 at 9:59 AM, Seymore4Head wrote: > http://www.practicepython.org/exercise/2014/03/12/06-string-lists.html > > Here is my answers. What would make it better? > > import random > str1="" > letcount=4 > count=0 > abc='abcdefghijklmnopqrstuvwxyz' > while True: > for i in range(letcount): > a=random.choice(abc) > str1+=a > print str1 > count+=1 > if str1==str1[::-1]: > break > else: > str1="" > print "Tries= ",count > print str1 > -- > > ? The question asks to get an input from the user and print if it's a palindrome or not. It should be just strA=raw_input() if strA==strA[::-1]: print "Palindrome" else: print "Not" Right? Am I missing something? Why are you generating random strings and trying to check for palindromes?? Thanks Abhiram R (IRC - abhiii5459_ ; Twitter - https://twitter.com/abhiii5459) From Seymore4Head at Hotmail.invalid Mon Nov 16 23:48:48 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Mon, 16 Nov 2015 23:48:48 -0500 Subject: palindrome References: Message-ID: <78cl4bljie79vqr80d1g084jm8ma3k0r9k@4ax.com> On Tue, 17 Nov 2015 10:09:27 +0530, Abhiram R wrote: >On Tue, Nov 17, 2015 at 9:59 AM, Seymore4Head >wrote: > >> http://www.practicepython.org/exercise/2014/03/12/06-string-lists.html >> >> Here is my answers. What would make it better? >> >> import random >> str1="" >> letcount=4 >> count=0 >> abc='abcdefghijklmnopqrstuvwxyz' >> while True: >> for i in range(letcount): >> a=random.choice(abc) >> str1+=a >> print str1 >> count+=1 >> if str1==str1[::-1]: >> break >> else: >> str1="" >> print "Tries= ",count >> print str1 >> -- >> >> ? > >The question asks to get an input from the user and print if it's a >palindrome or not. >It should be just > >strA=raw_input() >if strA==strA[::-1]: > print "Palindrome" >else: > print "Not" > >Right? Am I missing something? Why are you generating random strings and >trying to check for palindromes?? > The instructions do ask for input. I am lazy. I thought it would be cool to have random input instead of just typing a phrase. From abhi.darkness at gmail.com Mon Nov 16 23:55:47 2015 From: abhi.darkness at gmail.com (Abhiram R) Date: Tue, 17 Nov 2015 10:25:47 +0530 Subject: palindrome In-Reply-To: <78cl4bljie79vqr80d1g084jm8ma3k0r9k@4ax.com> References: <78cl4bljie79vqr80d1g084jm8ma3k0r9k@4ax.com> Message-ID: On Tue, Nov 17, 2015 at 10:18 AM, Seymore4Head wrote: > On Tue, 17 Nov 2015 10:09:27 +0530, Abhiram R > wrote: > > >On Tue, Nov 17, 2015 at 9:59 AM, Seymore4Head > > >wrote: > > > >> http://www.practicepython.org/exercise/2014/03/12/06-string-lists.html > >> > >> Here is my answers. What would make it better? > >> > >> import random > >> str1="" > >> letcount=4 > >> count=0 > >> abc='abcdefghijklmnopqrstuvwxyz' > >> while True: > >> for i in range(letcount): > >> a=random.choice(abc) > >> str1+=a > >> print str1 > >> count+=1 > >> if str1==str1[::-1]: > >> break > >> else: > >> str1="" > >> print "Tries= ",count > >> print str1 > >> -- > >> > >> ? > > > >The question asks to get an input from the user and print if it's a > >palindrome or not. > >It should be just > > > >strA=raw_input() > >if strA==strA[::-1]: > > print "Palindrome" > >else: > > print "Not" > > > >Right? Am I missing something? Why are you generating random strings and > >trying to check for palindromes?? > > > The instructions do ask for input. I am lazy. I thought it would be > cool to have random input instead of just typing a phrase. > -- > > ?Haha. Nice. Although with your length of string and the range you're picking from,the chances of you getting a palindrome are (1/24!) :D ? -- -Abhiram R From gandalf at shopzeus.com Tue Nov 17 03:24:41 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Tue, 17 Nov 2015 09:24:41 +0100 Subject: pybabel: default locale is None ??? Message-ID: <564AE449.5010108@shopzeus.com> Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32 >>> from datetime import timedelta >>> from babel.dates import format_timedelta >>> td = timedelta(seconds=39.28355172422679) >>> format_timedelta(td) Traceback (most recent call last): File "", line 1, in File "C:\Python35\lib\site-packages\babel\dates.py", line 779, in format_timedelta plural_form = locale.plural_form(value) AttributeError: 'NoneType' object has no attribute 'plural_form' >>> from babel.core import default_locale >>> repr(default_locale('LC_CTIME')) 'None' Why? The default_locale documentation tells this: "Returns the system default locale for a given category, based on environment variables." From __peter__ at web.de Tue Nov 17 04:31:37 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2015 10:31:37 +0100 Subject: palindrome References: Message-ID: Seymore4Head wrote: > http://www.practicepython.org/exercise/2014/03/12/06-string-lists.html > > Here is my answers. What would make it better? 1. Break the code into functions: one to generate a random string (the desired length could be a parameter) and one to check if the string is a palindrome. With that the loop will become tries = 0 while True: tries += 1 candidate = random_string(length=4) print(candidate) if is_palindrome(candidate): break print(tries, "tries") 2. If you plan to reuse these functions put the above code in a function (let's call it main), too, that you invoke with if __name__ == "__main__": main() to avoid that the code is executed when you import the module instead of running it as a script. 3. For better readability add spaces around operators. There is a tool called pep8 that will point out where you are breaking the standard Python coding conventions. 4. Minor rewrites: 4.1 Can you rewrite the while loop as a for loop? for tries in ...: ... Hint 1: you can put a while loop into a generator Hint 2: there's a ready-made solution in itertools. 4.2 Can you build the random string using a generator expression and "".join(...)? > import random > str1="" > letcount=4 > count=0 > abc='abcdefghijklmnopqrstuvwxyz' > while True: > for i in range(letcount): > a=random.choice(abc) > str1+=a > print str1 > count+=1 > if str1==str1[::-1]: > break > else: > str1="" > print "Tries= ",count > print str1 From __peter__ at web.de Tue Nov 17 04:48:36 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2015 10:48:36 +0100 Subject: palindrome References: <78cl4bljie79vqr80d1g084jm8ma3k0r9k@4ax.com> Message-ID: Abhiram R wrote: > ?Haha. Nice. Although with your length of string and the range you're > picking from,the chances of you getting a palindrome are (1/24!) :D ? Are you sure? >>> candidates = list(itertools.product(string.ascii_lowercase, repeat=4)) >>> len(candidates)/len([c for c in candidates if c == c[::-1]]) 676.0 That looks like one in 26**(length//2) From df at see.replyto.invalid Tue Nov 17 04:54:31 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Tue, 17 Nov 2015 09:54:31 +0000 Subject: Problems using struct pack/unpack in files, and reading them. References: <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <87vb94ikuv.fsf@elektro.pacujo.net> <5649c807$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5isl4bpluclfm0fhj3aa7a4u4gj1n2c4nh@4ax.com> Steven D'Aprano wrote: >On Mon, 16 Nov 2015 05:15 pm, Gregory Ewing wrote: > >> Ints are not the only thing that // can be applied to: >> >> >>> 1.0//0.01 >> 99.0 > >Good catch! Hmmm. I see that the float for 0.01 _is_ slightly larger than 0.01 >>> Decimal(0.01) Decimal('0.01000000000000000020816681711721685132943093776702880859375') But it seems that 1.0 // 0.01 is not directly equivalent to: >>> int(1.0 / 0.01) 100 And I see that: >>> Decimal(1.0 / 0.01) Decimal('100') >>> floor(1.0 / 0.01) 100 >>> 0.01 * 100.0 - 1.0 0.0 So I guess that the // operator is _very_ strict in its "floor division" of floats, but that the "/" operator returns the nearest float value. From michael at stroeder.com Tue Nov 17 05:14:21 2015 From: michael at stroeder.com (=?UTF-8?Q?Michael_Str=c3=b6der?=) Date: Tue, 17 Nov 2015 11:14:21 +0100 Subject: JOSE modules Message-ID: HI! It seems there are already three modules for implementing JOSE (see RFC 7515..7520). :-/ Anyone here who has practical experience with any of them (with Python 2.7.x and preferrably with elliptic curves)? Ciao, Michael. pyjwkest https://pypi.python.org/pypi/pyjwkest JWCrypto https://pypi.python.org/pypi/jwcrypto http://jwcrypto.readthedocs.org/en/stable/index.html python-jose https://pypi.python.org/pypi/python-jose From alexander_naumov at opensuse.org Tue Nov 17 05:44:42 2015 From: alexander_naumov at opensuse.org (Alex Naumov) Date: Tue, 17 Nov 2015 11:44:42 +0100 Subject: HTTPSConnection from http.client? Message-ID: Hello, does anybody know how to create a HTTPS connections in python2 or python3? I tried second day to do that with http.client[1], but every time get error: from http.client import HTTPSConnection ImportError: cannot import name HTTPSConnection Where is HTTPSConnection located? Which module? I use openSUSE 13.1 x86_64. Thank you, Alex [1] https://docs.python.org/3/library/http.client.html From __peter__ at web.de Tue Nov 17 06:22:50 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2015 12:22:50 +0100 Subject: HTTPSConnection from http.client? References: Message-ID: Alex Naumov wrote: > Hello, > > does anybody know how to create a HTTPS connections in python2 or python3? > I tried second day to do that with http.client[1], but every time get > error: > > from http.client import HTTPSConnection > ImportError: cannot import name HTTPSConnection > > > Where is HTTPSConnection located? Which module? > > I use openSUSE 13.1 x86_64. > > Thank you, > Alex > > > [1] https://docs.python.org/3/library/http.client.html Did you compile Python from source? You may be missing the development packages. If you are using the Python provided by the distribution, perhaps support for SSL is in a separate package? Note that I'm guessing, I don't have openSUSE. From marko at pacujo.net Tue Nov 17 06:41:23 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Nov 2015 13:41:23 +0200 Subject: HTTPSConnection from http.client? References: Message-ID: <87lh9wrgyk.fsf@elektro.pacujo.net> Peter Otten <__peter__ at web.de>: > Alex Naumov wrote: >> I tried second day to do that with http.client[1], but every time get >> error: >> >> from http.client import HTTPSConnection >> ImportError: cannot import name HTTPSConnection >> [...] >> I use openSUSE 13.1 x86_64. > > Did you compile Python from source? You may be missing the development > packages. > > If you are using the Python provided by the distribution, perhaps support > for SSL is in a separate package? > > Note that I'm guessing, I don't have openSUSE. On a minimal SLES-12-x86_64 installation: $ python3 Python 3.4.1 (default, Jun 19 2014, 14:40:48) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from http.client import HTTPSConnection >>> Marko From alexander_naumov at opensuse.org Tue Nov 17 07:34:56 2015 From: alexander_naumov at opensuse.org (Alex Naumov) Date: Tue, 17 Nov 2015 13:34:56 +0100 Subject: HTTPSConnection from http.client? In-Reply-To: References: Message-ID: On Tue, Nov 17, 2015 at 12:22 PM, Peter Otten <__peter__ at web.de> wrote: > Alex Naumov wrote: > >> Hello, >> >> does anybody know how to create a HTTPS connections in python2 or python3? >> I tried second day to do that with http.client[1], but every time get >> error: >> >> from http.client import HTTPSConnection >> ImportError: cannot import name HTTPSConnection >> >> >> Where is HTTPSConnection located? Which module? >> >> I use openSUSE 13.1 x86_64. >> >> Thank you, >> Alex >> >> >> [1] https://docs.python.org/3/library/http.client.html > > Did you compile Python from source? No, I install it as a package. > You may be missing the development > packages. Yes, it looks like some packages are not there. > On a minimal SLES-12-x86_64 installation: Can you tell me what's the name of package with http.client module please? Thank you, Alex From __peter__ at web.de Tue Nov 17 08:24:45 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2015 14:24:45 +0100 Subject: HTTPSConnection from http.client? References: Message-ID: Alex Naumov wrote: > On Tue, Nov 17, 2015 at 12:22 PM, Peter Otten <__peter__ at web.de> wrote: >> Alex Naumov wrote: >> >>> Hello, >>> >>> does anybody know how to create a HTTPS connections in python2 or >>> python3? I tried second day to do that with http.client[1], but every >>> time get error: >>> >>> from http.client import HTTPSConnection >>> ImportError: cannot import name HTTPSConnection >>> >>> >>> Where is HTTPSConnection located? Which module? >>> >>> I use openSUSE 13.1 x86_64. >>> >>> Thank you, >>> Alex >>> >>> >>> [1] https://docs.python.org/3/library/http.client.html >> >> Did you compile Python from source? > > No, I install it as a package. > >> You may be missing the development >> packages. > > Yes, it looks like some packages are not there. > > >> On a minimal SLES-12-x86_64 installation: > > Can you tell me what's the name of package with http.client module please? You already have that module as it is part of the Python standard installation. You can double check by importing something that is always available. E. g. the following should succeed on your system >>> from http.client import HTTPConnection >>> What you are likely missing is ssl support. Try >>> import ssl to verify that it fails and post the traceback. Unfortunately my conclusion from Marco's post is that >>> from http.client import HTTPSConnection should succeed on your system without the need for additional packages. Something seems to be broken, but I have no idea what, sorry. From andrea.gavana at gmail.com Tue Nov 17 08:26:49 2015 From: andrea.gavana at gmail.com (andrea.gavana at gmail.com) Date: Tue, 17 Nov 2015 05:26:49 -0800 (PST) Subject: cPickle.load vs. file.read+cPickle.loads on large binary files Message-ID: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> Hello List, I am working with relatively humongous binary files (created via cPickle), and I stumbled across some unexpected (for me) performance differences between two approaches I use to load those files: 1. Simply use cPickle.load(fid) 2. Read the file as binary using file.read() and then use cPickle.loads on the resulting output In the snippet below, the MakePickle function is a dummy function that generates a relatively big binary file with cPickle (WARNING: around 3 GB) in the current directory. I am using NumPy arrays to make the file big but my original data structure is much more complicated, and things like HDF5 or databases are currently not an option - I'd like to stay with pickles. The ReadPickle function simply uses cPickle.load(fid) on the opened binary file, and on my PC it takes about 2.3 seconds (approach 1). The ReadPlusLoads function reads the file using file.read() and then use cPickle.loads on the resulting output (approach 2). On my PC, the file.read() process takes 15 seconds (!!!) and the cPickle.loads only 1.5 seconds. What baffles me is the time it takes to read the file using file.read(): is there any way to slurp it all in one go (somehow) into a string ready for cPickle.loads without that much of an overhead? Note that all of this has been done on Windows 7 64bit with Python 2.7 64bit, with 16 cores and 100 GB RAM (so memory should not be a problem). Thank you in advance for all suggestions :-) . Andrea. # Begin code import os, sys import time import cPickle import numpy class Dummy(object): def __init__(self, name): self.name = name self.data = numpy.random.rand(200, 600, 10) def MakePickle(): num_objects = 300 list_of_objects = [] for index in xrange(num_objects): dummy = Dummy('dummy_%d'%index) list_of_objects.append(dummy) fid = open('dummy.pkl', 'wb') start = time.time() out = cPickle.dumps(list_of_objects, cPickle.HIGHEST_PROTOCOL) end = time.time() print 'cPickle.dumps time:', end-start start = end fid.write(out) end = time.time() print 'file.write time:', end-start fid.close() def ReadPickle(): fid = open('dummy.pkl', 'rb') start = time.time() out = cPickle.load(fid) end = time.time() print 'cPickle.load time:', end-start fid.close() def ReadPlusLoads(): start = time.time() fid = open('dummy.pkl', 'rb') strs = fid.read() fid.close() end = time.time() print 'file.read time:', end-start start = end out = cPickle.loads(strs) end = time.time() print 'cPickle.loads time:', end-start if __name__ == '__main__': ReadPickle() ReadPlusLoads() # End code From __peter__ at web.de Tue Nov 17 09:14:18 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2015 15:14:18 +0100 Subject: cPickle.load vs. file.read+cPickle.loads on large binary files References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> Message-ID: andrea.gavana at gmail.com wrote: > Hello List, > > I am working with relatively humongous binary files (created via > cPickle), and I stumbled across some unexpected (for me) performance > differences between two approaches I use to load those files: > > 1. Simply use cPickle.load(fid) > > 2. Read the file as binary using file.read() and then use cPickle.loads on > the resulting output > > In the snippet below, the MakePickle function is a dummy function that > generates a relatively big binary file with cPickle (WARNING: around 3 GB) > in the current directory. I am using NumPy arrays to make the file big but > my original data structure is much more complicated, and things like HDF5 > or databases are currently not an option - I'd like to stay with pickles. > > The ReadPickle function simply uses cPickle.load(fid) on the opened binary > file, and on my PC it takes about 2.3 seconds (approach 1). > > The ReadPlusLoads function reads the file using file.read() and then use > cPickle.loads on the resulting output (approach 2). On my PC, the > file.read() process takes 15 seconds (!!!) and the cPickle.loads only 1.5 > seconds. > > What baffles me is the time it takes to read the file using file.read(): > is there any way to slurp it all in one go (somehow) into a string ready > for cPickle.loads without that much of an overhead? > > Note that all of this has been done on Windows 7 64bit with Python 2.7 > 64bit, with 16 cores and 100 GB RAM (so memory should not be a problem). > > Thank you in advance for all suggestions :-) . > > Andrea. > > if __name__ == '__main__': > ReadPickle() > ReadPlusLoads() Do you get roughly the same times when you execute ReadPlusLoads() before ReadPIckle()? From andrea.gavana at gmail.com Tue Nov 17 09:20:03 2015 From: andrea.gavana at gmail.com (andrea.gavana at gmail.com) Date: Tue, 17 Nov 2015 06:20:03 -0800 (PST) Subject: cPickle.load vs. file.read+cPickle.loads on large binary files In-Reply-To: References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> Message-ID: <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> Hi Peter, On Tuesday, November 17, 2015 at 3:14:57 PM UTC+1, Peter Otten wrote: > Andrea Gavana wrote: > > > Hello List, > > > > I am working with relatively humongous binary files (created via > > cPickle), and I stumbled across some unexpected (for me) performance > > differences between two approaches I use to load those files: > > > > 1. Simply use cPickle.load(fid) > > > > 2. Read the file as binary using file.read() and then use cPickle.loads on > > the resulting output > > > > In the snippet below, the MakePickle function is a dummy function that > > generates a relatively big binary file with cPickle (WARNING: around 3 GB) > > in the current directory. I am using NumPy arrays to make the file big but > > my original data structure is much more complicated, and things like HDF5 > > or databases are currently not an option - I'd like to stay with pickles. > > > > The ReadPickle function simply uses cPickle.load(fid) on the opened binary > > file, and on my PC it takes about 2.3 seconds (approach 1). > > > > The ReadPlusLoads function reads the file using file.read() and then use > > cPickle.loads on the resulting output (approach 2). On my PC, the > > file.read() process takes 15 seconds (!!!) and the cPickle.loads only 1.5 > > seconds. > > > > What baffles me is the time it takes to read the file using file.read(): > > is there any way to slurp it all in one go (somehow) into a string ready > > for cPickle.loads without that much of an overhead? > > > > Note that all of this has been done on Windows 7 64bit with Python 2.7 > > 64bit, with 16 cores and 100 GB RAM (so memory should not be a problem). > > > > Thank you in advance for all suggestions :-) . > > > > Andrea. > > > > if __name__ == '__main__': > > ReadPickle() > > ReadPlusLoads() > > Do you get roughly the same times when you execute ReadPlusLoads() before > ReadPIckle()? Thank you for your answer. I do get similar timings when I swap the two functions, and specifically still 15 seconds to read the file via file.read() and 2.4 seconds (more or less as before) via cPickle.load(fid). I thought that the order of operations might be an issue but apparently that was not the case... Andrea. From nicoe at altern.org Tue Nov 17 09:27:39 2015 From: nicoe at altern.org (Nicolas =?utf-8?Q?=C3=89vrard?=) Date: Tue, 17 Nov 2015 11:27:39 -0300 Subject: Which type should be used when testing static structure appartenance Message-ID: <20151117142739.GC20735@localhost.localdomain> Hello, I saw the following retweet by Raymond Hettinger in this morning: https://twitter.com/sanityinc/status/666485814214287360 Programming tip: many of those arrays and hashes in your code should actually be sets. Match data structures to data constraints! I saw just in time because in a review I wrote something like this: if operator not in ('where', 'not where') and my colleague proposed that I should use a list instead of a tuple. But reading the mentioned tweet I tend to think that a set would be a better choice. What are your opinion on this issue (I realize it's not something of the utmost importance but rather a "philosophical" question). -- Nicolas ?vrard - B2CK SPRL E-mail/Jabber: nicolas.evrard at b2ck.com Tel: +32 472 54 46 59 Website: http://www.b2ck.com/ From gandalf at shopzeus.com Tue Nov 17 09:45:58 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Tue, 17 Nov 2015 15:45:58 +0100 Subject: Trouble installing Python 3.5.0 In-Reply-To: <1479749727.6211494.1447708113131.JavaMail.yahoo@mail.yahoo.com> References: <1479749727.6211494.1447708113131.JavaMail.yahoo.ref@mail.yahoo.com> <1479749727.6211494.1447708113131.JavaMail.yahoo@mail.yahoo.com> Message-ID: <564B3DA6.5080401@shopzeus.com> > Hello, > > I installed 3.5, "successfully" as the installer indicated, yet the program wouldn't run, with the following error message: "...failed to start because api-ms-win-crt-runtime-I1-1-0.dll was not found. Re-installing the application may fix this problem." I reinstalled, but no luck. I think Vista and XP was supported up to Python 3.4. The newest Python 3.5 does not support Vista or XP. From gandalf at shopzeus.com Tue Nov 17 09:51:45 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Tue, 17 Nov 2015 15:51:45 +0100 Subject: Trouble installing Python 3.5.0 In-Reply-To: <564B3DA6.5080401@shopzeus.com> References: <1479749727.6211494.1447708113131.JavaMail.yahoo.ref@mail.yahoo.com> <1479749727.6211494.1447708113131.JavaMail.yahoo@mail.yahoo.com> <564B3DA6.5080401@shopzeus.com> Message-ID: <564B3F01.2000901@shopzeus.com> >> Hello, >> >> I installed 3.5, "successfully" as the installer indicated, yet the program wouldn't run, with the following error message: "...failed to start because api-ms-win-crt-runtime-I1-1-0.dll was not found. Re-installing the application may fix this problem." I reinstalled, but no luck. > I think Vista and XP was supported up to Python 3.4. The newest Python > 3.5 does not support Vista or XP. https://docs.python.org/3.5/whatsnew/3.5.html You will find this under "Unsupported Operating Systems" section. Although Vista is not mentioned there, but Python 3.5 is built with Microsoft Visual Studio 2015, and its runtime library is AFAIK does not work under Vista. From rosuav at gmail.com Tue Nov 17 10:20:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Nov 2015 02:20:04 +1100 Subject: cPickle.load vs. file.read+cPickle.loads on large binary files In-Reply-To: <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> Message-ID: On Wed, Nov 18, 2015 at 1:20 AM, wrote: > Thank you for your answer. I do get similar timings when I swap the two functions, and specifically still 15 seconds to read the file via file.read() and 2.4 seconds (more or less as before) via cPickle.load(fid). > > I thought that the order of operations might be an issue but apparently that was not the case... What if you call one of them twice and then the other? Just trying to rule out any possibility that it's a caching problem. On my Linux box, running 2.7.9 64-bit, the two operations take roughly the same amount of time (1.8 seconds for load vs 1s to read and 0.8 to loads). Are you able to run this off a RAM disk or something? Most curious. ChrisA From rosuav at gmail.com Tue Nov 17 10:28:31 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Nov 2015 02:28:31 +1100 Subject: Which type should be used when testing static structure appartenance In-Reply-To: <20151117142739.GC20735@localhost.localdomain> References: <20151117142739.GC20735@localhost.localdomain> Message-ID: On Wed, Nov 18, 2015 at 1:27 AM, Nicolas ?vrard wrote: > I saw just in time because in a review I wrote something like this: > > if operator not in ('where', 'not where') > > and my colleague proposed that I should use a list instead of a tuple. > But reading the mentioned tweet I tend to think that a set would be a > better choice. > > What are your opinion on this issue (I realize it's not something of > the utmost importance but rather a "philosophical" question). Definitely a set. I don't know why it would be better to use a list; there's no advantage here for the list. "x [not] in some_set" accurately represents the concept of "any of these will match". With a two-element list/tuple/set, I doubt there's going to be any significant performance difference, but if anything, I would expect the tuple to be the fastest (because it can be stored as a literal), and the other two need to be built; but CPython's optimizer has me beat there - they're all stored as literals (the list becomes a tuple, the set becomes a frozenset), meaning there's basically no difference. So you're free to use the one that expresses the concept of "is this part of this set of strings", which is the set. ChrisA From andrea.gavana at gmail.com Tue Nov 17 10:31:50 2015 From: andrea.gavana at gmail.com (andrea.gavana at gmail.com) Date: Tue, 17 Nov 2015 07:31:50 -0800 (PST) Subject: cPickle.load vs. file.read+cPickle.loads on large binary files In-Reply-To: References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> Message-ID: <420ec4e9-6af6-49bd-a9f4-8b47ef1f136e@googlegroups.com> Hi Chris, On Tuesday, November 17, 2015 at 4:20:34 PM UTC+1, Chris Angelico wrote: > On Wed, Nov 18, 2015 at 1:20 AM, Andrea Gavana wrote: > > Thank you for your answer. I do get similar timings when I swap the two functions, and specifically still 15 seconds to read the file via file.read() and 2.4 seconds (more or less as before) via cPickle.load(fid). > > > > I thought that the order of operations might be an issue but apparently that was not the case... > > What if you call one of them twice and then the other? Just trying to > rule out any possibility that it's a caching problem. > > On my Linux box, running 2.7.9 64-bit, the two operations take roughly > the same amount of time (1.8 seconds for load vs 1s to read and 0.8 to > loads). Are you able to run this off a RAM disk or something? > > Most curious. Thank you for taking the time to run my little script. I have now run it with multiple combinations of calls (twice the first then the other, then viceversa, then alternate between the two functions multiple times, then three times the second and once the first, ...) with no luck at all. The file.read() line of code takes always at minimum 14 seconds (in all the trials I have done), while the cPickle.load call ranges between 2.3 and 2.5 seconds. I am puzzled with no end... Might there be something funny with my C libraries that use fread? I'm just shooting in the dark. I have a standard Python installation on Windows, nothing fancy :-( Andrea. From alexander_naumov at opensuse.org Tue Nov 17 10:47:05 2015 From: alexander_naumov at opensuse.org (Alex Naumov) Date: Tue, 17 Nov 2015 16:47:05 +0100 Subject: HTTPSConnection from http.client? In-Reply-To: References: Message-ID: Hello Peter, thanks for your reply. >>> import ssl Works well in python2 and 3. Maybe somebody know another way to create a SSL connection (username/password)? I just need to log in and log out. Thanks, Alex On Tue, Nov 17, 2015 at 2:24 PM, Peter Otten <__peter__ at web.de> wrote: > Alex Naumov wrote: > >> On Tue, Nov 17, 2015 at 12:22 PM, Peter Otten <__peter__ at web.de> wrote: >>> Alex Naumov wrote: >>> >>>> Hello, >>>> >>>> does anybody know how to create a HTTPS connections in python2 or >>>> python3? I tried second day to do that with http.client[1], but every >>>> time get error: >>>> >>>> from http.client import HTTPSConnection >>>> ImportError: cannot import name HTTPSConnection >>>> >>>> >>>> Where is HTTPSConnection located? Which module? >>>> >>>> I use openSUSE 13.1 x86_64. >>>> >>>> Thank you, >>>> Alex >>>> >>>> >>>> [1] https://docs.python.org/3/library/http.client.html >>> >>> Did you compile Python from source? >> >> No, I install it as a package. >> >>> You may be missing the development >>> packages. >> >> Yes, it looks like some packages are not there. >> >> >>> On a minimal SLES-12-x86_64 installation: >> >> Can you tell me what's the name of package with http.client module please? > > You already have that module as it is part of the Python standard > installation. You can double check by importing something that is always > available. E. g. the following should succeed on your system > >>>> from http.client import HTTPConnection >>>> > > What you are likely missing is ssl support. Try > >>>> import ssl > > to verify that it fails and post the traceback. > > Unfortunately my conclusion from Marco's post is that > >>>> from http.client import HTTPSConnection > > should succeed on your system without the need for additional packages. > Something seems to be broken, but I have no idea what, sorry. > > -- > https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Tue Nov 17 10:57:28 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2015 16:57:28 +0100 Subject: cPickle.load vs. file.read+cPickle.loads on large binary files References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> <420ec4e9-6af6-49bd-a9f4-8b47ef1f136e@googlegroups.com> Message-ID: andrea.gavana at gmail.com wrote: > Hi Chris, > > On Tuesday, November 17, 2015 at 4:20:34 PM UTC+1, Chris Angelico wrote: >> On Wed, Nov 18, 2015 at 1:20 AM, Andrea Gavana wrote: >> > Thank you for your answer. I do get similar timings when I swap the two >> > functions, and specifically still 15 seconds to read the file via >> > file.read() and 2.4 seconds (more or less as before) via >> > cPickle.load(fid). >> > >> > I thought that the order of operations might be an issue but apparently >> > that was not the case... >> >> What if you call one of them twice and then the other? Just trying to >> rule out any possibility that it's a caching problem. >> >> On my Linux box, running 2.7.9 64-bit, the two operations take roughly >> the same amount of time (1.8 seconds for load vs 1s to read and 0.8 to >> loads). Are you able to run this off a RAM disk or something? >> >> Most curious. > > > Thank you for taking the time to run my little script. I have now run it > with multiple combinations of calls (twice the first then the other, then > viceversa, then alternate between the two functions multiple times, then > three times the second and once the first, ...) with no luck at all. > > The file.read() line of code takes always at minimum 14 seconds (in all > the trials I have done), while the cPickle.load call ranges between 2.3 > and 2.5 seconds. > > I am puzzled with no end... Might there be something funny with my C > libraries that use fread? I'm just shooting in the dark. I have a standard > Python installation on Windows, nothing fancy :-( Perhaps there is a size threshold? You could experiment with different block sizes in the following f.read() replacement: def read_chunked(f, size=2**20): read = functools.partial(f.read, size) return "".join(iter(read, "")) From oscar.j.benjamin at gmail.com Tue Nov 17 11:15:37 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Nov 2015 16:15:37 +0000 Subject: Which type should be used when testing static structure appartenance In-Reply-To: <20151117142739.GC20735@localhost.localdomain> References: <20151117142739.GC20735@localhost.localdomain> Message-ID: On 17 November 2015 at 14:27, Nicolas ?vrard wrote: > Hello, > > I saw the following retweet by Raymond Hettinger in this morning: > > https://twitter.com/sanityinc/status/666485814214287360 > > Programming tip: many of those arrays and hashes in your code > should actually be sets. Match data structures to data > constraints! > > I saw just in time because in a review I wrote something like this: > > if operator not in ('where', 'not where') > > and my colleague proposed that I should use a list instead of a tuple. > But reading the mentioned tweet I tend to think that a set would be a > better choice. > > What are your opinion on this issue (I realize it's not something of > the utmost importance but rather a "philosophical" question). Conceptually it should be a set. Really it makes little difference though. I think that what the tip is really referring to is a situation where you have a larger data structure. For example asking if x in y has different algorithmic performance when y is a large tuple/list than a set. This is because a set is a hash-table with O(1) average lookup cost and a tuple/list needs to be scanned linearly having O(N) average cost. This can be very costly and can often be seen in beginner code where someone does something like: for x in stuff: if x in alist: # do stuff Here the "in" operator loops over alist once for each item in stuff (until it finds a match). If there are M things in stuff and N things in alist then this is O(M*N) items to compare. If we convert alist to a set at the start of the loop then we have: aset = set(alist) for xin stuff: if x in aset: # do stuff Here the set constructor scans alist which is O(N) and then for each of M things in stuff we do an O(1) lookup in aset. So the result is O(M+N) meaning linear rather than quadratic performance. This can be a significant difference especially for something so trivially easy to do. -- Oscar From zachary.ware+pylist at gmail.com Tue Nov 17 11:25:08 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 17 Nov 2015 10:25:08 -0600 Subject: Trouble installing Python 3.5.0 In-Reply-To: <564B3F01.2000901@shopzeus.com> References: <1479749727.6211494.1447708113131.JavaMail.yahoo.ref@mail.yahoo.com> <1479749727.6211494.1447708113131.JavaMail.yahoo@mail.yahoo.com> <564B3DA6.5080401@shopzeus.com> <564B3F01.2000901@shopzeus.com> Message-ID: On Tue, Nov 17, 2015 at 8:51 AM, Nagy L?szl? Zsolt wrote: > I think Vista and XP was supported up to Python 3.4. The newest Python > 3.5 does not support Vista or XP. Vista is still supported in Python 3.5, but it requires the Universal CRT update, which requires the latest Service Pack for Vista (see here: https://support.microsoft.com/en-us/kb/2999226). If your Vista is up to date, you should have no problem. It could be argued that if you're not up to date you're not supported by Microsoft and thus not supported by Python, but that may be stretching things a bit. -- Zach From rxjwg98 at gmail.com Tue Nov 17 11:31:08 2015 From: rxjwg98 at gmail.com (fl) Date: Tue, 17 Nov 2015 08:31:08 -0800 (PST) Subject: Help on savefig parameters Message-ID: <38fcc7ab-409d-4050-9058-634d987bcdd8@googlegroups.com> Hi, I find the parameters of savefig function has the similar format of that of main(*argc, **argv) in C. I have tried with savefig("temp.pdf", format='pdf'), and it works. I get the help content of savefig() as below. But I cannot understand why they also give: savefig(fname, dpi=None, facecolor='w', edgecolor='w', ... For me, it looks like the first item, i.e. 'args' is missing. Could you explain it to me? Thanks, //////////////// savefig(*args, **kwargs) Save the current figure. Call signature:: savefig(fname, dpi=None, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=None, transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None) From andrea.gavana at gmail.com Tue Nov 17 11:31:41 2015 From: andrea.gavana at gmail.com (andrea.gavana at gmail.com) Date: Tue, 17 Nov 2015 08:31:41 -0800 (PST) Subject: cPickle.load vs. file.read+cPickle.loads on large binary files In-Reply-To: References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> <420ec4e9-6af6-49bd-a9f4-8b47ef1f136e@googlegroups.com> Message-ID: Hi Peter, On Tuesday, November 17, 2015 at 4:57:57 PM UTC+1, Peter Otten wrote: > Andrea Gavana wrote: > > > Hi Chris, > > > > On Tuesday, November 17, 2015 at 4:20:34 PM UTC+1, Chris Angelico wrote: > >> On Wed, Nov 18, 2015 at 1:20 AM, Andrea Gavana wrote: > >> > Thank you for your answer. I do get similar timings when I swap the two > >> > functions, and specifically still 15 seconds to read the file via > >> > file.read() and 2.4 seconds (more or less as before) via > >> > cPickle.load(fid). > >> > > >> > I thought that the order of operations might be an issue but apparently > >> > that was not the case... > >> > >> What if you call one of them twice and then the other? Just trying to > >> rule out any possibility that it's a caching problem. > >> > >> On my Linux box, running 2.7.9 64-bit, the two operations take roughly > >> the same amount of time (1.8 seconds for load vs 1s to read and 0.8 to > >> loads). Are you able to run this off a RAM disk or something? > >> > >> Most curious. > > > > > > Thank you for taking the time to run my little script. I have now run it > > with multiple combinations of calls (twice the first then the other, then > > viceversa, then alternate between the two functions multiple times, then > > three times the second and once the first, ...) with no luck at all. > > > > The file.read() line of code takes always at minimum 14 seconds (in all > > the trials I have done), while the cPickle.load call ranges between 2.3 > > and 2.5 seconds. > > > > I am puzzled with no end... Might there be something funny with my C > > libraries that use fread? I'm just shooting in the dark. I have a standard > > Python installation on Windows, nothing fancy :-( > > Perhaps there is a size threshold? You could experiment with different block > sizes in the following f.read() replacement: > > def read_chunked(f, size=2**20): > read = functools.partial(f.read, size) > return "".join(iter(read, "")) Thank you for the suggestion. I have used the read_chunked function in my experiments now and I can report a nice improvements - I have tried various chunk sizes, from 2**10 to 2**31-1, and in general the optimum lies around size=2**22, although it is essentially flat from 2**20 up to 2**30 - with some interesting spikes at 45 seconds for 2**14 and 2**15 (see table below). Using your suggestion, I got it down to 3.4 seconds (on average). Still at least twice slower than cPickle.load, but better. What I find most puzzling is that a pure file.read() (or your read_chunked variation) should normally be much faster than a cPickle.load (which does so many more things than just reading a file), shouldn't it? Timing table: Size (power of 2) Read Time (seconds) 10 9.14 11 8.59 12 7.67 13 5.70 14 46.06 15 45.00 16 24.80 17 14.23 18 8.95 19 5.58 20 3.41 21 3.39 22 3.34 23 3.39 24 3.39 25 3.42 26 3.43 27 3.44 28 3.48 29 3.59 30 3.72 From rgaddi at technologyhighland.invalid Tue Nov 17 11:39:15 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Tue, 17 Nov 2015 16:39:15 -0000 (UTC) Subject: Help on savefig parameters References: <38fcc7ab-409d-4050-9058-634d987bcdd8@googlegroups.com> Message-ID: On Tue, 17 Nov 2015 08:31:08 -0800, fl wrote: > Hi, > I find the parameters of savefig function has the similar format of that > of main(*argc, **argv) in C. I have tried with savefig("temp.pdf", > format='pdf'), > and it works. I get the help content of savefig() as below. > But I cannot understand why they also give: > > savefig(fname, dpi=None, facecolor='w', edgecolor='w', ... > > For me, it looks like the first item, i.e. 'args' is missing. > Could you explain it to me? > > Thanks, > > //////////////// > savefig(*args, **kwargs) > Save the current figure. > > Call signature:: > > savefig(fname, dpi=None, facecolor='w', edgecolor='w', > orientation='portrait', papertype=None, format=None, > transparent=False, bbox_inches=None, pad_inches=0.1, > frameon=None) Numpy/scipy/matplotlib are in large part autogenerated code from the underlying libraries; that's where the default *args, **kwargs arguments are coming from. The signature given in the documentation is the one that actually matters. Prefer the web documentation to the inline docs for that entire set of libraries; it'll make your life easier. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From __peter__ at web.de Tue Nov 17 12:20:44 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2015 18:20:44 +0100 Subject: cPickle.load vs. file.read+cPickle.loads on large binary files References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> <420ec4e9-6af6-49bd-a9f4-8b47ef1f136e@googlegroups.com> Message-ID: andrea.gavana at gmail.com wrote: >> > I am puzzled with no end... Might there be something funny with my C >> > libraries that use fread? I'm just shooting in the dark. I have a >> > standard Python installation on Windows, nothing fancy :-( >> >> Perhaps there is a size threshold? You could experiment with different >> block sizes in the following f.read() replacement: >> >> def read_chunked(f, size=2**20): >> read = functools.partial(f.read, size) >> return "".join(iter(read, "")) > > > Thank you for the suggestion. I have used the read_chunked function in my > experiments now and I can report a nice improvements - I have tried > various chunk sizes, from 2**10 to 2**31-1, and in general the optimum > lies around size=2**22, although it is essentially flat from 2**20 up to > 2**30 - with some interesting spikes at 45 seconds for 2**14 and 2**15 > (see table below). > > Using your suggestion, I got it down to 3.4 seconds (on average). Still at > least twice slower than cPickle.load, but better. > > What I find most puzzling is that a pure file.read() (or your read_chunked > variation) should normally be much faster than a cPickle.load (which does > so many more things than just reading a file), shouldn't it? That would have been my expectation, too. I had a quick look into the fileobject.c source and didn't see anything that struck me as suspicious. I think you should file a bug report so that an expert can check if there is an underlying problem in Python or if it is a matter of the OS. > Timing table: > > Size (power of 2) Read Time (seconds) > 10 9.14 > 11 8.59 > 12 7.67 > 13 5.70 > 14 46.06 > 15 45.00 > 16 24.80 > 17 14.23 > 18 8.95 > 19 5.58 > 20 3.41 > 21 3.39 > 22 3.34 > 23 3.39 > 24 3.39 > 25 3.42 > 26 3.43 > 27 3.44 > 28 3.48 > 29 3.59 > 30 3.72 From ian.g.kelly at gmail.com Tue Nov 17 12:49:00 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 17 Nov 2015 10:49:00 -0700 Subject: PEP 484 stubs with generic types Message-ID: Playing around a bit with PEP 484, I annotated a function that returns an asyncio.Future: import asyncio def get_future() -> asyncio.Future[int]: future = asyncio.Future() future.set_result(42) return future The problem with this is that in Python 3.5, asyncio.Future can't be used as a generic type. Fortunately, the typeshed repository provides a stub that defines it as a generic type: https://github.com/python/typeshed/blob/master/stdlib/3.4/asyncio/futures.pyi This is fine for running a static type checker, but it still creates a problem when actually running the code. The real asyncio.Future doesn't support indexing, and so the annotation causes a TypeError at runtime. I could write the annotation as a forward reference, avoiding the TypeError: def get_future() -> "asyncio.Future[int]": ... But PEP 484 stipulates that a forward reference "should evaluate without errors once the module has been fully loaded", so this is invalid. Is there any advice for this case? How are generic types meant to be used with stub files? From rxjwg98 at gmail.com Tue Nov 17 15:51:12 2015 From: rxjwg98 at gmail.com (fl) Date: Tue, 17 Nov 2015 12:51:12 -0800 (PST) Subject: Is there any reason to introduce this intermediate variable (sz)? Message-ID: Hi, I find the following code snippet, which is useful in my project: n_iter = 50 sz = (n_iter,) # size of array x = -0.37727 z = np.random.normal(x,0.1,size=sz) Q = 1e-5 # process variance # allocate space for arrays xhat=np.zeros(sz) P=np.zeros(sz) I learn Python now and the above code seems from an experienced author. The curious thing to me is the variable 'sz'. I have check np.zeros(shape, ..) shape : int or sequence of ints The introduced 'sz' is a tuple. If n_iter function is similar to a constant in C, I don't see the reason for 'sz'. In fact, 'n_iter' is an int, which fits the below np.zeros(shape) correctly. Could you see something useful with variable 'sz'? Thanks, From gordon at panix.com Tue Nov 17 16:02:33 2015 From: gordon at panix.com (John Gordon) Date: Tue, 17 Nov 2015 21:02:33 +0000 (UTC) Subject: Is there any reason to introduce this intermediate variable (sz)? References: Message-ID: In fl writes: > correctly. Could you see something useful with variable 'sz'? 'sz' is fewer characters than '(n_iter,)', which may make your code easier to read. The np.zeros() function explicitly accepts an 'int or sequence of ints', so you don't specifically need a sequence. Is the same true for the 'size' keyword argument of np.random.normal()? -- 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 rxjwg98 at gmail.com Tue Nov 17 16:27:22 2015 From: rxjwg98 at gmail.com (fl) Date: Tue, 17 Nov 2015 13:27:22 -0800 (PST) Subject: Is there any reason to introduce this intermediate variable (sz)? In-Reply-To: References: Message-ID: On Tuesday, November 17, 2015 at 4:03:05 PM UTC-5, John Gordon wrote: > In fl <@gmail.com> writes: > > > correctly. Could you see something useful with variable 'sz'? > > 'sz' is fewer characters than '(n_iter,)', which may make your code easier > to read. > > The np.zeros() function explicitly accepts an 'int or sequence of ints', > so you don't specifically need a sequence. Is the same true for the > 'size' keyword argument of np.random.normal()? > > -- > John Gordon A is for Amy, who fell down the stairs > @panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" Hi, I get the following for the third parameter of np.random.normal(): size : int or tuple of ints, optional I still don't see the necessity of 'sz'. Thanks, From gordon at panix.com Tue Nov 17 17:20:39 2015 From: gordon at panix.com (John Gordon) Date: Tue, 17 Nov 2015 22:20:39 +0000 (UTC) Subject: Is there any reason to introduce this intermediate variable (sz)? References: Message-ID: In fl writes: > I still don't see the necessity of 'sz'. Thanks, sz isn't required. You can use (n_iter,) in place of sz. However, as I posted earlier, sz is shorter so it might make your code easier to read. Using sz can also lead to easier code maintenance. If the contents of the tuple were ever to change, it would be much easier to simply change it in once place (the definition of sz), rather than having to edit several different occurrences of (n_iter,) in your code. -- 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 breamoreboy at yahoo.co.uk Tue Nov 17 17:33:34 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 17 Nov 2015 22:33:34 +0000 Subject: Is there any reason to introduce this intermediate variable (sz)? In-Reply-To: References: Message-ID: On 17/11/2015 21:27, fl wrote: > On Tuesday, November 17, 2015 at 4:03:05 PM UTC-5, John Gordon wrote: >> In fl <@gmail.com> writes: >> >>> correctly. Could you see something useful with variable 'sz'? >> >> 'sz' is fewer characters than '(n_iter,)', which may make your code easier >> to read. >> >> The np.zeros() function explicitly accepts an 'int or sequence of ints', >> so you don't specifically need a sequence. Is the same true for the >> 'size' keyword argument of np.random.normal()? >> >> -- >> John Gordon A is for Amy, who fell down the stairs >> @panix.com B is for Basil, assaulted by bears >> -- Edward Gorey, "The Gashlycrumb Tinies" > > Hi, I get the following for the third parameter of np.random.normal(): > size : int or tuple of ints, optional > > I still don't see the necessity of 'sz'. Thanks, > I don't see the necessity for you to bombard this list with question after question without bothering to try and provide your own answers first. Did your last skivvy die of overwork? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From stephane at wirtel.be Tue Nov 17 22:29:03 2015 From: stephane at wirtel.be (Stephane Wirtel) Date: Wed, 18 Nov 2015 04:29:03 +0100 Subject: Mapping between python packages and distro packages? Message-ID: <20151118032903.GA8040@sg1> Hi, Do you know if there is a library to match a python package (from PyPI) and find the right debian/redhat packages ? Thank you, Stephane -- St?phane Wirtel - http://wirtel.be - @matrixise From ben+python at benfinney.id.au Tue Nov 17 23:33:08 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 18 Nov 2015 15:33:08 +1100 Subject: Mapping between python packages and distro packages? References: <20151118032903.GA8040@sg1> Message-ID: <85vb90c4fv.fsf@benfinney.id.au> Stephane Wirtel writes: > Do you know if there is a library to match a python package (from PyPI) > and find the right debian/redhat packages ? What would count as ?the right package?? Do you mean ?the package that has that PyPI distribution URL in its ?debian/watch? configuration?? Do you mean ?the package that names that PyPI distribution in its ?debian/copyright? ?Source? field?? Or something else? The answers will differ depending on exactly what question is being asked of the data. If you can define exactly what query you want to perform, perhaps a solution can be offered. -- \ ?The Vatican is not a state.? a state must have territory. This | `\ is a palace with gardens, about as big as an average golf | _o__) course.? ?Geoffrey Robertson, 2010-09-18 | Ben Finney From hua_lin at live.cn Tue Nov 17 23:58:30 2015 From: hua_lin at live.cn (=?gb2312?B?z8S7qsHW?=) Date: Wed, 18 Nov 2015 04:58:30 +0000 Subject: how do I learn python ? Message-ID: From rosuav at gmail.com Wed Nov 18 01:44:51 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Nov 2015 17:44:51 +1100 Subject: Mapping between python packages and distro packages? In-Reply-To: <85vb90c4fv.fsf@benfinney.id.au> References: <20151118032903.GA8040@sg1> <85vb90c4fv.fsf@benfinney.id.au> Message-ID: On Wed, Nov 18, 2015 at 3:33 PM, Ben Finney wrote: > What would count as ?the right package?? > > Do you mean ?the package that has that PyPI distribution URL in its > ?debian/watch? configuration?? > > Do you mean ?the package that names that PyPI distribution in its > ?debian/copyright? ?Source? field?? > > Or something else? I don't know how the program would detect it, but I'd be thinking "the one where 'sudo apt-get install PACKAGENAME' gets the same code that 'pip install THING' gets". In a lot of cases, PACKAGENAME will simply be python-THING or python3-THING, eg python3-sqlalchemy, python3-scipy, python3-bs4; as a human, that's what I'd try first. But having a program recognize this would be hugely beneficial. ChrisA From dh at dotcom.mfs32 Wed Nov 18 02:50:30 2015 From: dh at dotcom.mfs32 (Daniel Haude) Date: 18 Nov 2015 07:50:30 GMT Subject: Writing SOME class methods in C Message-ID: Hello, I'm trying to implement some (but not all) methods of a Python class in C. What I've found on the Net is: - how to implement entire modules in C so that I can import that module and use the C functions (successfully done it, too). - how to implement entire classes in C But I can't find any examples of modules which consist of a mixture of C and Python, nor modules that define classes of which some members are implemented in C, others in Python. Of course, once I have the "mixture" bit figured out I could just define wrapper class methods that call C functions (functions impleneted in C, that is). But I would find it rather elegant if the C function could access the class members directly. The fact that the C extension functions have a mandatory "PyObject *self" parameter tells me that this must be somehow possible, but I don't know how. I'm sure that many of the plethora of Python extension modules out there must use the technique that I'm looking for, but I don't even know where to start looking. Pointers are welcome. Thanks, robert From df at see.replyto.invalid Wed Nov 18 03:05:37 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Wed, 18 Nov 2015 08:05:37 +0000 Subject: Is there any reason to introduce this intermediate variable (sz)? References: Message-ID: fl wrote: >Hi, >I find the following code snippet, which is useful in my project: > ... >correctly. Could you see something useful with variable 'sz'? So that's example code in "An Introduction to the Kalman Filter" by Greg Welch and Gary Bishop, and no, that construct was unnecessary. As you've figured out, you can use the integer directly. It's the usual problem that people get when they switch from using Octave/Matlab to numpy/scipy/matplotlib. The former are better in an interactive maths-oriented environment, but people then often then switch to Python for more complex algorithms to take advantage of the features of an advanced general-purpose programming language. The problem that people then run into is that although there are equivalents in the Python libraries for most of the Matlab functions, this happens to be an area where the documentation is particularly uneven. "Pylab" is a project that attempted to be a Python equivalent of Matlab, but has now become a depreciated appendix to matplotlib. There have been attempts to restart it as a feature of Ipython, but although it mostly works, the documentation is almost nonexistent. The only way to figure out what it can do is to try it yourself with a lot of trial and error. Anyway, don't be surprised if you see unnecessary elaborations in maths/science Python code because it's what you expect when people are arriving at code that works from reading poor documentation, trial and error, and Googling other peoples code snippets. Just try it yourself and save yourself time rather than asking for hand-holding. From v+python at g.nevcal.com Wed Nov 18 03:12:35 2015 From: v+python at g.nevcal.com (Glenn Linderman) Date: Wed, 18 Nov 2015 00:12:35 -0800 Subject: Launcher, and ftype Python.File Message-ID: <564C32F3.2070909@g.nevcal.com> Setting up a new machine with Windows 10, I installed Python 3.5.0 and the Launcher. Invoking python files from batch files as foo.py -a -bunch -of -parameters Didn't seem to do _anything_ so I checked: d:\>assoc .py .py=Python.File d:\>ftype Python.File Python.File="C:\Windows\py.exe" "%L" %* I'm surprised by the "%L" where usually programs have "%1". Is this a new Windows feature I don't know about yet, or is it a bug in the installer for the Launcher? ftype /? does not enlighten me that there is a new %L feature available. I did upgrade to Threshold 2 after installing Python and before using it, if that matters, just due to the timing of setting up the new machine. Turns out I had an empty file named foo.py and that is why it didn't do anything, but now I'm just really puzzled about what "%L" means... Google doesn't support searching for "%L" very well. From framstag at rus.uni-stuttgart.de Wed Nov 18 03:39:19 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 08:39:19 +0000 (UTC) Subject: non-blocking getkey? Message-ID: In my program (for python 2.7) the user must enter file names with mouse copy+paste. I use: while True: file = raw_input(prompt) if file == '': break files.append(file) The problem now is: my users do not hit ENTER after pasting. The file names are pasted together in one single line without space or other delimiter. My idea now is: instead of raw_input() I use a get_paste() function, which reads input character for input character and after a (say) 1 s timeout it returns the string. Pasting a string with the mouse is rather fast, there should be no big delay between the characters. How can I implement such a get_paste() function? I need a non-blocking getkey() function. It must work on Windows and Linux. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From gandalf at shopzeus.com Wed Nov 18 04:00:21 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Wed, 18 Nov 2015 10:00:21 +0100 Subject: cPickle.load vs. file.read+cPickle.loads on large binary files In-Reply-To: References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> <420ec4e9-6af6-49bd-a9f4-8b47ef1f136e@googlegroups.com> Message-ID: <564C3E25.5090900@shopzeus.com> > Perhaps there is a size threshold? You could experiment with different block > sizes in the following f.read() replacement: > > def read_chunked(f, size=2**20): > read = functools.partial(f.read, size) > return "".join(iter(read, "")) > Under win32 platform, my experience is that the fastest way to read binary file from disk is the mmap module. You should try that too. From auriocus at gmx.de Wed Nov 18 04:14:45 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 18 Nov 2015 10:14:45 +0100 Subject: non-blocking getkey? In-Reply-To: References: Message-ID: Am 18.11.15 um 09:39 schrieb Ulli Horlacher: > In my program (for python 2.7) the user must enter file names with > mouse copy+paste. I use: > > while True: > file = raw_input(prompt) > if file == '': break > files.append(file) > > How can I implement such a get_paste() function? > I need a non-blocking getkey() function. > It must work on Windows and Linux. Non-blocking I/O from the commandline is OS specific. There are different solutions, and it's usually hacky (stty on Linux, Console API on Windows) Why do you not use a proper GUI toolkit to do this? It is straight-forward to accept keystrokes, copy/paste and drag'n'drop with most toolkits. Especially if you target Windows users, I think they would be more than happy to get a GUI app then to open a terminal window and paste something there. The standard terminal on Windows is very ugly, can't resize the width, and pasting works only if you right-click -> paste. Christian From tjreedy at udel.edu Wed Nov 18 04:47:56 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2015 04:47:56 -0500 Subject: Writing SOME class methods in C In-Reply-To: References: Message-ID: On 11/18/2015 2:50 AM, Daniel Haude wrote: > Hello, > > I'm trying to implement some (but not all) methods of a Python class in C. > What I've found on the Net is: > - how to implement entire modules in C so that I can import that module and > use the C functions (successfully done it, too). > - how to implement entire classes in C > > But I can't find any examples of modules which consist of a mixture of C and > Python, There at least to be such in the stdlib. The .py module defined *everything* and then ended with try: from _module import * except ImportError: pass to replace whatever top-level objects were also written in C. The try-except part is optional but let the module run when _module was not present. I believe the string module was once like this. > nor modules that define classes of which some members are > implemented in C, others in Python. I would try putting the C part in separate base or mix-in class, imported before the class statement. To make the C part optional: class mixin: ... try: from _module import mixin except ImportError pass class myclass(mixin): ... -- Terry Jan Reedy From tjreedy at udel.edu Wed Nov 18 05:02:13 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2015 05:02:13 -0500 Subject: Is there any reason to introduce this intermediate variable (sz)? In-Reply-To: References: Message-ID: On 11/17/2015 3:51 PM, fl wrote: > n_iter = 50 > sz = (n_iter,) # size of array > x = -0.37727 > z = np.random.normal(x,0.1,size=sz) > > Q = 1e-5 # process variance > > # allocate space for arrays > xhat=np.zeros(sz) > P=np.zeros(sz) > > > I learn Python now and the above code seems from an experienced author. > The curious thing to me is the variable 'sz'. 'sz' is a name and in the program above, it is a constant tuple derived from constant int n_iter. Since the tuple is used more than once, calculating it just once and naming it is a good idea. > I have check np.zeros(shape, ..) Reading about the the signature of functions that you use or read about is a good idea and quite normal. > shape : int or sequence of ints > The introduced 'sz' is a tuple. and tuples are sequences. > If n_iter function is similar to a constant in C, n_iter is a named constant, not a function, as you note below. > I don't see the reason for 'sz'. I gave a reason for it existig above, but I think you are asking about its use in the particular location. > In fact, 'n_iter' is an int, which fits the below > > np.zeros(shape) > > correctly. Could you see something useful with variable 'sz'? I would presume until I tried it that np.zeros(50) and np.zeros((50,)) are different (have a different shape). If they are not, then the use of a singleton tuple is confusing, whether or not the tuple is given a name. -- Terry Jan Reedy From andrea.gavana at gmail.com Wed Nov 18 05:31:34 2015 From: andrea.gavana at gmail.com (andrea.gavana at gmail.com) Date: Wed, 18 Nov 2015 02:31:34 -0800 (PST) Subject: cPickle.load vs. file.read+cPickle.loads on large binary files In-Reply-To: References: <463ad93c-0186-4911-9cd1-92d97b9dc87b@googlegroups.com> <54330891-6568-4469-93ae-7a7825961500@googlegroups.com> <420ec4e9-6af6-49bd-a9f4-8b47ef1f136e@googlegroups.com> Message-ID: Hi, On Wednesday, November 18, 2015 at 10:00:43 AM UTC+1, Nagy L?szl? Zsolt wrote: > > Perhaps there is a size threshold? You could experiment with different block > > sizes in the following f.read() replacement: > > > > def read_chunked(f, size=2**20): > > read = functools.partial(f.read, size) > > return "".join(iter(read, "")) > > > Under win32 platform, my experience is that the fastest way to read > binary file from disk is the mmap module. You should try that too. Thank you for your suggestion. I have tried that now, and with my naive approach I have done this: start = time.time() fid = open(filename, 'r+b') strs = mmap.mmap(fid.fileno(), 0, access=mmap.ACCESS_READ)[:] end = time.time() print 'mmap.read time:', end-start And it takes about 2.7 seconds. Not a bad improvement :-) . Unfortunately, when the file is on a network drive, all the other approaches ran at around 25-30 seconds loading time, while the mmap one clocks at 110 seconds :-( Andrea. From framstag at rus.uni-stuttgart.de Wed Nov 18 05:39:52 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 10:39:52 +0000 (UTC) Subject: non-blocking getkey? References: Message-ID: Christian Gollwitzer wrote: > > How can I implement such a get_paste() function? > > I need a non-blocking getkey() function. > > It must work on Windows and Linux. > > Non-blocking I/O from the commandline is OS specific. There are > different solutions, and it's usually hacky (stty on Linux, Console API > on Windows) A "if windows (...) else linux (...)" solution is ok, I have such distinction already at several places in my code. Do you have example code for non-blocking I/O? > Why do you not use a proper GUI toolkit to do this? it is too complicated to rewrite my application from CLI to GUI. But... is there a windows program with which one can select files and the result is written to STDOUT? Then I could use pipe open in my Python program. > The standard terminal on Windows is very ugly, can't resize the width, > and pasting works only if you right-click -> paste. You can also use drag&drop. This is ok for my users. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From tjreedy at udel.edu Wed Nov 18 05:52:57 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2015 05:52:57 -0500 Subject: Launcher, and ftype Python.File In-Reply-To: <564C32F3.2070909@g.nevcal.com> References: <564C32F3.2070909@g.nevcal.com> Message-ID: <564C5889.5040903@udel.edu> On 11/18/2015 3:12 AM, Glenn Linderman wrote: > Setting up a new machine with Windows 10, I installed Python 3.5.0 and > the Launcher. Invoking python files from batch files as > > foo.py -a -bunch -of -parameters > > Didn't seem to do _anything_ so I checked: > > d:\>assoc .py > .py=Python.File > > d:\>ftype Python.File > Python.File="C:\Windows\py.exe" "%L" %* Verified on my Win 10 > I'm surprised by the "%L" where usually programs have "%1". Is this a > new Windows feature I don't know about yet, or is it a bug in the > installer for the Launcher? It puzzles me tool. However, it works. > ftype /? does not enlighten me that there is a new %L feature available. I accidentally entered just 'ftype' and since WMP11 listings are at the end, noticed that they also use %L. I also see that WMP11 listings are the only ones (other than Python.*) using %L. Not even other MS listings, as for IE, do. After entering 'ftype /?' as intended, I see that %0 and %1 are synonyms for the first word == the file being launched. I also did not find mention of %L. My guess is 'L' is a new term for 'Launched file'. Steve Dower, who wrote the 3.5 intaller, would know about it as a MS employer. Steve, can you verify the above, and maybe tell whoever to update the ftype help? Is there any difference (other than our puzzlement) between using %1 and %L? > Turns out I had an empty file named foo.py and that is why it didn't do > anything, but now I'm just really puzzled about what "%L" means... > Google doesn't support searching for "%L" very well. -- Terry Jan Reedy From framstag at rus.uni-stuttgart.de Wed Nov 18 06:01:59 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 11:01:59 +0000 (UTC) Subject: non-blocking getkey? References: Message-ID: Ulli Horlacher wrote: > it is too complicated to rewrite my application from CLI to GUI. > But... is there a windows program with which one can select files and the > result is written to STDOUT? Found it: from Tkinter import Tk from tkFileDialog import askopenfilename Tk().withdraw() file = askopenfilename() Hey, easy! :-) -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From auriocus at gmx.de Wed Nov 18 06:17:07 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 18 Nov 2015 12:17:07 +0100 Subject: non-blocking getkey? In-Reply-To: References: Message-ID: Am 18.11.15 um 12:01 schrieb Ulli Horlacher: > Ulli Horlacher wrote: > >> it is too complicated to rewrite my application from CLI to GUI. >> But... is there a windows program with which one can select files and the >> result is written to STDOUT? > > Found it: > > from Tkinter import Tk > from tkFileDialog import askopenfilename > > Tk().withdraw() > file = askopenfilename() > > > Hey, easy! :-) > Welcome to GUI programming ;) Do you still have other data to input? There are nice tutorials at http://tkdocs.com and for simple input like a single number or a line of text, there is a module simpledialog Christian From steve at pearwood.info Wed Nov 18 06:37:20 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 18 Nov 2015 22:37:20 +1100 Subject: Which type should be used when testing static structure appartenance References: Message-ID: <564c62f3$0$1593$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Nov 2015 01:27 am, Nicolas ?vrard wrote: > Hello, > > I saw the following retweet by Raymond Hettinger in this morning: > > https://twitter.com/sanityinc/status/666485814214287360 > > Programming tip: many of those arrays and hashes in your code > should actually be sets. Match data structures to data > constraints! This is why I hold Twitter in contempt. What Raymond says could be a good tip, or a load of old hogwash, and there is no way of knowing because you can't explain much in 130 characters. If it were a blog post, he could explain what he means. But its a tweet, so he can't. Of course you should match the data structure to your data constraints, but what does that mean in practice? *Which* arrays and hashes should be sets? How do you know which should be changed to sets? > I saw just in time because in a review I wrote something like this: > > if operator not in ('where', 'not where') > > and my colleague proposed that I should use a list instead of a tuple. > But reading the mentioned tweet I tend to think that a set would be a > better choice. Exactly. Raymond's tweet only serves to muddy the water and add more confusion. Before, you thought you knew the right answer: use a tuple. Then, your colleague proposed a list, adding some uncertainty and confusion: which is better, a list or a tuple? And now Raymond's tweet has *increased* the uncertainty: should you use a set? > What are your opinion on this issue (I realize it's not something of > the utmost importance but rather a "philosophical" question). I would say that there is no doubt that in Python 2, using a tuple is far and away the best solution for the situation you show above. There are three factors to weigh up: (1) how easy is it to create the data structure? (2) how much space does the data structure use? (3) how fast is searching the data structure? How easy is it to create the data structure? In Python 2, lists and tuples are effectively just as easy to type, but sets not so much: ('where', 'not where') ['where', 'not where'] set(['where', 'not where']) Not only are sets longer to type, but they are created at runtime. Compare the byte-code compiled for each expression: py> from dis import dis py> a = compile("('where', 'not where')", "", "single") py> b = compile("['where', 'not where']", "", "single") py> c = compile("set(['where', 'not where'])", "", "single") py> dis(a) 1 0 LOAD_CONST 3 (('where', 'not where')) 3 PRINT_EXPR 4 LOAD_CONST 2 (None) 7 RETURN_VALUE py> dis(b) 1 0 LOAD_CONST 0 ('where') 3 LOAD_CONST 1 ('not where') 6 BUILD_LIST 2 9 PRINT_EXPR 10 LOAD_CONST 2 (None) 13 RETURN_VALUE py> dis(c) 1 0 LOAD_NAME 0 (set) 3 LOAD_CONST 0 ('where') 6 LOAD_CONST 1 ('not where') 9 BUILD_LIST 2 12 CALL_FUNCTION 1 15 PRINT_EXPR 16 LOAD_CONST 2 (None) 19 RETURN_VALUE Python can optimise the creation of the tuple to compile-time, but it has to create the list at run time. It also creates the set at run time, but it also needs to do a name lookup. All this takes time. How much space does each data structure take? Again, a tuple easily wins over the others: py> import sys py> sys.getsizeof(('where', 'not where')) 32 py> sys.getsizeof(['where', 'not where']) 40 py> sys.getsizeof(set(['where', 'not where'])) 112 The tuple is smaller than the list, and MUCH smaller than the set. (The exact sizes you see will depend on the precise version and platform you are using, but I am confident that the tuple will win.) Last but not least, which is fastest? For that, we can use the timeit module, running it as a script from the shell: [steve at ando ~]$ python -m timeit -s "x = 'not where'" "x in ('where', 'not where')" 10000000 loops, best of 3: 0.122 usec per loop [steve at ando ~]$ python -m timeit -s "x = 'not where'" "x in ['where', 'not where']" 10000000 loops, best of 3: 0.119 usec per loop [steve at ando ~]$ python -m timeit -s "x = 'not where'" "x in set(['where', 'not where'])" 1000000 loops, best of 3: 0.728 usec per loop The difference between 0.122 microseconds and 0.119 microseconds is too close to call. We can say that the tuple and the list are equally fast, and the set much, much slower. But... we can speed the set up, by only creating it once: [steve at ando ~]$ python -m timeit -s "x = 'not where'" -s "S = set(['where', 'not where'])" "x in S" 10000000 loops, best of 3: 0.101 usec per loop That's better! But only *marginally* faster than the tuple, and to get the speed increase you have to factor out the set into a constant. So for Python 2, I would say that tuples are the clean winner, at least for the case where you only have two items to check. If you have more than two, sets start becoming more attractive. How about Python 3? Python 3 has the advantage of using set literals. Let's test the speed: [steve at ando ~]$ python3.3 -m timeit -s "x = 'not where'" "x in ('where', 'not where')" 10000000 loops, best of 3: 0.11 usec per loop [steve at ando ~]$ python3.3 -m timeit -s "x = 'not where'" "x in ['where', 'not where']" 10000000 loops, best of 3: 0.113 usec per loop [steve at ando ~]$ python3.3 -m timeit -s "x = 'not where'" "x in {'where', 'not where'}" 10000000 loops, best of 3: 0.0907 usec per loop This makes sets much more attractive in Python 3. -- Steven From tjreedy at udel.edu Wed Nov 18 07:26:12 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2015 07:26:12 -0500 Subject: non-blocking getkey? In-Reply-To: References: Message-ID: On 11/18/2015 6:01 AM, Ulli Horlacher wrote: > Ulli Horlacher wrote: > >> it is too complicated to rewrite my application from CLI to GUI. >> But... is there a windows program with which one can select files and the >> result is written to STDOUT? > > Found it: > > from Tkinter import Tk > from tkFileDialog import askopenfilename > > Tk().withdraw() > file = askopenfilename() To get multiple names, add 's'. On Windows, one uses control-leftclick to get multiple names. Don't know about other systems. >>> fd.askopenfilenames() # ^click 4 names ('F:/Python/dev/27/Lib/idlelib/aboutDialog.py', 'F:/Python/dev/27/Lib/idlelib/AutoComplete.py', 'F:/Python/dev/27/Lib/idlelib/AutoCompleteWindow.pyc', 'F:/Python/dev/27/Lib/idlelib/Bindings.py') The limitation is that this will not work if any of the file names contain astral (non-BMP) chars because tk cannot handle such characters. -- Terry Jan Reedy From rosuav at gmail.com Wed Nov 18 07:40:09 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Nov 2015 23:40:09 +1100 Subject: Which type should be used when testing static structure appartenance In-Reply-To: <564c62f3$0$1593$c3e8da3$5496439d@news.astraweb.com> References: <564c62f3$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Nov 18, 2015 at 10:37 PM, Steven D'Aprano wrote: > How about Python 3? Python 3 has the advantage of using set literals. 2.7 has set literals too. All the questions of performance should be secondary to code clarity, though; so I would say the choices are: Set literal if available, else tuple. Forget the performance. ChrisA From oscar.j.benjamin at gmail.com Wed Nov 18 07:52:26 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 18 Nov 2015 12:52:26 +0000 Subject: Writing SOME class methods in C In-Reply-To: References: Message-ID: On 18 November 2015 at 07:50, Daniel Haude wrote: > > I'm trying to implement some (but not all) methods of a Python class in C. > What I've found on the Net is: > - how to implement entire modules in C so that I can import that module and > use the C functions (successfully done it, too). > - how to implement entire classes in C I would suggest to use Cython here. You can write your class in Python (that will be compiled to C) and then call out to any C code from any of its methods. Alternatively Terry's suggestion to implement a class in C and then subclass it in Python to add the remaining methods is a good one. But then I would write the C class using Cython so I may as well do the whole thing in Cython. -- Oscar From mal at europython.eu Wed Nov 18 08:05:53 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 18 Nov 2015 14:05:53 +0100 Subject: EuroPython 2016: Dates and URL available Message-ID: <564C77B1.2060201@europython.eu> The EuroPython 2016 Team is pleased to account the dates for EuroPython 2016 in Bilbao, Basque Country, Spain: Sunday, July 17 - Sunday, July 24 2016 Pre-launch Website ------------------ To keep you updated, we have put together a pre-launch website for the conference: *** http://ep2016.europython.eu/ *** Beginners? Day -------------- You may wonder why we?re having an extra day for the conference. Here?s the plan: In 2015, we introduced Beginners? Day as a new format to EuroPython providing special introductions and tutorials for Python beginners. The project was a great success. For the 2016 edition, we are planning to dedicate Sunday before the main conference as Beginner?s Day, so we?ll have the following conference layout: * Sunday, July 17: Beginners? day & registration * Monday, July 18 - Friday, July 22: Main conference & trainings * Saturday, July 23 - Sunday, July 24: Sprints Looking for Launch Sponsors --------------------------- We will launch the conference website in December. If your company would like to sponsor EuroPython 2016 and get extra attention by being one of our launch sponsors, please check our sponsor page for details. Enjoy, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ From framstag at rus.uni-stuttgart.de Wed Nov 18 08:06:31 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 13:06:31 +0000 (UTC) Subject: non-blocking getkey? References: Message-ID: Terry Reedy wrote: > > from Tkinter import Tk > > from tkFileDialog import askopenfilename > > > > Tk().withdraw() > > file = askopenfilename() > > To get multiple names, add 's'. I have found it already, thanks. > The limitation is that this will not work if any of the file names > contain astral (non-BMP) chars because tk cannot handle such characters. What are "astral chars"? But anyway, askopenfilename() is a dead end for me: one cannot select directories with it, just plain files. In my application the user MUST select files and directories (in one go). -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From rosuav at gmail.com Wed Nov 18 08:24:11 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 00:24:11 +1100 Subject: non-blocking getkey? In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 12:06 AM, Ulli Horlacher wrote: >> The limitation is that this will not work if any of the file names >> contain astral (non-BMP) chars because tk cannot handle such characters. > > What are "astral chars"? Characters not on the Basic Multilingual Plane (BMP). The Unicode character set is divided into a number of planes of 65,536 codepoints each, with the most commonly used ones on the first plane, the BMP. A lot of programs either cannot use non-BMP characters or have problems with them; for instance, anything that uses UTF-16 as its internal representation (ECMAScript, notably; also Python 2 on Windows) sees astral characters as pairs of code points. > In my application the user MUST select files and directories (in one go). It's extremely uncommon to be able to select a combination of files and directories. The UI for this would be quite annoying, I think. You may find it easier to have your own wrapper; for example, have a list of selected files/directories, with buttons "Add File" and "Add Directory" underneath. The former would use askopenfilenames (despite the singular in the button name), and the latter would use askdirectory. Trying to do both at once would be hard. ChrisA From steve at pearwood.info Wed Nov 18 08:30:36 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 19 Nov 2015 00:30:36 +1100 Subject: Which type should be used when testing static structure appartenance References: <564c62f3$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <564c7d80$0$1606$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Nov 2015 11:40 pm, Chris Angelico wrote: > On Wed, Nov 18, 2015 at 10:37 PM, Steven D'Aprano > wrote: >> How about Python 3? Python 3 has the advantage of using set literals. > > 2.7 has set literals too. Ah, so it does. I forgot about that. Most of my code has to run on multiple versions (back to 2.4) and I remembered that set literals don't work: [steve at ando ~]$ python2.6 -c "{1, 2, 3}" File "", line 1 {1, 2, 3} ^ SyntaxError: invalid syntax > All the questions of performance should be > secondary to code clarity, though; "All"? Surely not. > so I would say the choices are: Set > literal if available, else tuple. Forget the performance. It seems rather strange to argue that we should ignore performance when the whole reason for using sets in the first place is for performance. -- Steven From jon+usenet at unequivocal.co.uk Wed Nov 18 08:32:29 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Wed, 18 Nov 2015 13:32:29 -0000 (UTC) Subject: Which type should be used when testing static structure appartenance References: <564c62f3$0$1593$c3e8da3$5496439d@news.astraweb.com> <564c7d80$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-11-18, Steven D'Aprano wrote: > On Wed, 18 Nov 2015 11:40 pm, Chris Angelico wrote: >> so I would say the choices are: Set >> literal if available, else tuple. Forget the performance. > > It seems rather strange to argue that we should ignore performance when the > whole reason for using sets in the first place is for performance. Who says the whole reason for using sets is performance? Sets behave differently to tuples or lists - the members are guaranteed to be unique. From steve at pearwood.info Wed Nov 18 08:38:25 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 19 Nov 2015 00:38:25 +1100 Subject: non-blocking getkey? References: Message-ID: <564c7f54$0$1597$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Nov 2015 12:06 am, Ulli Horlacher wrote: > Terry Reedy wrote: > >> > from Tkinter import Tk >> > from tkFileDialog import askopenfilename >> > >> > Tk().withdraw() >> > file = askopenfilename() >> >> To get multiple names, add 's'. > > I have found it already, thanks. > > >> The limitation is that this will not work if any of the file names >> contain astral (non-BMP) chars because tk cannot handle such characters. > > What are "astral chars"? Unicode characters beyond U+FFFF. Unicode covers the entire range of code points (informally characters, don't worry about the technical difference) from U+0000 to U+10FFFF. The part following the "U+" is the numeric ordinal value, written in hexadecimal. Some older versions of Unicode only included 2**16 == 65536 distinct characters, but many years ago Unicode was extended far beyond that number. But the first 65536 characters are called the "Basic Multilingual Plane". All the rest are in the "Supplementary Multilingual Planes", which being a mouthful to say and write, often gets abbreviated as "astral planes". Hence the characters themselves are called "astral characters". Even today, some programming languages and systems have difficulty dealing with characters that require more than two bytes. -- Steven From rosuav at gmail.com Wed Nov 18 08:42:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 00:42:32 +1100 Subject: Which type should be used when testing static structure appartenance In-Reply-To: <564c7d80$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <564c62f3$0$1593$c3e8da3$5496439d@news.astraweb.com> <564c7d80$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Nov 19, 2015 at 12:30 AM, Steven D'Aprano wrote: > On Wed, 18 Nov 2015 11:40 pm, Chris Angelico wrote: >> All the questions of performance should be >> secondary to code clarity, though; > > "All"? Surely not. The OP's example was checking if a string was equal to either of two strings. Even if that's in a tight loop, the performance difference between the various options is negligible. The "all" is a little misleading (of course there are times when you warp your code for the sake of performance), but I was talking about this example, where it's basically coming down to microbenchmarks. >> so I would say the choices are: Set >> literal if available, else tuple. Forget the performance. > > It seems rather strange to argue that we should ignore performance when the > whole reason for using sets in the first place is for performance. They do perform well, but that's not the main point - not when you're working with just two strings. Of course, when you can get performance AND readability, it's perfect. That doesn't happen with Py2 sets, but it does with Python 3: rosuav at sikorsky:~$ python -m timeit -s "x='asdf'" "x in {'asdf','qwer'}" 10000000 loops, best of 3: 0.12 usec per loop rosuav at sikorsky:~$ python -m timeit -s "x='asdf'" "x in ('asdf','qwer')" 10000000 loops, best of 3: 0.0344 usec per loop rosuav at sikorsky:~$ python -m timeit -s "x='asdf'" "x=='asdf' or x=='qwer'" 10000000 loops, best of 3: 0.0392 usec per loop rosuav at sikorsky:~$ python3 -m timeit -s "x='asdf'" "x in {'asdf','qwer'}" 10000000 loops, best of 3: 0.0356 usec per loop rosuav at sikorsky:~$ python3 -m timeit -s "x='asdf'" "x in ('asdf','qwer')" 10000000 loops, best of 3: 0.0342 usec per loop rosuav at sikorsky:~$ python3 -m timeit -s "x='asdf'" "x=='asdf' or x=='qwer'" 10000000 loops, best of 3: 0.0418 usec per loop No set construction in Py3 - the optimizer figures out that you don't need mutability, and uses a constant frozenset. (Both versions do this with list->tuple.) Despite the performance hit from using a set in Py2, though, I would still advocate its use (assuming you don't need to support 2.6 or older), because it accurately represents the *concept* of "is this any one of these". ChrisA From framstag at rus.uni-stuttgart.de Wed Nov 18 08:51:33 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 13:51:33 +0000 (UTC) Subject: non-blocking getkey? References: <564c7f54$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > >> The limitation is that this will not work if any of the file names > >> contain astral (non-BMP) chars because tk cannot handle such characters. > > > > What are "astral chars"? > > Unicode characters beyond U+FFFF. I see, for very exotic character sets, like Klingon, etc :-) In my case, I can simple ignore them. > Unicode covers the entire range of code points (informally characters, don't > worry about the technical difference) from U+0000 to U+10FFFF. The part > following the "U+" is the numeric ordinal value, written in hexadecimal. That was my knowledge so far. > Some older versions of Unicode only included 2**16 == 65536 distinct > characters, but many years ago Unicode was extended far beyond that number. > But the first 65536 characters are called the "Basic Multilingual Plane". > All the rest are in the "Supplementary Multilingual Planes", which being a > mouthful to say and write, often gets abbreviated as "astral planes". Hence > the characters themselves are called "astral characters". And this was new to me. Learned :-) -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From framstag at rus.uni-stuttgart.de Wed Nov 18 08:57:53 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 13:57:53 +0000 (UTC) Subject: non-blocking getkey? References: Message-ID: Chris Angelico wrote: > > In my application the user MUST select files and directories (in one go). > > It's extremely uncommon to be able to select a combination of files > and directories. I have an uncommon application :-) Filetransfer of ANY size: http://fex.rus.uni-stuttgart.de:8080/ > The UI for this would be quite annoying, I think. You may find it easier > to have your own wrapper; for example, have a list of selected > files/directories, with buttons "Add File" and "Add Directory" > underneath. I came (independantly) to the same solution! So it must be a good idea :-) http://fex.rus.uni-stuttgart.de:8080/fop/3yxsCacS/X-20151118145221.png -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From rosuav at gmail.com Wed Nov 18 09:01:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 01:01:32 +1100 Subject: non-blocking getkey? In-Reply-To: References: <564c7f54$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Nov 19, 2015 at 12:51 AM, Ulli Horlacher wrote: > Steven D'Aprano wrote: > >> >> The limitation is that this will not work if any of the file names >> >> contain astral (non-BMP) chars because tk cannot handle such characters. >> > >> > What are "astral chars"? >> >> Unicode characters beyond U+FFFF. > > I see, for very exotic character sets, like Klingon, etc :-) > In my case, I can simple ignore them. And other exotic character sets, like Chinese. https://en.wikipedia.org/wiki/CJK_Unified_Ideographs#CJK_Unified_Ideographs_Extension_B But I'm sure you can ignore them, too. Hardly anyone on this planet speaks Chinese. ChrisA From harvesting at makes.invalid Wed Nov 18 09:13:56 2015 From: harvesting at makes.invalid (Jussi Piitulainen) Date: Wed, 18 Nov 2015 16:13:56 +0200 Subject: non-blocking getkey? References: <564c7f54$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ulli Horlacher writes: > Steven D'Aprano wrote: > >> >> The limitation is that this will not work if any of the file names >> >> contain astral (non-BMP) chars because tk cannot handle such >> >> characters. >> > >> > What are "astral chars"? >> >> Unicode characters beyond U+FFFF. > > I see, for very exotic character sets, like Klingon, etc :-) > In my case, I can simple ignore them. Better test how your user interface behaves when a user copy-pastes one of those characters into it. If it merely garbles the character somehow, you may be able to ignore the problem, but if it promptly shuts down your whole application and loses some unfinished work, the user may not be happy. Klingon may not be that widely spoken, but all manner of little picture characters seem popular. Wasn't one just chosen to be the Word Of The Year? And when it's the underlying GUI library that crashes, it's too late for your program to sanitize the input. From chris at chrullrich.net Wed Nov 18 09:45:54 2015 From: chris at chrullrich.net (Christian Ullrich) Date: Wed, 18 Nov 2015 15:45:54 +0100 Subject: Launcher, and ftype Python.File In-Reply-To: References: <564C32F3.2070909@g.nevcal.com> Message-ID: * Terry Reedy wrote: > On 11/18/2015 3:12 AM, Glenn Linderman wrote: >> d:\>ftype Python.File >> Python.File="C:\Windows\py.exe" "%L" %* > > Verified on my Win 10 > >> I'm surprised by the "%L" where usually programs have "%1". Is this a >> new Windows feature I don't know about yet, or is it a bug in the >> installer for the Launcher? > > It puzzles me tool. However, it works. Apparently %L is always the long file name, and %1 is the short name unless the shell can prove that the executable can handle long names. >> Google doesn't support searching for "%L" very well. https://www.google.com/search?q=ftype+%22%25L%22#q=ftype+%22%25L%22+-mks -- Christian From durozoyp at gmail.com Wed Nov 18 11:34:43 2015 From: durozoyp at gmail.com (durozoyp at gmail.com) Date: Wed, 18 Nov 2015 08:34:43 -0800 (PST) Subject: link a treeview to a list Message-ID: <650de6af-2ae1-4218-8d14-d06c84fc5cc9@googlegroups.com> So I am currently making a little program that generates a list of characters with different stats. Now I would like to display those characters in a list and when the user clicks on one of them display all the stats for that character. Here is my code for my GUI so far: class CTABLE: def __init__(self, master): self.charactersTable = ttk.Treeview(master, selectmode="browse") self.charactersTable["show"] = "headings" self.charactersTable["columns"]=("Name", "Surname", "Hunger", "Fear", "Comfort", "Hapiness") self.charactersTable.column("Name", width=100, anchor=E) self.charactersTable.heading("Name", text="Name") self.charactersTable.column("Surname", width=100, anchor=E) self.charactersTable.heading("Surname", text="Surname") self.charactersTable.column("Hunger", width=100, anchor=E) self.charactersTable.heading("Hunger", text="Hunger") self.charactersTable.column("Fear", width=100, anchor=E) self.charactersTable.heading("Fear", text="Fear") self.charactersTable.column("Comfort", width=100, anchor=E) self.charactersTable.heading("Comfort", text="Comfort") self.charactersTable.column("Hapiness", width=100, anchor=E) self.charactersTable.heading("Hapiness", text="Hapiness") for character in characters: self.charactersTable.insert("", "end", values=(character.surname, character.name, character.hunger, character.fear, character.comfort, character.happiness)) self.charactersTable.bind("", self.CTClick) self.charactersTable.grid(row=1, rowspan=3, column=1) def CTClick(self, event): item = self.charactersTable.selection()[0] print (self.charactersTable.item(item)) My problem is that my CTClick event refers to the line in the treeview object and not the character object itself and I don't know how to fix that From ryanshuell at gmail.com Wed Nov 18 11:37:47 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 18 Nov 2015 08:37:47 -0800 (PST) Subject: How can I export data from a website and write the contents to a text file? Message-ID: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> I'm trying the script below, and it simple writes the last line to a text file. I want to add a '\n' after each line is written, so I don't overwrite all the lines. from bs4 import BeautifulSoup import urllib2 var_file = urllib2.urlopen("http://www.imdb.com/chart/top") var_html = var_file.read() var_file.close() soup = BeautifulSoup(var_html) for item in soup.find_all(class_='lister-list'): for link in item.find_all('a'): print(link) text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") z = str(link) text_file.write(z + "\n") text_file.write("\n") text_file.close() Can someone please help me get this working? Thanks!! From framstag at rus.uni-stuttgart.de Wed Nov 18 11:45:49 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 16:45:49 +0000 (UTC) Subject: handling of non-ASCII filenames? Message-ID: I have written a program (Python 2.7) which reads a filename via tkFileDialog.askopenfilename() (was a good hint here, other thread). This filename may contain non-ASCII characters (German Umlauts). In this case my program crashes with: File "S:\python\fexit.py", line 1177, in url_encode u += '%' + c.encode("hex").upper() File "C:\Python27\lib\encodings\hex_codec.py", line 24, in hex_encode output = binascii.b2a_hex(input) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 0: ordinal not in range(128) This is my encoding function: def url_encode(s): u = '' for c in list(s): if match(r'[_=:,;<>()+.\w\-]',c): u += c else: u += '%' + c.encode("hex").upper() return u As I am Python newbie I have not quite understood the Python character encoding scheme :-} Where can I find a good introduction of this topic? I would also appreciate a concrete solution for my problem :-) -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From framstag at rus.uni-stuttgart.de Wed Nov 18 11:50:11 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 16:50:11 +0000 (UTC) Subject: non-blocking getkey? References: Message-ID: Ulli Horlacher wrote: > from Tkinter import Tk > from tkFileDialog import askopenfilename > > Tk().withdraw() > file = askopenfilename() I found another glitch: After termination of askopenfilename() the window focus is not returned to the calling window (xterm on Linux, cmd on Windows). I have to click it again, to regain the focus and continue typing. Is there a workaround? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From rosuav at gmail.com Wed Nov 18 11:54:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 03:54:58 +1100 Subject: handling of non-ASCII filenames? In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 3:45 AM, Ulli Horlacher wrote: > As I am Python newbie I have not quite understood the Python character > encoding scheme :-} > > Where can I find a good introduction of this topic? Here are a couple of articles on the basics of Unicode: http://www.joelonsoftware.com/articles/Unicode.html http://nedbatchelder.com/text/unipain.html If you can use Python 3, your life will be easier. Otherwise, you'll need to work some of this stuff out manually. ChrisA From rosuav at gmail.com Wed Nov 18 11:57:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 03:57:58 +1100 Subject: How can I export data from a website and write the contents to a text file? In-Reply-To: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> Message-ID: On Thu, Nov 19, 2015 at 3:37 AM, ryguy7272 wrote: > text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") > z = str(link) > text_file.write(z + "\n") > text_file.write("\n") > text_file.close() You're opening the file every time you go through the loop, overwriting each time. Instead, open the file once, then start the loop, and then close it at the end. You can use a 'with' statement to do the closing for you, or you can do it the way you are here. ChrisA From ryanshuell at gmail.com Wed Nov 18 12:03:58 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 18 Nov 2015 09:03:58 -0800 (PST) Subject: How can I export data from a website and write the contents to a text file? In-Reply-To: References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> Message-ID: <099133ed-c6df-4f5c-b47b-f1cf464511f6@googlegroups.com> On Wednesday, November 18, 2015 at 11:58:17 AM UTC-5, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 3:37 AM, ryguy7272 wrote: > > text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") > > z = str(link) > > text_file.write(z + "\n") > > text_file.write("\n") > > text_file.close() > > You're opening the file every time you go through the loop, > overwriting each time. Instead, open the file once, then start the > loop, and then close it at the end. You can use a 'with' statement to > do the closing for you, or you can do it the way you are here. > > ChrisA Thanks. What would the code look like? I tried the code below, and got the same results. for item in soup.find_all(class_='lister-list'): for link in item.find_all('a'): #print(link) z = str(link) text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") text_file.write(z + "\n") text_file.close() From ryanshuell at gmail.com Wed Nov 18 12:15:20 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 18 Nov 2015 09:15:20 -0800 (PST) Subject: How can I export data from a website and write the contents to a text file? In-Reply-To: <099133ed-c6df-4f5c-b47b-f1cf464511f6@googlegroups.com> References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> <099133ed-c6df-4f5c-b47b-f1cf464511f6@googlegroups.com> Message-ID: <9ddeb643-292f-4d5a-a891-83bee1d35c2f@googlegroups.com> On Wednesday, November 18, 2015 at 12:04:16 PM UTC-5, ryguy7272 wrote: > On Wednesday, November 18, 2015 at 11:58:17 AM UTC-5, Chris Angelico wrote: > > On Thu, Nov 19, 2015 at 3:37 AM, ryguy7272 <> wrote: > > > text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") > > > z = str(link) > > > text_file.write(z + "\n") > > > text_file.write("\n") > > > text_file.close() > > > > You're opening the file every time you go through the loop, > > overwriting each time. Instead, open the file once, then start the > > loop, and then close it at the end. You can use a 'with' statement to > > do the closing for you, or you can do it the way you are here. > > > > ChrisA > > > > Thanks. What would the code look like? I tried the code below, and got the same results. > > > for item in soup.find_all(class_='lister-list'): > for link in item.find_all('a'): > #print(link) > z = str(link) > text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") > text_file.write(z + "\n") > text_file.close() Oh, I see, it's like this: text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") var_file.close() soup = BeautifulSoup(var_html) for item in soup.find_all(class_='lister-list'): for link in item.find_all('a'): #print(link) z = str(link) text_file.write(z + "\n") text_file.close() However, it's not organized very well, and it's hard to read. I thought the '\n' would create a new line after one line was written. Now, it seems like everything is jumbled together. Kind of weird. Am I missing something? From denismfmcmahon at gmail.com Wed Nov 18 12:19:13 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 18 Nov 2015 17:19:13 -0000 (UTC) Subject: How can I export data from a website and write the contents to a text file? References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> Message-ID: On Wed, 18 Nov 2015 08:37:47 -0800, ryguy7272 wrote: > I'm trying the script below... The problem isn't that you're over-writing the lines (although it may seem that way to you), the problem is that you're overwriting the whole file every time you write a link to it. This is because you open and close the file for every link you write, and you do so in file mode "wb" which restarts writing at the first byte of the file every time. You only need to open and close the text file once, instead of for every link you output. Try moving the lines to open and close the file outside the outer for loop to change the loop from: for item in soup.find_all(class_='lister-list'): for link in item.find_all('a'): # open file # write link to file # close file to: # open file for item in soup.find_all(class_='lister-list'): for link in item.find_all('a'): # write link to file # close file Alternatively, use the with form: with open("blah","wb") as text_file: for item in soup.find_all(class_='lister-list'): for link in item.find_all('a'): # write link to file -- Denis McMahon, denismfmcmahon at gmail.com From auriocus at gmx.de Wed Nov 18 12:22:05 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 18 Nov 2015 18:22:05 +0100 Subject: handling of non-ASCII filenames? In-Reply-To: References: Message-ID: Am 18.11.15 um 17:45 schrieb Ulli Horlacher: > This is my encoding function: > > def url_encode(s): > u = '' > for c in list(s): > if match(r'[_=:,;<>()+.\w\-]',c): > u += c > else: > u += '%' + c.encode("hex").upper() > return u > > The quoting is applied to a UTF8 string. But I think you shouldn't do it yourself, use a library function: import urllib urllib.quote(yourstring.encode('utf8')) Christian From ryanshuell at gmail.com Wed Nov 18 12:40:58 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 18 Nov 2015 09:40:58 -0800 (PST) Subject: How can I export data from a website and write the contents to a text file? In-Reply-To: References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> Message-ID: <6e0f470b-f896-43ae-8f83-b20f22a9db8d@googlegroups.com> On Wednesday, November 18, 2015 at 12:21:47 PM UTC-5, Denis McMahon wrote: > On Wed, 18 Nov 2015 08:37:47 -0800, ryguy7272 wrote: > > > I'm trying the script below... > > The problem isn't that you're over-writing the lines (although it may > seem that way to you), the problem is that you're overwriting the whole > file every time you write a link to it. This is because you open and > close the file for every link you write, and you do so in file mode "wb" > which restarts writing at the first byte of the file every time. > > You only need to open and close the text file once, instead of for every > link you output. Try moving the lines to open and close the file outside > the outer for loop to change the loop from: > > for item in soup.find_all(class_='lister-list'): > for link in item.find_all('a'): > # open file > # write link to file > # close file > > to: > > # open file > for item in soup.find_all(class_='lister-list'): > for link in item.find_all('a'): > # write link to file > # close file > > Alternatively, use the with form: > > with open("blah","wb") as text_file: > for item in soup.find_all(class_='lister-list'): > for link in item.find_all('a'): > # write link to file > > -- > Denis McMahon, Yes, I just figured it out. Thanks. It doesn't seem like the '\n' is doing anything useful. All the text is jumbled together. When I open the file in Excel, or Notepad++, it is easy to read. However, when I open it in as a regular text file, everything is jumbled together. Is there an easy way to fix this? From ryanshuell at gmail.com Wed Nov 18 12:43:59 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 18 Nov 2015 09:43:59 -0800 (PST) Subject: How can I export data from a website and write the contents to a text file? In-Reply-To: <6e0f470b-f896-43ae-8f83-b20f22a9db8d@googlegroups.com> References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> <6e0f470b-f896-43ae-8f83-b20f22a9db8d@googlegroups.com> Message-ID: On Wednesday, November 18, 2015 at 12:41:19 PM UTC-5, ryguy7272 wrote: > On Wednesday, November 18, 2015 at 12:21:47 PM UTC-5, Denis McMahon wrote: > > On Wed, 18 Nov 2015 08:37:47 -0800, ryguy7272 wrote: > > > > > I'm trying the script below... > > > > The problem isn't that you're over-writing the lines (although it may > > seem that way to you), the problem is that you're overwriting the whole > > file every time you write a link to it. This is because you open and > > close the file for every link you write, and you do so in file mode "wb" > > which restarts writing at the first byte of the file every time. > > > > You only need to open and close the text file once, instead of for every > > link you output. Try moving the lines to open and close the file outside > > the outer for loop to change the loop from: > > > > for item in soup.find_all(class_='lister-list'): > > for link in item.find_all('a'): > > # open file > > # write link to file > > # close file > > > > to: > > > > # open file > > for item in soup.find_all(class_='lister-list'): > > for link in item.find_all('a'): > > # write link to file > > # close file > > > > Alternatively, use the with form: > > > > with open("blah","wb") as text_file: > > for item in soup.find_all(class_='lister-list'): > > for link in item.find_all('a'): > > # write link to file > > > > -- > > Denis McMahon, > > > Yes, I just figured it out. Thanks. > > It doesn't seem like the '\n' is doing anything useful. All the text is jumbled together. When I open the file in Excel, or Notepad++, it is easy to read. However, when I open it in as a regular text file, everything is jumbled together. Is there an easy way to fix this? I finally got it working. It's like this: "\r\n" Thanks everyone!! From tjreedy at udel.edu Wed Nov 18 12:55:33 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2015 12:55:33 -0500 Subject: non-blocking getkey? In-Reply-To: References: Message-ID: On 11/18/2015 11:50 AM, Ulli Horlacher wrote: > Ulli Horlacher wrote: > >> from Tkinter import Tk >> from tkFileDialog import askopenfilename >> >> Tk().withdraw() >> file = askopenfilename() > > I found another glitch: > > After termination of askopenfilename() the window focus is not returned to > the calling window (xterm on Linux, cmd on Windows). I have to click it > again, to regain the focus and continue typing. Is there a workaround? What happens with root = Tk() root.withdraw() fiel = ... root.destroy() Focus cannot stay with destroyed window. -- Terry Jan Reedy From eryksun at gmail.com Wed Nov 18 13:03:51 2015 From: eryksun at gmail.com (eryksun) Date: Wed, 18 Nov 2015 12:03:51 -0600 Subject: Launcher, and ftype Python.File In-Reply-To: References: <564C32F3.2070909@g.nevcal.com> Message-ID: On Wed, Nov 18, 2015 at 8:45 AM, Christian Ullrich wrote: > Apparently %L is always the long file name, and %1 is the short name unless > the shell can prove that the executable can handle long names. Specifically old Win16 programs (identified by the file header) aren't aware of long filenames. In the case of these old programs, the shell calls GetShortPathName when replacing %0 or %1, but not when replacing %L. For Win32 programs %0, %1, and %L are all the same: C:\Temp>ftype Python.File Python.File="C:\Windows\py.exe" "%0" "%1" "%L" %* C:\Temp>longfilename.py sys.argv: C:\Temp\longfilename.py C:\Temp\longfilename.py C:\Temp\longfilename.py Short Pathname: C:\Temp\LONGFI~1.PY From rgaddi at technologyhighland.invalid Wed Nov 18 13:05:33 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Wed, 18 Nov 2015 18:05:33 -0000 (UTC) Subject: How can I export data from a website and write the contents to a text file? References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> <6e0f470b-f896-43ae-8f83-b20f22a9db8d@googlegroups.com> Message-ID: On Wed, 18 Nov 2015 09:40:58 -0800, ryguy7272 wrote: > > It doesn't seem like the '\n' is doing anything useful. All the text is > jumbled together. When I open the file in Excel, or Notepad++, it is > easy to read. However, when I open it in as a regular text file, > everything is jumbled together. Is there an easy way to fix this? You're suffering cause-effect inversion. Windows default Notepad is a fundamentally crippled text editor that only knows how to handle Windows/ DOS style text files, where the line endings is '\n\r'. Notepad++, along with many other excellent editors available for Windows, is smart enough to figure out from the file whether it's Windows style or UNIX style, where line endings are just a bare '\n'. So the problem wasn't with what you were writing, it's with how you define "open it as a regular text file". On my Windows machine I long ago switched the default editor to Notepad++ for everything and was far happier for it. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From framstag at rus.uni-stuttgart.de Wed Nov 18 13:09:50 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 18:09:50 +0000 (UTC) Subject: handling of non-ASCII filenames? References: Message-ID: Chris Angelico wrote: > > As I am Python newbie I have not quite understood the Python character > > encoding scheme :-} > > > > Where can I find a good introduction of this topic? > > Here are a couple of articles on the basics of Unicode: > > http://www.joelonsoftware.com/articles/Unicode.html I do Unicode programming for over 20 years. So, I do have a basic understanding of it. I am just new to Python. > http://nedbatchelder.com/text/unipain.html Thanks. I will read it. > If you can use Python 3 I cannot use it, because the Python compiler pyinstaller does not work with it on Windows: S:\python>pyinstaller.exe --onefile tk.py Traceback (most recent call last): File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')() File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l oad_entry_point return get_distribution(dist).load_entry_point(group, name) File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, in load_entry_point return ep.load() File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, in load return self.resolve() File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in import PyInstaller.building.build_main File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", line 31, in from ..depend import bindepend File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 40, in from ..utils.win32.winmanifest import RT_MANIFEST File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l ine 97, in from PyInstaller.utils.win32 import winresource File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l ine 20, in import pywintypes File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in __import_pywin32_system_module__("pywintypes", globals()) File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __im port_pywin32_system_module__ import _win32sysloader ImportError: DLL load failed: The specified module could not be found. With python 2.7, pyinstaller runs without problems. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From eryksun at gmail.com Wed Nov 18 13:24:08 2015 From: eryksun at gmail.com (eryksun) Date: Wed, 18 Nov 2015 12:24:08 -0600 Subject: non-blocking getkey? In-Reply-To: References: Message-ID: On Wed, Nov 18, 2015 at 3:14 AM, Christian Gollwitzer wrote: > The standard terminal on Windows is very ugly, can't resize the width, and > pasting works only if you right-click -> paste. The console UI is improved in Windows 10: http://blogs.windows.com/buildingapps/2014/10/07/console-improvements-in-the-windows-10-technical-preview From lac at openend.se Wed Nov 18 14:30:34 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 18 Nov 2015 20:30:34 +0100 Subject: Mapping between python packages and distro packages? In-Reply-To: References: <20151118032903.GA8040@sg1> <85vb90c4fv.fsf@benfinney.id.au> Message-ID: <201511181930.tAIJUYUc017056@fido.openend.se> In a message of Wed, 18 Nov 2015 17:44:51 +1100, Chris Angelico writes: >I don't know how the program would detect it, but I'd be thinking "the >one where 'sudo apt-get install PACKAGENAME' gets the same code that >'pip install THING' gets". In a lot of cases, PACKAGENAME will simply >be python-THING or python3-THING, eg python3-sqlalchemy, >python3-scipy, python3-bs4; as a human, that's what I'd try first. But >having a program recognize this would be hugely beneficial. > >ChrisA The problem is that this may not exist. Debian developers, when faced with a python package, may decide to break it up into several pieces, and make several debian packagages. If you want the same functionality you have to load all of the debian packages, which of course involves finding out what they are. apt-cache search works reasonably well, as long as you are willing to put up with some false hits. And it assumes you have a debian system handy, of course. Laura From anthony at cajuntechie.org Wed Nov 18 15:01:52 2015 From: anthony at cajuntechie.org (Anthony Papillion) Date: Wed, 18 Nov 2015 14:01:52 -0600 Subject: How to create a folder using IMAPLib? Message-ID: <564CD930.9000005@cajuntechie.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 I'm writing a program to help migrate mail from one host to another with a few special circumstances. I'm able to get a list off of the source IMAP server using the .list() command but I'm not quite sure how to create a folder on the target machine. Does anyone know how to create a folder using IMAPlib? Thanks, Anthony - -- Phone: 1.845.666.1114 Skype: cajuntechie PGP Key: 0x028ADF7453B04B15 Fingerprint: C5CE E687 DDC2 D12B 9063 56EA 028A DF74 53B0 4B15 -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJWTNkwAAoJEAKK33RTsEsVWsUQAKwo8HkE1mCDr+fFMQhUoE9N Tb80bbZkERbY7wvy31sr9EIBVDan6KDk7ZJX/hcYMfjOmoOtq55Ywmb3UxEkLzh2 TK1uujPa3X61hOYquspQ2QQ3wPW0mIEf+dTSQGipRV5n/AotIMD4Wda5Qia3E8ak tcNqXmi9k6iQoW1ct3JWO2HScJL5AUAcnu/C/iFsC1oGWGLYFu3fXOkjExN3GBTg ihuiyHAtUsow6pMLuRQ61/HHU9c3G2laOs/4M6oRtsnMetANsxi7BAP/X+OBxCdA nz1qe2SORoFs/UYqbFkwJOvBDLTTrpyLv9ZvqWwdq1IUngMA1p/sJxRkYZ8bL6Wj zJVJxDSxkE5s6J/neqFA97KI8EVGX5DXS2lNSxBT5crJkF88brBcUvebx0Euogdk Jqk/rtRE1D6nFa+q0Og4A32Ajg0Qbr2prKcgxW8QxHuOEx/yuUkOpC9znW3qJ6uh D60b1tP03RasdfQEnoaKI3Z0+nKulBFVZW5iIQKTZgp+2Vqr3umodv4PUcz3wq5g nVRbtAu5pS904Jt+mr64DGW2ssBrYGl5HEwRG83r0coXgpO+GR0kZNZ9CoQtG4xl wF2wTL8PqvJNqBamQ5KJi8Mqeb2FkEc8hgfy6EtUPfOAs3zJkbQv1Q3IcGT8UvRL 8UAGdPsn1LQ51BVDLaZ4 =77Lm -----END PGP SIGNATURE----- From rosuav at gmail.com Wed Nov 18 15:24:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 07:24:06 +1100 Subject: Mapping between python packages and distro packages? In-Reply-To: <201511181930.tAIJUYUc017056@fido.openend.se> References: <20151118032903.GA8040@sg1> <85vb90c4fv.fsf@benfinney.id.au> <201511181930.tAIJUYUc017056@fido.openend.se> Message-ID: On Thu, Nov 19, 2015 at 6:30 AM, Laura Creighton wrote: > apt-cache search works reasonably well, as long as you are > willing to put up with some false hits. And it assumes you have a debian > system handy, of course. I suspect the most common case is "how can I get this on _this exact system_", which isn't too hard; but the next most common case is "I need to tell my friend how to get it on his/her system", which leaves me sometimes wondering what the equivalent RPM for some DEB is, or what sort of support there is for Program X on RHEL Y. So it would be really nice if there were some straight-forward way to recognize these equivalencies... but I doubt there is :( ChrisA From rosuav at gmail.com Wed Nov 18 15:29:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 07:29:24 +1100 Subject: handling of non-ASCII filenames? In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 5:09 AM, Ulli Horlacher wrote: > Chris Angelico wrote: > >> > As I am Python newbie I have not quite understood the Python character >> > encoding scheme :-} >> > >> > Where can I find a good introduction of this topic? >> >> Here are a couple of articles on the basics of Unicode: >> >> http://www.joelonsoftware.com/articles/Unicode.html > > I do Unicode programming for over 20 years. So, I do have a basic > understanding of it. I am just new to Python. Ah, okay. When you said you didn't understand the character encoding scheme, I thought you meant Unicode itself. In any case, I make no apology for recommending those two articles to people... at very worst you already know that stuff :) >> http://nedbatchelder.com/text/unipain.html > > Thanks. I will read it. That's a great talk, and has the coolness of having zero pictures on its slides. I love it. >> If you can use Python 3 > > I cannot use it, because the Python compiler pyinstaller does not work > with it on Windows: > > S:\python>pyinstaller.exe --onefile tk.py > Traceback (most recent call last): > File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in > load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')() > File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l > oad_entry_point > return get_distribution(dist).load_entry_point(group, name) > File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, in > load_entry_point > return ep.load() > File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, in > load > return self.resolve() > File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, in > resolve > module = __import__(self.module_name, fromlist=['__name__'], level=0) > File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in ule> > import PyInstaller.building.build_main > File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", line > 31, in > from ..depend import bindepend > File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 40, > in > from ..utils.win32.winmanifest import RT_MANIFEST > File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l > ine 97, in > from PyInstaller.utils.win32 import winresource > File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l > ine 20, in > import pywintypes > File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in dule> > __import_pywin32_system_module__("pywintypes", globals()) > File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __im > port_pywin32_system_module__ > import _win32sysloader > ImportError: DLL load failed: The specified module could not be found. > > > With python 2.7, pyinstaller runs without problems. Hmm. That's a separate consideration. If you take a step back and ask the broader question "How can I package my Python 3.5 script into a .exe file?", I'm pretty sure there is an answer; maybe pyinstaller isn't the way to do it. (I'm not an expert on exe file production.) Does your script run happily in 3.5 if it isn't packaged into an exe? ChrisA From rosuav at gmail.com Wed Nov 18 15:35:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 07:35:36 +1100 Subject: How to create a folder using IMAPLib? In-Reply-To: <564CD930.9000005@cajuntechie.org> References: <564CD930.9000005@cajuntechie.org> Message-ID: On Thu, Nov 19, 2015 at 7:01 AM, Anthony Papillion wrote: > I'm writing a program to help migrate mail from one host to another > with a few special circumstances. I'm able to get a list off of the > source IMAP server using the .list() command but I'm not quite sure > how to create a folder on the target machine. > > Does anyone know how to create a folder using IMAPlib? They're called "mailboxes", which I'll admit is not the most obvious name, but imaplib is following the IMAP spec here. You can create them with .create() and delete them with .delete(). ChrisA From rxjwg98 at gmail.com Wed Nov 18 16:08:11 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 18 Nov 2015 13:08:11 -0800 (PST) Subject: What is a function parameter =[] for? Message-ID: Hi, I have tried the below function and find that it can remember the previous setting value to 'val'. I think the second parameter has something on this effect, but I don't know the name and function of '=[]' in this application. Could you explain a little to me? Thanks, def eList(val, list0=[]): list0.append(val) return list0 list1 = eList(12) list1 = eList('a') From random832 at fastmail.com Wed Nov 18 16:38:30 2015 From: random832 at fastmail.com (Random832) Date: Wed, 18 Nov 2015 16:38:30 -0500 Subject: How can I export data from a website and write the contents to a text file? References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> Message-ID: <87si43kmy1.fsf@fastmail.com> ryguy7272 writes: > text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") Remove the "b" from this line. This is causing it to omit the platform-specific translation of "\n", which means some Windows applications will not recognize the line endings. From lac at openend.se Wed Nov 18 16:58:47 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 18 Nov 2015 22:58:47 +0100 Subject: How to create a folder using IMAPLib? In-Reply-To: References: <564CD930.9000005@cajuntechie.org> Message-ID: <201511182158.tAILwlNj027195@fido.openend.se> In a message of Thu, 19 Nov 2015 07:35:36 +1100, Chris Angelico writes: >On Thu, Nov 19, 2015 at 7:01 AM, Anthony Papillion > wrote: >> I'm writing a program to help migrate mail from one host to another >> with a few special circumstances. I'm able to get a list off of the >> source IMAP server using the .list() command but I'm not quite sure >> how to create a folder on the target machine. >> >> Does anyone know how to create a folder using IMAPlib? > >They're called "mailboxes", which I'll admit is not the most obvious >name, but imaplib is following the IMAP spec here. You can create them >with .create() and delete them with .delete(). > >ChrisA >-- >https://mail.python.org/mailman/listinfo/python-list Sample code here: https://pymotw.com/2/imaplib/ Laura From gordon at panix.com Wed Nov 18 17:05:19 2015 From: gordon at panix.com (John Gordon) Date: Wed, 18 Nov 2015 22:05:19 +0000 (UTC) Subject: What is a function parameter =[] for? References: Message-ID: In fl writes: > Hi, > I have tried the below function and find that it can remember the previous > setting value to 'val'. I think the second parameter has something on this > effect, but I don't know the name and function of '=[]' in this application. > Could you explain a little to me? > Thanks, > def eList(val, list0=[]): > list0.append(val) > return list0 > list1 = eList(12) > list1 = eList('a') That is a default parameter. If eList() is called without an argument for list0, it will use [] as the default value. -- 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 ian.g.kelly at gmail.com Wed Nov 18 17:11:43 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 Nov 2015 15:11:43 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: > Hi, > > I have tried the below function and find that it can remember the previous > setting value to 'val'. I think the second parameter has something on this > effect, but I don't know the name and function of '=[]' in this application. > > Could you explain a little to me? > Thanks, > > > def eList(val, list0=[]): > list0.append(val) > return list0 > list1 = eList(12) > list1 = eList('a') The list0 parameter has a default value, which is [], an initially empty list. The default value is evaluated when the function is defined, not when it is called, so the same list object is used each time and changes to the list are consequently retained between calls. From invalid at invalid.invalid Wed Nov 18 17:33:11 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 18 Nov 2015 22:33:11 +0000 (UTC) Subject: What is a function parameter =[] for? References: Message-ID: On 2015-11-18, Ian Kelly wrote: > On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: >> def eList(val, list0=[]): > The list0 parameter has a default value, which is [], an initially > empty list. The default value is evaluated when the function is > defined, not when it is called, so the same list object is used each > time and changes to the list are consequently retained between calls. One might consider this a way to have a local varible inside a function that's "static" a-la C. However, one probably oughtn't. -- Grant Edwards grant.b.edwards Yow! Gibble, Gobble, we at ACCEPT YOU ... gmail.com From framstag at rus.uni-stuttgart.de Wed Nov 18 17:37:59 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 22:37:59 +0000 (UTC) Subject: handling of non-ASCII filenames? References: Message-ID: Chris Angelico wrote: > >> If you can use Python 3 > > > > I cannot use it, because the Python compiler pyinstaller does not work > > with it on Windows: > > > > S:\python>pyinstaller.exe --onefile tk.py > > Traceback (most recent call last): > > File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in > > load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')() > > File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l > > oad_entry_point (...) > > > > With python 2.7, pyinstaller runs without problems. > > Hmm. That's a separate consideration. If you take a step back and ask > the broader question "How can I package my Python 3.5 script into a > .exe file?", I'm pretty sure there is an answer; maybe pyinstaller > isn't the way to do it. (I'm not an expert on exe file production.) pyinstaller works without any problems with Python 2.7.10 > Does your script run happily in 3.5 if it isn't packaged into an exe? Yes. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From rxjwg98 at gmail.com Wed Nov 18 17:38:31 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 18 Nov 2015 14:38:31 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote: > On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: > > Hi, > > > > I have tried the below function and find that it can remember the previous > > setting value to 'val'. I think the second parameter has something on this > > effect, but I don't know the name and function of '=[]' in this application. > > > > Could you explain a little to me? > > Thanks, > > > > > > def eList(val, list0=[]): > > list0.append(val) > > return list0 > > list1 = eList(12) > > list1 = eList('a') > > The list0 parameter has a default value, which is [], an initially > empty list. The default value is evaluated when the function is > defined, not when it is called, so the same list object is used each > time and changes to the list are consequently retained between calls. Thanks. The amazing thing to me is that the following two line codes: list1 = eList(12) list2 = eList('a') will have both list1 and list2 the same cascaded values: list1 Out[2]: [12, 'a'] list2 Out[3]: [12, 'a'] I have known object concept in Python. 1. Why do they have the same list value? Function eList must be for this purpose? 2. If I want to have two separate lists, how to avoid the above result? Function eList is not for this purpose? Thanks again. From framstag at rus.uni-stuttgart.de Wed Nov 18 17:46:17 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 18 Nov 2015 22:46:17 +0000 (UTC) Subject: pyinstaller and Python 3.5 on Windows? Message-ID: To run my Python programs on other Windows systems without a Python installation I must create standalone Windows executables. pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but with Python 3.5 I get: S:\python>pyinstaller.exe --onefile tk.py Traceback (most recent call last): File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')() File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l oad_entry_point return get_distribution(dist).load_entry_point(group, name) File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, in load_entry_point return ep.load() File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, in load return self.resolve() File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in import PyInstaller.building.build_main File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", line 31, in from ..depend import bindepend File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 40, in from ..utils.win32.winmanifest import RT_MANIFEST File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l ine 97, in from PyInstaller.utils.win32 import winresource File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l ine 20, in import pywintypes File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in __import_pywin32_system_module__("pywintypes", globals()) File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __im port_pywin32_system_module__ import _win32sysloader ImportError: DLL load failed: The specified module could not be found. Is there a solution available? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From ian.g.kelly at gmail.com Wed Nov 18 17:47:00 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 Nov 2015 15:47:00 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Wed, Nov 18, 2015 at 3:38 PM, fl wrote: > On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote: >> On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: >> > Hi, >> > >> > I have tried the below function and find that it can remember the previous >> > setting value to 'val'. I think the second parameter has something on this >> > effect, but I don't know the name and function of '=[]' in this application. >> > >> > Could you explain a little to me? >> > Thanks, >> > >> > >> > def eList(val, list0=[]): >> > list0.append(val) >> > return list0 >> > list1 = eList(12) >> > list1 = eList('a') >> >> The list0 parameter has a default value, which is [], an initially >> empty list. The default value is evaluated when the function is >> defined, not when it is called, so the same list object is used each >> time and changes to the list are consequently retained between calls. > > Thanks. The amazing thing to me is that the following two line codes: > list1 = eList(12) > list2 = eList('a') > > will have both list1 and list2 the same cascaded values: > > list1 > Out[2]: [12, 'a'] > > list2 > Out[3]: [12, 'a'] > > I have known object concept in Python. > 1. Why do they have the same list value? > Function eList must be for this purpose? Because eList returns list0, and as explained above list0 is the same list in both calls. Therefore list1 and list2 are the same list. > 2. If I want to have two separate lists, how to avoid the above result? > Function eList is not for this purpose? The usual advice is to not use a mutable object as the default value. If you want the default to be an empty list, it's usually better set it to None and then make it an empty list if the value is None. For example: def eList(val, list0=None): if list0 is None: list0 = [] list0.append(val) return list0 From rxjwg98 at gmail.com Wed Nov 18 17:48:57 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 18 Nov 2015 14:48:57 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: <49ad34bd-0943-4ac0-92e7-4636d2f9d447@googlegroups.com> On Wednesday, November 18, 2015 at 5:38:45 PM UTC-5, fl wrote: > On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote: > > On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: > > > Hi, > > > > > > I have tried the below function and find that it can remember the previous > > > setting value to 'val'. I think the second parameter has something on this > > > effect, but I don't know the name and function of '=[]' in this application. > > > > > > Could you explain a little to me? > > > Thanks, > > > > > > > > > def eList(val, list0=[]): > > > list0.append(val) > > > return list0 > > > list1 = eList(12) > > > list1 = eList('a') > > > > The list0 parameter has a default value, which is [], an initially > > empty list. The default value is evaluated when the function is > > defined, not when it is called, so the same list object is used each > > time and changes to the list are consequently retained between calls. > > Thanks. The amazing thing to me is that the following two line codes: > list1 = eList(12) > list2 = eList('a') > > will have both list1 and list2 the same cascaded values: > > list1 > Out[2]: [12, 'a'] > > list2 > Out[3]: [12, 'a'] > > I have known object concept in Python. > 1. Why do they have the same list value? > Function eList must be for this purpose? > 2. If I want to have two separate lists, how to avoid the above result? > Function eList is not for this purpose? > > Thanks again. After several trials, I find that the cascade list is caused by the second function parameter absent. It is interesting. Thanks. From bc at freeuk.com Wed Nov 18 18:14:12 2015 From: bc at freeuk.com (BartC) Date: Wed, 18 Nov 2015 23:14:12 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On 18/11/2015 22:11, Ian Kelly wrote: > On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: >> Hi, >> >> I have tried the below function and find that it can remember the previous >> setting value to 'val'. I think the second parameter has something on this >> effect, but I don't know the name and function of '=[]' in this application. >> >> Could you explain a little to me? >> Thanks, >> >> >> def eList(val, list0=[]): >> list0.append(val) >> return list0 >> list1 = eList(12) >> list1 = eList('a') > > The list0 parameter has a default value, which is [], an initially > empty list. The default value is evaluated when the function is > defined, not when it is called, so the same list object is used each > time and changes to the list are consequently retained between calls. That is really bizarre behaviour. So, looking at some source code, a default value for certain types is only certain to be that value for the very first call of that function? > The default value is evaluated when the function is > defined, not when it is called Given the amount of pointless dynamic stuff that goes on in Python, I'm surprised they've overlooked this one! It seems simple enough to me to check for a missing parameter, and to assign whatever default value was designated ([] in this case). (How does the default mechanism work now?) -- Bartc From vincent at vincentdavis.net Wed Nov 18 18:18:28 2015 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 18 Nov 2015 16:18:28 -0700 Subject: Public key encryption example. Message-ID: This might be a "Let me Google that for you question", I tried. I am looking for the "simplest" example of sending(encrypting) and receiving(decrypting) using public key encryption. I am think of something along the lines of having all the keys in local files and saving and reading the message from a local file. Possibly using cryptography library elliptic-curve https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/#elliptic-curve-signature-algorithms Surly there is an example out there? Vincent Davis From rosuav at gmail.com Wed Nov 18 18:22:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 10:22:04 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: > On 18/11/2015 22:11, Ian Kelly wrote: >> >> On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: >>> >>> Hi, >>> >>> I have tried the below function and find that it can remember the >>> previous >>> setting value to 'val'. I think the second parameter has something on >>> this >>> effect, but I don't know the name and function of '=[]' in this >>> application. >>> >>> Could you explain a little to me? >>> Thanks, >>> >>> >>> def eList(val, list0=[]): >>> list0.append(val) >>> return list0 >>> list1 = eList(12) >>> list1 = eList('a') >> >> >> The list0 parameter has a default value, which is [], an initially >> empty list. The default value is evaluated when the function is >> defined, not when it is called, so the same list object is used each >> time and changes to the list are consequently retained between calls. > > > That is really bizarre behaviour. > > So, looking at some source code, a default value for certain types is only > certain to be that value for the very first call of that function? On the contrary, it is certain always to be that exact object. >> The default value is evaluated when the function is >> defined, not when it is called > > Given the amount of pointless dynamic stuff that goes on in Python, I'm > surprised they've overlooked this one! > > It seems simple enough to me to check for a missing parameter, and to assign > whatever default value was designated ([] in this case). (How does the > default mechanism work now?) It's exactly the way Ian described it. Functions are defined, not declared - it's an executable statement. When the 'def' statement is reached, the expressions in the argument defaults get evaluated, and the results get saved into the function's attributes: >>> def demo(factory): ... def func(x=factory()): ... x.append("Hello!") ... return x ... return func ... >>> def make_list(): ... print("I'm making a list!") ... return [] ... >>> f1 = demo(make_list) I'm making a list! >>> f2 = demo(make_list) I'm making a list! >>> f3 = demo(make_list) I'm making a list! >>> f1() ['Hello!'] >>> f1() ['Hello!', 'Hello!'] >>> f1() ['Hello!', 'Hello!', 'Hello!'] >>> f2() ['Hello!'] >>> f2() ['Hello!', 'Hello!'] >>> f3() ['Hello!'] >>> f1.__defaults__ (['Hello!', 'Hello!', 'Hello!'],) >>> id(f1()) 140470001247688 >>> id(f1()) 140470001247688 >>> id(f1()) 140470001247688 >>> id(f1()) 140470001247688 >>> id(f1()) 140470001247688 >>> id(f1.__defaults__[0]) 140470001247688 If you want the expression (eg the empty list display) to be evaluated every time the body of the function is executed, you put it into the body of the function. There is no magic here. ChrisA From no.email at nospam.invalid Wed Nov 18 18:56:01 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 18 Nov 2015 15:56:01 -0800 Subject: Public key encryption example. References: Message-ID: <87vb8ylv5a.fsf@nightsong.com> Vincent Davis writes: > I am looking for the "simplest" example of sending(encrypting) and > receiving(decrypting) using public key encryption. I am think of something > along the lines of having all the keys in local files and saving and > reading the message from a local file. It's very easy to make mistakes doing stuff like that. Your simplest bet is to shell out to GPG or something comparable. From ian.g.kelly at gmail.com Wed Nov 18 19:02:39 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 Nov 2015 17:02:39 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: >> So, looking at some source code, a default value for certain types is only >> certain to be that value for the very first call of that function? > > On the contrary, it is certain always to be that exact object. "Certain" may be a bit overly strong. >>> def f(x=42): ... return x ... >>> f() 42 >>> f.__defaults__ = (43,) >>> f() 43 From rosuav at gmail.com Wed Nov 18 19:04:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 11:04:00 +1100 Subject: Public key encryption example. In-Reply-To: <87vb8ylv5a.fsf@nightsong.com> References: <87vb8ylv5a.fsf@nightsong.com> Message-ID: On Thu, Nov 19, 2015 at 10:56 AM, Paul Rubin wrote: > Vincent Davis writes: >> I am looking for the "simplest" example of sending(encrypting) and >> receiving(decrypting) using public key encryption. I am think of something >> along the lines of having all the keys in local files and saving and >> reading the message from a local file. > > It's very easy to make mistakes doing stuff like that. Your simplest > bet is to shell out to GPG or something comparable. It's not that hard to pull up a library. I've never done it in Python, though. ChrisA From rxjwg98 at gmail.com Wed Nov 18 19:05:37 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 18 Nov 2015 16:05:37 -0800 (PST) Subject: Could you explain why the following generates 4 same elements list? Message-ID: <3f1eecc8-e23d-4f86-abf8-38044939d085@googlegroups.com> Hi, I cannot reason out why the code: //////// def mpl(): return [lambda x : i * x for i in range(4)] print [m(2) for m in mpl()] ///////// has result: [6, 6, 6, 6] I have tried to simplify the above code to an easy understanding form, but fails. Either the modified code does not work, or it does not show relation to the original code. Could you explore it a little for me to understand it easier? Thanks in advance. From PointedEars at web.de Wed Nov 18 19:13:28 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 19 Nov 2015 01:13:28 +0100 Subject: pyinstaller and Python 3.5 on Windows? References: Message-ID: <16273698.Ox6ucYQkhb@PointedEars.de> Ulli Horlacher wrote: > To run my Python programs on other Windows systems without a Python > installation I must create standalone Windows executables. > > pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but > with Python 3.5 I get: > > [b0rked stack trace] > > Is there a solution available? Maybe. It would help if you posted something easier readable. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From rosuav at gmail.com Wed Nov 18 19:14:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 11:14:49 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly wrote: > On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico wrote: >> On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: >>> So, looking at some source code, a default value for certain types is only >>> certain to be that value for the very first call of that function? >> >> On the contrary, it is certain always to be that exact object. > > "Certain" may be a bit overly strong. > >>>> def f(x=42): > ... return x > ... >>>> f() > 42 >>>> f.__defaults__ = (43,) >>>> f() > 43 I'll raise you one. >>> def f(x=42): ... return x ... >>> f() 42 >>> import ctypes >>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)).value=42 >>> f.__defaults__ = (43,) >>> f() 42 >>> Nothing is certain in Python. And two wrongs can make a... hmm... no, this is not a right. It is not a privilege either. It is a dastardly trick played on people's minds. ChrisA From rxjwg98 at gmail.com Wed Nov 18 19:34:50 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 18 Nov 2015 16:34:50 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> On Wednesday, November 18, 2015 at 7:15:05 PM UTC-5, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly wrote: > > On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico wrote: > >> On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: > >>> So, looking at some source code, a default value for certain types is only > >>> certain to be that value for the very first call of that function? > >> > >> On the contrary, it is certain always to be that exact object. > > > > "Certain" may be a bit overly strong. > > > >>>> def f(x=42): > > ... return x > > ... > >>>> f() > > 42 > >>>> f.__defaults__ = (43,) > >>>> f() > > 43 > > I'll raise you one. > > >>> def f(x=42): > ... return x > ... > >>> f() > 42 > >>> import ctypes > >>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)).value=42 > >>> f.__defaults__ = (43,) > >>> f() > 42 > >>> > > Nothing is certain in Python. And two wrongs can make a... hmm... no, > this is not a right. It is not a privilege either. It is a dastardly > trick played on people's minds. > > ChrisA After I try with list1 = eList(12, [2]) and list1 = eList(12) it gives me new surprises. Even though I delete list1, the subsequent list1 = eList(12) will remember the number of '12' of the previous sequence. This is my new question: What does 'del' do? It does not look like a thorough list deletion from the effect. Thanks, ..................... list1 = eList(12, [2]) list1 Out[57]: [2, 12] list1 = eList(12) list1 Out[59]: [12, 12, 12] list1 = eList(12, [2]) list1 Out[61]: [2, 12] list1 = eList(12, [2]) list1 Out[63]: [2, 12] list1 = eList(12, [2]) list1 Out[65]: [2, 12] list1 = eList(12) list1 Out[67]: [12, 12, 12, 12] list1 = eList(12) list1 Out[69]: [12, 12, 12, 12, 12] list1 = eList(12, [2]) list1 Out[71]: [2, 12] list1 = eList(12) list1 Out[73]: [12, 12, 12, 12, 12, 12] del list1 list1 = eList(12, [2]) list1 = eList(12) list1 Out[77]: [12, 12, 12, 12, 12, 12, 12] From ian.g.kelly at gmail.com Wed Nov 18 19:47:51 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 Nov 2015 17:47:51 -0700 Subject: Could you explain why the following generates 4 same elements list? In-Reply-To: <3f1eecc8-e23d-4f86-abf8-38044939d085@googlegroups.com> References: <3f1eecc8-e23d-4f86-abf8-38044939d085@googlegroups.com> Message-ID: On Wed, Nov 18, 2015 at 5:05 PM, fl wrote: > Hi, > > I cannot reason out why the code: > //////// > def mpl(): > return [lambda x : i * x for i in range(4)] > > print [m(2) for m in mpl()] > ///////// > > has result: > > [6, 6, 6, 6] > > > I have tried to simplify the above code to an easy understanding form, > but fails. Either the modified code does not work, or it does not show > relation to the original code. > > Could you explore it a little for me to understand it easier? https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result From ian.g.kelly at gmail.com Wed Nov 18 19:52:33 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 Nov 2015 17:52:33 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> References: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> Message-ID: On Wed, Nov 18, 2015 at 5:34 PM, fl wrote: > After I try with > > list1 = eList(12, [2]) > > and > > list1 = eList(12) > > it gives me new surprises. Even though I delete list1, the subsequent > list1 = eList(12) > will remember the number of '12' of the previous sequence. This is my new > question: What does 'del' do? It does not look like a thorough list deletion > from the effect. It just deletes the variable list1, i.e. it unbinds the value from the name. It does nothing at all to the list that was bound, as other variables may still be bound to it. The core issue is that the default value of your eList function is always the same list. Assigning that list to a variable and then unassigning it is not going to change that. From python at mrabarnett.plus.com Wed Nov 18 20:02:11 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 19 Nov 2015 01:02:11 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> References: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> Message-ID: <564D1F93.7000902@mrabarnett.plus.com> On 2015-11-19 00:34, fl wrote: > On Wednesday, November 18, 2015 at 7:15:05 PM UTC-5, Chris Angelico wrote: >> On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly wrote: >> > On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico wrote: >> >> On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: >> >>> So, looking at some source code, a default value for certain types is only >> >>> certain to be that value for the very first call of that function? >> >> >> >> On the contrary, it is certain always to be that exact object. >> > >> > "Certain" may be a bit overly strong. >> > >> >>>> def f(x=42): >> > ... return x >> > ... >> >>>> f() >> > 42 >> >>>> f.__defaults__ = (43,) >> >>>> f() >> > 43 >> >> I'll raise you one. >> >> >>> def f(x=42): >> ... return x >> ... >> >>> f() >> 42 >> >>> import ctypes >> >>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)).value=42 >> >>> f.__defaults__ = (43,) >> >>> f() >> 42 >> >>> >> >> Nothing is certain in Python. And two wrongs can make a... hmm... no, >> this is not a right. It is not a privilege either. It is a dastardly >> trick played on people's minds. >> >> ChrisA > > After I try with > > list1 = eList(12, [2]) > If you pass something into the parameter, the default isn't needed/used. > and > > list1 = eList(12) > You're not passing anything into the parameter, so the default is used. > it gives me new surprises. Even though I delete list1, the subsequent > list1 = eList(12) > will remember the number of '12' of the previous sequence. This is my new > question: What does 'del' do? It does not look like a thorough list deletion > from the effect. > No, "del list1" doesn't delete the list, it deletes the name "list1". The list still exists as the default parameter. A default parameter is evaluated when the function is defined, and that value exists as the default as long as the function exists. If the value is mutable (can be modified), and you modify it, then the function will see that modified value. From ben+python at benfinney.id.au Wed Nov 18 20:26:28 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2015 12:26:28 +1100 Subject: What is a function parameter =[] for? References: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> <564D1F93.7000902@mrabarnett.plus.com> Message-ID: <85oaeqdbjv.fsf@benfinney.id.au> MRAB writes: > On 2015-11-19 00:34, fl wrote: > > What does 'del' do? It does not look like a thorough list deletion > > from the effect. > > No, "del list1" doesn't delete the list, it deletes the name "list1". > The list still exists as the default parameter. More generally, ?del? deletes a *reference*. Names are one kind of reference; others include items in a collection such as a dict or set. Deleting a reference *never* affects the value referred to. However, once a value has no more references, the program can no longer access it, so the Python machine is at liberty to delete the value behind the scenes at some future point. > A default parameter is evaluated when the function is defined, and > that value exists as the default as long as the function exists. So, because the function retains a reference to the value, the value remains unaffected when you delete the reference ?list1?. -- \ ?True greatness is measured by how much freedom you give to | `\ others, not by how much you can coerce others to do what you | _o__) want.? ?Larry Wall | Ben Finney From bc at freeuk.com Wed Nov 18 20:41:47 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 01:41:47 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On 18/11/2015 23:22, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: >> On 18/11/2015 22:11, Ian Kelly wrote: >>> >>> On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: >>>> >>>> Hi, >>>> >>>> I have tried the below function and find that it can remember the >>>> previous >>>> setting value to 'val'. I think the second parameter has something on >>>> this >>>> effect, but I don't know the name and function of '=[]' in this >>>> application. >>>> >>>> Could you explain a little to me? >>>> Thanks, >>>> >>>> >>>> def eList(val, list0=[]): >>>> list0.append(val) >>>> return list0 >>>> list1 = eList(12) >>>> list1 = eList('a') >>> >>> >>> The list0 parameter has a default value, which is [], an initially >>> empty list. The default value is evaluated when the function is >>> defined, not when it is called, so the same list object is used each >>> time and changes to the list are consequently retained between calls. >> >> >> That is really bizarre behaviour. >> >> So, looking at some source code, a default value for certain types is only >> certain to be that value for the very first call of that function? > > On the contrary, it is certain always to be that exact object. But, not the same value that appears as the default? >>> The default value is evaluated when the function is >>> defined, not when it is called >> >> Given the amount of pointless dynamic stuff that goes on in Python, I'm >> surprised they've overlooked this one! >> >> It seems simple enough to me to check for a missing parameter, and to assign >> whatever default value was designated ([] in this case). (How does the >> default mechanism work now?) > > It's exactly the way Ian described it. Functions are defined, not > declared - it's an executable statement. When the 'def' statement is > reached, the expressions in the argument defaults get evaluated, and > the results get saved into the function's attributes: .... Sorry, I didn't understand any of that. Let's try a simpler example like the OP's. There's this innocuous looking function that you are interested in calling: def fn(a=[]): # print ("Function fn called with",a) | a.append(10) | return a It appends a value to its argument and returns the result. It looks like at first like, if called with no argument, it will return [10]. But what it actually returns depends on the entire call history since the program started executing, something you probably have no knowledge of and no control over. So if fn has previously been called a million times with no argument, then after this call: x=fn() x contains a list of a million tens, not one. I'd say most people would be rather surprised by that. I suspect those same people (unless they are experts in the murky corners of the language) would expect: x=fn() when fn specifies a default argument of [], to be the same as writing: x=fn([]) and not be dependent on fn's entire call history. Your solution of using: def fn(a=None): is not really satisfactory. Partly because it now utilities two mechanisms for the default: first to get None, then some extra code to get []. But also it's no longer obvious how the function works and what the default is. At least, you can't tell from a glance at the start of the function that [] is the default. -- Bartc From rosuav at gmail.com Wed Nov 18 20:59:18 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 12:59:18 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 12:41 PM, BartC wrote: > On 18/11/2015 23:22, Chris Angelico wrote: >> On the contrary, it is certain always to be that exact object. > > But, not the same value that appears as the default? Nope. Mutable objects are never guaranteed to retain the same values. That's kinda the point. > Sorry, I didn't understand any of that. Let's try a simpler example like the > OP's. There's this innocuous looking function that you are interested in > calling: > > def fn(a=[]): > # print ("Function fn called with",a) > | a.append(10) > | return a > > It appends a value to its argument and returns the result. > > It looks like at first like, if called with no argument, it will return > [10]. If you want to think of function defaults as being values, then yes. But they're not. They're objects. > But what it actually returns depends on the entire call history since the > program started executing, something you probably have no knowledge of and > no control over. So if fn has previously been called a million times with no > argument, then after this call: > > x=fn() > > x contains a list of a million tens, not one. I'd say most people would be > rather surprised by that. So if you don't want them to be surprised by that, don't use mutable default arguments and expect them to have specific values. > I suspect those same people (unless they are experts in the murky corners of > the language) would expect: > > x=fn() > > when fn specifies a default argument of [], to be the same as writing: > > x=fn([]) > > and not be dependent on fn's entire call history. Tell me, do you expect these to do the same thing? x = [] fn(x) fn(x) fn(x) # or fn([]) fn([]) fn([]) The distinction is exactly the same. If you can understand that the first one constructs a single object and uses it three times, then you should be able to understand that the function default is also constructed once and used every time. > Your solution of using: > > def fn(a=None): > > is not really satisfactory. Partly because it now utilities two mechanisms > for the default: first to get None, then some extra code to get []. But also > it's no longer obvious how the function works and what the default is. At > least, you can't tell from a glance at the start of the function that [] is > the default. This I do agree with. It's a bit clunky. It would be nice to be able to say: def fn(a=`[]`): """If a is not passed, it will be a new empty list""" and have it function the same as: def fn(*args): a = args[0] if args else [] but currently there's no mechanism for it. (The example spelling I gave is almost certainly not going to be used, due to the Tim Peters' Monitor Grit argument, but something could probably be found.) It's a sufficiently common situation that it would merit its own syntax. Want to write up a PEP? All you need is a syntax that people can get behind. ChrisA From ben+python at benfinney.id.au Wed Nov 18 21:08:45 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2015 13:08:45 +1100 Subject: What is a function parameter =[] for? References: Message-ID: <85k2ped9le.fsf@benfinney.id.au> Chris Angelico writes: > On Thu, Nov 19, 2015 at 12:41 PM, BartC wrote: > > On 18/11/2015 23:22, Chris Angelico wrote: > >> On the contrary, it is certain always to be that exact object. > > > > But, not the same value that appears as the default? It depends what you mean by ?the same value?. > Nope. Mutable objects are never guaranteed to retain the same values. > That's kinda the point. Well, they are the *same value*, if by ?value? you mean ?a particular object?. On the other hand, the value can *change* over time, while remaining the same object. So it will not be equal to its initial state, even though it is the same object. -- \ ?[F]reedom of speech does not entail freedom to have your ideas | `\ accepted by governments and incorporated into law and policy.? | _o__) ?Russell Blackford, 2010-03-06 | Ben Finney From rosuav at gmail.com Wed Nov 18 21:15:29 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 13:15:29 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <85k2ped9le.fsf@benfinney.id.au> References: <85k2ped9le.fsf@benfinney.id.au> Message-ID: On Thu, Nov 19, 2015 at 1:08 PM, Ben Finney wrote: >> Nope. Mutable objects are never guaranteed to retain the same values. >> That's kinda the point. > > Well, they are the *same value*, if by ?value? you mean ?a particular > object?. > > On the other hand, the value can *change* over time, while remaining the > same object. So it will not be equal to its initial state, even though > it is the same object. I would normally interpret "value" as "the quality compared with the == operator". As such, mutables can change in value while retaining their identities: >>> x, y = [], [] >>> x == y True >>> x.append(1) >>> x == y False >>> y.append(1) >>> x == y True So a mutable default argument will always retain its identity (barring shenanigans), but may not retain its value. ChrisA From vincent at vincentdavis.net Wed Nov 18 21:22:30 2015 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 18 Nov 2015 19:22:30 -0700 Subject: Public key encryption example. In-Reply-To: References: <87vb8ylv5a.fsf@nightsong.com> Message-ID: Found an example, needs a little updating but then it works (appears to) in python 3.5. http://coding4streetcred.com/blog/post/Asymmetric-Encryption-Revisited-(in-PyCrypto) Vincent Davis 720-301-3003 On Wed, Nov 18, 2015 at 5:04 PM, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 10:56 AM, Paul Rubin > wrote: > > Vincent Davis writes: > >> I am looking for the "simplest" example of sending(encrypting) and > >> receiving(decrypting) using public key encryption. I am think of > something > >> along the lines of having all the keys in local files and saving and > >> reading the message from a local file. > > > > It's very easy to make mistakes doing stuff like that. Your simplest > > bet is to shell out to GPG or something comparable. > > It's not that hard to pull up a library. I've never done it in Python, > though. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rxjwg98 at gmail.com Wed Nov 18 21:55:33 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 18 Nov 2015 18:55:33 -0800 (PST) Subject: Question about 'print' in a loop Message-ID: <75f51ee1-907c-47c4-9be9-58241ff83115@googlegroups.com> Hi, >From previous post, I get many helpful replies. Now I have a new question when I run this example code: --------- sq=[] for xx in range(5): print 'here' sq.append(lambda:xx**2) here here here here here xx Out[150]: 4 sq[2]() Out[151]: 16 sq[3]() Out[152]: 16 ///// There are only one time 5 'here' printed out, but there is no 'here' print out in thereafter call sq[2]() etc. How to understand this phenomenon? Thanks, From rosuav at gmail.com Wed Nov 18 22:11:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 14:11:02 +1100 Subject: Question about 'print' in a loop In-Reply-To: <75f51ee1-907c-47c4-9be9-58241ff83115@googlegroups.com> References: <75f51ee1-907c-47c4-9be9-58241ff83115@googlegroups.com> Message-ID: On Thu, Nov 19, 2015 at 1:55 PM, fl wrote: > There are only one time 5 'here' printed out, but there is no 'here' print > out in thereafter call sq[2]() etc. How to understand this phenomenon? Code does what code should. Before you ask for comprehension of "this phenomenon", why don't you tell us what you expect your code to do, and why? I just asked my non-programmer sister and she was completely unsurprised by what Python did here. ChrisA From rxjwg98 at gmail.com Wed Nov 18 22:20:09 2015 From: rxjwg98 at gmail.com (fl) Date: Wed, 18 Nov 2015 19:20:09 -0800 (PST) Subject: Question about 'print' in a loop In-Reply-To: References: <75f51ee1-907c-47c4-9be9-58241ff83115@googlegroups.com> Message-ID: <9982d291-891a-4132-a0cf-2bc94b50d05f@googlegroups.com> On Wednesday, November 18, 2015 at 10:11:24 PM UTC-5, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 1:55 PM, fl wrote: > > There are only one time 5 'here' printed out, but there is no 'here' print > > out in thereafter call sq[2]() etc. How to understand this phenomenon? > > Code does what code should. > > Before you ask for comprehension of "this phenomenon", why don't you > tell us what you expect your code to do, and why? I just asked my > non-programmer sister and she was completely unsurprised by what > Python did here. > > ChrisA Excuse me. That is my unclear question. I expect that each call sq will have one print 'here', as I suppose that print 'here' is inside the loop. Oh, I just realize that it is not a function. It constructs list sq. When the loop (function as a constructor (not necessarily correct called), it print 5 'here'. Thanks for you feedback. From auriocus at gmx.de Thu Nov 19 02:04:08 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 19 Nov 2015 08:04:08 +0100 Subject: pyinstaller and Python 3.5 on Windows? In-Reply-To: References: Message-ID: Am 18.11.15 um 23:46 schrieb Ulli Horlacher: > To run my Python programs on other Windows systems without a Python > installation I must create standalone Windows executables. > > pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but > with Python 3.5 I get: > [stack trace] Are you using the newest version? According to http://www.pyinstaller.org/ they claim support for Python3. Does a hello world script work? If yes, it may have to do with some packages in your script. Is pywin32 a package that you load, or is it Pyinstaller that needs this? Christian From dieter at handshake.de Thu Nov 19 02:27:52 2015 From: dieter at handshake.de (dieter) Date: Thu, 19 Nov 2015 08:27:52 +0100 Subject: Could you explain why the following generates 4 same elements list? References: <3f1eecc8-e23d-4f86-abf8-38044939d085@googlegroups.com> Message-ID: <87a8qala87.fsf@handshake.de> fl writes: > Hi, > > I cannot reason out why the code: > //////// > def mpl(): > return [lambda x : i * x for i in range(4)] > > print [m(2) for m in mpl()] > ///////// > > has result: > > [6, 6, 6, 6] The "i" in your lambda definition is a variable reference which is not dereferenced (i.e. name replaced by the value) at definition but only at call time. Thus, all your "lambda"s are in fact equal; they all look up the current value of "i" when they are called (which happens to be "3"). To avoid this, you must force the dereferencing at definition time. This could look like: return [lambda x, i=i: i * x for i in range(4)] From dieter at handshake.de Thu Nov 19 02:31:04 2015 From: dieter at handshake.de (dieter) Date: Thu, 19 Nov 2015 08:31:04 +0100 Subject: Question about 'print' in a loop References: <75f51ee1-907c-47c4-9be9-58241ff83115@googlegroups.com> Message-ID: <87610yla2v.fsf@handshake.de> fl writes: > Hi, > > From previous post, I get many helpful replies. Now I have a new question > when I run this example code: > > > --------- > sq=[] > for xx in range(5): > print 'here' > sq.append(lambda:xx**2) > ... > sq[2]() > Out[151]: 16 > > sq[3]() > Out[152]: 16 > ///// Same reason as in your previous thread: variables in (the body of) function definitions (and "lambda"s, which are functions definitions, too) are resolved/dereferenced at call time, not at function definition time. From framstag at rus.uni-stuttgart.de Thu Nov 19 02:50:21 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 19 Nov 2015 07:50:21 +0000 (UTC) Subject: pyinstaller and Python 3.5 on Windows? References: Message-ID: Christian Gollwitzer wrote: > Am 18.11.15 um 23:46 schrieb Ulli Horlacher: > > To run my Python programs on other Windows systems without a Python > > installation I must create standalone Windows executables. > > > > pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but > > with Python 3.5 I get: > > [stack trace] > > Are you using the newest version? Yes. Yesterday installed. > According to http://www.pyinstaller.org/ they claim support for Python3. Therefore my try :-) > Does a hello world script work? No. My test-program I tried to compile was: #!/usr/bin/python from tkinter import Tk,filedialog askopenfilename = filedialog.askopenfilename Tk().withdraw() file = filedialog.askopenfilename() print('File selected: "%s"\n' % file) It runs directly, but I cannot compile it with pyinstaller. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From framstag at rus.uni-stuttgart.de Thu Nov 19 02:54:28 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 19 Nov 2015 07:54:28 +0000 (UTC) Subject: handling of non-ASCII filenames? References: Message-ID: Christian Gollwitzer wrote: > Am 18.11.15 um 17:45 schrieb Ulli Horlacher: > > This is my encoding function: > > > > def url_encode(s): > > u = '' > > for c in list(s): > > if match(r'[_=:,;<>()+.\w\-]',c): > > u += c > > else: > > u += '%' + c.encode("hex").upper() > > return u > > > > > > The quoting is applied to a UTF8 string. encode("hex") works only with binary strings? How do I convert a UTF8 string to binary? > But I think you shouldn't do it yourself, use a library function: > > import urllib > urllib.quote(yourstring.encode('utf8')) It does not encode exactly the same way I need it. Besides this, I want to understand how Python handles strings and character encoding. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From auriocus at gmx.de Thu Nov 19 03:16:15 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 19 Nov 2015 09:16:15 +0100 Subject: handling of non-ASCII filenames? In-Reply-To: References: Message-ID: Am 19.11.15 um 08:54 schrieb Ulli Horlacher: > Christian Gollwitzer wrote: >> Am 18.11.15 um 17:45 schrieb Ulli Horlacher: >>> This is my encoding function: >>> >>> def url_encode(s): >>> u = '' >>> for c in list(s): >>> if match(r'[_=:,;<>()+.\w\-]',c): >>> u += c >>> else: >>> u += '%' + c.encode("hex").upper() >>> return u >>> >>> >> >> The quoting is applied to a UTF8 string. > > encode("hex") works only with binary strings? > How do I convert a UTF8 string to binary? It's right in the other line I showed you: Apfelkiste:Tests chris$ python Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> u"blabl?a".encode('utf8') 'blabl\xc3\xbca' >>> Christian From c.buhtz at posteo.jp Thu Nov 19 03:17:35 2015 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Thu, 19 Nov 2015 09:17:35 +0100 Subject: PubMed / Entrez Message-ID: <3p1Ylk6Wjgz5vMw@dovecot03.posteo.de> I am looking for a way to use the PubMed (medical research search engine) API (aka Entrez) with Python3. Does anyone know packages for that? -- GnuPGP-Key ID 0751A8EC From motoom at xs4all.nl Thu Nov 19 04:00:47 2015 From: motoom at xs4all.nl (Michiel Overtoom) Date: Thu, 19 Nov 2015 10:00:47 +0100 Subject: how do I learn python ? In-Reply-To: References: Message-ID: > On 18 Nov 2015, at 05:58, ??? wrote: > (nothing) You might want to start at https://www.python.org/about/gettingstarted/ PS. Leaving the body of an email or usenet article empty is considered bad form. Greetings, From uganesh at qmschool.org.uk Thu Nov 19 04:28:24 2015 From: uganesh at qmschool.org.uk (Uma Ganesh) Date: Thu, 19 Nov 2015 09:28:24 +0000 Subject: Fwd: The results of your email commands In-Reply-To: <564D944A.1070102@timgolden.me.uk> References: <564D944A.1070102@timgolden.me.uk> Message-ID: > We are trying to use this for students GCSE & A'Level work and seem to ? be having this problem a lot. > What is the cause and the solution to this. > > > I need some help, everytime I install Python 3.3 on to a computer ? overnight it changes to Python X. Therefore most of the files and ? folders disappear please can you tell me why that is. > > ****************All jobs MUST be reported to the helpdesk.****************** > https://docs.google.com/a/qmschool.org.uk/forms/d/1fIRU9Xm-s36pAWtACiYanPyvYXvDb1sTSQl8LslVLDk/viewform > > Thank You > Uma Ganesh > Queensmead School > Queens Walk > South Ruislip > Middlesex > HA4 0LS > > On 19 November 2015 at 09:02, > wrote: > > The results of your email command are provided below. Attached is your > original message. > > - Results: > Ignoring non-text/plain MIME parts > Invalid confirmation string. Note that confirmation strings expire > approximately 3 days after the initial request. They also expire if > the request has already been handled in some way. If your > confirmation has > expired, please try to re-submit your original request or message. > > - Unprocessed: > Re: Your confirmation is required to join the Python-list > mailing list > confirm fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 > ****************All jobs MUST be reported to the > helpdesk.****************** > > https://docs.google.com/a/qmschool.org.uk/forms/d/1fIRU9Xm-s36pAWtACiYanPyvYXvDb1sTSQl8LslVLDk/viewform > Thank You > Uma Ganesh > Queensmead School > Queens Walk > South Ruislip > Middlesex > HA4 0LS > On 19 November 2015 at 09:01, < > > python-list-confirm+fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 at python.org > > > wrote: > > Mailing list subscription confirmation notice for mailing list > > Python-list > > > > We have received a request from 5.150.102.153 for subscription > of your > > email address, "uganesh at qmschool.org.uk > ", to the > > python-list at python.org mailing > list. To confirm that you want to be > > added to this mailing list, simply reply to this message, > keeping the > > Subject: header intact. Or visit this web page: > > - Ignored: > > > > > > > https://mail.python.org/mailman/confirm/python-list/fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 > > > > > > Or include the following line -- and only the following line > -- in a > > message to python-list-request at python.org > : > > > > confirm fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 > > > > Note that simply sending a `reply' to this message should work > from > > most mail readers, since that usually leaves the Subject: line > in the > > right form (additional "Re:" text in the Subject: is okay). > > > > If you do not wish to be subscribed to this list, please simply > > disregard this message. If you think you are being maliciously > > subscribed to the list, or have any other questions, send them to > > python-list-owner at python.org > . > > > > - Done. > > > > ---------- Forwarded message ---------- > From: Uma Ganesh > > To: python-list-confirm+fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 at python.org > > Cc: > Date: Thu, 19 Nov 2015 09:02:49 +0000 > Subject: Re: Your confirmation is required to join the Python-list > mailing list > > confirm fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 > > ****************All jobs MUST be reported to the > helpdesk.****************** > https://docs.google.com/a/qmschool.org.uk/forms/d/1fIRU9Xm-s36pAWtACiYanPyvYXvDb1sTSQl8LslVLDk/viewform > > Thank You > Uma Ganesh > Queensmead School > Queens Walk > South Ruislip > Middlesex > HA4 0LS > > On 19 November 2015 at 09:01, > < python-list-confirm+fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 at python.org > > > wrote: > > Mailing list subscription confirmation notice for mailing list > Python-list > > We have received a request from 5.150.102.153 for subscription > of your > email address, "uganesh at qmschool.org.uk > ", to the > python-list at python.org mailing > list. To confirm that you want to be > added to this mailing list, simply reply to this message, > keeping the > Subject: header intact. Or visit this web page: > > > https://mail.python.org/mailman/confirm/python-list/fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 > > > Or include the following line -- and only the following line -- in a > message to python-list-request at python.org > : > > confirm fe8b5eed3ddb48be4d09fb7c09630f21df6c9143 > > Note that simply sending a `reply' to this message should work from > most mail readers, since that usually leaves the Subject: line > in the > right form (additional "Re:" text in the Subject: is okay). > > If you do not wish to be subscribed to this list, please simply > disregard this message. If you think you are being maliciously > subscribed to the list, or have any other questions, send them to > python-list-owner at python.org . > > > > From rxjwg98 at gmail.com Thu Nov 19 06:28:53 2015 From: rxjwg98 at gmail.com (fl) Date: Thu, 19 Nov 2015 03:28:53 -0800 (PST) Subject: Is there an meaning of '[[]]' in a list? Message-ID: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> Hi, In the previous exercises, I see list: cc=[[],[],[]] Then, I can have this: ccc=[[[]],[[]],[[]]] I can also have ccc[0] Out[158]: [[]] ccc[0]='o' ccc Out[163]: ['o', [[]], [[]]] I have question: Is there any difference between [[]] and []? [[]] can have deeper assignment and use than ccc[0]='o' Thanks, From gandalf at shopzeus.com Thu Nov 19 06:36:46 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 19 Nov 2015 12:36:46 +0100 Subject: Is there an meaning of '[[]]' in a list? In-Reply-To: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> References: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> Message-ID: <564DB44E.8020503@shopzeus.com> > I have question: Is there any difference between [[]] and []? Yes. [] - a list with zero elements. That is an empty list. [[]] - A list with one element. (That element is an empty list.) > [[]] can have deeper assignment and use than You can have it as deep as you want, if you have enough memory. From steve at pearwood.info Thu Nov 19 06:38:12 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 19 Nov 2015 22:38:12 +1100 Subject: What is a function parameter =[] for? References: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> Message-ID: <564db4a5$0$1604$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Nov 2015 11:34 am, fl wrote: > This is my new > question: What does 'del' do? It does not look like a thorough list > deletion from the effect. Of course not. Did you Read The Fine Manual? Or at least use the interactive help function? At the Python prompt, enter: help("del") and you will see an explanation which includes this: Deletion of a name removes the binding of that name from the local or global namespace, depending on whether the name occurs in a ``global`` statement in the same code block. If the name is unbound, a ``NameError`` exception will be raised. Let us try it with the interactive interpreter: If the name "x" doesn't exist, and you try to delete it, you get an error: py> del x Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined If "x" does exist, and you delete it, the name no longer exists: py> x = 42 py> print(x) 42 py> del x py> print(x) Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined So "del" deletes **names**. What happens after the name is deleted? Then the garbage collector may run, and destroy the object that was bound to the name, reclaiming the memory used. But **only** if the object is safe to destroy, otherwise that would lead to segmentation faults and memory corruption. Here we have ONE object with TWO names: py> a = [1, 2, 3, 4] py> b = a py> b.append(999) py> print(a) [1, 2, 3, 4, 999] If we delete one of those names, the other name keeps the list alive: py> del a py> print(b) [1, 2, 3, 4, 999] -- Steven From __peter__ at web.de Thu Nov 19 06:40:17 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Nov 2015 12:40:17 +0100 Subject: Is there an meaning of '[[]]' in a list? References: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> Message-ID: fl wrote: > Hi, > In the previous exercises, I see list: > cc=[[],[],[]] > > Then, I can have this: > > ccc=[[[]],[[]],[[]]] > > I can also have > > ccc[0] > Out[158]: [[]] > > ccc[0]='o' > > ccc > Out[163]: ['o', [[]], [[]]] > > > I have question: Is there any difference between [[]] and []? > [[]] can have deeper assignment and use than > > ccc[0]='o' I'm sure with a little effort and a few experiments on the commandline you can answer your question yourself. Please limit your posts to c.l.py to those questions that are a little harder. Hint: when you experiment with nested lists use numbers, not strings as list entries that are not lists themselves. Strings can confuse you about the nesting level: >>> items = ["foo"] >>> items[0] 'foo' >>> items[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] 'f' From bc at freeuk.com Thu Nov 19 06:41:43 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 11:41:43 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On 19/11/2015 01:59, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 12:41 PM, BartC wrote: >> On 18/11/2015 23:22, Chris Angelico wrote: >>> On the contrary, it is certain always to be that exact object. >> >> But, not the same value that appears as the default? > > Nope. Mutable objects are never guaranteed to retain the same values. > That's kinda the point. But, presumably you would expect: a = [] to always assign an empty list to a? You don't expect this: a = [] a.append(10) b = [] that b now has the same value of a, namely [10]. Fortunately this isn't the case. >> Sorry, I didn't understand any of that. > If you want to think of function defaults as being values, then yes. > But they're not. They're objects. That's not much help to someone who *does* want the default to supply the same missing value that they don't want to bother remembering and/or writing in the call. Surely the language is trying to help people not hinder. How many times after all is this behaviour actually wanted? It's the equivalent of: fndefault=[] def fn(a=fndefault): a.append(10) return a where it is known that a and fndefault share the same mutable data. (Although I bet some people are still surprised by that!) >> I suspect those same people (unless they are experts in the murky corners of >> the language) would expect: .... >> and not be dependent on fn's entire call history. > > Tell me, do you expect these to do the same thing? > > x = [] > fn(x) > fn(x) > fn(x) > > # or > > fn([]) > fn([]) > fn([]) No I don't. But I expect the version with the default argument to be exactly the same as the last lot of calls, namely for: fn() fn() fn() to be equivalent to: temp=[] fn(temp) temp=[] fn(temp) temp=[] fn(temp) > The distinction is exactly the same. If you can understand that the > first one constructs a single object and uses it three times, then you > should be able to understand that the function default is also > constructed once and used every time. As I said, it's bizarre. It means that for certain types, Python doesn't have a default that works per call, but only a default that works once per program. -- Bartc From kw at codebykevin.com Thu Nov 19 06:41:52 2015 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 19 Nov 2015 06:41:52 -0500 Subject: pyinstaller and Python 3.5 on Windows? In-Reply-To: References: Message-ID: On 11/18/15 5:46 PM, Ulli Horlacher wrote: > > ImportError: DLL load failed: The specified module could not be found. > > > Is there a solution available? > I understand that Python 3.5 has shipped how the MS dll's from Visual Studio are shipped, and perhaps the freezing tools (pyinstaller, py2exe) haven't yet caught up. Consider filing a bug with the pyinstaller developers. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From hayesstw at telkomsa.net Thu Nov 19 06:47:05 2015 From: hayesstw at telkomsa.net (Steve Hayes) Date: Thu, 19 Nov 2015 13:47:05 +0200 Subject: how do I learn python ? References: Message-ID: <6ldr4b9c146bo8tgl9fdbrfqbr2b7apflq@4ax.com> On Wed, 18 Nov 2015 04:58:30 +0000, ?????? wrote: > -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From lac at openend.se Thu Nov 19 06:51:23 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 19 Nov 2015 12:51:23 +0100 Subject: Public key encryption example. In-Reply-To: References: Message-ID: <201511191151.tAJBpN9j018075@fido.openend.se> In a message of Wed, 18 Nov 2015 16:18:28 -0700, Vincent Davis writes: >This might be a "Let me Google that for you question", I tried. >I am looking for the "simplest" example of sending(encrypting) and >receiving(decrypting) using public key encryption. I am think of something >along the lines of having all the keys in local files and saving and >reading the message from a local file. > >Possibly using cryptography library elliptic-curve >https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/#elliptic-curve-signature-algorithms > >Surly there is an example out there? > >Vincent Davis pycrypto does this. https://pypi.python.org/pypi/pycrypto code and diagrams here http://www.laurentluce.com/posts/python-and-cryptography-with-pycrypto/ There really isn't much to it. Laura From rosuav at gmail.com Thu Nov 19 06:58:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Nov 2015 22:58:33 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 10:41 PM, BartC wrote: > As I said, it's bizarre. It means that for certain types, Python doesn't > have a default that works per call, but only a default that works once per > program. No, it's not "for certain types". Regardless of the type, the expression that defines the default is evaluated at *function definition*, not at each *function call*. (That's not the same as "once per program", although for 99% of situations, it'll be indistinguishable.) ChrisA From gengyangcai at gmail.com Thu Nov 19 06:59:53 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Thu, 19 Nov 2015 03:59:53 -0800 (PST) Subject: Writing a Financial Services App in Python Message-ID: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> >From YCombinator's new RFS, This is the problem I want to solve as it is a severe problem I face myself and something I need. I want to write this app in Python as I heard that Python is a great language that many programmers use ... How / where do I start ? The problem is detailed below : FINANCIAL SERVICES Saving money is hard and Americans are particularly bad at it. Because the personal savings rate has largely been falling since the early 80s, we don't have sufficient cushions to face economic shocks, weather unexpected unemployment, or even enjoy our retirements. Its simply too hard to find good ways to save or to invest. Savings accounts only pay a fraction of what's needed to keep up with inflation. Picking individual stocks and bonds exposes investors to huge volatility and does nothing to guarantee a return. While investors can dampen their volatility through various exchanges or closed ended funds, the reality is that few have the expertise needed to properly mix those funds, rebalance them, and optimize them for taxes to capture the best possible return (no matter how you define that) given each dollar of invested capital. Even if investors were able to pick optimal investment strategies, they'd find that that fees are a huge drag on performance. This seems to us like something software should help solve. We'd like to see teams tackling each of the component issues around saving and investing, along with ones tackling the entire package. Thanks alot ! Cai Gengyang From lac at openend.se Thu Nov 19 07:09:29 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 19 Nov 2015 13:09:29 +0100 Subject: PubMed / Entrez In-Reply-To: <3p1Ylk6Wjgz5vMw@dovecot03.posteo.de> References: <3p1Ylk6Wjgz5vMw@dovecot03.posteo.de> Message-ID: <201511191209.tAJC9TvR019795@fido.openend.se> In a message of Thu, 19 Nov 2015 09:17:35 +0100, c.buhtz at posteo.jp writes: >I am looking for a way to use the PubMed (medical research search >engine) API (aka Entrez) with Python3. > >Does anyone know packages for that? https://pypi.python.org/pypi/Bio_Eutils/1.63 Or just get BioPython and use the Entrez from that. Laura From steve at pearwood.info Thu Nov 19 07:19:53 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 19 Nov 2015 23:19:53 +1100 Subject: What is a function parameter =[] for? References: Message-ID: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Nov 2015 10:14 am, BartC wrote: > On 18/11/2015 22:11, Ian Kelly wrote: >> The list0 parameter has a default value, which is [], an initially >> empty list. The default value is evaluated when the function is >> defined, not when it is called, so the same list object is used each >> time and changes to the list are consequently retained between calls. > > That is really bizarre behaviour. It is standard early binding behaviour, applied to function defaults. Early versus late binding crops up in many places when programming: https://support.microsoft.com/en-us/kb/245115 http://javascript.info/tutorial/binding https://msdn.microsoft.com/en-us/library/0tcf61s1.aspx Unfortunately, like many evocative or useful terms in computing, it the term isn't used consistently. There are at least two related, but distinct, uses for "early/late binding", and Wikipedia only talks about the *other* one: https://en.wikipedia.org/wiki/Late_binding In Python terms, *all* (or nearly all?) name binding (assignment) is equivalent to C++ late binding, a.k.a. "dynamic dispatch". But Python also uses early/late binding to refer to when the default object is assigned. Consider this pair of functions: def expensive(): # Simulate some expensive calculation or procedure. time.sleep(100) return random.randint(1, 6) def demo(arg=expensive()): return arg + 1 Now we call the second function four times, without an argument so that the default value is used: demo() demo() demo() demo() What results do you expect? There are two standard behaviours: Early binding means that the default value is generated *once*, when the function `demo` is created. That's expensive, but it only gets used once, and the default value is now fixed, and can be retrieved almost instantly in subsequent calls. That's what Python uses. Late binding means that the default value is generated every time you call the function. That's expensive, and confusing. Why is the function parameter list being re-evaluated each time the function is called? Why is the default value different each time I call the function? Now *that's* bizarre. Compared to the weirdness of late binding, Python's early binding makes much more sense. Another advantage of early binding is that it involves a consistent execution model: only the function body is executed when you call the function, not the function declaration and parameter list. def demo(arg=expensive()): # declaration, including the parameter list # function body is indented Now it is easy to tell which part gets executed when: just look at the indentation. Both early and late binding are useful, so which should a language default to? (Assuming it doesn't offer both.) I think that there is absolutely no doubt that function defaults should use early binding. The overwhelming advantage of early binding is this: - if the language defaults to early binding, it is *easy* for the programmer to get late binding semantics; - if the language defaults to late binding, it is *very difficult* for the programmer to get early binding semantics. Given early binding, like Python has, it is easy to get late binding semantics. All you have to do is use a sentinel value, and move the code you want to execute every time the function is called into the body of the function. The most common sentinel is None: def demo(arg=None): if arg is None: arg = expensive() ... Now it is obvious that expensive() will be called each time you call demo() (with no argument provided), since the call to expensive is inside the function body. But let's try going the other way. Suppose function defaults were evaluated each and every time you called the function. How could you *avoid* the expense and waste of re-evaluating the default over and over again? You can't, or at least, not cleanly and easily. The most obvious way is to use a global variable: ARG = expensive() def demo(arg=ARG): ... This is ... horrible. You are still evaluating the default each time, but at least it is only a global variable lookup, not an expensive function call. But the cost is great. Now you have to pollute the module with a global variable for every function that has a default value. This breaks encapsulation -- the default value for the function is no longer visible in the function's declaration, you have to hunt for it through your module. And what if somebody changes the global, or deletes it? > So, looking at some source code, a default value for certain types is > only certain to be that value for the very first call of that function? When you deal with mutable objects, you have to expect them to mutate. The whole point of mutability is that their value can change. If you use a mutable default object, it is still mutable, and can change its value. If you don't want that, then use an immutable object. > > The default value is evaluated when the function is > > defined, not when it is called > > Given the amount of pointless dynamic stuff that goes on in Python, I'm > surprised they've overlooked this one! > > It seems simple enough to me to check for a missing parameter, and to > assign whatever default value was designated ([] in this case). (How > does the default mechanism work now?) What "seems" simple is not simple. The function default is not guaranteed to be a simple literal. Defaults are arbitrarily complex expressions: def func(a, b=[1, x] + [random.random() for i in range(x**4)]): ... So you have to store that expression: [1, x] + [random.random() for i in range(x**4)] together with enough information to know which scope it will be evaluated in. And you have to decide: should that be a closure, or a regular function call? Whichever decision you make, you will make some people unhappy. There are consequences of your choice: - Assuming that "x" is a global variable, then making the expression a closure will mean that the value of x is kept alive, possibly long after the default value is no longer needed. - But if you make the expression a non-closure, then the caller is responsible for ensuring that x is not deleted. If it is deleted, then you will get a NameError trying to evaluate the default value. Whichever option you choose, there will be a multitude of people on the internet telling you that you got it wrong. -- Steven From framstag at rus.uni-stuttgart.de Thu Nov 19 07:25:39 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 19 Nov 2015 12:25:39 +0000 (UTC) Subject: pyinstaller and Python 3.5 on Windows? References: Message-ID: Kevin Walzer wrote: > I understand that Python 3.5 has shipped how the MS dll's from Visual > Studio are shipped, and perhaps the freezing tools (pyinstaller, py2exe) > haven't yet caught up. Consider filing a bug with the pyinstaller > developers. http://pythonhosted.org/PyInstaller/#windows Installing in Windows For Windows, PyWin32 or the more recent pypiwin32, is a prerequisite. The latter is installed automatically when you install PyInstaller using pip or easy_install. If necessary, follow the pypiwin32 link to install it manually. I have installed PyInstaller using "pip install pyinstaller". Ok, then: C:\Users\admin>pip install pywin32 Collecting pywin32 Could not find a version that satisfies the requirement pywin32 (from versions: ) Some externally hosted files were ignored as access to them may be unreliable (use --allow-external pywin32 to allow). No matching distribution found for pywin32 C:\Users\admin>pip install pypiwin32 Collecting pypiwin32 Downloading pypiwin32-219-cp35-none-win32.whl (7.9MB) 100% |################################| 7.9MB 61kB/s Installing collected packages: pypiwin32 Exception: Traceback (most recent call last): File "c:\program files (x86)\python 3.5\lib\site-packages\pip\basecommand.py", line 211, in main status = self.run(options, args) File "c:\program files (x86)\python 3.5\lib\site-packages\pip\commands\install .py", line 311, in run root=options.root_path, File "c:\program files (x86)\python 3.5\lib\site-packages\pip\req\req_set.py", line 646, in install **kwargs File "c:\program files (x86)\python 3.5\lib\site-packages\pip\req\req_install. py", line 803, in install self.move_wheel_files(self.source_dir, root=root) File "c:\program files (x86)\python 3.5\lib\site-packages\pip\req\req_install. py", line 998, in move_wheel_files isolated=self.isolated, File "c:\program files (x86)\python 3.5\lib\site-packages\pip\wheel.py", line 339, in move_wheel_files clobber(source, lib_dir, True) File "c:\program files (x86)\python 3.5\lib\site-packages\pip\wheel.py", line 317, in clobber shutil.copyfile(srcfile, destfile) File "c:\program files (x86)\python 3.5\lib\shutil.py", line 115, in copyfile with open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied: 'c:\\program files (x86)\\python 3.5\\Lib\\site-packages\\PyWin32.chm' Why "Permission denied"? I am logged in as administrator! Stupid Windows... Then https://pypi.python.org/pypi/pypiwin32/219 : pypiwin32-219-cp35-none-win32.whl Python Wheel cp35 2015-01-09 7MB "Python Wheel"?! http://python-packaging-user-guide.readthedocs.org/en/latest/installing/#install-pip-setuptools-and-wheel C:\Users\admin>pip install wheel Collecting wheel Downloading wheel-0.26.0-py2.py3-none-any.whl (63kB) 100% |################################| 65kB 1.3MB/s Installing collected packages: wheel Failed to write executable - trying to use .deleteme logic Exception: Traceback (most recent call last): File "c:\program files (x86)\python 3.5\lib\site-packages\pip\_vendor\distlib\ scripts.py", line 209, in _write_script self._fileop.write_binary_file(outname, script_bytes) File "c:\program files (x86)\python 3.5\lib\site-packages\pip\_vendor\distlib\ util.py", line 388, in write_binary_file with open(path, 'wb') as f: PermissionError: [Errno 13] Permission denied: 'c:\\program files (x86)\\python 3.5\\Scripts\\wheel.exe' Looks like I have a broken Windows :-( -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From steve at pearwood.info Thu Nov 19 07:45:41 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 19 Nov 2015 23:45:41 +1100 Subject: What is a function parameter =[] for? References: Message-ID: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Nov 2015 10:41 pm, BartC wrote: > I expect the version with the default argument to be > exactly the same as the last lot of calls, namely for: > > fn() > fn() > fn() > > to be equivalent to: > > temp=[] > fn(temp) > temp=[] > fn(temp) > temp=[] > fn(temp) Why on earth would you expect that? I don't mean that it isn't sometimes useful. Of course it is sometimes useful, there's no doubt about that. But why would you expect the language to default to the *slow*, *expensive*, *complicated* behaviour instead of the *fast*, *cheap*, *simple* behaviour? You already have one way to set the argument to a fresh list every time you call the function: put the code you want executed inside the body of the function. There's no need for a *second* way to get the same result. But if you want the default value to be evaluated exactly once, and once only, there is no real alternative to early binding. You could use a global variable, of course, but that is no solution -- that's a problem waiting to happen. To get late binding, the interpreter needs to record the default expression *and its scope* in some sort of executable code. The traditional name for that is stolen from Algol, "thunk". And you need to decide whether it will behave like a closure or not. It needs to work sensibly with code like this: i = j = k = -1 def demo(): array = [] for i in range(5): def factory(): j = i def f(x=i + i**2, y=3*j+1, z=k**2 - k): return ((x, y, z), (i, j, k)) return f array.append(factory()) return array func = demo()[1] i = j = k = 9999 print(func()) >> The distinction is exactly the same. If you can understand that the >> first one constructs a single object and uses it three times, then you >> should be able to understand that the function default is also >> constructed once and used every time. > > As I said, it's bizarre. It means that for certain types, Python doesn't > have a default that works per call, but only a default that works once > per program. Nonsense. The semantics of default values is *completely* independent of the type. Python ALWAYS uses early binding, regardless of the type. Whether the default is an int, None, a list, a dict, a float, or some other instance, the behaviour is the same: the default value is the specific instance which the default expression evaluates to when the function is created. -- Steven From bc at freeuk.com Thu Nov 19 08:19:25 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 13:19:25 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 12:19, Steven D'Aprano wrote: > On Thu, 19 Nov 2015 10:14 am, BartC wrote: > Consider this pair of functions: > > > def expensive(): > # Simulate some expensive calculation or procedure. > time.sleep(100) > return random.randint(1, 6) > > > def demo(arg=expensive()): > return arg + 1 > > > Now we call the second function four times, without an argument so that the > default value is used: > > demo() > demo() > demo() > demo() > > What results do you expect? If someone /wants/ expensive() to be called each time, then why not? If they don't, then it seems easy enough to write: demo_default=expensive() def demo(arg=demo_default): ... (As you mention later...) > - if the language defaults to early binding, it is *easy* for the > programmer to get late binding semantics; > > - if the language defaults to late binding, it is *very difficult* > for the programmer to get early binding semantics. I got the impression that Python was a nice, easy language for everyone to use. Not one where you need a Master's degree in CS to understand the nuances of! And to understand why something that is so blindingly obvious doesn't work. > But let's try going the other way. Suppose function defaults were evaluated > each and every time you called the function. How could you *avoid* the > expense and waste of re-evaluating the default over and over again? I use default parameters a lot in other languages. 99% of the time the default value is a constant. And most often that constant is 0, "" or an empty list. You want these very common examples to /just work/ instead of going to lengths trying to explain why they don't. > You can't, or at least, not cleanly and easily. The most obvious way is to > use a global variable: > > ARG = expensive() > > def demo(arg=ARG): > ... > > This is ... horrible. You are still evaluating the default each time, I implement an interpreted language where these calls: demo() demo(ARG) would have exactly the same cost. I understand that Python is very different: at the call-site, the compiler has no idea of the number of arguments a function defines or what the default values might be, or even if it is a function that is being called. But even under those circumstances, I would endeavour to make such a function call as fast as is practical. (That could involve a runtime check on number of parameters, substituting the equivalent of None for missing ones, or whatever default expression has been declared. But here, I am benefiting from my language not being Python which does seem to like making things difficult.) > but at > least it is only a global variable lookup, Maybe you can wrap the entire module inside a function? Other than a bit at the end that calls that function. Does that solve the global lookup problem? > When you deal with mutable objects, you have to expect them to mutate. The > whole point of mutability is that their value can change. That [] doesn't look like an object that could change. It looks like an empty list constructor. You would expect a constructor for an empty list to yield an empty list throughout a program! (As it does, in most other contexts.) You presumably think differently because you have some inside knowledge of how Python works, and know that that [] undergoes a one-time assignment to a local, persistent 'default' variable where it's value can indeed by changed. (Thanks to another Python feature where an assignment is a very shallow copy of an object.) And it is that volatile variable that is the actual default. But not everyone is going to know that. -- Bartc From framstag at rus.uni-stuttgart.de Thu Nov 19 08:32:24 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 19 Nov 2015 13:32:24 +0000 (UTC) Subject: pyinstaller and Python 3.5 on Windows? References: Message-ID: Ulli Horlacher wrote: > C:\Users\admin>pip install pypiwin32 > Collecting pypiwin32 > Downloading pypiwin32-219-cp35-none-win32.whl (7.9MB) > 100% |################################| 7.9MB 61kB/s > Installing collected packages: pypiwin32 > Exception: (...) > PermissionError: [Errno 13] Permission denied: 'c:\\program files (x86)\\python > 3.5\\Lib\\site-packages\\PyWin32.chm' > > > Why "Permission denied"? I am logged in as administrator! Stupid Windows... I found, I have to deactivate Windows UAC with C:\Windows\System32\UserAccountControlSettings.exe Then I was able to run pip install pypiwin32 pip install pyinstaller without errors. BUT pyinstaller does not work: S:\python>pyinstaller.exe --onefile tk.py failed to create process. S:\python>pyinstaller --version failed to create process. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From rosuav at gmail.com Thu Nov 19 08:45:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 00:45:19 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 12:19 AM, BartC wrote: > You presumably think differently because you have some inside knowledge of > how Python works, and know that that [] undergoes a one-time assignment to a > local, persistent 'default' variable where it's value can indeed by changed. > (Thanks to another Python feature where an assignment is a very shallow copy > of an object.) And it is that volatile variable that is the actual default. > > But not everyone is going to know that. Correct: We think certain things because we understand how Python behaves. You, too, can join the Inner Circle of Pythonistas; all you have to do is read this (and/or watch the video): http://nedbatchelder.com/text/names1.html ChrisA From mal at europython.eu Thu Nov 19 09:31:17 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 19 Nov 2015 15:31:17 +0100 Subject: EuroPython 2016: Kick-off Message-ID: <564DDD35.7020106@europython.eu> The EuroPython 2016 Team is ready for starting the organization of next year?s event: *** http://ep2016.europython.eu/ *** July 17 - 24 2016 If you would like to actively help with the organization, we?d love to have you as volunteer in one of our workgroups. Please see the EuroPython Workgroups page for how to sign up. On-site Team WG ---------------- One of the workgroups, the on-site team workgroup, is especially important, since they provide the services and management on-site in Bilbao, as well as in the case of EuroPython 2016, also take on a major role in the financial and legal infrastructure of the conference organization. This team is your contact in case you have questions related to on-site setups. * Oier Echaniz Beneitez (Chair) * Borja Ayerdi Vilches * Darya Chyzhyk * Ion Marqu?s * Jos? David Nu?ez * Alexandre Savio * Luis Javier Salvatierra Conference Administration WG ---------------------------- Manages and organizes the administration side of the conference, in particular: contracts, venue contact, ticket support, satellite conferences, legal support, insurance, licensing. * Marc-Andre Lemburg (Chair) * Borja Ayerdi Vilches * Vicky Twomey-Lee * St?phane Wirtel Finance WG ---------- Manages and organizes the finances and budget of the conference, in particular: budget, controlling, accounting, billing, invoicing, taxes, payment system administration. * Borja Ayerdi Vilches (Chair) * Darya Chyzhyk * Marc-Andre Lemburg * Anthon van der Neut (EPS Treasurer) * St?phane Wirtel Sponsors WG ----------- Manages and organizes the sponsor activities of the conference, in particular: sponsor contacts, sponsor logistics, room/booth assignment, recruiting session, jobs fair, exhibit hall, startup row. * Fabio Pilger (Chair) * Borja Ayerdi Vilches * Darya Chyzhyk * Ra?l Cumplido * Marc-Andre Lemburg * Alexandre Savio * Vicky Twomey-Lee Communications WG ----------------- Manages and organizes the public communication and community relations of the conference, in particular: press, community relations, diversity/outreach/CoC, CoC contact, announcements, social media, attendee tools, volunteer coordination, mailing lists, Trello and Loomio groups. * Marc-Andre Lemburg (Chair) * Darya Chyzhyk * Ra?l Cumplido * Kerstin Kollmann * Leire Ozaeta * Vicky Twomey-Lee * Chris Ward * St?phane Wirtel Support WG ---------- Manages and organizes the attendee/speaker support of the conference, in particular: helpdesk, attendee support contact, visa help, travel management. * Christian Barra * Aisha Bello * Darya Chyzhyk * Anthon van der Neut * Alexandre Savio * St?phane Wirtel Financial Aid WG ---------------- Manages and organizes the financial aid program of the conference, in particular: setup, grant selection, aid organisation. * Darya Chyzhyk * Vicky Twomey-Lee * St?phane Wirtel Marketing/Design WG ------------------- Create and manage marketing and design aspects of the conference, in particular: brochures, advertisements, banners, flyers, travel guide, t-shirts, lanyards, badges, panels, logo. * Darya Chyzhyk * Marc-Andre Lemburg * Alexandre Savio * St?phane Wirtel Program WG ---------- Manages and organizes the conference program of the conference, in particular: talk selection/voting, scheduling, session chairs, sprint/openspace/keynote/lightning talks/poster session organization. * Alexandre Savio (Chair) * Alexander Hendorf (Co-chair) * Christian Barra * Ra?l Cumplido * Moshe Goldstein * Vicky Twomey-Lee * Chris Ward Web WG ------ Manages and organizes the web site, in particular: web site support, helpdesk ticket system, administration, backups, payment system integration, hosting. * Christian Barra (Chair) * Oier Beneitez * Ra?l Cumplido * Cesar Desales * Patrick Guido * Marc-Andre Lemburg * Fabio Pliger * Alexandre Savio * St?phane Wirtel Media WG -------- Manage and organize the talk and session recordings of the conference, in particular: video recording, live streaming, uploads to YouTube and archive.org. * Anthon van der Neut (Chair) * Luis Javier Salvatierra Code of Conduct WG ------------------ Manage and organize the code of conduct (CoC) workflows, create CoC documents, provide CoC contacts and handle CoC requests. * Darya Chyzhyk * Marc-Andre Lemburg * Anthon van der Neut * Leire Ozaeta On-Site Volunteers ------------------ In addition to several of the EuroPython Workgroup members, we will need quite a few attendees helping us as session manager, room manager, at the registration desk, bag stuffing and during set up and tear down of the conference. We will run a separate announcement for on-site volunteers closer to the event. Enjoy, -- EuroPython Society http://www.europython-society.org/ From jrmy.lnrd at gmail.com Thu Nov 19 10:02:27 2015 From: jrmy.lnrd at gmail.com (Jeremy Leonard) Date: Thu, 19 Nov 2015 07:02:27 -0800 (PST) Subject: Writing a Financial Services App in Python In-Reply-To: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> References: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> Message-ID: <529622b6-3649-419d-a303-03e48d90c294@googlegroups.com> On Thursday, November 19, 2015 at 7:00:05 AM UTC-5, Cai Gengyang wrote: > From YCombinator's new RFS, This is the problem I want to solve as it is a severe problem I face myself and something I need. I want to write this app in Python as I heard that Python is a great language that many programmers use ... How / where do I start ? The problem is detailed below : > > FINANCIAL SERVICES > > Saving money is hard and Americans are particularly bad at it. Because the personal savings rate has largely been falling since the early 80s, we don't have sufficient cushions to face economic shocks, weather unexpected unemployment, or even enjoy our retirements. > Its simply too hard to find good ways to save or to invest. Savings accounts only pay a fraction of what's needed to keep up with inflation. Picking individual stocks and bonds exposes investors to huge volatility and does nothing to guarantee a return. > > While investors can dampen their volatility through various exchanges or closed ended funds, the reality is that few have the expertise needed to properly mix those funds, rebalance them, and optimize them for taxes to capture the best possible return (no matter how you define that) given each dollar of invested capital. Even if investors were able to pick optimal investment strategies, they'd find that that fees are a huge drag on performance. > > This seems to us like something software should help solve. We'd like to see teams tackling each of the component issues around saving and investing, along with ones tackling the entire package. > > > Thanks alot ! > > Cai Gengyang What platform do you want the app to target (web/desktop/etc...)? Jeremy From gengyangcai at gmail.com Thu Nov 19 10:24:54 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Thu, 19 Nov 2015 07:24:54 -0800 (PST) Subject: Writing a Financial Services App in Python In-Reply-To: <529622b6-3649-419d-a303-03e48d90c294@googlegroups.com> References: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> <529622b6-3649-419d-a303-03e48d90c294@googlegroups.com> Message-ID: It will be a web-based application. Something like this : https://www.slicedinvesting.com/, but with different, better, more features and also graphics , forums, a system to track your daily, monthly expenses and earnings, a graphical tutorial system to teach users financial literacy , learn and utilise ways to invest and trade their money properly and create computerised trend following systems to trade stocks in the stock market. The truth is, very few individual investors really know how to properly trade stocks , and hedge funds are open to mainly very wealthy clients. Computerised and automated trend following systems can legally create huge profits for investors if a disciplined automated systems are utilised. I for example, am a terrible trader because of having almost zero discipline and thus keep losing money. My plan is to create such an all-in-one platform to help individual users like myself who might not have millions of dollars to invest in professional hedge funds properly invest , trade , keep track of their money and also network with our individual investors. On Thursday, November 19, 2015 at 11:03:50 PM UTC+8, Jeremy Leonard wrote: > On Thursday, November 19, 2015 at 7:00:05 AM UTC-5, Cai Gengyang wrote: > > From YCombinator's new RFS, This is the problem I want to solve as it is a severe problem I face myself and something I need. I want to write this app in Python as I heard that Python is a great language that many programmers use ... How / where do I start ? The problem is detailed below : > > > > FINANCIAL SERVICES > > > > Saving money is hard and Americans are particularly bad at it. Because the personal savings rate has largely been falling since the early 80s, we don't have sufficient cushions to face economic shocks, weather unexpected unemployment, or even enjoy our retirements. > > Its simply too hard to find good ways to save or to invest. Savings accounts only pay a fraction of what's needed to keep up with inflation. Picking individual stocks and bonds exposes investors to huge volatility and does nothing to guarantee a return. > > > > While investors can dampen their volatility through various exchanges or closed ended funds, the reality is that few have the expertise needed to properly mix those funds, rebalance them, and optimize them for taxes to capture the best possible return (no matter how you define that) given each dollar of invested capital. Even if investors were able to pick optimal investment strategies, they'd find that that fees are a huge drag on performance. > > > > This seems to us like something software should help solve. We'd like to see teams tackling each of the component issues around saving and investing, along with ones tackling the entire package. > > > > > > Thanks alot ! > > > > Cai Gengyang > > What platform do you want the app to target (web/desktop/etc...)? > > Jeremy From ian.g.kelly at gmail.com Thu Nov 19 10:42:00 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Nov 2015 08:42:00 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Nov 19, 2015 at 5:45 AM, Steven D'Aprano wrote: > But if you want the default value to be evaluated exactly once, and once > only, there is no real alternative to early binding. You could use a global > variable, of course, but that is no solution -- that's a problem waiting to > happen. It doesn't have to be a global. In a Python with late binding defaults, this would work to get early binding: def f(x=f.default_x): ... f.default_x = something() Of course, assignment to function attributes is a relatively modern thing that is only permitted since Python 2.1, whereas function defaults have been around since at least 1.4, so this wouldn't have been an option when the semantics were being determined. From framstag at rus.uni-stuttgart.de Thu Nov 19 10:48:07 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 19 Nov 2015 15:48:07 +0000 (UTC) Subject: non-blocking getkey? References: Message-ID: Terry Reedy wrote: > On 11/18/2015 11:50 AM, Ulli Horlacher wrote: > > Ulli Horlacher wrote: > > > >> from Tkinter import Tk > >> from tkFileDialog import askopenfilename > >> > >> Tk().withdraw() > >> file = askopenfilename() > > > > I found another glitch: > > > > After termination of askopenfilename() the window focus is not returned to > > the calling window (xterm on Linux, cmd on Windows). I have to click it > > again, to regain the focus and continue typing. Is there a workaround? > > What happens with > > root = Tk() > root.withdraw() > fiel = ... > root.destroy() > > Focus cannot stay with destroyed window. The focus is moved to another, unrelated window, but not back to the window in which the python scripts run. Same behaviour on Linux (XFCE) and windows 7. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From torriem at gmail.com Thu Nov 19 11:00:10 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 19 Nov 2015 09:00:10 -0700 Subject: Writing a Financial Services App in Python In-Reply-To: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> References: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> Message-ID: <564DF20A.6060708@gmail.com> On 11/19/2015 04:59 AM, Cai Gengyang wrote: > > From YCombinator's new RFS, This is the problem I want to solve as it > is a severe problem I face myself and something I need. I want to > write this app in Python as I heard that Python is a great language > that many programmers use ... How / where do I start ? The problem is > detailed below : I'm afraid you're going to be discouraged. Well the first step is you have to learn programming. And you don't start with such a large problem, I assure you. You start by learning the language by following the tutorials, writing small programs to become familiar with programming and the language itself. Then you become familiar with related things like algorithms and data structures, and how to use them with and from Python (or any language). Eventually you add to that graphical user interface development. After that then you might be in a position to start thinking about how to design and build a program that does what you were talking about. There honestly are no shortcuts. Python is a great language, and is easy to learn, but it's not like you can start cranking out full-blown applications magically. In the hands of experienced programmers, yes Python is incredibly fast and flexible for cranking out working apps. You might try checking out a Python application development framework that can produce apps that will run on Android and iOS (and Windows and Linux) called Kivy. I would think mobile should be your target platform for such an app. > > This seems to us like something software should help solve. We'd like > to see teams tackling each of the component issues around saving and > investing, along with ones tackling the entire package. Are you wanting to contract with some programmers to create this application for you? From steve at pearwood.info Thu Nov 19 11:01:27 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Nov 2015 03:01:27 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 12:19 am, BartC wrote: > On 19/11/2015 12:19, Steven D'Aprano wrote: >> On Thu, 19 Nov 2015 10:14 am, BartC wrote: > >> Consider this pair of functions: >> >> >> def expensive(): >> # Simulate some expensive calculation or procedure. >> time.sleep(100) >> return random.randint(1, 6) >> >> >> def demo(arg=expensive()): >> return arg + 1 [...] > If someone /wants/ expensive() to be called each time, then why not? If > they don't, then it seems easy enough to write: > > demo_default=expensive() > def demo(arg=demo_default): > ... > > (As you mention later...) Yes, I mentioned it, and you seem to have failed to understand why that is a horrible solution that causes more problems than it solves. It breaks encapsulation -- data which belongs to the function has to be stored outside the function, in a global variable, where just anybody or anything could come along and modify it or delete it. It pollutes the namespace -- imagine a module with twenty functions, each function having four or five arguments that take default values. That's 80 to 100 global variables, which all need to have unique names. Yuck. >> - if the language defaults to early binding, it is *easy* for the >> programmer to get late binding semantics; >> >> - if the language defaults to late binding, it is *very difficult* >> for the programmer to get early binding semantics. > > I got the impression that Python was a nice, easy language for everyone > to use. Not one where you need a Master's degree in CS to understand the > nuances of! And to understand why something that is so blindingly > obvious doesn't work. Master's degree in CS, ha ha very funny. Not. You know, for somebody who claims to design and implement your own languages, you sometimes go to a remarkable effort to claim to be a dummy. You write your own interpreter, but can't understand early versus late binding? I don't think so. I understand that the simplest things can be perplexing if you look at them the wrong way. But we've explained multiply times now, or at least tried to explain, that the argument default is a single object. That is blindingly obvious once you look at it the right way, and it is a nice, clean design. There's no need to introduce extra modes where code has to be stored away to be evaluated later (apart from the body of the function itself). Everything works the same way: assignment always evaluates a result and binds it to the name, whether that assignment is in a parameter list or not. If you insist on thinking about it in terms of how C or Pascal work, of course you will confuse yourself. The argument default is evaluated when the function is created, and the resulting object is stored away for later use, inside the function. That is clean and easy to understand. I'm not saying that the behaviour with mutable defaults isn't surprising to somebody coming from a completely different paradigm. I was surprised by it too, the first time I got bitten. But surprising doesn't equal *wrong*. The reason it was surprising to me was because I didn't think through the implications of what I already knew. I knew the default value was calculated once. I knew that the list was mutable. But I never put 2 and 2 together to get 4. If you have a list which is created once, and modify it, the second time you use it, it will be modified. Well duh. In hindsight, I shouldn't have been surprised. The fact that I was is *my* failure. It might be surprising the *first* time you see it, because you failed to think it through. If you modify the object, *naturally* it will be modified. Or if you failed to understand that the object was created once and once only. The interesting thing is, I've seen people write code *in the same program* which assumed early binding in one function and late binding in another. *Whichever* choice Python made, their program would have broken in one place or the other. I don't believe that people have an inherent expectation of one or the other. I believe that people expect whichever is more convenient for them at the time, and get disappointed when it doesn't work. >> But let's try going the other way. Suppose function defaults were >> evaluated each and every time you called the function. How could you >> *avoid* the expense and waste of re-evaluating the default over and over >> again? > > I use default parameters a lot in other languages. > > 99% of the time the default value is a constant. Well, if it's a constant, then (apart from efficiency) early binding and late binding makes *absolutely no difference*. Watch: py> def demo_const(x, y=[]): ... return x + len(y) ... py> demo_const(5) 5 py> demo_const(5) 5 Exactly as you should expect. Where you run into trouble is when the default value is NOT a constant: py> def demo_variable(x, y=[]): ... y.append(1) ... return x + len(y) ... py> demo_variable(5) 6 py> demo_variable(5) 7 py> demo_variable(5) 8 If you modify the value, the value will be modified. Why are you surprised by this? > And most often that constant is 0, "" or an empty list. > > You want these very common examples to /just work/ instead of going to > lengths trying to explain why they don't. Ah, the good-old "I shouldn't have to think to understand programming" model of programming. Because that works so well. [...] > Maybe you can wrap the entire module inside a function? Other than a bit > at the end that calls that function. Does that solve the global lookup > problem? No. >> When you deal with mutable objects, you have to expect them to mutate. >> The whole point of mutability is that their value can change. > > That [] doesn't look like an object that could change. Of course it does. It is a list literal, like int literals, float literals, string literals and the rest. The only difference is that lists are mutable and ints and strings are not. > It looks like an > empty list constructor. You would expect a constructor for an empty list > to yield an empty list throughout a program! (As it does, in most other > contexts.) You could write the function like this: def test(arg=list()): ... and it would make no difference. You could write it like this: def test(arg=list() if isprime(104729) else "Surprise!"): ... and you would still get the same result. In fact, you could even write it like this: if isprime(104729): def test(arg=[]): ... else: def test(arg="Surprise!"): ... > You presumably think differently because you have some inside knowledge > of how Python works, and know that that [] undergoes a one-time > assignment to a local, persistent 'default' variable where it's value > can indeed by changed. (Thanks to another Python feature where an > assignment is a very shallow copy of an object.) And it is that volatile > variable that is the actual default. Assignments are not copies at all. -- Steven From torriem at gmail.com Thu Nov 19 11:07:27 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 19 Nov 2015 09:07:27 -0700 Subject: Writing a Financial Services App in Python In-Reply-To: References: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> <529622b6-3649-419d-a303-03e48d90c294@googlegroups.com> Message-ID: <564DF3BF.4050508@gmail.com> On 11/19/2015 08:24 AM, Cai Gengyang wrote: > It will be a web-based application. Contract it out. Or attract people who are interested in making an open source application. What you are thinking of is a massive undertaking. Web-based application design is even more complicated than desktop app design. Web development involves many different languages. Requires a working knowledge of: - Python programming - a web framework for processing events like Django or web2py or something similar - html - css - SQL - Javascript, including jquery and probably others To say nothing of the algorithms necessary to implement the trend analysis you speak of. > I for example, am a terrible trader because of having almost zero > discipline and thus keep losing money. Something tells me if the people you're trying to help have zero discipline, then I don't think software is really going to help them. Computers are just tools. From boblatest at yahoo.com Thu Nov 19 11:13:44 2015 From: boblatest at yahoo.com (Robert Latest) Date: 19 Nov 2015 16:13:44 GMT Subject: Why doesn't this method have access to its "self" argument? Message-ID: Hi all, I'm still trying to find a simple way to implement a method (but not the full class) in C. Suggestions I have recived so far are good, but seem to be over the top for such a (seemingly) simple problem. I came up with the idea of implementing the class in Python, and just setting the method after the actual class definition. See example below. The "py_method" is added to the class later on, and it seems to become a proper method of the class (and its instances) just as if it had been defined inside the class itself. Of course it also has access to its "self" argument. If I do the same thing with a method implemented in the external module "cmethod", and I call that method on an instance, it gets passed a NULL pointer as its "self" argument and so has no access to the instance's "data" attribute. I found a workaround using a wrapper method which calls a C function, passing the instance as a separate argument. It works, and I cannot see any disadvantage. It's just not as elegant as I'd like it to be, and I don't understand WHY the C "method" doesn't receive a pointer to the Python instance. Maybe somebody can clarify. Here's what happens when I build, install and run the minimal example below: rl at dc:~/c/cwsf/python_module$ python test.py py_method(): <__main__.Test instance at 0xb71f5a2c> c_method(): self at (nil) c_function(): self at (nil), instance at 0xb71f5a2c <__main__.Test instance at 0xb71f5a2c> 'Some data' c_function(): self at (nil), instance at 0xb71f5a2c <__main__.Test instance at 0xb71f5a2c> 'New Data' rl at dc:~/c/cwsf/python_module$ Minimal example files: ========================== test.py =================================== import cmethod class Test(): def __init__(self): self.data = "Some data" def wrapper(self): return cmethod.c_function(self) def py_method(self): print "py_method(): %s" % repr(self) # add methods to the class "after the fact" Test.py_method = py_method Test.c_method = cmethod.c_method foo = Test() foo.py_method() # works as expected foo.c_method() # is passed NULL in its self argument, why? foo.wrapper() # works fine, updates "data" attribute foo.wrapper() # works fine, sees updated "data" attribute ==================== cmethod.c ======================================= #include #include static PyObject *c_method(PyObject *self, PyObject *args) { (void) args; /* not used */ fprintf(stderr, "c_method(): self at %p\n", (void*) self); /* always prints 0x0 */ Py_INCREF(Py_None); return Py_None; } static PyObject *c_function(PyObject *self, PyObject *args) { PyObject *instance; PyObject *o; /* Retrieve instance from wrapper through argument tuple: WORKS */ PyArg_UnpackTuple(args, "c_function", 1, 1, &instance); fprintf(stderr, "c_function(): self at %p, instance at %p\n", (void*) self, (void*) instance); PyObject_Print(instance, stderr, 0); fputc('\n', stderr); /* Get and set attributes of instance: WORKS */ o = PyObject_GetAttrString(instance, "data"); PyObject_Print(o, stderr, 0); fputc('\n', stderr); PyObject_SetAttrString(instance, "data", PyString_FromString("New Data")); /* Side question: Do I have to DECREF "o"? */ Py_INCREF(Py_None); return Py_None; } static PyMethodDef methods[] = { {"c_method", c_method, METH_VARARGS, "I want to be a class method"}, {"c_function", c_function, METH_VARARGS, "I am a function"}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initcmethod(void) { (void) Py_InitModule("cmethod", methods); } ======================== setup_cmethod.py =========================== from distutils.core import setup, Extension module1 = Extension('cmethod', sources = ['cmethod.c']) setup (name = 'cmethod', version = '0.1', description = 'struggling to implement a class method in C', ext_modules = [module1]) robert From gengyangcai at gmail.com Thu Nov 19 11:20:06 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Thu, 19 Nov 2015 08:20:06 -0800 (PST) Subject: Writing a Financial Services App in Python In-Reply-To: References: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> Message-ID: Sure ... is this : https://www.codecademy.com/learn/python a good place to learn Python ? Are you wanting to contract with some programmers to create this application for you? ---- Eventually I will have to find programming co-founders and employees to create and iterate the product as user feedback streams in. But I will write the initial prototype myself because I plan to be the main programmer / founder , but yes ... eventually I will need 1 or even 2 co-founders and when the platform gains enough users, we will have to hire programmers and sales/ business people. But this will be a tech-heavy company and all the main founders and employees should be excellent programmers. But for the moment, I plan to write the initial prototype myself ... On Friday, November 20, 2015 at 12:00:34 AM UTC+8, Michael Torrie wrote: > On 11/19/2015 04:59 AM, Cai Gengyang wrote: > > > > From YCombinator's new RFS, This is the problem I want to solve as it > > is a severe problem I face myself and something I need. I want to > > write this app in Python as I heard that Python is a great language > > that many programmers use ... How / where do I start ? The problem is > > detailed below : > > I'm afraid you're going to be discouraged. > > Well the first step is you have to learn programming. And you don't > start with such a large problem, I assure you. You start by learning > the language by following the tutorials, writing small programs to > become familiar with programming and the language itself. Then you > become familiar with related things like algorithms and data structures, > and how to use them with and from Python (or any language). Eventually > you add to that graphical user interface development. > > After that then you might be in a position to start thinking about how > to design and build a program that does what you were talking about. > > There honestly are no shortcuts. Python is a great language, and is > easy to learn, but it's not like you can start cranking out full-blown > applications magically. In the hands of experienced programmers, yes > Python is incredibly fast and flexible for cranking out working apps. > > You might try checking out a Python application development framework > that can produce apps that will run on Android and iOS (and Windows and > Linux) called Kivy. I would think mobile should be your target platform > for such an app. > > > > > > This seems to us like something software should help solve. We'd like > > to see teams tackling each of the component issues around saving and > > investing, along with ones tackling the entire package. > > Are you wanting to contract with some programmers to create this > application for you? From breamoreboy at yahoo.co.uk Thu Nov 19 11:26:01 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 19 Nov 2015 16:26:01 +0000 Subject: Is there an meaning of '[[]]' in a list? In-Reply-To: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> References: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> Message-ID: On 19/11/2015 11:28, fl wrote: > Hi, > In the previous exercises, I see list: > cc=[[],[],[]] > > Then, I can have this: > > ccc=[[[]],[[]],[[]]] > > I can also have > > ccc[0] > Out[158]: [[]] > > ccc[0]='o' > > ccc > Out[163]: ['o', [[]], [[]]] > > > I have question: Is there any difference between [[]] and []? > [[]] can have deeper assignment and use than > > ccc[0]='o' > > > Thanks, > I have question. Is there any chance that you stop wasting the time of people on this list by either doing your own research or trying things at an interactive prompt? Or are you now well past that point, as you're learned that the extremely generous people here have fitted your bibs, spoon fed you and and changed your nappies so many times that it has rendered you incapable of doing anything for yourself? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From torriem at gmail.com Thu Nov 19 11:31:10 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 19 Nov 2015 09:31:10 -0700 Subject: non-blocking getkey? In-Reply-To: References: Message-ID: <564DF94E.8020302@gmail.com> On 11/19/2015 08:48 AM, Ulli Horlacher wrote: > > The focus is moved to another, unrelated window, but not back to the > window in which the python scripts run. > Same behaviour on Linux (XFCE) and windows 7. That's because an app that communicates with standard in and standard out could be running over telnet, theoretically, so there would be no window at all. There's absolutely no link in stdin and stdout to a graphical window. It's not even possible on Windows as the console subsystem is completely separate from the GUI subsystem. When your app opens a Tk window, it's creating a brand new, top-level window, not associated with any existing window. One windows it might be possible to use the win32 api to enumerate the windows, find your console window and switch to it. Might even be possible on Linux using raw X11 calls. From torriem at gmail.com Thu Nov 19 12:25:08 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 19 Nov 2015 10:25:08 -0700 Subject: Writing a Financial Services App in Python In-Reply-To: References: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> Message-ID: <564E05F4.6010809@gmail.com> On 11/19/2015 09:20 AM, Cai Gengyang wrote: > Sure ... is this : https://www.codecademy.com/learn/python a good > place to learn Python ? Why not have a look first at the many tutorials, including the ones on Python's web site? You need to explore feasibility first before you go too far. Python is not the only language out there. I happen to like it, but there are other popular choices. An experienced developer can pick up and program in any language very quickly. Also you need to know a lot more than just programming in Python. You will need to know the various web development technologies and languages. I don't say this just to discourage you up front. I say this from a lot of sad experience. Your goals are *very* ambitious. I've seen fairly straightforward web apps stretch out into years and many tens of thousands of dollars with whole teams of programmers. And it does not appear you have any programming experience at all yet. Forget about a web app for now. Work on the pieces like the algorithms needed for doing the analysis you require. Do some simple programs that only do console input and output. > Are you wanting to contract with some programmers to create this > application for you? ---- Eventually I will have to find programming > co-founders and employees to create and iterate the product as user > feedback streams in. But I will write the initial prototype myself > because I plan to be the main programmer / founder , but yes ... > eventually I will need 1 or even 2 co-founders and when the platform > gains enough users, we will have to hire programmers and sales/ > business people. But this will be a tech-heavy company and all the > main founders and employees should be excellent programmers. But for > the moment, I plan to write the initial prototype myself ... Sounds ambitious! Hope you have a business plan in mind from the start. From rosuav at gmail.com Thu Nov 19 12:30:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 04:30:26 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 3:01 AM, Steven D'Aprano wrote: > You know, for somebody who claims to design and implement your own > languages, you sometimes go to a remarkable effort to claim to be a dummy. > You write your own interpreter, but can't understand early versus late > binding? I don't think so. I'm not sure that's such a fair comparison. Anyone can design a brand-new language, and even implementing one isn't all that hard. If you don't understand other languages, you can certainly create the one that always does what you think most intuitive, right at the instant when you designed/implemented some feature. What's hard is designing a clean language that does what _someone else_ expects. (And that includes yourself in six months.) ChrisA From bc at freeuk.com Thu Nov 19 12:30:43 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 17:30:43 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 16:01, Steven D'Aprano wrote: > On Fri, 20 Nov 2015 12:19 am, BartC wrote: > You know, for somebody who claims to design and implement your own > languages, you sometimes go to a remarkable effort to claim to be a dummy. > You write your own interpreter, but can't understand early versus late > binding? I don't think so. No I don't; so? Maybe my interpreter can do its thing without being aware that what it's doing has been called 'late binding' or 'early binding' by someone else. At least its default values work as expected! (And they can also be applied to existing external functions. Even C API functions where the implementation doesn't support these features. So if an argument is missing, it applies the default I specify in its place. It's that simple.) > I understand that the simplest things can be perplexing if you look at them > the wrong way. But we've explained multiply times now, or at least tried to > explain, that the argument default is a single object. That is blindingly > obvious once you look at it the right way, and it is a nice, clean design. I can understand now how it works as it does. But I still think it is unintuitive. A language design could have chosen to make it work however it liked. > There's no need to introduce extra modes where code has to be stored away > to be evaluated later (apart from the body of the function itself). > Everything works the same way: assignment always evaluates a result and > binds it to the name, whether that assignment is in a parameter list or > not. > > If you insist on thinking about it in terms of how C or Pascal work, of > course you will confuse yourself. The argument default is evaluated when > the function is created, and the resulting object is stored away for later > use, inside the function. That is clean and easy to understand. > > I'm not saying that the behaviour with mutable defaults The whole concept of 'mutable' default is alien to me. A default is just a convenient device to avoid having to write: fn(0) or fn("") or fn([]) You just write fn() instead. But it shouldn't come at the cost of completely different semantics! Because then it can't really be called a default value at all. isn't surprising to > somebody coming from a completely different paradigm. I was surprised by it > too, the first time I got bitten. So you didn't bother reading the LRM either! > py> def demo_const(x, y=[]): > ... return x + len(y) > Exactly as you should expect. Where you run into trouble is when the default > value is NOT a constant: > > py> def demo_variable(x, y=[]): > ... y.append(1) > ... return x + len(y) Sorry, what is the default value in each of these? As the first lines of the defintions look identical apart from the function names. > ... > py> demo_variable(5) > 6 > py> demo_variable(5) > 7 > py> demo_variable(5) > 8 > > > If you modify the value, the value will be modified. Why are you surprised > by this? Which value is being modified? The []? >> And most often that constant is 0, "" or an empty list. >> >> You want these very common examples to /just work/ instead of going to >> lengths trying to explain why they don't. > > Ah, the good-old "I shouldn't have to think to understand programming" model > of programming. Because that works so well. It works well when sharing code because not everyone understands things at the same level. >> Maybe you can wrap the entire module inside a function? Other than a bit >> at the end that calls that function. Does that solve the global lookup >> problem? > > No. Why not? > >>> When you deal with mutable objects, you have to expect them to mutate. >>> The whole point of mutability is that their value can change. >> >> That [] doesn't look like an object that could change. > > Of course it does. You've lost me know. Are you saying that: a=[] why sometimes not assign an empty list, because that [] could have been modified? It is a list literal, like int literals, float literals, > string literals and the rest. Another surprise? Literals by definition can't change: def fn(): a=[10,20,30] a.append(999) I would hope that a is set to [10,20,30] at each entry to the function! >> You presumably think differently because you have some inside knowledge >> of how Python works, and know that that [] undergoes a one-time >> assignment to a local, persistent 'default' variable where it's value >> can indeed by changed. (Thanks to another Python feature where an >> assignment is a very shallow copy of an object.) And it is that volatile >> variable that is the actual default. > > Assignments are not copies at all. if you write A=B then something of B needs to have been copied into A, even if it's just the reference that B contains. Otherwise it would be difficult to get A to refer to the same object as B. -- Bartc From rosuav at gmail.com Thu Nov 19 12:34:29 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 04:34:29 +1100 Subject: Why doesn't this method have access to its "self" argument? In-Reply-To: References: Message-ID: On Fri, Nov 20, 2015 at 3:13 AM, Robert Latest via Python-list wrote: > rl at dc:~/c/cwsf/python_module$ python test.py > > Minimal example files: > > ========================== test.py =================================== > > import cmethod > > class Test(): > > # add methods to the class "after the fact" > Test.py_method = py_method > Test.c_method = cmethod.c_method Are you using Python 2 here? If so, you're using an old-style class, which has specific consequences that I can never remember. Does the situation change if you slap 'object' between those parentheses? Or if you use Python 3? ChrisA From rosuav at gmail.com Thu Nov 19 12:45:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 04:45:14 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 4:30 AM, BartC wrote: > The whole concept of 'mutable' default is alien to me. A default is just a > convenient device to avoid having to write: > > fn(0) or fn("") or fn([]) > > You just write fn() instead. But it shouldn't come at the cost of completely > different semantics! Because then it can't really be called a default value > at all. > Do you understand the concept of "mutable objects"? Don't even try to discuss mutable function defaults until you do. If your language simply has no mutable objects, then sure, it's easy to understand function defaults! There's no such thing as early or late binding; in fact, you can even super-late-bind, where you don't actually call a function until its *return value* is being used (as long as that function has no side effects). But as soon as objects are capable of retaining their identities while changing their values, you need an object model that (a) distinguishes between identity and value, and (b) allows some definition of early or late binding, because it *will* matter. > if you write A=B then something of B needs to have been copied into > A, even if it's just the reference that B contains. Otherwise it would be > difficult to get A to refer to the same object as B. Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked you to earlier). Don't post another word on this subject until you comprehend what he is saying. ChrisA From __peter__ at web.de Thu Nov 19 13:00:15 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Nov 2015 19:00:15 +0100 Subject: Why doesn't this method have access to its "self" argument? References: Message-ID: Robert Latest via Python-list wrote: > I found a workaround using a wrapper method which calls a C function, > passing the instance as a separate argument. It works, and I cannot see > any disadvantage. It's just not as elegant as I'd like it to be, and I > don't understand WHY the C "method" doesn't receive a pointer to the > Python instance. Maybe somebody can clarify. I don't know much about the C-implementation side, but functions written in Python are also descriptors. Given def f(self): pass class A(object): m = f c = abs v = 42 a = A() a seemingly simple attribute access m = a.m # m is now a bound method invokes f.__get__(a, A) under the hood while m = a.c assert m is abs just returns the function (abs in the example) the same way it returns any other value: v = a.v assert v == 42 From bc at freeuk.com Thu Nov 19 13:19:26 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 18:19:26 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 17:45, Chris Angelico wrote: > On Fri, Nov 20, 2015 at 4:30 AM, BartC wrote: >> The whole concept of 'mutable' default is alien to me. A default is just a >> convenient device to avoid having to write: >> >> fn(0) or fn("") or fn([]) >> >> You just write fn() instead. But it shouldn't come at the cost of completely >> different semantics! Because then it can't really be called a default value >> at all. >> > > Do you understand the concept of "mutable objects"? Don't even try to > discuss mutable function defaults until you do. Yes. In the languages I create, pretty much everything is mutable, provided it can supply an l-value. Constructs such as those for empty lists ([] in Python, () in mine) aren't l-values. But it doesn't apply default values. The language is very different however, because the byte-code compiler always has full knowledge of functions that are called directly. Then it knows when an argument is omitted, and can simply substitute the expression used as the default. > If your language simply has no mutable objects, then sure, it's easy > to understand function defaults! There's no such thing as early or > late binding; in fact, you can even super-late-bind, where you don't > actually call a function until its *return value* is being used (as > long as that function has no side effects). But as soon as objects are > capable of retaining their identities while changing their values, you > need an object model that (a) distinguishes between identity and > value, and (b) allows some definition of early or late binding, > because it *will* matter. > >> if you write A=B then something of B needs to have been copied into >> A, even if it's just the reference that B contains. Otherwise it would be >> difficult to get A to refer to the same object as B. > > Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked > you to earlier). Don't post another word on this subject until you > comprehend what he is saying. I looked through the long article (I don't remember seeing a link to a video), and followed it up to about 3/4 of the way through, then it got a bit heavy. But what is it about my remarks above that isn't right? -- Bartc From breamoreboy at yahoo.co.uk Thu Nov 19 13:20:34 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 19 Nov 2015 18:20:34 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 17:30, BartC wrote: > On 19/11/2015 16:01, Steven D'Aprano wrote: >> On Fri, 20 Nov 2015 12:19 am, BartC wrote: > >> You know, for somebody who claims to design and implement your own >> languages, you sometimes go to a remarkable effort to claim to be a >> dummy. >> You write your own interpreter, but can't understand early versus late >> binding? I don't think so. > > No I don't; so? Maybe my interpreter can do its thing without being > aware that what it's doing has been called 'late binding' or 'early > binding' by someone else. > > At least its default values work as expected! > Python's default values work exactly as I expect as the subject has been debated at least twice a year on c.l.py for the 15 or so years that I've been using Python. If your expectations are clearly wrong, that is your problem and your problem alone. A solution to your problem is another language that does meet all of your expectations, but as there is never a "one size fits all" the only one that I can think of is your own, whatever that is called. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Thu Nov 19 13:26:08 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 19 Nov 2015 18:26:08 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 18:19, BartC wrote: > On 19/11/2015 17:45, Chris Angelico wrote: >> On Fri, Nov 20, 2015 at 4:30 AM, BartC wrote: >>> The whole concept of 'mutable' default is alien to me. A default is >>> just a >>> convenient device to avoid having to write: >>> >>> fn(0) or fn("") or fn([]) >>> >>> You just write fn() instead. But it shouldn't come at the cost of >>> completely >>> different semantics! Because then it can't really be called a default >>> value >>> at all. >>> >> >> Do you understand the concept of "mutable objects"? Don't even try to >> discuss mutable function defaults until you do. > > Yes. In the languages I create, pretty much everything is mutable, > provided it can supply an l-value. Constructs such as those for empty > lists ([] in Python, () in mine) aren't l-values. > > But it doesn't apply default values. The language is very different > however, because the byte-code compiler always has full knowledge of > functions that are called directly. Then it knows when an argument is > omitted, and can simply substitute the expression used as the default. > >> If your language simply has no mutable objects, then sure, it's easy >> to understand function defaults! There's no such thing as early or >> late binding; in fact, you can even super-late-bind, where you don't >> actually call a function until its *return value* is being used (as >> long as that function has no side effects). But as soon as objects are >> capable of retaining their identities while changing their values, you >> need an object model that (a) distinguishes between identity and >> value, and (b) allows some definition of early or late binding, >> because it *will* matter. >> >>> if you write A=B then something of B needs to have been copied into >>> A, even if it's just the reference that B contains. Otherwise it >>> would be >>> difficult to get A to refer to the same object as B. >> >> Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked >> you to earlier). Don't post another word on this subject until you >> comprehend what he is saying. > > I looked through the long article (I don't remember seeing a link to a > video), and followed it up to about 3/4 of the way through, then it got > a bit heavy. > > But what is it about my remarks above that isn't right? > To summarize, it once again shows that you haven't got the faintest idea what you're talking about. You're now in a very exclusive club with the RUE and Nick the Greek, the world's leading webmaster. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Thu Nov 19 13:39:38 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 19 Nov 2015 20:39:38 +0200 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mvu9esut.fsf@elektro.pacujo.net> BartC : > Yes. In the languages I create, pretty much everything is mutable, > provided it can supply an l-value. Constructs such as those for empty > lists ([] in Python, () in mine) aren't l-values. > > But it doesn't apply default values. Python's default-value semantics is analogous to C++: ======================================================================== #include using namespace std; static int z; static void f(int &x = z) { x++; } int main() { cout << z << endl; f(); cout << z << endl; f(); cout << z << endl; return 0; } ======================================================================== which prints: 0 1 2 Marko From ian.g.kelly at gmail.com Thu Nov 19 13:42:46 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Nov 2015 11:42:46 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Nov 19, 2015 at 11:26 AM, Mark Lawrence wrote: > To summarize, it once again shows that you haven't got the faintest idea > what you're talking about. You're now in a very exclusive club with the RUE > and Nick the Greek, the world's leading webmaster. Eh. Ranting Rick and Mark Janssen / Zipher / TheDoctor / whatever name he's using now belong in that club, but Nikos was just incompetent, not a crackpot. BartC on the other hand is just complaining about an aspect of Python that is legitimately controversial. From oscar.j.benjamin at gmail.com Thu Nov 19 13:44:50 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 19 Nov 2015 18:44:50 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19 November 2015 at 18:19, BartC wrote: >>> >>> if you write A=B then something of B needs to have been copied into >>> A, even if it's just the reference that B contains. Otherwise it would be >>> difficult to get A to refer to the same object as B. >> >> Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked >> you to earlier). Don't post another word on this subject until you >> comprehend what he is saying. > > I looked through the long article (I don't remember seeing a link to a > video), and followed it up to about 3/4 of the way through, then it got a > bit heavy. > > But what is it about my remarks above that isn't right? It's not necessarily incorrect (just focussing on the remark quoted above) but you'll find it easier to understand the model if you adopt the same terminology that is usually used. When talking of "copying" in a Python context something different is implied than what happens with A=B. The statement A=B (assuming A and B are names and not expressions) simply binds the name A to the same object that the name B is bound to. In the implementation of CPython the names are associated with pointers and the value of the pointer associated with B is copied to the pointer associated with A. Another implementation may not use pointers but there will in some way be a "reference" that is "copied" over if you like to view it that way. However in a Python context when someone talks of "copying" they will mean something different: creating a new object which is distinct from, but has the same value as, some previously existing object. It is important in Python to distinguish between operations that create/mutate objects and operations that rebind names. This distinction has semantic implications that are not hard to understand if you think about them carefully and consistent use of terminology really helps. -- Oscar From bc at freeuk.com Thu Nov 19 13:50:15 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 18:50:15 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 18:26, Mark Lawrence wrote: > On 19/11/2015 18:19, BartC wrote: >>>> if you write A=B then something of B needs to have been copied into >>>> A, even if it's just the reference that B contains. Otherwise it >>>> would be >>>> difficult to get A to refer to the same object as B. >>> >>> Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked >>> you to earlier). Don't post another word on this subject until you >>> comprehend what he is saying. > >> But what is it about my remarks above that isn't right? > > To summarize, it once again shows that you haven't got the faintest idea > what you're talking about. But you're not going to tell me what it is I got wrong! I said that Python's "=" does a very shallow copy. And I stated that in A=B, something of B must be copied into A. I (and probably others) would like to know why none of that is correct. But I suspect I'm not wrong. -- Bartc From rosuav at gmail.com Thu Nov 19 14:09:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 06:09:49 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 5:50 AM, BartC wrote: > But you're not going to tell me what it is I got wrong! > > I said that Python's "=" does a very shallow copy. And I stated that in A=B, > something of B must be copied into A. > > I (and probably others) would like to know why none of that is correct. But > I suspect I'm not wrong. There's no copying happening. You evaluate the expression `B`, and get back some kind of object (because all expressions in Python evaluate to objects, unless they raise exceptions or in some way don't finish evaluating). The name A then becomes bound to that object. You're not copying a reference; you're simply referencing the result of an expression. PLEASE finish reading Ned's talk. Here's the link again: http://nedbatchelder.com/text/names1.html It is an excellent explanation of the exact points you're confused about. ChrisA From patrickhess at gmx.net Thu Nov 19 14:17:37 2015 From: patrickhess at gmx.net (Patrick Hess) Date: Thu, 19 Nov 2015 20:17:37 +0100 Subject: How can I export data from a website and write the contents to a text file? In-Reply-To: References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> <6e0f470b-f896-43ae-8f83-b20f22a9db8d@googlegroups.com> Message-ID: <2052054.MEiq1cOQgg@desk8.phess.net> ryguy7272 wrote: > text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") > [...] > It doesn't seem like the '\n' is doing anything useful. All the text is jumbled together. > [...] > I finally got it working. It's like this: > "\r\n" The better solution would be to open text files in actual text mode: open("filename", "wb") # binary mode open("filename", "w") # text mode In text mode, the correct line-ending characters, which will vary depending on the operating system, are chosen automatically. with open("test.txt", "w") as textfile: textfile.write("line 1\n") textfile.write("line 2") This produces "line 1\nline 2" on Unix systems and "line 1\r\nline 2" on Windows. Also involves less typing this way. ;-) Patrick From rosuav at gmail.com Thu Nov 19 14:19:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 06:19:06 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 5:19 AM, BartC wrote: > Yes. In the languages I create, pretty much everything is mutable, provided > it can supply an l-value. Constructs such as those for empty lists ([] in > Python, () in mine) aren't l-values. > > But it doesn't apply default values. The language is very different however, > because the byte-code compiler always has full knowledge of functions that > are called directly. Then it knows when an argument is omitted, and can > simply substitute the expression used as the default. In other words, your language uses late binding by default. That's fine; it's a design choice that you've made one way and Python's made the other way. It's on par with design choices like whether adding a string and an integer implicitly stringifies the int, or raises an error. I know several good languages that have taken each of those choices. But every choice has consequences. Steven gave you a few examples of the consequences of late-binding default arguments. For example, can you translate this into (one of) your language(s), and explain the semantics of the late binding? # scope 1: can be a module, an inner function, whatever y = 42 def func(x=y): return x def change_y(): global y # affect the one in this scope y = 28 # scope 2: another module/function/etc from scope1 import func # gain access, however that's done change_y() y = 7 func() Should this return 7, 28, or 42? Early binding demands 42, which is nice and simple: you don't need to look anywhere outside the function's own definition to grok its defaults. The default is stable (it won't change from one run to another - it'll always be the same object). Scope-recognizing late binding would use 28; it re-evaluates the expression 'y' in its original scope. This one makes the most sense to me, of all late-bind semantics; it also happens to be the same semantics as you get if you do the classic "if x is None: x=y" late-bind in Python, modulo the effect of the nested scope. But you're saying that it "simply substitute[s] the expression", which would mean that "func()" is exactly the same as "func(y)". A function default argument is therefore able to STEAL STUFF FROM THE CALLER'S SCOPE. Sorry for shouting, but if that ain't bizarre, I don't know what is. ChrisA From ian.g.kelly at gmail.com Thu Nov 19 14:25:21 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Nov 2015 12:25:21 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Nov 19, 2015 at 12:19 PM, Chris Angelico wrote: > But you're > saying that it "simply substitute[s] the expression", which would mean > that "func()" is exactly the same as "func(y)". A function default > argument is therefore able to STEAL STUFF FROM THE CALLER'S SCOPE. > Sorry for shouting, but if that ain't bizarre, I don't know what is. It's like pass-by-name, but in reverse. From skaufman at tsi.com Thu Nov 19 14:45:41 2015 From: skaufman at tsi.com (Kaufman, Stan) Date: Thu, 19 Nov 2015 19:45:41 +0000 Subject: Unsuccessful installation Message-ID: <4530f633821e477798c80bf8d6d095f2@TSI-SV-MBX-01.tsi.corp.com> Python would not run on this Windows XP computer. After four attempts at "change/remove" it still gives the same message: [cid:image001.png at 01D122D0.93CC3270] The first trip through "change/remove" appeared to be a further step in installation. The second through fourth trips indicated "repairing..." Each time, an attempt to run it resulted in the above message. --------------------------------------- Stan Kaufman Principal Scientist (retired) TSI Incorporated 500 Cardigan Road St. Paul, MN 55126 --------------------------------------- "Science is what we have learned about how to keep from fooling ourselves." Richard Feynman --------------------------------------- This e-mail or the documents accompanying this e-mail contain information that may be confidential and/or privileged. It may also be prohibited from disclosure under applicable law. The information is intended to be for the use of the individual or entity named on this transmission. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is without authorization and is prohibited. If you have received this e-mail in error, please notify us immediately so that we can take action to correct the problem. From rosuav at gmail.com Thu Nov 19 14:46:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 06:46:42 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Message-ID: On Fri, Nov 20, 2015 at 5:42 AM, Ian Kelly wrote: > BartC on the other hand is just complaining about an aspect of Python > that is legitimately controversial. IMO it's controversial mainly because there's an easy and obvious syntax for early binding, but late binding doesn't have syntactic support, and all the options are imperfect. Consider: def late1(x=None): """Terse but buggy""" do_stuff_with(x or []) def late2(x=None): """Not bad but has an extra line for each default. Also, can't take None.""" if x is None: x = [] do_stuff_with(x) _SENTINEL = object() def late3(x=_SENTINEL): """Has the same global-pollution problem you get when you try to construct early binding from late; you can share the sentinel among multiple args, even multiple funcs, though""" if x is _SENTINEL: x = [] do_stuff_with(x) def late4(x=object()): """Depends on its own name remaining bound in its scope, and will break if you change argument order""" if x is late4.__defaults__[0]: x = [] do_stuff_with(x) And there might be other techniques, too. They all share one important flaw, too: When you ask for help about the function, you can't see what the default really is. All you see is: late1(x=None) late3(x=) In the first two cases, it's not too bad; you can specify a timeout as either a number or as None, and if it's None (the default), the timeout is three times the currently estimated round trip time. No problem. But how would you implement something like next() in pure Python? If you provide _any second argument at all_, it returns that instead of raising StopIteration. The ONLY way that I can think of is to use *args notation: def next(iterator, *default): try: return iterator.__next__() except StopIteration: if default: return default[0] raise And while that isn't TOO bad for just one argument, it scales poorly: def foo(fixed_arg, *args): """Foo the fixed_arg against the spam mapping, the ham sequence, and the jam file.""" args.reverse() spam = args.pop() if args else {} ham = args.pop() if args else [] jam = args.pop() if args else open("jam.txt") Suppose, instead, that Python had a syntax like this: def foo(fixed_arg, spam=>{}, ham=>[], jam=>open("jam.txt")): """Foo the fixed_arg against the spam mapping, the ham sequence, and the jam file.""" The expressions would be evaluated as closures, using the same scope that the function's own definition used. (This won't keep things alive unnecessarily, as the function's body will be nested within that same scope anyway.) Bikeshed the syntax all you like, but this would be something to point people to: "here's how to get late-binding semantics". For the purposes of documentation, the exact text of the parameter definition could be retained, and like docstrings, they could be discarded in -OO mode. Would this satisfy the people who get confused about "=[]"? ChrisA From bc at freeuk.com Thu Nov 19 14:48:55 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 19:48:55 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 19:09, Chris Angelico wrote: > On Fri, Nov 20, 2015 at 5:50 AM, BartC wrote: >> But you're not going to tell me what it is I got wrong! >> >> I said that Python's "=" does a very shallow copy. And I stated that in A=B, >> something of B must be copied into A. >> >> I (and probably others) would like to know why none of that is correct. But >> I suspect I'm not wrong. > > There's no copying happening. You evaluate the expression `B`, and get > back some kind of object (because all expressions in Python evaluate > to objects, unless they raise exceptions or in some way don't finish > evaluating). The name A then becomes bound to that object. You're not > copying a reference; you're simply referencing the result of an > expression. OK, so it's just a coincidence that after A=B, id(A) appears to be an identical copy of id(B)? And which also agrees with my assertions that a very shallow copy is done, and that some aspect of B is duplicated in A. > It is an excellent explanation of the exact points you're confused about. As far I'm concerned I'm not confused by these copying aspects. I said 'very shallow copy', not 'shallow copy' nor 'deep copy' nor just 'copy'. To me, 'very shallow copy' about sums it up. While Python byte-code for A=B: 6 LOAD_GLOBAL 0 (b) 9 STORE_GLOBAL 1 (a) doesn't really disagree with me either as it looks remarkably like any other basic copy operation of any machine language or byte-code that has ever been invented. If you said instead that I'm not using the official jargon then perhaps you're right. But the right terminology isn't going to make me like Python's default values any better! -- Bartc From rosuav at gmail.com Thu Nov 19 14:58:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 06:58:42 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 6:48 AM, BartC wrote: > On 19/11/2015 19:09, Chris Angelico wrote: >> >> On Fri, Nov 20, 2015 at 5:50 AM, BartC wrote: >>> >>> But you're not going to tell me what it is I got wrong! >>> >>> I said that Python's "=" does a very shallow copy. And I stated that in >>> A=B, >>> something of B must be copied into A. >>> >>> I (and probably others) would like to know why none of that is correct. >>> But >>> I suspect I'm not wrong. >> >> >> There's no copying happening. You evaluate the expression `B`, and get >> back some kind of object (because all expressions in Python evaluate >> to objects, unless they raise exceptions or in some way don't finish >> evaluating). The name A then becomes bound to that object. You're not >> copying a reference; you're simply referencing the result of an >> expression. > > > OK, so it's just a coincidence that after A=B, id(A) appears to be an > identical copy of id(B)? And which also agrees with my assertions that a > very shallow copy is done, and that some aspect of B is duplicated in A. When you execute A=B, you start by evaluating the expression B. It's not a coincidence that re-evaluating a simple name immediately afterward yields the same object: >>> id(B) 140330420093056 >>> id(B) 140330420093056 >>> id(B) 140330420093056 >>> id(B) 140330420093056 But that's all you've proven. You've shown that the result of evaluating B twice was the same object each time. That's no proof of copying; it's just proof that, barring threading or other reentrancy problems, expressions consisting solely of simple names are stable. >> It is an excellent explanation of the exact points you're confused about. > > > As far I'm concerned I'm not confused by these copying aspects. I said 'very > shallow copy', not 'shallow copy' nor 'deep copy' nor just 'copy'. To me, > 'very shallow copy' about sums it up. > > While Python byte-code for A=B: > > 6 LOAD_GLOBAL 0 (b) > 9 STORE_GLOBAL 1 (a) Technically that's CPython byte code. Python (the language) specifies the semantics of assignment, but not the exact byte code used. > doesn't really disagree with me either as it looks remarkably like any other > basic copy operation of any machine language or byte-code that has ever been > invented. I think you're warping the word "copy" to mean what Python does on assignment, rather than noting an actual similarity between Python assignment and any other concept of copying. Remember, Python does not have pointers, in the sense of machine integers storing addresses. When you assign one C pointer variable to another, yes, you're copying that integer value; but Python doesn't work that way, so there is nothing to copy. ChrisA From lac at openend.se Thu Nov 19 15:18:01 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 19 Nov 2015 21:18:01 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: <201511192018.tAJKI13E021560@fido.openend.se> In a message of Fri, 20 Nov 2015 06:46:42 +1100, Chris Angelico writes: >Would this satisfy the people who get confused about "=[]"? > >ChrisA My experience says that the people who are confused want lists to behave like tuples. period. i.e. they don't want lists to be mutable. Which means when I say 'use a tuple instead' they go away happy. Lots of very occasional programmers in my world (children) just use tuples instead of lists and never get surprises and never go on to learn about lists and why they are a good idea. But then there are those who come back with the problem: 'my python program is too slow'. From a perspective of 'Let us understand why this is so and what could we do to make things faster', I can get them to come up with the idea of a python list all on their own. But this requires the sort of brain that is interested in how interpreters work, otherwise this conversation will not happen. Without the actual problem biting them, the whole idea of mutable objects seems, ah, hazardous. I wonder if we do people a disservice by introducing them straight off in teaching python to absolute beginners, and if the learning would go easier if we taught tuples and made them all use them a while before we gave them lists. At any rate, 'what is a mutable object' is a conversation that I have had too many times with people who really aren't interested. I now think that 'use a tuple instead' is the way to go, with the addition -- come back and talk to me about this at any time if you want to learn why this is so. Laura From danielkasuza at gmail.com Thu Nov 19 15:22:10 2015 From: danielkasuza at gmail.com (Daniel Kasuza) Date: Thu, 19 Nov 2015 22:22:10 +0200 Subject: failing to run python on my pc Message-ID: Dear Sir/Madam I am student with University of the people and a beginner in programming. My problem is that l have down loaded python 2.7 but l am failing to muse it. If l try to to use it, I am getting an option which say run. If l press run, it just run and come back to the same option. I want to use it for some practice but i am failing. Please help Daniel From ian.g.kelly at gmail.com Thu Nov 19 15:37:54 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Nov 2015 13:37:54 -0700 Subject: Unsuccessful installation In-Reply-To: <4530f633821e477798c80bf8d6d095f2@TSI-SV-MBX-01.tsi.corp.com> References: <4530f633821e477798c80bf8d6d095f2@TSI-SV-MBX-01.tsi.corp.com> Message-ID: On Thu, Nov 19, 2015 at 12:45 PM, Kaufman, Stan wrote: > Python would not run on this Windows XP computer. After four attempts at "change/remove" it still gives the same message: > > [cid:image001.png at 01D122D0.93CC3270] > > The first trip through "change/remove" appeared to be a further step in installation. The second through fourth trips indicated "repairing..." Each time, an attempt to run it resulted in the above message. Python 3.5 does not support Windows XP. When Python 3.5.1 is released, the installer will better communicate this. You need to upgrade your OS to Vista or more recent, or downgrade your Python to 3.4. From marko at pacujo.net Thu Nov 19 15:57:10 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 19 Nov 2015 22:57:10 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: Message-ID: <87d1v5emhl.fsf@elektro.pacujo.net> Laura Creighton : > My experience says that the people who are confused want lists to > behave like tuples. period. i.e. they don't want lists to be mutable. I think it's simpler than that. When you have: def f(x=[]): y = [] the first [] is evaluated when "def" is executed, while the latter [] is evaluated whenever "f" is executed. It's easy to be confused. Marko From bc at freeuk.com Thu Nov 19 16:21:24 2015 From: bc at freeuk.com (BartC) Date: Thu, 19 Nov 2015 21:21:24 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 19:19, Chris Angelico wrote: > On Fri, Nov 20, 2015 at 5:19 AM, BartC wrote: > But every choice has consequences. Steven gave you a few examples of > the consequences of late-binding default arguments. For example, can > you translate this into (one of) your language(s), and explain the > semantics of the late binding? > > # scope 1: can be a module, an inner function, whatever > y = 42 > def func(x=y): > return x > def change_y(): > global y # affect the one in this scope > y = 28 > > # scope 2: another module/function/etc > from scope1 import func # gain access, however that's done > > change_y() > y = 7 > func() > > > Should this return 7, 28, or 42? I tried in two languages and both returned 28 the first time. Then I realised I'd missed out the y=7 line. Both then printed 7. It doesn't matter so much if split across modules or not; it depends mainly on whether the y in 'y=7' is the same one in 'x=y' and 'y=28' and this depends on how it's declared or not and how. (Both are here if you're interested: http://pastebin.com/0WPrYQw6) Actually I'm just glad I got one of the results in your list! (Python returns 42; so that means my languages are more dynamic than Python? That's hard to believe!) you don't need to look anywhere outside the > function's own definition to grok its defaults. The default is stable > (it won't change from one run to another - it'll always be the same > object). Scope-recognizing late binding would use 28; it re-evaluates > the expression 'y' in its original scope. This one makes the most > sense to me, of all late-bind semantics; it also happens to be the > same semantics as you get if you do the classic "if x is None: x=y" > late-bind in Python, modulo the effect of the nested scope. But you're > saying that it "simply substitute[s] the expression", which would mean > that "func()" is exactly the same as "func(y)". A function default > argument is therefore able to STEAL STUFF FROM THE CALLER'S SCOPE. > Sorry for shouting, but if that ain't bizarre, I don't know what is. Well, it's not quite the same as textual substitution of the default value expression, which would use names in the local scope at the call site. The expression is evaluated using the entities in scope where the function is defined, as far as I can determine, although the byte-code that evaluates it is at the call site. This is necessary I think because you want the default value to evaluated to the same result independently of the actual call site (unless the caller has deliberately manipulated things as in your example). -- From w.g.sneddon at gmail.com Thu Nov 19 16:53:09 2015 From: w.g.sneddon at gmail.com (bSneddon) Date: Thu, 19 Nov 2015 13:53:09 -0800 (PST) Subject: Dabbling in web development Message-ID: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> I know there are a plethora of web frameworks out there for Python and to be serious about website developement I should learn on like Django. Really thought, I just want to dabble and do some easy stuff. Does anyone have any suggestons? I have a a website hosted with a hosting company who is supposed to have python support but hard to know what they have installed on there apache server. I have seen a few examples out there but not too many. From ian.g.kelly at gmail.com Thu Nov 19 17:03:47 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Nov 2015 15:03:47 -0700 Subject: Dabbling in web development In-Reply-To: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> Message-ID: On Thu, Nov 19, 2015 at 2:53 PM, bSneddon wrote: > I know there are a plethora of web frameworks out there for Python and to be serious about website developement I should learn on like Django. Really thought, I just want to dabble and do some easy stuff. Does anyone have any suggestons? I have a a website hosted with a hosting company who is supposed to have python support but hard to know what they have installed on there apache server. I have seen a few examples out there but not too many. Flask is a good choice if you're just looking for something easy to get going. From breamoreboy at yahoo.co.uk Thu Nov 19 17:35:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 19 Nov 2015 22:35:37 +0000 Subject: Dabbling in web development In-Reply-To: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> Message-ID: On 19/11/2015 21:53, bSneddon wrote: > I know there are a plethora of web frameworks out there for Python and to be serious about website developement I should learn on like Django. Really thought, I just want to dabble and do some easy stuff. Does anyone have any suggestons? I have a a website hosted with a hosting company who is supposed to have python support but hard to know what they have installed on there apache server. I have seen a few examples out there but not too many. > Take a look at "Popular Non Full-Stack Frameworks" here https://wiki.python.org/moin/WebFrameworks -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Thu Nov 19 17:41:19 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 19 Nov 2015 23:41:19 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87d1v5emhl.fsf@elektro.pacujo.net> References: <87d1v5emhl.fsf@elektro.pacujo.net> Message-ID: <201511192241.tAJMfJZ6031048@fido.openend.se> In a message of Thu, 19 Nov 2015 22:57:10 +0200, Marko Rauhamaa writes: >Laura Creighton : > >> My experience says that the people who are confused want lists to >> behave like tuples. period. i.e. they don't want lists to be mutable. > >I think it's simpler than that. When you have: > > def f(x=[]): > y = [] > >the first [] is evaluated when "def" is executed, while the latter [] is >evaluated whenever "f" is executed. It's easy to be confused. > > >Marko Note: Ned Bachelder (who is probably reading this on python-list anyway added cc on this mail, as if I am to discuss somebody, however briefly, they deserve to hear about it. Which may irritate him to get 2 copies instead of one, but so it goes. I am talking about BartC as well, but since this is his thread, I assume he is here.) Now back to what Marko said: This is one of the times when it is nice to be dealing with children. The whole notion of 'when def is executed' is not on their radar at all. It is all a matter of 'I write this, I want that'. :) And with reasonable amount of authority from experience, I can tell you that 'write it with round brackets not square ones' makes the code *just work* for a large number of students who only have a limited amount of patience for 'understanding what they are doing'. They want to be able to do it first, and have understanding come later (if at all). This is the learning approach of 'training' as opposed to 'educating'. And, for all that we _talk_ of 'educating our children' -- what we really do, a whole lot of the time, is train them. The very basic skills of reading, writing (typing?) and arithmetic and foreign languages need to be trained, and no amount of understanding the theory behind such things will ever directly translate into being able to do it. Indeed, the best authority on the planet on 13th century French court dances is a one-legged Frenchman, (whose name I now forget). Although he has (or maybe had, he is likely dead by now, he lost his leg in WW2) the education and the theory and the scholasticism, anybody with 2 legs, however ignorant, can dance the court dances better. Sometimes you want to understand what you are doing. Sometimes you just want to do it. And sometimes, well, the only real way to get an understanding of what you are doing is to do it more. This is, in my opinion, Bartc's problem. He doesn't program in python enough to understand it more. He wants us to give him a better theoretical understanding of Python, but for me, at any rate he is hitting the wrong audience. And Ned Batchelder is unlikely to help. Both of us come from the practical end of things, and write lessons and talks like the one ChrisA recommended -- which is wonderful. And how I wish I could write like that -- but they are aimed at telling a practical python programmer 'now that you know how to do it, here is how to understand what you do'. And then, pedagogically, you can move to 'and now you understand what you have been doing, here are some awesome cool tricks you can do to make your life easier (and impress your friends, for a particularly nerdy set of freinds). I don't think that Ned works for the untrained python programmer. And until Bart writes a bunch of code in python, for many weeks or even months, I will not be able to help him, either. But in my life, I end up teaching programming, often to some very smart young people who are specialists at being trained. They want me to train them, not educate them. When you are 9 years old, approaching all of life with the attitude of 'how do I get to spit out the results I want' is enormously adaptive. They have the opposite problem of BartC -- they want to be excellent programmers without understanding anything, while he wants to understand everything before he knows how to write decent python code. It's a pedagogical problem. Laura From lac at openend.se Thu Nov 19 17:53:44 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 19 Nov 2015 23:53:44 +0100 Subject: Dabbling in web development In-Reply-To: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> Message-ID: <201511192253.tAJMrinN031922@fido.openend.se> In a message of Thu, 19 Nov 2015 13:53:09 -0800, bSneddon writes: >I know there are a plethora of web frameworks out there for Python and to be serious about website developement I should learn on like Django. Really thought, I just want to dabble and do some easy stuff. Does anyone have any suggestons? I have a a website hosted with a hosting company who is supposed to have python support but hard to know what they have installed on there apache server. I have seen a few examples out there but not too many. There are lots of other choices than Django. see: https://wiki.python.org/moin/WebFrameworks/ The big split is whether you want a large framework, like Django, which comes with all the batteries included, or a micro framework, like Flask and Bottle, which gives you more control and is a whole lot simpler. It is not the case that 'serious website developers use heavyweight systems like Django' --- lots and lots of serious developers use Flask or Bottle because Django makes you do it the Django way. Flask lets you do it however you like. Professionally, our company has designed a ton of websites and we use Flask nearly all of the time, and Pylons the rest of the time. If your brain is well-suited for Django, by all means use that, but if it is not, then do something else. I teach kids who are 9-12 years old, weekends. Hosting their own site to support pictures of their pets is a very common thing to want to do. I have translated this: http://bottlepy.org/docs/dev/tutorial.html into Swedish and we tend to get a website up and running in 3 weekends of thinking and coding. (This is with kids who already know Python. Learning enough python to do this takes longer, a whole lot longer if you only get to code on weekends -- but most of the kids who want to do this are also willing to write code on weekdays as well.) Laura From torriem at gmail.com Thu Nov 19 17:55:50 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 19 Nov 2015 15:55:50 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <564E5376.1000807@gmail.com> On 11/19/2015 02:21 PM, BartC wrote: > (Python returns 42; so that means my languages are more dynamic than > Python? That's hard to believe!) It tells me your language does late binding for default arguments, which does mean the default argument can dynamically change at call time, which would surprise me if I didn't know about it. Either form of binding is acceptable, and I don't think it makes a language more or less dynamic. Of course as Chris and Laura have said, a list as a default parameter throws people off because of the semantics of mutability, and the fact that Python's variable model does not follow the traditional memory box model used in compiled languages like C. From lac at openend.se Thu Nov 19 18:00:24 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 20 Nov 2015 00:00:24 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) (fwd) Message-ID: <201511192300.tAJN0OnW032461@fido.openend.se> Arrgh! I got Ned Batchelder's email wrong. Forgot the t. (for somebody whose irc nick is nedbat. ) sending this to him again. warning any repliers that the mail address is wrong.... apologies, Laura ------- Forwarded Message From: Laura Creighton Subject: Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-reply-to: <87d1v5emhl.fsf at elektro.pacujo.net> References: Laura Creighton : > >> My experience says that the people who are confused want lists to >> behave like tuples. period. i.e. they don't want lists to be mutable. > >I think it's simpler than that. When you have: > > def f(x=[]): > y = [] > >the first [] is evaluated when "def" is executed, while the latter [] is >evaluated whenever "f" is executed. It's easy to be confused. > > >Marko Note: Ned Bachelder (who is probably reading this on python-list anyway added cc on this mail, as if I am to discuss somebody, however briefly, they deserve to hear about it. Which may irritate him to get 2 copies instead of one, but so it goes. I am talking about BartC as well, but since this is his thread, I assume he is here.) Now back to what Marko said: This is one of the times when it is nice to be dealing with children. The whole notion of 'when def is executed' is not on their radar at all. It is all a matter of 'I write this, I want that'. :) And with reasonable amount of authority from experience, I can tell you that 'write it with round brackets not square ones' makes the code *just work* for a large number of students who only have a limited amount of patience for 'understanding what they are doing'. They want to be able to do it first, and have understanding come later (if at all). This is the learning approach of 'training' as opposed to 'educating'. And, for all that we _talk_ of 'educating our children' -- what we really do, a whole lot of the time, is train them. The very basic skills of reading, writing (typing?) and arithmetic and foreign languages need to be trained, and no amount of understanding the theory behind such things will ever directly translate into being able to do it. Indeed, the best authority on the planet on 13th century French court dances is a one-legged Frenchman, (whose name I now forget). Although he has (or maybe had, he is likely dead by now, he lost his leg in WW2) the education and the theory and the scholasticism, anybody with 2 legs, however ignorant, can dance the court dances better. Sometimes you want to understand what you are doing. Sometimes you just want to do it. And sometimes, well, the only real way to get an understanding of what you are doing is to do it more. This is, in my opinion, Bartc's problem. He doesn't program in python enough to understand it more. He wants us to give him a better theoretical understanding of Python, but for me, at any rate he is hitting the wrong audience. And Ned Batchelder is unlikely to help. Both of us come from the practical end of things, and write lessons and talks like the one ChrisA recommended -- which is wonderful. And how I wish I could write like that -- but they are aimed at telling a practical python programmer 'now that you know how to do it, here is how to understand what you do'. And then, pedagogically, you can move to 'and now you understand what you have been doing, here are some awesome cool tricks you can do to make your life easier (and impress your friends, for a particularly nerdy set of freinds). I don't think that Ned works for the untrained python programmer. And until Bart writes a bunch of code in python, for many weeks or even months, I will not be able to help him, either. But in my life, I end up teaching programming, often to some very smart young people who are specialists at being trained. They want me to train them, not educate them. When you are 9 years old, approaching all of life with the attitude of 'how do I get to spit out the results I want' is enormously adaptive. They have the opposite problem of BartC -- they want to be excellent programmers without understanding anything, while he wants to understand everything before he knows how to write decent python code. It's a pedagogical problem. Laura - -- https://mail.python.org/mailman/listinfo/python-list ------- End of Forwarded Message From maillist at schwertberger.de Thu Nov 19 18:02:53 2015 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Fri, 20 Nov 2015 00:02:53 +0100 Subject: Dabbling in web development In-Reply-To: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> Message-ID: <564E551D.8070704@schwertberger.de> Am 19.11.2015 um 22:53 schrieb bSneddon: > I know there are a plethora of web frameworks out there for Python and to be serious about website developement I should learn on like Django. Really thought, I just want to dabble and do some easy stuff. Does anyone have any suggestons? I have a a website hosted with a hosting company who is supposed to have python support but hard to know what they have installed on there apache server. I have seen a few examples out there but not too many. Maybe, you should have a look at the book "Lightweight Django". Regards, Dietmar From marko at pacujo.net Thu Nov 19 18:07:24 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 20 Nov 2015 01:07:24 +0200 Subject: Dabbling in web development References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> Message-ID: <8737w1eggj.fsf@elektro.pacujo.net> Laura Creighton : > There are lots of other choices than Django. > > see: https://wiki.python.org/moin/WebFrameworks/ However, are there any good web applications? I have seen some heroic attempts but most fail miserably or at least have some annoying glitches. The cardinal sin of web development seems to be micromanagement. Instead of letting the web standards do their work, the application wants to be in full control with JavaScript and XML HTTP requests. The results can be awe-inspiring but at the same time fail at the basics. For example, select/copy with the mouse might not work. Fonts might be garbled. Half the page might be invisible and unscrollable. Or nothing will be displayed at all. Marko From rosuav at gmail.com Thu Nov 19 18:09:01 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Nov 2015 10:09:01 +1100 Subject: Dabbling in web development In-Reply-To: <201511192253.tAJMrinN031922@fido.openend.se> References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> <201511192253.tAJMrinN031922@fido.openend.se> Message-ID: On Fri, Nov 20, 2015 at 9:53 AM, Laura Creighton wrote: > It is not the case that 'serious website developers use heavyweight > systems like Django' --- lots and lots of serious developers use > Flask or Bottle because Django makes you do it the Django way. > Flask lets you do it however you like. Professionally, our company > has designed a ton of websites and we use Flask nearly all of the > time, and Pylons the rest of the time. If your brain is well-suited > for Django, by all means use that, but if it is not, then do something > else. > > I teach kids who are 9-12 years old, weekends. > Hosting their own site to support pictures of their pets is a very > common thing to want to do. To add to the Flask recommendation: I teach adults (mostly; one of my students is in high school) to use Python, SQLAlchemy, and Flask, putting together a classic dynamic web site model. (I also use Flask myself for a couple of sites, and I like it; but that recommendation is weak because I don't have much experience with *other* frameworks. So all it means is "Flask hasn't majorly annoyed me".) ChrisA From lac at openend.se Thu Nov 19 18:20:09 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 20 Nov 2015 00:20:09 +0100 Subject: Dabbling in web development In-Reply-To: References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> <201511192253.tAJMrinN031922@fido.openend.se> Message-ID: <201511192320.tAJNK92a001507@fido.openend.se> In a message of Fri, 20 Nov 2015 10:09:01 +1100, Chris Angelico writes: >On Fri, Nov 20, 2015 at 9:53 AM, Laura Creighton wrote: >> It is not the case that 'serious website developers use heavyweight >> systems like Django' --- lots and lots of serious developers use >> Flask or Bottle because Django makes you do it the Django way. >> Flask lets you do it however you like. Professionally, our company >> has designed a ton of websites and we use Flask nearly all of the >> time, and Pylons the rest of the time. If your brain is well-suited >> for Django, by all means use that, but if it is not, then do something >> else. >> >> I teach kids who are 9-12 years old, weekends. >> Hosting their own site to support pictures of their pets is a very >> common thing to want to do. > >To add to the Flask recommendation: I teach adults (mostly; one of my >students is in high school) to use Python, SQLAlchemy, and Flask, >putting together a classic dynamic web site model. (I also use Flask >myself for a couple of sites, and I like it; but that recommendation >is weak because I don't have much experience with *other* frameworks. >So all it means is "Flask hasn't majorly annoyed me".) > >ChrisA Well, I highly recommend Flask, but the tutorial was for a different microframework, 'Bottle'. At the time I first collected the kids, it was a better tutorial. Now, I suspect, there are lots of great ones for both of them. But for me, the effort of translating any tutorial into Swedish is huge. Especially since I need to take a reputation hit with every Swedish grammatical error my students find. :) The students of 3 years ago have fixed my Swedish problems, mostly, I think by now in this tutorial. Being able to speak Swedish colloquially and read it does not mean you can write or translate it well enough to get your product past the hyper-critical eyes of 11-year-olds who want evidence that this teacher, unlike so many others, can deliver the promised goods. :) Laura From lac at openend.se Thu Nov 19 18:28:30 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 20 Nov 2015 00:28:30 +0100 Subject: Dabbling in web development In-Reply-To: <8737w1eggj.fsf@elektro.pacujo.net> References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> <8737w1eggj.fsf@elektro.pacujo.net> Message-ID: <201511192328.tAJNSUjK002147@fido.openend.se> In a message of Fri, 20 Nov 2015 01:07:24 +0200, Marko Rauhamaa writes: >Laura Creighton : > >> There are lots of other choices than Django. >> >> see: https://wiki.python.org/moin/WebFrameworks/ > >However, are there any good web applications? I have seen some heroic >attempts but most fail miserably or at least have some annoying >glitches. > >The cardinal sin of web development seems to be micromanagement. Instead >of letting the web standards do their work, the application wants to be >in full control with JavaScript and XML HTTP requests. The results can >be awe-inspiring but at the same time fail at the basics. For example, >select/copy with the mouse might not work. Fonts might be garbled. Half >the page might be invisible and unscrollable. Or nothing will be >displayed at all. > > >Marko But you see that whether or not you use a Heavy framework like Django or a Microframework like Flask (which is all about how to serve such things up .... how you butcher the results is your own business.) Web design is a lot harder than most people who make webpages think. So what else is new? Laura From bc at freeuk.com Thu Nov 19 19:11:25 2015 From: bc at freeuk.com (BartC) Date: Fri, 20 Nov 2015 00:11:25 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/11/2015 22:55, Michael Torrie wrote: > On 11/19/2015 02:21 PM, BartC wrote: >> (Python returns 42; so that means my languages are more dynamic than >> Python? That's hard to believe!) > > It tells me your language does late binding for default arguments, which > does mean the default argument can dynamically change at call time, > which would surprise me if I didn't know about it. Either form of > binding is acceptable, and I don't think it makes a language more or > less dynamic. You get the expression that is specified, which can give different values at different times unless it involves only constants. It can't be exactly the same as writing an identical expression in place of the missing argument, as apparently different scopes come into play if names are involved. However I mainly use them for constant values. And [] is a constant value in my opinion. -- Bartc From steve at pearwood.info Thu Nov 19 19:26:54 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Nov 2015 11:26:54 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <564e68d0$0$1608$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 05:50 am, BartC wrote: > I said that Python's "=" does a very shallow copy. And I stated that in > A=B, something of B must be copied into A. > > I (and probably others) would like to know why none of that is correct. > But I suspect I'm not wrong. Nothing of B is copied. Here is a terrible ASCII art diagram of an object, floating in memory (most likely in the heap), an instant before the garbage collector can reach it and collect it: +----------------------+ | DEADBEEF0012345... | +----------------------+ (Best viewed in a monospaced font, like Courier.) The contents of the object are shown as a hex-dump, and will depend on the actual object and its value, but in general you would expect a field which acts as some sort of tag or pointer linking the instance to its parent class, plus other fields specifying the object's value and/or attributes. The internal details of the object don't matter, but basically objects are structs or records. Here is an ASCII art diagram of that same object, now bound to the name "B", preventing the GC from collecting it: +----------------------+ B------------->| DEADBEEF0012345... | +----------------------+ The name "B" may be on the heap, or in an array. It is possible that the human-readable string "B" itself no longer appears in memory. I don't care about the specific implementation, but for the record, in the case of CPython the name "B" is itself a string object in the heap, linked to from a specific associative array (hash table) also in the heap. (I think.) The link between the name B and the object ---> could be anything that allows the compiler/interpreter to associate one to the other. We call it a "reference". In CPython, references are pointers. If somebody were to write Python using FORTRAN 77, they would most likely use a big array to hold the objects, and use the index into the array as references. Other implementations may use other things, but for simplicity, let's just stick with calling it a pointer. Now let's do the assignment A = B: +----------------------+ B------------->| DEADBEEF0012345... | +->+----------------------+ | A-----------+ This adds a new reference (think: pointer) to the object, linked to the name "A". But **nothing of the object** is copied. The pointers to the object are not part of the object -- they are external to the object. If you want to talk about anything being copied, you should talk about *copying the reference* to B, not copying B. [Aside: there is some ambiguity here. If I say "a reference to B", I actually mean a reference to the object referenced to by B. I don't mean a reference to the *name* B. Python doesn't support that feature: names are not values in Python.] -- Steven From ned at nedbatchelder.com Thu Nov 19 19:27:57 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 19 Nov 2015 16:27:57 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> On Thursday, November 19, 2015 at 7:11:52 PM UTC-5, BartC wrote: > On 19/11/2015 22:55, Michael Torrie wrote: > > On 11/19/2015 02:21 PM, BartC wrote: > >> (Python returns 42; so that means my languages are more dynamic than > >> Python? That's hard to believe!) > > > > It tells me your language does late binding for default arguments, which > > does mean the default argument can dynamically change at call time, > > which would surprise me if I didn't know about it. Either form of > > binding is acceptable, and I don't think it makes a language more or > > less dynamic. > > You get the expression that is specified, which can give different > values at different times unless it involves only constants. > > It can't be exactly the same as writing an identical expression in place > of the missing argument, as apparently different scopes come into play > if names are involved. > > However I mainly use them for constant values. And [] is a constant > value in my opinion. > > -- > Bartc You are not alone in being surprised by how mutable default values work. It is a topic that comes up in every "What's Bad About Python" discussion, and is a common question from new users of the language. I can understand how you would view [] as a constant value. It's true that it is an expression that produces a consistent value each time it is evaluated. But that value is a list, and lists are mutable. The examples here all use the .append() method on that value, which changes it. Different languages work differently. In Python, a default value expression for a function argument is evaluated only once, when the function is defined. That value (in this case, the actual list) is stored with the function. The expression is not stored, the value of the expression is. That value (the actual list) is supplied as the value of the argument if no other value is supplied. If you modify that value in the function, the value is modified, and used again at the next function call. Again, we understand why you are surprised by this, many people are. You'll have to accept it, it's just the way Python works. There have been many discussions about alternatives, and they are considered to be either too complicated, or have other undesirable behavior, or both. --Ned. From steve at pearwood.info Thu Nov 19 19:33:36 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Nov 2015 11:33:36 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> Message-ID: <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 07:57 am, Marko Rauhamaa wrote: > Laura Creighton : > >> My experience says that the people who are confused want lists to >> behave like tuples. period. i.e. they don't want lists to be mutable. > > I think it's simpler than that. When you have: > > def f(x=[]): > y = [] > > the first [] is evaluated when "def" is executed, while the latter [] is > evaluated whenever "f" is executed. It's easy to be confused. It shouldn't be. The function declaration def f(x=[]): is executed only once. The function body, conveniently indented to make it stand out: y = [] is executed every time you call the function. [Aside: that nice clean design is somewhat muddied by docstrings. Despite being indented, docstrings are actually part of the declaration in the sense that they are handled only once, at function definition time.] -- Steven From ned at nedbatchelder.com Thu Nov 19 19:36:17 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 19 Nov 2015 16:36:17 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: <564e68d0$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e68d0$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, November 19, 2015 at 7:28:44 PM UTC-5, Steven D'Aprano wrote: > On Fri, 20 Nov 2015 05:50 am, BartC wrote: > > > > I said that Python's "=" does a very shallow copy. And I stated that in > > A=B, something of B must be copied into A. > > > > I (and probably others) would like to know why none of that is correct. > > But I suspect I'm not wrong. > > Nothing of B is copied. I think we are stuck in a simple terminology conflict here. There is something of B copied. The name B refers to a value. In CPython, that reference is a pointer. That pointer (the memory address) is copied from B to A. Nothing of "B's value", that is, the object B is referring to, is copied. But there is something about B (the pointer to its value) that is now also something about A, because A also has that pointer. --Ned. From ian.g.kelly at gmail.com Thu Nov 19 19:59:48 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Nov 2015 17:59:48 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <564e68d0$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e68d0$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 19, 2015 5:31 PM, "Steven D'Aprano" wrote: > > [Aside: there is some ambiguity here. If I say "a reference to B", I > actually mean a reference to the object referenced to by B. I don't mean a > reference to the *name* B. Python doesn't support that feature: names are > not values in Python.] Quoting BartC: """ if you write A=B then something of B needs to have been copied into A, even if it's just the reference that B contains. Otherwise it would be difficult to get A to refer to the same object as B. """ If you're trying to draw some distinction between what BartC wrote 17 posts back and what you wrote here, I'm not seeing it. From lac at openend.se Thu Nov 19 20:00:02 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 20 Nov 2015 02:00:02 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e68d0$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201511200100.tAK102lc008293@fido.openend.se> In a message of Thu, 19 Nov 2015 16:36:17 -0800, Ned Batchelder writes: >On Thursday, November 19, 2015 at 7:28:44 PM UTC-5, Steven D'Aprano wrote: >> On Fri, 20 Nov 2015 05:50 am, BartC wrote: >> >> >> > I said that Python's "=" does a very shallow copy. And I stated that in >> > A=B, something of B must be copied into A. >> > >> > I (and probably others) would like to know why none of that is correct. >> > But I suspect I'm not wrong. >> >> Nothing of B is copied. > >I think we are stuck in a simple terminology conflict here. There is something >of B copied. The name B refers to a value. In CPython, that reference is a >pointer. That pointer (the memory address) is copied from B to A. > >Nothing of "B's value", that is, the object B is referring to, is copied. But >there is something about B (the pointer to its value) that is now also something >about A, because A also has that pointer. > >--Ned. In PyPy we do this too. But we don't copy a memory-address pointer. We have a moving garbage collector, and no objects are in any way guaranteed to be at their last memory address. We copy a thing that, when you ask it nicely, spits out "where the hell is the object right now, because I want to modify it." But this thing is in no way tied to any particular place in any DRAM. It hits PyPy at an abstraction layer above that of 'we write 1s and 0s here' so if you want to implement python on a message passing system implemented by carrier pigeon, we could do this. It would be slow, however. :) Laura From steve at pearwood.info Thu Nov 19 20:05:55 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Nov 2015 12:05:55 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 04:30 am, BartC wrote: > On 19/11/2015 16:01, Steven D'Aprano wrote: [...] > The whole concept of 'mutable' default is alien to me. A default is just > a convenient device to avoid having to write: > > fn(0) or fn("") or fn([]) Says who? Here's another use for function defaults, as static storage: # Ackermann's function def ack(m, n, _memo={}): key = m, n if key not in _memo: if m==0: v = n + 1 elif n==0: v = ack(m-1, 1) else: v = ack(m-1, ack(m, n-1)) _memo[key] = v return _memo[key] This is a quick and easy way to memoise a function which would otherwise be horribly slow. And it only works because _memo is bound to a mutable object once, and once only. > You just write fn() instead. But it shouldn't come at the cost of > completely different semantics! Because then it can't really be called a > default value at all. But it doesn't come with completely different semantics. This is the stock standard semantics for assignment. Since we're not passing an argument, let's get rid of the argument altogether. If we put the assignment inside the body of the function, that code is executed every time the function is called. "arg" gets a brand new, empty list each time: def test(): arg = [] arg.append(1) return len(arg) If we put the assignment *outside* of the body of the function, that code is executed once only, and the same list is used over and over again: arg = [] def test(): arg.append(1) return len(arg) This is *exactly* the same semantics as for parameter defaults (except that they aren't stored as globals, but as hidden fields deep inside the function object itself). Now, look at the function declaration: def test(arg=[]): arg.append(1) return len(arg) The binding arg=[] is NOT inside the body of the function. Therefore, it is NOT executed repeatedly, but only once. > isn't surprising to >> somebody coming from a completely different paradigm. I was surprised by >> it too, the first time I got bitten. > > So you didn't bother reading the LRM either! LRM? Left Right Manual? No, I read it. I knew that the list was only created once. But like I said, I didn't follow the implications of that. If it is only created once, and you modify the value, the value will be modified. >> py> def demo_const(x, y=[]): >> ... return x + len(y) > >> Exactly as you should expect. Where you run into trouble is when the >> default value is NOT a constant: >> >> py> def demo_variable(x, y=[]): >> ... y.append(1) >> ... return x + len(y) > > Sorry, what is the default value in each of these? As the first lines of > the defintions look identical apart from the function names. The *value* is whatever contents the list holds. a = [] a.append(1) a.append(2) a.append(3) What's the value of a? Are you shocked and horrified to discover that the value of a is not the empty list, but the list [1, 2, 3]? >> py> demo_variable(5) >> 6 >> py> demo_variable(5) >> 7 >> py> demo_variable(5) >> 8 >> >> >> If you modify the value, the value will be modified. Why are you >> surprised by this? > > Which value is being modified? The []? The object bound to y is being modified. y.append(1) modifies the object bound to y. That object gets taken from the defaults if you don't supply a value yourself. That default object starts of life as an empty list, but it doesn't stay empty if you append to it. >>>> When you deal with mutable objects, you have to expect them to mutate. >>>> The whole point of mutability is that their value can change. >>> >>> That [] doesn't look like an object that could change. >> >> Of course it does. > > You've lost me know. > > Are you saying that: > > a=[] > > why sometimes not assign an empty list, because that [] could have been > modified? No. But [] is syntax for an empty list, and lists can change -- they are mutable. a = [] a.append(1) Are you shocked to learn that a is no longer an empty list? (I know I asked a similar question before, but this is an important point.) >> It is a list literal, like int literals, float literals, >> string literals and the rest. > > Another surprise? Literals by definition can't change: Says who? The existence of literal syntax is a feature of the programming language. The mutability of values is a *separate* feature. The two are unrelated. > def fn(): > a=[10,20,30] > a.append(999) > > I would hope that a is set to [10,20,30] at each entry to the function! Naturally. Each time you call the function, the body of the function executes and creates a new list. You take that list, and then modify it in the very next line with a.append(999). What happens if you only create the list *once*? a = [10,20,30] def fn(): a.append(999) print(a) Are you surprised that a doesn't get reset to [10, 20, 30] each time you call the function? >> Assignments are not copies at all. > > if you write A=B then something of B needs to have been copied into A, > even if it's just the reference that B contains. Otherwise it would be > difficult to get A to refer to the same object as B. B doesn't contain the reference to itself. The reference is external to B. Nothing of B is copied. -- Steven From wrw at mac.com Thu Nov 19 21:58:27 2015 From: wrw at mac.com (William Ray Wing) Date: Thu, 19 Nov 2015 21:58:27 -0500 Subject: Writing a Financial Services App in Python In-Reply-To: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> References: <6f4f4d39-d33b-46dd-bda7-afeb2f0dbef4@googlegroups.com> Message-ID: <60000857-0F97-4FF0-B093-DB3DDF7B0973@mac.com> > On Nov 19, 2015, at 6:59 AM, Cai Gengyang wrote: > > > From YCombinator's new RFS, This is the problem I want to solve as it is a severe problem I face myself and something I need. I want to write this app in Python as I heard that Python is a great language that many programmers use ... How / where do I start ? The problem is detailed below : > > FINANCIAL SERVICES > [Big edit] You might enjoy reading the note here: http://www.wsj.com/articles/an-algo-and-a-dream-for-day-traders-1439160100?mod=djem10point Which, among other things, points out that DIY algorithmic trading is the latest DIY craze. Bill From mscir at yahoo.com Thu Nov 19 22:09:03 2015 From: mscir at yahoo.com (Mike S) Date: Thu, 19 Nov 2015 19:09:03 -0800 Subject: how do I learn python ? In-Reply-To: References: Message-ID: On 11/19/2015 1:00 AM, Michiel Overtoom wrote: > >> On 18 Nov 2015, at 05:58, ??? wrote: >> (nothing) > > You might want to start at https://www.python.org/about/gettingstarted/ > > PS. Leaving the body of an email or usenet article empty is considered bad form. > > Greetings, Thanks for that, there is a great list of tutorials there! https://wiki.python.org/moin/BeginnersGuide/Programmers From mscir at yahoo.com Thu Nov 19 22:26:49 2015 From: mscir at yahoo.com (Mike S) Date: Thu, 19 Nov 2015 19:26:49 -0800 Subject: Why won't this run? In-Reply-To: References: Message-ID: On 11/15/2015 12:38 PM, jbak36 wrote: > Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> #this program says hello and asks for my name >>>> print:('Hello world!') > Hello world! >>>> print:('What is your name?') #ask for their name > What is your name? >>>> myName = input() > print:('It is good to meet you,'+myName) >>>> print:('The length of your name is:') > The length of your name is: >>>> print:(len(myName)) > 39 >>>> print:('What is your age?')#ask for their age > What is your age? >>>> myAge=input() > print:('You will be ' + str(int(myAge)+1)'in a year.') >>> print("Hello World") Hello World >>> myname=input("What is your name? ") What is your name? John >>> print ("Your name is ", myname) Your name is John ...you can find code samples in the *quick tutorial listed here: https://wiki.python.org/moin/BeginnersGuide/Programmers *http://hetland.org/writing/instant-python.html From vincent at vincentdavis.net Thu Nov 19 22:45:08 2015 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 19 Nov 2015 20:45:08 -0700 Subject: shorten "compress" long integer to short ascii. Message-ID: My goal is to shorten a long integer into a shorter set of characters. Below is what I have which gets me about a 45-50% reduction. Any suggestion on how to improve upon this? I not limited to ascii but I didn't see how going to utf8 would help. The resulting string needs to be something I could type/paste into twitter for example. On a side note string.punctuation contains "\\" what is \\ ? import string import random # Random int to shorten r = random.getrandbits(300) lenofr = len(str(r)) l = string.ascii_lowercase + string.ascii_uppercase + '!"#$%&\'()*+,-./:;<=>?@[]^_`{|}~' n = [str(x) for x in list(range(10,93))] decoderdict = dict(zip(l, n)) encoderdict = dict(zip(n, l)) def encoder(integer): s = str(integer) ls = len(s) p = 0 code = "" while p < ls: if s[p:p+2] in encoderdict.keys(): code = code + encoderdict[s[p:p+2]] p += 2 else: code = code + s[p] p += 1 return code def decoder(code): integer = "" for c in code: if c.isdigit(): integer = integer + c else: integer = integer + decoderdict[c] return int(integer) short = encoder(r) backagain = decoder(short) print(lenofr, len(short), len(short)/lenofr, r==backagain) From Seymore4Head at Hotmail.invalid Thu Nov 19 23:05:12 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Thu, 19 Nov 2015 23:05:12 -0500 Subject: Generate a random list of numbers Message-ID: Why does a work and b doesn't? What I was trying to accomplish with b is to get a random list (of random length) that could have digits repeat. I got idea for both methods from the Internet. I do see that one uses brackets and the other doesn't, but I don't know the difference. import random for i in range (5): a = random.sample(range(10), random.randrange(3,6)) print a for i in range (5): b = [random.randrange (10), random.randrange(4,8)] print b From no.email at nospam.invalid Thu Nov 19 23:27:07 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 19 Nov 2015 20:27:07 -0800 Subject: shorten "compress" long integer to short ascii. References: Message-ID: <871tbll2hw.fsf@nightsong.com> Vincent Davis writes: > My goal is to shorten a long integer into a shorter set of characters. > Below is what I have which gets me about a 45-50% reduction. Any suggestion > on how to improve upon this? You can't improve much. A decimal digit carries log(10,2)=3.32 bits of information. A reasonable character set for Twitter-style links might have 80 or so characters (upper/lower alphabetic, digits, and a dozen or so punctuation characters), or log(80,2)= > I not limited to ascii but I didn't see how going to utf8 would help. If you could use Unicode characters like Chinese ideographs, that gives you a much larger alphabet to work with, so you'd need fewer chars displayed in the link, but they'd be hard for most people to type. > l = string.ascii_lowercase + string.ascii_uppercase + > '!"#$%&\'()*+,-./:;<=>?@[]^_`{|}~' OK, 83 chars, but it may not be ok to use some of them like #, /, and ?, since they can have special meanings in urls. Your algorithm looks basically ok though I didn't examine it closely. Here is my shortened version: import string # alphabet here is 83 chars alphabet = string.ascii_lowercase + \ string.ascii_uppercase +'!"#$%&\'()*+,-./:;<=>?@[]^_`{|}~' alphabet_size = len(alphabet) decoderdict = dict((b,a) for a,b in enumerate(alphabet)) def encoder(integer): a,b = divmod(integer, alphabet_size) if a == 0: return alphabet[b] return encoder(a) + alphabet[b] def decoder(code): return reduce(lambda n,d: n*alphabet_size + decoderdict[d], code, 0) def test(): n = 92928729379271 short = encoder(n) backagain = decoder(short) nlen = len(str(n)) print (nlen, len(short), float(len(short))/nlen) assert n==backagain, (n,short,b) test() From steve at pearwood.info Thu Nov 19 23:38:36 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Nov 2015 15:38:36 +1100 Subject: Generate a random list of numbers References: Message-ID: <564ea3cd$0$1605$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 03:05 pm, Seymore4Head wrote: > Why does a work and b doesn't? What I was trying to accomplish with b > is to get a random list (of random length) that could have digits > repeat. > > I got idea for both methods from the Internet. I do see that one uses > brackets and the other doesn't, but I don't know the difference. > > import random > for i in range (5): > a = random.sample(range(10), random.randrange(3,6)) > print a Break it up, step by step. range(10) produces a list from 0 to 9. random.randrange(3, 6) produces a single integer from 3 to 5 (6 is excluded). Let's say by chance it produces the number 4. Then random.sample takes the list, and the integer 4, and selects 4 values at random from the list. Say, something like this: [8, 6, 7, 0] Note that random.sample does NOT repeat selections. The numbers will always be unique. > for i in range (5): > b = [random.randrange (10), random.randrange(4,8)] > print b As above, run through this step by step. random.randrange(10) produces a single number at random between 0 and 9 (10 is excluded). Let's say it picks 8. random.randrange(4,8) produces a single number at random between 4 and 7 (8 is excluded). Let's say it picks 5. Then b is set to the list [8, 5]. This list will always have two items. If you want a random number of digits that might repeat: [random.randrange(10) for i in range(random.randrange(1, 21))] will produce a random number between 1 and 20 (21 is excluded). Let's say it picks 6. then range(6) produces the list [0, 1, 2, 3, 4, 5], and "for i in range..." will iterate over those values. Although i is not used, this ends up looping 6 times. For each loop, random.randrange(10) produces a random digit between 0 and 9 (10 is excluded). So we end up with something like: [6, 4, 2, 2, 6, 9] for example. -- Steven From Seymore4Head at Hotmail.invalid Fri Nov 20 00:09:19 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 20 Nov 2015 00:09:19 -0500 Subject: Generate a random list of numbers References: <564ea3cd$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 20 Nov 2015 15:38:36 +1100, Steven D'Aprano wrote: >On Fri, 20 Nov 2015 03:05 pm, Seymore4Head wrote: > >> Why does a work and b doesn't? What I was trying to accomplish with b >> is to get a random list (of random length) that could have digits >> repeat. >> >> I got idea for both methods from the Internet. I do see that one uses >> brackets and the other doesn't, but I don't know the difference. >> >> import random >> for i in range (5): >> a = random.sample(range(10), random.randrange(3,6)) >> print a > >Break it up, step by step. > >range(10) produces a list from 0 to 9. random.randrange(3, 6) produces a >single integer from 3 to 5 (6 is excluded). Let's say by chance it produces >the number 4. > >Then random.sample takes the list, and the integer 4, and selects 4 values >at random from the list. Say, something like this: > >[8, 6, 7, 0] > >Note that random.sample does NOT repeat selections. The numbers will always >be unique. > > > >> for i in range (5): >> b = [random.randrange (10), random.randrange(4,8)] >> print b > >As above, run through this step by step. > >random.randrange(10) produces a single number at random between 0 and 9 (10 >is excluded). Let's say it picks 8. > >random.randrange(4,8) produces a single number at random between 4 and 7 (8 >is excluded). Let's say it picks 5. > >Then b is set to the list [8, 5]. > >This list will always have two items. > > > >If you want a random number of digits that might repeat: > >[random.randrange(10) for i in range(random.randrange(1, 21))] > >will produce a random number between 1 and 20 (21 is excluded). Let's say it >picks 6. > >then range(6) produces the list [0, 1, 2, 3, 4, 5], and "for i in range..." >will iterate over those values. Although i is not used, this ends up >looping 6 times. > >For each loop, random.randrange(10) produces a random digit between 0 and 9 >(10 is excluded). So we end up with something like: > >[6, 4, 2, 2, 6, 9] > >for example. That works. Thanks From robertvstepp at gmail.com Fri Nov 20 00:18:28 2015 From: robertvstepp at gmail.com (boB Stepp) Date: Thu, 19 Nov 2015 23:18:28 -0600 Subject: failing to run python on my pc In-Reply-To: References: Message-ID: On Thu, Nov 19, 2015 at 2:22 PM, Daniel Kasuza wrote: > Dear Sir/Madam > I am student with University of the people and a beginner in programming. > My problem is that l have down loaded python 2.7 but l am failing to muse > it. If l try to to use it, I am getting an option which say run. If l press > run, it just run and come back to the same option. I want to use it for > some practice but i am failing. Your question is rather vague and difficult to understand. Are you having difficulty in installing Python 2.7? If yes, what operating system are you using? Did your course or course text book give you instructions on what to do? If so, what steps did you accomplish successfully, and at what step did things stop working? Or do you have Python installed and then tried to run a program? What program and how did you try to run it? What were the precise results? You might want to redirect your question to Python Tutor with a much fuller description of what you tried and what happened: https://mail.python.org/mailman/listinfo/tutor This mailing list is targeted towards beginners in Python. They have been extremely helpful to me! But you will have to give much more detailed information before anyone will be able to assist you. Also, the main Python website has many resources, including tutorials as well as the full docs. Poke around at www.python.org . And don't forget to search the 'Net! Your exact problem has probably been encountered many times before ... -- boB From dieter at handshake.de Fri Nov 20 02:00:57 2015 From: dieter at handshake.de (dieter) Date: Fri, 20 Nov 2015 08:00:57 +0100 Subject: PubMed / Entrez References: <3p1Ylk6Wjgz5vMw@dovecot03.posteo.de> Message-ID: <87fv01noie.fsf@handshake.de> writes: > I am looking for a way to use the PubMed (medical research search > engine) API (aka Entrez) with Python3. I am using (on Python 2) "urllib" and "lxml" to interface with the NCBI E-utilities. From dieter at handshake.de Fri Nov 20 02:18:02 2015 From: dieter at handshake.de (dieter) Date: Fri, 20 Nov 2015 08:18:02 +0100 Subject: Why doesn't this method have access to its "self" argument? References: Message-ID: <87bnapnnpx.fsf@handshake.de> Robert Latest via Python-list writes: > I'm still trying to find a simple way to implement a method (but not the > full class) in C. Suggestions I have recived so far are good, but seem to be > over the top for such a (seemingly) simple problem. The C interface of Python is far from simple - and it is very easy to make severe and difficult to analyse errors. Therefore, I confirm an advice you already got: use "cython" (which drastically reduces the danger of errors). A "method" in Python is just a function which happens to get automatically on call an additional first arguemnt: the object's reference. Apparently, this automatism does not work for C implemented functions (at least in Python 2). You would need to use a (so called) "descriptor" wrapper to do this explicitely. The easiest way (in my view), however would be: import _my_c_implementation class C(object): def my_method(self, *args, **kw): return _my_c_implementation.my_method(self, *args, **kw) With a descriptor "method" (sketched above), this would become: class C(object): my_method = method(_my_c_implementation.my_method) From hkrss at gmail.com Fri Nov 20 02:43:04 2015 From: hkrss at gmail.com (HKRSS) Date: Fri, 20 Nov 2015 08:43:04 +0100 Subject: How To Create A Endles List Of Lists In Python...??? Message-ID: Thanks In Advance, Robert...;) From karthik.sharma at gmail.com Fri Nov 20 02:47:52 2015 From: karthik.sharma at gmail.com (Karthik Sharma) Date: Thu, 19 Nov 2015 23:47:52 -0800 (PST) Subject: Plotting a timeseris graph from pandas dataframe using matplotlib Message-ID: I have the following data in a csv file SourceID BSs hour Type 7208 87 11 MAIN 11060 67 11 MAIN 3737 88 11 MAIN 9683 69 11 MAIN 9276 88 11 MAIN 7754 62 11 MAIN 11111 80 12 MAIN 9276 88 12 MAIN 11111 80 12 MAIN 6148 70 12 MAIN 11111 80 12 MAIN 9866 80 12 SUB 9866 78 13 MAIN 9866 78 13 SUB 20729 82 14 MAIN 9276 88 14 MAIN 11111 80 15 MAIN 20190 55 15 MAIN 7208 85 15 MAIN 7208 86 15 MAIN 7754 61 16 MAIN 8968 91 16 MAIN 3737 88 16 MAIN 9683 69 16 MAIN 20729 81 16 MAIN 9704 68 16 MAIN 11111 87 16 PAN I have the following python code.I want to plot a graph with the following specifications. For each `SourceID` and `Type` I want to plot a graph of `BSs` over time. I would prefer if each `SourceID` and `Type` is a subplot on single plot.I have tried a lot of options using groupby, but can't seem to get it work. import numpy as np import pandas as pd import matplotlib.pyplot as plt COLLECTION = 'NEW' DATA = r'C:\Analysis\Test\{}'.format(COLLECTION) INPUT_FILE = DATA + r'\in.csv' OUTPUT_FILE = DATA + r'\out.csv' with open(INPUT_FILE) as fin: df = pd.read_csv(INPUT_FILE, usecols=["SourceID", 'hour','BSs','Type'], header=0) df.drop_duplicates(inplace=True) df.reset_index(inplace=True) From dieter at handshake.de Fri Nov 20 02:49:12 2015 From: dieter at handshake.de (dieter) Date: Fri, 20 Nov 2015 08:49:12 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: Message-ID: <877fldnm9z.fsf@handshake.de> Chris Angelico writes: > On Fri, Nov 20, 2015 at 5:42 AM, Ian Kelly wrote: >> BartC on the other hand is just complaining about an aspect of Python >> that is legitimately controversial. > > IMO it's controversial mainly because there's an easy and obvious > syntax for early binding, but late binding doesn't have syntactic > support, and all the options are imperfect. I do not think that we should get additional syntax for lately bound default values. It would explicitely introduce the concepts early versus late binding which are likely difficult to understand by many users. In addition, the last few days have had two discussions in this list demonstrating the conceptial difficulties of late binding -- one of them: Why does "[lambda x: i * x for i in range(4)]" gives a list of essentially the same functions? Note as well, that it is difficult to define what "late binding" should mean in non-trivial cases: def f(..., a=) If "a" is lately bound, when are bound the variables involved in its defining expression? If they are early bound, you get the same effect as with realy bound default parameters: calling the function can change non local objects which may lead to surprises. If they are lately bound, the references may no longer be resolvable or (worse) may resolve to unexpected objects. If you need late binding, you might use something like this: class Late(object): def __init__(self, obj): self.obj = obj def bind: from copy import deepcopy return deepcopy(obj) def __repr__: ... def f(..., a=Late()): ... a = a.bind() ... Of course, you could define a decorator which performs the "bind" calls automatically. From hkrss at gmail.com Fri Nov 20 03:13:38 2015 From: hkrss at gmail.com (HKRSS) Date: Fri, 20 Nov 2015 09:13:38 +0100 Subject: How To Create A Endles List Of Lists In Python...??? References: Message-ID: I Think That There Are Two Ways: 1)Harder Way Use Procedural C... 2)Easier Way Use LISP... "HKRSS" wrote in message news:n2miu8$fl4$1 at ls237.t-com.hr... > Thanks In Advance, Robert...;) > > From eryksun at gmail.com Fri Nov 20 03:43:13 2015 From: eryksun at gmail.com (eryksun) Date: Fri, 20 Nov 2015 02:43:13 -0600 Subject: non-blocking getkey? In-Reply-To: <564DF94E.8020302@gmail.com> References: <564DF94E.8020302@gmail.com> Message-ID: On Thu, Nov 19, 2015 at 10:31 AM, Michael Torrie wrote: > One windows it might be possible to use the win32 api to enumerate the > windows, find your console window and switch to it. You can call GetConsoleWindow [1] and then SetForegroundWindow [2]. import os import sys try: import tkinter from tkinter import filedialog except ImportError: import Tkinter as tkinter import tkFileDialog as filedialog input = raw_input if sys.platform == 'win32': import ctypes kernel32 = ctypes.WinDLL('kernel32') user32 = ctypes.WinDLL('user32') def setfgwin(): hcon = kernel32.GetConsoleWindow() if hcon and user32.SetForegroundWindow(hcon): return True return False def get_filename(): filename = filedialog.askopenfilename() setfgwin() return os.path.normpath(filename) if __name__ == '__main__': root = tkinter.Tk() root.withdraw() filename = get_filename() print('filename: %s' % filename) input('press enter...') [1]: https://msdn.microsoft.com/en-us/library/ms683175 [2]: https://msdn.microsoft.com/en-us/library/ms633539 From harvesting at is.invalid Fri Nov 20 03:49:21 2015 From: harvesting at is.invalid (Jussi Piitulainen) Date: Fri, 20 Nov 2015 10:49:21 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: Message-ID: dieter writes: > Chris Angelico writes: > >> IMO it's controversial mainly because there's an easy and obvious >> syntax for early binding, but late binding doesn't have syntactic >> support, and all the options are imperfect. > > I do not think that we should get additional syntax for lately bound > default values. It would explicitely introduce the concepts early > versus late binding which are likely difficult to understand by many > users. I'm confused by the term. I don't like it one bit. "Early binding" of a default value seems to mean that the expression that produces the default value of a function parameter is evaluated when the function is defined. "Late binding" seems to mean that the expression is evaluated when the function is called. In both cases the actual binding of the parameter to the value (either the default or an actual argument) is established when the function is called. Several different bindings of that same parameter to different values can hold simultaneously, so the *binding* has to be conceptually "late". Because recursion. Why isn't the evaluation of the default expression called evaluation? Or at least something that doesn't already mean something else that is as crucially important as, well, I've already given up on talking about REDACTED and REDACTED in connection with Python, and here I see related established terminology used for something else *for no reason that I can see*. I see no *need* to call this other thing "binding". From __peter__ at web.de Fri Nov 20 03:53:06 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 Nov 2015 09:53:06 +0100 Subject: How To Create A Endles List Of Lists In Python...??? References: Message-ID: HKRSS wrote: > Thanks In Advance, Robert...;) >>> list_of_lists = [] >>> list_of_lists.append(list_of_lists) >>> list_of_lists[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] [[...]] From steephenmyroz at gmail.com Fri Nov 20 04:52:53 2015 From: steephenmyroz at gmail.com (marozzyye) Date: Fri, 20 Nov 2015 10:52:53 +0100 Subject: download Message-ID: <9gn0ssui8hfaavc4qw2b9x2b.1448013173332@email.android.com> i am about to download python 3.5.0 but there are three options 1.windows x86 web-based installer 2.windows x86 executable installer 3.windows x86 embeddable zip file i have tried no.1 but while installing there was an error. so which do i pick? From hkrss at gmail.com Fri Nov 20 06:00:27 2015 From: hkrss at gmail.com (HKRSS) Date: Fri, 20 Nov 2015 12:00:27 +0100 Subject: How To Create A Endles List Of Lists In Python...??? References: Message-ID: "Peter Otten" <__peter__ at web.de> wrote in message news:mailman.510.1448009596.16136.python-list at python.org... > HKRSS wrote: > >> Thanks In Advance, Robert...;) > >>>> list_of_lists = [] >>>> list_of_lists.append(list_of_lists) >>>> list_of_lists[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] > [[...]] > Sorry For Bad Question, But I need List Of Lists That I Can Acces Horyzontaly, Not In The Deep(But This IS Not All, I End That Evey List In List Of Lists Can Be A List... Thanks In Advance... Robert..;) From bc at freeuk.com Fri Nov 20 06:59:20 2015 From: bc at freeuk.com (BartC) Date: Fri, 20 Nov 2015 11:59:20 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20/11/2015 01:05, Steven D'Aprano wrote: > On Fri, 20 Nov 2015 04:30 am, BartC wrote: > >> On 19/11/2015 16:01, Steven D'Aprano wrote: > [...] > >> The whole concept of 'mutable' default is alien to me. A default is just >> a convenient device to avoid having to write: >> >> fn(0) or fn("") or fn([]) > > Says who? People who want to avoid having to write: fn(0) or fn("") or fn([]) > Here's another use for function defaults, as static storage: > > > # Ackermann's function > def ack(m, n, _memo={}): > key = m, n > if key not in _memo: > if m==0: v = n + 1 > elif n==0: v = ack(m-1, 1) > else: v = ack(m-1, ack(m, n-1)) > _memo[key] = v > return _memo[key] > > > This is a quick and easy way to memoise a function which would otherwise be > horribly slow. And it only works because _memo is bound to a mutable object > once, and once only. We're arguing at cross-purposes then since you are obviously interested in these esoteric aspects, but all I want to do is avoid remembering a long list of defaults. Here's an example from another language, a function I'm working on at the minute: function asklist(caption,&data,n=1, rows=10, width=50, flags="", buttons=(), tablist=(), heading="")= 9 parameters, 7 of them optional. This is designed to be used with keyword arguments which is where the default values come into their own, as you don't need to remember positional order either. Very basic stuff and very obvious what it's for. Notice some defaults are () (empty lists here), which are the ones that cause bother in Python. (Here, however, the language doesn't like you doing in-place modification of a parameter unless the '&' is used, in which case you wouldn't be able to assign a default value such as () as you can only pass l-values.) > def test(arg=[]): > arg.append(1) > return len(arg) > > > The binding arg=[] is NOT inside the body of the function. Therefore, it is > NOT executed repeatedly, but only once. OK, so the "=" is misleading if not a lie. >> So you didn't bother reading the LRM either! > > LRM? Left Right Manual? Language Reference Manual. >>>> That [] doesn't look like an object that could change. >>> >>> Of course it does. >> >> You've lost me know. > a = [] > a.append(1) > > Are you shocked to learn that a is no longer an empty list? No. But I would be surprised if, after this point, [] is no longer an empty list either! No, forget that; by now, I wouldn't be surprised at all! (That [] isn't changed is probably thanks to [] being implemented with the BUILD_LIST byte-code, which constructs a brand-new empty list each time. So the next time [] is used, it will be a different one from the one that has just been appended to. In my language, a construct such as [10,20,30] is evaluated just once at start-up. If Python did the same, then I suspect such a literal could conceivably be changed if just "=" was used to ______[1] it to 'a'.) ([1] To avoid further argument, insert your own choice of jargon here.) -- Bartc From ned at nedbatchelder.com Fri Nov 20 07:12:47 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 20 Nov 2015 04:12:47 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, November 20, 2015 at 6:59:54 AM UTC-5, BartC wrote: > On 20/11/2015 01:05, Steven D'Aprano wrote: > > On Fri, 20 Nov 2015 04:30 am, BartC wrote: > > > >> On 19/11/2015 16:01, Steven D'Aprano wrote: > > [...] > > > >> The whole concept of 'mutable' default is alien to me. A default is just > >> a convenient device to avoid having to write: > >> > >> fn(0) or fn("") or fn([]) > > > > Says who? > > People who want to avoid having to write: > > fn(0) or fn("") or fn([]) I think we all understand by now that you are unhappy with what happens in Python with mutable defaults. We get it. You are not alone. Lots of people are surprised by this. But it is how Python works. I'm not sure what your goal is at this point. Are you: 1) still unsure what the behavior is, or 2) trying to understand why it behaves that way, or 3) hoping to change Python, or 4) trying to convince us that your language is better, or 5) something else? --Ned. From marko at pacujo.net Fri Nov 20 07:28:17 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 20 Nov 2015 14:28:17 +0200 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877flcrh26.fsf@elektro.pacujo.net> BartC : > On 20/11/2015 01:05, Steven D'Aprano wrote: >> On Fri, 20 Nov 2015 04:30 am, BartC wrote: >>> The whole concept of 'mutable' default is alien to me. A default is just >>> a convenient device to avoid having to write: >>> >>> fn(0) or fn("") or fn([]) >> >> Says who? > > People who want to avoid having to write: > > fn(0) or fn("") or fn([]) Undoubtedly a mutable default value can lead to accidents. However, I already showed C++ default values can also be mutable and lead to analogous problems, so the question is not related to Python alone. If there is a risk of a default [] or {} ending up in the wrong hands, you can always write your function with a sentinel: omitted = object() def f(collection=omitted): if collection is omitted: collection = [] ... > We're arguing at cross-purposes then since you are obviously > interested in these esoteric aspects, The Ackermann function really is an esoteric example, but the other example that has been discussed here can make practical use of the default-value semantics: [ lambda x: i * x for i in range(4) ] which is salvaged with a default value: [ lambda x, i=i: i * x for i in range(4) ] or, more hygienically: [ (lambda i=i: lambda x: i * x)() for i in range(4) ] Even more appropriately, you may expressly want a mutable, singleton object to be the default: def initiate_query(query, database=global_database): > but all I want to do is avoid remembering a long list of defaults. > Here's an example from another language, a function I'm working on at > the minute: > > function asklist(caption,&data,n=1, rows=10, width=50, flags="", > buttons=(), tablist=(), heading="")= One could argue that you should always use a sentinel object for default values. That also allows you to distinguish between omitted values and default values: def asklist(caption, data, n=omitted, rows=omitted, width=omitted, flags=omitted, buttons=omitted, tablist=omitted, heading=omitted): but that would be rather pedantic in most circumstances. Marko From bc at freeuk.com Fri Nov 20 07:39:58 2015 From: bc at freeuk.com (BartC) Date: Fri, 20 Nov 2015 12:39:58 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20/11/2015 12:12, Ned Batchelder wrote: > On Friday, November 20, 2015 at 6:59:54 AM UTC-5, BartC wrote: >> On 20/11/2015 01:05, Steven D'Aprano wrote: >>> On Fri, 20 Nov 2015 04:30 am, BartC wrote: >>> >>>> On 19/11/2015 16:01, Steven D'Aprano wrote: >>> [...] >>> >>>> The whole concept of 'mutable' default is alien to me. A default is just >>>> a convenient device to avoid having to write: >>>> >>>> fn(0) or fn("") or fn([]) >>> >>> Says who? >> >> People who want to avoid having to write: >> >> fn(0) or fn("") or fn([]) > > I think we all understand by now that you are unhappy with what happens > in Python with mutable defaults. We get it. You are not alone. Lots of > people are surprised by this. But it is how Python works. > > I'm not sure what your goal is at this point. Are you: > > 1) still unsure what the behavior is, or > 2) trying to understand why it behaves that way, or > 3) hoping to change Python, or > 4) trying to convince us that your language is better, or > 5) something else? Mostly 5. (With a bit of 4. However that language is not something I'm selling or pushing. It's just something different used as a contrast.). What's bothering me is: * The large amount of mumbo-jumbo used to describe what's going on * The insistence (I think largely from Steven) that the way this feature works is good rather than bad * The refusal to acknowledge that the def fn(a=[]) syntax is misleading. (What value will a have when you call fn()? The true answer is that you can't tell.) * The persistent nonsense that somehow [] is mutable (what happens is that [] is assigned to a variable, and /that/ is mutable) (And I will probably get some flak now because 'assign' and 'variable' are meaningless in Python!) * And above, where I lay out /why/ people want to use the feature, so that the function can take care of some details, even that is refuted. -- Bartc From bc at freeuk.com Fri Nov 20 07:53:00 2015 From: bc at freeuk.com (BartC) Date: Fri, 20 Nov 2015 12:53:00 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <877flcrh26.fsf@elektro.pacujo.net> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: On 20/11/2015 12:28, Marko Rauhamaa wrote: > BartC : >> We're arguing at cross-purposes then since you are obviously >> interested in these esoteric aspects, > > The Ackermann function really is an esoteric example, but the other > example that has been discussed here can make practical use of the > default-value semantics: And you go on to give a couple of slightly less esoteric examples! (I don't think I've ever written a lambda function in my life.) > Even more appropriately, you may expressly want a mutable, singleton > object to be the default: > > def initiate_query(query, database=global_database): Finally, a down-to-earth example. Here it probably doesn't matter at what point 'global_database' gets bound. You know it will always refer to the current state of global_database, and you know that it is a data structure external to the function even if it is updated from inside. That is a bit different from an empty list that later is not empty. > def asklist(caption, data, n=omitted, rows=omitted, width=omitted, > flags=omitted, buttons=omitted, tablist=omitted, > heading=omitted): > > but that would be rather pedantic in most circumstances. Yes, that's along the lines of what I used do before I had proper default values! Then I had code inside the function to test a parameter and set it as needed. I still do this when the default isn't straightforward (where it depends on other parameters for example). -- Bartc From rosuav at gmail.com Fri Nov 20 08:04:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 00:04:03 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 11:39 PM, BartC wrote: > * The refusal to acknowledge that the def fn(a=[]) syntax is misleading. > (What value will a have when you call fn()? The true answer is that you > can't tell.) It isn't misleading. The default value for the argument is set when the function is defined, and it is set to the *object* that results from evaluating the *expression* given. After that, the *object* is the one you will always get (barring shenanigans) if the argument is omitted. If the value of that object changes, it changes! You keep expecting the *value* to be consistent. But what you actually get is that the *object* is consistent. It's virtually impossible to guarantee the former, in the face of mutable objects. > * The persistent nonsense that somehow [] is mutable (what happens is that > [] is assigned to a variable, and /that/ is mutable) (And I will probably > get some flak now because 'assign' and 'variable' are meaningless in > Python!) What happens is that [] evaluates to an object, and *that object* is mutable. Python does not store the syntactic element "[]" (empty list-display), but instead stores (a reference to) the object. It's exactly the same as: def fn(a=list()): ... def generate_list(): return [] def fn(a=generate_list()): ... initial_list = [] def fn(a=initial_list): ... import sys def fn(a=[x*3+424 for x in range(not sys)]): """how ridiculous would you like to go?""" Every one of these constructs exactly one new list, *when it is evaluated*, which is at function definition time. ChrisA From gandalf at shopzeus.com Fri Nov 20 08:06:08 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 20 Nov 2015 14:06:08 +0100 Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: Message-ID: <564F1AC0.5040106@shopzeus.com> > Sorry For Bad Question, But I need List Of Lists That I Can > Acces Horyzontaly, Not In The Deep(But This IS Not All, > I End That Evey List In List Of Lists Can Be A List... It is not possible to do it with a native list. But you can write your own iterable that can be iterated forever, and indexed with an integer. But before you do that: what is this needed for? From rosuav at gmail.com Fri Nov 20 08:09:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 00:09:05 +1100 Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: <564F1AC0.5040106@shopzeus.com> References: <564F1AC0.5040106@shopzeus.com> Message-ID: On Sat, Nov 21, 2015 at 12:06 AM, Nagy L?szl? Zsolt wrote: >> Sorry For Bad Question, But I need List Of Lists That I Can >> Acces Horyzontaly, Not In The Deep(But This IS Not All, >> I End That Evey List In List Of Lists Can Be A List... > It is not possible to do it with a native list. But you can write your > own iterable that can be iterated forever, and indexed with an integer. > > But before you do that: what is this needed for? My crystal ball suggests that defaultdict(list) might be useful here. ChrisA From robert.bralic at si.t-com.hr Fri Nov 20 08:29:35 2015 From: robert.bralic at si.t-com.hr (robert.bralic at si.t-com.hr) Date: Fri, 20 Nov 2015 05:29:35 -0800 (PST) Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: Message-ID: <9129317f-5f24-4e28-96de-8567e2d7afe8@googlegroups.com> Dana petak, 20. studenoga 2015. u 14:06:31 UTC+1, korisnik Nagy L?szl? Zsolt napisao je: > > Sorry For Bad Question, But I need List Of Lists That I Can > > Acces Horyzontaly, Not In The Deep(But This IS Not All, > > I End That Evey List In List Of Lists Can Be A List... > It is not possible to do it with a native list. But you can write your > own iterable that can be iterated forever, and indexed with an integer. > > But before you do that: what is this needed for? To Make A Turing Machine That Accepts A Classes.... (This Is My Idea, And Must Be Published By Me, And I Don't Respond How I Think Make This Machine)... Thanks, Robert...;) From ned at nedbatchelder.com Fri Nov 20 08:30:21 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 20 Nov 2015 05:30:21 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <67bccb9f-6b2f-4ffb-a0e5-71c32587eeb7@googlegroups.com> On Friday, November 20, 2015 at 7:40:37 AM UTC-5, BartC wrote: > On 20/11/2015 12:12, Ned Batchelder wrote: > > On Friday, November 20, 2015 at 6:59:54 AM UTC-5, BartC wrote: > >> On 20/11/2015 01:05, Steven D'Aprano wrote: > >>> On Fri, 20 Nov 2015 04:30 am, BartC wrote: > >>> > >>>> On 19/11/2015 16:01, Steven D'Aprano wrote: > >>> [...] > >>> > >>>> The whole concept of 'mutable' default is alien to me. A default is just > >>>> a convenient device to avoid having to write: > >>>> > >>>> fn(0) or fn("") or fn([]) > >>> > >>> Says who? > >> > >> People who want to avoid having to write: > >> > >> fn(0) or fn("") or fn([]) > > > > I think we all understand by now that you are unhappy with what happens > > in Python with mutable defaults. We get it. You are not alone. Lots of > > people are surprised by this. But it is how Python works. > > > > I'm not sure what your goal is at this point. Are you: > > > > 1) still unsure what the behavior is, or > > 2) trying to understand why it behaves that way, or > > 3) hoping to change Python, or > > 4) trying to convince us that your language is better, or > > 5) something else? > > Mostly 5. (With a bit of 4. However that language is not something I'm > selling or pushing. It's just something different used as a contrast.). > > What's bothering me is: Let me try to answer some of these. > > * The large amount of mumbo-jumbo used to describe what's going on We try not to use mumbo-jumbo, we use terms that can be confusing sometimes. This page was recommended early on in this thread: http://nedbatchelder.com/text/names1.html It is my best attempt to lay out many of the issues here. I hope you have had a chance to read/watch it. > * The insistence (I think largely from Steven) that the way this feature > works is good rather than bad I think the fairest summary is that the way this works is better than the alternatives, when you take into account the desire to keep the semantics of the language simple. > * The refusal to acknowledge that the def fn(a=[]) syntax is misleading. > (What value will a have when you call fn()? The true answer is that you > can't tell.) I completely agree with you that the syntax surprises people. Anyone who claims that it isn't surprising is ignoring the abundant empirical evidence that people new to Python (and even some who have been using it for a long time) are surprised by this. But it is not true that "you can't tell" what value a will have. You have been surprised by it, but I am confident that if we could sit together, I could explain to you what value you would get, and it would be clear to you. You might not like the answer, and it might not be what you first imagined, but it is not unpredictable. > * The persistent nonsense that somehow [] is mutable (what happens is > that [] is assigned to a variable, and /that/ is mutable) (And I will > probably get some flak now because 'assign' and 'variable' are > meaningless in Python!) As others have explained, [] is a value, a list. Lists are mutable. a = [] # Create an empty list a.append(1) # and mutate that list. If we don't agree on this, then please please please go and look at the page I linked above. This is a central concept in Python, and we aren't going to be able to get anywhere if we can't agree on this. > * And above, where I lay out /why/ people want to use the feature, so > that the function can take care of some details, even that is refuted. I understand why you want to use the feature. It would be nice if it came out the way you (and many others) want. But it doesn't. --Ned. From bc at freeuk.com Fri Nov 20 09:00:13 2015 From: bc at freeuk.com (BartC) Date: Fri, 20 Nov 2015 14:00:13 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> Message-ID: On 19/11/2015 22:41, Laura Creighton wrote: > In a message of Thu, 19 Nov 2015 22:57:10 +0200, Marko Rauhamaa writes: > Note: Ned Bachelder (who is probably reading this on python-list > anyway added cc on this mail, as if I am to discuss somebody, however > briefly, they deserve to hear about it. Which may irritate him to > get 2 copies instead of one, but so it goes. I am talking about > BartC as well, but since this is his thread, I assume he is here.) Actually that thread was started by 'fl'. > Sometimes you want to understand what you are doing. Sometimes > you just want to do it. And sometimes, well, the only real way > to get an understanding of what you are doing is to do it more. > This is, in my opinion, Bartc's problem. He doesn't program in > python enough to understand it more. That's true. I'll have to do a substantial project soon. But a lot of my interest is about comparisons between Python and the languages I work on. (Especially of speed. Up to now my interpreters have been comfortably faster. But with PyPy I might now have do do a bit more work on mine next year. This is where a proper application is needed for comparison and not small benchmarks.) I'm also interested in what handy features I can 'borrow' from Python. Enough that I was planning a big upgrade earlier this year to bring it more into line with how Python works. (/That/ is a good way of learning about a language! To try and implement a lookalike.) But that was changing my language too much (I was losing too many features of my own) so it was abandoned. (Perhaps it can be a separate, higher level language at some point as I quite like the Python style even if I have misgivings about some features.) > They have the opposite problem of BartC -- they want to be excellent > programmers without understanding anything, while he wants to > understand everything before he knows how to write decent python code. I can already tell you that I will never be able to write 'Pythonic' code if that is what you mean by 'decent'. But at least everyone will be able to understand it! -- Bartc From vincent at vincentdavis.net Fri Nov 20 09:18:55 2015 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 20 Nov 2015 07:18:55 -0700 Subject: shorten "compress" long integer to short ascii. In-Reply-To: <871tbll2hw.fsf@nightsong.com> References: <871tbll2hw.fsf@nightsong.com> Message-ID: On Thu, Nov 19, 2015 at 9:27 PM, Paul Rubin wrote: > You can't improve much. A decimal digit carries log(10,2)=3.32 bits > of information. A reasonable character set for Twitter-style links > might have 80 or so characters (upper/lower alphabetic, digits, and > a dozen or so punctuation characters), or log(80,2)= > ?Where do I find out more about the how to calculate information per digit? ? Lots of nice little tricks you used below. Thanks for sharing. > Here is my shortened version: > > import string > > # alphabet here is 83 chars > alphabet = string.ascii_lowercase + \ > string.ascii_uppercase +'!"#$%&\'()*+,-./:;<=>?@[]^_`{|}~' > alphabet_size = len(alphabet) > > decoderdict = dict((b,a) for a,b in enumerate(alphabet)) > > def encoder(integer): > a,b = divmod(integer, alphabet_size) > if a == 0: return alphabet[b] > return encoder(a) + alphabet[b] > > def decoder(code): > return reduce(lambda n,d: n*alphabet_size + decoderdict[d], code, 0) > > def test(): > n = 92928729379271 > short = encoder(n) > backagain = decoder(short) > nlen = len(str(n)) > print (nlen, len(short), float(len(short))/nlen) > assert n==backagain, (n,short,b) > > test() > Vincent Davis 720-301-3003 From breamoreboy at yahoo.co.uk Fri Nov 20 09:31:18 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 20 Nov 2015 14:31:18 +0000 Subject: download In-Reply-To: References: <9gn0ssui8hfaavc4qw2b9x2b.1448013173332@email.android.com> Message-ID: On 20/11/2015 13:48, Dennis Lee Bieber wrote: > On Fri, 20 Nov 2015 10:52:53 +0100, marozzyye > declaimed the following: > >> i am about to download python 3.5.0 but there are three options >> 1.windows x86 web-based installer >> 2.windows x86 executable installer >> 3.windows x86 embeddable zip file >> i have tried no.1 but while installing there was an error. so which do i pick? > > A) If you are running Windows XP, NONE OF THE ABOVE. 3.5 does not run > on WinXP > > B) What site is offering those? I just went to python.org, and the 3.5 > download button (just the one -- no options for type of file) only provides > a downloadable EXE installer (note: I normally use the ActiveState > installers rather than python.org) > Compare https://www.python.org/downloads/ which I believe is being referred to above, to https://www.python.org/ and hover your mouse over "downloads" and then "Python 3.5.0", this offers a web install exe, to https://www.python.org/downloads/windows/ which offers everything including the kitchen sink. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From random832 at fastmail.com Fri Nov 20 09:32:51 2015 From: random832 at fastmail.com (Random832) Date: Fri, 20 Nov 2015 14:32:51 +0000 (UTC) Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <9v7u4b1i0433efj1ineabik9p0e4ke0qop@4ax.com> Message-ID: On 2015-11-20, Dennis Lee Bieber wrote: > You can substitute list() where ever you use [] with no > effective change in the semantics. (I wouldn't be surprised if the parser > was doing that behind the scenes anyway). No, because list() does a name lookup on "list" (which is the primary issue behind every request for frozendict/frozenset literals) From random832 at fastmail.com Fri Nov 20 09:35:33 2015 From: random832 at fastmail.com (Random832) Date: Fri, 20 Nov 2015 14:35:33 +0000 (UTC) Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: On 2015-11-20, BartC wrote: > Finally, a down-to-earth example. Here it probably doesn't matter at > what point 'global_database' gets bound. You know it will always refer > to the current state of global_database, and you know that it is a data > structure external to the function even if it is updated from inside. > > That is a bit different from an empty list that later is not empty. Why is it different? The only difference is that you're thinking of it as "this particular database" rather than "a database containing this particular data", but I'd argue you can say the same for the list. From airween at gmail.com Fri Nov 20 09:52:27 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Fri, 20 Nov 2015 15:52:27 +0100 Subject: String format - resolve placeholders names Message-ID: <20151120145227.GB13994@arxnet.hu> Hi, Python has a good string formatter, eg. I can do this: s = "{who} likes {what}" d = {'who': "Adam", 'what': "ants"} s.format(**d) result: 'Adam likes ants' Is it possible, and if yes, how to resolve the placeholders names in string? There is a know method: d1 = {'who1': "Adam", 'what1': "ants"} try: s.format(**d1) except KeyError: print("keyword missing") (gives 'keyword missing' as result). But is there any other (direct) way, which keywords exists in string? Thanks, a. From rosuav at gmail.com Fri Nov 20 10:06:11 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 02:06:11 +1100 Subject: String format - resolve placeholders names In-Reply-To: <20151120145227.GB13994@arxnet.hu> References: <20151120145227.GB13994@arxnet.hu> Message-ID: On Sat, Nov 21, 2015 at 1:52 AM, Ervin Heged?s wrote: > Python has a good string formatter, eg. I can do this: > > s = "{who} likes {what}" > d = {'who': "Adam", 'what': "ants"} > s.format(**d) > > result: > 'Adam likes ants' > > Is it possible, and if yes, how to resolve the placeholders names > in string? > > There is a know method: > > d1 = {'who1': "Adam", 'what1': "ants"} > try: > s.format(**d1) > except KeyError: > print("keyword missing") > > (gives 'keyword missing' as result). > > > But is there any other (direct) way, which keywords exists in > string? I think what you're asking for can be done using format_map with a custom mapping object: >>> class IdentiMap: ... def __init__(self): ... self.keys = [] ... def __getitem__(self, key): ... self.keys.append(key) ... >>> m = IdentiMap() >>> "{who} likes {what}".format_map(m) 'None likes None' >>> m.keys ['who', 'what'] Does that help? ChrisA From airween at gmail.com Fri Nov 20 10:53:00 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Fri, 20 Nov 2015 16:53:00 +0100 Subject: String format - resolve placeholders names In-Reply-To: References: <20151120145227.GB13994@arxnet.hu> Message-ID: <20151120155300.GB14645@arxnet.hu> Hello Chris, On Sat, Nov 21, 2015 at 02:06:11AM +1100, Chris Angelico wrote: > On Sat, Nov 21, 2015 at 1:52 AM, Ervin Heged?s wrote: > > Python has a good string formatter, eg. I can do this: > > > > s = "{who} likes {what}" > > d = {'who': "Adam", 'what': "ants"} > > s.format(**d) ... > > But is there any other (direct) way, which keywords exists in > > string? > > I think what you're asking for can be done using format_map with a > custom mapping object: > > >>> class IdentiMap: > ... def __init__(self): > ... self.keys = [] > ... def __getitem__(self, key): > ... self.keys.append(key) > ... > >>> m = IdentiMap() > >>> "{who} likes {what}".format_map(m) > 'None likes None' > >>> m.keys > ['who', 'what'] > > Does that help? absolutely, many thanks again! a. From __peter__ at web.de Fri Nov 20 10:53:47 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 Nov 2015 16:53:47 +0100 Subject: String format - resolve placeholders names References: <20151120145227.GB13994@arxnet.hu> Message-ID: Ervin Heged?s wrote: > Python has a good string formatter, eg. I can do this: > > s = "{who} likes {what}" > d = {'who': "Adam", 'what': "ants"} > s.format(**d) > > result: > 'Adam likes ants' > > Is it possible, and if yes, how to resolve the placeholders names > in string? >>> import string >>> for item in string.Formatter().parse("{who} likes {what}"): ... print(item) ... ('', 'who', '', None) (' likes ', 'what', '', None) From invalid at invalid.invalid Fri Nov 20 10:55:54 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 20 Nov 2015 15:55:54 +0000 (UTC) Subject: shorten "compress" long integer to short ascii. References: <871tbll2hw.fsf@nightsong.com> Message-ID: On 2015-11-20, Vincent Davis wrote: > On Thu, Nov 19, 2015 at 9:27 PM, Paul Rubin wrote: > >> You can't improve much. A decimal digit carries log(10,2)=3.32 bits >> of information. A reasonable character set for Twitter-style links >> might have 80 or so characters (upper/lower alphabetic, digits, and >> a dozen or so punctuation characters), or log(80,2)= >> > > ?Where do I find out more about the how to calculate information per > digit? There are 10 possible states for a decimal digit. The number of digits required to represent N states in base M is log(N,M). -- Grant Edwards grant.b.edwards Yow! Are we on STRIKE yet? at gmail.com From invalid at invalid.invalid Fri Nov 20 10:58:59 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 20 Nov 2015 15:58:59 +0000 (UTC) Subject: How To Create A Endles List Of Lists In Python...??? References: Message-ID: On 2015-11-20, HKRSS wrote: > > Sorry For Bad Question, But I need List Of Lists That I Can > Acces Horyzontaly, Not In The Deep(But This IS Not All, > I End That Evey List In List Of Lists Can Be A List... > > Thanks In Advance... > Robert..;) Not only was that genuine frontier gibberish, it expressed... something? -- Grant Edwards grant.b.edwards Yow! I feel partially at hydrogenated! gmail.com From ian.g.kelly at gmail.com Fri Nov 20 11:16:45 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 Nov 2015 09:16:45 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <877flcrh26.fsf@elektro.pacujo.net> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: On Fri, Nov 20, 2015 at 5:28 AM, Marko Rauhamaa wrote: > The Ackermann function really is an esoteric example, but the other > example that has been discussed here can make practical use of the > default-value semantics: > > [ lambda x: i * x for i in range(4) ] > > which is salvaged with a default value: > > [ lambda x, i=i: i * x for i in range(4) ] > > or, more hygienically: > > [ (lambda i=i: lambda x: i * x)() for i in range(4) ] Note that this last version could be rewritten as: [ (lambda i: lambda x: i * x)(i) for i in range(4) ] At which point the default value semantics are no longer needed. > One could argue that you should always use a sentinel object for default > values. That also allows you to distinguish between omitted values and > default values: > > def asklist(caption, data, n=omitted, rows=omitted, width=omitted, > flags=omitted, buttons=omitted, tablist=omitted, > heading=omitted): > > but that would be rather pedantic in most circumstances. I think that would be bad design; in general, you shouldn't *need* to distinguish whether the value was omitted, because it should always be possible to explicitly pass the default value. From ian.g.kelly at gmail.com Fri Nov 20 11:18:44 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 Nov 2015 09:18:44 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Nov 20, 2015 at 5:39 AM, BartC wrote: > * The persistent nonsense that somehow [] is mutable (what happens is that > [] is assigned to a variable, and /that/ is mutable) (And I will probably > get some flak now because 'assign' and 'variable' are meaningless in > Python!) I think the problem here is that you're talking as if [] is a unique value, which it isn't. [] is a list display that *constructs* a list, not a list itself. From rosuav at gmail.com Fri Nov 20 11:24:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 03:24:07 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: On Sat, Nov 21, 2015 at 3:16 AM, Ian Kelly wrote: >> One could argue that you should always use a sentinel object for default >> values. That also allows you to distinguish between omitted values and >> default values: >> >> def asklist(caption, data, n=omitted, rows=omitted, width=omitted, >> flags=omitted, buttons=omitted, tablist=omitted, >> heading=omitted): >> >> but that would be rather pedantic in most circumstances. > > I think that would be bad design; in general, you shouldn't *need* to > distinguish whether the value was omitted, because it should always be > possible to explicitly pass the default value. The cases where that's not true are usually ones that are more like C++ overloaded functions: def next(iter): return iter.__next__() def next(iter, default): try: return iter.__next__() except StopIteration: return default You cannot have any actual object to represent the default state, for the same reasons that you can't have __next__ return a magic value to represent "no more values". That's why, in the proposed semantics for an explicit late-binding syntax, I compare with *args notation, which _can_ let you distinguish perfectly. ChrisA From ian.g.kelly at gmail.com Fri Nov 20 11:29:41 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 Nov 2015 09:29:41 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: On Fri, Nov 20, 2015 at 9:24 AM, Chris Angelico wrote: > The cases where that's not true are usually ones that are more like > C++ overloaded functions: > > def next(iter): > return iter.__next__() > def next(iter, default): > try: return iter.__next__() > except StopIteration: return default IMO the version with the default argument should have a different name, as it is conceptually a different function. From marko at pacujo.net Fri Nov 20 11:31:50 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 20 Nov 2015 18:31:50 +0200 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: <87vb8wd43t.fsf@elektro.pacujo.net> Ian Kelly : > On Fri, Nov 20, 2015 at 5:28 AM, Marko Rauhamaa wrote: >> One could argue that you should always use a sentinel object for >> default values. That also allows you to distinguish between omitted >> values and default values: >> >> def asklist(caption, data, n=omitted, rows=omitted, width=omitted, >> flags=omitted, buttons=omitted, tablist=omitted, >> heading=omitted): >> >> but that would be rather pedantic in most circumstances. > > I think that would be bad design; in general, you shouldn't *need* to > distinguish whether the value was omitted, because it should always be > possible to explicitly pass the default value. Consider the mutator pattern: def name(self, value=omitted): if value is omitted: return self._name self._name = value Marko From rosuav at gmail.com Fri Nov 20 11:36:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 03:36:28 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: On Sat, Nov 21, 2015 at 3:29 AM, Ian Kelly wrote: > On Fri, Nov 20, 2015 at 9:24 AM, Chris Angelico wrote: >> The cases where that's not true are usually ones that are more like >> C++ overloaded functions: >> >> def next(iter): >> return iter.__next__() >> def next(iter, default): >> try: return iter.__next__() >> except StopIteration: return default > > IMO the version with the default argument should have a different > name, as it is conceptually a different function. Which would make it like dict.__getitem__ and dict.get, which leads to a lot of people using dict.get() because they don't know about subscripting. And then they mask potential errors because they're using the version that suppresses them, since they didn't even know about the other. Not sure that's an improvement. But I do see the logic in the separation. ChrisA From rosuav at gmail.com Fri Nov 20 11:37:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 03:37:03 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <87vb8wd43t.fsf@elektro.pacujo.net> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> <87vb8wd43t.fsf@elektro.pacujo.net> Message-ID: On Sat, Nov 21, 2015 at 3:31 AM, Marko Rauhamaa wrote: > Consider the mutator pattern: > > def name(self, value=omitted): > if value is omitted: > return self._name > self._name = value > > That should DEFINITELY be two functions. Or just an attribute. ChrisA From ian.g.kelly at gmail.com Fri Nov 20 11:39:10 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 Nov 2015 09:39:10 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <87vb8wd43t.fsf@elektro.pacujo.net> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> <87vb8wd43t.fsf@elektro.pacujo.net> Message-ID: On Fri, Nov 20, 2015 at 9:31 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Fri, Nov 20, 2015 at 5:28 AM, Marko Rauhamaa wrote: >>> One could argue that you should always use a sentinel object for >>> default values. That also allows you to distinguish between omitted >>> values and default values: >>> >>> def asklist(caption, data, n=omitted, rows=omitted, width=omitted, >>> flags=omitted, buttons=omitted, tablist=omitted, >>> heading=omitted): >>> >>> but that would be rather pedantic in most circumstances. >> >> I think that would be bad design; in general, you shouldn't *need* to >> distinguish whether the value was omitted, because it should always be >> possible to explicitly pass the default value. > > Consider the mutator pattern: > > def name(self, value=omitted): > if value is omitted: > return self._name > self._name = value > > Why would you ever want to do this in a language with properties? From marko at pacujo.net Fri Nov 20 11:41:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 20 Nov 2015 18:41:42 +0200 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: <87r3jkd3nd.fsf@elektro.pacujo.net> Ian Kelly : > On Fri, Nov 20, 2015 at 9:24 AM, Chris Angelico wrote: >> The cases where that's not true are usually ones that are more like >> C++ overloaded functions: >> >> def next(iter): >> return iter.__next__() >> def next(iter, default): >> try: return iter.__next__() >> except StopIteration: return default > > IMO the version with the default argument should have a different > name, as it is conceptually a different function. I don't necessarily disagree, but consider this function: socket.create_connection(address[, timeout[, source_address]]) It has been implemented: _GLOBAL_DEFAULT_TIMEOUT = object() def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None): which is somewhat inconsistent. Why not: def create_connection(address, timeout=None, source_address=None): or: omitted = object() def create_connection(address, timeout=omitted, source_address=omitted): The argument for the former is that neither timeout nor source_address can meaningfully be None. The argument for the latter is that it follows a generic pattern that places no assumptions on the legality or illegality of None as a value. The chosen implementation allows: s.create_connection(address, source_address=None) but not: s.create_connection(address, timeout=None) Marko From denismfmcmahon at gmail.com Fri Nov 20 12:08:21 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 20 Nov 2015 17:08:21 -0000 (UTC) Subject: String format - resolve placeholders names References: <20151120145227.GB13994@arxnet.hu> Message-ID: On Fri, 20 Nov 2015 16:53:47 +0100, Peter Otten wrote: > Ervin Heged?s wrote: >> Python has a good string formatter, eg. I can do this: >> s = "{who} likes {what}" >> d = {'who': "Adam", 'what': "ants"} >> s.format(**d) >> result: >> 'Adam likes ants' >> Is it possible, and if yes, how to resolve the placeholders names in >> string? >>>> import string for item in string.Formatter().parse("{who} likes >>>> {what}"): > ... print(item) > ... > ('', 'who', '', None) > (' likes ', 'what', '', None) Or even: >>> s = "{who} likes {what}" >>> d = {'who': "Adam", 'what': "ants"} >>> keys = [x[1] for x in string.Formatter().parse(s)] >>> keys ['who', 'what'] then ... for key in keys: if key not in d: raise KeyError("Missing key '{}' in format string '{}'".format (key, s)) -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Fri Nov 20 12:14:21 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 20 Nov 2015 17:14:21 -0000 (UTC) Subject: How To Create A Endles List Of Lists In Python...??? References: Message-ID: On Fri, 20 Nov 2015 08:43:04 +0100, HKRSS wrote: > Thanks In Advance, Robert...;) Just keep appending child lists to parent list: l = [] while True: l.append([]) Until you run out of memory But I think that this answer although it appears accurate to the question is not a solution for anything useful, because it will just use all the memory up. So perhaps you need to express your question in a better manner. -- Denis McMahon, denismfmcmahon at gmail.com From dylan.riley at hotmail.com Fri Nov 20 12:22:10 2015 From: dylan.riley at hotmail.com (Dylan Riley) Date: Fri, 20 Nov 2015 09:22:10 -0800 (PST) Subject: error help import random Message-ID: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> This is my fortune cookie program i wrote in python. the problem is it will not run past the first line of input. could someone please identify the error and explain to me why. here is the code: #the program silulates a fortune cookie #the program should display one of five unique fortunes, at randon, each time its run import random print(" \\ \\ \\ \\ DYLANS FORTUNE COOKIE \\ \\ \\ ") print("\n\n\tGood things come to those who wait") input("\nPress enter to see your fortune") fortune = random.randrange(6) + 1 print(fortune) if fortune == 1: print("happy") elif fortune == 2: print("horny") elif fortune == 3: print("messy") elif fortune == 4: print("sad") elif fortune == 5: print("lool") print("hope ypu enjoyed your fortune being told") input("\nPress enter to exit") many thanks in advance From rosuav at gmail.com Fri Nov 20 12:30:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 04:30:42 +1100 Subject: error help import random In-Reply-To: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> References: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> Message-ID: On Sat, Nov 21, 2015 at 4:22 AM, Dylan Riley wrote: > This is my fortune cookie program i wrote in python. > the problem is it will not run past the first line of input. > could someone please identify the error and explain to me why. > here is the code: > > #the program silulates a fortune cookie > #the program should display one of five unique fortunes, at randon, each time its run > > import random Actually, you could help us identify the error. What happens when you run it? Show us exactly how you invoke it and what the output is. ChrisA From torriem at gmail.com Fri Nov 20 12:44:00 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 20 Nov 2015 10:44:00 -0700 Subject: How can I export data from a website and write the contents to a text file? In-Reply-To: <2052054.MEiq1cOQgg@desk8.phess.net> References: <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> <6e0f470b-f896-43ae-8f83-b20f22a9db8d@googlegroups.com> <2052054.MEiq1cOQgg@desk8.phess.net> Message-ID: <564F5BE0.8020306@gmail.com> On 11/19/2015 12:17 PM, Patrick Hess wrote: > ryguy7272 wrote: >> text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb") >> [...] >> It doesn't seem like the '\n' is doing anything useful. All the text is jumbled together. >> [...] >> I finally got it working. It's like this: >> "\r\n" > > The better solution would be to open text files in actual text mode: > > open("filename", "wb") # binary mode > open("filename", "w") # text mode > > In text mode, the correct line-ending characters, which will vary > depending on the operating system, are chosen automatically. It's not just a matter of line endings. It's a matter of text encoding also. This is critical in Python3 where everything is unicode and encoding is essential. You have to to use the text mode when writing files here, and it's also a good idea to specify what encoding you wish to write with (UTF-8 is a good default). From __peter__ at web.de Fri Nov 20 12:57:44 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 Nov 2015 18:57:44 +0100 Subject: error help import random References: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> Message-ID: Dylan Riley wrote: > This is my fortune cookie program i wrote in python. > the problem is it will not run past the first line of input. > could someone please identify the error and explain to me why. > here is the code: > > #the program silulates a fortune cookie > #the program should display one of five unique fortunes, at randon, each > #time its run > > import random > > print(" \\ \\ \\ \\ DYLANS FORTUNE COOKIE \\ \\ \\ ") > print("\n\n\tGood things come to those who wait") > input("\nPress enter to see your fortune") > > fortune = random.randrange(6) + 1 > print(fortune) > if fortune == 1: > print("happy") > elif fortune == 2: > print("horny") > elif fortune == 3: > print("messy") > elif fortune == 4: > print("sad") > elif fortune == 5: > print("lool") > > print("hope ypu enjoyed your fortune being told") > input("\nPress enter to exit") > > > many thanks in advance Make sure that you run your code with Python 3, not Python 2. From w.g.sneddon at gmail.com Fri Nov 20 13:01:02 2015 From: w.g.sneddon at gmail.com (bSneddon) Date: Fri, 20 Nov 2015 10:01:02 -0800 (PST) Subject: Dabbling in web development In-Reply-To: References: <2a5d3947-a49a-48f8-bc4c-7d126d3d6fef@googlegroups.com> Message-ID: Thanks all! From ian.g.kelly at gmail.com Fri Nov 20 13:10:49 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 Nov 2015 11:10:49 -0700 Subject: error help import random In-Reply-To: References: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> Message-ID: On Fri, Nov 20, 2015 at 10:57 AM, Peter Otten <__peter__ at web.de> wrote: > Dylan Riley wrote: > >> input("\nPress enter to see your fortune") > > Make sure that you run your code with Python 3, not Python 2. Or if you must use Python 2, use raw_input() instead of input(). >> fortune = random.randrange(6) + 1 Also, you have an off-by-one error here. randrange(6) will give you an integer between 0 and 5, inclusive (a total of 6 possible values). Adding 1 will then result in an integer between 1 and 6, inclusive, but you don't have a case for a value of 6. From robert.bralic at si.t-com.hr Fri Nov 20 13:16:06 2015 From: robert.bralic at si.t-com.hr (robert.bralic at si.t-com.hr) Date: Fri, 20 Nov 2015 10:16:06 -0800 (PST) Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: Message-ID: Dana petak, 20. studenoga 2015. u 18:16:52 UTC+1, korisnik Denis McMahon napisao je: > On Fri, 20 Nov 2015 08:43:04 +0100, HKRSS wrote: > > > Thanks In Advance, Robert...;) > > Just keep appending child lists to parent list: > > l = [] > > while True: > l.append([]) > > Until you run out of memory > > But I think that this answer although it appears accurate to the question > is not a solution for anything useful, because it will just use all the > memory up. So perhaps you need to express your question in a better > manner. > > -- > Denis McMahon, denismfmcmahon at gmail.com I Think That LISP Is Only Solution, I Wil Give Up Frpm Python... Thanks, Robert...;) From mr.eightnoteight at gmail.com Fri Nov 20 13:28:20 2015 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Fri, 20 Nov 2015 23:58:20 +0530 Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: <564F1AC0.5040106@shopzeus.com> Message-ID: On Fri, Nov 20, 2015 at 6:39 PM, Chris Angelico wrote: > My crystal ball suggests that defaultdict(list) might be useful here. > > ChrisA I used something similar to this for some problem in hackerrank, anyway i think this is what you want. class defaultlist(object): def __init__(self, factory, data=None): self.factory = factory self.list = [] self.data = data def __getitem__(self, x): if x >= len(self.list): self.list.extend([self.factory() for _ in range(len(self.list), x + 1)]) return self.list[x] def __repr__(self): return str(self) def __str__(self): if len(self.list) == 0: return '(' + str(self.data) + ')[...]' return ''.join(['(', str(self.data), ')['] + map(str, self.list) + [', ...]']) def __setitem__(self, x, v): if x >= len(self.list): self.list.extend([self.factory() for _ in range(len(self.list), x + 1)]) self.list[x] = v def main(): factory = lambda: defaultlist(factory) list_of_lists = defaultlist(factory) print (list_of_lists[0]) list_of_lists[0][10].data = 20 print (list_of_lists[0]) main() Gist: https://gist.github.com/c0c2ee1e7c6535ef8c3d From ian.g.kelly at gmail.com Fri Nov 20 13:29:11 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 Nov 2015 11:29:11 -0700 Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: Message-ID: On Fri, Nov 20, 2015 at 11:16 AM, wrote: > Dana petak, 20. studenoga 2015. u 18:16:52 UTC+1, korisnik Denis McMahon napisao je: >> On Fri, 20 Nov 2015 08:43:04 +0100, HKRSS wrote: >> >> > Thanks In Advance, Robert...;) >> >> Just keep appending child lists to parent list: >> >> l = [] >> >> while True: >> l.append([]) >> >> Until you run out of memory >> >> But I think that this answer although it appears accurate to the question >> is not a solution for anything useful, because it will just use all the >> memory up. So perhaps you need to express your question in a better >> manner. >> >> -- >> Denis McMahon, denismfmcmahon at gmail.com > > I Think That LISP Is Only Solution, I Wil Give Up Frpm Python... Nagy and Chris gave you two different perfectly good solutions for Python. From rosuav at gmail.com Fri Nov 20 13:30:23 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 05:30:23 +1100 Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: Message-ID: On Sat, Nov 21, 2015 at 5:16 AM, wrote: > I Think That LISP Is Only Solution, I Wil Give Up Frpm Python... Capital Letters For The Win. You Should Consider Talking In German. ChrisA From mr.eightnoteight at gmail.com Fri Nov 20 13:35:41 2015 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Sat, 21 Nov 2015 00:05:41 +0530 Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: <564F1AC0.5040106@shopzeus.com> Message-ID: On Fri, Nov 20, 2015 at 11:58 PM, srinivas devaki wrote: > def __str__(self): > if len(self.list) == 0: > return '(' + str(self.data) + ')[...]' > return ''.join(['(', str(self.data), ')['] + map(str, self.list) + [', ...]']) > ... > Gist: https://gist.github.com/c0c2ee1e7c6535ef8c3d uhh, there is an error in representing it, the code should be def __str__(self): if len(self.list) == 0: return '(' + str(self.data) + ')[...]' return ''.join(['(', str(self.data), ')[', ', '.join(map(str, self.list)), ', ...]']) Output: (None)[...] (None)[(None)[...], (None)[...], (None)[...], (20)[...], ...] ps: code is updated in gist. From sohcahtoa82 at gmail.com Fri Nov 20 14:26:33 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 20 Nov 2015 11:26:33 -0800 (PST) Subject: How To Create A Endles List Of Lists In Python...??? In-Reply-To: References: Message-ID: On Friday, November 20, 2015 at 10:16:34 AM UTC-8, robert... at si.t-com.hr wrote: > Dana petak, 20. studenoga 2015. u 18:16:52 UTC+1, korisnik Denis McMahon napisao je: > > On Fri, 20 Nov 2015 08:43:04 +0100, HKRSS wrote: > > > > > Thanks In Advance, Robert...;) > > > > Just keep appending child lists to parent list: > > > > l = [] > > > > while True: > > l.append([]) > > > > Until you run out of memory > > > > But I think that this answer although it appears accurate to the question > > is not a solution for anything useful, because it will just use all the > > memory up. So perhaps you need to express your question in a better > > manner. > > > > -- > > Denis McMahon, denismfmcmahon at gmail.com > > I Think That LISP Is Only Solution, I Wil Give Up Frpm Python... > > Thanks, Robert...;) Is There A Reason You're Starting Every Word With A Capital Letter? I mean, really, you're going out of your way and expending extra effort to type incorrectly. From airween at gmail.com Fri Nov 20 14:34:10 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Fri, 20 Nov 2015 20:34:10 +0100 Subject: String format - resolve placeholders names In-Reply-To: References: <20151120145227.GB13994@arxnet.hu> Message-ID: <20151120193410.GA29560@arxnet.hu> Hi Peter, On Fri, Nov 20, 2015 at 04:53:47PM +0100, Peter Otten wrote: > Ervin Heged?s wrote: > > > Python has a good string formatter, eg. I can do this: > > > > s = "{who} likes {what}" > > d = {'who': "Adam", 'what': "ants"} > > s.format(**d) > > > > result: > > 'Adam likes ants' > > > > Is it possible, and if yes, how to resolve the placeholders names > > in string? > > >>> import string > >>> for item in string.Formatter().parse("{who} likes {what}"): > ... print(item) > ... > ('', 'who', '', None) > (' likes ', 'what', '', None) nice solution, thanks, a. -- I ? UTF-8 From airween at gmail.com Fri Nov 20 14:36:31 2015 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Fri, 20 Nov 2015 20:36:31 +0100 Subject: String format - resolve placeholders names In-Reply-To: References: <20151120145227.GB13994@arxnet.hu> Message-ID: <20151120193631.GB29560@arxnet.hu> Hi Denis, On Fri, Nov 20, 2015 at 05:08:21PM -0000, Denis McMahon wrote: > On Fri, 20 Nov 2015 16:53:47 +0100, Peter Otten wrote: > > > Ervin Heged?s wrote: > > >> Python has a good string formatter, eg. I can do this: > > Or even: > > >>> s = "{who} likes {what}" > >>> d = {'who': "Adam", 'what': "ants"} > >>> keys = [x[1] for x in string.Formatter().parse(s)] > >>> keys > ['who', 'what'] > > then ... > > for key in keys: > if key not in d: > raise KeyError("Missing key '{}' in format string '{}'".format > (key, s)) well, I think I'm very satisfied - I got better and more better solutions :). Thanks for all, folks: a. -- I ? UTF-8 From tjreedy at udel.edu Fri Nov 20 15:15:42 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2015 15:15:42 -0500 Subject: error help import random In-Reply-To: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> References: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> Message-ID: On 11/20/2015 12:22 PM, Dylan Riley wrote: > This is my fortune cookie program i wrote in python. > the problem is it will not run past the first line of input. > could someone please identify the error and explain to me why. > here is the code: > > #the program silulates a fortune cookie > #the program should display one of five unique fortunes, at randon, each time its run > > import random > > print(" \\ \\ \\ \\ DYLANS FORTUNE COOKIE \\ \\ \\ ") > print("\n\n\tGood things come to those who wait") > input("\nPress enter to see your fortune") > > fortune = random.randrange(6) + 1 > print(fortune) > if fortune == 1: > print("happy") > elif fortune == 2: > print("horny") > elif fortune == 3: > print("messy") > elif fortune == 4: > print("sad") > elif fortune == 5: > print("lool") Use a dict instead of if-elif. i = random.randrange(6) fortunes = {0:'happy', 1:'horny', 2:'messy', 3:'sad', 4:'lool', 5:'buggy'} print(i, fortunes[i]) > print("hope ypu enjoyed your fortune being told") > input("\nPress enter to exit") -- Terry Jan Reedy From stephane at wirtel.be Fri Nov 20 17:14:57 2015 From: stephane at wirtel.be (Stephane Wirtel) Date: Fri, 20 Nov 2015 23:14:57 +0100 Subject: Mapping between python packages and distro packages? In-Reply-To: <85vb90c4fv.fsf@benfinney.id.au> References: <20151118032903.GA8040@sg1> <85vb90c4fv.fsf@benfinney.id.au> Message-ID: <20151120221457.GA7590@sg1> Hi Ben, sorry for my late reply, just forgotten to reply :/ really sorry in fact, I would like to have a database where I want the requests library, I will get the python-requests for debian/ubuntu and the right package for the yum installer. I have an other solution, but I don't like it because I risk to break the linux distribution (the target) and use the wheel package. On 11/18, Ben Finney wrote: > Stephane Wirtel writes: > > > Do you know if there is a library to match a python package (from PyPI) > > and find the right debian/redhat packages ? > > What would count as ?the right package?? > > Do you mean ?the package that has that PyPI distribution URL in its > ?debian/watch? configuration?? > > Do you mean ?the package that names that PyPI distribution in its > ?debian/copyright? ?Source? field?? > > Or something else? > > The answers will differ depending on exactly what question is being > asked of the data. > > If you can define exactly what query you want to perform, perhaps a > solution can be offered. > > -- > \ ?The Vatican is not a state.? a state must have territory. This | > `\ is a palace with gardens, about as big as an average golf | > _o__) course.? ?Geoffrey Robertson, 2010-09-18 | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list -- St?phane Wirtel - http://wirtel.be - @matrixise From stephane at wirtel.be Fri Nov 20 17:15:50 2015 From: stephane at wirtel.be (Stephane Wirtel) Date: Fri, 20 Nov 2015 23:15:50 +0100 Subject: Mapping between python packages and distro packages? In-Reply-To: References: <20151118032903.GA8040@sg1> <85vb90c4fv.fsf@benfinney.id.au> Message-ID: <20151120221550.GB7590@sg1> > I don't know how the program would detect it, but I'd be thinking "the > one where 'sudo apt-get install PACKAGENAME' gets the same code that > 'pip install THING' gets". In a lot of cases, PACKAGENAME will simply > be python-THING or python3-THING, eg python3-sqlalchemy, > python3-scipy, python3-bs4; as a human, that's what I'd try first. But > having a program recognize this would be hugely beneficial. +1 -- St?phane Wirtel - http://wirtel.be - @matrixise From rgaddi at technologyhighland.invalid Fri Nov 20 18:03:26 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Fri, 20 Nov 2015 23:03:26 -0000 (UTC) Subject: error help import random References: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> Message-ID: On Fri, 20 Nov 2015 15:15:42 -0500, Terry Reedy wrote: > On 11/20/2015 12:22 PM, Dylan Riley wrote: >> This is my fortune cookie program i wrote in python. >> the problem is it will not run past the first line of input. >> could someone please identify the error and explain to me why. >> here is the code: >> >> #the program silulates a fortune cookie #the program should display one >> of five unique fortunes, at randon, each time its run >> >> import random >> >> print(" \\ \\ \\ \\ DYLANS FORTUNE COOKIE \\ \\ \\ ") >> print("\n\n\tGood things come to those who wait") >> input("\nPress enter to see your fortune") >> >> fortune = random.randrange(6) + 1 print(fortune) >> if fortune == 1: >> print("happy") >> elif fortune == 2: >> print("horny") >> elif fortune == 3: >> print("messy") >> elif fortune == 4: >> print("sad") >> elif fortune == 5: >> print("lool") > > Use a dict instead of if-elif. > > i = random.randrange(6) > fortunes = {0:'happy', 1:'horny', 2:'messy', > 3:'sad', 4:'lool', 5:'buggy'} > print(i, fortunes[i]) > Or a list/tuple, which saves in typing, memory, and access time. fortunes = ('happy', 'horny', 'messy', 'sad', 'lool', 'buggy') i = random.randrange(len(fortunes)) print(i, fortunes[i]) Or to be lazier still, just use random.choice fortunes = ('happy', 'horny', 'messy', 'sad', 'lool', 'buggy') print(random.choice(fortunes)) None of which actually addresses the OP's issue with input(), but it's nice to get the back half clean as well. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From Seymore4Head at Hotmail.invalid Fri Nov 20 18:05:09 2015 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Fri, 20 Nov 2015 18:05:09 -0500 Subject: error help import random References: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> Message-ID: On Fri, 20 Nov 2015 09:22:10 -0800 (PST), Dylan Riley wrote: >This is my fortune cookie program i wrote in python. >the problem is it will not run past the first line of input. >could someone please identify the error and explain to me why. >here is the code: > >#the program silulates a fortune cookie >#the program should display one of five unique fortunes, at randon, each time its run > >import random > A problem I used to have is that if you have a file called random.py in the folder when you try to import random, it caused an error. >print(" \\ \\ \\ \\ DYLANS FORTUNE COOKIE \\ \\ \\ ") >print("\n\n\tGood things come to those who wait") >input("\nPress enter to see your fortune") > >fortune = random.randrange(6) + 1 >print(fortune) >if fortune == 1: > print("happy") >elif fortune == 2: > print("horny") >elif fortune == 3: > print("messy") >elif fortune == 4: > print("sad") >elif fortune == 5: > print("lool") > >print("hope ypu enjoyed your fortune being told") >input("\nPress enter to exit") > > >many thanks in advance From ben+python at benfinney.id.au Fri Nov 20 21:34:20 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 21 Nov 2015 13:34:20 +1100 Subject: Mapping between python packages and distro packages? References: <20151118032903.GA8040@sg1> <85vb90c4fv.fsf@benfinney.id.au> <20151120221457.GA7590@sg1> Message-ID: <85d1v4cc7n.fsf@benfinney.id.au> Stephane Wirtel writes: > in fact, I would like to have a database where I want the requests > library, I will get the python-requests for debian/ubuntu and the > right package for the yum installer. Okay. That's a pretty simple technical problem (a simple relation between PyPI distribution name, GNU+Linux operating system name, and package name). Of course, *populating* that database, *verifying* the ambiguous inputs, and *maintaining* that database into the future, are all social problems. You'll probably need an organised group of people to address it. I'm not aware of any sufficiently motivated group of people to put in the ongoing effort to provide what you want. (Another social problem is convincing people not to top-post, but instead to reply interleaved and trim irrelevant quoted material .) -- \ ?Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.? ?Tim O'Reilly, 2000-01-25 | Ben Finney From dylan.riley at hotmail.com Fri Nov 20 22:26:34 2015 From: dylan.riley at hotmail.com (Dylan Riley) Date: Fri, 20 Nov 2015 19:26:34 -0800 (PST) Subject: error help import random In-Reply-To: References: <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> Message-ID: <66756cd4-d3ef-42db-8471-8475ed540a27@googlegroups.com> On Friday, November 20, 2015 at 11:06:05 PM UTC, Rob Gaddi wrote: > On Fri, 20 Nov 2015 15:15:42 -0500, Terry Reedy wrote: > > > On 11/20/2015 12:22 PM, Dylan Riley wrote: > >> This is my fortune cookie program i wrote in python. > >> the problem is it will not run past the first line of input. > >> could someone please identify the error and explain to me why. > >> here is the code: > >> > >> #the program silulates a fortune cookie #the program should display one > >> of five unique fortunes, at randon, each time its run > >> > >> import random > >> > >> print(" \\ \\ \\ \\ DYLANS FORTUNE COOKIE \\ \\ \\ ") > >> print("\n\n\tGood things come to those who wait") > >> input("\nPress enter to see your fortune") > >> > >> fortune = random.randrange(6) + 1 print(fortune) > >> if fortune == 1: > >> print("happy") > >> elif fortune == 2: > >> print("horny") > >> elif fortune == 3: > >> print("messy") > >> elif fortune == 4: > >> print("sad") > >> elif fortune == 5: > >> print("lool") > > > > Use a dict instead of if-elif. > > > > i = random.randrange(6) > > fortunes = {0:'happy', 1:'horny', 2:'messy', > > 3:'sad', 4:'lool', 5:'buggy'} > > print(i, fortunes[i]) > > > > Or a list/tuple, which saves in typing, memory, and access time. > > fortunes = ('happy', 'horny', 'messy', 'sad', 'lool', 'buggy') > i = random.randrange(len(fortunes)) > print(i, fortunes[i]) > > Or to be lazier still, just use random.choice > > fortunes = ('happy', 'horny', 'messy', 'sad', 'lool', 'buggy') > print(random.choice(fortunes)) > > None of which actually addresses the OP's issue with input(), but it's > nice to get the back half clean as well. > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. very nice i like the way you code. i managed to solve the problem it was because i wasnt using raw_input however i updated to python 3 so the original now works. many thanks anyway From dylan.riley at hotmail.com Fri Nov 20 22:30:02 2015 From: dylan.riley at hotmail.com (Dylan Riley) Date: Fri, 20 Nov 2015 19:30:02 -0800 (PST) Subject: anyone tell me why my program will not run? Message-ID: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> i am learning python and was tasked with making a program that flips a coin 100 times and then tells you the number of heads and tails. I have done so coming up with this piece of work but it doesnt run can anyone help me out? #This is credited to dylan print(" \\ \\ \\ \\ \\ \\ \\ \\ D FLIPS \\ \\ \\ \\ \\ \\ \\ \\") print("\n\nThis is D's coin flipper program. You get 100 flips. \n\t LETS SEE HOW LUCKY YOU ARE") input("Press enter") import random heads = int("1") tails = int("2") flips = 100 headscount = 0 tailscount = 0 while flips != 0: flips -= 1 result = random.randint(heads, tails) if result = heads: headscount += 1 else: tailscount += 1 print(headscount, tailscount) input("press enter to exit") From joel.goldstick at gmail.com Fri Nov 20 22:39:22 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 20 Nov 2015 22:39:22 -0500 Subject: anyone tell me why my program will not run? In-Reply-To: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> References: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> Message-ID: On Fri, Nov 20, 2015 at 10:30 PM, Dylan Riley wrote: > i am learning python and was tasked with making a program that flips a > coin 100 times and then tells you > the number of heads and tails. > > I have done so coming up with this piece of work but it doesnt run can > anyone help me out? > > #This is credited to dylan > > print(" \\ \\ \\ \\ \\ \\ \\ \\ D FLIPS \\ \\ \\ \\ \\ \\ \\ \\") > print("\n\nThis is D's coin flipper program. You get 100 flips. \n\t LETS > SEE HOW LUCKY YOU ARE") > input("Press enter") > > import random > > heads = int("1") > tails = int("2") > flips = 100 > headscount = 0 > tailscount = 0 > > while flips != 0: > flips -= 1 > > shouldn't this below be in the while loop? > result = random.randint(heads, tails) > if result = heads: > headscount += 1 > else: > tailscount += 1 > > > up to here > print(headscount, tailscount) > > input("press enter to exit") > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From rosuav at gmail.com Sat Nov 21 00:50:39 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 16:50:39 +1100 Subject: anyone tell me why my program will not run? In-Reply-To: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> References: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> Message-ID: On Sat, Nov 21, 2015 at 2:30 PM, Dylan Riley wrote: > I have done so coming up with this piece of work but it doesnt run can anyone help me out? > Please, please, try to help us out here! What does it mean to "not run"? Does it run and give an exception? Does it run to completion but give no output? Do you type "python somefile.py" and get back an error from the system? What? ChrisA From gengyangcai at gmail.com Sat Nov 21 01:54:37 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Fri, 20 Nov 2015 22:54:37 -0800 (PST) Subject: Traceback error Message-ID: This is a piece of code about comparators : j# Assign True or False as appropriate on the lines below! # Set this to True if 17 < 328 or to False if it is not. bool_one = 17 < 328 # We did this one for you! # Set this to True if 100 == (2 * 50) or to False otherwise. bool_two = 100 == (2 * 50) # Set this to True if 19 <= 19 or to False if it is not. bool_three = 19 <= 19 # Set this to True if -22 >= -18 or to False if it is not. bool_four = -22 >= -18 # Set this to True if 99 != (98 + 1) or to False otherwise. bool_five = 99 != (98 + 1) When I tried to run it, this is the error I got : Traceback (most recent call last): File "python", line 1, in NameError: name 'j' is not defined Any ideas how to debug this ? Thanks a lot! Appreciate it Cai Gengyang From frank at chagford.com Sat Nov 21 02:26:06 2015 From: frank at chagford.com (Frank Millman) Date: Sat, 21 Nov 2015 09:26:06 +0200 Subject: Traceback error In-Reply-To: References: Message-ID: "Cai Gengyang" wrote in message news:e5d80196-61c5-44d9-bec8-dc563d58fa6a at googlegroups.com... > This is a piece of code about comparators : > j# Assign True or False as appropriate on the lines below! [snip rest of code] > When I tried to run it, this is the error I got : > Traceback (most recent call last): > File "python", line 1, in > NameError: name 'j' is not defined > Any ideas how to debug this ? It looks to me as if the error is right there on the first line. What is that 'j' doing there? It looks like a typo. HTH Frank Millman From dieter at handshake.de Sat Nov 21 02:26:44 2015 From: dieter at handshake.de (dieter) Date: Sat, 21 Nov 2015 08:26:44 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: Message-ID: <87egfjhky3.fsf@handshake.de> Jussi Piitulainen writes: > dieter writes: >> Chris Angelico writes: >> >>> IMO it's controversial mainly because there's an easy and obvious >>> syntax for early binding, but late binding doesn't have syntactic >>> support, and all the options are imperfect. >> >> I do not think that we should get additional syntax for lately bound >> default values. It would explicitely introduce the concepts early >> versus late binding which are likely difficult to understand by many >> users. > > I'm confused by the term. I don't like it one bit. > > "Early binding" of a default value seems to mean that the expression > that produces the default value of a function parameter is evaluated > when the function is defined. "Late binding" seems to mean that the > expression is evaluated when the function is called. > > In both cases the actual binding of the parameter to the value (either > the default or an actual argument) is established when the function is > called. Several different bindings of that same parameter to different > values can hold simultaneously, so the *binding* has to be conceptually > "late". Because recursion. Conventionally, "binding" is the association of a "value" with a "name". In this sense, you can call "early binding" the current Python behavior with respect to default parameters: the expression is evaluated into a "value" at function definition time and bound to the parameter name. A later call may rebind the parameter name (if it provides its own value). In the case of "late binding", the function definition would also bind at function definition time the "name" to something (but not a "value"): an expression, maybe together with some binding. This expression would then be evaluated at a later time (and we only then get the typical binding of a "name" to a "value"). > Why isn't the evaluation of the default expression called evaluation? I do not mind if you prefer to use the term "evaluation" instead of "binding". Nothing important in my previous message would be changed by the term exchange: you must specify how (and when) the variables referenced in the expression get their values. And this will give new difficulties - more serious than Python's current handling of default parameters. From dieter at handshake.de Sat Nov 21 02:31:13 2015 From: dieter at handshake.de (dieter) Date: Sat, 21 Nov 2015 08:31:13 +0100 Subject: Traceback error References: Message-ID: <87a8q7hkqm.fsf@handshake.de> Cai Gengyang writes: > This is a piece of code about comparators : > j# Assign True or False as appropriate on the lines below! > ... > When I tried to run it, this is the error I got : > > Traceback (most recent call last): > File "python", line 1, in > NameError: name 'j' is not defined The error information is very precise: in your line 1, you have: j# Assign True or False as appropriate on the lines below! The "j" before the comment ("#...") is what causes the problem. Likely, you did not want it there. From gengyangcai at gmail.com Sat Nov 21 02:33:06 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Fri, 20 Nov 2015 23:33:06 -0800 (PST) Subject: Traceback error In-Reply-To: References: Message-ID: <3e2577a5-a6e5-48b1-ae6a-6496403db7d0@googlegroups.com> Right ... I removed the 'j' and the code works now. I must have accidentally put it in , forgot about it and thought that it was part of the original code when it shouldn't have been there in the first place. Thanks ! On Saturday, November 21, 2015 at 3:27:02 PM UTC+8, Frank Millman wrote: > "Cai Gengyang" wrote in message > news:e5d80196-61c5-44d9-bec8-dc563d58fa6a at googlegroups.com... > > > This is a piece of code about comparators : > > > > j# Assign True or False as appropriate on the lines below! > > [snip rest of code] > > > When I tried to run it, this is the error I got : > > > Traceback (most recent call last): > > File "python", line 1, in > > NameError: name 'j' is not defined > > > > Any ideas how to debug this ? > > > It looks to me as if the error is right there on the first line. What is > that 'j' doing there? It looks like a typo. > > HTH > > Frank Millman From toddrjen at gmail.com Sat Nov 21 03:38:01 2015 From: toddrjen at gmail.com (Todd) Date: Sat, 21 Nov 2015 09:38:01 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: On Nov 19, 2015 20:48, "Chris Angelico" wrote: > > On Fri, Nov 20, 2015 at 5:42 AM, Ian Kelly wrote: > > BartC on the other hand is just complaining about an aspect of Python > > that is legitimately controversial. > > IMO it's controversial mainly because there's an easy and obvious > syntax for early binding, but late binding doesn't have syntactic > support, and all the options are imperfect. Consider: > > def late1(x=None): > """Terse but buggy""" > do_stuff_with(x or []) > > def late2(x=None): > """Not bad but has an extra line for each default. Also, can't take None.""" > if x is None: x = [] > do_stuff_with(x) > > _SENTINEL = object() > def late3(x=_SENTINEL): > """Has the same global-pollution problem you get when you > try to construct early binding from late; you can share the > sentinel among multiple args, even multiple funcs, though""" > if x is _SENTINEL: x = [] > do_stuff_with(x) > > def late4(x=object()): > """Depends on its own name remaining bound in its scope, > and will break if you change argument order""" > if x is late4.__defaults__[0]: x = [] > do_stuff_with(x) > > And there might be other techniques, too. They all share one important > flaw, too: When you ask for help about the function, you can't see > what the default really is. All you see is: > > late1(x=None) > late3(x=) > > In the first two cases, it's not too bad; you can specify a timeout as > either a number or as None, and if it's None (the default), the > timeout is three times the currently estimated round trip time. No > problem. But how would you implement something like next() in pure > Python? If you provide _any second argument at all_, it returns that > instead of raising StopIteration. The ONLY way that I can think of is > to use *args notation: > > def next(iterator, *default): > try: > return iterator.__next__() > except StopIteration: > if default: return default[0] > raise > > And while that isn't TOO bad for just one argument, it scales poorly: > > def foo(fixed_arg, *args): > """Foo the fixed_arg against the spam mapping, the > ham sequence, and the jam file.""" > args.reverse() > spam = args.pop() if args else {} > ham = args.pop() if args else [] > jam = args.pop() if args else open("jam.txt") > > Suppose, instead, that Python had a syntax like this: > > def foo(fixed_arg, spam=>{}, ham=>[], jam=>open("jam.txt")): > """Foo the fixed_arg against the spam mapping, the > ham sequence, and the jam file.""" > > The expressions would be evaluated as closures, using the same scope > that the function's own definition used. (This won't keep things alive > unnecessarily, as the function's body will be nested within that same > scope anyway.) Bikeshed the syntax all you like, but this would be > something to point people to: "here's how to get late-binding > semantics". For the purposes of documentation, the exact text of the > parameter definition could be retained, and like docstrings, they > could be discarded in -OO mode. > > Would this satisfy the people who get confused about "=[]"? > > ChrisA Rather than a dedicated syntax, might this be something that could be handled by a built-in decorator? Maybe something like: @late_binding def myfunc(x, y=[]): @late_binding('z') def myfunc(x, y=expensive(), z=[]): M = 5 @late_binding('z', vars_early=True) def myfunc(x, y=expensive(), z=list(range(n))): The big advantage, as shown in the last example, is that it could be possible to specify early our late binding for variables as well. From rosuav at gmail.com Sat Nov 21 03:46:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Nov 2015 19:46:17 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: On Sat, Nov 21, 2015 at 7:38 PM, Todd wrote: > Rather than a dedicated syntax, might this be something that could be > handled by a built-in decorator? > > Maybe something like: > > @late_binding > def myfunc(x, y=[]): No, it can't; by the time the decorator runs, the expression has already been evaluated. Without syntax, this can only be done with gross hacks like lambda functions. It could be done thus: @late_binding def myfunc(x, y=lambda: []): and then the decorator could wrap the function. I'm not entirely sure I could implement it reliably, but even leaving that aside, having to put "lambda:" in front of everything is pretty ugly. ChrisA From vostrushka at gmail.com Sat Nov 21 05:41:57 2015 From: vostrushka at gmail.com (vostrushka at gmail.com) Date: Sat, 21 Nov 2015 02:41:57 -0800 (PST) Subject: Problem to read from array Message-ID: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> Hi, I have a file with one parameter per line: a1 b1 c1 a2 b2 c2 a3 b3 c3 ... The parameters are lines of characters (not numbers) I need to load it to 2D array for further manipulations. So far I managed to upload this file into 1D array: ParametersRaw = [] with open(file1) as fh: ParametersRaw = fh.readlines() fh.close() NumberOfColumns = 7 NumberOfRows = len(ParametersRaw)/NumberOfColumns Parameters = [[],[]] i=0 j=0 k=0 while (i < NumberOfRows): while (j < NumberOfColumns): k = (i*NumberOfColumns)+j Parameters[i][j] = ParametersRaw[k] j = j + 1 i = i + 1 j = 0 it fails at the line "Parameters[i][j] = ParametersRaw[k]" with error: IndexError: index 0 is out of bounds for axis 0 with size 0 In case of populating 1D array I would use append() method. But in case of 2D I am lost of how append() can be applied. Could some one help newbie. CU From __peter__ at web.de Sat Nov 21 06:23:31 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 Nov 2015 12:23:31 +0100 Subject: Problem to read from array References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> Message-ID: vostrushka at gmail.com wrote: > Hi, > I have a file with one parameter per line: > a1 > b1 > c1 > a2 > b2 > c2 > a3 > b3 > c3 > ... > The parameters are lines of characters (not numbers) > > I need to load it to 2D array for further manipulations. > So far I managed to upload this file into 1D array: > > ParametersRaw = [] No need for this assignment as you throw the value away. > with open(file1) as fh: > ParametersRaw = fh.readlines() > fh.close() The with open() ... statement already ensures that the file is closed. > NumberOfColumns = 7 > NumberOfRows = len(ParametersRaw)/NumberOfColumns > > Parameters = [[],[]] > i=0 > j=0 > k=0 > while (i < NumberOfRows): > while (j < NumberOfColumns): > k = (i*NumberOfColumns)+j > Parameters[i][j] = ParametersRaw[k] The inner lists Parameters[i] are empty so every assignment Parameters[i][k] = ... will fail. While the minimal fix is to use append() Parameters[i].append(ParametersRaw[k]) you will run into the same problem with the rows if there are more than the two you prepared for in the line > Parameters = [[],[]] > j = j + 1 > i = i + 1 > j = 0 > > it fails at the line "Parameters[i][j] = ParametersRaw[k]" with error: > > IndexError: index 0 is out of bounds for axis 0 with size 0 > > In case of populating 1D array I would use append() method. > But in case of 2D I am lost of how append() can be applied. > Could some one help newbie. As a general remark in idiomatic Python the loop i = 0 while i < THRESHOLD: ... i = i + 1 is written as a for loop with range(): for i in range(THRESHOLD): ... For your specific problem list slicing is a good approach: COLUMNS = 7 with open(file1) as f: parameters_raw = f.readlines() parameters = [] for row_start in range(0, len(parameters_raw), COLUMNS): parameters.append(parameters_raw[row_start:row_start+COLUMNS]) From gengyangcai at gmail.com Sat Nov 21 08:20:05 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 21 Nov 2015 05:20:05 -0800 (PST) Subject: *= operator Message-ID: This is a piece of code that calculates tax and tip : def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return bill def tip(bill): """Adds 15% tip to a restaurant bill.""" bill *= 1.15 print "With tip: %f" % bill return bill meal_cost = 100 meal_with_tax = tax(meal_cost) meal_with_tip = tip(meal_with_tax) Does bill *= 1.08 mean bill = bill * 1.15 ? From bc at freeuk.com Sat Nov 21 08:37:25 2015 From: bc at freeuk.com (BartC) Date: Sat, 21 Nov 2015 13:37:25 +0000 Subject: *= operator In-Reply-To: References: Message-ID: On 21/11/2015 13:20, Cai Gengyang wrote: > This is a piece of code that calculates tax and tip : > > def tax(bill): > """Adds 8% tax to a restaurant bill.""" > bill *= 1.08 > print "With tax: %f" % bill > return bill > > def tip(bill): > """Adds 15% tip to a restaurant bill.""" > bill *= 1.15 > print "With tip: %f" % bill > return bill > > meal_cost = 100 > meal_with_tax = tax(meal_cost) > meal_with_tip = tip(meal_with_tax) > > Does bill *= 1.08 mean bill = bill * 1.15 ? bill *= 1.08 would mean bill = bill*1.08 (not 1.15; I assume that's a typo). Although you can never be 100% sure in Python (as * or *= could have been redefined to do something else), there's no reason to suspect that here. Also, there's probably some technical difference that someone could up with (*= doing in-place modification for example), but that shouldn't matter when bill is just a number. -- Bartc From steve at pearwood.info Sat Nov 21 08:39:44 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 22 Nov 2015 00:39:44 +1100 Subject: *= operator References: Message-ID: <56507422$0$1594$c3e8da3$5496439d@news.astraweb.com> On Sun, 22 Nov 2015 12:20 am, Cai Gengyang wrote: > Does bill *= 1.08 mean bill = bill * 1.15 ? No. It means `bill = bill * 1.08`, not 1.15. -- Steven From frank at chagford.com Sat Nov 21 08:46:46 2015 From: frank at chagford.com (Frank Millman) Date: Sat, 21 Nov 2015 15:46:46 +0200 Subject: *= operator In-Reply-To: References: Message-ID: "Cai Gengyang" wrote in message news:a76b1b5b-4321-41bb-aeca-0dac787752d9 at googlegroups.com... > This is a piece of code that calculates tax and tip : > > def tax(bill): > """Adds 8% tax to a restaurant bill.""" > bill *= 1.08 > print "With tax: %f" % bill > return bill > > def tip(bill): > """Adds 15% tip to a restaurant bill.""" > bill *= 1.15 > print "With tip: %f" % bill > return bill > > meal_cost = 100 > meal_with_tax = tax(meal_cost) > meal_with_tip = tip(meal_with_tax) > > Does bill *= 1.08 mean bill = bill * 1.15 ? Firstly, I assume that you actually meant 'bill = bill * 1.08' at the end of the last line. Secondly, how can I help you to answer this kind of question yourself. Here are two ways. 1. Try it out at the interpreter - c:\> Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> bill = 100 >>> bill *= 1.08 >>> bill I deliberately omitted the last line. Try it yourself and see what you get. 2. Read the fine manual. The Index has a section headed 'Symbols'. From there you will find '*=', with a link to 'augmented assignment'. If you follow the link, you will find a detailed explanation. Here is an excerpt - "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a similar, but not exactly equal effect. In the augmented version, x is only evaluated once. Also, when possible, the actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, the old object is modified instead." Frank Millman From gengyangcai at gmail.com Sat Nov 21 08:55:49 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 21 Nov 2015 05:55:49 -0800 (PST) Subject: *= operator In-Reply-To: References: Message-ID: <43e70c39-30a0-45c6-9414-c98304bf829f@googlegroups.com> >>> bill = 100 >>> bill *= 1.08 >>> bill 108.0 >>> On Saturday, November 21, 2015 at 9:47:29 PM UTC+8, Frank Millman wrote: > "Cai Gengyang" wrote in message > news:a76b1b5b-4321-41bb-aeca-0dac787752d9 at googlegroups.com... > > > This is a piece of code that calculates tax and tip : > > > > def tax(bill): > > """Adds 8% tax to a restaurant bill.""" > > bill *= 1.08 > > print "With tax: %f" % bill > > return bill > > > > def tip(bill): > > """Adds 15% tip to a restaurant bill.""" > > bill *= 1.15 > > print "With tip: %f" % bill > > return bill > > > > meal_cost = 100 > > meal_with_tax = tax(meal_cost) > > meal_with_tip = tip(meal_with_tax) > > > > Does bill *= 1.08 mean bill = bill * 1.15 ? > > Firstly, I assume that you actually meant 'bill = bill * 1.08' at the end of > the last line. > > Secondly, how can I help you to answer this kind of question yourself. > > Here are two ways. > > 1. Try it out at the interpreter - > > c:\> > Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit > (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> bill = 100 > >>> bill *= 1.08 > >>> bill > > I deliberately omitted the last line. Try it yourself and see what you get. > > 2. Read the fine manual. > > The Index has a section headed 'Symbols'. From there you will find '*=', > with a link to 'augmented assignment'. > > If you follow the link, you will find a detailed explanation. Here is an > excerpt - > > "An augmented assignment expression like x += 1 can be rewritten as x = x + > 1 to achieve a similar, but not exactly equal effect. In the augmented > version, x is only evaluated once. Also, when possible, the actual operation > is performed in-place, meaning that rather than creating a new object and > assigning that to the target, the old object is modified instead." > > Frank Millman From joel.goldstick at gmail.com Sat Nov 21 08:58:34 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 21 Nov 2015 08:58:34 -0500 Subject: *= operator In-Reply-To: <56507422$0$1594$c3e8da3$5496439d@news.astraweb.com> References: <56507422$0$1594$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Nov 21, 2015 at 8:39 AM, Steven D'Aprano wrote: > On Sun, 22 Nov 2015 12:20 am, Cai Gengyang wrote: > > > Does bill *= 1.08 mean bill = bill * 1.15 ? > > No. It means `bill = bill * 1.08`, not 1.15. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > Others have answered, but don't forget to try things like this yourself in the interactive python shell of your choice: Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> bill = 1 >>> bill *=1.08 >>> bill 1.08 >>> -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From lac at openend.se Sat Nov 21 09:22:55 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 21 Nov 2015 15:22:55 +0100 Subject: Problem to read from array In-Reply-To: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> Message-ID: <201511211422.tALEMtE0032395@fido.openend.se> In Python we don't write while loops that often. instead we do: for i in range(NumberOfColumns): for j in range(NumberOfRows): do_something() But for the particular case that you are after, constructing lists, we have something even neater -- list comprehensions. So you might write: >>> newarray=[] >>> for i in range(3): ... newarray[i] = i And this would not work. Traceback (most recent call last): File "", line 2, in IndexError: list assignment index out of range At this point you might get a bit frustrated. Python is happily telling you that you don't have a newarray[0][0] which is hardly news to you who was trying to initialise the thing. The trick is to initialise it with a list comprehension. You write one like this: [ calculate_something() for i in range(LIMIT)] This works: >>> newarray = [i for i in range(3)] >>> newarray [0, 1, 2] >>> As does >>> newarray = ["hello" for i in range(3)] >>> newarray ['hello', 'hello', 'hello'] You can even build your lists with a condition: >>> even_numbers=[x for x in range(11) if x % 2 == 0] >>> even_numbers [0, 2, 4, 6, 8, 10] You are not limited to one dimentional arrays (lists) here. You can have much more complicated expressions as the calculate_something. >>> newarray =[[ [x+2000, y*y] for x in range(3)] for y in range(5)] >>> newarray [[[2000, 0], [2001, 0], [2002, 0]], [[2000, 1], [2001, 1], [2002, 1]], [[2000, 4], [2001, 4], [2002, 4]], [[2000, 9], [2001, 9], [2002, 9]], [[2000, 16], [2001, 16], [2002, 16]]] Which leads us to a particularly useful construct: >>> emptyarray =[[ [] for x in range(3)] for y in range(5)] >>> emptyarray [[[], [], []], [[], [], []], [[], [], []], [[], [], []], [[], [], []]] Bingo. Now you won't have any index errors when you try to append to your x,y values. Hope this is useful. Also, there is the tutor mailing list https://mail.python.org/mailman/listinfo/tutor which you might be interested in, where we discuss things like this. Peter Otten is there, too. Laura From ian.g.kelly at gmail.com Sat Nov 21 10:01:05 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 21 Nov 2015 08:01:05 -0700 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: On Sat, Nov 21, 2015 at 1:46 AM, Chris Angelico wrote: > On Sat, Nov 21, 2015 at 7:38 PM, Todd wrote: >> Rather than a dedicated syntax, might this be something that could be >> handled by a built-in decorator? >> >> Maybe something like: >> >> @late_binding >> def myfunc(x, y=[]): > > No, it can't; by the time the decorator runs, the expression has > already been evaluated. Without syntax, this can only be done with > gross hacks like lambda functions. > > It could be done thus: > > @late_binding > def myfunc(x, y=lambda: []): > > and then the decorator could wrap the function. I'm not entirely sure > I could implement it reliably, but even leaving that aside, having to > put "lambda:" in front of everything is pretty ugly. Note that "lambda: []" can also be spelled "list". From lac at openend.se Sat Nov 21 10:05:20 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 21 Nov 2015 16:05:20 +0100 Subject: Problem to read from array In-Reply-To: <201511211422.tALEMtE0032395@fido.openend.se> References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> <201511211422.tALEMtE0032395@fido.openend.se> Message-ID: <201511211505.tALF5K8r003004@fido.openend.se> In a message of Sat, 21 Nov 2015 15:22:55 +0100, Laura Creighton writes: >At this point you might get a bit frustrated. Python is happily telling >you that you don't have a newarray[0][0] which is hardly news to you who >was trying to initialise the thing. My bad. I was thinking about 2 dimentional arrays, but of course that error is just that newarray[0] doesn't exit. (So why is it that I can read an article 3 times, find no more errors, post it, and _then_ discover one?!) Laura From bc at freeuk.com Sat Nov 21 10:26:34 2015 From: bc at freeuk.com (BartC) Date: Sat, 21 Nov 2015 15:26:34 +0000 Subject: Problem to read from array In-Reply-To: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> Message-ID: On 21/11/2015 10:41, vostrushka at gmail.com wrote: > Hi, > I have a file with one parameter per line: > a1 > b1 > c1 > a2 > b2 > c2 > a3 > b3 > c3 > ... > The parameters are lines of characters (not numbers) > > I need to load it to 2D array for further manipulations. > So far I managed to upload this file into 1D array: > > ParametersRaw = [] > with open(file1) as fh: > ParametersRaw = fh.readlines() > fh.close() I tried this code based on yours: with open("input") as fh: lines=fh.readlines() rows = len(lines)//3 params=[] index=0 for row in range(rows): params.append([lines[index],lines[index+1],lines[index+2]]) index += 3 for row in range(rows): print (row,":",params[row]) For the exact input you gave, it produced this output: 0 : ['a1\n', 'b1\n', 'c1\n'] 1 : ['a2\n', 'b2\n', 'c2\n'] 2 : ['a3\n', 'b3\n', 'c3\n'] Probably you'd want to get rid of those \n characters. (I don't know how off-hand as I'm not often write in Python.) The last bit could also be written: for param in params: print (params) but I needed the row index. -- BartC From nhilterbrand at gmail.com Sat Nov 21 10:52:06 2015 From: nhilterbrand at gmail.com (Nathan Hilterbrand) Date: Sat, 21 Nov 2015 10:52:06 -0500 Subject: Problem to read from array In-Reply-To: References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> Message-ID: <56509326.70906@gmail.com> On 11/21/2015 10:26 AM, BartC wrote: > On 21/11/2015 10:41, vostrushka at gmail.com wrote: >> Hi, >> I have a file with one parameter per line: >> a1 >> b1 >> c1 >> a2 >> b2 >> c2 >> a3 >> b3 >> c3 >> ... >> The parameters are lines of characters (not numbers) >> >> I need to load it to 2D array for further manipulations. >> So far I managed to upload this file into 1D array: >> >> ParametersRaw = [] >> with open(file1) as fh: >> ParametersRaw = fh.readlines() >> fh.close() > > I tried this code based on yours: > > with open("input") as fh: > lines=fh.readlines() > > rows = len(lines)//3 > > params=[] > index=0 > > for row in range(rows): > params.append([lines[index],lines[index+1],lines[index+2]]) > index += 3 > > for row in range(rows): > print (row,":",params[row]) > > For the exact input you gave, it produced this output: > > 0 : ['a1\n', 'b1\n', 'c1\n'] > 1 : ['a2\n', 'b2\n', 'c2\n'] > 2 : ['a3\n', 'b3\n', 'c3\n'] > > Probably you'd want to get rid of those \n characters. (I don't know > how off-hand as I'm not often write in Python.) > > The last bit could also be written: > > for param in params: > print (params) > > but I needed the row index. > To get rid of the '\n' (lineend) characters: with open(file1) as fh: ParametersRaw = [line.strip() for line in fh.readlines()] or, more succinctly.. with open(file1) as fh: ParametersRaw = [line.strip() for line in fh] Comprehensions are your friend. Nathan From sailor at lists.xtsubasa.org Sat Nov 21 11:57:37 2015 From: sailor at lists.xtsubasa.org (Pavel Volkov) Date: Sat, 21 Nov 2015 19:57:37 +0300 Subject: anyone tell me why my program will not =?iso-8859-1?Q?run=3F?= In-Reply-To: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> References: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> Message-ID: On ???????, 21 ?????? 2015 ?. 6:30:02 MSK, Dylan Riley wrote: > i am learning python and was tasked with making a program that > flips a coin 100 times and then tells you > the number of heads and tails. > First, you have a syntax error: if result = heads: should be: if result == heads: Second, there's incorrent indentation, your while loop is almost empty (not syntax error though). From rosuav at gmail.com Sat Nov 21 12:02:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Nov 2015 04:02:13 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: On Sun, Nov 22, 2015 at 2:01 AM, Ian Kelly wrote: >> and then the decorator could wrap the function. I'm not entirely sure >> I could implement it reliably, but even leaving that aside, having to >> put "lambda:" in front of everything is pretty ugly. > > Note that "lambda: []" can also be spelled "list". In that particular example, yes. I kept it in the large form to maintain the parallel with the version I was quoting. But if the decorator were to be written, it would probably be something along the lines of "if the default is callable, do the late-binding magic", so 'list' would work just fine. ChrisA From sailor at lists.xtsubasa.org Sat Nov 21 12:15:05 2015 From: sailor at lists.xtsubasa.org (Pavel Volkov) Date: Sat, 21 Nov 2015 20:15:05 +0300 Subject: anyone tell me why my program will not =?iso-8859-1?Q?run=3F?= In-Reply-To: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> References: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> Message-ID: <43bd9327-3fc8-4264-a62e-f4a62f21e21c@lists.xtsubasa.org> On ???????, 21 ?????? 2015 ?. 6:30:02 MSK, Dylan Riley wrote: Also some more notes: > heads = int("1") > tails = int("2") Why use this strange initialization? The usual way: heads = 1 tails = 2 gives the same result. > while flips != 0: > flips -= 1 There's no need to use while and flips variable: for _ in range(100): if random.randint(heads, tails) == heads: headscount += 1 else: tailscount += 1 Also, it's good to put import at the beginning. From david007killer at gmail.com Sat Nov 21 13:49:21 2015 From: david007killer at gmail.com (david burstein) Date: Sat, 21 Nov 2015 10:49:21 -0800 (PST) Subject: using re.split function Message-ID: im pretty new in python and i didnt get how to use the re.split function. for example if i have a string and i want to split it by two conditions: first one splitting when " [ " appears second one when "]" appears From python at mrabarnett.plus.com Sat Nov 21 14:20:55 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 21 Nov 2015 19:20:55 +0000 Subject: using re.split function In-Reply-To: References: Message-ID: <5650C417.9060400@mrabarnett.plus.com> On 2015-11-21 18:49, david burstein wrote: > im pretty new in python and i didnt get how to use the re.split function. > for example if i have a string and i want to split it by two conditions: > first one splitting when " [ " appears second one when "]" appears > re.split(r" \[ |\]", string) You need to escape the "[" because it normally indicates the start of a character set. From teamprimalforce at gmail.com Sat Nov 21 16:27:52 2015 From: teamprimalforce at gmail.com (Lee Bradley) Date: Sat, 21 Nov 2015 13:27:52 -0800 (PST) Subject: need help understanding a python program In-Reply-To: References: Message-ID: <0408f311-270d-49cb-9a21-48310bfa82f8@googlegroups.com> On Monday, November 2, 2015 at 1:45:58 PM UTC-5, Ben Finney wrote: > Lee Bradley writes: > > > http://pastebin.com/ndDYjYe1 > > We much prefer to discuss code in the context of plain text messages > right here, because this forum is archived longer than the expected > lifetime of content hosted on other services. > > > For now I am looking for someone who can dig into this code and > > explain what's going on. I understand a lot of it but not enough to > > really *get it*. > > Could you discuss your own impressions of it so far, with (parts of) the > code pasted here as plain text for context of your commentary? > > -- > \ Moriarty: "Forty thousand million billion dollars? That money | > `\ must be worth a fortune!" --The Goon Show, _The Sale of | > _o__) Manhattan_ | > Ben Finney Ben, Sorry it took so long to get back on this. I did start to put together a response to you. I made all sorts of notes about what I understood and what I didn't understand. But in the end I tried to write a solution myself using his ideas and what I had learned from many things I learned on the subject. I believe I have a working program which I have written in C. http://primepuzzle.com/tc/entropy.c Incredibly interesting exercise. I am awaiting any feedback Vitaly might have on what I have built. Lee From gengyangcai at gmail.com Sat Nov 21 17:16:27 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 21 Nov 2015 14:16:27 -0800 (PST) Subject: Comparators Message-ID: Comparators, interesting ... >>> booltwo = (10 + 18) == 3**17 >>> booltwo False >>> boolone = (50 - 35) > 35 >>> boolone False >>> booltwo = (65 - 35) > 15 >>> booltwo True >>> boolalpha = 3 < 6 >>> boolalpha True >>> boolbeta = 100 == 10*30 >>> boolbeta False >>> From jon+usenet at unequivocal.co.uk Sat Nov 21 17:21:53 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sat, 21 Nov 2015 22:21:53 -0000 (UTC) Subject: Comparators References: Message-ID: On 2015-11-21, Cai Gengyang wrote: > Comparators, interesting ... > >>>> booltwo = (10 + 18) == 3**17 >>>> booltwo > False What's interesting about that? From gengyangcai at gmail.com Sat Nov 21 17:49:36 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 21 Nov 2015 14:49:36 -0800 (PST) Subject: Comparators In-Reply-To: References: Message-ID: Hmm .. I am a slow learner and have poor memory. Sometimes when I see a new programming operator, I have to type it out so that I can remember it and let it sink into my brain On Sunday, November 22, 2015 at 6:24:28 AM UTC+8, Jon Ribbens wrote: > On 2015-11-21, Cai Gengyang wrote: > > Comparators, interesting ... > > > >>>> booltwo = (10 + 18) == 3**17 > >>>> booltwo > > False > > What's interesting about that? From rosuav at gmail.com Sat Nov 21 18:00:51 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Nov 2015 10:00:51 +1100 Subject: Comparators In-Reply-To: References: Message-ID: On Sun, Nov 22, 2015 at 9:49 AM, Cai Gengyang wrote: > Hmm .. I am a slow learner and have poor memory. Sometimes when I see a new programming operator, I have to type it out so that I can remember it and let it sink into my brain > I recommend creating a text file of notes. Every time you learn something new, add it to your notes file - and commit the change to git. Then, when you come back to the file, you'll have one of several reactions: 1) "Yeah, that's right! Good stuff to remember." - it's done its job by reminding you. 2) "Wait, what? How does that work?" - add some clarification notes. 3) "Of course it's like that. I know that. Don't need that any more." - remove it (and commit the change to git). Every time #3 comes up, you know you're learning - you're becoming a better programmer. And it will, often. This isn't something just for "novice" or "beginning" programmers, either; I have a file like that, although not only about programming. (This week, I added notes about using iptables to NAT from one IP address to a completely different one, and change the port number used, which basically let me deploy a temporary bouncer on a cheap cloud server, getting around a temporary outage here. Worth doing.) Some stuff will stay there for a long time, ready for you to look it up whenever you need it. Other stuff will come and go. All of it is useful. ChrisA From orgnut at yahoo.com Sat Nov 21 21:44:17 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 21 Nov 2015 18:44:17 -0800 Subject: anyone tell me why my program will not run? In-Reply-To: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> References: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> Message-ID: On 11/20/2015 07:30 PM, Dylan Riley wrote: > i am learning python and was tasked with making a program that flips a coin 100 times and then tells you > the number of heads and tails. > > I have done so coming up with this piece of work but it doesnt run can anyone help me out? > > #This is credited to dylan > > print(" \\ \\ \\ \\ \\ \\ \\ \\ D FLIPS \\ \\ \\ \\ \\ \\ \\ \\") > print("\n\nThis is D's coin flipper program. You get 100 flips. \n\t LETS SEE HOW LUCKY YOU ARE") > input("Press enter") > > import random > > heads = int("1") > tails = int("2") > flips = 100 > headscount = 0 > tailscount = 0 > > while flips != 0: > flips -= 1 > > result = random.randint(heads, tails) > if result = heads: > headscount += 1 > else: > tailscount += 1 > > > print(headscount, tailscount) > > input("press enter to exit") > It doesn't run because it if full of errors, which have already been discussed by others. I just wanted to show you a (radically) different approach that you can study (or not... your choice). I'm leaving out your heading and just showing the heart of the program. I am not necessarily recommending this, I just wanted you to see a different way of looking at the problem. Except for the initialization and printing of the results, the entire thing is done in one two-line for loop. from random import randint # Put your heading text here... HEADS = 0 TAILS = 1 # Note: Python _convention_ is to upper-case constants. counts = [0, 0] for flips in range(100): counts[randint(0, 1)] += 1 print('Number of heads: ', counts[HEADS]) print('Number of tails: ', counts[TAILS]) Note that the HEADS and TAILS constants are only used in one place (the final print functions), you could simply leave them out and directly use 0 and 1 in those final print()s. -=- Larry -=- From benjamin at python.org Sat Nov 21 21:48:27 2015 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 21 Nov 2015 18:48:27 -0800 Subject: [RELASE] Python 2.7.11 release candidate 1 Message-ID: <1448160507.1985354.446437097.5E584CD6@webmail.messagingengine.com> Greetings, It is my duty and honor to announce the immediate availability of Python 2.7.11 release candidate 1. Python 2.7.11 will be another bug fix release for the 2.7.x series. Downloads are at: https://www.python.org/downloads/release/python-2711rc1/ Please test the candidate and report bugs to https://bugs.python.org If no serious problems are found, 2.7.11 final will be released in two weeks. Regards, Benjamin Peterson (on behalf of Python 2.7.11's contributors) From steve at pearwood.info Sat Nov 21 22:43:42 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 22 Nov 2015 14:43:42 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 10:59 pm, BartC wrote: > On 20/11/2015 01:05, Steven D'Aprano wrote: >> Here's another use for function defaults, as static storage: [...] >> This is a quick and easy way to memoise a function which would otherwise >> be horribly slow. And it only works because _memo is bound to a mutable >> object once, and once only. > > We're arguing at cross-purposes then since you are obviously interested > in these esoteric aspects, Memoisation isn't "esoteric", it is a simple, basic and widely-used technique used to improve performance of otherwise expensive functions. Quite frankly, to call it such demonstrates a considerable level of ignorance about basic programming idioms. Not just Python, but general purpose programming. Instead of being so judgemental, why don't you take this as an opportunity to open your mind to new programming styles? The purpose of learning a new language is to open our minds to new ways of solving problems. If all we are going to do is bitch and moan that the new language isn't exactly the same as the old one we already know, we might as well just stick to using the old one and not even bother learning anything new. > but all I want to do is avoid remembering a > long list of defaults. Here's an example from another language, a > function I'm working on at the minute: [...] > (Here, however, the language doesn't like you doing in-place > modification of a parameter unless the '&' is used, in which case you > wouldn't be able to assign a default value such as () as you can only > pass l-values.) It sounds to me like you have implemented something like Pascal's "var" parameters, is that right? I believe some languages (VB perhaps?) call them "output parameters". >> def test(arg=[]): >> arg.append(1) >> return len(arg) >> >> >> The binding arg=[] is NOT inside the body of the function. Therefore, it >> is NOT executed repeatedly, but only once. > > OK, so the "=" is misleading if not a lie. No. Why would you conclude that? If I called the function like so: test( [1, 2, 3, 4, 5] ) and got the result 6, would I conclude that the "=" is misleading if not a lie? After all, the function declaration clearly shows arg being assigned the value [], so why am I getting 6 as the result instead of 1? The whole point of parameter default arguments is that they are bound to the parameter *only* if the parameter otherwise isn't given a value. That's a separate issue from *when* the default expression is evaluated. It can be evaluated only once, or it can be evaluated every single time you call the function. Both are legitimate techniques, both have their uses, and both have their limitations. >>>>> That [] doesn't look like an object that could change. >>>> >>>> Of course it does. >>> >>> You've lost me know. > >> a = [] >> a.append(1) >> >> Are you shocked to learn that a is no longer an empty list? > > No. But I would be surprised if, after this point, [] is no longer an > empty list either! Of course [] is an empty list. But the question isn't what [] represents, it is what value `a` has. Since [] creates a list (not a tuple), and lists can be modified in place, anyone familiar with Python should expect that just because you see `a = []` somewhere doesn't mean that `a` will always be an empty list. `a` can change. (Of course, any variable can change if you re-assign it.) > No, forget that; by now, I wouldn't be surprised at all! > > (That [] isn't changed is probably thanks to [] being implemented with > the BUILD_LIST byte-code, which constructs a brand-new empty list each > time. So the next time [] is used, it will be a different one from the > one that has just been appended to. Right. That's not an accident either. There isn't a single global empty list shared between all Python variables. There *could be* (but probably isn't) a single global empty tuple, since tuples are immutable and anything set to the empty tuple must remain the empty tuple forever (or until re-assigned to something else), so there would be no harm in having all such variables share the same object. But lists don't work like that, because they are mutable. > In my language, a construct such as [10,20,30] is evaluated just once at > start-up. I don't understand that explanation. How does that work? Given: x = [10, 20, 30] y = [10, 20, 30] how does your language know what value y has if it doesn't evaluate the second construct? -- Steven From steve at pearwood.info Sat Nov 21 22:58:14 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 22 Nov 2015 14:58:14 +1100 Subject: What is a function parameter =[] for? References: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56513d58$0$1619$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 02:42 am, Ian Kelly wrote: > On Thu, Nov 19, 2015 at 5:45 AM, Steven D'Aprano > wrote: >> But if you want the default value to be evaluated exactly once, and once >> only, there is no real alternative to early binding. You could use a >> global variable, of course, but that is no solution -- that's a problem >> waiting to happen. > > It doesn't have to be a global. In a Python with late binding > defaults, this would work to get early binding: > > def f(x=f.default_x): > ... > > f.default_x = something() Ah, of course it can. Good catch. As an illustration of how your expectations can colour your thinking, I actually considered that, but rejected it as a possibility because f.default_x couldn't be created until the function came into existence, and the function couldn't come into existence until after f.default_x was evaluated. In other words, I was making the complementary error to BartC's: I was still thinking in terms of early binding, when describing late binding. In fact, what Python actually does is rather similar, except that instead of "f.default_x" it uses f.__defaults__[0]. Roughly speaking, the function declaration def f(x=something()): ... using early-binding is somewhat analogous to this using late-binding: def f(x=f.__defaults__[0]): ... f.__defaults__ = (something(), ) > Of course, assignment to function attributes is a relatively modern > thing that is only permitted since Python 2.1, whereas function > defaults have been around since at least 1.4, so this wouldn't have > been an option when the semantics were being determined. I suspect that had Guido decided on late binding as the preferred semantics, he would have allowed function attributes much earlier. -- Steven From gengyangcai at gmail.com Sun Nov 22 01:30:13 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 21 Nov 2015 22:30:13 -0800 (PST) Subject: print("%.2f" % total) Message-ID: meal = 44.50 tax = 0.0675 tip = 0.15 meal = meal + meal * tax total = meal + meal * tip print("%.2f" % total) What do the lines inside the parentheses in this statement print("%.2f" % total) mean ? What does "%.2f" % total represent ? Thanks alot ... Gengyang From stephane at wirtel.be Sun Nov 22 02:01:02 2015 From: stephane at wirtel.be (Stephane Wirtel) Date: Sun, 22 Nov 2015 08:01:02 +0100 Subject: print("%.2f" % total) In-Reply-To: References: Message-ID: <20151122070102.GA1935@sg1> print the two digits after the point. On 11/21, Cai Gengyang wrote: > > meal = 44.50 > tax = 0.0675 > tip = 0.15 > > meal = meal + meal * tax > total = meal + meal * tip > > print("%.2f" % total) > > What do the lines inside the parentheses in this statement print("%.2f" % total) mean ? > > What does "%.2f" % total represent ? > > Thanks alot ... > > Gengyang > -- > https://mail.python.org/mailman/listinfo/python-list -- St?phane Wirtel - http://wirtel.be - @matrixise From rosuav at gmail.com Sun Nov 22 02:21:46 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Nov 2015 18:21:46 +1100 Subject: print("%.2f" % total) In-Reply-To: References: Message-ID: On Sun, Nov 22, 2015 at 5:30 PM, Cai Gengyang wrote: > What do the lines inside the parentheses in this statement print("%.2f" % total) mean ? > > What does "%.2f" % total represent ? > This is called "percent formatting" or "printf-style formatting". It's a means of formatting a tuple of values (or in this case, a single value) into a string; the percent sign introduces a format string, and the letter (in this case 'f') ends it, and says what kind of formatting to use. Everything else is just part of the string. >>> "Hello, %s!" % "world" 'Hello, world!' >>> "%d + %d = %o... in octal! I'M FINE!" % (4, 4, 8) "4 + 4 = 10... in octal! I'M FINE!" As you can see, you can play with this at the interactive prompt to find out what's happening. ChrisA From frank at chagford.com Sun Nov 22 02:29:54 2015 From: frank at chagford.com (Frank Millman) Date: Sun, 22 Nov 2015 09:29:54 +0200 Subject: print("%.2f" % total) In-Reply-To: References: Message-ID: "Cai Gengyang" wrote in message news:d34dc21b-fe74-40fc-9b54-c371105290f2 at googlegroups.com... > meal = 44.50 > tax = 0.0675 > tip = 0.15 > > meal = meal + meal * tax > total = meal + meal * tip > > print("%.2f" % total) > > What do the lines inside the parentheses in this statement print("%.2f" % > total) mean ? > > What does "%.2f" % total represent ? >From the Fine Manual - Index > Symbols > '%' > Formatting takes you to a section headed "printf-style String Formatting". "Given format % values (where format is a string), % conversion specifications in format are replaced with zero or more elements of values" A conversion specifier consists of two or more characters, of which the first is always '%', and the rest provide a wide variety of formatting options. Precision (optional) is given as a '.' (dot) followed by the precision, so '.2' means show the result with a precision of 2. 'f' is a conversion type which represents 'floating point decimal format'. Note the following warning - "The formatting operations described here exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer str.format() interface helps avoid these errors, and also provides a generally more powerful, flexible and extensible approach to formatting text." Using str.format(), your example would look like this - print('{:.2f}'.format(total)) Another word of warning. Using a format specifier displays the value nicely rounded to a number of decimal places, but the original value is unchanged. Use the interpreter to see what the actual value is. For serious work involving monetary values, you should look at the Decimal module. Frank Millman From steve at pearwood.info Sun Nov 22 05:06:24 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 22 Nov 2015 21:06:24 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Message-ID: <565193a1$0$1593$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 11:53 pm, BartC wrote: > On 20/11/2015 12:28, Marko Rauhamaa wrote: >> Even more appropriately, you may expressly want a mutable, singleton >> object to be the default: >> >> def initiate_query(query, database=global_database): > > Finally, a down-to-earth example. Really? Astonishing. To me, the Ackermann's function is a straight-forward, simple example. It is, after all, a pure mathematical function in the true sense: it has no side-effects, it takes some arguments, and returns a result. (Of course, the Python implementation I gave has the side-effect of keeping a cache of past results, but that's just an implementation detail.) Whereas this initiate_query example is the opposite of straight-forward. It involves a database, which means side-effects. The very opposite of a pure function. Besides, I've never written database code in my life, which makes it weird and exotic to me. (If lambda is exotic to you because your personal experience happens to have avoided that area, databases are equally exotic to me for the same reason. The lesson here is: programming covers a HUGE range of topics. Don't assume that the blind-spots in your experience don't exist or aren't important, because they will be to someone. What's exotic to you is boring and common-place to somebody else, and vice versa. > Here it probably doesn't matter at > what point 'global_database' gets bound. You know it will always refer > to the current state of global_database, No. You've got that completely backwards. With early binding semantics (or "early evaluation" if you prefer), the default object will be the value of global_data at the time the function declaration runs. Subsequent rebindings of the global variable will not effect the default object one iota, and you will always know that the default for database will always be the same thing, whatever it was when you first defined the function: global_database = DB("abc") def initiate_query(query, database=global_database): ... global_database = DB("xyz") initiate_query(query) # here, the database used is "abc", not "xyz" But with late binding, or "late evaluation", the opposite is the case: when you finally call initiate_query, the database used will be "xyz". *This* time. Next time, it could be something else: or even nothing at all, if the global variable has been deleted. -- Steven From steve at pearwood.info Sun Nov 22 07:01:59 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 22 Nov 2015 23:01:59 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5651aeb9$0$1601$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Nov 2015 11:39 pm, BartC wrote: > What's bothering me is: > > * The large amount of mumbo-jumbo used to describe what's going on Just because you don't know the terminology doesn't make it mumbo-jumbo. That's a particularly unfair and unjustified response to make when multiple people have spent a lot of their own time, gratis, to explain what is going on. If you are willing, you can learn a lot here, one of the few places left where education is still free. > * The insistence (I think largely from Steven) that the way this feature > works is good rather than bad It is good. It's just not good for *everything*. > * The refusal to acknowledge that the def fn(a=[]) syntax is misleading. > (What value will a have when you call fn()? The true answer is that you > can't tell.) I'm not really sure that anyone has disputed that specific point. I'd say that the value of the default `a` could change, which is no different from most other uses of mutable values. This is why some people insist that mutable values are a mistake, and programming should only involve immutable, fixed, values. > * The persistent nonsense that somehow [] is mutable (what happens is > that [] is assigned to a variable, and /that/ is mutable) No, objects are mutable, or immutable, as the case may be -- Steven From marko at pacujo.net Sun Nov 22 07:35:27 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 22 Nov 2015 14:35:27 +0200 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> <565193a1$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87poz29pps.fsf@elektro.pacujo.net> Steven D'Aprano : > Really? Astonishing. To me, the Ackermann's function is a > straight-forward, simple example. I must admit I have not once in my life written an implementation of the Ackermann function. > Whereas this initiate_query example is the opposite of > straight-forward. It involves a database, which means side-effects. Again, I must hang my head and confess that I have written quite many functions with side effects. > (If lambda is exotic to you because your personal experience happens > to have avoided that area, databases are equally exotic to me for the > same reason. Lambdas are less exotic than layman programmers might think. You may never need a lambda in Python but you will need to master closures and inner classes. Marko From gandalf at shopzeus.com Sun Nov 22 07:58:09 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sun, 22 Nov 2015 13:58:09 +0100 Subject: ANN: yubistorm Message-ID: <5651BBE1.8050208@shopzeus.com> YubiStorm provides a simple module that can be used from a Tornado server to authenticate users with YubiCloud authentication servers. The PyPi package contains the module for the API only. The repository contains an example web server that can be used to understand how YubiCloud authentication works in an async way. PyPi: https://pypi.python.org/pypi/yubistorm Documentation: http://pythonhosted.org/yubistorm/ Repository: https://bitbucket.org/nagylzs/yubistorm Cheers, Laszlo From bc at freeuk.com Sun Nov 22 08:21:02 2015 From: bc at freeuk.com (BartC) Date: Sun, 22 Nov 2015 13:21:02 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22/11/2015 03:43, Steven D'Aprano wrote: > On Fri, 20 Nov 2015 10:59 pm, BartC wrote: > >> On 20/11/2015 01:05, Steven D'Aprano wrote: > >>> Here's another use for function defaults, as static storage: > [...] >>> This is a quick and easy way to memoise a function which would otherwise >>> be horribly slow. And it only works because _memo is bound to a mutable >>> object once, and once only. >> >> We're arguing at cross-purposes then since you are obviously interested >> in these esoteric aspects, > > Memoisation isn't "esoteric", it is a simple, basic and widely-used > technique used to improve performance of otherwise expensive functions. Ackermann is esoteric and so is memoisation, or at least the term is. (I use the Ackermann function frequently, but usually as a benchmark measuring how good a language implementation is at function calls, especially recursive ones. And how well it copes with large recursion depth. Adding memoisation would defeat the purpose!) But if it's used for static storage, then why not just use static storage? That's a simpler and more general concept than memoisation. If Python's 'default values' are just a device for obtaining local static storage which are otherwise not possible, then why not use terminology to say so? As I guess it's too late to do anything about the syntax. (Of course it won't be quite the same, as the caller can overwrite the local and /private/ 'static' variables at any time, but I suppose that would be yet another feature!) > Quite frankly, to call it such demonstrates a considerable level of > ignorance about basic programming idioms. Not just Python, but general > purpose programming. I've come to learn that basic idioms are best. Especially trying to understand someone else's code (or to translate into another language with a different set of advanced features). Some people delight in pulling out all the stops and using all the advanced features of a language to the hilt. With the result being very concise and clever code, but completely unreadable. >> (Here, however, the language doesn't like you doing in-place >> modification of a parameter unless the '&' is used, > It sounds to me like you have implemented something like Pascal's "var" > parameters, is that right? I believe some languages (VB perhaps?) call > them "output parameters". (Something like that. Python seems to exclusively to push around references to objects. I use a mix of value objects and part-references. The & is an indication to use full references. I can also use actual pointers, but I'm trying to get away from that.) >> OK, so the "=" is misleading if not a lie. > > No. Why would you conclude that? If I called the function like so: > > test( [1, 2, 3, 4, 5] ) > > and got the result 6, would I conclude that the "=" is misleading if not a > lie? After all, the function declaration clearly shows arg being assigned > the value [], so why am I getting 6 as the result instead of 1? That's being silly. We all know this is default value syntax. The lie is the [] not necessarily being the default value on every call. > The whole point of parameter default arguments is that they are bound to the > parameter *only* if the parameter otherwise isn't given a value. That's a > separate issue from *when* the default expression is evaluated. No, that is at the heart of matter. And it's not just a question of 'when' the 'binding' is done, but the fact that, even if we accept that the default value is evaluated when the function is defined, that value can then subsequently change. We all know now /why/ it can do so, which is an unfortunate consequence of how it's implemented. But you seem very keen to show it in a positive light. It's a feature, not a bug! >> In my language, a construct such as [10,20,30] is evaluated just once at >> start-up. > > I don't understand that explanation. How does that work? Given: > > x = [10, 20, 30] > y = [10, 20, 30] > > > how does your language know what value y has if it doesn't evaluate the > second construct? (It generates some start-up code which assigns [10,20,30] to a variable. Then that variable is used in place of that particular [10,20,30]. (It doesn't combine multiple instances of the same constant list, as that is not common. So y would be dealt with separately.) I think Python already does something along these lines for tuples, which cannot change. It means you're executing a simple LOAD instead of BUILT_LIST on N values.) -- Bartc From me at sntsh.com Sun Nov 22 08:25:29 2015 From: me at sntsh.com (Santosh Kumar) Date: Sun, 22 Nov 2015 18:55:29 +0530 Subject: How to remember last position and size (geometry) of PyQt application? Message-ID: Hello all fellow Python programmers! I am using PyQt5 (5.5.1) with Python 3.4.0 (64-bit) on Windows 8.1 64-bit. I don't think this much data was needed. :P I am having trouble restoring the position and size (geometry) of my very simple PyQt app. What I read online is that this is the default behavior and we need to use QSettings to save and retrieve settings from Windows registry, which is stored in `\\HKEY_CURRENT_USER\Software\[CompanyName]\[AppName]\`. Here are some of the links are read: http://doc.qt.io/qt-5.5/restoring-geometry.html http://doc.qt.io/qt-5.5/qwidget.html#saveGeometry http://doc.qt.io/qt-5.5/qsettings.html#restoring-the-state-of-a-gui-application and the last one: https://ic3man5.wordpress.com/2013/01/26/save-qt-window-size-and-state-on-closeopen/ I could have followed those tutorials but those tutorials/docs were written for C++ users. C++ is not my glass of beer. Should I expect help from you guys? :) Here is minimal working application: import sys from PyQt5.QtWidgets import QApplication, QWidget class sViewer(QWidget): """Main class of sViewer""" def __init__(self): super(sViewer, self).__init__() self.initUI() def initUI(self): self.show() if __name__ == '__main__': app = QApplication(sys.argv) view = sViewer() sys.exit(app.exec_()) From bc at freeuk.com Sun Nov 22 09:28:34 2015 From: bc at freeuk.com (BartC) Date: Sun, 22 Nov 2015 14:28:34 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22/11/2015 13:21, BartC wrote: > On 22/11/2015 03:43, Steven D'Aprano wrote: >> Quite frankly, to call it such demonstrates a considerable level of >> ignorance about basic programming idioms. Not just Python, but general >> purpose programming. > > I've come to learn that basic idioms are best. I may have misunderstood what you meant by 'basic idioms' here. It seems we disagree as to what is 'basic'. -- bartc From gordon at panix.com Sun Nov 22 11:39:08 2015 From: gordon at panix.com (John Gordon) Date: Sun, 22 Nov 2015 16:39:08 +0000 (UTC) Subject: anyone tell me why my program will not run? References: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> Message-ID: In <1737402a-2f4d-440a-abd7-6cc500f673e1 at googlegroups.com> Dylan Riley writes: > heads = int("1") Why are you taking the int value of a string constant? If you know you want the value 1, why not just use it directly? > flips = 100 > headscount = 0 > tailscount = 0 > while flips != 0: > flips -= 1 This loop has no other effect than to set flips to zero, so why not just set flips to zero in the first place? > result = random.randint(heads, tails) > if result = heads: > headscount += 1 > else: > tailscount += 1 Perhaps you meant to have this piece of code indented under the while loop above? -- 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 orgnut at yahoo.com Sun Nov 22 16:42:20 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 22 Nov 2015 13:42:20 -0800 Subject: anyone tell me why my program will not run? In-Reply-To: References: <1737402a-2f4d-440a-abd7-6cc500f673e1@googlegroups.com> Message-ID: On 11/21/2015 06:44 PM, Larry Hudson wrote: > On 11/20/2015 07:30 PM, Dylan Riley wrote: >> i am learning python and was tasked with making a program that flips a coin 100 times and then >> tells you >> the number of heads and tails. >> [snip] >> import random >> >> heads = int("1") >> tails = int("2") >> flips = 100 >> headscount = 0 >> tailscount = 0 >> >> while flips != 0: >> flips -= 1 >> >> result = random.randint(heads, tails) >> if result = heads: >> headscount += 1 >> else: >> tailscount += 1 >> >> >> print(headscount, tailscount) [snip] > It doesn't run because it if full of errors, which have already been discussed by others. > > I just wanted to show you a (radically) different approach that you can study (or not... your > choice). I'm leaving out your heading and just showing the heart of the program. I am not > necessarily recommending this, I just wanted you to see a different way of looking at the > problem. Except for the initialization and printing of the results, the entire thing is done in > one two-line for loop. > > > from random import randint > > # Put your heading text here... > > HEADS = 0 > TAILS = 1 # Note: Python _convention_ is to upper-case constants. > counts = [0, 0] > > for flips in range(100): > counts[randint(0, 1)] += 1 > > print('Number of heads: ', counts[HEADS]) > print('Number of tails: ', counts[TAILS]) > > > Note that the HEADS and TAILS constants are only used in one place (the final print functions), > you could simply leave them out and directly use 0 and 1 in those final print()s. > > -=- Larry -=- > I purposely didn't give any explanation of this code in my original message because I wanted to allow people (particularly the OP) a chance to figure it out by themselves. But here's a bit of explanation... The counts variable is a two-element list. It's usage is, the count of heads is counts[0] and the count of tails is counts[1] -- or equivalently, counts[HEADS] and counts[TAILS]. Both values are initialized to 0. The body of the for loop is the very terse (and confusing?) expression: counts[randint(0, 1)] += 1 But if you break it down and look at the pieces individually, it's not too hard to understand. 1. randint(0, 1) gives a random value of either 0 or 1. 2. counts[...] gives you access to the heads count or tails count (... is the 0 or 1 from the randint() function). 3. counts[...] += 1 increments the appropriate counter value. Broken down that way it?s not too hard to understand, is it? :-) -=- Larry -=- From rosuav at gmail.com Sun Nov 22 17:12:01 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Nov 2015 09:12:01 +1100 Subject: Comparators In-Reply-To: References: Message-ID: On Mon, Nov 23, 2015 at 9:01 AM, Quivis wrote: > On Sun, 22 Nov 2015 10:00:51 +1100, Chris Angelico wrote: > >> I recommend creating a text file of notes. Every time you learn >> something new, add it to your notes file - and commit the change to git. >> Then, when you come back to the file, you'll have one of several >> reactions: > > The git part is good advice. I'd like to build on your idea, though. > > Create a directory of small text files, each containing a solution to a > problem, with comments, and what not. > > When you look for something, do: > > grep 'the stuff I look for' * I'm not sure the advantage of splitting the files, but yeah, same difference. Keep notes, one way or another. ChrisA From greg.ewing at canterbury.ac.nz Sun Nov 22 18:30:02 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 23 Nov 2015 12:30:02 +1300 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: BartC wrote: > What's bothering me is: > > ... > > * The insistence (I think largely from Steven) that the way this feature > works is good rather than bad Here's one reason to prefer the way it currently works: It's rare to want a mutable default value. The vast majority of default values are simple things such as None, 0 or "". Evaluating the default expression on every call in those cases would just be useless overhead. So Python optimises for the most common case. When you need a mutable default, there is a straightforward way to get it. -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 22 18:43:52 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 23 Nov 2015 12:43:52 +1300 Subject: What is a function parameter =[] for? In-Reply-To: <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Memoisation isn't "esoteric", it is a simple, basic and widely-used > technique used to improve performance of otherwise expensive functions. That may be true, but I don't think it's a good example of a use for a shared, mutable default value, because it's arguably an *abuse* of the default value mechanism. Whenever I want to cache function values, I use a module level variable to hold the cache. It's clearer, and it doesn't clutter the function signature with something that isn't logically a part of it at all. -- Greg From steve at pearwood.info Sun Nov 22 18:44:24 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 23 Nov 2015 10:44:24 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 Nov 2015 12:21 am, BartC wrote: > But if it's used for static storage, then why not just use static > storage? That's a simpler and more general concept than memoisation. /head-desk "But if it's used for cooking, why not just cook? That's a simpler and more general concept than roasting." -- Steven From breamoreboy at yahoo.co.uk Sun Nov 22 19:04:52 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 23 Nov 2015 00:04:52 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22/11/2015 23:44, Steven D'Aprano wrote: > On Mon, 23 Nov 2015 12:21 am, BartC wrote: > >> But if it's used for static storage, then why not just use static >> storage? That's a simpler and more general concept than memoisation. > > /head-desk > > "But if it's used for cooking, why not just cook? That's a simpler and more > general concept than roasting." > What happened to "Please do not feed the trolls"? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From joel.goldstick at gmail.com Sun Nov 22 19:08:50 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 22 Nov 2015 19:08:50 -0500 Subject: Is there an meaning of '[[]]' in a list? In-Reply-To: References: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> Message-ID: On Sun, Nov 22, 2015 at 6:25 PM, Quivis wrote: > On Thu, 19 Nov 2015 12:40:17 +0100, Peter Otten wrote: > > > those questions that are a little harder > > And just how is he going to determine what is hard? > -- > _____ __ __ __ __ __ __ __ > (( )) || || || \\ // || (( > \\_/X| \\_// || \V/ || \_)) > Omnia paratus *~*~*~*~*~*~* > -- > https://mail.python.org/mailman/listinfo/python-list > from the OP: Hi, In the previous exercises, I see list: cc=[[],[],[]] This seems to refer to some tutorial maybe? I suppose there could be some value in an exercise like this, but I don't see it. -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From rosuav at gmail.com Sun Nov 22 19:20:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Nov 2015 11:20:34 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Nov 23, 2015 at 11:04 AM, Mark Lawrence wrote: > What happened to "Please do not feed the trolls"? Hey, Norwegian researchers get hungry too you know! https://en.wikipedia.org/wiki/Troll_(research_station) ChrisA From bc at freeuk.com Sun Nov 22 19:37:32 2015 From: bc at freeuk.com (BartC) Date: Mon, 23 Nov 2015 00:37:32 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/11/2015 00:04, Mark Lawrence wrote: > On 22/11/2015 23:44, Steven D'Aprano wrote: >> On Mon, 23 Nov 2015 12:21 am, BartC wrote: >> >>> But if it's used for static storage, then why not just use static >>> storage? That's a simpler and more general concept than memoisation. >> >> /head-desk >> >> "But if it's used for cooking, why not just cook? That's a simpler and >> more >> general concept than roasting." With 'it' being a washing machine perhaps? But I'll let this other chap have the last word as he puts it across better: > Steven D'Aprano wrote: >> Memoisation isn't "esoteric", it is a simple, basic and widely-used >> technique used to improve performance of otherwise expensive functions. On 22/11/2015 23:43, Gregory Ewing wrote: > That may be true, but I don't think it's a good example > of a use for a shared, mutable default value, because > it's arguably an *abuse* of the default value mechanism. > What happened to "Please do not feed the trolls"? You mean, people with different opinions? I think I'm done here. -- Bartc From chris at simplistix.co.uk Mon Nov 23 01:46:35 2015 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 23 Nov 2015 06:46:35 +0000 Subject: testfixtures 4.5.1 Released! Message-ID: <5652B64B.1080804@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 4.5.1. This release that contains: - LogCapture, OutputCapture and TempDirectory explicitly show what is expected versus actual when reporting differences as of 4.5.0. - The 4.5.1 release contains a bugfix where OutputCapture couldn't handle capturing unicode. Thanks to Daniel Fortunov for the expected vs actual changes. Thanks to "tell-k" for the bugfix. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: 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 -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From larry at hastings.org Mon Nov 23 02:16:44 2015 From: larry at hastings.org (Larry Hastings) Date: Sun, 22 Nov 2015 23:16:44 -0800 Subject: [RELEASED] Python 3.5.1rc1 is now available Message-ID: <5652BD5C.6040107@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm pleased to announce the availability of Python 3.5.1rc1. Python 3.5.1 will be the first update for Python 3.5. Python 3.5 is the newest version of the Python language, and it contains many exciting new features and optimizations. You can see what's changed in Python 3.5.1rc1 (as compared to 3.5.0) here: https://docs.python.org/3.5/whatsnew/changelog.html And you can download Python 3.5.1 here: https://www.python.org/downloads/release/python-351rc1/ Windows and Mac users: please read the important platform-specific "Notes on this release" section near the end of that page. We hope you enjoy Python 3.5.1! //arry/ From steve+comp.lang.python at pearwood.info Mon Nov 23 02:47:52 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 23 Nov 2015 18:47:52 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5652c4ac$0$1621$c3e8da3$5496439d@news.astraweb.com> On Monday 23 November 2015 10:43, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Memoisation isn't "esoteric", it is a simple, basic and widely-used >> technique used to improve performance of otherwise expensive functions. > > That may be true, but I don't think it's a good example > of a use for a shared, mutable default value, because > it's arguably an *abuse* of the default value mechanism. > > Whenever I want to cache function values, I use a module > level variable to hold the cache. It's clearer, and it > doesn't clutter the function signature with something > that isn't logically a part of it at all. Neither solution is really fantastic, but they both get the job done. Module level global caches have all the disadvantages of global variables. You need a unique name for each function that uses one, it breaks encapsulation, and it leaves you at the mercy of any code which modifies the global. But I agree that having the cache in the function signature is a bit smelly. But smelly or not, it works well enough for a quick and dirty cache, and using the function parameter list to initialise static local variables is a moderately common thing to do. For example: help(random.randrange) Help on method randrange in module random: randrange(self, start, stop=None, step=1, int=, default=None, maxwidth=9007199254740992L) method of random.Random instance Choose a random item from range(start, stop[, step]). I think it would be cleaner and better if Python had dedicated syntax for declaring static local variables: def randrange(self, start, stop=None, step=1): static int=type(1), default=None, maxwidth=9007199254740992L ... def func(a, b): static cache = {} ... Another good example of using a default mutable argument comes from Guido himself: https://www.python.org/doc/essays/graphs/ Note that the use of a mutable default is perfectly safe, because the default is never modified. -- Steve From Cecil at decebal.nl Mon Nov 23 02:48:54 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 23 Nov 2015 08:48:54 +0100 Subject: pip does not work anymore Message-ID: <87vb8trw9l.fsf@Equus.decebal.nl> When I try to install something with pip2 I get: Traceback (most recent call last): File "/usr/bin/pip2", line 9, in load_entry_point('pip==7.1.2', 'console_scripts', 'pip2')() File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point return ep.load() File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load return self.resolve() File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 15, in from pip.vcs import git, mercurial, subversion, bazaar # noqa File "/usr/lib/python2.7/site-packages/pip/vcs/subversion.py", line 9, in from pip.index import Link File "/usr/lib/python2.7/site-packages/pip/index.py", line 30, in from pip.wheel import Wheel, wheel_ext File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 35, in from pip._vendor.distlib.scripts import ScriptMaker File "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/scripts.py", line 14, in from .compat import sysconfig, detect_encoding, ZipFile File "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/compat.py", line 31, in from urllib2 import (Request, urlopen, URLError, HTTPError, ImportError: cannot import name HTTPSHandler With pip3 I get the same problem. It looks like openSUSE has done an upgrade in which it disabled ssl2. How can I get pip2/3 working again? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From lac at openend.se Mon Nov 23 03:11:46 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 23 Nov 2015 09:11:46 +0100 Subject: pip does not work anymore In-Reply-To: <87vb8trw9l.fsf@Equus.decebal.nl> References: <87vb8trw9l.fsf@Equus.decebal.nl> Message-ID: <201511230811.tAN8Bk1n009770@fido.openend.se> In a message of Mon, 23 Nov 2015 08:48:54 +0100, Cecil Westerhof writes: >When I try to install something with pip2 I get: > Traceback (most recent call last): > File "/usr/bin/pip2", line 9, in > load_entry_point('pip==7.1.2', 'console_scripts', 'pip2')() > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point > return get_distribution(dist).load_entry_point(group, name) > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point > return ep.load() > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load > return self.resolve() > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve > module = __import__(self.module_name, fromlist=['__name__'], level=0) > File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 15, in > from pip.vcs import git, mercurial, subversion, bazaar # noqa > File "/usr/lib/python2.7/site-packages/pip/vcs/subversion.py", line 9, in > from pip.index import Link > File "/usr/lib/python2.7/site-packages/pip/index.py", line 30, in > from pip.wheel import Wheel, wheel_ext > File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 35, in > from pip._vendor.distlib.scripts import ScriptMaker > File "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/scripts.py", line 14, in > from .compat import sysconfig, detect_encoding, ZipFile > File "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/compat.py", line 31, in > from urllib2 import (Request, urlopen, URLError, HTTPError, > ImportError: cannot import name HTTPSHandler > >With pip3 I get the same problem. > >It looks like openSUSE has done an upgrade in which it disabled ssl2. >How can I get pip2/3 working again? > >-- >Cecil Westerhof >Senior Software Engineer >LinkedIn: http://www.linkedin.com/in/cecilwesterhof >-- >https://mail.python.org/mailman/listinfo/python-list Reading https://forums.opensuse.org/showthread.php/488962-OpenSuse-python-amp-openssl seems to indicatew that you are supposed to use python-pip and not pip for OpenSuse, but I don't have one, so that is just my interpretation. Laura From rosuav at gmail.com Mon Nov 23 03:23:54 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Nov 2015 19:23:54 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: On Fri, Nov 20, 2015 at 6:46 AM, Chris Angelico wrote: > The expressions would be evaluated as closures, using the same scope > that the function's own definition used. (This won't keep things alive > unnecessarily, as the function's body will be nested within that same > scope anyway.) Bikeshed the syntax all you like, but this would be > something to point people to: "here's how to get late-binding > semantics". For the purposes of documentation, the exact text of the > parameter definition could be retained, and like docstrings, they > could be discarded in -OO mode. Just out of interest, I had a shot at implementing this with a decorator. Here's the code: # -- cut -- import functools import time class lb: def __repr__(self): return "" def latearg(f): tot_args = f.__code__.co_argcount min_args = tot_args - len(f.__defaults__) defs = f.__defaults__ # With compiler help, we could get the original text as well as something # executable that works in the correct scope. Without compiler help, we # either use a lambda function, or an exec/eval monstrosity that can't use # the scope of its notional definition (since its *actual* definition will # be inside this decorator). Instead, just show a fixed bit of text. f.__defaults__ = tuple(lb() if callable(arg) else arg for arg in defs) @functools.wraps(f) def inner(*a,**kw): if len(a) < min_args: return f(*a, **kw) # Will trigger TypeError if len(a) < tot_args: more_args = defs[len(a)-tot_args:] a += tuple(arg() if callable(arg) else arg for arg in more_args) return f(*a,**kw) return inner def sleeper(tm): """An expensive function.""" t = time.monotonic() time.sleep(tm) return time.monotonic() - t - tm seen_args = [] @latearg def foo(spam, ham=lambda: [], val=lambda: sleeper(0.5)): print("%s: Ham %X with sleeper %s" % (spam, id(ham), val)) seen_args.append(ham) # Keep all ham objects alive so IDs are unique @latearg def x(y=lambda: []): y.append(1) return y print("Starting!") foo("one-arg 1") foo("one-arg 2") foo("two-arg 1", []) foo("two-arg 2", []) foo("tri-arg 1", [], 0.0) foo("tri-arg 2", [], 0.0) print(x()) print(x()) print(x()) print(x([2])) print(x([3])) print(x([4])) print("Done!") # -- cut -- This does implement late binding, but: 1) The adornment is the rather verbose "lambda:", where I'd much rather have something shorter 2) Since there's no way to recognize "the ones that were adorned", the decorator checks for "anything callable" 3) Keyword args aren't handled - they're passed through as-is (and keyword-only arg defaults aren't rendered) 4) As commented, the help text can't pick up the text of the function But it does manage to render args at execution time, and the help() for the function identifies the individual arguments correctly (thanks to functools.wraps and the modified defaults - though this implementation is a little unfriendly, mangling the original function defaults instead of properly wrapping). Clock this one up as "useless code that was fun to write". ChrisA From __peter__ at web.de Mon Nov 23 03:57:36 2015 From: __peter__ at web.de (Peter Otten) Date: Mon, 23 Nov 2015 09:57:36 +0100 Subject: Is there an meaning of '[[]]' in a list? References: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> Message-ID: Quivis wrote: > On Thu, 19 Nov 2015 12:40:17 +0100, Peter Otten wrote: > >> those questions that are a little harder > > And just how is he going to determine what is hard? Note that I said "a little harder", not "hard". Write down your next ten or so questions, then work through the tutorial or another introductory text, then use a search engine, then post the one or two questions that are still unanswered. From Cecil at decebal.nl Mon Nov 23 04:33:18 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 23 Nov 2015 10:33:18 +0100 Subject: pip does not work anymore References: <87vb8trw9l.fsf@Equus.decebal.nl> Message-ID: <87r3jhrrfl.fsf@Equus.decebal.nl> On Monday 23 Nov 2015 09:11 CET, Laura Creighton wrote: > In a message of Mon, 23 Nov 2015 08:48:54 +0100, Cecil Westerhof > writes: >> When I try to install something with pip2 I get: Traceback (most >> recent call last): File "/usr/bin/pip2", line 9, in >> load_entry_point('pip==7.1.2', 'console_scripts', 'pip2')() File >> "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line >> 558, in load_entry_point return >> get_distribution(dist).load_entry_point(group, name) File >> "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line >> 2682, in load_entry_point return ep.load() File >> "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line >> 2355, in load return self.resolve() File >> "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line >> 2361, in resolve module = __import__(self.module_name, >> fromlist=['__name__'], level=0) File >> "/usr/lib/python2.7/site-packages/pip/__init__.py", line 15, in >> from pip.vcs import git, mercurial, subversion, bazaar # >> noqa File "/usr/lib/python2.7/site-packages/pip/vcs/subversion.py", >> line 9, in from pip.index import Link File >> "/usr/lib/python2.7/site-packages/pip/index.py", line 30, in >> from pip.wheel import Wheel, wheel_ext File >> "/usr/lib/python2.7/site-packages/pip/wheel.py", line 35, in >> from pip._vendor.distlib.scripts import ScriptMaker File >> "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/scripts.py", >> line 14, in from .compat import sysconfig, >> detect_encoding, ZipFile File >> "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/compat.py", >> line 31, in from urllib2 import (Request, urlopen, >> URLError, HTTPError, ImportError: cannot import name HTTPSHandler >> >> With pip3 I get the same problem. >> >> It looks like openSUSE has done an upgrade in which it disabled >> ssl2. How can I get pip2/3 working again? >> > > Reading > https://forums.opensuse.org/showthread.php/488962-OpenSuse-python-amp-openssl > seems to indicatew that you are supposed to use python-pip and not > pip for OpenSuse, but I don't have one, so that is just my > interpretation. python-pip is the package that you need to install to use pip2. I removed it and then pip2 does not exist anymore. I reinstalled it, but keep getting the same error. It looks like I need to install: https://docs.python.org/2/library/urllib2.html?highlight=urllib2#urllib2.HTTPSHandler but I need pip2 to do that. So I need a working pip2 to get it working. :'-( By the way openSUSE did a big update and broke other things also. For example virtualbox. Probably time to really leave openSUSE for Debian. But that will not be painless. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From gengyangcai at gmail.com Mon Nov 23 04:55:11 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 23 Nov 2015 01:55:11 -0800 (PST) Subject: Creating a Dynamic Website Using Python Message-ID: <7710a5aa-ef92-40a9-9b00-59ed1dc80103@googlegroups.com> Ok, So I have gone through the CodeAcademy Python modules and decided to jump straight into a project. I want to create a dynamic web-based site like this --- https://www.wedpics.com using Python How / where do I start ? Thanks a lot ! Gengyang From bc at freeuk.com Mon Nov 23 05:40:41 2015 From: bc at freeuk.com (BartC) Date: Mon, 23 Nov 2015 10:40:41 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <5652c4ac$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652c4ac$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/11/2015 07:47, Steven D'Aprano wrote: > I think it would be cleaner and better if Python had dedicated syntax for > declaring static local variables: Interesting. So why is it that when /I/ said: > On Mon, 23 Nov 2015 12:21 am, BartC wrote: > >> But if it's used for static storage, then why not just use static >> storage? You replied with the insulting: > /head-desk ? Maybe it's my turn to bang my head on the desk. -- Bartc From Cecil at decebal.nl Mon Nov 23 06:14:11 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 23 Nov 2015 12:14:11 +0100 Subject: pip does not work anymore References: <87vb8trw9l.fsf@Equus.decebal.nl> Message-ID: <8737vxrmrg.fsf@Equus.decebal.nl> On Monday 23 Nov 2015 08:48 CET, Cecil Westerhof wrote: > When I try to install something with pip2 I get: Traceback (most > recent call last): File "/usr/bin/pip2", line 9, in > load_entry_point('pip==7.1.2', 'console_scripts', 'pip2')() File > "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line > 558, in load_entry_point return > get_distribution(dist).load_entry_point(group, name) File > "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line > 2682, in load_entry_point return ep.load() File > "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line > 2355, in load return self.resolve() File > "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line > 2361, in resolve module = __import__(self.module_name, > fromlist=['__name__'], level=0) File > "/usr/lib/python2.7/site-packages/pip/__init__.py", line 15, in > from pip.vcs import git, mercurial, subversion, bazaar # > noqa File "/usr/lib/python2.7/site-packages/pip/vcs/subversion.py", > line 9, in from pip.index import Link File > "/usr/lib/python2.7/site-packages/pip/index.py", line 30, in > from pip.wheel import Wheel, wheel_ext File > "/usr/lib/python2.7/site-packages/pip/wheel.py", line 35, in > from pip._vendor.distlib.scripts import ScriptMaker File > "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/scripts.py", > line 14, in from .compat import sysconfig, detect_encoding, > ZipFile File > "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/compat.py", > line 31, in from urllib2 import (Request, urlopen, > URLError, HTTPError, ImportError: cannot import name HTTPSHandler > > With pip3 I get the same problem. > > It looks like openSUSE has done an upgrade in which it disabled > ssl2. How can I get pip2/3 working again? Can I make pip work with ssl3? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Mon Nov 23 06:16:49 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 23 Nov 2015 12:16:49 +0100 Subject: Let urllib3 use ssl3 instead of ssl2 Message-ID: <87y4dpq82m.fsf@Equus.decebal.nl> For a program I need to import urllib3, but this gives: ImportError: /usr/lib64/python2.7/lib-dynload/_ssl.so: undefined symbol: SSLv2_method This probably has to do with that openSUSE removed ssl2 because it is not secure. Is there a way to let urllib3 use ssl3 instead of ssl2? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From breamoreboy at yahoo.co.uk Mon Nov 23 06:31:10 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 23 Nov 2015 11:31:10 +0000 Subject: Creating a Dynamic Website Using Python In-Reply-To: <7710a5aa-ef92-40a9-9b00-59ed1dc80103@googlegroups.com> References: <7710a5aa-ef92-40a9-9b00-59ed1dc80103@googlegroups.com> Message-ID: On 23/11/2015 09:55, Cai Gengyang wrote: > Ok, > > So I have gone through the CodeAcademy Python modules and decided to jump straight into a project. > > I want to create a dynamic web-based site like this --- https://www.wedpics.com using Python > > How / where do I start ? > With a search engine, or do you need instructions on how to use one? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Mon Nov 23 06:32:47 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 23 Nov 2015 11:32:47 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/11/2015 00:37, BartC wrote: > On 23/11/2015 00:04, Mark Lawrence wrote: >> On 22/11/2015 23:44, Steven D'Aprano wrote: >>> On Mon, 23 Nov 2015 12:21 am, BartC wrote: >>> >>>> But if it's used for static storage, then why not just use static >>>> storage? That's a simpler and more general concept than memoisation. >>> >>> /head-desk >>> >>> "But if it's used for cooking, why not just cook? That's a simpler and >>> more >>> general concept than roasting." > > With 'it' being a washing machine perhaps? But I'll let this other chap > have the last word as he puts it across better: > > > Steven D'Aprano wrote: > >> Memoisation isn't "esoteric", it is a simple, basic and widely-used > >> technique used to improve performance of otherwise expensive functions. > > On 22/11/2015 23:43, Gregory Ewing wrote: > > > That may be true, but I don't think it's a good example > > of a use for a shared, mutable default value, because > > it's arguably an *abuse* of the default value mechanism. > >> What happened to "Please do not feed the trolls"? > > You mean, people with different opinions? > > I think I'm done here. > Wow, so there is a God. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ned at nedbatchelder.com Mon Nov 23 07:05:52 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 23 Nov 2015 04:05:52 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <750e8337-ce14-4a72-b016-ab326424965d@googlegroups.com> On Monday, November 23, 2015 at 6:35:35 AM UTC-5, Mark Lawrence wrote: > On 23/11/2015 00:37, BartC wrote: > > On 23/11/2015 00:04, Mark Lawrence wrote: > >> What happened to "Please do not feed the trolls"? > > > > You mean, people with different opinions? > > > > I think I'm done here. > > > > Wow, so there is a God. Mark, you aren't helping. --Ned. From rosuav at gmail.com Mon Nov 23 07:21:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Nov 2015 23:21:02 +1100 Subject: Creating a Dynamic Website Using Python In-Reply-To: <7710a5aa-ef92-40a9-9b00-59ed1dc80103@googlegroups.com> References: <7710a5aa-ef92-40a9-9b00-59ed1dc80103@googlegroups.com> Message-ID: On Mon, Nov 23, 2015 at 8:55 PM, Cai Gengyang wrote: > So I have gone through the CodeAcademy Python modules and decided to jump straight into a project. > > I want to create a dynamic web-based site like this --- https://www.wedpics.com using Python > > How / where do I start ? While it's *possible* to create a web site using just a base Python install, it's a lot more work than you need. What you should instead do is pick up one of the popular web frameworks like Django, Flask, Bottle, etc, and use that. Pick a framework (personally, I use Flask, but you can use any of them), and work through its tutorial. Then, depending on how fancy you want your site to be, you'll need anywhere from basic to advanced knowledge of the web's client-side technologies - HTML, CSS, JavaScript, and possibly some libraries like Bootstrap, jQuery, etc. Again, pick up any that you want to use, and work through their tutorials. This is a massively open-ended goal. You can make this as big or small as you want. ChrisA From marko at pacujo.net Mon Nov 23 07:23:09 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 23 Nov 2015 14:23:09 +0200 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652535a$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87oaekq502.fsf@elektro.pacujo.net> BartC : > I think I'm done here. Bart, this is the internet. Just skip the articles you don't find uplifting. Marko From steve at pearwood.info Mon Nov 23 08:08:03 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 24 Nov 2015 00:08:03 +1100 Subject: pip does not work anymore References: <87vb8trw9l.fsf@Equus.decebal.nl> Message-ID: <56530fb4$0$1589$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 Nov 2015 06:48 pm, Cecil Westerhof wrote: > When I try to install something with pip2 I get: > Traceback (most recent call last): [...] > from urllib2 import (Request, urlopen, URLError, HTTPError, > ImportError: cannot import name HTTPSHandler Before blaming SUSE for breaking this, please run this at the interactive interpreter: import urllib2 print urllib2.__file__ Have you perhaps accidentally shadowed the std lib module? -- Steven From gengyangcai at gmail.com Mon Nov 23 08:26:26 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 23 Nov 2015 05:26:26 -0800 (PST) Subject: Creating a Dynamic Website Using Python In-Reply-To: References: <7710a5aa-ef92-40a9-9b00-59ed1dc80103@googlegroups.com> Message-ID: Ok, I will look through the Flask tutorials then ... On Monday, November 23, 2015 at 8:21:28 PM UTC+8, Chris Angelico wrote: > On Mon, Nov 23, 2015 at 8:55 PM, Cai Gengyang wrote: > > So I have gone through the CodeAcademy Python modules and decided to jump straight into a project. > > > > I want to create a dynamic web-based site like this --- https://www.wedpics.com using Python > > > > How / where do I start ? > > While it's *possible* to create a web site using just a base Python > install, it's a lot more work than you need. What you should instead > do is pick up one of the popular web frameworks like Django, Flask, > Bottle, etc, and use that. Pick a framework (personally, I use Flask, > but you can use any of them), and work through its tutorial. Then, > depending on how fancy you want your site to be, you'll need anywhere > from basic to advanced knowledge of the web's client-side technologies > - HTML, CSS, JavaScript, and possibly some libraries like Bootstrap, > jQuery, etc. Again, pick up any that you want to use, and work through > their tutorials. > > This is a massively open-ended goal. You can make this as big or small > as you want. > > ChrisA From sridhargunasekaran at gmail.com Mon Nov 23 08:55:59 2015 From: sridhargunasekaran at gmail.com (sridhar gunasekaran) Date: Mon, 23 Nov 2015 19:25:59 +0530 Subject: No subject Message-ID: <56531af0.0f13620a.cf2d9.6179@mx.google.com> Hai I have installed python 3.5 in my pc I could not see any application icon or application shortcut on my pc Sent from Mail for Windows 10 From steve at pearwood.info Mon Nov 23 08:58:55 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 24 Nov 2015 00:58:55 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652c4ac$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56531ba1$0$1597$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 Nov 2015 09:40 pm, BartC wrote: > On 23/11/2015 07:47, Steven D'Aprano wrote: > >> I think it would be cleaner and better if Python had dedicated syntax for >> declaring static local variables: > > Interesting. So why is it that when /I/ said: > > > On Mon, 23 Nov 2015 12:21 am, BartC wrote: > > > >> But if it's used for static storage, then why not just use static > >> storage? > > You replied with the insulting: > > > /head-desk > > ? > > Maybe it's my turn to bang my head on the desk. Let me steal^W borrow an idea from Galileo, and present the explanation in the form of a dialogue between two philosophers of computer science, Salviati and Simplicio, and a third, intelligent layman, Sagredo. https://en.wikipedia.org/wiki/Dialogue_Concerning_the_Two_Chief_World_Systems Salviati: Function defaults can also be used for static storage. Simplicio: If you want static storage, why not use static storage? Salviati: Function defaults in Python *are* static storage. Although they not the only way to get static storage, as closures can also be used for that purpose, they are surely the simplest way to get static storage in Python. Sagredo: Simplest though it might be, surely a reasonable person would consider that using function parameters for static storage is abuse of the feature and a global variable would be better? Salviati: Global variables have serious disadvantages. I will agree that using function parameters for static storage is something of a code smell, but good enough for rough and ready code. Nevertheless, it would be good if Python had dedicated syntax for static storage. Simplicio: Ah-ha! Gotcha! Salviati: No, perhaps you missed that I was referring to a hypothetical future addition to Python, not a current feature. But even if it did exist today, your statement misses the point that by using function defaults I *am* using static storage. In effect, you are telling me that rather than using static storage I should instead use static storage. -- Steven From me at sntsh.com Mon Nov 23 09:16:31 2015 From: me at sntsh.com (Santosh Kumar) Date: Mon, 23 Nov 2015 19:46:31 +0530 Subject: How to remember last position and size (geometry) of PyQt application? In-Reply-To: References: Message-ID: This question was reasked and answered on StackOverflow: http://stackoverflow.com/q/33869721/939986 From ian.g.kelly at gmail.com Mon Nov 23 11:40:50 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 23 Nov 2015 09:40:50 -0700 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: On Mon, Nov 23, 2015 at 1:23 AM, Chris Angelico wrote: > def latearg(f): > tot_args = f.__code__.co_argcount > min_args = tot_args - len(f.__defaults__) > defs = f.__defaults__ > # With compiler help, we could get the original text as well as something > # executable that works in the correct scope. Without compiler help, we > # either use a lambda function, or an exec/eval monstrosity that can't use > # the scope of its notional definition (since its *actual* definition will > # be inside this decorator). Instead, just show a fixed bit of text. You should be able to get the correct globals from f.__globals__. For locals, the decorator might capture the locals of the previous stack frame at the moment the decorator was called, but that's potentially a pretty heavy thing to be retaining for this purpose; the definition of a @latearg function would indefinitely keep a reference to every single object that was bound to a variable in that scope, not just the things it needs. For better specificity you could parse the expression and then just grab the names that it uses. Even so, this would still act somewhat like early binding in that it would reference the local variables at the time of definition rather than evaluation. Nonlocals? Just forget about it. > This does implement late binding, but: > 1) The adornment is the rather verbose "lambda:", where I'd much > rather have something shorter > 2) Since there's no way to recognize "the ones that were adorned", the > decorator checks for "anything callable" A parameter annotation could be used in conjunction with the decorator. @latearg def x(y: latearg = lambda: []): ... But that's even more verbose. In the simple case where all the defaults should be late, one could have something like: @latearg('*') def x(y=lambda: []): ... The argument could be generalized to pass a set of parameter names as an alternative to the annotation. > 3) Keyword args aren't handled - they're passed through as-is (and > keyword-only arg defaults aren't rendered) I would expect that Python 3 Signature objects would make this a lot simpler to handle. From framstag at rus.uni-stuttgart.de Mon Nov 23 12:01:55 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Mon, 23 Nov 2015 17:01:55 +0000 (UTC) Subject: non-blocking getkey? References: <564DF94E.8020302@gmail.com> Message-ID: eryksun wrote: > On Thu, Nov 19, 2015 at 10:31 AM, Michael Torrie wrote: > > One windows it might be possible to use the win32 api to enumerate the > > windows, find your console window and switch to it. > > You can call GetConsoleWindow [1] and then SetForegroundWindow [2]. (...) Sorry, for the late feedback: great, this works! Thanks! -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From c.buhtz at posteo.jp Mon Nov 23 12:04:01 2015 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Mon, 23 Nov 2015 18:04:01 +0100 Subject: [argparse] optional parameter without --switch Message-ID: <3p4FFS0cRdz5vNy@dovecot03.posteo.de> I want to call (on bash) a Python script in this two ways without any error. ./arg.py ./arg.py TEST It means that the parameter (here with the value `TEST`) should be optional. With argparse I only know a way to create optional paramters when they have a switch (like `--name`). Is there a way to fix that? #!/usr/bin/env python3 import sys import argparse parser = argparse.ArgumentParser(description=__file__) # must have #parser.add_argument('name', metavar='NAME', type=str) # optional BUT with a switch I don't want #parser.add_argument('--name', metavar='NAME', type=str) # store all arguments in objects/variables of the local namespace locals().update(vars(parser.parse_args())) print(name) sys.exit() -- GnuPGP-Key ID 0751A8EC From rosuav at gmail.com Mon Nov 23 12:05:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 Nov 2015 04:05:13 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 3:40 AM, Ian Kelly wrote: > On Mon, Nov 23, 2015 at 1:23 AM, Chris Angelico wrote: >> def latearg(f): >> tot_args = f.__code__.co_argcount >> min_args = tot_args - len(f.__defaults__) >> defs = f.__defaults__ >> # With compiler help, we could get the original text as well as something >> # executable that works in the correct scope. Without compiler help, we >> # either use a lambda function, or an exec/eval monstrosity that can't use >> # the scope of its notional definition (since its *actual* definition will >> # be inside this decorator). Instead, just show a fixed bit of text. > > You should be able to get the correct globals from f.__globals__. > > For locals, the decorator might capture the locals of the previous > stack frame at the moment the decorator was called, but that's > potentially a pretty heavy thing to be retaining for this purpose; the > definition of a @latearg function would indefinitely keep a reference > to every single object that was bound to a variable in that scope, not > just the things it needs. For better specificity you could parse the > expression and then just grab the names that it uses. Even so, this > would still act somewhat like early binding in that it would reference > the local variables at the time of definition rather than evaluation. > > Nonlocals? Just forget about it. And since nonlocals are fundamentally unsolvable, I took the simpler option and just used an actual lambda function. >> This does implement late binding, but: >> 1) The adornment is the rather verbose "lambda:", where I'd much >> rather have something shorter >> 2) Since there's no way to recognize "the ones that were adorned", the >> decorator checks for "anything callable" > > A parameter annotation could be used in conjunction with the decorator. > > @latearg > def x(y: latearg = lambda: []): > ... > > But that's even more verbose. In the simple case where all the > defaults should be late, one could have something like: > > @latearg('*') > def x(y=lambda: []): > ... > > The argument could be generalized to pass a set of parameter names as > an alternative to the annotation. Yeah, that might help. With real compiler support, both of these could be solved: def x(y=>[]): ... The displayed default could be "=>[]", exactly the way it's seen in the source, and the run-time would know exactly which args were flagged this way. Plus, it could potentially use a single closure to evaluate all the arguments. >> 3) Keyword args aren't handled - they're passed through as-is (and >> keyword-only arg defaults aren't rendered) > > I would expect that Python 3 Signature objects would make this a lot > simpler to handle. Maybe. It's still going to be pretty complicated. I could easily handle keyword-only arguments, but recognizing that something in **kw is replacing something in *a is a bit harder. Expansion invited. This is reminiscent of the manual "yield from" implementation in PEP 380. It looks simple enough, until you start writing in all the corner cases. ChrisA From israel at ravnalaska.net Mon Nov 23 12:54:38 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Mon, 23 Nov 2015 08:54:38 -0900 Subject: Bi-directional sub-process communication Message-ID: I have a multi-threaded python app (CherryPy WebApp to be exact) that launches a child process that it then needs to communicate with bi-driectionally. To implement this, I have used a pair of Queues: a child_queue which I use for master->child communication, and a master_queue which is used for child->master communication. The way I have the system set up, the child queue runs a loop in a tread that waits for messages on child_queue, and when received responds appropriately depending on the message received, which sometimes involves posting a message to master_queue. On the master side, when it needs to communicate with the child process, it posts a message to child_queue, and if the request requires a response it will then immediately start waiting for a message on master_queue, typically with a timeout. While this process works well in testing, I do have one concern (maybe unfounded) and a real-world issue Concern: Since the master process is multi-threaded, it seems likely enough that multiple threads on the master side would make requests at the same time. I understand that the Queue class has locks that make this fine (one thread will complete posting the message before the next is allowed to start), and since the child process only has a single thread processing messages from the queue, it should process them in order and post the responses (if any) to the master_queue in order. But now I have multiple master processes all trying to read master_queue at the same time. Again, the locks will take care of this and prevent any overlapping reads, but am I guaranteed that the threads will obtain the lock and therefore read the responses in the right order? Or is there a possibility that, say, thread three will get the response that should have been for thread one? Is this something I need to take into consideration, and if so, how? Real-world problem: While as I said this system worked well in testing, Now that I have gotten it out into production I've occasionally run into a problem where the master thread waiting for a response on master_queue times out while waiting. This causes a (potentially) two-fold problem, in that first off the master process doesn't get the information it had requested, and secondly that I *could* end up with an "orphaned" message on the queue that could cause problems the next time I try to read something from it. I currently have the timeout set to 3 seconds. I can, of course, increase that, but that could lead to a bad user experience - and might not even help the situation if something else is going on. The actual exchange is quite simple: On the master side, I have this code: config.socket_queue.put('GET_PORT') try: port = config.master_queue.get(timeout=3) #wait up to three seconds for a response except Empty: port = 5000 # default. Can't hurt to try. Which, as you might have been able to guess, tries to ask the child process (an instance of a tornado server, btw) what port it is listening on. The child process then, on getting this message from the queue, runs the following code: elif item == 'GET_PORT': port = utils.config.getint('global', 'tornado.port') master_queue.put(port) So nothing that should take any significant time. Of course, since this is a single thread handling any number of requests, it is possible that the thread is tied up responding to a different request (or that the GIL is preventing the thread from running at all, since another thread might be commandeering the processor), but I find it hard to believe that it could be tied up for more than three seconds. So is there a better way to do sub-process bi-directional communication that would avoid these issues? Or do I just need to increase the timeout (or remove it altogether, at the risk of potentially causing the thread to hang if no message is posted)? And is my concern justified, or just paranoid? Thanks for any information that can be provided! ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- From Cecil at decebal.nl Mon Nov 23 13:23:57 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 23 Nov 2015 19:23:57 +0100 Subject: pip does not work anymore References: <87vb8trw9l.fsf@Equus.decebal.nl> <56530fb4$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mvu4r2v6.fsf@Equus.decebal.nl> On Monday 23 Nov 2015 14:08 CET, Steven D'Aprano wrote: > On Mon, 23 Nov 2015 06:48 pm, Cecil Westerhof wrote: > >> When I try to install something with pip2 I get: >> Traceback (most recent call last): > [...] >> from urllib2 import (Request, urlopen, URLError, HTTPError, >> ImportError: cannot import name HTTPSHandler > > Before blaming SUSE for breaking this, please run this at the > interactive interpreter: > > import urllib2 > print urllib2.__file__ > > > Have you perhaps accidentally shadowed the std lib module? It worked without fail before the update, but you never know: Python 2.7.9 (default, Dec 13 2014, 18:02:08) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> print urllib2.__file__ /usr/lib64/python2.7/urllib2.pyc So I did not shadow I would think. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From israel at ravnalaska.net Mon Nov 23 13:29:28 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Mon, 23 Nov 2015 09:29:28 -0900 Subject: Designing DBI compliant SQL parameters for module Message-ID: <92FBE0C8-2853-4F3F-9F85-1144EE4D4EC7@ravnalaska.net> My company uses a database (4th dimension) for which there was no python DBI compliant driver available (I had to use ODBC, which I felt was cludgy). However, I did discover that the company had a C driver available, so I went ahead and used CFFI to wrap this driver into a DBI compliant python module (https://pypi.python.org/pypi/p4d). This works well (still need to make it python 3.x compatible), but since the underlying C library uses "qmark" style parameter markers, that's all I implemented in my module. I would like to expand the module to be able to use the more-common (or at least easier for me) "format" and "pyformat" parameter markers, as indicated in the footnote to PEP-249 (https://www.python.org/dev/peps/pep-0249/#id2 at least for the pyformat markers). Now I am fairly confidant that I can write code to convert such placeholders into the qmark style markers that the underlying library provides, but before I go and re-invent the wheel, is there already code that does this which I can simply use, or modify? ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- From ian.g.kelly at gmail.com Mon Nov 23 14:55:49 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 23 Nov 2015 12:55:49 -0700 Subject: Bi-directional sub-process communication In-Reply-To: References: Message-ID: On Mon, Nov 23, 2015 at 10:54 AM, Israel Brewster wrote: > Concern: Since the master process is multi-threaded, it seems likely enough that multiple threads on the master side would make requests at the same time. I understand that the Queue class has locks that make this fine (one thread will complete posting the message before the next is allowed to start), and since the child process only has a single thread processing messages from the queue, it should process them in order and post the responses (if any) to the master_queue in order. But now I have multiple master processes all trying to read master_queue at the same time. Again, the locks will take care of this and prevent any overlapping reads, but am I guaranteed that the threads will obtain the lock and therefore read the responses in the right order? Or is there a possibility that, say, thread three will get the response that should have been for thread one? Is this something I need to take into consideration, and if so, how? Yes, if multiple master threads are waiting on the queue, it's possible that a master thread could get a response that was not intended for it. As far as I know there's no guarantee that the waiting threads will be woken up in the order that they called get(), but even if there are, consider this case: Thread A enqueues a request. Thread B preempts A and enqueues a request. Thread B calls get on the response queue. Thread A calls get on the response queue. The response from A's request arrives and is given to B. Instead of having the master threads pull objects off the response queue directly, you might create another thread whose sole purpose is to handle the response queue. That could look like this: request_condition = threading.Condition() response_global = None def master_thread(): global response_global with request_condition: request_queue.put(request) request_condition.wait() # Note: the Condition should remain acquired until response_global is reset. response = response_global response_global = None if wrong_response(response): raise RuntimeError("got a response for the wrong request") handle_response(response) def response_thread(): global response_global while True: response = response_queue.get() with request_condition: response_global = response request_condition.notify() As another option you could use a multiprocessing.Manager to coordinate passing the response back more directly, but starting a third process seems like overkill for this. From ian.g.kelly at gmail.com Mon Nov 23 15:51:51 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 23 Nov 2015 13:51:51 -0700 Subject: Bi-directional sub-process communication In-Reply-To: References: Message-ID: On Mon, Nov 23, 2015 at 12:55 PM, Ian Kelly wrote: > On Mon, Nov 23, 2015 at 10:54 AM, Israel Brewster wrote: >> Concern: Since the master process is multi-threaded, it seems likely enough that multiple threads on the master side would make requests at the same time. I understand that the Queue class has locks that make this fine (one thread will complete posting the message before the next is allowed to start), and since the child process only has a single thread processing messages from the queue, it should process them in order and post the responses (if any) to the master_queue in order. But now I have multiple master processes all trying to read master_queue at the same time. Again, the locks will take care of this and prevent any overlapping reads, but am I guaranteed that the threads will obtain the lock and therefore read the responses in the right order? Or is there a possibility that, say, thread three will get the response that should have been for thread one? Is this something I need to take into consideration, and if so, how? > > Yes, if multiple master threads are waiting on the queue, it's > possible that a master thread could get a response that was not > intended for it. As far as I know there's no guarantee that the > waiting threads will be woken up in the order that they called get(), > but even if there are, consider this case: > > Thread A enqueues a request. > Thread B preempts A and enqueues a request. > Thread B calls get on the response queue. > Thread A calls get on the response queue. > The response from A's request arrives and is given to B. > > Instead of having the master threads pull objects off the response > queue directly, you might create another thread whose sole purpose is > to handle the response queue. That could look like this: > > > request_condition = threading.Condition() > response_global = None > > def master_thread(): > global response_global > with request_condition: > request_queue.put(request) > request_condition.wait() > # Note: the Condition should remain acquired until > response_global is reset. > response = response_global > response_global = None > if wrong_response(response): > raise RuntimeError("got a response for the wrong request") > handle_response(response) > > def response_thread(): > global response_global > while True: > response = response_queue.get() > with request_condition: > response_global = response > request_condition.notify() Actually I realized that this fails because if two threads get notified at about the same time, they could reacquire the Condition in the wrong order and so get the wrong responses. Concurrency, ugh. It's probably better just to have a Condition/Event per thread and have the response thread identify the correct one to notify, rather than just notify a single shared Condition and hope the threads wake up in the right order. From vostrushka at gmail.com Mon Nov 23 15:58:31 2015 From: vostrushka at gmail.com (Crane Ugly) Date: Mon, 23 Nov 2015 12:58:31 -0800 (PST) Subject: Problem to read from array In-Reply-To: References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> Message-ID: <81290337-638d-4e50-a85f-054e0a220357@googlegroups.com> Thank you all. Here is the last piece of code that caused me so much troubles but now working the way I wanted it: fRawData = [] with open(fStagingFile2) as fStagingFile2FH: fRawData = [line.strip() for line in fStagingFile2FH.readlines()] # #### This is to read each element from the file and chop off the end of line character fNumberOfColumns = 7 fNumberOfRows = len(fRawData)/fNumberOfColumns fRowID = 0 fParameters = [] for fRowID in range(0, len(fRawData), fNumberOfColumns): fParameters.append(fRawData[fRowID:fRowID+fNumberOfColumns]) # #### This is to convert 1D array to 2D # #### ... and down below section is an example of how to read each element of the list # #### and how to update it if I need so. That was also a problem before. fRowID = 0 fColumnID = 0 for fRowID in range(fNumberOfRows): for fColumnID in range(fNumberOfColumns): if fColumnID == 0: fParameters[fRowID][fColumnID] = "XXXX" Message2Log("fParameters[" + str(fRowID) + "][" + str(fColumnID) + "] = " + str(fParameters[fRowID][fColumnID])) CU On Saturday, November 21, 2015 at 4:52:35 PM UTC+1, Nathan Hilterbrand wrote: > On 11/21/2015 10:26 AM, BartC wrote: > > On 21/11/2015 10:41, vostrushka at gmail.com wrote: > >> Hi, > >> I have a file with one parameter per line: > >> a1 > >> b1 > >> c1 > >> a2 > >> b2 > >> c2 > >> a3 > >> b3 > >> c3 > >> ... > >> The parameters are lines of characters (not numbers) > >> > >> I need to load it to 2D array for further manipulations. > >> So far I managed to upload this file into 1D array: > >> > >> ParametersRaw = [] > >> with open(file1) as fh: > >> ParametersRaw = fh.readlines() > >> fh.close() > > > > I tried this code based on yours: > > > > with open("input") as fh: > > lines=fh.readlines() > > > > rows = len(lines)//3 > > > > params=[] > > index=0 > > > > for row in range(rows): > > params.append([lines[index],lines[index+1],lines[index+2]]) > > index += 3 > > > > for row in range(rows): > > print (row,":",params[row]) > > > > For the exact input you gave, it produced this output: > > > > 0 : ['a1\n', 'b1\n', 'c1\n'] > > 1 : ['a2\n', 'b2\n', 'c2\n'] > > 2 : ['a3\n', 'b3\n', 'c3\n'] > > > > Probably you'd want to get rid of those \n characters. (I don't know > > how off-hand as I'm not often write in Python.) > > > > The last bit could also be written: > > > > for param in params: > > print (params) > > > > but I needed the row index. > > > To get rid of the '\n' (lineend) characters: > > with open(file1) as fh: > ParametersRaw = [line.strip() for line in fh.readlines()] > > or, more succinctly.. > > with open(file1) as fh: > ParametersRaw = [line.strip() for line in fh] > > Comprehensions are your friend. > > Nathan From israel at ravnalaska.net Mon Nov 23 16:22:33 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Mon, 23 Nov 2015 12:22:33 -0900 Subject: Bi-directional sub-process communication In-Reply-To: References: Message-ID: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> On Nov 23, 2015, at 11:51 AM, Ian Kelly wrote: > > On Mon, Nov 23, 2015 at 12:55 PM, Ian Kelly wrote: >> On Mon, Nov 23, 2015 at 10:54 AM, Israel Brewster wrote: >>> Concern: Since the master process is multi-threaded, it seems likely enough that multiple threads on the master side would make requests at the same time. I understand that the Queue class has locks that make this fine (one thread will complete posting the message before the next is allowed to start), and since the child process only has a single thread processing messages from the queue, it should process them in order and post the responses (if any) to the master_queue in order. But now I have multiple master processes all trying to read master_queue at the same time. Again, the locks will take care of this and prevent any overlapping reads, but am I guaranteed that the threads will obtain the lock and therefore read the responses in the right order? Or is there a possibility that, say, thread three will get the response that should have been for thread one? Is this something I need to take into consideration, and if so, how? >> >> Yes, if multiple master threads are waiting on the queue, it's >> possible that a master thread could get a response that was not >> intended for it. As far as I know there's no guarantee that the >> waiting threads will be woken up in the order that they called get(), >> but even if there are, consider this case: >> >> Thread A enqueues a request. >> Thread B preempts A and enqueues a request. >> Thread B calls get on the response queue. >> Thread A calls get on the response queue. >> The response from A's request arrives and is given to B. >> >> Instead of having the master threads pull objects off the response >> queue directly, you might create another thread whose sole purpose is >> to handle the response queue. That could look like this: >> >> >> request_condition = threading.Condition() >> response_global = None >> >> def master_thread(): >> global response_global >> with request_condition: >> request_queue.put(request) >> request_condition.wait() >> # Note: the Condition should remain acquired until >> response_global is reset. >> response = response_global >> response_global = None >> if wrong_response(response): >> raise RuntimeError("got a response for the wrong request") >> handle_response(response) >> >> def response_thread(): >> global response_global >> while True: >> response = response_queue.get() >> with request_condition: >> response_global = response >> request_condition.notify() > > Actually I realized that this fails because if two threads get > notified at about the same time, they could reacquire the Condition in > the wrong order and so get the wrong responses. > > Concurrency, ugh. > > It's probably better just to have a Condition/Event per thread and > have the response thread identify the correct one to notify, rather > than just notify a single shared Condition and hope the threads wake > up in the right order. Tell me about it :-) I've actually never worked with conditions or notifications (actually even this bi-drectional type of communication is new to me), so I'll have to look into that and figure it out. Thanks for the information! > -- > https://mail.python.org/mailman/listinfo/python-list From cs at zip.com.au Mon Nov 23 16:45:16 2015 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 24 Nov 2015 08:45:16 +1100 Subject: Bi-directional sub-process communication In-Reply-To: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> References: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> Message-ID: <20151123214516.GA56871@cskk.homeip.net> On 23Nov2015 12:22, Israel Brewster wrote: >On Nov 23, 2015, at 11:51 AM, Ian Kelly wrote: >> Concurrency, ugh. I'm a big concurrency fan myself. >> It's probably better just to have a Condition/Event per thread and >> have the response thread identify the correct one to notify, rather >> than just notify a single shared Condition and hope the threads wake >> up in the right order. > >Tell me about it :-) I've actually never worked with conditions or >notifications (actually even this bi-drectional type of communication is new >to me), so I'll have to look into that and figure it out. Thanks for the >information! I include a tag with every request, and have the responses include the tag; the request submission function records the response hander in a mapping by tag and the response handing thread looks up the mapping and passes the response to the right handler. Works just fine and avoids all the worrying about ordering etc. Israel, do you have control over the protocol between you and your subprocess? If so, adding tags is easy and effective. Cheers, Cameron Simpson From plbrrt7 at hotmail.com Mon Nov 23 17:09:06 2015 From: plbrrt7 at hotmail.com (Alexandre Barreto) Date: Mon, 23 Nov 2015 22:09:06 +0000 Subject: No subject Message-ID: I install python 3.5.0 and run eazy to install and my antiv?rus detect and trogen can you explay cus im new to this language. From israel at ravnalaska.net Mon Nov 23 17:18:58 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Mon, 23 Nov 2015 13:18:58 -0900 Subject: Bi-directional sub-process communication In-Reply-To: <20151123214516.GA56871@cskk.homeip.net> References: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> <20151123214516.GA56871@cskk.homeip.net> Message-ID: On Nov 23, 2015, at 12:45 PM, Cameron Simpson wrote: > > On 23Nov2015 12:22, Israel Brewster wrote: >> On Nov 23, 2015, at 11:51 AM, Ian Kelly wrote: >>> Concurrency, ugh. > > I'm a big concurrency fan myself. > >>> It's probably better just to have a Condition/Event per thread and >>> have the response thread identify the correct one to notify, rather >>> than just notify a single shared Condition and hope the threads wake >>> up in the right order. >> >> Tell me about it :-) I've actually never worked with conditions or notifications (actually even this bi-drectional type of communication is new to me), so I'll have to look into that and figure it out. Thanks for the information! > > I include a tag with every request, and have the responses include the tag; the request submission function records the response hander in a mapping by tag and the response handing thread looks up the mapping and passes the response to the right handler. > > Works just fine and avoids all the worrying about ordering etc. > > Israel, do you have control over the protocol between you and your subprocess? If so, adding tags is easy and effective. I do, and the basic concept makes sense. The one difficulty I am seeing is getting back to the thread that requested the data. Let me know if this makes sense or I am thinking about it wrong: - When a thread requests some data, it sends the request as a dictionary containing a tag (unique to the thread) as well as the request - When the child processes the request, it encodes the response as a dictionary containing the tag and the response data - A single, separate thread on the "master" side parses out responses as they come in and puts them into a dictionary keyed by tag - The requesting threads, after putting the request into the Queue, would then block waiting for data to appear under their key in the dictionary Of course, that last step could be interesting - implementing the block in such a way as to not tie up the processor, while still getting the data "as soon" as it is available. Unless there is some sort of built-in notification system I could use for that? I.e. the thread would "subscribe" to a notification based on its tag, and then wait for notification. When the master processing thread receives data with said tag, it adds it to the dictionary and "publishes" a notification to that tag. Or perhaps the notification itself could contain the payload? Thanks for the information! > > Cheers, > Cameron Simpson From ckaynor at zindagigames.com Mon Nov 23 17:43:25 2015 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 23 Nov 2015 14:43:25 -0800 Subject: Bi-directional sub-process communication In-Reply-To: References: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> <20151123214516.GA56871@cskk.homeip.net> Message-ID: On Mon, Nov 23, 2015 at 2:18 PM, Israel Brewster wrote: > Of course, that last step could be interesting - implementing the block in > such a way as to not tie up the processor, while still getting the data "as > soon" as it is available. Unless there is some sort of built-in > notification system I could use for that? I.e. the thread would "subscribe" > to a notification based on its tag, and then wait for notification. When > the master processing thread receives data with said tag, it adds it to the > dictionary and "publishes" a notification to that tag. Or perhaps the > notification itself could contain the payload? There are a few ways I could see handling this, without having the threads spinning and consuming CPU: 1. Don't worry about having the follow-up code run in the same thread, and use a simple callback. This callback could be dispatched to a thread via a work queue, however you may not get the same thread as the one that made the request. This is probably the most efficient method to use, as the threads can continue doing other work while waiting for a reply, rather than blocking. It does make it harder to maintain state between the pre- and post-request functions, however. 2. Have a single, global, event variable that wakes all threads waiting on a reply, each of which then checks to see if the reply is for it, or goes back to sleep. This is good if most of the time, only a few threads will be waiting for a reply, and checking if the correct reply came in is cheap. This is probably good enough, unless you have a LOT of threads (hundreds). 3. Have an event per thread. This will use less CPU than the second option, however does require more memory and OS resources, and so will not be viable for huge numbers of threads, though if you hit the limit, you are probably using threads wrong. 4. Have an event per request. This is only better than #3 if a single thread may make multiple requests at once, and can do useful work when any of them get a reply back (if they need all, it will make no difference). Generally, I would use option #1 or #2. Option 2 has the advantage of making it easy to write the functions that use the functionality, while option 1 will generally use fewer resources, and allows threads to continue to be used while waiting for replies. How much of a benefit that is depends on exactly what you are doing. Option #4 would probably be better implemented using option #1 in all cases to avoid problems with running out of OS memory - threading features generally require more limited OS resources than memory. Option #3 will also often run into the same issues as option #4 in the cases it will provide any benefit over option #2. Chris From israel at ravnalaska.net Mon Nov 23 18:14:11 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Mon, 23 Nov 2015 14:14:11 -0900 Subject: Bi-directional sub-process communication In-Reply-To: References: <5A3A00A6-CFD2-42FC-9C87-6F8C6861F775@ravnalaska.net> <20151123214516.GA56871@cskk.homeip.net> Message-ID: <84B23819-6214-4BDA-959D-85CD46431212@ravnalaska.net> On Nov 23, 2015, at 1:43 PM, Chris Kaynor wrote: > > On Mon, Nov 23, 2015 at 2:18 PM, Israel Brewster > wrote: > >> Of course, that last step could be interesting - implementing the block in >> such a way as to not tie up the processor, while still getting the data "as >> soon" as it is available. Unless there is some sort of built-in >> notification system I could use for that? I.e. the thread would "subscribe" >> to a notification based on its tag, and then wait for notification. When >> the master processing thread receives data with said tag, it adds it to the >> dictionary and "publishes" a notification to that tag. Or perhaps the >> notification itself could contain the payload? > > > There are a few ways I could see handling this, without having the threads > spinning and consuming CPU: > > 1. Don't worry about having the follow-up code run in the same thread, > and use a simple callback. This callback could be dispatched to a thread > via a work queue, however you may not get the same thread as the one that > made the request. This is probably the most efficient method to use, as the > threads can continue doing other work while waiting for a reply, rather > than blocking. It does make it harder to maintain state between the pre- > and post-request functions, however. > 2. Have a single, global, event variable that wakes all threads waiting > on a reply, each of which then checks to see if the reply is for it, or > goes back to sleep. This is good if most of the time, only a few threads > will be waiting for a reply, and checking if the correct reply came in is > cheap. This is probably good enough, unless you have a LOT of threads > (hundreds). > 3. Have an event per thread. This will use less CPU than the second > option, however does require more memory and OS resources, and so will not > be viable for huge numbers of threads, though if you hit the limit, you are > probably using threads wrong. > 4. Have an event per request. This is only better than #3 if a single > thread may make multiple requests at once, and can do useful work when any > of them get a reply back (if they need all, it will make no difference). > > Generally, I would use option #1 or #2. Option 2 has the advantage of > making it easy to write the functions that use the functionality, while > option 1 will generally use fewer resources, and allows threads to continue > to be used while waiting for replies. How much of a benefit that is depends > on exactly what you are doing. While I would agree with #1 in general, the threads, in this case, are CherryPy threads, so I need to get the data and return it to the client in the same function call, which of course means the thread needs to block until the data is ready - it can't return and let the result be processed "later". Essentially there are times that the web client needs some information that only the Child process has. So the web client requests the data from the master process, and the master process then turns around and requests the data from the child, but it needs to get the data back before it can return it to the web client. So it has to block waiting for the data. Thus we come to option #2 (or 3), which sounds good but I have no clue how to implement :-) Maybe something like http://pubsub.sourceforge.net ? I'll dig into that. > > Option #4 would probably be better implemented using option #1 in all cases > to avoid problems with running out of OS memory - threading features > generally require more limited OS resources than memory. Option #3 will > also often run into the same issues as option #4 in the cases it will > provide any benefit over option #2. > > Chris > -- > https://mail.python.org/mailman/listinfo/python-list From israel at ravnalaska.net Mon Nov 23 19:27:39 2015 From: israel at ravnalaska.net (Israel Brewster) Date: Mon, 23 Nov 2015 15:27:39 -0900 Subject: Bi-directional sub-process communication In-Reply-To: References: Message-ID: On Nov 23, 2015, at 3:05 PM, Dennis Lee Bieber wrote: > > On Mon, 23 Nov 2015 08:54:38 -0900, Israel Brewster > declaimed the following: > >> Concern: Since the master process is multi-threaded, it seems likely enough that multiple threads on the master side would make requests at the same time. I understand that the Queue class has locks that make > > Multiple "master" threads, to me, means you do NOT have a "master > process". But I do: the CherryPy "application", which has multiple threads - one per request (and perhaps a few more) to be exact. It's these request threads that generate the calls to the child process. > > Let there be a Queue for EVERY LISTENER. > > Send the Queue as part of the request packet. No luck: "RuntimeError: Queue objects should only be shared between processes through inheritance" This IS a master process, with multiple threads, trying to communicate with a child process. That said, with some modifications this sort of approach could still work. ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- > > Let the subthread reply to the queue that was provided via the packet > > Voila! No intermixing of "master/slave" interaction; each slave only > replies to the master that sent it a command; each master only receives > replies from slaves it has commanded. Slaves can still be shared, as they > are given the information of which master they need to speak with. > > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list From sohcahtoa82 at gmail.com Mon Nov 23 19:44:54 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 23 Nov 2015 16:44:54 -0800 (PST) Subject: Problem to read from array In-Reply-To: <81290337-638d-4e50-a85f-054e0a220357@googlegroups.com> References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> <81290337-638d-4e50-a85f-054e0a220357@googlegroups.com> Message-ID: <9ea86586-0052-491a-8991-0a5f986c34ae@googlegroups.com> On Monday, November 23, 2015 at 12:58:49 PM UTC-8, Crane Ugly wrote: > Thank you all. > Here is the last piece of code that caused me so much troubles but now working the way I wanted it: > > fRawData = [] > with open(fStagingFile2) as fStagingFile2FH: > fRawData = [line.strip() for line in fStagingFile2FH.readlines()] # #### This is to read each element from the file and chop off the end of line character > > fNumberOfColumns = 7 > fNumberOfRows = len(fRawData)/fNumberOfColumns > > fRowID = 0 > fParameters = [] > for fRowID in range(0, len(fRawData), fNumberOfColumns): > fParameters.append(fRawData[fRowID:fRowID+fNumberOfColumns]) # #### This is to convert 1D array to 2D > > # #### ... and down below section is an example of how to read each element of the list > # #### and how to update it if I need so. That was also a problem before. > fRowID = 0 > fColumnID = 0 > for fRowID in range(fNumberOfRows): > for fColumnID in range(fNumberOfColumns): > if fColumnID == 0: > fParameters[fRowID][fColumnID] = "XXXX" > Message2Log("fParameters[" + str(fRowID) + "][" + str(fColumnID) + "] = " + str(fParameters[fRowID][fColumnID])) > > CU > > On Saturday, November 21, 2015 at 4:52:35 PM UTC+1, Nathan Hilterbrand wrote: > > On 11/21/2015 10:26 AM, BartC wrote: > > > On 21/11/2015 10:41, vostrushka at gmail.com wrote: > > >> Hi, > > >> I have a file with one parameter per line: > > >> a1 > > >> b1 > > >> c1 > > >> a2 > > >> b2 > > >> c2 > > >> a3 > > >> b3 > > >> c3 > > >> ... > > >> The parameters are lines of characters (not numbers) > > >> > > >> I need to load it to 2D array for further manipulations. > > >> So far I managed to upload this file into 1D array: > > >> > > >> ParametersRaw = [] > > >> with open(file1) as fh: > > >> ParametersRaw = fh.readlines() > > >> fh.close() > > > > > > I tried this code based on yours: > > > > > > with open("input") as fh: > > > lines=fh.readlines() > > > > > > rows = len(lines)//3 > > > > > > params=[] > > > index=0 > > > > > > for row in range(rows): > > > params.append([lines[index],lines[index+1],lines[index+2]]) > > > index += 3 > > > > > > for row in range(rows): > > > print (row,":",params[row]) > > > > > > For the exact input you gave, it produced this output: > > > > > > 0 : ['a1\n', 'b1\n', 'c1\n'] > > > 1 : ['a2\n', 'b2\n', 'c2\n'] > > > 2 : ['a3\n', 'b3\n', 'c3\n'] > > > > > > Probably you'd want to get rid of those \n characters. (I don't know > > > how off-hand as I'm not often write in Python.) > > > > > > The last bit could also be written: > > > > > > for param in params: > > > print (params) > > > > > > but I needed the row index. > > > > > To get rid of the '\n' (lineend) characters: > > > > with open(file1) as fh: > > ParametersRaw = [line.strip() for line in fh.readlines()] > > > > or, more succinctly.. > > > > with open(file1) as fh: > > ParametersRaw = [line.strip() for line in fh] > > > > Comprehensions are your friend. > > > > Nathan What is the significance of prefixing all your variables with "f"? I've frequently seen people use it to signify the variable is a float, but you're using it for things that aren't floats. From sohcahtoa82 at gmail.com Mon Nov 23 19:47:37 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 23 Nov 2015 16:47:37 -0800 (PST) Subject: pip does not work anymore In-Reply-To: <87vb8trw9l.fsf@Equus.decebal.nl> References: <87vb8trw9l.fsf@Equus.decebal.nl> Message-ID: <44438522-c78e-423c-b809-00e0145f8890@googlegroups.com> On Sunday, November 22, 2015 at 11:59:13 PM UTC-8, Cecil Westerhof wrote: > When I try to install something with pip2 I get: > Traceback (most recent call last): > File "/usr/bin/pip2", line 9, in > load_entry_point('pip==7.1.2', 'console_scripts', 'pip2')() > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point > return get_distribution(dist).load_entry_point(group, name) > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point > return ep.load() > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load > return self.resolve() > File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve > module = __import__(self.module_name, fromlist=['__name__'], level=0) > File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 15, in > from pip.vcs import git, mercurial, subversion, bazaar # noqa > File "/usr/lib/python2.7/site-packages/pip/vcs/subversion.py", line 9, in > from pip.index import Link > File "/usr/lib/python2.7/site-packages/pip/index.py", line 30, in > from pip.wheel import Wheel, wheel_ext > File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 35, in > from pip._vendor.distlib.scripts import ScriptMaker > File "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/scripts.py", line 14, in > from .compat import sysconfig, detect_encoding, ZipFile > File "/usr/lib/python2.7/site-packages/pip/_vendor/distlib/compat.py", line 31, in > from urllib2 import (Request, urlopen, URLError, HTTPError, > ImportError: cannot import name HTTPSHandler > > With pip3 I get the same problem. > > It looks like openSUSE has done an upgrade in which it disabled ssl2. > How can I get pip2/3 working again? > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof SSL2 *should* be disabled. It was deprecated nearly 20 years ago, replaced by SSL3, and even THAT has been deprecated. SSL2 is incredibly insecure. From baillargeon at visi.com Mon Nov 23 19:58:13 2015 From: baillargeon at visi.com (Bernard Baillargeon) Date: Mon, 23 Nov 2015 18:58:13 -0600 Subject: 3.5 64b windows Message-ID: <039b01d12653$329212f0$97b638d0$@visi.com> I'd just installed py3.5 most recent (downloaded, installed 11/23/15) and when starting via the windows start (win 8.1pro) shortcut, I always get this error. I'd navigated to the program directory (it installed in C:\Users\my-ID\AppData\Local\Programs\Python\Python35) and started the python.exe and that fails as well. (as does pythonw.exe -silently. nothing even pops!) From george.trojan at noaa.gov Mon Nov 23 22:25:48 2015 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 24 Nov 2015 03:25:48 +0000 Subject: tuples in conditional assignment In-Reply-To: References: Message-ID: <5653D8BC.1040800@noaa.gov> The following code has bitten me recently: >>> t=(0,1) >>> x,y=t if t else 8, 9 >>> print(x, y) (0, 1) 9 I was assuming that a comma has the highest order of evaluation, that is the expression 8, 9 should make a tuple. Why this is not the case? George From ben+python at benfinney.id.au Mon Nov 23 23:49:04 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 24 Nov 2015 15:49:04 +1100 Subject: tuples in conditional assignment References: <5653D8BC.1040800@noaa.gov> Message-ID: <85r3jgatof.fsf@benfinney.id.au> George Trojan writes: > The following code has bitten me recently: > > >>> t=(0,1) > >>> x,y=t if t else 8, 9 > >>> print(x, y) > (0, 1) 9 You can simplify this by taking assignment out of the picture:: >>> t = (0, 1) >>> t if t else 8, 9 ((0, 1), 9) So that's an ?expression list? containing a comma. The reference for expressions tells us:: An expression list containing at least one comma yields a tuple. The length of the tuple is the number of expressions in the list. > I was assuming that a comma has the highest order of evaluation You were? The operator precedence rules don't even mention comma as an operator, so why would you assume that? > that is the expression 8, 9 should make a tuple. Why this is not the > case? I'm not sure why it's the case that you assumed that :-) My practical advice: I don't bother trying to remember the complete operator precedence rules. My simplified precedence rules are: * ?+?, ?-? have the same precedence. * ?*?, ?/?, ?//? have the same precedence. * For anything else: Use parentheses to explicitly declare the precedence I want. Related: When an expression has enough clauses that it's not *completely obvious* what's going on, break it up by assigning some sub-parts to temporary well-chosen descriptive names (not ?t?). -- \ ?It is far better to grasp the universe as it really is than to | `\ persist in delusion, however satisfying and reassuring.? ?Carl | _o__) Sagan | Ben Finney From cs at zip.com.au Tue Nov 24 00:25:12 2015 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 24 Nov 2015 16:25:12 +1100 Subject: Bi-directional sub-process communication In-Reply-To: <84B23819-6214-4BDA-959D-85CD46431212@ravnalaska.net> References: <84B23819-6214-4BDA-959D-85CD46431212@ravnalaska.net> Message-ID: <20151124052512.GA51713@cskk.homeip.net> On 23Nov2015 14:14, Israel Brewster wrote: >On Nov 23, 2015, at 1:43 PM, Chris Kaynor wrote: >> On Mon, Nov 23, 2015 at 2:18 PM, Israel Brewster >> wrote: >> 3. Have an event per thread. This will use less CPU than the second >> option, however does require more memory and OS resources, and so will not >> be viable for huge numbers of threads, though if you hit the limit, you are >> probably using threads wrong. [...] >While I would agree with #1 in general, the threads, in this case, are >CherryPy threads, so I need to get the data and return it to the client in the >same function call, which of course means the thread needs to block until the >data is ready - it can't return and let the result be processed "later". Then #3. I would have a common function/method for submitting a request to go to the subprocess, and have that method return an Event on which to wait. Then caller then just waits for the Event and collects the data. Obviously, the method does not just return the Event, but an Event and something to receive the return data. I've got a class called a Result for this kind of thing; make a small class containing an Event and which will have a .result attribute for the return information; the submitting method allocates one of these and returns it. The response handler gets the instance (by looking it up from the tag), sets the .result attribute and fires the Event. Your caller wakes up from waiting on the Event and consults the .result attribute. Completely untested example code: class ReturnEvent: def __init__(self): self.event = Event() seq = 0 re_by_tag = {} def submit_request(query): global seq, re_by_tag tag = seq seq += 1 RE = ReturnEvent() re_by_tag[tag] = RE send_request(tag, query) return RE def process_response(tag, response_data): RE = re_by_tag.pop(tag) RE.result = response_data RE.event.set() ... CherryPy request handler ... RE = submit_request(your_query_info) RE.wait() response_data = RE.result Cheers, Cameron Simpson From cs at zip.com.au Tue Nov 24 00:29:05 2015 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 24 Nov 2015 16:29:05 +1100 Subject: Bi-directional sub-process communication In-Reply-To: <20151124052512.GA51713@cskk.homeip.net> References: <20151124052512.GA51713@cskk.homeip.net> Message-ID: <20151124052905.GA41045@cskk.homeip.net> On 24Nov2015 16:25, Cameron Simpson wrote: >Completely untested example code: > > class ReturnEvent: > def __init__(self): > self.event = Event() With, of course: def wait(self): return self.event.wait() Cheers, Cameron Simpson Maintainer's Motto: If we can't fix it, it ain't broke. From rosuav at gmail.com Tue Nov 24 01:11:20 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 Nov 2015 17:11:20 +1100 Subject: 3.5 64b windows In-Reply-To: <039b01d12653$329212f0$97b638d0$@visi.com> References: <039b01d12653$329212f0$97b638d0$@visi.com> Message-ID: On Tue, Nov 24, 2015 at 11:58 AM, Bernard Baillargeon wrote: > I'd just installed py3.5 most recent (downloaded, installed 11/23/15) and > when starting via the windows start (win 8.1pro) shortcut, I always get this > error. If you attached something, it didn't arrive. Can you type in the text of what's happening, please? ChrisA From __peter__ at web.de Tue Nov 24 03:36:38 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Nov 2015 09:36:38 +0100 Subject: [argparse] optional parameter without --switch References: <3p4FFS0cRdz5vNy@dovecot03.posteo.de> Message-ID: c.buhtz at posteo.jp wrote: > I want to call (on bash) a Python script in this two ways without any > error. > > ./arg.py > ./arg.py TEST > > It means that the parameter (here with the value `TEST`) should be > optional. With argparse I only know a way to create optional paramters > when they have a switch (like `--name`). $ cat tmp.py #!/usr/bin/env python3 import argparse parser = argparse.ArgumentParser() parser.add_argument("name", nargs="?") print("name =", parser.parse_args().name) $ ./tmp.py name = None $ ./tmp.py 42 name = 42 https://docs.python.org/dev/library/argparse.html#nargs From vostrushka at gmail.com Tue Nov 24 03:56:08 2015 From: vostrushka at gmail.com (Crane Ugly) Date: Tue, 24 Nov 2015 00:56:08 -0800 (PST) Subject: Problem to read from array In-Reply-To: <9ea86586-0052-491a-8991-0a5f986c34ae@googlegroups.com> References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> <81290337-638d-4e50-a85f-054e0a220357@googlegroups.com> <9ea86586-0052-491a-8991-0a5f986c34ae@googlegroups.com> Message-ID: <357a7214-49bc-48ef-902c-1d48ac80be13@googlegroups.com> It is nothing more but naming convention. This code was part of the function. Actually, in the final version I removed that "f" and changed some names of variables to shorter versions. It is all about your own preferences towards readability of the code and ability of visual capture of the code. I always try to have code that easy to read. At least for myself. CU > What is the significance of prefixing all your variables with "f"? I've frequently seen people use it to > signify the variable is a float, but you're using it for things that aren't floats. From Tolga.Karabiyikoglu at ankara.edu.tr Tue Nov 24 03:56:32 2015 From: Tolga.Karabiyikoglu at ankara.edu.tr (Tolga.Karabiyikoglu at ankara.edu.tr) Date: Tue, 24 Nov 2015 10:56:32 +0200 Subject: Persistent api-ms-win-crt-runtime-i1-1-0.dll start up error Message-ID: <979fb56bd7b09c3a8944e56bbcc0c481@ankara.edu.tr> Hi all; Yesterday just downloaded python-3.5.0-amd64 on windows10 running laptop- running flawless. But my trouble is with my office desktop Windows Vista. Considering the processor diference, this time, downloaded the python-3.5.0 (32 bit) version. The question is i am receiving 'api-ms-win-crt-runtime-i1-1-0.dll is missing' error on the start up. I think i did update my Visual C++ Redistributable gear downloading and running vcredist_x86.exe (32 bit) but could not get rid off the error. Do you have any other recipe for me.... From __peter__ at web.de Tue Nov 24 04:31:16 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Nov 2015 10:31:16 +0100 Subject: Problem to read from array References: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> <81290337-638d-4e50-a85f-054e0a220357@googlegroups.com> <9ea86586-0052-491a-8991-0a5f986c34ae@googlegroups.com> <357a7214-49bc-48ef-902c-1d48ac80be13@googlegroups.com> Message-ID: Crane Ugly wrote: > I always try to have code that easy to read. That's laudable, code is a means of communication. > At least for myself. and only for yourself, unfortunately. Recommended read: https://www.python.org/dev/peps/pep-0008/ From lac at openend.se Tue Nov 24 04:54:19 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 24 Nov 2015 10:54:19 +0100 Subject: Persistent api-ms-win-crt-runtime-i1-1-0.dll start up error In-Reply-To: <979fb56bd7b09c3a8944e56bbcc0c481@ankara.edu.tr> References: <979fb56bd7b09c3a8944e56bbcc0c481@ankara.edu.tr> Message-ID: <201511240954.tAO9sJHh007647@fido.openend.se> In a message of Tue, 24 Nov 2015 10:56:32 +0200, Tolga.Karabiyikoglu at ankara.edu .tr writes: >Hi all; > >Yesterday just downloaded python-3.5.0-amd64 on windows10 running >laptop- running flawless. > >But my trouble is with my office desktop Windows Vista. Considering the >processor diference, this time, downloaded the python-3.5.0 (32 bit) >version. >The question is i am receiving 'api-ms-win-crt-runtime-i1-1-0.dll is >missing' error on the start up. I think i did update my Visual C++ >Redistributable gear downloading and running vcredist_x86.exe (32 bit) >but could not get rid off the error. > >Do you have any other recipe for me.... >-- >https://mail.python.org/mailman/listinfo/python-list Yes. You appear to have this problem. https://bugs.python.org/issue25223 Installing http://www.microsoft.com/en-us/download/details.aspx?id=48234 directly seems to fix it. Laura From gengyangcai at gmail.com Tue Nov 24 05:04:56 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 24 Nov 2015 02:04:56 -0800 (PST) Subject: Returning a result from 3 items in a list Message-ID: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> Here's a dictionary with 3 values : results = { "gengyang": 14, "ensheng": 13, "jordan": 12 } How do I define a function that takes the last of the 3 items in that list and returns Jordan's results i.e. (12) ? Thanks a lot ! Gengyang From rosuav at gmail.com Tue Nov 24 05:14:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 Nov 2015 21:14:19 +1100 Subject: Returning a result from 3 items in a list In-Reply-To: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> Message-ID: On Tue, Nov 24, 2015 at 9:04 PM, Cai Gengyang wrote: > Here's a dictionary with 3 values : > > results = { > "gengyang": 14, > "ensheng": 13, > "jordan": 12 > } > > How do I define a function that takes the last of the 3 items in that list and returns Jordan's results i.e. (12) ? > > Thanks a lot ! If you want Jordan's result, that's easy: result["jordan"] But there's no concept of "the last" entry in a dict. They don't have an order. Do you mean "the entry with the greatest key"? That could be written thus: result[max(result)] because max(result) is the string "jordan". Does either of those make sense for what you're doing? ChrisA From gengyangcai at gmail.com Tue Nov 24 05:27:43 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 24 Nov 2015 02:27:43 -0800 (PST) Subject: Returning a result from 3 items in a list In-Reply-To: References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> Message-ID: <45b60b80-d6b7-423e-93b9-2ef4977fb368@googlegroups.com> Strange, it gives me an error message when i type result["jordan"] or result[max(result)] though : >>> results = { "gengyang": 14, "ensheng": 13, "jordan": 12 } >>> result["jordan"] Traceback (most recent call last): File "", line 1, in result["jordan"] NameError: name 'result' is not defined >>> result[max(result)] Traceback (most recent call last): File "", line 1, in result[max(result)] NameError: name 'result' is not defined >>> On Tuesday, November 24, 2015 at 6:14:43 PM UTC+8, Chris Angelico wrote: > On Tue, Nov 24, 2015 at 9:04 PM, Cai Gengyang wrote: > > Here's a dictionary with 3 values : > > > > results = { > > "gengyang": 14, > > "ensheng": 13, > > "jordan": 12 > > } > > > > How do I define a function that takes the last of the 3 items in that list and returns Jordan's results i.e. (12) ? > > > > Thanks a lot ! > > If you want Jordan's result, that's easy: > > result["jordan"] > > But there's no concept of "the last" entry in a dict. They don't have > an order. Do you mean "the entry with the greatest key"? That could be > written thus: > > result[max(result)] > > because max(result) is the string "jordan". > > Does either of those make sense for what you're doing? > > ChrisA From __peter__ at web.de Tue Nov 24 05:32:51 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Nov 2015 11:32:51 +0100 Subject: Returning a result from 3 items in a list References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> Message-ID: Cai Gengyang wrote: > Here's a dictionary with 3 values : > > results = { > "gengyang": 14, > "ensheng": 13, > "jordan": 12 > } > > How do I define a function that takes the last of the 3 items in that list > and returns Jordan's results i.e. (12) ? > > Thanks a lot ! You can access the last item in a *list* with items[-1]: >>> results = [ ... ("gengyang", 14), ... ("ensheng", 13), ... ("jordan", 12) ... ] >>> results[-1] ('jordan', 12) A *dict* is unordered (the order is undefined, to be exact), so there is no "last" item. For the rare case when you need both order and fast lookup there's collections.OrderedDict: >>> results = collections.OrderedDict([ ... ("gengyang", 14), ... ("ensheng", 13), ... ("jordan", 12) ... ]) Get the last value non-destructively: >>> results[next(reversed(results))] # is there a less tedious way? 12 Get the last pair, removing it from the dictionary: >>> results.popitem(last=True) ('jordan', 12) >>> "jordan" in results False From __peter__ at web.de Tue Nov 24 05:35:12 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Nov 2015 11:35:12 +0100 Subject: Returning a result from 3 items in a list References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> <45b60b80-d6b7-423e-93b9-2ef4977fb368@googlegroups.com> Message-ID: Cai Gengyang wrote: > Strange, it gives me an error message when i type result["jordan"] or > result[max(result)] though : > >>>> results = { > "gengyang": 14, > "ensheng": 13, > "jordan": 12 > } > >>>> result["jordan"] > Traceback (most recent call last): > File "", line 1, in > result["jordan"] > NameError: name 'result' is not defined Yeah, the error message really should be "NameError: name 'result' is not defined; did you mean 'results'?" ;) From gengyangcai at gmail.com Tue Nov 24 05:47:44 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 24 Nov 2015 02:47:44 -0800 (PST) Subject: Returning a result from 3 items in a list In-Reply-To: References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> <45b60b80-d6b7-423e-93b9-2ef4977fb368@googlegroups.com> Message-ID: <16cbc004-c22f-492d-9f75-94e14374616d@googlegroups.com> Yup, thanks a lot ... it works now ! >>> results = { "gengyang": 14, "ensheng": 13, "jordan": 12 } >>> results["jordan"] 12 On Tuesday, November 24, 2015 at 6:40:26 PM UTC+8, Peter Otten wrote: > Cai Gengyang wrote: > > > Strange, it gives me an error message when i type result["jordan"] or > > result[max(result)] though : > > > >>>> results = { > > "gengyang": 14, > > "ensheng": 13, > > "jordan": 12 > > } > > > >>>> result["jordan"] > > Traceback (most recent call last): > > File "", line 1, in > > result["jordan"] > > NameError: name 'result' is not defined > > Yeah, the error message really should be > > "NameError: name 'result' is not defined; did you mean 'results'?" > > ;) From eryksun at gmail.com Tue Nov 24 05:53:21 2015 From: eryksun at gmail.com (eryksun) Date: Tue, 24 Nov 2015 04:53:21 -0600 Subject: Persistent api-ms-win-crt-runtime-i1-1-0.dll start up error In-Reply-To: <201511240954.tAO9sJHh007647@fido.openend.se> References: <979fb56bd7b09c3a8944e56bbcc0c481@ankara.edu.tr> <201511240954.tAO9sJHh007647@fido.openend.se> Message-ID: On Tue, Nov 24, 2015 at 3:54 AM, Laura Creighton wrote: > In a message of Tue, 24 Nov 2015 10:56:32 +0200, Tolga.Karabiyikoglu at ankara.edu > >>The question is i am receiving 'api-ms-win-crt-runtime-i1-1-0.dll is >>missing' error on the start up. > > You appear to have this problem. > > https://bugs.python.org/issue25223 > > Installing http://www.microsoft.com/en-us/download/details.aspx?id=48234 > directly seems to fix it. For Vista the Universal CRT update requires service pack 2: http://windows.microsoft.com/en-US/windows-vista/Learn-how-to-install-Windows-Vista-Service-Pack-2-SP2 From gengyangcai at gmail.com Tue Nov 24 06:04:09 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 24 Nov 2015 03:04:09 -0800 (PST) Subject: Getting math scores (Dictionary inside dictionary) Message-ID: results = { "gengyang": { "maths": 10, "english": 15}, "ensheng": {"maths": 12, "english": 10}, "jordan": {"maths": 9, "english": 13} } How do you get gengyang's maths scores ? Thank you ... From rosuav at gmail.com Tue Nov 24 06:05:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 Nov 2015 22:05:04 +1100 Subject: Returning a result from 3 items in a list In-Reply-To: References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> <45b60b80-d6b7-423e-93b9-2ef4977fb368@googlegroups.com> Message-ID: On Tue, Nov 24, 2015 at 9:35 PM, Peter Otten <__peter__ at web.de> wrote: > Yeah, the error message really should be > > "NameError: name 'result' is not defined; did you mean 'results'?" > > ;) Heh. Yes, that was my fault. Sorry Cai! it should have been results["jordan"], as you figured out. ChrisA From gengyangcai at gmail.com Tue Nov 24 06:06:44 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 24 Nov 2015 03:06:44 -0800 (PST) Subject: Returning a result from 3 items in a list In-Reply-To: References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> <45b60b80-d6b7-423e-93b9-2ef4977fb368@googlegroups.com> Message-ID: <22e21276-50f6-49c8-925e-3d33284b49cb@googlegroups.com> Its cool ... No problem On Tuesday, November 24, 2015 at 7:05:25 PM UTC+8, Chris Angelico wrote: > On Tue, Nov 24, 2015 at 9:35 PM, Peter Otten <__peter__ at web.de> wrote: > > Yeah, the error message really should be > > > > "NameError: name 'result' is not defined; did you mean 'results'?" > > > > ;) > > Heh. Yes, that was my fault. Sorry Cai! it should have been > results["jordan"], as you figured out. > > ChrisA From xapwing at gmail.com Tue Nov 24 06:10:47 2015 From: xapwing at gmail.com (Arie van Wingerden) Date: Tue, 24 Nov 2015 12:10:47 +0100 Subject: Getting math scores (Dictionary inside dictionary) In-Reply-To: References: Message-ID: print((results["gengyang"])["maths"]) 2015-11-24 12:04 GMT+01:00 Cai Gengyang : > results = { > "gengyang": { "maths": 10, "english": 15}, > "ensheng": {"maths": 12, "english": 10}, > "jordan": {"maths": 9, "english": 13} > } > > How do you get gengyang's maths scores ? > > Thank you ... > -- > https://mail.python.org/mailman/listinfo/python-list > From gengyangcai at gmail.com Tue Nov 24 06:22:41 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 24 Nov 2015 19:22:41 +0800 Subject: Getting math scores (Dictionary inside dictionary) In-Reply-To: References: Message-ID: Great, it works! Thanks a lot .. >>> results = { "gengyang": { "maths": 10, "english": 15}, "ensheng": {"maths": 12, "english": 10}, "jordan": {"maths": 9, "english": 13} } >>> print((results["gengyang"])["maths"]) 10 On Tue, Nov 24, 2015 at 7:10 PM, Arie van Wingerden wrote: > print((results["gengyang"])["maths"]) > > 2015-11-24 12:04 GMT+01:00 Cai Gengyang : > >> results = { >> "gengyang": { "maths": 10, "english": 15}, >> "ensheng": {"maths": 12, "english": 10}, >> "jordan": {"maths": 9, "english": 13} >> } >> >> How do you get gengyang's maths scores ? >> >> Thank you ... >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From steve at pearwood.info Tue Nov 24 06:25:56 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 24 Nov 2015 22:25:56 +1100 Subject: tuples in conditional assignment References: Message-ID: <56544946$0$1593$c3e8da3$5496439d@news.astraweb.com> On Tue, 24 Nov 2015 02:25 pm, George Trojan wrote: > The following code has bitten me recently: > > >>> t=(0,1) > >>> x,y=t if t else 8, 9 > >>> print(x, y) > (0, 1) 9 > > I was assuming that a comma has the highest order of evaluation, that is > the expression 8, 9 should make a tuple. Why this is not the case? I'm not sure what sort of answer you are looking for. Why does anything have the precedence it has? Making assumptions about the comma's precedence in that way seems unsafe to me. Consider that function(a, b, c, d) is a function call with four arguments, NOT a single 4-tuple argument. And: py> 1, 2, 3 * 2 # expecting (1, 2, 3, 1, 2, 3) (1, 2, 6) So there's plenty of evidence that the comma has a very low order of evaluation, not the highest, and it seems remarkably unsafe to assume the opposite. Fortunately, it is very simple to test these things out at the interactive interpreter. I cannot imagine doing any Python programming without having a Python shell open and ready for me to try out code snippets. -- Steven From steve at pearwood.info Tue Nov 24 06:28:20 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 24 Nov 2015 22:28:20 +1100 Subject: Getting math scores (Dictionary inside dictionary) References: Message-ID: <565449d6$0$1593$c3e8da3$5496439d@news.astraweb.com> On Tue, 24 Nov 2015 10:04 pm, Cai Gengyang wrote: > results = { > "gengyang": { "maths": 10, "english": 15}, > "ensheng": {"maths": 12, "english": 10}, > "jordan": {"maths": 9, "english": 13} > } > > How do you get gengyang's maths scores ? Break the problem into two steps: - get Gengyang's scores; - then get the maths score: scores = results['gengyang'] maths_score = scores['maths'] Now you can simplify the process: maths_score = results['gengyang']['maths'] -- Steven From antoon.pardon at rece.vub.ac.be Tue Nov 24 06:36:11 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 12:36:11 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: Message-ID: <56544BAB.9020709@rece.vub.ac.be> Op 19-11-15 om 00:22 schreef Chris Angelico: > On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: >> On 18/11/2015 22:11, Ian Kelly wrote: >>> >>> On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: >>>> >>>> Hi, >>>> >>>> I have tried the below function and find that it can remember the >>>> previous >>>> setting value to 'val'. I think the second parameter has something on >>>> this >>>> effect, but I don't know the name and function of '=[]' in this >>>> application. >>>> >>>> Could you explain a little to me? >>>> Thanks, >>>> >>>> >>>> def eList(val, list0=[]): >>>> list0.append(val) >>>> return list0 >>>> list1 = eList(12) >>>> list1 = eList('a') >>> >>> >>> The list0 parameter has a default value, which is [], an initially >>> empty list. The default value is evaluated when the function is >>> defined, not when it is called, so the same list object is used each >>> time and changes to the list are consequently retained between calls. >> >> >> That is really bizarre behaviour. >> >> So, looking at some source code, a default value for certain types is only >> certain to be that value for the very first call of that function? > > On the contrary, it is certain always to be that exact object. No, he is talking about the value. Since the object can be mutated and thus have an other value, his statement seems correct. -- Antoon. From rosuav at gmail.com Tue Nov 24 07:07:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 Nov 2015 23:07:34 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <56544BAB.9020709@rece.vub.ac.be> References: <56544BAB.9020709@rece.vub.ac.be> Message-ID: On Tue, Nov 24, 2015 at 10:36 PM, Antoon Pardon wrote: >>> So, looking at some source code, a default value for certain types is only >>> certain to be that value for the very first call of that function? >> >> On the contrary, it is certain always to be that exact object. > > No, he is talking about the value. Since the object can be mutated > and thus have an other value, his statement seems correct. With mutable objects, you can *never* depend on their values. Any time ANY byte code gets executed, the value could change. That's why I have never said anything about *values* of arg defaults - what you're promised is that the *object* will be the same (so, I'm looking at its identity, rather than its value). So it's not even certain to be that value even for the first call: def create_user(name, email, creation_time=datetime.datetime.now()): Looks perfectly reasonable, right? And with late binding, sure! But with early binding, this will probably NEVER be what you want. But what if you have an object that always stringifies the current time? class Now: def __init__(self, fmt): self.fmt = fmt def __repr__(self): return datetime.datetime.now().strftime(self.fmt) def create_user(name, email, creation_time=Now("%Y%m%d%H%M%S")): Voila! An object whose value dynamically represents the notion of "Now", but where it makes fine sense to have the same object used every time. Since the value changes every second, it (probably) won't even have that value for the first call, yet the behaviour will be correct. His statement is still incorrect, in that the value is NEVER certain, but the identity is ALWAYS certain. It happens to be the case for the one example of lists that get mutated only in the function. It's about as accurate as the statement that Python is pass-by-value for integers but pass-by-reference for dictionaries. ChrisA From breamoreboy at yahoo.co.uk Tue Nov 24 07:15:48 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 24 Nov 2015 12:15:48 +0000 Subject: Getting math scores (Dictionary inside dictionary) In-Reply-To: References: Message-ID: On 24/11/2015 11:04, Cai Gengyang wrote: > results = { > "gengyang": { "maths": 10, "english": 15}, > "ensheng": {"maths": 12, "english": 10}, > "jordan": {"maths": 9, "english": 13} > } > > How do you get gengyang's maths scores ? > > Thank you ... > One way is to delete the scores for ensheng and jordan, only leaving those for gengyang, then extract the maths score. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From xapwing at gmail.com Tue Nov 24 07:23:56 2015 From: xapwing at gmail.com (Arie van Wingerden) Date: Tue, 24 Nov 2015 13:23:56 +0100 Subject: Getting math scores (Dictionary inside dictionary) In-Reply-To: References: Message-ID: Hi Mark, what use would that have? Please show your code ... 2015-11-24 13:15 GMT+01:00 Mark Lawrence : > On 24/11/2015 11:04, Cai Gengyang wrote: > >> results = { >> "gengyang": { "maths": 10, "english": 15}, >> "ensheng": {"maths": 12, "english": 10}, >> "jordan": {"maths": 9, "english": 13} >> } >> >> How do you get gengyang's maths scores ? >> >> Thank you ... >> >> > One way is to delete the scores for ensheng and jordan, only leaving those > for gengyang, then extract the maths score. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > From antoon.pardon at rece.vub.ac.be Tue Nov 24 07:38:01 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 13:38:01 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56545A29.1040101@rece.vub.ac.be> Op 19-11-15 om 13:45 schreef Steven D'Aprano: > On Thu, 19 Nov 2015 10:41 pm, BartC wrote: > > >> I expect the version with the default argument to be >> exactly the same as the last lot of calls, namely for: >> >> fn() >> fn() >> fn() >> >> to be equivalent to: >> >> temp=[] >> fn(temp) >> temp=[] >> fn(temp) >> temp=[] >> fn(temp) > > Why on earth would you expect that? > > I don't mean that it isn't sometimes useful. Of course it is sometimes > useful, there's no doubt about that. But why would you expect the language > to default to the *slow*, *expensive*, *complicated* behaviour instead of > the *fast*, *cheap*, *simple* behaviour? I would say because it is better understandable. The way default value behave now, is just a little less surprising as when the following segment of code would print: [1] a = [] a.append(1) b = [] print b Let us not forget that the tutorial talks about Default Argument *Values*. And also the language reference talks about precomputed *values*. What we really get is a precomputed object. > You already have one way to set the argument to a fresh list every time you > call the function: put the code you want executed inside the body of the > function. There's no need for a *second* way to get the same result. Which is beside the point. The point is understandability. > But if you want the default value to be evaluated exactly once, and once > only, there is no real alternative to early binding. You could use a global > variable, of course, but that is no solution -- that's a problem waiting to > happen. No more than the situation we have now. The situation we have now is a problem waiting to happen too. Which is confirmed again and again. You are stacking the deck by calling a possible alternative "a problem waiting to happen" while ignoring the problems that happen with the current situation. From antoon.pardon at rece.vub.ac.be Tue Nov 24 07:48:25 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 13:48:25 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <56544BAB.9020709@rece.vub.ac.be> Message-ID: <56545C99.9020902@rece.vub.ac.be> Op 24-11-15 om 13:07 schreef Chris Angelico: > On Tue, Nov 24, 2015 at 10:36 PM, Antoon Pardon > wrote: >>>> So, looking at some source code, a default value for certain types is only >>>> certain to be that value for the very first call of that function? >>> >>> On the contrary, it is certain always to be that exact object. >> >> No, he is talking about the value. Since the object can be mutated >> and thus have an other value, his statement seems correct. > > With mutable objects, you can *never* depend on their values. Any time > ANY byte code gets executed, the value could change. That's why I have > never said anything about *values* of arg defaults. Yes you have. You haven't mentioned them yourself. But when you contradict the statement of someone and that person talked about values, then in contradicting that statement you said something about values. You then switching to talking about objects, just gives the impression that object is a synonym for value. -- Antoon From marko at pacujo.net Tue Nov 24 07:57:34 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 24 Nov 2015 14:57:34 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> Message-ID: <874mgbpnb5.fsf@elektro.pacujo.net> Antoon Pardon : > You then switching to talking about objects, just gives the impression > that object is a synonym for value. It isn't? Marko From gengyangcai at gmail.com Tue Nov 24 08:25:28 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 24 Nov 2015 05:25:28 -0800 (PST) Subject: Finding scores from a list Message-ID: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> results = [ {"id": 1, "name": "ensheng", "score": 10}, {"id": 2, "name": "gengyang", "score": 12}, {"id": 3, "name": "jordan", "score": 5}, ] I want to find gengyang's score. This is what I tried : >>> print((results["gengyang"])["score"]) but I got an error message instead : Traceback (most recent call last): File "", line 1, in print((results["gengyang"])["score"]) TypeError: list indices must be integers, not str Any ideas how to solve this? Thank you .. From breamoreboy at yahoo.co.uk Tue Nov 24 08:30:23 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 24 Nov 2015 13:30:23 +0000 Subject: Getting math scores (Dictionary inside dictionary) In-Reply-To: References: Message-ID: On 24/11/2015 12:23, Arie van Wingerden wrote: > Hi Mark, what use would that have? Please show your code ... > > 2015-11-24 13:15 GMT+01:00 Mark Lawrence : > >> On 24/11/2015 11:04, Cai Gengyang wrote: >> >>> results = { >>> "gengyang": { "maths": 10, "english": 15}, >>> "ensheng": {"maths": 12, "english": 10}, >>> "jordan": {"maths": 9, "english": 13} >>> } >>> >>> How do you get gengyang's maths scores ? >>> >>> Thank you ... >>> >>> >> One way is to delete the scores for ensheng and jordan, only leaving those >> for gengyang, then extract the maths score. >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> 1) I was being facetious. 2) How many times do people have to be asked not to top post here before they stop top posting? 3) I only have two things to say so this is superfluous. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Tue Nov 24 08:41:58 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 24 Nov 2015 15:41:58 +0200 Subject: Getting math scores (Dictionary inside dictionary) References: Message-ID: <87poyzo6op.fsf@elektro.pacujo.net> Mark Lawrence : > 1) I was being facetious. > 2) How many times do people have to be asked not to top post here > before they stop top posting? > 3) I only have two things to say so this is superfluous. Mark, it may not be your objective, but you really are poisoning the atmosphere here. Marko From antoon.pardon at rece.vub.ac.be Tue Nov 24 08:43:33 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 14:43:33 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> Message-ID: <56546985.8060704@rece.vub.ac.be> Op 20-11-15 om 01:27 schreef Ned Batchelder: > On Thursday, November 19, 2015 at 7:11:52 PM UTC-5, BartC wrote: >> On 19/11/2015 22:55, Michael Torrie wrote: >>> On 11/19/2015 02:21 PM, BartC wrote: >>>> (Python returns 42; so that means my languages are more dynamic than >>>> Python? That's hard to believe!) >>> >>> It tells me your language does late binding for default arguments, which >>> does mean the default argument can dynamically change at call time, >>> which would surprise me if I didn't know about it. Either form of >>> binding is acceptable, and I don't think it makes a language more or >>> less dynamic. >> >> You get the expression that is specified, which can give different >> values at different times unless it involves only constants. >> >> It can't be exactly the same as writing an identical expression in place >> of the missing argument, as apparently different scopes come into play >> if names are involved. >> >> However I mainly use them for constant values. And [] is a constant >> value in my opinion. >> >> -- >> Bartc > > You are not alone in being surprised by how mutable default values work. > It is a topic that comes up in every "What's Bad About Python" discussion, > and is a common question from new users of the language. > > I can understand how you would view [] as a constant value. It's true that > it is an expression that produces a consistent value each time it is > evaluated. But that value is a list, and lists are mutable. The examples > here all use the .append() method on that value, which changes it. I think that part of the problem is, that [] is not a constant object. So that when you see a line like ls = [] It behaves more lke ls = [].copy() than what you would expect with the normal python semantics. -- Antoon From breamoreboy at yahoo.co.uk Tue Nov 24 08:44:47 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 24 Nov 2015 13:44:47 +0000 Subject: Finding scores from a list In-Reply-To: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> References: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> Message-ID: On 24/11/2015 13:25, Cai Gengyang wrote: > > results = [ > {"id": 1, "name": "ensheng", "score": 10}, > {"id": 2, "name": "gengyang", "score": 12}, > {"id": 3, "name": "jordan", "score": 5}, > ] > > I want to find gengyang's score. This is what I tried : > >>>> print((results["gengyang"])["score"]) > > but I got an error message instead : > > Traceback (most recent call last): > File "", line 1, in > print((results["gengyang"])["score"]) > TypeError: list indices must be integers, not str > > Any ideas how to solve this? Thank you .. > Please read and digest the TypeError. There is a very strong hint in there, follow it. Compare the type of your data structure `results` with the one you've used earlier today. Spot the difference? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From antoon.pardon at rece.vub.ac.be Tue Nov 24 08:48:34 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 14:48:34 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56546AB2.1080806@rece.vub.ac.be> Op 19-11-15 om 19:20 schreef Mark Lawrence: > On 19/11/2015 17:30, BartC wrote: >> On 19/11/2015 16:01, Steven D'Aprano wrote: >>> On Fri, 20 Nov 2015 12:19 am, BartC wrote: >> >>> You know, for somebody who claims to design and implement your own >>> languages, you sometimes go to a remarkable effort to claim to be a >>> dummy. >>> You write your own interpreter, but can't understand early versus late >>> binding? I don't think so. >> >> No I don't; so? Maybe my interpreter can do its thing without being >> aware that what it's doing has been called 'late binding' or 'early >> binding' by someone else. >> >> At least its default values work as expected! >> > > Python's default values work exactly as I expect as the subject has been debated at least twice a year > on c.l.py for the 15 or so years that I've been using Python. If your expectations are clearly wrong, > that is your problem and your problem alone. Absolution to your problem is another language that does > meet all of your expectations, but as there is never a "one size fits all" the only one that I can > think of is your own, whatever that is called. Nonsense. The fact that an experienced programmer, gets to be extremely familiar with some languages and thus gets his expectations adapted, doesn't mean that there is something wrong with what newby's intuitively expect to happen. On the contrary, the regularity with how this subjects keep coming up, is an indication that this is a problem with python. -- Antoon. From __peter__ at web.de Tue Nov 24 08:50:01 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Nov 2015 14:50:01 +0100 Subject: Finding scores from a list References: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> Message-ID: Cai Gengyang wrote: > > results = [ > {"id": 1, "name": "ensheng", "score": 10}, > {"id": 2, "name": "gengyang", "score": 12}, > {"id": 3, "name": "jordan", "score": 5}, > ] > > I want to find gengyang's score. This is what I tried : > >>>> print((results["gengyang"])["score"]) > > but I got an error message instead : > > Traceback (most recent call last): > File "", line 1, in > print((results["gengyang"])["score"]) > TypeError: list indices must be integers, not str > > Any ideas how to solve this? Thank you .. As the outer container is a list you have to provide an index: results[1]["score"] You can also search for a matching item: for result in results: if result["name"] == "gengyang": print(result["score"]) but when the list grows performance will suffer. General note: you will have a better experience learning Python when you read some introductory text first, to get the big picture. From rosuav at gmail.com Tue Nov 24 09:00:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 01:00:28 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <56546985.8060704@rece.vub.ac.be> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 12:43 AM, Antoon Pardon wrote: > I think that part of the problem is, that [] is not a constant object. So > that when you see a line like > > ls = [] > > It behaves more lke > > ls = [].copy() > > than what you would expect with the normal python semantics. You're still thinking in terms of [] being a literal. It isn't; the docs describe it as "list display", and it's closer to: ls = list() except that it doesn't look up the global name. Every time you call open(), you expect it to open a fresh file handle, right? (Even if you use the same file name.) And every time you call object(), you get a new and unique sentinel object. It's the same with list(), and it's the same with square brackets as well. Start thinking of it as a constructor call rather than a literal, and you'll get past most of the confusion. ChrisA From luisjosenovoa at gmail.com Tue Nov 24 09:04:14 2015 From: luisjosenovoa at gmail.com (LJ) Date: Tue, 24 Nov 2015 06:04:14 -0800 (PST) Subject: Multiprocessing PyPy-CPython Message-ID: Hi everyone. Im trying to solve some problems in parallel using the multiprocessing module in Python 2.7. A general model is built using CPython and then the subproblems are solved in parallel returning results in a queue. This is currently working fine. I would like to solve the subproblems using PyPy to increase speed. I found http://project-trains.tumblr.com/post/102076598295/multiprocessing-pypy , but there it says that the procedure only works with CPython 3.4. I wonder is there is any clean direct way to do this. Appreciate any help. From denismfmcmahon at gmail.com Tue Nov 24 09:07:31 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 24 Nov 2015 14:07:31 -0000 (UTC) Subject: Returning a result from 3 items in a list References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> Message-ID: On Tue, 24 Nov 2015 02:04:56 -0800, Cai Gengyang wrote: > Here's a dictionary with 3 values : > > results = { > "gengyang": 14, > "ensheng": 13, "jordan": 12 > } > > How do I define a function that takes the last of the 3 items in that > list and returns Jordan's results i.e. (12) ? You open a web browser and google for "python dictionary" -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Tue Nov 24 09:09:14 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 24 Nov 2015 14:09:14 -0000 (UTC) Subject: Getting math scores (Dictionary inside dictionary) References: Message-ID: On Tue, 24 Nov 2015 03:04:09 -0800, Cai Gengyang wrote: > results = { > "gengyang": { "maths": 10, "english": 15}, > "ensheng": {"maths": 12, "english": 10}, "jordan": {"maths": 9, > "english": 13} > } > > How do you get gengyang's maths scores ? I refer to my previous answer. Open a web browser and google "python dictionary" -- Denis McMahon, denismfmcmahon at gmail.com From bc at freeuk.com Tue Nov 24 09:12:39 2015 From: bc at freeuk.com (BartC) Date: Tue, 24 Nov 2015 14:12:39 +0000 Subject: Finding scores from a list In-Reply-To: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> References: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> Message-ID: On 24/11/2015 13:25, Cai Gengyang wrote: > > results = [ > {"id": 1, "name": "ensheng", "score": 10}, > {"id": 2, "name": "gengyang", "score": 12}, > {"id": 3, "name": "jordan", "score": 5}, > ] > > I want to find gengyang's score. This is what I tried : > >>>> print((results["gengyang"])["score"]) > > but I got an error message instead : > > Traceback (most recent call last): > File "", line 1, in > print((results["gengyang"])["score"]) > TypeError: list indices must be integers, not str > > Any ideas how to solve this? Thank you .. Your new results type is a list of dicts. Lists are indexed by a number. That will be results[1] for the dict relevant to "gengyang" (not even the 2 of the "id", because lists start counting at 0). To find the entry for particular name, you have to search for it (for a list entry where the dict key "name" gives you the value you expect, ie. "gengyang" in this example). So a dict of dicts was a better idea. -- Bartc From ned at nedbatchelder.com Tue Nov 24 09:18:19 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 24 Nov 2015 06:18:19 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: <874mgbpnb5.fsf@elektro.pacujo.net> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> Message-ID: <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> On Tuesday, November 24, 2015 at 7:57:54 AM UTC-5, Marko Rauhamaa wrote: > Antoon Pardon : > > > You then switching to talking about objects, just gives the impression > > that object is a synonym for value. > > It isn't? We are tangled up in another terminology conflict. The word "value" is being used in two different senses. It's understandable that this results in confusion. Neither use is incorrect, we just have to understand that there are multiple meanings, and clarify where the meaning is uncertain. 1) In English, "value" means something like, what is this equal to? There isn't another good word to use in place of "value" here. We might awkwardly use the word "equivalence" as a synonym. I'll use the word "evalue" (short for "equal value" or "equivalence value" or "English value"). The == operator is useful for testing whether two values are "the same evalue". In this sense, the expression "[]" always evaluates to the same value, an empty list: >>> a = [] >>> b = [] >>> a == b True 2) In Python, "value" means, what object does a name refer to, or what object did an evaluation produce. We could use "referent" as a synonym for this meaning. The Python operator "is" tests whether two values are the same referent, or, the same object. In this sense, "[]" always evaluates to a different value, because you get a new empty list each time: >>> a = [] >>> b = [] >>> a is b False Mutable objects are complicated because the same referent (object) can change its evalue over time. The confusion over mutable default arguments arises because the defaulted argument always gets the same referent, but it might not always be the same evalue. --Ned. From antoon.pardon at rece.vub.ac.be Tue Nov 24 09:18:43 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 15:18:43 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <565471C3.3060305@rece.vub.ac.be> Op 20-11-15 om 02:05 schreef Steven D'Aprano: > On Fri, 20 Nov 2015 04:30 am, BartC wrote: > >> On 19/11/2015 16:01, Steven D'Aprano wrote: > [...] > >> The whole concept of 'mutable' default is alien to me. A default is just >> a convenient device to avoid having to write: >> >> fn(0) or fn("") or fn([]) > > Says who? > > Here's another use for function defaults, as static storage: > > > # Ackermann's function > def ack(m, n, _memo={}): > key = m, n > if key not in _memo: > if m==0: v = n + 1 > elif n==0: v = ack(m-1, 1) > else: v = ack(m-1, ack(m, n-1)) > _memo[key] = v > return _memo[key] > > > This is a quick and easy way to memoise a function which would otherwise be > horribly slow. And it only works because _memo is bound to a mutable object > once, and once only. I think this is the worst kind of example you can give in defense for this kind of behaviour. Because you are defining a function as having three parameters where it really has only two. You really don't want this function to be called with that third parameter. Secondly, because we have decorators now, it really is not a good idea to define your function with the memoization in the body functionality. Thirdly your use with a default argument would go horribly wrong, should we try to use it in the decorator definition. -- Antoon. From antoon.pardon at rece.vub.ac.be Tue Nov 24 09:24:55 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 15:24:55 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> Message-ID: <56547337.4000709@rece.vub.ac.be> Op 24-11-15 om 15:00 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 12:43 AM, Antoon Pardon > wrote: >> I think that part of the problem is, that [] is not a constant object. So >> that when you see a line like >> >> ls = [] >> >> It behaves more lke >> >> ls = [].copy() >> >> than what you would expect with the normal python semantics. > > You're still thinking in terms of [] being a literal. It isn't; the > docs describe it as "list display", and it's closer to: > > ls = list() No I am not. The distinction you are making here is unimportant for the point I am making. And that is that although v = () and v = [] look very similar. They behave differently. > except that it doesn't look up the global name. Every time you call > open(), you expect it to open a fresh file handle, right? (Even if you > use the same file name.) And every time you call object(), you get a > new and unique sentinel object. It's the same with list(), and it's > the same with square brackets as well. > > Start thinking of it as a constructor call rather than a literal, and > you'll get past most of the confusion. That doesn't change the fact it does look like a literal and not like a constructor. -- Antoon. From breamoreboy at yahoo.co.uk Tue Nov 24 09:28:57 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 24 Nov 2015 14:28:57 +0000 Subject: Returning a result from 3 items in a list In-Reply-To: References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> Message-ID: On 24/11/2015 14:07, Denis McMahon wrote: > On Tue, 24 Nov 2015 02:04:56 -0800, Cai Gengyang wrote: > >> Here's a dictionary with 3 values : >> >> results = { >> "gengyang": 14, >> "ensheng": 13, "jordan": 12 >> } >> >> How do I define a function that takes the last of the 3 items in that >> list and returns Jordan's results i.e. (12) ? > > You open a web browser and google for "python dictionary" > Ooh steady on old chap, surely you should have fitted the bib, done the spoon feeding and then changed the nappy? That appears to me the preferred way of doing things nowadays on c.l.py, rather than bluntly telling people not to be so bloody lazy. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Tue Nov 24 09:34:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 01:34:03 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <56547337.4000709@rece.vub.ac.be> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon wrote: >> Start thinking of it as a constructor call rather than a literal, and >> you'll get past most of the confusion. > > That doesn't change the fact it does look like a literal and not like > a constructor. Then explain how this is a literal: squares = [x*x for x in range(int(input("How far? ")))] Or even a simple example like this: coords = (randrange(10), randrange(10)) Neither of them is a literal, even though one of them isn't even constructing a list. Tuples may be constant, but they still don't have a literal form. (Constant folding can make them function the same way literals do, though. If a tuple is constructed of nothing but immutable constants - including an empty tuple - then CPython will generally create a constant for the whole tuple and use that, rather than manually constructing one every time. But the same is true of other expressions involving nothing but constants.) So if it (in your opinion) looks like a literal but isn't one, whose fault is it? Yours or the language's? Not a rhetorical question. ChrisA From antoon.pardon at rece.vub.ac.be Tue Nov 24 09:34:15 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 15:34:15 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56547567.2090603@rece.vub.ac.be> Op 20-11-15 om 13:12 schreef Ned Batchelder: > On Friday, November 20, 2015 at 6:59:54 AM UTC-5, BartC wrote: >> On 20/11/2015 01:05, Steven D'Aprano wrote: >>> On Fri, 20 Nov 2015 04:30 am, BartC wrote: >>> >>>> On 19/11/2015 16:01, Steven D'Aprano wrote: >>> [...] >>> >>>> The whole concept of 'mutable' default is alien to me. A default is just >>>> a convenient device to avoid having to write: >>>> >>>> fn(0) or fn("") or fn([]) >>> >>> Says who? >> >> People who want to avoid having to write: >> >> fn(0) or fn("") or fn([]) > > I think we all understand by now that you are unhappy with what happens > in Python with mutable defaults. We get it. You are not alone. Lots of > people are surprised by this. But it is how Python works. May be you should get this message through to the python tribe, so that they stop reacting as a stung horse each time someone finds something bizarre with the language. > I'm not sure what your goal is at this point. Are you: > > 1) still unsure what the behavior is, or > 2) trying to understand why it behaves that way, or > 3) hoping to change Python, or > 4) trying to convince us that your language is better, or > 5) something else? Maybe just have us recognize that some aspects of python indeed are bizarre. That there is nothing wrong with him thinking so. After that he will have to make up his mind whether this bizarre aspect is to big a hurdle for using the language or not, because it seems unlikely to change. -- Antoon. From antoon.pardon at rece.vub.ac.be Tue Nov 24 09:38:26 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 15:38:26 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56547662.6060708@rece.vub.ac.be> Op 20-11-15 om 14:04 schreef Chris Angelico: > On Fri, Nov 20, 2015 at 11:39 PM, BartC wrote: >> * The refusal to acknowledge that the def fn(a=[]) syntax is misleading. >> (What value will a have when you call fn()? The true answer is that you >> can't tell.) > > It isn't misleading. The default value for the argument is set when > the function is defined, and it is set to the *object* that results > from evaluating the *expression* given. After that, the *object* is > the one you will always get (barring shenanigans) if the argument is > omitted. If the value of that object changes, it changes! That you can perfectly explain what happens, doesn't contradict that it is misleading. On the contrary, the fact that one needs all this explanation in order to grasp what is happening, confirms that it is misleading. And you may be talking about objects here. The tutorial talks about values. > You keep expecting the *value* to be consistent. But what you actually > get is that the *object* is consistent. It's virtually impossible to > guarantee the former, in the face of mutable objects. What is wrong with expecting the value to be consistent when the tutorial talks about values? -- Antoon. From xapwing at gmail.com Tue Nov 24 09:43:43 2015 From: xapwing at gmail.com (Arie van Wingerden) Date: Tue, 24 Nov 2015 15:43:43 +0100 Subject: Getting math scores (Dictionary inside dictionary) In-Reply-To: <87poyzo6op.fsf@elektro.pacujo.net> References: <87poyzo6op.fsf@elektro.pacujo.net> Message-ID: 2015-11-24 14:41 GMT+01:00 Marko Rauhamaa : > Mark Lawrence : > > > 1) I was being facetious. > > 2) How many times do people have to be asked not to top post here > > before they stop top posting? > > 3) I only have two things to say so this is superfluous. > > Having posted only 2 times in this list I was not aware of the specific religious mailing list book used here. So please apologize :-) From bc at freeuk.com Tue Nov 24 09:43:43 2015 From: bc at freeuk.com (BartC) Date: Tue, 24 Nov 2015 14:43:43 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> Message-ID: On 24/11/2015 14:18, Ned Batchelder wrote: > On Tuesday, November 24, 2015 at 7:57:54 AM UTC-5, Marko Rauhamaa wrote: >> Antoon Pardon : >> >>> You then switching to talking about objects, just gives the impression >>> that object is a synonym for value. >> >> It isn't? > 1) In English, "value" means something like, what is this equal to? There > isn't another good word to use in place of "value" here. We might awkwardly > use the word "equivalence" as a synonym. I'll use the word "evalue" (short > for "equal value" or "equivalence value" or "English value"). The == > operator is useful for testing whether two values are "the same evalue". > In this sense, the expression "[]" always evaluates to the same value, > an empty list: > > >>> a = [] > >>> b = [] > >>> a == b > True > > 2) In Python, "value" means, what object does a name refer to, or what > object did an evaluation produce. We could use "referent" as a > synonym for this meaning. The Python operator "is" tests whether two > values are the same referent, or, the same object. In this sense, "[]" > always evaluates to a different value, because you get a new empty list > each time: > > >>> a = [] > >>> b = [] > >>> a is b > False And [] is [] gives False too! For my own benefit, I use the term Handle when shared values are involved. It comes from the use of file handles (what you get in some languages when you open or create a file) which everyone can understand: * If you copy handle F to G like in an assignment, it obviously doesn't copy the contents of the file, just the handle. * If I compare the contents of files F and H, they might be the same, but they are not necessarily the same file. * If F and G are the same handle, then if I update a file via F, I will see the same change via handle G. The main difference is that when F and G go out of scope and the handles disappear, the file hopefully still exists! (And ideally the file is first closed via one of the handles.) From your example, the syntax '[]' is roughly equivalent to 'create_empty_file()' in my analogy. (I don't really want to get back to default arguments, but that would extend to: def fn(a = create_empty_file()): which makes it easier to appreciate the implications of 'early' and 'late' binding. But I still think that reads as though you get a fresh, empty file each time.) -- Bartc -- bartc From ned at nedbatchelder.com Tue Nov 24 09:50:33 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 24 Nov 2015 06:50:33 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <894f488e-9707-4184-a53f-670a16399665@googlegroups.com> On Tuesday, November 24, 2015 at 9:34:36 AM UTC-5, Antoon Pardon wrote: > Op 20-11-15 om 13:12 schreef Ned Batchelder: > > On Friday, November 20, 2015 at 6:59:54 AM UTC-5, BartC wrote: > >> On 20/11/2015 01:05, Steven D'Aprano wrote: > >>> On Fri, 20 Nov 2015 04:30 am, BartC wrote: > >>> > >>>> On 19/11/2015 16:01, Steven D'Aprano wrote: > >>> [...] > >>> > >>>> The whole concept of 'mutable' default is alien to me. A default is just > >>>> a convenient device to avoid having to write: > >>>> > >>>> fn(0) or fn("") or fn([]) > >>> > >>> Says who? > >> > >> People who want to avoid having to write: > >> > >> fn(0) or fn("") or fn([]) > > > > I think we all understand by now that you are unhappy with what happens > > in Python with mutable defaults. We get it. You are not alone. Lots of > > people are surprised by this. But it is how Python works. > > May be you should get this message through to the python tribe, so that > they stop reacting as a stung horse each time someone finds something > bizarre with the language. I agree with you: Python experts shouldn't be surprised when people are surprised by this behavior. > > > I'm not sure what your goal is at this point. Are you: > > > > 1) still unsure what the behavior is, or > > 2) trying to understand why it behaves that way, or > > 3) hoping to change Python, or > > 4) trying to convince us that your language is better, or > > 5) something else? > > Maybe just have us recognize that some aspects of python indeed are bizarre. > That there is nothing wrong with him thinking so. After that he will have > to make up his mind whether this bizarre aspect is to big a hurdle for > using the language or not, because it seems unlikely to change. I also agree with you: there is nothing wrong with people thinking parts of Python are bizarre. What we ask is that people then try to understand how Python works. If people say, "This surprised me, Python is stupid!" and then leave it there, the conversation is bound to go poorly. Every language works differently, and every language has things that will surprise new learners. --Ned. From rosuav at gmail.com Tue Nov 24 09:54:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 01:54:45 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> Message-ID: On Wed, Nov 25, 2015 at 1:43 AM, BartC wrote: > It comes from the use of file handles (what you get in some languages when > you open or create a file) which everyone can understand: > > * If you copy handle F to G like in an assignment, it obviously doesn't copy > the contents of the file, just the handle. > > * If I compare the contents of files F and H, they might be the same, but > they are not necessarily the same file. > > * If F and G are the same handle, then if I update a file via F, I will see > the same change via handle G. > > The main difference is that when F and G go out of scope and the handles > disappear, the file hopefully still exists! (And ideally the file is first > closed via one of the handles.) I would recommend picking a different example, actually. An open file (the resource) is different from the file that actually exists on the disk. You can open a file for reading three times, and barring access conflicts etc, you'll get three distinct open-file-objects (file handles, etc), with separate read pointers, and advancing the file pointer of one has no effect on the other two. Plus there are other considerations like the notion of duplicating file handles, force-duplicating file handles (sometimes called "dup2"), files that no longer exist on disk but only in memory, files that exist on disk but no longer have any file names, and so on. Files are way WAY more complicated than you want to dig into here. ChrisA From antoon.pardon at rece.vub.ac.be Tue Nov 24 09:58:12 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 15:58:12 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <56531ba1$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652c4ac$0$1621$c3e8da3$5496439d@news.astraweb.com> <56531ba1$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56547B04.1020006@rece.vub.ac.be> Op 23-11-15 om 14:58 schreef Steven D'Aprano: > On Mon, 23 Nov 2015 09:40 pm, BartC wrote: > >> On 23/11/2015 07:47, Steven D'Aprano wrote: >> >>> I think it would be cleaner and better if Python had dedicated syntax for >>> declaring static local variables: >> >> Interesting. So why is it that when /I/ said: >> >> > On Mon, 23 Nov 2015 12:21 am, BartC wrote: >> > >> >> But if it's used for static storage, then why not just use static >> >> storage? >> >> You replied with the insulting: >> >> > /head-desk >> >> ? >> >> Maybe it's my turn to bang my head on the desk. > > Let me steal^W borrow an idea from Galileo, and present the explanation in > the form of a dialogue between two philosophers of computer science, > Salviati and Simplicio, and a third, intelligent layman, Sagredo. > > https://en.wikipedia.org/wiki/Dialogue_Concerning_the_Two_Chief_World_Systems > > > Salviati: Function defaults can also be used for static storage. > > Simplicio: If you want static storage, why not use static storage? > > Salviati: Function defaults in Python *are* static storage. > > Although they not the only way to get static storage, as closures can > also be used for that purpose, they are surely the simplest way to get > static storage in Python. > > Sagredo: Simplest though it might be, surely a reasonable person would > consider that using function parameters for static storage is abuse of the > feature and a global variable would be better? > > Salviati: Global variables have serious disadvantages. I will agree that > using function parameters for static storage is something of a code smell, > but good enough for rough and ready code. Nevertheless, it would be good if > Python had dedicated syntax for static storage. > > Simplicio: Ah-ha! Gotcha! > > Salviati: No, perhaps you missed that I was referring to a hypothetical > future addition to Python, not a current feature. But even if it did exist > today, your statement misses the point that by using function defaults I > *am* using static storage. In effect, you are telling me that rather than > using static storage I should instead use static storage. If you really want mutable static storage, you can simulate it more cleanly with a closure than using a default argument. def factory(): static_dict = {} def myfunc(a, b): mutate static_dict as much as you like return myfunc myfunc = factory() Or you can use a class of course. From antoon.pardon at rece.vub.ac.be Tue Nov 24 10:01:34 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 16:01:34 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: <56547BCE.3090502@rece.vub.ac.be> Op 24-11-15 om 15:34 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon > wrote: >>> Start thinking of it as a constructor call rather than a literal, and >>> you'll get past most of the confusion. >> >> That doesn't change the fact it does look like a literal and not like >> a constructor. > > Then explain how this is a literal: > > squares = [x*x for x in range(int(input("How far? ")))] > > Or even a simple example like this: > > coords = (randrange(10), randrange(10)) > > Neither of them is a literal, even though one of them isn't even > constructing a list. Tuples may be constant, but they still don't have > a literal form. (Constant folding can make them function the same way > literals do, though. If a tuple is constructed of nothing but > immutable constants - including an empty tuple - then CPython will > generally create a constant for the whole tuple and use that, rather > than manually constructing one every time. But the same is true of > other expressions involving nothing but constants.) > > So if it (in your opinion) looks like a literal but isn't one, whose > fault is it? Yours or the language's? Not a rhetorical question. > > ChrisA > From antoon.pardon at rece.vub.ac.be Tue Nov 24 10:03:47 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 16:03:47 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: <56547C53.8030407@rece.vub.ac.be> Op 24-11-15 om 15:34 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon > wrote: >>> Start thinking of it as a constructor call rather than a literal, and >>> you'll get past most of the confusion. >> >> That doesn't change the fact it does look like a literal and not like >> a constructor. > > Then explain how this is a literal: > > squares = [x*x for x in range(int(input("How far? ")))] So are you saying () isn't a literal because (x * x for x in range(int(input("How far? ")))) isn't a literal? -- Antoon. From antoon.pardon at rece.vub.ac.be Tue Nov 24 10:10:27 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 16:10:27 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> Message-ID: <56547DE3.1040009@rece.vub.ac.be> Op 24-11-15 om 15:18 schreef Ned Batchelder: > 2) In Python, "value" means, what object does a name refer to, or what > object did an evaluation produce. I don't think this is correct because that would imply that objects don't change values (since the value would be the object). When a list is mutated, it's value has changed. That is how the word is generally used in python. -- Antoon. From antoon.pardon at rece.vub.ac.be Tue Nov 24 10:12:18 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 16:12:18 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: <56547E52.7040107@rece.vub.ac.be> Op 24-11-15 om 15:34 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon > wrote: >>> Start thinking of it as a constructor call rather than a literal, and >>> you'll get past most of the confusion. >> >> That doesn't change the fact it does look like a literal and not like >> a constructor. > > Then explain how this is a literal: > > squares = [x*x for x in range(int(input("How far? ")))] Are you arguing that () isn't a literal because the following is not a literal? squares = (x*x for x in range(int(input("How far? ")))) -- Antoon. From rosuav at gmail.com Tue Nov 24 10:17:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 02:17:14 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <56547C53.8030407@rece.vub.ac.be> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 2:03 AM, Antoon Pardon wrote: > Op 24-11-15 om 15:34 schreef Chris Angelico: >> On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon >> wrote: >>>> Start thinking of it as a constructor call rather than a literal, and >>>> you'll get past most of the confusion. >>> >>> That doesn't change the fact it does look like a literal and not like >>> a constructor. >> >> Then explain how this is a literal: >> >> squares = [x*x for x in range(int(input("How far? ")))] > > So are you saying > > () isn't a literal > > because > > (x * x for x in range(int(input("How far? ")))) isn't a literal? I'm pretty sure tuple/list/dict display predates comprehensions, and was already not a literal syntax. Steven, you know the history better than I do - confirm or deny? ChrisA From ned at nedbatchelder.com Tue Nov 24 10:27:37 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 24 Nov 2015 07:27:37 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> Message-ID: <3589d016-f9ba-4217-83ea-4041ac085230@googlegroups.com> On Tuesday, November 24, 2015 at 10:10:51 AM UTC-5, Antoon Pardon wrote: > Op 24-11-15 om 15:18 schreef Ned Batchelder: > > > 2) In Python, "value" means, what object does a name refer to, or what > > object did an evaluation produce. > > I don't think this is correct because that would imply that objects don't > change values (since the value would be the object). Sorry, I should have been more precise. Python documentation suffers from this two-meaning world also. There are places where "value" is used in this second sense, perhaps more places than you realize. I know when I wrote "Python Names and Values", I meant it in this second sense. When you think people's claims about values, or understanding of values are incorrect, take a moment to decipher which of these two meanings they are likely using, and see if it more sense. > When a list is mutated, it's value has changed. That is how the word is > generally used in python. I don't know about "generally." It's true that when a list is mutated, it is the same referent, but now has a different evalue. That's what it means to be mutable. It's also true that the Python docs, being written in English, will use the "evalue" sense of the word, mixed together with the "referent" sense of the word. And yes, this can be confusing. --Ned. From glicerinu at gmail.com Tue Nov 24 10:29:39 2015 From: glicerinu at gmail.com (Marc Aymerich) Date: Tue, 24 Nov 2015 16:29:39 +0100 Subject: Futex hang when running event loop on a separated thread Message-ID: Hi, I have to run the asyncio.loop on a separated thread because the main thread is running FUSE. Apparently fuse needs to run on the main thread because it uses signal(): .... File "/usr/local/lib/python3.4/dist-packages/fuse.py", line 390, in __init__ old_handler = signal(SIGINT, SIG_DFL) ValueError: signal only works in main thread Anyway, when I exit the program it appears that i run into a deadlock with the eventloop thread, strace is stuck with: .... futex(0x7f7ba0000c10, FUTEX_WAIT_PRIVATE, 0, NULL I've tried to stop the event loop from the main thread but the situation is exactly the same :( loop_container = {} handler = threading.Thread(target=run_loop, args=(loop_container,)) try: handler.start() FUSE(fs) finally: loop_container['loop'].stop() # handler.join() Any idea on how I can shutdown the hole thing? I have to manually kill the program each time :( -- Marc From israel at eraalaska.net Tue Nov 24 10:33:03 2015 From: israel at eraalaska.net (israel) Date: Tue, 24 Nov 2015 06:33:03 -0900 Subject: Bi-directional sub-process communication In-Reply-To: <20151124052905.GA41045@cskk.homeip.net> References: <20151124052512.GA51713@cskk.homeip.net> <20151124052905.GA41045@cskk.homeip.net> Message-ID: On 11/23/2015 20:29, Cameron Simpson wrote: > On 24Nov2015 16:25, Cameron Simpson wrote: >> Completely untested example code: >> >> class ReturnEvent: >> def __init__(self): >> self.event = Event() > > With, of course: > > def wait(self): > return self.event.wait() Of course :-) Ah, the Event() object comes from the threading module. That makes sense. This should work perfectly. Thanks so much for taking the time to help me out! --------- Israel Brewster > > Cheers, > Cameron Simpson > > Maintainer's Motto: If we can't fix it, it ain't broke. From glicerinu at gmail.com Tue Nov 24 10:46:15 2015 From: glicerinu at gmail.com (Marc Aymerich) Date: Tue, 24 Nov 2015 16:46:15 +0100 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 4:29 PM, Marc Aymerich wrote: > Hi, > > I have to run the asyncio.loop on a separated thread because the main > thread is running FUSE. Apparently fuse needs to run on the main > thread because it uses signal(): > > .... > File "/usr/local/lib/python3.4/dist-packages/fuse.py", line 390, in __init__ > old_handler = signal(SIGINT, SIG_DFL) > ValueError: signal only works in main thread > > > Anyway, when I exit the program it appears that i run into a deadlock > with the eventloop thread, strace is stuck with: > > .... > futex(0x7f7ba0000c10, FUTEX_WAIT_PRIVATE, 0, NULL > > > I've tried to stop the event loop from the main thread but the > situation is exactly the same :( > > loop_container = {} > handler = threading.Thread(target=run_loop, args=(loop_container,)) > try: > handler.start() > FUSE(fs) > finally: > loop_container['loop'].stop() > # handler.join() > > Any idea on how I can shutdown the hole thing? I have to manually kill > the program each time :( this can be reproduced with the following program: import asyncio import threading import time def run_loop(loop_container): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) coro = asyncio.start_server(lambda: 1, '0.0.0.0', 8888, loop=loop) server = loop.run_until_complete(coro) loop_container['loop'] = loop loop.run_forever() if __name__ == '__main__': loop_container = {} handler = threading.Thread(target=run_loop, args=(loop_container, )) handler.start() try: time.sleep(10000) finally: loop_container['loop'].stop() glic3 at XPS13:/tmp$ python3 /tmp/eventtest.py ^CTraceback (most recent call last): File "/tmp/eventtest.py", line 22, in time.sleep(10000) KeyboardInterrupt ^CException ignored in: Traceback (most recent call last): File "/usr/lib/python3.4/threading.py", line 1294, in _shutdown t.join() File "/usr/lib/python3.4/threading.py", line 1060, in join self._wait_for_tstate_lock() File "/usr/lib/python3.4/threading.py", line 1076, in _wait_for_tstate_lock elif lock.acquire(block, timeout): KeyboardInterrupt it is waiting for tstate_lock in the second ^C -- Marc From antoon.pardon at rece.vub.ac.be Tue Nov 24 10:46:22 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 16:46:22 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> Message-ID: <5654864E.2070906@rece.vub.ac.be> Op 24-11-15 om 16:17 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 2:03 AM, Antoon Pardon > wrote: >> Op 24-11-15 om 15:34 schreef Chris Angelico: >>> On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon >>> wrote: >>>>> Start thinking of it as a constructor call rather than a literal, and >>>>> you'll get past most of the confusion. >>>> >>>> That doesn't change the fact it does look like a literal and not like >>>> a constructor. >>> >>> Then explain how this is a literal: >>> >>> squares = [x*x for x in range(int(input("How far? ")))] >> >> So are you saying >> >> () isn't a literal >> >> because >> >> (x * x for x in range(int(input("How far? ")))) isn't a literal? > > I'm pretty sure tuple/list/dict display predates comprehensions, and > was already not a literal syntax. Steven, you know the history better > than I do - confirm or deny? What is your point? I say that [] looks like a literal. Because it sure resembles () which is a literal. That [] in fact isn't a literal doesn't contradict it looks like one. That you can come up with more complicated list expressions that are more easily recognizable as not being literals is beside the point because we have generator expressions that look similar to those list comprehensions and those generator expressions don't contradict that () is a literal. -- Antoon. From rosuav at gmail.com Tue Nov 24 10:48:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 02:48:32 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <5654864E.2070906@rece.vub.ac.be> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 2:46 AM, Antoon Pardon wrote: > What is your point? I say that [] looks like a literal. Because it > sure resembles () which is a literal. > > That [] in fact isn't a literal doesn't contradict it looks like > one. > > That you can come up with more complicated list expressions that > are more easily recognizable as not being literals is beside the > point because we have generator expressions that look similar to > those list comprehensions and those generator expressions don't > contradict that () is a literal. () is not a literal either. ChrisA From steve at pearwood.info Tue Nov 24 11:11:28 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 03:11:28 +1100 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> Message-ID: <56548c31$0$1596$c3e8da3$5496439d@news.astraweb.com> On Tue, 24 Nov 2015 11:57 pm, Marko Rauhamaa wrote: > Antoon Pardon : > >> You then switching to talking about objects, just gives the impression >> that object is a synonym for value. > > It isn't? No it isn't. The definition of "object" -- well, I say "the" definition, but the nasty truth is that there are many different definitions and nobody really agrees on what an object is -- the definition of "object" is a software entity with three fundamental attributes or qualities: - the type of object; - the value of the object; - the identity of the object. If we limit ourselves to Python, that definition works because Python has been designed to work that way. Other languages may be different, but when it comes to Python, it is true by definition that all objects have a type, a value and an identity because that's what Guido did. The type of the object is the class that it is an instance of: py> type("hello") The identity of the object is represented by the integer ID returned by the id() function. But what it represents is the distinct existence of one object as compared to another. In real life, the identity of *this* sheep versus *that* sheep, or this instance of a book versus that instance of the same book. (Aside: those of a philosophical bent will quickly realise that we don't really understand what identity *is*. See, for example, the paradox of my gradfather's axe. And what distinguishes this electron from some other electron? There's even a theory in physics that *all electrons are in fact the one electron*, bouncing backwards and forwards in time repeatedly.) The value of the object depends on its type -- the value of ints differ from the value of strings, for example. Immutable objects have a fixed value for their entire lifespan: the object 2 has the same numeric value, namely two, from the moment it is instantiated to the moment it is garbage collected. Mutable objects do not have such a fixed value: py> L = [] # value is the empty list py> L.append(None) # value is now a singleton list containing None py> L[:] = 'cat dog fox'.split() # value is now a list containing strings cat, dog, fox. py> L ['cat', 'dog', 'fox'] It's the same list, the same object, but the value changes. -- Steven From random832 at fastmail.com Tue Nov 24 11:28:58 2015 From: random832 at fastmail.com (Random832) Date: Tue, 24 Nov 2015 16:28:58 +0000 (UTC) Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: On 2015-11-24, Chris Angelico wrote: > On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon > wrote: >>> Start thinking of it as a constructor call rather than a literal, and >>> you'll get past most of the confusion. >> >> That doesn't change the fact it does look like a literal and not like >> a constructor. > > Neither of them is a literal, even though one of them isn't even > constructing a list. Tuples may be constant, but they still don't have > a literal form. How do you define "literal form"? I define it as any syntax that can participate in ast.literal_eval (And I consider [...] to be a literal form regardless of whether the ... values are literals or not). I don't think "Start thinking of it as a constructor call rather than a literal" is helpful, since it just hides one's confusion about what a literal is. The Python documentation itself seems to assume that "literal" should only be used for things that are a single token, though I have no idea where this thinking comes from. From rosuav at gmail.com Tue Nov 24 11:38:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 03:38:05 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 3:28 AM, Random832 wrote: > On 2015-11-24, Chris Angelico wrote: >> On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon >> wrote: >>>> Start thinking of it as a constructor call rather than a literal, and >>>> you'll get past most of the confusion. >>> >>> That doesn't change the fact it does look like a literal and not like >>> a constructor. >> >> Neither of them is a literal, even though one of them isn't even >> constructing a list. Tuples may be constant, but they still don't have >> a literal form. > > How do you define "literal form"? I define it as any syntax that > can participate in ast.literal_eval (And I consider [...] to be a > literal form regardless of whether the ... values are literals or > not). I don't think "Start thinking of it as a constructor call > rather than a literal" is helpful, since it just hides one's > confusion about what a literal is. https://docs.python.org/3/reference/lexical_analysis.html#literals ast.literal_eval can handle a number of things which are not literals, as long as they use nothing but literals combined by a restricted set of operators. For instance, Python has no complex literals, only imaginary ones - but: >>> ast.literal_eval("1+2j") (1+2j) And Python certainly doesn't have "expression literals", yet: >>> ast.literal_eval("[1,1+1,3]") [1, 2, 3] Its support for list display equally doesn't make that into a literal. > The Python documentation itself seems to assume that "literal" > should only be used for things that are a single token, though I > have no idea where this thinking comes from. Probably the grammar. In other words, it's part of the language's very definition. ChrisA From george.trojan at noaa.gov Tue Nov 24 11:40:23 2015 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 24 Nov 2015 16:40:23 +0000 Subject: tuples in conditional assignment (Ben Finney) In-Reply-To: References: Message-ID: <565492F7.5050408@noaa.gov> Ben Finney writes: > Ben Finney > Date: > 11/24/2015 04:49 AM > > To: > python-list at python.org > > > George Trojan writes: > >> The following code has bitten me recently: >> >>>>> t=(0,1) >>>>> x,y=t if t else 8, 9 >>>>> print(x, y) >> (0, 1) 9 > You can simplify this by taking assignment out of the picture:: > > >>> t = (0, 1) > >>> t if t else 8, 9 > ((0, 1), 9) > > So that's an ?expression list? containing a comma. The reference for > expressions tells us:: > > An expression list containing at least one comma yields a tuple. The > length of the tuple is the number of expressions in the list. > > > >> I was assuming that a comma has the highest order of evaluation > You were? The operator precedence rules don't even mention comma as an > operator, so why would you assume that? > > What threw me off was the right column in the table stating that binding or tuple display has the highest precedence. Somewhere else there is a statement that a comma makes a tuple, not the parentheses, so the parentheses on the left did not register with me. > >> that is the expression 8, 9 should make a tuple. Why this is not the >> case? > I'm not sure why it's the case that you assumed that > > My practical advice: I don't bother trying to remember the complete > operator precedence rules. My simplified precedence rules are: > > * ?+?, ?-? have the same precedence. > * ?*?, ?/?, ?//? have the same precedence. > * For anything else: Use parentheses to explicitly declare the > precedence I want. > > Related: When an expression has enough clauses that it's not *completely > obvious* what's going on, break it up by assigning some sub-parts to > temporary well-chosen descriptive names (not ?t?). t was just to illustrate my problem, not the actual code. My lesson is to use parentheses in all cases, maybe with an exception for an obvious y, x = x, y. In my new C code I always write if (a) { f(); } instead of a valid 2-liner if (a) f(); Too many times I added indented g() call, and since I do more Python than C, the error was not glaringly obvious. > > -- \ ?It is far better to grasp the universe as it really is than to | > `\ persist in delusion, however satisfying and reassuring.? ?Carl | > _o__) Sagan | Ben Finney George From antoon.pardon at rece.vub.ac.be Tue Nov 24 11:41:08 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 17:41:08 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> Message-ID: <56549324.8020607@rece.vub.ac.be> Op 24-11-15 om 16:48 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 2:46 AM, Antoon Pardon > wrote: >> What is your point? I say that [] looks like a literal. Because it >> sure resembles () which is a literal. >> >> That [] in fact isn't a literal doesn't contradict it looks like >> one. >> >> That you can come up with more complicated list expressions that >> are more easily recognizable as not being literals is beside the >> point because we have generator expressions that look similar to >> those list comprehensions and those generator expressions don't >> contradict that () is a literal. > > () is not a literal either. The byte code sure suggests it is. Take the following code: import dis def f(): i = 42 t = () l = [] dis.dis(f) That produces the following: 4 0 LOAD_CONST 1 (42) 3 STORE_FAST 0 (i) 5 6 LOAD_CONST 2 (()) 9 STORE_FAST 1 (t) 6 12 BUILD_LIST 0 15 STORE_FAST 2 (l) 18 LOAD_CONST 0 (None) 21 RETURN_VALUE So on what grounds would you argue that () is not a literal. -- Antoon. From glicerinu at gmail.com Tue Nov 24 11:43:59 2015 From: glicerinu at gmail.com (Marc Aymerich) Date: Tue, 24 Nov 2015 17:43:59 +0100 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: threading supports the 'daemon' option[1], when set to True and the program is in *foreground* then the event-loop thread dies when SIGTERM-ed, however, if the program is in the *background* it doesn't work! still deadlocked :'''( while I'm not finding a definitive solution I'll be doing a os.kill(os.getpid(), signal.SIGKILL) inside the finally block. [1] https://docs.python.org/3.5/library/threading.html#threading.Thread.daemon On Tue, Nov 24, 2015 at 4:46 PM, Marc Aymerich wrote: > On Tue, Nov 24, 2015 at 4:29 PM, Marc Aymerich wrote: >> Hi, >> >> I have to run the asyncio.loop on a separated thread because the main >> thread is running FUSE. Apparently fuse needs to run on the main >> thread because it uses signal(): >> >> .... >> File "/usr/local/lib/python3.4/dist-packages/fuse.py", line 390, in __init__ >> old_handler = signal(SIGINT, SIG_DFL) >> ValueError: signal only works in main thread >> >> >> Anyway, when I exit the program it appears that i run into a deadlock >> with the eventloop thread, strace is stuck with: >> >> .... >> futex(0x7f7ba0000c10, FUTEX_WAIT_PRIVATE, 0, NULL >> >> >> I've tried to stop the event loop from the main thread but the >> situation is exactly the same :( >> >> loop_container = {} >> handler = threading.Thread(target=run_loop, args=(loop_container,)) >> try: >> handler.start() >> FUSE(fs) >> finally: >> loop_container['loop'].stop() >> # handler.join() >> >> Any idea on how I can shutdown the hole thing? I have to manually kill >> the program each time :( > > > this can be reproduced with the following program: > > import asyncio > import threading > import time > > def run_loop(loop_container): > loop = asyncio.new_event_loop() > asyncio.set_event_loop(loop) > coro = asyncio.start_server(lambda: 1, '0.0.0.0', 8888, loop=loop) > server = loop.run_until_complete(coro) > loop_container['loop'] = loop > loop.run_forever() > > if __name__ == '__main__': > loop_container = {} > handler = threading.Thread(target=run_loop, args=(loop_container, )) > handler.start() > try: > time.sleep(10000) > finally: > loop_container['loop'].stop() > > > glic3 at XPS13:/tmp$ python3 /tmp/eventtest.py > ^CTraceback (most recent call last): > File "/tmp/eventtest.py", line 22, in > time.sleep(10000) > KeyboardInterrupt > ^CException ignored in: '/usr/lib/python3.4/threading.py'> > Traceback (most recent call last): > File "/usr/lib/python3.4/threading.py", line 1294, in _shutdown > t.join() > File "/usr/lib/python3.4/threading.py", line 1060, in join > self._wait_for_tstate_lock() > File "/usr/lib/python3.4/threading.py", line 1076, in _wait_for_tstate_lock > elif lock.acquire(block, timeout): > KeyboardInterrupt > > it is waiting for tstate_lock in the second ^C > > -- > Marc -- Marc From ian.g.kelly at gmail.com Tue Nov 24 11:56:02 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 24 Nov 2015 09:56:02 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <56549324.8020607@rece.vub.ac.be> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> Message-ID: On Tue, Nov 24, 2015 at 9:41 AM, Antoon Pardon wrote: > Op 24-11-15 om 16:48 schreef Chris Angelico: >> () is not a literal either. > > The byte code sure suggests it is. > > Take the following code: > > import dis > > def f(): > i = 42 > t = () > l = [] > > dis.dis(f) > > That produces the following: > > > 4 0 LOAD_CONST 1 (42) > 3 STORE_FAST 0 (i) > > 5 6 LOAD_CONST 2 (()) > 9 STORE_FAST 1 (t) > > 6 12 BUILD_LIST 0 > 15 STORE_FAST 2 (l) > 18 LOAD_CONST 0 (None) > 21 RETURN_VALUE I'm not sure what this is meant to prove. None is clearly an identifier, not a literal, and it also gets treated as a constant in the code above. > So on what grounds would you argue that () is not a literal. This enumerates exactly what literals are in Python: https://docs.python.org/3/reference/lexical_analysis.html#literals I think it's a rather pedantic point, though. How are nuances of the grammar at all related to user expectations? From ned at nedbatchelder.com Tue Nov 24 11:59:21 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 24 Nov 2015 08:59:21 -0800 (PST) Subject: Returning a result from 3 items in a list In-Reply-To: References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> Message-ID: <1900b12c-eb55-4fc5-a45f-b134bf8d36db@googlegroups.com> On Tuesday, November 24, 2015 at 9:29:30 AM UTC-5, Mark Lawrence wrote: > On 24/11/2015 14:07, Denis McMahon wrote: > > On Tue, 24 Nov 2015 02:04:56 -0800, Cai Gengyang wrote: > > > >> Here's a dictionary with 3 values : > >> > >> results = { > >> "gengyang": 14, > >> "ensheng": 13, "jordan": 12 > >> } > >> > >> How do I define a function that takes the last of the 3 items in that > >> list and returns Jordan's results i.e. (12) ? > > > > You open a web browser and google for "python dictionary" > > > > Ooh steady on old chap, surely you should have fitted the bib, done the > spoon feeding and then changed the nappy? That appears to me the > preferred way of doing things nowadays on c.l.py, rather than bluntly > telling people not to be so bloody lazy. Mark and Denis, if you are having a hard time with newcomers to this list, perhaps you need to find another list to read? Yes, Cai Gengyang could do more research before asking questions. But your response does nothing to improve the situation. It's just snark and bile, and does not exemplify the Python community's culture. > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. What you can do for our language is put a better foot forward. --Ned. From oscar.j.benjamin at gmail.com Tue Nov 24 12:25:05 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 24 Nov 2015 17:25:05 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <3589d016-f9ba-4217-83ea-4041ac085230@googlegroups.com> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <3589d016-f9ba-4217-83ea-4041ac085230@googlegroups.com> Message-ID: On 24 November 2015 at 15:27, Ned Batchelder wrote: > On Tuesday, November 24, 2015 at 10:10:51 AM UTC-5, Antoon Pardon wrote: >> Op 24-11-15 om 15:18 schreef Ned Batchelder: >> >> > 2) In Python, "value" means, what object does a name refer to, or what >> > object did an evaluation produce. >> >> I don't think this is correct because that would imply that objects don't >> change values (since the value would be the object). > > Sorry, I should have been more precise. Python documentation suffers from > this two-meaning world also. There are places where "value" is used in > this second sense, perhaps more places than you realize. I know when I > wrote "Python Names and Values", I meant it in this second sense. Hi Ned, I read your talk on this subject which was linked to further up in the thread and it is excellent so thanks for that. I forwarded it to a colleague for inspiration in our own introductory programming (with Python) teaching unit. However when I read it and imagined explaining it to our students I found myself wanting to adjust the terminology. I would not use the word value in the way that you suggest. Rather I would want to contrast "names" (or "references"), "objects" and "values". I think that many things can be expressed more cleanly with these terms and I think it corresponds more to the way in which I see Python programmers use these terms. So I would say that an object has a value. Immutable objects have unchanging values but the value of mutable objects can change. The expression "a is b" determines whether or not a and b are bound to the same object whereas "a == b" determines if the objects bound to a and b have the same value. To copy an object is to create a new object having the same value as the copied object. To mutate an object is to change its value etc. Earlier in this thread you said: """ In Python, a default value expression for a function argument is evaluated only once, when the function is defined. That value (in this case, the actual list) is stored with the function. The expression is not stored, the value of the expression is. That value (the actual list) is supplied as the value of the argument if no other value is supplied. If you modify that value in the function, the value is modified, and used again at the next function call. """ I think that's a good example of where it would be clearer to distinguish between objects and values, rather than using the word value for both. In particular what is stored with the function is the *object* that results from the default value expression. The *value* of that object may change if it is mutated but it will still be the same object each time the function is called (without a corresponding argument being passed). -- Oscar From steve at pearwood.info Tue Nov 24 12:29:52 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 04:29:52 +1100 Subject: What is a function parameter =[] for? References: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56549e92$0$1604$c3e8da3$5496439d@news.astraweb.com> On Tue, 24 Nov 2015 11:38 pm, Antoon Pardon wrote: > Op 19-11-15 om 13:45 schreef Steven D'Aprano: [...] >> I don't mean that it isn't sometimes useful. Of course it is sometimes >> useful, there's no doubt about that. But why would you expect the >> language to default to the *slow*, *expensive*, *complicated* behaviour >> instead of the *fast*, *cheap*, *simple* behaviour? > > I would say because it is better understandable. I disagree that it (late-binding) is more understandable. Late-binding (or, "late evaluation" for those who prefer that term) is no easier to understand than early binding. Earlier, I publicly screwed up reasoning about late binding. And so did BartC, whose personal language has precisely the late binding semantics he wants, exactly as he designed it, and yet he was surprised by its behaviour leading him to (wrongly) conclude that his language was more dynamic than Python: Quote: "(Python returns 42; so that means my languages are more dynamic than Python? That's hard to believe!)" See this thread, post from BartC dated Fri, 20 Nov 2015 08:21:24 am. > The way default value > behave now, is just a little less surprising as when the following segment > of code would print: [1] > > a = [] > a.append(1) > b = [] > print b No, it really isn't anything like that at all. If you (generic you, not specifically you personally) think that it is similar, you've misunderstood what is going on. If we want an analogy, this is a good one: alist = [] for i in range(20): alist.append(i) print alist Are you surprised that alist keeps growing? Contrast this to: for i in range(20): alist = [] alist.append(i) print alist Are you surprised that alist keeps getting re-set to the empty list? Change the for-loop to a function declaration. If the binding of the list [] happens inside the indented block, it will happen every time the function is called (just as it happens each time through the loop in the second example above). If the binding happens outside of the body, it happens once, not every time. Folk like BartC want the function default to be re-evaluated every time the function is called. I'm not blind to the usefulness of it: I write lots of functions with late-binding semantics too. I just write them like this: def func(a=None): if a is None: a = something() Perhaps as more people start using function annotations, it will become more obvious that function declarations aren't re-evaluated every single time you call the function: def func(a:some_expression=another_expression): ... *Both* expressions, the annotation and the default, are evaluated once and once only. > Let us not forget that the tutorial talks about Default Argument *Values*. > And also the language reference talks about precomputed *values*. What > we really get is a precomputed object. There is a distinction between value and object, but without seeing the exact wording and context of the tutorial and language reference, I cannot tell whether they are misleading or not. There's nothing wrong with talking about default values. You just have to remember that some values can change. >> You already have one way to set the argument to a fresh list every time >> you call the function: put the code you want executed inside the body of >> the function. There's no need for a *second* way to get the same result. > > Which is beside the point. The point is understandability. Okay. Suppose for the sake of the argument I agree with you that "understandability" is the most important factor here. Then early binding is still the clear winner, because it has simple, easy to understand semantics: - the "def" line is executed once, and once only, including all parameter defaults and annotations; - the *body* of the function is executed when the function is called, not the "def" function declaration. Since the function defaults are part of the declaration, not the body, it is far more understandable that it is executed once only. >> But if you want the default value to be evaluated exactly once, and once >> only, there is no real alternative to early binding. You could use a >> global variable, of course, but that is no solution -- that's a problem >> waiting to happen. > > No more than the situation we have now. The situation we have now is a > problem waiting to happen too. Which is confirmed again and again. You are > stacking the deck by calling a possible alternative "a problem waiting to > happen" while ignoring the problems that happen with the current > situation. Pardon me, I certainly am not ignoring anything of the sort. I do acknowledge that the behaviour of mutable defaults can be surprising. I even admitted that it surprised me. It's often not the behaviour that you want, so you have to do something slightly different. The bottom line is that there are good reasons for the way Python works with function defaults, but they aren't good for everything. Neither is the alternative. Whichever design Python used, it would inconvenience people at some time or another. -- Steven From antoon.pardon at rece.vub.ac.be Tue Nov 24 12:32:05 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 18:32:05 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> Message-ID: <56549F15.40206@rece.vub.ac.be> Op 24-11-15 om 17:56 schreef Ian Kelly: > >> So on what grounds would you argue that () is not a literal. > > This enumerates exactly what literals are in Python: > > https://docs.python.org/3/reference/lexical_analysis.html#literals > > I think it's a rather pedantic point, though. How are nuances of the > grammar at all related to user expectations? > I think that enumaration is too limited. The section starts with: Literals are notations for constant values of some built-in types. () satisfies that definition, which is confirmed by the byte code produced for it. -- Antoon. From ned at nedbatchelder.com Tue Nov 24 12:35:48 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 24 Nov 2015 09:35:48 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <3589d016-f9ba-4217-83ea-4041ac085230@googlegroups.com> Message-ID: <51dc19ec-9ea0-4b37-bd66-6ebdacc83d87@googlegroups.com> On Tuesday, November 24, 2015 at 12:25:54 PM UTC-5, Oscar Benjamin wrote: > On 24 November 2015 at 15:27, Ned Batchelder wrote: > > On Tuesday, November 24, 2015 at 10:10:51 AM UTC-5, Antoon Pardon wrote: > >> Op 24-11-15 om 15:18 schreef Ned Batchelder: > >> > >> > 2) In Python, "value" means, what object does a name refer to, or what > >> > object did an evaluation produce. > >> > >> I don't think this is correct because that would imply that objects don't > >> change values (since the value would be the object). > > > > Sorry, I should have been more precise. Python documentation suffers from > > this two-meaning world also. There are places where "value" is used in > > this second sense, perhaps more places than you realize. I know when I > > wrote "Python Names and Values", I meant it in this second sense. > > Hi Ned, I read your talk on this subject which was linked to further > up in the thread and it is excellent so thanks for that. I forwarded > it to a colleague for inspiration in our own introductory programming > (with Python) teaching unit. > > However when I read it and imagined explaining it to our students I > found myself wanting to adjust the terminology. I would not use the > word value in the way that you suggest. Rather I would want to > contrast "names" (or "references"), "objects" and "values". I think > that many things can be expressed more cleanly with these terms and I > think it corresponds more to the way in which I see Python programmers > use these terms. > > So I would say that an object has a value. Immutable objects have > unchanging values but the value of mutable objects can change. The > expression "a is b" determines whether or not a and b are bound to the > same object whereas "a == b" determines if the objects bound to a and > b have the same value. To copy an object is to create a new object > having the same value as the copied object. To mutate an object is to > change its value etc. > > Earlier in this thread you said: > """ > In Python, a default value expression > for a function argument is evaluated only once, when the function is defined. > That value (in this case, the actual list) is stored with the function. The > expression is not stored, the value of the expression is. That value (the > actual list) is supplied as the value of the argument if no other value is > supplied. If you modify that value in the function, the value is modified, > and used again at the next function call. > """ > I think that's a good example of where it would be clearer to > distinguish between objects and values, rather than using the word > value for both. In particular what is stored with the function is the > *object* that results from the default value expression. The *value* > of that object may change if it is mutated but it will still be the > same object each time the function is called (without a corresponding > argument being passed). > > -- > Oscar Oscar, thanks for the thoughtful comments. I agree that using "object" for the result of an expression, and for the referent of a name, would go some ways to clarifying things. Perhaps the Python world uses "value" less to mean "object" than I am thinking. But we do talk about "the value of an expression", and "what value does X have," and so on. --Ned. From tjreedy at udel.edu Tue Nov 24 12:46:36 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Nov 2015 12:46:36 -0500 Subject: What is a function parameter =[] for? In-Reply-To: <56547567.2090603@rece.vub.ac.be> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <56547567.2090603@rece.vub.ac.be> Message-ID: On 11/24/2015 9:34 AM, Antoon Pardon wrote: I agree that the tutorial should talk about default argument objects (which have values) instead of conflating 'object' with 'value'. > Op 20-11-15 om 13:12 schreef Ned Batchelder: >> I'm not sure what your goal is at this point. Are you: >> >> 1) still unsure what the behavior is, or >> 2) trying to understand why it behaves that way, or >> 3) hoping to change Python, or >> 4) trying to convince us that your language is better, or >> 5) something else? > > Maybe just have us recognize that some aspects of python indeed are bizarre. The current behavior under discussion is: default argument expressions are evaluated once at function creation time to produce default argument objects that are bound to the function object. I do not see this as bizarre. > That there is nothing wrong with him thinking so. I do recognize that some would prefer that default argument expressions be treated differently, that def f(a=expression): pass be compiled to operate as the following does now def f(a=None): a = a if a is not None else expression perhaps with None replaced with a hidden object() instance. I find the continuing fuss over the choice that was made to be the bizarre thing here. -- Terry Jan Reedy From gordon at panix.com Tue Nov 24 12:47:17 2015 From: gordon at panix.com (John Gordon) Date: Tue, 24 Nov 2015 17:47:17 +0000 (UTC) Subject: Finding scores from a list References: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> Message-ID: In <277843f7-c898-4378-85ea-841b09a289e3 at googlegroups.com> Cai Gengyang writes: > results = [ > {"id": 1, "name": "ensheng", "score": 10}, > {"id": 2, "name": "gengyang", "score": 12}, > {"id": 3, "name": "jordan", "score": 5}, > ] Okay, this is a list. > I want to find gengyang's score. This is what I tried : > >>> print((results["gengyang"])["score"]) > but I got an error message instead : > Traceback (most recent call last): > File "", line 1, in > print((results["gengyang"])["score"]) > TypeError: list indices must be integers, not str Lists are indexed by number, not by name. You want something like this: for result in results: if result["name"] == "gengyang": print result["score"] break -- 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 ian.g.kelly at gmail.com Tue Nov 24 12:53:44 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 24 Nov 2015 10:53:44 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <56549F15.40206@rece.vub.ac.be> References: <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> Message-ID: On Tue, Nov 24, 2015 at 10:32 AM, Antoon Pardon wrote: > Op 24-11-15 om 17:56 schreef Ian Kelly: > >> >>> So on what grounds would you argue that () is not a literal. >> >> This enumerates exactly what literals are in Python: >> >> https://docs.python.org/3/reference/lexical_analysis.html#literals >> >> I think it's a rather pedantic point, though. How are nuances of the >> grammar at all related to user expectations? >> > > I think that enumaration is too limited. The section starts with: > > Literals are notations for constant values of some built-in types. > > () satisfies that definition, which is confirmed by the byte code > produced for it. Literals are a type of lexical token. All of the literals shown in that section are, indeed, tokens. Now I would point you to the grammar specification: https://docs.python.org/3/reference/grammar.html And specifically the "atom" rule, which defines both list displays and list comprehensions (as well as literals) as being atoms. Specifically, it parses () as the token '(', followed by an optional yield_expr or testlist_comp, followed by the token ')'. In no way is that a single token, nor therefore a literal. From steve at pearwood.info Tue Nov 24 12:54:03 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 04:54:03 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> Message-ID: <5654a43d$0$1622$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 02:17 am, Chris Angelico wrote: > On Wed, Nov 25, 2015 at 2:03 AM, Antoon Pardon > wrote: >> So are you saying >> >> () isn't a literal >> >> because >> >> (x * x for x in range(int(input("How far? ")))) isn't a literal? > > I'm pretty sure tuple/list/dict display predates comprehensions, and > was already not a literal syntax. Steven, you know the history better > than I do - confirm or deny? I must admit that I'm often guilty of referring to [a, b, c] as a list literal, but, no, () and related forms aren't literals[1], and yes, tuple/list/dict displays predates list comprehensions by a long time. Here's Python 1.5: Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import dis >>> code = compile("(1, 2, 3)", "", "eval") >>> dis.dis(code) 0 SET_LINENO 0 3 LOAD_CONST 0 (1) 6 LOAD_CONST 1 (2) 9 LOAD_CONST 2 (3) 12 BUILD_TUPLE 3 15 RETURN_VALUE So you can see the tuple actually gets assembled at runtime. Even if the tuple is empty, the same process occurs: >>> code = compile("()", "", "eval") >>> dis.dis(code) 0 SET_LINENO 0 3 BUILD_TUPLE 0 6 RETURN_VALUE In contrast, using an actual literal (even a big one) loads the literal as a pre-existing constant: >>> code = compile("42000009999999999L", "", "eval") >>> dis.dis(code) 0 SET_LINENO 0 3 LOAD_CONST 0 (42000009999999999L) 6 RETURN_VALUE [1] Although with recent versions of Python, the peephole optimizer is clever enough to treat tuples consisting of nothing but literals as if it were itself a literal. E.g. in Python 3.3: py> import dis py> code = compile("(1, 2, 3)", "", "eval") py> dis.dis(code) 1 0 LOAD_CONST 3 ((1, 2, 3)) 3 RETURN_VALUE But that is a recent optimization, and it relies on the facts that tuples are immutable, and that the items within the tuple are themselves immutable literals: py> code = compile("(1, 2, [])", "", "eval") py> dis.dis(code) 1 0 LOAD_CONST 0 (1) 3 LOAD_CONST 1 (2) 6 BUILD_LIST 0 9 BUILD_TUPLE 3 12 RETURN_VALUE -- Steven From steve at pearwood.info Tue Nov 24 12:56:17 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 04:56:17 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652c4ac$0$1621$c3e8da3$5496439d@news.astraweb.com> <56531ba1$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5654a4c3$0$1622$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 01:58 am, Antoon Pardon wrote: > Op 23-11-15 om 14:58 schreef Steven D'Aprano: > > ... closures can also be used for [static storage] ... > If you really want mutable static storage, you can simulate it more > cleanly with a closure than using a default argument. You don't say. Thanks for letting me know what I already pointed out in the very post you responded to. It's always nice to see that people read my words with care and attention to detail. -- Steven From ian.g.kelly at gmail.com Tue Nov 24 13:04:05 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 24 Nov 2015 11:04:05 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> Message-ID: On Tue, Nov 24, 2015 at 10:53 AM, Ian Kelly wrote: > On Tue, Nov 24, 2015 at 10:32 AM, Antoon Pardon > wrote: >> Op 24-11-15 om 17:56 schreef Ian Kelly: >> >>> >>>> So on what grounds would you argue that () is not a literal. >>> >>> This enumerates exactly what literals are in Python: >>> >>> https://docs.python.org/3/reference/lexical_analysis.html#literals >>> >>> I think it's a rather pedantic point, though. How are nuances of the >>> grammar at all related to user expectations? >>> >> >> I think that enumaration is too limited. The section starts with: >> >> Literals are notations for constant values of some built-in types. >> >> () satisfies that definition, which is confirmed by the byte code >> produced for it. > > Literals are a type of lexical token. All of the literals shown in > that section are, indeed, tokens. Now I would point you to the grammar > specification: > > https://docs.python.org/3/reference/grammar.html > > And specifically the "atom" rule, which defines both list displays and > list comprehensions (as well as literals) as being atoms. > Specifically, it parses () as the token '(', followed by an optional > yield_expr or testlist_comp, followed by the token ')'. In no way is > that a single token, nor therefore a literal. In case reading the grammar doesn't convince, we can also get this result from playing with the language: >>> import tokenize >>> from io import StringIO >>> list(tokenize.generate_tokens(StringIO('()').readline)) [TokenInfo(type=52 (OP), string='(', start=(1, 0), end=(1, 1), line='()'), TokenInfo(type=52 (OP), string=')', start=(1, 1), end=(1, 2), line='()'), TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')] Two separate tokens of the OP type. >>> list(tokenize.generate_tokens(StringIO('42').readline)) [TokenInfo(type=2 (NUMBER), string='42', start=(1, 0), end=(1, 2), line='42'), TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')] One token, of a literal type. >>> list(tokenize.generate_tokens(StringIO('(1,2,3)').readline)) [TokenInfo(type=52 (OP), string='(', start=(1, 0), end=(1, 1), line='(1,2,3)'), TokenInfo(type=2 (NUMBER), string='1', start=(1, 1), end=(1, 2), line='(1,2,3)'), TokenInfo(type=52 (OP), string=',', start=(1, 2), end=(1, 3), line='(1,2,3)'), TokenInfo(type=2 (NUMBER), string='2', start=(1, 3), end=(1, 4), line='(1,2,3)'), TokenInfo(type=52 (OP), string=',', start=(1, 4), end=(1, 5), line='(1,2,3)'), TokenInfo(type=2 (NUMBER), string='3', start=(1, 5), end=(1, 6), line='(1,2,3)'), TokenInfo(type=52 (OP), string=')', start=(1, 6), end=(1, 7), line='(1,2,3)'), TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')] Two tokens for the parentheses, plus three literal tokens for the ints, plus two more tokens for the separating commas. Definitely not a literal. Credit to Steven for using this approach to make a similar point about literals in a previous thread. From zachary.ware+pylist at gmail.com Tue Nov 24 13:11:10 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 24 Nov 2015 12:11:10 -0600 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 9:46 AM, Marc Aymerich wrote: > if __name__ == '__main__': > loop_container = {} > handler = threading.Thread(target=run_loop, args=(loop_container, )) > handler.start() > try: > time.sleep(10000) > finally: > loop_container['loop'].stop() loop.stop() must be called from the thread running the loop. You can do this by doing `loop_container['loop'].call_soon_threadsafe(loop_container['loop'].stop)` from the main thread (untested). Hope this helps, -- Zach From marko at pacujo.net Tue Nov 24 13:13:22 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 24 Nov 2015 20:13:22 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <3589d016-f9ba-4217-83ea-4041ac085230@googlegroups.com> <51dc19ec-9ea0-4b37-bd66-6ebdacc83d87@googlegroups.com> Message-ID: <877fl78dvh.fsf@elektro.pacujo.net> Ned Batchelder : > Oscar, thanks for the thoughtful comments. I agree that using "object" > for the result of an expression, and for the referent of a name, would > go some ways to clarifying things. > > Perhaps the Python world uses "value" less to mean "object" than I am > thinking. But we do talk about "the value of an expression", and "what > value does X have," and so on. There are all kinds of uses (Google: python "value of"): "How to get the value of a variable given its name in a string" "The value of some objects can change. Objects whose value can change are said to be mutable" "I'm taking the return value of one function and using it as the argument of another function" "Don't get confused ? name on the left, value on the right" "We can print the current value of the dictionary in the usual way" "A return statement ends the execution of the function call and "returns" the result, i.e. the value of the expression following the return keyword, to the caller" "When we ask python what the value of x > 5 is, we get False" "To display the value of a variable, you can use a print statement" "Get a value of a specified key" Personally, I don't like the "official" Python usage: Objects whose value can change are said to be mutable I would prefer this wording: Objects whose inner state can change are said to be mutable Marko From antoon.pardon at rece.vub.ac.be Tue Nov 24 13:27:16 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 19:27:16 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <56547567.2090603@rece.vub.ac.be> Message-ID: <5654AC04.1050501@rece.vub.ac.be> Op 24-11-15 om 18:46 schreef Terry Reedy: > On 11/24/2015 9:34 AM, Antoon Pardon wrote: > > I agree that the tutorial should talk about default argument objects (which have values) instead of conflating 'object' with 'value'. > >> Op 20-11-15 om 13:12 schreef Ned Batchelder: > >>> I'm not sure what your goal is at this point. Are you: >>> >>> 1) still unsure what the behavior is, or >>> 2) trying to understand why it behaves that way, or >>> 3) hoping to change Python, or >>> 4) trying to convince us that your language is better, or >>> 5) something else? >> >> Maybe just have us recognize that some aspects of python indeed are bizarre. > > The current behavior under discussion is: default argument expressions are evaluated once at function creation > time to produce default argument objects that are bound to the function object. I do not see this as bizarre. I do. That a default can be mutated so that your default can have different values upon different calls is IMO bizarre. I understand where it is coming from and I can live with it, but I still find it bizarre. >> That there is nothing wrong with him thinking so. > > I do recognize that some would prefer that default argument expressions be treated differently, that > > def f(a=expression): pass > > be compiled to operate as the following does now > > def f(a=None): > a = a if a is not None else expression > > perhaps with None replaced with a hidden object() instance. An other possibility could be compiling as the following _tmp = expression def f(a = None): a = a if a is not None else _tmp.copy() > > I find the continuing fuss over the choice that was made to be the bizarre thing here. > IMO that comes because the python tribe often enough can't handle differences of appreciation. So what if BartC finds this behaviour bizarre? Why this need to correct him of that notion? By absolutly wanting to argue that it is not bizarre the most likely result was that BartC went on the defensive, while if people would simply have acknowlegded that he is not the only one that finds that behaviour bizarre and then focused on explaining what happens, a lot less fuss would have been generated. -- Antoon Pardon. From steve at pearwood.info Tue Nov 24 13:33:23 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 05:33:23 +1100 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <3589d016-f9ba-4217-83ea-4041ac085230@googlegroups.com> <51dc19ec-9ea0-4b37-bd66-6ebdacc83d87@googlegroups.com> <877fl78dvh.fsf@elektro.pacujo.net> Message-ID: <5654ad75$0$1583$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 05:13 am, Marko Rauhamaa wrote: > Personally, I don't like the "official" Python usage: > > Objects whose value can change are said to be mutable > > I would prefer this wording: > > Objects whose inner state can change are said to be mutable I see your point, but "inner state" might not be related to the object's externally visible value. For example, dicts have an inner state which can vary, even when their value remains the same: # using Python 3.3 py> d = {-1: "a", -2: "b"} py> e = {-2: "b", -1: "a"} py> d == e True py> print(d, e) {-2: 'b', -1: 'a'} {-1: 'a', -2: 'b'} The two dicts have the same value, but their inner state is slightly different, which is why they print in different order. Likewise for lists: py> a = [] py> for i in range(100): ... a.append(1) ... py> b = [1]*100 py> a == b True py> sys.getsizeof(a) == sys.getsizeof(b) False -- Steven From glicerinu at gmail.com Tue Nov 24 13:37:35 2015 From: glicerinu at gmail.com (Marc Aymerich) Date: Tue, 24 Nov 2015 19:37:35 +0100 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 7:11 PM, Zachary Ware wrote: > On Tue, Nov 24, 2015 at 9:46 AM, Marc Aymerich wrote: >> if __name__ == '__main__': >> loop_container = {} >> handler = threading.Thread(target=run_loop, args=(loop_container, )) >> handler.start() >> try: >> time.sleep(10000) >> finally: >> loop_container['loop'].stop() > > loop.stop() must be called from the thread running the loop. You can > do this by doing > `loop_container['loop'].call_soon_threadsafe(loop_container['loop'].stop)` > from the main thread (untested). > Hi Zachary, nice to know about call_soon_threadsafe! still it appears to work only if the main thread is in the foreground (as of calling Thread() with deamon=True), I don't get why it behaves differently :( maybe it is waiting for other stuff, but no idea how to confirm this with strace of other means.. i always see the same 'futex(0x7f9a70000c10, FUTEX_WAIT_PRIVATE, 0, NULL' -- Marc From antoon.pardon at rece.vub.ac.be Tue Nov 24 13:45:11 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 19:45:11 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> Message-ID: <5654B037.6020107@rece.vub.ac.be> Op 24-11-15 om 18:53 schreef Ian Kelly: > On Tue, Nov 24, 2015 at 10:32 AM, Antoon Pardon > wrote: >> Op 24-11-15 om 17:56 schreef Ian Kelly: >> >>> >>>> So on what grounds would you argue that () is not a literal. >>> >>> This enumerates exactly what literals are in Python: >>> >>> https://docs.python.org/3/reference/lexical_analysis.html#literals >>> >>> I think it's a rather pedantic point, though. How are nuances of the >>> grammar at all related to user expectations? >>> >> >> I think that enumaration is too limited. The section starts with: >> >> Literals are notations for constant values of some built-in types. >> >> () satisfies that definition, which is confirmed by the byte code >> produced for it. > > Literals are a type of lexical token. All of the literals shown in > that section are, indeed, tokens. Now I would point you to the grammar > specification: > > https://docs.python.org/3/reference/grammar.html > > And specifically the "atom" rule, which defines both list displays and > list comprehensions (as well as literals) as being atoms. > Specifically, it parses () as the token '(', followed by an optional > yield_expr or testlist_comp, followed by the token ')'. In no way is > that a single token, nor therefore a literal. I think limiting literals to lexical tokens is too limited. Sure we can define them like that in the context of the python grammar, but I don't see why we should limit ourselves to such a definition outside that context. I see nothing wrong with regarding -42 as a literal while according to the python grammar it isn't. There is nothing wrong with the notion that a literal can be a compounded value. But no matter what you want to call it. The dis module shows that -42 is treated in exactly the same way as 42, which is treated exactly the same way as () or as (5, 8, 13) which is treated differently from [] or [5, 8, 13]. Whether you want to call it literals or something else, the fact remains that (3, 5, 8) is treated like -42 by the CPython interpreter and [3, 5, 8] is not. -- Antoon. From ned at nedbatchelder.com Tue Nov 24 13:54:37 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 24 Nov 2015 10:54:37 -0800 (PST) Subject: What is a function parameter =[] for? In-Reply-To: References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> Message-ID: <36243614-aaaf-40df-a6b7-5b669cec02e1@googlegroups.com> On Tuesday, November 24, 2015 at 1:45:34 PM UTC-5, Antoon Pardon wrote: > Whether you want to call it literals or something else, the fact > remains that (3, 5, 8) is treated like -42 by the CPython interpreter > and [3, 5, 8] is not. Maybe I've lost the original point in all this minutia about what is a literal and what is not. Isn't the key point here that some objects are mutable (lists), and some are not (tuples, ints)? --Ned. From random832 at fastmail.com Tue Nov 24 14:00:40 2015 From: random832 at fastmail.com (Random832) Date: Tue, 24 Nov 2015 19:00:40 +0000 (UTC) Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: On 2015-11-24, Chris Angelico wrote: > Probably the grammar. In other words, it's part of the language's very > definition. Then the definition is wrong. I think "literal" is a word whose meaning is generally agreed on, rather than something each language's spec can invent from whole cloth for itself. It's not a python term, it's a programming term. And the documentation doesn't even use it consistently; it calls {} a literal. From ian.g.kelly at gmail.com Tue Nov 24 14:15:02 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 24 Nov 2015 12:15:02 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <5654B037.6020107@rece.vub.ac.be> References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> Message-ID: On Tue, Nov 24, 2015 at 11:45 AM, Antoon Pardon wrote: > I think limiting literals to lexical tokens is too limited. Sure we > can define them like that in the context of the python grammar, but > I don't see why we should limit ourselves to such a definition outside > that context. > > I see nothing wrong with regarding -42 as a literal while according > to the python grammar it isn't. > > There is nothing wrong with the notion that a literal can be a > compounded value. I'm somewhat inclined to agree with this. Taking an example from another language, if you use Javascript you'll hear all the time about "object literals" or "object literal notation". If you read the ECMAScript spec, however, you won't find the phrase "object literal" in there once. It seems that the common usage of "literal" is not the same as the way it's used in formal writing of language specifications. > But no matter what you want to call it. The dis module shows that > -42 is treated in exactly the same way as 42, which is treated > exactly the same way as () or as (5, 8, 13) which is treated > differently from [] or [5, 8, 13]. This is an implementation detail. The compiler would also be free to compile -42 into byte code as the negation of the constant 42. That 42 is a literal, on the other hand, is part of the language specification. From ian.g.kelly at gmail.com Tue Nov 24 14:15:48 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 24 Nov 2015 12:15:48 -0700 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: On Tue, Nov 24, 2015 at 12:00 PM, Random832 wrote: > On 2015-11-24, Chris Angelico wrote: >> Probably the grammar. In other words, it's part of the language's very >> definition. > > Then the definition is wrong. I think "literal" is a word whose meaning is > generally agreed on, rather than something each language's spec can invent from > whole cloth for itself. It's not a python term, it's a programming term. The Python language spec uses the word the same way that other language specs do. Is it the spec's usage that is wrong, or the common understanding of it? From marko at pacujo.net Tue Nov 24 14:17:10 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 24 Nov 2015 21:17:10 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <3589d016-f9ba-4217-83ea-4041ac085230@googlegroups.com> <51dc19ec-9ea0-4b37-bd66-6ebdacc83d87@googlegroups.com> <877fl78dvh.fsf@elektro.pacujo.net> <5654ad75$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8737vv8ax5.fsf@elektro.pacujo.net> Steven D'Aprano : > On Wed, 25 Nov 2015 05:13 am, Marko Rauhamaa wrote: >> I would prefer this wording: >> >> Objects whose inner state can change are said to be mutable > > I see your point, but "inner state" might not be related to the > object's externally visible value. The inner state is indeed inaccessible. We cannot determine immutability by testing, but we *can* determine mutability (if we're lucky). > For example, dicts have an inner state which can vary, even when their value > remains the same: > > # using Python 3.3 > > py> d = {-1: "a", -2: "b"} > py> e = {-2: "b", -1: "a"} > py> d == e > True > py> print(d, e) > {-2: 'b', -1: 'a'} {-1: 'a', -2: 'b'} > > The two dicts have the same value, but their inner state is slightly > different, which is why they print in different order. I'd say an object o is mutable (at least) if it has got a method m such that: before = o.m() # any intervening code that does not reassign o after = o.m() before == after => False Marko From zachary.ware+pylist at gmail.com Tue Nov 24 14:41:51 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 24 Nov 2015 13:41:51 -0600 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 12:37 PM, Marc Aymerich wrote: > still it appears to work only if the main thread is in the foreground > (as of calling Thread() with deamon=True), I don't get why it behaves > differently :( maybe it is waiting for other stuff, but no idea how to > confirm this with strace of other means.. i always see the same > 'futex(0x7f9a70000c10, FUTEX_WAIT_PRIVATE, 0, NULL' What's your exact version of Python? asyncio is still evolving rapidly, and may behave differently between patch releases (say, between 3.4.1 and 3.4.3). I have tried out your reproducer with my fix, and I can't provoke a hang using Python 3.4.3 on either OSX or Ubuntu Trusty. Can you give some more specific directions to reproduce? -- Zach From glicerinu at gmail.com Tue Nov 24 15:17:02 2015 From: glicerinu at gmail.com (Marc Aymerich) Date: Tue, 24 Nov 2015 21:17:02 +0100 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 8:41 PM, Zachary Ware wrote: > On Tue, Nov 24, 2015 at 12:37 PM, Marc Aymerich wrote: >> still it appears to work only if the main thread is in the foreground >> (as of calling Thread() with deamon=True), I don't get why it behaves >> differently :( maybe it is waiting for other stuff, but no idea how to >> confirm this with strace of other means.. i always see the same >> 'futex(0x7f9a70000c10, FUTEX_WAIT_PRIVATE, 0, NULL' > > What's your exact version of Python? asyncio is still evolving > rapidly, and may behave differently between patch releases (say, > between 3.4.1 and 3.4.3). > > I have tried out your reproducer with my fix, and I can't provoke a > hang using Python 3.4.3 on either OSX or Ubuntu Trusty. Can you give > some more specific directions to reproduce? > > -- > Zach > -- > https://mail.python.org/mailman/listinfo/python-list Yep, I'm a bit lost about how fuse implements going into background... so the only way I have to reproduce this so far is by using fuse :( # pip3 install fusepy import asyncio import threading import time import os import sys from fuse import FUSE, Operations def run_loop(loop_container): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) coro = asyncio.start_server(lambda: 1, '0.0.0.0', 8888, loop=loop) server = loop.run_until_complete(coro) loop_container['loop'] = loop loop.run_forever() if __name__ == '__main__': mountpoint = sys.argv[1] loop_container = {} handler = threading.Thread(target=run_loop, args=(loop_container,)) handler.start() try: # with foreground=True works FUSE(Operations(), mountpoint, foreground=False) finally: loop_container['loop'].call_soon_threadsafe(loop_container['loop'].stop) $ mkdir /tmp/7777 $ python3.5 /tmp/eventtest.py /tmp/7777 # Another terminal $ ps aux | grep python3.5 glic3 19983 0.5 0.1 215540 10772 ? Ssl 21:05 0:00 python3.5 me.py /tmp/7777 $ sudo strace -p 19983 Process 19983 attached - interrupt to quit futex(0x7fff42affca0, FUTEX_WAIT_PRIVATE, 0, NULL) = 0 # Here i fire $ fusermount -u /tmp/7777 tgkill(19983, 19985, SIGRTMIN) = 0 futex(0x7fff42affc30, FUTEX_WAKE_PRIVATE, 1) = 0 futex(0x7f9840afc9d0, FUTEX_WAIT, 19984, NULL I've just tried with python3.5 and the same behavior. The thing is that with foreground=True it just works. thank you for your time! -- Marc From glicerinu at gmail.com Tue Nov 24 15:22:49 2015 From: glicerinu at gmail.com (Marc Aymerich) Date: Tue, 24 Nov 2015 21:22:49 +0100 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 9:17 PM, Marc Aymerich wrote: > On Tue, Nov 24, 2015 at 8:41 PM, Zachary Ware > wrote: >> On Tue, Nov 24, 2015 at 12:37 PM, Marc Aymerich wrote: >>> still it appears to work only if the main thread is in the foreground >>> (as of calling Thread() with deamon=True), I don't get why it behaves >>> differently :( maybe it is waiting for other stuff, but no idea how to >>> confirm this with strace of other means.. i always see the same >>> 'futex(0x7f9a70000c10, FUTEX_WAIT_PRIVATE, 0, NULL' >> >> What's your exact version of Python? asyncio is still evolving >> rapidly, and may behave differently between patch releases (say, >> between 3.4.1 and 3.4.3). >> >> I have tried out your reproducer with my fix, and I can't provoke a >> hang using Python 3.4.3 on either OSX or Ubuntu Trusty. Can you give >> some more specific directions to reproduce? >> >> -- >> Zach >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > Yep, I'm a bit lost about how fuse implements going into background... > so the only way I have to reproduce this so far is by using fuse :( > > # pip3 install fusepy > import asyncio > import threading > import time > import os > import sys > from fuse import FUSE, Operations > > def run_loop(loop_container): > loop = asyncio.new_event_loop() > asyncio.set_event_loop(loop) > coro = asyncio.start_server(lambda: 1, '0.0.0.0', 8888, loop=loop) > server = loop.run_until_complete(coro) > loop_container['loop'] = loop > loop.run_forever() > > if __name__ == '__main__': > mountpoint = sys.argv[1] > loop_container = {} > handler = threading.Thread(target=run_loop, args=(loop_container,)) > handler.start() > try: > # with foreground=True works > FUSE(Operations(), mountpoint, foreground=False) > finally: > loop_container['loop'].call_soon_threadsafe(loop_container['loop'].stop) > > > $ mkdir /tmp/7777 > $ python3.5 /tmp/eventtest.py /tmp/7777 > > # Another terminal > $ ps aux | grep python3.5 > glic3 19983 0.5 0.1 215540 10772 ? Ssl 21:05 0:00 > python3.5 me.py /tmp/7777 > $ sudo strace -p 19983 > Process 19983 attached - interrupt to quit > futex(0x7fff42affca0, FUTEX_WAIT_PRIVATE, 0, NULL) = 0 > > # Here i fire > $ fusermount -u /tmp/7777 > > tgkill(19983, 19985, SIGRTMIN) = 0 > futex(0x7fff42affc30, FUTEX_WAKE_PRIVATE, 1) = 0 > futex(0x7f9840afc9d0, FUTEX_WAIT, 19984, NULL > > > I've just tried with python3.5 and the same behavior. The thing is > that with foreground=True it just works. > thank you for your time! In case this could be of some use: strace using foreground=True $ sudo strace -p 20326 Process 20326 attached - interrupt to quit futex(0x7fffd9b8e5a0, FUTEX_WAIT_PRIVATE, 0, NULL # Here umount command ) = 0 tgkill(20326, 20334, SIGRTMIN) = 0 tgkill(20326, 20335, SIGRTMIN) = 0 futex(0x7fffd9b8e530, FUTEX_WAKE_PRIVATE, 1) = 0 rt_sigaction(SIGHUP, NULL, {0x7fb60d850540, [], SA_RESTORER, 0x7fb61106ccb0}, 8) = 0 rt_sigaction(SIGINT, NULL, {0x7fb60d850540, [], SA_RESTORER, 0x7fb61106ccb0}, 8) = 0 rt_sigaction(SIGTERM, NULL, {0x7fb60d850540, [], SA_RESTORER, 0x7fb61106ccb0}, 8) = 0 rt_sigaction(SIGPIPE, NULL, {SIG_IGN, [], SA_RESTORER, 0x7fb61106ccb0}, 8) = 0 poll([{fd=5, events=0}], 1, 0) = 1 ([{fd=5, revents=POLLERR}]) close(5) = 0 brk(0x126d000) = 0x126d000 rt_sigaction(SIGINT, {0x50b380, [], SA_RESTORER, 0x7fb61106ccb0}, {0x7fb60d850540, [], SA_RESTORER, 0x7fb61106ccb0}, 8) = 0 sendto(8, "\0", 1, 0, NULL, 0) = 1 futex(0x7fb600001740, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x9d3204, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x9d3200, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 futex(0x9d31c0, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x7fb600000c10, FUTEX_WAIT_PRIVATE, 0, NULL) = 0 rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7fb61106ccb0}, {0x50b380, [], SA_RESTORER, 0x7fb61106ccb0}, 8) = 0 epoll_ctl(4, EPOLL_CTL_DEL, 7, {EPOLLWRBAND|EPOLLMSG|EPOLLERR|0xdea9800, {u32=32694, u64=23586238107778998}}) = 0 close(7) = 0 close(8) = 0 close(4) = 0 getsockname(6, {sa_family=AF_INET, sin_port=htons(8888), sin_addr=inet_addr("0.0.0.0")}, [16]) = 0 getpeername(6, 0x7fffd9b8dc70, [16]) = -1 ENOTCONN (Transport endpoint is not connected) close(6) = 0 madvise(0x7fb600033000, 8192, MADV_DONTNEED) = 0 close(3) = 0 exit_group(0) = ? Process 20326 detached -- Marc From c.buhtz at posteo.jp Tue Nov 24 15:27:07 2015 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Tue, 24 Nov 2015 21:27:07 +0100 Subject: import logging raise NotImplementedError Message-ID: <3p4xjG0FzSz5vN9@dovecot03.posteo.de> I using 'logging' for some month. But today I have strange problem. When importing it it fails. Python 3.4.3 (default, Oct 14 2015, 20:33:09) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import logging Traceback (most recent call last): File "", line 1, in File "", line 2237, in _find_and_load File "", line 2222, in _find_and_load_unlocked File "", line 2164, in _find_spec File "", line 1940, in find_spec File "", line 1916, in _get_spec File "", line 1897, in _legacy_get_spec File "", line 863, in spec_from_loader File "", line 904, in spec_from_file_location File "/usr/local/lib/python3.4/dist-packages/logging-0.4.9.6-py3.4.egg/logging/__init__.py", line 618 raise NotImplementedError, 'emit must be implemented '\ ^ SyntaxError: invalid syntax Any idea about it? I am not sure if there where an update in the background or something changed. The current situation make each "logging" using Python application unable to run. The problem happens with Python3 because "logging" is in the default installation. In Python2 it is not installed. I installed it with sudo python2 -m pip install logging -U This works without problems. Importing in Python2 works, too. -- GnuPGP-Key ID 0751A8EC From antoon.pardon at rece.vub.ac.be Tue Nov 24 15:54:43 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 21:54:43 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> Message-ID: <5654CE93.8080900@rece.vub.ac.be> Op 24-11-15 om 20:15 schreef Ian Kelly: >> But no matter what you want to call it. The dis module shows that >> -42 is treated in exactly the same way as 42, which is treated >> exactly the same way as () or as (5, 8, 13) which is treated >> differently from [] or [5, 8, 13]. > > This is an implementation detail. The compiler would also be free to > compile -42 into byte code as the negation of the constant 42. That 42 > is a literal, on the other hand, is part of the language > specification. I think you are picking nits. Sure the byte code could compile -42 into a byte code for 42 and a negation. Just as it could compile 42 into byte code for adding 32, 8 and 2. The point is, that the reverse isn't true. It couldn't compile [5, 8, 13] into a LOAD_CONST. -- Antoon Pardon From cs at zip.com.au Tue Nov 24 16:06:39 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 25 Nov 2015 08:06:39 +1100 Subject: Bi-directional sub-process communication In-Reply-To: References: Message-ID: <20151124210639.GA80502@cskk.homeip.net> On 24Nov2015 06:33, israel wrote: >On 11/23/2015 20:29, Cameron Simpson wrote: >>On 24Nov2015 16:25, Cameron Simpson wrote: >>>Completely untested example code: >>> >>>class ReturnEvent: >>> def __init__(self): >>> self.event = Event() >> >>With, of course: >> >> def wait(self): >> return self.event.wait() > >Of course :-) Ah, the Event() object comes from the threading module. >That makes sense. This should work perfectly. Thanks so much for >taking the time to help me out! Glad to be of service, Cameron Simpson All the doors in this ship have nice sunny dispositions. It is their pleasure to open for you, and their satisfaction to close with the knowledge of a job well done. - Marvin _The Hitchhiker's Guide to the Galaxy_ From bc at freeuk.com Tue Nov 24 16:14:12 2015 From: bc at freeuk.com (BartC) Date: Tue, 24 Nov 2015 21:14:12 +0000 Subject: What is a function parameter =[] for? In-Reply-To: References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> Message-ID: On 24/11/2015 20:54, Antoon Pardon wrote: > Op 24-11-15 om 20:15 schreef Ian Kelly: > >>> But no matter what you want to call it. The dis module shows that >>> -42 is treated in exactly the same way as 42, which is treated >>> exactly the same way as () or as (5, 8, 13) which is treated >>> differently from [] or [5, 8, 13]. >> >> This is an implementation detail. The compiler would also be free to >> compile -42 into byte code as the negation of the constant 42. That 42 >> is a literal, on the other hand, is part of the language >> specification. > > I think you are picking nits. Sure the byte code could compile -42 into > a byte code for 42 and a negation. Just as it could compile 42 into byte > code for adding 32, 8 and 2. > > The point is, that the reverse isn't true. It couldn't compile [5, 8, 13] > into a LOAD_CONST. I think it can, with a couple of extra instructions: LOAD_GLOBAL 0 (list) LOAD_CONST 1 ((5, 8, 13)) CALL_FUNCTION ie. by converting a tuple to a list, but it can also be done with a special byte-code. The effect is a that a constant list can be constructed without having to evalate each element at runtime, which I assume would be less efficient if the list is big enough (perhaps not for just 3 elements). -- Bartc From antoon.pardon at rece.vub.ac.be Tue Nov 24 16:25:18 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 24 Nov 2015 22:25:18 +0100 Subject: What is a function parameter =[] for? In-Reply-To: References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> Message-ID: <5654D5BE.2090801@rece.vub.ac.be> Op 24-11-15 om 22:14 schreef BartC: > On 24/11/2015 20:54, Antoon Pardon wrote: >> Op 24-11-15 om 20:15 schreef Ian Kelly: >> >>>> But no matter what you want to call it. The dis module shows that >>>> -42 is treated in exactly the same way as 42, which is treated >>>> exactly the same way as () or as (5, 8, 13) which is treated >>>> differently from [] or [5, 8, 13]. >>> >>> This is an implementation detail. The compiler would also be free to >>> compile -42 into byte code as the negation of the constant 42. That 42 >>> is a literal, on the other hand, is part of the language >>> specification. >> >> I think you are picking nits. Sure the byte code could compile -42 into >> a byte code for 42 and a negation. Just as it could compile 42 into byte >> code for adding 32, 8 and 2. >> >> The point is, that the reverse isn't true. It couldn't compile [5, 8, 13] >> into a LOAD_CONST. > > I think it can, with a couple of extra instructions: Sure it can with a couple of extra instructions. With extra instructions you can always use constants to build a mutable. The point is that a tuple can just be loaded as a constant without needing something extra. -- Antoon. From ian.g.kelly at gmail.com Tue Nov 24 16:33:17 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 24 Nov 2015 14:33:17 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <5654CE93.8080900@rece.vub.ac.be> References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> <5654CE93.8080900@rece.vub.ac.be> Message-ID: On Tue, Nov 24, 2015 at 1:54 PM, Antoon Pardon wrote: > Op 24-11-15 om 20:15 schreef Ian Kelly: > >>> But no matter what you want to call it. The dis module shows that >>> -42 is treated in exactly the same way as 42, which is treated >>> exactly the same way as () or as (5, 8, 13) which is treated >>> differently from [] or [5, 8, 13]. >> >> This is an implementation detail. The compiler would also be free to >> compile -42 into byte code as the negation of the constant 42. That 42 >> is a literal, on the other hand, is part of the language >> specification. > > I think you are picking nits. Yes. This entire subtopic about literals is picking nits. :-) From kisik2010 at live.ru Tue Nov 24 16:33:34 2015 From: kisik2010 at live.ru (=?utf-8?B?0JrQuNGB0LjQuiDQnNGD0YDRi9GB0LjQug==?=) Date: Wed, 25 Nov 2015 00:33:34 +0300 Subject: Reading files from .ar / .deb archives Message-ID: Hello! I'm new to Python, so I decided to learn it and write simple apt alternative (apt is somewhat broken for me). But I can't decide - can I read just one file (/DEBIAN/control) from archive without unpacking it, or do I need to unpack? And what module I can use to handle .ar files? (I read in Wikipedia that .deb is just .ar archive with specific structure) Sincerely, ?? Sent from my Windows Phone From pavlos.parissis at gmail.com Tue Nov 24 16:38:22 2015 From: pavlos.parissis at gmail.com (Pavlos Parissis) Date: Tue, 24 Nov 2015 22:38:22 +0100 Subject: list slice and generators Message-ID: <5654D8CE.2020105@gmail.com> Hi, Do you see any possible dangerous hidden bug in the below code(using python2.7 and python3.4)? My goal is to avoid go through the metrics list twice. But, I don't know if there will be a problem with doing in place replace of list elements using 2 generators. # metrics = ['', '0', '10'....] metrics = [x.metric(name) for x in self._server_per_proc] metrics[:] = (converter(x) for x in metrics) metrics[:] = (x for x in metrics if x is not None) return calculate(name, metrics) def calculate(name, metrics): if not metrics: return None if name in METRICS_SUM: return sum(metrics) elif name in METRICS_AVG: return int(sum(metrics)/len(metrics)) else: raise ValueError("Unknown type of calculation for {}".format(name)) def converter(value): try: return int(float(value)) except ValueError: return value.strip() or None except TypeError: return None Cheers, Pavlos -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From ian.g.kelly at gmail.com Tue Nov 24 16:53:17 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 24 Nov 2015 14:53:17 -0700 Subject: Bi-directional sub-process communication In-Reply-To: <20151124052512.GA51713@cskk.homeip.net> References: <84B23819-6214-4BDA-959D-85CD46431212@ravnalaska.net> <20151124052512.GA51713@cskk.homeip.net> Message-ID: On Mon, Nov 23, 2015 at 10:25 PM, Cameron Simpson wrote: > Then #3. I would have a common function/method for submitting a request to > go to the subprocess, and have that method return an Event on which to wait. > Then caller then just waits for the Event and collects the data. Obviously, > the method does not just return the Event, but an Event and something to > receive the return data. I've got a class called a Result for this kind of > thing; make a small class containing an Event and which will have a .result > attribute for the return information; the submitting method allocates one of > these and returns it. The response handler gets the instance (by looking it > up from the tag), sets the .result attribute and fires the Event. Your > caller wakes up from waiting on the Event and consults the .result > attribute. Your Result sounds suspiciously like a Future. ;-) From rosuav at gmail.com Tue Nov 24 17:00:46 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 09:00:46 +1100 Subject: import logging raise NotImplementedError In-Reply-To: <3p4xjG0FzSz5vN9@dovecot03.posteo.de> References: <3p4xjG0FzSz5vN9@dovecot03.posteo.de> Message-ID: On Wed, Nov 25, 2015 at 7:27 AM, wrote: > The problem happens with Python3 because "logging" is in the default > installation. In Python2 it is not installed. I installed it with > sudo python2 -m pip install logging -U > > This works without problems. Importing in Python2 works, too. You appear to have installed it into your Python 3.4's package directory, so I suspect you didn't just use the command given. But don't bother installing it in Py2 either - the docs say it's "New in version 2.3", so unless you're supporting Python 2.2, you shouldn't need to worry about this. ChrisA From cs at zip.com.au Tue Nov 24 17:07:22 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 25 Nov 2015 09:07:22 +1100 Subject: Bi-directional sub-process communication In-Reply-To: References: Message-ID: <20151124220722.GA38663@cskk.homeip.net> On 24Nov2015 14:53, Ian Kelly wrote: >On Mon, Nov 23, 2015 at 10:25 PM, Cameron Simpson wrote: >> Then #3. I would have a common function/method for submitting a request to >> go to the subprocess, and have that method return an Event on which to wait. >> Then caller then just waits for the Event and collects the data. Obviously, >> the method does not just return the Event, but an Event and something to >> receive the return data. I've got a class called a Result for this kind of >> thing; make a small class containing an Event and which will have a .result >> attribute for the return information; the submitting method allocates one of >> these and returns it. The response handler gets the instance (by looking it >> up from the tag), sets the .result attribute and fires the Event. Your >> caller wakes up from waiting on the Event and consults the .result >> attribute. > >Your Result sounds suspiciously like a Future. ;-) Yeah. I already had this stuff when the futures module was released, with some additional stuff futures didn't have (eg my dispatch queue is a priority queue, which is handy for some kinds of workflows; default dispatch is FIFO). My commonest use case/instance is a LateFunction, returned from my Later class. Use: L = Later() LF = L.defer(cllable, *a, *kw) ... result = LF() When you call a LateFunction you get the function result, blocking if it has not yet been run. It also raises if the deferred function raised. It has additional methods, but that is the core use: make it look like a function. You can do other easy things like: L.after(LFs, callable, *a, **kw) to have a function dispatched after the completion of other LateFunctions or: with L.ready(): ... suite ... to block until the Later has a slot, then run the suite. My Result and LateFunctions are subclasses of an Asynchron base class, which lets you wait for the result to arrive and has the common methods (wait, etc). The Result class supports this: R = Result() # caller, blocks until value received value = R.result # worker: deliver result R.result = func(blah) This makes thread cooperation far far more friendly. Cheers, Cameron Simpson Ride with a llama and you never ride alone. - Jeff Earls, DoD #0530, From rosuav at gmail.com Tue Nov 24 17:09:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 09:09:27 +1100 Subject: What is a function parameter =[] for? In-Reply-To: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 6:00 AM, Random832 wrote: > On 2015-11-24, Chris Angelico wrote: >> Probably the grammar. In other words, it's part of the language's very >> definition. > > Then the definition is wrong. I think "literal" is a word whose meaning is > generally agreed on, rather than something each language's spec can invent from > whole cloth for itself. It's not a python term, it's a programming term. > > And the documentation doesn't even use it consistently; it calls {} a literal. Can you link to that, please? Maybe there's something that can be improved. (Or maybe not.) ChrisA From steve at pearwood.info Tue Nov 24 19:34:45 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 11:34:45 +1100 Subject: What is a function parameter =[] for? References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> Message-ID: <56550227$0$1585$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 06:00 am, Random832 wrote: > On 2015-11-24, Chris Angelico wrote: >> Probably the grammar. In other words, it's part of the language's very >> definition. > > Then the definition is wrong. I think "literal" is a word whose meaning is > generally agreed on, rather than something each language's spec can invent > from whole cloth for itself. It's not a python term, it's a programming > term. Well, I don't know about that. According to you, and Ruby, this is a literal: [x+1, y+2*x, func(arg), MyClass(a, b)] http://ruby-doc.org/core-2.1.1/doc/syntax/literals_rdoc.html#label-Arrays which seems like an abuse of the term to me. How can it be a *literal* when it contains non-literal expressions which aren't known until runtime? Although I note that the actual examples of Array literals and Hash literals in the Ruby docs punt on the issue by only showing expressions that could be replaced by constants by a peephole optimizer. Lua refers to *string literals* but *table constructors*: http://www.lua.org/manual/5.1/manual.html Apart from strings, the above manual avoids the use of "literal". > And the documentation doesn't even use it consistently; it calls {} a > literal. Citation required. -- Steven From steve at pearwood.info Tue Nov 24 19:36:01 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 11:36:01 +1100 Subject: What is a function parameter =[] for? References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> Message-ID: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 08:25 am, Antoon Pardon wrote: > The point is that a > tuple can just be loaded as a constant without needing something extra. How would one load this tuple as a constant? (myfile.read(), "%.5f" % sin(x or y)) The point is that *in general*, tuple so-called "literals" (what the docs call displays) cannot be loaded as constants. If, and only if, the tuple contains nothing but immutable constants e.g. (1, 2.0, None, "spam") then a sufficiently smart compiler may be able to treat that specific tuple as a constant/literal. But that's a special case, and cannot be generalised to all tuple displays. All tuple so-called "literals" e.g. (), (1, 2), (x, y, z) etc. are fundamentally expressions that *may* have to be built at runtime. Hence the word "literal" is inappropriate. -- Steven From steve at pearwood.info Tue Nov 24 19:39:54 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 11:39:54 +1100 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> Message-ID: <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 01:18 am, Ned Batchelder wrote: > In English, "value" means something like, what is this equal to? > There isn't another good word to use in place of "value" here. There are many different meanings for the English noun "value" (Websters 1913 dictionary includes ten), but I think that the only one that is relevant is: "Any particular quantitative determination". although since we're not just talking about numbers even that needs to be modified to allow qualitative as well as quantitative determination. E.g. the value of a particular str object is the string "foobarbaz". > 2) In Python, "value" means, what object does a name refer to, or what > object did an evaluation produce. I don't think that is correct. The Docs clearly say that "value" is an attribute or quality of objects, not a synonym for "object": Quote: "Every object has an identity, a type and a value." https://docs.python.org/2/reference/datamodel.html#objects-values-and-types If the docs are a bit inconsistent in ensuring that "value" means something that objects *have* rather than something that objects *are*, that may be something to fix. > The confusion over mutable default arguments arises because the > defaulted argument always gets the same referent, but it might not > always be the same evalue. I'm not sure what value [ha, see what I did there?!] there is in inventing two new words for things that we already have standard terms for. "Referent" is just a funny way of saying "object", and "evalue" is just a misspelling of "value". -- Steven From lac at openend.se Tue Nov 24 19:55:51 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 25 Nov 2015 01:55:51 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201511250055.tAP0tpfO005889@fido.openend.se> In a message of Wed, 25 Nov 2015 11:39:54 +1100, "Steven D'Aprano" writes: >I'm not sure what value [ha, see what I did there?!] there is in inventing >two new words for things that we already have standard terms for. Done correctly, you can get clarity. >"Referent" is just a funny way of saying "object", and "evalue" is just a >misspelling of "value". If I had a time machine, I would go back to early days of Python and ban the use of the term 'assignment' and 'value' both. I would insist that the term 'binding' be used instead, though if you want to use the verb refer, to be synonymous with bind, well, I think that would work. (If not, next trip with the time machine, I ban that one as well.) Then you make it perfectly clear that what are bound are _objects_ not values (or evalues). The object has an evalue, but it is the object that is bound. It is crystal clear than people on this list mean very different things when they use the term 'value', and every one of them thinks that Python agrees with them. Cutting this knot may require a new word. Laura From rosuav at gmail.com Tue Nov 24 19:56:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 11:56:45 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Nov 25, 2015 at 11:36 AM, Steven D'Aprano wrote: > If, and only if, the tuple > contains nothing but immutable constants e.g. > > (1, 2.0, None, "spam") > > then a sufficiently smart compiler may be able to treat that specific tuple > as a constant/literal. But that's a special case, and cannot be generalised > to all tuple displays. In which case it's simply an example of constant-folding. It's the same as (1+2j) being called up with LOAD_CONST, despite being an expression. Recent CPythons are even willing to change what data type something is, to make it a constant: >>> dis.dis(lambda x: x in ["a","b","c","d","e"]) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 6 (('a', 'b', 'c', 'd', 'e')) 6 COMPARE_OP 6 (in) 9 RETURN_VALUE >>> dis.dis(lambda x: x in {"a","b","c","d","e"}) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 6 (frozenset({'d', 'c', 'a', 'e', 'b'})) 6 COMPARE_OP 6 (in) 9 RETURN_VALUE Lists and sets are definitely not constants. Tuples and frozensets aren't literals, but they can be constant. This is the optimizer talking, though, not language semantics. ChrisA From g.rodola at gmail.com Tue Nov 24 20:50:40 2015 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Wed, 25 Nov 2015 02:50:40 +0100 Subject: ANN: released psutil 3.3.0 with OpenBSD support Message-ID: Full story here: http://grodola.blogspot.com/2015/11/openbsd-support-for-psutil.html -- Giampaolo - http://grodola.blogspot.com From ben+python at benfinney.id.au Tue Nov 24 21:17:35 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 25 Nov 2015 13:17:35 +1100 Subject: A name refers to an object, an object has a value, equality compares values (was: What is a function parameter =[] for?) References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> Message-ID: <85h9kabz5s.fsf_-_@benfinney.id.au> Laura Creighton writes: > If I had a time machine, I would go back to early days of Python and > ban the use of the term 'assignment' and 'value' both. I would insist > that the term 'binding' be used instead, though if you want to use the > verb refer, to be synonymous with bind, well, I think that would work. +1 > (If not, next trip with the time machine, I ban that one as well.) I've never been able to remember where the keys are kept; I'm sure they keep being moved by previous drivers. > It is crystal clear than people on this list mean very different > things when they use the term 'value', and every one of them thinks > that Python agrees with them. Cutting this knot may require a new > word. Indeed, in the past I used the term ?value? as synonymous (in Python context) with the term ?object?. I have become convinced through this discussion that I should no longer use the terms that way. Instead, an object *has* a value at a point in time; if the object's value can change, we say the object is mutable. The syntax for literals describe a value, but the object once created may change its value. Typically, ?is? compares object identity; ?==? compares object value. The concepts are distinct, so I apologise for misleadingly conflating them in my terminology. -- \ ?Skepticism is the highest duty and blind faith the one | `\ unpardonable sin.? ?Thomas Henry Huxley, _Essays on | _o__) Controversial Questions_, 1889 | Ben Finney From scott at zml.ca Tue Nov 24 22:45:37 2015 From: scott at zml.ca (Scott Montreuil) Date: Wed, 25 Nov 2015 03:45:37 +0000 Subject: if else python Message-ID: Hi, I have an if statement which seems to run both commands and I cannot figure out why. (just learning so I may be missing something obvious) Any ideas? while True: global latit,longt,jlatit,jlongt,mlongt,mlatit response = urllib.urlopen(url) data = json.loads(response.read()) latit = data['Data'][0]['Latitude'] longt = data['Data'][0]['Longitude'] jlatit = data['Data'][1]['Latitude'] jlongt = data['Data'][1]['Longitude'] mlatit = data['Data'][2]['Latitude'] mlongt = data['Data'][2]['Longitude'] for i in user1locat: if float(i[2]) <= float(latit) <= float(i[3]) and float(i[4]) >= float(longt) >= float(i[5]): newlocation = int(i[1]) screen.addstr(7, 40, "%s at %s" %(user1, i[0])) motor1thread = threading.Thread(target=motor1) motor1thread.start() screen.refresh() else: screen.addstr(5, 40, "%s is at an unknown location %f %f\n" % (user1, latit, longt)) newlocation = 200 motor1thread = threading.Thread(target=motor1) motor1thread.start() screen.refresh() time.sleep(10) From a_kot2 at yahoo.com Tue Nov 24 23:22:54 2015 From: a_kot2 at yahoo.com (ARONA KANAGARATHNA) Date: Wed, 25 Nov 2015 04:22:54 +0000 (UTC) Subject: Istalling python References: <1283946663.9514492.1448425374289.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1283946663.9514492.1448425374289.JavaMail.yahoo@mail.yahoo.com> I tried to install this software python 3.4.3 to my pc which run windows Xp 32. i could installed but it doesnot run.it gives this message "python35-32/python.exe isnot a valid win32 app.Please help me to get solved this problem Thanks Aruna From rosuav at gmail.com Wed Nov 25 01:20:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 17:20:48 +1100 Subject: Istalling python In-Reply-To: <1283946663.9514492.1448425374289.JavaMail.yahoo@mail.yahoo.com> References: <1283946663.9514492.1448425374289.JavaMail.yahoo.ref@mail.yahoo.com> <1283946663.9514492.1448425374289.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Wed, Nov 25, 2015 at 3:22 PM, ARONA KANAGARATHNA via Python-list wrote: > I tried to install this software python 3.4.3 to my pc which run windows Xp 32. i could installed but it doesnot run.it gives this message "python35-32/python.exe isnot a valid win32 app.Please help me to get solved this problem It looks like you actually installed Python 3.5, not 3.4. If you get 3.4 installed successfully, it should work correctly. Better still, upgrade to Windows 7, 8, or 10, or make the jump to a free operating system, and start using something that's actually supported; XP is going to become increasingly problematic as time goes on. ChrisA From marko at pacujo.net Wed Nov 25 01:44:29 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 08:44:29 +0200 Subject: A name refers to an object, an object has a value, equality compares values References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> Message-ID: <87egfe7f3m.fsf@elektro.pacujo.net> Ben Finney : > Indeed, in the past I used the term ?value? as synonymous (in Python > context) with the term ?object?. I have become convinced through this > discussion that I should no longer use the terms that way. > > [...] > > The concepts are distinct, so I apologise for misleadingly conflating > them in my terminology. I don't think the meaning of the word "value" can be restricted in that way. Let's try to "refactor" the examples I had found in the wild: "How to get the value of a variable given its name in a string" => How to get the object a variable is bound to given the name of the variable in a string "The value of some objects can change. Objects whose value can change are said to be mutable" [no change] "I'm taking the return value of one function and using it as the argument of another function" => I'm taking the return object of one function and using it as the argument of another function "Don't get confused ? name on the left, value on the right" => Don't get confused ? name on the left, object on the right "We can print the current value of the dictionary in the usual way" [no change] "A return statement ends the execution of the function call and "returns" the result, i.e. the value of the expression following the return keyword, to the caller" => A return statement ends the execution of the function call and "returns" the result, i.e. the resulting object of the expression following the return keyword, to the caller "When we ask python what the value of x > 5 is, we get False" => When we ask python what the resulting object of x > 5 is, we get False "To display the value of a variable, you can use a print statement" => To display the value of the object a variable is bound to, you can use a print statement "Get a value of a specified key" => Get an image object of a specified key In a word, it's a lost cause. It is actually somewhat comical how Python documentation tries, but fails, to maintain terminological orthodoxy: A mapping object maps hashable values to arbitrary objects. [...] A dictionary?s keys are almost arbitrary values. Values that are not hashable, that is, values containing lists, dictionaries or other mutable types (that are compared by value rather than by object identity) may not be used as keys. [...] Dictionaries can be created by placing a comma-separated list of key: value pairs within braces [...] The first object of each item becomes a key in the new dictionary, and the second object the corresponding value. If a key occurs more than once, the last value for that key becomes the corresponding value in the new dictionary. [...] d[key] = value Set d[key] to value. [...] values() Return a new view of the dictionary?s values. Marko From ben+python at benfinney.id.au Wed Nov 25 01:48:55 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 25 Nov 2015 17:48:55 +1100 Subject: Reading files from .ar / .deb archives References: Message-ID: <85d1uybmlk.fsf@benfinney.id.au> ????? ??????? writes: > Hello! > I'm new to Python, so I decided to learn it Congratulations! Python is a fine language to learn, and this is the place to discuss general Python topics. You may also want to join the ?tutor? forum , which is specifically focussed on collaborative mentoring of Python newcomers. > and write simple apt alternative (apt is somewhat broken for me). > But I can't decide - can I read just one file (/DEBIAN/control) from > archive without unpacking it, or do I need to unpack? And what module > I can use to handle .ar files? (I read in Wikipedia that .deb is just > .ar archive with specific structure) You're right. The ?ar? archive format was IIUC chosen by the early Debian project because it is very simple. Unfortunately it is not widely supported; there is no standard library support in Python for ?ar? archives. You can use the third-party ?python-debian? library for reading Debian archive files . -- \ ?I know when I'm going to die, because my birth certificate has | `\ an expiration date.? ?Steven Wright | _o__) | Ben Finney From framstag at rus.uni-stuttgart.de Wed Nov 25 02:02:06 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 25 Nov 2015 07:02:06 +0000 (UTC) Subject: readline and TAB-completion? Message-ID: I need an input function with GNU readline support. So far I have: import readline readline.parse_and_bind("tab: complete") file = raw_input('File to send: ') Cursor keys are working, but TAB-completion works only in the current directory. Example: File to send: [TAB][TAB] argv.py error.py md5b64.py x.py Python_Cookbook.pdf bookmarks fexit.py murksigkeiten _.py compile.py https.py wcp File to send: /tmp/[TAB][TAB] argv.py error.py md5b64.py x.py Python_Cookbook.pdf bookmarks fexit.py murksigkeiten _.py compile.py https.py wcp Is there a way to make TAB-completion work for other directories, too? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From antoon.pardon at rece.vub.ac.be Wed Nov 25 03:14:48 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 09:14:48 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56556DF8.1080407@rece.vub.ac.be> Op 20-11-15 om 01:33 schreef Steven D'Aprano: > On Fri, 20 Nov 2015 07:57 am, Marko Rauhamaa wrote: > >> Laura Creighton : >> >>> My experience says that the people who are confused want lists to >>> behave like tuples. period. i.e. they don't want lists to be mutable. >> I think it's simpler than that. When you have: >> >> def f(x=[]): >> y = [] >> >> the first [] is evaluated when "def" is executed, while the latter [] is >> evaluated whenever "f" is executed. It's easy to be confused. > It shouldn't be. The function declaration > > def f(x=[]): > > is executed only once. The function body, conveniently indented to make it > stand out: > > y = [] > > is executed every time you call the function. What exactly is your point? People's confusions don't disappear because you as an expert have a good understanding of what is going on and so are no longer confused. Some aspects in the langauage are easily grasped and other aspects tend to create confusion. I see nothing wrong with people trying to point out what the cause of this confusion could be. You arguing that people shouldn't be confused is not helping. -- Antoon. From rosuav at gmail.com Wed Nov 25 03:27:47 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 19:27:47 +1100 Subject: A name refers to an object, an object has a value, equality compares values In-Reply-To: <87egfe7f3m.fsf@elektro.pacujo.net> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> <87egfe7f3m.fsf@elektro.pacujo.net> Message-ID: On Wed, Nov 25, 2015 at 5:44 PM, Marko Rauhamaa wrote: > I don't think the meaning of the word "value" can be restricted in that > way. Let's try to "refactor" the examples I had found in the wild: > > "How to get the value of a variable given its name in a string" > => How to get the object a variable is bound to given the name of the > variable in a string > > "The value of some objects can change. Objects whose value can change > are said to be mutable" > [no change] Agree with these. > "I'm taking the return value of one function and using it as the > argument of another function" > => I'm taking the return object of one function and using it as the > argument of another function > > "Don't get confused ? name on the left, value on the right" > => Don't get confused ? name on the left, object on the right > > "A return statement ends the execution of the function call and > "returns" the result, i.e. the value of the expression following the > return keyword, to the caller" > => A return statement ends the execution of the function call and > "returns" the result, i.e. the resulting object of the expression > following the return keyword, to the caller > > "When we ask python what the value of x > 5 is, we get False" > => When we ask python what the resulting object of x > 5 is, we get > False These are all talking about the value of an expression. Expressions have values, just as objects do; in Python, evaluation of an expression results in some object whose value is the value of the expression. In many cases, the definition of an expression's value has nothing to do with object identity, only value - for instance, when you call methods on strings such as lower(), center(), or format(), they're required to return a string object with a particular value, but there's no rule about that object's identity. On the CPython that I tried: $ python3 Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> s = "hello world" >>> s.lower() is s False >>> s.center(len(s)) is s True >>> s.format() is s True A compliant Python would be allowed to return either True or False for each of these; but if you change the 'is' checks to '==', they have to all be True, because the given operations don't change the string's *value* at all. Same with integer arithmetic, string concatenation, and so on. > "To display the value of a variable, you can use a print statement" > => To display the value of the object a variable is bound to, you can > use a print statement This one was probably talking to a new programmer. It's often not worth going into extreme detail early on; being slightly sloppy with terminology isn't a problem when what you're really saying is just "use print to find out what your program is doing". > "Get a value of a specified key" > => Get an image object of a specified key Another one that's looking at the value of an expression. In this case, though, the value is defined based on object identity as well as value, so I suppose you could word this as: "Get the object referenced by a specified key" if you wanted to be pedantic. But dictionaries are defined as mapping keys to values, and the value associated with a key happens to be represented by some object. > In a word, it's a lost cause. Doesn't need to be. > It is actually somewhat comical how Python documentation tries, but > fails, to maintain terminological orthodoxy: > > A mapping object maps hashable values to arbitrary objects. [...] > > A dictionary?s keys are almost arbitrary values. Values that are not > hashable, that is, values containing lists, dictionaries or other > mutable types (that are compared by value rather than by object > identity) may not be used as keys. No, this is strictly correct. A dictionary's keys are defined by values, not objects. The dict retains references to the objects used, but it's equality, not identity, that defines the match. >>> class S(str): pass ... >>> k1 = S("hello") >>> k2 = S("hello") >>> k1 is k2 False >>> k1 == k2 True >>> d = {k1: 42} >>> d[k2] 42 The *value* of the setter key is what the dictionary cares about, although it does retain the identity of the object: >>> next(iter(d)) is k1 True > Dictionaries can be created by placing a comma-separated list of > key: value pairs within braces > > [...] > > The first object of each item becomes a key in the new dictionary, and > the second object the corresponding value. If a key occurs more than > once, the last value for that key becomes the corresponding value in > the new dictionary. > > [...] > > d[key] = value > Set d[key] to value. > > [...] > > values() > Return a new view of the dictionary?s values. > > ht=value#mapping-types-dict> These are all talking about the other sense of "value" - the way expressions yield values. If you were to build a binary tree in Python, you'd have a similar concept of the nodes' "values", which would again be represented by Python objects; but to the tree, they're values. It's equivocation on the word "value", but I don't know of a better word for it (I've sometimes used "payload", but that has its own issues). ChrisA From rosuav at gmail.com Wed Nov 25 03:32:29 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 19:32:29 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <56556DF8.1080407@rece.vub.ac.be> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 7:14 PM, Antoon Pardon wrote: > What exactly is your point? People's confusions don't disappear > because you as an expert have a good understanding of what is > going on and so are no longer confused. > > Some aspects in the langauage are easily grasped and other > aspects tend to create confusion. I see nothing wrong with > people trying to point out what the cause of this confusion > could be. You arguing that people shouldn't be confused is > not helping. "Oh come on. It's basic arithmetic. You should be able to add 7 and 7... the result's 14!" "But it's so confusing. Why can't it be 16? It'd be more convenient for me if it were 16." "This is just how arithmetic works." "But it's still confusing!" At some point, you have to simply accept that this is how the system works.. or use a different system. (Octal maybe.) If you are perpetually confused by Python, you need to either learn how Python works, or use something else. ChrisA From c.buhtz at posteo.jp Wed Nov 25 03:40:18 2015 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Wed, 25 Nov 2015 09:40:18 +0100 Subject: import logging raise NotImplementedError In-Reply-To: References: <3p4xjG0FzSz5vN9@dovecot03.posteo.de> Message-ID: <3p5FzJ4R4Yz5vNN@dovecot03.posteo.de> On 2015-11-25 09:00 Chris Angelico wrote: > You appear to have installed it into your Python 3.4's package No really me. I found out who. I installed "ebscopy" from its GitHub repository with "sudo pip3 ./setup.py install" And this (tried to) install(ed) "logging" from PyPi. Don't know why. I just removed the egg-file in the dist-utils directory. After that everything works fine. -- GnuPGP-Key ID 0751A8EC From marko at pacujo.net Wed Nov 25 03:43:34 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 10:43:34 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> Message-ID: <87lh9mo4eh.fsf@elektro.pacujo.net> Chris Angelico : > At some point, you have to simply accept that this is how the system > works.. or use a different system. (Octal maybe.) If you are > perpetually confused by Python, you need to either learn how Python > works, or use something else. You are mixing two things: protesting and being confused. Protesting about a fundamental tenet is of no use, but talking about confusion might help. One psychological problem I'm seeing in many answers here is that people seem to want to defend the honor of Python. It's very religion-like. New potential converts are welcomed with open arms but when they start to ask awkward questions, they are treated as suppressive persons. Marko From rosuav at gmail.com Wed Nov 25 03:51:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Nov 2015 19:51:48 +1100 Subject: import logging raise NotImplementedError In-Reply-To: <3p5FzJ4R4Yz5vNN@dovecot03.posteo.de> References: <3p4xjG0FzSz5vN9@dovecot03.posteo.de> <3p5FzJ4R4Yz5vNN@dovecot03.posteo.de> Message-ID: On Wed, Nov 25, 2015 at 7:40 PM, wrote: > On 2015-11-25 09:00 Chris Angelico wrote: >> You appear to have installed it into your Python 3.4's package > > No really me. I found out who. > > I installed "ebscopy" from its GitHub repository with > "sudo pip3 ./setup.py install" > And this (tried to) install(ed) "logging" from PyPi. Don't know why. > > I just removed the egg-file in the dist-utils directory. After that > everything works fine. Ah! That would do it, yes. (Incidentally, 'pip install ebscopy' would be how I'd do it.) I think this is something that would merit reporting upstream. Neither datetime nor logging is needed in any even half-way recent Python; removing them would prevent your issue, and I doubt it'll cause problems on any supported version of Python. ChrisA From c.buhtz at posteo.jp Wed Nov 25 04:00:33 2015 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Wed, 25 Nov 2015 10:00:33 +0100 Subject: import logging raise NotImplementedError In-Reply-To: References: <3p4xjG0FzSz5vN9@dovecot03.posteo.de> <3p5FzJ4R4Yz5vNN@dovecot03.posteo.de> Message-ID: <3p5GQg36vXz5vNM@dovecot03.posteo.de> On 2015-11-25 19:51 Chris Angelico wrote: > Ah! That would do it, yes. (Incidentally, 'pip install ebscopy' would > be how I'd do it.) Yes, I did first. But I had some problems with 'ebscopy' so I wanted to be sure to get the freshes version of it available. ;) -- GnuPGP-Key ID 0751A8EC From antoon.pardon at rece.vub.ac.be Wed Nov 25 04:13:26 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 10:13:26 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> Message-ID: <56557BB6.70101@rece.vub.ac.be> Op 25-11-15 om 09:32 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 7:14 PM, Antoon Pardon > wrote: >> What exactly is your point? People's confusions don't disappear >> because you as an expert have a good understanding of what is >> going on and so are no longer confused. >> >> Some aspects in the langauage are easily grasped and other >> aspects tend to create confusion. I see nothing wrong with >> people trying to point out what the cause of this confusion >> could be. You arguing that people shouldn't be confused is >> not helping. > "Oh come on. It's basic arithmetic. You should be able to add 7 and > 7... the result's 14!" > > "But it's so confusing. Why can't it be 16? It'd be more convenient > for me if it were 16." > > "This is just how arithmetic works." > > "But it's still confusing!" > > At some point, you have to simply accept that this is how the system > works.. or use a different system. (Octal maybe.) If you are > perpetually confused by Python, you need to either learn how Python > works, or use something else. Those are not the only choices. The third option is that those at the drawing board of python come to the conclusion that some aspect of python is needlessly confusing and change the design. I also find your comparison disingenous. The responses I see often enough are not simply: this is how python works. They are often enough something like: How can you find this confusing, you shouldn't. If the regulars would answer more something like: Yes it can be confusing, you are not the only one, but let me explain what is going on. and the other would keep complaining about it being confusing, you would have a point. Instead the regulars all too often go on a tangent on how it shouldn't be confusing or something similar and then they are surprised that the exchange that follows isn't very fruitful. -- Antoon Pardon From lac at openend.se Wed Nov 25 04:22:38 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 25 Nov 2015 10:22:38 +0100 Subject: Istalling python In-Reply-To: <1283946663.9514492.1448425374289.JavaMail.yahoo@mail.yahoo.com> References: <1283946663.9514492.1448425374289.JavaMail.yahoo.ref@mail.yahoo.com> <1283946663.9514492.1448425374289.JavaMail.yahoo@mail.yahoo.com> Message-ID: <201511250922.tAP9McEo014435@fido.openend.se> In a message of Wed, 25 Nov 2015 04:22:54 +0000, ARONA KANAGARATHNA via Python- list writes: >I tried to install this software python 3.4.3 to my pc which run windows Xp 32. i could installed but it doesnot run.it gives this message "python35-32/python.exe isnot a valid win32 app.Please help me to get solved this problem >Thanks >Aruna The 'python35-32' part means that what you were trying to do was install python3.5 not 3.4.3 And that is what did not work. The reason that it did not work is that 3.5 does not run on windows xp. 3.4 is the latest version you can use. So, you can either change your operating system, and then get 3.5, or you can find 3.4.3 over here: https://www.python.org/downloads/release/python-343/ (downloads on the bottom of the page). Laura From antoon.pardon at rece.vub.ac.be Wed Nov 25 04:36:45 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 10:36:45 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <201511250055.tAP0tpfO005889@fido.openend.se> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> Message-ID: <5655812D.6030203@rece.vub.ac.be> Op 25-11-15 om 01:55 schreef Laura Creighton: > In a message of Wed, 25 Nov 2015 11:39:54 +1100, "Steven D'Aprano" writes: >> I'm not sure what value [ha, see what I did there?!] there is in inventing >> two new words for things that we already have standard terms for. > Done correctly, you can get clarity. > >> "Referent" is just a funny way of saying "object", and "evalue" is just a >> misspelling of "value". > If I had a time machine, I would go back to early days of Python and > ban the use of the term 'assignment' and 'value' both. I would insist > that the term 'binding' be used instead, though if you want to use the > verb refer, to be synonymous with bind, well, I think that would work. > (If not, next trip with the time machine, I ban that one as well.) > Then you make it perfectly clear that what are bound are _objects_ > not values (or evalues). The object has an evalue, but it is the > object that is bound. Not far enough back. Since there are older languages with the same assignment semantics as python, you should at least go so far. Otherwise you would get the argument why one shouldn't use the word assignment in python, while other languages use it for the same kind of thing. -- Antoon. From __peter__ at web.de Wed Nov 25 04:44:05 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Nov 2015 10:44:05 +0100 Subject: readline and TAB-completion? References: Message-ID: Ulli Horlacher wrote: > I need an input function with GNU readline support. So far I have: > > import readline > readline.parse_and_bind("tab: complete") > > file = raw_input('File to send: ') > > > Cursor keys are working, but TAB-completion works only in the current > directory. Example: > > > File to send: [TAB][TAB] > argv.py error.py md5b64.py x.py [...] > Is there a way to make TAB-completion work for other directories, too? Remove "/" from the set of delimiters: readline.set_completer_delims( "".join(c for c in readline.get_completer_delims() if c != "/")) > murksigkeiten I wonder what's in there ;) From antoon.pardon at rece.vub.ac.be Wed Nov 25 04:56:27 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 10:56:27 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <565585CB.7060709@rece.vub.ac.be> Op 25-11-15 om 01:36 schreef Steven D'Aprano: > On Wed, 25 Nov 2015 08:25 am, Antoon Pardon wrote: > >> The point is that a >> tuple can just be loaded as a constant without needing something extra. > > How would one load this tuple as a constant? > > (myfile.read(), "%.5f" % sin(x or y)) Picking nits again. That respons was done in a context fo what I called literals. Do you expect me to summarize the context in each response? > The point is that *in general*, tuple so-called "literals" (what the docs > call displays) cannot be loaded as constants. If, and only if, the tuple > contains nothing but immutable constants e.g. > > (1, 2.0, None, "spam") > > then a sufficiently smart compiler may be able to treat that specific tuple > as a constant/literal. But that's a special case, and cannot be generalised > to all tuple displays. > > All tuple so-called "literals" e.g. (), (1, 2), (x, y, z) etc. are > fundamentally expressions that *may* have to be built at runtime. Hence the > word "literal" is inappropriate. Literals are constants. So (x, y, z) is not a literal. This is what wikipedia says: In computer science, a literal is a notation for representing a fixed value in source code. Since (x, y, z) is not a fixed value, it is not a literal. -- Antoon. From __peter__ at web.de Wed Nov 25 05:07:08 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Nov 2015 11:07:08 +0100 Subject: list slice and generators References: <5654D8CE.2020105@gmail.com> Message-ID: Pavlos Parissis wrote: > Hi, > > Do you see any possible dangerous hidden bug in the below code(using > python2.7 and python3.4)? > > My goal is to avoid go through the metrics list twice. But, I don't > know if there will be a problem with doing in place replace of list > elements using 2 generators. > > # metrics = ['', '0', '10'....] > metrics = [x.metric(name) for x in self._server_per_proc] > metrics[:] = (converter(x) for x in metrics) > metrics[:] = (x for x in metrics if x is not None) Both generators are executed immediately, and the right side is always evaluated before the the slice assignment. Try metrics = (x.metric(name) for x in self._server_per_proc) metrics = (converter(x) for x in metrics) metrics = [x for x in metrics if x is not None] or metrics = (converter(x.metric(name)) for x in self._server_per_proc) metrics = [x for x in metrics if x is not None] to get down to one intermediate list. Avoiding the last one is a bit tricky: metrics = (converter(x.metric(name)) for x in self._server_per_proc) metrics = (x for x in metrics if x is not None) try: # if there is at least one item the generator is not empty first = next(metrics) except StopIteration: metrics = () else: # put the first item back in metrics = itertools.chain([first], metrics) assert metrics > return calculate(name, metrics) > > > def calculate(name, metrics): > if not metrics: > return None > > if name in METRICS_SUM: > return sum(metrics) > elif name in METRICS_AVG: # writing a function that calculates the average without # materialising the list left as an exercise ;) metrics = list(metrics) > return int(sum(metrics)/len(metrics)) > else: > raise ValueError("Unknown type of calculation for > {}".format(name)) > > > def converter(value): > try: > return int(float(value)) > except ValueError: > return value.strip() or None > except TypeError: > return None Disclaimer: all code untested. From ammammata at tiscalinet.it Wed Nov 25 05:14:16 2015 From: ammammata at tiscalinet.it (Ammammata) Date: Wed, 25 Nov 2015 10:14:16 +0000 (UTC) Subject: installing 3.5 Message-ID: hello ng well, it's about 10 minutes that's stuck at about 40%, installing C Runtime Update (KB2999226) on windows 7 64-bit is it a known issue (I must end the process manually and do something else first) or I just have to wait? -- /-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\ -=- -=- -=- -=- -=- -=- -=- -=- - -=- >>>>> http://www.bb2002.it :) <<<<< ........... [ al lavoro ] ........... From gengyangcai at gmail.com Wed Nov 25 05:26:51 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Wed, 25 Nov 2015 02:26:51 -0800 (PST) Subject: Returning a result from 3 items in a list In-Reply-To: <1900b12c-eb55-4fc5-a45f-b134bf8d36db@googlegroups.com> References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> <1900b12c-eb55-4fc5-a45f-b134bf8d36db@googlegroups.com> Message-ID: Programming is indeed tough ... I wish I had picked up this skill much earlier in life. But true, I will try to research my questions more in depth before posting here. My goal eventually is to build a successful YCombinator based web-based startup. On Wednesday, November 25, 2015 at 12:59:36 AM UTC+8, Ned Batchelder wrote: > On Tuesday, November 24, 2015 at 9:29:30 AM UTC-5, Mark Lawrence wrote: > > On 24/11/2015 14:07, Denis McMahon wrote: > > > On Tue, 24 Nov 2015 02:04:56 -0800, Cai Gengyang wrote: > > > > > >> Here's a dictionary with 3 values : > > >> > > >> results = { > > >> "gengyang": 14, > > >> "ensheng": 13, "jordan": 12 > > >> } > > >> > > >> How do I define a function that takes the last of the 3 items in that > > >> list and returns Jordan's results i.e. (12) ? > > > > > > You open a web browser and google for "python dictionary" > > > > > > > Ooh steady on old chap, surely you should have fitted the bib, done the > > spoon feeding and then changed the nappy? That appears to me the > > preferred way of doing things nowadays on c.l.py, rather than bluntly > > telling people not to be so bloody lazy. > > Mark and Denis, if you are having a hard time with newcomers to this list, > perhaps you need to find another list to read? > > Yes, Cai Gengyang could do more research before asking questions. But > your response does nothing to improve the situation. It's just snark > and bile, and does not exemplify the Python community's culture. > > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > What you can do for our language is put a better foot forward. > > --Ned. From ammammata at tiscalinet.it Wed Nov 25 05:27:20 2015 From: ammammata at tiscalinet.it (Ammammata) Date: Wed, 25 Nov 2015 10:27:20 +0000 (UTC) Subject: installing 3.5 References: Message-ID: Il giorno Wed 25 Nov 2015 11:14:16a, *Ammammata* inviava su comp.lang.python il messaggio news:XnsA55D7254213C3ammammatatiscalineti at 46.4.82.189. Vediamo cosa scrisse: > or I just have to wait? > this one It took ages to install, time to change my HDD -- /-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\ -=- -=- -=- -=- -=- -=- -=- -=- - -=- >>>>> http://www.bb2002.it :) <<<<< ........... [ al lavoro ] ........... From steve at pearwood.info Wed Nov 25 05:52:24 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 21:52:24 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 07:14 pm, Antoon Pardon wrote: > Op 20-11-15 om 01:33 schreef Steven D'Aprano: >> On Fri, 20 Nov 2015 07:57 am, Marko Rauhamaa wrote: >> >>> Laura Creighton : >>> >>>> My experience says that the people who are confused want lists to >>>> behave like tuples. period. i.e. they don't want lists to be mutable. >>> I think it's simpler than that. When you have: >>> >>> def f(x=[]): >>> y = [] >>> >>> the first [] is evaluated when "def" is executed, while the latter [] is >>> evaluated whenever "f" is executed. It's easy to be confused. >> It shouldn't be. The function declaration >> >> def f(x=[]): >> >> is executed only once. The function body, conveniently indented to make >> it stand out: >> >> y = [] >> >> is executed every time you call the function. > > What exactly is your point? That there is a simple analogy between the distinction between code inside/outside a for-loop, and code inside/outside a function. If you can understand why this loops forever, instead of just twice, then you can understand why function defaults work the way they do: L = [1, 2] for i in L: L.append(i) print(L) There is nothing "bizarre" or complicated or difficult to understand happening here. It might not be what you want to happen. It might not be what you expect to happen. But if you can't understand why it happens even after multiple explanations, then your learning skills are severely lacking. > People's confusions don't disappear > because you as an expert have a good understanding of what is > going on and so are no longer confused. I'm an expert? Awesome! No. But people's confusion would disappear if they would: - think about the process - try to follow the steps of what is happening - pay attention to the explanations given - and ask for clarification instead of arguing. I have come to the conclusion that there is nobody as stupid as an intelligent person who refuses to learn. I really don't know how more clear we can possibly be. If you take a list, initialised as the empty list ONCE, and then modify it repeatedly, the list doesn't magically become empty just because you want it to be empty. I completely understand beginners making this mistake: # Simulate tossing a coin until it is heads. count = 1 coin = random.choice(['heads', 'tails']) while coin != 'heads': count += 1 "Why does the loop run forever?" The coin doesn't magically toss itself, no matter how intuitively obvious it is that it should. (And I'm not making this example up -- I've seen three or four beginners make equivalent errors. It seems to be a very common conceptual mistake.) These beginners, at least, don't argue back that it is "bizarre" and stupid and crazy that you have to choose a new value for the coin variable each time through the loop. They soon learn that code outside the loop only runs once, if you want it to run each time through the loop, you should put it inside the body of the loop. Just like functions. If you want code to run each time you call the function, PUT IT INSIDE THE FUNCTION BODY. > Some aspects in the langauage are easily grasped and other > aspects tend to create confusion. You're right. Some aspects of the language are inherently confusing and hard to reason about. Threads are an example of that. The more powerful, and tricky, aspects of regular expressions. The weird stuff that happens during interpreter shutdown if you have __del__ methods in your objects. __del__ methods in general. There are many things which are hard to reason about, and therefore confusing. *This is not one of them.* This is not hard to reason about. The rules are no different from what happens in simple, ordinary code: L = [] # Initialise the list *once*. def func(): L.append(1) return L If I call func() three times, what value does it return? If you can get that, you can get this: def func(L=[]): # Initialise the list *once*. L.append(1) return L Confusing? Absolutely not. Or rather, if anyone cannot understand the behaviour of either function *after having it explained multiple times*, then programming is the wrong area for them. They should take up something more suited to their intellectual limitations, like dish washing, ditch digging, or politics. But is it predictable or intuitive? No, I agree, this behaviour is not intuitive, if you are coming from a background without equivalent rules. I will completely grant you that most people without Python experience would not correctly predict the behaviour of mutable defaults. I was caught out on that too, as I already admitted. Even though I already knew all the facts I needed to predict the behaviour correctly, I didn't put 2+2 together and get 4. That's *my bad*, not the language's fault. How much harder must it be for those who don't know the essential facts? I don't expect anyone to intuit the behaviour of Python defaults. That would be unreasonable. There's no shame in guessing wrong from a position of ignorance. Me, on the other hand... I should have known better. I did know better. But there's a big difference between those who guess wrong from a position of ignorance, and then make an honest attempt to understand the behaviour and why it actually does make sense and is even sometimes useful (even if they don't like it), and those people who insist that it is nonsensical, magical and "bizarre". -- Steven From steve at pearwood.info Wed Nov 25 05:58:09 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Nov 2015 21:58:09 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <87lh9mo4eh.fsf@elektro.pacujo.net> Message-ID: <56559443$0$1611$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 07:43 pm, Marko Rauhamaa wrote: > One psychological problem I'm seeing in many answers here is that people > seem to want to defend the honor of Python. No, your other honour! (It's an Oglaf reference, and *definitely* not safe for work. I'm not even going to link to it.) -- Steven From antoon.pardon at rece.vub.ac.be Wed Nov 25 06:04:03 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 12:04:03 +0100 Subject: Is there an meaning of '[[]]' in a list? In-Reply-To: References: <750e1071-395b-4e9b-ad64-05faa174a5bf@googlegroups.com> Message-ID: <565595A3.2050003@rece.vub.ac.be> Op 23-11-15 om 09:57 schreef Peter Otten: > Quivis wrote: > >> On Thu, 19 Nov 2015 12:40:17 +0100, Peter Otten wrote: >> >>> those questions that are a little harder >> And just how is he going to determine what is hard? > Note that I said "a little harder", not "hard". > > Write down your next ten or so questions, then work through the tutorial or > another introductory text, then use a search engine, then post the one or > two questions that are still unanswered. The problem is of course that he may already be doing that. We have just no idea about which questions he solved for himself because those are not mentioned here. But I do agree that he probably should try harder, he doesn't seem to come with the result of an experiment he tried where the result surprised him. -- Antoon. From PointedEars at web.de Wed Nov 25 06:10:09 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 25 Nov 2015 11:10:09 +0000 Subject: if else python References: Message-ID: <1555359.vKlKcyBEKv@PointedEars.de> Scott Montreuil wrote: > I have an if statement which seems to run both commands and I cannot > figure out why. (just learning so I may be missing something obvious) Any > ideas? Use a Python IDE and debugger. I recommend PyDev, but YMMV. > while True: > global latit,longt,jlatit,jlongt,mlongt,mlatit Why globals? Why so many? > response = urllib.urlopen(url) > data = json.loads(response.read()) > latit = data['Data'][0]['Latitude'] > longt = data['Data'][0]['Longitude'] DRY. [latit, longt] = [data['Data'][0][key] for key in ['Latitude', 'Longitude']] There may be even more efficient ways. Certainly the value of data['Data'] can be stored in a variable. > jlatit = data['Data'][1]['Latitude'] > jlongt = data['Data'][1]['Longitude'] > mlatit = data['Data'][2]['Latitude'] > mlongt = data['Data'][2]['Longitude'] Shouts out for applying DRY. [added line continuation escape] > for i in user1locat: > if float(i[2]) <= float(latit) <= float(i[3]) and \ > float(i[4]) >= float(longt) >= float(i[5]): > newlocation = int(i[1]) > screen.addstr(7, 40, "%s at %s" %(user1, i[0])) ["{0} at {1}".format(user1, i[0]) is recommended instead: ] The indentation of the last quoted line is ? as posted ? one space to the left of that of the previous line. That is a syntax error in Python as the ?if? statement is 8 columns to the left instead. Perhaps you have mixed tabs and spaces and that got lost while posting; in any case, this is not the original code, so all bets are off. Also, 8 spaces per indentation level is too much; it certainly is too much to be posted to Usenet where there is a customary limit at the 80th column. An indentation of 4 spaces per level is recommended for Python code. If the code still extends beyond the 80th column, you should use a line continuation escape sequence if that is syntactically necessary (it is not in my suggestion above). -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From breamoreboy at yahoo.co.uk Wed Nov 25 06:22:23 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 25 Nov 2015 11:22:23 +0000 Subject: Returning a result from 3 items in a list In-Reply-To: References: <133829df-f57f-442f-9dbf-b22b22f656ae@googlegroups.com> <1900b12c-eb55-4fc5-a45f-b134bf8d36db@googlegroups.com> Message-ID: On 25/11/2015 10:26, Cai Gengyang wrote: > But true, I will try to research my questions more in depth before posting here. > Please also research how to intersperse your answers or bottom post. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From harvest at should.be.invalid Wed Nov 25 06:39:44 2015 From: harvest at should.be.invalid (Jussi Piitulainen) Date: Wed, 25 Nov 2015 13:39:44 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> Message-ID: Antoon Pardon writes: > Op 25-11-15 om 01:55 schreef Laura Creighton: >> If I had a time machine, I would go back to early days of Python and >> ban the use of the term 'assignment' and 'value' both. I would >> insist that the term 'binding' be used instead, though if you want to >> use the verb refer, to be synonymous with bind, well, I think that >> would work. (If not, next trip with the time machine, I ban that one >> as well.) Then you make it perfectly clear that what are bound are >> _objects_ not values (or evalues). The object has an evalue, but it >> is the object that is bound. > > Not far enough back. Since there are older languages with the same > assignment semantics as python, you should at least go so far. Back to 1958 or so when Lisp was LISP and the association of names with whatever they named was represented as "association lists" (singly linked lists of key-keyed pairs), or possibly as "property lists" (singly linked lists with alternative elements being the key and the keyed). Other arrangements are known. Such a list would have the role that namespaces have in Python. One could replace the named thing. Then the name would be associated with something else when that same list still served as the namespace. This node (point b) in reminiscenses by John McCarthy himself refers to the "pseudo-functions" rplaca and rplacd that can replace components of these data structures (the "a" and "d" refer to the "address part" and the "decrement part" of a register). In point d, McCarthy refers to variables as variables; I'm sure this would go back to Church and 1940's at least, so I expect they used this word already back then. But the ability to store new content to the data structure that associates variables with stuff must be newer. I think it was new with LISP. I don't know if assignment was originally called assignment, or whether the association of names with stuff was originally called binding, but this terminology is old enough that I've known binding and assignment of variables by these names for as long as I can remember, with more or less the semantics that Python now uses. "Rebinding" I've not known elsewhere. > Otherwise you would get the argument why one shouldn't use the > word assignment in python, while other languages use it for the > same kind of thing. I think the argument is just that: One shouldn't use otherwise standard terminology in connection with Python. (With the possible exception of the Python language reference.) Because people might be confused. (Other people's confusion doesn't matter. And does the terminology ban even help?) Also, C is different! (Only C matters. Because no reasons.) That became snarky in the end. The trouble is that my mental model and terminology serve me really well when I work in Python. From antoon.pardon at rece.vub.ac.be Wed Nov 25 07:25:23 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 13:25:23 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5655A8B3.6000103@rece.vub.ac.be> Op 25-11-15 om 11:52 schreef Steven D'Aprano: > On Wed, 25 Nov 2015 07:14 pm, Antoon Pardon wrote: > >> Op 20-11-15 om 01:33 schreef Steven D'Aprano: >>> On Fri, 20 Nov 2015 07:57 am, Marko Rauhamaa wrote: >>> >>>> Laura Creighton : >>>> >>>>> My experience says that the people who are confused want lists to >>>>> behave like tuples. period. i.e. they don't want lists to be mutable. >>>> I think it's simpler than that. When you have: >>>> >>>> def f(x=[]): >>>> y = [] >>>> >>>> the first [] is evaluated when "def" is executed, while the latter [] is >>>> evaluated whenever "f" is executed. It's easy to be confused. >>> It shouldn't be. The function declaration >>> >>> def f(x=[]): >>> >>> is executed only once. The function body, conveniently indented to make >>> it stand out: >>> >>> y = [] >>> >>> is executed every time you call the function. >> What exactly is your point? > That there is a simple analogy between the distinction between code > inside/outside a for-loop, and code inside/outside a function. If you can > understand why this loops forever, instead of just twice, then you can > understand why function defaults work the way they do: > > L = [1, 2] > for i in L: > L.append(i) > print(L) > > > There is nothing "bizarre" or complicated or difficult to understand > happening here. It might not be what you want to happen. It might not be > what you expect to happen. But if you can't understand why it happens even > after multiple explanations, then your learning skills are severely > lacking. You shouldn't equate that what you understand with what is not bizarre complicated or difficult. I think there are reasons to find the above behaviour bizarre. I personnaly don't find it bizarre, but that is because I'm familiar with what is going on. But if someone expects the compilor to take a snapshot of L and iterate over that I am not going to say he shouldn't have expected that. And IMO each time you proclaim something nothing bizarre or complicated or difficult you are not helping. >> People's confusions don't disappear >> because you as an expert have a good understanding of what is >> going on and so are no longer confused. > I'm an expert? Awesome! > > No. But people's confusion would disappear if they would: > > - think about the process > - try to follow the steps of what is happening > - pay attention to the explanations given > - and ask for clarification instead of arguing. People would be more inclined to do so, if there wasn't someone claiming there was nothing bizarre or complicated or difficult going on. Telling the above is implying those steps are not needed because it is obvious what is happening. And if you don't want people arguing, don't start yourself. Because my impression of what is most likely to happen when someone says something like: That is bizarre, is that the regulars here are the ones that start arguing about it not being bizarre and then they are annoyed that the other is arguing too. > I have come to the conclusion that there is nobody as stupid as an > intelligent person who refuses to learn. Sure but that works just as much for the regulars here, who despite that some subjects keep confusing people new to the language, keep repeating that there is nothing bizarre, complicated or difficult going on. >> Some aspects in the langauage are easily grasped and other >> aspects tend to create confusion. > You're right. Some aspects of the language are inherently confusing and hard > to reason about. Threads are an example of that. The more powerful, and > tricky, aspects of regular expressions. The weird stuff that happens during > interpreter shutdown if you have __del__ methods in your objects. __del__ > methods in general. There are many things which are hard to reason about, > and therefore confusing. > > *This is not one of them.* Please stop using your personal evaluation as if it is some kind of objective measure. The number of people that seem to get confused by this, contradicts your claim. > But is it predictable or intuitive? No, I agree, this behaviour is not > intuitive, if you are coming from a background without equivalent rules. I > will completely grant you that most people without Python experience would > not correctly predict the behaviour of mutable defaults. > > I was caught out on that too, as I already admitted. Even though I already > knew all the facts I needed to predict the behaviour correctly, I didn't > put 2+2 together and get 4. That's *my bad*, not the language's fault. Why not? People are not perfect rational thinking machines. And expecting them to act like ones in order to get the language out of the wind, is a rather weak argument IMO. > How much harder must it be for those who don't know the essential facts? I > don't expect anyone to intuit the behaviour of Python defaults. That would > be unreasonable. There's no shame in guessing wrong from a position of > ignorance. > > Me, on the other hand... I should have known better. I did know better. > > But there's a big difference between those who guess wrong from a position > of ignorance, and then make an honest attempt to understand the behaviour > and why it actually does make sense and is even sometimes useful (even if > they don't like it), and those people who insist that it is nonsensical, > magical and "bizarre". There is an equally big difference between trying to explain what is going on and insisting that what is going on is not bizarre. -- Antoon. From bc at freeuk.com Wed Nov 25 07:35:32 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 12:35:32 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> Message-ID: On 25/11/2015 08:32, Chris Angelico wrote: > On Wed, Nov 25, 2015 at 7:14 PM, Antoon Pardon > wrote: >> What exactly is your point? People's confusions don't disappear >> because you as an expert have a good understanding of what is >> going on and so are no longer confused. >> >> Some aspects in the langauage are easily grasped and other >> aspects tend to create confusion. I see nothing wrong with >> people trying to point out what the cause of this confusion >> could be. You arguing that people shouldn't be confused is >> not helping. > > "Oh come on. It's basic arithmetic. You should be able to add 7 and > 7... the result's 14!" > > "But it's so confusing. Why can't it be 16? It'd be more convenient > for me if it were 16." > > "This is just how arithmetic works." > > "But it's still confusing!" > > At some point, you have to simply accept that this is how the system > works.. or use a different system. (Octal maybe.) If you are > perpetually confused by Python, you need to either learn how Python > works, or use something else. What is the purpose of the language, to make things easier for people or what? And who is it for? In other forums I've frequently recommended Python as an easy to learn language with a rapid development cycle. That was before I knew it had nearly as many quirks and gotchas as C! That was in preference to other choices which I found difficult and also elitist because of the advanced knowledge of CS and mathematics that it seemed you were expected to know. (Eg Lisp, which has at least 4 different ways of comparing for equality. Python only has two that I know of. A simple language would have only one, although my own has recently graduated from one to two; it's no longer simple!) One gotcha at least is well known. Where, in a language of the least surprises, you might write: d1 = date (25,12,2010) d2 = d1 d2.year += 1 You would expect d1 and d2 to represent a period one year apart. In Python, they would both be the later date. OK, so both names are bound to the same object-value. So then you try this: a = 10 b = a b += 1 '+=' is an 'in-place add', so you might expect different semantics from 'b = b+1'. But no, a isn't changed (disappointingly!). Then, from the point of view of a beginner, you have two distinct ways of representing a list of objects: a tuple and a list. Exactly why there have to be two is never really made clear beyond the inadequate explanation that one is immutable and the other mutable. OK, but now I have to continuously think about whether this multiple-set-of-objects is going to be a tuple or a list, or something else entirely (my date example above I think needs to be a class in Python, so that's a third way of doing things. Plus there is something called a 'set' that I haven't played with yet). > or use something else. Python isn't as bad as some languages, but it's well on the way. But is there anything simpler around that is also well-supported? -- Bartc From framstag at rus.uni-stuttgart.de Wed Nov 25 07:44:00 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Wed, 25 Nov 2015 12:44:00 +0000 (UTC) Subject: readline and TAB-completion? References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > > Is there a way to make TAB-completion work for other directories, too? > > Remove "/" from the set of delimiters: > > readline.set_completer_delims( > "".join(c for c in readline.get_completer_delims() if c != "/")) Great! > > murksigkeiten > > I wonder what's in there ;) Fexed to you :-) -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From marko at pacujo.net Wed Nov 25 07:48:21 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 14:48:21 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> Message-ID: <87egfent2i.fsf@elektro.pacujo.net> Jussi Piitulainen : > In point d, McCarthy refers to variables as variables; I'm sure this > would go back to Church and 1940's at least, so I expect they used > this word already back then. But the ability to store new content to > the data structure that associates variables with stuff must be newer. > I think it was new with LISP. As far as the words "variable" and "binding" go, they are present in lambda calculus (1929 and on): Lambda calculus (also written as ?-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. First formulated by Alonzo Church [...] [...] The abstraction operator, ?, is said to bind its variable wherever it occurs in the body of the abstraction. Variables that fall within the scope of an abstraction are said to be bound. All other variables are called free. In lambda calculus, variables are formal markers that are used during substitution during reduction (ie, evaluation). If we were to apply the thinking to Python, we could have: def f(x): return (x + 3) * x def g(x): return x * 2 - math.sqrt(x) Now the Python expression f(g(7)) could be reduced as follows: f(g(7)) => (g(7) + 3) * g(7) => ((7 * 2 - math.sqrt(7)) + 3) * (7 * 2 - math.sqrt(7)) => (7 * 2 - 2.6457513110645907) + 3 * (7 * 2 - 2.6457513110645907) => [etc] That is, binding/substitution is syntactic/formal. Or, to say it in another way, lambda calculus is a kind of macro processing language like cpp or m4. > I don't know if assignment was originally called assignment, or whether > the association of names with stuff was originally called binding, but > this terminology is old enough that I've known binding and assignment of > variables by these names for as long as I can remember, with more or > less the semantics that Python now uses. "Rebinding" I've not known > elsewhere. I think "binding" is too fancy a word to be used with conventional programming languages like Python. If your programming language has an assignment statement, "binding" is even nonsensical. Consider: def f(x): x += 1 return 2 * x Now we would have this reduction: f(7) => 7 += 1; return 2 * 7 because "x" would be bound to "7" everywhere in the function body. Marko From marko at pacujo.net Wed Nov 25 08:06:04 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 15:06:04 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> Message-ID: <878u5mns8z.fsf@elektro.pacujo.net> BartC : > That was in preference to other choices which I found difficult and > also elitist because of the advanced knowledge of CS and mathematics > that it seemed you were expected to know. Python is not a toy. It is a tool for advanced programmers. Mathematics has barely any touching point, but yes, solid CS fluency is required to be a productive software developer regardless of the programming language. Is a plumber an elitist, when he prefers to use tools I wouldn't know how to operate? > One gotcha at least is well known. Where, in a language of the least > surprises, you might write: > > d1 = date (25,12,2010) > d2 = d1 > d2.year += 1 > > You would expect d1 and d2 to represent a period one year apart. In > Python, they would both be the later date. No elitism or expertise would help you "expect" any outcome. I wouldn't even expect d2 to have a field called "year". That's why you read the specification. > Then, from the point of view of a beginner, you have two distinct ways > of representing a list of objects: a tuple and a list. Exactly why > there have to be two is never really made clear beyond the inadequate > explanation that one is immutable and the other mutable. >From a functional point of view, there don't have to be two separate concepts. The immutability of tuples is also just a design choice. However, tuples are a way to represent records, groupings of related values, where the semantics of each value is determined by its position in the tuple. The members in a tuple are typically of different data types. Lists are collections of values. Typically, each member of list is of the same type. Tuples are handy because they allow you to treat multiple values as a single value. Also, they are syntactically analogous to tuples in mathematics so chances are you have encountered them in elementary school. Finally, they are similar to function arguments, allowing you to return multiple values the same way you pass multiple values to the function. > Python isn't as bad as some languages, but it's well on the way. But > is there anything simpler around that is also well-supported? My "simpler" is different from your "simpler". Even C# has a lot of advanced concepts, as maybe even Fortran does nowadays. My own recommendation would be Scheme, but it is even more "elitist" than Python. Marko From bc at freeuk.com Wed Nov 25 08:20:31 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 13:20:31 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/11/2015 10:52, Steven D'Aprano wrote: > On Wed, 25 Nov 2015 07:14 pm, Antoon Pardon wrote: >> What exactly is your point? > > That there is a simple analogy between the distinction between code > inside/outside a for-loop, and code inside/outside a function. If you can > understand why this loops forever, instead of just twice, then you can > understand why function defaults work the way they do: > > L = [1, 2] > for i in L: > L.append(i) > print(L) > > > There is nothing "bizarre" or complicated or difficult to understand > happening here. What do you think most people would expect to happen here? I know, because you gave a spoiler, that it loops forever, otherwise I wouldn't be sure /without trying it/ (but I tried it anyway). Here's the same code in a somewhat different language: L := (1,2) for i in L do | L append:= i | println L od And this is the output: (1,2,1) (1,2,1,2) Which output (infinite series of [1,2,1,2,1,....] or the above) is more sensible, and which do you think people might prefer? The point is that the behaviour of the loop is by no means obvious, so neither is the behaviour of the function defaults. > It might not be what you want to happen. It might not be > what you expect to happen. But if you can't understand why it happens even > after multiple explanations, then your learning skills are severely > lacking. Accept that some things /are/ a source of confusion. When, in writing documentation, I find something hard to explain something, then I try and make it simpler in the program. But not enough of that goes on: it seems to be more lucrative to write thicker user manuals, and provide longer training courses, than to make software simpler. > I really don't know how more clear we can possibly be. If you take a list, > initialised as the empty list ONCE, and then modify it repeatedly, the list > doesn't magically become empty just because you want it to be empty. Sure. The problem is that it might not be obvious it's initialised once. > I completely understand beginners making this mistake: > > # Simulate tossing a coin until it is heads. > count = 1 > coin = random.choice(['heads', 'tails']) > while coin != 'heads': > count += 1 > > "Why does the loop run forever?" > > The coin doesn't magically toss itself, no matter how intuitively obvious it > is that it should. The concept of variables doesn't take long to learn in an 'ordinary' language. But one problem with Python is that it gives the impression that almost anything is possible. Your example can be made to work with a slight tweak: count = 1 coin = lambda: random.choice(['heads', 'tails']) while coin() != 'heads': count += 1 In some languages, there would never be such a possibility because they don't have the extraordinary flexibility and dynamism of Python. But once you get the idea that the language can almost do magic, then it doesn't seem so far-fetched that you original example could work! > Just like functions. If you want code to run each time you call the > function, PUT IT INSIDE THE FUNCTION BODY. Many languages don't have the concept of code running outside a function body. And especially they don't have the truly bizarre one that a function definition is itself a piece of code that is executed. Or maybe not executed, if it's inside a conditional statement! And therefore does not exist. This is an extra hurdle with learning or even using this language. -- bartc From rosuav at gmail.com Wed Nov 25 08:24:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 00:24:32 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <5655A8B3.6000103@rece.vub.ac.be> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <5655A8B3.6000103@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 11:25 PM, Antoon Pardon wrote: >> But there's a big difference between those who guess wrong from a position >> of ignorance, and then make an honest attempt to understand the behaviour >> and why it actually does make sense and is even sometimes useful (even if >> they don't like it), and those people who insist that it is nonsensical, >> magical and "bizarre". > > There is an equally big difference between trying to explain what is going > on and insisting that what is going on is not bizarre. There is also a big difference between finding that something doesn't match your expectations and declaring that it is "bizarre", which implies that it makes no sense *to anyone*. What we've been pointing out to you is that Python's way *does* make sense - just a different sense from the one you're expecting. There are many design decisions in programming languages. I've used languages that have myriad keywords, multiple levels of keywords (SQL is a shocking mess in that area), or no keywords at all (in REXX, you can legally write "if if then then; else else", and it interprets three of those as structure-defining and three as identifiers). I've used languages where everything's a statement, even basic arithmetic. Some languages make you declare your local variables, while others have you declare your globals instead. These are all viable choices, and they all make sense. The languages are internally coherent. I would not call any of them "bizarre", with the possible exception of DeScribe Macro Language, and even that's not too hard to get your head around. (I wouldn't want to use it for any sort of general programming, though. Its sole value is manipulating the DeScribe Word Processor, and if you were to use it for something else, you'd have to expand the language lexicon. There's no system of extensibility.) Expanding on one of those examples, here are three ways that you can distinguish between local/nonlocal/global variables/names/etc: /* C++: Declare everything at a specific scope. */ int global_variable = 1; struct outer_scope { int instance_variable; void inner_scope() { int local_variable = 3; } }; /* PHP: Declare your globals, otherwise they're local. */ $global_variable = 1; function outer_function() { global $global_variable; $local_variable = 2; /* I don't trust PHP's nested functions. */ } # Python: Declare any globals you want to rebind. global_name = 1 def outer_function(): nonlocal_name = 2 def inner_function(): global global_name local_name = 3 There are variations on these, too (like ECMAScript's "declare and it's function local, else it's an attribute of the global object"). Anyway. Point is, each of these systems is internally consistent, and in each one, you can explain in a single sentence what the rule is. Not one of these is bizarre, but I do completely understand that anyone who has experience with just one of them _would_ find either of the others confusing at first. "Wait, why do you need to declare this as global, but not that?" "You're not assigning to that one, so you don't need to declare it." If you want to call Python's system "bizarre", you have to show more than just that your expectations weren't matched by the language. You have to show that Python lacks internal sense or consistency. You have, so far, not shown anything of the kind, ergo we are continuing to insist that Python is NOT bizarre. ChrisA From rosuav at gmail.com Wed Nov 25 08:35:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 00:35:38 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 11:35 PM, BartC wrote: > One gotcha at least is well known. Where, in a language of the least > surprises, you might write: > > d1 = date (25,12,2010) > d2 = d1 > d2.year += 1 > > You would expect d1 and d2 to represent a period one year apart. In Python, > they would both be the later date. I'm not sure why this is "a language of least surprises". It's just a language of *different* surprises. I'll give you an example of exactly that: PHP has semantics similar to what you're describing. $ php foo [1] => bar ) I'm not exactly sure of the definition of PHP's assignment, as it's been a while since I looked it up; but it seems to be something like what you're describing. This seems well and good, until you start contemplating gigantic arrays and what happens when you pass them from one function to another. What're your performance expectations? With Python, I know that "a = b" happens in constant time, and I also know that the performance of "a[1]=2" is not going to be affected by any other names that might be bound to the same object. PHP's references make this even more messy: $ php foo [1] => baz ) So... since I'd previously set $b to be a reference, now assigning to it does something different. And what, exactly? Is $a[1] the exact same array as $a? Has any copying happened? When I change $b[1], is that the same as changing $a[1], or is it actually changing $a[1][1], and is that even any different? This isn't a magical solution to all surprises, except perhaps in that you've built a language yourself, so it conforms perfectly to *your* expectations. You can never make something that fits everyone's expectations, so you'll always have surprises somewhere. It's just a question of where, and how easily they can be explained when someone runs into them. ChrisA From bc at freeuk.com Wed Nov 25 08:37:59 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 13:37:59 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <878u5mns8z.fsf@elektro.pacujo.net> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <878u5mns8z.fsf@elektro.pacujo.net> Message-ID: On 25/11/2015 13:06, Marko Rauhamaa wrote: > BartC : >> Then, from the point of view of a beginner, you have two distinct ways >> of representing a list of objects: a tuple and a list. Exactly why >> there have to be two is never really made clear beyond the inadequate >> explanation that one is immutable and the other mutable. > However, tuples are a way to represent records, groupings of related > values, where the semantics of each value is determined by its position > in the tuple. The members in a tuple are typically of different data > types. Using tuples in the same way that other languages implement records is going to be difficult if you can't change the values of the fields! > My "simpler" is different from your "simpler". Even C# has a lot of > advanced concepts, as maybe even Fortran does nowadays. > > My own recommendation would be Scheme, but it is even more "elitist" > than Python. OK, Lisp. (I can't actually tell the difference.) -- Bartc From rosuav at gmail.com Wed Nov 25 08:44:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 00:44:38 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <878u5mns8z.fsf@elektro.pacujo.net> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <878u5mns8z.fsf@elektro.pacujo.net> Message-ID: On Thu, Nov 26, 2015 at 12:06 AM, Marko Rauhamaa wrote: > However, tuples are a way to represent records, groupings of related > values, where the semantics of each value is determined by its position > in the tuple. The members in a tuple are typically of different data > types. > > Lists are collections of values. Typically, each member of list is of > the same type. This is a distinction I generally make. Putting it another way: a list has the same meaning regardless of how many items are on it (for instance, a shopping list is still a shopping list whether it has five or fifty items on it), where a tuple is a package where each element has a specific meaning (such as Cartesian coordinates; the difference between the position (2,3) and the position (2,3,4) is not just that there's "more position" in the second one - it's a drastically different beast, living in three dimensions instead of two). Nothing in the language enforces this, but the mutability of lists does tend to align well with things that can grow and shrink, and the immutability of tuples makes them more like strings or complex numbers (in fact, a complex number is basically a tuple of two floats). ChrisA From rosuav at gmail.com Wed Nov 25 08:50:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 00:50:59 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <87egfent2i.fsf@elektro.pacujo.net> References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> <87egfent2i.fsf@elektro.pacujo.net> Message-ID: On Wed, Nov 25, 2015 at 11:48 PM, Marko Rauhamaa wrote: > I think "binding" is too fancy a word to be used with conventional > programming languages like Python. If your programming language has an > assignment statement, "binding" is even nonsensical. Consider: > > def f(x): > x += 1 > return 2 * x > > Now we would have this reduction: > > f(7) > => > 7 += 1; return 2 * 7 > > because "x" would be bound to "7" everywhere in the function body. This is exactly the sort of problem that inevitably happens when you try to extend mathematics into programming. Most branches of mathematics are simply looking at pure, eternal statements of truth; if once you discover (or decide) that x is equal to 7, you can perfectly substitute one for the other in any context. There is no chronology - x has always been equal to 7, you just didn't know it until now. It's possible to write code this way, and there are benefits to it, but as soon as you have an assignment operator, you're introducing a whole aspect of chronological truth that math lacks, so some concepts ARE going to need to be modified. However, that doesn't stop us from making use of terminology, where it's helpful. We know from grade school that adding two numbers together and dividing by 2 gives us the average, or the midpoint between them. Programming languages introduce the notion of adding two strings together, and also throw the curve-ball at us that sometimes the average isn't the same as the perfect mathematical average (due to rounding or other issues). But we'll still call that operation adding, and we'll still have avg() functions that do what we broadly expect. ChrisA From antoon.pardon at rece.vub.ac.be Wed Nov 25 08:51:23 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 14:51:23 +0100 Subject: What does a list comprehension do (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?)) In-Reply-To: <877fldnm9z.fsf@handshake.de> References: <877fldnm9z.fsf@handshake.de> Message-ID: <5655BCDB.4020905@rece.vub.ac.be> Op 20-11-15 om 08:49 schreef dieter: > In addition, the last few days have had two discussions in this list > demonstrating the conceptial difficulties of late binding -- one of them: > > Why does "[lambda x: i * x for i in range(4)]" gives > a list of essentially the same functions? Can you (or someone else) explain what a list comprehension is equivallent of. Especially in python3. Take this simple list comprhesion: [x * x for x in range(10)] what would this be equivallent of? Something like: def lch1(): ls = [] for x in range(10): ls.append(x * x) return ls Or more something like: def lch2(): def expr(x): return x * x ls = [] for x in range(10): ls.append(expr(x)) return ls For this example it doesn't make a difference but for the example above it would become important. def lch3(): ls = [] for i in range(4): ls.append(lambda x: i * x) return ls versus def lch4(): def expr(i): return lambda x: i * x ls = [] for i in range(4) ls.append(expr(i)) return ls Now from the result we get I expect list comprehensions to work more like lch1 and lch3 rather than lch2 and lch4. But I can understand people who think of the expression as a function of the variable that is iterated over. Am I missing something? Would it be worthwile considering changing this behaviour? -- Antoon. From marko at pacujo.net Wed Nov 25 08:53:01 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 15:53:01 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <878u5mns8z.fsf@elektro.pacujo.net> Message-ID: <874mganq2q.fsf@elektro.pacujo.net> BartC : > Using tuples in the same way that other languages implement records is > going to be difficult if you can't change the values of the fields! Guido could decide tomorrow that tuples are mutable. The decision is more or less arbitrary, and has to do with dictionary keys, I bet (not a particularly good reason). Anyway, Python has two ways to represent records: classes and tuples. Tuples are nice because they are concise and ad hoc. Often you start with a scalar value, then turn it into a tuple. After a while your handy tuple turns out a bit cumbersome to use so you convert it into an actual class. Marko From marko at pacujo.net Wed Nov 25 09:08:26 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 16:08:26 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> <87egfent2i.fsf@elektro.pacujo.net> Message-ID: <87ziy2masl.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Nov 25, 2015 at 11:48 PM, Marko Rauhamaa wrote: >> I think "binding" is too fancy a word to be used with conventional >> programming languages like Python. If your programming language has >> an assignment statement, "binding" is even nonsensical. Consider: >> >> def f(x): >> x += 1 >> return 2 * x >> >> Now we would have this reduction: >> >> f(7) >> => >> 7 += 1; return 2 * 7 >> >> because "x" would be bound to "7" everywhere in the function body. > > This is exactly the sort of problem that inevitably happens when you > try to extend mathematics into programming. Most branches of > mathematics are simply looking at pure, eternal statements of truth; > if once you discover (or decide) that x is equal to 7, you can > perfectly substitute one for the other in any context. There is no > chronology - x has always been equal to 7, you just didn't know it > until now. It's possible to write code this way, and there are > benefits to it, but as soon as you have an assignment operator, you're > introducing a whole aspect of chronological truth that math lacks, so > some concepts ARE going to need to be modified. > > However, that doesn't stop us from making use of terminology, where > it's helpful. I think that's the point. Binding is a concept of a formal (textual) substitution algorithm, which Python's assignment is not. Variable-binding mechanisms occur in different contexts in mathematics, logic and computer science. In all cases, however, they are purely syntactic properties of expressions and variables in them. Marko From glicerinu at gmail.com Wed Nov 25 09:10:31 2015 From: glicerinu at gmail.com (Marc Aymerich) Date: Wed, 25 Nov 2015 15:10:31 +0100 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Tue, Nov 24, 2015 at 9:17 PM, Marc Aymerich wrote: > On Tue, Nov 24, 2015 at 8:41 PM, Zachary Ware > wrote: >> On Tue, Nov 24, 2015 at 12:37 PM, Marc Aymerich wrote: >>> still it appears to work only if the main thread is in the foreground >>> (as of calling Thread() with deamon=True), I don't get why it behaves >>> differently :( maybe it is waiting for other stuff, but no idea how to >>> confirm this with strace of other means.. i always see the same >>> 'futex(0x7f9a70000c10, FUTEX_WAIT_PRIVATE, 0, NULL' >> >> What's your exact version of Python? asyncio is still evolving >> rapidly, and may behave differently between patch releases (say, >> between 3.4.1 and 3.4.3). >> >> I have tried out your reproducer with my fix, and I can't provoke a >> hang using Python 3.4.3 on either OSX or Ubuntu Trusty. Can you give >> some more specific directions to reproduce? >> >> -- >> Zach >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > Yep, I'm a bit lost about how fuse implements going into background... > so the only way I have to reproduce this so far is by using fuse :( problem solved ! Just found out that threads should be started by fuse.init() in order to run when fuse is backgrounded. -- Marc From antoon.pardon at rece.vub.ac.be Wed Nov 25 09:17:43 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 15:17:43 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <5655A8B3.6000103@rece.vub.ac.be> Message-ID: <5655C307.7020003@rece.vub.ac.be> Op 25-11-15 om 14:24 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 11:25 PM, Antoon Pardon > wrote: >>> But there's a big difference between those who guess wrong from a position >>> of ignorance, and then make an honest attempt to understand the behaviour >>> and why it actually does make sense and is even sometimes useful (even if >>> they don't like it), and those people who insist that it is nonsensical, >>> magical and "bizarre". >> There is an equally big difference between trying to explain what is going >> on and insisting that what is going on is not bizarre. > There is also a big difference between finding that something doesn't > match your expectations and declaring that it is "bizarre", which > implies that it makes no sense *to anyone*. What we've been pointing > out to you is that Python's way *does* make sense - just a different > sense from the one you're expecting. I find the above a very defensive attitude. People are mostly not very accurate in how they put things into words. People tend to say that something was delicious instead of saying that they found it delicious. So when someone declares as aspect of python to be bizarre I interpret that as an indication of what impression that aspect made on that person instead of some declaration of fact. So stop feeling attacked because someone found something bizarre. You also seem to think that bizarre contradicts making sense. It is entirly possible to understand what is going on and still find it bizarre that the designers allowed for certain kinds or result. > If you want to call Python's system "bizarre", you have to show more > than just that your expectations weren't matched by the language. You > have to show that Python lacks internal sense or consistency. You > have, so far, not shown anything of the kind, ergo we are continuing > to insist that Python is NOT bizarre. No I don't have to show any such thing. There are things with an internal sense of consistency that can be found utterly bizarre. I also find it telling that you go from me talking about someone thinking that what is going on in a specific aspect of python being bizarre, to regarding such a person as calling Python's system "bizarre", as if judging one aspect is like judging the whole system. -- Antoon. From bc at freeuk.com Wed Nov 25 09:34:12 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 14:34:12 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <874mganq2q.fsf@elektro.pacujo.net> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <878u5mns8z.fsf@elektro.pacujo.net> <874mganq2q.fsf@elektro.pacujo.net> Message-ID: On 25/11/2015 13:53, Marko Rauhamaa wrote: > BartC : > >> Using tuples in the same way that other languages implement records is >> going to be difficult if you can't change the values of the fields! > > Guido could decide tomorrow that tuples are mutable. (Could that be done without breaking existing code? And what then would be the difference between them and lists?) > Anyway, Python has two ways to represent records: classes and tuples. > Tuples are nice because they are concise and ad hoc. Often you start > with a scalar value, then turn it into a tuple. After a while your handy > tuple turns out a bit cumbersome to use so you convert it into an actual > class. This is how records are handled in another language which I believe is simpler than Python: http://pastebin.com/vhsJML8U This also implements my example from earlier in the thread. Now compare with Python's approach. OK, that also needs two concepts, a list, and a record. But the distinction is now completely obvious. Records are also mutable. It would also be clear why you can't append to a record. Now try explaining again to me how you would use tuples for the same thing... -- Bartc From harvest at should.be.invalid Wed Nov 25 10:13:38 2015 From: harvest at should.be.invalid (Jussi Piitulainen) Date: Wed, 25 Nov 2015 17:13:38 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> <87egfent2i.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> In point d, McCarthy refers to variables as variables; I'm sure this >> would go back to Church and 1940's at least, so I expect they used >> this word already back then. But the ability to store new content to >> the data structure that associates variables with stuff must be >> newer. I think it was new with LISP. > > As far as the words "variable" and "binding" go, they are present in > lambda calculus (1929 and on): So it's more than ten years earlier than I thought. Old enough, anyway. Strictly speaking, that a Wikipedia article uses the words "variable" and "binding" to discuss lambda calculi today is not a proof that Church used those words in his time. I'm inclined to believe he did. (Our CS department had a copy of Church's book. It smelled funny.) A point is that McCarthy knew about lambda calculus. That's where the name "lambda" for the binding operator comes from, together with "variable" and "binding" and the correct scoping rules that other people worked out quite a bit later. >> I don't know if assignment was originally called assignment, or >> whether the association of names with stuff was originally called >> binding, but this terminology is old enough that I've known binding >> and assignment of variables by these names for as long as I can >> remember, with more or less the semantics that Python now >> uses. "Rebinding" I've not known elsewhere. > > I think "binding" is too fancy a word to be used with conventional > programming languages like Python. If your programming language has an > assignment statement, "binding" is even nonsensical. The term has more than fifty years of history in languages that have not only an assignment statement but also mutable things. It's needed to speak of where and when in a program the occurrences of an identifier have what meaning. A statement like x = 31 does not affect every x even in a Python program, only those that are bound in the same namespace. In Scheme, a variable is bound to a location where its value is stored. A variable reference evaluates to that stored value. In Python, one chooses to say that a mumble is bound to an object, but then there is a namespace that also serves as a store where one can put a new object, like one can put a new object in a Python dictionary, and then the mumble becomes bound to that object instead. These are different ways to talk about the same thing. (The Scheme way in a sense "explains" mutable store in terms of mathematical functions where the Python way takes it for granted, I think). No nonsense. > Consider: > > def f(x): > x += 1 > return 2 * x > > Now we would have this reduction: > > f(7) > => > 7 += 1; return 2 * 7 > > because "x" would be bound to "7" everywhere in the function body. You know, people have developed further ways to talk about these things precisely because substitution semantics is inadequate for what they wanted to talk about. See references in that Wikipedia article (Felleisen might be to the point. The field is called denotational semantics.) The description, in the language reference (or is it the library reference), of how Python function calls are evaluated can be seen as an example. First the actual arguments and possibly some defaults are put in fresh locations, then the formal parameters are bound to these in an order that is a bit complicated because of keyword parameters and such, but nevertheless *bound* *then*. Not substituted to the program text - who would even think that? And then the evaluation of the occurrences of the parameters in the code of the function goes through *these* bindings rather than any other bindings that might be in effect elsewhere in the program, including any pending calls of the same function. From ned at nedbatchelder.com Wed Nov 25 10:13:41 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 25 Nov 2015 07:13:41 -0800 (PST) Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, November 25, 2015 at 8:20:59 AM UTC-5, BartC wrote: > Accept that some things /are/ a source of confusion. When, in writing > documentation, I find something hard to explain something, then I try > and make it simpler in the program. But not enough of that goes on: it > seems to be more lucrative to write thicker user manuals, and provide > longer training courses, than to make software simpler. You seem to be insinuating that someone has made Python unusually complex for personal gain? I'm not sure what to do with that: it's an absurd claim. > > "Why does the loop run forever?" > > > > The coin doesn't magically toss itself, no matter how intuitively obvious it > > is that it should. > > The concept of variables doesn't take long to learn in an 'ordinary' > language. There is a natural tension between making a language simple enough that it has no surprises or difficult parts; and making a language rich enough that it can be used for building serious systems. If you have another language to propose as a better beginner's learning language, please propose it. I think it serves beginners better to teach them with a language that they can then go on to use for building real things. Is there a real language (an "ordinary" language) that you think is better than Python for that? Empirical evidence in the world says, "not really." I know you have languages of your own, and that you like the way they work better. We have no way of evaluating their power or simplicity, since they are not available to us. I agree with you: there are things about Python that surprise people. That's because it's a programming language, and very very little about programming languages is obvious. The best we can hope for is "familiar," and even then, familiar to who? High school algebra students will at first be baffled by "x = x + 1", an equation which is clearly unsatisfiable. So yes, there are parts of Python that are hard, and surprising. There are subtleties that require study and careful thought. We believe that on the balance, Python is better than many of the alternatives. You are welcome to disagree, but don't be surprised if you encounter vigorous counter-arguments in a Python mailing list! There isn't much we can do about the structure of the language, certainly not the parts that have been discussed in this thread. The best we can do is try to explain it better. --Ned. From zachary.ware+pylist at gmail.com Wed Nov 25 10:58:20 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 25 Nov 2015 09:58:20 -0600 Subject: Futex hang when running event loop on a separated thread In-Reply-To: References: Message-ID: On Wed, Nov 25, 2015 at 8:10 AM, Marc Aymerich wrote: > problem solved ! > Just found out that threads should be started by fuse.init() in order > to run when fuse is backgrounded. Glad you found it; I would not have, not being a pyfuse user :) -- Zach From lac at openend.se Wed Nov 25 10:59:31 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 25 Nov 2015 16:59:31 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201511251559.tAPFxVm6020346@fido.openend.se> In a message of Wed, 25 Nov 2015 07:13:41 -0800, Ned Batchelder writes: >That's because it's a programming language, and very very little about >programming languages is obvious. The best we can hope for is "familiar," >and even then, familiar to who? High school algebra students will at >first be baffled by "x = x + 1", an equation which is clearly >unsatisfiable. The great sticking point for the children I am teaching is '*' means multiplication. You can really see that some people have to make extensive mental modifications in order to handle the concept that mathematical truths are expressed in linguistic and orthographic conventions, and that one can swap out a particular convention 'x means multiply' and swap in another one '* means multiply' while leaving the underlying truth unchanged. Laura From xapwing at gmail.com Wed Nov 25 11:12:58 2015 From: xapwing at gmail.com (Arie van Wingerden) Date: Wed, 25 Nov 2015 17:12:58 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: >and even then, familiar to who? High school algebra students will at >first be baffled by "x = x + 1", an equation which is clearly >unsatisfiable. Some languages are "better" in that specific case in my opinion (mind te double quotes :-) - Ada and Pascal use := instead of = which is simpler to grasp for n00bs (I think) - Erlang uses pattern matching. So when left hand side does NOT right hand side, yuou get an exception. Each variable can be only assigned once and only once. That is the most purely mathematical approach (I think) - Haskell 2015-11-25 16:13 GMT+01:00 Ned Batchelder : > On Wednesday, November 25, 2015 at 8:20:59 AM UTC-5, BartC wrote: > > Accept that some things /are/ a source of confusion. When, in writing > > documentation, I find something hard to explain something, then I try > > and make it simpler in the program. But not enough of that goes on: it > > seems to be more lucrative to write thicker user manuals, and provide > > longer training courses, than to make software simpler. > > You seem to be insinuating that someone has made Python unusually complex > for personal gain? I'm not sure what to do with that: it's an absurd > claim. > > > > "Why does the loop run forever?" > > > > > > The coin doesn't magically toss itself, no matter how intuitively > obvious it > > > is that it should. > > > > The concept of variables doesn't take long to learn in an 'ordinary' > > language. > > There is a natural tension between making a language simple enough that > it has no surprises or difficult parts; and making a language rich > enough that it can be used for building serious systems. > > If you have another language to propose as a better beginner's learning > language, please propose it. I think it serves beginners better to > teach them with a language that they can then go on to use for building > real things. Is there a real language (an "ordinary" language) that > you think is better than Python for that? Empirical evidence in the > world says, "not really." > > I know you have languages of your own, and that you like the way they > work better. We have no way of evaluating their power or simplicity, > since they are not available to us. > > I agree with you: there are things about Python that surprise people. > That's because it's a programming language, and very very little about > programming languages is obvious. The best we can hope for is "familiar," > and even then, familiar to who? High school algebra students will at > first be baffled by "x = x + 1", an equation which is clearly > unsatisfiable. > > So yes, there are parts of Python that are hard, and surprising. There > are subtleties that require study and careful thought. We believe that > on the balance, Python is better than many of the alternatives. You > are welcome to disagree, but don't be surprised if you encounter > vigorous counter-arguments in a Python mailing list! > > There isn't much we can do about the structure of the language, certainly > not the parts that have been discussed in this thread. The best we can > do is try to explain it better. > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed Nov 25 11:29:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 03:29:41 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Nov 26, 2015 at 2:13 AM, Ned Batchelder wrote: > I agree with you: there are things about Python that surprise people. > That's because it's a programming language, and very very little about > programming languages is obvious. The best we can hope for is "familiar," > and even then, familiar to who? High school algebra students will at > first be baffled by "x = x + 1", an equation which is clearly > unsatisfiable. And then *lots* of people are confused by "x += 1" being almost, but not entirely, identical to the above. Actually, if there were one change I could make to Python, it would be to redefine the augmented assignment operators to be semantically identical to their expanded forms; there might be some optimizations, but absolutely no difference in effect. (Which would mean, among other things, that it would be a very bad way to append to a list, instead of being an alias for .extend.) ChrisA From marko at pacujo.net Wed Nov 25 11:44:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 18:44:42 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> <87egfent2i.fsf@elektro.pacujo.net> Message-ID: <877fl66nb9.fsf@elektro.pacujo.net> Jussi Piitulainen : > Marko Rauhamaa writes: >> As far as the words "variable" and "binding" go, they are present in >> lambda calculus (1929 and on): > > So it's more than ten years earlier than I thought. Old enough, > anyway. Strictly speaking, that a Wikipedia article uses the words > "variable" and "binding" to discuss lambda calculi today is not a > proof that Church used those words in his time. I'm inclined to > believe he did. (Our CS department had a copy of Church's book. It > smelled funny.) I haven't even smelled the originals, but the formalization of variable substitution was *the* big selling point for lambda calculus. Previously, combinatory logic solved the age-old problem with variables by eliminating them altogether: Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. >> Now we would have this reduction: >> >> f(7) >> => >> 7 += 1; return 2 * 7 >> >> because "x" would be bound to "7" everywhere in the function body. > > You know, people have developed further ways to talk about these things > precisely because substitution semantics is inadequate for what they > wanted to talk about. "Assignment" is what everybody uses and understands. > Not substituted to the program text - who would even think that? Actually, if Scheme didn't possess set! et al, we would be talking about true binding. For example, the function (define (sum numbers) (let loop ((total 0) (remaining numbers)) (if (null? remaining) total (loop (+ total (car remaining)) (cdr remaining))))) can be described and effectively implemented using true, syntactic binding. To execute such code, you start with an expression, say, (sum '(1 2 3 4 5)) and keep on rewriting the expression until you can't rewrite it anymore. The availability of set! forces the implementation to generate a memory slot for each binding, turning the binding semantics into an assignment semantics. Marko From bc at freeuk.com Wed Nov 25 12:18:44 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 17:18:44 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/11/2015 15:13, Ned Batchelder wrote: > On Wednesday, November 25, 2015 at 8:20:59 AM UTC-5, BartC wrote: >> Accept that some things /are/ a source of confusion. When, in writing >> documentation, I find something hard to explain something, then I try >> and make it simpler in the program. But not enough of that goes on: it >> seems to be more lucrative to write thicker user manuals, and provide >> longer training courses, than to make software simpler. > > You seem to be insinuating that someone has made Python unusually complex > for personal gain? I'm not sure what to do with that: it's an absurd > claim. Actually I was thinking of certain Microsoft products. But I think my point stands: the design of software could be influenced more by the documentation. In the case of languages, that's perhaps harder because languages tend to evolve, and they usually have to be backwards compatible. >>> "Why does the loop run forever?" >>> >>> The coin doesn't magically toss itself, no matter how intuitively obvious it >>> is that it should. >> >> The concept of variables doesn't take long to learn in an 'ordinary' >> language. > There is a natural tension between making a language simple enough that > it has no surprises or difficult parts; and making a language rich > enough that it can be used for building serious systems. Well, with Python I get the impression it's gone too far. Too many things are dynamic for the sake of it, and people are perhaps tempted to make too much use of that. Although I do find Python's design interesting, from a language design and implementation point of view. It looks deceptively simple... > I know you have languages of your own, and that you like the way they > work better. We have no way of evaluating their power or simplicity, > since they are not available to us. My language, while simpler, has its own problems. And I don't want to get into support (I've done that in the past with other languages). So at present, I'd probably still recommend Python, although there is also the similar Ruby and the smaller language Lua. There a few others but I haven't tried them. > We have no way of evaluating their power or simplicity, > since they are not available to us. I'll see if I can rustle up a comparison so that Python users can see what they're missing! -- Bartc From steve at pearwood.info Wed Nov 25 12:40:09 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 26 Nov 2015 04:40:09 +1100 Subject: What is a function parameter =[] for? References: <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Nov 2015 08:56 pm, Antoon Pardon wrote: > Since (x, y, z) is not a fixed value, it is not a literal. Right. And therefore, (x, y, z) syntax is not syntax for a literal. Hence why the Python docs call it a tuple display instead of a tuple literal -- no matter what x, y, z are. Even if they themselves are literals, that's just a special case that *some* compiler versions may be able to handle. You call this "picking nits", but if so, they are nits that are twice the size of an an elephant and painted bright yellow. Your language arguing about "tuple literals" seems to be based on the idea that it is usually a constant and that cases like (x+1, y+2) is some unusual, rare corner case -- what you call "nits". Its not. The most general case is that a tuple display is an expression which, after evaluation, constructs a tuple. Those few cases where the compiler can optimize it into a constant are the nits, not the majority of cases when it can't. In fact, it's easy to find cases even now where the compiler is insufficiently smart to recognise all the possible optimizations available. There's no tuple simpler than the empty tuple, but Python 3.3 at least fails to optimize that case: py> dis(compile("()", '', 'eval')) 1 0 BUILD_TUPLE 0 3 RETURN_VALUE The bottom line is, *in general*, the terms "tuple literal", "list literal", "dict literal" etc. are inappropriate and incorrect, which is why the docs correctly distinguish them from actual literals by calling them "displays". -- Steven From ian.g.kelly at gmail.com Wed Nov 25 12:44:35 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Nov 2015 10:44:35 -0700 Subject: list slice and generators In-Reply-To: References: <5654D8CE.2020105@gmail.com> Message-ID: On Wed, Nov 25, 2015 at 3:07 AM, Peter Otten <__peter__ at web.de> wrote: > to get down to one intermediate list. Avoiding the last one is a bit tricky: > > metrics = (converter(x.metric(name)) for x in self._server_per_proc) > metrics = (x for x in metrics if x is not None) > try: > # if there is at least one item the generator is not empty > first = next(metrics) > except StopIteration: > metrics = () > else: > # put the first item back in > metrics = itertools.chain([first], metrics) > assert metrics metrics is always going to be an itertools.chain object at this assert, so how could the assertion ever fail? >> elif name in METRICS_AVG: > # writing a function that calculates the average without > # materialising the list left as an exercise ;) metrics = itertools.tee(metrics) return int(sum(metrics[0]) / len(metrics[1])) From ian.g.kelly at gmail.com Wed Nov 25 12:45:54 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Nov 2015 10:45:54 -0700 Subject: list slice and generators In-Reply-To: References: <5654D8CE.2020105@gmail.com> Message-ID: On Wed, Nov 25, 2015 at 10:44 AM, Ian Kelly wrote: > On Wed, Nov 25, 2015 at 3:07 AM, Peter Otten <__peter__ at web.de> wrote: >>> elif name in METRICS_AVG: >> # writing a function that calculates the average without >> # materialising the list left as an exercise ;) > > metrics = itertools.tee(metrics) > return int(sum(metrics[0]) / len(metrics[1])) Actually, don't do that. It does effectively materialize the list, just not as a list. From ian.g.kelly at gmail.com Wed Nov 25 13:03:51 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Nov 2015 11:03:51 -0700 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Nov 25, 2015 at 10:18 AM, BartC wrote: >> We have no way of evaluating their power or simplicity, >> since they are not available to us. > > I'll see if I can rustle up a comparison so that Python users can see what > they're missing! Unless you're going to make the actual languages available for public use, what's the point? From steve at pearwood.info Wed Nov 25 13:09:13 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 26 Nov 2015 05:09:13 +1100 Subject: Multiplication [was Re: Late-binding of function defaults] References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5655f94b$0$1583$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 02:59 am, Laura Creighton wrote: > The great sticking point for the children I am teaching is > '*' means multiplication. You can really see that some people > have to make extensive mental modifications in order to handle > the concept that mathematical truths are expressed in linguistic > and orthographic conventions, and that one can swap out a particular > convention 'x means multiply' and swap in another one '* means > multiply' while leaving the underlying truth unchanged. Wow. What age children are you talking about? I wasn't introduced to programming in any real depth until uni, after graduating secondary school. I had lots of problems understanding bits of it, and so did many of my fellow students, but * for multiplication wasn't one of them. But by this time, we had already learned in secondary school that you can use any of the following to write multiplication: x ? y x ? y x y just as you can write division as: x / y x ? y Adding * to the list of ways to write multiplication wasn't hard. And I don't remember anyone having conceptual difficulty learning that xy is a short-cut for x?y in maths class. -- Steven From __peter__ at web.de Wed Nov 25 13:22:39 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Nov 2015 19:22:39 +0100 Subject: list slice and generators References: <5654D8CE.2020105@gmail.com> Message-ID: Ian Kelly wrote: >>assert metrics > > metrics is always going to be an itertools.chain object at this > assert, so how could the assertion ever fail? Should an assertion ever fail? >From your reaction I conclude that it was puzzling and a comment like # always true in a boolean context would have been the better choice. The problem I was half-heartedly addressing is that >>> if not metrics: >>> return None "works" for empty lists but not for "empty" iterators. If it were my code I'd probably allow the average calculation to raise an exception and the sum to return 0, but there's always a limit to changing other people's code. From __peter__ at web.de Wed Nov 25 13:26:57 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Nov 2015 19:26:57 +0100 Subject: list slice and generators References: <5654D8CE.2020105@gmail.com> Message-ID: Ian Kelly wrote: > On Wed, Nov 25, 2015 at 10:44 AM, Ian Kelly wrote: >> On Wed, Nov 25, 2015 at 3:07 AM, Peter Otten <__peter__ at web.de> wrote: >>>> elif name in METRICS_AVG: >>> # writing a function that calculates the average without >>> # materialising the list left as an exercise ;) >> >> metrics = itertools.tee(metrics) >> return int(sum(metrics[0]) / len(metrics[1])) > > Actually, don't do that. It does effectively materialize the list, > just not as a list. Not just that, it will also complain >>> a, b = itertools.tee([1,2,3]) >>> sum(a), len(b) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'itertools._tee' has no len() From antoon.pardon at rece.vub.ac.be Wed Nov 25 13:27:56 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 19:27:56 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5655FDAC.4070305@rece.vub.ac.be> Op 25-11-15 om 18:40 schreef Steven D'Aprano: > On Wed, 25 Nov 2015 08:56 pm, Antoon Pardon wrote: > >> Since (x, y, z) is not a fixed value, it is not a literal. > > Right. And therefore, (x, y, z) syntax is not syntax for a literal. Hence > why the Python docs call it a tuple display instead of a tuple literal -- > no matter what x, y, z are. Even if they themselves are literals, that's > just a special case that *some* compiler versions may be able to handle. > > You call this "picking nits", but if so, they are nits that are twice the > size of an an elephant and painted bright yellow. Your language arguing > about "tuple literals" seems to be based on the idea that it is usually a > constant and that cases like (x+1, y+2) is some unusual, rare corner > case -- what you call "nits". I don't know what you are talking about. The first thing I have argued is that () is a literal. Then I have expaned that to that something like (3, 5, 8) is a literal. I never argued that tuple expressions in general are literals. And one way I supported my point was with the following quote from the python language reference. Literals are notations for constant values of some built-in types. And I think that the things I argued were literals, were in fact constant values of some built-in type. > Its not. The most general case is that a > tuple display is an expression which, after evaluation, constructs a tuple. > Those few cases where the compiler can optimize it into a constant are the > nits, not the majority of cases when it can't. The nits, depend on what someone tries to argue. Since I didn't try to argue that tuple displays in general are literals but argued for very specific tuple values to be literals, you starting about tuple displays is going of on a tangent that has little to do with what I was arguing. -- Antoon From harvest at should.be.invalid Wed Nov 25 13:30:07 2015 From: harvest at should.be.invalid (Jussi Piitulainen) Date: Wed, 25 Nov 2015 20:30:07 +0200 Subject: What is a function parameter =[] for? References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> <87egfent2i.fsf@elektro.pacujo.net> <877fl66nb9.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> You know, people have developed further ways to talk about these >> things precisely because substitution semantics is inadequate for >> what they wanted to talk about. > > "Assignment" is what everybody uses and understands. You can tell that to those who insist otherwise, and to those who understand it differently, and to those who are just confused. All are around in this thread. But yes, I would find it easier if variables could be called variables, assignment could be called assignment, and binding could be called binding even in Python (variations of the last one somewhat work; the former two are problematic in the way that any mention of regular expressions is, whether you've noticed it or not). >> Not substituted to the program text - who would even think that? > > Actually, if Scheme didn't possess set! et al, we would be talking > about true binding. For example, the function > > (define (sum numbers) > (let loop ((total 0) (remaining numbers)) > (if (null? remaining) > total > (loop (+ total (car remaining)) (cdr remaining))))) > > can be described and effectively implemented using true, syntactic > binding. To execute such code, you start with an expression, say, > (sum '(1 2 3 4 5)) and keep on rewriting the expression until you can't > rewrite it anymore. Interesting. Can you just keep reducing / expanding the expression without reference to an environment? I see how it's easy to talk about assignment because one can talk about something else, but I'm not yet quite sure how you intend to handle recursion. ==> (let loop ((total 0) (remaining '(1 2 3 4 5))) (if (null? remaining) total (loop (+ total (car remaining)) (cdr remaining)))) Now what? Rewrite using a call-by-value fixed-point operator and keep insisting that you just saw a squirrel? Or rewrite with respect to an environment where loop is bound to a lambda expression that is closed in that same environment and this is somehow true substitution and you just saw a squirrel? Link to a Wikipedia page that tells what call-by-value and call-by-reference are and remind me that one should really talk about passing a reference by value? That last one is as irrelevant as squirrels, by the way. > The availability of set! forces the implementation to generate a > memory slot for each binding, turning the binding semantics into an > assignment semantics. Thank you. I'm probably out now. From lac at openend.se Wed Nov 25 13:45:10 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 25 Nov 2015 19:45:10 +0100 Subject: Multiplication [was Re: Late-binding of function defaults] In-Reply-To: <5655f94b$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <5655f94b$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201511251845.tAPIjAde022935@fido.openend.se> In a message of Thu, 26 Nov 2015 05:09:13 +1100, "Steven D'Aprano" writes: >On Thu, 26 Nov 2015 02:59 am, Laura Creighton wrote: > >> The great sticking point for the children I am teaching is >> '*' means multiplication. You can really see that some people >> have to make extensive mental modifications in order to handle >> the concept that mathematical truths are expressed in linguistic >> and orthographic conventions, and that one can swap out a particular >> convention 'x means multiply' and swap in another one '* means >> multiply' while leaving the underlying truth unchanged. > >Wow. What age children are you talking about? 12 and 13 and 14 year olds. Smart 12, 13 and 14 year olds. They want to build web servers and host pictures of their pets. and use the gimp to do image manipulation like crazy. They are as interested in art as much as, or perhaps even more so than in programming -- they just need to learn enough programming to get to make the art and serve it up. Designing your own Magic The Gathering cards, which has manipulated pictures of your friends on them, and then using them to play games with said friends has been the craze since September. It's not that the idea of we will use '*' is hard, but if you have never thought about the difference between THE TRUTH and the notation used to express the truth before, then well, you may need some time to get used to the idea. Laura From bc at freeuk.com Wed Nov 25 13:48:44 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 18:48:44 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/11/2015 18:03, Ian Kelly wrote: > On Wed, Nov 25, 2015 at 10:18 AM, BartC wrote: >>> We have no way of evaluating their power or simplicity, >>> since they are not available to us. >> >> I'll see if I can rustle up a comparison so that Python users can see what >> they're missing! > > Unless you're going to make the actual languages available for public > use, what's the point? For ideas? Sometimes it's interesting to know about other approaches to a feature or new ones that can be useful. Then someone else can implement them! I'd be sharing my language design ideas not my amateurish implementations. (Which aren't easy to distribute anyway because they are implemented in themselves.) -- Bartc From emile at fenx.com Wed Nov 25 13:51:12 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 25 Nov 2015 10:51:12 -0800 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <5655A8B3.6000103@rece.vub.ac.be> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <5655A8B3.6000103@rece.vub.ac.be> Message-ID: On 11/25/2015 4:25 AM, Antoon Pardon wrote: > I think there are reasons to find the above behaviour bizarre. I personnaly > don't find it bizarre, but that is because I'm familiar with what is going > on. Which I suspect is necessary. >but if someone expects the compilor to take a snapshot of L and iterate > over that I am not going to say he shouldn't have expected that. That's something I've learned to figure out about any new language I pick up -- if parameters are passed by value or by reference, and secondly how to invoke a function appropriately for my specific use case. Unfortunately, there are issues determining if python is in either camp, which certainly leads to confusion. see http://www.python-course.eu/passing_arguments.php or google "python pass by value or reference" for more examples. Emile From emile at fenx.com Wed Nov 25 13:56:43 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 25 Nov 2015 10:56:43 -0800 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/25/2015 5:20 AM, BartC wrote: > it seems to be more lucrative to write thicker user manuals, and provide > longer training courses, than to make software simpler. If that were true, certainly by now the sufficiently thick manual would provide crystal clear explanations. :) I-don't-think-obfustication-is-the-point-ly y'rs, Emile From ben+python at benfinney.id.au Wed Nov 25 14:55:24 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 Nov 2015 06:55:24 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <878u5mns8z.fsf@elektro.pacujo.net> Message-ID: <858u5lc0r7.fsf@benfinney.id.au> Chris Angelico writes: > This is a distinction I generally make. Putting it another way: a list > has the same meaning regardless of how many items are on it (for > instance, a shopping list is still a shopping list whether it has five > or fifty items on it), where a tuple is a package where each element > has a specific meaning [?] Yes. The disctinction is even clearer, I find, by saying that the *meaning of the position* in the sequence is significant for a tuple, not significant for a list. That is, the ?2? in ?cartesian_point = (2, 3)? means something different than in ?cartesian_point = (3, 2)?. Whereas the ?2? in ?test_scores = [2, 3]? means exactly the same as in ?test_scores = [3, 2]?. If each position in the sequence gives the value there a different menaning, use a tuple; if not, use a list. > Nothing in the language enforces this, but the mutability of lists > does tend to align well with things that can grow and shrink, and the > immutability of tuples makes them more like strings or complex numbers > (in fact, a complex number is basically a tuple of two floats). Not only the growing and shrinking, but the re-ordering of items in a list should not change the meaning of its items. If you can ?sort? the sequence and the items still mean exactly what they did before, then a tuple is the wrong type to use, semantically. -- \ ?Crime is contagious? if the government becomes a lawbreaker, | `\ it breeds contempt for the law.? ?Justice Louis Brandeis | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Nov 25 14:57:17 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 Nov 2015 06:57:17 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <201511251559.tAPFxVm6020346@fido.openend.se> Message-ID: <854mg9c0o2.fsf@benfinney.id.au> Laura Creighton writes: > The great sticking point for the children I am teaching is '*' means > multiplication. [?] that one can swap out a particular convention 'x > means multiply' and swap in another one '* means multiply' while > leaving the underlying truth unchanged. Perhaps it would be easier if you point out that ?x? doesn't mean multiply either, and they've *already* been substituting that symbol instead of the correct ??? for multiply. -- \ ?Our task must be to free ourselves from our prison by widening | `\ our circle of compassion to embrace all humanity and the whole | _o__) of nature in its beauty.? ?Albert Einstein | Ben Finney From Cecil at decebal.nl Wed Nov 25 15:23:05 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 25 Nov 2015 21:23:05 +0100 Subject: Help needed with compiling python Message-ID: <877fl596c6.fsf@Equus.decebal.nl> I wanted to install python myself. I started with 2.7.10. If that works I also will install 3.5.0. I did: ./configure --prefix=/usr make make altinstall I have: /usr/bin/python2.7 But when I execute this, I get: Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] Python 2.7.10 (default, Nov 25 2015, 20:58:29) [GCC 4.8.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "/etc/pythonstart", line 7, in import readline ImportError: No module named readline What do I need to do to get it working? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From francisfunari at hotmail.com Wed Nov 25 15:34:01 2015 From: francisfunari at hotmail.com (francis funari) Date: Wed, 25 Nov 2015 20:34:01 +0000 Subject: Python on windows 10 Message-ID: I have tried installing Python 3 on windows 10 it install OK but I do not get Idle. When I type Idle in the interpreter nothing happen can you send me a link to latest release of Python 3 with Idle that will run on windows 10 64 bit Thankyou Francis Funari Sent from Mail for Windows 10 From ian.g.kelly at gmail.com Wed Nov 25 15:39:44 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Nov 2015 13:39:44 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <5655FDAC.4070305@rece.vub.ac.be> References: <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> <5654B037.6020107@rece.vub.ac.be> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <5655FDAC.4070305@rece.vub.ac.be> Message-ID: On Wed, Nov 25, 2015 at 11:27 AM, Antoon Pardon wrote: > I don't know what you are talking about. The first thing I have argued > is that () is a literal. Then I have expaned that to that something > like (3, 5, 8) is a literal. I never argued that tuple expressions > in general are literals. And one way I supported my point was with the > following quote from the python language reference. > > Literals are notations for constant values of some built-in types. > > And I think that the things I argued were literals, were in fact > constant values of some built-in type. I believe that sentence from the docs is using "some" to mean "not all", whereas you are apparently using it to mean "any". frozenset([1,2,3]) constructs a constant value of a built-in type. Would you consider that a literal? How about tuple(1, 2+3, abs(-19))? Still a constant value of a built-in type. I think the most important word in the definition you quoted is actually "notation". It says it right there: literals are not "constant values", but notations for *expressing* constant values. The tuple display notation expresses values that may be constant but need not be. Therefore it's not a literal notation. From ryanshuell at gmail.com Wed Nov 25 15:42:00 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 25 Nov 2015 12:42:00 -0800 (PST) Subject: Screen scraper to get all 'a title' elements Message-ID: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> Hello experts. I'm looking at this url: https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names I'm trying to figure out how to list all 'a title' elements. For instance, I see the following: Accident Ala-Lemu Alert Apocalypse Peaks So, I tried putting a script together to get 'title'. Here's my attempt. import requests import sys from bs4 import BeautifulSoup url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" source_code = requests.get(url) plain_text = source_code.text soup = BeautifulSoup(plain_text) for link in soup.findAll('title'): print(link) All that does is get the title of the page. I tried to get the links from that url, with this script. import urllib2 import re #connect to a URL website = urllib2.urlopen('https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names') #read html code html = website.read() #use re.findall to get all the links links = re.findall('"((http|ftp)s?://.*?)"', html) print links That doesn't work wither. Basically, I'd like to see this. Accident Ala-Lemu Alert Apocalypse Peaks Athol ? Barbecue B?stad Bastardstown Batman Bathmen (Battem), Netherlands ... Worms Yell Zigzag Zzyzx How can I do that? Thanks all!! From pavlos.parissis at gmail.com Wed Nov 25 15:43:20 2015 From: pavlos.parissis at gmail.com (Pavlos Parissis) Date: Wed, 25 Nov 2015 21:43:20 +0100 Subject: list slice and generators In-Reply-To: References: <5654D8CE.2020105@gmail.com> Message-ID: <56561D68.9080901@gmail.com> On 25/11/2015 11:07 ??, Peter Otten wrote: > Pavlos Parissis wrote: > >> Hi, >> >> Do you see any possible dangerous hidden bug in the below code(using >> python2.7 and python3.4)? >> >> My goal is to avoid go through the metrics list twice. But, I don't >> know if there will be a problem with doing in place replace of list >> elements using 2 generators. >> >> # metrics = ['', '0', '10'....] >> metrics = [x.metric(name) for x in self._server_per_proc] >> metrics[:] = (converter(x) for x in metrics) >> metrics[:] = (x for x in metrics if x is not None) > > Both generators are executed immediately, and the right side is always > evaluated before the the slice assignment. Try > This is what I was vaguely remembering, thanks for the confirmation. > metrics = (x.metric(name) for x in self._server_per_proc) > metrics = (converter(x) for x in metrics) > metrics = [x for x in metrics if x is not None] > I see you prefer to bind the result of the evaluation to the same variable. I learned (the hard way) that it could lead to problems where:: In [1]: a = [1, 2, 3] In [2]: b = a In [3]: a == b, a is b Out[3]: (True, True) In [4]: a = (x for x in a if x >1) In [5]: a == b, a is b Out[5]: (False, False) In [6]: a Out[6]: at 0x7f7f8b7400d8> In [7]: list(a) Out[7]: [2, 3] In [8]: a = [1, 2, 3] In [9]: b = a In [10]: a == b, a is b Out[10]: (True, True) In [11]: a = [x for x in a if x >1] In [12]: a == b, a is b Out[12]: (False, False) In [13]: a Out[13]: [2, 3] In [14]: b Out[14]: [1, 2, 3] Thus, I always use slice assignment, even when above case isn't applied. > or > > metrics = (converter(x.metric(name)) for x in self._server_per_proc) > metrics = [x for x in metrics if x is not None] > I should do the above. > to get down to one intermediate list. Avoiding the last one is a bit tricky: > > metrics = (converter(x.metric(name)) for x in self._server_per_proc) > metrics = (x for x in metrics if x is not None) > try: > # if there is at least one item the generator is not empty > first = next(metrics) > except StopIteration: > metrics = () > else: > # put the first item back in > metrics = itertools.chain([first], metrics) > assert metrics > Tricky, indeed Thanks for your time and effort to answer my question, it is very much appreciated. Cheers, Pavlos -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From zachary.ware+pylist at gmail.com Wed Nov 25 15:49:16 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 25 Nov 2015 14:49:16 -0600 Subject: Help needed with compiling python In-Reply-To: <877fl596c6.fsf@Equus.decebal.nl> References: <877fl596c6.fsf@Equus.decebal.nl> Message-ID: On Wed, Nov 25, 2015 at 2:23 PM, Cecil Westerhof wrote: > I wanted to install python myself. I started with 2.7.10. If that > works I also will install 3.5.0. > > I did: > ./configure --prefix=/usr > make > make altinstall > > I have: > /usr/bin/python2.7 > > But when I execute this, I get: > Could not find platform dependent libraries > Consider setting $PYTHONHOME to [:] > Python 2.7.10 (default, Nov 25 2015, 20:58:29) > [GCC 4.8.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > Traceback (most recent call last): > File "/etc/pythonstart", line 7, in > import readline > ImportError: No module named readline > > What do I need to do to get it working? First off, I strongly suggest not using --prefix=/usr. Stick with --prefix=/usr/local (the default) to avoid overwriting the system Python, which may differ from a source build (and, in fact, overwriting your system Python may be what's causing some of your problems; those first two lines are worrying). Secondly, there are several optional modules that are not compiled unless particular libraries are found to link against, including readline. You'll need the readline development package (probably readline-dev or readline-devel, depending on your distribution). You can quickly pull in the dependencies for all optional modules by doing something like the following for an apt-based system: `apt-get build-dep python3`. Hope this helps, -- Zach From breamoreboy at yahoo.co.uk Wed Nov 25 15:50:38 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 25 Nov 2015 20:50:38 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/11/2015 17:18, BartC wrote: > On 25/11/2015 15:13, Ned Batchelder wrote: >> On Wednesday, November 25, 2015 at 8:20:59 AM UTC-5, BartC wrote: >>> Accept that some things /are/ a source of confusion. When, in writing >>> documentation, I find something hard to explain something, then I try >>> and make it simpler in the program. But not enough of that goes on: it >>> seems to be more lucrative to write thicker user manuals, and provide >>> longer training courses, than to make software simpler. >> >> You seem to be insinuating that someone has made Python unusually complex >> for personal gain? I'm not sure what to do with that: it's an absurd >> claim. > > Actually I was thinking of certain Microsoft products. But I think my > point stands: the design of software could be influenced more by the > documentation. In the case of languages, that's perhaps harder because > languages tend to evolve, and they usually have to be backwards compatible. > >>>> "Why does the loop run forever?" >>>> >>>> The coin doesn't magically toss itself, no matter how intuitively >>>> obvious it >>>> is that it should. >>> >>> The concept of variables doesn't take long to learn in an 'ordinary' >>> language. > >> There is a natural tension between making a language simple enough that >> it has no surprises or difficult parts; and making a language rich >> enough that it can be used for building serious systems. > > Well, with Python I get the impression it's gone too far. Too many > things are dynamic for the sake of it, and people are perhaps tempted to > make too much use of that. > > Although I do find Python's design interesting, from a language design > and implementation point of view. It looks deceptively simple... > > > I know you have languages of your own, and that you like the way they > > work better. We have no way of evaluating their power or simplicity, > > since they are not available to us. > > My language, while simpler, has its own problems. And I don't want to > get into support (I've done that in the past with other languages). > > So at present, I'd probably still recommend Python, although there is > also the similar Ruby and the smaller language Lua. There a few others > but I haven't tried them. > > > We have no way of evaluating their power or simplicity, > > since they are not available to us. > > I'll see if I can rustle up a comparison so that Python users can see > what they're missing! > Can you please let us know what you're taking, what it costs and where we can get it, as we would also like to live in cloud cuckoo land, provided that The Price Is Right?. Although credit where credit is due, you are one of the most successful trolls to con this list in years. I must offer my congratulations. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From clalancette at gmail.com Wed Nov 25 15:52:25 2015 From: clalancette at gmail.com (Chris Lalancette) Date: Wed, 25 Nov 2015 15:52:25 -0500 Subject: Looking for ideas to improve library API Message-ID: Hello, I'm currently developing a library called pyiso ( https://github.com/clalancette/pyiso), used for manipulating ISO disk images. I'm pretty far along with it, but there is one part of the API that I really don't like. Typical usage of the library is something like: import pyiso p = pyiso.PyIso() // create the object f = open('/path/to/original.iso', 'r') p.open(f) // parse all of the metadata from the input ISO fp = open('/path/to/file/to/add/to/iso', 'r') p.add_fp(fp) // add a new file to the ISO out = open('/path/to/modified.iso', 'w') p.write(out) // write out the modified ISO to another file out.close() fp.close() f.close() This currently works OK. The problem ends up being the file descriptor lifetimes. I want the user to be able to do multiple operations to the ISO, and I also don't want to read the entire ISO (and new files) into memory. That means that internal to the library, I take a reference to the file object that the user passes in during open() and add_fp(). This is fine, unless the user decides to close the file object before calling the write method, at which point the write complains of I/O to a closed file. This is especially problematic when it comes to using context managers, since the user needs to leave the context open until they call write(). I've thought of a couple ways to deal with this: 1. Make a copy of the file object internal to the library, using os.dup() to copy the file descriptor. This is kind of nasty, especially since I want to support other kinds of file objects (think StringIO). 2. Just document the fact that the user needs to leave the file objects open until they are done. This is simple, but not super user-friendly. I'm looking for any ideas of how to do this better, or something I missed. Any input is appreciated! Thanks, Chris Lalancette From python at mrabarnett.plus.com Wed Nov 25 15:55:56 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 25 Nov 2015 20:55:56 +0000 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> Message-ID: <5656205C.1030804@mrabarnett.plus.com> On 2015-11-25 20:42, ryguy7272 wrote: > Hello experts. I'm looking at this url: > https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names > > I'm trying to figure out how to list all 'a title' elements. For instance, I see the following: > Accident > Ala-Lemu > Alert > Apocalypse Peaks > > So, I tried putting a script together to get 'title'. Here's my attempt. > > import requests > import sys > from bs4 import BeautifulSoup > > url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" > source_code = requests.get(url) > plain_text = source_code.text > soup = BeautifulSoup(plain_text) > for link in soup.findAll('title'): > print(link) > > All that does is get the title of the page. I tried to get the links from that url, with this script. > A 'title' element has the form "". What you should be looking for are 'a' elements, those of the form "<a ...>". > import urllib2 > import re > > #connect to a URL > website = urllib2.urlopen('https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names') > > #read html code > html = website.read() > > #use re.findall to get all the links > links = re.findall('"((http|ftp)s?://.*?)"', html) > > print links > > That doesn't work wither. Basically, I'd like to see this. > > Accident > Ala-Lemu > Alert > Apocalypse Peaks > Athol > ? > Barbecue > B?stad > Bastardstown > Batman > Bathmen (Battem), Netherlands > ... > Worms > Yell > Zigzag > Zzyzx > > How can I do that? > Thanks all!! > > From marko at pacujo.net Wed Nov 25 16:00:55 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 23:00:55 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <201511251559.tAPFxVm6020346@fido.openend.se> <mailman.91.1448481614.20593.python-list@python.org> Message-ID: <877fl56bg8.fsf@elektro.pacujo.net> Ben Finney <ben+python at benfinney.id.au>: > Perhaps it would be easier if you point out that ?x? doesn't mean > multiply either, and they've *already* been substituting that symbol > instead of the correct ??? for multiply. In my childhood, we always used '?' for the multiplication sign until senior high school, when the vector product was introduced. I seem to recall ??? was used in cartesian products already in junior high. Marko From marko at pacujo.net Wed Nov 25 16:04:55 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 25 Nov 2015 23:04:55 +0200 Subject: Multiplication [was Re: Late-binding of function defaults] References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <mailman.77.1448467192.20593.python-list@python.org> <5655f94b$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8737vt6b9k.fsf@elektro.pacujo.net> Steven D'Aprano <steve at pearwood.info>: > But by this time, we had already learned in secondary school that you can > use any of the following to write multiplication: > > x ? y Not where I lived. (Those x's would have been a nightmare for the teacher who had to mark people's test answers.) > x ? y Yes. After all, it would never get mixed up with the decimal comma. > x y Not to multiply numbers with each other. > just as you can write division as: > > x / y Not where I lived. > x ? y Not that one, either. x We only had: --- y Marko From antoon.pardon at rece.vub.ac.be Wed Nov 25 16:05:30 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 25 Nov 2015 22:05:30 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <CALwzidkkuQDfGCZUmEDuvLEwLwy27BsDvPaow_LVN_tFYt-1qg@mail.gmail.com> References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <5655FDAC.4070305@rece.vub.ac.be> <CALwzidkkuQDfGCZUmEDuvLEwLwy27BsDvPaow_LVN_tFYt-1qg@mail.gmail.com> Message-ID: <5656229A.2000309@rece.vub.ac.be> Op 25-11-15 om 21:39 schreef Ian Kelly: > On Wed, Nov 25, 2015 at 11:27 AM, Antoon Pardon > <antoon.pardon at rece.vub.ac.be> wrote: >> I don't know what you are talking about. The first thing I have argued >> is that () is a literal. Then I have expaned that to that something >> like (3, 5, 8) is a literal. I never argued that tuple expressions >> in general are literals. And one way I supported my point was with the >> following quote from the python language reference. >> >> Literals are notations for constant values of some built-in types. >> >> And I think that the things I argued were literals, were in fact >> constant values of some built-in type. > > I believe that sentence from the docs is using "some" to mean "not > all", whereas you are apparently using it to mean "any". > > frozenset([1,2,3]) constructs a constant value of a built-in type. > Would you consider that a literal? I am inclined to say yes, because a sufficient intelligent compilor can compute the value and store it do be retrieved and bound to a target when needed. > How about tuple(1, 2+3, abs(-19))? Still a constant value of a built-in type. Same reasoning. > I think the most important word in the definition you quoted is > actually "notation". It says it right there: literals are not > "constant values", but notations for *expressing* constant values. And how does that make a difference? > The tuple display notation expresses values that may be constant but > need not be. Therefore it's not a literal notation. Not in general no. It doesn't imply that not any tuple display notation is a literal notation. Expression may be constant but need not be, that is no reason to claim that anything that is an expression can't be a literal. -- Antoon. From Cecil at decebal.nl Wed Nov 25 16:52:23 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 25 Nov 2015 22:52:23 +0100 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> Message-ID: <8737vt927c.fsf@Equus.decebal.nl> On Wednesday 25 Nov 2015 21:49 CET, Zachary Ware wrote: > On Wed, Nov 25, 2015 at 2:23 PM, Cecil Westerhof <Cecil at decebal.nl> wrote: >> I wanted to install python myself. I started with 2.7.10. If that >> works I also will install 3.5.0. >> >> I did: >> ./configure --prefix=/usr >> make >> make altinstall >> >> I have: >> /usr/bin/python2.7 >> >> But when I execute this, I get: Could not find platform dependent >> libraries <exec_prefix> Consider setting $PYTHONHOME to >> <prefix>[:<exec_prefix>] Python 2.7.10 (default, Nov 25 2015, >> 20:58:29) [GCC 4.8.5] on linux2 Type "help", "copyright", "credits" >> or "license" for more information. Traceback (most recent call >> last): File "/etc/pythonstart", line 7, in <module> import readline >> ImportError: No module named readline >> >> What do I need to do to get it working? > > First off, I strongly suggest not using --prefix=/usr. Stick with > --prefix=/usr/local (the default) to avoid overwriting the system > Python, which may differ from a source build (and, in fact, > overwriting your system Python may be what's causing some of your > problems; those first two lines are worrying). My system python was all-ready damaged: that is why I wanted to build myself. > Secondly, there are several optional modules that are not compiled > unless particular libraries are found to link against, including > readline. You'll need the readline development package (probably > readline-dev or readline-devel, depending on your distribution). You > can quickly pull in the dependencies for all optional modules by > doing something like the following for an apt-based system: `apt-get > build-dep python3`. It is an openSUSE system. I installed the readline with: zypper install readline-devel The strange thing is that it does mot compile anymore now. I get: Python build finished, but the necessary bits to build these modules were not found: _bsddb _tkinter bsddb185 dbm dl gdbm imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. I have to look into that. I still can install it, but get the same errors. I think I need a bit more time to solve it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From bc at freeuk.com Wed Nov 25 16:56:39 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 21:56:39 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <mailman.95.1448484677.20593.python-list@python.org> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> Message-ID: <n35amf$21o$1@dont-email.me> On 25/11/2015 20:50, Mark Lawrence wrote: > On 25/11/2015 17:18, BartC wrote: > Can you please let us know what you're taking, what it costs and where > we can get it, as we would also like to live in cloud cuckoo land, > provided that The Price Is Right?. And I would really like to know what your problem is. I'm interested in language design because that's what I've done on and off for over 30 years. And I'm discussing some design decisions in Python. > Although credit where credit is due, you are one of the most successful > trolls to con this list in years. I must offer my congratulations. If you think I'm a 'troll' then that's your business. But I'm not holding a gun to your head and forcing you to read my posts. From ryanshuell at gmail.com Wed Nov 25 17:04:08 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 25 Nov 2015 14:04:08 -0800 (PST) Subject: Screen scraper to get all 'a title' elements In-Reply-To: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> Message-ID: <a6f3a0a7-acc3-46db-a36b-c3d774293347@googlegroups.com> On Wednesday, November 25, 2015 at 3:42:21 PM UTC-5, ryguy7272 wrote: > Hello experts. I'm looking at this url: > https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names > > I'm trying to figure out how to list all 'a title' elements. For instance, I see the following: > <a title="Accident, Maryland" href="/wiki/Accident,_Maryland">Accident</a> > <a class="new" title="Ala-Lemu (page does not exist)" href="/w/index.php?title=Ala-Lemu&action=edit&redlink=1">Ala-Lemu</a> > <a title="Alert, Nunavut" href="/wiki/Alert,_Nunavut">Alert</a> > <a title="Apocalypse Peaks" href="/wiki/Apocalypse_Peaks">Apocalypse Peaks</a> > > So, I tried putting a script together to get 'title'. Here's my attempt. > > import requests > import sys > from bs4 import BeautifulSoup > > url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" > source_code = requests.get(url) > plain_text = source_code.text > soup = BeautifulSoup(plain_text) > for link in soup.findAll('title'): > print(link) > > All that does is get the title of the page. I tried to get the links from that url, with this script. > > import urllib2 > import re > > #connect to a URL > website = urllib2.urlopen('https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names') > > #read html code > html = website.read() > > #use re.findall to get all the links > links = re.findall('"((http|ftp)s?://.*?)"', html) > > print links > > That doesn't work wither. Basically, I'd like to see this. > > Accident > Ala-Lemu > Alert > Apocalypse Peaks > Athol > ? > Barbecue > B?stad > Bastardstown > Batman > Bathmen (Battem), Netherlands > ... > Worms > Yell > Zigzag > Zzyzx > > How can I do that? > Thanks all!! Ok, I guess that makes sense. So, I just tried the script below, and got nothing... import requests from bs4 import BeautifulSoup r = requests.get("https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names") soup = BeautifulSoup(r.content) print soup.find_all("a",{"title"}) From rosuav at gmail.com Wed Nov 25 17:06:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 09:06:26 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <5656229A.2000309@rece.vub.ac.be> References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <5655FDAC.4070305@rece.vub.ac.be> <CALwzidkkuQDfGCZUmEDuvLEwLwy27BsDvPaow_LVN_tFYt-1qg@mail.gmail.com> <5656229A.2000309@rece.vub.ac.be> Message-ID: <CAPTjJmpc+upayXctBei4ZC04vfgPQSpY0RfvG7jv-n4npViHBg@mail.gmail.com> On Thu, Nov 26, 2015 at 8:05 AM, Antoon Pardon <antoon.pardon at rece.vub.ac.be> wrote: > Op 25-11-15 om 21:39 schreef Ian Kelly: >> On Wed, Nov 25, 2015 at 11:27 AM, Antoon Pardon >> <antoon.pardon at rece.vub.ac.be> wrote: >>> I don't know what you are talking about. The first thing I have argued >>> is that () is a literal. Then I have expaned that to that something >>> like (3, 5, 8) is a literal. I never argued that tuple expressions >>> in general are literals. And one way I supported my point was with the >>> following quote from the python language reference. >>> >>> Literals are notations for constant values of some built-in types. >>> >>> And I think that the things I argued were literals, were in fact >>> constant values of some built-in type. >> >> I believe that sentence from the docs is using "some" to mean "not >> all", whereas you are apparently using it to mean "any". >> >> frozenset([1,2,3]) constructs a constant value of a built-in type. >> Would you consider that a literal? > > I am inclined to say yes, because a sufficient intelligent compilor > can compute the value and store it do be retrieved and bound to a > target when needed. Then you're using the word "literal" in a way that is flat wrong. It may be a constant, but it is not a literal. ChrisA From rosuav at gmail.com Wed Nov 25 17:10:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 09:10:43 +1100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <a6f3a0a7-acc3-46db-a36b-c3d774293347@googlegroups.com> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <a6f3a0a7-acc3-46db-a36b-c3d774293347@googlegroups.com> Message-ID: <CAPTjJmqTJ5f_WPZZM-gC3=iCCVOMHStmS8MKb3o_G29dwF4yBg@mail.gmail.com> On Thu, Nov 26, 2015 at 9:04 AM, ryguy7272 <ryanshuell at gmail.com> wrote: > Ok, I guess that makes sense. So, I just tried the script below, and got nothing... > > import requests > from bs4 import BeautifulSoup > > r = requests.get("https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names") > soup = BeautifulSoup(r.content) > print soup.find_all("a",{"title"}) The second argument to find_all is supposed to be a dict, not a set, and it's only useful if you want to put some restriction on the titles. To simply enumerate all the titles, try this: [a.get("title") for a in soup.find_all("a")] ChrisA From marko at pacujo.net Wed Nov 25 17:16:32 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 00:16:32 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> Message-ID: <87k2p54tdr.fsf@elektro.pacujo.net> BartC <bc at freeuk.com>: > I'm interested in language design because that's what I've done on and > off for over 30 years. And I'm discussing some design decisions in > Python. That *is* a fun ambition, useful or not. However, while I'm very choosy and critical when it comes to my programming tools, I'm extremely happy with the programming language options that are freely available. It would be very difficult to beat the existing options with expressive power or elegance. You seem to have been surprised with some advanced concepts and idioms in this discussion. Really, apart from its indentation syntax, Python offers no unique or even rare software engineering concepts (Python's emphasis duck-typing comes close to being distinctive). You'll find equivalents in quite many languages, and in active, money-making uses. > I'm not holding a gun to your head and forcing you to read my posts. Follow your own advice. Marko From snailcoder at retrosite.invalid Wed Nov 25 17:30:04 2015 From: snailcoder at retrosite.invalid (Grobu) Date: Wed, 25 Nov 2015 23:30:04 +0100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <mailman.96.1448484959.20593.python-list@python.org> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> Message-ID: <n35ckk$9q0$1@dont-email.me> Hi It seems that links on that Wikipedia page follow the structure : <a href="..." title="..."> You could extract a list of link titles with something like : re.findall( r'\<a[^>]+title="(.+?)"', html ) HTH, -Grobu- On 25/11/15 21:55, MRAB wrote: > On 2015-11-25 20:42, ryguy7272 wrote: >> Hello experts. I'm looking at this url: >> https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names >> >> I'm trying to figure out how to list all 'a title' elements. For >> instance, I see the following: >> <a title="Accident, Maryland" >> href="/wiki/Accident,_Maryland">Accident</a> >> <a class="new" title="Ala-Lemu (page does not exist)" >> href="/w/index.php?title=Ala-Lemu&action=edit&redlink=1">Ala-Lemu</a> >> <a title="Alert, Nunavut" href="/wiki/Alert,_Nunavut">Alert</a> >> <a title="Apocalypse Peaks" href="/wiki/Apocalypse_Peaks">Apocalypse >> Peaks</a> >> >> So, I tried putting a script together to get 'title'. Here's my attempt. >> >> import requests >> import sys >> from bs4 import BeautifulSoup >> >> url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" >> source_code = requests.get(url) >> plain_text = source_code.text >> soup = BeautifulSoup(plain_text) >> for link in soup.findAll('title'): >> print(link) >> >> All that does is get the title of the page. I tried to get the links >> from that url, with this script. >> > A 'title' element has the form "<title ...>". What you should be looking > for are 'a' elements, those of the form "<a ...>". > >> import urllib2 >> import re >> >> #connect to a URL >> website = >> urllib2.urlopen('https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names') >> >> >> #read html code >> html = website.read() >> >> #use re.findall to get all the links >> links = re.findall('"((http|ftp)s?://.*?)"', html) >> >> print links >> >> That doesn't work wither. Basically, I'd like to see this. >> >> Accident >> Ala-Lemu >> Alert >> Apocalypse Peaks >> Athol >> ? >> Barbecue >> B?stad >> Bastardstown >> Batman >> Bathmen (Battem), Netherlands >> ... >> Worms >> Yell >> Zigzag >> Zzyzx >> >> How can I do that? >> Thanks all!! From ian.g.kelly at gmail.com Wed Nov 25 17:38:27 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Nov 2015 15:38:27 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <5656229A.2000309@rece.vub.ac.be> References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <5655FDAC.4070305@rece.vub.ac.be> <CALwzidkkuQDfGCZUmEDuvLEwLwy27BsDvPaow_LVN_tFYt-1qg@mail.gmail.com> <5656229A.2000309@rece.vub.ac.be> Message-ID: <CALwzidngZMafqiWv-2dZPEsAP+5qVDST2fW0X8i5Y4m0YdJ3Uw@mail.gmail.com> On Wed, Nov 25, 2015 at 2:05 PM, Antoon Pardon <antoon.pardon at rece.vub.ac.be> wrote: > Op 25-11-15 om 21:39 schreef Ian Kelly: >> On Wed, Nov 25, 2015 at 11:27 AM, Antoon Pardon >> <antoon.pardon at rece.vub.ac.be> wrote: >>> I don't know what you are talking about. The first thing I have argued >>> is that () is a literal. Then I have expaned that to that something >>> like (3, 5, 8) is a literal. I never argued that tuple expressions >>> in general are literals. And one way I supported my point was with the >>> following quote from the python language reference. >>> >>> Literals are notations for constant values of some built-in types. >>> >>> And I think that the things I argued were literals, were in fact >>> constant values of some built-in type. >> >> I believe that sentence from the docs is using "some" to mean "not >> all", whereas you are apparently using it to mean "any". >> >> frozenset([1,2,3]) constructs a constant value of a built-in type. >> Would you consider that a literal? > > I am inclined to say yes, because a sufficient intelligent compilor > can compute the value and store it do be retrieved and bound to a > target when needed. I'm curious then what you think of this: from collections import namedtuple class Point(namedtuple("Point", "x y")): pass Point(17, 12) Still a constant, but not a built-in type. Would you consider that a literal? From zachary.ware+pylist at gmail.com Wed Nov 25 17:39:28 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 25 Nov 2015 16:39:28 -0600 Subject: Help needed with compiling python In-Reply-To: <8737vt927c.fsf@Equus.decebal.nl> References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> Message-ID: <CAKJDb-PZjpiZkgSGAgOW0wSENnGOqtwTNSq9HQdMJLcirdU7Og@mail.gmail.com> On Wed, Nov 25, 2015 at 3:52 PM, Cecil Westerhof <Cecil at decebal.nl> wrote: > My system python was all-ready damaged: that is why I wanted to build > myself. Then you should try to repair the system Python install via the system package manager. It's not worth the hassle to try to replace it; it almost certainly won't work for some strange corner case that won't bite you until 3 months from now. It's perfectly OK to have a second Python install in /usr/local, even of the same version as the system Python. > It is an openSUSE system. I installed the readline with: > zypper install readline-devel > > The strange thing is that it does mot compile anymore now. I get: > Python build finished, but the necessary bits to build these modules were not found: > _bsddb _tkinter bsddb185 > dbm dl gdbm > imageop sunaudiodev > To find the necessary bits, look in setup.py in detect_modules() for the module's name. Before you installed readline-devel, readline would have been listed there as well. It's ok to have modules listed there if you don't need those particular modules. Most of those are actually deprecated, and have been removed from Python 3. Of those that remain, _tkinter requires tcl-devel and tk-devel; dbm and gdbm require similarly named development packages (I have no experience with using dbm/gdbm). -- Zach From bc at freeuk.com Wed Nov 25 17:41:56 2015 From: bc at freeuk.com (BartC) Date: Wed, 25 Nov 2015 22:41:56 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87k2p54tdr.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> Message-ID: <n35dbc$ckb$1@dont-email.me> On 25/11/2015 22:16, Marko Rauhamaa wrote: > BartC <bc at freeuk.com>: > >> I'm interested in language design because that's what I've done on and >> off for over 30 years. And I'm discussing some design decisions in >> Python. > > That *is* a fun ambition, useful or not. (At the moment, it's mostly fun. But in the past I actually needed the languages to do my job (designing microprocessor hardware). The scripting languages came a bit later, to go with my 3D graphics applications.) > You seem to have been surprised with some advanced concepts and idioms > in this discussion. Really, apart from its indentation syntax, Python > offers no unique or even rare software engineering concepts (Python's > emphasis duck-typing comes close to being distinctive). You'll find > equivalents in quite many languages, and in active, money-making uses. Maybe you're too familiar with it. But the idea of /executing/ the function and other definitions in a file, instead of they just being there, is novel. -- Bartc From ryanshuell at gmail.com Wed Nov 25 17:48:40 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 25 Nov 2015 14:48:40 -0800 (PST) Subject: Screen scraper to get all 'a title' elements In-Reply-To: <n35ckk$9q0$1@dont-email.me> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> Message-ID: <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> On Wednesday, November 25, 2015 at 5:30:14 PM UTC-5, Grobu wrote: > Hi > > It seems that links on that Wikipedia page follow the structure : > <a href="..." title="..."> > > You could extract a list of link titles with something like : > re.findall( r'\<a[^>]+title="(.+?)"', html ) > > HTH, > > -Grobu- > > > On 25/11/15 21:55, MRAB wrote: > > On 2015-11-25 20:42, ryguy7272 wrote: > >> Hello experts. I'm looking at this url: > >> https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names > >> > >> I'm trying to figure out how to list all 'a title' elements. For > >> instance, I see the following: > >> <a title="Accident, Maryland" > >> href="/wiki/Accident,_Maryland">Accident</a> > >> <a class="new" title="Ala-Lemu (page does not exist)" > >> href="/w/index.php?title=Ala-Lemu&action=edit&redlink=1">Ala-Lemu</a> > >> <a title="Alert, Nunavut" href="/wiki/Alert,_Nunavut">Alert</a> > >> <a title="Apocalypse Peaks" href="/wiki/Apocalypse_Peaks">Apocalypse > >> Peaks</a> > >> > >> So, I tried putting a script together to get 'title'. Here's my attempt. > >> > >> import requests > >> import sys > >> from bs4 import BeautifulSoup > >> > >> url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" > >> source_code = requests.get(url) > >> plain_text = source_code.text > >> soup = BeautifulSoup(plain_text) > >> for link in soup.findAll('title'): > >> print(link) > >> > >> All that does is get the title of the page. I tried to get the links > >> from that url, with this script. > >> > > A 'title' element has the form "<title ...>". What you should be looking > > for are 'a' elements, those of the form "<a ...>". > > > >> import urllib2 > >> import re > >> > >> #connect to a URL > >> website = > >> urllib2.urlopen('https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names') > >> > >> > >> #read html code > >> html = website.read() > >> > >> #use re.findall to get all the links > >> links = re.findall('"((http|ftp)s?://.*?)"', html) > >> > >> print links > >> > >> That doesn't work wither. Basically, I'd like to see this. > >> > >> Accident > >> Ala-Lemu > >> Alert > >> Apocalypse Peaks > >> Athol > >> ? > >> Barbecue > >> B?stad > >> Bastardstown > >> Batman > >> Bathmen (Battem), Netherlands > >> ... > >> Worms > >> Yell > >> Zigzag > >> Zzyzx > >> > >> How can I do that? > >> Thanks all!! Thanks!! Is that regex? Can you explain exactly what it is doing? Also, it seems to pick up a lot more than just the list I wanted, but that's ok, I can see why it does that. Can you just please explain what it's doing??? From lac at openend.se Wed Nov 25 17:58:38 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 25 Nov 2015 23:58:38 +0100 Subject: Help needed with compiling python In-Reply-To: <8737vt927c.fsf@Equus.decebal.nl> References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> Message-ID: <201511252258.tAPMwcdp026898@fido.openend.se> In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof writes: > >My system python was all-ready damaged: that is why I wanted to build >myself. Your Suse system probably wants to use python for something. If your system python is damaged, you badly need to fix that, using the system package managers tools, before Suse does some sort of update on you, using the broken python, which damages more of your system. Laura From rosuav at gmail.com Wed Nov 25 18:06:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 10:06:21 +1100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> Message-ID: <CAPTjJmogm7sc8m=czauTNnQD12=xoynO09GX74jwJ9JGcgZkzw@mail.gmail.com> On Thu, Nov 26, 2015 at 9:48 AM, ryguy7272 <ryanshuell at gmail.com> wrote: > Thanks!! Is that regex? Can you explain exactly what it is doing? > Also, it seems to pick up a lot more than just the list I wanted, but that's ok, I can see why it does that. > > Can you just please explain what it's doing??? It's a trap! Don't use a regex to parse HTML, unless you're deliberately trying to entice young and innocent programmers to the dark side. ChrisA From snailcoder at retrosite.invalid Wed Nov 25 18:33:48 2015 From: snailcoder at retrosite.invalid (Grobu) Date: Thu, 26 Nov 2015 00:33:48 +0100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> Message-ID: <n35gc3$r1k$1@dont-email.me> On 25/11/15 23:48, ryguy7272 wrote: >> re.findall( r'\<a[^>]+title="(.+?)"', html ) [ ... ] > Thanks!! Is that regex? Can you explain exactly what it is doing? > Also, it seems to pick up a lot more than just the list I wanted, but that's ok, I can see why it does that. > > Can you just please explain what it's doing??? > Yes it's a regular expression. Because RegEx's use the backslash as an escape character, it is advisable to use the "raw string" prefix (r before single/double/triple quote. To illustrate it with an example : >>> print "1\n2" 1 2 >>> print r"1\n2" 1\n2 As the backslash escape character is "neutralized" by the raw string, you can use the usual RegEx syntax at leisure : \<a[^>]+title="(.+?)" \< was a mistake on my part, a single < is perfectly enough [^>] is a class definition, and the caret (^) character indicates negation. Thus it means : any character other than > + incidates repetition : one or more of the previous element . will match just anything .+" is a _greedy_ pattern that would match anything until it encountered a double quote The problem with a greedy pattern is that it doesn't stop at the first match. To illustrate : >>> a = re.search( r'".+"', 'title="this is a test" class="test"' ) >>> a.group() '"this is a test" class="test"' It matches the first quote up to the last one. On the other hand, you can use the "?" modifier to specify a non-greedy pattern : >>> b = re.search( r'".+?"', 'title="this is a test" class="test"' ) '"this is a test"' It matches the first quote and stops looking for further matches after the second quote. Finally, the parentheses are used to indicate a capture group : >>> a = re.search( r'"this (is) a (.+?)"', 'title="this is a test" class="test"' ) >>> a.groups() ('is', 'test') You can find detailed explanations about Python regular expressions at this page : https://docs.python.org/2/howto/regex.html HTH, -Grobu- From ryanshuell at gmail.com Wed Nov 25 18:37:15 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 25 Nov 2015 15:37:15 -0800 (PST) Subject: Screen scraper to get all 'a title' elements In-Reply-To: <n35gc3$r1k$1@dont-email.me> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> <n35gc3$r1k$1@dont-email.me> Message-ID: <e55c49e2-539d-4f62-89f7-34fa3882ff59@googlegroups.com> On Wednesday, November 25, 2015 at 6:34:00 PM UTC-5, Grobu wrote: > On 25/11/15 23:48, ryguy7272 wrote: > >> re.findall( r'\<a[^>]+title="(.+?)"', html ) > [ ... ] > > Thanks!! Is that regex? Can you explain exactly what it is doing? > > Also, it seems to pick up a lot more than just the list I wanted, but that's ok, I can see why it does that. > > > > Can you just please explain what it's doing??? > > > > Yes it's a regular expression. Because RegEx's use the backslash as an > escape character, it is advisable to use the "raw string" prefix (r > before single/double/triple quote. To illustrate it with an example : > >>> print "1\n2" > 1 > 2 > >>> print r"1\n2" > 1\n2 > As the backslash escape character is "neutralized" by the raw string, > you can use the usual RegEx syntax at leisure : > > \<a[^>]+title="(.+?)" > > \< was a mistake on my part, a single < is perfectly enough > [^>] is a class definition, and the caret (^) character indicates > negation. Thus it means : any character other than > > + incidates repetition : one or more of the previous element > . will match just anything > .+" is a _greedy_ pattern that would match anything until it encountered > a double quote > > The problem with a greedy pattern is that it doesn't stop at the first > match. To illustrate : > >>> a = re.search( r'".+"', 'title="this is a test" class="test"' ) > >>> a.group() > '"this is a test" class="test"' > > It matches the first quote up to the last one. > On the other hand, you can use the "?" modifier to specify a non-greedy > pattern : > > >>> b = re.search( r'".+?"', 'title="this is a test" class="test"' ) > '"this is a test"' > > It matches the first quote and stops looking for further matches after > the second quote. > > Finally, the parentheses are used to indicate a capture group : > >>> a = re.search( r'"this (is) a (.+?)"', 'title="this is a test" > class="test"' ) > >>> a.groups() > ('is', 'test') > > > You can find detailed explanations about Python regular expressions at > this page : https://docs.python.org/2/howto/regex.html > > HTH, > > -Grobu- Wow! Awesome! I bookmarked that link! Thanks for everything!!! From rosuav at gmail.com Wed Nov 25 18:42:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 10:42:34 +1100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <e55c49e2-539d-4f62-89f7-34fa3882ff59@googlegroups.com> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> <n35gc3$r1k$1@dont-email.me> <e55c49e2-539d-4f62-89f7-34fa3882ff59@googlegroups.com> Message-ID: <CAPTjJmqH1cBdZ+Z1maPkSJ+-FUvAH_uQ+S7_vXPtATO2m1ZT-w@mail.gmail.com> On Thu, Nov 26, 2015 at 10:37 AM, ryguy7272 <ryanshuell at gmail.com> wrote: > Wow! Awesome! I bookmarked that link! > Thanks for everything!!! Also bookmark this link: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags And read it before you do any parsing of HTML using regular expressions. ChrisA From snailcoder at retrosite.invalid Wed Nov 25 18:44:55 2015 From: snailcoder at retrosite.invalid (Grobu) Date: Thu, 26 Nov 2015 00:44:55 +0100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <mailman.103.1448492791.20593.python-list@python.org> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> <mailman.103.1448492791.20593.python-list@python.org> Message-ID: <n35h0v$stn$1@dont-email.me> On 26/11/15 00:06, Chris Angelico wrote: > On Thu, Nov 26, 2015 at 9:48 AM, ryguy7272 <ryanshuell at gmail.com> wrote: >> Thanks!! Is that regex? Can you explain exactly what it is doing? >> Also, it seems to pick up a lot more than just the list I wanted, but that's ok, I can see why it does that. >> >> Can you just please explain what it's doing??? > > It's a trap! > > Don't use a regex to parse HTML, unless you're deliberately trying to > entice young and innocent programmers to the dark side. > > ChrisA > Sorry, I wasn't aware of regex being on the dark side :-) Now that you mention it, I suppose that their being complex and error-inducing could lead to broken code all too easily when there is a reliable, ready-made solution like BeautifulSoup. From marko at pacujo.net Wed Nov 25 18:53:26 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 01:53:26 +0200 Subject: Screen scraper to get all 'a title' elements References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> <mailman.103.1448492791.20593.python-list@python.org> <n35h0v$stn$1@dont-email.me> Message-ID: <87y4dl3abt.fsf@elektro.pacujo.net> Grobu <snailcoder at retrosite.invalid>: > Sorry, I wasn't aware of regex being on the dark side :-) No, regular expressions are great for many purposes. Parsing context-free syntax isn't one of them. See: <URL: https://en.wikipedia.org/wiki/Chomsky_hierarchy#The_hierarchy> Most modern programming languages including HTML are context-free. Their structure is too rich for regular expressions to capture. Regular expressions can handle any regular language just fine. They are commonly used to define the lexical tokens of a language. Marko From rosuav at gmail.com Wed Nov 25 18:54:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 10:54:04 +1100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <n35h0v$stn$1@dont-email.me> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> <mailman.103.1448492791.20593.python-list@python.org> <n35h0v$stn$1@dont-email.me> Message-ID: <CAPTjJmqzWXjAJo_=3xtBYhUfnb2TwtrmC9AYYmiiC9G3v58zsw@mail.gmail.com> On Thu, Nov 26, 2015 at 10:44 AM, Grobu <snailcoder at retrosite.invalid> wrote: > On 26/11/15 00:06, Chris Angelico wrote: >> >> On Thu, Nov 26, 2015 at 9:48 AM, ryguy7272 <ryanshuell at gmail.com> wrote: >>> >>> Thanks!! Is that regex? Can you explain exactly what it is doing? >>> Also, it seems to pick up a lot more than just the list I wanted, but >>> that's ok, I can see why it does that. >>> >>> Can you just please explain what it's doing??? >> >> >> It's a trap! >> >> Don't use a regex to parse HTML, unless you're deliberately trying to >> entice young and innocent programmers to the dark side. >> >> ChrisA >> > > Sorry, I wasn't aware of regex being on the dark side :-) > Now that you mention it, I suppose that their being complex and > error-inducing could lead to broken code all too easily when there is a > reliable, ready-made solution like BeautifulSoup. Regular expressions have their uses, but parsing HTML is not one of them. The most important use of a regex is letting an end user control the search pattern; it's a compact language for describing a variety of text search concepts. For hard-coded regular expressions, there are some places where they're very good, and a lot of places where they're the wrong tool for the job. And one of those wrong-tool-for-job places is parsing stuff that fundamentally cannot be parsed with regexes, such as HTML. You _need_ a proper parser, which is what Beautiful Soup is for. ChrisA From rosuav at gmail.com Wed Nov 25 18:59:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 10:59:14 +1100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <87y4dl3abt.fsf@elektro.pacujo.net> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> <mailman.103.1448492791.20593.python-list@python.org> <n35h0v$stn$1@dont-email.me> <87y4dl3abt.fsf@elektro.pacujo.net> Message-ID: <CAPTjJmqjyA-zwaECDn3BjCJCpzSQtaMWHOtauSvo2Uz5CJM0VQ@mail.gmail.com> On Thu, Nov 26, 2015 at 10:53 AM, Marko Rauhamaa <marko at pacujo.net> wrote: > Regular expressions can handle any regular language just fine. They are > commonly used to define the lexical tokens of a language. Not sure about _defining_ them, but they're certainly often used to _recognize_ them, eg in syntax highlighters. ChrisA From steve at pearwood.info Wed Nov 25 19:10:58 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 26 Nov 2015 11:10:58 +1100 Subject: What is a function parameter =[] for? References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <CAPTjJmoGt3B_zTVd8dVLHNeanX=4g1yhN-PLpXzZoYiKb9HYuw@mail.gmail.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <mailman.84.1448476089.20593.python-list@python.org> Message-ID: <56564e14$0$1595$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 05:27 am, Antoon Pardon wrote: > Op 25-11-15 om 18:40 schreef Steven D'Aprano: >> On Wed, 25 Nov 2015 08:56 pm, Antoon Pardon wrote: >> >>> Since (x, y, z) is not a fixed value, it is not a literal. >> >> Right. And therefore, (x, y, z) syntax is not syntax for a literal. Hence >> why the Python docs call it a tuple display instead of a tuple literal -- >> no matter what x, y, z are. Even if they themselves are literals, that's >> just a special case that *some* compiler versions may be able to handle. >> >> You call this "picking nits", but if so, they are nits that are twice the >> size of an an elephant and painted bright yellow. Your language arguing >> about "tuple literals" seems to be based on the idea that it is usually a >> constant and that cases like (x+1, y+2) is some unusual, rare corner >> case -- what you call "nits". > > I don't know what you are talking about. The first thing I have argued > is that () is a literal. How embarrassing that Python doesn't treat it as a literal, but as an expression. > And one way I supported my point was with the > following quote from the python language reference. > > Literals are notations for constant values of some built-in types. > > And I think that the things I argued were literals, were in fact > constant values of some built-in type. Since you didn't bother to provide a link, I googled for that quote, and here's a page that gives the canonical set of literals available in Python: https://docs.python.org/2/reference/lexical_analysis.html#literals https://docs.python.org/3/reference/lexical_analysis.html#literals I see strings, ints, floats, but no tuples, lists or dicts. It takes either great chutzpah or great stupidity to use the official documentation to argue in favour of a point which is contradicted by that very same documentation. The Python docs *define* "literal" to only refer to certain types. That definition is related to the grammar of Python: https://docs.python.org/3/reference/grammar.html It would be silly, wasteful and error-prone to define two sorts of tuple displays: "tuple displays where each component is a literal" "tuple displays where at least one component is not a literal" as you want to distinguish. Now obviously this is a legitimate distinction to make in some circumstances: the compiler may (or may not) be able optimise the first case in some way. But it's not a distinction that makes sense for the parser. It makes no difference to the parser whether you have (1, 2) or (1, x), it gets parsed the same way. To the parser, there is only one sort of tuple display, and it is absolutely not a literal. The terminology used for lexical analysis is the terminology used for the parser, not the peephole optimizer. All Python compilers must have a parser, and they must agree on the grammar. But optimization is implementation dependent. There is talk about adding a switch to Python to disable all peep-hole optimizations, which means whether (1, 2) gets compiled to a BUILD_CONST or a BUILD_TUPLE will depend on a runtime switch. The bottom-line is that tuples, lists, sets and dicts are compound data types, and while it is easy and convenient to talk about "tuple literals" that's sloppy language which is not supported by the language reference. When this fact is pointed out, there are multiple sensible strategies available: (1) we can acknowledge that "tuple literal" is sloppy language, and vow never to use it again; (2) we can acknowledge that "tuple literal" is sloppy language, but argue that it's convenient to use, more familiar than "tuple display", and most people will understand what you mean, and so we'll continue to use it no matter how sloppy it is; (3) or we can declare that the definition in the language reference is wrong, that we know better. What I've never seen before though is what you appear to have done: (4) Respond that the language reference, which clearly and obviously does NOT include tuples in the list of types that can be described as "literals", supports your claim that tuples are literals. -- Steven From steve at pearwood.info Wed Nov 25 19:31:27 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 26 Nov 2015 11:31:27 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> Message-ID: <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 09:41 am, BartC wrote: > Maybe you're too familiar with it. But the idea of executing the > function and other definitions in a file, instead of they just being > there, is novel. It really, truly isn't. Your viewpoint is clouded by too much immersion in crippled languages. *Old and obsolete versions* of crippled languages. Dynamic creation of functions goes back to the 1950s. Functions in Python are *first class values*, just like ints, strings, lists etc. That means functions can be passed around as arguments, assigned to variables, returned from functions, and created on the fly as needed. This is not an innovation from Python -- Python rarely, if ever, innovates. By the time any feature hits Python (yes, even significant indentation) it has typically been proven in at least one other language. Languages with first class functions include Perl, Javascript, Lua, PHP, Tcl/Tk, Io, Go, Rust, Maple, Mathematica, Smalltalk, Swift, and varied mix of old (Smalltalk and Perl) and new (Rust and Swift). It is almost unthinkable to imagine a functional programming language without this feature, and sure enough Scala, Haskell, ML, Clojure, and Scheme have it -- as does Lisp, which is the second oldest high level language in existence. Only Fortran is older. Delphi (a variant on Pascal/Algol) has supported them since 2009. C++, C# and Objective C have support for first class functions. Even Java 8 and above includes this feature. In 2015, it's hard to think of any non-obsolete, non-toy language which doesn't treat functions as first-class values, including creating them on the fly. Fortran and C perhaps. -- Steven From random832 at fastmail.com Wed Nov 25 19:52:55 2015 From: random832 at fastmail.com (Random832) Date: Thu, 26 Nov 2015 00:52:55 +0000 (UTC) Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <CAPTjJmoyGi04Dnxxp1AFytLkWQg=D4ccXqE6OwfJJMgp7fg1YA@mail.gmail.com> <858u5lc0r7.fsf@benfinney.id.au> Message-ID: <n35l57$ots$1@ger.gmane.org> On 2015-11-25, Ben Finney <ben+python at benfinney.id.au> wrote: > That is, the ?2? in ?cartesian_point = (2, 3)? means something different > than in ?cartesian_point = (3, 2)?. > > Whereas the ?2? in ?test_scores = [2, 3]? means exactly the same as in > ?test_scores = [3, 2]?. > > If each position in the sequence gives the value there a different > menaning, use a tuple; if not, use a list. I don't think that's really right. The absence of first-class multisets in python does mean that lists get "abused" for that purpose, but I don't think that means that there's no legitimate use-case for a list (i.e. a mutable sequence in which position is significant). The difference between a tuple and a list is that one is mutable and the other is not. The difference you are describing is between a list and a multiset (or a tuple and an immutable multiset). From steve at pearwood.info Wed Nov 25 19:53:51 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 26 Nov 2015 11:53:51 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> Message-ID: <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 01:34 am, BartC wrote: > On 25/11/2015 13:53, Marko Rauhamaa wrote: >> BartC <bc at freeuk.com>: >> >>> Using tuples in the same way that other languages implement records is >>> going to be difficult if you can't change the values of the fields! >> >> Guido could decide tomorrow that tuples are mutable. > > (Could that be done without breaking existing code? And what then would > be the difference between them and lists?) No it could not, and no Guido could not decide to make them mutable. Well, strictly speaking he could make that decision, but the other core developers would not go along with such a stupid backwards-incompatible change. I don't know what would happen if Guido did make that decision -- I suppose it would provoke some sort of constitutional crisis (figuratively speaking), like what would happen if the Queen of the UK refused to sign into law legislation after being lawfully asked to do so by the Prime Minister. (The Queen has the power to reject any legislation put to her by the Prime Minister, so long as she does not actually make use of that power.) Guido, as BDFL, has every right to make tuples mutable, or remove numbers from the language, so long as he does not actually do so. Making tuples mutable would break their use as dictionary keys, which is a *critical* use. https://docs.python.org/2/faq/design.html#why-must-dictionary-keys-be-immutable >> Anyway, Python has two ways to represent records: classes and tuples. >> Tuples are nice because they are concise and ad hoc. Often you start >> with a scalar value, then turn it into a tuple. After a while your handy >> tuple turns out a bit cumbersome to use so you convert it into an actual >> class. > > This is how records are handled in another language which I believe is > simpler than Python: http://pastebin.com/vhsJML8U > > This also implements my example from earlier in the thread. Now compare > with Python's approach. > > OK, that also needs two concepts, a list, and a record. But the > distinction is now completely obvious. Records are also mutable. It > would also be clear why you can't append to a record. > > Now try explaining again to me how you would use tuples for the same > thing... In Pascal, strings are mutable. (Well, technically, standard Pascal doesn't define a string data type, but most implementations do.) So you typically have some function like: insert(thestring, substring, pos) which modifies thestring in place. In Python, strings are immutable, so the equivalent of insert() would be a function that returns a new string: thestring = insert(thestring, substring, pos) It's not exactly an earth-shattering difference. The implementation is simple that it is almost pointless to put it in a function: def insert(s, substring, pos): return s[:pos] + substring + s[pos:] Tuples-as-records are no different. Instead of modifying the existing record, you create a new one. If that's inconvenient, then use a class, which will be mutable by default. -- Steven From snailcoder at retrosite.invalid Wed Nov 25 20:05:34 2015 From: snailcoder at retrosite.invalid (Grobu) Date: Thu, 26 Nov 2015 02:05:34 +0100 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <n35h0v$stn$1@dont-email.me> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> <mailman.96.1448484959.20593.python-list@python.org> <n35ckk$9q0$1@dont-email.me> <c1e43997-0da3-4b93-b9af-98a2568eff9d@googlegroups.com> <mailman.103.1448492791.20593.python-list@python.org> <n35h0v$stn$1@dont-email.me> Message-ID: <n35lo5$b06$1@dont-email.me> Chris, Marko, thank you both for your links and explanations! From wingusr at gmail.com Wed Nov 25 20:15:49 2015 From: wingusr at gmail.com (TP) Date: Wed, 25 Nov 2015 17:15:49 -0800 Subject: Screen scraper to get all 'a title' elements In-Reply-To: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> Message-ID: <CAMEax76MwY323=z9n_o+=zJQhAQdRpeFM-nKEbARG__UEoGxmg@mail.gmail.com> On Wed, Nov 25, 2015 at 12:42 PM, ryguy7272 <ryanshuell at gmail.com> wrote: > Hello experts. I'm looking at this url: > https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names Wildly offtopic but interesting, easy way to grab/analyze Wikipedia data using F# instead of Python http://evelinag.com/blog/2015/11-18-f-tackles-james-bond/ In your particular case something like: open FSharp.Data let [<Literal>] wikiURL = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" type PlaceNamesProvider = HtmlProvider<wikiURL> let placeNamesWiki = PlaceNamesProvider() for row in placeNamesWiki.Tables.``Short & medium length names``.Rows do printfn "%s" row.Column1 From bc at freeuk.com Wed Nov 25 20:23:16 2015 From: bc at freeuk.com (BartC) Date: Thu, 26 Nov 2015 01:23:16 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <n35mps$dv8$1@dont-email.me> On 26/11/2015 00:31, Steven D'Aprano wrote: > On Thu, 26 Nov 2015 09:41 am, BartC wrote: > >> Maybe you're too familiar with it. But the idea of executing the >> function and other definitions in a file, instead of they just being >> there, is novel. > > > It really, truly isn't. Your viewpoint is clouded by too much immersion in > crippled languages. *Old and obsolete versions* of crippled languages. > Dynamic creation of functions goes back to the 1950s. > > Functions in Python are *first class values*, just like ints, strings, lists > etc. That means functions can be passed around as arguments, assigned to > variables, returned from functions, and created on the fly as needed. This > is not an innovation from Python -- Python rarely, if ever, innovates. By > the time any feature hits Python (yes, even significant indentation) it has > typically been proven in at least one other language. > > Languages with first class functions include Perl, Javascript, Lua, PHP, > Tcl/Tk, Io, Go, Rust, Maple, Mathematica, Smalltalk, Swift, and varied mix > of old (Smalltalk and Perl) and new (Rust and Swift). > > It is almost unthinkable to imagine a functional programming language > without this feature, and sure enough Scala, Haskell, ML, Clojure, and > Scheme have it -- as does Lisp, which is the second oldest high level > language in existence. Only Fortran is older. > > Delphi (a variant on Pascal/Algol) has supported them since 2009. C++, C# > and Objective C have support for first class functions. Even Java 8 and > above includes this feature. > > In 2015, it's hard to think of any non-obsolete, non-toy language which > doesn't treat functions as first-class values, including creating them on > the fly. Fortran and C perhaps. It's funny then that the vast majority of top-level function definitions I see in Python (and import and class statements too) are decidedly static. The names are declared, but the names are rarely bound to anything else. Functions are just called the same boring way they are in C. /They might as well be static definitions/. (In fact, all this dynamic set-up, while it makes for an elegant and consistent language, probably also makes it unnecessarily harder to accelerate.) Clearly a huge amount of programming can be done without having to deal with first-class functions (or constructing functions at run-time; that sounds fun). (Or without using OOP, another thing I can't stand.) Some people just don't want to be functional programmers. It is elitist to try and make out it that it is that important. If lots of languages now have functional features, it's more likely to be a case of keeping up with the Joneses. -- Bartc From ned at nedbatchelder.com Wed Nov 25 20:52:21 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 25 Nov 2015 17:52:21 -0800 (PST) Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <n35mps$dv8$1@dont-email.me> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> Message-ID: <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> On Wednesday, November 25, 2015 at 8:23:36 PM UTC-5, BartC wrote: > On 26/11/2015 00:31, Steven D'Aprano wrote: > > On Thu, 26 Nov 2015 09:41 am, BartC wrote: > > > >> Maybe you're too familiar with it. But the idea of executing the > >> function and other definitions in a file, instead of they just being > >> there, is novel. > > > > > > It really, truly isn't. Your viewpoint is clouded by too much immersion in > > crippled languages. *Old and obsolete versions* of crippled languages. > > Dynamic creation of functions goes back to the 1950s. > > > > Functions in Python are *first class values*, just like ints, strings, lists > > etc. That means functions can be passed around as arguments, assigned to > > variables, returned from functions, and created on the fly as needed. This > > is not an innovation from Python -- Python rarely, if ever, innovates. By > > the time any feature hits Python (yes, even significant indentation) it has > > typically been proven in at least one other language. > > > > Languages with first class functions include Perl, Javascript, Lua, PHP, > > Tcl/Tk, Io, Go, Rust, Maple, Mathematica, Smalltalk, Swift, and varied mix > > of old (Smalltalk and Perl) and new (Rust and Swift). > > > > It is almost unthinkable to imagine a functional programming language > > without this feature, and sure enough Scala, Haskell, ML, Clojure, and > > Scheme have it -- as does Lisp, which is the second oldest high level > > language in existence. Only Fortran is older. > > > > Delphi (a variant on Pascal/Algol) has supported them since 2009. C++, C# > > and Objective C have support for first class functions. Even Java 8 and > > above includes this feature. > > > > In 2015, it's hard to think of any non-obsolete, non-toy language which > > doesn't treat functions as first-class values, including creating them on > > the fly. Fortran and C perhaps. > > It's funny then that the vast majority of top-level function definitions > I see in Python (and import and class statements too) are decidedly static. > > The names are declared, but the names are rarely bound to anything else. > Functions are just called the same boring way they are in C. > > /They might as well be static definitions/. > > (In fact, all this dynamic set-up, while it makes for an elegant and > consistent language, probably also makes it unnecessarily harder to > accelerate.) > > Clearly a huge amount of programming can be done without having to deal > with first-class functions (or constructing functions at run-time; that > sounds fun). (Or without using OOP, another thing I can't stand.) > > Some people just don't want to be functional programmers. It is elitist > to try and make out it that it is that important. > > If lots of languages now have functional features, it's more likely to > be a case of keeping up with the Joneses. I almost started to explain about how yes, Python is often written in conservative static ways. I was going to mention that a little dynamic nature goes a long way, and is never far from the surface in even the simplest Python programs. But I won't, because I'm not sure you're really interested. There's a pattern here of people trying to explain Python to you, and eventually, after many words, getting to some kind of shared understanding, only for you to shrug it all off as a fad, or pocket-lining, or needless complexity. For someone who claims to be interested in language design, you're remarkably dismissive of pretty much the entire industry. I don't think it's worth the effort to try to change your mind. --Ned. From steve at pearwood.info Wed Nov 25 21:01:56 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 26 Nov 2015 13:01:56 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> Message-ID: <56566815$0$1598$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 12:20 am, BartC wrote: > On 25/11/2015 10:52, Steven D'Aprano wrote: >> On Wed, 25 Nov 2015 07:14 pm, Antoon Pardon wrote: > >>> What exactly is your point? >> >> That there is a simple analogy between the distinction between code >> inside/outside a for-loop, and code inside/outside a function. If you can >> understand why this loops forever, instead of just twice, then you can >> understand why function defaults work the way they do: >> >> L = [1, 2] >> for i in L: >> L.append(i) >> print(L) >> >> >> There is nothing "bizarre" or complicated or difficult to understand >> happening here. > > What do you think most people would expect to happen here? I wouldn't try to guess what "most" people would expect. Their expectations would depend on what exposure they have had with programming languages, if any, what languages those are, and how well they grok the idea of simulating code in their own head. > I know, > because you gave a spoiler, that it loops forever, otherwise I wouldn't > be sure /without trying it/ (but I tried it anyway). > > Here's the same code in a somewhat different language: > > L := (1,2) > for i in L do > | L append:= i > | println L > od > > And this is the output: > > (1,2,1) > (1,2,1,2) > > Which output (infinite series of [1,2,1,2,1,....] or the above) is more > sensible, and which do you think people might prefer? The infinite loop is more sensible, and people would prefer the above output. Who wants an infinite loop? That's nearly always a bug. But consider why, bug or no bug, the Python version which leads to an infinite series should be preferred over the other version. I can think of at least three reasons why the Python behaviour is objectively better, despite leading to an unwanted infinite loop in this specific case. (1) The Python version avoids always making a copy of the (potentially huge) list before looping over it. That makes the performance of for-loops more predictable and avoids horrible surprises: for x in L: break takes the same amount of time to execute whether L has one item or a hundred billion items. The for-loop *overhead* (as opposed to the cost of the loop itself) is a fixed, small amount. (2) The Python version has a cleaner, easier to understand execution model. Apart from two obvious exceptions (on the left hand side of an assignment, or following the "del" statement) all uses of the name L have the same meaning. Whether you write: for x in L if "foo" in L while L L + [1, 2] len(L) L or [] L.append(42) or any other expression, all uses of the name L evaluate to the same thing: the object currently bound to that name. You don't have to try to remember which uses evaluate to the original object and which make a copy. It is *never* a copy -- if you want a copy, you can copy it yourself. (Use the copy module, copy.copy(L), or take a slice, L[:].) The cost of this is that you are always responsible for making a copy, since Python won't automatically do it for you (whether you want a copy or not). But the benefit is that you avoid making unnecessary copies. I infer from the line "L append:= i" that your language doesn't always make a copy (otherwise, how could you modify the original?). That means that you, the programmer, still has to manage the copying of the list, exactly the same as we have to do with Python. The difference is, Python doesn't lure you into a false sense of security by *sometimes* making that copy for you. The rules are: "In Python, if you want a copy of the list, make a copy yourself." versus: "In BartC's language, if you want a copy of the list, look up the operation you are about to do to see if it already makes a copy, and if it doesn't, then make a copy yourself. (Otherwise, you might make two copies.)" (3) What if you don't want a copy? How does one disable that feature? Or does your language simply declare that "you can't do that"? for item in queue: process(item) if condition: queue.append(something) What's the most natural equivalent to that code snippet in your language? > The point is that the behaviour of the loop is by no means obvious, so > neither is the behaviour of the function defaults. I'm pretty sure that nobody said the behaviour was obvious in the sense of predictable to those unfamiliar with the rules of the language. There's even a FAQ about it. There's a big difference between *obvious in advance* and *obvious in hindsight once an explanation is given*. -- Steven From alan at csail.mit.edu Wed Nov 25 21:08:17 2015 From: alan at csail.mit.edu (Alan Bawden) Date: Wed, 25 Nov 2015 21:08:17 -0500 Subject: What is a function parameter =[] for? References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547337.4000709@rece.vub.ac.be> <CAPTjJmoGt3B_zTVd8dVLHNeanX=4g1yhN-PLpXzZoYiKb9HYuw@mail.gmail.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> Steven D'Aprano <steve at pearwood.info> writes: > In fact, it's easy to find cases even now where the compiler is > insufficiently smart to recognise all the possible optimizations available. > There's no tuple simpler than the empty tuple, but Python 3.3 at least > fails to optimize that case: > > py> dis(compile("()", '', 'eval')) > 1 0 BUILD_TUPLE 0 > 3 RETURN_VALUE Actually, it would be silly to compile that as a LOAD_CONST of an empty tuple. "BUILD_TUPLE 0" doesn't allocate storage, it returns the same empty tuple every time! In effect "BUILD_TUPLE 0" is just a global load. A different disassembler might decide to print "BUILD_TUPLE 0" as "LOAD_EMPTY_TUPLE". Using LOAD_CONST would just waste space in the function's vector of constants. (Note that nothing in the documentation I can find actually _guarantees_ that a Python implementation will only have one unique empty tuple, but I wouldn't be suprised if the following is nonetheless true in all current implementations: >>> tuple([]) is tuple([]) True ) -- Alan Bawden From rosuav at gmail.com Wed Nov 25 21:25:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 13:25:24 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547337.4000709@rece.vub.ac.be> <CAPTjJmoGt3B_zTVd8dVLHNeanX=4g1yhN-PLpXzZoYiKb9HYuw@mail.gmail.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> Message-ID: <CAPTjJmqrEhMR7Uq_V1zPUw6huPjKYPMPDciHvJoCwZDXaSkZfg@mail.gmail.com> On Thu, Nov 26, 2015 at 1:08 PM, Alan Bawden <alan at csail.mit.edu> wrote: > (Note that nothing in the documentation I can find actually _guarantees_ > that a Python implementation will only have one unique empty tuple, but > I wouldn't be suprised if the following is nonetheless true in all > current implementations: > > >>> tuple([]) is tuple([]) > True > > ) Jython 2.5.3 (, Oct 8 2014, 03:39:09) [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_85 Type "help", "copyright", "credits" or "license" for more information. >>> tuple([]) is tuple([]) False Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46) [PyPy 2.4.0 with GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>> tuple([]) is tuple([]) False ChrisA From ian.g.kelly at gmail.com Wed Nov 25 21:46:52 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Nov 2015 19:46:52 -0700 Subject: What is a function parameter =[] for? In-Reply-To: <CAPTjJmqrEhMR7Uq_V1zPUw6huPjKYPMPDciHvJoCwZDXaSkZfg@mail.gmail.com> References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547337.4000709@rece.vub.ac.be> <CAPTjJmoGt3B_zTVd8dVLHNeanX=4g1yhN-PLpXzZoYiKb9HYuw@mail.gmail.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <CAPTjJmqrEhMR7Uq_V1zPUw6huPjKYPMPDciHvJoCwZDXaSkZfg@mail.gmail.com> Message-ID: <CALwzidmFqTWodNxGnJSoeV3wWMvi8dP-6X=dp_kT8m6r=WLcog@mail.gmail.com> On Wed, Nov 25, 2015 at 7:25 PM, Chris Angelico <rosuav at gmail.com> wrote: > On Thu, Nov 26, 2015 at 1:08 PM, Alan Bawden <alan at csail.mit.edu> wrote: >> (Note that nothing in the documentation I can find actually _guarantees_ >> that a Python implementation will only have one unique empty tuple, but >> I wouldn't be suprised if the following is nonetheless true in all >> current implementations: >> >> >>> tuple([]) is tuple([]) >> True >> >> ) > > Jython 2.5.3 (, Oct 8 2014, 03:39:09) > [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_85 > Type "help", "copyright", "credits" or "license" for more information. >>>> tuple([]) is tuple([]) > False > > Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46) > [PyPy 2.4.0 with GCC 4.9.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>>> tuple([]) is tuple([]) > False Well, he did say all "current" implementations. CPython 2.7 may still be supported, but that doesn't make it current. And anything at 2.5 is just archaic. From ian.g.kelly at gmail.com Wed Nov 25 22:01:43 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Nov 2015 20:01:43 -0700 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <n35l57$ots$1@ger.gmane.org> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <CAPTjJmoyGi04Dnxxp1AFytLkWQg=D4ccXqE6OwfJJMgp7fg1YA@mail.gmail.com> <858u5lc0r7.fsf@benfinney.id.au> <n35l57$ots$1@ger.gmane.org> Message-ID: <CALwzidkHTUbxYY0cwspJ8jpCEw_BR_WmhqcHaTk3h2gc2XYbSQ@mail.gmail.com> On Wed, Nov 25, 2015 at 5:52 PM, Random832 <random832 at fastmail.com> wrote: > On 2015-11-25, Ben Finney <ben+python at benfinney.id.au> wrote: >> That is, the ?2? in ?cartesian_point = (2, 3)? means something different >> than in ?cartesian_point = (3, 2)?. >> >> Whereas the ?2? in ?test_scores = [2, 3]? means exactly the same as in >> ?test_scores = [3, 2]?. >> >> If each position in the sequence gives the value there a different >> menaning, use a tuple; if not, use a list. > > I don't think that's really right. The absence of first-class > multisets in python does mean that lists get "abused" for that > purpose, but I don't think that means that there's no legitimate > use-case for a list (i.e. a mutable sequence in which position is > significant). > > The difference between a tuple and a list is that one is mutable > and the other is not. The difference you are describing is > between a list and a multiset (or a tuple and an immutable > multiset). I think that Ben was actually trying to make a distinction between heterogeneity and homogeneity of the contents, not a distinction of whether the collection was ordered or not. You can of course have a homogeneous collection for which order is still important, e.g. a batting line-up. From rosuav at gmail.com Wed Nov 25 22:02:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 14:02:00 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <CALwzidmFqTWodNxGnJSoeV3wWMvi8dP-6X=dp_kT8m6r=WLcog@mail.gmail.com> References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547337.4000709@rece.vub.ac.be> <CAPTjJmoGt3B_zTVd8dVLHNeanX=4g1yhN-PLpXzZoYiKb9HYuw@mail.gmail.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <CAPTjJmqrEhMR7Uq_V1zPUw6huPjKYPMPDciHvJoCwZDXaSkZfg@mail.gmail.com> <CALwzidmFqTWodNxGnJSoeV3wWMvi8dP-6X=dp_kT8m6r=WLcog@mail.gmail.com> Message-ID: <CAPTjJmq42U+tk_=Za572X0qpihS=+yWcGfMn2keF827jMUeyfw@mail.gmail.com> On Thu, Nov 26, 2015 at 1:46 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote: > On Wed, Nov 25, 2015 at 7:25 PM, Chris Angelico <rosuav at gmail.com> wrote: >> On Thu, Nov 26, 2015 at 1:08 PM, Alan Bawden <alan at csail.mit.edu> wrote: >>> (Note that nothing in the documentation I can find actually _guarantees_ >>> that a Python implementation will only have one unique empty tuple, but >>> I wouldn't be suprised if the following is nonetheless true in all >>> current implementations: >>> >>> >>> tuple([]) is tuple([]) >>> True >>> >>> ) >> >> Jython 2.5.3 (, Oct 8 2014, 03:39:09) >> [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_85 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> tuple([]) is tuple([]) >> False >> >> Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46) >> [PyPy 2.4.0 with GCC 4.9.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>>> tuple([]) is tuple([]) >> False > > Well, he did say all "current" implementations. CPython 2.7 may still > be supported, but that doesn't make it current. And anything at 2.5 is > just archaic. Those are the versions of Jython and PyPy available from the Debian Jessie repositories. I'm not sure what Jython's compatibility is, but this is at least reasonably current. But I grabbed the latest 2.x-compatible PyPy nightly: Python 2.7.10 (b4515dee6ebf, Nov 25 2015, 23:01:41) [PyPy 4.1.0-alpha0 with GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. And now for something completely different: ``Every time someone argues with "Smalltalk has always done X", it is always a good hint that something needs to be changed fast. - Marcus Denker'' >>>> tuple([]) is tuple([]) False The latest PyPy3 nightly builds seem to be broken, though; I was unable to get one to run. The builds compatible with Python 3.2 work, though: Python 3.2.5 (b2091e973da6, Oct 19 2014, 18:29:55) [PyPy 2.4.0 with GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>> tuple([]) is tuple([]) False So current PyPy still behaves that way. ChrisA From alan at csail.mit.edu Wed Nov 25 23:27:43 2015 From: alan at csail.mit.edu (Alan Bawden) Date: Wed, 25 Nov 2015 23:27:43 -0500 Subject: What is a function parameter =[] for? References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <56547C53.8030407@rece.vub.ac.be> <CAPTjJmqAMwnxBZ97umsNg255v47dsQD6qEr0ysECtGiZ409k0Q@mail.gmail.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> Message-ID: <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> Chris Angelico <rosuav at gmail.com> writes: > On Thu, Nov 26, 2015 at 1:08 PM, Alan Bawden <alan at csail.mit.edu> wrote: >> (Note that nothing in the documentation I can find actually _guarantees_ >> that a Python implementation will only have one unique empty tuple, but >> I wouldn't be suprised if the following is nonetheless true in all >> current implementations: >> >> >>> tuple([]) is tuple([]) >> True >> >> ) > > Jython 2.5.3 (, Oct 8 2014, 03:39:09) > [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_85 > Type "help", "copyright", "credits" or "license" for more information. >>>> tuple([]) is tuple([]) > False > > Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46) > [PyPy 2.4.0 with GCC 4.9.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>>> tuple([]) is tuple([]) > False > > ChrisA I said I wouldn't be suprised if it was always true, but that doesn't imply that I need to be suprised if it is sometimes false! Having said that, I _am_ curious whether that remains False for various other variant expressions. "tuple([])" is actually a rather perverse way to obtain an empty tuple. How about plain "() is ()"? While "tuple([]) is tuple([])" is False is some implementations, it is still possible that "() is ()" is True in those same implementations, depending on how that compiles. An even more perverse way to obtain an empty tuple is "tuple(x for x in ())" and in fact in CPython: >>> tuple(x for x in ()) is tuple(x for x in ()) False If I had thought to try that earlier, I wouldn't have bothered making the parenthetical remark to are responding to -- because none of this has any relevance to my original point about "BUILD_TUPLE 0". -- Alan Bawden From ben+python at benfinney.id.au Thu Nov 26 00:04:39 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 Nov 2015 16:04:39 +1100 Subject: Semantics of collection types (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?)) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <CAPTjJmoyGi04Dnxxp1AFytLkWQg=D4ccXqE6OwfJJMgp7fg1YA@mail.gmail.com> <858u5lc0r7.fsf@benfinney.id.au> <n35l57$ots$1@ger.gmane.org> <CALwzidkHTUbxYY0cwspJ8jpCEw_BR_WmhqcHaTk3h2gc2XYbSQ@mail.gmail.com> Message-ID: <85wpt59wrc.fsf_-_@benfinney.id.au> Ian Kelly <ian.g.kelly at gmail.com> writes: > On Wed, Nov 25, 2015 at 5:52 PM, Random832 <random832 at fastmail.com> wrote: > > On 2015-11-25, Ben Finney <ben+python at benfinney.id.au> wrote: > >> That is, the ?2? in ?cartesian_point = (2, 3)? means something > >> different than in ?cartesian_point = (3, 2)?. > >> > >> Whereas the ?2? in ?test_scores = [2, 3]? means exactly the same as > >> in ?test_scores = [3, 2]?. > >> > >> If each position in the sequence gives the value there a different > >> menaning, use a tuple; if not, use a list. > > > > I don't think that's really right. I was expanding on (by replying to) earlier advice about expressing semantics in our choice of data types. > > The difference between a tuple and a list is that one is mutable > > and the other is not. That is a difference enforced in the behaviour of the types, yes. I didn't talk about behaviour, but about meaning. I'm saying that the behavioural difference conveniently lines up with a semantic difference, even to the point of the meaning of ?tuple? that pre-dates Python. > I think that Ben was actually trying to make a distinction between > heterogeneity and homogeneity of the contents, not a distinction of > whether the collection was ordered or not. That's right, thank you. -- \ ?Nothing exists except atoms and empty space; everything else | `\ is opinion.? ?Democritus, c. 460 BCE ? 370 BCE | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Nov 26 00:08:27 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 Nov 2015 16:08:27 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> Message-ID: <85si3t9wl0.fsf@benfinney.id.au> Ned Batchelder <ned at nedbatchelder.com> writes: > For someone who claims to be interested in language design, you're > remarkably dismissive of pretty much the entire industry. I don't > think it's worth the effort to try to change your mind. +1. BartC, when you want to join us in discussions on good faith ? that is, honestly wanting to learn Python rather than dogmatically persisting in your misperceptions dogmatically onto it ? we'll still be here, making happy use of Python the way it is. -- \ ?Facts are meaningless. You could use facts to prove anything | `\ that's even remotely true!? ?Homer, _The Simpsons_ | _o__) | Ben Finney From ramjee.ag at gmail.com Thu Nov 26 01:26:19 2015 From: ramjee.ag at gmail.com (ramjee a.g.) Date: Thu, 26 Nov 2015 11:56:19 +0530 Subject: Py_NewInterpreter() - Fatal Error with ceval - orphan tstate Message-ID: <CAGQhfC5ZSZyyL7kmaQmL=ECqCU_Ruy4ytXMYpDeJR=HdKLQ05A@mail.gmail.com> Hi, I am using python 2.7 for extending my C++ application with python. And when two pthread of C is executing Py_NewInterpreter() it is throwing faltal error with ceval-orphan tstate. There is no problem when sequential thread execution. Let me know if any solution to be fixed in my python library. Regards, Ramjee From breamoreboy at yahoo.co.uk Thu Nov 26 01:39:38 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 26 Nov 2015 06:39:38 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <85si3t9wl0.fsf@benfinney.id.au> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <85si3t9wl0.fsf@benfinney.id.au> Message-ID: <n369fe$1dk$1@ger.gmane.org> On 26/11/2015 05:08, Ben Finney wrote: > Ned Batchelder <ned at nedbatchelder.com> writes: > >> For someone who claims to be interested in language design, you're >> remarkably dismissive of pretty much the entire industry. I don't >> think it's worth the effort to try to change your mind. > > +1. > > BartC, when you want to join us in discussions on good faith ? that is, > honestly wanting to learn Python rather than dogmatically persisting in > your misperceptions dogmatically onto it ? we'll still be here, making > happy use of Python the way it is. > Ben and Ned, I'd like to thank both of you for these comments as they are put far more eloquently and diplomatically than I would ever manage. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Thu Nov 26 01:41:25 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 08:41:25 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> Message-ID: <87si3t2rfu.fsf@elektro.pacujo.net> BartC <bc at freeuk.com>: > Clearly a huge amount of programming can be done without having to deal > with first-class functions (or constructing functions at run-time; that > sounds fun). (Or without using OOP, another thing I can't stand.) Even the lowliest code monkeys deal with on-the-fly functions and OOP nowadays. You can't escape them in C# and Java, for example. > Some people just don't want to be functional programmers. It is > elitist to try and make out it that it is that important. > > If lots of languages now have functional features, it's more likely to > be a case of keeping up with the Joneses. There's some of that. Generics and closures in Java are examples. However, anonymous classes have been there in Java since the dawn of days, and they are equally "elitist" as closures. Marko From orgnut at yahoo.com Thu Nov 26 01:44:41 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 25 Nov 2015 22:44:41 -0800 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <mailman.56.1448440353.20593.python-list@python.org> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> Message-ID: <DdSdnUfq3sfHN8vLnZ2dnUU7-XudnZ2d@giganews.com> On 11/25/2015 12:32 AM, Chris Angelico wrote: > On Wed, Nov 25, 2015 at 7:14 PM, Antoon Pardon > <antoon.pardon at rece.vub.ac.be> wrote: >> [snip] > > "Oh come on. It's basic arithmetic. You should be able to add 7 and > 7... the result's 14!" > > "But it's so confusing. Why can't it be 16? It'd be more convenient > for me if it were 16." No. It's 42. ;-) -=- Larry -=- <The Hitchhiker's Guide to the Galaxy says that's what *The Answer* is.> From marko at pacujo.net Thu Nov 26 01:52:07 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 08:52:07 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87oaeh2qy0.fsf@elektro.pacujo.net> Steven D'Aprano <steve at pearwood.info>: > Making tuples mutable would break their use as dictionary keys, which is a > *critical* use. No, it wouldn't. Any object that provides __hash__() and __eq__() can be used as a key. Nothing prevents using mutable objects as keys in Python. Egon Spengler: There's something very important I forgot to tell you. Peter Venkman: What? Spengler: Don't use mutable keys. Venkman: Why? Spengler: It would be bad. Venkman: I'm fuzzy on the whole good/bad thing. What do you mean, "bad"? Spengler: Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light. Ray Stantz: Total protonic reversal! Venkman: Right. That's bad. Okay. All right. Important safety tip. Thanks, Egon. Marko From Cecil at decebal.nl Thu Nov 26 01:55:51 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 26 Nov 2015 07:55:51 +0100 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.101.1448491194.20593.python-list@python.org> Message-ID: <87lh9ldzbc.fsf@Equus.decebal.nl> On Wednesday 25 Nov 2015 23:39 CET, Zachary Ware wrote: > On Wed, Nov 25, 2015 at 3:52 PM, Cecil Westerhof <Cecil at decebal.nl> wrote: >> My system python was all-ready damaged: that is why I wanted to >> build myself. > > Then you should try to repair the system Python install via the > system package manager. It's not worth the hassle to try to replace > it; it almost certainly won't work for some strange corner case that > won't bite you until 3 months from now. It's perfectly OK to have a > second Python install in /usr/local, even of the same version as the > system Python. I tried that. It did install things in /usr/lib and /usr/lib64, but nothing in /usr/bin. Thought to solve it this way, but I suppose I have to delve deeper in it. >> It is an openSUSE system. I installed the readline with: >> zypper install readline-devel >> >> The strange thing is that it does mot compile anymore now. I get: >> Python build finished, but the necessary bits to build these >> modules were not found: _bsddb _tkinter bsddb185 dbm dl gdbm >> imageop sunaudiodev To find the necessary bits, look in setup.py in >> detect_modules() for the module's name. > > Before you installed readline-devel, readline would have been listed > there as well. It's ok to have modules listed there if you don't I did not look good the first time then, because I do not remember having those messages. But I still get: ImportError: No module named readline -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Thu Nov 26 02:00:58 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 26 Nov 2015 08:00:58 +0100 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.102.1448492328.20593.python-list@python.org> Message-ID: <87h9k9dz2t.fsf@Equus.decebal.nl> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote: > In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof > writes: >> >> My system python was all-ready damaged: that is why I wanted to >> build myself. > > Your Suse system probably wants to use python for something. If your > system python is damaged, you badly need to fix that, using the > system package managers tools, before Suse does some sort of update > on you, using the broken python, which damages more of your system. I tried that. But it installs only things in /usr/lib and /usr/lib64, nothing in /usr/bin, but at the same time it is adamant that it installed python. I wanted a quick fix, but it looks like that is not going to work. :'-( I'll have to find a way to get things fixed. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Thu Nov 26 02:14:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 18:14:02 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87oaeh2qy0.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> Message-ID: <CAPTjJmpg+Lq8-Y4JErXV1zLXGe-VwfaGrnDtdENMD6OEFzo_UQ@mail.gmail.com> On Thu, Nov 26, 2015 at 5:52 PM, Marko Rauhamaa <marko at pacujo.net> wrote: > Steven D'Aprano <steve at pearwood.info>: > >> Making tuples mutable would break their use as dictionary keys, which is a >> *critical* use. > > No, it wouldn't. Any object that provides __hash__() and __eq__() can be > used as a key. > > Nothing prevents using mutable objects as keys in Python. > > Sure, you _can_. But if the key's hash changes between dict insertion and retrieval, all manner of invariants will break, and likewise if two equal objects have different hashes. From which you can deduce logically that any object used as a key must remain (not) equal to everything that it was (not) equal to from that time until it is looked up... which basically means its value mustn't change. It must be immutable. ChrisA From dieter at handshake.de Thu Nov 26 02:17:43 2015 From: dieter at handshake.de (dieter) Date: Thu, 26 Nov 2015 08:17:43 +0100 Subject: What does a list comprehension do References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <5655BCDB.4020905@rece.vub.ac.be> Message-ID: <877fl5ut48.fsf@handshake.de> Antoon Pardon <antoon.pardon at rece.vub.ac.be> writes: > Op 20-11-15 om 08:49 schreef dieter: >> In addition, the last few days have had two discussions in this list >> demonstrating the conceptial difficulties of late binding -- one of them: >> >> Why does "[lambda x: i * x for i in range(4)]" gives >> a list of essentially the same functions? > > Can you (or someone else) explain what a list comprehension is equivallent of. > Especially in python3. I am not sure about "Python3" (never used it), but in Python 2, the simple list comprehension "[x for x in l]" is roughly equivalent to: result = [] for x in l: result.append(x) ... the list comprehension result is in "result" which (however) is not bound ... In Python 3, "x" might not be bound as well - to harmonise list comprehension with generator expressions (and avoid the confusion, that a local (temporary) binding can change the value of a global binding). From antoon.pardon at rece.vub.ac.be Thu Nov 26 03:15:09 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 09:15:09 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <CALwzidngZMafqiWv-2dZPEsAP+5qVDST2fW0X8i5Y4m0YdJ3Uw@mail.gmail.com> References: <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> <5654864E.2070906@rece.vub.ac.be> <CAPTjJmoUtwHzOEwcObh5hzUDbz-713kVE_Kq-rg_bmYFHE_tYw@mail.gmail.com> <56549324.8020607@rece.vub.ac.be> <CALwzidmAKgmxjR=nDU4bPn5iy9AqCCiT=nTQYSORADCtpdM+SA@mail.gmail.com> <56549F15.40206@rece.vub.ac.be> <CALwzidkuiSfyXxiQ8H6YSEtEL5cqj6sOUPXdUru6n8XtGnvzug@mail.gmail.com> <5654B037.6020107@rece.vub.ac.be> <CALwzidkRj7G-W3UdtdczM10kHmHZ_qrdOoPNcJNjiw2QcNr0YQ@mail.gmail.com> <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <5655FDAC.4070305@rece.vub.ac.be> <CALwzidkkuQDfGCZUmEDuvLEwLwy27BsDvPaow_LVN_tFYt-1qg@mail.gmail.com> <5656229A.2000309@rece.vub.ac.be> <CALwzidngZMafqiWv-2dZPEsAP+5qVDST2fW0X8i5Y4m0YdJ3Uw@mail.gmail.com> Message-ID: <5656BF8D.3050701@rece.vub.ac.be> Op 25-11-15 om 23:38 schreef Ian Kelly: > On Wed, Nov 25, 2015 at 2:05 PM, Antoon Pardon > <antoon.pardon at rece.vub.ac.be> wrote: >> Op 25-11-15 om 21:39 schreef Ian Kelly: >> >>> I believe that sentence from the docs is using "some" to mean "not >>> all", whereas you are apparently using it to mean "any". >>> >>> frozenset([1,2,3]) constructs a constant value of a built-in type. >>> Would you consider that a literal? >> I am inclined to say yes, because a sufficient intelligent compilor >> can compute the value and store it do be retrieved and bound to a >> target when needed. > I'm curious then what you think of this: > > from collections import namedtuple > > class Point(namedtuple("Point", "x y")): pass > > Point(17, 12) > > Still a constant, but not a built-in type. Would you consider that a literal? I think I would answer no to that. In this case we have a user class. So the compilor has no intrinsic knowledge of the structure of this type. So the language has no choice but to construct the object at the moment of execution. -- Antoon. From marko at pacujo.net Thu Nov 26 03:27:13 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 10:27:13 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> Message-ID: <87a8q1f9ni.fsf@elektro.pacujo.net> Chris Angelico <rosuav at gmail.com>: > On Thu, Nov 26, 2015 at 5:52 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >> Nothing prevents using mutable objects as keys in Python. > > Sure, you _can_. But if the key's hash changes between dict insertion > and retrieval, all manner of invariants will break, and likewise if > two equal objects have different hashes. From which you can deduce > logically that any object used as a key must remain (not) equal to > everything that it was (not) equal to from that time until it is > looked up... which basically means its value mustn't change. It must > be immutable. What I'm saying is that Python does not prevent mutable keys but tries to do that with lists and tuples. I think Python should stop trying. I have wanted to use lists as keys, and there should be no reason to allow mutable tuples. It should be enough to say that the behavior of a dictionary is undefined if a key should mutate on the fly. Marko From steve+comp.lang.python at pearwood.info Thu Nov 26 03:29:20 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Nov 2015 19:29:20 +1100 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.102.1448492328.20593.python-list@python.org> <87h9k9dz2t.fsf@Equus.decebal.nl> Message-ID: <5656c2e0$0$11120$c3e8da3@news.astraweb.com> On Thursday 26 November 2015 18:00, Cecil Westerhof wrote: > On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote: > >> In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof >> writes: >>> >>> My system python was all-ready damaged: that is why I wanted to >>> build myself. >> >> Your Suse system probably wants to use python for something. If your >> system python is damaged, you badly need to fix that, using the >> system package managers tools, before Suse does some sort of update >> on you, using the broken python, which damages more of your system. > > I tried that. But it installs only things in /usr/lib and /usr/lib64, > nothing in /usr/bin, but at the same time it is adamant that it > installed python. I wanted a quick fix, but it looks like that is not > going to work. :'-( I'll have to find a way to get things fixed. > On the assumption that you are more interested in fixing your broken system than learning how to compile Python, what happens if you use the Suse package manager to re-install Python? e.g. zypper python or equivalent. -- Steve From antoon.pardon at rece.vub.ac.be Thu Nov 26 03:31:55 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 09:31:55 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> Message-ID: <5656C37B.4020801@rece.vub.ac.be> Op 26-11-15 om 02:52 schreef Ned Batchelder: > I almost started to explain about how yes, Python is often written in > conservative static ways. I was going to mention that a little dynamic > nature goes a long way, and is never far from the surface in even the > simplest Python programs. > > But I won't, because I'm not sure you're really interested. There's a > pattern here of people trying to explain Python to you, and eventually, > after many words, getting to some kind of shared understanding, only > for you to shrug it all off as a fad, or pocket-lining, or needless > complexity. > > For someone who claims to be interested in language design, you're > remarkably dismissive of pretty much the entire industry. I don't think > it's worth the effort to try to change your mind. I agree. I still think the regulars tend to react in a too defensive way when someone rather new dares to find fault with some python aspects. But if someone comes here and can't get over their bizarre first impression of some python aspects then there is not much reason to continue the discussion with them either. -- Antoon. From rosuav at gmail.com Thu Nov 26 03:34:47 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 19:34:47 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87a8q1f9ni.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> Message-ID: <CAPTjJmrc23hSo7Z7B42M0G2QV+VOFNon5O=nbGbxPThg4rw3hA@mail.gmail.com> On Thu, Nov 26, 2015 at 7:27 PM, Marko Rauhamaa <marko at pacujo.net> wrote: > Chris Angelico <rosuav at gmail.com>: > >> On Thu, Nov 26, 2015 at 5:52 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >>> Nothing prevents using mutable objects as keys in Python. >> >> Sure, you _can_. But if the key's hash changes between dict insertion >> and retrieval, all manner of invariants will break, and likewise if >> two equal objects have different hashes. From which you can deduce >> logically that any object used as a key must remain (not) equal to >> everything that it was (not) equal to from that time until it is >> looked up... which basically means its value mustn't change. It must >> be immutable. > > What I'm saying is that Python does not prevent mutable keys but tries > to do that with lists and tuples. > > I think Python should stop trying. > > I have wanted to use lists as keys, and there should be no reason to > allow mutable tuples. It should be enough to say that the behavior of a > dictionary is undefined if a key should mutate on the fly. Python defines dict-key-validity as being synonymous with hashability. It's up to the class author to make sure the object's hash is useful. Behaviour being undefined works just fine [1] in C. It's not so popular in Python. I don't think we want to have myriad new and experienced programmers trying to figure out why square brackets in dict keys are usually fine but occasionally not. ChrisA [1] For some definition of "fine", anyway. From antoon.pardon at rece.vub.ac.be Thu Nov 26 03:45:46 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 09:45:46 +0100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87a8q1f9ni.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> Message-ID: <5656C6BA.50404@rece.vub.ac.be> Op 26-11-15 om 09:27 schreef Marko Rauhamaa: > Chris Angelico <rosuav at gmail.com>: > >> On Thu, Nov 26, 2015 at 5:52 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >>> Nothing prevents using mutable objects as keys in Python. >> Sure, you _can_. But if the key's hash changes between dict insertion >> and retrieval, all manner of invariants will break, and likewise if >> two equal objects have different hashes. From which you can deduce >> logically that any object used as a key must remain (not) equal to >> everything that it was (not) equal to from that time until it is >> looked up... which basically means its value mustn't change. It must >> be immutable. > What I'm saying is that Python does not prevent mutable keys but tries > to do that with lists and tuples. > > I think Python should stop trying. > > I have wanted to use lists as keys, and there should be no reason to > allow mutable tuples. It should be enough to say that the behavior of a > dictionary is undefined if a key should mutate on the fly. Maybe python could introduce a dictionary that copies the keys in and out the dictionary. In that case keys can be mutable without that being a problem for the dictionary, because the dictionary works with it's own copy of the key that it doesn't mutate. -- Antoon. From rxjwg98 at gmail.com Thu Nov 26 04:02:19 2015 From: rxjwg98 at gmail.com (fl) Date: Thu, 26 Nov 2015 01:02:19 -0800 (PST) Subject: Question about output different with command dis.dis(code) Message-ID: <f0dc1c2c-6fda-4bd8-a71b-29db358afe14@googlegroups.com> Hi, I see the following from a previous post: Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import dis >>> code = compile("(1, 2, 3)", "", "eval") >>> dis.dis(code) 0 SET_LINENO 0 3 LOAD_CONST 0 (1) 6 LOAD_CONST 1 (2) 9 LOAD_CONST 2 (3) 12 BUILD_TUPLE 3 15 RETURN_VALUE When I run the above three line code, I get the following: dis.dis(code) 1 0 LOAD_CONST 3 ((1, 2, 3)) 3 RETURN_VALUE on my Windows 7 PC Canopy. Are there something, my input or Python difference make the output different? Thanks, From rosuav at gmail.com Thu Nov 26 04:09:30 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 20:09:30 +1100 Subject: Question about output different with command dis.dis(code) In-Reply-To: <f0dc1c2c-6fda-4bd8-a71b-29db358afe14@googlegroups.com> References: <f0dc1c2c-6fda-4bd8-a71b-29db358afe14@googlegroups.com> Message-ID: <CAPTjJmq1===o30TftEd+uRgw6=fWMmpCrtsRh2pvDPp4yB9htw@mail.gmail.com> On Thu, Nov 26, 2015 at 8:02 PM, fl <rxjwg98 at gmail.com> wrote: > Are there something, my input or Python difference > make the output different? Anything involving the disassembly of Python code depends heavily on internal interpreter details. You just quoted something showing that ancient versions of Python did at run-time what current versions have optimized to a compile-time construction (and thus the quick LOAD_CONST instead of the full work of building the tuple). If you switch to PyPy, Jython, IronPython, or some other implementation of the language, the byte code may be completely different - or may not be available at all. Using dis.dis is a great way of finding out what is actually happening, but it's never something you can depend on the stability of. ChrisA From random832 at fastmail.com Thu Nov 26 04:12:39 2015 From: random832 at fastmail.com (Random832) Date: Thu, 26 Nov 2015 04:12:39 -0500 Subject: Question about output different with command dis.dis(code) References: <f0dc1c2c-6fda-4bd8-a71b-29db358afe14@googlegroups.com> Message-ID: <m2lh9l86pk.fsf@fastmail.com> fl <rxjwg98 at gmail.com> writes: > Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat > 4.1.2-52)] on linux2 The context of the post was discussing the behavior of a very old version of python. I'm not sure how you missed this. > When I run the above three line code, I get the following: Further down in the same post you saw, he mentioned that modern versions of python do this, and showed the same output that you have. From df at see.replyto.invalid Thu Nov 26 05:34:43 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Thu, 26 Nov 2015 10:34:43 +0000 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> Message-ID: <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> Alan Bawden <alan at csail.mit.edu> wrote: >Chris Angelico <rosuav at gmail.com> writes: > ... >> Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46) >> [PyPy 2.4.0 with GCC 4.9.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>>> tuple([]) is tuple([]) >> False > >I said I wouldn't be suprised if it was always true, but that doesn't >imply that I need to be suprised if it is sometimes false! > >Having said that, I _am_ curious whether that remains False for various >other variant expressions. "tuple([])" is actually a rather perverse >way to obtain an empty tuple. How about plain "() is ()"? ... Still false in PyPy it seems [PyPy 2.6.1 with GCC 4.9.2] on linux2 >>>> id(()) 139836165383760L >>>> id(()) 139836165383776L (Conversely, I see that unlike CPython, all PyPy's numbers have unchanging ids, even after exiting PyPy and restarting, so it seems that PyPy's numerical ids are "faked".) [PyPy 2.6.1 with GCC 4.9.2] on linux2 >>>> id(1+2j) 679900119843984469027190799480815353863L [PyPy 2.6.1 with GCC 4.9.2] on linux2 >>>> id(1+2j) 679900119843984469027190799480815353863L From marko at pacujo.net Thu Nov 26 05:54:05 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 12:54:05 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> <mailman.120.1448526890.20593.python-list@python.org> Message-ID: <87610pf2uq.fsf@elektro.pacujo.net> Chris Angelico <rosuav at gmail.com>: > On Thu, Nov 26, 2015 at 7:27 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >> I have wanted to use lists as keys, and there should be no reason to >> allow mutable tuples. It should be enough to say that the behavior of >> a dictionary is undefined if a key should mutate on the fly. > > Python defines dict-key-validity as being synonymous with hashability. > It's up to the class author to make sure the object's hash is useful. >>> hash([]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list' Annoying. > Behaviour being undefined works just fine [1] in C. It's not so > popular in Python. I don't think we want to have myriad new and > experienced programmers trying to figure out why square brackets in > dict keys are usually fine but occasionally not. But there's no way to enforce that with any of the myriad new classes. Ye blind guides, which strain at a gnat, and swallow a camel. But I say unto you, Swallow the gnat as well. Marko From marko at pacujo.net Thu Nov 26 05:58:07 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 12:58:07 +0200 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> Message-ID: <871tbdf2o0.fsf@elektro.pacujo.net> Dave Farrance <df at see.replyto.invalid>: > (Conversely, I see that unlike CPython, all PyPy's numbers have > unchanging ids, even after exiting PyPy and restarting, so it seems > that PyPy's numerical ids are "faked".) What's a faked id? Marko From rosuav at gmail.com Thu Nov 26 06:04:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 22:04:06 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87610pf2uq.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> <mailman.120.1448526890.20593.python-list@python.org> <87610pf2uq.fsf@elektro.pacujo.net> Message-ID: <CAPTjJmoJSsbdTA=CUL+NPkv8=XL4UVpuStcoLXXoYM6maZnT2g@mail.gmail.com> On Thu, Nov 26, 2015 at 9:54 PM, Marko Rauhamaa <marko at pacujo.net> wrote: > Chris Angelico <rosuav at gmail.com>: > >> On Thu, Nov 26, 2015 at 7:27 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >>> I have wanted to use lists as keys, and there should be no reason to >>> allow mutable tuples. It should be enough to say that the behavior of >>> a dictionary is undefined if a key should mutate on the fly. >> >> Python defines dict-key-validity as being synonymous with hashability. >> It's up to the class author to make sure the object's hash is useful. > > >>> hash([]) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: unhashable type: 'list' > > Annoying. Yes, it's really annoying that you get an immediate exception instead of unpredictably getting bizarre failures that depend on the exact bucket sizes and dict size and so on. It's such a pain to get told exactly where the problem is. >> Behaviour being undefined works just fine [1] in C. It's not so >> popular in Python. I don't think we want to have myriad new and >> experienced programmers trying to figure out why square brackets in >> dict keys are usually fine but occasionally not. > > But there's no way to enforce that with any of the myriad new classes. Python tends to assume that programmers are intelligent people who are prepared to fix their mistakes. As a general rule, if you define __eq__, you should probably define __hash__ as well, and then you need to know what you're doing; specifically, the invariant that if a==b, hash(a)==hash(b). Python doesn't enforce that because it's impossible to enforce. ChrisA From df at see.replyto.invalid Thu Nov 26 06:07:06 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Thu, 26 Nov 2015 11:07:06 +0000 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.102.1448492328.20593.python-list@python.org> <87h9k9dz2t.fsf@Equus.decebal.nl> Message-ID: <pdpd5b9nn14apgog6pie58lhr2ivfo9i57@4ax.com> Cecil Westerhof <Cecil at decebal.nl> wrote: >On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote: >> >> Your Suse system probably wants to use python for something. If your >> system python is damaged, you badly need to fix that, using the >> system package managers tools, before Suse does some sort of update >> on you, using the broken python, which damages more of your system. > >I tried that. But it installs only things in /usr/lib and /usr/lib64, >nothing in /usr/bin, but at the same time it is adamant that it >installed python. I wanted a quick fix, but it looks like that is not >going to work. :'-( I'll have to find a way to get things fixed. A complete reinstall of Suse (after saving your home directory and work) might be quickest if you're in the dark about what's broken. But you might be able to fix it. If you can figure out which packages contain the damaged files, then do forced reinstalls of those. I've not used Suse, but a quick Google tells me that the syntax is: zypper in -f <package-name> So you'll want to try package names like "python" and "python2.7". From df at see.replyto.invalid Thu Nov 26 06:12:03 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Thu, 26 Nov 2015 11:12:03 +0000 Subject: What is a function parameter =[] for? References: <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> Message-ID: <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> Marko Rauhamaa <marko at pacujo.net> wrote: >Dave Farrance <df at see.replyto.invalid>: > >> (Conversely, I see that unlike CPython, all PyPy's numbers have >> unchanging ids, even after exiting PyPy and restarting, so it seems >> that PyPy's numerical ids are "faked".) > >What's a faked id? You can figure out what I'm getting at -- i.e. I presume that the ids are not pointers to stored numbers in memory (as with CPython) but are a translation of the numerical variable's value. From nobody at nowhere.invalid Thu Nov 26 06:13:44 2015 From: nobody at nowhere.invalid (Nobody) Date: Thu, 26 Nov 2015 11:13:44 +0000 Subject: What does a list comprehension do (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?)) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> Message-ID: <pan.2015.11.26.11.13.43.440000@nowhere.invalid> On Wed, 25 Nov 2015 14:51:23 +0100, Antoon Pardon wrote: > Am I missing something? The issue is with lambdas rather than with list comprehensions per se. Python's lambdas capture free variables by reference, not value. > x = 3 > f = lambda y: x + y > f(0) 3 > x = 7 > f(0) 7 The same issue applies to nested functions: > def foo(): = x = 3 = def f(y): = return x + y = print f(0) = x = 7 = print f(0) = > foo() 3 7 And also to non-nested functions (but most people expect that): > x = 3 > def f(y,x=x): = return x + y = > print f(0) 3 > x=7 > print f(0) 3 If you want to capture a variable by value, add a parameter with a default value using that variable: > def foo(): = x = 3 = def f(y, x=x): = return x + y = print f(0) = x = 7 = print f(0) = > foo() 3 3 This also works for lambdas: > x = 3 > f = lambda y,x=x: x + y > f(0) 3 > x = 7 > f(0) 3 Returning to the original expression: > q = [lambda x: i * x for i in range(4)] > q[0](1), q[3](1) (3, 3) > q = [lambda x,i=i: i * x for i in range(4)] > q[0](1), q[3](1) (0, 3) From breamoreboy at yahoo.co.uk Thu Nov 26 06:17:56 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 26 Nov 2015 11:17:56 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87oaeh2qy0.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> Message-ID: <n36pp8$82f$1@ger.gmane.org> On 26/11/2015 06:52, Marko Rauhamaa wrote: > Steven D'Aprano <steve at pearwood.info>: > >> Making tuples mutable would break their use as dictionary keys, which is a >> *critical* use. > > No, it wouldn't. Any object that provides __hash__() and __eq__() can be > used as a key. > Almost, see https://wiki.python.org/moin/DictionaryKeys. Under the title "Types Usable as Dictionary Keys" it states "The discussion above should explain why Python requires that: To be used as a dictionary key, an object must support the hash function (e.g. through __hash__), equality comparison (e.g. through __eq__ or __cmp__), and must satisfy the correctness condition above." The correctness condition is:- "For such a lookup algorithm to work correctly, the hash functions provided must guarantee that if two keys produce different hash values then the two key objects are not equivalent, that is, for all i1, i2, if hash(i1) != hash(i2), then i1 != i2" Aren't search engines just wonderful :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Thu Nov 26 06:23:23 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 13:23:23 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> <mailman.120.1448526890.20593.python-list@python.org> <87610pf2uq.fsf@elektro.pacujo.net> <mailman.127.1448535849.20593.python-list@python.org> Message-ID: <87wpt5dmxg.fsf@elektro.pacujo.net> Chris Angelico <rosuav at gmail.com>: > On Thu, Nov 26, 2015 at 9:54 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >> >> >>> hash([]) >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> TypeError: unhashable type: 'list' >> >> Annoying. > > Yes, it's really annoying that you get an immediate exception instead > of unpredictably getting bizarre failures that depend on the exact > bucket sizes and dict size and so on. It's such a pain to get told > exactly where the problem is. The problem is that lists don't have __hash__ and __eq__ defined. > Python tends to assume that programmers are intelligent people who are > prepared to fix their mistakes. It's not letting me in the case of list. Marko From ben+python at benfinney.id.au Thu Nov 26 06:24:25 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 Nov 2015 22:24:25 +1100 Subject: Object identity has no necessary connection to memory location (was: What is a function parameter =[] for?) References: <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> Message-ID: <85lh9l9f6e.fsf_-_@benfinney.id.au> Dave Farrance <df at see.replyto.invalid> writes: > Marko Rauhamaa <marko at pacujo.net> wrote: > > >Dave Farrance <df at see.replyto.invalid>: > > > >> (Conversely, I see that unlike CPython, all PyPy's numbers have > >> unchanging ids, even after exiting PyPy and restarting, so it seems > >> that PyPy's numerical ids are "faked".) > > > >What's a faked id? > > You can figure out what I'm getting at -- i.e. I presume that the ids > are not pointers to stored numbers in memory (as with CPython) but are > a translation of the numerical variable's value. Why refer to that as ?faked?? That's what I can't figure out about what you're getting at. Perhaps Marko shares my uncomprehension. The Python language makes no promise about ?pointers to stored numbers in memory? for object identity. That is an implementation detail of CPython, and is *explicitly* not promised for any other Python implementation. If you are surprised that object identity appears to have no connection with memory location, then you've made unwarranted assumptions that are explicitly warned against in the Python documentation. -- \ ?Absurdity, n. A statement or belief manifestly inconsistent | `\ with one's own opinion.? ?Ambrose Bierce, _The Devil's | _o__) Dictionary_, 1906 | Ben Finney From rosuav at gmail.com Thu Nov 26 06:24:44 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 22:24:44 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> References: <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> Message-ID: <CAPTjJmo0g7ssCxyiKdMffS-fRQ+03ataD-DOLjyJNH68PkUohA@mail.gmail.com> On Thu, Nov 26, 2015 at 10:12 PM, Dave Farrance <df at see.replyto.invalid> wrote: > Marko Rauhamaa <marko at pacujo.net> wrote: > >>Dave Farrance <df at see.replyto.invalid>: >> >>> (Conversely, I see that unlike CPython, all PyPy's numbers have >>> unchanging ids, even after exiting PyPy and restarting, so it seems >>> that PyPy's numerical ids are "faked".) >> >>What's a faked id? > > You can figure out what I'm getting at -- i.e. I presume that the ids > are not pointers to stored numbers in memory (as with CPython) but are a > translation of the numerical variable's value. As long as they're unique among concurrently-existing objects, that's fully compliant and not at all invalid. It might be generated in some way from its value, but that's safe as long as there's a scheme that keeps all other objects away from them. ChrisA From marko at pacujo.net Thu Nov 26 06:27:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 13:27:42 +0200 Subject: What is a function parameter =[] for? References: <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> Message-ID: <87si3tdmq9.fsf@elektro.pacujo.net> Dave Farrance <df at see.replyto.invalid>: > Marko Rauhamaa <marko at pacujo.net> wrote: >>What's a faked id? > > You can figure out what I'm getting at -- i.e. I presume that the ids > are not pointers to stored numbers in memory (as with CPython) but are > a translation of the numerical variable's value. CPython is within its rights to fake the ids. Marko From rosuav at gmail.com Thu Nov 26 06:35:54 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 22:35:54 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87wpt5dmxg.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> <mailman.120.1448526890.20593.python-list@python.org> <87610pf2uq.fsf@elektro.pacujo.net> <mailman.127.1448535849.20593.python-list@python.org> <87wpt5dmxg.fsf@elektro.pacujo.net> Message-ID: <CAPTjJmrYRP1C51WWtXkTC7MS2rNHE8=N68VWodTJc2V3iuZXpQ@mail.gmail.com> On Thu, Nov 26, 2015 at 10:23 PM, Marko Rauhamaa <marko at pacujo.net> wrote: > Chris Angelico <rosuav at gmail.com>: > >> On Thu, Nov 26, 2015 at 9:54 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >>> >>> >>> hash([]) >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in <module> >>> TypeError: unhashable type: 'list' >>> >>> Annoying. >> >> Yes, it's really annoying that you get an immediate exception instead >> of unpredictably getting bizarre failures that depend on the exact >> bucket sizes and dict size and so on. It's such a pain to get told >> exactly where the problem is. > > The problem is that lists don't have __hash__ and __eq__ defined. They do define equality. And it depends on their contents, ergo there cannot be a stable hash. This is NOT a problem. This is the concept of unhashability behaving EXACTLY CORRECTLY. Sorry to shout, but this is another case of refusing to accept what has been explained as having good reason, and I'm getting a little tired of it. >> Python tends to assume that programmers are intelligent people who are >> prepared to fix their mistakes. > > It's not letting me in the case of list. Actually it is. Your mistake is trying to use a list as a dict key. You have a solution available: use a tuple. ChrisA From rosuav at gmail.com Thu Nov 26 06:49:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Nov 2015 22:49:14 +1100 Subject: Object identity has no necessary connection to memory location (was: What is a function parameter =[] for?) In-Reply-To: <85lh9l9f6e.fsf_-_@benfinney.id.au> References: <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> <85lh9l9f6e.fsf_-_@benfinney.id.au> Message-ID: <CAPTjJmrBbJ8mo8LcdGywe256AEKt1QqGpGVk49nvTwPjXiWS9w@mail.gmail.com> On Thu, Nov 26, 2015 at 10:24 PM, Ben Finney <ben+python at benfinney.id.au> wrote: > Dave Farrance <df at see.replyto.invalid> writes: > >> Marko Rauhamaa <marko at pacujo.net> wrote: >> >> >Dave Farrance <df at see.replyto.invalid>: >> > >> >> (Conversely, I see that unlike CPython, all PyPy's numbers have >> >> unchanging ids, even after exiting PyPy and restarting, so it seems >> >> that PyPy's numerical ids are "faked".) >> > >> >What's a faked id? >> >> You can figure out what I'm getting at -- i.e. I presume that the ids >> are not pointers to stored numbers in memory (as with CPython) but are >> a translation of the numerical variable's value. > > Why refer to that as ?faked?? That's what I can't figure out about what > you're getting at. Perhaps Marko shares my uncomprehension. > > The Python language makes no promise about ?pointers to stored numbers > in memory? for object identity. That is an implementation detail of > CPython, and is *explicitly* not promised for any other Python > implementation. > > If you are surprised that object identity appears to have no connection > with memory location, then you've made unwarranted assumptions that are > explicitly warned against in the Python documentation. I can't remember which language it was (maybe Lua?), but I know there's one that uses a machine word to store either a pointer to a heap object, or an integer of at most one less bit than the machine word, represented by 2*n+1. A system like this would work for Python object IDs; it guarantees that all heap objects have unique even IDs (because no two can share the same address; all it takes is requiring 16-bit alignment, and most modern CPUs will give at least 32-bit), and all small integers will be slotted in between them. So the integer objects might themselves be entirely faked, never actually existing in memory, yet never violating the rule of object IDs. (Any integer too big to fit in a machine word minus one bit would be heap-allocated, so they're safe.) That's "faked", in a sense, but still perfectly compliant. ChrisA From df at see.replyto.invalid Thu Nov 26 06:50:15 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Thu, 26 Nov 2015 11:50:15 +0000 Subject: Object identity has no necessary connection to memory location (was: What is a function parameter =[] for?) References: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> <mailman.129.1448537076.20593.python-list@python.org> Message-ID: <1esd5bdujvog21u4qu6llhna5c3d573873@4ax.com> Ben Finney <ben+python at benfinney.id.au> wrote: >Dave Farrance <df at see.replyto.invalid> writes: > >> Marko Rauhamaa <marko at pacujo.net> wrote: >> >> >Dave Farrance <df at see.replyto.invalid>: >> > >> >> (Conversely, I see that unlike CPython, all PyPy's numbers have >> >> unchanging ids, even after exiting PyPy and restarting, so it seems >> >> that PyPy's numerical ids are "faked".) >> > >> >What's a faked id? >> >> You can figure out what I'm getting at -- i.e. I presume that the ids >> are not pointers to stored numbers in memory (as with CPython) but are >> a translation of the numerical variable's value. > >Why refer to that as ?faked?? That's what I can't figure out about what >you're getting at. Perhaps Marko shares my uncomprehension. Hence https://en.wikipedia.org/wiki/Scare_quotes From antoon.pardon at rece.vub.ac.be Thu Nov 26 06:52:45 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 12:52:45 +0100 Subject: What does a list comprehension do In-Reply-To: <pan.2015.11.26.11.13.43.440000@nowhere.invalid> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> Message-ID: <5656F28D.80803@rece.vub.ac.be> Op 26-11-15 om 12:13 schreef Nobody: > Returning to the original expression: > > > q = [lambda x: i * x for i in range(4)] > > q[0](1), q[3](1) > (3, 3) > > q = [lambda x,i=i: i * x for i in range(4)] > > q[0](1), q[3](1) > (0, 3) Personnaly I would prefer: >>> q = [(lambda i: lambda x: i * x)(i) for i in range(4)] >>> q[0](1), q[3](1) (0, 3) And this is where I ask whether it would be worth the effort to change the behaviour of python. In general the following two seem equivallent: [<expression> for x in <iter>] and [(lambda x: <expression>)(x) for x in <iter>] The only exceptions seems to be when <expression> is itself a lambda. It also seems that people who try this for the first time are surprised with what they get and seem to expect there list comprehension to act as if they had written the second version. So would it be advisable if python would translate the expression people write into a lambda that gets called? Are there issues that could come up? From marko at pacujo.net Thu Nov 26 07:03:47 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 14:03:47 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> <mailman.120.1448526890.20593.python-list@python.org> <87610pf2uq.fsf@elektro.pacujo.net> <mailman.127.1448535849.20593.python-list@python.org> <87wpt5dmxg.fsf@elektro.pacujo.net> <mailman.131.1448537758.20593.python-list@python.org> Message-ID: <87oaehdl24.fsf@elektro.pacujo.net> Chris Angelico <rosuav at gmail.com>: > On Thu, Nov 26, 2015 at 10:23 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >> It's not letting me in the case of list. > > Actually it is. Your mistake is trying to use a list as a dict key. > You have a solution available: use a tuple. Yes, or wrap the list in a class. Marko From antoon.pardon at rece.vub.ac.be Thu Nov 26 07:04:54 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 13:04:54 +0100 Subject: Object identity has no necessary connection to memory location In-Reply-To: <CAPTjJmrBbJ8mo8LcdGywe256AEKt1QqGpGVk49nvTwPjXiWS9w@mail.gmail.com> References: <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> <85lh9l9f6e.fsf_-_@benfinney.id.au> <CAPTjJmrBbJ8mo8LcdGywe256AEKt1QqGpGVk49nvTwPjXiWS9w@mail.gmail.com> Message-ID: <5656F566.6010306@rece.vub.ac.be> Op 26-11-15 om 12:49 schreef Chris Angelico: > I can't remember which language it was (maybe Lua?), but I know > there's one that uses a machine word to store either a pointer to a > heap object, or an integer of at most one less bit than the machine > word, represented by 2*n+1. I think that was smalltalk. From python at mrabarnett.plus.com Thu Nov 26 07:36:21 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Nov 2015 12:36:21 +0000 Subject: Looking for ideas to improve library API In-Reply-To: <CABMb9Gu+m9cJXQavXwxc0iouhsKsFSFKVvepLXhJcorc8aUkRw@mail.gmail.com> References: <CABMb9Gu+m9cJXQavXwxc0iouhsKsFSFKVvepLXhJcorc8aUkRw@mail.gmail.com> Message-ID: <5656FCC5.9000308@mrabarnett.plus.com> On 2015-11-25 20:52, Chris Lalancette wrote: > Hello, > I'm currently developing a library called pyiso ( > https://github.com/clalancette/pyiso), used for manipulating ISO disk > images. I'm pretty far along with it, but there is one part of the API > that I really don't like. > Typical usage of the library is something like: > > import pyiso > > p = pyiso.PyIso() // create the object > f = open('/path/to/original.iso', 'r') > p.open(f) // parse all of the metadata from the input ISO > fp = open('/path/to/file/to/add/to/iso', 'r') > p.add_fp(fp) // add a new file to the ISO > out = open('/path/to/modified.iso', 'w') > p.write(out) // write out the modified ISO to another file > out.close() > fp.close() > f.close() > > This currently works OK. The problem ends up being the file descriptor > lifetimes. I want the user to be able to do multiple operations to the > ISO, and I also don't want to read the entire ISO (and new files) into > memory. That means that internal to the library, I take a reference to the > file object that the user passes in during open() and add_fp(). This is > fine, unless the user decides to close the file object before calling the > write method, at which point the write complains of I/O to a closed file. > This is especially problematic when it comes to using context managers, > since the user needs to leave the context open until they call write(). > I've thought of a couple ways to deal with this: > > 1. Make a copy of the file object internal to the library, using os.dup() > to copy the file descriptor. This is kind of nasty, especially since I > want to support other kinds of file objects (think StringIO). > 2. Just document the fact that the user needs to leave the file objects > open until they are done. This is simple, but not super user-friendly. > > I'm looking for any ideas of how to do this better, or something I missed. > Any input is appreciated! > Why pass a file descriptor? Why not a filename? From jeanpierreda at gmail.com Thu Nov 26 07:46:34 2015 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 26 Nov 2015 04:46:34 -0800 Subject: Looking for ideas to improve library API In-Reply-To: <CABMb9Gu+m9cJXQavXwxc0iouhsKsFSFKVvepLXhJcorc8aUkRw@mail.gmail.com> References: <CABMb9Gu+m9cJXQavXwxc0iouhsKsFSFKVvepLXhJcorc8aUkRw@mail.gmail.com> Message-ID: <CABicbJJkNCTW6PAWw_P5mQmHAwysJaG49N8C+zLV9vKQkWB8_Q@mail.gmail.com> Why not take ownership of the file object, instead of requiring users to manage lifetimes? -- Devin On Wed, Nov 25, 2015 at 12:52 PM, Chris Lalancette <clalancette at gmail.com> wrote: > Hello, > I'm currently developing a library called pyiso ( > https://github.com/clalancette/pyiso), used for manipulating ISO disk > images. I'm pretty far along with it, but there is one part of the API > that I really don't like. > Typical usage of the library is something like: > > import pyiso > > p = pyiso.PyIso() // create the object > f = open('/path/to/original.iso', 'r') > p.open(f) // parse all of the metadata from the input ISO > fp = open('/path/to/file/to/add/to/iso', 'r') > p.add_fp(fp) // add a new file to the ISO > out = open('/path/to/modified.iso', 'w') > p.write(out) // write out the modified ISO to another file > out.close() > fp.close() > f.close() > > This currently works OK. The problem ends up being the file descriptor > lifetimes. I want the user to be able to do multiple operations to the > ISO, and I also don't want to read the entire ISO (and new files) into > memory. That means that internal to the library, I take a reference to the > file object that the user passes in during open() and add_fp(). This is > fine, unless the user decides to close the file object before calling the > write method, at which point the write complains of I/O to a closed file. > This is especially problematic when it comes to using context managers, > since the user needs to leave the context open until they call write(). > I've thought of a couple ways to deal with this: > > 1. Make a copy of the file object internal to the library, using os.dup() > to copy the file descriptor. This is kind of nasty, especially since I > want to support other kinds of file objects (think StringIO). > 2. Just document the fact that the user needs to leave the file objects > open until they are done. This is simple, but not super user-friendly. > > I'm looking for any ideas of how to do this better, or something I missed. > Any input is appreciated! > > Thanks, > Chris Lalancette > -- > https://mail.python.org/mailman/listinfo/python-list From bc at freeuk.com Thu Nov 26 07:53:27 2015 From: bc at freeuk.com (BartC) Date: Thu, 26 Nov 2015 12:53:27 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> Message-ID: <n36v80$1nt$1@dont-email.me> On 26/11/2015 01:52, Ned Batchelder wrote: > On Wednesday, November 25, 2015 at 8:23:36 PM UTC-5, BartC wrote: >> On 26/11/2015 00:31, Steven D'Aprano wrote: >>> It really, truly isn't. Your viewpoint is clouded by too much immersion in >>> crippled languages. *Old and obsolete versions* of crippled languages. >>> Dynamic creation of functions goes back to the 1950s. >> It's funny then that the vast majority of top-level function definitions >> I see in Python (and import and class statements too) are decidedly static. > I almost started to explain about how yes, Python is often written in > conservative static ways. I was going to mention that a little dynamic > nature goes a long way, and is never far from the surface in even the > simplest Python programs. > > But I won't, because I'm not sure you're really interested. There's a > pattern here of people trying to explain Python to you, and eventually, > after many words, getting to some kind of shared understanding, only > for you to shrug it all off as a fad, or pocket-lining, or needless > complexity. I'm sorry if I've been misunderstood. I simply stated that Python's approach was novel. Steven D'Aprano then responded by belittling my view, and effectively trashing every language I've ever used. But as it happens I do think features like first class functions are overrated (and probably the software underpinning the hardware we're all using is written in the very languages he despises). I don't think a language is worthless without such a feature. > For someone who claims to be interested in language design, you're > remarkably dismissive of pretty much the entire industry. I don't think > it's worth the effort to try to change your mind. I did say somewhere in this thread or the other one, that I liked Python's model well enough that I tried to emulate it in my own language. That's not being dismissive! (It don't work because the languages are too different internally; I'll have to save it for a separate, higher-level language.) Also, as an implementer, you can understand that I might view certain features differently from other people. Dynamic features do make it harder to implement things efficiently, and you have to decide whether it's worthwhile for the 1% of the time they might be used. ------------------------------------------ FWIW here is that list of features that are different between Python and my language, or that work a different way, or that I think could be a useful addition. (Although Python's internal workings make many impractical.) http://pastebin.com/JrVTher6 This is not an attempt to compare the complete languages as they are for different purposes (mine is more low-level, simpler, smaller and designed to make it easier to create an efficient byte-code interpreter for it). -- Bartc From framstag at rus.uni-stuttgart.de Thu Nov 26 07:54:58 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Thu, 26 Nov 2015 12:54:58 +0000 (UTC) Subject: fexit: file transfer of ANY size Message-ID: <n36vf2$86s$1@news2.informatik.uni-stuttgart.de> In the last weeks I have asked here some beginners questions and got great response. I was able to solve all my problems. Now, my first real Python program is ready: fexit, a F*EX client. And what is F*EX? ==> Frams' Fast File EXchange, a service for transfering files of ANY size from any user A to any user B in the internet. For details see: http://fex.rus.uni-stuttgart.de/ I am now looking for beta testers. If you are interested, send me a mail. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From marko at pacujo.net Thu Nov 26 07:56:58 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 14:56:58 +0200 Subject: What does a list comprehension do References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> <mailman.132.1448538769.20593.python-list@python.org> Message-ID: <87k2p4ex5x.fsf@elektro.pacujo.net> Antoon Pardon <antoon.pardon at rece.vub.ac.be>: > Personnaly I would prefer: > >>>> q = [(lambda i: lambda x: i * x)(i) for i in range(4)] >>>> q[0](1), q[3](1) > (0, 3) > > And this is where I ask whether it would be worth the effort to change > the behaviour of python. Don't go there. Consider: q = [] n = 0 x = "hello" for i in range(4): def stepper(): global n n += 1 return i * x q.append(stepper) print(n) print(q[1]()) print(n) x = "there" print(q[3]()) print(n) which prints: 0 hellohellohello 1 theretherethere 2 after your change, you'd get: 0 hello 0 hellohellohello 0 > It also seems that people who try this for the first time are > surprised with what they get and seem to expect there list > comprehension to act as if they had written the second version. I might trip over that one, too. Still, nothing should be changed. Marko From rosuav at gmail.com Thu Nov 26 08:15:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Nov 2015 00:15:10 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <n36v80$1nt$1@dont-email.me> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> Message-ID: <CAPTjJmr81apSbw1=YxqAP0BSRHgHuC=fsQr5EL2hOVvWOOrVQA@mail.gmail.com> On Thu, Nov 26, 2015 at 11:53 PM, BartC <bc at freeuk.com> wrote: > FWIW here is that list of features that are different between Python and my > language, or that work a different way, or that I think could be a useful > addition. (Although Python's internal workings make many impractical.) > > http://pastebin.com/JrVTher6 > > This is not an attempt to compare the complete languages as they are for > different purposes (mine is more low-level, simpler, smaller and designed to > make it easier to create an efficient byte-code interpreter for it). "I think Python now has hex, octal and binary literals. X allows any base from 2 to 16: 2x10101 is binary, while 4x101 is quaternary (ie. 20)." Do you mean that 4x101 means 1*(4*4) + 0*(4) + 1? If so, it would be 17, not 20. Is this a typo in the document, or am I misunderstanding your syntax? #14 and #15: Are you assuming that a character is a byte and that diacritical-free English is the only language in the world? Case insensitivity is a *pain* when you try to be language-agnostic; for instance, the case-folding rules of English state that U+0069 LATIN SMALL LETTER I and U+0049 LATIN CAPITAL LETTER I are identical, but Turkish would upper-case the first to U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE and lower-case the second to U+0131 LATIN SMALL LETTER DOTLESS I. German has U+00DF LATIN SMALL LETTER SHARP S (also called eszett), which traditionally upper-cases to "SS", which lower-cases to "ss". ChrisA From gordon at panix.com Thu Nov 26 08:25:41 2015 From: gordon at panix.com (John Gordon) Date: Thu, 26 Nov 2015 13:25:41 +0000 (UTC) Subject: if else python References: <mailman.51.1448431821.20593.python-list@python.org> Message-ID: <n3718l$7an$1@reader1.panix.com> In <mailman.51.1448431821.20593.python-list at python.org> Scott Montreuil <scott at zml.ca> writes: > I have an if statement which seems to run both commands and I cannot > figure out why. I'm not sure what you mean by "both commands". Do you mean that the 'if' and 'else' branches both execute? Your if/else branches are in a loop, so perhaps you're seeing the 'if' branch on one loop iteration, anf the 'else' branch on the next iteration? I see that your if and else branches both contain a screen.addstr() call. Are you seeing both of these outputs? -- 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 clalancette at gmail.com Thu Nov 26 08:33:46 2015 From: clalancette at gmail.com (Chris Lalancette) Date: Thu, 26 Nov 2015 08:33:46 -0500 Subject: Looking for ideas to improve library API In-Reply-To: <5656FCC5.9000308@mrabarnett.plus.com> References: <CABMb9Gu+m9cJXQavXwxc0iouhsKsFSFKVvepLXhJcorc8aUkRw@mail.gmail.com> <5656FCC5.9000308@mrabarnett.plus.com> Message-ID: <CABMb9Gt_oeajB+G2A4Lw=Lp6tfgcj=Yf5kCunGcGu25oFYPFVA@mail.gmail.com> On Thu, Nov 26, 2015 at 7:36 AM, MRAB <python at mrabarnett.plus.com> wrote: > Why pass a file descriptor? Why not a filename? The reason for a file descriptor is so that I can also add other file-like objects, such as StringIO. My unit tests, for instance, rely heavily on this. That being said, it is not *strictly* required (my unit tests could be modified to write to temporary files), but I thought it was a nice feature. Chris From antoon.pardon at rece.vub.ac.be Thu Nov 26 08:33:59 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 14:33:59 +0100 Subject: What does a list comprehension do In-Reply-To: <87k2p4ex5x.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> <mailman.132.1448538769.20593.python-list@python.org> <87k2p4ex5x.fsf@elektro.pacujo.net> Message-ID: <56570A47.4050304@rece.vub.ac.be> Op 26-11-15 om 13:56 schreef Marko Rauhamaa: > Antoon Pardon <antoon.pardon at rece.vub.ac.be>: > >> Personnaly I would prefer: >> >>>>> q = [(lambda i: lambda x: i * x)(i) for i in range(4)] >>>>> q[0](1), q[3](1) >> (0, 3) >> >> And this is where I ask whether it would be worth the effort to change >> the behaviour of python. > Don't go there. > > Consider: > > q = [] > n = 0 > x = "hello" > > for i in range(4): > def stepper(): > global n > n += 1 > return i * x > q.append(stepper) > > print(n) > print(q[1]()) > print(n) > x = "there" > print(q[3]()) > print(n) > > which prints: > > 0 > hellohellohello > 1 > theretherethere > 2 > > after your change, you'd get: > > 0 > hello > 0 > hellohellohello > 0 I don't understand. What I propose would be a minor change in how list comprehension works. I don't see how your example can be turned into a list comprehension. I can of course put the stepper function out of the for loop and then convert the for loop into a list comprehension. The results in that case is that my proposed change wouldn't effect the results in python2 and that the code wouldn't run in python3. So could you clarify what list comprehension you are talking about, that you think would cause trouble, should my proposal be adopted. -- Antoon. From clalancette at gmail.com Thu Nov 26 08:35:20 2015 From: clalancette at gmail.com (Chris Lalancette) Date: Thu, 26 Nov 2015 08:35:20 -0500 Subject: Looking for ideas to improve library API In-Reply-To: <CABicbJJkNCTW6PAWw_P5mQmHAwysJaG49N8C+zLV9vKQkWB8_Q@mail.gmail.com> References: <CABMb9Gu+m9cJXQavXwxc0iouhsKsFSFKVvepLXhJcorc8aUkRw@mail.gmail.com> <CABicbJJkNCTW6PAWw_P5mQmHAwysJaG49N8C+zLV9vKQkWB8_Q@mail.gmail.com> Message-ID: <CABMb9GtR_WVngUUmNAVP83vXJbUZK40REfUBeBpCn3XL2YFaPw@mail.gmail.com> On Thu, Nov 26, 2015 at 7:46 AM, Devin Jeanpierre <jeanpierreda at gmail.com> wrote: > Why not take ownership of the file object, instead of requiring users > to manage lifetimes? Yeah, I've kind of been coming to this conclusion. So my question then becomes: how do I "take ownership" of it? I already keep a reference to it, but how would I signal to the API user that they should no longer use that file object (other than documentation)? Thanks, Chris From marko at pacujo.net Thu Nov 26 08:56:41 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 15:56:41 +0200 Subject: What does a list comprehension do References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> <mailman.132.1448538769.20593.python-list@python.org> <87k2p4ex5x.fsf@elektro.pacujo.net> <mailman.138.1448544914.20593.python-list@python.org> Message-ID: <87fuzseuee.fsf@elektro.pacujo.net> Antoon Pardon <antoon.pardon at rece.vub.ac.be>: > I don't understand. What I propose would be a minor change in > how list comprehension works. I don't see how your example > can be turned into a list comprehension. The list comprehension is only a special case of the interaction between closures and variables. If you dabble with list comprehensions and lambdas, you'll need to make consistent changes in closure semantics. That would lead to the trouble I mentioned. Closures need to have dynamic access to the variables they refer to. This whole issue is a consequence of Python's assignment semantics. If Python didn't allow altering the values of variables, we wouldn't be having this discussion. BTW, all(!?) other languages from Java to Scheme share closure semantics with Python so you would really be making a mess by changing Python. Marko From antoon.pardon at rece.vub.ac.be Thu Nov 26 09:26:47 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 15:26:47 +0100 Subject: What does a list comprehension do In-Reply-To: <87fuzseuee.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> <mailman.132.1448538769.20593.python-list@python.org> <87k2p4ex5x.fsf@elektro.pacujo.net> <mailman.138.1448544914.20593.python-list@python.org> <87fuzseuee.fsf@elektro.pacujo.net> Message-ID: <565716A7.4080707@rece.vub.ac.be> Op 26-11-15 om 14:56 schreef Marko Rauhamaa: > Antoon Pardon <antoon.pardon at rece.vub.ac.be>: > >> I don't understand. What I propose would be a minor change in >> how list comprehension works. I don't see how your example >> can be turned into a list comprehension. > The list comprehension is only a special case of the interaction between > closures and variables. If you dabble with list comprehensions and > lambdas, you'll need to make consistent changes in closure semantics. It would only dabble with the list comprehension not with the lambda. The effect of the change would only be that a list comprehension like [ <expression> for <var> in <iter> ] would implicitly be rewritten as follows: [ (lambda <var>: <expression>)(<var>) for <var> in <iter>] There would no change on how lambdas work or functions or closures. > BTW, all(!?) other languages from Java to Scheme share closure semantics > with Python so you would really be making a mess by changing Python. Not this proposal, which wouldn't touch closure semantics. -- Antoon. From bc at freeuk.com Thu Nov 26 09:40:15 2015 From: bc at freeuk.com (BartC) Date: Thu, 26 Nov 2015 14:40:15 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <mailman.140.1448547231.20593.python-list@python.org> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> <mailman.140.1448547231.20593.python-list@python.org> Message-ID: <n375g8$pvv$1@dont-email.me> On 26/11/2015 13:15, Chris Angelico wrote: > On Thu, Nov 26, 2015 at 11:53 PM, BartC <bc at freeuk.com> wrote: >> FWIW here is that list of features that are different between Python and my >> language, or that work a different way, or that I think could be a useful >> addition. (Although Python's internal workings make many impractical.) >> >> http://pastebin.com/JrVTher6 >> >> This is not an attempt to compare the complete languages as they are for >> different purposes (mine is more low-level, simpler, smaller and designed to >> make it easier to create an efficient byte-code interpreter for it). > > "I think Python now has hex, octal and binary literals. X allows any > base from 2 to 16: 2x10101 is binary, while 4x101 is quaternary (ie. > 20)." > > Do you mean that 4x101 means 1*(4*4) + 0*(4) + 1? If so, it would be > 17, not 20. Is this a typo in the document, or am I misunderstanding > your syntax? Just a mistake. The example had been 4x100 which is 16, but I changed it to 4x101 for a bit less confusion, which as you say is 17 not 20 which is 4x110. (Although not used much, I have used quaternary here for example: 4x3032_3233_2323 The digits represent the number of extra days more than 28 in each month, from Jan to Dec.) -- Bartc From denismfmcmahon at gmail.com Thu Nov 26 09:49:39 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Nov 2015 14:49:39 -0000 (UTC) Subject: Screen scraper to get all 'a title' elements References: <23ed6f4b-0ef2-4c9e-ade6-e597e7e03ca2@googlegroups.com> Message-ID: <n37663$h02$1@dont-email.me> On Wed, 25 Nov 2015 12:42:00 -0800, ryguy7272 wrote: > Hello experts. I'm looking at this url: > https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names > > I'm trying to figure out how to list all 'a title' elements. a is the element tag, title is an attribute of the htmlanchorelement. combining bs4 with python structures allows you to find all the specified attributes of an element type, for example to find the class attributes of all the paragraphs with a class attribute: stuff = [p.attrs['class'] for p in soup.find_all('p') if 'class' in p.attrs] Then you can do this for thing in stuff: print thing (Python 2.7) This may be adaptable to your requirement. -- Denis McMahon, denismfmcmahon at gmail.com From lac at openend.se Thu Nov 26 10:20:50 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 26 Nov 2015 16:20:50 +0100 Subject: Python on windows 10 In-Reply-To: <CY1PR13MB0809508315283B56278491A7AA050@CY1PR13MB0809.namprd13.prod.outlook.com> References: <CY1PR13MB0809508315283B56278491A7AA050@CY1PR13MB0809.namprd13.prod.outlook.com> Message-ID: <201511261520.tAQFKodc009450@fido.openend.se> In a message of Wed, 25 Nov 2015 20:34:01 +0000, francis funari writes: >I have tried installing Python 3 on windows 10 it install OK but I do not get Idle. When I type Idle in the interpreter nothing happen can you send me a link to latest release of Python 3 with Idle that will run on windows 10 64 bit > Thankyou Francis Funari > >Sent from Mail<http://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10 >-- >https://mail.python.org/mailman/listinfo/python-list Sorry to hear you are having problems. Can you please go to a command window and type python -m idlelib This should fail. However, it should fail with a meaningful traceback which indicates where the problem is. Copy and paste that traceback into mail and post that here so we have proceed. If 'python' isn't the command you need to use to get python3.5 perhaps py -3.5 -m idlelib will work. But the idea is we want to catch idle failing, so we can figure out what is going on. Laura Creighton From tjreedy at udel.edu Thu Nov 26 10:24:37 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Nov 2015 10:24:37 -0500 Subject: Python on windows 10 In-Reply-To: <CY1PR13MB0809508315283B56278491A7AA050@CY1PR13MB0809.namprd13.prod.outlook.com> References: <CY1PR13MB0809508315283B56278491A7AA050@CY1PR13MB0809.namprd13.prod.outlook.com> Message-ID: <n37886$nls$1@ger.gmane.org> On 11/25/2015 3:34 PM, francis funari wrote: > I have tried installing Python 3 on windows 10 it install OK but I do > not get Idle. When I type Idle in the interpreter nothing happen Starting programs by typing their names into the interactive interpreter does not work. Use Start Menu | All Apps | Python 3.5 | IDLE (...). You can make this a Start Menu 'favorite' or create a Desktop icon. Typing 'idle' in the Command Prompt console may also work. Typing 'python -m idlelib' should work. After I start IDLE once I pin it to the taskbar since I use it constantly. -- Terry Jan Reedy From marko at pacujo.net Thu Nov 26 10:36:33 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 17:36:33 +0200 Subject: What does a list comprehension do References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> <mailman.132.1448538769.20593.python-list@python.org> <87k2p4ex5x.fsf@elektro.pacujo.net> <mailman.138.1448544914.20593.python-list@python.org> <87fuzseuee.fsf@elektro.pacujo.net> <mailman.141.1448548095.20593.python-list@python.org> Message-ID: <87k2p43h8e.fsf@elektro.pacujo.net> Antoon Pardon <antoon.pardon at rece.vub.ac.be>: > [ <expression> for <var> in <iter> ] > > would implicitly be rewritten as follows: > > [ (lambda <var>: <expression>)(<var>) for <var> in <iter>] Funny enough, that's how "list comprehensions" are created in Scheme: (map (lambda (i) (lambda (x) (* i x))) '(0 1 2 3)))) > There would no change on how lambdas work or functions or closures. First of all, it's weird to spend any effort in trying to alter a very special case. I don't recall having to generate a list of such functions. In fact, I barely ever use lambda in Python; explicit def statements are much more pleasing to the eye and are not restricted to simple expressions. Secondly, you'd lose the nice symmetry between for statements and comprehensions/generators. For example: ( lambda x: i * x for i in range(4) ) corresponds to: for i in range(4): yield lambda x: i * x Would you embed an extra lambda there, too? How about: i = 0 while i < 4: yield lambda x: i * x i += 1 or: for i in range(4): def f(x): return i * x yield f Marko From gandalf at shopzeus.com Thu Nov 26 10:56:21 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 26 Nov 2015 16:56:21 +0100 Subject: ANN: tornadostreamform Message-ID: <56572BA5.1080705@shopzeus.com> Pure python module that let?s you upload *huge* files to a tornado web server. This project provides the |tornadostreamform.multipart_streamer.MultiPartStreamer| class that incrementally parses incoming multipart/form-data, splits it into form fields, and streams the fields into file like objects (temp file, opened pipe, network socket etc.) With this class, it is possible to POST/PUT large files to a tornado server, without loading anything big into memory. Can be used as an alternative to the ngnx large file upload extension (especially when you want to stream files into process pipes). The PyPi package contains the classes only. The bitbucket repository contains some examples. PyPi: https://pypi.python.org/pypi/tornadostreamform Documentation: https://pypi.python.org/pypi/tornadostreamform Repository: https://bitbucket.org/nagylzs/tornadostreamform Cheers, Laszlo From gandalf at shopzeus.com Thu Nov 26 10:56:59 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 26 Nov 2015 16:56:59 +0100 Subject: ANN: tornadostreamform In-Reply-To: <56572BA5.1080705@shopzeus.com> References: <56572BA5.1080705@shopzeus.com> Message-ID: <56572BCB.4030605@shopzeus.com> > PyPi: https://pypi.python.org/pypi/tornadostreamform > Documentation: https://pypi.python.org/pypi/tornadostreamform Wrong paste. Here is the good one: https://pythonhosted.org/tornadostreamform/ From harvest at is.invalid Thu Nov 26 11:11:57 2015 From: harvest at is.invalid (Jussi Piitulainen) Date: Thu, 26 Nov 2015 18:11:57 +0200 Subject: What does a list comprehension do References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> <mailman.132.1448538769.20593.python-list@python.org> <87k2p4ex5x.fsf@elektro.pacujo.net> <mailman.138.1448544914.20593.python-list@python.org> <87fuzseuee.fsf@elektro.pacujo.net> <mailman.141.1448548095.20593.python-list@python.org> Message-ID: <lf5vb8oyc36.fsf@ling.helsinki.fi> Antoon Pardon writes: > Op 26-11-15 om 14:56 schreef Marko Rauhamaa: >> Antoon Pardon wrote: >> >>> I don't understand. What I propose would be a minor change in how >>> list comprehension works. I don't see how your example can be turned >>> into a list comprehension. >> >> The list comprehension is only a special case of the interaction >> between closures and variables. If you dabble with list >> comprehensions and lambdas, you'll need to make consistent changes in >> closure semantics. > > It would only dabble with the list comprehension not with the lambda. > The effect of the change would only be that a list comprehension like > > [ <expression> for <var> in <iter> ] > > would implicitly be rewritten as follows: > > [ (lambda <var>: <expression>)(<var>) for <var> in <iter>] > > There would no change on how lambdas work or functions or closures. > >> BTW, all(!?) other languages from Java to Scheme share closure semantics >> with Python so you would really be making a mess by changing Python. > > Not this proposal, which wouldn't touch closure semantics. It needs to take into account the possibility of more than one variable, but that's a minor adjustment. I like it. It's simple enough. The following code exercises different values from nested comprehension loops, together with a shared global whose value actually changes before each call to one of the listed thunks. m = "good morning to you" thoughts = [ (lambda n, u : ((lambda : (u//2)*m), (lambda : n))) (n, u) for n in range(10) if n % 2 # odd? for u in range(10) if u % 2 - 1 # less odd? if n < u ] for t, g in zip(thoughts, ((["hello"], ["eiku"], ["hej"]) + tuple(20 * "."))): m = g message, number = t print(number(), *message()) # Prints: 1 hello 1 eiku eiku 1 hej hej hej 1 . . . . 3 . . 3 . . . 3 . . . . 5 . . . 5 . . . . 7 . . . . From python at mrabarnett.plus.com Thu Nov 26 11:14:21 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Nov 2015 16:14:21 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <n375g8$pvv$1@dont-email.me> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> <mailman.140.1448547231.20593.python-list@python.org> <n375g8$pvv$1@dont-email.me> Message-ID: <56572FDD.8000301@mrabarnett.plus.com> On 2015-11-26 14:40, BartC wrote: > On 26/11/2015 13:15, Chris Angelico wrote: >> On Thu, Nov 26, 2015 at 11:53 PM, BartC <bc at freeuk.com> wrote: >>> FWIW here is that list of features that are different between Python and my >>> language, or that work a different way, or that I think could be a useful >>> addition. (Although Python's internal workings make many impractical.) >>> >>> http://pastebin.com/JrVTher6 >>> >>> This is not an attempt to compare the complete languages as they are for >>> different purposes (mine is more low-level, simpler, smaller and designed to >>> make it easier to create an efficient byte-code interpreter for it). >> >> "I think Python now has hex, octal and binary literals. X allows any >> base from 2 to 16: 2x10101 is binary, while 4x101 is quaternary (ie. >> 20)." >> >> Do you mean that 4x101 means 1*(4*4) + 0*(4) + 1? If so, it would be >> 17, not 20. Is this a typo in the document, or am I misunderstanding >> your syntax? > > Just a mistake. The example had been 4x100 which is 16, but I changed it > to 4x101 for a bit less confusion, which as you say is 17 not 20 which > is 4x110. > > (Although not used much, I have used quaternary here for example: > > 4x3032_3233_2323 > > The digits represent the number of extra days more than 28 in each > month, from Jan to Dec.) > Smalltalk uses "r" (for "radix") rather than "x", and can handle any base from 2 to 36. From python at mrabarnett.plus.com Thu Nov 26 11:16:57 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Nov 2015 16:16:57 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <n36v80$1nt$1@dont-email.me> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> Message-ID: <56573079.5000401@mrabarnett.plus.com> On 2015-11-26 12:53, BartC wrote: > On 26/11/2015 01:52, Ned Batchelder wrote: >> On Wednesday, November 25, 2015 at 8:23:36 PM UTC-5, BartC wrote: >>> On 26/11/2015 00:31, Steven D'Aprano wrote: > >>>> It really, truly isn't. Your viewpoint is clouded by too much immersion in >>>> crippled languages. *Old and obsolete versions* of crippled languages. >>>> Dynamic creation of functions goes back to the 1950s. > >>> It's funny then that the vast majority of top-level function definitions >>> I see in Python (and import and class statements too) are decidedly static. > >> I almost started to explain about how yes, Python is often written in >> conservative static ways. I was going to mention that a little dynamic >> nature goes a long way, and is never far from the surface in even the >> simplest Python programs. >> >> But I won't, because I'm not sure you're really interested. There's a >> pattern here of people trying to explain Python to you, and eventually, >> after many words, getting to some kind of shared understanding, only >> for you to shrug it all off as a fad, or pocket-lining, or needless >> complexity. > > I'm sorry if I've been misunderstood. > > I simply stated that Python's approach was novel. Steven D'Aprano then > responded by belittling my view, and effectively trashing every language > I've ever used. > [snip] Well, it's not /that/ new. Both Forth and PostScript define functions by execution. From jorge.conrado at cptec.inpe.br Thu Nov 26 12:15:43 2015 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Thu, 26 Nov 2015 15:15:43 -0200 Subject: read 4D binary data Message-ID: <4d15f12abb4c4781168ce05d3b450f63@cptec.inpe.br> Hi, I'm startig in Python and I have a 4D binary data. The dimension of my data is: 67 ----> longitude points 41 ----> latitude points 10 ----> pressure levels points 33 ----> time points How can I read this data and what can I do to get a 2D array (longitude,latitude) for a specific pressure and time dimension. Conrado From breamoreboy at yahoo.co.uk Thu Nov 26 12:43:34 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 26 Nov 2015 17:43:34 +0000 Subject: read 4D binary data In-Reply-To: <4d15f12abb4c4781168ce05d3b450f63@cptec.inpe.br> References: <4d15f12abb4c4781168ce05d3b450f63@cptec.inpe.br> Message-ID: <n37gca$u5b$1@ger.gmane.org> On 26/11/2015 17:15, jorge.conrado at cptec.inpe.br wrote: > Hi, > > > I'm startig in Python and I have a 4D binary data. The dimension of my > data is: > > 67 ----> longitude points > 41 ----> latitude points > 10 ----> pressure levels points > 33 ----> time points > > > How can I read this data and what can I do to get a 2D array > (longitude,latitude) for a specific pressure and time dimension. > > > Conrado To open a file to access the contents https://docs.python.org/3/library/functions.html#open If the data is in CSV format see https://docs.python.org/3/library/csv.html For your data structure lists https://docs.python.org/3/library/stdtypes.html#lists and dicts https://docs.python.org/3/library/stdtypes.html#mapping-types-dict are always the first port of call. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From denismfmcmahon at gmail.com Thu Nov 26 12:52:16 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Nov 2015 17:52:16 -0000 (UTC) Subject: read 4D binary data References: <mailman.148.1448558147.20593.python-list@python.org> Message-ID: <n37gsf$h02$5@dont-email.me> On Thu, 26 Nov 2015 15:15:43 -0200, jorge.conrado wrote: > I'm startig in Python and I have a 4D binary data. The dimension of my > data is: > > 67 ----> longitude points 41 ----> latitude points 10 ----> pressure > levels points 33 ----> time points > > How can I read this data and what can I do to get a 2D array > (longitude,latitude) for a specific pressure and time dimension. First of all, define the data structure you want to create. I would have thought that for any given time, you would want a 2d array containing the pressure at each point (given by lat and lon) at that time. -- Denis McMahon, denismfmcmahon at gmail.com From lac at openend.se Thu Nov 26 13:00:35 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 26 Nov 2015 19:00:35 +0100 Subject: read 4D binary data In-Reply-To: <4d15f12abb4c4781168ce05d3b450f63@cptec.inpe.br> References: <4d15f12abb4c4781168ce05d3b450f63@cptec.inpe.br> Message-ID: <201511261800.tAQI0ZIO011744@fido.openend.se> In a message of Thu, 26 Nov 2015 15:15:43 -0200, jorge.conrado at cptec.inpe.br wr ites: >Hi, > > >I'm startig in Python and I have a 4D binary data. The dimension of my >data is: > >67 ----> longitude points >41 ----> latitude points >10 ----> pressure levels points >33 ----> time points > > >How can I read this data and what can I do to get a 2D array >(longitude,latitude) for a specific pressure and time dimension. > > >Conrado If your binary data is all of the same type -- these are all floats, or all ints -- you can use the python array module to read it. https://docs.python.org/3/library/array.html If they are heterogenous then you cannot use array, but can use struct https://docs.python.org/3.5/library/struct.html If I were you, I would want to get my data into pandas, which is the best tool for data analysis http://pandas.pydata.org/ And I would do this pretty much exactly as Albert Jan outlines in this stackoverflow question. http://stackoverflow.com/questions/16573089/reading-binary-data-into-pandas though, as I said, if your data is homogeneous you can use the array module instead of using the struct one. But struct will work on homogenous data as well -- it is just slower. You may not care. Note that Albert Jan's answer is the one on the bottom, i.e. not the one that got the checkmark from the original poster. Laura From antoon.pardon at rece.vub.ac.be Thu Nov 26 14:18:14 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Nov 2015 20:18:14 +0100 Subject: What does a list comprehension do In-Reply-To: <87k2p43h8e.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <mailman.73.1448459485.20593.python-list@python.org> <pan.2015.11.26.11.13.43.440000@nowhere.invalid> <mailman.132.1448538769.20593.python-list@python.org> <87k2p4ex5x.fsf@elektro.pacujo.net> <mailman.138.1448544914.20593.python-list@python.org> <87fuzseuee.fsf@elektro.pacujo.net> <mailman.141.1448548095.20593.python-list@python.org> <87k2p43h8e.fsf@elektro.pacujo.net> Message-ID: <56575AF6.1050202@rece.vub.ac.be> Op 26-11-15 om 16:36 schreef Marko Rauhamaa: > Antoon Pardon <antoon.pardon at rece.vub.ac.be>: > >> [ <expression> for <var> in <iter> ] >> >> would implicitly be rewritten as follows: >> >> [ (lambda <var>: <expression>)(<var>) for <var> in <iter>] > > Funny enough, that's how "list comprehensions" are created in Scheme: > > (map (lambda (i) > (lambda (x) (* i x))) > '(0 1 2 3)))) > >> There would no change on how lambdas work or functions or closures. > > First of all, it's weird to spend any effort in trying to alter a very > special case. <shrug> Maybe it is small enough an effort but I wont loose any sleep over it should the dev team have other priorities. > I don't recall having to generate a list of such > functions. In fact, I barely ever use lambda in Python; explicit def > statements are much more pleasing to the eye and are not restricted to > simple expressions. > > Secondly, you'd lose the nice symmetry between for statements and > comprehensions/generators. For example: > > ( lambda x: i * x for i in range(4) ) > > corresponds to: > > for i in range(4): > yield lambda x: i * x > > Would you embed an extra lambda there, too? No, not because that would be so troublesome in semantics but because it would be annoying in python. Because in that case you would embed a function (call) or introduce an intermediate scope. Which would mean that if you want to rebind a variable within the suite of the for loop that is also used in other parts of the function/modules you would have to declare that variable nonlocal/global at the start of the suite. So it would be annoying plus that it would be difficult to explain to people new to the language. Such an embedding would only be practical in a language where you have to declare your variables. -- Antoon. From ben+python at benfinney.id.au Thu Nov 26 15:00:56 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 Nov 2015 07:00:56 +1100 Subject: Object identity has no necessary connection to memory location References: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> <mailman.129.1448537076.20593.python-list@python.org> <1esd5bdujvog21u4qu6llhna5c3d573873@4ax.com> Message-ID: <85fuzsa5tz.fsf@benfinney.id.au> Dave Farrance <df at see.replyto.invalid> writes: > >> >Dave Farrance <df at see.replyto.invalid>: > >> > > >> >> (Conversely, I see that unlike CPython, all PyPy's numbers have > >> >> unchanging ids, even after exiting PyPy and restarting, so it seems > >> >> that PyPy's numerical ids are "faked".) > > Hence > > https://en.wikipedia.org/wiki/Scare_quotes I saw the scare quotes. They still communicate your position that object identity ?should? be reliably connected to the object's memory location. Either you don't hold that position, in which case your original statement was as ambiguous as this most recent one you wrote; or you do hold that position, and my response stands. -- \ ?When I was little, my grandfather used to make me stand in a | `\ closet for five minutes without moving. He said it was elevator | _o__) practice.? ?Steven Wright | Ben Finney From hb.heber at gmail.com Thu Nov 26 15:16:54 2015 From: hb.heber at gmail.com (Heber Futuri) Date: Thu, 26 Nov 2015 15:16:54 -0500 Subject: it's posible? raw audio encoder to vorbis Message-ID: <CA+3gEyseSJLUxoiZ3tOfcgM1GX0VBnKTMVR6EwcXbTYafJqqQg@mail.gmail.com> Receipt from websocket server audio raw and I want to encode ogg help! :( from websocket_server import WebsocketServer # Called when a client sends a messagedef data_received(client, server, datos): #HERE encoder "datos" to ogg and save data PORT=9001 server = WebsocketServer(PORT) server.set_fn_message_received(data_received) server.run_forever() From vincentypedro at gmail.com Thu Nov 26 15:34:36 2015 From: vincentypedro at gmail.com (vincentypedro at gmail.com) Date: Thu, 26 Nov 2015 12:34:36 -0800 (PST) Subject: reading from a txt file Message-ID: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> Hey, I'm wondering how to read individual strings in a text file. I can read a text file by lines with .readlines() , but I need to read specifically by strings, not including spaces. Thanks in advance From denismfmcmahon at gmail.com Thu Nov 26 15:50:26 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Nov 2015 20:50:26 -0000 (UTC) Subject: reading from a txt file References: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> Message-ID: <n37rah$h02$8@dont-email.me> On Thu, 26 Nov 2015 12:34:36 -0800, vincentypedro wrote: > Hey, I'm wondering how to read individual strings in a text file. I can > read a text file by lines with .readlines() , > but I need to read specifically by strings, not including spaces. > Thanks in advance How do you define a string? Is it just a line with the spaces removed? >>> "".join(" this is a test string my friends ".split(" ")) 'thisisateststringmyfriends' -- Denis McMahon, denismfmcmahon at gmail.com From gherron at digipen.edu Thu Nov 26 16:01:55 2015 From: gherron at digipen.edu (Gary Herron) Date: Thu, 26 Nov 2015 13:01:55 -0800 Subject: reading from a txt file In-Reply-To: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> References: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> Message-ID: <56577343.4080901@digipen.edu> On 11/26/2015 12:34 PM, vincentypedro at gmail.com wrote: > Hey, I'm wondering how to read individual strings in a text file. I can read a text file by lines with .readlines() , > but I need to read specifically by strings, not including spaces. Thanks in advance Read the lines with readlines(), as you say, then split each line into whatever pieces you want with split (or with any of the many other string methods). A minimal example (without readlines): >>> lines = ['a b c', 'aa bb cc'] >>> for line in lines: ... words = line.split() ... print(words) ... ['a', 'b', 'c'] ['aa', 'bb', 'cc'] -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From jsf80238 at gmail.com Thu Nov 26 16:04:34 2015 From: jsf80238 at gmail.com (Jason Friedman) Date: Thu, 26 Nov 2015 14:04:34 -0700 Subject: reading from a txt file In-Reply-To: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> References: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> Message-ID: <CANy1k1gxdwwy61p1fENdHSnDY30JRGeVY8adirr+_xhYk26TqQ@mail.gmail.com> > > Hey, I'm wondering how to read individual strings in a text file. I can > read a text file by lines with .readlines() , > but I need to read specifically by strings, not including spaces. Thanks > in advance > How about: for a_string in open("/path/to/file").read().split(): print(a_string) From greg.ewing at canterbury.ac.nz Thu Nov 26 16:20:57 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 27 Nov 2015 10:20:57 +1300 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <87a8q1f9ni.fsf@elektro.pacujo.net> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> Message-ID: <dbpbdrFce6nU1@mid.individual.net> Marko Rauhamaa wrote: > What I'm saying is that Python does not prevent mutable keys but tries > to do that with lists and tuples. > > I think Python should stop trying. Do you volunteer to answer all the posts from beginners complaining that "the dict type is broken" because they used a list as a key and then mutated it? -- Greg From Cecil at decebal.nl Thu Nov 26 16:33:17 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 26 Nov 2015 22:33:17 +0100 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.102.1448492328.20593.python-list@python.org> <87h9k9dz2t.fsf@Equus.decebal.nl> <5656c2e0$0$11120$c3e8da3@news.astraweb.com> Message-ID: <87d1uwe99e.fsf@Equus.decebal.nl> On Thursday 26 Nov 2015 09:29 CET, Steven D'Aprano wrote: > On Thursday 26 November 2015 18:00, Cecil Westerhof wrote: > >> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote: >> >>> In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof >>> writes: >>>> >>>> My system python was all-ready damaged: that is why I wanted to >>>> build myself. >>> >>> Your Suse system probably wants to use python for something. If >>> your system python is damaged, you badly need to fix that, using >>> the system package managers tools, before Suse does some sort of >>> update on you, using the broken python, which damages more of your >>> system. >> >> I tried that. But it installs only things in /usr/lib and >> /usr/lib64, nothing in /usr/bin, but at the same time it is adamant >> that it installed python. I wanted a quick fix, but it looks like >> that is not going to work. :'-( I'll have to find a way to get >> things fixed. >> > > On the assumption that you are more interested in fixing your broken > system than learning how to compile Python, what happens if you use > the Suse package manager to re-install Python? > > e.g. zypper python It installs things in /usr/lib and /usr/lib64, but nothing in /usr/bin. So it installs libraries, but not programs. By the way: I am of-course most interested to fix my system, but I would not mind to have python compiled also, so I (can) work with the latest stable version. ;-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From marko at pacujo.net Thu Nov 26 16:36:13 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Nov 2015 23:36:13 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> <dbpbdrFce6nU1@mid.individual.net> Message-ID: <87egfc30ky.fsf@elektro.pacujo.net> Gregory Ewing <greg.ewing at canterbury.ac.nz>: > Marko Rauhamaa wrote: >> What I'm saying is that Python does not prevent mutable keys but >> tries to do that with lists and tuples. >> >> I think Python should stop trying. > > Do you volunteer to answer all the posts from beginners complaining > that "the dict type is broken" because they used a list as a key and > then mutated it? What happened to consenting adults? Even Java (of all languages) allows lists to be keys and simply notes: Note: great care must be exercised if mutable objects are used as map keys. <URL: http://docs.oracle.com/javase/7/docs/api/java/util/Map.html> Marko From Cecil at decebal.nl Thu Nov 26 16:39:01 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 26 Nov 2015 22:39:01 +0100 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.102.1448492328.20593.python-list@python.org> <87h9k9dz2t.fsf@Equus.decebal.nl> <pdpd5b9nn14apgog6pie58lhr2ivfo9i57@4ax.com> Message-ID: <878u5ke8zu.fsf@Equus.decebal.nl> On Thursday 26 Nov 2015 12:07 CET, Dave Farrance wrote: > Cecil Westerhof <Cecil at decebal.nl> wrote: > >> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote: >>> >>> Your Suse system probably wants to use python for something. If >>> your system python is damaged, you badly need to fix that, using >>> the system package managers tools, before Suse does some sort of >>> update on you, using the broken python, which damages more of your >>> system. >> >> I tried that. But it installs only things in /usr/lib and >> /usr/lib64, nothing in /usr/bin, but at the same time it is adamant >> that it installed python. I wanted a quick fix, but it looks like >> that is not going to work. :'-( I'll have to find a way to get >> things fixed. > > A complete reinstall of Suse (after saving your home directory and > work) might be quickest if you're in the dark about what's broken. > > But you might be able to fix it. If you can figure out which > packages contain the damaged files, then do forced reinstalls of > those. I've not used Suse, but a quick Google tells me that the > syntax is: > > zypper in -f <package-name> > > So you'll want to try package names like "python" and "python2.7". Sadly that also only installs only libraries and no applications. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From breamoreboy at yahoo.co.uk Thu Nov 26 16:44:41 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 26 Nov 2015 21:44:41 +0000 Subject: Object identity has no necessary connection to memory location In-Reply-To: <85fuzsa5tz.fsf@benfinney.id.au> References: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> <mailman.129.1448537076.20593.python-list@python.org> <1esd5bdujvog21u4qu6llhna5c3d573873@4ax.com> <85fuzsa5tz.fsf@benfinney.id.au> Message-ID: <n37ugd$rdk$1@ger.gmane.org> On 26/11/2015 20:00, Ben Finney wrote: > Dave Farrance <df at see.replyto.invalid> writes: > >>>>> Dave Farrance <df at see.replyto.invalid>: >>>>> >>>>>> (Conversely, I see that unlike CPython, all PyPy's numbers have >>>>>> unchanging ids, even after exiting PyPy and restarting, so it seems >>>>>> that PyPy's numerical ids are "faked".) >> >> Hence >> >> https://en.wikipedia.org/wiki/Scare_quotes > > I saw the scare quotes. They still communicate your position that object > identity ?should? be reliably connected to the object's memory location. > > Either you don't hold that position, in which case your original > statement was as ambiguous as this most recent one you wrote; or you do > hold that position, and my response stands. > It still fascinates me that after roughly 15 years using Python I've never considered using object identity, let alone actually done so. What, if anything, have I missed out on? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From greg.ewing at canterbury.ac.nz Thu Nov 26 16:48:46 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 27 Nov 2015 10:48:46 +1300 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <n36v80$1nt$1@dont-email.me> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> Message-ID: <dbpd20FcqvnU1@mid.individual.net> BartC wrote: > I simply stated that Python's approach was novel. Steven D'Aprano then > responded by belittling my view, and effectively trashing every language > I've ever used. He pointed out that many other dynamic languages construct functions on the fly the same way that Python does, going all the way back to the earliest Lisp implementations. If you think that Python invented that idea, then either you haven't studied any of those languages, or you didn't realise that's what they were doing. If your view was "belittled" in any way, it's only because you said something that is objectively wrong. > But as it happens I do think features like first class functions are > overrated (and probably the software underpinning the hardware we're all > using is written in the very languages he despises). I don't think a > language is worthless without such a feature. I think Steven went off on a bit of a tangent there. First-classness of functions doesn't really have anything to do with whether they're constructed statically or dynamically. C lets you pass pointers to functions around, for example, but I don't think anyone would describe C as executing function definitions at run time. While a language isn't worthless without first-class functions, such a language tends to feel rather limited if you're used to having them. Think of any API that involves passing in callback functions, and what you would have to do if you didn't have that ability. Anyhow, the whole issue of static vs. dynamic function creation is itself tangential to what started all this. I think Laura Creighton has it right: Python provides exactly *one* way to delay evaluation of code: put it in the body of a function. That's a very simple rule, and I think maintaining that simplicity is a good thing. -- Greg From bc at freeuk.com Thu Nov 26 17:27:52 2015 From: bc at freeuk.com (BartC) Date: Thu, 26 Nov 2015 22:27:52 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <mailman.140.1448547231.20593.python-list@python.org> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> <mailman.140.1448547231.20593.python-list@python.org> Message-ID: <n380t1$b69$1@dont-email.me> On 26/11/2015 13:15, Chris Angelico wrote: > On Thu, Nov 26, 2015 at 11:53 PM, BartC <bc at freeuk.com> wrote: >> http://pastebin.com/JrVTher6 > #14 and #15: Are you assuming that a character is a byte and that > diacritical-free English is the only language in the world? I don't think that need be the assumption. Any UTF8 string that fits within 8 bytes could also be represented by an integer value. > Case > insensitivity is a *pain* when you try to be language-agnostic; for > instance, the case-folding rules of English state that U+0069 LATIN > SMALL LETTER I and U+0049 LATIN CAPITAL LETTER I are identical, but > Turkish would upper-case the first to U+0130 LATIN CAPITAL LETTER I > WITH DOT ABOVE and lower-case the second to U+0131 LATIN SMALL LETTER > DOTLESS I. German has U+00DF LATIN SMALL LETTER SHARP S (also called > eszett), which traditionally upper-cases to "SS", which lower-cases to > "ss". I use Windows which is also case insensitive with regard to filenames and such. How does it solve those problems? How about web-site names, email addresses and Google searches? Within a program source code (where you have mainly technical users), you can just impose some restrictions on keywords and identifiers otherwise there are plenty of problems even without case switching, if you want to allow Unicode here. -- Bartc From rosuav at gmail.com Thu Nov 26 18:07:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Nov 2015 10:07:34 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <n380t1$b69$1@dont-email.me> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> <mailman.140.1448547231.20593.python-list@python.org> <n380t1$b69$1@dont-email.me> Message-ID: <CAPTjJmr=6y1v66s5AEcBT7w9e7TvXPg8B-XnGU-sbi=WXgt49g@mail.gmail.com> On Fri, Nov 27, 2015 at 9:27 AM, BartC <bc at freeuk.com> wrote: > On 26/11/2015 13:15, Chris Angelico wrote: >> >> On Thu, Nov 26, 2015 at 11:53 PM, BartC <bc at freeuk.com> wrote: > > >>> http://pastebin.com/JrVTher6 > > >> #14 and #15: Are you assuming that a character is a byte and that >> diacritical-free English is the only language in the world? > > > I don't think that need be the assumption. Any UTF8 string that fits within > 8 bytes could also be represented by an integer value. Okay, so you're making UTF-8 your visible string representation. That's better than assuming character==byte, but it still has the case insensitivity problem. >> Case >> insensitivity is a *pain* when you try to be language-agnostic; for >> instance, the case-folding rules of English state that U+0069 LATIN >> SMALL LETTER I and U+0049 LATIN CAPITAL LETTER I are identical, but >> Turkish would upper-case the first to U+0130 LATIN CAPITAL LETTER I >> WITH DOT ABOVE and lower-case the second to U+0131 LATIN SMALL LETTER >> DOTLESS I. German has U+00DF LATIN SMALL LETTER SHARP S (also called >> eszett), which traditionally upper-cases to "SS", which lower-cases to >> "ss". > > > I use Windows which is also case insensitive with regard to filenames and > such. How does it solve those problems? How about web-site names, email > addresses and Google searches? Windows: I'm not sure, and frankly, I don't trust it. A quick test showed a couple of failures: C:\Users\Rosuav\Desktop>dir /b TE* te?ting C:\Users\Rosuav\Desktop>dir /b TESST* File Not Found C:\Users\Rosuav\Desktop>dir /b Par?ld?YOR* Par?ld?yor Parts & Pieces C:\Users\Rosuav\Desktop>dir /b PARILDIYOR* File Not Found It might be case insensitive only for ASCII. (Note: This test was done on Windows 7, because that's the VM I had handy. Things might be different on newer Windowses, but I can't check. Web site names: Presumably you mean DNS. It started out as an ASCII-only protocol, and grew a number of gross hacks to support "internationalized domain names". I'm not sure where the case insensitivity is applied; but it doesn't matter too much, because conflicts can be resolved at registration. Also, you'll generally see IDNs in country-specific TLDs, so there'll be only one language (or a small family of languages) used, reducing the likelihood of collisions. Google searches are (deliberately) a LOT more sloppy than just case sensitivity. You can search for something without diacriticals and get back results with diacriticals; you can transpose letters, omit letters, have extra letters, and it'll generally figure out what you want. This is absolutely awesome for a search engine, but equally horrifying for name lookups in a program. None of these is something I'd recommend following. > Within a program source code (where you have mainly technical users), you > can just impose some restrictions on keywords and identifiers otherwise > there are plenty of problems even without case switching, if you want to > allow Unicode here. I would strongly support ASCII-only *language keywords*. You don't have many of them (compared to the number of identifiers in a program), and everyone has to type them. But for identifiers, Python 3 defines character validity based on Unicode categories, and performs NFKC normalization on all names. That's pretty straight-forward. No case sensitivity hassles, no messy non-transitive equalities, it's easy. ChrisA From random832 at fastmail.com Thu Nov 26 19:15:21 2015 From: random832 at fastmail.com (Random832) Date: Thu, 26 Nov 2015 19:15:21 -0500 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> <mailman.140.1448547231.20593.python-list@python.org> <n380t1$b69$1@dont-email.me> <CAPTjJmr=6y1v66s5AEcBT7w9e7TvXPg8B-XnGU-sbi=WXgt49g@mail.gmail.com> Message-ID: <m2si3s70x2.fsf@fastmail.com> Chris Angelico <rosuav at gmail.com> writes: > Windows: I'm not sure, and frankly, I don't trust it. A quick test > showed a couple of failures: > > It might be case insensitive only for ASCII. Windows uses a simple WCHAR->WCHAR (lower->upper) mapping for case comparison. it doesn't handle those cases, but it does handle all BMP characters that have a simple case equivalent within the BMP as of the unicode version that Microsoft supported when the disk was formatted. It's unfair to pick the two worst examples that you know offhand and declare that this means "only for ASCII". Pick any latin-1 (etc) diacritic, any letter of the greek and cyrillic alphabet, and it'll handle them just fine. OSX fails the same cases, incidentally. From rosuav at gmail.com Thu Nov 26 19:48:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Nov 2015 11:48:14 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <m2si3s70x2.fsf@fastmail.com> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> <mailman.140.1448547231.20593.python-list@python.org> <n380t1$b69$1@dont-email.me> <CAPTjJmr=6y1v66s5AEcBT7w9e7TvXPg8B-XnGU-sbi=WXgt49g@mail.gmail.com> <m2si3s70x2.fsf@fastmail.com> Message-ID: <CAPTjJmoo_ZP2fatWLYsOHx9gjWZxzeu1_TibQvNhcruxMwrARQ@mail.gmail.com> On Fri, Nov 27, 2015 at 11:15 AM, Random832 <random832 at fastmail.com> wrote: > Chris Angelico <rosuav at gmail.com> writes: >> Windows: I'm not sure, and frankly, I don't trust it. A quick test >> showed a couple of failures: >> >> It might be case insensitive only for ASCII. > > Windows uses a simple WCHAR->WCHAR (lower->upper) mapping for case > comparison. it doesn't handle those cases, but it does handle all BMP > characters that have a simple case equivalent within the BMP as of the > unicode version that Microsoft supported when the disk was formatted. > > It's unfair to pick the two worst examples that you know offhand and > declare that this means "only for ASCII". Pick any latin-1 (etc) > diacritic, any letter of the greek and cyrillic alphabet, and it'll > handle them just fine. > I picked a couple of test cases, found them to not do the case insensitivity special cases, and concluded that I don't understand Windows' file system case folding (with the possibility that it's an ASCII-only case fold). Anyway, it's still not something I would recommend; if you want true case folding, you need to go the whole way - and it still has problems. ChrisA From steve at pearwood.info Thu Nov 26 20:09:53 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 12:09:53 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> Message-ID: <5657ad63$0$1600$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 12:23 pm, BartC wrote: > On 26/11/2015 00:31, Steven D'Aprano wrote: >> In 2015, it's hard to think of any non-obsolete, non-toy language which >> doesn't treat functions as first-class values, including creating them on >> the fly. Fortran and C perhaps. > > It's funny then that the vast majority of top-level function definitions > I see in Python (and import and class statements too) are decidedly > static. I can't be held responsible for what code you see. It is probably true that many, maybe even a majority, of top-level functions, and methods, are static. So what? That's not the point. The point is that *more than that is possible*, so when you need the power, you have it. Any time you see a function decorator: @decorate def function(arg): ... you're probably seeing a dynamically-generated function. The typical decorator idiom looks like this: def decorate(function): @functools.wraps(function) def inner(arg): do stuff call the original function return the result return inner Lo and behold, the simple @decorate idiom usually hides a function created on the fly. (That would be the inner function, which is called a closure.) Any time you see a function factory, chances are good that it involves dynamic generation of function objects. Any time you see lambda, you are definitely seeing the dynamic generation of function objects. If you do any sort of programming involving callbacks (for example, some GUI toolkits, like Tkinter, make extensive use of callbacks) you probably will use lambda a lot. The equivalent to lambda, code blocks, is even more powerful in Ruby, and Ruby programmers use code blocks *a lot*. So much so that I know at least one Ruby programmer who considers Python almost unusably primitive and crippled because it lacks code blocks. You really should read Paul Graham's essay, "Beating the Averages", and understand the Blub Paradox. (It's not really a paradox.) It might open your eyes. [quote] As long as our hypothetical Blub programmer is looking down the power continuum, he knows he's looking down. Languages less powerful than Blub are obviously less powerful, because they're missing some feature he's used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn't realize he's looking up. What he sees are merely weird languages. He probably considers them about equivalent in power to Blub, but with all this other hairy stuff thrown in as well. Blub is good enough for him, because he thinks in Blub. [end quote] http://www.paulgraham.com/avg.html We're all Blub programmers. But some of us are aware that we're Blub programmers, and when we see "weird languages" with "hairy stuff", we don't immediately dismiss the possibility that maybe that stuff is powerful and useful, just because we've never found a use for it. > The names are declared, but the names are rarely bound to anything else. > Functions are just called the same boring way they are in C. > > /They might as well be static definitions/. Sure. And that's probably true for, oh, I don't know, I'll be generous, and say that 95% of Python functions in use are of a straight-forward pseudo-static form, using no dynamic features. But it's the other 5% -- one in twenty -- that *shine*. They're the ones that do things that you can't do in Pascal or C except with the greatest of difficulty. Back when I was an undergrad at uni, I did a course on computational mathematics. At the time, Pascal was the language of choice at my uni, and when it came to solving ODEs (Ordinary Differential Equations) we used a package of Pascal programs to do so. Because Pascal doesn't have first-class functions, you couldn't pass a function as an argument to another function. So the ODE solvers used a hard-coded function as the equation to be solved. So if you wanted to solve a particular equation, you had to *edit the source code of the program*, modifying that hard-coded function to match your equation, then re-compile, and then run the code. You couldn't just type in the equation you wanted to solve and run the code. Of course Pascal is Turing Complete, and the solver could have been written to work that way. It just would have been much, much, much harder. Something that in a language like Python you can do almost without thinking: function(another_function, x, y, z) would have required hundreds, perhaps thousands or tens of thousands of lines to do in standard Pascal. You would have had to build up all this infrastructure for dealing with functions that Python gives you for free. There's a lot to like about Pascal, but gosh it sure is lacking in power. C at least has function pointers, which is a step up from Pascal, but still pretty weak and feeble. If functions are first class values in Python, Ruby, Lisp and others, they're second class values in C and third class in Pascal. -- Steven From python at mrabarnett.plus.com Thu Nov 26 20:15:00 2015 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 Nov 2015 01:15:00 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <m2si3s70x2.fsf@fastmail.com> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <n36v80$1nt$1@dont-email.me> <mailman.140.1448547231.20593.python-list@python.org> <n380t1$b69$1@dont-email.me> <CAPTjJmr=6y1v66s5AEcBT7w9e7TvXPg8B-XnGU-sbi=WXgt49g@mail.gmail.com> <m2si3s70x2.fsf@fastmail.com> Message-ID: <5657AE94.4010002@mrabarnett.plus.com> On 2015-11-27 00:15, Random832 wrote: > Chris Angelico <rosuav at gmail.com> writes: >> Windows: I'm not sure, and frankly, I don't trust it. A quick test >> showed a couple of failures: >> >> It might be case insensitive only for ASCII. > > Windows uses a simple WCHAR->WCHAR (lower->upper) mapping for case > comparison. it doesn't handle those cases, but it does handle all BMP > characters that have a simple case equivalent within the BMP as of the > unicode version that Microsoft supported when the disk was formatted. > Interesting, on Windows 10, "dir" on the command line treats "TE?TING.txt" and "te?ting.txt" as equivalent, whereas a file dialog treats "TE?TING.txt", "te?ting.txt" and "TESSTING.txt" as equivalent. They don't treat "Par?ld?YOR.txt" and "PARILDIYOR.txt" as equivalent, which doesn't surprise me. > It's unfair to pick the two worst examples that you know offhand and > declare that this means "only for ASCII". Pick any latin-1 (etc) > diacritic, any letter of the greek and cyrillic alphabet, and it'll > handle them just fine. > > OSX fails the same cases, incidentally. > From steve at pearwood.info Thu Nov 26 20:23:11 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 12:23:11 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> Message-ID: <5657b081$0$1586$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 07:27 pm, Marko Rauhamaa wrote: > What I'm saying is that Python does not prevent mutable keys but tries > to do that with lists and tuples. > > I think Python should stop trying. > > I have wanted to use lists as keys, and there should be no reason to > allow mutable tuples. It should be enough to say that the behavior of a > dictionary is undefined if a key should mutate on the fly. Well, when you design your own language, you can make all the bad design decisions you like :-) Seriously, if you think *this* thread about mutable function defaults has been long, can you imagine the bug reports and arguments if this was possible in Python? L = [1, 2] d = {L: "found it"} # much later, after L has been modified... d[ [1, 2] ] => raises KeyError But even worse: a = [1, 2] b = [1, 3] d = {a: "spam", b: "ham"} a[1] += 1 What will d[ [1, 3] ] return? -- Steven From vincentypedro at gmail.com Thu Nov 26 20:24:38 2015 From: vincentypedro at gmail.com (Pedro Vincenty) Date: Thu, 26 Nov 2015 17:24:38 -0800 (PST) Subject: reading from a txt file In-Reply-To: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> References: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> Message-ID: <1e567393-3750-43f2-8e7c-6e92f687ce9f@googlegroups.com> All were really helpful thanks a lot. Now I'm interested in identifying a particular index after being able to print out each word. Printing each word to the console I have : ['METEOSAT-7'] ['1', '24932U', '97049B', '15319.57839525', '.00000058', '00000-0', '00000+0', '0', '9994'] ['2', '24932', '9.9015', '42.7484', '0001500', '224.8381', '52.7416', '1.00266716', '66645'] It seems awkward because I was expecting to have brackets only outside of all the words. I would like to identify one of these words. Thanks again! From steve at pearwood.info Thu Nov 26 20:28:29 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 12:28:29 +1100 Subject: Question about output different with command dis.dis(code) References: <f0dc1c2c-6fda-4bd8-a71b-29db358afe14@googlegroups.com> Message-ID: <5657b1bf$0$1601$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 08:02 pm, fl wrote: > Hi, > > I see the following from a previous post: > > > Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat > 4.1.2-52)] on linux2 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>> import dis >>>> code = compile("(1, 2, 3)", "", "eval") >>>> dis.dis(code) > 0 SET_LINENO 0 > 3 LOAD_CONST 0 (1) > 6 LOAD_CONST 1 (2) > 9 LOAD_CONST 2 (3) > 12 BUILD_TUPLE 3 > 15 RETURN_VALUE This output is from Python 1.5, which is about 20 years old or so, and long obsolete. > When I run the above three line code, I get the following: > > dis.dis(code) > 1 0 LOAD_CONST 3 ((1, 2, 3)) > 3 RETURN_VALUE This output is (probably) from Python 2.7, which is much more recent. The byte-code compiler is much smarter now than in old versions of Python. By the way, this is a really good question! I especially like the fact that you tried running the code for yourself first. -- Steven From steve at pearwood.info Thu Nov 26 20:34:02 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 12:34:02 +1100 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> Message-ID: <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 09:34 pm, Dave Farrance wrote: > (Conversely, I see that unlike CPython, all PyPy's numbers have > unchanging ids, even after exiting PyPy and restarting, so it seems that > PyPy's numerical ids are "faked".) > > [PyPy 2.6.1 with GCC 4.9.2] on linux2 >>>>> id(1+2j) > 679900119843984469027190799480815353863L > > [PyPy 2.6.1 with GCC 4.9.2] on linux2 >>>>> id(1+2j) > 679900119843984469027190799480815353863L I'm pretty sure that they are faked. I remember seeing a question on the pypy-dev mailing list asking whether it was important that object IDs remained stable. They had a problem where the JIT compiler would take a Python list, convert it to a low-level array of machine-sized ints for fast processing, and then recreate the list. This all happened in the background without the user knowing, and the PyPy devs needed to know if it was important that the object ID of the new list matched the old list. The language guarantees that the id of an object won't change for the lifespan of the object, and consequently PyPy has to fake them. -- Steven From ben+python at benfinney.id.au Thu Nov 26 20:40:06 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 Nov 2015 12:40:06 +1100 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8537vs9q4p.fsf@benfinney.id.au> Steven D'Aprano <steve at pearwood.info> writes: > On Thu, 26 Nov 2015 09:34 pm, Dave Farrance wrote: > > > > (Conversely, I see that unlike CPython, all PyPy's numbers have > > unchanging ids, even after exiting PyPy and restarting, so it seems > > that PyPy's numerical ids are "faked".) > > I'm pretty sure that they are faked. It's still not been expressed what ?fake? refers to here. Or, rather, what ?real? thing was being expected, and how these don't qualify. The object IDs are real IDs, they identify the object, they're not pretending to be anything other than object IDs, they are perfectly compliant with the language definition and all the documentation. What is fake? What ?real? thing was expected, and *why* was that expected? -- \ ?Do unto others twenty-five percent better than you expect them | `\ to do unto you. (The twenty-five percent is [to correct] for | _o__) error.)? ?Linus Pauling's Golden Rule | Ben Finney From steve at pearwood.info Thu Nov 26 20:43:05 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 12:43:05 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <mailman.56.1448440353.20593.python-list@python.org> <n349qb$qj4$1@dont-email.me> <878u5mns8z.fsf@elektro.pacujo.net> <n34dfe$8n5$1@dont-email.me> <874mganq2q.fsf@elektro.pacujo.net> <n34gor$kq8$1@dont-email.me> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> <mailman.117.1448525450.20593.python-list@python.org> <87a8q1f9ni.fsf@elektro.pacujo.net> <mailman.120.1448526890.20593.python-list@python.org> <87610pf2uq.fsf@elektro.pacujo.net> <mailman.127.1448535849.20593.python-list@python.org> <87wpt5dmxg.fsf@elektro.pacujo.net> Message-ID: <5657b52c$0$1617$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 10:23 pm, Marko Rauhamaa wrote: > Chris Angelico <rosuav at gmail.com>: > >> On Thu, Nov 26, 2015 at 9:54 PM, Marko Rauhamaa <marko at pacujo.net> wrote: >>> >>> >>> hash([]) >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in <module> >>> TypeError: unhashable type: 'list' >>> >>> Annoying. >> >> Yes, it's really annoying that you get an immediate exception instead >> of unpredictably getting bizarre failures that depend on the exact >> bucket sizes and dict size and so on. It's such a pain to get told >> exactly where the problem is. > > The problem is that lists don't have __hash__ and __eq__ defined. I'm pretty sure that lists have __eq__ defined :-P >> Python tends to assume that programmers are intelligent people who are >> prepared to fix their mistakes. > > It's not letting me in the case of list. Less whining, more programming: class MyList(list): def __hash__(self): return 1 There you go, problem solved. New problems are your responsibility: py> a = MyList([1, 2]) py> d = {a: "spam"} py> d[MyList([1, 2])] # Looks good so far. 'spam' py> a.append(3) py> d[MyList([1, 2])] # Where did my key go? Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: [1, 2] py> b = MyList([1, 3]) py> d[b] = "eggs" py> d[MyList([1, 3])] # So far so good. 'eggs' py> b[1] -= 1 py> b.append(3) py> d[b] # What? 'spam' All I can say is, this would be an absolutely awesome feature for Python to have, if you were being paid by the hour for debugging. -- Steven From steve at pearwood.info Thu Nov 26 20:46:01 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 12:46:01 +1100 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> Message-ID: <5657b5db$0$1617$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Nov 2015 12:52 pm, Ned Batchelder wrote: > For someone who claims to be interested in language design, you're > remarkably dismissive of pretty much the entire industry. I don't think > it's worth the effort to try to change your mind. In fairness to BartC, I don't think that's malicious or trolling. I think it is as pure an example of what Paul Graham calls the Blub Paradox as I've ever seen. -- Steven From bc at freeuk.com Thu Nov 26 21:01:28 2015 From: bc at freeuk.com (BartC) Date: Fri, 27 Nov 2015 02:01:28 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <5657b5db$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <b70213fa-2b4a-475b-a444-eaaf43c2a69e@googlegroups.com> <5657b5db$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <n38ddi$jrc$1@dont-email.me> On 27/11/2015 01:46, Steven D'Aprano wrote: > On Thu, 26 Nov 2015 12:52 pm, Ned Batchelder wrote: > >> For someone who claims to be interested in language design, you're >> remarkably dismissive of pretty much the entire industry. I don't think >> it's worth the effort to try to change your mind. > > In fairness to BartC, I don't think that's malicious or trolling. I think it > is as pure an example of what Paul Graham calls the Blub Paradox as I've > ever seen. "Well, PaulGraham has a very (very) low opinion of OO, mostly because he does a lot of stuff that most people haven't been able to do, and he says he almost never "resorts" to it. However, more recent posts on LL1 suggest PaulGraham is coming around. He's starting to be less derogatory to OO (and seems to have done a 180 on continuations). No one, not even PaulGraham himself, ever said that PaulGraham was immune to the BlubParadox. ;) " http://c2.com/cgi/wiki?BlubParadox -- bartc From steve at pearwood.info Thu Nov 26 21:17:53 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 13:17:53 +1100 Subject: Object identity has no necessary connection to memory location References: <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <871tbdf2o0.fsf@elektro.pacujo.net> <70qd5b9lbtjlsotn7d21gor4rd67o79ou7@4ax.com> <mailman.129.1448537076.20593.python-list@python.org> <1esd5bdujvog21u4qu6llhna5c3d573873@4ax.com> <mailman.152.1448568068.20593.python-list@python.org> Message-ID: <5657bd52$0$1610$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 Nov 2015 07:00 am, Ben Finney wrote: > Dave Farrance <df at see.replyto.invalid> writes: > >> >> >Dave Farrance <df at see.replyto.invalid>: >> >> > >> >> >> (Conversely, I see that unlike CPython, all PyPy's numbers have >> >> >> unchanging ids, even after exiting PyPy and restarting, so it seems >> >> >> that PyPy's numerical ids are "faked".) >> >> Hence >> >> https://en.wikipedia.org/wiki/Scare_quotes > > I saw the scare quotes. They still communicate your position that object > identity ?should? be reliably connected to the object's memory location. > > Either you don't hold that position, in which case your original > statement was as ambiguous as this most recent one you wrote; or you do > hold that position, and my response stands. Ben is right that object IDs are not promised to have any connection to object memory location. In Jython and IronPython, for example, objects appear to be given sequential IDs based on when you first ask for their ID. This is in IronPython: >>> a = [] >>> b = [] >>> id(b) 43 >>> id(a) 44 Jython is similar, except the IDs are 1 and 2 rather than 43 and 44. (All these results are subject to change, of course.) But (I think) that Dave is right that PyPy fakes IDs, in the sense that objects can be destroyed and recreated behind the scenes in PyPy without your knowledge. As I understand it, what appears to be happening is that PyPy can take Python objects, convert them to low-level machine values (destroying the Python object in the process), perform processing on the machine values, and recreate the Python object before you know it is gone. The consequence of that is that what we see as a single Python object with a fixed lifespan may in fact be multiple objects with much shorter lifespans. I'm rather partial to science fiction analogies, so here is one: when Captain Kirk uses the transporter to beam down to the Planet Of Hot Space Babes Wearing Hats With A Moral Lesson For Us All, we see Kirk on the Enterprise disappear and then re-appear on the planet a moment later. As far as we are concerned, and as far as Kirk is concerned, he has existed the whole time he was in transport. If he had an itchy nose just as he left, it's still itchy when he arrives, and if he is transported mid-thought, he finishes the thought when he arrives. There's no perception of discontinuity. But as Scotty well knows, in fact Kirk's entire body is ripped into atoms by the transporter beam, utterly destroying Kirk in the process, then transported via some oh-so-clever quantum-magical^W quantum-mechanical trick, to be reassembled at the other end. Although Kirk doesn't feel like he ceased to exist and then was re-created, in fact that's exactly what happened. One second after arriving on the planet, Kirk's body is now precisely one second old. It may not even be made of the same atoms that his former body was made of. In PyPy, an object's lifetime is not necessarily the same as the lifetime of the actual block of memory used for that object. Not only might objects be relocated in space (as they can be in IronPython and Jython) but in time as well. -- Steven From steve at pearwood.info Thu Nov 26 21:44:05 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 13:44:05 +1100 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <mailman.160.1448588423.20593.python-list@python.org> Message-ID: <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 Nov 2015 12:40 pm, Ben Finney wrote: > Steven D'Aprano <steve at pearwood.info> writes: > >> On Thu, 26 Nov 2015 09:34 pm, Dave Farrance wrote: >> >> >> > (Conversely, I see that unlike CPython, all PyPy's numbers have >> > unchanging ids, even after exiting PyPy and restarting, so it seems >> > that PyPy's numerical ids are "faked".) >> >> I'm pretty sure that they are faked. > > It's still not been expressed what ?fake? refers to here. Or, rather, > what ?real? thing was being expected, and how these don't qualify. They are faked in the sense that in this implementation, the object lifespan that you think of as the Python programmer has little if any connection to the actual lifespan of the chunk of memory representing that object. Suppose you have a Python object which in turn contains three other objects: L = [10001, 10002, 10003] Take the id of that list: myid = id(L) You do some long-running processing of that list, and then compare the id at the end: assert myid == id(L) This is guaranteed to pass by the language definition. We can say that at *every instant* from the creation of the list to the moment it is garbage collected, if you took a snap-shot of the process' memory, and manually scanned through it, you could be able to identify four object structs, corresponding to the list and the three ints. They might move around and be found in different memory locations, (as in IronPython and Jython), but they will be there. But not with PyPy. Not only might the objects have moved location, but in some snapshots you won't find them at all. The JIT compiler may convert the high-level Python objects (a list, and three ints) to (let's say) a low-level array containing three C shorts, perform processing on that, and then recreate the Python objects only when finished. Looked at from the perspective of the implementation, the actual lifespan of the objects (in the sense of the struct in memory that represents that object) may be much less than what we see from the perspective of the high-level Python code. Of course in Python, the object continues to exist the whole time, as far as we can tell -- there is no test we can do from Python code that can distinguish the state of the object, just as there is no test we can do from Python to tell whether an object has moved memory location or not. But from outside of Python -- say, a debugger that hooks into the particular implementation, or by taking a dump of the memory and looking at it in a hex editor -- we can see the high-level objects come and go and move around. The PyPy implementation has to take special actions to preserve the ID across object recreations. That is what I mean by "faked". -- Steven From python at mrabarnett.plus.com Thu Nov 26 21:56:12 2015 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 Nov 2015 02:56:12 +0000 Subject: What is a function parameter =[] for? In-Reply-To: <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <mailman.160.1448588423.20593.python-list@python.org> <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5657C64C.1020807@mrabarnett.plus.com> On 2015-11-27 02:44, Steven D'Aprano wrote: > On Fri, 27 Nov 2015 12:40 pm, Ben Finney wrote: > >> Steven D'Aprano <steve at pearwood.info> writes: >> >>> On Thu, 26 Nov 2015 09:34 pm, Dave Farrance wrote: >>> >>> >>> > (Conversely, I see that unlike CPython, all PyPy's numbers have >>> > unchanging ids, even after exiting PyPy and restarting, so it seems >>> > that PyPy's numerical ids are "faked".) >>> >>> I'm pretty sure that they are faked. >> >> It's still not been expressed what ?fake? refers to here. Or, rather, >> what ?real? thing was being expected, and how these don't qualify. > > They are faked in the sense that in this implementation, the object lifespan > that you think of as the Python programmer has little if any connection to > the actual lifespan of the chunk of memory representing that object. > > Suppose you have a Python object which in turn contains three other objects: > > L = [10001, 10002, 10003] > > Take the id of that list: > > myid = id(L) > > You do some long-running processing of that list, and then compare the id at > the end: > > assert myid == id(L) > > This is guaranteed to pass by the language definition. > > We can say that at *every instant* from the creation of the list to the > moment it is garbage collected, if you took a snap-shot of the process' > memory, and manually scanned through it, you could be able to identify four > object structs, corresponding to the list and the three ints. They might > move around and be found in different memory locations, (as in IronPython > and Jython), but they will be there. > > But not with PyPy. Not only might the objects have moved location, but in > some snapshots you won't find them at all. The JIT compiler may convert the > high-level Python objects (a list, and three ints) to (let's say) a > low-level array containing three C shorts, perform processing on that, and > then recreate the Python objects only when finished. > > Looked at from the perspective of the implementation, the actual lifespan of > the objects (in the sense of the struct in memory that represents that > object) may be much less than what we see from the perspective of the > high-level Python code. > > Of course in Python, the object continues to exist the whole time, as far as > we can tell -- there is no test we can do from Python code that can > distinguish the state of the object, just as there is no test we can do > from Python to tell whether an object has moved memory location or not. But > from outside of Python -- say, a debugger that hooks into the particular > implementation, or by taking a dump of the memory and looking at it in a > hex editor -- we can see the high-level objects come and go and move > around. > > The PyPy implementation has to take special actions to preserve the ID > across object recreations. That is what I mean by "faked". > You could argue that it _does_ continue to exist, it just changes its form... From rosuav at gmail.com Thu Nov 26 22:06:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Nov 2015 14:06:42 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <5657C64C.1020807@mrabarnett.plus.com> References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <mailman.160.1448588423.20593.python-list@python.org> <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> <5657C64C.1020807@mrabarnett.plus.com> Message-ID: <CAPTjJmrkn468vq9UGEowkbCVY=fNHOC7J72T1gU3=rUiSSCmiA@mail.gmail.com> On Fri, Nov 27, 2015 at 1:56 PM, MRAB <python at mrabarnett.plus.com> wrote: > You could argue that it _does_ continue to exist, it just changes its > form... PyPy: The Quantum Mechanics of Python programming. If you aren't actually looking at something right at this instant, it might exist in a different form... or not exist at all. But hey! By the time you get to look at it again, it'll exist just as if it was never gone! ChrisA From random832 at fastmail.com Thu Nov 26 23:33:53 2015 From: random832 at fastmail.com (Random832) Date: Thu, 26 Nov 2015 23:33:53 -0500 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <m2lh9k6oy6.fsf@fastmail.com> Steven D'Aprano <steve at pearwood.info> writes: > On Thu, 26 Nov 2015 09:34 pm, Dave Farrance wrote: > > >> (Conversely, I see that unlike CPython, all PyPy's numbers have >> unchanging ids, even after exiting PyPy and restarting, so it seems that >> PyPy's numerical ids are "faked".) >> >> [PyPy 2.6.1 with GCC 4.9.2] on linux2 >>>>>> id(1+2j) >> 679900119843984469027190799480815353863L >> >> [PyPy 2.6.1 with GCC 4.9.2] on linux2 >>>>>> id(1+2j) >> 679900119843984469027190799480815353863L > > > I'm pretty sure that they are faked. The hex value may be instructive: 0x1ff800000000000020000000000000007L That's 0x3ff00000000000004000000000000000 << 3 | 7. 3ff000... is the double representation of 1, 400000... is 2. I bet that that three-bit field at the end has different values for all the different types they are "faked" for, and one for the ones that they're "not faked". From ben+python at benfinney.id.au Thu Nov 26 23:56:40 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 Nov 2015 15:56:40 +1100 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <mailman.160.1448588423.20593.python-list@python.org> <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85y4dk82gn.fsf@benfinney.id.au> Steven D'Aprano <steve at pearwood.info> writes: > On Fri, 27 Nov 2015 12:40 pm, Ben Finney wrote: > > > It's still not been expressed what ?fake? refers to here. Or, rather, > > what ?real? thing was being expected, and how these don't qualify. > > They are faked in the sense that in this implementation, the object > lifespan that you think of as the Python programmer has little if any > connection to the actual lifespan of the chunk of memory representing > that object. Since that's nothing to do with the definition nor API of an object ID, I think all the uses of ?faked? so far in this thread just don't apply to PyPy's object IDs. > The PyPy implementation has to take special actions to preserve the ID > across object recreations. That is what I mean by "faked". Thanks for the interesting explanation. I don't think any of this makes PyPy's object IDs in any sense not-real-object-IDs, so I disagree with using ?faked? to characterise them. None of CPython, Jython, PyPy, etc. have object IDs that are anything but real object IDs, IMO. -- \ ?[Entrenched media corporations will] maintain the status quo, | `\ or die trying. Either is better than actually WORKING for a | _o__) living.? ?ringsnake.livejournal.com, 2007-11-12 | Ben Finney From zachary.ware+pylist at gmail.com Fri Nov 27 00:48:30 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 26 Nov 2015 23:48:30 -0600 Subject: Help needed with compiling python In-Reply-To: <878u5ke8zu.fsf@Equus.decebal.nl> References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.102.1448492328.20593.python-list@python.org> <87h9k9dz2t.fsf@Equus.decebal.nl> <pdpd5b9nn14apgog6pie58lhr2ivfo9i57@4ax.com> <878u5ke8zu.fsf@Equus.decebal.nl> Message-ID: <CAKJDb-Njb73BuLuHYHDdyGngpvKjXhd6bXx5hsXhsqd6GAPtjQ@mail.gmail.com> On Thu, Nov 26, 2015 at 3:39 PM, Cecil Westerhof <Cecil at decebal.nl> wrote: > On Thursday 26 Nov 2015 12:07 CET, Dave Farrance wrote: >> zypper in -f <package-name> >> >> So you'll want to try package names like "python" and "python2.7". > > Sadly that also only installs only libraries and no applications. Try "python-base". (See `zypper wp /usr/bin/python`). -- Zach From kevin.p.dwyer at gmail.com Fri Nov 27 01:46:23 2015 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 27 Nov 2015 06:46:23 +0000 Subject: Help needed with compiling python References: <877fl596c6.fsf@Equus.decebal.nl> <mailman.94.1448484579.20593.python-list@python.org> <8737vt927c.fsf@Equus.decebal.nl> <mailman.102.1448492328.20593.python-list@python.org> <87h9k9dz2t.fsf@Equus.decebal.nl> <5656c2e0$0$11120$c3e8da3@news.astraweb.com> <87d1uwe99e.fsf@Equus.decebal.nl> Message-ID: <n38u7v$iid$1@ger.gmane.org> Cecil Westerhof wrote: > On Thursday 26 Nov 2015 09:29 CET, Steven D'Aprano wrote: > >> On Thursday 26 November 2015 18:00, Cecil Westerhof wrote: >> >>> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote: >>> >>>> In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof >>>> writes: >>>>> >>>>> My system python was all-ready damaged: that is why I wanted to >>>>> build myself. >>>> >>>> Your Suse system probably wants to use python for something. If >>>> your system python is damaged, you badly need to fix that, using >>>> the system package managers tools, before Suse does some sort of >>>> update on you, using the broken python, which damages more of your >>>> system. >>> >>> I tried that. But it installs only things in /usr/lib and >>> /usr/lib64, nothing in /usr/bin, but at the same time it is adamant >>> that it installed python. I wanted a quick fix, but it looks like >>> that is not going to work. :'-( I'll have to find a way to get >>> things fixed. >>> >> >> On the assumption that you are more interested in fixing your broken >> system than learning how to compile Python, what happens if you use >> the Suse package manager to re-install Python? >> >> e.g. zypper python > > It installs things in /usr/lib and /usr/lib64, but nothing in > /usr/bin. So it installs libraries, but not programs. > > > By the way: I am of-course most interested to fix my system, but I > would not mind to have python compiled also, so I (can) work with the > latest stable version. ;-) > FWIW, I'm running OpenSuse 13.2 on a number of machines. Pythons built with make altinstall have the python executable placed in /usr/local/bin. e.g.: kev at pluto ~ which python3.5 /usr/local/bin/python3.5 kev at pluto ~ which python2.7 /usr/local/bin/python2.7 NB due to http://bugs.python.org/issue15631 I find I have to symlink lib-dynload to get a working python: kev at pluto ~ ls -l /usr/local/lib/python3.5/lib-dynload lrwxrwxrwx 1 root root 38 Sep 26 19:51 /usr/local/lib/python3.5/lib-dynload -> /usr/local/lib64/python3.5/lib-dynload Having said that, I'd still recommend that you follow everyone else's advice and fix your system python/rebuild your OS. Opensuse has not attempted to install python 2.7.9 on any of my (fully patched) machines, so something is wrong with your install, unless you're using Tumbleweed. Cheers, Kev From dieter at handshake.de Fri Nov 27 02:30:51 2015 From: dieter at handshake.de (dieter) Date: Fri, 27 Nov 2015 08:30:51 +0100 Subject: Py_NewInterpreter() - Fatal Error with ceval - orphan tstate References: <CAGQhfC5ZSZyyL7kmaQmL=ECqCU_Ruy4ytXMYpDeJR=HdKLQ05A@mail.gmail.com> Message-ID: <87wpt3ew5w.fsf@handshake.de> "ramjee a.g." <ramjee.ag at gmail.com> writes: > I am using python 2.7 for extending my C++ application with python. > > And when two pthread of C is executing Py_NewInterpreter() it is throwing > faltal error with ceval-orphan tstate. There is no problem when sequential > thread execution. "tstate" likely stands for "thread state". Python must somewhere store important information of the currently running Python thread - and apparently, your use of "Py_NewInterpreter" confuses this management. Maybe, the "tstate" is a global variable and you cannot have multiple interpreters at the same time. I suggest to have a look at Python's C implementation, especially the location where the error comes from. From jfong at ms4.hinet.net Fri Nov 27 02:51:35 2015 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 26 Nov 2015 23:51:35 -0800 (PST) Subject: python response slow when running external DLL Message-ID: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> I am new to Python. As an exercise of it, I try to port a program which was written more than 10 years ago. This program use the Borland C++ Builder as its GUI front end and a DLL does the real work(it will takes a few seconds to complete). I saw a strange phenomenon in the following codes. The "var_status.set('Download...')" statement seems was deferred and didn't show up until the external DLL job was finished and I can only saw the result of "var_status.set('Download OK')" statement which immediately follows. I try to do the DLL function in a thread(selected by using the "test" flag in codes), but it didn't help. Can anyone tell me what's the point I was missed? ------------------------- def download(): global iniFilename if test: global result, busy ini = iniFilename iniFilename = "c:\\$$temp.in3" saveIniFile() iniFilename = ini #do the rest var_status.set('Download...') if not test: result = mydll.SayHello() else: busy = True _thread.start_new_thread(td_download, ()) while busy: pass if result: var_status.set("Download Fail at %s" % hex(result)) showerror('Romter', 'Download Fail') else: var_status.set('Download OK') showinfo('Romter', 'Download OK') if test: result = 0x5555 busy = True def td_download(): global busy, result result = mydll.SayHello() busy = False -------------------------- Best Regards, Jach From __peter__ at web.de Fri Nov 27 04:18:35 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 27 Nov 2015 10:18:35 +0100 Subject: python response slow when running external DLL References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> Message-ID: <n3975b$osk$1@ger.gmane.org> jfong at ms4.hinet.net wrote: > I am new to Python. As an exercise of it, I try to port a program which > was written more than 10 years ago. This program use the Borland C++ > Builder as its GUI front end and a DLL does the real work(it will takes a > few seconds to complete). I saw a strange phenomenon in the following > codes. The "var_status.set('Download...')" statement seems was deferred > and didn't show up until the external DLL job was finished and I can only > saw the result of "var_status.set('Download OK')" statement which > immediately follows. I try to do the DLL function in a thread(selected by > using the "test" flag in codes), but it didn't help. > > Can anyone tell me what's the point I was missed? What does var_status.set() do? If it writes to stdout you may just need to flush(). Do you see the same behaviour when you replace mydll.SayHello() with something simple like time.sleep(1)? > ------------------------- > def download(): > global iniFilename > if test: global result, busy > ini = iniFilename > iniFilename = "c:\\$$temp.in3" > saveIniFile() > iniFilename = ini > #do the rest > var_status.set('Download...') > if not test: > result = mydll.SayHello() > else: > busy = True > _thread.start_new_thread(td_download, ()) > while busy: pass > if result: > var_status.set("Download Fail at %s" % hex(result)) > showerror('Romter', 'Download Fail') > else: > var_status.set('Download OK') > showinfo('Romter', 'Download OK') > > if test: > result = 0x5555 > busy = True > def td_download(): > global busy, result > result = mydll.SayHello() > busy = False > -------------------------- As a general remark keep your test scripts as simple as possible. Example: If import mydll print("Download...", end="") mydll.SayHello() print("OK") showed the same behaviour it would be the ideal test script. From rianconnery at googlemail.com Fri Nov 27 04:43:53 2015 From: rianconnery at googlemail.com (justin bloomer) Date: Fri, 27 Nov 2015 01:43:53 -0800 (PST) Subject: Help with this program??? Message-ID: <c3c2d9d0-d59c-489b-bf3e-9488b202225b@googlegroups.com> Your program should contain a function that: 1. Seeks input from the user (via the keyboard); 2. To build a list of student exam results; 3. For each student their name (first and last), student number, and mark out of 100 should be captured; 4. For full marks regular expressions or similar mechanisms should be used to ensure the data appears valid. From ben+python at benfinney.id.au Fri Nov 27 04:57:27 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 Nov 2015 20:57:27 +1100 Subject: Help with this program??? References: <c3c2d9d0-d59c-489b-bf3e-9488b202225b@googlegroups.com> Message-ID: <85poyv933s.fsf@benfinney.id.au> justin bloomer via Python-list <python-list at python.org> writes: > Your program should contain a function that: This is a homework assignment, yes? We're not going to write the code for you. If you have a program you already wrote, we can offer feedback on *your* code. You should also collaborate with other classmates in the course, or look into the course material your teacher has provided. -- \ ?Why doesn't Python warn that it's not 100% perfect? Are people | `\ just supposed to ?know? this, magically?? ?Mitya Sirenef, | _o__) comp.lang.python, 2012-12-27 | Ben Finney From rosuav at gmail.com Fri Nov 27 04:57:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Nov 2015 20:57:55 +1100 Subject: Help with this program??? In-Reply-To: <c3c2d9d0-d59c-489b-bf3e-9488b202225b@googlegroups.com> References: <c3c2d9d0-d59c-489b-bf3e-9488b202225b@googlegroups.com> Message-ID: <CAPTjJmruTJK6raW36OYGYkSow3jDgQSjEbtcdwReE4tJDgjdnA@mail.gmail.com> On Fri, Nov 27, 2015 at 8:43 PM, justin bloomer via Python-list <python-list at python.org> wrote: > Your program should contain a function that: > 1. Seeks input from the user (via the keyboard); > 2. To build a list of student exam results; > 3. For each student their name (first and last), student number, and mark > out of 100 should be captured; > 4. For full marks regular expressions or similar mechanisms should be used > to ensure the data appears valid. I suggest you start by opening up a programmer's editor and saving an empty file under the name "examresults.py". Then take your keyboard in hand, and start writing code. The above text would make a good set of "stub comments" - notes to indicate what parts of code you still need to write - which you can progressively replace with actual code. ChrisA From lac at openend.se Fri Nov 27 05:14:14 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 27 Nov 2015 11:14:14 +0100 Subject: Help with this program??? In-Reply-To: <c3c2d9d0-d59c-489b-bf3e-9488b202225b@googlegroups.com> References: <c3c2d9d0-d59c-489b-bf3e-9488b202225b@googlegroups.com> Message-ID: <201511271014.tARAEEJB025295@fido.openend.se> In a message of Fri, 27 Nov 2015 01:43:53 -0800, justin bloomer via Python-list writes: >Your program should contain a function that: >1. Seeks input from the user (via the keyboard); >2. To build a list of student exam results; >3. For each student their name (first and last), student number, and mark >out of 100 should be captured; >4. For full marks regular expressions or similar mechanisms should be used >to ensure the data appears valid. Hello. We don't do people's assignments for them. However, over on the tutor mailing list, https://mail.python.org/mailman/listinfo/tutor we do help people who are learning Python. You will have to post your code, along with any error messages you get and explain what you were trying to do. Laura From bc at freeuk.com Fri Nov 27 05:31:27 2015 From: bc at freeuk.com (BartC) Date: Fri, 27 Nov 2015 10:31:27 +0000 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) In-Reply-To: <5657ad63$0$1600$c3e8da3$5496439d@news.astraweb.com> References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <5657ad63$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <n39b9o$25t$1@dont-email.me> On 27/11/2015 01:09, Steven D'Aprano wrote: > On Thu, 26 Nov 2015 12:23 pm, BartC wrote: [First-class functions] >> The names are declared, but the names are rarely bound to anything else. >> Functions are just called the same boring way they are in C. >> >> /They might as well be static definitions/. > > Sure. And that's probably true for, oh, I don't know, I'll be generous, and > say that 95% of Python functions in use are of a straight-forward > pseudo-static form, using no dynamic features. > > But it's the other 5% -- one in twenty -- that *shine*. They're the ones > that do things that you can't do in Pascal or C except with the greatest of > difficulty. OK, you're worried about that 5%, I'm more concerned about the other 95%. I'm not saying you shouldn't have dynamic functions at all, just that it's not necessary for 100% to be dynamic. I understand now that they are dynamic because that is the only mechanism that Python has to create any function definition, even the boring, static ones. Together with the ability to subsequently re-bind the function name to something else, that's a bit unfortunate because it makes it harder to identifier calls to those functions in order to streamline them, or even for someone to look at a bit of code and be sure whether that fn(a,b,c) is calling the function defined as 'fn' a few hundred lines earlier or something else entirely. (MRAB mentioned Postscript, which also introduces functions using executable statements. However, Postscript was designed to execute code on-the-fly being received a character at a time over a printer cable. It had a good excuse!) > Because Pascal doesn't have first-class functions, you couldn't pass a > function as an argument to another function. So the ODE solvers used a > hard-coded function as the equation to be solved. So if you wanted to solve > a particular equation, you had to *edit the source code of the program*, > modifying that hard-coded function to match your equation, then re-compile, > and then run the code. You couldn't just type in the equation you wanted to > solve and run the code. Wouldn't Python have the same problem? If the equation to be solved, or even the actual function to be executed, is input by the user, then doesn't that require whichever one of exec() or eval() it is that processes the source code? > There's a lot to like about Pascal, It was designed for teaching. The original language would have needed tweaking for use in general purpose programming. > but gosh it sure is lacking in power. C > at least has function pointers, which is a step up from Pascal, but still > pretty weak and feeble. If functions are first class values in Python, > Ruby, Lisp and others, they're second class values in C and third class in > Pascal. I think they are more first class in Lisp than they are in most other languages including Python. That doesn't stop Python still being jolly useful though... -- Bartc From jfong at ms4.hinet.net Fri Nov 27 06:14:40 2015 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 27 Nov 2015 03:14:40 -0800 (PST) Subject: python response slow when running external DLL In-Reply-To: <mailman.169.1448615930.20593.python-list@python.org> References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> Message-ID: <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> Peter Otten at 2015/11/27 UTC+8 5:19:17 PM wrote? Hi! Peter, thanks for your prompt reply. > What does var_status.set() do? If it writes to stdout you may just need to > flush(). var_status is a StringVar which binds to a lable's textvariable. I use this label as the status bar to show message. > Do you see the same behaviour when you replace mydll.SayHello() with > something simple like time.sleep(1)? I use time.sleep(3) to replace mydll.SayHello(), still get the same. > As a general remark keep your test scripts as simple as possible. Example: > If > > import mydll > print("Download...", end="") > mydll.SayHello() > print("OK") > > showed the same behaviour it would be the ideal test script. I run the above statements in a test file, it works as expected. I can see "Download..." and then "OK". From marko at pacujo.net Fri Nov 27 06:30:54 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 27 Nov 2015 13:30:54 +0200 Subject: Late-binding of function defaults (was Re: What is a function parameter =[] for?) References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.484.1447964295.16136.python-list@python.org> <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <mailman.54.1448439359.20593.python-list@python.org> <565592e9$0$1615$c3e8da3$5496439d@news.astraweb.com> <n34cem$4l5$1@dont-email.me> <d1c4eaac-5f3d-4836-9b3e-1bdfee5f4f57@googlegroups.com> <n34qdc$sbp$1@dont-email.me> <mailman.95.1448484677.20593.python-list@python.org> <n35amf$21o$1@dont-email.me> <87k2p54tdr.fsf@elektro.pacujo.net> <n35dbc$ckb$1@dont-email.me> <565652e1$0$1619$c3e8da3$5496439d@news.astraweb.com> <n35mps$dv8$1@dont-email.me> <5657ad63$0$1600$c3e8da3$5496439d@news.astraweb.com> <n39b9o$25t$1@dont-email.me> Message-ID: <878u5jel1t.fsf@elektro.pacujo.net> BartC <bc at freeuk.com>: > I think [functions] are more first class in Lisp than they are in most > other languages including Python. Functions in Python and Lisp have the same status. I would say that Python is one of the many modern Lisp derivatives. What Python still lacks is: * A way to augment the language syntax on the fly. (How could I add an "until" statement to Python in my Python application?) * A unified syntax for code and data. (Why use braces for dictionaries instead of indentation?) Marko From __peter__ at web.de Fri Nov 27 07:20:03 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 27 Nov 2015 13:20:03 +0100 Subject: python response slow when running external DLL References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> Message-ID: <n39hpj$384$1@ger.gmane.org> jfong at ms4.hinet.net wrote: > Peter Otten at 2015/11/27 UTC+8 5:19:17 PM wrote? > > Hi! Peter, thanks for your prompt reply. > >> What does var_status.set() do? If it writes to stdout you may just need >> to flush(). > > var_status is a StringVar which binds to a lable's textvariable. I use > this label as the status bar to show message. Can I conclude from the above that you are using tkinter? Widgets can only update when the event loop gets a chance to run. While a quick fix is to invoke update_idletasks() callbacks shouldn't generally contain long-running code that -- as you have seen -- will block the complete user interface. >> Do you see the same behaviour when you replace mydll.SayHello() with >> something simple like time.sleep(1)? > > I use time.sleep(3) to replace mydll.SayHello(), still get the same. > >> As a general remark keep your test scripts as simple as possible. >> Example: If >> >> import mydll >> print("Download...", end="") >> mydll.SayHello() >> print("OK") >> >> showed the same behaviour it would be the ideal test script. > > I run the above statements in a test file, it works as expected. I can > see "Download..." and then "OK". > > Quick-fix example: #!/usr/bin/env python3 import tkinter as tk import time def download(): var.set("Starting download...") root.update_idletasks() time.sleep(3) var.set("... done") root = tk.Tk() var = tk.StringVar() label = tk.Label(root, textvariable=var) label.pack() button = tk.Button(root, text="Download", command=download) button.pack() root.mainloop() A cleaner solution can indeed involve threads; you might adapt the approach from <http://effbot.org/zone/tkinter-threads.htm> (Python 2 code). From denismfmcmahon at gmail.com Fri Nov 27 07:28:09 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 27 Nov 2015 12:28:09 -0000 (UTC) Subject: Help with this program??? References: <c3c2d9d0-d59c-489b-bf3e-9488b202225b@googlegroups.com> Message-ID: <n39i8p$k01$1@dont-email.me> On Fri, 27 Nov 2015 01:43:53 -0800, justin bloomer wrote: > Your program should contain a function that: > 1. Seeks input from the user (via the keyboard); > 2. To build a list of student exam results; > 3. For each student their name (first and last), student number, and > mark out of 100 should be captured; > 4. For full marks regular expressions or similar mechanisms should be > used to ensure the data appears valid. Try writing a function that does the following: 1. Seeks input from the user (via the keyboard); 2. Builds a list of student exam results; 3. Captures name (first and last), student number, and mark out of 100 for each student; 4. Uses regular expressions or similar mechanisms to ensure the data appears valid. -- Denis McMahon, denismfmcmahon at gmail.com From lac at openend.se Fri Nov 27 07:49:47 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 27 Nov 2015 13:49:47 +0100 Subject: python response slow when running external DLL In-Reply-To: <n39hpj$384$1@ger.gmane.org> References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <n39hpj$384$1@ger.gmane.org> Message-ID: <201511271249.tARCnlsJ027820@fido.openend.se> In a message of Fri, 27 Nov 2015 13:20:03 +0100, Peter Otten writes: >A cleaner solution can indeed involve threads; you might adapt the approach >from <http://effbot.org/zone/tkinter-threads.htm> (Python 2 code). But it is probably better to use threading http://code.activestate.com/recipes/82965-threads-tkinter-and-asynchronous-io/ Laura From delphicr at gmail.com Fri Nov 27 07:52:58 2015 From: delphicr at gmail.com (RENISH RUDANI) Date: Fri, 27 Nov 2015 18:22:58 +0530 Subject: Fwd: convert php in to python In-Reply-To: <CAP9M=4B6oBxOG1g8E2WJSKEtCNV=WcowvU_EO7sU=eA3jaMF1w@mail.gmail.com> References: <CAP9M=4B6oBxOG1g8E2WJSKEtCNV=WcowvU_EO7sU=eA3jaMF1w@mail.gmail.com> Message-ID: <CAP9M=4BabE0gg5svMB5rQJacAK-vEGR7_4suaJQ45u9NqwHqaQ@mail.gmail.com> Hi, Please help me to convert this code in python. *Thanks & Regards,* *Renish Rudani* *Action Speaks Louder than Words* From steve at pearwood.info Fri Nov 27 07:57:29 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 27 Nov 2015 23:57:29 +1100 Subject: What is a function parameter =[] for? References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <mailman.160.1448588423.20593.python-list@python.org> <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> <mailman.162.1448592976.20593.python-list@python.org> Message-ID: <5658533c$0$1591$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 Nov 2015 01:56 pm, MRAB wrote: > On 2015-11-27 02:44, Steven D'Aprano wrote: >> The PyPy implementation has to take special actions to preserve the ID >> across object recreations. That is what I mean by "faked". >> > You could argue that it _does_ continue to exist, it just changes its > form... *Something* continues to exist, but it is no longer an object. I like Chris' analogy of it being like quantum mechanics -- the *object* isn't guaranteed to exist except when you try to access it, until then you don't know what form it will take at any instance. -- Steven From lac at openend.se Fri Nov 27 08:24:36 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 27 Nov 2015 14:24:36 +0100 Subject: What is a function parameter =[] for? In-Reply-To: <5658533c$0$1591$c3e8da3$5496439d@news.astraweb.com> References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <mailman.160.1448588423.20593.python-list@python.org> <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> <mailman.162.1448592976.20593.python-list@python.org> <5658533c$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201511271324.tARDOafP028282@fido.openend.se> In a message of Fri, 27 Nov 2015 23:57:29 +1100, "Steven D'Aprano" writes: >On Fri, 27 Nov 2015 01:56 pm, MRAB wrote: > >> On 2015-11-27 02:44, Steven D'Aprano wrote: > >>> The PyPy implementation has to take special actions to preserve the ID >>> across object recreations. That is what I mean by "faked". >>> >> You could argue that it _does_ continue to exist, it just changes its >> form... > >*Something* continues to exist, but it is no longer an object. > >I like Chris' analogy of it being like quantum mechanics -- the *object* >isn't guaranteed to exist except when you try to access it, until then you >don't know what form it will take at any instance. I think it's just another instance of Just-In-Time Manufacturing https://en.wikipedia.org/wiki/Just-in-time_manufacturing "As soon as you need a object, we'll have one ready". :) Laura From rosuav at gmail.com Fri Nov 27 08:29:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 Nov 2015 00:29:49 +1100 Subject: What is a function parameter =[] for? In-Reply-To: <201511271324.tARDOafP028282@fido.openend.se> References: <mailman.33.1448398558.20593.python-list@python.org> <n32jqq$k4j$1@dont-email.me> <mailman.35.1448400323.20593.python-list@python.org> <56550273$0$1585$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1448445391.20593.python-list@python.org> <5655f27b$0$1614$c3e8da3$5496439d@news.astraweb.com> <w2dh9k9bjhq.fsf@daphne.csail.mit.edu> <mailman.109.1448504727.20593.python-list@python.org> <w2dd1uxbd1c.fsf@daphne.csail.mit.edu> <6imd5b9it55sucrcl95o95tppro7errfsi@4ax.com> <5657b30d$0$1600$c3e8da3$5496439d@news.astraweb.com> <mailman.160.1448588423.20593.python-list@python.org> <5657c376$0$1618$c3e8da3$5496439d@news.astraweb.com> <mailman.162.1448592976.20593.python-list@python.org> <5658533c$0$1591$c3e8da3$5496439d@news.astraweb.com> <201511271324.tARDOafP028282@fido.openend.se> Message-ID: <CAPTjJmoEiT68aMwMpuYVT+Cenyd=bGJoRj0ZunOrJ9f-2QWn=A@mail.gmail.com> On Sat, Nov 28, 2015 at 12:24 AM, Laura Creighton <lac at openend.se> wrote: > I think it's just another instance of Just-In-Time Manufacturing > https://en.wikipedia.org/wiki/Just-in-time_manufacturing > > "As soon as you need a object, we'll have one ready". :) Just-In-Time Quantum Manufacturing: "As soon as you need an electron, we'll have the same one ready!" ChrisA From paul.hermeneutic at gmail.com Fri Nov 27 11:45:35 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Fri, 27 Nov 2015 09:45:35 -0700 Subject: fexit: file transfer of ANY size In-Reply-To: <n36vf2$86s$1@news2.informatik.uni-stuttgart.de> References: <n36vf2$86s$1@news2.informatik.uni-stuttgart.de> Message-ID: <CAJ4+4ar8oB6+MJmS-xcEKJxNn824LQdvuwvFp6B7ofdtnh9y2g@mail.gmail.com> > And what is F*EX? > ==> Frams' Fast File EXchange, a service for transfering files of ANY size > from any user A to any user B in the internet. > For details see: http://fex.rus.uni-stuttgart.de/ > > I am now looking for beta testers. If you are interested, send me a mail. Can you tell us a git or svn repository from which the kit is available? Or, is this a proprietary product? From framstag at rus.uni-stuttgart.de Fri Nov 27 13:32:29 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Fri, 27 Nov 2015 18:32:29 +0000 (UTC) Subject: fexit: file transfer of ANY size References: <n36vf2$86s$1@news2.informatik.uni-stuttgart.de> <mailman.178.1448642737.20593.python-list@python.org> Message-ID: <n3a7jt$4mv$1@news2.informatik.uni-stuttgart.de> paul.hermeneutic at gmail.com wrote: > > I am now looking for beta testers. If you are interested, send me a mail. > > Can you tell us a git or svn repository from which the kit is available? Available via email request. > Or, is this a proprietary product? No. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From real-not-anti-spam-address at apple-juice.co.uk Fri Nov 27 19:37:21 2015 From: real-not-anti-spam-address at apple-juice.co.uk (D.M. Procida) Date: Sat, 28 Nov 2015 00:37:21 +0000 Subject: Python 3 virtualenvs Message-ID: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> I have a new installation of Debian Jessie, with Python 2.7 and 3.4 installed. I want to use Python 3.4 by default for most things, so I want virtualenv to create Python 3.4 virtualenvs unless I ask it to otherwise. It turns out that this seems to be inordinately complex. The best solution I have come up with is to alias virtualenv to 'virtualenv -p python3.5', which seems really ugly and clunky. Then I discover things like <http://askubuntu.com/questions/603935/pyvenv-vs-venv-vs-python-virtualenv-vs-virtualenv-and-python-3> and realise it's not just me, it really is a nasty mess and nobody seems to understand what's going on. Daniele From lac at openend.se Fri Nov 27 20:09:20 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 28 Nov 2015 02:09:20 +0100 Subject: Python 3 virtualenvs In-Reply-To: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: <201511280109.tAS19KpM009020@fido.openend.se> In a message of Sat, 28 Nov 2015 00:37:21 +0000, D.M. Procida writes: >I have a new installation of Debian Jessie, with Python 2.7 and 3.4 >installed. > >I want to use Python 3.4 by default for most things, so I want >virtualenv to create Python 3.4 virtualenvs unless I ask it to >otherwise. > >It turns out that this seems to be inordinately complex. > >The best solution I have come up with is to alias virtualenv to >'virtualenv -p python3.5', which seems really ugly and clunky. This will get you python3.5 which I infinitely prefer over 3.4. But you said you wanted to use 3.4 ... >Then I discover things like ><http://askubuntu.com/questions/603935/pyvenv-vs-venv-vs-python-virtualenv-vs-virtualenv-and-python-3> >and realise it's not just me, it really is a nasty mess and nobody seems >to understand what's going on. > >Daniele What I found out. https://bugs.python.org/issue25151 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732703 https://bugs.python.org/issue25152 https://bugs.python.org/issue25154 pyenv is going away. use python -m venv instead, if you want a venv. You will never (unless somebody does a backport, which seems very unlikley) be able to get a venv with 2.7. I've long ago aliased virtualenv to v, so things aren't as clunky for me. Laura From real-not-anti-spam-address at apple-juice.co.uk Fri Nov 27 20:35:54 2015 From: real-not-anti-spam-address at apple-juice.co.uk (D.M. Procida) Date: Sat, 28 Nov 2015 01:35:54 +0000 Subject: Python 3 virtualenvs References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <mailman.179.1448672987.20593.python-list@python.org> Message-ID: <1mekoqg.11rv2hi1owcmgjN%real-not-anti-spam-address@apple-juice.co.uk> Laura Creighton <lac at openend.se> wrote: > In a message of Sat, 28 Nov 2015 00:37:21 +0000, D.M. Procida writes: > >I have a new installation of Debian Jessie, with Python 2.7 and 3.4 > >installed. > > > >I want to use Python 3.4 by default for most things, so I want > >virtualenv to create Python 3.4 virtualenvs unless I ask it to > >otherwise. > > > >It turns out that this seems to be inordinately complex. > > > >The best solution I have come up with is to alias virtualenv to > >'virtualenv -p python3.5', which seems really ugly and clunky. > > This will get you python3.5 which I infinitely prefer over 3.4. > But you said you wanted to use 3.4 ... Typo! > >Then I discover things like > ><http://askubuntu.com/questions/603935/pyvenv-vs-venv-vs-python-virtualen > >v-vs-virtualenv-and-python-3> and realise it's not just me, it really is > >a nasty mess and nobody seems to understand what's going on. > What I found out. > https://bugs.python.org/issue25151 > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732703 > https://bugs.python.org/issue25152 > https://bugs.python.org/issue25154 Good lord. > I've long ago aliased virtualenv to v, so things aren't as clunky > for me. I'll stick with virtualenv as an alias to virtualenv -p python3.5. Thanks, Daniele From ben+python at benfinney.id.au Fri Nov 27 20:42:30 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2015 12:42:30 +1100 Subject: Faviourite improvements in Python 3.5 (was: Python 3 virtualenvs) References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <201511280109.tAS19KpM009020@fido.openend.se> Message-ID: <85lh9i99x5.fsf_-_@benfinney.id.au> Laura Creighton <lac at openend.se> writes: > [?] python3.5 which I infinitely prefer over 3.4. That's strong language :-) Laura ? and anyone else ? what in your opinion are the best improvements brought by Python 3.5 (over Python 3.4)? -- \ ?DRM doesn't inconvenience [lawbreakers] ? indeed, over time it | `\ trains law-abiding users to become [lawbreakers] out of sheer | _o__) frustration.? ?Charles Stross, 2010-05-09 | Ben Finney From lac at openend.se Fri Nov 27 21:23:23 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 28 Nov 2015 03:23:23 +0100 Subject: Faviourite improvements in Python 3.5 (was: Python 3 virtualenvs) In-Reply-To: <85lh9i99x5.fsf_-_@benfinney.id.au> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <201511280109.tAS19KpM009020@fido.openend.se> <85lh9i99x5.fsf_-_@benfinney.id.au> Message-ID: <201511280223.tAS2NNuj010015@fido.openend.se> In a message of Sat, 28 Nov 2015 12:42:30 +1100, Ben Finney writes: >Laura Creighton <lac at openend.se> writes: > >> [?] python3.5 which I infinitely prefer over 3.4. > >That's strong language :-) > >Laura ? and anyone else ? what in your opinion are the best improvements >brought by Python 3.5 (over Python 3.4)? The interactive console started working again. https://bugs.python.org/issue23441 Laura From rhills at medimorphosis.com.au Fri Nov 27 21:35:16 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Sat, 28 Nov 2015 10:35:16 +0800 Subject: Find relative url in mixed text/html Message-ID: <565912E4.4000908@medimorphosis.com.au> Hi, For my sins I am migrating a volunteer association forum from one platform (WebWiz) to another (phpBB). I am (I hope) 95% of the way through the process. Posts to our original forum comprise a soup of plain text, HTML and BBCodes. A post */may/* include links done as either standard HTML links ( <a href=... ), BBCode links ( [url]http://... [/url] ) or sometimes just text: ( http://blah.blah.com.au or even just www.blah.blah.com.au ). In my conversion process, I am trying to identify cross-links (links from one post on the forum to another) so I can convert them to links that will work in the new forum. My current code uses a Regular Expression (yes, I read the recent posts on this forum about regex and HTML!) to pull out "absolute" links ( starting with http:// ) and then I use Python to identify and convert the specific links I am interested in. However, the forum also contains "cross-links" done using relative links and I'm unsure how best to proceed with that one. Googling so far has not been helpful, but that might be me using the wrong search terms. Some examples of what I am talking about are: Post fragment containing an "Absolute" cross-link: <br />ive made a new thread: <br />http://www.aeva.asn.au/forums/forum_posts.asp?TID=316&PID=1958#1958 <br /> converts to: <br /> <br />ive made a new thread: <br />/viewtopic.php?t=316&p=1958#1958 Post fragment containing a "Relative" cross-link: <font size="3"><u>Battery Management System</u></font><br /><a href="/forum_posts.asp?TID=980&PID=15479#15479" target="_blank" rel="nofollow">Veroboard prototype</a><br /> Needs converting to: <font size="3"><u>Battery Management System</u></font><br /><a href="/viewtopic.php?p=15479&t=980#15479" target="_blank" rel="nofollow">Veroboard prototype</a><br /> So, my question is: What is the best way to extract a list of "relative links" from mixed text/html that I can then walk through to identify the specific ones I want to convert? Note, in the beginning of this project, I looked at using "Beautiful Soup" but my reading and limited testing lead me to believe that it is designed for well-formed HTML/XML and therefore was unsuitable for the text/html soup I have. If that belief is incorrect, I'd be grateful for general tips about using Beautiful Soup in this scenario... TIA, -- Rob Hills Waikiki, Western Australia From no.email at nospam.invalid Sat Nov 28 00:11:58 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 27 Nov 2015 21:11:58 -0800 Subject: Find relative url in mixed text/html References: <mailman.182.1448678122.20593.python-list@python.org> Message-ID: <8737vqyag1.fsf@jester.gateway.pace.com> Rob Hills <rhills at medimorphosis.com.au> writes: > Note, in the beginning of this project, I looked at using "Beautiful > Soup" but my reading and limited testing lead me to believe that it is > designed for well-formed HTML/XML and therefore was unsuitable for the > text/html soup I have. If that belief is incorrect, I'd be grateful for > general tips about using Beautiful Soup in this scenario... Beautiful Soup can deal with badly formed HTML pretty well, or at least it could in earlier versions. It gives you several different parsing options to choose from now. I think the default is lxml which is fast but maybe more strict. Check what the others are and see if a loose slow one is still there. It really is pretty slow so plan on a big computation task if you're converting a large forum. phpBB gets a bad rap that's maybe well-deserved but I don't know what to suggest instead. From snailcoder at retrosite.invalid Sat Nov 28 02:07:32 2015 From: snailcoder at retrosite.invalid (Grobu) Date: Sat, 28 Nov 2015 08:07:32 +0100 Subject: Find relative url in mixed text/html In-Reply-To: <mailman.182.1448678122.20593.python-list@python.org> References: <mailman.182.1448678122.20593.python-list@python.org> Message-ID: <n3bjmq$pdi$1@dont-email.me> On 28/11/15 03:35, Rob Hills wrote: > Hi, > > For my sins I am migrating a volunteer association forum from one > platform (WebWiz) to another (phpBB). I am (I hope) 95% of the way > through the process. > > Posts to our original forum comprise a soup of plain text, HTML and > BBCodes. A post */may/* include links done as either standard HTML > links ( <a href=... ), BBCode links ( [url]http://... [/url] ) or > sometimes just text: ( http://blah.blah.com.au or even just > www.blah.blah.com.au ). > > In my conversion process, I am trying to identify cross-links (links > from one post on the forum to another) so I can convert them to links > that will work in the new forum. > > My current code uses a Regular Expression (yes, I read the recent posts > on this forum about regex and HTML!) to pull out "absolute" links ( > starting with http:// ) and then I use Python to identify and convert > the specific links I am interested in. However, the forum also contains > "cross-links" done using relative links and I'm unsure how best to > proceed with that one. Googling so far has not been helpful, but that > might be me using the wrong search terms. > > Some examples of what I am talking about are: > > Post fragment containing an "Absolute" cross-link: > > <br />ive made a new thread: > <br />http://www.aeva.asn.au/forums/forum_posts.asp?TID=316&PID=1958#1958 > <br /> > > converts to: > > <br /> > <br />ive made a new thread: > <br />/viewtopic.php?t=316&p=1958#1958 > > Post fragment containing a "Relative" cross-link: > > <font size="3"><u>Battery Management System</u></font><br /><a href="/forum_posts.asp?TID=980&PID=15479#15479" target="_blank" rel="nofollow">Veroboard prototype</a><br /> > > Needs converting to: > > <font size="3"><u>Battery Management System</u></font><br /><a href="/viewtopic.php?p=15479&t=980#15479" target="_blank" rel="nofollow">Veroboard prototype</a><br /> > > So, my question is: What is the best way to extract a list of "relative > links" from mixed text/html that I can then walk through to identify the > specific ones I want to convert? > > Note, in the beginning of this project, I looked at using "Beautiful > Soup" but my reading and limited testing lead me to believe that it is > designed for well-formed HTML/XML and therefore was unsuitable for the > text/html soup I have. If that belief is incorrect, I'd be grateful for > general tips about using Beautiful Soup in this scenario... > > TIA, > Hi Rob Is it safe to assume that all the relative (cross) links take one of the following forms? : http://www.aeva.asn.au/forums/forum_posts.asp www.aeva.asn.au/forums/forum_posts.asp /forums/forum_posts.asp /forum_posts.asp (are you really sure about this one?) If so, and if your goal boils down to converting all instances of old style URLs to new style ones regardless of the context where they appear, why would a regex fail to meet your needs? From songofacandy at gmail.com Sat Nov 28 02:17:17 2015 From: songofacandy at gmail.com (INADA Naoki) Date: Sat, 28 Nov 2015 16:17:17 +0900 Subject: Faviourite improvements in Python 3.5 (was: Python 3 virtualenvs) In-Reply-To: <85lh9i99x5.fsf_-_@benfinney.id.au> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <201511280109.tAS19KpM009020@fido.openend.se> <85lh9i99x5.fsf_-_@benfinney.id.au> Message-ID: <CAEfz+TxCG5PkWpDGKw3eMHDN4KK6V6C=UheFCt8Dnnbdrwm0HQ@mail.gmail.com> OrderedDict is now faster and efficient. On Sat, Nov 28, 2015 at 10:42 AM, Ben Finney <ben+python at benfinney.id.au> wrote: > Laura Creighton <lac at openend.se> writes: > > > [?] python3.5 which I infinitely prefer over 3.4. > > That's strong language :-) > > Laura ? and anyone else ? what in your opinion are the best improvements > brought by Python 3.5 (over Python 3.4)? > > -- > \ ?DRM doesn't inconvenience [lawbreakers] ? indeed, over time it | > `\ trains law-abiding users to become [lawbreakers] out of sheer | > _o__) frustration.? ?Charles Stross, 2010-05-09 | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -- INADA Naoki <songofacandy at gmail.com> From jfong at ms4.hinet.net Sat Nov 28 02:37:58 2015 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 27 Nov 2015 23:37:58 -0800 (PST) Subject: python response slow when running external DLL In-Reply-To: <mailman.173.1448626828.20593.python-list@python.org> References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <mailman.173.1448626828.20593.python-list@python.org> Message-ID: <d6c59a36-38ba-4f26-b949-18f2b226e7e3@googlegroups.com> Peter Otten at 2015/11/27 UTC+8 8:20:54PM wrote? > Quick-fix example: > def download(): > var.set("Starting download...") > root.update_idletasks() > time.sleep(3) > var.set("... done") Thanks, Peter, The update_idletasks() works. In my trivial program it's easy to apply for there are only two places call the DLL function. > A cleaner solution can indeed involve threads; you might adapt the approach > from <http://effbot.org/zone/tkinter-threads.htm> (Python 2 code). Using thread is obviously more logical. I think my mistake was the "while busy: pass" loop which makes no sense because it blocks the main thread, just as the time.sleep() does. That's why in your link (and Laura's too) the widget.after() scheduling was used for this purpose. >From what I had learned here, the other way I can do is making the codes modified as follows. It will get ride of the "result" and "busy" global variables, but it also makes the codes looks a little ugly. I think I will take the update_idletasks() way in this porting for it seems more simpler, and can be used on thread or non-thread calling. Thank you again. ..... ..... #do the rest var_status.set('Download...') _thread.start_new_thread(td_download, ()) #must use threading def td_download(): result = mydll.SayHello() if result: var_status.set("Download Fail at %s" % hex(result)) showerror('Romter', 'Download Fail') else: var_status.set('Download OK') showinfo('Romter', 'Download OK') From __peter__ at web.de Sat Nov 28 05:13:38 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 28 Nov 2015 11:13:38 +0100 Subject: python response slow when running external DLL References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <mailman.173.1448626828.20593.python-list@python.org> <d6c59a36-38ba-4f26-b949-18f2b226e7e3@googlegroups.com> Message-ID: <n3buoh$3r1$1@ger.gmane.org> jfong at ms4.hinet.net wrote: > Peter Otten at 2015/11/27 UTC+8 8:20:54PM wrote? > >> Quick-fix example: >> def download(): >> var.set("Starting download...") >> root.update_idletasks() >> time.sleep(3) >> var.set("... done") > > Thanks, Peter, The update_idletasks() works. In my trivial program it's > easy to apply for there are only two places call the DLL function. > >> A cleaner solution can indeed involve threads; you might adapt the >> approach from <http://effbot.org/zone/tkinter-threads.htm> (Python 2 >> code). > > Using thread is obviously more logical. I think my mistake was the "while > busy: pass" loop which makes no sense because it blocks the main thread, > just as the time.sleep() does. That's why in your link (and Laura's too) > the widget.after() scheduling was used for this purpose. No, the point of both recipes is that tkinter operations are only ever invoked from the main thread. The main thread has polling code that repeatedly looks if there are results from the helper thread. As far I understand the polling method has the structure f(): # did we get something back from the other thread? # a queue is used to avoid race conditions # if yes react. # var_status.set() goes here # reschedule f to run again in a few millisecs; # that's what after() does > From what I had learned here, the other way I can do is making the codes > modified as follows. It will get ride of the "result" and "busy" global > variables, but it also makes the codes looks a little ugly. I think I will > take the update_idletasks() way in this porting for it seems more simpler, > and can be used on thread or non-thread calling. Thank you again. > ..... > ..... > #do the rest > var_status.set('Download...') > _thread.start_new_thread(td_download, ()) #must use threading > > def td_download(): > result = mydll.SayHello() > if result: > var_status.set("Download Fail at %s" % hex(result)) > showerror('Romter', 'Download Fail') > else: > var_status.set('Download OK') > showinfo('Romter', 'Download OK') As td_download() runs in the other thread the var_status.set() methods are problematic. Another complication that inevitably comes with concurrency: what if the user triggers another download while one download is already running? If you don't keep track of all downloads the message will already switch to "Download OK" while one download is still running. From framstag at rus.uni-stuttgart.de Sat Nov 28 05:29:55 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Sat, 28 Nov 2015 10:29:55 +0000 (UTC) Subject: askopenfilename() (was: Re: non-blocking getkey?) References: <n2hdfn$b1d$1@news2.informatik.uni-stuttgart.de> <n2hfe1$n3l$1@dont-email.me> <n2hkho$d1j$1@news2.informatik.uni-stuttgart.de> <n2hlr7$d1j$2@news2.informatik.uni-stuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> <mailman.509.1448009036.16136.python-list@python.org> <n2vgq3$76g$1@news2.informatik.uni-stuttgart.de> Message-ID: <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> Ulli Horlacher <framstag at rus.uni-stuttgart.de> wrote: > eryksun <eryksun at gmail.com> wrote: > > On Thu, Nov 19, 2015 at 10:31 AM, Michael Torrie <torriem at gmail.com> wrote: > > > One windows it might be possible to use the win32 api to enumerate the > > > windows, find your console window and switch to it. > > > > You can call GetConsoleWindow [1] and then SetForegroundWindow [2]. > (...) > > great, this works! Thanks! One of my Windows test users reports, that the file dialog window of askopenfilename() starts behind the console window and has no focus. On Linux (XFCE) I do not have this problem. I start it with: Tk().withdraw() file = askopenfilename(title='select a file',initialdir=HOME) set_window_focus() # give focus back to console window Can one force askopenfilename() to start in foreground with focus? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From lac at openend.se Sat Nov 28 05:51:55 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 28 Nov 2015 11:51:55 +0100 Subject: python response slow when running external DLL In-Reply-To: <n3buoh$3r1$1@ger.gmane.org> References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <mailman.173.1448626828.20593.python-list@python.org> <d6c59a36-38ba-4f26-b949-18f2b226e7e3@googlegroups.com> <n3buoh$3r1$1@ger.gmane.org> Message-ID: <201511281051.tASAptQQ016625@fido.openend.se> In a message of Sat, 28 Nov 2015 11:13:38 +0100, Peter Otten writes: >jfong at ms4.hinet.net wrote: >> Using thread is obviously more logical. I think my mistake was the "while >> busy: pass" loop which makes no sense because it blocks the main thread, >> just as the time.sleep() does. That's why in your link (and Laura's too) >> the widget.after() scheduling was used for this purpose. I never saw the reply that Peter is replying to. The threading module constructs a higher level interface on top of the low level thread module. Thus it is the preferred way to go for standard Python code -- and even Fredrik's recipe contains the line: import thread # should use the threading module instead! Laura From jeanpierreda at gmail.com Sat Nov 28 06:31:14 2015 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 28 Nov 2015 03:31:14 -0800 Subject: Looking for ideas to improve library API In-Reply-To: <CABMb9GtR_WVngUUmNAVP83vXJbUZK40REfUBeBpCn3XL2YFaPw@mail.gmail.com> References: <CABMb9Gu+m9cJXQavXwxc0iouhsKsFSFKVvepLXhJcorc8aUkRw@mail.gmail.com> <CABicbJJkNCTW6PAWw_P5mQmHAwysJaG49N8C+zLV9vKQkWB8_Q@mail.gmail.com> <CABMb9GtR_WVngUUmNAVP83vXJbUZK40REfUBeBpCn3XL2YFaPw@mail.gmail.com> Message-ID: <CABicbJKi=ZuCNhw2DTgn0F43=EYFvctjQiiRyyoceQA-QV7BvA@mail.gmail.com> Documentation is all you can do. -- Devin On Thu, Nov 26, 2015 at 5:35 AM, Chris Lalancette <clalancette at gmail.com> wrote: > On Thu, Nov 26, 2015 at 7:46 AM, Devin Jeanpierre > <jeanpierreda at gmail.com> wrote: >> Why not take ownership of the file object, instead of requiring users >> to manage lifetimes? > > Yeah, I've kind of been coming to this conclusion. So my question > then becomes: how do I "take ownership" of it? I already keep a > reference to it, but how would I signal to the API user that they > should no longer use that file object (other than documentation)? > > Thanks, > Chris From auriocus at gmx.de Sat Nov 28 06:45:18 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 28 Nov 2015 12:45:18 +0100 Subject: askopenfilename() In-Reply-To: <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> References: <n2hdfn$b1d$1@news2.informatik.uni-stuttgart.de> <n2hfe1$n3l$1@dont-email.me> <n2hkho$d1j$1@news2.informatik.uni-stuttgart.de> <n2hlr7$d1j$2@news2.informatik.uni-stuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> <mailman.509.1448009036.16136.python-list@python.org> <n2vgq3$76g$1@news2.informatik.uni-stuttgart.de> <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> Message-ID: <n3c3vu$a8t$1@dont-email.me> Am 28.11.15 um 11:29 schrieb Ulli Horlacher: > One of my Windows test users reports, that the file dialog window of > askopenfilename() starts behind the console window and has no focus. > On Linux (XFCE) I do not have this problem. > > I start it with: > > Tk().withdraw() > file = askopenfilename(title='select a file',initialdir=HOME) > set_window_focus() # give focus back to console window > > Can one force askopenfilename() to start in foreground with focus? I can't test it right now, but I think it /should/ go into the foreground by itself. For a toplevel window, which you create manually, there is a lift() method which asks the OS to move the window to the top. But on Windows, this file dialog is a native call and cannot be influenced that much. I see two thingd: 1) Tk().withdraw() - this seems odd to me, because you don't keep a reference to the Tk object around. Better do root=Tk() roo.withdraw() 2) Maybe it helps if you inject an update() after the withdraw(), maybe not root.update() 3) I can confirm, that also on OSX the file dialog does not raise above the console window, though it is not as bad because the dialog window is muhc bigger then the console window. I think that you are curing a lot of symptoms with the focus setting to the console etc. Many problems would simply go away if you wrote the whole thing as a GUI program. If I understand correctly, what you want - a program to select files and folders to upload to your server - then this would not be that much more work than the CLI with input() which you are writing, and definitely less work to get it correct than the plastering of the symptoms. For example, a very simple approach would use a listbox with a + and a - button. upon hitting - (or the delete key), you delete the selected entries. Upon hitting +, you pop up the file selection dialog. upon hitting a Go button, you send the files to the server. A minimalistic version of it is included below. That is less then 50 lines of code, including comments, without all the focus problems, providing a standard desktop GUI metaphor. I haven't seen your command line code, but I doubt that it is significantly simpler. Of course, the code below can still use a great deal of polishing, like scrollbars for the listbox, allowing multiple selection both for the file dialog and the listbox, nice icons for the buttons, trapping the close button on the main window with an "are you sure?"-type question, maybe wrapping it up in a class, a progress bar during the upload and a way to interrupt it... which is left as an exercise to the reader. Christian ================================= import Tkinter as tk, tkFileDialog as fd, ttk from Tkinter import N,S,W,E # create one ttk::frame to fill the main window root=tk.Tk() main=ttk.Frame(master=root) # tell the pack geometry manager to completely # fill the toplevel with this frame main.pack(fill=tk.BOTH, expand=1) # now create a listbox and a button frame lb=tk.Listbox(master=main) bf=ttk.Frame(master=main) # use the grid manager to stack them, whereby # the listbox should expand lb.grid(row=0, column=0, sticky=(N,S,E,W)) bf.grid(row=1, column=0, sticky=(N,S,E,W)) main.rowconfigure(0, weight=1) main.columnconfigure(0, weight=1) def addfile(): filename=fd.askopenfilename() if filename: lb.insert(tk.END, filename) def remove(*args): sel=lb.curselection() if sel: lb.delete(sel) def submit(): print("Submitting files:") for filename in lb.get(0,tk.END): print("Sending %s"%filename) # create the three buttons btnplus=ttk.Button(master=bf, text="+", command=addfile) btnminus=ttk.Button(master=bf, text="-", command=remove) btngo=ttk.Button(master=bf, text="Submit", command=submit) btnplus.pack(side=tk.LEFT) btnminus.pack(side=tk.LEFT) btngo.pack(side=tk.LEFT) # bind also the delete and Backspace keys lb.bind('<Delete>', remove) lb.bind('<BackSpace>', remove) root.mainloop() =================================================== From framstag at rus.uni-stuttgart.de Sat Nov 28 07:48:43 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Sat, 28 Nov 2015 12:48:43 +0000 (UTC) Subject: askopenfilename() References: <n2hdfn$b1d$1@news2.informatik.uni-stuttgart.de> <n2hlr7$d1j$2@net.de> <n2ia83$icf$2@nuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> <mailman.509.1448009036.16136.python-list@python.org> <n2vgq3$76g$1@news2.informatik.uni-stuttgart.de> <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> <n3c3vu$a8t$1@dont-email.me> Message-ID: <n3c7rb$m4v$1@news2.informatik.uni-stuttgart.de> Christian Gollwitzer <auriocus at gmx.de> wrote: > Am 28.11.15 um 11:29 schrieb Ulli Horlacher: > > One of my Windows test users reports, that the file dialog window of > > askopenfilename() starts behind the console window and has no focus. > > On Linux (XFCE) I do not have this problem. > > > > I start it with: > > > > Tk().withdraw() > > file = askopenfilename(title='select a file',initialdir=HOME) > > set_window_focus() # give focus back to console window > > > > Can one force askopenfilename() to start in foreground with focus? > > I can't test it right now, but I think it /should/ go into the > foreground by itself. This is what I think, too :-) But my test user reports me, it is not so. > I see two thingd: > > 1) Tk().withdraw() > > - this seems odd to me, because you don't keep a reference to the Tk > object around. I thought, I need it for Tk initialization. But true, it is superfluous > I think that you are curing a lot of symptoms with the focus setting to > the console etc. This is done after the file selection window is closed. This works. > Many problems would simply go away if you wrote the whole thing as a GUI > program. Too much hassle. The predecessor was a Perl/Tk program and I have had to invest 90% of the programming work into the GUI handling. No fun at all. Now, with fexit in Python, I skipped most of these problems. The only GUI part is the file selection. > If I understand correctly, what you want - a program to select files and > folders to upload to your server This is only one of the tasks. The main menu looks: [s] send a file or directory [g] get a file [c] change login data (user, server, auth-ID) [l] login with webbrowser [u] update fexit [h] help [q] quit (with more features to come in the future) And the CLI: framstag at juhu:~: ./fexit.py -h usage: fexit [-C "comment"] [-a container] file(s) recipient[,...] example: fexit flupp.avi framstag at rus.uni-stuttgart.de example: fexit -C "more data" -a labdata *.png x1 at flupp.org,x2 at flupp.org usage: fexit FEX-download-URL example: fexit http://fex.rus.uni-stuttgart.de/fop/jHn34yp7/flupp.avi -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From jon+usenet at unequivocal.co.uk Sat Nov 28 08:29:54 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sat, 28 Nov 2015 13:29:54 -0000 (UTC) Subject: Python 3 virtualenvs References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> On 2015-11-28, D.M. Procida <real-not-anti-spam-address at apple-juice.co.uk> wrote: > I have a new installation of Debian Jessie, with Python 2.7 and 3.4 > installed. > > I want to use Python 3.4 by default for most things, so I want > virtualenv to create Python 3.4 virtualenvs unless I ask it to > otherwise. > > It turns out that this seems to be inordinately complex. sudo apt-get remove python-virtualenv sudo apt-get install python3-virtualenv From auriocus at gmx.de Sat Nov 28 08:34:27 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 28 Nov 2015 14:34:27 +0100 Subject: askopenfilename() In-Reply-To: <n3c7rb$m4v$1@news2.informatik.uni-stuttgart.de> References: <n2hdfn$b1d$1@news2.informatik.uni-stuttgart.de> <n2hlr7$d1j$2@net.de> <n2ia83$icf$2@nuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> <mailman.509.1448009036.16136.python-list@python.org> <n2vgq3$76g$1@news2.informatik.uni-stuttgart.de> <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> <n3c3vu$a8t$1@dont-email.me> <n3c7rb$m4v$1@news2.informatik.uni-stuttgart.de> Message-ID: <n3cacj$o5$1@dont-email.me> Am 28.11.15 um 13:48 schrieb Ulli Horlacher: > Christian Gollwitzer <auriocus at gmx.de> wrote: >> Many problems would simply go away if you wrote the whole thing as a GUI >> program. > > Too much hassle. > The predecessor was a Perl/Tk program and I have had to invest 90% of the > programming work into the GUI handling. No fun at all. As I see it, the program consists only of user interface - or is there any "algorithm" working behinds the scenes? Maybe you could pass the task on to somebody who enjoys GUI programming? > Now, with fexit in Python, I skipped most of these problems. > The only GUI part is the file selection. > > >> If I understand correctly, what you want - a program to select files and >> folders to upload to your server > > This is only one of the tasks. The main menu looks: > > [s] send a file or directory > [g] get a file > [c] change login data (user, server, auth-ID) > [l] login with webbrowser > [u] update fexit > [h] help > [q] quit All of this is easily integrated into a GUI like the one I posted (have you tried it?), either as a button or as a menu entry. IMO the most common GUI pattern for this kind of thing is a side-by-side view of the directories on the server and on the client, and a button (or drag'n'drop) to move files between both views. I understand this is not as easy as the script posted by me - nonetheless quite doable. For an experienced GUI script writer it'll take a weekend to get the basics running. > (with more features to come in the future) > > And the CLI: > > framstag at juhu:~: ./fexit.py -h > usage: fexit [-C "comment"] [-a container] file(s) recipient[,...] > example: fexit flupp.avi framstag at rus.uni-stuttgart.de > example: fexit -C "more data" -a labdata *.png x1 at flupp.org,x2 at flupp.org > > usage: fexit FEX-download-URL > example: fexit http://fex.rus.uni-stuttgart.de/fop/jHn34yp7/flupp.avi > This part should probably stay as it is. For a command line tool, an scp-like interface seems well-fitting. But for guided user input, an interface which prompts the user for input has never been a good solution. You have to work very hard to make that convenient. Have a look at lftp, for instance. In the end, real GUI programming will be easier (and more accessible) A (still) alternative solution would be an interface to the OS to make it a remote mounted folder (works for WebDAV on any modern OS, for instance) or a daemon, which watches and synchronizes a directory (this is how Dropbox works). This way it feels much more integrated to the user - they can use whatever file manager they like to do the transfer, or even "save" from any application (like Word, Firefox, ...) into the remote folder. Christian From gengyangcai at gmail.com Sat Nov 28 10:25:10 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 28 Nov 2015 07:25:10 -0800 (PST) Subject: An Educational Software Platform written in Python Message-ID: <88e7805c-700f-4a39-9698-f5c00401a335@googlegroups.com> So after reading YCombinator's new RFS, I have decided I want to build an educational software platform written in Python (mostly, if not entirely). Here is the description from YCombinator's RFS : If we can fix education, we can eventually do everything else on this list. The first attempts to use technology to fix education have focused on using the Internet to distribute traditional content to a wider audience. This is good, but the Internet is a fundamentally different medium and capable of much more. Solutions that combine the mass scale of technology with one-on-one in-person interaction are particularly interesting to us. This may not require a "breakthrough" technology in the classical sense, but at a minimum it will require very new ways of doing things. What resources would I need to obtain, learn and utilise on order to create this platform? Can I create something like this entirely in Python, or would I need to learn other technologies? Anyone can give some directions, thanks alot ! Gengyang From lac at openend.se Sat Nov 28 11:02:31 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 28 Nov 2015 17:02:31 +0100 Subject: askopenfilename() In-Reply-To: <n3c7rb$m4v$1@news2.informatik.uni-stuttgart.de> References: <n2hdfn$b1d$1@news2.informatik.uni-stuttgart.de> <n2hlr7$d1j$2@net.de> <n2ia83$icf$2@nuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> <mailman.509.1448009036.16136.python-list@python.org> <n2vgq3$76g$1@news2.informatik.uni-stuttgart.de> <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> <n3c3vu$a8t$1@dont-email.me> <n3c7rb$m4v$1@news2.informatik.uni-stuttgart.de> Message-ID: <201511281602.tASG2VgT020533@fido.openend.se> Maybe Wei Li Jiang's hack will work for you? http://stackoverflow.com/questions/3375227/how-to-give-tkinter-file-dialog-focus But then see if it works under MacOS. I fear it will not. Laura From framstag at rus.uni-stuttgart.de Sat Nov 28 11:05:57 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Sat, 28 Nov 2015 16:05:57 +0000 (UTC) Subject: askopenfilename() References: <n2hdfn$b1d$1@news2.informatik.uni-stuttgart.de> <n2hkho$d1j$1@news2.informatik.uni-stuttgart.de> <n2hlr7$d1j$2@net.de> <n2ia83$icf$2@nuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> <mailman.509.1448009036.16136.python-list@python.org> <n2vgq3$76g$1@news2.informatik.uni-stuttgart.de> <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> Message-ID: <n3cjd5$pip$1@news2.informatik.uni-stuttgart.de> Ulli Horlacher <framstag at rus.uni-stuttgart.de> wrote: > One of my Windows test users reports, that the file dialog window of > askopenfilename() starts behind the console window and has no focus. I have got a followup: this happens only with Windows XP, not with Windows 7. Therefore I will ignore this problem :-) -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From rhills at medimorphosis.com.au Sat Nov 28 11:25:07 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Sun, 29 Nov 2015 00:25:07 +0800 Subject: Find relative url in mixed text/html In-Reply-To: <8737vqyag1.fsf@jester.gateway.pace.com> References: <mailman.182.1448678122.20593.python-list@python.org> <8737vqyag1.fsf@jester.gateway.pace.com> Message-ID: <5659D563.6000005@medimorphosis.com.au> Hi Paul, On 28/11/15 13:11, Paul Rubin wrote: > Rob Hills <rhills at medimorphosis.com.au> writes: >> Note, in the beginning of this project, I looked at using "Beautiful >> Soup" but my reading and limited testing lead me to believe that it is >> designed for well-formed HTML/XML and therefore was unsuitable for the >> text/html soup I have. If that belief is incorrect, I'd be grateful for >> general tips about using Beautiful Soup in this scenario... > Beautiful Soup can deal with badly formed HTML pretty well, or at least > it could in earlier versions. It gives you several different parsing > options to choose from now. I think the default is lxml which is fast > but maybe more strict. Check what the others are and see if a loose > slow one is still there. It really is pretty slow so plan on a big > computation task if you're converting a large forum. I've had another look at Beautiful Soup and while it doesn't really help me much with urls (relative or absolute) embedded within text, it seems to do a good job of separating out links from the rest, so that could be useful in itself. WRT time, I'm converting about 65MB of data which currently takes 14 seconds (on a 3yo laptop with a SSD running Ubuntu), which I reckon is pretty amazing performance for Python3, especially given my relatively crude coding skills. It'll be interesting to see if using Beautiful Soup adds significantly to that. > phpBB gets a bad rap that's maybe well-deserved but I don't know what to > suggest instead. I did start to investigate Python-based alternatives; I've not heard much good said about php, but I probably move in the wrong circles. However, our hosting service doesn't support Python so I stopped hunting. Plus there is a significant group of forum members who hold very strong opinions about the functionality they want and it took a lot of work to get them to agree on something! All that said, I'd be interested to see specific (and hopefully unbiased) info about phpBB's failings... Cheers, -- Rob Hills Waikiki, Western Australia From marko at pacujo.net Sat Nov 28 11:39:36 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 28 Nov 2015 18:39:36 +0200 Subject: An Educational Software Platform written in Python References: <88e7805c-700f-4a39-9698-f5c00401a335@googlegroups.com> Message-ID: <87r3ja13jr.fsf@elektro.pacujo.net> Cai Gengyang <gengyangcai at gmail.com>: > Can I create something like this entirely in Python, Absolutely. It will only take ten to one hundred years for one person to create. Marko From framstag at rus.uni-stuttgart.de Sat Nov 28 11:45:51 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Sat, 28 Nov 2015 16:45:51 +0000 (UTC) Subject: askopenfilename() References: <n2hdfn$b1d$1@news2.informatik.uni-stuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> <mailman.509.1448009036.16136.python-list@python.org> <n2vgq3$76g$1@news2.informatik.uni-stuttgart.de> <n3bvn3$k2f$1@news2.informatik.uni-stuttgart.de> <n3c3vu$a8t$1@dont-email.me> <n3c7rb$m4v$1@news2.informatik.uni-stuttgart.de> <n3cacj$o5$1@dont-email.me> Message-ID: <n3clnv$pip$2@news2.informatik.uni-stuttgart.de> Christian Gollwitzer <auriocus at gmx.de> wrote: > Am 28.11.15 um 13:48 schrieb Ulli Horlacher: > > Christian Gollwitzer <auriocus at gmx.de> wrote: > >> Many problems would simply go away if you wrote the whole thing as a GUI > >> program. > > > > Too much hassle. > > The predecessor was a Perl/Tk program and I have had to invest 90% of the > > programming work into the GUI handling. No fun at all. > > As I see it, the program consists only of user interface - or is there > any "algorithm" working behinds the scenes? There is a lot of "algorithms", about 50 kB of code: - resuming upload and download after link failures - sending multiple files as zip or tar containers - deleting files - configuring login - handling HTTP proxy - many other things... > Maybe you could pass the task on to somebody who enjoys GUI programming? No, I then have to maintain it. I do not like to support foreign code. I was in this situation already. The client was written in Java, which I do not know. I have had to throw it away some day, because I was not able to fix the bugs. Therefore I started to write the new client fexit in Python. Here we are :-) > > This is only one of the tasks. The main menu looks: > > > > [s] send a file or directory > > [g] get a file > > [c] change login data (user, server, auth-ID) > > [l] login with webbrowser > > [u] update fexit > > [h] help > > [q] quit > > All of this is easily integrated into a GUI like the one I posted (have > you tried it?) As I wrote: I have done this already with Perl/Tk and it was HASSLE. No fun at all. > IMO the most common GUI pattern for this kind of thing is a side-by-side > view of the directories on the server and on the client There is no directory view on server side. > For an experienced GUI script writer it'll take a weekend to get the > basics running. I am not even a beginner GUI script writer and I do not want to become one. GUIs are most superfluous and delay the work flow. > for guided user input, an interface which prompts the user for input has > never been a good solution. You have to work very hard to make that > convenient. This is easy, because they have no alternative :-) > Have a look at lftp, for instance. Yes. Horrible user interface and even more horrible to program :-} > A (still) alternative solution would be an interface to the OS to make > it a remote mounted folder There are no remote folders. > (works for WebDAV on any modern OS, for instance) or a daemon, which > watches and synchronizes a directory (this is how Dropbox works). A VERY bad idea, if you have to send TB files. > This way it feels much more integrated to the user It shall not look integrated. The user should think before using it. > they can use whatever file manager they like to do the transfer There are no file manager which supports the F*EX protocol. Therefore I am forced to write my own clients. I am a lazy guy: if there is already a program, I will happily use it. Only if there is none, I program it by myself. > or even "save" from any application (like Word, Firefox, ...) into the > remote folder. There are no remote folders. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From lac at openend.se Sat Nov 28 12:04:08 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 28 Nov 2015 18:04:08 +0100 Subject: Find relative url in mixed text/html In-Reply-To: <5659D563.6000005@medimorphosis.com.au> References: <mailman.182.1448678122.20593.python-list@python.org> <8737vqyag1.fsf@jester.gateway.pace.com> <5659D563.6000005@medimorphosis.com.au> Message-ID: <201511281704.tASH48eB021469@fido.openend.se> In a message of Sun, 29 Nov 2015 00:25:07 +0800, Rob Hills writes: >All that said, I'd be interested to see specific (and hopefully >unbiased) info about phpBB's failings... People I know of who run different bb software say that the spammers really prefer phpBB. So keeping it spam free is about 4 times the work as for, for instance, IPB. Hackers seem to like it too -- possibly due to this: http://defensivedepth.com/2009/03/03/anatomy-of-a-hack-the-phpbbcom-attack/ make sure you aren't vulnerable. From amfarrell at mit.edu Sat Nov 28 12:18:05 2015 From: amfarrell at mit.edu (Andrew Farrell) Date: Sat, 28 Nov 2015 11:18:05 -0600 Subject: An Educational Software Platform written in Python In-Reply-To: <87r3ja13jr.fsf@elektro.pacujo.net> References: <88e7805c-700f-4a39-9698-f5c00401a335@googlegroups.com> <87r3ja13jr.fsf@elektro.pacujo.net> Message-ID: <CA+y5TLaZowUg1tJ2fkEBZ-EQWcueYvSv4VEGe3BudLamNDgxYg@mail.gmail.com> I would look first at the open source software released by EdX: https://open.edx.org/ On Sat, Nov 28, 2015 at 10:39 AM, Marko Rauhamaa <marko at pacujo.net> wrote: > Cai Gengyang <gengyangcai at gmail.com>: > > > Can I create something like this entirely in Python, > > Absolutely. It will only take ten to one hundred years for one person to > create. > > > Marko > -- > https://mail.python.org/mailman/listinfo/python-list > From rhills at medimorphosis.com.au Sat Nov 28 12:40:49 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Sun, 29 Nov 2015 01:40:49 +0800 Subject: Find relative url in mixed text/html In-Reply-To: <201511281704.tASH48eB021469@fido.openend.se> References: <mailman.182.1448678122.20593.python-list@python.org> <8737vqyag1.fsf@jester.gateway.pace.com> <5659D563.6000005@medimorphosis.com.au> <201511281704.tASH48eB021469@fido.openend.se> Message-ID: <5659E721.4020007@medimorphosis.com.au> Hi Laura, On 29/11/15 01:04, Laura Creighton wrote: > In a message of Sun, 29 Nov 2015 00:25:07 +0800, Rob Hills writes: >> All that said, I'd be interested to see specific (and hopefully >> unbiased) info about phpBB's failings... > People I know of who run different bb software say that the spammers > really prefer phpBB. So keeping it spam free is about 4 times the > work as for, for instance, IPB. > > Hackers seem to like it too -- possibly due to this: > http://defensivedepth.com/2009/03/03/anatomy-of-a-hack-the-phpbbcom-attack/ > > make sure you aren't vulnerable. Thanks for the link and the advice. Personally, I'd rather go with something based on a language I am reasonably familiar with (eg Python or Java) however it seems the vast bulk of Forum software is based on PHP :-( Cheers, -- Rob Hills Waikiki, Western Australia From rhills at medimorphosis.com.au Sat Nov 28 12:44:58 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Sun, 29 Nov 2015 01:44:58 +0800 Subject: Find relative url in mixed text/html In-Reply-To: <n3bjmq$pdi$1@dont-email.me> References: <mailman.182.1448678122.20593.python-list@python.org> <n3bjmq$pdi$1@dont-email.me> Message-ID: <5659E81A.3090202@medimorphosis.com.au> Hi Grobu, On 28/11/15 15:07, Grobu wrote: > Is it safe to assume that all the relative (cross) links take one of > the following forms? : > > http://www.aeva.asn.au/forums/forum_posts.asp > www.aeva.asn.au/forums/forum_posts.asp > /forums/forum_posts.asp > /forum_posts.asp (are you really sure about this one?) > > If so, and if your goal boils down to converting all instances of old > style URLs to new style ones regardless of the context where they > appear, why would a regex fail to meet your needs? I'm actually not discounting anything and as I mentioned, I've already used some regex to extract the properly-formed URLs (those starting with http://). I was fortunately able to find some example regex that I could figure out enough to tweak for my purpose. Unfortunately, my small brain hurts whenever I try and understand what a piece of regex is doing and I don't like having bits in my code that hurt my brain. BTW, that's not meant to be an invitation to someone to produce some regex for me, if I can't find any other way of doing it, I'll try and create my own regex and come back here if I can't get that working. Cheers, -- Rob Hills Waikiki, Western Australia From no.email at nospam.invalid Sat Nov 28 13:10:28 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 28 Nov 2015 10:10:28 -0800 Subject: Find relative url in mixed text/html References: <mailman.182.1448678122.20593.python-list@python.org> <8737vqyag1.fsf@jester.gateway.pace.com> <5659D563.6000005@medimorphosis.com.au> <201511281704.tASH48eB021469@fido.openend.se> <mailman.190.1448732454.20593.python-list@python.org> Message-ID: <87a8pyc7vv.fsf@nightsong.com> Rob Hills <rhills at medimorphosis.com.au> writes: > Personally, I'd rather go with something based on a language I am > reasonably familiar with (eg Python or Java) however it seems the vast > bulk of Forum software is based on PHP :-( It's certainly possible to write good software in PHP, so it's mostly a matter of the design and implementation quality. I was on a big PhpBB forum years ago and it got very slow as the database got large, and there were multiple incidents of database corruption. The board eventually switched to VBB which was a lot better. VBB is the best one I know of but it's not FOSS. I'm on another one right now which uses IPB (also not FOSS) and don't like it much (too clever for its own good). Another one is FluxBB which is nice and lightweight and FOSS, but it's a small forum and the software might not be up to handling a bigger one. Some people like Discourse. I don't like it much myself, but that's just me. There's certainly plenty of cheap hosting available these days (or raw VPS) that let you run Python or whatever else you want. But it seems to me that forum software is something of a ghetto. I do think there is some written in Python but I don't remember any specifics. From real-not-anti-spam-address at apple-juice.co.uk Sat Nov 28 14:37:21 2015 From: real-not-anti-spam-address at apple-juice.co.uk (D.M. Procida) Date: Sat, 28 Nov 2015 19:37:21 +0000 Subject: Python 3 virtualenvs References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> Message-ID: <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> Jon Ribbens <jon+usenet at unequivocal.co.uk> wrote: > On 2015-11-28, D.M. Procida <real-not-anti-spam-address at apple-juice.co.uk> wrote: > > I have a new installation of Debian Jessie, with Python 2.7 and 3.4 > > installed. > > > > I want to use Python 3.4 by default for most things, so I want > > virtualenv to create Python 3.4 virtualenvs unless I ask it to > > otherwise. > > > > It turns out that this seems to be inordinately complex. > > sudo apt-get remove python-virtualenv > sudo apt-get install python3-virtualenv Yup, I did try installing python3-virtualenv, but it didn't appear actually do do anything. It didn't provide me with a virtualenv command, that's for sure. And pages such as https://packages.debian.org/jessie/python3-virtualenv are not exactly informative. Is something else required? Daniele From joel.goldstick at gmail.com Sat Nov 28 16:33:40 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 28 Nov 2015 16:33:40 -0500 Subject: An Educational Software Platform written in Python In-Reply-To: <87r3ja13jr.fsf@elektro.pacujo.net> References: <88e7805c-700f-4a39-9698-f5c00401a335@googlegroups.com> <87r3ja13jr.fsf@elektro.pacujo.net> Message-ID: <CAPM-O+wrKROvFDP2mYwSBTkvWbm3ygX5ZphwpXa7kQGiBgwEZg@mail.gmail.com> On Sat, Nov 28, 2015 at 11:39 AM, Marko Rauhamaa <marko at pacujo.net> wrote: > Cai Gengyang <gengyangcai at gmail.com>: > > > Can I create something like this entirely in Python, > > Absolutely. It will only take ten to one hundred years for one person to > create. > > > Marko > -- > https://mail.python.org/mailman/listinfo/python-list > Cai, Start small. write some 10 line programs. Then some 30 line programs. then write 100 more usefull programs. Then you will understand what it is you can do or can't. -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From matthew.herzog at gmail.com Sat Nov 28 16:45:34 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sat, 28 Nov 2015 13:45:34 -0800 (PST) Subject: Generate config file from template using Python search and replace. Message-ID: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> I need to generate a config file based on an existing "template" file. I need to replace a set of strings with other strings globally in the generated file. Here is a snippet of the template file, where CONTENT_PATH and DAMPATH are two "placeholders" or variables. There are several other such placeholders. $include "_dispatcher_publish_filters.any" /1000 { /type "allow" /glob "* /CONTENT_PATH/*.html*" } /1001 { /type "allow" /glob "POST /DAMPATH/www/*.html *" } The script's user will be asked to type in unique values when prompted for DAMPATH or CONTENT_PATH. Since I know the variables themselves are not going to change (because the contents of the template file don't spontaneously change) should I be using regex to search for them or is there a better way? I was planning on using re.sub but I don't know whether that's the best way. Here's what my script looks like today. from sys import argv import re from os.path import exists script, template_file = argv print "Opening the template file..." in_file = open(template_file) lines = in_file.readlines() print "What is the serial number of the site?", _NNN = raw_input() print "What is the brand, or product name?", _BRAND = raw_input() print "What is the content path?", _CONTENT_PATH = raw_input() out_file = open(_nnn + _brand + "_farm.any", 'w') for line in lines: re.sub('NNN', _NNN, line) re.sub('BRAND, _BRAND', line) re.sub('CONTENT_PATH', _CONTENT_PATH, line) out_file.close() From jon+usenet at unequivocal.co.uk Sat Nov 28 16:48:37 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sat, 28 Nov 2015 21:48:37 -0000 (UTC) Subject: Python 3 virtualenvs References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> On 2015-11-28, D.M. Procida <real-not-anti-spam-address at apple-juice.co.uk> wrote: > Jon Ribbens <jon+usenet at unequivocal.co.uk> wrote: > >> On 2015-11-28, D.M. Procida <real-not-anti-spam-address at apple-juice.co.uk> > wrote: >> > I have a new installation of Debian Jessie, with Python 2.7 and 3.4 >> > installed. >> > >> > I want to use Python 3.4 by default for most things, so I want >> > virtualenv to create Python 3.4 virtualenvs unless I ask it to >> > otherwise. >> > >> > It turns out that this seems to be inordinately complex. >> >> sudo apt-get remove python-virtualenv >> sudo apt-get install python3-virtualenv > > Yup, I did try installing python3-virtualenv, but it didn't appear > actually do do anything. It didn't provide me with a virtualenv command, > that's for sure. > > And pages such as https://packages.debian.org/jessie/python3-virtualenv > are not exactly informative. > > Is something else required? Hmm. Well basically the answer to your question is that you want virtualenv to be installed by Python 3, then it will default to using it. Debian's package management is mysterious and apparently bizarre and frankly in respect to Python, not very good. So perhaps the best thing to do is simply ignore it and install virtualenv yourself with: sudo apt-get install python3-pip sudo pip3 install virtualenv ... although you might want to install pip manually too. From ryanshuell at gmail.com Sat Nov 28 17:03:10 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Sat, 28 Nov 2015 14:03:10 -0800 (PST) Subject: Does Python allow variables to be passed into function for dynamic screen scraping? Message-ID: <e13afc4b-ac4e-4a75-bca6-1c7be9399cb6@googlegroups.com> I'm looking at this URL. https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names If I hit F12 I can see tags such as these: <a title= <a class= And so on and so forth. I'm wondering if someone can share a script, or a function, that will allow me to pass in variables and download (or simply print) the results. I saw a sample online that I thought would work, and I made a few modifications but now I keep getting a message that says: ValueError: All objects passed were None Here's the script that I'm playing around with. import requests import pandas as pd from bs4 import BeautifulSoup #Get the relevant webpage set the data up for parsing url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" r = requests.get(url) soup=BeautifulSoup(r.content,"lxml") #set up a function to parse the "soup" for each category of information and put it in a DataFrame def get_match_info(soup,tag,class_name): info_array=[] for info in soup.find_all('%s'%tag,attrs={'class':'%s'%class_name}): return pd.DataFrame(info_array) #for each category pass the above function the relevant information i.e. tag names tag1 = get_match_info(soup,"td","title") tag2 = get_match_info(soup,"td","class") #Concatenate the DataFrames to present a final table of all the above info match_info = pd.concat([tag1,tag2],ignore_index=False,axis=1) print match_info I'd greatly appreciate any help with this. From matthew.herzog at gmail.com Sat Nov 28 17:04:38 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sat, 28 Nov 2015 14:04:38 -0800 (PST) Subject: Generate config file from template using Python search and replace. In-Reply-To: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> Message-ID: <8324634d-5afe-48d6-942a-1b006ddc0ce4@googlegroups.com> I should mention the template file is small, just 98 lines long and the working config file will be the same size. From lac at openend.se Sat Nov 28 17:28:25 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 28 Nov 2015 23:28:25 +0100 Subject: Does Python allow variables to be passed into function for dynamic screen scraping? In-Reply-To: <e13afc4b-ac4e-4a75-bca6-1c7be9399cb6@googlegroups.com> References: <e13afc4b-ac4e-4a75-bca6-1c7be9399cb6@googlegroups.com> Message-ID: <201511282228.tASMSPhf025908@fido.openend.se> In a message of Sat, 28 Nov 2015 14:03:10 -0800, ryguy7272 writes: >I'm looking at this URL. >https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names > >If I hit F12 I can see tags such as these: ><a title= ><a class= >And so on and so forth. > >I'm wondering if someone can share a script, or a function, that will allow me to pass in variables and download (or simply print) the results. I saw a sample online that I thought would work, and I made a few modifications but now I keep getting a message that says: ValueError: All objects passed were None > >Here's the script that I'm playing around with. > >import requests >import pandas as pd >from bs4 import BeautifulSoup > >#Get the relevant webpage set the data up for parsing >url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" >r = requests.get(url) >soup=BeautifulSoup(r.content,"lxml") > >#set up a function to parse the "soup" for each category of information and put it in a DataFrame >def get_match_info(soup,tag,class_name): > info_array=[] > for info in soup.find_all('%s'%tag,attrs={'class':'%s'%class_name}): > return pd.DataFrame(info_array) > >#for each category pass the above function the relevant information i.e. tag names >tag1 = get_match_info(soup,"td","title") >tag2 = get_match_info(soup,"td","class") > >#Concatenate the DataFrames to present a final table of all the above info >match_info = pd.concat([tag1,tag2],ignore_index=False,axis=1) > >print match_info > >I'd greatly appreciate any help with this. Post your error traceback. If you are getting Value Errors about None, then probably something you expect to return a match, isn't. But without the actual error, we cannot help much. Laura From ryanshuell at gmail.com Sat Nov 28 17:37:26 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Sat, 28 Nov 2015 14:37:26 -0800 (PST) Subject: Does Python allow variables to be passed into function for dynamic screen scraping? In-Reply-To: <mailman.1.1448749716.14615.python-list@python.org> References: <e13afc4b-ac4e-4a75-bca6-1c7be9399cb6@googlegroups.com> <mailman.1.1448749716.14615.python-list@python.org> Message-ID: <48f7bb74-93f0-4bf8-b781-e7f4b2daf032@googlegroups.com> On Saturday, November 28, 2015 at 5:28:55 PM UTC-5, Laura Creighton wrote: > In a message of Sat, 28 Nov 2015 14:03:10 -0800, ryguy7272 writes: > >I'm looking at this URL. > >https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names > > > >If I hit F12 I can see tags such as these: > ><a title= > ><a class= > >And so on and so forth. > > > >I'm wondering if someone can share a script, or a function, that will allow me to pass in variables and download (or simply print) the results. I saw a sample online that I thought would work, and I made a few modifications but now I keep getting a message that says: ValueError: All objects passed were None > > > >Here's the script that I'm playing around with. > > > >import requests > >import pandas as pd > >from bs4 import BeautifulSoup > > > >#Get the relevant webpage set the data up for parsing > >url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" > >r = requests.get(url) > >soup=BeautifulSoup(r.content,"lxml") > > > >#set up a function to parse the "soup" for each category of information and put it in a DataFrame > >def get_match_info(soup,tag,class_name): > > info_array=[] > > for info in soup.find_all('%s'%tag,attrs={'class':'%s'%class_name}): > > return pd.DataFrame(info_array) > > > >#for each category pass the above function the relevant information i.e. tag names > >tag1 = get_match_info(soup,"td","title") > >tag2 = get_match_info(soup,"td","class") > > > >#Concatenate the DataFrames to present a final table of all the above info > >match_info = pd.concat([tag1,tag2],ignore_index=False,axis=1) > > > >print match_info > > > >I'd greatly appreciate any help with this. > > Post your error traceback. If you are getting Value Errors about None, > then probably something you expect to return a match, isn't. But without > the actual error, we cannot help much. > > Laura Ok. How do I post the error traceback? I'm using Spyder Python 2.7. From lac at openend.se Sat Nov 28 17:44:21 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 28 Nov 2015 23:44:21 +0100 Subject: Does Python allow variables to be passed into function for dynamic screen scraping? In-Reply-To: <48f7bb74-93f0-4bf8-b781-e7f4b2daf032@googlegroups.com> References: <e13afc4b-ac4e-4a75-bca6-1c7be9399cb6@googlegroups.com> <mailman.1.1448749716.14615.python-list@python.org> <48f7bb74-93f0-4bf8-b781-e7f4b2daf032@googlegroups.com> Message-ID: <201511282244.tASMiLKp026166@fido.openend.se> In a message of Sat, 28 Nov 2015 14:37:26 -0800, ryguy7272 writes: >On Saturday, November 28, 2015 at 5:28:55 PM UTC-5, Laura Creighton wrote: >> In a message of Sat, 28 Nov 2015 14:03:10 -0800, ryguy7272 writes: >> >I'm looking at this URL. >> >https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names >> > >> >If I hit F12 I can see tags such as these: >> ><a title= >> ><a class= >> >And so on and so forth. >> > >> >I'm wondering if someone can share a script, or a function, that will allow me to pass in variables and download (or simply print) the results. I saw a sample online that I thought would work, and I made a few modifications but now I keep getting a message that says: ValueError: All objects passed were None >> > >> >Here's the script that I'm playing around with. >> > >> >import requests >> >import pandas as pd >> >from bs4 import BeautifulSoup >> > >> >#Get the relevant webpage set the data up for parsing >> >url = "https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names" >> >r = requests.get(url) >> >soup=BeautifulSoup(r.content,"lxml") >> > >> >#set up a function to parse the "soup" for each category of information and put it in a DataFrame >> >def get_match_info(soup,tag,class_name): >> > info_array=[] >> > for info in soup.find_all('%s'%tag,attrs={'class':'%s'%class_name}): >> > return pd.DataFrame(info_array) >> > >> >#for each category pass the above function the relevant information i.e. tag names >> >tag1 = get_match_info(soup,"td","title") >> >tag2 = get_match_info(soup,"td","class") >> > >> >#Concatenate the DataFrames to present a final table of all the above info >> >match_info = pd.concat([tag1,tag2],ignore_index=False,axis=1) >> > >> >print match_info >> > >> >I'd greatly appreciate any help with this. >> >> Post your error traceback. If you are getting Value Errors about None, >> then probably something you expect to return a match, isn't. But without >> the actual error, we cannot help much. >> >> Laura > > >Ok. How do I post the error traceback? I'm using Spyder Python 2.7. You cut and paste it out of wherever you are reading it, and paste it into the email, along with your code, also cut and pasted from somewhere (like an editor). That way we get the exact code that caused the exact traceback you are getting. Laura From __peter__ at web.de Sat Nov 28 18:07:53 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 29 Nov 2015 00:07:53 +0100 Subject: Generate config file from template using Python search and replace. References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> Message-ID: <n3dc4a$bli$1@ger.gmane.org> Mr Zaug wrote: > I need to generate a config file based on an existing "template" file. I > need to replace a set of strings with other strings globally in the > generated file. > > Here is a snippet of the template file, where CONTENT_PATH and DAMPATH are > two "placeholders" or variables. There are several other such > placeholders. > > $include "_dispatcher_publish_filters.any" > /1000 { /type "allow" /glob "* /CONTENT_PATH/*.html*" } > /1001 { /type "allow" /glob "POST /DAMPATH/www/*.html *" } > > The script's user will be asked to type in unique values when prompted for > DAMPATH or CONTENT_PATH. > > Since I know the variables themselves are not going to change (because the > contents of the template file don't spontaneously change) should I be > using regex to search for them or is there a better way? I was planning on > using re.sub but I don't know whether that's the best way. Here's what my > script looks like today. > > from sys import argv > import re > from os.path import exists > > script, template_file = argv > print "Opening the template file..." > > in_file = open(template_file) > lines = in_file.readlines() > > print "What is the serial number of the site?", > _NNN = raw_input() > > print "What is the brand, or product name?", > _BRAND = raw_input() > > print "What is the content path?", > _CONTENT_PATH = raw_input() > > out_file = open(_nnn + _brand + "_farm.any", 'w') > > for line in lines: > re.sub('NNN', _NNN, line) > re.sub('BRAND, _BRAND', line) > re.sub('CONTENT_PATH', _CONTENT_PATH, line) > > out_file.close() There are many templating systems out there. Pick the one that suits you best. A very basic one is str.format(): >>> "{foo} {bar}".format(foo=1, bar=2) '1 2' Here's what your script might become if you choose that one: $ cat interactive_template.txt $include "_dispatcher_publish_filters.any" /1000 {{ /type "allow" /glob "* /{CONTENT_PATH}/*.html*" }} /1001 {{ /type "allow" /glob "POST /{DAMPATH}/www/*.html *" }} $ cat interactive_template.py try: format_map = str.format_map except AttributeError: # python 2 compatibility import string def format_map(text, lookup): return string.Formatter().vformat(text, (), lookup) input = raw_input class Lookup(dict): def __missing__(self, key): self[key] = value = input("{}: ".format(key)) return value def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument("template_file") parser.add_argument("generated_file", nargs="?") args = parser.parse_args() with open(args.template_file) as instream: template_text = instream.read() lookup = Lookup() generated_text = format_map(template_text, lookup) generated_file = args.generated_file if generated_file is None: generated_file = format_map("{nnn}{brand}_farm.any", lookup) print("Writing {}".format(generated_file)) with open(generated_file, "w") as outstream: outstream.write(generated_text) if __name__ == "__main__": main() $ python interactive_template.py interactive_template.txt CONTENT_PATH: foo DAMPATH: bar nnn: baz brand: ham Writing bazham_farm.any $ cat bazham_farm.any $include "_dispatcher_publish_filters.any" /1000 { /type "allow" /glob "* /foo/*.html*" } /1001 { /type "allow" /glob "POST /bar/www/*.html *" } From steve at pearwood.info Sat Nov 28 20:58:42 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 29 Nov 2015 12:58:42 +1100 Subject: Does Python allow variables to be passed into function for dynamic screen scraping? References: <e13afc4b-ac4e-4a75-bca6-1c7be9399cb6@googlegroups.com> Message-ID: <565a5bd5$0$1606$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 Nov 2015 09:03 am, ryguy7272 wrote: > I'm looking at this URL. > https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names Don't screen-scrape Wikipedia. Just don't. They have an official API for downloading content, use it. There's even a Python library for downloading from Wikipedia and other Mediawiki sites: https://www.mediawiki.org/wiki/Manual:Pywikibot Wikimedia does a fantastic job, for free, and automated screen-scraping hurts their ability to provide that service. It is rude and anti-social. Please don't do it. -- Steven From jfong at ms4.hinet.net Sat Nov 28 21:55:10 2015 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 28 Nov 2015 18:55:10 -0800 (PST) Subject: python response slow when running external DLL In-Reply-To: <mailman.184.1448705627.20593.python-list@python.org> References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <mailman.173.1448626828.20593.python-list@python.org> <d6c59a36-38ba-4f26-b949-18f2b226e7e3@googlegroups.com> <mailman.184.1448705627.20593.python-list@python.org> Message-ID: <3ec6a016-dae5-4986-b035-c1a8cd4dc3e7@googlegroups.com> Peter Otten at 2015/11/28 UTC+8 6:14:09PM wrote? > No, the point of both recipes is that tkinter operations are only ever > invoked from the main thread. The main thread has polling code that > repeatedly looks if there are results from the helper thread. As far I > understand the polling method has the structure > > f(): > # did we get something back from the other thread? > # a queue is used to avoid race conditions > > # if yes react. > # var_status.set() goes here > > # reschedule f to run again in a few millisecs; > # that's what after() does Have no idea how the main thread poll on all those events (or it use a queue)? All I know now is that the main thread(mainloop()?) can be easily blocked by event handlers if the handler didn't run as a separate thread. > > ..... > > ..... > > #do the rest > > var_status.set('Download...') > > _thread.start_new_thread(td_download, ()) #must use threading > > > > def td_download(): > > result = mydll.SayHello() > > if result: > > var_status.set("Download Fail at %s" % hex(result)) > > showerror('Romter', 'Download Fail') > > else: > > var_status.set('Download OK') > > showinfo('Romter', 'Download OK') > > As td_download() runs in the other thread the var_status.set() methods are > problematic. No idea what kind of problem it will encounter. Can you explain? > Another complication that inevitably comes with concurrency: what if the > user triggers another download while one download is already running? If you > don't keep track of all downloads the message will already switch to > "Download OK" while one download is still running. Hummm...this thought never comes to my mind. After take a quick test I found, you are right, a second "download" was triggered immediately. That's a shock to me. I suppose the same event shouldn't be triggered again, or at least not triggered immediately, before its previous handler was completed. ...I will take a check later on Borland C++ builder to see how it reacts! Anyway to prevent this happens? if Python didn't take care it for us. From jfong at ms4.hinet.net Sat Nov 28 22:04:23 2015 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 28 Nov 2015 19:04:23 -0800 (PST) Subject: python response slow when running external DLL In-Reply-To: <mailman.185.1448707926.20593.python-list@python.org> References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <mailman.173.1448626828.20593.python-list@python.org> <d6c59a36-38ba-4f26-b949-18f2b226e7e3@googlegroups.com> <n3buoh$3r1$1@ger.gmane.org> <mailman.185.1448707926.20593.python-list@python.org> Message-ID: <3ee1f8f1-afaa-4610-a942-f6cdef61995e@googlegroups.com> Laura Creighton at 2015/11/28 UTC+8 6:52:25PM wrote? > I never saw the reply that Peter is replying to. > The threading module constructs a higher level interface on top of the > low level thread module. Thus it is the preferred way to go for > standard Python code -- and even Fredrik's recipe contains the > line: > import thread # should use the threading module instead! > > Laura Hi! Laura, takes the porting of an old BCB GUI program as an exercise in my learning python, I just quickly grab the required tools (mainly the tkinter) in python to complete this "work" and get a feeling of how python performs on doing this. Most of my knowledge of python comes from Mark Lutz's book "Learning python" and "Programming python". I didn't dive into this language deeply yet. There are topics about "_thread" and "threading" modules in the book and I just pick the lower level one for this because the "threading" is based on the "_thread". Thanks for your note and link. --Jach From ryanshuell at gmail.com Sat Nov 28 23:52:59 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Sat, 28 Nov 2015 20:52:59 -0800 (PST) Subject: Does Python allow variables to be passed into function for dynamic screen scraping? In-Reply-To: <565a5bd5$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <e13afc4b-ac4e-4a75-bca6-1c7be9399cb6@googlegroups.com> <565a5bd5$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2e25f82c-1ed6-4c56-836d-8f9a25990ea9@googlegroups.com> On Saturday, November 28, 2015 at 8:59:04 PM UTC-5, Steven D'Aprano wrote: > On Sun, 29 Nov 2015 09:03 am, ryguy7272 wrote: > > > I'm looking at this URL. > > https://en.wikipedia.org/wiki/Wikipedia:Unusual_place_names > > Don't screen-scrape Wikipedia. Just don't. They have an official API for > downloading content, use it. There's even a Python library for downloading > from Wikipedia and other Mediawiki sites: > > https://www.mediawiki.org/wiki/Manual:Pywikibot > > Wikimedia does a fantastic job, for free, and automated screen-scraping > hurts their ability to provide that service. It is rude and anti-social. > Please don't do it. > > > > -- > Steven Thanks Steven. Do you know of a good tutorial for learning about Wikipedia APIs? I'm not sure where to get started on this topic. I did some Google searches, but didn't come up with a lot of useful info...not much actually... From plucena24 at gmail.com Sun Nov 29 03:14:03 2015 From: plucena24 at gmail.com (Pablo Lucena) Date: Sun, 29 Nov 2015 03:14:03 -0500 Subject: https://www.python.org/downloads/ offline Message-ID: <CAB_tDZyWubAdN8H-2J5YXU5L+r4Zeyeenkvgv1Ve2e246D4Oog@mail.gmail.com> Is anyone else getting 503 errors when accessing the downloads page of python.org? -- *Pablo Lucena* From rosuav at gmail.com Sun Nov 29 04:26:12 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Nov 2015 20:26:12 +1100 Subject: https://www.python.org/downloads/ offline In-Reply-To: <CAB_tDZyWubAdN8H-2J5YXU5L+r4Zeyeenkvgv1Ve2e246D4Oog@mail.gmail.com> References: <CAB_tDZyWubAdN8H-2J5YXU5L+r4Zeyeenkvgv1Ve2e246D4Oog@mail.gmail.com> Message-ID: <CAPTjJmpyR6vfPyv54fu0zV53YQ5gULSiyBE_hm_=3LXTgaJm+w@mail.gmail.com> On Sun, Nov 29, 2015 at 7:14 PM, Pablo Lucena <plucena24 at gmail.com> wrote: > Is anyone else getting 503 errors when accessing the downloads page of > python.org? > > > -- > *Pablo Lucena* > -- > https://mail.python.org/mailman/listinfo/python-list Yes, the whole site seems to be down. Cc'ing the www list, although someone probably knows already. ChrisA From lele at metapensiero.it Sun Nov 29 07:19:46 2015 From: lele at metapensiero.it (Lele Gaifax) Date: Sun, 29 Nov 2015 13:19:46 +0100 Subject: Python 3 virtualenvs References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> Message-ID: <8737vp0zh9.fsf@metapensiero.it> Jon Ribbens <jon+usenet at unequivocal.co.uk> writes: > On 2015-11-28, D.M. Procida <real-not-anti-spam-address at apple-juice.co.uk> wrote: >> >> Is something else required? > > Debian's package management is mysterious and apparently bizarre > and frankly in respect to Python, not very good. I do not agree with you on the quality of Python support on Debian systems, but I think Daniele is missing the package "pythonX.Y-venv": they install the needed stuff, and in particular /usr/bin/pyvenv-X-Y. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From lac at openend.se Sun Nov 29 07:27:02 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 29 Nov 2015 13:27:02 +0100 Subject: Python 3 virtualenvs In-Reply-To: <8737vp0zh9.fsf@metapensiero.it> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> Message-ID: <201511291227.tATCR2on004824@fido.openend.se> In a message of Sun, 29 Nov 2015 13:19:46 +0100, Lele Gaifax writes: >Jon Ribbens <jon+usenet at unequivocal.co.uk> writes: > >> On 2015-11-28, D.M. Procida <real-not-anti-spam-address at apple-juice.co.uk> wrote: >>> >>> Is something else required? >> >> Debian's package management is mysterious and apparently bizarre >> and frankly in respect to Python, not very good. > >I do not agree with you on the quality of Python support on Debian systems, >but I think Daniele is missing the package "pythonX.Y-venv": they install the >needed stuff, and in particular /usr/bin/pyvenv-X-Y. > >ciao, lele. No, Pyvenv is precisely what Daniele can not use. The problem is that venv does not come with a big sign saying ONLY FOR PYTHON 3.x ABSOLUTELY DOES NOT WORK FOR BUILDING 2.7 VIRTUALENVS USE virtualenv INSTEAD for Python 2.7 ---- which means you can waste a whole lot of time finding this out the hard way. Laura From jon+usenet at unequivocal.co.uk Sun Nov 29 08:23:19 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sun, 29 Nov 2015 13:23:19 -0000 (UTC) Subject: Python 3 virtualenvs References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> <mailman.7.1448800035.14615.python-list@python.org> Message-ID: <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> On 2015-11-29, Laura Creighton <lac at openend.se> wrote: > In a message of Sun, 29 Nov 2015 13:19:46 +0100, Lele Gaifax writes: >>Jon Ribbens <jon+usenet at unequivocal.co.uk> writes: > No, Pyvenv is precisely what Daniele can not use. > The problem is that venv does not come with a big sign saying > > ONLY FOR PYTHON 3.x > ABSOLUTELY DOES NOT WORK FOR BUILDING 2.7 VIRTUALENVS > USE virtualenv INSTEAD for Python 2.7 > > ---- > > which means you can waste a whole lot of time finding this out > the hard way. More specifically, "only for Python >= 3.4", because before that it does not install pip, which makes it fairly useless. In my experience the best thing to do is ignore pyvenv and ignore Debian's package management for anything other than installing the Python interpreter itself. Install pip by hand, then use that to install virtualenv, then just use those to create virtualenvs to run your stuff. I don't know if, in future, pyvenv will be the way to go and virtualenv will be deprecated, but either way we do not appear to be there yet. From stefan_ml at behnel.de Sun Nov 29 08:26:41 2015 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 29 Nov 2015 14:26:41 +0100 Subject: Writing SOME class methods in C In-Reply-To: <CAHVvXxSEN5PYeJ==u=fWKxAkmsZXU8FhsFOFDQd_05T8M5OgBw@mail.gmail.com> References: <slrnn4obfa.db7.dh@dotcom.mfs32> <CAHVvXxSEN5PYeJ==u=fWKxAkmsZXU8FhsFOFDQd_05T8M5OgBw@mail.gmail.com> Message-ID: <n3eueh$pfd$1@ger.gmane.org> Oscar Benjamin schrieb am 18.11.2015 um 13:52: > On 18 November 2015 at 07:50, Daniel Haude wrote: >> >> I'm trying to implement some (but not all) methods of a Python class in C. >> What I've found on the Net is: >> - how to implement entire modules in C so that I can import that module and >> use the C functions (successfully done it, too). >> - how to implement entire classes in C > > I would suggest to use Cython here. You can write your class in Python > (that will be compiled to C) and then call out to any C code from any > of its methods. Or, in fact, do the reverse: Implement the base class in Cython and inherit from it in a Python class that extends it. That would give you a fast, native extension type at the base and leaves you with all the freedom to extend it in Python code or even natively in other Cython code. I strongly recommend not to resort to writing real C code here (using the C-API of CPython). It will be slower and will contain more bugs. Stefan From vadodsantos at yahoo.com Sun Nov 29 08:30:20 2015 From: vadodsantos at yahoo.com (Osvaldo Dias dos Santos) Date: Sun, 29 Nov 2015 14:30:20 +0100 Subject: Caret key quits idle on pt keyboard Message-ID: <ADE3DE97-52FD-4A99-838D-4BEBCC5261D6@yahoo.com> Hi, I can?t enter a caret in regex on a Portuguese keyboard because by pressing it, IDLE quits. Any help ? Thanks. Kind regards, Osvaldo From lac at openend.se Sun Nov 29 09:12:20 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 29 Nov 2015 15:12:20 +0100 Subject: Python 3 virtualenvs In-Reply-To: <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> <mailman.7.1448800035.14615.python-list@python.org> <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> Message-ID: <201511291412.tATECKN8006265@fido.openend.se> In a message of Sun, 29 Nov 2015 13:23:19 +0000, Jon Ribbens writes: >I don't know if, in future, pyvenv will be the way to go and >virtualenv will be deprecated, but either way we do not appear >to be there yet. pyenv is going away. python -m venv is the preferred way to get a venv https://bugs.python.org/issue25154 Of course if you try it, you may get: Error: Command '['<directory>/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1 which turns out to mean: Your Python isn't configured with ensure-pip! ..... Right now, I personally don't know why there is a venv at all. Despite the similarity of names, it doesn't seem to be about doing what virtualenv does. I think it is only meant to be used by people who want to install packages but not site-wide, but I am not sure about that. I don't think there are any plans to give venv the functionality of virtualenv, so presumably there are people who like it just fine the way it is now. They must have very different needs than I do. Laura From cescus92 at gmail.com Sun Nov 29 10:05:30 2015 From: cescus92 at gmail.com (cescus92 at gmail.com) Date: Sun, 29 Nov 2015 07:05:30 -0800 (PST) Subject: New JSON encoding method proposal for custom objects Message-ID: <aac1b6e8-e294-4916-9485-ffc031c3aeb3@googlegroups.com> Hello everyone! I'm writing here since I've read on the Pyhton's documentation that this is the most common path that a new proposal should follow. I'd be really glad if this proposal could become a PEP if I see a good response from the community or, in the worst case, understand why this proposal is not good enough. In this day I stumbled upon a very simple task: I had a list of instances of a custom class and I had to convert i into a JSON. Actually, from what I've discovered, there are 2 ways to get the JSON out of a custom non serializable instance: - defining a new method ( e.g. to_json() ) inside the class that converts the item manually (quicker) - a custom encoder/decoder that goes to extend the ones from the json lib (cleander, I think) Since I thought it was the most cost-effective and I was in hurry, I took the first way that drove me to a "problem": if I wanted to get the JSON out from my list, it obviously would have given me the "non serializable object" error since the json lib didn't know how to transform it into JSON! I was astonished that Python was requiring me such ugly ways to accomplish this simple task! JSON WebServices are becoming more and more popular and Python _must_ keep the pace of time! And here it is my proposal to make this task easier in the best Pythonic way :) I propose that every custom class that wants to allow its instances to have a JSON representation could implement a simple method, __json__(). The way how it works it very straightforward: every time json lib is required to convert an object that doesn't know, it looks for the __json__() method to learn how to treat the object. The duty of this method should be to reduce the complexity of an object instance into an elementary data type (int, str, list, dict, etc..). Often the process to get the JSON out of an object is a one-way need, in this way it would become even simpler to do it in the most flawless way so the programmer should no more care to implement some custom logic to handle quickly these situations. Let me give you a very small example of what a __json__ method could be like: class CustomObj(): def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 def __json__(self): return { 'p1': self.p1, 'p2': self.p2 } Once more, the job of __json__ should simply be the one of make our object json-readable :) What do you think of it? Do you think it's good? If not, why? Do you have any guidance to make this idea advance? Do you advice me to write down a preliminary PEP or to make directly a pull request to the Python's source code? Thank you for you're time! I'm waiting for your feedback :) Have a good Sunday! Francesco From __peter__ at web.de Sun Nov 29 10:46:13 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 29 Nov 2015 16:46:13 +0100 Subject: New JSON encoding method proposal for custom objects References: <aac1b6e8-e294-4916-9485-ffc031c3aeb3@googlegroups.com> Message-ID: <n3f6k4$h5o$1@ger.gmane.org> cescus92 at gmail.com wrote: > Hello everyone! > > I'm writing here since I've read on the Pyhton's documentation that this > is the most common path that a new proposal should follow. I'd be really > glad if this proposal could become a PEP if I see a good response from the > community or, in the worst case, understand why this proposal is not good > enough. > > In this day I stumbled upon a very simple task: I had a list of instances > of a custom class and I had to convert i into a JSON. > > Actually, from what I've discovered, there are 2 ways to get the JSON out > of a custom non serializable instance: - defining a new method ( e.g. > to_json() ) inside the class that converts the item manually (quicker) - a > custom encoder/decoder that goes to extend the ones from the json lib > (cleander, I think) > > Since I thought it was the most cost-effective and I was in hurry, I took > the first way that drove me to a "problem": if I wanted to get the JSON > out from my list, it obviously would have given me the "non serializable > object" error since the json lib didn't know how to transform it into > JSON! > > I was astonished that Python was requiring me such ugly ways to accomplish > this simple task! JSON WebServices are becoming more and more popular and > Python _must_ keep the pace of time! And here it is my proposal to make > this task easier in the best Pythonic way :) > > I propose that every custom class that wants to allow its instances to > have a JSON representation could implement a simple method, __json__(). > > The way how it works it very straightforward: every time json lib is > required to convert an object that doesn't know, it looks for the > __json__() method to learn how to treat the object. The duty of this > method should be to reduce the complexity of an object instance into an > elementary data type (int, str, list, dict, etc..). > > Often the process to get the JSON out of an object is a one-way need, in > this way it would become even simpler to do it in the most flawless way so > the programmer should no more care to implement some custom logic to > handle quickly these situations. > > Let me give you a very small example of what a __json__ method could be > like: > > class CustomObj(): > def __init__(self, p1, p2): > self.p1 = p1 > self.p2 = p2 > > def __json__(self): > return { > 'p1': self.p1, > 'p2': self.p2 > } > > Once more, the job of __json__ should simply be the one of make our object > json-readable :) > > What do you think of it? Do you think it's good? If not, why? I'm not sure if that is needed often enough so that adding yet another __dunder__ method is worthwhile, particularly as the current mechanism already makes an implementation of your idea a matter of a few lines: >>> import json >>> class Encoder(json.JSONEncoder): ... def default(self, obj): ... try: encode = obj.__json__ ... except AttributeError: return super().default(obj) ... return encode() ... >>> class Foo: ... def __json__(self): return dict(bar=1, baz=2) ... >>> json.dumps({1:2, 3:Foo()}, cls=Encoder) '{"1": 2, "3": {"baz": 2, "bar": 1}}' Personally I would find it more interesting if there were a unified mechanism for json and pickle. At the very least you should come up with a decoding mechanism. > Do you have any guidance to make this idea advance? Go to python-ideas for a lengthy discussion ;) > Do you advice me to write down a preliminary PEP or to make directly a > pull request to the Python's source code? > > Thank you for you're time! > I'm waiting for your feedback :) > Have a good Sunday! > > Francesco From rossmcm at gmail.com Sun Nov 29 15:08:26 2015 From: rossmcm at gmail.com (rossmcm at gmail.com) Date: Sun, 29 Nov 2015 12:08:26 -0800 (PST) Subject: Installing the gcalcli Python app under windows Message-ID: <0d7cc2ff-075a-48f9-86f8-943d171a3042@googlegroups.com> gcalcli (https://github.com/insanum/gcalcli) is a Python application that provides a command-line interface to Google calendar. All of the stuff I can find on installation seems to be written for *nix platforms and there is precious little for windows. I'm wondering if anyone can provide the steps involved in getting this thing going under Windows. My setup: - Windows 10 - Python 2.7 - PyDev Eclipse I don't want to clone the repository, I just want to get the source files I need and anything else I need to run this utility from a command prompt. I downloaded a zip file from the GitHuib site and then ran a command line "setup.py install" and this produced a whole lot of output: ---------------------------------------------------------------------------- C:\Users\Public\Documents\Downloads\Python\gcalcli\gcalcli-master>setup.py install running install running bdist_egg running egg_info creating gcalcli.egg-info writing requirements to gcalcli.egg-info\requires.txt writing gcalcli.egg-info\PKG-INFO writing top-level names to gcalcli.egg-info\top_level.txt writing dependency_links to gcalcli.egg-info\dependency_links.txt writing manifest file 'gcalcli.egg-info\SOURCES.txt' reading manifest file 'gcalcli.egg-info\SOURCES.txt' writing manifest file 'gcalcli.egg-info\SOURCES.txt' installing library code to build\bdist.win32\egg running install_lib warning: install_lib: 'build\lib' does not exist -- no Python modules to install creating build creating build\bdist.win32 creating build\bdist.win32\egg creating build\bdist.win32\egg\EGG-INFO installing scripts to build\bdist.win32\egg\EGG-INFO\scripts running install_scripts running build_scripts creating build\scripts-2.7 copying and adjusting gcalcli -> build\scripts-2.7 creating build\bdist.win32\egg\EGG-INFO\scripts copying build\scripts-2.7\gcalcli -> build\bdist.win32\egg\EGG-INFO\scripts copying gcalcli.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO copying gcalcli.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO copying gcalcli.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-INFO copying gcalcli.egg-info\requires.txt -> build\bdist.win32\egg\EGG-INFO copying gcalcli.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO zip_safe flag not set; analyzing archive contents... creating dist creating 'dist\gcalcli-3.3.2-py2.7.egg' and adding 'build\bdist.win32\egg' to it removing 'build\bdist.win32\egg' (and everything under it) Processing gcalcli-3.3.2-py2.7.egg Copying gcalcli-3.3.2-py2.7.egg to c:\python27\lib\site-packages Adding gcalcli 3.3.2 to easy-install.pth file Installing gcalcli script to C:\Python27\Scripts Installed c:\python27\lib\site-packages\gcalcli-3.3.2-py2.7.egg Processing dependencies for gcalcli==3.3.2 Searching for oauth2client<=1.4.12 Reading https://pypi.python.org/simple/oauth2client/ Reading http://code.google.com/p/google-api-python-client/ Reading http://github.com/google/oauth2client/ Best match: oauth2client 1.4.12 Downloading https://pypi.python.org/packages/2.7/o/oauth2client/oauth2client-1.4.12-py2.7.egg#md5=8265f6985905a5590c622741980a47e5 Processing oauth2client-1.4.12-py2.7.egg Moving oauth2client-1.4.12-py2.7.egg to c:\python27\lib\site-packages Adding oauth2client 1.4.12 to easy-install.pth file Installed c:\python27\lib\site-packages\oauth2client-1.4.12-py2.7.egg Searching for google-api-python-client Best match: google-api-python-client 1.2 Downloading http://google-api-python-client.googlecode.com/files/google-api-python-client-1.2.zip Processing google-api-python-client-1.2.zip Writing c:\users\ross\appdata\local\temp\easy_install-a2jaif\google-api-python-client-1.2\setup.cfg Running google-api-python-client-1.2\setup.py -q bdist_egg --dist-dir c:\users\ross\appdata\local\temp\easy_install-a2jaif\google-api-python-client-1.2\egg-dist-tmp-uumuki warning: no files found matching '*.json' under directory 'apiclient' zip_safe flag not set; analyzing archive contents... Moving google_api_python_client-1.2-py2.7.egg to c:\python27\lib\site-packages Adding google-api-python-client 1.2 to easy-install.pth file Installed c:\python27\lib\site-packages\google_api_python_client-1.2-py2.7.egg Searching for httplib2 Reading https://pypi.python.org/simple/httplib2/ Reading http://code.google.com/p/httplib2/ Reading https://github.com/jcgregorio/httplib2 Best match: httplib2 0.9.2 Downloading https://pypi.python.org/packages/source/h/httplib2/httplib2-0.9.2.zip#md5=404bac4a4e0d10b3ba498ce483c8c456 Processing httplib2-0.9.2.zip Writing c:\users\ross\appdata\local\temp\easy_install-jps_ft\httplib2-0.9.2\setup.cfg Running httplib2-0.9.2\setup.py -q bdist_egg --dist-dir c:\users\ross\appdata\local\temp\easy_install-jps_ft\httplib2-0.9.2\egg-dist-tmp-cpfwpj zip_safe flag not set; analyzing archive contents... httplib2.__init__: module references __file__ creating c:\python27\lib\site-packages\httplib2-0.9.2-py2.7.egg Extracting httplib2-0.9.2-py2.7.egg to c:\python27\lib\site-packages Adding httplib2 0.9.2 to easy-install.pth file Installed c:\python27\lib\site-packages\httplib2-0.9.2-py2.7.egg Searching for python-gflags Reading https://pypi.python.org/simple/python-gflags/ Reading http://code.google.com/p/python-gflags Best match: python-gflags 2.0 Downloading https://pypi.python.org/packages/source/p/python-gflags/python-gflags-2.0.tar.gz#md5=23c9a793959a54971b1f094b0c6d03b1 Processing python-gflags-2.0.tar.gz Writing c:\users\ross\appdata\local\temp\easy_install-n_jqlw\python-gflags-2.0\setup.cfg Running python-gflags-2.0\setup.py -q bdist_egg --dist-dir c:\users\ross\appdata\local\temp\easy_install-n_jqlw\python-gflags-2.0\egg-dist-tmp-0xznni zip_safe flag not set; analyzing archive contents... Moving python_gflags-2.0-py2.7.egg to c:\python27\lib\site-packages Adding python-gflags 2.0 to easy-install.pth file Installed c:\python27\lib\site-packages\python_gflags-2.0-py2.7.egg Searching for python-dateutil Reading https://pypi.python.org/simple/python-dateutil/ Reading http://labix.org/python-dateutil Reading https://dateutil.readthedocs.org Best match: python-dateutil 2.4.2 Downloading https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.4.2.tar.gz#md5=4ef68e1c485b09e9f034e10473e5add2 Processing python-dateutil-2.4.2.tar.gz Writing c:\users\ross\appdata\local\temp\easy_install-5nw3ie\python-dateutil-2.4.2\setup.cfg Running python-dateutil-2.4.2\setup.py -q bdist_egg --dist-dir c:\users\ross\appdata\local\temp\easy_install-5nw3ie\python-dateutil-2.4.2\egg-dist-tmp-80gzmb Moving python_dateutil-2.4.2-py2.7.egg to c:\python27\lib\site-packages Adding python-dateutil 2.4.2 to easy-install.pth file Installed c:\python27\lib\site-packages\python_dateutil-2.4.2-py2.7.egg Searching for six>=1.6.1 Reading https://pypi.python.org/simple/six/ Best match: six 1.10.0 Downloading https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55 Processing six-1.10.0.tar.gz Writing c:\users\ross\appdata\local\temp\easy_install-v1g4z3\six-1.10.0\setup.cfg Running six-1.10.0\setup.py -q bdist_egg --dist-dir c:\users\ross\appdata\local\temp\easy_install-v1g4z3\six-1.10.0\egg-dist-tmp-_zal4h no previously-included directories found matching 'documentation\_build' zip_safe flag not set; analyzing archive contents... six: module references __path__ creating c:\python27\lib\site-packages\six-1.10.0-py2.7.egg Extracting six-1.10.0-py2.7.egg to c:\python27\lib\site-packages Adding six 1.10.0 to easy-install.pth file Installed c:\python27\lib\site-packages\six-1.10.0-py2.7.egg Searching for rsa>=3.1.4 Reading https://pypi.python.org/simple/rsa/ Best match: rsa 3.2.3 Downloading https://pypi.python.org/packages/source/r/rsa/rsa-3.2.3.tar.gz#md5=0e93ca942184650116d84452d4b90253 Processing rsa-3.2.3.tar.gz Writing c:\users\ross\appdata\local\temp\easy_install-ewgfp0\rsa-3.2.3\setup.cfg Running rsa-3.2.3\setup.py -q bdist_egg --dist-dir c:\users\ross\appdata\local\temp\easy_install-ewgfp0\rsa-3.2.3\egg-dist-tmp-xaruhh warning: no files found matching 'README' zip_safe flag not set; analyzing archive contents... Moving rsa-3.2.3-py2.7.egg to c:\python27\lib\site-packages Adding rsa 3.2.3 to easy-install.pth file Installing pyrsa-encrypt-bigfile-script.py script to C:\Python27\Scripts Installing pyrsa-encrypt-bigfile.exe script to C:\Python27\Scripts Installing pyrsa-encrypt-bigfile.exe.manifest script to C:\Python27\Scripts Installing pyrsa-encrypt-script.py script to C:\Python27\Scripts Installing pyrsa-encrypt.exe script to C:\Python27\Scripts Installing pyrsa-encrypt.exe.manifest script to C:\Python27\Scripts Installing pyrsa-verify-script.py script to C:\Python27\Scripts Installing pyrsa-verify.exe script to C:\Python27\Scripts Installing pyrsa-verify.exe.manifest script to C:\Python27\Scripts Installing pyrsa-sign-script.py script to C:\Python27\Scripts Installing pyrsa-sign.exe script to C:\Python27\Scripts Installing pyrsa-sign.exe.manifest script to C:\Python27\Scripts Installing pyrsa-priv2pub-script.py script to C:\Python27\Scripts Installing pyrsa-priv2pub.exe script to C:\Python27\Scripts Installing pyrsa-priv2pub.exe.manifest script to C:\Python27\Scripts Installing pyrsa-decrypt-script.py script to C:\Python27\Scripts Installing pyrsa-decrypt.exe script to C:\Python27\Scripts Installing pyrsa-decrypt.exe.manifest script to C:\Python27\Scripts Installing pyrsa-decrypt-bigfile-script.py script to C:\Python27\Scripts Installing pyrsa-decrypt-bigfile.exe script to C:\Python27\Scripts Installing pyrsa-decrypt-bigfile.exe.manifest script to C:\Python27\Scripts Installing pyrsa-keygen-script.py script to C:\Python27\Scripts Installing pyrsa-keygen.exe script to C:\Python27\Scripts Installing pyrsa-keygen.exe.manifest script to C:\Python27\Scripts Installed c:\python27\lib\site-packages\rsa-3.2.3-py2.7.egg Searching for pyasn1-modules>=0.0.5 Reading https://pypi.python.org/simple/pyasn1_modules/ Best match: pyasn1-modules 0.0.8 Downloading https://pypi.python.org/packages/2.7/p/pyasn1-modules/pyasn1_modules-0.0.8-py2.7.egg#md5=f03fff5bc43106475a64a1c34d4052d7 Processing pyasn1_modules-0.0.8-py2.7.egg Moving pyasn1_modules-0.0.8-py2.7.egg to c:\python27\lib\site-packages Adding pyasn1-modules 0.0.8 to easy-install.pth file Installed c:\python27\lib\site-packages\pyasn1_modules-0.0.8-py2.7.egg Searching for pyasn1>=0.1.7 Reading https://pypi.python.org/simple/pyasn1/ Best match: pyasn1 0.1.9 Downloading https://pypi.python.org/packages/2.7/p/pyasn1/pyasn1-0.1.9-py2.7.egg#md5=08eef0e822233609f6cad55b419ae00c Processing pyasn1-0.1.9-py2.7.egg Moving pyasn1-0.1.9-py2.7.egg to c:\python27\lib\site-packages Adding pyasn1 0.1.9 to easy-install.pth file Installed c:\python27\lib\site-packages\pyasn1-0.1.9-py2.7.egg Finished processing dependencies for gcalcli==3.3.2 ---------------------------------------------------------------------------- but at the end of this I'm not sure what has happened - it has found my Python installation and copied a whole bunch of stuff there, but there seems to be no trace of a file gcalcli.py on my machine, which is what I was expecting to be created. Any comments appreciated! From matthew.herzog at gmail.com Sun Nov 29 15:23:12 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sun, 29 Nov 2015 12:23:12 -0800 (PST) Subject: Generate config file from template using Python search and replace. In-Reply-To: <mailman.3.1448752087.14615.python-list@python.org> References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> Message-ID: <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> When I run this script on OS X El Capitan, I see, # permission sensitive cache $include "_dispatcher_shared_auth-checker: Was I supposed to incorporate it into the script I posted? From denismfmcmahon at gmail.com Sun Nov 29 15:40:31 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 29 Nov 2015 20:40:31 -0000 (UTC) Subject: New JSON encoding method proposal for custom objects References: <aac1b6e8-e294-4916-9485-ffc031c3aeb3@googlegroups.com> Message-ID: <n3fnru$5sf$3@dont-email.me> On Sun, 29 Nov 2015 07:05:30 -0800, cescus92 wrote: > In this day I stumbled upon a very simple task: I had a list of > instances of a custom class and I had to convert i into a JSON. That's all well and good, but firstly you need to both dumps and loads to work properly with json, and secondly there's no mechanism in json that tells you what class of object you have. So you may have a __json_dumps__ that will dump your object out to a json string representation, but then how does json.loads recognise that it's loading your object to call your object's __json_loads__? -- Denis McMahon, denismfmcmahon at gmail.com From matthew.herzog at gmail.com Sun Nov 29 16:36:57 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sun, 29 Nov 2015 13:36:57 -0800 (PST) Subject: I can't understand re.sub Message-ID: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> I need to use re.sub to replace strings in a text file. I can't seem to understand how to use the re module to this end. result = re.sub(pattern, repl, string, count=0, flags=0); I think I understand that pattern is the regex I'm searching for and repl is the thing I want to substitute for whatever pattern finds but what is string? The items I'm searching for are few and they do not change. They are "CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template file. They do not appear together on any line and they only appear once on each line. This should be simple, right? From rxjwg98 at gmail.com Sun Nov 29 16:36:58 2015 From: rxjwg98 at gmail.com (fl) Date: Sun, 29 Nov 2015 13:36:58 -0800 (PST) Subject: What use is this class? Message-ID: <783981e2-a996-42f9-ad90-8e90a3bd6492@googlegroups.com> Hi, When I search around tutorial about None, I came across this link: http://jaredgrubb.blogspot.ca/2009/04/python-is-none-vs-none.html I don't understand what use of this class example: >>> class Zero(): # a class that is zero ... def __nonzero__(self): ... return False I can only get the following code running: cz1=Zero() cz1.__nonzero__() Out[119]: False Here are my questions: 1. Is there any other means to use class Zero? 2. What connection to None on the original author's intention? Thanks, From python at lucidity.plus.com Sun Nov 29 16:53:51 2015 From: python at lucidity.plus.com (Erik) Date: Sun, 29 Nov 2015 21:53:51 +0000 Subject: I can't understand re.sub In-Reply-To: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> References: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> Message-ID: <565B73EF.9080708@lucidity.plus.com> On 29/11/15 21:36, Mr Zaug wrote: > I need to use re.sub to replace strings in a text file. Do you? Is there any other way? > result = re.sub(pattern, repl, string, count=0, flags=0); > > I think I understand that pattern is the regex I'm searching for and > repl is the thing I want to substitute for whatever pattern finds but > what is string? Where do you think the function gets the string you want to transform from? > This should be simple, right? It is. And it could be even simpler if you don't bother with regexes at all (if your input is as fixed as you say it is): >>> foo = "foo bar baz spam CONTENT_PATH bar spam" >>> ' Substitute '.join(foo.split(' CONTENT_PATH ', 1)) 'foo bar baz spam Substitute bar spam' >>> E. From denismfmcmahon at gmail.com Sun Nov 29 17:01:34 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 29 Nov 2015 22:01:34 -0000 (UTC) Subject: I can't understand re.sub References: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> Message-ID: <n3fsju$348$2@dont-email.me> On Sun, 29 Nov 2015 13:36:57 -0800, Mr Zaug wrote: > result = re.sub(pattern, repl, string, count=0, flags=0); re.sub works on a string, not on a file. Read the file to a string, pass it in as the string. Or pre-compile the search pattern(s) and process the file line by line: import re patts = [ (re.compile("axe"), "hammer"), (re.compile("cat"), "dog"), (re.compile("tree"), "fence") ] with open("input.txt","r") as inf, open("output.txt","w") as ouf: line = inf.readline() for patt in patts: line = patt[0].sub(patt[1], line) ouf.write(line) Not tested, but I think it should do the trick. Or use a single patt and a replacement func: import re patt = re.compile("(axe)|(cat)|(tree)") def replfunc(match): if match == 'axe': return 'hammer' if match == 'cat': return 'dog' if match == 'tree': return 'fence' return match with open("input.txt","r") as inf, open("output.txt","w") as ouf: line = inf.readline() line = patt.sub(replfunc, line) ouf.write(line) (also not tested) -- Denis McMahon, denismfmcmahon at gmail.com From __peter__ at web.de Sun Nov 29 17:50:17 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 29 Nov 2015 23:50:17 +0100 Subject: Generate config file from template using Python search and replace. References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> Message-ID: <n3fvf8$pnn$1@ger.gmane.org> Mr Zaug wrote: > When I run this script on OS X El Capitan, I see, > > # permission sensitive cache > $include "_dispatcher_shared_auth-checker: > > Was I supposed to incorporate it into the script I posted? Are you referring to my post? I'm sorry, I can't make sense of your question. From lac at openend.se Sun Nov 29 19:00:08 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 30 Nov 2015 01:00:08 +0100 Subject: What use is this class? In-Reply-To: <783981e2-a996-42f9-ad90-8e90a3bd6492@googlegroups.com> References: <783981e2-a996-42f9-ad90-8e90a3bd6492@googlegroups.com> Message-ID: <201511300000.tAU008b9013896@fido.openend.se> In a message of Sun, 29 Nov 2015 13:36:58 -0800, fl writes: >Hi, > >When I search around tutorial about None, I came across this link: > >http://jaredgrubb.blogspot.ca/2009/04/python-is-none-vs-none.html > >I don't understand what use of this class example: > > > >>>> class Zero(): # a class that is zero >... def __nonzero__(self): >... return False > > >I can only get the following code running: > >cz1=Zero() >cz1.__nonzero__() >Out[119]: False > > >Here are my questions: >1. Is there any other means to use class Zero? >2. What connection to None on the original author's intention? The person who wrote this was curious as to why PEP 8 says: "Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators." He wrote this class to play around with, to see if it really made a difference whether you write: if x is None: vs if x == None: and it does. A class is free to implement its own version of '==' if if likes, and there, 'being equal to None' might means something complicated and crazy. People who are just testing against None will burn their fingers if they use '==' there. Also its a bad problem when porting code to Jython. A java null is supposed to be None. But using '==' will call the underlying .equals method. If you call that on a null, Java will spit out a Null Pointer Exception. Laura From ryanshuell at gmail.com Sun Nov 29 19:49:16 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Sun, 29 Nov 2015 16:49:16 -0800 (PST) Subject: How can I count word frequency in a web site? Message-ID: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> I'm trying to figure out how to count words in a web site. Here is a sample of the link I want to scrape data from and count specific words. http://finance.yahoo.com/q/h?s=STRP+Headlines I only want to count certain words, like 'fraud', 'lawsuit', etc. I want to have a way to control for specific words. I have a couple Python scripts that do this for a text file, but not for a web site. I can post that, if that's helpful. From rantingrickjohnson at gmail.com Sun Nov 29 20:12:04 2015 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 29 Nov 2015 17:12:04 -0800 (PST) Subject: I can't understand re.sub In-Reply-To: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> References: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> Message-ID: <feee81b6-2549-4bfa-b741-35da861a0317@googlegroups.com> On Sunday, November 29, 2015 at 3:37:34 PM UTC-6, Mr Zaug wrote: > The items I'm searching for are few and they do not change. They are "CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template file. They do not appear together on any line and they only appear once on each line. This should be simple, right? Yes. In fact so simple that string methods and a "for loop" will suffice. Using regexps for this tasks would be like using a dump truck to haul a teaspoon of salt. From matthew.herzog at gmail.com Sun Nov 29 20:20:31 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sun, 29 Nov 2015 17:20:31 -0800 (PST) Subject: I can't understand re.sub In-Reply-To: <n3fsju$348$2@dont-email.me> References: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> <n3fsju$348$2@dont-email.me> Message-ID: <58af2723-cd82-4ce5-a6fd-fbe31d4bf692@googlegroups.com> Thanks. That does help quite a lot. From matthew.herzog at gmail.com Sun Nov 29 20:24:34 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sun, 29 Nov 2015 17:24:34 -0800 (PST) Subject: I can't understand re.sub In-Reply-To: <feee81b6-2549-4bfa-b741-35da861a0317@googlegroups.com> References: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> <feee81b6-2549-4bfa-b741-35da861a0317@googlegroups.com> Message-ID: <967ecfa3-b240-44d6-9a75-bbd9f3865da4@googlegroups.com> On Sunday, November 29, 2015 at 8:12:25 PM UTC-5, Rick Johnson wrote: > On Sunday, November 29, 2015 at 3:37:34 PM UTC-6, Mr Zaug wrote: > > > The items I'm searching for are few and they do not change. They are "CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template file. They do not appear together on any line and they only appear once on each line. This should be simple, right? > > Yes. In fact so simple that string methods and a "for loop" will suffice. Using regexps for this tasks would be like using a dump truck to haul a teaspoon of salt. I rarely get a chance to do any scripting so yeah, I stink at it. Ideally I would have a script that will spit out a config file such as 087_pre-prod_snakeoil_farm.any and not need to manually rename said output file. From matthew.herzog at gmail.com Sun Nov 29 20:28:14 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sun, 29 Nov 2015 17:28:14 -0800 (PST) Subject: Generate config file from template using Python search and replace. In-Reply-To: <mailman.11.1448837430.14615.python-list@python.org> References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> <mailman.11.1448837430.14615.python-list@python.org> Message-ID: <0dd0db34-7f8f-4e8b-ad6a-c82ad19c2e5e@googlegroups.com> On Sunday, November 29, 2015 at 5:50:51 PM UTC-5, Peter Otten wrote: > Mr Zaug wrote: > > > When I run this script on OS X El Capitan, I see, > > > > # permission sensitive cache > > $include "_dispatcher_shared_auth-checker: > > > > Was I supposed to incorporate it into the script I posted? > > Are you referring to my post? I'm sorry, I can't make sense of your > question. Yes. The snippet you posted went way over my head. When I ran it, it printed # permission sensitive cache $include "_dispatcher_shared_auth-checker: From rxjwg98 at gmail.com Sun Nov 29 21:06:38 2015 From: rxjwg98 at gmail.com (fl) Date: Sun, 29 Nov 2015 18:06:38 -0800 (PST) Subject: variable vs. object Message-ID: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> Hi, I read several parts on line about Python that everything in Python is an object. Yes, it is a key difference with other languages. Then, I read a page it says variables: global and local variable at: http://www.tutorialspoint.com/python/python_functions.htm I have a question that whether variables are objects? For example, a=10 'a' is an integer. Is it an object too? Thanks, From joel.goldstick at gmail.com Sun Nov 29 21:16:04 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 29 Nov 2015 21:16:04 -0500 Subject: variable vs. object In-Reply-To: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> References: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> Message-ID: <CAPM-O+zb_c-7Fz9R8P3zYRgOthsWZQOLd675cTbORu_VRLCj+A@mail.gmail.com> On Sun, Nov 29, 2015 at 9:06 PM, fl <rxjwg98 at gmail.com> wrote: > Hi, > > I read several parts on line about Python that everything in Python is an > object. Yes, it is a key difference with other languages. Then, I read a > page > it says variables: global and local variable at: > > http://www.tutorialspoint.com/python/python_functions.htm > > > I have a question that whether variables are objects? > > For example, > > a=10 > > 'a' is an integer. Is it an object too? > yes > > Thanks, > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays From andre.roberge at gmail.com Sun Nov 29 21:24:21 2015 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Sun, 29 Nov 2015 18:24:21 -0800 (PST) Subject: variable vs. object In-Reply-To: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> References: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> Message-ID: <2c516888-de4f-4dd7-b1c0-fe56bb03f754@googlegroups.com> On Sunday, 29 November 2015 22:06:58 UTC-4, fl wrote: > Hi, > > I read several parts on line about Python that everything in Python is an > object. Yes, it is a key difference with other languages. Then, I read a page > it says variables: global and local variable at: > > http://www.tutorialspoint.com/python/python_functions.htm > > > I have a question that whether variables are objects? > > For example, > > a=10 > > 'a' is an integer. Is it an object too? > > Thanks, In Python, a "variable" is a name given to an object. In Python, the "=" sign is used to assign a name to an object: the name is on the left-hand side, and the object is on the right hand side. Multiple names can be assigned to the same object. In the example you gave, "a" is a name given to the object "10" which is an integer. If you do: a = 10 b = a a = "hello" b will be 10. b was just another name given to object 10 to which the name "a" was referring to at that point, even though we decided later that a should refer to the string "hello" (which is an object). Andr? From matthew.herzog at gmail.com Sun Nov 29 21:31:28 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Sun, 29 Nov 2015 18:31:28 -0800 (PST) Subject: Generate config file from template using Python search and replace. In-Reply-To: <mailman.11.1448837430.14615.python-list@python.org> References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> <mailman.11.1448837430.14615.python-list@python.org> Message-ID: <11d4423f-7912-426c-9d20-d2cb5efba18b@googlegroups.com> On Sunday, November 29, 2015 at 5:50:51 PM UTC-5, Peter Otten wrote: > Mr Zaug wrote: > > > When I run this script on OS X El Capitan, I see, > > > > # permission sensitive cache > > $include "_dispatcher_shared_auth-checker: > > > > Was I supposed to incorporate it into the script I posted? > > Are you referring to my post? I'm sorry, I can't make sense of your > question. I seem to be heading in this direction. #!/usr/bin/env python import re from os.path import exists script, template_file = argv print "Opening the template file..." with open (template_file, "r") as a_string: data=a_string.read().replace('BRAND', 'Fluxotine') print(data) So now the challenge is to use the read().replace magic for multiple values. From cfkaran2 at gmail.com Sun Nov 29 21:31:49 2015 From: cfkaran2 at gmail.com (Cem Karan) Date: Sun, 29 Nov 2015 21:31:49 -0500 Subject: How can I count word frequency in a web site? In-Reply-To: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> References: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> Message-ID: <AE33E0E3-35FA-4C1B-A708-BFD2F83A55D2@gmail.com> You might want to look into Beautiful Soup (https://pypi.python.org/pypi/beautifulsoup4), which is an HTML screen-scraping tool. I've never used it, but I've heard good things about it. Good luck, Cem Karan On Nov 29, 2015, at 7:49 PM, ryguy7272 <ryanshuell at gmail.com> wrote: > I'm trying to figure out how to count words in a web site. Here is a sample of the link I want to scrape data from and count specific words. > http://finance.yahoo.com/q/h?s=STRP+Headlines > > I only want to count certain words, like 'fraud', 'lawsuit', etc. I want to have a way to control for specific words. I have a couple Python scripts that do this for a text file, but not for a web site. I can post that, if that's helpful. > > -- > https://mail.python.org/mailman/listinfo/python-list From rhills at medimorphosis.com.au Sun Nov 29 21:40:29 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Mon, 30 Nov 2015 10:40:29 +0800 Subject: Generate config file from template using Python search and replace. In-Reply-To: <11d4423f-7912-426c-9d20-d2cb5efba18b@googlegroups.com> References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> <mailman.11.1448837430.14615.python-list@python.org> <11d4423f-7912-426c-9d20-d2cb5efba18b@googlegroups.com> Message-ID: <565BB71D.1010303@medimorphosis.com.au> A program I am writing at present does exactly this and I simply do multiple calls to string.replace (see below) On 30/11/15 10:31, Mr Zaug wrote: > I seem to be heading in this direction. > > #!/usr/bin/env python > import re > from os.path import exists > > script, template_file = argv > print "Opening the template file..." > > with open (template_file, "r") as a_string: > data=a_string.read().replace('BRAND', 'Fluxotine') data=data.replace('STRING_2', 'New String 2') data=data.replace('STRING_3', 'New String 3') > print(data) > > So now the challenge is to use the read().replace magic for multiple values. It's crude, but it works well for me! -- Rob Hills Waikiki, Western Australia From ben+python at benfinney.id.au Sun Nov 29 21:41:42 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2015 13:41:42 +1100 Subject: variable vs. object References: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> Message-ID: <85a8pw8azd.fsf@benfinney.id.au> fl <rxjwg98 at gmail.com> writes: > I read several parts on line about Python that everything in Python is an > object. Yes, every piece of information that you can get to with your program, is made available as an object. The phrase ?everything is an object? is significant when newcomers are surprised that, for example, every function is an object; every type is an object; every number is an object. > Then, I read a page it says variables [?] I have a question that > whether variables are objects? A ?variable?, as we use the term in Python, is a *way to access* a specific object. It is a binding between a name and an object. > For example, > > a=10 > > 'a' is an integer. Is it an object too? More specifically, ?a? is a name. That name is, at any point in time, bound to some object. The object to which that name is bound is, in your example, the integer ?10?. A variable is a specific kind of binding: a binding between one name and one object. An assignment statement (?a = 10? in your example) binds a reference to an object. If that reference is a name, then we call that a ?variable?. The object is not a variable; objects typically do not know whether any names are bound to them. The binding from a name to an object is often called a variable. Everyone serious about Python should watch Ned Batchelder's presentation on names and values <URL:http://nedbatchelder.com/text/names.html>, which covers this territory well. -- \ ?I went to a general store. They wouldn't let me buy anything | `\ specifically.? ?Steven Wright | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Nov 29 21:45:55 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2015 13:45:55 +1100 Subject: variable vs. object References: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> <2c516888-de4f-4dd7-b1c0-fe56bb03f754@googlegroups.com> Message-ID: <85610k8asc.fsf@benfinney.id.au> Andr? Roberge <andre.roberge at gmail.com> writes: > In Python, a "variable" is a name given to an object. In Python, the > "=" sign is used to assign a name to an object: the name is on the > left-hand side, and the object is on the right hand side. Multiple > names can be assigned to the same object. Take care with the directionality of those statements. In Python we don't give the name *to* the object, which would imply that the object ?has? that name in some sense. The object is totally unaffected, and assignment does not give the object any knowledge about that name. We also don't assign names *to* objects; if anything, we assign the object to the name. It is the name that ?has? the object. Or perhaps less confusingly, the name is *bound to* the object. It is frequently a point of confusion that assignment *never* affects the object, so it's best to avoid giving that false impression. > In the example you gave, "a" is a name given to the object "10" which > is an integer. Rather, I'd prefer to say that ?a? now refers to the object ?10?. The object ?10? was not ?given? anything. -- \ ?When I get new information, I change my position. What, sir, | `\ do you do with new information?? ?John Maynard Keynes | _o__) | Ben Finney From lac at openend.se Sun Nov 29 21:51:28 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 30 Nov 2015 03:51:28 +0100 Subject: How can I count word frequency in a web site? In-Reply-To: <AE33E0E3-35FA-4C1B-A708-BFD2F83A55D2@gmail.com> References: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> <AE33E0E3-35FA-4C1B-A708-BFD2F83A55D2@gmail.com> Message-ID: <201511300251.tAU2pSBS016224@fido.openend.se> In a message of Sun, 29 Nov 2015 21:31:49 -0500, Cem Karan writes: >You might want to look into Beautiful Soup (https://pypi.python.org/pypi/beautifulsoup4), which is an HTML screen-scraping tool. I've never used it, but I've heard good things about it. > >Good luck, >Cem Karan http://codereview.stackexchange.com/questions/73887/finding-the-occurrences-of-all-words-in-movie-scripts scrapes a site of movie scripts and then spits out the 10 most common words. I suspect the OP could modify this script to suit his or her needs. Laura From ryanshuell at gmail.com Sun Nov 29 21:54:11 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Sun, 29 Nov 2015 18:54:11 -0800 (PST) Subject: How can I count word frequency in a web site? In-Reply-To: <mailman.14.1448850720.14615.python-list@python.org> References: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> <mailman.14.1448850720.14615.python-list@python.org> Message-ID: <88ec2ba2-6b06-421b-89d5-ece408bb4c8e@googlegroups.com> On Sunday, November 29, 2015 at 9:32:22 PM UTC-5, Cem Karan wrote: > You might want to look into Beautiful Soup (https://pypi.python.org/pypi/beautifulsoup4), which is an HTML screen-scraping tool. I've never used it, but I've heard good things about it. > > Good luck, > Cem Karan > > On Nov 29, 2015, at 7:49 PM, ryguy7272 wrote: > > > I'm trying to figure out how to count words in a web site. Here is a sample of the link I want to scrape data from and count specific words. > > http://finance.yahoo.com/q/h?s=STRP+Headlines > > > > I only want to count certain words, like 'fraud', 'lawsuit', etc. I want to have a way to control for specific words. I have a couple Python scripts that do this for a text file, but not for a web site. I can post that, if that's helpful. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list Ok, this small script will grab everything from the link. import requests from bs4 import BeautifulSoup r = requests.get("http://finance.yahoo.com/q/h?s=STRP+Headlines") soup = BeautifulSoup(r.content) htmltext = soup.prettify() print htmltext Now, how can I count specific words like 'fraud' and 'lawsuit'? From python at mrabarnett.plus.com Sun Nov 29 22:23:34 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 30 Nov 2015 03:23:34 +0000 Subject: Generate config file from template using Python search and replace. In-Reply-To: <565BB71D.1010303@medimorphosis.com.au> References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> <mailman.11.1448837430.14615.python-list@python.org> <11d4423f-7912-426c-9d20-d2cb5efba18b@googlegroups.com> <565BB71D.1010303@medimorphosis.com.au> Message-ID: <565BC136.1050708@mrabarnett.plus.com> On 2015-11-30 02:40, Rob Hills wrote: > A program I am writing at present does exactly this and I simply do > multiple calls to string.replace (see below) > > On 30/11/15 10:31, Mr Zaug wrote: >> I seem to be heading in this direction. >> >> #!/usr/bin/env python >> import re >> from os.path import exists >> >> script, template_file = argv >> print "Opening the template file..." >> >> with open (template_file, "r") as a_string: >> data=a_string.read().replace('BRAND', 'Fluxotine') > > data=data.replace('STRING_2', 'New String 2') > data=data.replace('STRING_3', 'New String 3') > >> print(data) >> >> So now the challenge is to use the read().replace magic for multiple values. > > It's crude, but it works well for me! > You do need to watch out for matches that are part of something else. For example, if you had this: template = "REPLACE_THIS but DONT_REPLACE_THIS" and you did: result = template.replace("REPLACE_THIS", "Python") you would get: "Python but DONT_Python" From marko at pacujo.net Mon Nov 30 00:28:06 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 30 Nov 2015 07:28:06 +0200 Subject: variable vs. object References: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> Message-ID: <87y4dgys2h.fsf@elektro.pacujo.net> fl <rxjwg98 at gmail.com>: > I read several parts on line about Python that everything in Python is > an object. Python has two distinct entities: objects and references. All numbers, strings, classes, modules, class instances, files etc are objects. Variables, however, are not objects. They are references. Here are different references: a # variable a.x # attribute a[3] # subscription > Yes, it is a key difference with other languages. Python shares this feature with many higher-level languages. Marko From motoom at xs4all.nl Mon Nov 30 02:56:32 2015 From: motoom at xs4all.nl (Michiel Overtoom) Date: Mon, 30 Nov 2015 08:56:32 +0100 Subject: How can I count word frequency in a web site? In-Reply-To: <88ec2ba2-6b06-421b-89d5-ece408bb4c8e@googlegroups.com> References: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> <mailman.14.1448850720.14615.python-list@python.org> <88ec2ba2-6b06-421b-89d5-ece408bb4c8e@googlegroups.com> Message-ID: <3EE25A27-CCBF-4B3B-B6D2-F649086050F5@xs4all.nl> > On 30 Nov 2015, at 03:54, ryguy7272 <ryanshuell at gmail.com> wrote: > > Now, how can I count specific words like 'fraud' and 'lawsuit'? - convert the page to plain text - remove any interpunction - split into words - see what words occur - enumerate all the words and increase a counter for each word Something like this: s = """Today we're rounding out our planetary tour with ice giants Uranus and Neptune. Both have small rocky cores, thick mantles of ammonia, water, and methane, and atmospheres that make them look greenish and blue. Uranus has a truly weird rotation and relatively dull weather, while Neptune has clouds and storms whipped by tremendous winds. Both have rings and moons, with Neptune's Triton probably being a captured iceball that has active geology.""" import collections cleaned = s.lower().replace("\n", " ").replace(".", "").replace(",", "").replace("'", " ") count = collections.Counter(cleaned.split(" ")) for interesting in ("neptune", "and"): print "The word '%s' occurs %d times" % (interesting, count[interesting]) # Outputs: The word 'neptune' occurs 3 times The word 'and' occurs 7 times From gandalf at shopzeus.com Mon Nov 30 03:09:32 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Mon, 30 Nov 2015 09:09:32 +0100 Subject: variable vs. object In-Reply-To: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> References: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> Message-ID: <565C043C.1000003@shopzeus.com> > a=10 > > 'a' is an integer. Is it an object too? In Python, objects have an identity. When you do "a=10" then you *bind* the object to the name *a*. By "variable", the documentation refers to a name that was bound to an object. This is different from many other low level languages. For example: in C, you can do a=10; And it will "set the value of the variable 'a' to 10". In other words: "a" is not just a name, it refers to a certain location in memory where an integer value is stored. And in C, it is not an object but a value of a built-in type. In contrast, this is what happens in Python: * An "Integer" object is constructed with the value 10. * This object is then bound to the name "a". The key point is that "variables" are just names that may reference to objects. There is a distinction between names and objects. Strictly speaking, you cannot "set the value of a variable", because variables do not hold values. They just refer to objects. In Python, you can only "create an object", or "change the state of an object", and "bind a name to an object". From rosuav at gmail.com Mon Nov 30 03:19:18 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Nov 2015 19:19:18 +1100 Subject: variable vs. object In-Reply-To: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> References: <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com> Message-ID: <CAPTjJmq0PrfdVVdy1K2axBsoSiVmD_BXcegHdYAd3RG=96NXNQ@mail.gmail.com> On Mon, Nov 30, 2015 at 1:06 PM, fl <rxjwg98 at gmail.com> wrote: > For example, > > a=10 > > 'a' is an integer. Is it an object too? Other people have explained the difference between the name "a" and the object it's bound to... but to the extent that "a" is an integer, yes it most definitely is an object. To be specific, the integer 10 is an object, as you can see thus: >>> a = 10 >>> a.to_bytes(4, "big") b'\x00\x00\x00\n' >>> (a*12+8).to_bytes(4,"big") b'\x00\x00\x00\x80' Every expression [1] in Python has a value which is some sort of object, so you can do method calls on anything at all. Sometimes this looks a bit odd, but it does work: >>> 7.25.as_integer_ratio() (29, 4) The floating-point number 7.25 is represented in Python as a float object, and float objects have methods, same as all objects do. In this case, I've asked Python to tell me what this number would be as a fraction (ratio) of integers - 29/4 is equal to 7.25, so that's what it returns. So yes! It is an object. Everything is an object! ChrisA [1] To silence the nitpickers: An expression could raise an exception, or not terminate at all. As Grandpa said in The Princess Bride, you're very clever, now shut up. From marco.kaulea at gmail.com Mon Nov 30 03:42:01 2015 From: marco.kaulea at gmail.com (Marco Kaulea) Date: Mon, 30 Nov 2015 09:42:01 +0100 Subject: New JSON encoding method proposal for custom objects In-Reply-To: <n3fnru$5sf$3@dont-email.me> References: <aac1b6e8-e294-4916-9485-ffc031c3aeb3@googlegroups.com> <n3fnru$5sf$3@dont-email.me> Message-ID: <CAF0cjT_gP5SiZt2YepMo-Rh1+qz1Ny6kbYs5XTDuByPHuhNp7A@mail.gmail.com> Hi, I think his goal is not to load the data back into python, but to use it to provide some kind of REST-Style interface. An example would be, if you have a class instance of a record of a movie, that it could be simply encoded and send over the wire to display. Without necessarily recreating the class on the other end. This would prevent any security risks from the deserialization. On Sun, Nov 29, 2015 at 9:40 PM, Denis McMahon <denismfmcmahon at gmail.com> wrote: > That's all well and good, but firstly you need to both dumps and loads to > work properly with json, and secondly there's no mechanism in json that > tells you what class of object you have. But I am not sure how useful that PEP/Change would be, assuming the code in Peter's response works. - Marco Kaulea From rosuav at gmail.com Mon Nov 30 03:44:50 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Nov 2015 19:44:50 +1100 Subject: Caret key quits idle on pt keyboard In-Reply-To: <ADE3DE97-52FD-4A99-838D-4BEBCC5261D6@yahoo.com> References: <ADE3DE97-52FD-4A99-838D-4BEBCC5261D6@yahoo.com> Message-ID: <CAPTjJmoQZGaJyq9PqE9=kNcnGXCpy7e3ncuOYkByU6pCmwznMA@mail.gmail.com> On Mon, Nov 30, 2015 at 12:30 AM, Osvaldo Dias dos Santos via Python-list <python-list at python.org> wrote: > I can?t enter a caret in regex on a Portuguese keyboard because by pressing it, IDLE quits. > Any help ? Hmm. This could be part of the known issues with Tk (on which Idle depends) and non-BMP characters, but a caret should be safe. What OS and Python are you running? Can you pull up a terminal (aka command prompt or console) and run "python3 -m idlelib.idle"? (Or "python2 -m idlelib.idle" if you're using Python 2.7.) Then try it again, and see if there's an exception traceback shown in the terminal. If you can't get Idle to start from a terminal, try opening Python's interactive mode (if you have a standard Windows installation, you should have a Python command line in the Start menu). From there, type "import idlelib.idle" and it should fire up Idle. ChrisA From rosuav at gmail.com Mon Nov 30 03:48:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Nov 2015 19:48:38 +1100 Subject: convert php in to python In-Reply-To: <CAP9M=4BabE0gg5svMB5rQJacAK-vEGR7_4suaJQ45u9NqwHqaQ@mail.gmail.com> References: <CAP9M=4B6oBxOG1g8E2WJSKEtCNV=WcowvU_EO7sU=eA3jaMF1w@mail.gmail.com> <CAP9M=4BabE0gg5svMB5rQJacAK-vEGR7_4suaJQ45u9NqwHqaQ@mail.gmail.com> Message-ID: <CAPTjJmrXk5-iZXCRK7aejixmO0uyTPiCDfMKwNLNRh2_2AhnVQ@mail.gmail.com> On Fri, Nov 27, 2015 at 11:52 PM, RENISH RUDANI <delphicr at gmail.com> wrote: > Please help me to convert this code in python. > > > *Thanks & Regards,* > > *Renish Rudani* > > *Action Speaks Louder than Words* Sure. #!/usr/bin/python3 """Emit no output""" You didn't provide any PHP code, so the equivalent Python code is actually an empty file. I put in a docstring and a shebang so you'd be able to find what I wrote. It's possible you included an attachment, but attachments don't always survive as far as the newsgroup/mailing list. Translating code from one language to another usually requires comprehension of what the code's trying to accomplish. You might have to dig into the code a bit and get to know it, and then recreate it in Python. It's not a simple question, unless the code itself is trivially simple. Good luck! At least you're migrating to a better language. ChrisA From harvesting at is.invalid Mon Nov 30 03:51:13 2015 From: harvesting at is.invalid (Jussi Piitulainen) Date: Mon, 30 Nov 2015 10:51:13 +0200 Subject: I can't understand re.sub References: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> <mailman.26.1448872519.14615.python-list@python.org> Message-ID: <lf54mg3eupq.fsf@ling.helsinki.fi> Erik writes: > On 29/11/15 21:36, Mr Zaug wrote: >> This should be simple, right? > > It is. And it could be even simpler if you don't bother with regexes > at all (if your input is as fixed as you say it is): > > >>> foo = "foo bar baz spam CONTENT_PATH bar spam" > >>> ' Substitute '.join(foo.split(' CONTENT_PATH ', 1)) > 'foo bar baz spam Substitute bar spam' Surely the straight thing to say is: >>> foo.replace(' CONTENT_PATH ', ' Substitute ') 'foo bar baz spam Substitute bar spam' But there was no guarantee of spaces around the target. If you wish to, say, replace "spam" in your foo with "REDACTED" but leave it intact in "May the spammer be prosecuted", a regex might be attractive after all. From __peter__ at web.de Mon Nov 30 04:14:16 2015 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Nov 2015 10:14:16 +0100 Subject: Generate config file from template using Python search and replace. References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> <mailman.11.1448837430.14615.python-list@python.org> <0dd0db34-7f8f-4e8b-ad6a-c82ad19c2e5e@googlegroups.com> Message-ID: <n3h417$srs$1@ger.gmane.org> Mr Zaug wrote: > On Sunday, November 29, 2015 at 5:50:51 PM UTC-5, Peter Otten wrote: >> Mr Zaug wrote: >> >> > When I run this script on OS X El Capitan, I see, >> > >> > # permission sensitive cache >> > $include "_dispatcher_shared_auth-checker: >> > >> > Was I supposed to incorporate it into the script I posted? >> >> Are you referring to my post? I'm sorry, I can't make sense of your >> question. > > Yes. The snippet you posted went way over my head. When I ran it, it > printed > > # permission sensitive cache > $include "_dispatcher_shared_auth-checker: It's hard to tell from that problem description what might have gone wrong. However: In your template file you have to enclose all words you want to replace in braces ("you have foo options" becomes "you have {foo} options"), to replace all literal { with {{ and all literal } with }}. Did you do that? From cescus92 at gmail.com Mon Nov 30 07:35:13 2015 From: cescus92 at gmail.com (cescus92 at gmail.com) Date: Mon, 30 Nov 2015 04:35:13 -0800 (PST) Subject: New JSON encoding method proposal for custom objects In-Reply-To: <mailman.32.1448873773.14615.python-list@python.org> References: <aac1b6e8-e294-4916-9485-ffc031c3aeb3@googlegroups.com> <n3fnru$5sf$3@dont-email.me> <mailman.32.1448873773.14615.python-list@python.org> Message-ID: <6f5cd8a5-6e14-4069-8dfe-4a1a00c05827@googlegroups.com> Hello everyone and thank you for your interest! The Peter's code is very similar to what I think the default JSON encoder should be. The advantage of the method that I propose is that you should not care anymore about which encoder you're going to use even in case of different class instances. Imagine if you could just do json.dumps({[1,2,3], Obj(), [DifferentObj()] }) Probably it doesn't worth a PEP but it's a very small change that can be great for making painless REST interfaces as Marco underlined (it was exactly what I was meaning, thanks)! Denis, the way back is not considered in my proposal. But using the standard json.loads() could be nice enough! :) > Go to python-ideas for a lengthy discussion ;) Where can I find it? Thank you again, I hope now my idea is clearer! From ryanshuell at gmail.com Mon Nov 30 10:04:11 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Mon, 30 Nov 2015 07:04:11 -0800 (PST) Subject: How can I count word frequency in a web site? In-Reply-To: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> References: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> Message-ID: <a9dbdd7e-6c32-49aa-ae6c-9a4f42b8e497@googlegroups.com> On Sunday, November 29, 2015 at 7:49:40 PM UTC-5, ryguy7272 wrote: > I'm trying to figure out how to count words in a web site. Here is a sample of the link I want to scrape data from and count specific words. > http://finance.yahoo.com/q/h?s=STRP+Headlines > > I only want to count certain words, like 'fraud', 'lawsuit', etc. I want to have a way to control for specific words. I have a couple Python scripts that do this for a text file, but not for a web site. I can post that, if that's helpful. This works great! Thanks for sharing!! From ryanshuell at gmail.com Mon Nov 30 10:04:50 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Mon, 30 Nov 2015 07:04:50 -0800 (PST) Subject: How can I count word frequency in a web site? In-Reply-To: <mailman.18.1448851896.14615.python-list@python.org> References: <6851e3b8-0d46-4808-9f7f-372b71bf327c@googlegroups.com> <AE33E0E3-35FA-4C1B-A708-BFD2F83A55D2@gmail.com> <mailman.18.1448851896.14615.python-list@python.org> Message-ID: <b67bd51c-9f92-471c-b9ca-73292a8315d0@googlegroups.com> On Sunday, November 29, 2015 at 9:51:46 PM UTC-5, Laura Creighton wrote: > In a message of Sun, 29 Nov 2015 21:31:49 -0500, Cem Karan writes: > >You might want to look into Beautiful Soup (https://pypi.python.org/pypi/beautifulsoup4), which is an HTML screen-scraping tool. I've never used it, but I've heard good things about it. > > > >Good luck, > >Cem Karan > > http://codereview.stackexchange.com/questions/73887/finding-the-occurrences-of-all-words-in-movie-scripts > > scrapes a site of movie scripts and then spits out the 10 most common > words. I suspect the OP could modify this script to suit his or her needs. > > Laura Thanks Laura! From random832 at fastmail.com Mon Nov 30 10:10:26 2015 From: random832 at fastmail.com (Random832) Date: Mon, 30 Nov 2015 15:10:26 +0000 (UTC) Subject: Caret key quits idle on pt keyboard References: <ADE3DE97-52FD-4A99-838D-4BEBCC5261D6@yahoo.com> <CAPTjJmoQZGaJyq9PqE9=kNcnGXCpy7e3ncuOYkByU6pCmwznMA@mail.gmail.com> Message-ID: <n3hot2$fgb$1@ger.gmane.org> On 2015-11-30, Chris Angelico <rosuav at gmail.com> wrote: > Hmm. This could be part of the known issues with Tk (on which Idle > depends) and non-BMP characters, but a caret should be safe. Is there a known issue with dead keys? From what I can find the Portuguese keyboard doesn't have a "proper" caret, it has a circumflex dead key which you can press space or any non-vowel to get a caret. Seems to work fine for me though. From rosuav at gmail.com Mon Nov 30 10:57:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Dec 2015 02:57:15 +1100 Subject: Caret key quits idle on pt keyboard In-Reply-To: <n3hot2$fgb$1@ger.gmane.org> References: <ADE3DE97-52FD-4A99-838D-4BEBCC5261D6@yahoo.com> <CAPTjJmoQZGaJyq9PqE9=kNcnGXCpy7e3ncuOYkByU6pCmwznMA@mail.gmail.com> <n3hot2$fgb$1@ger.gmane.org> Message-ID: <CAPTjJmoRAZ5dR0wNgU2ZmyYLNJSW8_tN71bg_NHJw7O4HrYztw@mail.gmail.com> On Tue, Dec 1, 2015 at 2:10 AM, Random832 <random832 at fastmail.com> wrote: > On 2015-11-30, Chris Angelico <rosuav at gmail.com> wrote: >> Hmm. This could be part of the known issues with Tk (on which Idle >> depends) and non-BMP characters, but a caret should be safe. > > Is there a known issue with dead keys? From what I can find the > Portuguese keyboard doesn't have a "proper" caret, it has a > circumflex dead key which you can press space or any non-vowel to > get a caret. Seems to work fine for me though. Ah, that might explain it. I don't have a system to test it on, though. Definitely needs OS/Python version details. ChrisA From lac at openend.se Mon Nov 30 11:13:00 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 30 Nov 2015 17:13:00 +0100 Subject: Caret key quits idle on pt keyboard In-Reply-To: <CAPTjJmoRAZ5dR0wNgU2ZmyYLNJSW8_tN71bg_NHJw7O4HrYztw@mail.gmail.com> References: <ADE3DE97-52FD-4A99-838D-4BEBCC5261D6@yahoo.com> <CAPTjJmoQZGaJyq9PqE9=kNcnGXCpy7e3ncuOYkByU6pCmwznMA@mail.gmail.com> <n3hot2$fgb$1@ger.gmane.org> <CAPTjJmoRAZ5dR0wNgU2ZmyYLNJSW8_tN71bg_NHJw7O4HrYztw@mail.gmail.com> Message-ID: <201511301613.tAUGD09O014134@fido.openend.se> In a message of Tue, 01 Dec 2015 02:57:15 +1100, Chris Angelico writes: >On Tue, Dec 1, 2015 at 2:10 AM, Random832 <random832 at fastmail.com> wrote: >> On 2015-11-30, Chris Angelico <rosuav at gmail.com> wrote: >>> Hmm. This could be part of the known issues with Tk (on which Idle >>> depends) and non-BMP characters, but a caret should be safe. >> >> Is there a known issue with dead keys? From what I can find the >> Portuguese keyboard doesn't have a "proper" caret, it has a >> circumflex dead key which you can press space or any non-vowel to >> get a caret. Seems to work fine for me though. > >Ah, that might explain it. I don't have a system to test it on, >though. Definitely needs OS/Python version details. > >ChrisA I have a Swedish keyboard which has a caret dead-key that works as Random832 describes. Idle works perfectly well for me. There are a bunch of MacOS specific idle keyboard bugs. I wonder if this is (possibly another) one of them. Laura From carl at oddbird.net Mon Nov 30 11:32:27 2015 From: carl at oddbird.net (Carl Meyer) Date: Mon, 30 Nov 2015 09:32:27 -0700 Subject: Python 3 virtualenvs In-Reply-To: <201511291412.tATECKN8006265@fido.openend.se> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> <mailman.7.1448800035.14615.python-list@python.org> <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> <201511291412.tATECKN8006265@fido.openend.se> Message-ID: <565C7A1B.2070202@oddbird.net> Hi Laura, On 11/29/2015 07:12 AM, Laura Creighton wrote: > pyenv is going away. python -m venv is the preferred way to get a venv > > https://bugs.python.org/issue25154 > > Of course if you try it, you may get: > > Error: Command '['<directory>/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1 > > which turns out to mean: > > Your Python isn't configured with ensure-pip! AFAIK "isn't configured with ensurepip" is a thing which is only done to Python by some downstream distributors (e.g. Linux packagers). If they remove ensurepip, it should be their responsibility to also fix the venv module accordingly (at least enough to provide a useful error message). So I believe that's a bug that should be filed against whoever is distributing the Python you're using. > Right now, I personally don't know why there is a venv at all. Because virtualenv is an ugly hack which is difficult to maintain (I should know, I used to maintain it). In order to work at all, virtualenv maintains its own patched copy of several stdlib modules (based originally on Python 2.4(?) and modified since then) and uses them instead of the version distributed with whatever version of Python you are using. Some other stdlib modules it monkeypatches. As you might expect, this regularly causes problems when new Python versions are released, requiring even more hacks piled atop the previous ones. It's a real testament to the dedication of the current virtualenv maintainers (thank you, PyPA!) that it even works at all. The built-in venv module in Python 3.3+ fixes that by building a minimal level of support for virtual environments directly into the Python interpreter and stdlib, removing the need for (monkey)patching. Of course that interpreter support isn't available in Pythons prior to 3.3, which is why virtualenv remains much more popular today. (Also, the first version of venv in Python 3.3 didn't automatically install pip into the envs, which made them less useful, because at that point pip was a purely third-party project. That's been fixed with ensurepip in Python 3.4+). I very much hope that some day in the future, when all new Python projects are in Python 3, almost everyone will use venv, and virtualenv will be relevant only to those maintaining legacy Python 2 projects. There has been some work towards writing a transitional version of virtualenv that looks the same to users, but (under the hood) uses the old code only for 2.x and uses venv for Python 3. > Despite > the similarity of names, it doesn't seem to be about doing what virtualenv > does. I don't know what you mean by this. Venv is intended to do _exactly_ what virtualenv does, only better. Unless by "what virtualenv does" you mean "also support Python 2." > I think it is only meant to be used by people who want to install > packages but not site-wide, but I am not sure about that. I don't know what you mean by this either. Isn't the ability to "install packages but not site-wide" precisely what virtualenv (and venv) give you? > I don't think > there are any plans to give venv the functionality of virtualenv, What functionality do you mean? > so > presumably there are people who like it just fine the way it is now. > They must have very different needs than I do. I don't know, since you never said what it is about venv that doesn't meet your needs :-) Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: <http://mail.python.org/pipermail/python-list/attachments/20151130/06c17253/attachment.sig> From rxjwg98 at gmail.com Mon Nov 30 11:44:05 2015 From: rxjwg98 at gmail.com (fl) Date: Mon, 30 Nov 2015 08:44:05 -0800 (PST) Subject: Question about code writing '% i, callback' Message-ID: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> Hi, I come across the following code snippet. for i in range(10): def callback(): print "clicked button", i UI.Button("button %s" % i, callback) The content inside parenthesis in last line is strange to me. "button %s" % i, callback That is, the writing looks like recognized as three items when I try with a class definition (it can run with this): class buibutton(): print 'sd' def __nonzero__(self): return False def Button(str, ii, callbackk): return Could you explain it to me? The link is here: http://effbot.org/zone/default-values.htm Thanks, From zachary.ware+pylist at gmail.com Mon Nov 30 11:53:08 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 30 Nov 2015 10:53:08 -0600 Subject: Question about code writing '% i, callback' In-Reply-To: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> Message-ID: <CAKJDb-Pd-fU+aj3nzgjm_D5UBow6X5BN=idotu5T8=0mj_7JcA@mail.gmail.com> On Mon, Nov 30, 2015 at 10:44 AM, fl <rxjwg98 at gmail.com> wrote: > The content inside parenthesis in last line is strange to me. > > "button %s" % i, callback https://docs.python.org/library/stdtypes.html#printf-style-string-formatting -- Zach From zachary.ware+pylist at gmail.com Mon Nov 30 11:54:53 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 30 Nov 2015 10:54:53 -0600 Subject: Question about code writing '% i, callback' In-Reply-To: <CAKJDb-Pd-fU+aj3nzgjm_D5UBow6X5BN=idotu5T8=0mj_7JcA@mail.gmail.com> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> <CAKJDb-Pd-fU+aj3nzgjm_D5UBow6X5BN=idotu5T8=0mj_7JcA@mail.gmail.com> Message-ID: <CAKJDb-N1HvFcKEQW8oCxa68b31FCwq4rb_dTwRwrz0bX__BHRw@mail.gmail.com> On Mon, Nov 30, 2015 at 10:53 AM, Zachary Ware <zachary.ware+pylist at gmail.com> wrote: > On Mon, Nov 30, 2015 at 10:44 AM, fl <rxjwg98 at gmail.com> wrote: >> The content inside parenthesis in last line is strange to me. >> >> "button %s" % i, callback > > https://docs.python.org/library/stdtypes.html#printf-style-string-formatting Sorry, should have tested that link before sending. That should be either https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting or https://docs.python.org/2/library/stdtypes.html#string-formatting-operations -- Zach From ian.g.kelly at gmail.com Mon Nov 30 12:01:55 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 Nov 2015 11:01:55 -0600 Subject: Question about code writing '% i, callback' In-Reply-To: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> Message-ID: <CALwzidn0wCAUd9zQRYHp3Lgg3hYBY769aJF-OkZxgWxdNXi4Nw@mail.gmail.com> On Mon, Nov 30, 2015 at 10:44 AM, fl <rxjwg98 at gmail.com> wrote: > I come across the following code snippet. > > for i in range(10): > def callback(): > print "clicked button", i > UI.Button("button %s" % i, callback) > > The content inside parenthesis in last line is strange to me. > > "button %s" % i, callback These are the arguments being passed to UI.Button. The first argument is: "button %s" % i This is an example of printf-style string formatting. See the link that Zachary posted. The second argument is the function named callback. > That is, the writing looks like recognized as three items when I try with a > class definition (it can run with this): > > class buibutton(): > print 'sd' > def __nonzero__(self): > return False > > def Button(str, ii, callbackk): > > return > > > Could you explain it to me? How is this related to the example above? Here, Button is defined as a method of a class. Since it's a method, the first parameter is the "self" parameter, which will implicitly take the value of the class instance that you're calling the Button method on. If you're trying to call this like above, then the second parameter "ii" will take the value of the string from the example above, and callbackk will take the value of the callback argument from above. Thus, the method that you've defined has three parameters but only takes two explicit arguments. From framstag at rus.uni-stuttgart.de Mon Nov 30 12:15:04 2015 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Mon, 30 Nov 2015 17:15:04 +0000 (UTC) Subject: static variables Message-ID: <n3i06o$9ot$1@news2.informatik.uni-stuttgart.de> I try to to implement a "static variable" inside a function: def main(): a(1) a(2) a() print(a.x) if 'a.x' in globals(): print('global variable') if 'a.x' in locals(): print('local variable') def a(x=None): if not x is None: a.x = x print(':',a.x) main() When I run this code, I get: : 1 : 2 : 2 2 This is exactly what I expect. But what is a.x? It is neither a variable in globals() nor in locals() -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From lac at openend.se Mon Nov 30 12:20:47 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 30 Nov 2015 18:20:47 +0100 Subject: Python 3 virtualenvs In-Reply-To: <565C7A1B.2070202@oddbird.net> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> <mailman.7.1448800035.14615.python-list@python.org> <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> <201511291412.tATECKN8006265@fido.openend.se> <565C7A1B.2070202@oddbird.net> Message-ID: <201511301720.tAUHKlAe017071@fido.openend.se> In a message of Mon, 30 Nov 2015 09:32:27 -0700, Carl Meyer writes: >Hi Laura, >I don't know what you mean by this. Venv is intended to do _exactly_ >what virtualenv does, only better. Unless by "what virtualenv does" you >mean "also support Python 2." That is exactly what I mean. >> I think it is only meant to be used by people who want to install >> packages but not site-wide, but I am not sure about that. > >I don't know what you mean by this either. Isn't the ability to "install >packages but not site-wide" precisely what virtualenv (and venv) give you? I rarely use it for that. What I nearly always want is different python interpreters. CPython, PyPy, Jython for anything from 2.6 to 3.6. Laura From carl at oddbird.net Mon Nov 30 12:28:46 2015 From: carl at oddbird.net (Carl Meyer) Date: Mon, 30 Nov 2015 10:28:46 -0700 Subject: Python 3 virtualenvs In-Reply-To: <201511301720.tAUHKlAe017071@fido.openend.se> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> <mailman.7.1448800035.14615.python-list@python.org> <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> <201511291412.tATECKN8006265@fido.openend.se> <565C7A1B.2070202@oddbird.net> <201511301720.tAUHKlAe017071@fido.openend.se> Message-ID: <565C874E.7060008@oddbird.net> On 11/30/2015 10:20 AM, Laura Creighton wrote: > In a message of Mon, 30 Nov 2015 09:32:27 -0700, Carl Meyer writes: >>> I think it is only meant to be used by people who want to install >>> packages but not site-wide, but I am not sure about that. >> >> I don't know what you mean by this either. Isn't the ability to "install >> packages but not site-wide" precisely what virtualenv (and venv) give you? > > I rarely use it for that. What I nearly always want is different > python interpreters. CPython, PyPy, Jython for anything from 2.6 to > 3.6. If you just want the variety of interpreters, virtualenv doesn't give you that -- you have to already have a given interpreter installed system-wide for virtualenv to be able to use it. What virtualenv gives you is isolated environments for package installations (which can use any interpreter you have installed). Venv does the same (and won't have any trouble with PyPy or Jython either, once they reach Python 3.3 compatibility). So I agree that for now you should be sticking with virtualenv (I use it too), but I hope you'll take another look at venv a few years down the road, if you find yourself in a situation where all the interpreters you need are 3.3+. (Or maybe virtualenv will make the transition sooner, and you'll start using venv under the hood for 3.3+ without even realizing it.) Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: <http://mail.python.org/pipermail/python-list/attachments/20151130/37c86c30/attachment.sig> From tjreedy at udel.edu Mon Nov 30 12:30:03 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2015 12:30:03 -0500 Subject: Caret key quits idle on pt keyboard In-Reply-To: <201511301613.tAUGD09O014134@fido.openend.se> References: <ADE3DE97-52FD-4A99-838D-4BEBCC5261D6@yahoo.com> <CAPTjJmoQZGaJyq9PqE9=kNcnGXCpy7e3ncuOYkByU6pCmwznMA@mail.gmail.com> <n3hot2$fgb$1@ger.gmane.org> <CAPTjJmoRAZ5dR0wNgU2ZmyYLNJSW8_tN71bg_NHJw7O4HrYztw@mail.gmail.com> <201511301613.tAUGD09O014134@fido.openend.se> Message-ID: <n3i13n$810$1@ger.gmane.org> On 11/30/2015 11:13 AM, Laura Creighton wrote: > In a message of Tue, 01 Dec 2015 02:57:15 +1100, Chris Angelico writes: >> On Tue, Dec 1, 2015 at 2:10 AM, Random832 <random832 at fastmail.com> wrote: >>> On 2015-11-30, Chris Angelico <rosuav at gmail.com> wrote: >>>> Hmm. This could be part of the known issues with Tk (on which Idle >>>> depends) and non-BMP characters, but a caret should be safe. >>> >>> Is there a known issue with dead keys? From what I can find the >>> Portuguese keyboard doesn't have a "proper" caret, it has a >>> circumflex dead key which you can press space or any non-vowel to >>> get a caret. Seems to work fine for me though. Older versions of tcl/tk had problems with some non-ascii keyboards. The fix was around 8.5.12. The 8.5.9 that come with Mac does not have it. Help | About Idle shows the tk version. >> Ah, that might explain it. I don't have a system to test it on, >> though. Definitely needs OS/Python version details. >> >> ChrisA > > I have a Swedish keyboard which has a caret dead-key that works > as Random832 describes. Idle works perfectly well for me. > > There are a bunch of MacOS specific idle keyboard bugs. I wonder > if this is (possibly another) one of them. Some are fixed in the upcoming releases because Mark Roseman is a Mac user, tk expert, and now an IDLE contributor who submitted patches for the Mac bugs that bugged him. Mac bugs not on the tracker are unlikely to be fixed, though. -- Terry Jan Reedy From jon+usenet at unequivocal.co.uk Mon Nov 30 12:30:41 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 30 Nov 2015 17:30:41 -0000 (UTC) Subject: Python 3 virtualenvs References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> <mailman.7.1448800035.14615.python-list@python.org> <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> <201511291412.tATECKN8006265@fido.openend.se> <565C7A1B.2070202@oddbird.net> <201511301720.tAUHKlAe017071@fido.openend.se> <mailman.43.1448904539.14615.python-list@python.org> Message-ID: <slrnn5p22i.1t1.jon+usenet@frosty.unequivocal.co.uk> On 2015-11-30, Carl Meyer <carl at oddbird.net> wrote: > (Or maybe virtualenv will make the transition sooner, and you'll start > using venv under the hood for 3.3+ without even realizing it.) It does sound like that would be the ideal solution, and presumably can't be very hard if venv is supposed to do exactly what virtualenv does anyway - virtualenv just needs to say "if python >= 3.4 then call venv". From rxjwg98 at gmail.com Mon Nov 30 12:36:09 2015 From: rxjwg98 at gmail.com (fl) Date: Mon, 30 Nov 2015 09:36:09 -0800 (PST) Subject: Question about code writing '% i, callback' In-Reply-To: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> Message-ID: <f18de0eb-07f1-424a-90c3-62fbc9be128a@googlegroups.com> On Monday, November 30, 2015 at 11:44:44 AM UTC-5, fl wrote: > Hi, > > I come across the following code snippet. > > > > > > for i in range(10): > def callback(): > print "clicked button", i > UI.Button("button %s" % i, callback) > > > > > The content inside parenthesis in last line is strange to me. > > "button %s" % i, callback > > > That is, the writing looks like recognized as three items when I try with a > class definition (it can run with this): > > class buibutton(): > print 'sd' > def __nonzero__(self): > return False > > def Button(str, ii, callbackk): > > return > > > Could you explain it to me? > > The link is here: > > http://effbot.org/zone/default-values.htm > > Thanks, Thanks for the replies. Now, I have the following code: class buibutton(): print 'sd' def __nonzero__(self): return False def Button(self, ii, callbackk): callbackk() return UI=buibutton() for i in range(10): def callback(): print "clicked button", i UI.Button("button %s" % i, callback) To my surprise, the output is not the original link expected. i.e. it is the same with binding to the current values: for i in range(10): def callback(i=i): I have the output for both: %run "C:/Users/CCS6_1_Tiva_C/Python_prj0/uibutton1.py" sd clicked button 0 clicked button 1 clicked button 2 clicked button 3 clicked button 4 clicked button 5 clicked button 6 clicked button 7 clicked button 8 clicked button 9 %run "C:\Users\CCS6_1_Tiva_C\Python_prj0\uibutton0.py" sd clicked button 0 clicked button 1 clicked button 2 clicked button 3 clicked button 4 clicked button 5 clicked button 6 clicked button 7 clicked button 8 clicked button 9 I don't know why it does not have the not expected format output: sd clicked button 9 clicked button 9 clicked button 9 clicked button 9 clicked button 9 clicked button 9 clicked button 9 clicked button 9 clicked button 9 clicked button 9 Thanks, From tjreedy at udel.edu Mon Nov 30 12:36:56 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2015 12:36:56 -0500 Subject: Question about code writing '% i, callback' In-Reply-To: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> Message-ID: <n3i1gk$fk8$1@ger.gmane.org> On 11/30/2015 11:44 AM, fl wrote: > I come across the following code snippet. > for i in range(10): > def callback(): > print "clicked button", i > UI.Button("button %s" % i, callback) > http://effbot.org/zone/default-values.htm Note that the above is an intentional example of common buggy code. It is followed by a version that works, with 'i=i' added to the callback header. -- Terry Jan Reedy From tjreedy at udel.edu Mon Nov 30 12:38:40 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2015 12:38:40 -0500 Subject: static variables In-Reply-To: <n3i06o$9ot$1@news2.informatik.uni-stuttgart.de> References: <n3i06o$9ot$1@news2.informatik.uni-stuttgart.de> Message-ID: <n3i1jr$fk8$2@ger.gmane.org> On 11/30/2015 12:15 PM, Ulli Horlacher wrote: > > I try to to implement a "static variable" inside a function: > > def main(): > a(1) > a(2) > a() > print(a.x) > if 'a.x' in globals(): print('global variable') > if 'a.x' in locals(): print('local variable') > > def a(x=None): > if not x is None: a.x = x > print(':',a.x) > > main() > > When I run this code, I get: > > : 1 > : 2 > : 2 > 2 > > This is exactly what I expect. > But what is a.x? > It is neither a variable in globals() nor in locals() a.x is an attribute of the object a. -- Terry Jan Reedy From lac at openend.se Mon Nov 30 12:46:21 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 30 Nov 2015 18:46:21 +0100 Subject: Python 3 virtualenvs In-Reply-To: <565C874E.7060008@oddbird.net> References: <1mekmrs.1xn5n6010b7a1xN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5jb72.1t1.jon+usenet@frosty.unequivocal.co.uk> <1mem3lu.1327fd91org8tkN%real-not-anti-spam-address@apple-juice.co.uk> <slrnn5k8e4.1t1.jon+usenet@frosty.unequivocal.co.uk> <8737vp0zh9.fsf@metapensiero.it> <mailman.7.1448800035.14615.python-list@python.org> <slrnn5lv6n.1t1.jon+usenet@frosty.unequivocal.co.uk> <201511291412.tATECKN8006265@fido.openend.se> <565C7A1B.2070202@oddbird.net> <201511301720.tAUHKlAe017071@fido.openend.se> <565C874E.7060008@oddbird.net> Message-ID: <201511301746.tAUHkLRI017661@fido.openend.se> In a message of Mon, 30 Nov 2015 10:28:46 -0700, Carl Meyer writes: >So I agree that for now you should be sticking with virtualenv (I use it >too), but I hope you'll take another look at venv a few years down the >road, if you find yourself in a situation where all the interpreters you >need are 3.3+. I will, but these days I am playing with fades, which I only discovered a week ago, when Facundo made an announcment. https://pypi.python.org/pypi/fades/3 And it looks like this will make my life a whole lot easier. Laura From rxjwg98 at gmail.com Mon Nov 30 12:50:42 2015 From: rxjwg98 at gmail.com (fl) Date: Mon, 30 Nov 2015 09:50:42 -0800 (PST) Subject: Question about code writing '% i, callback' In-Reply-To: <mailman.45.1448905059.14615.python-list@python.org> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> <mailman.45.1448905059.14615.python-list@python.org> Message-ID: <06c312b2-a137-46e1-b31c-c9c2224224ad@googlegroups.com> On Monday, November 30, 2015 at 12:37:52 PM UTC-5, Terry Reedy wrote: > On 11/30/2015 11:44 AM, fl wrote: > > > I come across the following code snippet. > > > for i in range(10): > > def callback(): > > print "clicked button", i > > UI.Button("button %s" % i, callback) > > > http://effbot.org/zone/default-values.htm > > Note that the above is an intentional example of common buggy code. It > is followed by a version that works, with 'i=i' added to the callback > header. > > -- > Terry Jan Reedy With the following code, there is no bug as the original author said. class buibutton(): print 'sd' def __nonzero__(self): return False def Button(self, ii, callbackk): callbackk() return for i in range(10): def callback(): print "clicked button", i UI.Button("button %s" % i, callback) only to find that all callbacks print the same value (most likely 9, in this case). Why does it have no bug? From ian.g.kelly at gmail.com Mon Nov 30 13:24:23 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 30 Nov 2015 11:24:23 -0700 Subject: Question about code writing '% i, callback' In-Reply-To: <f18de0eb-07f1-424a-90c3-62fbc9be128a@googlegroups.com> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> <f18de0eb-07f1-424a-90c3-62fbc9be128a@googlegroups.com> Message-ID: <CALwzidkw9kgW2PQ=jgX_=go2KjZn0eM0sroo50+V4LuORcjSxw@mail.gmail.com> On Mon, Nov 30, 2015 at 10:36 AM, fl <rxjwg98 at gmail.com> wrote: > Thanks for the replies. Now, I have the following code: > > > > class buibutton(): > print 'sd' > def __nonzero__(self): > return False > > def Button(self, ii, callbackk): > callbackk() > return > UI=buibutton() > > > for i in range(10): > def callback(): > print "clicked button", i > UI.Button("button %s" % i, callback) > > > To my surprise, the output is not the original link expected. i.e. it is > the same with binding to the current values: The callback function is being called immediately, in the body of the loop, not stored and called later. The value of i in the closure has not actually changed yet at the point you're calling it. If you instead store the callback and call it later, you'll find that each message says "button 9". From rxjwg98 at gmail.com Mon Nov 30 13:55:23 2015 From: rxjwg98 at gmail.com (fl) Date: Mon, 30 Nov 2015 10:55:23 -0800 (PST) Subject: Question about code writing '% i, callback' In-Reply-To: <mailman.41.1448902962.14615.python-list@python.org> References: <25af8ac3-5fc7-44bd-a73f-7a870b69515a@googlegroups.com> <mailman.41.1448902962.14615.python-list@python.org> Message-ID: <53ef7ef4-cfec-4c91-a45c-5b847dde8fad@googlegroups.com> On Monday, November 30, 2015 at 12:02:57 PM UTC-5, Ian wrote: > On Mon, Nov 30, 2015 at 10:44 AM, fl <ail.com> wrote: > > I come across the following code snippet. > > > > for i in range(10): > > def callback(): > > print "clicked button", i > > UI.Button("button %s" % i, callback) > > > > The content inside parenthesis in last line is strange to me. > > > > "button %s" % i, callback > > These are the arguments being passed to UI.Button. The first argument is: > > "button %s" % i > > This is an example of printf-style string formatting. See the link > that Zachary posted. > > The second argument is the function named callback. > > > That is, the writing looks like recognized as three items when I try with a > > class definition (it can run with this): > > > > class buibutton(): > > print 'sd' > > def __nonzero__(self): > > return False > > > > def Button(str, ii, callbackk): > > > > return > > > > > > Could you explain it to me? > > How is this related to the example above? > > Here, Button is defined as a method of a class. Since it's a method, > the first parameter is the "self" parameter, which will implicitly > take the value of the class instance that you're calling the Button > method on. If you're trying to call this like above, then the second > parameter "ii" will take the value of the string from the example > above, and callbackk will take the value of the callback argument from > above. > > Thus, the method that you've defined has three parameters but only > takes two explicit arguments. "How is this related to the example above? Here, Button is defined as a method of a class. Since it's a method, the first parameter is the "self" parameter, which will implicitly take the value of the class instance that you're calling the Button method on." Thanks Ian. I created the class because I want to use the original example line UI.Button("button %s" % i, callback) Is there another way to use the above line without my class definition? I do feel that my created class does not match well with the above line because the first item "button %s" does not fit __self__ in the class. My understanding about the above line code may not correct. This may further result in not the original bug pops up. Thanks, From bc at freeuk.com Mon Nov 30 15:32:26 2015 From: bc at freeuk.com (BartC) Date: Mon, 30 Nov 2015 20:32:26 +0000 Subject: static variables In-Reply-To: <n3i06o$9ot$1@news2.informatik.uni-stuttgart.de> References: <n3i06o$9ot$1@news2.informatik.uni-stuttgart.de> Message-ID: <n3ibkd$nl0$1@dont-email.me> On 30/11/2015 17:15, Ulli Horlacher wrote: > def main(): > a(1) > a(2) > a() > print(a.x) > if 'a.x' in globals(): print('global variable') > if 'a.x' in locals(): print('local variable') Try this: if 'x' in a.__dict__: print('attribute of a') -- Bartc From pcmanticore at gmail.com Mon Nov 30 18:42:46 2015 From: pcmanticore at gmail.com (Claudiu Popa) Date: Tue, 1 Dec 2015 01:42:46 +0200 Subject: Pylint 1.5.0 / Astroid 1.4.1 released Message-ID: <CAMy=CLpp1SfTpkpktFyFVg0NwUZrq3LgXd75ZNqCyp7kDgjFAg@mail.gmail.com> Hello, I'm happy to announce you the release of Pylint 1.5.0, respectively Astroid 1.4.1. It's been over a year since the last major release and the amount of changes that were brought into pylint in this time is humongous, with over 30 new checks and tons of bug fixes. I would like to use this occasion for thanking for their contributions the new committers who joined pylint's team in the past months, ceridwen and Dmitry, as well as thanking the contributors that made this release possible. Here are some of the major changes of this release: - We finally support Python 3.5 in both projects. - We stopped depending on logilab-common, which means that users of the popular testing framework pytest will finally stop being confused by having two executables with the same name doing different things. - Almost 30 new checks you might enjoy not having in your project. These checks fall into multiple categories, regarding maintainability, readability, recommendations for improving the code, as well as new type-checking capabilities. They are: 'wrong-import-order', 'ungrouped-imports', 'wrong-import-position', 'unneeded-not', 'simplifiable-if-condition', 'too-many-boolean-expressions' 'too-many-nested-blocks', 'multiple-imports', 'duplicate-except', 'using-constant-test', 'confusing-with-statement', 'singleton-comparison', 'misplaced-comparison-constant', 'consider-using-enumerate', 'nonlocal-and-global', 'continue-in-finally', 'misplaced-bare-raise', 'nonlocal-without-binding', 'yield-inside-async-function', 'too-many-star-expressions', 'invalid-star-assignment-target', 'import-star-module-level, 'star-needs-assignment', 'unexpected-special-method-signature', 'repeated-keyword'. Some new type checks for finding violations of the type system are 'unsubscriptable-object', 'unsupported-membership-test', 'not-an-iterable', 'not-context-manager', 'not-async-context-manager', 'duplicate-bases' and 'inconsistent-mro'. - We also added a new 'extensions' component, which contains optional checkers that needs to be activated explicitly. These includes 'extensions.check_docs', which verifies a bunch of properties of the docstrings, such as checking that all function, method and constructor parameters are mentioned in the params and types part of the docstring. Also, it checks that there are no naming inconsistencies between the signature and the documentation, i.e. also report documented parameters that are missing in the signature. This is important to find cases where parameters are renamed only in the code, not in the documentation. Activate this checker with: --load-plugins=pylint.extensions.check_docs Most of the work was put into astroid though, which got more capable in this period of time. Unfortunately, more than half of the work that went into it was postponed for astroid 1.6 and astroid 2.0, since it wasn't deemed stable enough for this release. New features worth mentioning are: - Python 3.5 support - some of the nodes were renamed in order to be more similar to builtin's ast module, such as Class to ClassDef, Function to FunctionDef Getattr to Attribute etc, the old names being slated for removal in astroid 2.0. This affects the plugins as well, since it means that the visit methods should use the new names instead (so visit_classdef for class). Old names are still supported in visit methods for a while, until pylint 2.0. Activating the warnings when running should result in spurious PendingDeprecationWarnings when using the old node names. - add proper grammatical names for `infered` and `ass_type` methods, namely `inferred` and `assign_type`. The old methods will raise PendingDeprecationWarning, being slated for removal in astroid 2.0. - we added a new convenience API, `astroid.parse`, which can be used to retrieve an astroid AST from a source code string, similar to how ast.parse can be used to obtain a Python AST from a source string. - There's a new separate step for transforms. Until now, the transforms were applied at the same time the tree was being built. This was problematic if the transform functions were using inference, since the inference was executed on a partially constructed tree, which led to failures when post-building information was needed. - Better support for understanding builtins. We're understanding a bunch of new builtins, but unfortunately most of them weren't released, since they weren't stable enough for now, due to some inherent problems that astroid has. The most important that's released though is the understanding of super, which means that we can now detect problems of sort: class A(B, C, D): def __init__(self): super(A, self).call_missing_method() You can read the complete changelog here https://bitbucket.org/logilab/astroid/raw/4f45b6fc4c23b80b4f7154add1b9d9cee3a54297/ChangeLog and https://bitbucket.org/logilab/pylint/raw/2871c4d7084478b5db02f384e4e5167641c698f2/ChangeLog Now with every release there's going to be new false positives or regressions or things that could be improved. Don't hesitate to open an issue or to send a PR if you notice something's amiss and we'll try to have new bug fix releases as soon as possible (you might have noticed that's astroid 1.4.1..) As a final note, we're planning to switch to GitHub soon, which will mean an improved CI for us, resulting in less maintenance pain. Thank you for reading all this and enjoy pylinting! Claudiu From steve at pearwood.info Mon Nov 30 20:00:46 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 01 Dec 2015 12:00:46 +1100 Subject: Is vars() the most useless Python built-in ever? Message-ID: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> I'm trying to understand why vars() exists. Does anyone use it? Every time I try to use it, I find it doesn't quite do what I want. And even if it did, there are more obvious and/or correct alternatives. For instance, I want to check whether a particular name is an instance attribute. So first I write: "name" in obj.__dict__ but when I see the dunder name I think that's an implementation detail. And sure enough, not all instances have a __dict__ (e.g. if it uses __slots__ instead) and so I re-write it as: "name" in vars(obj) but that also fails if obj has no instance __dict__. But why am I looking just in the instance __dict__? Chances are I should be looking for the attribute *anywhere* in the instance/class/superclass hierarchy: hasattr(obj, "name") Or, if you are worried about triggering dynamic attributes using __getattr__, you can do this: sentinel = object() inspect.getattr_static(obj, "name", sentinel) is not sentinel which only checks for pre-existing attributes without triggering __getattr__, __getattribute__, or the descriptor protocol. Either way, vars() doesn't solve the problem. What problem does it solve? -- Steven From steve at pearwood.info Mon Nov 30 20:01:21 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 01 Dec 2015 12:01:21 +1100 Subject: static variables References: <n3i06o$9ot$1@news2.informatik.uni-stuttgart.de> <n3ibkd$nl0$1@dont-email.me> Message-ID: <565cf163$0$1612$c3e8da3$5496439d@news.astraweb.com> On Tue, 1 Dec 2015 07:32 am, BartC wrote: > On 30/11/2015 17:15, Ulli Horlacher wrote: >> def main(): >> a(1) >> a(2) >> a() >> print(a.x) >> if 'a.x' in globals(): print('global variable') >> if 'a.x' in locals(): print('local variable') > > Try this: > > if 'x' in a.__dict__: print('attribute of a') That will work in this specific case, but it isn't guaranteed to always work. Not all objects have a __dict__, even if they can hold attributes, and not all attributes are stored in a __dict__. A better and more general test is: if hasattr(a, 'x'): print('attribute of a') -- Steven From jfong at ms4.hinet.net Mon Nov 30 20:03:28 2015 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 30 Nov 2015 17:03:28 -0800 (PST) Subject: python response slow when running external DLL In-Reply-To: <3ec6a016-dae5-4986-b035-c1a8cd4dc3e7@googlegroups.com> References: <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <mailman.173.1448626828.20593.python-list@python.org> <d6c59a36-38ba-4f26-b949-18f2b226e7e3@googlegroups.com> <mailman.184.1448705627.20593.python-list@python.org> <3ec6a016-dae5-4986-b035-c1a8cd4dc3e7@googlegroups.com> Message-ID: <1450e163-23f7-47b7-8e8d-40d304ea003f@googlegroups.com> jf... at ms4.hinet.net at 2015/11/29 UTC+8 10:55:28AM wrote? > > > ..... > > > ..... > > > #do the rest > > > var_status.set('Download...') > > > _thread.start_new_thread(td_download, ()) #must use threading > > > > > > def td_download(): > > > result = mydll.SayHello() > > > if result: > > > var_status.set("Download Fail at %s" % hex(result)) > > > showerror('Romter', 'Download Fail') > > > else: > > > var_status.set('Download OK') > > > showinfo('Romter', 'Download OK') > > > > As td_download() runs in the other thread the var_status.set() methods are > > problematic. > > No idea what kind of problem it will encounter. Can you explain? It might be not a good idea to update GUI in a spawned thread, according to Mark Lutz's book "Programming Python", section "Using Threads with tkinter GUIs" "If you do use threads in tkinter programs, however, you need to remember that only the main thread (the one that built the GUI and started the mainloop) should generally make GUI calls. At the least, multiple threads should not attempt to update the GUI at the same time..." > > Another complication that inevitably comes with concurrency: what if the > > user triggers another download while one download is already running? If you > > don't keep track of all downloads the message will already switch to > > "Download OK" while one download is still running. > > Hummm...this thought never comes to my mind. After take a quick test I found, you are right, a second "download" was triggered immediately. That's a shock to me. I suppose the same event shouldn't be triggered again, or at least not triggered immediately, before its previous handler was completed. ...I will take a check later on Borland C++ builder to see how it reacts! > > Anyway to prevent this happens? if Python didn't take care it for us. then don't use thread if you prefer the GUI freeze. From python at lucidity.plus.com Mon Nov 30 20:26:11 2015 From: python at lucidity.plus.com (Erik) Date: Tue, 1 Dec 2015 01:26:11 +0000 Subject: I can't understand re.sub In-Reply-To: <lf54mg3eupq.fsf@ling.helsinki.fi> References: <af27abe4-f81e-4d44-a504-c58d9e71986a@googlegroups.com> <mailman.26.1448872519.14615.python-list@python.org> <lf54mg3eupq.fsf@ling.helsinki.fi> Message-ID: <565CF733.7040004@lucidity.plus.com> On 30/11/15 08:51, Jussi Piitulainen wrote: > Surely the straight thing to say is: > > >>> foo.replace(' CONTENT_PATH ', ' Substitute ') > 'foo bar baz spam Substitute bar spam' Not quite the same thing (but yes, with a third argument of 1, it would be). > But there was no guarantee of spaces around the target. I know. It was just an example to show that there might be an option that's not a regex for the specific use indicated. It's up to the OP to decide whether they think the spaces (or any other, or no, delimiter) would actually be required or useful. Or whether they really prefer a regex after all. > If you wish to, > say, replace "spam" in your foo with "REDACTED" but leave it intact in > "May the spammer be prosecuted", a regex might be attractive after all. But that's not what the OP said they wanted to do. They said everything was very fixed - they did not want a general purpose human language text processing solution ... ;) E. From rxjwg98 at gmail.com Mon Nov 30 21:14:22 2015 From: rxjwg98 at gmail.com (fl) Date: Mon, 30 Nov 2015 18:14:22 -0800 (PST) Subject: Could you explain this rebinding (or some other action) on "nums = nums"? In-Reply-To: <mailman.37.1435191416.3674.python-list@python.org> References: <94c2e42e-1e5f-40cf-9259-26035e277bf3@googlegroups.com> <mailman.37.1435191416.3674.python-list@python.org> Message-ID: <b48d4b38-a28a-4408-8271-f79e850f453f@googlegroups.com> On Wednesday, June 24, 2015 at 8:17:08 PM UTC-4, Chris Angelico wrote: > On Thu, Jun 25, 2015 at 9:52 AM, fl <rxjgmail.com> wrote: > > The reason is that list implements __iadd__ like this (except in C, not Python): > > > > class List: > > def __iadd__(self, other): > > self.extend(other) > > return self > > When you execute "nums += more", you're getting the same effect as: > > > > nums = nums.__iadd__(more) > > which, because of the implementation of __iadd__, acts like this: > > > > nums.extend(more) > > nums = nums > > So there is a rebinding operation here, but first, there's a mutating operation, and the rebinding operation is a no-op. > > It's not a complete no-op, as can be demonstrated if you use something > other than a simple name: > > >>> tup = ("spam", [1, 2, 3], "ham") > >>> tup[1] > [1, 2, 3] > >>> tup[1].extend([4,5]) > >>> tup[1] = tup[1] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'tuple' object does not support item assignment > >>> tup > ('spam', [1, 2, 3, 4, 5], 'ham') > >>> tup[1] += [6,7] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'tuple' object does not support item assignment > >>> tup > ('spam', [1, 2, 3, 4, 5, 6, 7], 'ham') > > The reason for the rebinding is that += can do two completely > different things: with mutable objects, like lists, it changes them in > place, but with immutables, it returns a new one: > > >>> msg = "Hello" > >>> msg += ", world!" > >>> msg > 'Hello, world!' > > This didn't change the string "Hello", because you can't do that. > Instead, it rebound msg to "Hello, world!". For consistency, the += > operator will *always* rebind, but in situations where that's not > necessary, it rebinds to the exact same object. > > Does that answer the question? > > ChrisA I have revisit the past post. In the example code snippet: type(tup[1]) Out[162]: list 'list' is mutable. Why does the following line have errors? In practical Python code, error is not acceptable. Then, what purpose is for the following code here to show? Thanks, >>> tup[1] += [6,7] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' object does not support item assignment From python at mrabarnett.plus.com Mon Nov 30 22:32:31 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 1 Dec 2015 03:32:31 +0000 Subject: Could you explain this rebinding (or some other action) on "nums = nums"? In-Reply-To: <b48d4b38-a28a-4408-8271-f79e850f453f@googlegroups.com> References: <94c2e42e-1e5f-40cf-9259-26035e277bf3@googlegroups.com> <mailman.37.1435191416.3674.python-list@python.org> <b48d4b38-a28a-4408-8271-f79e850f453f@googlegroups.com> Message-ID: <565D14CE.30708@mrabarnett.plus.com> On 2015-12-01 02:14, fl wrote: > On Wednesday, June 24, 2015 at 8:17:08 PM UTC-4, Chris Angelico wrote: >> On Thu, Jun 25, 2015 at 9:52 AM, fl <rxjgmail.com> wrote: >> > The reason is that list implements __iadd__ like this (except in C, not Python): >> > >> > class List: >> > def __iadd__(self, other): >> > self.extend(other) >> > return self >> > When you execute "nums += more", you're getting the same effect as: >> > >> > nums = nums.__iadd__(more) >> > which, because of the implementation of __iadd__, acts like this: >> > >> > nums.extend(more) >> > nums = nums >> > So there is a rebinding operation here, but first, there's a mutating operation, and the rebinding operation is a no-op. >> >> It's not a complete no-op, as can be demonstrated if you use something >> other than a simple name: >> >> >>> tup = ("spam", [1, 2, 3], "ham") >> >>> tup[1] >> [1, 2, 3] >> >>> tup[1].extend([4,5]) >> >>> tup[1] = tup[1] >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> TypeError: 'tuple' object does not support item assignment >> >>> tup >> ('spam', [1, 2, 3, 4, 5], 'ham') >> >>> tup[1] += [6,7] >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> TypeError: 'tuple' object does not support item assignment >> >>> tup >> ('spam', [1, 2, 3, 4, 5, 6, 7], 'ham') >> >> The reason for the rebinding is that += can do two completely >> different things: with mutable objects, like lists, it changes them in >> place, but with immutables, it returns a new one: >> >> >>> msg = "Hello" >> >>> msg += ", world!" >> >>> msg >> 'Hello, world!' >> >> This didn't change the string "Hello", because you can't do that. >> Instead, it rebound msg to "Hello, world!". For consistency, the += >> operator will *always* rebind, but in situations where that's not >> necessary, it rebinds to the exact same object. >> >> Does that answer the question? >> >> ChrisA > > I have revisit the past post. In the example code snippet: > > type(tup[1]) > Out[162]: list > > 'list' is mutable. Why does the following line have errors? > In practical Python code, error is not acceptable. Then, what purpose is > for the following code here to show? > > Thanks, > > >>>> tup[1] += [6,7] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'tuple' object does not support item assignment > When you write: x += y Python tries to do: x = x.__iadd__(y) If x doesn't have the "__iadd__" method, Python then tries to do: x = x.__add__(y) The "__iadd__" method should mutate the object in-place and then return itself. Here's an example where it returns something else instead: # Example class Test: def __init__(self): self.string = '' def __iadd__(self, other): self.string += other return "Surprise!" t = Test() t += 'foo' print(t) # End of example In the case of: tup[1] += [6, 7] what it's trying to do is: tup[1] = tup[1].__iadd__([6, 7]) tup[1] refers to a list, and the __iadd__ method _does_ mutate it, but then Python tries to put the result that the method returns into tup[1]. That fails because tup itself is a tuple, which is immutable. From josef.pktd at gmail.com Mon Nov 30 22:45:42 2015 From: josef.pktd at gmail.com (Josef Pktd) Date: Mon, 30 Nov 2015 19:45:42 -0800 (PST) Subject: Is vars() the most useless Python built-in ever? In-Reply-To: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <98d1c37d-0c25-45fd-a06f-244eca5e3f6a@googlegroups.com> On Monday, November 30, 2015 at 8:01:14 PM UTC-5, Steven D'Aprano wrote: > I'm trying to understand why vars() exists. Does anyone use it? > > Every time I try to use it, I find it doesn't quite do what I want. And even > if it did, there are more obvious and/or correct alternatives. > > For instance, I want to check whether a particular name is an instance > attribute. So first I write: > > "name" in obj.__dict__ > > but when I see the dunder name I think that's an implementation detail. And > sure enough, not all instances have a __dict__ (e.g. if it uses __slots__ > instead) and so I re-write it as: > > "name" in vars(obj) > > but that also fails if obj has no instance __dict__. > > But why am I looking just in the instance __dict__? Chances are I should be > looking for the attribute *anywhere* in the instance/class/superclass > hierarchy: > > hasattr(obj, "name") > > Or, if you are worried about triggering dynamic attributes using > __getattr__, you can do this: > > sentinel = object() > inspect.getattr_static(obj, "name", sentinel) is not sentinel > > which only checks for pre-existing attributes without triggering > __getattr__, __getattribute__, or the descriptor protocol. > > > Either way, vars() doesn't solve the problem. What problem does it solve? I'm using dir and vars pretty often when I'm trying to figure out new code or review a pull request, or when I'm reviewing code that I don't remember. Both are convenient for quickly checking which attributes are available at the moment. I never realized that there might be issues with "fancy" problems. `vars` is convenient, for example, to check which attributes have been initialized to None, and which already have assigned values. And checking again after some calculations, I roughly see which attributes have been added or changed in the mean time. aside: I'm boring and like code that has no magic, especially if I have to maintain it. Josef > > > > -- > Steven From matthew.herzog at gmail.com Mon Nov 30 23:54:24 2015 From: matthew.herzog at gmail.com (Mr Zaug) Date: Mon, 30 Nov 2015 20:54:24 -0800 (PST) Subject: Generate config file from template using Python search and replace. In-Reply-To: <mailman.33.1448874871.14615.python-list@python.org> References: <73046000-f634-40f2-9c83-f03a5db134e6@googlegroups.com> <mailman.3.1448752087.14615.python-list@python.org> <4f923003-4f85-4a69-bfda-165194211bb4@googlegroups.com> <mailman.11.1448837430.14615.python-list@python.org> <0dd0db34-7f8f-4e8b-ad6a-c82ad19c2e5e@googlegroups.com> <mailman.33.1448874871.14615.python-list@python.org> Message-ID: <8c787187-910c-40df-9235-9e4c2dafb19c@googlegroups.com> On Monday, November 30, 2015 at 4:14:48 AM UTC-5, Peter Otten wrote: > Mr Zaug wrote: > > > On Sunday, November 29, 2015 at 5:50:51 PM UTC-5, Peter Otten wrote: > >> Mr Zaug wrote: > >> > >> > When I run this script on OS X El Capitan, I see, > >> > > >> > # permission sensitive cache > >> > $include "_dispatcher_shared_auth-checker: > >> > > >> > Was I supposed to incorporate it into the script I posted? > >> > >> Are you referring to my post? I'm sorry, I can't make sense of your > >> question. > > > > Yes. The snippet you posted went way over my head. When I ran it, it > > printed > > > > # permission sensitive cache > > $include "_dispatcher_shared_auth-checker: > > It's hard to tell from that problem description what might have gone wrong. > However: > > In your template file you have to enclose all words you want to replace in > braces ("you have foo options" becomes "you have {foo} options"), to replace > all literal { with {{ and all literal } with }}. > > Did you do that? Yup, I sure did. So here is my current script. The only remaining task now is figuring out how to write the contents to a new file. #!/usr/bin/env python import os import sys script, template_file = sys.argv print "Opening the template file..." print "What is the serial number of the site?", nnn = raw_input() print "What is the brand, or product name?", brand = raw_input() print "What is the (fqdn) ServerName?", server_name = raw_input() print "What is the content path?", content_path = raw_input() print "What is the DAM path?", dampath = raw_input() print "Which environment is this for?", env = raw_input() print "What is the cache document root?", cache_docroot = raw_input() with open (template_file, "r") as a_string: data=a_string.read().replace('{SERVER_NAME}', server_name).replace('{BRAND}', brand).replace('{CONTENT_PATH}', content_path).replace('{DAMPATH}', dampath).replace('{ENV}', env).replace('{CACHE_DOCROOT}', cache_docroot)