From muhamadwahidi at gmail.com Sun Dec 15 12:39:31 2013 From: muhamadwahidi at gmail.com (muhamadwahidi at gmail.com) Date: Sun, 15 Dec 2013 09:39:31 -0800 (PST) Subject: Python for IPSA (Power flow analysis) In-Reply-To: <6288a409-db46-4987-91a7-2f3dd65b42dc@googlegroups.com> References: <6288a409-db46-4987-91a7-2f3dd65b42dc@googlegroups.com> Message-ID: Pada Selasa, 28 Mei 2013 17:00:42 UTC+7, Debbie menulis: > Hi there, > > I am new to Python, and wondering if you could help me with python based coding for the IPSA (Power system analysis software). I have a electrical distribution network with generators, buses and loads, on which I am performing the load flow analysis every 1 hour for a period of 1 year. > > > > The code to perform instantaneous load/power flow analysis is given below. I need to modify it such that I can perform this load flow analysis every 1 hour for a period of 1 year. Please help. > > > > from ipsa import * > > > > ipsasys = IscInterface() > > net = ipsasys.ReadFile("refinery.iif") > > bok = net.DoLoadFlow(); > > if bok: > > busbars = net.GetBusbars() > > print "Load Flow results:" > > print "" > > print "BusName Vmag(kV)" > > print "====================" > > for bus in busbars.itervalues(): > > name = bus.GetName() > > vm = bus.GetVoltageMagnitudekV() > > res = "%-8s %10.5f" % (name, vm) > > print res > > else: > > print "Load Flow failed!" > > > > Regards, > > Debbie From awilliam at whitemice.org Thu Dec 5 07:42:12 2013 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 05 Dec 2013 07:42:12 -0500 Subject: Share Code: Laptop Lid State In-Reply-To: References: <51F7C861.3060208@Gmail.com> Message-ID: <1386247332.3603.8.camel@workstation.wmmi.net> On Tue, 2013-07-30 at 17:00 +0100, Chris Angelico wrote: > On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson > wrote: > > Aloha everyone! > > I attached a script that I thought I could share with everyone for your > > help. This Python3 script only works on Unix systems. It prints the current > > state of the lid. This can be used to make a script that performs some > > action when the lid is closed or open. The script is licensed under LGPLv3 > > and I will soon upload it to my Launchpad account. Enjoy! > There's... no Python code in that. Why not simply > open("/proc/acpi/button/lid/LID/state") and read from it, instead of > using cat and awk? The correct way to implement this is to use the power management services available on the System D-Bus. Integrating with D-Bus from Python is easy! From cmpython at gmail.com Tue Dec 10 18:55:34 2013 From: cmpython at gmail.com (CM) Date: Tue, 10 Dec 2013 15:55:34 -0800 (PST) Subject: PEP 450 Adding a statistics module to Python In-Reply-To: <520592f9$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <520592f9$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, August 9, 2013 9:10:18 PM UTC-4, Steven D'Aprano wrote: > I am seeking comments on PEP 450, Adding a statistics module to Python's > standard library: I just saw today that this will be included in Python 3.4. Congratulations, Steven, this is a nice addition. From breamoreboy at yahoo.co.uk Wed Dec 4 11:21:16 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 16:21:16 +0000 Subject: status of regex modules In-Reply-To: References: Message-ID: On 24/10/2013 22:47, Mark Lawrence wrote: > The new module is now five years old. PEP 429 Python 3.4 release > schedule has it listed under "Other proposed large-scale changes" but I > don't believe this is actually happening. Lots of issues on the bug > tracker have been closed as fixed in the new module, see issue 2636 for > more data. Some work is still being carried out on the old re module. > > So where do we stand? Is the new module getting into Python 3.x, Python > 4.y or what? If no do all the old issues have to be reopened and > applied to the re module? Who has to make the final decision on all of > this? > > Note that I've no direct interest as I rarely if ever use the little > perishers, I just find this situation bizarre. > Anybody? And FTR I'll break Armed Forces Rule No. 1 and volunteer my own pitifully poor servies if I can help take this forward, as I think it's daft having issues marked as fixed on the bug tracker but the fix not being available in the standard library, only on pypi. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Wed Dec 4 23:37:57 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Dec 2013 23:37:57 -0500 Subject: status of regex modules In-Reply-To: References: Message-ID: On 12/4/2013 11:21 AM, Mark Lawrence wrote: > On 24/10/2013 22:47, Mark Lawrence wrote: >> The new module is now five years old. PEP 429 Python 3.4 release >> schedule has it listed under "Other proposed large-scale changes" but I >> don't believe this is actually happening. Lots of issues on the bug >> tracker have been closed as fixed in the new module, see issue 2636 for >> more data. Some work is still being carried out on the old re module. >> So where do we stand? Is the new module getting into Python 3.x, Python >> 4.y or what? Good question. I hope so. >> If no do all the old issues have to be reopened and >> applied to the re module? I would prefer not. >> Who has to make the final decision on all of this? Ultimately Guido, with a lot of input >> Note that I've no direct interest as I rarely if ever use the little >> perishers, I just find this situation bizarre. It is definitely unfortunate and even embarrassing. At one time, the hangup was a minor feature incompatibility between re and regex. Guido was reluctant to make a switch that would occasionally break code. I believe that this is fixed -- by deciding to call it regex rather then re. My impression from http://bugs.python.org/issue2636 Stage: patch review and pydev discussion is that regex did not land in 3.4 because no one did the rest of the needed review. I do not really know what needs to be done next. Being coded in C does not help speed review. > And FTR I'll break Armed Forces Rule No. 1 and volunteer my own > pitifully poor servies if I can help take this forward, as I think it's > daft having issues marked as fixed on the bug tracker but the fix not > being available in the standard library, only on pypi. Are you volunteering to list issues to be reopened, or to help with code review? -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Thu Dec 5 16:20:19 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Dec 2013 21:20:19 +0000 Subject: status of regex modules In-Reply-To: References: Message-ID: On 05/12/2013 04:37, Terry Reedy wrote: > On 12/4/2013 11:21 AM, Mark Lawrence wrote: >> On 24/10/2013 22:47, Mark Lawrence wrote: >>> The new module is now five years old. PEP 429 Python 3.4 release >>> schedule has it listed under "Other proposed large-scale changes" but I >>> don't believe this is actually happening. Lots of issues on the bug >>> tracker have been closed as fixed in the new module, see issue 2636 for >>> more data. Some work is still being carried out on the old re module. > >>> So where do we stand? Is the new module getting into Python 3.x, Python >>> 4.y or what? > > Good question. I hope so. So do I. When? is the simple question that I'd like to see answered. > >>> If no do all the old issues have to be reopened and >>> applied to the re module? > > I would prefer not. So would I, but it's already been deffered twice (see below), wash rinse, repeat? So should it again fail to be accepted into the Python core for 3.5, will there be a sensible alternative to doing precisely this? > >>> Who has to make the final decision on all of this? > > Ultimately Guido, with a lot of input I assume that Guido could now delegate this if he wished, in the same way that PEPs are now delegated? > >>> Note that I've no direct interest as I rarely if ever use the little >>> perishers, I just find this situation bizarre. > > It is definitely unfortunate and even embarrassing. At one time, the > hangup was a minor feature incompatibility between re and regex. Guido > was reluctant to make a switch that would occasionally break code. I > believe that this is fixed -- by deciding to call it regex rather then re. A definite pig's ear, but one that has been shaped by history. It's my belief that it's now too late to go back and write a PEP for all the changes as would certainly be required now, so let's take this forward. I do not know enough about the hangup or name change to comment. > > My impression from > http://bugs.python.org/issue2636 Stage: patch review > and pydev discussion is that regex did not land in 3.4 because no one > did the rest of the needed review. I do not really know what needs to be > done next. Being coded in C does not help speed review. I don't recall seeing any discussion about it getting into 3.4, did I miss something? Previously it didn't get into 3.3 either, see http://www.python.org/dev/peps/pep-0398/ Python 3.3 Release Schedule, where it's listed in the section "Deferred to post-3.3:". > >> And FTR I'll break Armed Forces Rule No. 1 and volunteer my own >> pitifully poor servies if I can help take this forward, as I think it's >> daft having issues marked as fixed on the bug tracker but the fix not >> being available in the standard library, only on pypi. > > Are you volunteering to list issues to be reopened, or to help with code > review? > I don't mind doing any grunt work to help out. I am not qualified to take on code review for a high profile Python module that is written in C. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From stanward at gmail.com Sun Dec 29 14:38:26 2013 From: stanward at gmail.com (stanward at gmail.com) Date: Sun, 29 Dec 2013 11:38:26 -0800 (PST) Subject: Python 3.3.2 Shell Message In-Reply-To: References: Message-ID: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> Hi Ned, I am running into the same problem described by Bart. I am teaching my kids to program using the Python For Kids book on a Mac OSX 10.8.5. I have installed "Mac OS X 64-bit/32-bit Installer (3.3.3) for Mac OS X 10.6 and later" (file: python-3.3.3-macosx10.6.dmg) and installed the "ActiveTcl 8.6.1 for Mac OS X (10.5+, x86_64/x86)" (file: ActiveTcl8.6.1.1.297588-macosx10.5-i386-x86_64-threaded), but IDLE keeps showing the message "WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable. Visit http://www.python.org/download/mac/tcltk/ for current information." Per your instructions in the thread http://code.activestate.com/lists/python-dev/117314/ I have inspected the IDLE process using Activity Monitor and the Tcl/Tk processes being used are: /System/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk Is there a PATH setting or something I can use to force the use of the ActiveTcl Tcl/Tk located in: /Library/Frameworks/Tcl.framework/Versions/8.5/Tcl and /Library/Frameworks/Tk.framework/Versions/8.5/Tk I have tried a bunch of different things all to no avail, so I am now reaching for help. I have UNIX experience and a CS degree, although very rusty, so have at with any technical instructions. Thank you very much!!! From stanward at gmail.com Sun Dec 29 15:56:53 2013 From: stanward at gmail.com (stanward at gmail.com) Date: Sun, 29 Dec 2013 12:56:53 -0800 (PST) Subject: Python 3.3.2 Shell Message In-Reply-To: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> References: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> Message-ID: > Is there a PATH setting or something I can use to force the use of the ActiveTcl Tcl/Tk located in: > /Library/Frameworks/Tcl.framework/Versions/8.5/Tcl and > /Library/Frameworks/Tk.framework/Versions/8.5/Tk Correction. The ActiveTcl /Library directions are: /Library/Frameworks/Tcl.framework/Versions/8.6 /Library/Frameworks/Tcl.framework/Versions/8.6 Note also that symbolic links were created by something (assume the install script) from: /Library/Frameworks/Tcl.framework/Versions/Current to /Library/Frameworks/Tcl.framework/Versions/8.6 to and /Library/Frameworks/Tk.framework/Versions/Current to /Library/Frameworks/Tk.framework/Versions/8.6 Also, the IDLE message I am getting (which is slightly different than Bart's) is: "WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable." I assume this is referring to the Apple system version of Tcl/Tk. Maybe there is symbolic link I need to set-up... By the way, I have tried to address with setting to PATH in .bash_profile, having /usr/local/bin first in the path. This has created a situation of running the correct version of tclsh from bash, but it does not solve the problem for IDLE, even if putting a specific call to . .bash_profile from the Automator script which starts IDLE. Actively working on this... may try to create a symbolic link from /System/Library/Frameworks/Tcl.framework/Versions/Current to /Library/Frameworks/Tcl.framework/Versions/Current From stanward at gmail.com Sun Dec 29 17:18:18 2013 From: stanward at gmail.com (stanward at gmail.com) Date: Sun, 29 Dec 2013 14:18:18 -0800 (PST) Subject: Python 3.3.2 Shell Message In-Reply-To: References: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> Message-ID: > Actively working on this... may try to create a symbolic link from > /System/Library/Frameworks/Tcl.framework/Versions/Current to > /Library/Frameworks/Tcl.framework/Versions/Current Symbolic link (ln -s) does not seem to have worked either. Grrrr. Tried /System/Library/Frameworks/Tcl.framework/Versions, did ln -s /Library/Frameworks/Tcl.framework/Versions/8.6 Current and /System/Library/Frameworks/Tk.framework/Versions, did ln -s /Library/Frameworks/Tk.framework/Versions/8.6 Current Also tried /System/Library/Frameworks/Tcl.framework/Versions, did ln -s /Library/Frameworks/Tcl.framework/Versions/Current Current and /System/Library/Frameworks/Tk.framework/Versions, did ln -s /Library/Frameworks/Tk.framework/Versions/Current Current such as /System/Library/Frameworks/Tcl.framework/Versions/Current to /Library/Frameworks/Tcl.framework/Versions/8.6 (instead of Current). From stanward at gmail.com Sun Dec 29 23:25:05 2013 From: stanward at gmail.com (Stan Ward) Date: Sun, 29 Dec 2013 20:25:05 -0800 (PST) Subject: Python 3.3.2 Shell Message In-Reply-To: References: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> Message-ID: On Sunday, December 29, 2013 5:18:18 PM UTC-5, Stan Ward wrote: Note: I do not get the "WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable." message when I run python directly from bash (Mac "Terminal"), but I do get it in the IDLE.app Shell Window, run as follows, based on the recommendation in Python for Kids, with the addition of the .bash_profile call to to try to ensure paths. . .bash_profile open -a "//Applications/Python 3.3/IDLE.app" --args -n Sorry about all this newbie questions/info. From stanward at gmail.com Sun Dec 29 17:09:25 2013 From: stanward at gmail.com (stanward at gmail.com) Date: Sun, 29 Dec 2013 14:09:25 -0800 (PST) Subject: Python 3.3.2 Shell Message In-Reply-To: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> References: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> Message-ID: <9628c3cb-f0f1-4089-8c9a-fa9b32e50432@googlegroups.com> > Is there a PATH setting or something I can use to force the use of the ActiveTcl Tcl/Tk located in: > /Library/Frameworks/Tcl.framework/Versions/8.5/Tcl and > /Library/Frameworks/Tk.framework/Versions/8.5/Tk Correction. The ActiveTcl /Library directions are: /Library/Frameworks/Tcl.framework/Versions/8.6 /Library/Frameworks/Tk.framework/Versions/8.6 Note also that symbolic links were created by something (assume the install script) from: /Library/Frameworks/Tcl.framework/Versions/Current to /Library/Frameworks/Tcl.framework/Versions/8.6 to and /Library/Frameworks/Tk.framework/Versions/Current to /Library/Frameworks/Tk.framework/Versions/8.6 Also, the IDLE message I am getting (which is slightly different than Bart's) is: "WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable." I assume this is referring to the Apple system version of Tcl/Tk. Maybe there is symbolic link I need to set-up... By the way, I have tried to address with setting to PATH in .bash_profile, having /usr/local/bin first in the path. This has created a situation of running the correct version of tclsh from bash, but it does not solve the problem for IDLE, even if putting a specific call to . .bash_profile from the Automator script which starts IDLE. Actively working on this...May try to create a symbolic link from /System/Library/Frameworks/Tcl.framework/Versions/Current to /Library/Frameworks/Tcl.framework/Versions/Current From nad at acm.org Mon Dec 30 01:32:24 2013 From: nad at acm.org (Ned Deily) Date: Sun, 29 Dec 2013 22:32:24 -0800 Subject: Python 3.3.2 Shell Message References: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> Message-ID: In article <78312fc7-adf1-4324-82f3-c53a4622b216 at googlegroups.com>, stanward at gmail.com wrote: > I have installed "Mac OS X 64-bit/32-bit Installer (3.3.3) for Mac OS X 10.6 > and later" (file: python-3.3.3-macosx10.6.dmg) and installed the "ActiveTcl > 8.6.1 for Mac OS X (10.5+, x86_64/x86)" (file: > ActiveTcl8.6.1.1.297588-macosx10.5-i386-x86_64-threaded), but IDLE keeps > showing the message "WARNING: The version of Tcl/Tk (8.5.9) in use may be > unstable. Visit http://www.python.org/download/mac/tcltk/ for current > information." You need to install ActiveTcl 8.5 for OS X, currently 8.5.15.0. It's further down on the ActiveTcl download page (http://www.activestate.com/activetcl/downloads). Installing 8.6.1 does not help (it doesn't hurt, either, so you don't need to worry about removing it). -- Ned Deily, nad at acm.org From stanward at gmail.com Mon Dec 30 23:26:13 2013 From: stanward at gmail.com (Stan Ward) Date: Mon, 30 Dec 2013 20:26:13 -0800 (PST) Subject: Python 3.3.2 Shell Message In-Reply-To: References: <78312fc7-adf1-4324-82f3-c53a4622b216@googlegroups.com> Message-ID: <2e4f978c-2077-4ce1-9579-53e26c4ce834@googlegroups.com> Thanks Ned. That did the trick! Jason Briggs, author of Python of Kids, gave me the same answer. Happy to be over this hurdle. Thanks! Happy New Year!! From albert at spenarnc.xs4all.nl Fri Dec 6 08:54:53 2013 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 06 Dec 2013 13:54:53 GMT Subject: Sharing Python installation between architectures References: Message-ID: <52a1d72d$0$4657$e4fe514c@dreader37.news.xs4all.nl> In article , Paul Smith wrote: >One thing I always liked about Perl was the way you can create a single >installation directory which can be shared between archictures. Say >what you will about the language: the Porters have an enormous amount of >experience and expertise producing portable and flexible interpreter >installations. > >By this I mean, basically, multiple architectures (Linux, Solaris, >MacOSX, even Windows) sharing the same $prefix/lib/python2.7 directory. >The large majority of the contents there are completely portable across >architectures (aren't they?) so why should I have to duplicate many >megabytes worth of files? The solution is of course to replace all duplicates by hard links. A tool for this is useful in a lot of other circumstances too. In a re-installation of the whole or parts, the hard links will be removed, and the actual files are only removed if they aren't needed for any of the installations, so this is transparent for reinstallation. After a lot of reinstallation you want to run the tool again. This is of course only possible on real file systems (probably not on FAT), but your files reside on a server, so chances are they are on a real file system. (The above is partly in jest. It is a real solution to storage problems, but storage problems are unheard of in these days of Tera byte disks. It doesn't help with the clutter, which was probably the main motivation.) Symbolic links are not as transparent, but they may work very well too. Have the common part set apart and replace everything else by symbolic links. There is always one more way to skin a cat. Groetjes Albert -- 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 drsalists at gmail.com Thu Dec 5 23:05:00 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 5 Dec 2013 20:05:00 -0800 Subject: Recursive generator for combinations of a multiset? In-Reply-To: <20131121174614.53450d51@mini.home> References: <20131121174614.53450d51@mini.home> Message-ID: On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan wrote: > > Short story: the subject says it all, so if you have an answer already, > fire away. Below is the long story of what I'm using it for, and why I > think it needs to be recursive. It may even be of more general > interest in terms of filtering the results of generators. > > Any suggestions? > I've updated my code at http://stromberg.dnsalias.org/svn/anagrams/trunk/; It's multiword now. It can blast through the word "punishment" in 4 seconds, but for "The public art galleries" it ate about 7 gigabytes of RAM and ran for more than a day before I killed it. I believe it's an exponential problem. Parallelization might help, but it'd probably take a lot of RAM that way. Maybe the RAM use would be better with CPython, but it's much faster with Pypy; I did most of my testing with Pypy 2.2. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Mon Dec 2 09:39:36 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 02 Dec 2013 09:39:36 -0500 Subject: Getting the Appdata Directory with Python and PEP? In-Reply-To: <2b6c4be1-e23f-488b-b64d-191d625dee46@googlegroups.com> References: <50402350-c9cb-47be-b513-ad2fb7170187@googlegroups.com> <27870dae-87ff-4435-a2ff-a42f95c21d48@googlegroups.com> <5294f942$0$16012$e4fe514c@news.xs4all.nl> <2b6c4be1-e23f-488b-b64d-191d625dee46@googlegroups.com> Message-ID: On 11/26/13, 5:49 PM, Eamonn Rea wrote: >> Maybe this module is of some use to you: >> > >> >https://pypi.python.org/pypi/appdirs >> > >> > >> > >> >It provides a unified Python API to the various OS specific 'user' directory locations. >> > >> > >> > >> >Irmen > I saw this, but I wanted to do it myself as I stated in the OP:) This module appears to simply use hard-coded paths on Unix/Linux and OS X--not much to learn there, except which paths to code. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From josefg at gmail.com Tue Dec 3 20:33:56 2013 From: josefg at gmail.com (josefg at gmail.com) Date: Tue, 3 Dec 2013 17:33:56 -0800 (PST) Subject: Tkinter: winfo_screenmmwidth discussion In-Reply-To: References: Message-ID: <46210473-d5e9-421d-a9fd-1a4a66423f20@googlegroups.com> On Tuesday, November 26, 2013 2:13:57 PM UTC-8, jos... at gmail.com wrote: > I am currently using Windows 7 Sp1, Tkinter 8.5, Python 2.7.4 on a laptop with no attached monitor. I am attempting to use winfo_screenmmwidth, but the returned value is incorrect. Specs state 280 mm. Physical measurement is 275 mm. EDID states 280 mm. Tkinter's winfo_screenmmwidth returns 361 mm. I don't have very much tkinter experience, please bear with me. > > > > From where does winfo_screenmmheight get this information? I have looked through the source code and can't really find the source. The source code seems to lead to WidthMMOfScreen(Screen(tkwin)) in both tkGet.c and tkObj.c. Xlib.h defines the Screen structure which has mwidth defined in it. Xlib.h also defines WidthMMOfScreen as a macro "#define WidthMMOfScreen(s) ((s)->mwidth)" The X Window System Protocol:8 Connection Setup:Screen Information states "Width-in-millimeters and height-in-millimeters can be used to determine the physical size and the aspect ratio," but I'm not sure where the code is for the request. > > > > So that's where I stopped on the X Windows side of things. I think I need to look at the source code for _tkinter.lib, but I'm not sure. I downloaded and started to look at the pywin32.exe (win32all) source code, but I'm not sure where to start with that either. I was expecting to see an entry which returns the EDID information, but I have not seen that yet. > > > > Could somebody point me in the right direction? Or does anyone have any ideas? > > > > Thank you in advance. I wrote this to extract the EDID information. It's not very robust and for some reason not all of the subkeys are iterated in a sub key. I also haven't gotten a response from the tcl/tk folks yet. import _winreg def screen_wh(): """Input - none Output - Screen's physical (width, height)""" hive = _winreg.HKEY_LOCAL_MACHINE path = "SYSTEM\\CurrentControlSet\\Enum\\DISPLAY" number = 0 rtpath = None def search_subkeys(hive, path, number, rtpath): number = number + 1 key = _winreg.OpenKey(hive, path, 0, _winreg.KEY_READ) try: i = 0 while 1: name = _winreg.EnumKey(key, i) #print(" "*number + name, i) #Used to view registry path #for some reason this does not iterate over all registry keys crappy fix if i == 2: try: #This works with a direct call, but it's not very portable. name2 = _winreg.EnumKey(key, 3) if name2 == "Control": rtpath = path except WindowsError: pass if rtpath == None: rtpath = search_subkeys(hive, path+"\\"+name, number, rtpath) i += 1 except WindowsError: pass return(rtpath) monitor = search_subkeys(hive,path, number,rtpath) print("EDID registry path: {0}".format(monitor)) key = _winreg.OpenKey(hive, monitor+"\\Device Parameters") try: i = 0 while 1: name, data, type = _winreg.EnumValue(key, i) if name == 'EDID': break except WindowsError: "EDID not found" width = int(data[21].encode('hex'),16) * 10 height = int(data[22].encode('hex'),16) * 10 print("Width: {0} mm\nHeight: {1} mm".format(width,height)) return((width, height)) From thebalancepro at gmail.com Wed Dec 4 20:47:01 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Wed, 4 Dec 2013 17:47:01 -0800 (PST) Subject: Python and PEP8 - Recommendations on breaking up long lines? In-Reply-To: References: Message-ID: <4dd6c66d-7852-49c7-be02-ff57906e5303@googlegroups.com> Hi Victor, I use PyCharm which is set up by default to warn when line length exceeds 120 chars, not 80. Perhaps times have changed? I often break comprehensions at the for, in and else clauses. It's often not for line length reasons but because it's easier to follow the code that way. I have heard this is how Haskell programmers tend to use comprehensions (comprehensions are from Haskell originally): location=random.choice([loc['pk'] for loc in locations.whole_register() if loc['fields']['provider_id'] == provider_id]))) The other suggestion I have is to put the with clauses in a generator function. This saves you a level or more of indentation and modularises the code usefully. Here's an example: def spreadsheet(csv_filename): with open(csv_filename) as csv_file: for csv_row in list(csv.DictReader(csv_file, delimiter='\t')): yield csv_row then invoked using: for row in spreadsheet("...") # your processing code here Cheers, Nick From robin at reportlab.com Mon Dec 2 09:42:52 2013 From: robin at reportlab.com (Robin Becker) Date: Mon, 02 Dec 2013 14:42:52 +0000 Subject: reporting proxy porting problem In-Reply-To: References: <5297250A.80709@chamonix.reportlab.co.uk> Message-ID: <529C9C6C.6050106@chamonix.reportlab.co.uk> On 28/11/2013 22:01, Terry Reedy wrote: .............. > > All the transition guides I have seen recommend first updating 2.x code (and its > tests) to work in 2.x with *all* classes being new-style classes. I presume one > of the code checker programs will check this for you. To some extent, the > upgrade can be done by changing one class at a time. > the intent is to produce a compatible code with aid of six.py like functions. > Yes, this means abandoning support of 2.1 ;-). It also means giving up > magical hacks that only work with old-style classes. > >> I find that I don't understand exactly how the original works so well, > > To me, not being comprehensible is not a good sign. I explain some of > the behavior below. The author has commented that he might have been drunk at time of writing :) > >> but here is a cut down version > .. thanks for the analysis, I think we came to the same broad conclusion. I think this particular module may get lost in the wash. If it ever needs re-implementing we can presumably rely on some more general approach as used in the various remote object proxies like pyro or similar. -- Robin Becker From cs at zip.com.au Tue Dec 3 19:38:19 2013 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Dec 2013 11:38:19 +1100 Subject: Managing Google Groups headaches In-Reply-To: References: Message-ID: <20131204003819.GA85826@cskk.homeip.net> On 28Nov2013 19:46, Arif Khokar wrote: > The problem with just using email is that it's a bit more difficult > to browse archived posts to this group. After I subscribed to this > group (comp.lang.python) using my news client, I could immediately > browse posts made as far back as April. I vastly prefer email. My first act on joining any mailing list is to download the entire archive into my local mail store. I have a script for this, for mailman at least. Example: get-mailman-archive http://mail.python.org/pipermail/pythonmac-sig/ >python-mac.mbox I then suck the whole thing into the folder to which future list posts will get filed. That way I have the whole archive, and it is local, and I can examine it with whatever tools take my fancy (mairix, mutt, grep, etc). Most mailman lists make their archives readily available. This cannot be said for the travesty that is Google Groups, and in fact almost any other list/group/forum run with other software. Really, most mailing list archives are easily small enough to do this routinely. Happy to assist anyone with scripts etc. Cheers, -- Cameron Simpson Carpe Daemon - Seize the Background Process - Paul Tomblin From rustompmody at gmail.com Tue Dec 3 20:39:16 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Dec 2013 17:39:16 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: Message-ID: <46bef6f7-0ca3-4574-8641-9838eba7bb9f@googlegroups.com> On Wednesday, December 4, 2013 6:10:05 AM UTC+5:30, Cameron Simpson wrote: > > Dennis Lee Bieber writes: > > > [NNTP] clients provide full-fledged editors > > and conversely full-fledged editors provide > > NNTP clients > GNU Emacs is a LISP operating system disguised as a word processor. > - Doug Mohney, in comp.arch In a similar vein, most phones nowadays are just computers with a pocket-size form-factor and some wireless networking. So when you say? > My first act on joining any mailing list is to download the entire > archive into my local mail store. I have a script for this, for > mailman at least. and you happen to own >1 thingys that have general computing functionality -- phones, laptops, desktops, etc -- do you sync all your mailing-lists with all of them? I know friends who have installed a home-data-store? [Ive been resisting getting something like a NAS because each new thingabob I own is one more thing to maintain. I also know from past experience that such luddite battles are in the end always lost -- Im no technophile but I expect to live and die a techie] And inspite of all that it still sometimes happens that one has to work on a 'machine' that is not one's own. What then? The unfortunate and inexorable conclusion is that when the (wo)man <-> computer relation goes from 1-1 to 1-many, data and functionality will move away from 'own-machine' to the cloud. Will the data be subject to privacy-abuse and worse? Sure Will the functionality be as good as something one can fine-tune on one's own computer? heck no! But in the end, uniform access will trump all that -- compare the number of vi+emacs+eclipse users with google-doc users? So to come back full-circle: Earlier (your quote paraphrased) Emacs is a full-blown OS -- only lacks a good editor. Now: replace 'emacs' with 'firefox'. From rosuav at gmail.com Tue Dec 3 21:03:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Dec 2013 13:03:03 +1100 Subject: Managing Google Groups headaches In-Reply-To: <46bef6f7-0ca3-4574-8641-9838eba7bb9f@googlegroups.com> References: <46bef6f7-0ca3-4574-8641-9838eba7bb9f@googlegroups.com> Message-ID: On Wed, Dec 4, 2013 at 12:39 PM, rusi wrote: > The unfortunate and inexorable conclusion is that when the > (wo)man <-> computer relation goes from 1-1 to 1-many, data and > functionality will move away from 'own-machine' to the cloud. > > Will the data be subject to privacy-abuse and worse? Sure > Will the functionality be as good as something one can fine-tune > on one's own computer? heck no! The solution often is to run your own central server and have all devices connect to that. You get full control and still allow any device to access the same content. ChrisA From cs at zip.com.au Wed Dec 4 17:47:11 2013 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 5 Dec 2013 09:47:11 +1100 Subject: Managing Google Groups headaches In-Reply-To: <46bef6f7-0ca3-4574-8641-9838eba7bb9f@googlegroups.com> References: <46bef6f7-0ca3-4574-8641-9838eba7bb9f@googlegroups.com> Message-ID: <20131204224711.GA76939@cskk.homeip.net> On 03Dec2013 17:39, rusi wrote: > On Wednesday, December 4, 2013 6:10:05 AM UTC+5:30, Cameron Simpson wrote: > > My first act on joining any mailing list is to download the entire > > archive into my local mail store. I have a script for this, for > > mailman at least. > > and you happen to own >1 thingys that have general computing > functionality -- phones, laptops, desktops, etc -- do you sync > all your mailing-lists with all of them? No. I'm using a laptops my primary host, and it has the mailing lists (and all my email). It is usually on and fetches and files my email; it also forwards _specific_ stuff to a separate mail account accessed by my phone. I used to use a home server, but the remote access, while fairly transparent (script to "ssh then run mutt"), was irritating. And when I didn't have remote access, very very irritating. So I'm choosing the better environment with my email local to the laptop and a select copy of important things (work and friends) copied to an account for my phone. [...] > And inspite of all that it still sometimes happens that one has > to work on a 'machine' that is not one's own. What then? Fingers crossed the important stuff gets to my phone. If urgent I can reply from that, and I'm somewhat up to date on what I care about. The phone also has (disabled) access to my primary mail spool for circumstances when the laptop is offline. When online, the laptop empties that spool ad forwards particulars. When offline, I can consult what's queuing up. > The unfortunate and inexorable conclusion is that when the > (wo)man <-> computer relation goes from 1-1 to 1-many, data and > functionality will move away from 'own-machine' to the cloud. > Will the data be subject to privacy-abuse and worse? Sure > Will the functionality be as good as something one can fine-tune > on one's own computer? heck no! I'm striving to resist that for now. Privacy. Security. Dependence on others' hardware and (not mine => wrong!) technical choices of software. Cheers, -- Cameron Simpson All it takes is working on someone elses program to understand why they call it "code". - Henry O. Farad From rustompmody at gmail.com Fri Dec 6 02:42:57 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 5 Dec 2013 23:42:57 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: <46bef6f7-0ca3-4574-8641-9838eba7bb9f@googlegroups.com> Message-ID: On Thursday, December 5, 2013 4:17:11 AM UTC+5:30, Cameron Simpson wrote: > On 03Dec2013 17:39, rusi wrote: > > On Wednesday, December 4, 2013 6:10:05 AM UTC+5:30, Cameron Simpson wrote: > > > My first act on joining any mailing list is to download the entire > > > archive into my local mail store. I have a script for this, for > > > mailman at least. > > and you happen to own >1 thingys that have general computing > > functionality -- phones, laptops, desktops, etc -- do you sync > > all your mailing-lists with all of them? > No. I'm using a laptops my primary host, and it has the mailing > lists (and all my email). It is usually on and fetches and files > my email; it also forwards _specific_ stuff to a separate mail > account accessed by my phone. > I used to use a home server, but the remote access, while fairly > transparent (script to "ssh then run mutt"), was irritating. And > when I didn't have remote access, very very irritating. > So I'm choosing the better environment with my email local to the laptop and > a select copy of important things (work and friends) copied to an account for > my phone. > [...] > > And inspite of all that it still sometimes happens that one has > > to work on a 'machine' that is not one's own. What then? > Fingers crossed the important stuff gets to my phone. If urgent I > can reply from that, and I'm somewhat up to date on what I care > about. The phone also has (disabled) access to my primary mail spool > for circumstances when the laptop is offline. When online, the > laptop empties that spool ad forwards particulars. When offline, I > can consult what's queuing up. > > The unfortunate and inexorable conclusion is that when the > > (wo)man <-> computer relation goes from 1-1 to 1-many, data and > > functionality will move away from 'own-machine' to the cloud. > > Will the data be subject to privacy-abuse and worse? Sure > > Will the functionality be as good as something one can fine-tune > > on one's own computer? heck no! > I'm striving to resist that for now. Privacy. Security. Dependence > on others' hardware and (not mine => wrong!) technical choices of > software. Thanks Cameron. I am not sure how to parse the last sentence but on the whole thanks for a fair balanced and honest review. I think I have similar sentiments, viz. I am not one to gush about the latest gizmodic blissiness, however whenever Ive resisted and been a late adopter -- color monitor, laptop, cellphone, credit card etc etc -- in the end Ive had to move with the time and not been better-off for my earlier resistance. From cs at zip.com.au Tue Dec 3 19:40:05 2013 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Dec 2013 11:40:05 +1100 Subject: Managing Google Groups headaches In-Reply-To: <874n6uc97q.fsf@pascolo.net> References: <874n6uc97q.fsf@pascolo.net> Message-ID: <20131204004005.GA93000@cskk.homeip.net> On 30Nov2013 14:25, pecore at pascolo.net wrote: > Dennis Lee Bieber writes: > > [NNTP] clients provide full-fledged editors > and conversely full-fledged editors provide > NNTP clients GNU Emacs is a LISP operating system disguised as a word processor. - Doug Mohney, in comp.arch Sorry, could not resist. I am, of course, a vi user. Cheers, -- Cameron Simpson [...] look at yourself and, while you're at it, drag your eyes over some of your mates who also ride bikes. They are doers, are they not, and what of the rest of the population, that tragic ants nest of ever so busy bodies who scurry from nest to work and back to the nest again at night, to recharge themselves for another day of spirit-crushing toil? They are the watchers. - Sanford, REVS, 23dec93 From invalid at invalid.invalid Wed Dec 4 10:50:11 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 Dec 2013 15:50:11 +0000 (UTC) Subject: Managing Google Groups headaches References: <874n6uc97q.fsf@pascolo.net> Message-ID: On 2013-12-04, Cameron Simpson wrote: > On 30Nov2013 14:25, pecore at pascolo.net wrote: >> Dennis Lee Bieber writes: >> > [NNTP] clients provide full-fledged editors >> and conversely full-fledged editors provide >> NNTP clients > > GNU Emacs is a LISP operating system disguised as a word processor. > - Doug Mohney, in comp.arch Unix: A set of device drivers used to support the the Emacs operating system. - Don't remember who, where, or when -- Grant Edwards grant.b.edwards Yow! I feel like a wet at parking meter on Darvon! gmail.com From breamoreboy at yahoo.co.uk Wed Dec 4 11:07:45 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 16:07:45 +0000 Subject: Managing Google Groups headaches In-Reply-To: References: <874n6uc97q.fsf@pascolo.net> Message-ID: On 04/12/2013 15:50, Grant Edwards wrote: > On 2013-12-04, Cameron Simpson wrote: >> On 30Nov2013 14:25, pecore at pascolo.net wrote: >>> Dennis Lee Bieber writes: >>>> [NNTP] clients provide full-fledged editors >>> and conversely full-fledged editors provide >>> NNTP clients >> >> GNU Emacs is a LISP operating system disguised as a word processor. >> - Doug Mohney, in comp.arch > > Unix: A set of device drivers used to support the the Emacs operating > system. > > - Don't remember who, where, or when > It's a funny thing the computing world, with some people deriving operating systems from raincoats, and others editing code with a domestic household cleaner, what next, I ask myself? -- 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 Wed Dec 4 11:21:07 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 04 Dec 2013 11:21:07 -0500 Subject: Managing Google Groups headaches In-Reply-To: References: <874n6uc97q.fsf@pascolo.net> Message-ID: On 12/4/13 11:07 AM, Mark Lawrence wrote: > On 04/12/2013 15:50, Grant Edwards wrote: >> On 2013-12-04, Cameron Simpson wrote: >>> On 30Nov2013 14:25, pecore at pascolo.net wrote: >>>> Dennis Lee Bieber writes: >>>>> [NNTP] clients provide full-fledged editors >>>> and conversely full-fledged editors provide >>>> NNTP clients >>> >>> GNU Emacs is a LISP operating system disguised as a word processor. >>> - Doug Mohney, in comp.arch >> >> Unix: A set of device drivers used to support the the Emacs operating >> system. >> >> - Don't remember who, where, or when >> > > It's a funny thing the computing world, with some people deriving > operating systems from raincoats, and others editing code with a > domestic household cleaner, what next, I ask myself? > Computing with vacuum cleaners is on the decline at least: http://www.vax.co.uk/vacuum-cleaners --Ned. From breamoreboy at yahoo.co.uk Wed Dec 4 11:33:44 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 16:33:44 +0000 Subject: Managing Google Groups headaches In-Reply-To: References: <874n6uc97q.fsf@pascolo.net> Message-ID: On 04/12/2013 16:21, Ned Batchelder wrote: > On 12/4/13 11:07 AM, Mark Lawrence wrote: >> On 04/12/2013 15:50, Grant Edwards wrote: >>> On 2013-12-04, Cameron Simpson wrote: >>>> On 30Nov2013 14:25, pecore at pascolo.net wrote: >>>>> Dennis Lee Bieber writes: >>>>>> [NNTP] clients provide full-fledged editors >>>>> and conversely full-fledged editors provide >>>>> NNTP clients >>>> >>>> GNU Emacs is a LISP operating system disguised as a word processor. >>>> - Doug Mohney, in comp.arch >>> >>> Unix: A set of device drivers used to support the the Emacs operating >>> system. >>> >>> - Don't remember who, where, or when >>> >> >> It's a funny thing the computing world, with some people deriving >> operating systems from raincoats, and others editing code with a >> domestic household cleaner, what next, I ask myself? >> > > Computing with vacuum cleaners is on the decline at least: > http://www.vax.co.uk/vacuum-cleaners > > --Ned. > Well it shouldn't be. It's a well known fact that VMS stands for Very Much Safer. I'd compare it to inferior products, but not even the threat of The Comfy Chair will make me type the names. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From neilc at norwich.edu Mon Dec 2 08:03:52 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 2 Dec 2013 13:03:52 +0000 (UTC) Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: On 2013-11-28, Roy Smith wrote: > In article , > Alister wrote: >> Perhaps the best option is for everybody to bombard Google >> with bug reports (preferably typed with extra long lines & >> double spaced as that is clearly what they are used to & we >> would not want to upset them would we? ) > > It's pretty clear Google doesn't care about Google Groups. Or, > at least, they don't care that it interacts badly with > newsgroups, and in particular with bidirectional > newsgroup/mailing-list gateways. > > The purpose of Google Groups is to generate traffic to their > site, which it does just fine. Making it behave better with > newsgroups won't change that, so there's no incentive for them > to do so. The current situation does force a lot of technology-focused people, progammers in particular, into a low opinion of Google. The crappy usenet portal is poor marketing. I wish they'd never bought dejanews. -- Neil Cerutti From torriem at gmail.com Mon Dec 2 20:17:51 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Dec 2013 18:17:51 -0700 Subject: [OT] Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: <529D313F.6040104@gmail.com> On 12/02/2013 06:03 AM, Neil Cerutti wrote: > I wish they'd never bought dejanews. I wish Google hadn't bought a lot of things. Seems like they bye up a lot of cool, nerd-centric apps and companies and then turned them into apps that do less and do it poorly, but in a slick way that appeals to the unwashed masses. And add "social" to it. Great for their bottom line, but horrible for those of us that actually use things as tools. Besides the dejanews thing, another one is Google Voice. Used to be a great tool but now they are trying to integrate it with Google Hangouts, reduce its functionality, reduce interoperability, and otherwise ruin it. I fear next year is the last year for Google Voice in any usable form for me. Might just have to bite the bullet and set up my own PBX and pay for a voip provider and port my google voice number over to it. I'd hate to lose the number; I've used it since Grand Central times. And Gmail is also becoming less useful to me. I don't want to use hangouts; xmpp and google talk worked just fine. But alas that's disappearing. And the list goes on. From breamoreboy at yahoo.co.uk Tue Dec 3 07:09:41 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Dec 2013 12:09:41 +0000 Subject: [OT] Managing Google Groups headaches In-Reply-To: <529D313F.6040104@gmail.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> <529D313F.6040104@gmail.com> Message-ID: On 03/12/2013 01:17, Michael Torrie wrote: > > And the list goes on. > The love of money... -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Mon Dec 2 20:43:03 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Dec 2013 20:43:03 -0500 Subject: [OT] Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: In article , Michael Torrie wrote: > I wish Google hadn't bought a lot of things. Seems like they bye up a > lot of cool, nerd-centric apps and companies and then turned them into > apps that do less and do it poorly, but in a slick way that appeals to > the unwashed masses. And add "social" to it. Great for their bottom > line, but horrible for those of us that actually use things as tools. And this is surprising, why? From rustompmody at gmail.com Mon Dec 2 21:27:42 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 2 Dec 2013 18:27:42 -0800 (PST) Subject: [OT] Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: <9b6e5315-eefa-466e-9774-5bf071618604@googlegroups.com> On Tuesday, December 3, 2013 7:13:03 AM UTC+5:30, Roy Smith wrote: > Michael Torrie wrote: > > I wish Google hadn't bought a lot of things. Seems like they bye up a > > lot of cool, nerd-centric apps and companies and then turned them into > > apps that do less and do it poorly, but in a slick way that appeals to > > the unwashed masses. And add "social" to it. Great for their bottom > > line, but horrible for those of us that actually use things as tools. > And this is surprising, why? Something floating around here (was it Ben Finney's footer??) went something like: We must expect it; else we would be surprised Put differently: One evidence of being awake (and not in dreamland) is surprise A directly related piece by Nicholas Carr http://www.theatlantic.com/magazine/archive/2008/07/is-google-making-us-stupid/306868/ Relevant at a deeper level is his "IT doesn't matter" http://www.roughtype.com/?p=644 We software professionals cannot agree with this and keep our self-respect/sanity/identity. However its true; so denial remains the only option. From torriem at gmail.com Mon Dec 2 22:09:02 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 02 Dec 2013 20:09:02 -0700 Subject: [OT] Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: <529D4B4E.9040303@gmail.com> On 12/02/2013 06:43 PM, Roy Smith wrote: > In article , > Michael Torrie wrote: > >> I wish Google hadn't bought a lot of things. Seems like they bye up a >> lot of cool, nerd-centric apps and companies and then turned them into >> apps that do less and do it poorly, but in a slick way that appeals to >> the unwashed masses. And add "social" to it. Great for their bottom >> line, but horrible for those of us that actually use things as tools. > > And this is surprising, why? Well back when Google was a young hip company they billed themselves as a bunch of nerds making stuff for nerds. But yes we should have seen this coming. From rustompmody at gmail.com Mon Dec 2 22:26:31 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 2 Dec 2013 19:26:31 -0800 (PST) Subject: [OT] Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: <89c02bb6-1a10-4567-8e8d-f6089430558a@googlegroups.com> On Tuesday, December 3, 2013 8:39:02 AM UTC+5:30, Michael Torrie wrote: > On 12/02/2013 06:43 PM, Roy Smith wrote: > > And this is surprising, why? > > Well back when Google was a young hip company they billed themselves as > a bunch of nerds making stuff for nerds. But yes we should have seen > this coming. So were Bill Gates and Jobs -- nerdy youths. We tend to not think them so because they are an earlier generation. From invalid at invalid.invalid Mon Dec 2 23:27:07 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 Dec 2013 04:27:07 +0000 (UTC) Subject: [OT] Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: On 2013-12-03, Michael Torrie wrote: > On 12/02/2013 06:03 AM, Neil Cerutti wrote: >> I wish they'd never bought dejanews. > > I wish Google hadn't bought a lot of things. Seems like they bye up a > lot of cool, nerd-centric apps and companies and then turned them into > apps that do less and do it poorly, Or they just shut them down. I still wish SageTv was in business. My SageTv stuff is still running fine, but I don't know what I'm going to do when it dies. I guess I'll have to go back to Mytv and the associated huge, loud, noisy front-end boxes. That said, I'm still pretty happy with Gmail (I use it mostly via mutt/IMAP rather than the WebUI), and it sure beats the e-mail service I paid for in the past [it's certainly _way_ better than the Outlook server they run at work]. The Google search engine still works fine for me, and my Nexus Galaxy phone has been great. -- Grant From rosuav at gmail.com Tue Dec 3 02:01:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Dec 2013 18:01:59 +1100 Subject: [OT] Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: On Tue, Dec 3, 2013 at 3:27 PM, Grant Edwards wrote: > That said, I'm still pretty happy with Gmail (I use it mostly via > mutt/IMAP rather than the WebUI), and it sure beats the e-mail service > I paid for in the past [it's certainly _way_ better than the Outlook > server they run at work]. The Google search engine still works fine > for me, and my Nexus Galaxy phone has been great. Things Google does well are those that take advantage of the corpus of searchable data - like Translate. I wouldn't bother with any other online translation tool than Google Translate. ChrisA From wuwei23 at gmail.com Tue Dec 3 01:30:05 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 03 Dec 2013 16:30:05 +1000 Subject: [OT] Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: On 3/12/2013 11:17 AM, Michael Torrie wrote: > And Gmail is also becoming less useful to me. I don't want to use > hangouts; xmpp and google talk worked just fine. But alas that's > disappearing. I really hate Hangouts. If I wanted to use Skype I would be using Skype. I'm also still unable to understand why Google scrapped Reader and kept Groups, although I suspect it's because the latter will eventually integrate more closely with Plus & Hangouts. From steve at pearwood.info Tue Dec 3 02:13:16 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Dec 2013 07:13:16 GMT Subject: [OT] Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: <529d848b$0$11113$c3e8da3@news.astraweb.com> On Tue, 03 Dec 2013 16:30:05 +1000, alex23 wrote: > On 3/12/2013 11:17 AM, Michael Torrie wrote: >> And Gmail is also becoming less useful to me. I don't want to use >> hangouts; xmpp and google talk worked just fine. But alas that's >> disappearing. > > I really hate Hangouts. If I wanted to use Skype I would be using Skype. > > I'm also still unable to understand why Google scrapped Reader and kept > Groups, although I suspect it's because the latter will eventually > integrate more closely with Plus & Hangouts. Not aimed specifically at either Michael or Alex, but a general observation aimed at you all. You poor fools you, this is what happens when you give control of the tools you use to a (near) monopolist whose incentives are not your incentives. I mean, Microsoft was bad enough, but they could never reach through the aether into your computer and remove software they no longer wanted you to use. The worst that could happen was that they would stop supporting it and you'd be stuck with old obsolete hardware running old obsolete software that nevertheless did exactly what you want. Google, on the other hand, can and will take away software that you use. -- Steven From wuwei23 at gmail.com Tue Dec 3 19:23:43 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 04 Dec 2013 10:23:43 +1000 Subject: [OT] Managing Google Groups headaches In-Reply-To: <529d848b$0$11113$c3e8da3@news.astraweb.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> <529d848b$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 3/12/2013 5:13 PM, Steven D'Aprano wrote: > You poor fools you, this is what happens when you give control of the > tools you use to a (near) monopolist whose incentives are not your > incentives. To paraphrase Franklin: those who would give up control to purchase convenience deserve neither. A lesson hard learned :( From neilc at norwich.edu Wed Dec 4 09:34:41 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 4 Dec 2013 14:34:41 +0000 (UTC) Subject: [OT] Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> <529d848b$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2013-12-04, alex23 wrote: > On 3/12/2013 5:13 PM, Steven D'Aprano wrote: >> You poor fools you, this is what happens when you give control >> of the tools you use to a (near) monopolist whose incentives >> are not your incentives. > > To paraphrase Franklin: those who would give up control to > purchase convenience deserve neither. A lesson hard learned :( But Franklin's quote doesn't apply when free alternatives exist. I can use a non-open email system until I don't want to any more, and switch out when it no longer please me. The cost of switching isn't zero, but it's much easier than emmigrating from a police state. Moreover, I'll always feel that I deserve more than I actually do deserve. -- Neil Cerutti From breamoreboy at yahoo.co.uk Wed Dec 4 10:21:29 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 15:21:29 +0000 Subject: [OT] Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> <529d848b$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 04/12/2013 14:34, Neil Cerutti wrote: > On 2013-12-04, alex23 wrote: >> On 3/12/2013 5:13 PM, Steven D'Aprano wrote: >>> You poor fools you, this is what happens when you give control >>> of the tools you use to a (near) monopolist whose incentives >>> are not your incentives. >> >> To paraphrase Franklin: those who would give up control to >> purchase convenience deserve neither. A lesson hard learned :( > > But Franklin's quote doesn't apply when free alternatives exist. Free at the point of delivery, someone, somewhere, has given blood, toil, tears and sweat. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Mon Dec 2 08:29:47 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Dec 2013 08:29:47 -0500 Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: In article , Neil Cerutti wrote: > On 2013-11-28, Roy Smith wrote: > > In article , > > Alister wrote: > >> Perhaps the best option is for everybody to bombard Google > >> with bug reports (preferably typed with extra long lines & > >> double spaced as that is clearly what they are used to & we > >> would not want to upset them would we? ) > > > > It's pretty clear Google doesn't care about Google Groups. Or, > > at least, they don't care that it interacts badly with > > newsgroups, and in particular with bidirectional > > newsgroup/mailing-list gateways. > > > > The purpose of Google Groups is to generate traffic to their > > site, which it does just fine. Making it behave better with > > newsgroups won't change that, so there's no incentive for them > > to do so. > > The current situation does force a lot of technology-focused > people, progammers in particular, into a low opinion of Google. > The crappy usenet portal is poor marketing. If you think, "The set of people who are still trying to use usenet groups for anything serious" is a lot of people, you don't understand the scale on which Google operates. From neilc at norwich.edu Mon Dec 2 09:04:33 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 2 Dec 2013 14:04:33 +0000 (UTC) Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: On 2013-12-02, Roy Smith wrote: > In article , > Neil Cerutti wrote: > >> On 2013-11-28, Roy Smith wrote: >> > In article , >> > Alister wrote: >> >> Perhaps the best option is for everybody to bombard Google >> >> with bug reports (preferably typed with extra long lines & >> >> double spaced as that is clearly what they are used to & we >> >> would not want to upset them would we? ) >> > >> > It's pretty clear Google doesn't care about Google Groups. Or, >> > at least, they don't care that it interacts badly with >> > newsgroups, and in particular with bidirectional >> > newsgroup/mailing-list gateways. >> > >> > The purpose of Google Groups is to generate traffic to their >> > site, which it does just fine. Making it behave better with >> > newsgroups won't change that, so there's no incentive for them >> > to do so. >> >> The current situation does force a lot of technology-focused >> people, progammers in particular, into a low opinion of Google. >> The crappy usenet portal is poor marketing. > > If you think, "The set of people who are still trying to use > usenet groups for anything serious" is a lot of people, you > don't understand the scale on which Google operates. It's probably hard to even visualize. -- Neil Cerutti From rustompmody at gmail.com Mon Dec 2 12:11:01 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 2 Dec 2013 09:11:01 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> Message-ID: <695ec03f-b066-4b72-b1c8-a1b18c5e835b@googlegroups.com> On Monday, December 2, 2013 7:34:33 PM UTC+5:30, Neil Cerutti wrote: > On 2013-12-02, Roy Smith wrote: > >> The current situation does force a lot of technology-focused > >> people, progammers in particular, into a low opinion of Google. > >> The crappy usenet portal is poor marketing. > > > > If you think, "The set of people who are still trying to use > > usenet groups for anything serious" is a lot of people, you > > don't understand the scale on which Google operates. > > It's probably hard to even visualize. I was dreaming about in an alternate surreal world? And now you guys have crashed me back to planet-earth-2013 !MEAN! From breamoreboy at yahoo.co.uk Mon Dec 2 12:48:25 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 17:48:25 +0000 Subject: Managing Google Groups headaches In-Reply-To: <695ec03f-b066-4b72-b1c8-a1b18c5e835b@googlegroups.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> <695ec03f-b066-4b72-b1c8-a1b18c5e835b@googlegroups.com> Message-ID: On 02/12/2013 17:11, rusi wrote: > On Monday, December 2, 2013 7:34:33 PM UTC+5:30, Neil Cerutti wrote: >> On 2013-12-02, Roy Smith wrote: >>>> The current situation does force a lot of technology-focused >>>> people, progammers in particular, into a low opinion of Google. >>>> The crappy usenet portal is poor marketing. >>> >>> If you think, "The set of people who are still trying to use >>> usenet groups for anything serious" is a lot of people, you >>> don't understand the scale on which Google operates. >> >> It's probably hard to even visualize. > > I was dreaming about in an alternate surreal world? > And now you guys have crashed me back to planet-earth-2013 > > !MEAN! > ?As this is an international group why not ?MEAN!? :) Quickly runs off to hide... -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From rosuav at gmail.com Mon Dec 2 12:54:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Dec 2013 04:54:36 +1100 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> <695ec03f-b066-4b72-b1c8-a1b18c5e835b@googlegroups.com> Message-ID: On Tue, Dec 3, 2013 at 4:48 AM, Mark Lawrence wrote: > ?As this is an international group why not ?MEAN!? :) ?Does punctuation nest to any level when you ask, ?Shouldn't it be ?MEAN!?? ChrisA From breamoreboy at yahoo.co.uk Mon Dec 2 13:07:27 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 18:07:27 +0000 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <834d2e9d-2fb2-4401-82fe-dbe161d6d362@googlegroups.com> <695ec03f-b066-4b72-b1c8-a1b18c5e835b@googlegroups.com> Message-ID: On 02/12/2013 17:54, Chris Angelico wrote: > On Tue, Dec 3, 2013 at 4:48 AM, Mark Lawrence wrote: >> ?As this is an international group why not ?MEAN!? :) > > ?Does punctuation nest to any level when you ask, ?Shouldn't it be ?MEAN!?? > > ChrisA > Yes. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From rsk at gsp.org Wed Dec 4 09:52:23 2013 From: rsk at gsp.org (Rich Kulawiec) Date: Wed, 4 Dec 2013 09:52:23 -0500 Subject: Managing Google Groups headaches In-Reply-To: <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> Message-ID: <20131204145223.GA7205@gsp.org> (comments from a lurker on python-list) - Google "groups" is a disaster. It's extremely poorly-run, and is in fact a disservice to Usenet -- which is alive and well, tyvm, and still used by many of the most senior and experienced people on the Internet. (While some newsgroups are languishing and some have almost no traffic, others are thriving. As it should be.) I could catalog the litany of egregious mistakes that Google has made, but what's the point? They're clearly uninterested in fixing them. Their only interest is in slapping the "Google" label on Usenet -- which is far more important in the evolution of the Internet than Google will ever be -- so that they can use it as a marketing vehicle. Worse, Google has completely failed to control outbound abuse from Google groups, which is why many consider it a best practice to simply drop all Usenet traffic originating there. - That said, there is value in bidirectionally gatewaying mailing lists with corresponding Usenet newsgroups. Usenet's propagation properties often make it the medium of choice for many people, particularly those in areas with slow, expensive, erratic, etc. connectivity. Conversely, delivery of Usenet traffic via email is a better solution for others. Software like Mailman facilitates this fairly well, even given the impedance mismatch between SMTP and NNTP. - Mailing lists/Usenet newsgroups remain, as they've been for a very long time, the solutions of choice for online discussions. Yes, I'm aware of web forums: I've used hundreds of them. They suck. They ALL suck, they just all suck differently. I could spend the next several thousand lines explaining why, but instead I'll just abbreviate: they don't handle threading, they don't let me use my editor of choice, they don't let me build my own archive that I can search MY way including when I'm offline, they are brittle and highly vulnerable to abuse and security breaches, they encourage worst practices in writing style (including top-posting and full-quoting), they translate poorly to other formats, they are difficult to archive, they're even more difficult to migrate (whereas Unix mbox format files from 30 years ago are still perfectly usable today), they aren't standardized, they aren't easily scalable, they're overly complex, they don't support proper quoting, they don't support proper attribution, they can't be easily forwarded, they...oh, it just goes on. My point being that there's a reason that the IETF and the W3C and NANOG and lots of other groups that could use anything they want use mailing lists: they work. - That said, they work *if configured properly*, which unfortunately these days includes a hefty dose of anti-abuse controls. This list (for the most part) isn't particularly targeted, but it is occasionally and in the spirit of trying to help out, I can assist with that. (I think it's fair to say I have a little bit of email expertise.) If any of the list's owners are reading this and want help, please let me know. - They also work well *if used properly*, which means that participants should use proper email/news etiquette: line wrap, sane quoting style, reasonable editing of followups, preservation of threads, all that stuff. The more people do more of that, the smoother things work. On the other hand, if nobody does that, the result is impaired communication and quite often, a chorus of "mailing lists suck" even though the problem is not the mailing lists: it's the bad habits of the users on them. (And of course changing mediums won't fix that.) - To bring this back around to one of the starting points for this discussion: I think the current setup is functioning well, even given the sporadic stresses placed on it. I think it would be best to invest effort in maintaining/improving it as it stands (which is why I volunteered to do so, see above) rather than migrating to something else. ---rsk From rosuav at gmail.com Wed Dec 4 10:46:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Dec 2013 02:46:22 +1100 Subject: Managing Google Groups headaches In-Reply-To: <20131204145223.GA7205@gsp.org> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <20131204145223.GA7205@gsp.org> Message-ID: On Thu, Dec 5, 2013 at 1:52 AM, Rich Kulawiec wrote: > Mailing lists/Usenet newsgroups remain, as they've been for a very > long time, the solutions of choice for online discussions. Yes, I'm > aware of web forums: I've used hundreds of them. They suck. They ALL > suck, they just all suck differently. I absolutely agree. And Mailman lists are both easy and powerful - I've deployed a number of them and subscribed to many MANY more - and play nicely with other internet standards. Instead of having to remember to check umpteen web-based forums, I just check my emails, which I do constantly anyway. Adding another mailing list costs me nothing; adding another forum costs me quite a bit of time. Ultimately it comes down to this: It would take an enormous amount of effort for something else to replicate the power of SMTP and/or NNTP, ergo nothing has achieved that. The open standards mean there are myriad clients available, and no new protocol or system can ever hope to compete with that. ChrisA From travisgriggs at gmail.com Wed Dec 4 11:31:12 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Wed, 4 Dec 2013 08:31:12 -0800 Subject: Managing Google Groups headaches In-Reply-To: <20131204145223.GA7205@gsp.org> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <20131204145223.GA7205@gsp.org> Message-ID: On Dec 4, 2013, at 6:52 AM, Rich Kulawiec wrote: > Yes, I'm > aware of web forums: I've used hundreds of them. They suck. They ALL > suck, they just all suck differently. I could spend the next several > thousand lines explaining why, but instead I'll just abbreviate: they > don't handle threading, they don't let me use my editor of choice, > they don't let me build my own archive that I can search MY way including > when I'm offline, they are brittle and highly vulnerable to abuse > and security breaches, they encourage worst practices in writing > style (including top-posting and full-quoting), they translate poorly > to other formats, they are difficult to archive, they're even more > difficult to migrate (whereas Unix mbox format files from 30 years ago > are still perfectly usable today), they aren't standardized, they > aren't easily scalable, they're overly complex, they don't support > proper quoting, they don't support proper attribution, they can't > be easily forwarded, they...oh, it just goes on. My point being that > there's a reason that the IETF and the W3C and NANOG and lots of other > groups that could use anything they want use mailing lists: they work. One of the best rants I?ve ever read. Full mental harmonic resonance while I read this. Hope you don?t mind, but I think I?ll be plagiarizing your comments in the future. Maybe I?ll post it on a couple of the web forums I currently have the luxury of regularly hating. From roy at panix.com Wed Dec 4 19:58:54 2013 From: roy at panix.com (Roy Smith) Date: Wed, 04 Dec 2013 19:58:54 -0500 Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> Message-ID: In article , Rich Kulawiec wrote: > Yes, I'm > aware of web forums: I've used hundreds of them. They suck. They ALL > suck, they just all suck differently. I could spend the next several > thousand lines explaining why, but instead I'll just abbreviate: they > don't handle threading, they don't let me use my editor of choice, > they don't let me build my own archive that I can search MY way including > when I'm offline, they are brittle and highly vulnerable to abuse > and security breaches, they encourage worst practices in writing > style (including top-posting and full-quoting), they translate poorly > to other formats, they are difficult to archive, they're even more > difficult to migrate (whereas Unix mbox format files from 30 years ago > are still perfectly usable today), they aren't standardized, they > aren't easily scalable, they're overly complex, they don't support > proper quoting, they don't support proper attribution, they can't > be easily forwarded, they...oh, it just goes on. The real problem with web forums is they conflate transport and presentation into a single opaque blob, and are pretty much universally designed to be a closed system. Mail and usenet were both engineered to make a sharp division between transport and presentation, which meant it was possible to evolve each at their own pace. Mostly that meant people could go off and develop new client applications which interoperated with the existing system. But, it also meant that transport layers could be switched out (as when NNTP gradually, but inexorably, replaced UUCP as the primary usenet transport layer). From rustompmody at gmail.com Fri Dec 6 02:13:54 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 5 Dec 2013 23:13:54 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> Message-ID: <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> On Thursday, December 5, 2013 6:28:54 AM UTC+5:30, Roy Smith wrote: > Rich Kulawiec wrote: > > Yes, I'm > > aware of web forums: I've used hundreds of them. They suck. They ALL > > suck, they just all suck differently. I could spend the next several > > thousand lines explaining why, but instead I'll just abbreviate: they > > don't handle threading, they don't let me use my editor of choice, > > they don't let me build my own archive that I can search MY way including > > when I'm offline, they are brittle and highly vulnerable to abuse > > and security breaches, they encourage worst practices in writing > > style (including top-posting and full-quoting), they translate poorly > > to other formats, they are difficult to archive, they're even more > > difficult to migrate (whereas Unix mbox format files from 30 years ago > > are still perfectly usable today), they aren't standardized, they > > aren't easily scalable, they're overly complex, they don't support > > proper quoting, they don't support proper attribution, they can't > > be easily forwarded, they...oh, it just goes on. > The real problem with web forums is they conflate transport and > presentation into a single opaque blob, and are pretty much universally > designed to be a closed system. Mail and usenet were both engineered to > make a sharp division between transport and presentation, which meant it > was possible to evolve each at their own pace. > Mostly that meant people could go off and develop new client > applications which interoperated with the existing system. But, it also > meant that transport layers could be switched out (as when NNTP > gradually, but inexorably, replaced UUCP as the primary usenet transport > layer). There is a deep assumption hovering round-about the above -- what I will call the 'Unix assumption(s)'. But before that, just a check on terminology. By 'presentation' you mean what people normally call 'mail-clients': thunderbird, mutt etc. And by 'transport' you mean sendmail, exim, qmail etc etc -- what normally are called 'mail-servers.' Right?? Assuming this is the intended meaning of the terminology (yeah its clearer terminology than the usual and yeah Im also a 'Unix-guy'), here's the 'Unix-assumption': - human communication? (is not very different from) - machine communication? (can be done by) - text? (for which) - ASCII is fine? (which is just) - bytes? (inside/between byte-memory-organized) - von Neumann computers To the extent that these assumptions are invalid, the 'opaque-blob' may well be preferable. From roy at panix.com Fri Dec 6 02:36:30 2013 From: roy at panix.com (Roy Smith) Date: Fri, 06 Dec 2013 02:36:30 -0500 Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: In article <51007240-6bc9-4f0b-9937-4883bcc0ceb6 at googlegroups.com>, rusi wrote: > On Thursday, December 5, 2013 6:28:54 AM UTC+5:30, Roy Smith wrote: > > The real problem with web forums is they conflate transport and > > presentation into a single opaque blob, and are pretty much universally > > designed to be a closed system. Mail and usenet were both engineered to > > make a sharp division between transport and presentation, which meant it > > was possible to evolve each at their own pace. > > > Mostly that meant people could go off and develop new client > > applications which interoperated with the existing system. But, it also > > meant that transport layers could be switched out (as when NNTP > > gradually, but inexorably, replaced UUCP as the primary usenet transport > > layer). > > There is a deep assumption hovering round-about the above -- what I > will call the 'Unix assumption(s)'. It has nothing to do with Unix. The separation of transport from presentation is just as valid on Windows, Mac, etc. > But before that, just a check on > terminology. By 'presentation' you mean what people normally call > 'mail-clients': thunderbird, mutt etc. And by 'transport' you mean > sendmail, exim, qmail etc etc -- what normally are called > 'mail-servers.' Right?? Yes. > Assuming this is the intended meaning of the terminology (yeah its > clearer terminology than the usual and yeah Im also a 'Unix-guy'), > here's the 'Unix-assumption': > > - human communication? > (is not very different from) > - machine communication? > (can be done by) > - text? > (for which) > - ASCII is fine? > (which is just) > - bytes? > (inside/between byte-memory-organized) > - von Neumann computers > > To the extent that these assumptions are invalid, the 'opaque-blob' > may well be preferable. I think you're off on the wrong track here. This has nothing to do with plain text (ascii or otherwise). It has to do with divorcing how you store and transport messages (be they plain text, HTML, or whatever) from how a user interacts with them. Take something like Wikipedia (by which, I really mean, MediaWiki, which is the underlying software package). Most people think of Wikipedia as a web site. But, there's another layer below that which lets you get access to the contents of articles, navigate all the rich connections like category trees, and all sorts of metadata like edit histories. Which means, if I wanted to (and many examples of this exist), I can write my own client which presents the same information in different ways. From rustompmody at gmail.com Fri Dec 6 08:03:57 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 05:03:57 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: On Friday, December 6, 2013 1:06:30 PM UTC+5:30, Roy Smith wrote: > Rusi wrote: > > On Thursday, December 5, 2013 6:28:54 AM UTC+5:30, Roy Smith wrote: > > > The real problem with web forums is they conflate transport and > > > presentation into a single opaque blob, and are pretty much universally > > > designed to be a closed system. Mail and usenet were both engineered to > > > make a sharp division between transport and presentation, which meant it > > > was possible to evolve each at their own pace. > > > Mostly that meant people could go off and develop new client > > > applications which interoperated with the existing system. But, it also > > > meant that transport layers could be switched out (as when NNTP > > > gradually, but inexorably, replaced UUCP as the primary usenet transport > > > layer). > > There is a deep assumption hovering round-about the above -- what I > > will call the 'Unix assumption(s)'. > It has nothing to do with Unix. The separation of transport from > presentation is just as valid on Windows, Mac, etc. > > But before that, just a check on > > terminology. By 'presentation' you mean what people normally call > > 'mail-clients': thunderbird, mutt etc. And by 'transport' you mean > > sendmail, exim, qmail etc etc -- what normally are called > > 'mail-servers.' Right?? > Yes. > > Assuming this is the intended meaning of the terminology (yeah its > > clearer terminology than the usual and yeah Im also a 'Unix-guy'), > > here's the 'Unix-assumption': > > - human communication? > > (is not very different from) > > - machine communication? > > (can be done by) > > - text? > > (for which) > > - ASCII is fine? > > (which is just) > > - bytes? > > (inside/between byte-memory-organized) > > - von Neumann computers > > To the extent that these assumptions are invalid, the 'opaque-blob' > > may well be preferable. > I think you're off on the wrong track here. This has nothing to do with > plain text (ascii or otherwise). It has to do with divorcing how you > store and transport messages (be they plain text, HTML, or whatever) > from how a user interacts with them. Evidently (and completely inadvertently) this exchange has just illustrated one of the inadmissable assumptions: "unicode as a medium is universal in the same way that ASCII used to be" I wrote a number of ellipsis characters ie codepoint 2026 as in: - human communication? (is not very different from) - machine communication? Somewhere between my sending and your quoting those ellipses became the replacement character FFFD > > - human communication? > > (is not very different from) > > - machine communication? Leaving aside whose fault this is (very likely buggy google groups), this mojibaking cannot happen if the assumption "All text is ASCII" were to uniformly hold. Of course with unicode also this can be made to not happen, but that is fragile and error-prone. And that is because ASCII (not extended) is ONE thing in a way that unicode is hopelessly a motley inconsistent variety. With unicode there are in-memory formats, transportation formats eg UTF-8, strange beasties like FSR (which then hopelessly and inveterately tickle our resident trolls!) multi-layer encodings (in html), BOMS and unnecessary/inconsistent BOMS (in microsoft-notepad). With ASCII, ASCII is ASCII; ie "ABC" is 65,66,67 whether its in-core, in-file, in-pipe or whatever. Ok there are a few wrinkles to this eg. the null-terminator in C-strings. I think this is the exception to the rule that in classic Unix, ASCII is completely inter-operable and therefore a universal data-structure for inter-process or inter-machine communication. It is this universal data structure that makes classic unix pipes and filters possible and easy (of which your separation of presentation and transportation is just one case). Give it up and the composability goes with it. Go up from the ASCII -> Unicode level to the plain-text -> hypertext (aka html) level and these composability problems hit with redoubled force. > Take something like Wikipedia (by which, I really mean, MediaWiki, which > is the underlying software package). Most people think of Wikipedia as > a web site. But, there's another layer below that which lets you get > access to the contents of articles, navigate all the rich connections > like category trees, and all sorts of metadata like edit histories. > Which means, if I wanted to (and many examples of this exist), I can > write my own client which presents the same information in different > ways. Not sure whats your point. Html is a universal data-structuring format -- ok for presentation, bad for data-structuring SQL databases (assuming thats the mediawiki backend) is another -- ok for data-structuring bad for presentation. Mediawiki mediates between the two formats. Beyond that I lost you... what are you trying to say?? From rosuav at gmail.com Fri Dec 6 08:19:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 00:19:04 +1100 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: On Sat, Dec 7, 2013 at 12:03 AM, rusi wrote: > SQL databases (assuming thats the mediawiki backend) is another -- ok for > data-structuring bad for presentation. No, SQL databases don't store structured text. MediaWiki just stores a single blob (not in the database sense of that word) of text. ChrisA From rustompmody at gmail.com Fri Dec 6 08:32:35 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 05:32:35 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: <10982d24-d47c-4a99-a93a-360fbe6b52ed@googlegroups.com> On Friday, December 6, 2013 6:49:04 PM UTC+5:30, Chris Angelico wrote: > On Sat, Dec 7, 2013 at 12:03 AM, rusi wrote: > > SQL databases (assuming thats the mediawiki backend) is another -- ok for > > data-structuring bad for presentation. > No, SQL databases don't store structured text. MediaWiki just stores a > single blob (not in the database sense of that word) of text. I guess we are using 'structured' in different ways. All I am saying is that mediawiki which seems to present as html, actually stores its stuff as SQL -- nothing more or less structured than the schemas here: http://www.mediawiki.org/wiki/Manual:MediaWiki_architecture#Database_and_text_storage From rosuav at gmail.com Fri Dec 6 08:48:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 00:48:19 +1100 Subject: Managing Google Groups headaches In-Reply-To: <10982d24-d47c-4a99-a93a-360fbe6b52ed@googlegroups.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <10982d24-d47c-4a99-a93a-360fbe6b52ed@googlegroups.com> Message-ID: On Sat, Dec 7, 2013 at 12:32 AM, rusi wrote: > I guess we are using 'structured' in different ways. All I am saying > is that mediawiki which seems to present as html, actually stores its > stuff as SQL -- nothing more or less structured than the schemas here: > http://www.mediawiki.org/wiki/Manual:MediaWiki_architecture#Database_and_text_storage Yeah, but the structure is all about the metadata. Ultimately, there's one single text field containing the entire content as you would see it in the page editor: wiki markup in straight text. MediaWiki uses an SQL database to store that lump of text, but ultimately the relationship is between wikitext and HTML, no SQL involvement. Wiki markup is reasonable for text structuring. (Not for generic data structuring, but it's decent for text.) Same with reStructuredText, used for PEPs. An SQL database is a good way to store mappings of "this key, this tuple of data" and retrieve them conveniently, including (and this is the bit that's more complicated in a straight Python dictionary) using any value out of the tuple as the key, and (and this is where a dict *really* can't hack it) storing/retrieving more data than fits in memory. The two are orthogonal. Your point is better supported by wikitext than by SQL, here, except that there aren't fifty other systems that parse and display wikitext. In fact, what you're suggesting is a good argument for deprecating HTML email in favour of RST email, and using docutils to render the result either as HTML (for webmail users) or as some other format. And I wouldn't be against that :) But good luck convincing the world that Microsoft Outlook is doing the wrong thing. ChrisA From rustompmody at gmail.com Fri Dec 6 09:11:23 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 06:11:23 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <10982d24-d47c-4a99-a93a-360fbe6b52ed@googlegroups.com> Message-ID: On Friday, December 6, 2013 7:18:19 PM UTC+5:30, Chris Angelico wrote: > On Sat, Dec 7, 2013 at 12:32 AM, rusi wrote: > > I guess we are using 'structured' in different ways. All I am saying > > is that mediawiki which seems to present as html, actually stores its > > stuff as SQL -- nothing more or less structured than the schemas here: > > http://www.mediawiki.org/wiki/Manual:MediaWiki_architecture#Database_and_text_storage > Yeah, but the structure is all about the metadata. Ok (I'd drop the 'all') > Ultimately, there's one single text field containing the entire content Right > as you would see it in the page editor: wiki markup in straight text. Aha! There you are! Its 'page editor' here and not the html which 'display source' (control-u) which a browser would show. And wikimedia is the software that mediates. The usual direction (seen by users of wikipedia) is that wikimedia takes this text, along with the other unrelated (metadata?) seen around -- sidebar, tabs etc, css settings and munges it all into html The other direction (seen by editors of wikipedia) is that you edit a page and that page and history etc will show the changes, reflecting the fact that the SQL content has changed. > MediaWiki uses an SQL database to store that lump of text, but > ultimately the relationship is between wikitext and HTML, no SQL > involvement. Dunno what you mean. Every time someone browses wikipedia, things are getting pulled out of the SQL and munged into the html (s)he sees. From rosuav at gmail.com Fri Dec 6 09:51:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 01:51:13 +1100 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <10982d24-d47c-4a99-a93a-360fbe6b52ed@googlegroups.com> Message-ID: On Sat, Dec 7, 2013 at 1:11 AM, rusi wrote: > Aha! There you are! Its 'page editor' here and not the html which > 'display source' (control-u) which a browser would show. And wikimedia > is the software that mediates. > > The usual direction (seen by users of wikipedia) is that wikimedia > takes this text, along with the other unrelated (metadata?) seen > around -- sidebar, tabs etc, css settings and munges it all into html > > The other direction (seen by editors of wikipedia) is that you edit a > page and that page and history etc will show the changes, > reflecting the fact that the SQL content has changed. MediaWiki is fundamentally very similar to a structure that I'm trying to deploy for a community web site that I host, approximately thus: * A git repository stores a bunch of RST files * A script auto-generates index files based on the presence of certain file names, and renders via rst2html * The HTML pages are served as static content MediaWiki is like this: * Each page has a history, represented by a series of state snapshots of wikitext * On display, the wikitext is converted to HTML and served. The main difference is that MediaWiki is optimized for rapid and constant editing, where what I'm pushing for is optimized for less common edits that might span multiple files. (MW has no facility for atomically changing multiple pages, and atomically reverting those changes, and so on. Each page stands alone.) They're still broadly doing the same thing: storing marked-up text and rendering HTML. The fact that one uses an SQL database and the other uses a git repository is actually quite insignificant - it's as significant as the choice of whether to store your data on a hard disk or an SSD. The system is no different. >> MediaWiki uses an SQL database to store that lump of text, but >> ultimately the relationship is between wikitext and HTML, no SQL >> involvement. > > Dunno what you mean. Every time someone browses wikipedia, things are > getting pulled out of the SQL and munged into the html (s)he sees. Yes, but that's just mechanics. The fact that the PHP scripts to operate Wikipedia are being pulled off a file system doesn't mean that MediaWiki is an ext3-to-HTML renderer. It's a wikitext-to-HTML renderer. Anyway. As I said, your point is still mostly there, as long as you use wikitext rather than SQL. ChrisA From steve+comp.lang.python at pearwood.info Fri Dec 6 14:00:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Dec 2013 19:00:18 GMT Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Dec 2013 05:03:57 -0800, rusi wrote: > Evidently (and completely inadvertently) this exchange has just > illustrated one of the inadmissable assumptions: > > "unicode as a medium is universal in the same way that ASCII used to be" Ironically, your post was not Unicode. Seriously. I am 100% serious. Your post was sent using a legacy encoding, Windows-1252, also known as CP-1252, which is most certainly *not* Unicode. Whatever software you used to send the message correctly flagged it with a charset header: Content-Type: text/plain; charset=windows-1252 Alas, the software Roy Smith uses, MT-NewsWatcher, does not handle encodings correctly (or at all!), it screws up the encoding then sends a reply with no charset line at all. This is one bug that cannot be blamed on Google Groups -- or on Unicode. > I wrote a number of ellipsis characters ie codepoint 2026 as in: Actually you didn't. You wrote a number of ellipsis characters, hex byte \x85 (decimal 133), in the CP1252 charset. That happens to be mapped to code point U+2026 in Unicode, but the two are as distinct as ASCII and EBCDIC. > Somewhere between my sending and your quoting those ellipses became the > replacement character FFFD Yes, it appears that MT-NewsWatcher is *deeply, deeply* confused about encodings and character sets. It doesn't just assume things are ASCII, but makes a half-hearted attempt to be charset-aware, but badly. I can only imagine that it was written back in the Dark Ages where there were a lot of different charsets in use but no conventions for specifying which charset was in use. Or perhaps the author was smoking crack while coding. > Leaving aside whose fault this is (very likely buggy google groups), > this mojibaking cannot happen if the assumption "All text is ASCII" were > to uniformly hold. This is incorrect. People forget that ASCII has evolved since the first version of the standard in 1963. There have actually been five versions of the ASCII standard, plus one unpublished version. (And that's not including the things which are frequently called ASCII but aren't.) ASCII-1963 didn't even include lowercase letters. It is also missing some graphic characters like braces, and included at least two characters no longer used, the up-arrow and left-arrow. The control characters were also significantly different from today. ASCII-1965 was unpublished and unused. I don't know the details of what it changed. ASCII-1967 is a lot closer to the ASCII in use today. It made considerable changes to the control characters, moving, adding, removing, or renaming at least half a dozen control characters. It officially added lowercase letters, braces, and some others. It replaced the up-arrow character with the caret and the left-arrow with the underscore. It was ambiguous, allowing variations and substitutions, e.g.: - character 33 was permitted to be either the exclamation mark ! or the logical OR symbol | - consequently character 124 (vertical bar) was always displayed as a broken bar ?, which explains why even today many keyboards show it that way - character 35 was permitted to be either the number sign # or the pound sign ? - character 94 could be either a caret ^ or a logical NOT ? Even the humble comma could be pressed into service as a cedilla. ASCII-1968 didn't change any characters, but allowed the use of LF on its own. Previously, you had to use either LF/CR or CR/LF as newline. ASCII-1977 removed the ambiguities from the 1967 standard. The most recent version is ASCII-1986 (also known as ANSI X3.4-1986). Unfortunately I haven't been able to find out what changes were made -- I presume they were minor, and didn't affect the character set. So as you can see, even with actual ASCII, you can have mojibake. It's just not normally called that. But if you are given an arbitrary ASCII file of unknown age, containing code 94, how can you be sure it was intended as a caret rather than a logical NOT symbol? You can't. Then there are at least 30 official variations of ASCII, strictly speaking part of ISO-646. These 7-bit codes were commonly called "ASCII" by their users, despite the differences, e.g. replacing the dollar sign $ with the international currency sign ?, or replacing the left brace { with the letter s with caron ?. One consequence of this is that the MIME type for ASCII text is called "US ASCII", despite the redundancy, because many people expect "ASCII" alone to mean whatever national variation they are used to. But it gets worse: there are proprietary variations on ASCII which are commonly called "ASCII" but aren't, including dozens of 8-bit so-called "extended ASCII" character sets, which is where the problems *really* pile up. Invariably back in the 1980s and early 1990s people used to call these "ASCII" no matter that they used 8-bits and contained anything up to 256 characters. Just because somebody calls something "ASCII", doesn't make it so; even if it is ASCII, doesn't mean you know which version of ASCII; even if you know which version, doesn't mean you know how to interpret certain codes. It simply is *wrong* to think that "good ol' plain ASCII text" is unambiguous and devoid of problems. > With unicode there are in-memory formats, transportation formats eg > UTF-8, And the same applies to ASCII. ASCII is a *seven-bit code*. It will work fine on computers where the word-size is seven bits. If the word-size is eight bits, or more, you have to pad the ASCII code. How do you do that? Pad the most-significant end or the least significant end? That's a choice there. How do you pad it, with a zero or a one? That's another choice. If your word-size is more than eight bits, you might even pad *both* ends. In C, a char is defined as the smallest addressable unit of the machine that can contain basic character set, not necessarily eight bits. Implementations of C and C++ sometimes reserve 8, 9, 16, 32, or 36 bits as a "byte" and/or char. Your in-memory representation of ASCII "a" could easily end up as bits 001100001 or 0000000001100001. And then there is the question of whether ASCII characters should be Big Endian or Little Endian. I'm referring here to bit endianness, rather than bytes: should character 'a' be represented as bits 1100001 (most significant bit to the left) or 1000011 (least significant bit to the left)? This may be relevant with certain networking protocols. Not all networking protocols are big-endian, nor are all processors. The Ada programming language even supports both bit orders. When transmitting ASCII characters, the networking protocol could include various start and stop bits and parity codes. A single 7-bit ASCII character might be anything up to 12 bits in length on the wire. It is simply naive to imagine that the transmission of ASCII codes is the same as the in-memory or on-disk storage of ASCII. You're lucky to be active in a time when most common processors have standardized on a single bit-order, and when most (but not all) network protocols have done the same. But that doesn't mean that these issues don't exist for ASCII. If you get a message that purports to be ASCII text but looks like this: "\tS\x1b\x1b{\x01u{'\x1b\x13!" you should suspect strongly that it is "Hello World!" which has been accidentally bit-reversed by some rogue piece of hardware. -- Steven From gheskett at wdtv.com Fri Dec 6 14:34:54 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 6 Dec 2013 14:34:54 -0500 Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] In-Reply-To: <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201312061434.54512.gheskett@wdtv.com> On Friday 06 December 2013 14:30:06 Steven D'Aprano did opine: > On Fri, 06 Dec 2013 05:03:57 -0800, rusi wrote: > > Evidently (and completely inadvertently) this exchange has just > > illustrated one of the inadmissable assumptions: > > > > "unicode as a medium is universal in the same way that ASCII used to > > be" > > Ironically, your post was not Unicode. > > Seriously. I am 100% serious. > > Your post was sent using a legacy encoding, Windows-1252, also known as > CP-1252, which is most certainly *not* Unicode. Whatever software you > used to send the message correctly flagged it with a charset header: > > Content-Type: text/plain; charset=windows-1252 > > Alas, the software Roy Smith uses, MT-NewsWatcher, does not handle > encodings correctly (or at all!), it screws up the encoding then sends a > reply with no charset line at all. This is one bug that cannot be blamed > on Google Groups -- or on Unicode. > > > I wrote a number of ellipsis characters ie codepoint 2026 as in: > Actually you didn't. You wrote a number of ellipsis characters, hex byte > \x85 (decimal 133), in the CP1252 charset. That happens to be mapped to > code point U+2026 in Unicode, but the two are as distinct as ASCII and > EBCDIC. > > > Somewhere between my sending and your quoting those ellipses became > > the replacement character FFFD > > Yes, it appears that MT-NewsWatcher is *deeply, deeply* confused about > encodings and character sets. It doesn't just assume things are ASCII, > but makes a half-hearted attempt to be charset-aware, but badly. I can > only imagine that it was written back in the Dark Ages where there were > a lot of different charsets in use but no conventions for specifying > which charset was in use. Or perhaps the author was smoking crack while > coding. > > > Leaving aside whose fault this is (very likely buggy google groups), > > this mojibaking cannot happen if the assumption "All text is ASCII" > > were to uniformly hold. > > This is incorrect. People forget that ASCII has evolved since the first > version of the standard in 1963. There have actually been five versions > of the ASCII standard, plus one unpublished version. (And that's not > including the things which are frequently called ASCII but aren't.) > > ASCII-1963 didn't even include lowercase letters. It is also missing > some graphic characters like braces, and included at least two > characters no longer used, the up-arrow and left-arrow. The control > characters were also significantly different from today. > > ASCII-1965 was unpublished and unused. I don't know the details of what > it changed. > > ASCII-1967 is a lot closer to the ASCII in use today. It made > considerable changes to the control characters, moving, adding, > removing, or renaming at least half a dozen control characters. It > officially added lowercase letters, braces, and some others. It > replaced the up-arrow character with the caret and the left-arrow with > the underscore. It was ambiguous, allowing variations and > substitutions, e.g.: > > - character 33 was permitted to be either the exclamation > mark ! or the logical OR symbol | > > - consequently character 124 (vertical bar) was always > displayed as a broken bar ??, which explains why even today > many keyboards show it that way > > - character 35 was permitted to be either the number sign # or > the pound sign ?? > > - character 94 could be either a caret ^ or a logical NOT ?? > > Even the humble comma could be pressed into service as a cedilla. > > ASCII-1968 didn't change any characters, but allowed the use of LF on > its own. Previously, you had to use either LF/CR or CR/LF as newline. > > ASCII-1977 removed the ambiguities from the 1967 standard. > > The most recent version is ASCII-1986 (also known as ANSI X3.4-1986). > Unfortunately I haven't been able to find out what changes were made -- > I presume they were minor, and didn't affect the character set. > > So as you can see, even with actual ASCII, you can have mojibake. It's > just not normally called that. But if you are given an arbitrary ASCII > file of unknown age, containing code 94, how can you be sure it was > intended as a caret rather than a logical NOT symbol? You can't. > > Then there are at least 30 official variations of ASCII, strictly > speaking part of ISO-646. These 7-bit codes were commonly called "ASCII" > by their users, despite the differences, e.g. replacing the dollar sign > $ with the international currency sign ??, or replacing the left brace > { with the letter s with caron ??. > > One consequence of this is that the MIME type for ASCII text is called > "US ASCII", despite the redundancy, because many people expect "ASCII" > alone to mean whatever national variation they are used to. > > But it gets worse: there are proprietary variations on ASCII which are > commonly called "ASCII" but aren't, including dozens of 8-bit so-called > "extended ASCII" character sets, which is where the problems *really* > pile up. Invariably back in the 1980s and early 1990s people used to > call these "ASCII" no matter that they used 8-bits and contained > anything up to 256 characters. > > Just because somebody calls something "ASCII", doesn't make it so; even > if it is ASCII, doesn't mean you know which version of ASCII; even if > you know which version, doesn't mean you know how to interpret certain > codes. It simply is *wrong* to think that "good ol' plain ASCII text" > is unambiguous and devoid of problems. > > > With unicode there are in-memory formats, transportation formats eg > > UTF-8, > > And the same applies to ASCII. > > ASCII is a *seven-bit code*. It will work fine on computers where the > word-size is seven bits. If the word-size is eight bits, or more, you > have to pad the ASCII code. How do you do that? Pad the most-significant > end or the least significant end? That's a choice there. How do you pad > it, with a zero or a one? That's another choice. If your word-size is > more than eight bits, you might even pad *both* ends. > > In C, a char is defined as the smallest addressable unit of the machine > that can contain basic character set, not necessarily eight bits. > Implementations of C and C++ sometimes reserve 8, 9, 16, 32, or 36 bits > as a "byte" and/or char. Your in-memory representation of ASCII "a" > could easily end up as bits 001100001 or 0000000001100001. > > And then there is the question of whether ASCII characters should be Big > Endian or Little Endian. I'm referring here to bit endianness, rather > than bytes: should character 'a' be represented as bits 1100001 (most > significant bit to the left) or 1000011 (least significant bit to the > left)? This may be relevant with certain networking protocols. Not all > networking protocols are big-endian, nor are all processors. The Ada > programming language even supports both bit orders. > > When transmitting ASCII characters, the networking protocol could > include various start and stop bits and parity codes. A single 7-bit > ASCII character might be anything up to 12 bits in length on the wire. > It is simply naive to imagine that the transmission of ASCII codes is > the same as the in-memory or on-disk storage of ASCII. > > You're lucky to be active in a time when most common processors have > standardized on a single bit-order, and when most (but not all) network > protocols have done the same. But that doesn't mean that these issues > don't exist for ASCII. If you get a message that purports to be ASCII > text but looks like this: > > "\tS\x1b\x1b{\x01u{'\x1b\x13!" > > you should suspect strongly that it is "Hello World!" which has been > accidentally bit-reversed by some rogue piece of hardware. You can lay a lot of the ASCII ambiguity on D.E.C. and their vt series terminals, anything newer than a vt100 made liberal use of the msbit in a character. Having written an emulator for the vt-220, I can testify that really getting it right, was a right pain in the ass. And then I added zmodem triggers and detections. Cheers, Gene -- "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 Mother Earth is not flat! A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From roy at panix.com Fri Dec 6 15:54:03 2013 From: roy at panix.com (Roy Smith) Date: Fri, 6 Dec 2013 20:54:03 +0000 (UTC) Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano pearwood.info> writes: > Yes, it appears that MT-NewsWatcher is *deeply, deeply* confused about > encodings and character sets. It doesn't just assume things are ASCII, > but makes a half-hearted attempt to be charset-aware, but badly. I can > only imagine that it was written back in the Dark Ages Indeed. The basic codebase probably goes back 20 years. I'm posting this from gmane, just so people don't think I'm a total luddite. > When transmitting ASCII characters, the networking protocol could include > various start and stop bits and parity codes. A single 7-bit ASCII > character might be anything up to 12 bits in length on the wire. Not to mention that some really old hardware used 1.5 stop bits! From rosuav at gmail.com Fri Dec 6 18:42:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 10:42:13 +1100 Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] In-Reply-To: <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Dec 7, 2013 at 6:00 AM, Steven D'Aprano wrote: > - character 33 was permitted to be either the exclamation > mark ! or the logical OR symbol | > > - consequently character 124 (vertical bar) was always > displayed as a broken bar ?, which explains why even today > many keyboards show it that way > > - character 35 was permitted to be either the number sign # or > the pound sign ? > > - character 94 could be either a caret ^ or a logical NOT ? Yeah, good fun stuff. I first met several of these ambiguities in the OS/2 REXX documentation, which detailed the language's operators by specifying their byte values as well as their characters - for instance, this quote from the docs (yeah, I still have it all here): """ Note: Depending upon your Personal System keyboard and the code page you are using, you may not have the solid vertical bar to select. For this reason, REXX also recognizes the use of the split vertical bar as a logical OR symbol. Some keyboards may have both characters. If so, they are not interchangeable; only the character that is equal to the ASCII value of 124 works as the logical OR. This type of mismatch can also cause the character on your screen to be different from the character on your keyboard. """ (The front material on the docs says "(C) Copyright IBM Corp. 1987, 1994. All Rights Reserved.") It says "ASCII value" where on this list we would be more likely to call it "byte value", and I'd prefer to say "represented by" rather than "equal to", but nonetheless, this is still clearly distinguishing characters and bytes. The language spec is on characters, but ultimately the interpreter is going to be looking at bytes, so when there's a problem, it's byte 124 that's the one defined as logical OR. Oh, and note the copyright date. The byte/char distinction isn't new. ChrisA From rustompmody at gmail.com Fri Dec 6 21:33:39 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 18:33:39 -0800 (PST) Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] In-Reply-To: <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <41e2ac37-d751-43b4-a720-e8da58429420@googlegroups.com> On Saturday, December 7, 2013 12:30:18 AM UTC+5:30, Steven D'Aprano wrote: > On Fri, 06 Dec 2013 05:03:57 -0800, rusi wrote: > > Evidently (and completely inadvertently) this exchange has just > > illustrated one of the inadmissable assumptions: > > "unicode as a medium is universal in the same way that ASCII used to be" > Ironically, your post was not Unicode. > Seriously. I am 100% serious. > Your post was sent using a legacy encoding, Windows-1252, also known as > CP-1252, which is most certainly *not* Unicode. Whatever software you > used to send the message correctly flagged it with a charset header: > Content-Type: text/plain; charset=windows-1252 > Alas, the software Roy Smith uses, MT-NewsWatcher, does not handle > encodings correctly (or at all!), it screws up the encoding then sends a > reply with no charset line at all. This is one bug that cannot be blamed > on Google Groups -- or on Unicode. > > I wrote a number of ellipsis characters ie codepoint 2026 as in: > Actually you didn't. You wrote a number of ellipsis characters, hex byte > \x85 (decimal 133), in the CP1252 charset. That happens to be mapped to > code point U+2026 in Unicode, but the two are as distinct as ASCII and > EBCDIC. > > Somewhere between my sending and your quoting those ellipses became the > > replacement character FFFD > Yes, it appears that MT-NewsWatcher is *deeply, deeply* confused about > encodings and character sets. It doesn't just assume things are ASCII, > but makes a half-hearted attempt to be charset-aware, but badly. I can > only imagine that it was written back in the Dark Ages where there were a > lot of different charsets in use but no conventions for specifying which > charset was in use. Or perhaps the author was smoking crack while coding. > > Leaving aside whose fault this is (very likely buggy google groups), > > this mojibaking cannot happen if the assumption "All text is ASCII" were > > to uniformly hold. > This is incorrect. People forget that ASCII has evolved since the first > version of the standard in 1963. There have actually been five versions > of the ASCII standard, plus one unpublished version. (And that's not > including the things which are frequently called ASCII but aren't.) > ASCII-1963 didn't even include lowercase letters. It is also missing some > graphic characters like braces, and included at least two characters no > longer used, the up-arrow and left-arrow. The control characters were > also significantly different from today. > ASCII-1965 was unpublished and unused. I don't know the details of what > it changed. > ASCII-1967 is a lot closer to the ASCII in use today. It made > considerable changes to the control characters, moving, adding, removing, > or renaming at least half a dozen control characters. It officially added > lowercase letters, braces, and some others. It replaced the up-arrow > character with the caret and the left-arrow with the underscore. It was > ambiguous, allowing variations and substitutions, e.g.: > - character 33 was permitted to be either the exclamation > mark ! or the logical OR symbol | > - consequently character 124 (vertical bar) was always > displayed as a broken bar ?, which explains why even today > many keyboards show it that way > - character 35 was permitted to be either the number sign # or > the pound sign ? > - character 94 could be either a caret ^ or a logical NOT ? > Even the humble comma could be pressed into service as a cedilla. > ASCII-1968 didn't change any characters, but allowed the use of LF on its > own. Previously, you had to use either LF/CR or CR/LF as newline. > ASCII-1977 removed the ambiguities from the 1967 standard. > The most recent version is ASCII-1986 (also known as ANSI X3.4-1986). > Unfortunately I haven't been able to find out what changes were made -- I > presume they were minor, and didn't affect the character set. > So as you can see, even with actual ASCII, you can have mojibake. It's > just not normally called that. But if you are given an arbitrary ASCII > file of unknown age, containing code 94, how can you be sure it was > intended as a caret rather than a logical NOT symbol? You can't. > Then there are at least 30 official variations of ASCII, strictly > speaking part of ISO-646. These 7-bit codes were commonly called "ASCII" > by their users, despite the differences, e.g. replacing the dollar sign $ > with the international currency sign ?, or replacing the left brace > { with the letter s with caron ?. > One consequence of this is that the MIME type for ASCII text is called > "US ASCII", despite the redundancy, because many people expect "ASCII" > alone to mean whatever national variation they are used to. > But it gets worse: there are proprietary variations on ASCII which are > commonly called "ASCII" but aren't, including dozens of 8-bit so-called > "extended ASCII" character sets, which is where the problems *really* > pile up. Invariably back in the 1980s and early 1990s people used to call > these "ASCII" no matter that they used 8-bits and contained anything up > to 256 characters. > Just because somebody calls something "ASCII", doesn't make it so; even > if it is ASCII, doesn't mean you know which version of ASCII; even if you > know which version, doesn't mean you know how to interpret certain codes. > It simply is *wrong* to think that "good ol' plain ASCII text" is > unambiguous and devoid of problems. > > With unicode there are in-memory formats, transportation formats eg > > UTF-8, > And the same applies to ASCII. > ASCII is a *seven-bit code*. It will work fine on computers where the > word-size is seven bits. If the word-size is eight bits, or more, you > have to pad the ASCII code. How do you do that? Pad the most-significant > end or the least significant end? That's a choice there. How do you pad > it, with a zero or a one? That's another choice. If your word-size is > more than eight bits, you might even pad *both* ends. > In C, a char is defined as the smallest addressable unit of the machine > that can contain basic character set, not necessarily eight bits. > Implementations of C and C++ sometimes reserve 8, 9, 16, 32, or 36 bits > as a "byte" and/or char. Your in-memory representation of ASCII "a" could > easily end up as bits 001100001 or 0000000001100001. > And then there is the question of whether ASCII characters should be Big > Endian or Little Endian. I'm referring here to bit endianness, rather > than bytes: should character 'a' be represented as bits 1100001 (most > significant bit to the left) or 1000011 (least significant bit to the > left)? This may be relevant with certain networking protocols. Not all > networking protocols are big-endian, nor are all processors. The Ada > programming language even supports both bit orders. > When transmitting ASCII characters, the networking protocol could include > various start and stop bits and parity codes. A single 7-bit ASCII > character might be anything up to 12 bits in length on the wire. It is > simply naive to imagine that the transmission of ASCII codes is the same > as the in-memory or on-disk storage of ASCII. > You're lucky to be active in a time when most common processors have > standardized on a single bit-order, and when most (but not all) network > protocols have done the same. But that doesn't mean that these issues > don't exist for ASCII. If you get a message that purports to be ASCII > text but looks like this: > "\tS\x1b\x1b{\x01u{'\x1b\x13!" > you should suspect strongly that it is "Hello World!" which has been > accidentally bit-reversed by some rogue piece of hardware. OOf! Thats a lot of data to digest! Thanks anyway. There's one thing I want to get into: > Your post was sent using a legacy encoding, Windows-1252, also known as > CP-1252, which is most certainly *not* Unicode. Whatever software you > used to send the message correctly flagged it with a charset header: What the hell! I am using firefox 25.0 in debian-testing and posting via GG. $ locale shows me: LANG=en_US.UTF-8 and a bunch of other things all en_US.UTF-8. For the most part when I point FF at any site and go to view -> character-encoding, it says Unicode (UTF-8). However when I go to anything in the python archives: https://mail.python.org/pipermail/python-list/2013-December/ FF shows it as Western (Windows-1252) That seems to suggest that something is not right with the python mailing list config. No?? From rosuav at gmail.com Fri Dec 6 21:41:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 13:41:45 +1100 Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] In-Reply-To: <41e2ac37-d751-43b4-a720-e8da58429420@googlegroups.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <41e2ac37-d751-43b4-a720-e8da58429420@googlegroups.com> Message-ID: On Sat, Dec 7, 2013 at 1:33 PM, rusi wrote: > That seems to suggest that something is not right with the python > mailing list config. No?? If in doubt, blame someone else, eh? I'd first check what your browser's actually sending. Firebug will help there. See if your form fill-out is encoded as UTF-8 or CP-1252. That's the first step. ChrisA From python at mrabarnett.plus.com Fri Dec 6 22:19:15 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 07 Dec 2013 03:19:15 +0000 Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <41e2ac37-d751-43b4-a720-e8da58429420@googlegroups.com> Message-ID: <52A293B3.4050908@mrabarnett.plus.com> On 07/12/2013 02:41, Chris Angelico wrote: > On Sat, Dec 7, 2013 at 1:33 PM, rusi wrote: >> That seems to suggest that something is not right with the python >> mailing list config. No?? > > If in doubt, blame someone else, eh? > > I'd first check what your browser's actually sending. Firebug will > help there. See if your form fill-out is encoded as UTF-8 or CP-1252. > That's the first step. > Looking back through the thread, it looks like: Roy posted a reply in us-ascii. rusi replied in windows-1252, adding the '?'. Roy replied in us-ascii, but with '?' in place of '?'. rusi replied in utf-8, with '?' in place of '?' From rustompmody at gmail.com Fri Dec 6 22:16:35 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 19:16:35 -0800 (PST) Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <41e2ac37-d751-43b4-a720-e8da58429420@googlegroups.com> Message-ID: On Saturday, December 7, 2013 8:11:45 AM UTC+5:30, Chris Angelico wrote: > On Sat, Dec 7, 2013 at 1:33 PM, rusi wrote: > > That seems to suggest that something is not right with the python > > mailing list config. No?? > If in doubt, blame someone else, eh? > I'd first check what your browser's actually sending. Firebug will > help there. See if your form fill-out is encoded as UTF-8 or CP-1252. > That's the first step. If you give me some tip where to look, I'll do that. But I dont see what this has to do with forms. Everything in the python archive (not just my posts) show as Win 1252 [I checked about 6] Every other page that I checked (most nothing to do with python list, GG etc) show UTF-8. [I checked about 5] None of these checkings had forms to be filled. From rosuav at gmail.com Fri Dec 6 23:08:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 15:08:41 +1100 Subject: ASCII and Unicode [was Re: Managing Google Groups headaches] In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <41e2ac37-d751-43b4-a720-e8da58429420@googlegroups.com> Message-ID: On Sat, Dec 7, 2013 at 2:16 PM, rusi wrote: > On Saturday, December 7, 2013 8:11:45 AM UTC+5:30, Chris Angelico wrote: >> On Sat, Dec 7, 2013 at 1:33 PM, rusi wrote: >> > That seems to suggest that something is not right with the python >> > mailing list config. No?? > >> If in doubt, blame someone else, eh? > >> I'd first check what your browser's actually sending. Firebug will >> help there. See if your form fill-out is encoded as UTF-8 or CP-1252. >> That's the first step. > > If you give me some tip where to look, I'll do that. > But I dont see what this has to do with forms. > Page encodings specify what comes from the server to your browser. Your post went the other way. Tracing the data going back to the server would tell you how it's encoded. ChrisA From pecore at pascolo.net Sat Dec 7 11:05:34 2013 From: pecore at pascolo.net (giacomo boffi) Date: Sat, 07 Dec 2013 17:05:34 +0100 Subject: ASCII and Unicode References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87iov0ir3l.fsf@pascolo.net> Steven D'Aprano writes: > Ironically, your post was not Unicode. [...] Your post was sent > using a legacy encoding, Windows-1252, also known as CP-1252 i access rusi's post using a NNTP server, and in his post i see Content-Type: text/plain; charset=UTF-8 is it possible that what you see is an artifact of the gateway? From rustompmody at gmail.com Sun Dec 8 11:41:10 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 08:41:10 -0800 (PST) Subject: ASCII and Unicode In-Reply-To: <87iov0ir3l.fsf@pascolo.net> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <87iov0ir3l.fsf@pascolo.net> Message-ID: On Saturday, December 7, 2013 9:35:34 PM UTC+5:30, giacomo boffi wrote: > Steven D'Aprano writes: > > Ironically, your post was not Unicode. [...] Your post was sent > > using a legacy encoding, Windows-1252, also known as CP-1252 > i access rusi's post using a NNTP server, > and in his post i see > Content-Type: text/plain; charset=UTF-8 > is it possible that what you see is an artifact > of the gateway? Thanks for checking that! From steve+comp.lang.python at pearwood.info Sun Dec 8 12:22:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2013 17:22:34 GMT Subject: ASCII and Unicode References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <87iov0ir3l.fsf@pascolo.net> Message-ID: <52a4aada$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Dec 2013 17:05:34 +0100, giacomo boffi wrote: > Steven D'Aprano writes: > >> Ironically, your post was not Unicode. [...] Your post was sent using >> a legacy encoding, Windows-1252, also known as CP-1252 > > i access rusi's post using a NNTP server, and in his post i see > > Content-Type: text/plain; charset=UTF-8 But *which post* are you looking at? I have just looked at three posts from him: Rusi's original post, where he used the ellipsis characters: Subject: Re: Managing Google Groups headaches Date: Thu, 5 Dec 2013 23:13:54 -0800 (PST) Content-Type: text/plain; charset=windows-1252 Then his reply to me: Subject: Re: ASCII and Unicode [was Re: Managing Google Groups headaches] Date: Fri, 6 Dec 2013 18:33:39 -0800 (PST) Content-Type: text/plain; charset=UTF-8 And finally, his reply to you: Subject: Re: ASCII and Unicode Date: Sun, 8 Dec 2013 08:41:10 -0800 (PST) Content-Type: text/plain; charset=ISO-8859-1 It seems to me that whatever client he is using to post (I believe it is Google Groups web interface?) varies the encoding depending on what characters are included in his post. > is it possible that what you see is an artifact of the gateway? I doubt it. Unfortunately the email mailing list archive doesn't display all the email headers, but for the record here is his original post as seen by the email mailing list: https://mail.python.org/pipermail/python-list/2013-December/661782.html If you view source, you'll see that Mailman (the mailing list software) sets the webpage encoding to US-ASCII and encodes the ellipses to …, which is a perfectly reasonable thing for a web page to do. So we can be confident that when Mailman saw Rusi's post, it was able to correctly decode the message and see ellipses. Although I think that (probably) Google Groups is being stupid by varying the charset (why not just use UTF-8 always?), at least it is setting the charset correctly. -- Steven From rustompmody at gmail.com Sun Dec 8 12:39:47 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 09:39:47 -0800 (PST) Subject: ASCII and Unicode In-Reply-To: <52a4aada$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <87iov0ir3l.fsf@pascolo.net> <52a4aada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <43bf6ffb-696d-4b5f-bfee-ec3e5e138883@googlegroups.com> On Sunday, December 8, 2013 10:52:34 PM UTC+5:30, Steven D'Aprano wrote: > On Sat, 07 Dec 2013 17:05:34 +0100, giacomo boffi wrote: > > Steven D'Aprano writes: > >> Ironically, your post was not Unicode. [...] Your post was sent using > >> a legacy encoding, Windows-1252, also known as CP-1252 > > i access rusi's post using a NNTP server, and in his post i see > > Content-Type: text/plain; charset=UTF-8 > But *which post* are you looking at? > I have just looked at three posts from him: > Rusi's original post, where he used the ellipsis characters: > Subject: Re: Managing Google Groups headaches > Date: Thu, 5 Dec 2013 23:13:54 -0800 (PST) > Content-Type: text/plain; charset=windows-1252 > Then his reply to me: > Subject: Re: ASCII and Unicode [was Re: Managing Google Groups headaches] > Date: Fri, 6 Dec 2013 18:33:39 -0800 (PST) > Content-Type: text/plain; charset=UTF-8 > And finally, his reply to you: > Subject: Re: ASCII and Unicode > Date: Sun, 8 Dec 2013 08:41:10 -0800 (PST) > Content-Type: text/plain; charset=ISO-8859-1 > It seems to me that whatever client he is using to post (I believe it is > Google Groups web interface?) varies the encoding depending on what > characters are included in his post. > > is it possible that what you see is an artifact of the gateway? > I doubt it. Unfortunately the email mailing list archive doesn't display > all the email headers, but for the record here is his original post as > seen by the email mailing list: > https://mail.python.org/pipermail/python-list/2013-December/661782.html > If you view source, you'll see that Mailman (the mailing list software) > sets the webpage encoding to US-ASCII and encodes the ellipses to …, > which is a perfectly reasonable thing for a web page to do. So we can be > confident that when Mailman saw Rusi's post, it was able to correctly > decode the message and see ellipses. > Although I think that (probably) Google Groups is being stupid by varying > the charset (why not just use UTF-8 always?), at least it is setting the > charset correctly. I think GG is being being sweet and affectionate and delectable enough that a ? in the footer will keep it stuck at UTF-8 you think ?? :-) From pecore at pascolo.net Sun Dec 8 15:11:41 2013 From: pecore at pascolo.net (giacomo boffi) Date: Sun, 08 Dec 2013 21:11:41 +0100 Subject: ASCII and Unicode References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <87iov0ir3l.fsf@pascolo.net> <52a4aada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ppp7umpu.fsf@pascolo.net> Steven D'Aprano writes: > On Sat, 07 Dec 2013 17:05:34 +0100, giacomo boffi wrote: > >> Steven D'Aprano writes: >> >>> Ironically, your post was not Unicode. [...] Your post was sent using >>> a legacy encoding, Windows-1252, also known as CP-1252 >> >> i access rusi's post using a NNTP server, and in his post i see >> >> Content-Type: text/plain; charset=UTF-8 > > But *which post* are you looking at? the wrong one... i.e, the one JUST BEFORE your change of subject --- if i look at the "ellipsis" post, i see the same encoding that you have mentioned sorry for the confusion From rustompmody at gmail.com Sun Dec 8 22:02:24 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 19:02:24 -0800 (PST) Subject: ASCII and Unicode In-Reply-To: <87ppp7umpu.fsf@pascolo.net> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a21ec1$0$30003$c3e8da3$5496439d@news.astraweb.com> <87iov0ir3l.fsf@pascolo.net> <52a4aada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87ppp7umpu.fsf@pascolo.net> Message-ID: <559eaf34-a2f3-4fb4-8a70-9384e84468fe@googlegroups.com> On Monday, December 9, 2013 1:41:41 AM UTC+5:30, giacomo boffi wrote: > the wrong one... i.e, the one JUST BEFORE your change of > subject --- if i look at the "ellipsis" post, i see the same encoding > that you have mentioned > sorry for the confusion And thank you for pointing the way to the culprit, viz. GG trying to be too clever. [Since you neglected to close your I am included in it :-) ] From greg.ewing at canterbury.ac.nz Fri Dec 6 18:27:58 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 Dec 2013 12:27:58 +1300 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: rusi wrote: > On Friday, December 6, 2013 1:06:30 PM UTC+5:30, Roy Smith wrote: > >>Which means, if I wanted to (and many examples of this exist), I can >>write my own client which presents the same information in different >>ways. > > Not sure whats your point. The point is the existence of an alternative interface that's designed for use by other programs rather than humans. This is what web forums are missing. If it existed, one could easily create an alternative client with a newsreader-like interface. Without it, such a client would have to be a monstrosity that worked by screen-scraping the html. It's not about the format of the messages themselves -- that could be text, or html, or reST, or bbcode or whatever. It's about the *framing* of the messages, and being able to query them by their metadata. -- Greg From ned at nedbatchelder.com Fri Dec 6 21:24:50 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 06 Dec 2013 21:24:50 -0500 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: On 12/6/13 8:03 AM, rusi wrote: >> I think you're off on the wrong track here. This has nothing to do with >> >plain text (ascii or otherwise). It has to do with divorcing how you >> >store and transport messages (be they plain text, HTML, or whatever) >> >from how a user interacts with them. > > Evidently (and completely inadvertently) this exchange has just > illustrated one of the inadmissable assumptions: > > "unicode as a medium is universal in the same way that ASCII used to be" > > I wrote a number of ellipsis characters ie codepoint 2026 as in: > > - human communication? > (is not very different from) > - machine communication? > > Somewhere between my sending and your quoting those ellipses became > the replacement character FFFD > >>> > > - human communication? >>> > >(is not very different from) >>> > > - machine communication? > Leaving aside whose fault this is (very likely buggy google groups), > this mojibaking cannot happen if the assumption "All text is ASCII" > were to uniformly hold. > > Of course with unicode also this can be made to not happen, but that > is fragile and error-prone. And that is because ASCII (not extended) > is ONE thing in a way that unicode is hopelessly a motley inconsistent > variety. You seem to be suggesting that we should stick to ASCII. There are of course languages that need more than just the Latin alphabet. How would you suggest we support them? Or maybe I don't understand? --Ned. From rustompmody at gmail.com Sat Dec 7 02:43:05 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 23:43:05 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> On Saturday, December 7, 2013 7:54:50 AM UTC+5:30, Ned Batchelder wrote: > On 12/6/13 8:03 AM, rusi wrote: > > Leaving aside whose fault this is (very likely buggy google groups), > > this mojibaking cannot happen if the assumption "All text is ASCII" > > were to uniformly hold. > > Of course with unicode also this can be made to not happen, but that > > is fragile and error-prone. And that is because ASCII (not extended) > > is ONE thing in a way that unicode is hopelessly a motley inconsistent > > variety. > You seem to be suggesting that we should stick to ASCII. There are of > course languages that need more than just the Latin alphabet. How would > you suggest we support them? Or maybe I don't understand? Heh! Yes I guess that can be read into what I was saying. Practically: I dont see that as an option or that the question of going back to ASCII even arises. I was talking more philosophically/historically. Up until the time of Unix a file for example was a structured heavy-duty concept motivated by entirely technological considerations: http://en.wikipedia.org/wiki/Data_set_%28IBM_mainframe%29 By simplifying that into the modern concept of file -- just a stream of bytes -- and allowing the puns: byte string = char list = text some elegant systems could be made with people having 'beautiful thoughts:' Everything that could be stored anywhere -- core or disk -- being bytes one could go to the next stage and pass around these bytes between processes. And so we get the elegant -- pipeline -- beauty of Unix scripts. Of course there was a catch (Isn't there always?): Things that did not fit in with this philosophy -- eg clicks of a mouse, bits on display -- were modelled badly or not at all. Not-at-all: CLI Badly: Monstrosity called X And this explains some of the cultural kinks of our field: Unix guys invariably think of CLIs as natural and obvious whereas GUIs are just wasteful eye-candy. [Yours truly is one of those old geezers who does not know how to write a GUI to save his life. Almost normal in the Unix world except that he's not proud of it] Windows/Mac people do not suffer these delusions but then they dont think of programming as natural or obvious at all. Ive often been amused at windows folk: They dont think of Word as a program. Rather docs are things that magically open when clicked :-) Brings me to the point I was trying to make (got side-tracked by the failure of a character to roundtrip between me and Roy -- Im none the wiser why) The ASCII = Text = Unicode (non)equation is a relatively minor point. The more central point is that humans use and need more than just words to communicate. By straitjacketing communication into the thin channel of text we are severely impoverishing ourselves. We communicate with systems with programs that are unstructured text-files even though programs are conceptually highly structured entities. Likewise we communicate with each other by this obscenely obsolete textual mode that I am using right now when rich text formats have been available for decades. Some of my more detailed writings on this: http://blog.languager.org/2013/09/poorest-computer-users-are-programmers.html http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html From wxjmfauth at gmail.com Sat Dec 7 05:16:02 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 7 Dec 2013 02:16:02 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> Message-ID: <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> Rusi: "unicode as a medium is universal in the same way that ASCII used to be" Probably, you do not realize deeply how this sentence is correct. Unicode and ascii are constructed in the same way. It has not even to do with "characters", but with mathematics. It is on this level the FSR fails. It is mathematically wrong by design! jmf From steve+comp.lang.python at pearwood.info Sat Dec 7 06:25:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2013 11:25:07 GMT Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> Message-ID: <52a30593$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Dec 2013 02:16:02 -0800, wxjmfauth wrote: > Rusi: > > "unicode as a medium is universal in the same way that ASCII used to be" > > Probably, you do not realize deeply how this sentence is correct. > Unicode and ascii are constructed in the same way. It has not even to do > with "characters", but with mathematics. > > It is on this level the FSR fails. It is mathematically wrong by design! I'm reminded of that fellow, I don't remember his name, who *years* after the Wright Brothers had flown, and there were dozens of people building aeroplanes, was still trying to convince everyone that heavier-than-air flight was mathematically impossible. -- Steven From rosuav at gmail.com Sat Dec 7 06:49:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 22:49:51 +1100 Subject: Managing Google Groups headaches In-Reply-To: <52a30593$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> <52a30593$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Dec 7, 2013 at 10:25 PM, Steven D'Aprano wrote: > On Sat, 07 Dec 2013 02:16:02 -0800, wxjmfauth wrote: > >> Rusi: >> >> "unicode as a medium is universal in the same way that ASCII used to be" >> >> Probably, you do not realize deeply how this sentence is correct. >> Unicode and ascii are constructed in the same way. It has not even to do >> with "characters", but with mathematics. >> >> It is on this level the FSR fails. It is mathematically wrong by design! > > > I'm reminded of that fellow, I don't remember his name, who *years* after > the Wright Brothers had flown, and there were dozens of people building > aeroplanes, was still trying to convince everyone that heavier-than-air > flight was mathematically impossible. Nearest I can find is: https://en.wikipedia.org/wiki/Simon_Newcomb#On_the_impossibility_of_a_flying_machine He at least accepted the Wrights' work once he found out about it. Also, he didn't make repeated usenet posts that torpedo you in the face and leave an "Uh?"-shaped hole. [1] I'm still not sure what jmf meant by the above. ChrisA [1] http://bofh.ntk.net/BOFH/1999/bastard99-24.php From roy at panix.com Sat Dec 7 11:08:08 2013 From: roy at panix.com (Roy Smith) Date: Sat, 07 Dec 2013 11:08:08 -0500 Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> Message-ID: In article <31f1bb84-1432-446c-a7d4-79ce16f2a543 at googlegroups.com>, wxjmfauth at gmail.com wrote: > It is on this level the FSR fails. What is "FSR"? I apologize if this was explained earlier in the thread and I can't find the reference. https://en.wikipedia.org/wiki/FSR#Science_and_technology was no help. From python.list at tim.thechases.com Sat Dec 7 11:19:32 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 7 Dec 2013 10:19:32 -0600 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> Message-ID: <20131207101932.5a187a65@bigbox.christie.dr> On 2013-12-07 11:08, Roy Smith wrote: > In article <31f1bb84-1432-446c-a7d4-79ce16f2a543 at googlegroups.com>, > wxjmfauth at gmail.com wrote: > > > It is on this level the FSR fails. > > What is "FSR"? I apologize if this was explained earlier in the > thread and I can't find the reference. Flexible String Representation = PEP393 http://www.python.org/dev/peps/pep-0393/ -tkc From sg552 at hotmail.co.uk Sat Dec 7 11:15:33 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Sat, 07 Dec 2013 16:15:33 +0000 Subject: Managing Google Groups headaches In-Reply-To: References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> Message-ID: On 07/12/2013 16:08, Roy Smith wrote: > In article <31f1bb84-1432-446c-a7d4-79ce16f2a543 at googlegroups.com>, > wxjmfauth at gmail.com wrote: > >> It is on this level the FSR fails. > > What is "FSR"? I apologize if this was explained earlier in the thread > and I can't find the reference. It's the Flexible String Representation, introduced in Python 3.3: http://www.python.org/dev/peps/pep-0393/ From rustompmody at gmail.com Sat Dec 7 11:27:38 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 7 Dec 2013 08:27:38 -0800 (PST) Subject: Managing Google Groups headaches In-Reply-To: <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> Message-ID: <4f2f52f7-4f6f-4944-9d61-86f676f0ae82@googlegroups.com> On Saturday, December 7, 2013 3:46:02 PM UTC+5:30, wxjm... at gmail.com wrote: > Rusi: > "unicode as a medium is universal in the same way that > ASCII used to be" > Probably, you do not realize deeply how this sentence > is correct. Unicode and ascii are constructed in the > same way. It has not even to do with "characters", but > with mathematics. On the contrary, I'd say we have some rather interesting 'characters' out here. > It is on this level the FSR fails. It is mathematically > wrong by design! Now thats an even more interesting statement. Only not sure what it means Here are some attempts It is wrong therefore unmathematical It is designed so its wrong It is mathematical so its undesigned Any Ive missed?? From ned at nedbatchelder.com Sat Dec 7 12:04:30 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 07 Dec 2013 12:04:30 -0500 Subject: Managing Google Groups headaches In-Reply-To: <4f2f52f7-4f6f-4944-9d61-86f676f0ae82@googlegroups.com> References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <5137f9a5-d0a0-4f7a-8d50-e464094392e2@googlegroups.com> <31f1bb84-1432-446c-a7d4-79ce16f2a543@googlegroups.com> <4f2f52f7-4f6f-4944-9d61-86f676f0ae82@googlegroups.com> Message-ID: On 12/7/13 11:27 AM, rusi wrote: > On Saturday, December 7, 2013 3:46:02 PM UTC+5:30, wxjm... at gmail.com wrote: >> Rusi: > >> "unicode as a medium is universal in the same way that >> ASCII used to be" > >> Probably, you do not realize deeply how this sentence >> is correct. Unicode and ascii are constructed in the >> same way. It has not even to do with "characters", but >> with mathematics. > > On the contrary, I'd say we have some rather interesting > 'characters' out here. > >> It is on this level the FSR fails. It is mathematically >> wrong by design! > > Now thats an even more interesting statement. Only not sure what it means > Here are some attempts > > It is wrong therefore unmathematical > It is designed so its wrong > It is mathematical so its undesigned > > Any Ive missed?? > JMF: Please stop making this claim. The last 20 times you claimed it you didn't convince anyone on this list, and I doubt you have any new information. Rusi: if you are interested in the details, search the archives. -- Ned Batchelder, http://nedbatchelder.com From steve+comp.lang.python at pearwood.info Fri Dec 6 22:07:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2013 03:07:25 GMT Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> Message-ID: <52a290ed$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Dec 2013 23:13:54 -0800, rusi wrote: > On Thursday, December 5, 2013 6:28:54 AM UTC+5:30, Roy Smith wrote: >> The real problem with web forums is they conflate transport and >> presentation into a single opaque blob, and are pretty much universally >> designed to be a closed system. Mail and usenet were both engineered >> to make a sharp division between transport and presentation, which >> meant it was possible to evolve each at their own pace. > >> Mostly that meant people could go off and develop new client >> applications which interoperated with the existing system. But, it >> also meant that transport layers could be switched out (as when NNTP >> gradually, but inexorably, replaced UUCP as the primary usenet >> transport layer). > > There is a deep assumption hovering round-about the above -- what I will > call the 'Unix assumption(s)'. But before that, just a check on > terminology. By 'presentation' you mean what people normally call > 'mail-clients': thunderbird, mutt etc. And by 'transport' you mean > sendmail, exim, qmail etc etc -- what normally are called > 'mail-servers.' Right?? Presentation means how the data is presented. Transport means how the data is transported. It doesn't refer to a specific piece of software like Thunderbird, but to the logical fact that what people see (the presentation) is not identical to what gets transported from one computer to another. All programs make *some* distinction between the two. Email is encoded, wrapped with normally-hidden headers, and then sent, before being displayed at the other end sans such headers. But some programs make a nice clean distinction. If your mail client converts emails to sound for the benefit of the blind, that is easy to do because there is a clean *and public* distinction between the transport and presentation of email -- everybody can agree on how to extract the message ("Hi Bob, are we still meeting up for drinks tomorrow night?") from the transportation layer (the email envelope). In contrast, that is not the case with nearly all web forums. By deliberate design, or mere ignorance and neglect, they mix up the message you care about ("Hi Bob...") and the stuff you need to get that message (the HTML and Javascript code) in one big ball of mud, and don't have APIs for getting messages. Or worse, they deliberate obfuscate the content, in an attempt to lock people in to only using the specific interface they want you to use. Consider the difference between (say) Twitter, which has published standard APIs for reading and writing tweets, and StackOverflow, which as far as I can tell insists that the one and only way to read and write comments is via their website. The internal formatting of the website is not public and is subject to change without notice. (If I have unfairly maligned StackOverflow, substitute any number of dozens or hundreds of web forums.) [...] > To the extent that these assumptions are invalid, the 'opaque-blob' may > well be preferable. No. Nice clean interfaces separating concerns (such as transport and presentation) have little to do with ASCII text. One can define clear and open binary protocols too. -- Steven From roy at panix.com Fri Dec 6 22:40:58 2013 From: roy at panix.com (Roy Smith) Date: Fri, 06 Dec 2013 22:40:58 -0500 Subject: Managing Google Groups headaches References: <5f370a06-8d2c-4d7d-bc22-b9a489c15c59@googlegroups.com> <132658ff-d06a-4136-ade6-353189da5769@googlegroups.com> <51007240-6bc9-4f0b-9937-4883bcc0ceb6@googlegroups.com> <52a290ed$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52a290ed$0$30003$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > In contrast, that is not the case with nearly all web forums. By > deliberate design, or mere ignorance and neglect, they mix up the message > you care about ("Hi Bob...") and the stuff you need to get that message > (the HTML and Javascript code) in one big ball of mud, and don't have > APIs for getting messages. BTW, I was going to bring up vBulletin as an example of a typical web forum which suffers from the "big ball of mud" syndrome. Then I discovered that it does indeed have a reasonable looking API (http://www.vbulletin.com/vbcms/content.php/367-API-Overview). Beautiful Soup is an awesome tool. Even more awesome is when you don't have to use it :-) From redstone-cold at 163.com Mon Dec 2 06:41:09 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 2 Dec 2013 03:41:09 -0800 (PST) Subject: how to implement a queue-like container with sort function In-Reply-To: References: <0c445e44-25c7-42b9-8c62-c30428261251@googlegroups.com> Message-ID: <39b48b0b-5c0a-42d9-922f-27987386764b@googlegroups.com> ? 2013?11?29????UTC+8??10?57?36??Mark Lawrence??? > On 29/11/2013 12:33, iMath wrote: > > > > > > BTW ,the Queue object has an attribute 'queue' ,but I cannot find it described in the DOC ,what it means ? > > > > > > > Really? AttributeError: type object 'Queue' has no attribute 'queue' > > > > -- > > Python is the second best programming language in the world. > > But the best has yet to be invented. Christian Tismer > > > > Mark Lawrence you can do a check by hasattr() From ned at nedbatchelder.com Mon Dec 2 06:58:11 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 06:58:11 -0500 Subject: how to implement a queue-like container with sort function In-Reply-To: <39b48b0b-5c0a-42d9-922f-27987386764b@googlegroups.com> References: <0c445e44-25c7-42b9-8c62-c30428261251@googlegroups.com> <39b48b0b-5c0a-42d9-922f-27987386764b@googlegroups.com> Message-ID: On 12/2/13 6:41 AM, iMath wrote: > ? 2013?11?29????UTC+8??10?57?36??Mark Lawrence??? >> On 29/11/2013 12:33, iMath wrote: >> >>> >> >>> BTW ,the Queue object has an attribute 'queue' ,but I cannot find it described in the DOC ,what it means ? >> >>> >> >> >> >> Really? AttributeError: type object 'Queue' has no attribute 'queue' >> >> >> >> -- >> >> Python is the second best programming language in the world. >> >> But the best has yet to be invented. Christian Tismer >> >> >> >> Mark Lawrence > > you can do a check by hasattr() > Yes, a Queue object has a queue attribute: >>> import Queue >>> q = Queue.Queue() >>> q.queue deque([]) But you shouldn't use it. It's part of the implementation of Queue, not meant for you to use directly. In particular, if you use it directly, you are skipping all synchronization, which is the main reason to use a Queue in the first place. It should have been named "_queue". We'll add that to the list of PEP-8 violations in the Queue module! :) --Ned. From rosuav at gmail.com Mon Dec 2 07:04:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Dec 2013 23:04:51 +1100 Subject: how to implement a queue-like container with sort function In-Reply-To: References: <0c445e44-25c7-42b9-8c62-c30428261251@googlegroups.com> <39b48b0b-5c0a-42d9-922f-27987386764b@googlegroups.com> Message-ID: On Mon, Dec 2, 2013 at 10:58 PM, Ned Batchelder wrote: > Yes, a Queue object has a queue attribute: > > >>> import Queue > >>> q = Queue.Queue() > >>> q.queue > deque([]) > > But you shouldn't use it. It's part of the implementation of Queue, not > meant for you to use directly. In particular, if you use it directly, you > are skipping all synchronization, which is the main reason to use a Queue in > the first place. I should apologize here; when the OP said "queue", I immediately noticed that I could import that and use it, and mistakenly started my testing on that, instead of using the deque type. It's deque that should be used here. Queue is just a wrapper around deque that adds functionality that has nothing to do with what's needed here. ChrisA From ned at nedbatchelder.com Mon Dec 2 07:26:01 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 07:26:01 -0500 Subject: how to implement a queue-like container with sort function In-Reply-To: References: <0c445e44-25c7-42b9-8c62-c30428261251@googlegroups.com> <39b48b0b-5c0a-42d9-922f-27987386764b@googlegroups.com> Message-ID: On 12/2/13 7:04 AM, Chris Angelico wrote: > On Mon, Dec 2, 2013 at 10:58 PM, Ned Batchelder wrote: >> Yes, a Queue object has a queue attribute: >> >> >>> import Queue >> >>> q = Queue.Queue() >> >>> q.queue >> deque([]) >> >> But you shouldn't use it. It's part of the implementation of Queue, not >> meant for you to use directly. In particular, if you use it directly, you >> are skipping all synchronization, which is the main reason to use a Queue in >> the first place. > > I should apologize here; when the OP said "queue", I immediately > noticed that I could import that and use it, and mistakenly started my > testing on that, instead of using the deque type. It's deque that > should be used here. Queue is just a wrapper around deque that adds > functionality that has nothing to do with what's needed here. > > ChrisA > Actually, I had a long conversation in the #python IRC channel with the OP at the same time he was posting the question here, and it turns out he knows exactly how many entries are going into the "queue", so a plain-old list is the best solution. I don't know quite where the idea of limiting the number of entries came from. --Ned. From cs at zip.com.au Tue Dec 3 16:17:18 2013 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Dec 2013 08:17:18 +1100 Subject: how to implement a queue-like container with sort function In-Reply-To: References: Message-ID: <20131203211718.GA94804@cskk.homeip.net> On 02Dec2013 07:26, Ned Batchelder wrote: > Actually, I had a long conversation in the #python IRC channel with > the OP at the same time he was posting the question here, and it > turns out he knows exactly how many entries are going into the > "queue", so a plain-old list is the best solution. I don't know > quite where the idea of limiting the number of entries came from. For me, it was because he said "fill the queue" in the OP. I took that to imply that the queue had a capacity limit. Cheers, -- It's bubble, bubble, toil and trouble in conductive polymer. - overhead by WIRED at the Intelligent Printing conference Oct2006 From cs at zip.com.au Tue Dec 3 16:19:39 2013 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Dec 2013 08:19:39 +1100 Subject: how to implement a queue-like container with sort function In-Reply-To: <20131203211718.GA94804@cskk.homeip.net> References: <20131203211718.GA94804@cskk.homeip.net> Message-ID: <20131203211939.GA96916@cskk.homeip.net> On 04Dec2013 08:17, I wrote: > On 02Dec2013 07:26, Ned Batchelder wrote: > > Actually, I had a long conversation in the #python IRC channel with > > the OP at the same time he was posting the question here, and it > > turns out he knows exactly how many entries are going into the > > "queue", so a plain-old list is the best solution. I don't know > > quite where the idea of limiting the number of entries came from. > > For me, it was because he said "fill the queue" in the OP. I took > that to imply that the queue had a capacity limit. And then I check the source:-( He actually said "I want to a fixed length list-like container". That still sounds like a limit to the number of entries. Cheers, -- Cameron Simpson Success in software development depends on making a carefully planned series of small mistakes in order to avoid making unplanned large mistakes. - Steve McConnell, _Software Project Survival Guide_ From ned at nedbatchelder.com Tue Dec 3 16:34:02 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 03 Dec 2013 16:34:02 -0500 Subject: how to implement a queue-like container with sort function In-Reply-To: <20131203211939.GA96916@cskk.homeip.net> References: <20131203211718.GA94804@cskk.homeip.net> <20131203211939.GA96916@cskk.homeip.net> Message-ID: On 12/3/13 4:19 PM, Cameron Simpson wrote: > On 04Dec2013 08:17, I wrote: >> On 02Dec2013 07:26, Ned Batchelder wrote: >>> Actually, I had a long conversation in the #python IRC channel with >>> the OP at the same time he was posting the question here, and it >>> turns out he knows exactly how many entries are going into the >>> "queue", so a plain-old list is the best solution. I don't know >>> quite where the idea of limiting the number of entries came from. >> >> For me, it was because he said "fill the queue" in the OP. I took >> that to imply that the queue had a capacity limit. > > And then I check the source:-( He actually said "I want to a fixed > length list-like container". That still sounds like a limit to the > number of entries. > > Cheers, > Sorry, I was unclear. When I said, "I don't know where the idea came from," I should have said, "the OP said he wanted a fixed-length contained, but I don't know why he thinks that." --Ned. From cs at zip.com.au Tue Dec 3 18:23:49 2013 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Dec 2013 10:23:49 +1100 Subject: how to implement a queue-like container with sort function In-Reply-To: References: Message-ID: <20131203232349.GA18433@cskk.homeip.net> On 03Dec2013 16:34, Ned Batchelder wrote: > On 12/3/13 4:19 PM, Cameron Simpson wrote: > >And then I check the source:-( He actually said "I want to a fixed > >length list-like container". That still sounds like a limit to the > >number of entries. > > Sorry, I was unclear. When I said, "I don't know where the idea came > from," I should have said, "the OP said he wanted a fixed-length > contained, but I don't know why he thinks that." Me either. Unless this is a homework task: "make one of these". -- Cameron Simpson It's as if all of Scottish cuisine is based on a dare. - Saturday Night Live From redstone-cold at 163.com Tue Dec 3 19:47:24 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 3 Dec 2013 16:47:24 -0800 (PST) Subject: how to implement a queue-like container with sort function In-Reply-To: References: Message-ID: ? 2013?12?4????UTC+8??7?23?49??Cameron Simpson??? > On 03Dec2013 16:34, Ned Batchelder wrote: > > > On 12/3/13 4:19 PM, Cameron Simpson wrote: > > > >And then I check the source:-( He actually said "I want to a fixed > > > >length list-like container". That still sounds like a limit to the > > > >number of entries. > > > > > > Sorry, I was unclear. When I said, "I don't know where the idea came > > > from," I should have said, "the OP said he wanted a fixed-length > > > contained, but I don't know why he thinks that." > > > > Me either. > > > > Unless this is a homework task: "make one of these". > > -- > > Cameron Simpson > > > > It's as if all of Scottish cuisine is based on a dare. - Saturday Night Live deque meets my requirement here :) From julio at techfuel.net Sun Dec 1 20:01:11 2013 From: julio at techfuel.net (Julio Schwarzbeck) Date: Sun, 01 Dec 2013 17:01:11 -0800 Subject: Need help with programming in python for class (beginner level) In-Reply-To: References: Message-ID: On 11/29/2013 04:31 PM, farhanken at gmail.com wrote: > It's for a school assignment. Basically, I need to roll 5 dies with 6 sides each. So basically, 6 random numbers. That part is easy. Then I need to add it up. Ok, done that. However, I also need to say something along the lines of "your total number was X". That's what I'm having trouble with. I added the dice rolls together and put them into a variable I called "number" but it seems to glitch out that variable is in any command other than "print number". Like, if I try to write: > > print "

your total number was:" number "

" > > It just doesn't work. > > Here is my code so far: > > > import cgi > > form = cgi.FieldStorage() > name = form.getvalue("name") > value = form.getvalue("value") > > > print """Content-type: text/html > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > > A CGI Script > > """ > import random > > die1 = random.randint(1,6) > die2 = random.randint(1,6) > die3 = random.randint(1,6) > die4 = random.randint(1,6) > die5 = random.randint(1,6) > print die1, die2, die3, die4, die5 > number = die1 + die2 + die3 + die4 + die5 > print "

The total rolled was: "number"

" > > print "

Thanks for playing, " + name + ".

" > print "

You bet the total would be at least " + value + ".

" > print "" > My two "favorites": print '

The total rolled was: %s

' % number [py 2.7+] print('

The total rolled was: {}

'.format(number)) Cheers, -- Speedbird From wxjmfauth at gmail.com Sun Dec 1 11:57:44 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 1 Dec 2013 08:57:44 -0800 (PST) Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <15147203-f1e3-44dc-ab11-3847c638b37c@googlegroups.com> Le dimanche 1 d?cembre 2013 00:07:36 UTC+1, Ned Batchelder a ?crit?: > On 11/30/13 5:37 PM, Gregory Ewing wrote: > > > wxjmfauth at gmail.com wrote: > > >> And do you know the origin of this typographical feature? > > >> Because, mechanically, the dot of the "i" broke too often. > > >> > > >> In my opinion, a very plausible explanation. > > > > > > It doesn't sound very plausible to me, because there > > > are a lot more stand-alone 'i's in English text than > > > there are ones following an f. What is there to stop > > > them from breaking? > > > > > > It's more likely to be simply a kerning issue. You > > > want to get the stems of the f and the i close together, > > > and the only practical way to do that with mechanical > > > type is to merge them into one piece of metal. > > > > > > Which makes it even sillier to have an 'ffi' character > > > in this day and age, when you can simply space the > > > characters so that they overlap. > > > > > > > The fi ligature was created because visually, an f and i wouldn't work > > well together: the crossbar of the f was near, but not connected to the > > serif of the i, and the terminal bulb of the f was close to, but not > > coincident, with the dot of the i. > > > > This article goes into great detail, and has a good illustration of how > > an f and i can clash, and how an fi ligature can fix the problem: > > http://opentype.info/blog/2012/11/20/whats-a-ligature/ . Note the second > > fi illustration, which demonstrates using a ligature to make the letters > > appear *less* connected than they would individually! > > > > This is also why "simply spacing the characters" isn't a solution: a > > specially designed ligature looks better than a separate f and i, no > > matter how minutely kerned. > > > > It's unfortunate that Unicode includes presentation alternatives like > > the fi (and ff, fl, ffi, and fl) ligatures. It was done to be a > > superset of existing encodings. > > > > Many typefaces have other non-encoded ligatures as well, especially > > display faces, which also have alternate glyphs. Unicode is a funny mix > > in that it includes some forms of alternates, but can't include all of > > them, so we have to put up with both an ad-hoc Unicode that includes > > presentational variants, and also some other way to specify variants > > because Unicode can't include all of them. > I'm speaking about those times where the "characters" (some) were not even built with metal, but with wood (see Garamond, Bodoni). --------- Unicode is "only" collecting "characters" in the sense "abstract entities". What is supposed to be a "character" is one problem. How a tool is supposed to handle these "characters" is a problem too, but a different one. "Unicode" is not a coding scheme, it is a "repertoire". Illustrative examples instead of explanations. The ffl ligature is a "character" because it has always existed. The & and ? are considered today as unique "characters". They were historically "ligaturated forms". The Fahrenheit, Kelvin and Celsius are considered as "characters", despite Fahrenheit, Kelvin are "letters". Text justification. Calculating the space between "words" in "rendering units" makes sense. Using a specific "character" like a thin space to force a predefined space makes sense too. The miscellaneous zeroes one may see, like uppercase O, O with a dot in the center or a striked O are all the same zero, but with stylistic variants, => a single "character" in the unicode table. ... but this medieval "character" existing in two forms (I do not remember which one) was finally registrated as two "characters", and not as a stylistic variant of a single "character". There are no "characters" for the symbols of the chemical elements, a latin script is good enough. The QPlainTextEdit widget from Qt does not know '\n'. It uses only the paragraph separator and the line separator. To render a paragraph separator, it uses one another "character", the pilcrow. The ? "character" in the iso-8859-1 coding scheme is a greek letter, it must be used or percieved as a SI unit prefix. Unicode category: Ll, unicode name: micro sign. How to place an arrow (vector) on top of an ?, if one cann't decompose it? Related, there are dotless variants of i and j. STIX fonts with the huge number of math symbols, not yet in the unicode repertoire but present in the PUA. etc. Unicode is quite open. It's a good idea to keep that openess to the developer. Shortly, if a coder decomposes a "character" like "?" in a "a" plus a "^", it's up to the developer to know what to do when reversing such a string and to count this sequence as two real "characters". jmf From storchaka at gmail.com Sun Dec 1 13:00:21 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 01 Dec 2013 20:00:21 +0200 Subject: Python Unicode handling wins again -- mostly In-Reply-To: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: 30.11.13 02:44, Steven D'Aprano ???????(??): > (2) If you reverse that string, does it give "l?on"? The implication of > this question is that strings should operate on grapheme clusters rather > than code points. Python fails this test: > > py> print("noe\u0308l"[::-1]) > leon >>> print(unicodedata.normalize('NFC', "noe\u0308l")[::-1]) l?on > (3) What are the first three characters? The author suggests that the > answer should be "no?", in which case Python fails again: > > py> print("noe\u0308l"[:3]) > noe >>> print(unicodedata.normalize('NFC', "noe\u0308l")[:3]) no? > (4) Likewise, what is the length of the decomposed string? The author > expects 4, but Python gives 5: > > py> len("noe\u0308l") > 5 >>> print(len(unicodedata.normalize('NFC', "noe\u0308l"))) 4 From wxjmfauth at gmail.com Sun Dec 1 15:15:57 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 1 Dec 2013 12:15:57 -0800 (PST) Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: 0.11.13 02:44, Steven D'Aprano ???????(??): > (2) If you reverse that string, does it give "l?on"? The implication of > this question is that strings should operate on grapheme clusters rather > than code points. ... > BTW, a grapheme cluster *is* a code points cluster. jmf From timothy.c.delaney at gmail.com Sun Dec 1 15:54:48 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Mon, 2 Dec 2013 07:54:48 +1100 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2 December 2013 07:15, wrote: > 0.11.13 02:44, Steven D'Aprano ???????(??): > > (2) If you reverse that string, does it give "l?on"? The implication of > > this question is that strings should operate on grapheme clusters rather > > than code points. ... > > > > BTW, a grapheme cluster *is* a code points cluster. > Anyone with a decent level of reading comprehension would have understood that Steven knows that. The implied word is "individual" i.e. "... rather than [individual] code points". Why am I responding to a troll? Probably because out of all his baseless complaints about the FSR, he *did* have one valid point about performance that has now been fixed. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Dec 1 17:06:10 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Dec 2013 22:06:10 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/12/2013 20:54, Tim Delaney wrote: > On 2 December 2013 07:15, > wrote: > > 0.11.13 02:44, Steven D'Aprano ???????(??): > > (2) If you reverse that string, does it give "l?on"? The > implication of > > this question is that strings should operate on grapheme clusters > rather > > than code points. ... > > > > BTW, a grapheme cluster *is* a code points cluster. > > > Anyone with a decent level of reading comprehension would have > understood that Steven knows that. The implied word is "individual" i.e. > "... rather than [individual] code points". > > Why am I responding to a troll? Probably because out of all his baseless > complaints about the FSR, he *did* have one valid point about > performance that has now been fixed. > > Tim Delaney > > I don't remember him ever having a valid point, so FTR can we have a reference please. I do remember Steven D'Aprano showing that there was a regression which I flagged up here http://bugs.python.org/issue16061. It was fixed by Serhiy Storchaka, who appears to have forgotten more about Python than I'll ever know, grrr!!! :) -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From timothy.c.delaney at gmail.com Sun Dec 1 17:29:51 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Mon, 2 Dec 2013 09:29:51 +1100 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2 December 2013 09:06, Mark Lawrence wrote: > I don't remember him ever having a valid point, so FTR can we have a > reference please. I do remember Steven D'Aprano showing that there was a > regression which I flagged up here http://bugs.python.org/issue16061. It > was fixed by Serhiy Storchaka, who appears to have forgotten more about > Python than I'll ever know, grrr!!! :) > >From your own bug report (quoting Steven): "Nevertheless, I think there is something here. The consequences are nowhere near as dramatic as jmf claims ..." His initial postings did lead to a regression being found. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Dec 1 18:10:33 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Dec 2013 23:10:33 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/12/2013 22:29, Tim Delaney wrote: > On 2 December 2013 09:06, Mark Lawrence > wrote: > > I don't remember him ever having a valid point, so FTR can we have a > reference please. I do remember Steven D'Aprano showing that there > was a regression which I flagged up here > http://bugs.python.org/__issue16061 > . It was fixed by Serhiy > Storchaka, who appears to have forgotten more about Python than I'll > ever know, grrr!!! :) > > > From your own bug report (quoting Steven): "Nevertheless, I think there > is something here. The consequences are nowhere near as dramatic as jmf > claims ..." > > His initial postings did lead to a regression being found. > > Tim Delaney > > I'll begrudgungly concede that point, but must state that it was was an edge case that is unlikely to have too much impact in the real world. Unfortunately he's still making his ridiculous claims about the FSR, hence my nickname of "Joseph McCarthy". I'll admit to liking that, it just feels right to me, YMMV. What also really riles me is that he uses double spaced google crap, despite repeated requests from various people here for others to fix how they use it, or get a decent email client. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From ethan at stoneleaf.us Sun Dec 1 17:50:53 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 01 Dec 2013 14:50:53 -0800 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <529BBD4D.4070408@stoneleaf.us> On 12/01/2013 02:06 PM, Mark Lawrence wrote: > > I don't remember him [jmf] ever having a valid point, so FTR can we have a reference please. I do remember Steven D'Aprano > showing that there was a regression which I flagged up here http://bugs.python.org/issue16061. It was fixed by Serhiy > Storchaka, who appears to have forgotten more about Python than I'll ever know, grrr!!! :) The initial complaint came, unsurprisingly, from jmf. But don't worry much, even a stopped clock has a better track record... it's at least right twice a day. ;) -- ~Ethan~ From breamoreboy at yahoo.co.uk Sun Dec 1 19:43:43 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 00:43:43 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: <529BBD4D.4070408@stoneleaf.us> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529BBD4D.4070408@stoneleaf.us> Message-ID: On 01/12/2013 22:50, Ethan Furman wrote: > On 12/01/2013 02:06 PM, Mark Lawrence wrote: >> >> I don't remember him [jmf] ever having a valid point, so FTR can we >> have a reference please. I do remember Steven D'Aprano >> showing that there was a regression which I flagged up here >> http://bugs.python.org/issue16061. It was fixed by Serhiy >> Storchaka, who appears to have forgotten more about Python than I'll >> ever know, grrr!!! :) > > The initial complaint came, unsurprisingly, from jmf. But don't worry > much, even a stopped clock has a better track record... it's at least > right twice a day. ;) > > -- > ~Ethan~ I had to chuckle, "initial complaint" indeed!!! He first started complaining in August 2012 in this thread https://mail.python.org/pipermail/python-list/2012-August/628650.html. Then he continued in September 2012 in this thread https://mail.python.org/pipermail/python-list/2012-September/631613.html, which lead to issue 16061. He's been continuing to moan on and off ever since, but funnily enough has *NEVER* produced a single shred of evidence to back his claims. We'll have to wait until the cows come home before he does. Contrast that to the Victor Stinner statement here http://bugs.python.org/issue16061#msg171413 "Python 3.3 is 2x faster than Python 3.2 to replace a character with another if the string only contains the character 3 times. This is not acceptable, Python 3.3 must be as slow as Python 3.2!" Thinking about that I really do want the Python 2 code back. Apart from the PEP 393 implementation being faster, using less memory and being correct, it has nothing to offer. Now what Python sketch does that remind me of? :) -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From wxjmfauth at gmail.com Mon Dec 2 07:39:26 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 2 Dec 2013 04:39:26 -0800 (PST) Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Le dimanche 1 d?cembre 2013 21:54:48 UTC+1, Tim Delaney a ?crit?: > On 2 December 2013 07:15, wrote: > > > 0.11.13 02:44, Steven D'Aprano ???????(??): > > > > (2) If you reverse that string, does it give "l?on"? The implication of > > > this question is that strings should operate on grapheme clusters rather > > > than code points. ... > > > > > > > BTW, a grapheme cluster *is* a code points cluster. > > > > Anyone with a decent level of reading comprehension would have understood that Steven knows that. The implied word is "individual" i.e. "... rather than [individual] code points". > > > > Why am I responding to a troll? Probably because out of all his baseless complaints about the FSR, he *did* have one valid point about performance that has now been fixed. > > > Tim Delaney My English is far too be perfect, I think I understood it correctly. The point in not in the words "grapheme" or "code point", neither in "individual", ;-), the point is in "rather". If one wishes to work on a set of graphemes, one can only work with the set of the corresponding code points. To complete Serhiy Storchaka's example: >>> len(unicodedata.normalize('NFKD', '\ufdfa')) == 18 True is correct. jmf PS I did not even speak about the FSR. From breamoreboy at yahoo.co.uk Mon Dec 2 09:46:28 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 14:46:28 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 02/12/2013 12:39, wxjmfauth at gmail.com wrote: > > My English is far too be perfect, I think I understood > it correctly. > > PS I did not even speak about the FSR. > 1) Your English is far from perfect as you clearly do not understand the repeated requests *NOT* to send us double spaced crap via google groups. 2) You can't speak about the FSR as you know precisely nothing about it, but as they say, ignorance is bliss. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From ned at nedbatchelder.com Mon Dec 2 10:22:43 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 10:22:43 -0500 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 12/2/13 9:46 AM, Mark Lawrence wrote: > On 02/12/2013 12:39, wxjmfauth at gmail.com wrote: >> >> My English is far too be perfect, I think I understood >> it correctly. >> >> PS I did not even speak about the FSR. >> > > 1) Your English is far from perfect as you clearly do not understand the > repeated requests *NOT* to send us double spaced crap via google groups. > > 2) You can't speak about the FSR as you know precisely nothing about it, > but as they say, ignorance is bliss. > As annoying as baseless claims against the FSR were, wxjmafauth is right: he didn't even mention the FSR in this thread. There's really no point dragging this thread into that territory. --Ned. From breamoreboy at yahoo.co.uk Mon Dec 2 10:45:18 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 15:45:18 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 02/12/2013 15:22, Ned Batchelder wrote: > On 12/2/13 9:46 AM, Mark Lawrence wrote: >> On 02/12/2013 12:39, wxjmfauth at gmail.com wrote: >>> >>> My English is far too be perfect, I think I understood >>> it correctly. >>> >>> PS I did not even speak about the FSR. >>> >> >> 1) Your English is far from perfect as you clearly do not understand the >> repeated requests *NOT* to send us double spaced crap via google groups. >> >> 2) You can't speak about the FSR as you know precisely nothing about it, >> but as they say, ignorance is bliss. >> > > As annoying as baseless claims against the FSR were, wxjmafauth is > right: he didn't even mention the FSR in this thread. There's really no > point dragging this thread into that territory. > > --Ned. > He's quite deliberately dragged it up by using p.s. Without doubt he's the worst loser in the world and I'm *NOT* stopping getting at him. I find his behaviour, continuously and groundlessly insulting the Python core developers, quite disgusting. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From rosuav at gmail.com Mon Dec 2 10:49:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Dec 2013 02:49:34 +1100 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On Tue, Dec 3, 2013 at 2:45 AM, Mark Lawrence wrote: > He's quite deliberately dragged it up by using p.s. Without doubt he's the > worst loser in the world and I'm *NOT* stopping getting at him. I find his > behaviour, continuously and groundlessly insulting the Python core > developers, quite disgusting. What he does is make very sure that the awesomeness of Python 3.3+ is constantly being brought up on python-list. New users of Python who come here will, within a fairly short time, learn that Python actually gets Unicode right, unlike most languages out there, and that it's efficient and high performance. ChrisA From ned at nedbatchelder.com Mon Dec 2 10:58:26 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 10:58:26 -0500 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 12/2/13 10:45 AM, Mark Lawrence wrote: > On 02/12/2013 15:22, Ned Batchelder wrote: >> On 12/2/13 9:46 AM, Mark Lawrence wrote: >>> On 02/12/2013 12:39, wxjmfauth at gmail.com wrote: >>>> >>>> My English is far too be perfect, I think I understood >>>> it correctly. >>>> >>>> PS I did not even speak about the FSR. >>>> >>> >>> 1) Your English is far from perfect as you clearly do not understand the >>> repeated requests *NOT* to send us double spaced crap via google groups. >>> >>> 2) You can't speak about the FSR as you know precisely nothing about it, >>> but as they say, ignorance is bliss. >>> >> >> As annoying as baseless claims against the FSR were, wxjmafauth is >> right: he didn't even mention the FSR in this thread. There's really no >> point dragging this thread into that territory. >> >> --Ned. >> > > He's quite deliberately dragged it up by using p.s. Without doubt he's > the worst loser in the world and I'm *NOT* stopping getting at him. I > find his behaviour, continuously and groundlessly insulting the Python > core developers, quite disgusting. > His PS is in reference to you, Ethan, and Tim reminiscing about his past complaints against the FSR. He made three posts to this thread before you started in on him, and none of them mentioned the FSR. Tim first mentioned it. There's no need to call him "the worst loser in the world." Nothing good will come from that kind of attack. It doesn't make this community better, and it will not change his behavior. He said nothing in this thread that insulted the Python core developers. His posts in this thread are not about the FSR, and yet you dragged the old fights into it. You are being the troll here. --Ned. From tjreedy at udel.edu Mon Dec 2 15:26:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Dec 2013 15:26:09 -0500 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 12/2/2013 10:45 AM, Mark Lawrence wrote: > the worst loser in the world Mark, I consider your continual direct personal attacks on other posters to be a violation of the PSF Code of Conduct, which *does* apply to python-list. Please stop. -- Terry Jan Reedy, one of multiple list moderators From breamoreboy at yahoo.co.uk Mon Dec 2 15:45:10 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 20:45:10 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 02/12/2013 20:26, Terry Reedy wrote: > On 12/2/2013 10:45 AM, Mark Lawrence wrote: > >> the worst loser in the world > > Mark, I consider your continual direct personal attacks on other posters > to be a violation of the PSF Code of Conduct, which *does* apply to > python-list. Please stop. > The attacks that "Joseph McCarthy" has been launching on the core developers for the last 15 months are in my view now perfectly acceptable. This is excellent news. Everybody can now say what they like about the core developers and there's no comeback. You can also stuff the code of conduct, it's quite clearly only brought into play when it suits. Never, ever aim it at somebody who goes out of their way to stir things up, always target it at the people who fight back *IS THE RULE HERE*. -- 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 Dec 2 16:44:03 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 16:44:03 -0500 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 12/2/13 3:45 PM, Mark Lawrence wrote: > On 02/12/2013 20:26, Terry Reedy wrote: >> On 12/2/2013 10:45 AM, Mark Lawrence wrote: >> >>> the worst loser in the world >> >> Mark, I consider your continual direct personal attacks on other posters >> to be a violation of the PSF Code of Conduct, which *does* apply to >> python-list. Please stop. >> > > The attacks that "Joseph McCarthy" has been launching on the core > developers for the last 15 months are in my view now perfectly > acceptable. This is excellent news. Everybody can now say what they > like about the core developers and there's no comeback. > > You can also stuff the code of conduct, it's quite clearly only brought > into play when it suits. Never, ever aim it at somebody who goes out of > their way to stir things up, always target it at the people who fight > back *IS THE RULE HERE*. > The point is that in this thread, no one was making attacks on core developers. You were bringing up old animosity here for no reason at all, and making them personal attacks to boot. I don't see how you think wxjmfauth was "going out of his way to stir things up" in *this* thread. He made three comments, none of which mentioned the FSR or any other controversial topic. Can't we respond to the content of posts, and not to past offenses by the poster? Additionally, wxjmfauth's past complaints about the flexible string representation were not personal. He didn't say, "Joe Smith is the worst loser in the world for writing the FSR". He complained about a feature of CPython, baselessly, but he never attacked the people doing the work. His continued complaints were aggravating, I agree. I don't know that they rose to the level of "disrespectful". I know that your behavior here is disrespectful. As to when the code of conduct is brought up, it's only fairly recently that it has been mentioned in this forum. There have clearly been posts in recent memory (the last year) which could have been examined in light of the code of conduct, and were not. I think we are using it more uniformly now. You helped me realize better how to apply it to this forum, and I thank you for that. I welcome your help in applying it better still. But it applies to you as well and I don't think it's too much to ask that you abide by it. The way to improve this list is to respectfully point to and demonstrate community norms and ask people to conform to them. Spewing vitriol isn't going to fix anything. --Ned. From ned at nedbatchelder.com Mon Dec 2 17:24:37 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 17:24:37 -0500 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 12/2/13 4:44 PM, Ned Batchelder wrote: > On 12/2/13 3:45 PM, Mark Lawrence wrote: >> On 02/12/2013 20:26, Terry Reedy wrote: >>> On 12/2/2013 10:45 AM, Mark Lawrence wrote: >>> >>>> the worst loser in the world >>> >>> Mark, I consider your continual direct personal attacks on other posters >>> to be a violation of the PSF Code of Conduct, which *does* apply to >>> python-list. Please stop. >>> >> >> The attacks that "Joseph McCarthy" has been launching on the core >> developers for the last 15 months are in my view now perfectly >> acceptable. This is excellent news. Everybody can now say what they >> like about the core developers and there's no comeback. >> >> You can also stuff the code of conduct, it's quite clearly only brought >> into play when it suits. Never, ever aim it at somebody who goes out of >> their way to stir things up, always target it at the people who fight >> back *IS THE RULE HERE*. >> > > The point is that in this thread, no one was making attacks on core > developers. You were bringing up old animosity here for no reason at > all, and making them personal attacks to boot. > > I don't see how you think wxjmfauth was "going out of his way to stir > things up" in *this* thread. He made three comments, none of which > mentioned the FSR or any other controversial topic. Can't we respond to > the content of posts, and not to past offenses by the poster? > > Additionally, wxjmfauth's past complaints about the flexible string > representation were not personal. He didn't say, "Joe Smith is the > worst loser in the world for writing the FSR". He complained about a > feature of CPython, baselessly, but he never attacked the people doing > the work. His continued complaints were aggravating, I agree. I don't > know that they rose to the level of "disrespectful". > > I know that your behavior here is disrespectful. > > As to when the code of conduct is brought up, it's only fairly recently > that it has been mentioned in this forum. There have clearly been posts > in recent memory (the last year) which could have been examined in light > of the code of conduct, and were not. I think we are using it more > uniformly now. You helped me realize better how to apply it to this > forum, and I thank you for that. I welcome your help in applying it > better still. But it applies to you as well and I don't think it's too > much to ask that you abide by it. > > The way to improve this list is to respectfully point to and demonstrate > community norms and ask people to conform to them. Spewing vitriol > isn't going to fix anything. > > --Ned. > > BTW: I think Mark has kill-filed me, so if anyone agrees enough with me here to want Mark to see it, someone else will have to respond before he gets the text. --Ned. From breamoreboy at yahoo.co.uk Mon Dec 2 17:32:09 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 22:32:09 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 02/12/2013 22:24, Ned Batchelder wrote: > On 12/2/13 4:44 PM, Ned Batchelder wrote: >> On 12/2/13 3:45 PM, Mark Lawrence wrote: >>> On 02/12/2013 20:26, Terry Reedy wrote: >>>> On 12/2/2013 10:45 AM, Mark Lawrence wrote: >>>> >>>>> the worst loser in the world >>>> >>>> Mark, I consider your continual direct personal attacks on other >>>> posters >>>> to be a violation of the PSF Code of Conduct, which *does* apply to >>>> python-list. Please stop. >>>> >>> >>> The attacks that "Joseph McCarthy" has been launching on the core >>> developers for the last 15 months are in my view now perfectly >>> acceptable. This is excellent news. Everybody can now say what they >>> like about the core developers and there's no comeback. >>> >>> You can also stuff the code of conduct, it's quite clearly only brought >>> into play when it suits. Never, ever aim it at somebody who goes out of >>> their way to stir things up, always target it at the people who fight >>> back *IS THE RULE HERE*. >>> >> >> The point is that in this thread, no one was making attacks on core >> developers. You were bringing up old animosity here for no reason at >> all, and making them personal attacks to boot. >> >> I don't see how you think wxjmfauth was "going out of his way to stir >> things up" in *this* thread. He made three comments, none of which >> mentioned the FSR or any other controversial topic. Can't we respond to >> the content of posts, and not to past offenses by the poster? >> >> Additionally, wxjmfauth's past complaints about the flexible string >> representation were not personal. He didn't say, "Joe Smith is the >> worst loser in the world for writing the FSR". He complained about a >> feature of CPython, baselessly, but he never attacked the people doing >> the work. His continued complaints were aggravating, I agree. I don't >> know that they rose to the level of "disrespectful". >> >> I know that your behavior here is disrespectful. >> >> As to when the code of conduct is brought up, it's only fairly recently >> that it has been mentioned in this forum. There have clearly been posts >> in recent memory (the last year) which could have been examined in light >> of the code of conduct, and were not. I think we are using it more >> uniformly now. You helped me realize better how to apply it to this >> forum, and I thank you for that. I welcome your help in applying it >> better still. But it applies to you as well and I don't think it's too >> much to ask that you abide by it. >> >> The way to improve this list is to respectfully point to and demonstrate >> community norms and ask people to conform to them. Spewing vitriol >> isn't going to fix anything. >> >> --Ned. >> >> > > BTW: I think Mark has kill-filed me, so if anyone agrees enough with me > here to want Mark to see it, someone else will have to respond before he > gets the text. > > --Ned. > I've kill-filed you on my personnal email address which I asked you specifically *NOT* to message me on. You completely ignored that request. FTR you're only the second person I've ever done that to, the other being a pot smoking hippy who thankfully hasn't been seen for years. -- 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 Dec 2 17:53:28 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 17:53:28 -0500 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: On 12/2/13 5:32 PM, Mark Lawrence wrote: > On 02/12/2013 22:24, Ned Batchelder wrote: >> On 12/2/13 4:44 PM, Ned Batchelder wrote: >>> On 12/2/13 3:45 PM, Mark Lawrence wrote: >>>> On 02/12/2013 20:26, Terry Reedy wrote: >>>>> On 12/2/2013 10:45 AM, Mark Lawrence wrote: >>>>> >>>>>> the worst loser in the world >>>>> >>>>> Mark, I consider your continual direct personal attacks on other >>>>> posters >>>>> to be a violation of the PSF Code of Conduct, which *does* apply to >>>>> python-list. Please stop. >>>>> >>>> >>>> The attacks that "Joseph McCarthy" has been launching on the core >>>> developers for the last 15 months are in my view now perfectly >>>> acceptable. This is excellent news. Everybody can now say what they >>>> like about the core developers and there's no comeback. >>>> >>>> You can also stuff the code of conduct, it's quite clearly only brought >>>> into play when it suits. Never, ever aim it at somebody who goes >>>> out of >>>> their way to stir things up, always target it at the people who fight >>>> back *IS THE RULE HERE*. >>>> >>> >>> The point is that in this thread, no one was making attacks on core >>> developers. You were bringing up old animosity here for no reason at >>> all, and making them personal attacks to boot. >>> >>> I don't see how you think wxjmfauth was "going out of his way to stir >>> things up" in *this* thread. He made three comments, none of which >>> mentioned the FSR or any other controversial topic. Can't we respond to >>> the content of posts, and not to past offenses by the poster? >>> >>> Additionally, wxjmfauth's past complaints about the flexible string >>> representation were not personal. He didn't say, "Joe Smith is the >>> worst loser in the world for writing the FSR". He complained about a >>> feature of CPython, baselessly, but he never attacked the people doing >>> the work. His continued complaints were aggravating, I agree. I don't >>> know that they rose to the level of "disrespectful". >>> >>> I know that your behavior here is disrespectful. >>> >>> As to when the code of conduct is brought up, it's only fairly recently >>> that it has been mentioned in this forum. There have clearly been posts >>> in recent memory (the last year) which could have been examined in light >>> of the code of conduct, and were not. I think we are using it more >>> uniformly now. You helped me realize better how to apply it to this >>> forum, and I thank you for that. I welcome your help in applying it >>> better still. But it applies to you as well and I don't think it's too >>> much to ask that you abide by it. >>> >>> The way to improve this list is to respectfully point to and demonstrate >>> community norms and ask people to conform to them. Spewing vitriol >>> isn't going to fix anything. >>> >>> --Ned. >>> >>> >> >> BTW: I think Mark has kill-filed me, so if anyone agrees enough with me >> here to want Mark to see it, someone else will have to respond before he >> gets the text. >> >> --Ned. >> > > I've kill-filed you on my personnal email address which I asked you > specifically *NOT* to message me on. You completely ignored that > request. FTR you're only the second person I've ever done that to, the > other being a pot smoking hippy who thankfully hasn't been seen for years. > Yes, I've apologized for that faux pas. I hope that you can forgive me. Someday I hope to understand why it angered you so much. Good to hear that we can communicate here. --Ned. From ethan at stoneleaf.us Mon Dec 2 17:41:14 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Dec 2013 14:41:14 -0800 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: <529D0C8A.1070800@stoneleaf.us> On 12/02/2013 02:32 PM, Mark Lawrence wrote: > > ... the other being a pot smoking hippy who ... Please trim your posts. You comment a lot on people sending double-spaced google posts -- not trimming is nearly as bad. The above is a good example of unnecessary name calling. I value your good posts. Please keep a light-hearted and respectful tone. When light-hearted doesn't cut it, you can still be respectful (of the other readers, even if the offender doesn't deserve it). -- ~Ethan~ From ethan at stoneleaf.us Mon Dec 2 16:25:55 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Dec 2013 13:25:55 -0800 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> Message-ID: <529CFAE3.1070707@stoneleaf.us> On 12/02/2013 12:45 PM, Mark Lawrence wrote: > On 02/12/2013 20:26, Terry Reedy wrote: >> On 12/2/2013 10:45 AM, Mark Lawrence wrote: >> >>> the worst loser in the world >> >> Mark, I consider your continual direct personal attacks on other posters >> to be a violation of the PSF Code of Conduct, which *does* apply to >> python-list. Please stop. > > The attacks that "Joseph McCarthy" has been launching on the core developers for the last 15 months are in my view now > perfectly acceptable. This is excellent news. Everybody can now say what they like about the core developers and > there's no comeback. > > You can also stuff the code of conduct, it's quite clearly only brought into play when it suits. Never, ever aim it at > somebody who goes out of their way to stir things up, always target it at the people who fight back *IS THE RULE HERE*. Mark, I sympathize with your feelings. jmf is certainly a troll, and it doesn't feel like anything has been, or is being, done about that situation (or for that matter, the help vampire situation... although I haven't seen any threads from that one lately -- did he give up, or has he been moderated away?). However, I would suggest that when you are venting, you write the email and then just delete it. I personally don't mind the light and humorous posts, but when the name-calling starts it makes the list an unfriendly place to be. And, to be clear, the coddling of trolls and help-vampires also makes the list an unfriendly place to be. Terry, would it be appropriate to share some of what the moderators do do for us on this list and the others? And what does the Code of Conduct have to say about trolls and help-vampires? -- ~Ethan~ From breamoreboy at yahoo.co.uk Mon Dec 2 17:04:34 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 02 Dec 2013 22:04:34 +0000 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] In-Reply-To: <529CFAE3.1070707@stoneleaf.us> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: On 02/12/2013 21:25, Ethan Furman wrote: > On 12/02/2013 12:45 PM, Mark Lawrence wrote: >> On 02/12/2013 20:26, Terry Reedy wrote: >>> On 12/2/2013 10:45 AM, Mark Lawrence wrote: >>> >>>> the worst loser in the world >>> >>> Mark, I consider your continual direct personal attacks on other posters >>> to be a violation of the PSF Code of Conduct, which *does* apply to >>> python-list. Please stop. >> >> The attacks that "Joseph McCarthy" has been launching on the core >> developers for the last 15 months are in my view now >> perfectly acceptable. This is excellent news. Everybody can now say >> what they like about the core developers and >> there's no comeback. >> >> You can also stuff the code of conduct, it's quite clearly only >> brought into play when it suits. Never, ever aim it at >> somebody who goes out of their way to stir things up, always target it >> at the people who fight back *IS THE RULE HERE*. > > Mark, I sympathize with your feelings. jmf is certainly a troll, and > it doesn't feel like anything has been, or is being, done about that > situation (or for that matter, the help vampire situation... although I > haven't seen any threads from that one lately -- did he give up, or has > he been moderated away?). However, I would suggest that when you are > venting, you write the email and then just delete it. I personally > don't mind the light and humorous posts, but when the name-calling > starts it makes the list an unfriendly place to be. And, to be clear, > the coddling of trolls and help-vampires also makes the list an > unfriendly place to be. > > Terry, would it be appropriate to share some of what the moderators do > do for us on this list and the others? And what does the Code of > Conduct have to say about trolls and help-vampires? > > -- > ~Ethan~ I deleted the first really spiteful reply, but the hypocrisy that continues to be shown gets right up both of my nostrils, hence I couldn't resist the above, greatly toned down response. This will surely give an indication of how strongly I feel on issues such as this. Rules are rules to be applied evenly, not on a pick and choose basis. -- 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 Mon Dec 2 18:11:41 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Dec 2013 10:11:41 +1100 Subject: Code of Conduct, Trolls, and Thankless Jobs References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: <7wr49uonki.fsf@benfinney.id.au> Mark Lawrence writes: > [?] the hypocrisy that continues to be shown gets right up both of my > nostrils, hence I couldn't resist the above, greatly toned down > response. This will surely give an indication of how strongly I feel > on issues such as this. Rules are rules to be applied evenly, not on a > pick and choose basis. This forum doesn't have authorised moderators, and we don't have a body of state employees charged with meting out justice evenly to all parties. If you perceive uneven application of our code of conduct, that will go a long way to explaining it. What we do have is a community of volunteers whom we expect to both uphold the code of conduct and self-apply it to the extent feasible. This works only if we acknowledge both that we are human and will be inconsistent and make errors, and conversely that what we *intend* to do matters less than the actual and potential effects of our actions. Anyone who feels compelled to be vitriolic here needs to find a way to stop it, regardless how they perceive the treatment of others. We all need each other's efforts to keep this community healthy. -- \ ?I don't know half of you half as well as I should like, and I | `\ like less than half of you half as well as you deserve.? ?Bilbo | _o__) Baggins | Ben Finney From tjreedy at udel.edu Mon Dec 2 22:39:53 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Dec 2013 22:39:53 -0500 Subject: Code of Conduct, Trolls, and Thankless Jobs In-Reply-To: <7wr49uonki.fsf@benfinney.id.au> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> <7wr49uonki.fsf@benfinney.id.au> Message-ID: On 12/2/2013 6:11 PM, Ben Finney wrote: > This forum doesn't have authorised moderators, At least some PSF mailing lists have 1 or more PSF-authorized moderators (currently 4 for python-list) who pretty thanklessly check the initial posts of new subscribers and posts flagged by the spam detector as possible spam, or with other problems. We do not have 'every-post' moderation. > If you perceive uneven application of our code of conduct, As far as I know, there has been just one non-spam application of CoC to python-list: Nikos. I do not see how anyone could call that uneven or unfair. -- Terry Jan Reedy From ned at nedbatchelder.com Mon Dec 2 17:23:35 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 17:23:35 -0500 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] In-Reply-To: <529CFAE3.1070707@stoneleaf.us> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: On 12/2/13 4:25 PM, Ethan Furman wrote: > On 12/02/2013 12:45 PM, Mark Lawrence wrote: >> On 02/12/2013 20:26, Terry Reedy wrote: >>> On 12/2/2013 10:45 AM, Mark Lawrence wrote: >>> >>>> the worst loser in the world >>> >>> Mark, I consider your continual direct personal attacks on other posters >>> to be a violation of the PSF Code of Conduct, which *does* apply to >>> python-list. Please stop. >> >> The attacks that "Joseph McCarthy" has been launching on the core >> developers for the last 15 months are in my view now >> perfectly acceptable. This is excellent news. Everybody can now say >> what they like about the core developers and >> there's no comeback. >> >> You can also stuff the code of conduct, it's quite clearly only >> brought into play when it suits. Never, ever aim it at >> somebody who goes out of their way to stir things up, always target it >> at the people who fight back *IS THE RULE HERE*. > > Mark, I sympathize with your feelings. jmf is certainly a troll, and > it doesn't feel like anything has been, or is being, done about that > situation (or for that matter, the help vampire situation... although I > haven't seen any threads from that one lately -- did he give up, or has > he been moderated away?). However, I would suggest that when you are > venting, you write the email and then just delete it. I personally > don't mind the light and humorous posts, but when the name-calling > starts it makes the list an unfriendly place to be. And, to be clear, > the coddling of trolls and help-vampires also makes the list an > unfriendly place to be. > > Terry, would it be appropriate to share some of what the moderators do > do for us on this list and the others? And what does the Code of > Conduct have to say about trolls and help-vampires? > > -- > ~Ethan~ We have pointed help-vampires at the Code of Conduct: https://mail.python.org/pipermail/python-list/2013-November/660343.html He's also banned from the mailing list, which reduces the number of people who see his questions, and helps keep threads from exploding. For example, this message to the newsgroup https://groups.google.com/d/msg/comp.lang.python/fdhF_Fr4fX0/9B0iK8jGigkJ (sorry for the groups link, didn't know how else to link to a post) doesn't appear at all in the mailing list, and therefore, in gmane. But the mailing list ban isn't why you aren't seeing posts from him: he hasn't posted again since that linked message, on Nov 21. I think he's not posting in part because we adopted a uniform stance of politely refusing to answer his questions, or even completely ignoring his questions. Of course, he could be back at any time. I hope we'll continue to present a calm unified front. --Ned. From roy at panix.com Mon Dec 2 20:38:35 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Dec 2013 20:38:35 -0500 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: In article , Mark Lawrence wrote: > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. "I believe that Pythonistas should commit themselves to achieving the goal, before this decade is out, of making Python 3 the default version and having everybody be cool with unicode." From ethan at stoneleaf.us Mon Dec 2 20:56:14 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Dec 2013 17:56:14 -0800 Subject: Pythonista Goals [was Re: Code of Conduct, Trolls, and Thankless Jobs] In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: <529D3A3E.4060709@stoneleaf.us> On 12/02/2013 05:38 PM, Roy Smith wrote: > Mark Lawrence wrote: >> >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. > > "I believe that Pythonistas should commit themselves to achieving the > goal, before this decade is out, of making Python 3 the default version > and having everybody be cool with unicode." Hear, Hear! +1000! :D -- ~Ethan~ From invalid at invalid.invalid Mon Dec 2 23:32:13 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 3 Dec 2013 04:32:13 +0000 (UTC) Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: On 2013-12-03, Roy Smith wrote: > "I believe that Pythonistas should commit themselves to achieving the > goal, before this decade is out, of making Python 3 the default version > and having everybody be cool with unicode." I'm cool with Unicode as long as it "just works" without me ever having to understand it and I can interact effortlessly with plain old ASCII files. Evertime I start to read anything about Unicode with any technical detail at all, I start to get dizzy and bleed from the ears. -- Grant From steve at pearwood.info Tue Dec 3 00:41:07 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Dec 2013 05:41:07 GMT Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: <529d6ef2$0$11113$c3e8da3@news.astraweb.com> On Tue, 03 Dec 2013 04:32:13 +0000, Grant Edwards wrote: > On 2013-12-03, Roy Smith wrote: > >> "I believe that Pythonistas should commit themselves to achieving the >> goal, before this decade is out, of making Python 3 the default version >> and having everybody be cool with unicode." > > I'm cool with Unicode as long as it "just works" without me ever having > to understand it That will never happen. Unicode is a bit like floating point maths: there's always *some* odd corner case that will lead to annoyance and confusion and even murder: http://gizmodo.com/382026/a-cellphones-missing-dot-kills-two-people-puts-three-more-in-jail And then there are legacy encodings. There are three things in life that are inevitable: death, taxes, and text with the wrong encoding. Anyone dealing with text they didn't generate themselves is going to have to deal with mojibake at some point. Having said that, if you control the text and always use UTF-8 for storage and transmission, Unicode isn't that hard. Decode bytes to Unicode as early as possible, do all your work in text rather than bytes, then encode back to bytes as late as possible, and you'll be fine. > and I can interact effortlessly with plain old ASCII files. That at least is easy, provided you can guarantee that what you think if plain ol' ASCII actually is plain ol' ASCII, which isn't as easy as you might think given that an awful lot of people think that "extended ASCII" is a thing and that you ought to be able to deal with it just like ASCII. > Evertime I start to read anything about Unicode with any > technical detail at all, I start to get dizzy and bleed from the ears. Heh, the standard certainly covers a lot of ground. -- Steven From breamoreboy at yahoo.co.uk Tue Dec 3 07:14:52 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Dec 2013 12:14:52 +0000 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: On 03/12/2013 04:32, Grant Edwards wrote: > On 2013-12-03, Roy Smith wrote: > >> "I believe that Pythonistas should commit themselves to achieving the >> goal, before this decade is out, of making Python 3 the default version >> and having everybody be cool with unicode." > > I'm cool with Unicode as long as it "just works" without me ever > having to understand it and I can interact effortlessly with plain old > ASCII files. Evertime I start to read anything about Unicode with any > technical detail at all, I start to get dizzy and bleed from the ears. > I'm pleased to see that I'm not the only one who suffers in this way :) -- 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 Tue Dec 3 07:11:50 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Dec 2013 12:11:50 +0000 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: On 03/12/2013 01:38, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. > > "I believe that Pythonistas should commit themselves to achieving the > goal, before this decade is out, of making Python 3 the default version > and having everybody be cool with unicode." > I like that, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Mon Dec 2 22:22:21 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Dec 2013 22:22:21 -0500 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] In-Reply-To: <529CFAE3.1070707@stoneleaf.us> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: On 12/2/2013 4:25 PM, Ethan Furman wrote: > jmf is certainly a troll No, he is a person who discovered a minor performance regression in the FSR, which we fixed. Unfortunately, he then continued for a year with a strange troll-like anti-FSR crusade. But his posts in the Unicode handling thread were not part of that. It seems to me that continually beating someone over the head with the past discourages changed behavior. To me, the point of asking someone to 'stop' is to persuade them to stop. The reward for stopping should be to let the issue go. > haven't seen any threads from that one lately -- did he give up, or has > he been moderated away?). Action was taken, including changing the usenet (clr) to mailing-list gateway. (I already mentioned this twice here.) The was done by one of the mailman infrastructure people at the request of the list owner/moderators. The people who stuck their necks out to privately contact the person in question displeased him and got privately mail-bombed with repeated insults. I guess he subsequently gave up. > the coddling of trolls and help-vampires also makes the list an > unfriendly place to be. I agree with the that as a statement, but not the implication. Was I hallucinating, or did you not recently participate in the discussion and decision to stop coddling our most obnoxious 'troll' in the community? > Terry, would it be appropriate to share some of what the moderators do > do for us on this list and the others? Python-list moderators discard perhaps one spam post a day. You already noticed a recent major benefit. > And what does the Code of > Conduct have to say about trolls and help-vampires? I need to re-read it to really answer that adequately. The term and defined concept 'help-vampire' is new to me (as of a month ago) and probably to the CoC writers. However, the behavior strikes me as disrespectful of the community, and that *is* generically covered. -- Terry Jan Reedy From ethan at stoneleaf.us Mon Dec 2 23:11:47 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Dec 2013 20:11:47 -0800 Subject: Code of Conduct, Trolls, and Thankless Jobs [was Re: Python Unicode handling wins again -- mostly] In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <23ee5279-bdfd-4fb0-b535-042f7c3bab23@googlegroups.com> <529CFAE3.1070707@stoneleaf.us> Message-ID: <529D5A03.8020007@stoneleaf.us> On 12/02/2013 07:22 PM, Terry Reedy wrote: > On 12/2/2013 4:25 PM, Ethan Furman wrote: >> jmf is certainly a troll > > No, he is a person who discovered a minor performance regression in the FSR, which we fixed. Unfortunately, he then > continued for a year with a strange troll-like anti-FSR crusade. But his posts in the Unicode handling thread were not > part of that. It seems to me that continually beating someone over the head with the past discourages changed behavior. > To me, the point of asking someone to 'stop' is to persuade them to stop. The reward for stopping should be to let the > issue go. I remember it slightly differently, but you're right -- we should let it drop. >> the coddling of trolls and help-vampires also makes the list an >> unfriendly place to be. > > I agree with the that as a statement, but not the implication. Was I hallucinating, or did you not recently participate > in the discussion and decision to stop coddling our most obnoxious 'troll' in the community? I'm afraid I don't see the point you are trying to make. I'm against coddling those who refuse to learn and participate with respect to the rest of us, and I did vote to stop such coddling [1] of a certain troll. I don't see the discrepancy. All that aside, thank you to you and the other moderators for your time and efforts. -- ~Ethan~ [1] Coddling can be an offensive word, and I wish to make clear that initial efforts to educate and help newcomers are appropriate and warranted. However, after some time has passed and the newcomer is no longer a newcomer and is still exhibiting rude and ignorant behavior, further attempts to help most likely won't, and that is when I would classify such attempts as coddling. -- ~Ethan~ From ethan at stoneleaf.us Mon Dec 2 15:38:09 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Dec 2013 12:38:09 -0800 Subject: Python Unicode handling wins again -- mostly In-Reply-To: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <529CEFB1.2030007@stoneleaf.us> On 11/29/2013 04:44 PM, Steven D'Aprano wrote: > > Out of the nine tests, Python 3.3 passes six, with three tests being > failures or dubious. If you believe that the native string type should > operate on code-points, then you'll think that Python does the right > thing. I think Python is doing it correctly. If I want to operate on "clusters" I'll normalize the string first. Thanks for this excellent post. -- ~Ethan~ From ned at nedbatchelder.com Mon Dec 2 16:14:13 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 02 Dec 2013 16:14:13 -0500 Subject: Python Unicode handling wins again -- mostly In-Reply-To: <529CEFB1.2030007@stoneleaf.us> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: On 12/2/13 3:38 PM, Ethan Furman wrote: > On 11/29/2013 04:44 PM, Steven D'Aprano wrote: >> >> Out of the nine tests, Python 3.3 passes six, with three tests being >> failures or dubious. If you believe that the native string type should >> operate on code-points, then you'll think that Python does the right >> thing. > > I think Python is doing it correctly. If I want to operate on > "clusters" I'll normalize the string first. > > Thanks for this excellent post. > > -- > ~Ethan~ This is where my knowledge about Unicode gets fuzzy. Isn't it the case that some grapheme clusters (or whatever the right word is) can't be normalized down to a single code point? Characters can accept many accents, for example. In that case, you can't always normalize and use the existing string methods, but would need more specialized code. --Ned. From rosuav at gmail.com Mon Dec 2 16:23:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Dec 2013 08:23:02 +1100 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: On Tue, Dec 3, 2013 at 8:14 AM, Ned Batchelder wrote: > This is where my knowledge about Unicode gets fuzzy. Isn't it the case that > some grapheme clusters (or whatever the right word is) can't be normalized > down to a single code point? Characters can accept many accents, for > example. You can't normalize everything down to a single code point, but you can normalize the other way by breaking out everything that can be broken out. >>> print(ascii(unicodedata.normalize("NFKC", "?"))) '\xe4' >>> print(ascii(unicodedata.normalize("NFKD", "?"))) 'a\u0308' ChrisA From ethan at stoneleaf.us Mon Dec 2 16:27:08 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Dec 2013 13:27:08 -0800 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: <529CFB2C.2000803@stoneleaf.us> On 12/02/2013 01:23 PM, Chris Angelico wrote: > On Tue, Dec 3, 2013 at 8:14 AM, Ned Batchelder wrote: >> This is where my knowledge about Unicode gets fuzzy. Isn't it the case that >> some grapheme clusters (or whatever the right word is) can't be normalized >> down to a single code point? Characters can accept many accents, for >> example. > > You can't normalize everything down to a single code point, but you > can normalize the other way by breaking out everything that can be > broken out. > >>>> print(ascii(unicodedata.normalize("NFKC", "?"))) > '\xe4' >>>> print(ascii(unicodedata.normalize("NFKD", "?"))) > 'a\u0308' Well, Stephen was right then! There's room for a library to handle this situation. Or is there one already? -- ~Ethan~ From python at mrabarnett.plus.com Mon Dec 2 16:27:23 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Dec 2013 21:27:23 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: <529CFB3B.10504@mrabarnett.plus.com> On 02/12/2013 21:14, Ned Batchelder wrote: > On 12/2/13 3:38 PM, Ethan Furman wrote: >> On 11/29/2013 04:44 PM, Steven D'Aprano wrote: >>> >>> Out of the nine tests, Python 3.3 passes six, with three tests being >>> failures or dubious. If you believe that the native string type should >>> operate on code-points, then you'll think that Python does the right >>> thing. >> >> I think Python is doing it correctly. If I want to operate on >> "clusters" I'll normalize the string first. >> >> Thanks for this excellent post. >> >> -- >> ~Ethan~ > > This is where my knowledge about Unicode gets fuzzy. Isn't it the case > that some grapheme clusters (or whatever the right word is) can't be > normalized down to a single code point? Characters can accept many > accents, for example. In that case, you can't always normalize and use > the existing string methods, but would need more specialized code. > A better way of saying it is that there are codepoints for some grapheme clusters. Those 'precomposed' codepoints exist because some legacy character sets contained them, and having a one-to-one mapping encouraged Unicode's adoption. From ben+python at benfinney.id.au Mon Dec 2 17:56:57 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Dec 2013 09:56:57 +1100 Subject: Python Unicode handling wins again -- mostly References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: <7wvbz6oo92.fsf@benfinney.id.au> Ned Batchelder writes: > This is where my knowledge about Unicode gets fuzzy. Isn't it the > case that some grapheme clusters (or whatever the right word is) can't > be normalized down to a single code point? Characters can accept many > accents, for example. That's true, but doesn't affect the point being made: that one can have both ?sequence of Unicode code points? in Python's ?unicode? (now ?str?) type, and also deal with ?sequence of text the reader will see?. > In that case, you can't always normalize and use the existing string > methods, but would need more specialized code. Specialised code may not be needed. It will at least be true that ?any two code-point sequences which normalise to the same value will be visually the same for the reader?, which is an important assertion for addressing the complaints from Mortoray's article. -- \ ?Pray, v. To ask that the laws of the universe be annulled in | `\ behalf of a single petitioner confessedly unworthy.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From steve at pearwood.info Tue Dec 3 00:06:26 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Dec 2013 05:06:26 GMT Subject: Python Unicode handling wins again -- mostly References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: <529d66d1$0$11113$c3e8da3@news.astraweb.com> On Mon, 02 Dec 2013 16:14:13 -0500, Ned Batchelder wrote: > On 12/2/13 3:38 PM, Ethan Furman wrote: >> On 11/29/2013 04:44 PM, Steven D'Aprano wrote: >>> >>> Out of the nine tests, Python 3.3 passes six, with three tests being >>> failures or dubious. If you believe that the native string type should >>> operate on code-points, then you'll think that Python does the right >>> thing. >> >> I think Python is doing it correctly. If I want to operate on >> "clusters" I'll normalize the string first. >> >> Thanks for this excellent post. >> >> -- >> ~Ethan~ > > This is where my knowledge about Unicode gets fuzzy. Isn't it the case > that some grapheme clusters (or whatever the right word is) can't be > normalized down to a single code point? Characters can accept many > accents, for example. In that case, you can't always normalize and use > the existing string methods, but would need more specialized code. That is correct. If Unicode had a distinct code point for every possible combination of base-character plus an arbitrary number of diacritics or accents, the 0x10FFFF code points wouldn't be anywhere near enough. I see over 300 diacritics used just in the first 5000 code points. Let's pretend that's only 100, and that you can use up to a maximum of 5 at a time. That gives 79375496 combinations per base character, much larger than the total number of Unicode code points in total. If anyone wishes to check my logic: # count distinct combining chars import unicodedata s = ''.join(chr(i) for i in range(33, 5000)) s = unicodedata.normalize('NFD', s) t = [c for c in s if unicodedata.combining(c)] len(set(t)) # calculate the number of combinations def comb(r, n): """Combinations nCr""" p = 1 for i in range(r+1, n+1): p *= i for i in range(1, n-r+1): p /= i return p sum(comb(i, 100) for i in range(6)) I'm not suggesting that all of those accents are necessarily in use in the real world, but there are languages which construct arbitrary combinations of accents. (Or so I have been lead to believe.) -- Steven From joeedh at gmail.com Tue Dec 3 02:35:29 2013 From: joeedh at gmail.com (joe) Date: Mon, 2 Dec 2013 23:35:29 -0800 Subject: Python Unicode handling wins again -- mostly In-Reply-To: <529d66d1$0$11113$c3e8da3@news.astraweb.com> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> <529d66d1$0$11113$c3e8da3@news.astraweb.com> Message-ID: How would a grapheme library work? Basic cluster combination, or would implementing other algorithms (line break, normalizing to a "canonical" form) be necessary? How do people use grapheme clusters in non-rendering situations? Or here's perhaps here's a better question: does anyone know any non-latin (Japanese and Arabic come to mind) speakers who use python to process text in their own language? Who could perhaps tell us what most bugs them about python's current api and which standard libraries need work. On Dec 2, 2013 10:10 PM, "Steven D'Aprano" wrote: > On Mon, 02 Dec 2013 16:14:13 -0500, Ned Batchelder wrote: > > > On 12/2/13 3:38 PM, Ethan Furman wrote: > >> On 11/29/2013 04:44 PM, Steven D'Aprano wrote: > >>> > >>> Out of the nine tests, Python 3.3 passes six, with three tests being > >>> failures or dubious. If you believe that the native string type should > >>> operate on code-points, then you'll think that Python does the right > >>> thing. > >> > >> I think Python is doing it correctly. If I want to operate on > >> "clusters" I'll normalize the string first. > >> > >> Thanks for this excellent post. > >> > >> -- > >> ~Ethan~ > > > > This is where my knowledge about Unicode gets fuzzy. Isn't it the case > > that some grapheme clusters (or whatever the right word is) can't be > > normalized down to a single code point? Characters can accept many > > accents, for example. In that case, you can't always normalize and use > > the existing string methods, but would need more specialized code. > > That is correct. > > If Unicode had a distinct code point for every possible combination of > base-character plus an arbitrary number of diacritics or accents, the > 0x10FFFF code points wouldn't be anywhere near enough. > > I see over 300 diacritics used just in the first 5000 code points. Let's > pretend that's only 100, and that you can use up to a maximum of 5 at a > time. That gives 79375496 combinations per base character, much larger > than the total number of Unicode code points in total. > > If anyone wishes to check my logic: > > # count distinct combining chars > import unicodedata > s = ''.join(chr(i) for i in range(33, 5000)) > s = unicodedata.normalize('NFD', s) > t = [c for c in s if unicodedata.combining(c)] > len(set(t)) > > # calculate the number of combinations > def comb(r, n): > """Combinations nCr""" > p = 1 > for i in range(r+1, n+1): > p *= i > for i in range(1, n-r+1): > p /= i > return p > > sum(comb(i, 100) for i in range(6)) > > > I'm not suggesting that all of those accents are necessarily in use in > the real world, but there are languages which construct arbitrary > combinations of accents. (Or so I have been lead to believe.) > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Tue Dec 3 13:34:59 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 3 Dec 2013 10:34:59 -0800 (PST) Subject: Python Unicode handling wins again -- mostly In-Reply-To: <529d66d1$0$11113$c3e8da3@news.astraweb.com> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> <529d66d1$0$11113$c3e8da3@news.astraweb.com> Message-ID: Le mardi 3 d?cembre 2013 06:06:26 UTC+1, Steven D'Aprano a ?crit?: > On Mon, 02 Dec 2013 16:14:13 -0500, Ned Batchelder wrote: > > > > > On 12/2/13 3:38 PM, Ethan Furman wrote: > > >> On 11/29/2013 04:44 PM, Steven D'Aprano wrote: > > >>> > > >>> Out of the nine tests, Python 3.3 passes six, with three tests being > > >>> failures or dubious. If you believe that the native string type should > > >>> operate on code-points, then you'll think that Python does the right > > >>> thing. > > >> > > >> I think Python is doing it correctly. If I want to operate on > > >> "clusters" I'll normalize the string first. > > >> > > >> Thanks for this excellent post. > > >> > > >> -- > > >> ~Ethan~ > > > > > > This is where my knowledge about Unicode gets fuzzy. Isn't it the case > > > that some grapheme clusters (or whatever the right word is) can't be > > > normalized down to a single code point? Characters can accept many > > > accents, for example. In that case, you can't always normalize and use > > > the existing string methods, but would need more specialized code. > > > > That is correct. > > > > If Unicode had a distinct code point for every possible combination of > > base-character plus an arbitrary number of diacritics or accents, the > > 0x10FFFF code points wouldn't be anywhere near enough. > > > > I see over 300 diacritics used just in the first 5000 code points. Let's > > pretend that's only 100, and that you can use up to a maximum of 5 at a > > time. That gives 79375496 combinations per base character, much larger > > than the total number of Unicode code points in total. > > > > If anyone wishes to check my logic: > > > > # count distinct combining chars > > import unicodedata > > s = ''.join(chr(i) for i in range(33, 5000)) > > s = unicodedata.normalize('NFD', s) > > t = [c for c in s if unicodedata.combining(c)] > > len(set(t)) > > > > # calculate the number of combinations > > def comb(r, n): > > """Combinations nCr""" > > p = 1 > > for i in range(r+1, n+1): > > p *= i > > for i in range(1, n-r+1): > > p /= i > > return p > > > > sum(comb(i, 100) for i in range(6)) > > > > > > I'm not suggesting that all of those accents are necessarily in use in > > the real world, but there are languages which construct arbitrary > > combinations of accents. (Or so I have been lead to believe.) > > > from one of my libs, bmp only >>> import fourbiunicode5 >>> print(len(fourbiunicode5.AllCombiningMarks)) 240 jmf From neilc at norwich.edu Tue Dec 3 08:47:42 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 3 Dec 2013 13:47:42 +0000 (UTC) Subject: Python Unicode handling wins again -- mostly References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: On 2013-12-02, Ethan Furman wrote: > On 11/29/2013 04:44 PM, Steven D'Aprano wrote: >> Out of the nine tests, Python 3.3 passes six, with three tests >> being failures or dubious. If you believe that the native >> string type should operate on code-points, then you'll think >> that Python does the right thing. > > I think Python is doing it correctly. If I want to operate on > "clusters" I'll normalize the string first. Normalizing doesn't resolve the issues the blog brings up; NFC can't condense every multi-code-point sequence into one, and normalizing can lose or mangle information. There are good examples here: http://unicode.org/reports/tr15/ > Thanks for this excellent post. Agreed. -- Neil Cerutti From ethan at stoneleaf.us Tue Dec 3 09:26:45 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Dec 2013 06:26:45 -0800 Subject: Python Unicode handling wins again -- mostly In-Reply-To: <529CEFB1.2030007@stoneleaf.us> References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: <529DEA25.2000703@stoneleaf.us> On 12/02/2013 12:38 PM, Ethan Furman wrote: > On 11/29/2013 04:44 PM, Steven D'Aprano wrote: >> >> Out of the nine tests, Python 3.3 passes six, with three tests being >> failures or dubious. If you believe that the native string type should >> operate on code-points, then you'll think that Python does the right >> thing. > > I think Python is doing it correctly. If I want to operate on "clusters" I'll normalize the string first. Hrmm, well, after being educated ;) I think I may have to reverse my position. Given that not every cluster can be normalized to a single code point perhaps Python is doing it the best possible way. On the other hand, we have a uni*code* type, not a uni*char* type. Maybe 3.5 can have that. ;) At any rate, definitely good to be aware of the issue. -- ~Ethan~ From wxjmfauth at gmail.com Wed Dec 4 08:52:34 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 4 Dec 2013 05:52:34 -0800 (PST) Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: Le mardi 3 d?cembre 2013 15:26:45 UTC+1, Ethan Furman a ?crit?: > On 12/02/2013 12:38 PM, Ethan Furman wrote: > > > On 11/29/2013 04:44 PM, Steven D'Aprano wrote: > > >> > > >> Out of the nine tests, Python 3.3 passes six, with three tests being > > >> failures or dubious. If you believe that the native string type should > > >> operate on code-points, then you'll think that Python does the right > > >> thing. > > > > > > I think Python is doing it correctly. If I want to operate on "clusters" I'll normalize the string first. > > > > Hrmm, well, after being educated ;) I think I may have to reverse my position. Given that not every cluster can be > > normalized to a single code point perhaps Python is doing it the best possible way. On the other hand, we have a > > uni*code* type, not a uni*char* type. Maybe 3.5 can have that. ;) > > ------ Yon intuitively pointed a very important feature of "unicode". However, it is not necessary, this is exactly what unicode does (when used properly). jmf From breamoreboy at yahoo.co.uk Wed Dec 4 09:07:34 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 14:07:34 +0000 Subject: Python Unicode handling wins again -- mostly In-Reply-To: References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: On 04/12/2013 13:52, wxjmfauth at gmail.com wrote: [snip all the double spaced stuff] > > Yon intuitively pointed a very important feature > of "unicode". However, it is not necessary, this is > exactly what unicode does (when used properly). > > jmf > Presumably using unicode correctly prevents messages being sent across the ether with superfluous, extremely irritating double spacing? Or is that down to poor tools in combination with the ignorance of their users? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From neilc at norwich.edu Wed Dec 4 09:38:40 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 4 Dec 2013 14:38:40 +0000 (UTC) Subject: Python Unicode handling wins again -- mostly References: <529934dc$0$29993$c3e8da3$5496439d@news.astraweb.com> <529CEFB1.2030007@stoneleaf.us> Message-ID: On 2013-12-04, wxjmfauth at gmail.com wrote: > Yon intuitively pointed a very important feature of "unicode". > However, it is not necessary, this is exactly what unicode does > (when used properly). Unicode only provides character sets. It's not a natural language parsing facility. -- Neil Cerutti From rosuav at gmail.com Sun Dec 1 00:03:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Dec 2013 16:03:17 +1100 Subject: Change a file type in Python? In-Reply-To: References: <37c37e04-87f1-42d3-ae24-0c159281aa46@googlegroups.com> Message-ID: On Sun, Dec 1, 2013 at 3:58 PM, rusi wrote: > I think we are dealing with 3 completely separable problems: > [Slightly changing what I earlier wrote?] > > 1. Undesirable elements -- spam, troll and more exotic > 2. Immature noobs -- literally or almost literally kids > 3. Stupid technology -- in this case, GG > > The anti-GG crusade is getting pissed-off with 1 and/or 2 and then > attacking 3. Most of it is getting annoyed at the results of 3, and then attacking 3. That's what I do, at least. There have been several people who've switched to email as a result of being told that their posts are coming out looking ugly; their posts subsequently are NOT ugly, and they always had useful content in them, so they become productive and highly welcome members of the community without being masked behind buggy technology. Nothing to do with immaturity or spam. ChrisA From steve+comp.lang.python at pearwood.info Sun Dec 1 06:20:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2013 11:20:18 GMT Subject: Change a file type in Python? References: <37c37e04-87f1-42d3-ae24-0c159281aa46@googlegroups.com> Message-ID: <529b1b72$0$29993$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 Dec 2013 16:03:17 +1100, Chris Angelico wrote: > Most of it is getting annoyed at the results of 3, and then attacking 3. I know the feeling. I've never trusted 3, I've always felt that it's plotting something. And it looks like half an 8, but it's not. What's with that? -- Steven From breamoreboy at yahoo.co.uk Sun Dec 1 06:20:31 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 01 Dec 2013 11:20:31 +0000 Subject: Change a file type in Python? In-Reply-To: References: Message-ID: On 01/12/2013 00:04, Eamonn Rea wrote: > Thanks for the help! > > Ok, I'll look into the mailing list. > It's very useful, you can even see things in context, which is conspicious by its absence above :) -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence From jadec375 at msn.com Sun Dec 1 13:27:16 2013 From: jadec375 at msn.com (jade) Date: Sun, 1 Dec 2013 18:27:16 +0000 Subject: Checking Common File Types Message-ID: Hello, I'm trying to create a script that checks all the files in my 'downloaded' directory against common file types and then tells me how many of the files in that directory aren't either a GIF or a JPG file. I'm familiar with basic Python but this is the first time I've attempted anything like this and I'm looking for a little help or a point in the right direction? file_sigs = {'\xFF\xD8\xFF':('JPEG','jpg'), '\x47\x49\x46':('GIF','gif')} def readFile(): filename = r'c:/temp/downloads' fh = open(filename, 'r') file_sig = fh.read(4) print '[*] check_sig() File:',filename #, 'Hash Sig:', binascii.hexlify(file_sig) RegardsJade -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Dec 1 17:49:54 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Dec 2013 09:49:54 +1100 Subject: Checking Common File Types In-Reply-To: References: Message-ID: On Mon, Dec 2, 2013 at 5:27 AM, jade wrote: > file_sigs = {'\xFF\xD8\xFF':('JPEG','jpg'), > '\x47\x49\x46':('GIF','gif')} > > file_sig = fh.read(4) You're reading in four bytes, but your signatures are three bytes long. :) After that, all you need to do is look up file_sig in the file_sigs dictionary, and see if anything's there. Look at the Python docs for the dict type; there's an easy way to do this. ChrisA From jadec375 at msn.com Sun Dec 1 18:41:15 2013 From: jadec375 at msn.com (jade) Date: Sun, 1 Dec 2013 23:41:15 +0000 Subject: Checking Common File Types In-Reply-To: References: , Message-ID: > To: python-list at python.org > From: wlfraed at ix.netcom.com > Subject: Re: Checking Common File Types > Date: Sun, 1 Dec 2013 18:23:22 -0500 > > On Sun, 1 Dec 2013 18:27:16 +0000, jade declaimed the > following: > > >Hello, > >I'm trying to create a script that checks all the files in my 'downloaded' directory against common file types and then tells me how many of the files in that directory aren't either a GIF or a JPG file. I'm familiar with basic Python but this is the first time I've attempted anything like this and I'm looking for a little help or a point in the right direction? > > > >file_sigs = {'\xFF\xD8\xFF':('JPEG','jpg'), '\x47\x49\x46':('GIF','gif')} > > Apparently you presume the file extensions are inaccurate, as you are > digging into the files for signatures. > > >def readFile(): filename = r'c:/temp/downloads' fh = open(filename, 'r') file_sig = fh.read(4) print '[*] check_sig() File:',filename #, 'Hash Sig:', binascii.hexlify(file_sig) > > Note: if you are hardcoding forward slashes, you don't need the raw > indicator... > > That said, what is "c:/temp/downloads"? You apparently are opening IT > as the file to be examined. Is it supposed to be a directory containing > many files, a file containing a list of files, ??? > > What is "check_sig" -- it looks like a function you haven't defined -- > but it's inside the quotes making a string literal that will never be > called anyway. > > If you are just concerned with one directory of files, you might want > to read the help file on the glob module, along with os.path > (join/splitext/etc). Or just string methods... > > >>> import glob > >>> import os.path > >>> TARGET = os.path.join(os.environ["USERPROFILE"], > ... "documents/BW-conversion/*") > >>> TARGET = os.path.join(os.environ["USERPROFILE"], > ... "documents/BW-conversion/*") > >>> files = glob.glob(TARGET) > >>> for fn in files: > ... fp, fx = os.path.splitext(fn) > ... print "File %s purports to be of type %s" % (fn, fx.upper()) > ... > File C:\Users\Wulfraed\documents/BW-conversion\BW-1.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\BW-2.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\BW-3.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\BW-4.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\BWConv.html purports to be > of type .HTML > File C:\Users\Wulfraed\documents/BW-conversion\roo_b1.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\roo_b2.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\roo_b3.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\roo_b4.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\roo_b5.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\roo_b6.jpg purports to be of > type .JPG > File C:\Users\Wulfraed\documents/BW-conversion\roo_col.jpg purports to be > of type .JPG > >>> > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list Hi, thanks for all your replies. I realised pretty soon after I asked for help that I was trying to read the wrong amount of bytes and set about completely rewriting my code (after a coffee break) import sys, os, binascii def readfile(): dictionary = {'474946':('GIF', 'gif'), 'ffd8ff':('JPEG', 'jpeg')} try: files = os.listdir('C:\\Temp\\downloads') for item in files: f = open('C:\\Temp\\downloads\\'+ item, 'r') file_sig = f.read(3) file_sig_hex = binascii.hexlify(file_sig) if file_sig_hex in dictionary: print item + ' is a image file, it is a ' + file_sig else: print item + ' is not an image file, it is' +file_sig print file_sig_hex except: print 'Error. Try again' finally: if 'f' in locals(): f.close() def main(): readfile() if __name__ == '__main__': main() As of right now my script prints out 'Error Try again' but when i comment out this part of the code; if file_sig_hex in dictionary: print item + ' is a image file' + dictionary else: print item + ' is not an image file, is it' +dictionary it prints the file signatures to the screen, however what I'm trying to do with the if statement is tell me if the file is an image and give me is signature and if it is not, I want it to tell me and still give me it's signature and tell me what type of file it is. Can anyone point out an obvious error? RegardsJade -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Sun Dec 1 22:05:42 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 1 Dec 2013 19:05:42 -0800 (PST) Subject: Checking Common File Types In-Reply-To: References: ,> Message-ID: On Monday, December 2, 2013 5:11:15 AM UTC+5:30, jade wrote: > > To: pytho... at python.org > > From: wlf... at ix.netcom.com > > Subject: Re: Checking Common File Types > > Date: Sun, 1 Dec 2013 18:23:22 -0500 > > > > On Sun, 1 Dec 2013 18:27:16 +0000, jade declaimed the > > following: > > > > >Hello, > > >I'm trying to create a script that checks all the files in my 'downloaded' directory against common file types and then tells me how many of the files in that directory aren't either a GIF or a JPG file. I'm familiar with basic Python but this is the first time I've attempted anything like this and I'm looking for a little help or a point in the right direction? > > > > > >file_sigs = {'\xFF\xD8\xFF':('JPEG','jpg'), '\x47\x49\x46':('GIF','gif')} > > > > Apparently you presume the file extensions are inaccurate, as you are > > digging into the files for signatures. > > > > >def readFile(): filename = r'c:/temp/downloads' fh = open(filename, 'r') file_sig = fh.read(4) print '[*] check_sig() File:',filename #, 'Hash Sig:', binascii.hexlify(file_sig) > > > > Note: if you are hardcoding forward slashes, you don't need the raw > > indicator... > > > > That said, what is "c:/temp/downloads"? You apparently are opening IT > > as the file to be examined. Is it supposed to be a directory containing > > many files, a file containing a list of files, ??? > > > > What is "check_sig" -- it looks like a function you haven't defined -- > > but it's inside the quotes making a string literal that will never be > > called anyway. > > > > If you are just concerned with one directory of files, you might want > > to read the help file on the glob module, along with os.path > > (join/splitext/etc). Or just string methods... > > > > >>> import glob > > >>> import os.path > > >>> TARGET = os.path.join(os.environ["USERPROFILE"], > > ... "documents/BW-conversion/*") > > >>> TARGET = os.path.join(os.environ["USERPROFILE"], > > ... "documents/BW-conversion/*") > > >>> files = glob.glob(TARGET) > > >>> for fn in files: > > ... fp, fx = os.path.splitext(fn) > > ... print "File %s purports to be of type %s" % (fn, fx.upper()) > > ... > > File C:\Users\Wulfraed\documents/BW-conversion\BW-1.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\BW-2.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\BW-3.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\BW-4.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\BWConv.html purports to be > > of type .HTML > > File C:\Users\Wulfraed\documents/BW-conversion\roo_b1.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\roo_b2.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\roo_b3.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\roo_b4.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\roo_b5.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\roo_b6.jpg purports to be of > > type .JPG > > File C:\Users\Wulfraed\documents/BW-conversion\roo_col.jpg purports to be > > of type .JPG > > >>> > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlf... at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > Hi, thanks for all your replies. I realised pretty soon after I asked for help that I was trying to read the wrong amount of bytes and set about completely rewriting my code (after a coffee break) > > import sys, os, binascii > > def readfile(): > > > ? ? dictionary = {'474946':('GIF', 'gif'), 'ffd8ff':('JPEG', 'jpeg')} > ? ? try: > ? ? ? ? files = os.listdir('C:\\Temp\\downloads') ? ? ? ? > ? ? ? ? for item in files: > ? ? ? ? ? ? f = open('C:\\Temp\\downloads\\'+ item, 'r') > ? ? ? ? ? ? file_sig = f.read(3) > ? ? ? ? ? ? file_sig_hex = binascii.hexlify(file_sig) > ? ? ? ? ? ? ? ? ? ? ? ?? > ? ? ? ? ? ? if file_sig_hex in dictionary: > ? ? ? ? ? ? ? ? print item + ' is a image file, it is a ' + file_sig > > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? print item + ' is not an image file, it is' +file_sig > > ? ? ? ? ? ? print file_sig_hex > > ? ?? > > ? ? except: > ? ? ? ? print 'Error. Try again' > > ? ? finally: > ? ? ? ? if 'f' in locals(): > ? ? ? ? ? ? f.close() > > def main(): > ? > ? ? readfile() > > if __name__ == '__main__': > ? ? main() > > As of right now my script prints out 'Error Try again' but when i comment out this part of the code; > > ? ? ? ? ? if file_sig_hex in dictionary: > ? ? ? ? ? ? ? ? print item + ' is a image file' + dictionary? > > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? print item + ' is not an image file, is it' +dictionary? > > ? ? ? ? ? ?? > > it prints the file signatures to the screen, however what I'm trying to do with the if statement is tell me if the file is an image and give me is signature and if it is not, I want it to tell me and still give me it's signature and tell me what type of file it is. Can anyone point out an obvious error?? You are catching all exceptions -- that garbages all the debugging finesse that python offers you. Dont. http://stackoverflow.com/questions/10594113/bad-idea-to-catch-all-exceptions-in-python On a different note: You seem to be using google groups. It causes some nuisance to people: https://wiki.python.org/moin/GoogleGroupsPython Heres a more automated solution see my post here: https://groups.google.com/forum/#!topic/comp.lang.python/Cf6adRN3KGs From grumsk at grumsk.tz Sun Dec 1 14:18:58 2013 From: grumsk at grumsk.tz (G.) Date: 01 Dec 2013 19:18:58 GMT Subject: Extending the 'function' built-in class Message-ID: <529b8ba2$0$2270$426a74cc@news.free.fr> Hi, I can't figure out how I can extend the 'function' built-in class. I tried: class test(function): def test(self): print("test") but I get an error. Is it possible ? Regards, G. From roy at panix.com Sun Dec 1 14:30:24 2013 From: roy at panix.com (Roy Smith) Date: Sun, 01 Dec 2013 14:30:24 -0500 Subject: Extending the 'function' built-in class References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: In article <529b8ba2$0$2270$426a74cc at news.free.fr>, "G." wrote: > Hi, I can't figure out how I can extend the 'function' built-in class. I > tried: > class test(function): > def test(self): > print("test") > but I get an error. Is it possible ? > > Regards, G. It really helps to give us some basic information when asking questions. To start, what version of Python are you using, and what error message do you get? At least in Python 2 (but, I'm guessing, maybe, you're using Python 3, since you put parens in your print() statement?), there is no built-in class called "function". There are built-in functions, and they are of type builtin_function_or_method. When I try to subclass that by doing: class foo(type(open)): pass I get: Traceback (most recent call last): File "", line 1, in TypeError: Error when calling the metaclass bases type 'builtin_function_or_method' is not an acceptable base type So, we're back to asking what version you're using and what error message you got. From grumsk at grumsk.tz Sun Dec 1 14:37:46 2013 From: grumsk at grumsk.tz (G.) Date: 01 Dec 2013 19:37:46 GMT Subject: Extending the 'function' built-in class References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: <529b900a$0$3626$426a74cc@news.free.fr> Le 01-12-2013, Roy Smith a ?crit?: > > class foo(type(open)): > pass > > I get: > > Traceback (most recent call last): > File "", line 1, in > TypeError: Error when calling the metaclass bases > type 'builtin_function_or_method' is not an acceptable base type > > So, we're back to asking what version you're using and what error > message you got. Hi, I don't care that much for the version, since I wanted rather to perform some tests. I tried your code with various versions and got the same message than yours. Thus I guess the type can't be extended. Regards, G. From python.list at tim.thechases.com Sun Dec 1 14:43:59 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 1 Dec 2013 13:43:59 -0600 Subject: Extending the 'function' built-in class In-Reply-To: <529b8ba2$0$2270$426a74cc@news.free.fr> References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: <20131201134359.77c0afb8@bigbox.christie.dr> On 2013-12-01 19:18, G. wrote: > Hi, I can't figure out how I can extend the 'function' built-in > class. I tried: class test(function): > def test(self): > print("test") > but I get an error. Is it possible ? While I don't have an answer, I did find this interesting. First, "function" doesn't seem to be in the default __buitin__ namespace: >>> function Traceback (most recent call last): File "", line 1, in NameError: name 'function' is not defined I presume you're doing it with the following: >>> from types import FunctionType >>> class MyFunc(FunctionType): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: Error when calling the metaclass bases type 'function' is not an acceptable base type but, as you mention, the inability to subclass it is somewhat peculiar. It appears to be metaclass-related. I'm not quite sure *why* one might want to subclass FunctionType, but I'm also not sure why you should be *prevented* from subclassing it. -tkc From robert.kern at gmail.com Sun Dec 1 15:18:37 2013 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Dec 2013 20:18:37 +0000 Subject: Extending the 'function' built-in class In-Reply-To: <20131201134359.77c0afb8@bigbox.christie.dr> References: <529b8ba2$0$2270$426a74cc@news.free.fr> <20131201134359.77c0afb8@bigbox.christie.dr> Message-ID: On 2013-12-01 19:43, Tim Chase wrote: > I'm not quite sure *why* one might want to subclass FunctionType, but > I'm also not sure why you should be *prevented* from subclassing it. Previously: http://grokbase.com/t/python/python-list/033r5nks47/type-function-does-not-subtype#20030324rcnwbkfedhzbaf3vmiuer3z4xq -- 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 gary.herron at islandtraining.com Sun Dec 1 14:38:57 2013 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 01 Dec 2013 11:38:57 -0800 Subject: Extending the 'function' built-in class In-Reply-To: <529b8ba2$0$2270$426a74cc@news.free.fr> References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: <529B9051.80606@islandtraining.com> On 12/01/2013 11:18 AM, G. wrote: > Hi, I can't figure out how I can extend the 'function' built-in class. I tried: > class test(function): > def test(self): > print("test") > but I get an error. Is it possible ? > > Regards, G. What error do you get? What version of Python? What OS? And in particular: What 'function' built-in class? I know of no such thing, and the error message I get with your code says exactly that: NameError: name 'function' is not defined Did you not get that same error? All of which begs the questions: What do you think the function class is, and why are you trying to extend it? Gary Herron From grumsk at grumsk.tz Sun Dec 1 15:13:52 2013 From: grumsk at grumsk.tz (G.) Date: 01 Dec 2013 20:13:52 GMT Subject: Extending the 'function' built-in class References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: <529b9880$0$2241$426a74cc@news.free.fr> Le 01-12-2013, Gary Herron a ?crit?: > And in particular: What 'function' built-in class? I know of no such > thing, and the error message I get with your code says exactly that: > NameError: name 'function' is not defined > Did you not get that same error? Yes, indeed. The 'function' built-in class was the following one: >>> type(lambda x: 2*x) but I am interested by answers concerning other similar types also. Regards, G. From dreamingforward at gmail.com Sun Dec 1 20:26:50 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 1 Dec 2013 17:26:50 -0800 Subject: Extending the 'function' built-in class In-Reply-To: <529b8ba2$0$2270$426a74cc@news.free.fr> References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: > Hi, I can't figure out how I can extend the 'function' built-in class. I tried: > class test(function): > def test(self): > print("test") > but I get an error. Is it possible ? It has to do with differing models of computation, and python isn't designed for this. Perhaps you're searching for the ultimate lambda?. -- MarkJ Tacoma, Washington From wuwei23 at gmail.com Sun Dec 1 21:24:10 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 02 Dec 2013 12:24:10 +1000 Subject: Extending the 'function' built-in class In-Reply-To: <529b8ba2$0$2270$426a74cc@news.free.fr> References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: On 2/12/2013 5:18 AM, G. wrote: > Hi, I can't figure out how I can extend the 'function' built-in class. I tried: > class test(function): > def test(self): > print("test") > but I get an error. Is it possible ? Others have pointed out that you cannot subclass the function type. Could you explain what you're trying to achieve? It's possible you could use a decorator instead: def test(fn): def _test(): print('test') fn.test = _test return fn @test def foo(): pass >>> foo.test() test (Note that I've only included _test inside the decorator to show that you can create a closure to include the wrapped function, as a way of replicating 'self' in your class definition.) From steve at pearwood.info Mon Dec 2 02:01:41 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 02 Dec 2013 07:01:41 GMT Subject: Extending the 'function' built-in class References: <529b8ba2$0$2270$426a74cc@news.free.fr> Message-ID: <529c3055$0$2869$c3e8da3$76491128@news.astraweb.com> On Sun, 01 Dec 2013 19:18:58 +0000, G. wrote: > Hi, I can't figure out how I can extend the 'function' built-in class. I > tried: > class test(function): > def test(self): > print("test") > but I get an error. Is it possible ? You cannot subclass the function type directly, but you can extend functions. Firstly, rather than subclassing, you can use delegation and composition. Google for more info on delegation and composition as an alternative to subclassing: https://duckduckgo.com/html/?q=delegation%20as%20alternative%20to% 20subclassing You can also add attributes to functions: def spam(): pass spam.eggs = 23 Want to add a method to a function? You can do that too: from types import MethodType spam.method = MethodType( lambda self, n: "%s got %d as arg" % (self.__name__, n), spam) It's even simpler if it doesn't need to be a method: spam.function = lambda n: "spam got %d as arg" % n) Want more complex behaviour? Write a callable class: class MyCallable(object): def __call__(self, arg): pass func = MyCallable() There are plenty of ways to extend functions. Subclassing isn't one of them. -- Steven From grumsk at grumsk.tz Mon Dec 2 04:32:48 2013 From: grumsk at grumsk.tz (G.) Date: 02 Dec 2013 09:32:48 GMT Subject: Extending the 'function' built-in class References: <529b8ba2$0$2270$426a74cc@news.free.fr> <529c3055$0$2869$c3e8da3$76491128@news.astraweb.com> Message-ID: <529c53c0$0$2150$426a74cc@news.free.fr> Le 02-12-2013, Steven D'Aprano a ?crit?: > There are plenty of ways to extend functions. Subclassing isn't one of > them. Thank you very mych for your complete answer; I falled back to your last proposal by myself in my attempts; I am happyt to learn about the other ways also. Regards, G. From martin914k at hotmail.com Sun Dec 1 16:59:07 2013 From: martin914k at hotmail.com (martin koh) Date: Mon, 2 Dec 2013 05:59:07 +0800 Subject: wiimote IR tracking in python Message-ID: Hi all..may i know how to do the IR tracking by using wiimote? i did tried the source code from (http://ph-elec.com/archives/simple-python-wii-mote-test/) using command prompt but i can't compile successfully, i think is because i don't have any idea how to import the cwiid module. Can anyone please provide me some informations about this? Thanks so much. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailman at hanez.org Sun Dec 1 17:05:43 2013 From: mailman at hanez.org (Johannes Findeisen) Date: Sun, 1 Dec 2013 23:05:43 +0100 Subject: wiimote IR tracking in python In-Reply-To: References: Message-ID: <20131201230543.7e4ed7be@hanez.org> On Mon, 2 Dec 2013 05:59:07 +0800 martin koh wrote: > Hi all..may i know how to do the IR tracking by using wiimote? i did tried the source code from > (http://ph-elec.com/archives/simple-python-wii-mote-test/) using command prompt but i can't compile successfully, i think is because i don't have any idea how to import the cwiid module. Can anyone please provide me some informations about this? Thanks so much. Did you took a look here: http://abstrakraft.org/cwiid/ ? There you find the sources and installation instructions in a README file. --Johannes From redstone-cold at 163.com Mon Dec 2 06:34:46 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 2 Dec 2013 03:34:46 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module Message-ID: I have few wav files that I can use either of the following command line mentioned here https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20%28join,%20merge%29%20media%20files to concatenate ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy output.wav ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy output.wav anyone know how to convert either of them to work with python's subprocess module, it would be better if your solution is platform independent . From rosuav at gmail.com Mon Dec 2 06:40:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Dec 2013 22:40:52 +1100 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: Message-ID: On Mon, Dec 2, 2013 at 10:34 PM, iMath wrote: > I have few wav files that I can use either of the following command line mentioned here > https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20%28join,%20merge%29%20media%20files > to concatenate > > > ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy output.wav > ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav > ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy output.wav In bash, the <(...) notation is like piping: it executes the command inside the parentheses and uses that as standard input to ffmpeg. So if you work out what the commands are doing (it looks like they emit a line saying "file '...'" for each .wav file in the current directory, possibly including subdirectories) and replicate that in Python, you should be able to make it cross-platform. ChrisA From ben+python at benfinney.id.au Mon Dec 2 16:19:21 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Dec 2013 08:19:21 +1100 Subject: using ffmpeg command line with python's subprocess module References: Message-ID: <7wzjojne7a.fsf@benfinney.id.au> Chris Angelico writes: > On Mon, Dec 2, 2013 at 10:34 PM, iMath wrote: > > ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy output.wav > > ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav > > ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy output.wav > > In bash, the <(...) notation is like piping: it executes the command > inside the parentheses and uses that as standard input to ffmpeg. Not standard input, no. What it does is create a temporary file to contain the result, and inserts that file name on the command line. This is good for programs that require an actual file, not standard input. So the above usage seems right to me: the ?ffmpeg -i FOO? option is provided with a filename dynamically created by Bash, referring to a temporary file that contains the output of the subshell. -- \ ?Welchen Teil von ?Gestalt? verstehen Sie nicht? [What part of | `\ ?gestalt? don't you understand?]? ?Karsten M. Self | _o__) | Ben Finney From rosuav at gmail.com Mon Dec 2 16:25:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Dec 2013 08:25:01 +1100 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <7wzjojne7a.fsf@benfinney.id.au> References: <7wzjojne7a.fsf@benfinney.id.au> Message-ID: On Tue, Dec 3, 2013 at 8:19 AM, Ben Finney wrote: > Chris Angelico writes: > >> On Mon, Dec 2, 2013 at 10:34 PM, iMath wrote: >> > ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy output.wav >> > ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav >> > ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy output.wav >> >> In bash, the <(...) notation is like piping: it executes the command >> inside the parentheses and uses that as standard input to ffmpeg. > > Not standard input, no. What it does is create a temporary file to > contain the result, and inserts that file name on the command line. This > is good for programs that require an actual file, not standard input. Ah, sorry, my bad - bit rusty on my arcane bashisms. In any case, the general point of what I was saying is: Figure out what's happening, and replicate that. In this case, that means creating a file, then, rather than putting it on stdin - that's probably actually easier anyway. ChrisA From redstone-cold at 163.com Mon Dec 2 20:15:42 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 2 Dec 2013 17:15:42 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: Message-ID: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> ? 2013?12?3????UTC+8??5?19?21??Ben Finney??? > Chris Angelico writes: > > > > > On Mon, Dec 2, 2013 at 10:34 PM, iMath wrote: > > > > ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy output.wav > > > > ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav > > > > ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy output.wav > > > > > > In bash, the <(...) notation is like piping: it executes the command > > > inside the parentheses and uses that as standard input to ffmpeg. > > > > Not standard input, no. What it does is create a temporary file to > > contain the result, and inserts that file name on the command line. This > > is good for programs that require an actual file, not standard input. > > > > So the above usage seems right to me: the ?ffmpeg -i FOO? option is > > provided with a filename dynamically created by Bash, referring to a > > temporary file that contains the output of the subshell. > > > > -- > > \ ?Welchen Teil von ?Gestalt? verstehen Sie nicht? [What part of | > > `\ ?gestalt? don't you understand?]? ?Karsten M. Self | > > _o__) | > > Ben Finney so is there any way to create a temporary file by Python here ? From rustompmody at gmail.com Mon Dec 2 20:42:11 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 2 Dec 2013 17:42:11 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> Message-ID: <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> On Tuesday, December 3, 2013 6:45:42 AM UTC+5:30, iMath wrote: > so is there any way to create a temporary file by Python here ? http://docs.python.org/2/library/tempfile.html From redstone-cold at 163.com Tue Dec 3 20:42:35 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 3 Dec 2013 17:42:35 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> Message-ID: <0ac025f1-242e-492a-a77b-621a7f585182@googlegroups.com> ? 2013?12?3????UTC+8??9?42?11??rusi??? > On Tuesday, December 3, 2013 6:45:42 AM UTC+5:30, iMath wrote: > > > so is there any way to create a temporary file by Python here ? > > > > http://docs.python.org/2/library/tempfile.html I use the following code to do the test ,but error occurred ,it prompts system cannot find specified files ,but the files are indeed exists there ,any help ? with tempfile.TemporaryFile() as fp: fp.write(("file '"+'a1.mp3'+"'\n").encode('utf-8')) fp.write(("file '"+'a2.mp3'+"'\n").encode('utf-8')) subprocess.call(['ffmpeg/ffmpeg', '-f', 'concat','-i',fp, '-c', 'copy', 'a3.mp3']) From redstone-cold at 163.com Tue Dec 3 20:42:45 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 3 Dec 2013 17:42:45 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> Message-ID: <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> ? 2013?12?3????UTC+8??9?42?11??rusi??? > On Tuesday, December 3, 2013 6:45:42 AM UTC+5:30, iMath wrote: > > > so is there any way to create a temporary file by Python here ? > > > > http://docs.python.org/2/library/tempfile.html I use the following code to do the test ,but error occurred ,it prompts system cannot find specified files ,but the files are indeed exists there ,any help ? with tempfile.TemporaryFile() as fp: fp.write(("file '"+'a1.mp3'+"'\n").encode('utf-8')) fp.write(("file '"+'a2.mp3'+"'\n").encode('utf-8')) subprocess.call(['ffmpeg/ffmpeg', '-f', 'concat','-i',fp, '-c', 'copy', 'a3.mp3']) From andipersti at gmail.com Wed Dec 4 04:38:27 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Wed, 4 Dec 2013 10:38:27 +0100 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: <20131204103827.6c5332c6@Hof> iMath wrote: >I use the following code to do the test ,but error occurred ,it >prompts system cannot find specified files ,but the files are indeed >exists there ,any help ? > >with tempfile.TemporaryFile() as fp: > fp.write(("file '"+'a1.mp3'+"'\n").encode('utf-8')) > fp.write(("file '"+'a2.mp3'+"'\n").encode('utf-8')) > > subprocess.call(['ffmpeg/ffmpeg', '-f', 'concat','-i',fp, '-c', > 'copy', 'a3.mp3']) Basic rule: Always copy'n'paste the exact traceback you get. I don't think you are running the code you have posted because your subprocess call doesn't work: >>> import tempfile, subprocess >>> with tempfile.TemporaryFile() as fp: ... subprocess.call(["foo", "bar", fp, "baz"]) ... Traceback (most recent call last): File "", line 2, in File "/usr/lib/python3.3/subprocess.py", line 520, in call with Popen(*popenargs, **kwargs) as p: File "/usr/lib/python3.3/subprocess.py", line 820, in __init__ restore_signals, start_new_session) File "/usr/lib/python3.3/subprocess.py", line 1380, in _execute_child restore_signals, start_new_session, preexec_fn) TypeError: Can't convert '_io.BufferedRandom' object to str implicitly "fp" is a file object, but subprocess expects a list of strings as its first argument. Bye, Andreas From rosuav at gmail.com Wed Dec 4 05:51:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Dec 2013 21:51:49 +1100 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <20131204103827.6c5332c6@Hof> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <20131204103827.6c5332c6@Hof> Message-ID: On Wed, Dec 4, 2013 at 8:38 PM, Andreas Perstinger wrote: > "fp" is a file object, but subprocess expects a list of strings as > its first argument. More fundamentally: The subprocess's arguments must include the *name* of the file. This means you can't use TemporaryFile at all, as it's not guaranteed to return an object that actually has a file name. There's another problem, too, and that's that you're not closing the file before expecting the subprocess to open it. And once you do that, you'll find that the file no longer exists once it's been closed. In fact, you'll need to research the tempfile module a bit to be able to do what you want here; rather than spoon-feed you an exact solution, I'll just say that there is one, and it can be found here: http://docs.python.org/3.3/library/tempfile.html ChrisA From redstone-cold at 163.com Fri Dec 6 09:54:38 2013 From: redstone-cold at 163.com (iMath) Date: Fri, 6 Dec 2013 06:54:38 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <20131204103827.6c5332c6@Hof> Message-ID: <60f2e393-658c-4e18-85b1-fc7d0b07ddb4@googlegroups.com> ? 2013?12?4????UTC+8??6?51?49??Chris Angelico??? > On Wed, Dec 4, 2013 at 8:38 PM, Andreas Perstinger wrote: > > > "fp" is a file object, but subprocess expects a list of strings as > > > its first argument. > > > > More fundamentally: The subprocess's arguments must include the *name* > > of the file. This means you can't use TemporaryFile at all, as it's > > not guaranteed to return an object that actually has a file name. > > > > There's another problem, too, and that's that you're not closing the > > file before expecting the subprocess to open it. And once you do that, > > you'll find that the file no longer exists once it's been closed. In > > fact, you'll need to research the tempfile module a bit to be able to > > do what you want here; rather than spoon-feed you an exact solution, > > I'll just say that there is one, and it can be found here: > > > > http://docs.python.org/3.3/library/tempfile.html > > > > ChrisA I think you mean I should create a temporary file by NamedTemporaryFile(). After tried it many times, I found there is nearly no convenience in creating a temporary file or a persistent one here ,because we couldn't use the temporary file while it has not been closed ,so we couldn't depend on the convenience of letting the temporary file automatically delete itself when closing, we have to delete it later by os.remove() after it has been used in that command line. code without the with statement is here ,but it is wrong ,it shows this line c:\docume~1\admini~1\locals~1\temp\tmp0d8959: Invalid data found when processing input fp=tempfile.NamedTemporaryFile(delete=False) fp.write(("file '"+fileName1+"'\n").encode('utf-8')) fp.write(("file '"+fileName2+"'\n").encode('utf-8')) subprocess.call(['ffmpeg', '-f', 'concat','-i',fp.name, '-c', 'copy', fileName]) fp.close() From rosuav at gmail.com Fri Dec 6 09:59:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 01:59:43 +1100 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <60f2e393-658c-4e18-85b1-fc7d0b07ddb4@googlegroups.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <20131204103827.6c5332c6@Hof> <60f2e393-658c-4e18-85b1-fc7d0b07ddb4@googlegroups.com> Message-ID: On Sat, Dec 7, 2013 at 1:54 AM, iMath wrote: > fp=tempfile.NamedTemporaryFile(delete=False) > fp.write(("file '"+fileName1+"'\n").encode('utf-8')) > fp.write(("file '"+fileName2+"'\n").encode('utf-8')) > > > subprocess.call(['ffmpeg', '-f', 'concat','-i',fp.name, '-c', 'copy', fileName]) > fp.close() You need to close the file before getting the other process to use it. Otherwise, it may not be able to open the file at all, and even if it can, you might find that not all the data has been written. But congrats! You have successfully found the points I was directing you to. Yes, I was hinting that you need NamedTemporaryFile, the .name attribute, and delete=False. Good job! ChrisA From redstone-cold at 163.com Mon Dec 9 04:04:14 2013 From: redstone-cold at 163.com (iMath) Date: Mon, 9 Dec 2013 01:04:14 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <20131204103827.6c5332c6@Hof> <60f2e393-658c-4e18-85b1-fc7d0b07ddb4@googlegroups.com> Message-ID: <6030eab0-17f7-4b7b-b057-d0889031b3d2@googlegroups.com> ? 2013?12?6????UTC+8??10?59?43??Chris Angelico??? > On Sat, Dec 7, 2013 at 1:54 AM, iMath wrote: > > > fp=tempfile.NamedTemporaryFile(delete=False) > > > fp.write(("file '"+fileName1+"'\n").encode('utf-8')) > > > fp.write(("file '"+fileName2+"'\n").encode('utf-8')) > > > > > > > > > subprocess.call(['ffmpeg', '-f', 'concat','-i',fp.name, '-c', 'copy', fileName]) > > > fp.close() > > > > You need to close the file before getting the other process to use it. > > Otherwise, it may not be able to open the file at all, and even if it > > can, you might find that not all the data has been written. > > > > But congrats! You have successfully found the points I was directing > > you to. Yes, I was hinting that you need NamedTemporaryFile, the .name > > attribute, and delete=False. Good job! > > > > ChrisA we don't have permission to use the temporary file while it has not been closed,but when the file is closed , it will be destroyed by default(delete=True),but once we set delete=False,then we couldn't depend on the convenience of letting the temporary file automatically delete itself after it has been used(then we have to delete it later by os.remove()) ,thus there is nearly no convenience in creating a temporary file or a persistent one when using NamedTemporaryFile. I think this is a design flaw and should be improved like this :when delete=True,the file should be removed upon destruction of the object or on function return or on garbage collected,only when delete=False,the file can remain on the disk . From andipersti at gmail.com Tue Dec 10 07:59:47 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Tue, 10 Dec 2013 13:59:47 +0100 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <6030eab0-17f7-4b7b-b057-d0889031b3d2@googlegroups.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <20131204103827.6c5332c6@Hof> <60f2e393-658c-4e18-85b1-fc7d0b07ddb4@googlegroups.com> <6030eab0-17f7-4b7b-b057-d0889031b3d2@googlegroups.com> Message-ID: <20131210135947.26115916@Hof> iMath wrote: >we don't have permission to use the temporary file while it has not >been closed,but when the file is closed , it will be destroyed by >default(delete=True),but once we set delete=False,then we couldn't >depend on the convenience of letting the temporary file automatically >delete itself after it has been used(then we have to delete it later >by os.remove()) ,thus there is nearly no convenience in creating a >temporary file or a persistent one when using NamedTemporaryFile. In your OP you asked for a platform independent solution thus I don't think it's possible to do what you want if the OS doesn't support opening a file another time while it's still open. Otherwise, on my Linux system this works: >>> import tempfile, subprocess >>> with tempfile.NamedTemporaryFile() as fp: ... fp.write(b"foo\nbar\nbaz\n") ... fp.flush() ... subprocess.call(["cat", fp.name]) ... 12 foo bar baz 0 Bye, Andreas From redstone-cold at 163.com Fri Dec 6 01:23:48 2013 From: redstone-cold at 163.com (iMath) Date: Thu, 5 Dec 2013 22:23:48 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: ? 2013?12?4????UTC+8??5?38?27??Andreas Perstinger??? > iMath wrote: > > >I use the following code to do the test ,but error occurred ,it > > >prompts system cannot find specified files ,but the files are indeed > > >exists there ,any help ? > > > > > >with tempfile.TemporaryFile() as fp: > > > fp.write(("file '"+'a1.mp3'+"'\n").encode('utf-8')) > > > fp.write(("file '"+'a2.mp3'+"'\n").encode('utf-8')) > > > > > > subprocess.call(['ffmpeg/ffmpeg', '-f', 'concat','-i',fp, '-c', > > > 'copy', 'a3.mp3']) > > > > Basic rule: Always copy'n'paste the exact traceback you get. > > > > I don't think you are running the code you have posted because your > > subprocess call doesn't work: > > > > >>> import tempfile, subprocess > > >>> with tempfile.TemporaryFile() as fp: > > ... subprocess.call(["foo", "bar", fp, "baz"]) > > ... > > Traceback (most recent call last): > > File "", line 2, in > > File "/usr/lib/python3.3/subprocess.py", line 520, in call > > with Popen(*popenargs, **kwargs) as p: > > File "/usr/lib/python3.3/subprocess.py", line 820, in __init__ > > restore_signals, start_new_session) > > File "/usr/lib/python3.3/subprocess.py", line 1380, in _execute_child > > restore_signals, start_new_session, preexec_fn) > > TypeError: Can't convert '_io.BufferedRandom' object to str implicitly > > > > "fp" is a file object, but subprocess expects a list of strings as > > its first argument. > > > > Bye, Andreas sorry for my fuss. it prompts StdErr: -c: No such file or directory From breamoreboy at yahoo.co.uk Fri Dec 6 04:23:59 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 09:23:59 +0000 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: On 06/12/2013 06:23, iMath wrote: Dearest iMath, wouldst thou be kind enough to partake of obtaining some type of email client that dost not sendeth double spaced data into this most illustrious of mailing lists/newsgroups. Thanking thee for thine participation in my most humble of requests. I do remain your most obedient servant. -- 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 Fri Dec 6 06:31:17 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 06 Dec 2013 06:31:17 -0500 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: On 12/6/13 4:23 AM, Mark Lawrence wrote: > On 06/12/2013 06:23, iMath wrote: > > Dearest iMath, wouldst thou be kind enough to partake of obtaining some > type of email client that dost not sendeth double spaced data into this > most illustrious of mailing lists/newsgroups. Thanking thee for thine > participation in my most humble of requests. I do remain your most > obedient servant. > iMath seems to be a native Chinese speaker. I think this message, though amusing, will be baffling and won't have any effect... --Ned. From redstone-cold at 163.com Fri Dec 6 09:52:48 2013 From: redstone-cold at 163.com (iMath) Date: Fri, 6 Dec 2013 06:52:48 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: ? 2013?12?6????UTC+8??5?23?59??Mark Lawrence??? > On 06/12/2013 06:23, iMath wrote: > > > > Dearest iMath, wouldst thou be kind enough to partake of obtaining some > > type of email client that dost not sendeth double spaced data into this > > most illustrious of mailing lists/newsgroups. Thanking thee for thine > > participation in my most humble of requests. I do remain your most > > obedient servant. > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence yes ,I am a native Chinese speaker.I always post question by Google Group not through email ,is there something wrong with it ? your english is a little strange to me . From breamoreboy at yahoo.co.uk Fri Dec 6 10:12:02 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 15:12:02 +0000 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: On 06/12/2013 14:52, iMath wrote: > ? 2013?12?6????UTC+8??5?23?59??Mark Lawrence??? >> On 06/12/2013 06:23, iMath wrote: >> >> >> >> Dearest iMath, wouldst thou be kind enough to partake of obtaining some >> >> type of email client that dost not sendeth double spaced data into this >> >> most illustrious of mailing lists/newsgroups. Thanking thee for thine >> >> participation in my most humble of requests. I do remain your most >> >> obedient servant. >> >> >> >> -- >> >> My fellow Pythonistas, ask not what our language can do for you, ask >> >> what you can do for our language. >> >> >> >> Mark Lawrence > > yes ,I am a native Chinese speaker.I always post question by Google Group not through email ,is there something wrong with it ? > your english is a little strange to me . > You can see the extra lines inserted by google groups above. It's not too bad in one and only one message, but when a message has been backwards and forwards several times it's extremely irritating, or worse still effectively unreadable. Work arounds have been posted on this list, but I'd recommend using any decent email client. The English I used was archaic, please ignore it :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Fri Dec 6 10:13:12 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 07:13:12 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: <474cfa20-3618-4426-9635-903b9255dc07@googlegroups.com> On Friday, December 6, 2013 8:22:48 PM UTC+5:30, iMath wrote: > ? 2013?12?6????UTC+8??5?23?59??Mark Lawrence??? > > On 06/12/2013 06:23, iMath wrote: > > Dearest iMath, wouldst thou be kind enough to partake of obtaining some > > type of email client that dost not sendeth double spaced data into this > > most illustrious of mailing lists/newsgroups. Thanking thee for thine > > participation in my most humble of requests. I do remain your most > > obedient servant. > yes ,I am a native Chinese speaker.I always post question by Google Group not through email ,is there something wrong with it ? Yes but its easily correctable I recently answered this question to another poster here https://groups.google.com/forum/#!searchin/comp.lang.python/rusi$20google$20groups|sort:date/comp.lang.python/C51hEvi-KbY/KSeaMFoHtcIJ From rustompmody at gmail.com Fri Dec 6 10:15:43 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 07:15:43 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: <62811266-35c5-4401-851a-91c3ce622ad0@googlegroups.com> On Friday, December 6, 2013 8:42:02 PM UTC+5:30, Mark Lawrence wrote: > The English I used was archaic, please ignore it :) "Archaic" is almost archaic "Old" is ever-young :D From steve+comp.lang.python at pearwood.info Fri Dec 6 10:34:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Dec 2013 15:34:11 GMT Subject: using ffmpeg command line with python's subprocess module References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> Message-ID: <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Dec 2013 06:52:48 -0800, iMath wrote: > yes ,I am a native Chinese speaker.I always post question by Google > Group not through email ,is there something wrong with it ? your > english is a little strange to me . Mark is writing in fake old-English style, the way people think English was spoken a thousand years ago. I don't know why he did that. Perhaps he thought it was amusing. There are many problems with Google Groups. If you pay attention to this forum, you will see dozens of posts about "Managing Google Groups headaches" and other complaints: - Google Groups double-spaces replies, so text which should appear like: line one line two line three line four turns into: line one blank line line two blank line line three blank line line four - Google Groups often starts sending HTML code instead of plain text - it often mangles indentation, which is terrible for Python code - sometimes it automatically sets the reply address for posts to go to Google Groups, instead of the mailing list it should go to - almost all of the spam on his forum comes from Google Groups, so many people automatically filter everything from Google Groups straight to the trash. There are alternatives to Google Groups: - the mailing list, python-list at python.org - Usenet, comp.lang.python - the Gmane mirror: http://gmane.org/find.php?list=python-list%40python.org and possibly others. You will maximise the number of people reading your posts if you avoid Google Groups. If for some reason you cannot use any of the alternatives, please take the time to fix some of the problems with Google Groups. If you search the archives, you should find some posts by Rusi defending Google Groups and explaining what he does to make it more presentable, and (if I remember correctly) I think Mark also sometimes posts a link to managing Google Groups. -- Steven From breamoreboy at yahoo.co.uk Fri Dec 6 10:53:47 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 15:53:47 +0000 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/12/2013 15:34, Steven D'Aprano wrote: (if I remember correctly) I think Mark also > sometimes posts a link to managing Google Groups. > You do, and here it is https://wiki.python.org/moin/GoogleGroupsPython -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Fri Dec 6 11:19:00 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 08:19:00 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, December 6, 2013 9:23:47 PM UTC+5:30, Mark Lawrence wrote: > On 06/12/2013 15:34, Steven D'Aprano wrote: > > (if I remember correctly) I think Mark also > > > sometimes posts a link to managing Google Groups. > > > > > You do, and here it is https://wiki.python.org/moin/GoogleGroupsPython That link needs updating. Even if my almost-automatic correction methods are not considered kosher for some reason or other, the thing that needs to go in there is that GG has TWO problems 1. Blank lines 2. Long lines That link only describes 1. Roy's yesterday's post in "Packaging a proprietary python library" says: > I, and Rusi, know enough, and take the effort, to overcome its > shortcomings doesn't change that. But in fact his post takes care of 1 not 2. In all fairness I did not know that 2 is a problem until rurpy pointed it out recently and was not correcting it. In fact, I'd take the trouble to make the lines long assuming that clients were intelligent enough to fit it properly into whatever was the current window!!! So someone please update that page! From breamoreboy at yahoo.co.uk Fri Dec 6 11:25:54 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 16:25:54 +0000 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/12/2013 16:19, rusi wrote: > On Friday, December 6, 2013 9:23:47 PM UTC+5:30, Mark Lawrence wrote: >> On 06/12/2013 15:34, Steven D'Aprano wrote: >> >> (if I remember correctly) I think Mark also >> >>> sometimes posts a link to managing Google Groups. >> >>> >> >> You do, and here it is https://wiki.python.org/moin/GoogleGroupsPython > > That link needs updating. > > Even if my almost-automatic correction methods are not considered > kosher for some reason or other, the thing that needs to go in there > is that GG has TWO problems > > 1. Blank lines > 2. Long lines > > That link only describes 1. > > Roy's yesterday's post in "Packaging a proprietary python library" > says: > >> I, and Rusi, know enough, and take the effort, to overcome its >> shortcomings doesn't change that. > > But in fact his post takes care of 1 not 2. > > In all fairness I did not know that 2 is a problem until rurpy pointed > it out recently and was not correcting it. In fact, I'd take the > trouble to make the lines long assuming that clients were intelligent > enough to fit it properly into whatever was the current window!!! > > So someone please update that page! > This is a community so why don't you? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Fri Dec 6 11:45:07 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 08:45:07 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, December 6, 2013 9:55:54 PM UTC+5:30, Mark Lawrence wrote: > On 06/12/2013 16:19, rusi wrote: > > So someone please update that page! > This is a community so why don't you? Ok done (at least a first draft) I was under the impression that anyone could not edit From python at mrabarnett.plus.com Fri Dec 6 11:41:04 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Dec 2013 16:41:04 +0000 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52A1FE20.3060706@mrabarnett.plus.com> On 06/12/2013 15:34, Steven D'Aprano wrote: > On Fri, 06 Dec 2013 06:52:48 -0800, iMath wrote: > >> yes ,I am a native Chinese speaker.I always post question by Google >> Group not through email ,is there something wrong with it ? your >> english is a little strange to me . > > Mark is writing in fake old-English style, the way people think English > was spoken a thousand years ago. I don't know why he did that. Perhaps he > thought it was amusing. > [snip] You're exaggerating. It's more like 500 years ago. :-) From rustompmody at gmail.com Fri Dec 6 11:53:08 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 6 Dec 2013 08:53:08 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, December 6, 2013 10:11:04 PM UTC+5:30, MRAB wrote: > On 06/12/2013 15:34, Steven D'Aprano wrote: > > On Fri, 06 Dec 2013 06:52:48 -0800, iMath wrote: > >> yes ,I am a native Chinese speaker.I always post question by Google > >> Group not through email ,is there something wrong with it ? your > >> english is a little strange to me . > > Mark is writing in fake old-English style, the way people think English > > was spoken a thousand years ago. I don't know why he did that. Perhaps he > > thought it was amusing. > [snip] > You're exaggerating. It's more like 500 years ago. :-) I was going to say the same until I noticed the "the way people think English was spoken..." That makes it unarguable -- surely there are some people who (wrongly) think so? From greg.ewing at canterbury.ac.nz Fri Dec 6 19:01:01 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 Dec 2013 13:01:01 +1300 Subject: using ffmpeg command line with python's subprocess module In-Reply-To: References: <3104d38f-3fca-43b0-b6a4-b600684f765e@googlegroups.com> <6fb2b162-cf9b-4c1c-bf5f-f14baf5baac4@googlegroups.com> <35c86484-d0dd-4954-adee-cde3a2fd7ac1@googlegroups.com> <52a1ee73$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: rusi wrote: > On Friday, December 6, 2013 10:11:04 PM UTC+5:30, MRAB wrote: > >>You're exaggerating. It's more like 500 years ago. :-) > > I was going to say the same until I noticed the "the way people think English > was spoken..." > > That makes it unarguable -- surely there are some people who (wrongly) think so? Probably. They're surprisingly far off, though. Here's a sample of actual 1000-year-old English: http://answers.yahoo.com/question/index?qid=20100314001840AAygUaq -- Greg From alain at dpt-info.u-strasbg.fr Tue Dec 3 04:33:09 2013 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 03 Dec 2013 10:33:09 +0100 Subject: using ffmpeg command line with python's subprocess module References: Message-ID: <87li029t4a.fsf@dpt-info.u-strasbg.fr> Ben Finney writes: > Chris Angelico writes: > >> On Mon, Dec 2, 2013 at 10:34 PM, iMath wrote: >> > ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy output.wav >> > ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav >> > ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy output.wav >> >> In bash, the <(...) notation is like piping: it executes the command >> inside the parentheses and uses that as standard input to ffmpeg. > > Not standard input, no. What it does is create a temporary file to > contain the result, and inserts that file name on the command line. This > is good for programs that require an actual file, not standard input. Just in case (it may not be relevant to the current discussion): it may not be a file, it will more probably be a FIFO (i.e., not seekable). Here is the relevant part of the manual page: | Process Substitution | Process substitution is supported on systems that support named | pipes (FIFOs) or the /dev/fd method of naming open files. It | takes the form of <(list) or >(list). The process list is run | with its input or output connected to a FIFO or some file in | /dev/fd. The name of this file is passed as an argument to the | current command as the result of the expansion. -- Alain. From redstone-cold at 163.com Tue Dec 3 08:59:19 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 3 Dec 2013 05:59:19 -0800 (PST) Subject: using ffmpeg command line with python's subprocess module In-Reply-To: <87li029t4a.fsf@dpt-info.u-strasbg.fr> References: <87li029t4a.fsf@dpt-info.u-strasbg.fr> Message-ID: <32aae712-6ffe-4640-9254-53fae264be61@googlegroups.com> ? 2013?12?3????UTC+8??5?33?09??Alain Ketterlin??? > Ben Finney writes: > > > > > Chris Angelico writes: > > > > > >> On Mon, Dec 2, 2013 at 10:34 PM, iMath wrote: > > >> > ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '$f'"; done) -c copy output.wav > > >> > ffmpeg -f concat -i <(printf "file '%s'\n" ./*.wav) -c copy output.wav > > >> > ffmpeg -f concat -i <(find . -name '*.wav' -printf "file '%p'\n") -c copy output.wav > > >> > > >> In bash, the <(...) notation is like piping: it executes the command > > >> inside the parentheses and uses that as standard input to ffmpeg. > > > > > > Not standard input, no. What it does is create a temporary file to > > > contain the result, and inserts that file name on the command line. This > > > is good for programs that require an actual file, not standard input. > > > > Just in case (it may not be relevant to the current discussion): it may > > not be a file, it will more probably be a FIFO (i.e., not seekable). > > Here is the relevant part of the manual page: > > > > | Process Substitution > > | Process substitution is supported on systems that support named > > | pipes (FIFOs) or the /dev/fd method of naming open files. It > > | takes the form of <(list) or >(list). The process list is run > > | with its input or output connected to a FIFO or some file in > > | /dev/fd. The name of this file is passed as an argument to the > > | current command as the result of the expansion. > > > > -- Alain. thanks for your reply, but is there any method that we can convert this to python ? From contact at stephane-klein.info Mon Dec 2 11:18:29 2013 From: contact at stephane-klein.info (=?ISO-8859-1?Q?St=E9phane_Klein?=) Date: Mon, 02 Dec 2013 17:18:29 +0100 Subject: I look for a list to convert time zone abbreviation to full time zone in python Message-ID: Hi, I would like to convert time zone abbreviation to full time zone in Python. I've found this information : * http://stackoverflow.com/questions/1703546/parsing-date-time-string-with-timezone-abbreviated-name-in-python I'm currently writing dict with this informations : http://www.timeanddate.com/library/abbreviations/timezones/ Questions : * are there the same list somewhere (I didn't found in pytz) ? * is it possible to append this list in pytz or in standard python date module ? Best regards, Stephane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane cv: http://cv.stephane-klein.info From joel.goldstick at gmail.com Mon Dec 2 12:31:22 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Dec 2013 12:31:22 -0500 Subject: I look for a list to convert time zone abbreviation to full time zone in python In-Reply-To: References: Message-ID: On Mon, Dec 2, 2013 at 11:18 AM, St?phane Klein wrote: > Hi, > > I would like to convert time zone abbreviation to full time zone in Python. > > I've found this information : > > * > > http://stackoverflow.com/questions/1703546/parsing-date-time-string-with-timezone-abbreviated-name-in-python > > I'm currently writing dict with this informations : > http://www.timeanddate.com/library/abbreviations/timezones/ > > Questions : > > * are there the same list somewhere (I didn't found in pytz) ? > * is it possible to append this list in pytz or in standard python date > module ? > Is this what you are looking for: http://timezonedb.com/download > > Best regards, > Stephane > -- > St?phane Klein > blog: http://stephane-klein.info > Twitter: http://twitter.com/klein_stephane > cv: http://cv.stephane-klein.info > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuart at stuartbishop.net Tue Dec 3 05:07:34 2013 From: stuart at stuartbishop.net (Stuart Bishop) Date: Tue, 3 Dec 2013 17:07:34 +0700 Subject: I look for a list to convert time zone abbreviation to full time zone in python In-Reply-To: References: Message-ID: On Mon, Dec 2, 2013 at 11:18 PM, St?phane Klein wrote: > * are there the same list somewhere (I didn't found in pytz) ? Not that I know of. > * is it possible to append this list in pytz or in standard python date module ? It could go into pytz (but generated from the IANA database, not from the list you quote). Whether it should go into pytz is debatable. If you need to map an abbreviation back to a single timezone you are solving the wrong problem, because you can only map an abbreviation back to a list of possible timezones (And that list might change when the database is corrected). Also, to correctly represent this you need to specify the point in time. EST in 'Tue Dec 3 20:44:00 EST 2013' maps to about 3 timezones. EST in 'Tue Dec 3 20:44:00 EST 2011' maps to about 6. -- Stuart Bishop http://www.stuartbishop.net/ From contact at stephane-klein.info Tue Dec 3 10:27:15 2013 From: contact at stephane-klein.info (=?UTF-8?B?U3TDqXBoYW5lIEtsZWlu?=) Date: Tue, 03 Dec 2013 16:27:15 +0100 Subject: I look for a list to convert time zone abbreviation to full time zone in python In-Reply-To: References: Message-ID: <529DF853.5080900@stephane-klein.info> Le 03/12/13 11:07, Stuart Bishop a ?crit : > It could go into pytz (but generated from the IANA database, not from > the list you quote). Whether it should go into pytz is debatable. > Ok. > If you need to map an abbreviation back to a single timezone you are > solving the wrong problem, because you can only map an abbreviation > back to a list of possible timezones (And that list might change when > the database is corrected). Also, to correctly represent this you need > to specify the point in time. EST in 'Tue Dec 3 20:44:00 EST 2013' > maps to about 3 timezones. EST in 'Tue Dec 3 20:44:00 EST 2011' maps > to about 6. > Ok I understand this now. My original need is by example, convert Apr 16 12:09:00 SGT 2010 to UTC format. I would like to use datetime.datetime.strptime function, but it don't success to parse %Z param. pytz haven't parse function. python-dateutil have a auto discover parse function, but I don't want to use this auto discover feature. Question, pytz can't implement a parsing feature ? Best regards, St?phane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane cv: http://cv.stephane-klein.info From contact at stephane-klein.info Tue Dec 3 10:46:17 2013 From: contact at stephane-klein.info (=?UTF-8?B?U3TDqXBoYW5lIEtsZWlu?=) Date: Tue, 03 Dec 2013 16:46:17 +0100 Subject: I look for a list to convert time zone abbreviation to full time zone in python In-Reply-To: <529DF853.5080900@stephane-klein.info> References: <529DF853.5080900@stephane-klein.info> Message-ID: <529DFCC9.9010203@stephane-klein.info> Le 03/12/13 16:27, St?phane Klein a ?crit : > python-dateutil have a auto discover parse function, but I don't want to use > this auto discover feature For now, I use this : -------- import dateutil.parser import pytz tz_str = '''-12 Y -11 X NUT SST -10 W CKT HAST HST TAHT TKT -9 V AKST GAMT GIT HADT HNY -8 U AKDT CIST HAY HNP PST PT -7 T HAP HNR MST PDT -6 S CST EAST GALT HAR HNC MDT -5 R CDT COT EASST ECT EST ET HAC HNE PET -4 Q AST BOT CLT COST EDT FKT GYT HAE HNA PYT -3 P ADT ART BRT CLST FKST GFT HAA PMST PYST SRT UYT WGT -2 O BRST FNT PMDT UYST WGST -1 N AZOT CVT EGT 0 Z EGST GMT UTC WET WT 1 A CET DFT WAT WEDT WEST 2 B CAT CEDT CEST EET SAST WAST 3 C EAT EEDT EEST IDT MSK 4 D AMT AZT GET GST KUYT MSD MUT RET SAMT SCT 5 E AMST AQTT AZST HMT MAWT MVT PKT TFT TJT TMT UZT YEKT 6 F ALMT BIOT BTT IOT KGT NOVT OMST YEKST 7 G CXT DAVT HOVT ICT KRAT NOVST OMSST THA WIB 8 H ACT AWST BDT BNT CAST HKT IRKT KRAST MYT PHT SGT ULAT WITA WST 9 I AWDT IRKST JST KST PWT TLT WDT WIT YAKT 10 K AEST ChST PGT VLAT YAKST YAPT 11 L AEDT LHDT MAGT NCT PONT SBT VLAST VUT 12 M ANAST ANAT FJT GILT MAGST MHT NZST PETST PETT TVT WFT 13 FJST NZDT 11.5 NFT 10.5 ACDT LHST 9.5 ACST 6.5 CCT MMT 5.75 NPT 5.5 SLT 4.5 AFT IRDT 3.5 IRST -2.5 HAT NDT -3.5 HNT NST NT -4.5 HLV VET -9.5 MART MIT''' tzd = {} for tz_descr in map(str.split, tz_str.split('\n')): tz_offset = int(float(tz_descr[0]) * 3600) for tz_code in tz_descr[1:]: tzd[tz_code] = tz_offset print(tzd) date1 = 'Apr 16 12:09:00 SGT 2010' date = dateutil.parser.parse(date1, tzinfos=tzd).astimezone(pytz.utc) print(date) -------- Are there a better solution ? -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane cv: http://cv.stephane-klein.info From contact at stephane-klein.info Tue Dec 3 10:46:17 2013 From: contact at stephane-klein.info (=?UTF-8?B?U3TDqXBoYW5lIEtsZWlu?=) Date: Tue, 03 Dec 2013 16:46:17 +0100 Subject: I look for a list to convert time zone abbreviation to full time zone in python In-Reply-To: <529DF853.5080900@stephane-klein.info> References: <529DF853.5080900@stephane-klein.info> Message-ID: <529DFCC9.9010203@stephane-klein.info> Le 03/12/13 16:27, St?phane Klein a ?crit : > python-dateutil have a auto discover parse function, but I don't want to use > this auto discover feature For now, I use this : -------- import dateutil.parser import pytz tz_str = '''-12 Y -11 X NUT SST -10 W CKT HAST HST TAHT TKT -9 V AKST GAMT GIT HADT HNY -8 U AKDT CIST HAY HNP PST PT -7 T HAP HNR MST PDT -6 S CST EAST GALT HAR HNC MDT -5 R CDT COT EASST ECT EST ET HAC HNE PET -4 Q AST BOT CLT COST EDT FKT GYT HAE HNA PYT -3 P ADT ART BRT CLST FKST GFT HAA PMST PYST SRT UYT WGT -2 O BRST FNT PMDT UYST WGST -1 N AZOT CVT EGT 0 Z EGST GMT UTC WET WT 1 A CET DFT WAT WEDT WEST 2 B CAT CEDT CEST EET SAST WAST 3 C EAT EEDT EEST IDT MSK 4 D AMT AZT GET GST KUYT MSD MUT RET SAMT SCT 5 E AMST AQTT AZST HMT MAWT MVT PKT TFT TJT TMT UZT YEKT 6 F ALMT BIOT BTT IOT KGT NOVT OMST YEKST 7 G CXT DAVT HOVT ICT KRAT NOVST OMSST THA WIB 8 H ACT AWST BDT BNT CAST HKT IRKT KRAST MYT PHT SGT ULAT WITA WST 9 I AWDT IRKST JST KST PWT TLT WDT WIT YAKT 10 K AEST ChST PGT VLAT YAKST YAPT 11 L AEDT LHDT MAGT NCT PONT SBT VLAST VUT 12 M ANAST ANAT FJT GILT MAGST MHT NZST PETST PETT TVT WFT 13 FJST NZDT 11.5 NFT 10.5 ACDT LHST 9.5 ACST 6.5 CCT MMT 5.75 NPT 5.5 SLT 4.5 AFT IRDT 3.5 IRST -2.5 HAT NDT -3.5 HNT NST NT -4.5 HLV VET -9.5 MART MIT''' tzd = {} for tz_descr in map(str.split, tz_str.split('\n')): tz_offset = int(float(tz_descr[0]) * 3600) for tz_code in tz_descr[1:]: tzd[tz_code] = tz_offset print(tzd) date1 = 'Apr 16 12:09:00 SGT 2010' date = dateutil.parser.parse(date1, tzinfos=tzd).astimezone(pytz.utc) print(date) -------- Are there a better solution ? -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane cv: http://cv.stephane-klein.info From alan.isaac at gmail.com Mon Dec 2 17:34:05 2013 From: alan.isaac at gmail.com (Alan) Date: Mon, 2 Dec 2013 14:34:05 -0800 (PST) Subject: multiprocessing: child process share changes to global variable Message-ID: In the code below, child processes see changes to global variables caused by other child processes. That is, pool.map is producing a list where the value of ``lst`` is being (non-deterministically) shared across child processes. Standard advice is that, "Processes have independent memory space" and "each process works with its own copy" of global variables, so I thought this was not supposed to happen. In the end, the globals are not changed, which matches my expectation. Still, clearly I have misunderstood what seemed to be standard advice. Can someone clarify for me? Expected result from pool.map: [[0],[1],[2]] Usual result: [[0],[0,1],[0,1,2]] Occasional result: [[0],[1],[0,2]] Thanks, Alan Isaac #--------------- temp.py ------------------------- #run at Python 2.7 command prompt import time import multiprocessing as mp lst = [] lstlst = [] def alist(x): lst.append(x) lstlst.append(lst) print "a" return lst if __name__=='__main__': pool = mp.Pool(3) print pool.map(alist,range(3)) #UNEXPECTED RESULTS print "b" time.sleep(0.1) print "c" print lst print lstlst From jsf80238 at gmail.com Tue Dec 3 22:14:40 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 3 Dec 2013 20:14:40 -0700 Subject: multiprocessing: child process share changes to global variable In-Reply-To: References: Message-ID: > #--------------- temp.py ------------------------- > #run at Python 2.7 command prompt > import time > import multiprocessing as mp > lst = [] > lstlst = [] > > def alist(x): > lst.append(x) > lstlst.append(lst) > print "a" > return lst > > if __name__=='__main__': > pool = mp.Pool(3) > print pool.map(alist,range(3)) #UNEXPECTED RESULTS > print "b" > time.sleep(0.1) > > print "c" > print lst > print lstlst > -- I get several different results: $ for i in {1..1000}; do > python2.7 temp.py | md5sum >> result > done $ wc -l result 1000 result $ sort result | uniq | wc -l 9 From alan.isaac at gmail.com Mon Dec 9 12:56:26 2013 From: alan.isaac at gmail.com (Alan) Date: Mon, 9 Dec 2013 09:56:26 -0800 (PST) Subject: multiprocessing: child process share changes to global variable In-Reply-To: References: Message-ID: <7d9fa51a-729c-4903-a251-dc6709cef097@googlegroups.com> I received a suggestion off list that my results indicated that the jobs were not being distributed across the pool workers. I used mp.current_process().name to confirm this suggestion. Alan Isaac From winefrog at gmail.com Mon Dec 2 20:40:19 2013 From: winefrog at gmail.com (Isaac Won) Date: Mon, 2 Dec 2013 17:40:19 -0800 (PST) Subject: Using MFDataset to combine netcdf files in python Message-ID: <8c020248-8deb-47db-8224-7125e698dda7@googlegroups.com> I am trying to combine netcdf files, but it contifuously shows " File "CBL_plot.py", line 11, in f = MFDataset(fili) File "utils.pyx", line 274, in netCDF4.MFDataset.init (netCDF4.c:3822) IOError: master dataset THref_11:00.nc does not have a aggregation dimension." So, I checked only one netcdf files and the information of a netcdf file is as below: float64 th_ref(u't',) unlimited dimensions = () current size = (30,) It looks there is no aggregation dimension. However, I would like to combine those netcdf files rather than just using one by one. Is there any way to create aggregation dimension to make this MFData set work? Below is the python code I used: import numpy as np from netCDF4 import MFDataset varn = 'th_ref' fili = THref_*nc' f = MFDataset(fili) Th = f.variables[varn] Th_ref=np.array(Th[:]) print Th.shape I will really appreciate any help, idea, and hint. Thank you, Isaac From jarausch at igpm.rwth-aachen.de Tue Dec 3 07:18:59 2013 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 3 Dec 2013 12:18:59 GMT Subject: extracting a heapq in a for loop - there must be more elegant solution Message-ID: Hi, I'd like to extracted elements from a heapq in a for loop. I feel my solution below is much too complicated. How to do it more elegantly? I know I could use a while loop but I don't like it. Many thanks for some lessons in Python. Here is my clumsy solution from heapq import heappush, heappop # heappop raises IndexError if heap is empty H=[] for N in 'H','C','W','I' : heappush(H,N) # how to avoid / simplify the following function def in_sequence(H) : try : while True : N= heappop(H) yield N except IndexError : raise StopIteration # and here the application: for N in in_sequence(H) : print(N) From __peter__ at web.de Tue Dec 3 07:38:58 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Dec 2013 13:38:58 +0100 Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: Helmut Jarausch wrote: > Hi, > > I'd like to extracted elements from a heapq in a for loop. > I feel my solution below is much too complicated. > How to do it more elegantly? > I know I could use a while loop but I don't like it. > > Many thanks for some lessons in Python. > > Here is my clumsy solution > > from heapq import heappush, heappop > # heappop raises IndexError if heap is empty > > H=[] > for N in 'H','C','W','I' : > heappush(H,N) H = ["H", "C", "W", "I"] heapq.heapify(H) But see below. > # how to avoid / simplify the following function > > def in_sequence(H) : > try : > while True : > N= heappop(H) > yield N > except IndexError : > raise StopIteration > > # and here the application: > > for N in in_sequence(H) : > print(N) If you are iterating over the complete heap I see no advantage over a sorted list. So for N in sorted(H): print(N) If H is huge use H.sort() instead of sorted() to save memory. If you need only a few items use heapq.nsmallest(). From rustompmody at gmail.com Tue Dec 3 07:40:26 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Dec 2013 04:40:26 -0800 (PST) Subject: extracting a heapq in a for loop - there must be more elegant solution In-Reply-To: References: Message-ID: <7124acb3-7ba2-4b4d-b6e6-8b49e00550fe@googlegroups.com> On Tuesday, December 3, 2013 5:48:59 PM UTC+5:30, Helmut Jarausch wrote: > Hi, > > I'd like to extracted elements from a heapq in a for loop. > I feel my solution below is much too complicated. > How to do it more elegantly? > I know I could use a while loop but I don't like it. How about def in_sequence(h): for i in range(len(h)): yield heapq.heappop(h) Yeah its a bit fiddly: 1. i needed for for but not used 2. The range in the for loop -- normally a python 'smell' If python3 def ins3(h): yield from (heapq.heappop(h) for i in range(len(h))) From jarausch at igpm.rwth-aachen.de Wed Dec 4 04:37:08 2013 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 4 Dec 2013 09:37:08 GMT Subject: extracting a heapq in a for loop - there must be more elegant solution References: <7124acb3-7ba2-4b4d-b6e6-8b49e00550fe@googlegroups.com> Message-ID: On Tue, 03 Dec 2013 04:40:26 -0800, rusi wrote: > On Tuesday, December 3, 2013 5:48:59 PM UTC+5:30, Helmut Jarausch wrote: >> Hi, >> >> I'd like to extracted elements from a heapq in a for loop. >> I feel my solution below is much too complicated. >> How to do it more elegantly? >> I know I could use a while loop but I don't like it. > > How about > > def in_sequence(h): > for i in range(len(h)): > yield heapq.heappop(h) > > Yeah its a bit fiddly: > 1. i needed for for but not used > 2. The range in the for loop -- normally a python 'smell' > > If python3 > > def ins3(h): > yield from (heapq.heappop(h) for i in range(len(h))) Many thanks, I'm using Python3 anyway! Helmut From duncan.booth at invalid.invalid Tue Dec 3 08:06:05 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 3 Dec 2013 13:06:05 GMT Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: Helmut Jarausch wrote: > Hi, > > I'd like to extracted elements from a heapq in a for loop. > I feel my solution below is much too complicated. > How to do it more elegantly? > I know I could use a while loop but I don't like it. > > Many thanks for some lessons in Python. > > Here is my clumsy solution > > from heapq import heappush, heappop > # heappop raises IndexError if heap is empty > > H=[] > for N in 'H','C','W','I' : > heappush(H,N) > > # how to avoid / simplify the following function > > def in_sequence(H) : > try : > while True : > N= heappop(H) > yield N > except IndexError : > raise StopIteration > > # and here the application: > > for N in in_sequence(H) : > print(N) > If all you want to do is pull all of the elements out of the heap in order, you would probably be better off just doing: for N in sorted(H): print(N) Heaps are mostly useful if you want only some of the elements, or if you are continually producing more elements while also processing the smallest ones. However, if you really wnt to do this: for N in iter(lambda: heappop(H) if H else None, None): print(N) will work so long as H cannot contain None. If it can just replace both occurences of None with some other sentinel: sentinel = object() for N in iter(lambda: heappop(H) if H else sentinel, sentinel): print(N) Alternatively your 'in_sequence' function would look better without the exception handling: def in_sequence(H) : while H: yield heappop(H) -- Duncan Booth From jarausch at igpm.rwth-aachen.de Wed Dec 4 04:39:21 2013 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 4 Dec 2013 09:39:21 GMT Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: On Tue, 03 Dec 2013 13:06:05 +0000, Duncan Booth wrote: > Helmut Jarausch wrote: > >> Hi, >> >> I'd like to extracted elements from a heapq in a for loop. >> I feel my solution below is much too complicated. >> How to do it more elegantly? >> I know I could use a while loop but I don't like it. >> >> Many thanks for some lessons in Python. >> >> Here is my clumsy solution >> >> from heapq import heappush, heappop >> # heappop raises IndexError if heap is empty >> >> H=[] >> for N in 'H','C','W','I' : >> heappush(H,N) >> >> # how to avoid / simplify the following function >> >> def in_sequence(H) : >> try : >> while True : >> N= heappop(H) >> yield N >> except IndexError : >> raise StopIteration >> >> # and here the application: >> >> for N in in_sequence(H) : >> print(N) >> > > If all you want to do is pull all of the elements out of the heap in > order, you would probably be better off just doing: > > for N in sorted(H): > print(N) > > Heaps are mostly useful if you want only some of the elements, or if you > are continually producing more elements while also processing the > smallest ones. > > However, if you really wnt to do this: > > for N in iter(lambda: heappop(H) if H else None, None): > print(N) > > will work so long as H cannot contain None. If it can just replace both > occurences of None with some other sentinel: > > sentinel = object() > for N in iter(lambda: heappop(H) if H else sentinel, sentinel): > print(N) > > > Alternatively your 'in_sequence' function would look better without the > exception handling: > > def in_sequence(H) : > while H: > yield heappop(H) Many thanks! And as noted in another reply, I try to overlap CPU time with file I/O since I have to open / read / close a file for each line that gets pushed onto the heap. Helmut From jpiitula at ling.helsinki.fi Tue Dec 3 08:56:11 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 03 Dec 2013 15:56:11 +0200 Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: Helmut Jarausch writes: ... > I know I could use a while loop but I don't like it. ... > from heapq import heappush, heappop > # heappop raises IndexError if heap is empty ... > # how to avoid / simplify the following function > > def in_sequence(H) : > try : > while True : > N= heappop(H) > yield N > except IndexError : > raise StopIteration That seems equivalent to this: def in_sequence(H): while H: yield heappop(H) But I don't like the side-effect. I'd change the name to something that indicates the draining of the heap - heapaerobic? - or consider sorted(H) instead as others suggested. From jarausch at igpm.rwth-aachen.de Wed Dec 4 04:41:35 2013 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 4 Dec 2013 09:41:35 GMT Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: On Tue, 03 Dec 2013 15:56:11 +0200, Jussi Piitulainen wrote: > Helmut Jarausch writes: > ... >> I know I could use a while loop but I don't like it. > ... >> from heapq import heappush, heappop >> # heappop raises IndexError if heap is empty > ... >> # how to avoid / simplify the following function >> >> def in_sequence(H) : >> try : >> while True : >> N= heappop(H) >> yield N >> except IndexError : >> raise StopIteration > > That seems equivalent to this: > > def in_sequence(H): > while H: yield heappop(H) Many thanks, that's something I'd hoped for. > But I don't like the side-effect. I'd change the name to something > that indicates the draining of the heap - heapaerobic? - or consider > sorted(H) instead as others suggested. Since I fill the heap once and empty it afterwards I regard the side-effect clearly visible. Helmut From cs at zip.com.au Tue Dec 3 16:13:03 2013 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Dec 2013 08:13:03 +1100 Subject: extracting a heapq in a for loop - there must be more elegant solution In-Reply-To: References: Message-ID: <20131203211303.GA83257@cskk.homeip.net> On 03Dec2013 12:18, Helmut Jarausch wrote: > I'd like to extracted elements from a heapq in a for loop. > I feel my solution below is much too complicated. > How to do it more elegantly? I can't believe nobody has mentioned PriorityQueue. A PriorityQueue (from the queue module in python 3 and the Queue module in python 2) is essentially just a regular Queue using a heapq for the storage. Example (untested): from Queue import PriorityQueue PQ = PriorityQueue() for item in [1,2,3,7,6,5,9,4]: PQ.put(item) while not PQ.empty(): item = PQ.get() ... do stuff with item ... I iterate over Queues so often that I have a personal class called a QueueIterator which is a wrapper for a Queue or PriorityQueue which is iterable, and an IterablePriorityQueue factory function. Example: from cs.queues import IterablePriorityQueue IPQ = IterablePriorityQueue() for item in [1,2,3,7,6,5,9,4]: IPQ.put(item) for item in IPQ: ... do stuff with item ... Cheers, -- Cameron Simpson http://www.cskk.ezoshosting.com/cs/ Those who do not understand Unix are condemned to reinvent it, poorly. - Henry Spencer @ U of Toronto Zoology, henry at zoo.toronto.edu From ian.g.kelly at gmail.com Tue Dec 3 16:43:10 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Dec 2013 14:43:10 -0700 Subject: extracting a heapq in a for loop - there must be more elegant solution In-Reply-To: <20131203211303.GA83257@cskk.homeip.net> References: <20131203211303.GA83257@cskk.homeip.net> Message-ID: On Tue, Dec 3, 2013 at 2:13 PM, Cameron Simpson wrote: > On 03Dec2013 12:18, Helmut Jarausch wrote: >> I'd like to extracted elements from a heapq in a for loop. >> I feel my solution below is much too complicated. >> How to do it more elegantly? > > I can't believe nobody has mentioned PriorityQueue. As far as I'm aware, the only advantage of PriorityQueue over heapq is that the former is thread-safe, which does not appear to be relevant here. I haven't tested it for speed, but I imagine it would be a fair bit slower, mostly thanks to the locking it needs to do. From ned at nedbatchelder.com Tue Dec 3 17:32:39 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 03 Dec 2013 17:32:39 -0500 Subject: extracting a heapq in a for loop - there must be more elegant solution In-Reply-To: References: <20131203211303.GA83257@cskk.homeip.net> Message-ID: On 12/3/13 4:43 PM, Ian Kelly wrote: > On Tue, Dec 3, 2013 at 2:13 PM, Cameron Simpson wrote: >> On 03Dec2013 12:18, Helmut Jarausch wrote: >>> I'd like to extracted elements from a heapq in a for loop. >>> I feel my solution below is much too complicated. >>> How to do it more elegantly? >> >> I can't believe nobody has mentioned PriorityQueue. > > As far as I'm aware, the only advantage of PriorityQueue over heapq is > that the former is thread-safe, which does not appear to be relevant > here. I haven't tested it for speed, but I imagine it would be a fair > bit slower, mostly thanks to the locking it needs to do. > In fact, if you look at the implementation of PriorityQueue, it uses a heapq internally, so yes, other than the locking, the speed will be the same. --Ned. From cs at zip.com.au Tue Dec 3 18:27:25 2013 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 4 Dec 2013 10:27:25 +1100 Subject: extracting a heapq in a for loop - there must be more elegant solution In-Reply-To: References: Message-ID: <20131203232725.GA19709@cskk.homeip.net> On 03Dec2013 14:43, Ian Kelly wrote: > On Tue, Dec 3, 2013 at 2:13 PM, Cameron Simpson wrote: > > On 03Dec2013 12:18, Helmut Jarausch wrote: > >> I'd like to extracted elements from a heapq in a for loop. > >> I feel my solution below is much too complicated. > >> How to do it more elegantly? > > > > I can't believe nobody has mentioned PriorityQueue. > > As far as I'm aware, the only advantage of PriorityQueue over heapq is > that the former is thread-safe, which does not appear to be relevant > here. I haven't tested it for speed, but I imagine it would be a fair > bit slower, mostly thanks to the locking it needs to do. I could claim I do a lot of multithreaded stuff, which is true. But really I just prefer the put/get abstraction. A heapq is very overtly a heap manipulator applied to an arbitrary list. A Queue is more self contained, for all that it is the same thing happening inside. Cheers, -- Cameron Simpson "Are we alpinists, or are we tourists" followed by "tourists! tourists!" - Kobus Barnard in rec.climbing, on things he's heard firsthand From jarausch at igpm.rwth-aachen.de Wed Dec 4 04:36:17 2013 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 4 Dec 2013 09:36:17 GMT Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: On Tue, 03 Dec 2013 13:38:58 +0100, Peter Otten wrote: > Helmut Jarausch wrote: > >> Hi, >> >> I'd like to extracted elements from a heapq in a for loop. >> I feel my solution below is much too complicated. >> How to do it more elegantly? >> I know I could use a while loop but I don't like it. >> >> Many thanks for some lessons in Python. >> >> Here is my clumsy solution >> >> from heapq import heappush, heappop >> # heappop raises IndexError if heap is empty >> >> H=[] >> for N in 'H','C','W','I' : >> heappush(H,N) > > H = ["H", "C", "W", "I"] > heapq.heapify(H) > > But see below. > >> # how to avoid / simplify the following function >> >> def in_sequence(H) : >> try : >> while True : >> N= heappop(H) >> yield N >> except IndexError : >> raise StopIteration >> >> # and here the application: >> >> for N in in_sequence(H) : >> print(N) > > If you are iterating over the complete heap I see no advantage over a sorted > list. So > > for N in sorted(H): > print(N) > > If H is huge use H.sort() instead of sorted() to save memory. > If you need only a few items use heapq.nsmallest(). Many thanks! In my real application the data which is pushed onto the heap will be extracted from a small file which is executed several thousands times. So, I thought, I could keep the CPU a bit busy while the OS is doing file I/O. Of course, I could have appended all these strings to a list which is sorted at the end. From __peter__ at web.de Wed Dec 4 04:50:52 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Dec 2013 10:50:52 +0100 Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: Helmut Jarausch wrote: > On Tue, 03 Dec 2013 13:38:58 +0100, Peter Otten wrote: > >> Helmut Jarausch wrote: >> >>> Hi, >>> >>> I'd like to extracted elements from a heapq in a for loop. >>> I feel my solution below is much too complicated. >>> How to do it more elegantly? >>> I know I could use a while loop but I don't like it. >>> >>> Many thanks for some lessons in Python. >>> >>> Here is my clumsy solution >>> >>> from heapq import heappush, heappop >>> # heappop raises IndexError if heap is empty >>> >>> H=[] >>> for N in 'H','C','W','I' : >>> heappush(H,N) >> >> H = ["H", "C", "W", "I"] >> heapq.heapify(H) >> >> But see below. >> >>> # how to avoid / simplify the following function >>> >>> def in_sequence(H) : >>> try : >>> while True : >>> N= heappop(H) >>> yield N >>> except IndexError : >>> raise StopIteration >>> >>> # and here the application: >>> >>> for N in in_sequence(H) : >>> print(N) >> >> If you are iterating over the complete heap I see no advantage over a >> sorted list. So >> >> for N in sorted(H): >> print(N) >> >> If H is huge use H.sort() instead of sorted() to save memory. >> If you need only a few items use heapq.nsmallest(). > > > Many thanks! > In my real application the data which is pushed onto the heap will be > extracted from a small file which is executed several thousands times. So, > I thought, I could keep the CPU a bit busy while the OS is doing file I/O. > Of course, I could have appended all these strings to a list which is > sorted at the end. In that case have a look at bisect.insort() which adds an item to a list while keeping it sorted. From jarausch at igpm.rwth-aachen.de Wed Dec 4 04:44:49 2013 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 4 Dec 2013 09:44:49 GMT Subject: extracting a heapq in a for loop - there must be more elegant solution References: Message-ID: On Wed, 04 Dec 2013 08:13:03 +1100, Cameron Simpson wrote: > On 03Dec2013 12:18, Helmut Jarausch wrote: >> I'd like to extracted elements from a heapq in a for loop. >> I feel my solution below is much too complicated. >> How to do it more elegantly? > > I can't believe nobody has mentioned PriorityQueue. > > A PriorityQueue (from the queue module in python 3 and the Queue > module in python 2) is essentially just a regular Queue using a > heapq for the storage. > > Example (untested): > > from Queue import PriorityQueue > > PQ = PriorityQueue() > for item in [1,2,3,7,6,5,9,4]: > PQ.put(item) > > while not PQ.empty(): > item = PQ.get() > ... do stuff with item ... > > I iterate over Queues so often that I have a personal class called > a QueueIterator which is a wrapper for a Queue or PriorityQueue > which is iterable, and an IterablePriorityQueue factory function. > Example: > > from cs.queues import IterablePriorityQueue > > IPQ = IterablePriorityQueue() > for item in [1,2,3,7,6,5,9,4]: > IPQ.put(item) > > for item in IPQ: > ... do stuff with item ... > > Cheers, Many thanks! I think you QueueIterator would be a nice addition to Python's library. Helmut From cs at zip.com.au Wed Dec 4 21:29:58 2013 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 5 Dec 2013 13:29:58 +1100 Subject: extracting a heapq in a for loop - there must be more elegant solution In-Reply-To: References: Message-ID: <20131205022958.GA23485@cskk.homeip.net> On 04Dec2013 09:44, Helmut Jarausch wrote: > On Wed, 04 Dec 2013 08:13:03 +1100, Cameron Simpson wrote: > > I iterate over Queues so often that I have a personal class called > > a QueueIterator which is a wrapper for a Queue or PriorityQueue > > which is iterable, and an IterablePriorityQueue factory function. > > Example: > > > > from cs.queues import IterablePriorityQueue > > > > IPQ = IterablePriorityQueue() > > for item in [1,2,3,7,6,5,9,4]: > > IPQ.put(item) > > > > for item in IPQ: > > ... do stuff with item ... > > Many thanks! > I think you QueueIterator would be a nice addition to Python's library. I'm not convinced. I'm still sorting out the edge cases, and it's my own code and use cases! The basic idea is simple enough: class QueueIterator: def __init__(self, Q, sentinel=None): self.q = Q self.sentinel = sentinel def __next__(self): item = self.q.get() if item is self.sentinel: # queue sentinel again for other users self.q.put(item) raise StopIteration return item def put(self, item): if item is self.sentinel: raise ValueError('.put of sentinel object') return self.q.put(item) def close(self): self.q.put(self.sentinel) QI = QueueIterator(Queue()) Note that it does not work well for PriorityQueues unless you can ensure the sentinel sorted later than any other item. But you really need to be sure nobody does a .get() in the internal queue, or the close protocol doesn't work. This is why the above does not expose a .get() method. You want to prevent .put() on the queue after close(). Of course, I have use cases where I _want_ to allow .put() after close:-( You may want to issue a warning if more than one call to .close happens. And so on. And I have a some weird cases where the close situation has trouble, which probably points to .close() not being a great mapping to my termination scenarios. It is easy to code for the simple data-in, data-out case though. Cheers, -- Cameron Simpson Computer manufacturers have been failing to deliver working systems on time and to budget since Babbage. - Jack Schofield, in The Guardian From breamoreboy at yahoo.co.uk Tue Dec 3 07:58:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Dec 2013 12:58:26 +0000 Subject: Python for microcontrollers Message-ID: I thought this might be of interest Http://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From cjw at ncf.ca Tue Dec 3 09:18:43 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 03 Dec 2013 09:18:43 -0500 Subject: Python for microcontrollers In-Reply-To: References: Message-ID: On 03/12/2013 7:58 AM, Mark Lawrence wrote: > I thought this might be of interest > Http://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers > > Is this intended to be better than the Raspberry PI? RPi handles Python 2 or 3. How would it differ? Colin W. From travisgriggs at gmail.com Tue Dec 3 11:04:48 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 3 Dec 2013 08:04:48 -0800 Subject: Python for microcontrollers In-Reply-To: References: Message-ID: <1C81DF8B-E167-4544-A9AC-0E95BDF54B49@gmail.com> On Dec 3, 2013, at 6:18 AM, Colin J. Williams wrote: > On 03/12/2013 7:58 AM, Mark Lawrence wrote: >> I thought this might be of interest >> Http://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers >> >> > Is this intended to be better than the Raspberry PI? RPi handles Python 2 or 3. > > How would it differ? IMO, a whole different class of computer. From that page, the board they?re targeting ?... clocked at 168MHz and has 1MiB flash and 192KiB RAM.? They?re running OS-less. The Pi, on the other hand actually runs a full OS (Linux) and has specs like 700 MHz, 512MB Ram, and an sd card for storage which means you?re going to have to work hard to find something as small as 2G, the sweet price point is going to actually give you 8G. Whether or not you go for their board, they?re targeting a compute environment that is 5x-ish slower, has at least 2000x less storage space, and works with about a thousandth of the ram of a Pi. Having forayed into the world of small small micro controllers myself this last year and a half, I?m kind of torn on whether this is a good idea or not. But I think it?s cool they?re trying. And I?d definitely try it to see how it worked out. From torriem at gmail.com Tue Dec 3 11:54:49 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 03 Dec 2013 09:54:49 -0700 Subject: Python for microcontrollers In-Reply-To: <1C81DF8B-E167-4544-A9AC-0E95BDF54B49@gmail.com> References: <1C81DF8B-E167-4544-A9AC-0E95BDF54B49@gmail.com> Message-ID: <529E0CD9.4010201@gmail.com> On 12/03/2013 09:04 AM, Travis Griggs wrote: > Having forayed into the world of small small micro controllers myself > this last year and a half, I?m kind of torn on whether this is a good > idea or not. But I think it?s cool they?re trying. And I?d definitely > try it to see how it worked out. I've also been foraying into the world of micro controllers and I personally, after watching the video and reading their spiel, am super excited about this! This is really cool. It's not exactly vaporware either. The software is 95% done. My only concern is that it appears to be (since it's ARM), a 3.3v system. The future is 3.3v, I understand that. But many of the current off-the-shelf sensors and parts are 5v (TTL level). But there's a lot of stuff that's 3.3v now, and there are ways of converting logic levels. From torriem at gmail.com Tue Dec 3 11:06:49 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 03 Dec 2013 09:06:49 -0700 Subject: Python for microcontrollers In-Reply-To: References: Message-ID: <529E0199.2020108@gmail.com> On 12/03/2013 07:18 AM, Colin J. Williams wrote: > On 03/12/2013 7:58 AM, Mark Lawrence wrote: >> I thought this might be of interest >> Http://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers >> >> > Is this intended to be better than the Raspberry PI? RPi handles Python > 2 or 3. > > How would it differ? Raspberry Pi is not a microcontroller. It's an embedded, but still full blown computer and operating system. Big difference. At least at this stage of the game. Maybe in the future all our microwaves will run linux on every chip. But for now, microcontrollers are dominated by 8 and 16-bit microcontrollers that run code with minimal abstraction. Years ago there were chips that ran LISP byte codes, and later Java byte codes. And the stamp chips run BASIC byte codes. And now maybe Python byte codes! At least a subset of python. Right now for prototyping I can place a small program on an Atmel chip (well most microcontrollers actually) that communicates via a well-known protocol on serial, and then I can hack my algorithms together using Python on a PC (or a RPi[1]) and give it a test. Staying in Python would rock. [1] In fact RPi's electrical interface is harder to work with than say an Arduino (3.3v, not quite as adept at interfacing with analog inputs, etc). So many people use them together by mating an Arduino add-on board to the Pi and then communicating with it over serial port. Makes a powerful combination. The RPi turns out to be a very powerful and affordable ethernet shield for arduino! From breamoreboy at yahoo.co.uk Tue Dec 3 09:48:43 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Dec 2013 14:48:43 +0000 Subject: [OT]Does the BDFL play golf? Message-ID: Saw this on a UK Python mailing list and couldn't resist http://thesandtrap.com/products/snake-eyes-python-xld-iron-head -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From geezle86 at gmail.com Tue Dec 3 10:48:43 2013 From: geezle86 at gmail.com (geezle86 at gmail.com) Date: Tue, 3 Dec 2013 07:48:43 -0800 (PST) Subject: The input and output is as wanted, but why error? Message-ID: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> I am trying to solve this problem: http://codeforces.com/problemset/problem/71/A The input and output is as wanted, but my answer keep rejected, here is my source code http://txt.do/1smv Please, I need help. From gordon at panix.com Tue Dec 3 11:03:31 2013 From: gordon at panix.com (John Gordon) Date: Tue, 3 Dec 2013 16:03:31 +0000 (UTC) Subject: The input and output is as wanted, but why error? References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> Message-ID: In <387f5b5f-faf1-4715-8d49-e366be53fd00 at googlegroups.com> geezle86 at gmail.com writes: > I am trying to solve this problem: > http://codeforces.com/problemset/problem/71/A > The input and output is as wanted, but my answer keep rejected, here is > my source code http://txt.do/1smv > Please, I need help. You'll have to explain more about your problem. What, exactly, is wrong? If, as you say, the input and output is correct, then why do you say there is a problem? -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From neilc at norwich.edu Tue Dec 3 11:10:40 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 3 Dec 2013 16:10:40 +0000 (UTC) Subject: The input and output is as wanted, but why error? References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> Message-ID: On 2013-12-03, geezle86 at gmail.com wrote: > I am trying to solve this problem: > > http://codeforces.com/problemset/problem/71/A Please post your code in and the problem in your message. Here it is for those reading along: > A. Way Too Long Words > Sometimes some words like "localization" or > "internationalization" are so long that writing them many times > in one text is quite tiresome. > > Let's consider a word too long, if its length is strictly more > than 10 characters. All too long words should be replaced with > a special abbreviation. > > This abbreviation is made like this: we write down the first > and the last letter of a word and between them we write the > number of letters between the first and the last letters. That > number is in decimal system and doesn't contain any leading > zeroes. > > Thus, "localization" will be spelt as "l10n", and > "internationalization? will be spelt as "i18n". This is a ridiculous abbreviation scheme, but for purposes of your project that doesn't matter. > You are suggested to automatize the process of changing the > words with abbreviations. At that all too long words should be > replaced by the abbreviation and the words that are not too > long should not undergo any changes. > > Input > The first line contains an integer n (1?=?n?=?100). Each of the > following n lines contains one word. All the words consist of > lowercase Latin letters and possess the lengths of from 1 to > 100 characters. > > Output > Print n lines. The i-th line should contain the result of > replacing of the i-th word from the input data Here's your solution so far: > x = input() > > if x.isdigit() == False: > i = len(x) > j = i - 1 > k = i - 2 > > xList = list(x) > > if len(xList) > 4: > print(xList[0], int(k), xList[j], sep='', end='') > else: > print(x) > else: > SystemExit > > The input and output is as wanted, but my answer keep rejected, > here is my source code http://txt.do/1smv No, your program outputs nothing. That's bound to fail. ;) How is your program supposed to work, in your own words? -- Neil Cerutti From geezle86 at gmail.com Tue Dec 3 11:35:20 2013 From: geezle86 at gmail.com (geezle86 at gmail.com) Date: Tue, 3 Dec 2013 08:35:20 -0800 (PST) Subject: The input and output is as wanted, but why error? In-Reply-To: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> Message-ID: <02798e66-515f-45d8-9f45-92f58b16642d@googlegroups.com> > x = input() > > if x.isdigit() == False: > i = len(x) > j = i - 1 > k = i - 2 > > xList = list(x) > > if len(xList) > 4: > print(xList[0], int(k), xList[j], sep='', end='') > else: > print(x) > else: > SystemExit I just dont understand what is wrong, seriously. I mean. They said: "..if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation." and: "... This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes." I solved it with my: xList = list(x) if len(xList) > 4: print(xList[0], int(k), xList[j], sep='', end='') else: print(x) really, i dont know why.. :( From davea at davea.name Tue Dec 3 12:58:13 2013 From: davea at davea.name (Dave Angel) Date: Tue, 03 Dec 2013 12:58:13 -0500 Subject: The input and output is as wanted, but why error? In-Reply-To: <02798e66-515f-45d8-9f45-92f58b16642d@googlegroups.com> References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> <02798e66-515f-45d8-9f45-92f58b16642d@googlegroups.com> Message-ID: On Tue, 3 Dec 2013 08:35:20 -0800 (PST), geezle86 at gmail.com wrote: > really, i dont know why.. :( How about because you do a system exit on the first line of their input? The one that's all digits. And even if you get past that, you only process one of their words. -- DaveA From geezle86 at gmail.com Tue Dec 3 11:36:31 2013 From: geezle86 at gmail.com (geezle86 at gmail.com) Date: Tue, 3 Dec 2013 08:36:31 -0800 (PST) Subject: The input and output is as wanted, but why error? In-Reply-To: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> Message-ID: <01b71b3a-f324-4850-a566-b5402e48baf0@googlegroups.com> > x = input() > > if x.isdigit() == False: > i = len(x) > j = i - 1 > k = i - 2 > > xList = list(x) > > if len(xList) > 4: > print(xList[0], int(k), xList[j], sep='', end='') > else: > print(x) > else: > SystemExit I just dont understand what is wrong, seriously. I mean. They said: "..if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation." and: "... This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes." I solved it with my: xList = list(x) if len(xList) > 10: #I changed it from 4, still not accepted print(xList[0], int(k), xList[j], sep='', end='') else: print(x) really, i dont know why.. :( From neilc at norwich.edu Tue Dec 3 11:58:45 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 3 Dec 2013 16:58:45 +0000 (UTC) Subject: The input and output is as wanted, but why error? References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> <01b71b3a-f324-4850-a566-b5402e48baf0@googlegroups.com> Message-ID: On 2013-12-03, geezle86 at gmail.com wrote: >> x = input() Your first problem is that input() returns text only up the a newline, and then stops. So you are reading the initial number line, but never reading the rest of the lines. -- Neil Cerutti From geezle86 at gmail.com Tue Dec 3 11:38:46 2013 From: geezle86 at gmail.com (geezle86 at gmail.com) Date: Tue, 3 Dec 2013 08:38:46 -0800 (PST) Subject: The input and output is as wanted, but why error? In-Reply-To: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> Message-ID: <66f9ae94-9ba6-4468-a43f-57b19f57816e@googlegroups.com> Well, i've changed the "if len(xList).." from 4 to 10 But still, it is not accepted :( From breamoreboy at yahoo.co.uk Tue Dec 3 11:51:02 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Dec 2013 16:51:02 +0000 Subject: The input and output is as wanted, but why error? In-Reply-To: <66f9ae94-9ba6-4468-a43f-57b19f57816e@googlegroups.com> References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> <66f9ae94-9ba6-4468-a43f-57b19f57816e@googlegroups.com> Message-ID: On 03/12/2013 16:38, geezle86 at gmail.com wrote: > Well, > i've changed the "if len(xList).." from 4 to 10 > > But still, it is not accepted :( > Where is your code that meets these requirements? Input The first line contains an integer n (1?=?n?=?100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Tue Dec 3 12:19:58 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Dec 2013 09:19:58 -0800 (PST) Subject: The input and output is as wanted, but why error? In-Reply-To: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> Message-ID: <49c77ea4-21ab-40f2-a141-975b6f4daa39@googlegroups.com> On Tuesday, December 3, 2013 9:18:43 PM UTC+5:30, geez... at gmail.com wrote: > I am trying to solve this problem: > > http://codeforces.com/problemset/problem/71/A > > The input and output is as wanted, but my answer keep rejected, here is my source code http://txt.do/1smv > > Please, I need help. I suggest you take your problem one step at a time, like this: 1. You need to convert a string like "localization" to "l10n" Write a function that takes strings like "localization" and RETURNS strings like "l10n". The function SHOULD NOT use print. 2. Now you need to convert a list of strings like ["word", "localization", "internationalization", "pneumonoultramicroscopicsilicovolcanoconiosis" ] to a list like ["word", "l10n", "i18n", "p43s"] You can use the above function (1). NO PRINTS 3. Use the function in 2 above to solve the problem. Here you may use print From denismfmcmahon at gmail.com Tue Dec 3 18:52:25 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 3 Dec 2013 23:52:25 +0000 (UTC) Subject: The input and output is as wanted, but why error? References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> Message-ID: On Tue, 03 Dec 2013 07:48:43 -0800, geezle86 wrote: > I am trying to solve this problem: > > http://codeforces.com/problemset/problem/71/A That's not a problem, it's a url. > The input and output is as wanted, but my answer keep rejected, here is > my source code http://txt.do/1smv That's not source code, it's a url. > Please, I need help. As my newsreader isn't a web browser, I can't help. Sorry. -- Denis McMahon, denismfmcmahon at gmail.com From p at google-groups-2013.dobrogost.net Tue Dec 3 12:14:49 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Tue, 3 Dec 2013 09:14:49 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? Message-ID: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Hi! I find global getattr() function awkward when reading code. What is the reason there's no "natural" syntax allowing to access attributes with names not being valid Python identifiers in a similar way to other attributes? Something along the line of my_object.'valid-attribute-name-but-not-valid-identifier'? Regards, Piotr Dobrogost From ned at nedbatchelder.com Tue Dec 3 12:38:21 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 03 Dec 2013 12:38:21 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On 12/3/13 12:14 PM, Piotr Dobrogost wrote: > Hi! > > I find global getattr() function awkward when reading code. > What is the reason there's no "natural" syntax allowing to access attributes with names not being valid Python identifiers in a similar way to other attributes? > Something along the line of my_object.'valid-attribute-name-but-not-valid-identifier'? > > > Regards, > Piotr Dobrogost > I don't know the real reason, but I imagine it would be that it would be very rarely used. It would need to be an attribute that isn't a valid identifier, and you know the attribute at the time you write the code. I can see scenarios for needing attributes that aren't identifiers, but in many of them you also need to access them through a variable rather than literally. --Ned. From davea at davea.name Tue Dec 3 12:48:38 2013 From: davea at davea.name (Dave Angel) Date: Tue, 03 Dec 2013 12:48:38 -0500 Subject: =?UTF-8?Q?Re:_Why_is_there_no_natural_syntax_for_accessing_a?= =?UTF-8?Q?ttributes_with_names=0A_not_being_valid_identifiers=3F?= In-Reply-To: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On Tue, 3 Dec 2013 09:14:49 -0800 (PST), Piotr Dobrogost

wrote: > I find global getattr() function awkward when reading code. Me too. > What is the reason there's no "natural" syntax allowing to access attributes with names not being valid Python identifiers in a similar way to other attributes? There is. Just use a dictionary. -- DaveA From ethan at stoneleaf.us Tue Dec 3 12:31:58 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Dec 2013 09:31:58 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <529E158E.5000106@stoneleaf.us> On 12/03/2013 09:14 AM, Piotr Dobrogost wrote: > > I find global getattr() function awkward when reading code. > What is the reason there's no "natural" syntax allowing to > access attributes with names not being valid Python > identifiers in a similar way to other attributes? > > Something along the line of my_object.'valid-attribute-name-but-not-valid-identifier'? When would you have attribute names that are not valid identifiers? -- ~Ethan~ From random832 at fastmail.us Tue Dec 3 13:03:41 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 03 Dec 2013 13:03:41 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <1386093821.5913.55047941.073BAC99@webmail.messagingengine.com> On Tue, Dec 3, 2013, at 12:14, Piotr Dobrogost wrote: > Hi! > > I find global getattr() function awkward when reading code. > What is the reason there's no "natural" syntax allowing to access > attributes with names not being valid Python identifiers in a similar way > to other attributes? > Something along the line of > my_object.'valid-attribute-name-but-not-valid-identifier'? The getattr function is meant for when your attribute name is in a variable. Being able to use strings that aren't valid identifiers is a side effect. Why are you designing classes with attributes that aren't valid identifiers? From p at google-groups-2013.dobrogost.net Tue Dec 3 18:47:37 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Tue, 3 Dec 2013 15:47:37 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On Tuesday, December 3, 2013 7:03:41 PM UTC+1, rand... at fastmail.us wrote: > On Tue, Dec 3, 2013, at 12:14, Piotr Dobrogost wrote: > > > Hi! > > > I find global getattr() function awkward when reading code. > > What is the reason there's no "natural" syntax allowing to access > > attributes with names not being valid Python identifiers in a similar way > > to other attributes? > > Something along the line of > > my_object.'valid-attribute-name-but-not-valid-identifier'? > > The getattr function is meant for when your attribute name is in a > variable. Being able to use strings that aren't valid identifiers is a > side effect. Why do you say it's a side effect? Could you elaborate? I see nothing odd in passing literal (string literal in this case) as a value of function's argument. > Why are you designing classes with attributes that aren't > valid identifiers? Attribute access syntax being very concise is very often preferred to dict's interface. That's why various containers expose their elements as attributes. In my case I'm using in-house web form library which provides FieldSet class holding objects of type Field or other FieldSets. This nesting leads to names of the form 'outer_fieldset-inner_fieldset-third_field' which are not valid identifiers due to minus sign. From python.list at tim.thechases.com Tue Dec 3 20:06:44 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 3 Dec 2013 19:06:44 -0600 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <20131203190644.2c784f4f@bigbox.christie.dr> On 2013-12-03 15:47, Piotr Dobrogost wrote: > > The getattr function is meant for when your attribute name is in a > > variable. Being able to use strings that aren't valid identifiers > > is a side effect. > > Why do you say it's a side effect? I think random832 is saying that the designed purpose of setattr() was to dynamically set attributes by name, so they could later be accessed the traditional way; not designed from the ground-up to support non-identifier names. But because of the getattr/setattr machinery (dict key/value pairs), it doesn't prevent you from having non-identifiers as names as long as you use only the getattr/setattr method of accessing them. I see non-traditional-identifiers most frequently in test code where the globals() dictionary gets injected with various objects for testing purposes, driven by a table with descriptors. Something like (untested) tests = [ dict(desc="Test 1", input=10, expected=42), dict(desc="Test 2", input=314, expected=159), ] for test in tests: test_name = "test_" + test["desc"] globals()[test_name] = generate_test_function( test["input"], test["output"]) -tkc From timr at probo.com Wed Dec 4 00:45:05 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 03 Dec 2013 21:45:05 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> Piotr Dobrogost

wrote: > >Attribute access syntax being very concise is very often preferred >to dict's interface. It is not "very concise". It is slightly more concise. x = obj.value1 x = dct['value1'] You have saved 3 keystrokes. That is not a significant enough savings to create new syntax. Remember the Python philosophy that there ought to be one way to do it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rustompmody at gmail.com Wed Dec 4 01:31:44 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Dec 2013 22:31:44 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> Message-ID: <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> On Wednesday, December 4, 2013 11:15:05 AM UTC+5:30, Tim Roberts wrote: > Piotr Dobrogost wrote: > > > >Attribute access syntax being very concise is very often preferred > >to dict's interface. > > It is not "very concise". It is slightly more concise. > > x = obj.value1 > x = dct['value1'] > > You have saved 3 keystrokes. That is not a significant enough savings to > create new syntax. Remember the Python philosophy that there ought to be > one way to do it. Its a more fundamental problem than that: It emerges from the OP's second post) that he wants '-' in the attributes. Is that all? Where does this syntax-enlargement stop? Spaces? Newlines? From ian.g.kelly at gmail.com Wed Dec 4 03:57:28 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Dec 2013 01:57:28 -0700 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> Message-ID: On Tue, Dec 3, 2013 at 11:31 PM, rusi wrote: > Its a more fundamental problem than that: > It emerges from the OP's second post) that he wants '-' in the attributes. > Is that all? > > Where does this syntax-enlargement stop? Spaces? Newlines? At non-strings. >>> setattr(foo, 21+21, 42) Traceback (most recent call last): File "", line 1, in TypeError: attribute name must be string, not 'int' From rustompmody at gmail.com Wed Dec 4 05:09:37 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 4 Dec 2013 02:09:37 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> Message-ID: <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> On Wednesday, December 4, 2013 2:27:28 PM UTC+5:30, Ian wrote: > On Tue, Dec 3, 2013 at 11:31 PM, rusi wrote: > > Its a more fundamental problem than that: > > It emerges from the OP's second post) that he wants '-' in the attributes. > > Is that all? > > > > Where does this syntax-enlargement stop? Spaces? Newlines? > > At non-strings. > > >>> setattr(foo, 21+21, 42) > Traceback (most recent call last): > File "", line 1, in > TypeError: attribute name must be string, not 'int' Not sure what's your point. OP wants attribute identifiers like outer_fieldset-inner_fieldset-third_field. Say I have a python expression: obj.outer_fieldset-inner_fieldset-third_field It can (in the proposed extension) be parsed as above, or as: obj.outer_fieldset - inner_fieldset-third_field the first hyphen being minus and the second being part of the identifier. How do we decide which '-' are valid identifier components -- hyphens and which minus-signs? So to state my point differently: The grammar of python is well-defined It has a 'sub-grammar' of strings that is completely* free-for-all ie just about anything can be put into a string literal. The border between the orderly and the wild world are the quote-marks. Remove that border and you get complete grammatical chaos. [Maybe I should have qualified my reference to 'spaces'. Algol-68 allowed spaces in identifiers (for readability!!) The result was chaos] I used the spaces case to indicate the limit of chaos. Other characters (that already have uses) are just as problematic. * Oh well there are some restrictions like quotes need to be escaped, no newlines etc etc -- minor enough to be ignored. From antoon.pardon at rece.vub.ac.be Wed Dec 4 05:29:06 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 04 Dec 2013 11:29:06 +0100 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: <529F03F2.5070707@rece.vub.ac.be> Op 04-12-13 11:09, rusi schreef: > On Wednesday, December 4, 2013 2:27:28 PM UTC+5:30, Ian wrote: >> On Tue, Dec 3, 2013 at 11:31 PM, rusi wrote: >>> Its a more fundamental problem than that: >>> It emerges from the OP's second post) that he wants '-' in the attributes. >>> Is that all? >>> >>> Where does this syntax-enlargement stop? Spaces? Newlines? >> >> At non-strings. >> >>>>> setattr(foo, 21+21, 42) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: attribute name must be string, not 'int' > > Not sure what's your point. > > OP wants attribute identifiers like outer_fieldset-inner_fieldset-third_field. > Say I have a python expression: > obj.outer_fieldset-inner_fieldset-third_field > > It can (in the proposed extension) be parsed as above, or as: > obj.outer_fieldset - inner_fieldset-third_field > the first hyphen being minus and the second being part of the identifier. > > How do we decide which '-' are valid identifier components -- hyphens > and which minus-signs? > > So to state my point differently: > The grammar of python is well-defined > It has a 'sub-grammar' of strings that is completely* free-for-all ie just > about anything can be put into a string literal. > The border between the orderly and the wild world are the quote-marks. > Remove that border and you get complete grammatical chaos. > [Maybe I should have qualified my reference to 'spaces'. > Algol-68 allowed spaces in identifiers (for readability!!) > The result was chaos] > > I used the spaces case to indicate the limit of chaos. Other characters (that > already have uses) are just as problematic. I don't agree with the latter. As it is now python can make the distinction between from A import B and fromAimportB. I see no a priori reason why this should be limited to letters. A language designer might choose to allow a bigger set of characters in identifiers like '-', '+' and others. In that case a-b would be an identifier and a - b would be the operation. Just as in python fromAimportB is an identifier and from A import B is an import statement. -- Antoon Pardon From rosuav at gmail.com Wed Dec 4 05:33:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Dec 2013 21:33:14 +1100 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: On Wed, Dec 4, 2013 at 9:09 PM, rusi wrote: > OP wants attribute identifiers like outer_fieldset-inner_fieldset-third_field. > Say I have a python expression: > obj.outer_fieldset-inner_fieldset-third_field I don't think so. What the OP asked for was: my_object.'valid-attribute-name-but-not-valid-identifier' Or describing it another way: A literal string instead of a token. This is conceivable, at least, but I don't think it gives any advantage over a dictionary. What you could do, though, is create a single object that can be indexed either with dot notation or as a dictionary. For that to work, there'd have to be some restrictions (eg no leading underscores - at very least, __token__ should be special still), but it wouldn't be hard to do - two magic methods and the job's done, I think; you might even be able to manage on one. (Code golf challenge, anyone?) Of course, there's still the question of whether that even is an advantage. ChrisA From python.list at tim.thechases.com Wed Dec 4 06:25:15 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Dec 2013 05:25:15 -0600 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: <20131204052515.593b0d27@bigbox.christie.dr> On 2013-12-04 21:33, Chris Angelico wrote: > I don't think so. What the OP asked for was: > > my_object.'valid-attribute-name-but-not-valid-identifier' > > Or describing it another way: A literal string instead of a token. > This is conceivable, at least, but I don't think it gives any > advantage over a dictionary. In both cases (attribute-access-as-dict-functionality and attribute-access-as-avoiding-setattr), forcing a literal actually diminishes Python's power. I like the ability to do a[key.strip().lower()] = some_value setattr(thing, key.strip().lower(), some_value) which can't be done (?) with mere literal notation. What would they look like? a.(key.strip().lower()) = some_value (note that "key.strip().lower()" not actually a "literal" that ast.literal_eval would accept). That's pretty ugly, IMHO :-) -tkc From rustompmody at gmail.com Wed Dec 4 06:27:46 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 4 Dec 2013 03:27:46 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: <41f1543d-edb7-4e8d-bb47-f23d0440f180@googlegroups.com> On Wednesday, December 4, 2013 4:03:14 PM UTC+5:30, Chris Angelico wrote: > On Wed, Dec 4, 2013 at 9:09 PM, rusi wrote: > > OP wants attribute identifiers like outer_fieldset-inner_fieldset-third_field. > > Say I have a python expression: > > obj.outer_fieldset-inner_fieldset-third_field > > I don't think so. What the OP asked for was: > > my_object.'valid-attribute-name-but-not-valid-identifier' > > Or describing it another way: A literal string instead of a token. This is just pushing the issue one remove away. Firstly a literal string is very much a token -- lexically. Now consider the syntax as defined by the grammar. Let Ident = Set of strings* that are valid python identifiers -- something like [a-zA-Z][a-zA-Z0-9]* Let Exp = Set to strings* that are python expressions * Note that I am using string from the language implementers pov not language user ie the python identifier var is the implementers string "var" whereas the python string literal "var" is the implementer's string "\"var\"" Now clearly Ident is a proper subset of Exp. Now what is the proposal? You want to extend the syntactically allowable a.b set. If the b's can be any arbitrary expression we can have var.fld(1,2) with the grammatical ambiguity that this can be (var.fld)(1,2) -- the usual interpretation Or var.(fld(1,2)) -- the new interpretation -- ie a computed field name. OTOH if you say superset of Ident but subset of Exp, then we have to determine what this new limbo set is to be. ie what is the grammatical category of 'what-follows-a-dot' ?? Some other-language notes: 1. In C there is one case somewhat like this: #include "string" the "string" cannot be an arbitrary expression as the rest of C. But then this is not really C but the C preprocessor 2. In lisp the Ident set is way more permissive than in most languages -- allowing operators etc that would be delimiters in most languages. If one wants to go even beyond that and include say spaces and parenthesis -- almost the only delimiters that lisp has -- one must write |ident with spaces| ie for identifiers the bars behave somewhat like strings' quote marks. Because the semantics of identifiers and strings are different -- the lexical structures need to reflect that difference -- so you cannot replace the bars by quotes. From jpiitula at ling.helsinki.fi Wed Dec 4 06:30:06 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 04 Dec 2013 13:30:06 +0200 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: rusi writes: > On Wednesday, December 4, 2013 2:27:28 PM UTC+5:30, Ian wrote: > > On Tue, Dec 3, 2013 at 11:31 PM, rusi wrote: > > > Its a more fundamental problem than that: > > > It emerges from the OP's second post) that he wants '-' in the > > > attributes. Is that all? > > > > > > Where does this syntax-enlargement stop? Spaces? Newlines? > > > > At non-strings. > > > > >>> setattr(foo, 21+21, 42) > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: attribute name must be string, not 'int' > > Not sure what's your point. > > OP wants attribute identifiers like > outer_fieldset-inner_fieldset-third_field. > Say I have a python expression: > obj.outer_fieldset-inner_fieldset-third_field > > It can (in the proposed extension) be parsed as above, or as: > obj.outer_fieldset - inner_fieldset-third_field > the first hyphen being minus and the second being part of the > identifier. > > How do we decide which '-' are valid identifier components -- > hyphens and which minus-signs? I think the OP might be after the JavaScript mechanism where an attribute name can be any string, the indexing brackets are always available, and the dot notation is available when the attribute name looks like a simple identifier. That could be made to work. (I'm not saying should, or should not. Just that it seems technically simple.) Hm. Can't specific classes be made to behave this way even now by implementing suitable underscored methods? From rosuav at gmail.com Wed Dec 4 06:40:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Dec 2013 22:40:01 +1100 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: On Wed, Dec 4, 2013 at 10:30 PM, Jussi Piitulainen wrote: > Hm. Can't specific classes be made to behave this way even now by > implementing suitable underscored methods? Yup. Definitely possible. I don't think it'd be a good idea, though, not without somehow changing every dict method into a stand-alone function. ChrisA From ethan at stoneleaf.us Wed Dec 4 10:56:13 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 07:56:13 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: <529F509D.9010803@stoneleaf.us> On 12/04/2013 03:30 AM, Jussi Piitulainen wrote: > rusi writes: >> >> How do we decide which '-' are valid identifier components -- >> hyphens and which minus-signs? > > I think the OP might be after the JavaScript mechanism where an > attribute name can be any string, the indexing brackets are always > available, and the dot notation is available when the attribute name > looks like a simple identifier. That could be made to work. (I'm not > saying should, or should not. Just that it seems technically simple.) > > Hm. Can't specific classes be made to behave this way even now by > implementing suitable underscored methods? No. It is possible to provide attribute access along with key access, but not currently possible to provide attribute access with quoted values -- which is what the OP wants. -- ~Ethan~ From rustompmody at gmail.com Wed Dec 4 07:01:23 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 4 Dec 2013 04:01:23 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: <68a2d20a-793f-4493-b856-c6c65617eb0d@googlegroups.com> On Wednesday, December 4, 2013 3:59:06 PM UTC+5:30, Antoon Pardon wrote: > Op 04-12-13 11:09, rusi schreef: > > I used the spaces case to indicate the limit of chaos. > > Other characters (that > > already have uses) are just as problematic. > > I don't agree with the latter. As it is now python can make the > distinction between > > from A import B and fromAimportB. > > I see no a priori reason why this should be limited to letters. A > language designer might choose to allow a bigger set of characters > in identifiers like '-', '+' and others. In that case a-b would be > an identifier and a - b would be the operation. Just as in python > fromAimportB is an identifier and from A import B is an import > statement. Im not sure what you are saying. Sure a language designer can design a language differently from python. I mentioned lisp. Cobol is another behaving exactly as you describe. My point is that when you do (something like) that, you will need to change the lexical and grammatical structure of the language. And this will make for rather far-reaching changes ALL OVER the language not just in what-follows-dot. IOW: I dont agree that we have a disagreement :-) From antoon.pardon at rece.vub.ac.be Wed Dec 4 07:32:18 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 04 Dec 2013 13:32:18 +0100 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <68a2d20a-793f-4493-b856-c6c65617eb0d@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> <68a2d20a-793f-4493-b856-c6c65617eb0d@googlegroups.com> Message-ID: <529F20D2.90701@rece.vub.ac.be> Op 04-12-13 13:01, rusi schreef: > On Wednesday, December 4, 2013 3:59:06 PM UTC+5:30, Antoon Pardon wrote: >> Op 04-12-13 11:09, rusi schreef: >>> I used the spaces case to indicate the limit of chaos. >>> Other characters (that >>> already have uses) are just as problematic. >> >> I don't agree with the latter. As it is now python can make the >> distinction between >> >> from A import B and fromAimportB. >> >> I see no a priori reason why this should be limited to letters. A >> language designer might choose to allow a bigger set of characters >> in identifiers like '-', '+' and others. In that case a-b would be >> an identifier and a - b would be the operation. Just as in python >> fromAimportB is an identifier and from A import B is an import >> statement. > > Im not sure what you are saying. > Sure a language designer can design a language differently from python. > I mentioned lisp. Cobol is another behaving exactly as you describe. > > My point is that when you do (something like) that, you will need to change the > lexical and grammatical structure of the language. And this will make > for rather far-reaching changes ALL OVER the language not just in what-follows-dot. No you don't need to change the lexical and grammatical structure of the language. Changing the characters allowed in identifiers, is not a change in lexical structure. The only difference in lexical structuring would be that '-', '>=' and other similars symbols would have to be treated like keyword like 'from', 'as' etc instead of being recognizable by just being present. And the grammatical structure of the language wouldn't change at all. Sure a-b would now be an identifier and not an operation but that is of no concern for the parser. People would have to be careful to insert spaces around operators and that might make the language somewhat error prone but that doesn't mean the syntactical structure is different. -- Antoon Pardon From rustompmody at gmail.com Wed Dec 4 08:02:37 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 4 Dec 2013 05:02:37 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> <68a2d20a-793f-4493-b856-c6c65617eb0d@googlegroups.com> Message-ID: On Wednesday, December 4, 2013 6:02:18 PM UTC+5:30, Antoon Pardon wrote: > Op 04-12-13 13:01, rusi schreef: > > On Wednesday, December 4, 2013 3:59:06 PM UTC+5:30, Antoon Pardon wrote: > >> Op 04-12-13 11:09, rusi schreef: > >>> I used the spaces case to indicate the limit of chaos. > >>> Other characters (that > >>> already have uses) are just as problematic. > >> > >> I don't agree with the latter. As it is now python can make the > >> distinction between > >> > >> from A import B and fromAimportB. > >> > >> I see no a priori reason why this should be limited to letters. A > >> language designer might choose to allow a bigger set of characters > >> in identifiers like '-', '+' and others. In that case a-b would be > >> an identifier and a - b would be the operation. Just as in python > >> fromAimportB is an identifier and from A import B is an import > >> statement. > > > > Im not sure what you are saying. > > Sure a language designer can design a language differently from python. > > I mentioned lisp. Cobol is another behaving exactly as you describe. > > > > My point is that when you do (something like) that, you will need to change the > > lexical and grammatical structure of the language. And this will make > > for rather far-reaching changes ALL OVER the language not just in what-follows-dot. > > No you don't need to change the lexical and grammatical structure of > the language. Changing the characters allowed in identifiers, is not a > change in lexical structure. The only difference in lexical structuring > would be that '-', '>=' and other similars symbols would have to be > treated like keyword like 'from', 'as' etc instead of being recognizable > by just being present. Well I am mystified? Consider the string a-b in a program text. A Cobol or Lisp system sees this as one identifier. Python, C (and most modern languages) see this ident, operator, ident. As I understand it this IS the lexical structure of the language and the lexer is the part that implements this: - in cobol/lisp keeping it as one - in python/C breaking it into 3 Maybe you understand in some other way the phrase "lexical structure"? > And the grammatical structure of the language wouldn't change at all. > Sure a-b would now be an identifier and not an operation but that is > of no concern for the parser. About grammar maybe what you are saying will hold: presumably if the token-set is the same, one could keep the same grammar, with the differences being entirely inter-lexeme ones. From antoon.pardon at rece.vub.ac.be Wed Dec 4 14:57:11 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 04 Dec 2013 20:57:11 +0100 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> <68a2d20a-793f-4493-b856-c6c65617eb0d@googlegroups.com> Message-ID: <529F8917.8020004@rece.vub.ac.be> Op 04-12-13 14:02, rusi schreef: > On Wednesday, December 4, 2013 6:02:18 PM UTC+5:30, Antoon Pardon wrote: >> Op 04-12-13 13:01, rusi schreef: >>> On Wednesday, December 4, 2013 3:59:06 PM UTC+5:30, Antoon Pardon wrote: >>>> Op 04-12-13 11:09, rusi schreef: >>>>> I used the spaces case to indicate the limit of chaos. >>>>> Other characters (that >>>>> already have uses) are just as problematic. >>>> >>>> I don't agree with the latter. As it is now python can make the >>>> distinction between >>>> >>>> from A import B and fromAimportB. >>>> >>>> I see no a priori reason why this should be limited to letters. A >>>> language designer might choose to allow a bigger set of characters >>>> in identifiers like '-', '+' and others. In that case a-b would be >>>> an identifier and a - b would be the operation. Just as in python >>>> fromAimportB is an identifier and from A import B is an import >>>> statement. >>> >>> Im not sure what you are saying. >>> Sure a language designer can design a language differently from python. >>> I mentioned lisp. Cobol is another behaving exactly as you describe. >>> >>> My point is that when you do (something like) that, you will need to change the >>> lexical and grammatical structure of the language. And this will make >>> for rather far-reaching changes ALL OVER the language not just in what-follows-dot. >> >> No you don't need to change the lexical and grammatical structure of >> the language. Changing the characters allowed in identifiers, is not a >> change in lexical structure. The only difference in lexical structuring >> would be that '-', '>=' and other similars symbols would have to be >> treated like keyword like 'from', 'as' etc instead of being recognizable >> by just being present. > > Well I am mystified? > Consider the string a-b in a program text. > A Cobol or Lisp system sees this as one identifier. > Python, C (and most modern languages) see this ident, operator, ident. > > As I understand it this IS the lexical structure of the language and the lexer > is the part that implements this: > - in cobol/lisp keeping it as one > - in python/C breaking it into 3 > > Maybe you understand in some other way the phrase "lexical structure"? Yes I do. The fact that a certain string is lexically evaluated differently is IMO not enough to conclude the language has a different lexical structure. It only means that the values allowed within the structure are different. What I see here is that some languages have an other alphabet over which identifiers are allowed. >> And the grammatical structure of the language wouldn't change at all. >> Sure a-b would now be an identifier and not an operation but that is >> of no concern for the parser. > > About grammar maybe what you are saying will hold: presumably if the token-set > is the same, one could keep the same grammar, with the differences being > entirely inter-lexeme ones. And the question is. If the token-set is the same, how is then is the lexical structure different rather than just the possible values associate with the tokens? -- Antoon Pardon From ian.g.kelly at gmail.com Wed Dec 4 21:43:49 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Dec 2013 19:43:49 -0700 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: On Wed, Dec 4, 2013 at 3:09 AM, rusi wrote: > On Wednesday, December 4, 2013 2:27:28 PM UTC+5:30, Ian wrote: >> On Tue, Dec 3, 2013 at 11:31 PM, rusi wrote: >> > Its a more fundamental problem than that: >> > It emerges from the OP's second post) that he wants '-' in the attributes. >> > Is that all? >> > >> > Where does this syntax-enlargement stop? Spaces? Newlines? >> >> At non-strings. >> >> >>> setattr(foo, 21+21, 42) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: attribute name must be string, not 'int' > > Not sure what's your point. There was no point. My comment was only meant to be amusing. From rustompmody at gmail.com Wed Dec 4 23:48:29 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 4 Dec 2013 20:48:29 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> <549180f1-fb98-4b59-b92f-5beceb1a6fb5@googlegroups.com> Message-ID: <893d6e43-ac3b-4459-b72b-3106157a301d@googlegroups.com> On Thursday, December 5, 2013 8:13:49 AM UTC+5:30, Ian wrote: > On Wed, Dec 4, 2013 at 3:09 AM, rusi wrote: > > On Wednesday, December 4, 2013 2:27:28 PM UTC+5:30, Ian wrote: > >> On Tue, Dec 3, 2013 at 11:31 PM, rusi wrote: > >> > Its a more fundamental problem than that: > >> > It emerges from the OP's second post) that he wants '-' in the attributes. > >> > Is that all? > >> > > >> > Where does this syntax-enlargement stop? Spaces? Newlines? > >> > >> At non-strings. > >> > >> >>> setattr(foo, 21+21, 42) > >> Traceback (most recent call last): > >> File "", line 1, in > >> TypeError: attribute name must be string, not 'int' > > > > Not sure what's your point. > > There was no point. My comment was only meant to be amusing. Duh! Im dense! From roy at panix.com Wed Dec 4 20:03:14 2013 From: roy at panix.com (Roy Smith) Date: Wed, 04 Dec 2013 20:03:14 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <080d6a56-588b-425f-8968-8f77bc330427@googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: > Spaces? I present to you two FORTRAN statements > > DO 10 I = 3 . 14159 > and > DO10I = 3 , 1 4 1 5 9 > > Which is the loop and which is the assignment? I know it's rude to quote oneself, but: http://www.python.org/doc/humor/#bad-habits From ethan at stoneleaf.us Wed Dec 4 04:12:52 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 01:12:52 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> Message-ID: <529EF214.10604@stoneleaf.us> On 12/03/2013 09:45 PM, Tim Roberts wrote: > Piotr Dobrogost

wrote: >> >> Attribute access syntax being very concise is very often preferred >> to dict's interface. > > It is not "very concise". It is slightly more concise. > > x = obj.value1 > x = dct['value1'] > > You have saved 3 keystrokes. That is not a significant enough savings to > create new syntax. Remember the Python philosophy that there ought to be > one way to do it. That should be "one obvious way". On my keyboard, at least, those are an important three keystrokes! ;) To be clear, I am -1 on the new syntax. -- ~Ethan~ From roy at panix.com Wed Dec 4 08:23:24 2013 From: roy at panix.com (Roy Smith) Date: Wed, 04 Dec 2013 08:23:24 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> Message-ID: In article <17gt99hg615jfm7bdid26185884d2pfdkf at 4ax.com>, Tim Roberts wrote: > Piotr Dobrogost

wrote: > > > >Attribute access syntax being very concise is very often preferred > >to dict's interface. > > It is not "very concise". It is slightly more concise. > > x = obj.value1 > x = dct['value1'] > > You have saved 3 keystrokes. That is not a significant enough savings to > create new syntax. Remember the Python philosophy that there ought to be > one way to do it. I'll trade typing [ ' ' ] for . any day. Easier to type, easier to read. It's not just the character count, it's that you need to move your fingers off the home row (or, at the very least, a big stretch with your pinkie) to reach the brackets. I suppose that depends on your particular keyboard layout and typing style/skill. From p at google-groups-2013.dobrogost.net Wed Dec 4 16:00:32 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 13:00:32 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> Message-ID: On Wednesday, December 4, 2013 2:23:24 PM UTC+1, Roy Smith wrote: > In article <17gt99hg615jfm7bdid26185884d2pfdkf at 4ax.com>, > > Tim Roberts <> wrote: > > > Piotr Dobrogost <> wrote: > > > >Attribute access syntax being very concise is very often preferred > > >to dict's interface. > > > It is not "very concise". It is slightly more concise. > > > x = obj.value1 > > x = dct['value1'] > > > You have saved 3 keystrokes. That is not a significant enough savings to > > create new syntax. Remember the Python philosophy that there ought to be > > one way to do it. > > I'll trade typing [ ' ' ] for . any day. Easier to type, easier to > read. It's not just the character count, it's that you need to move > your fingers off the home row (or, at the very least, a big stretch with > your pinkie) to reach the brackets. I suppose that depends on your > particular keyboard layout and typing style/skill. Very true. Just a remark it's actually trading getattr(o,'x') for o.'x' (saving of 11 keystrokes - don't forget shifts :)) as attribute is quite a different beast then key in a dictionary so comparing this to dict's interface is comparing apples to oranges. Regards, Piotr From p at google-groups-2013.dobrogost.net Wed Dec 4 15:07:17 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 12:07:17 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> Message-ID: <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> On Wednesday, December 4, 2013 6:45:05 AM UTC+1, Tim Roberts wrote: > > It is not "very concise". It is slightly more concise. > > x = obj.value1 > x = dct['value1'] > > You have saved 3 keystrokes. Actually only 1 as you should have compared these: x = obj.'value-1' x = dct['value-1'] Unless we compare with what we have now, which gives 9 (without space) or 10 (with space): x = obj.'value-1' x = getattr(obj, 'value-1') > That is not a significant enough savings to create new syntax. Well, 9 characters is probably significant enough saving to create new syntax but saving these characters is only a side effect and is not the most important aspect of this proposal which leads us to the next point. > Remember the Python philosophy that there ought to be one way to do it. Funny you use this argument against my idea as this idea comes from following this rule whereas getattr goes against it. Using dot is the main syntax to access attributes. Following this, the syntax I'm proposing is much more in line with this primary syntax than getattr is. If there ought to be only one way to access attributes then it should be dot notation. Regards, Piotr From ethan at stoneleaf.us Wed Dec 4 15:22:59 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 12:22:59 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> Message-ID: <529F8F23.20006@stoneleaf.us> On 12/04/2013 12:07 PM, Piotr Dobrogost wrote: > > If there ought to be only one way to access attributes then it should > be dot notation. Not "only one way", it's "one obvious way". The obvious way to deal with objects that do not have legal identifier names is with a dict. -- ~Ethan~ From breamoreboy at yahoo.co.uk Wed Dec 4 15:55:35 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 20:55:35 +0000 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <529F8F23.20006@stoneleaf.us> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> <529F8F23.20006@stoneleaf.us> Message-ID: On 04/12/2013 20:22, Ethan Furman wrote: > On 12/04/2013 12:07 PM, Piotr Dobrogost wrote: >> >> If there ought to be only one way to access attributes then it should >> be dot notation. > > Not "only one way", it's "one obvious way". > > -- > ~Ethan~ Not "one obvious way" it's "There should be one-- and preferably only one --obvious way to do it.". Get it right lad :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ethan at stoneleaf.us Wed Dec 4 16:00:58 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 13:00:58 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> <529F8F23.20006@stoneleaf.us> Message-ID: <529F980A.6020807@stoneleaf.us> On 12/04/2013 12:55 PM, Mark Lawrence wrote: > On 04/12/2013 20:22, Ethan Furman wrote: >> On 12/04/2013 12:07 PM, Piotr Dobrogost wrote: >>> >>> If there ought to be only one way to access attributes then it should >>> be dot notation. >> >> Not "only one way", it's "one obvious way". >> > > Not "one obvious way" it's "There should be one-- and preferably only one --obvious way to do it.". Get it right lad :) I was paraphrasing. ;) -- ~Ethan~ From tjreedy at udel.edu Wed Dec 4 17:11:56 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Dec 2013 17:11:56 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> Message-ID: On 12/4/2013 3:07 PM, Piotr Dobrogost wrote: You have proposed to make non-identifier attribute names 'official', rather than discouraged, by abbreviating > x = getattr(obj, 'value-1') or x = obj.__dict__['value-1'] # implementation detail as > x = obj.'value-1' The discussion of enlarging the scope of 'identifier' is not relevant as you are not proposing that. In particular, you are not asking that obj.value-1 get the 'value-1' attribute of obj. The discussion of keystrokes is also a side-track. What you are proposing, I believe, is a new grammatical category: attribute-name := identifier or string-literal. This would break the symmetry of the grammatical form identifier '.' identifier and change it to the asymmetrical identifier '.' attribute-name, and that is the problem. Most identifiers are attributes of a namespace and many attributes are set *and accessed* as undotted names in module or class code. The symmetry is at least partly inherent and breaking it does not work very well. >>> len is __builtins__.len True >>> __globals__ = __import__(__name__) >>> a = 1 >>> a is __globals__.a True To put it another way, how does 'obj' get the non-standard attribute 'value-1', when obj is a module or class? The workaround given above for module attributes will not work for classes. >> Remember the Python philosophy that there ought to be one way to do >> it. > > Funny you use this argument against my idea as this idea comes from > following this rule whereas getattr goes against it. Not really. As others have pointed out, getattr is the preferred way to get the value of an attribute when you have an object with attributes and a run-time-only reference to the name in a string variable. It would also be the case that "obj.'value' is obj.value", so the proposal *would* add duplication. -- Terry Jan Reedy From p at google-groups-2013.dobrogost.net Wed Dec 4 18:42:14 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 15:42:14 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> Message-ID: <451d174b-6620-476d-bf84-a76c6b1de87e@googlegroups.com> On Wednesday, December 4, 2013 11:11:56 PM UTC+1, Terry Reedy wrote: > > The discussion of enlarging the scope of 'identifier' is not relevant as > you are not proposing that. In particular, you are not asking that > obj.value-1 get the 'value-1' attribute of obj. Right. > The discussion of keystrokes is also a side-track. To great degree, yes. Having said that I find extra 11 keystrokes needed to access some attributes to be a freaking big and unjustifiable number. > What you are proposing, I believe, is a new grammatical category: > attribute-name := identifier or string-literal. This would break the > symmetry of the grammatical form identifier '.' identifier and change it > to the asymmetrical identifier '.' attribute-name, and that is the Nice description. > To put it another way, how does 'obj' get the non-standard attribute > 'value-1', when obj is a module or class? The workaround given above for > module attributes will not work for classes. I'm not sure I see your point. Do you mean that being inside class declaration there's no name that referrs to the current namespace (the way __globals__ refer to module's namespace) thus we can't use proposed syntax to access non-standard attributes from this namespace? > > >> Remember the Python philosophy that there ought to be one way to do > >> it. > > > Funny you use this argument against my idea as this idea comes from > > following this rule whereas getattr goes against it. > > Not really. As others have pointed out, getattr is the preferred way to > get the value of an attribute when you have an object with attributes > and a run-time-only reference to the name in a string variable. Yes, and I think it's very unfortunate in itself. Attribute access is fundamental operation and it's not accident that "operator" for this action is very concise in many languages being one char only. Having to switch to global function to access attribute in case its name is known only at run time is very awkward both when writing and reading code. > It would also be the case that "obj.'value' is obj.value", so the > proposal *would* add duplication. This is not a big deal and that's what you get when someone had already decided that in expression a.b, b is treated literally. Regards, Piotr From tjreedy at udel.edu Wed Dec 4 22:21:06 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Dec 2013 22:21:06 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <451d174b-6620-476d-bf84-a76c6b1de87e@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> <451d174b-6620-476d-bf84-a76c6b1de87e@googlegroups.com> Message-ID: On 12/4/2013 6:42 PM, Piotr Dobrogost wrote: > On Wednesday, December 4, 2013 11:11:56 PM UTC+1, Terry Reedy wrote: >> The discussion of keystrokes is also a side-track. > > To great degree, yes. Having said that I find extra 11 keystrokes > needed to access some attributes to be a freaking big and > unjustifiable number. Given that there is almost no need to ever use operator chars in attribute names and given that syntax changes have the major undesirable consequence of backward incompatibility, I find it to be a small and inconsequential number. >> What you are proposing, I believe, is a new grammatical category: >> attribute-name := identifier or string-literal. This would break >> the symmetry of the grammatical form identifier '.' identifier and >> change it to the asymmetrical identifier '.' attribute-name, and >> that is the > > Nice description. > >> To put it another way, how does 'obj' get the non-standard >> attribute 'value-1', when obj is a module or class? The workaround >> given above for module attributes will not work for classes. The module workaround, which I find pretty ugly, is this: >>> len is __builtins__.len True >>> __globals__ = __import__(__name__) >>> a = 1 >>> a is __globals__.a True I have not checked that the import trick will work when a module is imported, but I believe it will. > I'm not sure I see your point. Do you mean that being inside class > declaration there's no name that referrs to the current namespace > (the way __globals__ refer to module's namespace) thus we can't use > proposed syntax to access non-standard attributes from this > namespace? Right. Class objects are not created until after the class code runs. >> Not really. As others have pointed out, getattr is the preferred >> way to get the value of an attribute when you have an object with >> attributes and a run-time-only reference to the name in a string >> variable. > > Yes, and I think it's very unfortunate in itself. Do you prefer obj.__dict__['name'] to getattr(obj, 'name')? -- Terry Jan Reedy From sg552 at hotmail.co.uk Wed Dec 4 20:50:59 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 05 Dec 2013 01:50:59 +0000 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <17gt99hg615jfm7bdid26185884d2pfdkf@4ax.com> <5eb566a0-3911-48fa-ba83-a863da66a55d@googlegroups.com> Message-ID: On 04/12/2013 20:07, Piotr Dobrogost wrote: >> [...] > > Unless we compare with what we have now, which gives 9 (without space) or 10 (with space): > x = obj.'value-1' > x = getattr(obj, 'value-1') > >> That is not a significant enough savings to create new syntax. > > Well, 9 characters is probably significant enough saving to create new syntax but saving these characters is only a side effect and is not the most important aspect of this proposal which leads us to the next point. > >> Remember the Python philosophy that there ought to be one way to do it. > > Funny you use this argument against my idea as this idea comes from following this rule whereas getattr goes against it. Using dot is the main syntax to access attributes. Following this, the syntax I'm proposing is much more in line with this primary syntax than getattr is. If there ought to be only one way to access attributes then it should be dot notation. I believe that you are missing the point of getattr. It's not there so that one can use arbitrary strings as attribute names; it's there so that one can get attributes with names that aren't known until run time. For this purpose the dot-notation-with-quotes you suggest above is not good enough. For suppose e.g. that one does this: name = 'attribute' x.name How would the interpreter know whether you're asking for getattr(x, name) or getattr(x, 'name')? From p at google-groups-2013.dobrogost.net Wed Dec 4 15:35:14 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 12:35:14 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: > > I think random832 is saying that the designed purpose of setattr() > was to dynamically set attributes by name, so they could later be > accessed the traditional way; not designed from the ground-up to > support non-identifier names. But because of the getattr/setattr > machinery (dict key/value pairs), it doesn't prevent you from having > non-identifiers as names as long as you use only the getattr/setattr > method of accessing them. Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too. Regards, Piotr From breamoreboy at yahoo.co.uk Wed Dec 4 15:46:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 20:46:26 +0000 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On 04/12/2013 20:35, Piotr Dobrogost wrote: > On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: >> >> I think random832 is saying that the designed purpose of setattr() >> was to dynamically set attributes by name, so they could later be >> accessed the traditional way; not designed from the ground-up to >> support non-identifier names. But because of the getattr/setattr >> machinery (dict key/value pairs), it doesn't prevent you from having >> non-identifiers as names as long as you use only the getattr/setattr >> method of accessing them. > > Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too. > > Regards, > Piotr > The obvious thing to do is to either raise this on python ideas, or if you're that confident about it raise an issue on the bug tracker with a patch, which would include changes to unit tests and documentation as well as code, get it reviewed and approved and Bob's your uncle, job done. Too late for Python 3.4 of course, but no problem for 3.5. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Wed Dec 4 21:58:23 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Dec 2013 21:58:23 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On 12/4/2013 3:46 PM, Mark Lawrence wrote: > On 04/12/2013 20:35, Piotr Dobrogost wrote: >> On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: >>> >>> I think random832 is saying that the designed purpose of setattr() >>> was to dynamically set attributes by name, so they could later be >>> accessed the traditional way; not designed from the ground-up to >>> support non-identifier names. But because of the getattr/setattr >>> machinery (dict key/value pairs), it doesn't prevent you from having >>> non-identifiers as names as long as you use only the getattr/setattr >>> method of accessing them. >> >> Right. If there's already a way to have attributes with these >> "non-standard" names Fact. >> (which is a good thing) Opinion, not universally shared by developers, or 'good thing only as long as kept obscure'. >> then for uniformity with dot access to attributes with "standard" names In a later post (after you wrote this) I explained that standard names are not always accessed with a dot, and that uniformity is impossible. >> there should be a variant of dot access allowing to access >> these "non-standard" named attributes, too. More opinion. I am sure that I am not the only developer who disagrees. > The obvious thing to do is to either raise this on python ideas, or if > you're that confident about it raise an issue on the bug tracker with a > patch, which would include changes to unit tests and documentation as > well as code, get it reviewed and approved and Bob's your uncle, job > done. I think the latter would be foolish. Syntax changes have a high bar for acceptance. They should do more than save a few keystrokes. Use of new syntax makes code backward incompatible. New or changed Python modules can be backported (as long as they do not use new syntax ;-) either privately or publicly (on PyPI). 3.2 had no syntax changes; 3.3 one that I know of ('yield from'), which replaced about 15-20 *lines* of very tricky code; 3.4 has none that I can remember. -- Terry Jan Reedy From ethan at stoneleaf.us Wed Dec 4 22:05:14 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 19:05:14 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <529FED6A.6050706@stoneleaf.us> On 12/04/2013 06:58 PM, Terry Reedy wrote: > On 12/4/2013 3:46 PM, Mark Lawrence wrote: >> On 04/12/2013 20:35, Piotr Dobrogost wrote: >>> >>> there should be a variant of dot access allowing to access >>> these "non-standard" named attributes, too. > > More opinion. I am sure that I am not the only developer who disagrees. +1 >> The obvious thing to do is to either raise this on python ideas, or if >> you're that confident about it raise an issue on the bug tracker with a >> patch, which would include changes to unit tests and documentation as >> well as code, get it reviewed and approved and Bob's your uncle, job >> done. > > I think the latter would be foolish. Syntax changes have a high bar for acceptance. They should do more than save a few > keystrokes. +1 -- ~Ethan~ From malaclypse2 at gmail.com Wed Dec 4 15:58:21 2013 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 4 Dec 2013 15:58:21 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On Wed, Dec 4, 2013 at 3:35 PM, Piotr Dobrogost

wrote: > Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too. Given the follow code, what do you think should print? class My_Class(object): pass bar = 1 my_object = My_Class() setattr(my_object, 'foo', 10) setattr(my_object, 'bar', 100) setattr(my_object, 'foo-bar', 1000) print(my_object.foo-bar) Today (in python 3.3), it prints 9, because my_object.foo is 10, the local variable bar is equal to 1, and 10 minus 1 is 9.. Under your new proposal, it would print 1000, right? Is there any way for your proposal to be backwards compatible? -- Jerry From ethan at stoneleaf.us Wed Dec 4 16:02:45 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 13:02:45 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <529F9875.8020408@stoneleaf.us> On 12/04/2013 12:58 PM, Jerry Hill wrote: > On Wed, Dec 4, 2013 at 3:35 PM, Piotr Dobrogost >

wrote: >> Right. If there's already a way to have attributes with these "non-standard" names (which is a good thing) then for uniformity with dot access to attributes with "standard" names there should be a variant of dot access allowing to access these "non-standard" named attributes, too. > > Given the follow code, what do you think should print? > > class My_Class(object): > pass > > bar = 1 > my_object = My_Class() > setattr(my_object, 'foo', 10) > setattr(my_object, 'bar', 100) > setattr(my_object, 'foo-bar', 1000) > > print(my_object.foo-bar) Actually, under his proposal it would be: print(my_object."foo-bar") and it would print 1000, while yours would still print 9. -- ~Ethan~ From neilc at norwich.edu Wed Dec 4 16:41:49 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 4 Dec 2013 21:41:49 +0000 (UTC) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On 2013-12-04, Piotr Dobrogost

wrote: > On Wednesday, December 4, 2013 2:06:44 AM UTC+1, Tim Chase wrote: >> >> I think random832 is saying that the designed purpose of setattr() >> was to dynamically set attributes by name, so they could later be >> accessed the traditional way; not designed from the ground-up to >> support non-identifier names. But because of the getattr/setattr >> machinery (dict key/value pairs), it doesn't prevent you from having >> non-identifiers as names as long as you use only the getattr/setattr >> method of accessing them. > > Right. If there's already a way to have attributes with these > "non-standard" names (which is a good thing) At best its a neutral thing. You can use dict for the same purpose with very little effort and no(?) loss of efficiency. > then for uniformity with dot access to attributes with > "standard" names there should be a variant of dot access > allowing to access these "non-standard" named attributes, too. New syntax needs more than theoretical justifications; it needs persuasive use cases. Using invalid identifiers as attributes is generally a bad idea, not something to do commonly. Your proposed syntax leaves the distinction between valid and invalid identifiers a problem the programmer has to deal with. It doesn't unify access to attributes the way the getattr and setattr do. -- Neil Cerutti From p at google-groups-2013.dobrogost.net Wed Dec 4 16:54:00 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 13:54:00 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti wrote: > > not something to do commonly. Your proposed syntax leaves the > distinction between valid and invalid identifiers a problem the > programmer has to deal with. It doesn't unify access to > attributes the way the getattr and setattr do. Taking into account that obj.'x' would be equivalent to obj.x any attribute can be accessed with the new syntax. I don't see how this is not unified access compared to using getattr instead dot... Regards, Piotr From neilc at norwich.edu Fri Dec 6 09:07:51 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Fri, 6 Dec 2013 14:07:51 +0000 (UTC) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On 2013-12-04, Piotr Dobrogost

wrote: > On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti > wrote: >> not something to do commonly. Your proposed syntax leaves the >> distinction between valid and invalid identifiers a problem >> the programmer has to deal with. It doesn't unify access to >> attributes the way the getattr and setattr do. > > Taking into account that obj.'x' would be equivalent to obj.x > any attribute can be accessed with the new syntax. I don't see > how this is not unified access compared to using getattr > instead dot... I thought of that argument later the next day. Your proposal does unify access if the old obj.x syntax is removed. -- Neil Cerutti From p at google-groups-2013.dobrogost.net Fri Dec 6 11:51:20 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Fri, 6 Dec 2013 08:51:20 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <07ce304a-644b-4e90-8c7d-5d1dcc28ed81@googlegroups.com> On Friday, December 6, 2013 3:07:51 PM UTC+1, Neil Cerutti wrote: > On 2013-12-04, Piotr Dobrogost > >

wrote: > > > On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti > > wrote: > > >> not something to do commonly. Your proposed syntax leaves the > >> distinction between valid and invalid identifiers a problem > >> the programmer has to deal with. It doesn't unify access to > > >> attributes the way the getattr and setattr do. > > > > > > Taking into account that obj.'x' would be equivalent to obj.x > > any attribute can be accessed with the new syntax. I don't see > > how this is not unified access compared to using getattr > > instead dot... > > I thought of that argument later the next day. Your proposal does > unify access if the old obj.x syntax is removed. As long as obj.x is a very concise way to get attribute named 'x' from object obj it's somehow odd that identifier x is treated not like identifier but like string literal 'x'. If it were treated like an identifier then we would get attribute with name being value of x instead attribute named 'x'. Making it possible to use string literals in the form obj.'x' as proposed this would make getattr basically needless as long as we use only variable not expression to denote attribute's name. This is just casual remark. Regards, Piotr From sg552 at hotmail.co.uk Fri Dec 6 19:47:06 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Sat, 07 Dec 2013 00:47:06 +0000 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <07ce304a-644b-4e90-8c7d-5d1dcc28ed81@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <07ce304a-644b-4e90-8c7d-5d1dcc28ed81@googlegroups.com> Message-ID: On 06/12/2013 16:51, Piotr Dobrogost wrote: >> [...] >> >> I thought of that argument later the next day. Your proposal does >> unify access if the old obj.x syntax is removed. > > As long as obj.x is a very concise way to get attribute named 'x' from > object obj it's somehow odd that identifier x is treated not like > identifier but like string literal 'x'. If it were treated like an > identifier then we would get attribute with name being value of x > instead attribute named 'x'. Making it possible to use string literals > in the form obj.'x' as proposed this would make getattr basically > needless as long as we use only variable not expression to denote > attribute's name. But then every time you wanted to get an attribute with a name known at compile time you'd need to write obj.'x' instead of obj.x, thereby requiring two additional keystrokes. Given that the large majority of attribute access Python code uses dot syntax rather than getattr, this seems like it would massively outweigh the eleven keystrokes one saves by writing obj.'x' instead of getattr(obj,'x'). From p at google-groups-2013.dobrogost.net Wed Dec 4 17:13:12 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 14:13:12 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <3a27ef53-64b7-4cf3-9879-8452fab458a1@googlegroups.com> On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti wrote: > On 2013-12-04, Piotr Dobrogost <> wrote: > > > Right. If there's already a way to have attributes with these > > "non-standard" names (which is a good thing) > > At best its a neutral thing. You can use dict for the same > purpose with very little effort and no(?) loss of efficiency. As much as many people in this topic would like to put equal sign between attributes and dictionary's keys they are not the same thing. AFAIK descriptor protocol works only with attributes, right? Regards, Piotr From ethan at stoneleaf.us Wed Dec 4 18:09:52 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 15:09:52 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <3a27ef53-64b7-4cf3-9879-8452fab458a1@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <3a27ef53-64b7-4cf3-9879-8452fab458a1@googlegroups.com> Message-ID: <529FB640.6000005@stoneleaf.us> On 12/04/2013 02:13 PM, Piotr Dobrogost wrote: > On Wednesday, December 4, 2013 10:41:49 PM UTC+1, Neil Cerutti wrote: >> On 2013-12-04, Piotr Dobrogost <> wrote: >> >>> Right. If there's already a way to have attributes with these >>> "non-standard" names (which is a good thing) >> >> At best its a neutral thing. You can use dict for the same >> purpose with very little effort and no(?) loss of efficiency. > > As much as many people in this topic would like to put equal > sign between attributes and dictionary's keys they are not the > same thing. AFAIK descriptor protocol works only with attributes, > right? Correct. It is looking very unlikely that you are going to get enough support for this change. Perhaps you should look at different ways of spelling your identifiers? Why can't you use an underscore instead of a hyphen? -- ~Ethan~ From p at google-groups-2013.dobrogost.net Wed Dec 4 18:57:04 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 15:57:04 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <3a27ef53-64b7-4cf3-9879-8452fab458a1@googlegroups.com> Message-ID: <5d99a76c-35eb-4c1d-bdb5-e4e1f6bea188@googlegroups.com> On Thursday, December 5, 2013 12:09:52 AM UTC+1, Ethan Furman wrote: > Perhaps you should look > at different ways of spelling your identifiers? Why can't you use an > underscore instead of a hyphen? So that underscore could be left for use inside fields' names? However I think we could use some unique Unicode character for this instead hyphen as long as Python allows any alphanumeric Unicode character inside identifiers which I think it does... Regards, Piotr From ethan at stoneleaf.us Wed Dec 4 19:26:20 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Dec 2013 16:26:20 -0800 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <5d99a76c-35eb-4c1d-bdb5-e4e1f6bea188@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <3a27ef53-64b7-4cf3-9879-8452fab458a1@googlegroups.com> <5d99a76c-35eb-4c1d-bdb5-e4e1f6bea188@googlegroups.com> Message-ID: <529FC82C.7020201@stoneleaf.us> On 12/04/2013 03:57 PM, Piotr Dobrogost wrote: > On Thursday, December 5, 2013 12:09:52 AM UTC+1, Ethan Furman wrote: >> >> Perhaps you should look at different ways of spelling your identifiers? >> Why can't you use an underscore instead of a hyphen? > > So that underscore could be left for use inside fields' names? > However I think we could use some unique Unicode character for this > instead hyphen as long as Python allows any alphanumeric Unicode > character inside identifiers which I think it does... Yes, although I don't remember at which version that became true... -- ~Ethan~ From ned at nedbatchelder.com Wed Dec 4 20:17:45 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 04 Dec 2013 20:17:45 -0500 Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: <5d99a76c-35eb-4c1d-bdb5-e4e1f6bea188@googlegroups.com> References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <3a27ef53-64b7-4cf3-9879-8452fab458a1@googlegroups.com> <5d99a76c-35eb-4c1d-bdb5-e4e1f6bea188@googlegroups.com> Message-ID: On 12/4/13 6:57 PM, Piotr Dobrogost wrote: > On Thursday, December 5, 2013 12:09:52 AM UTC+1, Ethan Furman wrote: >> Perhaps you should look >> at different ways of spelling your identifiers? Why can't you use an >> underscore instead of a hyphen? > > So that underscore could be left for use inside fields' names? > However I think we could use some unique Unicode character for this instead hyphen as long as Python allows any alphanumeric Unicode character inside identifiers which I think it does... > > Regards, > Piotr > You object to typing [''] but you don't mind typing an unusual Unicode character? --Ned. From steve at pearwood.info Thu Dec 5 02:56:18 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Dec 2013 07:56:18 GMT Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <52a031a1$0$11112$c3e8da3@news.astraweb.com> On Wed, 04 Dec 2013 12:35:14 -0800, Piotr Dobrogost wrote: > Right. If there's already a way to have attributes with these > "non-standard" names (which is a good thing) No it is not a good thing. It is a bad thing, and completely an accident of implementation that it works at all. Python does not support names (variable names, method names, attribute names, module names etc.) which are not valid identifiers except by accident. The right way to handle non-identifier names is to use keys in a dictionary, which works for any legal string. As you correctly say in another post: "attribute is quite a different beast then key in a dictionary" attributes are intended to be variables, not arbitrary keys. In some languages, they are even called "instance variables". As they are variables, they should be legal identifiers: spam = 42 # legal identifier name spam\n-ham\n = 42 # illegal identifier name Sticking a dot in front of the name doesn't make it any different. Variables, and attributes, should be legal identifiers. If I remember correctly (and I may not), this issue has been raised with the Python-Dev core developers, including Guido, and their decision was: - allowing non-identifier attribute names is an accident of implementation; - Python implementations are allowed to optimize __dict__ to prohibit non- valid identifiers; - but it's probably not worth doing in CPython. getattr already enforces that the attribute name is a string rather than any arbitrary object. You've also raised the issue of linking attribute names to descriptors. Descriptors is certainly a good reason to use attributes, but it's not a good reason for allowing non-identifier names. Instead of writing: obj.'#$^%\n-\'."' just use a legal identifier name! The above is an extreme example, but the principle applies to less extreme examples. It might be slightly annoying to write obj.foo_bar when you actually want of obj.'foo.bar' or obj.'foo\nbar' or some other variation, but frankly, that's just too bad for you. As far as descriptors go, you can implement descriptor-like functionality by overriding __getitem__. Here's a basic example: class MyDict(dict): def __getitem__(self, key): obj = super(MyDict, self).__getitem__(key) if hasattr(obj, '__get__'): obj = obj.__get__(self) which ought to be close to (but not identical) to the semantics of attribute descriptors. While I can see that there is some benefit to allowing non-identifier attributes, I believe such benefit is very small, and not enough to justify the cost by allowing non-identifier attributes. If I wanted to program in a language where #$^%\n-\'." was a legal name for a variable, I'd program in Forth. -- Steven From p at google-groups-2013.dobrogost.net Tue Dec 3 18:49:29 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Tue, 3 Dec 2013 15:49:29 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: <0c86f511-9f41-4758-b9f4-5306402ff50f@googlegroups.com> On Tuesday, December 3, 2013 6:31:58 PM UTC+1, Ethan Furman wrote: > > When would you have attribute names that are not valid identifiers? > See my answer to rand's post. From p at google-groups-2013.dobrogost.net Wed Dec 4 17:05:11 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Wed, 4 Dec 2013 14:05:11 -0800 (PST) Subject: Why is there no natural syntax for accessing attributes with names not being valid identifiers? In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On Tuesday, December 3, 2013 6:48:38 PM UTC+1, Dave Angel wrote: > On Tue, 3 Dec 2013 09:14:49 -0800 (PST), Piotr Dobrogost > > wrote: > > > What is the reason there's no "natural" syntax allowing to access > > attributes with names not being valid Python identifiers in a similar > > way to other attributes? > > There is. Just use a dictionary. Object's attributes and dictionary's keys are quite different things. What about descriptors? Regards, Piotr From davea at davea.name Wed Dec 4 17:28:02 2013 From: davea at davea.name (Dave Angel) Date: Wed, 04 Dec 2013 17:28:02 -0500 Subject: =?UTF-8?Q?Re:_Why_is_there_no_natural_syntax_for_accessing_a?= =?UTF-8?Q?ttributes_with=0A_names_not_being_valid_identifiers=3F?= In-Reply-To: References: <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> <15912943-29a1-4365-b027-7bb8cec447f8@googlegroups.com> Message-ID: On Wed, 4 Dec 2013 14:05:11 -0800 (PST), Piotr Dobrogost

wrote: > Object's attributes and dictionary's keys are quite different things. Right. So if you need arbitrary keys, use a dict. Attributes are keyed by identifiers, which are constrained. No problem. -- DaveA From hpj at urpla.net Tue Dec 3 17:32:25 2013 From: hpj at urpla.net (Hans-Peter Jansen) Date: Tue, 03 Dec 2013 23:32:25 +0100 Subject: Python 2.7.5: Strange and differing behavior depending on sys.setdefaultencoding being set Message-ID: <3323513.NxQf30XKqz@xrated> Hi, I'm experiencing strange behavior with attached code, that differs depending on sys.setdefaultencoding being set or not. If it is set, the code works as expected, if not - what should be the usual case - the code fails with some non-sensible traceback. I tried to boil it down to a comprehensible state, but some LOC are still involved. I use similar code to represent database records, where the repr's appear in user visible logs for example. It is greatly appreciated, if some kind soul could shed some light on this ungrateful behavior. Thanks in advance, Pete -------------- next part -------------- A non-text attachment was scrubbed... Name: reprtest.py Type: text/x-python Size: 4894 bytes Desc: not available URL: From rosuav at gmail.com Tue Dec 3 18:20:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Dec 2013 10:20:31 +1100 Subject: Python 2.7.5: Strange and differing behavior depending on sys.setdefaultencoding being set In-Reply-To: <3323513.NxQf30XKqz@xrated> References: <3323513.NxQf30XKqz@xrated> Message-ID: On Wed, Dec 4, 2013 at 9:32 AM, Hans-Peter Jansen wrote: > I'm experiencing strange behavior with attached code, that differs depending > on sys.setdefaultencoding being set or not. If it is set, the code works as > expected, if not - what should be the usual case - the code fails with some > non-sensible traceback. Interesting. You're mixing str and unicode objects a lot here. The cleanest solution, IMO, would be to either switch to Python 3 or add this to the top of your code: from __future__ import unicode_literals Either way, you'll have all your quoted strings be Unicode, rather than byte, strings. Then take away the requirement that Unicode strings contain non-ASCII characters, and let everything go through that code branch. Looking at this line in reprstr(): s = "u'%s'" % s.replace("'", "\\'") Two potential problems with that. Firstly, the representation is flawed: a backslash in the input string won't be changed, so it's not a true repr; but if this is just for debugging output, that's not a big deal. Secondly, this code might produce either a str or a unicode, depending on the type of s. That may cause messes later; since you seem to be mostly working with the unicode type after that, it'd probably be simpler/safer to make that always return one: s = u"u'%s'" % s.replace("'", "\\'") But the actual problem, I think, is that repr() guarantees to return a str, and you're trying to return a unicode. Here's an illustration: # -*- coding: utf-8 -*- class Foo(object): def __repr__(self): return u'???' foo = Foo() print(foo.__repr__()) print(repr(foo)) The first one succeeds, because building up that string isn't at all a problem. The second one then tries to turn the return value of __repr__ into a string using the default encoding - which defaults to 'ascii', hence the problem you're seeing. Solution 1: Switch to Python 3, in which this will work fine (because repr() in Py3 returns a Unicode string, since _everything_ is Unicode). Solution 2: Explicitly encode in frec, or at the end of Record.__repr__(): def __repr__(self): s = u'%s(\n%s\n)' % (self.__class__.__name__, frec(self.__dict__)) return s.encode("utf-8") (that could be a one-liner, but it's already pushing 80-chars, so if you have a length limit, breaking it helps) Solution 3: Don't use __repr__ here, but simply have your frec function intelligently handle Record types. Effectively, you have your own method of generating a debug description of a Record, which could then return a unicode instead of a str. I personally recommend switching to Python 3 :) But presumably that's not an option, or you'd already have considered it. ChrisA From hpj at urpla.net Tue Dec 3 19:15:34 2013 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 04 Dec 2013 01:15:34 +0100 Subject: Python 2.7.5: Strange and differing behavior depending on sys.setdefaultencoding being set In-Reply-To: References: <3323513.NxQf30XKqz@xrated> Message-ID: <3636037.ckptLqdZpk@xrated> Hi Chris, On Mittwoch, 4. Dezember 2013 10:20:31 Chris Angelico wrote: > On Wed, Dec 4, 2013 at 9:32 AM, Hans-Peter Jansen wrote: > > I'm experiencing strange behavior with attached code, that differs > > depending on sys.setdefaultencoding being set or not. If it is set, the > > code works as expected, if not - what should be the usual case - the code > > fails with some non-sensible traceback. > > Interesting. You're mixing str and unicode objects a lot here. The > cleanest solution, IMO, would be to either switch to Python 3 or add > this to the top of your code: > > from __future__ import unicode_literals > > Either way, you'll have all your quoted strings be Unicode, rather > than byte, strings. Then take away the requirement that Unicode > strings contain non-ASCII characters, and let everything go through > that code branch. > > Looking at this line in reprstr(): > > s = "u'%s'" % s.replace("'", "\\'") > > Two potential problems with that. Firstly, the representation is > flawed: a backslash in the input string won't be changed, so it's not > a true repr; but if this is just for debugging output, that's not a > big deal. Secondly, this code might produce either a str or a unicode, > depending on the type of s. That may cause messes later; since you > seem to be mostly working with the unicode type after that, it'd > probably be simpler/safer to make that always return one: The code serves three purposes: make simple strings more readable, document the others as being unicode, and display those correctly ;) > s = u"u'%s'" % s.replace("'", "\\'") > > But the actual problem, I think, is that repr() guarantees to return a > str, and you're trying to return a unicode. Here's an illustration: > > # -*- coding: utf-8 -*- > class Foo(object): > def __repr__(self): > return u'???' > > foo = Foo() > print(foo.__repr__()) > print(repr(foo)) > > The first one succeeds, because building up that string isn't at all a > problem. The second one then tries to turn the return value of > __repr__ into a string using the default encoding - which defaults to > 'ascii', hence the problem you're seeing. > > Solution 1: Switch to Python 3, in which this will work fine (because > repr() in Py3 returns a Unicode string, since _everything_ is > Unicode). > > Solution 2: Explicitly encode in frec, or at the end of Record.__repr__(): > > def __repr__(self): > s = u'%s(\n%s\n)' % (self.__class__.__name__, > frec(self.__dict__)) return s.encode("utf-8") > > (that could be a one-liner, but it's already pushing 80-chars, so if > you have a length limit, breaking it helps) > > Solution 3: Don't use __repr__ here, but simply have your frec > function intelligently handle Record types. Effectively, you have your > own method of generating a debug description of a Record, which could > then return a unicode instead of a str. Thanks for all your considerations, they are very helpful indeed. Even more helpful, that I understand the issue in question now. I will take some rest and then decide, what to do about this with your precious help. > I personally recommend switching to Python 3 :) But presumably that's > not an option, or you'd already have considered it. You nailed it ;) Given the amount of special unicode handling code, that is necessary to keep Python 2 happy, makes proceeding with it no real fun on a longer term.. And the biggest proponent for hacking in Python IS the fun part of it. Then productivity, elegance, ..., you name it. Have-a-good-day-ly y'rs, Pete From rosuav at gmail.com Tue Dec 3 19:20:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Dec 2013 11:20:40 +1100 Subject: Python 2.7.5: Strange and differing behavior depending on sys.setdefaultencoding being set In-Reply-To: <3636037.ckptLqdZpk@xrated> References: <3323513.NxQf30XKqz@xrated> <3636037.ckptLqdZpk@xrated> Message-ID: On Wed, Dec 4, 2013 at 11:15 AM, Hans-Peter Jansen wrote: > Given the amount of special unicode handling code, that is necessary to keep > Python 2 happy, makes proceeding with it no real fun on a longer term.. > > And the biggest proponent for hacking in Python IS the fun part of it. Then > productivity, elegance, ..., you name it. Yeah. I think Py2 is improved significantly by turning it as much as possible into Py3 (which means, in this case, unicode_literals and then basically working everywhere with Unicode), but of course, that sometimes just moves the breakage - as you found here, with repr() insisting on returning a str. The breakage created by Py3 is so worth taking, it's just a matter of when you move. ChrisA From tristan at realss.com Tue Dec 3 20:34:13 2013 From: tristan at realss.com (Zhang Weiwu) Date: Wed, 4 Dec 2013 09:34:13 +0800 Subject: any use case of logging.config.listen()? Message-ID: Why would anyone use it? I can't think of use cases when one need to change logging configuration dynamically through socket, but not needing the same flexibility on overall configuration for his application (configparser). It feels strange to design a socket interface only to expose logging configuration. If you use logging.config.listen, I very much wish to know what problem are you attacking. I imagined this use case, and invite you to debate if it be valid. Thanks. To design a GUI monitor of a daemon, like amule-gui (log-reading monitor for amule) or pureadmin (log-reading monitor for pureftp). Here is how: 1. The user starts the monitor on his PC. It socket-coneect the daemon written in python - perhaps wrapped by SSH protection - and send a new config file that adds SocketHandler with his own IP address and port. 2. The daemon starts to emit log to TCP socket, the user watches his monitor. 3. When the user finishes, the GUI monitor sends a new config file to remove the handler (is it possible with current API?) Or, the user drops out, the server finds socket dead and removes the SocketHandler on its own. It works like FTP's PORT command, asking server to establish connection back to the client. Unfortunately this technology doesn't work nowadays when most PCs are behind NAT firewall. It begets the question, that if it is easier to write a socket-listening loging handler and forget all about logging.config.listen() stuff. I never did it before, hence the question. From dan at tombstonezero.net Tue Dec 3 22:05:38 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 4 Dec 2013 03:05:38 +0000 (UTC) Subject: any use case of logging.config.listen()? References: Message-ID: On Wed, 04 Dec 2013 09:34:13 +0800, Zhang Weiwu wrote: > Why would anyone use [logging.config.listen()]? I can't think of use > cases when one need to change logging configuration dynamically > through socket, but not needing the same flexibility on overall > configuration for his application (configparser). It feels strange to > design a socket interface only to expose logging configuration. If you > use logging.config.listen, I very much wish to know what problem are > you attacking. Consider a long-running process that listens for input (HTTP, CLI, GUI, or something else; it doesn't matter), does some processing, and produces output. A web server is an example of such a process. Now consider the case that something is wrong with the process, but you're not sure what. So you use logging.config.listen to raise the logging level so that you can see more logging from your process without disturbing it in any way. Or suppose you want to deploy a new plug-in to the process, and temporarily turn "up" the logging to watch the new plug-in emit some debugging-level messages as it starts up. When the new plug-in is finished, you can turn "down" the logging level. With logging.config.listen(), you can do all of this without stopping and restarting the process. > I imagined this use case, and invite you to debate if it be > valid. Thanks. I think your use case is equivalent to the ones I described. Therefore, it is valid. ;-) > It begets the question, that if it is easier to write a > socket-listening loging handler and forget all about > logging.config.listen() stuff. I never did it before, hence the > question. But why develop all of that code when logging.config.listen() already exists? Adding a new SocketHandler seems more heavyweight (and more risky) than adjusting the logging level on an existing SocketHandler. HTH, Dan From tristan at realss.com Wed Dec 4 04:09:22 2013 From: tristan at realss.com (Zhang Weiwu) Date: Wed, 4 Dec 2013 17:09:22 +0800 Subject: any use case of logging.config.listen()? In-Reply-To: References: Message-ID: Thank you a lot for your case description. On Wed, 4 Dec 2013, Dan Sommers wrote: >> It begets the question, that if it is easier to write a >> socket-listening loging handler and forget all about >> logging.config.listen() stuff. I never did it before, hence the >> question. > > But why develop all of that code when logging.config.listen() already > exists? Adding a new SocketHandler seems more heavyweight (and more > risky) than adjusting the logging level on an existing SocketHandler. There are 2 reasons that i cannot just use existing API for the project I am working on. 1. My monitoring GUI client is often behind various NAT. In fact it is a hand-held client, I could be using it in a caf?'s WIFI. It is impossible to tell the python-daemon to just send the log to given address and port. 2. I forgot to explain that in my project adjusting log level is only half of what needs to be done. The monitoring GUI client also needs to be able to send a few operational parameters' change. e.g. I need to see the log, and decide to change 'Threshold' from 0.5 to 0.53 and see the difference. For the first problem, a new logging.ListeningSocketHandler would work - don't know if it is easy to write one - which can be written in a way that simply drops logs if no one is listening, thus forgoing logging.config.listen(). For the second problem, a way to dynamically accept new operational paramters from socket is needed, solo logging.config.listen() wouldn't suffice. Either case I don't find use of logging.config.listen(), even though I am looking hard for every way to reuse existing code. From rosuav at gmail.com Wed Dec 4 05:53:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Dec 2013 21:53:49 +1100 Subject: any use case of logging.config.listen()? In-Reply-To: References: Message-ID: On Wed, Dec 4, 2013 at 8:09 PM, Zhang Weiwu wrote: > Either case I don't find use of logging.config.listen(), even though I am > looking hard for every way to reuse existing code. > That's not a problem. It's a feature that doesn't quite fit your task, so you don't use it. It's like trying to install an operating system on a new computer and deciding that emacs isn't the one for you. *dives for cover* ChrisA From frank at chagford.com Wed Dec 4 04:16:40 2013 From: frank at chagford.com (Frank Millman) Date: Wed, 4 Dec 2013 11:16:40 +0200 Subject: A cautionary tale Message-ID: Hi all There is no question at the end of this, it is just an account of a couple of days in the life of a programmer (me). I just felt like sharing it. Feel free to ignore. The business/accounting system I am writing involves a lot of reading data from a database, and if changed, writing it back again. There are a number of data types involved - string, integer, decimal, boolean, date, datetime. I currently support PostgreSQL, MS SQL Server, and sqlite3. In all cases, they have a DB-API 2.0-compliant adaptor which handles the conversion to and from python objects transparently. Over the last year or so I have added two new types. I added a JSON type, to handle 'lists' and 'dicts', and an XML type to handle more complex structures. In both cases they are stored in the database as strings, so I have to handle the conversions myself. I don't allow direct access to the objects, as they can be affected by various business rules, so I use getters and setters. For the new types, I used the getter to convert from the string to the underlying object, and the setter to convert it back to a string. Then a couple of days ago I decided that this was not the correct place to do it - it should be done when reading from and writing to the database. That way the data is always represented by the underlying object, which can be passed around without worrying about conversions. It was a bit of effort, as I had to add extra getters and setters to handle the transfer between the database and the program, and then over-ride them in the case of the new data types to provide the required functionality. But after a few hours of hunting down all the places that required changes, testing, fixing errors, etc, it seemed to be working fine, so I thought I could carry on with the meat of my program. Then I noticed that certain changes were not being written back to the database. After some investigation, I found the error in a part of my program that I have not had to look at for ages. When reading data in from the database, I preserve a copy of the original value. When saving, I compare that to the current value when deciding which columns need updating. I do this in the obvious way - on reading - orig_value = value on saving - if value != orig_value: this one needs updating Have you spotted the deliberate mistake yet? In the case of a JSON list, orig_value and value point to the same, mutable, list. So when I compare value with orig_value, they are always the same, whether changes have been made or not! The obvious answer is to store a copy of the list. It was not so obvious where to make the change, as there were other implications. Eventually I decided to over-ride the 'getter' for the JSON type, and return copy(value) instead of value. That way if it is changed and then put back using the 'setter', the two objects are no longer equal. I have made that change, done some more testing, and for now it seems ok. So have the last couple of days been a waste of time? I don't think so. Is the program a bit cleaner and conceptually sounder? I hope so. Why am I telling you all this? No particular reason, just thought some of you might find it interesting. Frank Millman From __peter__ at web.de Wed Dec 4 05:08:23 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Dec 2013 11:08:23 +0100 Subject: A cautionary tale References: Message-ID: Frank Millman wrote: > Hi all > > There is no question at the end of this, it is just an account of a couple > of days in the life of a programmer (me). I just felt like sharing it. > Feel free to ignore. > > The business/accounting system I am writing involves a lot of reading data > from a database, and if changed, writing it back again. > > There are a number of data types involved - string, integer, decimal, > boolean, date, datetime. I currently support PostgreSQL, MS SQL Server, > and sqlite3. In all cases, they have a DB-API 2.0-compliant adaptor which > handles the conversion to and from python objects transparently. > > Over the last year or so I have added two new types. I added a JSON type, > to handle 'lists' and 'dicts', and an XML type to handle more complex > structures. In both cases they are stored in the database as strings, so I > have to handle the conversions myself. > > I don't allow direct access to the objects, as they can be affected by > various business rules, so I use getters and setters. For the new types, I > used the getter to convert from the string to the underlying object, and > the setter to convert it back to a string. > > Then a couple of days ago I decided that this was not the correct place to > do it - it should be done when reading from and writing to the database. > That way the data is always represented by the underlying object, which > can be passed around without worrying about conversions. > > It was a bit of effort, as I had to add extra getters and setters to > handle the transfer between the database and the program, and then > over-ride them in the case of the new data types to provide the required > functionality. But after a few hours of hunting down all the places that > required changes, testing, fixing errors, etc, it seemed to be working > fine, so I thought I could carry on with the meat of my program. > > Then I noticed that certain changes were not being written back to the > database. After some investigation, I found the error in a part of my > program that I have not had to look at for ages. When reading data in from > the database, I preserve a copy of the original value. When saving, I > compare that to the current value when deciding which columns need > updating. I do this in the obvious way - > > on reading - > orig_value = value > > on saving - > if value != orig_value: > this one needs updating > > Have you spotted the deliberate mistake yet? In the case of a JSON list, > orig_value and value point to the same, mutable, list. So when I compare > value with orig_value, they are always the same, whether changes have been > made or not! > > The obvious answer is to store a copy of the list. It was not so obvious > where to make the change, as there were other implications. Eventually I > decided to over-ride the 'getter' for the JSON type, and return > copy(value) instead of value. That way if it is changed and then put back > using the 'setter', the two objects are no longer equal. I have made that > change, done some more testing, and for now it seems ok. > > So have the last couple of days been a waste of time? I don't think so. Is > the program a bit cleaner and conceptually sounder? I hope so. > > Why am I telling you all this? No particular reason, just thought some of > you might find it interesting. You might like to know how others cope with basically the same problem: http://docs.python.org/dev/library/shelve.html#example http://www.zodb.org/en/latest/documentation/tutorial.html#persistent-objects From steve at pearwood.info Thu Dec 5 03:06:13 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Dec 2013 08:06:13 GMT Subject: A cautionary tale References: Message-ID: <52a033f5$0$11112$c3e8da3@news.astraweb.com> On Wed, 04 Dec 2013 11:16:40 +0200, Frank Millman wrote: [...] > Then I noticed that certain changes were not being written back to the > database. After some investigation, I found the error in a part of my > program that I have not had to look at for ages. When reading data in > from the database, I preserve a copy of the original value. When saving, > I compare that to the current value when deciding which columns need > updating. I do this in the obvious way - > > on reading - > orig_value = value As you know, that is not the obvious way to create a copy. That binds a new name to the same value. To create a copy, you need: orig_value = copy.copy(value) or for lists: orig_value = value[:] I think we've all made the same mistake you have, it's an easy mistake to make, but for an experienced Python code it should also be an easy mistake to identify. Mind you, tracking it down might take a while... > on saving - > if value != orig_value: > this one needs updating > > Have you spotted the deliberate mistake yet? In the case of a JSON list, > orig_value and value point to the same, mutable, list. So when I compare > value with orig_value, they are always the same, whether changes have > been made or not! > > The obvious answer is to store a copy of the list. It was not so obvious > where to make the change, as there were other implications. Eventually I > decided to over-ride the 'getter' for the JSON type, and return > copy(value) instead of value. That way if it is changed and then put > back using the 'setter', the two objects are no longer equal. I have > made that change, done some more testing, and for now it seems ok. I wouldn't do it that way. To my mind, the most obvious way of handling this is to add a "changed" flag to the object, and ensure that any modifications set the flag. Of course, that may end up being more work than the way you've done it, but it will save making potentially many copies of objects which don't need to be copied. > So have the last couple of days been a waste of time? I don't think so. > Is the program a bit cleaner and conceptually sounder? I hope so. > > Why am I telling you all this? No particular reason, just thought some > of you might find it interesting. Thank you for sharing your experiences with us! -- Steven From frank at chagford.com Thu Dec 5 03:57:28 2013 From: frank at chagford.com (Frank Millman) Date: Thu, 5 Dec 2013 10:57:28 +0200 Subject: A cautionary tale References: <52a033f5$0$11112$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:52a033f5$0$11112$c3e8da3 at news.astraweb.com... > On Wed, 04 Dec 2013 11:16:40 +0200, Frank Millman wrote: > > [...] >> Then I noticed that certain changes were not being written back to the >> database. After some investigation, I found the error in a part of my >> program that I have not had to look at for ages. When reading data in >> from the database, I preserve a copy of the original value. When saving, >> I compare that to the current value when deciding which columns need >> updating. I do this in the obvious way - >> >> on reading - >> orig_value = value > > As you know, that is not the obvious way to create a copy. That binds a > new name to the same value. To create a copy, you need: > > orig_value = copy.copy(value) > > or for lists: > > orig_value = value[:] > True enough, but before I added my new data types, all the types I used were immutable, so I got away with it. [...] > > I wouldn't do it that way. To my mind, the most obvious way of handling > this is to add a "changed" flag to the object, and ensure that any > modifications set the flag. > > Of course, that may end up being more work than the way you've done it, > but it will save making potentially many copies of objects which don't > need to be copied. > > There are two (no, make that three) reasons why I need to preserve the original value - 1. A user can make changes to an object, and then before saving, select 'cancel'. I then restore all values to their originals. 2. I keep an 'audit trail' of changes to data rows, showing before and after values. 3. I use a form of 'optimistic concurrency control' to guard against two users updating the same row at the same time, resulting in one set of changes being overwritten. The classic form adds a 'timestamp' column to the table, which is timestamped on every update. Prior to executing an update, the timestamp is re-read from the database, and if not the same as the original, the update is aborted. My variation is to compare only those columns which have been changed, so I compare the re-read values with the orig_values. The benefit is that an organisation could have one user maintaining, say, credit information, while another may be trying to change the same person's telephone number. With my approach, both will succeed even if executed simultaneously [1]. Frank [1] Not literally simultaneously. All that is required is that one user selects the row, and then before updating it, someone else selects the same row. From loic.espern at gmail.com Wed Dec 4 05:18:22 2013 From: loic.espern at gmail.com (loic.espern at gmail.com) Date: Wed, 4 Dec 2013 02:18:22 -0800 (PST) Subject: Print a text at a specific location on the page Message-ID: Hi all This is my first post on this list :-) I have a web-application (developped using a python framework). In this web-app, I would like to print certificates for some courses. The principle : The course teacher has a "default" certificates, with placeholders for the name, and the certification name. ("Congratulations _______ you successfully passed the ______ course") He puts the certificate in his printer, and my app prints the name, and the certification on a specific location, to fill the placeholders. I looked at ReportLab, and Pod. They seems powerfull to build complex reports, but I wonder if it exists a simpler solution just to print a text at a specific place on the page... Thank you From __peter__ at web.de Wed Dec 4 05:57:08 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Dec 2013 11:57:08 +0100 Subject: Print a text at a specific location on the page References: Message-ID: loic.espern at gmail.com wrote: > Hi all > > This is my first post on this list :-) > > I have a web-application (developped using a python framework). In this > web-app, I would like to print certificates for some courses. > > The principle : > The course teacher has a "default" certificates, with placeholders for the > name, and the certification name. ("Congratulations _______ you > successfully passed the ______ course") He puts the certificate in his > printer, and my app prints the name, and the certification on a specific > location, to fill the placeholders. > > I looked at ReportLab, and Pod. They seems powerfull to build complex > reports, but I wonder if it exists a simpler solution just to print a text > at a specific place on the page... > > Thank you I have the following quick-and-dirty wrapper for cairographics lying around -- just added the demo. #/usr/bin/env python3 import cairo import math from contextlib import contextmanager A4 = 595, 842 _mm = 72/25.4 def mm(x): """Convert mm to cairo-native (point)""" return x * _mm class Context(object): """Wrapper for a cairo context object. Methods it doesn't provide are delegated to the cairo.Context instance. """ def __init__(self, width, height, context): self.width = width self.height = height self.context = context def __getattr__(self, name): """Unknown attribute, delegate to cairo context """ return getattr(self.context, name) @contextmanager def fontsize(self, size): """Set fontsize temporarily to something other than 12pt""" self.context.set_font_size(size) yield self.context.set_font_size(12) def line(self, start_x, start_y, end_x, end_y): """Draw a line from (start_x, start_y) to (end_x, end_y)""" self.context.move_to(start_x, start_y) self.context.line_to(end_x, end_y) def text_at(self, left, top, text): """Draw `text` at position (left, top)""" self.context.move_to(left, top) self.context.text_path(text) def setup_context( filename, size, landscape, font="Times New Roman", slant=cairo.FONT_SLANT_NORMAL): """Create a cairo drawing context suitable for printing in landscape format. """ width, height = size # http://cairographics.org/documentation/using_the_postscript_surface/ # recommends the following for printing in landscape # # the "natural" approach (swapping width and height directly without # dsc_comment, translate, rotate, looked OK in Okular resulted in misplaced # (large left/top offset, bottom right corner clipped) output in print surface = cairo.PSSurface(filename, width, height) if landscape: surface.dsc_comment("%%PageOrientation: Landscape") context = cairo.Context(surface) context.translate(0, height) context.rotate(-math.pi/2) width, height = height, width else: context = cairo.Context(surface) context.select_font_face( font, slant, cairo.FONT_WEIGHT_NORMAL) context.set_font_size(12) context.set_line_width(.5) return Context(width, height, context) if __name__ == "__main__": def demo(): context = setup_context("tmp.ps", A4, landscape=False, font="Times") with context.fontsize(18): context.text_at(mm(20), mm(100), "Max Mustermann") context.text_at(mm(120), mm(100), "Brewing") context.fill() demo() If that's too dirty for you consider using cairographics directly... From robin at reportlab.com Wed Dec 4 08:42:44 2013 From: robin at reportlab.com (Robin Becker) Date: Wed, 04 Dec 2013 13:42:44 +0000 Subject: simple ElementTree based parser that allows entity definition map Message-ID: <529F3154.2020709@chamonix.reportlab.co.uk> I'm tasked with writing a 'simple' ElementTree based parser with support for unknown entities eg &foo;. This code derived from FL's old documentation fails in both python 2 and 3. ######################## import xml.etree.ElementTree as ET try: ascii except: from future_builtins import ascii class EchoTarget: def start(self, tag, attrib): print("start %s %s"%(tag, ascii(attrib))) def end(self, tag): print("end %s"%tag) def data(self, data): print("data %s" % ascii(data)) def close(self): print("close") def __getattr__(self,a): print('target attempting to get attribute %s' % a) target = EchoTarget() parser = ET.XMLParser(target=target) parser.entity['foo'] = b'AAAA&fum;BBBB' parser.entity['fum'] = b'CCCC' print("parser.entity=%s" % ascii(parser.entity)) parser.feed("some text &foo;") parser.feed("") parser.close() ######################## The entity value doesn't seem to get referenced. I tried this derived from http://stackoverflow.com/questions/7237466/python-elementtree-support-for-parsing-unknown-xml-entities ######################## __all__=tuple(filter(None,''' Xml2TT EntityMap '''.split())) import xml.etree.ElementTree as ET try: from StringIO import StringIO except ImportError: from io import StringIO class EntityMap(dict): def __getitem__(self,key): try: r = dict.__getitem__(self,key) except: r = '&' + key +';' return r class Xml2TT: ''' create a callable object that can turns xml into a tupletree if mutable is set to True then it's really a list tree ''' def __init__(self,mutable=False,entityMap=None): self._mutable = mutable self._parser = parser = ET.XMLParser() parser.parser.UseForeignDTD(True) parser.entity = self._entityMap = entityMap def __call__(self,xml): r = self._mtt(ET.ElementTree().parse(StringIO(xml.strip()), parser=self._parser)) return r[0] def _mtt(self,node): t = [node.text] if node.text else [] e = t.extend for c in node: e(self._mtt(c)) t = (node.tag,node.attrib,t,None) if self._mutable: t = list(t) return [t,node.tail] if node.tail else [t] if __name__=='__main__': print(repr(Xml2TT()('aaaaabbbb22'))) print(repr(Xml2TT()('aaaaa=&=bbbbb< >'))) print(repr(Xml2TT(entityMap=EntityMap({'mu': '…','foo': 'AAA&fum;BBB','fum':'CCC'}))('amp=& moo=&moo; lt=< gt=> mu=μ foo=&foo;'))) ######################## and it sort of works in python2, fails in python3 with AttributeError: 'xml.etree.ElementTree.XMLParser' object has no attribute 'parser' Even in python 2 there's a subtle bug as the output is ('a', {}, ['aaaaa', ('b', {}, ['bbbb', ('c', {'ca': '123'}, [], None), '22'], None)], None) ('a', {}, ['aaaaa=&=bbbbb< >'], None) ('a', {}, [u'amp=& moo=&moo; lt=< gt=> mu=… foo=AAA&fum;BBB'], None) ie the result of the &foo; lookup is not re-parsed so &fum; is not translated. Is there a way to get a simple ElementTree based parser that can do what I want? I have several hundred entities and the size of the DTD would probably be larger than 99% of the strings I need to parse. I think I can live with the non-reparsing of the map output, but can I get Python 3 to do the UseForeignDTD thing? -- Robin Becker From geezle86 at gmail.com Wed Dec 4 10:38:09 2013 From: geezle86 at gmail.com (geezle86 at gmail.com) Date: Wed, 4 Dec 2013 07:38:09 -0800 (PST) Subject: Input without line break, is it possible? Message-ID: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> The source code: for i in range(8): n = input() When we run it, consider the numbers below is the user input, 1 2 3 4 5 6 (and so forth) my question, can i make it in just a single line like, 1 2 3 4 5 6 (and so forth) Can I? From python.list at tim.thechases.com Wed Dec 4 10:55:43 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Dec 2013 09:55:43 -0600 Subject: Input without line break, is it possible? In-Reply-To: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> Message-ID: <20131204095543.3b4269d8@bigbox.christie.dr> On 2013-12-04 07:38, geezle86 at gmail.com wrote: > for i in range(8): > n = input() > > When we run it, consider the numbers below is the user input, > > 1 > 2 > 3 > 4 > 5 > 6 > (and so forth) > > my question, can i make it in just a single line like, > > 1 2 3 4 5 6 (and so forth) Not easily while processing the input one at a time. You can, however, read one line of input and then split it: s = input() bits = s.split() if len(bits) != 8: what_now("?") else: for bit in bits: do_something(bit) You could make it a bit more robust with something like: answers = [] while len(answers) < 8: s = input() answers.append(s.split()) del answers[8:] # we only want 8, so throw away extras for answer in answers: do_something(answer) which would at least ensure that you have 8 entries. -tkc From tim at thechases.com Wed Dec 4 11:07:41 2013 From: tim at thechases.com (Tim Chase) Date: Wed, 4 Dec 2013 10:07:41 -0600 Subject: Input without line break, is it possible? [correction] In-Reply-To: <20131204095543.3b4269d8@bigbox.christie.dr> References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> <20131204095543.3b4269d8@bigbox.christie.dr> Message-ID: <20131204100741.36d6f5af@bigbox.christie.dr> On 2013-12-04 09:55, Tim Chase wrote: > You could make it a bit more robust with something like: > > answers = [] > while len(answers) < 8: > s = input() > answers.append(s.split()) this should be answers.extend(s.split()) instead of .append() That's what I get for coding in my inbox rather than copy/pasting from tested Python code. -tkc From breamoreboy at yahoo.co.uk Wed Dec 4 11:04:00 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 16:04:00 +0000 Subject: Input without line break, is it possible? In-Reply-To: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> Message-ID: On 04/12/2013 15:38, geezle86 at gmail.com wrote: > The source code: > > for i in range(8): > n = input() > > When we run it, consider the numbers below is the user input, > > 1 > 2 > 3 > 4 > 5 > 6 > (and so forth) > > my question, can i make it in just a single line like, > > 1 2 3 4 5 6 (and so forth) > > Can I? > Yes you can get them on a single line, see the response from Tim Chase. But just to be crystal clear, are you aware that you're getting string representations of numbers, and not the numbers themselves? -- 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 Wed Dec 4 11:14:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Dec 2013 03:14:18 +1100 Subject: Input without line break, is it possible? In-Reply-To: References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> Message-ID: On Thu, Dec 5, 2013 at 3:04 AM, Mark Lawrence wrote: > On 04/12/2013 15:38, geezle86 at gmail.com wrote: >> >> The source code: >> >> for i in range(8): >> n = input() > > Yes you can get them on a single line, see the response from Tim Chase. But > just to be crystal clear, are you aware that you're getting string > representations of numbers, and not the numbers themselves? Just to clarify, this is assuming that you're using Python 3. Geezle, if you're using Python 2, you need to not use input() for anything - use raw_input() instead, which will do what we're describing here. I yearn for the day when nobody uses Python 2 any more so this doesn't need to be asked. ChrisA From breamoreboy at yahoo.co.uk Wed Dec 4 11:27:46 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 16:27:46 +0000 Subject: Input without line break, is it possible? In-Reply-To: References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> Message-ID: On 04/12/2013 16:14, Chris Angelico wrote: > On Thu, Dec 5, 2013 at 3:04 AM, Mark Lawrence wrote: >> On 04/12/2013 15:38, geezle86 at gmail.com wrote: >>> >>> The source code: >>> >>> for i in range(8): >>> n = input() >> >> Yes you can get them on a single line, see the response from Tim Chase. But >> just to be crystal clear, are you aware that you're getting string >> representations of numbers, and not the numbers themselves? > > Just to clarify, this is assuming that you're using Python 3. Geezle, > if you're using Python 2, you need to not use input() for anything - > use raw_input() instead, which will do what we're describing here. Good point, I saw input() and automatically assumed Python 3, what a sin! The assumption obviously, not Python 3!! > > I yearn for the day when nobody uses Python 2 any more so this doesn't > need to be asked. > I'm contemplating what it would be like migrating code from Python 1.x to Python 4.0, the fun and games that could be :) -- 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 Wed Dec 4 11:33:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Dec 2013 03:33:05 +1100 Subject: Input without line break, is it possible? In-Reply-To: References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> Message-ID: On Thu, Dec 5, 2013 at 3:27 AM, Mark Lawrence wrote: > I'm contemplating what it would be like migrating code from Python 1.x to > Python 4.0, the fun and games that could be :) I never used Python 1.x seriously, but when I went digging in one of my OS/2 machines a while ago, I found several Pythons, including a 1.something. Fortunately for my task at hand, there was also a 2.5 or 2.6 or somesuch, which served my purposes :) ChrisA From torriem at gmail.com Wed Dec 4 11:23:00 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 04 Dec 2013 09:23:00 -0700 Subject: Input without line break, is it possible? In-Reply-To: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> Message-ID: <529F56E4.9030308@gmail.com> On 12/04/2013 08:38 AM, geezle86 at gmail.com wrote: > my question, can i make it in just a single line like, > > 1 2 3 4 5 6 (and so forth) > > Can I? Yes of course. raw_input() is going to give you a string that you can then parse any way you want. From breamoreboy at yahoo.co.uk Wed Dec 4 11:36:53 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 04 Dec 2013 16:36:53 +0000 Subject: Input without line break, is it possible? In-Reply-To: <529F56E4.9030308@gmail.com> References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> <529F56E4.9030308@gmail.com> Message-ID: On 04/12/2013 16:23, Michael Torrie wrote: > On 12/04/2013 08:38 AM, geezle86 at gmail.com wrote: >> my question, can i make it in just a single line like, >> >> 1 2 3 4 5 6 (and so forth) >> >> Can I? > > Yes of course. raw_input() is going to give you a string that you can > then parse any way you want. > That's it lad, you're in detention for one hour. You will write repeatedly "I should be selling Python 3 instead of Python 2" :) -- 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 Dec 5 10:21:29 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 05 Dec 2013 08:21:29 -0700 Subject: Input without line break, is it possible? In-Reply-To: References: <6f831d02-26bf-4e68-a1c6-a9c9e87db1dc@googlegroups.com> <529F56E4.9030308@gmail.com> Message-ID: <52A099F9.9000101@gmail.com> On 12/04/2013 09:36 AM, Mark Lawrence wrote: > On 04/12/2013 16:23, Michael Torrie wrote: >> On 12/04/2013 08:38 AM, geezle86 at gmail.com wrote: >>> my question, can i make it in just a single line like, >>> >>> 1 2 3 4 5 6 (and so forth) >>> >>> Can I? >> >> Yes of course. raw_input() is going to give you a string that you can >> then parse any way you want. >> > > That's it lad, you're in detention for one hour. You will write > repeatedly "I should be selling Python 3 instead of Python 2" :) Yup. Though if he is using Python 2, then input() is a real no-no. From musicdenotation at gmail.com Wed Dec 4 22:17:00 2013 From: musicdenotation at gmail.com (musicdenotation at gmail.com) Date: Thu, 05 Dec 2013 10:17:00 +0700 Subject: The Python license Message-ID: <529ff051.83c9440a.132c.28f5@mx.google.com> The third clause of the PSF license requires you to include a brief summary of changes in Python-derived software. Why? How exactly to comply with it? I think that this condition is not suitable for using Python in closed-source software. I suggest to remove it. From roy at panix.com Wed Dec 4 22:37:09 2013 From: roy at panix.com (Roy Smith) Date: Wed, 04 Dec 2013 22:37:09 -0500 Subject: The Python license References: Message-ID: In article , musicdenotation at gmail.com wrote: Now that's the kind of software license I like. Short, and easy to understand. From tjreedy at udel.edu Wed Dec 4 23:09:55 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Dec 2013 23:09:55 -0500 Subject: The Python license In-Reply-To: <529ff051.83c9440a.132c.28f5@mx.google.com> References: <529ff051.83c9440a.132c.28f5@mx.google.com> Message-ID: On 12/4/2013 10:17 PM, musicdenotation at gmail.com wrote: > The third clause of the PSF license requires you to include a brief > summary of changes in Python-derived software. "In the event Licensee prepares a derivative work that is based on or incorporates Python 3.3.3 or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python 3.3.3." A program written in Python uses some Python interpreter to execute but is not a derivative work of any of them, as meant above. (Similarly, a Standard C program is not a derivative work of any of the numerous C compilers.) Examples where the above does or might apply: Stackless Python 2.7 is based on CPython 2.7, but it alters the core interpreter a bit to make some things work (or work better). In the process, I believe that some 2.7 code is broken. So it should explain how the 'Stackless 2.7' language is slightly different from 'Python 2.7' (beside any bugfixes not ported back yet). (For one thing, we don't want bug reports like "I ran this code on Stackless and it worked. When I ran it on CPython, it failed. Please fix CPython.") ActiveState Python x.y is CPython x.y, including the stdlib, plus some 3rd party modules, plus propriety code, including a package manager for Windows. They *should* explain that, both to promote their distribution, and to avoid misunderstanding about what is included with the PSF distribution of CPython. Some Python applications bundle the exact Python interpreter they work with. If they alter the bundled Python *and expose it to users*, as a scripting language, then they should explain the language changes. If they do not alter the bundled Python, there is nothing to explain (other than the version), even if it is exposed. For instance, Libre Office 4.0 included a *nix-style copy of Python 3.3.0 for scripting purposes. So the clause is needed, appropriate, and almost certainly not applicable to you. -- Terry Jan Reedy From michael.herrmann at heliumhq.com Thu Dec 5 05:14:50 2013 From: michael.herrmann at heliumhq.com (Michael Herrmann) Date: Thu, 5 Dec 2013 02:14:50 -0800 (PST) Subject: Packaging a proprietary Python library for multiple OSs Message-ID: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Hi everyone, I am developing a proprietary Python library. The library is currently Windows-only, and I want to also make it available for other platforms (Linux & Mac). I'm writing because I wanted to ask for your expert opinion on how to best do this. The library is currently shipped in the form of a Zip file. This archive contains the compiled Python code for the implementation of my library, plus all dependencies. By placing the Zip file on his PYTHONPATH, the customer can use the library from his Python scripts. Shipping a Zip file with all dependencies included has the following advantages: * No internet access or administrator privileges are required to install the library. * The customer does not have to worry about installing / managing dependencies of my library. It also has the disadvantage that the customer is not (easily) able to use his own versions of my library's dependencies. Even though I am not generating an EXE, I am using py2exe to obtain the distributable Zip file for my library. This "hack" is very convenient, as py2exe allows me to simply say which packages I require and does the work of performing a dependency analysis of the required libraries for me. py2exe automatically generates the Zip file with my (compiled) library code, and all dependencies. Unfortunately, py2exe is only available for Windows. I need to also be able to build it on Linux & Mac, hence change the build process to not use py2exe. My questions are: 1. Is it considered a bad idea in the Python community to ship one large Zip file with all dependencies? From what I have seen, it seems to be an unusual approach, at the least. How do *you* prefer to obtain and install Python libraries? 2. Is it possible to distribute the library in a form that allows for an offline installation without administrator privileges using other tools, such as setuptools? My insight into the state of the art in Python regarding these matters is limited, so I would appreciate advice from someone with more experience in the subject. A hard requirement is that I can only ship binary distributions of my library, as this is a proprietary product. I looked at Distutils and Setuptools, where the recommended approach seems to be to simply ship all sources. Many thanks! From rustompmody at gmail.com Thu Dec 5 05:56:16 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 5 Dec 2013 02:56:16 -0800 (PST) Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Message-ID: <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> On Thursday, December 5, 2013 3:44:50 PM UTC+5:30, Michael Herrmann wrote: > Hi everyone, > > I am developing a proprietary Python library. The library is currently Windows-only, and I want to also make it available for other platforms (Linux & Mac). I'm writing because I wanted to ask for your expert opinion on how to best do this. Wheel is the upcoming standard I think. http://www.python.org/dev/peps/pep-0427/ 1. It would be dishonest to remove the 'upcoming' 2. It would also be dishonest if you thought I know anything about the subject :-) 3. https://groups.google.com/forum/#!forum/python-virtualenv may be a better place to ask From travisgriggs at gmail.com Thu Dec 5 10:32:26 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Thu, 5 Dec 2013 07:32:26 -0800 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> Message-ID: <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> On Dec 5, 2013, at 2:56 AM, rusi wrote: > 3. https://groups.google.com/forum/#!forum/python-virtualenv may be a better > place to ask Am I the only one that sees the irony in this suggestion? Given the long running tirades^H^H^H^H^H^H thread about ?Managing Google Groups headaches?? ?Pleassse don?t use Google Groupssssesss. It?sss nasssty. It hurtssess our eyesssessss with itsss long linessssieesss. Unlessssss it hassss a ssspecial neeeeed. Then the groupssesss are OK, Yessss?" From rosuav at gmail.com Thu Dec 5 11:20:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Dec 2013 03:20:41 +1100 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> Message-ID: On Fri, Dec 6, 2013 at 2:32 AM, Travis Griggs wrote: > > On Dec 5, 2013, at 2:56 AM, rusi wrote: > >> 3. https://groups.google.com/forum/#!forum/python-virtualenv may be a better >> place to ask > > Am I the only one that sees the irony in this suggestion? Given the long running tirades^H^H^H^H^H^H thread about ?Managing Google Groups headaches?? > > ?Pleassse don?t use Google Groupssssesss. It?sss nasssty. It hurtssess our eyesssessss with itsss long linessssieesss. Unlessssss it hassss a ssspecial neeeeed. Then the groupssesss are OK, Yessss?" No, it's not like that. It's that there are some people who, despite truckloads of evidence to the contrary, still think that Google Groups is worth using. Rusi is one of them. Fortunately, he has defended his position by making his posts not look like the ridiculous junk that GG creates by default, but that doesn't make GG a good product. It's like an argument my boss and I had: I said that PHP is a bad language, and he said that it can't possibly be a bad language because he's able to write good code in it. I don't know what mailing list there is for virtualenv as I don't use it, but there's likely to be an alternative source of knowledge on it. ChrisA From breamoreboy at yahoo.co.uk Thu Dec 5 12:22:57 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Dec 2013 17:22:57 +0000 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> Message-ID: On 05/12/2013 16:20, Chris Angelico wrote: > On Fri, Dec 6, 2013 at 2:32 AM, Travis Griggs wrote: >> >> On Dec 5, 2013, at 2:56 AM, rusi wrote: >> >>> 3. https://groups.google.com/forum/#!forum/python-virtualenv may be a better >>> place to ask >> >> Am I the only one that sees the irony in this suggestion? Given the long running tirades^H^H^H^H^H^H thread about ?Managing Google Groups headaches?? >> >> ?Pleassse don?t use Google Groupssssesss. It?sss nasssty. It hurtssess our eyesssessss with itsss long linessssieesss. Unlessssss it hassss a ssspecial neeeeed. Then the groupssesss are OK, Yessss?" > > No, it's not like that. It's that there are some people who, despite > truckloads of evidence to the contrary, still think that Google Groups > is worth using. Rusi is one of them. Fortunately, he has defended his > position by making his posts not look like the ridiculous junk that GG > creates by default, but that doesn't make GG a good product. It's like > an argument my boss and I had: I said that PHP is a bad language, and > he said that it can't possibly be a bad language because he's able to > write good code in it. > > I don't know what mailing list there is for virtualenv as I don't use > it, but there's likely to be an alternative source of knowledge on it. > > ChrisA > gmane.comp.python.virtualenv -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Thu Dec 5 12:12:30 2013 From: roy at panix.com (Roy Smith) Date: Thu, 5 Dec 2013 09:12:30 -0800 (PST) Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> Message-ID: <9b899369-c6c9-44d1-980f-05c32c704e07@googlegroups.com> On Thursday, December 5, 2013 11:20:41 AM UTC-5, Chris Angelico wrote: > No, it's not like that. It's that there are some people who, despite > truckloads of evidence to the contrary, still think that Google Groups > > is worth using. Rusi is one of them. Fortunately, he has defended his > > position by making his posts not look like the ridiculous junk that GG > > creates by default, but that doesn't make GG a good product. I use GG on occasion (I'm using it now), when I don't have access to a better newsreader. Like Rusi, I take the effort to clean up the double-space mess GG produces by default. That doesn't mean GG isn't a piece of crap; it is. That fact that I, and Rusi, know enough, and take the effort, to overcome its shortcomings doesn't change that. I put GG it in the category of "attractive nuisance". It's like leaving cans of spray paint laying around school playgrounds and then being surprised when the kids pick them up and use them to paint graffiti. It certainly violates Google's "do no harm" motto when it interacts with usenet groups. I keep hearing that I should use gmane as a superior interface. Well, I tried that. I went to http://dir.gmane.org/search.php, where it asks me to search for a newsgroup. I type in "comp.lang.python", and it tells me, "No matching groups". So, that seems pretty broken to me. > It's like an argument my boss and I had: I said that PHP is a bad language, and > he said that it can't possibly be a bad language because he's able to > write good code in it. PHP is a disaster of a language. But, like any bad tool, a good craftsman can produce a quality product with it. Wikipedia is written in PHP. So, apparently, is gmane :-) As much as I loathe working with PHP, I have to admit that if you can build a product like Wikipedia on it, it must have some redeeming qualities. From rosuav at gmail.com Thu Dec 5 12:46:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Dec 2013 04:46:48 +1100 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <9b899369-c6c9-44d1-980f-05c32c704e07@googlegroups.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> <9b899369-c6c9-44d1-980f-05c32c704e07@googlegroups.com> Message-ID: On Fri, Dec 6, 2013 at 4:12 AM, Roy Smith wrote: >> It's like an argument my boss and I had: I said that PHP is a bad language, and >> he said that it can't possibly be a bad language because he's able to >> write good code in it. > > PHP is a disaster of a language. But, like any bad tool, a good craftsman can produce a quality product with it. Wikipedia is written in PHP. So, apparently, is gmane :-) As much as I loathe working with PHP, I have to admit that if you can build a product like Wikipedia on it, it must have some redeeming qualities. Right. And the fact that Wikipedia can be written in PHP is not itself proof that it's a good language. You and Rusi are fighting against GG's faults and not entirely succeeding, as your paragraphs come out unwrapped; that's possibly the least of the GG woes, but it's one of the first clues that someone's replies are likely to be double-spaced. A good tool does most of your work for you. A bad tool has to be fought every inch of the way. Sometimes a tool is good but wrongly chosen (don't use DeScribe Macro Language for writing a GUI - drop to REXX for that!), but some tools have no good use at all. ChrisA From z at etiol.net Thu Dec 5 12:50:45 2013 From: z at etiol.net (Zero Piraeus) Date: Thu, 5 Dec 2013 14:50:45 -0300 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <9b899369-c6c9-44d1-980f-05c32c704e07@googlegroups.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> <9b899369-c6c9-44d1-980f-05c32c704e07@googlegroups.com> Message-ID: <20131205175045.GA7679@piedra> : On Thu, Dec 05, 2013 at 09:12:30AM -0800, Roy Smith wrote: > I keep hearing that I should use gmane as a superior interface. Well, > I tried that. I went to http://dir.gmane.org/search.php, where it > asks me to search for a newsgroup. I type in "comp.lang.python", and > it tells me, "No matching groups". So, that seems pretty broken to > me. That's not entirely fair - Gmane presents mailing lists as newsgroups, not vice versa, so it doesn't know that python-list at python.org is connected to comp.lang.python (or that comp.lang.python even exists). A search for the mailing list from the front page works just fine: http://gmane.org/find.php?list=python-list%40python.org -[]z. -- Zero Piraeus: flagellum dei http://etiol.net/pubkey.asc From breamoreboy at yahoo.co.uk Thu Dec 5 13:18:30 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 05 Dec 2013 18:18:30 +0000 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <20131205175045.GA7679@piedra> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> <9b899369-c6c9-44d1-980f-05c32c704e07@googlegroups.com> <20131205175045.GA7679@piedra> Message-ID: On 05/12/2013 17:50, Zero Piraeus wrote: > : > > On Thu, Dec 05, 2013 at 09:12:30AM -0800, Roy Smith wrote: >> I keep hearing that I should use gmane as a superior interface. Well, >> I tried that. I went to http://dir.gmane.org/search.php, where it >> asks me to search for a newsgroup. I type in "comp.lang.python", and >> it tells me, "No matching groups". So, that seems pretty broken to >> me. > > That's not entirely fair - Gmane presents mailing lists as newsgroups, > not vice versa, so it doesn't know that python-list at python.org is > connected to comp.lang.python (or that comp.lang.python even exists). > > A search for the mailing list from the front page works just fine: > > http://gmane.org/find.php?list=python-list%40python.org > > -[]z. > Another useful link, there are just a few python goodies there http://news.gmane.org/index.php?prefix=gmane.comp.python -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From robert.kern at gmail.com Thu Dec 5 13:28:25 2013 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 05 Dec 2013 18:28:25 +0000 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <20131205175045.GA7679@piedra> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> <9b899369-c6c9-44d1-980f-05c32c704e07@googlegroups.com> <20131205175045.GA7679@piedra> Message-ID: On 2013-12-05 17:50, Zero Piraeus wrote: > : > > On Thu, Dec 05, 2013 at 09:12:30AM -0800, Roy Smith wrote: >> I keep hearing that I should use gmane as a superior interface. Well, >> I tried that. I went to http://dir.gmane.org/search.php, where it >> asks me to search for a newsgroup. I type in "comp.lang.python", and >> it tells me, "No matching groups". So, that seems pretty broken to >> me. > > That's not entirely fair - Gmane presents mailing lists as newsgroups, > not vice versa, so it doesn't know that python-list at python.org is > connected to comp.lang.python (or that comp.lang.python even exists). > > A search for the mailing list from the front page works just fine: > > http://gmane.org/find.php?list=python-list%40python.org Right. GMane is an NNTP service, but it is not part of the USENET network. comp.lang.python is a USENET newsgroup and requires a true USENET server (not just an NNTP server) to access. -- 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 ben+python at benfinney.id.au Thu Dec 5 16:56:27 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 06 Dec 2013 08:56:27 +1100 Subject: Official discussion forum for a project (was: Packaging a proprietary Python library for multiple OSs) References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> <219CFE92-92F1-47EB-850C-BDF5024E1F3E@gmail.com> Message-ID: <7weh5rner8.fsf_-_@benfinney.id.au> Travis Griggs writes: > On Dec 5, 2013, at 2:56 AM, rusi wrote: > > > 3. https://groups.google.com/forum/#!forum/python-virtualenv may be > > a better place to ask > > Am I the only one that sees the irony in this suggestion? Given the > long running tirades^H^H^H^H^H^H thread about ?Managing Google Groups > headaches?? In addition to the fact that ?rusi? evidently does not hold that position, the Virtualenv project has its official discussion forum hosted at Google Groups, and the above quote merely points that out. One can recommend strongly against Google Groups in general as a dreadful service, while still directing people to the official discussion forum for a particular project which has made the (to whatever degree misguided) decision to use that service. -- \ ?Simplicity and elegance are unpopular because they require | `\ hard work and discipline to achieve and education to be | _o__) appreciated.? ?Edsger W. Dijkstra | Ben Finney From michael.herrmann at heliumhq.com Thu Dec 5 10:41:21 2013 From: michael.herrmann at heliumhq.com (Michael Herrmann) Date: Thu, 5 Dec 2013 07:41:21 -0800 (PST) Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <921295d6-a73f-4379-a938-c5188e35b6bd@googlegroups.com> Message-ID: <2c4fe992-5909-4c6c-a85f-4a46bc8b7a14@googlegroups.com> On Thursday, December 5, 2013 11:56:16 AM UTC+1, rusi wrote: > Wheel is the upcoming standard I think. > http://www.python.org/dev/peps/pep-0427/ I hadn't known of Wheel - thanks for pointing it out! From roy at panix.com Thu Dec 5 09:09:32 2013 From: roy at panix.com (Roy Smith) Date: Thu, 05 Dec 2013 09:09:32 -0500 Subject: Packaging a proprietary Python library for multiple OSs References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Message-ID: In article <58d49c5b-c837-4dac-b764-369fea02568c at googlegroups.com>, Michael Herrmann wrote: > 1. Is it considered a bad idea in the Python community to ship one large Zip > file with all dependencies? Yes. > How do *you* prefer to obtain and install Python libraries? "pip install" > 2. Is it possible to distribute the library in a form that allows for an > offline installation without administrator privileges using other tools, > such as setuptools? You can use "pip --find-links" to point pip at a local repository of packages. That solves the offline part. And the "without admin privs" part is solved by setting up a virtualenv. > A hard requirement is that I can only ship binary distributions of my > library, as this is a proprietary product. I looked at Distutils and > Setuptools, where the recommended approach seems to be to simply ship all > sources. Keep in mind that shipping just the pyc files offers very weak protection against people examining your code. Google for "python decompile" and you'll find a number of projects. I'm looking at the docs for uncompyle now, which says: > 'uncompyle' converts Python byte-code back into equivalent Python > source. It accepts byte-code from Python version 2.7 only. > > The generated source is very readable: docstrings, lists, tuples and > hashes get pretty-printed. About the only thing not shipping Python source does is satisfy a check-box requirement that you not ship source. It may make the lawyers and bean-counters happy, but that's about it. From michael.herrmann at heliumhq.com Thu Dec 5 10:49:35 2013 From: michael.herrmann at heliumhq.com (Michael Herrmann) Date: Thu, 5 Dec 2013 07:49:35 -0800 (PST) Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Message-ID: <6c283680-20b7-49c5-9b1e-50680e2118a0@googlegroups.com> On Thursday, December 5, 2013 3:09:32 PM UTC+1, Roy Smith wrote: > > 1. Is it considered a bad idea in the Python community to ship one large Zip file with all dependencies? > Yes. I see. Unfortunately, the library's users may be non-technical and might not even have experience with Python. The easier the installation process, therefore, the better. > > How do *you* prefer to obtain and install Python libraries? > "pip install" Thanks for this input. > > 2. Is it possible to distribute the library in a form that allows for an > > offline installation without administrator privileges using other tools, > > such as setuptools? > > You can use "pip --find-links" to point pip at a local repository of > packages. That solves the offline part. And the "without admin privs" > part is solved by setting up a virtualenv. Both "pip --find-links" and "virtualenv" sound technically feasible but may be too difficult for my users (especially virtualenv). > > A hard requirement is that I can only ship binary distributions of my > > library, as this is a proprietary product. I looked at Distutils and > > Setuptools, where the recommended approach seems to be to simply ship all > > sources. > Keep in mind that shipping just the pyc files offers very weak > protection against people examining your code. Google for "python > decompile" and you'll find a number of projects. I'm looking at the > docs for uncompyle now, which says: > > 'uncompyle' converts Python byte-code back into equivalent Python > > source. It accepts byte-code from Python version 2.7 only. Very interesting point. Thank you very much for pointing out uncompyle. I had always known that it was easy to decompile .pyc files, but hadn't imagined it to be that easy. I just tried uncompyle with some of our proprietary .pyc files. It took 5 minutes to set up and the results are near-perfect. Scary... :-S We might have to look into tools such as http://www.bitboost.com/#Python_obfuscator to obfuscate our code. Thanks for the valuable insights! Michael From random832 at fastmail.us Thu Dec 5 10:52:45 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 05 Dec 2013 10:52:45 -0500 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <6c283680-20b7-49c5-9b1e-50680e2118a0@googlegroups.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <6c283680-20b7-49c5-9b1e-50680e2118a0@googlegroups.com> Message-ID: <1386258765.7927.55933597.6D0E1B0E@webmail.messagingengine.com> On Thu, Dec 5, 2013, at 10:49, Michael Herrmann wrote: > Very interesting point. Thank you very much for pointing out uncompyle. I > had always known that it was easy to decompile .pyc files, but hadn't > imagined it to be that easy. I just tried uncompyle with some of our > proprietary .pyc files. It took 5 minutes to set up and the results are > near-perfect. Scary... :-S We might have to look into tools such as > http://www.bitboost.com/#Python_obfuscator to obfuscate our code. Or you could just sue anyone who steals your code. From mherrmann.at at gmail.com Thu Dec 5 11:24:06 2013 From: mherrmann.at at gmail.com (mherrmann.at at gmail.com) Date: Thu, 5 Dec 2013 08:24:06 -0800 (PST) Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> <6c283680-20b7-49c5-9b1e-50680e2118a0@googlegroups.com> Message-ID: <70d4d533-7b4c-4fcd-b3fc-4c4206a75098@googlegroups.com> On Thursday, 5 December 2013 16:52:45 UTC+1, rand... at fastmail.us wrote: > Or you could just sue anyone who steals your code. I see your point but I don't think it's very practical. If the person who stole the code sits in some remote country with a completely different legal system, I think I'll have a hard time getting at this person. If I even manage to find out where the person is at all. From kw at codebykevin.com Thu Dec 5 10:26:40 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 05 Dec 2013 10:26:40 -0500 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Message-ID: On 12/5/13, 5:14 AM, Michael Herrmann wrote: > Even though I am not generating an EXE, I am using py2exe to obtain the distributable Zip file for my library. This "hack" is very convenient, as py2exe allows me to simply say which packages I require and does the work of performing a dependency analysis of the required libraries for me. py2exe automatically generates the Zip file with my (compiled) library code, and all dependencies. If your library and their dependencies are simply .pyc files, then I don't see why a zip collated via py2exe wouldn't work on other platforms. Obviously this point is moot if your library includes true compiled (C-based) extensions. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From michael.herrmann at heliumhq.com Thu Dec 5 10:50:38 2013 From: michael.herrmann at heliumhq.com (Michael Herrmann) Date: Thu, 5 Dec 2013 07:50:38 -0800 (PST) Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Message-ID: On Thursday, December 5, 2013 4:26:40 PM UTC+1, Kevin Walzer wrote: > On 12/5/13, 5:14 AM, Michael Herrmann wrote: > If your library and their dependencies are simply .pyc files, then I > don't see why a zip collated via py2exe wouldn't work on other > platforms. Obviously this point is moot if your library includes true > compiled (C-based) extensions. As I said, I need to make my *build* platform-independent. Thanks, Michael From kw at codebykevin.com Thu Dec 5 11:03:06 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 05 Dec 2013 11:03:06 -0500 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Message-ID: On 12/5/13, 10:50 AM, Michael Herrmann wrote: > As I said, I need to make my *build* platform-independent. cx_Freeze is platform independent, but I'm not sure if it generates libraries or simply executables. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From kw at codebykevin.com Fri Dec 6 10:35:26 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 06 Dec 2013 10:35:26 -0500 Subject: Packaging a proprietary Python library for multiple OSs In-Reply-To: References: <58d49c5b-c837-4dac-b764-369fea02568c@googlegroups.com> Message-ID: On 12/5/13, 10:50 AM, Michael Herrmann wrote: > On Thursday, December 5, 2013 4:26:40 PM UTC+1, Kevin Walzer wrote: >> On 12/5/13, 5:14 AM, Michael Herrmann wrote: >> If your library and their dependencies are simply .pyc files, then I >> don't see why a zip collated via py2exe wouldn't work on other >> platforms. Obviously this point is moot if your library includes true >> compiled (C-based) extensions. > > As I said, I need to make my *build* platform-independent. Giving this further thought, I'm wondering how hard it would be to roll your own using modulefinder, Python's zip tools, and some custom code. Just sayin'. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From ramkrishan.bhatt at gmail.com Thu Dec 5 08:39:29 2013 From: ramkrishan.bhatt at gmail.com (ramkrishan.bhatt at gmail.com) Date: Thu, 5 Dec 2013 05:39:29 -0800 (PST) Subject: Finding keywords In-Reply-To: References: Message-ID: Hi , If you got the solutions please let me know also. I have to implement asap. On Wednesday, 9 March 2011 23:43:26 UTC+5:30, Cross wrote: > On 03/09/2011 01:21 AM, Vlastimil Brom wrote: > > 2011/3/8 Cross: > >> On 03/08/2011 06:09 PM, Heather Brown wrote: > >>> > >>> The keywords are an attribute in a tag called, in the section > >>> called > >>> . Are you having trouble parsing the xhtml to that point? > >>> > >>> Be more specific in your question, and somebody is likely to chime in. > >>> Although > >>> I'm not the one, if it's a question of parsing the xhtml. > >>> > >>> DaveA > >> > >> I know meta tags contain keywords but they are not always reliable. I can > >> parse xhtml to obtain keywords from meta tags; but how do I verify them. To > >> obtain reliable keywords, I have to parse the plain text obtained from the > >> URL. > >> > >> Cross > >> > >> --- news://freenews.netfront.net/ - complaints: news at netfront.net --- > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > >> > > > > Hi, > > if you need to extract meaningful keywords in terms of data mining > > using natural language processing, it might become quite a complex > > task, depending on the requirements; the NLTK toolkit may help with > > some approaches [ http://www.nltk.org/ ]. > > One possibility would be to filter out more frequent and less > > meaningful words ("stopwords") and extract the more frequent words > > from the reminder., e.g. (with some simplifications/hacks in the > > interactive mode): > > > >>>> import re, urllib2, nltk > >>>> page_src = urllib2.urlopen("http://www.python.org/doc/essays/foreword/").read().decode("utf-8") > >>>> page_plain = nltk.clean_html(page_src).lower() > >>>> txt_filtered = nltk.Text((word for word in re.findall(r"(?u)\w+", page_plain) if word not in set(nltk.corpus.stopwords.words("english")))) > >>>> frequency_dist = nltk.FreqDist(txt_filtered) > >>>> [(word, freq) for (word, freq) in frequency_dist.items() if freq> 2] > > [(u'python', 39), (u'abc', 11), (u'code', 10), (u'c', 7), > > (u'language', 7), (u'programming', 7), (u'unix', 7), (u'foreword', 5), > > (u'new', 5), (u'would', 5), (u'1st', 4), (u'book', 4), (u'ed', 4), > > (u'features', 4), (u'many', 4), (u'one', 4), (u'programmer', 4), > > (u'time', 4), (u'use', 4), (u'community', 3), (u'documentation', 3), > > (u'early', 3), (u'enough', 3), (u'even', 3), (u'first', 3), (u'help', > > 3), (u'indentation', 3), (u'instance', 3), (u'less', 3), (u'like', 3), > > (u'makes', 3), (u'personal', 3), (u'programmers', 3), (u'readability', > > 3), (u'readable', 3), (u'write', 3)] > >>>> > > > > Another possibility would be to extract parts of speech (e.g. nouns, > > adjective, verbs) using e.g. nltk.pos_tag(input_txt) etc.; > > for more convoluted html code e.g. BeautifulSoup might be used and > > there are likely many other options. > > > > hth, > > vbr > I had considered nltk. That is why I said that straightforward frequency > calculation of words would be naive. I have to look into this BeautifulSoup thing. > > --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From bv4bv4bv4 at gmail.com Thu Dec 5 10:35:10 2013 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Thu, 5 Dec 2013 07:35:10 -0800 (PST) Subject: Why Muslims Believe that Islam is the truth ????????????? Message-ID: <50a2d633-78a2-4a1f-ac2d-4f52d0332a14@googlegroups.com> Why Muslims Believe that Islam is the truth Many Christians & Jews don't know that Muslims believe in their prophets and holy books. Muslims believe that the Bible and the Torah were changed by people for their personal benefits. This is why God sent Prophet Muhammad, peace be upon him, not with a new religion, but to correct the people who had gone astray, those who were worshipping idols and being misguided by their forefathers. Islam is the last message to the world and God wants the miracle of Islam to be witnessed by the people from Prophet Muhammad's, peace be upon him, time till the day of Judgment. The miracle is the Qu'ran, Muslims holy book. Many Christians & Jews don't know that Muslims believe in their prophets and holy books. Muslims believe that the Bible and the Torah were changed by people for their personal benefits. This is why God sent Prophet Muhammad, peace be upon him, not with a new religion, but to correct the people who had gone astray, those who were worshipping idols and being misguided by their forefathers. Islam is the last message to the world and God wants the miracle of Islam to be witnessed by the people from Prophet Muhammad's, peace be upon him, time till the day of Judgment. The miracle is the Qu'ran, Muslims holy book. Why is the Qur'an a miracle ? 1- The Qu'ran is an untouchable book : After 1400 years, from the begining of Prophet Muhammad's, peace be upon him, message, the Qu'ran has not changed in any way, even as a matter of one charachter. Prooving this is very easy, since you can compare all the versions of the Qu'ran everywhere in the world and you will find them all the same. God ensured that this book would be saved from any changes attempted by human beings. God said in the Qur'an : " We have, without doubt, sent down the Message; and We will assuredly guard it (from corruption)" 2- The Qu'ran contains many scientific facts that have been discovered recently using computer systems and microscopes. Many scientists have attended conferences dealing with this subject and have themselves accepted Islam. These same scientists have said that it is not possible that Muhammad, peace be upon him, an illiterate man, who lived 1400 years ago, could have discovered such things on his own. God said in the Qur'an : "Soon will We show them Our Signs in the (furthest) regions (of the earth), and in their own souls, until it becomes manifest to them that this is the Truth. Is it not enough that thy Lord doth witness all things" ( Quran 41:53 ) 3- The Qu'ran, which is in Arabic, was revealed to the people of the Arabian Gulf who invented the Arabic language. Through Muhammad, peace be upon him, Allah challenged the people who claimed that a human wrote it to emulate such a book. No one from the time of the Prophet till now could write a book that contained the many scientific facts, miracles and similar effects on people that the Qu'ran did and still does today. 4- The Qu'ran had not one Arabic grammar mistake, which was recognized by the disbelievers at the time of the Prophet, who were the founders of the Arabic language. These are a few examples of why Muslims believe in the Qur'an. Here are some verses from God to Muslims encouraging them to invite the People of the Book ( Jews and Christians to Islam ): God said : {Say: "O People of the Book! Why reject ye the Signs of Allah, when Allah is Himself witness to all ye do?} (Quran 3:98) God tell Muslims to say : {..'We believe in that which had been revealed to us and revealed to you, and our God and your God is One, and unto Him we surrender} (Quran 29:46) If you have any questions or would like to know more about the Qu'ran and Islam please contact me at : webmaster at islamway.com andenglish at islamway.com ================================= http://en.islamway.net/article/8124 thank you From tastyminerals at gmail.com Thu Dec 5 15:26:11 2013 From: tastyminerals at gmail.com (tastyminerals) Date: Thu, 05 Dec 2013 23:26:11 +0300 Subject: PIL(Pillow) fails with PNG image Message-ID: <52A0E163.5030702@gmail.com> Hi, I am getting an error when trying to use Pillow library to display image PNG on a Tkinter Button widget. Here is my code. |image= Image.open(os.path.join('icons','bulb.png')) # using PIL for png images self.correctGuessImage= ImageTk.PhotoImage(image) |>>> |File "/home/user/Documents/temp.py", line222, in drawButtons self.correctGuessImage= ImageTk.PhotoImage(image) File "/usr/lib/python2.7/dist-packages/PIL/ImageTk.py", line121, in __init__ self.paste(image) File "/usr/lib/python2.7/dist-packages/PIL/ImageTk.py", line171, in paste im.load() File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line192, in load d= Image._getdecoder(self.mode, d, a, self.decoderconfig) AttributeError: 'module' object has no attribute'_getdecoder'||| While working fine under windows 7x64 it fails to work on Linux Mint x64. I am getting this error running the same file. I installed everything I could find with 'python','png' and 'tk' from the reps but no effect. Any ideas why is this happening and how to fix this? Pavel -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Dec 5 20:14:25 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Dec 2013 20:14:25 -0500 Subject: PIL(Pillow) fails with PNG image In-Reply-To: <52A0E163.5030702@gmail.com> References: <52A0E163.5030702@gmail.com> Message-ID: I cannot answer your question, but wanted to mention that you should send text only and not include an html copy of messages. On 12/5/2013 3:26 PM, tastyminerals wrote: > Hi, I am getting an error when trying to use Pillow library to display > image PNG on a Tkinter Button widget. Here is my code. > > |image= Image.open(os.path.join('icons','bulb.png')) # using PIL for png images > self.correctGuessImage= ImageTk.PhotoImage(image) > > |>>> > |File "/home/user/Documents/temp.py", line222, in drawButtons > self.correctGuessImage= ImageTk.PhotoImage(image) > File "/usr/lib/python2.7/dist-packages/PIL/ImageTk.py", line121, in __init__ > self.paste(image) > File "/usr/lib/python2.7/dist-packages/PIL/ImageTk.py", line171, in paste > im.load() > File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line192, in load > d= Image._getdecoder(self.mode, d, a, self.decoderconfig) > AttributeError: 'module' object has no attribute'_getdecoder'||| > > While working fine under windows 7x64 it fails to work on Linux Mint > x64. I am getting this error running the same file. I installed > everything I could find with 'python','png' and 'tk' from the reps but > no effect. Any ideas why is this happening and how to fix this? > > Pavel > > -- Terry Jan Reedy From gordon at panix.com Thu Dec 5 21:07:05 2013 From: gordon at panix.com (John Gordon) Date: Fri, 6 Dec 2013 02:07:05 +0000 (UTC) Subject: PIL(Pillow) fails with PNG image References: Message-ID: In tastyminerals writes: > d= Image._getdecoder(self.mode, d, a, self.decoderconfig) > AttributeError: 'module' object has no attribute'_getdecoder'||| Do you have your own module named Image.py? -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From auriocus at gmx.de Fri Dec 6 01:54:09 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 06 Dec 2013 07:54:09 +0100 Subject: PIL(Pillow) fails with PNG image In-Reply-To: References: Message-ID: Am 05.12.13 21:26, schrieb tastyminerals: > Hi, I am getting an error when trying to use Pillow library to display > image PNG on a Tkinter Button widget. Here is my code. > > |image= Image.open(os.path.join('icons','bulb.png')) # using PIL for png images > self.correctGuessImage= ImageTk.PhotoImage(image) I don't know what is the problem here, but Tk supports PNG natively from 8.5 onwards; just use self.correctGuessImage= ImageTk.PhotoImage(file='bulb.png') Christian From garthy_nhtyp at entropicsoftware.com Thu Dec 5 21:34:27 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 13:04:27 +1030 Subject: Embedding multiple interpreters Message-ID: <52A137B3.7010408@entropicsoftware.com> Hi! I hope I've got the right list here- there were a few to choose from. :} I am trying to embed Python with multiple interpreters into an existing application. I have things working fine with a single interpreter thus far. I am running into problems when using multiple interpreters [1] and I am presently trying to track down these issues. Can anyone familiar with the process of embedding multiple interpreters have a skim of the details below and let me know of any obvious problems? If I can get the essentials right, then presumably it's just a matter of my tracking down any problems with my code. I am presently using Python 3.3.3. What I am after: - Each sub-interpreter will have its own dedicated thread. Each thread will have no more than one sub-interpreter. Basically, there is a one-to-one mapping between threads and interpreters (some threads are unrelated to Python though). - The default interpreter in the main thread will never be used, although I can explicitly use it if it'll help in some way. - Each thread is created and managed outside of Python. This can't be readily changed. - I have a single internal module I need to be able to use for each interpreter. - I load scripts into __main__ and create objects from it to bootstrap. - I understand that for the most part only a single interpreter will be running at a time due to the GIL. This is unfortunate but not a major problem. - I don't need to share objects between interpreters (if it is even possible- I don't know). - My fallback if I can't do this is to implement each instance in a dedicated *process* rather than per-thread. However, there is a significant cost to doing this that I would rather not incur. Could I confirm: - There is one GIL in a given process, shared amongst all (sub) interpreters. There seems some disagreement on this one online, although I'm fairly confident that there is only the one GIL. - I am using the mod_wsgi source for inspiration. Is there a better source for an example of embedding multiple interpreters? A query re the doco: http://docs.python.org/3/c-api/init.html#gilstate "Python supports the creation of additional interpreters (using Py_NewInterpreter()), but mixing multiple interpreters and the PyGILState_*() API is unsupported." Is this actually correct? mod_wsgi seems to do it. Have I misunderstood? I've extracted what I have so far from my code into a form that can be followed more easily. Hopefully I have not made any mistakes in doing so. The essence of what my code calls should be as follows: === Global init, run once: static PyThreadState *mtstate = NULL; PyImport_AppendInittab("myinternalmodule", PyInit_myinternalmodule); Py_SetProgramName((wchar_t *)"foo"); Pu_InitializeEx(0); PyEval_InitThreads(); mtstate = PyThreadState_Get(); PyEval_ReleaseThread(mtstate); === Global shutdown, run once at end: Py_Finalize(); === Per-interpreter init in main thread before launching child thread: (none thus far) === Init in dedicated thread for each interpreter: // NB: Also protected by a single global non-Python mutex to be sure. PyGILState_STATE gil = PyGILState_Ensure(); PyThreadState *save_tstate = PyThreadState_Swap(NULL); state = Py_NewInterpreter(); PyThreadState_Swap(save_tstate); PyObject *mmodule = PyImport_AddModule("__main__"); Py_INCREF(mmodule); PyImport_ImportModule("myinternalmodule"); PyGILState_Release(gil); === Shutdown in dedicated thread for each interpreter: // NB: Also protected by the same single global non-Python mutex as in the init. PyGILState_STATE gil = PyGILState_Ensure(); PyThreadState *save_tstate = PyThreadState_Swap(state); Py_EndInterpreter(state); PyThreadState_Swap(save_tstate); PyGILState_Release(gil); === Placed at top of scope where calls made to Python C API: SafeLock lock; === SafeLock implementation: class SafeLock { public: SafeLock() {gil = PyGILState_Ensure();} ~SafeLock() {PyGILState_Release(gil);} private: PyGILState_STATE gil; }; === Does this look roughly right? Have I got the global and per-interpreter init and shutdown right? Am I locking correctly in SafeLock- is PyGILState_Ensure() and PyGILState_Release() sufficient? Is there an authoritative summary of the global and per-interpreter init and shutdown somewhere that I have missed? Any resource I should be reading? Cheers, Garth [1] It presently crashes in Py_EndInterpreter() after running through a series of tests during the shutdown of the 32nd interpreter I create. I don't know if this is significant, but the tests pass for the first 31 interpreters. From torriem at gmail.com Fri Dec 6 00:16:21 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 05 Dec 2013 22:16:21 -0700 Subject: Embedding multiple interpreters In-Reply-To: <52A137B3.7010408@entropicsoftware.com> References: <52A137B3.7010408@entropicsoftware.com> Message-ID: <52A15DA5.3040705@gmail.com> On 12/05/2013 07:34 PM, Garthy wrote: > - My fallback if I can't do this is to implement each instance in a > dedicated *process* rather than per-thread. However, there is a > significant cost to doing this that I would rather not incur. What cost is this? Are you speaking of cost in terms of what you the programmer would have to do, cost in terms of setting things up and communicating with the process, or the cost of creating a process vs a thread? If it's the last, on most modern OS's (particularly Linux), it's really not that expensive. On Linux the cost of threads and processes are nearly the same. From rosuav at gmail.com Fri Dec 6 00:21:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Dec 2013 16:21:23 +1100 Subject: Embedding multiple interpreters In-Reply-To: <52A15DA5.3040705@gmail.com> References: <52A137B3.7010408@entropicsoftware.com> <52A15DA5.3040705@gmail.com> Message-ID: On Fri, Dec 6, 2013 at 4:16 PM, Michael Torrie wrote: > On 12/05/2013 07:34 PM, Garthy wrote: >> - My fallback if I can't do this is to implement each instance in a >> dedicated *process* rather than per-thread. However, there is a >> significant cost to doing this that I would rather not incur. > > What cost is this? Are you speaking of cost in terms of what you the > programmer would have to do, cost in terms of setting things up and > communicating with the process, or the cost of creating a process vs a > thread? If it's the last, on most modern OS's (particularly Linux), > it's really not that expensive. On Linux the cost of threads and > processes are nearly the same. If you want my guess, the cost of going to multiple processes would be to do with passing data back and forth between them. Why is Python being embedded in another application? Sounds like there's data moving from C to Python to C, ergo breaking that into separate processes means lots of IPC. ChrisA From garthy_nhtyp at entropicsoftware.com Fri Dec 6 01:30:59 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 17:00:59 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: <52A137B3.7010408@entropicsoftware.com> <52A15DA5.3040705@gmail.com> Message-ID: <52A16F23.2050107@entropicsoftware.com> Hi Chris (and Michael), On 06/12/13 15:51, Chris Angelico wrote: > On Fri, Dec 6, 2013 at 4:16 PM, Michael Torrie wrote: >> On 12/05/2013 07:34 PM, Garthy wrote: >>> - My fallback if I can't do this is to implement each instance in a >>> dedicated *process* rather than per-thread. However, there is a >>> significant cost to doing this that I would rather not incur. >> >> What cost is this? Are you speaking of cost in terms of what you the >> programmer would have to do, cost in terms of setting things up and >> communicating with the process, or the cost of creating a process vs a >> thread? If it's the last, on most modern OS's (particularly Linux), >> it's really not that expensive. On Linux the cost of threads and >> processes are nearly the same. > > If you want my guess, the cost of going to multiple processes would be > to do with passing data back and forth between them. Why is Python > being embedded in another application? Sounds like there's data moving > from C to Python to C, ergo breaking that into separate processes > means lots of IPC. An excellent guess. :) One characteristic of the application I am looking to embed Python in is that there are a fairly large number calls from the app into Python, and for each, generally many back to the app. There is a healthy amount of data flowing back and forth each time. An implementation with an inter-process roundtrip each time (with a different scripting language) proved to be too limiting, and needlessly complicated the design of the app. As such, more development effort has gone into making things work better with components that work well running across thread boundaries than process boundaries. I am confident at this point I could pull things off with a Python one-interpreter-per-process design, but I'd then need to visit the IPC side of things again and put up with the limitations that arise. Additionally, the IPC code has has less attention and isn't as capable. I know roughly how I'd proceed if I went with this approach, but it is the least desirable outcome of the two. However, if I could manage to get a thread-based solution going, I can put the effort where it is most productive, namely into making sure that the thread-based solution works best. This is my preferred outcome and current goal. :) Cheers, Garth From garthy_nhtyp at entropicsoftware.com Fri Dec 6 03:16:57 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 18:46:57 +1030 Subject: Embedding multiple interpreters In-Reply-To: <52A15DA5.3040705@gmail.com> References: <52A137B3.7010408@entropicsoftware.com> <52A15DA5.3040705@gmail.com> Message-ID: <52A187F9.907@entropicsoftware.com> Hi Chris (and Michael), On 06/12/13 15:46, Michael Torrie wrote: > On 12/05/2013 07:34 PM, Garthy wrote: >> - My fallback if I can't do this is to implement each instance in a >> dedicated *process* rather than per-thread. However, there is a >> significant cost to doing this that I would rather not incur. > > What cost is this? Are you speaking of cost in terms of what you the > programmer would have to do, cost in terms of setting things up and > communicating with the process, or the cost of creating a process vs a > thread? If it's the last, on most modern OS's (particularly Linux), > it's really not that expensive. On Linux the cost of threads and > processes are nearly the same. An excellent guess. :) One characteristic of the application I am looking to embed Python in is that there are a fairly large number calls from the app into Python, and for each, generally many back to the app. There is a healthy amount of data flowing back and forth each time. An implementation with an inter-process roundtrip each time (with a different scripting language) proved to be too limiting, and needlessly complicated the design of the app. As such, more development effort has gone into making things work better with components that work well running across thread boundaries than process boundaries. I am confident at this point I could pull things off with a Python one-interpreter-per-process design, but I'd then need to visit the IPC side of things again and put up with the limitations that arise. Additionally, the IPC code has has less attention and isn't as capable. I know roughly how I'd proceed if I went with this approach, but it is the least desirable outcome of the two. However, if I could manage to get a thread-based solution going, I can put the effort where it is most productive, namely into making sure that the thread-based solution works best. This is my preferred outcome and current goal. :) Cheers, Garth From garthy_nhtyp at entropicsoftware.com Fri Dec 6 01:44:52 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 17:14:52 +1030 Subject: Embedding multiple interpreters In-Reply-To: <52A137B3.7010408@entropicsoftware.com> References: <52A137B3.7010408@entropicsoftware.com> Message-ID: <52A17264.2040407@entropicsoftware.com> Hi all, A small update here: On 06/12/13 13:04, Garthy wrote: > [1] It presently crashes in Py_EndInterpreter() after running through a > series of tests during the shutdown of the 32nd interpreter I create. I > don't know if this is significant, but the tests pass for the first 31 > interpreters. This turned out to be a red herring, so please ignore this bit. I had a code path that failed to call Py_INCREF on Py_None which was held in a PyObject that was later Py_DECREF'd. This had some interesting consequences, and not surprisingly led to some double-frees. ;) I was able to get much further with this fix, although I'm still having some trouble getting multiple interpreters running together simultaneously. Advice and thoughts still very much welcomed on the rest of the email. :) Cheers, Garth From greg.ewing at canterbury.ac.nz Fri Dec 6 01:58:49 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 06 Dec 2013 19:58:49 +1300 Subject: Embedding multiple interpreters In-Reply-To: References: Message-ID: Garthy wrote: > I am running into problems when using multiple interpreters [1] and > I am presently trying to track down these issues. Can anyone familiar > with the process of embedding multiple interpreters have a skim of the > details below and let me know of any obvious problems? As far as I know, multiple interpreters in one process is not really supported. There *seems* to be partial support for it in the code, but there is no way to fully isolate them from each other. Why do you think you need multiple interpreters, as opposed to one interpreter with multiple threads? If you're trying to sandbox the threads from each other and/or from the rest of the system, be aware that it's extremely difficult to securely sandbox Python code. You'd be much safer to run each one in its own process and rely on OS-level protections. > - I understand that for the most part only a single interpreter will be > running at a time due to the GIL. Yes, as far as I can tell, there is only one GIL in a given process. > - I don't need to share objects between interpreters (if it is even > possible- I don't know). The hard part is *not* sharing objects between interpreters. If nothing else, all the builtin type objects, constants, etc. will be shared. -- Greg From garthy_nhtyp at entropicsoftware.com Fri Dec 6 02:59:52 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 18:29:52 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: Message-ID: <52A183F8.7000807@entropicsoftware.com> Hi Gregory, On 06/12/13 17:28, Gregory Ewing wrote: > Garthy wrote: >> I am running into problems when using multiple interpreters [1] and I >> am presently trying to track down these issues. Can anyone familiar >> with the process of embedding multiple interpreters have a skim of the >> details below and let me know of any obvious problems? > > As far as I know, multiple interpreters in one process is > not really supported. There *seems* to be partial support for > it in the code, but there is no way to fully isolate them > from each other. That's not good to hear. Is there anything confirming that it's an incomplete API insofar as multiple interpreters are concerned? Wouldn't this carry consequences for say mod_wsgi, which also does this? > Why do you think you need multiple interpreters, as opposed > to one interpreter with multiple threads? If you're trying > to sandbox the threads from each other and/or from the rest > of the system, be aware that it's extremely difficult to > securely sandbox Python code. You'd be much safer to run > each one in its own process and rely on OS-level protections. To allow each script to run in its own environment, with minimal chance of inadvertent interaction between the environments, whilst allowing each script the ability to stall on conditions that will be later met by another thread supplying the information, and to fit in with existing infrastructure. >> - I don't need to share objects between interpreters (if it is even >> possible- I don't know). > > The hard part is *not* sharing objects between interpreters. > If nothing else, all the builtin type objects, constants, etc. > will be shared. I understand. To clarify: I do not need to pass any Python objects I create or receive back and forth between different interpreters. I can imagine some environments would not react well to this. Cheers, Garth From rosuav at gmail.com Fri Dec 6 03:33:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Dec 2013 19:33:19 +1100 Subject: Embedding multiple interpreters In-Reply-To: <52A183F8.7000807@entropicsoftware.com> References: <52A183F8.7000807@entropicsoftware.com> Message-ID: On Fri, Dec 6, 2013 at 6:59 PM, Garthy wrote: > Hi Chris (and Michael), Hehe. People often say that to me IRL, addressing me and my brother. But he isn't on python-list, so you clearly mean Michael Torrie, yet my brain still automatically thought you were addressing Michael Angelico :) > To allow each script to run in its own environment, with minimal chance of > inadvertent interaction between the environments, whilst allowing each > script the ability to stall on conditions that will be later met by another > thread supplying the information, and to fit in with existing > infrastructure. Are the scripts written cooperatively, or must you isolate one from another? If you need to isolate them for trust reasons, then there's only one solution, and that's separate processes with completely separate interpreters. But if you're prepared to accept that one thread of execution is capable of mangling another's state, things are a lot easier. You can protect against *inadvertent* interaction much more easily than malicious interference. It may be that you can get away with simply running multiple threads in one interpreter; obviously that would have problems if you need more than one CPU core between them all (hello GIL), but that would really be your first limit. One thread could fiddle with __builtins__ or a standard module and thus harass another thread, but you would know if that's what's going on. ChrisA From garthy_nhtyp at entropicsoftware.com Fri Dec 6 04:35:17 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 20:05:17 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: <52A183F8.7000807@entropicsoftware.com> Message-ID: <52A19A55.1000901@entropicsoftware.com> Hi Chris, On 06/12/13 19:03, Chris Angelico wrote: > On Fri, Dec 6, 2013 at 6:59 PM, Garthy > wrote: >> Hi Chris (and Michael), > > Hehe. People often say that to me IRL, addressing me and my brother. > But he isn't on python-list, so you clearly mean Michael Torrie, yet > my brain still automatically thought you were addressing Michael > Angelico :) These strange coincidences happen from time to time- it's entertaining when they do. :) >> To allow each script to run in its own environment, with minimal chance of >> inadvertent interaction between the environments, whilst allowing each >> script the ability to stall on conditions that will be later met by another >> thread supplying the information, and to fit in with existing >> infrastructure. > > Are the scripts written cooperatively, or must you isolate one from > another? If you need to isolate them for trust reasons, then there's > only one solution, and that's separate processes with completely > separate interpreters. But if you're prepared to accept that one > thread of execution is capable of mangling another's state, things are > a lot easier. You can protect against *inadvertent* interaction much > more easily than malicious interference. It may be that you can get > away with simply running multiple threads in one interpreter; > obviously that would have problems if you need more than one CPU core > between them all (hello GIL), but that would really be your first > limit. One thread could fiddle with __builtins__ or a standard module > and thus harass another thread, but you would know if that's what's > going on. I think the ideal is completely sandboxed, but it's something that I understand I may need to make compromises on. The bare minimum would be protection against inadvertent interaction. Better yet would be a setup that made such interaction annoyingly difficult, and the ideal would be where it was impossible to interfere. My approaching this problem with interpreters was based on an assumption that it might provide a reasonable level of isolation- perhaps not ideal, but hopefully good enough. The closest analogy for understanding would be browser plugins: Scripts from multiple authors who for the most part aren't looking to create deliberate incompatibilities or interference between plugins. The isolation is basic, and some effort is made to make sure that one plugin can't cripple another trivially, but the protection is not exhaustive. Strangely enough, the GIL restriction isn't a big one in this case. For the application, the common case is actually one script running at a time, with other scripts waiting or not running at that time. They do sometimes overlap, but this isn't the common case. If it turned out that only one script could be progressing at a time, it's an annoyance but not a deal-breaker. If it's suboptimal (as seems to be the case), then it's actually not a major issue. With the single interpreter and multiple thread approach suggested, do you know if this will work with threads created externally to Python, ie. if I can create a thread in my application as normal, and then call something like PyGILState_Ensure() to make sure that Python has the internals it needs to work with it, and then use the GIL (or similar) to ensure that accesses to it remain thread-safe? If the answer is yes I can integrate such a thing more easily as an experiment. If it requires calling a dedicated "control" script that feeds out threads then it would need a fair bit more mucking about to integrate- I'd like to avoid this if possible. Cheers, Garth From rosuav at gmail.com Fri Dec 6 06:57:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Dec 2013 22:57:12 +1100 Subject: Embedding multiple interpreters In-Reply-To: <52A19A55.1000901@entropicsoftware.com> References: <52A183F8.7000807@entropicsoftware.com> <52A19A55.1000901@entropicsoftware.com> Message-ID: On Fri, Dec 6, 2013 at 8:35 PM, Garthy wrote: > I think the ideal is completely sandboxed, but it's something that I > understand I may need to make compromises on. The bare minimum would be > protection against inadvertent interaction. Better yet would be a setup that > made such interaction annoyingly difficult, and the ideal would be where it > was impossible to interfere. In Python, "impossible to interfere" is a pipe dream. There's no way to stop Python from fiddling around with the file system, and if ctypes is available, with memory in the running program. The only way to engineer that kind of protection is to prevent _the whole process_ from doing those things (using OS features, not Python features), hence the need to split the code out into another process (which might be chrooted, might be running as a user with no privileges, etc). A setup that makes such interaction "annoyingly difficult" is possible as long as your users don't think Ruby. For instance: # script1.py import sys sys.stdout = open("logfile", "w") while True: print("Blah blah") # script2.py import sys sys.stdout = open("otherlogfile", "w") while True: print("Bleh bleh") These two scripts won't play nicely together, because each has modified global state in a different module. So you'd have to set that as a rule. (For this specific example, you probably want to capture stdout/stderr to some sort of global log file anyway, and/or use the logging module, but it makes a simple example.) Most Python scripts aren't going to do this sort of thing, or if they do, will do very little of it. Monkey-patching other people's code is a VERY rare thing in Python. > The closest analogy for understanding would be browser plugins: Scripts from > multiple authors who for the most part aren't looking to create deliberate > incompatibilities or interference between plugins. The isolation is basic, > and some effort is made to make sure that one plugin can't cripple another > trivially, but the protection is not exhaustive. Browser plugins probably need a lot more protection - maybe it's not exhaustive, but any time someone finds a way for one plugin to affect another, the plugin / browser authors are going to treat it as a bug. If I understand you, though, this is more akin to having two forms on one page and having JS validation code for each. It's trivially easy for one to check the other's form objects, but quite simple to avoid too, so for the sake of encapsulation you simply stay safe. > With the single interpreter and multiple thread approach suggested, do you > know if this will work with threads created externally to Python, ie. if I > can create a thread in my application as normal, and then call something > like PyGILState_Ensure() to make sure that Python has the internals it needs > to work with it, and then use the GIL (or similar) to ensure that accesses > to it remain thread-safe? Now that's something I can't help with. The only time I embedded Python seriously was a one-Python-per-process system (arbitrary number of processes fork()ed from one master, but each process had exactly one Python environment and exactly one database connection, etc), and I ended up being unable to make it secure, so I had to switch to embedding ECMAScript (V8, specifically, as it happens... I'm morbidly curious what my boss plans to do, now that he's fired me; he hinted at rewriting the C++ engine in PHP, and I'd love to be a fly on the wall as he tries to test a PHP extension for V8 and figure out whether or not he can trust arbitrary third-party compiled code). But there'll be someone on this list who's done threads and embedded Python. ChrisA From garthy_nhtyp at entropicsoftware.com Fri Dec 6 08:56:01 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Sat, 07 Dec 2013 00:26:01 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: <52A183F8.7000807@entropicsoftware.com> <52A19A55.1000901@entropicsoftware.com> Message-ID: <52A1D771.2030109@entropicsoftware.com> Hi Chris, On 06/12/13 22:27, Chris Angelico wrote: > On Fri, Dec 6, 2013 at 8:35 PM, Garthy > wrote: >> I think the ideal is completely sandboxed, but it's something that I >> understand I may need to make compromises on. The bare minimum would be >> protection against inadvertent interaction. Better yet would be a setup that >> made such interaction annoyingly difficult, and the ideal would be where it >> was impossible to interfere. > > In Python, "impossible to interfere" is a pipe dream. There's no way > to stop Python from fiddling around with the file system, and if > ctypes is available, with memory in the running program. The only way > to engineer that kind of protection is to prevent _the whole process_ > from doing those things (using OS features, not Python features), > hence the need to split the code out into another process (which might > be chrooted, might be running as a user with no privileges, etc). Absolutely- it would be an impractical ideal. If it was my highest and only priority, CPython might not be the best place to start. But there are plenty of other factors that make Python very desirable to use regardless. :) Re file and ctype-style functionality, that is something I'm going to have to find a way to limit somewhat. But first things first: I need to see what I can accomplish re initial embedding with a reasonable amount of work. > A setup that makes such interaction "annoyingly difficult" is possible > as long as your users don't think Ruby. For instance: > > # script1.py > import sys > sys.stdout = open("logfile", "w") > while True: print("Blah blah") > > # script2.py > import sys > sys.stdout = open("otherlogfile", "w") > while True: print("Bleh bleh") > > > These two scripts won't play nicely together, because each has > modified global state in a different module. So you'd have to set that > as a rule. (For this specific example, you probably want to capture > stdout/stderr to some sort of global log file anyway, and/or use the > logging module, but it makes a simple example.) Thanks for the example. Hopefully I can minimise the cases where this would potentially be a problem. Modifying the basic environment and the source is something I can do readily if needed. Re stdout/stderr, on that subject I actually wrote a replacement log catcher for embedded Python a few years back. I can't remember how on earth I did it now, but I've still got the code that did it somewhere. > Most Python scripts > aren't going to do this sort of thing, or if they do, will do very > little of it. Monkey-patching other people's code is a VERY rare thing > in Python. That's good to hear. :) >> The closest analogy for understanding would be browser plugins: Scripts from >> multiple authors who for the most part aren't looking to create deliberate >> incompatibilities or interference between plugins. The isolation is basic, >> and some effort is made to make sure that one plugin can't cripple another >> trivially, but the protection is not exhaustive. > > Browser plugins probably need a lot more protection - maybe it's not > exhaustive, but any time someone finds a way for one plugin to affect > another, the plugin / browser authors are going to treat it as a bug. > If I understand you, though, this is more akin to having two forms on > one page and having JS validation code for each. It's trivially easy > for one to check the other's form objects, but quite simple to avoid > too, so for the sake of encapsulation you simply stay safe. There have been cases where browser plugins have played funny games to mess with the behaviour of other plugins (eg. one plugin removing entries from the configuration of another). It's certainly not ideal, but it comes from the environment being not entirely locked down, and one plugin author being inclined enough to make destructive changes that impact another. I think the right effort/reward ratio will mean I end up in a similar place. I know it's not the best analogy, but it was one that readily came to mind. :) >> With the single interpreter and multiple thread approach suggested, do you >> know if this will work with threads created externally to Python, ie. if I >> can create a thread in my application as normal, and then call something >> like PyGILState_Ensure() to make sure that Python has the internals it needs >> to work with it, and then use the GIL (or similar) to ensure that accesses >> to it remain thread-safe? > > Now that's something I can't help with. The only time I embedded > Python seriously was a one-Python-per-process system (arbitrary number > of processes fork()ed from one master, but each process had exactly > one Python environment and exactly one database connection, etc), and > I ended up being unable to make it secure, so I had to switch to > embedding ECMAScript (V8, specifically, as it happens... I'm morbidly > curious what my boss plans to do, now that he's fired me; he hinted at > rewriting the C++ engine in PHP, and I'd love to be a fly on the wall > as he tries to test a PHP extension for V8 and figure out whether or > not he can trust arbitrary third-party compiled code). But there'll be > someone on this list who's done threads and embedded Python. Thanks in any case. I'm guessing someone with the right inclination and experience might see the question and jump in with their thoughts. Many thanks for your continued thoughts by the way. :) Cheers, Garth PS. As a dev with a heavy C++ background, I also wonder at the type of C++ engine that could be improved with a PHP rewrite. ;) From greg.ewing at canterbury.ac.nz Fri Dec 6 17:23:24 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 Dec 2013 11:23:24 +1300 Subject: Embedding multiple interpreters In-Reply-To: References: <52A183F8.7000807@entropicsoftware.com> Message-ID: Garthy wrote: > The bare minimum would be > protection against inadvertent interaction. Better yet would be a setup > that made such interaction annoyingly difficult, and the ideal would be > where it was impossible to interfere. To give you an idea of the kind of interference that's possible, consider: 1) You can find all the subclasses of a given class object using its __subclasses__() method. 2) Every class ultimately derives from class object. 3) All built-in class objects are shared between interpreters. So, starting from object.__subclasses__(), code in any interpreter could find any class defined by any other interpreter and mutate it. This is not something that is likely to happen by accident. Whether it's "annoyingly difficult" enough is something you'll have to decide. Also keep in mind that it's fairly easy for Python code to chew up large amounts of memory and/or CPU time in an uninterruptible way, e.g. by evaluating 5**100000000. So even a thread that's keeping its hands entirely to itself can still cause trouble. -- Greg From garthy_nhtyp at entropicsoftware.com Fri Dec 6 19:31:37 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Sat, 07 Dec 2013 11:01:37 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: <52A183F8.7000807@entropicsoftware.com> Message-ID: <52A26C69.5050209@entropicsoftware.com> Hi Gregory, On 07/12/13 08:53, Gregory Ewing wrote: > Garthy wrote: >> The bare minimum would be protection against inadvertent interaction. >> Better yet would be a setup that made such interaction annoyingly >> difficult, and the ideal would be where it was impossible to interfere. > > To give you an idea of the kind of interference that's > possible, consider: > > 1) You can find all the subclasses of a given class > object using its __subclasses__() method. > > 2) Every class ultimately derives from class object. > > 3) All built-in class objects are shared between > interpreters. > > So, starting from object.__subclasses__(), code in any > interpreter could find any class defined by any other > interpreter and mutate it. Many thanks for the excellent example. It was not clear to me how readily such a small and critical bit of shared state could potentially be abused across interpreter boundaries. I am guessing this would be the first in a chain of potential problems I may run into. > This is not something that is likely to happen by > accident. Whether it's "annoyingly difficult" enough > is something you'll have to decide. I think it'd fall under "protection against inadvertent modification"- down the scale somewhat. It doesn't sound like it would be too difficult to achieve if the author was so inclined. > Also keep in mind that it's fairly easy for Python > code to chew up large amounts of memory and/or CPU > time in an uninterruptible way, e.g. by > evaluating 5**100000000. So even a thread that's > keeping its hands entirely to itself can still > cause trouble. Thanks for the tip. The potential for deliberate resource exhaustion is unfortunately something that I am likely going to have to put up with in order to keep things in the same process. Cheers, Garth From garthy_nhtyp at entropicsoftware.com Fri Dec 6 03:21:56 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 18:51:56 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: Message-ID: <52A18924.3080101@entropicsoftware.com> Hi Gregory, On 06/12/13 17:28, Gregory Ewing wrote: > Garthy wrote: >> I am running into problems when using multiple interpreters [1] and I >> am presently trying to track down these issues. Can anyone familiar >> with the process of embedding multiple interpreters have a skim of the >> details below and let me know of any obvious problems? > > As far as I know, multiple interpreters in one process is > not really supported. There *seems* to be partial support for > it in the code, but there is no way to fully isolate them > from each other. That's not good to hear. Is there anything confirming that it's an incomplete API insofar as multiple interpreters are concerned? Wouldn't this carry consequences for say mod_wsgi, which also does this? > Why do you think you need multiple interpreters, as opposed > to one interpreter with multiple threads? If you're trying > to sandbox the threads from each other and/or from the rest > of the system, be aware that it's extremely difficult to > securely sandbox Python code. You'd be much safer to run > each one in its own process and rely on OS-level protections. To allow each script to run in its own environment, with minimal chance of inadvertent interaction between the environments, whilst allowing each script the ability to stall on conditions that will be later met by another thread supplying the information, and to fit in with existing infrastructure. >> - I don't need to share objects between interpreters (if it is even >> possible- I don't know). > > The hard part is *not* sharing objects between interpreters. > If nothing else, all the builtin type objects, constants, etc. > will be shared. I understand. To clarify: I do not need to pass any Python objects I create or receive back and forth between different interpreters. I can imagine some environments would not react well to this. Cheers, Garth PS. Apologies if any of these messages come through more than once. Most lists that I've posted to set reply-to meaning a normal reply can be used, but python-list does not seem to. The replies I have sent manually to python-list at python.org instead don't seem to have appeared. I'm not quite sure what is happening- apologies for any blundering around on my part trying to figure it out. From rosuav at gmail.com Fri Dec 6 04:27:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Dec 2013 20:27:43 +1100 Subject: Embedding multiple interpreters In-Reply-To: <52A18924.3080101@entropicsoftware.com> References: <52A18924.3080101@entropicsoftware.com> Message-ID: On Fri, Dec 6, 2013 at 7:21 PM, Garthy wrote: > PS. Apologies if any of these messages come through more than once. Most > lists that I've posted to set reply-to meaning a normal reply can be used, > but python-list does not seem to. The replies I have sent manually to > python-list at python.org instead don't seem to have appeared. I'm not quite > sure what is happening- apologies for any blundering around on my part > trying to figure it out. They are coming through more than once. If you're subscribed to the list, sending to python-list at python.org should be all you need to do - where else are they going? ChrisA From garthy_nhtyp at entropicsoftware.com Fri Dec 6 04:44:33 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 20:14:33 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: <52A18924.3080101@entropicsoftware.com> Message-ID: <52A19C81.1050806@entropicsoftware.com> Hi Chris, On 06/12/13 19:57, Chris Angelico wrote: > On Fri, Dec 6, 2013 at 7:21 PM, Garthy > wrote: >> PS. Apologies if any of these messages come through more than once. Most >> lists that I've posted to set reply-to meaning a normal reply can be used, >> but python-list does not seem to. The replies I have sent manually to >> python-list at python.org instead don't seem to have appeared. I'm not quite >> sure what is happening- apologies for any blundering around on my part >> trying to figure it out. > > They are coming through more than once. If you're subscribed to the > list, sending to python-list at python.org should be all you need to do - > where else are they going? I think I've got myself sorted out now. The mailing list settings are a bit different from what I am used to and I just need to reply to messages differently than I normally do. First attempt for three emails each went to the wrong place, second attempt for each appeared to have disappeared into the ether and I assumed non-delivery, but I was incorrect and they all actually arrived along with my third attempt at each. Apologies to all for the inadvertent noise. Cheers, Garth From mail at timgolden.me.uk Fri Dec 6 05:17:21 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 06 Dec 2013 10:17:21 +0000 Subject: Embedding multiple interpreters In-Reply-To: References: <52A18924.3080101@entropicsoftware.com> Message-ID: <52A1A431.3020005@timgolden.me.uk> On 06/12/2013 09:27, Chris Angelico wrote: > On Fri, Dec 6, 2013 at 7:21 PM, Garthy > wrote: >> PS. Apologies if any of these messages come through more than once. Most >> lists that I've posted to set reply-to meaning a normal reply can be used, >> but python-list does not seem to. The replies I have sent manually to >> python-list at python.org instead don't seem to have appeared. I'm not quite >> sure what is happening- apologies for any blundering around on my part >> trying to figure it out. > > They are coming through more than once. If you're subscribed to the > list, sending to python-list at python.org should be all you need to do - > where else are they going? I released a batch from the moderation queue from Garthy first thing this [my] morning -- ie about 1.5 hours ago. I'm afraid I didn't check first as to whether they'd already got through to the list some other way. TJG From garthy_nhtyp at entropicsoftware.com Fri Dec 6 09:04:20 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Sat, 07 Dec 2013 00:34:20 +1030 Subject: Embedding multiple interpreters In-Reply-To: <52A1A431.3020005@timgolden.me.uk> References: <52A18924.3080101@entropicsoftware.com> <52A1A431.3020005@timgolden.me.uk> Message-ID: <52A1D964.5000207@entropicsoftware.com> Hi Tim, On 06/12/13 20:47, Tim Golden wrote: > On 06/12/2013 09:27, Chris Angelico wrote: >> On Fri, Dec 6, 2013 at 7:21 PM, Garthy >> wrote: >>> PS. Apologies if any of these messages come through more than once. Most >>> lists that I've posted to set reply-to meaning a normal reply can be used, >>> but python-list does not seem to. The replies I have sent manually to >>> python-list at python.org instead don't seem to have appeared. I'm not quite >>> sure what is happening- apologies for any blundering around on my part >>> trying to figure it out. >> >> They are coming through more than once. If you're subscribed to the >> list, sending to python-list at python.org should be all you need to do - >> where else are they going? > > > I released a batch from the moderation queue from Garthy first thing > this [my] morning -- ie about 1.5 hours ago. I'm afraid I didn't check > first as to whether they'd already got through to the list some other way. I had to make a call between re-sending posts that might have gone missing, or seemingly not responding promptly when people had taken the time to answer my complex query. I made a call to re-send, and it was the wrong one. The fault for the double-posting is entirely mine. Cheers, Garth From greg.ewing at canterbury.ac.nz Fri Dec 6 17:09:11 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 Dec 2013 11:09:11 +1300 Subject: Embedding multiple interpreters In-Reply-To: References: Message-ID: Garthy wrote: > To allow each script to run in its own environment, with minimal chance > of inadvertent interaction between the environments, whilst allowing > each script the ability to stall on conditions that will be later met by > another thread supplying the information, and to fit in with existing > infrastructure. The last time I remember this being discussed was in the context of allowing free threading. Multiple interpreters don't solve that problem, because there's still only one GIL and some objects are shared. But if all you want is for each plugin to have its own version of sys.modules, etc., and you're not concerned about malicious code, then it may be good enough. It seems to be good enough for mod_wsgi, because presumably all the people with the ability to install code on a given web server trust each other. -- Greg From garthy_nhtyp at entropicsoftware.com Fri Dec 6 19:57:47 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Sat, 07 Dec 2013 11:27:47 +1030 Subject: Embedding multiple interpreters In-Reply-To: References: Message-ID: <52A2728B.1020703@entropicsoftware.com> Hi Gregory, On 07/12/13 08:39, Gregory Ewing wrote: > Garthy wrote: >> To allow each script to run in its own environment, with minimal >> chance of inadvertent interaction between the environments, whilst >> allowing each script the ability to stall on conditions that will be >> later met by another thread supplying the information, and to fit in >> with existing infrastructure. > > The last time I remember this being discussed was in the context > of allowing free threading. Multiple interpreters don't solve > that problem, because there's still only one GIL and some > objects are shared. I am fortunate in my case as the normal impact of the GIL would be much reduced. The common case is only one script actively progressing at a time- with the others either not running or waiting for external input to continue. But as you point out in your other reply, there are still potential concerns that arise from the smaller set of shared objects even across interpreters. > But if all you want is for each plugin to have its own version > of sys.modules, etc., and you're not concerned about malicious > code, then it may be good enough. I wouldn't say that I wasn't concerned about it entirely, but on the other hand it is not a hard requirement to which all other concerns are secondary. Cheers, Garth From garthy_nhtyp at entropicsoftware.com Fri Dec 6 03:17:19 2013 From: garthy_nhtyp at entropicsoftware.com (Garthy) Date: Fri, 06 Dec 2013 18:47:19 +1030 Subject: Embedding multiple interpreters In-Reply-To: <52A137B3.7010408@entropicsoftware.com> References: <52A137B3.7010408@entropicsoftware.com> Message-ID: <52A1880F.8010509@entropicsoftware.com> Hi all, A small update here: On 06/12/13 13:04, Garthy wrote: > [1] It presently crashes in Py_EndInterpreter() after running through a > series of tests during the shutdown of the 32nd interpreter I create. I > don't know if this is significant, but the tests pass for the first 31 > interpreters. This turned out to be a red herring, so please ignore this bit. I had a code path that failed to call Py_INCREF on Py_None which was held in a PyObject that was later Py_DECREF'd. This had some interesting consequences, and not surprisingly led to some double-frees. ;) I was able to get much further with this fix, although I'm still having some trouble getting multiple interpreters running together simultaneously. Advice and thoughts still very much welcomed on the rest of the email. :) Cheers, Garth From r.voigtlaender at gmail.com Fri Dec 6 03:47:54 2013 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Fri, 6 Dec 2013 00:47:54 -0800 (PST) Subject: squeeze out some performance Message-ID: Hi, I try to squeeze out some performance of the code pasted on the link below. http://pastebin.com/gMnqprST The code will be used to continuously analyze sonar sensor data. I set this up to calculate all coordinates in a sonar cone without heavy use of trigonometry (assuming that this way is faster in the end). I optimized as much as I could. Maybe one of you has another bright idea to squeeze out a bit more? Thanks Robert From jeremy at jeremysanders.net Fri Dec 6 04:46:46 2013 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Fri, 06 Dec 2013 10:46:46 +0100 Subject: squeeze out some performance References: Message-ID: Robert Voigtl?nder wrote: > I try to squeeze out some performance of the code pasted on the link > below. http://pastebin.com/gMnqprST > > The code will be used to continuously analyze sonar sensor data. I set > this up to calculate all coordinates in a sonar cone without heavy use of > trigonometry (assuming that this way is faster in the end). > > I optimized as much as I could. Maybe one of you has another bright idea > to squeeze out a bit more? This sort of code is probably harder to make faster in pure python. You could try profiling it to see where the hot spots are. Perhaps the choice of arrays or sets might have some speed impact. One idea would be to use something like cython to compile your python code to an extension module, with some hints to the types of the various values. I would go down the geometry route. If you can restate your problem in terms of geometry, it might be possible to replace all that code with a few numpy array operations. e.g. for finding pixels in a circle of radius 50 import numpy as np radiussqd = np.fromfunction(lambda y,x: (y-50)**2+(x-50)**2, (100,100) ) all_y, all_x = np.indices((100,100)) yvals = all_y[radiussqd < 50**2] Jeremy From rosuav at gmail.com Fri Dec 6 07:13:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Dec 2013 23:13:34 +1100 Subject: squeeze out some performance In-Reply-To: References: Message-ID: On Fri, Dec 6, 2013 at 8:46 PM, Jeremy Sanders wrote: > This sort of code is probably harder to make faster in pure python. You > could try profiling it to see where the hot spots are. Perhaps the choice of > arrays or sets might have some speed impact. I'd make this recommendation MUCH stronger. Rule 1 of optimization: Don't. Rule 2 (for experts only): Don't yet. Once you find that your program actually is running too slowly, then AND ONLY THEN do you start looking at tightening something up. You'll be amazed how little you need to change; start with good clean idiomatic code, and then if it takes too long, you tweak just a couple of things and it's fast enough. And when you do come to the tweaking... Rule 3: Measure twice, cut once. Rule 4: Actually, measure twenty times, cut once. Profile your code to find out what's actually slow. This is very important. Here's an example from a real application (not in Python, it's in a semantically-similar language called Pike): https://github.com/Rosuav/Gypsum/blob/d9907e1507c52189c83ae25f5d7be85235b616fa/window.pike I noticed that I could saturate one CPU core by typing commands very quickly. Okay. That gets us past the first two rules (it's a MUD client, it should not be able to saturate one core of an i5). The code looks roughly like this: paint(): for line in lines: if line_is_visible: paint_line(line) paint_line(): for piece_of_text in text: if highlighted: draw_highlighted() else: draw_not_highlighted() My first guess was that the actual drawing was taking the time, since that's a whole lot of GTK calls. But no; the actual problem was the iteration across all lines and then finding out if they're visible or not (possibly because it obliterates the CPU caches). Once the scrollback got to a million lines or so, that was prohibitively expensive. I didn't realize that until I actually profiled the code and _measured_ where the time was being spent. How fast does your code run? How fast do you need it to run? Lots of optimization questions are answered by "Yaknow what, it don't even matter", unless you're running in a tight loop, or on a microcontroller, or something. Halving the time taken sounds great until you see that it's currently taking 0.0001 seconds and happens in response to user action. ChrisA From r.voigtlaender at gmail.com Fri Dec 6 11:29:30 2013 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Fri, 6 Dec 2013 08:29:30 -0800 (PST) Subject: squeeze out some performance In-Reply-To: References: Message-ID: <35814163-d0a5-4927-b61d-7d3b4ee0989b@googlegroups.com> Thanks for your replies. I already did some basic profiling and optimized a lot. Especially with help of a goof python performance tips list I found. I think I'll follow the cython path. The geometry approach also sound good. But it's way above my math/geometry knowledge. Thanks for your input! From breamoreboy at yahoo.co.uk Fri Dec 6 11:36:03 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 16:36:03 +0000 Subject: squeeze out some performance In-Reply-To: <35814163-d0a5-4927-b61d-7d3b4ee0989b@googlegroups.com> References: <35814163-d0a5-4927-b61d-7d3b4ee0989b@googlegroups.com> Message-ID: On 06/12/2013 16:29, Robert Voigtl?nder wrote: > Thanks for your replies. > > I already did some basic profiling and optimized a lot. Especially > with help of a goof python performance tips list I found. > Wonderful typo -----^ :) > I think I'll follow the cython path. > The geometry approach also sound good. But it's way above my math/geometry knowledge. > > Thanks for your input! > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From r.voigtlaender at gmail.com Fri Dec 6 11:44:38 2013 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Fri, 6 Dec 2013 08:44:38 -0800 (PST) Subject: squeeze out some performance In-Reply-To: References: <35814163-d0a5-4927-b61d-7d3b4ee0989b@googlegroups.com> Message-ID: Am Freitag, 6. Dezember 2013 17:36:03 UTC+1 schrieb Mark Lawrence: > > I already did some basic profiling and optimized a lot. Especially > with help of a goof python performance tips list I found. > > Wonderful typo -----^ :) > Oh well :-) ... it was a good one. Just had a quick look at Cython. Looks great. Thanks for the tip. From john_ladasky at sbcglobal.net Fri Dec 6 11:52:47 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 6 Dec 2013 08:52:47 -0800 (PST) Subject: squeeze out some performance In-Reply-To: References: Message-ID: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> On Friday, December 6, 2013 12:47:54 AM UTC-8, Robert Voigtl?nder wrote: > I try to squeeze out some performance of the code pasted on the link below. > http://pastebin.com/gMnqprST Several comments: 1) I find this program to be very difficult to read, largely because there's a whole LOT of duplicated code. Look at lines 53-80, and lines 108-287, and lines 294-311. It makes it harder to see what this algorithm actually does. Is there a way to refactor some of this code to use some shared function calls? 2) I looked up the "Bresenham algorithm", and found two references which may be relevant. The original algorithm was one which computed good raster approximations to straight lines. The second algorithm described may be more pertinent to you, because it draws arcs of circles. http://en.wikipedia.org/wiki/Bresenham's_line_algorithm http://en.wikipedia.org/wiki/Midpoint_circle_algorithm Both of these algorithms are old, from the 1960's, and can be implemented using very simple CPU register operations and minimal memory. Both of the web pages I referenced have extensive example code and pseudocode, and discuss optimization. If you need speed, is this really a job for Python? 3) I THINK that I see some code -- those duplicated parts -- which might benefit from the use of multiprocessing (assuming that you have a multi-core CPU). But I would have to read more deeply to be sure. I need to understand the algorithm more completely, and exactly how you have modified it for your needs. From joel.goldstick at gmail.com Fri Dec 6 17:07:56 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 6 Dec 2013 17:07:56 -0500 Subject: squeeze out some performance In-Reply-To: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> Message-ID: On Fri, Dec 6, 2013 at 11:52 AM, John Ladasky wrote: > On Friday, December 6, 2013 12:47:54 AM UTC-8, Robert Voigtl?nder wrote: > > > I try to squeeze out some performance of the code pasted on the link > below. > > http://pastebin.com/gMnqprST > Not that this will speed up your code but you have this: if not clockwise: s = start start = end end = s Python people would write: end, start = start, end You have quite a few if statements that involve multiple comparisons of the same variable. Did you know you can do things like this in python: >>> x = 4 >>> 2 < x < 7 True >>> x = 55 >>> 2 < x < 7 False > Several comments: > > 1) I find this program to be very difficult to read, largely because > there's a whole LOT of duplicated code. Look at lines 53-80, and lines > 108-287, and lines 294-311. It makes it harder to see what this algorithm > actually does. Is there a way to refactor some of this code to use some > shared function calls? > > 2) I looked up the "Bresenham algorithm", and found two references which > may be relevant. The original algorithm was one which computed good raster > approximations to straight lines. The second algorithm described may be > more pertinent to you, because it draws arcs of circles. > > http://en.wikipedia.org/wiki/Bresenham's_line_algorithm > http://en.wikipedia.org/wiki/Midpoint_circle_algorithm > > Both of these algorithms are old, from the 1960's, and can be implemented > using very simple CPU register operations and minimal memory. Both of the > web pages I referenced have extensive example code and pseudocode, and > discuss optimization. If you need speed, is this really a job for Python? > > 3) I THINK that I see some code -- those duplicated parts -- which might > benefit from the use of multiprocessing (assuming that you have a > multi-core CPU). But I would have to read more deeply to be sure. I need > to understand the algorithm more completely, and exactly how you have > modified it for your needs. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Mon Dec 9 10:54:36 2013 From: robin at reportlab.com (Robin Becker) Date: Mon, 09 Dec 2013 15:54:36 +0000 Subject: squeeze out some performance In-Reply-To: References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> Message-ID: <52A5E7BC.5090600@chamonix.reportlab.co.uk> On 06/12/2013 22:07, Joel Goldstick wrote: .......... >> > > Not that this will speed up your code but you have this: > > if not clockwise: > s = start > start = end > end = s > > Python people would write: > end, start = start, end this works for some small number of variables, but on my machine with python 2.7 I start losing with 4 variables eg > C:\code\optichrome\74663>python -mtimeit -s"a=1;b=2;c=3;d=4" "a,b,c,d=b,c,d,a" > 1000000 loops, best of 3: 0.206 usec per loop > > C:\code\optichrome\74663>python -mtimeit -s"a=1;b=2;c=3;d=4" "t=a;a=b;b=c;c=d;d=t" > 10000000 loops, best of 3: 0.118 usec per loop It doesn't seem to make much difference that the variables are related as I see a similar behaviour for simple assignments > C:\code\optichrome\74663>python -mtimeit -s"a=1;b=2;c=3;d=4;e=5;f=6;g=7;h=8" "a,b,c,d=e,f,g,h" > 1000000 loops, best of 3: 0.204 usec per loop > > C:\code\optichrome\74663>python -mtimeit -s"a=1;b=2;c=3;d=4;e=5;f=6;g=7;h=8" "a=e;b=f;c=g;d=h" > 10000000 loops, best of 3: 0.103 usec per loop for less than 4 variables the tuple method is faster. -- Robin Becker From davea at davea.name Mon Dec 9 15:46:16 2013 From: davea at davea.name (Dave Angel) Date: Mon, 09 Dec 2013 15:46:16 -0500 Subject: squeeze out some performance In-Reply-To: <52A5E7BC.5090600@chamonix.reportlab.co.uk> References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> <52A5E7BC.5090600@chamonix.reportlab.co.uk> Message-ID: On Mon, 09 Dec 2013 15:54:36 +0000, Robin Becker wrote: > On 06/12/2013 22:07, Joel Goldstick wrote: > > end, start = start, end > a similar behaviour for simple assignments > for less than 4 variables the tuple method is faster. What does speed have to do with it? When you want to swap two variables, the tuple assignment reads better. -- DaveA From robin at reportlab.com Tue Dec 10 07:54:13 2013 From: robin at reportlab.com (Robin Becker) Date: Tue, 10 Dec 2013 12:54:13 +0000 Subject: squeeze out some performance In-Reply-To: References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> <52A5E7BC.5090600@chamonix.reportlab.co.uk> Message-ID: <52A70EF5.1040008@chamonix.reportlab.co.uk> On 09/12/2013 20:46, Dave Angel wrote: > On Mon, 09 Dec 2013 15:54:36 +0000, Robin Becker wrote: >> On 06/12/2013 22:07, Joel Goldstick wrote: >> > end, start = start, end > >> a similar behaviour for simple assignments > >> for less than 4 variables the tuple method is faster. > > What does speed have to do with it? When you want to swap two variables, the > tuple assignment reads better. > Well the OP is asking about performance so I guess the look and feel might be sacrificed for speed in some circumstances. The tuple approach is more appealing when the lhs & rhs are connected, but it seems that even for more general assignments the tuple assignment may be faster for small numbers of variables. Looking at the output of dis for this case d,e,f=c,b,a it seems that we get code like this LOAD_NAME 3 (c) LOAD_NAME 2 (b) LOAD_NAME 1 (a) ROT_THREE ROT_TWO STORE_NAME 4 (d) STORE_NAME 5 (e) STORE_NAME 6 (f) for d = c e = b f = a we get this LOAD_NAME 3 (c) STORE_NAME 4 (d) LOAD_NAME 2 (b) STORE_NAME 5 (e) LOAD_NAME 1 (a) STORE_NAME 6 (f) which is not obviously slower, but I consistently get the former to be faster. I suppose it's a cache issue or something. However, for this particular case when the variables are not connected I find the tuple assignment less pythonic, but perhaps faster (even though in this case no tuples are built). -- Robin Becker From breamoreboy at yahoo.co.uk Fri Dec 6 17:38:57 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 22:38:57 +0000 Subject: squeeze out some performance In-Reply-To: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> Message-ID: On 06/12/2013 16:52, John Ladasky wrote: > On Friday, December 6, 2013 12:47:54 AM UTC-8, Robert Voigtl?nder wrote: > >> I try to squeeze out some performance of the code pasted on the link below. >> http://pastebin.com/gMnqprST > > Several comments: > > 1) I find this program to be very difficult to read, largely because there's a whole LOT of duplicated code. Look at lines 53-80, and lines 108-287, and lines 294-311. It makes it harder to see what this algorithm actually does. Is there a way to refactor some of this code to use some shared function calls? > A handy tool for detecting duplicated code here http://clonedigger.sourceforge.net/ for anyone who's interested. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From drsalists at gmail.com Fri Dec 6 18:01:49 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 6 Dec 2013 15:01:49 -0800 Subject: squeeze out some performance In-Reply-To: References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> Message-ID: On Fri, Dec 6, 2013 at 2:38 PM, Mark Lawrence wrote: > On 06/12/2013 16:52, John Ladasky wrote: > >> On Friday, December 6, 2013 12:47:54 AM UTC-8, Robert Voigtl?nder wrote: >> >> I try to squeeze out some performance of the code pasted on the link >>> below. >>> http://pastebin.com/gMnqprST >>> >> >> Several comments: >> >> 1) I find this program to be very difficult to read, largely because >> there's a whole LOT of duplicated code. Look at lines 53-80, and lines >> 108-287, and lines 294-311. It makes it harder to see what this algorithm >> actually does. Is there a way to refactor some of this code to use some >> shared function calls? >> >> > A handy tool for detecting duplicated code here > http://clonedigger.sourceforge.net/ for anyone who's interested. > Pylint does this too... -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.voigtlaender at gmail.com Mon Dec 9 09:19:21 2013 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Mon, 9 Dec 2013 06:19:21 -0800 (PST) Subject: squeeze out some performance In-Reply-To: References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> Message-ID: <5320aa30-8ea5-4680-8796-ef2c7dac3984@googlegroups.com> Am Samstag, 7. Dezember 2013 00:01:49 UTC+1 schrieb Dan Stromberg: > On Fri, Dec 6, 2013 at 2:38 PM, Mark Lawrence wrote: > > > On 06/12/2013 16:52, John Ladasky wrote: > > > On Friday, December 6, 2013 12:47:54 AM UTC-8, Robert Voigtl?nder wrote: > > > > > I try to squeeze out some performance of the code pasted on the link below. > > http://pastebin.com/gMnqprST > > > > > Several comments: > > > > 1) I find this program to be very difficult to read, largely because there's a whole LOT of duplicated code. ?Look at lines 53-80, and lines 108-287, and lines 294-311. ?It makes it harder to see what this algorithm actually does. ?Is there a way to refactor some of this code to use some shared function calls? > > > > > > > > A handy tool for detecting duplicated code here http://clonedigger.sourceforge.net/ for anyone who's interested. > > > > Pylint does this too... Thanks again. I'll try to compress the code and have a look at the "multiple comparisons" topic. Robert From breamoreboy at yahoo.co.uk Mon Dec 9 09:52:54 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 14:52:54 +0000 Subject: squeeze out some performance In-Reply-To: <5320aa30-8ea5-4680-8796-ef2c7dac3984@googlegroups.com> References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> <5320aa30-8ea5-4680-8796-ef2c7dac3984@googlegroups.com> Message-ID: On 09/12/2013 14:19, Robert Voigtl?nder wrote: > Am Samstag, 7. Dezember 2013 00:01:49 UTC+1 schrieb Dan Stromberg: >> On Fri, Dec 6, 2013 at 2:38 PM, Mark Lawrence wrote: >> >> >> On 06/12/2013 16:52, John Ladasky wrote: >> >> >> On Friday, December 6, 2013 12:47:54 AM UTC-8, Robert Voigtl?nder wrote: >> >> >> >> >> I try to squeeze out some performance of the code pasted on the link below. >> >> http://pastebin.com/gMnqprST >> >> >> >> >> Several comments: >> >> >> >> 1) I find this program to be very difficult to read, largely because there's a whole LOT of duplicated code. Look at lines 53-80, and lines 108-287, and lines 294-311. It makes it harder to see what this algorithm actually does. Is there a way to refactor some of this code to use some shared function calls? >> >> >> >> >> >> >> >> A handy tool for detecting duplicated code here http://clonedigger.sourceforge.net/ for anyone who's interested. >> >> >> >> Pylint does this too... > > Thanks again. I'll try to compress the code and have a look at the "multiple comparisons" topic. > > Robert > Would you be kind enough to compress your messages while you're at it by reading and actioning https://wiki.python.org/moin/GoogleGroupsPython thanks, a quick glance above will tell you why :) -- 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 Dec 9 18:57:57 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 23:57:57 +0000 Subject: squeeze out some performance In-Reply-To: References: Message-ID: On 06/12/2013 08:47, Robert Voigtl?nder wrote: > Hi, > > I try to squeeze out some performance of the code pasted on the link below. > http://pastebin.com/gMnqprST > > The code will be used to continuously analyze sonar sensor data. I set this up to calculate all coordinates in a sonar cone without heavy use of trigonometry (assuming that this way is faster in the end). > > I optimized as much as I could. Maybe one of you has another bright idea to squeeze out a bit more? > > Thanks > Robert > Actually for optimised code it looks very similar to some code posted here http://www.daniweb.com/software-development/python/threads/321181/python-bresenham-circle-arc-algorithm over three years ago. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From r.voigtlaender at gmail.com Tue Dec 10 07:14:39 2013 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 10 Dec 2013 04:14:39 -0800 (PST) Subject: squeeze out some performance In-Reply-To: References: Message-ID: <4162ca51-a334-471e-84c7-8478411d41f7@googlegroups.com> > Actually for optimised code it looks very similar to some code posted > > here > > http://www.daniweb.com/software-development/python/threads/321181/python-bresenham-circle-arc-algorithm > > over three years ago. > This is where it origins from. I just extended it for my needs and now want to optimize it. List comprehensions instead of some for loops brought another 25%. And made the code shorter. From info at egenix.com Fri Dec 6 04:53:00 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Fri, 06 Dec 2013 10:53:00 +0100 Subject: ANN: eGenix PyRun - One file Python Runtime 1.3.1 Message-ID: <52A19E7C.1080007@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix PyRun - One file Python Runtime Version 1.3.1 An easy-to-use single file relocatable Python run-time - available for Linux, Mac OS X and Unix platforms, with support for Python 2.5, 2.6 and 2.7 This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-PyRun-1.3.0-GA.html ________________________________________________________________________ INTRODUCTION Our new eGenix PyRun combines a Python interpreter with an almost complete Python standard library into a single easy-to-use executable, that does not require a system wide installation and is fully relocatable. eGenix PyRun's executable only needs 11MB, but still supports most Python application and scripts - and it can be further compressed to just 3-4MB using upx. Compared to a regular Python installation of typically 100MB on disk, this makes eGenix PyRun ideal for applications and scripts that need to be distributed to many target machines, client installations or customers. It makes "installing" Python on a Unix based system as simple as copying a single file. We have been using the product internally in our mxODBC Connect Server since 2008 with great success and have now extracted it into a stand-alone open-source product. We provide both the source archive to build your own eGenix PyRun, as well as pre-compiled binaries for Linux, FreeBSD and Mac OS X, as 32- and 64-bit versions. The binaries can be downloaded manually, or you can let our automatic install script install-pyrun take care of the installation: ./install-pyrun dir and you're done. Please see the product page for more details: http://www.egenix.com/products/python/PyRun/ ________________________________________________________________________ NEWS This is a new minor release of eGenix PyRun, which comes with updates to the latest Python releases and includes a number of compatibility enhancements. New Features ------------ * Upgraded eGenix PyRun to work with and use Python 2.7.6 per default. * Upgraded eGenix PyRun to use Python 2.6.9 as default Python 2.6 version. install-pyrun Quick Installation Enhancements --------------------------------------------- Since version 1.1.0, eGenix PyRun includes a shell script called install-pyrun, which greatly simplifies installation of eGenix PyRun. It works much like the virtualenv shell script used for creating new virtual environments (except that there's nothing virtual about PyRun environments). https://downloads.egenix.com/python/install-pyrun With the script, an eGenix PyRun installation is as simple as running: ./install-pyrun targetdir We have updated this script since the last release: * install-pyrun now defaults to installing setuptools 1.4.2 and pip 1.4.1 when looking for local downloads of these tools. For a complete list of changes, please see the eGenix PyRun Changelog: http://www.egenix.com/products/python/PyRun/changelog.html For a list of changes in the 1.3.0 minor release, please read the eGenix PyRun 1.3.0 announcement: http://www.egenix.com/company/news/eGenix-PyRun-1.3.0-GA.html Presentation at EuroPython 2012 ------------------------------- Marc-Andr? Lemburg, CEO of eGenix, gave a presentation about eGenix PyRun at EuroPython 2012 last year. The talk video as well as the slides are available on our website: http://www.egenix.com/library/presentations/EuroPython2012-eGenix-PyRun/ ________________________________________________________________________ LICENSE eGenix PyRun is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use eGenix PyRun in both commercial and non-commercial settings without fee or charge. Please see our license page for more details: http://www.egenix.com/products/python/PyRun/license.html The package comes with full source code. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing eGenix PyRun can be found at: http://www.egenix.com/products/python/PyRun/ As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on other platforms, such as Solaris, AIX, HP-UX, etc. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about eGenix PyRun, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/python/PyRun/ About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company specializing in expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Dec 06 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From jeandubois314 at gmail.com Fri Dec 6 07:24:59 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Fri, 6 Dec 2013 04:24:59 -0800 (PST) Subject: [newbie] problem trying out simple non object oriented use of Tkinter Message-ID: <94a9c18f-595d-486a-96b5-d0f9f57824ba@googlegroups.com> I'm trying out Tkinter with the (non object oriented) code fragment below: It works partially as I expected, but I thought that pressing "1" would cause the program to quit, however I get this message: TypeError: quit() takes no arguments (1 given), I tried changing quit to quit() but that makes things even worse. So my question: can anyone here help me debug this? #!/usr/bin/env python import Tkinter as tk def quit(): sys.exit() root = tk.Tk() label = tk.Label(root, text="Hello, world") label.pack() label.bind("<1>", quit) root.mainloop() p.s. I like the code not object orientated From daniel at daniel-watkins.co.uk Fri Dec 6 07:30:53 2013 From: daniel at daniel-watkins.co.uk (Daniel Watkins) Date: Fri, 6 Dec 2013 12:30:53 +0000 Subject: [newbie] problem trying out simple non object oriented use of Tkinter In-Reply-To: <94a9c18f-595d-486a-96b5-d0f9f57824ba@googlegroups.com> References: <94a9c18f-595d-486a-96b5-d0f9f57824ba@googlegroups.com> Message-ID: <20131206123053.GT22882@daniel-watkins.co.uk> Hi Jean, On Fri, Dec 06, 2013 at 04:24:59AM -0800, Jean Dubois wrote: > I'm trying out Tkinter with the (non object oriented) code fragment below: > It works partially as I expected, but I thought that pressing "1" would > cause the program to quit, however I get this message: > TypeError: quit() takes no arguments (1 given), I tried changing quit to quit() > but that makes things even worse. So my question: can anyone here help me > debug this? I don't know the details of the Tkinter library, but you could find out what quit is being passed by modifying it to take a single parameter and printing it out (or using pdb): def quit(param): print(param) sys.exit() Having taken a quick look at the documentation, it looks like event handlers (like your quit function) are passed the event that triggered them. So you can probably just ignore the parameter: def quit(_): sys.exit() Cheers, Dan From jeanmichel at sequans.com Fri Dec 6 07:33:05 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 6 Dec 2013 13:33:05 +0100 (CET) Subject: [newbie] problem trying out simple non object oriented use of Tkinter In-Reply-To: <94a9c18f-595d-486a-96b5-d0f9f57824ba@googlegroups.com> Message-ID: <241214611.387563.1386333185901.JavaMail.root@sequans.com> ----- Original Message ----- > I'm trying out Tkinter with the (non object oriented) code fragment > below: > It works partially as I expected, but I thought that pressing "1" > would > cause the program to quit, however I get this message: > TypeError: quit() takes no arguments (1 given), I tried changing quit > to quit() > but that makes things even worse. So my question: can anyone here > help me > debug this? > > #!/usr/bin/env python > import Tkinter as tk > def quit(): > sys.exit() > root = tk.Tk() > label = tk.Label(root, text="Hello, world") > label.pack() > label.bind("<1>", quit) > root.mainloop() > > p.s. I like the code not object orientated > -- > https://mail.python.org/mailman/listinfo/python-list > the engine is probably passing an argument to your quit callback method. try def quit(param): sys.exit(str(param)) You probably don't even care about the parameter: def quit(param): sys.exit() JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From jeandubois314 at gmail.com Fri Dec 6 08:12:01 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Fri, 6 Dec 2013 05:12:01 -0800 (PST) Subject: [newbie] problem trying out simple non object oriented use of Tkinter In-Reply-To: References: <94a9c18f-595d-486a-96b5-d0f9f57824ba@googlegroups.com> Message-ID: Op vrijdag 6 december 2013 13:30:53 UTC+1 schreef Daniel Watkins: > Hi Jean, > > > > On Fri, Dec 06, 2013 at 04:24:59AM -0800, Jean Dubois wrote: > > > I'm trying out Tkinter with the (non object oriented) code fragment below: > > > It works partially as I expected, but I thought that pressing "1" would > > > cause the program to quit, however I get this message: > > > TypeError: quit() takes no arguments (1 given), I tried changing quit to quit() > > > but that makes things even worse. So my question: can anyone here help me > > > debug this? > > > > I don't know the details of the Tkinter library, but you could find out > > what quit is being passed by modifying it to take a single parameter and > > printing it out (or using pdb): > > > > def quit(param): > > print(param) > > sys.exit() > > > > Having taken a quick look at the documentation, it looks like event > > handlers (like your quit function) are passed the event that triggered > > them. So you can probably just ignore the parameter: > > > > def quit(_): > > sys.exit() > > > > > > Cheers, > > > > Dan I tried out your suggestions and discovered that I had the line import sys to the program. So you can see below what I came up with. It works but it's not all clear to me. Can you tell me what "label.bind("<1>", quit)" is standing for? What's the <1> meaning? #!/usr/bin/env python import Tkinter as tk import sys #underscore is necessary in the following line def quit(_): sys.exit() root = tk.Tk() label = tk.Label(root, text="Click mouse here to quit") label.pack() label.bind("<1>", quit) root.mainloop() thanks jean From jeanmichel at sequans.com Fri Dec 6 09:01:27 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 6 Dec 2013 15:01:27 +0100 (CET) Subject: [newbie] problem trying out simple non object oriented use of Tkinter In-Reply-To: Message-ID: <1584661095.397721.1386338487627.JavaMail.root@sequans.com> > I tried out your suggestions and discovered that I had the line > import sys to the program. So you can see below what I came up with. > It works but it's not all clear to me. Can you tell me what > "label.bind("<1>", quit)" is standing for? What's the <1> meaning? > > > > #!/usr/bin/env python > import Tkinter as tk > import sys > #underscore is necessary in the following line > def quit(_): > sys.exit() > root = tk.Tk() > label = tk.Label(root, text="Click mouse here to quit") > label.pack() > label.bind("<1>", quit) > root.mainloop() > > thanks > jean The best thing to do would be to read http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm "<1>" is the identifier for you mouse button 1. quit is the callback called by the label upon receiving the event mouse1 click. Note that the parameter given to your quit callback is the event. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From auriocus at gmx.de Fri Dec 6 13:03:19 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 06 Dec 2013 19:03:19 +0100 Subject: [newbie] problem trying out simple non object oriented use of Tkinter In-Reply-To: References: <94a9c18f-595d-486a-96b5-d0f9f57824ba@googlegroups.com> Message-ID: Am 06.12.13 14:12, schrieb Jean Dubois: > It works but it's not all clear to me. Can you tell me what "label.bind("<1>", quit)" is standing for? What's the <1> meaning? "bind" connects events sent to the label with a handler. The <1> is the event description; in this case, it means a click with the left mouse button. The mouse buttons are numbered 1,2,3 for left,middle,right, respectively (with right and middle switched on OSX, confusingly). It is actually short for Binding to the key "1" would look like this The event syntax is rather complex, for example it is possible to add modifiers to bind to a Shift-key + right click like this It is described in detail at the bind man page of Tk. http://www.tcl.tk/man/tcl8.6/TkCmd/bind.htm The event object passed to the handler contains additional information, for instance the position of the mouse pointer on the screen. In practice, for large parts of the interface you do not mess with the keyboard and mouse events directly, but use the corresponding widgets. In your program, the label works as a simple pushbutton, and therefore a button should be used. #!/usr/bin/env python import Tkinter as tk import ttk # for modern widgets import sys # no underscore - nothing gets passed def quit(): sys.exit() root = tk.Tk() button = ttk.Button(root, text="Click mouse here to quit", command=quit) button.pack() root.mainloop() note, that 1) nothing gets passed, so we could have left out changing quit(). This is because a button comand usually does not care about details of the mouse click. It just reacts as the user expects. 2) I use ttk widgets, which provide native look&feel. If possible, use those. Good examples on ttk usage are shown at http://www.tkdocs.com/tutorial/index.html HTH, Christia From breamoreboy at yahoo.co.uk Fri Dec 6 12:03:13 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 17:03:13 +0000 Subject: interactive help on the base object Message-ID: Is it just me, or is this basically useless? >>> help(object) Help on class object in module builtins: class object | The most base type >>> Surely a few more words, or a pointer to this http://docs.python.org/3/library/functions.html#object, would be better? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Fri Dec 6 20:35:15 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Dec 2013 20:35:15 -0500 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 12/6/2013 12:03 PM, Mark Lawrence wrote: > Is it just me, or is this basically useless? > > >>> help(object) > Help on class object in module builtins: > > class object > | The most base type Given that this can be interpreted as 'least desirable', it could definitely be improved. > Surely a few more words, How about something like. '''The default top superclass for all Python classes. Its methods are inherited by all classes unless overriden. ''' When you have 1 or more concrete suggestions for the docstring, open a tracker issue. > or a pointer to this > http://docs.python.org/3/library/functions.html#object, would be better? URLs don't belong in docstrings. People should know how to find things in the manual index. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sun Dec 8 18:48:57 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Dec 2013 23:48:57 +0000 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 07/12/2013 01:35, Terry Reedy wrote: > On 12/6/2013 12:03 PM, Mark Lawrence wrote: >> Is it just me, or is this basically useless? >> >> >>> help(object) >> Help on class object in module builtins: >> >> class object >> | The most base type > > Given that this can be interpreted as 'least desirable', it could > definitely be improved. > >> Surely a few more words, > > How about something like. > > '''The default top superclass for all Python classes. > > Its methods are inherited by all classes unless overriden. > ''' > > When you have 1 or more concrete suggestions for the docstring, open a > tracker issue. > Terry's suggestion above remains odds on favourite on the grounds that there have been no other suggestions. I'll give it another day, then raise a tracker issue, unless the overwhelming smell of pot that has been drifting around this thread knocks me unconscious. -- 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 Sun Dec 8 19:45:48 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 9 Dec 2013 00:45:48 +0000 (UTC) Subject: interactive help on the base object References: Message-ID: On Sun, 08 Dec 2013 23:48:57 +0000, Mark Lawrence wrote: >>> >>> help(object) >>> Help on class object in module builtins: >>> >>> class object >>> | The most base type >> '''The default top superclass for all Python classes. >> Its methods are inherited by all classes unless overriden. >> ''' > Terry's suggestion above remains odds on favourite on the grounds that > there have been no other suggestions. I'll give it another day, then > raise a tracker issue, unless the overwhelming smell of pot that has > been drifting around this thread knocks me unconscious. """ The root class for all Python classes. Its methods are inherited by all classes unless overriden. """ -- Denis McMahon, denismfmcmahon at gmail.com From dreamingforward at gmail.com Sun Dec 8 20:09:32 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 8 Dec 2013 17:09:32 -0800 Subject: interactive help on the base object In-Reply-To: References: Message-ID: >>>> >>> help(object) >>>> Help on class object in module builtins: >>>> >>>> class object >>>> | The most base type > >>> '''The default top superclass for all Python classes. >>> Its methods are inherited by all classes unless overriden. >>> ''' > > """ The root class for all Python classes. Its methods are inherited by > all classes unless overriden. """ *sits back*. -- MarkJ Tacoma, Washington From breamoreboy at yahoo.co.uk Sun Dec 8 20:38:25 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 01:38:25 +0000 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 09/12/2013 01:09, Mark Janssen wrote: >>>>> >>> help(object) >>>>> Help on class object in module builtins: >>>>> >>>>> class object >>>>> | The most base type >> >>>> '''The default top superclass for all Python classes. >>>> Its methods are inherited by all classes unless overriden. >>>> ''' >> >> """ The root class for all Python classes. Its methods are inherited by >> all classes unless overriden. """ > > *sits back*. > Why? If a newbie is encouraged, as everybody is, to use help at the interactive prompt, then surely them seeing "The most base type" when typing "help(object)" is of no use to them at all. -- 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 Sun Dec 8 20:43:43 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 01:43:43 +0000 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 09/12/2013 00:45, Denis McMahon wrote: > On Sun, 08 Dec 2013 23:48:57 +0000, Mark Lawrence wrote: > >>>> >>> help(object) >>>> Help on class object in module builtins: >>>> >>>> class object >>>> | The most base type > > >>> '''The default top superclass for all Python classes. >>> Its methods are inherited by all classes unless overriden. >>> ''' > >> Terry's suggestion above remains odds on favourite on the grounds that >> there have been no other suggestions. I'll give it another day, then >> raise a tracker issue, unless the overwhelming smell of pot that has >> been drifting around this thread knocks me unconscious. > > """ The root class for all Python classes. Its methods are inherited by > all classes unless overriden. """ > Thanks Denis, you've reminded me why I asked in the first place. What methods, if any does it provide? Are they all abstract? etc??? Personally I'm not really interested, but a newbie might well be and hence might wonder what the hell is going on. If and only if the situation can be improved I'll raise an issue, if not I'll quietly let it drop, and consider more important things, like why are Australia currently thrashing England at cricket? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Mon Dec 9 00:00:53 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Dec 2013 00:00:53 -0500 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 12/8/2013 8:43 PM, Mark Lawrence wrote: > On 09/12/2013 00:45, Denis McMahon wrote: >> On Sun, 08 Dec 2013 23:48:57 +0000, Mark Lawrence wrote: >> >>>>> >>> help(object) >>>>> Help on class object in module builtins: >>>>> >>>>> class object >>>>> | The most base type >> >> >>>> '''The default top superclass for all Python classes. >>>> Its methods are inherited by all classes unless overriden. >>>> ''' I said 'top' instead of 'bottom' or 'base' to loosen up thinking a bit. I did not expect Mark to make a mound out of that flip. >>> Terry's suggestion above remains odds on favourite on the grounds that >>> there have been no other suggestions. I'll give it another day, then >>> raise a tracker issue, unless the overwhelming smell of pot that has >>> been drifting around this thread knocks me unconscious. >> >> """ The root class for all Python classes. Its methods are inherited by >> all classes unless overriden. """ 'Root' is even better, since it does not depend on whether a tree is drawn up or down. Thanks. > Thanks Denis, you've reminded me why I asked in the first place. What > methods, if any does it provide? Good question. >>> dir(object) ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] > Are they all abstract? etc??? No. > Personally I'm not really interested, but a newbie might well be and > hence might wonder what the hell is going on. For everything else, help lists the special name methods directly associated with the object, along with docstrings. >>> help(C) Help on class C in module __main__: class C(builtins.object) | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) I think help should do the same for object >>> object.__hash__.__doc__ 'x.__hash__() <==> hash(x)' is equivalent to | __abs__(...) | x.__abs__() <==> abs(x) etc printed for help(int) The fact that __dict__ does not exist for object but is only added for subclasses explains why one must subclass object to get instances that allow attributes. >>> o = object() >>> o.a = 1 Traceback (most recent call last): File "", line 1, in o.a = 1 AttributeError: 'object' object has no attribute 'a' >>> c = C() >>> c.a=1 > If and only if the > situation can be improved I'll raise an issue I think it can be. If you prefer me to open the issue, say so. We should look for existing issues, and closed issues that rejected change. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Mon Dec 9 18:48:33 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 23:48:33 +0000 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 09/12/2013 05:00, Terry Reedy wrote: > > I think it can be. If you prefer me to open the issue, say so. > We should look for existing issues, and closed issues that rejected change. > Thanks for the offer Terry and yes, please open an issue. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Sun Dec 8 21:31:52 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Dec 2013 02:31:52 GMT Subject: interactive help on the base object References: Message-ID: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> On Mon, 09 Dec 2013 01:43:43 +0000, Mark Lawrence wrote about object: > What methods, if any does it provide? Are they all abstract? etc??? Pretty much nothing useful :-) py> dir(object) ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] What few methods there are typically do nothing, or nothing interesting. A few implement basic functionality, e.g. __eq__ performs equality based on identity (an object is equal to itself and nothing else). -- Steven From dreamingforward at gmail.com Sun Dec 8 21:41:47 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 8 Dec 2013 18:41:47 -0800 Subject: interactive help on the base object In-Reply-To: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: >> What methods, if any does it provide? Are they all abstract? etc??? > > Pretty much nothing useful :-) > > py> dir(object) > [...] > So (prodding the student), Why does everything inherit from Object if it provides no functionality? Practicality-beats-purity-yours? -- MarkJ Tacoma, Washington From rosuav at gmail.com Sun Dec 8 21:57:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 13:57:28 +1100 Subject: interactive help on the base object In-Reply-To: References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Dec 9, 2013 at 1:41 PM, Mark Janssen wrote: >>> What methods, if any does it provide? Are they all abstract? etc??? >> >> Pretty much nothing useful :-) >> >> py> dir(object) >> [...] >> > > So (prodding the student), Why does everything inherit from Object if > it provides no functionality? > > Practicality-beats-purity-yours? Nothing useful to call directly. An int has some useful methods in Python: >>> (258).to_bytes(2,"little") b'\x02\x01' So does a list: >>> [1,4,1,5,9].count(1) 2 But there's nothing you'd normally want to call from object itself (except maybe __repr__). There *are*, however, important pieces of default functionality. Steven mentioned __eq__, and there's also its pair __hash__. The default system works because the root type provides implementations of those two functions: >>> a = object() >>> b = object() >>> a == b False >>> d = {a:"A", b:"B"} >>> d[a] 'A' And it's important that these sorts of things work, because otherwise a simple Python class would look like this: class Foo: def __new__(self): pass def __init__(self): pass def __hash__(self): return id(self) def __eq__(self, other): return self is other # ... This repetition is exactly what inheritance is good at solving. Therefore putting that functionality into a base class makes sense; and since everything MUST have these functions to be able to be used plausibly, putting them in the lowest base class of all makes the most sense. ChrisA From rustompmody at gmail.com Sun Dec 8 21:58:09 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 18:58:09 -0800 (PST) Subject: interactive help on the base object In-Reply-To: References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: On Monday, December 9, 2013 8:11:47 AM UTC+5:30, zipher wrote: > >> What methods, if any does it provide? Are they all abstract? etc??? > > Pretty much nothing useful :-) > > py> dir(object) > > [...] > So (prodding the student), Why does everything inherit from Object if > it provides no functionality? Thats right. What does a collection object like [] or the empty set ? (assuming the unicode-gods will allow and bless that) do when it collects nothing? Lets make sure all lists and sets start non-empty. And why have a stupid number like 0 when it counts nothing? Lets go back to roman numerals which is so much more? > Practicality-beats-purity-yours? Practical!!??? PS Can some kind soul inform me whether I could convince GG to unicode my post? From steve at pearwood.info Sun Dec 8 23:16:30 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Dec 2013 04:16:30 GMT Subject: interactive help on the base object References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: <52a5441e$0$2762$c3e8da3$76491128@news.astraweb.com> On Sun, 08 Dec 2013 18:58:09 -0800, rusi wrote: > PS Can some kind soul inform me whether I could convince GG to unicode > my post? Does GG not give you some way of inspecting the post's full headers? Anyway, here you go: Content-Type: text/plain; charset=UTF-8 Your plan succeeded. Personally, I wouldn't stress too much about this. While it would be nice, and desirable, for GG to always use UTF-8 instead of picking a different encoding based on the phase of the moon, the main thing is that it picks a valid encoding. So far I see no reason to accuse GG of using an invalid encoding. Valid but legacy encodings are better than mojibake :-) -- Steven From rustompmody at gmail.com Sun Dec 8 23:46:35 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 20:46:35 -0800 (PST) Subject: interactive help on the base object In-Reply-To: <52a5441e$0$2762$c3e8da3$76491128@news.astraweb.com> References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a5441e$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: <182d6303-4095-45ce-9b69-04de33e058af@googlegroups.com> Thanks for the info. On Monday, December 9, 2013 9:46:30 AM UTC+5:30, Steven D'Aprano wrote: > On Sun, 08 Dec 2013 18:58:09 -0800, rusi wrote: > > PS Can some kind soul inform me whether I could convince GG to unicode > > my post? > Does GG not give you some way of inspecting the post's full headers? Well I spent half hour looking around -- both inside GG and of course searching before asking. > Anyway, here you go: > Content-Type: text/plain; charset=UTF-8 > Your plan succeeded. > Personally, I wouldn't stress too much about this. While it would be > nice, and desirable, for GG to always use UTF-8 instead of picking a > different encoding based on the phase of the moon, the main thing is that > it picks a valid encoding. So far I see no reason to accuse GG of using > an invalid encoding. Valid but legacy encodings are better than > mojibake :-) Heh! I'm hardly a heavy-duty user of unicode -- just keeping track of bugs and workarounds. I am of course using 'bug' in a wide pragmatic sense of preventing communication. Mojibake is a technical problem. Non (human) communication is a more fundamental problem. Keeping an eye on the latter is (for me) a bigger issue than the former. From rurpy at yahoo.com Mon Dec 9 00:26:28 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 8 Dec 2013 21:26:28 -0800 (PST) Subject: interactive help on the base object In-Reply-To: <182d6303-4095-45ce-9b69-04de33e058af@googlegroups.com> References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a5441e$0$2762$c3e8da3$76491128@news.astraweb.com> <182d6303-4095-45ce-9b69-04de33e058af@googlegroups.com> Message-ID: <1ef797ae-3439-46b5-842e-61e17135d9bf@googlegroups.com> On 12/08/2013 09:46 PM, rusi wrote: > On Monday, December 9, 2013 9:46:30 AM UTC+5:30, Steven D'Aprano wrote: >> On Sun, 08 Dec 2013 18:58:09 -0800, rusi wrote: >[...] >> Does GG not give you some way of inspecting the post's full headers? > > Well I spent half hour looking around -- both inside GG and of course > searching before asking. If you click on the little "down" triangle to the right of the "reply" button for a message, you'll get a menu that includes "Show Original". You can see the headers including the "Content-Type:" in that original. Of course this means you have to post first and find out after... From rustompmody at gmail.com Mon Dec 9 01:44:28 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 22:44:28 -0800 (PST) Subject: interactive help on the base object In-Reply-To: <1ef797ae-3439-46b5-842e-61e17135d9bf@googlegroups.com> References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a5441e$0$2762$c3e8da3$76491128@news.astraweb.com> <182d6303-4095-45ce-9b69-04de33e058af@googlegroups.com> <1ef797ae-3439-46b5-842e-61e17135d9bf@googlegroups.com> Message-ID: On Monday, December 9, 2013 10:56:28 AM UTC+5:30, ru... at yahoo.com wrote: > On 12/08/2013 09:46 PM, rusi wrote: > > On Monday, December 9, 2013 9:46:30 AM UTC+5:30, Steven D'Aprano wrote: > >> On Sun, 08 Dec 2013 18:58:09 -0800, rusi wrote: > >[...] > >> Does GG not give you some way of inspecting the post's full headers? > > Well I spent half hour looking around -- both inside GG and of course > > searching before asking. > If you click on the little "down" triangle to the right > of the "reply" button for a message, you'll get a menu > that includes "Show Original". You can see the headers > including the "Content-Type:" in that original. Thanks rurpy -- I only looked for how one may set and not just what is. So now I look at my own post in GG and see Content-Type: text/plain; charset=UTF-8 So far so good. However when I point firefox at my own post in the archive https://mail.python.org/pipermail/python-list/2013-December/662015.html firefox shows encoding as Windows-1252. Note Ive looked at a dozen random pages and for all FF shows encoding as utf-8 except the python list archive ones which show as Win 1252 Note looking into the html I see How us-ascii becomes Win-1252 is outside the reach of my meagre intelligence! Though I still suspect something is not quite right with the python mailing-list and/or archive in respect of char encodings. [Am I beginning to sound like jmf is my guru :-) ] From breamoreboy at yahoo.co.uk Mon Dec 9 04:44:48 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 09:44:48 +0000 Subject: interactive help on the base object In-Reply-To: References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a5441e$0$2762$c3e8da3$76491128@news.astraweb.com> <182d6303-4095-45ce-9b69-04de33e058af@googlegroups.com> <1ef797ae-3439-46b5-842e-61e17135d9bf@googlegroups.com> Message-ID: On 09/12/2013 06:44, rusi wrote: > On Monday, December 9, 2013 10:56:28 AM UTC+5:30, ru... at yahoo.com wrote: >> On 12/08/2013 09:46 PM, rusi wrote: >>> On Monday, December 9, 2013 9:46:30 AM UTC+5:30, Steven D'Aprano wrote: >>>> On Sun, 08 Dec 2013 18:58:09 -0800, rusi wrote: >>> [...] >>>> Does GG not give you some way of inspecting the post's full headers? >>> Well I spent half hour looking around -- both inside GG and of course >>> searching before asking. > >> If you click on the little "down" triangle to the right >> of the "reply" button for a message, you'll get a menu >> that includes "Show Original". You can see the headers >> including the "Content-Type:" in that original. > > Thanks rurpy -- I only looked for how one may set and not just what is. > > So now I look at my own post in GG and see > > Content-Type: text/plain; charset=UTF-8 > > So far so good. > > However when I point firefox at my own post in the archive > https://mail.python.org/pipermail/python-list/2013-December/662015.html > > firefox shows encoding as Windows-1252. > > Note Ive looked at a dozen random pages and for all FF shows encoding as > utf-8 except the python list archive ones which show as Win 1252 > > Note looking into the html I see > > > How us-ascii becomes Win-1252 is outside the reach of my meagre intelligence! > > Though I still suspect something is not quite right with the python > mailing-list and/or archive in respect of char encodings. > > [Am I beginning to sound like jmf is my guru :-) ] > I'd mention that I never seem to have a problem using Thunderbird on Windows 7, but I won't as I don't want to be accused of bullying, hating GG, or whatever. Doh!!! :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Mon Dec 9 00:44:34 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Dec 2013 05:44:34 GMT Subject: interactive help on the base object References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: <52a558c2$0$2762$c3e8da3$76491128@news.astraweb.com> On Sun, 08 Dec 2013 18:41:47 -0800, Mark Janssen wrote: >>> What methods, if any does it provide? Are they all abstract? etc??? >> >> Pretty much nothing useful :-) >> >> py> dir(object) >> [...] >> >> > So (prodding the student), Why does everything inherit from Object if it > provides no functionality? You cut out the part of my post where I explained that object does in fact provide a minimal set of useful functionality. The example I gave was __eq__ (equal), but there is also __ne__ (not equal), __hash__ (hashing), __str__ and __repr__ (although many classes will wish to override them) and a few more. They're useful, even necessary, but hardly exciting. The other reasons for inheriting from object include: - If all classes are part of a single hierarchy, it must logically end at one (or more, if you support multiple inheritance, which Python does) bases classes. (Unless there are loops, which are generally prohibited in all OOP systems I know of). The simplest way to do this is with a single base class. - Pragmatism: it was the easiest way to unify types and classes way back in Python 2.2, prior to which there was no single hierarchy and all classes were (in a sense) distinct. Pedants will of course realise that Python 2 has *two* object hierarchies, classic classes which don't share a base class, and types (a.k.a. "new style classes") which do. In Python 3, classic classes are gone, and there is a single class hierarchy with object the base. There may be other reasons. -- Steven From alan at scooby-doo.csail.mit.edu Mon Dec 9 02:31:00 2013 From: alan at scooby-doo.csail.mit.edu (Alan Bawden) Date: Mon, 09 Dec 2013 02:31:00 -0500 Subject: interactive help on the base object References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a558c2$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: Steven D'Aprano writes: > - If all classes are part of a single hierarchy, it must logically end at > one (or more, if you support multiple inheritance, which Python does) > bases classes. (Unless there are loops, which are generally prohibited in > all OOP systems I know of). The simplest way to do this is with a single > base class. The original Lisp Machine "Flavors" system (one of the ancestors of the Common Lisp Object System) allowed inheritance to be an arbitrary directed graph -- possibly with cycles. I don't believe that this was done for any deep principled reason, but rather it was just permitted because the algorithm for computing method resolution order didn't actually care whether there were inheritance cycles -- it still terminated and returned an ordered list of component classes. I do not remember seeing any code that made use of this ability, so don't ask me if it was good for anything, but it was definitely there... -- Alan Bawden From rosuav at gmail.com Mon Dec 9 02:39:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 18:39:21 +1100 Subject: interactive help on the base object In-Reply-To: References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a558c2$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Dec 9, 2013 at 6:31 PM, Alan Bawden wrote: > I don't believe that this was done for any deep principled reason, but > rather it was just permitted because the algorithm for computing method > resolution order didn't actually care whether there were inheritance > cycles -- it still terminated and returned an ordered list of component > classes. How does that work, exactly? How do you have a class inherit (ultimately) from itself, and how does that impact the component class list? ChrisA From alan at scooby-doo.csail.mit.edu Tue Dec 10 00:34:05 2013 From: alan at scooby-doo.csail.mit.edu (Alan Bawden) Date: Tue, 10 Dec 2013 00:34:05 -0500 Subject: interactive help on the base object References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a558c2$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: Chris Angelico writes: > How does that work, exactly? How do you have a class inherit > (ultimately) from itself, and how does that impact the component class > list? How does it work "exactly"? You're asking me about a feature I never made use of, in a system I have no source for, and that I haven't used in over 25 years! If it wasn't mentioned in a parenthetical comment in the 32-year-old documentation I still have on my bookshelf (Lisp Machine Manual, 4th edition, July 1981, blue cover), I wouldn't trust my own memory that such a thing ever even existed. So you're not getting anything "exact" here! I have no idea exactly how it worked, but imagine something that walked the superclass graph _as_ _if_ it was a tree, collected classes in some order, and that just skips any class it encounters for the second time. That results in _some_ linear ordering of all the classes you can reach from the starting class. Now use that. Now the results aren't going to be very good by modern standards. As the Common Lisp Object System, Dylan, Python, and others, have all discovered, you really want something that is at _least_ a topological sort of the superclass graph -- and there is no topological sort at all unless your superclass graph is acyclic. But even if the results aren't up to modern standards, you can write a hell of a lot of code before the deficiencies have hurt enough people enough times to motivate you to do better. After all modern Python classes didn't start using their current ordering until Python 2.3. -- Alan Bawden From rosuav at gmail.com Tue Dec 10 00:44:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 16:44:48 +1100 Subject: interactive help on the base object In-Reply-To: References: <52a52b98$0$2762$c3e8da3$76491128@news.astraweb.com> <52a558c2$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Dec 10, 2013 at 4:27 PM, Alan Bawden wrote: > Chris Angelico writes: > >> On Mon, Dec 9, 2013 at 6:31 PM, Alan Bawden >> ... >> How does that work, exactly? How do you have a class inherit >> (ultimately) from itself, and how does that impact the component class >> list? > > How does it work "exactly"? You're asking me about a feature I never > made use of, in a system I have no source for, and that I haven't used > in over 25 years! If it wasn't mentioned in a parenthetical comment in > the 32-year-old documentation I still have on my bookshelf (Lisp Machine > Manual, 4th edition, July 1981, blue cover), I wouldn't trust my own > memory that such a thing ever even existed. > > So you're not getting anything "exact" here! LOL! > I have no idea exactly how it worked, but imagine something that walked > the superclass graph _as_ _if_ it was a tree, collected classes in some > order, and that just skips any class it encounters for the second time. > That results in _some_ linear ordering of all the classes you can reach > from the starting class. Now use that. Ow, that sounds a bit... weird. I think I prefer an acyclic graph for inheritance! A few weirdnesses are necessary for bootstrapping - type(object) is type, type(type) is type, and type.__bases__ = (object,) - but normally every type should be created before all instances of it, and every superclass before all its subclasses. But of course, *multiple* inheritance is always weird. I've worked in some detail with four systems (C++, Python, Pike, Java), and they're all quite different in how they handle MI. Java says "There is no MI... but you can implement multiple interfaces". C++ says "There is MI and there is virtual MI, and if one of them doesn't do your head in, the other will". Python says "It's all about method resolution, instance data is separate, so make sure everything cooperates". Pike says "If both parents define a method, super() will return an array of methods, but that's okay because arrays are callable". It's a fundamentally tricky problem, largely because every real-world analogy we can muster is going to end up looking more like composition than inheritance (a guided missile is-a bomb and is-a rocket, but it's just as valid to say it is-a rocket and it has-a bomb). ChrisA From steve at pearwood.info Sun Dec 8 20:58:26 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Dec 2013 01:58:26 GMT Subject: interactive help on the base object References: Message-ID: <52a523c1$0$2762$c3e8da3$76491128@news.astraweb.com> On Sun, 08 Dec 2013 23:48:57 +0000, Mark Lawrence wrote: > Terry's suggestion above remains odds on favourite on the grounds that > there have been no other suggestions. I'll give it another day, then > raise a tracker issue, It's not merely the default superclass, it *is* the superclass to everything. In Python 3, you cannot create an object that doesn't derive from object. (At least not in pure Python -- perhaps you could do so in a C extension class?) "Top" is misleading, because it assumes that class diagrams are always drawn with ancestors at the top and descendants at the bottom. No need to say that methods are inherited unless overridden, it goes without saying that you can override methods. object: The most fundamental base class for all Python classes and the root of the class inheritance hierarchy. All classes inherit from object. -- Steven From greg.ewing at canterbury.ac.nz Sat Dec 7 19:10:37 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 08 Dec 2013 13:10:37 +1300 Subject: interactive help on the base object In-Reply-To: References: Message-ID: Mark Lawrence wrote: > Is it just me, or is this basically useless? > > class object > | The most base type It's also a somewhat strange construction from an English language point of view. To make sense, it requires interpreting the word "base" as an adjective, and when used that way it has connotations of something to turn your nose up at. I'm assuming that's not the impression we want to give! Maybe something like "The ultimate base class of all classes" would be better. -- Greg From ned at nedbatchelder.com Sat Dec 7 19:59:26 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 07 Dec 2013 19:59:26 -0500 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 12/7/13 7:10 PM, Gregory Ewing wrote: > Mark Lawrence wrote: >> Is it just me, or is this basically useless? >> >> class object >> | The most base type > > It's also a somewhat strange construction from an English language > point of view. To make sense, it requires interpreting the word > "base" as an adjective, and when used that way it has connotations > of something to turn your nose up at. I'm assuming that's not the > impression we want to give! > > Maybe something like "The ultimate base class of all classes" > would be better. > I've heard this described as "the root of the class hierarchy." -- Ned Batchelder, http://nedbatchelder.com From dreamingforward at gmail.com Sat Dec 7 23:21:06 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sat, 7 Dec 2013 20:21:06 -0800 Subject: interactive help on the base object In-Reply-To: References: Message-ID: >>> Is it just me, or is this basically useless? >>> >>> class object >>> | The most *base* type >> [[Terry Reedy:]] > How about something like. > The default top *superclass* for all Python classes. How 'bout you foos just admit that you didn't realize you've been confused this whole time? (It *is* possible isn't it?) Mr. Ewing says "base" has to be interpreted as an *adjective* because otherwise it would mean the BOTTOM (like the BASE of the pyramid), while Terry responds that it is the TOP (*super*class). Earlier, Steven D'Aprano wanted to argue that this distinction was irrelevant, but obviously it can't very well be both at once now cannit? Could-the-world-be-so-crazy-confused-and-then-shoot-the-messenger? Sadly, yes. MarkJ Tacoma, Washington From ned at nedbatchelder.com Sun Dec 8 07:11:35 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 08 Dec 2013 07:11:35 -0500 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 12/7/13 11:21 PM, Mark Janssen wrote: >>>> Is it just me, or is this basically useless? >>>> >>>> class object >>>> | The most *base* type >>> > [[Terry Reedy:]] >> How about something like. >> The default top *superclass* for all Python classes. > > How 'bout you foos just admit that you didn't realize you've been > confused this whole time? (It *is* possible isn't it?) Mark, if you want to participate in this forum, please refrain from opening with an insult. I've tried talking with you here in the past, and got nothing but sarcastic sneers and put-downs for my trouble. I gave you the benefit of the doubt, and believed that previous contentious points (no tokens on punched cards, initializing arrays to NaN, etc) were due to misunderstandings that could be worked out. You treated me with contempt and refused to discuss the details that would have let us understand each other. I know you have a theory that all of computer science has been confused for half a century. You expounded on this before, but haven't managed to explain your point clearly, and have not convinced anyone that you have a better model than the ones we're already using. Perhaps we are confused, and you have a better idea. I don't know yet, though frankly I doubt it. I'd be glad to learn about your ideas, but you have to present them seriously, and with some humility, to get them to spread. So far, repeated attempts to get details from you have failed. > > Mr. Ewing says "base" has to be interpreted as an *adjective* because > otherwise it would mean the BOTTOM (like the BASE of the pyramid), > while Terry responds that it is the TOP (*super*class). Earlier, > Steven D'Aprano wanted to argue that this distinction was irrelevant, > but obviously it can't very well be both at once now cannit? > > Could-the-world-be-so-crazy-confused-and-then-shoot-the-messenger? > > Sadly, yes. I'm sorry you feel martyred. It's not because you bring truth to crazy-confused people. It's because you can't explain yourself, and you push people away with your style. We try hard to treat each other with respect, and I'll ask you to do the same. > > MarkJ > Tacoma, Washington > -- Ned Batchelder, http://nedbatchelder.com From steve+comp.lang.python at pearwood.info Sun Dec 8 05:33:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2013 10:33:32 GMT Subject: interactive help on the base object References: Message-ID: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Dec 2013 20:21:06 -0800, Mark Janssen wrote: >>>> Is it just me, or is this basically useless? >>>> >>>> class object >>>> | The most *base* type >>> > [[Terry Reedy:]] >> How about something like. >> The default top *superclass* for all Python classes. > > How 'bout you foos just admit that you didn't realize you've been > confused this whole time? (It *is* possible isn't it?) > > Mr. Ewing says "base" has to be interpreted as an *adjective* because > otherwise it would mean the BOTTOM (like the BASE of the pyramid), while > Terry responds that it is the TOP (*super*class). Earlier, Steven > D'Aprano wanted to argue that this distinction was irrelevant, What are you talking about? Until this very post, I haven't made any comments in this thread. > but obviously it can't very well be both at once now cannit? Of course it can. To people in the southern hemisphere, the South Pole is at the top of the world and the North Pole is at the bottom. For people in the northern hemisphere, it's the opposite, with the North Pole being "up" and the South Pole being "down". http://cdn.shopify.com/s/files/1/0071/5032/products/upside_down_world_map.png Family trees and other hierarchies, including class inheritance diagrams, have a *relative* direction not an absolute direction. We can all agree that Fred and Wilma are the parents of Pebbles, but it doesn't really matter whether we draw the family tree like this: Fred Wilma (diagrams best viewed in a fixed-width font | | like Courier, Monaco or Lucinda Typewriter) +----+----+ | Pebbles (inheritance goes *down* the page from ancestors to descendants) or like this: Pebbles | +----+----+ | | Fred Wilma (inheritance goes *up* the page from ancestors to descendants). What matters is the relationships between the entities, not the specific direction they are drawn in relative to some imaginary absolute space. Likewise it doesn't matter whether we draw class hierarchies from the top down or the bottom up or even sidewise: object --> int --> myint is the same as: myint <-- int <-- object Ironically, although it is conventional to draw the most distant ancestor at the *top* of the page, it is called the *base* or *root* of the tree. This Way Up || || || \ || / \||/ -- Steven From dreamingforward at gmail.com Sun Dec 8 18:01:59 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 8 Dec 2013 15:01:59 -0800 Subject: interactive help on the base object In-Reply-To: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Dec 8, 2013 at 2:33 AM, Steven D'Aprano wrote: > On Sat, 07 Dec 2013 20:21:06 -0800, Mark Janssen wrote: > >>>>> Is it just me, or is this basically useless? >>>>> >>>>> class object >>>>> | The most *base* type >>>> >> [[Terry Reedy:]] >>> How about something like. >>> The default top *superclass* for all Python classes. >> >> How 'bout you foos just admit that you didn't realize you've been >> confused this whole time? (It *is* possible isn't it?) >> >> Mr. Ewing says "base" has to be interpreted as an *adjective* because >> otherwise it would mean the BOTTOM (like the BASE of the pyramid), while >> Terry responds that it is the TOP (*super*class). Earlier, Steven >> D'Aprano wanted to argue that this distinction was irrelevant, > > What are you talking about? Until this very post, I haven't made any > comments in this thread. It was a few months ago. You do know what I'm talking about because you just expounded with the exact same argument below. It's like a broken record. (Now if *I* sound like a broken record, it's because no seems to see the obvious, but carry on.) >> but obviously it can't very well be both at once now cannit? > > Family trees and other hierarchies, including class inheritance diagrams, > have a *relative* direction not an absolute direction. We can all agree > that Fred and Wilma are the parents of Pebbles, but it doesn't really > matter whether we draw the family tree like this: > > > Fred Wilma (diagrams best viewed in a fixed-width font > | | like Courier, Monaco or Lucinda Typewriter) > +----+----+ > | > Pebbles > > > (inheritance goes *down* the page from ancestors to descendants) > > or like this: > > Pebbles > | > +----+----+ > | | > Fred Wilma > > > (inheritance goes *up* the page from ancestors to descendants). > > What matters is the relationships between the entities, not the specific > direction they are drawn in relative to some imaginary absolute space. > [yadda, yagni, yadda] But, there IS A DIFFERENCE. Let me explain the concept of a object model (or "type model" if you prefer). In a family inheritance tree, there is this difference -- called the "calendar" -- which imposes an ordering which can't be countermanded by flipping your silly chart around. You made a bullshit example to simply argue a point and *fooled yourself* into ignoring this. Yes? Likewise, WITH A COMPUTER, there is a definite order which can't be countermanded by simply having this artifice called "Object". If you FEE(L)s hadn't noticed (no longer using the insult "foo"s out of respect for the sensativities of the brogrammers), this artifice has just been *called on the floor* with this little innocent question that fired up this discussion again (don't hate the messenger). Again: people entering the community are pointing out a problem -- that Object is both trying to be the BASE and the SUPERclass of all objects. CS554: A type/object *model* has to define the relationship of these nice abstractions so that they can be mapped to the *actual concreteness* of the machine. And there, bro, there is an ordering. You're not going to magically flip the hierarchy so that your bitless Object becomes a machine word that is the base of all your types. You've been fooled by the magic of the Turing Machine. The modern computer mollifies you with the illusion of "total abstraction" where there are no bits or 1s and 0s involved, but yea, it did not turn out that way. (Note bene: as a comparison, C++ is very UNAMBIGUOUS about this fact -- all objects inherit from concrete machine types, which is why it remains important, *despite* being one of the worst to do OOP in. Its *type model* is probably the most clear of any object-oriented language). > Likewise it doesn't matter whether we draw class hierarchies from the top > down or the bottom up or even sidewise: Have you caught it by now, friends: IT MATTERS TO THE COMPUTER. With some apologies for Ned for attempting to be neutral. Apparently you guys are philosophers more than Computer Engineers. MarkJ Tacoma, Washington From rosuav at gmail.com Sun Dec 8 21:44:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 13:44:01 +1100 Subject: interactive help on the base object In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Dec 9, 2013 at 10:01 AM, Mark Janssen wrote: > (Note bene: as a comparison, C++ is very UNAMBIGUOUS about > this fact -- all objects inherit from concrete machine types, which is > why it remains important, *despite* being one of the worst to do OOP > in. Its *type model* is probably the most clear of any > object-oriented language). Factually wrong. In C++, it is actually *impossible* to inherit from a "concrete machine type", by which presumably you mean the classic types int/char/float etc. struct foo: public int { foo() {} }; 1.cpp:1:20: error: expected class-name before ?int? 1.cpp:1:20: error: expected ?{? before ?int? 1.cpp:2:1: error: expected unqualified-id before ?{? token Okay, that's a parse error. Maybe if we avoid the language keyword? typedef int integer; struct foo: public integer { foo() {} }; 1.cpp:4:1: error: expected class-name before ?{? token Nope. There are two completely different groups here: the basic types (called here [1] "Fundamental data types") and the structure types. The latter are created by the struct/class keyword and can use inheritance. The former... aren't. Not every C++ type is part of the type hierarchy. This is actually somewhat true of Python, too, but the set of types that are unavailable for inheritance is much smaller and less useful. You can't inherit from the 'function' type, for instance: >>> class foo(type(lambda:1)): pass Traceback (most recent call last): File "", line 1, in class foo(type(lambda:1)): TypeError: type 'function' is not an acceptable base type And yet inherits from class <'object'>, so it's not entirely outside in the way C++ int is. And I can apparently subclass module, though not generator, and unsurprisingly NoneType can't be inherited from. (Though you can instantiate it, and it's probably the only class that will appear to have no return value from instantiation.) C++ has you *compose* structs/classes from primitives, but this is not the same as inheritance. They're completely separate concepts. ChrisA [1] http://www.cplusplus.com/doc/tutorial/variables/ From dreamingforward at gmail.com Sun Dec 8 22:05:14 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 8 Dec 2013 19:05:14 -0800 Subject: interactive help on the base object In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Dec 8, 2013 at 6:44 PM, Chris Angelico wrote: > On Mon, Dec 9, 2013 at 10:01 AM, Mark Janssen wrote: >> (Note bene: as a comparison, C++ is very UNAMBIGUOUS about >> this fact -- all objects inherit from concrete machine types, which is >> why it remains important, *despite* being one of the worst to do OOP >> in. Its *type model* is probably the most clear of any >> object-oriented language). > > Factually wrong. In C++, it is actually *impossible* to inherit from a > "concrete machine type", by which presumably you mean the classic > types int/char/float etc. Wow, you guys trip me out, but I guess I've been working in a different universe where I was mapping classes into basic types (using generic programming along with typedef). I'm going to have to re-think all this confusion. But, in any case, if you don't have a way to map your abstract objects into machine types, you're working on magic, not computer science. MarkJ Tacoma, Washington From rosuav at gmail.com Sun Dec 8 22:17:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 14:17:05 +1100 Subject: interactive help on the base object In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Dec 9, 2013 at 2:05 PM, Mark Janssen wrote: > But, in any case, if you don't have a way to map your abstract objects > into machine types, you're working on magic, not computer science. Maybe, but that mapping isn't always an inheritance relationship. Ultimately the computer can't work with my data without it being represented in memory and in registers (at least in part - "relational database" could be considered a type, the full implementation of which is never actually loaded into memory), but the most common way to do this is effectively some form of composition. For instance, C++ has a type called "pair" (actually a template); what's the most obvious way to define the type "pair of integers"? Place the first integer, then place the second integer. The pair has two members, first and second. The pair isn't the first integer, nor is it the second integer. It doesn't make sense to inherit pair from integer, so you don't. You compose it of two integers. class Pair(object): # in C++, we'd need to declare these: # int first; # int second; def __init__(self, first, second): self.first, self.second = first, second Calling integer methods on a Pair makes no sense. Which of its members did you want to call that on? Both of them? (Wouldn't make sense if you had a mixed pair, like pair which could be a little awkward to try to fire().) You can't sensibly use a Pair in a context where an integer would be wanted, so it fails LSP. It composes, but does not inherit from, int. ChrisA From ian.g.kelly at gmail.com Mon Dec 9 05:12:12 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Dec 2013 03:12:12 -0700 Subject: interactive help on the base object In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Dec 8, 2013 at 4:01 PM, Mark Janssen wrote: > Likewise, WITH A COMPUTER, there is a definite order which can't be > countermanded by simply having this artifice called "Object". If you > FEE(L)s hadn't noticed (no longer using the insult "foo"s out of > respect for the sensativities of the brogrammers), this artifice has > just been *called on the floor* with this little innocent question > that fired up this discussion again (don't hate the messenger). > Again: people entering the community are pointing out a problem -- > that Object is both trying to be the BASE and the SUPERclass of all > objects. You're mixing two different terminologies. Whereas "superclass" contrasts with "subclass" and connotes an imaginary spatial relationship, "base" contrasts with "derived" (not "top"), which pairing does not suggest any spatial relationship at all. There is no inconsistency in that these two words happen to mean the same thing. >> Likewise it doesn't matter whether we draw class hierarchies from the top >> down or the bottom up or even sidewise: > > Have you caught it by now, friends: IT MATTERS TO THE COMPUTER. No, I'm pretty sure the computer doesn't care one whit whether the inheritance hierarchy that I scribble on a random sheet of paper happens to be represented as top-down, bottom-up, left-right, right-left, center-out, ana-kata, or using any other conceivable spatial relationship that I may have omitted. The computer only cares (inasmuch as I'm willing to personify it) about the actual *code* that I feed into it. How the programmer abstracts or visualizes that code is irrelevant. From breamoreboy at yahoo.co.uk Mon Dec 9 10:06:35 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 15:06:35 +0000 Subject: interactive help on the base object In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/12/2013 10:12, Ian Kelly wrote: > On Sun, Dec 8, 2013 at 4:01 PM, Mark Janssen wrote: >> Likewise, WITH A COMPUTER, there is a definite order which can't be >> countermanded by simply having this artifice called "Object". If you >> FEE(L)s hadn't noticed (no longer using the insult "foo"s out of >> respect for the sensativities of the brogrammers), this artifice has >> just been *called on the floor* with this little innocent question >> that fired up this discussion again (don't hate the messenger). >> Again: people entering the community are pointing out a problem -- >> that Object is both trying to be the BASE and the SUPERclass of all >> objects. > > You're mixing two different terminologies. Whereas "superclass" > contrasts with "subclass" and connotes an imaginary spatial > relationship, "base" contrasts with "derived" (not "top"), which > pairing does not suggest any spatial relationship at all. There is no > inconsistency in that these two words happen to mean the same thing. > >>> Likewise it doesn't matter whether we draw class hierarchies from the top >>> down or the bottom up or even sidewise: >> >> Have you caught it by now, friends: IT MATTERS TO THE COMPUTER. > > No, I'm pretty sure the computer doesn't care one whit whether the > inheritance hierarchy that I scribble on a random sheet of paper > happens to be represented as top-down, bottom-up, left-right, > right-left, center-out, ana-kata, or using any other conceivable > spatial relationship that I may have omitted. The computer only cares > (inasmuch as I'm willing to personify it) about the actual *code* that > I feed into it. How the programmer abstracts or visualizes that code > is irrelevant. > MASCOT is the One True Way http://en.wikipedia.org/wiki/Modular_Approach_to_Software_Construction_Operation_and_Test -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Mon Dec 9 00:11:58 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Dec 2013 05:11:58 GMT Subject: interactive help on the base object References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> On Sun, 08 Dec 2013 15:01:59 -0800, Mark Janssen wrote: > On Sun, Dec 8, 2013 at 2:33 AM, Steven D'Aprano > wrote: >> On Sat, 07 Dec 2013 20:21:06 -0800, Mark Janssen wrote: >> >>>>>> Is it just me, or is this basically useless? >>>>>> >>>>>> class object >>>>>> | The most *base* type >>>>> >>> [[Terry Reedy:]] >>>> How about something like. >>>> The default top *superclass* for all Python classes. >>> >>> How 'bout you foos just admit that you didn't realize you've been >>> confused this whole time? (It *is* possible isn't it?) >>> >>> Mr. Ewing says "base" has to be interpreted as an *adjective* because >>> otherwise it would mean the BOTTOM (like the BASE of the pyramid), >>> while Terry responds that it is the TOP (*super*class). Earlier, >>> Steven D'Aprano wanted to argue that this distinction was irrelevant, >> >> What are you talking about? Until this very post, I haven't made any >> comments in this thread. > > It was a few months ago. You do know what I'm talking about because you > just expounded with the exact same argument below. It's like a broken > record. While I am gratified that you apparently memorise and obsess over things I wrote months ago, I'm sorry to tell you that I wasn't lying when I said that I didn't know what you were talking about. I had no idea that you were referring to a completely different conversation, nor do I recall every post I write here. If I repeated the same argument, it is because the argument is still valid. Drawing the root of the tree at the top of the page is just a convention, just driving on the left side of the road, or calling the elected head of state "Prime Minister". There are other ways to do such things which are equally valid, and so long as both parties agree on the convention, it doesn't matter whether you write from left-to-right like in Australia, right-to-left like in Egypt, or alternate like in Israel. > (Now if *I* sound like a broken record, it's because no seems > to see the obvious, but carry on.) It must be such a trial to be the only sane man in a world gone mad. [...] >> What matters is the relationships between the entities, not the >> specific direction they are drawn in relative to some imaginary >> absolute space. [yadda, yagni, yadda] > > But, there IS A DIFFERENCE. Let me explain the concept of a object > model (or "type model" if you prefer). > > In a family inheritance tree, there is this difference -- called the > "calendar" -- which imposes an ordering which can't be countermanded by > flipping your silly chart around. You made a bullshit example to simply > argue a point and *fooled yourself* into ignoring this. Yes? No. You haven't explained anything, you have merely made an assertion with no supporting evidence at all. In a family tree of ancestors and descendants, the relationship being draw is time-based. Ancestors exist before descendants. Descendants are derived in some way from ancestors, not the other way around. We all agree that your father existed before you. The temporal direction of the relationship is absolutely fixed, past before present, ancestors before descendants. We can agree on this. Explain to me this: what (apart from mere human convention) imposes the ordering "past must be at the top of the page"? If you are reading this as email, your mail client very likely has an option to sort message in order that they were received, either most- recent at the top or oldest at the top. Do you really mean to imply that one of those is logical and the other is delusional? > Likewise, WITH A COMPUTER, there is a definite order which can't be > countermanded by simply having this artifice called "Object". If you > FEE(L)s hadn't noticed (no longer using the insult "foo"s out of respect > for the sensativities of the brogrammers), this artifice has just been > *called on the floor* with this little innocent question that fired up > this discussion again (don't hate the messenger). Again: people > entering the community are pointing out a problem -- that Object is both > trying to be the BASE and the SUPERclass of all objects. How is this a problem? They mean the same thing. A television is both an appliance and a device. object is both the base class and a superclass of all other classes. > CS554: A type/object *model* has to define the relationship of these > nice abstractions so that they can be mapped to the *actual > concreteness* of the machine. And there, bro, there is an ordering. Yes, the ordering is that the subclass is derived from the superclass. Nobody disputes that. But we can show that relationship using any convention we like: superclass -> subclass subclass <- superclass "superclass extended by subclass" "subclass extends superclass" superclass ? subclass subclass ? superclass Python syntax: class MySubclass(MySuperclass): ... Smalltalk syntax: MySuperclass :subclass #MySubclass Java syntax: class MySubclass extends MySuperclass {...} > You're not going to magically flip the hierarchy so that your bitless > Object becomes a machine word that is the base of all your types. You seem to be labouring under the delusion that inheritance, which is a high-level concept which only applies to objects, goes "all the way down" to low-level concepts like words and bits. Objects do not *inherit* from bits. They are *composed* of bits. > You've > been fooled by the magic of the Turing Machine. The modern computer > mollifies you with the illusion of "total abstraction" where there are > no bits or 1s and 0s involved, but yea, it did not turn out that way. > (Note bene: as a comparison, C++ is very UNAMBIGUOUS about this fact -- > all objects inherit from concrete machine types, which is why it remains > important, *despite* being one of the worst to do OOP in. Its *type > model* is probably the most clear of any object-oriented language). You haven't actually programmed in C++ have you? There's no shame in answering that you haven't. I've never programmed in C++. It's on my to-do list, after giving myself an appendectomy with a dull rusty knife and just ahead of buying the complete collection of Justin Bieber albums. But even I know that you cannot inherit from native types, on account that they aren't objects. >> Likewise it doesn't matter whether we draw class hierarchies from the >> top down or the bottom up or even sidewise: > > Have you caught it by now, friends: IT MATTERS TO THE COMPUTER. How the hell does the computer know which way I draw my class diagrams? -- Steven From ned at nedbatchelder.com Mon Dec 9 05:59:29 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 09 Dec 2013 05:59:29 -0500 Subject: interactive help on the base object In-Reply-To: <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: On 12/9/13 12:11 AM, Steven D'Aprano wrote: > On Sun, 08 Dec 2013 15:01:59 -0800, Mark Janssen wrote: > >> On Sun, Dec 8, 2013 at 2:33 AM, Steven D'Aprano >> wrote: >>> On Sat, 07 Dec 2013 20:21:06 -0800, Mark Janssen wrote: >>> >>>>>>> Is it just me, or is this basically useless? >>>>>>> >>>>>>> class object >>>>>>> | The most *base* type >>>>>> >>>> [[Terry Reedy:]] >>>>> How about something like. >>>>> The default top *superclass* for all Python classes. >>>> >>>> How 'bout you foos just admit that you didn't realize you've been >>>> confused this whole time? (It *is* possible isn't it?) >>>> >>>> Mr. Ewing says "base" has to be interpreted as an *adjective* because >>>> otherwise it would mean the BOTTOM (like the BASE of the pyramid), >>>> while Terry responds that it is the TOP (*super*class). Earlier, >>>> Steven D'Aprano wanted to argue that this distinction was irrelevant, >>> >>> What are you talking about? Until this very post, I haven't made any >>> comments in this thread. >> >> It was a few months ago. You do know what I'm talking about because you >> just expounded with the exact same argument below. It's like a broken >> record. > > While I am gratified that you apparently memorise and obsess over things > I wrote months ago, I'm sorry to tell you that I wasn't lying when I said > that I didn't know what you were talking about. I had no idea that you > were referring to a completely different conversation, nor do I recall > every post I write here. > > If I repeated the same argument, it is because the argument is still > valid. Drawing the root of the tree at the top of the page is just a > convention, just driving on the left side of the road, or calling the > elected head of state "Prime Minister". There are other ways to do such > things which are equally valid, and so long as both parties agree on the > convention, it doesn't matter whether you write from left-to-right like > in Australia, right-to-left like in Egypt, or alternate like in Israel. > > >> (Now if *I* sound like a broken record, it's because no seems >> to see the obvious, but carry on.) > > It must be such a trial to be the only sane man in a world gone mad. > > > [...] >>> What matters is the relationships between the entities, not the >>> specific direction they are drawn in relative to some imaginary >>> absolute space. [yadda, yagni, yadda] >> >> But, there IS A DIFFERENCE. Let me explain the concept of a object >> model (or "type model" if you prefer). >> >> In a family inheritance tree, there is this difference -- called the >> "calendar" -- which imposes an ordering which can't be countermanded by >> flipping your silly chart around. You made a bullshit example to simply >> argue a point and *fooled yourself* into ignoring this. Yes? > > No. You haven't explained anything, you have merely made an assertion > with no supporting evidence at all. > > In a family tree of ancestors and descendants, the relationship being > draw is time-based. Ancestors exist before descendants. Descendants are > derived in some way from ancestors, not the other way around. We all > agree that your father existed before you. The temporal direction of the > relationship is absolutely fixed, past before present, ancestors before > descendants. We can agree on this. > > Explain to me this: what (apart from mere human convention) imposes the > ordering "past must be at the top of the page"? > > If you are reading this as email, your mail client very likely has an > option to sort message in order that they were received, either most- > recent at the top or oldest at the top. Do you really mean to imply that > one of those is logical and the other is delusional? > > >> Likewise, WITH A COMPUTER, there is a definite order which can't be >> countermanded by simply having this artifice called "Object". If you >> FEE(L)s hadn't noticed (no longer using the insult "foo"s out of respect >> for the sensativities of the brogrammers), this artifice has just been >> *called on the floor* with this little innocent question that fired up >> this discussion again (don't hate the messenger). Again: people >> entering the community are pointing out a problem -- that Object is both >> trying to be the BASE and the SUPERclass of all objects. > > How is this a problem? They mean the same thing. > > A television is both an appliance and a device. object is both the base > class and a superclass of all other classes. > > >> CS554: A type/object *model* has to define the relationship of these >> nice abstractions so that they can be mapped to the *actual >> concreteness* of the machine. And there, bro, there is an ordering. > > Yes, the ordering is that the subclass is derived from the superclass. > Nobody disputes that. But we can show that relationship using any > convention we like: > > > superclass -> subclass > > subclass <- superclass > > "superclass extended by subclass" > > "subclass extends superclass" > > superclass > ? > subclass > > > subclass > ? > superclass > > > Python syntax: > class MySubclass(MySuperclass): ... > > > Smalltalk syntax: > MySuperclass :subclass #MySubclass > > > Java syntax: > class MySubclass extends MySuperclass {...} > > > >> You're not going to magically flip the hierarchy so that your bitless >> Object becomes a machine word that is the base of all your types. > > You seem to be labouring under the delusion that inheritance, which is a > high-level concept which only applies to objects, goes "all the way down" > to low-level concepts like words and bits. > > Objects do not *inherit* from bits. They are *composed* of bits. > > >> You've >> been fooled by the magic of the Turing Machine. The modern computer >> mollifies you with the illusion of "total abstraction" where there are >> no bits or 1s and 0s involved, but yea, it did not turn out that way. >> (Note bene: as a comparison, C++ is very UNAMBIGUOUS about this fact -- >> all objects inherit from concrete machine types, which is why it remains >> important, *despite* being one of the worst to do OOP in. Its *type >> model* is probably the most clear of any object-oriented language). > > You haven't actually programmed in C++ have you? > > There's no shame in answering that you haven't. I've never programmed in > C++. It's on my to-do list, after giving myself an appendectomy with a > dull rusty knife and just ahead of buying the complete collection of > Justin Bieber albums. But even I know that you cannot inherit from native > types, on account that they aren't objects. > > >>> Likewise it doesn't matter whether we draw class hierarchies from the >>> top down or the bottom up or even sidewise: >> >> Have you caught it by now, friends: IT MATTERS TO THE COMPUTER. > > How the hell does the computer know which way I draw my class diagrams? > > > And the cycle continues: 1. A thread mentions some fundamental aspect of computing. 2. Mark Janssen jumps in to hint that we are all confused, and he knows how things should really work, with no details. 3. The discussion expands to the point of Mark making some claim which sounds close to a truth, but seems actually wrong ("It matters to the computer"). 4. Reasonable people try to engage in an actual discussion of what was said. 5. (Coming next) Mark ignores the bulk of the discussion, picks out one detail, and continues making snide and incorrect remarks, skittering away from the light of reason. Maybe we could just not? -- Ned Batchelder, http://nedbatchelder.com From steve at pearwood.info Mon Dec 9 22:19:46 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Dec 2013 03:19:46 GMT Subject: interactive help on the base object References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> Message-ID: <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> On Mon, 09 Dec 2013 05:59:29 -0500, Ned Batchelder wrote: [...] > And the cycle continues: [...] > Maybe we could just not? A reasonable request, but just because it's reasonable doesn't mean it is a no-brainer that we shouldn't engage with Mark. While I'm very confident at this point that he is a crank, in the same category as circle-squarers, cold fusion proponents, pi-is-a-rational- number theorists, perpetual motion machine inventors, evolution or AGW Denialists[1], and other such obsessive examples of Dunning-Kruger, I'm not *totally* confident that he is a crank. Maybe he'll prove me wrong and actually learn something. Who knows, maybe *I'll* learn something! Even if Mark is a crank and beyond the reach of logic, reason or facts, and I'm 90% convinced his is, consider that he's not the only one reading this thread. If just one person learns something useful or new from a reply to Mark, I believe that it is worthwhile. I daresay that at some point I'll make the same decision as you, that the pain of answering Mark is not worth the benefit to readers, or perhaps that there aren't any readers who will learn something new. But I'm not there yet. (Perhaps I'm just slow.) Speaking of cranks, anyone unaware of the Crack-pot index should check it out: http://math.ucr.edu/home/baez/crackpot.html It's probably more entertaining for those who have actually spent time engaging with cranks in the sciences (e.g. Relativity Denialists) or mathematics. [1] A lot of people dislike the term Denialist. I justify it this way -- there is a difference between those who merely have doubts about the existence of something (say, evolution, global warming, the Holocaust, Operation Gladio, Shakespeare, etc.) and a Denialist. Those doubts don't even need to be *reasonable* doubts. If the person happens to be unknowledgeable (i.e. ignorant) about the subject in question, their doubts may be unreasonable relative to the state of knowledge. What matters is whether the person doing the doubting is reasonable. Denialists are cranks. Not all people who deny, dispute or question accepted knowledge are cranks. Normally the difference between a crank and a non-crank is relatively obvious. One very strong sign is to ask the question "what evidence would change your mind?". If the answer is either "no evidence at all will change my mind", or something which is impossible to satisfy (e.g. "I won't accept evolution until I see a chicken give birth to a human being"), then the person is a crank and hence the term Denialist is likely to be apt. -- Steven From rustompmody at gmail.com Mon Dec 9 23:32:06 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 9 Dec 2013 20:32:06 -0800 (PST) Subject: interactive help on the base object In-Reply-To: <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> Message-ID: <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> On Tuesday, December 10, 2013 8:49:46 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 09 Dec 2013 05:59:29 -0500, Ned Batchelder wrote: > [...] > > And the cycle continues: > [...] > > Maybe we could just not? Thanks Ned for your attempts at bringing some order and sense in these parts of the universe > A reasonable request, but just because it's reasonable doesn't mean it is > a no-brainer that we shouldn't engage with Mark. Some basic statistics Suppose a random variable X takes 2 values x and y with probabilities p and q=1-p. Then expected value of X E[X] = px + qy p = probability of some good result from an interaction q = 1-p = No good x = benefit value y = harm value > Even if Mark is a crank and beyond the reach of logic, reason or facts, > and I'm 90% convinced his is, consider that he's not the only one reading > this thread. So you are pegging 'no-good-probability' at 90% and so p at 10%. Ok lets accept these. And in the benefit value you include the possible benefit to Mark, to whoever engages with him and the random [no relation of random variable X] lurking reader. So far so good And in the harm-value y, are you including the harm done to the random reader from a disorderly, abusive, fruitless and almost completely OT conversation? > If just one person learns something useful or new from a > reply to Mark, I believe that it is worthwhile. And if 3 people drop out because the levels of bullshit have crossed their thresholds? [BTW: My statistics was never very strong and is now quite rusty. So... Whos that guy who recently added a stats module to python?? Cant remember his name... Maybe I should take some tuitions from him...] From steve at pearwood.info Tue Dec 10 00:10:27 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Dec 2013 05:10:27 GMT Subject: interactive help on the base object References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> Message-ID: <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> On Mon, 09 Dec 2013 20:32:06 -0800, rusi wrote: > On Tuesday, December 10, 2013 8:49:46 AM UTC+5:30, Steven D'Aprano > wrote: >> On Mon, 09 Dec 2013 05:59:29 -0500, Ned Batchelder wrote: > >> [...] >> > And the cycle continues: >> [...] > >> > Maybe we could just not? > > Thanks Ned for your attempts at bringing some order and sense in these > parts of the universe > >> A reasonable request, but just because it's reasonable doesn't mean it >> is a no-brainer that we shouldn't engage with Mark. > > Some basic statistics > > Suppose a random variable X takes 2 values x and y with probabilities p > and q=1-p. Then expected value of X > > E[X] = px + qy > > p = probability of some good result from an interaction Define "good result". > q = 1-p = No good Define "No good". > x = benefit value > y = harm value > >> Even if Mark is a crank and beyond the reach of logic, reason or facts, >> and I'm 90% convinced his is, consider that he's not the only one >> reading this thread. > > So you are pegging 'no-good-probability' at 90% and so p at 10%. Ok lets > accept these. Certainly not. I'm pegging my confidence that Mark is a crank at 90%, which is not the same thing. For example, although Mark is (presumably) a crank, nevertheless I have brought some enjoyment into your life as it has given you the opportunity to regale us all with your opinion on off-topic posts, and show off your advanced knowledge of probability *wink* That counts as a good result. > And in the benefit value you include the possible benefit to Mark, to > whoever engages with him and the random [no relation of random variable > X] lurking reader. So far so good > > And in the harm-value y, are you including the harm done to the random > reader from a disorderly, abusive, fruitless and almost completely OT > conversation? You are conflating the magnitude of harm with the probability of harm. But please, do continue in your off-topic rant complaining about off- topic conversations, I'm sure that we're all learning either something or possibly nothing from it. >> If just one person learns something useful or new from a reply to Mark, >> I believe that it is worthwhile. > > And if 3 people drop out because the levels of bullshit have crossed > their thresholds? I don't know. If twelve people are moved to drop out of this group because of your post complaining about my post, how would you react? I'd probably feel between 0 and 1/4 times as good. By the way, I'm curious. Why are discussions about object oriented coding off-topic to Python? This is not a rhetorical question. -- Steven From rustompmody at gmail.com Tue Dec 10 00:16:02 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 9 Dec 2013 21:16:02 -0800 (PST) Subject: interactive help on the base object In-Reply-To: <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> Message-ID: <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> On Tuesday, December 10, 2013 10:40:27 AM UTC+5:30, Steven D'Aprano wrote: > By the way, I'm curious. Why are discussions about object oriented coding > off-topic to Python? This is not a rhetorical question. Well OOP on the python list is certainly on topic. Interminable discussions about why redrawing the inheritance arrows the other way round will save the world is OT (for me!) From roy at panix.com Tue Dec 10 00:31:15 2013 From: roy at panix.com (Roy Smith) Date: Tue, 10 Dec 2013 00:31:15 -0500 Subject: interactive help on the base object References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> Message-ID: In article <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69 at googlegroups.com>, rusi wrote: > On Tuesday, December 10, 2013 10:40:27 AM UTC+5:30, Steven D'Aprano wrote: > > By the way, I'm curious. Why are discussions about object oriented coding > > off-topic to Python? This is not a rhetorical question. > > Well OOP on the python list is certainly on topic. > > Interminable discussions about why redrawing the inheritance arrows > the other way round will save the world is OT (for me!) What about whether the arrows should have solid heads, open heads, barbed heads, double-barbed heads, or circles (filled or open)? Surely you can't expect people to write decent programs when they can't even draw the right kind of arrowhead? From steve at pearwood.info Tue Dec 10 01:05:27 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Dec 2013 06:05:27 GMT Subject: interactive help on the base object References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> Message-ID: <52a6af26$0$2829$c3e8da3$76491128@news.astraweb.com> On Tue, 10 Dec 2013 00:31:15 -0500, Roy Smith wrote: > In article <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69 at googlegroups.com>, > rusi wrote: > >> On Tuesday, December 10, 2013 10:40:27 AM UTC+5:30, Steven D'Aprano >> wrote: >> > By the way, I'm curious. Why are discussions about object oriented >> > coding off-topic to Python? This is not a rhetorical question. >> >> Well OOP on the python list is certainly on topic. >> >> Interminable discussions about why redrawing the inheritance arrows the >> other way round will save the world is OT (for me!) > > What about whether the arrows should have solid heads, open heads, > barbed heads, double-barbed heads, or circles (filled or open)? Surely > you can't expect people to write decent programs when they can't even > draw the right kind of arrowhead? You mock, and so you should, but I just thought I'd mention that there are standards for this sort of thing: http://en.wikipedia.org/wiki/Unified_Modeling_Language According to UML the type of arrow head does make a difference. -- Steven From roy at panix.com Tue Dec 10 01:20:30 2013 From: roy at panix.com (Roy Smith) Date: Tue, 10 Dec 2013 01:20:30 -0500 Subject: interactive help on the base object References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> <52a6af26$0$2829$c3e8da3$76491128@news.astraweb.com> Message-ID: In article <52a6af26$0$2829$c3e8da3$76491128 at news.astraweb.com>, Steven D'Aprano wrote: > > What about whether the arrows should have solid heads, open heads, > > barbed heads, double-barbed heads, or circles (filled or open)? Surely > > you can't expect people to write decent programs when they can't even > > draw the right kind of arrowhead? > > You mock, and so you should, but I just thought I'd mention that there > are standards for this sort of thing: > > http://en.wikipedia.org/wiki/Unified_Modeling_Language > > According to UML the type of arrow head does make a difference. Surely you realize that such a carefully constructed mock could not have been generated without knowledge of the mockee? UML, like so many things, started out with a few good ideas. Giving some structure to how you sketch out classes on a whiteboard was a good idea. Sequence diagrams, in particular, are a neat way to understand complicated control flows. I've even used UML tools to make sense of some huge pile of C++ code that was tossed my way. Import the code, then start shoving boxes around on the screen until some sort of logical structure emerges. But, once things got to there being N different types of arrowheads, each having some magical significance, they lost me. PS: other things that fall into the "Some good basic ideas, but got totally out of hand" include Agile, Six Sigma, and Perl. From breamoreboy at yahoo.co.uk Tue Dec 10 04:37:36 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 10 Dec 2013 09:37:36 +0000 Subject: interactive help on the base object In-Reply-To: <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> Message-ID: On 10/12/2013 05:16, rusi wrote: > On Tuesday, December 10, 2013 10:40:27 AM UTC+5:30, Steven D'Aprano wrote: >> By the way, I'm curious. Why are discussions about object oriented coding >> off-topic to Python? This is not a rhetorical question. > > Well OOP on the python list is certainly on topic. > > Interminable discussions about why redrawing the inheritance arrows > the other way round will save the world is OT (for me!) > One of the great joys of reading this list is how wonderfully OT it can get. I have the right to make this statement as I started *THIS* thread. Now what *WERE* we talking about? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Tue Dec 10 06:51:02 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 10 Dec 2013 03:51:02 -0800 (PST) Subject: interactive help on the base object In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> Message-ID: <3b28f40f-cf67-49ef-8047-b7eea936d78a@googlegroups.com> On Tuesday, December 10, 2013 3:07:36 PM UTC+5:30, Mark Lawrence wrote: > On 10/12/2013 05:16, rusi wrote: > > On Tuesday, December 10, 2013 10:40:27 AM UTC+5:30, Steven D'Aprano wrote: > >> By the way, I'm curious. Why are discussions about object oriented coding > >> off-topic to Python? This is not a rhetorical question. > > Well OOP on the python list is certainly on topic. > > Interminable discussions about why redrawing the inheritance arrows > > the other way round will save the world is OT (for me!) > One of the great joys of reading this list is how wonderfully OT it can > get. I have the right to make this statement as I started *THIS* > thread. Now what *WERE* we talking about? :) My boy, I see that you are making progress towards your guru -- Nikos. "You are spamming MY THREAD" From wuwei23 at gmail.com Tue Dec 10 21:04:25 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 Dec 2013 12:04:25 +1000 Subject: interactive help on the base object In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> <07e43ef4-a2d9-420c-9760-a78a48e6dad6@googlegroups.com> <52a6a242$0$2829$c3e8da3$76491128@news.astraweb.com> <5f7e3e2f-2f86-4a2b-bea5-6e70b6fc2f69@googlegroups.com> Message-ID: On 10/12/2013 7:37 PM, Mark Lawrence wrote: > One of the great joys of reading this list is how wonderfully OT it can > get. I have the right to make this statement as I started *THIS* > thread. Now what *WERE* we talking about? :) The God Object (or Higgs Object for the non-theists). From ian.g.kelly at gmail.com Tue Dec 10 06:35:04 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 10 Dec 2013 04:35:04 -0700 Subject: interactive help on the base object In-Reply-To: <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a5511d$0$2762$c3e8da3$76491128@news.astraweb.com> <52a68851$0$2829$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Dec 9, 2013 at 8:19 PM, Steven D'Aprano wrote: > While I'm very confident at this point that he is a crank, in the same > category as circle-squarers, cold fusion proponents, pi-is-a-rational- > number theorists, perpetual motion machine inventors, evolution or AGW > Denialists[1], and other such obsessive examples of Dunning-Kruger, I'm > not *totally* confident that he is a crank. Maybe he'll prove me wrong > and actually learn something. Who knows, maybe *I'll* learn something! I would compare him more closely to the "Einstein was wrong" armchair physics revisionists, myself. From greg.ewing at canterbury.ac.nz Sun Dec 8 18:15:19 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 09 Dec 2013 12:15:19 +1300 Subject: interactive help on the base object In-Reply-To: References: Message-ID: Mark Janssen wrote: > Mr. Ewing says "base" has to be interpreted as an *adjective* because > otherwise it would mean the BOTTOM (like the BASE of the pyramid), Not exactly -- a native English speaker would say something like "the bottommost class" if that's what they meant. Or they would say "the most basic class" to mean the simplest one -- but that's not quite what we mean either. The only way that "most base class" makes grammatical sense is if you interpret "base" as meaning "undesirable", as in "base metal" (i.e. a non-precious metal), "base instinct" (the kind of animal urges that humans are meant to be too good for), etc. > while Terry responds that it is the TOP (*super*class). Yeah, "top" or "bottom" only conveys the right idea if you assume the diagram is drawn a particular way up. Which is why I like the term "base class" -- you just need to be careful with the grammar! -- Greg From jeanpierreda at gmail.com Sun Dec 8 00:23:37 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 7 Dec 2013 21:23:37 -0800 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On Fri, Dec 6, 2013 at 9:03 AM, Mark Lawrence wrote: > Is it just me, or is this basically useless? > >>>> help(object) > Help on class object in module builtins: > > class object > | The most base type > >>>> > > Surely a few more words, or a pointer to this > http://docs.python.org/3/library/functions.html#object, would be better? It's good enough to give anyone that's seen it before a reminder of what it is. pydoc is useless or worse if you don't know anything about what you're reading. For example, the HTML docs frequently point out potential security vulnerabilities in usages of libraries where pydoc does not. (The wording *is* awkward, though.) -- Devin From john_ladasky at sbcglobal.net Fri Dec 6 13:16:19 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 6 Dec 2013 10:16:19 -0800 (PST) Subject: Does Python optimize low-power functions? Message-ID: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> The following two functions return the same result: x**2 x*x But they may be computed in different ways. The first choice can accommodate non-integer powers and so it would logically proceed by taking a logarithm, multiplying by the power (in this case, 2), and then taking the anti-logarithm. But for a trivial value for the power like 2, this is clearly a wasteful choice. Just multiply x by itself, and skip the expensive log and anti-log steps. My question is, what do Python interpreters do with power operators where the power is a small constant, like 2? Do they know to take the shortcut? From jeanmichel at sequans.com Fri Dec 6 13:52:05 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 6 Dec 2013 19:52:05 +0100 (CET) Subject: Does Python optimize low-power functions? In-Reply-To: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> Message-ID: <442073098.478011.1386355925557.JavaMail.root@sequans.com> ----- Original Message ----- > The following two functions return the same result: > > x**2 > x*x > > But they may be computed in different ways. The first choice can > accommodate non-integer powers and so it would logically proceed by > taking a logarithm, multiplying by the power (in this case, 2), and > then taking the anti-logarithm. But for a trivial value for the > power like 2, this is clearly a wasteful choice. Just multiply x by > itself, and skip the expensive log and anti-log steps. > > My question is, what do Python interpreters do with power operators > where the power is a small constant, like 2? Do they know to take > the shortcut? > -- > https://mail.python.org/mailman/listinfo/python-list It is probably specific to the interpreter implementation(cython, jython, iron python etc...). You'd better optimize it yourself should you really care about this. An alternative is to use numpy functions, like numpy.power, they are optimized version of most mathematical functions. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From neilc at norwich.edu Fri Dec 6 14:01:26 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Fri, 6 Dec 2013 19:01:26 +0000 (UTC) Subject: Does Python optimize low-power functions? References: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> Message-ID: On 2013-12-06, John Ladasky wrote: > The following two functions return the same result: > > x**2 > x*x > > But they may be computed in different ways. The first choice > can accommodate non-integer powers and so it would logically > proceed by taking a logarithm, multiplying by the power (in > this case, 2), and then taking the anti-logarithm. But for a > trivial value for the power like 2, this is clearly a wasteful > choice. Just multiply x by itself, and skip the expensive log > and anti-log steps. > > My question is, what do Python interpreters do with power > operators where the power is a small constant, like 2? Do they > know to take the shortcut? It uses a couple of fast algorithms for computing powers. Here's the excerpt with the comments identifying the algorithms used. >From longobject.c: 2873 if (Py_SIZE(b) <= FIVEARY_CUTOFF) { 2874 /* Left-to-right binary exponentiation (HAC Algorithm 14.79) */ 2875 /* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf */ ... 2886 else { 2887 /* Left-to-right 5-ary exponentiation (HAC Algorithm 14.82) */ The only outright optimization of the style I think your describing that I can see is it quickly returns zero when modulus is one. I'm not a skilled or experienced CPython source reader, though. -- Neil Cerutti From robert.kern at gmail.com Fri Dec 6 14:12:30 2013 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 06 Dec 2013 19:12:30 +0000 Subject: Does Python optimize low-power functions? In-Reply-To: References: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> Message-ID: On 2013-12-06 19:01, Neil Cerutti wrote: > On 2013-12-06, John Ladasky wrote: >> The following two functions return the same result: >> >> x**2 >> x*x >> >> But they may be computed in different ways. The first choice >> can accommodate non-integer powers and so it would logically >> proceed by taking a logarithm, multiplying by the power (in >> this case, 2), and then taking the anti-logarithm. But for a >> trivial value for the power like 2, this is clearly a wasteful >> choice. Just multiply x by itself, and skip the expensive log >> and anti-log steps. >> >> My question is, what do Python interpreters do with power >> operators where the power is a small constant, like 2? Do they >> know to take the shortcut? > > It uses a couple of fast algorithms for computing powers. Here's > the excerpt with the comments identifying the algorithms used. > From longobject.c: > > 2873 if (Py_SIZE(b) <= FIVEARY_CUTOFF) { > 2874 /* Left-to-right binary exponentiation (HAC Algorithm 14.79) */ > 2875 /* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf */ > ... > 2886 else { > 2887 /* Left-to-right 5-ary exponentiation (HAC Algorithm 14.82) */ It's worth noting that the *interpreter* per se is not doing this. The implementation of the `long` object does this in its implementation of the `__pow__` method, which the interpreter invokes. Other objects may implement this differently and use whatever optimizations they like. They may even (ab)use the syntax for things other than numerical exponentiation where `x**2` is not equivalent to `x*x`. Since objects are free to do so, the interpreter itself cannot choose to optimize that exponentiation down to multiplication. -- 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 nick.cash at npcinternational.com Fri Dec 6 14:32:00 2013 From: nick.cash at npcinternational.com (Nick Cash) Date: Fri, 6 Dec 2013 19:32:00 +0000 Subject: Does Python optimize low-power functions? In-Reply-To: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> References: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> Message-ID: <64aa230f94f04c938101f928ac1a0276@DM2PR06MB542.namprd06.prod.outlook.com> >My question is, what do Python interpreters do with power operators where the power is a small constant, like 2? Do they know to take the shortcut? Nope: Python 3.3.0 (default, Sep 25 2013, 19:28:08) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dis >>> dis.dis(lambda x: x*x) 1 0 LOAD_FAST 0 (x) 3 LOAD_FAST 0 (x) 6 BINARY_MULTIPLY 7 RETURN_VALUE >>> dis.dis(lambda x: x**2) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (2) 6 BINARY_POWER 7 RETURN_VALUE The reasons why have already been answered, I just wanted to point out that Python makes it extremely easy to check these sorts of things for yourself. From torriem at gmail.com Sat Dec 7 21:00:09 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Dec 2013 19:00:09 -0700 Subject: Does Python optimize low-power functions? In-Reply-To: <64aa230f94f04c938101f928ac1a0276@DM2PR06MB542.namprd06.prod.outlook.com> References: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> <64aa230f94f04c938101f928ac1a0276@DM2PR06MB542.namprd06.prod.outlook.com> Message-ID: <52A3D2A9.9030703@gmail.com> On 12/06/2013 12:32 PM, Nick Cash wrote: > Nope: > > Python 3.3.0 (default, Sep 25 2013, 19:28:08) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import dis >>>> dis.dis(lambda x: x*x) > 1 0 LOAD_FAST 0 (x) > 3 LOAD_FAST 0 (x) > 6 BINARY_MULTIPLY > 7 RETURN_VALUE >>>> dis.dis(lambda x: x**2) > 1 0 LOAD_FAST 0 (x) > 3 LOAD_CONST 1 (2) > 6 BINARY_POWER > 7 RETURN_VALUE > > > The reasons why have already been answered, I just wanted to point > out that Python makes it extremely easy to check these sorts of > things for yourself. But this is just the interpreter bytecode that dis is showing. It's not showing the underlying implementation of binary_power, for example. That could be defined in C code with any number of optimizations, and indeed it appears that some are being done. dis is great for showing how python code breaks down, but it can't tell you much about the code that underlies the byte codes themselves. From john_ladasky at sbcglobal.net Fri Dec 6 14:43:44 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 6 Dec 2013 11:43:44 -0800 (PST) Subject: Does Python optimize low-power functions? In-Reply-To: References: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> Message-ID: <4ff14c9b-c745-4c31-98a7-e0b457c661cf@googlegroups.com> On Friday, December 6, 2013 11:32:00 AM UTC-8, Nick Cash wrote: > The reasons why have already been answered, I just wanted to point out that Python makes it extremely easy to check these sorts of things for yourself. Thanks for the heads-up on the dis module, Nick. I haven't played with that one yet. From oscar.j.benjamin at gmail.com Fri Dec 6 15:57:49 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 6 Dec 2013 20:57:49 +0000 Subject: Does Python optimize low-power functions? In-Reply-To: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> References: <5ea86e1b-f5b5-49d1-acfb-22ee4d9a1f16@googlegroups.com> Message-ID: On 6 December 2013 18:16, John Ladasky wrote: > The following two functions return the same result: > > x**2 > x*x > > But they may be computed in different ways. The first choice can accommodate non-integer powers and so it would logically proceed by taking a logarithm, multiplying by the power (in this case, 2), and then taking the anti-logarithm. But for a trivial value for the power like 2, this is clearly a wasteful choice. Just multiply x by itself, and skip the expensive log and anti-log steps. > > My question is, what do Python interpreters do with power operators where the power is a small constant, like 2? Do they know to take the shortcut? As mentioned this will depend on the interpreter and on the type of x. Python's integer arithmetic is exact and unbounded so switching to floating point and using approximate logarithms is a no go if x is an int object. For CPython specifically, you can see here: http://hg.python.org/cpython/file/07ef52e751f3/Objects/floatobject.c#l741 that for floats x**2 will be equivalent to x**2.0 and will be handled by the pow function from the underlying C math library. If you read the comments around that line you'll see that different inconsistent math libraries can do things very differently leading to all kinds of different problems. For CPython if x is an int (long) then as mentioned before it is handled by the HAC algorithm: http://hg.python.org/cpython/file/07ef52e751f3/Objects/longobject.c#l3934 For CPython if x is a complex then it is handled roughly as you say: for x**n if n is between -100 and 100 then multiplication is performed using the "bit-mask exponentiation" algorithm. Otherwise it is computed by converting to polar exponential form and using logs (see also the two functions above this one): http://hg.python.org/cpython/file/07ef52e751f3/Objects/complexobject.c#l151 Oscar From ikorot01 at gmail.com Fri Dec 6 14:37:11 2013 From: ikorot01 at gmail.com (Igor Korot) Date: Fri, 6 Dec 2013 11:37:11 -0800 Subject: Eliminate "extra" variable Message-ID: Hi, ALL, I have following code: def MyFunc(self, originalData): data = {} dateStrs = [] for i in xrange(0, len(originalData)): dateStr, freq, source = originalData[i] data[str(dateStr)] = {source: freq} dateStrs.append(dateStr) for i in xrange(0, len(dateStrs) - 1): currDateStr = str(dateStrs[i]) nextDateStrs = str(dateStrs[i + 1]) It seems very strange that I need the dateStrs list just for the purpose of looping thru the dictionary keys. Can I get rid of the "dateStrs" variable? Thank you. From gary.herron at islandtraining.com Fri Dec 6 18:28:20 2013 From: gary.herron at islandtraining.com (Gary Herron) Date: Fri, 06 Dec 2013 15:28:20 -0800 Subject: Eliminate "extra" variable In-Reply-To: References: Message-ID: <52A25D94.9040404@islandtraining.com> On 12/06/2013 11:37 AM, Igor Korot wrote: > Hi, ALL, > I have following code: > > def MyFunc(self, originalData): > data = {} > dateStrs = [] > for i in xrange(0, len(originalData)): > dateStr, freq, source = originalData[i] > data[str(dateStr)] = {source: freq} > dateStrs.append(dateStr) > for i in xrange(0, len(dateStrs) - 1): > currDateStr = str(dateStrs[i]) > nextDateStrs = str(dateStrs[i + 1]) > > > It seems very strange that I need the dateStrs list just for the > purpose of looping thru the dictionary keys. > Can I get rid of the "dateStrs" variable? > > Thank you. You want to build a list, but you don't want to give that list a name? Why not? And how would you refer to that list in the second loop if it didn't have a name? And concerning that second loop: What are you trying to do there? It looks like a complete waste of time. In fact, with what you've shown us, you can eliminate the variable dateStrs, and both loops and be no worse off. Perhaps there is more to your code than you've shown to us ... Gary Herron From ikorot01 at gmail.com Sun Dec 8 02:14:03 2013 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 7 Dec 2013 23:14:03 -0800 Subject: Fwd: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> Message-ID: OK, here is the complete function code that I'm trying to improve. def MyFunc(self, originalData): self.dates = [] data = {} dateStrs = [] for i in xrange(0, len(originalData)): dateStr, freq, source = originalData[i] data[str(dateStr)] = {source: freq} dateStrs.append(dateStr) for i in xrange(0, len(dateStrs) - 1): currDateStr = str(dateStrs[i]) nextDateStr = str(dateStrs[i + 1]) self.dates.append(currDateStr) currDate = datetime.datetime.strptime(currDateStr, '%Y-%m-%d') nextDate = datetime.datetime.strptime(nextDateStr, '%Y-%m-%d') if nextDate - curDate < datetime.timedelta(days=31): d = currDate + datetime.timedelta(days=1) while d < nextDate: self.dates.append(d.strftime('%Y-%m-%d')) d = d + datetime.timedelta(days=1) lastDateStr = dateStrs[-1] self.dates.append(str(lastDateStr)) return data As you can see there is many conversion going on and there's unneeded dateStrs which is used just to loop thru the dictionary and get the 2 consecutive keys. This I'm trying to avoid to make this function perform faster and consume less memory. This code was written a long time ago before me and now I'm trying to improve it. I'm thinking of using the suggestion of Tim Chase which will eliminate the extra unneeded variables and will let me also eliminate a lot of back and force conversions. But if you see a better way - please share. Thank you. On Fri, Dec 6, 2013 at 5:36 PM, Igor Korot wrote: > OK, people, thank you everybody for the input. > > Here is the more explanation that I think is in order: > > The originalData comes from either SQLite DB or mySQL DB. Since first > uses strings and second uses datetime I am using str() to make the > data consistent. > Now the query is this: > > SELECT date, freq, value FROM my_table ORDER BY date; > > and so I do know that the originalData is already presorted (ordered). > So sorting is not a problem here. > > Now what I'm looking for here is check whether the time difference > between the currDateStr and nextDateStr is 30 days. If its do some > calculation and pass the dictionary with dates as strings to the next > function. > That function is inside wxPython (GUI) which will do plotting. In the > plot function the dates will be used as the labels for the x-axis. So > this is another reason to keep dates as strings. > > I hope I made it a little clear and hopefully someone will give me > Python example of how do I simplify this code to eliminate un-needed > variables. > > Thank you. > > > On Fri, Dec 6, 2013 at 5:19 PM, Igor Korot wrote: >> Hi, Gary, >> >> On Fri, Dec 6, 2013 at 3:28 PM, Gary Herron >> wrote: >>> On 12/06/2013 11:37 AM, Igor Korot wrote: >>>> >>>> Hi, ALL, >>>> I have following code: >>>> >>>> def MyFunc(self, originalData): >>>> data = {} >>>> dateStrs = [] >>>> for i in xrange(0, len(originalData)): >>>> dateStr, freq, source = originalData[i] >>>> data[str(dateStr)] = {source: freq} >>>> dateStrs.append(dateStr) >>>> for i in xrange(0, len(dateStrs) - 1): >>>> currDateStr = str(dateStrs[i]) >>>> nextDateStrs = str(dateStrs[i + 1]) >>>> >>>> >>>> It seems very strange that I need the dateStrs list just for the >>>> purpose of looping thru the dictionary keys. >>>> Can I get rid of the "dateStrs" variable? >>>> >>>> Thank you. >>> >>> >>> You want to build a list, but you don't want to give that list a name? Why >>> not? And how would you refer to that list in the second loop if it didn't >>> have a name? >>> >>> And concerning that second loop: What are you trying to do there? It looks >>> like a complete waste of time. In fact, with what you've shown us, you can >>> eliminate the variable dateStrs, and both loops and be no worse off. >>> >>> Perhaps there is more to your code than you've shown to us ... >> >> What I want here is to do something like this: >> >> def MyFunc(self, originalData): >> data = {} >> for i in xrange(0, len(originalData)): >> dateStr, freq, source = originalData[i] >> data[str(dateStr)] = {source: freq} >> for i in xrange(0, len(data) - 1): >> currDateStr = str(data[i].key()) // I need a syntax here >> nextDateStrs = str(data[i + 1].key()) // I need a syntax here >> >> Thank you. >> >>> >>> Gary Herron >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list From python.list at tim.thechases.com Sun Dec 8 13:58:23 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 8 Dec 2013 12:58:23 -0600 Subject: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> Message-ID: <20131208125823.241112db@bigbox.christie.dr> On 2013-12-07 23:14, Igor Korot wrote: > def MyFunc(self, originalData): > self.dates = [] > data = {} > dateStrs = [] > for i in xrange(0, len(originalData)): > dateStr, freq, source = originalData[i] > data[str(dateStr)] = {source: freq} > dateStrs.append(dateStr) > for i in xrange(0, len(dateStrs) - 1): > currDateStr = str(dateStrs[i]) > nextDateStr = str(dateStrs[i + 1]) > self.dates.append(currDateStr) > currDate = datetime.datetime.strptime(currDateStr, > '%Y-%m-%d') nextDate = datetime.datetime.strptime(nextDateStr, > '%Y-%m-%d') if nextDate - curDate < datetime.timedelta(days=31): > d = currDate + datetime.timedelta(days=1) > while d < nextDate: > self.dates.append(d.strftime('%Y-%m-%d')) > d = d + datetime.timedelta(days=1) > lastDateStr = dateStrs[-1] > self.dates.append(str(lastDateStr)) > return data It would help to know what you want this function to accomplish: "MyFunc" isn't exactly descriptive. From what I gather by reading it, you want it to do two things: - append each date in the range from originalData[0] through originalData[-1] to self.dates every time this function is called (which means that multiple calls to this will grow self.dates every time) - if there's less than 31 days between N and N+1, also append all the dates in between (this seems weird, but okay). Again, every time this function is called. - return a dictionary that maps dates in the input-data to the associated source:freq dictionary. It's hard to tell what you intend to do with these results. If you just intend to iterate over them once, asking for associated data, you could even create a generator that yields the date along with either None or the associated data. See below for that. Alternatively, you can return both the dict-mapping and the date-list from the function: def f(...): return (the_dict, the_list) a_dict, a_list = f(...) That would prevent repeated mutation of self.dates > As you can see there is many conversion going on and there's > unneeded dateStrs which is used just to loop thru the dictionary > and get the 2 consecutive keys. The final snippet of code that I provided handles this pretty nicely by zipping up the staggered lists and iterating over them while unpacking them into sensible variable names. Unless you have a need to operate on the dates as string, I'd just keep them as dates throughout the code and only turn them into strings upon output. > But if you see a better way - please share. I'd likely incorporate Peter's sliding_window() suggestion and do something like the following (I commented out using a tuple for the values, but using a tuple/namedtuple might make more sense) import itertools def sliding_window(i): a, b = itertools.tee(i) next(b) return itertools.izip(a, b) def some_descriptive_function_name(self, original_data): # construct these once-per-call rather than every loop # or even move them out to module-scope ONE_DAY = datetime.timedelta(days=1) MONTHISH = datetime.timedelta(days=31) for ( (cur_dt, cur_freq, cur_source), (next_dt, next_freq, next_source) ) in sliding_window(original_data): info = {cur_source: cur_freq} # info = (cur_source, cur_freq) yield cur_dt, info if next_dt - cur_dt < MONTHISH: d = cur_dt + ONE_DAY while d < next_dt: yield d, None d += ONE_DAY info = {next_source: next_freq} # info = (next_source, next_freq) yield next_dt, info which can then be used with for dt, info in self.some_descriptive_function_name(data): # dates should be returned in the same sequence # as your original logic if info is None: do_something_when_no_info(dt) else: do_something_with_dt_and_info(dt, info) If you need to iterate over the data multiple times, you can just do tmp = list(self.some_descriptive_function_name(data)) do_first(tmp) do_second(tmp) -tkc From breamoreboy at yahoo.co.uk Sun Dec 8 14:10:56 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Dec 2013 19:10:56 +0000 Subject: Eliminate "extra" variable In-Reply-To: <20131208125823.241112db@bigbox.christie.dr> References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> Message-ID: On 08/12/2013 18:58, Tim Chase wrote: > On 2013-12-07 23:14, Igor Korot wrote: [big snip] > Whenever I need date manipulations I always reach out to this http://labix.org/python-dateutil -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python.list at tim.thechases.com Sun Dec 8 14:23:26 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 8 Dec 2013 13:23:26 -0600 Subject: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> Message-ID: <20131208132326.67741f9f@bigbox.christie.dr> On 2013-12-08 19:10, Mark Lawrence wrote: > On 08/12/2013 18:58, Tim Chase wrote: > > On 2013-12-07 23:14, Igor Korot wrote: > > [big snip] > > Whenever I need date manipulations I always reach out to this > http://labix.org/python-dateutil But based on the OP's repeated transformations from date-to-string and back again, what do you reach for when you want to transform things *needlessly*? I recommend the delete key and some healthy refactoring. :-) -tkc From breamoreboy at yahoo.co.uk Sun Dec 8 14:28:20 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Dec 2013 19:28:20 +0000 Subject: Eliminate "extra" variable In-Reply-To: <20131208132326.67741f9f@bigbox.christie.dr> References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208132326.67741f9f@bigbox.christie.dr> Message-ID: On 08/12/2013 19:23, Tim Chase wrote: > On 2013-12-08 19:10, Mark Lawrence wrote: >> On 08/12/2013 18:58, Tim Chase wrote: >>> On 2013-12-07 23:14, Igor Korot wrote: >> >> [big snip] >> >> Whenever I need date manipulations I always reach out to this >> http://labix.org/python-dateutil > > But based on the OP's repeated transformations from date-to-string > and back again, what do you reach for when you want to transform > things *needlessly*? I recommend the delete key and some healthy > refactoring. :-) > > -tkc Painkillers :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Sun Dec 8 15:07:25 2013 From: roy at panix.com (Roy Smith) Date: Sun, 08 Dec 2013 15:07:25 -0500 Subject: Eliminate "extra" variable References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> Message-ID: In article , Mark Lawrence wrote: > On 08/12/2013 18:58, Tim Chase wrote: > > On 2013-12-07 23:14, Igor Korot wrote: > > [big snip] > > > > > Whenever I need date manipulations I always reach out to this > http://labix.org/python-dateutil The problem with dateutil is it's dog slow. Sure, I use it too, when convenience is more important than performance, but have you ever looked at the code for dateutil.parser.parse()? It's worth reading, just for fun. From ikorot01 at gmail.com Sun Dec 8 15:58:18 2013 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 8 Dec 2013 12:58:18 -0800 Subject: Fwd: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> Message-ID: ---------- Forwarded message ---------- From: Igor Korot Date: Sun, Dec 8, 2013 at 12:57 PM Subject: Re: Eliminate "extra" variable To: Roy Smith Hi, guys, Thank you for all those valuable suggestions. 2Tim Chase: I guess you missed this: "My originalData comes from the database query" and so the checking of the data quality is a DB burden. ;-) As to the function: the function purpose is to process the data and give out the list of dates and the dictionary of date:frequency. It's input is the query result, so there is no looping when the function is called. It is called only once. Also, the data comes from either SQLite or mySQL and so to eliminate the difference between those engines dates are processed as strings and converted to dates for the calculation purposes only. Maybe I will need to refactor SQLite processing to get the dates as dates and not a string, but that's probably for the future. so that dates will be kept as the datetime type until the end of the function. As I wrote the dates will be used as the text for the plotting window axis labels and as the labels they should come out as strings, hence the conversion. Thank you. On Sun, Dec 8, 2013 at 12:07 PM, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> On 08/12/2013 18:58, Tim Chase wrote: >> > On 2013-12-07 23:14, Igor Korot wrote: >> >> [big snip] >> >> > >> >> Whenever I need date manipulations I always reach out to this >> http://labix.org/python-dateutil > > The problem with dateutil is it's dog slow. Sure, I use it too, when > convenience is more important than performance, but have you ever looked > at the code for dateutil.parser.parse()? It's worth reading, just for > fun. > -- > https://mail.python.org/mailman/listinfo/python-list From python.list at tim.thechases.com Sun Dec 8 17:18:58 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 8 Dec 2013 16:18:58 -0600 Subject: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> Message-ID: <20131208161858.1365f2d7@bigbox.christie.dr> On 2013-12-08 12:58, Igor Korot wrote: > Also, the data comes from either SQLite or mySQL and so to eliminate > the difference between those engines dates are processed as strings > and converted to dates for the calculation purposes only. > Maybe I will need to refactor SQLite processing to get the dates as > dates and not a string, but that's probably for the future. so that > dates will be kept as the datetime type until the end of the > function. As I wrote the dates will be used as the text for the > plotting window axis labels and as the labels they should come out > as strings, hence the conversion. Sqlite can do this automatically if you tell it to upon connecting: >>> import sqlite3 >>> conn = sqlite3.connect('x.sqlite', ... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >>> cur.execute("create table foo (s date);") >>> import datetime >>> today = datetime.date.today() >>> cur.execute("insert into foo(s) values (?)", (today,)) >>> cur.execute("select * from foo") >>> r = cur.fetchone() >>> print r (datetime.date(2013, 12, 8),) Note that it returns a datetime.date, the same as it was defined. -tkc From ikorot01 at gmail.com Sun Dec 15 02:49:58 2013 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 14 Dec 2013 23:49:58 -0800 Subject: Eliminate "extra" variable In-Reply-To: <20131208161858.1365f2d7@bigbox.christie.dr> References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> Message-ID: Tim, On Sun, Dec 8, 2013 at 2:18 PM, Tim Chase wrote: > On 2013-12-08 12:58, Igor Korot wrote: >> Also, the data comes from either SQLite or mySQL and so to eliminate >> the difference between those engines dates are processed as strings >> and converted to dates for the calculation purposes only. >> Maybe I will need to refactor SQLite processing to get the dates as >> dates and not a string, but that's probably for the future. so that >> dates will be kept as the datetime type until the end of the >> function. As I wrote the dates will be used as the text for the >> plotting window axis labels and as the labels they should come out >> as strings, hence the conversion. > > Sqlite can do this automatically if you tell it to upon connecting: > >>>> import sqlite3 >>>> conn = sqlite3.connect('x.sqlite', > ... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >>>> cur.execute("create table foo (s date);") > >>>> import datetime >>>> today = datetime.date.today() >>>> cur.execute("insert into foo(s) values (?)", (today,)) > >>>> cur.execute("select * from foo") > >>>> r = cur.fetchone() >>>> print r > (datetime.date(2013, 12, 8),) Interesting. I'm using datetime rather than the date type for CREATE TABLE() command. And when running SELECT I still see the b'1998-08-05 23:12:12' string representation when running my program under debugger. And it is confirmed by running this: >>> cur.execute("CREATE TABLE foo(bar datetime);") >>> import datetime >>> today = datetime.date.today() >>> cur.execute("insert into foo(bar) values (?)", (today,)) >>> cur.execute("select * from foo") >>> res = cur.fetchall() >>> print res [(u'2013-12-14',)] >>> So, I guess this is a bug in the sqlite3 python module as datetime is legal data type on the DB engine. Thank you. > > > Note that it returns a datetime.date, the same as it was defined. > > -tkc > > > > > -- > https://mail.python.org/mailman/listinfo/python-list From python.list at tim.thechases.com Sun Dec 15 07:17:20 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 15 Dec 2013 06:17:20 -0600 Subject: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> Message-ID: <20131215061720.2fbb394d@bigbox.christie.dr> On 2013-12-14 23:49, Igor Korot wrote: > Tim, > > On Sun, Dec 8, 2013 at 2:18 PM, Tim Chase wrote: >>>>> conn = sqlite3.connect('x.sqlite', >>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) Your example code omitted this one crucial line. Do you specify the detect_types parameter to connect()? -tkc From python.list at tim.thechases.com Sun Dec 15 07:29:23 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 15 Dec 2013 06:29:23 -0600 Subject: Eliminate "extra" variable In-Reply-To: <20131215061720.2fbb394d@bigbox.christie.dr> References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> <20131215061720.2fbb394d@bigbox.christie.dr> Message-ID: <20131215062923.184bf636@bigbox.christie.dr> On 2013-12-15 06:17, Tim Chase wrote: >>>>>> conn = sqlite3.connect('x.sqlite', >>>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > > Your example code omitted this one crucial line. Do you specify the > detect_types parameter to connect()? It's really the PARSE_DECLTYPES that is important. http://docs.python.org/2/library/sqlite3.html#sqlite3.PARSE_DECLTYPES -tkc From ikorot01 at gmail.com Sun Dec 15 17:46:18 2013 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 15 Dec 2013 14:46:18 -0800 Subject: Eliminate "extra" variable In-Reply-To: <20131215062923.184bf636@bigbox.christie.dr> References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> <20131215061720.2fbb394d@bigbox.christie.dr> <20131215062923.184bf636@bigbox.christie.dr> Message-ID: Tim, On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase wrote: > On 2013-12-15 06:17, Tim Chase wrote: >>>>>>> conn = sqlite3.connect('x.sqlite', >>>>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >> >> Your example code omitted this one crucial line. Do you specify the >> detect_types parameter to connect()? Yes, I did. This is the beginning of the session: >>> import sqlite3 >>> conn = sqlite3.connect('c:\Documents and Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) Also please note that you session was missing the cursor creation command. ;-) Thank you. > > It's really the PARSE_DECLTYPES that is important. > > http://docs.python.org/2/library/sqlite3.html#sqlite3.PARSE_DECLTYPES > > -tkc > > > -- > https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Sun Dec 15 19:58:31 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Dec 2013 00:58:31 +0000 Subject: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> <20131215061720.2fbb394d@bigbox.christie.dr> <20131215062923.184bf636@bigbox.christie.dr> Message-ID: <52AE5037.5000300@mrabarnett.plus.com> On 15/12/2013 22:46, Igor Korot wrote: > Tim, > > On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase > wrote: >> On 2013-12-15 06:17, Tim Chase wrote: >>>>>>>> conn = sqlite3.connect('x.sqlite', >>>>>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >>> >>> Your example code omitted this one crucial line. Do you specify the >>> detect_types parameter to connect()? > > Yes, I did. > This is the beginning of the session: > >>>> import sqlite3 >>>> conn = sqlite3.connect('c:\Documents and Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > When writing paths on Windows, it's a good idea to use raw string literals or slashes instead of backslashes: conn = sqlite3.connect(r'c:\Documents and Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) or: conn = sqlite3.connect('c:/Documents and Settings/Igor.FORDANWORK/Desktop/mydb.db', detect_types = sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > Also please note that you session was missing the cursor creation command. ;-) > > Thank you. > >> >> It's really the PARSE_DECLTYPES that is important. >> >> http://docs.python.org/2/library/sqlite3.html#sqlite3.PARSE_DECLTYPES >> From ikorot01 at gmail.com Sun Dec 15 21:43:53 2013 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 15 Dec 2013 18:43:53 -0800 Subject: Eliminate "extra" variable In-Reply-To: <52AE5037.5000300@mrabarnett.plus.com> References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> <20131215061720.2fbb394d@bigbox.christie.dr> <20131215062923.184bf636@bigbox.christie.dr> <52AE5037.5000300@mrabarnett.plus.com> Message-ID: Hi, On Sun, Dec 15, 2013 at 4:58 PM, MRAB wrote: > On 15/12/2013 22:46, Igor Korot wrote: >> >> Tim, >> >> On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase >> wrote: >>> >>> On 2013-12-15 06:17, Tim Chase wrote: >>>>>>>>> >>>>>>>>> conn = sqlite3.connect('x.sqlite', >>>>>> >>>>>> ... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >>>> >>>> >>>> Your example code omitted this one crucial line. Do you specify the >>>> detect_types parameter to connect()? >> >> >> Yes, I did. >> This is the beginning of the session: >> >>>>> import sqlite3 >>>>> conn = sqlite3.connect('c:\Documents and >>>>> Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = >>>>> sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >> >> > When writing paths on Windows, it's a good idea to use raw string > literals or slashes instead of backslashes: > > conn = sqlite3.connect(r'c:\Documents and > Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > > or: > > conn = sqlite3.connect('c:/Documents and > Settings/Igor.FORDANWORK/Desktop/mydb.db', detect_types = > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) So, how do I convert my string to one of those? I realized I can just do replace '/' to '\', but is there a better alternative? Thank you. > > >> Also please note that you session was missing the cursor creation command. >> ;-) >> >> Thank you. >> >>> >>> It's really the PARSE_DECLTYPES that is important. >>> >>> http://docs.python.org/2/library/sqlite3.html#sqlite3.PARSE_DECLTYPES >>> > > -- > https://mail.python.org/mailman/listinfo/python-list From davea at davea.name Sun Dec 15 21:58:24 2013 From: davea at davea.name (Dave Angel) Date: Sun, 15 Dec 2013 21:58:24 -0500 Subject: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> <20131215061720.2fbb394d@bigbox.christie.dr> <20131215062923.184bf636@bigbox.christie.dr> <52AE5037.5000300@mrabarnett.plus.com> Message-ID: On Sun, 15 Dec 2013 18:43:53 -0800, Igor Korot wrote: > On Sun, Dec 15, 2013 at 4:58 PM, MRAB wrote: > > When writing paths on Windows, it's a good idea to use raw string > > literals or slashes instead of backslashes: > > > > conn = sqlite3.connect(r'c:\Documents and > > Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = > > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > > > > or: > > > > conn = sqlite3.connect('c:/Documents and > > Settings/Igor.FORDANWORK/Desktop/mydb.db', detect_types = > > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > So, how do I convert my string to one of those? > I realized I can just do replace '/' to '\', but is there a better alternative? The "conversion" is done with a text editor. The string literals you had were just wrong. By the time they have been turned into strings it's too late to algorithmically recover your intended string values. -- DaveA From rosuav at gmail.com Sun Dec 15 21:57:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Dec 2013 13:57:24 +1100 Subject: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> <20131215061720.2fbb394d@bigbox.christie.dr> <20131215062923.184bf636@bigbox.christie.dr> <52AE5037.5000300@mrabarnett.plus.com> Message-ID: On Mon, Dec 16, 2013 at 1:43 PM, Igor Korot wrote: > So, how do I convert my string to one of those? > I realized I can just do replace '/' to '\', but is there a better alternative? The path is exactly the same, whether you use forward slashes or backslashes, on Windows. Most of the world uses backslashes for Windows paths, but forward slashes do work fine (and that's not a Python thing - the underlying APIs work with / just fine too). So you don't have to actually replace anything. >>> len(open("c:/Festival2013.txt").read()) 79137 ChrisA From ikorot01 at gmail.com Sun Dec 15 23:24:20 2013 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 15 Dec 2013 20:24:20 -0800 Subject: Eliminate "extra" variable In-Reply-To: <52AE5037.5000300@mrabarnett.plus.com> References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> <20131215061720.2fbb394d@bigbox.christie.dr> <20131215062923.184bf636@bigbox.christie.dr> <52AE5037.5000300@mrabarnett.plus.com> Message-ID: Hi, I have the same result even with: sqlite3.connect(r'...') Any other alternatives? Thank you. On Sun, Dec 15, 2013 at 4:58 PM, MRAB wrote: > On 15/12/2013 22:46, Igor Korot wrote: >> >> Tim, >> >> On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase >> wrote: >>> >>> On 2013-12-15 06:17, Tim Chase wrote: >>>>>>>>> >>>>>>>>> conn = sqlite3.connect('x.sqlite', >>>>>> >>>>>> ... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >>>> >>>> >>>> Your example code omitted this one crucial line. Do you specify the >>>> detect_types parameter to connect()? >> >> >> Yes, I did. >> This is the beginning of the session: >> >>>>> import sqlite3 >>>>> conn = sqlite3.connect('c:\Documents and >>>>> Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = >>>>> sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >> >> > When writing paths on Windows, it's a good idea to use raw string > literals or slashes instead of backslashes: > > conn = sqlite3.connect(r'c:\Documents and > Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types = > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > > or: > > conn = sqlite3.connect('c:/Documents and > Settings/Igor.FORDANWORK/Desktop/mydb.db', detect_types = > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > > >> Also please note that you session was missing the cursor creation command. >> ;-) >> >> Thank you. >> >>> >>> It's really the PARSE_DECLTYPES that is important. >>> >>> http://docs.python.org/2/library/sqlite3.html#sqlite3.PARSE_DECLTYPES >>> > > -- > https://mail.python.org/mailman/listinfo/python-list From davea at davea.name Sun Dec 8 17:36:30 2013 From: davea at davea.name (Dave Angel) Date: Sun, 08 Dec 2013 17:36:30 -0500 Subject: Fwd: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> Message-ID: On Sun, 8 Dec 2013 12:58:18 -0800, Igor Korot wrote: > It's input is the query result, so there is no looping when the > function is called. It is called only once. Then why save part of the result in an instance attribute? Just return all of the results as a tuple. -- DaveA From joel.goldstick at gmail.com Fri Dec 6 18:38:37 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 6 Dec 2013 18:38:37 -0500 Subject: Eliminate "extra" variable In-Reply-To: References: Message-ID: On Fri, Dec 6, 2013 at 2:37 PM, Igor Korot wrote: > Hi, ALL, > I have following code: > > def MyFunc(self, originalData): > data = {} > dateStrs = [] > for i in xrange(0, len(originalData)): > dateStr, freq, source = originalData[i] > data[str(dateStr)] = {source: freq} > # above line confuses me! > dateStrs.append(dateStr) > for i in xrange(0, len(dateStrs) - 1): > currDateStr = str(dateStrs[i]) > nextDateStrs = str(dateStrs[i + 1]) > > Python lets you iterate over a list directly, so : for d in originalData: dateStr, freq, source = d data[source] = freq Your code looks like you come from a c background. Python idioms are different I'm not sure what you are trying to do in the second for loop, but I think you are trying to iterate thru a dictionary in a certain order, and you can't depend on the order > > It seems very strange that I need the dateStrs list just for the > purpose of looping thru the dictionary keys. > Can I get rid of the "dateStrs" variable? > > Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Dec 6 18:49:18 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 06 Dec 2013 15:49:18 -0800 Subject: Eliminate "extra" variable In-Reply-To: References: Message-ID: <52A2627E.7070307@stoneleaf.us> On 12/06/2013 03:38 PM, Joel Goldstick wrote: > On Fri, Dec 6, 2013 at 2:37 PM, Igor Korot wrote: >> >> def MyFunc(self, originalData): >> data = {} >> dateStrs = [] >> for i in xrange(0, len(originalData)): >> dateStr, freq, source = originalData[i] >> data[str(dateStr)] = {source: freq} >> >> # above line confuses me! >> >> dateStrs.append(dateStr) >> for i in xrange(0, len(dateStrs) - 1): >> currDateStr = str(dateStrs[i]) >> nextDateStrs = str(dateStrs[i + 1]) > > Python lets you iterate over a list directly, so : > > for d in originalData: > dateStr, freq, source = d > data[source] = freq You could shorten that to for dateStr, freq, source in originalData: and if dateStr is already a string: data[dateStr] = {source: freq} > Your code looks like you come from a c background. Python idioms are different Agreed. > I'm not sure what you are trying to do in the second for loop, but I think you are trying to iterate thru a dictionary > in a certain order, and you can't depend on the order The second loop is iterating over the list dateStrs. -- ~Ethan~ From roy at panix.com Fri Dec 6 19:16:13 2013 From: roy at panix.com (Roy Smith) Date: Fri, 06 Dec 2013 19:16:13 -0500 Subject: Eliminate "extra" variable References: Message-ID: In article , Joel Goldstick wrote: > Python lets you iterate over a list directly, so : > > for d in originalData: > dateStr, freq, source = d > data[source] = freq I would make it even simpler: > for dateStr, freq, source in originalData: > data[source] = freq From joel.goldstick at gmail.com Fri Dec 6 19:32:28 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 6 Dec 2013 19:32:28 -0500 Subject: Eliminate "extra" variable In-Reply-To: References: Message-ID: On Fri, Dec 6, 2013 at 7:16 PM, Roy Smith wrote: > In article , > Joel Goldstick wrote: > > > Python lets you iterate over a list directly, so : > > > > for d in originalData: > > dateStr, freq, source = d > > data[source] = freq > > I would make it even simpler: > > > for dateStr, freq, source in originalData: > > data[source] = freq > +1 --- I agree To the OP: Could you add a docstring to your function to explain what is supposed to happen, describe the input and output? If you do that I'm sure you could get some more complete help with your code. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Fri Dec 6 19:37:21 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 6 Dec 2013 18:37:21 -0600 Subject: Eliminate "extra" variable In-Reply-To: References: Message-ID: <20131206183721.3e7f21c2@bigbox.christie.dr> On 2013-12-06 11:37, Igor Korot wrote: > def MyFunc(self, originalData): > data = {} > for i in xrange(0, len(originalData)): > dateStr, freq, source = originalData[i] > data[str(dateStr)] = {source: freq} this can be more cleanly/pythonically written as def my_func(self, original_data): for date, freq, source in original_data data[str(date)] = {source: freq} or even just data = dict( (str(date), {source: freq}) for date, freq, source in original_data ) You're calling it a "dateStr", which suggests that it's already a string, so I'm not sure why you're str()'ing it. So I'd either just call it "date", or skip the str(date) bit if it's already a string. That said, do you even need to convert it to a string (as datetime.date objects can be used as keys in dictionaries)? > for i in xrange(0, len(dateStrs) - 1): > currDateStr = str(dateStrs[i]) > nextDateStrs = str(dateStrs[i + 1]) > > It seems very strange that I need the dateStrs list just for the > purpose of looping thru the dictionary keys. > Can I get rid of the "dateStrs" variable? Your code isn't actually using the data-dict at this point. If you were doing something with it, it might help to know what you want to do. Well, you can iterate over the original data, zipping them together: for (cur, _, _), (next, _, _) in zip( original_data[:-1], original_data[1:] ): do_something(cur, next) If your purpose for the "data" dict is to merely look up stats from the next one, the whole batch of your original code can be replaced with: for ( (cur_dt, cur_freq, cur_source), (next_dt, next_freq, next_source) ) in zip(original_data[:-1], original_data[1:]): # might need to do str(cur_dt) and str(next_dt) instead? do_things_with(cur_dt, cur_freq, cur_source, next_dt, next_freq, next_source) That eliminates the dict *and* the extra variable name. :-) -tkc From __peter__ at web.de Sun Dec 8 09:04:13 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 08 Dec 2013 15:04:13 +0100 Subject: Eliminate "extra" variable References: <20131206183721.3e7f21c2@bigbox.christie.dr> Message-ID: Tim Chase wrote: > On 2013-12-06 11:37, Igor Korot wrote: >> def MyFunc(self, originalData): >> data = {} >> for i in xrange(0, len(originalData)): >> dateStr, freq, source = originalData[i] >> data[str(dateStr)] = {source: freq} > > this can be more cleanly/pythonically written as > > def my_func(self, original_data): > for date, freq, source in original_data > data[str(date)] = {source: freq} > > or even just > > data = dict( > (str(date), {source: freq}) > for date, freq, source in original_data > ) or even just data = {str(date): {source: freq} for date, freq, source in original_data} But do you really need a dict with a single key? And is it even correct? If a date occurs twice only the last source:freq pair is kept. Without knowing the context the humble data = {} for date, freq, source in original_data: source_to_freq = data.setdefault(date, {}) if source in source_to_freq: raise ValueError( "Multiple frequencies for one source not supported") source_to_freq[source] = freq appears so much more plausible... > You're calling it a "dateStr", which suggests that it's already a > string, so I'm not sure why you're str()'ing it. So I'd either just > call it "date", or skip the str(date) bit if it's already a string. > That said, do you even need to convert it to a string (as > datetime.date objects can be used as keys in dictionaries)? > >> for i in xrange(0, len(dateStrs) - 1): >> currDateStr = str(dateStrs[i]) >> nextDateStrs = str(dateStrs[i + 1]) >> >> It seems very strange that I need the dateStrs list just for the >> purpose of looping thru the dictionary keys. >> Can I get rid of the "dateStrs" variable? > > Your code isn't actually using the data-dict at this point. If you > were doing something with it, it might help to know what you want to > do. > > Well, you can iterate over the original data, zipping them together: > > for (cur, _, _), (next, _, _) in zip( > original_data[:-1], > original_data[1:] > ): > do_something(cur, next) This reminds me that I am a proponent of small dumb helper functions ;) I find def sliding_window(items): a, b = itertools.tee(items) next(b, None) return zip(a, b) dates = (date for date, _freq, _source in original_data) for from_date, to_date in sliding_window(dates): do_something(from_date, to_date) much more accessible. Plus, I can apply arbitrary improvements to the sliding_window() implementation or switch to a library version of that function without fear of messing things up. Likewise, should original_data become a sequence of namedtuples it is straightforward to propagate this change with dates = (item.date for item in original_data) > If your purpose for the "data" dict is to merely look up stats from > the next one, the whole batch of your original code can be replaced > with: > > for ( > (cur_dt, cur_freq, cur_source), > (next_dt, next_freq, next_source) > ) in zip(original_data[:-1], original_data[1:]): > # might need to do str(cur_dt) and str(next_dt) instead? > do_things_with(cur_dt, cur_freq, cur_source, > next_dt, next_freq, next_source) > > That eliminates the dict *and* the extra variable name. :-) Smileys are overused ;) Anyway, with namedtuples this ... would become for cur_item, next_item in zip(original_data, original_data[1:]): do_things_with(cur_item, next_item) Note that there's no need to slice the first argument as zip() ignores extra items. From python.list at tim.thechases.com Sun Dec 8 13:58:20 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 8 Dec 2013 12:58:20 -0600 Subject: Eliminate "extra" variable In-Reply-To: References: <20131206183721.3e7f21c2@bigbox.christie.dr> Message-ID: <20131208125820.61ae927a@bigbox.christie.dr> On 2013-12-08 15:04, Peter Otten wrote: > > data = dict( > > (str(date), {source: freq}) > > for date, freq, source in original_data > > ) > > or even just > > data = {str(date): {source: freq} > for date, freq, source in original_data} I maintain enough pre-2.7 code that I tend to eschew dict-comprehensions for the time being. I like them as a language addition, but can't use them yet in most of the code-bases with which I work. To the OP, if you don't have to support pre-2.7 code, then this is a tidier way to go. > But do you really need a dict with a single key? And is it even > correct? If a date occurs twice only the last source:freq pair is > kept. Without knowing the context the humble > > data = {} > for date, freq, source in original_data: > source_to_freq = data.setdefault(date, {}) > if source in source_to_freq: > raise ValueError( > "Multiple frequencies for one source not supported") > source_to_freq[source] = freq > > appears so much more plausible... The OP's code didn't do any such sanity-checking so I made the assumption that the data came in clean. I know better than to trust incoming data (even my own) in my own code, but... (followup to the OP's reply elsewhere in the thread coming shortly) -tkc From breamoreboy at yahoo.co.uk Fri Dec 6 16:26:31 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 06 Dec 2013 21:26:31 +0000 Subject: Python 2.8 release schedule Message-ID: My apologies if you've seen this before but here is the official schedule http://www.python.org/dev/peps/pep-0404/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Fri Dec 6 20:39:57 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Dec 2013 20:39:57 -0500 Subject: Python 2.8 release schedule In-Reply-To: References: Message-ID: On 12/6/2013 4:26 PM, Mark Lawrence wrote: > My apologies if you've seen this before but here is the official > schedule http://www.python.org/dev/peps/pep-0404/ The PEP number is not an accident ;-). -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Fri Dec 6 20:48:57 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Dec 2013 01:48:57 +0000 Subject: Python 2.8 release schedule In-Reply-To: References: Message-ID: On 07/12/2013 01:39, Terry Reedy wrote: > On 12/6/2013 4:26 PM, Mark Lawrence wrote: >> My apologies if you've seen this before but here is the official >> schedule http://www.python.org/dev/peps/pep-0404/ > > The PEP number is not an accident ;-). Sorry but I don't get it :) -- 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 Fri Dec 6 20:54:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 12:54:34 +1100 Subject: Python 2.8 release schedule In-Reply-To: References: Message-ID: On Sat, Dec 7, 2013 at 12:48 PM, Mark Lawrence wrote: > On 07/12/2013 01:39, Terry Reedy wrote: >> >> On 12/6/2013 4:26 PM, Mark Lawrence wrote: >>> >>> My apologies if you've seen this before but here is the official >>> schedule http://www.python.org/dev/peps/pep-0404/ >> >> >> The PEP number is not an accident ;-). > > > Sorry but I don't get it :) HTTP error 404 "Not Found", probably the most famous (though not the most common) HTTP return code. You asked for Python 2.8? Sorry, not found... it's 404. ChrisA From breamoreboy at yahoo.co.uk Fri Dec 6 21:00:33 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Dec 2013 02:00:33 +0000 Subject: Python 2.8 release schedule In-Reply-To: References: Message-ID: On 07/12/2013 01:54, Chris Angelico wrote: > On Sat, Dec 7, 2013 at 12:48 PM, Mark Lawrence wrote: >> On 07/12/2013 01:39, Terry Reedy wrote: >>> >>> On 12/6/2013 4:26 PM, Mark Lawrence wrote: >>>> >>>> My apologies if you've seen this before but here is the official >>>> schedule http://www.python.org/dev/peps/pep-0404/ >>> >>> >>> The PEP number is not an accident ;-). >> >> >> Sorry but I don't get it :) > > HTTP error 404 "Not Found", probably the most famous (though not the > most common) HTTP return code. > > You asked for Python 2.8? Sorry, not found... it's 404. > > ChrisA > Clearly that went straight over your head. -- 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 Fri Dec 6 21:07:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 13:07:30 +1100 Subject: Python 2.8 release schedule In-Reply-To: References: Message-ID: On Sat, Dec 7, 2013 at 1:00 PM, Mark Lawrence wrote: > On 07/12/2013 01:54, Chris Angelico wrote: >> >> On Sat, Dec 7, 2013 at 12:48 PM, Mark Lawrence >> wrote: >>> Sorry but I don't get it :) >> >> [explained the joke] > > Clearly that went straight over your head. *facepalm* Yep, it did. Completely missed what you said there. Doh. I see what you did there... now. ChrisA From ethan at stoneleaf.us Fri Dec 6 22:23:06 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 06 Dec 2013 19:23:06 -0800 Subject: Python 2.8 release schedule In-Reply-To: References: Message-ID: <52A2949A.7020104@stoneleaf.us> On 12/06/2013 06:07 PM, Chris Angelico wrote: > On Sat, Dec 7, 2013 at 1:00 PM, Mark Lawrence wrote: >> On 07/12/2013 01:54, Chris Angelico wrote: >>> >>> On Sat, Dec 7, 2013 at 12:48 PM, Mark Lawrence >>> wrote: >>>> Sorry but I don't get it :) >>> >>> [explained the joke] >> >> Clearly that went straight over your head. > > *facepalm* Yep, it did. Completely missed what you said there. > > Doh. I see what you did there... now. Heh. It was too subtle for me, too. 'Course, I've been fighting OpenERP all day... -- ~Ethan~ From drsalists at gmail.com Fri Dec 6 18:54:22 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 6 Dec 2013 15:54:22 -0800 Subject: One liners Message-ID: Does anyone else feel like Python is being dragged too far in the direction of long, complex, multiline one-liners? Or avoiding temporary variables with descriptive names? Or using regex's for everything under the sun? What happened to using classes? What happened to the beautiful emphasis on readability? What happened to debuggability (which is always harder than writing things in the first place)? And what happened to string methods? I'm pleased to see Python getting more popular, but it feels like a lot of newcomers are trying their best to turn Python into Perl or something, culturally speaking. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Fri Dec 6 19:07:42 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 06 Dec 2013 19:07:42 -0500 Subject: One liners In-Reply-To: References: Message-ID: On 12/6/13 6:54 PM, Dan Stromberg wrote: > > Does anyone else feel like Python is being dragged too far in the > direction of long, complex, multiline one-liners? Or avoiding temporary > variables with descriptive names? Or using regex's for everything under > the sun? > > What happened to using classes? What happened to the beautiful emphasis > on readability? What happened to debuggability (which is always harder > than writing things in the first place)? And what happened to string > methods? > > I'm pleased to see Python getting more popular, but it feels like a lot > of newcomers are trying their best to turn Python into Perl or > something, culturally speaking. I agree with you that those trends would be bad. But I'm not sure how you are judging that "Python" is being dragged in that direction? It's a huge community. Sure some people are obsessed with fewer lines, and micro-optimizations, and other newb mistakes, but there are good people too! --Ned, ever the optimist. From torriem at gmail.com Fri Dec 6 19:10:11 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 06 Dec 2013 17:10:11 -0700 Subject: One liners In-Reply-To: References: Message-ID: <52A26763.3070803@gmail.com> On 12/06/2013 04:54 PM, Dan Stromberg wrote: > Does anyone else feel like Python is being dragged too far in the direction > of long, complex, multiline one-liners? Or avoiding temporary variables > with descriptive names? Or using regex's for everything under the sun? > > What happened to using classes? What happened to the beautiful emphasis on > readability? What happened to debuggability (which is always harder than > writing things in the first place)? And what happened to string methods? > > I'm pleased to see Python getting more popular, but it feels like a lot of > newcomers are trying their best to turn Python into Perl or something, > culturally speaking. I have not seen any evidence that this trend of yours is widespread. The Python code I come across seems pretty normal to me. Expressive and readable. Haven't seen any attempt to turn Python into Perl or that sort of thing. And I don't see that culture expressed on the list. Maybe I'm just blind... From drsalists at gmail.com Fri Dec 6 19:14:49 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 6 Dec 2013 16:14:49 -0800 Subject: One liners In-Reply-To: <52A26763.3070803@gmail.com> References: <52A26763.3070803@gmail.com> Message-ID: On Fri, Dec 6, 2013 at 4:10 PM, Michael Torrie wrote: > On 12/06/2013 04:54 PM, Dan Stromberg wrote: > > Does anyone else feel like Python is being dragged too far in the > direction > > of long, complex, multiline one-liners? Or avoiding temporary variables > > with descriptive names? Or using regex's for everything under the sun? > > > > What happened to using classes? What happened to the beautiful emphasis > on > > readability? What happened to debuggability (which is always harder than > > writing things in the first place)? And what happened to string methods? > > > > I'm pleased to see Python getting more popular, but it feels like a lot > of > > newcomers are trying their best to turn Python into Perl or something, > > culturally speaking. > > I have not seen any evidence that this trend of yours is widespread. > The Python code I come across seems pretty normal to me. Expressive and > readable. Haven't seen any attempt to turn Python into Perl or that > sort of thing. And I don't see that culture expressed on the list. > Maybe I'm just blind... I'm thinking mostly of stackoverflow, but here's an example I ran into (a lot of) on a job: somevar = some_complicated_thing(somevar) if some_other_complicated_thing(somevar) else somevar Would it really be so bad to just use an if statement? Why are we assigning somevar to itself? This sort of thing was strewn across 3 or 4 physical lines at a time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Fri Dec 6 19:20:27 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 06 Dec 2013 17:20:27 -0700 Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> Message-ID: <52A269CB.9080704@gmail.com> On 12/06/2013 05:14 PM, Dan Stromberg wrote: > I'm thinking mostly of stackoverflow, but here's an example I ran into (a > lot of) on a job: > > somevar = some_complicated_thing(somevar) if > some_other_complicated_thing(somevar) else somevar > > Would it really be so bad to just use an if statement? Why are we > assigning somevar to itself? This sort of thing was strewn across 3 or 4 > physical lines at a time. You're right that a conventional "if" block is not only more readable, but also faster and more efficient code. Sorry you have to deal with code written like that! That'd frustrate any sane programmer. It might bother me enough to write code to reformat the program to convert that style to something sane! There are times when the ternary (did I get that right?) operator is useful and clear. From joel.goldstick at gmail.com Fri Dec 6 19:39:50 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 6 Dec 2013 19:39:50 -0500 Subject: One liners In-Reply-To: <52A269CB.9080704@gmail.com> References: <52A26763.3070803@gmail.com> <52A269CB.9080704@gmail.com> Message-ID: On Fri, Dec 6, 2013 at 7:20 PM, Michael Torrie wrote: > On 12/06/2013 05:14 PM, Dan Stromberg wrote: > > I'm thinking mostly of stackoverflow, but here's an example I ran into (a > > lot of) on a job: > > > > somevar = some_complicated_thing(somevar) if > > some_other_complicated_thing(somevar) else somevar > > > > Would it really be so bad to just use an if statement? Why are we > > assigning somevar to itself? This sort of thing was strewn across 3 or 4 > > physical lines at a time. > > You're right that a conventional "if" block is not only more readable, > but also faster and more efficient code. Sorry you have to deal with > code written like that! That'd frustrate any sane programmer. It might > bother me enough to write code to reformat the program to convert that > style to something sane! There are times when the ternary (did I get > that right?) operator is useful and clear. > -- > https://mail.python.org/mailman/listinfo/python-list > While it seems to be a higher status in the team to write new code as compared to fixing old code, so much can be learned by having to plough through old code. To learn others coding style, pick up new understanding, and most importantly totally disabuse yourself of trying to be cute with code. Code is read by the machine and by the programmer. The programmer is the one who should be deferred to, imo. You buy the machine, you rent the programmer by the hour! Aside from django urls, I am not sure I ever wrote regexes in python. For some reason they must seem awfully sexy to quite a few people. Back to my point above -- ever try to figure out a complicated regex written by someone else? -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Fri Dec 6 19:56:54 2013 From: roy at panix.com (Roy Smith) Date: Fri, 06 Dec 2013 19:56:54 -0500 Subject: One liners References: <52A26763.3070803@gmail.com> <52A269CB.9080704@gmail.com> Message-ID: In article , Joel Goldstick wrote: > Aside from django urls, I am not sure I ever wrote regexes in python. For > some reason they must seem awfully sexy to quite a few people. Back to my > point above -- ever try to figure out a complicated regex written by > someone else? Regex has a bad rap in the Python community. To be sure, you can abuse them, and write horrible monstrosities. On the other hand, stuff like this (slightly reformatted for posting): pattern = re.compile( r'haproxy\[(?P\d+)]: ' r'(?P(\d{1,3}\.){3}\d{1,3}):' r'(?P\d{1,5}) ' r'\[(?P\d{2}/\w{3}/\d{4}(:\d{2}){3}\.\d{3})] ' r'(?P\S+) ' r'(?P\S+)/' r'(?P\S+) ' r'(?P(-1|\d+))/' r'(?P(-1|\d+))/' r'(?P(-1|\d+))/' r'(?P(-1|\d+))/' r'(?P\+?\d+) ' r'(?P\d{3}) ' r'(?P\d+) ' r'(?P\S+) ' r'(?P\S+) ' r'(?P[\w-]{4}) ' r'(?P\d+)/' r'(?P\d+)/' r'(?P\d+)/' r'(?P\d+)/' r'(?P\d+) ' r'(?P\d+)/' r'(?P\d+) ' r'(\{(?P.*?)\} )?' # Comment out for stock haproxy r'(\{(?P.*?)\} )?' r'(\{(?P.*?)\} )?' r'"(?P.+)"' ) while intimidating at first glance, really isn't that hard to understand. Python's raw string literals, adjacent string literal catenation, and automatic line continuation team up to eliminate a lot of extra fluff. From steve+comp.lang.python at pearwood.info Fri Dec 6 21:28:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2013 02:28:27 GMT Subject: One liners References: <52A26763.3070803@gmail.com> Message-ID: <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Dec 2013 17:20:27 -0700, Michael Torrie wrote: > On 12/06/2013 05:14 PM, Dan Stromberg wrote: >> I'm thinking mostly of stackoverflow, but here's an example I ran into >> (a lot of) on a job: >> >> somevar = some_complicated_thing(somevar) if >> some_other_complicated_thing(somevar) else somevar >> >> Would it really be so bad to just use an if statement? Why are we >> assigning somevar to itself? This sort of thing was strewn across 3 or >> 4 physical lines at a time. Unless you're embedding it in another statement, there's no advantage to using the ternary if operator if the clauses are so large you have to split the line over two or more lines in the first place. I agree that: result = (spam(x) + eggs(x) + toast(x) if x and condition(x) or another_condition(x) else foo(x) + bar(x) + foobar(x)) is probably better written as: if x and condition(x) or another_condition(x): result = spam(x) + eggs(x) + toast(x) else: result = foo(x) + bar(x) + foobar(x) The ternary if is slightly unusual and unfamiliar, and is best left for when you need an expression: ingredients = [spam, eggs, cheese, toast if flag else bread, tomato] As for your second complaint, "why are we assigning somevar to itself", I see nothing wrong with that. Better that than a plethora of variables used only once: # Screw this for a game of soldiers. def function(arg, param_as_list_or_string): if isinstance(param_as_list_or_string, str): param = param_as_list_or_string.split() else: param = param_as_list_or_string # Better. def function(arg, param): if isinstance(param, str): param = param.split() "Replace x with a transformed version of x" is a perfectly legitimate technique, and not one which ought to be too hard to follow. > You're right that a conventional "if" block is not only more readable, > but also faster and more efficient code. Really? I don't think so. This is using Python 2.7: [steve at ando ~]$ python -m timeit --setup="flag = 0" \ > "if flag: y=1 > else: y=2" 10000000 loops, best of 3: 0.0836 usec per loop [steve at ando ~]$ python -m timeit --setup="flag = 0" "y = 1 if flag else 2" 10000000 loops, best of 3: 0.0813 usec per loop There's practically nothing between the two, but the ternary if operator is marginally faster. As for readability, I accept that ternary if is unusual compared to other languages, but it's still quite readable in small doses. If you start chaining them: result = a if condition else b if flag else c if predicate else d you probably shouldn't. -- Steven From rosuav at gmail.com Fri Dec 6 21:40:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 13:40:13 +1100 Subject: One liners In-Reply-To: <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Dec 7, 2013 at 1:28 PM, Steven D'Aprano wrote: > As for readability, I accept that ternary if is unusual compared to other > languages... All the C-derived ternary operators put the condition first, but Python puts the condition in the middle. What that does for readability I don't really know. Which is more important? ChrisA From roy at panix.com Fri Dec 6 22:27:00 2013 From: roy at panix.com (Roy Smith) Date: Fri, 06 Dec 2013 22:27:00 -0500 Subject: One liners References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52a287cb$0$30003$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > The ternary if is slightly unusual and unfamiliar It's only unusual an unfamiliar if you're not used to using it :-) Coming from a C/C++ background, I always found the lack of a ternary expression rather limiting. There was much rejoicing in these parts when it was added to the language relatively recently. I use them a lot. On the other hand, I found list comprehensions to be mind-bogglingly confusing when I first saw them (read: slightly unusual and unfamiliar). It took me a long time to warm up to the concept. Now I love them. > As for readability, I accept that ternary if is unusual compared to other > languages, but it's still quite readable in small doses. If you start > chaining them: > > result = a if condition else b if flag else c if predicate else d > > you probably shouldn't. That I agree with (and it's just as true in C as it is in Python). Just for fun, I took a look through the Songza code base. 66 kloc of non-whitespace Python. I found 192 ternary expressions. Here's a few of the more bizarre ones (none of which I consider remotely readable): -------------------------------------------------- extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if tracks else [] -------------------------------------------------- c2s = compids2songs(set(targets.keys()) | set.union(*map(set,targets.itervalues())),self.docmap,self.logger) if targets else {} -------------------------------------------------- code = 2 if (pmp3,paac)==(mmp3,maac) else 3 if any(x is None for x in (pmp3,paac,mmp3,maac)) else 4 -------------------------------------------------- Anybody else have some fun ternary abuse examples? From rosuav at gmail.com Fri Dec 6 23:06:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Dec 2013 15:06:00 +1100 Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Dec 7, 2013 at 2:27 PM, Roy Smith wrote: > -------------------------------------------------- > extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if > tracks else [] > -------------------------------------------------- > c2s = compids2songs(set(targets.keys()) | > set.union(*map(set,targets.itervalues())),self.docmap,self.logger) if > targets else {} Easy rewrites: extracols = tracks and sorted(set.union(*(set(t.data.keys()) for t in tracks))) Assumes that tracks is a list, which it most likely is given the context. Parallel with the other. ChrisA From steve+comp.lang.python at pearwood.info Sat Dec 7 06:27:47 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2013 11:27:47 GMT Subject: One liners References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Dec 2013 22:27:00 -0500, Roy Smith wrote: > Just for fun, I took a look through the Songza code base. 66 kloc of > non-whitespace Python. I found 192 ternary expressions. Here's a few > of the more bizarre ones (none of which I consider remotely readable): > > -------------------------------------------------- > extracols = ( sorted(set.union(*(set(t.data.keys()) for t in tracks))) > if tracks else [] ) [extra parentheses added so I can split the line over two] I actually don't find that too bad, readability-wise. Not ideal, but I can follow it. However, I wonder why t.data.keys() is converted to a set before being unpacked? Even assuming that data.keys are not necessarily unique, wouldn't building the union make them so? extracols = ( sorted(set.union(*(t.data.keys()) for t in tracks))) if tracks else [] ) Also, you can get rid of the `if tracks` check altogether by using a bound method instead of an unbound method: extracols = sorted(set().union(*(t.data.keys()) for t in tracks)) ought to work even if tracks is empty. -- Steven From jpiitula at ling.helsinki.fi Sat Dec 7 07:41:17 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 07 Dec 2013 14:41:17 +0200 Subject: One liners References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Fri, 06 Dec 2013 22:27:00 -0500, Roy Smith wrote: > > > Just for fun, I took a look through the Songza code base. 66 kloc of > > non-whitespace Python. I found 192 ternary expressions. Here's a few > > of the more bizarre ones (none of which I consider remotely readable): > > > > -------------------------------------------------- > > extracols = ( sorted(set.union(*(set(t.data.keys()) for t in tracks))) > > if tracks else [] ) > > [extra parentheses added so I can split the line over two] > > I actually don't find that too bad, readability-wise. Not ideal, but I > can follow it. However, I wonder why t.data.keys() is converted to a set > before being unpacked? Even assuming that data.keys are not necessarily > unique, wouldn't building the union make them so? > > extracols = ( sorted(set.union(*(t.data.keys()) for t in tracks))) > if tracks else [] ) > > > Also, you can get rid of the `if tracks` check altogether by using a > bound method instead of an unbound method: > > extracols = sorted(set().union(*(t.data.keys()) for t in tracks)) > > ought to work even if tracks is empty. I suspect in the original code tracks could be None (or False) and then the part of the code that bombs is 'for t in tracks' because tracks is not iterable. One could write [f(t) for t in tracks or []] and it wouldn't be blamed on a binary operator - or maybe it would - but I suspect the cleaner design would be to first make sure that an empty tracks is an empty list (or an empty whatever-it-needs-to-be): if tracks is None: tracks = [] ... extracols = sorted(set.union(*(t.data.keys()) for t in tracks)) Still, is t.data.keys() a collection of sets? Maybe frozensets? And then their unions are being sorted by set inclusion, which is not a total order. Does sorted work correctly with a partial order? I don't think it does. From sg552 at hotmail.co.uk Sat Dec 7 11:13:09 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Sat, 07 Dec 2013 16:13:09 +0000 Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/12/2013 12:41, Jussi Piitulainen wrote: > [...] > > if tracks is None: > tracks = [] Sorry to go off on a tangent, but in my code I often have stuff like this at the start of functions: tracks = something if tracks is None else tracks or, in the case where I don't intend for the function to be passed non-default Falsey values: tracks = tracks or something Is there any reason why the two-line version that avoids the ternary operator should be preferred to the above? From torriem at gmail.com Sat Dec 7 11:26:42 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Dec 2013 09:26:42 -0700 Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52A34C42.9040408@gmail.com> On 12/07/2013 09:13 AM, Rotwang wrote: > On 07/12/2013 12:41, Jussi Piitulainen wrote: >> [...] >> >> if tracks is None: >> tracks = [] > > Sorry to go off on a tangent, but in my code I often have stuff like > this at the start of functions: > > tracks = something if tracks is None else tracks > > or, in the case where I don't intend for the function to be passed > non-default Falsey values: > > tracks = tracks or something > > Is there any reason why the two-line version that avoids the ternary > operator should be preferred to the above? I think for such a short operation, and for a common need like this, what you do is fine. Personally I prefer the part you quoted from Jussi, but your examples are just fine for correctness and readability. I think Dan's gripes come when cleverness is taken to the extreme. From steve+comp.lang.python at pearwood.info Sat Dec 7 11:25:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2013 16:25:07 GMT Subject: One liners References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52a34be2$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Dec 2013 16:13:09 +0000, Rotwang wrote: > On 07/12/2013 12:41, Jussi Piitulainen wrote: >> [...] >> >> if tracks is None: >> tracks = [] > > Sorry to go off on a tangent, but in my code I often have stuff like > this at the start of functions: > > tracks = something if tracks is None else tracks > > or, in the case where I don't intend for the function to be passed > non-default Falsey values: > > tracks = tracks or something > > Is there any reason why the two-line version that avoids the ternary > operator should be preferred to the above? Only if you need to support Python 2.4, which doesn't have the ternary if operator :-) -- Steven From sg552 at hotmail.co.uk Sat Dec 7 21:23:49 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Sun, 08 Dec 2013 02:23:49 +0000 Subject: One liners In-Reply-To: <52a34be2$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a34be2$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/12/2013 16:25, Steven D'Aprano wrote: > On Sat, 07 Dec 2013 16:13:09 +0000, Rotwang wrote: > >> On 07/12/2013 12:41, Jussi Piitulainen wrote: >>> [...] >>> >>> if tracks is None: >>> tracks = [] >> >> Sorry to go off on a tangent, but in my code I often have stuff like >> this at the start of functions: >> >> tracks = something if tracks is None else tracks >> >> or, in the case where I don't intend for the function to be passed >> non-default Falsey values: >> >> tracks = tracks or something >> >> Is there any reason why the two-line version that avoids the ternary >> operator should be preferred to the above? > > Only if you need to support Python 2.4, which doesn't have the ternary if > operator :-) Thanks, and likewise to everyone else who replied. From jpiitula at ling.helsinki.fi Sat Dec 7 12:49:57 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 07 Dec 2013 19:49:57 +0200 Subject: One liners References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Rotwang writes: > On 07/12/2013 12:41, Jussi Piitulainen wrote: > > [...] > > > > if tracks is None: > > tracks = [] > > Sorry to go off on a tangent, but in my code I often have stuff like > this at the start of functions: > > tracks = something if tracks is None else tracks > > or, in the case where I don't intend for the function to be passed > non-default Falsey values: > > tracks = tracks or something > > Is there any reason why the two-line version that avoids the ternary > operator should be preferred to the above? My motivation is that the "one-armed if" highlights the condition, together with the fact that nothing is changed unless the condition holds. That said, I'm also fine with the forms you use. On another tangent, I wish people called the conditional expression the conditional expression. The number of its slots is about the least salient property of the thing. :) From tjreedy at udel.edu Sat Dec 7 16:02:26 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Dec 2013 16:02:26 -0500 Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/7/2013 11:13 AM, Rotwang wrote: > On 07/12/2013 12:41, Jussi Piitulainen wrote: >> [...] >> >> if tracks is None: >> tracks = [] > > Sorry to go off on a tangent, but in my code I often have stuff like > this at the start of functions: > > tracks = something if tracks is None else tracks > > or, in the case where I don't intend for the function to be passed > non-default Falsey values: > > tracks = tracks or something > > Is there any reason why the two-line version that avoids the ternary > operator should be preferred to the above? The 'extra' line is not necessary, as one can write if tracks is None: tracks = [] # or something I prefer this because it exactly expresses what one want done. The other branch else: tracks = tracks is superfluous and to me unaesthetic. -- Terry Jan Reedy From torriem at gmail.com Sat Dec 7 11:56:04 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Dec 2013 09:56:04 -0700 Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52A35324.9050504@gmail.com> On 12/06/2013 08:27 PM, Roy Smith wrote: > In article <52a287cb$0$30003$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> The ternary if is slightly unusual and unfamiliar > > It's only unusual an unfamiliar if you're not used to using it :-) > Coming from a C/C++ background, I always found the lack of a ternary > expression rather limiting. There was much rejoicing in these parts > when it was added to the language relatively recently. I use them a lot. > > On the other hand, I found list comprehensions to be mind-bogglingly > confusing when I first saw them (read: slightly unusual and unfamiliar). > It took me a long time to warm up to the concept. Now I love them. > >> As for readability, I accept that ternary if is unusual compared to other >> languages, but it's still quite readable in small doses. If you start >> chaining them: >> >> result = a if condition else b if flag else c if predicate else d >> >> you probably shouldn't. > > That I agree with (and it's just as true in C as it is in Python). > > Just for fun, I took a look through the Songza code base. 66 kloc of > non-whitespace Python. I found 192 ternary expressions. Here's a few > of the more bizarre ones (none of which I consider remotely readable): > > -------------------------------------------------- > extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if > tracks else [] This is a generator expressions, and ternary ifs are common and often needed in generator expressions. > -------------------------------------------------- > c2s = compids2songs(set(targets.keys()) | > set.union(*map(set,targets.itervalues())),self.docmap,self.logger) if > targets else {} I suspect the ternary distracted you on this one. The ternary here is needed because if targets is None the expression fails. This part anyway is a common idiom. The rest is basically making a set (list of unique items only) of the combined keys and values from the "targets" dictionary. Now I'm not sure why the programmer needs do this, but nevertheless that's what it's doing. set.union is used because that can iterate over a list of sets, which is what the map returns. I suppose they could have done this, but it wouldn't be much clearer unless you knew what sets, map and itervalues do: if targets: c2s = compids2songs( set(targets.keys()) | set.union(*map(set,targets.itervalues())), self.docmap, self.logger ) else: c2s = {} In any case the ternary operator isn't really the part you were complaining about. Personally if I needed to do this particular operation a lot (combine keys and values into a set), I'd write a function that returned the set. Still can't avoid the ternary, though, unless you made compids2songs a little smarter (and we don't know what compids2songs does with an empty set): def dict_keys_and_values_set (some_dict): return set(some_dict.keys()) | set.union(*map(set,some_dict.itervalues())) c2s = compids2songs( dict_keys_and_values_set(targets) ) if targets else {} or I suppose you could o this: c2s = {} if targets: c2s = compids2songs( dict_keys_and_values_set(targets) ) Just a matter of taste. > -------------------------------------------------- > code = 2 if (pmp3,paac)==(mmp3,maac) else 3 if any(x is None for x in > (pmp3,paac,mmp3,maac)) else 4 > -------------------------------------------------- This one probably could stand to be reworked for sure! A standard if block would be much clearer. Definitely an example of a programmer thinking he was clever... maybe a git bisect could identify the author and we can shame him. > Anybody else have some fun ternary abuse examples? Only the last one seems to be problematic to me. From torriem at gmail.com Sat Dec 7 12:02:27 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Dec 2013 10:02:27 -0700 Subject: One liners In-Reply-To: <52A35324.9050504@gmail.com> References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52A35324.9050504@gmail.com> Message-ID: <52A354A3.1050904@gmail.com> On 12/07/2013 09:56 AM, Michael Torrie wrote: >> extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if >> tracks else [] > > This is a generator expressions, and ternary ifs are common and often > needed in generator expressions. Oops. This is not a generator expression at all! From rustompmody at gmail.com Sat Dec 7 12:10:50 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 7 Dec 2013 09:10:50 -0800 (PST) Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9052b1e1-7113-4dd9-8450-c04768ec559d@googlegroups.com> On Saturday, December 7, 2013 10:26:04 PM UTC+5:30, Michael Torrie wrote: > On 12/06/2013 08:27 PM, Roy Smith wrote: > > Steven D'Aprano wrote: > >> The ternary if is slightly unusual and unfamiliar > > It's only unusual an unfamiliar if you're not used to using it :-) > > Coming from a C/C++ background, I always found the lack of a ternary > > expression rather limiting. There was much rejoicing in these parts > > when it was added to the language relatively recently. I use them a lot. > > On the other hand, I found list comprehensions to be mind-bogglingly > > confusing when I first saw them (read: slightly unusual and unfamiliar). > > It took me a long time to warm up to the concept. Now I love them. > >> As for readability, I accept that ternary if is unusual compared to other > >> languages, but it's still quite readable in small doses. If you start > >> chaining them: > >> result = a if condition else b if flag else c if predicate else d > >> you probably shouldn't. > > That I agree with (and it's just as true in C as it is in Python). > > Just for fun, I took a look through the Songza code base. 66 kloc of > > non-whitespace Python. I found 192 ternary expressions. Here's a few > > of the more bizarre ones (none of which I consider remotely readable): > > -------------------------------------------------- > > extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if > > tracks else [] > This is a generator expressions, and ternary ifs are common and often > needed in generator expressions. > > -------------------------------------------------- > > c2s = compids2songs(set(targets.keys()) | > > set.union(*map(set,targets.itervalues())),self.docmap,self.logger) if > > targets else {} > I suspect the ternary distracted you on this one. The ternary here is > needed because if targets is None the expression fails. This part > anyway is a common idiom. > The rest is basically making a set (list of unique items only) of the > combined keys and values from the "targets" dictionary. Now I'm not > sure why the programmer needs do this, but nevertheless that's what it's > doing. set.union is used because that can iterate over a list of sets, > which is what the map returns. I suppose they could have done this, but > it wouldn't be much clearer unless you knew what sets, map and > itervalues do: > if targets: > c2s = compids2songs( > set(targets.keys()) | > set.union(*map(set,targets.itervalues())), > self.docmap, > self.logger ) > else: > c2s = {} > In any case the ternary operator isn't really the part you were > complaining about. Personally if I needed to do this particular > operation a lot (combine keys and values into a set), I'd write a > function that returned the set. Still can't avoid the ternary, though, > unless you made compids2songs a little smarter (and we don't know what > compids2songs does with an empty set): > def dict_keys_and_values_set (some_dict): > return set(some_dict.keys()) | > set.union(*map(set,some_dict.itervalues())) > c2s = compids2songs( dict_keys_and_values_set(targets) ) if targets else {} > or I suppose you could o this: > c2s = {} > if targets: c2s = compids2songs( dict_keys_and_values_set(targets) ) > Just a matter of taste. > > -------------------------------------------------- > > code = 2 if (pmp3,paac)==(mmp3,maac) else 3 if any(x is None for x in > > (pmp3,paac,mmp3,maac)) else 4 > > -------------------------------------------------- Just trying to rewrite that in a way which I try to use for long if-exprs code = 2 if (pmp3,paac)==(mmp3,maac) else 3 if any(x is None for x in (pmp3,paac,mmp3,maac)) else 4 > This one probably could stand to be reworked for sure! A standard if > block would be much clearer. Definitely an example of a programmer > thinking he was clever... maybe a git bisect could identify the author > and we can shame him. The logic for writing (and hopefully reading) it this way is like this: In math we often have equations that are defined by cases -- typically typeset with a large curly bracket. Those else's hanging at the end are to be read as a signal to read this whole expr and though under a big curly brace. From rasmussen.bryan at gmail.com Sat Dec 7 19:41:13 2013 From: rasmussen.bryan at gmail.com (bryan rasmussen) Date: Sun, 8 Dec 2013 01:41:13 +0100 Subject: One liners In-Reply-To: References: <52A26763.3070803@gmail.com> Message-ID: Someone was thinking in ruby there. On Sat, Dec 7, 2013 at 1:14 AM, Dan Stromberg wrote: > > On Fri, Dec 6, 2013 at 4:10 PM, Michael Torrie wrote: > >> On 12/06/2013 04:54 PM, Dan Stromberg wrote: >> > Does anyone else feel like Python is being dragged too far in the >> direction >> > of long, complex, multiline one-liners? Or avoiding temporary variables >> > with descriptive names? Or using regex's for everything under the sun? >> > >> > What happened to using classes? What happened to the beautiful >> emphasis on >> > readability? What happened to debuggability (which is always harder >> than >> > writing things in the first place)? And what happened to string >> methods? >> > >> > I'm pleased to see Python getting more popular, but it feels like a lot >> of >> > newcomers are trying their best to turn Python into Perl or something, >> > culturally speaking. >> >> I have not seen any evidence that this trend of yours is widespread. >> The Python code I come across seems pretty normal to me. Expressive and >> readable. Haven't seen any attempt to turn Python into Perl or that >> sort of thing. And I don't see that culture expressed on the list. >> Maybe I'm just blind... > > > I'm thinking mostly of stackoverflow, but here's an example I ran into (a > lot of) on a job: > > somevar = some_complicated_thing(somevar) if > some_other_complicated_thing(somevar) else somevar > > Would it really be so bad to just use an if statement? Why are we > assigning somevar to itself? This sort of thing was strewn across 3 or 4 > physical lines at a time. > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Dec 6 21:07:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2013 02:07:13 GMT Subject: One liners References: Message-ID: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Dec 2013 15:54:22 -0800, Dan Stromberg wrote: > Does anyone else feel like Python is being dragged too far in the > direction of long, complex, multiline one-liners? Or avoiding temporary > variables with descriptive names? Or using regex's for everything under > the sun? All those things are stylistic issues, not language issues. Yes, I see far too many people trying to squeeze three lines of code into one, but that's their choice, not the language leading them that way. On the other hand, Python code style is influenced strongly by functional languages like Lisp, Scheme and Haskell (despite the radically different syntax). Python has even been described approvingly as "Lisp without the brackets". To somebody coming from a C or Pascal procedural background, or a Java OOP background, such functional-style code might seem too concise and/or weird. But frankly, I think that such programmers would write better code with a more functional approach. I refuse to apologise for writing the one-liner: result = [func(item) for item in sequence] instead of four: result = [] for i in range(len(sequence)): item = sequence[i] result.append(func(item)) > What happened to using classes? What happened to the beautiful emphasis > on readability? What happened to debuggability (which is always harder > than writing things in the first place)? And what happened to string > methods? What about string methods? As far as classes go, I find that they're nearly always overkill. Most of the time, a handful of pre-written standard classes, like dict, list, namedtuple and the like, get me 90% of the way to where I need to go. The beauty of Python is that it is a multi-paradigm language. You can write imperative, procedural, functional, OOP, or pipelining style (and probably more). The bad thing about Python is that if you're reading other people's code you *need* to be familiar with all those styles. > I'm pleased to see Python getting more popular, but it feels like a lot > of newcomers are trying their best to turn Python into Perl or > something, culturally speaking. They're probably writing code using the idioms they are used to from whatever language they have come from. Newcomers nearly always do this. The more newcomers you get, the less Pythonic the code you're going to see from them. -- Steven From drsalists at gmail.com Fri Dec 6 22:20:07 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 6 Dec 2013 19:20:07 -0800 Subject: One liners In-Reply-To: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Dec 6, 2013 at 6:07 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Fri, 06 Dec 2013 15:54:22 -0800, Dan Stromberg wrote: > > > Does anyone else feel like Python is being dragged too far in the > > direction of long, complex, multiline one-liners? Or avoiding temporary > > variables with descriptive names? Or using regex's for everything under > > the sun? > > All those things are stylistic issues, not language issues. Yes, I see > far too many people trying to squeeze three lines of code into one, but > that's their choice, not the language leading them that way. > Yes, stylistic, or even "cultural". > I refuse to apologise > for writing the one-liner: > > result = [func(item) for item in sequence] > > instead of four: > > result = [] > for i in range(len(sequence)): > item = sequence[i] > result.append(func(item)) > IMO, this is a time when the one liner is more clear. But if you start trying to stretch that to extremes, it becomes worse instead of better. > > > What happened to using classes? What happened to the beautiful emphasis > > on readability? What happened to debuggability (which is always harder > > than writing things in the first place)? And what happened to string > > methods? > > What about string methods? > A lot of things people do with regex's, could be done with string methods more clearly and concisely. The beauty of Python is that it is a multi-paradigm language. You can > write imperative, procedural, functional, OOP, or pipelining style (and > probably more). The bad thing about Python is that if you're reading > other people's code you *need* to be familiar with all those styles. > That's fine. That's appropriate. But I imagine any of these can be done with the intention of being more clever than clear. BTW, what's pipelining style? Like bash? > I'm pleased to see Python getting more popular, but it feels like a lot > of newcomers are trying their best to turn Python into Perl or > something, culturally speaking. They're probably writing code using the idioms they are used to from > whatever language they have come from. Newcomers nearly always do this. > The more newcomers you get, the less Pythonic the code you're going to > see from them. > Nod. -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Mon Dec 9 08:49:24 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 9 Dec 2013 13:49:24 +0000 (UTC) Subject: One liners References: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-12-07, Dan Stromberg wrote: > BTW, what's pipelining style? Like bash? I think, in Python, it might refer to composing your program of a series of generators. names = (p.name for p in db.query_people() if p.total_purchases > 0) names = (n.upper() for n in names) names = (n for n in names if not n.startswith("Q")) for n in names: # Finally actually do something. Coincidentally it's a nice way to break up an ugly one-liner. I also really like that if I choose to no longer filter out customers whose name begins with Q, I can just comment out that one line. Try doing that with the one-liner version! >> I'm pleased to see Python getting more popular, but it feels >> like a lot of newcomers are trying their best to turn Python >> into Perl or something, culturally speaking. > >> They're probably writing code using the idioms they are used >> to from whatever language they have come from. Newcomers >> nearly always do this. The more newcomers you get, the less >> Pythonic the code you're going to see from them. > > Nod. That's the sound of practicality slapping purity with a fish. A new Python programmer can generally just get her code working in a fairly comfortable way, then possibly rewrite it once her first few programs become horrifying years later. I haven't found time to rewrite all of mine yet. I still have a program I use almost every day with an __init__ that returns invalid objects but helpfully sets self.valid to 0. -- Neil Cerutti From rosuav at gmail.com Mon Dec 9 08:59:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 00:59:23 +1100 Subject: One liners In-Reply-To: References: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Dec 10, 2013 at 12:49 AM, Neil Cerutti wrote: > names = (p.name for p in db.query_people() if p.total_purchases > 0) > names = (n.upper() for n in names) > names = (n for n in names if not n.startswith("Q")) > for n in names: > # Finally actually do something. > > Coincidentally it's a nice way to break up an ugly one-liner. I > also really like that if I choose to no longer filter out > customers whose name begins with Q, I can just comment out that > one line. Try doing that with the one-liner version! # With the restriction: for n in (p.name.upper() for n in names if not n.startswith("Q")): # Without the restriction: for n in (p.name.upper() for n in names ):# if not n.startswith("Q")): You just have to use the special "comment-out-partially" operator, which looks like "):#" and is inspired by some kind of insane smiley with weird hair. ChrisA (Anyone got the cheek de-tonguer handy?) From roy at panix.com Fri Dec 6 22:53:07 2013 From: roy at panix.com (Roy Smith) Date: Fri, 06 Dec 2013 22:53:07 -0500 Subject: One liners References: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Dan Stromberg wrote: > A lot of things people do with regex's, could be done with string methods > more clearly and concisely. That is true. The problem is, there are a lot of things for which regex is the right tool, but people get out of practice using them (or never learned how) because they gravitate to string methods for most tasks. It's like any sharp tool. When skillfully handled, they're excellent at the tasks they were designed for. But, if you don't practice the necessary skills, you end up just re-enacting the Black Night Sketch. From steve at pearwood.info Mon Dec 9 22:36:57 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Dec 2013 03:36:57 GMT Subject: One liners References: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52a68c59$0$2829$c3e8da3$76491128@news.astraweb.com> On Fri, 06 Dec 2013 19:20:07 -0800, Dan Stromberg wrote: > On Fri, Dec 6, 2013 at 6:07 PM, Steven D'Aprano < > steve+comp.lang.python at pearwood.info> wrote: >> The beauty of Python is that it is a multi-paradigm language. You can >> write imperative, procedural, functional, OOP, or pipelining style (and >> probably more). The bad thing about Python is that if you're reading >> other people's code you *need* to be familiar with all those styles. >> >> > That's fine. That's appropriate. But I imagine any of these can be > done with the intention of being more clever than clear. > > BTW, what's pipelining style? Like bash? Yes, correct. You have a data stream and you pass it through various filters to process it. David Beazley has some nice examples of writing pipelining code: http://www.dabeaz.com/generators/index.html -- Steven From breamoreboy at yahoo.co.uk Sat Dec 7 16:10:30 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 07 Dec 2013 21:10:30 +0000 Subject: One liners In-Reply-To: References: Message-ID: On 06/12/2013 23:54, Dan Stromberg wrote: > > Does anyone else feel like Python is being dragged too far in the > direction of long, complex, multiline one-liners? Or avoiding temporary > variables with descriptive names? Or using regex's for everything under > the sun? > > What happened to using classes? What happened to the beautiful emphasis > on readability? What happened to debuggability (which is always harder > than writing things in the first place)? And what happened to string > methods? > > I'm pleased to see Python getting more popular, but it feels like a lot > of newcomers are trying their best to turn Python into Perl or > something, culturally speaking. > I see all of the above as being down to poor quality programmers who are new to Python and have their priorities wrong. The following is extracted from Steve Maguire's "Writing Solid Code". It's my belief that this is a reasonable summing up. Jack's Priority List Jill's Priority List Correctness Correctness Global efficiency Testability Size Global efficiency Local efficiency Maintainability/clarity Personal convenience Consistency Maintainability/clarity Size Personal expression Local efficiency Testability Personal expression Consistency Personal convenience Jill wants to write good quality, Pythonic code, Jack doesn't, yep? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From d.joshi84 at gmail.com Sat Dec 7 03:53:04 2013 From: d.joshi84 at gmail.com (Unix SA) Date: Sat, 7 Dec 2013 14:23:04 +0530 Subject: New Project for rpm spec file creation Message-ID: Hello Guys, I am starting new project on github for rpm spec file creation .. currently repository is empty and i am looking for ideas from the people who are experts in creating rpms for different applications .... please share your ideas to me .. . currently what i know is i can have some template file for .SPEC file and i can ask some inputs from users and update that template file .. but looks like there are lot of template i will have to look in .. so if you got any better idea, please clone my repository and help to contribute.. .. or just reply back with your ideas.. Thanks in advance. https://github.com/dhajoshi/rpm-spec-generator Regards, DJ -------------- next part -------------- An HTML attachment was scrubbed... URL: From advanced.world.unlimited at gmail.com Sat Dec 7 07:41:28 2013 From: advanced.world.unlimited at gmail.com (Eamonn Rea) Date: Sat, 7 Dec 2013 12:41:28 +0000 Subject: Centring text in a rect in PyGame? Message-ID: <2BF41548-E665-4678-ACDE-2222C07C3E78@gmail.com> First of all. I?d like to say I have no idea how these ?mailing lists? work, so I don?t know if this?ll come through right, but we?ll see I guess :-) I?m coming from the Google Group comp.lang.python, and was suggested to use this instead. Assuming attachments and images work, you should have an image of my code?s result and the attached code files. Anyway, I have a problem. In my game, I want to draw a button. I?ve gotten the button to draw fine, but I want some text on the button. I?ve gotten the text to draw, but I can?t get it to centre into the button. Here?s the code I?ve used: self.surface.blit(self.button_text, (self.width / 2 - self.button_text.get_width() / 2, self.height / 2 - self.button_text.get_height() / 2)) self.width is the width of the button, and same goes for self.height. self.button_text is a surface, so I can just call get_width() and get_height() on it because it?s a surface I believe. Here?s the code for drawing the button and it?s border (I have a little border around the button because it?s how I want it to look for my game): pygame.draw.rect( self.surface, self.button_color, Rect((self.x, self.y), (self.width, self.height))) pygame.draw.rect( self.surface, self.border_color, Rect((self.x, self.y), (self.width, self.height)), self.border_width) I really don?t know why it isn?t centring it. Here?s an image of what I get as a result: Code files should be attached :-) Thanks! Any help is appreciated! My code is formatted the way it is due to my Sublime Text 2 PEP8 auto formatter. I quite like it, actually, and sorry if you find it hard to read :/ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Screen Shot 2013-12-07 at 12.34.22.jpg Type: image/jpg Size: 35776 bytes Desc: not available URL: -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: button.py Type: text/x-python-script Size: 1726 bytes Desc: not available URL: -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: main.py Type: text/x-python-script Size: 1486 bytes Desc: not available URL: -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Sun Dec 8 09:06:04 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 08 Dec 2013 14:06:04 +0000 Subject: Centring text in a rect in PyGame? In-Reply-To: <2BF41548-E665-4678-ACDE-2222C07C3E78@gmail.com> References: <2BF41548-E665-4678-ACDE-2222C07C3E78@gmail.com> Message-ID: <52A47CCC.5060206@timgolden.me.uk> On 07/12/2013 12:41, Eamonn Rea wrote: > First of all. I?d like to say I have no idea how these ?mailing lists? > work, so I don?t know if this?ll come through right, but we?ll see I > guess :-) I?m coming from the Google Group comp.lang.python, and was > suggested to use this instead. Assuming attachments and images work, you > should have an image of my code?s result and the attached code files. [... snip HTML text, images & attached code files ...] Hi Eamonn. I'm one of the list owners so this reply is about list etiquette rather than the pygame issue you're having :) I'm taking advantage of your self-professed ignorance to make some general points which other might find helpful. I hope you don't mind. First: python-list mirrors comp.lang.python and vice versa (either via nntp or via Google Groups). However GG has, for the last while, been responsible for disrupting the text it passes through -- extra line spaces etc. -- with the result that mailing list or newsgroup readers find it very frustrating to read GG-formatted versions of messages. I expect that's why you were pointed towards the mailing list. It's also possible to access via comp.lang.python on Usenet; or comp.python.general on gmane. In general, while it's technically possible to post screenshots and to attach code files to the mailing list, it's not encouraged. At least partly that's because those who read via Usenet probably won't see them. Even those of us reading via mailing list may find it harder to read your post if it's spread out among multiple files. And to complete the list, you should post in plain text rather than HTML or rich-text. For much the same reasons. In short, the mailing list and the newsgroup it mirrors are best treated as plain text only. Another reason for discouraging screen / code dumps is that the very fact of narrowing down a small, repeatable segment of code with which to illustrate the issue can actually lead to your seeing the problem anyway! Even if it doesn't it's *much* easier for the other list members to comprehend / try out a small code segment than to read through your whole code. If push comes to shove, you can post code on a pastebin service -- but that is frowned upon by some, both because of the need to link to an unknown URL and because the code you post may not be there in 2 years time when someone having the same issue is following this thread to find help! TJG From rustompmody at gmail.com Sun Dec 8 10:39:57 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 07:39:57 -0800 (PST) Subject: Centring text in a rect in PyGame? In-Reply-To: References: <2BF41548-E665-4678-ACDE-2222C07C3E78@gmail.com> Message-ID: <1812b2ad-4bf0-4a82-97dd-d1af39bff68c@googlegroups.com> On Sunday, December 8, 2013 7:36:04 PM UTC+5:30, Tim Golden wrote: > On 07/12/2013 12:41, Eamonn Rea wrote: > > First of all. Id like to say I have no idea how these mailing lists > > work, so I dont know if this'll come through right, but we'll see I > > guess :-) I'm coming from the Google Group comp.lang.python, and was > > suggested to use this instead. Assuming attachments and images work, you > > should have an image of my code???s result and the attached code files. Hi Eamonn There are some new instructions/suggestions to make google groups easier on you (and other readers!) https://wiki.python.org/moin/GoogleGroupsPython If you try them and they work (or even if they dont!) please let me know. Particularly note the new section at the end https://wiki.python.org/moin/GoogleGroupsPython#Automatic_correction_.28EXPERIMENTAL.29 From mail at timgolden.me.uk Sun Dec 8 10:42:44 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 08 Dec 2013 15:42:44 +0000 Subject: Centring text in a rect in PyGame? In-Reply-To: <2BF41548-E665-4678-ACDE-2222C07C3E78@gmail.com> References: <2BF41548-E665-4678-ACDE-2222C07C3E78@gmail.com> Message-ID: <52A49374.90302@timgolden.me.uk> On 07/12/2013 12:41, Eamonn Rea wrote: > Anyway, I have a problem. In my game, I want to draw a button. I?ve > gotten the button to draw fine, but I want some text on the button. I?ve > gotten the text to draw, but I can?t get it to centre into the button. > Here?s the code I?ve used: > > *self.surface.blit(self.button_text, (self.width / 2 - > self.button_text.get_width() / 2, self.height / 2 - > self.button_text.get_height() / 2))* Side-stepping your actual code, here's a handy thing in pygame. You can center one rect on another to achieve the same effect without bothering with the (x - y) / 2 stuff. import pygame pygame.init() # # For demo purposes, the button is the whole window # button = pygame.display.set_mode((400, 320)) # # Create 12-point text in white saying "Hello, World!" # font = pygame.font.Font(pygame.font.get_default_font(), 12) text = font.render("Hello, World!", True, (0xff, 0xff, 0xff)) # # Use the text's rect to get width / height # Then center that rect on the target surface # text_rect = text.get_rect() text_rect.center = button.get_rect().center button.blit(text, text_rect) pygame.display.flip() TJG From jeandubois314 at gmail.com Sat Dec 7 11:52:08 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sat, 7 Dec 2013 08:52:08 -0800 (PST) Subject: [newbie] struggling wth tkinter Message-ID: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message. However the "main" window which should let you enter the numbers is not shown. This is the quit error message: Traceback (most recent call last): File "./feet2meters.py", line 3, in from tkinter import ttk ImportError: cannot import name ttk This is the code: #!/usr/bin/env python from tkinter import * from tkinter import ttk def calculate(*args): try: value = float(feet.get()) meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0) except ValueError: pass root = Tk() root.title("Feet to Meters") mainframe = ttk.Frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) feet = StringVar() meters = StringVar() feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet) feet_entry.grid(column=2, row=1, sticky=(W, E)) ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E)) ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W) ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W) ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E) ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W) for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) feet_entry.focus() root.bind('', calculate) root.mainloop() thanks in advance jean From davea at davea.name Sat Dec 7 13:12:50 2013 From: davea at davea.name (Dave Angel) Date: Sat, 07 Dec 2013 13:12:50 -0500 Subject: [newbie] struggling wth tkinter In-Reply-To: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois wrote: > I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message. > However the "main" window which should let you enter the numbers is not shown. > This is the quit error message: > Traceback (most recent call last): > File "./feet2meters.py", line 3, in > from tkinter import ttk > ImportError: cannot import name ttk > This is the code: > #!/usr/bin/env python > from tkinter import * > from tkinter import ttk Thanks for supplying the complete traceback. But you should also tell the python version and what OS. I'll guess python 3.3 on Linux. Finally, what version tk are you running? These widgets were introduced in tk 8.5 Since it failed on the second import, none of the rest of the code matters. However, since you're not running it from a terminal window, it's conceivable that your ide is affecting the result. -- DaveA From tjreedy at udel.edu Sat Dec 7 16:11:35 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Dec 2013 16:11:35 -0500 Subject: [newbie] struggling wth tkinter In-Reply-To: References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: On 12/7/2013 1:12 PM, Dave Angel wrote: > On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois > wrote: >> I'm trying to go through a tutorial on tkinter which has the code > below as an example. The only thing I see when running it is a little > popup with "Click mouse here to quit" which works as expected but always > shows the following error-message. >> However the "main" window which should let you enter the numbers is > not shown. >> This is the quit error message: >> Traceback (most recent call last): >> File "./feet2meters.py", line 3, in >> from tkinter import ttk >> ImportError: cannot import name ttk That is supposed to work. >> This is the code: >> #!/usr/bin/env python >> from tkinter import * >> from tkinter import ttk > > Thanks for supplying the complete traceback. But you should also tell > the python version and what OS. I'll guess python 3.3 on Linux. > > Finally, what version tk are you running? These widgets were > introduced in tk 8.5 In 8.4, they were in the Tile extension. I do not know if that will work. Better, probably, to upgrade. > > Since it failed on the second import, none of the rest of the code > matters. However, since you're not running it from a terminal window, > it's conceivable that your ide is affecting the result. Until you are able to import ttk, I believe you could remove the import and all 'ttk.' appearances, as I do not see anything ttk-specific. -- Terry Jan Reedy From cousinstanley at gmail.com Sat Dec 7 13:23:30 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sat, 07 Dec 2013 11:23:30 -0700 Subject: [newbie] struggling wth tkinter References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: > .... > The only thing I see when running it is a little popup > with "Click mouse here to quit" which works as expected > but always shows the following error-message. This seems to be left over from an earlier post where you were binding a mouse event to a tk label Did you create a new file ? > However the "main" window which should let you enter the > numbers is not shown. > > This is the quit error message: > Traceback (most recent call last): > File "./feet2meters.py", line 3, in > from tkinter import ttk > ImportError: cannot import name ttk > > This is the code: > .... If I copy/paste your code as posted into a new file named ftom.py and change the she-bang line as follows .... #!/usr/bin/env python3 Then from the command line .... python3 ftom.py Your code runs as expected using python 3.2.3 .... -- Stanley C. Kitching Human Being Phoenix, Arizona From jeandubois314 at gmail.com Sun Dec 8 02:45:06 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sat, 7 Dec 2013 23:45:06 -0800 (PST) Subject: [newbie] struggling wth tkinter In-Reply-To: References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: <3d9e313c-958f-4532-b968-0aee7f849246@googlegroups.com> Op zaterdag 7 december 2013 19:23:30 UTC+1 schreef Cousin Stanley: > > .... > > > The only thing I see when running it is a little popup > > > with "Click mouse here to quit" which works as expected > > > but always shows the following error-message. > > > > This seems to be left over from an earlier post > > where you were binding a mouse event to a tk label > > > > Did you create a new file ? > > > > > > > However the "main" window which should let you enter the > > > numbers is not shown. > > > > > > This is the quit error message: > > > Traceback (most recent call last): > > > File "./feet2meters.py", line 3, in > > > from tkinter import ttk > > > ImportError: cannot import name ttk > > > > > > This is the code: > > > .... > > > > If I copy/paste your code as posted > > into a new file named ftom.py > > and change the she-bang line > > as follows .... > > > > #!/usr/bin/env python3 > > > > Then from the command line .... > > > > python3 ftom.py > > > > Your code runs as expected > > using python 3.2.3 .... I tried you suggestion above: This is what I get: Traceback (most recent call last): File "./feet2meters.py", line 2, in from tkinter import * File "/home/jean/tkinter.py", line 2, in import Tkinter as tk ImportError: No module named Tkinter and this is my python3-version: Python 3.2.3 (default, Sep 25 2013, 18:22:43) [GCC 4.6.3] on linux2 any idea what is going wrong? thanks in advance jean From davea at davea.name Sun Dec 8 09:16:25 2013 From: davea at davea.name (Dave Angel) Date: Sun, 08 Dec 2013 09:16:25 -0500 Subject: [newbie] struggling wth tkinter In-Reply-To: <3d9e313c-958f-4532-b968-0aee7f849246@googlegroups.com> References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> <3d9e313c-958f-4532-b968-0aee7f849246@googlegroups.com> Message-ID: On Sat, 7 Dec 2013 23:45:06 -0800 (PST), Jean Dubois wrote: > This is what I get: > Traceback (most recent call last): > File "./feet2meters.py", line 2, in > from tkinter import * > File "/home/jean/tkinter.py", line 2, in > import Tkinter as tk > ImportError: No module named Tkinter Regardless of your other fixes, you should rename the bogus file: /home/jean/tkinter.py You very seldom want to have files that can shadow system modules. -- DaveA From cousinstanley at gmail.com Sun Dec 8 09:16:44 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 08 Dec 2013 07:16:44 -0700 Subject: [newbie] struggling wth tkinter References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> <3d9e313c-958f-4532-b968-0aee7f849246@googlegroups.com> Message-ID: > .... > This is what I get: > > Traceback (most recent call last): > File "./feet2meters.py", line 2, in > from tkinter import * > File "/home/jean/tkinter.py", line 2, in > import Tkinter as tk > ImportError: No module named Tkinter > .... From your original post I only changed the she-bang line from python to python3 .... #!/usr/bin/env python3 and the import lines remained as you originally posted which are appropriate for python3 .... from tkinter import * from tkinter import ttk The traceback above shows an import statement that is different from the one you originally posted which would be ok in python2 but not python3 .... import Tkinter as tk -- Stanley C. Kitching Human Being Phoenix, Arizona From jeandubois314 at gmail.com Sun Dec 8 10:53:47 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sun, 8 Dec 2013 07:53:47 -0800 (PST) Subject: [newbie] struggling wth tkinter In-Reply-To: References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> <3d9e313c-958f-4532-b968-0aee7f849246@googlegroups.com> Message-ID: Op zondag 8 december 2013 15:16:25 UTC+1 schreef Dave Angel: > On Sat, 7 Dec 2013 23:45:06 -0800 (PST), Jean Dubois > > wrote: > > > This is what I get: > > > Traceback (most recent call last): > > > File "./feet2meters.py", line 2, in > > > from tkinter import * > > > File "/home/jean/tkinter.py", line 2, in > > > import Tkinter as tk > > > ImportError: No module named Tkinter > > > > Regardless of your other fixes, you should rename the bogus file: > > > > /home/jean/tkinter.py > > > > You very seldom want to have files that can shadow system modules. > > > > -- > > DaveA Thank you Dave, this made it work under python3 too. I also had to remove tkinter.pyc kind regards, jean From jeandubois314 at gmail.com Sun Dec 8 02:40:19 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sat, 7 Dec 2013 23:40:19 -0800 (PST) Subject: [newbie] struggling wth tkinter In-Reply-To: References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: Op zaterdag 7 december 2013 19:12:50 UTC+1 schreef Dave Angel: > On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois > > wrote: > > > I'm trying to go through a tutorial on tkinter which has the code > > below as an example. The only thing I see when running it is a little > > popup with "Click mouse here to quit" which works as expected but > > always shows the following error-message. > > > However the "main" window which should let you enter the numbers is > > not shown. > > > This is the quit error message: > > > Traceback (most recent call last): > > > File "./feet2meters.py", line 3, in > > > from tkinter import ttk > > > ImportError: cannot import name ttk > > > > > This is the code: > > > #!/usr/bin/env python > > > from tkinter import * > > > from tkinter import ttk > > > > Thanks for supplying the complete traceback. But you should also > > tell the python version and what OS. I'll guess python 3.3 on Linux. > > > > > > Finally, what version tk are you running? These widgets were > > introduced in tk 8.5 > > > > Since it failed on the second import, none of the rest of the code > > matters. However, since you're not running it from a terminal window, > > it's conceivable that your ide is affecting the result. > > > > -- > > DaveA I have two pythons installed on my system: Python 2.7.3 and Python 3.2.3 When using python2 I get the errors mentioned above When using python3 (I removed the shebang and started as python3 feettometers.py) then I get these errors: coolens at antec2:~$ python3 feet2meters.py Traceback (most recent call last): File "feet2meters.py", line 1, in from tkinter import * File "/home/coolens/tkinter.py", line 2, in import Tkinter as tk ImportError: No module named Tkinter I tried to fix this by installing apt-get install python3-tk (python3-tk_3.2.3-1_amd64.deb) but the error remains What should I do now? thanks in advance jean From rosuav at gmail.com Sun Dec 8 02:49:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Dec 2013 18:49:22 +1100 Subject: [newbie] struggling wth tkinter In-Reply-To: References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: On Sun, Dec 8, 2013 at 6:40 PM, Jean Dubois wrote: > coolens at antec2:~$ python3 feet2meters.py > ImportError: No module named Tkinter In Python 3, the module's named tkinter instead of Tkinter. You should be able to do the exact same import but with the lower-case name, or if you need to support both: try: import tkinter as tk except ImportError: import Tkinter as tk ChrisA From jeandubois314 at gmail.com Sun Dec 8 04:15:12 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sun, 8 Dec 2013 01:15:12 -0800 (PST) Subject: [newbie] struggling wth tkinter In-Reply-To: References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: <306a33b1-d9f9-433b-91fa-b89b99e774eb@googlegroups.com> Op zondag 8 december 2013 08:49:22 UTC+1 schreef Chris Angelico: > On Sun, Dec 8, 2013 at 6:40 PM, Jean Dubois wrote: > > > coolens at antec2:~$ python3 feet2meters.py > > > ImportError: No module named Tkinter > > > > In Python 3, the module's named tkinter instead of Tkinter. You should > > be able to do the exact same import but with the lower-case name, or > > if you need to support both: > > > > try: > > import tkinter as tk > > except ImportError: > > import Tkinter as tk > This seems a very nice approach, but can you tell me how I should change the import-section as a whole; I tried it like here below (but that's certainly not the right way): try: import tkinter as tk except ImportError: import Tkinter as tk from tk import * import ttk thanks in advance jean From auriocus at gmx.de Sun Dec 8 03:10:28 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 08 Dec 2013 09:10:28 +0100 Subject: [newbie] struggling wth tkinter In-Reply-To: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: Am 07.12.13 17:52, schrieb Jean Dubois: > I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message. > However the "main" window which should let you enter the numbers is not shown. > > This is the quit error message: > Traceback (most recent call last): > File "./feet2meters.py", line 3, in > from tkinter import ttk > ImportError: cannot import name ttk > > This is the code: > #!/usr/bin/env python > from tkinter import * > from tkinter import ttk With my python2, it works to replace the import by from Tkinter import * import ttk Christian From jeandubois314 at gmail.com Sun Dec 8 03:57:55 2013 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sun, 8 Dec 2013 00:57:55 -0800 (PST) Subject: [newbie] struggling wth tkinter In-Reply-To: References: <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> Message-ID: <74c0caeb-0543-4819-a291-80e679344d6e@googlegroups.com> Op zondag 8 december 2013 09:10:28 UTC+1 schreef Christian Gollwitzer: > Am 07.12.13 17:52, schrieb Jean Dubois: > > > I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message. > > > However the "main" window which should let you enter the numbers is not shown. > > > > > > This is the quit error message: > > > Traceback (most recent call last): > > > File "./feet2meters.py", line 3, in > > > from tkinter import ttk > > > ImportError: cannot import name ttk > > > > > > This is the code: > > > #!/usr/bin/env python > > > > > from tkinter import * > > > from tkinter import ttk > > > > With my python2, it works to replace the import by > > > > from Tkinter import * > > import ttk > > > > Christian Thank you very much Christian, this solves the problem kind regards, jean From mahanmarwat at gmail.com Sat Dec 7 19:58:24 2013 From: mahanmarwat at gmail.com (Mahan Marwat) Date: Sat, 7 Dec 2013 16:58:24 -0800 (PST) Subject: Is It Bug? Message-ID: <5865401e-aef8-4dd2-927c-52d2b7ca3ed8@googlegroups.com> Why this is not working. >>> 'Hello, \\\\World'.replace('\\', '\\') To me, Python will interpret '\\\\' to '\\'. And the replace method will replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 'Hello, \\\\World'. The result I want form the code is 'Hello, \World'. From iurisilvio at gmail.com Sat Dec 7 20:04:13 2013 From: iurisilvio at gmail.com (Iuri) Date: Sat, 7 Dec 2013 23:04:13 -0200 Subject: Is It Bug? In-Reply-To: <5865401e-aef8-4dd2-927c-52d2b7ca3ed8@googlegroups.com> References: <5865401e-aef8-4dd2-927c-52d2b7ca3ed8@googlegroups.com> Message-ID: This way, it will replace '\' with '\', so nothing change. >>> 'Hello, \\\\World'.replace('\\\\', '\\') 'Hello, \\World' >>> print 'Hello, \\\\World'.replace('\\\\', '\\') Hello, \World On Sat, Dec 7, 2013 at 10:58 PM, Mahan Marwat wrote: > Why this is not working. > > >>> 'Hello, \\\\World'.replace('\\', '\\') > > To me, Python will interpret '\\\\' to '\\'. And the replace method will > replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's > give me 'Hello, \\\\World'. > > The result I want form the code is 'Hello, \World'. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Sun Dec 8 00:48:36 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 7 Dec 2013 21:48:36 -0800 (PST) Subject: Is It Bug? In-Reply-To: <5865401e-aef8-4dd2-927c-52d2b7ca3ed8@googlegroups.com> References: <5865401e-aef8-4dd2-927c-52d2b7ca3ed8@googlegroups.com> Message-ID: <598b3c82-37b8-47bf-a5dc-fcfab266d34f@googlegroups.com> On Sunday, December 8, 2013 6:28:24 AM UTC+5:30, Mahan Marwat wrote: > Why this is not working. > >>> 'Hello, \\\\World'.replace('\\', '\\') > To me, Python will interpret '\\\\' to '\\'. And the replace method > will replace '\\' with '\'. So, the result will be 'Hello, > \World'. But it's give me 'Hello, \\\\World'. > The result I want form the code is 'Hello, \World'. I am mystified by this question. Yes '\\' may be one slash or two or something else more exotic. But whatever it is (and its not a syntax error like with '\') it is something. So how can ....replace(something,something).... be anything other than a no-op? From mellowcellofellow at gmail.com Sun Dec 8 01:39:58 2013 From: mellowcellofellow at gmail.com (Joshua Gardner) Date: Sat, 07 Dec 2013 23:39:58 -0700 Subject: Is It Bug? References: <5865401e-aef8-4dd2-927c-52d2b7ca3ed8@googlegroups.com> Message-ID: If I'm having to deal with incessant backslashes in a string I'll often use the r'\' (raw string literal) syntax. Simplifies things quite a bit. From mahanmarwat at gmail.com Sat Dec 7 19:59:17 2013 From: mahanmarwat at gmail.com (Mahan Marwat) Date: Sat, 7 Dec 2013 16:59:17 -0800 (PST) Subject: Is It Bug? Message-ID: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Why this is not working. >>> 'Hello, \\\\World'.replace('\\', '\\') To me, Python will interpret '\\\\' to '\\'. And the replace method will replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 'Hello, \\\\World'. The result I want form the code is 'Hello, \World'. From rosuav at gmail.com Sat Dec 7 20:05:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Dec 2013 12:05:41 +1100 Subject: Is It Bug? In-Reply-To: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: On Sun, Dec 8, 2013 at 11:59 AM, Mahan Marwat wrote: > Why this is not working. > >>>> 'Hello, \\\\World'.replace('\\', '\\') > > To me, Python will interpret '\\\\' to '\\'. And the replace method will replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 'Hello, \\\\World'. > > The result I want form the code is 'Hello, \World'. You're replacing with the same as the source string. That's not going to change anything. The first thing to get your head around is Python string literals. You'll find them well described in the online tutorial, or poke around in the interactive interpreter. Once you master that, you should be able to understand what you're trying to do here. ChrisA From breamoreboy at yahoo.co.uk Sat Dec 7 20:06:45 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Dec 2013 01:06:45 +0000 Subject: Is It Bug? In-Reply-To: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: On 08/12/2013 00:59, Mahan Marwat wrote: > Why this is not working. > >>>> 'Hello, \\\\World'.replace('\\', '\\') Whoops a daisy!!! --------------^^^^--^^^^ ??? > > To me, Python will interpret '\\\\' to '\\'. And the replace method will replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 'Hello, \\\\World'. > > The result I want form the code is 'Hello, \World'. > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python at mrabarnett.plus.com Sat Dec 7 20:12:44 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 08 Dec 2013 01:12:44 +0000 Subject: Is It Bug? In-Reply-To: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: <52A3C78C.4020504@mrabarnett.plus.com> On 08/12/2013 00:59, Mahan Marwat wrote: > Why this is not working. > >>>> 'Hello, \\\\World'.replace('\\', '\\') > > To me, Python will interpret '\\\\' to '\\'. And the replace method > will replace '\\' with '\'. So, the result will be 'Hello, \World'. > But it's give me 'Hello, \\\\World'. > > The result I want form the code is 'Hello, \World'. > The original string contains 2 actual backslashes: >>> print('Hello, \\\\World') Hello, \\World Both the search and replacement strings contain 1 backslash: >>> print('\\') \ You're asking it to replace every backslash with a backslash! If you want to replace 2 consecutive backslashed with a single backslash: >>> 'Hello, \\\\World'.replace('\\\\', '\\') 'Hello, \\World' Maybe it's clearer if you print it: >>> print('Hello, \\\\World'.replace('\\\\', '\\')) Hello, \World From roy at panix.com Sat Dec 7 20:22:41 2013 From: roy at panix.com (Roy Smith) Date: Sat, 07 Dec 2013 20:22:41 -0500 Subject: Is It Bug? References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > The first thing to get your head around is Python string literals. > You'll find them well described in the online tutorial, or poke around > in the interactive interpreter. A couple of ideas to explore along those lines: 1) Read up on raw strings, i.e. r'Hello, \World' instead of 'Hello, \\Word' There's nothing you can do with raw strings that you can't do with regular strings, but they're easier to read when you start to use backslashes. 2) When in doubt about what I'm looking at in a string, I turn it into a list. So, if I do: >>> s = 'Hello, \\World' >>> print s Hello, \World What is that character after the space? Is it a backslash, or is it something that Python is printing as \W? Not sure? Just do: >>> print list(s) ['H', 'e', 'l', 'l', 'o', ',', ' ', '\\', 'W', 'o', 'r', 'l', 'd'] and it's immediately obvious which it is. From kwpolska at gmail.com Sun Dec 8 05:01:47 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 8 Dec 2013 11:01:47 +0100 Subject: Is It Bug? In-Reply-To: References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: On Sun, Dec 8, 2013 at 2:22 AM, Roy Smith wrote: > There's nothing you can do with raw strings that you can't do with > regular strings, but they're easier to read when you start to use > backslashes. Unfortunately, there is one. A raw string cannot end with a backslash. >>> r'a\a' 'a\\a' >>> r'a\' File "", line 1 r'a\' ^ SyntaxError: EOL while scanning string literal >>> r'\' File "", line 1 r'\' ^ SyntaxError: EOL while scanning string literal -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From rosuav at gmail.com Sun Dec 8 05:04:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Dec 2013 21:04:05 +1100 Subject: Is It Bug? In-Reply-To: References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: On Sun, Dec 8, 2013 at 9:01 PM, Chris ?Kwpolska? Warrick wrote: > On Sun, Dec 8, 2013 at 2:22 AM, Roy Smith wrote: >> There's nothing you can do with raw strings that you can't do with >> regular strings, but they're easier to read when you start to use >> backslashes. > > Unfortunately, there is one. A raw string cannot end with a backslash. That's the other way around. There's something you can't do with a raw string that you can do with a regular. But there's nothing you can do with a raw that you can't do with a regular, as can be easily proven by looking at the repr handling - nothing will ever have a repr that's a raw string. ChrisA From rosuav at gmail.com Sun Dec 8 05:26:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Dec 2013 21:26:39 +1100 Subject: Is It Bug? In-Reply-To: References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: On Sun, Dec 8, 2013 at 9:01 PM, Chris ?Kwpolska? Warrick wrote: > A raw string cannot end with a backslash. > >>>> r'a\a' > 'a\\a' >>>> r'a\' > File "", line 1 > r'a\' > ^ > SyntaxError: EOL while scanning string literal Incidentally, the solution to this would be to not use the backslash to escape the quote. That's what introduces the ambiguity. Instead, a raw literal could do as REXX does and double the quote to escape it. (Any whitespace and it's still concatenation as normal. I'm not advocating REXX's handling there.) >>> r"asdf""qwer" 'asdfqwer' If we had a new "pure string" that worked thus: >>> p"asdf""qwer" 'asdf"qwer' >>> p"\b""\d+""\b" '\\b"\\d+"\\b' which would be a regex matching quoted strings of digits. The only potential ambiguity would be in that closing the quote and opening another would normally revert to a regular string literal, where by this model it's still a pure string. Editor lexers would have to understand that. ChrisA From timr at probo.com Sun Dec 8 01:53:37 2013 From: timr at probo.com (Tim Roberts) Date: Sat, 07 Dec 2013 22:53:37 -0800 Subject: Is It Bug? References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: <6k58a9do25ftf4b9h33ff96gs046eruej8@4ax.com> Mahan Marwat wrote: > >Why this is not working. > >>>> 'Hello, \\\\World'.replace('\\', '\\') > >To me, Python will interpret '\\\\' to '\\'. It's really important that you think about the difference between the way string literals are written in Python code, and the way the strings actually look in memory. The Python literal 'Hello, \\\\World' contains exactly 2 backslashes. We have to spell it with 4 backslashes to get that result, but in memory there are only two. Similarly, the Python literal '\\' contains exactly one character. So, if your goal is to change 2 backslashes to 1, you would need 'Hello, \\\\World'.replace('\\\\','\\') However, REMEMBER that if you just have the command-line interpreter echo the result of that, it's going to show you the string representation, in which each backslash is shown as TWO characters. Observe: Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> s = 'Hello, \\\\World' >>> s 'Hello, \\\\World' >>> print s Hello, \\World >>> s = s.replace('\\\\','\\') >>> s 'Hello, \\World' >>> print s Hello, \World >>> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From __peter__ at web.de Sun Dec 8 05:43:37 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 08 Dec 2013 11:43:37 +0100 Subject: Is It Bug? References: <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> Message-ID: Mahan Marwat wrote: > Why this is not working. > >>>> 'Hello, \\\\World'.replace('\\', '\\') > > To me, Python will interpret '\\\\' to '\\'. And the replace method will > replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's > give me 'Hello, \\\\World'. > > The result I want form the code is 'Hello, \World'. Let's forget about backslashes for the moment and use 'a' instead. We can replace an 'a' with an 'a' >>> "Hello, aaWorld".replace("a", "a") 'Hello, aaWorld' That changes nothing. Or we can replace two 'a's with one 'a' >>> "Hello, aaWorld".replace("aa", "a") 'Hello, aWorld' This does the obvious thing. Finally we can replace an 'a' with the empty string '': >>> "Hello, aaWorld".replace("a", "") 'Hello, World' This effectively removes all 'a's. Now let's replace the "a" with a backslash. Because the backslash has a special meaning it has to be "escaped", i. e. preceded by another backslash. The examples then become >>> "Hello, \\\\World".replace("\\", "\\") 'Hello, \\\\World' >>> "Hello, \\\\World".replace("\\\\", "\\") 'Hello, \\World' >>> "Hello, \\\\World".replace("\\", "") 'Hello, World' While doubling of backslashes is required by Python the doubling of backslahses in the output occurs because the interactive interpreter applies repr() to the string before it is shown. You can avoid that with an explicit print statement in Python 2 or a print() function call in Python 3: >>> print "Hello, \\\\World".replace("\\", "\\") Hello, \\World >>> print "Hello, \\\\World".replace("\\\\", "\\") Hello, \World >>> print "Hello, \\\\World".replace("\\", "") Hello, World From musicdenotation at gmail.com Sun Dec 8 05:35:54 2013 From: musicdenotation at gmail.com (Kalinni Gorzkis) Date: Sun, 8 Dec 2013 17:35:54 +0700 Subject: Origin of eval()-ing in separate namespace object Message-ID: <62C97841-33E3-4761-A670-D12E61DEB3E3@gmail.com> By which languages(s) Python was inspired to support evaluating expressions and executing statements in a separate ?namespace? object? This syntax: eval(expression,globals) or exec(code,globals) What is the origin of the functionality provided by the globals argument? From rustompmody at gmail.com Sun Dec 8 08:45:01 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 05:45:01 -0800 (PST) Subject: Origin of eval()-ing in separate namespace object In-Reply-To: References: Message-ID: <05d1151c-ee29-4631-bdeb-24102f527815@googlegroups.com> On Sunday, December 8, 2013 4:05:54 PM UTC+5:30, Kalinni Gorzkis wrote: > By which languages(s) Python was inspired to support evaluating expressions and executing statements in a separate ?namespace? object? > This syntax: > eval(expression,globals) or exec(code,globals) > What is the origin of the functionality provided by the globals argument? Been here since the days of scheme at least http://docs.racket-lang.org/guide/eval.html#%28part._namespaces%29 For the record lisp was conceptualized in the late 50s and implemented by 1960. By the 80s it was widely regarded as the premier AI language but it was also clear to users that the scoping rules were terribly wrong. So a number of the then lisps coalesced and re-separated into 2 major dialects -- scheme and common lisp. I expect it -- 2 argument eval -- goes all the way back to the earliest lisp but Ive not access to the history. From jpiitula at ling.helsinki.fi Sun Dec 8 09:39:39 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 08 Dec 2013 16:39:39 +0200 Subject: Origin of eval()-ing in separate namespace object References: <05d1151c-ee29-4631-bdeb-24102f527815@googlegroups.com> Message-ID: rusi writes: > On Sunday, December 8, 2013 4:05:54 PM UTC+5:30, Kalinni Gorzkis wrote: > > > By which languages(s) Python was inspired to support evaluating > > expressions and executing statements in a separate "namespace" > > object? > > > This syntax: > > eval(expression,globals) or exec(code,globals) > > What is the origin of the functionality provided by the globals > > argument? > > Been here since the days of scheme at least > http://docs.racket-lang.org/guide/eval.html#%28part._namespaces%29 > > For the record lisp was conceptualized in the late 50s and > implemented by 1960. By the 80s it was widely regarded as the > premier AI language but it was also clear to users that the scoping > rules were terribly wrong. So a number of the then lisps coalesced > and re-separated into 2 major dialects -- scheme and common lisp. > > I expect it -- 2 argument eval -- goes all the way back to the > earliest lisp but Ive not access to the history. Yes. From p. 13 of LISP 1.5 Programmer's Manual (the preface is dated in 1962): # _evalquote_ is defined by using two main functions, called _eval_ # and _apply_. _apply_ handles a function and its arguments, while # _eval_ handles forms. Each of these functions also has another # argument that is used as an association list for storing the values # of bound variables and function names. That association list is the namespace. _eval_ and _apply_ pass it around and extend it as they call each other to evalute code. So it seems that at least the idea of an explicit namespace argument was there from the start. Mistakes related to the original dynamic scoping continued to be made. From rustompmody at gmail.com Sun Dec 8 11:39:24 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 08:39:24 -0800 (PST) Subject: Origin of eval()-ing in separate namespace object In-Reply-To: References: <05d1151c-ee29-4631-bdeb-24102f527815@googlegroups.com> Message-ID: On Sunday, December 8, 2013 8:09:39 PM UTC+5:30, Jussi Piitulainen wrote: > rusi writes: > > On Sunday, December 8, 2013 4:05:54 PM UTC+5:30, Kalinni Gorzkis wrote: > > > By which languages(s) Python was inspired to support evaluating > > > expressions and executing statements in a separate "namespace" > > > object? > > > This syntax: > > > eval(expression,globals) or exec(code,globals) > > > What is the origin of the functionality provided by the globals > > > argument? > > Been here since the days of scheme at least > > http://docs.racket-lang.org/guide/eval.html#%28part._namespaces%29 > > For the record lisp was conceptualized in the late 50s and > > implemented by 1960. By the 80s it was widely regarded as the > > premier AI language but it was also clear to users that the scoping > > rules were terribly wrong. So a number of the then lisps coalesced > > and re-separated into 2 major dialects -- scheme and common lisp. > > I expect it -- 2 argument eval -- goes all the way back to the > > earliest lisp but Ive not access to the history. > Yes. From p. 13 of LISP 1.5 Programmer's Manual (the preface is dated > in 1962): > # _evalquote_ is defined by using two main functions, called _eval_ > # and _apply_. _apply_ handles a function and its arguments, while > # _eval_ handles forms. Each of these functions also has another > # argument that is used as an association list for storing the values > # of bound variables and function names. Heh ? I am nostalgia-fied! Wrote a Lisp interpreter as a student degree project in 1986. Tried to use the Lisp 1.5 manual then but it was too archaic for me to understand. So mostly chewed on the UCI Lisp manual. Took me some years to understand that dynamic scoping was not my mistake but Lisp's!! From rafaellasav at gmail.com Sun Dec 8 12:59:52 2013 From: rafaellasav at gmail.com (rafaellasav at gmail.com) Date: Sun, 8 Dec 2013 09:59:52 -0800 (PST) Subject: python programming help Message-ID: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. please help From ybmess at nooos.fr.invalid Sun Dec 8 13:07:47 2013 From: ybmess at nooos.fr.invalid (YBM) Date: Sun, 08 Dec 2013 19:07:47 +0100 Subject: python programming help In-Reply-To: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> Message-ID: <52a4b574$0$2116$426a74cc@news.free.fr> Le 08.12.2013 18:59, rafaellasav at gmail.com a ?crit : > i have a dictionary with names and ages for each name. > I want to write a function that takes in an age and returns > the names of all the people who are that age. > please help ageDict = { 'john':42, 'jane':36, 'paul':42 } peopleWithAge = lambda age: [ name for name in ageDict if ageDict[name]==age] From rafaellasav at gmail.com Sun Dec 8 13:14:47 2013 From: rafaellasav at gmail.com (rafaellasav at gmail.com) Date: Sun, 8 Dec 2013 10:14:47 -0800 (PST) Subject: python programming help In-Reply-To: <52a4b574$0$2116$426a74cc@news.free.fr> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <52a4b574$0$2116$426a74cc@news.free.fr> Message-ID: <780a4832-411d-499e-96a1-3321d123b82b@googlegroups.com> On Sunday, December 8, 2013 6:07:47 PM UTC, YBM wrote: > Le 08.12.2013 18:59, rafaellasav at gmail.com a ???crit : > > > i have a dictionary with names and ages for each name. > > > I want to write a function that takes in an age and returns > > > the names of all the people who are that age. > > > please help > > > > ageDict = { 'john':42, 'jane':36, 'paul':42 } > > peopleWithAge = lambda age: [ name for name in ageDict if > > ageDict[name]==age] sorry but i'm new to python ;p 1. it has to be in a form of a function called people and 2. how this code takes in an age and returns the names? From ybmess at nooos.fr.invalid Sun Dec 8 13:18:00 2013 From: ybmess at nooos.fr.invalid (YBM) Date: Sun, 08 Dec 2013 19:18:00 +0100 Subject: python programming help In-Reply-To: <780a4832-411d-499e-96a1-3321d123b82b@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <52a4b574$0$2116$426a74cc@news.free.fr> <780a4832-411d-499e-96a1-3321d123b82b@googlegroups.com> Message-ID: <52a4b7d8$0$2146$426a34cc@news.free.fr> Le 08.12.2013 19:14, rafaellasav at gmail.com a ?crit : > On Sunday, December 8, 2013 6:07:47 PM UTC, YBM wrote: >> Le 08.12.2013 18:59, rafaellasav at gmail.com a ???crit : >> >>> i have a dictionary with names and ages for each name. >> >>> I want to write a function that takes in an age and returns >> >>> the names of all the people who are that age. >> >>> please help >> >> >> >> ageDict = { 'john':42, 'jane':36, 'paul':42 } >> >> peopleWithAge = lambda age: [ name for name in ageDict if >> >> ageDict[name]==age] > > > sorry but i'm new to python ;p > 1. it has to be in a form of a function called people and > 2. how this code takes in an age and returns the names? >>> ageDict = { 'john':42, 'jane':36, 'paul':42 } >>> people = lambda age: [ name for name in ageDict if ... ageDict[name]==age] >>> people(42) ['paul', 'john'] From breamoreboy at yahoo.co.uk Sun Dec 8 13:25:32 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Dec 2013 18:25:32 +0000 Subject: python programming help In-Reply-To: <780a4832-411d-499e-96a1-3321d123b82b@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <52a4b574$0$2116$426a74cc@news.free.fr> <780a4832-411d-499e-96a1-3321d123b82b@googlegroups.com> Message-ID: On 08/12/2013 18:14, rafaellasav at gmail.com wrote: > On Sunday, December 8, 2013 6:07:47 PM UTC, YBM wrote: >> Le 08.12.2013 18:59, rafaellasav at gmail.com a ???crit : >> >>> i have a dictionary with names and ages for each name. >> >>> I want to write a function that takes in an age and returns >> >>> the names of all the people who are that age. >> >>> please help >> >> >> >> ageDict = { 'john':42, 'jane':36, 'paul':42 } >> >> peopleWithAge = lambda age: [ name for name in ageDict if >> >> ageDict[name]==age] > > > sorry but i'm new to python ;p > 1. it has to be in a form of a function called people and > 2. how this code takes in an age and returns the names? > I'm awfully sorry but I'm not doing your homework for you :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From cjwelborn at live.com Mon Dec 9 18:34:57 2013 From: cjwelborn at live.com (Christopher Welborn) Date: Mon, 09 Dec 2013 17:34:57 -0600 Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <52a4b574$0$2116$426a74cc@news.free.fr> <780a4832-411d-499e-96a1-3321d123b82b@googlegroups.com> Message-ID: > On 08/12/2013 18:14, rafaellasav at gmail.com wrote: >> sorry but i'm new to python ;p >> 1. it has to be in a form of a function called people and >> 2. how this code takes in an age and returns the names? >> "it has to be in the form of a function called people", that made me laugh. Too bad he got an answer, even worse he doesn't know what to do with it. -- - Christopher Welborn http://welbornprod.com From roy at panix.com Sun Dec 8 13:23:38 2013 From: roy at panix.com (Roy Smith) Date: Sun, 08 Dec 2013 13:23:38 -0500 Subject: python programming help References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> Message-ID: In article <264c1144-5d04-4ad0-aa32-f4e6770d210c at googlegroups.com>, rafaellasav at gmail.com wrote: > i have a dictionary with names and ages for each name. I want to write a > function that takes in an age and returns the names of all the people who are > that age. > please help Homework problem? In any case, this is a classic example of a real-life problem, and thus worth exploring. The general case is you have a many-to-one mapping and you want to find the inverse one-to-many map. I'm assuming when you say, "a dictionary with names and ages for each name", you mean the names are the keys and the ages are the values. That would also imply that the names are unique; that's a poor assumption for real data sets, but let's assume that's the case here. So, we're going to take your original dictionary and create a new one where the keys are the ages, and the values are lists of names. That's pretty straight forward. Here's the most brute-force way (which is a good place to start): d2 = {} for name, age in d1.items(): if age not in d2: d2[age] = [] d2[age].append(name) Work through that code in your head to convince yourself that you understand what's going on. This is such a common pattern, Python has a neat tool to make this easier. It's called a defaultdict. Bascially, this is a dictionary which has built into it the "if key doesn't exist, initialize something" logic. It works like this: from collections import defaultdict d2 = defaultdict(list) for name, age in d1.items(): d2[age].append(name) The "defaultdict(list)" creates one of these and tells it that the "initialize something" part should be "create an empty list". It's hugely convenient and used all the time. From gary.herron at islandtraining.com Sun Dec 8 13:20:37 2013 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 08 Dec 2013 10:20:37 -0800 Subject: python programming help In-Reply-To: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> Message-ID: <52A4B875.2070605@islandtraining.com> On 12/08/2013 09:59 AM, rafaellasav at gmail.com wrote: > i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. > please help This looks like homework for a beginning programming class. Correct? We like helping people use Python, and we like helping people learn Python, but neither of those purposes are served by us *doing* your homework for you. Please, you try to solve the problem, and when you get stuck, show us your code, and ask a specific question. Hint: You will almost certainly need a loop (through the dictionary entries), an 'if' conditional to test for the age matching the given age, and a print, Gary Herron From bgailer at gmail.com Sun Dec 8 13:27:34 2013 From: bgailer at gmail.com (bob gailer) Date: Sun, 08 Dec 2013 13:27:34 -0500 Subject: python programming help In-Reply-To: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> Message-ID: <52A4BA16.20900@gmail.com> On 12/8/2013 12:59 PM, rafaellasav at gmail.com wrote: > i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. > please help Welcome to the python list. Thanks for posting a question. If you were hoping for one of us to write the program for you ... well that's not what we do on this list. Please post the code you have so far and tell us exactly where you need help. Also tell us what version of Python, what OS, and what you use to write and run Python programs. From rafaellasav at gmail.com Sun Dec 8 13:32:31 2013 From: rafaellasav at gmail.com (rafaellasav at gmail.com) Date: Sun, 8 Dec 2013 10:32:31 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> Message-ID: <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote: > On 12/8/2013 12:59 PM, rafaellasav at gmail.com wrote: > > > i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. > > > please help > > Welcome to the python list. Thanks for posting a question. > > > > If you were hoping for one of us to write the program for you ... well > > that's not what we do on this list. > > > > Please post the code you have so far and tell us exactly where you need > > help. > > > > Also tell us what version of Python, what OS, and what you use to write > > and run Python programs. name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] dic={} def combine_lists(name,age): for i in range(len(name)): dic[name[i]]= age[i] combine_lists(name,age) print dic def people(age): people=lambda age: [name for name in dic if dic[name]==age] people(20) this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. and this code doesn't give me any result From rafaellasav at gmail.com Sun Dec 8 13:42:16 2013 From: rafaellasav at gmail.com (rafaellasav at gmail.com) Date: Sun, 8 Dec 2013 10:42:16 -0800 (PST) Subject: python programming help In-Reply-To: <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> Message-ID: <97634c6d-9ac5-4e2d-8616-426a59c6b439@googlegroups.com> On Sunday, December 8, 2013 6:32:31 PM UTC, rafae... at gmail.com wrote: > On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote: > > > On 12/8/2013 12:59 PM, rafaellasav at gmail.com wrote: > > > > > > > i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. > > > > > > > please help > > > > > > Welcome to the python list. Thanks for posting a question. > > > > > > > > > > > > If you were hoping for one of us to write the program for you ... well > > > > > > that's not what we do on this list. > > > > > > > > > > > > Please post the code you have so far and tell us exactly where you need > > > > > > help. > > > > > > > > > > > > Also tell us what version of Python, what OS, and what you use to write > > > > > > and run Python programs. > > > > name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] > > age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] > > dic={} > > def combine_lists(name,age): > > for i in range(len(name)): > > dic[name[i]]= age[i] > > combine_lists(name,age) > > print dic > > > > def people(age): > > people=lambda age: [name for name in dic if dic[name]==age] > > > > people(20) > > > > > > > > > > this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. and this code doesn't give me any result and I'm sorry but this is the first time i ask for help in a forum and i just didn't know how it works. I'm not looking for someone to do my homework i just need someone to help me with my code :) From benjamin.kaplan at case.edu Sun Dec 8 13:52:12 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Dec 2013 10:52:12 -0800 Subject: python programming help In-Reply-To: <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> Message-ID: On Sun, Dec 8, 2013 at 10:32 AM, wrote: > > On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote: > > On 12/8/2013 12:59 PM, rafaellasav at gmail.com wrote: > > > > > i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. > > > > > please help > > > > Welcome to the python list. Thanks for posting a question. > > > > > > > > If you were hoping for one of us to write the program for you ... well > > > > that's not what we do on this list. > > > > > > > > Please post the code you have so far and tell us exactly where you need > > > > help. > > > > > > > > Also tell us what version of Python, what OS, and what you use to write > > > > and run Python programs. > > name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] > age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] > dic={} > def combine_lists(name,age): > for i in range(len(name)): > dic[name[i]]= age[i] > combine_lists(name,age) > print dic > > def people(age): > people=lambda age: [name for name in dic if dic[name]==age] > > people(20) > > > > > this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. and this code doesn't give me any result > > To return a value from a function, you need to use the "return" statement with the value you want to pass back out. You're not doing that here. Also, you're using a lot of shorthand stuff that you should probably avoid until you're more comfortable with the language * Lambda is shorthand for a function. foo = lambda bar : bar + 2 is the same thing as the function def foo(bar) : return bar + 2 * a list comprehension is short-hand for a loop. spam = [foo for foo in bar if baz(foo)] is the same thing as spam = [] for foo in bar : if baz(foo) : spam.append(foo) You don't need a lambda here- just call the code that you need to call directly. From rafaellasav at gmail.com Sun Dec 8 14:06:55 2013 From: rafaellasav at gmail.com (rafaellasav at gmail.com) Date: Sun, 8 Dec 2013 11:06:55 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> Message-ID: <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> On Sunday, December 8, 2013 6:52:12 PM UTC, Benjamin Kaplan wrote: > On Sun, Dec 8, 2013 at 10:32 AM, wrote: > > > > > > On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote: > > > > On 12/8/2013 12:59 PM, rafaellasav at gmail.com wrote: > > > > > > > > > i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. > > > > > > > > > please help > > > > > > > > Welcome to the python list. Thanks for posting a question. > > > > > > > > > > > > > > > > If you were hoping for one of us to write the program for you ... well > > > > > > > > that's not what we do on this list. > > > > > > > > > > > > > > > > Please post the code you have so far and tell us exactly where you need > > > > > > > > help. > > > > > > > > > > > > > > > > Also tell us what version of Python, what OS, and what you use to write > > > > > > > > and run Python programs. > > > > > > name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] > > > age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] > > > dic={} > > > def combine_lists(name,age): > > > for i in range(len(name)): > > > dic[name[i]]= age[i] > > > combine_lists(name,age) > > > print dic > > > > > > def people(age): > > > people=lambda age: [name for name in dic if dic[name]==age] > > > > > > people(20) > > > > > > > > > > > > > > > this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. and this code doesn't give me any result > > > > > > > > > > To return a value from a function, you need to use the "return" > > statement with the value you want to pass back out. You're not doing > > that here. Also, you're using a lot of shorthand stuff that you should > > probably avoid until you're more comfortable with the language > > > > * Lambda is shorthand for a function. foo = lambda bar : bar + 2 is > > the same thing as the function > > def foo(bar) : > > return bar + 2 > > > > * a list comprehension is short-hand for a loop. spam = [foo for foo > > in bar if baz(foo)] is the same thing as > > spam = [] > > for foo in bar : > > if baz(foo) : > > spam.append(foo) > > > > You don't need a lambda here- just call the code that you need to call directly. i get it, thanks a lot i wrote a different one and it works def people(age): people=[name for name in dic if dic[name]==age] print(people) people(20) i have one last question it asks me to test my program function by running these lines: print ?Dan? in people(18) and ?Cathy? in people(18) print ?Ed? in people(19) and ?Helen? in people(19) and\ ?Irene? in people(19) and ?Jack? in people(19) and ?Larry?in people(19) print ?Alice? in people(20) and ?Frank? in people(20) and ?Gary? in people(20) print people(21) == [?Bob?] print people(22) == [?Kelly?] print people(23) == [] but when i wrote these lines it returns me an error Traceback (most recent call last): File "/Users/rafaellasavva/Desktop/people.py", line 19, in print 'Dan' in people(18) and 'Cathy' in people(18) TypeError: argument of type 'NoneType' is not utterable do you know what it might be wrong? From rosuav at gmail.com Sun Dec 8 14:17:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 06:17:03 +1100 Subject: python programming help In-Reply-To: <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> Message-ID: On Mon, Dec 9, 2013 at 6:06 AM, wrote: > but when i wrote these lines it returns me an error > Traceback (most recent call last): > File "/Users/rafaellasavva/Desktop/people.py", line 19, in > print 'Dan' in people(18) and 'Cathy' in people(18) > TypeError: argument of type 'NoneType' is not utterable > > do you know what it might be wrong? Hehe. The first thing that's wrong is that you're retyping the error instead of copying and pasting it. The problem is actually that it's not *iterable* here. And the reason for that is that you're printing the result instead of returning it, as has been mentioned by a few people. Also, your posts are acquiring the slimy stain of Google Groups, which makes them rather distasteful. All your replies are getting double-spaced, among other problems. Please consider switching to an alternative newsgroup reader, or subscribing to the mailing list: https://mail.python.org/mailman/listinfo/python-list The content is the same, but it comes by email instead of netnews. ChrisA From breamoreboy at yahoo.co.uk Sun Dec 8 14:21:22 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 08 Dec 2013 19:21:22 +0000 Subject: python programming help In-Reply-To: <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> Message-ID: On 08/12/2013 19:06, rafaellasav at gmail.com wrote: > i get it, thanks a lot i wrote a different one and it works > > def people(age): > people=[name for name in dic if dic[name]==age] > print(people) > > people(20) > > i have one last question > > it asks me to test my program function by running these lines: > print ?Dan? in people(18) and ?Cathy? in people(18) > print ?Ed? in people(19) and ?Helen? in people(19) and\ > ?Irene? in people(19) and ?Jack? in people(19) and ?Larry?in > people(19) > print ?Alice? in people(20) and ?Frank? in people(20) and ?Gary? in > people(20) > print people(21) == [?Bob?] > print people(22) == [?Kelly?] > print people(23) == [] > > but when i wrote these lines it returns me an error > Traceback (most recent call last): > File "/Users/rafaellasavva/Desktop/people.py", line 19, in > print 'Dan' in people(18) and 'Cathy' in people(18) > TypeError: argument of type 'NoneType' is not utterable > > do you know what it might be wrong? > You've typed up the error message instead of using cut and paste, which is why it says "utterable" instead of "iterable"? :) Seriously, it's already been pointed out that your people function needs a return statement. Without it, the default returned is always None. Would you also please read and action this https://wiki.python.org/moin/GoogleGroupsPython as it prevents us seeing huge numbers of unwanted newlines which some find extremely irritating. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Sun Dec 8 16:17:56 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 Dec 2013 16:17:56 -0500 Subject: python programming help In-Reply-To: <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> Message-ID: On 12/8/2013 2:06 PM, rafaellasav at gmail.com wrote: Even when you do get what lambda means and how use it, name = lambda args: expression which is a carryover from other languages, is inferior to def name(args): return expression because the function object resulting from lambda does not have a proper name attribute. > def people(age): > people=[name for name in dic if dic[name]==age] An alternative is [name for name, value in dic.itervalues() if value == age] In Python 3, remove 'iter'. It this is not homework and you are not otherwise forced to start with Python 3, I (and some others here) recommend starting with Python 3. -- Terry Jan Reedy From rurpy at yahoo.com Sun Dec 8 19:08:02 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 8 Dec 2013 16:08:02 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> Message-ID: <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> On 12/08/2013 12:17 PM, Chris Angelico wrote: > On Mon, Dec 9, 2013 at 6:06 AM, wrote:>[...] > Also, your posts are acquiring the slimy stain of Google Groups, which > makes them rather distasteful. All your replies are getting > double-spaced, among other problems. Please consider switching to an > alternative newsgroup reader, or subscribing to the mailing list: > https://mail.python.org/mailman/listinfo/python-list To the OP: First, my apologies if my reply ends up trashing your discussion here, but you should know what is behind Mr. Angelico's response. For some time now the Google Group Wars are being fought in this group. There is a (probably very small) clique of Google haters who try present themselves as "the community" and who try to intimidate anyone posting from Google Groups into using some other means of posting, completely disregarding the fact that for many new people or occasional posters, Google Groups is an order of magnitude easier to use. These people are extremely noisy and obnoxious but *do not* represent "the community" except in their own minds. I suspect many of them are motivated by political dislike of Google as a corporation, or want to stay with the 1990's technology they invested time in learning and don't want see change. I and many other people post here from Google Groups and you should feel free to too if it is more convenient for you. (Of course you can also use the maillist or usenet if you find them a good solution for *you* but please don't feel compelled to by some loud obnoxious bullies.) As another poster pointed out, if you are able to follow some of the advice at, https://wiki.python.org/moin/GoogleGroupsPython it will help quiet down the anti-Google crowd a little but even if you don't, those without a Google chip on their shoulder will simply skip your posts if they find the Google formatting too annoying. Most of us though will deal with it as adults and try our best to answer your questions. I just thought you should have both sides of the story so to won't take the anti-Google crowd here as gospel. Addressing you last question, I presume you understood the other responses about replacing the "print (people)" statement in your people() function with "return people". The only additional thing I wanted to add is that, people=[name for name in dic if dic[name]==age] is (I would guess) a rather advanced way of doing what you are doing, given where you seem to be in learning about python (but maybe not, in which case ignore the following). The [....] thing is called as "list comprehension and in described here http://docs.python.org/3/tutorial/datastructures.html#list-comprehensions However, it is just a more concise way of writing: people = [] for n, a in dic.items(): if a == age: people.append (n) return people To understand the above (if you don't already) you'll want to read about the the items() method of dicts: http://docs.python.org/3/tutorial/datastructures.html#looping-techniques http://docs.python.org/3/library/stdtypes.html#mapping-types-dict the append() method of lists, http://docs.python.org/3/tutorial/controlflow.html#for-statements http://docs.python.org/3/library/stdtypes.html#mutable-sequence-types and of course "for" loops; http://docs.python.org/3/tutorial/controlflow.html#for-statements Hope this helps. From breamoreboy at yahoo.co.uk Sun Dec 8 19:27:48 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 00:27:48 +0000 Subject: python programming help In-Reply-To: <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> Message-ID: On 09/12/2013 00:08, rurpy at yahoo.com wrote: > On 12/08/2013 12:17 PM, Chris Angelico wrote: >> On Mon, Dec 9, 2013 at 6:06 AM, wrote:>[...] >> Also, your posts are acquiring the slimy stain of Google Groups, which >> makes them rather distasteful. All your replies are getting >> double-spaced, among other problems. Please consider switching to an >> alternative newsgroup reader, or subscribing to the mailing list: >> https://mail.python.org/mailman/listinfo/python-list > > To the OP: > > First, my apologies if my reply ends up trashing your > discussion here, but you should know what is behind Mr. > Angelico's response. > > For some time now the Google Group Wars are being fought > in this group. > > There is a (probably very small) clique of Google haters > who try present themselves as "the community" and who try > to intimidate anyone posting from Google Groups into using > some other means of posting, completely disregarding the > fact that for many new people or occasional posters, Google > Groups is an order of magnitude easier to use. These people > are extremely noisy and obnoxious but *do not* represent > "the community" except in their own minds. I suspect many > of them are motivated by political dislike of Google as > a corporation, or want to stay with the 1990's technology > they invested time in learning and don't want see change. > > I and many other people post here from Google Groups and > you should feel free to too if it is more convenient for > you. (Of course you can also use the maillist or usenet > if you find them a good solution for *you* but please don't > feel compelled to by some loud obnoxious bullies.) > > As another poster pointed out, if you are able to follow > some of the advice at, > > https://wiki.python.org/moin/GoogleGroupsPython > > it will help quiet down the anti-Google crowd a little but > even if you don't, those without a Google chip on their shoulder > will simply skip your posts if they find the Google formatting > too annoying. Most of us though will deal with it as adults > and try our best to answer your questions. > > I just thought you should have both sides of the story so > to won't take the anti-Google crowd here as gospel. > To the OP, please ignore the above, it's sheer, unadulterated rubbish. Nobody has ever been bullied into doing anything. People have however been asked repeatedly to either A) use the link referenced above to avoid sending double spaced crap here from the inferior google groups product or B) use an alternative technology that doesn't send double spaced crap. -- 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 Sun Dec 8 22:05:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 14:05:55 +1100 Subject: python programming help In-Reply-To: <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> Message-ID: On Mon, Dec 9, 2013 at 11:08 AM, wrote: > I suspect many > of them are motivated by political dislike of Google as > a corporation, or want to stay with the 1990's technology > they invested time in learning and don't want see change. Neither. I don't at all hate Google (I quite like the company, and what it's done for the world), and I use plenty of other Google services - as you can see, I'm posting from gmail here. The only thing I call out against is Google Groups, because it is buggy. I'll cry out against anything else that's buggy, too. Of course, I'll first try to do things quietly (bug reports to the maintainers), but ultimately, the solution to buggy software is to NOT USE IT. If Google doesn't care enough about Groups to bring it up to the standard, then their penalty has to be reduced usage. In fact, Rurpy, you are actually encouraging the faulty system, because you're providing ad impressions and usage stats every time you read or write via GG. When less-buggy systems see more use than more-buggy systems, big companies have an incentive to fix bugs. ChrisA From rurpy at yahoo.com Mon Dec 9 00:07:38 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 8 Dec 2013 21:07:38 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> Message-ID: <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> On 12/08/2013 05:27 PM, Mark Lawrence wrote: > On 09/12/2013 00:08, rurpy at yahoo.com wrote: >> On 12/08/2013 12:17 PM, Chris Angelico wrote: >>> On Mon, Dec 9, 2013 at 6:06 AM, wrote:>[...] >[...] > To the OP, please ignore the above, it's sheer, unadulterated rubbish. > Nobody has ever been bullied into doing anything. People have however > been asked repeatedly to either A) use the link referenced above to > avoid sending double spaced crap here from the inferior google groups > product or B) use an alternative technology that doesn't send double > spaced crap. Mark, I appreciate your calm and reasonable requests for people to checkout the page you gave a link to, that's why I repeated your advice. It is also why I responded to Chris and not to you. However it does not change the fact that people here have responded in rather extreme way to GG posts including calling GG users "twits" and claiming GG posts damage their eyesight, as well as repeatedly denying the obvious fact that GG is much easier to use for many than to subscribe to a usenet provider or to a mailing list. One frequently sees words like "crap", "slimy", "rubbish" etc to describe GG posts which is pretty intimating to people who just want some help with a python question using a tool they already know how to use and have had no complaints about in other places. From rustompmody at gmail.com Mon Dec 9 00:20:33 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 8 Dec 2013 21:20:33 -0800 (PST) Subject: python programming help In-Reply-To: <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: On Monday, December 9, 2013 10:37:38 AM UTC+5:30, ru... at yahoo.com wrote: > On 12/08/2013 05:27 PM, Mark Lawrence wrote: > > On 09/12/2013 00:08, wrote: > >> On 12/08/2013 12:17 PM, Chris Angelico wrote: > >>> On Mon, Dec 9, 2013 at 6:06 AM, rafaell wrote: > >[...] > > To the OP, please ignore the above, it's sheer, unadulterated rubbish. > > Nobody has ever been bullied into doing anything. People have however > > been asked repeatedly to either A) use the link referenced above to > > avoid sending double spaced crap here from the inferior google groups > > product or B) use an alternative technology that doesn't send double > > spaced crap. > Mark, I appreciate your calm and reasonable requests for people > to checkout the page you gave a link to, that's why I repeated > your advice. It is also why I responded to Chris and not to you. Yes agreed. > However it does not change the fact that people here have responded > in rather extreme way to GG posts including calling GG users "twits" > and claiming GG posts damage their eyesight, as well as repeatedly > denying the obvious fact that GG is much easier to use for many than > to subscribe to a usenet provider or to a mailing list. One frequently > sees words like "crap", "slimy", "rubbish" etc to describe GG posts > which is pretty intimating to people who just want some help with a > python question using a tool they already know how to use and have > had no complaints about in other places. About the last -- no complaints about (that) in other places -- Ive recently seen that on the html/stylesheets/javascript lists (not sure which) there are also annoyed complaints about GG. About the rest -- when people get annoyed they say and do things they would not otherwise do. The sensible not-yet-annoyed-enough-to-lose-the-head folks should try to cure the annoyance rather than get annoyed with it -- dont you think? In short if we are programmers we should be thinking bug-fixes when we are bugged :-) And what is put up here https://wiki.python.org/moin/GoogleGroupsPython (only yesterday BTW) is a dynamically loadable GG-bugfix. From rurpy at yahoo.com Tue Dec 10 00:15:04 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 9 Dec 2013 21:15:04 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: On 12/08/2013 10:20 PM, rusi wrote: > On Monday, December 9, 2013 10:37:38 AM UTC+5:30, ru... at yahoo.com wrote: >[...] >> However it does not change the fact that people here have responded >> in rather extreme way to GG posts including calling GG users "twits" >> and claiming GG posts damage their eyesight, as well as repeatedly >> denying the obvious fact that GG is much easier to use for many than >> to subscribe to a usenet provider or to a mailing list. One frequently >> sees words like "crap", "slimy", "rubbish" etc to describe GG posts >> which is pretty intimating to people who just want some help with a >> python question using a tool they already know how to use and have >> had no complaints about in other places. > > About the last -- no complaints about (that) in other places -- Ive recently > seen that on the html/stylesheets/javascript lists (not sure which) > there are also annoyed complaints about GG. I am sure that there are other usenet groups that get Google Groups posts and find them irritating for the same reason that some here do. But usenet is nearly all the way in death's door (at least text groups; binaries groups may be still be growing.) The only usenet groups I know of with any vitality left at all are ones like the Python list that are backed by an active maillist. (Curiously, it seems to me the dramatic decline in usenet occurred around 2008-2010, about the same time as the dramatic rise of social networking sites.) As for pure mailing lists, I am not sure how many are gatewayed to GG -- I subscribe to several because they are not available through GG -- so they don't get GG posts. There are however a large number of mailing lists that are hosted solely on GG by various projects. It is participants in these lists that I was thinking of by "other places". Such people are likely very surprised by the hostility they meet when they simply change to the python list (or one of the other usenet-gatewayed groups) which looks very much like any another GG group from their perspective. For all the GG hostility on the python list, many python project lists are hosted on GG (Sqlalchemy, Webpy, GvR's own Tulip project, etc) > About the rest -- when people get annoyed they say and do things they > would not otherwise do. Humans have big cortexes so that they don't need to act out based on their feelings of the moment -- like a dog humping the boy next door or trying to bite off the arm of the postal delivery person. From rosuav at gmail.com Mon Dec 9 02:57:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 18:57:37 +1100 Subject: python programming help In-Reply-To: <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: On Mon, Dec 9, 2013 at 4:07 PM, wrote: > However it does not change the fact that people here have responded > in rather extreme way to GG posts including calling GG users "twits" > and claiming GG posts damage their eyesight, as well as repeatedly > denying the obvious fact that GG is much easier to use for many than > to subscribe to a usenet provider or to a mailing list. One frequently > sees words like "crap", "slimy", "rubbish" etc to describe GG posts > which is pretty intimating to people who just want some help with a > python question using a tool they already know how to use and have > had no complaints about in other places. Please note though that there is a difference between describing the users as twits and describing the posts as slimy. Suppose you write a letter (the sort that goes on a slab of dead tree) and, instead of placing it in an envelope and putting a stamp on it, you hand it to the Arac News Insertion Device[1] to do the enveloping for you. He does a reasonable job of it, but he uses cobwebs instead of paper for the envelope. Sure, it's still readable... but your readers now have to rub off a whole lot of cobwebs before they can read what you said. That makes your post distasteful, without it being at all your fault - other than choosing to use Arac's service. That's how I see Google Groups posts. Someone's gone looking for help about Python and has found that. It's not their fault that they don't know about alternatives; so I point out the alternatives. ChrisA [1] http://math.boisestate.edu/gas/princess_ida/webop/pi_04.html On the whole we are Not intelligent... From breamoreboy at yahoo.co.uk Mon Dec 9 04:34:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 09 Dec 2013 09:34:26 +0000 Subject: python programming help In-Reply-To: <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: On 09/12/2013 05:07, rurpy at yahoo.com wrote: > On 12/08/2013 05:27 PM, Mark Lawrence wrote: >> On 09/12/2013 00:08, rurpy at yahoo.com wrote: >>> On 12/08/2013 12:17 PM, Chris Angelico wrote: >>>> On Mon, Dec 9, 2013 at 6:06 AM, wrote:>[...] >> [...] >> To the OP, please ignore the above, it's sheer, unadulterated rubbish. >> Nobody has ever been bullied into doing anything. People have however >> been asked repeatedly to either A) use the link referenced above to >> avoid sending double spaced crap here from the inferior google groups >> product or B) use an alternative technology that doesn't send double >> spaced crap. > > Mark, I appreciate your calm and reasonable requests for people > to checkout the page you gave a link to, that's why I repeated > your advice. It is also why I responded to Chris and not to you. > > However it does not change the fact that people here have responded > in rather extreme way to GG posts including calling GG users "twits" > and claiming GG posts damage their eyesight, as well as repeatedly > denying the obvious fact that GG is much easier to use for many than > to subscribe to a usenet provider or to a mailing list. One frequently > sees words like "crap", "slimy", "rubbish" etc to describe GG posts > which is pretty intimating to people who just want some help with a > python question using a tool they already know how to use and have > had no complaints about in other places. > Well you can ask iMath, amongst others, not to send double spaced google nonsense. They've been asked repeatedly, politely, but apparently have no consideration at all for people who have no interest in seeing this ill formed dross spread throughout web land. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From travisgriggs at gmail.com Mon Dec 9 10:44:08 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Mon, 9 Dec 2013 07:44:08 -0800 Subject: Meta Fight About Posting (was: python programming help) In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: On Dec 9, 2013, at 1:34 AM, Mark Lawrence wrote: > On 09/12/2013 05:07, rurpy at yahoo.com wrote: >> On 12/08/2013 05:27 PM, Mark Lawrence wrote: >>> On 09/12/2013 00:08, rurpy at yahoo.com wrote: >>>> On 12/08/2013 12:17 PM, Chris Angelico wrote: >>>>> On Mon, Dec 9, 2013 at 6:06 AM, wrote:>[...] >>> [...] >>> To the OP, please ignore the above, it's sheer, unadulterated rubbish. >>> Nobody has ever been bullied into doing anything. People have however >>> been asked repeatedly to either A) use the link referenced above to >>> avoid sending double spaced crap here from the inferior google groups >>> product or B) use an alternative technology that doesn't send double >>> spaced crap. >> >> Mark, I appreciate your calm and reasonable requests for people >> to checkout the page you gave a link to, that's why I repeated >> your advice. It is also why I responded to Chris and not to you. >> >> However it does not change the fact that people here have responded >> in rather extreme way to GG posts including calling GG users "twits" >> and claiming GG posts damage their eyesight, as well as repeatedly >> denying the obvious fact that GG is much easier to use for many than >> to subscribe to a usenet provider or to a mailing list. One frequently >> sees words like "crap", "slimy", "rubbish" etc to describe GG posts >> which is pretty intimating to people who just want some help with a >> python question using a tool they already know how to use and have >> had no complaints about in other places. >> > > Well you can ask iMath, amongst others, not to send double spaced google nonsense. They've been asked repeatedly, politely, but apparently have no consideration at all for people who have no interest in seeing this ill formed dross spread throughout web land. As long as we?re in full scale rant drift, I?d like to remind others of the time honored tradition of changing the post subject, when, er, uh, the subject changes. Because this obviously is not "programming help" anymore. The python mailing list is the only one I know of that is cross posted between 3 different technologies. Maybe it?s an outgrowth of the ?multi paradigm? philosophy of python or something. It would be an interesting experiment, to shut down the cross forum replication engines for a month. Personally, I think they should each thrive, or die, on their own. If there?s enough mass on the groups to answer the occasional one off question, it?ll go on, indifferent of the existence of the mailing list. Comp.lang.python can truly become a troll haven. :) And the mailing list can be for the more thorough threads, or something. If you?re worried about ?fragmentation?? these weekly rants seem to indicate it?s happened anyway, and the impedance mismatch between styles/technologies/formats is generating more heat from friction than it is contributing light to the cross-sharing. Besides, there?s nothing stopping periodic posts being sent to any of the sites saying ?by the way, did you know there?s also a mailing list?? The nice thing about doing it for a month (or so), is that it?s not a ?huge disturbance in the force.? If it stinks, you turn them back on in a month (or so). If you?re still not sold, and find yourself solidly in the ?keep it all together? group, I propose, we embrace that idea, and set up a bi-directional engine between the IRC channel (which I?ve found very helpful often) and the mailing list. From rustompmody at gmail.com Mon Dec 9 11:25:19 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 9 Dec 2013 08:25:19 -0800 (PST) Subject: Meta Fight About Posting (was: python programming help) In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: <058a0d03-4017-4e95-b402-94d8959ecdc9@googlegroups.com> On Monday, December 9, 2013 9:14:08 PM UTC+5:30, Travis Griggs wrote: > As long as we?re in full scale rant drift, I?d like to remind others > of the time honored tradition of changing the post subject, when, > er, uh, the subject changes. Because this obviously is not > "programming help" anymore. I believe you are missing what's actually at issue here. Lets just look at this thread: New poster asks help for a homework problem without saying so Different list members express concern/annoyance with this [NO technological (3 different technologies) issues here yet] This -- annoyance+answers -- continues for while until it morphs into GG-annoyance The *context* of the earlier annoyance -- kid asking for homework help without clearly saying so -- is lost in the GG annoyance. Now GG is clearly annoying As are kids who ask for homework help without saying so ??Whats the connection?? From rustompmody at gmail.com Mon Dec 9 11:47:46 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 9 Dec 2013 08:47:46 -0800 (PST) Subject: Meta Fight About Posting (was: python programming help) In-Reply-To: <058a0d03-4017-4e95-b402-94d8959ecdc9@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> <058a0d03-4017-4e95-b402-94d8959ecdc9@googlegroups.com> Message-ID: <25558d63-af26-488c-9345-5693d4a9b186@googlegroups.com> On Monday, December 9, 2013 9:55:19 PM UTC+5:30, rusi wrote: > On Monday, December 9, 2013 9:14:08 PM UTC+5:30, Travis Griggs wrote: > > As long as we?re in full scale rant drift, I?d like to remind others > > of the time honored tradition of changing the post subject, when, > > er, uh, the subject changes. Because this obviously is not > > "programming help" anymore. > I believe you are missing what's actually at issue here. > Lets just look at this thread: > New poster asks help for a homework problem without saying so > Different list members express concern/annoyance with this > [NO technological (3 different technologies) issues here yet] > This -- annoyance+answers -- continues for while until it morphs into GG-annoyance > The *context* of the earlier annoyance -- kid asking for homework help > without clearly saying so -- is lost in the GG annoyance. > Now GG is clearly annoying > As are kids who ask for homework help without saying so > ??Whats the connection?? I should have mentioned/asked: Are you using Google Groups to post? Your post suffers from one of GG's annoyances ? long lines. If you are using it then I wonder about the *content* of your complaint If you are not ? and the *form* of your post still has a classic-GG nuisance ? then it weakens the anti-GG case. From roy at panix.com Mon Dec 9 13:48:20 2013 From: roy at panix.com (Roy Smith) Date: Mon, 09 Dec 2013 13:48:20 -0500 Subject: Meta Fight About Posting (was: python programming help) References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> <058a0d03-4017-4e95-b402-94d8959ecdc9@googlegroups.com> Message-ID: In article <058a0d03-4017-4e95-b402-94d8959ecdc9 at googlegroups.com>, rusi wrote: > On Monday, December 9, 2013 9:14:08 PM UTC+5:30, Travis Griggs wrote: > > As long as we?re in full scale rant drift, I?d like to remind others > > of the time honored tradition of changing the post subject, when, > > er, uh, the subject changes. Because this obviously is not > > "programming help" anymore. > > > > I believe you are missing what's actually at issue here. > > Lets just look at this thread: > > New poster asks help for a homework problem without saying so While it's good nettiquette, I suppose, to state that your question is about a homework problem, it's rarely necessary. They pretty much announce themselves :-) From roy at panix.com Mon Dec 9 13:45:37 2013 From: roy at panix.com (Roy Smith) Date: Mon, 09 Dec 2013 13:45:37 -0500 Subject: Meta Fight About Posting (was: python programming help) References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: In article , Travis Griggs wrote: > The python mailing list is the only one I know of that is cross posted > between 3 different technologies. Maybe it?s an outgrowth of the ?multi > paradigm? philosophy of python or something. Usenet is not a bicycle. From rurpy at yahoo.com Tue Dec 10 00:07:51 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 9 Dec 2013 21:07:51 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <8ed4b168-7a45-4476-9078-080c43f4c1f1@googlegroups.com> Message-ID: On 12/09/2013 12:57 AM, Chris Angelico wrote: > On Mon, Dec 9, 2013 at 4:07 PM, wrote: >> However it does not change the fact that people here have responded >> in rather extreme way to GG posts including calling GG users "twits" >> and claiming GG posts damage their eyesight, as well as repeatedly >> denying the obvious fact that GG is much easier to use for many than >> to subscribe to a usenet provider or to a mailing list. One frequently >> sees words like "crap", "slimy", "rubbish" etc to describe GG posts >> which is pretty intimating to people who just want some help with a >> python question using a tool they already know how to use and have >> had no complaints about in other places. > > Please note though that there is a difference between describing the > users as twits and describing the posts as slimy. Suppose you write a > letter (the sort that goes on a slab of dead tree) and, instead of > placing it in an envelope and putting a stamp on it, you hand it to > the Arac News Insertion Device[1] to do the enveloping for you. He > does a reasonable job of it, but he uses cobwebs instead of paper for > the envelope. Sure, it's still readable... but your readers now have > to rub off a whole lot of cobwebs before they can read what you said. > That makes your post distasteful, without it being at all your fault - > other than choosing to use Arac's service. That's how I see Google > Groups posts. Someone's gone looking for help about Python and has > found that. It's not their fault that they don't know about > alternatives; so I point out the alternatives. Nevertheless, that kind of strong judgmental language is very likely to be taken as reflecting at least in part on the poster, especially when the person is from a different culture or unsure of their English skills. And if you truly just want the poster to be apprised of alternatives, I sure you'll grant me the right to point out the alternative you consistently leave out: the option to continue to use Google Groups. From rurpy at yahoo.com Mon Dec 9 00:10:30 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 8 Dec 2013 21:10:30 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> Message-ID: <3c0b48b6-2129-4e36-a455-525d6c2da3dc@googlegroups.com> On 12/08/2013 08:05 PM, Chris Angelico wrote: > On Mon, Dec 9, 2013 at 11:08 AM, wrote: >> I suspect many >> of them are motivated by political dislike of Google as >> a corporation, or want to stay with the 1990's technology >> they invested time in learning and don't want see change. > > Neither. I don't at all hate Google (I quite like the company, and > what it's done for the world), and I use plenty of other Google > services - as you can see, I'm posting from gmail here. If the shoe doesn't fit, don't wear it. There have certainly been others who have publicly railed against Google. > The only thing > I call out against is Google Groups, because it is buggy. And yet you are publicly on record as referring to GG users as "twits". > I'll cry out > against anything else that's buggy, too. Of course, I'll first try to > do things quietly (bug reports to the maintainers), but ultimately, > the solution to buggy software is to NOT USE IT. If Google doesn't > care enough about Groups to bring it up to the standard, then their > penalty has to be reduced usage. In fact, Rurpy, you are actually > encouraging the faulty system, because you're providing ad impressions > and usage stats every time you read or write via GG. When less-buggy > systems see more use than more-buggy systems, big companies have an > incentive to fix bugs. We all use buggy software every day. *Every* piece of non-trival software is buggy -- you already know that. So you are saying that bugs that annoy *you* are ones that *others* should change their practice to join your boycott to fix. You sound like some Unix hard-asses of the 1990's who, by god, weren't going pollute their software with any kind of MS Windows compatibility. No supporting a broken OS for them. They would keep the software pure and Unix-only and force Microsoft to fix their broken OS. Well, most of that software and those programmers have been eliminated by Darwinian selection, and today cross-platform (or Windows only) software is the norm. So good luck on your crusade to force Google to do things the way you think is right. (Especially given the large and growing number of Python project mailing lists *hosted* on Google Groups.) Until you're successful, I will try to encourage GG users to post more compatibly to avoid pissing off the old farts, do what I can to support Rusi's attempt to put together a tool to make it easier to do so, and finally, live with double-spaced "crap" because that is the lesser of two evils, the other being creating an excessively picky and hostile place for newcomers who just want to learn more about Python. From joel.goldstick at gmail.com Mon Dec 9 00:22:29 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 9 Dec 2013 00:22:29 -0500 Subject: python programming help In-Reply-To: <3c0b48b6-2129-4e36-a455-525d6c2da3dc@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <3c0b48b6-2129-4e36-a455-525d6c2da3dc@googlegroups.com> Message-ID: "why can't we all just get along?" Rodney King, RIP -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Dec 9 03:15:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 19:15:49 +1100 Subject: python programming help In-Reply-To: <3c0b48b6-2129-4e36-a455-525d6c2da3dc@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <3c0b48b6-2129-4e36-a455-525d6c2da3dc@googlegroups.com> Message-ID: On Mon, Dec 9, 2013 at 4:10 PM, wrote: > We all use buggy software every day. *Every* piece of non-trival > software is buggy -- you already know that. So you are saying > that bugs that annoy *you* are ones that *others* should change > their practice to join your boycott to fix. The ones that have interoperability problems are the ones that need to be fixed. When a MUD client uses CP-1252 instead of either Latin-1 or UTF-8, that's a fault in it. (Confession: My own RosMud has that exact problem, because of what it uses under the covers for screen display. But it's being retired in favour of Gypsum, which supports full Unicode and defaults to UTF-8 transport.) > You sound like some Unix hard-asses of the 1990's who, by god, weren't > going pollute their software with any kind of MS Windows compatibility. > No supporting a broken OS for them. They would keep the software pure > and Unix-only and force Microsoft to fix their broken OS. > Well, most of that software and those programmers have been eliminated > by Darwinian selection, and today cross-platform (or Windows only) > software is the norm. And there were Microsoft people in the same era who, by Bill, weren't going to pollute their software with any kind of standards compatibility. Let's look at just one product, Internet Explorer: IE6: Microsoft enjoys a near monopoly and uses this to encourage people to use IE-only features Myriad intranet sites get set up that won't work properly on any other browser. IE7: Other browsers now actually have some market-share, and people are agitating for IE to match them in behaviour. Oh dear. Guess we'd better add tabbed browsing, everyone else has it... the monopoly isn't enough to maintain itself on its own. IE8: Actually, it looks like standards compliance is becoming important. But so is compatibility with IE6. What a pain, what a pain. IE9 and IE10: The market shift to other browsers and thus the pressure shift to standards compliance continues. Unfortunately, it's just not possible to maintain IE6 compatibility, so lots of corporates have to keep XP and IE6 for their daily use. (I was in a Subway buying a sandwich a few weeks ago, and the system was having trouble. Guy was on the phone to the US trying to get it sorted out. Everything was in IE6. I pity them.) Windows-only is hardly the norm. There's at least as much software that's Mac-only or Linux-only as Windows-only. And far far more that's cross-platform or at least multi-platform. The most important thing is interoperability - sometimes that means stuff like Samba (specifically written to talk to a "foreign" system), but more often it means coding to the pre-written standards. I can write all sorts of TELNET servers and clients, and I can be confident that they'll work nicely with other people's clients and servers, and that they'll understand each other when they say IAC DO NAWS or IAC SB TERMTYPE IS "Gypsum" IAC SE. If one of them is buggy, it must be fixed, or it must not be used. ChrisA From rurpy at yahoo.com Tue Dec 10 00:10:51 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 9 Dec 2013 21:10:51 -0800 (PST) Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <3c0b48b6-2129-4e36-a455-525d6c2da3dc@googlegroups.com> Message-ID: On 12/09/2013 01:15 AM, Chris Angelico wrote: > On Mon, Dec 9, 2013 at 4:10 PM, wrote: >> We all use buggy software every day. *Every* piece of non-trival >> software is buggy -- you already know that. So you are saying >> that bugs that annoy *you* are ones that *others* should change >> their practice to join your boycott to fix. > > The ones that have interoperability problems are the ones that need to > be fixed. [...snip stuff about mud clients...]) Huh? You declare a universal truth that interoperability bugs need to be fixed but other bugs don't? A bug that give wrong financial results is less important than mojibake sometimes displayed on a web page? A bug that cause a connection failure is more important than a bug that silently corrupts saved data? Congratulations, you just won this week's jmf prize (with apologies to jmf.) >> You sound like some Unix hard-asses of the 1990's who, by god, weren't >> going pollute their software with any kind of MS Windows compatibility. >> No supporting a broken OS for them. They would keep the software pure >> and Unix-only and force Microsoft to fix their broken OS. >> Well, most of that software and those programmers have been eliminated >> by Darwinian selection, and today cross-platform (or Windows only) >> software is the norm. > > And there were Microsoft people in the same era who, by Bill, weren't > going to pollute their software with any kind of standards > compatibility. I don't think that is analogous in the same way. Unlike most people here, who seem to be driven by an personal (and emotional judging from the language used) distaste for GG posts, and a similar emotional response against MS by the Unix elitists in the 1990s, Microsoft's alleged "embrace, extend, extinguish" policy was/is (I'm pretty sure) carefully thought out and based on rational analysis. > Let's look at just one product, Internet Explorer: [...snip MSIE version history claiming decreasing market share and increasing standards compliance...] Not a convincing example at all. First its not even clear that what the factors driving such change are; open standards are only one factor. Not should you assume that all open standards are equally important and that MS' (or Google's) response will be the same to all standards across all product lines. Two, although you present MSIE as changing in response to demands to "match [other browsers] in behaviour" you leave out demands on those other browsers (and standards) to adopt features of MSIE. A unfortunate example might be the W3C consideration (maybe approved by now?) of DRM. It is not a one-way street and standards are not cast in stone. Finally it is an absurd stretch to take pressure applied by large corporate customers to MS to adopt more open standards as comparable to a handful of people in a non-major programming language mailing list refusing to read posts from GG. I am not saying that you shouldn't continue to promote your boycott against Google, just that you shouldn't be surprised or get angry when the response of some people is similar to my response towards some friends who want me to stop eating meat to fight factory farming. > Windows-only is hardly the norm. There's at least as much software > that's Mac-only or Linux-only as Windows-only. As much Mac-only software as Windows-only? Possibly, but I doubt it although I acknowledge things are moving in that direction. As much Linux-only software as Windows-only? You must be smoking crack. :-) > And far far more that's > cross-platform or at least multi-platform. The most important thing is > interoperability - sometimes that means stuff like Samba (specifically > written to talk to a "foreign" system), but more often it means coding > to the pre-written standards. I can write all sorts of TELNET servers > and clients, and I can be confident that they'll work nicely with > other people's clients and servers, and that they'll understand each > other when they say IAC DO NAWS or IAC SB TERMTYPE IS "Gypsum" IAC SE. > If one of them is buggy, it must be fixed, or it must not be used. TELNET? Does any one still use that except perhaps on secure, controlled legacy intranets? We nuked that and other protocols of it's era (FTP etc) for ssh and other (more) secure protocols ages ago. From rosuav at gmail.com Tue Dec 10 00:29:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 16:29:43 +1100 Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> <95f70ade-57a5-4537-85ba-1b612812212f@googlegroups.com> <3c0b48b6-2129-4e36-a455-525d6c2da3dc@googlegroups.com> Message-ID: On Tue, Dec 10, 2013 at 4:10 PM, wrote: >> Windows-only is hardly the norm. There's at least as much software >> that's Mac-only or Linux-only as Windows-only. > > As much Mac-only software as Windows-only? Possibly, but I doubt > it although I acknowledge things are moving in that direction. > As much Linux-only software as Windows-only? You must be smoking > crack. :-) Or just using Linux. Stuff that runs only on Linux is actually a bit of a problem at times - coders making assumptions about the environment that aren't guaranteed, and merely happen to be correct on all current versions of the Linux kernel. >> And far far more that's >> cross-platform or at least multi-platform. The most important thing is >> interoperability - sometimes that means stuff like Samba (specifically >> written to talk to a "foreign" system), but more often it means coding >> to the pre-written standards. I can write all sorts of TELNET servers >> and clients, and I can be confident that they'll work nicely with >> other people's clients and servers, and that they'll understand each >> other when they say IAC DO NAWS or IAC SB TERMTYPE IS "Gypsum" IAC SE. >> If one of them is buggy, it must be fixed, or it must not be used. > > TELNET? Does any one still use that except perhaps on secure, > controlled legacy intranets? We nuked that and other protocols > of it's era (FTP etc) for ssh and other (more) secure protocols > ages ago. TELNET protocol is the fundamental basis of MUDs. Doesn't mean there's a TELNET server at the other end. ChrisA From ybmess at nooos.fr.invalid Sun Dec 8 21:02:32 2013 From: ybmess at nooos.fr.invalid (YBM) Date: Mon, 09 Dec 2013 03:02:32 +0100 Subject: python programming help In-Reply-To: <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> <78e2bedb-edcb-47ab-a89d-b62d60611481@googlegroups.com> Message-ID: <52a524b8$0$2299$426a34cc@news.free.fr> Le 08.12.2013 20:06, rafaellasav at gmail.com a ?crit : > i get it, thanks a lot i wrote a different one and it works > > def people(age): > people=[name for name in dic if dic[name]==age] > print(people) No it doesn't. You are printing things not returning something. and combine_list is the most stupidest function you could write in Python, as it is built-in with the name 'zip'. >>> name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] >>> age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] >>> dic = dict(zip(name,age)) >>> def people(age): ... ''' How stupid it is to write three line for a one-line function''' ... return [name for name in dic if dic[name]==age] ... >>> people(20) ['Gary', 'Alice', 'Frank'] Sorry for having being rude, but : 1. you shouldn't post raw homework in any kind of public group (aren't you supposed to learn something by yourself ?) 2. your teacher is a nut. From john_ladasky at sbcglobal.net Sun Dec 8 14:21:26 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 8 Dec 2013 11:21:26 -0800 (PST) Subject: python programming help In-Reply-To: <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> Message-ID: On Sunday, December 8, 2013 10:32:31 AM UTC-8, rafae... at gmail.com wrote: [snip] > def people(age): > people=lambda age: [name for name in dic if dic[name]==age] > > people(20) [snip] > this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. Well then, don't use it! It's clear that you are new, and at least you have posted some code now, so let me try to help. >and this code doesn't give me any result Right, for TWO reasons. First problem: if your function does not end with a statement like "return people", the function returns a special Python object called None. Now, if it were me, I would not "wrap" the calculation of your "people" list inside a "people" function for such a short program. But this is apparently a requirement of your assignment. My guess is, in the future, you will write a program that calls the people function multiple times. The "lambda" word has to do with creating something called an "anonymous one-line function." You don't need that here. It's more advanced Python. What you want to do is compute and, importantly, return a list calculated from your dictionary. That is accomplished by this expression: "[name for name in dic if dic[name]==age]" This is called a "list comprehension." Do you understand what this does? It's fairly advanced. I don't teach list comprehensions to my Python students for the first several lessons. So, now that you have created the list, let's make sure that Python doesn't lose it. Let's assign a NAME to it. By the way, it's probably not good form to use the same name for a function and any of its internal variables. Pick a different name for your list: for example, "p". Then, return p from your function to your main program. My suggested rewrite of your function would be: """ def people(age): p = [name for name in dic if dic[name]==age] return p """ The truth is that you can cut this down by even one more line. This function doesn't need to hold on to the result after it is done returning it, but the computation of the result can be accomplished in one line. Therefore this will also work: """ def people(age): return [name for name in dic if dic[name]==age] """ OK, that takes care of Problem 1. Second problem: you call the "people" function with your statement "people(20)", but you don't do anything with the output. Once you fix the people function by providing a proper return statement, what does the main program do with the output of the function? Right now, it just throws it away. One solution to the problem is to make sure that the function's output gets a name. Try: """ result = people(20) """ Now, what do you want to do with result? I will wait to see your answer on that one before I intervene again. From greg.ewing at canterbury.ac.nz Sun Dec 8 19:00:38 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 09 Dec 2013 13:00:38 +1300 Subject: python programming help In-Reply-To: <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> Message-ID: rafaellasav at gmail.com wrote: > def people(age): > people=lambda age: [name for name in dic if dic[name]==age] > > but i don't get the lambda age part. Just to explain: YBM has tried to sabotage you by posting a solution that uses a couple of advanced Python features (lambda and list comprehensions) that a beginner would be unlikely to know about. The idea is that if you had simply handed that code in as-is, your teacher would know that you had almost certainly not written it yourself. Anyhow, you seem to be almost there. The only thing now is that your function needs to *return* the result instead of printing it out. To illustrate with a different example, you currently have a function like this: def add(a, b): print a + b This is fine as far as it goes, but the drawback is that printing out the result is all it will ever do. You're being asked to write a function like this: def add(a, b): return a + b This is much more useful, because you can do anything you like with the result, e.g. print add(2, 3) * add(4, 5) -- Greg From ybmess at nooos.fr.invalid Sun Dec 8 20:51:38 2013 From: ybmess at nooos.fr.invalid (YBM) Date: Mon, 09 Dec 2013 02:51:38 +0100 Subject: python programming help In-Reply-To: References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> Message-ID: <52a5222a$0$2408$426a74cc@news.free.fr> Le 09.12.2013 01:00, Gregory Ewing a ?crit : > rafaellasav at gmail.com wrote: > >> def people(age): >> people=lambda age: [name for name in dic if dic[name]==age] >> >> but i don't get the lambda age part. > > Just to explain: YBM has tried to sabotage you by posting a > solution that uses a couple of advanced Python features > (lambda and list comprehensions) that a beginner would be > unlikely to know about. Oh! I've been caught! ;-) My point is not that I had a problem with the OP (btw asking for homework in a public group always irrates me), but that the teacher of the OP is incredibly stupid and illiterate (or should I say illluterate ?) So I tried to catch both. From ybmess at nooos.fr.invalid Sun Dec 8 21:31:53 2013 From: ybmess at nooos.fr.invalid (YBM) Date: Mon, 09 Dec 2013 03:31:53 +0100 Subject: python programming help In-Reply-To: <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> References: <264c1144-5d04-4ad0-aa32-f4e6770d210c@googlegroups.com> <2243d31b-f2cb-484a-b6a3-f9f265aa8fd6@googlegroups.com> Message-ID: <52a52b99$0$2109$426a74cc@news.free.fr> Le 08.12.2013 19:32, rafaellasav at gmail.com a ?crit : > On Sunday, December 8, 2013 6:27:34 PM UTC, bob gailer wrote: >> On 12/8/2013 12:59 PM, rafaellasav at gmail.com wrote: >> >>> i have a dictionary with names and ages for each name. I want to write a function that takes in an age and returns the names of all the people who are that age. >> >>> please help >> >> Welcome to the python list. Thanks for posting a question. >> >> >> >> If you were hoping for one of us to write the program for you ... well >> >> that's not what we do on this list. >> >> >> >> Please post the code you have so far and tell us exactly where you need >> >> help. >> >> >> >> Also tell us what version of Python, what OS, and what you use to write >> >> and run Python programs. > > name = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', 'Gary', 'Helen', 'Irene', 'Jack', 'Kelly', 'Larry'] > age = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] > dic={} > def combine_lists(name,age): > for i in range(len(name)): > dic[name[i]]= age[i] > combine_lists(name,age) > print dic > > def people(age): > people=lambda age: [name for name in dic if dic[name]==age] > > people(20) > > > > > this is the code i have so far(with the help of the first post ;p). i understand how a function and a dictionary works and what I'm asked to find. but i don't get the lambda age part. and this code doesn't give me any result > You didn't write a function which return a result, so you have no result. From vasudevram at gmail.com Sun Dec 8 15:02:12 2013 From: vasudevram at gmail.com (vasudevram) Date: Sun, 8 Dec 2013 12:02:12 -0800 (PST) Subject: Domino, a Python PaaS for data science Message-ID: <48194ed6-1fc1-4c48-8c53-4eb23ad82a7b@googlegroups.com> Hi list, This may be of interest: Domino, a Python PaaS for data science: http://jugad2.blogspot.in/2013/12/domino-paas-for-data-science.html - Vasudev Ram Software training and consulting Python, Linux, C, open source, databases ... www.dancingbison.com jugad2.blogspot.com From chip9munk at gmail.com Sun Dec 8 15:25:24 2013 From: chip9munk at gmail.com (chip9munk at gmail.com) Date: Sun, 8 Dec 2013 12:25:24 -0800 (PST) Subject: django - adding a button with parallel functionality Message-ID: Hi all! I'll try to be clear and brief. I have created a django project some months ago. It is an online survey. Now I want to add a button that when pressed adds something to a database, but does not change any existing functionalities. Brief explanation: button will always be present at the pages with survey questions, when pressed it will simply add a page number (at which page user decided to press the button) to a database, but the user will continue with the survey as normal. (when the button is pressed, the view, template, questions at hand should not change. Nothing changes for the survey subject!) My question is how to simply add this button without interfering with the survey. I do not need detailed instructions with models, views, templates, etc. just brief idea if it is possible to do that without adding new view, reloading view, adding forms etc... (If anyone is interested.. the button will be used to mark when (at which page) the user gets bored with questions, it is for the pilot testing of the survey. pilot users will press the button but then continue with the survey.) Thanks in advance! Best, chip From roy at panix.com Sun Dec 8 16:27:22 2013 From: roy at panix.com (Roy Smith) Date: Sun, 08 Dec 2013 16:27:22 -0500 Subject: django - adding a button with parallel functionality References: Message-ID: In article , chip9munk at gmail.com wrote: > Hi all! I'll try to be clear and brief. > > I have created a django project some months ago. It is an online survey. > Now I want to add a button that when pressed adds something to a database, > but does not change any existing functionalities. > > Brief explanation: > button will always be present at the pages with survey questions, > when pressed it will simply add a page number (at which page user decided to > press the button) to a database, but the user will continue with the survey > as normal. > (when the button is pressed, the view, template, questions at hand should not > change. Nothing changes for the survey subject!) > > My question is how to simply add this button without interfering with the > survey. > I do not need detailed instructions with models, views, templates, etc. just > brief idea if it is possible to do that without adding new view, reloading > view, adding forms etc... Offhand, it sounds like you need a button wired up to some javascript which fires off an asynchronous HTTP request. But, since you haven't really described anything about the structure of your application, that's just a wild guess. Almost certainly, the real answer has nothing to do with Python, however. From levinie at qq.com Mon Dec 9 03:38:19 2013 From: levinie at qq.com (=?gb18030?B?bGV2aW5pZQ==?=) Date: Mon, 9 Dec 2013 16:38:19 +0800 Subject: Qml Error on CentOS6.4 when ./configure ? Message-ID: I install latest QT5 and PyQt5 on CentOS6.4 And here is some error: g++ -c -pipe -O2 -fPIC -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt/5.1.1/gcc_64/mkspecs/linux-g++ -I. -I. -I../../QtQml -I/opt/python/include/python2.7 -I/opt/Qt/5.1.1/gcc_64/include -I/opt/Qt/5.1.1/gcc_64/include/QtQml -I/opt/Qt/5.1.1/gcc_64/include/QtNetwork -I/opt/Qt/5.1.1/gcc_64/include/QtGui -I/opt/Qt/5.1.1/gcc_64/include/QtCore -I. -o qpyqml_register_type.o qpyqml_register_type.cpp qpyqml_register_type.cpp: In function ?QQmlPrivate::RegisterType* init_type(PyTypeObject*, bool, int, PyTypeObject*)?: qpyqml_register_type.cpp:262: error: insufficient contextual information to determine type qpyqml_register_type.cpp:263: error: insufficient contextual information to determine type qpyqml_register_type.cpp:264: error: insufficient contextual information to determine type qpyqml_register_type.cpp:265: error: insufficient contextual information to determine type qpyqml_register_type.cpp:266: error: insufficient contextual information to determine type qpyqml_register_type.cpp:267: error: insufficient contextual information to determine type qpyqml_register_type.cpp:268: error: insufficient contextual information to determine type qpyqml_register_type.cpp:269: error: insufficient contextual information to determine type qpyqml_register_type.cpp:270: error: insufficient contextual information to determine type qpyqml_register_type.cpp:271: error: insufficient contextual information to determine type qpyqml_register_type.cpp:272: error: insufficient contextual information to determine type qpyqml_register_type.cpp:273: error: insufficient contextual information to determine type qpyqml_register_type.cpp:274: error: insufficient contextual information to determine type qpyqml_register_type.cpp:275: error: insufficient contextual information to determine type qpyqml_register_type.cpp:276: error: insufficient contextual information to determine type qpyqml_register_type.cpp:277: error: insufficient contextual information to determine type qpyqml_register_type.cpp:278: error: insufficient contextual information to determine type qpyqml_register_type.cpp:279: error: insufficient contextual information to determine type qpyqml_register_type.cpp:280: error: insufficient contextual information to determine type qpyqml_register_type.cpp:281: error: insufficient contextual information to determine type make[2]: *** [qpyqml_register_type.o] Error 1 make[2]: Leaving directory `/root/Downloads/PyQt-gpl-5.1.1/qpy/QtQml' make[1]: *** [sub-QtQml-make_first] Error 2 make[1]: Leaving directory `/root/Downloads/PyQt-gpl-5.1.1/qpy' make: *** [sub-qpy-make_first-ordered] Error 2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Dec 10 05:46:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Dec 2013 10:46:18 GMT Subject: Qml Error on CentOS6.4 when ./configure ? References: Message-ID: <52a6f0f9$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 Dec 2013 16:38:19 +0800, levinie wrote: > I install latest QT5 and PyQt5 on CentOS6.4 And here is some error: Sorry, I have no experience installing QT or PyQT. If you don't get a response here, perhaps you should try on a dedicated QT or PyQT forum. It will probably help if you explain: - How did you install QT and PyQT? Did you use yum or did you install from source? - Is this error when you are installing QT or PyQT? - Which exact version? Is it a stable or unstable version? Good luck! -- Steven From jaiprakashsingh213 at gmail.com Mon Dec 9 03:41:57 2013 From: jaiprakashsingh213 at gmail.com (Jai) Date: Mon, 9 Dec 2013 00:41:57 -0800 (PST) Subject: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") Message-ID: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> from BeautifulSoup import BeautifulSoup import re, urllib2, MySQLdb #MySQLdb.escape_string(" ") import sys import unicodedata if __name__=="__main__": #link = raw_input("Enter the url link: ") db = MySQLdb.connect("localhost","root","", "ebay") cursor=db.cursor() link = "http://www.ebay.com/sch/Mens-Shoes-/93427/i.html?_pppn=r1&_dcat=93427&LH_ItemCondition=1000%7C1500" link1 =db.escape_string(link) page = urllib2.urlopen(link) soup = BeautifulSoup(page) Contents = soup.findAll(itemprop = "name") lst_content = [] for x in Contents: x = x.string lst_content.append(x) Price = soup.findAll(itemprop = "price") lst_price =[] for y in Price: y = y.string lst_price.append(y) for x , y in zip(lst_content, lst_price): sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""%(link1,x,y) #print sql sql = unicodedata.normalize('NFKD', sql).encode('ascii','ignore') #sys.exit(0) cursor.execute(sql) db.commit() db.close() +++++++++++++++++++++++ error occur ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") >>> From daniel at daniel-watkins.co.uk Mon Dec 9 04:32:04 2013 From: daniel at daniel-watkins.co.uk (Daniel Watkins) Date: Mon, 9 Dec 2013 09:32:04 +0000 Subject: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") In-Reply-To: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> References: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> Message-ID: <20131209093204.GV22882@daniel-watkins.co.uk> On Mon, Dec 09, 2013 at 12:41:57AM -0800, Jai wrote: > sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""%(link1,x,y) > sql = unicodedata.normalize('NFKD', sql).encode('ascii','ignore') > cursor.execute(sql) > > ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") Though you haven't given the full traceback, I suspect that the lines above are what is causing your problem. My best guess is that you're being hit by a form of SQL injection[0], in that the values you are combining in to your query have single quotes which are resulting in an SQL statement that looks like: insert into `category` (url, category, price) VALUES ('...', 'MEN'S SIZE 11.5 NEW IN BOX', '$49.99'); As you can see, the second value you are passing has mismatched quotes. This is a common problem, so the MySQLdb library handles it by allowing you to pass in the values you want to cursor.execute; it then takes care of escaping them correctly: sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')""" cursor.execute(sql, (link1, x, y)) I'm not 100% sure what the Unicode normalisation is meant to be doing, so you'll have to work out how to integrate that yourself. Cheers, Dan [0] https://en.wikipedia.org/wiki/SQL_injection From python at mrabarnett.plus.com Mon Dec 9 13:06:21 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 Dec 2013 18:06:21 +0000 Subject: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") In-Reply-To: <20131209093204.GV22882@daniel-watkins.co.uk> References: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> <20131209093204.GV22882@daniel-watkins.co.uk> Message-ID: <52A6069D.20000@mrabarnett.plus.com> On 09/12/2013 09:32, Daniel Watkins wrote: > On Mon, Dec 09, 2013 at 12:41:57AM -0800, Jai wrote: >> sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""%(link1,x,y) >> sql = unicodedata.normalize('NFKD', sql).encode('ascii','ignore') >> cursor.execute(sql) >> >> ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") > > Though you haven't given the full traceback, I suspect that the lines > above are what is causing your problem. My best guess is that you're > being hit by a form of SQL injection[0], in that the values you are > combining in to your query have single quotes which are resulting in an > SQL statement that looks like: > > insert into `category` (url, category, price) VALUES ('...', 'MEN'S SIZE 11.5 NEW IN BOX', '$49.99'); > > As you can see, the second value you are passing has mismatched quotes. > This is a common problem, so the MySQLdb library handles it by allowing > you to pass in the values you want to cursor.execute; it then takes care > of escaping them correctly: > > sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')""" > cursor.execute(sql, (link1, x, y)) > You shouldn't put quotes around the placeholders: sql = """insert into `category` (url, catagory,price) VAlUES (%s, %s, %s)""" cursor.execute(sql, (link1, x, y)) > I'm not 100% sure what the Unicode normalisation is meant to be doing, > so you'll have to work out how to integrate that yourself. > > > Cheers, > > Dan > > > [0] https://en.wikipedia.org/wiki/SQL_injection > From rosuav at gmail.com Mon Dec 9 04:36:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Dec 2013 20:36:11 +1100 Subject: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") In-Reply-To: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> References: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> Message-ID: On Mon, Dec 9, 2013 at 7:41 PM, Jai wrote: > for x , y in zip(lst_content, lst_price): > sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""%(link1,x,y) > #print sql > sql = unicodedata.normalize('NFKD', sql).encode('ascii','ignore') > #sys.exit(0) > cursor.execute(sql) My reading of your error message suggests that you just came across an item category with an apostrophe in it. What you've done here is horribly dangerous - it's an invitation for SQL injection attacks. Do not EVER do this sort of thing, it will always come back to bite you! Look into parameterized queries. They are the right way to do this. Read up on SQL injection and how to avoid it. Also: Encoding to ASCII, ignore, is a bad idea. You'll do far better to tell MySQL to use UTF-8 and then store true Unicode. Though you may find that you'll do better to get a better database like PostgreSQL, as MySQL has been known to have some issues with Unicode (not sure if they're all fixed; MySQL has enough other problems that I don't bother with it any more). Small tip, also: Spelling "VAlUES" with a lower-case L is only going to confuse people, mainly yourself :) You also seem to be inconsistent with your names - the table is called "category" (I don't think it's a reserved word, so the escaping is unnecessary there), and the column is "catagory". Is one of those incorrect? ChrisA From drsalists at gmail.com Tue Dec 10 11:23:27 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 10 Dec 2013 08:23:27 -0800 Subject: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") In-Reply-To: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> References: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> Message-ID: On Mon, Dec 9, 2013 at 12:41 AM, Jai wrote: > > sql = """insert into `category` (url, catagory,price) VAlUES > ('%s', '%s', '%s')"""%(link1,x,y) > Is that VALUES or VAlUES or VAIUES? It probably should be VALUES. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Dec 10 11:28:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Dec 2013 03:28:22 +1100 Subject: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") In-Reply-To: References: <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com> Message-ID: On Wed, Dec 11, 2013 at 3:23 AM, Dan Stromberg wrote: > > On Mon, Dec 9, 2013 at 12:41 AM, Jai wrote: >> >> >> sql = """insert into `category` (url, catagory,price) VAlUES >> ('%s', '%s', '%s')"""%(link1,x,y) > > > Is that VALUES or VAlUES or VAIUES? It probably should be VALUES. SQL's case insensitive. But I did have to check carefully to see that that really was correct. ChrisA From dfnsonfsduifb at gmx.de Mon Dec 9 06:49:46 2013 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Mon, 09 Dec 2013 12:49:46 +0100 Subject: Programming puzzle with boolean circuits Message-ID: Hi group, it's somewhat OT here, but I have a puzzle to which I would like a solution -- but I'm unsure how I should tackle the problem with Python. But it's a fun puzzle, so maybe it'll be appreciated here. The question is: How do you design a boolean circuit that contains at most 2 NOT gates, but may contain as many AND or OR gates that inverts three inputs? IOW: Build three inverters by using only two inverters (and an infinite amount of AND/OR). Surprisingly, this is possible (and I even know the solution, but won't give it away just yet). I found this puzzle again and was thinking about: How would I code a brute-force approach to this problem in Python? And to my surprise, it isn't as easy as I thought. So I'm looking for some advice from you guys (never huts to improve ones coding skills). Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rosuav at gmail.com Mon Dec 9 08:25:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 00:25:45 +1100 Subject: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: On Mon, Dec 9, 2013 at 10:49 PM, Johannes Bauer wrote: > The question is: How do you design a boolean circuit that contains at > most 2 NOT gates, but may contain as many AND or OR gates that inverts > three inputs? IOW: Build three inverters by using only two inverters > (and an infinite amount of AND/OR). > > I found this puzzle again and was thinking about: How would I code a > brute-force approach to this problem in Python? Ooooh interesting! Well, here's a start: There's no value in combining the same value in an AND or an OR, ergo every gate you add must bring together two different values. To start with, you have three values (the three inputs). Every time you combine two of them, with either type of gate, you create a new value. You can also combine a single value with a NOT to create its inverse, but only if you have done so no more than once. The goal is to produce something which is provably the opposite of each of the three inputs. I'm not sure if this helps or not, but one thing I learned from geometry is that setting down everything you know and need to know is a good basis for the search! The hardest part, so far, is proving a result. The algorithm that's coming to mind is this: def find_solution(inputs, not_count): # TODO: First, see if inputs contains three values that are the inverses of # the three values i1,i2,i3. If they are, throw something, that's probably # the easiest way to unwind the stack. if not_count < 2: for val in inputs: find_solution(inputs + [not val], not_count + 1) for val1 in inputs: for val2 in inputs: if val1 is not val2: find_solution(inputs + [val1 and val2], not_count) find_solution(inputs + [val1 or val2], not_count) find_solution([i1, i2, i3], 0) So, here's a crazy idea: Make i1, i2, i3 into objects of a type with an __eq__ that actually does the verification. Schrodinger's Objects: they might be True, might be False, and until you call __eq__, they're in both states. This probably isn't the best way, but I think it's the most fun! I couldn't make this work with the and/or/not operators, so I'm using the &/|/~ operators, which can be overridden. So! There's the basics, but it's a depth-first search, which means it's bound to hit the recursion limit. Refinement needed; specifically, it needs to not add any input that's equal to any other. That's easy enough. Unfortunately I haven't been able to prove that the code works, because even with some changes it's taking way too long. But hey, it's a crazy fun piece to work with! class Schrodinger: def __init__(self, bit): self.state = bit def coalesce(self, master): return bool(master & self.state) def __len__(self): return 1; def __invert__(self): return Negated(self) def __and__(self, other): return Anded((self, other)) def __or__(self, other): return Ored((self, other)) def __eq__(self, other): for master in range(8): if self.coalesce(master) != other.coalesce(master): return False return True def __repr__(self): return "$%d" % self.state class Negated(Schrodinger): def coalesce(self, master): return not self.state.coalesce(master) def __len__(self): return len(self.state) + 1 def __repr__(self): return "not %r" % self.state class Anded(Schrodinger): def coalesce(self, master): return self.state[0].coalesce(master) and self.state[1].coalesce(master) def __len__(self): return len(self.state[0]) + len(self.state[1]) + 1 def __repr__(self): return "%r and %r" % self.state class Ored(Schrodinger): def coalesce(self, master): return self.state[0].coalesce(master) or self.state[1].coalesce(master) def __len__(self): return len(self.state[0]) + len(self.state[1]) + 1 def __repr__(self): return "%r or %r" % self.state class SolutionFound(Exception): pass def find_solution(inputs, not_count): # First see if the newest input is equal to anything we already have. # If it is, we gain nothing by probing this. if inputs[-1] in inputs[:-1]: return # Then, see if inputs contains three values that are the inverses of # the three values i1,i2,i3. If they are, throw something, that's probably # the easiest way to unwind the stack. try: raise SolutionFound("""Solution: ~$1 = %r ~$2 = %r ~$4 = %r""" % ( inputs[inputs.index(~inputs[0])], inputs[inputs.index(~inputs[1])], inputs[inputs.index(~inputs[2])], )) except ValueError: pass # ValueError means one of the negations wasn't found. if not_count < 2: for val in inputs: find_solution(inputs + [~val], not_count + 1) for val1 in inputs: for val2 in inputs: find_solution(inputs + [val1 & val2], not_count) find_solution(inputs + [val1 | val2], not_count) i1 = Schrodinger(1) i2 = Schrodinger(2) i3 = Schrodinger(4) find_solution([i1, i2, i3], 0) ChrisA From rosuav at gmail.com Mon Dec 9 20:41:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 12:41:46 +1100 Subject: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: On Tue, Dec 10, 2013 at 12:25 AM, Chris Angelico wrote: > Unfortunately I haven't been able to prove that the code works, > because even with some changes it's taking way too long. But hey, it's > a crazy fun piece to work with! Well... it eventually solved the problem. I don't know how many CPU hours it took but it threw a SolutionFound exception eventually. Unfortunately I didn't parenthesize the display. The solution seems to involve using a NOT gate and then splitting its output, so you'll see more than two instances of 'not' in the output. This is definitely not an optimal solution, but hey, you asked for a brute-force solver! ~$1 = $4 or not $1 and $2 or $4 and $1 or $2 and $4 and not $1 and $2 or $4 and $1 or $2 or $2 or not $1 and $2 or $4 and $1 or $2 and $2 and not $1 and $2 or $4 and $1 or $2 or not $2 or $1 or $4 and $2 and $1 and $4 or not $1 and $2 or $4 and $1 or $2 ~$2 = $4 or not $1 and $2 or $4 and $1 or $2 and $4 and not $1 and $2 or $4 and $1 or $2 or $1 or not $1 and $2 or $4 and $1 or $2 and $1 and not $1 and $2 or $4 and $1 or $2 or not $2 or $1 or $4 and $2 and $1 and $4 or not $1 and $2 or $4 and $1 or $2 ~$4 = $2 or not $1 and $2 or $4 and $1 or $2 and $2 and not $1 and $2 or $4 and $1 or $2 or $1 or not $1 and $2 or $4 and $1 or $2 and $1 and not $1 and $2 or $4 and $1 or $2 or not $2 or $1 or $4 and $2 and $1 and $4 or not $1 and $2 or $4 and $1 or $2 ChrisA From joel.goldstick at gmail.com Mon Dec 9 15:19:25 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 9 Dec 2013 15:19:25 -0500 Subject: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: On Mon, Dec 9, 2013 at 6:49 AM, Johannes Bauer wrote: > Hi group, > > it's somewhat OT here, but I have a puzzle to which I would like a > solution -- but I'm unsure how I should tackle the problem with Python. > But it's a fun puzzle, so maybe it'll be appreciated here. > > The question is: How do you design a boolean circuit that contains at > most 2 NOT gates, but may contain as many AND or OR gates that inverts > three inputs? IOW: Build three inverters by using only two inverters > (and an infinite amount of AND/OR). > > Surprisingly, this is possible (and I even know the solution, but won't > give it away just yet). > > I found this puzzle again and was thinking about: How would I code a > brute-force approach to this problem in Python? And to my surprise, it > isn't as easy as I thought. So I'm looking for some advice from you guys > (never huts to improve ones coding skills). > > Best regards, > Johannes > > I studied Electrical Engineering in college, so this puzzle grabbed my attention. For a couple of hours I played around thinking about how to attack this problem My first thought was that if you had two inverters (NOT gates), you needed to create an inverter with and and or gates. That goes nowhere. So, I googled around and found this: http://www.thelowlyprogrammer.com/2008/05/not-puzzle-solution.html (spoiler alert). It discusses how you can solve the problem, but it doesn't give python code. As it ends up I implemented that solution in 18 lines of code So, my hint is that it can be solved by creating several simultaneous equations I'll send my code along if someone asks, but I don't want to post it here because I'm sure others will want to figure it out on their own. > -- > >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > > Zumindest nicht ?ffentlich! > Ah, der neueste und bis heute genialste Streich unsere gro?en > Kosmologen: Die Geheim-Vorhersage. > - Karl Kaos ?ber R?diger Thomas in dsa > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From john_ladasky at sbcglobal.net Mon Dec 9 15:39:18 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 9 Dec 2013 12:39:18 -0800 (PST) Subject: Spoiler alert? (Re: Programming puzzle with boolean circuits) In-Reply-To: References: Message-ID: It has been ages since I've thought about logic gates, but... (Spoiler alert? I'm not sure...) . . . . . . . . . . . . . . . . My thought is that with two NOT logic gates, you can only build a flip-flop memory circuit. That strongly suggests to me that a memory circuit would actually be used to solve the problem somehow. I'm thinking that feedback loops would have to be involved, no matter what the solution is. A need for feedback loops would make it very hard to write code to look for the solution automatically. The dimensionality of the search space will be high. From joel.goldstick at gmail.com Mon Dec 9 15:45:51 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 9 Dec 2013 15:45:51 -0500 Subject: Spoiler alert? (Re: Programming puzzle with boolean circuits) In-Reply-To: References: Message-ID: On Mon, Dec 9, 2013 at 3:39 PM, John Ladasky wrote: > It has been ages since I've thought about logic gates, but... > > My thought is that with two NOT logic gates, you can only build a > flip-flop memory circuit. That strongly suggests to me that a memory > circuit would actually be used to solve the problem somehow. > > Two NOT gates plus as many AND and OR gates as you need. > I'm thinking that feedback loops would have to be involved, no matter what > the solution is. A need for feedback loops would make it very hard to > write code to look for the solution automatically. The dimensionality of > the search space will be high. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Mon Dec 9 21:03:21 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 9 Dec 2013 21:03:21 -0500 Subject: Fwd: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: Chris, and all.. Since you posted yours, I post this for your pleasure. I couldn't figure out what you were doing. #!/usr/bin/env python """ This is a puzzle brought up on the python mailing list. The goal is to take 3 bits and invert them using boolean logic, but restricted to only 2 NOT gates Here is a solution I found via google: http://www.thelowlyprogrammer.com/2008/05/not-puzzle-solution.html """ def invert_three(a,b,c): """ give three boolean values, return their inverted values Only 2 NOT operators are allowed Deduce these truths """ all_ones = a and b and c two_or_three = (a and b) or (a and c) or (b and c) zero_or_one = not two_or_three one_one = zero_or_one and (a or b or c) zero_or_two = not (all_ones or one_one) zero_ones = zero_or_one and zero_or_two two_ones = zero_or_two and two_or_three # the output is true if all the inputs are zero, or if one of the inputs is zero and it is either b or c # or two inputs are zero and they are b and c # ditto for other two inputs x = zero_ones or (one_one and (b or c)) or (two_ones and (b and c)) y = zero_ones or (one_one and (a or c)) or (two_ones and (a and c)) z = zero_ones or (one_one and (b or a)) or (two_ones and (b and a)) return int(x), int(y), int(z) if __name__ == "__main__": for a in range(2): for b in range(2): for c in range(2): print "Input: ", a, b, c, x, y, z = invert_three(a,b,c) print "Output: ", x, y, z -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Dec 9 21:21:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 13:21:46 +1100 Subject: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: On Tue, Dec 10, 2013 at 1:03 PM, Joel Goldstick wrote: > Chris, and all.. Since you posted yours, I post this for your pleasure. I > couldn't figure out what you were doing. > [chomp Python implementation of a fairly elegant solution] That's a fairly nice piece of code that comes from a deliberate solution. What the OP asked was how to devise a brute-force solver. Grab the four class definitions from my code a few posts ago, and then tweak your code to use them: a = Schrodinger(1) b = Schrodinger(2) c = Schrodinger(4) all_ones = a & b & c two_or_three = (a & b) | (a & c) | (b & c) zero_or_one = ~two_or_three one_one = zero_or_one & (a | b | c) zero_or_two = ~(all_ones | one_one) zero_ones = zero_or_one & zero_or_two two_ones = zero_or_two & two_or_three # the output is true if all the inputs are zero, | if one of the inputs is zero & it is either b | c # | two inputs are zero & they are b & c # ditto f| other two inputs x = zero_ones | (one_one & (b | c)) | (two_ones & (b & c)) y = zero_ones | (one_one & (a | c)) | (two_ones & (a & c)) z = zero_ones | (one_one & (b | a)) | (two_ones & (b & a)) if x == ~a: print(x) if y == ~b: print(y) if z == ~c: print(z) Output: (I tweaked my __repr__ functions to parenthesize for clarity) (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)) and ($2 or $4))) or ((not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and $4))) and ($2 and $4))) (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)) and ($1 or $4))) or ((not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and $4))) and ($1 and $4))) (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)) and ($2 or $1))) or ((not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and $4))) and ($2 and $1))) Okay, so maybe the brute-force-discovered version isn't so bad after all. :) The classes allow "a and b == c" to be evaluated for all possible values of a, b, and c, so the brute-forcing actually accumulates data and only subsequently evaluates it. It's far from the most efficient solution (took hours on an i5 CPU), but it's fun :) ChrisA From rosuav at gmail.com Tue Dec 10 03:50:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 19:50:40 +1100 Subject: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: On Tue, Dec 10, 2013 at 1:21 PM, Chris Angelico wrote: > Output: (I tweaked my __repr__ functions to parenthesize for clarity) > > (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and > $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and > (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 > and $4)) and (($1 or $2) or $4)) and ($2 or $4))) or ((not ((($1 and > $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and > (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and > $4))) and ($2 and $4))) > (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and > $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and > (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 > and $4)) and (($1 or $2) or $4)) and ($1 or $4))) or ((not ((($1 and > $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and > (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and > $4))) and ($1 and $4))) > (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and > $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and > (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 > and $4)) and (($1 or $2) or $4)) and ($2 or $1))) or ((not ((($1 and > $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and > (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and > $4))) and ($2 and $1))) > > Okay, so maybe the brute-force-discovered version isn't so bad after all. :) I added the same parenthesizing to the brute force searcher and reran it through 'time'. ~$1 = (($4 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($4 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($2 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($2 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) ~$2 = (($4 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($4 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($1 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($1 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) ~$4 = (($2 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($2 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($1 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($1 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) real 362m12.261s user 362m7.186s sys 0m0.064s Yes, that is indeed six full hours of CPU time for a simple problem. Ha! It seems to have come up with something fairly similar, actually. A bit shorter than the algebraic solution. brute: (($4 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($4 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($2 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($2 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) algebra: (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)) and ($2 or $4))) or ((not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and $4))) and ($2 and $4))) Here's the most notable difference: two_or_three = (a & b) | (a & c) | (b & c) can be simplified to: two_or_three = (a & b) | (c & (a | b)) That's one less gate in an early step. Even applying that change, though, the brute-forced solution is still a bit shorter. Looks like the algebraic solution could have a bit of optimization done! ChrisA From antoon.pardon at rece.vub.ac.be Tue Dec 10 09:25:42 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 10 Dec 2013 15:25:42 +0100 Subject: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: <52A72466.6060306@rece.vub.ac.be> Op 09-12-13 12:49, Johannes Bauer schreef: > Hi group, > > it's somewhat OT here, but I have a puzzle to which I would like a > solution -- but I'm unsure how I should tackle the problem with Python. > But it's a fun puzzle, so maybe it'll be appreciated here. > > The question is: How do you design a boolean circuit that contains at > most 2 NOT gates, but may contain as many AND or OR gates that inverts > three inputs? IOW: Build three inverters by using only two inverters > (and an infinite amount of AND/OR). > > Surprisingly, this is possible (and I even know the solution, but won't > give it away just yet). > > I found this puzzle again and was thinking about: How would I code a > brute-force approach to this problem in Python? And to my surprise, it > isn't as easy as I thought. So I'm looking for some advice from you guys > (never huts to improve ones coding skills). Well I would make some kind of connecter type, that would have a binary vector associated with it. How do we calculate bit n of a connector? Take the three input signals, i0, i1, i2, these can be seen as a binary digits. So suppose we have input 0, 1, 0 then bit 2 of the connector would be the value of that connector with these input signals. The original three connectors would have the following values: 01010101, 00110011, 00001111. What you can do now is make new connectors by combining them with an or, and or not port and search for those whose value is 10101010, 11001100 and 11110000. -- Antoon Pardon From dfnsonfsduifb at gmx.de Wed Dec 11 08:52:40 2013 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 11 Dec 2013 14:52:40 +0100 Subject: Programming puzzle with boolean circuits In-Reply-To: References: Message-ID: On 09.12.2013 14:25, Chris Angelico wrote: >> I found this puzzle again and was thinking about: How would I code a >> brute-force approach to this problem in Python? > > Ooooh interesting! Ha, I thought so too :-) > Well, here's a start: There's no value in combining the same value in > an AND or an OR, ergo every gate you add must bring together two > different values. > > To start with, you have three values (the three inputs). Every time > you combine two of them, with either type of gate, you create a new > value. You can also combine a single value with a NOT to create its > inverse, but only if you have done so no more than once. > > The goal is to produce something which is provably the opposite of > each of the three inputs. > > I'm not sure if this helps or not, but one thing I learned from > geometry is that setting down everything you know and need to know is > a good basis for the search! Absolutely. > > The hardest part, so far, is proving a result. The algorithm that's > coming to mind is this: > > def find_solution(inputs, not_count): > # TODO: First, see if inputs contains three values that are the inverses of > # the three values i1,i2,i3. If they are, throw something, that's probably > # the easiest way to unwind the stack. > if not_count < 2: > for val in inputs: > find_solution(inputs + [not val], not_count + 1) > for val1 in inputs: > for val2 in inputs: > if val1 is not val2: > find_solution(inputs + [val1 and val2], not_count) > find_solution(inputs + [val1 or val2], not_count) > > find_solution([i1, i2, i3], 0) I understand your approach, it has given me some ideas too. Thanks for this! > So, here's a crazy idea: Make i1, i2, i3 into objects of a type with > an __eq__ that actually does the verification. Schrodinger's Objects: > they might be True, might be False, and until you call __eq__, they're > in both states. This probably isn't the best way, but I think it's the > most fun! Haha, it surely is a very cool idea! Thanks for the ideas and your very cool approach. I'll try to tackle it myself (I think I have a good point to start) and will post the code once I'm finished. Best regards, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From oscar.j.benjamin at gmail.com Mon Dec 9 07:23:41 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 9 Dec 2013 12:23:41 +0000 Subject: Experiences/guidance on teaching Python as a first programming language Message-ID: Hi all, I work in a University Engineering faculty teaching, among other things, programming. In our last meeting about improving our teaching syllabus and delivery we've identified the first year programming courses as an area where there is room for improvement and we're considering (mainly on my suggestion) switching to using Python as the first programming language that we use to introduce our students to programming. I'm interested to know if anyone can share experience of a similar situation or can point to any case studies about this. The course is for ~100 1st year students with half studying Engineering Mathematics and the other half Electrical Engineering. Currently we introduce programming with C for the 1st semester and then C++ for the 2nd semester. In the 3rd semester they learn Matlab and following on from that they can take optional units run by the CS department in Java, Haskell and many more. Our faculty does not currently offer any Python courses for students at any level in CS or Engineering. Many of the students complain that the C course is too hard and my experience is that it doesn't equip them with the general understanding of programming that we really want them to get from the first programming course. I'm not sure about the Electrical Engineering students but the Engineering Mathematics students tend not to use C/C++ once they have covered Matlab and just use Matlab for all future projects, including in situations where it is highly inappropriate. In our recent meeting I proposed that Python should be the first programming language, and others proposed that Java should be the second. So we're currently evaluating the option of having Python in the first semester followed by Java in the second. Both courses would have to be created from scratch meaning that we would need to draw a complete outline and syllabus by mid-January in order to roll this out for the next academic year. I think that the benefits of this would be that using an "easy" language would be less distracting while we introduce the general concepts of programming. What we really want is for the students to focus on things like "why would I write a program?", "what kind of things can I do with a program?" and "how would I go about writing a program that does X?". Ideally by the end of the course we want that, given a description of a simple command line program that would perhaps calculate something or do some simple data processing, then the students would feel confident that they could do that. I think that using C distracts them from learning these more important general lessons as they struggle with simple things like how to print output, or avoid segmentation faults. Also ideally they would continue to use the language, where appropriate, for subsequent project work (which is when they would *really* learn the language). Some of the objections to the idea that were voiced in the meeting were that: 1) Some people felt that Python is not an "industry standard" unlike C/C++/Java and that it is not as good for employability. 2) Students should learn to program in a statically typed language because it leads to good programming discipline. 3) Python is too close to Matlab (which is considered essential for some industries our students often go in to). 4) It is better for students to be introduced to programming with a low-level language so that they gain a better understanding of how computers "really work". 5) Learning to program "should be painful" and we should expect the students to complain about it (someone actually said that!) but the pain makes them better programmers in the end. I'm particularly interested to know if anyone can share experience of switching to teaching Python as a first programming language in a similar context. A written up case study that I could circulate among the relevant staff would be especially useful. Thanks in advance, Oscar From gheskett at wdtv.com Mon Dec 9 08:24:25 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 9 Dec 2013 08:24:25 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <201312090824.25211.gheskett@wdtv.com> On Monday 09 December 2013 07:51:12 Oscar Benjamin did opine: > Hi all, > > I work in a University Engineering faculty teaching, among other > things, programming. In our last meeting about improving our teaching > syllabus and delivery we've identified the first year programming > courses as an area where there is room for improvement and we're > considering (mainly on my suggestion) switching to using Python as the > first programming language that we use to introduce our students to > programming. I'm interested to know if anyone can share experience of > a similar situation or can point to any case studies about this. > > The course is for ~100 1st year students with half studying > Engineering Mathematics and the other half Electrical Engineering. > Currently we introduce programming with C for the 1st semester and > then C++ for the 2nd semester. In the 3rd semester they learn Matlab > and following on from that they can take optional units run by the CS > department in Java, Haskell and many more. Our faculty does not > currently offer any Python courses for students at any level in CS or > Engineering. > > Many of the students complain that the C course is too hard and my > experience is that it doesn't equip them with the general > understanding of programming that we really want them to get from the > first programming course. I'm not sure about the Electrical > Engineering students but the Engineering Mathematics students tend not > to use C/C++ once they have covered Matlab and just use Matlab for all > future projects, including in situations where it is highly > inappropriate. > > In our recent meeting I proposed that Python should be the first > programming language, and others proposed that Java should be the > second. So we're currently evaluating the option of having Python in > the first semester followed by Java in the second. Both courses would > have to be created from scratch meaning that we would need to draw a > complete outline and syllabus by mid-January in order to roll this out > for the next academic year. > > I think that the benefits of this would be that using an "easy" > language would be less distracting while we introduce the general > concepts of programming. What we really want is for the students to > focus on things like "why would I write a program?", "what kind of > things can I do with a program?" and "how would I go about writing a > program that does X?". Ideally by the end of the course we want that, > given a description of a simple command line program that would > perhaps calculate something or do some simple data processing, then > the students would feel confident that they could do that. I think > that using C distracts them from learning these more important general > lessons as they struggle with simple things like how to print output, > or avoid segmentation faults. Also ideally they would continue to use > the language, where appropriate, for subsequent project work (which is > when they would *really* learn the language). > > Some of the objections to the idea that were voiced in the meeting were > that: 1) Some people felt that Python is not an "industry standard" > unlike C/C++/Java and that it is not as good for employability. > 2) Students should learn to program in a statically typed language > because it leads to good programming discipline. > 3) Python is too close to Matlab (which is considered essential for > some industries our students often go in to). > 4) It is better for students to be introduced to programming with a > low-level language so that they gain a better understanding of how > computers "really work". > 5) Learning to program "should be painful" and we should expect the > students to complain about it (someone actually said that!) but the > pain makes them better programmers in the end. > > I'm particularly interested to know if anyone can share experience of > switching to teaching Python as a first programming language in a > similar context. A written up case study that I could circulate among > the relevant staff would be especially useful. > > > Thanks in advance, > Oscar I toss out that 1. a semester is insufficient to gain a working familiarity with either python or java. And neither should be introduced until a decent foundation has been laid. 2. If you want to start at the nuts and bolts level, (and you should) then nothing can compare with a semester or more in assembly language for an easy to learn 8/16 bit mcu like a 6809. IMO learning the Intel assembly for the 8088 and its git, or even the higher level motorola stuff is counter productive because they get lost in the details that are really best handled by a compiler. We actually have a reasonably complete, unix like OS for that mcu, used to be os9 30 years ago, migrated to community supported now and called Nitros9 as we have about doubled its speed over the original. I helped in its conversion to run on the smarter 6309, and I've written some of its lesser used drivers, like a serial mouse. Once they get the concept of doing operations on registers they have loaded with data, and then storing the result, possibly for further use in another block of code, C will be much easier to teach well as that background will give them the ability to treat C as a higher level, but still close to assembly language. The student can easily envision what C is doing, statement by statement, which will help comprehension, a lot. Then spend at least a semester on methods of looking at a problem, breaking it down into pieces to solve, then organizing the code to solve that problem, which if done right, should result in their having a view that might even be language independent. This can't help but be good in the long run. The ability to compose a block diagram with the flow, will result in a student whose code will be a lot closer to correct right out of the gate as opposed to the student and prof doing 2 weeks of back and forth until he, sometimes accidentally, finally gets it right. By that time both are cross-eyed from looking at so much code that doesn't work well. Here is where the truly high level language like python or java enters the conversation. My $0.02, in 1934 dollars of course. ;-) Cheers, Gene -- "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 All God's children are not beautiful. Most of God's children are, in fact, barely presentable. -- Fran Lebowitz, "Metropolitan Life" A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From larry.martell at gmail.com Mon Dec 9 08:39:36 2013 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 9 Dec 2013 08:39:36 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <201312090824.25211.gheskett@wdtv.com> References: <201312090824.25211.gheskett@wdtv.com> Message-ID: On Mon, Dec 9, 2013 at 8:24 AM, Gene Heskett wrote: > On Monday 09 December 2013 07:51:12 Oscar Benjamin did opine: > >> Hi all, >> >> I work in a University Engineering faculty teaching, among other >> things, programming. In our last meeting about improving our teaching >> syllabus and delivery we've identified the first year programming >> courses as an area where there is room for improvement and we're >> considering (mainly on my suggestion) switching to using Python as the >> first programming language that we use to introduce our students to >> programming. I'm interested to know if anyone can share experience of >> a similar situation or can point to any case studies about this. >> >> The course is for ~100 1st year students with half studying >> Engineering Mathematics and the other half Electrical Engineering. >> Currently we introduce programming with C for the 1st semester and >> then C++ for the 2nd semester. In the 3rd semester they learn Matlab >> and following on from that they can take optional units run by the CS >> department in Java, Haskell and many more. Our faculty does not >> currently offer any Python courses for students at any level in CS or >> Engineering. >> >> Many of the students complain that the C course is too hard and my >> experience is that it doesn't equip them with the general >> understanding of programming that we really want them to get from the >> first programming course. I'm not sure about the Electrical >> Engineering students but the Engineering Mathematics students tend not >> to use C/C++ once they have covered Matlab and just use Matlab for all >> future projects, including in situations where it is highly >> inappropriate. >> >> In our recent meeting I proposed that Python should be the first >> programming language, and others proposed that Java should be the >> second. So we're currently evaluating the option of having Python in >> the first semester followed by Java in the second. Both courses would >> have to be created from scratch meaning that we would need to draw a >> complete outline and syllabus by mid-January in order to roll this out >> for the next academic year. >> >> I think that the benefits of this would be that using an "easy" >> language would be less distracting while we introduce the general >> concepts of programming. What we really want is for the students to >> focus on things like "why would I write a program?", "what kind of >> things can I do with a program?" and "how would I go about writing a >> program that does X?". Ideally by the end of the course we want that, >> given a description of a simple command line program that would >> perhaps calculate something or do some simple data processing, then >> the students would feel confident that they could do that. I think >> that using C distracts them from learning these more important general >> lessons as they struggle with simple things like how to print output, >> or avoid segmentation faults. Also ideally they would continue to use >> the language, where appropriate, for subsequent project work (which is >> when they would *really* learn the language). >> >> Some of the objections to the idea that were voiced in the meeting were >> that: 1) Some people felt that Python is not an "industry standard" >> unlike C/C++/Java and that it is not as good for employability. >> 2) Students should learn to program in a statically typed language >> because it leads to good programming discipline. >> 3) Python is too close to Matlab (which is considered essential for >> some industries our students often go in to). >> 4) It is better for students to be introduced to programming with a >> low-level language so that they gain a better understanding of how >> computers "really work". >> 5) Learning to program "should be painful" and we should expect the >> students to complain about it (someone actually said that!) but the >> pain makes them better programmers in the end. >> >> I'm particularly interested to know if anyone can share experience of >> switching to teaching Python as a first programming language in a >> similar context. A written up case study that I could circulate among >> the relevant staff would be especially useful. >> >> >> Thanks in advance, >> Oscar > > I toss out that > > 1. a semester is insufficient to gain a working familiarity with either > python or java. And neither should be introduced until a decent foundation > has been laid. > > 2. If you want to start at the nuts and bolts level, (and you should) then > nothing can compare with a semester or more in assembly language for an > easy to learn 8/16 bit mcu like a 6809. IMO learning the Intel assembly > for the 8088 and its git, or even the higher level motorola stuff is > counter productive because they get lost in the details that are really > best handled by a compiler. We actually have a reasonably complete, unix > like OS for that mcu, used to be os9 30 years ago, migrated to community > supported now and called Nitros9 as we have about doubled its speed over > the original. I helped in its conversion to run on the smarter 6309, and > I've written some of its lesser used drivers, like a serial mouse. > > Once they get the concept of doing operations on registers they have loaded > with data, and then storing the result, possibly for further use in another > block of code, C will be much easier to teach well as that background will > give them the ability to treat C as a higher level, but still close to > assembly language. The student can easily envision what C is doing, > statement by statement, which will help comprehension, a lot. > > Then spend at least a semester on methods of looking at a problem, breaking > it down into pieces to solve, then organizing the code to solve that > problem, which if done right, should result in their having a view that > might even be language independent. This can't help but be good in the > long run. The ability to compose a block diagram with the flow, will > result in a student whose code will be a lot closer to correct right out of > the gate as opposed to the student and prof doing 2 weeks of back and forth > until he, sometimes accidentally, finally gets it right. By that time both > are cross-eyed from looking at so much code that doesn't work well. > Here is where the truly high level language like python or java enters the > conversation. > > My $0.02, in 1934 dollars of course. ;-) I agree with Gene on the benefit of knowing a low level language and having experience with the hardware and top-down analysis. I went to college in the late 70's and I find my knowledge of those things helps me tremendously when debugging. I think college isn't as much to teach you specific things as it is to teach you how to learn (especially in this industry). I've encountered many kids today who come out of school, and think java is the only language and they have no design skills and no knowledge of how the machine actually works. From gheskett at shentel.net Mon Dec 9 11:10:25 2013 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 9 Dec 2013 11:10:25 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> Message-ID: <201312091110.25470.gheskett@wdtv.com> On Monday 09 December 2013 10:46:42 Larry Martell did opine: > On Mon, Dec 9, 2013 at 8:24 AM, Gene Heskett wrote: > > On Monday 09 December 2013 07:51:12 Oscar Benjamin did opine: > >> Hi all, > >> > >> I work in a University Engineering faculty teaching, among other > >> things, programming. In our last meeting about improving our teaching > >> syllabus and delivery we've identified the first year programming > >> courses as an area where there is room for improvement and we're > >> considering (mainly on my suggestion) switching to using Python as > >> the first programming language that we use to introduce our students > >> to programming. I'm interested to know if anyone can share > >> experience of a similar situation or can point to any case studies > >> about this. > >> > >> The course is for ~100 1st year students with half studying > >> Engineering Mathematics and the other half Electrical Engineering. > >> Currently we introduce programming with C for the 1st semester and > >> then C++ for the 2nd semester. In the 3rd semester they learn Matlab > >> and following on from that they can take optional units run by the CS > >> department in Java, Haskell and many more. Our faculty does not > >> currently offer any Python courses for students at any level in CS or > >> Engineering. > >> > >> Many of the students complain that the C course is too hard and my > >> experience is that it doesn't equip them with the general > >> understanding of programming that we really want them to get from the > >> first programming course. I'm not sure about the Electrical > >> Engineering students but the Engineering Mathematics students tend > >> not to use C/C++ once they have covered Matlab and just use Matlab > >> for all future projects, including in situations where it is highly > >> inappropriate. > >> > >> In our recent meeting I proposed that Python should be the first > >> programming language, and others proposed that Java should be the > >> second. So we're currently evaluating the option of having Python in > >> the first semester followed by Java in the second. Both courses would > >> have to be created from scratch meaning that we would need to draw a > >> complete outline and syllabus by mid-January in order to roll this > >> out for the next academic year. > >> > >> I think that the benefits of this would be that using an "easy" > >> language would be less distracting while we introduce the general > >> concepts of programming. What we really want is for the students to > >> focus on things like "why would I write a program?", "what kind of > >> things can I do with a program?" and "how would I go about writing a > >> program that does X?". Ideally by the end of the course we want that, > >> given a description of a simple command line program that would > >> perhaps calculate something or do some simple data processing, then > >> the students would feel confident that they could do that. I think > >> that using C distracts them from learning these more important > >> general lessons as they struggle with simple things like how to > >> print output, or avoid segmentation faults. Also ideally they would > >> continue to use the language, where appropriate, for subsequent > >> project work (which is when they would *really* learn the language). > >> > >> Some of the objections to the idea that were voiced in the meeting > >> were that: 1) Some people felt that Python is not an "industry > >> standard" unlike C/C++/Java and that it is not as good for > >> employability. 2) Students should learn to program in a statically > >> typed language because it leads to good programming discipline. > >> 3) Python is too close to Matlab (which is considered essential for > >> some industries our students often go in to). > >> 4) It is better for students to be introduced to programming with a > >> low-level language so that they gain a better understanding of how > >> computers "really work". > >> 5) Learning to program "should be painful" and we should expect the > >> students to complain about it (someone actually said that!) but the > >> pain makes them better programmers in the end. > >> > >> I'm particularly interested to know if anyone can share experience of > >> switching to teaching Python as a first programming language in a > >> similar context. A written up case study that I could circulate among > >> the relevant staff would be especially useful. > >> > >> > >> Thanks in advance, > >> Oscar > > > > I toss out that > > > > 1. a semester is insufficient to gain a working familiarity with > > either python or java. And neither should be introduced until a > > decent foundation has been laid. > > > > 2. If you want to start at the nuts and bolts level, (and you should) > > then nothing can compare with a semester or more in assembly language > > for an easy to learn 8/16 bit mcu like a 6809. IMO learning the > > Intel assembly for the 8088 and its git, or even the higher level > > motorola stuff is counter productive because they get lost in the > > details that are really best handled by a compiler. We actually have > > a reasonably complete, unix like OS for that mcu, used to be os9 30 > > years ago, migrated to community supported now and called Nitros9 as > > we have about doubled its speed over the original. I helped in its > > conversion to run on the smarter 6309, and I've written some of its > > lesser used drivers, like a serial mouse. > > > > Once they get the concept of doing operations on registers they have > > loaded with data, and then storing the result, possibly for further > > use in another block of code, C will be much easier to teach well as > > that background will give them the ability to treat C as a higher > > level, but still close to assembly language. The student can easily > > envision what C is doing, statement by statement, which will help > > comprehension, a lot. > > > > Then spend at least a semester on methods of looking at a problem, > > breaking it down into pieces to solve, then organizing the code to > > solve that problem, which if done right, should result in their > > having a view that might even be language independent. This can't > > help but be good in the long run. The ability to compose a block > > diagram with the flow, will result in a student whose code will be a > > lot closer to correct right out of the gate as opposed to the student > > and prof doing 2 weeks of back and forth until he, sometimes > > accidentally, finally gets it right. By that time both are > > cross-eyed from looking at so much code that doesn't work well. Here > > is where the truly high level language like python or java enters the > > conversation. > > > > My $0.02, in 1934 dollars of course. ;-) > > I agree with Gene on the benefit of knowing a low level language and > having experience with the hardware and top-down analysis. I went to > college in the late 70's and I find my knowledge of those things helps > me tremendously when debugging. I think college isn't as much to teach > you specific things as it is to teach you how to learn (especially in > this industry). I've encountered many kids today who come out of > school, and think java is the only language and they have no design > skills and no knowledge of how the machine actually works. Thanks for the flowers Larry. You just said what I was talking all around, A college education shouldn't teach you specifics about a narrow subject, but should teach you _how_ to learn because it truly is a never ending process that for me, continues to this day as I work on my 80th year here. And you would be amazed at the college diploma possessing people who think they can quit learning when they get the diploma and refuse to learn anything new after that, saying "my hands don't fit the tools". And while you went to college 40+ years ago to learn that, I learned that at the School of Hard Knocks aka the working world in the late 40's on. FWIW, I actually have a diploma from there, got it about 20 years ago. It is part of Alderson-Broddus University & has been for 50+ years. Along with a G.E.D. about that same age since I quit school in 1948 or so to go out and make a living fixing those then brand new things called tv's. I think I did well at the electronics field in general. Getting a raise you didn't ask for many times was the icing on the cake that said I was doing it right, and I was doing it right because I understood the physics that makes it all work, tube type or solid state. Now, back to your regularly scheduled bashing of new bees. ;-) Cheers, Gene -- "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 BOFH excuse #24: network packets travelling uphill (use a carrier pigeon) A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From ethan at stoneleaf.us Tue Dec 10 16:53:36 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 Dec 2013 13:53:36 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <201312091110.25470.gheskett@wdtv.com> References: <201312090824.25211.gheskett@wdtv.com> <201312091110.25470.gheskett@wdtv.com> Message-ID: <52A78D60.2020603@stoneleaf.us> On 12/09/2013 08:10 AM, Gene Heskett wrote: > On Monday 09 December 2013 10:46:42 Larry Martell did opine: >> On Mon, Dec 9, 2013 at 8:24 AM, Gene Heskett wrote: >>> On Monday 09 December 2013 07:51:12 Oscar Benjamin did opine: [weapon of mass snippage] Okay, folks, it's really okay to snip stuff! ;) -- ~Ethan~ From ethan at stoneleaf.us Tue Dec 10 17:02:23 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 Dec 2013 14:02:23 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <201312090824.25211.gheskett@wdtv.com> References: <201312090824.25211.gheskett@wdtv.com> Message-ID: <52A78F6F.3060507@stoneleaf.us> On 12/09/2013 05:24 AM, Gene Heskett wrote: > > I toss out that > > 1. a semester is insufficient to gain a working familiarity with either > python or java. I don't know about java, but it would certainly be enough to get a good start in Python. > 2. If you want to start at the nuts and bolts level, (and you should) Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially if your degree is not in CS. One of the (many) nice things about Python is one doesn't need to know that stuff to Get Things Done. -- ~Ethan~ From jeanpierreda at gmail.com Wed Dec 11 03:34:10 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 11 Dec 2013 00:34:10 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52A78F6F.3060507@stoneleaf.us> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman wrote: > Doesn't sound like they do, as that's causing plenty of problems. In > today's world that level of knowledge isn't always necessary, especially if > your degree is not in CS. One of the (many) nice things about Python is one > doesn't need to know that stuff to Get Things Done. You don't need to know how to use the brakes to drive to Wal-Mart, either. "Get Things Done" is not the one and only goal. It ignores productivity, correctness, ethics... It isn't a bad thing to learn things that are unnecessary to get the bare minimum accomplished. -- Devin From rosuav at gmail.com Wed Dec 11 03:43:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Dec 2013 19:43:52 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Wed, Dec 11, 2013 at 7:34 PM, Devin Jeanpierre wrote: > On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman wrote: >> Doesn't sound like they do, as that's causing plenty of problems. In >> today's world that level of knowledge isn't always necessary, especially if >> your degree is not in CS. One of the (many) nice things about Python is one >> doesn't need to know that stuff to Get Things Done. > > You don't need to know how to use the brakes to drive to Wal-Mart, > either. "Get Things Done" is not the one and only goal. It ignores > productivity, correctness, ethics... It isn't a bad thing to learn > things that are unnecessary to get the bare minimum accomplished. When you tell a story, it's important to engage the reader from the start. Sometimes that means starting the story in the middle of the action, and filling in the important-but-less-exciting details later, when they mean something. [1] Teaching a skill often hits the same sorts of issues. Rather than explain "This is how to manipulate registers in a CPU", explain "This is how to print Hello World to the console" and worry about what exactly the console is (and how redirection affects it) later. My tutorial on assembly language programming did the same, though it used a one-character-output operation so it printed a single asterisk to standard out. (Manually setting CPU register AX to 0200 and DX to 002A, placing an INT 21 command in memory, and single-stepping it.) Learning how all that functions - or even what the INT opcode means - came later. Start with something visible and engaging. After that, learn/teach as much background as is of interest, and improve skills. But start with something that gets something done. [1] http://tvtropes.org/pmwiki/pmwiki.php/Main/InMediasRes ChrisA From oscar.j.benjamin at gmail.com Wed Dec 11 06:46:50 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 11 Dec 2013 11:46:50 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On 11 December 2013 08:43, Chris Angelico wrote: > On Wed, Dec 11, 2013 at 7:34 PM, Devin Jeanpierre > wrote: > > When you tell a story, it's important to engage the reader from the > start. Sometimes that means starting the story in the middle of the > action, and filling in the important-but-less-exciting details later, > when they mean something. [1] Teaching a skill often hits the same > sorts of issues. Rather than explain "This is how to manipulate > registers in a CPU", explain "This is how to print Hello World to the > console" and worry about what exactly the console is (and how > redirection affects it) later. My tutorial on assembly language > programming did the same, though it used a one-character-output > operation so it printed a single asterisk to standard out. (Manually > setting CPU register AX to 0200 and DX to 002A, placing an INT 21 > command in memory, and single-stepping it.) Learning how all that > functions - or even what the INT opcode means - came later. Start with > something visible and engaging. > > After that, learn/teach as much background as is of interest, and > improve skills. But start with something that gets something done. I certainly agree with this for our students. Explicit computing courses make up about 30 credits (~16%) of the whole degree program for the Engineering Mathematics students (if they don't take additional optional units). They are however many units that implicitly require computing skills, so we really need them to be able to be productive quickly. Some of them will focus on programming and get really good at it. Some do go on to become programmers but most do not. The Electrical Engineering students will subsequently do low-level programming with registers etc. but at the earliest stage we just want them to think about how algorithms and programs work before going into all the hardware specific details. While reading around this subject I found this interesting (although verbose) speech from Dijkstra advocating the opposite point of view: http://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html This definitely wouldn't work for my students but a friend of mine studied CS (at Warwick?) and his course worked as Dijkstra describes. In the first year they don't touch a real programming language or write any actual programs. They take exams in pseudocode and formal proofs of correctness. Then after a year of studying algorithms, linguistics, semantics, proof, mathematics and so on they write their first hello world program in a real programming language. I don't really know whether he's any good at programming but he's certainly a good mathematician. Oscar From rosuav at gmail.com Wed Dec 11 07:35:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Dec 2013 23:35:49 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Wed, Dec 11, 2013 at 10:46 PM, Oscar Benjamin wrote: > This definitely wouldn't work for my students but a friend of mine > studied CS (at Warwick?) and his course worked as Dijkstra describes. > In the first year they don't touch a real programming language or > write any actual programs. They take exams in pseudocode and formal > proofs of correctness. Then after a year of studying algorithms, > linguistics, semantics, proof, mathematics and so on they write their > first hello world program in a real programming language. I don't > really know whether he's any good at programming but he's certainly a > good mathematician. Yeah, that's how that sounds. If programming is, to your students, a tool for mathematical analysis (if code is a kind of super-algebra), then it's right to take eams in pseudocode and study algorithms before writing hello world. But if programming is a means of gaining command of a computer, it's far better to see some results of that. Some people like the idea of creating games (usually because they've played so many), so there are courses around that take you from knowing nothing about code to creating your first game (often in one of those systems that lets you build an application without writing code, though, in which case it's not really teaching programming at all). Personally, I'd rather focus on something that's universal[1] (the console and "Hello, world!"), but I do see the appeal of "And by the end of the course, you'll have created a playable game!". Early in my computing days, I met REXX, and a program called REXXTry. It provided a basic Read/Eval/Print loop, though the Print part wasn't very sophisticated (though since REXX didn't have much in the way of complex types, all that meant was that the display of long strings was a bit ugly). I ended up creating an Extended REXXTry, partly by adding a sophisticated input routine courtesy of REXXTT, and then by adding a pile of custom functions - with the goal of making it the ultimate in algebraic handlers. It was, in fact, quite a reasonable tool for playing around with maths; I could sketch a geometric problem on paper, figure out what I knew and what I needed to know, key stuff into EREXXTry, and get a result back. Python could do exactly the same, only way way better (already has support for fractions and complex numbers, which REXX doesn't), and that would make a fine introduction to programming... for someone with a background in algebra. Different styles for different origins. ChrisA [1] Or nearly so. Ironically, many of the systems that don't have a console available are called "consoles". Does that seem right to you? From rustompmody at gmail.com Wed Dec 11 09:44:49 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 11 Dec 2013 06:44:49 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> On Wednesday, December 11, 2013 5:16:50 PM UTC+5:30, Oscar Benjamin wrote: > The Electrical Engineering students will subsequently do low-level > programming with registers etc. but at the earliest stage we just want > them to think about how algorithms and programs work before going into > all the hardware specific details. > While reading around this subject I found this interesting (although > verbose) speech from Dijkstra advocating the opposite point of view: > http://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html > This definitely wouldn't work for my students but a friend of mine > studied CS (at Warwick?) and his course worked as Dijkstra describes. > In the first year they don't touch a real programming language or > write any actual programs. They take exams in pseudocode and formal > proofs of correctness. Then after a year of studying algorithms, > linguistics, semantics, proof, mathematics and so on they write their > first hello world program in a real programming language. I don't > really know whether he's any good at programming but he's certainly a > good mathematician. A government form -- say for filing income tax -- and poetry may both be in English but one doesn't read them with the same attitude! Dijkstra talks in so much hyperbole that one does not take him literally. In particular if you want to take him seriously, you must not take him literally. [I remember reading somewhere that in CS arrogance is measured in nano-dijkstras] I believe there is a truth in the line that Chris and Gene take of getting students' hands dirty early. Equally there is truth in Dijkstra's line that students need the habit of thinking and reflecting before diving in. Now if you believe that one is clearly more important than the other, your way is clear. However what if you want to balance both? Its a challenge... It is this need to balance that makes functional programming attractive: - implemented like any other programming language - but also mathematically rigorous No python is not strictly a functional language but it can be bent to seem that way more than C/C++/Java/what-have-you From rosuav at gmail.com Wed Dec 11 10:24:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 02:24:30 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On Thu, Dec 12, 2013 at 1:44 AM, rusi wrote: > It is this need to balance that makes functional programming attractive: > > - implemented like any other programming language > - but also mathematically rigorous Attractive *to the mathematician*. A more imperative style makes sense to someone who's grown up with... well, parents... clean_room() eat_dinner() One won't start till the other finishes. ChrisA From rustompmody at gmail.com Wed Dec 11 10:41:32 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 11 Dec 2013 07:41:32 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On Wednesday, December 11, 2013 8:54:30 PM UTC+5:30, Chris Angelico wrote: > On Thu, Dec 12, 2013 at 1:44 AM, rusi wrote: > > It is this need to balance that makes functional programming attractive: > > - implemented like any other programming language > > - but also mathematically rigorous > Attractive *to the mathematician*. A more imperative style makes sense > to someone who's grown up with... well, parents... > clean_room() > eat_dinner() > One won't start till the other finishes. Yes its always like that: When you have to figure 2 (or 10) line programs its a no-brainer that the imperative style just works. When the ten becomes ten-thousand, written by a nut who's left you with code whose semantics is dependent on weird dependencies and combinatorial paths through the code you start wishing that - your only dependencies were data dependencies - "Explicit is better than implicit" dinned into the nut's head which BTW are the basic tenets of FP. We have functions in C, in Scheme and in Haskell. The difference is that - in C its impractical and unrealistic to have all functions as (mathematical) functions of the arguments - in Scheme its natural but not enforced - in Haskell its enforced The nice thing about python is that one can (kindof) teach it in the Scheme-like way before showing the C-like side. From breamoreboy at yahoo.co.uk Wed Dec 11 10:53:01 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 11 Dec 2013 15:53:01 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On 11/12/2013 15:41, rusi wrote: > > When the ten becomes ten-thousand, written by a nut who's left you with > code whose semantics is dependent on weird dependencies and combinatorial > paths through the code you start wishing that > ... he'd not been a Led Zeppelin fan, whereby every variable/module/function name was based on a song title/album name/lyric. Thankfully not on my project, it was a mate's. Code ended up in small, round filing cabinet. -- 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 Wed Dec 11 11:04:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 03:04:11 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On Thu, Dec 12, 2013 at 2:41 AM, rusi wrote: > Yes its always like that: > When you have to figure 2 (or 10) line programs its a no-brainer that > the imperative style just works. > > When the ten becomes ten-thousand, written by a nut who's left you with > code whose semantics is dependent on weird dependencies and combinatorial > paths through the code you start wishing that > > - your only dependencies were data dependencies > - "Explicit is better than implicit" dinned into the nut's head > > which BTW are the basic tenets of FP. And since teaching is seldom done with 10KLOC codebases, functional style can be left till later. I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. Start with something easy, then pick up something harder later. ESR in "How to become a hacker" [1] suggests learning "Python, C/C++, Java, Perl, and LISP" [2], and do take note of his reasons _why_. I'm not sure that Perl is so important any more (though a Unix sysadmin should probably have at least a working knowledge of it, given the likelihood of tripping over it at some point), and for LISP you might substitute some other functional language, but broadly, those five recommendations haven't changed in years and years. Knowing multiple styles lets you learn from all of them. Pure functional programming means the result of any function can be determined entirely from its arguments; that doesn't fit into everything, but it sure does make your code easier to understand when you (mostly) stick to it. (For instance, the current logging level might change whether a particular line does something or does nothing, but it still fundamentally has the same meaning, and it won't change state magically anywhere else.) And there's a lot of "similarity of thinking" between a well-written program in one style and a well-written program in another style, regardless of which two styles they are. ChrisA [1] http://www.catb.org/esr/faqs/hacker-howto.html [2] http://www.catb.org/esr/faqs/hacker-howto.html#skills1 From breamoreboy at yahoo.co.uk Wed Dec 11 11:18:08 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 11 Dec 2013 16:18:08 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On 11/12/2013 16:04, Chris Angelico wrote: > I strongly believe that a career > programmer should learn as many languages and styles as possible, but > most of them can wait. I chuckle every time I read this one. Five years per language, ten languages, that's 50 years I think. Or do I rewrite my diary for next week, so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia Tuesday morning ... -- 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 Wed Dec 11 11:25:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 03:25:57 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence wrote: > On 11/12/2013 16:04, Chris Angelico wrote: >> >> I strongly believe that a career >> programmer should learn as many languages and styles as possible, but >> most of them can wait. > > > I chuckle every time I read this one. Five years per language, ten > languages, that's 50 years I think. Or do I rewrite my diary for next week, > so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia Tuesday > morning ... Well, I went exploring the Wikipedia list of languages [1] one day, and found I had at least broad familiarity with about one in five. I'd like to get that up to one in four, if only because four's a power of two. More seriously: Once you've learned five of very different styles, it won't take you five years to learn a sixth language. I picked up Pike in about a weekend by realizing that it was "Python semantics meets C syntax", and then went on to spend the next few years getting to know its own idioms. I'd say anyone who knows a dozen languages should be able to pick up any non-esoteric language in a weekend, at least to a level of broad familiarity of being able to read and comprehend code and make moderate changes to it. [1] https://en.wikipedia.org/wiki/List_of_programming_languages ChrisA From timothy.c.delaney at gmail.com Wed Dec 11 15:13:05 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 12 Dec 2013 07:13:05 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On 12 December 2013 03:25, Chris Angelico wrote: > On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence > wrote: > > On 11/12/2013 16:04, Chris Angelico wrote: > >> > >> I strongly believe that a career > >> programmer should learn as many languages and styles as possible, but > >> most of them can wait. > > > > > > I chuckle every time I read this one. Five years per language, ten > > languages, that's 50 years I think. Or do I rewrite my diary for next > week, > > so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia Tuesday > > morning ... > > Well, I went exploring the Wikipedia list of languages [1] one day, > and found I had at least broad familiarity with about one in five. I'd > like to get that up to one in four, if only because four's a power of > two. > > More seriously: Once you've learned five of very different styles, it > won't take you five years to learn a sixth language. I picked up Pike > in about a weekend by realizing that it was "Python semantics meets C > syntax", and then went on to spend the next few years getting to know > its own idioms. I'd say anyone who knows a dozen languages should be > able to pick up any non-esoteric language in a weekend, at least to a > level of broad familiarity of being able to read and comprehend code > and make moderate changes to it. > Absolutely. 10 years ago I was saying I'd forgotten at least 20 languages, and there have been many more since. Once you know enough programming languages you (and by "you" I mean "me") get to the point where if you don't know a specific language you can pick up enough to be useful in a day or two, reasonably proficient in a week, and have a fairly high level of mastery by the time you've finished whatever project you picked it up for. And then you don't use it for a while, forget it to make room for something else, and pick it up again when you need it (much faster this time). Except Prolog. Never could get my head around it - I should go back and have another try one of these days. Some languages stick with you (e.g. Python) and I don't tend to learn languages that are too similar to what I already know unless it's for a specific project. So I've never learned Ruby ... but I have had to modify a few Ruby scripts along the way, and been able to achieve what I wanted the same day. TimD elaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Wed Dec 11 20:50:53 2013 From: roy at panix.com (Roy Smith) Date: Wed, 11 Dec 2013 20:50:53 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: In article , Mark Lawrence wrote: > On 11/12/2013 16:04, Chris Angelico wrote: > > I strongly believe that a career > > programmer should learn as many languages and styles as possible, but > > most of them can wait. > > I chuckle every time I read this one. Five years per language, ten > languages, that's 50 years I think. Or do I rewrite my diary for next > week, so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia > Tuesday morning ... Not counting little side explorations, I have used in anger (and in vaguely chronological order): Basic Fortran C Various assemblers (pdp-10, pdp-11, IBM-1130, M6800) Common Lisp Postscript Python TCL Perl Java C++ Javascript From rhodri at wildebst.org.uk Thu Dec 12 18:50:45 2013 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 12 Dec 2013 23:50:45 -0000 Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <05fc5a48-576d-4eb9-a714-96df39f0ef1f@googlegroups.com> Message-ID: On Wed, 11 Dec 2013 16:18:08 -0000, Mark Lawrence wrote: > On 11/12/2013 16:04, Chris Angelico wrote: >> I strongly believe that a career >> programmer should learn as many languages and styles as possible, but >> most of them can wait. > > I chuckle every time I read this one. Five years per language, ten > languages, that's 50 years I think. Or do I rewrite my diary for next > week, so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia > Tuesday morning ... Welcome to Computer Science lectures :-) -- Rhodri James *-* Wildebeest Herder to the Masses From bgailer at gmail.com Wed Dec 11 11:01:42 2013 From: bgailer at gmail.com (bob gailer) Date: Wed, 11 Dec 2013 11:01:42 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <52A88C66.8050103@gmail.com> On 12/11/2013 3:43 AM, Chris Angelico wrote: > When you tell a story, it's important to engage the reader from the > start...explain "This is how to print Hello World to the > console" and worry about what exactly the console is (and how > redirection affects it) Highly agree. I was once given FORTRAN course materials and an assignment to teach this course. The first morning was spent on how to construct expressions! No context as to what a program was or what it might do or how to run it. As soon as that class was over I rewrote the materials so the first morning was how to write and run(batch job submission) a program that read a record, did a simple calculation and wrote the results. I certainly felt better about teaching this way. Asides: One student (PhD in Physics) looked at X = X + 1 and said "no it doesn't". Another wrote his first program. I took one look at it and saw the mistakes. I explained how to walk thru the program step by step. He exclaimed "In that much detail?". From breamoreboy at yahoo.co.uk Wed Dec 11 11:11:59 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 11 Dec 2013 16:11:59 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52A88C66.8050103@gmail.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <52A88C66.8050103@gmail.com> Message-ID: On 11/12/2013 16:01, bob gailer wrote: > > One student (PhD in Physics) looked at X = X + 1 and said "no it doesn't". > Someone I worked with used x := x - x - x to invert a number. -- 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 Wed Dec 11 11:14:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 03:14:12 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52A88C66.8050103@gmail.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <52A88C66.8050103@gmail.com> Message-ID: On Thu, Dec 12, 2013 at 3:01 AM, bob gailer wrote: > One student (PhD in Physics) looked at X = X + 1 and said "no it doesn't". Yeah, which is why some languages (I first met it with Pascal) spell that as "X *becomes* X + 1"... but regardless of what you call it, there's a fundamental difference between algebra (where every line is a statement of truth) and imperative programming (which may change state as time progresses). What's called a "variable" in programming really can vary; in maths, it's really just an "unknown". This is a difference that, one way or another, just has to be taught. > Another wrote his first program. I took one look at it and saw the mistakes. > I explained how to walk thru the program step by step. He exclaimed "In that > much detail?". You mean a dry run [1]? Yes, can be tedious. Can also be very VERY valuable, especially if done verbally to another programmer, as a means of spotting differences between what the programmer thinks something does and what the language thinks it does. x = a * b + c "Set x to a times the sum of b and c." ChrisA [1] http://foldoc.org/dry+run From rustompmody at gmail.com Wed Dec 11 11:27:23 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 11 Dec 2013 08:27:23 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Wednesday, December 11, 2013 9:31:42 PM UTC+5:30, bob gailer wrote: > On 12/11/2013 3:43 AM, Chris Angelico wrote: > > When you tell a story, it's important to engage the reader from the > > start...explain "This is how to print Hello World to the > > console" and worry about what exactly the console is (and how > > redirection affects it) > Highly agree. I was once given FORTRAN course materials and an > assignment to teach this course. The first morning was spent on how to > construct expressions! No context as to what a program was or what it > might do or how to run it. > As soon as that class was over I rewrote the materials so the first > morning was how to write and run(batch job submission) a program that > read a record, did a simple calculation and wrote the results. Kernighan and Ritchie set an important "first" in our field by making "Hello World" their first program. People tend to under-estimate the importance of this: Many assumptions need to be verified/truthified/dovetailed starting from switching on the machine onwards for this to work. And its quite a pleasurable sense of achievement when it finally holds together -- something which is sorely missing in the Dijkstra approach. However when we have an REPL language like python, one has the choice of teaching the hello-world program as: print ("Hello World") or just "Hello World" The second needs one more assumption than the first, viz that we are in the REPL, however on the whole it creates better habits in the kids. [BTW: From the theoretical POV, imperative programming is 'unclean' because of assignment statements. From the practical POV of a teacher, the imperativeness of print is a bigger nuisance in students' thinking patterns ] > I certainly felt better about teaching this way. > Asides: > One student (PhD in Physics) looked at X = X + 1 and said "no it doesn't". Yes thats one issue in most modern imperative languages that the older generation (Pascal-family) did not have, viz that assignment looks like equality. > Another wrote his first program. I took one look at it and saw the > mistakes. I explained how to walk thru the program step by step. He > exclaimed "In that much detail?". From steve+comp.lang.python at pearwood.info Wed Dec 11 11:36:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Dec 2013 16:36:04 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <52a89474$0$29992$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Dec 2013 08:27:23 -0800, rusi wrote: > [BTW: From the theoretical POV, imperative programming is 'unclean' > because of assignment statements. From the practical POV of a teacher, > the imperativeness of print is a bigger nuisance in students' thinking > patterns ] +1 on this Trying to teach newbies to use return rather than print in their functions is one of the more difficult parts of teaching beginners. -- Steven From rosuav at gmail.com Wed Dec 11 11:45:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 03:45:51 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Thu, Dec 12, 2013 at 3:27 AM, rusi wrote: > However when we have an REPL language like python, one has the choice > of teaching the hello-world program as: > > print ("Hello World") > > or just > > "Hello World" > > The second needs one more assumption than the first, viz that we are in the > REPL, however on the whole it creates better habits in the kids. How is the bare string creating better habits? The only time I've ever been happy with bare strings having functionality[1] is in shell-like languages (including REXX; the one time I built a REXX system in which bare strings weren't executed as commands was a MUD, where command handlers could use bare strings to send lines of text to the client, and I wasn't happy with that - an explicit function would have been better). I'd much rather teach a function that produces clean output than depend on the REPL for Hello World. Now, depending on the REPL for *expressions* is quite another thing. >>> 1+2 3 That makes perfect sense! But it's using Python as a calculator, not as a programming language. Python blurs the line a bit, but for teaching programming, I'd use programming style even at the REPL: >>> print("Hello, world!") Hello, world! ChrisA [1] I don't have anything to footnote here, I just felt like having one. From roy at panix.com Wed Dec 11 20:42:32 2013 From: roy at panix.com (Roy Smith) Date: Wed, 11 Dec 2013 20:42:32 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: In article , rusi wrote: > Kernighan and Ritchie set an important "first" in our field by making > "Hello World" their first program. Yup. > People tend to under-estimate the importance of this: > Many assumptions need to be verified/truthified/dovetailed > starting from switching on the machine onwards for this to work. At the time that they wrote it, very few people who used computers ever got anywhere near the power switch :-) But, the point is valid. To get "Hello, world" to print, you've got to figure out a lot of stuff. Predating the whole agile movement by two decades, it is the quintessential MVP. It compiles and runs. The rest is just adding features and fixing bugs. From larry.martell at gmail.com Wed Dec 11 21:07:31 2013 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 11 Dec 2013 21:07:31 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > In article , > rusi wrote: > >> Kernighan and Ritchie set an important "first" in our field by making >> "Hello World" their first program. > > Yup. > >> People tend to under-estimate the importance of this: >> Many assumptions need to be verified/truthified/dovetailed >> starting from switching on the machine onwards for this to work. > > At the time that they wrote it, very few people who used computers ever > got anywhere near the power switch :-) Nope. Long before that I was working on computers that didn't boot when you powered them up, You had to manually key in a bootstrap program from the front panel switches. (And no, this is not a takeoff of the Four Yorkshiremen sketch.) From ben+python at benfinney.id.au Wed Dec 11 21:21:38 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Dec 2013 13:21:38 +1100 Subject: The increasing disempowerment of the computer user (was: Experiences/guidance on teaching Python as a first programming language) References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <7wbo0mlsgd.fsf_-_@benfinney.id.au> Larry Martell writes: > On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > > rusi wrote: > > > >> Many assumptions need to be verified/truthified/dovetailed > >> starting from switching on the machine onwards for this to work. > > > > At the time that [Kerningham & Ritchie] wrote [the C programming > > language], very few people who used computers ever got anywhere near > > the power switch :-) > > Nope. Long before that I was working on computers that didn't boot > when you powered them up, You had to manually key in a bootstrap > program from the front panel switches. That's done by the *operator*, not the user. Most people who *used* those computers worked at terminals at a distance, and usually separated by a locked door, from the computer's power switch. > (And no, this is not a takeoff of the Four Yorkshiremen sketch.) The pendulum swings back and forth. Computer users are once again blithely handing all their agency and choice back to centralised operators (so-called ?could computing?) who follow an agenda not of those users's choosing. Just as in the bad old days of 1960s centralised computing, complete with computer operators who dismiss the needs of their users. And who hold unquestionable authority to dictate how the computers may be used, regardless what the users want to do. Only, now we get worldwide unaccountable surveillance as part of the deal. But you tell the users of today about that, and they don't believe you. -- \ ?If nature has made any one thing less susceptible than all | `\ others of exclusive property, it is the action of the thinking | _o__) power called an idea? ?Thomas Jefferson | Ben Finney From breamoreboy at yahoo.co.uk Wed Dec 11 21:35:19 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 12 Dec 2013 02:35:19 +0000 Subject: The increasing disempowerment of the computer user In-Reply-To: <7wbo0mlsgd.fsf_-_@benfinney.id.au> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <7wbo0mlsgd.fsf_-_@benfinney.id.au> Message-ID: On 12/12/2013 02:21, Ben Finney wrote: > Only, now we get worldwide unaccountable surveillance as part of the deal. > Whereas the 1920 UK Official Secrets Act required all international cable companies operating on British terrority to submit copies of all their traffic (both dispatched and received) within ten days of transmission. Now there's accountability for you. -- 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 Wed Dec 11 21:35:37 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Dec 2013 13:35:37 +1100 Subject: The increasing disempowerment of the computer user References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <7wbo0mlsgd.fsf_-_@benfinney.id.au> Message-ID: <7w7gbalrt2.fsf@benfinney.id.au> Ben Finney writes: > Larry Martell writes: > > > On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > > > rusi wrote: > > > > > >> Many assumptions need to be verified/truthified/dovetailed > > >> starting from switching on the machine onwards for this to work. > > > > > > At the time that [Kerningham & Ritchie] wrote [the C programming > > > language], very few people who used computers ever got anywhere near > > > the power switch :-) > > > > Nope. Long before that I was working on computers that didn't boot > > when you powered them up, You had to manually key in a bootstrap > > program from the front panel switches. > > That's done by the *operator*, not the user. Most people who *used* > those computers worked at terminals at a distance, and usually separated > by a locked door, from the computer's power switch. > > > (And no, this is not a takeoff of the Four Yorkshiremen sketch.) > > The pendulum swings back and forth. Computer users are once again > blithely handing all their agency and choice back to centralised > operators (so-called ?could computing?) who follow an agenda not of > those users's choosing. Hmm, interesting Freudian slip there. I meant ?cloud computing?, of course. That's where the computer owner pretends their service is always available and easy to access, while having terms of service that give them unilateral power to kick you off with no warning, no explanation, no accountability, and no recourse. -- \ ?All television is educational television. The question is: | `\ what is it teaching?? ?Nicholas Johnson | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Thu Dec 12 05:59:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Dec 2013 10:59:58 GMT Subject: The increasing disempowerment of the computer user References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <7wbo0mlsgd.fsf_-_@benfinney.id.au> Message-ID: <52a9972d$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 Dec 2013 13:35:37 +1100, Ben Finney wrote: > Hmm, interesting Freudian slip there. I meant ?cloud computing?, of > course. That's where the computer owner pretends their service is always > available and easy to access, while having terms of service that give > them unilateral power to kick you off with no warning, no explanation, > no accountability, and no recourse. Now Ben, you know that's not true. Everybody has the only recourse that matters: buy the company and make them do what you want them to do. How hard could that possibly be? -- Steven From dwightdhutto at gmail.com Sat Dec 14 00:44:53 2013 From: dwightdhutto at gmail.com (David Hutto) Date: Sat, 14 Dec 2013 00:44:53 -0500 Subject: The increasing disempowerment of the computer user In-Reply-To: <52a9972d$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <7wbo0mlsgd.fsf_-_@benfinney.id.au> <52a9972d$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: Three word response...Conglomerate business intelligence. On Thu, Dec 12, 2013 at 5:59 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Thu, 12 Dec 2013 13:35:37 +1100, Ben Finney wrote: > > > Hmm, interesting Freudian slip there. I meant ?cloud computing?, of > > course. That's where the computer owner pretends their service is always > > available and easy to access, while having terms of service that give > > them unilateral power to kick you off with no warning, no explanation, > > no accountability, and no recourse. > > Now Ben, you know that's not true. Everybody has the only recourse that > matters: buy the company and make them do what you want them to do. How > hard could that possibly be? > > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From bgailer at gmail.com Thu Dec 12 11:51:28 2013 From: bgailer at gmail.com (bob gailer) Date: Thu, 12 Dec 2013 11:51:28 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <52A9E990.9070002@gmail.com> On 12/11/2013 9:07 PM, Larry Martell wrote: > Nope. Long before that I was working on computers that didn't boot > when you powered them up, You had to manually key in a bootstrap > program from the front panel switches. PDP8? RIM loader, BIN loader? From larry.martell at gmail.com Thu Dec 12 16:18:22 2013 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 12 Dec 2013 16:18:22 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52A9E990.9070002@gmail.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <52A9E990.9070002@gmail.com> Message-ID: On Thu, Dec 12, 2013 at 11:51 AM, bob gailer wrote: > On 12/11/2013 9:07 PM, Larry Martell wrote: > >> Nope. Long before that I was working on computers that didn't boot when >> you powered them up, You had to manually key in a bootstrap program from the >> front panel switches. > > PDP8? RIM loader, BIN loader? Data General Nova 3 From fpm at u.washington.edu Fri Dec 13 11:21:16 2013 From: fpm at u.washington.edu (Frank Miles) Date: Fri, 13 Dec 2013 16:21:16 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <52A9E990.9070002@gmail.com> Message-ID: On Thu, 12 Dec 2013 16:18:22 -0500, Larry Martell wrote: > On Thu, Dec 12, 2013 at 11:51 AM, bob gailer wrote: >> On 12/11/2013 9:07 PM, Larry Martell wrote: >> >>> Nope. Long before that I was working on computers that didn't boot when >>> you powered them up, You had to manually key in a bootstrap program from the >>> front panel switches. >> >> PDP8? RIM loader, BIN loader? > > Data General Nova 3 IIRC - wasn't that a machine that didn't even have 'subtract' - you had to complement and add (2 steps) ? From roy at panix.com Wed Dec 11 21:31:51 2013 From: roy at panix.com (Roy Smith) Date: Wed, 11 Dec 2013 21:31:51 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: In article , Larry Martell wrote: > On Wed, Dec 11, 2013 at 8:42 PM, Roy Smith wrote: > > In article , > > rusi wrote: > > > >> Kernighan and Ritchie set an important "first" in our field by making > >> "Hello World" their first program. > > > > Yup. > > > >> People tend to under-estimate the importance of this: > >> Many assumptions need to be verified/truthified/dovetailed > >> starting from switching on the machine onwards for this to work. > > > > At the time that they wrote it, very few people who used computers ever > > got anywhere near the power switch :-) > > Nope. Long before that I was working on computers that didn't boot > when you powered them up, You had to manually key in a bootstrap > program from the front panel switches. Or put a boot card in the reader and hit the IPL button :-) From rustompmody at gmail.com Wed Dec 11 22:52:02 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 11 Dec 2013 19:52:02 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Thursday, December 12, 2013 7:12:32 AM UTC+5:30, Roy Smith wrote: > rusi wrote: > > Kernighan and Ritchie set an important "first" in our field by making > > "Hello World" their first program. > Yup. > > People tend to under-estimate the importance of this: > > Many assumptions need to be verified/truthified/dovetailed > > starting from switching on the machine onwards for this to work. > At the time that they wrote it, very few people who used computers ever > got anywhere near the power switch :-) But, the point is valid. To get > "Hello, world" to print, you've got to figure out a lot of stuff. > Predating the whole agile movement by two decades, it is the > quintessential MVP. It compiles and runs. The rest is just adding > features and fixing bugs. Which comes back full-circle to where we started: if main() { printf("Hello World\n"); } is the foundation on which other programs are built, then later excising the print(f) is a significant headache -- at least for teachers as Steven also seems to have found. If instead the print was presented more as a 'debug' -- when something goes wrong stick a probe in there and figure the problem -- then leaving it there would be as unacceptable as a car mechanic giving you your keys with the hood open and parts lying around. Anecdote about the great mathematician Gauss: He was asked why his writings were so devoid of motivations/explanations. He answered: Do you leave the scaffolding after the building is built? From rosuav at gmail.com Wed Dec 11 23:20:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 15:20:47 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Thu, Dec 12, 2013 at 2:52 PM, rusi wrote: > Which comes back full-circle to where we started: if > > main() { printf("Hello World\n"); } > > is the foundation on which other programs are built, then later excising > the print(f) is a significant headache -- at least for teachers as Steven > also seems to have found. > > If instead the print was presented more as a 'debug' -- when something > goes wrong stick a probe in there and figure the problem -- then > leaving it there would be as unacceptable as a car mechanic giving you > your keys with the hood open and parts lying around. Console output isn't just a debug feature, though - and if you're using it as such, you possibly should be using the logging module instead. It's the most fundamental form of output. It plays nicely with shell redirection and long pipelines, which means it automatically lets you work with something larger than memory or even disk. Imagine starting a pipeline with a decompression step (eg gzip -d), and ending it with a tight filter (eg grep) - everything in between could manipulate any amount of data at all, without caring about storage space. Console output works in the REPL, works in the default interpreter (other than pythonw.exe which suppresses it), works across SSH... if your most normal form of output is a GUI, that's not always true. Console output works without requiring any other program, too, unlike (for instance) a CGI script, which needs a web browser to interpret its output. There's a reason many languages bless it with a keyword. ChrisA From wxjmfauth at gmail.com Wed Dec 11 04:39:15 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 11 Dec 2013 01:39:15 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: A few practical considerations, far away from theoretical aspects. Mainly for non ascii, understand non native English speakers. Python is an "ascii oriented product". Platform. On Windows, the solely version which works harmoniously with the system is Py 2.7 in a byte string mode (ie non unicode). Unicode. Sorry, but Python just becomes a no-go. The great strength is(are) the Python interactive interpreter(s). It makes learning this language a game. jmf (Not teaching computer stuff, but regulary confrontated with students and/or potential users). From breamoreboy at yahoo.co.uk Wed Dec 11 05:05:13 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 11 Dec 2013 10:05:13 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On 11/12/2013 09:39, wxjmfauth at gmail.com wrote: > A few practical considerations, far away from theoretical > aspects. Mainly for non ascii, understand non native English > speakers. > > Python is an "ascii oriented product". Sheer unadulterated rubbish. > > Platform. On Windows, the solely version which works > harmoniously with the system is Py 2.7 in a byte string > mode (ie non unicode). Fixed in Python 3, especially with the superb work done on PEP 393 and the FSR. > > Unicode. Sorry, but Python just becomes a no-go. Yawn. > > The great strength is(are) the Python interactive > interpreter(s). It makes learning this language a game. > Blimey, got something correct, miracles do happen. -- 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 Wed Dec 11 05:45:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Dec 2013 21:45:43 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Wed, Dec 11, 2013 at 7:43 PM, Chris Angelico wrote: > When you tell a story, it's important to engage the reader from the > start. On Wed, Dec 11, 2013 at 8:39 PM, wrote: > A few practical considerations, far away from theoretical > aspects. Mainly for non ascii, understand non native English > speakers. And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in our role-play storytelling scenario! A round of applause for jmf, folks, for doing a brilliant impression of the uninformed-yet-fanatical Knight Templar villain! ChrisA From square.steve at gmail.com Wed Dec 11 06:33:49 2013 From: square.steve at gmail.com (Steve Simmons) Date: Wed, 11 Dec 2013 12:33:49 +0100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <52A84D9D.9030608@gmail.com> On 11/12/2013 11:45, Chris Angelico wrote: > And then, shortly after the beginning of the story, you need to > introduce the villain. Thanks, jmf, for taking that position in our > role-play storytelling scenario! A round of applause for jmf, folks, > for doing a brilliant impression of the uninformed-yet-fanatical > Knight Templar villain! > > ChrisA Oi! You!! I'll have you know I'm a bona fide Knight of the Temple and we're not (all) villains! If I catch you calling us villains again, I'll slide up behind you in the mud and dig you with my ceremonial sword! ;-) SteveS From rosuav at gmail.com Wed Dec 11 07:02:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Dec 2013 23:02:22 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52A84D9D.9030608@gmail.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <52A84D9D.9030608@gmail.com> Message-ID: On Wed, Dec 11, 2013 at 10:33 PM, Steve Simmons wrote: > > On 11/12/2013 11:45, Chris Angelico wrote: >> >> And then, shortly after the beginning of the story, you need to >> introduce the villain. Thanks, jmf, for taking that position in our >> role-play storytelling scenario! A round of applause for jmf, folks, >> for doing a brilliant impression of the uninformed-yet-fanatical >> Knight Templar villain! >> >> ChrisA > > > Oi! You!! > > I'll have you know I'm a bona fide Knight of the Temple and we're not (all) > villains! > If I catch you calling us villains again, I'll slide up behind you in the > mud and dig you > with my ceremonial sword! ;-) Mister Simmons, Mister Simmons! We are not for one moment doubting your sincerity. It's just your intelligence that's in question. [1] [1] http://www.thegoonshow.net/scripts_show.asp?title=s06e19_the_jet_propelled_guided_naafi ChrisA Attempting to atone for pointing people to TVTropes... or maybe to be hung for a sheep rather than a lamb.... From square.steve at gmail.com Wed Dec 11 07:30:45 2013 From: square.steve at gmail.com (Steve Simmons) Date: Wed, 11 Dec 2013 13:30:45 +0100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <52A84D9D.9030608@gmail.com> Message-ID: <52A85AF5.6000507@gmail.com> On 11/12/2013 13:02, Chris Angelico wrote: > On Wed, Dec 11, 2013 at 10:33 PM, Steve Simmons wrote: >> On 11/12/2013 11:45, Chris Angelico wrote: >>> And then, shortly after the beginning of the story, you need to >>> introduce the villain. Thanks, jmf, for taking that position in our >>> role-play storytelling scenario! A round of applause for jmf, folks, >>> for doing a brilliant impression of the uninformed-yet-fanatical >>> Knight Templar villain! >>> >>> ChrisA >> >> Oi! You!! >> >> I'll have you know I'm a bona fide Knight of the Temple and we're not (all) >> villains! >> If I catch you calling us villains again, I'll slide up behind you in the >> mud and dig you >> with my ceremonial sword! ;-) > Mister Simmons, Mister Simmons! We are not for one moment doubting > your sincerity. It's just your intelligence that's in question. [1] > > [1] http://www.thegoonshow.net/scripts_show.asp?title=s06e19_the_jet_propelled_guided_naafi > > ChrisA > Attempting to atone for pointing people to TVTropes... or maybe to be > hung for a sheep rather than a lamb.... OK, We'll call it a draw. [2 - or is that 1?] SteveS [2 - or is that 3? Three shall be the number...] http://montypython.50webs.com/scripts/Holy_Grail/Scene4.htm From wuwei23 at gmail.com Thu Dec 12 00:38:08 2013 From: wuwei23 at gmail.com (alex23) Date: Thu, 12 Dec 2013 15:38:08 +1000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On 11/12/2013 8:45 PM, Chris Angelico wrote: > A round of applause for jmf, folks, > for doing a brilliant impression of the uninformed-yet-fanatical > Knight Templar villain! Jacques de Molay, thou are avenged! From wxjmfauth at gmail.com Thu Dec 12 04:17:27 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 12 Dec 2013 01:17:27 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: Le mercredi 11 d?cembre 2013 11:45:43 UTC+1, Chris Angelico a ?crit?: > On Wed, Dec 11, 2013 at 7:43 PM, Chris Angelico wrote: > > > When you tell a story, it's important to engage the reader from the > > > start. > > > > On Wed, Dec 11, 2013 at 8:39 PM, wrote: > > > A few practical considerations, far away from theoretical > > > aspects. Mainly for non ascii, understand non native English > > > speakers. > > > > And then, shortly after the beginning of the story, you need to > > introduce the villain. Thanks, jmf, for taking that position in our > > role-play storytelling scenario! A round of applause for jmf, folks, > > for doing a brilliant impression of the uninformed-yet-fanatical > > Knight Templar villain! > I know Python since ver. 1.5.6 and used it intensively since ver. 2.0 or 2.1 (?). I acquired some user experience. Windows, Py2.(7), ascii. It is not a secret Python uses ascii for the representation. As an example, this guy who some time ago exposed his own solution to solve that problem (btw, elegant and correct). --- you wrote blah, blah about his "mysterious code point", you did not recognize he is (was) using Turkish Windows with the code page cp1254 ---. It is a little bit fascinating, 20 years after the creation a language, people are still fighting to write text in a human way. Unicode. For a first language, it may be not a bad idea to use a language which uses "unicode ? la unicode". Windows, Py3, unicode. It is is infortunate, but it is a fact Python has some problems with that platform (file sytem encoding), -> potential problems which should not exist for a beginner. I am the first to recognize the win console is all but friendly. If one wishes to use a unicode code page, Python fails [*]. Python has plenty of good qualities, you (and others) are discussing plenty of theoretical aspects. I'm pointing the fact, one may be stuck simply because one cannot display a piece of of text! I'm not so sure, such a behaviour is expected from a beginner learning a computer language. [*] I toyed with go(lang) and ruby 2 (only in a unicode perspective), I should say I had no problems. Why? No idea, it is too far beyond my knowlege. jmf From rosuav at gmail.com Thu Dec 12 05:28:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 21:28:35 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Thu, Dec 12, 2013 at 8:17 PM, wrote: > Windows, Py2.(7), ascii. It is not a secret Python uses > ascii for the representation. Actually no, it doesn't. Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32 >>> s = "abcd\xa9" >>> print(s) abcd? The copyright symbol is not in ASCII. Are you suggesting that Python uses a 7-bit internal representation of this data? Because a quick squiz at the source code will prove that wrong. This is not ASCII. ChrisA From ned at nedbatchelder.com Thu Dec 12 08:52:21 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 12 Dec 2013 08:52:21 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On 12/12/13 4:17 AM, wxjmfauth at gmail.com wrote: > Le mercredi 11 d?cembre 2013 11:45:43 UTC+1, Chris Angelico a ?crit : >> On Wed, Dec 11, 2013 at 7:43 PM, Chris Angelico wrote: >> >>> When you tell a story, it's important to engage the reader from the >> >>> start. >> >> >> >> On Wed, Dec 11, 2013 at 8:39 PM, wrote: >> >>> A few practical considerations, far away from theoretical >> >>> aspects. Mainly for non ascii, understand non native English >> >>> speakers. >> >> >> >> And then, shortly after the beginning of the story, you need to >> >> introduce the villain. Thanks, jmf, for taking that position in our >> >> role-play storytelling scenario! A round of applause for jmf, folks, >> >> for doing a brilliant impression of the uninformed-yet-fanatical >> >> Knight Templar villain! >> > > I know Python since ver. 1.5.6 and used it intensively > since ver. 2.0 or 2.1 (?). I acquired some user experience. > > Windows, Py2.(7), ascii. It is not a secret Python uses > ascii for the representation. It is incorrect that Py2.x uses ASCII strings. It uses byte strings. Source files are assumed to be encoded in ASCII, so byte strings often are ASCII. But as Chris has pointed out, bytestrings can hold any byte data, including UTF-8 if you wish. JMF, I think you are clever enough and care enough about these issues to get this straight. Many people seem to like the Pragmatic Unicode presentation I did, it may clear up some issues: http://nedbatchelder.com/text/unipain.html I'd be glad to have an extended conversation with you offline if you don't want to get into details here. > As an example, this guy > who some time ago exposed his own solution to solve that > problem (btw, elegant and correct). --- you wrote blah, blah > about his "mysterious code point", you did not recognize > he is (was) using Turkish Windows with the code > page cp1254 ---. It is a little bit fascinating, 20 years > after the creation a language, people are still fighting > to write text in a human way. "This guy": I have no idea who you are talking about. > > Unicode. For a first language, it may be not a bad idea > to use a language which uses "unicode ? la unicode". > > Windows, Py3, unicode. It is is infortunate, but it is > a fact Python has some problems with that platform (file > sytem encoding), -> potential problems which should not > exist for a beginner. File system encodings are very difficult. Linux uses byte strings for file names, with no attempt to record the encoding, so there's a strong possibility that the declared encoding for the filesystem is wrong, or that your guess at the encoding will be wrong. > I am the first to recognize the win console is all but > friendly. If one wishes to use a unicode code page, Python > fails [*]. Yes, the Windows console and Python don't get along well with Unicode. This is a long-standing ticket: http://bugs.python.org/issue1602 I'm sure they would welcome your contribution towards a solution. When I use Windows, I often wish this were solved. > > Python has plenty of good qualities, you (and others) > are discussing plenty of theoretical aspects. > I'm pointing the fact, one may be stuck simply because > one cannot display a piece of of text! > I'm not so sure, such a behaviour is expected from a > beginner learning a computer language. > > > [*] I toyed with go(lang) and ruby 2 (only in a unicode > perspective), I should say I had no problems. Why? No > idea, it is too far beyond my knowlege. > > jmf > > -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Thu Dec 12 09:30:24 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 12 Dec 2013 14:30:24 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On 12/12/2013 13:52, Ned Batchelder wrote: > > I'd be glad to have an extended conversation with you offline if you > don't want to get into details here. Would you please to kind enough to keep it online, I enjoy a good comedian and our erstwhile unicode expert is one of the best, if not the best, in this field. If you do take it offline would you please ask him to stop sending via google groups, or to take appropriate action to stop the extremely annoying double spacing. > Yes, the Windows console and Python don't get along well with Unicode. > This is a long-standing ticket: http://bugs.python.org/issue1602 I'm > sure they would welcome your contribution towards a solution. When I > use Windows, I often wish this were solved. > There's also http://bugs.python.org/issue14170 and http://bugs.python.org/issue15809 amongst others. Contributing towards a solution is a simple thing to do. Finding a solution isn't as simple see e.g. http://www.gossamer-threads.com/lists/python/dev/731701 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From wxjmfauth at gmail.com Thu Dec 12 09:34:40 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 12 Dec 2013 06:34:40 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: Le jeudi 12 d?cembre 2013 11:28:35 UTC+1, Chris Angelico a ?crit?: > On Thu, Dec 12, 2013 at 8:17 PM, wrote: > > > Windows, Py2.(7), ascii. It is not a secret Python uses > > > ascii for the representation. > > > > Actually no, it doesn't. > > > > Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit > > (Intel)] on win32 > > >>> s = "abcd\xa9" > > >>> print(s) > > abcd? > > > > The copyright symbol is not in ASCII. Are you suggesting that Python > > uses a 7-bit internal representation of this data? Because a quick > > squiz at the source code will prove that wrong. This is not ASCII. > > >>> sys.version '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>> sys.stdout.encoding 'cp1252' >>> s = 'abc\xa9' >>> t = 'abc?' >>> s 'abc\xa9' >>> t 'abc\xa9' >>> print s, t, (s, t) abc? abc? ('abc\xa9', 'abc\xa9') >>> def HumanStr(o): t = repr(o) newt = t.replace('\\xa9', '?') return newt >>> print s, t, (s, t), HumanStr((s, t)) abc? abc? ('abc\xa9', 'abc\xa9') ('abc?', 'abc?') >>> jmf PS I do not insist on "sys.displayhook" PS2 I can only congratulate this Turkish guy for his understanding of Python From rosuav at gmail.com Thu Dec 12 09:47:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Dec 2013 01:47:40 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On Fri, Dec 13, 2013 at 1:34 AM, wrote: > Le jeudi 12 d?cembre 2013 11:28:35 UTC+1, Chris Angelico a ?crit : >> On Thu, Dec 12, 2013 at 8:17 PM, wrote: >> >> > Windows, Py2.(7), ascii. It is not a secret Python uses >> > ascii for the representation. >> >> Actually no, it doesn't. > >>>> sys.version > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>>> sys.stdout.encoding > 'cp1252' What has this to do with ASCII or with Python's internal representation? All you've proven is that you can convert the repr of a string back into a byte-string, by replacing "\\xa9" with "\xa9", and then shown that you can successfully render that as CP-1252 and it displays as a copyright symbol. Meanwhile when I try the same thing on my Windows box, the default encoding is cp437, so it throws. Proves nothing about ASCII, as neither of those encodings is ASCII, and A9 does not decode as ASCII. ChrisA From breamoreboy at yahoo.co.uk Thu Dec 12 10:01:39 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 12 Dec 2013 15:01:39 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On 12/12/2013 14:34, wxjmfauth at gmail.com wrote: > Le jeudi 12 d?cembre 2013 11:28:35 UTC+1, Chris Angelico a ?crit : >> On Thu, Dec 12, 2013 at 8:17 PM, wrote: >> >>> Windows, Py2.(7), ascii. It is not a secret Python uses >> >>> ascii for the representation. >> >> >> >> Actually no, it doesn't. >> >> >> >> Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit >> >> (Intel)] on win32 >> >>>>> s = "abcd\xa9" >> >>>>> print(s) >> >> abcd? >> >> >> >> The copyright symbol is not in ASCII. Are you suggesting that Python >> >> uses a 7-bit internal representation of this data? Because a quick >> >> squiz at the source code will prove that wrong. This is not ASCII. >> >> > >>>> sys.version > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>>> sys.stdout.encoding > 'cp1252' >>>> s = 'abc\xa9' >>>> t = 'abc?' >>>> s > 'abc\xa9' >>>> t > 'abc\xa9' >>>> print s, t, (s, t) > abc? abc? ('abc\xa9', 'abc\xa9') >>>> def HumanStr(o): > t = repr(o) > newt = t.replace('\\xa9', '?') > return newt > >>>> print s, t, (s, t), HumanStr((s, t)) > abc? abc? ('abc\xa9', 'abc\xa9') ('abc?', 'abc?') >>>> > > jmf > > PS I do not insist on "sys.displayhook" > > PS2 I can only congratulate this Turkish guy for > his understanding of Python > I understand that this Turkish guy will be added to the list here http://en.wikipedia.org/wiki/Turing_Award next year for his stunning contribution to the field of computer science. The year after he will win the award again for his outstanding contribution which prevents people from sending double spaced crap to this list. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From wxjmfauth at gmail.com Thu Dec 12 11:20:45 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 12 Dec 2013 08:20:45 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <0e74b365-0f34-40dd-9d38-48135e428ec7@googlegroups.com> Le jeudi 12 d?cembre 2013 15:47:40 UTC+1, Chris Angelico a ?crit?: > On Fri, Dec 13, 2013 at 1:34 AM, wrote: > > > Le jeudi 12 d?cembre 2013 11:28:35 UTC+1, Chris Angelico a ?crit : > > >> On Thu, Dec 12, 2013 at 8:17 PM, wrote: > > >> > > >> > Windows, Py2.(7), ascii. It is not a secret Python uses > > >> > ascii for the representation. > > >> > > >> Actually no, it doesn't. > > > > > >>>> sys.version > > > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' > > >>>> sys.stdout.encoding > > > 'cp1252' > > > > What has this to do with ASCII or with Python's internal > > representation? All you've proven is that you can convert the repr of > > a string back into a byte-string, by replacing "\\xa9" with "\xa9", > > and then shown that you can successfully render that as CP-1252 and it > > displays as a copyright symbol. Meanwhile when I try the same thing on > > my Windows box, the default encoding is cp437, so it throws. Proves > > nothing about ASCII, as neither of those encodings is ASCII, and A9 > > does not decode as ASCII. > > Are you understanding Python by chance? print, __repr__, __str__, sys.std*.encoding, ... Are you understanding Windows? CHCP Are you understanding the coding of the characters? cp1252, cp850, cp437, ... Python (2) is managing all this very well. Unfortunately, not in a friendly way. jmf From ned at nedbatchelder.com Thu Dec 12 11:58:06 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 12 Dec 2013 11:58:06 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <0e74b365-0f34-40dd-9d38-48135e428ec7@googlegroups.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <0e74b365-0f34-40dd-9d38-48135e428ec7@googlegroups.com> Message-ID: On 12/12/13 11:20 AM, wxjmfauth at gmail.com wrote: > Le jeudi 12 d?cembre 2013 15:47:40 UTC+1, Chris Angelico a ?crit : >> On Fri, Dec 13, 2013 at 1:34 AM, wrote: >> >>> Le jeudi 12 d?cembre 2013 11:28:35 UTC+1, Chris Angelico a ?crit : >> >>>> On Thu, Dec 12, 2013 at 8:17 PM, wrote: >> >>>> >> >>>>> Windows, Py2.(7), ascii. It is not a secret Python uses >> >>>>> ascii for the representation. >> >>>> >> >>>> Actually no, it doesn't. >> >>> >> >>>>>> sys.version >> >>> '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >> >>>>>> sys.stdout.encoding >> >>> 'cp1252' >> >> >> >> What has this to do with ASCII or with Python's internal >> >> representation? All you've proven is that you can convert the repr of >> >> a string back into a byte-string, by replacing "\\xa9" with "\xa9", >> >> and then shown that you can successfully render that as CP-1252 and it >> >> displays as a copyright symbol. Meanwhile when I try the same thing on >> >> my Windows box, the default encoding is cp437, so it throws. Proves >> >> nothing about ASCII, as neither of those encodings is ASCII, and A9 >> >> does not decode as ASCII. >> >> > > > Are you understanding Python by chance? print, __repr__, __str__, > sys.std*.encoding, ... > Are you understanding Windows? CHCP > Are you understanding the coding of the characters? cp1252, cp850, cp437, ... > Before we talk about Unicode, we should talk about the process of convincing people of things. Asking questions won't convince anyone of anything. If you have new information, then present it to us. Presenting it means: show some code, show some bad outcome, and then explain what you you have demonstrated. Be specific about what problem you are showing. You said "Python uses ASCII." Then you showed us Python code with non-ASCII characters. We are confused what you are trying to tell us. Python 2 uses byte strings. Those byte strings can contain any bytes, conforming to any encoding the developer desires. You asserted that it uses ASCII. That is incorrect. We have discussed Unicode with you enough to believe that we are not going to agree with you. You hold a (very) minority view about what Python does with text, and you are not able to convince people of your view. Isn't that frustrating? Perhaps you need a new approach. > Python (2) is managing all this very well. Unfortunately, not in > a friendly way. > > jmf > -- Ned Batchelder, http://nedbatchelder.com From tjreedy at udel.edu Thu Dec 12 12:55:15 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Dec 2013 12:55:15 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: On 12/12/2013 4:17 AM, wxjmfauth at gmail.com wrote: > Windows, Py3, unicode. It is is infortunate, but it is > a fact Python has some problems with that platform (file > sytem encoding), -> potential problems which should not > exist for a beginner. Some disappear if, for instance, one uses Idle. > I am the first to recognize the win console is all but > friendly. Something we agree on. It is a piece crap. I believe that MS keeps it crippled to discourage use. (They apparently would like to remove it.) > If one wishes to use a unicode code page, Python fails [*]. If you mean cp65xxx (I forget exact numbers), MS Command Prompt fails, not Python. One should not use any other code page, but only other code pages work. Tk, and hence tkinter and idle work fine with the entire BMP. If one tells tk to use a font that can handle the entire BMP, it displays the entire BMP. > Python has plenty of good qualities, you (and others) > are discussing plenty of theoretical aspects. > I'm pointing the fact, one may be stuck simply because > one cannot display a piece of of text! Most text display problems disappear if one avoids Command Prompt and uses a GUI that can handle at least the BMP. Idle works on Windows after Python is installed unless one tells the installer to not install tcl/tk. -- Terry Jan Reedy From wxjmfauth at gmail.com Fri Dec 13 11:15:42 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 13 Dec 2013 08:15:42 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Le jeudi 12 d?cembre 2013 18:55:15 UTC+1, Terry Reedy a ?crit?: > > > > > > If you mean cp65xxx (I forget exact numbers), MS Command Prompt fails, > > not Python. One should not use any other code page, but only other code > > pages work. > > > ----- Please, do not exaggerate too much. On my win7 box, using cp65001: The golang works. Despite my poor knowledge with with this language, I even relatively quickly succeded to write a "readline" fct. Ruby 2 works. irb, the interactive ruby works. I remember to have had some diffuculties in entering some chars, this a different problem. echo "unicode" works. xelatex (my favourite tool), a tex-unicode engine, works. I'm usualy using a GUI tool, I just tested with a "???.tex" document. Indeed, it works. Starting that created document "???.pdf" with the cmd > start ???.pdf works. It calls Acrobat Reader. Starting that created document with Sumatra, a pdf viewer works. Not directly related to my comment, I can compile a .tex document in such a dir > D:\jm\??????\Z?rich\?????\?dipe and it works. Something a little bit different. Neil Hodgson's SciTE editor. One can configure the output pane to use 65001. All the examples above works. It is also possible to make Python working, but I had to write my own "printing material". A note about font. The console does not, and is not able, to display all the "chars". It is however always displaying text very smoothly and correctly using the replacement *glyph". Nothing to do with an "incorrect behaviour" of the console. Eg: > echo "??????*" works. I mainly considered BMP "characters". Windows is not so bad. One can discuss ad nauseam the pros and cons of console-gui application. I have always considered Windows as a system which use gui applications. And even with Python using a gui toolkit, I sometimes "link" my own created "gui console". I do not wish to defend MS. What I wrote depends on the Windows version, XP, Vista, Windows 7. One should recognize, with win7, MS, finally, produce a full unicode system. Strangely, among all the "bashing" one can read about that system, this is rarely mentioned. (With an excellent unicode coding scheme!) jmf From rosuav at gmail.com Fri Dec 13 11:27:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Dec 2013 03:27:35 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On Sat, Dec 14, 2013 at 3:15 AM, wrote: > One should recognize, with win7, MS, finally, produce > a full unicode system. Strangely, among all the "bashing" > one can read about that system, this is rarely mentioned. > (With an excellent unicode coding scheme!) [citation needed] ChrisA From breamoreboy at yahoo.co.uk Fri Dec 13 11:39:35 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 13 Dec 2013 16:39:35 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On 13/12/2013 16:27, Chris Angelico wrote: > On Sat, Dec 14, 2013 at 3:15 AM, wrote: >> One should recognize, with win7, MS, finally, produce >> a full unicode system. Strangely, among all the "bashing" >> one can read about that system, this is rarely mentioned. >> (With an excellent unicode coding scheme!) > > [citation needed] > > ChrisA > You'll have to wait until the cows come home on two counts. One, he's never yet provided any evidence to support any statement that he's ever made here. Second, he's still not smart enough to stop sending double spaced google crap. -- 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 Fri Dec 13 11:43:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Dec 2013 03:43:11 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On Sat, Dec 14, 2013 at 3:39 AM, Mark Lawrence wrote: > On 13/12/2013 16:27, Chris Angelico wrote: >> >> On Sat, Dec 14, 2013 at 3:15 AM, wrote: >>> >>> One should recognize, with win7, MS, finally, produce >>> a full unicode system. Strangely, among all the "bashing" >>> one can read about that system, this is rarely mentioned. >>> (With an excellent unicode coding scheme!) >> >> >> [citation needed] >> >> ChrisA >> > > You'll have to wait until the cows come home on two counts. One, he's never > yet provided any evidence to support any statement that he's ever made here. > Second, he's still not smart enough to stop sending double spaced google > crap. I don't know that it's a matter of not being smart enough. It's just as likely to be a deliberate choice, as that method of posting ensures that the quality of the style matches the quality of the substance. ChrisA From breamoreboy at yahoo.co.uk Fri Dec 13 12:02:29 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 13 Dec 2013 17:02:29 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On 13/12/2013 16:43, Chris Angelico wrote: > On Sat, Dec 14, 2013 at 3:39 AM, Mark Lawrence wrote: >> On 13/12/2013 16:27, Chris Angelico wrote: >>> >>> On Sat, Dec 14, 2013 at 3:15 AM, wrote: >>>> >>>> One should recognize, with win7, MS, finally, produce >>>> a full unicode system. Strangely, among all the "bashing" >>>> one can read about that system, this is rarely mentioned. >>>> (With an excellent unicode coding scheme!) >>> >>> >>> [citation needed] >>> >>> ChrisA >>> >> >> You'll have to wait until the cows come home on two counts. One, he's never >> yet provided any evidence to support any statement that he's ever made here. >> Second, he's still not smart enough to stop sending double spaced google >> crap. > > I don't know that it's a matter of not being smart enough. It's just > as likely to be a deliberate choice, as that method of posting ensures > that the quality of the style matches the quality of the substance. > > ChrisA > How can it be deliberate choice, that implies thought in the first place, which is highly conspicious by its absence? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Fri Dec 13 11:54:07 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 13 Dec 2013 08:54:07 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On Friday, December 13, 2013 10:13:11 PM UTC+5:30, Chris Angelico wrote: > On Sat, Dec 14, 2013 at 3:39 AM, Mark Lawrence wrote: > > You'll have to wait until the cows come home on two counts. One, he's never > > yet provided any evidence to support any statement that he's ever made here. > > Second, he's still not smart enough to stop sending double spaced google > > crap. > I don't know that it's a matter of not being smart enough. It's just > as likely to be a deliberate choice, as that method of posting ensures > that the quality of the style matches the quality of the substance. Correlates? Ok Ensures?? Citation needed From rosuav at gmail.com Fri Dec 13 11:57:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Dec 2013 03:57:07 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On Sat, Dec 14, 2013 at 3:54 AM, rusi wrote: >> I don't know that it's a matter of not being smart enough. It's just >> as likely to be a deliberate choice, as that method of posting ensures >> that the quality of the style matches the quality of the substance. > > Correlates? Ok > Ensures?? Citation needed For jmf's posts? Definitely ensures. Citation: python-list archives. :) ChrisA From tjreedy at udel.edu Fri Dec 13 18:30:38 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Dec 2013 18:30:38 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On 12/13/2013 11:27 AM, Chris Angelico wrote: > On Sat, Dec 14, 2013 at 3:15 AM, wrote: >> One should recognize, with win7, MS, finally, produce >> a full unicode system. Strangely, among all the "bashing" >> one can read about that system, this is rarely mentioned. >> (With an excellent unicode coding scheme!) > > [citation needed] Chris, I hardly think Jim's last statement (which I presume is your target) is egregious enough to start another junk subthread of 9 (now 10) posts. Certainly '[citation needed]' is a pretty senseless comment. 'Citation' to what, for what? It is well-known that Windows uses 2-byte words for unicode coding. If you want a citation for that fact, find it yourself. What is not clear to me is whether Windows internally uses UCS-2, which only codes BMP chars, and which would *not* be excellent, or UTF-16, which covers all chars by using surrogates. I will guess the latter. More to the point, even if MS uses a complete coding scheme internally (UFT-16), it does not, as far as I know, make it fully available and usable to *me*, as I showed in my response about code page 65001. -- Terry Jan Reedy From rosuav at gmail.com Fri Dec 13 18:38:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Dec 2013 10:38:48 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On Sat, Dec 14, 2013 at 10:30 AM, Terry Reedy wrote: > Chris, I hardly think Jim's last statement (which I presume is your target) > is egregious enough to start another junk subthread of 9 (now 10) posts. > Certainly '[citation needed]' is a pretty senseless comment. 'Citation' to > what, for what? It is well-known that Windows uses 2-byte words for unicode > coding. If you want a citation for that fact, find it yourself. > > What is not clear to me is whether Windows internally uses UCS-2, which only > codes BMP chars, and which would *not* be excellent, or UTF-16, which covers > all chars by using surrogates. I will guess the latter. More to the point, > even if MS uses a complete coding scheme internally (UFT-16), it does not, > as far as I know, make it fully available and usable to *me*, as I showed in > my response about code page 65001. And what I'm more asking for is a clarification on how Win 7 is different from the previous Windowses. I know a lot did change from XP to 7 (I don't care which side of Vista the change happened, let's just compare the popular Windows with the popular Windows here), but I wasn't aware that anything to do with Unicode had changed there. Since jmf made the assertion in words which implied that Microsoft had now *and only now* produced such a system, I asked for a citation. ChrisA From wxjmfauth at gmail.com Sat Dec 14 09:03:46 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 14 Dec 2013 06:03:46 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: Le samedi 14 d?cembre 2013 00:30:38 UTC+1, Terry Reedy a ?crit?: > > > > > > What is not clear to me is whether Windows internally uses UCS-2, which > > only codes BMP chars, and which would *not* be excellent, or UTF-16, > > which covers all chars by using surrogates. I will guess the latter. > > More to the point, even if MS uses a complete coding scheme internally > > (UFT-16), it does not, as far as I know, make it fully available and > > usable to *me*, as I showed in my response about code page 65001. > > ------------- D:\>chcp 65001 Page de codes active?: 65001 D:\>echo "*" "*" D:\> >>> locale.getdefaultlocale() ('fr_CH', 'cp1252') ---------- In my understanding and experience, in the MS world (desktop, intel), today: Unicode == utf-16-le ---------- If you think, utf-16, because of surrogate pairs, is not a proper solution, the single choice is utf-32. You may not be aware, you are already using utf-32 probably much more than you think, (in a correct way). jmf From rosuav at gmail.com Sat Dec 14 09:15:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Dec 2013 01:15:00 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On Sun, Dec 15, 2013 at 1:03 AM, wrote: > D:\>chcp 65001 > Page de codes active : 65001 > D:\>echo "*" > "*" > D:\> > > >>>> locale.getdefaultlocale() > ('fr_CH', 'cp1252') > > ---------- > > In my understanding and experience, in the MS world > (desktop, intel), today: > Unicode == utf-16-le You still haven't explained how Win7 is different from every other Windows going back as far as NT. Back in the NT days, Windows had "Unicode" (really UCS-2 - it predated Unicode 2.0, so that was correct for a few years) while OS/2 had DBCS. Hindsight shows that OS/2 did kinda get left behind there :) Though maybe it would be easier to force migration from DBCS to true Unicode than from UTF-16 or UCS-2 where it looks fine till you hit an astral character. Now how is Win7 different from NT? And where does the current "oldstable" Windows (if I may borrow a term from Debian), XP, fit into that? > If you think, utf-16, because of surrogate pairs, is > not a proper solution, the single choice is utf-32. > > You may not be aware, you are already using utf-32 > probably much more than you think, (in a correct way). Yeah. I use UTF-32 a lot, often stored in ways that elide unnecessary 00 bytes. It's a pretty good system, actually, giving high performance, compact memory usage, and correct behaviour. Still don't know what this has to do with Win7. ChrisA From breamoreboy at yahoo.co.uk Sat Dec 14 09:38:23 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Dec 2013 14:38:23 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On 14/12/2013 14:15, Chris Angelico wrote: > On Sun, Dec 15, 2013 at 1:03 AM, wrote: >> D:\>chcp 65001 >> Page de codes active : 65001 >> D:\>echo "*" >> "*" >> D:\> >> >> >>>>> locale.getdefaultlocale() >> ('fr_CH', 'cp1252') >> >> ---------- >> >> In my understanding and experience, in the MS world >> (desktop, intel), today: >> Unicode == utf-16-le > > You still haven't explained how Win7 is different from every other > Windows going back as far as NT. Back in the NT days, Windows had > "Unicode" (really UCS-2 - it predated Unicode 2.0, so that was correct > for a few years) while OS/2 had DBCS. Hindsight shows that OS/2 did > kinda get left behind there :) Though maybe it would be easier to > force migration from DBCS to true Unicode than from UTF-16 or UCS-2 > where it looks fine till you hit an astral character. Now how is Win7 > different from NT? And where does the current "oldstable" Windows (if > I may borrow a term from Debian), XP, fit into that? > >> If you think, utf-16, because of surrogate pairs, is >> not a proper solution, the single choice is utf-32. >> >> You may not be aware, you are already using utf-32 >> probably much more than you think, (in a correct way). > > Yeah. I use UTF-32 a lot, often stored in ways that elide unnecessary > 00 bytes. It's a pretty good system, actually, giving high > performance, compact memory usage, and correct behaviour. Still don't > know what this has to do with Win7. > > ChrisA > Reread "The Emperor's New Clothes" and you'll get it :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Sat Dec 14 13:43:41 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Dec 2013 13:43:41 -0500 Subject: CP65001 fails (was re: ...) In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On 12/14/2013 9:03 AM, wxjmfauth at gmail.com wrote: > D:\>chcp 65001 > Page de codes active : 65001 > D:\>echo "*" > "*" Try pasting *your* original echo command: echo "??????*" To repeat, here is what I see: ''' C:\Users\Terry>echo "??????*" "??????*" C:\Users\Terry>chcp 65001 Active code page: 65001 C:\Users\Terry>echo "*" The system cannot write to the specified device. ''' To repeat, the second time I paste: echo "??????*" but Command Prompt only displays: echo "*". Typing in the latter, ascii-only, command is meaningless. A similar test: ''' C:\Users\Terry>more ^Z C:\Users\Terry>chcp 65001 Active code page: 65001 C:\Users\Terry>more Not enough memory. ''' This was reported by Victor Stinner as part of http://bugs.python.org/issue19914 to explain how cp65001 causes behavior like this with Python's interactive help() function (which more for paging on Windows). >>> help(str) Not enough memory. See http://stackoverflow.com/questions/3401802/codepage-850-works-65001-fails-there-is-no-response-to-call-foo-cmd-interna for other reports that cp65001 fails. It is not just me. -- Terry Jan Reedy From wxjmfauth at gmail.com Sat Dec 14 15:48:05 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 14 Dec 2013 12:48:05 -0800 (PST) Subject: CP65001 fails (was re: ...) In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> Le samedi 14 d?cembre 2013 19:43:41 UTC+1, Terry Reedy a ?crit?: > On 12/14/2013 9:03 AM, wxjmfauth at gmail.com wrote: > > > > > D:\>chcp 65001 > > > Page de codes active : 65001 > > > D:\>echo "*" > > > "*" > > > > Try pasting *your* original echo command: echo "??????*" > > > > To repeat, here is what I see: > > ''' > > C:\Users\Terry>echo "??????*" > > "??????*" > > > > C:\Users\Terry>chcp 65001 > > Active code page: 65001 > > > > C:\Users\Terry>echo "*" > > The system cannot write to the specified device. > > ''' > > To repeat, the second time I paste: echo "??????*" > > but Command Prompt only displays: echo "*". Typing in the latter, > > ascii-only, command is meaningless. > > > > A similar test: > > ''' > > C:\Users\Terry>more > > ^Z > > > > C:\Users\Terry>chcp 65001 > > Active code page: 65001 > > > > C:\Users\Terry>more > > Not enough memory. > > ''' > > This was reported by Victor Stinner as part of > > http://bugs.python.org/issue19914 > > to explain how cp65001 causes behavior like this with Python's > > interactive help() function (which more for paging on Windows). > > > > >>> help(str) > > Not enough memory. > > > > See > > http://stackoverflow.com/questions/3401802/codepage-850-works-65001-fails-there-is-no-response-to-call-foo-cmd-interna > > for other reports that cp65001 fails. It is not just me. > > > ---- >>> print((os.linesep).join([unicodedata.name(c) for c in u])) ETHIOPIC SYLLABLE SEE LATIN SMALL LETTER E WITH ACUTE EURO SIGN CJK UNIFIED IDEOGRAPH-3456 CYRILLIC CAPITAL LETTER GJE COUNTERBORE ASTERISK ----- cp65001, font: Consolas D:\jm\jmgo>echo "??????*" "??????*" As I explained some chars are rendered with the .notdef glyph: the chars 1, 4 and 7. I build an exe with the golang. Same result. Just for curiosity: XeTeX -> pdf: same result. LucidaConsole CID TrueType, Consolas CID TrueType understand: "OpenType" jmf From breamoreboy at yahoo.co.uk Sat Dec 14 16:05:05 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Dec 2013 21:05:05 +0000 Subject: CP65001 fails (was re: ...) In-Reply-To: <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> Message-ID: On 14/12/2013 20:48, wxjmfauth at gmail.com wrote: > >>>> print((os.linesep).join([unicodedata.name(c) for c in u])) > ETHIOPIC SYLLABLE SEE > LATIN SMALL LETTER E WITH ACUTE > EURO SIGN > CJK UNIFIED IDEOGRAPH-3456 > CYRILLIC CAPITAL LETTER GJE > COUNTERBORE > ASTERISK > > ----- > > cp65001, font: Consolas > > D:\jm\jmgo>echo "??????*" > "??????*" > > As I explained some chars are rendered with the .notdef glyph: > the chars 1, 4 and 7. > > I build an exe with the golang. Same result. > > Just for curiosity: > XeTeX -> pdf: same result. > LucidaConsole CID TrueType, > Consolas CID TrueType > understand: "OpenType" > > jmf > Where is the Python related issue here? Why do you keep posting double spaced crap, despite repeated requests not to do so? Or do you blame this on the allegedly failed PEP 393 FSR implementation? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sat Dec 14 17:51:08 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Dec 2013 22:51:08 GMT Subject: CP65001 fails (was re: ...) References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> Message-ID: <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Dec 2013 21:05:05 +0000, Mark Lawrence wrote: > On 14/12/2013 20:48, wxjmfauth at gmail.com wrote: >> >>>>> print((os.linesep).join([unicodedata.name(c) for c in u])) >> ETHIOPIC SYLLABLE SEE >> LATIN SMALL LETTER E WITH ACUTE >> EURO SIGN >> CJK UNIFIED IDEOGRAPH-3456 >> CYRILLIC CAPITAL LETTER GJE >> COUNTERBORE >> ASTERISK >> >> ----- >> >> cp65001, font: Consolas >> >> D:\jm\jmgo>echo "??????*" >> "??????*" >> >> As I explained some chars are rendered with the .notdef glyph: the >> chars 1, 4 and 7. >> >> I build an exe with the golang. Same result. >> >> Just for curiosity: >> XeTeX -> pdf: same result. >> LucidaConsole CID TrueType, >> Consolas CID TrueType >> understand: "OpenType" >> >> jmf >> >> > Where is the Python related issue here? Read the whole thread before charging in like a bull at a gate accusing people of being off-topic. This is on-topic, and if you don't see the connection, you need to read the whole thread. > Why do you keep posting double spaced crap, despite repeated requests > not to do so? Or do you blame this on the allegedly failed PEP 393 > FSR implementation? I see no double-spacing in the text you quoted. Do you have nothing better to do than continually hassle people over minor formatting issues? Formatting issues are harmful to the degree they get in the way of efficient communication. Since by your own admission you have never treated JMF as being credible, there's nothing he can write or say that you will believe, so why do you care what he writes? You are not the target of his communication unless you choose to be. Apart from annoying the bystanders, your repeated angry and abusive screeds aimed at JMF in particular but others as well over minor formatting issues is more disruptive than the issues you are complaining about. I am grateful to you for taking the time and effort to write up a wiki page on fixing this issues, but gratitude for that will only go so far in forgiving disruptive behaviour. -- Steven From breamoreboy at yahoo.co.uk Sat Dec 14 18:32:33 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Dec 2013 23:32:33 +0000 Subject: CP65001 fails (was re: ...) In-Reply-To: <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/12/2013 22:51, Steven D'Aprano wrote: > On Sat, 14 Dec 2013 21:05:05 +0000, Mark Lawrence wrote: > >> On 14/12/2013 20:48, wxjmfauth at gmail.com wrote: >>> >>>>>> print((os.linesep).join([unicodedata.name(c) for c in u])) >>> ETHIOPIC SYLLABLE SEE >>> LATIN SMALL LETTER E WITH ACUTE >>> EURO SIGN >>> CJK UNIFIED IDEOGRAPH-3456 >>> CYRILLIC CAPITAL LETTER GJE >>> COUNTERBORE >>> ASTERISK >>> >>> ----- >>> >>> cp65001, font: Consolas >>> >>> D:\jm\jmgo>echo "??????*" >>> "??????*" >>> >>> As I explained some chars are rendered with the .notdef glyph: the >>> chars 1, 4 and 7. >>> >>> I build an exe with the golang. Same result. >>> >>> Just for curiosity: >>> XeTeX -> pdf: same result. >>> LucidaConsole CID TrueType, >>> Consolas CID TrueType >>> understand: "OpenType" >>> >>> jmf >>> >>> >> Where is the Python related issue here? > > Read the whole thread before charging in like a bull at a gate accusing > people of being off-topic. This is on-topic, and if you don't see the > connection, you need to read the whole thread. I have. Going back over this thread the words from Terry Reedy make things perfectly clear that this is a *WINDOWS* problem, not a *PYTHON* one. Chris Angelico also weighed in, but again he was simply ignored. Instead some completely irrelevant cobblers turned up from "Joseph McCarthy". > > >> Why do you keep posting double spaced crap, despite repeated requests >> not to do so? Or do you blame this on the allegedly failed PEP 393 >> FSR implementation? > > I see no double-spacing in the text you quoted. There is no double spacing because for the umpteenth time I've snipped the whole damn lot. > > Do you have nothing better to do than continually hassle people over > minor formatting issues? This is *NOT* a minor formatting issue, it's a big PITA that should be stopped at source. It would be easier for this to happen if and only if people would stop defending the bug ridden crap tools that are being used to send the double spaced crap. Oh Lord, won't you buy me Mozilla Thunderbird ? My friends all use GG, I think that's absurd. Worked hard all my lifetime, no help from the nerds, So Lord, won't you buy me Mozilla Thunderbird ? > > Formatting issues are harmful to the degree they get in the way of > efficient communication. Since by your own admission you have never > treated JMF as being credible, there's nothing he can write or say that > you will believe, so why do you care what he writes? You are not the > target of his communication unless you choose to be. While he continues to talk crap here I will respond, as I will also complain about double spaced google crap until it stops. I will further state again that I find his disgusting, unwarrented attacks on the PEP 393 FSR indefensible, and are also an attack on the core developers who've taken the time to deliver a faster, (relatively) bug free and lower memory useage implementation of unicode for Python 3.3+. > > Apart from annoying the bystanders, your repeated angry and abusive > screeds aimed at JMF in particular but others as well over minor > formatting issues is more disruptive than the issues you are complaining > about. I am grateful to you for taking the time and effort to write up a > wiki page on fixing this issues, but gratitude for that will only go so > far in forgiving disruptive behaviour. > Your opinion, obviously I disagree, these IMO are *NOT* minor issues, and they're also completely avoidable. Stop the problems at source and there are no issues to complain about. I've written no such thing, I simply point it out half a dozen times a day as the latest pile of crap turns up here. Stop the problems at source and there are no issues to complain about. Yes, that's there twice so nobody can miss it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Sat Dec 14 23:42:40 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 14 Dec 2013 20:42:40 -0800 (PST) Subject: CP65001 fails (was re: ...) In-Reply-To: <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1a0db7e5-98fe-4c83-92fa-de2a644e34d0@googlegroups.com> On Sunday, December 15, 2013 4:21:08 AM UTC+5:30, Steven D'Aprano wrote: > Apart from annoying the bystanders, your repeated angry and abusive > screeds aimed at JMF in particular but others as well over minor > formatting issues is more disruptive than the issues you are complaining > about. I am grateful to you for taking the time and effort to write up a > wiki page on fixing this issues, but gratitude for that will only go so > far in forgiving disruptive behaviour. I guess you are talking about https://wiki.python.org/moin/GoogleGroupsPython As you will see https://wiki.python.org/moin/GoogleGroupsPython?action=info most of the edits there are by rurpy and the recent ones (sorry I missed putting comments) which are for a more automatic solution are by me. [No I am not asking for 'gratitude'... just sayin' and giving some context] There was this ridiculous guy Jonas https://mail.python.org/pipermail/python-list/2013-October/658671.html who responded to calls to correct the typical GG mess with more and more exceptional rudeness https://mail.python.org/pipermail/python-list/2013-October/658816.html So I thought to myself: Well this is too much! And yet while the rudeness is indefensible the technical grumble: "I'm not going to go deleting newlines" is not. Hell! Rather than making a socio-eco-politco-anthropo-marxist-feminist mess, why dont we fix a technical problem technically?? To me all this GG complaining sounds like some elderly mom-pop-uncle who weeps/coaxes/moans/pleads/grumbles/ about a fused light bulb, rather than climbing on a stool and changing the bloody thing. So, given that I am a programmer I came up (with some tips from Kushal Kumaran?) with a technical solution. If I were an ace programmer (can learn JS in a day and make useful contributions) it would have been a 0-click solution. [And if I were a super-ace, it would have been a beneficient virus, that would comb the net, discover all GG users and self-install without anyone's knowing] Since I am not ace or super-ace but only a humble programmer (like Dijkstra!) its a 2-click solution that needs installation :-; Still, GIVEN THE CONTEXT -- addressing not anyone but an already-GG user who is clueless about the nuisance he's causing -- I think this solution is easiest to all. From rosuav at gmail.com Sat Dec 14 23:48:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Dec 2013 15:48:05 +1100 Subject: CP65001 fails (was re: ...) In-Reply-To: <1a0db7e5-98fe-4c83-92fa-de2a644e34d0@googlegroups.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> <1a0db7e5-98fe-4c83-92fa-de2a644e34d0@googlegroups.com> Message-ID: On Sun, Dec 15, 2013 at 3:42 PM, rusi wrote: > To me all this GG complaining sounds like some elderly mom-pop-uncle > who weeps/coaxes/moans/pleads/grumbles/ about a fused light bulb, > rather than climbing on a stool and changing the bloody thing. No, it's like moaning about Foo Brand light bulbs that die after two weeks, when there are perfectly good light bulbs that last for years if you'll just use a different brand. And there are people who say "But Foo Brand light bulbs are easy, you just go up on a ladder every time you want to turn it on and make sure there's a good bulb in it!". ChrisA From breamoreboy at yahoo.co.uk Sun Dec 15 09:25:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 15 Dec 2013 14:25:26 +0000 Subject: CP65001 fails (was re: ...) In-Reply-To: References: <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> <1a0db7e5-98fe-4c83-92fa-de2a644e34d0@googlegroups.com> Message-ID: On 15/12/2013 04:48, Chris Angelico wrote: > On Sun, Dec 15, 2013 at 3:42 PM, rusi wrote: >> To me all this GG complaining sounds like some elderly mom-pop-uncle >> who weeps/coaxes/moans/pleads/grumbles/ about a fused light bulb, >> rather than climbing on a stool and changing the bloody thing. > > No, it's like moaning about Foo Brand light bulbs that die after two > weeks, when there are perfectly good light bulbs that last for years > if you'll just use a different brand. And there are people who say > "But Foo Brand light bulbs are easy, you just go up on a ladder every > time you want to turn it on and make sure there's a good bulb in it!". > > ChrisA > On this count I observe that on 15/12/2013 GMT at 08:26 the cows still haven't come home :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sun Dec 15 00:00:12 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Dec 2013 05:00:12 GMT Subject: CP65001 fails (was re: ...) References: <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> <1a0db7e5-98fe-4c83-92fa-de2a644e34d0@googlegroups.com> Message-ID: <52ad375c$0$29992$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Dec 2013 20:42:40 -0800, rusi wrote: > On Sunday, December 15, 2013 4:21:08 AM UTC+5:30, Steven D'Aprano wrote: >> Apart from annoying the bystanders, your repeated angry and abusive >> screeds aimed at JMF in particular but others as well over minor >> formatting issues is more disruptive than the issues you are >> complaining about. I am grateful to you for taking the time and effort >> to write up a wiki page on fixing this issues, but gratitude for that >> will only go so far in forgiving disruptive behaviour. > > I guess you are talking about > https://wiki.python.org/moin/GoogleGroupsPython > > As you will see > https://wiki.python.org/moin/GoogleGroupsPython?action=info > > most of the edits there are by rurpy and the recent ones (sorry I missed > putting comments) which are for a more automatic solution are by me. I'm sorry, I was under the impression that Mark had done most of the work. I hadn't realised that others had contributed most of the practical advice. -- Steven From rustompmody at gmail.com Sun Dec 15 00:24:55 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 14 Dec 2013 21:24:55 -0800 (PST) Subject: CP65001 fails (was re: ...) In-Reply-To: <52ad375c$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <256fbd43-597c-4d23-910c-37f878b5bd91@googlegroups.com> <52ace0dc$0$29992$c3e8da3$5496439d@news.astraweb.com> <1a0db7e5-98fe-4c83-92fa-de2a644e34d0@googlegroups.com> <52ad375c$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <082c4f73-55c3-49d1-881e-19193985398c@googlegroups.com> On Sunday, December 15, 2013 10:30:12 AM UTC+5:30, Steven D'Aprano wrote: > I'm sorry, I was under the impression that Mark had done most of the > work. I hadn't realised that others had contributed most of the practical > advice. To be fair, I added the stuff to the wiki on Mark's prompting. Earlier was under the impression that not anyone could edit the wiki. From steve+comp.lang.python at pearwood.info Sat Dec 14 21:39:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Dec 2013 02:39:50 GMT Subject: CP65001 fails (was re: ...) References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: <52ad1675$0$29992$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Dec 2013 13:43:41 -0500, Terry Reedy wrote: > This was reported by Victor Stinner as part of > http://bugs.python.org/issue19914 > to explain how cp65001 causes behavior like this with Python's > interactive help() function (which more for paging on Windows). > > >>> help(str) > Not enough memory. Terry, I see you have closed the bug report. I think you were a little hasty. The ultimate cause of the bug may be the failure of Window's "more" command when the code-page is set to CP-65001, but that doesn't necessarily imply that Python shouldn't, or can't, do something about it. The interactive help system already supports different pagers, depending on the environment. I think that it could fall back on a more primitive pager if the preferred one fails. The relevant code is the pager() and getpager() functions in the pydoc module. The patch won't be trivial, but I think it can be done, and I think it should be done. Although possibly for Python 3.5 rather than a bug-fix version. Your thoughts? -- Steven From tjreedy at udel.edu Sun Dec 15 00:07:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Dec 2013 00:07:09 -0500 Subject: CP65001 fails (was re: ...) In-Reply-To: <52ad1675$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <52ad1675$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/14/2013 9:39 PM, Steven D'Aprano wrote: > On Sat, 14 Dec 2013 13:43:41 -0500, Terry Reedy wrote: > >> This was reported by Victor Stinner as part of >> http://bugs.python.org/issue19914 >> to explain how cp65001 causes behavior like this with Python's >> interactive help() function (which more for paging on Windows). >> >> >>> help(str) >> Not enough memory. > > > Terry, I see you have closed the bug report. I think you were a little > hasty. I might have been premature, but I was not hasty. I read the SO reports and though about it for an hour or so while looking at other issues. I did not see any use to leaving it open as I did not see any realistic propect of a useful and acceptible patch to Python. The OP himself said that i/o did not work with 65001 and that not using it fixed his issue. > The ultimate cause of the bug may be the failure of Window's > "more" command when the code-page is set to CP-65001, but that doesn't > necessarily imply that Python shouldn't, or can't, do something about it. I believe running Python on Windows with cp=65001 falls in the category of "Don't do that". This is based on my experiences and the reported experience of other developers who have tried and failed to make it work, reinforced by the SO thread and a couple of other web pages. > The interactive help system already supports different pagers, depending > on the environment. I think that it could fall back on a more primitive > pager if the preferred one fails. Do you know if 'more' actually signals failure? Do you know if there are any other situations in which a pager fails? > The relevant code is the pager() and > getpager() functions in the pydoc module. The patch won't be trivial, but > I think it can be done, and I think it should be done. Although possibly > for Python 3.5 rather than a bug-fix version. Your thoughts? My thought is that if the only situation in which a pager fails is one that one should not use, because other things will also fail, then a patch would not be worth the bother. -- Terry Jan Reedy From wxjmfauth at gmail.com Sun Dec 15 03:26:01 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 15 Dec 2013 00:26:01 -0800 (PST) Subject: CP65001 fails (was re: ...) In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <52ad1675$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: Le dimanche 15 d?cembre 2013 06:07:09 UTC+1, Terry Reedy a ?crit?: > On 12/14/2013 9:39 PM, Steven D'Aprano wrote: > > > On Sat, 14 Dec 2013 13:43:41 -0500, Terry Reedy wrote: > > > > > >> This was reported by Victor Stinner as part of > > >> http://bugs.python.org/issue19914 > > >> to explain how cp65001 causes behavior like this with Python's > > >> interactive help() function (which more for paging on Windows). > > >> > > >> >>> help(str) > > >> Not enough memory. > > > > > > > > > Terry, I see you have closed the bug report. I think you were a little > > > hasty. > > > > I might have been premature, but I was not hasty. I read the SO reports > > and though about it for an hour or so while looking at other issues. I > > did not see any use to leaving it open as I did not see any realistic > > propect of a useful and acceptible patch to Python. The OP himself said > > that i/o did not work with 65001 and that not using it fixed his issue. > > > > > The ultimate cause of the bug may be the failure of Window's > > > "more" command when the code-page is set to CP-65001, but that doesn't > > > necessarily imply that Python shouldn't, or can't, do something about it. > > > > I believe running Python on Windows with cp=65001 falls in the category > > of "Don't do that". This is based on my experiences and the reported > > experience of other developers who have tried and failed to make it > > work, reinforced by the SO thread and a couple of other web pages. > > > > > The interactive help system already supports different pagers, depending > > > on the environment. I think that it could fall back on a more primitive > > > pager if the preferred one fails. > > > > Do you know if 'more' actually signals failure? > > Do you know if there are any other situations in which a pager fails? > > > > > The relevant code is the pager() and > > > getpager() functions in the pydoc module. The patch won't be trivial, but > > > I think it can be done, and I think it should be done. Although possibly > > > for Python 3.5 rather than a bug-fix version. Your thoughts? > > > > My thought is that if the only situation in which a pager fails is one > > that one should not use, because other things will also fail, then a > > patch would not be worth the bother. > > If I'm understanding a little bit about coding of characters, fonts, chars "inputing", I should say I never really understood how all this stuff is arranged. (I never found a real explanation too). There is something, which may be very deeply bound to the system (kernel ?). As an example, entering a char with Alt+0XXX always works accordingly to my (the?) localized windows version. Entering a char with Alt+XXX (not the missing 0) uses the OEM (bios?) encoding. jmf From wxjmfauth at gmail.com Fri Dec 13 13:27:41 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 13 Dec 2013 10:27:41 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: Le vendredi 13 d?cembre 2013 17:27:35 UTC+1, Chris Angelico a ?crit?: > On Sat, Dec 14, 2013 at 3:15 AM, wrote: > > > One should recognize, with win7, MS, finally, produce > > > a full unicode system. Strangely, among all the "bashing" > > > one can read about that system, this is rarely mentioned. > > > (With an excellent unicode coding scheme!) > > > > [citation needed] > ----- My guess is that you are referring to that sentence "(With an excellent unicode coding scheme!)". I do not need to cite anything. That's my opinion. My comment was mainly oriented about cp65*** in the context of a teaching programming language. I pointed that some tools are working very well with that code page. jmf From rosuav at gmail.com Fri Dec 13 13:32:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Dec 2013 05:32:58 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On Sat, Dec 14, 2013 at 5:27 AM, wrote: > My guess is that you are referring to that > sentence "(With an excellent unicode coding scheme!)". > I do not need to cite anything. That's my opinion. Just as much to what's above it, where you state that MS has produced "a full unicode system". Is that, too, just opinion, utterly unfounded in fact, or can you provide a citation? ChrisA From wxjmfauth at gmail.com Fri Dec 13 14:30:49 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 13 Dec 2013 11:30:49 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: Le vendredi 13 d?cembre 2013 19:32:58 UTC+1, Chris Angelico a ?crit?: > On Sat, Dec 14, 2013 at 5:27 AM, wrote: > > > My guess is that you are referring to that > > > sentence "(With an excellent unicode coding scheme!)". > > > I do not need to cite anything. That's my opinion. > > > > Just as much to what's above it, where you state that MS has produced > > "a full unicode system". Is that, too, just opinion, utterly unfounded > > in fact, or can you provide a citation? > > I have not the knowledge to put a jugment on this. I read many articles on the subject from people who seems to have some skills on the subject. >From my own experience with my limited and empirical computing experience, when I see the file system, the rendering engine, the usage of OpenType fonts, ... I tend to have to agree. I can also point that all these aspects jump to my mind when I switched from XP to 7. Some time ago, I even fall on an article about the bootstraping mechanism (7 or 8 or future version or RT ?) which uses natively ucs-2. jmf From tjreedy at udel.edu Fri Dec 13 17:49:32 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Dec 2013 17:49:32 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On 12/13/2013 11:15 AM, wxjmfauth at gmail.com wrote: > Le jeudi 12 d?cembre 2013 18:55:15 UTC+1, Terry Reedy a ?crit : >> If you mean cp65xxx (I forget exact numbers), MS Command Prompt fails, >> not Python. One should not use any other code page, but only other code >> pages work. > Please, do not exaggerate too much. I try not to, so in case I mis-remembered, I tried your experiment. >> echo "??????*" > works. I cut the mixed alphabet input line and pasted into a *fresh* Command Prompt window on my USA Win 7 machine with all updates. C:\Users\Terry>echo "??????*" "??????*" About what I expected, except for ? becoming ,. Now the test. Change the code page and re-paste. ''' C:\Users\Terry>chcp 65001 Active code page: 65001 C:\Users\Terry>echo "*" The system cannot write to the specified device. ''' This a major fail as all non-ascii chars are deleted when pasted (at least visibly) and the echo does not echo. There is no Python involved in this failure. I am willing to believe that you might have gotten different behavior on your French Win 7 machine. Windows is not an international OS, but rather a collection of ghettoized national versions. As I said before, Idle does work in this regard. Python 3.4.0a4 (v3.4.0a4:e245b0d7209b, Oct 20 2013, 19:57:58) [MSC v.1600 64 bit (AMD64)] on win32 >>> "??????*" '??????*' -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Fri Dec 13 18:10:01 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 13 Dec 2013 23:10:01 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: On 13/12/2013 22:49, Terry Reedy wrote: > On 12/13/2013 11:15 AM, wxjmfauth at gmail.com wrote: >> Le jeudi 12 d?cembre 2013 18:55:15 UTC+1, Terry Reedy a ?crit : > >>> If you mean cp65xxx (I forget exact numbers), MS Command Prompt fails, >>> not Python. One should not use any other code page, but only other code >>> pages work. > >> Please, do not exaggerate too much. > > I try not to, so in case I mis-remembered, I tried your experiment. > > >> echo "??????*" > > works. > > I cut the mixed alphabet input line and pasted into a *fresh* Command > Prompt window on my USA Win 7 machine with all updates. > > C:\Users\Terry>echo "??????*" > "??????*" > > About what I expected, except for ? becoming ,. Now the test. Change the > code page and re-paste. > ''' > C:\Users\Terry>chcp 65001 > Active code page: 65001 > > C:\Users\Terry>echo "*" > The system cannot write to the specified device. > ''' > This a major fail as all non-ascii chars are deleted when pasted (at > least visibly) and the echo does not echo. There is no Python involved > in this failure. > > I am willing to believe that you might have gotten different behavior on > your French Win 7 machine. Windows is not an international OS, but > rather a collection of ghettoized national versions. > > As I said before, Idle does work in this regard. > > Python 3.4.0a4 (v3.4.0a4:e245b0d7209b, Oct 20 2013, 19:57:58) [MSC > v.1600 64 bit (AMD64)] on win32 > >>> "??????*" > '??????*' > Seems like we're now in the later stages of the 15, three minute rounds. The trainer won't throw in the towel, the referee won't stop the fight and the boxer himself won't quit. Is jmf actually trying to get himself killed? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ethan at stoneleaf.us Fri Dec 13 18:17:36 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 13 Dec 2013 15:17:36 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: <52AB9590.80505@stoneleaf.us> On 12/13/2013 03:10 PM, Mark Lawrence wrote: > > Seems like we're now in the later stages of the 15, three minute rounds. The trainer won't throw in the towel, the > referee won't stop the fight and the boxer himself won't quit. Is jmf actually trying to get himself killed? His credibility with me has been long dead. :( -- ~Ethan~ From breamoreboy at yahoo.co.uk Fri Dec 13 18:58:14 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 13 Dec 2013 23:58:14 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52AB9590.80505@stoneleaf.us> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <52AB9590.80505@stoneleaf.us> Message-ID: On 13/12/2013 23:17, Ethan Furman wrote: > On 12/13/2013 03:10 PM, Mark Lawrence wrote: >> >> Seems like we're now in the later stages of the 15, three minute >> rounds. The trainer won't throw in the towel, the >> referee won't stop the fight and the boxer himself won't quit. Is jmf >> actually trying to get himself killed? > > His credibility with me has been long dead. :( > > -- > ~Ethan~ With me it never lived, we've simply had to put up with his FUD for 16 months. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sat Dec 14 05:00:56 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Dec 2013 10:00:56 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <52AB9590.80505@stoneleaf.us> Message-ID: <52ac2c58$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Dec 2013 23:58:14 +0000, Mark Lawrence wrote: > On 13/12/2013 23:17, Ethan Furman wrote: >> On 12/13/2013 03:10 PM, Mark Lawrence wrote: >>> >>> Seems like we're now in the later stages of the 15, three minute >>> rounds. The trainer won't throw in the towel, the referee won't stop >>> the fight and the boxer himself won't quit. Is jmf actually trying to >>> get himself killed? >> >> His credibility with me has been long dead. :( >> >> -- >> ~Ethan~ > > With me it never lived, we've simply had to put up with his FUD for 16 > months. Mark, do you really mean to say that you were prejudiced against JMF before he even write a word here? Strange thing to say, since he did actually identify a real performance regression, even if he has since become obsessed with demonstrating that a micro-performance slowdown means that Python is mathematically and logically broken. -- Steven From breamoreboy at yahoo.co.uk Sat Dec 14 08:21:28 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 14 Dec 2013 13:21:28 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52ac2c58$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> <52AB9590.80505@stoneleaf.us> <52ac2c58$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/12/2013 10:00, Steven D'Aprano wrote: > On Fri, 13 Dec 2013 23:58:14 +0000, Mark Lawrence wrote: > >> On 13/12/2013 23:17, Ethan Furman wrote: >>> On 12/13/2013 03:10 PM, Mark Lawrence wrote: >>>> >>>> Seems like we're now in the later stages of the 15, three minute >>>> rounds. The trainer won't throw in the towel, the referee won't stop >>>> the fight and the boxer himself won't quit. Is jmf actually trying to >>>> get himself killed? >>> >>> His credibility with me has been long dead. :( >>> >>> -- >>> ~Ethan~ >> >> With me it never lived, we've simply had to put up with his FUD for 16 >> months. > > Mark, do you really mean to say that you were prejudiced against JMF > before he even write a word here? > > Strange thing to say, since he did actually identify a real performance > regression, even if he has since become obsessed with demonstrating that > a micro-performance slowdown means that Python is mathematically and > logically broken. > IIRC he first started spreading his rubbish sometime in August 2012, I make that around 16 months, what does your maths skills make it? He also identified a problem in an edge case that stood out like a sore thumb when compared to real world cases. Big deal. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sat Dec 14 04:58:43 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Dec 2013 09:58:43 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <5b62c6f8-fb92-48ef-a59a-6025b9b39994@googlegroups.com> Message-ID: <52ac2bd3$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Dec 2013 17:49:32 -0500, Terry Reedy wrote: > On 12/13/2013 11:15 AM, wxjmfauth at gmail.com wrote: >> Le jeudi 12 d?cembre 2013 18:55:15 UTC+1, Terry Reedy a ?crit : > >>> If you mean cp65xxx (I forget exact numbers), MS Command Prompt fails, >>> not Python. One should not use any other code page, but only other >>> code pages work. > >> Please, do not exaggerate too much. > > I try not to, so in case I mis-remembered, I tried your experiment. Terry, thanks for actually doing some useful Unicode experiments instead of just jumping on the "Let's all make fun of JMF bandwagon." -- Steven From steve+comp.lang.python at pearwood.info Wed Dec 11 06:17:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Dec 2013 11:17:45 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <52a849d9$0$29992$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Dec 2013 19:43:52 +1100, Chris Angelico wrote: > [1] http://tvtropes.org/pmwiki/pmwiki.php/Main/InMediasRes TV Tropes? You utter, utter bastard. Must... resist... call... of... TV Tropes... -- Steven From ethan at stoneleaf.us Wed Dec 11 15:47:28 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Dec 2013 12:47:28 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> Message-ID: <52A8CF60.9040202@stoneleaf.us> On 12/11/2013 12:34 AM, Devin Jeanpierre wrote: > On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman wrote: >> Doesn't sound like they do, as that's causing plenty of problems. In >> today's world that level of knowledge isn't always necessary, especially if >> your degree is not in CS. One of the (many) nice things about Python is one >> doesn't need to know that stuff to Get Things Done. > > You don't need to know how to use the brakes to drive to Wal-Mart, > either. In my world, Getting Things Done includes not crashing at my destination. ;) -- ~Ethan~ From rosuav at gmail.com Wed Dec 11 18:07:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Dec 2013 10:07:40 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52A8CF60.9040202@stoneleaf.us> References: <201312090824.25211.gheskett@wdtv.com> <52A78F6F.3060507@stoneleaf.us> <52A8CF60.9040202@stoneleaf.us> Message-ID: On Thu, Dec 12, 2013 at 7:47 AM, Ethan Furman wrote: > On 12/11/2013 12:34 AM, Devin Jeanpierre wrote: >> >> On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman wrote: >>> >>> Doesn't sound like they do, as that's causing plenty of problems. In >>> today's world that level of knowledge isn't always necessary, especially >>> if >>> your degree is not in CS. One of the (many) nice things about Python is >>> one >>> doesn't need to know that stuff to Get Things Done. >> >> >> You don't need to know how to use the brakes to drive to Wal-Mart, >> either. > > > In my world, Getting Things Done includes not crashing at my destination. > ;) Reminds me of this discussion of reaching the moon: http://htmlimg4.scribdassets.com/4uppo05fpc5w0c0/images/17-77601f4dfc.jpg "We shall end up by arriving, I suppose." ChrisA From rosuav at gmail.com Mon Dec 9 08:27:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 00:27:39 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: On Mon, Dec 9, 2013 at 11:23 PM, Oscar Benjamin wrote: > 1) Some people felt that Python is not an "industry standard" unlike > C/C++/Java and that it is not as good for employability. Disprove that by checking any job listing site in your area/industry. You'll find plenty of Python jobs there. ChrisA From rustompmody at gmail.com Mon Dec 9 08:54:34 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 9 Dec 2013 05:54:34 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <375c2f39-d867-4512-9776-e451281d8b98@googlegroups.com> On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: > Hi all, > I work in a University Engineering faculty teaching, among other > things, programming. In our last meeting about improving our teaching > syllabus and delivery we've identified the first year programming > courses as an area where there is room for improvement and we're > considering (mainly on my suggestion) switching to using Python as the > first programming language that we use to introduce our students to > programming. I'm interested to know if anyone can share experience of > a similar situation or can point to any case studies about this. 1 Some Background ================= Early in my teaching career - 1988 -- I experienced what it means to switch from Pascal to Scheme to teach programming. And in 2002 I swtiched to using python. I may talk a bit about this but before that? 2 Some Philosophical Context ============================ Some years ago I read in a book (I think it was called "Heart of Philosophy") about the difference between 'ideas' and 'concepts.' Ideas are large vague touchy-feely things like freedom, love, justice etc; things that matter but poets deal with better than intellectuals. Concepts are the basic currency for an academic. In a typical 1-hour class you deal with a few and in a lifetime you deal with thousands; in short they are a dime a dozen -- especially if you are an academic. And yet if you have a conscience you'd know that covering the concepts specified in a formal printed syllabus is cheating. What really needs to be conveyed are a few ideas: - modular code - code invariants - abstractions - Syntax, semantics and the large grey in between which for want of a better word we may call 'structure' - Recursion much wider than people think see http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html - Interpretation see http://blog.languager.org/2013/08/applying-si-on-sicp.html - Computable and non-computable - The meaning and significance of the word 'code' - (Even more vaguely) beautiful (and ugly) code Before reading on, I suggest you think what for a while what for you are important/core ideas and then what vehicles/mediums are conducive/obstructive to them. 3 My Prejudices =============== Historically I've been associated with functional programming. While I am not so passionate about it as when I was half my age. still I'd say: - FP *as a philosophy* collects a bunch of stuff -- technology, practices, culture -- that conduces to good programming even for kids who after the course never use FP *as a technology* See http://blog.languager.org/2012/10/functional-programming-lost-booty.html - By contrast OOP is mostly (at best) clerical common sense -- organizing libraries to be easily searchable is better by data than by code. At worst OOP is hogwash -- inheritance. And so? - Python which can be quite functional, imperative and object oriented has a rather special place. Because it is object oriented you will be able to use it to silence those who are subscribed to that religion. Because it is imperative you can write straightforward code -- 'scripts' -- without undue fanfare Because it is functional (well almost -- I have some beefs in this regard) you can use it as a vehicle to actually convey important *ideas* in short space and time - For me Lisp (closely followed by APL) are the ultimate in programming paradigms. However they are not serious technology in 2013. [Even the birthplace of Scheme -- MIT -- has switched to python]. And so in 2013 python occupies a sweet spot in the sense of being academically clean and realistically usable. - That said there are some important elements of FPLs, most notably a polymorphic type discipline, that are sorely missing from python. Unfortunately Haskell is much harder to teach/learn than python and with each new addition only gets harder. So python remains even with its lacks, an academically sound language. 4 CS-Edu Writings ================= My CS-101 syllabus from the early 90s -- uses gofer a predecessor of a predecessor of Haskell http://www.the-magus.in/Publications/ip.pdf Some more general CS-Edu related writings, containing strewn about "FP is a good idea" http://blog.languager.org/2011/02/cs-education-is-fat-and-weak-1.html and following 2 posts ------ ???? ???? ["Rusi Mody" in devanagari so that GG will not use an obsolete charset] From rustompmody at gmail.com Mon Dec 9 11:57:29 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 9 Dec 2013 08:57:29 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: > 5) Learning to program "should be painful" and we should expect the > students to complain about it (someone actually said that!) but the > pain makes them better programmers in the end. Yeah this will get some people's back up -- Atrocious! Preposterous! etc Change the word 'pain' to 'taxing' 'hard' 'challenge' etc and there is much truth in it. Here is Joel Spolsky on why Java is a poor language for this reason: http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html From wrw at mac.com Mon Dec 9 12:55:41 2013 From: wrw at mac.com (William Ray Wing) Date: Mon, 09 Dec 2013 12:55:41 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: <7614A493-7472-49DC-B4D7-CC1A8636B2C2@mac.com> On Dec 9, 2013, at 11:57 AM, rusi wrote: > On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: >> 5) Learning to program "should be painful" and we should expect the >> students to complain about it (someone actually said that!) but the >> pain makes them better programmers in the end. > > Yeah this will get some people's back up -- Atrocious! Preposterous! etc > > Change the word 'pain' to 'taxing' 'hard' 'challenge' etc and there is much > truth in it. Here is Joel Spolsky on why Java is a poor language for > this reason: http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html > -- > https://mail.python.org/mailman/listinfo/python-list I'm not sure I agree with either of these points of view. Based on my own personal experience, there is an "Ah HA!" moment[*] when a student understands what it means to decompose a problem into a series of algorithmic steps - after that, the details of the particular programming language are just that, details. Some students get that quickly and intuitively and some never get there, but that bit of fundamental understanding doesn't require either pain or (necessarily) hard work - it just requires adopting a way of approaching and thinking about problems, a mind-set. -Bill ------------ * For me it came during a no-credit, no-cost, lunch-time course one of my college math teachers offered for anyone who was interested. The year was 1963, we used McCracken's FORTRAN book as our text, and tested our programs over open weekends at Argonne National Lab, where they had an IBM 1620 they opened to classes like ours a couple of times a month. From greg.ewing at canterbury.ac.nz Tue Dec 10 00:25:48 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 10 Dec 2013 18:25:48 +1300 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: > On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: > >>5) Learning to program "should be painful" and we should expect the >>students to complain about it (someone actually said that!) but the >>pain makes them better programmers in the end. That's like saying that when teaching woodwork we shouldn't let people use hammers, we should make them use rocks to bang nails in, because it will make them better carpenters in the long run. -- Greg From rosuav at gmail.com Tue Dec 10 00:55:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 16:55:32 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On Tue, Dec 10, 2013 at 4:25 PM, Gregory Ewing wrote: >> On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: >> >>> 5) Learning to program "should be painful" and we should expect the >>> students to complain about it (someone actually said that!) but the >>> pain makes them better programmers in the end. > > > That's like saying that when teaching woodwork we shouldn't > let people use hammers, we should make them use rocks to > bang nails in, because it will make them better carpenters > in the long run. But in teaching woodwork you SHOULD let people use basic tools, and not just a CNC lathe. Or in the most extreme sense, putting together IKEA furniture is not carpentry, and neither is picking from an extremely limited toolbox programming - which is why "Build a program without writing a line of code" systems are junk for anything complicated. (Occasionally, VERY occasionally, it's possible to use the simple drag-and-drop system to get you 90% of the way, and then fill in the rest yourself. Usually, you'll end up fighting the system as soon as you do something the author didn't intend.) Programming shouldn't be painful just for the sake of making it painful. But you should be programming, not just solving a Sudoku puzzle. It should be possible for a programmer to develop a unique program that does a unique thing, and if that's beyond the scope of the system, the system isn't a programming system. (Might still be a useful system, of course, but it's not programming.) ChrisA From greg.ewing at canterbury.ac.nz Tue Dec 10 16:38:57 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 11 Dec 2013 10:38:57 +1300 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: Chris Angelico wrote: > But in teaching woodwork you SHOULD let people use basic tools, and > not just a CNC lathe. > > Programming shouldn't be painful just for the sake of making it > painful. That's the only point I was trying to make. Pain in and of itself doesn't help anyone to learn anything! -- Greg From denismfmcmahon at gmail.com Tue Dec 10 21:16:18 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 11 Dec 2013 02:16:18 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On Tue, 10 Dec 2013 20:35:47 -0500, Dennis Lee Bieber wrote: > On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing > declaimed the following: >>That's like saying that when teaching woodwork we shouldn't let people >>use hammers, we should make them use rocks to bang nails in, because it >>will make them better carpenters in the long run. > NAILS???? > Nails were verboten in my high school wood working class... > We used dowels and glue; chisels to carve dove-tails; etc. We were allowed to use screws, but they had to be brass, not steel, we had to drill appropriate clearance and pilot holes, and countersink where appropriate. And god help you if you deformed the slot in a brass screw head by over tightening - I think that may have been why they made us use brass ones only, so that such damage was easier to spot and more likely to happen. And yes, I can dovetail, mortise and tenon, dowel etc etc etc. -- Denis McMahon, denismfmcmahon at gmail.com From larry.martell at gmail.com Wed Dec 11 07:08:46 2013 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 11 Dec 2013 07:08:46 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On Tue, Dec 10, 2013 at 9:16 PM, Denis McMahon wrote: > On Tue, 10 Dec 2013 20:35:47 -0500, Dennis Lee Bieber wrote: > >> On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing >> declaimed the following: > >>>That's like saying that when teaching woodwork we shouldn't let people >>>use hammers, we should make them use rocks to bang nails in, because it >>>will make them better carpenters in the long run. > >> NAILS???? >> Nails were verboten in my high school wood working class... >> We used dowels and glue; chisels to carve dove-tails; etc. > > We were allowed to use screws, but they had to be brass, not steel, we > had to drill appropriate clearance and pilot holes, and countersink where > appropriate. Ohhhh we used to DREAM of using screws! We were given steel shafts and had to tap the threads into them with our teeth. From invalid at invalid.invalid Wed Dec 11 10:05:10 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 11 Dec 2013 15:05:10 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On 2013-12-11, Dennis Lee Bieber wrote: >>That's like saying that when teaching woodwork we shouldn't >>let people use hammers, we should make them use rocks to >>bang nails in, because it will make them better carpenters >>in the long run. > > NAILS???? > > Nails were verboten in my high school wood working class... > > We used dowels and glue; chisels to carve dove-tails; etc. GLUE??? -- Grant Edwards grant.b.edwards Yow! When this load is at DONE I think I'll wash it gmail.com AGAIN ... From rantingrickjohnson at gmail.com Mon Dec 16 19:47:28 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 16 Dec 2013 16:47:28 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On Tuesday, December 10, 2013 7:35:47 PM UTC-6, Dennis Lee Bieber wrote: > NAILS???? Nails were verboten in my high school wood > working class... We used dowels and glue; chisels to carve > dove-tails; etc. That could be a result of two possibilities: 1. Your high school years were before the great war, or: 2. Your wood shop teacher was a Luddite, a sadist, or both! FYI: Fastener technology has come a long way since the fall of the of the "Amish empire". All that laborious joinery has been surpassed by mass production of helical threads and pneumatic drivers. What once took a "master craftsman" an entire day to build could now be built by a novice in mere minutes. Dovetails are nothing more than sadistic nostalgia -- they give old men a "chubby" and young men a nightmare. When are we going to realize that the goal, *ahem*, OUR GOAL, is to delegate minutiae DOWNWARDS, building the collective knowledge base layer by layer... ABSTRACTIONS people, ABSTRACTIONS!!! Because, when you've got all your mental focus attuned to carving intricate inter-meshing teeth into dense hardwoods using razor sharp hand tools, you will be unable to see the big picture, and furthermore, you might slip and cut your finger off! From roy at panix.com Mon Dec 16 20:06:06 2013 From: roy at panix.com (Roy Smith) Date: Mon, 16 Dec 2013 20:06:06 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: In article , Rick Johnson wrote: > Dovetails are nothing more than sadistic nostalgia -- > they give old men a "chubby" and young men a nightmare. There is nothing more satisfying than cutting a set of dovetails by hand and having them glide together like silk, the first time you test-fit them, with no daylight visible anywhere. Someday, mine will be like that :-) From breamoreboy at yahoo.co.uk Mon Dec 16 20:25:25 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 17 Dec 2013 01:25:25 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On 17/12/2013 01:06, Roy Smith wrote: > In article , > Rick Johnson wrote: > >> Dovetails are nothing more than sadistic nostalgia -- >> they give old men a "chubby" and young men a nightmare. > > There is nothing more satisfying than cutting a set of dovetails by hand > and having them glide together like silk, the first time you test-fit > them, with no daylight visible anywhere. > > Someday, mine will be like that :-) > I suspect that your manual skills are rather better than mine. One of my favourite expressions, perhaps because I only ever heard my dad use it, is "like watching a cow handle a shotgun". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Mon Dec 16 20:27:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Dec 2013 12:27:18 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On Tue, Dec 17, 2013 at 12:25 PM, Mark Lawrence wrote: > I suspect that your manual skills are rather better than mine. One of my > favourite expressions, perhaps because I only ever heard my dad use it, is > "like watching a cow handle a shotgun". Heh. In D&D terms, I think that would be a DEX of 5 or 6. The average for humans is 10-11, the average for adventurers is 12-13. ChrisA From gheskett at wdtv.com Mon Dec 16 20:32:07 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 16 Dec 2013 20:32:07 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <201312162032.08058.gheskett@wdtv.com> On Monday 16 December 2013 20:30:47 Mark Lawrence did opine: > On 17/12/2013 01:06, Roy Smith wrote: > > In article , > > > > Rick Johnson wrote: > >> Dovetails are nothing more than sadistic nostalgia -- > >> they give old men a "chubby" and young men a nightmare. > > > > There is nothing more satisfying than cutting a set of dovetails by > > hand and having them glide together like silk, the first time you > > test-fit them, with no daylight visible anywhere. > > > > Someday, mine will be like that :-) > > I suspect that your manual skills are rather better than mine. One of > my favourite expressions, perhaps because I only ever heard my dad use > it, is "like watching a cow handle a shotgun". I'll plead to using a jig, and figure I have a good fit when I have to drive it together with a deadblow hammer. Cheers, Gene -- "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 IBM's original motto: Cogito ergo vendo; vendo ergo sum. A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From cousinstanley at gmail.com Tue Dec 17 09:32:04 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 17 Dec 2013 07:32:04 -0700 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: >> Rick Johnson wrote: >> >> Dovetails are nothing more than sadistic nostalgia -- >> they give old men a "chubby" and young men a nightmare. > There is nothing more satisfying than cutting a set of dovetails by hand > and having them glide together like silk, the first time you test-fit > them, with no daylight visible anywhere. This dove-tailer understands Rapid Application Development .... http://woodwork.ars-informatica.ca/tool.php?art=dovetail_video Frank Klausz's three-minute dovetails using a bow saw -- Stanley C. Kitching Human Being Phoenix, Arizona --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From gheskett at wdtv.com Tue Dec 17 12:27:35 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 17 Dec 2013 12:27:35 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <201312171227.36028.gheskett@wdtv.com> On Tuesday 17 December 2013 12:23:28 Cousin Stanley did opine: > >> Rick Johnson wrote: > >> Dovetails are nothing more than sadistic nostalgia -- > >> they give old men a "chubby" and young men a nightmare. > > > > There is nothing more satisfying than cutting a set of dovetails by > > hand and having them glide together like silk, the first time you > > test-fit them, with no daylight visible anywhere. > > This dove-tailer understands Rapid Application Development .... > > http://woodwork.ars-informatica.ca/tool.php?art=dovetail_video > Frank Klausz's three-minute dovetails using a bow saw Frank is a Master, and too many people never really learn to use a bow saw. However I'd expect that joint would take more glue to fill, I've had a single drop of TB-III extrude from every edge of one of my jig made joints. But, I really think we are just a tad off topic. Cheers, Gene -- "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 UNIX is hot. It's more than hot. It's steaming. It's quicksilver lightning with a laserbeam kicker. -- Michael Jay Tucker A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From neilc at norwich.edu Wed Dec 11 10:46:28 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 11 Dec 2013 15:46:28 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <889721b4-a980-4205-9b1d-a1bedadd7eb3@googlegroups.com> Message-ID: On 2013-12-11, Dennis Lee Bieber wrote: > On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing > declaimed the following: >>> On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: >>>>5) Learning to program "should be painful" and we should >>>>expect the students to complain about it (someone actually >>>>said that!) but the pain makes them better programmers in the >>>>end. >> >>That's like saying that when teaching woodwork we shouldn't let >>people use hammers, we should make them use rocks to bang nails >>in, because it will make them better carpenters in the long >>run. > > NAILS???? > > Nails were verboten in my high school wood working class... > > We used dowels and glue; chisels to carve dove-tails; etc. ... You lucky BASTARD! We had to build bookcases out of banana leaves held together with our own spittle. -- Neil Cerutti From rhodri at wildebst.demon.co.uk Mon Dec 9 18:32:12 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 09 Dec 2013 23:32:12 -0000 Subject: Experiences/guidance on teaching Python as a first programming language References: Message-ID: On Mon, 09 Dec 2013 12:23:41 -0000, Oscar Benjamin wrote: > Some of the objections to the idea that were voiced in the meeting were > that: > 1) Some people felt that Python is not an "industry standard" unlike > C/C++/Java and that it is not as good for employability. > 2) Students should learn to program in a statically typed language > because it leads to good programming discipline. > 3) Python is too close to Matlab (which is considered essential for > some industries our students often go in to). > 4) It is better for students to be introduced to programming with a > low-level language so that they gain a better understanding of how > computers "really work". > 5) Learning to program "should be painful" and we should expect the > students to complain about it (someone actually said that!) but the > pain makes them better programmers in the end. I have taught Python as a first language to 12-15 year old kids, and for their purposes (learning how to get computers to do stuff) it was just fine. In particular, it reads easily (as long as you steer clear of funny stuff like decorators and metaclasses), so our students found it easier to explain to themselves what examples did without all the unusual (in English) punctuation getting in the way. While your students aren't 12-15 year olds, it sounds rather like what you want to give them is very similar. Unlike Computer Science students, they don't need to know how computers "really work" (except in the limited sense of floating point arithmetic, which is going to give them headaches however you introduce it). What they need is confidence in manipulating data and algorithms, and Python's a perfectly good choice for that. For contrast, my CS degree of >mumble< years antiquity threw a lot of different languages at us, usually in pairs, to illustrate different concepts. 6502 assembler showed us the basics of how a computer works, while System/370 assembler showed how horribly complex those basics can get; Pascal and BCPL contrasted rigid typing with practically non-existent typing (something Modula-2 and C didn't do nearly as well); and so on and so forth. None of this is stuff your students need for their work, so I wouldn't waste time side-tracking them with it. -- Rhodri James *-* Wildebeest Herder to the Masses From roy at panix.com Mon Dec 9 18:42:14 2013 From: roy at panix.com (Roy Smith) Date: Mon, 09 Dec 2013 18:42:14 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: Message-ID: In article , "Rhodri James" wrote: > Pascal and BCPL contrasted rigid typing with practically non-existent > typing Wow, you actually used BCPL? I didn't realize the language ever had any real use. I had only ever heard of it in the context of being a C precursor, mentioned once in an introduction of a paper and never heard from again. From rhodri at wildebst.demon.co.uk Mon Dec 9 19:00:29 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Dec 2013 00:00:29 -0000 Subject: Experiences/guidance on teaching Python as a first programming language References: Message-ID: On Mon, 09 Dec 2013 23:42:14 -0000, Roy Smith wrote: > In article , > "Rhodri James" wrote: > >> Pascal and BCPL contrasted rigid typing with practically non-existent >> typing > > Wow, you actually used BCPL? I didn't realize the language ever had any > real use. I had only ever heard of it in the context of being a C > precursor, mentioned once in an introduction of a paper and never heard > from again. It probably wasn't an accident that Martin Richards was the lecturer :-) Seriously, though, it was an excellent teaching language, and a slightly bastardized version of the compiler was readily available on the communal BBC Micros. -- Rhodri James *-* Wildebeest Herder to the Masses From feliphil at gmx.net Thu Dec 12 15:36:02 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 12 Dec 2013 21:36:02 +0100 Subject: Experiences/guidance on teaching Python as a first programming language References: Message-ID: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> > I'm particularly interested to know if anyone can share experience of > switching to teaching Python as a first programming language in a > similar context. A written up case study that I could circulate among > the relevant staff would be especially useful. Just one experience from the "other" (student's) side. When I started to study engineering science in 1991, Pascal was the "first language" at the university in question (there were no programming classes at highschool over here at that time yet). The class was quite motivating and taught me some essential basics, I think. Although issues such as object-orientation or event-based (GUI) programming were not even mentioned, which is something that I'm desperately missing today. When I went to a different university (in 1993), still in engineering science, they used C as the "first language" in the class there. The result was that I tried (and succeeded) to pass that class with the strict minimum of effort possible and deliberately forgot everything that I had to learn about C as quickly as possible afterwards. I was a "very good" student back then otherwise, so this was not due to general laziness. What that class has taught me, essentially, was to *hate* C. And it was not an issue of bad teachers. And they didn't mean to make me hate C, after all, it was them who had chosen that language. I never ever used C for anything (outside of that class). And ever after that experience, I avoided all languages that were even remotely similar to C, such as C++, Java, C#, Javascript, PHP etc. In numerics classes and for research projects, I had to learn and use Fortran, which was easy after the introduction with Pascal. The teachers who taught me Fortran easily were the same as those who made me hate C. Then, I accidentally got in touch with Python (in 1994 iirc) and thought it was interesting and useful. In fact Python is the only programming language that I ever learned without being obliged to do so. And the only one that I keep using whenever I have the choice. Since then, the university that once used C as a "first language" has switched to Python. Which is a good thing, imho. If I had had to learn the basics of programming with C instead of Pascal, I most certainly would have avoided anything even remotely connected to programming ever since, even "office automation" through scripting (which is what I use Python for today). Sincerely, Wolfgang From rosuav at gmail.com Thu Dec 12 16:12:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Dec 2013 08:12:46 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> Message-ID: On Fri, Dec 13, 2013 at 7:36 AM, Wolfgang Keller wrote: > And ever > after that experience, I avoided all languages that were even remotely > similar to C, such as C++, Java, C#, Javascript, PHP etc. I think that's disappointing, for two reasons. Firstly, C syntax isn't that terrible. You might prefer Python syntax to it, but it's undeniably better than several of its predecessors (I do not want to write in COBOL, tyvm!), and there are recent languages that manage to get some things so crazily backward (like abolishing operator precedence so 2 + 3 * 4 = 24 not 14) that I wouldn't want to use them. And secondly, C is very much the language of Unix. Sure, its best job is implementing high level languages so day-to-day code doesn't need to use it, but it's still important when you need to get to some lower-level facilities. For those two reasons, I think a basic working knowledge of C is useful for working with computers, networking, pretty much everything these days. It won't break your brain to understand multiple styles, and it might help you to remember why it is you love Python syntax so much :) Last time I had to do some C work, I was reminded just how amazingly convenient a high-level string class is... all I wanted to do was concatenate a bunch of strings with spaces between them, and I had to go through so many hoops! " ".join(list_of_strings) Et voila. ChrisA From feliphil at gmx.net Mon Dec 16 15:32:25 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Mon, 16 Dec 2013 21:32:25 +0100 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> Message-ID: <20131216213225.2006b30246e3a08ee241a191@gmx.net> > > And ever after that experience, I avoided all languages that were > > even remotely similar to C, such as C++, Java, C#, Javascript, PHP > > etc. > > I think that's disappointing, for two reasons. Firstly, C syntax isn't > that terrible. It's not just the abysmally appalling, hideously horrifying syntax. At about everything about C is just *not* "made for human beings" imho. It's just an un-language that gets at about everything wrong. Sort of like Microsoft's products. Sincerely, Wolfgang From rhodri at wildebst.org.uk Mon Dec 16 18:01:50 2013 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 16 Dec 2013 23:01:50 -0000 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: On Mon, 16 Dec 2013 20:32:25 -0000, Wolfgang Keller wrote: >> > And ever after that experience, I avoided all languages that were >> > even remotely similar to C, such as C++, Java, C#, Javascript, PHP >> > etc. >> >> I think that's disappointing, for two reasons. Firstly, C syntax isn't >> that terrible. > > It's not just the abysmally appalling, hideously horrifying syntax. At > about everything about C is just *not* "made for human beings" imho. It's an excellent macro assembler, so of course it's not made for human beings. Unfortunately the software development took one look at it and exclaimed, "It's a hammer, all our problems must be nails!" And the rest is C++. -- Rhodri James *-* Wildebeest Herder to the Masses From ned at nedbatchelder.com Mon Dec 16 19:28:12 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 16 Dec 2013 19:28:12 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <20131216213225.2006b30246e3a08ee241a191@gmx.net> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: On 12/16/13 3:32 PM, Wolfgang Keller wrote: >>> And ever after that experience, I avoided all languages that were >>> even remotely similar to C, such as C++, Java, C#, Javascript, PHP >>> etc. >> >> I think that's disappointing, for two reasons. Firstly, C syntax isn't >> that terrible. > > It's not just the abysmally appalling, hideously horrifying syntax. At > about everything about C is just *not* "made for human beings" imho. I've never heard C syntax reviled quite so intensely. What syntax do you like, out of curiosity? > > It's just an un-language that gets at about everything wrong. Sort of > like Microsoft's products. > > Sincerely, > > Wolfgang > -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Mon Dec 16 19:39:14 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 16 Dec 2013 16:39:14 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: On Tuesday, December 17, 2013 5:58:12 AM UTC+5:30, Ned Batchelder wrote: > On 12/16/13 3:32 PM, Wolfgang Keller wrote: > >>> And ever after that experience, I avoided all languages that were > >>> even remotely similar to C, such as C++, Java, C#, Javascript, PHP > >>> etc. > >> I think that's disappointing, for two reasons. Firstly, C syntax isn't > >> that terrible. > > It's not just the abysmally appalling, hideously horrifying syntax. At > > about everything about C is just *not* "made for human beings" imho. > I've never heard C syntax reviled quite so intensely. What syntax do > you like, out of curiosity? I had a paper some years ago on why C is a horrible language *to teach with* http://www.the-magus.in/Publications/chor.pdf I believe people did not get then (and still dont) that bad for - beginner education (CS101) - intermediate -- compilers, OS, DBMS etc - professional software engineering are all almost completely unrelated From rosuav at gmail.com Mon Dec 16 19:44:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Dec 2013 11:44:59 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: On Tue, Dec 17, 2013 at 11:39 AM, rusi wrote: > I had a paper some years ago on why C is a horrible language *to teach with* > http://www.the-magus.in/Publications/chor.pdf > > I believe people did not get then (and still dont) that bad for > - beginner education (CS101) > - intermediate -- compilers, OS, DBMS etc > - professional software engineering > > are all almost completely unrelated Yes. In esr's essay on becoming a hacker[1] he says: """There is perhaps a more general point here. If a language does too much for you, it may be simultaneously a good tool for production and a bad one for learning.""" Definitely true, though I think it has exceptions. [1] http://www.catb.org/esr/faqs/hacker-howto.html ChrisA From rustompmody at gmail.com Mon Dec 16 20:58:44 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 16 Dec 2013 17:58:44 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: <69ec140f-700b-4155-a5cc-5053dd7b91a3@googlegroups.com> On Tuesday, December 17, 2013 6:14:59 AM UTC+5:30, Chris Angelico wrote: > On Tue, Dec 17, 2013 at 11:39 AM, rusi wrote: > > I had a paper some years ago on why C is a horrible language *to teach with* > > http://www.the-magus.in/Publications/chor.pdf > > I believe people did not get then (and still dont) that bad for > > - beginner education (CS101) > > - intermediate -- compilers, OS, DBMS etc > > - professional software engineering > > are all almost completely unrelated > Yes. In esr's essay on becoming a hacker[1] he says: > """There is perhaps a more general point here. If a language does too > much for you, it may be simultaneously a good tool for production and > a bad one for learning.""" There is this principle by Buchberger called the "Black-box White-box principle" Unfortunately I can only find mathematicians talking about it http://www.math.rutgers.edu/~zeilberg/Opinion65.html and no CS-ists/programmers. eg To teach OS, minix is better than linux To use, linux is better FreeBSD may be a good middle point. It may also be a bad middle point -- practically too hard to use or study. Which is why in practice separating teaching tools from professional ones is better than thrashing about using the same for both > Definitely true, though I think it has exceptions. > [1] http://www.catb.org/esr/faqs/hacker-howto.html Yeah As esr says python is an exception And even here as it progresses it becomes more professional and less educational From steve+comp.lang.python at pearwood.info Mon Dec 16 21:33:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2013 02:33:11 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Dec 2013 16:39:14 -0800, rusi wrote: > I had a paper some years ago on why C is a horrible language *to teach > with* http://www.the-magus.in/Publications/chor.pdf Nice paper! I have a few quibbles with it, but overall I think it is very good. > I believe people did not get then (and still dont) that bad for - > beginner education (CS101) > - intermediate -- compilers, OS, DBMS etc - professional software > engineering > > are all almost completely unrelated I do not believe that they are "almost" unrelated. I think that, in general, there is a very high correlation between languages which are easy to use correctly and languages which are easy to learn. (Not the other way around -- languages which are easy to learn may only be so because you can't do much with them.) If your aim is to challenge yourself, as the hacker ethos often leads to, then C is an excellent language to learn because both *learning* and *using* the language is a challenge. If you just want to write a program which works correctly with as little fuss as possible, you surely wouldn't choose C unless it was the only language you knew. There are many reasons why languages fail to become popular among hackers (PHP and Flash are too d?class?, being used by *cough spit* web developers; Java is for people who wear suits and ties; Forth is, well Forth is just too weird even for hackers who like Lisp, Scheme, or Haskell). But the popular old-school hacker languages like Perl, Lisp and C have three things in common: - they grew organically, and so have little in the way of design constraints (apart from the most fundamental, which the average programmer doesn't even recognise as a constraint -- see the Blub paradox); - they are powerful and can do (nearly) anything, with sufficient hard work; - and they are challenging to use. That last one is, I believe, the key. Nothing will get hackers and programmers sneering at a language as being "a toy" or "not a real language" if it makes programming too easy, particularly if there are performance or functionality costs to such ease of use. I would really like to see good quality statistics about bugs per program written in different languages. I expect that, for all we like to make fun of COBOL, it probably has few bugs per unit-of-useful-work-done than the equivalent written in C. Of course, this is very hard to measure: different languages require different amounts of code to get something useful done. Different languages get used for different things -- there are no operating system kernels written in COBOL, although there are plenty of business apps written in C. There are vast differences in software methodologies. But I think that people intuitively grasp that if something is hard to learn, as C is, chances are very good that it is equally hard to use even for experts. Why do you think that C programs often have so many bugs and vulnerabilities, such as buffer overflows and the like? It's not just down to lousy coders. In your paper, you quote Meyer: I knew that the bulk of the student's time was spent fighting tricky pointer arithmetic, chasing memory allocation bugs, trying to figure out whether an argument was a structure or a pointer, making sure the number of asterisks was right, and so on? It's not just students who have to do all these things. They may become easier with experience, but "someone who chases memory allocation bugs" is practically the definition of a C programmer. Good C programmers are good in spite of C, not because of it. Languages like C, which lack clean design and semantics, means the programmer has to memorise a lot of special cases in order to become expert. People who would otherwise make excellent programmers except for their difficulty memorising special cases will make poor C coders -- they will always be fighting the language. Or they will learn just a small subset of the language, and always use that. If the compiler is efficient enough, as C compilers typically are, you'll never know from the performance that it was written poorly or non-idiomatically. -- Steven From rantingrickjohnson at gmail.com Mon Dec 16 23:41:14 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 16 Dec 2013 20:41:14 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <96b650e1-a721-431f-a90c-5a7281c604c0@googlegroups.com> On Monday, December 16, 2013 8:33:11 PM UTC-6, Steven D'Aprano wrote: > Of course, this is very hard to measure: different languages require > different amounts of code to get something useful done. Different > languages get used for different things -- there are no operating system > kernels written in COBOL, although there are plenty of business apps > written in C. There are vast differences in software methodologies. But I > think that people intuitively grasp that if something is hard to learn, > as C is, chances are very good that it is equally hard to use even for > experts. Why do you think that C programs often have so many bugs and > vulnerabilities, such as buffer overflows and the like? It's not just > down to lousy coders. I have a real life example of such horrendous design flaws involving a highway intersection. A while back, can't remember when, a friend of mine was involved in an accident that was his fault. This surprised me because i consider this person to be a very cautious driver. After checking records, i was amazed to find a high occurrence of traffic incidents that mirror the exact conditions of my friends accident, and in almost every incident, the person at fault runs the thru the red light. This seemed odd because how could so many people be making the same mistake? The sheer number of signal violations would exclude malevolent intentions. So being the curious chap i am, i investigated further. I myself traveled the course my friend took the day of the fateful accident. The course involves starting from a traffic signal on one side of the freeway, following a long left turn lane under the freeway, and then emerging on the other side to cross the opposing feeder road -- it is a this point that the accidents happen with great frequency! There are two distinct design flaws contributing: 1. The bridge itself is obscuring the view of the second signal. The second signal is not visible until the motorist are very close -- much too close in my opinion! But i feel #2 is the *real* contributing factor! 2. The second signal and the first signal are not synchronized, creating an inconsistency between both signals. For example, sometimes you can catch both lights green, but sometimes, the second light will change unexpectedly whilst you're navigating the long left turn, THUS requiring all traffic to stop under the freeway before crossing the opposing feeder road. ...and the results of this poor design are resulting in injuries on a regular basis!!! The problem is, sometimes people don't stop. Sometimes they simply "assume" that the light will be green because stopping under a bridge does not "feel" normal. Of course they must accept the blame for not being more alert, however, at what point does the fallibility of humans excuse poor interface design? Humans are by nature INCAPABLE of maintaining perfect alertness, and driving requires more processing than the human mind can possibly muster. Your mind is constantly attempting to "predict the future" outcome of current events, and it is this unconsciousness mechanism that, when overloaded, will force the less acute modality of intuition to propagate up and take full control. It is for that very reason that we must design interfaces with the fallibility of human operators in mind -- at least until we can remove the human from the equation. We MUST strive to achieve the highest level of intuitiveness whilst eliminating any and all inconsistencies from the system. From neilc at norwich.edu Tue Dec 17 09:51:39 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 17 Dec 2013 14:51:39 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-12-17, Steven D'Aprano wrote: > I would really like to see good quality statistics about bugs > per program written in different languages. I expect that, for > all we like to make fun of COBOL, it probably has few bugs per > unit-of-useful-work-done than the equivalent written in C. I can't think of a reference, but I to recall that bugs-per-line-of-code is nearly constant; it is not language dependent. So, unscientifically, the more work you can get done in a line of code, then the fewer bugs you'll have per amount of work done. -- Neil Cerutti From roy at panix.com Tue Dec 17 09:54:41 2013 From: roy at panix.com (Roy Smith) Date: Tue, 17 Dec 2013 09:54:41 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Neil Cerutti wrote: > On 2013-12-17, Steven D'Aprano > wrote: > > I would really like to see good quality statistics about bugs > > per program written in different languages. I expect that, for > > all we like to make fun of COBOL, it probably has few bugs per > > unit-of-useful-work-done than the equivalent written in C. Well, there was that little Y2K thing... From breamoreboy at yahoo.co.uk Tue Dec 17 10:07:47 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 17 Dec 2013 15:07:47 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 17/12/2013 14:54, Roy Smith wrote: > In article , > Neil Cerutti wrote: > >> On 2013-12-17, Steven D'Aprano >> wrote: >>> I would really like to see good quality statistics about bugs >>> per program written in different languages. I expect that, for >>> all we like to make fun of COBOL, it probably has few bugs per >>> unit-of-useful-work-done than the equivalent written in C. > > Well, there was that little Y2K thing... > Design assumption made 30 to 40 years earlier "It'll only have to be in the field for six months" :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Tue Dec 17 10:24:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2013 15:24:25 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b06ca9$0$29976$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 Dec 2013 09:54:41 -0500, Roy Smith wrote: > In article , > Neil Cerutti wrote: > >> On 2013-12-17, Steven D'Aprano >> wrote: >> > I would really like to see good quality statistics about bugs per >> > program written in different languages. I expect that, for all we >> > like to make fun of COBOL, it probably has few bugs per >> > unit-of-useful-work-done than the equivalent written in C. > > Well, there was that little Y2K thing... Oh come on, how were people in the 1990s supposed to predict that they would be followed by the year 2000??? That's a good point, but that wasn't a language issue, it was a program design issue. Back in the 70s and 80s, when saving two digits per date field seemed to be a sensible thing to do, people simply didn't imagine that their programs would still be used in the year 1999[1]. That's not the same sort of bug as (say) C buffer overflows, or SQL code injection attacks. It's not like the COBOL language defined dates as having only two digits. [1] What gets me is that even in the year 1999, there were still programmers writing code that assumed two-digit years. I have it on good authority from somebody working as an external consultant for a bank in 1999 that he spent most of 1998 and 1999 fixing *brand new code* written by the bank's own staff. You'd think that having lived through that experience would have shaken his belief that private enterprise does everything better, and the bigger the corporation the better they do it, but apparently not. Go figure. -- Steven From breamoreboy at yahoo.co.uk Tue Dec 17 10:35:27 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 17 Dec 2013 15:35:27 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b06ca9$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> <52b06ca9$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 17/12/2013 15:24, Steven D'Aprano wrote: > On Tue, 17 Dec 2013 09:54:41 -0500, Roy Smith wrote: > >> In article , >> Neil Cerutti wrote: >> >>> On 2013-12-17, Steven D'Aprano >>> wrote: >>>> I would really like to see good quality statistics about bugs per >>>> program written in different languages. I expect that, for all we >>>> like to make fun of COBOL, it probably has few bugs per >>>> unit-of-useful-work-done than the equivalent written in C. >> >> Well, there was that little Y2K thing... > > Oh come on, how were people in the 1990s supposed to predict that they > would be followed by the year 2000??? > > That's a good point, but that wasn't a language issue, it was a program > design issue. Back in the 70s and 80s, when saving two digits per date > field seemed to be a sensible thing to do, people simply didn't imagine > that their programs would still be used in the year 1999[1]. That's not > the same sort of bug as (say) C buffer overflows, or SQL code injection > attacks. It's not like the COBOL language defined dates as having only > two digits. > > > > > [1] What gets me is that even in the year 1999, there were still > programmers writing code that assumed two-digit years. I have it on good > authority from somebody working as an external consultant for a bank in > 1999 that he spent most of 1998 and 1999 fixing *brand new code* written > by the bank's own staff. You'd think that having lived through that > experience would have shaken his belief that private enterprise does > everything better, and the bigger the corporation the better they do it, > but apparently not. Go figure. > > I was in charge of the team at work that had to make all code Y2K compliant. I discovered the one bug that to my knowledge slipped through the net. Four years later back at the same place on contract I fixed the fix!!! -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From larry.martell at gmail.com Tue Dec 17 11:21:07 2013 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 17 Dec 2013 11:21:07 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> <52b06ca9$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Dec 17, 2013 at 10:35 AM, Mark Lawrence wrote: > I was in charge of the team at work that had to make all code Y2K compliant. > I discovered the one bug that to my knowledge slipped through the net. Four > years later back at the same place on contract I fixed the fix!!! >From around 1997 till 2000 all I did was fix Y2K bugs. I'm pretty sure I got them all. For one client I fixed well over 200. After the new year came and nothing broke, the owner of the company said "You made such a big deal about this Y2K stuff, and it turned out not to be a problem at all." From rustompmody at gmail.com Tue Dec 17 11:56:32 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 17 Dec 2013 08:56:32 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> <52b06ca9$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3d9493f0-f80b-44de-9682-18a52c314167@googlegroups.com> On Tuesday, December 17, 2013 9:51:07 PM UTC+5:30, Larry.... at gmail.com wrote: > On Tue, Dec 17, 2013 at 10:35 AM, Mark Lawrence wrote: > > I was in charge of the team at work that had to make all code Y2K compliant. > > I discovered the one bug that to my knowledge slipped through the net. Four > > years later back at the same place on contract I fixed the fix!!! > > From around 1997 till 2000 all I did was fix Y2K bugs. I'm pretty > > sure I got them all. For one client I fixed well over 200. After > > the new > year came and nothing broke, the owner of the company > > said "You made > such a big deal about this Y2K stuff, and it > > turned out not to be a > problem at all." Hahaha -- Very funny and serious. Ive been actually experienced being kicked out of job for writing decent working code and not making a big deal of it. Comes back the start of the thread -- What do we teach students? Should we teach how to write the best possible code and as effortlessly as possible? Or should we also teach how to make a fuss, how to pretend to (over)work while actually (under)delivering? In a Utopia this would not be a question at all. But we dont live in Utopia... [And there are languages WAY better than C... C++ for example] From rustompmody at gmail.com Tue Dec 17 13:03:08 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 17 Dec 2013 10:03:08 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2733a35e-a9c9-44c2-a29c-1d8c252c2159@googlegroups.com> On Tuesday, December 17, 2013 8:21:39 PM UTC+5:30, Neil Cerutti wrote: > On 2013-12-17, Steven D'Aprano wrote: > > I would really like to see good quality statistics about bugs > > per program written in different languages. I expect that, for > > all we like to make fun of COBOL, it probably has few bugs per > > unit-of-useful-work-done than the equivalent written in C. > I can't think of a reference, but I to recall that > bugs-per-line-of-code is nearly constant; it is not language > dependent. So, unscientifically, the more work you can get done > in a line of code, then the fewer bugs you'll have per amount of > work done. Enter the (One-Liner) Dragon! http://www.youtube.com/watch?v=a9xAKttWgP4 From rosuav at gmail.com Tue Dec 17 13:20:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Dec 2013 05:20:40 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <2733a35e-a9c9-44c2-a29c-1d8c252c2159@googlegroups.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> <2733a35e-a9c9-44c2-a29c-1d8c252c2159@googlegroups.com> Message-ID: On Wed, Dec 18, 2013 at 5:03 AM, rusi wrote: > On Tuesday, December 17, 2013 8:21:39 PM UTC+5:30, Neil Cerutti wrote: >> I can't think of a reference, but I to recall that >> bugs-per-line-of-code is nearly constant; it is not language >> dependent. So, unscientifically, the more work you can get done >> in a line of code, then the fewer bugs you'll have per amount of >> work done. > > Enter the (One-Liner) Dragon! > > http://www.youtube.com/watch?v=a9xAKttWgP4 Some languages work differently with lines, cramming more onto a single line while still having more "code". What's nearly constant is bugs per "amount of code", except that it's practically impossible to measure how much code you've produced. So there are a few exceptions to the "lines of code" metric, a few languages that jump around a bit on the scale. ChrisA From joel.goldstick at gmail.com Tue Dec 17 13:39:23 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 17 Dec 2013 13:39:23 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> <2733a35e-a9c9-44c2-a29c-1d8c252c2159@googlegroups.com> Message-ID: On Tue, Dec 17, 2013 at 1:20 PM, Chris Angelico wrote: > On Wed, Dec 18, 2013 at 5:03 AM, rusi wrote: > > On Tuesday, December 17, 2013 8:21:39 PM UTC+5:30, Neil Cerutti wrote: > >> I can't think of a reference, but I to recall that > >> bugs-per-line-of-code is nearly constant; it is not language > >> dependent. So, unscientifically, the more work you can get done > >> in a line of code, then the fewer bugs you'll have per amount of > >> work done. > > > If its true that bugs per line of code is more or less a constant, I think the key is that some languages are more expressive than others. So, in assembler, you are moving data around registers, and doing basic math, etc. It takes a lot of code to get something done. So maybe more bugs. Moving up the ladder to C, which is in a way high level assembly language, you get more done in few lines. Python or other languages maybe do more per line than C (eg the for loop in python does a lot with very little code because of python having iterable stuff built in) So, if you have a language that is expressive and fits your programming needs, you will have less to debug -- not because you don't make as many errors, but the good code just does more for you -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Dec 17 06:12:07 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Dec 2013 11:12:07 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: On 17 December 2013 00:39, rusi wrote: > On Tuesday, December 17, 2013 5:58:12 AM UTC+5:30, Ned Batchelder wrote: >> On 12/16/13 3:32 PM, Wolfgang Keller wrote: >> >>> And ever after that experience, I avoided all languages that were >> >>> even remotely similar to C, such as C++, Java, C#, Javascript, PHP >> >>> etc. Thanks for sharing your experiences Wolfgang. I think many of my students have a similar experience after learning C and it is interesting to hear it from your perspective many years later. I was also taught C as an undergrad but having already learned Java, C and C++ before arriving at University I found the C course very easy so my own experience is not representative. Many of the other students at that time found the course too hard and just cheated on all the assignments (I remember one students offering to fix/finish anyone's assignment in exchange for a bottle of cider!). >> >> I think that's disappointing, for two reasons. Firstly, C syntax isn't >> >> that terrible. >> >> > It's not just the abysmally appalling, hideously horrifying syntax. At >> > about everything about C is just *not* "made for human beings" imho. > >> I've never heard C syntax reviled quite so intensely. What syntax do >> you like, out of curiosity? > > I had a paper some years ago on why C is a horrible language *to teach with* > http://www.the-magus.in/Publications/chor.pdf Thanks for this Rusi, I just read it and it describes very well what I think about our own C course. My choice quote from the beginning would be "When the irrelevant becomes significant, the essentials become obscured and incomprehensible." (BTW is there any reason that the document is repeated twice in the same pdf?) As a case in point one of my tutees asked for help with his C assignment last week. I looked at his code and it was a complete mess. I explained roughly what it should look like and he explained that he had had so much trouble figuring out how to get the compiler to pass a pair of strings into a function that he had given up and used global variables instead. He's just not ready yet to get an intuitive understanding of where to put the asterisks in order to make it work - and as you point out in that paper the rules for where the asterisks go are hopelessly inconsistent. A couple of weeks before, another of my tutees brought their assignment which was about dynamic memory allocation (~7 weeks into her first programming course). She had just written something like char *x = (char*)malloc(31*sizeof(char)); for a global x at the top of the file. So the message about dynamic memory allocation was entirely lost in the details of C: "dynamic memory allocation means using malloc". These types of problems are compounded by the fact that the current C course uses automated marking so a program that produces the correct output gets full marks even if it is terribly written and the student entirely misses the point - another thing about this course that definitely needs to change. > I believe people did not get then (and still dont) that bad for > - beginner education (CS101) > - intermediate -- compilers, OS, DBMS etc > - professional software engineering > > are all almost completely unrelated Agreed. Oscar From rosuav at gmail.com Tue Dec 17 09:10:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Dec 2013 01:10:22 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: On Tue, Dec 17, 2013 at 10:12 PM, Oscar Benjamin wrote: > I was also taught C as an undergrad but having already learned Java, C > and C++ before arriving at University I found the C course very easy > so my own experience is not representative. Many of the other students > at that time found the course too hard and just cheated on all the > assignments (I remember one students offering to fix/finish anyone's > assignment in exchange for a bottle of cider!). Student cheats on assignment and gets, in effect, a fraudulent certification. (Piece of paper claims competence, competence doesn't exist.) Graduating student shows certification to employer. Employer hires ex-student, because employer doesn't know good code from bad (hence hiring someone). Ex-student writes a pile of junk, then leaves for a better opportunity. Real programmer is hired, or seconded from another project, to fix a few small issues in ex-student's code. Lunatic asylum gains another patient. It's all too common. I'd like to tell people that they're only cheating themselves, but the trouble is, they're cheating other people a lot more. ChrisA From steve+comp.lang.python at pearwood.info Tue Dec 17 07:18:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2013 12:18:10 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: <52b04102$0$29976$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 Dec 2013 11:12:07 +0000, Oscar Benjamin wrote: > These types of problems are compounded by the fact that the current C > course uses automated marking so a program that produces the correct > output gets full marks even if it is terribly written and the student > entirely misses the point This suggests that even the lecturers can't read C, and so have got one of their post-grad students to write an automated tester so they don't have to. Only-half-joking-ly y'rs, -- Steven From feliphil at gmx.net Tue Dec 17 10:51:44 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 17 Dec 2013 16:51:44 +0100 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> > I was also taught C as an undergrad but having already learned Java, C > and C++ before arriving at University I found the C course very easy > so my own experience is not representative. Many of the other students > at that time found the course too hard and just cheated on all the > assignments (I remember one students offering to fix/finish anyone's > assignment in exchange for a bottle of cider!). The problem with the C class wasn't that it was "hard". I had passed my Pascal class, which taught nearly exactly the same issues with "straight A"s before (without ever having writeen any source code ever before). And by standard cognitive testing standards, I'm not exactly considered to be an idiot. The only issue for me was to figure out how to do in C what I already knew in Pascal. And I had to waste a *lot* more time and mental effort to mess with that language than it took for me to learn *both* the basics of programming per se *and* Pascal in the first class at my home university. C is just a kafkaesque mess invented by a sadistic pervert who must have regularly consumed illegal substances for breakfast. Its only reason to exist seems to be that apparently it's ridiculously easy to implement a "compiler" for it. Although, as a professional developer once told me, most C compilers are garbage. One student in the C class (who had been doing software development for years before he came to university) jokingly passed around samples of "valid" C code by email. Most of them looked like uuencoded binaries (this was in the early-to-mid 90s), but they all compiled and produced an output. Except that *no one* (including professors) was able to predict the output without actually running the compiled code. In the classroom lectures parallel to the C exercises, the professor spent most of his time explaining what *not* to do because... Heck, why does a language provide features resp. allow their use in ways that are known to be bottomless cans of worms. > These types of problems are compounded by the fact that the current C > course uses automated marking so a program that produces the correct > output gets full marks even if it is terribly written and the student > entirely misses the point - another thing about this course that > definitely needs to change. In our classes, when a program was correct, but e.g. you used just *one* single non-semantic identifier (such as an "i" for a loop index), you got *automatically* zero points for that exercise. Other absolutely mandatory requirements were about minimum commenting etc. Less comment lines than code was very likely to yield zero points for that exercise as well. Sincerely, Wolfgang From invalid at invalid.invalid Tue Dec 17 11:59:01 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 17 Dec 2013 16:59:01 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 2013-12-17, Wolfgang Keller wrote: >> I was also taught C as an undergrad but having already learned Java, C >> and C++ before arriving at University I found the C course very easy >> so my own experience is not representative. Many of the other students >> at that time found the course too hard and just cheated on all the >> assignments (I remember one students offering to fix/finish anyone's >> assignment in exchange for a bottle of cider!). > > The problem with the C class wasn't that it was "hard". I had passed my > Pascal class, which taught nearly exactly the same issues with > "straight A"s before (without ever having writeen any source code ever > before). And by standard cognitive testing standards, I'm not exactly > considered to be an idiot. I agree that C is a awful pedagogical language. When I was in university, the first language for Computer Science or Computer Engineering students was Pascal. After that, there were classes that surveyed Prolog, SNOBOL, LISP, Modula, APL, FORTRAN, COBOL, etc. If you were an "other" engineering/science major, you learned FORTRAN first (and last). I think there may also have been some business types who were taught BASIC. C wasn't taught at all. When I graduated and started doing real-time embedded firmware, the choices were Generally C or Pascal. The first projects I did were in Pascal, but I learned C because the development host was a PDP-11 running Unix and I needed to write some small (non embedded) utilities. Today, all my embedded work is in C. Python fell out of style for some reason, but (with a few extensions) it was a fine language for embedded work as well. I've always thought C was a great language for low-level, bare-metal, embedded stuff -- but teaching it to first or second year computer science students is just insane. C has a certain minimalist orthogonality that I have always found pleasing. [People who smile wistfully when they think about the PDP-11 instruction word layouts probably know what I mean.] But, exposure to C should wait until you have a firm grasp of basic algorithms and data structures and are proficient in assembly language for a couple different architectures. Ideally, you should also have written at least one functioning compiler before learning C as well. -- Grant Edwards grant.b.edwards Yow! Maybe we could paint at GOLDIE HAWN a rich PRUSSIAN gmail.com BLUE -- From larry.martell at gmail.com Tue Dec 17 12:18:13 2013 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 17 Dec 2013 12:18:13 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Tue, Dec 17, 2013 at 11:59 AM, Grant Edwards wrote: > On 2013-12-17, Wolfgang Keller wrote: > >>> I was also taught C as an undergrad but having already learned Java, C >>> and C++ before arriving at University I found the C course very easy >>> so my own experience is not representative. Many of the other students >>> at that time found the course too hard and just cheated on all the >>> assignments (I remember one students offering to fix/finish anyone's >>> assignment in exchange for a bottle of cider!). I did that, but my fee was a case of beer. >> >> The problem with the C class wasn't that it was "hard". I had passed my >> Pascal class, which taught nearly exactly the same issues with >> "straight A"s before (without ever having writeen any source code ever >> before). And by standard cognitive testing standards, I'm not exactly >> considered to be an idiot. > > I agree that C is a awful pedagogical language. When I was in > university, the first language for Computer Science or Computer > Engineering students was Pascal. After that, there were classes that > surveyed Prolog, SNOBOL, LISP, Modula, APL, FORTRAN, COBOL, etc. If > you were an "other" engineering/science major, you learned FORTRAN > first (and last). I think there may also have been some business > types who were taught BASIC. > > C wasn't taught at all. It wasn't for me either when I went to college in the late 1970's. Pascal first, then FORTRAN, then IBM 360 assembler. That was all the formal language training I had. (I had taught myself BASIC in high school.) From breamoreboy at yahoo.co.uk Tue Dec 17 12:24:32 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 17 Dec 2013 17:24:32 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 17/12/2013 17:18, Larry Martell wrote: > On Tue, Dec 17, 2013 at 11:59 AM, Grant Edwards wrote: >> On 2013-12-17, Wolfgang Keller wrote: >> >>>> I was also taught C as an undergrad but having already learned Java, C >>>> and C++ before arriving at University I found the C course very easy >>>> so my own experience is not representative. Many of the other students >>>> at that time found the course too hard and just cheated on all the >>>> assignments (I remember one students offering to fix/finish anyone's >>>> assignment in exchange for a bottle of cider!). > > I did that, but my fee was a case of beer. > Pay bottle get monkey? -- 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 Tue Dec 17 12:44:55 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 17 Dec 2013 17:44:55 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 17/12/2013 16:59, Grant Edwards wrote: > > I've always thought C was a great language for low-level, bare-metal, > embedded stuff -- but teaching it to first or second year computer > science students is just insane. C has a certain minimalist > orthogonality that I have always found pleasing. [People who smile > wistfully when they think about the PDP-11 instruction word layouts > probably know what I mean.] I agree with you here, but wasn't there a tie-in between C and the rise of Unix via universities, or am I barking in the wrong forest? > > But, exposure to C should wait until you have a firm grasp of basic > algorithms and data structures and are proficient in assembly language > for a couple different architectures. Ideally, you should also have > written at least one functioning compiler before learning C as well. > I never had a problem with C as I'd written assembler for RCA 1802, Ferranti F110L and DEC/VAX, plus CORAL 66. Hum, a bit of a fib there, I recall vainly struggling with a C for loop before I finally realised I'd effectively written a CORAL 66 one, page 50 here http://www.xgc.com/manuals/pdf/xgc-c66-rm.pdf for (ouch!!!) anyone who's interested. Using a Whitesmith's pre-ANSI C compiler didn't exactly help me either. IIRC printf was spelt format and all the formatting codes were different to what became standard C. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From invalid at invalid.invalid Tue Dec 17 14:38:27 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 17 Dec 2013 19:38:27 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 2013-12-17, Mark Lawrence wrote: > On 17/12/2013 16:59, Grant Edwards wrote: >> >> I've always thought C was a great language for low-level, bare-metal, >> embedded stuff -- but teaching it to first or second year computer >> science students is just insane. C has a certain minimalist >> orthogonality that I have always found pleasing. [People who smile >> wistfully when they think about the PDP-11 instruction word layouts >> probably know what I mean.] > > I agree with you here, but wasn't there a tie-in between C and the rise > of Unix via universities, or am I barking in the wrong forest? Yes, I think the popularity of Unix on university campuses is what caused the migration from Pascal to C for freshman programming classes. IIRC, there were decent Pascal compilers for Unix back then, so I still think it was a big mistake. Later on when studying low level OS stuff would have been a fine time to introduce C if required for logistical reasons. -- Grant Edwards grant.b.edwards Yow! Vote for ME -- I'm at well-tapered, half-cocked, gmail.com ill-conceived and TAX-DEFERRED! From roy at panix.com Tue Dec 17 19:39:29 2013 From: roy at panix.com (Roy Smith) Date: Tue, 17 Dec 2013 19:39:29 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: In article , Grant Edwards wrote: > Ideally, you should also have written at least one functioning > compiler before learning C as well. Why? I've never written a compiler. I've written plenty of C. I don't see how my lack of compiler writing experience has hindered my ability to write C. From invalid at invalid.invalid Wed Dec 18 13:05:01 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 18 Dec 2013 18:05:01 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 2013-12-18, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> Ideally, you should also have written at least one functioning >> compiler before learning C as well. > > Why? I've never written a compiler. I've written plenty of C. I don't > see how my lack of compiler writing experience has hindered my ability > to write C. I've always felt that there are features in C that don't make a lot of sense until you've actually implemented a compiler -- at which point it becomes a lot more obvious why some thing are done certain ways. Maybe that's just me. I had written a compiler before I learned C, and there were things that made perfect sense to me that seemed to confuse others I worked with who were learning C at the same time. -- Grant Edwards grant.b.edwards Yow! It's a hole all the at way to downtown Burbank! gmail.com From breamoreboy at yahoo.co.uk Wed Dec 18 13:17:56 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 18 Dec 2013 18:17:56 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 18/12/2013 18:05, Grant Edwards wrote: > On 2013-12-18, Roy Smith wrote: >> In article , >> Grant Edwards wrote: >> >>> Ideally, you should also have written at least one functioning >>> compiler before learning C as well. >> >> Why? I've never written a compiler. I've written plenty of C. I don't >> see how my lack of compiler writing experience has hindered my ability >> to write C. > > I've always felt that there are features in C that don't make a lot of > sense until you've actually implemented a compiler -- at which point > it becomes a lot more obvious why some thing are done certain ways. > > Maybe that's just me. I had written a compiler before I learned C, and > there were things that made perfect sense to me that seemed to confuse > others I worked with who were learning C at the same time. > I've never contemplated writing a compiler, let alone actually written one. It's like the comments along the lines of "you can't call yourself a programmer until you've mastered regular expressions". Some of my mates who work on air traffic management systems have maybe never heard of a regex but who cares, I certainly don't. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Wed Dec 18 20:40:53 2013 From: roy at panix.com (Roy Smith) Date: Wed, 18 Dec 2013 20:40:53 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: In article , Grant Edwards wrote: > On 2013-12-18, Roy Smith wrote: > > In article , > > Grant Edwards wrote: > > > >> Ideally, you should also have written at least one functioning > >> compiler before learning C as well. > > > > Why? I've never written a compiler. I've written plenty of C. I don't > > see how my lack of compiler writing experience has hindered my ability > > to write C. > > I've always felt that there are features in C that don't make a lot of > sense until you've actually implemented a compiler -- at which point > it becomes a lot more obvious why some thing are done certain ways. Example? I suspect what you mean is, "There are some things that don't make sense until you understand computer architecture". From rustompmody at gmail.com Wed Dec 18 23:05:28 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 18 Dec 2013 20:05:28 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: <07c6e6a3-c5f4-4846-9551-434bdaba8b50@googlegroups.com> On Thursday, December 19, 2013 7:10:53 AM UTC+5:30, Roy Smith wrote: > Grant Edwards wrote: > > I've always felt that there are features in C that don't make a lot of > > sense until you've actually implemented a compiler -- at which point > > it becomes a lot more obvious why some thing are done certain ways. > Example? > I suspect what you mean is, "There are some things that don't make sense > until you understand computer architecture". One way of rephrasing what Grant is saying is: "You cannot be a C programmer without being a system programmer" This certainly includes machine (hardware) architecture. But it includes much else besides, which can generally be subsumed under the rubric "toolchain" A python programmer can write foo.py and run: $ python foo.py A C programmer writes foo.c and has to run the sequence: $ gcc foo.c $ a.out So far the difference looks minimal. However it does not stop here. Soon the foo has to split into foo1.c and foo2.c. And suddenly you need to understand: 1. Separate compilation 2. Make (which is separate from 'separate compilation') 3. Header files and libraries and the connection and difference Now if youve taught a few classes you will know what a hell each of these is. In particular, every C teacher struggles with: "stdio.h is the standard library" And all this has not yet touched the labyrinths of linker errors with the corresponding magic spells called ranlib, nm etc Got past all this kid-stuff? Now for the Great Initiation into Manhood -- autoconf So... Is all this core computer science? Or is it the curiosities of 40 year old technology? From roy at panix.com Wed Dec 18 23:16:26 2013 From: roy at panix.com (Roy Smith) Date: Wed, 18 Dec 2013 23:16:26 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <07c6e6a3-c5f4-4846-9551-434bdaba8b50@googlegroups.com> Message-ID: In article <07c6e6a3-c5f4-4846-9551-434bdaba8b50 at googlegroups.com>, rusi wrote: > Soon the foo has to split into foo1.c and foo2.c. And suddenly you need to > understand: > > 1. Separate compilation > 2. Make (which is separate from 'separate compilation') > 3. Header files and libraries and the connection and difference None of that is specific to C. Virtually any language (including Python) allows a program to be split up into multiple source files. If you're running all but the most trivial example, you need to know how to manage these multiple files and how the pieces interact. It's pretty common here to have people ask questions about how import works. How altering sys.path effects import. Why is import not finding my module? You quickly get into things like virtualenv, and now you've got modules coming from your source tree, from your vitualenv, from your system library. You need to understand all of that to make it all work. From rosuav at gmail.com Wed Dec 18 23:26:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Dec 2013 15:26:34 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <07c6e6a3-c5f4-4846-9551-434bdaba8b50@googlegroups.com> Message-ID: On Thu, Dec 19, 2013 at 3:16 PM, Roy Smith wrote: > It's pretty common here to have people ask questions about how import > works. How altering sys.path effects import. Why is import not finding > my module? You quickly get into things like virtualenv, and now you've > got modules coming from your source tree, from your vitualenv, from your > system library. You need to understand all of that to make it all work. Python might one day want to separate "system paths" from "local paths", to give the same effect as: #include #include "local_config.h" where the current directory won't be searched for stdio.h. But other than that, it's exactly the same consideration in either Python or C. ChrisA From rustompmody at gmail.com Wed Dec 18 23:48:18 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 18 Dec 2013 20:48:18 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <07c6e6a3-c5f4-4846-9551-434bdaba8b50@googlegroups.com> Message-ID: On Thursday, December 19, 2013 9:46:26 AM UTC+5:30, Roy Smith wrote: > rusi wrote: > > Soon the foo has to split into foo1.c and foo2.c. And suddenly you need to > > understand: > > 1. Separate compilation > > 2. Make (which is separate from 'separate compilation') > > 3. Header files and libraries and the connection and difference > It's pretty common here to have people ask questions about how import > works. How altering sys.path effects import. Why is import not finding > my module? You quickly get into things like virtualenv, and now you've > got modules coming from your source tree, from your vitualenv, from your > system library. You need to understand all of that to make it all work. Yes agreed. Python is far from stellar in this regard. Just as distutils got into the core at 2.3(??) now at 3.3 virtualenv(+pip+wheel) is getting in. Belated but better late than never. > None of that is specific to C. Virtually any language (including > Python) allows a program to be split up into multiple source files. If > you're running all but the most trivial example, you need to know how to > manage these multiple files and how the pieces interact. Thats a strange thing to say. In the abstract every language that allows for significant programs supports separate units/modules. Somewhere those units will map onto system entities -- usually though not always files (think of PL-SQL inside Oracle). Even assuming files, the lines drawn between interior (to the language) and exterior (OS-facing) are vastly different. C, Pascal, Python, Java, SML, APL -- all very different in this regard. From rustompmody at gmail.com Thu Dec 19 12:14:52 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 19 Dec 2013 09:14:52 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <07c6e6a3-c5f4-4846-9551-434bdaba8b50@googlegroups.com> Message-ID: <211cfe7d-b5b6-4c06-9e31-295864503d4c@googlegroups.com> > On Thursday, December 19, 2013 9:46:26 AM UTC+5:30, Roy Smith wrote: > > rusi wrote: > > > Soon the foo has to split into foo1.c and foo2.c. And suddenly you need to > > > understand: > > > 1. Separate compilation > > > 2. Make (which is separate from 'separate compilation') > > > 3. Header files and libraries and the connection and difference > > It's pretty common here to have people ask questions about how import > > works. How altering sys.path effects import. Why is import not finding > > my module? You quickly get into things like virtualenv, and now you've > > got modules coming from your source tree, from your vitualenv, from your > > system library. You need to understand all of that to make it all work. > Yes agreed. Python is far from stellar in this regard. > Just as distutils got into the core at 2.3(??) now at 3.3 virtualenv(+pip+wheel) > is getting in. Belated but better late than never. > > None of that is specific to C. Virtually any language (including > > Python) allows a program to be split up into multiple source files. If > > you're running all but the most trivial example, you need to know how to > > manage these multiple files and how the pieces interact. > Thats a strange thing to say. In the abstract every language that > allows for significant programs supports separate units/modules. > Somewhere those units will map onto system entities -- usually though > not always files (think of PL-SQL inside Oracle). > Even assuming files, the lines drawn between interior (to the language) > and exterior (OS-facing) are vastly different. > C, Pascal, Python, Java, SML, APL -- all very different in this regard. Just adding this: Different languages do their modularizing and packaging differently (what I earlier said) in order to achieve different tradeoffs. Here's a thread by a competent programmer who switched from Lisp to C++. https://groups.google.com/forum/#!topic/ledger-cli/Mjky9AvrRKU He clearly says that while he loves Lisp the language, its packaging facilities lost out to C++ and so he rewrote his whole app in C++. From dihedral88888 at gmail.com Thu Dec 19 01:03:33 2013 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Wed, 18 Dec 2013 22:03:33 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <07c6e6a3-c5f4-4846-9551-434bdaba8b50@googlegroups.com> Message-ID: Roy Smith? 2013?12?19????UTC+8??12?16?26???? > In article <07c6e6a3-c5f4-4846-9551-434bdaba8b50 at googlegroups.com>, > > rusi wrote: > > > > > Soon the foo has to split into foo1.c and foo2.c. And suddenly you need to > > > understand: > > > > > > 1. Separate compilation > > > 2. Make (which is separate from 'separate compilation') > > > 3. Header files and libraries and the connection and difference > > > > None of that is specific to C. Virtually any language (including > > Python) allows a program to be split up into multiple source files. If > > you're running all but the most trivial example, you need to know how to > > manage these multiple files and how the pieces interact. > > > > It's pretty common here to have people ask questions about how import > > works. How altering sys.path effects import. Why is import not finding > > my module? You quickly get into things like virtualenv, and now you've > > got modules coming from your source tree, from your vitualenv, from your > > system library. You need to understand all of that to make it all work. OK, just any novice can take the BOA and WXPYTHON packages to implement an editor in 1 to 3 hours, but that is trivial in Delphi and object pascal long time ago. The GUI to python scrit generation engine is the smarter way to let the mass interested in programming. From greg.ewing at canterbury.ac.nz Thu Dec 19 01:40:05 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 19 Dec 2013 19:40:05 +1300 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: Roy Smith wrote: > I suspect what you mean is, "There are some things that don't make sense > until you understand computer architecture". An example of that kind of thing from a different perspective: I learned Z80 assembly language by first learning Z80 *machine* language (my homebrew computer didn't have an assembler, so I had to write my own and hand assemble it (after writing my own DOS (after building my own disk controller... etc!))). If you just look at the Z80 architecture at the assembly language level, the rules for which instructions go with which registers and which addressing modes seem very haphazard. But because I knew how the instructions were encoded, I never had any trouble remembering the allowable combinations. If it didn't have an encoding, you couldn't do it! -- Greg From roy at panix.com Wed Dec 18 20:49:10 2013 From: roy at panix.com (Roy Smith) Date: Wed, 18 Dec 2013 20:49:10 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: In article , Mark Lawrence wrote: > I've never contemplated writing a compiler, let alone actually written > one. It's like the comments along the lines of "you can't call yourself > a programmer until you've mastered regular expressions". Who makes comments like that? As far as I can tell, I'm the resident regexphile on this newsgroup, and I certainly don't say that. I find it frustrating that Pythonistas shy away from regex as much as they do. Yes, Python strings have a rich set of built-in operations which provide easy ways to do a lot of things traditionally done with regexes in other languages. Regex is a powerful tool, and programmers will improve their skill set by knowing how to use them. But that's not the same as saying you can't be a programmer if you don't know regex. From breamoreboy at yahoo.co.uk Wed Dec 18 21:05:55 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 19 Dec 2013 02:05:55 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 19/12/2013 01:49, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> I've never contemplated writing a compiler, let alone actually written >> one. It's like the comments along the lines of "you can't call yourself >> a programmer until you've mastered regular expressions". > > Who makes comments like that? As far as I can tell, I'm the resident > regexphile on this newsgroup, and I certainly don't say that. > > I find it frustrating that Pythonistas shy away from regex as much as > they do. Yes, Python strings have a rich set of built-in operations > which provide easy ways to do a lot of things traditionally done with > regexes in other languages. > > Regex is a powerful tool, and programmers will improve their skill set > by knowing how to use them. But that's not the same as saying you can't > be a programmer if you don't know regex. > Idiots make comments like that, I've seen them in the past, and no, I can't remember where :) As for me I'm not a regexphobe, more a stringmethodphile. But I'm not going to use a dozen string methods when one fairly simple regex will do the same job in one hit. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From feliphil at gmx.net Thu Dec 19 09:54:02 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 19 Dec 2013 15:54:02 +0100 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: <20131219155402.04e3a4d330e4f63310be414b@gmx.net> > I find it frustrating that Pythonistas shy away from regex as much as > they do. I find regular expression syntax frustrating. >;-> As long as I have the choice, I still prefer syntax like e.g. VerbalExpressions. That's made for actual humans like me. Sincerely, Wolfgang From oscar.j.benjamin at gmail.com Tue Dec 17 12:09:00 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Dec 2013 17:09:00 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 17 December 2013 15:51, Wolfgang Keller wrote: >> >> I was also taught C as an undergrad but having already learned Java, C >> and C++ before arriving at University I found the C course very easy >> so my own experience is not representative. Many of the other students >> at that time found the course too hard and just cheated on all the >> assignments (I remember one students offering to fix/finish anyone's >> assignment in exchange for a bottle of cider!). > > The problem with the C class wasn't that it was "hard". I had passed my > Pascal class, which taught nearly exactly the same issues with > "straight A"s before (without ever having writeen any source code ever > before). And by standard cognitive testing standards, I'm not exactly > considered to be an idiot. Please don't misunderstand me: I'm certainly not saying that you're an idiot. Also I'm sure many of the students on my course would have fared better on a course that was using e.g. Python instead of C. Well actually come to think of it some of the other students were pretty stupid. The lecturer had explained that they were using a plagiarism detector so if you copy-paste code from someone else they could catch you out for cheating. A few people took that literally and thought that it could detect copy-pasting (in plain text files!). The rumour went round that it would be okay if you printed out the code and then typed it back in. For some reason they didn't bother running the plagiarism detector until about 6 weeks into the course by which time ~20% of submissions were exact duplicates of at least one other (according to the lecturer who announced that all such students would get zero marks for those assignments). Oscar From roy at panix.com Tue Dec 17 19:32:20 2013 From: roy at panix.com (Roy Smith) Date: Tue, 17 Dec 2013 19:32:20 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: In article <20131217165144.39bf9ba1cd4e4f27a96893ca at gmx.net>, Wolfgang Keller wrote: > C is just a kafkaesque mess invented by a sadistic pervert who must > have regularly consumed illegal substances for breakfast. Don't be absurd. C is a perfectly good language for the kinds of things it's meant for. It lets you get down close to the hardware while still using rational flow control and program structure, and being reasonably portable. There's very few mysteries in C. You never have to wonder what the lifetime of an object is, or be mystified by which of the 7 signatures of Foo.foo() are going to get called, or just what operation "x + y" is actually going to perform. If you maim yourself with a razor-sharp chisel, do you blame the chisel for being a bad tool? From steve at pearwood.info Tue Dec 17 20:33:03 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Dec 2013 01:33:03 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 Dec 2013 19:32:20 -0500, Roy Smith wrote: > There's very few mysteries in C. Apart from "What the hell does this piece of code actually do?". It's no coincidence that C, and Perl which borrows a lot of syntax from C, are the two champion languages for writing obfuscated code. And "What does 'implementation-specific undefined behaviour' actually mean in practice?", another common question when dealing with C. And most importantly, "how many asterisks do I need, and where do I put them?" (only half joking). > You never have to wonder what the > lifetime of an object is, Since C isn't object oriented, the lifetime of objects in C is, um, any number you like. "The lifetime of objects in is ONE MILLION YEARS!!!" is as good as any other vacuously true statement. > or be mystified by which of the 7 signatures > of Foo.foo() are going to get called, Is that even possible in C? If Foo is a struct, and Foo.foo a member, I don't think C has first-class functions and so Foo.foo can't be callable. But if I'm wrong, and it is callable, then surely with no arguments there can only be one signature that Foo.foo() might call, even if C supported generic functions, which I don't believe it does. (You can simulate something rather like generic functions using pointers, but that's it.) > or just what operation "x + y" is > actually going to perform. With no operator overloading, that one at least is correct. -- Steven From rosuav at gmail.com Tue Dec 17 21:11:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Dec 2013 13:11:58 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Dec 18, 2013 at 12:33 PM, Steven D'Aprano wrote: > On Tue, 17 Dec 2013 19:32:20 -0500, Roy Smith wrote: > >> There's very few mysteries in C. > > Apart from "What the hell does this piece of code actually do?". It's no > coincidence that C, and Perl which borrows a lot of syntax from C, are > the two champion languages for writing obfuscated code. I thought APL would beat both of them, though you're right that the International Obfuscoted Python Code Contest would be a quite different beast. But maybe it'd be just as viable... a competent programmer can write unreadable code in any language. > And "What does 'implementation-specific undefined behaviour' actually > mean in practice?", another common question when dealing with C. You mean like mutating locals()? The only difference is that there are a lot more implementations of C than there are of Python (especially popular and well-used implementations). There are plenty of things you shouldn't do in Python, but instead of calling them "implementation-specific undefined behaviour", we call them "consenting adults" and "shooting yourself in the foot". > And most importantly, "how many asterisks do I need, and where do I put > them?" (only half joking). The one differentiation that I don't like is between the . and -> operators. The distinction feels like syntactic salt. There's no context when both are valid, save in C++ where you can create a "pointer-like object" that implements the -> operator (and has the . operator for its own members). >> You never have to wonder what the >> lifetime of an object is, > > Since C isn't object oriented, the lifetime of objects in C is, um, any > number you like. "The lifetime of objects in objects> is ONE MILLION YEARS!!!" is as good as any other vacuously true > statement. Lifetime still matters. The difference between automatic and static variables is lifetime - you come back into this function and the same value is there waiting for you. Call it "values" or "things" instead of "objects" if it makes you feel better, but the consideration is identical. (And in C++, it becomes critical, with object destructors being used to release resources. So you need to know.) >> or be mystified by which of the 7 signatures >> of Foo.foo() are going to get called, > > Is that even possible in C? If Foo is a struct, and Foo.foo a member, I > don't think C has first-class functions and so Foo.foo can't be callable. > But if I'm wrong, and it is callable, then surely with no arguments there > can only be one signature that Foo.foo() might call, even if C supported > generic functions, which I don't believe it does. Well, okay. In C you can't have Foo.foo(). But if that were Foo_foo(), then the point would be better made, because C will have just one function of that name (barring preprocessor shenanigans, of course). In C++, the types of its arguments may affect which function is called (polymorphism), and the dot notation works, too; but C++ does this without having first-class functions, so that part of your response is immaterial. In C++, Foo.foo() will always call a function foo defined in the class of which Foo is an instance. Very simple, and static type analysis will tell you exactly which function that is. Things do get a bit messier with pointers, because a function might be virtual or not virtual; C++ gives us the simple option (non-virtual functions) that most high level languages don't (C++'s virtual functions behave the same way as Python member functions do). ChrisA From paul at mad-scientist.net Tue Dec 17 22:49:43 2013 From: paul at mad-scientist.net (Paul Smith) Date: Tue, 17 Dec 2013 22:49:43 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1387338583.4269.77.camel@homebase> On Wed, 2013-12-18 at 01:33 +0000, Steven D'Aprano wrote: > And "What does 'implementation-specific undefined behaviour' actually > mean in practice?", another common question when dealing with C. Only asked by people who haven't had it explained. There's "undefined behavior", and there's "implementation-specific behavior", but it is impossible to have "implementation-specific undefined behavior". And, the definitions are simple to understand: "undefined behavior" means that if your program invokes it, there is no definition of what will happen. This is buggy code. "Implementation-specific" behavior means that the standard requires the implementation to do some well-defined thing, but the standard does not define exactly what it must be. You can go look up what your implementation will do in its documentation (the standard requires that it be documented), but you can't assume the same thing will happen in another implementation. This is non-portable code. It's a very rare language indeed that has no undefined or implementation-specific behaviors. Python gets to "cheat" by having one reference implementation. Every time you've had to go try something out in the Python interpreter because the documentation didn't provide the details you needed, that WAS implementation-specific behavior. > > You never have to wonder what the > > lifetime of an object is, > > Since C isn't object oriented, the lifetime of objects in C is, um, any > number you like. "The lifetime of objects in objects> is ONE MILLION YEARS!!!" is as good as any other vacuously true > statement. The implication that only an "object oriented" language could have a concept of object lifetimes is false. Another, less hyperbolic way of saying this is that in C, the lifetime of objects is _exactly as long as you specify_. Heap objects come into existence when you explicitly create them, and they go out of existence when you explicitly destroy them. If you don't destroy them, they never go away. If you destroy them more than once, that's undefined behavior. Stack objects are even simpler. > > or be mystified by which of the 7 signatures > > of Foo.foo() are going to get called, > > Is that even possible in C? If Foo is a struct, and Foo.foo a member, I > don't think C has first-class functions and so Foo.foo can't be callable. Of course that's valid C. It's true that C doesn't have first-class functions, but it supports invoking functions through pointers and you can store functions in data members, pass functions as arguments, and return functions from other functions, so Foo.foo can certainly be callable. ~$ cat /tmp/foo.c #include struct Foo { void (*foo)(); }; void foobar(void) { printf("foobar\n"); } int main() { struct Foo Foo = { foobar }; Foo.foo(); return 0; } $ gcc -Wall -o /tmp/foo /tmp/foo.c $ /tmp/foo foobar From steve at pearwood.info Wed Dec 18 02:53:24 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Dec 2013 07:53:24 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b15474$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Dec 2013 01:33:03 +0000, Steven D'Aprano wrote: >> or just what operation "x + y" is >> actually going to perform. > > > With no operator overloading, that one at least is correct. Actually, I stand corrected. I was completely mistaken about that. The C operation x + y is undefined if the addition overflows. A valid C compiler can produce whatever code it damn well feels like in the case of overflow. Oh, and in case you think that integer overflow in C will always follow two's complement semantics, such that INT_MAX+1 = INT_MIN, you are wrong. That's not guaranteed either. Clang and gcc have a flag, -fwrapv, to force defined behaviour on integer overflow, but that's not part of the C standard and not all C compilers will do the same. -- Steven From steve at pearwood.info Wed Dec 18 03:18:50 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Dec 2013 08:18:50 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 Dec 2013 22:49:43 -0500, Paul Smith wrote: > On Wed, 2013-12-18 at 01:33 +0000, Steven D'Aprano wrote: >> And "What does 'implementation-specific undefined behaviour' actually >> mean in practice?", another common question when dealing with C. > > Only asked by people who haven't had it explained. There's "undefined > behavior", and there's "implementation-specific behavior", but it is > impossible to have "implementation-specific undefined behavior". Of course it is possible. An implementation has to do *something*, even if it's not defined anywhere. Even if that "something" is crash, or emit no code, or display a compile-time error. I think you're making a distinction that doesn't apply to the plain-English meaning of the words I was using: the behaviour is undefined by the standard and specific to that implementation. > And, the definitions are simple to understand: "undefined behavior" > means that if your program invokes it, there is no definition of what > will happen. This is buggy code. Yes, it is buggy code, but nevertheless it often works the way people expect it to work, and so through carelessness or ignorance programmers rely on it. If you've ever written i+1 without a guard for the case that i is INT_MAX, you're guilty of that too. The C99 standard lists 191 different kinds of undefined behavior, including what happens when there is an unmatched ' or " on a line of source code. You want to know why programs written in C are so often full of security holes? One reason is "undefined behaviour". The C language doesn't give a damn about writing *correct* code, it only cares about writing *efficient* code. Consequently, one little error, and does the compiler tell you that you've done something undefined? No, it turns your validator into a no-op -- silently: http://code.google.com/p/nativeclient/issues/detail?id=245 No compile-time error, no run-time error, just blindingly fast and correct (according to the standard) code that does the wrong thing. > "Implementation-specific" behavior means that the standard requires the > implementation to do some well-defined thing, but the standard does not > define exactly what it must be. You can go look up what your > implementation will do in its documentation (the standard requires that > it be documented), but you can't assume the same thing will happen in > another implementation. This is non-portable code. So much for the promise of C to be portable :-) > It's a very rare language indeed that has no undefined or > implementation-specific behaviors. Java? Ada? But indeed, most languages do have odd corners where odd things happen. Including Python, as you point out. But C has so many of them, and they affect *nearly everything*. The aim of C is to write fast code, and if it happens to be correct, that's a bonus. C compilers will compromise on safety and correctness in order to be fast. Then end result is usually one of two outcomes: - the programmer spends a lot of time and effort to manually guard against the undefined behaviour, thus slowing down the code; - or he doesn't, and has bugs and security vulnerabilities in the code. > Python gets to "cheat" by having one > reference implementation. Every time you've had to go try something out > in the Python interpreter because the documentation didn't provide the > details you needed, that WAS implementation-specific behavior. The situation is quite different though. Python makes at least one implicit promise: nothing you write in pure Python can possibly cause a segfault. No buffer overflows for you! We don't know what locals()['spam'] = 42 will do inside a function, but unlike the C case, we can reason about it: - it may bind 42 to the name "spam"; - it may raise a runtime exception; - it may even be a no-op; But even if it is a no-op, the Python compiler doesn't have carte blanche to do anything it likes with the entire function, as a C compiler has. C has more indeterminacy than Python. >> > You never have to wonder what the >> > lifetime of an object is, >> >> Since C isn't object oriented, the lifetime of objects in C is, um, any >> number you like. "The lifetime of objects in > objects> is ONE MILLION YEARS!!!" is as good as any other vacuously >> true statement. > > The implication that only an "object oriented" language could have a > concept of object lifetimes is false. Only object-oriented languages have *objects*. C does not have objects, it has values. And yes, I'm being pedantic. [...] >> > or be mystified by which of the 7 signatures of Foo.foo() are going >> > to get called, >> >> Is that even possible in C? If Foo is a struct, and Foo.foo a member, I >> don't think C has first-class functions and so Foo.foo can't be >> callable. > > Of course that's valid C. It's true that C doesn't have first-class > functions, but it supports invoking functions through pointers and you > can store functions in data members, pass functions as arguments, and > return functions from other functions, so Foo.foo can certainly be > callable. Okay, fair enough, that's why I prefixed my statement with a question. -- Steven From rosuav at gmail.com Wed Dec 18 03:51:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Dec 2013 19:51:26 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Dec 18, 2013 at 7:18 PM, Steven D'Aprano wrote: > You want to know why programs written in C are so often full of security > holes? One reason is "undefined behaviour". The C language doesn't give a > damn about writing *correct* code, it only cares about writing > *efficient* code. Consequently, one little error, and does the compiler > tell you that you've done something undefined? No, it turns your validator > into a no-op -- silently: I disagree about undefined behaviour causing a large proportion of security holes. Maybe it produces some, but it's more likely to produce crashes or inoperative codde. The example you cite is a rare one where it's actually security code; that's why it's a security vulnerability. If the same operation were flagging, say, that this value needed to be saved to disk, then the same bug would result in stuff not getting saved on that platform, which isn't a security risk. Here's something from CERN about C and security: https://security.web.cern.ch/security/recommendations/en/codetools/c.shtml Apart from the last one (file system atomicity, not a C issue at all), every single issue on that page comes back to one thing: fixed-size buffers and functions that treat a char pointer as if it were a string. In fact, that one fundamental issue - the buffer overrun - comes up directly when I search Google for 'most common security holes in c code' (second hit, Wikipedia "Buffer overflow" page). Here's another page listing security concerns: http://www.makelinux.net/alp/085 First entry: Buffer overruns. Second: File system races. Third: Improper quoting of shell commands. Not one of the above pages, nor any other that I came across as I was skimming, mentioned anything involving undefined behaviour. Every one of them is issues with properly-defined behaviour - unless you count specific details of memory layout. If you know that automatic variables are stored on the stack, then you can blow some buffer and overwrite the return value. But that's the *attacker* depending on undefined behaviour, not the *programmer*, who simply has a bug in his code (something that's able to write more to the buffer than there's room for). Python is actually *worse* than C in this respect. I know this particular one is reasonably well known now, but how likely is it that you'll still see code like this: def create_file(): f = open(".....", "w") f.write(".......") f.write(".......") f.write(".......") Looks fine, is nice and simple, does exactly what it should. And in (current versions of) CPython, this will close the file before the function returns, so it'd be perfectly safe to then immediately read from that file. But that's undefined behaviour. Python does not guarantee that this will work, so this might work for years and then break when it's run under Jython, or it might even work in Jython too, but there's just one specific situation where the file's read immediately after being written, and that one case fails. I think that's used at least as often as any of C's pieces of undefined behaviour. ChrisA From ethan at stoneleaf.us Wed Dec 18 10:23:54 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 18 Dec 2013 07:23:54 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52B1BE0A.9000206@stoneleaf.us> On 12/18/2013 12:18 AM, Steven D'Aprano wrote: > On Tue, 17 Dec 2013 22:49:43 -0500, Paul Smith wrote: >> On Wed, 2013-12-18 at 01:33 +0000, Steven D'Aprano wrote: >>> On 12/17/2013 04:32 PM, Roy Smith wrote: >>>> >>>> You never have to wonder what the >>>> lifetime of an object is, >>> >>> Since C isn't object oriented, the lifetime of objects in C is, um, any >>> number you like. "The lifetime of objects in >> objects> is ONE MILLION YEARS!!!" is as good as any other vacuously >>> true statement. >> >> The implication that only an "object oriented" language could have a >> concept of object lifetimes is false. > > Only object-oriented languages have *objects*. C does not have objects, > it has values. The word 'object' has many more meanings than the one implied by Object Oriented Programming, as you well know. > And yes, I'm being pedantic. No, you're being an ass. -- ~Ethan~ From rustompmody at gmail.com Wed Dec 18 11:53:05 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 18 Dec 2013 08:53:05 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, December 18, 2013 8:53:54 PM UTC+5:30, Ethan Furman wrote: > On 12/18/2013 12:18 AM, Steven D'Aprano wrote: > > On Tue, 17 Dec 2013 22:49:43 -0500, Paul Smith wrote: > >> On Wed, 2013-12-18 at 01:33 +0000, Steven D'Aprano wrote: > >>> On 12/17/2013 04:32 PM, Roy Smith wrote: > >>>> You never have to wonder what the > >>>> lifetime of an object is, > >>> Since C isn't object oriented, the lifetime of objects in C is, um, any > >>> number you like. "The lifetime of objects in >>> objects> is ONE MILLION YEARS!!!" is as good as any other vacuously > >>> true statement. > >> The implication that only an "object oriented" language could have a > >> concept of object lifetimes is false. > > Only object-oriented languages have *objects*. C does not have objects, > > it has values. > The word 'object' has many more meanings than the one implied by Object Oriented Programming, as you well know. > > And yes, I'm being pedantic. > No, you're being an ass. Is this discussion REALLY happening...??? In a non-programmer/layman forum it would be completely normal However given that we are supposedly a programmer list I am incredulous Here is some innocuous looking python code: A> def draw_helper(canvas, level, p1, p2, p3): if level == 1: canvas.create_polygon(p1, p2, p3) else: p4 = midpoint(p1, p2) p5 = midpoint(p2, p3) p6 = midpoint(p1, p3) draw_helper(canvas, level - 1, p1, p4, p6) draw_helper(canvas, level - 1, p4, p2, p5) draw_helper(canvas, level - 1, p6, p5, p3) And here is what happens when you run it B> http://homes.cs.washington.edu/~reges/python/sierpinski8.png (More here http://homes.cs.washington.edu/~reges/python/) Can you really say that what you see in B you can infer from A WITHOUT RUNNING IT?? The above is the subject that is technically called 'complexity' in math terms. If we allow the term 'complex' to be more general (like the argument about 'object') then this becomes the pain and beauty, the mystery and horror of programming -- seemingly trivial code when seen as a PROGRAM can endlessly evolve into unimaginable complexity when elaborated into a PROCESS. So when Chris/Roy are talking of the simplicity of C's lifetime rules they are talking of the primitive building blocks to make and understand program-texts. And when Steven/Devin are talking of the complexity of the same they are talking of the arcane results that emerge when those programs run. And from here its a small step to understand why python's slightly more complicated semantics result in so much less complexity than C's seemingly simple rules: C has a double complexity generator -- stack + heap vs python only having a 'managed' heap. Analogously if the Sierpinsky triangle above were flattened into 1-d there would be nothing to note about it. Like python: Boring 'weenie' language... Never segfaults From steve+comp.lang.python at pearwood.info Thu Dec 19 11:20:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2013 16:20:55 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b31ce6$0$6512$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Dec 2013 07:23:54 -0800, Ethan Furman wrote: > On 12/18/2013 12:18 AM, Steven D'Aprano wrote: >> And yes, I'm being pedantic. > > No, you're being an ass. My my, it doesn't take much of a challenge to the Holy Church Of C to bring out the personal attacks. -- Steven From breamoreboy at yahoo.co.uk Wed Dec 18 12:15:30 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 18 Dec 2013 17:15:30 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/12/2013 08:18, Steven D'Aprano wrote: > > The C99 standard lists 191 different kinds of undefined behavior, > including what happens when there is an unmatched ' or " on a line of > source code. > > No compile-time error, no run-time error, just blindingly fast and > correct (according to the standard) code that does the wrong thing. > Plenty of compile-time warnings depending on the compiler, which the CPython core devs take a great deal of trouble to eliminate on every buildbot. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Wed Dec 18 17:33:49 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Dec 2013 17:33:49 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/18/2013 3:18 AM, Steven D'Aprano wrote: > We don't know what locals()['spam'] = 42 will do inside a function, I am mystified that you would write this. Locals() will "Update and return a dictionary representing the current local symbol table." The only thing unspecified is the relation between the 'current local symbol table' and the *dict* that 'represents' it. Given that a dict is returned, the rest is unambiguous. > unlike the C case, we can reason about it: > > - it may bind 42 to the name "spam"; "somedict['spam'] = 42" will do exactly that. > - it may raise a runtime exception; Absolutely not. > - it may even be a no-op; Absolutely not. -- Terry Jan Reedy From oscar.j.benjamin at gmail.com Wed Dec 18 19:21:06 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 19 Dec 2013 00:21:06 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18 December 2013 22:33, Terry Reedy wrote: > On 12/18/2013 3:18 AM, Steven D'Aprano wrote: > >> We don't know what locals()['spam'] = 42 will do inside a function, > > I am mystified that you would write this. Locals() will "Update and return a > dictionary representing the current local symbol table." The only thing > unspecified is the relation between the 'current local symbol table' and the > *dict* that 'represents' it. Given that a dict is returned, the rest is > unambiguous. It's not unambiguous. The full wording is: ''' locals() Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks. Note: The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter. ''' The part that says "changes may ..." is deliberately ambiguous; the author didn't want to impose too strong a constraint on any particular implementation. >> unlike the C case, we can reason about it: >> >> - it may bind 42 to the name "spam"; > > "somedict['spam'] = 42" will do exactly that. That's not what is usually meant by "name-binding". >> - it may raise a runtime exception; > > Absolutely not. Agreed. >> - it may even be a no-op; > > Absolutely not. Incorrect. The code in question is: locals()['spam'] = 42 and it is semantically a no-op. The index assignment on a temporary dict may actually be performed by e.g. the CPython interpreter but it is really just dead code. Oscar From steve+comp.lang.python at pearwood.info Thu Dec 19 11:20:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2013 16:20:10 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b31cba$0$6512$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Dec 2013 19:51:26 +1100, Chris Angelico wrote: > On Wed, Dec 18, 2013 at 7:18 PM, Steven D'Aprano > wrote: >> You want to know why programs written in C are so often full of >> security holes? One reason is "undefined behaviour". The C language >> doesn't give a damn about writing *correct* code, it only cares about >> writing *efficient* code. Consequently, one little error, and does the >> compiler tell you that you've done something undefined? No, it turns >> your validator into a no-op -- silently: > > I disagree about undefined behaviour causing a large proportion of > security holes. I didn't actually specify "large proportion", that's your words. But since you mention crashes: > Maybe it produces some, but it's more likely to produce > crashes or inoperative codde. *Every* crash is a potential security hole. Not only is a denial of service, but a fatal exception[1] is a sign that arbitrary memory has been executed as if it were code, or an illegal instruction executed. Every such crash is a potential opportunity for an attacker to run arbitrary code. There are only two sorts of bugs: bugs with exploits, and bugs that haven't been exploited *yet*. I think you are severely under-estimating the rule of undefined behaviour in C on security vulnerabilities. I quote from "Silent Elimination of Bounds Checks": "Most of the security vulnerabilities described in my book, Secure Coding in C and C++, Second Edition, are the result of exploiting undefined behavior in code." http://www.informit.com/articles/article.aspx?p=2086870 Undefined behaviour interferes with the ability of the programmer to understand causality with respect to his source code. That makes bugs of all sorts more likely, including buffer overflows. Earlier this year, four researchers at MIT analysed how undefined behaviour is effecting software, and they found that C compilers are becoming increasingly aggressive at optimizing such code, resulting in more bugs and vulnerabilities. They found 32 previously unknown bugs in the Linux kernel, 9 in Postgres and 5 in Python. http://www.itworld.com/security/380406/how-your-compiler-may-be-compromising-application-security I believe that the sheer number of buffer overflows in C is more due to the language semantics than the (lack of) skill of the programmers. C the language pushes responsibility for safety onto the developer. Even expert C programmers cannot always tell what their own code will do. Why else do you think there are so many applications for checking C code for buffer overflows, memory leaks, buggy code, and so forth? Because even expert C programmers cannot detect these things without help, and they don't get that help from the language or the compiler. [...] > Apart from the last one (file system atomicity, not a C issue at all), > every single issue on that page comes back to one thing: fixed-size > buffers and functions that treat a char pointer as if it were a string. > In fact, that one fundamental issue - the buffer overrun - comes up > directly when I search Google for 'most common security holes in c code' I think that you have missed the point that buffer overflows are often a direct consequence of the language. For example: http://www.kb.cert.org/vuls/id/162289 Quote: "Some C compilers optimize away pointer arithmetic overflow tests that depend on undefined behavior without providing a diagnostic (a warning). Applications containing these tests may be vulnerable to buffer overflows if compiled with these compilers." The truly frightening thing about this is that even if the programmer tries to write safe code that checks the buffer length, the C compiler is *allowed to silently optimize that check away*. > Python is actually *worse* than C in this respect. You've got to be joking. > I know this > particular one is reasonably well known now, but how likely is it that > you'll still see code like this: > > def create_file(): > f = open(".....", "w") > f.write(".......") > f.write(".......") > f.write(".......") > > Looks fine, is nice and simple, does exactly what it should. And in > (current versions of) CPython, this will close the file before the > function returns, so it'd be perfectly safe to then immediately read > from that file. But that's undefined behaviour. No it isn't. I got chastised for (allegedly) conflating undefined and implementation-specific behaviour. In this case, whether the file is closed or not is clearly implementation-specific behaviour, not undefined. An implementation is permitted to delay closing the file. It's not permitted to erase your hard drive. Python doesn't have an ISO standard like C, so where the documentation doesn't define the semantics of something, CPython behaves as the reference implementation. CPython allows you to simultaneously open the same file for reading and writing, in which case subsequent reads and writes will deterministically depend on the precise timing of when writes are written to disk. That's not something which the language can control, given the expected semantics of file I/O. The behaviour is defined, but it's defined in such a way that what you'll get is deterministic but unpredictable -- a bit like dict order, or pseudo-random numbers. A Python implementation is not permitted to optimize away subsequent reads, erase your hard drive, or download a copy of Wikipedia from the Internet. A C compiler is permitted to do any of these. (Of course, no competent C compiler would actually download all of Wikipedia, since that would be slow. Instead, they would probably only download the HTTP headers for the main page.) [1] I'm talking low level exceptions or errors, not Python exceptions. -- Steven From rosuav at gmail.com Thu Dec 19 12:02:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Dec 2013 04:02:38 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b31cba$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b31cba$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Dec 20, 2013 at 3:20 AM, Steven D'Aprano wrote: > On Wed, 18 Dec 2013 19:51:26 +1100, Chris Angelico wrote: > >> On Wed, Dec 18, 2013 at 7:18 PM, Steven D'Aprano >> wrote: >>> You want to know why programs written in C are so often full of >>> security holes? One reason is "undefined behaviour". The C language >>> doesn't give a damn about writing *correct* code, it only cares about >>> writing *efficient* code. Consequently, one little error, and does the >>> compiler tell you that you've done something undefined? No, it turns >>> your validator into a no-op -- silently: >> >> I disagree about undefined behaviour causing a large proportion of >> security holes. > > I didn't actually specify "large proportion", that's your words. But > since you mention crashes: You implied that it's a significant cause of security holes. I counter by saying that most security holes come from well-defined behaviour. > I think you are severely under-estimating the rule of undefined behaviour > in C on security vulnerabilities. I quote from "Silent Elimination of > Bounds Checks": > > "Most of the security vulnerabilities described in my book, Secure Coding > in C and C++, Second Edition, are the result of exploiting undefined > behavior in code." > > http://www.informit.com/articles/article.aspx?p=2086870 I don't intend to buy the book to find out what he's talking about. All I know is that the one single most common cause of problems in C, the buffer overrun, is NOT "exploiting undefined behavior", an nor are several other common problems (as described in my previous message). > Earlier this year, four researchers at MIT analysed how undefined > behaviour is effecting software, and they found that C compilers are > becoming increasingly aggressive at optimizing such code, resulting in > more bugs and vulnerabilities. They found 32 previously unknown bugs in > the Linux kernel, 9 in Postgres and 5 in Python. > > http://www.itworld.com/security/380406/how-your-compiler-may-be-compromising-application-security Yes, those are issues. Not nearly as large as the ones that _don't_ involve your compiler hurting you, except that CPython had proper memory-usage discipline and didn't have the more glaring bugs. > I believe that the sheer number of buffer overflows in C is more due to > the language semantics than the (lack of) skill of the programmers. C the > language pushes responsibility for safety onto the developer. Even expert > C programmers cannot always tell what their own code will do. Why else do > you think there are so many applications for checking C code for buffer > overflows, memory leaks, buggy code, and so forth? Because even expert C > programmers cannot detect these things without help, and they don't get > that help from the language or the compiler. I agree. The lack of a native string type is fundamental to probably 99% of C program bugs. (Maybe I'm exaggerating, but I reckon it'll be ball-park.) But at no point do these programs or programmers *exploit* undefined behaviour. They might run into it when things go wrong, but by that time, things have already gone wrong. Example: int foo() { char buffer[80]; gets(buffer); return buffer[0]=='A'; } So long as the user enters no more than 79 characters, this function's perfectly well defined. It's vulnerable because user input can trigger a problem, but if anyone consciously exploits compiler-specific memory layouts, it's the attacker, and *NOT* the original code. On the flip side, this code actually does depend on undefined behaviour: int bar() { char buffer[5]; char tmp; memset(buffer,0,6); return tmp; } This code is always going to go past its buffer, and if 'tmp' happens to be the next thing in memory, it'll be happily zeroed. I'm pretty sure I saw code like this on thedailywtf.com a while back. >> Python is actually *worse* than C in this respect. > > You've got to be joking. Trolling, more than joking, but as usual, there is a grain of truth in what I say. >> I know this >> particular one is reasonably well known now, but how likely is it that >> you'll still see code like this: >> >> def create_file(): >> f = open(".....", "w") >> f.write(".......") >> f.write(".......") >> f.write(".......") >> >> Looks fine, is nice and simple, does exactly what it should. And in >> (current versions of) CPython, this will close the file before the >> function returns, so it'd be perfectly safe to then immediately read >> from that file. But that's undefined behaviour. > > No it isn't. I got chastised for (allegedly) conflating undefined and > implementation-specific behaviour. In this case, whether the file is > closed or not is clearly implementation-specific behaviour, not > undefined. An implementation is permitted to delay closing the file. It's > not permitted to erase your hard drive. The problem is that delaying closing the file is a potentially major issue, if the file is about to be reopened. And it _is_ undefined behaviour that one particular Python implementation handles in a very simple and convenient way (and, what's more, in a way that matches how other languages (eg C++, Pike) would handle it, so it's going to "feel right" to people); it's actually very easy to depend on this without realizing it. > Python doesn't have an ISO standard like C, so where the documentation > doesn't define the semantics of something, CPython behaves as the > reference implementation. CPython allows you to simultaneously open the > same file for reading and writing, in which case subsequent reads and > writes will deterministically depend on the precise timing of when writes > are written to disk. Errr, Python does have its standard. It's not an implementation-defined language. Yes, there are places where CPython is the de facto standard, but that doesn't mean something's not undefined. Delaying the close might be completely insignificant, but it has the potential to be critical (depending on the exact share modes and such). And, in the strictest sense of the word, it *is* undefined, and it *is* depended on. ChrisA From steve+comp.lang.python at pearwood.info Thu Dec 19 12:06:05 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2013 17:06:05 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b3277c$0$6512$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Dec 2013 17:33:49 -0500, Terry Reedy wrote: > On 12/18/2013 3:18 AM, Steven D'Aprano wrote: > >> We don't know what locals()['spam'] = 42 will do inside a function, > > I am mystified that you would write this. Context is everything. locals() doesn't just return any old dictionary. It returns a dictionary of variables. > Locals() will "Update and > return a dictionary representing the current local symbol table." The > only thing unspecified is the relation between the 'current local symbol > table' and the *dict* that 'represents' it. Precisely. > Given that a dict is returned, the rest is unambiguous. > >> unlike the C case, we can reason about it: >> >> - it may bind 42 to the name "spam"; > > "somedict['spam'] = 42" will do exactly that. We're not talking about setting items in an arbitrary dict. We're talking about setting variables using locals(), and in that case, writing to locals() does not guarantee to bind the value to the *name*. def test(): spam = 23 locals()["spam"] = 42 assert spam == 42 test() passes the assertion in IronPython 2.6, but fails in CPython 2.7 and 3.4, and Jython 2.5. >> - it may raise a runtime exception; > > Absolutely not. I don't know of any Python implementation which does so, but the documentation says: The contents of this dictionary should not be modified so it is hardly beyond the realm of possibility that some implementation may choose to treat it as an error and raise an exception. >> - it may even be a no-op; > > Absolutely not. In the example I show above, it is a no-op. The dict returned by locals is modified and then immediately garbage-collected. There are no side- effects. Should some implementation decide to compile that away as dead code, it would be perfectly allowed to. (Well, assuming that it determined first that locals() actually was the built-in and not some substitute, either by static analysis or runtime testing.) It wouldn't surprise me if PyPy was capable of doing that today. -- Steven From rosuav at gmail.com Thu Dec 19 12:18:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Dec 2013 04:18:21 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b3277c$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b3277c$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Dec 20, 2013 at 4:06 AM, Steven D'Aprano wrote: > Should some implementation decide to compile that away as dead > code, it would be perfectly allowed to. (Well, assuming that it > determined first that locals() actually was the built-in and not some > substitute, either by static analysis or runtime testing.) Hmm. I'm not sure how safe it is to optimize that sort of thing away in Python. Is there any way to be truly sure that locals is still the built-in, and if there isn't, is there any advantage to optimizing it out with some sort of check to see if it should be de-optimized now? But yes, in theory you're right. Mutating locals() could be optimized out. ChrisA From steve+comp.lang.python at pearwood.info Thu Dec 19 12:12:24 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2013 17:12:24 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Dec 2013 17:15:30 +0000, Mark Lawrence wrote: > On 18/12/2013 08:18, Steven D'Aprano wrote: >> >> The C99 standard lists 191 different kinds of undefined behavior, >> including what happens when there is an unmatched ' or " on a line of >> source code. >> >> No compile-time error, no run-time error, just blindingly fast and >> correct (according to the standard) code that does the wrong thing. >> >> > Plenty of compile-time warnings depending on the compiler, which the > CPython core devs take a great deal of trouble to eliminate on every > buildbot. Correct. The *great deal of trouble* part is important. Things which are the responsibility of the language and compiler in (say) Java, D, Rust, Go, etc. are the responsibility of the programmer with C. I mention these languages as they are all intended to be safer languages than C while still being efficient. Whether they succeed or not is another question. Now, I wish to be absolutely clear. There are certain programming areas where squeezing out every last iota of performance is important, and to do so may require making some compromises on correctness or safety. I find the C standard's position on undefined behaviour to be irresponsible, but, hey, maybe it is justified on the basis that C is a systems language intended for use in writing performance-critical operating system kernels, device drivers and similar. It's fine for Python to promise that nothing you do will ever cause a segfault, but for a language used to write kernels and device drivers, you probably want something more powerful and less constrained. But why is so much non-performance critical code written in C? Why so many user-space applications? History has shown us that the decision to prefer efficiency-by-default rather than correctness-by-default has been a disaster for software safety and security. C language practically is the embodiment of premature optimization: the language allows compilers to silently throw your code away in order to generate efficient code by default, whether you need it or not. -- Steven From rosuav at gmail.com Thu Dec 19 12:28:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Dec 2013 04:28:39 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Dec 20, 2013 at 4:12 AM, Steven D'Aprano wrote: > But why is so much non-performance critical code written in C? Why so > many user-space applications? Very good question! I don't have an answer. There are a few "maybe-answers", but they mostly come down to "programmer didn't know of a viable alternative". When I wrote RosMud, I wrote it in C++, because I was making tweaks to an existing C++ program (Gmud) and because I thought that that was the way to make it run fast enough for what I needed. Seven years on (or will be, come January), I've learned how much can be done in Python, Pike, and other high level languages, and RosMud's successor is not written in C. Maybe part of the answer comes from people who've learned based on old hardware. Growing up in the 80s on an Epson XT-clone, I wrote code in BASIC, C, and assembly. Now, most of my performance problems in BASIC were because of flawed algorithms (it's amazing how slowly an O(n*n) algorithm will run, isn't it!), but I could imagine someone growing up learning "C is the only way to make code run fast" and then going on to teach the next generation of programmers to use C, without necessarily even explaining why. But that's just speculation. All I know is, even if you do need to write in C for some reason (your preferred language doesn't have bindings for some library, maybe), chances are you can write the tiniest bit of code that way, and do the rest in a high level language. ChrisA From neilc at norwich.edu Thu Dec 19 13:40:52 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Thu, 19 Dec 2013 18:40:52 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-12-19, Chris Angelico wrote: > On Fri, Dec 20, 2013 at 4:12 AM, Steven D'Aprano > wrote: >> But why is so much non-performance critical code written in C? >> Why so many user-space applications? > > Very good question! I don't have an answer. There are a few > "maybe-answers", but they mostly come down to "programmer > didn't know of a viable alternative". I believe it was Andrew Plotkin (glk, Glulxe, lots of other stuff) who said that writing good C requires something like brain-damage. Once you have acquired the brain-damage, writing C code is no problem; in fact, it feels darn good. And another thing: How many other languages have their very own calling convention? -- Neil Cerutti From rosuav at gmail.com Thu Dec 19 15:18:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Dec 2013 07:18:35 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Dec 20, 2013 at 5:40 AM, Neil Cerutti wrote: > And another thing: How many other languages have their very own > calling convention? Pascal does (sometimes called the Win32 convention). ChrisA From roy at panix.com Thu Dec 19 19:38:51 2013 From: roy at panix.com (Roy Smith) Date: Thu, 19 Dec 2013 19:38:51 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52b328f7$0$6512$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Correct. The *great deal of trouble* part is important. Things which are > the responsibility of the language and compiler in (say) Java, D, Rust, > Go, etc. are the responsibility of the programmer with C. Does anybody ever use D? I looked at it a few years ago. It seemed like a very good concept. Sort of C++, with the worst of the crap torn out. If nothing else, with the preprocessor torn out :-) Did it ever go anywhere? > Now, I wish to be absolutely clear. There are certain programming areas > where squeezing out every last iota of performance is important, and to > do so may require making some compromises on correctness or safety. I > find the C standard's position on undefined behaviour to be > irresponsible, but, hey, maybe it is justified on the basis that C is a > systems language intended for use in writing performance-critical > operating system kernels, device drivers and similar. It's fine for > Python to promise that nothing you do will ever cause a segfault, but for > a language used to write kernels and device drivers, you probably want > something more powerful and less constrained. I disagree entirely (but respectfully). If you want to get down to the hardware where you can fiddle bits, you want as little getting between you and the silicon as possible. Every time you add a safety feature, you put another layer of *stuff* between you and the machine. That's not to say it's the right language to be writing applications. From rhodri at wildebst.org.uk Thu Dec 19 19:45:49 2013 From: rhodri at wildebst.org.uk (Rhodri James) Date: Fri, 20 Dec 2013 00:45:49 -0000 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 20 Dec 2013 00:38:51 -0000, Roy Smith wrote: > I disagree entirely (but respectfully). If you want to get down to the > hardware where you can fiddle bits, you want as little getting between > you and the silicon as possible. Every time you add a safety feature, > you put another layer of *stuff* between you and the machine. > > That's not to say it's the right language to be writing applications. +1 -- Rhodri James *-* Wildebeest Herder to the Masses From steve+comp.lang.python at pearwood.info Thu Dec 19 21:16:05 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Dec 2013 02:16:05 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b3a864$0$6599$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Dec 2013 19:38:51 -0500, Roy Smith wrote: > In article <52b328f7$0$6512$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Correct. The *great deal of trouble* part is important. Things which >> are the responsibility of the language and compiler in (say) Java, D, >> Rust, Go, etc. are the responsibility of the programmer with C. > > Does anybody ever use D? I looked at it a few years ago. It seemed > like a very good concept. Sort of C++, with the worst of the crap torn > out. If nothing else, with the preprocessor torn out :-) > > Did it ever go anywhere? There are still people using D. Like most niche languages, it's in a niche :-) >> Now, I wish to be absolutely clear. There are certain programming areas >> where squeezing out every last iota of performance is important, and to >> do so MAY REQUIRE MAKING SOME COMPROMISES ON CORRECTNESS OR SAFETY. I >> find the C standard's position on undefined behaviour to be >> irresponsible, but, hey, MAYBE IT IS JUSTIFIED on the basis that C is a >> systems language intended for use in writing performance-critical >> operating system kernels, device drivers and similar. It's fine for >> Python to promise that nothing you do will ever cause a segfault, but >> for a language used to write kernels and device drivers, you probably >> want something more powerful and less constrained. Emphasis added. > I disagree entirely (but respectfully). If you want to get down to the > hardware where you can fiddle bits, you want as little getting between > you and the silicon as possible. Every time you add a safety feature, > you put another layer of *stuff* between you and the machine. I think that if you re-read what I wrote, you actually agree with me. With the following two provisos: 1) There is a tendency among some programmers to premature optimization and coding machismo where correctness is a distant fourth place behind speed, memory use, and code size -- and security doesn't even place. For those programmers, "I want to get down to the hardware" often has nothing to do with *needing* to get down to the hardware. Screw 'em. 2) Even for kernel developers, I believe that systems languages should be safe by default. You ought to have to explicitly disable (say) bounds checking in critical sections of code, rather than explicitly enable it. Or worse, have to program your own bounds checking -- especially if the compiler is permitted to silently disregard it if you make one tiny mistake. > That's not to say it's the right language to be writing applications. I find it interesting to note that the utter failure of C programmers to deal with the consequences of buffer overflows has lead Intel to put pointer safety into hardware. http://software.intel.com/en-us/articles/introduction-to-intel-memory-protection-extensions There is little reason to believe that a safer language would necessarily be slower in practice. C has had 40 years of development to get to where it is now. With a fraction of the development of C, Scala code gets to within a factor of 2-3 of the equivalent C++ code, Go to within a factor of 5-7, and even Java to within a factor of 3-4. Okay, so Java has had oodles of optimization development too, so that's probably about as good as it will get. Imagine if newer languages like Go and Rust had even a quarter of the development effort as C and C++. http://readwrite.com/2011/06/06/cpp-go-java-scala-performance-benchmark -- Steven From ned at nedbatchelder.com Fri Dec 20 21:04:24 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 20 Dec 2013 21:04:24 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <77m9b9p3ibfsari44gvmcq1nvepm7bkdnl@4ax.com> References: <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> <52b3a864$0$6599$c3e8da3$5496439d@news.astraweb.com> <77m9b9p3ibfsari44gvmcq1nvepm7bkdnl@4ax.com> Message-ID: On 12/20/13 6:58 PM, Dennis Lee Bieber wrote: > On 20 Dec 2013 02:16:05 GMT, Steven D'Aprano > declaimed the following: > >> >> 2) Even for kernel developers, I believe that systems languages should be >> safe by default. You ought to have to explicitly disable (say) bounds >> checking in critical sections of code, rather than explicitly enable it. >> Or worse, have to program your own bounds checking -- especially if the >> compiler is permitted to silently disregard it if you make one tiny >> mistake. >> > I wonder how BLISS falls into that... Have to read the rest of > http://en.wikipedia.org/wiki/BLISS (while I had 22 years on VMS, it was > mostly F77, a touch of F90, C, Pascal, and some DCL; but never used BLISS) > Bliss is even lower-level than C. It made the too-consistent choice of having names mean the same thing on the left-hand side of an assignment as on the right-hand side. A name meant the address of a variable, so to access the value of a variable, you had to dereference it with the dot operator, much like the unary asterisk in C. C: a = b Bliss: a = .b C: a = a + 1 Bliss: a = .a + 1 C: a = *b Bliss: a = ..b C: a = &b Bliss: a = b It was far too common to forget the dots... -- Ned Batchelder, http://nedbatchelder.com From steve+comp.lang.python at pearwood.info Fri Dec 27 09:35:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2013 14:35:33 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15a69$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b328f7$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52bd9035$0$6599$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Dec 2013 19:38:51 -0500, Roy Smith wrote: > Does anybody ever use D? I looked at it a few years ago. It seemed > like a very good concept. Sort of C++, with the worst of the crap torn > out. If nothing else, with the preprocessor torn out :-) > > Did it ever go anywhere? Apparently Facebook are now working with it: http://www.fastcolabs.com/3019948/more-about-d-language-and-why-facebook-is-experimenting-with-it -- Steven From steve at pearwood.info Wed Dec 18 03:22:58 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Dec 2013 08:22:58 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Dec 2013 13:11:58 +1100, Chris Angelico wrote: > On Wed, Dec 18, 2013 at 12:33 PM, Steven D'Aprano > wrote: >> On Tue, 17 Dec 2013 19:32:20 -0500, Roy Smith wrote: >> >>> There's very few mysteries in C. >> >> Apart from "What the hell does this piece of code actually do?". It's >> no coincidence that C, and Perl which borrows a lot of syntax from C, >> are the two champion languages for writing obfuscated code. > > I thought APL would beat both of them, though you're right that the > International Obfuscoted Python Code Contest would be a quite different > beast. But maybe it'd be just as viable... a competent programmer can > write unreadable code in any language. > >> And "What does 'implementation-specific undefined behaviour' actually >> mean in practice?", another common question when dealing with C. > > You mean like mutating locals()? The only difference is that there are a > lot more implementations of C than there are of Python (especially > popular and well-used implementations). There are plenty of things you > shouldn't do in Python, but instead of calling them > "implementation-specific undefined behaviour", we call them "consenting > adults" and "shooting yourself in the foot". > >> And most importantly, "how many asterisks do I need, and where do I put >> them?" (only half joking). > > The one differentiation that I don't like is between the . and -> > operators. The distinction feels like syntactic salt. There's no context > when both are valid, save in C++ where you can create a "pointer-like > object" that implements the -> operator (and has the . operator for its > own members). > >>> You never have to wonder what the >>> lifetime of an object is, >> >> Since C isn't object oriented, the lifetime of objects in C is, um, any >> number you like. "The lifetime of objects in > objects> is ONE MILLION YEARS!!!" is as good as any other vacuously >> true statement. > > Lifetime still matters. The difference between automatic and static > variables is lifetime - you come back into this function and the same > value is there waiting for you. Call it "values" or "things" instead of > "objects" if it makes you feel better, but the consideration is > identical. (And in C++, it becomes critical, with object destructors > being used to release resources. So you need to know.) > >>> or be mystified by which of the 7 signatures of Foo.foo() are going to >>> get called, >> >> Is that even possible in C? If Foo is a struct, and Foo.foo a member, I >> don't think C has first-class functions and so Foo.foo can't be >> callable. But if I'm wrong, and it is callable, then surely with no >> arguments there can only be one signature that Foo.foo() might call, >> even if C supported generic functions, which I don't believe it does. > > Well, okay. In C you can't have Foo.foo(). Hah, well according to Paul Smith's example code you can. So either: - it's possible to be an experienced C programmer and still have fundamental gaps in your knowledge about basic concepts like dotted function calls; - or Paul's sample code was not what he claimed it to be; - or maybe the whole thing is undefined and we're all right! C both does and doesn't allow Foo.foo() function calls, *sometimes at the same time*. -- Steven From rosuav at gmail.com Wed Dec 18 03:32:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Dec 2013 19:32:56 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Dec 18, 2013 at 7:22 PM, Steven D'Aprano wrote: >> Well, okay. In C you can't have Foo.foo(). > > Hah, well according to Paul Smith's example code you can. So either: > > > - it's possible to be an experienced C programmer and still have > fundamental gaps in your knowledge about basic concepts like dotted > function calls; > > - or Paul's sample code was not what he claimed it to be; > > - or maybe the whole thing is undefined and we're all right! C both does > and doesn't allow Foo.foo() function calls, *sometimes at the same time*. - or it's possible to be an experienced C and C++ programmer and have your mind just blank out about which things you can do in C and which were added in C++, especially when you've been up all night and are wired on energy drinks. Mea culpa. My brain looked at that and thought it was a member function, which is a C++ feature, and forgot that it could be a straight-up function pointer, which is a C feature. Paul's correct, I'm wrong. ChrisA From davea at davea.name Wed Dec 18 07:53:23 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Dec 2013 07:53:23 -0500 Subject: =?UTF-8?Q?Re:_Experiences/guidance_on_teaching_P?= =?UTF-8?Q?ython_as_a_first_programming=0A_language?= In-Reply-To: <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18 Dec 2013 08:22:58 GMT, Steven D'Aprano wrote: > On Wed, 18 Dec 2013 13:11:58 +1100, Chris Angelico wrote: > > The one differentiation that I don't like is between the . and -> > > operators. The distinction feels like syntactic salt. There's no context > > when both are valid, save in C++ where you can create a "pointer-like > > object" that implements the -> operator (and has the . operator for its > > own members). Funny you should say that in the middle of a discussion about lifetime. In C, when you do the -> thing, you're now in a different struct with a potentially different lifetime. If p is a local, with auto lifetime, then so is p.x So, although the two are mutually exclusive, there's valuable information hidden in the required choice. -- DaveA From rosuav at gmail.com Wed Dec 18 09:55:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Dec 2013 01:55:10 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Dec 18, 2013 at 11:53 PM, Dave Angel wrote: > Funny you should say that in the middle of a discussion about lifetime. In > C, when you do the -> thing, you're now in a different struct with a > potentially different lifetime. If p is a local, with auto lifetime, then > so is p.x > > So, although the two are mutually exclusive, there's valuable information > hidden in the required choice. Sure, but you can figure out whether p is a local struct or a local pointer to some other struct by looking at its declaration. Do you also need to look at every usage of it? We don't adorn every / with a marker saying whether we're dividing ints or floats, and that's something that could be potentially useful (float division of two ints being what Py3 does). Why adorn pointer usage? ChrisA From neilc at norwich.edu Wed Dec 18 10:17:34 2013 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 18 Dec 2013 15:17:34 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-12-18, Chris Angelico wrote: > On Wed, Dec 18, 2013 at 11:53 PM, Dave Angel wrote: >> Funny you should say that in the middle of a discussion about >> lifetime. In C, when you do the -> thing, you're now in a >> different struct with a potentially different lifetime. If p >> is a local, with auto lifetime, then so is p.x >> >> So, although the two are mutually exclusive, there's valuable >> information hidden in the required choice. > > Sure, but you can figure out whether p is a local struct or a > local pointer to some other struct by looking at its > declaration. Do you also need to look at every usage of it? We > don't adorn every / with a marker saying whether we're dividing > ints or floats, and that's something that could be potentially > useful (float division of two ints being what Py3 does). Why > adorn pointer usage? Indeed. Golang allows . to do member lookup for both structs and pointers to structs. The -> syntax perhaps was needful in the days before function prototypes. -- Neil Cerutti From davea at davea.name Wed Dec 18 15:52:43 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Dec 2013 15:52:43 -0500 Subject: =?UTF-8?Q?Re:_Re:_Experiences/guidance_on_teaching?= =?UTF-8?Q?_Python_as_a_first=0A_programming_language?= In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 19 Dec 2013 01:55:10 +1100, Chris Angelico wrote: > Sure, but you can figure out whether p is a local struct or a local > pointer to some other struct by looking at its declaration. Do you > also need to look at every usage of it? C is a glorified macro assembler. So the -> operator is not analogous to the dot operator, it's Syntactic sugar: p-> a. Is really (*p).a -- DaveA From greg.ewing at canterbury.ac.nz Thu Dec 19 01:41:00 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 19 Dec 2013 19:41:00 +1300 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dave Angel wrote: > C is a glorified macro assembler. So the -> operator is not analogous > to the dot operator, it's Syntactic sugar: > > p-> a. Is really > (*p).a But it's not above inferring a dereferencing operation when you call a function via a pointer. If f is a pointer to a function, then f(a) is equivalent to (*f)(a) If the compiler can do that for function calls, there's no reason it couldn't do it for member access as well. If I remember rightly, Ada not only does implicit dereferencing like this, it doesn't even have an explicit dereferencing operator! If you want to refer to the whole record pointed to by p, you have to say 'p.all'. BTW, the whole notion of a "pointer to a function" is redundant in C, since you can't do anything with what it points to other than call it. The equivalent concept in Modula, for example, is just called a function type, not a pointer-to- function type. Similarly in most languages that have functions as values. -- Greg From davea at davea.name Thu Dec 19 07:06:44 2013 From: davea at davea.name (Dave Angel) Date: Thu, 19 Dec 2013 07:06:44 -0500 Subject: =?UTF-8?Q?Re:_Experiences/guidance_on_teaching_P?= =?UTF-8?Q?ython_as_a_first_programming=0A_language?= In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 19 Dec 2013 19:41:00 +1300, Gregory Ewing wrote: > But it's not above inferring a dereferencing > operation when you call a function via a > pointer. If f is a pointer to a function, > then > f(a) > is equivalent to > (*f)(a) > If the compiler can do that for function calls, > there's no reason it couldn't do it for member > access as well. Quite right. And I recall being confounded by the function pointer syntax; it never fit in my mental model of how the rest of C worked. Anyway I was not intending to defend C choices, merely to point out an advantage this choice gave me. On a language without garbage collection, the indirection was very important to keep in mind. -- DaveA From rhodri at wildebst.org.uk Wed Dec 18 19:10:04 2013 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 19 Dec 2013 00:10:04 -0000 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> <52b15b62$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 18 Dec 2013 14:55:10 -0000, Chris Angelico wrote: > On Wed, Dec 18, 2013 at 11:53 PM, Dave Angel wrote: >> Funny you should say that in the middle of a discussion about >> lifetime. In >> C, when you do the -> thing, you're now in a different struct with a >> potentially different lifetime. If p is a local, with auto lifetime, >> then >> so is p.x >> >> So, although the two are mutually exclusive, there's valuable >> information >> hidden in the required choice. > > Sure, but you can figure out whether p is a local struct or a local > pointer to some other struct by looking at its declaration. Do you > also need to look at every usage of it? We don't adorn every / with a > marker saying whether we're dividing ints or floats, and that's > something that could be potentially useful (float division of two ints > being what Py3 does). Why adorn pointer usage? Because explicit is better than implicit? -- Rhodri James *-* Wildebeest Herder to the Masses From invalid at invalid.invalid Wed Dec 18 13:00:08 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 18 Dec 2013 18:00:08 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-12-18, Chris Angelico wrote: > Well, okay. In C you can't have Foo.foo(). If "Foo" is a structure with a field named "foo" that is a pointer to a function, then you can indeed "have" Foo.foo(). -- Grant Edwards grant.b.edwards Yow! It's OKAY -- I'm an at INTELLECTUAL, too. gmail.com From breamoreboy at yahoo.co.uk Wed Dec 18 13:07:52 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 18 Dec 2013 18:07:52 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/12/2013 18:00, Grant Edwards wrote: > On 2013-12-18, Chris Angelico wrote: > >> Well, okay. In C you can't have Foo.foo(). > > If "Foo" is a structure with a field named "foo" that is a pointer to > a function, then you can indeed "have" Foo.foo(). > Complete fooey :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Wed Dec 18 20:56:45 2013 From: roy at panix.com (Roy Smith) Date: Wed, 18 Dec 2013 20:56:45 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Grant Edwards wrote: > On 2013-12-18, Chris Angelico wrote: > > > Well, okay. In C you can't have Foo.foo(). > > If "Foo" is a structure with a field named "foo" that is a pointer to > a function, then you can indeed "have" Foo.foo(). Sigh. This has gone off in a direction I never intended. What I meant was that in C++, when you write call a method by name, it can sometimes be difficult to know exactly what method is being called. Between inheritance, optional parameters, automatic type promotion, default constructors, and maybe a few other things I've forgotten, even if you've got all the signatures of foo() in front of you, it can sometimes be hard to figure out which one the compiler will pick. And that sort of confusion never happens in C. From greg.ewing at canterbury.ac.nz Thu Dec 19 00:39:35 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 19 Dec 2013 18:39:35 +1300 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Roy Smith wrote: > even > if you've got all the signatures of foo() in front of you, it can > sometimes be hard to figure out which one the compiler will pick. And conversely, sometimes the compiler will have a hard time figuring out which one you want it to pick! I had an experience in Java recently where a library author had provided two overloads of a function, that at first sight could be disambiguated by argument types. But for a certain combination of types it was ambiguous, and I was unlucky enough to want to use that particular combination, and the compiler insisted on picking the wrong one. As far as I could see, it was *impossible* to call the other overload with those parameter types. I ended up resorting to copying the whole function and giving it another name, just so I could get it called. -- Function overloading: Just say no. Greg From roy at panix.com Thu Dec 19 00:56:56 2013 From: roy at panix.com (Roy Smith) Date: Thu, 19 Dec 2013 00:56:56 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b0fb4f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Gregory Ewing wrote: > Roy Smith wrote: > > even > > if you've got all the signatures of foo() in front of you, it can > > sometimes be hard to figure out which one the compiler will pick. > > And conversely, sometimes the compiler will have a hard > time figuring out which one you want it to pick! > > I had an experience in Java recently where a library > author had provided two overloads of a function, that > at first sight could be disambiguated by argument types. > But for a certain combination of types it was > ambiguous, and I was unlucky enough to want to use that > particular combination, and the compiler insisted on > picking the wrong one. As far as I could see, it was > *impossible* to call the other overload with those > parameter types. > > I ended up resorting to copying the whole function and > giving it another name, just so I could get it called. BTDT. We were doing a huge network management application. There was an SNMP_Manager class, which had three or four different constructors, each one taking a dozen or more arguments, many of them optional. I finally got fed up with eternally trying to figure out which constructor was being called and replaced them with a series of factory functions: construct_for_traps(), construct_for_polling(), etc. From jeanpierreda at gmail.com Tue Dec 17 21:33:54 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 17 Dec 2013 18:33:54 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Tue, Dec 17, 2013 at 4:32 PM, Roy Smith wrote: > There's very few mysteries in C. You never have to wonder what the > lifetime of an object is Yes you do. Lifetimes are hard, because you need to malloc a lot, and there is no defined lifetime for pointers -- they could last for just the lifetime of a stack frame, or until the end of the program, or anywhere in-between, and it's impossible to know for sure, and if you get it wrong your program crashes. So there's all these conventions you have to come up with like "borrowing" and "owning", but they aren't compiler-enforced, so you still have to figure it out, and you will get it wrong. Successors like C++ mitigate these issues with destructors (allowing heap-allocated stuff to be tied to the lifetime of a stack), and smart pointers and so on. > , or be mystified by which of the 7 signatures > of Foo.foo() are going to get called C still has overloaded functions, just fewer of them. It'll still mystify you when you encounter it, though. http://www.robertgamble.net/2012/01/c11-generic-selections.html > , or just what operation "x + y" is > actually going to perform. I don't know. Will it do float addition? int addition? size_t addition? How does coercion work? + can do many different things, it's not just a straight translation to an obvious machine instruction. > If you maim yourself with a razor-sharp chisel, do you blame the chisel > for being a bad tool? If I didn't need it to be that sharp, then yes. -- Devin From rosuav at gmail.com Tue Dec 17 22:01:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Dec 2013 14:01:52 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Wed, Dec 18, 2013 at 1:33 PM, Devin Jeanpierre wrote: > On Tue, Dec 17, 2013 at 4:32 PM, Roy Smith wrote: >> There's very few mysteries in C. You never have to wonder what the >> lifetime of an object is > > Yes you do. Lifetimes are hard, because you need to malloc a lot, and > there is no defined lifetime for pointers -- they could last for just > the lifetime of a stack frame, or until the end of the program, or > anywhere in-between, and it's impossible to know for sure, and if you > get it wrong your program crashes. So there's all these conventions > you have to come up with like "borrowing" and "owning", but they > aren't compiler-enforced, so you still have to figure it out, and you > will get it wrong. Successors like C++ mitigate these issues with > destructors (allowing heap-allocated stuff to be tied to the lifetime > of a stack), and smart pointers and so on. Wrong. A pointer is a scalar value, usually some kind of integer, and its lifetime is the same as any other scalar. Heap memory's lifetime is also very simple: it lasts until freed. (Though technically that's not even a part of the language - malloc/free are just functions. Not that it matters. Anyway, C++ has the new and delete operators, which are part of the language.) There are conventions to prevent memory leaks, but those are mere conventions. It's simple in the same way that a toy electric motor is simple: you apply current to it, and it spins. There's so little that it can do that it HAS to be simple. ChrisA From jeanpierreda at gmail.com Tue Dec 17 22:12:00 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 17 Dec 2013 19:12:00 -0800 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Tue, Dec 17, 2013 at 7:01 PM, Chris Angelico wrote: > On Wed, Dec 18, 2013 at 1:33 PM, Devin Jeanpierre > wrote: >> Yes you do. Lifetimes are hard, because you need to malloc a lot, and >> there is no defined lifetime for pointers -- they could last for just >> the lifetime of a stack frame, or until the end of the program, or >> anywhere in-between, and it's impossible to know for sure, and if you >> get it wrong your program crashes. So there's all these conventions >> you have to come up with like "borrowing" and "owning", but they >> aren't compiler-enforced, so you still have to figure it out, and you >> will get it wrong. Successors like C++ mitigate these issues with >> destructors (allowing heap-allocated stuff to be tied to the lifetime >> of a stack), and smart pointers and so on. > > Wrong. A pointer is a scalar value, usually some kind of integer, and > its lifetime is the same as any other scalar. The duration of a pointer's validity is far more interesting, and that is why it is the primary meaning of the term "pointer lifetime". Also, it's obviously what I meant. > Heap memory's lifetime > is also very simple: it lasts until freed. Sometimes simple things are hard to use correctly. I only said it was hard, not complicated. -- Devin From rosuav at gmail.com Tue Dec 17 22:24:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Dec 2013 14:24:06 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Wed, Dec 18, 2013 at 2:12 PM, Devin Jeanpierre wrote: >> Wrong. A pointer is a scalar value, usually some kind of integer, and >> its lifetime is the same as any other scalar. > > The duration of a pointer's validity is far more interesting, and that > is why it is the primary meaning of the term "pointer lifetime". Also, > it's obviously what I meant. >> Heap memory's lifetime >> is also very simple: it lasts until freed. > > Sometimes simple things are hard to use correctly. I only said it was > hard, not complicated. Sure, which is why I went on to discuss the block of memory pointed to. But the rules are a lot simpler than in Python, where something exists until... uhh... the system feels like disposing of it. At which point __del__ will probably be called, but we can't be sure of that. All we know about an object's lifetime in Python is that it will continue to live so long as we're using it. And then multiprocessing and fork make it messier, but that's true in any language. The original point was that C has no mysteries. I posit that this is true because C's rules are so simple. It might well be harder to work in this system (taking it to an extreme, Brainf* is about the simplest Turing-complete language possible, and it's virtually impossible to write good code in it), but it has no mysteries. ChrisA From rhodri at wildebst.org.uk Wed Dec 18 19:49:04 2013 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 19 Dec 2013 00:49:04 -0000 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Tue, 17 Dec 2013 15:51:44 -0000, Wolfgang Keller wrote: > The only issue for me was to figure out how to do in C what I already > knew in Pascal. And I had to waste a *lot* more time and mental effort > to mess with that language than it took for me to learn *both* the > basics of programming per se *and* Pascal in the first class at my home > university. It's sounds like you made, and are carrying on making, one of the classic mistakes of software engineering: you're trying to write one language in the style of another. It is possible to write C code as if it were Pascal, but it's a painful process and it won't be pretty. It's far better to use a language as it is rather than as you want it to be. -- Rhodri James *-* Wildebeest Herder to the Masses From rosuav at gmail.com Wed Dec 18 19:54:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Dec 2013 11:54:12 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Thu, Dec 19, 2013 at 11:49 AM, Rhodri James wrote: > It's sounds like you made, and are carrying on making, one of the classic > mistakes of software engineering Never get into a flame war in Asia, and never go up against a C programmer when segfaults are on the line! ChrisA From rustompmody at gmail.com Wed Dec 18 23:29:31 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 18 Dec 2013 20:29:31 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On Thursday, December 19, 2013 6:19:04 AM UTC+5:30, Rhodri James wrote: > On Tue, 17 Dec 2013 15:51:44 -0000, Wolfgang Keller wrote: > > The only issue for me was to figure out how to do in C what I already > > knew in Pascal. And I had to waste a *lot* more time and mental effort > > to mess with that language than it took for me to learn *both* the > > basics of programming per se *and* Pascal in the first class at my home > > university. > It's sounds like you made, and are carrying on making, one of the classic > mistakes of software engineering: you're trying to write one language in > the style of another. It is possible to write C code as if it were > Pascal, but it's a painful process and it won't be pretty. It's far > better to use a language as it is rather than as you want it to be. Yes but the reverse is also true: Sometimes the best code in language L is first conceptualized in design-language D and then 'coded' into L. When we were students D was called 'flow-charts' Gone out of fashion today and replaced by UML. Now I expect the majority on this list to not care for UML. However the idea of a separate design language is not negated by the fact that UML is overkill and silly. eg Saw this (on the Erlang mailing list) In some Australian university (in the 90s) 2 sems of Cobol was replaced by 1 sem Scheme + 1 sem Cobol. Students learnt more Cobol in the second arrangement than in the first. [Note: 'More Cobol' not 'More Programming'] Now if you were to ask those *students* I would expect similar emotions towards Cobol as Wolfgang is expressing towards C. That is however a separate issue :D From breamoreboy at yahoo.co.uk Wed Dec 18 23:50:54 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 19 Dec 2013 04:50:54 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: On 19/12/2013 04:29, rusi wrote: > On Thursday, December 19, 2013 6:19:04 AM UTC+5:30, Rhodri James wrote: >> On Tue, 17 Dec 2013 15:51:44 -0000, Wolfgang Keller wrote: >>> The only issue for me was to figure out how to do in C what I already >>> knew in Pascal. And I had to waste a *lot* more time and mental effort >>> to mess with that language than it took for me to learn *both* the >>> basics of programming per se *and* Pascal in the first class at my home >>> university. > >> It's sounds like you made, and are carrying on making, one of the classic >> mistakes of software engineering: you're trying to write one language in >> the style of another. It is possible to write C code as if it were >> Pascal, but it's a painful process and it won't be pretty. It's far >> better to use a language as it is rather than as you want it to be. > > Yes but the reverse is also true: Sometimes the best code in language > L is first conceptualized in design-language D and then 'coded' into > L. > > When we were students D was called 'flow-charts' > Gone out of fashion today and replaced by UML. > > Now I expect the majority on this list to not care for UML. > However the idea of a separate design language is not negated by the fact > that UML is overkill and silly. > > eg Saw this (on the Erlang mailing list) > In some Australian university (in the 90s) 2 sems of Cobol was > replaced by 1 sem Scheme + 1 sem Cobol. Students learnt more Cobol in > the second arrangement than in the first. [Note: 'More Cobol' not 'More > Programming'] > > Now if you were to ask those *students* I would expect similar > emotions towards Cobol as Wolfgang is expressing towards C. > That is however a separate issue :D > If C is such a crap language, what does it says for the thousands of languages that never got anywhere? Or did C simply have a far larger sales and marketing budget? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Thu Dec 19 00:09:42 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 18 Dec 2013 21:09:42 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: <049186d3-2a00-48bb-94c3-34b3214ce08d@googlegroups.com> On Thursday, December 19, 2013 10:20:54 AM UTC+5:30, Mark Lawrence wrote: > On 19/12/2013 04:29, rusi wrote: > > On Thursday, December 19, 2013 6:19:04 AM UTC+5:30, Rhodri James wrote: > >> On Tue, 17 Dec 2013 15:51:44 -0000, Wolfgang Keller wrote: > >>> The only issue for me was to figure out how to do in C what I already > >>> knew in Pascal. And I had to waste a *lot* more time and mental effort > >>> to mess with that language than it took for me to learn *both* the > >>> basics of programming per se *and* Pascal in the first class at my home > >>> university. > >> It's sounds like you made, and are carrying on making, one of the classic > >> mistakes of software engineering: you're trying to write one language in > >> the style of another. It is possible to write C code as if it were > >> Pascal, but it's a painful process and it won't be pretty. It's far > >> better to use a language as it is rather than as you want it to be. > > Yes but the reverse is also true: Sometimes the best code in language > > L is first conceptualized in design-language D and then 'coded' into > > L. > > When we were students D was called 'flow-charts' > > Gone out of fashion today and replaced by UML. > > Now I expect the majority on this list to not care for UML. > > However the idea of a separate design language is not negated by the fact > > that UML is overkill and silly. > > eg Saw this (on the Erlang mailing list) > > In some Australian university (in the 90s) 2 sems of Cobol was > > replaced by 1 sem Scheme + 1 sem Cobol. Students learnt more Cobol in > > the second arrangement than in the first. [Note: 'More Cobol' not 'More > > Programming'] > > Now if you were to ask those *students* I would expect similar > > emotions towards Cobol as Wolfgang is expressing towards C. > > That is however a separate issue :D > If C is such a crap language, what does it says for the thousands of > languages that never got anywhere? Or did C simply have a far larger > sales and marketing budget? :) Are you addressing that to me? [Assuming you are a good boy who does not use GG-crap and knows the laws of snipping and attributing I am taking it so :D ] No I am not in the 'C-is-crap' camp. Very far into the opposite actually. What would you say to someone who says: - food is crap to eat - air is crap to breathe "C is crap technology" is analogous. If you are using python its likely CPython. Whats the C there? If you are connected to the net the modem likely runs a linux. Coded in? I am an Luddite -- dont touch computers. Right. The car I drive probably has embedded chips... Embeded linux. No Amish/Luddite is not enough to say "No!" to C You'd have to be completely isolated from every connection with modern civilization. So python programmers employ the 'black-cat' squad of GvR and gang to shield us from C. Because they are good at it we can afford to ignore it. No, "No C" is no option. The only option is at how many removes we keep away from it. From breamoreboy at yahoo.co.uk Thu Dec 19 00:36:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 19 Dec 2013 05:36:26 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <049186d3-2a00-48bb-94c3-34b3214ce08d@googlegroups.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <049186d3-2a00-48bb-94c3-34b3214ce08d@googlegroups.com> Message-ID: On 19/12/2013 05:09, rusi wrote: > On Thursday, December 19, 2013 10:20:54 AM UTC+5:30, Mark Lawrence wrote: >> On 19/12/2013 04:29, rusi wrote: >>> On Thursday, December 19, 2013 6:19:04 AM UTC+5:30, Rhodri James wrote: >>>> On Tue, 17 Dec 2013 15:51:44 -0000, Wolfgang Keller wrote: >>>>> The only issue for me was to figure out how to do in C what I already >>>>> knew in Pascal. And I had to waste a *lot* more time and mental effort >>>>> to mess with that language than it took for me to learn *both* the >>>>> basics of programming per se *and* Pascal in the first class at my home >>>>> university. >>>> It's sounds like you made, and are carrying on making, one of the classic >>>> mistakes of software engineering: you're trying to write one language in >>>> the style of another. It is possible to write C code as if it were >>>> Pascal, but it's a painful process and it won't be pretty. It's far >>>> better to use a language as it is rather than as you want it to be. >>> Yes but the reverse is also true: Sometimes the best code in language >>> L is first conceptualized in design-language D and then 'coded' into >>> L. >>> When we were students D was called 'flow-charts' >>> Gone out of fashion today and replaced by UML. >>> Now I expect the majority on this list to not care for UML. >>> However the idea of a separate design language is not negated by the fact >>> that UML is overkill and silly. >>> eg Saw this (on the Erlang mailing list) >>> In some Australian university (in the 90s) 2 sems of Cobol was >>> replaced by 1 sem Scheme + 1 sem Cobol. Students learnt more Cobol in >>> the second arrangement than in the first. [Note: 'More Cobol' not 'More >>> Programming'] >>> Now if you were to ask those *students* I would expect similar >>> emotions towards Cobol as Wolfgang is expressing towards C. >>> That is however a separate issue :D > >> If C is such a crap language, what does it says for the thousands of >> languages that never got anywhere? Or did C simply have a far larger >> sales and marketing budget? :) > > Are you addressing that to me? No, I never address individuals. As far as I'm concerned I'm sending to an entire newsgroup/mailing list. > [Assuming you are a good boy who does not use GG-crap and knows the laws > of snipping and attributing I am taking it so :D ] Please cut the sarcastic crap. > > No I am not in the 'C-is-crap' camp. Very far into the opposite actually. > > What would you say to someone who says: > - food is crap to eat > - air is crap to breathe > > "C is crap technology" is analogous. > > If you are using python its likely CPython. Whats the C there? > If you are connected to the net the modem likely runs a linux. Coded in? > > I am an Luddite -- dont touch computers. > Right. The car I drive probably has embedded chips... Embeded linux. > > No Amish/Luddite is not enough to say "No!" to C > You'd have to be completely isolated from every connection with modern > civilization. > > So python programmers employ the 'black-cat' squad of GvR and gang to shield > us from C. Because they are good at it we can afford to ignore it. > > No, "No C" is no option. > The only option is at how many removes we keep away from it. > I've no idea what most of the above is meant to mean. Have you been reading too much RR or "Joseph McCarthy"? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Thu Dec 19 16:31:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2013 21:31:34 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> Message-ID: <52b365b6$0$6512$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Dec 2013 04:50:54 +0000, Mark Lawrence wrote: > If C is such a crap language, what does it says for the thousands of > languages that never got anywhere? Or did C simply have a far larger > sales and marketing budget? :) The sociology of computer languages is a fascinating topic. Like any technology, it's a mix of factors. Why did VHS defeat Betamax when all the experts agreed Betamax was the better system? How did Windows take over IT? The advantages of C in the 1970s and 80s included: - although "portable C code" is a sad joke, compared to most of the languages that came before it, C *is* portable; - C compilers can be small, efficient and fast, although they weren't as small, efficient and fast as (say) TurboPascal; - the machine code they generated was acceptably lightweight and fast, although not as lightweight and fast as (say) Forth; - C was an open standard at a time when computing was big enough that open standards were becoming important; - C did (and still does) have some areas where it is quite advantageous, like systems programming; - C benefited from it's close association with Unix, where Unix went, so did C; - Unix made some universities a lot of money, hence they had a motive to support C with both money and attention; - C was associated with universities, so people learned C and then taught C to the next generation of students, who went on to introduce C to industry; and - C (like Perl) falls into the hacker-machismo sweet-spot, where it is just challenging enough to still be fun without being either too easy or too hard. It is low-level enough to allow premature optimization (without being as low as assembly language, which is too low-level to be fun) and gives the freedom to play code golf and write amazingly obfuscated code. So C is a language that allows hackers to show off. Some of those reasons also applied to Lisp, and remember that in the 1970s and even 80s Lisp compilers were at least as efficient as C compilers. I believe there are two factors that lead to C becoming more popular than Lisp. The first is Worse Is Better: http://www.jwz.org/doc/worse-is-better.html The second is that, despite all the weird punctuation and digraphs and even trigraphs, C fits the mental space of English-speakers better than Lisp. To the average programmer, C is a more natural syntax and programming model than Lisp. -- Steven From roy at panix.com Thu Dec 19 19:30:39 2013 From: roy at panix.com (Roy Smith) Date: Thu, 19 Dec 2013 19:30:39 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217165144.39bf9ba1cd4e4f27a96893ca@gmx.net> <52b365b6$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52b365b6$0$6512$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: [some stuff] > where Unix went, so did C; [some more stuff] What he said. From rustompmody at gmail.com Wed Dec 18 04:18:13 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 18 Dec 2013 01:18:13 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: <23663ad2-9b3f-4950-87af-ea1be504234b@googlegroups.com> On Tuesday, December 17, 2013 4:42:07 PM UTC+5:30, Oscar Benjamin wrote: > On 17 December 2013 00:39, rusi wrote: > > I had a paper some years ago on why C is a horrible language *to teach with* > > http://www.the-magus.in/Publications/chor.pdf > Thanks for this Rusi, I just read it and it describes very well what I > think about our own C course. My choice quote from the beginning would > be "When the irrelevant becomes significant, the essentials become > obscured and incomprehensible." > (BTW is there any reason that the document is repeated twice in the same pdf?) Thanks for the heads-up -- some pdf generation issues I guess Is it ok now? Yeah I could clean up some more formatting some more but its 25 years now and Ive forgotten my troff!! More important the tone is not what I would use today. The point I was trying to make then was: C is an unsuitable language to TEACH PROGRAMMING WITH because it fills students' brains with irreleventia Once one knows the stuff, C is a NEAT programming language. IOW its a question of learning-curve not the content. From oscar.j.benjamin at gmail.com Wed Dec 18 05:06:26 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 18 Dec 2013 10:06:26 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <23663ad2-9b3f-4950-87af-ea1be504234b@googlegroups.com> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <23663ad2-9b3f-4950-87af-ea1be504234b@googlegroups.com> Message-ID: On 18 December 2013 09:18, rusi wrote: >> (BTW is there any reason that the document is repeated twice in the same pdf?) > > Thanks for the heads-up -- some pdf generation issues I guess > > Is it ok now? Yes. Also it definitely reads better without the twocolumn format. Oscar From feliphil at gmx.net Tue Dec 17 10:22:33 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 17 Dec 2013 16:22:33 +0100 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: <20131217162233.1538587c27b6a27df9a33aee@gmx.net> > > It's not just the abysmally appalling, hideously horrifying syntax. > > At about everything about C is just *not* "made for human beings" > > imho. > > I've never heard C syntax reviled quite so intensely. What syntax do > you like, out of curiosity? Pascal, Python, if written by someone who uses semantic identifiers and avoids to use C(++)/Java-isms. I've seen Eiffel as well (without understanding it) and it didn't look ridiculous to me. In short, syntax that contains the strict minimum of "special" characters (delimiting lists etc. with brackets is ok to me), and almost exclusively human readable words. Although, if you push it to the extreme; Applescript is nice to read, but much less nice to write imho... :-/ C, C++, Java, Javascript, PHP, Perl etc., however, are just unspeakable . BTW; Yes, I do *hate* those C(++)-isms (or Java-isms) that have started to sneak into Python in the past ~10 years. Using e.g. == for comparisons is just braindead. Use := for assignments instead, because that's mathematical syntax. And that "@" for decorators is, well, who proposed it? I'd like to cut off all his fingers with a bolt cutter. The same for people who use augmented assignments, "syntax shortcuts" or abbrvtd idtfrs. Ship them all to Fukushima, one way, no return ticket. Learn to touch-type, get an editor with decent syntax completion or just stop wreaking havoc to the world economy with your laziness. Code is read a hundred times more often than it is typed. Sincerely, Wolfgang From feliphil at gmx.net Thu Dec 19 10:14:13 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 19 Dec 2013 16:14:13 +0100 Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217162233.1538587c27b6a27df9a33aee@gmx.net> Message-ID: <20131219161413.b011741a67dba9eb892dd500@gmx.net> > > I've never heard C syntax reviled quite so intensely. What syntax > > do you like, out of curiosity? > > Pascal, Python, if written by someone who uses semantic identifiers > and avoids to use C(++)/Java-isms. I've seen Eiffel as well (without > understanding it) and it didn't look ridiculous to me. Nor did a recent dialect of Cobol (since someone else mentioned it) horrify me at first sight to the point all those C-derivatives do. I also get to use SQL a bit (instead of those "query builders" that I consider as garbage), although that's just for databases of course. Verbosity is definitely A Good Thing. In fact, thinking of it, a really good language should imho *require* verbosity (how about a *minimum* length - or maybe even a dictionary-based sanity check - for identifiers?), since that already keeps all those lazy morons away who think that "shortcuts are cool". Sincerely, Wolfgang From greg.ewing at canterbury.ac.nz Thu Dec 19 15:42:04 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 20 Dec 2013 09:42:04 +1300 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: <20131219161413.b011741a67dba9eb892dd500@gmx.net> References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217162233.1538587c27b6a27df9a33aee@gmx.net> <20131219161413.b011741a67dba9eb892dd500@gmx.net> Message-ID: Wolfgang Keller wrote: > In fact, thinking of it, a really good language should imho *require* > verbosity (how about a *minimum* length - or maybe even a > dictionary-based sanity check - for identifiers?), since that already > keeps all those lazy morons away who think that "shortcuts are cool". No, that wouldn't be a really good language, that would be a language designed by someone with a very shallow understanding of what makes programs understandable. A piece of code such as for (i = 0; i < numThings; i++) total[i] += things[i]; is NOT improved by rewriting it as for (theLoopIndex = 0; theLoopIndex < numThings; theLoopIndex++) total[theLoopIndex] += things[theLoopIndex]; Quite the reverse, IMO. -- Greg From rosuav at gmail.com Thu Dec 19 15:51:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Dec 2013 07:51:16 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> <20131217162233.1538587c27b6a27df9a33aee@gmx.net> <20131219161413.b011741a67dba9eb892dd500@gmx.net> Message-ID: On Fri, Dec 20, 2013 at 7:42 AM, Gregory Ewing wrote: > A piece of code such as > > for (i = 0; i < numThings; i++) > total[i] += things[i]; > > is NOT improved by rewriting it as > > for (theLoopIndex = 0; theLoopIndex < numThings; theLoopIndex++) > total[theLoopIndex] += things[theLoopIndex]; > > Quite the reverse, IMO. Wholeheartedly agreed. The only improvement I would make would be to declare i in the if block (valid in C++ and some of the more recent C standards), to emphasize the locality of the variable. ChrisA From roy at panix.com Mon Dec 9 11:06:06 2013 From: roy at panix.com (Roy Smith) Date: Mon, 09 Dec 2013 11:06:06 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: Message-ID: In article , Chris Angelico wrote: > On Mon, Dec 9, 2013 at 11:23 PM, Oscar Benjamin > wrote: > > 1) Some people felt that Python is not an "industry standard" unlike > > C/C++/Java and that it is not as good for employability. > > Disprove that by checking any job listing site in your area/industry. > You'll find plenty of Python jobs there. > > ChrisA I have access to the resume search feature on careers.stackoverflow.com. Just for fun, I ran the following searches (for skills advertised by people who have listed their resumes): C 1k C++ 1.3k Java 1.7k Python 1.2k The search qualifiers were "within 200 miles of the United States", "legal right to work here required", "full time", "exclude students", and, "only active candidates". Not sure what the proves, other than these are the languages people who are looking for jobs know (or at least claim to know). From rosuav at gmail.com Mon Dec 9 11:25:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Dec 2013 03:25:55 +1100 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: On Tue, Dec 10, 2013 at 3:06 AM, Roy Smith wrote: > Not sure what the proves, other than these are the languages people who > are looking for jobs know (or at least claim to know). That's the converse of what I was talking about. Employability of a skill depends on how many employers are looking for that skill; sightings on resumes aren't quite that. But since people will put on their resumes what they think employers will actually care about (mine doesn't mention my ability to use Q-BASIC's CALL ABSOLUTE command to make use of a mouse), they're going to be at least somewhat connected. Of course, it might be that stackoverflow careers attracts Python programmers and something else attracts C programmers, but unless there's some really major skew, I'd say it's still at least somewhat valid to point to that and show that Python matters to employment. ChrisA From tjreedy at udel.edu Mon Dec 9 14:57:18 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Dec 2013 14:57:18 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: On 12/9/2013 7:23 AM, Oscar Benjamin wrote: > Hi all, > > I work in a University Engineering faculty teaching, among other > things, programming. In our last meeting about improving our teaching > syllabus and delivery we've identified the first year programming > courses as an area where there is room for improvement and we're > considering (mainly on my suggestion) switching to using Python as the > first programming language that we use to introduce our students to > programming. I'm interested to know if anyone can share experience of > a similar situation or can point to any case studies about this. A few years ago, MIT switched from Scheme (which I believe originated at MIT) to Python for its first course. There might faculty blogs discussing the reasons. In any case, the course is one of MIT's free online offerings. There is a draft of a syllabus for your school. Certainly, most of the concept taught in the current C course could be taught with Python instead. -- Terry Jan Reedy From oscar.j.benjamin at gmail.com Tue Dec 10 05:42:53 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 10 Dec 2013 10:42:53 +0000 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: On 9 December 2013 19:57, Terry Reedy wrote: > On 12/9/2013 7:23 AM, Oscar Benjamin wrote: >> >> Hi all, >> >> I work in a University Engineering faculty teaching, among other >> things, programming. In our last meeting about improving our teaching >> syllabus and delivery we've identified the first year programming >> courses as an area where there is room for improvement and we're >> considering (mainly on my suggestion) switching to using Python as the >> first programming language that we use to introduce our students to >> programming. I'm interested to know if anyone can share experience of >> a similar situation or can point to any case studies about this. > > > A few years ago, MIT switched from Scheme (which I believe originated at > MIT) to Python for its first course. There might faculty blogs discussing > the reasons. Thanks Terry. The best I've found is this: http://cemerick.com/2009/03/24/why-mit-now-uses-python-instead-of-scheme-for-its-undergraduate-cs-program/ It doesn't really describe why Python was chosen and I can't find any actual evaluation of how well it worked but I guess if they haven't backed out of the decision then that says something. > In any case, the course is one of MIT's free online offerings. > There is a draft of a syllabus for your school. Certainly, most of the > concept taught in the current C course could be taught with Python instead. I guess you mean this: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/ The description there sounds like exactly what we're aiming for: ''' This subject is aimed at students with little or no programming experience. It aims to provide students with an understanding of the role computation can play in solving problems. It also aims to help students, regardless of their major, to feel justifiably confident of their ability to write small programs that allow them to accomplish useful goals. The class will use the Python programming language. ''' I'll have a bit of a look at that. In our case the course would probably be called something like "Introduction to [scientific] programming using Python" so we may want to put more time into numpy/matplotlib etc than some other courses would. Oscar From rustompmody at gmail.com Tue Dec 10 10:36:19 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 10 Dec 2013 07:36:19 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <90312db8-18ae-4af4-abcb-f31e54da702b@googlegroups.com> On Tuesday, December 10, 2013 4:12:53 PM UTC+5:30, Oscar Benjamin wrote: > On 9 December 2013 19:57, Terry Reedy wrote: > > On 12/9/2013 7:23 AM, Oscar Benjamin wrote: > >> Hi all, > >> I work in a University Engineering faculty teaching, among other > >> things, programming. In our last meeting about improving our teaching > >> syllabus and delivery we've identified the first year programming > >> courses as an area where there is room for improvement and we're > >> considering (mainly on my suggestion) switching to using Python as the > >> first programming language that we use to introduce our students to > >> programming. I'm interested to know if anyone can share experience of > >> a similar situation or can point to any case studies about this. > > A few years ago, MIT switched from Scheme (which I believe originated at > > MIT) to Python for its first course. There might faculty blogs discussing > > the reasons. > Thanks Terry. The best I've found is this: > http://cemerick.com/2009/03/24/why-mit-now-uses-python-instead-of-scheme-for-its-undergraduate-cs-program/ There's this http://danweinreb.org/blog/why-did-mit-switch-from-scheme-to-python which seems to have died -- the internet archive has it here https://web.archive.org/web/20120429151818/http://danweinreb.org/blog/why-did-mit-switch-from-scheme-to-python Neither really talks of why python was chosen In that direction you may want to see why Java has been ousted from CMU: http://existentialtype.wordpress.com/2011/03/15/teaching-fp-to-freshmen/ From bgailer at gmail.com Mon Dec 9 15:53:30 2013 From: bgailer at gmail.com (bob gailer) Date: Mon, 09 Dec 2013 15:53:30 -0500 Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <52A62DCA.4070101@gmail.com> On 12/9/2013 7:23 AM, Oscar Benjamin wrote: [snip] > I'm interested to know if anyone can share experience of > a similar situation or can point to any case studies about this. Taking the opposite perspective from Gene: I think Python is great as an intro to computing and programming. Give a student a tool with which he can be productive quickly. and with minimal effort. Understanding the real machine may be of interest to some but is not essential .I'd make that "later" and optional. Do you teach potential drivers how the engine works before letting them drive? Caution: having listened to many students express their suffering on these lists I recommend: beta test any course before putting it into production. be sure you give the student what he needs to understand and take the next step. be sure your instructors are willing to help the students. it is, after all, the job of the instructor to ensure the student succeeds. From roy at panix.com Mon Dec 9 16:32:34 2013 From: roy at panix.com (Roy Smith) Date: Mon, 09 Dec 2013 16:32:34 -0500 Subject: Experiences/guidance on teaching Python as a first programming language References: Message-ID: In article , bob gailer wrote: > Understanding the real machine may be of interest to some but is not > essential. Surprisingly (to myself, anyway), I agree. Languages like C, Fortran, and Java, are fairly close to the machine. They all expose (C more than the others) fundamental machine features such as hardware data types (various sizes of ints and floats) and addresses. Understanding how a computer works gives you added understanding of how the higher level language you're using works. But, Python operates at a higher level of abstraction. In a sense, understanding how a computer works is a hinderance to learning Python. Look at all the beginner questions we get regarding what >>> a = 47 means in Python. People have a mental picture of a 32-bit (or maybe 64-bit) integer value 47 being placed into some pre-allocated memory location, and that interferes with their understanding of what's really happening in Python. Likewise, they have incorrect expectations about what happens if that follow that up with >>> b = a ** 100 From rantingrickjohnson at gmail.com Mon Dec 16 22:26:37 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 16 Dec 2013 19:26:37 -0800 (PST) Subject: Experiences/guidance on teaching Python as a first programming language In-Reply-To: References: Message-ID: <61e7f602-f9aa-45c5-a3a4-c99a7eadf24e@googlegroups.com> On Monday, December 9, 2013 2:53:30 PM UTC-6, bob gailer wrote: > Taking the opposite perspective from Gene: I think Python > is great as an intro to computing and programming. Give a > student a tool with which he can be productive quickly. > and with minimal effort. Understanding the real machine > may be of interest to some but is not essential .I'd make > that "later" and optional. Do you teach potential drivers > how the engine works before letting them drive? No, not a scientific understanding of the process by which chemical energy is converted to mechanical energy, or even the demanding study of fuel efficiency, or much less the historical evolution of engines from the time of the Aeolipile But, as with any mental evolution, many tangential areas of study need to be considered for both the wholistic and practical application of said knowledge. The first course of study for any "would be" motor vehicle operator is the fundamental forces of classical physics that effect ALL bodies in motion -- acceleration, velocity, inertia, blah-blah-blah, but, more importantly, how these forces are amplified to extreme danger during the operation of a motor vehicle. Secondly even though a student of "motorized locomotion" need not understand the inner workings of an internal combustion engine, he would behoove himself to study some basic and practical knowledge of the generalized system. 1. A modern motor vehicle converts chemical energy stored in fuel into mechanical energy via and internal explosion. The major components of a modern motor vehicle include: Engine, Transmission and Drive-train -- Nuff said. 2. Mechanical components require fluids to reduce friction and remove heat from the system, therefore, a working knowledge of fluid levels and locations is vital. Furthermore, fluids are color coded. Oil is black; most transmission fluids are red; coolant is colored yellow (or green) and mixed with water. **As a side note, you might want to be aware that ethylene glycol, whilst quite poisonous, tastes sweet. That fact may seem inconsequential until your beloved pet drinks leaking coolant water, quickly goes blind, and dies a slow horrible death. 3. Vehicles require lights and signals for safety and useability. An understanding of the proper locations and procedures for periodic testing is vital to safe operation. Same for other safety devises and interfaces. 4. Obviously some rules of the road are applicable. Your car will not be the ONLY vehicle on the road, therefor your must understand how to interface with other drivers, navigate adverse road conditions, and react to unexpected situations that can arise at any time. ============================================================ Conclusion: ============================================================ The main points i outlined are merely a blip on the radar of the many tangential points of study, however, they are quite relevant to proper operation of a motor vehicle. Most of you can probably draw the parallels to programming from these examples. My opinion is that problem solving should be covered before any language is even discussed or any code is written. Too many people lack basic problem solving skills. Look, if you can't write up (or imagine) the "general" steps that are required to solve your problem, then how the heck do you expect to write code to solve the problem? And let's just get one thing strait from day uno for all you "perspective programmers" out there: If the idea of banging your head on a desk for days only to find out that some stupid API does not work as expected, or was poorly designed, or that, GOD FORBID... you made the dumbest mistake ever! Ha Ha Ha! If the idea of that kind of mind numbing detective work is not fun for you, well, you're in good company because i don't always enjoy it either... HOWEVER! if you're not driven by the satisfaction of finding the answer; by a burning desire to solve the problem; by an unflinching will not to be defeated by any bug -- because the answer is always out there, you just have to find it -- well then, programming might not be for you. But i'm just wasting my time because soon you'll discover Python list and Stack overflow and from these sources flows an endless supply of free labor. Teach a man to Google and others program for a day. Teach him to problem solve, and he programs for life. From steve at pearwood.info Mon Dec 16 23:05:12 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 17 Dec 2013 04:05:12 GMT Subject: Experiences/guidance on teaching Python as a first programming language References: <61e7f602-f9aa-45c5-a3a4-c99a7eadf24e@googlegroups.com> Message-ID: <52afcd78$0$29973$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Dec 2013 19:26:37 -0800, Rick Johnson wrote: > **As a side note, you might want to be aware that ethylene glycol, > whilst quite poisonous, tastes sweet. That fact may seem > inconsequential until your beloved pet drinks leaking coolant water, > quickly goes blind, and dies a slow horrible death. /s/beloved pet/Russian tank crew/ -- Steven From conorh at conorh.net Mon Dec 9 18:25:39 2013 From: conorh at conorh.net (Conor Hughes) Date: Mon, 09 Dec 2013 15:25:39 -0800 Subject: Experiences/guidance on teaching Python as a first programming language References: Message-ID: <8761qxfvyk.fsf@conorh.net> Terry Reedy writes: > A few years ago, MIT switched from Scheme (which I believe originated > at MIT) to Python for its first course. There might faculty blogs > discussing the reasons. In any case, the course is one of MIT's free > online offerings. Berkeley recently made the same transition. They had been mirroring the MIT Scheme-based 6.001 quite closely; I believe the Python-based replacement at Berkeley doesn't concern itself with tracking the new 6.001 at MIT. In any case, much (read: some) ink was spilled and consternation felt about the transition, but all in all my impression was that it went OK. IMHO, if you're going to switch from Scheme to something else for first-time programmers, Python is quite nice, as it reads exceptionally well and is very close to pseudocode in appearance sometimes. Of course, given that I didn't learn on Python, my opinions may be colored by prior experience. From fred.sells at adventistcare.org Mon Dec 9 14:24:22 2013 From: fred.sells at adventistcare.org (Sells, Fred) Date: Mon, 9 Dec 2013 19:24:22 +0000 Subject: noobie needs help with ctypes Message-ID: I'm using python 2.6 on Linux/CentOs 6.x I'm getting ctypes to work, but getting stuck on the use of .argtypes. Can someone point out what I'm doing. This is my first use of ctypes and it looks like I'm getting different definitions in stackoverflow that may correspond to different version of python. Here is my code. Without the restype/argtypes it works, but I cannot figure out how to define argtypes to match the data. mylibrary = ctypes.CDLL(LIBRARY_PATH) mdsconvert = mylibrary.RugVersionConverter mdsconvert.restype = ctypes.c_int mdsconvert.argtypes = [ charptr, #flat buffer of mds 3.0 data ctypes.c_buffer, #computed flat buffer of mds 2.0 data ctypes.c_buffer #version set to "1.00.4" in c++, never used ] def convertMds2to3(mds30buffer): mds20 = ctypes.create_string_buffer('\000'*3000) t = ctypes.create_string_buffer('\000'*30) success = mdsconvert(mds30buffer, ctypes.byref(mds20), ctypes.byref(t) ) print 'convert %s to %s success=%s version=%s' % (len(mds30buffer), len(mds20.value), success, t.value) return mds20.value ------------------------------- C++ code looks like this ------------------------------------------------------- extern "C" int RugVersionConverter( char * sInputRecord, char * MDS2_Rec, char * Version ); where sInputRecord is input and MDS2_Rec and Version are output. From tjreedy at udel.edu Mon Dec 9 15:15:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Dec 2013 15:15:09 -0500 Subject: noobie needs help with ctypes In-Reply-To: References: Message-ID: On 12/9/2013 2:24 PM, Sells, Fred wrote: > I'm using python 2.6 on Linux/CentOs 6.x I would use the latest 2.7 (or 3.3) for a new project if at all possible. > I'm getting ctypes to work, but getting stuck on the use of .argtypes. Can someone point out what I'm doing. This is my first use of ctypes and it looks like I'm getting different definitions in stackoverflow that may correspond to different version of python. In particular, I am sure that there have been bugfixes for ctypes. -- Terry Jan Reedy From joel.goldstick at gmail.com Mon Dec 9 15:22:08 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 9 Dec 2013 15:22:08 -0500 Subject: noobie needs help with ctypes In-Reply-To: References: Message-ID: On Mon, Dec 9, 2013 at 3:15 PM, Terry Reedy wrote: > On 12/9/2013 2:24 PM, Sells, Fred wrote: > >> I'm using python 2.6 on Linux/CentOs 6.x >> > > I would use the latest 2.7 (or 3.3) for a new project if at all possible. > > I seem to recall that Centos needs 2.6 as default python for its own purposes, so you need to install another version without messing with 2.6. VirtualEnv might help. > I'm getting ctypes to work, but getting stuck on the use of .argtypes. >> Can someone point out what I'm doing. This is my first use of ctypes and >> it looks like I'm getting different definitions in stackoverflow that may >> correspond to different version of python. >> > > In particular, I am sure that there have been bugfixes for ctypes. > > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From fred.sells at adventistcare.org Mon Dec 9 21:27:28 2013 From: fred.sells at adventistcare.org (Sells, Fred) Date: Tue, 10 Dec 2013 02:27:28 +0000 Subject: noobie needs help with ctypes In-Reply-To: References: Message-ID: My management requires that we stick with the version that comes with CentOs which is 2.6. I know that it?s possible to have multiple versions co-resident with or without virtualenv, but policy is policy ? From: Python-list [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of Joel Goldstick Sent: Monday, December 09, 2013 3:22 PM To: Terry Reedy Cc: python-list at python.org Subject: Re: noobie needs help with ctypes On Mon, Dec 9, 2013 at 3:15 PM, Terry Reedy > wrote: On 12/9/2013 2:24 PM, Sells, Fred wrote: I'm using python 2.6 on Linux/CentOs 6.x I would use the latest 2.7 (or 3.3) for a new project if at all possible. I seem to recall that Centos needs 2.6 as default python for its own purposes, so you need to install another version without messing with 2.6. VirtualEnv might help. I'm getting ctypes to work, but getting stuck on the use of .argtypes. Can someone point out what I'm doing. This is my first use of ctypes and it looks like I'm getting different definitions in stackoverflow that may correspond to different version of python. In particular, I am sure that there have been bugfixes for ctypes. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Mon Dec 9 22:27:47 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Dec 2013 03:27:47 GMT Subject: noobie needs help with ctypes References: Message-ID: <52a68a33$0$2829$c3e8da3$76491128@news.astraweb.com> On Tue, 10 Dec 2013 02:27:28 +0000, Sells, Fred wrote: > My management requires that we stick with the version that comes with > CentOs which is 2.6. I know that it?s possible to have multiple > versions co-resident with or without virtualenv, but policy is policy ? And a perfectly reasonable policy it is too. Python 2.6 is still supported by Centos and RedHat, so it's not obsolete yet. What's not reasonable though is this gunk in your post: > xmlns:o="urn:schemas-microsoft-com:office:office" > xmlns:w="urn:schemas-microsoft-com:office:word" > xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" > xmlns="http://www.w3.org/TR/REC-html40"> > > >