From pjh at nanoworks.com Fri Dec 1 10:31:24 2017 From: pjh at nanoworks.com (Percival John Hackworth) Date: Fri, 01 Dec 2017 07:31:24 -0800 Subject: [OT] - Re: Has anyone worked on docker with windows References: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> <0001HW.1FCFBA76014D790414BB022CF@news.individual.net> <1fdb9932-dba6-8cb8-5eeb-f9237b4212e6@gmail.com> Message-ID: <0001HW.1FD1AD4C002F105214F9732CF@news.individual.net> On 30-Nov-2017, Michael Torrie wrote (in article): > Marking this message as off topic, since it has nothing much to do with > Python and Python programming. In fact this whole thread should have > been started on a Docker-specific forum, mailing list, or USENET group. > To the original poster: you should visit the Docker web site and access > the community resources they have there: > > https://www.docker.com/docker-community > > On 11/29/2017 09:03 PM, Percival John Hackworth wrote: > > To clarify, I think the OP was asking if they could Windows inside a Docker > > container. Since Docker uses the kernel of the OS it's running on, that > > would > > mean it would have to run natively on Windows. > > Unless things have changed Docker has always been about running Linux > software in Linux containers on all supported OSes, which includes Mac > and Windows. On Mac and Windows this requires running a VM, although now > with Docker for Windows it can run the Linux containers on the > integrated HyperV virtualization system, so you don't necessarily need > to install VirtualBox or VMWare. > > https://www.microsoft.com/en-ca/cloud-platform/containers > > > Back in January, it didn't run on Windows. Now apparently you can run a > > Windows 10 or Server 2016 environment in a container. I would think, given > > the architecture of Docker, that you can only do this on a Windows machine, > > not a Linux box. So the ability to containerize an application on Linux and > > run it anywhere Docker is installed (even MacOS) only applicable to Linux > > apps. > > Docker has run on Windows since very early on. Not quite sure why you > say it didn't run on Windows back in January. > > As for running Windows applications in a Windows container, this is not > possible using any container technology I'm aware of. I'm sure MS could > one day build Windows-centric containerization into Windows, but there's > no support now. I guess they haven't figured out how to work out the > licensing. Proprietary licensing and containers would be complex. When I said "Didn't run on Windows" I should have written "Didn't run on Windows *natively*". Back then, Docker had come out with a MacOS version that stopped using the Docker-machine CoreOS VM and Virtual Box and ran directly on supported Intel-based MacOS. My 2009 MacPro desktop is to old to run the right processor and boot ROM to run Docker natively but my 2011 laptop has no problem. In May, I played with Docker on Windows 10 and discovered their new distribution model of a free community edition and an paid Enterprise edition. Neither supported running *native* Windows and still required docker-machine and a Virtual Box VM to run Linux Kernel 3.10 or greater based containers. You could not, at that time, run Windows anything inside a container. Apparently, today in Dec 2017, you can run Windows inside a docker container natively on a Windows 10 or Windows 2016 server machine without a VM. And it uses hyperV or some other technology to run a Linux container with a Linux VM natively on Windows 10/Windows 2016 Server. Or so the site says. Licensing Linux software depends on the software. Windows, as you say, is complex. Or as Steve Jobs said "a huge bag of hurt" (he was referring to licensing and support for BluRay on MacOS at the time). From pengyu.ut at gmail.com Fri Dec 1 10:55:25 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 1 Dec 2017 09:55:25 -0600 Subject: How to get the redirected URL only but not the actual content? Message-ID: Hi, Does anybody know how only get the redirected URL but not the actual content? I guess the request module probably should be used. But I am not sure how to do it exactly. Can somebody show me the best way to request (https://doi.org/10.1109/5.771073) and get the URL (http://ieeexplore.ieee.org/document/771073/)? Thanks. -- Regards, Peng From __peter__ at web.de Fri Dec 1 11:08:47 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Dec 2017 17:08:47 +0100 Subject: How to get the redirected URL only but not the actual content? References: Message-ID: Peng Yu wrote: > Hi, > > Does anybody know how only get the redirected URL but not the actual > content? > > I guess the request module probably should be used. But I am not sure > how to do it exactly. > > Can somebody show me the best way to request > (https://doi.org/10.1109/5.771073) and get the URL > (http://ieeexplore.ieee.org/document/771073/)? Thanks. > How about >>> from urllib.request import urlopen >>> urlopen("https://doi.org/10.1109/5.771073").url 'http://ieeexplore.ieee.org:80/document/771073/?reload=true' ? From pengyu.ut at gmail.com Fri Dec 1 22:32:39 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 1 Dec 2017 21:32:39 -0600 Subject: How to get the redirected URL only but not the actual content? In-Reply-To: References: Message-ID: Where is `?reload=true` from? How to just get the redict URL that one would get from the browser? Thanks. > 'http://ieeexplore.ieee.org:80/document/771073/?reload=true' -- Regards, Peng From p.f.moore at gmail.com Sat Dec 2 05:27:04 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 2 Dec 2017 10:27:04 +0000 Subject: How to get the redirected URL only but not the actual content? In-Reply-To: References: Message-ID: On 2 December 2017 at 03:32, Peng Yu wrote: > Where is `?reload=true` from? How to just get the redict URL that one > would get from the browser? Thanks. > >> 'http://ieeexplore.ieee.org:80/document/771073/?reload=true' The reload=true comes because http://ieeexplore.ieee.org/document/771073/ is itself redirected to that location: >curl -I http://ieeexplore.ieee.org/document/771073/ HTTP/1.1 302 Moved Temporarily Date: Sat, 02 Dec 2017 10:25:58 GMT Location: http://ieeexplore.ieee.org:80/document/771073/?reload=true Set-Cookie: JSESSIONID=YewWwt7dRSRhQWpfvW_L_pCovlFPKnyDULFtYJGxwvaIvmv8-RK-!-1840538570; path=/; HttpOnly;HttpOnly Set-Cookie: ERIGHTS=null; domain=ieeexplore.ieee.org; expires=Thu, 01-Jan-1970 01:00:00 GMT; path=/;HttpOnly Set-Cookie: ipCheck=109.154.64.43; domain=ieeexplore.ieee.org; path=/;HttpOnly Set-Cookie: ipCheck=109.154.64.43; domain=ieeexplore.ieee.org; path=/;HttpOnly Set-Cookie: cookieCheck=true; domain=ieeexplore.ieee.org; path=/;HttpOnly X-XSS-Protection: 1 Set-Cookie: WLSESSION=186802828.20480.0000; expires=Sun, 03-Dec-2017 10:25:58 GMT; path=/; Httponly Set-Cookie: TS011813a0=012f350623b6ced9dc5148879303ea57ba3f9321e686d26e43e83dddc173810cbaa92efa0046e79b1666b3f14f416143c59004edd9a10f9c23f67089ad348420304ac91dcfd756c69a4bbb7c0afe436aadb111a234; Path=/ Set-Cookie: TS01d430e1=012f3506230b0f867dbbdc2d8cd9812cc6cda6004b86d26e43e83dddc173810cbaa92efa00939a6282cc7ad5b9b80ddea276f6b5409df42e43a52ed561e1234df4ab341c2f3974c06b59548aab1e30a871ec4efc9bba1a756faf9076574ae4a4f67b57fa79856f016141e55bb9497d8dc4bbd4037c; path=/; domain=ieeexplore.ieee.org Transfer-Encoding: chunked Paul From __peter__ at web.de Sat Dec 2 05:49:49 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Dec 2017 11:49:49 +0100 Subject: How to get the redirected URL only but not the actual content? References: Message-ID: Paul Moore wrote: > On 2 December 2017 at 03:32, Peng Yu wrote: >> Where is `?reload=true` from? How to just get the redict URL that one >> would get from the browser? Thanks. >> >>> 'http://ieeexplore.ieee.org:80/document/771073/?reload=true' > > The reload=true comes because > http://ieeexplore.ieee.org/document/771073/ is itself redirected to > that location: > >>curl -I http://ieeexplore.ieee.org/document/771073/ > HTTP/1.1 302 Moved Temporarily > Date: Sat, 02 Dec 2017 10:25:58 GMT > Location: http://ieeexplore.ieee.org:80/document/771073/?reload=true > Set-Cookie: > JSESSIONID=YewWwt7dRSRhQWpfvW_L_pCovlFPKnyDULFtYJGxwvaIvmv8- RK-!-1840538570; > path=/; HttpOnly;HttpOnly Set-Cookie: ERIGHTS=null; > domain=ieeexplore.ieee.org; expires=Thu, 01-Jan-1970 01:00:00 GMT; > path=/;HttpOnly Set-Cookie: ipCheck=109.154.64.43; > domain=ieeexplore.ieee.org; path=/;HttpOnly Set-Cookie: > ipCheck=109.154.64.43; domain=ieeexplore.ieee.org; path=/;HttpOnly > Set-Cookie: cookieCheck=true; domain=ieeexplore.ieee.org; path=/;HttpOnly > X-XSS-Protection: 1 Set-Cookie: WLSESSION=186802828.20480.0000; > expires=Sun, 03-Dec-2017 10:25:58 GMT; path=/; Httponly > Set-Cookie: > TS011813a0=012f350623b6ced9dc5148879303ea57ba3f9321e686d26e43e83dddc173810cbaa92efa0046e79b1666b3f14f416143c59004edd9a10f9c23f67089ad348420304ac91dcfd756c69a4bbb7c0afe436aadb111a234; > Path=/ Set-Cookie: > TS01d430e1=012f3506230b0f867dbbdc2d8cd9812cc6cda6004b86d26e43e83dddc173810cbaa92efa00939a6282cc7ad5b9b80ddea276f6b5409df42e43a52ed561e1234df4ab341c2f3974c06b59548aab1e30a871ec4efc9bba1a756faf9076574ae4a4f67b57fa79856f016141e55bb9497d8dc4bbd4037c; > path=/; domain=ieeexplore.ieee.org Transfer-Encoding: chunked But why don't you see that in the browser? The server probably gives a user agent specific response. You may be able to "deceive" it with a library like mechanize (python2- only). From martin.schoon at gmail.com Sat Dec 2 12:55:12 2017 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 2 Dec 2017 17:55:12 GMT Subject: Pros and cons of Python sources? References: <20171128212955.GA77940@cskk.homeip.net> Message-ID: Den 2017-11-29 skrev Martin Sch??n : > Den 2017-11-28 skrev Cameron Simpson : >> On 28Nov2017 21:23, Martin Sch??n wrote: >>>The reason I think all is not well is the fact that pip list no only >>>results in a list of packages but at the end of the list (which does >>>not look complete) there is a bunch of error messages. >> >> Please post them. Maybe someone has some insight. (Also post the pip command >> itself producing the messages.) >> > From pip.log: > > /usr/bin/pip run on Tue Nov 28 22:54:09 2017 > apptools (4.2.1) > apt-xapian-index (0.47) > arandr (0.1.7.1) > argparse (1.2.1) > Problem solved -- I think. Here is how: Going through all Python 2.7 packages in Synaptic (this is in Debian) I marked every package that did not seem to impact anything else plus python-pip for complete removal and went ahead and removed them. I then re-installed python-pip and whatever it felt it needed. After that I ran pip list -- no errors or warnings whatsoever! Finally I installed packages my laptop has but my desktop box now was missing. I have not tampered with my laptop so I think it should be an OK template for my Python packages. pip list is still OK and what little else I have tested also works. /Martin (a little wiser regarding Python and pip) From python at bladeshadow.org Sun Dec 3 00:25:54 2017 From: python at bladeshadow.org (Python) Date: Sun, 03 Dec 2017 17:25:54 +1200 Subject: urllib2 urlopen takes too much time Message-ID: <231985067@f38.n261.z1.binkp.net> On Sun, Dec 03, 2017 at 09:49:45AM -0800, cpollio at vt.edu wrote: > On Tuesday, June 23, 2009 at 11:09:30 PM UTC-4, Aahz wrote: > > In article , > > =?UTF-8?Q?Filip_Gruszczy=C5=84ski?= wrote: > > > > > >I have encountered a performance problem using suds, which was traced > > >down to _socket.recv. I am calling some web services and each of them > > >uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen, > > >while the rest of the call is finished in milliseconds. > > > > What happens if you use urlopen() by itself? > > I am having the same issue. Did you ever figure out a solution? > The time delay is also the same, from .2 to .25 sec. I need to stay > with urlopen though so I can do a custom request header Depending on your network conditions, this doesn't seem all that outrageous. Using tcpdump or some other packet sniffer should reveal what is going on, but most likely urlopen() needs to do all of the following, every time it is called: - resolve the address via DNS + 1 round trip: DNS request + response; possibly more if DNS doesn't have host entry and forwards... - initiate a TCP connection + three way handshake = 1.5 round trip times - send the request (.5 round trip) - wait for server processing (unknown time) - receive the response (.5 round trip time) If the DNS server is busy, or the SOAP server is busy, add that latency to the mix. Assuming NO latency due to server load, you're still looking at 3.5 round trips to service the request, or 7 one-way (possibly 6, if the ACK contains the request, which IIRC is allowed). .2s / 7 = ~29ms, so if the latency between server and client is 29ms or higher, that explains everything. On a LAN I'd hope for much better than 29ms latency (1ms is more typical), but it's not outside the realm of possibility depending on network architecture and load. Ping to the server will tell you that... if your network isn't blocking ICMP. If the C# app is faster, my guess would be it is caching the DNS response and/or maintaining persistent connections to the server, whereas urllib isn't, though that's just a guess... I'm not familiar with the implementations of either. But again, a packet sniffer should show you exactly what's happening and who is being slow. From kpavan30 at gmail.com Sun Dec 3 00:30:12 2017 From: kpavan30 at gmail.com (pavan kopparthi) Date: Sun, 03 Dec 2017 17:30:12 +1200 Subject: pip3 file in Scripts folder is missing - Python installation - Tensor Message-ID: <363739592@f38.n261.z1.binkp.net> Hi, Installed Python 3.6.3 Amd64 in Windows 10 OS. Want to install Tensor flow using native pip as suggested... C:\> *pip3 install --upgrade tensorflow* But, observed that pip3 file in Scripts folder is missing. Also, Scripts folder is empty. Reg, Pavan Kumar K. <#m_1095693827828497751_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From tjol at tjol.eu Sun Dec 3 02:05:46 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 03 Dec 2017 19:05:46 +1200 Subject: Meaning of "Add Python to environment variables" Message-ID: <1664666607@f38.n261.z1.binkp.net> On 03/12/17 18:32, John Yeung wrote: > In the custom installation options for Python 3.6, what *exactly* does "Add Python to environment variables" mean? > > Which environment variables are we talking about? I imagine one of them would have to be PATH. Are there any others? If the note on the "PrependPath" option in https://docs.python.org/3/using/windows.html#installing-without-ui is complete (which I believe it is, but I couldn't swear to it), it's PATH and PATHEXT. -- Thomas From kpavan30 at gmail.com Sun Dec 3 07:00:13 2017 From: kpavan30 at gmail.com (pavan kopparthi) Date: Sun, 3 Dec 2017 17:30:13 +0530 Subject: pip3 file in Scripts folder is missing - Python installation - Tensor flow upgrade In-Reply-To: References: Message-ID: Hi, Installed Python 3.6.3 Amd64 in Windows 10 OS. Want to install Tensor flow using native pip as suggested... C:\> *pip3 install --upgrade tensorflow* But, observed that pip3 file in Scripts folder is missing. Also, Scripts folder is empty. Reg, Pavan Kumar K. <#m_1095693827828497751_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From dhananjaysingh091298 at gmail.com Sun Dec 3 08:48:42 2017 From: dhananjaysingh091298 at gmail.com (dhananjaysingh091298) Date: Mon, 04 Dec 2017 01:48:42 +1200 Subject: Please tell me how to execute python file in Ubuntu by double Message-ID: <207543188@f38.n261.z1.binkp.net> Respected Sir/Mam, I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. Sir please help me. From breamoreboy at gmail.com Sun Dec 3 09:09:50 2017 From: breamoreboy at gmail.com (breamoreboy) Date: Mon, 04 Dec 2017 02:09:50 +1200 Subject: How to use a regexp here References: <1521907012@f38.n261.z1.binkp.net> Message-ID: <2589498778@f38.n261.z1.binkp.net> On Monday, December 4, 2017 at 9:44:27 AM UTC, Cecil Westerhof wrote: > I have a script that was running perfectly for some time. It uses: > array = [elem for elem in output if 'CPU_TEMP' in elem] > > But because output has changed, I have to check for CPU_TEMP at the > beginning of the line. What would be the best way to implement this? > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof Use https://docs.python.org/3/library/stdtypes.html#str.startswith instead of the test for `in`. -- Kindest regards. Mark Lawrence. From manishti2004 at gmail.com Sun Dec 3 11:47:50 2017 From: manishti2004 at gmail.com (manishti2004 at gmail.com) Date: Sun, 3 Dec 2017 08:47:50 -0800 (PST) Subject: Blog for basic python programming Message-ID: <9289ac79-d920-4bce-8201-d888c6a73846@googlegroups.com> Python for Engineers - Solve Problems by Coding Solutions https://pythonforengineers.blogspot.in From ned at nedbatchelder.com Sun Dec 3 12:21:46 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 04 Dec 2017 05:21:46 +1200 Subject: How to use a regexp here Message-ID: <1914380400@f38.n261.z1.binkp.net> On 12/4/17 4:36 AM, Cecil Westerhof wrote: > I have a script that was running perfectly for some time. It uses: > array = [elem for elem in output if 'CPU_TEMP' in elem] > > But because output has changed, I have to check for CPU_TEMP at the > beginning of the line. What would be the best way to implement this? > No need for a regex just yet: ? ? ? array = [elem for elem in output if elem.startswith('CPU_TEMP')] (btw, note that the result of this expression is a list, not an array, for future Googling.) --Ned. From gallium.arsenide at gmail.com Sun Dec 3 12:32:57 2017 From: gallium.arsenide at gmail.com (John Yeung) Date: Sun, 3 Dec 2017 09:32:57 -0800 (PST) Subject: Meaning of "Add Python to environment variables" Message-ID: <5c92a792-57a4-40bc-b7ca-61cc3da1896f@googlegroups.com> In the custom installation options for Python 3.6, what *exactly* does "Add Python to environment variables" mean? Which environment variables are we talking about? I imagine one of them would have to be PATH. Are there any others? John Y. From joel.goldstick at gmail.com Sun Dec 3 12:41:20 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 04 Dec 2017 05:41:20 +1200 Subject: How to use a regexp here Message-ID: <1585134724@f38.n261.z1.binkp.net> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder wrote: > On 12/4/17 4:36 AM, Cecil Westerhof wrote: > >> I have a script that was running perfectly for some time. It uses: >> array = [elem for elem in output if 'CPU_TEMP' in elem] >> >> But because output has changed, I have to check for CPU_TEMP at the >> beginning of the line. What would be the best way to implement this? >> >> > No need for a regex just yet: > > array = [elem for elem in output if elem.startswith('CPU_TEMP')] > > (btw, note that the result of this expression is a list, not an array, for > future Googling.) > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > I like Ned's clear answer, but I'm wondering why the original code would fail because the substring is at the start of the line, since 'in' would still be true no matter where the desired string is placed. It would be useful to see some sample data of the old data, and the new data -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From cpollio at vt.edu Sun Dec 3 12:49:45 2017 From: cpollio at vt.edu (cpollio at vt.edu) Date: Sun, 3 Dec 2017 09:49:45 -0800 (PST) Subject: urllib2 urlopen takes too much time In-Reply-To: References: Message-ID: On Tuesday, June 23, 2009 at 11:09:30 PM UTC-4, Aahz wrote: > In article , > =?UTF-8?Q?Filip_Gruszczy=C5=84ski?= wrote: > > > >I have encountered a performance problem using suds, which was traced > >down to _socket.recv. I am calling some web services and each of them > >uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen, > >while the rest of the call is finished in milliseconds. > > What happens if you use urlopen() by itself? > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha I am having the same issue. Did you ever figure out a solution? The time delay is also the same, from .2 to .25 sec. I need to stay with urlopen though so I can do a custom request header From tjol at tjol.eu Sun Dec 3 13:05:46 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 3 Dec 2017 19:05:46 +0100 Subject: Meaning of "Add Python to environment variables" In-Reply-To: <5c92a792-57a4-40bc-b7ca-61cc3da1896f@googlegroups.com> References: <5c92a792-57a4-40bc-b7ca-61cc3da1896f@googlegroups.com> Message-ID: On 03/12/17 18:32, John Yeung wrote: > In the custom installation options for Python 3.6, what *exactly* does "Add Python to environment variables" mean? > > Which environment variables are we talking about? I imagine one of them would have to be PATH. Are there any others? If the note on the "PrependPath" option in https://docs.python.org/3/using/windows.html#installing-without-ui is complete (which I believe it is, but I couldn't swear to it), it's PATH and PATHEXT. -- Thomas From rantingrickjohnson at gmail.com Sun Dec 3 13:13:20 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 04 Dec 2017 06:13:20 +1200 Subject: How to use a regexp here References: <3502471932@f38.n261.z1.binkp.net> Message-ID: <3304169341@f38.n261.z1.binkp.net> Cecil Westerhof wrote: > Joel Goldstick writes: [...] > > I like Ned's clear answer, but I'm wondering why the > > original code would fail because the substring is at the > > start of the line, since 'in' would still be true no > > matter where the desired string is placed. It would be > > useful to see some sample data of the old data, and the > > new data @Goldstick "Inclusion testing" will return false positives when the target is part of a larger structure (aka: word). Observe: >>> s = "Complex is better than complicated." >>> "plex" in s True >>> "om" in s True >>> s.count("om") 2 I'm sure you already know this, and only made the comment because you did not have all the data, but i thought it would be good to mention for any lurkers who may be watching. > There is now also a line that starts with: PCH_CPU_TEMP: > And I do not want that one. Yes. But be aware, that while the `str.startswith(target)` method is indeed more efficient than a more generalized "inclusion test", if the target is not _always_ at the beginning of the string, then your code is going to skip right over valid match like a round stone skipping across the surface of a glass-smooth lake. But if you are sure the target will always be at the beginning of the string, then it is the best choice. > -- > Cecil Westerhof > Senior Software Engineer Perhaps it's not politically correct for me to say this, but i've never been one who cared much about political correctness, so i'm just going to say it... If you really are a "_Senior_ software engineer", and that title is not simply an ego-booster bestowed by your boss to a one-person-dev-team in order to avoid pay raises, then i would expect more competence from someone who holds such an esteemed title. And even *IF* you are only vaguely familiar with Python, and even *IF*, you rarely use Python in your projects, i don't think it's too much to ask of a ~~Senior~~ Software Engineer that they possess the basic skills required to peruse the Python documentation and decide which method is most appropriate for the situation at hand. And if you're using Python on a regular basis, then you should be intimately familiar with _all_ methods of each major type. Granted, your question did "hint" about the possibility of using a regexp (although, based on the data you have provided so far, a string method will suffice), but i would also expect a ~~Senior~~ Software Engineer to not only be knowledgeable of regexps, but also know when they are a strength and when they are a weakness. Now, there are one of two ways you can take this advice: (1) You can take it as a personal attack; get all huffy about it; drop to the floor and flail your arms and legs like a petulant two-year-old who didn't get the toy he wanted; and learn nothing in the process. or (2) You can take it as what it is -> constructive criticism; shower me with gratitude[1]; and become a better person and a better programmer in the process. The choice is yours. [1] Well, i had to sneak something in there for myself, after all, it is the season of giving, yes? O:-) Here comes santa claws... Here comes santa claws... ... From rantingrickjohnson at gmail.com Sun Dec 3 13:38:50 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 04 Dec 2017 06:38:50 +1200 Subject: Please tell me how to execute python file in Ubuntu by double References: <207543188@f38.n261.z1.binkp.net> Message-ID: <2826558770@f38.n261.z1.binkp.net> On Monday, December 4, 2017 at 3:49:11 AM UTC-6, dhananjays... at gmail.com wrote: > I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when > i am double click in python program (Dhananjay.py),it is > opening in Text Editor by Default in Ubuntu.I want to run > this program when i double click on it as any *.Exe file > executes as in Window. Sir please help me. Sounds like your OS file associations are all botched-up and the ".py" extention has been linked (either by you purposefully, as a system default, or as the side-effect of something else) to a texteditor program. It's easy enough to change this setting in the OS, and i believe there is a Python module or two for the task -- if that's your cup-o-tea. Granted, opening a text editor for unknown files is always a wise default system setting as it avoids any exploits that may be initiated by a hapless neophyte. Take, for example, the braindead Windozes default setting for autorun, which has been the source of many nasty exploits. I suppose that Gates figures his user base is so dumb that they can't even find the My Computer icon and double click it in order to access the contents of a removable drive, CD-ROM, or whatever STD riddled device they happen to plug in. The wise windoze user knows that disabling autorun is paramount to ensuring a secure experience, among other braindead defaults. This is not really a "python" question, and is actually generally applicable to Operating Systems. And the solution is specific to each platform. From Cecil at decebal.nl Sun Dec 3 17:36:36 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 10:36:36 +1200 Subject: How to use a regexp here Message-ID: <1521907012@f38.n261.z1.binkp.net> I have a script that was running perfectly for some time. It uses: array = [elem for elem in output if 'CPU_TEMP' in elem] But because output has changed, I have to check for CPU_TEMP at the beginning of the line. What would be the best way to implement this? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From ned at nedbatchelder.com Sun Dec 3 18:14:46 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 04 Dec 2017 11:14:46 +1200 Subject: How to use a regexp here Message-ID: <125428791@f38.n261.z1.binkp.net> On 12/4/17 9:13 AM, Rick Johnson wrote: > Perhaps it's not politically correct for me to say this, but > i've never been one who cared much about political > correctness, so i'm just going to say it... Cecil, feel free to ignore the rest of Rick's message.? His messages are famous for their outrageous and/or abrasive tone, something he seems to revel in.? Luckily, it's not typical of the Python community. --Ned. From breamoreboy at gmail.com Sun Dec 3 18:19:02 2017 From: breamoreboy at gmail.com (breamoreboy) Date: Mon, 04 Dec 2017 11:19:02 +1200 Subject: why won't slicing lists raise IndexError? Message-ID: <1059629376@f38.n261.z1.binkp.net> On Monday, December 4, 2017 at 7:10:01 PM UTC, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100] # does not raise an IndexError, but instead returns the full > list > > Is there any background on why that doesn't raise an IndexError? Knowing > that might help me design my extended list class better. For my specific > use case, it would simplify my code (and prevent `if isinstance(item, > slice)` checks) if the slicing raised an IndexError in the example I gave. This is explained in the Python tutorial for strings https://docs.python.org/3/tutorial/introduction.html#strings, as a list is a sequence just like a string it will act in exactly the same way. -- Kindest regards. Mark Lawrence. From python at bladeshadow.org Sun Dec 3 18:25:54 2017 From: python at bladeshadow.org (Python) Date: Sun, 3 Dec 2017 17:25:54 -0600 Subject: urllib2 urlopen takes too much time In-Reply-To: References: Message-ID: <20171203232554.GB30413@bladeshadow.org> On Sun, Dec 03, 2017 at 09:49:45AM -0800, cpollio at vt.edu wrote: > On Tuesday, June 23, 2009 at 11:09:30 PM UTC-4, Aahz wrote: > > In article , > > =?UTF-8?Q?Filip_Gruszczy=C5=84ski?= wrote: > > > > > >I have encountered a performance problem using suds, which was traced > > >down to _socket.recv. I am calling some web services and each of them > > >uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen, > > >while the rest of the call is finished in milliseconds. > > > > What happens if you use urlopen() by itself? > > I am having the same issue. Did you ever figure out a solution? > The time delay is also the same, from .2 to .25 sec. I need to stay > with urlopen though so I can do a custom request header Depending on your network conditions, this doesn't seem all that outrageous. Using tcpdump or some other packet sniffer should reveal what is going on, but most likely urlopen() needs to do all of the following, every time it is called: - resolve the address via DNS + 1 round trip: DNS request + response; possibly more if DNS doesn't have host entry and forwards... - initiate a TCP connection + three way handshake = 1.5 round trip times - send the request (.5 round trip) - wait for server processing (unknown time) - receive the response (.5 round trip time) If the DNS server is busy, or the SOAP server is busy, add that latency to the mix. Assuming NO latency due to server load, you're still looking at 3.5 round trips to service the request, or 7 one-way (possibly 6, if the ACK contains the request, which IIRC is allowed). .2s / 7 = ~29ms, so if the latency between server and client is 29ms or higher, that explains everything. On a LAN I'd hope for much better than 29ms latency (1ms is more typical), but it's not outside the realm of possibility depending on network architecture and load. Ping to the server will tell you that... if your network isn't blocking ICMP. If the C# app is faster, my guess would be it is caching the DNS response and/or maintaining persistent connections to the server, whereas urllib isn't, though that's just a guess... I'm not familiar with the implementations of either. But again, a packet sniffer should show you exactly what's happening and who is being slow. From tjreedy at udel.edu Sun Dec 3 18:58:04 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Dec 2017 11:58:04 +1200 Subject: How to use a regexp here Message-ID: <3827876361@f38.n261.z1.binkp.net> On 12/4/2017 11:14 AM, Ned Batchelder wrote: > On 12/4/17 9:13 AM, Rick Johnson wrote: >> Perhaps it's not politically correct for me to say this, but >> i've never been one who cared much about political >> correctness, so i'm just going to say it... > > Cecil, feel free to ignore the rest of Rick's message.? His messages are > famous for their outrageous and/or abrasive tone, something he seems to > revel in.? Luckily, it's not typical of the Python community. Or take Rick's 'rest' as a suggestion to reread Library Reference chapters 2, 3, 4 and in particular 4.7. As for your idea of an RE, '^' matches the beginning of a line, and '$' the end, though using .startswith, and .endswith, are easier if no other RE syntax is needed for matching. -- Terry Jan Reedy From tjol at tjol.eu Sun Dec 3 19:49:00 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 04 Dec 2017 12:49:00 +1200 Subject: Please tell me how to execute python file in Ubuntu by double Message-ID: <1994761381@f38.n261.z1.binkp.net> On 2017-12-04 10:48, dhananjaysingh091298 at gmail.com wrote: > Respected Sir/Mam, > I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. > Sir please help me. > https://askubuntu.com/a/544544 -- Thomas Jollans From jjmaldonis at gmail.com Sun Dec 3 19:54:26 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Mon, 04 Dec 2017 12:54:26 +1200 Subject: why won't slicing lists raise IndexError? Message-ID: <1629467146@f38.n261.z1.binkp.net> I was extending a `list` and am wondering why slicing lists will never raise an IndexError, even if the `slice.stop` value if greater than the list length. Quick example: my_list = [1, 2, 3] my_list[:100] # does not raise an IndexError, but instead returns the full list Is there any background on why that doesn't raise an IndexError? Knowing that might help me design my extended list class better. For my specific use case, it would simplify my code (and prevent `if isinstance(item, slice)` checks) if the slicing raised an IndexError in the example I gave. From Cecil at decebal.nl Sun Dec 3 20:12:08 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 13:12:08 +1200 Subject: How to use a regexp here References: <1585134724@f38.n261.z1.binkp.net> Message-ID: <3502471932@f38.n261.z1.binkp.net> Joel Goldstick writes: > On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder > wrote: > >> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >> >>> I have a script that was running perfectly for some time. It uses: >>> array = [elem for elem in output if 'CPU_TEMP' in elem] >>> >>> But because output has changed, I have to check for CPU_TEMP at the >>> beginning of the line. What would be the best way to implement this? >>> >>> >> No need for a regex just yet: >> >> array = [elem for elem in output if elem.startswith('CPU_TEMP')] >> >> (btw, note that the result of this expression is a list, not an array, for >> future Googling.) >> >> --Ned. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > I like Ned's clear answer, but I'm wondering why the original code would > fail because the substring is at the start of the line, since 'in' would > still be true no matter where the desired string is placed. It would be > useful to see some sample data of the old data, and the new data There is now also a line that starts with: PCH_CPU_TEMP: And I do not want that one. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sun Dec 3 20:13:52 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 13:13:52 +1200 Subject: How to use a regexp here References: <1914380400@f38.n261.z1.binkp.net> Message-ID: <1987567240@f38.n261.z1.binkp.net> Ned Batchelder writes: > On 12/4/17 4:36 AM, Cecil Westerhof wrote: >> I have a script that was running perfectly for some time. It uses: >> array = [elem for elem in output if 'CPU_TEMP' in elem] >> >> But because output has changed, I have to check for CPU_TEMP at the >> beginning of the line. What would be the best way to implement this? >> > > No need for a regex just yet: > > ? ? ? array = [elem for elem in output if elem.startswith('CPU_TEMP')] Yes, that is it. I should have known that. :'-( -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From random832 at fastmail.com Sun Dec 3 21:31:16 2017 From: random832 at fastmail.com (Random832) Date: Mon, 04 Dec 2017 14:31:16 +1200 Subject: why won't slicing lists raise IndexError? Message-ID: <1770059777@f38.n261.z1.binkp.net> On Mon, Dec 4, 2017, at 13:54, Jason Maldonis wrote: > Is there any background on why that doesn't raise an IndexError? Knowing > that might help me design my extended list class better. For my specific > use case, it would simplify my code (and prevent `if isinstance(item, > slice)` checks) if the slicing raised an IndexError in the example I > gave. Slicing (of strings, lists, tuples, anyway) never raises an IndexError. If the start is out of range it will return an empty list. I don't know. As for "why", it's just how the operation was designed. Perhaps it was considered that an exception isn't needed because there's no ambiguity (i.e. there's no other reason a slice operation can return a list shorter than the length implied by the slice parameters). Why would this simplify your code? What are you doing that would benefit from an IndexError here? From Cecil at decebal.nl Mon Dec 4 00:06:32 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 17:06:32 +1200 Subject: How to use a regexp here References: <3304169341@f38.n261.z1.binkp.net> Message-ID: <3373497041@f38.n261.z1.binkp.net> Rick Johnson writes: >> There is now also a line that starts with: PCH_CPU_TEMP: >> And I do not want that one. > > Yes. But be aware, that while the `str.startswith(target)` > method is indeed more efficient than a more generalized > "inclusion test", if the target is not _always_ at the > beginning of the string, then your code is going to skip > right over valid match like a round stone skipping across > the surface of a glass-smooth lake. But if you are sure the > target will always be at the beginning of the string, then > it is the best choice. Yes, I am sure it is always at the beginning of the line. (It is output from the Linux sensors command.) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From neilc at norwich.edu Mon Dec 4 01:48:02 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 04 Dec 2017 18:48:02 +1200 Subject: How to use a regexp here Message-ID: <3042191400@f38.n261.z1.binkp.net> On 2017-12-04, Cecil Westerhof wrote: > Joel Goldstick writes: > >> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder >> wrote: >> >>> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >>> >>>> I have a script that was running perfectly for some time. It uses: >>>> array = [elem for elem in output if 'CPU_TEMP' in elem] >>>> >>>> But because output has changed, I have to check for CPU_TEMP at the >>>> beginning of the line. What would be the best way to implement this? >>>> >>>> >>> No need for a regex just yet: >>> >>> array = [elem for elem in output if elem.startswith('CPU_TEMP')] >>> >>> (btw, note that the result of this expression is a list, not an array, for >>> future Googling.) >>> >>> --Ned. >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> I like Ned's clear answer, but I'm wondering why the original code would >> fail because the substring is at the start of the line, since 'in' would >> still be true no matter where the desired string is placed. It would be >> useful to see some sample data of the old data, and the new data > > There is now also a line that starts with: > PCH_CPU_TEMP: > > And I do not want that one. You'll probably want to include the ':' in the startswith check, in case someday they also add CPU_TEMP_SOMETHING:. -- Neil Cerutti From Cecil at decebal.nl Mon Dec 4 03:09:24 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 20:09:24 +1200 Subject: How to use a regexp here References: <3042191400@f38.n261.z1.binkp.net> Message-ID: <3305328328@f38.n261.z1.binkp.net> Neil Cerutti writes: > On 2017-12-04, Cecil Westerhof wrote: >> Joel Goldstick writes: >> >>> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder >>> wrote: >>> >>>> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >>>> >>>>> I have a script that was running perfectly for some time. It uses: >>>>> array = [elem for elem in output if 'CPU_TEMP' in elem] >>>>> >>>>> But because output has changed, I have to check for CPU_TEMP at the >>>>> beginning of the line. What would be the best way to implement this? >>>>> >>>>> >>>> No need for a regex just yet: >>>> >>>> array = [elem for elem in output if elem.startswith('CPU_TEMP')] >>>> >>>> (btw, note that the result of this expression is a list, not an array, for >>>> future Googling.) >>>> >>>> --Ned. >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>> >>> I like Ned's clear answer, but I'm wondering why the original code would >>> fail because the substring is at the start of the line, since 'in' would >>> still be true no matter where the desired string is placed. It would be >>> useful to see some sample data of the old data, and the new data >> >> There is now also a line that starts with: >> PCH_CPU_TEMP: >> >> And I do not want that one. > > You'll probably want to include the ':' in the startswith check, > in case someday they also add CPU_TEMP_SOMETHING:. I already did. And to be really sure also included a space after it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Mon Dec 4 04:36:36 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 10:36:36 +0100 Subject: How to use a regexp here Message-ID: <87tvx6ltqz.fsf@munus.decebal.nl> I have a script that was running perfectly for some time. It uses: array = [elem for elem in output if 'CPU_TEMP' in elem] But because output has changed, I have to check for CPU_TEMP at the beginning of the line. What would be the best way to implement this? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From dhananjaysingh091298 at gmail.com Mon Dec 4 04:48:43 2017 From: dhananjaysingh091298 at gmail.com (dhananjaysingh091298 at gmail.com) Date: Mon, 4 Dec 2017 01:48:43 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. Message-ID: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> Respected Sir/Mam, I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. Sir please help me. From breamoreboy at gmail.com Mon Dec 4 05:09:51 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 4 Dec 2017 02:09:51 -0800 (PST) Subject: How to use a regexp here In-Reply-To: <87tvx6ltqz.fsf@munus.decebal.nl> References: <87tvx6ltqz.fsf@munus.decebal.nl> Message-ID: On Monday, December 4, 2017 at 9:44:27 AM UTC, Cecil Westerhof wrote: > I have a script that was running perfectly for some time. It uses: > array = [elem for elem in output if 'CPU_TEMP' in elem] > > But because output has changed, I have to check for CPU_TEMP at the > beginning of the line. What would be the best way to implement this? > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof Use https://docs.python.org/3/library/stdtypes.html#str.startswith instead of the test for `in`. -- Kindest regards. Mark Lawrence. From ned at nedbatchelder.com Mon Dec 4 05:21:47 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 4 Dec 2017 05:21:47 -0500 Subject: How to use a regexp here In-Reply-To: <87tvx6ltqz.fsf@munus.decebal.nl> References: <87tvx6ltqz.fsf@munus.decebal.nl> Message-ID: <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> On 12/4/17 4:36 AM, Cecil Westerhof wrote: > I have a script that was running perfectly for some time. It uses: > array = [elem for elem in output if 'CPU_TEMP' in elem] > > But because output has changed, I have to check for CPU_TEMP at the > beginning of the line. What would be the best way to implement this? > No need for a regex just yet: ??? array = [elem for elem in output if elem.startswith('CPU_TEMP')] (btw, note that the result of this expression is a list, not an array, for future Googling.) --Ned. From joel.goldstick at gmail.com Mon Dec 4 05:41:21 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 4 Dec 2017 05:41:21 -0500 Subject: How to use a regexp here In-Reply-To: <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> Message-ID: On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder wrote: > On 12/4/17 4:36 AM, Cecil Westerhof wrote: > >> I have a script that was running perfectly for some time. It uses: >> array = [elem for elem in output if 'CPU_TEMP' in elem] >> >> But because output has changed, I have to check for CPU_TEMP at the >> beginning of the line. What would be the best way to implement this? >> >> > No need for a regex just yet: > > array = [elem for elem in output if elem.startswith('CPU_TEMP')] > > (btw, note that the result of this expression is a list, not an array, for > future Googling.) > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > I like Ned's clear answer, but I'm wondering why the original code would fail because the substring is at the start of the line, since 'in' would still be true no matter where the desired string is placed. It would be useful to see some sample data of the old data, and the new data -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From tjol at tjol.eu Mon Dec 4 06:49:00 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 4 Dec 2017 12:49:00 +0100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. In-Reply-To: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> Message-ID: <3517ea12-8055-cedc-364f-ad57dcacdc53@tjol.eu> On 2017-12-04 10:48, dhananjaysingh091298 at gmail.com wrote: > Respected Sir/Mam, > I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. > Sir please help me. > https://askubuntu.com/a/544544 -- Thomas Jollans From Cecil at decebal.nl Mon Dec 4 07:12:08 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 13:12:08 +0100 Subject: How to use a regexp here References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> Message-ID: <87mv2ylmjr.fsf@munus.decebal.nl> Joel Goldstick writes: > On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder > wrote: > >> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >> >>> I have a script that was running perfectly for some time. It uses: >>> array = [elem for elem in output if 'CPU_TEMP' in elem] >>> >>> But because output has changed, I have to check for CPU_TEMP at the >>> beginning of the line. What would be the best way to implement this? >>> >>> >> No need for a regex just yet: >> >> array = [elem for elem in output if elem.startswith('CPU_TEMP')] >> >> (btw, note that the result of this expression is a list, not an array, for >> future Googling.) >> >> --Ned. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > I like Ned's clear answer, but I'm wondering why the original code would > fail because the substring is at the start of the line, since 'in' would > still be true no matter where the desired string is placed. It would be > useful to see some sample data of the old data, and the new data There is now also a line that starts with: PCH_CPU_TEMP: And I do not want that one. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Mon Dec 4 07:13:53 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 13:13:53 +0100 Subject: How to use a regexp here References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> Message-ID: <87indmlmgu.fsf@munus.decebal.nl> Ned Batchelder writes: > On 12/4/17 4:36 AM, Cecil Westerhof wrote: >> I have a script that was running perfectly for some time. It uses: >> array = [elem for elem in output if 'CPU_TEMP' in elem] >> >> But because output has changed, I have to check for CPU_TEMP at the >> beginning of the line. What would be the best way to implement this? >> > > No need for a regex just yet: > > ??? array = [elem for elem in output if elem.startswith('CPU_TEMP')] Yes, that is it. I should have known that. :'-( -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rantingrickjohnson at gmail.com Mon Dec 4 09:13:21 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 06:13:21 -0800 (PST) Subject: How to use a regexp here In-Reply-To: <87mv2ylmjr.fsf@munus.decebal.nl> References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> <87mv2ylmjr.fsf@munus.decebal.nl> Message-ID: <8326e291-8937-470a-9401-a24a31f8fee3@googlegroups.com> Cecil Westerhof wrote: > Joel Goldstick writes: [...] > > I like Ned's clear answer, but I'm wondering why the > > original code would fail because the substring is at the > > start of the line, since 'in' would still be true no > > matter where the desired string is placed. It would be > > useful to see some sample data of the old data, and the > > new data @Goldstick "Inclusion testing" will return false positives when the target is part of a larger structure (aka: word). Observe: >>> s = "Complex is better than complicated." >>> "plex" in s True >>> "om" in s True >>> s.count("om") 2 I'm sure you already know this, and only made the comment because you did not have all the data, but i thought it would be good to mention for any lurkers who may be watching. > There is now also a line that starts with: PCH_CPU_TEMP: > And I do not want that one. Yes. But be aware, that while the `str.startswith(target)` method is indeed more efficient than a more generalized "inclusion test", if the target is not _always_ at the beginning of the string, then your code is going to skip right over valid match like a round stone skipping across the surface of a glass-smooth lake. But if you are sure the target will always be at the beginning of the string, then it is the best choice. > -- > Cecil Westerhof > Senior Software Engineer Perhaps it's not politically correct for me to say this, but i've never been one who cared much about political correctness, so i'm just going to say it... If you really are a "_Senior_ software engineer", and that title is not simply an ego-booster bestowed by your boss to a one-person-dev-team in order to avoid pay raises, then i would expect more competence from someone who holds such an esteemed title. And even *IF* you are only vaguely familiar with Python, and even *IF*, you rarely use Python in your projects, i don't think it's too much to ask of a ~~Senior~~ Software Engineer that they possess the basic skills required to peruse the Python documentation and decide which method is most appropriate for the situation at hand. And if you're using Python on a regular basis, then you should be intimately familiar with _all_ methods of each major type. Granted, your question did "hint" about the possibility of using a regexp (although, based on the data you have provided so far, a string method will suffice), but i would also expect a ~~Senior~~ Software Engineer to not only be knowledgeable of regexps, but also know when they are a strength and when they are a weakness. Now, there are one of two ways you can take this advice: (1) You can take it as a personal attack; get all huffy about it; drop to the floor and flail your arms and legs like a petulant two-year-old who didn't get the toy he wanted; and learn nothing in the process. or (2) You can take it as what it is -> constructive criticism; shower me with gratitude[1]; and become a better person and a better programmer in the process. The choice is yours. [1] Well, i had to sneak something in there for myself, after all, it is the season of giving, yes? O:-) Here comes santa claws... Here comes santa claws... ... From rantingrickjohnson at gmail.com Mon Dec 4 09:38:51 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 06:38:51 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. In-Reply-To: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> Message-ID: On Monday, December 4, 2017 at 3:49:11 AM UTC-6, dhananjays... at gmail.com wrote: > I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when > i am double click in python program (Dhananjay.py),it is > opening in Text Editor by Default in Ubuntu.I want to run > this program when i double click on it as any *.Exe file > executes as in Window. Sir please help me. Sounds like your OS file associations are all botched-up and the ".py" extention has been linked (either by you purposefully, as a system default, or as the side-effect of something else) to a texteditor program. It's easy enough to change this setting in the OS, and i believe there is a Python module or two for the task -- if that's your cup-o-tea. Granted, opening a text editor for unknown files is always a wise default system setting as it avoids any exploits that may be initiated by a hapless neophyte. Take, for example, the braindead Windozes default setting for autorun, which has been the source of many nasty exploits. I suppose that Gates figures his user base is so dumb that they can't even find the My Computer icon and double click it in order to access the contents of a removable drive, CD-ROM, or whatever STD riddled device they happen to plug in. The wise windoze user knows that disabling autorun is paramount to ensuring a secure experience, among other braindead defaults. This is not really a "python" question, and is actually generally applicable to Operating Systems. And the solution is specific to each platform. From Cecil at decebal.nl Mon Dec 4 11:06:32 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 17:06:32 +0100 Subject: How to use a regexp here References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> <87mv2ylmjr.fsf@munus.decebal.nl> <8326e291-8937-470a-9401-a24a31f8fee3@googlegroups.com> Message-ID: <87609mlbp3.fsf@munus.decebal.nl> Rick Johnson writes: >> There is now also a line that starts with: PCH_CPU_TEMP: >> And I do not want that one. > > Yes. But be aware, that while the `str.startswith(target)` > method is indeed more efficient than a more generalized > "inclusion test", if the target is not _always_ at the > beginning of the string, then your code is going to skip > right over valid match like a round stone skipping across > the surface of a glass-smooth lake. But if you are sure the > target will always be at the beginning of the string, then > it is the best choice. Yes, I am sure it is always at the beginning of the line. (It is output from the Linux sensors command.) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From ned at nedbatchelder.com Mon Dec 4 11:14:46 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 4 Dec 2017 11:14:46 -0500 Subject: How to use a regexp here In-Reply-To: <8326e291-8937-470a-9401-a24a31f8fee3@googlegroups.com> References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> <87mv2ylmjr.fsf@munus.decebal.nl> <8326e291-8937-470a-9401-a24a31f8fee3@googlegroups.com> Message-ID: On 12/4/17 9:13 AM, Rick Johnson wrote: > Perhaps it's not politically correct for me to say this, but > i've never been one who cared much about political > correctness, so i'm just going to say it... Cecil, feel free to ignore the rest of Rick's message.? His messages are famous for their outrageous and/or abrasive tone, something he seems to revel in.? Luckily, it's not typical of the Python community. --Ned. From tjreedy at udel.edu Mon Dec 4 11:58:04 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 4 Dec 2017 11:58:04 -0500 Subject: How to use a regexp here In-Reply-To: References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> <87mv2ylmjr.fsf@munus.decebal.nl> <8326e291-8937-470a-9401-a24a31f8fee3@googlegroups.com> Message-ID: On 12/4/2017 11:14 AM, Ned Batchelder wrote: > On 12/4/17 9:13 AM, Rick Johnson wrote: >> Perhaps it's not politically correct for me to say this, but >> i've never been one who cared much about political >> correctness, so i'm just going to say it... > > Cecil, feel free to ignore the rest of Rick's message.? His messages are > famous for their outrageous and/or abrasive tone, something he seems to > revel in.? Luckily, it's not typical of the Python community. Or take Rick's 'rest' as a suggestion to reread Library Reference chapters 2, 3, 4 and in particular 4.7. As for your idea of an RE, '^' matches the beginning of a line, and '$' the end, though using .startswith, and .endswith, are easier if no other RE syntax is needed for matching. -- Terry Jan Reedy From neilc at norwich.edu Mon Dec 4 13:48:02 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 4 Dec 2017 18:48:02 +0000 (UTC) Subject: How to use a regexp here References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> <87mv2ylmjr.fsf@munus.decebal.nl> Message-ID: On 2017-12-04, Cecil Westerhof wrote: > Joel Goldstick writes: > >> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder >> wrote: >> >>> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >>> >>>> I have a script that was running perfectly for some time. It uses: >>>> array = [elem for elem in output if 'CPU_TEMP' in elem] >>>> >>>> But because output has changed, I have to check for CPU_TEMP at the >>>> beginning of the line. What would be the best way to implement this? >>>> >>>> >>> No need for a regex just yet: >>> >>> array = [elem for elem in output if elem.startswith('CPU_TEMP')] >>> >>> (btw, note that the result of this expression is a list, not an array, for >>> future Googling.) >>> >>> --Ned. >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> I like Ned's clear answer, but I'm wondering why the original code would >> fail because the substring is at the start of the line, since 'in' would >> still be true no matter where the desired string is placed. It would be >> useful to see some sample data of the old data, and the new data > > There is now also a line that starts with: > PCH_CPU_TEMP: > > And I do not want that one. You'll probably want to include the ':' in the startswith check, in case someday they also add CPU_TEMP_SOMETHING:. -- Neil Cerutti From jjmaldonis at gmail.com Mon Dec 4 13:54:27 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Mon, 4 Dec 2017 12:54:27 -0600 Subject: why won't slicing lists raise IndexError? Message-ID: I was extending a `list` and am wondering why slicing lists will never raise an IndexError, even if the `slice.stop` value if greater than the list length. Quick example: my_list = [1, 2, 3] my_list[:100] # does not raise an IndexError, but instead returns the full list Is there any background on why that doesn't raise an IndexError? Knowing that might help me design my extended list class better. For my specific use case, it would simplify my code (and prevent `if isinstance(item, slice)` checks) if the slicing raised an IndexError in the example I gave. From Cecil at decebal.nl Mon Dec 4 14:09:25 2017 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Dec 2017 20:09:25 +0100 Subject: How to use a regexp here References: <87tvx6ltqz.fsf@munus.decebal.nl> <8ad2c549-b1a8-f08d-5da8-e7f03e6828fe@nedbatchelder.com> <87mv2ylmjr.fsf@munus.decebal.nl> Message-ID: <87bmjejonu.fsf@munus.decebal.nl> Neil Cerutti writes: > On 2017-12-04, Cecil Westerhof wrote: >> Joel Goldstick writes: >> >>> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder >>> wrote: >>> >>>> On 12/4/17 4:36 AM, Cecil Westerhof wrote: >>>> >>>>> I have a script that was running perfectly for some time. It uses: >>>>> array = [elem for elem in output if 'CPU_TEMP' in elem] >>>>> >>>>> But because output has changed, I have to check for CPU_TEMP at the >>>>> beginning of the line. What would be the best way to implement this? >>>>> >>>>> >>>> No need for a regex just yet: >>>> >>>> array = [elem for elem in output if elem.startswith('CPU_TEMP')] >>>> >>>> (btw, note that the result of this expression is a list, not an array, for >>>> future Googling.) >>>> >>>> --Ned. >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>> >>> I like Ned's clear answer, but I'm wondering why the original code would >>> fail because the substring is at the start of the line, since 'in' would >>> still be true no matter where the desired string is placed. It would be >>> useful to see some sample data of the old data, and the new data >> >> There is now also a line that starts with: >> PCH_CPU_TEMP: >> >> And I do not want that one. > > You'll probably want to include the ':' in the startswith check, > in case someday they also add CPU_TEMP_SOMETHING:. I already did. And to be really sure also included a space after it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From breamoreboy at gmail.com Mon Dec 4 14:19:03 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 4 Dec 2017 11:19:03 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: On Monday, December 4, 2017 at 7:10:01 PM UTC, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100] # does not raise an IndexError, but instead returns the full > list > > Is there any background on why that doesn't raise an IndexError? Knowing > that might help me design my extended list class better. For my specific > use case, it would simplify my code (and prevent `if isinstance(item, > slice)` checks) if the slicing raised an IndexError in the example I gave. This is explained in the Python tutorial for strings https://docs.python.org/3/tutorial/introduction.html#strings, as a list is a sequence just like a string it will act in exactly the same way. -- Kindest regards. Mark Lawrence. From random832 at fastmail.com Mon Dec 4 14:31:16 2017 From: random832 at fastmail.com (Random832) Date: Mon, 04 Dec 2017 14:31:16 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: <1512415876.3863499.1193735296.510C003D@webmail.messagingengine.com> On Mon, Dec 4, 2017, at 13:54, Jason Maldonis wrote: > Is there any background on why that doesn't raise an IndexError? Knowing > that might help me design my extended list class better. For my specific > use case, it would simplify my code (and prevent `if isinstance(item, > slice)` checks) if the slicing raised an IndexError in the example I > gave. Slicing (of strings, lists, tuples, anyway) never raises an IndexError. If the start is out of range it will return an empty list. I don't know. As for "why", it's just how the operation was designed. Perhaps it was considered that an exception isn't needed because there's no ambiguity (i.e. there's no other reason a slice operation can return a list shorter than the length implied by the slice parameters). Why would this simplify your code? What are you doing that would benefit from an IndexError here? From python at mrabarnett.plus.com Mon Dec 4 14:46:19 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Dec 2017 19:46:19 +0000 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: On 2017-12-04 18:54, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100] # does not raise an IndexError, but instead returns the full > list > > Is there any background on why that doesn't raise an IndexError? Knowing > that might help me design my extended list class better. For my specific > use case, it would simplify my code (and prevent `if isinstance(item, > slice)` checks) if the slicing raised an IndexError in the example I gave. > Have you ever used a language that does that? I have. The String class in the C# language does that, and it's /really/ annoying. I have to add extra code to prevent such exceptions. In practice, I find that the way that Python does it is much nicer. (And Python isn't unique in this respect, either.) From jjmaldonis at gmail.com Mon Dec 4 15:13:30 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Mon, 4 Dec 2017 14:13:30 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: >Why would this simplify your code? What are you doing that would benefit >from an IndexError here? Without simplifying too much, I'm writing a wrapper around a REST API. I want lazy-loading functionality for lists-of-things, so I am creating a LazyList class. This LazyList class will load items as needed, and store them on the list. When a user triggers `__getitem__`, the LazyList may not yet have data for the index the user requests, in which case it needs to load more data. I'll write out the basic functionality of the LazyList class so you can explicitly see how slicing is impacting the implementation: class LazyList(list): def __getitem__(item): try: return super().__getitem__(item) except IndexError: self._generate_more_data(item) # If, for example, item == 10, this function will keep generating more data until there are 10 items in the list return super().__getitem__(item) This works great when `item` is an integer. However, when `item` is a slice, the IndexError is never triggered, and so new data will never be loaded. Consider this snippet: lazy_list = LazyList() sublist = lazy_list[:10] In this case, `sublist` will always be empty, because the first `return super().__getitem__(item)` "succeeds" by returning an empty list. If slicing raised an IndexError, the above code would work great. Instead, I need to add a check before the try/except to check if the `item` is a `slice`, and if it is, I need to do bounds checking on the list. It seems a bit unpythonic to have to do an isinstance check here, so I am wondering if I am missing something important about why slices don't raise IndexErrors. And I'll be honest -- I like the implementation of the LazyList I wrote above. I think it's pretty logical, because it allows you to think about the lazy list like this: "Treat the list like a norma list. If you run out of bounds, get more data, then treat the list like a normal list again." And I really like that clean logic. From jjmaldonis at gmail.com Mon Dec 4 15:13:53 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Mon, 4 Dec 2017 14:13:53 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: > > Have you ever used a language that does that? I have. > The String class in the C# language does that, and it's /really/ annoying. > I have to add extra code to prevent such exceptions. > In practice, I find that the way that Python does it is much nicer. (And > Python isn't unique in this respect, either.) > I'm not here to criticize one way or the other, just understand. As far as I'm aware, I don't rely on python's slicing functionality allowing indexes that are over the length of a list. But I'm just one person and I'm sure there are many other use cases I'm not thinking about. If you think what you wrote is a good explanation for why slicing doesn't raise IndexErrors in python, I'd be interesting in seeing some of your use cases about when you had to explicitly check bounds of list slices in C#. From christian.gabrisch at gmail.com Mon Dec 4 15:44:19 2017 From: christian.gabrisch at gmail.com (christian.gabrisch at gmail.com) Date: Mon, 4 Dec 2017 12:44:19 -0800 (PST) Subject: Python installer hangs in Windows 7 In-Reply-To: References: <765703485.1601081.1486357381135.ref@mail.yahoo.com> <765703485.1601081.1486357381135@mail.yahoo.com> Message-ID: Same with me, except that I tried to install Python 3.6.3. Unchecking "Install launcher for all users" helped, however. From jjmaldonis at gmail.com Mon Dec 4 16:03:56 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Mon, 4 Dec 2017 15:03:56 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: > > This is explained in the Python tutorial for strings > https://docs.python.org/3/tutorial/introduction.html#strings, as a list > is a sequence just like a string it will act in exactly the same way. > The only relevant bit I found in that link is: "However, out of range slice indexes are handled gracefully when used for slicing". I do understand _how_ slices work, but I would really like to know a bit more about why slices will never throw out-of-bounds IndexErrors. From rosuav at gmail.com Mon Dec 4 16:07:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Dec 2017 08:07:16 +1100 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: On Tue, Dec 5, 2017 at 8:03 AM, Jason Maldonis wrote: >> >> This is explained in the Python tutorial for strings >> https://docs.python.org/3/tutorial/introduction.html#strings, as a list >> is a sequence just like a string it will act in exactly the same way. >> > > The only relevant bit I found in that link is: "However, out of range > slice indexes are handled gracefully when used for slicing". I do > understand _how_ slices work, but I would really like to know a bit more > about why slices will never throw out-of-bounds IndexErrors. That's what "handled gracefully" means. Instead of throwing, they get clamped. ChrisA From jjmaldonis at gmail.com Mon Dec 4 16:22:27 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Mon, 4 Dec 2017 15:22:27 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: > > >> This is explained in the Python tutorial for strings > >> https://docs.python.org/3/tutorial/introduction.html#strings, as a list > >> is a sequence just like a string it will act in exactly the same way. > >> > > > > The only relevant bit I found in that link is: "However, out of range > > slice indexes are handled gracefully when used for slicing". I do > > understand _how_ slices work, but I would really like to know a bit more > > about why slices will never throw out-of-bounds IndexErrors. > > That's what "handled gracefully" means. Instead of throwing, they get > clamped. > > ChrisA Cool! Why? I know I'm being a bit pedantic here, but I truly would like to understand _why_ slices get clamped. I've been writing python code every day for almost 7 years, so usually I can figure stuff like this out, but I'm struggling here and would really appreciate some insight. From p.f.moore at gmail.com Mon Dec 4 16:30:10 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 4 Dec 2017 21:30:10 +0000 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: On 4 December 2017 at 20:13, Jason Maldonis wrote: > And I'll be honest -- I like the implementation of the LazyList I wrote > above. I think it's pretty logical, because it allows you to think about > the lazy list like this: "Treat the list like a norma list. If you run out > of bounds, get more data, then treat the list like a normal list again." > And I really like that clean logic. I can't give you a definitive answer as to why slices behave as they do, any more than anyone else (barring probably Guido). But as a user, I can say that I find the ability to use slices without checking for out of bounds cases or handling exceptions to be really convenient. And one thing Python consistently emphasises is making things easy for the user, even if that convenience comes at a cost to the implementer. Certainly, you're a user of the built in list class, but you're using it to build a wrapper around it, and that makes you a non-core use case (as I see it). At the end of the day, whether to clamp the values or raise IndexError is a trade-off in terms of which type of user to inconvenience, and as I say, in my experience user code wins when that sort of trade-off comes up. That's not to say Python makes it deliberately difficult for people writing code like yours. For your lazy list class, do you know the maximum amount of data available? If you don't, then supporting lst[:-1] will be hard, so you're pretty much bound to have to handle slices differently than built in lists. If you *do* know the maximum length of the underlying data, then the indices() method of slices will probably help: Help on built-in function indices: indices(...) method of builtins.slice instance S.indices(len) -> (start, stop, stride) Assuming a sequence of length len, calculate the start and stop indices, and the stride length of the extended slice described by S. Out of bounds indices are clipped in a manner consistent with the handling of normal slices. Using indices(), you'll get (from "stop") the amount of data you need to load. Paul From rantingrickjohnson at gmail.com Mon Dec 4 16:37:22 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 13:37:22 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: <94b5a55f-fead-4c5d-9cf2-b9dc812b562d@googlegroups.com> On Monday, December 4, 2017 at 1:10:01 PM UTC-6, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100] # does not raise an IndexError, but instead returns the full > list That's a feature dude, not a bug. In this case, it only seems illogical because you already know the extents of the buffer, and that's because you created it. However, outside of hand-stiched arts and crafts projects in the interactive basement of your parent's home, you have no way of knowing how large a buffer may be in the wild. And many times, you just need a "transparent slice" from it. What does "transparent slice" mean, you ask? Well, for example, (contrived example here) consider a case where you want the first N chars from a collection of N strings. In such a case, even if `s[:100]` returns a null string from the first target, 55 chars from the next target, 99 chars from the next target, and so on and so forth -- you don't care -- because all you want is a "transparent slice" of each target string. And the onerous exception handling required to deal with disparate buffer lengths would just get in the way of doing that job _cleanly_. Now, some might argue that such a feature breaks the Python Zen. Okay. Let's investigate, shall we> ZEN SAYS: "SPECIAL CASES ARE NOT SPECIAL ENOUGH TO BREAK THE RULES" Hmm, with this "feature" being applicable to so many problems, i would hardly consider it to be a "special case". Next! ZEN SAYS: "EXPLICIT IS BETTER THAN IMPLICIT" Hmm, this one may be difficult to overcome, but we need to conduct a cost-benefit analysis _first_. And, since i have not encountered, in my many years of writing Python code, even one instance of a negative side-effect to this transparent slicing feature, and, furthermore, i have not even ~heard~ of one instance of this feature causing havoc, i will, at this time, and until compelling evidence is provided to the contrary, conclude that the Zen is wrong in this case. *GASP* Next! ZEN SAYS: "ALTHOUGH PRACTICALITY BEATS PURITY. ERRORS SHOULD NEVER PASS SILENTLY. UNLESS EXPLICITLY SILENCED." Some might accuse this feature of "masking errors", however, i don't agree, And while technically speaking -- yes -- a requested slice range which overlaps the actual physical boundaries of a target buffer _is_ violating the physical laws which govern disparate entities existing in a material universe, code exists beyond the material universe, So this beef boils down to a petty qualm over semantics. Next! From python at mrabarnett.plus.com Mon Dec 4 16:52:00 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Dec 2017 21:52:00 +0000 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: <9b91178c-befe-d1af-8e7f-7aeee37e3f25@mrabarnett.plus.com> On 2017-12-04 21:22, Jason Maldonis wrote: >> >> >> This is explained in the Python tutorial for strings >> >> https://docs.python.org/3/tutorial/introduction.html#strings, as a list >> >> is a sequence just like a string it will act in exactly the same way. >> >> >> > >> > The only relevant bit I found in that link is: "However, out of range >> > slice indexes are handled gracefully when used for slicing". I do >> > understand _how_ slices work, but I would really like to know a bit more >> > about why slices will never throw out-of-bounds IndexErrors. >> >> That's what "handled gracefully" means. Instead of throwing, they get >> clamped. >> >> ChrisA > > > Cool! Why? I know I'm being a bit pedantic here, but I truly would like > to understand _why_ slices get clamped. I've been writing python code > every day for almost 7 years, so usually I can figure stuff like this out, > but I'm struggling here and would really appreciate some insight. > Here's an example: You have a string of at least n characters. You want to get the first n characters and leave the remainder. The first n characters is my_string[ : n]. The remainder is my_string[n : ]. What if len(my_string) == n? Wouldn't my_string[n : ] raise an IndexError? Another example: You want at most n characters of my_string. What if len(my_string) < n? my_string[ : n] would raise an IndexError. You'd need to do my_string[ : min(n, len(my_string))]. Although Python's slicing behaviour doesn't help in your use-case, in the majority of cases it does. From tjreedy at udel.edu Mon Dec 4 17:01:50 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 4 Dec 2017 17:01:50 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: On 12/4/2017 1:54 PM, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > Is there any background on why that doesn't raise an IndexError? Slicing is perhaps most commonly used on strings, and clamping is probably most useful for strings. Example 1: s[0:k] gets the k or fewer initial characters of the string, perhaps to put in a fixed-width display or storage field. Example 2: below are two equivalent (I believe) code snippets. try: item = seq[n] except IndexError do_without_item() else: process(item) item = seq[n:n+1] if item: process(item) else: do_without_item() Many prefer the second. Note that moving process(item) in the first into the try clause makes the two non-equivalent. Example 3: 'if s[k:k+1] in okset' versus 'if len(s) >= k+1 and s[k] in okset'. There are many examples like this where is slicing did not clamp, the user would have to reproduce some of the logic done by slices. -- Terry Jan Reedy From cs at cskk.id.au Mon Dec 4 17:02:03 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 5 Dec 2017 09:02:03 +1100 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: <20171204220203.GA64328@cskk.homeip.net> On 04Dec2017 14:13, Jason Maldonis wrote: >And I'll be honest -- I like the implementation of the LazyList I wrote >above. I think it's pretty logical, because it allows you to think about >the lazy list like this: "Treat the list like a norma list. If you run out >of bounds, get more data, then treat the list like a normal list again." >And I really like that clean logic. Yes, it is very attractive. I've got a buffer class with that behaviour which is very useful for parsing data streams. I think the salient difference between your LazyList's API and my buffer's API is that in mine, the space allocation is a distinct operation from the __getitem__. My buffer class keeps an internal buffer of unconsumed data, and its __getitem__ indexes only that. It has two methods for "on demand": .extend(), which ensures that the internal buffer has at least n bytes, and .take(), which does a .extend and then returns the leading n bytes (trimming them from the internal buffer of course). So if I need to inspect the buffer I do a .extend to ensure there's enough data, then one can directly use [] to look at stuff, or use .take to grab a known size chunk. The .extend and .take operation accept an optional "short_ok" boolean, default False. When false, .extend and .take raise an exception if there aren't enough data available, otherwise they can return with a short buffer containing what was available. That covers your slice situation: true implies Python-like slicing and false (the default) acts like you (and I) usually want: an exception. And it sidesteps Python's design decisions because it leaves the __getitem__ semantics unchanged. One ensures the require preconditions (enough data) by calling .extend _first_. Here's some example code parsing an ISO14496 Box header record, which has 2 4 byte values at the start. The code uses short_ok to probe for immediate end-of-input. But if there are data, it uses .extend and .take in default mode so that an _incomplete_ record raises an exception: def parse_box_header(bfr): ''' Decode a box header from the CornuCopyBuffer `bfr`. Return (box_header, new_buf, new_offset) or None at end of input. ''' # return BoxHeader=None if at the end of the data bfr.extend(1, short_ok=True) if not bfr: return None # note start point offset0 = bfr.offset user_type = None bfr.extend(8) box_size, = unpack('>L', bfr.take(4)) box_type = bfr.take(4) In summary, I think you should give your LazyList a .extend method to establish your code's precondition (enough elements) and then you can proceed with your slicing in surety that it will behave correctly. Cheers, Cameron Simpson (formerly cs at zip.com.au) From rantingrickjohnson at gmail.com Mon Dec 4 17:22:54 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 14:22:54 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> Terry Reedy wrote: [...] > try: > item = seq[n] > except IndexError > do_without_item() > else: > process(item) > > item = seq[n:n+1] > if item: > process(item) > else: > do_without_item() > > Many prefer the second. And they'll prefer it even more when they realize the entire ELSE clause of your latter example is superfluous. But there are many usages where the conditional logic is not needed at all. Sometimes you don't care what you get back from a slice. Yep, even when the slice is a null string. From rosuav at gmail.com Mon Dec 4 17:29:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Dec 2017 09:29:48 +1100 Subject: why won't slicing lists raise IndexError? In-Reply-To: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> Message-ID: Against my better judgement, I'm going to ask... On Tue, Dec 5, 2017 at 9:22 AM, Rick Johnson wrote: > Terry Reedy wrote: > > [...] > >> try: >> item = seq[n] >> except IndexError >> do_without_item() >> else: >> process(item) >> >> item = seq[n:n+1] >> if item: >> process(item) >> else: >> do_without_item() >> >> Many prefer the second. > > And they'll prefer it even more when they realize the entire ELSE > clause of your latter example is superfluous. ... how is it superfluous? ChrisA From larry.martell at gmail.com Mon Dec 4 18:46:21 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 4 Dec 2017 18:46:21 -0500 Subject: zlib OverflowError: 'size does not fit in an int' Message-ID: Trying to zip a large file is failing with OverflowError: 'size does not fit in an int'. Googling I found this: https://bugs.python.org/issue23306 and this: https://hg.python.org/cpython/rev/2192edcfea02 which seems to make me think this was fixed this was fixed on Jul 23 2016. I am running CentOS 7 and I have python version: Python 2.7.5 (default, Sep 15 2016, 22:37:39) Which I guess does not have this fix. How can I get a version with that fix (that doesn't break CentOS) From rantingrickjohnson at gmail.com Mon Dec 4 18:50:55 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 15:50:55 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> Message-ID: <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> Chris Angelico wrote: > wrote: > > Terry Reedy wrote: > > > > [...] > > > >> try: > >> item = seq[n] > >> except IndexError > >> do_without_item() > >> else: > >> process(item) > >> > >> item = seq[n:n+1] > >> if item: > >> process(item) > >> else: > >> do_without_item() > >> > >> Many prefer the second. > > > > And they'll prefer it even more when they realize the entire ELSE > > clause of your latter example is superfluous. > > ... how is it superfluous? If the only purpose of an if/else logic structure is to process an arbitrary value _only_ when that value is "truthy", and futhermore, the else clause does nothing of any significance (and in the example provided, appears to be nothing but a placeholder for dead code) then why bother writing the else clause in the first place? I'm not questioning Terry's skills here. I'm merely pointing out that there seems to be no justification for the else clause in this example. Indeed, there are valid instances when a decision making process requires an explicit binary choice (aka: if/else), but the provided example seems to be saying something more like this: # BEGIN CODE (Py2.x, Untested!) ## if item: do_something_with(item) else: import cons as cons try: try: h = get_handle_for_current_module() except NameError: import gvrs_backdoor h = gvrs_backdoor.force_connection(cons.CURRENT_MODULE) # # Assume we have a valid module handle here. # with h.request_connection(cons.PYTHON) as py: py.send_message(cons.EXIT_CONDITIONAL) except Exception as e: # # Alas, now we must wipe the sweat from our brow # and accept our unavoidable fate. ':-( # # But first! We shall be good stewards and log # this error message. # msg = e.message print msg[len(msg):] del msg # # Now: 1. 2.. 3... JUMP! # pass ## END CODE ## Of course, we could have accomplished the same goal -- and burned a few less processor cycles in the meantime -- by omitting the superflouous else clause. But to each, his or her own, i suppose. From torriem at gmail.com Mon Dec 4 19:03:02 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 4 Dec 2017 17:03:02 -0700 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. In-Reply-To: <3517ea12-8055-cedc-364f-ad57dcacdc53@tjol.eu> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <3517ea12-8055-cedc-364f-ad57dcacdc53@tjol.eu> Message-ID: <1177741c-9f49-55e0-b2f5-e4f3622fd9de@gmail.com> On 12/04/2017 04:49 AM, Thomas Jollans wrote: > On 2017-12-04 10:48, dhananjaysingh091298 at gmail.com wrote: >> Respected Sir/Mam, >> I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. >> Sir please help me. >> > > https://askubuntu.com/a/544544 Oops! You misread his question. The question was, how can he run a python script by simply double clicking on it in the file browser in Ubuntu? Now I don't know the answer to that question, but I can say that nearly all the time you just don't want to do that anyway, for reasons I state below. Instead, open a terminal, change to the directory where you python script is and either run it directly (if it's chmod'd as exectuable) using "./myscript.py" or use the python interpreter: "python3 /path/to/myscript.py" The reason scripts are rarely launched from the file browser like you want to do is that often scripts communicate with the user via standard out, so you need to run them from a terminal. There are some GUI programs written in Python, but those are usually launched from a .desktop file shortcut. From tjol at tjol.eu Mon Dec 4 19:10:02 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 5 Dec 2017 01:10:02 +0100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. In-Reply-To: <1177741c-9f49-55e0-b2f5-e4f3622fd9de@gmail.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <3517ea12-8055-cedc-364f-ad57dcacdc53@tjol.eu> <1177741c-9f49-55e0-b2f5-e4f3622fd9de@gmail.com> Message-ID: <66208e3f-8d2d-1e7d-dc20-279bc900d065@tjol.eu> On 05/12/17 01:03, Michael Torrie wrote: > On 12/04/2017 04:49 AM, Thomas Jollans wrote: >> On 2017-12-04 10:48, dhananjaysingh091298 at gmail.com wrote: >>> Respected Sir/Mam, >>> I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. >>> Sir please help me. >>> >> >> https://askubuntu.com/a/544544 > > Oops! You misread his question. The question was, how can he run a > python script by simply double clicking on it in the file browser in > Ubuntu? No, I was just being (rudely, perhaps) terse. The file browser used by default in Ubuntu/Gnome (aka Nautilus) has a setting, as described in that Ask Ubuntu answer, that makes it execute scripts, Python or otherwise, on double click (as long as they have a correct #! line and are executable) > > Now I don't know the answer to that question, but I can say that nearly > all the time you just don't want to do that anyway, for reasons I state > below. I absolutely agree. > > Instead, open a terminal, change to the directory where you python > script is and either run it directly (if it's chmod'd as exectuable) > using "./myscript.py" or use the python interpreter: "python3 > /path/to/myscript.py" > > The reason scripts are rarely launched from the file browser like you > want to do is that often scripts communicate with the user via standard > out, so you need to run them from a terminal. > > There are some GUI programs written in Python, but those are usually > launched from a .desktop file shortcut. > > > From rosuav at gmail.com Mon Dec 4 19:13:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Dec 2017 11:13:05 +1100 Subject: why won't slicing lists raise IndexError? In-Reply-To: <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> Message-ID: On Tue, Dec 5, 2017 at 10:50 AM, Rick Johnson wrote: > Chris Angelico wrote: >> wrote: >> > Terry Reedy wrote: >> > >> > [...] >> > >> >> try: >> >> item = seq[n] >> >> except IndexError >> >> do_without_item() >> >> else: >> >> process(item) >> >> >> >> item = seq[n:n+1] >> >> if item: >> >> process(item) >> >> else: >> >> do_without_item() >> >> >> >> Many prefer the second. >> > >> > And they'll prefer it even more when they realize the entire ELSE >> > clause of your latter example is superfluous. >> >> ... how is it superfluous? > > If the only purpose of an if/else logic structure is to > process an arbitrary value _only_ when that value is > "truthy", and futhermore, the else clause does nothing of > any significance (and in the example provided, appears to > be nothing but a placeholder for dead code) then why > bother writing the else clause in the first place? Ahhh, I see how it is. You didn't run the code, ergo you don't understand it. Makes perfect sense. :) Hint: Truthiness is fairly clearly defined here, regardless of the value of item. ChrisA From rosuav at gmail.com Mon Dec 4 19:15:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Dec 2017 11:15:39 +1100 Subject: zlib OverflowError: 'size does not fit in an int' In-Reply-To: References: Message-ID: On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell wrote: > Trying to zip a large file is failing with OverflowError: 'size does > not fit in an int'. Googling I found this: > > https://bugs.python.org/issue23306 > > and this: > > https://hg.python.org/cpython/rev/2192edcfea02 > > which seems to make me think this was fixed this was fixed on Jul 23 2016. > > I am running CentOS 7 and I have python version: > > Python 2.7.5 (default, Sep 15 2016, 22:37:39) > > Which I guess does not have this fix. How can I get a version with > that fix (that doesn't break CentOS) First thing I'd consider is a Python 3.x version. Is there one in your CentOS repositories? If not, worst case, you can compile one from source or get one from some other repo, and it can't possibly break your system because it won't mess with anything you're using. If you absolutely HAVE to stick with 2.7, you may do well to compile from source and NOT install - just run the binary from the source directory. ChrisA From larry.martell at gmail.com Mon Dec 4 19:21:40 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 4 Dec 2017 19:21:40 -0500 Subject: zlib OverflowError: 'size does not fit in an int' In-Reply-To: References: Message-ID: On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: > On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell wrote: >> Trying to zip a large file is failing with OverflowError: 'size does >> not fit in an int'. Googling I found this: >> >> https://bugs.python.org/issue23306 >> >> and this: >> >> https://hg.python.org/cpython/rev/2192edcfea02 >> >> which seems to make me think this was fixed this was fixed on Jul 23 2016. >> >> I am running CentOS 7 and I have python version: >> >> Python 2.7.5 (default, Sep 15 2016, 22:37:39) >> >> Which I guess does not have this fix. How can I get a version with >> that fix (that doesn't break CentOS) > > First thing I'd consider is a Python 3.x version. Is there one in your > CentOS repositories? If not, worst case, you can compile one from > source or get one from some other repo, and it can't possibly break > your system because it won't mess with anything you're using. > > If you absolutely HAVE to stick with 2.7, you may do well to compile > from source and NOT install - just run the binary from the source > directory. This is a django app, using version 1.9, installed on many sites that do not have external internet access, so any changes are onerous. Possible, but a PITA. I will look into building from source. From tjol at tjol.eu Mon Dec 4 19:25:54 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 5 Dec 2017 01:25:54 +0100 Subject: zlib OverflowError: 'size does not fit in an int' In-Reply-To: References: Message-ID: <8e5e8670-07c3-c2a2-38d0-0f4b5e9e1b49@tjol.eu> On 05/12/17 01:15, Chris Angelico wrote: > On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell wrote: >> Trying to zip a large file is failing with OverflowError: 'size does >> not fit in an int'. Googling I found this: >> >> https://bugs.python.org/issue23306 >> >> and this: >> >> https://hg.python.org/cpython/rev/2192edcfea02 >> >> which seems to make me think this was fixed this was fixed on Jul 23 2016. >> >> I am running CentOS 7 and I have python version: >> >> Python 2.7.5 (default, Sep 15 2016, 22:37:39) >> >> Which I guess does not have this fix. How can I get a version with >> that fix (that doesn't break CentOS) > > First thing I'd consider is a Python 3.x version. Is there one in your > CentOS repositories? If not, worst case, you can compile one from > source or get one from some other repo, and it can't possibly break > your system because it won't mess with anything you're using. For CentOS, I recommend using either an SCL (https://www.softwarecollections.org/en/scls/rhscl/rh-python36/) or perhaps Anaconda. Installing Python 3 with an SCL is nice because it's managed through your package manager, but is completely independent of the system Python (so it won't break anything). You have to enable it on a case-by-case basis when you want to use it, which can be a bit finicky. > > If you absolutely HAVE to stick with 2.7, you may do well to compile > from source and NOT install - just run the binary from the source > directory. > > ChrisA > From tjol at tjol.eu Mon Dec 4 19:36:07 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 5 Dec 2017 01:36:07 +0100 Subject: zlib OverflowError: 'size does not fit in an int' In-Reply-To: References: Message-ID: <0eff3459-50fe-d5f2-9483-16b0e2d47bad@tjol.eu> On 05/12/17 01:21, Larry Martell wrote: > On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: >> On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell wrote: >>> Trying to zip a large file is failing with OverflowError: 'size does >>> not fit in an int'. Googling I found this: >>> >>> https://bugs.python.org/issue23306 >>> >>> and this: >>> >>> https://hg.python.org/cpython/rev/2192edcfea02 >>> >>> which seems to make me think this was fixed this was fixed on Jul 23 2016. >>> >>> I am running CentOS 7 and I have python version: >>> >>> Python 2.7.5 (default, Sep 15 2016, 22:37:39) >>> >>> Which I guess does not have this fix. How can I get a version with >>> that fix (that doesn't break CentOS) >> >> First thing I'd consider is a Python 3.x version. Is there one in your >> CentOS repositories? If not, worst case, you can compile one from >> source or get one from some other repo, and it can't possibly break >> your system because it won't mess with anything you're using. >> >> If you absolutely HAVE to stick with 2.7, you may do well to compile >> from source and NOT install - just run the binary from the source >> directory. > > This is a django app, using version 1.9, installed on many sites that > do not have external internet access, so any changes are onerous. > Possible, but a PITA. I will look into building from source. > FWIW, there is also an SCL with a newer version of Python 2.7 (loathe as I am to point it out) See also: https://pythonclock.org/ From larry.martell at gmail.com Mon Dec 4 19:42:09 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 4 Dec 2017 19:42:09 -0500 Subject: zlib OverflowError: 'size does not fit in an int' In-Reply-To: <0eff3459-50fe-d5f2-9483-16b0e2d47bad@tjol.eu> References: <0eff3459-50fe-d5f2-9483-16b0e2d47bad@tjol.eu> Message-ID: On Mon, Dec 4, 2017 at 7:36 PM, Thomas Jollans wrote: > On 05/12/17 01:21, Larry Martell wrote: >> On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: >>> On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell wrote: >>>> Trying to zip a large file is failing with OverflowError: 'size does >>>> not fit in an int'. Googling I found this: >>>> >>>> https://bugs.python.org/issue23306 >>>> >>>> and this: >>>> >>>> https://hg.python.org/cpython/rev/2192edcfea02 >>>> >>>> which seems to make me think this was fixed this was fixed on Jul 23 2016. >>>> >>>> I am running CentOS 7 and I have python version: >>>> >>>> Python 2.7.5 (default, Sep 15 2016, 22:37:39) >>>> >>>> Which I guess does not have this fix. How can I get a version with >>>> that fix (that doesn't break CentOS) >>> >>> First thing I'd consider is a Python 3.x version. Is there one in your >>> CentOS repositories? If not, worst case, you can compile one from >>> source or get one from some other repo, and it can't possibly break >>> your system because it won't mess with anything you're using. >>> >>> If you absolutely HAVE to stick with 2.7, you may do well to compile >>> from source and NOT install - just run the binary from the source >>> directory. >> >> This is a django app, using version 1.9, installed on many sites that >> do not have external internet access, so any changes are onerous. >> Possible, but a PITA. I will look into building from source. >> > > FWIW, there is also an SCL with a newer version of Python 2.7 (loathe as > I am to point it out) > > See also: https://pythonclock.org/ Where is there a link on that page to download a new version of 2.7? From waylan.limberg at icloud.com Mon Dec 4 19:55:16 2017 From: waylan.limberg at icloud.com (waylan) Date: Tue, 05 Dec 2017 12:55:16 +1200 Subject: How to upload to Pythonhosted.org References: <922593953@f38.n261.z1.binkp.net> Message-ID: <4232940931@f38.n261.z1.binkp.net> After asking here, I found a mailing list post here: https://mail.python.org/pipermail/distutils-sig/2015-May/026381.html That post outlines a roadmap for shutting down pythonhosted. Unfortunately, it seems that they skipped from step 1 to step 5 without bothering with steps 2, 3, & 4. In any event, that list discussion seems to be the official word that things are being shut down, which was what I was looking for. It's unfortunate that things weren't done more smoothly. Also it seems that if you want to avoid search results showing up for the pythonhosted content after you find a new host, they at least provide a way to "delete" the content from pyhtonhosted. That way, Google will stop indexing it and stop including it in search results. Unfortunately, all the existing links across the internet are now dead with no way to redirect people. Waylan On Thursday, November 30, 2017 at 1:47:32 PM UTC-5, Irmen de Jong wrote: > On 11/30/2017 03:31 AM, Ben Finney wrote: > > Irmen de Jong writes: > > > >> On 11/30/2017 02:06 AM, waylan wrote: > >>> So, how do I upload an update to my documentation? > >> > >> I ran into the same issue. From what I gathered, Pythonhosted.org is > >> in the process of being dismantled and it hasn't allowed new doc > >> uploads for quite some time now. I switched to using readthedocs.io > >> instead. > > > > The issue that many are facing is how to update the pages *at the > > existing URL* to tell visitors where to go next. Cool URIs don't change > > but, when they do, we > > are obliged to update the existing pages to point to the new ones. > > Sorry, yes, that is the problem I experience as well. My library's old version > documentation is somehow frozen on Pythonhosted.org (and obviously still pops up as the > first few google hits). > > > > So, if pythonhosted.org is indeed being dismantled, there should be a > > way to update the pages there for informing visitor where they should go > > next. > > > > If that's not possible and instead the service is just locked down, > > that's IMO a mistake. > > I agree with that. I think it's an unsolved issue until now, that gets some discussion > in this github issue https://github.com/pypa/warehouse/issues/582 > > > Irmen From skip.montanaro at gmail.com Mon Dec 4 20:03:36 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 05 Dec 2017 13:03:36 +1200 Subject: csv.DictReader line skipping should be considered a bug? Message-ID: <4259277366@f38.n261.z1.binkp.net> > And I want to argue that the difference of behavior should be considered a bug. Sorry, that ship has sailed. If you want different behavior, subclassing DictReader and providing your own next() implementation should be straightforward. All you need to do is copy the existing implementation of next() and strip out the comment and the while loop which follows it. Skip From rantingrickjohnson at gmail.com Mon Dec 4 20:03:48 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 17:03:48 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> Message-ID: On Monday, December 4, 2017 at 6:13:19 PM UTC-6, Chris Angelico wrote: [...] > Ahhh, I see how it is. You didn't run the code, ergo you > don't understand it. Makes perfect sense. :) Being that Terry didn't offer any declarations or defintions for his variables or functions, i assumed, i suppose, like any other rational person, that it was all just pseudo code. But, in any event, i don't see how running the code and then watching helplessly as a volley of NameErrors come rip- roaring down a stdout stream like a half naked, middle-aged drunk feller bobbing precariously along a river rapid -- hey, look out for that rock! -- is going to help shed any light on any of this. But i suppose it's possible i missed an esoteric joke somewhere... From jjmaldonis at gmail.com Mon Dec 4 20:37:09 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Mon, 4 Dec 2017 19:37:09 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> Message-ID: I'll try to summarize what I've learned with a few responses in hodge-podge order and to no one in particular: >That's a feature dude, not a bug. Absolutely. I _do not_ think that how slicing works in python should be changed, but I _do_ want to understand its design decisions because it will make me a better programmer. >one thing Python consistently emphasises is making things easy for >the user, even if that convenience comes at a cost to the implementer. I completely agree, and I'm always happy to do the work as a developer to make the user experience better. That's something I really appreciate about python as well. >I've got a buffer class with that behaviour which is very useful for parsing data streams. [...] >In summary, I think you should give your LazyList a .extend method to establish your code's precondition (enough elements) and then you can proceed with your slicing in surety that it will behave correctly. Thanks for this detailed response, I'll have to reread it a few times to understand it but I think I'll understand how I might improve my implementation from your example. In particular, that last "In summary" sentence hit on something I'd been thinking about. A `.extend` method might clean things up nicely. -- It seems to me that the consensus on the reason for why slices don't throw IndexErrors is essentially "It's very convenient for them not to" and I'm just fine with that response (not super thrilled, but happy enough). There were two comments in particular that sounded pretty good: >But as a user, I can say that I find the ability to use slices without checking for >out of bounds cases or handling exceptions to be really convenient. That's fair. The alternative would be something that someone else mentioned: `my_string[ : min(n, len(my_string))]` and that's not very pretty, although I don't think it's absolutely horrible. And: the use case where you are trying to split a list or string at index `n` is: `first_half, second_half = my_string[:n], my_string[n:]` and if n > len(my_string) then this use case becomes a bit annoying to write (although it could use the `min` example above). So I guess the conclusion (as far as I can tell) is that: `my_string[:n]` is more convenient than `my_string[:min(n, len(my_string))]`, and that sounds okay enough to me. If I'm being completely honest I kinda like the logical explicitness of the latter, but it's way less convenient. And I'm 100% sure the people who made this decision are incredibly smart, and I certainly trust their decision. Thanks everyone for the responses. On Mon, Dec 4, 2017 at 6:13 PM, Chris Angelico wrote: > On Tue, Dec 5, 2017 at 10:50 AM, Rick Johnson > wrote: > > Chris Angelico wrote: > >> wrote: > >> > Terry Reedy wrote: > >> > > >> > [...] > >> > > >> >> try: > >> >> item = seq[n] > >> >> except IndexError > >> >> do_without_item() > >> >> else: > >> >> process(item) > >> >> > >> >> item = seq[n:n+1] > >> >> if item: > >> >> process(item) > >> >> else: > >> >> do_without_item() > >> >> > >> >> Many prefer the second. > >> > > >> > And they'll prefer it even more when they realize the entire ELSE > >> > clause of your latter example is superfluous. > >> > >> ... how is it superfluous? > > > > If the only purpose of an if/else logic structure is to > > process an arbitrary value _only_ when that value is > > "truthy", and futhermore, the else clause does nothing of > > any significance (and in the example provided, appears to > > be nothing but a placeholder for dead code) then why > > bother writing the else clause in the first place? > > Ahhh, I see how it is. You didn't run the code, ergo you don't > understand it. Makes perfect sense. :) > > Hint: Truthiness is fairly clearly defined here, regardless of the > value of item. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From ned at nedbatchelder.com Mon Dec 4 20:47:06 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 4 Dec 2017 20:47:06 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> Message-ID: <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> On 12/4/17 8:03 PM, Rick Johnson wrote: > On Monday, December 4, 2017 at 6:13:19 PM UTC-6, Chris Angelico wrote: > > [...] > >> Ahhh, I see how it is. You didn't run the code, ergo you >> don't understand it. Makes perfect sense. :) > Being that Terry didn't offer any declarations or defintions > for his variables or functions, i assumed, i suppose, like > any other rational person, that it was all just pseudo code. > > But, in any event, i don't see how running the code and then > watching helplessly as a volley of NameErrors come rip- > roaring down a stdout stream like a half naked, middle-aged > drunk feller bobbing precariously along a river rapid -- > hey, look out for that rock! -- is going to help shed any > light on any of this. > > But i suppose it's possible i missed an esoteric joke > somewhere... Here are details filled in: $ python3.6 Python 3.6.3 (default, Oct? 4 2017, 06:03:25) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def do_the_thing(seq, n): ...???? item = seq[n:n+1] ...???? if item: ...???????? print(f"process({item})") ...???? else: ...???????? print("do_without_item()") ... >>> do_the_thing([1, 2, 3], 2) process([3]) >>> do_the_thing([1, 2, 3], 5) do_without_item() >>> --Ned. From python at mrabarnett.plus.com Mon Dec 4 21:24:43 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 5 Dec 2017 02:24:43 +0000 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> Message-ID: <12f59435-c1f5-51d1-3155-7a57a2259288@mrabarnett.plus.com> On 2017-12-05 01:37, Jason Maldonis wrote: [snip] > So I guess the conclusion (as far as I can tell) is that: `my_string[:n]` > is more convenient than `my_string[:min(n, len(my_string))]`, and that > sounds okay enough to me. > > If I'm being completely honest I kinda like the logical explicitness of the > latter, but it's way less convenient. And I'm 100% sure the people who made > this decision are incredibly smart, and I certainly trust their decision. > Thanks everyone for the responses. > The first sentence of this paragraph can be summarised as "Practicality beats purity". It's in the Zen. From rantingrickjohnson at gmail.com Mon Dec 4 21:31:34 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 18:31:34 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> Message-ID: <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> On Monday, December 4, 2017 at 7:47:20 PM UTC-6, Ned Batchelder wrote: [...] > Here are details filled in: > > $ python3.6 > Python 3.6.3 (default, Oct 4 2017, 06:03:25) > [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> def do_the_thing(seq, n): > ... item = seq[n:n+1] > ... if item: > ... print(f"process({item})") > ... else: > ... print("do_without_item()") > ... > >>> do_the_thing([1, 2, 3], 2) > process([3]) > >>> do_the_thing([1, 2, 3], 5) > do_without_item() > >>> Thanks for filling in the blanks. However, my objection to this else-clause stems from a perspective based in pragmatics. Specifically, i see no benefit here in logging the "non-action". Sure, perhaps logging a non-action may serve a useful purpose during debugging sessions, but i find them to be nothing but useless noise in production code. Do you agree or disagree with my assessment? If you disagree, please explain why. From rosuav at gmail.com Mon Dec 4 21:37:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Dec 2017 13:37:58 +1100 Subject: why won't slicing lists raise IndexError? In-Reply-To: <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> Message-ID: On Tue, Dec 5, 2017 at 1:31 PM, Rick Johnson wrote: > On Monday, December 4, 2017 at 7:47:20 PM UTC-6, Ned Batchelder wrote: > > [...] > >> Here are details filled in: >> >> $ python3.6 >> Python 3.6.3 (default, Oct 4 2017, 06:03:25) >> [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>> def do_the_thing(seq, n): >> ... item = seq[n:n+1] >> ... if item: >> ... print(f"process({item})") >> ... else: >> ... print("do_without_item()") >> ... >> >>> do_the_thing([1, 2, 3], 2) >> process([3]) >> >>> do_the_thing([1, 2, 3], 5) >> do_without_item() >> >>> > > Thanks for filling in the blanks. However, my objection to > this else-clause stems from a perspective based in > pragmatics. Specifically, i see no benefit here in logging > the "non-action". Sure, perhaps logging a non-action may serve a > useful purpose during debugging sessions, but i find them to > be nothing but useless noise in production code. > > Do you agree or disagree with my assessment? > > If you disagree, please explain why. Why do you believe this to be a non-action? There is no indication that do_without_item does nothing. ChrisA From ned at nedbatchelder.com Mon Dec 4 21:50:13 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 4 Dec 2017 21:50:13 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> Message-ID: <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> On 12/4/17 9:31 PM, Rick Johnson wrote: > On Monday, December 4, 2017 at 7:47:20 PM UTC-6, Ned Batchelder wrote: > > [...] > >> Here are details filled in: >> >> $ python3.6 >> Python 3.6.3 (default, Oct 4 2017, 06:03:25) >> [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>> def do_the_thing(seq, n): >> ... item = seq[n:n+1] >> ... if item: >> ... print(f"process({item})") >> ... else: >> ... print("do_without_item()") >> ... >> >>> do_the_thing([1, 2, 3], 2) >> process([3]) >> >>> do_the_thing([1, 2, 3], 5) >> do_without_item() >> >>> > Thanks for filling in the blanks. However, my objection to > this else-clause stems from a perspective based in > pragmatics. Specifically, i see no benefit here in logging > the "non-action". Sure, perhaps logging a non-action may serve a > useful purpose during debugging sessions, but i find them to > be nothing but useless noise in production code. > > Do you agree or disagree with my assessment? > > If you disagree, please explain why. The point of the example was to demonstrate what happens when slicing beyond the bounds of the list.? It's beyond the scope of the thread to debate whether you might want to perform an action in that case.? I think we've demonstrated the slicing semantics well. --Ned. From ikorot01 at gmail.com Mon Dec 4 22:39:46 2017 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 05 Dec 2017 15:39:46 +1200 Subject: we want python software Message-ID: <949889101@f38.n261.z1.binkp.net> Hi, Tony, On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: > On 05/12/17 16:55, Igor Korot wrote: >> Hi, >> >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy >> wrote: >>> Sir, >>> I am b.tech student I would like to learn python. So please send the python software. >> Sorry, we don't send anything. You will have to go get it yourself. -) >> > Well, at least try to be helpful: > https://www.python.org/downloads/ This is LMGIFY. If they say they are tech students - they should know how to work with Google. And I even tried to be polite. I should have probably write something like: 1. Open the Web browser. 2. In the "Address Bar" type "www.pyton.org". 3. Find the link which reads "Downloads". Click on it. 4. Carefully read what version you need to install for your OS. 5. Apply the acquired knowledge and download the appropriate version. 6. Click on the installer (if on Windows). 7. Follow all the prompts. 8. Enjoy. but this is too much for the tech student. Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From rantingrickjohnson at gmail.com Mon Dec 4 22:41:49 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Dec 2017 19:41:49 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> Message-ID: <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> Ned Batchelder wrote: [...] > The point of the example was to demonstrate what happens > when slicing beyond the bounds of the list. It's beyond > the scope of the thread to debate whether you might want to > perform an action in that case. But, nevertheless, the else-clause is there! And that's the point i've been trying to make. The inclusion of this else- clause only serves to distract from the intent of the lesson and also the main topic of the thread. Hence my objection. > I think we've demonstrated the slicing semantics well. Indeed. And i never questioned this aspect. I merely wanted to inform the lurkers that the else-clause was handling a non-action, and therefore, could be omitted. I believe strongly that bad examples are worse than no examples at all. Consider the following: Take for example the Tkinter method `root.quit()`, a method that was presented in a famous web tutorial many years ago, and has since (even to this _day_!) caused misconceptions in the mind's of noobs as to its _true_ function. Sure, part of that misconception can be blamed on a poor name choice, as root.suspend_event_processing() would have been self- explanatory. But this method is for advanced usage, and thus, should not be a part of _any_ introductory or even intermediate lesson. Of course, once the tut owner posted this bad code, other tut owners just blindly copy/pasted, and the damage has spread all over the web. Or the example code presented as an introductory to defining functions in the official Python documentation, one which distracts from the main topic with an algorithm which builds a Fibonacci sequence. Both of these examples underscore the importance of clear presentation, and what can go wrong if one fails to heed this protocol of good teaching. From rustompmody at gmail.com Mon Dec 4 23:04:30 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Dec 2017 20:04:30 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: Message-ID: <414ba7fc-5ac8-479e-8a32-ddf300630fc4@googlegroups.com> On Tuesday, December 5, 2017 at 12:40:01 AM UTC+5:30, Jason Maldonis wrote: > I was extending a `list` and am wondering why slicing lists will never > raise an IndexError, even if the `slice.stop` value if greater than the > list length. > > Quick example: > > my_list = [1, 2, 3] > my_list[:100] # does not raise an IndexError, but instead returns the full > list > > Is there any background on why that doesn't raise an IndexError? Knowing > that might help me design my extended list class better. For my specific > use case, it would simplify my code (and prevent `if isinstance(item, > slice)` checks) if the slicing raised an IndexError in the example I gave. Data Structures have invariants. Some of these are just side-notes? interesting, cute Some are more fundamental, the raison d'?tre for the data structure Whether the following inv is that fundamental or not I wont offer an opinion It certainly seems important (to me) Python slice inv: (? n:?, l:sequence | l[:n] + l[n:] == l) Your preferred inv: (? n:?, l:sequence ? jason_caveat(n) | l[:n] + l[n:] == l) where def jason_caveat(n,l): return 0 ? n ? len(l) Do you consider it arguable that your preferred invariant is at least more heavy-weight if not downright clunkier? Note I am not offering a view on this. eg for zip python does this >>> zip([1,2,3], [4,5,6,7,8]) [(1, 4), (2, 5), (3, 6)] I find myself sometimes needing this Sometimes needing it extended to the longer (with what??) Sometimes needing your preferred behavior ? an exception On a more fundamental note: def const(x): return 42 has the invariant that const(x) == 42 when x is well-defined This is true for most mainstream languages Lazy functional languages (like Haskell) make a big deal of not having the definedness caveat. People (like me) not quite on the FP bandwagon are conflicted on whether the mathematical elegance is worth the computational mess From lists at vanderhoff.org Tue Dec 5 00:10:32 2017 From: lists at vanderhoff.org (Tony van der Hoff) Date: Tue, 05 Dec 2017 17:10:32 +1200 Subject: we want python software Message-ID: <1341936746@f38.n261.z1.binkp.net> On 05/12/17 16:55, Igor Korot wrote: > Hi, > > On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy > wrote: >> Sir, >> I am b.tech student I would like to learn python. So please send the python software. > Sorry, we don't send anything. You will have to go get it yourself. -) > Well, at least try to be helpful: https://www.python.org/downloads/ From nick.martinez2 at aol.com Tue Dec 5 00:33:18 2017 From: nick.martinez2 at aol.com (nick martinez2) Date: Tue, 05 Dec 2017 17:33:18 +1200 Subject: Python homework Message-ID: <3079057093@f38.n261.z1.binkp.net> I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 times and then prints (i). the most frequent side of the die (ii). the average die value of all rolls. I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. This is what I have so far: import random def rollDie(number): rolls = [0] * 6 for i in range(0, number): roll=int(random.randint(1,6)) rolls[roll - 1] += 1 return rolls if __name__ == "__main__": result = rollDie(50) print (result) print(max(result)) From rantingrickjohnson at gmail.com Tue Dec 5 01:23:04 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 05 Dec 2017 18:23:04 +1200 Subject: why won't slicing lists raise IndexError? Message-ID: <2008578615@f38.n261.z1.binkp.net> Steve D'Aprano wrote: [...] > You've already been told that there's no indication or > reason to believe that it is a non-action. You've already > been given at least one possible action. It isn't a non- > action, it is two distinct actions: > > - the action you take when the slice is non-empty; > > - the action you take when the slice is empty. When Python follows a logic clause like a train skating along a set of railroad tracks, and finds itself in a *GHOST TOWN*, that's not an action -- "Steve-o" -- it's a non- action. Listen, I think it might help you to understand the absurdity of this else-clause if you ruminate about this code using a metaphor. Below, i've defined some fictional characters and objects that will live in a little metaphorical world, and futhermore, explained how these characters and objects relate to our real-life code example. TERRY("THE BUILDER"): Terry is a personable fella who builds little shanty towns for a living. IF_VILLE: This is the first of two towns that Terry establish in our little metaphorical world. And although it's not quite the shining-city-on-a-hill that he, or the inhabitants, had envisioned, he did manage to build a proper train platform and a small warehouse for strong deliverables, so we shouldn't be too critical of his work here. ELSE_VILLE: This is the "other" town that Terry establish. However, after slaving away in the hot desert sun building IF_VILLE all day, Terry decided to go home and drink a case of beer, became drunk, and then forgot all about his responsibilities to develope ELSE_VILLE. This has happened before. But we typically forgive Terry for his irresponsible nature simple because he's such a personable fella. However, if this gets any worse, we may have to give him an intervention. KENNY_LINTER: Kenny Linter is a faithful civil servant who's sole job is to inspect little shanty towns. And though he's a little short on manners, he is typically competent _enough_ to tell us if our towns are built to quality standards, and if they're not built to quality standards, well, it's his job to annoy us until we repair them. Unfortunately, i've got some bad news to share with you. After hastily exiting the train in ELSE-VILLE last night and not realizing there was no platform in this town (Thanks Terry!), KENNY_LINTER has broken both of his legs, fractured an arm, and scratched his face up pretty bad. So i doubt we'll be hearing from him in this episode, but stay tuned for future appearances. THE_TRAIN: The Train represents our Python script. THE_TRACKS: The (railroad)tracks represent our program logic. And the train's course is bound to these tracks THE_ENGINEER: This is the Python runtime which "drives" the train. THE_TRACK_SWITCH: The Track Switch is a mechanical section of the track (aka: logic gate) placed approximately halfway between the train station and the two shanty towns that Terry built. The switch allows the train to travel in one of two directions -- one leading to IF_VILLE, and one leading to ELSE_VILLE. Now, the mechanical apparatus of the switch is spring loaded, and thus, by default, it always sends a passing train to ELSE_VILLE. However, there is a tiny control button mounted on a nearby fence post, one which when pressed, will align the tracks with IF_VILLE. However, since the trains in this metaphor have no brakes, and since the button is really ~really~ small -- and since i couldn't think of a more creative scenario! -- there is only one creature who can press this button (TRUTHY_CLAWS!). And she presses this button using one of her long pointy claws, and thus, can send the train towards IF_VILLE. TRUTHY_CLAWS: TruthyClaws (or "TC", as we like to call her) is a mostly harmless anthropomorphized version of a marsupial who's long claws only seem useful (at least upon first sight) for causing a dreadful fright. But in reality, these claws serve a vital purpose in our little metaphorical world. You see, of ~all~ the characters in our little universe, only TC (using one of her dreadfully long claws) can press the little button on the TRACK_SWITCH and send us along a path to IF-VILLE. And, every time TC takes a ride with us in the train, she presses the little button for us, and off we go to IF-VILLE (Hooray!). However, sometimes us guys get a little rowdy and tell dirty jokes during the trip, and TC, being uptight and all, tends to get offended, and sometimes she refuses to ride with us. So, whenever TC is with us, we always go to IF-VILLE, but if she's off pouting somewhere, the train goes to ELSE-VILLE THE_TRACK_DEVIL: The Track Devil is a supernatural being in the mold of Loki who specializes in all forms of mischievous pranks. And you never know where the little devil might pop- up next. Rumor has it he's been seen lurking around the THE_TRACK_SWITCH and placing coinage on the tracks, but we can neither confirm nor deny these rumours. Although, there is a strange old woman who lives on the outskirts of ELSE_VILLE who claims she can foretell the appearance of the track devil. But most people 'round these parts consider her to be a total nut job. Using this metaphor we can understand that the else-clause in Terry's example serves no practical purpose. And being that Kenny Linter is already in the hospital for an injury he would have _never_ suffered if the undeveloped ELSE_VILLE had not been on his inspection roster, how the hell can you justify your argument? I mean, seriously. Terry almost killed Kenny! From hasan.diwan at gmail.com Tue Dec 5 01:44:52 2017 From: hasan.diwan at gmail.com (Hasan Diwan) Date: Tue, 05 Dec 2017 18:44:52 +1200 Subject: [Python-Dev] [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available Message-ID: <3154461154@f38.n261.z1.binkp.net> Congrats to all involved! -- H? ? From ned at nedbatchelder.com Tue Dec 5 02:37:32 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 05 Dec 2017 19:37:32 +1200 Subject: f-string Message-ID: <1146633501@f38.n261.z1.binkp.net> On 12/5/17 7:16 PM, Steve D'Aprano wrote: > compile('f"{spam} {eggs}"', '', 'single') $ python3.6 Python 3.6.3 (default, Oct? 4 2017, 06:03:25) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> compile('f"{spam} {eggs}"', '', 'single') at 0x105e79660, file "", line 1> >>> co = _ >>> spam = 17 >>> eggs = 34 >>> eval(co) '17 34' >>> dis.dis(co) ? 1? ? ? ? ? ? ? ? ? ? 0 LOAD_NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 (spam) ? ? ? ? ? ? ? ? ? ? ? ? ? 2 FORMAT_VALUE? ? ? ? ? ? ? ? ? ? ? ? 0 ? ? ? ? ? ? ? ? ? ? ? ? ? 4 LOAD_CONST? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 (' ') ? ? ? ? ? ? ? ? ? ? ? ? ? 6 LOAD_NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 (eggs) ? ? ? ? ? ? ? ? ? ? ? ? ? 8 FORMAT_VALUE? ? ? ? ? ? ? ? ? ? ? ? 0 ? ? ? ? ? ? ? ? ? ? ? ? 10 BUILD_STRING? ? ? ? ? ? ? ? ? ? ? ? 3 ? ? ? ? ? ? ? ? ? ? ? ? 12 PRINT_EXPR ? ? ? ? ? ? ? ? ? ? ? ? 14 LOAD_CONST? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 (None) ? ? ? ? ? ? ? ? ? ? ? ? 16 RETURN_VALUE --Ned. From rustompmody at gmail.com Tue Dec 5 02:49:16 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 05 Dec 2017 19:49:16 +1200 Subject: we want python software References: <949889101@f38.n261.z1.binkp.net> Message-ID: <1168663431@f38.n261.z1.binkp.net> On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote: > Hi, Tony, > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: > > On 05/12/17 16:55, Igor Korot wrote: > >> Hi, > >> > >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote: > >>> Sir, > >>> I am b.tech student I would like to learn python. So please send the python software. > >> Sorry, we don't send anything. You will have to go get it yourself. -) > >> > > Well, at least try to be helpful: > > https://www.python.org/downloads/ > > This is LMGIFY. > If they say they are tech students - they should know how to work with Google. > > And I even tried to be polite. I should have probably write something like: > > 1. Open the Web browser. > 2. In the "Address Bar" type "www.pyton.org". > 3. Find the link which reads "Downloads". Click on it. > 4. Carefully read what version you need to install for your OS. > 5. Apply the acquired knowledge and download the appropriate version. > 6. Click on the installer (if on Windows). > 7. Follow all the prompts. > 8. Enjoy. > > but this is too much for the tech student. You are assuming that the strangeness of the request is about 'tech' [engineering/tech existed centuries before computers] Do remember one can be a tech-{student,professional} without - ever having encountered free-software - internet/USENET culture ? | from which pov the request would not look so odd From ssghotra1997 at gmail.com Tue Dec 5 04:02:54 2017 From: ssghotra1997 at gmail.com (ssghotra1997) Date: Tue, 05 Dec 2017 21:02:54 +1200 Subject: Python homework References: <3079057093@f38.n261.z1.binkp.net> Message-ID: <59472662@f38.n261.z1.binkp.net> import random def rollDie(num): sides = {'One':0, 'Two':0,'Three':0,'Four':0,'Five':0,'Six':0} for i in range(num): rolls = int(random.randint(1, 6)) if rolls == 1: sides['One'] += 1 if rolls == 2: sides['Two'] += 1 if rolls == 3: sides['Three'] += 1 if rolls == 4: sides['Four'] += 1 if rolls == 5: sides['Five'] += 1 if rolls == 6: sides['Six'] += 1 return sides,max(sides,key=sides.get) print(rollDie(50)) *********************** OUTPUT ********************************************* ({'One': 10, 'Two': 7, 'Three': 7, 'Four': 11, 'Five': 7, 'Six': 8}, 'Four') From nad at python.org Tue Dec 5 04:29:54 2017 From: nad at python.org (Ned Deily) Date: Tue, 05 Dec 2017 21:29:54 +1200 Subject: [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available for testing Message-ID: <1712108208@f38.n261.z1.binkp.net> Announcing the immediate availability of Python 3.6.4 release candidate 1 and of Python 3.7.0 alpha 3! Python 3.6.4rc1 is the first release candidate for Python 3.6.4, the next maintenance release of Python 3.6. While 3.6.4rc1 is a preview release and, thus, not intended for production environments, we encourage you to explore it and provide feedback via the Python bug tracker (https://bugs.python.org). 3.6.4 is planned for final release on 2017-12-18 with the next maintenance release expected to follow in about 3 months. You can find Python 3.6.4rc1 and more information here: https://www.python.org/downloads/release/python-364rc1/ Python 3.7.0a3 is the third of four planned alpha releases of Python 3.7, the next feature release of Python. During the alpha phase, Python 3.7 remains under heavy development: additional features will be added and existing features may be modified or deleted. Please keep in mind that this is a preview release and its use is not recommended for production environments. The next preview release, 3.7.0a4, is planned for 2018-01-08. You can find Python 3.7.0a3 and more information here: https://www.python.org/downloads/release/python-370a3/ -- Ned Deily nad at python.org -- [] From ethan at stoneleaf.us Tue Dec 5 05:17:14 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 05 Dec 2017 22:17:14 +1200 Subject: we want python software Message-ID: <3795236189@f38.n261.z1.binkp.net> On 12/05/2017 09:27 PM, km wrote: [snip] Many things in this world are frustrating, but being hateful will not solve anything. Please control yourself. -- ~Ethan~ From rustompmody at gmail.com Tue Dec 5 06:18:57 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Dec 2017 03:18:57 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> Message-ID: <726f5805-ac6c-48ea-9373-b8288f64fb05@googlegroups.com> On Tuesday, December 5, 2017 at 2:28:44 PM UTC+5:30, Lawrence D?Oliveiro wrote: > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: > > > > Sounds like your OS file associations are all botched-up ... > > Linux doesn?t do ?OS file associations?. >From a strict pov thats right But then from a strict pov linux is not an OS, its just one component of an OS https://www.howtogeek.com/177213/linux-isnt-just-linux-8-pieces-of-software-that-make-up-linux-systems/ The more pragmatic answer to this question is to run $ man xdg-mime $ man xdg-open etc (terrible documentation like everything else gnome? but thats another story) From ned at nedbatchelder.com Tue Dec 5 06:31:54 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 5 Dec 2017 06:31:54 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> Message-ID: <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> On 12/4/17 10:41 PM, Rick Johnson wrote: >> I think we've demonstrated the slicing semantics well. > Indeed. And i never questioned this aspect. I merely wanted > to inform the lurkers that the else-clause was handling a > non-action, and therefore, could be omitted. Your original statement sounded like, "The else clause can never be executed," which would have been in direct opposition to the point, that slicing outside the limits would produce an empty list, not an exception.? I'm not sure why you are certain that there's never a reason to execute code in that case. Perhaps I have a simulation on a conceptually infinite line, but only store the actual points needed.? The "non action" would be to extend the line. --Ned. From pjh at nanoworks.com Tue Dec 5 07:14:12 2017 From: pjh at nanoworks.com (Percival John Hackworth) Date: Wed, 06 Dec 2017 00:14:12 +1200 Subject: we want python software References: <976278232@f38.n261.z1.binkp.net> Message-ID: <698903100@f38.n261.z1.binkp.net> On 05-Dec-2017, km wrote (in article): > I dont know how these students are selected into b tech stream in India. > they are so dumb. All they know is a to open a program we need to double > click it and it runs.- windoze legacy. most of the time they pay huge > amount to a greedy college and get into tech stream. > Now that Java boom (jobs) is over in India and python is booming in AI and > machine learning these people want to learn python and get easy jobs > (software coolies). pls dont even entertain such posts. A friend who deals with outsource Indian developers told me something interesting. Apparently, the programmers are paid very poorly in India. Managers are paid much better. So the career path over there is to "pay your dues" writing code, then become a manager where you no longer have to write code. It means that all the product teams that are outsourced to India *always* get new, green people because as soon as they get any good, they become managers. That explains a lot, doesn't it. It also means when your company lays off a lot of technical staff and outsources tech pubs, 1st line support, and development to India, the people left in the US are the "Tiger Team" to fix screw ups or major issues in a product release. Then they sell the company. Another friend hired a programmer from India to develop a java-based web site to sell their product in the iOS App Store. He asked me to look at problems they were having with the site. I'm a sysadmin, not a java programmer, but I knew that you're not supposed to run a Tomcat web server as root. According to friends, you're not supposed to expose Tomcat to the internet at all. That's not what this developer did. It looked like it was a school project that he setup stuff but didn't know how it's done in production with security enabled. Nor could he deal with AWS. It's a nightmare out there for people looking to get development done "on the cheap". The good people (e.g. the friends I asked for advice) are to busy to do such little projects to bother. So the market is left with Junior people in India making crap. It's not a question of them taking jobs away from U.S. developers. It's a question of the good ones already have work. Can we train Joe to setup Wordpress and secure it or write a Java Web site when all he's done before is manufacturing or worked in a grocery store. Other groups aren't so nice to beginners - the perl group is brutal and tell a student to do their own homework. I'm just dipping my toe into python here and you guys more helpful. Mostly because there's so much possibility in python (compared to other scripting languages). From rantingrickjohnson at gmail.com Tue Dec 5 07:31:30 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 5 Dec 2017 04:31:30 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> Message-ID: <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> Ned Batchelder wrote: [...] > Your original statement sounded like, "The else clause can > never be executed," No. Of course not. Note that i mentioned _pragmatism_. My complaint about the else-clause was not that it could _never_ be executed, my complaint that was that the else- clause (in Terry's example) serves no useful purpose save to act as a semantical placeholder for a non-action. Heck, it doesn't even log anything! "Practicality beats purity". For instance: (1) Would it be practical to make a shopping list that includes only the products you _don't_ want to buy? no ham no eggs no spam no Limburger "Okay, but what do we _need_!!!" (2) How about a list of navigation directions that includes tangential info? "After you take the second left turn, you'll see a big windmill -- just ignore that" (3) How about a recipe that includes non-ingredients? 1 egg 2 pounds of ham 0 teaspoons coarse sea-salt 0 cups of finely shreded Limburger ... > which would have been in direct opposition to the point, > that slicing outside the limits would produce an empty > list, not an exception. And again, that is precisely why i raised an objection to this else-clause. Because the inclusion of this else-clause is a distraction from the point. > I'm not sure why you are certain that there's never a > reason to execute code in that case. Oh, there will be a _reason_ for else-clause to execute (when the slice overlaps the boundary), but i argue the code contained within is not a _good_ reason for it to execute. item = seq[n:n+1] if item: process(item) else: do_without_item() "do_without_item()" implies a non-action. However, that's not to say that under different circumstances, the else- clause might serve a practical purpose for a programmer. For instance, even a logging event serves a purpose. ss, se = n, n+1 item = seq[ss:se] if item: process(item) else: print('Slice ({0}, {1}) out of bounds!'.format(ss, se)) > Perhaps I have a simulation on a conceptually infinite > line, but only store the actual points needed. The "non > action" would be to extend the line. That logic does not follow! How do you _extend_ an infinite line? :-). Of course, in the realm of maths, a line is by definition infinite. But whether you're speaking in metaphor or not, there are literally infinite ways in which an else-clause can be justified. My argument was simply: "do_without_item()" is not a legitimate justification. From python at mrabarnett.plus.com Tue Dec 5 07:41:46 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Dec 2017 00:41:46 +1200 Subject: f-string Message-ID: <3436932175@f38.n261.z1.binkp.net> On 2017-12-06 00:16, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first. > > > Thanks in advance. > > Microsoft Windows [Version 10.0.15063] (c) 2017 Microsoft Corporation. All rights reserved. C:\Users\MRAB>py -3.6 Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> spam = 'SPAM' >>> eggs = 'EGGS' >>> c = compile('f"{spam} {eggs}"', '', 'single') >>> c at 0x00000269E2020C00, file "", line 1> >>> eval(c) 'SPAM EGGS' >>> From python at mrabarnett.plus.com Tue Dec 5 07:43:02 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Dec 2017 00:43:02 +1200 Subject: csv.DictReader line skipping should be considered a bug? Message-ID: <3728060086@f38.n261.z1.binkp.net> On 2017-12-06 00:06, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 04:20 am, Jason wrote: > >> I ran into this: >> > https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-emp ty-lines >> >> # unlike the basic reader, we prefer not to return blanks, >> # because we will typically wind up with a dict full of None >> # values >> >> while iterating over two files, which are line-by-line corresponding. The >> DictReader skipped ahead many lines breaking the line-by-line >> correspondence. > > Um... this doesn't follow. If they are line-by-line corresponding, then they > should skip the same number of blank lines and read the same number of > non-blank lines. > > Even if one file has blanks and the other does not, if you iterate the over > the records themselves, they should keep their correspondence. > > I'm afraid that if you want to convince me this is a buggy design, you need to > demonstrate a simple pair of CSV files where the non-blank lines are > corresponding (possibly with differing numbers of blanks in between) but the > CSV readers get out of alignment somehow. > > >> And I want to argue that the difference of behavior should be considered a >> bug. It should be considered as such because: 1. I need to know what's in >> the file to know what class to use. > > Sure. But blank lines don't tell you what class to use. > >> The file content should not break at-least-1-record-per-line. > > Blank lines DO break that requirement. A blank line is not a record. > > >> There may me multiple lines per record in the >> case of embedded new lines, but it should never no record per line. > > I disagree. A blank line is not a record. If I have (say) five fields, then: > > ,,,,\n > > is a blank record with five empty fields. \n alone is just a blank. The > DictReader correctly returns records with blank fields. > A blank line could be a record if there's only one field and it's empty. [snip] From johnpote at jptechnical.co.uk Tue Dec 5 07:54:02 2017 From: johnpote at jptechnical.co.uk (John Pote) Date: Wed, 06 Dec 2017 00:54:02 +1200 Subject: f-string Message-ID: <3251756805@f38.n261.z1.binkp.net> On 06/12/2017 00:16, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first. > > > Thanks in advance. > > rslt = compile('f"{spam} {eggs}"', '', 'single') print( rslt ) print( "\n" ) spam = "SPAM" eggs = "scrambled" eRslt = eval( 'f"{spam} {eggs}"' ) print( eRslt ) Ran above test file and got, >>python36 compiletest.py at 0x0000000002120E40, file "", line 1> SPAM scrambled >> Py version on Win 7 box Python 3.6.3 (v3.6.3:2c5fed8, Oct? 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32 Any help? John From python at mrabarnett.plus.com Tue Dec 5 08:56:54 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Dec 2017 01:56:54 +1200 Subject: Python homework Message-ID: <1346855208@f38.n261.z1.binkp.net> On 2017-12-06 01:33, nick.martinez2--- via Python-list wrote: > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value of all rolls. > I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. > This is what I have so far: > import random > > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls > > if __name__ == "__main__": > result = rollDie(50) > print (result) > print(max(result)) > What is "rolls"? It's the number of times each side came up. In the last line you asked it for the maximum number of times a side came up, and that's what you got. You now just have to figure out _which_ side of the die that count corresponds to. From jyothiswaroopreddy9121 at gmail.com Tue Dec 5 10:10:42 2017 From: jyothiswaroopreddy9121 at gmail.com (Jyothiswaroop Reddy) Date: Tue, 5 Dec 2017 20:40:42 +0530 Subject: we want python software Message-ID: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Sir, I am b.tech student I would like to learn python. So please send the python software. Thanking you sir. Sent from Mail for Windows 10 From steve+python at pearwood.info Tue Dec 5 11:06:13 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 03:06:13 +1100 Subject: why won't slicing lists raise IndexError? References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> Message-ID: <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> On Tue, 5 Dec 2017 11:31 pm, Rick Johnson wrote: > Ned Batchelder wrote: > [...] >> Your original statement sounded like, "The else clause can >> never be executed," > > No. Of course not. Note that i mentioned _pragmatism_. My > complaint about the else-clause was not that it could > _never_ be executed, my complaint that was that the else- > clause (in Terry's example) serves no useful purpose save to > act as a semantical placeholder for a non-action. When you find yourself in a hole, stop digging. You've already been told that there's no indication or reason to believe that it is a non-action. You've already been given at least one possible action. It isn't a non-action, it is two distinct actions: - the action you take when the slice is non-empty; - the action you take when the slice is empty. > Heck, it > doesn't even log anything! "Practicality beats purity". For > instance: > > (1) Would it be practical to make a shopping list that > includes only the products you _don't_ want to buy? Obviously not *only* the products you don't want, but it is very common to specify constraints, e.g. what you don't want. New car. Must not have an internet connected engine. Gluten-free bread. Unscented toilet paper. Ingredients to make fruit salad. No bananas. Or alternatives: Get a slice of pizza for lunch. If they're out of pizza (i.e. the slice is empty) get Chinese food instead. > (2) How about a list of navigation directions that includes > tangential info? > > "After you take the second left turn, you'll see a big > windmill -- just ignore that" Be careful about rhetorical questions. The answer is not always what you think it must be. Giving directions that include landmarks is *very* useful. If you don't see the windmill, you know you've taken the wrong turn. When you do see it, you know you're on the right track. > (3) How about a recipe that includes non-ingredients? My wife is an expert at making bread-and-no-butter pudding. This should be obvious, but in case it isn't, the reason it has that name is because it is a modified recipe based on (can you guess what?) bread-and-butter pudding, a British staple. Also: Flourless orange cake. Taken from a recipe for cooking lentils: "Don't add vinegar, as it makes the lentils tough." (Apparently some people add vinegar when cooking pulses. Curious.) And for those who are well-educated but not wise: "The difference between being educated and being smart is, the educated person knows that tomato is a fruit, while the wise person knows not to put tomato in fruit salad." I can think of a couple of people I would need to write "No tomatoes" on any fruit salad recipe I gave them. >> which would have been in direct opposition to the point, >> that slicing outside the limits would produce an empty >> list, not an exception. > > And again, that is precisely why i raised an objection to > this else-clause. Because the inclusion of this else-clause > is a distraction from the point. Ah, we've entered Ricksville, where demonstrating that slicing can return an empty list is taken as distraction from the point that slicing can return an empty list. No, wait, you've convinced me Rick! Your logic is impeccable! Except for one teeny tiny flaw in your reasoning -- you have the conclusion backwards. Its not the *empty* slice (the else clause) that is the distraction. Its the *non* empty clause. We already know that slicing returns a list of items. The part we're discussing is what happens when the slice is out of bounds? Does it return an empty list, or raise an exception? alist = bigger_list[start:finish] if not alist: print("Look Ma, no exception was raised!!!") /only half serious [...] > item = seq[n:n+1] > if item: > process(item) > else: > do_without_item() > > "do_without_item()" implies a non-action. The mind boggles how you get by in real life, when you're so busy digging yourself into deeper and deeper holes. Do you think about things before you write them? "I was going to make spaghetti and meat balls for tea tonight, but the store was out of mince, so I'll have to do without meat balls." Does that mean I go hungry and don't eat? >> Perhaps I have a simulation on a conceptually infinite >> line, but only store the actual points needed. The "non >> action" would be to extend the line. > > That logic does not follow! How do you _extend_ an infinite > line? :-). Ned said that the line stores only the points needed. If you've only used positions between 1 and 10, only values 1 through 10 have been stored. If you then try to access position 20, the line is extended to position 20. > Of course, in the realm of maths, a line is by > definition infinite. Not necessarily. Lines can be finite (e.g. a chord) or infinite, and if infinite, they can be defined as extending towards infinity in both directions, or in only one (a ray). > But whether you're speaking in metaphor or not, there are > literally infinite ways in which an else-clause can be > justified. My argument was simply: "do_without_item()" is > not a legitimate justification. Simple and wrong. Do yourself a favour Rick. Stop digging. If you go much deeper, you'll hit magma. -- Steve From skip.montanaro at gmail.com Tue Dec 5 11:11:04 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 5 Dec 2017 10:11:04 -0600 Subject: Profiler which takes I/O into account? Message-ID: Is there a profiler for Python (2.7 in my case) which recognizes when a process (or all threads but the profiler's) is blocked on I/O? I'm using cProfile at the moment, which is fine as far as it goes, but the program I'm profiling does a fair amount of I/O, so that dominates the actual time the program spends calculating. My goal in this case is minimizing latency of request handling, so while it's not CPU-bound, it's still important to minimize the relevant code paths. Thx, Skip From ikorot01 at gmail.com Tue Dec 5 11:55:09 2017 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 5 Dec 2017 10:55:09 -0600 Subject: we want python software In-Reply-To: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: Hi, On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote: > Sir, > I am b.tech student I would like to learn python. So please send the python software. Sorry, we don't send anything. You will have to go get it yourself. -) Thanking you back. > Thanking you sir. > > Sent from Mail for Windows 10 > > -- > https://mail.python.org/mailman/listinfo/python-list From rantingrickjohnson at gmail.com Tue Dec 5 12:02:03 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 5 Dec 2017 09:02:03 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> Message-ID: On Tuesday, December 5, 2017 at 2:58:44 AM UTC-6, Lawrence D'Oliveiro wrote: > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: > > > > Sounds like your OS file associations are all botched-up ... > > Linux doesn't do "OS file associations". True. But i'm not convinced that file associations are really all that terrible of a thing. What do you think? Though, Micheal Torrie did raise a valid point regarding the pitfalls of those who rely too heavily on the X-Windows mouse event, warning that -- paraphrasing here -- "You don't want to invoke a python script with a double-click as you will not maintain control of the output stream when the program fails or quietly exits" Fair point. Although, on windows, at least, there is an option of using either a ".py" file extension or a ".pyw" file extension for your scripts, such that, when invoking the script from the desktop enviroment (via double-click), the former will ensure a terminal window is displayed while the latter will suppress a terminal entirely. However, i find this design to be woefully inadequate as a "feature". Hmm, it seems this design is best described as: "a feature that wanted to be great, allbeit, one that failed _miserably_". With that in mind, a more practical implementation of "forcing" or "suppressing" terminals via file extensions would take the form of the following three alternatives: (OPTION_1): Run the script with a terminal, and autoclose upon fatal error or EOP. (".py") (OPTION_2): Run script with a terminal, but do not auto-close the terminal when Python chokes or the program exits, instead, allow the human to decide. (this will be best for debugging purposes) (".pydb" or ".pyt" or "pyl") (OPTION_3): Run the script, but suppress the terminal entirely. (".pyw") From jasonhihn at gmail.com Tue Dec 5 12:09:24 2017 From: jasonhihn at gmail.com (Jason) Date: Tue, 5 Dec 2017 09:09:24 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. In-Reply-To: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> Message-ID: <09c38b05-87fd-4455-befb-8a6ebee45bff@googlegroups.com> On Monday, December 4, 2017 at 4:49:11 AM UTC-5, dhananjays... at gmail.com wrote: > Respected Sir/Mam, > I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window. > Sir please help me. Make the first line oh the file: #!/usr/bin/env python Then chmod it with executable permissions: chmod +x Dhananjay.py Then you can double-click to run it. From lists at vanderhoff.org Tue Dec 5 12:10:32 2017 From: lists at vanderhoff.org (Tony van der Hoff) Date: Tue, 5 Dec 2017 17:10:32 +0000 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On 05/12/17 16:55, Igor Korot wrote: > Hi, > > On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy > wrote: >> Sir, >> I am b.tech student I would like to learn python. So please send the python software. > Sorry, we don't send anything. You will have to go get it yourself. -) > Well, at least try to be helpful: https://www.python.org/downloads/ From jasonhihn at gmail.com Tue Dec 5 12:20:26 2017 From: jasonhihn at gmail.com (Jason) Date: Tue, 5 Dec 2017 09:20:26 -0800 (PST) Subject: csv.DictReader line skipping should be considered a bug? Message-ID: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> I ran into this: https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty-lines # unlike the basic reader, we prefer not to return blanks, # because we will typically wind up with a dict full of None # values while iterating over two files, which are line-by-line corresponding. The DictReader skipped ahead many lines breaking the line-by-line correspondence. And I want to argue that the difference of behavior should be considered a bug. It should be considered as such because: 1. I need to know what's in the file to know what class to use. The file content should not break at-least-1-record-per-line. There may me multiple lines per record in the case of embedded new lines, but it should never no record per line. 2. It's a premature optimization. If skipping blank lines is desirable, then have another class on top of DictReader, maybe call it EmptyLineSkippingDictReader. 3. The intent of DictReader is to return a dict, nothing more, therefore the change of behavior isn inappropriate. Does anyone agree, or am I crazy? From joel.goldstick at gmail.com Tue Dec 5 12:30:45 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Dec 2017 12:30:45 -0500 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: Go visit python.org to see how to download python for the operating system you are using. Its free of course On Tue, Dec 5, 2017 at 11:55 AM, Igor Korot wrote: > Hi, > > On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy > wrote: > > Sir, > > I am b.tech student I would like to learn python. So please send > the python software. > > Sorry, we don't send anything. You will have to go get it yourself. -) > > Thanking you back. > > > Thanking you sir. > > > > Sent from Mail for Windows 10 > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From neilc at norwich.edu Tue Dec 5 13:39:51 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 5 Dec 2017 18:39:51 +0000 (UTC) Subject: csv.DictReader line skipping should be considered a bug? References: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> Message-ID: On 2017-12-05, Jason wrote: > I ran into this: > https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty-lines > > # unlike the basic reader, we prefer not to return blanks, > # because we will typically wind up with a dict full of None > # values > > while iterating over two files, which are line-by-line corresponding. The DictReader skipped ahead many lines breaking the line-by-line correspondence. > > And I want to argue that the difference of behavior should be considered a bug. It should be considered as such because: > 1. I need to know what's in the file to know what class to use. The file content should not break at-least-1-record-per-line. There may me multiple lines per record in the case of embedded new lines, but it should never no record per line. > 2. It's a premature optimization. If skipping blank lines is desirable, then have another class on top of DictReader, maybe call it EmptyLineSkippingDictReader. > 3. The intent of DictReader is to return a dict, nothing more, therefore the change of behavior isn inappropriate. > > Does anyone agree, or am I crazy? I've used csv.DictReader for years and never come across this oddity. Very interesting! I am with you. Silently discarding blank records hides information--the current design is unusable if blank records are of interest. Moreover, what's wrong with a dict full of None, if that's what's in the record? Haw many Nones are too many? -- Neil Cerutti From skip.montanaro at gmail.com Tue Dec 5 14:03:37 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 5 Dec 2017 13:03:37 -0600 Subject: csv.DictReader line skipping should be considered a bug? In-Reply-To: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> References: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> Message-ID: > And I want to argue that the difference of behavior should be considered a bug. Sorry, that ship has sailed. If you want different behavior, subclassing DictReader and providing your own next() implementation should be straightforward. All you need to do is copy the existing implementation of next() and strip out the comment and the while loop which follows it. Skip From waylan.limberg at icloud.com Tue Dec 5 15:55:16 2017 From: waylan.limberg at icloud.com (waylan) Date: Tue, 5 Dec 2017 12:55:16 -0800 (PST) Subject: How to upload to Pythonhosted.org In-Reply-To: <5a205228$0$10072$e4fe514c@news.xs4all.nl> References: <5a949de0-9fdd-4637-adf4-22c3535d4c54@googlegroups.com> <5a1f61b9$0$10045$e4fe514c@news.xs4all.nl> <851skgv6ol.fsf@benfinney.id.au> <5a205228$0$10072$e4fe514c@news.xs4all.nl> Message-ID: <8ae4a5dd-026d-4843-8003-22808a7a977b@googlegroups.com> After asking here, I found a mailing list post here: https://mail.python.org/pipermail/distutils-sig/2015-May/026381.html That post outlines a roadmap for shutting down pythonhosted. Unfortunately, it seems that they skipped from step 1 to step 5 without bothering with steps 2, 3, & 4. In any event, that list discussion seems to be the official word that things are being shut down, which was what I was looking for. It's unfortunate that things weren't done more smoothly. Also it seems that if you want to avoid search results showing up for the pythonhosted content after you find a new host, they at least provide a way to "delete" the content from pyhtonhosted. That way, Google will stop indexing it and stop including it in search results. Unfortunately, all the existing links across the internet are now dead with no way to redirect people. Waylan On Thursday, November 30, 2017 at 1:47:32 PM UTC-5, Irmen de Jong wrote: > On 11/30/2017 03:31 AM, Ben Finney wrote: > > Irmen de Jong writes: > > > >> On 11/30/2017 02:06 AM, waylan wrote: > >>> So, how do I upload an update to my documentation? > >> > >> I ran into the same issue. From what I gathered, Pythonhosted.org is > >> in the process of being dismantled and it hasn't allowed new doc > >> uploads for quite some time now. I switched to using readthedocs.io > >> instead. > > > > The issue that many are facing is how to update the pages *at the > > existing URL* to tell visitors where to go next. Cool URIs don't change > > but, when they do, we > > are obliged to update the existing pages to point to the new ones. > > Sorry, yes, that is the problem I experience as well. My library's old version > documentation is somehow frozen on Pythonhosted.org (and obviously still pops up as the > first few google hits). > > > > So, if pythonhosted.org is indeed being dismantled, there should be a > > way to update the pages there for informing visitor where they should go > > next. > > > > If that's not possible and instead the service is just locked down, > > that's IMO a mistake. > > I agree with that. I think it's an unsolved issue until now, that gets some discussion > in this github issue https://github.com/pypa/warehouse/issues/582 > > > Irmen From ikorot01 at gmail.com Tue Dec 5 16:39:47 2017 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 5 Dec 2017 15:39:47 -0600 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: Hi, Tony, On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: > On 05/12/17 16:55, Igor Korot wrote: >> Hi, >> >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy >> wrote: >>> Sir, >>> I am b.tech student I would like to learn python. So please send the python software. >> Sorry, we don't send anything. You will have to go get it yourself. -) >> > Well, at least try to be helpful: > https://www.python.org/downloads/ This is LMGIFY. If they say they are tech students - they should know how to work with Google. And I even tried to be polite. I should have probably write something like: 1. Open the Web browser. 2. In the "Address Bar" type "www.pyton.org". 3. Find the link which reads "Downloads". Click on it. 4. Carefully read what version you need to install for your OS. 5. Apply the acquired knowledge and download the appropriate version. 6. Click on the installer (if on Windows). 7. Follow all the prompts. 8. Enjoy. but this is too much for the tech student. Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From abhi.darkness at gmail.com Tue Dec 5 17:15:14 2017 From: abhi.darkness at gmail.com (Abhiram R) Date: Wed, 06 Dec 2017 10:15:14 +1200 Subject: we want python software Message-ID: <441615813@f38.n261.z1.binkp.net> On Wed, Dec 6, 2017 at 10:08 AM, km wrote: > I dont know how these students are selected into b tech stream in India. > they are so dumb. All they know is a to open a program we need to double > click it and it runs. > > ? ?We were all once "dumb". We learnt it because someone Taught us. I'd rather not entertain such or refrain from condescending replies that would further discourage people from trying to get into the field. With all the emphasis on the Python "community", it's important not to be so dismissive. Thanks Abhiram ? ? > > > On Wed, Dec 6, 2017 at 9:19 AM, Rustom Mody wrote: > > > On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote: > > > Hi, Tony, > > > > > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: > > > > On 05/12/17 16:55, Igor Korot wrote: > > > >> Hi, > > > >> > > > >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote: > > > >>> Sir, > > > >>> I am b.tech student I would like to learn python. So please > > send the python software. > > > >> Sorry, we don't send anything. You will have to go get it yourself. > -) > > > >> > > > > Well, at least try to be helpful: > > > > https://www.python.org/downloads/ > > > > > > This is LMGIFY. > > > If they say they are tech students - they should know how to work with > > Google. > > > > > > And I even tried to be polite. I should have probably write something > > like: > > > > > > 1. Open the Web browser. > > > 2. In the "Address Bar" type "www.pyton.org". > > > 3. Find the link which reads "Downloads". Click on it. > > > 4. Carefully read what version you need to install for your OS. > > > 5. Apply the acquired knowledge and download the appropriate version. > > > 6. Click on the installer (if on Windows). > > > 7. Follow all the prompts. > > > 8. Enjoy. > > > > > > but this is too much for the tech student. > > > > You are assuming that the strangeness of the request is about 'tech' > > [engineering/tech existed centuries before computers] > > > > Do remember one can be a tech-{student,professional} without > > - ever having encountered free-software > > - internet/USENET culture > > > > ? | from which pov the request would not look so odd > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- -Abhiram R ??$ From steve+python at pearwood.info Tue Dec 5 17:35:58 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 10:35:58 +1200 Subject: Please tell me how to execute python file in Ubuntu by double click References: <2555707956@f38.n261.z1.binkp.net> Message-ID: <2217129085@f38.n261.z1.binkp.net> On Tue, 5 Dec 2017 07:58 pm, Lawrence D? ?Oliveiro wrote: > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: >> >> Sounds like your OS file associations are all botched-up ... > > Linux doesn? ?t do ? ?OS file associations? ?. Then how does my Linux box know that when I double-click on a text file, it launches kwrite rather than (say) the Gimp or LibreOffice? When I right-click on a mp4 video, I get a menu that includes a Open With command that shows (amount others) Kaffeine, mplayer and VLC. If you mean the Linux *kernel* doesn't do file associations, then you should have said so. But why do you care about the kernel? Would you think it even the *tiniest* useful to claim that "Linux doesn't do email" because it is sendmail or postfix (or similar) that sends email rather than the Linux kernel itself? -- Steve From steve+python at pearwood.info Tue Dec 5 18:06:38 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 11:06:38 +1200 Subject: csv.DictReader line skipping should be considered a bug? References: <2574297724@f38.n261.z1.binkp.net> Message-ID: <2891836479@f38.n261.z1.binkp.net> On Wed, 6 Dec 2017 04:20 am, Jason wrote: > I ran into this: > https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty -lines > > # unlike the basic reader, we prefer not to return blanks, > # because we will typically wind up with a dict full of None > # values > > while iterating over two files, which are line-by-line corresponding. The > DictReader skipped ahead many lines breaking the line-by-line > correspondence. Um... this doesn't follow. If they are line-by-line corresponding, then they should skip the same number of blank lines and read the same number of non-blank lines. Even if one file has blanks and the other does not, if you iterate the over the records themselves, they should keep their correspondence. I'm afraid that if you want to convince me this is a buggy design, you need to demonstrate a simple pair of CSV files where the non-blank lines are corresponding (possibly with differing numbers of blanks in between) but the CSV readers get out of alignment somehow. > And I want to argue that the difference of behavior should be considered a > bug. It should be considered as such because: 1. I need to know what's in > the file to know what class to use. Sure. But blank lines don't tell you what class to use. > The file content should not break at-least-1-record-per-line. Blank lines DO break that requirement. A blank line is not a record. > There may me multiple lines per record in the > case of embedded new lines, but it should never no record per line. I disagree. A blank line is not a record. If I have (say) five fields, then: ,,,,\n is a blank record with five empty fields. \n alone is just a blank. The DictReader correctly returns records with blank fields. > 2. It's a premature optimization. If skipping blank lines is desirable, > then have another class on top of DictReader, maybe call it > EmptyLineSkippingDictReader. No, that's needless ravioli code. The csv module already defines a basic reader that doesn't skip blank lines. Having two different DictReaders, one which doesn't work correctly because it wrongly expands blank lines to collections of blank fields, is not helpful. Perhaps if they were called BrokenDictReader for the one which expands blank lines to empty records, and DictReader for the one which correctly skips blank lines. > 3. The intent of DictReader is to return a > dict, nothing more, therefore the change of behavior isn inappropriate. No, if all you want is a dict, call dict() or use the dict display {}. The intent of DictReader is to *read a CSV file and extract the records* as a dict. Since blank lines aren't records, they should be skipped. > Does anyone agree, or am I crazy? I wouldn't want to guess your mental health based just on this isolated incident, but if I had to make a diagnosis, I'd say, yes, crazy as a loon. *wink* -- Steve From steve+python at pearwood.info Tue Dec 5 18:16:26 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 11:16:26 +1200 Subject: f-string Message-ID: <2511121346@f38.n261.z1.binkp.net> Anyone got a handy copy of Python 3.6 available to test something for me? What does compile('f"{spam} {eggs}"', '', 'single') return? What does eval()'ing the above compiled object do? If necessary, you may have to define spam and eggs first. Thanks in advance. -- Steve ? ?Cheer up,? ? they said, ? ?things could be worse.? ? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Tue Dec 5 18:33:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 06 Dec 2017 11:33:40 +1200 Subject: f-string Message-ID: <2622488452@f38.n261.z1.binkp.net> On Wed, Dec 6, 2017 at 11:16 AM, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first. > > In 3.6a4+, which is the only 3.6 I have handy, it returns a code object. >>> spam = "((spam))" >>> eggs = "!!eggs!!" >>> compile('f"{spam} {eggs}"', '', 'single') at 0x7f0f82bf7db0, file "", line 1> >>> eval(_) '((spam)) !!eggs!!' >>> dis.dis(compile('f"{spam} {eggs}"', '', 'single')) 1 0 LOAD_NAME 0 (spam) 2 FORMAT_VALUE 0 4 LOAD_CONST 0 (' ') 6 LOAD_NAME 1 (eggs) 8 FORMAT_VALUE 0 10 BUILD_STRING 3 12 PRINT_EXPR 14 LOAD_CONST 1 (None) 16 RETURN_VALUE Same is true in 3.7 alphas. ChrisA From steve+python at pearwood.info Tue Dec 5 18:35:58 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 10:35:58 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> Message-ID: <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> On Tue, 5 Dec 2017 07:58 pm, Lawrence D?Oliveiro wrote: > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: >> >> Sounds like your OS file associations are all botched-up ... > > Linux doesn?t do ?OS file associations?. Then how does my Linux box know that when I double-click on a text file, it launches kwrite rather than (say) the Gimp or LibreOffice? When I right-click on a mp4 video, I get a menu that includes a Open With command that shows (amount others) Kaffeine, mplayer and VLC. If you mean the Linux *kernel* doesn't do file associations, then you should have said so. But why do you care about the kernel? Would you think it even the *tiniest* useful to claim that "Linux doesn't do email" because it is sendmail or postfix (or similar) that sends email rather than the Linux kernel itself? -- Steve From steve+python at pearwood.info Tue Dec 5 19:06:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 11:06:39 +1100 Subject: csv.DictReader line skipping should be considered a bug? References: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> Message-ID: <5a27348f$0$2075$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 04:20 am, Jason wrote: > I ran into this: > https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty-lines > > # unlike the basic reader, we prefer not to return blanks, > # because we will typically wind up with a dict full of None > # values > > while iterating over two files, which are line-by-line corresponding. The > DictReader skipped ahead many lines breaking the line-by-line > correspondence. Um... this doesn't follow. If they are line-by-line corresponding, then they should skip the same number of blank lines and read the same number of non-blank lines. Even if one file has blanks and the other does not, if you iterate the over the records themselves, they should keep their correspondence. I'm afraid that if you want to convince me this is a buggy design, you need to demonstrate a simple pair of CSV files where the non-blank lines are corresponding (possibly with differing numbers of blanks in between) but the CSV readers get out of alignment somehow. > And I want to argue that the difference of behavior should be considered a > bug. It should be considered as such because: 1. I need to know what's in > the file to know what class to use. Sure. But blank lines don't tell you what class to use. > The file content should not break at-least-1-record-per-line. Blank lines DO break that requirement. A blank line is not a record. > There may me multiple lines per record in the > case of embedded new lines, but it should never no record per line. I disagree. A blank line is not a record. If I have (say) five fields, then: ,,,,\n is a blank record with five empty fields. \n alone is just a blank. The DictReader correctly returns records with blank fields. > 2. It's a premature optimization. If skipping blank lines is desirable, > then have another class on top of DictReader, maybe call it > EmptyLineSkippingDictReader. No, that's needless ravioli code. The csv module already defines a basic reader that doesn't skip blank lines. Having two different DictReaders, one which doesn't work correctly because it wrongly expands blank lines to collections of blank fields, is not helpful. Perhaps if they were called BrokenDictReader for the one which expands blank lines to empty records, and DictReader for the one which correctly skips blank lines. > 3. The intent of DictReader is to return a > dict, nothing more, therefore the change of behavior isn inappropriate. No, if all you want is a dict, call dict() or use the dict display {}. The intent of DictReader is to *read a CSV file and extract the records* as a dict. Since blank lines aren't records, they should be skipped. > Does anyone agree, or am I crazy? I wouldn't want to guess your mental health based just on this isolated incident, but if I had to make a diagnosis, I'd say, yes, crazy as a loon. *wink* -- Steve From steve+python at pearwood.info Tue Dec 5 19:16:27 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 11:16:27 +1100 Subject: f-string Message-ID: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> Anyone got a handy copy of Python 3.6 available to test something for me? What does compile('f"{spam} {eggs}"', '', 'single') return? What does eval()'ing the above compiled object do? If necessary, you may have to define spam and eggs first. Thanks in advance. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Tue Dec 5 19:21:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 06 Dec 2017 12:21:50 +1200 Subject: f-string Message-ID: <1171780012@f38.n261.z1.binkp.net> On Wed, Dec 6, 2017 at 11:54 AM, John Pote wrote: > > On 06/12/2017 00:16, Steve D'Aprano wrote: >> >> Anyone got a handy copy of Python 3.6 available to test something for me? >> >> What does compile('f"{spam} {eggs}"', '', 'single') return? >> >> What does eval()'ing the above compiled object do? If necessary, you may >> have >> to define spam and eggs first. > > SPAM scrambled > > Py version on Win 7 box > Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit > (AMD64)] on win32 > > Any help? I think Steve just wanted to see what we'd all define spam and eggs as. ChrisA *ducking for cover* From rosuav at gmail.com Tue Dec 5 19:33:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Dec 2017 11:33:40 +1100 Subject: f-string In-Reply-To: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> Message-ID: On Wed, Dec 6, 2017 at 11:16 AM, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first. > > In 3.6a4+, which is the only 3.6 I have handy, it returns a code object. >>> spam = "((spam))" >>> eggs = "!!eggs!!" >>> compile('f"{spam} {eggs}"', '', 'single') at 0x7f0f82bf7db0, file "", line 1> >>> eval(_) '((spam)) !!eggs!!' >>> dis.dis(compile('f"{spam} {eggs}"', '', 'single')) 1 0 LOAD_NAME 0 (spam) 2 FORMAT_VALUE 0 4 LOAD_CONST 0 (' ') 6 LOAD_NAME 1 (eggs) 8 FORMAT_VALUE 0 10 BUILD_STRING 3 12 PRINT_EXPR 14 LOAD_CONST 1 (None) 16 RETURN_VALUE Same is true in 3.7 alphas. ChrisA From ned at nedbatchelder.com Tue Dec 5 19:37:32 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 5 Dec 2017 19:37:32 -0500 Subject: f-string In-Reply-To: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> Message-ID: <81a7feac-6f78-8b06-8c7b-8ea0e426116e@nedbatchelder.com> On 12/5/17 7:16 PM, Steve D'Aprano wrote: > compile('f"{spam} {eggs}"', '', 'single') $ python3.6 Python 3.6.3 (default, Oct? 4 2017, 06:03:25) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> compile('f"{spam} {eggs}"', '', 'single') at 0x105e79660, file "", line 1> >>> co = _ >>> spam = 17 >>> eggs = 34 >>> eval(co) '17 34' >>> dis.dis(co) ? 1?????????? 0 LOAD_NAME??????????????? 0 (spam) ????????????? 2 FORMAT_VALUE???????????? 0 ????????????? 4 LOAD_CONST?????????????? 0 (' ') ????????????? 6 LOAD_NAME??????????????? 1 (eggs) ????????????? 8 FORMAT_VALUE???????????? 0 ???????????? 10 BUILD_STRING???????????? 3 ???????????? 12 PRINT_EXPR ???????????? 14 LOAD_CONST?????????????? 1 (None) ???????????? 16 RETURN_VALUE --Ned. From python at mrabarnett.plus.com Tue Dec 5 19:41:46 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Dec 2017 00:41:46 +0000 Subject: f-string In-Reply-To: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> Message-ID: On 2017-12-06 00:16, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first. > > > Thanks in advance. > > Microsoft Windows [Version 10.0.15063] (c) 2017 Microsoft Corporation. All rights reserved. C:\Users\MRAB>py -3.6 Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> spam = 'SPAM' >>> eggs = 'EGGS' >>> c = compile('f"{spam} {eggs}"', '', 'single') >>> c at 0x00000269E2020C00, file "", line 1> >>> eval(c) 'SPAM EGGS' >>> From python at mrabarnett.plus.com Tue Dec 5 19:43:02 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Dec 2017 00:43:02 +0000 Subject: csv.DictReader line skipping should be considered a bug? In-Reply-To: <5a27348f$0$2075$b1db1813$d948b532@news.astraweb.com> References: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> <5a27348f$0$2075$b1db1813$d948b532@news.astraweb.com> Message-ID: <615b60a8-4cad-52fd-2462-36efe5567343@mrabarnett.plus.com> On 2017-12-06 00:06, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 04:20 am, Jason wrote: > >> I ran into this: >> > https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty-lines >> >> # unlike the basic reader, we prefer not to return blanks, >> # because we will typically wind up with a dict full of None >> # values >> >> while iterating over two files, which are line-by-line corresponding. The >> DictReader skipped ahead many lines breaking the line-by-line >> correspondence. > > Um... this doesn't follow. If they are line-by-line corresponding, then they > should skip the same number of blank lines and read the same number of > non-blank lines. > > Even if one file has blanks and the other does not, if you iterate the over > the records themselves, they should keep their correspondence. > > I'm afraid that if you want to convince me this is a buggy design, you need to > demonstrate a simple pair of CSV files where the non-blank lines are > corresponding (possibly with differing numbers of blanks in between) but the > CSV readers get out of alignment somehow. > > >> And I want to argue that the difference of behavior should be considered a >> bug. It should be considered as such because: 1. I need to know what's in >> the file to know what class to use. > > Sure. But blank lines don't tell you what class to use. > >> The file content should not break at-least-1-record-per-line. > > Blank lines DO break that requirement. A blank line is not a record. > > >> There may me multiple lines per record in the >> case of embedded new lines, but it should never no record per line. > > I disagree. A blank line is not a record. If I have (say) five fields, then: > > ,,,,\n > > is a blank record with five empty fields. \n alone is just a blank. The > DictReader correctly returns records with blank fields. > A blank line could be a record if there's only one field and it's empty. [snip] From johnpote at jptechnical.co.uk Tue Dec 5 19:54:03 2017 From: johnpote at jptechnical.co.uk (John Pote) Date: Wed, 6 Dec 2017 00:54:03 +0000 Subject: f-string In-Reply-To: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> Message-ID: <1386adbe-024e-b83f-b71b-9d3d36d4372b@jptechnical.co.uk> On 06/12/2017 00:16, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first. > > > Thanks in advance. > > rslt = compile('f"{spam} {eggs}"', '', 'single') print( rslt ) print( "\n" ) spam = "SPAM" eggs = "scrambled" eRslt = eval( 'f"{spam} {eggs}"' ) print( eRslt ) Ran above test file and got, >>python36 compiletest.py at 0x0000000002120E40, file "", line 1> SPAM scrambled >> Py version on Win 7 box Python 3.6.3 (v3.6.3:2c5fed8, Oct? 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32 Any help? John From rosuav at gmail.com Tue Dec 5 20:21:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Dec 2017 12:21:50 +1100 Subject: f-string In-Reply-To: <1386adbe-024e-b83f-b71b-9d3d36d4372b@jptechnical.co.uk> References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> <1386adbe-024e-b83f-b71b-9d3d36d4372b@jptechnical.co.uk> Message-ID: On Wed, Dec 6, 2017 at 11:54 AM, John Pote wrote: > > On 06/12/2017 00:16, Steve D'Aprano wrote: >> >> Anyone got a handy copy of Python 3.6 available to test something for me? >> >> What does compile('f"{spam} {eggs}"', '', 'single') return? >> >> What does eval()'ing the above compiled object do? If necessary, you may >> have >> to define spam and eggs first. > > SPAM scrambled > > Py version on Win 7 box > Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit > (AMD64)] on win32 > > Any help? I think Steve just wanted to see what we'd all define spam and eggs as. ChrisA *ducking for cover* From nick.martinez2 at aol.com Tue Dec 5 20:33:18 2017 From: nick.martinez2 at aol.com (nick.martinez2 at aol.com) Date: Tue, 5 Dec 2017 17:33:18 -0800 (PST) Subject: Python homework Message-ID: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 times and then prints (i). the most frequent side of the die (ii). the average die value of all rolls. I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. This is what I have so far: import random def rollDie(number): rolls = [0] * 6 for i in range(0, number): roll=int(random.randint(1,6)) rolls[roll - 1] += 1 return rolls if __name__ == "__main__": result = rollDie(50) print (result) print(max(result)) From python at mrabarnett.plus.com Tue Dec 5 20:56:54 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Dec 2017 01:56:54 +0000 Subject: Python homework In-Reply-To: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: <98a70a3f-2547-9bfd-2a4c-846d7cb7c81a@mrabarnett.plus.com> On 2017-12-06 01:33, nick.martinez2--- via Python-list wrote: > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value of all rolls. > I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. > This is what I have so far: > import random > > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls > > if __name__ == "__main__": > result = rollDie(50) > print (result) > print(max(result)) > What is "rolls"? It's the number of times each side came up. In the last line you asked it for the maximum number of times a side came up, and that's what you got. You now just have to figure out _which_ side of the die that count corresponds to. From rantingrickjohnson at gmail.com Tue Dec 5 21:23:04 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 5 Dec 2017 18:23:04 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> References: <5a236b0e-6559-42c8-8a51-dddb4141e4bc@googlegroups.com> <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> Message-ID: <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> Steve D'Aprano wrote: [...] > You've already been told that there's no indication or > reason to believe that it is a non-action. You've already > been given at least one possible action. It isn't a non- > action, it is two distinct actions: > > - the action you take when the slice is non-empty; > > - the action you take when the slice is empty. When Python follows a logic clause like a train skating along a set of railroad tracks, and finds itself in a *GHOST TOWN*, that's not an action -- "Steve-o" -- it's a non- action. Listen, I think it might help you to understand the absurdity of this else-clause if you ruminate about this code using a metaphor. Below, i've defined some fictional characters and objects that will live in a little metaphorical world, and futhermore, explained how these characters and objects relate to our real-life code example. TERRY("THE BUILDER"): Terry is a personable fella who builds little shanty towns for a living. IF_VILLE: This is the first of two towns that Terry establish in our little metaphorical world. And although it's not quite the shining-city-on-a-hill that he, or the inhabitants, had envisioned, he did manage to build a proper train platform and a small warehouse for strong deliverables, so we shouldn't be too critical of his work here. ELSE_VILLE: This is the "other" town that Terry establish. However, after slaving away in the hot desert sun building IF_VILLE all day, Terry decided to go home and drink a case of beer, became drunk, and then forgot all about his responsibilities to develope ELSE_VILLE. This has happened before. But we typically forgive Terry for his irresponsible nature simple because he's such a personable fella. However, if this gets any worse, we may have to give him an intervention. KENNY_LINTER: Kenny Linter is a faithful civil servant who's sole job is to inspect little shanty towns. And though he's a little short on manners, he is typically competent _enough_ to tell us if our towns are built to quality standards, and if they're not built to quality standards, well, it's his job to annoy us until we repair them. Unfortunately, i've got some bad news to share with you. After hastily exiting the train in ELSE-VILLE last night and not realizing there was no platform in this town (Thanks Terry!), KENNY_LINTER has broken both of his legs, fractured an arm, and scratched his face up pretty bad. So i doubt we'll be hearing from him in this episode, but stay tuned for future appearances. THE_TRAIN: The Train represents our Python script. THE_TRACKS: The (railroad)tracks represent our program logic. And the train's course is bound to these tracks THE_ENGINEER: This is the Python runtime which "drives" the train. THE_TRACK_SWITCH: The Track Switch is a mechanical section of the track (aka: logic gate) placed approximately halfway between the train station and the two shanty towns that Terry built. The switch allows the train to travel in one of two directions -- one leading to IF_VILLE, and one leading to ELSE_VILLE. Now, the mechanical apparatus of the switch is spring loaded, and thus, by default, it always sends a passing train to ELSE_VILLE. However, there is a tiny control button mounted on a nearby fence post, one which when pressed, will align the tracks with IF_VILLE. However, since the trains in this metaphor have no brakes, and since the button is really ~really~ small -- and since i couldn't think of a more creative scenario! -- there is only one creature who can press this button (TRUTHY_CLAWS!). And she presses this button using one of her long pointy claws, and thus, can send the train towards IF_VILLE. TRUTHY_CLAWS: TruthyClaws (or "TC", as we like to call her) is a mostly harmless anthropomorphized version of a marsupial who's long claws only seem useful (at least upon first sight) for causing a dreadful fright. But in reality, these claws serve a vital purpose in our little metaphorical world. You see, of ~all~ the characters in our little universe, only TC (using one of her dreadfully long claws) can press the little button on the TRACK_SWITCH and send us along a path to IF-VILLE. And, every time TC takes a ride with us in the train, she presses the little button for us, and off we go to IF-VILLE (Hooray!). However, sometimes us guys get a little rowdy and tell dirty jokes during the trip, and TC, being uptight and all, tends to get offended, and sometimes she refuses to ride with us. So, whenever TC is with us, we always go to IF-VILLE, but if she's off pouting somewhere, the train goes to ELSE-VILLE THE_TRACK_DEVIL: The Track Devil is a supernatural being in the mold of Loki who specializes in all forms of mischievous pranks. And you never know where the little devil might pop- up next. Rumor has it he's been seen lurking around the THE_TRACK_SWITCH and placing coinage on the tracks, but we can neither confirm nor deny these rumours. Although, there is a strange old woman who lives on the outskirts of ELSE_VILLE who claims she can foretell the appearance of the track devil. But most people 'round these parts consider her to be a total nut job. Using this metaphor we can understand that the else-clause in Terry's example serves no practical purpose. And being that Kenny Linter is already in the hospital for an injury he would have _never_ suffered if the undeveloped ELSE_VILLE had not been on his inspection roster, how the hell can you justify your argument? I mean, seriously. Terry almost killed Kenny! From nad at python.org Tue Dec 5 21:29:55 2017 From: nad at python.org (Ned Deily) Date: Tue, 5 Dec 2017 21:29:55 -0500 Subject: [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available for testing Message-ID: Announcing the immediate availability of Python 3.6.4 release candidate 1 and of Python 3.7.0 alpha 3! Python 3.6.4rc1 is the first release candidate for Python 3.6.4, the next maintenance release of Python 3.6. While 3.6.4rc1 is a preview release and, thus, not intended for production environments, we encourage you to explore it and provide feedback via the Python bug tracker (https://bugs.python.org). 3.6.4 is planned for final release on 2017-12-18 with the next maintenance release expected to follow in about 3 months. You can find Python 3.6.4rc1 and more information here: https://www.python.org/downloads/release/python-364rc1/ Python 3.7.0a3 is the third of four planned alpha releases of Python 3.7, the next feature release of Python. During the alpha phase, Python 3.7 remains under heavy development: additional features will be added and existing features may be modified or deleted. Please keep in mind that this is a preview release and its use is not recommended for production environments. The next preview release, 3.7.0a4, is planned for 2018-01-08. You can find Python 3.7.0a3 and more information here: https://www.python.org/downloads/release/python-370a3/ -- Ned Deily nad at python.org -- [] From hasan.diwan at gmail.com Tue Dec 5 21:44:53 2017 From: hasan.diwan at gmail.com (Hasan Diwan) Date: Tue, 5 Dec 2017 18:44:53 -0800 Subject: [Python-Dev] [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available for testing In-Reply-To: References: Message-ID: Congrats to all involved! -- H? From rustompmody at gmail.com Tue Dec 5 22:49:17 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Dec 2017 19:49:17 -0800 (PST) Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote: > Hi, Tony, > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: > > On 05/12/17 16:55, Igor Korot wrote: > >> Hi, > >> > >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote: > >>> Sir, > >>> I am b.tech student I would like to learn python. So please send the python software. > >> Sorry, we don't send anything. You will have to go get it yourself. -) > >> > > Well, at least try to be helpful: > > https://www.python.org/downloads/ > > This is LMGIFY. > If they say they are tech students - they should know how to work with Google. > > And I even tried to be polite. I should have probably write something like: > > 1. Open the Web browser. > 2. In the "Address Bar" type "www.pyton.org". > 3. Find the link which reads "Downloads". Click on it. > 4. Carefully read what version you need to install for your OS. > 5. Apply the acquired knowledge and download the appropriate version. > 6. Click on the installer (if on Windows). > 7. Follow all the prompts. > 8. Enjoy. > > but this is too much for the tech student. You are assuming that the strangeness of the request is about 'tech' [engineering/tech existed centuries before computers] Do remember one can be a tech-{student,professional} without - ever having encountered free-software - internet/USENET culture ? from which pov the request would not look so odd From srikrishnamohan at gmail.com Tue Dec 5 23:38:54 2017 From: srikrishnamohan at gmail.com (km) Date: Wed, 6 Dec 2017 10:08:54 +0530 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: I dont know how these students are selected into b tech stream in India. they are so dumb. All they know is a to open a program we need to double click it and it runs.- windoze legacy. most of the time they pay huge amount to a greedy college and get into tech stream. Now that Java boom (jobs) is over in India and python is booming in AI and machine learning these people want to learn python and get easy jobs (software coolies). pls dont even entertain such posts. On Wed, Dec 6, 2017 at 9:19 AM, Rustom Mody wrote: > On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote: > > Hi, Tony, > > > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: > > > On 05/12/17 16:55, Igor Korot wrote: > > >> Hi, > > >> > > >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote: > > >>> Sir, > > >>> I am b.tech student I would like to learn python. So please > send the python software. > > >> Sorry, we don't send anything. You will have to go get it yourself. -) > > >> > > > Well, at least try to be helpful: > > > https://www.python.org/downloads/ > > > > This is LMGIFY. > > If they say they are tech students - they should know how to work with > Google. > > > > And I even tried to be polite. I should have probably write something > like: > > > > 1. Open the Web browser. > > 2. In the "Address Bar" type "www.pyton.org". > > 3. Find the link which reads "Downloads". Click on it. > > 4. Carefully read what version you need to install for your OS. > > 5. Apply the acquired knowledge and download the appropriate version. > > 6. Click on the installer (if on Windows). > > 7. Follow all the prompts. > > 8. Enjoy. > > > > but this is too much for the tech student. > > You are assuming that the strangeness of the request is about 'tech' > [engineering/tech existed centuries before computers] > > Do remember one can be a tech-{student,professional} without > - ever having encountered free-software > - internet/USENET culture > > ? from which pov the request would not look so odd > > -- > https://mail.python.org/mailman/listinfo/python-list > From abhi.darkness at gmail.com Tue Dec 5 23:45:15 2017 From: abhi.darkness at gmail.com (Abhiram R) Date: Wed, 6 Dec 2017 10:15:15 +0530 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On Wed, Dec 6, 2017 at 10:08 AM, km wrote: > I dont know how these students are selected into b tech stream in India. > they are so dumb. All they know is a to open a program we need to double > click it and it runs. > > ?We were all once "dumb". We learnt it because someone Taught us. I'd rather not entertain such or refrain from condescending replies that would further discourage people from trying to get into the field. With all the emphasis on the Python "community", it's important not to be so dismissive. Thanks Abhiram ? > > > On Wed, Dec 6, 2017 at 9:19 AM, Rustom Mody wrote: > > > On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote: > > > Hi, Tony, > > > > > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: > > > > On 05/12/17 16:55, Igor Korot wrote: > > > >> Hi, > > > >> > > > >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote: > > > >>> Sir, > > > >>> I am b.tech student I would like to learn python. So please > > send the python software. > > > >> Sorry, we don't send anything. You will have to go get it yourself. > -) > > > >> > > > > Well, at least try to be helpful: > > > > https://www.python.org/downloads/ > > > > > > This is LMGIFY. > > > If they say they are tech students - they should know how to work with > > Google. > > > > > > And I even tried to be polite. I should have probably write something > > like: > > > > > > 1. Open the Web browser. > > > 2. In the "Address Bar" type "www.pyton.org". > > > 3. Find the link which reads "Downloads". Click on it. > > > 4. Carefully read what version you need to install for your OS. > > > 5. Apply the acquired knowledge and download the appropriate version. > > > 6. Click on the installer (if on Windows). > > > 7. Follow all the prompts. > > > 8. Enjoy. > > > > > > but this is too much for the tech student. > > > > You are assuming that the strangeness of the request is about 'tech' > > [engineering/tech existed centuries before computers] > > > > Do remember one can be a tech-{student,professional} without > > - ever having encountered free-software > > - internet/USENET culture > > > > ? from which pov the request would not look so odd > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- -Abhiram R ? From ssghotra1997 at gmail.com Wed Dec 6 00:02:55 2017 From: ssghotra1997 at gmail.com (ssghotra1997 at gmail.com) Date: Tue, 5 Dec 2017 21:02:55 -0800 (PST) Subject: Python homework In-Reply-To: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: import random def rollDie(num): sides = {'One':0, 'Two':0,'Three':0,'Four':0,'Five':0,'Six':0} for i in range(num): rolls = int(random.randint(1, 6)) if rolls == 1: sides['One'] += 1 if rolls == 2: sides['Two'] += 1 if rolls == 3: sides['Three'] += 1 if rolls == 4: sides['Four'] += 1 if rolls == 5: sides['Five'] += 1 if rolls == 6: sides['Six'] += 1 return sides,max(sides,key=sides.get) print(rollDie(50)) *********************** OUTPUT ********************************************* ({'One': 10, 'Two': 7, 'Three': 7, 'Four': 11, 'Five': 7, 'Six': 8}, 'Four') From steve+python at pearwood.info Wed Dec 6 00:26:00 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 17:26:00 +1200 Subject: f-string References: <3251756805@f38.n261.z1.binkp.net> Message-ID: <2031336228@f38.n261.z1.binkp.net> On Wed, 6 Dec 2017 11:54 am, John Pote wrote: [...] > Ran above test file and got, > >>python36 compiletest.py > at 0x0000000002120E40, file "", line 1> > > > SPAM scrambled Thanks everyone, that's what I wanted to see. -- Steve ? ?Cheer up,? ? they said, ? ?things could be worse.? ? So I cheered up, and sure enough, things got worse. From srikrishnamohan at gmail.com Wed Dec 6 00:27:36 2017 From: srikrishnamohan at gmail.com (km) Date: Wed, 6 Dec 2017 10:57:36 +0530 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: Remember that you are wasting time of lakhs of python subscribers by asking such dumb questions being tech students. You people can Google and watch movies / songs online and you can't find how to download and install python ? That's ridiculous! On Dec 6, 2017 10:15 AM, "Abhiram R" wrote: > > > On Wed, Dec 6, 2017 at 10:08 AM, km wrote: > >> I dont know how these students are selected into b tech stream in India. >> they are so dumb. All they know is a to open a program we need to double >> click it and it runs. >> >> ?We were all once "dumb". We learnt it because someone Taught us. I'd > rather not entertain such or refrain from condescending replies that would > further discourage people from trying to get into the field. With all the > emphasis on the Python "community", it's important not to be so dismissive. > > > Thanks > Abhiram ? > > > > >> >> >> On Wed, Dec 6, 2017 at 9:19 AM, Rustom Mody >> wrote: >> >> > On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote: >> > > Hi, Tony, >> > > >> > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: >> > > > On 05/12/17 16:55, Igor Korot wrote: >> > > >> Hi, >> > > >> >> > > >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote: >> > > >>> Sir, >> > > >>> I am b.tech student I would like to learn python. So >> please >> > send the python software. >> > > >> Sorry, we don't send anything. You will have to go get it >> yourself. -) >> > > >> >> > > > Well, at least try to be helpful: >> > > > https://www.python.org/downloads/ >> > > >> > > This is LMGIFY. >> > > If they say they are tech students - they should know how to work with >> > Google. >> > > >> > > And I even tried to be polite. I should have probably write something >> > like: >> > > >> > > 1. Open the Web browser. >> > > 2. In the "Address Bar" type "www.pyton.org". >> > > 3. Find the link which reads "Downloads". Click on it. >> > > 4. Carefully read what version you need to install for your OS. >> > > 5. Apply the acquired knowledge and download the appropriate version. >> > > 6. Click on the installer (if on Windows). >> > > 7. Follow all the prompts. >> > > 8. Enjoy. >> > > >> > > but this is too much for the tech student. >> > >> > You are assuming that the strangeness of the request is about 'tech' >> > [engineering/tech existed centuries before computers] >> > >> > Do remember one can be a tech-{student,professional} without >> > - ever having encountered free-software >> > - internet/USENET culture >> > >> > ? from which pov the request would not look so odd >> > >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> > >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > > -- > -Abhiram R > ? > From rosuav at gmail.com Wed Dec 6 00:54:57 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Dec 2017 16:54:57 +1100 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On Wed, Dec 6, 2017 at 4:27 PM, km wrote: > Remember that you are wasting time of lakhs of python subscribers by > asking such dumb questions being tech students. You people can Google and > watch movies / songs online and you can't find how to download and install > python ? That's ridiculous! > This attack is unwarranted. Please don't set fire to people simply because they asked a question like this. You can be far more courteous than this, even if you refuse to help. Particularly, the "you people" sounds like a blanket statement, which is almost certainly not useful to the discussion. To the OP: Several people have suggested ways to get the software you need, even if they've done it somewhat rudely. The best thing to do here is to type "python" into your favourite search engine (Google, DuckDuckGo, Bing, AltaVista, etc), and then read the web page for a download link. You should be able to find it. If you've tried and failed, or if something confuses you, come back to the list and ask a specific question, and we'll be happy to answer. ChrisA From ethan at stoneleaf.us Wed Dec 6 01:17:14 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 05 Dec 2017 22:17:14 -0800 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: <5A278B6A.7090001@stoneleaf.us> On 12/05/2017 09:27 PM, km wrote: [snip] Many things in this world are frustrating, but being hateful will not solve anything. Please control yourself. -- ~Ethan~ From steve+python at pearwood.info Wed Dec 6 01:26:01 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 17:26:01 +1100 Subject: f-string References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> <1386adbe-024e-b83f-b71b-9d3d36d4372b@jptechnical.co.uk> Message-ID: <5a278d79$0$2050$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 11:54 am, John Pote wrote: [...] > Ran above test file and got, > >>python36 compiletest.py > at 0x0000000002120E40, file "", line 1> > > > SPAM scrambled Thanks everyone, that's what I wanted to see. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Dec 6 02:49:23 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 18:49:23 +1100 Subject: csv.DictReader line skipping should be considered a bug? References: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> <5a27348f$0$2075$b1db1813$d948b532@news.astraweb.com> <615b60a8-4cad-52fd-2462-36efe5567343@mrabarnett.plus.com> Message-ID: <5a27a104$0$2067$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 11:43 am, MRAB wrote: > A blank line could be a record if there's only one field and it's empty. That's technically correct, but if you have only one field, its barely a CSV file at all. Given that CSV technically requires at least two fields (in order to have a separator between fields) I'm not too concerned by the inability to represent a record consisting of only a single blank field. If there was an actual CSV standard (rather than just a collection of implementations with slightly different behaviour) I'd be more concerned at this design lack. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From pjh at nanoworks.com Wed Dec 6 03:14:13 2017 From: pjh at nanoworks.com (Percival John Hackworth) Date: Wed, 06 Dec 2017 00:14:13 -0800 Subject: we want python software References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> On 05-Dec-2017, km wrote (in article): > I dont know how these students are selected into b tech stream in India. > they are so dumb. All they know is a to open a program we need to double > click it and it runs.- windoze legacy. most of the time they pay huge > amount to a greedy college and get into tech stream. > Now that Java boom (jobs) is over in India and python is booming in AI and > machine learning these people want to learn python and get easy jobs > (software coolies). pls dont even entertain such posts. A friend who deals with outsource Indian developers told me something interesting. Apparently, the programmers are paid very poorly in India. Managers are paid much better. So the career path over there is to "pay your dues" writing code, then become a manager where you no longer have to write code. It means that all the product teams that are outsourced to India *always* get new, green people because as soon as they get any good, they become managers. That explains a lot, doesn't it. It also means when your company lays off a lot of technical staff and outsources tech pubs, 1st line support, and development to India, the people left in the US are the "Tiger Team" to fix screw ups or major issues in a product release. Then they sell the company. Another friend hired a programmer from India to develop a java-based web site to sell their product in the iOS App Store. He asked me to look at problems they were having with the site. I'm a sysadmin, not a java programmer, but I knew that you're not supposed to run a Tomcat web server as root. According to friends, you're not supposed to expose Tomcat to the internet at all. That's not what this developer did. It looked like it was a school project that he setup stuff but didn't know how it's done in production with security enabled. Nor could he deal with AWS. It's a nightmare out there for people looking to get development done "on the cheap". The good people (e.g. the friends I asked for advice) are to busy to do such little projects to bother. So the market is left with Junior people in India making crap. It's not a question of them taking jobs away from U.S. developers. It's a question of the good ones already have work. Can we train Joe to setup Wordpress and secure it or write a Java Web site when all he's done before is manufacturing or worked in a grocery store. Other groups aren't so nice to beginners - the perl group is brutal and tell a student to do their own homework. I'm just dipping my toe into python here and you guys more helpful. Mostly because there's so much possibility in python (compared to other scripting languages). From steve+python at pearwood.info Wed Dec 6 03:24:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 20:24:22 +1200 Subject: f-string References: <1171780012@f38.n261.z1.binkp.net> Message-ID: <753716518@f38.n261.z1.binkp.net> On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 11:54 AM, John Pote > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test something for me? >>> >>> What does compile('f"{spam} {eggs}"', '', 'single') return? [...] > I think Steve just wanted to see what we'd all define spam and eggs as. > > ChrisA > *ducking for cover* Possibly duck eggs :-) I was thinking of responding to your comment on Python-Ideas that said there is no way to represent an unevaluated f-string in Python, but then I decided that even for me that was too pedantic. -- Steve ? ?Cheer up,? ? they said, ? ?things could be worse.? ? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Wed Dec 6 03:34:38 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 06 Dec 2017 20:34:38 +1200 Subject: f-string Message-ID: <669954835@f38.n261.z1.binkp.net> On Wed, Dec 6, 2017 at 8:24 PM, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > >> On Wed, Dec 6, 2017 at 11:54 AM, John Pote >> wrote: >>> >>> On 06/12/2017 00:16, Steve D'Aprano wrote: >>>> >>>> Anyone got a handy copy of Python 3.6 available to test something for me? >>>> >>>> What does compile('f"{spam} {eggs}"', '', 'single') return? > > [...] > >> I think Steve just wanted to see what we'd all define spam and eggs as. >> >> ChrisA >> *ducking for cover* > > Possibly duck eggs :-) > > > I was thinking of responding to your comment on Python-Ideas that said there > is no way to represent an unevaluated f-string in Python, but then I decided > that even for me that was too pedantic. > Considering that it isn't an object, it'd be on par with saying that there's no way to represent an unevaluated "if-else" expression. You can wrap it in a function and carry that function around, or you can use the source code and then exec it when you need it, but neither of those really represents an unevaluated f-string - they represent something else that might be equivalent. So yeah, even for the great D'Aprano, that would be a bit too pedantic. :) ChrisA From steve+python at pearwood.info Wed Dec 6 03:35:20 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 20:35:20 +1200 Subject: we want python software References: <441615813@f38.n261.z1.binkp.net> Message-ID: <3823140200@f38.n261.z1.binkp.net> On Wed, 6 Dec 2017 03:45 pm, Abhiram R wrote: > On Wed, Dec 6, 2017 at 10:08 AM, km wrote: > >> I dont know how these students are selected into b tech stream in India. >> they are so dumb. All they know is a to open a program we need to double >> click it and it runs. >> >> We were all once "dumb". We learnt it because someone Taught us. Since you're so open to being corrected, let me remind you to read your posts before sending. Somehow you managed to introduce an extra > quote marker at the beginning of your own comment, (the line starting "We were all once..."). Check it out here: https://mail.python.org/pipermail/python-list/2017-December/729112.html and you will see that your comment is quoted, as if it were written by the person you are replying to. (Normally I wouldn't bother mentioning something so trivial, but since you make the excellent point that we don't learn to correct mistakes unless we have them pointed out, I thought I'd do so.) > I'd rather not entertain such or refrain from condescending replies I think you have misunderstood the word "condescending". It is condescending to assume that the OP, Jyothiswaroop Reddy, is a fragile and delicate little hothouse flower that needs protecting from reality where people will tell you "Don't be so lazy and don't waste our time". I prefer to expect more of people and let them meet my expectations, than to downgrade my expectations and coddle them into a spiral of lower and lower competence and ability. (By the way Rustom, if you're reading, thank you for that link to the video a few weeks ago about teaching 2 + 2 = 22. My blood pressure just about doubled watching it.) -- Steve ? ?Cheer up,? ? they said, ? ?things could be worse.? ? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Dec 6 04:24:23 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 20:24:23 +1100 Subject: f-string References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> <1386adbe-024e-b83f-b71b-9d3d36d4372b@jptechnical.co.uk> Message-ID: <5a27b747$0$2085$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 11:54 AM, John Pote > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test something for me? >>> >>> What does compile('f"{spam} {eggs}"', '', 'single') return? [...] > I think Steve just wanted to see what we'd all define spam and eggs as. > > ChrisA > *ducking for cover* Possibly duck eggs :-) I was thinking of responding to your comment on Python-Ideas that said there is no way to represent an unevaluated f-string in Python, but then I decided that even for me that was too pedantic. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Wed Dec 6 04:34:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Dec 2017 20:34:39 +1100 Subject: f-string In-Reply-To: <5a27b747$0$2085$b1db1813$d948b532@news.astraweb.com> References: <5a2736dc$0$2737$b1db1813$eb6074ea@news.astraweb.com> <1386adbe-024e-b83f-b71b-9d3d36d4372b@jptechnical.co.uk> <5a27b747$0$2085$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Dec 6, 2017 at 8:24 PM, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > >> On Wed, Dec 6, 2017 at 11:54 AM, John Pote >> wrote: >>> >>> On 06/12/2017 00:16, Steve D'Aprano wrote: >>>> >>>> Anyone got a handy copy of Python 3.6 available to test something for me? >>>> >>>> What does compile('f"{spam} {eggs}"', '', 'single') return? > > [...] > >> I think Steve just wanted to see what we'd all define spam and eggs as. >> >> ChrisA >> *ducking for cover* > > Possibly duck eggs :-) > > > I was thinking of responding to your comment on Python-Ideas that said there > is no way to represent an unevaluated f-string in Python, but then I decided > that even for me that was too pedantic. > Considering that it isn't an object, it'd be on par with saying that there's no way to represent an unevaluated "if-else" expression. You can wrap it in a function and carry that function around, or you can use the source code and then exec it when you need it, but neither of those really represents an unevaluated f-string - they represent something else that might be equivalent. So yeah, even for the great D'Aprano, that would be a bit too pedantic. :) ChrisA From steve+python at pearwood.info Wed Dec 6 04:35:20 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 20:35:20 +1100 Subject: we want python software References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: <5a27b9d9$0$2083$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 03:45 pm, Abhiram R wrote: > On Wed, Dec 6, 2017 at 10:08 AM, km wrote: > >> I dont know how these students are selected into b tech stream in India. >> they are so dumb. All they know is a to open a program we need to double >> click it and it runs. >> >> We were all once "dumb". We learnt it because someone Taught us. Since you're so open to being corrected, let me remind you to read your posts before sending. Somehow you managed to introduce an extra > quote marker at the beginning of your own comment, (the line starting "We were all once..."). Check it out here: https://mail.python.org/pipermail/python-list/2017-December/729112.html and you will see that your comment is quoted, as if it were written by the person you are replying to. (Normally I wouldn't bother mentioning something so trivial, but since you make the excellent point that we don't learn to correct mistakes unless we have them pointed out, I thought I'd do so.) > I'd rather not entertain such or refrain from condescending replies I think you have misunderstood the word "condescending". It is condescending to assume that the OP, Jyothiswaroop Reddy, is a fragile and delicate little hothouse flower that needs protecting from reality where people will tell you "Don't be so lazy and don't waste our time". I prefer to expect more of people and let them meet my expectations, than to downgrade my expectations and coddle them into a spiral of lower and lower competence and ability. (By the way Rustom, if you're reading, thank you for that link to the video a few weeks ago about teaching 2 + 2 = 22. My blood pressure just about doubled watching it.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From darcy at VybeNetworks.com Wed Dec 6 05:20:26 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Wed, 6 Dec 2017 04:20:26 -0600 Subject: Python homework In-Reply-To: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: <3e6ebec8-8950-5613-fa3e-b7ae7b5c7a80@VybeNetworks.com> On 12/05/2017 07:33 PM, nick.martinez2--- via Python-list wrote: > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value of all rolls. > I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. How did you come up with 4? I come up with 3.36 with those numbers. > This is what I have so far: > import random > > def rollDie(number): > rolls = [0] * 6 For a small efficiency use "[0] * 7". See below for reason. > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 Use "rolls[roll] += 1" here. You save one arithmetic instruction each time through the loop. Fifty times isn't much saving but imagine fifty million. > return rolls return rolls[1:]. No matter how many rolls you only need to do the slice once. However, you really need a lot of iterations before it really affects the total run time. You need one more thing though. Create a new variable called "total" and set it to 0.0. Add "total += roll" to your loop. your return statement is now "return rolls[1:], total/number". > > if __name__ == "__main__": > result = rollDie(50) Now "result, average = ..." > print (result) > print(max(result)) This is why you get 14. The maximum number of rolls for any one side is 14 for side 4. Is that where you got "4"? -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From steve+python at pearwood.info Wed Dec 6 05:35:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Dec 2017 21:35:22 +1100 Subject: we want python software References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: <5a27c7eb$0$2066$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 02:49 pm, Rustom Mody wrote: > You are assuming that the strangeness of the request is about 'tech' > [engineering/tech existed centuries before computers] > > Do remember one can be a tech-{student,professional} without > - ever having encountered free-software > - internet/USENET culture > > ? from which pov the request would not look so odd So you're suggesting that rather than being unwilling to google for "Download Python" because he doesn't understand free software culture, the OP is unwilling to google for "Download Python" because he thinks it is proprietary software and wants a bunch of strangers on the Internet to send him a pirate copy? I'm not entirely sure that's better... -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Wed Dec 6 07:25:36 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Dec 2017 04:25:36 -0800 (PST) Subject: Politeness (was: we want python software) In-Reply-To: <5a27c7eb$0$2066$b1db1813$d948b532@news.astraweb.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a27c7eb$0$2066$b1db1813$d948b532@news.astraweb.com> Message-ID: <7dd1b4ae-3f38-4be7-8c08-0f54097e5dca@googlegroups.com> On Wednesday, December 6, 2017 at 4:05:43 PM UTC+5:30, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 02:49 pm, Rustom Mody wrote: > > > You are assuming that the strangeness of the request is about 'tech' > > [engineering/tech existed centuries before computers] > > > > Do remember one can be a tech-{student,professional} without > > - ever having encountered free-software > > - internet/USENET culture > > > > ? from which pov the request would not look so odd > > So you're suggesting that rather than being unwilling to google for "Download > Python" because he doesn't understand free software culture, the OP is > unwilling to google for "Download Python" because he thinks it is proprietary > software and wants a bunch of strangers on the Internet to send him a pirate > copy? > > I'm not entirely sure that's better... Dunno anything about OP so no 'suggesting'? I did hint one point above which can be restated more explicitly. An engineering degree (aka ?B.Tech?) can be in any of - IT, CS, Computer Engineering etc - aeronautics, civil, electrical, mechanical? classical, non-computer related - bioinformatics, statistics, "scientific computing" etc ie heavy-duty *users* of computers For the latter two classes it would be normal/natural for the student to have little knowledge/interest in computer-related stuff except as a user. Are you interested in the latest disk-drive technology? power-supplies? kernel? systemd-vs-sysv? We use these all the time. Likewise these other fields are *users* of computers. Inter alia I will mention: I have a colleague working on ACM's next curriculum And the inter-disciplinarity of CS is the next big deal it would appear. ie "unwilling to google" could well be "ignorant of google (usage/practices)" Do consider the possibility that a student could be a non-owner of a computer and/or studying in a college in a poor/non networked location. So? So while the specific slurs/attacks on some country are of near-zero interest to me ? to support or oppose ? the deeper divisions and inequities are (IMHO) more important. So here's a little statistical exercise for you: - Take any demographic of your choice containing programmers. - Compute the male/female programmers in that population - Now come to this list and work out the same ratio - How do these ratios compare? [When's the last time a woman appeared here?] IOW I would wish Ethan's "control yourself" to be imperated ? preferably by oneself, if not then forcibly. And especially when the vitriol is flung at a first-time poster. From steve at holdenweb.com Wed Dec 6 07:30:13 2017 From: steve at holdenweb.com (Steve Holden) Date: Wed, 6 Dec 2017 12:30:13 +0000 Subject: [Python-Dev] [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available for testing In-Reply-To: References: Message-ID: Ned, In your role as a representative of the many fine release managers Python has had over the years I'd like to thank you for continuing to make high-quality software available to a large and growing community. And thanks to everyone who contributes to Python so the majority just get to enjoy it. Seasons greetings Steve Steve Holden On Wed, Dec 6, 2017 at 2:29 AM, Ned Deily wrote: > Announcing the immediate availability of Python 3.6.4 release candidate 1 > and of Python 3.7.0 alpha 3! > > Python 3.6.4rc1 is the first release candidate for Python 3.6.4, the next > maintenance release of Python 3.6. While 3.6.4rc1 is a preview release > and, > thus, not intended for production environments, we encourage you to explore > it and provide feedback via the Python bug tracker ( > https://bugs.python.org). > 3.6.4 is planned for final release on 2017-12-18 with the next maintenance > release expected to follow in about 3 months. You can find Python 3.6.4rc1 > and more information here: > https://www.python.org/downloads/release/python-364rc1/ > > Python 3.7.0a3 is the third of four planned alpha releases of Python 3.7, > the next feature release of Python. During the alpha phase, Python 3.7 > remains under heavy development: additional features will be added > and existing features may be modified or deleted. Please keep in mind > that this is a preview release and its use is not recommended for > production environments. The next preview release, 3.7.0a4, is planned > for 2018-01-08. You can find Python 3.7.0a3 and more information here: > https://www.python.org/downloads/release/python-370a3/ > > -- > Ned Deily > nad at python.org -- [] > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ > steve%40holdenweb.com > From rustompmody at gmail.com Wed Dec 6 07:53:20 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Dec 2017 04:53:20 -0800 (PST) Subject: Lies (was: we want python software) In-Reply-To: <5a27b9d9$0$2083$b1db1813$d948b532@news.astraweb.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a27b9d9$0$2083$b1db1813$d948b532@news.astraweb.com> Message-ID: <45bc7895-fc59-45a0-962c-23b3226ad337@googlegroups.com> On Wednesday, December 6, 2017 at 3:05:33 PM UTC+5:30, Steve D'Aprano wrote: > (By the way Rustom, if you're reading, thank you for that link to the video a > few weeks ago about teaching 2 + 2 = 22. My blood pressure just about doubled > watching it.) [Ref: https://youtu.be/Zh3Yz3PiXZw ] Yes? Lies are a big problem today. [For myself] Between being nice and being truthful, latter should have priority. I was at first surprised and even a bit shocked when people called me right-wing. Over time Ive come to accept that lies (left-wing) is upstream of hate (right-wing). And to the extent that effects must be stemmed from causes, the world is probably safer with the right than the left Coming to this thread, I am surprised that you took to task Abhiram R for his (minor) slips of posting, neglecting to mention that the repeated vituperative posts of "KM" are chock-full of - grammatical errors - spelling errors - top-posting - Indianisms like ?lakh? ?coolie? which are unlikely decipherable by an international audience And that in a post critical of Indians! From dvl at psu.edu Wed Dec 6 09:59:38 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Wed, 6 Dec 2017 09:59:38 -0500 Subject: Python-list Digest, Vol 171, Issue 7 In-Reply-To: mailman.679.1512563403.28473.python-list@python.org References: Message-ID: <1512572378l.24117414l.0l@psu.edu> I think I also came up with 4 as "the most frequent number". It is unclear ot me how you came up with 3.36 as the most common number, because I tried rolling a six-sided die myself several times, and somehow 3.36 didn't come up even once! On Wed, Dec 6, 2017, D'Arcy Cain wrote: > On 12/05/2017 07:33 PM, nick.martinez2--- via Python-list wrote: >> I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 >> times and then prints >> (i). the most frequent side of the die >> (ii). the average die value of all rolls. >> I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. > >How did you come up with 4? I come up with 3.36 with those numbers. > From dvl at psu.edu Wed Dec 6 10:15:09 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Wed, 6 Dec 2017 10:15:09 -0500 Subject: Python-list Digest, Vol 171, Issue 7 In-Reply-To: mailman.679.1512563403.28473.python-list@python.org References: Message-ID: <1512573309l.30670904l.0l@psu.edu> On Wed, Dec 6, 2017, ssghotra1997 wrote: import random def rollDie(num): sides = {'One':0, 'Two':0,'Three':0,'Four':0,'Five':0,'Six':0} for i in range(num): rolls = int(random.randint(1, 6) if rolls == 1: sides['One'] += 1 if rolls == 2: sides['Two'] += 1 if rolls == 3: sides['Three'] += 1 if rolls == 4: sides['Four'] += 1 if rolls == 5: sides['Five'] += 1 if rolls == 6: sides['Six'] += 1 return sides,max(sides,key=sides.get) print(rollDie(50) *********************** OUTPUT ********************************************* ({'One': 10, 'Two': 7, 'Three': 7, 'Four': 11, 'Five': 7, 'Six': 8}, 'Four') You should always be suspicious if any case where you see identical or nearly-identical code duplicated more than three times, because that strongly suggests that there is a much better way that avoids such code duplication. This problem of identifying a most frequent die roll could be applicable to imaginary dice of any size, since the concept would e the same. Imagine how much tedious work you would have to do if the question was about a 20-sided die or a 34-sided die! Of course, there is the special feature here of using words ('One', 'Two'..) to stand for the numbers, but even those could be addressed very neatly with a hand data structure and no code complexity. It might not make much difference for a homework assignment of this size at this point in your curriculum. But later on, you would pay a heavy price for choosing implementations that require 5, 10, or 20 times as much code as necessary. The increase in program size would have a multiplicative effect on writing time and debugging time and would have an adverse affect on a course grade, product delivery date, customer satisfaction, and job security. So learn how to find the efficient solutions now while you still have instructors around to help you. Roger Christman Pennsylvania State University From rantingrickjohnson at gmail.com Wed Dec 6 10:27:05 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 07:27:05 -0800 (PST) Subject: we want python software In-Reply-To: <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> Message-ID: On Wednesday, December 6, 2017 at 2:14:40 AM UTC-6, Percival John Hackworth wrote: [...] > [...] > The good people (e.g. the friends I asked for advice) are > to busy to do such little projects to bother. Good work is not cheap. And cheap work is not good. > So the market is left with Junior people in India making > crap. It's not a question of them taking jobs away from > U.S. developers. It's a question of the good ones already > have work. Can we train Joe to setup Wordpress and secure > it or write a Java Web site when all he's done before is > manufacturing or worked in a grocery store. Not easily, no. There are certain fundamental personality attributes and natural inclinations that lend themselves nicely to writing code. (1) Strongly self-reliance This cannot be stressed enough. If you're the type of person who requires a micro-manager to hover over your shoulder all day telling you what to do, then writing software is _not_ for you. (2) Naturally analytical If the greatest thought that has ever entered your mind is "Hmm, i wonder what the Kardasians are doing today?", then writing software is _not_ for you. There are plenty of department stores who could use another brain-dead sales rep. OTOH, if you find yourself intrigued by the inner workings of just about every system and process in our universe, then you may be an excellent candidate for this field -- among many other mentally challenging fields. (3) Logically inclined If logic did not come naturally to you, or you feel that logic is nothing but the philosophical penchant of sadistic pedantics, then writing software is _absolutely_ not for you. You simply cannot write software unless you possess a strong grasp of logic. (4) Exceptional problem solving skills Problem solving requires first breaking a problem structure down into its component parts using your analytical skills, and then applying logical solutions to each of these components in a manner that will satisfy the whole. Pragmatics is often your best friend. But you must not loose sight of the bigger picture. For if you dismiss the delicate and synergistic interplay between these components, your naive solution will collapse on itself. Problem solving requires thinking deeply in the abstract using metaphors, applying diverse methodologies, and identifying the weak spots in your proposed solution. Typically there isn't a perfect solution. For, if there were a perfect solution to every software problem, we could automate the software development process. Code is not something you just yank out of your colon like it were a fictional story for entertainment purposes, no, it's called Engineering for a _reason_. The remainder can be taught, and mostly a matter of memorization. Any idiot of average intelligence can learn the syntax, structural formatting rules and library contents of one or more programming languages, however, if they lack the aforementioned personality traits and natural skill sets, they can't do much of anything with such knowledge, and essentially, all they have accomplished is to fill their head with useless facts. Facts are only useful when they can be applied to solve problems. Short of that, they are mental refuse. I once encountered a most annoyingly uninformed dolt who quiped: DOLT: "Programming is easy! Once you learn the langauge, it's just a matter of fill-in-the-blanks." ME: "Oh really?" o_O ME: "Are you literate in the English?" DOLT: "Of course i am!" ME: "I see. And are you literate in English at an _advanced_ level?" DOLT: "Of course i am!!!" >:-( ME: "And does being literate in the English language necessarily mean that you could author a best selling novel?" DOLT: "Uh? Uh? (*sigh*) Probably not. No." :-'( ME: "Hmm, and could you author _anything_ that is worthy enough to be included on the shelves of a respectable book store?" DOLT: "Muh... Muh... Well, maybe!? :^|" [Hope springs eternal!] ?_? ME: "And how many books have you authored thus far?" DOLT: "Well nothing yet. >:-(" ME: "Okay then." ME: "Next time, think before you open your mouth." > Other groups aren't so nice to beginners - the perl group > is brutal and tell a student to do their own homework. There is clear difference between requesting advice on one small detail that is unclear, and positing a verbatim outline of a homework project and then expecting the group to cough up a complete solution on a silver platter. In the latter case, the student should be admonished. However, another approach is to offer an absurd solution. One which produces the correct result whilst being structurally, practically, and/or semantically a total train wreck. The instructor will "know". ;-) [Hope springs eternal!] ?_? From steve+python at pearwood.info Wed Dec 6 10:44:05 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Dec 2017 02:44:05 +1100 Subject: csv.DictReader line skipping should be considered a bug? References: <994fa3ff-587d-4d61-8b3f-2dadb88a54bb@googlegroups.com> <5a27348f$0$2075$b1db1813$d948b532@news.astraweb.com> <8b3g2dhsbbufv7crtlqk0o889j0al1sk8b@4ax.com> Message-ID: <5a281045$0$2727$b1db1813$eb6074ea@news.astraweb.com> On Thu, 7 Dec 2017 02:33 am, Dennis Lee Bieber wrote: > On Wed, 06 Dec 2017 11:06:39 +1100, Steve D'Aprano > declaimed the following: > > >>I wouldn't want to guess your mental health based just on this isolated >>incident, but if I had to make a diagnosis, I'd say, yes, crazy as a loon. >> > > Loons aren't crazy; they just sound that way. Kookaburras, OTOH... Don't knock kookaburras. Anything that makes a living by eating Australian snakes is worth respecting. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ikorot01 at gmail.com Wed Dec 6 10:49:14 2017 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 6 Dec 2017 09:49:14 -0600 Subject: Politeness (was: we want python software) In-Reply-To: <7dd1b4ae-3f38-4be7-8c08-0f54097e5dca@googlegroups.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a27c7eb$0$2066$b1db1813$d948b532@news.astraweb.com> <7dd1b4ae-3f38-4be7-8c08-0f54097e5dca@googlegroups.com> Message-ID: Rustom, On Wed, Dec 6, 2017 at 6:25 AM, Rustom Mody wrote: > On Wednesday, December 6, 2017 at 4:05:43 PM UTC+5:30, Steve D'Aprano wrote: >> On Wed, 6 Dec 2017 02:49 pm, Rustom Mody wrote: >> >> > You are assuming that the strangeness of the request is about 'tech' >> > [engineering/tech existed centuries before computers] >> > >> > Do remember one can be a tech-{student,professional} without >> > - ever having encountered free-software >> > - internet/USENET culture >> > >> > ? from which pov the request would not look so odd >> >> So you're suggesting that rather than being unwilling to google for "Download >> Python" because he doesn't understand free software culture, the OP is >> unwilling to google for "Download Python" because he thinks it is proprietary >> software and wants a bunch of strangers on the Internet to send him a pirate >> copy? >> >> I'm not entirely sure that's better... > > Dunno anything about OP so no 'suggesting'? > I did hint one point above which can be restated more explicitly. > > An engineering degree (aka ?B.Tech?) can be in any of > - IT, CS, Computer Engineering etc > - aeronautics, civil, electrical, mechanical? classical, non-computer related > - bioinformatics, statistics, "scientific computing" etc ie heavy-duty *users* > of computers I would agree with you here, but... (see below). > > For the latter two classes it would be normal/natural for the student to have > little knowledge/interest in computer-related stuff except as a user. > > Are you interested in the latest disk-drive technology? power-supplies? > kernel? systemd-vs-sysv? We use these all the time. Likewise these other fields are *users* of computers. > > Inter alia I will mention: I have a colleague working on ACM's next curriculum > And the inter-disciplinarity of CS is the next big deal it would appear. > > ie "unwilling to google" could well be "ignorant of google (usage/practices)" > Do consider the possibility that a student could be a non-owner of a computer > and/or studying in a college in a poor/non networked location. We live in a XXI century. This person do have access t the Internet. And he does say "send us", which implies that (s)he request the Python not just for one person. Moreover, Google should not be banned from any and all college. In fact it should be a standard policy for any technical school/college/university to have access to Google. But I'm actually more curious why a student request the help and the lab tech/teacher if he doesn't have a computer and work/study from the college. Thank you. > > So? > > So while the specific slurs/attacks on some country are of near-zero interest to me ? to support or oppose ? the deeper divisions and inequities are (IMHO) more important. > > So here's a little statistical exercise for you: > - Take any demographic of your choice containing programmers. > - Compute the male/female programmers in that population > - Now come to this list and work out the same ratio > - How do these ratios compare? > [When's the last time a woman appeared here?] > > IOW I would wish Ethan's "control yourself" to be imperated ? preferably > by oneself, if not then forcibly. > And especially when the vitriol is flung at a first-time poster. > -- > https://mail.python.org/mailman/listinfo/python-list From rantingrickjohnson at gmail.com Wed Dec 6 11:04:23 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 08:04:23 -0800 (PST) Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On Wednesday, December 6, 2017 at 12:11:47 AM UTC-6, Chris Angelico wrote: [...] > To the OP: [...] The best thing to do here is to type > "python" into your favourite search engine (Google, > DuckDuckGo, Bing, AltaVista, etc), and then read the web > page for a download link. I don't think a general web search is really such a good idea, as it is vital for the OP to download a _legitimate_ copy of the software, one that is not filled with bloatware and/or infected with exploits. And the only way to know you have a legit copy of Python software is to download it from the official Python.org website. Random web searches are great when you know what you're looking for, however, if the OP finds himself/herself on a shady site like downloads.com, or worse, somewhere in the filthy virus infected catacombs of Bill and Hillary Clinton's private email server haphazardly jammed into a bathroom closet with all manner of toiletries and even a commercial quality washing machine filled with Clinton Cash, you never know what you might find in there! Eh comrade? o_O From ian.g.kelly at gmail.com Wed Dec 6 11:18:35 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Dec 2017 09:18:35 -0700 Subject: Lies (was: we want python software) In-Reply-To: <45bc7895-fc59-45a0-962c-23b3226ad337@googlegroups.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a27b9d9$0$2083$b1db1813$d948b532@news.astraweb.com> <45bc7895-fc59-45a0-962c-23b3226ad337@googlegroups.com> Message-ID: On Wed, Dec 6, 2017 at 5:53 AM, Rustom Mody wrote: > I was at first surprised and even a bit shocked when people called me right-wing. > Over time Ive come to accept that lies (left-wing) is upstream of hate (right-wing). And to the extent that effects must be stemmed from causes, the world > is probably safer with the right than the left In my experience with politics, lies are the most universally bipartisan thing that we have. Just look at Donald Trump. From steve+python at pearwood.info Wed Dec 6 11:18:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Dec 2017 03:18:39 +1100 Subject: Politeness (was: we want python software) References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a27c7eb$0$2066$b1db1813$d948b532@news.astraweb.com> <7dd1b4ae-3f38-4be7-8c08-0f54097e5dca@googlegroups.com> Message-ID: <5a28185f$0$2067$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 11:25 pm, Rustom Mody wrote: > On Wednesday, December 6, 2017 at 4:05:43 PM UTC+5:30, Steve D'Aprano wrote: >> On Wed, 6 Dec 2017 02:49 pm, Rustom Mody wrote: >> >> > You are assuming that the strangeness of the request is about 'tech' >> > [engineering/tech existed centuries before computers] >> > >> > Do remember one can be a tech-{student,professional} without >> > - ever having encountered free-software >> > - internet/USENET culture >> > >> > ? from which pov the request would not look so odd >> >> So you're suggesting that rather than being unwilling to google for >> "Download Python" because he doesn't understand free software culture, the >> OP is unwilling to google for "Download Python" because he thinks it is >> proprietary software and wants a bunch of strangers on the Internet to send >> him a pirate copy? >> >> I'm not entirely sure that's better... > > Dunno anything about OP so no 'suggesting'? Rustom, you LITERALLY suggested that the OP could be a tech student who isn't familiar with free-software and that would explain the "strangeness" of the request. What other interpretation of your words quoted above is reasonable? You suggested that if he wasn't familiar with free software, his request that people send him a copy of Python wouldn't look so odd. Okay, if Python weren't free software, it would be non-free software, and you are saying that it wouldn't look so odd for somebody to join a mailing list and request a bunch of strangers to gift him a copy of non-free software. That seems pretty odd to me. Laziness I get. Being so naive as to expect that someone will purchase a legal copy and give it to a perfect stranger out of the goodness of their heart, I don't think is so believable. But maybe that happens all the time in India *shrug* If the OP was as ignorant of software (whether free or not) and the Internet as your defence of him makes out, I would expect his question would have been "How do I get the Python? software" rather than "Send me the Python software". The OP clearly understands that Python is something that will run on his computer, that it can be sent to him, that there are people willing and able to do so, and he understands the internet well enough to expect those people will be able to contact him without his needing to explicitly give them his address. > I did hint one point above which can be restated more explicitly. > > An engineering degree (aka ?B.Tech?) can be in any of > - IT, CS, Computer Engineering etc > - aeronautics, civil, electrical, mechanical? classical, non-computer > related - bioinformatics, statistics, "scientific computing" etc ie > heavy-duty *users* > of computers > > For the latter two classes it would be normal/natural for the student to > have little knowledge/interest in computer-related stuff except as a user. None of this is the slightest bit relevant. The OP explicitly said that he wants to learn Python. He's not some random civil engineering or biology student, he is a tech student who wants to learn to program in Python. And the idea that "users of computers" don't know how to use Google is ludicrous. Google hasn't become one of the biggest tech companies in the world because only a tiny number of Open Source programmers use it. It is 2017, not 1997, and Google is ubiquitous. Even my dad knows about Google and he doesn't even have a computer, not even a smart phone. [...] > ie "unwilling to google" could well be "ignorant of google > (usage/practices)" Do consider the possibility that a student could be a > non-owner of a computer and/or studying in a college in a poor/non networked > location. Your hypothetical that the OP is a tech student who has barely used a computer before and doesn't know about Google but nevertheless knows about Python (which is about a million times less well-known) *and* is internet-savvy enough to send an email to this mailing list is such a remote possibility that I don't know why I'm even responding to it. [...] > IOW I would wish Ethan's "control yourself" to be imperated ? preferably > by oneself, if not then forcibly. > And especially when the vitriol is flung at a first-time poster. KM also appears to be a first-time poster. And after all the critical attacks he's received, I doubt he'll hang around. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From random832 at fastmail.com Wed Dec 6 11:28:22 2017 From: random832 at fastmail.com (Random832) Date: Wed, 06 Dec 2017 11:28:22 -0500 Subject: Politeness (was: we want python software) In-Reply-To: <5a28185f$0$2067$b1db1813$d948b532@news.astraweb.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a27c7eb$0$2066$b1db1813$d948b532@news.astraweb.com> <7dd1b4ae-3f38-4be7-8c08-0f54097e5dca@googlegroups.com> <5a28185f$0$2067$b1db1813$d948b532@news.astraweb.com> Message-ID: <1512577702.3983525.1196161760.68548477@webmail.messagingengine.com> On Wed, Dec 6, 2017, at 11:18, Steve D'Aprano wrote: > You suggested that if he wasn't familiar with free software, his > request that people send him a copy of Python wouldn't look so odd. > Okay, if Python weren't free software, it would be non-free software, > and you are saying that it wouldn't look so odd for somebody to join a > mailing list and request a bunch of strangers to gift him a copy of > non-free software. The third possibility is that he believes that this list is official in some corporate sense, that if he asks for the software and it is not free he will receive a price quote. From steve+python at pearwood.info Wed Dec 6 11:33:14 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Dec 2017 03:33:14 +1100 Subject: we want python software References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Dec 2017 04:54 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 4:27 PM, km wrote: >> Remember that you are wasting time of lakhs of python subscribers by >> asking such dumb questions being tech students. You people can Google and >> watch movies / songs online and you can't find how to download and install >> python ? That's ridiculous! >> > > This attack is unwarranted. Please don't set fire to people simply > because they asked a question like this. I'm going to defend KM (srikrishnamohan) -- his comments were not "an attack", they are a well-deserved criticism of a *tech student* who apparently made zero effort to find out how to download Python before asking others to do it for him. I'm sorry for the length of this post. It is trivially easy to sink the boots in and tell KM off for his blunt criticism of the OP's request. But in the face of this hostile environment (out of the nine people who responded to this thread, no fewer than three have piled onto KM to tell him off), it isn't so easy to get through the message of why we shouldn't always coddle people asking questions like that asked by the OP, and why KM's response was tough but fair. It's not enough to merely shout back "No, you're wrong!", hence the length of this reply. Its been a while since I've seen anyone here link to "How to ask questions the smart way": http://catb.org/~esr/faqs/smart-questions.html and quote this: When you ask your question, display the fact that you have done these things [try to find an answer] first; this will help establish that you're not being a lazy sponge and wasting people's time. (And more importantly: *you might learn something* by trying to solve your own problem.) And yes, I'm aware of the irony of me taking this position only a couple of posts after I asked the group to run some code for me without explaining why I couldn't run it myself.[1] The difference is, I have many years of answering other people's questions, I'm well known here, and I have a proven track record of not being a lazy sponge. But if somebody wants to take me to task for not explicitly stating why I wasn't running the code myself, I will preemptively take it in good grace and accept the criticism. Mea culpa. How likely is it that somebody who is tech-savvy enough to sign up and post to the Python-List mailing list is not savvy enough to have heard of google or to have thought of search terms "download Python"? https://duckduckgo.com/html/?q=download%20python We're not talking about a young child, or some other barely computer literate person, but somebody studying for a Bachelor of Technology in India. Offering criticism is not attacking somebody. Not even tough criticism. And if you are thinking that it is, well, consider the beam in your own eye before the mote in KM's. You have just "attacked" (criticised) KM quite harshly, accusing him of making an "unwarranted" attack (I think it was very warranted), and using a metaphor which has particular cultural and colonial associations in India and neighbouring countries which we Westerners should be wary of making without good cause.[2] When somebody mildly breaches social norms, even the norms of a tech forum, mild shaming is often an effective method of enforcement. I'm not saying that the OP should be doxxed, his family and employer harassed, ripped apart on social media, but KM telling him off for wasting people's time seems fair to me. We can assume that the OP isn't a two year old. He should know better, and we ought to expect more from him. Its not a crime if he doesn't, but we don't have to molly-coddle him either. Consider your bible: a soft answer turns away wrath. But the bible never says that the wrath wasn't justified in the first place. KM is clearly angry at the OP's behaviour, hence his strong words. We should balance our concern about driving away newbies like the OP with some concern about the justified anger at needy, entitled, demanding people who take, take, take and never give back. "Smart Questions" (above) is not just good advice, it is also a set of social norms, and the OP violated them. And again, consider your own beam: what you are complaining about KM doing to the OP, is exactly what you, Ethan and others are attempting to do to KM. You consider KM's actions to have violated *your* social norm of "be nice" and consequently you are trying to shame KM into changing his behaviour to meet those norms, by chastising him and telling him off for supposedly attacking the OP, for being condescending, for being hateful. Ironically, it appears that both KM and the OP are newbies. Aren't we supposed to be more welcoming to newbies? > You can be far more courteous > than this, even if you refuse to help. Particularly, the "you people" > sounds like a blanket statement, which is almost certainly not useful > to the discussion. I think that given both posters appear to be Indian, perhaps there's some cultural baggage that we outsiders aren't privy too. I might guess that it could have something to do with the (allegedly) high incidence of academic dishonesty and cheating amongst India's students, many students feeling that they are entitled to pass courses without doing any work or studying. http://beta.latimes.com/world/asia/la-fg-c1-india-cheating-20140416-m-story.html You (and a few others) have "attacked" (criticised) someone who shows signs of being concerned about the quality of discussion in this forum, while encouraging somebody who shows signs of possibly becoming an entitled, needy, demanding Help Vampire: http://www.skidmore.edu/~pdwyer/e/eoc/help_vampire.htm Now to be fair to the OP, Jyothiswaroop Reddy, may not realise he is breaking a social norm for a tech group, perhaps due to cluelessness, inexperience, or a lifetime of entitlement where his every need has been done for him. I'm not saying he should be shunned. But a swift kick up the (virtual) behind is a wake-up call. KM's comments were tough but fair: Jyothiswaroop *is* wasting people's time with a simple problem that he should be capable of solving himself, or at least making an attempt to solve it himself, and it doesn't require much nous to google for "Download Python" before asking for help. In our urge to be inclusive, we forget that it is just basic simple politeness that before asking strangers for a favour, we should make an honest attempt to solve the problem ourselves. If you don't, but still expect others to solve your problems for you, that's a violation of some pretty deeply embedded cultural norms about social cheating (taking advantage of others without giving back). Those norms are so deeply embedded they might even be biological. I can completely understand KM's apparant anger. The bottom line is, I disagree that KM's posts were out of line and more worthy of chastisement than Jyothiswaroop's post. [1] I cannot compile Python 3.6 or better on any of the computers I have access to at the moment -- although it's probably time for me to try again in case those dependency problems have been fixed. [2] Given the historical practice of suttee (sati) and the questions it raises about colonial imperialism[3], as well as the still-current practice of dowry murder[4] and even more vicious crimes[5] in India, accusing KM of setting another person on fire (even metaphorically) is not something I'd do so casually. [3] http://www.victorianweb.org/history/empire/india/suttee.html [4] https://preview.tinyurl.com/y86vglvm [5] https://preview.tinyurl.com/hnaa29w -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From gheskett at shentel.net Wed Dec 6 11:42:22 2017 From: gheskett at shentel.net (Gene Heskett) Date: Wed, 6 Dec 2017 11:42:22 -0500 Subject: Politeness (was: we want python software) In-Reply-To: <1512577702.3983525.1196161760.68548477@webmail.messagingengine.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a28185f$0$2067$b1db1813$d948b532@news.astraweb.com> <1512577702.3983525.1196161760.68548477@webmail.messagingengine.com> Message-ID: <201712061142.22347.gheskett@shentel.net> On Wednesday 06 December 2017 11:28:22 Random832 wrote: > On Wed, Dec 6, 2017, at 11:18, Steve D'Aprano wrote: > > You suggested that if he wasn't familiar with free software, his > > request that people send him a copy of Python wouldn't look so odd. > > Okay, if Python weren't free software, it would be non-free > > software, and you are saying that it wouldn't look so odd for > > somebody to join a mailing list and request a bunch of strangers to > > gift him a copy of non-free software. > > The third possibility is that he believes that this list is official > in some corporate sense, that if he asks for the software and it is > not free he will receive a price quote. Sadly, that an attitude even college profs don't get, having gotten their sheepskin with only M$ stuff, that something could be both free and good. It's a concept that makes no sense to the teachers, so of course they don't teach it either. Hell of a way to run a train. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From gheskett at shentel.net Wed Dec 6 11:47:07 2017 From: gheskett at shentel.net (Gene Heskett) Date: Wed, 6 Dec 2017 11:47:07 -0500 Subject: we want python software In-Reply-To: <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> Message-ID: <201712061147.07438.gheskett@shentel.net> On Wednesday 06 December 2017 11:33:14 Steve D'Aprano wrote: > On Wed, 6 Dec 2017 04:54 pm, Chris Angelico wrote: > > On Wed, Dec 6, 2017 at 4:27 PM, km wrote: > >> Remember that you are wasting time of lakhs of python subscribers > >> by asking such dumb questions being tech students. You people can > >> Google and watch movies / songs online and you can't find how to > >> download and install python ? That's ridiculous! > > > > This attack is unwarranted. Please don't set fire to people simply > > because they asked a question like this. > > I'm going to defend KM (srikrishnamohan) -- his comments were not "an > attack", they are a well-deserved criticism of a *tech student* who > apparently made zero effort to find out how to download Python before > asking others to do it for him. > > I'm sorry for the length of this post. It is trivially easy to sink > the boots in and tell KM off for his blunt criticism of the OP's > request. But in the face of this hostile environment (out of the nine > people who responded to this thread, no fewer than three have piled > onto KM to tell him off), it isn't so easy to get through the message > of why we shouldn't always coddle people asking questions like that > asked by the OP, and why KM's response was tough but fair. > > It's not enough to merely shout back "No, you're wrong!", hence the > length of this reply. > > > Its been a while since I've seen anyone here link to "How to ask > questions the smart way": > > http://catb.org/~esr/faqs/smart-questions.html > > > and quote this: > > > When you ask your question, display the fact that you have done > these things [try to find an answer] first; this will help > establish that you're not being a lazy sponge and wasting people's > time. > > > (And more importantly: *you might learn something* by trying to solve > your own problem.) > > And yes, I'm aware of the irony of me taking this position only a > couple of posts after I asked the group to run some code for me > without explaining why I couldn't run it myself.[1] > > The difference is, I have many years of answering other people's > questions, I'm well known here, and I have a proven track record of > not being a lazy sponge. But if somebody wants to take me to task for > not explicitly stating why I wasn't running the code myself, I will > preemptively take it in good grace and accept the criticism. Mea > culpa. > > How likely is it that somebody who is tech-savvy enough to sign up and > post to the Python-List mailing list is not savvy enough to have heard > of google or to have thought of search terms "download Python"? > > https://duckduckgo.com/html/?q=download%20python > > We're not talking about a young child, or some other barely computer > literate person, but somebody studying for a Bachelor of Technology in > India. > > Offering criticism is not attacking somebody. Not even tough > criticism. > > And if you are thinking that it is, well, consider the beam in your > own eye before the mote in KM's. You have just "attacked" (criticised) > KM quite harshly, accusing him of making an "unwarranted" attack (I > think it was very warranted), and using a metaphor which has > particular cultural and colonial associations in India and > neighbouring countries which we Westerners should be wary of making > without good cause.[2] > > When somebody mildly breaches social norms, even the norms of a tech > forum, mild shaming is often an effective method of enforcement. I'm > not saying that the OP should be doxxed, his family and employer > harassed, ripped apart on social media, but KM telling him off for > wasting people's time seems fair to me. We can assume that the OP > isn't a two year old. He should know better, and we ought to expect > more from him. Its not a crime if he doesn't, but we don't have to > molly-coddle him either. > > Consider your bible: a soft answer turns away wrath. But the bible > never says that the wrath wasn't justified in the first place. KM is > clearly angry at the OP's behaviour, hence his strong words. We should > balance our concern about driving away newbies like the OP with some > concern about the justified anger at needy, entitled, demanding people > who take, take, take and never give back. "Smart Questions" (above) is > not just good advice, it is also a set of social norms, and the OP > violated them. > > And again, consider your own beam: what you are complaining about KM > doing to the OP, is exactly what you, Ethan and others are attempting > to do to KM. You consider KM's actions to have violated *your* social > norm of "be nice" and consequently you are trying to shame KM into > changing his behaviour to meet those norms, by chastising him and > telling him off for supposedly attacking the OP, for being > condescending, for being hateful. > > Ironically, it appears that both KM and the OP are newbies. Aren't we > supposed to be more welcoming to newbies? > > > You can be far more courteous > > than this, even if you refuse to help. Particularly, the "you > > people" sounds like a blanket statement, which is almost certainly > > not useful to the discussion. > > I think that given both posters appear to be Indian, perhaps there's > some cultural baggage that we outsiders aren't privy too. I might > guess that it could have something to do with the (allegedly) high > incidence of academic dishonesty and cheating amongst India's > students, many students feeling that they are entitled to pass courses > without doing any work or studying. > > http://beta.latimes.com/world/asia/la-fg-c1-india-cheating-20140416-m- >story.html > > > You (and a few others) have "attacked" (criticised) someone who shows > signs of being concerned about the quality of discussion in this > forum, while encouraging somebody who shows signs of possibly becoming > an entitled, needy, demanding Help Vampire: > > http://www.skidmore.edu/~pdwyer/e/eoc/help_vampire.htm > > Now to be fair to the OP, Jyothiswaroop Reddy, may not realise he is > breaking a social norm for a tech group, perhaps due to cluelessness, > inexperience, or a lifetime of entitlement where his every need has > been done for him. I'm not saying he should be shunned. > > But a swift kick up the (virtual) behind is a wake-up call. KM's > comments were tough but fair: Jyothiswaroop *is* wasting people's time > with a simple problem that he should be capable of solving himself, or > at least making an attempt to solve it himself, and it doesn't require > much nous to google for "Download Python" before asking for help. > > In our urge to be inclusive, we forget that it is just basic simple > politeness that before asking strangers for a favour, we should make > an honest attempt to solve the problem ourselves. If you don't, but > still expect others to solve your problems for you, that's a violation > of some pretty deeply embedded cultural norms about social cheating > (taking advantage of others without giving back). Those norms are so > deeply embedded they might even be biological. I can completely > understand KM's apparant anger. > > The bottom line is, I disagree that KM's posts were out of line and > more worthy of chastisement than Jyothiswaroop's post. > > > > > > [1] I cannot compile Python 3.6 or better on any of the computers I > have access to at the moment -- although it's probably time for me to > try again in case those dependency problems have been fixed. > > [2] Given the historical practice of suttee (sati) and the questions > it raises about colonial imperialism[3], as well as the still-current > practice of dowry murder[4] and even more vicious crimes[5] in India, > accusing KM of setting another person on fire (even metaphorically) is > not something I'd do so casually. > > [3] http://www.victorianweb.org/history/empire/india/suttee.html > > [4] https://preview.tinyurl.com/y86vglvm > > [5] https://preview.tinyurl.com/hnaa29w > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and > sure enough, things got worse. +100 Steve, spot on IOW. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From kpavan30 at gmail.com Wed Dec 6 11:48:52 2017 From: kpavan30 at gmail.com (pavan kopparthi) Date: Wed, 6 Dec 2017 22:18:52 +0530 Subject: Fwd: pip3 file in Scripts folder is missing - Python installation - Tensor flow upgrade In-Reply-To: References: Message-ID: Hi, Installed Python 3.6.3 Amd64 in Windows 10 OS. Want to install Tensor flow using native pip as suggested... C:\> *pip3 install --upgrade tensorflow* But, observed that pip3 file in Scripts folder is missing. Also, Scripts folder is empty. -- Reg, Pavan Kumar K Virus-free. www.avg.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From nad at python.org Wed Dec 6 11:57:56 2017 From: nad at python.org (Ned Deily) Date: Wed, 6 Dec 2017 11:57:56 -0500 Subject: [Python-Dev] [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available for testing In-Reply-To: References: Message-ID: <1EE02BC9-F21B-4979-B312-9C08EAFD2200@python.org> On Dec 6, 2017, at 07:30, Steve Holden wrote: > In your role as a representative of the many fine release managers Python has had over the years I'd like to thank you for continuing to make high-quality software available to a large and growing community. And thanks to everyone who contributes to Python so the majority just get to enjoy it. Thank you for your kind words, Steve, but, as you know, in our roles as release managers, we are just the conductors, making sure that the release trains get scheduled and arrive at their station stops on time. Without the enormous contributions of all core developers and an increasing body of other contributors, all volunteering their time, the trains would be empty. For those of you who might be tempted to contribute your time to working on Python, feel free to hop on board: https://devguide.python.org. Or if you or perhaps your organization would like to help the Python community in other ways, consider supporting the Python Software Foundation: https://www.python.org/psf-landing/. -- Ned Deily nad at python.org -- [] From rosuav at gmail.com Wed Dec 6 12:12:44 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Dec 2017 04:12:44 +1100 Subject: Python-list Digest, Vol 171, Issue 7 In-Reply-To: References: <1512572378l.24117414l.0l@psu.edu> Message-ID: On Thu, Dec 7, 2017 at 3:56 AM, Dennis Lee Bieber wrote: > Granted, the statistics module in newer Python releases makes the > entire assignment trivial... > > ClgubaJva 3.5.3 (qrsnhyg, Wha 26 2017, 16:17:54) [ZFP i.1900 64 ovg > (NZQ64)] ba jva32. Is this from the Function Call of Cthulu? ChrisA From ian.g.kelly at gmail.com Wed Dec 6 12:14:32 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Dec 2017 10:14:32 -0700 Subject: Politeness (was: we want python software) In-Reply-To: <201712061142.22347.gheskett@shentel.net> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a28185f$0$2067$b1db1813$d948b532@news.astraweb.com> <1512577702.3983525.1196161760.68548477@webmail.messagingengine.com> <201712061142.22347.gheskett@shentel.net> Message-ID: On Wed, Dec 6, 2017 at 9:42 AM, Gene Heskett wrote: > On Wednesday 06 December 2017 11:28:22 Random832 wrote: >> The third possibility is that he believes that this list is official >> in some corporate sense, that if he asks for the software and it is >> not free he will receive a price quote. > > Sadly, that an attitude even college profs don't get, having gotten their > sheepskin with only M$ stuff, that something could be both free and > good. > > It's a concept that makes no sense to the teachers, so of course they > don't teach it either. Hell of a way to run a train. Depends where you went to school, probably. The CS department at my college was all over using Linux and free software. From gheskett at shentel.net Wed Dec 6 12:56:14 2017 From: gheskett at shentel.net (Gene Heskett) Date: Wed, 6 Dec 2017 12:56:14 -0500 Subject: Politeness (was: we want python software) In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <201712061142.22347.gheskett@shentel.net> Message-ID: <201712061256.14896.gheskett@shentel.net> On Wednesday 06 December 2017 12:14:32 Ian Kelly wrote: > On Wed, Dec 6, 2017 at 9:42 AM, Gene Heskett wrote: > > On Wednesday 06 December 2017 11:28:22 Random832 wrote: > >> The third possibility is that he believes that this list is > >> official in some corporate sense, that if he asks for the software > >> and it is not free he will receive a price quote. > > > > Sadly, that an attitude even college profs don't get, having gotten > > their sheepskin with only M$ stuff, that something could be both > > free and good. > > > > It's a concept that makes no sense to the teachers, so of course > > they don't teach it either. Hell of a way to run a train. > > Depends where you went to school, probably. The CS department at my > college was all over using Linux and free software. Then why not promote that seat of higher learning by naming it? Word of mouth publicity is the best kind. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From grant.b.edwards at gmail.com Wed Dec 6 13:04:17 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 6 Dec 2017 18:04:17 +0000 (UTC) Subject: we want python software References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On 2017-12-05, Igor Korot wrote: > Hi, Tony, > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: >> On 05/12/17 16:55, Igor Korot wrote: >>> Hi, >>> >>> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy >>> wrote: >>>> Sir, >>>> I am b.tech student I would like to learn python. So please send the python software. >>> Sorry, we don't send anything. You will have to go get it yourself. -) >>> >> Well, at least try to be helpful: >> https://www.python.org/downloads/ > > This is LMGIFY. > If they say they are tech students - they should know how to work with Google. Yea, I've always been baffled by requests like that. How is somebody able figure out how to post a question to the mailing list, but is unable to type "Install Python" into Google? -- Grant Edwards grant.b.edwards Yow! Now KEN and BARBIE at are PERMANENTLY ADDICTED to gmail.com MIND-ALTERING DRUGS ... From __peter__ at web.de Wed Dec 6 13:11:22 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Dec 2017 19:11:22 +0100 Subject: Python-list Digest, Vol 171, Issue 7 References: <1512572378l.24117414l.0l@psu.edu> Message-ID: Chris Angelico wrote: > On Thu, Dec 7, 2017 at 3:56 AM, Dennis Lee Bieber > wrote: >> Granted, the statistics module in newer Python releases makes the >> entire assignment trivial... >> >> ClgubaJva 3.5.3 (qrsnhyg, Wha 26 2017, 16:17:54) [ZFP i.1900 64 ovg >> (NZQ64)] ba jva32. > > Is this from the Function Call of Cthulu? > > ChrisA Perhaps. It is also rot13. Fun fact: in Python 2 you could run an actual session using rot13: $ PYTHONIOENCODING=rot13 python Python 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> vzcbeg fgngvfgvpf >>> vzcbeg enaqbz >>> aEbyyf = 50 >>> ebyyf = [enaqbz.enaqvag(1, 6) sbe wax va enatr(aEbyyf)] >>> fgngvfgvpf.zrna(ebyyf) 3.5 From rosuav at gmail.com Wed Dec 6 13:38:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Dec 2017 05:38:36 +1100 Subject: we want python software In-Reply-To: <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Dec 7, 2017 at 3:33 AM, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 04:54 pm, Chris Angelico wrote: > >> On Wed, Dec 6, 2017 at 4:27 PM, km wrote: >>> Remember that you are wasting time of lakhs of python subscribers by >>> asking such dumb questions being tech students. You people can Google and >>> watch movies / songs online and you can't find how to download and install >>> python ? That's ridiculous! >>> >> >> This attack is unwarranted. Please don't set fire to people simply >> because they asked a question like this. > > I'm going to defend KM (srikrishnamohan) -- his comments were not "an attack", > they are a well-deserved criticism of a *tech student* who apparently made > zero effort to find out how to download Python before asking others to do it > for him. > > I'm sorry for the length of this post. It is trivially easy to sink the boots > in and tell KM off for his blunt criticism of the OP's request. But in the > face of this hostile environment (out of the nine people who responded to > this thread, no fewer than three have piled onto KM to tell him off), it > isn't so easy to get through the message of why we shouldn't always coddle > people asking questions like that asked by the OP, and why KM's response was > tough but fair. I was the first to tell KM off, so I wasn't "piling on". The others may or may not have been aware of my post at the time they made theirs. It's easy to look at the end of a thread and say that people were piling on, but usually that isn't the intention (how often do you deliberately set out to make a thread nothing but attacks on the same person?). > How likely is it that somebody who is tech-savvy enough to sign up and post to > the Python-List mailing list is not savvy enough to have heard of google or > to have thought of search terms "download Python"? > > https://duckduckgo.com/html/?q=download%20python > > We're not talking about a young child, or some other barely computer literate > person, but somebody studying for a Bachelor of Technology in India. > > Offering criticism is not attacking somebody. Not even tough criticism. > > And if you are thinking that it is, well, consider the beam in your own eye > before the mote in KM's. You have just "attacked" (criticised) KM quite > harshly, accusing him of making an "unwarranted" attack (I think it was very > warranted), and using a metaphor which has particular cultural and colonial > associations in India and neighbouring countries which we Westerners should > be wary of making without good cause.[2] I, on the other hand, think that it was indeed unwarranted. 1) The OP makes a lazy post 2) KM responds harshly 3) I respond, criticizing the harshness of KM's response 4) You respond, criticizing the harshness of my response. While I absolutely agree with you that the OP should have done more research before asking, I don't think that KM's attack was fully warranted - at least, not in the way it was made. The text is still above, in the quoted section; do you really think that that tone is justified in response to a person's first post? That said, though, I was wrong to use the metaphor I did. Mea culpa. I did not think of the implications to people in India. KM, please accept my apology for this. > In our urge to be inclusive, we forget that it is just basic simple politeness > that before asking strangers for a favour, we should make an honest attempt > to solve the problem ourselves. If you don't, but still expect others to > solve your problems for you, that's a violation of some pretty deeply > embedded cultural norms about social cheating (taking advantage of others > without giving back). Those norms are so deeply embedded they might even be > biological. I can completely understand KM's apparant anger. > > The bottom line is, I disagree that KM's posts were out of line and more > worthy of chastisement than Jyothiswaroop's post. I would say they were comparably out of line, similarly worthy of chastisement. Both of them were wrong. I'd like to think that my response to KM was less wrong than either of the preceding posts, but if you want to assert that I was also just as wrong, I'll accept that (there were parts of it which I should definitely have thought more about before sending). Bottom line is, I still think KM was wrong to use the tone he did. ChrisA From rosuav at gmail.com Wed Dec 6 14:04:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Dec 2017 06:04:20 +1100 Subject: rot13 as I/O encoding (was Re: Python-list Digest, Vol 171, Issue 7) Message-ID: On Thu, Dec 7, 2017 at 5:11 AM, Peter Otten <__peter__ at web.de> wrote: > Chris Angelico wrote: > >> On Thu, Dec 7, 2017 at 3:56 AM, Dennis Lee Bieber >> wrote: >>> Granted, the statistics module in newer Python releases makes the >>> entire assignment trivial... >>> >>> ClgubaJva 3.5.3 (qrsnhyg, Wha 26 2017, 16:17:54) [ZFP i.1900 64 ovg >>> (NZQ64)] ba jva32. >> >> Is this from the Function Call of Cthulu? >> >> ChrisA > > Perhaps. It is also rot13. I know, but it looked hilarious. :) > Fun fact: in Python 2 you could run an actual session using rot13: > > $ PYTHONIOENCODING=rot13 python > Python 2.7.6 (default, Nov 23 2017, 15:49:48) > [GCC 4.8.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> vzcbeg fgngvfgvpf >>>> vzcbeg enaqbz >>>> aEbyyf = 50 >>>> ebyyf = [enaqbz.enaqvag(1, 6) sbe wax va enatr(aEbyyf)] >>>> fgngvfgvpf.zrna(ebyyf) > 3.5 > Curiously, that doesn't seem to affect everything. >>> znc(beq, "abcd") [97, 98, 99, 100] According to "python --help", that env var should be setting the encoding for all three standard streams. So I would expect that the actual string would contain "nopq", which - when mapped through ord() - should be [110, 111, 112, 113]. Oh. I'm an idiot. Or rather, I've gotten so used to Python 3 that I forget how Python 2 works... >>> znc(beq, h"abcd") [110, 111, 112, 113] And that's what I was expecting to see. Except that... variable names get decoded. And error messages don't. >>> abcd Traceback (most recent call last): File "", line 1, in NameError: name 'nopq' is not defined Curiouser and curiouser! >>> cevag("abcd") abcd >>> cevag(h"abcd") abcd >>> "abcd" 'abcd' >>> h"abcd" u'nopq' All tested using Python 2.7.13 on Debian GNU/Linux, if that makes any difference (I doubt that it will, but you never know). ChrisA From rantingrickjohnson at gmail.com Wed Dec 6 15:11:37 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 12:11:37 -0800 (PST) Subject: Politeness (was: we want python software) In-Reply-To: <5a28185f$0$2067$b1db1813$d948b532@news.astraweb.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a27c7eb$0$2066$b1db1813$d948b532@news.astraweb.com> <7dd1b4ae-3f38-4be7-8c08-0f54097e5dca@googlegroups.com> <5a28185f$0$2067$b1db1813$d948b532@news.astraweb.com> Message-ID: <00fd1562-a7cb-4d26-aad8-ffc028465902@googlegroups.com> Steve D'Aprano wrote: [...] > And yes, I'm aware of the irony of me taking this position > only a couple of posts after I asked the group to run some > code for me without explaining why I couldn't run it > myself.[1] [...] But if somebody wants to take me to task > for Your virtue signaling here, whilst quite impressive indeed, won't distract from that over-the-knee-spanking you received from me in the "Slicing Thread" started by Jason Maldonis. But uh, nice try ;-) -- https://plus.google.com/u/0/collection/UAv9UE From ian.g.kelly at gmail.com Wed Dec 6 15:33:40 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Dec 2017 13:33:40 -0700 Subject: Politeness (was: we want python software) In-Reply-To: <201712061256.14896.gheskett@shentel.net> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <201712061142.22347.gheskett@shentel.net> <201712061256.14896.gheskett@shentel.net> Message-ID: On Wed, Dec 6, 2017 at 10:56 AM, Gene Heskett wrote: > On Wednesday 06 December 2017 12:14:32 Ian Kelly wrote: > >> On Wed, Dec 6, 2017 at 9:42 AM, Gene Heskett > wrote: >> > On Wednesday 06 December 2017 11:28:22 Random832 wrote: >> >> The third possibility is that he believes that this list is >> >> official in some corporate sense, that if he asks for the software >> >> and it is not free he will receive a price quote. >> > >> > Sadly, that an attitude even college profs don't get, having gotten >> > their sheepskin with only M$ stuff, that something could be both >> > free and good. >> > >> > It's a concept that makes no sense to the teachers, so of course >> > they don't teach it either. Hell of a way to run a train. >> >> Depends where you went to school, probably. The CS department at my >> college was all over using Linux and free software. > > Then why not promote that seat of higher learning by naming it? Word of > mouth publicity is the best kind. Earlham College. From bazthelinuxguy at gmail.com Wed Dec 6 15:59:24 2017 From: bazthelinuxguy at gmail.com (Bryan Zimmer) Date: Wed, 6 Dec 2017 14:59:24 -0600 Subject: Module _socket not found in python3.6 "No module named _socket" Message-ID: I have been getting this message, "No module named '_socket'", since I installed python 3.6, about two months ago. My platform is Slackware Linux (14.2). I compiled python3.6 from source, because binary python packages aren't distributed by python.org for Linux. I have the same experience on multiple Slackware computers, not just one. Actually, this problem hits the 64-bit distribution. I have a 32-bit Slackware box that has no trouble with _socket. I can not 'import socket' into a program, nor can I use 'pip' to install modules. These require the _socket module, which doesn't exist. What does exist is a shared library object called '_ socket.cpython-36m-i386-linux-gnu.so'. This looks tantalizingly like the missing module, but it is for a 32-bit architecture. This is not the only missing module for 64-bit Slackware Linux. I can not find a trace of the 'math' module, which, again, works fine on my 32-bit computer. I am far from an expert on installing python modules, so I am asking for advice on how I should proceed to find these modules. Thanks in advance. "BryGuy" (my handle on linuxquestions.org) From python at bladeshadow.org Wed Dec 6 16:11:01 2017 From: python at bladeshadow.org (Python) Date: Wed, 6 Dec 2017 15:11:01 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> References: <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> Message-ID: <20171206211101.GE30413@bladeshadow.org> On Tue, Dec 05, 2017 at 06:23:04PM -0800, Rick Johnson wrote: > [bunch of old, irrelevant context snipped] > > item = seq[n:n+1] > > if item: > > process(item) > > else: > > do_without_item() > > When Python follows a logic clause like a train skating > along a set of railroad tracks, and finds itself in a *GHOST > TOWN*, that's not an action -- "Steve-o" -- it's a non- > action. Geez, seriously? The snippet is purely academic, obviously not a complete or useful program, intended to illustrate that python can take two different branches depending on whether or not the slicing operation yeilded a non-empty container, using uncomplicated syntax. It effectively serves that purpose. Moreover, in order for the example to make sense, we must assume the existence of unspecified code: The variables need to have been initialized previously, or else the snippet is non-functional. The if conditional would never be reached. We can as easily assume that the hypothetical example continues with other, unspecified code, and that the equally unspecified do_without_item() actually does something, which renders your argument completely invalid and pointless. The whole thing is entirely academic; continuing to argue this is an utter waste of time and bandwidth. From formisc at gmail.com Wed Dec 6 16:19:12 2017 From: formisc at gmail.com (Andrew Z) Date: Wed, 6 Dec 2017 16:19:12 -0500 Subject: Politeness (was: we want python software) In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <201712061142.22347.gheskett@shentel.net> <201712061256.14896.gheskett@shentel.net> Message-ID: Looks like the longest thread for past 2 months. Should we push it to be the longest for 2017? :) On Dec 6, 2017 15:34, "Ian Kelly" wrote: > On Wed, Dec 6, 2017 at 10:56 AM, Gene Heskett > wrote: > > On Wednesday 06 December 2017 12:14:32 Ian Kelly wrote: > > > >> On Wed, Dec 6, 2017 at 9:42 AM, Gene Heskett > > wrote: > >> > On Wednesday 06 December 2017 11:28:22 Random832 wrote: > >> >> The third possibility is that he believes that this list is > >> >> official in some corporate sense, that if he asks for the software > >> >> and it is not free he will receive a price quote. > >> > > >> > Sadly, that an attitude even college profs don't get, having gotten > >> > their sheepskin with only M$ stuff, that something could be both > >> > free and good. > >> > > >> > It's a concept that makes no sense to the teachers, so of course > >> > they don't teach it either. Hell of a way to run a train. > >> > >> Depends where you went to school, probably. The CS department at my > >> college was all over using Linux and free software. > > > > Then why not promote that seat of higher learning by naming it? Word of > > mouth publicity is the best kind. > > Earlham College. > -- > https://mail.python.org/mailman/listinfo/python-list > From python at bladeshadow.org Wed Dec 6 16:22:21 2017 From: python at bladeshadow.org (Python) Date: Wed, 6 Dec 2017 15:22:21 -0600 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> Message-ID: <20171206212221.GF30413@bladeshadow.org> On Wed, Dec 06, 2017 at 10:35:58AM +1100, Steve D'Aprano wrote: > On Tue, 5 Dec 2017 07:58 pm, Lawrence D?Oliveiro wrote: > > > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: > >> > >> Sounds like your OS file associations are all botched-up ... > > > > Linux doesn?t do ?OS file associations?. > > > Then how does my Linux box know that when I double-click on a text file, it > launches kwrite rather than (say) the Gimp or LibreOffice? The answer to that is (sadly) complicated. How it knows indeed depends on the context of the click, what desktop environment you're using, what application(s) you're using, and what configurations you've made to those things to address any file associations. There isn't one answer. On the same system, the answer could well be completely different for any two users, or even for the same user, given different application contexts. The latter is less true than it used to be, but still true nonetheless. Granted, this isn't a very useful answer, but it's the only one you can give that is certainly correct, without more context. From tjreedy at udel.edu Wed Dec 6 16:43:35 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Dec 2017 16:43:35 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> References: <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> Message-ID: On 12/5/2017 9:23 PM, Rick Johnson wrote: > Steve D'Aprano wrote: > > [...] > >> You've already been told that there's no indication or >> reason to believe that it is a non-action. You've already >> been given at least one possible action. It isn't a non- >> action, it is two distinct actions: >> >> - the action you take when the slice is non-empty; >> >> - the action you take when the slice is empty. > > When Python follows a logic clause like a train skating > along a set of railroad tracks, and finds itself in a *GHOST > TOWN*, that's not an action -- "Steve-o" -- it's a non- > action. Rick, cut the crap. If you do not understand that 'something_else()' != 'pass', re-read the tutorial. --- The OP asked: "Why is slicing 'forgiving'?" The current behavior could be interpreted as 'letting errors pass silently'. It would be if slicing meant 'give me exactly the length stop-start subsequence from start to stop (or raise)'. But slicing actually means 'give me whatever subsequence exists between start and stop'. My examples attempted to show why this looser definition of slicing is *useful*. The focus of the third example was entirely on the condition, not the alternative actions. (Reminder: either action can be the if-action, and the other the else-action, depending on how the condition is written.) I should have mentioned, and others did, that the OP can write a custom __getitem__ method that implements stricter slicing for instances of a custom class. I think we have collectively answered the OP's question quite well. -- Terry Jan Reedy From rosuav at gmail.com Wed Dec 6 16:48:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Dec 2017 08:48:31 +1100 Subject: Module _socket not found in python3.6 "No module named _socket" In-Reply-To: References: Message-ID: On Thu, Dec 7, 2017 at 7:59 AM, Bryan Zimmer wrote: > I have been getting this message, "No module named '_socket'", since I > installed python 3.6, about two months ago. > > My platform is Slackware Linux (14.2). I compiled python3.6 from source, > because binary python packages aren't distributed by python.org for Linux. > I have the same experience on multiple Slackware computers, not just one. > Actually, this problem hits the 64-bit distribution. I have a 32-bit > Slackware box that has no trouble with _socket. > > I can not 'import socket' into a program, nor can I use 'pip' to install > modules. These require the _socket module, which doesn't exist. What does > exist is a shared library object called '_ > socket.cpython-36m-i386-linux-gnu.so'. This looks tantalizingly like the > missing module, but it is for a 32-bit architecture. > > This is not the only missing module for 64-bit Slackware Linux. I can not > find a trace of the 'math' module, which, again, works fine on my 32-bit > computer. > > I am far from an expert on installing python modules, so I am asking for > advice on how I should proceed to find these modules. The 'socket' module (with the '_socket' helper) is part of the standard library, so it sounds like something failed during compilation. I don't know Slackware specifically, but my guess is that you need to install development libraries for something in order to compile _socket, and you installed the 32-bit but not the 64-bit of it. ChrisA From BILL_NOSPAM at Noway.net Wed Dec 6 16:55:04 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Wed, 6 Dec 2017 16:55:04 -0500 Subject: Python homework In-Reply-To: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: I think carelessness in choosing variable names may be at the root of the problem. nick.martinez2 at aol.com wrote: > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value of all rolls. > I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. > This is what I have so far: > import random > > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls > > if __name__ == "__main__": > result = rollDie(50) > print (result) > print(max(result)) From tjreedy at udel.edu Wed Dec 6 17:21:56 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Dec 2017 17:21:56 -0500 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On 12/5/2017 4:39 PM, Igor Korot wrote: > Hi, Tony, > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff wrote: >> On 05/12/17 16:55, Igor Korot wrote: >>> Hi, >>> >>> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy >>> wrote: >>>> Sir, >>>> I am b.tech student I would like to learn python. So please send the python software. >>> Sorry, we don't send anything. You will have to go get it yourself. -) >>> >> Well, at least try to be helpful: >> https://www.python.org/downloads/ > > This is LMGIFY. > If they say they are tech students - they should know how to work with Google. > > And I even tried to be polite. I should have probably write something like: > > 1. Open the Web browser. > 2. In the "Address Bar" type "www.pyton.org". Fortunately, this wrong url does not currently lead to a fake site with malware binaries. > 3. Find the link which reads "Downloads". Click on it. > 4. Carefully read what version you need to install for your OS. > 5. Apply the acquired knowledge and download the appropriate version. > 6. Click on the installer (if on Windows). > 7. Follow all the prompts. > 8. Enjoy. > > but this is too much for the tech student. > > Thank you. > >> -- >> https://mail.python.org/mailman/listinfo/python-list -- Terry Jan Reedy From rosuav at gmail.com Wed Dec 6 17:31:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Dec 2017 09:31:41 +1100 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> Message-ID: On Thu, Dec 7, 2017 at 9:21 AM, Terry Reedy wrote: > On 12/5/2017 4:39 PM, Igor Korot wrote: >> >> Hi, Tony, >> >> On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff >> wrote: >>> >>> On 05/12/17 16:55, Igor Korot wrote: >>>> >>>> Hi, >>>> >>>> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy >>>> wrote: >>>>> >>>>> Sir, >>>>> I am b.tech student I would like to learn python. So please >>>>> send the python software. >>>> >>>> Sorry, we don't send anything. You will have to go get it yourself. -) >>>> >>> Well, at least try to be helpful: >>> https://www.python.org/downloads/ >> >> >> This is LMGIFY. >> If they say they are tech students - they should know how to work with >> Google. >> >> And I even tried to be polite. I should have probably write something >> like: >> >> 1. Open the Web browser. >> 2. In the "Address Bar" type "www.pyton.org". > > > Fortunately, this wrong url does not currently lead to a fake site with > malware binaries. Which is why I recommend using a search engine. I tried four of them on the misspelled word "pyton", and all four had www.python.org (correctly spelled) as the first non-sponsored link. ChrisA From greg.ewing at canterbury.ac.nz Wed Dec 6 17:51:52 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 07 Dec 2017 11:51:52 +1300 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> Message-ID: Rick Johnson wrote: > DOLT: "Programming is easy! Once you learn the langauge, > it's just a matter of fill-in-the-blanks." To be fair to this person, for someone who has a natural aptitude for programming, it can be difficult to appreciate how hard it is for people who don't. When I first started programming, in my early teens, the basic ideas all seemed very straightforward, and I had no trouble seeing how to apply them. I unconsciously assumed it would be the same for anyone else with a reasonable level of intelligence. It was a while before it became clear to me that this is not the case at all. -- Greg From formisc at gmail.com Wed Dec 6 18:01:07 2017 From: formisc at gmail.com (Andrew Z) Date: Wed, 6 Dec 2017 18:01:07 -0500 Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> Message-ID: Can we mark the entire thread "spam", please? On Dec 6, 2017 17:55, "Gregory Ewing" wrote: > Rick Johnson wrote: > > DOLT: "Programming is easy! Once you learn the langauge, >> it's just a matter of fill-in-the-blanks." >> > > To be fair to this person, for someone who has a natural > aptitude for programming, it can be difficult to appreciate > how hard it is for people who don't. > > When I first started programming, in my early teens, the > basic ideas all seemed very straightforward, and I had > no trouble seeing how to apply them. I unconsciously > assumed it would be the same for anyone else with a > reasonable level of intelligence. > > It was a while before it became clear to me that this is > not the case at all. > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list > From rantingrickjohnson at gmail.com Wed Dec 6 18:08:51 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 15:08:51 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> Message-ID: On Wednesday, December 6, 2017 at 3:13:41 PM UTC-6, Python wrote: [...] > Geez, seriously? The snippet is purely academic, obviously > not a complete or useful program, Who ever made the claim that it was? > intended to illustrate that python can take two different > branches depending on whether or not the slicing operation > yeilded a non-empty container, using uncomplicated syntax. > It effectively serves that purpose. "Uncomplicated" is a relative term, not an absolute. The following is Terry's original: if item: process(item) else: do_without_item() And here is the functioning equivalent, sans any fuzzy semantics: if item: process(item) else: pass And finally, here is the functioning equivalent, sans the fuzzy semantics *AND* the forced vist to a little "ghost town". if item: process(item) My point is simple: What good could possibly come from posting bloat-ware example code? The else-clause is superfluous. How many times must i explain this simple concept before you will admit you are wrong? > Moreover, in order for the example to make sense, we must > assume the existence of unspecified code: The variables > need to have been initialized previously, or else the > snippet is non-functional. Agreed. > The if conditional would never be reached. We can as > easily assume that the hypothetical example continues with > other, unspecified code, and that the equally unspecified > do_without_item() actually does something, Fine. Why stop at a single if/else binary? Why not offer N more irrelevant clauses? import os, re value = "foo" if value: do_something1(value) elif isinstance(value, (int, float)): do_something_else1(value) elif os.path.exists(value): do_something_else2(value) elif re.match(r'.*ly', value): do_something_else3(value) else: do_nothing() The possibilities are literally endless. > which renders your argument completely invalid and > pointless. And that's an opinion you get to have. > The whole thing is entirely academic; continuing to argue > this is an utter waste of time and bandwidth. Yet, here you are, apeaking on behalf of others. It boggles the mind. -- https://plus.google.com/u/0/collection/UAv9UE From python at bladeshadow.org Wed Dec 6 18:22:17 2017 From: python at bladeshadow.org (Python) Date: Wed, 6 Dec 2017 17:22:17 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> Message-ID: <20171206232217.GG30413@bladeshadow.org> On Wed, Dec 06, 2017 at 03:08:51PM -0800, Rick Johnson wrote: > The following is Terry's original: > > if item: > process(item) > else: > do_without_item() > > And here is the functioning equivalent, sans any fuzzy > semantics: > > if item: > process(item) > else: > pass > THIS IS FALSE. CALLING A FUNCTION IS NOT FUNCTIONALLY EQUIVALENT TO THE PASS STATEMENT. Therefore your entire premise is false, and the remainder of what you said is meaningless. From rantingrickjohnson at gmail.com Wed Dec 6 18:48:04 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 15:48:04 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <533ee8dc-b889-4ad4-bc24-abb5ddfd024b@googlegroups.com> <57fecfcc-d0bf-a3cf-5a7c-9a19c0036050@nedbatchelder.com> <8f82aac0-28fc-4b1b-bd90-d0a9d0a755fe@googlegroups.com> <4757542b-4e3b-bff9-abe5-b289b9378285@nedbatchelder.com> <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> Message-ID: <27bc74ae-0a63-4b2c-a4e0-307de063dffd@googlegroups.com> Terry Reedy wrote: [...] > Rick, cut the crap. If you do not understand that > 'something_else()' != 'pass', re-read the tutorial. How is the official tutorial going to give me any insight into an undefined symbol that you invented? Of course, we all understand that "something_else()" is merely a semantical placeholder which is synonomous with "fill_in_the_blank()" or "do_as_you_please()". I'm sure the OP is competent enough to decide when his/her if-clauses need to grow a complementary else-clause, or when a chain of elif-clauses are required as well. My intention was not to make you out as some sort of boogeyman, i simply want to inform those watching. So no need to take any of this personally. > The OP asked: "Why is slicing 'forgiving'?" The current > behavior could be interpreted as 'letting errors pass > silently'. It would be if slicing meant 'give me exactly > the length stop-start subsequence from start to stop (or > raise)'. But slicing actually means 'give me whatever > subsequence exists between start and stop'. Agreed. > My examples attempted to show why this looser definition of > slicing is *useful*. The focus of the third example was > entirely on the condition, not the alternative actions. > (Reminder: either action can be the if-action, and the > other the else-action, depending on how the condition is > written.) True. But your conditional presented a specific binary choice, where the if-clause takes the role of a "TRUTHY_CLAWS", and the else-clause takes the role of a "FALSEY_CLAWS". Unfortunately i didn't get a chance to work FLASEY_CLAWS into my metaphor, hmm, as i was afraid the power dynamic between the two "clawed marsupials" might distract from the narrative. TC always has to be first in everything. That's the way she is, i'm afraid. > I should have mentioned, and others did, that the OP can > write a custom __getitem__ method that implements stricter > slicing for instances of a custom class. Yep. Could name it "StrictSlice". > I think we have collectively answered the OP's question > quite well. Yes. But i like to take advantage of any tangential teaching moments whenever they arise. And don't forget, the OP is not the only person who is learning from this exchange. We are all students of knowledge. -- https://plus.google.com/u/0/collection/UAv9UE From rantingrickjohnson at gmail.com Wed Dec 6 19:05:42 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 16:05:42 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> Message-ID: Python wrote: [...] > THIS IS FALSE. CALLING A FUNCTION What *FUNCTION*? You think you can just slap a function-y looking symbol willy-nilly in the middle of a chunk of code and then have it "magically" transform into a python function object? >>> do_without_item() Traceback (most recent call last): File "", line 1, in do_without_item() NameError: name 'do_without_item' is not defined >>> foo() Traceback (most recent call last): File "", line 1, in foo() NameError: name 'foo' is not defined >>> bar() Traceback (most recent call last): File "", line 1, in bar() NameError: name 'bar' is not defined if "do_without_item()" had been defined, then you could call it a function. But until you do, it's just a NameError. From abrault at mapgears.com Wed Dec 6 19:39:23 2017 From: abrault at mapgears.com (Alexandre Brault) Date: Wed, 6 Dec 2017 19:39:23 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> Message-ID: process() wasn't defined either, nor were n and seq and yet you're not complaining about them. It seems it was clear to everyone but you that seq was a sequence defined elsewhere, n was an index defined elsewhere, and both process and do_without_item were functions defined elsewhere. And even if you want to be so incredibly pedantic that do_without_item (and only do_without_item, because the rest of the code fragment seems to get your seal of approval) is not defined, your "functioning equivalent" is still not equivalent, because the original code would have raised a NameError that yours doesn't. On 2017-12-06 7:05 PM, Rick Johnson wrote: > Python wrote: > > [...] > >> THIS IS FALSE. CALLING A FUNCTION > What *FUNCTION*? > > You think you can just slap a function-y looking symbol > willy-nilly in the middle of a chunk of code and then have > it "magically" transform into a python function object? > > >>> do_without_item() > > Traceback (most recent call last): > File "", line 1, in > do_without_item() > NameError: name 'do_without_item' is not defined > >>> foo() > > Traceback (most recent call last): > File "", line 1, in > foo() > NameError: name 'foo' is not defined > >>> bar() > > Traceback (most recent call last): > File "", line 1, in > bar() > NameError: name 'bar' is not defined > > if "do_without_item()" had been defined, then you could call > it a function. But until you do, it's just a NameError. From rantingrickjohnson at gmail.com Wed Dec 6 19:49:50 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 16:49:50 -0800 (PST) Subject: we want python software In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> Message-ID: <4db9548d-ed1f-4949-acdc-3089fb88ed96@googlegroups.com> Gregory Ewing wrote: [...] > To be fair to this person, for someone who has a natural > aptitude for programming, it can be difficult to appreciate > how hard it is for people who don't. When I first started > programming, in my early teens, the basic ideas all seemed > very straightforward, and I had no trouble seeing how to > apply them. I unconsciously assumed it would be the same > for anyone else with a reasonable level of intelligence. > It was a while before it became clear to me that this is > not the case at all. Indeed. It's not simply a matter of being intelligent "enough". A prospect must also possess some very specific innate skills and personality traits. And these attributes simply cannot be taught. You either have them, or you don't. That's why these huge advertising campaigns to bring new folk into the programming arts have been a total flop. I guess you can teach anybody how to be a code monkey, but without a bonafide software engineer on the team directing the Orcestrial Circus (ook-ook!), not much will get done. I can't imagine how awful it would be to stand over people's shoulder all day and tell them how to write each and every line of code. That's not what any software engineer was born to do. It's just shameful. -- https://plus.google.com/u/0/collection/UAv9UE From gheskett at shentel.net Wed Dec 6 19:53:52 2017 From: gheskett at shentel.net (Gene Heskett) Date: Wed, 6 Dec 2017 19:53:52 -0500 Subject: Politeness (was: we want python software) In-Reply-To: References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <201712061256.14896.gheskett@shentel.net> Message-ID: <201712061953.52244.gheskett@shentel.net> On Wednesday 06 December 2017 15:33:40 Ian Kelly wrote: > On Wed, Dec 6, 2017 at 10:56 AM, Gene Heskett wrote: > > On Wednesday 06 December 2017 12:14:32 Ian Kelly wrote: > >> On Wed, Dec 6, 2017 at 9:42 AM, Gene Heskett > > > > wrote: > >> > On Wednesday 06 December 2017 11:28:22 Random832 wrote: > >> >> The third possibility is that he believes that this list is > >> >> official in some corporate sense, that if he asks for the > >> >> software and it is not free he will receive a price quote. > >> > > >> > Sadly, that an attitude even college profs don't get, having > >> > gotten their sheepskin with only M$ stuff, that something could > >> > be both free and good. > >> > > >> > It's a concept that makes no sense to the teachers, so of course > >> > they don't teach it either. Hell of a way to run a train. > >> > >> Depends where you went to school, probably. The CS department at my > >> college was all over using Linux and free software. > > > > Then why not promote that seat of higher learning by naming it? Word > > of mouth publicity is the best kind. > > Earlham College. Thank you, but at first the only Earlham I could think of was Earlham, IA. Which isn't the home of a higher ed facility that I know of. Sounds like an interesting place that google sent me to. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From nick.martinez2 at aol.com Wed Dec 6 19:58:00 2017 From: nick.martinez2 at aol.com (nick martinez) Date: Wed, 6 Dec 2017 16:58:00 -0800 (PST) Subject: Round to 2 decimal places Message-ID: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> I'm stuck. I need my program to round the end solution to 2 decimal places but cant figure it out. Can someone help? I've been trying between printf and round() but cant seem to get either to work. Python 3.5 is what I'm using. import math print("This program will calculate the surface area and volume of a 3-dimensional cone: ") print() print() r = input("What is the radius in feet? (no negatives): ") h = input("What is the height in feet? (no negatives): ") r = float(r) h = float(h) if r > 0 and h > 0: surfacearea = math.pi*r**2+r*math.pi*(math.sqrt(r**2+h**2)) volume = (1/3)*math.pi*r**2*h print() print("Your Answer is:") print() print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", volume, "\nand surface area of : ", surfacearea,) else: print("No negatives allowed, try again.") From ssghotra1997 at gmail.com Wed Dec 6 20:13:04 2017 From: ssghotra1997 at gmail.com (ssghotra1997 at gmail.com) Date: Wed, 6 Dec 2017 17:13:04 -0800 (PST) Subject: Round to 2 decimal places In-Reply-To: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> Message-ID: <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> The following works: import math print("This program will calculate the surface area and volume of a 3-dimensional cone: ") print() print() r = input("What is the radius in feet? (no negatives): ") h = input("What is the height in feet? (no negatives): ") r = float(r) h = float(h) if r > 0 and h > 0: surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) volume = (1 / 3) * math.pi * r ** 2 * h print() print("Your Answer is:") print() print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", round(surfacearea,2), ) else: print("No negatives allowed, try again.") From ssghotra1997 at gmail.com Wed Dec 6 20:13:54 2017 From: ssghotra1997 at gmail.com (ssghotra1997 at gmail.com) Date: Wed, 6 Dec 2017 17:13:54 -0800 (PST) Subject: Round to 2 decimal places In-Reply-To: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> Message-ID: <82c40ffb-514a-41b5-97a9-1885e92d0d58@googlegroups.com> import math print("This program will calculate the surface area and volume of a 3-dimensional cone: ") print() print() r = input("What is the radius in feet? (no negatives): ") h = input("What is the height in feet? (no negatives): ") r = float(r) h = float(h) if r > 0 and h > 0: surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) volume = (1 / 3) * math.pi * r ** 2 * h print() print("Your Answer is:") print() print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", round(surfacearea,2), ) else: print("No negatives allowed, try again.") From ned at nedbatchelder.com Wed Dec 6 20:16:19 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 6 Dec 2017 20:16:19 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> Message-ID: <8f0b73ab-40dc-4371-6bf3-753124052fcb@nedbatchelder.com> After a certain point, the only thing you can do with a troll is ignore them. --Ned. From ssghotra1997 at gmail.com Wed Dec 6 20:18:10 2017 From: ssghotra1997 at gmail.com (ssghotra1997 at gmail.com) Date: Wed, 6 Dec 2017 17:18:10 -0800 (PST) Subject: Python homework In-Reply-To: References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> <3e6ebec8-8950-5613-fa3e-b7ae7b5c7a80@VybeNetworks.com> Message-ID: <9e071c71-9741-44f3-a73f-6e5ac46bb1d3@googlegroups.com> On Wednesday, December 6, 2017 at 9:28:26 PM UTC+11, D'Arcy Cain wrote: > On 12/05/2017 07:33 PM, nick.martinez2--- via Python-list wrote: > > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > > times and then prints > > (i). the most frequent side of the die > > (ii). the average die value of all rolls. > > I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. > > How did you come up with 4? I come up with 3.36 with those numbers. > > > This is what I have so far: > > import random > > > > def rollDie(number): > > rolls = [0] * 6 > > For a small efficiency use "[0] * 7". See below for reason. > > > for i in range(0, number): > > roll=int(random.randint(1,6)) > > rolls[roll - 1] += 1 > > Use "rolls[roll] += 1" here. You save one arithmetic instruction each > time through the loop. Fifty times isn't much saving but imagine fifty > million. > > > return rolls > > return rolls[1:]. No matter how many rolls you only need to do the > slice once. However, you really need a lot of iterations before it > really affects the total run time. > > You need one more thing though. Create a new variable called "total" > and set it to 0.0. Add "total += roll" to your loop. your return > statement is now "return rolls[1:], total/number". > > > > > if __name__ == "__main__": > > result = rollDie(50) > > Now "result, average = ..." > > > print (result) > > print(max(result)) > > This is why you get 14. The maximum number of rolls for any one side is > 14 for side 4. Is that where you got "4"? > > -- > D'Arcy J.M. Cain > Vybe Networks Inc. > http://www.VybeNetworks.com/ > IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com The 'four' is the number which was rolled the highest during the 50 rolls From nick.martinez2 at aol.com Wed Dec 6 20:39:08 2017 From: nick.martinez2 at aol.com (nick martinez) Date: Wed, 6 Dec 2017 17:39:08 -0800 (PST) Subject: Round to 2 decimal places In-Reply-To: <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> Message-ID: <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot... at gmail.com wrote: > The following works: > > import math > > print("This program will calculate the surface area and volume of a 3-dimensional cone: ") > print() > print() > r = input("What is the radius in feet? (no negatives): ") > h = input("What is the height in feet? (no negatives): ") > r = float(r) > h = float(h) > if r > 0 and h > 0: > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) > volume = (1 / 3) * math.pi * r ** 2 * h > > print() > print("Your Answer is:") > print() > > print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", > round(surfacearea,2), ) > else: > print("No negatives allowed, try again.") Tried this but it doesn't seem to work. It still prints out all of the decimals From steve+python at pearwood.info Wed Dec 6 20:45:43 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Dec 2017 12:45:43 +1100 Subject: Module _socket not found in python3.6 "No module named _socket" References: Message-ID: <5a289d48$0$2072$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Dec 2017 07:59 am, Bryan Zimmer wrote: > I have been getting this message, "No module named '_socket'", since I > installed python 3.6, about two months ago. > > My platform is Slackware Linux (14.2). I compiled python3.6 from source, > because binary python packages aren't distributed by python.org for Linux. > I have the same experience on multiple Slackware computers, not just one. > Actually, this problem hits the 64-bit distribution. I have a 32-bit > Slackware box that has no trouble with _socket. You need to look at the output of compilation. That might mean doing it again :-( Unfortunately the default is to output everything including the kitchen sink, which makes it hard to notice the errors. Take note of which files failed to compile, and if need be, post the list here. Chances are you are missing some development library. You may have the 32-bit dev library installed, but not the 64-bit version. > I can not 'import socket' into a program, nor can I use 'pip' to install > modules. These require the _socket module, which doesn't exist. What does > exist is a shared library object called '_ > socket.cpython-36m-i386-linux-gnu.so'. This looks tantalizingly like the > missing module, but it is for a 32-bit architecture. Where is that file? On your 64-bit box? Do you have the 32-bit Python 3.6 already installed on that machine? If so, make sure you install the 64-bit version in a different location. If this isn't enough to diagnose the problems, best to go back to basics and post *each* step you take and any error output. (The config and make steps tend to send a metric ton of uninformative output to stdout, probably best to just capture stderr.) Trivial steps that you are sure are correct can be summarised (e.g. "Downloaded Python3.6.tar.gz, unpacked it, and cd'ed into the resulting directory") but if you have any doubt that you are doing it correctly, better to post too much information than not enough. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rantingrickjohnson at gmail.com Wed Dec 6 21:02:08 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Dec 2017 18:02:08 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <9463d0b1-a20d-425b-8f1e-9241481145ea@googlegroups.com> <062c0016-ae7d-5d38-c75b-b54a24c8080e@nedbatchelder.com> <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> Message-ID: Alexandre Brault wrote: [...] > process() wasn't defined either, nor were n and seq and yet > you're not complaining about them. Why would i? Both are highly relevant to the example of performing a slice. "Don't throw the baby out with the bathwater", as they say... > It seems it was clear to everyone but you that seq was a > sequence defined elsewhere, n was an index defined > elsewhere, and both process and do_without_item were > functions defined elsewhere. OMG! I never would have guessed that! O_O And whilst we can see that your cryptology skills are quite impressive -- and by impressive, i mean, like up there with some of the best cryptologist in the world, impressive -- your ability to distinguish between the portions of this teeny tiny example that are _relevant_ to the action of performing a slice, and the portions that are _irrelevant_ to performing a slice, leads me to the conclusion that your ability to make simple value judgments is seriously flawed, or missing altogether. If we consider the entire working sample that Ned offered (because Ned is the only person from your side who's bothered to offer error-free code) and we break this code down into its relevant parts, starting from the most relevant part (the actual slice), and extending the scope outwards from there, each time enveloping only the minimum structures required to maintain legal code, we will see that all of the structures *SANS* the else-clause can be justified. The function can be justified because it wraps the contents in a self contained reusable code object. Likewise, the conditional *if-clause* can be justified because it brings logic into the equation. But the else- clause is only relevant to the if-clause, and does not offer _enough_ useful content of its own to validate its own existence. > And even if you want to be so incredibly pedantic that > do_without_item (and only do_without_item, because the rest > of the code fragment seems to get your seal of approval) is > not defined, your "functioning equivalent" is still not > equivalent, because the original code would have raised a > NameError that yours doesn't. Oh this is rich. Now i'm wrong because my code executes _cleanly_? You must be joking! From ssghotra1997 at gmail.com Wed Dec 6 21:03:02 2017 From: ssghotra1997 at gmail.com (ssghotra1997 at gmail.com) Date: Wed, 6 Dec 2017 18:03:02 -0800 (PST) Subject: Round to 2 decimal places In-Reply-To: <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> Message-ID: On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote: > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot... at gmail.com wrote: > > The following works: > > > > import math > > > > print("This program will calculate the surface area and volume of a 3-dimensional cone: ") > > print() > > print() > > r = input("What is the radius in feet? (no negatives): ") > > h = input("What is the height in feet? (no negatives): ") > > r = float(r) > > h = float(h) > > if r > 0 and h > 0: > > > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) > > volume = (1 / 3) * math.pi * r ** 2 * h > > > > print() > > print("Your Answer is:") > > print() > > > > print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", > > round(surfacearea,2), ) > > else: > > print("No negatives allowed, try again.") > > Tried this but it doesn't seem to work. It still prints out all of the decimals This is the output from the code above (Working): What is the radius in feet? (no negatives): >? 2 What is the height in feet? (no negatives): >? 4 Your Answer is: A cone with radius 2.0 and height of 4.0 has a volume of : 16.76 and surface area of : 40.67 From python at mrabarnett.plus.com Wed Dec 6 21:09:25 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 7 Dec 2017 02:09:25 +0000 Subject: Round to 2 decimal places In-Reply-To: <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> Message-ID: <86d8d5cd-a63d-3db1-4599-b250395d2606@mrabarnett.plus.com> On 2017-12-07 01:39, nick martinez via Python-list wrote: > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot... at gmail.com wrote: >> The following works: >> >> import math >> >> print("This program will calculate the surface area and volume of a 3-dimensional cone: ") >> print() >> print() >> r = input("What is the radius in feet? (no negatives): ") >> h = input("What is the height in feet? (no negatives): ") >> r = float(r) >> h = float(h) >> if r > 0 and h > 0: >> >> surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) >> volume = (1 / 3) * math.pi * r ** 2 * h >> >> print() >> print("Your Answer is:") >> print() >> >> print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", >> round(surfacearea,2), ) >> else: >> print("No negatives allowed, try again.") > > Tried this but it doesn't seem to work. It still prints out all of the decimals > Try using .format: print("A cone with radius {}\nand height of {}\nhas a volume of : {:.2f}\nand surface area of : {:.2f}".format(r, h, volume, surfacearea))) round(volume,2) will round the volume to 2 decimal places, but floating-point numbers in Python are stored in binary, and you can't always represent a fractional decimal number exactly in binary. For example, you can't store 0.1 exactly as a float. From steve+python at pearwood.info Wed Dec 6 21:29:11 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Dec 2017 13:29:11 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> Message-ID: <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Dec 2017 08:22 am, Python wrote: > On Wed, Dec 06, 2017 at 10:35:58AM +1100, Steve D'Aprano wrote: >> On Tue, 5 Dec 2017 07:58 pm, Lawrence D?Oliveiro wrote: >> >> > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: >> >> >> >> Sounds like your OS file associations are all botched-up ... >> > >> > Linux doesn?t do ?OS file associations?. >> >> >> Then how does my Linux box know that when I double-click on a text file, it >> launches kwrite rather than (say) the Gimp or LibreOffice? > > The answer to that is (sadly) complicated. Actually, no, the answer to my question is very simple: Lawrence is mistaken about Linux not doing file associations. It does -- it is merely handled by the desktop environment (if there is one). Lawrence is showing off his geek cred with an answer that is pedantically correct but in practice not just useless but actually false. Of course Linux computers can associate certain files with certain applications. If the term "OS file associations" is ever so slightly inaccurate (it's not the actual OS kernel that does the associating, but the desktop environment), well, we can probably say the same thing about Mac OS X and maybe even Windows itself. > How it knows indeed > depends on the context of the click, what desktop environment you're > using, what application(s) you're using, and what configurations > you've made to those things to address any file associations. Indeed you are correct, which is why it may not be a trivial matter to answer the OP's question about how to get the behaviour he wants. But that isn't what my comment is about. I'm simply replying to Lawrence's insinuation that Linux computers don't associate file types to applications. I'm sure that Lawrence worded his statement *ever so carefully* to ensure that it was pedantically correct if read to the letter, while still insinuating something completely wrong. It takes a lot of care to provide information which is both true and utterly misleading at the same time, but Lawrence does it very, very well indeed. If only he would use his considerable intellect to provide *useful* answers instead of *accurate but misleading* answers. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From nick.martinez2 at aol.com Wed Dec 6 21:31:57 2017 From: nick.martinez2 at aol.com (nick martinez) Date: Wed, 6 Dec 2017 18:31:57 -0800 (PST) Subject: Round to 2 decimal places In-Reply-To: References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> Message-ID: <5eb1060d-0eee-4880-b751-a032fefb430c@googlegroups.com> On Wednesday, December 6, 2017 at 9:03:27 PM UTC-5, ssghot... at gmail.com wrote: > On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote: > > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot... at gmail.com wrote: > > > The following works: > > > > > > import math > > > > > > print("This program will calculate the surface area and volume of a 3-dimensional cone: ") > > > print() > > > print() > > > r = input("What is the radius in feet? (no negatives): ") > > > h = input("What is the height in feet? (no negatives): ") > > > r = float(r) > > > h = float(h) > > > if r > 0 and h > 0: > > > > > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) > > > volume = (1 / 3) * math.pi * r ** 2 * h > > > > > > print() > > > print("Your Answer is:") > > > print() > > > > > > print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", > > > round(surfacearea,2), ) > > > else: > > > print("No negatives allowed, try again.") > > > > Tried this but it doesn't seem to work. It still prints out all of the decimals > > This is the output from the code above (Working): > > What is the radius in feet? (no negatives): >? 2 > What is the height in feet? (no negatives): >? 4 > Your Answer is: > A cone with radius 2.0 > and height of 4.0 > has a volume of : 16.76 > and surface area of : 40.67 interesting, what version of python are you using? Tried it multiple times and it still isn't working. From kpavan30 at gmail.com Wed Dec 6 21:40:09 2017 From: kpavan30 at gmail.com (pavan kopparthi) Date: Thu, 7 Dec 2017 08:10:09 +0530 Subject: Module _socket not found in python3.6 "No module named _socket" In-Reply-To: References: Message-ID: I too facing the same issue related to pip file for other models installation. Installed Python 3.6.3 Amd64 in Windows 10 OS. Want to install Tensor flow using native pip as suggested... But, observed that pip3 file in Scripts folder is missing. Also, Scripts folder is empty. On 7 Dec 2017 3:02 a.m., "Bryan Zimmer" wrote: I have been getting this message, "No module named '_socket'", since I installed python 3.6, about two months ago. My platform is Slackware Linux (14.2). I compiled python3.6 from source, because binary python packages aren't distributed by python.org for Linux. I have the same experience on multiple Slackware computers, not just one. Actually, this problem hits the 64-bit distribution. I have a 32-bit Slackware box that has no trouble with _socket. I can not 'import socket' into a program, nor can I use 'pip' to install modules. These require the _socket module, which doesn't exist. What does exist is a shared library object called '_ socket.cpython-36m-i386-linux-gnu.so'. This looks tantalizingly like the missing module, but it is for a 32-bit architecture. This is not the only missing module for 64-bit Slackware Linux. I can not find a trace of the 'math' module, which, again, works fine on my 32-bit computer. I am far from an expert on installing python modules, so I am asking for advice on how I should proceed to find these modules. Thanks in advance. "BryGuy" (my handle on linuxquestions.org) -- https://mail.python.org/mailman/listinfo/python-list From nick.martinez2 at aol.com Wed Dec 6 21:40:09 2017 From: nick.martinez2 at aol.com (nick martinez) Date: Wed, 6 Dec 2017 18:40:09 -0800 (PST) Subject: Round to 2 decimal places In-Reply-To: <5eb1060d-0eee-4880-b751-a032fefb430c@googlegroups.com> References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> <5eb1060d-0eee-4880-b751-a032fefb430c@googlegroups.com> Message-ID: <9c66a1a6-52f7-420a-92d3-b8673a460bfd@googlegroups.com> On Wednesday, December 6, 2017 at 9:32:27 PM UTC-5, nick martinez wrote: > On Wednesday, December 6, 2017 at 9:03:27 PM UTC-5, ssghot... at gmail.com wrote: > > On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote: > > > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot... at gmail.com wrote: > > > > The following works: > > > > > > > > import math > > > > > > > > print("This program will calculate the surface area and volume of a 3-dimensional cone: ") > > > > print() > > > > print() > > > > r = input("What is the radius in feet? (no negatives): ") > > > > h = input("What is the height in feet? (no negatives): ") > > > > r = float(r) > > > > h = float(h) > > > > if r > 0 and h > 0: > > > > > > > > surfacearea = math.pi * r ** 2 + r * math.pi * (math.sqrt(r ** 2 + h ** 2)) > > > > volume = (1 / 3) * math.pi * r ** 2 * h > > > > > > > > print() > > > > print("Your Answer is:") > > > > print() > > > > > > > > print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : ", round(volume,2), "\nand surface area of : ", > > > > round(surfacearea,2), ) > > > > else: > > > > print("No negatives allowed, try again.") > > > > > > Tried this but it doesn't seem to work. It still prints out all of the decimals > > > > This is the output from the code above (Working): > > > > What is the radius in feet? (no negatives): >? 2 > > What is the height in feet? (no negatives): >? 4 > > Your Answer is: > > A cone with radius 2.0 > > and height of 4.0 > > has a volume of : 16.76 > > and surface area of : 40.67 > > interesting, what version of python are you using? Tried it multiple times and it still isn't working. Never mind its working now, just had to change something up real quick, thank you. From steve+python at pearwood.info Wed Dec 6 21:43:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Dec 2017 13:43:06 +1100 Subject: Round to 2 decimal places References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> Message-ID: <5a28aabb$0$2069$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Dec 2017 11:58 am, nick martinez wrote: > I'm stuck. I need my program to round the end solution to 2 decimal places > but cant figure it out. Can someone help? I've been trying between printf > and round() but cant seem to get either to work. It might help if you show exactly what values you have tried. This works for me: py> volume = 1.23456789 py> print(volume ) 1.23456789 py> print(round(volume , 2)) 1.23 The rest of your code is interesting but irrelevant to your question. If you want to learn how to round to 2 decimal places, the actual calculation of surface area and volume aren't necessary. The only really important part is this line: > print("A cone with radius", r, "\nand height of", h, "\nhas a volume of : > ", volume, "\nand surface area of : ", surfacearea,) and even that can be cut down to just: volume = 2345.987654321 # for example print(volume) We can round the result first, then print it: print(round(volume, 2)) or we can change the display by using string formatting: print("%.2f" % volume) print("{:.2f}".format(volume)) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Dec 6 22:29:51 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Dec 2017 14:29:51 +1100 Subject: Round to 2 decimal places References: <6ff1e2de-1e7c-4b4e-9b36-48e8b68fdb33@googlegroups.com> <6efcb3f8-593c-4114-a363-a9f605bb23db@googlegroups.com> <0a8b5d90-e5cf-470c-9371-3702a099147e@googlegroups.com> <5eb1060d-0eee-4880-b751-a032fefb430c@googlegroups.com> Message-ID: <5a28b5af$0$2717$b1db1813$eb6074ea@news.astraweb.com> On Thu, 7 Dec 2017 01:31 pm, nick martinez wrote: > interesting, what version of python are you using? Tried it multiple times > and it still isn't working. Please launch a terminal window, copy this command exactly into the terminal and hit ENTER. You should have a $ or maybe % prompt for this to work. python3.5 -c "volume = 257.148345678; print(round(volume, 2))" (Do you need help opening a terminal window? If so, ask. We'll need to know your operating system, and if you are using Linux, which desktop environment you are using.) If your prompt is ">>>" (without the quotes) or something similar to "In [1]:" then copy these two lines to the prompt and hit ENTER: volume = 257.148345678 print(round(volume, 2)) Either way, reply here with the output. Make sure you copy it. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ethan at stoneleaf.us Thu Dec 7 00:04:47 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 06 Dec 2017 21:04:47 -0800 Subject: we want python software In-Reply-To: <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> Message-ID: <5A28CBEF.8020900@stoneleaf.us> On 12/06/2017 08:33 AM, Steve D'Aprano wrote: > I'm going to defend KM (srikrishnamohan) -- his comments were not "an attack", On 12/05/2017 08:38 PM, km wrote: > I dont know how these students are selected into b tech stream in India. > they are so dumb. On 12/05/2017 09:27 PM, km wrote: > You people can Google and watch movies / songs online and you can't find > how to download and install python ? That's ridiculous! Really, Steve? -- ~Ethan~ From ben+python at benfinney.id.au Thu Dec 7 00:10:19 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Dec 2017 16:10:19 +1100 Subject: we want python software References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <5a281bcb$0$2087$b1db1813$d948b532@news.astraweb.com> <5A28CBEF.8020900@stoneleaf.us> Message-ID: <85vahjqg1w.fsf@benfinney.id.au> Ethan Furman writes: > On 12/06/2017 08:33 AM, Steve D'Aprano wrote: > > > I'm going to defend KM (srikrishnamohan) -- his comments were not "an attack", > > On 12/05/2017 08:38 PM, km wrote: > > I dont know how these students are selected into b tech stream in India. > > they are so dumb. > > On 12/05/2017 09:27 PM, km wrote: > > You people can Google and watch movies / songs online and you can't find > > how to download and install python ? That's ridiculous! > > Really, Steve? I'm with Ethan; ?km? took what appears to be a sincere request from a newcomer, and responded with what I'd classify as personal attacks. That is both unnecessary for the substance of ?km?'s points, and contrary to our Code of Conduct. Let's not defend that behaviour. -- \ ?Nothing worth saying is inoffensive to everyone. Nothing worth | `\ saying will fail to make you enemies. And nothing worth saying | _o__) will not produce a confrontation.? ?Johann Hari, 2011 | Ben Finney From Karsten.Hilbert at gmx.net Thu Dec 7 02:31:17 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 7 Dec 2017 08:31:17 +0100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: <20171207073117.GA3134@hermes.hilbert.loc> On Thu, Dec 07, 2017 at 01:29:11PM +1100, Steve D'Aprano wrote: > Actually, no, the answer to my question is very simple: Lawrence is mistaken > about Linux not doing file associations. It does -- it is merely handled by > the desktop environment (if there is one). We _can_ go one level below that: mailcap is independant of the desktop environment, it does associate file (content) types with suitable (hopefully) applications. The one thing it doesn't "do" that's relevant to OPs post is that it doesn't react to clicks or taps in order to _execute_ those associations. Best, Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From marko at pacujo.net Thu Dec 7 02:54:29 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Dec 2017 09:54:29 +0200 Subject: we want python software References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> Message-ID: <87mv2vnfbe.fsf@elektro.pacujo.net> Gregory Ewing : > Rick Johnson wrote: >> DOLT: "Programming is easy! Once you learn the langauge, >> it's just a matter of fill-in-the-blanks." > > To be fair to this person, for someone who has a natural aptitude for > programming, it can be difficult to appreciate how hard it is for > people who don't. > > When I first started programming, in my early teens, the basic ideas > all seemed very straightforward, and I had no trouble seeing how to > apply them. I unconsciously assumed it would be the same for anyone > else with a reasonable level of intelligence. > > It was a while before it became clear to me that this is not the case > at all. A junior programmer sees the unlimited possibilities of programming. No montain is too high to climb. A seasoned programmer is elated if they can get anything to work at all. Marko From rosuav at gmail.com Thu Dec 7 05:35:51 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Dec 2017 21:35:51 +1100 Subject: we want python software In-Reply-To: <87mv2vnfbe.fsf@elektro.pacujo.net> References: <5a26b6e5.46d1620a.5e2cb.151b@mx.google.com> <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> <87mv2vnfbe.fsf@elektro.pacujo.net> Message-ID: On Thu, Dec 7, 2017 at 6:54 PM, Marko Rauhamaa wrote: > Gregory Ewing : > >> Rick Johnson wrote: >>> DOLT: "Programming is easy! Once you learn the langauge, >>> it's just a matter of fill-in-the-blanks." >> >> To be fair to this person, for someone who has a natural aptitude for >> programming, it can be difficult to appreciate how hard it is for >> people who don't. >> >> When I first started programming, in my early teens, the basic ideas >> all seemed very straightforward, and I had no trouble seeing how to >> apply them. I unconsciously assumed it would be the same for anyone >> else with a reasonable level of intelligence. >> >> It was a while before it became clear to me that this is not the case >> at all. > > A junior programmer sees the unlimited possibilities of programming. No > montain is too high to climb. > > A seasoned programmer is elated if they can get anything to work at all. > And an expert programmer sees that those mountains are so full of bugs they're better described as ant-hills... ChrisA From Karsten.Hilbert at gmx.net Thu Dec 7 05:54:58 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 7 Dec 2017 11:54:58 +0100 Subject: we want python software In-Reply-To: References: <0001HW.1FD7DE5500A594A014F5F02CF@news.individual.net> <87mv2vnfbe.fsf@elektro.pacujo.net> Message-ID: <20171207105458.GD3134@hermes.hilbert.loc> > > A junior programmer sees the unlimited possibilities of programming. No > > montain is too high to climb. > > > > A seasoned programmer is elated if they can get anything to work at all. Good judgement comes from experience. And a lot of that comes from bad judgement. Karsten From edmondo.giovannozzi at gmail.com Thu Dec 7 07:49:18 2017 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Thu, 7 Dec 2017 04:49:18 -0800 (PST) Subject: Python homework In-Reply-To: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: Il giorno mercoled? 6 dicembre 2017 02:33:52 UTC+1, nick martinez ha scritto: > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value of all rolls. > I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. > This is what I have so far: > import random > > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls > > if __name__ == "__main__": > result = rollDie(50) > print (result) > print(max(result)) Another way to get an answer is to use the numpy package. It is freely available and it is the "de facto" standard for numerical problems. If you get python from one of the scientific distribution (Anaconda, enthought, etc.) it will be automatically installed. import numpy Nrolls = 50 # but you can easily have millions of rolls a = numpy.random.randint(1,7,Nrolls) And then to count the rolls for each number you can use the histogram function frequency , _ = numpy.histogram(a, bins=[1,2,3,4,5,6,7]) You can now use the "argmax" method to find the number that appeared most frequently. Use the "mean" method to calculate the mean. Look on the help pages of numpy why I used radint(1,7) instead of radint(1,6) and the same for the bins in the histogram function. Have a look at: www.scipy.org Cheers :-) From nimbiotics at gmail.com Thu Dec 7 08:19:37 2017 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Thu, 7 Dec 2017 05:19:37 -0800 (PST) Subject: Python homework In-Reply-To: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: <45d22fd0-44aa-413c-b88f-916f0034d9b8@googlegroups.com> On Tuesday, December 5, 2017 at 8:33:52 PM UTC-5, nick martinez wrote: > I have a question on my homework. My homework is to write a program in which the computer simulates the rolling of a die 50 > times and then prints > (i). the most frequent side of the die > (ii). the average die value of all rolls. > I wrote the program so it says the most frequent number out of all the rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need. > This is what I have so far: > import random > > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls > > if __name__ == "__main__": > result = rollDie(50) > print (result) > print(max(result)) Just my 2 cents: import random def rollDie(number): rolls = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0} for i in range(0, number): roll=int(random.randint(1,6)) rolls[roll] += 1 return rolls if __name__ == "__main__": rolls = rollDie(50) most_rolled = rolls[max(rolls, key=lambda i: rolls[i])] top_rollers = [k for k,v in rolls.items() if v == most_rolled] print('The dice rolled: %s' % (rolls,)) if len(top_rollers) > 1: message = 'The sides with most hits are %s, with %i hits each.' else: message = 'The side with most hits is %s, with %i hits' print(message % (top_rollers, most_rolled)) # Sample output: # The dice rolled: {1: 10, 2: 10, 3: 7, 4: 7, 5: 10, 6: 6} # The sides with most hits are [1, 2, 5], with 10 hits each. # # The dice rolled: {1: 7, 2: 11, 3: 10, 4: 6, 5: 8, 6: 8} # The side with most hits is [2], with 11 hits From prvn.mora at gmail.com Thu Dec 7 09:06:03 2017 From: prvn.mora at gmail.com (prvn.mora at gmail.com) Date: Thu, 7 Dec 2017 06:06:03 -0800 (PST) Subject: Python script Message-ID: Hi All, I am new to python need help to write a script in python my requirement is :- write a python script to print sentence from a txt file to another txt file Regards, Praveen From auriocus at gmx.de Thu Dec 7 09:10:29 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 7 Dec 2017 15:10:29 +0100 Subject: Python script In-Reply-To: References: Message-ID: Am 07.12.17 um 15:06 schrieb prvn.mora at gmail.com: > Hi All, > I am new to python need help to write a script in python > my requirement is :- > write a python script to print sentence from a txt file to another txt file txt = open("another.txt", "w") print("sentence from txt file", file = txt) Christian From joel.goldstick at gmail.com Thu Dec 7 09:17:26 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 7 Dec 2017 09:17:26 -0500 Subject: Python script In-Reply-To: References: Message-ID: On Thu, Dec 7, 2017 at 9:06 AM, wrote: > Hi All, > I am new to python need help to write a script in python > my requirement is :- > write a python script to print sentence from a txt file to another txt file > > Regards, > Praveen > -- > https://mail.python.org/mailman/listinfo/python-list > So, the way it works here is that you should write some code as best you can. Paste it into your question using plaintext so that the formatting remains as coded, and tell us what errors you get (copy the traceback). People won't write code for you here, but they will help you figure out what you don't understand -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From rhodri at kynesim.co.uk Thu Dec 7 09:43:07 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 7 Dec 2017 14:43:07 +0000 Subject: Python homework In-Reply-To: <45d22fd0-44aa-413c-b88f-916f0034d9b8@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> <45d22fd0-44aa-413c-b88f-916f0034d9b8@googlegroups.com> Message-ID: <9e642cb7-f974-1503-3bcf-6f9d8f1bf136@kynesim.co.uk> On 07/12/17 13:19, Mario R. Osorio wrote: > > > > On Tuesday, December 5, 2017 at 8:33:52 PM UTC-5, nick martinez wrote: >> I have a question on my homework. [snip] > > Just my 2 cents: Sigh. Please don't do people's homework for them. It doesn't teach them anything. Now Nick had got 90% of the way there and shown his working, which is truly excellent, but what he needed was for someone to hint at how to search through the array, not to be handed a working example with no explanation. -- Rhodri James *-* Kynesim Ltd From breamoreboy at gmail.com Thu Dec 7 09:44:21 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 7 Dec 2017 06:44:21 -0800 (PST) Subject: Python script In-Reply-To: References: Message-ID: On Thursday, December 7, 2017 at 2:06:46 PM UTC, prvn... at gmail.com wrote: > Hi All, > I am new to python need help to write a script in python > my requirement is :- > write a python script to print sentence from a txt file to another txt file > > Regards, > Praveen Read this https://docs.python.org/3/tutorial/inputoutput.html. Run your favourite editor, type your code and save it. Try running the script and when you hit problems show us your code, the input, the expected output and state exactly what happened. Then we'll happily help you. -- Kindest regards. Mark Lawrence. From natalieleung.29 at gmail.com Thu Dec 7 10:36:00 2017 From: natalieleung.29 at gmail.com (Natalie Leung) Date: Thu, 7 Dec 2017 07:36:00 -0800 (PST) Subject: SystemError: error return without exception set Message-ID: I am trying to use Python to communicate and send commands in MSC Marc. A part of the code looks something like this: from py_mentat import* directory = '[specified the file path to my model]' marcModel = '[name of my model]' py_echo(0) openModel = '*new_model yes *open_model "'+ directory + marcModel +'"' py_send(openModel) The code stops at "py_send(openModel)" with an error message that reads: Traceback (most recent call last): File "[my file path]", line 11, in py_send(openModel) SystemError: error return without exception set I tried running the code on different platforms (e.g. Command Prompt, Wing 101, python.exe) and I get the same result. What could be the problem? From larry.martell at gmail.com Thu Dec 7 10:46:17 2017 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 7 Dec 2017 10:46:17 -0500 Subject: SystemError: error return without exception set In-Reply-To: References: Message-ID: On Thu, Dec 7, 2017 at 10:36 AM, Natalie Leung wrote: > I am trying to use Python to communicate and send commands in MSC Marc. A part of the code looks something like this: > > from py_mentat import* > > directory = '[specified the file path to my model]' > marcModel = '[name of my model]' > > py_echo(0) > openModel = '*new_model yes *open_model "'+ directory + marcModel +'"' > py_send(openModel) > > > The code stops at "py_send(openModel)" with an error message that reads: Traceback (most recent call last): File "[my file path]", line 11, in py_send(openModel) > SystemError: error return without exception set > > I tried running the code on different platforms (e.g. Command Prompt, Wing 101, python.exe) and I get the same result. What could be the problem? Faced with this I would use the debugger to break on the py_send line and then step into that function, and then step through it, e.g.: python -m pdb your_script.py b 8 [ or whatever the py_send line is) c [to continue to the BP) s [to step into py_send] then step through the function and something more informative may be revealed. From tomuxiong at gmx.com Thu Dec 7 11:04:23 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Thu, 7 Dec 2017 17:04:23 +0100 Subject: SystemError: error return without exception set In-Reply-To: References: Message-ID: <38e29b2d-ce0f-3a85-04e2-f7f281371c65@gmx.com> On 12/07/2017 04:36 PM, Natalie Leung wrote: > The code stops at "py_send(openModel)" with an error message that reads: Traceback (most recent call last): File "[my file path]", line 11, in py_send(openModel) > SystemError: error return without exception set > > I tried running the code on different platforms (e.g. Command Prompt, Wing 101, python.exe) and I get the same result. What could be the problem? > I presume they have written an extension module, but haven't done their error handling correctly and are eating some internal information about the error that occurred. Judging by some quick searches online, the software is closed source right? In that case, you could try emailing the provider. If this is the case, you might try to attach to the extension code in a debugger, though I'd assume they've compiled it in a way to make that pretty difficult. Another approach might be not to use the python bindings, but to use whatever other binding are available (say in C?). Then you could try to set things up in the same way and see if an error occurs there and if that error has more information than yours. Cheers, Thomas From natalieleung.29 at gmail.com Thu Dec 7 11:15:01 2017 From: natalieleung.29 at gmail.com (Natalie Leung) Date: Thu, 7 Dec 2017 08:15:01 -0800 (PST) Subject: SystemError: error return without exception set In-Reply-To: References: <38e29b2d-ce0f-3a85-04e2-f7f281371c65@gmx.com> Message-ID: <2f7071e6-2599-4cad-b19f-5ff0ea26458e@googlegroups.com> On Thursday, December 7, 2017 at 11:00:37 AM UTC-5, Thomas Nyberg wrote: > On 12/07/2017 04:36 PM, Natalie Leung wrote: > > The code stops at "py_send(openModel)" with an error message that reads: Traceback (most recent call last): File "[my file path]", line 11, in py_send(openModel) > > SystemError: error return without exception set > > > > I tried running the code on different platforms (e.g. Command Prompt, Wing 101, python.exe) and I get the same result. What could be the problem? > > > > I presume they have written an extension module, but haven't done their > error handling correctly and are eating some internal information about > the error that occurred. Judging by some quick searches online, the > software is closed source right? In that case, you could try emailing > the provider. > > If this is the case, you might try to attach to the extension code in a > debugger, though I'd assume they've compiled it in a way to make that > pretty difficult. Another approach might be not to use the python > bindings, but to use whatever other binding are available (say in C?). > Then you could try to set things up in the same way and see if an error > occurs there and if that error has more information than yours. > > Cheers, > Thomas Hi Thomas, You are correct in that the software and its packages are close-sourced. I have emailed the provider but their technical support staff has stated that they have exhausted of all ideas. An interesting thing to note is that this part of the code has been previously used by another individual with success, on the same computer. Kind regards, Natalie From python at mrabarnett.plus.com Thu Dec 7 11:19:33 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 7 Dec 2017 16:19:33 +0000 Subject: SystemError: error return without exception set In-Reply-To: References: Message-ID: <1fe3847c-00dc-5d08-19f0-9490dee8236b@mrabarnett.plus.com> On 2017-12-07 15:36, Natalie Leung wrote: > I am trying to use Python to communicate and send commands in MSC Marc. A part of the code looks something like this: > > from py_mentat import* > > directory = '[specified the file path to my model]' > marcModel = '[name of my model]' > > py_echo(0) > openModel = '*new_model yes *open_model "'+ directory + marcModel +'"' > py_send(openModel) > > > The code stops at "py_send(openModel)" with an error message that reads: Traceback (most recent call last): File "[my file path]", line 11, in py_send(openModel) > SystemError: error return without exception set > > I tried running the code on different platforms (e.g. Command Prompt, Wing 101, python.exe) and I get the same result. What could be the problem? > It looks like it's calling some code written in C that's returning NULL, which indicates there's an error. The code should've set the exception that should be raised, but it hasn't done that. That's a bug in the C code. From tomuxiong at gmx.com Thu Dec 7 11:27:48 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Thu, 7 Dec 2017 17:27:48 +0100 Subject: SystemError: error return without exception set In-Reply-To: <2f7071e6-2599-4cad-b19f-5ff0ea26458e@googlegroups.com> References: <38e29b2d-ce0f-3a85-04e2-f7f281371c65@gmx.com> <2f7071e6-2599-4cad-b19f-5ff0ea26458e@googlegroups.com> Message-ID: On 12/07/2017 05:15 PM, Natalie Leung wrote: > Hi Thomas, > > You are correct in that the software and its packages are close-sourced. I have emailed the provider but their technical support staff has stated that they have exhausted of all ideas. > > An interesting thing to note is that this part of the code has been previously used by another individual with success, on the same computer. > > Kind regards, > > Natalie > I would recommend a few things then. 0) See if you can access the code in the form that was previously sucessfully run and compare. To both versions do the following steps: 1) Make sure to rip out all extraneous code. I.e. only leave lines of code in if they absolutely need to be there. Hard-code paths, etc. Make sure you have an absolutely minimal script. 2) Make sure the file paths really are where the code thinks they are. Check permissions. In this case just write what the openModel string should be in directly (removing string concatenation). 3) Look at all the strings, paths, involved and see if things make sense. Also as an aside, look at the format of the string openModel and make sure it's a valid Marc command. It looks like it's basically a command in a domain specific language so that language should be documented and you might be able to find it. Good luck. Cheers, Thomas From rosuav at gmail.com Thu Dec 7 12:22:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Dec 2017 04:22:33 +1100 Subject: SystemError: error return without exception set In-Reply-To: References: Message-ID: On Fri, Dec 8, 2017 at 2:36 AM, Natalie Leung wrote: > I am trying to use Python to communicate and send commands in MSC Marc. A part of the code looks something like this: > > from py_mentat import* > > directory = '[specified the file path to my model]' > marcModel = '[name of my model]' > > py_echo(0) > openModel = '*new_model yes *open_model "'+ directory + marcModel +'"' > py_send(openModel) > > > The code stops at "py_send(openModel)" with an error message that reads: Traceback (most recent call last): File "[my file path]", line 11, in py_send(openModel) > SystemError: error return without exception set > > I tried running the code on different platforms (e.g. Command Prompt, Wing 101, python.exe) and I get the same result. What could be the problem? In its purest sense, that error is a bug inside a Python extension module (as others have mentioned). Since the failure is basically "hey, you said you raised an exception, but I can't find the exception you thought you were raising", it's quite probable that there is a bug in your Python code; go back to the tutorial for Marc, and see if you can find an issue. Unfortunately you're flying blind here, but maybe you can figure something out even without the usual help of the error message. But regardless, the bug first and foremost is in the extension module. The module's creator should be able to audit the py_send function to figure out where it is returning NULL without calling one of the "raise exception" functions. ChrisA From python at mrabarnett.plus.com Thu Dec 7 13:28:18 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 7 Dec 2017 18:28:18 +0000 Subject: SystemError: error return without exception set In-Reply-To: References: Message-ID: <9fc7d181-31aa-c63b-facb-0bc94a09cf85@mrabarnett.plus.com> On 2017-12-07 17:22, Chris Angelico wrote: > On Fri, Dec 8, 2017 at 2:36 AM, Natalie Leung wrote: >> I am trying to use Python to communicate and send commands in MSC Marc. A part of the code looks something like this: >> >> from py_mentat import* >> >> directory = '[specified the file path to my model]' >> marcModel = '[name of my model]' >> >> py_echo(0) >> openModel = '*new_model yes *open_model "'+ directory + marcModel +'"' >> py_send(openModel) >> >> >> The code stops at "py_send(openModel)" with an error message that reads: Traceback (most recent call last): File "[my file path]", line 11, in py_send(openModel) >> SystemError: error return without exception set >> >> I tried running the code on different platforms (e.g. Command Prompt, Wing 101, python.exe) and I get the same result. What could be the problem? > > In its purest sense, that error is a bug inside a Python extension > module (as others have mentioned). Since the failure is basically > "hey, you said you raised an exception, but I can't find the exception > you thought you were raising", it's quite probable that there is a bug > in your Python code; go back to the tutorial for Marc, and see if you > can find an issue. Unfortunately you're flying blind here, but maybe > you can figure something out even without the usual help of the error > message. > > But regardless, the bug first and foremost is in the extension module. > The module's creator should be able to audit the py_send function to > figure out where it is returning NULL without calling one of the > "raise exception" functions. > It's probably that the code is assuming that call somewhere to the Python API is returning a reference, but sometimes it isn't. _All_ such return values should be checked for NULL. From ethan at stoneleaf.us Thu Dec 7 13:28:33 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Dec 2017 10:28:33 -0800 Subject: Stackoverflow question: Is there a built-in identity function in Python? Message-ID: <5A298851.8030404@stoneleaf.us> The simple answer is No, and all the answers agree on that point. It does beg the question of what an identity function is, though. My contention is that an identity function is a do-nothing function that simply returns what it was given: --> identity(1) 1 --> identity('spam') 'spam' --> identity('spam', 'eggs', 7) ('spam', 'eggs', 7) Of the five answers to that SO question, mine is the only one that will correctly handle those three examples. If you agree with my contention feel free to up-vote my answer. :) https://stackoverflow.com/a/8748063/208880 -- ~Ethan~ From rosuav at gmail.com Thu Dec 7 13:31:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Dec 2017 05:31:46 +1100 Subject: SystemError: error return without exception set In-Reply-To: <9fc7d181-31aa-c63b-facb-0bc94a09cf85@mrabarnett.plus.com> References: <9fc7d181-31aa-c63b-facb-0bc94a09cf85@mrabarnett.plus.com> Message-ID: On Fri, Dec 8, 2017 at 5:28 AM, MRAB wrote: > On 2017-12-07 17:22, Chris Angelico wrote: >> >> On Fri, Dec 8, 2017 at 2:36 AM, Natalie Leung >> wrote: >>> >>> I am trying to use Python to communicate and send commands in MSC Marc. A >>> part of the code looks something like this: >>> >>> from py_mentat import* >>> >>> directory = '[specified the file path to my model]' >>> marcModel = '[name of my model]' >>> >>> py_echo(0) >>> openModel = '*new_model yes *open_model "'+ directory + marcModel +'"' >>> py_send(openModel) >>> >>> >>> The code stops at "py_send(openModel)" with an error message that reads: >>> Traceback (most recent call last): File "[my file path]", line 11, in >>> py_send(openModel) >>> SystemError: error return without exception set >>> >>> I tried running the code on different platforms (e.g. Command Prompt, >>> Wing 101, python.exe) and I get the same result. What could be the problem? >> >> >> In its purest sense, that error is a bug inside a Python extension >> module (as others have mentioned). Since the failure is basically >> "hey, you said you raised an exception, but I can't find the exception >> you thought you were raising", it's quite probable that there is a bug >> in your Python code; go back to the tutorial for Marc, and see if you >> can find an issue. Unfortunately you're flying blind here, but maybe >> you can figure something out even without the usual help of the error >> message. >> >> But regardless, the bug first and foremost is in the extension module. >> The module's creator should be able to audit the py_send function to >> figure out where it is returning NULL without calling one of the >> "raise exception" functions. >> > It's probably that the code is assuming that call somewhere to the Python > API is returning a reference, but sometimes it isn't. > > _All_ such return values should be checked for NULL. Mmm.... true. Forgot about that part. So, yes, that's a different type of failure that could be happening. Makes the audit a bit harder. ChrisA From rudplatt at gmail.com Thu Dec 7 13:42:20 2017 From: rudplatt at gmail.com (rudplatt at gmail.com) Date: Thu, 7 Dec 2017 10:42:20 -0800 (PST) Subject: Python installer hangs in Windows 7 In-Reply-To: References: <765703485.1601081.1486357381135.ref@mail.yahoo.com> <765703485.1601081.1486357381135@mail.yahoo.com> Message-ID: <56e56dc8-d7a7-41f1-918e-060e6d8883f4@googlegroups.com> On Monday, December 4, 2017 at 3:44:48 PM UTC-5, christian... at gmail.com wrote: > Same with me, except that I tried to install Python 3.6.3. Unchecking "Install launcher for all users" helped, however. I'm having the same issue. I need Python to be available for all users. Has anyone found a solution? I'm using Windows 7, by the way. From __peter__ at web.de Thu Dec 7 13:53:43 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Dec 2017 19:53:43 +0100 Subject: Stackoverflow question: Is there a built-in identity function in Python? References: <5A298851.8030404@stoneleaf.us> Message-ID: Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. > > My contention is that an identity function is a do-nothing function that > simply returns what it was given: > > --> identity(1) > 1 > > --> identity('spam') > 'spam' > > --> identity('spam', 'eggs', 7) > ('spam', 'eggs', 7) Hm, what does -- and what should -- identity(('spam', 'eggs', 7)) produce? > > Of the five answers to that SO question, mine is the only one that will > correctly handle those three examples. If you > agree with my contention feel free to up-vote my answer. :) > > https://stackoverflow.com/a/8748063/208880 > > -- > ~Ethan~ From rosuav at gmail.com Thu Dec 7 13:58:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Dec 2017 05:58:41 +1100 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> Message-ID: On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__peter__ at web.de> wrote: > Ethan Furman wrote: > >> The simple answer is No, and all the answers agree on that point. >> >> It does beg the question of what an identity function is, though. >> >> My contention is that an identity function is a do-nothing function that >> simply returns what it was given: >> >> --> identity(1) >> 1 >> >> --> identity('spam') >> 'spam' >> >> --> identity('spam', 'eggs', 7) >> ('spam', 'eggs', 7) > > Hm, what does -- and what should -- > > identity(('spam', 'eggs', 7)) > > produce? The same thing. And so should identity((('spam', 'eggs', 7))) and identity(((('spam', 'eggs', 7)))) and identity((((('spam', 'eggs', 7))))). For consistency, identity 'spam', 'eggs', 7 should work too. ChrisA From ethan at stoneleaf.us Thu Dec 7 14:20:18 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Dec 2017 11:20:18 -0800 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> Message-ID: <5A299472.10705@stoneleaf.us> On 12/07/2017 10:53 AM, Peter Otten wrote: > Ethan Furman wrote: > >> The simple answer is No, and all the answers agree on that point. >> >> It does beg the question of what an identity function is, though. >> >> My contention is that an identity function is a do-nothing function that >> simply returns what it was given: >> >> --> identity(1) >> 1 >> >> --> identity('spam') >> 'spam' >> >> --> identity('spam', 'eggs', 7) >> ('spam', 'eggs', 7) > > Hm, what does -- and what should -- > > identity(('spam', 'eggs', 7)) > > produce? Well, since it's the lowly "," that makes a tuple (not the parentheses), those extra parentheses don't have any affect. If you were trying to get a 3-item tuple inside a 1-item tuple: (('spam', 'eggs', 7), ) Then you would need: --> identity( (('spam', 'eggs', 7), ) ) (('spam', 'eggs', 7),) Okay, actually sometimes it takes both. ;) -- ~Ethan~ From lele at metapensiero.it Thu Dec 7 14:23:20 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 07 Dec 2017 20:23:20 +0100 Subject: SystemError: error return without exception set References: <9fc7d181-31aa-c63b-facb-0bc94a09cf85@mrabarnett.plus.com> Message-ID: <87shcm1gwn.fsf@metapensiero.it> Chris Angelico writes: > On Fri, Dec 8, 2017 at 5:28 AM, MRAB wrote: >> It's probably that the code is assuming that call somewhere to the Python >> API is returning a reference, but sometimes it isn't. >> >> _All_ such return values should be checked for NULL. > > Mmm.... true. Forgot about that part. So, yes, that's a different type > of failure that could be happening. Makes the audit a bit harder. More probably the problem is not directly from a Python API, as most of the time when such APIs return NULL they also call PyErr_SetXXX() appropriately. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From ned at nedbatchelder.com Thu Dec 7 14:23:21 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 7 Dec 2017 14:23:21 -0500 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: <5A298851.8030404@stoneleaf.us> References: <5A298851.8030404@stoneleaf.us> Message-ID: On 12/7/17 1:28 PM, Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. > > My contention is that an identity function is a do-nothing function > that simply returns what it was given: > > --> identity(1) > 1 > > --> identity('spam') > 'spam' > > --> identity('spam', 'eggs', 7) > ('spam', 'eggs', 7) I don't see why this last case should hold.? Why does the function take more than one argument?? And if it does, then why doesn't it work like this? ??? --> identity('spam') ??? ('spam',) (because then it wouldn't be an identity function!)? Trying to handle the multi-argument case seems like it adds an unneeded special case to the function. --Ned. From lele at metapensiero.it Thu Dec 7 14:29:03 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 07 Dec 2017 20:29:03 +0100 Subject: Stackoverflow question: Is there a built-in identity function in Python? References: <5A298851.8030404@stoneleaf.us> Message-ID: <87o9na1gn4.fsf@metapensiero.it> Chris Angelico writes: > On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__peter__ at web.de> wrote: >> >> Hm, what does -- and what should -- >> >> identity(('spam', 'eggs', 7)) >> >> produce? > > The same thing. And so should identity((('spam', 'eggs', 7))) and > identity(((('spam', 'eggs', 7)))) and identity((((('spam', 'eggs', > 7))))). > > For consistency, identity 'spam', 'eggs', 7 should work too. So you think that identity('spam', 'eggs', 7) \ == identity(('spam', 'eggs', 7)) \ == identity((('spam', 'eggs', 7),)) \ == identity(((('spam', 'eggs', 7),),)) should yield True? ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From rosuav at gmail.com Thu Dec 7 14:32:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Dec 2017 06:32:55 +1100 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: <87o9na1gn4.fsf@metapensiero.it> References: <5A298851.8030404@stoneleaf.us> <87o9na1gn4.fsf@metapensiero.it> Message-ID: On Fri, Dec 8, 2017 at 6:29 AM, Lele Gaifax wrote: > Chris Angelico writes: > >> On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__peter__ at web.de> wrote: >>> >>> Hm, what does -- and what should -- >>> >>> identity(('spam', 'eggs', 7)) >>> >>> produce? >> >> The same thing. And so should identity((('spam', 'eggs', 7))) and >> identity(((('spam', 'eggs', 7)))) and identity((((('spam', 'eggs', >> 7))))). >> >> For consistency, identity 'spam', 'eggs', 7 should work too. > > So you think that > > identity('spam', 'eggs', 7) \ > == identity(('spam', 'eggs', 7)) \ > == identity((('spam', 'eggs', 7),)) \ > == identity(((('spam', 'eggs', 7),),)) > > should yield True? No, because you're adding commas. Commas are, like, really important, yo? ChrisA From ethan at stoneleaf.us Thu Dec 7 14:41:13 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Dec 2017 11:41:13 -0800 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> Message-ID: <5A299959.5090906@stoneleaf.us> On 12/07/2017 11:23 AM, Ned Batchelder wrote: > On 12/7/17 1:28 PM, Ethan Furman wrote: >> --> identity('spam', 'eggs', 7) >> ('spam', 'eggs', 7) > > I don't see why this last case should hold. Why does the function take more than one argument? And if it does, then > why doesn't it work like this? > > --> identity('spam') > ('spam',) > > (because then it wouldn't be an identity function!) Trying to handle the multi-argument case seems like it adds an > unneeded special case to the function. --> a = 'spam' --> a == neds_identity(a) False ;) -- ~Ethan~ From p.f.moore at gmail.com Thu Dec 7 14:46:03 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 7 Dec 2017 19:46:03 +0000 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: <5A298851.8030404@stoneleaf.us> References: <5A298851.8030404@stoneleaf.us> Message-ID: On 7 December 2017 at 18:28, Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. > > My contention is that an identity function is a do-nothing function that > simply returns what it was given: > > --> identity(1) > 1 > > --> identity('spam') > 'spam' > > --> identity('spam', 'eggs', 7) > ('spam', 'eggs', 7) > > Of the five answers to that SO question, mine is the only one that will > correctly handle those three examples. If you agree with my contention feel > free to up-vote my answer. :) IMO (as a mathematician ;-)) the identity function is a *single-argument* function that returns the value passed to it. So: def identity(x): return x See https://en.wikipedia.org/wiki/Identity_function identity(1,2) is an error. Extending the definition to multiple arguments causes all sorts of confusion, as you've seen. Paul From ethan at stoneleaf.us Thu Dec 7 15:10:47 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Dec 2017 12:10:47 -0800 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> Message-ID: <5A29A047.9020508@stoneleaf.us> On 12/07/2017 11:46 AM, Paul Moore wrote: > On 7 December 2017 at 18:28, Ethan Furman wrote: >> The simple answer is No, and all the answers agree on that point. >> >> It does beg the question of what an identity function is, though. >> >> My contention is that an identity function is a do-nothing function that >> simply returns what it was given: >> >> --> identity(1) >> 1 >> >> --> identity('spam') >> 'spam' >> >> --> identity('spam', 'eggs', 7) >> ('spam', 'eggs', 7) >> >> Of the five answers to that SO question, mine is the only one that will >> correctly handle those three examples. If you agree with my contention feel >> free to up-vote my answer. :) > > IMO (as a mathematician ;-)) the identity function is a > *single-argument* function that returns the value passed to it. So: > > def identity(x): > return x > > See https://en.wikipedia.org/wiki/Identity_function > > identity(1,2) is an error. > > Extending the definition to multiple arguments causes all sorts of > confusion, as you've seen. So in other words: for thing in ( 1, (2, 3), 'spam', ('eggs', 'green', 4.15), (1, ), ): assert thing == identity(thing) try: identity('too', 'many', 'things') except TypeError: pass else: raise Exception('identity should only be passed a single item') Thank you for clearing that up, Paul! I up-voted your answer, hopefully others will also: https://stackoverflow.com/a/47702881/208880 -- ~Ethan~ From nathan.ernst at gmail.com Thu Dec 7 15:12:03 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Thu, 7 Dec 2017 14:12:03 -0600 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> Message-ID: There is a built-in identity function in Python. The function is called 'id'. See https://docs.python.org/3/library/functions.html#id Note that this will not behave the same across different Python runtimes. e.g. CPython, IronPython or Jython all implement this differently. An example: Python 3.5.2 (default, Sep 14 2017, 22:51:06) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> a = 1 >>> b = 2 >>> id(a) 10911168 >>> id(b) 10911200 >>> c = 1 >>> id (c) 10911168 Regards, Nathan On Thu, Dec 7, 2017 at 1:46 PM, Paul Moore wrote: > On 7 December 2017 at 18:28, Ethan Furman wrote: > > The simple answer is No, and all the answers agree on that point. > > > > It does beg the question of what an identity function is, though. > > > > My contention is that an identity function is a do-nothing function that > > simply returns what it was given: > > > > --> identity(1) > > 1 > > > > --> identity('spam') > > 'spam' > > > > --> identity('spam', 'eggs', 7) > > ('spam', 'eggs', 7) > > > > Of the five answers to that SO question, mine is the only one that will > > correctly handle those three examples. If you agree with my contention > feel > > free to up-vote my answer. :) > > IMO (as a mathematician ;-)) the identity function is a > *single-argument* function that returns the value passed to it. So: > > def identity(x): > return x > > See https://en.wikipedia.org/wiki/Identity_function > > identity(1,2) is an error. > > Extending the definition to multiple arguments causes all sorts of > confusion, as you've seen. > > Paul > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu Dec 7 15:24:40 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Dec 2017 21:24:40 +0100 Subject: Stackoverflow question: Is there a built-in identity function in Python? References: <5A298851.8030404@stoneleaf.us> <5A299472.10705@stoneleaf.us> Message-ID: Ethan Furman wrote: > On 12/07/2017 10:53 AM, Peter Otten wrote: >> Ethan Furman wrote: >> >>> The simple answer is No, and all the answers agree on that point. >>> >>> It does beg the question of what an identity function is, though. >>> >>> My contention is that an identity function is a do-nothing function that >>> simply returns what it was given: >>> >>> --> identity(1) >>> 1 >>> >>> --> identity('spam') >>> 'spam' >>> >>> --> identity('spam', 'eggs', 7) >>> ('spam', 'eggs', 7) >> >> Hm, what does -- and what should -- >> >> identity(('spam', 'eggs', 7)) >> >> produce? > > Well, since it's the lowly "," that makes a tuple (not the parentheses), > those extra parentheses don't have any affect. identity((a, b, c)) calls identity() with one argument whereas identity(a, b, c) calls identity() with three arguments. That's certainly an effect; you just undo it with your test for len(args) == 1. That means that your identity() function throws away the information about the number of arguments it was called with. I would expect an identity() function to be lossless ("bijective") and I think that is possible only if you restrict it to a single argument. > > If you were trying to get a 3-item tuple inside a 1-item tuple: > > (('spam', 'eggs', 7), ) > > Then you would need: > > --> identity( (('spam', 'eggs', 7), ) ) > (('spam', 'eggs', 7),) > > Okay, actually sometimes it takes both. ;) > > -- > ~Ethan~ From ned at nedbatchelder.com Thu Dec 7 15:25:45 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 7 Dec 2017 15:25:45 -0500 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: <5A299959.5090906@stoneleaf.us> References: <5A298851.8030404@stoneleaf.us> <5A299959.5090906@stoneleaf.us> Message-ID: On 12/7/17 2:41 PM, Ethan Furman wrote: > On 12/07/2017 11:23 AM, Ned Batchelder wrote: >> On 12/7/17 1:28 PM, Ethan Furman wrote: > >>> --> identity('spam', 'eggs', 7) >>> ('spam', 'eggs', 7) >> >> I don't see why this last case should hold.? Why does the function >> take more than one argument?? And if it does, then >> why doesn't it work like this? >> >> ???? --> identity('spam') >> ???? ('spam',) >> >> (because then it wouldn't be an identity function!)? Trying to handle >> the multi-argument case seems like it adds an >> unneeded special case to the function. > > --> a = 'spam' > --> a == neds_identity(a) > False > Right, but why does one argument return the argument, but n>1 returns a tuple of the args? --Ned. From rosuav at gmail.com Thu Dec 7 15:35:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Dec 2017 07:35:56 +1100 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> <5A299959.5090906@stoneleaf.us> Message-ID: On Fri, Dec 8, 2017 at 7:25 AM, Ned Batchelder wrote: > On 12/7/17 2:41 PM, Ethan Furman wrote: >> >> On 12/07/2017 11:23 AM, Ned Batchelder wrote: >>> >>> On 12/7/17 1:28 PM, Ethan Furman wrote: >> >> >>>> --> identity('spam', 'eggs', 7) >>>> ('spam', 'eggs', 7) >>> >>> >>> I don't see why this last case should hold. Why does the function take >>> more than one argument? And if it does, then >>> why doesn't it work like this? >>> >>> --> identity('spam') >>> ('spam',) >>> >>> (because then it wouldn't be an identity function!) Trying to handle the >>> multi-argument case seems like it adds an >>> unneeded special case to the function. >> >> >> --> a = 'spam' >> --> a == neds_identity(a) >> False >> > > Right, but why does one argument return the argument, but n>1 returns a > tuple of the args? > Because it's impossible to return multiple values. IMO the "identity function" is defined only in terms of one single argument, so all of this is meaningless. ChrisA From ethan at stoneleaf.us Thu Dec 7 16:03:22 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Dec 2017 13:03:22 -0800 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> <5A299472.10705@stoneleaf.us> Message-ID: <5A29AC9A.3010100@stoneleaf.us> On 12/07/2017 12:24 PM, Peter Otten wrote: > identity((a, b, c)) > > calls identity() with one argument whereas > > identity(a, b, c) > > calls identity() with three arguments. That's certainly an effect; you just > undo it with your test for len(args) == 1. That means that your identity() > function throws away the information about the number of arguments it was > called with. I would expect an identity() function to be lossless > ("bijective") and I think that is possible only if you restrict it to a > single argument. Thanks for exposing/clarifying that flaw. I have removed my answer. -- ~Ethan~ From lele at metapensiero.it Thu Dec 7 16:30:27 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 07 Dec 2017 22:30:27 +0100 Subject: Stackoverflow question: Is there a built-in identity function in Python? References: <5A298851.8030404@stoneleaf.us> <87o9na1gn4.fsf@metapensiero.it> Message-ID: <87k1xy1b0s.fsf@metapensiero.it> Chris Angelico writes: > On Fri, Dec 8, 2017 at 6:29 AM, Lele Gaifax wrote: >> Chris Angelico writes: >> >>> On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__peter__ at web.de> wrote: >>>> >>>> Hm, what does -- and what should -- >>>> >>>> identity(('spam', 'eggs', 7)) >>>> >>>> produce? >>> >>> The same thing. And so should identity((('spam', 'eggs', 7))) and >>> identity(((('spam', 'eggs', 7)))) and identity((((('spam', 'eggs', >>> 7))))). >>> >>> For consistency, identity 'spam', 'eggs', 7 should work too. >> >> So you think that >> >> identity('spam', 'eggs', 7) \ >> == identity(('spam', 'eggs', 7)) \ >> == identity((('spam', 'eggs', 7),)) \ >> == identity(((('spam', 'eggs', 7),),)) >> >> should yield True? > > No, because you're adding commas. Commas are, like, really important, yo? I probably misunderstood your "The same thing" answer to Peter's question, but IMHO `identity(('spam','eggs',7))` should not return the same as `identity('spam','eggs',7)` as I got from your answer, should it? ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From rosuav at gmail.com Thu Dec 7 16:34:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Dec 2017 08:34:50 +1100 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: <87k1xy1b0s.fsf@metapensiero.it> References: <5A298851.8030404@stoneleaf.us> <87o9na1gn4.fsf@metapensiero.it> <87k1xy1b0s.fsf@metapensiero.it> Message-ID: On Fri, Dec 8, 2017 at 8:30 AM, Lele Gaifax wrote: > Chris Angelico writes: > >> On Fri, Dec 8, 2017 at 6:29 AM, Lele Gaifax wrote: >>> Chris Angelico writes: >>> >>>> On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__peter__ at web.de> wrote: >>>>> >>>>> Hm, what does -- and what should -- >>>>> >>>>> identity(('spam', 'eggs', 7)) >>>>> >>>>> produce? >>>> >>>> The same thing. And so should identity((('spam', 'eggs', 7))) and >>>> identity(((('spam', 'eggs', 7)))) and identity((((('spam', 'eggs', >>>> 7))))). >>>> >>>> For consistency, identity 'spam', 'eggs', 7 should work too. >>> >>> So you think that >>> >>> identity('spam', 'eggs', 7) \ >>> == identity(('spam', 'eggs', 7)) \ >>> == identity((('spam', 'eggs', 7),)) \ >>> == identity(((('spam', 'eggs', 7),),)) >>> >>> should yield True? >> >> No, because you're adding commas. Commas are, like, really important, yo? > > I probably misunderstood your "The same thing" answer to Peter's question, > but IMHO `identity(('spam','eggs',7))` should not return the same as > `identity('spam','eggs',7)` as I got from your answer, should it? > That's exactly the point under discussion. According to Ethan's posted implementation, multiple arguments get collected into a tuple. That means that passing three arguments results in a tuple, but passing a single argument (that happens to be a tuple of three things) returns that argument unchanged. So, yes, the two would return the same value. ChrisA From lawrencedo99 at gmail.com Thu Dec 7 16:40:22 2017 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 7 Dec 2017 13:40:22 -0800 (PST) Subject: SystemError: error return without exception set In-Reply-To: <2f7071e6-2599-4cad-b19f-5ff0ea26458e@googlegroups.com> References: <38e29b2d-ce0f-3a85-04e2-f7f281371c65@gmx.com> <2f7071e6-2599-4cad-b19f-5ff0ea26458e@googlegroups.com> Message-ID: <6e668132-78ab-4be0-bf4c-3d4197ca0e7e@googlegroups.com> On Friday, December 8, 2017 at 5:15:35 AM UTC+13, Natalie Leung wrote: > I have emailed the provider but their technical support staff has stated > that they have exhausted of all ideas. If they can?t supply you with a product fit for purpose, time to send it back for a refund. From p.f.moore at gmail.com Thu Dec 7 17:18:40 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 7 Dec 2017 22:18:40 +0000 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: References: <5A298851.8030404@stoneleaf.us> <5A299959.5090906@stoneleaf.us> Message-ID: On 7 December 2017 at 20:35, Chris Angelico wrote: > Because it's impossible to return multiple values. IMO the "identity > function" is defined only in terms of one single argument, so all of > this is meaningless. Indeed, this is the key point. The Python language only allows returning one value (which can be a tuple, sure, but it's still *one value*). So a function that returns what it's called with can only have one argument. Anything else isn't an "identity function". Certainly, it might be useful - "def f(arg, *rest, **kw): return arg" could be a useful dummy function in some contexts, for example - but it's not an identity function in the strict sense (and so you can't avoid having to specify its behaviour explicitly). Paul From ben+python at benfinney.id.au Thu Dec 7 18:38:24 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 08 Dec 2017 10:38:24 +1100 Subject: Stackoverflow question: Is there a built-in identity function in Python? References: <5A298851.8030404@stoneleaf.us> Message-ID: <85r2s6qfbj.fsf@benfinney.id.au> Ethan Furman writes: > My contention is that an identity function is a do-nothing function > that simply returns what it was given: > > --> identity(1) > 1 > > --> identity('spam') > 'spam' These seem good to me. One argument given, the same result returned. > --> identity('spam', 'eggs', 7) > ('spam', 'eggs', 7) That's a confusingly inconsistent result, as pointed out by other responses in this thread. I would expect an identity function to accept exactly one positional argument. Given more than one positional argument, it should raise a TypeError. -- \ Legionnaire: ?We have their leader captive!? C?sar: ?Is he | `\ bound?? Legionnaire: ?Of his health I know not, sir.? ?The | _o__) Goon Show, _The Histories Of Pliny The Elder_ | Ben Finney From ben+python at benfinney.id.au Thu Dec 7 18:43:28 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 08 Dec 2017 10:43:28 +1100 Subject: Stackoverflow question: Is there a built-in identity function in Python? References: <5A298851.8030404@stoneleaf.us> Message-ID: <85mv2uqf33.fsf@benfinney.id.au> Nathan Ernst writes: > There is a built-in identity function in Python. The function is called > 'id'. It should be clear from the rest of the thread. But, to be explicit: That's not what is meant by ?identity function?, and the Python ?id? function is not an identity function. The Python ?id? function returns the ?identity of the object?, a Python-specific concept that is unrelated to the identity function. An ?identity function? is mathematics terminology for ?a function that always returns the same value that was used as its argument.? -- \ ?But Marge, what if we chose the wrong religion? Each week we | `\ just make God madder and madder.? ?Homer, _The Simpsons_ | _o__) | Ben Finney From rantingrickjohnson at gmail.com Thu Dec 7 19:32:53 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 7 Dec 2017 16:32:53 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: <684fdd3b-f28b-452b-9429-91c167e9a5c4@googlegroups.com> On Wednesday, December 6, 2017 at 8:29:23 PM UTC-6, Steve D'Aprano wrote: [...] > If the term "OS file associations" is ever so slightly > inaccurate (it's not the actual OS kernel that does the > associating, but the desktop environment), well, we can > probably say the same thing about Mac OS X and maybe even > Windows itself. I don't believe many folks think about the OS in the strictly narrow view that it is "only a kernel existing below higher abstractions", as much as they accept the OS as encompassing the OS kernel and all the ooey and gooey interfacing layers on top. I suppose you might call that a "system", but such a word is far too ambiguous. IOWs: it may not be technically correct, but it is the accepted norm. From python at bladeshadow.org Thu Dec 7 20:08:31 2017 From: python at bladeshadow.org (Python) Date: Thu, 7 Dec 2017 19:08:31 -0600 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: <20171208010831.GH30413@bladeshadow.org> On Thu, Dec 07, 2017 at 01:29:11PM +1100, Steve D'Aprano wrote: > On Thu, 7 Dec 2017 08:22 am, Python wrote: > >> > Linux doesn?t do ?OS file associations?. > >> > >> Then how does my Linux box know that when I double-click on a text file, it > >> launches kwrite rather than (say) the Gimp or LibreOffice? > > > > The answer to that is (sadly) complicated. > > Actually, no, the answer to my question is very simple: Lawrence is mistaken > about Linux not doing file associations. It does -- it is merely handled by > the desktop environment (if there is one). Pedantically speaking, this is only *probably true*, not certainly true (e.g. running Linux on a text console with something like midnight commander, some unrelated file manager while running a particular desktop environment, etc.). But more importantly, practically speaking, it still doesn't really provide much more help to the OP than Lawrence's answer. He may well know already that the desktop environment is what does the job (and probably does even, in broad terms, if he's familiar with computers in general), but have no idea how to configure it. A reasonably helpful answer would be one that mentioned a few of the likely possibilities (Gnome, KDE, Unity, /etc/mime.types, "other"), and gave hints for how to find out the answer for each. A thoroughly helpful answer would be, well, outside the scope of this list/group. Pedantry has its place, FWIW. In the computer field, as with other science and engineering disciplines, often precision is much more essential than in other fields. I personally find such precision is especially warranted if you take it upon yourself to criticize what someone else has said. Though, providing such precision via natural language often turns out to be more challenging than one would hope... From python at bladeshadow.org Thu Dec 7 21:02:31 2017 From: python at bladeshadow.org (Python) Date: Thu, 7 Dec 2017 20:02:31 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> Message-ID: <20171208020218.GI30413@bladeshadow.org> Hi Rick! On Wed, Dec 06, 2017 at 04:05:42PM -0800, Rick Johnson wrote: > Python wrote: > > [...] > > > THIS IS FALSE. CALLING A FUNCTION > > What *FUNCTION*? In this snippet (which again, we agreed was an incomplete academic example): if item: process(item) else: do_without_item() Can you please explain to me what sort of Python syntactical construct do_without_item() could be, other than a call to a Python callable object (i.e. a function)? Then, could you explain to me how that particular syntactical construct is in any way equivalent to the pass statement? Could you then explain to me how using that in the simple example given makes any sense whatsoever? [FWIW, if there is an answer to this, I am genuinely interested...] Since it can indeed be a function call, then if you can't do all of the above things, doesn't that imply that in the example given, do_witout_item() can't be anything BUT a function call? Even if it somehow doesn't by some logic that escapes me, for the purposes of this simple academic example, isn't it preferable to assume that it is the most obvious thing (i.e. a function call)? Isn't the else clause in fact NOT superfluous, because it illustrates that if the slice operation would be out of the container object's bounds, then item will be assigned a value that evaluates to false, enabling one to trigger the else clause of an if block to do something ONLY under that condition? > if "do_without_item()" had been defined, then you could call > it a function. But until you do, it's just a NameError. OK! Then could you explain to me how a NameError is equivalent to the pass statement? I thought one continued execution without any side effects, and the other required handling or else will stop the program. Isn't that in fact functionally nonequivalent? Thanks. From ethan at stoneleaf.us Thu Dec 7 21:04:05 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Dec 2017 18:04:05 -0800 Subject: Stackoverflow question: Is there a built-in identity function in Python? In-Reply-To: <5A298851.8030404@stoneleaf.us> References: <5A298851.8030404@stoneleaf.us> Message-ID: <5A29F315.8010907@stoneleaf.us> On 12/07/2017 10:28 AM, Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. Thankfully, Paul answered that question with a good explanation*. Thanks, everyone, for the discussion. -- ~Ethan~ * https://stackoverflow.com/a/47702881/208880 From pengyu.ut at gmail.com Fri Dec 8 00:55:48 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 7 Dec 2017 23:55:48 -0600 Subject: Anything similar to __END__ in perl Message-ID: Hi, perl has __END__ which ignore all the lines below it. Is there anything similar to __END__ in python? Thanks. -- Regards, Peng From nomail at com.invalid Fri Dec 8 04:08:24 2017 From: nomail at com.invalid (ast) Date: Fri, 8 Dec 2017 10:08:24 +0100 Subject: asyncio awaitable object Message-ID: <5a2a568c$0$3699$426a74cc@news.free.fr> Hello, According to: https://www.python.org/dev/peps/pep-0492/#await-expression an awaitable object is: - A native coroutine object returned from a native coroutine function - A generator-based coroutine object returned from a function decorated with types.coroutine() - An object with an __await__ method returning an iterator I dont understand the last one. For example in instruction "res = await obj" where obj has a __await__ method returning an iterator What kind of data this generator is supposed to provide when next() is applied to it and what are these data becoming ? what res contains when the iterator has finished to iterate ? It seems that PEP492 documentation says nothing about it (or I dont understand, english is not my native language) From Karsten.Hilbert at gmx.net Fri Dec 8 04:43:22 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 8 Dec 2017 10:43:22 +0100 Subject: Anything similar to __END__ in perl In-Reply-To: References: Message-ID: <20171208094321.GA3410@hermes.hilbert.loc> On Thu, Dec 07, 2017 at 11:55:48PM -0600, Peng Yu wrote: > Hi, perl has __END__ which ignore all the lines below it. > > Is there anything similar to __END__ in python? Thanks. Something similar is: import sys sys.exit() Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From nomail at com.invalid Fri Dec 8 04:48:48 2017 From: nomail at com.invalid (ast) Date: Fri, 8 Dec 2017 10:48:48 +0100 Subject: asyncio awaitable object In-Reply-To: <5a2a568c$0$3699$426a74cc@news.free.fr> References: <5a2a568c$0$3699$426a74cc@news.free.fr> Message-ID: <5a2a6005$0$4823$426a74cc@news.free.fr> "ast" a ?crit dans le message de news:5a2a568c$0$3699$426a74cc at news.free.fr... I made some experiment. It seems that the iterator shall provide None values, an other value raises an exception: "RuntimeError: Task got bad yield: 1" and in instruction "res = await obj", res got the StopIteration exception value See my test program and output. import asyncio class Test: def __init__(self): self.i = 0 def __await__(self): return self def __iter__(self): return self def __next__(self): if self.i < 5: self.i += 1 return None else: raise StopIteration(11) test = Test() async def coro1(): print("Enter coro1") res = await test print("end of coro1, res= ", res) async def coro2(): print("Enter coro2") for i in range(8): print("in coro2") await asyncio.sleep(0) loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait([coro1(), coro2()])) ========== RESTART ========== Enter coro1 Enter coro2 in coro2 in coro2 in coro2 in coro2 in coro2 end of coro1, res= 11 in coro2 in coro2 in coro2 From rustompmody at gmail.com Fri Dec 8 05:19:13 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Dec 2017 02:19:13 -0800 (PST) Subject: Anything similar to __END__ in perl In-Reply-To: References: <20171208094321.GA3410@hermes.hilbert.loc> Message-ID: On Friday, December 8, 2017 at 3:13:56 PM UTC+5:30, Karsten Hilbert wrote: > On Thu, Dec 07, 2017 at 11:55:48PM -0600, Peng Yu wrote: > > > Hi, perl has __END__ which ignore all the lines below it. > > > > Is there anything similar to __END__ in python? Thanks. > > Something similar is: > > import sys > sys.exit() That will give syntax (or something) errors for what follows I'd say something similar is """ eg ---- $ cat xyz.py def f(): print("hello world") f() """ Tyger Tyger burning bright In the forests of the night What immortal hand or eye Dare frame thy fearful symmetry """ From Karsten.Hilbert at gmx.net Fri Dec 8 05:28:53 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 8 Dec 2017 11:28:53 +0100 Subject: Anything similar to __END__ in perl In-Reply-To: References: <20171208094321.GA3410@hermes.hilbert.loc> Message-ID: <20171208102853.GB3410@hermes.hilbert.loc> On Fri, Dec 08, 2017 at 02:19:13AM -0800, Rustom Mody wrote: > > > Hi, perl has __END__ which ignore all the lines below it. > > > > > > Is there anything similar to __END__ in python? Thanks. > > > > Something similar is: > > > > import sys > > sys.exit() > > That will give syntax (or something) errors for what follows True enough, didn't think of that. However, OP asked for something _similar_ :-) Which proves that any answer needs a definition of "similar" by OP. Or at least: how similar is similar _enough_ to __END__ in Perl. Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From ned at nedbatchelder.com Fri Dec 8 05:52:21 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 8 Dec 2017 05:52:21 -0500 Subject: why won't slicing lists raise IndexError? In-Reply-To: <20171208020218.GI30413@bladeshadow.org> References: <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> <20171208020218.GI30413@bladeshadow.org> Message-ID: <2d28478c-7bbd-db13-474f-0d261efc0e28@nedbatchelder.com> On 12/7/17 9:02 PM, Python wrote: > Can you please explain to me .... Really, you just have to ignore him. --Ned. From rantingrickjohnson at gmail.com Fri Dec 8 08:12:35 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 8 Dec 2017 05:12:35 -0800 (PST) Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <5878a49c-896a-4a10-9f10-5fab3a0a2633@googlegroups.com> <5a26c3f6$0$2086$b1db1813$d948b532@news.astraweb.com> <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> <20171208020218.GI30413@bladeshadow.org> Message-ID: Python wrote: [...] > > In this snippet (which again, we agreed was an incomplete > academic example): > > if item: > process(item) > else: > do_without_item() > > Can you please explain to me what sort of Python > syntactical construct do_without_item() could be, other > than a call to a Python callable object (i.e. a function)? > Then, could you explain to me how that particular > syntactical construct is in any way equivalent to the pass > statement? Could you then explain to me how using that in > the simple example given makes any sense whatsoever? I have already backed my argument with multiple code examples, exhaustive explanations, and even constructed a metaphor that was slightly entertaining. Yet, none of those are good enough? Alas, allow me to try once more. Consider: > if item: > process(item) > else: > do_without_item() The above code sample is semantically equivalent to the following real-life "situational logic": [man sits on couch and enjoys sports programming] if thirsty: grab_beer_from_fridge() else: stay_on_couch() Above, just as with Terry's code, the else-clause cannot justify itself. And why you ask? Because, we were _already_ on the damned couch! The else-clause is a "do nothing" condition, hence, it is functionally equivalent to: else: pass *HENCE*, it is super-freaking-fluous! Get it? However. Here is an example which _can_ justify the else- clause if thirsty and (not tooLazyToMove): grab_beer_from_fridge() else: tell_wife_to_grab_beer() Heck, even tangential actions can be justified. Observe: import random if thirsty and (not tooLazyToMove): grab_beer_from_fridge() else: random.choice([ scratch_self, eat_tater_chip, change_channel, relieve_abdominal_pressure, ])() From ian.g.kelly at gmail.com Fri Dec 8 09:42:17 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Dec 2017 07:42:17 -0700 Subject: asyncio awaitable object In-Reply-To: <5a2a568c$0$3699$426a74cc@news.free.fr> References: <5a2a568c$0$3699$426a74cc@news.free.fr> Message-ID: On Fri, Dec 8, 2017 at 2:08 AM, ast wrote: > Hello, > > According to: https://www.python.org/dev/peps/pep-0492/#await-expression > an awaitable object is: > > - A native coroutine object returned from a native coroutine function > - A generator-based coroutine object returned from a function decorated with > types.coroutine() > - An object with an __await__ method returning an iterator > > I dont understand the last one. > > For example in instruction "res = await obj" > > where obj has a __await__ method returning an iterator > > What kind of data this generator is supposed to provide when next() is > applied to it and what are these data becoming ? > > what res contains when the iterator has finished to iterate ? > > It seems that PEP492 documentation says nothing about it (or I dont > understand, english is not my native language) I believe the reason that PEP492 doesn't specify that is because it only creates the keywords and specifies where they can be used. What values are passed by the iterator is an implementation detail of the asyncio framework, and the intention is that async/await should be usable by other async frameworks, not just asyncio. So the proper answer to the question "what kind of data should the iterator provide" is "it depends on framework". An example implementation of an object with an __await__ method is an asyncio.Future object. If you look at the definition of asyncio.Future, you can find its __await__ method. Here it is: __await__ = __iter__ Huh? To understand this, bear in mind that anywhere you can use "await", you would previously have used "yield from". To "yield from" something, that something must be iterable. So to "yield from" asyncio Futures, they must be iterable, which means they must have an __iter__ method. The protocol that asyncio uses for __await__ is the same that it uses __iter__, so when __await__ was added it returns an iterator which made __await__ literally a drop-in replacement of __iter__. So what does Future.__iter__ do? def __iter__(self): if not self.done(): self._asyncio_future_blocking = True yield self # This tells Task to wait for completion. assert self.done(), "yield from wasn't used with future" return self.result() # May raise too. It returns a generator that first checks if the future is already done. If it is, it just returns its result (which raises a StopIteration) without ever sleeping. Otherwise, it yields itself, exactly once. The chain of "yield from" / "await"s ultimately pass this future all the way down to the asyncio event loop, which adds it to the scheduler. When the future is done, the task is resumed and the flow of control goes back up the chain all the way to the futures, which asserts for sanity that it is now done and returns its result. So the answer to "what should the iterator yield for asyncio" is that it should yield unfinished asyncio Futures one at a time, with the expectation that they will be done when the iterator resumes. From python at bladeshadow.org Fri Dec 8 11:24:56 2017 From: python at bladeshadow.org (Python) Date: Fri, 8 Dec 2017 10:24:56 -0600 Subject: why won't slicing lists raise IndexError? In-Reply-To: References: <2df66aad-caba-4427-95fa-e34ce37a8f19@googlegroups.com> <20171206211101.GE30413@bladeshadow.org> <20171206232217.GG30413@bladeshadow.org> <20171208020218.GI30413@bladeshadow.org> Message-ID: <20171208162456.GJ30413@bladeshadow.org> On Fri, Dec 08, 2017 at 05:12:35AM -0800, Rick Johnson wrote: > I have already backed my argument with multiple code > examples, exhaustive explanations Which were all false and/or nonsensical. > > if item: > > process(item) > > else: > > do_without_item() > > The above code sample is semantically equivalent to the > following real-life "situational logic": > > [man sits on couch and enjoys sports programming] > > if thirsty: > grab_beer_from_fridge() > else: > stay_on_couch() So what you're ultimately saying is you're making an *assumption* that the English phrase "do without item" MEANS to do nothing, and therefore do_without_item() MUST be defined as pass. However both of those things are FALSE, and once again your entire argument is completely invalid. It's also true that such an assumption is antithetical to the example. So, your assumption is both logically and contextually nonsensical. If you're on a sinking boat, and you could stop the boat from sinking if you had a rubber seal, but you don't have one, you're forced to do_without_item(). Does that mean you're going to sit in the boat and let it sink with you in it? By your arguments, apparently YOU must... But the rest of us would try to fix the leak another way, or failing that, get the hell out of the boat. I like our definition of do_without_item() better. Ned is right, you just need to be ingored. From bob at mellowood.ca Fri Dec 8 13:36:11 2017 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 8 Dec 2017 11:36:11 -0700 Subject: Save and load initialized class Message-ID: I'm trying to something simple (yeah, right). Mainly I want to have a bunch of variables which my program needs and uses to be in a saveable/loadable block. Currently I have then all as a bunch of globals which works, but trying to keep track of them and the correct spellings, etc becomes a bit of maintenance nightmare. So, demonstrating all my cleverness I came up with: class Opts(): var1 = 123 var2 = "hello world" Notationally, it looks much like the variables are stored in a separate module. I can call these options from within a function with the simple notation: if Opts.var1 == 99 ... And, if I need to change a value I can: global Opts.var1 = 0 Further, and importantly, I can save the lot with: json.dump(Opts.__dict__, open("mybuffer", "w")) But, I can't figure out how to load the saved data back into my program. Doing z=json.load (open("mybuffer", "r")) loads a dictionary ... which makes sense since that is what I saved. So, can I now reset the values in Opts from a saved dictionary? Best, -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From larry.martell at gmail.com Fri Dec 8 17:57:51 2017 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 8 Dec 2017 17:57:51 -0500 Subject: scipy Message-ID: Trying to install scipy on ubuntu-trusty-64 running Python 2.7.6. It's failing with: $ sudo pip install scipy Downloading/unpacking scipy Downloading scipy-1.0.0.tar.gz (15.2MB): 15.2MB downloaded Running setup.py (path:/tmp/pip_build_root/scipy/setup.py) egg_info for package scipy /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires' Followed by many screens full of errors. Is that just a warning or is that the issue? I've installed many other packages without a problem on this same system. What is the issue here? From rustompmody at gmail.com Sat Dec 9 00:35:15 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Dec 2017 21:35:15 -0800 (PST) Subject: repeating posts Message-ID: <4b499518-27da-45ae-bf3c-33a8f1a14434@googlegroups.com> Repeating old posts again appearing [No not complaining? I know people are working on it. Thanks Skip and whoever else] Just thought I'd mention they are now mildly mojibaked From rosuav at gmail.com Sat Dec 9 01:15:38 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Dec 2017 17:15:38 +1100 Subject: f-string In-Reply-To: <1146633501@f38.n261.z1.binkp.net> References: <1146633501@f38.n261.z1.binkp.net> Message-ID: On Tue, Dec 5, 2017 at 6:37 PM, Ned Batchelder wrote: > On 12/5/17 7:16 PM, Steve D'Aprano wrote: >> compile('f"{spam} {eggs}"', '', 'single') > > $ python3.6 > Python 3.6.3 (default, Oct? 4 2017, 06:03:25) > [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> compile('f"{spam} {eggs}"', '', 'single') > at 0x105e79660, file "", line 1> > >>> co = _ > >>> spam = 17 > >>> eggs = 34 > >>> eval(co) > '17 34' > >>> dis.dis(co) > ? 1? ? ? ? ? ? ? ? ? ? 0 LOAD_NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 > (spam) > ? ? ? ? ? ? ? ? ? ? ? ? ? 2 FORMAT_VALUE? ? ? ? ? ? ? ? ? ? ? ? 0 > ? ? ? ? ? ? ? ? ? ? ? ? ? 4 LOAD_CONST? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 (' > ') > ? ? ? ? ? ? ? ? ? ? ? ? ? 6 LOAD_NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 > (eggs) > ? ? ? ? ? ? ? ? ? ? ? ? ? 8 FORMAT_VALUE? ? ? ? ? ? ? ? ? ? ? ? 0 > ? ? ? ? ? ? ? ? ? ? ? ? 10 BUILD_STRING? ? ? ? ? ? ? ? ? ? ? ? 3 > ? ? ? ? ? ? ? ? ? ? ? ? 12 PRINT_EXPR > ? ? ? ? ? ? ? ? ? ? ? ? 14 LOAD_CONST? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 > (None) > ? ? ? ? ? ? ? ? ? ? ? ? 16 RETURN_VALUE > We have another batch of duplicated messages coming through. Are they related to the previous issue? Possibly noteworthy: they all seem to have a consistent issue with character encoding. ChrisA From dieter at handshake.de Sat Dec 9 03:38:25 2017 From: dieter at handshake.de (dieter) Date: Sat, 09 Dec 2017 09:38:25 +0100 Subject: Save and load initialized class References: Message-ID: <87609g2t4u.fsf@handshake.de> Bob van der Poel writes: > I'm trying to something simple (yeah, right). Mainly I want to have a bunch > of variables which my program needs and uses to be in a saveable/loadable > block. Currently I have then all as a bunch of globals which works, but > trying to keep track of them and the correct spellings, etc becomes a bit > of maintenance nightmare. So, demonstrating all my cleverness I came up > with: > > class Opts(): > var1 = 123 > var2 = "hello world" > .... > Further, and importantly, I can save the lot with: > > json.dump(Opts.__dict__, open("mybuffer", "w")) > > But, I can't figure out how to load the saved data back into my program. > Doing > > z=json.load (open("mybuffer", "r")) > > loads a dictionary ... which makes sense since that is what I saved. So, > can I now reset the values in Opts from a saved dictionary? You could use: for k, v in z.iteritems: setattr(Opts, k, v) Of course, this means that you already have a class "Opts" (maybe without or with different parameter values). This poses the question why you want to dump/load the class in the first place. Usually, you would want to have the values in code, not stored/loaded. If you really want make parameter values persistent, you could use the following approach: class ParameterCollection(object): def __init__(self, **kwargs): for k, v in kwargs.iteritems(): setattr(self, k, v) my_parameters = ParameterCollection(a=1, b=2, ) from pickle import load, dump dump(my_parameters, open(..., "wb"), -1) ... my_parameters_reloaded = load(open(..., "rb")) From gheskett at shentel.net Sat Dec 9 04:01:21 2017 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 9 Dec 2017 04:01:21 -0500 Subject: repeating posts In-Reply-To: <4b499518-27da-45ae-bf3c-33a8f1a14434@googlegroups.com> References: <4b499518-27da-45ae-bf3c-33a8f1a14434@googlegroups.com> Message-ID: <201712090401.21682.gheskett@shentel.net> On Saturday 09 December 2017 00:35:15 Rustom Mody wrote: > Repeating old posts again appearing > > [No not complaining? I know people are working on it. Thanks Skip and > whoever else] > > Just thought I'd mention they are now mildly mojibaked Not familiar with that term. For me they are highly spammy, and are winding up in my spam box, scoreing around 8 because the headers are so mucked up. I train Bayes on that folder daily, move it to another folder so I can retrieve it if I want to. Thats a very rare occurrence. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From rosuav at gmail.com Sat Dec 9 05:09:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Dec 2017 21:09:59 +1100 Subject: repeating posts In-Reply-To: <201712090401.21682.gheskett@shentel.net> References: <4b499518-27da-45ae-bf3c-33a8f1a14434@googlegroups.com> <201712090401.21682.gheskett@shentel.net> Message-ID: On Sat, Dec 9, 2017 at 8:01 PM, Gene Heskett wrote: > On Saturday 09 December 2017 00:35:15 Rustom Mody wrote: > >> Repeating old posts again appearing >> >> [No not complaining? I know people are working on it. Thanks Skip and >> whoever else] >> >> Just thought I'd mention they are now mildly mojibaked > > Not familiar with that term. > > For me they are highly spammy, and are winding up in my spam box, > scoreing around 8 because the headers are so mucked up. I train Bayes on > that folder daily, move it to another folder so I can retrieve it if I > want to. Thats a very rare occurrence. Mojibake is messed up characters caused by mis-encoding or mis-decoding. https://en.wikipedia.org/wiki/Mojibake ChrisA From mail at timgolden.me.uk Sat Dec 9 05:13:04 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 9 Dec 2017 10:13:04 +0000 Subject: repeating posts In-Reply-To: <4b499518-27da-45ae-bf3c-33a8f1a14434@googlegroups.com> References: <4b499518-27da-45ae-bf3c-33a8f1a14434@googlegroups.com> Message-ID: On 09/12/2017 05:35, Rustom Mody wrote: > Repeating old posts again appearing > > [No not complaining? I know people are working on it. Thanks Skip and whoever else] > > Just thought I'd mention they are now mildly mojibaked > I've just added a new filter and pinged the other list admins / postmaster. The same thing on python-announce. Still not sure if this is malicious or merely a misconfigured newsreader. Given the mojibake, may well be the latter. TJG From alister.ware at ntlworld.com Sat Dec 9 06:49:04 2017 From: alister.ware at ntlworld.com (alister) Date: Sat, 09 Dec 2017 11:49:04 GMT Subject: Please tell me how to execute python file in Ubuntu by double click References: <2555707956@f38.n261.z1.binkp.net> <2217129085@f38.n261.z1.binkp.net> Message-ID: On Wed, 06 Dec 2017 10:35:58 +1200, Steve D'Aprano wrote: > On Tue, 5 Dec 2017 07:58 pm, Lawrence D? ?Oliveiro wrote: > >> On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: >>> >>> Sounds like your OS file associations are all botched-up ... >> >> Linux doesn? ?t do ? ?OS file associations? ?. > > > Then how does my Linux box know that when I double-click on a text file, > it launches kwrite rather than (say) the Gimp or LibreOffice? > > When I right-click on a mp4 video, I get a menu that includes a Open > With command that shows (amount others) Kaffeine, mplayer and VLC. > > If you mean the Linux *kernel* doesn't do file associations, then you > should have said so. > > But why do you care about the kernel? Would you think it even the > *tiniest* useful to claim that "Linux doesn't do email" because it is > sendmail or postfix > (or similar) that sends email rather than the Linux kernel itself? Linux does not associate by file extn it uses a 'magic' file to analyse the content of the file so that it runs the correct application regardless of the file extn. to get a python program to run it simply needs the correct "Shebang" ass the 1st line Usually #!/usr/bin/env python or similar -- Some say the world will end in fire, Some say in ice. >From what I've tasted of desire I hold with those who favor fire. But if it had to perish twice, I think I know enough of hate To say that for destruction, ice Is also great And would suffice. -- Robert Frost, "Fire and Ice" From marko at pacujo.net Sat Dec 9 08:58:43 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 09 Dec 2017 15:58:43 +0200 Subject: Please tell me how to execute python file in Ubuntu by double click References: <2555707956@f38.n261.z1.binkp.net> <2217129085@f38.n261.z1.binkp.net> Message-ID: <87efo4knos.fsf@elektro.pacujo.net> alister : > On Wed, 06 Dec 2017 10:35:58 +1200, Steve D'Aprano wrote: >> Then how does my Linux box know that when I double-click on a text >> file, it launches kwrite rather than (say) the Gimp or LibreOffice? >> >> When I right-click on a mp4 video, I get a menu that includes a Open >> With command that shows (amount others) Kaffeine, mplayer and VLC. >> >> If you mean the Linux *kernel* doesn't do file associations, then you >> should have said so. >> >> But why do you care about the kernel? Would you think it even the >> *tiniest* useful to claim that "Linux doesn't do email" because it is >> sendmail or postfix (or similar) that sends email rather than the >> Linux kernel itself? > > Linux does not associate by file extn it uses a 'magic' file to > analyse the content of the file so that it runs the correct > application regardless of the file extn. "Linux" is one of those words that has ceased to have much meaning. Personally, I wouldn't think "double-clicking on a text file" has anything to do with linux. I use linux during most of my waking hours but I don't remember ever "double-clicking on a text file". BTW, with the triumph of systemd, I would say linux is falling ever more to the background. I am thinking more and more that "Linux" is a bad generic name for the modern distros. Instead, we should talk about "systemd" as the overall name of the OS. Linux really is a relatively minor component in the mind of the user or the application developer. For example, Linux doesn't dictate how one should develop a system service; systemd calls the shots. Marko From tjol at tjol.eu Sat Dec 9 11:43:02 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 9 Dec 2017 17:43:02 +0100 Subject: scipy In-Reply-To: References: Message-ID: <082a2e8e-5d1f-ca18-16b3-84fe3e740d7b@tjol.eu> On 08/12/17 23:57, Larry Martell wrote: > Trying to install scipy on ubuntu-trusty-64 running Python 2.7.6. I STRONGLY recommend moving to Python 3 if you can. The scientific python ecosystem has had good support for Python 3 for years now. Many scientific packages, including numpy (the king of scientific Pythonland), have decided to drop official Python 2 support fairly soon; numpy will not release any new versions for Python 2 after 2018. See: http://www.python3statement.org/ Trusty includes Python 3.3. Ubuntu trusty also has scipy packages. Installing with sudo apt-get install python3-scipy # or python-scipy, if you insist in being stuck on Python 2.7 is probably the easiest option. This will, of course, give you an equally dated version of scipy. If you want current versions of Python and scientific packages on an old OS, I recommend you have a look at Anaconda. > It's failing with: > > $ sudo pip install scipy > Downloading/unpacking scipy > Downloading scipy-1.0.0.tar.gz (15.2MB): 15.2MB downloaded > Running setup.py (path:/tmp/pip_build_root/scipy/setup.py) egg_info > for package scipy > /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown > distribution option: 'python_requires' > > Followed by many screens full of errors. Is that just a warning or is > that the issue? I've installed many other packages without a problem > on this same system. What is the issue here? > I'm just guessing here, but do you have the latest versions of distutils, setuptools and pip? It's likely that scipy requires newer versions of these than your distribution provides. You may have to upgrade them. Best of luck, Thomas From python at mrabarnett.plus.com Sat Dec 9 12:52:44 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 9 Dec 2017 17:52:44 +0000 Subject: Save and load initialized class In-Reply-To: References: Message-ID: <00d03107-d365-bcf5-b708-870e85c63086@mrabarnett.plus.com> On 2017-12-08 18:36, Bob van der Poel wrote: > I'm trying to something simple (yeah, right). Mainly I want to have a bunch > of variables which my program needs and uses to be in a saveable/loadable > block. Currently I have then all as a bunch of globals which works, but > trying to keep track of them and the correct spellings, etc becomes a bit > of maintenance nightmare. So, demonstrating all my cleverness I came up > with: > > class Opts(): > var1 = 123 > var2 = "hello world" > > Notationally, it looks much like the variables are stored in a separate > module. I can call these options from within a function with the simple > notation: > > if Opts.var1 == 99 ... > > And, if I need to change a value I can: > > global > Opts.var1 = 0 > > Further, and importantly, I can save the lot with: > > json.dump(Opts.__dict__, open("mybuffer", "w")) > > But, I can't figure out how to load the saved data back into my program. > Doing > > z=json.load (open("mybuffer", "r")) > > loads a dictionary ... which makes sense since that is what I saved. So, > can I now reset the values in Opts from a saved dictionary? > Try updating __dict__: Opts.__dict__.update(json.load(open("mybuffer"))) From rosuav at gmail.com Sat Dec 9 17:15:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Dec 2017 09:15:49 +1100 Subject: Please tell me how to execute python file in Ubuntu by double click In-Reply-To: <87efo4knos.fsf@elektro.pacujo.net> References: <2555707956@f38.n261.z1.binkp.net> <2217129085@f38.n261.z1.binkp.net> <87efo4knos.fsf@elektro.pacujo.net> Message-ID: On Sun, Dec 10, 2017 at 12:58 AM, Marko Rauhamaa wrote: > alister : > >> On Wed, 06 Dec 2017 10:35:58 +1200, Steve D'Aprano wrote: >>> Then how does my Linux box know that when I double-click on a text >>> file, it launches kwrite rather than (say) the Gimp or LibreOffice? >>> >>> When I right-click on a mp4 video, I get a menu that includes a Open >>> With command that shows (amount others) Kaffeine, mplayer and VLC. >>> >>> If you mean the Linux *kernel* doesn't do file associations, then you >>> should have said so. >>> >>> But why do you care about the kernel? Would you think it even the >>> *tiniest* useful to claim that "Linux doesn't do email" because it is >>> sendmail or postfix (or similar) that sends email rather than the >>> Linux kernel itself? >> >> Linux does not associate by file extn it uses a 'magic' file to >> analyse the content of the file so that it runs the correct >> application regardless of the file extn. > > "Linux" is one of those words that has ceased to have much meaning. > Personally, I wouldn't think "double-clicking on a text file" has > anything to do with linux. I use linux during most of my waking hours > but I don't remember ever "double-clicking on a text file". And there are plenty of people who use Python all their waking hours, but never once write a generator function. Systems like this are large enough that different people get to use different subsets of the functionality. There's a HUGE difference between "using Linux for headless servers" and "using Linux for software development" and "using Linux for video editing" in terms of which features you'll use. I, for instance, couldn't *imagine* using Linux without SSH, but my mother uses Linux too and has never SSH'd to a different computer for any reason. On the other hand, she makes extensive use of Libre Office, which I only have installed for those rare occasions when someone sends me a spreadsheet file or something. But we're both using Linux, and that's perfectly acceptable use of terminology. ChrisA From tjreedy at udel.edu Sat Dec 9 17:20:08 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 9 Dec 2017 17:20:08 -0500 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On 12/9/2017 5:57 AM, Gilmeh Serda wrote: > And next demands to allow Unicode as keywords in a translated version of > Python Python's liberal open source license allows people to revise and distribute their own python or python-like interpreters. I believe there are already a couple of non-english versions aimed at schoolkids. The cpython core developer group has nothing to do with such. -- Terry Jan Reedy From steve+python at pearwood.info Sat Dec 9 20:42:04 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Dec 2017 12:42:04 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) References: Message-ID: <5a2c90ed$0$2056$b1db1813$d948b532@news.astraweb.com> On Sun, 10 Dec 2017 09:20 am, Terry Reedy wrote: > On 12/9/2017 5:57 AM, Gilmeh Serda wrote: > >> And next demands to allow Unicode as keywords in a translated version of >> Python > > Python's liberal open source license allows people to revise and > distribute their own python or python-like interpreters. I believe > there are already a couple of non-english versions aimed at schoolkids. > The cpython core developer group has nothing to do with such. I don't know who their target audiences are, but there's a German and Chinese version of Python. http://www.fiber-space.de/EasyExtend/doc/teuton/teuton.htm http://www.chinesepython.org/english/english.html My *guess* is that Teuton is intended as a proof-of-concept just to show it can be done, and ChinesePython is intended for students. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Dec 9 20:45:45 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Dec 2017 12:45:45 +1100 Subject: Benefits of unicode identifiers (was: Allow additional References: <1744763208@f38.n261.z1.binkp.net> Message-ID: <5a2c91c9$0$2056$b1db1813$d948b532@news.astraweb.com> On Sat, 9 Dec 2017 09:57 am, Gilmeh Serda wrote: > And next demands to allow Unicode as keywords in a translated version of > Python > will make open source go away. For good. Do you seriously think that because *one* project forks their code base and introduces non-English keywords, the tens of hundreds of thousands of other projects (including *enormous* projects like the Linux kernel, LibreOffice, Apache, Mozilla, etc) will all say "well, that's it, we're shutting down"? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Dec 9 20:56:16 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Dec 2017 12:56:16 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> Message-ID: <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Dec 2017 12:08 pm, Python wrote: > But more importantly, practically speaking, it still doesn't really > provide much more help to the OP than Lawrence's answer. I wasn't responding to the OP, I was responding to Lawrence. If I had a solution for the OP beyond what others have already said (especially Thomas Jollans' link to an AskUbuntu post), I would have given it. Practically speaking, your responses to me don't help the OP either, do they? So why single me out for criticism for *exactly* the same thing that you yourself are doing? > He may well > know already that the desktop environment is what does the job (and > probably does even, in broad terms, if he's familiar with computers in > general), but have no idea how to configure it. Anything is possible, but if he were that clueful, he would know that this has nothing to do with Python and he should be asking in a forum dedicated to his preferred desktop environment. The fact that this is a Python script is irrelevant. > A reasonably helpful > answer would be one that mentioned a few of the likely possibilities > (Gnome, KDE, Unity, /etc/mime.types, "other"), and gave hints for how > to find out the answer for each. A thoroughly helpful answer would > be, well, outside the scope of this list/group. Arguably -- and I'm not sure that I personally would take this position -- it might be said that somebody clueless enough to ask a desktop-specific question without specifying which desktop he is running, would only be confused rather than enlightened by an answer which lists three or more desktops. If we take a user-centric position, there's a lot to be said for the attitude "Don't bother me with technical details, I just want to make the file executable when I double-click on it". (I presume that there's a single, trivial, right answer to this question on Mac OS and Windows.) > Pedantry has its place, FWIW. In the computer field, as with other > science and engineering disciplines, often precision is much more > essential than in other fields. I personally find such precision is > especially warranted if you take it upon yourself to criticize what > someone else has said. There's a famous story where some English Lit student took it upon themselves to criticise Isaac Asimov for his claim to be living in a century where we finally knew the basics of how the universe worked. Asimov's response was to quote something he had once told his editor, John Campbell: [W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together. http://hermiene.net/essays-trans/relativity_of_wrong.html https://en.wikipedia.org/wiki/Wronger_than_wrong (This is becoming ever more relevant again, as for some reason -- possibly Poe's Law -- the number of people on the Internet claiming to believe the world is flat is on the rise.) If you think that my statement is just as wrong as Lawrence's statement, you're wronger than both of us together :-) Remember the context here: we're replying to a thread discussing somebody who is running Ubuntu with a GUI desktop environment. Of course there are *some* Linux systems which don't run a GUI at all, but you can't double-click on files on such systems, and they aren't Ubuntu, so they aren't relevant. > Though, providing such precision via natural > language often turns out to be more challenging than one would hope... Indeed. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sat Dec 9 22:01:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Dec 2017 14:01:03 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano wrote: > Remember the context here: we're replying to a thread discussing somebody who > is running Ubuntu with a GUI desktop environment. Of course there are *some* > Linux systems which don't run a GUI at all, but you can't double-click on > files on such systems, and they aren't Ubuntu, so they aren't relevant. Been a long time since I had an Ubuntu, but is it really the case that you can't install Ubuntu without a GUI? Anyhow, your first part is correct: without a GUI, you can't exactly double-click on a file. (No doubt someone's going to become even more pedantic now and point out some way in which you can double-click something without a GUI. Probably involving networked file systems or something. If I've learned one thing from this list, it's that there is ALWAYS someone more pedantic than you are.) ChrisA From tjol at tjol.eu Sat Dec 9 22:26:01 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 10 Dec 2017 04:26:01 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: <5a2c90ed$0$2056$b1db1813$d948b532@news.astraweb.com> References: <5a2c90ed$0$2056$b1db1813$d948b532@news.astraweb.com> Message-ID: On 10/12/17 02:42, Steve D'Aprano wrote: > On Sun, 10 Dec 2017 09:20 am, Terry Reedy wrote: > >> On 12/9/2017 5:57 AM, Gilmeh Serda wrote: >> >>> And next demands to allow Unicode as keywords in a translated version of >>> Python >> >> Python's liberal open source license allows people to revise and >> distribute their own python or python-like interpreters. I believe >> there are already a couple of non-english versions aimed at schoolkids. >> The cpython core developer group has nothing to do with such. > > I don't know who their target audiences are, but there's a German and Chinese > version of Python. > > http://www.fiber-space.de/EasyExtend/doc/teuton/teuton.htm > > http://www.chinesepython.org/english/english.html > > My *guess* is that Teuton is intended as a proof-of-concept just to show it > can be done, That's certainly what it looks like, though the documentation page reads like a bad joke (or a once-mediocre one that really hasn't aged well). Joke or not, it does appear to be real, however, and a part of this long dead and forgotten package: https://pypi.python.org/pypi/EasyExtend/3.0.1 -- Thomas From tjol at tjol.eu Sat Dec 9 22:32:17 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 10 Dec 2017 04:32:17 +0100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: <46533a9d-9bd9-5712-91d1-7bc0e17cf136@tjol.eu> On 10/12/17 04:01, Chris Angelico wrote: > but is it really the case that you can't install Ubuntu without a GUI? Of course not. There are millions of people using Ubuntu on servers, without as much as a whiff of GUI. I'm rather sure that the server version of Ubuntu makes significantly more money for Canonical than the desktop one, too. -- Thomas From torriem at gmail.com Sat Dec 9 22:39:12 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 9 Dec 2017 20:39:12 -0700 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: <8befddce-0e66-60da-6d9f-c59d4dd7b04f@gmail.com> On 12/09/2017 08:01 PM, Chris Angelico wrote: > Been a long time since I had an Ubuntu, but is it really the case that > you can't install Ubuntu without a GUI? Of course not. Ubuntu is used in headless server situations all the time. From rosuav at gmail.com Sat Dec 9 22:44:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Dec 2017 14:44:21 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <8befddce-0e66-60da-6d9f-c59d4dd7b04f@gmail.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> <8befddce-0e66-60da-6d9f-c59d4dd7b04f@gmail.com> Message-ID: On Sun, Dec 10, 2017 at 2:39 PM, Michael Torrie wrote: > On 12/09/2017 08:01 PM, Chris Angelico wrote: >> Been a long time since I had an Ubuntu, but is it really the case that >> you can't install Ubuntu without a GUI? > > Of course not. Ubuntu is used in headless server situations all the time. That's what I thought. Anyhow, the other half still stands. ChrisA From rustompmody at gmail.com Sat Dec 9 23:42:11 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 9 Dec 2017 20:42:11 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> Message-ID: <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> On Friday, December 8, 2017 at 6:40:17 AM UTC+5:30, Python wrote: > On Thu, Dec 07, 2017 at 01:29:11PM +1100, Steve D'Aprano wrote: > > On Thu, 7 Dec 2017 08:22 am, Python wrote: > > >> > Linux doesn?t do ?OS file associations?. > > >> > > >> Then how does my Linux box know that when I double-click on a text file, it > > >> launches kwrite rather than (say) the Gimp or LibreOffice? > > > > > > The answer to that is (sadly) complicated. > > > > Actually, no, the answer to my question is very simple: Lawrence is mistaken > > about Linux not doing file associations. It does -- it is merely handled by > > the desktop environment (if there is one). > > Pedantically speaking, this is only *probably true*, not certainly > true (e.g. running Linux on a text console with something like > midnight commander, some unrelated file manager while running a > particular desktop environment, etc.). > > But more importantly, practically speaking, it still doesn't really > provide much more help to the OP than Lawrence's answer. He may well > know already that the desktop environment is what does the job (and > probably does even, in broad terms, if he's familiar with computers in > general), but have no idea how to configure it. A reasonably helpful > answer would be one that mentioned a few of the likely possibilities > (Gnome, KDE, Unity, /etc/mime.types, "other"), and gave hints for how > to find out the answer for each. A thoroughly helpful answer would > be, well, outside the scope of this list/group. > > Pedantry has its place, FWIW. In the computer field, as with other > science and engineering disciplines, often precision is much more > essential than in other fields. I personally find such precision is > especially warranted if you take it upon yourself to criticize what > someone else has said. Though, providing such precision via natural > language often turns out to be more challenging than one would hope... I was sending some files to some students. Since it was more than one, the natural choice was a tarball. [I believe that since it was a very tiny total space I did not compress the tarball? but I dont remember this part exactly] The point is that instead of sending a stuff.tgz or stuff.tar file I sent a file called just stuff; ie I must have done: $ tar xvf stuff directory rather than the more normal $ tar xvf stuff.tar directory I got a return mail soon enough: ?Your file is corrupt; it wont open? (in file-roller or whatever tar-GUI the kids nowadays use) I could have given them the answer: There are no associations in Linux. Just $ mv stuff stuff.tar and it will work As it happens I am lazy; easier to believe that my file was "wrongly" named; did the mv myself, and resent the now "correct" tarball; problem solved. Whether there was nothing wrong in what I did, the "wrong-right" was de facto, or de jure? I will leave to more wise persons than myself From rustompmody at gmail.com Sat Dec 9 23:45:29 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 9 Dec 2017 20:45:29 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> Message-ID: <398b3a91-ba5c-4648-8d54-c3e837231afe@googlegroups.com> On Sunday, December 10, 2017 at 10:12:38 AM UTC+5:30, Rustom Mody wrote: > I was sending some files to some students. > Since it was more than one, the natural choice was a tarball. > [I believe that since it was a very tiny total space I did not compress the > tarball? but I dont remember this part exactly] > The point is that instead of sending a stuff.tgz or stuff.tar file I sent a file > called just stuff; ie I must have done: > $ tar xvf stuff directory > rather than the more normal > $ tar xvf stuff.tar directory Er? Not xvf of course but cvf [And yeah the v is not necessary] From frank at chagford.com Sun Dec 10 00:44:37 2017 From: frank at chagford.com (Frank Millman) Date: Sun, 10 Dec 2017 07:44:37 +0200 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> Message-ID: "Rustom Mody" wrote in message news:4f25d0a9-64a5-4d36-b072-97e293a7cadd at googlegroups.com... I was sending some files to some students. Since it was more than one, the natural choice was a tarball. [I believe that since it was a very tiny total space I did not compress the tarball? but I dont remember this part exactly] The point is that instead of sending a stuff.tgz or stuff.tar file I sent a file called just stuff; ie I must have done: $ tar xvf stuff directory rather than the more normal $ tar xvf stuff.tar directory I got a return mail soon enough: ?Your file is corrupt; it wont open? (in file-roller or whatever tar-GUI the kids nowadays use) I could have given them the answer: There are no associations in Linux. Just $ mv stuff stuff.tar and it will work As it happens I am lazy; easier to believe that my file was "wrongly" named; did the mv myself, and resent the now "correct" tarball; problem solved. I had a similar experience a few years ago, but the recipient was not a student, but a bank's IT department! I had to send them an encrypted document, and their spec specified PGP. I used GPG instead, which produces exactly the same result, but with a .gpg file extension. I was told that my file did not work. After much time trying to figure out what was wrong, I spoke to one of their staff over the phone, and asked him to right-click on the file, select 'rename', and change '.gpg' to '.pgp'. He did so, tried again, and said 'Ah, now it works'. Frank Millman From steve+python at pearwood.info Sun Dec 10 00:52:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Dec 2017 16:52:44 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: <5a2ccbad$0$2054$b1db1813$d948b532@news.astraweb.com> On Sun, 10 Dec 2017 02:01 pm, Chris Angelico wrote: > On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano > wrote: >> Remember the context here: we're replying to a thread discussing somebody >> who is running Ubuntu with a GUI desktop environment. Of course there are >> *some* Linux systems which don't run a GUI at all, but you can't >> double-click on files on such systems, and they aren't Ubuntu, so they >> aren't relevant. > > Been a long time since I had an Ubuntu, but is it really the case that > you can't install Ubuntu without a GUI? I mispoke -- I meant something like "they aren't whatever Ububtu GUI the OP has installed". There is, apparently, headless Ubuntu, but it isn't clear to me whether they install X (or Mir, Wayland or some other alternative) or not. E.g. this: https://www.howtoforge.com/tutorial/ubuntu-gnome-vnc-headless-server/ seems to suggest to me that X.org is already installed, I can see X utils being installed as a recommended package but I couldn't spot X being added as a dependency. So my *guess* is that even headless Ubuntu server includes an X server. (Or possibly Mir.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Dec 10 01:01:34 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Dec 2017 17:01:34 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <5a2ccbad$0$2054$b1db1813$d948b532@news.astraweb.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> <5a2ccbad$0$2054$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Dec 10, 2017 at 4:52 PM, Steve D'Aprano wrote: > On Sun, 10 Dec 2017 02:01 pm, Chris Angelico wrote: > >> On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano >> wrote: >>> Remember the context here: we're replying to a thread discussing somebody >>> who is running Ubuntu with a GUI desktop environment. Of course there are >>> *some* Linux systems which don't run a GUI at all, but you can't >>> double-click on files on such systems, and they aren't Ubuntu, so they >>> aren't relevant. >> >> Been a long time since I had an Ubuntu, but is it really the case that >> you can't install Ubuntu without a GUI? > > I mispoke -- I meant something like "they aren't whatever Ububtu GUI the OP > has installed". > > There is, apparently, headless Ubuntu, but it isn't clear to me whether they > install X (or Mir, Wayland or some other alternative) or not. E.g. this: > > https://www.howtoforge.com/tutorial/ubuntu-gnome-vnc-headless-server/ > > seems to suggest to me that X.org is already installed, I can see X utils > being installed as a recommended package but I couldn't spot X being added as > a dependency. So my *guess* is that even headless Ubuntu server includes an X > server. (Or possibly Mir.) Or that installing a VNC server automatically installs X11 or equivalent. That's what I'd expect, though it's entirely possible that a headless server still gets certain libraries installed. ChrisA From rustompmody at gmail.com Sun Dec 10 04:00:06 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Dec 2017 01:00:06 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> Message-ID: On Sunday, December 10, 2017 at 11:15:15 AM UTC+5:30, Frank Millman wrote: > "Rustom Mody" wrote in message > > > > I was sending some files to some students. > Since it was more than one, the natural choice was a tarball. > [I believe that since it was a very tiny total space I did not compress the > tarball? but I dont remember this part exactly] > The point is that instead of sending a stuff.tgz or stuff.tar file I sent a > file > called just stuff; ie I must have done: > $ tar xvf stuff directory > rather than the more normal > $ tar xvf stuff.tar directory > > I got a return mail soon enough: ?Your file is corrupt; it wont open? > (in file-roller or whatever tar-GUI the kids nowadays use) > > I could have given them the answer: There are no associations in > Linux. Just > $ mv stuff stuff.tar > and it will work > As it happens I am lazy; easier to believe that my file was "wrongly" named; > did the mv myself, and resent the now "correct" tarball; problem solved. > > > > I had a similar experience a few years ago, but the recipient was not a > student, but a bank's IT department! > > I had to send them an encrypted document, and their spec specified PGP. I > used GPG instead, which produces exactly the same result, but with a .gpg > file extension. > > I was told that my file did not work. After much time trying to figure out > what was wrong, I spoke to one of their staff over the phone, and asked him > to right-click on the file, select 'rename', and change '.gpg' to '.pgp'. He > did so, tried again, and said 'Ah, now it works'. Inspired by this thread, I added alias o="xdg-open" to my ~/.bash_aliases And as best as I can see, now $ o foo.png $ o bar.mp3 $ o baz.pdf and $ o http://python.org all do the ?Right Thing? My main attraction for this is that I often end up doing evince foo.png instead of eog foo.png The one thing that does not work (yet) is $ o foo.py starts up gedit (instead of emacs) PS. As it happens I had figured out something for my students some years ago: https://bitbucket.org/rustom/vit-projects/wiki/emacsasdefault I?ll have to reread and recheckout what I wrote back then ? From cl at isbd.net Sun Dec 10 04:26:35 2017 From: cl at isbd.net (Chris Green) Date: Sun, 10 Dec 2017 09:26:35 +0000 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> Message-ID: Chris Angelico wrote: > On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano > wrote: > > Remember the context here: we're replying to a thread discussing somebody who > > is running Ubuntu with a GUI desktop environment. Of course there are *some* > > Linux systems which don't run a GUI at all, but you can't double-click on > > files on such systems, and they aren't Ubuntu, so they aren't relevant. > > Been a long time since I had an Ubuntu, but is it really the case that > you can't install Ubuntu without a GUI? Anyhow, your first part is > correct: without a GUI, you can't exactly double-click on a file. > You'd have to install 'ubuntu server' to get an Ubuntu without a GUI, -- Chris Green ? From steve+python at pearwood.info Sun Dec 10 06:00:27 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Dec 2017 22:00:27 +1100 Subject: Save and load initialized class References: <00d03107-d365-bcf5-b708-870e85c63086@mrabarnett.plus.com> Message-ID: <5a2d13cb$0$2064$b1db1813$d948b532@news.astraweb.com> On Sun, 10 Dec 2017 04:52 am, MRAB wrote: > Try updating __dict__: > > Opts.__dict__.update(json.load(open("mybuffer"))) __dict__ is implementation, vars() is the public interface: vars(Opts).update(json.load(open("mybuffer"))) Looks nicer too :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tjol at tjol.eu Sun Dec 10 07:24:44 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 10 Dec 2017 13:24:44 +0100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <5a2c9441$0$2061$b1db1813$d948b532@news.astraweb.com> <5a2ccbad$0$2054$b1db1813$d948b532@news.astraweb.com> Message-ID: <9f3dfff0-5428-7f14-be75-142f530b3dec@tjol.eu> On 10/12/17 07:01, Chris Angelico wrote: > On Sun, Dec 10, 2017 at 4:52 PM, Steve D'Aprano > wrote: >> On Sun, 10 Dec 2017 02:01 pm, Chris Angelico wrote: >> >>> On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano >>> wrote: >>>> Remember the context here: we're replying to a thread discussing somebody >>>> who is running Ubuntu with a GUI desktop environment. Of course there are >>>> *some* Linux systems which don't run a GUI at all, but you can't >>>> double-click on files on such systems, and they aren't Ubuntu, so they >>>> aren't relevant. >>> >>> Been a long time since I had an Ubuntu, but is it really the case that >>> you can't install Ubuntu without a GUI? >> >> I mispoke -- I meant something like "they aren't whatever Ububtu GUI the OP >> has installed". >> >> There is, apparently, headless Ubuntu, but it isn't clear to me whether they >> install X (or Mir, Wayland or some other alternative) or not. E.g. this: >> >> https://www.howtoforge.com/tutorial/ubuntu-gnome-vnc-headless-server/ >> >> seems to suggest to me that X.org is already installed, I can see X utils >> being installed as a recommended package but I couldn't spot X being added as >> a dependency. So my *guess* is that even headless Ubuntu server includes an X >> server. (Or possibly Mir.) > > Or that installing a VNC server automatically installs X11 or > equivalent. That's what I'd expect, though it's entirely possible that > a headless server still gets certain libraries installed. Indeed, VNC pulls in X11: https://packages.ubuntu.com/xenial/vnc4server If you're interested in what the bare-bones Ubuntu server install contains, you can look it up here: https://packages.ubuntu.com/xenial/ubuntu-server In other news: in case you hadn't heard, Mir is dead. Mark Shuttleworth killed it this summer. From no at spam.com Sun Dec 10 16:57:03 2017 From: no at spam.com (Cutter) Date: Sun, 10 Dec 2017 22:57:03 +0100 Subject: Can't install wrapt on Windows Message-ID: <5a2dadae$0$7181$426a74cc@news.free.fr> Hi, I have trouble installing pylint on Windows 10, Python 3.6. There's a problem during the installation of wrapt, which is a dependency of pylint. Here are the contents of the commandline: > C:\WINDOWS\system32>python -m pip install pylint > Collecting pylint > Using cached pylint-1.7.4-py2.py3-none-any.whl > Collecting colorama; sys_platform == "win32" (from pylint) > Using cached colorama-0.3.9-py2.py3-none-any.whl > Requirement already satisfied: mccabe in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Requirement already satisfied: isort>=4.2.5 in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Collecting astroid>=1.5.1 (from pylint) > Using cached astroid-1.5.3-py2.py3-none-any.whl > Requirement already satisfied: six in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Requirement already satisfied: lazy-object-proxy in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from astroid>=1.5.1->pylint) > Collecting wrapt (from astroid>=1.5.1->pylint) > Using cached wrapt-1.10.11.tar.gz > Installing collected packages: colorama, wrapt, astroid, pylint > Running setup.py install for wrapt ... error > Exception: > Traceback (most recent call last): > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str > return s.decode(sys.__stdout__.encoding) > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: invalid start byte > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\basecommand.py", line 215, in main > status = self.run(options, args) > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\commands\install.py", line 342, in run > prefix=options.prefix_path, > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\req\req_set.py", line 784, in install > **kwargs > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\req\req_install.py", line 878, in install > spinner=spinner, > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess > line = console_to_str(proc.stdout.readline()) > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str > return s.decode('utf_8') > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: invalid start byte The same problem happens from a venv. I have reinstalled Python 3.6.3 and 3.6.4rc1 several times, that didn't change anything. Note that the installation of pylint was reported to be successful a few times but despite that, pylint was unusable: when I tried to use pylint an error message said that module wrapt.wrappers couldn't be found. Since the wrapt module seemed to be incorrectly installed I uninstalled it. I don't know how I managed to get passed the above error message a couple of times when installing pylint. I would appreciate any help. From rantingrickjohnson at gmail.com Sun Dec 10 18:10:07 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Dec 2017 15:10:07 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> Message-ID: <950b31eb-ed13-48fa-b15f-e4d8d06e0ba7@googlegroups.com> Rustom Mody wrote: [...] > Whether there was nothing wrong in what I did, the "wrong- > right" was de facto, or de jure? I will leave to more wise > persons than myself A file with no extension (regardless of the OS or desktop enviroment that it was created on), is like a sealed box with no label to indicate the contents. And it's not like we can just pick file up and shake it, in a crude attempt to intuit the contents. >>> box.shake(ms=1000, aggression=0.1, log=sys.stdout) Hiss "What was that?" o_O >>> box.shake(ms=3000, aggression=0.9, log=sys.stdout) Reeeeeeooooooowwwwww! Hissssssss! Hiss! "Holy crap! O_O "Grandma must have gift-wrapped the cat again!" Granted, the label could be an outright lie or mistake. However, we can safely assume that outright lies, mistakes, and even gift-wrapped cats, will be the minority. The vast majority of file extensions we encounter will be truthful reflections of the contents. Unless we're paranoid, of course. But that's another issue entirely... Our DEs can deal with lies and mismarked labels on a case by case basis. From lnporter99 at gmail.com Sun Dec 10 19:05:37 2017 From: lnporter99 at gmail.com (Lauren Porter) Date: Sun, 10 Dec 2017 16:05:37 -0800 (PST) Subject: Processing Game Help Message-ID: <919cc4ef-fb2a-4fc2-aa7c-b3beb7432fd2@googlegroups.com> Hello all! I've been trying to create a game in Python Processing where a spaceship moves horizontally in order to miss a collision with an asteroid. I'm having difficulty making it so that the game quits when an asteroid hits the spaceship, could anybody help? Here is my code. As you can see, I tried using globals in order use variables from previous classes, but nothing has worked. For this specific approach, no error message popped up, but nothing happened either. Thanks so much! COLORS = {"black":"#000000", "white":"#FFFFFF", "red":"#FF0000", "green":"#00FF00", "blue":"#D1F5FF", "yellow":"#FFFF00", "orange":"#FFA500", "hendrixorange":"#F58025", "purple":"#9B30FF", "gray":"#808080", "lightgray": "#CACACA", "darkgray":"#A9A9A9"} import random asteroid = [] spaceship = [] stars = [] justPressed = False aX = 0 aY = 0 x = 0 y = 0 def setup(): global aX, aY, X, Y size(640, 480) for s in range(1): X = 320 Y = 440 spaceship.append(Space(X, Y, COLORS["orange"])) for a in range(4): aX = random.randint(0, 640) aY = 0 asteroid.append(Asteroid(aX, aY, COLORS["orange"])) for d in range(100): randX = random.randint(0, 640) randY = random.randint(0, 480) stars.append(Star(randX, randY, COLORS["orange"])) class Space: def __init__(self, x, y, color): self.x = x self.y = y self.color = color def spaceship(self): fill(COLORS["blue"]) stroke(COLORS["white"]) ellipse(self.x, self.y, 75, 75) #body fill(COLORS["green"]) fill(COLORS["gray"]) stroke(COLORS["green"]) ellipse(self.x, self.y + 20, 120, 35) stroke(COLORS["orange"]) fill(COLORS["purple"]) ellipse(self.x, self.y + 20, 10, 10) ellipse(self.x + 30, self.y + 20, 10, 10) ellipse(self.x - 30, self.y + 20, 10, 10) def move(self, dx, dy): self.x += dx self.y += dy class Asteroid: def __init__(self, x, y, color): self.x = x self.y = y self.color = color def update(self): self.velx = 0 self.vely = random.randint(1, 5) self.x += self.velx self.y += self.vely if self.y > 480: self.y = 0 self.x = random.randint(1,640) def asteroid(self): fill(COLORS["lightgray"]) stroke(COLORS["white"]) ellipse(self.x, self.y, 50, 50) fill(COLORS["gray"]) ellipse(self.x +15, self.y + 6, 15, 15) ellipse(self.x -12, self.y + 7, 10, 10) ellipse(self.x + 5, self.y - 13, 11, 11) ellipse(self.x - 12, self.y - 9, 7, 7) ellipse(self.x + 2, self.y + 18, 7, 7) class Star: def __init__(self, x, y, color): self.x = x self.y = y self.color = color def star(self): fill(COLORS["white"]) ellipse(self.x, self.y, 3, 3) def draw(): global justPressed background(COLORS["black"]) for f in stars: f.star() for f in spaceship: f.spaceship() if f.x < 60: f.move(3, 0) elif f.x > 580: f.move(-3, 0) elif justPressed : if key == 'd': f.move(3, 0) elif key == 'a': f.move(-3, 0) for f in asteroid: f.asteroid() f.update() #collision detection 'for' loop distance = sqrt(((aX - X)**2) + ((aY - Y)**2)) for f in asteroid: if distance < 62.5: background(COLORS["red"]) def keyTyped(): global justPressed justPressed = True print("typed", key) def keyPressed(): global justPressed justPressed = True print("pressed", key) From bob at mellowood.ca Sun Dec 10 19:19:26 2017 From: bob at mellowood.ca (Bob van der Poel) Date: Sun, 10 Dec 2017 17:19:26 -0700 Subject: Save and load initialized class In-Reply-To: <5a2d13cb$0$2064$b1db1813$d948b532@news.astraweb.com> References: <00d03107-d365-bcf5-b708-870e85c63086@mrabarnett.plus.com> <5a2d13cb$0$2064$b1db1813$d948b532@news.astraweb.com> Message-ID: Yes, all cool. But, json.dump(Opts.__dict__, open("mybuffer", "w")) still doesn't work with python3. Returns "is not JSON serializable" On Sun, Dec 10, 2017 at 4:00 AM, Steve D'Aprano wrote: > On Sun, 10 Dec 2017 04:52 am, MRAB wrote: > > > Try updating __dict__: > > > > Opts.__dict__.update(json.load(open("mybuffer"))) > > __dict__ is implementation, vars() is the public interface: > > vars(Opts).update(json.load(open("mybuffer"))) > > > Looks nicer too :-) > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From rosuav at gmail.com Sun Dec 10 19:29:52 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Dec 2017 11:29:52 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <950b31eb-ed13-48fa-b15f-e4d8d06e0ba7@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> <950b31eb-ed13-48fa-b15f-e4d8d06e0ba7@googlegroups.com> Message-ID: On Mon, Dec 11, 2017 at 10:10 AM, Rick Johnson wrote: > Rustom Mody wrote: > > [...] > >> Whether there was nothing wrong in what I did, the "wrong- >> right" was de facto, or de jure? I will leave to more wise >> persons than myself > > A file with no extension (regardless of the OS or desktop > enviroment that it was created on), is like a sealed box with > no label to indicate the contents. > > And it's not like we can just pick file up and shake > it, in a crude attempt to intuit the contents. No, but fortunately we have magic. And magic can tell us a lot about what a file contains. man 5 magic ChrisA From steve+python at pearwood.info Sun Dec 10 22:35:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 11 Dec 2017 14:35:36 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> <950b31eb-ed13-48fa-b15f-e4d8d06e0ba7@googlegroups.com> Message-ID: <5a2dfd08$0$2058$b1db1813$d948b532@news.astraweb.com> On Mon, 11 Dec 2017 11:29 am, Chris Angelico wrote: > On Mon, Dec 11, 2017 at 10:10 AM, Rick Johnson > wrote: >> And it's not like we can just pick file up and shake >> it, in a crude attempt to intuit the contents. > > No, but fortunately we have magic. And magic can tell us a lot about > what a file contains. > > man 5 magic https://pypi.python.org/pypi/python-magic -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Dec 10 22:47:35 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Dec 2017 14:47:35 +1100 Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <5a2dfd08$0$2058$b1db1813$d948b532@news.astraweb.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> <950b31eb-ed13-48fa-b15f-e4d8d06e0ba7@googlegroups.com> <5a2dfd08$0$2058$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Dec 11, 2017 at 2:35 PM, Steve D'Aprano wrote: > On Mon, 11 Dec 2017 11:29 am, Chris Angelico wrote: > >> On Mon, Dec 11, 2017 at 10:10 AM, Rick Johnson >> wrote: > >>> And it's not like we can just pick file up and shake >>> it, in a crude attempt to intuit the contents. >> >> No, but fortunately we have magic. And magic can tell us a lot about >> what a file contains. >> >> man 5 magic > > https://pypi.python.org/pypi/python-magic > Yep, that's an interface to the same magic I'm talking about. Wands, scrolls, incantations, they're all just front ends to libmagic. ChrisA From BILL_NOSPAM at Noway.net Sun Dec 10 23:36:14 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 10 Dec 2017 23:36:14 -0500 Subject: Processing Game Help In-Reply-To: <919cc4ef-fb2a-4fc2-aa7c-b3beb7432fd2@googlegroups.com> References: <919cc4ef-fb2a-4fc2-aa7c-b3beb7432fd2@googlegroups.com> Message-ID: Lauren Porter wrote: > Hello all! I've been trying to create a game in Python Processing where a spaceship moves horizontally in order to miss a collision with an asteroid. I'm having difficulty making it so that the game quits when an asteroid hits the spaceship, could anybody help? Here is my code. The code looks rather "naked" with any sort of documentation. Do you want to ask us to figure out how it is supposed to work in order to help you? My debugging suggestion is "print, print, print!" so you can follow what your code is doing. I find that the sooner I start doing that, the sooner my debugging session is over. Good luck! Bill > As you can see, I tried using globals in order use variables from previous classes, but nothing has worked. For this specific approach, no error message popped up, but nothing happened either. Thanks so much! > > COLORS = {"black":"#000000", "white":"#FFFFFF", > "red":"#FF0000", "green":"#00FF00", > "blue":"#D1F5FF", "yellow":"#FFFF00", > "orange":"#FFA500", "hendrixorange":"#F58025", > "purple":"#9B30FF", "gray":"#808080", "lightgray": "#CACACA", > "darkgray":"#A9A9A9"} > import random > asteroid = [] > spaceship = [] > stars = [] > justPressed = False > aX = 0 > aY = 0 > x = 0 > y = 0 > > def setup(): > global aX, aY, X, Y > size(640, 480) > for s in range(1): > X = 320 > Y = 440 > spaceship.append(Space(X, Y, COLORS["orange"])) > for a in range(4): > aX = random.randint(0, 640) > aY = 0 > asteroid.append(Asteroid(aX, aY, COLORS["orange"])) > for d in range(100): > randX = random.randint(0, 640) > randY = random.randint(0, 480) > stars.append(Star(randX, randY, COLORS["orange"])) > > > > class Space: > def __init__(self, x, y, color): > self.x = x > self.y = y > self.color = color > > def spaceship(self): > fill(COLORS["blue"]) > stroke(COLORS["white"]) > ellipse(self.x, self.y, 75, 75) #body > fill(COLORS["green"]) > fill(COLORS["gray"]) > stroke(COLORS["green"]) > ellipse(self.x, self.y + 20, 120, 35) > stroke(COLORS["orange"]) > fill(COLORS["purple"]) > ellipse(self.x, self.y + 20, 10, 10) > ellipse(self.x + 30, self.y + 20, 10, 10) > ellipse(self.x - 30, self.y + 20, 10, 10) > > def move(self, dx, dy): > self.x += dx > self.y += dy > > class Asteroid: > def __init__(self, x, y, color): > self.x = x > self.y = y > self.color = color > > def update(self): > self.velx = 0 > self.vely = random.randint(1, 5) > self.x += self.velx > self.y += self.vely > if self.y > 480: > self.y = 0 > self.x = random.randint(1,640) > > def asteroid(self): > fill(COLORS["lightgray"]) > stroke(COLORS["white"]) > ellipse(self.x, self.y, 50, 50) > fill(COLORS["gray"]) > ellipse(self.x +15, self.y + 6, 15, 15) > ellipse(self.x -12, self.y + 7, 10, 10) > ellipse(self.x + 5, self.y - 13, 11, 11) > ellipse(self.x - 12, self.y - 9, 7, 7) > ellipse(self.x + 2, self.y + 18, 7, 7) > > class Star: > def __init__(self, x, y, color): > self.x = x > self.y = y > self.color = color > > def star(self): > fill(COLORS["white"]) > ellipse(self.x, self.y, 3, 3) > > > def draw(): > global justPressed > background(COLORS["black"]) > for f in stars: > f.star() > for f in spaceship: > f.spaceship() > if f.x < 60: > f.move(3, 0) > elif f.x > 580: > f.move(-3, 0) > elif justPressed : > if key == 'd': > f.move(3, 0) > elif key == 'a': > f.move(-3, 0) > for f in asteroid: > f.asteroid() > f.update() > #collision detection 'for' loop > distance = sqrt(((aX - X)**2) + ((aY - Y)**2)) > for f in asteroid: > if distance < 62.5: > background(COLORS["red"]) > > > def keyTyped(): > global justPressed > justPressed = True > print("typed", key) > > def keyPressed(): > global justPressed > justPressed = True > print("pressed", key) > From dieter at handshake.de Mon Dec 11 02:46:56 2017 From: dieter at handshake.de (dieter) Date: Mon, 11 Dec 2017 08:46:56 +0100 Subject: Can't install wrapt on Windows References: <5a2dadae$0$7181$426a74cc@news.free.fr> Message-ID: <87374hogen.fsf@handshake.de> Cutter writes: > ... > I have trouble installing pylint on Windows 10, Python 3.6. There's a > problem during the installation of wrapt, which is a dependency of > pylint. > > Here are the contents of the commandline: > >> C:\WINDOWS\system32>python -m pip install pylint >> ... >> Collecting wrapt (from astroid>=1.5.1->pylint) >> Using cached wrapt-1.10.11.tar.gz >> Installing collected packages: colorama, wrapt, astroid, pylint >> Running setup.py install for wrapt ... error >> Exception: >> Traceback (most recent call last): >> File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str >> return s.decode(sys.__stdout__.encoding) >> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: invalid start byte Obviously, something causes some "s" to be decoded using the "stdout" encoding (which usually is the system encoding). In your case, this encoding is "utf-8", but "s" does not seem to be utf-8 encoded. I would use debugging to find out what "s" is, where is comes from and why it does not use the "stdout" encoding. From fmassion at web.de Mon Dec 11 06:14:09 2017 From: fmassion at web.de (F Massion) Date: Mon, 11 Dec 2017 03:14:09 -0800 (PST) Subject: request fails on wikipedia (https) - certificate verify failed (_ssl.c:748) Message-ID: <20f299c0-9ab2-4ce2-87a2-7a723d0805ce@googlegroups.com> Hi, I would like to get information from Wikipedia articles and I am testing the connection to Wikipedia. I am running Python 3.6.2 on Windows 10. I get certificate errors for all pages with https. Any suggestions are welcome! Here my code: import requests, bs4 from bs4 import BeautifulSoup res = requests.get('https://en.wikipedia.org/wiki/Stethoscope') type(res) res.status_code == requests.codes.ok wiki = bs4.BeautifulSoup(res.text) type(wiki) len(res.text) print(res.text[:250]) Here the error message: Traceback (most recent call last): File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen chunked=chunked) File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request self._validate_conn(conn) File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn conn.connect() File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connection.py", line 326, in connect ssl_context=context) File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 401, in wrap_socket _context=self, _session=session) File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 808, in __init__ self.do_handshake() File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 1061, in do_handshake self._sslobj.do_handshake() File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 683, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send timeout=timeout File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen _stacktrace=sys.exc_info()[2]) File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\util\retry.py", line 388, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /wiki/Stethoscope (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "web_1.py", line 3, in res = requests.get('https://en.wikipedia.org/wiki/Stethoscope') File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\api.py", line 72, in get return request('get', url, params=params, **kwargs) File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\adapters.py", line 506, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /wiki/Stethoscope (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)) From kryptxy at protonmail.com Mon Dec 11 06:22:07 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Mon, 11 Dec 2017 06:22:07 -0500 Subject: request fails on wikipedia (https) - certificate verify failed (_ssl.c:748) In-Reply-To: <20f299c0-9ab2-4ce2-87a2-7a723d0805ce@googlegroups.com> References: <20f299c0-9ab2-4ce2-87a2-7a723d0805ce@googlegroups.com> Message-ID: Install pyopenssl package and try again? -------- Original Message -------- On 11 Dec 2017, 16:44, F Massion wrote: > Hi, > > I would like to get information from Wikipedia articles and I am testing the connection to Wikipedia. > > I am running Python 3.6.2 on Windows 10. > > I get certificate errors for all pages with https. > Any suggestions are welcome! > > Here my code: > > import requests, bs4 > from bs4 import BeautifulSoup > res = requests.get('https://en.wikipedia.org/wiki/Stethoscope') > type(res) > res.status_code == requests.codes.ok > wiki = bs4.BeautifulSoup(res.text) > type(wiki) > len(res.text) > print(res.text[:250]) > > Here the error message: > > Traceback (most recent call last): > File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen > chunked=chunked) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request > self._validate_conn(conn) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn > conn.connect() > File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connection.py", line 326, in connect > ssl_context=context) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket > return context.wrap_socket(sock, server_hostname=server_hostname) > File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 401, in wrap_socket > _context=self, _session=session) > File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 808, in __init__ > self.do_handshake() > File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 1061, in do_handshake > self._sslobj.do_handshake() > File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 683, in do_handshake > self._sslobj.do_handshake() > ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send > timeout=timeout > File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen > _stacktrace=sys.exc_info()[2]) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\urllib3\util\retry.py", line 388, in increment > raise MaxRetryError(_pool, url, error or ResponseError(cause)) > urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /wiki/Stethoscope (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)) > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "web_1.py", line 3, in > res = requests.get('https://en.wikipedia.org/wiki/Stethoscope') > File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\api.py", line 72, in get > return request('get', url, params=params, **kwargs) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\api.py", line 58, in request > return session.request(method=method, url=url, **kwargs) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request > resp = self.send(prep, **send_kwargs) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send > r = adapter.send(request, **kwargs) > File "c:\Program Files (x86)\Python36-32\lib\site-packages\requests\adapters.py", line 506, in send > raise SSLError(e, request=request) > requests.exceptions.SSLError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /wiki/Stethoscope (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)) > -- > https://mail.python.org/mailman/listinfo/python-list From larry.martell at gmail.com Mon Dec 11 08:30:57 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 11 Dec 2017 08:30:57 -0500 Subject: scipy In-Reply-To: <082a2e8e-5d1f-ca18-16b3-84fe3e740d7b@tjol.eu> References: <082a2e8e-5d1f-ca18-16b3-84fe3e740d7b@tjol.eu> Message-ID: On Sat, Dec 9, 2017 at 11:43 AM, Thomas Jollans wrote: > > On 08/12/17 23:57, Larry Martell wrote: > > Trying to install scipy on ubuntu-trusty-64 running Python 2.7.6. > > I STRONGLY recommend moving to Python 3 if you can. The scientific > python ecosystem has had good support for Python 3 for years now. Many > scientific packages, including numpy (the king of scientific > Pythonland), have decided to drop official Python 2 support fairly soon; > numpy will not release any new versions for Python 2 after 2018. It's not in my control. This is part of a django app that is deployed it many sites all over the world, and my customer wants to make as few changes as possible. > > It's failing with: > > > > $ sudo pip install scipy > > Downloading/unpacking scipy > > Downloading scipy-1.0.0.tar.gz (15.2MB): 15.2MB downloaded > > Running setup.py (path:/tmp/pip_build_root/scipy/setup.py) egg_info > > for package scipy > > /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown > > distribution option: 'python_requires' > > > > Followed by many screens full of errors. Is that just a warning or is > > that the issue? I've installed many other packages without a problem > > on this same system. What is the issue here? > > > > I'm just guessing here, but do you have the latest versions of > distutils, setuptools and pip? It's likely that scipy requires newer > versions of these than your distribution provides. You may have to > upgrade them. I resolved this by installing a newer version of pip. From neilc at norwich.edu Mon Dec 11 08:48:32 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 11 Dec 2017 13:48:32 +0000 (UTC) Subject: csv.DictReader line skipping should be considered a bug? References: <2574297724@f38.n261.z1.binkp.net> <2891836479@f38.n261.z1.binkp.net> Message-ID: On 2017-12-05, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 04:20 am, Jason wrote: >> while iterating over two files, which are line-by-line >> corresponding. The DictReader skipped ahead many lines >> breaking the line-by-line correspondence. > > Um... this doesn't follow. If they are line-by-line > corresponding, then they should skip the same number of blank > lines and read the same number of non-blank lines. > > Even if one file has blanks and the other does not, if you > iterate the over the records themselves, they should keep their > correspondence. > > I'm afraid that if you want to convince me this is a buggy > design, you need to demonstrate a simple pair of CSV files > where the non-blank lines are corresponding (possibly with > differing numbers of blanks in between) but the CSV readers get > out of alignment somehow. Preface: I'm not arguing for this to be changed--it obviously cannot be at this point, and we know how to work around it when it matters--although the current design does make finding the erronesou records needlessly harder than it needs to be. Examine the records that DictReader returns for the following csv file and see if you think it still feels obvious and usable. A,B,C a,b,c a,b a a,b a,b,c Furthermore, see what DictWriter produces from this program: with open("wcsv.csv", 'w', newline='') as f: writer = csv.DictWriter(f, fieldnames=('A', 'B', 'C')) writer.writeheader() for rec in ( {'A': 'a', 'B': 'b', 'C': 'c'}, {'A': 'a', 'B': 'b'}, {'A': 'a'}, {}, {'A': 'a'}, {'A': 'a', 'B': 'b'}, {'A': 'a', 'B': 'b', 'C': 'c'},): writer.writerow(rec) DictReader doesn't handle the output of DictWriter in a usable and recoverable way. >> And I want to argue that the difference of behavior should be >> considered a bug. It should be considered as such because: 1. >> I need to know what's in the file to know what class to use. > > Sure. But blank lines don't tell you what class to use. > >> The file content should not break at-least-1-record-per-line. > > Blank lines DO break that requirement. A blank line is not a > record. Except it inconsistently is one for DictWriter, which if you were right should produce no output for an empty dict. > is a blank record with five empty fields. \n alone is just a > blank. The DictReader correctly returns records with blank > fields. The question to me is what should DictReader do when the hopeful constraint that the header defines the number of fields is broken in the data. In my opinion, it should do a thing that makes it the simplest to handle the situation for the programmer. This is in fact usually what happens. When there are more records than define in the header, you can choose what happens by setting extrasaction. When some records are missing--it sets them to None. Except, when all the records are missing, it silently hides the error with no ability provided to recover it. -- Neil Cerutti From neilc at norwich.edu Mon Dec 11 08:59:26 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 11 Dec 2017 13:59:26 +0000 (UTC) Subject: csv.DictReader line skipping should be considered a bug? References: <2574297724@f38.n261.z1.binkp.net> <2891836479@f38.n261.z1.binkp.net> Message-ID: On 2017-12-11, Neil Cerutti wrote: > On 2017-12-05, Steve D'Aprano wrote: >> On Wed, 6 Dec 2017 04:20 am, Jason wrote: >>> while iterating over two files, which are line-by-line >>> corresponding. The DictReader skipped ahead many lines >>> breaking the line-by-line correspondence. >> >> Um... this doesn't follow. If they are line-by-line >> corresponding, then they should skip the same number of blank >> lines and read the same number of non-blank lines. >> >> Even if one file has blanks and the other does not, if you >> iterate the over the records themselves, they should keep their >> correspondence. >> >> I'm afraid that if you want to convince me this is a buggy >> design, you need to demonstrate a simple pair of CSV files >> where the non-blank lines are corresponding (possibly with >> differing numbers of blanks in between) but the CSV readers get >> out of alignment somehow. > > Preface: I'm not arguing for this to be changed--it obviously > cannot be at this point, and we know how to work around it when > it matters--although the current design does make finding the > erronesou records needlessly harder than it needs to be. > > Examine the records that DictReader returns for the following csv > file and see if you think it still feels obvious and usable. > > A,B,C > a,b,c > a,b > a > > a,b > a,b,c > > Furthermore, see what DictWriter produces from this program: > > with open("wcsv.csv", 'w', newline='') as f: > writer = csv.DictWriter(f, fieldnames=('A', 'B', 'C')) > writer.writeheader() > for rec in ( > {'A': 'a', 'B': 'b', 'C': 'c'}, > {'A': 'a', 'B': 'b'}, > {'A': 'a'}, > {}, > {'A': 'a'}, > {'A': 'a', 'B': 'b'}, > {'A': 'a', 'B': 'b', 'C': 'c'},): > writer.writerow(rec) > > DictReader doesn't handle the output of DictWriter in a usable > and recoverable way. DOH! Never mind this part of my argument. I'll take some time to eat these eggs on my face. ;) -- Neil Cerutti From torriem at gmail.com Mon Dec 11 10:59:14 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Dec 2017 08:59:14 -0700 Subject: Processing Game Help In-Reply-To: <5n4t2dl3vifu4b6qsnmoi200ud4ojkuroh@4ax.com> References: <919cc4ef-fb2a-4fc2-aa7c-b3beb7432fd2@googlegroups.com> <5n4t2dl3vifu4b6qsnmoi200ud4ojkuroh@4ax.com> Message-ID: On 12/11/2017 07:27 AM, Dennis Lee Bieber wrote: > On Sun, 10 Dec 2017 16:05:37 -0800 (PST), Lauren Porter > declaimed the following: > >> Hello all! I've been trying to create a game in Python Processing ^^^^^^^^^^^^^^^^^^^^ Seems like most of the replies missed this information. http://py.processing.org/ >> where a spaceship moves horizontally in order to miss a collision with >> an asteroid. >> > Global variables are seldom the proper solution -- especially if, as > you say, you have classes (in which case you likely should be > providing an instance of the class and modifying its contents) Except that with Processing, global variables are the only way to share things between the setup() function and the loop() function, since both are called directly by the framework. > And NO SIGN of a main program to actually call any of it. You've > defined a half dozen functions, and a few classes, but nothing to run any > of it. This is a python script that runs within the Processing framework, so it has no "main program" in the traditional sense. setup() and loop() are the entry points. Unfortunately this is confusing both to us on the mailing list and to the original poster, as I doubt very few of us use the Processing framework (unless you've worked with Arduino), and the OP is led to think that Python Processing is the same thing as generic Python (which it kind of is...). The OP probably will want to consult with the community at the Processing website (https://forum.processing.org/two/). From __peter__ at web.de Mon Dec 11 13:46:55 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Dec 2017 19:46:55 +0100 Subject: Processing Game Help References: <919cc4ef-fb2a-4fc2-aa7c-b3beb7432fd2@googlegroups.com> Message-ID: Lauren Porter wrote: > Hello all! I've been trying to create a game in Python Processing where a > spaceship moves horizontally in order to miss a collision with an > asteroid. I'm having difficulty making it so that the game quits when an > asteroid hits the spaceship, could anybody help? Here is my code. As you > can see, I tried using globals in order use variables from previous > classes, but nothing has worked. For this specific approach, no error > message popped up, but nothing happened either. Thanks so much! > > COLORS = {"black":"#000000", "white":"#FFFFFF", > "red":"#FF0000", "green":"#00FF00", > "blue":"#D1F5FF", "yellow":"#FFFF00", > "orange":"#FFA500", "hendrixorange":"#F58025", > "purple":"#9B30FF", "gray":"#808080", "lightgray": "#CACACA", > "darkgray":"#A9A9A9"} > import random > asteroid = [] > spaceship = [] > stars = [] > justPressed = False > aX = 0 > aY = 0 > x = 0 > y = 0 > > def setup(): > global aX, aY, X, Y > size(640, 480) > for s in range(1): > X = 320 > Y = 440 > spaceship.append(Space(X, Y, COLORS["orange"])) > for a in range(4): > aX = random.randint(0, 640) > aY = 0 > asteroid.append(Asteroid(aX, aY, COLORS["orange"])) > for d in range(100): > randX = random.randint(0, 640) > randY = random.randint(0, 480) > stars.append(Star(randX, randY, COLORS["orange"])) > > > > class Space: > def __init__(self, x, y, color): > self.x = x > self.y = y > self.color = color > > def spaceship(self): > fill(COLORS["blue"]) > stroke(COLORS["white"]) > ellipse(self.x, self.y, 75, 75) #body > fill(COLORS["green"]) > fill(COLORS["gray"]) > stroke(COLORS["green"]) > ellipse(self.x, self.y + 20, 120, 35) > stroke(COLORS["orange"]) > fill(COLORS["purple"]) > ellipse(self.x, self.y + 20, 10, 10) > ellipse(self.x + 30, self.y + 20, 10, 10) > ellipse(self.x - 30, self.y + 20, 10, 10) > > def move(self, dx, dy): > self.x += dx > self.y += dy > > class Asteroid: > def __init__(self, x, y, color): > self.x = x > self.y = y > self.color = color > > def update(self): > self.velx = 0 > self.vely = random.randint(1, 5) > self.x += self.velx > self.y += self.vely > if self.y > 480: > self.y = 0 > self.x = random.randint(1,640) > > def asteroid(self): > fill(COLORS["lightgray"]) > stroke(COLORS["white"]) > ellipse(self.x, self.y, 50, 50) > fill(COLORS["gray"]) > ellipse(self.x +15, self.y + 6, 15, 15) > ellipse(self.x -12, self.y + 7, 10, 10) > ellipse(self.x + 5, self.y - 13, 11, 11) > ellipse(self.x - 12, self.y - 9, 7, 7) > ellipse(self.x + 2, self.y + 18, 7, 7) > > class Star: > def __init__(self, x, y, color): > self.x = x > self.y = y > self.color = color > > def star(self): > fill(COLORS["white"]) > ellipse(self.x, self.y, 3, 3) > > > def draw(): > global justPressed > background(COLORS["black"]) > for f in stars: > f.star() > for f in spaceship: > f.spaceship() > if f.x < 60: > f.move(3, 0) > elif f.x > 580: > f.move(-3, 0) > elif justPressed : > if key == 'd': > f.move(3, 0) > elif key == 'a': > f.move(-3, 0) > for f in asteroid: I'd swap the following lines to move the asteroid before drawing it. That way the x and y attributes keep in sync with what the user sees. > f.asteroid() > f.update() Remove this: > #collision detection 'for' loop > distance = sqrt(((aX - X)**2) + ((aY - Y)**2)) You can test for a collision and exit if an asteroid is close to a spaceship with for s in spaceship: for a in asteroid: if calculate_distance(s, a) < 62.5: print("One of your ships was hit by an asteroid") exit() There are two loops because you want to test every asteroid for every spaceship (although you only have one at the moment). I defined calculate_distance() as def calculate_distance(a, b): dx = a.x - b.x dy = a.y - b.y return sqrt(dx*dx + dy * dy) As invoked in the for loops `a` will be bound to a spaceship and `b` to an asteroid. The function uses the x and y attributes of these objects, so you do not need global variables for coordinates. > def keyTyped(): > global justPressed > justPressed = True > print("typed", key) > > def keyPressed(): > global justPressed > justPressed = True > print("pressed", key) From rosuav at gmail.com Mon Dec 11 14:13:01 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Dec 2017 06:13:01 +1100 Subject: Processing Game Help In-Reply-To: References: <919cc4ef-fb2a-4fc2-aa7c-b3beb7432fd2@googlegroups.com> Message-ID: On Tue, Dec 12, 2017 at 5:46 AM, Peter Otten <__peter__ at web.de> wrote: > You can test for a collision and exit if an asteroid is close to a spaceship > with > > for s in spaceship: > for a in asteroid: > if calculate_distance(s, a) < 62.5: > print("One of your ships was hit by an asteroid") > exit() > > There are two loops because you want to test every asteroid for every > spaceship (although you only have one at the moment). Then shouldn't they be "spaceships" and "asteroids" in the plural? It looks wrong to iterate over a singular asteroid. (And I'd prefer to iterate over a collection of spaceships in the plural even if I know it's a list of one, though I can understand that a list of one is a tricky case for some people.) ChrisA From python at bladeshadow.org Mon Dec 11 15:53:25 2017 From: python at bladeshadow.org (Python) Date: Mon, 11 Dec 2017 14:53:25 -0600 Subject: Python homework In-Reply-To: <59472662@f38.n261.z1.binkp.net> References: <3079057093@f38.n261.z1.binkp.net> <59472662@f38.n261.z1.binkp.net> Message-ID: <20171211205325.GL30413@bladeshadow.org> On Tue, Dec 05, 2017 at 09:02:54PM +1200, ssghotra1997 wrote: > for i in range(num): > rolls = int(random.randint(1, 6)) > if rolls == 1: > sides['One'] += 1 [...] Using integers as the key makes the code a bit shorter... That approach is also better if you're using a function where you don't know the full range, or if the range is very large. In that case, you don't need to initialize the dictionary; you can instead test if the index exists in the dictionary already, and if not set its value to 1. Much harder to do that if you use text keys (but not impossible--you could write a function that converts numbers to their text names). This is Python 2.7, but there's very little difference from the 3.x version: -=-=-=-=-=-=-=- #!/usr/bin/python import random def roll_die(times): sides = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0} for i in range(times): roll = int(random.randint(1, 6)) sides[roll] += 1 return sides, max(sides,key=sides.get) (rolls, max_side) = roll_die(50) print rolls print "%d was rolled the most: %d times." % (max_side, rolls[max_side]) -=-=-=-=-=-=-=- Both versions have a flaw: If there is a tie, only one is printed: $ ./sides.py {1: 11, 2: 7, 3: 6, 4: 6, 5: 11, 6: 9} 1 was rolled the most: 11 times. [So was 5.] Here's a version that prints all sides that were rolled the maximum number of times: -=-=-=-=-=-=-=- #!/usr/bin/python import random def roll_die(times): sides = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0} max_rolls_sides = [] # roll the dice... for i in range(times): roll = int(random.randint(1, 6)) sides[roll] += 1 # find the first side which was rolled the maximum number index = max(sides, key=sides.get) # get the number of rolls for the side we just got max_rolls = sides[index] # now find all sides that have that number of rolls for i in range(6): current_side = i + 1 if sides[current_side] == max_rolls: max_rolls_sides.append(current_side) # return all those things in a tuple return sides, max_rolls, max_rolls_sides # roll the dice 50 times, and print the results (rolls, max_roll, max_roll_sides) = roll_die(50) print rolls print "max rolls of %d was rolled on sides: %s." % (max_roll, max_roll_sides) -=-=-=-=-=-=-=- [The lines to calculate the index and the max_rolls can be combined, but I left them explicitly separated as I felt it improved clarity.] $ ./sides.py {1: 11, 2: 11, 3: 7, 4: 6, 5: 9, 6: 6} max rolls of 11 was rolled on sides: [1, 2]. $ ./sides.py {1: 8, 2: 9, 3: 9, 4: 7, 5: 8, 6: 9} max rolls of 9 was rolled on sides: [2, 3, 6]. From __peter__ at web.de Mon Dec 11 16:04:17 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Dec 2017 22:04:17 +0100 Subject: Processing Game Help References: <919cc4ef-fb2a-4fc2-aa7c-b3beb7432fd2@googlegroups.com> Message-ID: Chris Angelico wrote: > On Tue, Dec 12, 2017 at 5:46 AM, Peter Otten <__peter__ at web.de> wrote: >> You can test for a collision and exit if an asteroid is close to a >> spaceship with >> >> for s in spaceship: >> for a in asteroid: >> if calculate_distance(s, a) < 62.5: >> print("One of your ships was hit by an asteroid") >> exit() >> >> There are two loops because you want to test every asteroid for every >> spaceship (although you only have one at the moment). > > Then shouldn't they be "spaceships" and "asteroids" in the plural? Yes. (I started out with for spaceship in spacehips: for asteroid in asteroids: if distance(spaceship, asteroid) < 62.5: ... but then decided that while better in principle this slope was too slippery for me, and, after only a few minor changes, the OP would no longer recognize her script...) > It > looks wrong to iterate over a singular asteroid. (And I'd prefer to > iterate over a collection of spaceships in the plural even if I know > it's a list of one, though I can understand that a list of one is a > tricky case for some people.) Here's another line aX = random.randint(0, 640) that "hurts" almost as much as the missing plural. There are other naming problems (did you see the Spaceship class, the drawing methods?). If you write code for some time you develop a set of conventions that help you avoid certain errors, and allows others with similar experience to do sanity checks quickly. However, the script mostly works, has some nice graphics and responds to user input. That's quite an achievement. From rantingrickjohnson at gmail.com Mon Dec 11 17:34:54 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Dec 2017 14:34:54 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited) In-Reply-To: <269d9615-bdb0-4e2c-8a6b-427085b09270@googlegroups.com> References: <5591f442-1ec7-48fd-8184-f3c89979c35b@googlegroups.com> <2ac84820-c227-437d-b9bb-43975004279f@googlegroups.com> <5a272d5f$0$2719$b1db1813$eb6074ea@news.astraweb.com> <20171206212221.GF30413@bladeshadow.org> <5a28a778$0$2061$b1db1813$d948b532@news.astraweb.com> <20171208010831.GH30413@bladeshadow.org> <4f25d0a9-64a5-4d36-b072-97e293a7cadd@googlegroups.com> <950b31eb-ed13-48fa-b15f-e4d8d06e0ba7@googlegroups.com> <269d9615-bdb0-4e2c-8a6b-427085b09270@googlegroups.com> Message-ID: Lawrence D?Oliveiro wrote: > Rick Johnson wrote: > > And it's not like we can just pick file up and shake > > it, in a crude attempt to intuit the contents. > > Yes we can! BO??? Is that you? From jladasky at itu.edu Mon Dec 11 18:29:50 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Mon, 11 Dec 2017 15:29:50 -0800 (PST) Subject: Python homework In-Reply-To: References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: <628e5528-57e3-4237-8a1d-8d7aaa3fa28b@googlegroups.com> On Thursday, December 7, 2017 at 4:49:52 AM UTC-8, edmondo.g... at gmail.com wrote: > import numpy I teach Python to students at varying levels. As much as I love and use Numpy in my regular work, I try to avoid showing beginning Python students solutions that require third-party packages. Here are my reasons: 1. Not every programming novice needs to understand things at the bits-and-bytes level, but they should learn the inner workings of algorithms. You won't always have a ready-made algorithm to solve your problem in a library function call, so you should learn to write your own. 2. Package maintenance can be its own headache. Sure, Anaconda can help, but it's a heavyweight distribution. And not every student is working on a computer where they have the rights to install software. From rustompmody at gmail.com Mon Dec 11 20:37:13 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Dec 2017 17:37:13 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: <2882728314@f38.n261.z1.binkp.net> References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> Message-ID: <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> This thread is getting like a mini hologram of our current surreal time? If we can put aside who is right and wrong for a moment we see the more frightening spectacle that Repubs and democrats, Remainers and Brexiters and so on all over ? by getting more and more shrill are not talking to each other but past each other So? On Tuesday, December 12, 2017 at 2:45:32 AM UTC+5:30, Rick Johnson wrote: > Rustom Mody wrote: > > [...] > > > Whether there was nothing wrong in what I did, the "wrong- > > right" was de facto, or de jure? | I will leave to more wise > > persons than myself > > A file with no extension (regardless of the OS or desktop enviroment that it > was created on), is like a sealed box with no label to indicate the contents. So to Rick: Not if you use something like file (magic) My (unschooled) estimate is it gets its detection right 80% of the time And to Chris and others who think file(magic) is a replacement for file-associations. Even assuming that magic works 100% : Say I have an html file. That means its ALSO a text file. So its equally legitimate to set defaults to use? - a plain text editor (of which there are hundreds) - to open it in browser of choice (also plural nowadays) - some sort of html composer - etc Which means we are beyond the nature of the file per se to the pattern of its usage Yeah? magic? in the category of mind-reading? sooth-saying? From rosuav at gmail.com Mon Dec 11 20:57:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Dec 2017 12:57:59 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: On Tue, Dec 12, 2017 at 12:37 PM, Rustom Mody wrote: > > This thread is getting like a mini hologram of our current surreal time? > If we can put aside who is right and wrong for a moment we see the more > frightening spectacle that Repubs and democrats, Remainers and Brexiters and so > on all over ? by getting more and more shrill are not talking to each other but > past each other > > So? > > On Tuesday, December 12, 2017 at 2:45:32 AM UTC+5:30, Rick Johnson wrote: >> Rustom Mody wrote: >> >> [...] >> >> > Whether there was nothing wrong in what I did, the "wrong- >> > right" was de facto, or de jure? | I will leave to more wise >> > persons than myself >> >> A file with no extension (regardless of the OS or desktop enviroment that it >> was created on), is like a sealed box with no label to indicate the contents. > > So to Rick: > > Not if you use something like file (magic) > My (unschooled) estimate is it gets its detection right 80% of the time > > And to Chris and others who think file(magic) is a replacement for file-associations. Even assuming that magic works 100% : > > Say I have an html file. > That means its ALSO a text file. > So its equally legitimate to set defaults to use? > - a plain text editor (of which there are hundreds) > - to open it in browser of choice (also plural nowadays) > - some sort of html composer > - etc > > Which means we are beyond the nature of the file per se to the pattern of its usage > > Yeah? magic? in the category of mind-reading? sooth-saying? Which is why OS/2, back in the 1990s, had *multiple* associations for any given file. You could use file types (sadly not MIME types - this was before MIME was the one obvious standard to use) to identify *any number* of programs that are likely to be used with a file, and then one of them is the global default. For any specific file, you can change which program is its own default, and even add specific associations for that individual file. When you double-click, you get the default; if you right-click and choose "Open", you could pick from the associated programs. A good system, and one that I still haven't seen replicated in a mainstream OS. ChrisA From dieter at handshake.de Tue Dec 12 02:29:33 2017 From: dieter at handshake.de (dieter) Date: Tue, 12 Dec 2017 08:29:33 +0100 Subject: request fails on wikipedia (https) - certificate verify failed (_ssl.c:748) References: <20f299c0-9ab2-4ce2-87a2-7a723d0805ce@googlegroups.com> Message-ID: <87h8swpfoi.fsf@handshake.de> F Massion writes: > ... > I would like to get information from Wikipedia articles and I am testing the connection to Wikipedia. > > I am running Python 3.6.2 on Windows 10. > > I get certificate errors for all pages with https. > Any suggestions are welcome! > ... > self._sslobj.do_handshake() > File "c:\Program Files (x86)\Python36-32\lib\ssl.py", line 683, in do_handshake > self._sslobj.do_handshake() > ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) There are too possibilities: * the certificate is really invalid * Python does not know the root certificate[s] necessary for the verification. To differenciate between the possibilities, connect (on the same computer) Wikipedia via a browser. If it, too, reports certificate problems, you likely have the first possibility; otherwise, the second. Python typically looks for root certificate information at the same (platform dependent) place as the browsers. Thus, normally, there is no need to tell Python where to look for them; but, you can do it in the case that the root certificates are installed strangely. Consult the documentation. From phd at phdru.name Tue Dec 12 07:23:22 2017 From: phd at phdru.name (Oleg Broytman) Date: Tue, 12 Dec 2017 13:23:22 +0100 Subject: mimedecode 2.9 Message-ID: <20171212122322.GA26965@phdru.name> mimedecode WHAT IS IT Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is good because it allows us to use appropriate format/encoding/whatever. Sometimes, though, some unification is desirable. For example, one may want to put mail messages into an archive, make HTML indices, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary attachments is much desirable. Here is the solution - mimedecode. This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which is treated as an RFC822 message, and decodes to stdout or an output file. If the file is not an RFC822 message it is just copied to the output one-to-one. If the file is a simple RFC822 message it is decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts are decoded. Decoding can be controlled by command-line options. Think about said mail archive; for example, its maintainer wants to put there only texts, convert PDF/Postscript to text, pass HTML and images decoding base64 to html but leaving images encoded, and ignore everything else. This is how it could be done: mimedecode -t application/pdf -t application/postscript -t text/plain -b text/html -B 'image/*' -i '*/*' Version 2.9.0 (2017-12-12) Split mimedecode.py into mimedecode library and a small script. Made the library executable via ``python -m mimedecode``. Version 2.8.0 (2017-11-03) Python 3. Stop supporting Python 2.6. WHERE TO GET Home page: http://phdru.name/Software/Python/#mimedecode git clone https://github.com/phdru/mimedecode.git git clone http://git.phdru.name/mimedecode.git git clone git://git.phdru.name/mimedecode.git Requires: Python 2.7 or Python 3.3+, m_lib.defenc 1.0+. Tests require: tox, m_lib 3.1+. Recommends: configured mailcap database. Documentation: http://phdru.name/Software/Python/mimedecode.html (also included in the package in html, man and txt formats). AUTHOR Oleg Broytman COPYRIGHT Copyright (C) 2001-2017 PhiloSoft Design. LICENSE GPL Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From jon+usenet at unequivocal.eu Tue Dec 12 08:33:13 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 12 Dec 2017 13:33:13 -0000 (UTC) Subject: request fails on wikipedia (https) - certificate verify failed (_ssl.c:748) References: <20f299c0-9ab2-4ce2-87a2-7a723d0805ce@googlegroups.com> Message-ID: On 2017-12-11, F Massion wrote: > ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) Try `pip install certifi` From rantingrickjohnson at gmail.com Tue Dec 12 08:52:41 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Dec 2017 05:52:41 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: <9023fd24-b9c2-49fd-bcc9-c1445cbf6bf5@googlegroups.com> Rustom Mody wrote: > This thread is getting like a mini hologram of our current > surreal time If we can put aside who is right and wrong > for a moment we see the more frightening spectacle that > Repubs and democrats, Remainers and Brexiters and so on all > over by getting more and more shrill are not talking to > each other but past each other I blame the confirmation bias of social media for the current state of dissed-discourse we find ourselves in these days. > > [Rick Johnson wrote] > > A file with no extension (regardless of the OS or desktop > > enviroment that it was created on), is like a sealed box > > with no label to indicate the contents. > > So to Rick: Not if you use something like file (magic) My > (unschooled) estimate is it gets its detection right 80% of > the time But this suggestion misses my point entirely. And the point is, we shouldn't have to pick-up the "box" (aka: file) and shake it (ook-ook) just to "intuit" what is inside. Using file extentions (aka: labels) solves this semantical problem much more elegantly. Now, is a perfect solution? Of course not! However, it is the most practical solution. > And to Chris and others who think file(magic) is a > replacement for file-associations. Even assuming that magic > works 100% : > Say I have an html file. > That means its ALSO a text file. > So its equally legitimate to set defaults to use: > - a plain text editor (of which there are hundreds) > - to open it in browser of choice (also plural nowadays) > - some sort of html composer > - etc > > Which means we are beyond the nature of the file per se to > the pattern of its usage And although an automated "intuitor" could easily determine if a file contained a markup language, we would still be force to "shake the box" by running it. From rantingrickjohnson at gmail.com Tue Dec 12 08:54:09 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Dec 2017 05:54:09 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: Chris Angelico wrote: [...] > > Yeah? magic? in the category of mind-reading? sooth- > > saying? > > Which is why OS/2, back in the 1990s, had *multiple* > associations for any given file. You could use file types > (sadly not MIME types - this was before MIME was the one > obvious standard to use) to identify *any number* of > programs that are likely to be used with a file, and then > one of them is the global default. For any specific file, > you can change which program is its own default, and even > add specific associations for that individual file. When > you double-click, you get the default; if you right-click > and choose "Open", you could pick from the associated > programs. A good system, and one that I still haven't seen > replicated in a mainstream OS. Windows has the same features. From rosuav at gmail.com Tue Dec 12 10:30:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Dec 2017 02:30:59 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: On Wed, Dec 13, 2017 at 12:54 AM, Rick Johnson wrote: > Chris Angelico wrote: > > [...] > >> > Yeah? magic? in the category of mind-reading? sooth- >> > saying? >> >> Which is why OS/2, back in the 1990s, had *multiple* >> associations for any given file. You could use file types >> (sadly not MIME types - this was before MIME was the one >> obvious standard to use) to identify *any number* of >> programs that are likely to be used with a file, and then >> one of them is the global default. For any specific file, >> you can change which program is its own default, and even >> add specific associations for that individual file. When >> you double-click, you get the default; if you right-click >> and choose "Open", you could pick from the associated >> programs. A good system, and one that I still haven't seen >> replicated in a mainstream OS. > > Windows has the same features. It does? Show me how to specify that one file - which might have the exact same name as many similar files - should be associated with a different program than the one its name would normally suggest. Show me how to identify multiple file types for a given file, independently of its filename. ChrisA From alister.ware at ntlworld.com Tue Dec 12 11:51:17 2017 From: alister.ware at ntlworld.com (alister) Date: Tue, 12 Dec 2017 16:51:17 GMT Subject: Please tell me how to execute python file in Ubuntu by double References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <9023fd24-b9c2-49fd-bcc9-c1445cbf6bf5@googlegroups.com> Message-ID: <9OTXB.227839$QV3.108742@fx11.am4> On Tue, 12 Dec 2017 05:52:41 -0800, Rick Johnson wrote: > Rustom Mody wrote: >> This thread is getting like a mini hologram of our current surreal time >> If we can put aside who is right and wrong for a moment we see the >> more frightening spectacle that Repubs and democrats, Remainers and >> Brexiters and so on all over by getting more and more shrill are not >> talking to each other but past each other > > I blame the confirmation bias of social media for the current state of > dissed-discourse we find ourselves in these days. > >> > [Rick Johnson wrote] >> > A file with no extension (regardless of the OS or desktop enviroment >> > that it was created on), is like a sealed box with no label to >> > indicate the contents. >> >> So to Rick: Not if you use something like file (magic) My (unschooled) >> estimate is it gets its detection right 80% of the time > > But this suggestion misses my point entirely. And the point is, we > shouldn't have to pick-up the "box" (aka: file) and shake it (ook-ook) > just to "intuit" what is inside. Using file extentions (aka: labels) > solves this semantical problem much more elegantly. Now, is a perfect > solution? Of course not! However, it is the most practical solution. > >> And to Chris and others who think file(magic) is a replacement for >> file-associations. Even assuming that magic works 100% : >> Say I have an html file. >> That means its ALSO a text file. >> So its equally legitimate to set defaults to use: >> - a plain text editor (of which there are hundreds) >> - to open it in browser of choice (also plural nowadays) >> - some sort of html composer - etc >> >> Which means we are beyond the nature of the file per se to the pattern >> of its usage > > And although an automated "intuitor" could easily determine if a file > contained a markup language, we would still be force to "shake the box" > by running it. Back to the original problem has the execute bit been set on the file? -- All Hell hadn't been let loose. It was merely Detritus. But from a few feet away you couldn't tell the difference. (The Fifth Elephant) From fmassion at web.de Tue Dec 12 13:18:06 2017 From: fmassion at web.de (F Massion) Date: Tue, 12 Dec 2017 10:18:06 -0800 (PST) Subject: request fails on wikipedia (https) - certificate verify failed (_ssl.c:748) In-Reply-To: References: <20f299c0-9ab2-4ce2-87a2-7a723d0805ce@googlegroups.com> Message-ID: Am Dienstag, 12. Dezember 2017 14:33:42 UTC+1 schrieb Jon Ribbens: > On 2017-12-11, F Massion wrote: > > ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) > > Try `pip install certifi` certifi was installed. If I make the following changes I do not have the error message. I don't understand why, but this makes a difference: #import requests --> import urllib.request url = 'https://en.wikipedia.org/wiki/Stethoscope' #res = requests.get(url) --> res = urllib.request.urlopen(url).read() From eryksun at gmail.com Tue Dec 12 23:41:39 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 13 Dec 2017 04:41:39 +0000 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: On Tue, Dec 12, 2017 at 3:30 PM, Chris Angelico wrote: > On Wed, Dec 13, 2017 at 12:54 AM, Rick Johnson > wrote: >> Chris Angelico wrote: >> >>> Which is why OS/2, back in the 1990s, had *multiple* >>> associations for any given file. You could use file types >>> (sadly not MIME types - this was before MIME was the one >>> obvious standard to use) to identify *any number* of >>> programs that are likely to be used with a file, and then >>> one of them is the global default. For any specific file, >>> you can change which program is its own default, and even >>> add specific associations for that individual file. When >>> you double-click, you get the default; if you right-click >>> and choose "Open", you could pick from the associated >>> programs. A good system, and one that I still haven't seen >>> replicated in a mainstream OS. >> >> Windows has the same features. > > It does? Show me how to specify that one file - which might have the > exact same name as many similar files - should be associated with a > different program than the one its name would normally suggest. Show > me how to identify multiple file types for a given file, independently > of its filename. AFAIK that's not currently possible in Windows -- at least not without writing a custom shell extension. Hypothetically, the shell could support something like this on NTFS drives by storing a perceived type (e.g. text, audio, image, video) and lists of ProgIDs (e.g. txtfile, mp3file, jpegfile, mpegfile) either in a file's extended attributes (EAs) or an alternate data stream. I think OS/2 used EAs to store file associations. It's too bad NT's FAT32 doesn't support EAs (unlike FAT16 on NT, which needed them for the OS/2 subsystem) or alternate data streams. So an unobtrusive, decentralized approach that works automatically with existing backup software isn't feasible with FAT32 drives. That said, I don't see this feature as being very useful compared to just using "open with" when I occasionally need to open a file with a non-default program. From rosuav at gmail.com Wed Dec 13 00:43:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Dec 2017 16:43:55 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: On Wed, Dec 13, 2017 at 3:41 PM, eryk sun wrote: > On Tue, Dec 12, 2017 at 3:30 PM, Chris Angelico wrote: >> On Wed, Dec 13, 2017 at 12:54 AM, Rick Johnson >> wrote: >>> Chris Angelico wrote: >>> >>>> Which is why OS/2, back in the 1990s, had *multiple* >>>> associations for any given file. You could use file types >>>> (sadly not MIME types - this was before MIME was the one >>>> obvious standard to use) to identify *any number* of >>>> programs that are likely to be used with a file, and then >>>> one of them is the global default. For any specific file, >>>> you can change which program is its own default, and even >>>> add specific associations for that individual file. When >>>> you double-click, you get the default; if you right-click >>>> and choose "Open", you could pick from the associated >>>> programs. A good system, and one that I still haven't seen >>>> replicated in a mainstream OS. >>> >>> Windows has the same features. >> >> It does? Show me how to specify that one file - which might have the >> exact same name as many similar files - should be associated with a >> different program than the one its name would normally suggest. Show >> me how to identify multiple file types for a given file, independently >> of its filename. > > AFAIK that's not currently possible in Windows -- at least not without > writing a custom shell extension. Hypothetically, the shell could > support something like this on NTFS drives by storing a perceived type > (e.g. text, audio, image, video) and lists of ProgIDs (e.g. txtfile, > mp3file, jpegfile, mpegfile) either in a file's extended attributes > (EAs) or an alternate data stream. I think OS/2 used EAs to store file > associations. It's too bad NT's FAT32 doesn't support EAs (unlike > FAT16 on NT, which needed them for the OS/2 subsystem) or alternate > data streams. So an unobtrusive, decentralized approach that works > automatically with existing backup software isn't feasible with FAT32 > drives. Yeah, EAs were used for custom file associations and the "use that one as the default for this file" custom default. But honestly, who cares about FAT32? If the means of achieving this requires a better file system, eg NTFS or ext4, that's not much of a cost. > That said, I don't see this feature as being very useful compared to > just using "open with" when I occasionally need to open a file with a > non-default program. I used to often have a text executable associated with two or three things - "run", an editor, and maybe some ancillary tool like CASBuild. All files of that type would be associated with the same three targets, but for one, I might have double click do a regular run, but for another, I might always want it to go to CASBuild. Or perhaps a GUI application might be associated with the VX-REXX "run script" launcher rather than the regular console. A Windows equivalent would be to have a .py file associated normally with the regular console, but some individual ones associated with pythonw.exe - without renaming them to .pyw. AFAIK there is no way to do this on Windows short of renaming the files. ChrisA From lorenzofsutton at gmail.com Wed Dec 13 04:53:16 2017 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Wed, 13 Dec 2017 10:53:16 +0100 Subject: Python homework In-Reply-To: <3079057093@f38.n261.z1.binkp.net> References: <3079057093@f38.n261.z1.binkp.net> Message-ID: Hi, On 05/12/17 06:33, nick martinez2 via Python-list wrote: > I have a question on my homework. My homework is to write a program in which > the computer simulates the rolling of a die 50 times and then prints > (i). the most frequent side of the die (ii). the average die value of all > rolls. For this kind of problem I think the collections module [1] can be very useful. In this case in particular have a look at the Counter package ;) Lorenzo. [1] https://docs.python.org/3.6/library/collections.html I wrote the program so it says the most frequent number out of all the > rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I > need. This is what I have so far: > import random > > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls > > if __name__ == "__main__": > result = rollDie(50) > print (result) > print(max(result)) > From jon+usenet at unequivocal.eu Wed Dec 13 06:38:51 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 13 Dec 2017 11:38:51 -0000 (UTC) Subject: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited) References: <4169366685@f38.n261.z1.binkp.net> <3405516122@f38.n261.z1.binkp.net> <4e655a5e-bff2-4919-9c5e-c85ab16492ad@googlegroups.com> Message-ID: On 2017-12-13, Lawrence D?Oliveiro wrote: > On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: >> Try `pip install certifi` > > It really is preferable to install standard distro packages where available, rather than resort to pip: > > sudo apt-get install python3-certifi No, it really really isn't. From jon+usenet at unequivocal.eu Wed Dec 13 06:46:47 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 13 Dec 2017 11:46:47 -0000 (UTC) Subject: request fails on wikipedia (https) - certificate verify failed (_ss References: <3405516122@f38.n261.z1.binkp.net> <3717404664@f38.n261.z1.binkp.net> Message-ID: On 2017-12-11, F Massion wrote: > Am Dienstag, 12. Dezember 2017 14:33:42 UTC+1 schrieb Jon Ribbens: >> On 2017-12-11, F Massion wrote: >> > ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed > (_ssl.c:748) >> >> Try `pip install certifi` > > certifi was installed. > If I make the following changes I do not have the error message. I don't > understand why, but this makes a difference: > > #import requests --> import urllib.request > > url = 'https://en.wikipedia.org/wiki/Stethoscope' > #res = requests.get(url) --> res = urllib.request.urlopen(url).read() That's because that won't even try to verify the SSL certificate. From rosuav at gmail.com Wed Dec 13 07:01:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Dec 2017 23:01:46 +1100 Subject: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited) In-Reply-To: References: <4169366685@f38.n261.z1.binkp.net> <3405516122@f38.n261.z1.binkp.net> <4e655a5e-bff2-4919-9c5e-c85ab16492ad@googlegroups.com> Message-ID: On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens wrote: > On 2017-12-13, Lawrence D?Oliveiro wrote: >> On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: >>> Try `pip install certifi` >> >> It really is preferable to install standard distro packages where available, rather than resort to pip: >> >> sudo apt-get install python3-certifi > > No, it really really isn't. This isn't a connected series of statements intended to establish a proposition. This is just contradiction. Not very useful here. Care to elaborate as to why apt-get is such a bad thing? Generally, if you're using a system-provided Python (either Py2 or Py3) and not using a virtual environment, it's easier and safer to use your system-provided package manager to install additional components. If you want to argue otherwise, argue it, don't just assert it. ChrisA From antoon.pardon at vub.be Wed Dec 13 07:26:16 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 13 Dec 2017 13:26:16 +0100 Subject: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited) In-Reply-To: References: <4169366685@f38.n261.z1.binkp.net> <3405516122@f38.n261.z1.binkp.net> <4e655a5e-bff2-4919-9c5e-c85ab16492ad@googlegroups.com> Message-ID: <4fe1446f-1e4d-60dc-e009-63db4fe4b7f9@vub.be> Op 13-12-17 om 13:01 schreef Chris Angelico: > On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens wrote: >> On 2017-12-13, Lawrence D?Oliveiro wrote: >>> On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: >>>> Try `pip install certifi` >>> It really is preferable to install standard distro packages where available, rather than resort to pip: >>> >>> sudo apt-get install python3-certifi >> No, it really really isn't. > This isn't a connected series of statements intended to establish a > proposition. This is just contradiction. Not very useful here. Care to > elaborate as to why apt-get is such a bad thing? > > Generally, if you're using a system-provided Python (either Py2 or > Py3) and not using a virtual environment, it's easier and safer to use > your system-provided package manager to install additional components. > If you want to argue otherwise, argue it, don't just assert it. Why do you ask this of Jon Ribbens? As far as I can see, Laurence D'Oliveiro, just stated something as fact, without argument. Why do you give him a pass but expect Jon Ribbens to argue his position? -- Antoon Pardon From rosuav at gmail.com Wed Dec 13 07:31:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Dec 2017 23:31:19 +1100 Subject: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited) In-Reply-To: <4fe1446f-1e4d-60dc-e009-63db4fe4b7f9@vub.be> References: <4169366685@f38.n261.z1.binkp.net> <3405516122@f38.n261.z1.binkp.net> <4e655a5e-bff2-4919-9c5e-c85ab16492ad@googlegroups.com> <4fe1446f-1e4d-60dc-e009-63db4fe4b7f9@vub.be> Message-ID: On Wed, Dec 13, 2017 at 11:26 PM, Antoon Pardon wrote: > Op 13-12-17 om 13:01 schreef Chris Angelico: >> On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens wrote: >>> On 2017-12-13, Lawrence D?Oliveiro wrote: >>>> On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: >>>>> Try `pip install certifi` >>>> It really is preferable to install standard distro packages where available, rather than resort to pip: >>>> >>>> sudo apt-get install python3-certifi >>> No, it really really isn't. >> This isn't a connected series of statements intended to establish a >> proposition. This is just contradiction. Not very useful here. Care to >> elaborate as to why apt-get is such a bad thing? >> >> Generally, if you're using a system-provided Python (either Py2 or >> Py3) and not using a virtual environment, it's easier and safer to use >> your system-provided package manager to install additional components. >> If you want to argue otherwise, argue it, don't just assert it. > > Why do you ask this of Jon Ribbens? As far as I can see, Laurence D'Oliveiro, > just stated something as fact, without argument. Why do you give him a pass > but expect Jon Ribbens to argue his position? > Because Lawrence's post didn't come through to me, probably because he's put something in the headers to say that he doesn't want to talk to people on the mailing list, so I'm not going to (not really able to) do him the courtesy of replying. ChrisA From boffi at choices.random.py Wed Dec 13 08:28:46 2017 From: boffi at choices.random.py (boffi at choices.random.py) Date: Wed, 13 Dec 2017 14:28:46 +0100 Subject: Python homework References: <3079057093@f38.n261.z1.binkp.net> Message-ID: <87bmj23gfl.fsf@debian.i-did-not-set--mail-host-address--so-tickle-me> nick.martinez2 at aol.com (nick martinez2) writes: > def rollDie(number): > rolls = [0] * 6 > for i in range(0, number): > roll=int(random.randint(1,6)) > rolls[roll - 1] += 1 > return rolls def rollDie(number): from random import choices return choices((1,2,3,4,5,6), k=number) ps: sorry for the noise if someone else in this thread has already highlighted the usefulness of `random.choices` From jon+usenet at unequivocal.eu Wed Dec 13 09:36:40 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 13 Dec 2017 14:36:40 -0000 (UTC) Subject: request fails on wikipedia (https) - certificate verify failed (Posting On Python-List Prohibited) References: <4169366685@f38.n261.z1.binkp.net> <3405516122@f38.n261.z1.binkp.net> <4e655a5e-bff2-4919-9c5e-c85ab16492ad@googlegroups.com> Message-ID: On 2017-12-13, Chris Angelico wrote: > On Wed, Dec 13, 2017 at 10:38 PM, Jon Ribbens wrote: >> On 2017-12-13, Lawrence D?Oliveiro wrote: >>> On Wednesday, December 13, 2017 at 10:17:15 AM UTC+13, Jon Ribbens wrote: >>>> Try `pip install certifi` >>> >>> It really is preferable to install standard distro packages where available, rather than resort to pip: >>> >>> sudo apt-get install python3-certifi >> >> No, it really really isn't. > > This isn't a connected series of statements intended to establish a > proposition. This is just contradiction. Not very useful here. Care to > elaborate as to why apt-get is such a bad thing? > > Generally, if you're using a system-provided Python (either Py2 or > Py3) and not using a virtual environment, it's easier and safer to use > your system-provided package manager to install additional components. > If you want to argue otherwise, argue it, don't just assert it. I'll make assertions if I feel like it, especially in response to bare assertions. System-provided Python has tended to be a disaster and best kept at bargepole-distance. But regardless, in this specific case you'll note that the OP is clearly using Windows and therefore any advice to use 'sudo apt-get' will be less than entirely helpful. From paul at lanscape.io Wed Dec 13 11:23:21 2017 From: paul at lanscape.io (paul at lanscape.io) Date: Wed, 13 Dec 2017 08:23:21 -0800 (PST) Subject: Python homework In-Reply-To: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> Message-ID: <009badda-82f4-4f2a-93c2-42761af4afdc@googlegroups.com> from random import randint rolls = [randint(1, 6) for x in range(50)] print("Average: %s" % (sum(rolls) / len(rolls))) print("Most Common: %s" % max(rolls, key=rolls.count)) From rosuav at gmail.com Wed Dec 13 13:28:57 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Dec 2017 05:28:57 +1100 Subject: Python homework In-Reply-To: <009badda-82f4-4f2a-93c2-42761af4afdc@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> <009badda-82f4-4f2a-93c2-42761af4afdc@googlegroups.com> Message-ID: On Thu, Dec 14, 2017 at 3:23 AM, wrote: > from random import randint > > rolls = [randint(1, 6) for x in range(50)] > print("Average: %s" % (sum(rolls) / len(rolls))) > print("Most Common: %s" % max(rolls, key=rolls.count)) Great demo of a bad algorithm. :) ChrisA From eryksun at gmail.com Wed Dec 13 15:56:47 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 13 Dec 2017 20:56:47 +0000 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: On Wed, Dec 13, 2017 at 5:43 AM, Chris Angelico wrote: > > A Windows equivalent would be to have a .py file associated normally > with the regular console, but some individual ones associated with > pythonw.exe - without renaming them to .pyw. AFAIK there is no way to > do this on Windows short of renaming the files. If using another file is ok, then a shell shortcut or hard link would work.A symbolic link doesn't work because it seems the shell resolves the link before querying the file association. From rosuav at gmail.com Wed Dec 13 16:04:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Dec 2017 08:04:03 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: On Thu, Dec 14, 2017 at 7:56 AM, eryk sun wrote: > On Wed, Dec 13, 2017 at 5:43 AM, Chris Angelico wrote: >> >> A Windows equivalent would be to have a .py file associated normally >> with the regular console, but some individual ones associated with >> pythonw.exe - without renaming them to .pyw. AFAIK there is no way to >> do this on Windows short of renaming the files. > > If using another file is ok, then a shell shortcut or hard link would > work.A symbolic link doesn't work because it seems the shell resolves > the link before querying the file association. As workarounds go, a hardlink isn't too bad. (A shell shortcut has its own problems and limitations.) But you still need to be able to define a filename pattern, usually by specifying an extension, that catches the alternates. So it's definitely a workaround, not a true feature. ChrisA From eryksun at gmail.com Wed Dec 13 16:43:51 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 13 Dec 2017 21:43:51 +0000 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: On Wed, Dec 13, 2017 at 9:04 PM, Chris Angelico wrote: > On Thu, Dec 14, 2017 at 7:56 AM, eryk sun wrote: >> On Wed, Dec 13, 2017 at 5:43 AM, Chris Angelico wrote: >>> >>> A Windows equivalent would be to have a .py file associated normally >>> with the regular console, but some individual ones associated with >>> pythonw.exe - without renaming them to .pyw. AFAIK there is no way to >>> do this on Windows short of renaming the files. >> >> If using another file is ok, then a shell shortcut or hard link would >> work.A symbolic link doesn't work because it seems the shell resolves >> the link before querying the file association. > > As workarounds go, a hardlink isn't too bad. (A shell shortcut has its > own problems and limitations.) But you still need to be able to define > a filename pattern, usually by specifying an extension, that catches > the alternates. So it's definitely a workaround, not a true feature. I think a shell shortcut is a good workaround. It's less obtrusive than a hard link since the script still has the same name. The command line would be something like `"C:\Windows\pyw.exe" "path\to\script.py"`. Clear the shortcut's "start in" field to make pyw.exe inherit the working directory of the parent process. Add .LNK to the PATHEXT environment variable to support executing "script.lnk" as "script". From dvl at psu.edu Wed Dec 13 17:31:58 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Wed, 13 Dec 2017 17:31:58 -0500 Subject: Python homework In-Reply-To: mailman.23.1513184403.15737.python-list@python.org References: Message-ID: <1513204317l.42074304l.0l@psu.edu> On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > On 05/12/17 06:33, nick martinez2 via Python-list wrote: >> I have a question on my homework. My homework is to write a program in >which >> the computer simulates the rolling of a die 50 times and then prints >> (i). the most frequent side of the die (ii). the >average die value of all >> rolls. > >For this kind of problem I think the collections module [1] can be very >useful. In this case in particular have a look at the Counter package ;) > >Lorenzo. > >[1] https://docs.python.org/3.6/library/collections.html > > A nice answer at face value, and for general questions, but perhaps not the best given the subject line and the first sentence in the OP's note. Counting is such a fundamental programming skill, that I expect whoever teaches this course expects students to know how to count, without appealing to a third-party object to do all their work for them. When I teach my course, I have no desire to have all my students turn into cargo cultists. At least this particular student did post his intended solution, instead of outright begging for code. And most of the responses I see did attempt to work within the perceived constraints regarding what language tools the student was expected to use. Roger Christman Pennsylvania State University From tjreedy at udel.edu Wed Dec 13 18:18:08 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Dec 2017 18:18:08 -0500 Subject: Python homework In-Reply-To: <87bmj23gfl.fsf@debian.i-did-not-set--mail-host-address--so-tickle-me> References: <3079057093@f38.n261.z1.binkp.net> <87bmj23gfl.fsf@debian.i-did-not-set--mail-host-address--so-tickle-me> Message-ID: On 12/13/2017 8:28 AM, boffi at choices.random.py wrote: > nick.martinez2 at aol.com (nick martinez2) writes: > >> def rollDie(number): >> rolls = [0] * 6 >> for i in range(0, number): >> roll=int(random.randint(1,6)) One could just as well use randint(0, 5) and skip the -1 below. >> rolls[roll - 1] += 1 >> return rolls This returns a list with a count of how many times each of 1 to 6 is chosen in *number* rolls. > def rollDie(number): > from random import choices > return choices((1,2,3,4,5,6), k=number) This returns a list with all *number* rolls. Assuming the the first function is the one wanted, one could feed choices into a counter. (The import should be outside of the function.) def rollDie(number): rolls = [0] * 6 for i in random.choices((0,1,2,3,4,5), k=number): rolls[i] += 1 return rolls -- Terry Jan Reedy From info at wingware.com Wed Dec 13 18:20:24 2017 From: info at wingware.com (Wingware) Date: Wed, 13 Dec 2017 18:20:24 -0500 Subject: ANN: Wing Python IDE v. 6.0.9 released Message-ID: <5A31B5B8.70305@wingware.com> Hi, We've just released Wing 6.0.9, which adds support for Vagrant, improves support for Django and Plone, further improves remote development, fixes startup problems seen on some OS X systems, and makes about 35 other improvements. For details, see https://wingware.com/pub/wingide/6.0.9/CHANGELOG.txt Download now: http://wingware.com/downloads About Wing Wing is a family of cross-platform Python IDEs with powerful integrated editing, debugging, unit testing, and project management features. Wing runs on Windows, Linux, and OS X, and can be used to develop any kind of Python code for web, desktop, embedded scripting, and other applications. Wing 101 and Wing Personal omit some features and are free to download and use without a license. Wing Pro requires purchasing or upgrading a license, or obtaining a 30-day trial at startup. Version 6 introduces many new features, including improved multi-selection, much easier remote development, debugging from the Python Shell, recursive debugging, PEP 484 and 526 type hinting, support for Python 3.6, Vagrant, Jupyter, and Django 1.10+, easier Raspberry Pi development, optimized debugger, OS X full screen mode, One Dark color palette, expanded free product line, and much more. For details, see http://wingware.com/wingide/whatsnew. Wing 6 works with Python versions 2.5 through 2.7 and 3.2 through 3.6, including also Anaconda, ActivePython, EPD, Stackless, and others derived from the CPython implementation. For more product information, please visit wingware.com Upgrading You can try Wing 6 without removing older versions. Wing 6 will read and convert your old preferences, settings, and projects. Projects should be saved to a new name since previous versions of Wing cannot read Wing 6 projects. See also https://wingware.com/doc/install/migrating Links Release notice: https://wingware.com/news/2017-12-13 Downloads and Free Trial: https://wingware.com/downloads Buy: https://wingware.com/store/purchase Upgrade: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From jladasky at itu.edu Wed Dec 13 19:11:19 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Wed, 13 Dec 2017 16:11:19 -0800 (PST) Subject: Python homework In-Reply-To: References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> <45d22fd0-44aa-413c-b88f-916f0034d9b8@googlegroups.com> <9e642cb7-f974-1503-3bcf-6f9d8f1bf136@kynesim.co.uk> Message-ID: On Thursday, December 7, 2017 at 7:11:18 AM UTC-8, Rhodri James wrote: > Sigh. Please don't do people's homework for them. It doesn't teach > them anything. Now Nick had got 90% of the way there and shown his > working, which is truly excellent, but what he needed was for someone to > hint at how to search through the array, not to be handed a working > example with no explanation. I teach Python programming from time to time. I've noticed that a few people post quite esoteric solutions to students' homework problems. The unstated intent seems to be to get the student's teacher to quiz the student on their solution. When the student can't explain what the code does, a hard lesson will be learned. Mario Osorio's solution to the homework problem uses a list comprehension, formatted printing, and even a lambda function. If my students are new to Python and I see them using lambdas, you bet I'll be asking questions. All that being said: since Nick Martinez actually showed working code and explained where he was stuck, he doesn't strike me as the kind of student that needs a stealth lesson in the hazards of plagiarism. From rantingrickjohnson at gmail.com Wed Dec 13 20:35:37 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Dec 2017 17:35:37 -0800 (PST) Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> Message-ID: <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: [...] > That said, I don't see this feature as being very useful > compared to just using "open with" when I occasionally need > to open a file with a non-default program. That's the point i was trying to make, but i think it may have whoooshed over Chris's head. ;-) From rosuav at gmail.com Wed Dec 13 20:55:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Dec 2017 12:55:24 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> Message-ID: On Thu, Dec 14, 2017 at 12:35 PM, Rick Johnson wrote: > On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: > [...] >> That said, I don't see this feature as being very useful >> compared to just using "open with" when I occasionally need >> to open a file with a non-default program. > > That's the point i was trying to make, but i think it may > have whoooshed over Chris's head. ;-) No, it didn't. I just happen to have about twelve years' experience with a GUI system that has this as a feature, and I found it extremely helpful. It's funny how our experience colours our expectations, isn't it? We just won't settle for trash once we've tasted quality. ChrisA From yuriv1127 at gmail.com Wed Dec 13 22:13:50 2017 From: yuriv1127 at gmail.com (yuriv1127 at gmail.com) Date: Wed, 13 Dec 2017 19:13:50 -0800 (PST) Subject: Python GUI application embedding a web browser - Options? In-Reply-To: <1c4488d1-aafa-41c3-a2aa-8bd01837dc2f@googlegroups.com> References: <1c4488d1-aafa-41c3-a2aa-8bd01837dc2f@googlegroups.com> Message-ID: On Wednesday, October 19, 2016 at 3:08:15 AM UTC-7, Paul Moore wrote: > I'm looking to write a GUI application in Python (to run on Windows, using Python 3.5). The application is just a relatively thin wrapper around a browser - it's presenting an existing web application, just in its own window rather than in a standard browser window. I'm looking for advice on a good GUI toolkit to use. > > I've not done much GUI programming in Python, so I don't have a "preferred toolkit" as such. A bit of Google searching found an embedded browser widget in PyQt, but the examples I tried didn't work - it looks like the QWebView class is deprecated and has been removed in the current version of PyQt. I haven't really found any other examples (there's a "embedding a web page in Tkinter" example I found, but it looks like it's just doing rendering, not embedding a full browser - which I need as the site I want to access uses CSS/JavaScript). > > Is there any good option for this, or would I be better looking elsewhere for a solution? I could probably work out how to knock something up using .NET, or a HTA file, for example, I'm just more comfortable coding in Python. > > Thanks, > Paul From auriocus at gmx.de Thu Dec 14 01:44:01 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 14 Dec 2017 07:44:01 +0100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> Message-ID: Am 14.12.17 um 02:55 schrieb Chris Angelico: > On Thu, Dec 14, 2017 at 12:35 PM, Rick Johnson > wrote: >> On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: >> [...] >>> That said, I don't see this feature as being very useful >>> compared to just using "open with" when I occasionally need >>> to open a file with a non-default program. >> >> That's the point i was trying to make, but i think it may >> have whoooshed over Chris's head. ;-) > > No, it didn't. I just happen to have about twelve years' experience > with a GUI system that has this as a feature, and I found it extremely > helpful. It's funny how our experience colours our expectations, isn't > it? We just won't settle for trash once we've tasted quality. > I'm still unconvinced that this is much different from the Windows way (though I haven't used OS/2, so I'm probably missing something): Suppose, you have a file "Letter.txt" in your Documents folder on Windows. With standard settings, the "dumb" user (non IT expert) does not see the ".txt". It shows up as "Letter" with an icon for "written text". If you double click on it, Notepad will come up. If you right click, you'll see a list of programs which can open text files: Notepad, Wordpad, MS Word, any other editor you might have installed. How is the file extension different (to the regular user!) than a file type information stored in an alternate stream? Both are normally invisible and determine a default application as well as a number of programs which can open/edit the file. The only thing I can see from your description, apparently it was possible to change the default for an individual file ("Open this file always with Wordpad instead of Notepad") without changing th eglobal default. Is this the missing feature? Christian From rosuav at gmail.com Thu Dec 14 02:25:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Dec 2017 18:25:19 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> Message-ID: On Thu, Dec 14, 2017 at 5:44 PM, Christian Gollwitzer wrote: > Am 14.12.17 um 02:55 schrieb Chris Angelico: >> >> On Thu, Dec 14, 2017 at 12:35 PM, Rick Johnson >> wrote: >>> >>> On Tuesday, December 12, 2017 at 10:42:54 PM UTC-6, eryk sun wrote: >>> [...] >>>> >>>> That said, I don't see this feature as being very useful >>>> compared to just using "open with" when I occasionally need >>>> to open a file with a non-default program. >>> >>> >>> That's the point i was trying to make, but i think it may >>> have whoooshed over Chris's head. ;-) >> >> >> No, it didn't. I just happen to have about twelve years' experience >> with a GUI system that has this as a feature, and I found it extremely >> helpful. It's funny how our experience colours our expectations, isn't >> it? We just won't settle for trash once we've tasted quality. >> > > I'm still unconvinced that this is much different from the Windows way > (though I haven't used OS/2, so I'm probably missing something): > > Suppose, you have a file "Letter.txt" in your Documents folder on Windows. > With standard settings, the "dumb" user (non IT expert) does not see the > ".txt". It shows up as "Letter" with an icon for "written text". If you > double click on it, Notepad will come up. If you right click, you'll see a > list of programs which can open text files: Notepad, Wordpad, MS Word, any > other editor you might have installed. > > How is the file extension different (to the regular user!) than a file type > information stored in an alternate stream? Both are normally invisible and > determine a default application as well as a number of programs which can > open/edit the file. If you accept that a file's name consists of the "visible part" and the "part that affects file associations", then I suppose you could say that Windows allows you to customize a file's associations. However: 1) You can use this to select a file's category, but a file has to be in precisely one category. A file cannot be both a "text file" (associated with your editor of choice) and a "program file" (associated with "run this program") unless you create a "text program file" hybrid type and manually control your associations. Want to install a new text editor? Sure. Go associate it with all of your text types. With OS/2's type system, a program can choose on installation to associate itself with "Plain Text", and then all text-y files will see that program in their "Open With" sets, even if they're another type as well (maybe "Makefile", associated with make). 2) The sort of user who would consider the file extension to be out-of-band information is NOT going to be inventing new file extensions and crafting associations for them. So you're basically limited to those categories that have been set up by someone else. > The only thing I can see from your description, apparently it was possible > to change the default for an individual file ("Open this file always with > Wordpad instead of Notepad") without changing th eglobal default. Is this > the missing feature? 3) This. It's impossible to have one file in a category have a different default; you have to change the whole category's configuration. 4) A file's "category" also controls other things than its program association(s), such as its icon. So if you want to invent a new file category, you have to replicate all those other settings. 5) And the big one: you have to accept that the file name is no longer in your control. So this fundamentally won't work with any file that is looked for by another program, other than in the specific way of "this is the file you clicked on". So you can't choose the editor for an ancillary config file, you can't subcategorize your Python scripts and still import them successfully, and you basically can't categorize dotfiles (because ".bashrc" is of the type "bashrc", whereas ".zshrc" is of the completely different type "zshrc"). So it's an imperfect solution even as far as it goes, and a highly limiting way to do things. I'm sure it made good sense back when MS-DOS file systems ruled the Windows world, and 8.3 was just the way of things. ChrisA From giuseppecostanzi at gmail.com Thu Dec 14 04:35:02 2017 From: giuseppecostanzi at gmail.com (Beppe) Date: Thu, 14 Dec 2017 01:35:02 -0800 (PST) Subject: [TKinter]How to set LabelFrames font and color from option file Message-ID: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> Hi to everybody, I don't succeed in planning the value of the font and color in the LabelFrames using the option_db file, such as *LabelFrame*font: Helvetica 14 *LabelFrame*foreground: red exist a list of the keywordses to use? thanks beppe From ayaskant.mantu111 at gmail.com Thu Dec 14 05:08:06 2017 From: ayaskant.mantu111 at gmail.com (ayaskant.mantu111 at gmail.com) Date: Thu, 14 Dec 2017 02:08:06 -0800 (PST) Subject: write your replace function in python Message-ID: Hi, I want to replace the spaces in a sting with hyphen with my own replace function or with using the pre-defined replace function. Can anybody help me with this issue??? Thanks From rosuav at gmail.com Thu Dec 14 05:16:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Dec 2017 21:16:18 +1100 Subject: write your replace function in python In-Reply-To: References: Message-ID: On Thu, Dec 14, 2017 at 9:08 PM, wrote: > Hi, > > I want to replace the spaces in a sting with hyphen with my own replace function or with using the pre-defined replace function. > Can anybody help me with this issue??? > Ahh, the old "I want to" as a prefix for a homework assignment. Start by having a good-faith attempt to solve the problem on your own - spend maybe 30 to 60 minutes on it. At the end of that time, you might not have fully-working code, but you should at least have some code to talk about. Figure out what's working and what's not working, and *then* ask for help. ChrisA From lorenzofsutton at gmail.com Thu Dec 14 05:22:52 2017 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Thu, 14 Dec 2017 11:22:52 +0100 Subject: Answers to homework questions [WAS]: Re: Python homework In-Reply-To: <1513204317l.42074304l.0l@psu.edu> References: <1513204317l.42074304l.0l@psu.edu> Message-ID: Hi Roger, On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: > On Wed, Dec 13, 2017, Lorenzo Sutton wrote: >> > On 05/12/17 06:33, nick martinez2 via Python-list wrote: >>> I have a question on my homework. [...] >> For this kind of problem I think the collections module [1] can be very >> useful. In this case in particular have a look at the Counter package ;) [...] > > A nice answer at face value, and for general questions, but > perhaps not the best given the subject line and the first sentence > in the OP's note. > [...] > When I teach my course, I have no desire to have > all my students turn into cargo cultists. > > At least this particular student did post his intended solution, > instead of outright begging for code. And most of the responses > I see did attempt to work within the perceived constraints > regarding what language tools the student was expected to use. I see your point as a teacher, but after all this *is* a Python mailing list and not a python-homework-support mailing list. Plus, the OP had already received various good answers specifically helping them solve the problem along the lines of his proposed code, so I guessed hinting to a standard library module which is interesting and potentially relevant in this case might be useful to both the OP and other people on the ML while enriching the discussion ;-) Best, Lorenzo. From rhodri at kynesim.co.uk Thu Dec 14 06:53:48 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 14 Dec 2017 11:53:48 +0000 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> Message-ID: <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> On 14/12/17 07:25, Chris Angelico wrote: > So it's an imperfect solution even as far as it goes, and a highly > limiting way to do things. I'm sure it made good sense back when > MS-DOS file systems ruled the Windows world, and 8.3 was just the way > of things. Even then there was RiscOS, which divorced file names from file types entirely. A file's type was part of its directory data, and that was what determined what happened when you double-clicked on it. You were still limited to only one default application (and icon, and so on) per file type, so OS/2 still wins on that front, but I always felt that having names determine types was somehow mucky. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Thu Dec 14 06:55:50 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 14 Dec 2017 11:55:50 +0000 Subject: Answers to homework questions [WAS]: Re: Python homework In-Reply-To: References: <1513204317l.42074304l.0l@psu.edu> Message-ID: <22b857de-acf3-3e3c-0431-2b481f92bff0@kynesim.co.uk> On 14/12/17 10:22, Lorenzo Sutton wrote: > Hi Roger, > > On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: >> On Wed, Dec 13, 2017, Lorenzo Sutton wrote: >>> >> On 05/12/17 06:33, nick martinez2 via Python-list wrote: >>>> I have a question on my homework. > [...] >>> For this kind of problem I think the collections module [1] can be very >>> useful. In this case in particular have a look at the Counter package ;) > [...] >> >> A nice answer at face value, and for general questions, but >> perhaps not the best given the subject line and the first sentence >> in the OP's note. > > > [...] >> When I teach my course, I have no desire to have >> all my students turn into cargo cultists. >> >> At least this particular student did post his intended solution, >> instead of outright begging for code.? And most of the responses >> I see did attempt to work within the perceived constraints >> regarding what language tools the student was expected to use. > > I see your point as a teacher, but after all this *is* a Python mailing > list and not a python-homework-support mailing list. That implies you shouldn't have answered a homework assignment at all :-p -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Thu Dec 14 07:44:04 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Dec 2017 23:44:04 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> Message-ID: On Thu, Dec 14, 2017 at 10:53 PM, Rhodri James wrote: > On 14/12/17 07:25, Chris Angelico wrote: >> >> So it's an imperfect solution even as far as it goes, and a highly >> limiting way to do things. I'm sure it made good sense back when >> MS-DOS file systems ruled the Windows world, and 8.3 was just the way >> of things. > > > Even then there was RiscOS, which divorced file names from file types > entirely. A file's type was part of its directory data, and that was what > determined what happened when you double-clicked on it. You were still > limited to only one default application (and icon, and so on) per file type, > so OS/2 still wins on that front, but I always felt that having names > determine types was somehow mucky. > Having names as the *sole* way to determine types? I agree. But as one of a suite of methods? It makes a decent default. There are plenty of files out there whose names correctly match (a) their contents and (b) what you want to do with them, so forcing people to ALSO choose a type in some other way is redundant. But if a file can have an explicit type or "no type specified", and in the latter case it uses a filename-based mapping, that would be a slab of the functionality right there. ChrisA From rustompmody at gmail.com Thu Dec 14 08:32:22 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 14 Dec 2017 05:32:22 -0800 (PST) Subject: Answers to homework questions [WAS]: Re: Python homework In-Reply-To: References: <1513204317l.42074304l.0l@psu.edu> Message-ID: <4bc69875-6c67-4b3d-8788-0381fa8efdf2@googlegroups.com> On Thursday, December 14, 2017 at 3:53:21 PM UTC+5:30, Lorenzo Sutton wrote: > Hi Roger, > > On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: > > On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > >> > > On 05/12/17 06:33, nick martinez2 via Python-list wrote: > >>> I have a question on my homework. > [...] > >> For this kind of problem I think the collections module [1] can be very > >> useful. In this case in particular have a look at the Counter package ;) > [...] > > > > A nice answer at face value, and for general questions, but > > perhaps not the best given the subject line and the first sentence > > in the OP's note. > > > [...] > > When I teach my course, I have no desire to have > > all my students turn into cargo cultists. > > > > At least this particular student did post his intended solution, > > instead of outright begging for code. And most of the responses > > I see did attempt to work within the perceived constraints > > regarding what language tools the student was expected to use. > > I see your point as a teacher, but after all this *is* a Python mailing > list and not a python-homework-support mailing list. > > Plus, the OP had already received various good answers specifically > helping them solve the problem along the lines of his proposed code, so > I guessed hinting to a standard library module which is interesting and > potentially relevant in this case might be useful to both the OP and > other people on the ML while enriching the discussion ;-) Somebody has already pointed out that some setting in Roger Christman's mail client(?) breaks discussion threads. Now either Lorenzo is also breaking threads? Or else something in Roger's post makes the next person (in this case Lorenzo) break the thread?? From rustompmody at gmail.com Thu Dec 14 08:40:55 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 14 Dec 2017 05:40:55 -0800 (PST) Subject: Answers to homework questions [WAS]: Re: Python homework In-Reply-To: <4bc69875-6c67-4b3d-8788-0381fa8efdf2@googlegroups.com> References: <1513204317l.42074304l.0l@psu.edu> <4bc69875-6c67-4b3d-8788-0381fa8efdf2@googlegroups.com> Message-ID: On Thursday, December 14, 2017 at 7:02:56 PM UTC+5:30, Rustom Mody wrote: > On Thursday, December 14, 2017 at 3:53:21 PM UTC+5:30, Lorenzo Sutton wrote: > > Hi Roger, > > > > On 13/12/17 23:31, ROGER GRAYDON CHRISTMAN wrote: > > > On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > > >> > > > On 05/12/17 06:33, nick martinez2 via Python-list wrote: > > >>> I have a question on my homework. > > [...] > > >> For this kind of problem I think the collections module [1] can be very > > >> useful. In this case in particular have a look at the Counter package ;) > > [...] > > > > > > A nice answer at face value, and for general questions, but > > > perhaps not the best given the subject line and the first sentence > > > in the OP's note. > > > > > [...] > > > When I teach my course, I have no desire to have > > > all my students turn into cargo cultists. > > > > > > At least this particular student did post his intended solution, > > > instead of outright begging for code. And most of the responses > > > I see did attempt to work within the perceived constraints > > > regarding what language tools the student was expected to use. > > > > I see your point as a teacher, but after all this *is* a Python mailing > > list and not a python-homework-support mailing list. > > > > Plus, the OP had already received various good answers specifically > > helping them solve the problem along the lines of his proposed code, so > > I guessed hinting to a standard library module which is interesting and > > potentially relevant in this case might be useful to both the OP and > > other people on the ML while enriching the discussion ;-) > > Somebody has already pointed out that some setting in Roger Christman's > mail client(?) breaks discussion threads. > Now either Lorenzo is also breaking threads? > Or else something in Roger's post makes the next person (in this case Lorenzo) > break the thread?? Didn't notice that Lorenzo had renamed the subject line Sorry for noise From gheskett at shentel.net Thu Dec 14 09:14:14 2017 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 14 Dec 2017 09:14:14 -0500 Subject: [TKinter]How to set LabelFrames font and color from option file In-Reply-To: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> Message-ID: <201712140914.14147.gheskett@shentel.net> On Thursday 14 December 2017 04:35:02 Beppe wrote: > Hi to everybody, > > I don't succeed in planning the value of the font and color in the > LabelFrames using the option_db file, such as > > *LabelFrame*font: Helvetica 14 > *LabelFrame*foreground: red > > exist a list of the keywordses to use? > > thanks > > beppe In pyvcp, the xml file can have: ("Helvetica",16) ... It has a default, which I haven't changed, but the above ("Helvetica",12) s/b how you do it. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From __peter__ at web.de Thu Dec 14 09:17:56 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Dec 2017 15:17:56 +0100 Subject: [TKinter]How to set LabelFrames font and color from option file References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> Message-ID: Beppe wrote: > I don't succeed in planning the value of the font and color in the > LabelFrames using the option_db file, such as > > *LabelFrame*font: Helvetica 14 > *LabelFrame*foreground: red > > exist a list of the keywordses to use? >>> import tkinter as tk >>> root = tk.Tk() >>> lf = tk.LabelFrame(root) >>> lf["class"] 'Labelframe' Do you spot the difference? The class of the LabelFrame widget is Labelframe with a lowercase f. Once you change your database entries to *Labelframe*font: Helvetica 14 *Labelframe*foreground: red everything should work as expected. From giuseppecostanzi at gmail.com Thu Dec 14 10:00:07 2017 From: giuseppecostanzi at gmail.com (Beppe) Date: Thu, 14 Dec 2017 07:00:07 -0800 (PST) Subject: [TKinter]How to set LabelFrames font and color from option file In-Reply-To: References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> Message-ID: <7b7bbc7d-85bf-4c94-baed-6a64c59f90bf@googlegroups.com> Il giorno gioved? 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > Beppe wrote: > > > I don't succeed in planning the value of the font and color in the > > LabelFrames using the option_db file, such as > > > > *LabelFrame*font: Helvetica 14 > > *LabelFrame*foreground: red > > > > exist a list of the keywordses to use? > > >>> import tkinter as tk > >>> root = tk.Tk() > >>> lf = tk.LabelFrame(root) > >>> lf["class"] > 'Labelframe' > > Do you spot the difference? The class of the LabelFrame widget is Labelframe > with a lowercase f. Once you change your database entries to > > *Labelframe*font: Helvetica 14 > *Labelframe*foreground: red > > everything should work as expected. perfect, it works too much well, even my buttons now are helvetica 14 and red ;( From __peter__ at web.de Thu Dec 14 10:35:39 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Dec 2017 16:35:39 +0100 Subject: [TKinter]How to set LabelFrames font and color from option file References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> <7b7bbc7d-85bf-4c94-baed-6a64c59f90bf@googlegroups.com> Message-ID: Beppe wrote: > Il giorno gioved? 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: >> Beppe wrote: >> >> > I don't succeed in planning the value of the font and color in the >> > LabelFrames using the option_db file, such as >> > >> > *LabelFrame*font: Helvetica 14 >> > *LabelFrame*foreground: red >> > >> > exist a list of the keywordses to use? >> >> >>> import tkinter as tk >> >>> root = tk.Tk() >> >>> lf = tk.LabelFrame(root) >> >>> lf["class"] >> 'Labelframe' >> >> Do you spot the difference? The class of the LabelFrame widget is >> Labelframe with a lowercase f. Once you change your database entries to >> >> *Labelframe*font: Helvetica 14 >> *Labelframe*foreground: red >> >> everything should work as expected. > > perfect, it works too much well, even my buttons now are helvetica 14 and > red ;( I does what you tell it to do. Remove the second wildcard if you only want to change the Labelframe style: *Labelframe.font: Helvetica 14 *Labelframe.foreground: red From rosuav at gmail.com Thu Dec 14 11:23:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Dec 2017 03:23:24 +1100 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> Message-ID: On Fri, Dec 15, 2017 at 3:06 AM, Dennis Lee Bieber wrote: > C:\Users\Wulfraed>assoc .docx > .docx=Word.Document.12 > > C:\Users\Wulfraed>ftype word.document.12 > word.document.12="C:\Program Files\Microsoft > Office\Root\Office16\WINWORD.EXE" /n "%1" /o "%u" I'm almost afraid to ask... why "word.document.12" and why "Office16"? If only one of those, I would guess that it's a version number ("Office16" ==> MS Office 2016?), but there are two of them and they disagree... ChrisA From giuseppecostanzi at gmail.com Thu Dec 14 11:29:03 2017 From: giuseppecostanzi at gmail.com (Beppe) Date: Thu, 14 Dec 2017 08:29:03 -0800 (PST) Subject: [TKinter]How to set LabelFrames font and color from option file In-Reply-To: References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> <7b7bbc7d-85bf-4c94-baed-6a64c59f90bf@googlegroups.com> Message-ID: <65461dc3-5aa1-423d-be54-5346cb70deb4@googlegroups.com> Il giorno gioved? 14 dicembre 2017 16:36:24 UTC+1, Peter Otten ha scritto: > Beppe wrote: > > > Il giorno gioved? 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > >> Beppe wrote: > >> > >> > I don't succeed in planning the value of the font and color in the > >> > LabelFrames using the option_db file, such as > >> > > >> > *LabelFrame*font: Helvetica 14 > >> > *LabelFrame*foreground: red > >> > > >> > exist a list of the keywordses to use? > >> > >> >>> import tkinter as tk > >> >>> root = tk.Tk() > >> >>> lf = tk.LabelFrame(root) > >> >>> lf["class"] > >> 'Labelframe' > >> > >> Do you spot the difference? The class of the LabelFrame widget is > >> Labelframe with a lowercase f. Once you change your database entries to > >> > >> *Labelframe*font: Helvetica 14 > >> *Labelframe*foreground: red > >> > >> everything should work as expected. > > > > perfect, it works too much well, even my buttons now are helvetica 14 and > > red ;( > > I does what you tell it to do. Remove the second wildcard if you only want > to change the Labelframe style: > > *Labelframe.font: Helvetica 14 > *Labelframe.foreground: red Does that mean buttons inerith text from labelframe?!?! it looks so. From giuseppecostanzi at gmail.com Thu Dec 14 11:47:51 2017 From: giuseppecostanzi at gmail.com (Beppe) Date: Thu, 14 Dec 2017 08:47:51 -0800 (PST) Subject: [TKinter]How to set LabelFrames font and color from option file In-Reply-To: <65461dc3-5aa1-423d-be54-5346cb70deb4@googlegroups.com> References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> <7b7bbc7d-85bf-4c94-baed-6a64c59f90bf@googlegroups.com> <65461dc3-5aa1-423d-be54-5346cb70deb4@googlegroups.com> Message-ID: Il giorno gioved? 14 dicembre 2017 17:29:36 UTC+1, Beppe ha scritto: > Il giorno gioved? 14 dicembre 2017 16:36:24 UTC+1, Peter Otten ha scritto: > > Beppe wrote: > > > > > Il giorno gioved? 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > > >> Beppe wrote: > > >> > > >> > I don't succeed in planning the value of the font and color in the > > >> > LabelFrames using the option_db file, such as > > >> > > > >> > *LabelFrame*font: Helvetica 14 > > >> > *LabelFrame*foreground: red > > >> > > > >> > exist a list of the keywordses to use? > > >> > > >> >>> import tkinter as tk > > >> >>> root = tk.Tk() > > >> >>> lf = tk.LabelFrame(root) > > >> >>> lf["class"] > > >> 'Labelframe' > > >> > > >> Do you spot the difference? The class of the LabelFrame widget is > > >> Labelframe with a lowercase f. Once you change your database entries to > > >> > > >> *Labelframe*font: Helvetica 14 > > >> *Labelframe*foreground: red > > >> > > >> everything should work as expected. > > > > > > perfect, it works too much well, even my buttons now are helvetica 14 and > > > red ;( > > > > I does what you tell it to do. Remove the second wildcard if you only want > > to change the Labelframe style: > > > > *Labelframe.font: Helvetica 14 > > *Labelframe.foreground: red > > Does that mean buttons inerith text from labelframe?!?! it looks so. ok, so it seems working *Labelframe*font: Helvetica 14 *Labelframe*foreground: red *Button*foreground: black *Button*font: Verdana 10 From edmondo.giovannozzi at gmail.com Thu Dec 14 12:07:44 2017 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Thu, 14 Dec 2017 09:07:44 -0800 (PST) Subject: Python homework In-Reply-To: <628e5528-57e3-4237-8a1d-8d7aaa3fa28b@googlegroups.com> References: <144ea1de-9752-4976-939f-5179f5541eae@googlegroups.com> <628e5528-57e3-4237-8a1d-8d7aaa3fa28b@googlegroups.com> Message-ID: Il giorno marted? 12 dicembre 2017 00:30:24 UTC+1, jlad... at itu.edu ha scritto: > On Thursday, December 7, 2017 at 4:49:52 AM UTC-8, edmondo.g... at gmail.com wrote: > > > import numpy > > I teach Python to students at varying levels. As much as I love and use Numpy in my regular work, I try to avoid showing beginning Python students solutions that require third-party packages. Here are my reasons: > > 1. Not every programming novice needs to understand things at the bits-and-bytes level, but they should learn the inner workings of algorithms. You won't always have a ready-made algorithm to solve your problem in a library function call, so you should learn to write your own. > > 2. Package maintenance can be its own headache. Sure, Anaconda can help, but it's a heavyweight distribution. And not every student is working on a computer where they have the rights to install software. I understand you points, on the other end, as we are not his teachers, we can also suggest other ways to solve its problem. Look that I haven't posted a complete solution, I just stopped at the same point he had already reached, and then I had given him just hints. I think there is also another lessons that a student should learn: not to reinvent the wheel. But it may just be my feeling about this issue. I think also that introducing third-party package or not depends on the student environment. If he is studying to become an engineer he may have already been exposed to other proprietary software (the famous one). It could be useful to show him that most of the same things can be done in python with just an almost standard third-party package. Cheers, Edmondo From wanderer at dialup4less.com Thu Dec 14 12:35:02 2017 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 14 Dec 2017 09:35:02 -0800 (PST) Subject: subprocess call question Message-ID: <591dffef-d757-461f-a444-764d6172b90d@googlegroups.com> This dos batch files works on windows 7 "C:\Program Files (x86)\DOOM 3\qoom3.exe" +set fs_game_base darkmod +set fs_game training_mission but this python subprocess.call doesn't subprocess.call(['C:/Program Files (x86)/DOOM 3/qoom3.exe', '+set fs_game_base darkmod', '+set fs_game training_mission']) qoom3.exe starts but it gives the warnings "unknown commands set fs_game_base darkmod and set fs_game training_mission" Why? From python at mrabarnett.plus.com Thu Dec 14 13:00:19 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Dec 2017 18:00:19 +0000 Subject: subprocess call question In-Reply-To: <591dffef-d757-461f-a444-764d6172b90d@googlegroups.com> References: <591dffef-d757-461f-a444-764d6172b90d@googlegroups.com> Message-ID: On 2017-12-14 17:35, Wanderer wrote: > This dos batch files works on windows 7 > > "C:\Program Files (x86)\DOOM 3\qoom3.exe" +set fs_game_base darkmod +set fs_game training_mission > > but this python subprocess.call doesn't > > subprocess.call(['C:/Program Files (x86)/DOOM 3/qoom3.exe', '+set fs_game_base darkmod', '+set fs_game training_mission']) > > qoom3.exe starts but it gives the warnings "unknown commands set fs_game_base darkmod and set fs_game training_mission" > > Why? > Each of the strings in the list will be quoted, so the command line you're actually giving it is: "C:/Program Files (x86)/DOOM 3/qoom3.exe" "+set fs_game_base darkmod" "+set fs_game training_mission" hence it's complaining that there's no command "+set fs_game_base darkmod". The call should be: subprocess.call(['C:/Program Files (x86)/DOOM 3/qoom3.exe', '+set', 'fs_game_base', 'darkmod', '+set', 'fs_game', 'training_mission']) From wanderer at dialup4less.com Thu Dec 14 13:11:37 2017 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 14 Dec 2017 10:11:37 -0800 (PST) Subject: subprocess call question In-Reply-To: References: <591dffef-d757-461f-a444-764d6172b90d@googlegroups.com> Message-ID: That works. Thanks From gheskett at shentel.net Thu Dec 14 13:28:16 2017 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 14 Dec 2017 13:28:16 -0500 Subject: [TKinter]How to set LabelFrames font and color from option file In-Reply-To: <7b7bbc7d-85bf-4c94-baed-6a64c59f90bf@googlegroups.com> References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> <7b7bbc7d-85bf-4c94-baed-6a64c59f90bf@googlegroups.com> Message-ID: <201712141328.16351.gheskett@shentel.net> On Thursday 14 December 2017 10:00:07 Beppe wrote: > Il giorno gioved? 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > > Beppe wrote: > > > I don't succeed in planning the value of the font and color in the > > > LabelFrames using the option_db file, such as > > > > > > *LabelFrame*font: Helvetica 14 > > > *LabelFrame*foreground: red > > > > > > exist a list of the keywordses to use? > > > > > >>> import tkinter as tk > > >>> root = tk.Tk() > > >>> lf = tk.LabelFrame(root) > > >>> lf["class"] > > > > 'Labelframe' > > > > Do you spot the difference? The class of the LabelFrame widget is > > Labelframe with a lowercase f. Once you change your database entries > > to > > > > *Labelframe*font: Helvetica 14 > > *Labelframe*foreground: red > > > > everything should work as expected. > > perfect, it works too much well, even my buttons now are helvetica 14 > and red ;( In that event, you can label the text buttons like this: For a different font. I'd assume ('green') might work, but haven't tried it since it cannot be changed with the halpin state. Then it would be useful to report status w/o having the put an led underline under it for state. That would save a considerable acreage in screen real estate if it were possible on an already busy linuxcnc gui. IMO the enforced blank space around text is also a huge waster of screen real estate. You can find some tut's on doing all this in the linuxcnc Documentation.pdf, downloadable from linuxcnc.org, in my version starting on page 366. Under "pyvcp" If you know of others, plz advise. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From gheskett at shentel.net Thu Dec 14 13:30:35 2017 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 14 Dec 2017 13:30:35 -0500 Subject: [TKinter]How to set LabelFrames font and color from option file In-Reply-To: <65461dc3-5aa1-423d-be54-5346cb70deb4@googlegroups.com> References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> <65461dc3-5aa1-423d-be54-5346cb70deb4@googlegroups.com> Message-ID: <201712141330.35379.gheskett@shentel.net> On Thursday 14 December 2017 11:29:03 Beppe wrote: > Il giorno gioved? 14 dicembre 2017 16:36:24 UTC+1, Peter Otten ha scritto: > > Beppe wrote: > > > Il giorno gioved? 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: > > >> Beppe wrote: > > >> > I don't succeed in planning the value of the font and color in > > >> > the LabelFrames using the option_db file, such as > > >> > > > >> > *LabelFrame*font: Helvetica 14 > > >> > *LabelFrame*foreground: red > > >> > > > >> > exist a list of the keywordses to use? > > >> > > > >> >>> import tkinter as tk > > >> >>> root = tk.Tk() > > >> >>> lf = tk.LabelFrame(root) > > >> >>> lf["class"] > > >> > > >> 'Labelframe' > > >> > > >> Do you spot the difference? The class of the LabelFrame widget is > > >> Labelframe with a lowercase f. Once you change your database > > >> entries to > > >> > > >> *Labelframe*font: Helvetica 14 > > >> *Labelframe*foreground: red > > >> > > >> everything should work as expected. > > > > > > perfect, it works too much well, even my buttons now are helvetica > > > 14 and red ;( > > > > I does what you tell it to do. Remove the second wildcard if you > > only want to change the Labelframe style: > > > > *Labelframe.font: Helvetica 14 > > *Labelframe.foreground: red > > Does that mean buttons inerith text from labelframe?!?! it looks so. They do if you do not specify differently within the Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From giuseppecostanzi at gmail.com Thu Dec 14 13:58:27 2017 From: giuseppecostanzi at gmail.com (Beppe) Date: Thu, 14 Dec 2017 10:58:27 -0800 (PST) Subject: [TKinter]How to set LabelFrames font and color from option file In-Reply-To: References: <7dd74db6-05ed-466d-92df-1f336c8be1ae@googlegroups.com> <7b7bbc7d-85bf-4c94-baed-6a64c59f90bf@googlegroups.com> <201712141328.16351.gheskett@shentel.net> Message-ID: Il giorno gioved? 14 dicembre 2017 19:28:53 UTC+1, Gene Heskett ha scritto: > On Thursday 14 December 2017 10:00:07 Beppe wrote: > > > Il giorno gioved? 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha > scritto: > > > Beppe wrote: > > > > I don't succeed in planning the value of the font and color in the > > > > LabelFrames using the option_db file, such as > > > > > > > > *LabelFrame*font: Helvetica 14 > > > > *LabelFrame*foreground: red > > > > > > > > exist a list of the keywordses to use? > > > > > > > >>> import tkinter as tk > > > >>> root = tk.Tk() > > > >>> lf = tk.LabelFrame(root) > > > >>> lf["class"] > > > > > > 'Labelframe' > > > > > > Do you spot the difference? The class of the LabelFrame widget is > > > Labelframe with a lowercase f. Once you change your database entries > > > to > > > > > > *Labelframe*font: Helvetica 14 > > > *Labelframe*foreground: red > > > > > > everything should work as expected. > > > > perfect, it works too much well, even my buttons now are helvetica 14 > > and red ;( > In that event, you can label the text buttons like this: > > For a different font. > > I'd assume ('green') might work, but haven't tried it since it > cannot be changed with the halpin state. Then it would be useful to > report status w/o having the put an led underline under it for state. > That would save a considerable acreage in screen real estate if it were > possible on an already busy linuxcnc gui. IMO the enforced blank space > around text is also a huge waster of screen real estate. > > You can find some tut's on doing all this in the linuxcnc > Documentation.pdf, downloadable from linuxcnc.org, in my version > starting on page 366. Under "pyvcp" If you know of others, plz advise. > > Cheers, Gene Heskett > -- > "There are four boxes to be used in defense of liberty: > soap, ballot, jury, and ammo. Please use in that order." > -Ed Howdershelt (Author) > Genes Web page linuxcnc.org ?!?! wow...very cool... From brianherman at gmail.com Thu Dec 14 14:44:44 2017 From: brianherman at gmail.com (Brian Herman) Date: Thu, 14 Dec 2017 13:44:44 -0600 Subject: Accessing Self Inside Decorator with parameters Message-ID: I would like to access the instance variable of a class using a decorator with arguments: I used to do with with a decorator without arguments: def decorator(method): """ This method is a decorator to get a security token each time you have a service call. """ def wrapper(self, *args, **kw): self.call_this() result = method(self, *args, **kw) return result return wrapper class test1: def call_this(self): print("this works") @decorator def preform_action(self): print("test") However when I add the arguments decorator I cannot access the self of the object that calls the decorator. def decorator_with_arguments(arg1, arg2): def decorator(self, method): """ This method is a decorator to get a security token each time you have a service call. """ def wrapper(self, *args, **kw): self.call_this() result = method(self, *args, **kw) return result return wrapper class test2: def call_this(self): print("this does not") @decorator_with_arguments(1,2) def preform_action(self): print("test") Is there any way to do this pythonically? -- Thanks, Brian Herman kompile.org From rosuav at gmail.com Thu Dec 14 16:03:38 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Dec 2017 08:03:38 +1100 Subject: Accessing Self Inside Decorator with parameters In-Reply-To: References: Message-ID: On Fri, Dec 15, 2017 at 6:44 AM, Brian Herman wrote: > However when I add the arguments decorator I cannot access the self of the > object that calls the decorator. > > def decorator_with_arguments(arg1, arg2): > def decorator(self, method): > """ This method is a decorator to get a security token each time > you have a service call. """ > def wrapper(self, *args, **kw): > self.call_this() > result = method(self, *args, **kw) > > return result > return wrapper Why does the decorator take a self parameter? The wrapper function does, but when your decorator() runs, it's just looking at a function and returning a function. Try removing self from that and see if it solves your problem. ChrisA From greg.ewing at canterbury.ac.nz Thu Dec 14 17:48:20 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 15 Dec 2017 11:48:20 +1300 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> Message-ID: Rhodri James wrote: > Even then there was RiscOS, which divorced file names from file types > entirely. As did classic MacOS. I believe MacOSX also has the ability to store a file type as metadata, but it doesn't seem to be used much. -- Greg From breamoreboy at gmail.com Thu Dec 14 19:46:11 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 14 Dec 2017 16:46:11 -0800 (PST) Subject: Let your code type-hint itself: introducing open source MonkeyType Message-ID: <20801178-1a88-46f4-887a-f7d1c8d02294@googlegroups.com> Seeing that type hinting is one of the big new features of Python I thought folks might find this https://engineering.instagram.com/let-your-code-type-hint-itself-introducing-open-source-monkeytype-a855c7284881 of interest. Kindest regards. Mark Lawrence. From tmrsg11 at gmail.com Thu Dec 14 21:37:48 2017 From: tmrsg11 at gmail.com (C W) Date: Thu, 14 Dec 2017 21:37:48 -0500 Subject: Why does Jupyter Notebook searches files in folders, but PyCharm and Sublime Text does not? Message-ID: Hi all, I am confused why Jupyter Notebook searches files in subfolder, but PyCharm and Sublime Text 3 does not. Is there a rule? For example, I have a module or file called lr_utils.py in the current folder. If I run the following line in Jupyter, it's fine. > import lr_utils But in PyCharm, I get the error, ModuleNotFoundError: No module named 'lr_utils' If I run it in Sublime Text, it's find too > import os > os.chdir("Users/My_name/Desktop/Python_Codes") > import lr_utils Why the code works in one but not the other? Thank you! From steve+python at pearwood.info Thu Dec 14 23:11:11 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 15 Dec 2017 15:11:11 +1100 Subject: write your replace function in python References: Message-ID: <5a334b60$0$2048$b1db1813$d948b532@news.astraweb.com> On Thu, 14 Dec 2017 09:08 pm, ayaskant.mantu111 at gmail.com wrote: > Hi, > > I want to replace the spaces in a sting with hyphen with my own replace > function or with using the pre-defined replace function. Can anybody help me > with this issue??? new_string = "string with spaces".replace(" ", "hyphen") When in doubt, open the Python interpreter to a command prompt ">>> " and enter: help("") to see the string methods. Other commands work too: help(str.replace) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From supswain at gmail.com Fri Dec 15 04:58:21 2017 From: supswain at gmail.com (supswain at gmail.com) Date: Fri, 15 Dec 2017 01:58:21 -0800 (PST) Subject: unabe to import /pyd file. Message-ID: <231c952f-3fdd-4519-bcf1-b7bb0ab0d968@googlegroups.com> Hi, I have created one library file "modified_python_automation_tcl.py"..Inside my library file I have set of codes as follows. import sys import time from datetime import datetime import re,sys,os,itertools,datetime,commands,logging,math,time,copy,inspect from robot.api import logger import unicodedata sys.path.append('C:\Python27\Lib\lib-tk') sys.path.append('C:\Python27\DLLs') sys.path.append('C:\Python27\libs') from Tkinter import Tcl tcl = Tcl() . . . . . . I am able to run the file from python IDLE.and able to source all kind of .py and .pyd file...But the issue is coming when trying through robo framework. I am using robo-framework and have defined the modified_python_automation_tcl.py file as the library file. and tryuing to excute my testcase..but getting the below error.. Someone please help me how to import .pyd files from robo framework ============================================================================== Acceptance.Tests ============================================================================== Acceptance.Tests.PCC ============================================================================== Acceptance.Tests.PCC.Automation 2.0 ============================================================================== [ ERROR ] Error in file 'C:\PCCAutomation\src\test\robotframework\acceptance\Tests\PCC\Automation_2.0\Spirent.txt': Importing test library 'C:\Users\supriysw\Desktop\abcd\modified_python_automation_tcl.py' failed: ImportError: No module named _tkinter Traceback (most recent call last): File "C:\Users\supriysw\Desktop\abcd\modified_python_automation_tcl.py", line 15, in from Tkinter import Tcl File "C:\Python27\Lib\lib-tk\Tkinter.py", line 41, in import _tkinter # If this fails your Python may not be configured for Tk PYTHONPATH: C:\PCCAutomation\target\libs\xlrd-0.7.1 C:\PCCAutomation\target\libs\xlrd-0.7.1\xlrd C:\PCCAutomation\target\libs\xlutils-1.5.2 C:\PCCAutomation\target\libs\xlutils-1.5.2\xlutils C:\PCCAutomation\target\libs\xlwt-0.7.4 C:\PCCAutomation\target\libs\xlwt-0.7.4\xlwt C:\PCCAutomation\target\libs\main\com\nokia\epg\automation\ams\lib C:\Users\supriysw\.m2\repository\org\robotframework\robotframework\2.8.7\robotframework-2.8.7.jar\Lib\robot\libraries C:\Users\supriysw\.m2\repository\org\robotframework\robotframework\2.8.7\robotframework-2.8.7.jar\Lib C:\Users\supriysw\.m2\repository\org\robotframework\robotframework\2.8.7\Lib __classpath__ __pyclasspath__/ . C:\PCCAutomation C:\Python27\Lib\lib-tk C:\Python27\DLLs C:\Python27\libs CLASSPATH: C:/apache-maven-3.3.9/boot/plexus-classworlds-2.5.2.jar Acceptance.Tests.PCC.Automation 2.0.Spirent From mail at timgolden.me.uk Fri Dec 15 05:09:50 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 15 Dec 2017 10:09:50 +0000 Subject: unabe to import /pyd file. In-Reply-To: <231c952f-3fdd-4519-bcf1-b7bb0ab0d968@googlegroups.com> References: <231c952f-3fdd-4519-bcf1-b7bb0ab0d968@googlegroups.com> Message-ID: <424f35a1-5b74-6a84-a9ad-05b8073ce2cb@timgolden.me.uk> On 15/12/2017 09:58, supswain at gmail.com wrote: > Hi, > > I have created one library file > "modified_python_automation_tcl.py"..Inside my library file I have > set of codes as follows. > > import sys import time from datetime import datetime import > re,sys,os,itertools,datetime,commands,logging,math,time,copy,inspect > from robot.api import logger import unicodedata > sys.path.append('C:\Python27\Lib\lib-tk') > sys.path.append('C:\Python27\DLLs') > sys.path.append('C:\Python27\libs') from Tkinter import Tcl tcl = Apart from anything else these need to be raw strings: sys.path.append(r'C:\Python27\Lib\lib-tk') etc. TJG From steve+python at pearwood.info Fri Dec 15 05:23:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 15 Dec 2017 21:23:33 +1100 Subject: unabe to import /pyd file. References: <231c952f-3fdd-4519-bcf1-b7bb0ab0d968@googlegroups.com> <424f35a1-5b74-6a84-a9ad-05b8073ce2cb@timgolden.me.uk> Message-ID: <5a33a2a6$0$2716$b1db1813$eb6074ea@news.astraweb.com> On Fri, 15 Dec 2017 09:09 pm, Tim Golden wrote: > Apart from anything else these need to be raw strings: > > sys.path.append(r'C:\Python27\Lib\lib-tk') Don't use raw strings for paths. It's a trap: r'C:\Python27' # okay r'C:\Python27\' # fails Windows supports / as directory separator. You should use / as the directory separator in your source code, and let the OS convert them to backslashes. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Dec 15 05:34:40 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 15 Dec 2017 21:34:40 +1100 Subject: Please tell me how to execute python file in Ubuntu by double References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> Message-ID: <5a33a541$0$2087$b1db1813$d948b532@news.astraweb.com> On Fri, 15 Dec 2017 09:48 am, Gregory Ewing wrote: > Rhodri James wrote: >> Even then there was RiscOS, which divorced file names from file types >> entirely. > > As did classic MacOS. Classic MacOS associated two such pieces of metadata with each file: the creator and type. Regardless of the optional file type extension, you could associate different creators with different files of the same type: https://en.wikipedia.org/wiki/Creator_code > I believe MacOSX also has the ability to store a file type > as metadata, but it doesn't seem to be used much. They are still supported (-ish) by OS X, but have been superseded by Uniform Type Identifiers. https://en.wikipedia.org/wiki/Uniform_Type_Identifier -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From nomail at com.invalid Fri Dec 15 05:36:19 2017 From: nomail at com.invalid (ast) Date: Fri, 15 Dec 2017 11:36:19 +0100 Subject: Problem with timeit Message-ID: <5a33a5aa$0$10195$426a74cc@news.free.fr> Hi Time measurment with module timeit seems to work with some statements but not with some other statements on my computer. Python version 3.6.3 from timeit import Timer >>> Timer("'-'.join([str(i) for i in range(10)])").timeit(10000) 0.179271876732912 >>> Timer("'-'.join([str(i) for i in range(10)])").timeit(100000) 1.7445643231192776 It's OK, with 10 more loops I get 10 more execution time. But with exponentiation, it's a mess >>> Timer("x=123456**123456").timeit(1) 6.076191311876755e-06 >>> Timer("x=123456**123456").timeit(10) 3.841270313387213e-06 All wrong, the calculation of 123456**123456 is much longer than 6 microseconds, it takes few seconds, and with 10 loops timeit provided a shorter time ... What happens plz ? From glicerinu at gmail.com Fri Dec 15 05:51:56 2017 From: glicerinu at gmail.com (Marc Aymerich) Date: Fri, 15 Dec 2017 10:51:56 +0000 Subject: Sharing credentials between multiple interactive processes Message-ID: I would like to throw at you some problem that I don't know how to best approach :) Have an interactive CLI python program that holds credentials entered by the user. I want users to be able to spawn a new instance of this program (on another TTY) without the need of reentering credentials. Want to do it in a secure way, meaning make it very difficult for malicious programs to gain access to the credentials. Some solutions that I thought of: 1) From another TTY, communicate with the existing process and tell it to fork and attach to my TTY. Not sure yet how to do it, but I think is doable. 2) Make the program to be able to send credentials through a Unix Domain Socket to its peers. Not sure is there any way to prevent sending credentials to any random process pocking at the socket without a challenge. Maybe is there any way to validate that 2 running python processes are executing the exact same code (peers)? any thoughts? -- Marc From ceiussandicus at gmail.com Fri Dec 15 06:37:02 2017 From: ceiussandicus at gmail.com (ceiussandicus at gmail.com) Date: Fri, 15 Dec 2017 03:37:02 -0800 (PST) Subject: Can't start IDLE on mac os x high sierra can't import Tkinter Message-ID: <7e8d1fbc-cfa3-48fd-8ad9-0af2df6267fe@googlegroups.com> Hi, I've been trying to get python 3.4.3 (needed for programming course) on my mac, running High Sierra. I've installed python and activetcl 8.5.18 as per instructions. When I start IDLE from finder it flashes in the dock and disappears. When I start it from terminal, I get the following response: ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** I've googled for the answer but I can't find anything, the closest I got was to this https://github.com/pyinstaller/pyinstaller/issues/2665 but I'm not sure if it is this issue or not. Can someone help me get started using python? Cheers ceiussandicus From tjol at tjol.eu Fri Dec 15 06:47:04 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 15 Dec 2017 12:47:04 +0100 Subject: Problem with timeit In-Reply-To: <5a33a5aa$0$10195$426a74cc@news.free.fr> References: <5a33a5aa$0$10195$426a74cc@news.free.fr> Message-ID: <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> On 2017-12-15 11:36, ast wrote: > Hi > > Time measurment with module timeit seems to work with some statements > but not with some other statements on my computer. > > Python version 3.6.3 > > from timeit import Timer > >>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(10000) > 0.179271876732912 >>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(100000) > 1.7445643231192776 > > It's OK, with 10 more loops I get 10 more execution time. > > But with exponentiation, it's a mess > >>>> Timer("x=123456**123456").timeit(1) > 6.076191311876755e-06 >>>> Timer("x=123456**123456").timeit(10) > 3.841270313387213e-06 > > All wrong, the calculation of 123456**123456 is much longer > than 6 microseconds, it takes few seconds, and with 10 loops timeit > provided a shorter time ... No, this is right. The calculation takes practically no time; on my system, it takes some 10 ns. The uncertainty of the timeit result is at least a few hundred nanoseconds. Perhaps you entered 123456**123456 at a Python console (which takes a few seconds), which makes you think the exponentiation should take that long? In fact, it's printing the result to the console that takes time. You can convince yourself of this by running x=123456**123456 (which takes no time at all) and then typing "x" (which will take seconds) >>> Timer("x=123456**123456").timeit(10**6) 0.00969144597183913 >>> Timer("print(123456**123456, file=open('/dev/null', 'w'))").timeit(1) 4.949162941076793 -- Thomas > > What happens plz ? > From r.varunrockz at gmail.com Fri Dec 15 06:49:40 2017 From: r.varunrockz at gmail.com (Varun R) Date: Fri, 15 Dec 2017 03:49:40 -0800 (PST) Subject: Python Learning Message-ID: Hi All, I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. Thanks all From pcmanticore at gmail.com Fri Dec 15 06:59:17 2017 From: pcmanticore at gmail.com (Claudiu Popa) Date: Fri, 15 Dec 2017 12:59:17 +0100 Subject: Pylint 1.8 / Astroid 1.6 released! Message-ID: Hi folks! I'm happy to announce the release of Pylint 1.8, along with Astroid 1.6! This is going to be the last version that will work on Python 2. Starting with the next planned version, 2.0, we are going to support only Python 3.5+. 1.8 will most likely become a LTS release, with bug fixes backports until 2019-2020. You can find more details about what's new in this release over here: https://pylint.readthedocs.io/en/latest/whatsnew/1.8.html Thanks and enjoy! Claudiu & all the Pylint contributors From tjreedy at udel.edu Fri Dec 15 07:43:39 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Dec 2017 07:43:39 -0500 Subject: Can't start IDLE on mac os x high sierra can't import Tkinter In-Reply-To: <7e8d1fbc-cfa3-48fd-8ad9-0af2df6267fe@googlegroups.com> References: <7e8d1fbc-cfa3-48fd-8ad9-0af2df6267fe@googlegroups.com> Message-ID: On 12/15/2017 6:37 AM, ceiussandicus at gmail.com wrote: > Hi, I've been trying to get python 3.4.3 (needed for programming course) on my mac, running High Sierra. > I've installed python and activetcl 8.5.18 as per instructions. When I start IDLE from finder it flashes in the dock and disappears. When I start it from terminal, I get the following response: > ** IDLE can't import Tkinter. > Your Python may not be configured for Tk. ** > I've googled for the answer but I can't find anything, the closest I got was to this https://github.com/pyinstaller/pyinstaller/issues/2665 but I'm not sure if it is this issue or not. > Can someone help me get started using python? I don't have a Mac, but I know that https://www.python.org/download/mac/tcltk/ has some fairly exacting instructions at the bottom on how to get Python to find the newly installed tcl/tk. You should probably specify rather exactly what you did. There are multiple issues on bugs.python.org and questions on stackoverflow. -- Terry Jan Reedy From alister.ware at ntlworld.com Fri Dec 15 07:55:38 2017 From: alister.ware at ntlworld.com (alister) Date: Fri, 15 Dec 2017 12:55:38 GMT Subject: Please tell me how to execute python file in Ubuntu by double References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> Message-ID: On Fri, 15 Dec 2017 11:48:20 +1300, Gregory Ewing wrote: > Rhodri James wrote: >> Even then there was RiscOS, which divorced file names from file types >> entirely. > > As did classic MacOS. > > I believe MacOSX also has the ability to store a file type as metadata, > but it doesn't seem to be used much. Amiga os used a separate file as the ICON & this contained lots of meta data including which application to open the file with (usualy the application that created it) -- "I'd love to go out with you, but I have to stay home and see if I snore." From __peter__ at web.de Fri Dec 15 08:11:11 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 Dec 2017 14:11:11 +0100 Subject: Problem with timeit References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> Message-ID: Thomas Jollans wrote: > On 2017-12-15 11:36, ast wrote: >> Hi >> >> Time measurment with module timeit seems to work with some statements >> but not with some other statements on my computer. >> >> Python version 3.6.3 >> >> from timeit import Timer >> >>>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(10000) >> 0.179271876732912 >>>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(100000) >> 1.7445643231192776 >> >> It's OK, with 10 more loops I get 10 more execution time. >> >> But with exponentiation, it's a mess >> >>>>> Timer("x=123456**123456").timeit(1) >> 6.076191311876755e-06 >>>>> Timer("x=123456**123456").timeit(10) >> 3.841270313387213e-06 >> >> All wrong, the calculation of 123456**123456 is much longer >> than 6 microseconds, it takes few seconds, and with 10 loops timeit >> provided a shorter time ... > > No, this is right. The calculation takes practically no time; on my > system, it takes some 10 ns. The uncertainty of the timeit result is at > least a few hundred nanoseconds. > > Perhaps you entered 123456**123456 at a Python console (which takes a > few seconds), which makes you think the exponentiation should take that > long? In fact, it's printing the result to the console that takes time. > You can convince yourself of this by running > > x=123456**123456 > > (which takes no time at all) > > and then typing "x" (which will take seconds) > > > >>>> Timer("x=123456**123456").timeit(10**6) > 0.00969144597183913 >>>> Timer("print(123456**123456, file=open('/dev/null', 'w'))").timeit(1) > 4.949162941076793 > > > -- Thomas > > >> >> What happens plz ? What Thomas says. Also, the value 123456**123456 is computed only once, when the code is compiled (this is called "constant folding"). Therefore you measure name binding only: $ python3 -m timeit 'x = 123456**123456' 10000000 loops, best of 3: 0.0535 usec per loop $ python3 -m timeit 'x = 123456' 10000000 loops, best of 3: 0.0535 usec per loop Compare that with an actual calculation: $ python3 -m timeit -s 'a = 123456' 'x = a' 10000000 loops, best of 3: 0.0539 usec per loop $ python3 -m timeit -s 'a = 123456' 'x = a ** a' 10 loops, best of 3: 259 msec per loop From steve+python at pearwood.info Fri Dec 15 08:19:18 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 16 Dec 2017 00:19:18 +1100 Subject: Problem with timeit References: <5a33a5aa$0$10195$426a74cc@news.free.fr> Message-ID: <5a33cbd7$0$2057$b1db1813$d948b532@news.astraweb.com> On Fri, 15 Dec 2017 09:36 pm, ast wrote: [...] > It's OK, with 10 more loops I get 10 more execution time. > > But with exponentiation, it's a mess > >>>> Timer("x=123456**123456").timeit(1) > 6.076191311876755e-06 >>>> Timer("x=123456**123456").timeit(10) > 3.841270313387213e-06 > > All wrong, the calculation of 123456**123456 is much longer > than 6 microseconds, it takes few seconds, and with 10 loops > timeit provided a shorter time ... > > What happens plz ? You are not measuring what you think you are measuring. Import the dis command to disassemble your source code and see what you are measuring. Here is an example: py> from dis import dis py> dis("x=123**123") 1 0 LOAD_CONST 2 (1143743679346171900998802952280662767462180784518502297758879750523695 04785666896446606568365201542169649974727730628842345343196581134895919 94282087444983721209947664895835902379607854904194900780722062535652692 6729664064846685758382803707100766740220839267) 3 STORE_NAME 0 (x) 6 LOAD_CONST 1 (None) 9 RETURN_VALUE I simplified the expression to 123**123 instead of 123456**123456, in order to make the disassembly small enough to read. Otherwise there would be thousands of digits. The important thing is that Python's keyhole optimizer is optimizing the constant expression 123456**123456, calculating it at compile time, so you are timing the equivalent of: x = 5374822891...2343545856 # a 628578 digit number All the expensive work is done once, at compile time (and even that only takes a second or so). What timeit measures is just repeatedly assigning x to the pre-defined constant, over and over again. So in theory, the speed should be **really really fast**. In practice, you are measuring more-or-less just the overhead of assignment, and the overhead of timeit itself. That overhead is so small that it is dominated by the random noise of your computer, which is doing many other things at the same time, and it is just a fluke that sometimes calling timeit(10) will be shorter than calling timeit(1). On my computer, I get results like this: py> Timer("x=123456**123456").timeit(1) 7.5660645961761475e-06 py> Timer("x=123456**123456").timeit(1) 6.902962923049927e-06 py> Timer("x=123456**123456").timeit(1) 5.256384611129761e-06 The fact that the time taken keeps getting smaller might be a fluke, or it might have something to do with CPU prediction and caching results. Now look what happens when I increase the number of iterations: py> Timer("x=123456**123456").timeit(10) 7.111579179763794e-06 py> Timer("x=123456**123456").timeit(10) 5.822628736495972e-06 py> Timer("x=123456**123456").timeit(10) 5.457550287246704e-06 The time barely changes. My prediction is that this is because the time of the actual assignment is so small, the measured time is dominated by timeit itself. I can test this: py> Timer("pass").timeit(1) 4.108995199203491e-06 py> Timer("pass").timeit(10) 4.8354268074035645e-06 So that is approximately the fastest thing timeit can measure on my computer, and there is no significant difference between doing it once, and doing it ten times. The difference is lost in the noise. The right way to measure this is like this: py> Timer("x = n**n", "n = 123456").timeit(1) 0.9905387535691261 py> Timer("x = n**n", "n = 123456").timeit(10) 18.006236914545298 As you can see, repeating the calculation 10 times doesn't take exactly ten times as long as doing the calculation once. That could be because the garbage collector runs. The more expensive the calculation, the more overhead there is. Running Python on a modern machine with CPU branch prediction and caching isn't like running pure assembly on an old, single-process machine where every run is 100% deterministic. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Dec 15 08:23:52 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 16 Dec 2017 00:23:52 +1100 Subject: Problem with timeit References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> Message-ID: <5a33cce8$0$2057$b1db1813$d948b532@news.astraweb.com> On Fri, 15 Dec 2017 10:47 pm, Thomas Jollans wrote: > On 2017-12-15 11:36, ast wrote: >> Hi >> >> Time measurment with module timeit seems to work with some statements >> but not with some other statements on my computer. >> >> Python version 3.6.3 >> >> from timeit import Timer >> >>>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(10000) >> 0.179271876732912 >>>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(100000) >> 1.7445643231192776 >> >> It's OK, with 10 more loops I get 10 more execution time. >> >> But with exponentiation, it's a mess >> >>>>> Timer("x=123456**123456").timeit(1) >> 6.076191311876755e-06 >>>>> Timer("x=123456**123456").timeit(10) >> 3.841270313387213e-06 >> >> All wrong, the calculation of 123456**123456 is much longer >> than 6 microseconds, it takes few seconds, and with 10 loops timeit >> provided a shorter time ... > > No, this is right. The calculation takes practically no time; on my > system, it takes some 10 ns. The uncertainty of the timeit result is at > least a few hundred nanoseconds. You've misdiagnosed Ast's problem, and fallen for the same Gotcha he has. You're not measuring what you think you measured: >>>> Timer("x=123456**123456").timeit(10**6) > 0.00969144597183913 Calculating BigInt exponentiation is fast, but its not that fast once you get to hundreds of thousands of digits. That calculates the 600,000+ digit number 123456**123456 once, at compile time, then simply assigns that huge number to x a million times. So you would likely get almost the same result by running: Timer("x=17").timeit(10**6) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ceiussandicus at gmail.com Fri Dec 15 08:25:44 2017 From: ceiussandicus at gmail.com (Cei Sanderson) Date: Fri, 15 Dec 2017 05:25:44 -0800 (PST) Subject: Can't start IDLE on mac os x high sierra can't import Tkinter In-Reply-To: References: <7e8d1fbc-cfa3-48fd-8ad9-0af2df6267fe@googlegroups.com> Message-ID: <81e7f894-d74f-4831-8885-c7d5aba63da9@googlegroups.com> On Friday, December 15, 2017 at 12:44:14 PM UTC, Terry Reedy wrote: > On 12/15/2017 6:37 AM, ceiussandicus at gmail.com wrote: > > Hi, I've been trying to get python 3.4.3 (needed for programming course) on my mac, running High Sierra. > > I've installed python and activetcl 8.5.18 as per instructions. When I start IDLE from finder it flashes in the dock and disappears. When I start it from terminal, I get the following response: > > ** IDLE can't import Tkinter. > > Your Python may not be configured for Tk. ** > > I've googled for the answer but I can't find anything, the closest I got was to this https://github.com/pyinstaller/pyinstaller/issues/2665 but I'm not sure if it is this issue or not. > > Can someone help me get started using python? > > I don't have a Mac, but I know that > https://www.python.org/download/mac/tcltk/ > has some fairly exacting instructions at the bottom on how to get Python > to find the newly installed tcl/tk. You should probably specify rather > exactly what you did. There are multiple issues on bugs.python.org and > questions on stackoverflow. > > -- > Terry Jan Reedy Thanks Terry, I posted on here because I've struggled after trawling through Google and following the instructions on that page. I have installed: ActiveTcl 8.5.18.0 then I installed Python 3.4.3 I've found the issue by continuing to trawl a bit more, the course download for python (a few years old) pointed to the python install for 10.5 onwards not 10.6 onwards. Installed the right python and working. From nomail at com.invalid Fri Dec 15 08:25:55 2017 From: nomail at com.invalid (ast) Date: Fri, 15 Dec 2017 14:25:55 +0100 Subject: Problem with timeit In-Reply-To: References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> Message-ID: <5a33cd6c$0$3419$426a74cc@news.free.fr> "Thomas Jollans" a ?crit dans le message de news:mailman.74.1513341235.14074.python-list at python.org... > On 2017-12-15 11:36, ast wrote: > No, this is right. The calculation takes practically no time; on my > system, it takes some 10 ns. The uncertainty of the timeit result is at > least a few hundred nanoseconds. There are more than 100000 multiplications to perform on a soaring size integer. I have some doubts "x=123456**123456 " only takes 10 ns on your system. On my computer it takes roughtly 4 s, mesured with a watch. I can't do "len(str(x))" to know the size, I have to kill the process But x.bit_length() answers 2088091, so x should have about 600000 digits If I measure execution time: >>> t=time(); x=123456**123456; print(time()-t) 0.0 There is still something wrong I suppose that my computer CPU goes to 100% busy and that the timer used by timeit or time no longer works. From nomail at com.invalid Fri Dec 15 08:37:07 2017 From: nomail at com.invalid (ast) Date: Fri, 15 Dec 2017 14:37:07 +0100 Subject: Problem with timeit In-Reply-To: <5a33a5aa$0$10195$426a74cc@news.free.fr> References: <5a33a5aa$0$10195$426a74cc@news.free.fr> Message-ID: <5a33d00f$0$3451$426a74cc@news.free.fr> "ast" a ?crit dans le message de news:5a33a5aa$0$10195$426a74cc at news.free.fr... Ty Peter and Steve, I would never have found that explanation myself From steve+python at pearwood.info Fri Dec 15 08:41:15 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 16 Dec 2017 00:41:15 +1100 Subject: Problem with timeit References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> <5a33cd6c$0$3419$426a74cc@news.free.fr> Message-ID: <5a33d0fc$0$2087$b1db1813$d948b532@news.astraweb.com> On Sat, 16 Dec 2017 12:25 am, ast wrote: > > "Thomas Jollans" a ?crit dans le message de > news:mailman.74.1513341235.14074.python-list at python.org... >> On 2017-12-15 11:36, ast wrote: > > >> No, this is right. The calculation takes practically no time; on my >> system, it takes some 10 ns. The uncertainty of the timeit result is at >> least a few hundred nanoseconds. > > There are more than 100000 multiplications to perform on a > soaring size integer. I have some doubts "x=123456**123456 " > only takes 10 ns on your system. You would be right. My computer appears to be about a thousand times slower than Thomas' computer. On my computer, it takes about a second to calculate 123456**123456, so I predict his will take about a millisecond. > On my computer it takes roughtly 4 s, mesured with a watch. That's not a very accurate way to measure it. You are measuring your own reaction time, the time it takes the interactive interpreter to parse the text of the code, compile it, execute the code, then print a new prompt, and then your reaction time again. The actual execution time is drowned in the rest of the noise. > I can't do "len(str(x))" to know the size, I have to kill the process On my computer, that took about five minutes or so. I wasn't really paying attention on precisely how long it took, but it was around that. > But x.bit_length() answers 2088091, so x should have about > 600000 digits py> x = 123456**123456 py> s = str(x) py> len(s) 628578 > If I measure execution time: > >>>> t=time(); x=123456**123456; print(time()-t) > 0.0 > > There is still something wrong The interpreter first computes the big int 123456**123456 while it is compiling the entire command line, so that happens *before* the time starts. The assignment is so fast that the three statements: t = time() x = 5...6 # huge number, pre-calculated print(time() - t) essentially occurs faster than the resolution of time.time() on your machine. Try using time.perf_counter instead. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From p.f.moore at gmail.com Fri Dec 15 08:47:10 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 15 Dec 2017 13:47:10 +0000 Subject: Problem with timeit In-Reply-To: <5a33cd6c$0$3419$426a74cc@news.free.fr> References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> <5a33cd6c$0$3419$426a74cc@news.free.fr> Message-ID: On 15 December 2017 at 13:25, ast wrote: > On my computer it takes roughtly 4 s, mesured with a watch. Is your computer particularly old? On my PC, the time it takes to run x=123456**123456 at the Python interpreter prompt is barely noticeable. > I can't do "len(str(x))" to know the size, I have to kill the process Took a few seconds (5-10s) on my PC, and returned 628578. > But x.bit_length() answers 2088091, so x should have about > 600000 digits Yep, that's what I get > > If I measure execution time: > >>>> t=time(); x=123456**123456; print(time()-t) > > 0.0 Same here. > There is still something wrong As far as I can see, it's in your manual measurement. All of the code you've provided gives the same results on my PC as on yours, but your manual measurements differ drastically from mine (and my manual measurements match what I'd expect given results of timeit/time.time whereas yours don't...). Paul From michael.biondi at gnetsys.net Fri Dec 15 10:09:40 2017 From: michael.biondi at gnetsys.net (Michael Biondi) Date: Fri, 15 Dec 2017 10:09:40 -0500 Subject: Python Learning In-Reply-To: References: Message-ID: <626d05ca-da7b-1e83-07dd-605c807b1a85@gnetsys.net> I've been slowly reading through "Learning Python: Powerful Object-Oriented Programming" - ( https://www.amazon.com/Learning-Python-Powerful-Object-Oriented-Programming-ebook/dp/B00DDZPC9S/ref=sr_1_2?ie=UTF8&qid=1513350446&sr=8-2&keywords=learning+python+powerful+object-oriented+programming ) It's a huge read and not a great book if you just want to get started right away, but I've found it to be very helpful in explaining the nuances of the language.? I'm interested to see what other people find useful. Thanks, Michael On 12/15/2017 6:49 AM, Varun R wrote: > Hi All, > > I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. > > Thanks all -- -- Michael Biondi Generic Network Systems, LLC (212) 268-4722 ext. 215 From grant.b.edwards at gmail.com Fri Dec 15 11:45:06 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Dec 2017 16:45:06 +0000 (UTC) Subject: Please tell me how to execute python file in Ubuntu by double References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> <5a33a541$0$2087$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-12-15, Steve D'Aprano wrote: > On Fri, 15 Dec 2017 09:48 am, Gregory Ewing wrote: [...] > Classic MacOS associated two such pieces of metadata with each file: the > creator and type. [...] > > https://en.wikipedia.org/wiki/Creator_code > >> I believe MacOSX also has the ability to store a file type as >> metadata, but it doesn't seem to be used much. > > They are still supported (-ish) by OS X, but have been superseded by Uniform > Type Identifiers. Where are the UTIs stored? Do OS X filesystems still have a "resource fork"? -- Grant Edwards grant.b.edwards Yow! I smell like a wet at reducing clinic on Columbus gmail.com Day! From bob at mellowood.ca Fri Dec 15 13:52:35 2017 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 15 Dec 2017 11:52:35 -0700 Subject: Problem with timeit In-Reply-To: References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> <5a33cd6c$0$3419$426a74cc@news.free.fr> Message-ID: I get a very short delay when doing the calculation. 1.90734863281e-06 to be precise. But, printing the result takes much longer. 4.82930707932 seconds. On Fri, Dec 15, 2017 at 6:47 AM, Paul Moore wrote: > On 15 December 2017 at 13:25, ast wrote: > > On my computer it takes roughtly 4 s, mesured with a watch. > > Is your computer particularly old? On my PC, the time it takes to run > x=123456**123456 at the Python interpreter prompt is barely > noticeable. > > > I can't do "len(str(x))" to know the size, I have to kill the process > > Took a few seconds (5-10s) on my PC, and returned 628578. > > > But x.bit_length() answers 2088091, so x should have about > > 600000 digits > > Yep, that's what I get > > > > > If I measure execution time: > > > >>>> t=time(); x=123456**123456; print(time()-t) > > > > 0.0 > > Same here. > > > There is still something wrong > > As far as I can see, it's in your manual measurement. All of the code > you've provided gives the same results on my PC as on yours, but your > manual measurements differ drastically from mine (and my manual > measurements match what I'd expect given results of timeit/time.time > whereas yours don't...). > > Paul > -- > https://mail.python.org/mailman/listinfo/python-list > -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From skip.montanaro at gmail.com Fri Dec 15 14:03:11 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 15 Dec 2017 13:03:11 -0600 Subject: Automated distribution building tools to support SpamBayes Message-ID: SpamBayes (http://www.spambayes.org/) has languished for quite awhile, in part because nobody is around who can put together a Windows installer. Unfortunately, most users are on Windows and have to work around problems caused by the march of time and consequent beefing up of Windows security. I don't do Windows, but I wonder... Can one of the various continuous integration tools out there be enlisted to build Windows installers? The SB code is written in Python, uses the Win32 extension, and is hosted on GitHub (https://github.com/smontanaro/spambayes), so something which plays nice with that environment would be a plus. I'm slowly gaining familiarity at work with Bamboo (very, very slowly), so the general idea of what CI tools can do is starting to sink in. Since I'm a captive Atlassian customer at work, though, I don't know what limitations I might encounter trying to use it in an open source environment. Any feedback appreciated. As this is only Python-related in the sense that SpamBayes is written in Python, feel free to reply off-list. Skip From 114piyush at gmail.com Fri Dec 15 14:06:52 2017 From: 114piyush at gmail.com (Piyush Verma) Date: Sat, 16 Dec 2017 00:36:52 +0530 Subject: ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol Message-ID: Getting SSL error while connecting from httplib.HTTPSConnection. Any help would be appreciated. self.connection.request(method, request, payload, self.headers) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1053, in request self._send_request(method, url, body, headers) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1093, in _send_request self.endheaders(body) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1049, in endheaders self._send_output(message_body) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 893, in _send_output self.send(msg) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 855, in send self.connect() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1274, in connect server_hostname=server_hostname) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 352, in wrap_socket _context=self) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 579, in __init__ self.do_handshake() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 808, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590) Regards, ~Piyush Facebook Twitter From BILL_NOSPAM at Noway.net Fri Dec 15 16:51:09 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Fri, 15 Dec 2017 16:51:09 -0500 Subject: Python Learning In-Reply-To: References: Message-ID: Varun R wrote: > Hi All, > > I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. > > Thanks all Are you sure you want to learn Python first? Python does enough things "behind the scene" that it makes me question the wisdom of that. Other points of view are welcome, of course. Learning the primitives of C++ first, may make for an easier transition. Surely this has been discussed before? From rosuav at gmail.com Fri Dec 15 17:18:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Dec 2017 09:18:05 +1100 Subject: Python Learning In-Reply-To: References: Message-ID: On Sat, Dec 16, 2017 at 8:51 AM, Bill wrote: > Varun R wrote: >> >> Hi All, >> >> I'm new to programming, can anyone guide me, how to start learning python >> programming language,...plz suggest some books also. >> >> Thanks all > > > Are you sure you want to learn Python first? > Python does enough things "behind the scene" > that it makes me question the wisdom of that. > Other points of view are welcome, of course. > Learning the primitives of C++ first, may make for an easier transition. > Surely this has been discussed before? On the contrary, that makes Python an *excellent* first language. We don't force people to learn about the chemistry of petrochemical combustion before letting them learn how to drive a car; we don't make people understand TCP/IP networking before they're allowed to type something into Google. And if you DO want people to start off with a lower-level language, why C++? Why not machine code (or at least assembly code), since that's what the CPU actually executes? Or wait - let's start off by teaching people the electrical engineering that underlies all of the CPU's operation. And at least a bit of quantum physics, since that governs stuff once you get to the level of miniaturization of modern CPUs. No; it's far better to start out by treating Python as its own thing, powered by magic. Later on, you can peel back the layers and learn about what's behind everything - at your own pace. ChrisA From greg.ewing at canterbury.ac.nz Fri Dec 15 17:44:44 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 16 Dec 2017 11:44:44 +1300 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: <5a33a541$0$2087$b1db1813$d948b532@news.astraweb.com> References: <2233058465@f38.n261.z1.binkp.net> <2882728314@f38.n261.z1.binkp.net> <8e136b65-635b-4470-8f25-73a5a5685c8c@googlegroups.com> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> <5a33a541$0$2087$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > They are still supported (-ish) by OS X, but have been superseded by Uniform > Type Identifiers. > > https://en.wikipedia.org/wiki/Uniform_Type_Identifier I know, what I'm not sure about is how much those are used by apps these days, with so much of the widely used software being multi-platform. The Finder doesn't make it easy to tell -- it just shows you which app is the default one for a file, without any details as to how it's determining that. And if you change the default app for a file, it asks "Do you want to open all file like this with ?", but it's not very clear what "like" means for a given file. It could mean "having the same suffix", "having the same UTI", or "having the same legacy type code". -- Greg From greg.ewing at canterbury.ac.nz Fri Dec 15 17:56:39 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 16 Dec 2017 11:56:39 +1300 Subject: Please tell me how to execute python file in Ubuntu by double In-Reply-To: References: <2233058465@f38.n261.z1.binkp.net> <5ab11fcb-7ce6-4bd8-a3e8-dec2d8cefb64@googlegroups.com> <101b16f2-f19d-2015-73d9-23054b37a636@kynesim.co.uk> <5a33a541$0$2087$b1db1813$d948b532@news.astraweb.com> Message-ID: Grant Edwards wrote: > Where are the UTIs stored? Do OS X filesystems still have a "resource > fork"? UTIs are stored as extended attributes. Resource forks still exist, but they're deprecated. Things that used to be kept in resource forks are now usually just files in the application bundle -- which is just a specially marked directory as far as the OS is concerned. -- Greg From ned at nedbatchelder.com Fri Dec 15 18:38:43 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 15 Dec 2017 18:38:43 -0500 Subject: Automated distribution building tools to support SpamBayes In-Reply-To: References: Message-ID: <17951cff-16de-7aa3-32ef-520867d34bc5@nedbatchelder.com> On 12/15/17 2:03 PM, Skip Montanaro wrote: > SpamBayes (http://www.spambayes.org/) has languished for quite awhile, > in part because nobody is around who can put together a Windows > installer. Unfortunately, most users are on Windows and have to work > around problems caused by the march of time and consequent beefing up > of Windows security. > > I don't do Windows, but I wonder... Can one of the various continuous > integration tools out there be enlisted to build Windows installers? > The SB code is written in Python, uses the Win32 extension, and is > hosted on GitHub (https://github.com/smontanaro/spambayes), so > something which plays nice with that environment would be a plus. I'm > slowly gaining familiarity at work with Bamboo (very, very slowly), so > the general idea of what CI tools can do is starting to sink in. Since > I'm a captive Atlassian customer at work, though, I don't know what > limitations I might encounter trying to use it in an open source > environment. > > Any feedback appreciated. As this is only Python-related in the sense > that SpamBayes is written in Python, feel free to reply off-list. > > Skip I use AppVeyor CI to build Windows installers for coverage.py.? It's not straightforward though, there are Powershell scripts, etc. The config file is here: https://github.com/nedbat/coveragepy/blob/master/appveyor.yml with other necessities in the ci folder. Hope that helps, --Ned. From greg.ewing at canterbury.ac.nz Fri Dec 15 18:56:07 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 16 Dec 2017 12:56:07 +1300 Subject: Repeated Names (Repeated Names) Message-ID: Anyone else now getting duplicate posts with the sender's name repeated in parentheses? -- Greg From python at mrabarnett.plus.com Fri Dec 15 19:49:09 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 16 Dec 2017 00:49:09 +0000 Subject: Repeated Names (Repeated Names) In-Reply-To: References: Message-ID: <4b6785b5-6004-36fd-79d0-b8589334d809@mrabarnett.plus.com> On 2017-12-15 23:56, Gregory Ewing wrote: > Anyone else now getting duplicate posts with the sender's > name repeated in parentheses? > It's happened twice before, but I haven't had any today. From BILL_NOSPAM at Noway.net Fri Dec 15 23:14:01 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Fri, 15 Dec 2017 23:14:01 -0500 Subject: Python Learning In-Reply-To: References: Message-ID: Chris Angelico wrote: > On Sat, Dec 16, 2017 at 8:51 AM, Bill wrote: >> Varun R wrote: >>> Hi All, >>> >>> I'm new to programming, can anyone guide me, how to start learning python >>> programming language,...plz suggest some books also. >>> >>> Thanks all >> >> Are you sure you want to learn Python first? >> Python does enough things "behind the scene" >> that it makes me question the wisdom of that. >> Other points of view are welcome, of course. >> Learning the primitives of C++ first, may make for an easier transition. >> Surely this has been discussed before? > On the contrary, that makes Python an *excellent* first language. We > don't force people to learn about the chemistry of petrochemical > combustion before letting them learn how to drive a car; we don't make > people understand TCP/IP networking before they're allowed to type > something into Google. And if you DO want people to start off with a > lower-level language, why C++? Why not machine code (or at least > assembly code), since that's what the CPU actually executes? Most decent introductions to C++ discuss machine language (it helps make sense of compilation). As you indirectly suggest, learning is something of a circular process, so it really doesn't make that much difference where one starts, just "Do It!". : ) From rustompmody at gmail.com Fri Dec 15 23:34:46 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 15 Dec 2017 20:34:46 -0800 (PST) Subject: Python Learning In-Reply-To: References: Message-ID: <52606653-d016-4cad-948a-b9fe701f21cf@googlegroups.com> On Saturday, December 16, 2017 at 9:45:17 AM UTC+5:30, Bill wrote: > Chris Angelico wrote: > > On Sat, Dec 16, 2017 at 8:51 AM, Bill wrote: > >> Varun R wrote: > >>> Hi All, > >>> > >>> I'm new to programming, can anyone guide me, how to start learning python > >>> programming language,...plz suggest some books also. > >>> > >>> Thanks all > >> > >> Are you sure you want to learn Python first? > >> Python does enough things "behind the scene" > >> that it makes me question the wisdom of that. > >> Other points of view are welcome, of course. > >> Learning the primitives of C++ first, may make for an easier transition. > >> Surely this has been discussed before? > > On the contrary, that makes Python an *excellent* first language. We > > don't force people to learn about the chemistry of petrochemical > > combustion before letting them learn how to drive a car; we don't make > > people understand TCP/IP networking before they're allowed to type > > something into Google. And if you DO want people to start off with a > > lower-level language, why C++? Why not machine code (or at least > > assembly code), since that's what the CPU actually executes? > > Most decent introductions to C++ discuss machine language (it helps make > sense of compilation). > As you indirectly suggest, learning is something of a circular process, > so it really doesn't make that much difference where one starts, just > "Do It!". : ) Really?? https://en.wikipedia.org/wiki/Principles_of_learning#Primacy From dieter at handshake.de Sat Dec 16 03:29:50 2017 From: dieter at handshake.de (dieter) Date: Sat, 16 Dec 2017 09:29:50 +0100 Subject: ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol References: Message-ID: <87po7fgjnl.fsf@handshake.de> Piyush Verma <114piyush at gmail.com> writes: > Getting SSL error while connecting from httplib.HTTPSConnection. > > Any help would be appreciated. > ... > line 579, in __init__ > self.do_handshake() > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", > line 808, in do_handshake > self._sslobj.do_handshake() > ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590) Are you sure, you try to connect to an HTTPS port? The error message tells you that the "ssl" handshake failed because the protocol was unknown (likely because the message was not understood). The most natural reason is to try to connect to something which is not prepared for an "ssl" handshake. From marko at pacujo.net Sat Dec 16 07:41:01 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Dec 2017 14:41:01 +0200 Subject: Python Learning References: Message-ID: <87r2ru6e1u.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > Varun R writes: >>I'm new to programming, can anyone guide me, how to start >>learning python programming language > > As a start, one should learn: > > 1.) how to install Python > (if not already installed) > > 2.) how to start the Python console > (if not already started) > > 3.) how to type characters into a line of the > console and how to submit the line (using > the Enter key) (if this is not already known) A good list. Even more important, though, is the installation, use and understanding of a text editor. What is the difference of MS Word, Notepad and a Python-aware text editor? What text editors are there? What is a newline? What is whitespace? (Advanced: what is a TAB.) What is the difference between lower case and upper case? What is trailing whitespace? What is an underscore? What is the difference between a parenthesis, bracket and a brace? What is a file? What is a filename? What is a directory/folder? What is a pathname? What is a terminal (emulator)? What is standard input? What is standard output? How do I see the listing of files? How do I erase a file? How do I rename a file? What is the current working directory? How do I change it and why? Marko From rosuav at gmail.com Sat Dec 16 08:12:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Dec 2017 00:12:49 +1100 Subject: Python Learning In-Reply-To: <87r2ru6e1u.fsf@elektro.pacujo.net> References: <87r2ru6e1u.fsf@elektro.pacujo.net> Message-ID: On Sat, Dec 16, 2017 at 11:41 PM, Marko Rauhamaa wrote: > ram at zedat.fu-berlin.de (Stefan Ram): > >> Varun R writes: >>>I'm new to programming, can anyone guide me, how to start >>>learning python programming language >> >> As a start, one should learn: >> >> 1.) how to install Python >> (if not already installed) >> >> 2.) how to start the Python console >> (if not already started) >> >> 3.) how to type characters into a line of the >> console and how to submit the line (using >> the Enter key) (if this is not already known) > > A good list. Even more important, though, is the installation, use and > understanding of a text editor. What is the difference of MS Word, > Notepad and a Python-aware text editor? What text editors are there? > What is a newline? What is whitespace? (Advanced: what is a TAB.) What > is the difference between lower case and upper case? What is trailing > whitespace? What is an underscore? What is the difference between a > parenthesis, bracket and a brace? > > What is a file? What is a filename? What is a directory/folder? What is > a pathname? What is a terminal (emulator)? What is standard input? What > is standard output? > > How do I see the listing of files? How do I erase a file? How do I > rename a file? What is the current working directory? How do I change it > and why? > ... at which point you realize that you're deep in TL;DR territory and none of what you mentioned will be even thought about. ChrisA From marko at pacujo.net Sat Dec 16 08:26:21 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Dec 2017 15:26:21 +0200 Subject: Python Learning References: <87r2ru6e1u.fsf@elektro.pacujo.net> Message-ID: <87mv2i6bya.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Dec 16, 2017 at 11:41 PM, Marko Rauhamaa wrote: >> ram at zedat.fu-berlin.de (Stefan Ram): >>> As a start, one should learn: >>> >>> 1.) how to install Python >>> (if not already installed) >>> >>> 2.) how to start the Python console >>> (if not already started) >>> >>> 3.) how to type characters into a line of the >>> console and how to submit the line (using >>> the Enter key) (if this is not already known) >> >> A good list. Even more important, though, is the installation, use and >> understanding of a text editor. What is the difference of MS Word, >> Notepad and a Python-aware text editor? What text editors are there? >> What is a newline? What is whitespace? (Advanced: what is a TAB.) What >> is the difference between lower case and upper case? What is trailing >> whitespace? What is an underscore? What is the difference between a >> parenthesis, bracket and a brace? >> >> What is a file? What is a filename? What is a directory/folder? What is >> a pathname? What is a terminal (emulator)? What is standard input? What >> is standard output? >> >> How do I see the listing of files? How do I erase a file? How do I >> rename a file? What is the current working directory? How do I change it >> and why? > > ... at which point you realize that you're deep in TL;DR territory and > none of what you mentioned will be even thought about. Hm. I don't think you can get away from getting acquainted with all of the above before you can write your first "Hello, World!" program in Python. It was simpler when I first learned Basic. There were no files, and your REPL was your editor. The ingenious line numbers took the role of the text editor. Unfortunately, Python's indentation mechanism makes the REPL too frustrating an environment to type in even the simplest of function definitions, let alone a whole class. Marko From edmondo.giovannozzi at gmail.com Sat Dec 16 12:44:33 2017 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Sat, 16 Dec 2017 09:44:33 -0800 (PST) Subject: Python Learning In-Reply-To: References: Message-ID: <654d1ac6-eeb8-49b2-bef7-d27de5c6bf08@googlegroups.com> Il giorno venerd? 15 dicembre 2017 12:50:08 UTC+1, Varun R ha scritto: > Hi All, > > I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. > > Thanks all Personally I learnt python from the tutorial that you can find in: https://docs.python.org/3/tutorial/index.html But I should say that I already knew other programming languages. By the way I would give a try at that tutorial and ask if you cannot understand something. :-) From dvl at psu.edu Sat Dec 16 12:56:44 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Sat, 16 Dec 2017 12:56:44 -0500 Subject: Python Learning In-Reply-To: mailman.40.1513443603.29050.python-list@python.org References: Message-ID: <1513447004l.18874524l.0l@psu.edu> On Sat, Dec 16, 2017, Bill wrote: > Varun R wrote: >> Hi All, >> >> I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. >> >> Thanks all > >Are you sure you want to learn Python first? >Python does enough things "behind the scene" >that it makes me question the wisdom of that. >Other points of view are welcome, of course. >Learning the primitives of C++ first, may make for an easier transition. >Surely this has been discussed before? > Having taught introductory courses both with C++ and Python as first languages, I really think Python is a better choice. Consider this nice simple Python program: print('Hello, world!') How much background does a student need to understand this, or to produce programs of equivalent complexity? Do you really want to get into explaining why you need to refer to the iostream library, consult the std namespace, and define a function named main, and why it returns zero? Is any of that really necessary to understand how to print output? Or by primitives, do you first get into the integer data type, how to declare variables, and how to do arithmetic (all of which are nice and primitive and C++) and postpone all input and output until the third month of the course, after you have had adequate time to to explain in detail the meanings of function declarations, namespaces, streams and #include? >From my experience, both as instructor and student, with introductory programming courses with half a dozen different first languages to use for those courses, I think C++ is one of the worst choices! (In my humble opinion, of course) Roger Christman Pennsylvania State University From dvl at psu.edu Sat Dec 16 13:27:40 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Sat, 16 Dec 2017 13:27:40 -0500 Subject: Python Learning In-Reply-To: mailman.40.1513443603.29050.python-list@python.org References: Message-ID: <1513448860l.39780406l.0l@psu.edu> On Sat, Dec 16, 2017, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Dec 16, 2017 at 11:41 PM, Marko Rauhamaa wrote: >> ram at zedat.fu-berlin.de (Stefan Ram): >> As a start, one should learn: >> >> 1.) how to install Python >> (if not already installed) >> >> 2.) how to start the Python console >> (if not already started) >> >> 3.) how to type characters into a line of the >> console and how to submit the line (using >> the Enter key) (if this is not already known) >> >> A good list. Even more important, though, is the installation, use and >> understanding of a text editor. What is the difference of MS Word, >> Notepad and a Python-aware text editor? What text editors are there? >> What is a newline? What is whitespace? (Advanced: what is a TAB.) What >> is the difference between lower case and upper case? What is trailing >> whitespace? What is an underscore? What is the difference between a >> parenthesis, bracket and a brace? >> >> What is a file? What is a filename? What is a directory/folder? What is >> a pathname? What is a terminal (emulator)? What is standard input? What >> is standard output? >> >> How do I see the listing of files? How do I erase a file? How do I >> rename a file? What is the current working directory? How do I change it >> and why? >> >> ... at which point you realize that you're deep in TL;DR territory and >> none of what you mentioned will be even thought about. > >Hm. I don't think you can get away from getting acquainted with all of >the above before you can write your first "Hello, World!" program in >Python. > >It was simpler when I first learned Basic. There were no files, and your >REPL was your editor. The ingenious line numbers took the role of the >text editor. > >Unfortunately, Python's indentation mechanism makes the REPL too >frustrating an environment to type in even the simplest of function >definitions, let alone a whole class. > > >Marko > On the contrary, I think I think you can getaway with a lot of those items: Let's see: All the stuff about files, folders, directories, etc: Running the Python IDLE environment that comes for free along with the free download, creates its own little folder for all the work, saves the files in that folder, and makes it easy for you to see what is in there, recover your previous programs, etc. I have never had any difficulty in using the File menu to Open a Recent File, etc. Of course, I assume the ability to obtain the Python environment, that requires pointing your browser at the appropriate web site, find the download page, and so on. I guess I am assuming that most of my students have either used the web before, or have downloaded software (such as their favorite games or apps). It has been about twenty years since I felt a need to teach my students how to find the on/off switch. MS Word, vs. Notepad, vs. vi, vs. Emacs, vs. vs. vs. vs. Since Python IDLE has its own development environment, that is sufficient. And it even addresses the tab vs. space indentation issues all by itself, and lets you Indent and Dedent whole blocks of code cleanly and easily. So, Hello World is trivial. In fact, there are two trivial ways to do it with Python IDLE. You get the Shell for free, and just type your print call there. Or you go to the File Menu, Open a new file, type in one statement, and activate the Run option on the menu bar. Now, as far as those other items you think impose an excessive burden on our poor students: Difference between parenthesis, bracket, and a brace: These are simple syntactic punctuation, introduced one item at a time. They should already know about parentheses from even elementary arithmetic courses, if not basic algebra. Brackets can be postponed until you are ready to reach about lists. Braces can be postponed until you are ready to teach about dictionaries. Put them in their proper context, and then thinking in the proper context should make the correct choice of punctuation automatic. "Python's indentation mechanism ... frustrating ... even the simplest function definitions, let alone a whole class." When first reading this, I was wondering why you were even considering class definitions in a first course. If you find print("Hello, world!" to be too complicated for this first course, how can you expect any meaningful coverage of OOP? But aside from that, indentation can also be postponed. I went four-five weeks into my course before needing any indentation whatsoever. All the code was straight down top to bottom with no function definitions, conditional statements, or loops. I did make use of some short lists and dictionaries, since those conveniently have many useful methods defined within them, so could solve several interesting straightforward problems without introducing too much of the language. Oh, and when the time comes, as above, the Python IDLE environment does a perfectly adequate job in handling indentation. Not so much the case in C++ as a first language, of course. Well, yes, you could get away with writing a complete C++ program with no indentation whatsoever, but I haven't yet met a course that would encourage that. I hope you are not one of those instructors I still see that reason that since all programs in Java, C, and C++ require a function named main(), then so do all Python programs require a function named main(), called within if __name__ == '__main__': main() From Ziggy at Free.net Sat Dec 16 14:24:21 2017 From: Ziggy at Free.net (Ziggy) Date: Sat, 16 Dec 2017 19:24:21 GMT Subject: Python Learning References: Message-ID: On 2017-12-15, Varun R wrote: > Hi All, > > I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. > > Thanks all IMHO These're must have look at: http://opim.wharton.upenn.edu/~sok/idtresources/python/instant-hacking.html https://www.learnpython.org https://docs.python.org/3.5/ http://stackoverflow.com -- Thank you From tjreedy at udel.edu Sat Dec 16 16:09:06 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Dec 2017 16:09:06 -0500 Subject: Python Learning In-Reply-To: <87mv2i6bya.fsf@elektro.pacujo.net> References: <87r2ru6e1u.fsf@elektro.pacujo.net> <87mv2i6bya.fsf@elektro.pacujo.net> Message-ID: On 12/16/2017 8:26 AM, Marko Rauhamaa wrote: > Unfortunately, Python's indentation mechanism makes the REPL too > frustrating an environment to type in even the simplest of function > definitions, let alone a whole class. The fundamental problem is that most REPLs are for 'command lines', and Python does not have 'command lines'. It has statements. A statement may consist of a single line, and if simple, it looks and acts like a command line. But a statement may also be multiple lines. Even without indentation, a single-line editing and history mechanism is a poor fit to a multiline statement language. IDLE has a shell built for Python and Python only. One enters, edits, and retrieves complete statements. Indentation is automatic. There is currently a glitch in that Shell indents with tabs instead of spaces, but I want to change that and know of two ways to do so. -- Terry Jan Reedy From bazthelinuxguy at gmail.com Sat Dec 16 16:27:00 2017 From: bazthelinuxguy at gmail.com (Bryan Zimmer) Date: Sat, 16 Dec 2017 15:27:00 -0600 Subject: pip failed installs Message-ID: I have had only partial success with pip. Some things seem to install OK. But I've tried a couple of packages, specifically "BeautifulSoup" and "WxPython", and they fail with the same message, e.g.: *Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ku98d6jd/BeautifulSoup/* I've gotten this error for most of the packages I have tried to install, but I don't know what causes the error. I have successfully installed some packages, such as html5lib, so my installation isn't totally messed up. I am using a Slackware Linux. I have gotten this error message both on a 64-bit installation and a 32-bit installation. From no at spam.com Sat Dec 16 17:12:10 2017 From: no at spam.com (Cutter) Date: Sat, 16 Dec 2017 23:12:10 +0100 Subject: Can't install wrapt on Windows In-Reply-To: <4205577533@f38.n261.z1.binkp.net> References: <4205577533@f38.n261.z1.binkp.net> Message-ID: <5a359a40$0$3421$426a74cc@news.free.fr> Le 10/12/2017 ? 21:46, dieter (dieter) a ?crit?: > Cutter writes: >> ... >> I have trouble installing pylint on Windows 10, Python 3.6. There's a >> problem during the installation of wrapt, which is a dependency of >> pylint. >> >> Here are the contents of the commandline: >> >>> C:\WINDOWS\system32>python -m pip install pylint >>> ... >>> Collecting wrapt (from astroid>=1.5.1->pylint) >>> Using cached wrapt-1.10.11.tar.gz >>> Installing collected packages: colorama, wrapt, astroid, pylint >>> Running setup.py install for wrapt ... error >>> Exception: >>> Traceback (most recent call last): >>> File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packa > ges\pip\compat\__init__.py", line 73, in console_to_str >>> return s.decode(sys.__stdout__.encoding) >>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: > invalid start byte > > Obviously, something causes some "s" to be decoded using the "stdout" encoding > (which usually is the system encoding). In your case, this encoding is "utf-8", > but "s" does not seem to be utf-8 encoded. > > I would use debugging to find out what "s" is, where is comes from and why it > does not use the "stdout" encoding. > I don't know how to use pdb. Instead, I've added the following instruction at line 73 before the error occurs: print("!! TEST !! : ", s) Here's the output now: > C:\WINDOWS\system32>python -m pdb C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\__main__.py install pylint >> c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages\pip\__main__.py(1)() > -> from __future__ import absolute_import > (Pdb) c > Requirement already satisfied: pylint in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages > Requirement already satisfied: mccabe in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Requirement already satisfied: six in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Requirement already satisfied: isort>=4.2.5 in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Requirement already satisfied: astroid<2.0 in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Requirement already satisfied: colorama; sys_platform == "win32" in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from pylint) > Requirement already satisfied: lazy-object-proxy in c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from astroid<2.0->pylint) > Collecting wrapt (from astroid<2.0->pylint) > Using cached wrapt-1.10.11.tar.gz > !! TEST !! : b'running egg_info\r\n' > !! TEST !! : b'creating pip-egg-info\\wrapt.egg-info\r\n' > !! TEST !! : b'writing pip-egg-info\\wrapt.egg-info\\PKG-INFO\r\n' > !! TEST !! : b'writing dependency_links to pip-egg-info\\wrapt.egg-info\\dependency_links.txt\r\n' > !! TEST !! : b'writing top-level names to pip-egg-info\\wrapt.egg-info\\top_level.txt\r\n' > !! TEST !! : b"writing manifest file 'pip-egg-info\\wrapt.egg-info\\SOURCES.txt'\r\n" > !! TEST !! : b"warning: manifest_maker: standard file '-c' not found\r\n" > !! TEST !! : b'\r\n' > !! TEST !! : b"reading manifest file 'pip-egg-info\\wrapt.egg-info\\SOURCES.txt'\r\n" > !! TEST !! : b"writing manifest file 'pip-egg-info\\wrapt.egg-info\\SOURCES.txt'\r\n" > !! TEST !! : b'' > Building wheels for collected packages: wrapt > Running setup.py bdist_wheel for wrapt ... !! TEST !! : b'usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]\r\n' > -!! TEST !! : b' or: -c --help [cmd1 cmd2 ...]\r\n' > !! TEST !! : b' or: -c --help-commands\r\n' > !! TEST !! : b' or: -c cmd --help\r\n' > !! TEST !! : b'\r\n' > !! TEST !! : b"error: invalid command 'bdist_wheel'\r\n" > !! TEST !! : b'' > error > Complete output from command C:\Users\(...)\AppData\Local\Programs\Python\Python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\(...)\\AppData\\Local\\Temp\\pip-build-4_065lch\\wrapt\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\(...)\AppData\Local\Temp\tmpzyfae43tpip-wheel- --python-tag cp36: > usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] > or: -c --help [cmd1 cmd2 ...] > or: -c --help-commands > or: -c cmd --help > > error: invalid command 'bdist_wheel' > > ---------------------------------------- > Failed building wheel for wrapt > Running setup.py clean for wrapt > !! TEST !! : b'running clean\r\n' > !! TEST !! : b"'build\\lib.win-amd64-3.6' does not exist -- can't clean it\r\n" > !! TEST !! : b"'build\\bdist.win-amd64' does not exist -- can't clean it\r\n" > !! TEST !! : b"'build\\scripts-3.6' does not exist -- can't clean it\r\n" > !! TEST !! : b'' > Failed to build wrapt > Installing collected packages: wrapt > Running setup.py install for wrapt ... !! TEST !! : b'running install\r\n' > -!! TEST !! : b'running build\r\n' > !! TEST !! : b'running build_py\r\n' > !! TEST !! : b'creating build\r\n' > !! TEST !! : b'creating build\\lib.win-amd64-3.6\r\n' > !! TEST !! : b'creating build\\lib.win-amd64-3.6\\wrapt\r\n' > !! TEST !! : b'copying src\\wrapt\\arguments.py -> build\\lib.win-amd64-3.6\\wrapt\r\n' > !! TEST !! : b'copying src\\wrapt\\decorators.py -> build\\lib.win-amd64-3.6\\wrapt\r\n' > !! TEST !! : b'copying src\\wrapt\\importer.py -> build\\lib.win-amd64-3.6\\wrapt\r\n' > !! TEST !! : b'copying src\\wrapt\\wrappers.py -> build\\lib.win-amd64-3.6\\wrapt\r\n' > !! TEST !! : b'copying src\\wrapt\\__init__.py -> build\\lib.win-amd64-3.6\\wrapt\r\n' > !! TEST !! : b'running build_ext\r\n' > !! TEST !! : b"building 'wrapt._wrappers' extension\r\n" > !! TEST !! : b'creating build\\temp.win-amd64-3.6\r\n' > \!! TEST !! : b'creating build\\temp.win-amd64-3.6\\Release\r\n' > !! TEST !! : b'creating build\\temp.win-amd64-3.6\\Release\\src\r\n' > !! TEST !! : b'creating build\\temp.win-amd64-3.6\\Release\\src\\wrapt\r\n' > !! TEST !! : b'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.11.25503\\bin\\HostX86\\x64\\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\\Users\\(...)\\AppData\\Local\\Programs\\Python\\Python36\\include -IC:\\Users\\(...)\\AppData\\Local\\Programs\\Python\\Python36\\include "-IC:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.11.25503\\ATLMFC\\include" "-IC:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.11.25503\\include" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.16299.0\\ucrt" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.16299.0\\shared" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.16299.0\\um" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.16299.0\\winrt" /Tcsrc/wrapt/_wrappers.c /Fobuild\\temp.win-amd64-3.6\\Release\\src/wrapt/_wrappers.obj\r\n' > !! TEST !! : b'_wrappers.c\r\n' > !! TEST !! : b"src/wrapt/_wrappers.c(195): warning C4244: 'return'\xff: conversion de 'Py_hash_t' en 'long', perte possible de donn\x82es\r\n" > error > Exception: > Traceback (most recent call last): > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\compat\__init__.py", line 74, in console_to_str > return s.decode(sys.__stdout__.encoding) > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: invalid start byte > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\basecommand.py", line 215, in main > status = self.run(options, args) > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\commands\install.py", line 342, in run > prefix=options.prefix_path, > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\req\req_set.py", line 784, in install > **kwargs > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\req\req_install.py", line 878, in install > spinner=spinner, > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess > line = console_to_str(proc.stdout.readline()) > File "C:\Users\(...)\AppData\Local\Programs\Python\Python36\Lib\site-packages\pip\compat\__init__.py", line 76, in console_to_str > return s.decode('utf_8') > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: invalid start byte > The program exited via sys.exit(). Exit status: 2 >> c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages\pip\__main__.py(1)() > -> from __future__ import absolute_import Apparently _wrappers.c is compiled with MSVC but the Python script managing the installation can't handle a warning from MSVC containing a special character. _wrappers.c is deleted right after the installation fails so I can't look into it. Also wrapt's setup.py doesn't recognize the command "bdist_wheel" ... I can't go much further than that. From pkpearson at nowhere.invalid Sat Dec 16 17:40:45 2017 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 16 Dec 2017 22:40:45 GMT Subject: Repeated Names (Repeated Names) References: Message-ID: On Sat, 16 Dec 2017 12:56:07 +1300, Gregory Ewing wrote: > Anyone else now getting duplicate posts with the sender's > name repeated in parentheses? Yes. Both of the posts on this thread appear twice, once with and once without the parenthesized name. In each pair, the Date field differed by one second, once in each direction. -- To email me, substitute nowhere->runbox, invalid->com. From BILL_NOSPAM at Noway.net Sat Dec 16 18:25:52 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sat, 16 Dec 2017 18:25:52 -0500 Subject: Python Learning In-Reply-To: <268249281@f38.n261.z1.binkp.net> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Rustom Mody (Rustom Mody) wrote: > On Saturday, December 16, 2017 at 9:45:17 AM UTC+5:30, Bill wrote: >> Chris Angelico wrote: >>> On Sat, Dec 16, 2017 at 8:51 AM, Bill wrote: >>>> Varun R wrote: >>>>> Hi All, >>>>> >>>>> I'm new to programming, can anyone guide me, how to start learning python >>>>> programming language,...plz suggest some books also. >>>>> >>>>> Thanks all >>>> Are you sure you want to learn Python first? >>>> Python does enough things "behind the scene" >>>> that it makes me question the wisdom of that. >>>> Other points of view are welcome, of course. >>>> Learning the primitives of C++ first, may make for an easier transition. >>>> Surely this has been discussed before? >>> On the contrary, that makes Python an *excellent* first language. We >>> don't force people to learn about the chemistry of petrochemical >>> combustion before letting them learn how to drive a car; we don't make >>> people understand TCP/IP networking before they're allowed to type >>> something into Google. And if you DO want people to start off with a >>> lower-level language, why C++? Why not machine code (or at least >>> assembly code), since that's what the CPU actually executes? >> Most decent introductions to C++ discuss machine language (it helps make >> sense of compilation). >> As you indirectly suggest, learning is something of a circular process, >> so it really doesn't make that much difference where one starts, just >> "Do It!". : ) > Really??? > https://en.wikipedia.org/wiki/Principles_of_learning#Primacy > You would give precedence to something written on a wikipedia page over your experience? In our current context, we are talking about self-learning where one is one's own teacher. To my mind, if one gets that part right, one doesn't need to worry about the other types. I learned a great deal from BYTE magazine and before that Popular Electronics. Computer technology is so ubiquitous today, that the interested person one need only grab hold of something and start learning. YouTube for instance, offers a plethora of places to "begin". I tell students, that if they have the math behind them, then the doors of science will be open to them. In my experience, if they do not have the basic (~pre-calc) math behind them, then learning from a textbook on a programming language, say, may be a bit beyond them. From greg.ewing at canterbury.ac.nz Sat Dec 16 18:41:50 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 17 Dec 2017 12:41:50 +1300 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Bill wrote: > In my experience, > if they do not have the basic (~pre-calc) math behind them, then > learning from a textbook on a programming language, say, may be a bit > beyond them. Very little mathematical *knowledge* is needed to get started with programming. You can do a lot of useful things in Python without even using any arithmetic. What does seem to correlate is that if you're the sort of person who finds maths interesting and fun to play with, you're also likely to take to programming easily. The same kind of logical thought processes are involved. -- Greg From greg.ewing at canterbury.ac.nz Sat Dec 16 19:10:37 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 17 Dec 2017 13:10:37 +1300 Subject: Repeated Names (Repeated Names) In-Reply-To: References: Message-ID: The duplicate posts all seem to have this header: Injection-Info: news.bbs.geek.nz; posting-host="M6YmRdZYyc42DJk0lNlt/X4dpP4dzvceBNabSmESN3E"; logging-data="4415"; mail-complaints-to="abuse at news.bbs.geek.nz" I've emailed the administrator of bbs.geek.nz, maybe he will be able to stop it. -- Greg From BILL_NOSPAM at Noway.net Sat Dec 16 20:01:51 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sat, 16 Dec 2017 20:01:51 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Gregory Ewing wrote: > Bill wrote: >> In my experience, if they do not have the basic (~pre-calc) math >> behind them, then learning from a textbook on a programming language, >> say, may be a bit beyond them. > > Very little mathematical *knowledge* is needed to get started > with programming. You can do a lot of useful things in Python > without even using any arithmetic. > > What does seem to correlate is that if you're the sort of > person who finds maths interesting and fun to play with, you're > also likely to take to programming easily. The same kind of > logical thought processes are involved. > I think we are talking about the same people. But in college, the prerequisite of "at least co-enrolled in pre-calc", turned out to be the right one (based upon quite a lot of teaching experience). From rosuav at gmail.com Sat Dec 16 21:13:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Dec 2017 13:13:55 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Sun, Dec 17, 2017 at 12:01 PM, Bill wrote: > Gregory Ewing wrote: >> >> Bill wrote: >>> >>> In my experience, if they do not have the basic (~pre-calc) math behind >>> them, then learning from a textbook on a programming language, say, may be >>> a bit beyond them. >> >> >> Very little mathematical *knowledge* is needed to get started >> with programming. You can do a lot of useful things in Python >> without even using any arithmetic. >> >> What does seem to correlate is that if you're the sort of >> person who finds maths interesting and fun to play with, you're >> also likely to take to programming easily. The same kind of >> logical thought processes are involved. >> > > I think we are talking about the same people. > But in college, the prerequisite of "at least co-enrolled in pre-calc", > turned out to be the right one (based upon quite a lot of teaching > experience). Fortunately for the programming world, college isn't when everyone starts. I started coding at six years old. Should I have waited till I had some pre-calc before getting into programming? ChrisA From spluque at gmail.com Sat Dec 16 22:40:43 2017 From: spluque at gmail.com (Seb) Date: Sat, 16 Dec 2017 21:40:43 -0600 Subject: argparse.ArgumentParser formatter_class argument Message-ID: <87tvwqkon8.fsf@otaria.sebmel.org> Hello, As far as I can see it is currently impossible to apply more than one class to an ArgumentParser. For example, I'd like to use both RawDescriptionHelpFormatter *and* ArgumentDefaultsHelpFormatter in an ArgumentParser, but it seems that's impossible, as one can only choose a single one. Any suggestions? -- Seb From bazthelinuxguy at gmail.com Sun Dec 17 00:00:55 2017 From: bazthelinuxguy at gmail.com (Bryan Zimmer) Date: Sat, 16 Dec 2017 23:00:55 -0600 Subject: pip failed installs Message-ID: I believe it's because you're installing that into a directory that the current user has no write privileges for. Try installing those into a virtual environment (if you don't know what that is, let us know!). -Jorge On Sat, Dec 16, 2017 at 1:27 PM, Bryan Zimmer wrote: I have had only partial success with pip. Some things seem to install OK. But I've tried a couple of packages, specifically "BeautifulSoup" and "WxPython", and they fail with the same message, e.g.: *Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ku98d6jd/BeautifulSoup/* Thanks for the reply. I have taken to performing pip installs as root (on Slackware Linux), precisely because my regular user (baz) does not have the permissions necessary to install most software. So root, when performing a pip install, also gets error 1 when trying to install packages. I did follow your advice and set up a virtual environment using python3.6's *venv *module. According to the documentation, installations would go into the virtual environment if it is activated at install-time. But I got the same error. This time it took the following form: *Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-zhuoo23l/BeautifulSoup/* Permissions on the /tmp directory are 1777, or read-write-execute allowed for everybody, plus it is a sticky directory (which shouldn't be important here). From bazthelinuxguy at gmail.com Sun Dec 17 00:11:08 2017 From: bazthelinuxguy at gmail.com (Bryan Zimmer) Date: Sat, 16 Dec 2017 23:11:08 -0600 Subject: pip failed installs Message-ID: Wait! Cancel my last post! In exploring the virtual environment, I was struck by the existence of an executable *pip *in the virtual environment's "bin" directory. So I tried again to install BeautifulSoup, but this time I got a very different error message. This pip couldn't find BeautifulSoup, unlike the module I had been using. (My python3.6 installation does not include a command-line executable pip). So I reissued the command, this time giving it the name of the module,"bs4". And this time, pip found and installed beautifulsoup (note the lowercasing) into my virtual environment! Thanks for your help. From BILL_NOSPAM at Noway.net Sun Dec 17 00:42:51 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 00:42:51 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > On Sun, Dec 17, 2017 at 12:01 PM, Bill wrote: >> >> I think we are talking about the same people. >> But in college, the prerequisite of "at least co-enrolled in pre-calc", >> turned out to be the right one (based upon quite a lot of teaching >> experience). > Fortunately for the programming world, college isn't when everyone > starts. I started coding at six years old. Should I have waited till I > had some pre-calc before getting into programming? It probably wouldn't have hurt if you had co-enrolled in it. ;) And add an English course too to help you to write suitable documentation! I would think a 6 year old would have priorities above coding--what's the hurry? Bill > > ChrisA From mail at timgolden.me.uk Sun Dec 17 01:38:57 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 17 Dec 2017 06:38:57 +0000 Subject: Repeated Names (Repeated Names) In-Reply-To: References: Message-ID: <1187264d-0906-7d76-1efd-13bb839e4ffc@timgolden.me.uk> On 17/12/17 00:10, Gregory Ewing wrote: > The duplicate posts all seem to have this header: > > Injection-Info: news.bbs.geek.nz; > posting-host="M6YmRdZYyc42DJk0lNlt/X4dpP4dzvceBNabSmESN3E"; > ????logging-data="4415"; mail-complaints-to="abuse at news.bbs.geek.nz" > > I've emailed the administrator of bbs.geek.nz, maybe he > will be able to stop it. > Thanks, Greg. We're actually blocking via that and related headers at the gateway, which is why the mailing list is no longer seeing the duplicates. I'm not sure any of us thought to email the news server admin, though! TJG From arj.python at gmail.com Sun Dec 17 01:41:55 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 17 Dec 2017 10:41:55 +0400 Subject: Python Templating Language Message-ID: Hi all, Can somebody point out to me some py-based template languages interpreters resources? Thank you ! From info at tundraware.com Sun Dec 17 02:39:53 2017 From: info at tundraware.com (Tim Daneliuk) Date: Sun, 17 Dec 2017 01:39:53 -0600 Subject: Python Templating Language In-Reply-To: References: Message-ID: <9jjhge-oem.ln1@oceanview.tundraware.com> On 12/17/2017 12:41 AM, Abdur-Rahmaan Janhangeer wrote: > Hi all, > > Can somebody point out to me some py-based template languages interpreters > resources? > > Thank you ! > http://jinja.pocoo.org/ From brian.j.oney at googlemail.com Sun Dec 17 02:42:16 2017 From: brian.j.oney at googlemail.com (Brian J. Oney) Date: Sun, 17 Dec 2017 07:42:16 +0000 Subject: Python Templating Language In-Reply-To: References: Message-ID: I am not exactly sure what you mean, so I will guess. Jinja may be what you're looking for. It's an important component of flask & ansible, for example. pyweave may also serve your purposes. HTH From __peter__ at web.de Sun Dec 17 04:12:07 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Dec 2017 10:12:07 +0100 Subject: argparse.ArgumentParser formatter_class argument References: <87tvwqkon8.fsf@otaria.sebmel.org> Message-ID: Seb wrote: > As far as I can see it is currently impossible to apply more than one > class to an ArgumentParser. For example, I'd like to use both > RawDescriptionHelpFormatter *and* ArgumentDefaultsHelpFormatter in an > ArgumentParser, but it seems that's impossible, as one can only choose a > single one. Any suggestions? Try class MyHelpFormatter( argparse.RawDescriptionHelpFormatter, argparse.ArgumentDefaultsHelpFormatter ): pass parser = argparse.ArgumentParser(formatter_class=MyHelpFormatter) If there are any conflicts you have to write more code... From alister.ware at ntlworld.com Sun Dec 17 05:36:46 2017 From: alister.ware at ntlworld.com (alister) Date: Sun, 17 Dec 2017 10:36:46 GMT Subject: Python Learning References: <903158165@f38.n261.z1.binkp.net> <834239212@f38.n261.z1.binkp.net> Message-ID: <2NrZB.9238$uS5.2408@fx45.am4> On Sat, 16 Dec 2017 14:41:00 +1200, Marko Rauhamaa wrote: > ram at zedat.fu-berlin.de (Stefan Ram): > >> Varun R writes: >>>I'm new to programming, can anyone guide me, how to start learning >>>python programming language >> >> As a start, one should learn: >> >> 1.) how to install Python >> (if not already installed) >> >> 2.) how to start the Python console >> (if not already started) >> >> 3.) how to type characters into a line of the >> console and how to submit the line (using the Enter key) (if >> this is not already known) > > A good list. Even more important, though, is the installation, use and > understanding of a text editor. What is the difference of MS Word, > Notepad and a Python-aware text editor? What text editors are there? > What is a newline? What is whitespace? (Advanced: what is a TAB.) What > is the difference between lower case and upper case? What is trailing > whitespace? What is an underscore? > What is the difference between a parenthesis, bracket and a brace? > > What is a file? What is a filename? What is a directory/folder? What is > a pathname? What is a terminal (emulator)? What is standard input? What > is standard output? > > How do I see the listing of files? How do I erase a file? How do I > rename a file? What is the current working directory? How do I change it > and why? > > > Marko you seem to be moving more into knowledge about the operating system rather than programming itself. Still a good pre-requisite you cannot hope to successfully program a system you do no know how to use -- Mr Young hadn't had to quiet a screaming baby for years. He'd never been much good at it to start with. He'd always respected Sir Winston Churchill, and patting small versions of him on the bottom had always seemed ungracious. -- (Terry Pratchett & Neil Gaiman, Good Omens) From jon+usenet at unequivocal.eu Sun Dec 17 08:22:03 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 17 Dec 2017 13:22:03 -0000 (UTC) Subject: Repeated Names (Repeated Names) References: <1187264d-0906-7d76-1efd-13bb839e4ffc@timgolden.me.uk> Message-ID: On 2017-12-17, Tim Golden wrote: > On 17/12/17 00:10, Gregory Ewing wrote: >> The duplicate posts all seem to have this header: >> >> Injection-Info: news.bbs.geek.nz; >> posting-host="M6YmRdZYyc42DJk0lNlt/X4dpP4dzvceBNabSmESN3E"; >> ????logging-data="4415"; mail-complaints-to="abuse at news.bbs.geek.nz" >> >> I've emailed the administrator of bbs.geek.nz, maybe he >> will be able to stop it. > > Thanks, Greg. We're actually blocking via that and related headers at > the gateway, which is why the mailing list is no longer seeing the > duplicates. I'm not sure any of us thought to email the news server > admin, though! I did; the address is fake. From rustompmody at gmail.com Sun Dec 17 08:52:27 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Dec 2017 05:52:27 -0800 (PST) Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: In response to > Rustom Mody wrote: >> On Saturday, December 16, 2017 at 9:45:17 AM UTC+5:30, Bill wrote: >>> so it really doesn't make that much difference where one starts, just >>> "Do It!". : ) >> Really ?? >> https://en.wikipedia.org/wiki/Principles_of_learning#Primacy On Sunday, December 17, 2017 Bill wrote: > You would give precedence to something written on a wikipedia page over > your experience? Bill also wrote: > ?in college, the prerequisite of "at least co-enrolled in pre-calc", > turned out to be the right one (based upon quite a lot of teaching > experience). So? I dont understand where you are coming from: Is there such a thing as a ?learning curve? or not? From rustompmody at gmail.com Sun Dec 17 08:54:50 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Dec 2017 05:54:50 -0800 (PST) Subject: Python Learning (Posting On Python-List Prohibited) In-Reply-To: References: <87r2ru6e1u.fsf@elektro.pacujo.net> <87mv2i6bya.fsf@elektro.pacujo.net> Message-ID: <927fb53a-adb6-405e-9758-ed7e0cf59eb2@googlegroups.com> On Sunday, December 17, 2017 at 6:39:41 AM UTC+5:30, Lawrence D?Oliveiro wrote: > On Sunday, December 17, 2017 at 2:26:43 AM UTC+13, Marko Rauhamaa wrote: > > > Unfortunately, Python's indentation mechanism makes the REPL too > > frustrating an environment to type in even the simplest of function > > definitions, let alone a whole class. > > Let me suggest using a Jupyter notebook as an introductory program editor. Um? Well? At first I did not take jupyter seriously ?browser is the universal OS??? Sounds like the usual empty fluff But now seeing things like this: http://www.leouieda.com/blog/scipy-on-android.html I guess I am going to be force From rustompmody at gmail.com Sun Dec 17 09:02:38 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Dec 2017 06:02:38 -0800 (PST) Subject: Python Learning In-Reply-To: <87r2ru6e1u.fsf@elektro.pacujo.net> References: <87r2ru6e1u.fsf@elektro.pacujo.net> Message-ID: On Saturday, December 16, 2017 at 6:11:31 PM UTC+5:30, Marko Rauhamaa wrote: > Stefan Ram: > > > Varun R writes: > >>I'm new to programming, can anyone guide me, how to start > >>learning python programming language > > > > As a start, one should learn: > > > > 1.) how to install Python > > (if not already installed) > > > > 2.) how to start the Python console > > (if not already started) > > > > 3.) how to type characters into a line of the > > console and how to submit the line (using > > the Enter key) (if this is not already known) > > A good list. Even more important, though, is the installation, use and > understanding of a text editor. What is the difference of MS Word, > Notepad and a Python-aware text editor? This is a useful 3-way classification Just now dealing with a class in which students write python resolutely - using gedit - on linux VMs - on Windows hosts So I wonder where on the spectrum MS Word ? notepad ? Programmer?s editor would you place gedit?? [If you know what that is ] > What text editors are there? Seriously?!? Does that list ever end? From mail at timgolden.me.uk Sun Dec 17 09:10:01 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 17 Dec 2017 14:10:01 +0000 Subject: Repeated Names (Repeated Names) In-Reply-To: References: <1187264d-0906-7d76-1efd-13bb839e4ffc@timgolden.me.uk> Message-ID: <9ffd7ee9-2c27-e00d-c004-77bf5545f208@timgolden.me.uk> On 17/12/2017 13:22, Jon Ribbens wrote: > On 2017-12-17, Tim Golden wrote: >> On 17/12/17 00:10, Gregory Ewing wrote: >>> The duplicate posts all seem to have this header: >>> >>> Injection-Info: news.bbs.geek.nz; >>> posting-host="M6YmRdZYyc42DJk0lNlt/X4dpP4dzvceBNabSmESN3E"; >>> ????logging-data="4415"; mail-complaints-to="abuse at news.bbs.geek.nz" >>> >>> I've emailed the administrator of bbs.geek.nz, maybe he >>> will be able to stop it. >> Thanks, Greg. We're actually blocking via that and related headers at >> the gateway, which is why the mailing list is no longer seeing the >> duplicates. I'm not sure any of us thought to email the news server >> admin, though! > I did; the address is fake. Thanks, Jon. Looks like there's nothing for us to do on the mailing list but keep blocking, then! TJG From skip.montanaro at gmail.com Sun Dec 17 09:30:20 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 17 Dec 2017 08:30:20 -0600 Subject: Repeated Names (Repeated Names) In-Reply-To: References: <1187264d-0906-7d76-1efd-13bb839e4ffc@timgolden.me.uk> Message-ID: >> I've emailed the administrator of bbs.geek.nz, maybe he >> will be able to stop it. > > Thanks, Greg. We're actually blocking via that and related headers at > the gateway, which is why the mailing list is no longer seeing the > duplicates. I'm not sure any of us thought to email the news server > admin, though! I did; the address is fake. Worked for me. From the URL http://news.bbs.geek.nz/ *Welcome to Agency News - a Usenet News system located in Dunedin, New Zealand.* *...* *Agency News is run as a not-for-profit hobby and offers free access to text-only Usenet News* *...* *Contact - newsmaster {at} news.bbs.geek.nz to obtain a username / password.* I just sent a note to that email address. No bounce yet. Skip From pengyu.ut at gmail.com Sun Dec 17 10:29:47 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 17 Dec 2017 09:29:47 -0600 Subject: What is wrong with this regex for matching emails? Message-ID: Hi, I would like to extract "abc at efg.hij.xyz". But it only shows ".hij". Does anybody see what is wrong with it? Thanks. $ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: import re email_regex = re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)') s = 'abc at efg.hij.xyz.' for email in re.findall(email_regex, s): print email $ ./main.py .hij -- Regards, Peng From rosuav at gmail.com Sun Dec 17 10:46:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 02:46:55 +1100 Subject: What is wrong with this regex for matching emails? In-Reply-To: References: Message-ID: On Mon, Dec 18, 2017 at 2:29 AM, Peng Yu wrote: > Hi, > > I would like to extract "abc at efg.hij.xyz". But it only shows ".hij". > Does anybody see what is wrong with it? Thanks. > > $ cat main.py > #!/usr/bin/env python > # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: > > import re > email_regex = re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)') > s = 'abc at efg.hij.xyz.' > for email in re.findall(email_regex, s): > print email > > $ ./main.py > .hij What is the goal of your email address extraction? There are two goals, one of which cannot be done perfectly but doesn't need to, and the other cannot be done perfectly and is thus virtually useless. If you want to detect email addresses in text and turn them into mailto: links, it's okay to miss out some edge cases, and for that, I would recommend keeping your regex REALLY simple - something like you have above, but maybe even simpler. (And I wouldn't have the parentheses in there, which I think might be what you're getting tripped up on.) But if you're trying to *validate* an email address - for instance, if you receive a form submission and want to know if there was an email address included - then my recommendation is simply DON'T. You can't get all the edge cases right; it is actually impossible for a regex to perfectly match every valid email address and no invalid addresses. And that's only counting *syntactically* valid - it doesn't take into account the fact that "blah at junk.example.com" is not going to get anywhere. So if you're trying to do validation, basically just don't. ChrisA From ned at nedbatchelder.com Sun Dec 17 12:01:14 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 17 Dec 2017 12:01:14 -0500 Subject: What is wrong with this regex for matching emails? In-Reply-To: References: Message-ID: <39ea2268-3435-3057-0e2a-2f505b722ba9@nedbatchelder.com> On 12/17/17 10:29 AM, Peng Yu wrote: > Hi, > > I would like to extract "abc at efg.hij.xyz". But it only shows ".hij". > Does anybody see what is wrong with it? Thanks. > > $ cat main.py > #!/usr/bin/env python > # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: > > import re > email_regex = re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)') > s = 'abc at efg.hij.xyz.' > for email in re.findall(email_regex, s): > print email > > $ ./main.py > .hij > There are two problems: you have a group at the end to match .something, but you need to make that 1-or-more of those, with a +. Second, re.findall will only return the matched groups, so you need to change your final group to be a non-capturing group, with (?:...) ??? email_regex = re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+') --Ned. From spluque at gmail.com Sun Dec 17 13:27:16 2017 From: spluque at gmail.com (Seb) Date: Sun, 17 Dec 2017 12:27:16 -0600 Subject: argparse.ArgumentParser formatter_class argument References: <87tvwqkon8.fsf@otaria.sebmel.org> Message-ID: <87h8spky63.fsf@otaria.sebmel.org> On Sun, 17 Dec 2017 10:12:07 +0100, Peter Otten <__peter__ at web.de> wrote: > Seb wrote: >> As far as I can see it is currently impossible to apply more than one >> class to an ArgumentParser. For example, I'd like to use both >> RawDescriptionHelpFormatter *and* ArgumentDefaultsHelpFormatter in an >> ArgumentParser, but it seems that's impossible, as one can only >> choose a single one. Any suggestions? > Try > class MyHelpFormatter( argparse.RawDescriptionHelpFormatter, > argparse.ArgumentDefaultsHelpFormatter ): pass > parser = argparse.ArgumentParser(formatter_class=MyHelpFormatter) Yes, that worked. Thanks, -- Seb From 114piyush at gmail.com Sun Dec 17 14:28:13 2017 From: 114piyush at gmail.com (Piyush Verma) Date: Mon, 18 Dec 2017 00:58:13 +0530 Subject: ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol In-Reply-To: <87po7fgjnl.fsf@handshake.de> References: <87po7fgjnl.fsf@handshake.de> Message-ID: Yes Dieter, I see that it is connecting with 443 port number and service is running. Is this related to python version or mac? Regards, ~Piyush Facebook Twitter On Sat, Dec 16, 2017 at 1:59 PM, dieter wrote: > Piyush Verma <114piyush at gmail.com> writes: > > > Getting SSL error while connecting from httplib.HTTPSConnection. > > > > Any help would be appreciated. > > ... > > line 579, in __init__ > > self.do_handshake() > > File > > "/System/Library/Frameworks/Python.framework/Versions/2.7/ > lib/python2.7/ssl.py", > > line 808, in do_handshake > > self._sslobj.do_handshake() > > ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590) > > Are you sure, you try to connect to an HTTPS port? > > The error message tells you that the "ssl" handshake failed because > the protocol was unknown (likely because the message was not understood). > The most natural reason is to try to connect to something which is not > prepared for an "ssl" handshake. > > -- > https://mail.python.org/mailman/listinfo/python-list > From BILL_NOSPAM at Noway.net Sun Dec 17 14:51:38 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 14:51:38 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Rustom Mody wrote: > In response to > >> Rustom Mody wrote: >>> On Saturday, December 16, 2017 at 9:45:17 AM UTC+5:30, Bill wrote: >>>> so it really doesn't make that much difference where one starts, just >>>> "Do It!". : ) >>> Really ?? >>> https://en.wikipedia.org/wiki/Principles_of_learning#Primacy > > On Sunday, December 17, 2017 Bill wrote: >> You would give precedence to something written on a wikipedia page over >> your experience? > Bill also wrote: >> ?in college, the prerequisite of "at least co-enrolled in pre-calc", >> turned out to be the right one (based upon quite a lot of teaching >> experience). > So? I dont understand where you are coming from: > Is there such a thing as a ?learning curve? or not? The point is that it takes a certain amount of what is referred to as "mathematical maturity" (not mathematical knowledge) to digest a book concerning computer programming. In my years of teaching experience, students who came to college without the equivalent of "college algebra" were under-prepared for what was expected of them. This is not just an opinion, it's a fact. Of course, you could argue that a student who arrives at college needing to take college algebra is of a certain category. In your words, they are not yet ready to face any sort of (steep) learning curve. Bill From ben+python at benfinney.id.au Sun Dec 17 15:57:27 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 18 Dec 2017 07:57:27 +1100 Subject: What is wrong with this regex for matching emails? References: Message-ID: <85mv2hnkco.fsf@benfinney.id.au> Peng Yu writes: > Hi, > > I would like to extract "abc at efg.hij.xyz". But it only shows ".hij". Others have address this question. I'll answer a separate one: > Does anybody see what is wrong with it? Thanks. One thing that's wrong with it is that it is far too restrictive. > email_regex = re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)') This excludes a great many email addresses that are valid. Please don't try to restrict a match for email addresses that will exclude actual email addresses. For an authoritative guide to matching email addresses, see RFC 3696 ?3 . A more correct match would boil down to: * Match any printable Unicode characters (not just ASCII). * Locate the *last* ?@? character. (An email address may contain more than one ?@? character; you should allow any printable ASCII character in the local part.) * Match the domain part as the text after the last ?@? character. Match the local part as anything before that character. Reject an address that has either of these empty. * Validate the domain by DNS request. Your program is not an authority for what domains are valid; the only authority for that is the DNS. * Don't validate the local part at all. Your program is not an authority for what local parts are accepted to the destination host; the only authority for that is the destination mail host. -- \ ?Jealousy: The theory that some other fellow has just as little | `\ taste.? ?Henry L. Mencken | _o__) | Ben Finney From dieter at handshake.de Sun Dec 17 15:59:58 2017 From: dieter at handshake.de (dieter) Date: Sun, 17 Dec 2017 21:59:58 +0100 Subject: ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol References: <87po7fgjnl.fsf@handshake.de> Message-ID: <87a7yh83zl.fsf@handshake.de> Piyush Verma <114piyush at gmail.com> writes: > Yes Dieter, I see that it is connecting with 443 port number and service is > running. Is this related to python version or mac? It might be. Python does not perform the SSL handling itself but delegates it to an external SSL library ("OpenSSL" on a *nix like platform). SSL can use different protocols, e.g. for the encryption. The error message might mean that the server side uses a protocol which is not supported by the client side. In this case, you would need to use a more up-to-date SSL library. I have had no problems to acces "https://www.facebook.com/piyushkv1" with "urllib2.urlopen" of Python 2.7.12 (on Ubuntu 16.4). From rosuav at gmail.com Sun Dec 17 16:18:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 08:18:02 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Mon, Dec 18, 2017 at 6:51 AM, Bill wrote: > The point is that it takes a certain amount of what is referred to as > "mathematical maturity" (not mathematical knowledge) to digest a book > concerning computer programming. Emphasis on *a book*. > In my years of teaching experience, > students who came to college without the equivalent of "college algebra" > were under-prepared for what was expected of them. This is not just an > opinion, it's a fact. So, your experience is that the style of learning you offer is unsuitable to anyone who doesn't have some background in algebra. That's fine. For your course, you set the prereqs. But that's not the only way for someone to get into coding. You do NOT have to go to college before you start creating software. That is also not an opinion; it's a fact backed by a number of proven instances (myself included). ChrisA From rosuav at gmail.com Sun Dec 17 16:19:07 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 08:19:07 +1100 Subject: ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol In-Reply-To: References: <87po7fgjnl.fsf@handshake.de> Message-ID: On Mon, Dec 18, 2017 at 6:28 AM, Piyush Verma <114piyush at gmail.com> wrote: > Yes Dieter, I see that it is connecting with 443 port number and service is > running. Is this related to python version or mac? Can you confirm that it really is an HTTPS server, not just an HTTP server that's running on port 443? Try accessing it using a web browser or some other program. ChrisA From larry.martell at gmail.com Sun Dec 17 16:23:16 2017 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 17 Dec 2017 16:23:16 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Sun, Dec 17, 2017 at 4:18 PM, Chris Angelico wrote: > On Mon, Dec 18, 2017 at 6:51 AM, Bill wrote: >> The point is that it takes a certain amount of what is referred to as >> "mathematical maturity" (not mathematical knowledge) to digest a book >> concerning computer programming. > > Emphasis on *a book*. > >> In my years of teaching experience, >> students who came to college without the equivalent of "college algebra" >> were under-prepared for what was expected of them. This is not just an >> opinion, it's a fact. > > So, your experience is that the style of learning you offer is > unsuitable to anyone who doesn't have some background in algebra. > That's fine. For your course, you set the prereqs. But that's not the > only way for someone to get into coding. You do NOT have to go to > college before you start creating software. That is also not an > opinion; it's a fact backed by a number of proven instances (myself > included). I started coding when I was 16, in 1975. I wrote a downhill skiing game in basic, which I had taught to myself. I went to collage when I was 17, and I had taught myself FORTRAN and I tested out of the class. From greg.ewing at canterbury.ac.nz Sun Dec 17 17:08:26 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 18 Dec 2017 11:08:26 +1300 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Bill wrote: > In my years of teaching experience, > students who came to college without the equivalent of "college algebra" > were under-prepared for what was expected of them. This could be simply because it weeds out people who aren't good at the required style of thinking. If that's true, anything that exercises mathematical thinking should have the same effect. There just doesn't happen to be anything else in the mainstream education curriculum that does that. -- Greg From greg.ewing at canterbury.ac.nz Sun Dec 17 17:16:16 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 18 Dec 2017 11:16:16 +1300 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > You do NOT have to go to > college before you start creating software. That is also not an > opinion; it's a fact backed by a number of proven instances (myself > included). Me, too. I started programming (a tiny homebrew machine) when I was about 12 or 13. I was just starting to get exposed to algebra at school then. -- Greg From marko at pacujo.net Sun Dec 17 17:33:45 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Dec 2017 00:33:45 +0200 Subject: Python Learning References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: <87vah53rxy.fsf@elektro.pacujo.net> Gregory Ewing : > Chris Angelico wrote: >> You do NOT have to go to college before you start creating software. >> That is also not an opinion; it's a fact backed by a number of proven >> instances (myself included). > > Me, too. I started programming (a tiny homebrew machine) when I was > about 12 or 13. I was just starting to get exposed to algebra at > school then. I thought I had programming covered when I entered college. I wondered if I'd be wasting my time and just collecting my diploma. However, after every year I realized I hadn't understood anything the year before. There was just such a wealth of understanding I never would have been able to come up with on my own. Then I graduated and joined the workforce. Since then, I have learned a thing or two, but I learned more during my first year in college than I have during the 25 since I left. What's more, everything I learned in college has been priceless in practical day-to-day work. Marko From rosuav at gmail.com Sun Dec 17 18:57:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 10:57:29 +1100 Subject: Python Learning In-Reply-To: <87vah53rxy.fsf@elektro.pacujo.net> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> Message-ID: On Mon, Dec 18, 2017 at 9:33 AM, Marko Rauhamaa wrote: > Gregory Ewing : >> Chris Angelico wrote: >>> You do NOT have to go to college before you start creating software. >>> That is also not an opinion; it's a fact backed by a number of proven >>> instances (myself included). >> >> Me, too. I started programming (a tiny homebrew machine) when I was >> about 12 or 13. I was just starting to get exposed to algebra at >> school then. > > I thought I had programming covered when I entered college. I wondered > if I'd be wasting my time and just collecting my diploma. However, after > every year I realized I hadn't understood anything the year before. > There was just such a wealth of understanding I never would have been > able to come up with on my own. > > Then I graduated and joined the workforce. Since then, I have learned a > thing or two, but I learned more during my first year in college than I > have during the 25 since I left. > > What's more, everything I learned in college has been priceless in > practical day-to-day work. > Interesting. I'm not surprised that you can learn more in college than in the years *prior* to it (if you were just dabbling), but I would have expected that you learn more actually on the job. Are you seriously saying that you've been 25 years in the workforce and not learned anything new? ChrisA From BILL_NOSPAM at Noway.net Sun Dec 17 19:31:12 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 19:31:12 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Larry Martell wrote: > So, your experience is that the style of learning you offer is >> unsuitable to anyone who doesn't have some background in algebra. >> That's fine. For your course, you set the prereqs. But that's not the >> only way for someone to get into coding. You do NOT have to go to >> college before you start creating software. That is also not an >> opinion; it's a fact backed by a number of proven instances (myself >> included). You might benefit by a course in logic. I never said that was the only way to learn. I learned (BASIC) in 8th grade too. > I started coding when I was 16, in 1975. I wrote a downhill skiing > game in basic, which I had taught to myself. I went to collage when I > was 17, and I had taught myself FORTRAN and I tested out of the class. From BILL_NOSPAM at Noway.net Sun Dec 17 19:43:21 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 19:43:21 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Gregory Ewing wrote: > Bill wrote: >> In my years of teaching experience, students who came to college >> without the equivalent of "college algebra" were under-prepared for >> what was expected of them. > > This could be simply because it weeds out people who aren't > good at the required style of thinking. I think that's absolutely true. If someone gets out of high school and doesn't understand college algebra (~8th grade math), they come into a programming class with an inherent disadvantage. They "can't understand" the book, just like they "couldn't" understand their math book. > If that's true, > anything that exercises mathematical thinking should have > the same effect. There just doesn't happen to be anything > else in the mainstream education curriculum that does that. > From BILL_NOSPAM at Noway.net Sun Dec 17 19:48:39 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 19:48:39 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > On Mon, Dec 18, 2017 at 6:51 AM, Bill wrote: >> The point is that it takes a certain amount of what is referred to as >> "mathematical maturity" (not mathematical knowledge) to digest a book >> concerning computer programming. > Emphasis on *a book*. > >> In my years of teaching experience, >> students who came to college without the equivalent of "college algebra" >> were under-prepared for what was expected of them. This is not just an >> opinion, it's a fact. > So, your experience is that the style of learning you offer is > unsuitable to anyone who doesn't have some background in algebra. That's fine. For your course, you set the prereqs. I never said that they needed any knowledge of algebra. But if they don't understand the logic behind an inequality, for instance, then may run into some trouble. From rosuav at gmail.com Sun Dec 17 20:44:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 12:44:27 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Mon, Dec 18, 2017 at 11:31 AM, Bill wrote: > Larry Martell wrote: >> >> So, your experience is that the style of learning you offer is >>> >>> unsuitable to anyone who doesn't have some background in algebra. >>> That's fine. For your course, you set the prereqs. But that's not the >>> only way for someone to get into coding. You do NOT have to go to >>> college before you start creating software. That is also not an >>> opinion; it's a fact backed by a number of proven instances (myself >>> included). > > > You might benefit by a course in logic. I never said that was the only way > to learn. I learned (BASIC) in 8th grade too. > You said earlier: > In my years of teaching experience, students who came to college without > the equivalent of "college algebra" were under-prepared for what was > expected of them. This is not just an opinion, it's a fact. If you want to qualify that by saying that coming to college is not the only way to learn programming, you'd better say so, because otherwise, the tone of what you're saying says that students NEED algebra prior to learning a programming language. Logic isn't the problem here. Clarity of language is. Watch your implications if you don't want to be misunderstood. ChrisA From skip.montanaro at gmail.com Sun Dec 17 21:35:44 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 17 Dec 2017 20:35:44 -0600 Subject: Automated distribution building tools to support SpamBayes In-Reply-To: <17951cff-16de-7aa3-32ef-520867d34bc5@nedbatchelder.com> References: <17951cff-16de-7aa3-32ef-520867d34bc5@nedbatchelder.com> Message-ID: Thanks. I've had a couple references to Appveyor, so will see if I can make heads or tails of it during my Christmas-to-New Year's break. Skip On Dec 15, 2017 5:43 PM, "Ned Batchelder" wrote: > On 12/15/17 2:03 PM, Skip Montanaro wrote: > >> SpamBayes (http://www.spambayes.org/) has languished for quite awhile, >> in part because nobody is around who can put together a Windows >> installer. Unfortunately, most users are on Windows and have to work >> around problems caused by the march of time and consequent beefing up >> of Windows security. >> >> I don't do Windows, but I wonder... Can one of the various continuous >> integration tools out there be enlisted to build Windows installers? >> The SB code is written in Python, uses the Win32 extension, and is >> hosted on GitHub (https://github.com/smontanaro/spambayes), so >> something which plays nice with that environment would be a plus. I'm >> slowly gaining familiarity at work with Bamboo (very, very slowly), so >> the general idea of what CI tools can do is starting to sink in. Since >> I'm a captive Atlassian customer at work, though, I don't know what >> limitations I might encounter trying to use it in an open source >> environment. >> >> Any feedback appreciated. As this is only Python-related in the sense >> that SpamBayes is written in Python, feel free to reply off-list. >> >> Skip >> > > I use AppVeyor CI to build Windows installers for coverage.py. It's not > straightforward though, there are Powershell scripts, etc. The config file > is here: https://github.com/nedbat/coveragepy/blob/master/appveyor.yml > with other necessities in the ci folder. > > Hope that helps, > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > From BILL_NOSPAM at Noway.net Sun Dec 17 23:09:12 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 23:09:12 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > On Mon, Dec 18, 2017 at 11:31 AM, Bill wrote: >> Larry Martell wrote: >>> So, your experience is that the style of learning you offer is >>>> unsuitable to anyone who doesn't have some background in algebra. >>>> That's fine. For your course, you set the prereqs. But that's not the >>>> only way for someone to get into coding. You do NOT have to go to >>>> college before you start creating software. That is also not an >>>> opinion; it's a fact backed by a number of proven instances (myself >>>> included). >> >> You might benefit by a course in logic. I never said that was the only way >> to learn. I learned (BASIC) in 8th grade too. >> > You said earlier: > >> In my years of teaching experience, students who came to college without >> the equivalent of "college algebra" were under-prepared for what was >> expected of them. This is not just an opinion, it's a fact. > If you want to qualify that by saying that coming to college is not > the only way to learn programming, you'd better say so, because > otherwise, the tone of what you're saying says that students NEED > algebra prior to learning a programming language. I tried pretty hard not to say that. I said they needed some "mathematical sophistication"--not actual mathematics. My error was using that expression among an audience not so familiar with that terminology. That said, I think I would have a hard time explaining polymorphism and vtables to a student who had not grasped the distributive property of multiplication over addition. You can try, and let me know how it goes for you... I've been there. Bill > > Logic isn't the problem here. Clarity of language is. Watch your > implications if you don't want to be misunderstood. > > ChrisA From rosuav at gmail.com Sun Dec 17 23:17:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 15:17:18 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Mon, Dec 18, 2017 at 3:09 PM, Bill wrote: > I tried pretty hard not to say that. I said they needed some "mathematical > sophistication"--not actual mathematics. My error was using that expression > among an audience not so familiar with that terminology. That said, I think > I would have a hard time explaining polymorphism and vtables to a student > who had not grasped the distributive property of multiplication over > addition. > You can try, and let me know how it goes for you... I've been there. I don't know about vtables as needing to be in ANY programming course. They're part of a "let's dive into the internals of C++" course. You certainly don't need them to understand how things work in Python, because they don't exist; and I'm doubtful that you need to explain them even to C++ programmers. Polymorphism... actually, I could explain that to a three year old. "Eat your broccoli" "Eat your dessert" See? Polymorphism. The same operation being done to different things and having different results. ChrisA From BILL_NOSPAM at Noway.net Sun Dec 17 23:31:37 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 23:31:37 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > > I don't know about vtables as needing to be in ANY programming course. > They're part of a "let's dive into the internals of C++" course. You > certainly don't need them to understand how things work in Python, > because they don't exist; and I'm doubtful that you need to explain > them even to C++ programmers. I guess "need to" is a relative thing. You can drive a car without know how one works. You can use functions with little knowledge of a run-time stack. You can avoid recursion if you are scared of it. And you can totally avoid functions if you are scared of them. And who needs documentation...seems like a big waste of time! Programmers don't need to know how to write, do they? Ask some programmers that just taught themselves, and they will tell you! After reading, writing, and arithmetic, then perhaps programming. > > Polymorphism... actually, I could explain that to a three year old. > > "Eat your broccoli" > > "Eat your dessert" > > See? Polymorphism. The same operation being done to different things > and having different results. > > ChrisA From rosuav at gmail.com Sun Dec 17 23:49:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 15:49:55 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Mon, Dec 18, 2017 at 3:31 PM, Bill wrote: > Chris Angelico wrote: >> >> >> I don't know about vtables as needing to be in ANY programming course. >> They're part of a "let's dive into the internals of C++" course. You >> certainly don't need them to understand how things work in Python, >> because they don't exist; and I'm doubtful that you need to explain >> them even to C++ programmers. > > > I guess "need to" is a relative thing. You can drive a car without know how > one works. You can use functions with little knowledge of a run-time stack. > You can avoid recursion if you are scared of it. And you can totally avoid > functions if you are scared of them. And who needs documentation...seems > like a big waste of time! Programmers don't need to know how to write, do > they? Ask some programmers that just taught themselves, and they will tell > you! > > After reading, writing, and arithmetic, then perhaps programming. > I agree with some of that, but you then take it to absurdity. You most certainly CAN drive a car without knowing how one works; in fact, with this century's cars, I think that's very much the case. How many people REALLY know what happens when you push the accelerator pedal, and how that makes the car go faster? Originally, it would actually open a valve and allow more fuel into the engine; now, it's all managed by a computer. So how much can you really understand of how it works? You can certainly use functions without knowing details of the run-time stack, though you'll need at least SOME comprehension of it. Avoiding functions and documentation, though, now you're just being ridiculous. ChrisA From BILL_NOSPAM at Noway.net Sun Dec 17 23:54:02 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Sun, 17 Dec 2017 23:54:02 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > I don't know about vtables as needing to be in ANY programming course. > They're part of a "let's dive into the internals of C++" course. You > certainly don't need them to understand how things work in Python, > because they don't exist; and I'm doubtful that you need to explain > them even to C++ programmers. > Then how are you going to explain dynamic_cast? > Polymorphism... actually, I could explain that to a three year old. > > "Eat your broccoli" > > "Eat your dessert" > > See? Polymorphism. The same operation being done to different things > and having different results. > > ChrisA From rosuav at gmail.com Mon Dec 18 00:04:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 16:04:36 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Mon, Dec 18, 2017 at 3:54 PM, Bill wrote: > Chris Angelico wrote: >> >> I don't know about vtables as needing to be in ANY programming course. >> They're part of a "let's dive into the internals of C++" course. You >> certainly don't need them to understand how things work in Python, >> because they don't exist; and I'm doubtful that you need to explain >> them even to C++ programmers. >> > Then how are you going to explain dynamic_cast? > I wouldn't. I'd teach Python to beginning programmers. C++ is not a good first language. ChrisA From rosuav at gmail.com Mon Dec 18 00:05:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 16:05:20 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Mon, Dec 18, 2017 at 4:04 PM, Chris Angelico wrote: > On Mon, Dec 18, 2017 at 3:54 PM, Bill wrote: >> Chris Angelico wrote: >>> >>> I don't know about vtables as needing to be in ANY programming course. >>> They're part of a "let's dive into the internals of C++" course. You >>> certainly don't need them to understand how things work in Python, >>> because they don't exist; and I'm doubtful that you need to explain >>> them even to C++ programmers. >>> >> Then how are you going to explain dynamic_cast? >> > > I wouldn't. I'd teach Python to beginning programmers. C++ is not a > good first language. And even for C++ programners, you can go a pretty long way without dynamic_cast. ChrisA From BILL_NOSPAM at Noway.net Mon Dec 18 00:06:56 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Mon, 18 Dec 2017 00:06:56 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > > I agree with some of that, but you then take it to absurdity. You most > certainly CAN drive a car without knowing how one works; in fact, with > this century's cars, I think that's very much the case. How many > people REALLY know what happens when you push the accelerator pedal, > and how that makes the car go faster? Originally, it would actually > open a valve and allow more fuel into the engine; now, it's all > managed by a computer. So how much can you really understand of how it > works? You can understand the "systems" which comprise your car. Engine, Cooling, braking, transmission, exhaust, etc. And you can similarly understand the systems which comprise the workings of your computer program. As it happens, I've been studying electronics lately. In answer to your question, there is an "invisible line" between hardware and software which most people don't generally cross. As another response to your question, try to master all of the features of the emacs editor. Personally, I've never felt motivated enough to do so. > > You can certainly use functions without knowing details of the > run-time stack, though you'll need at least SOME comprehension of it. > > Avoiding functions and documentation, though, now you're just being ridiculous. > > ChrisA From auriocus at gmx.de Mon Dec 18 00:15:34 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 18 Dec 2017 06:15:34 +0100 Subject: Repeated Names (Repeated Names) In-Reply-To: References: <1187264d-0906-7d76-1efd-13bb839e4ffc@timgolden.me.uk> Message-ID: Am 17.12.17 um 15:30 schrieb Skip Montanaro: >>> I've emailed the administrator of bbs.geek.nz, maybe he >>> will be able to stop it. >> >> Thanks, Greg. We're actually blocking via that and related headers at >> the gateway, which is why the mailing list is no longer seeing the >> duplicates. I'm not sure any of us thought to email the news server >> admin, though! > > I did; the address is fake. > > > Worked for me. From the URL http://news.bbs.geek.nz/ > > *Welcome to Agency News - a Usenet News system located in Dunedin, New > Zealand.* > *...* > *Agency News is run as a not-for-profit hobby and offers free access to > text-only Usenet News* > *...* > *Contact - newsmaster {at} news.bbs.geek.nz to > obtain a username / password.* > > I just sent a note to that email address. No bounce yet. He already replied; maybe it's not going through to the list because of the blocking. Here is the post: > Apologies guys for the dupes being injected in to this newsgroup. > > I run a message network using Fido Technical Networking standards and a > single node within fsxNet (bbs.geek.nz/fsxnet.zip) that was connected to the > gateway software had seemingly sent a bunch of looped messages though the > gateway. I have closed the node access off and removed some borked packets on > my side of the gateway. > > Hopefully someone will see this reply and know I've acted as soon as I heard > from Greg. :) > > If anyone spots anything further amiss you can reach me at avon [at] bbs > [dot] geek [dot] nz > > Best, Paul Christian From BILL_NOSPAM at Noway.net Mon Dec 18 00:25:47 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Mon, 18 Dec 2017 00:25:47 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Chris Angelico wrote: > On Mon, Dec 18, 2017 at 4:04 PM, Chris Angelico wrote: >> On Mon, Dec 18, 2017 at 3:54 PM, Bill wrote: >>> Chris Angelico wrote: >>>> I don't know about vtables as needing to be in ANY programming course. >>>> They're part of a "let's dive into the internals of C++" course. You >>>> certainly don't need them to understand how things work in Python, >>>> because they don't exist; and I'm doubtful that you need to explain >>>> them even to C++ programmers. >>>> >>> Then how are you going to explain dynamic_cast? >>> >> I wouldn't. I'd teach Python to beginning programmers. C++ is not a >> good first language. > And even for C++ programners, you can go a pretty long way without dynamic_cast. You either know it exists, and what it can do for you, or you don't. If you want to teach a 2nd course in C++, and leave out vtables and dynamic_cast, I don't have a problem with that. If you always choose the lowest common denominator, your class may not be that interesting. I told my students that my goal was for them was to learn how to learn so that they "didn't need me". > > ChrisA From random832 at fastmail.com Mon Dec 18 01:43:22 2017 From: random832 at fastmail.com (Random832) Date: Mon, 18 Dec 2017 01:43:22 -0500 Subject: What is wrong with this regex for matching emails? In-Reply-To: References: Message-ID: <1513579402.896660.1208374440.26EBC426@webmail.messagingengine.com> On Sun, Dec 17, 2017, at 10:46, Chris Angelico wrote: > But if you're trying to *validate* an email address - for instance, if > you receive a form submission and want to know if there was an email > address included - then my recommendation is simply DON'T. You can't > get all the edge cases right; it is actually impossible for a regex to > perfectly match every valid email address and no invalid addresses. That's not actually true (the thing that notoriously can't be matched in a regex, RFC822 "address", is basically most of the syntax of the To: header - the part that is *the address* as we speak of it normally is "addr-spec" and is in fact a regular language, though a regex to match it goes on for a few hundred characters. The formal syntax also has some surprising corners that might not reflect real-world implementations: for example, a local-part may not begin or end with a dot or contain two dots in a row (unless quoted - the suggestion someone else made that a local-part may contain an @ sign also requires quoting). It's also unfortunate that a domain-part may not end with the dot, since this would provide a way to specify TLD- only addresses without allowing the error of mistakenly leaving the TLD off of an address. > And that's only counting *syntactically* valid - it doesn't take into > account the fact that "blah at junk.example.com" is not going to get > anywhere. So if you're trying to do validation, basically just don't. The recommendation still stands, of course - this script is probably not the place to explore these obscure corners. If the email address is important, you can send a link to it and wait for them to click it to confirm the email. If it's not, don't bother at all. From marko at pacujo.net Mon Dec 18 01:59:29 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Dec 2017 08:59:29 +0200 Subject: Python Learning References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> Message-ID: <87o9mw4j3i.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Dec 18, 2017 at 9:33 AM, Marko Rauhamaa wrote: >> Then I graduated and joined the workforce. Since then, I have learned >> a thing or two, but I learned more during my first year in college >> than I have during the 25 since I left. > > Interesting. I'm not surprised that you can learn more in college than > in the years *prior* to it (if you were just dabbling), but I would > have expected that you learn more actually on the job. Are you > seriously saying that you've been 25 years in the workforce and not > learned anything new? Let's see. What I have learned on the job is projects and processes (even though college tried to give a taste of those, as well). Then, I have gathered some encyclopedic knowledge about programming languages, libraries, frameworks and operating systems. Finally, I have developed routine. But true eye-openers took place in college: data structures, algorithms, complexity theory, parsing and compiling, recursion, object-oriented programming, logic programming, functional programming, distributed systems, cryptography, logic and formalisms, mathematical rigor etc. Marko From rosuav at gmail.com Mon Dec 18 02:01:37 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 18:01:37 +1100 Subject: What is wrong with this regex for matching emails? In-Reply-To: <1513579402.896660.1208374440.26EBC426@webmail.messagingengine.com> References: <1513579402.896660.1208374440.26EBC426@webmail.messagingengine.com> Message-ID: On Mon, Dec 18, 2017 at 5:43 PM, Random832 wrote: > On Sun, Dec 17, 2017, at 10:46, Chris Angelico wrote: >> But if you're trying to *validate* an email address - for instance, if >> you receive a form submission and want to know if there was an email >> address included - then my recommendation is simply DON'T. You can't >> get all the edge cases right; it is actually impossible for a regex to >> perfectly match every valid email address and no invalid addresses. > > That's not actually true (the thing that notoriously can't be matched in > a regex, RFC822 "address", is basically most of the syntax of the To: > header - the part that is *the address* as we speak of it normally is > "addr-spec" and is in fact a regular language, though a regex to match > it goes on for a few hundred characters. Hmm, is that true? I was under the impression that the quoting rules were impossible to match with a regex. Or maybe it's just that they're impossible to match with a *standard* regex, but the extended implementations (including Python's, possibly) are able to match them? Anyhow, it is FAR from simple; and also, for the purpose of "detect email addresses in text documents", not desirable. Same as with URL detection - it's better to have a handful of weird cases that don't autolink correctly than to mis-detect any address that's at the end of a sentence, for instance. For that purpose, it's better to ignore the RFC and just craft a regex that matches *common* email address formats. ChrisA From rosuav at gmail.com Mon Dec 18 02:09:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 18:09:13 +1100 Subject: Python Learning In-Reply-To: <87o9mw4j3i.fsf@elektro.pacujo.net> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> Message-ID: On Mon, Dec 18, 2017 at 5:59 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Dec 18, 2017 at 9:33 AM, Marko Rauhamaa wrote: >>> Then I graduated and joined the workforce. Since then, I have learned >>> a thing or two, but I learned more during my first year in college >>> than I have during the 25 since I left. >> >> Interesting. I'm not surprised that you can learn more in college than >> in the years *prior* to it (if you were just dabbling), but I would >> have expected that you learn more actually on the job. Are you >> seriously saying that you've been 25 years in the workforce and not >> learned anything new? > > Let's see. What I have learned on the job is projects and processes > (even though college tried to give a taste of those, as well). Then, I > have gathered some encyclopedic knowledge about programming languages, > libraries, frameworks and operating systems. Finally, I have developed > routine. > > But true eye-openers took place in college: data structures, algorithms, > complexity theory, parsing and compiling, recursion, object-oriented > programming, logic programming, functional programming, distributed > systems, cryptography, logic and formalisms, mathematical rigor etc. > So if you were to choose between two potential hires, one who had 25 years' experience and the other had nothing but college, which would you choose? Are you worth virtually the same salary now as you were worth straight out of college? ChrisA From 114piyush at gmail.com Mon Dec 18 04:59:08 2017 From: 114piyush at gmail.com (Piyush Verma) Date: Mon, 18 Dec 2017 15:29:08 +0530 Subject: ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol In-Reply-To: References: <87po7fgjnl.fsf@handshake.de> Message-ID: Hi Chris, Yes it is HTTPS server. I was debugging and found some relevant data which may help to identify the problem. In my Mac OS, I have two version of openssl version installed. default was /usr/bin/openssl, which i changed to brew installed one. (virtenv) $ /usr/bin/openssl version OpenSSL 0.9.8zh 14 Jan 2016 (virtenv) $ openssl version OpenSSL 1.0.2n 7 Dec 2017 In my python code when I printed the ssl version, python still taking the system installed ssl version in my Mac OS. I think same problem in my code, how can I make python to understand to take latest ssl? import ssl ssl.OPENSSL_VERSION 'OpenSSL 0.9.8zh 14 Jan 2016' Regards, ~Piyush Facebook Twitter On Mon, Dec 18, 2017 at 2:49 AM, Chris Angelico wrote: > On Mon, Dec 18, 2017 at 6:28 AM, Piyush Verma <114piyush at gmail.com> wrote: > > Yes Dieter, I see that it is connecting with 443 port number and service > is > > running. Is this related to python version or mac? > > Can you confirm that it really is an HTTPS server, not just an HTTP > server that's running on port 443? Try accessing it using a web > browser or some other program. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From jon+usenet at unequivocal.eu Mon Dec 18 06:12:17 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 18 Dec 2017 11:12:17 -0000 (UTC) Subject: Repeated Names (Repeated Names) References: <1187264d-0906-7d76-1efd-13bb839e4ffc@timgolden.me.uk> Message-ID: On 2017-12-17, Skip Montanaro wrote: >>> I've emailed the administrator of bbs.geek.nz, maybe he >>> will be able to stop it. >> >> Thanks, Greg. We're actually blocking via that and related headers at >> the gateway, which is why the mailing list is no longer seeing the >> duplicates. I'm not sure any of us thought to email the news server >> admin, though! > > I did; the address is fake. > > Worked for me. From the URL http://news.bbs.geek.nz/ ... > I just sent a note to that email address. No bounce yet. "No bounce" is not the same as "worked". You'll get a bounce message when the mail server at your end gives up some time several days in the future. Depending on how your mail server is configured, you may get a "delayed" warning some time before that. From rosuav at gmail.com Mon Dec 18 07:36:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Dec 2017 23:36:05 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: On Sun, Dec 17, 2017 at 4:42 PM, Bill wrote: > Chris Angelico wrote: >> >> On Sun, Dec 17, 2017 at 12:01 PM, Bill wrote: >>> >>> >>> I think we are talking about the same people. >>> But in college, the prerequisite of "at least co-enrolled in pre-calc", >>> turned out to be the right one (based upon quite a lot of teaching >>> experience). >> >> Fortunately for the programming world, college isn't when everyone >> starts. I started coding at six years old. Should I have waited till I >> had some pre-calc before getting into programming? > > > It probably wouldn't have hurt if you had co-enrolled in it. ;) > And add an English course too to help you to write suitable documentation! > I would think a 6 year old would have priorities above coding--what's the > hurry? > You mean priorities like "making sure my older brother isn't better than me"? Because that motive - jealousy - was exactly what got me started :) Sure, it may not be the most noble of goals, but it sure gave me a good incentive to work hard. (And not just in programming. That's what made me study hard in other areas, like spelling and mathematics.) And that was two decades ago. It's now the 21st century; computers are ubiquitous. Starting to toy around with coding - maybe with Scratch, or one of those online algorithm development sites - is an excellent thing for a single-digit-age person to get into. I don't know of anyone younger than 4 getting started, but plenty of pre-teens, and they're doing well at it. ChrisA From mwild at sun.ac.za Mon Dec 18 08:00:36 2017 From: mwild at sun.ac.za (Wild, Marcel, Dr ) Date: Mon, 18 Dec 2017 13:00:36 +0000 Subject: binary decision diagrams Message-ID: Hello everybody: I really don't know anything about Python (I'm using Mathematica) but with the help of others learned that g=expr2bdd(f) makes the BDD (=binary decision diagram) g of a Boolean function f. But what is the easiest (fool-proof) way to print out a diagram of g ? Regards, Marcel Wild The integrity and confidentiality of this email is governed by these terms / Die integriteit en vertroulikheid van hierdie e-pos word deur die volgende bepalings gere?l. http://www.sun.ac.za/emaildisclaimer From brian.j.oney at googlemail.com Mon Dec 18 08:04:20 2017 From: brian.j.oney at googlemail.com (Brian Oney) Date: Mon, 18 Dec 2017 14:04:20 +0100 Subject: Python Templating Language In-Reply-To: <1513540168.11549.1.camel@gmail.com> References: <1513540168.11549.1.camel@gmail.com> Message-ID: you may consider checking out a more general approach. Noweb was the first to my knowledge and lead the way for Sweave (R or S), and pyweave, as mentioned. https://en.wikipedia.org/wiki/Noweb Cheers From marko at pacujo.net Mon Dec 18 08:28:09 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Dec 2017 15:28:09 +0200 Subject: Python Learning References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> Message-ID: <87d13c413q.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Dec 18, 2017 at 5:59 PM, Marko Rauhamaa wrote: >> Let's see. What I have learned on the job is projects and processes >> (even though college tried to give a taste of those, as well). Then, >> I have gathered some encyclopedic knowledge about programming >> languages, libraries, frameworks and operating systems. Finally, I >> have developed routine. >> >> But true eye-openers took place in college: data structures, >> algorithms, complexity theory, parsing and compiling, recursion, >> object-oriented programming, logic programming, functional >> programming, distributed systems, cryptography, logic and formalisms, >> mathematical rigor etc. > > So if you were to choose between two potential hires, one who had 25 > years' experience and the other had nothing but college, which would > you choose? Are you worth virtually the same salary now as you were > worth straight out of college? I am not in management at the moment so I don't do salary negotiations. I do know people's compensation is *very* loosely correlated with their value to the organization for various shortsighted and/or exploitative reasons. However, I have been doing quite a bit of hiring, quite successfully, I might add. I am not prejudiced one way or another. Your r?sum? doesn't count. Your education doesn't count. What you can do for the team counts, and that is measured during the interview process. The team where I work has a gamut of education and experience backgrounds. Some are college dropouts, some have a PhD. Some are still in school. I'm the most senior. Frankly, I have *not* detected much advantage (or disadvantage, for that matter) with a long on-the-job experience. What has been hugely more important is adaptability and sheer smarts. The team members have to be able to grasp, evaluate and express new abstract concepts and be generally on the same wave-length. Long years in service don't automatically translate into wisdom or practical solutions. However, I have put to good use what I have learned along the way. As for my take-home pay? It peaked during the telecom bubble in the 1990's. Don't worry. I get by fine. Marko From skip.montanaro at gmail.com Mon Dec 18 08:31:39 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 18 Dec 2017 07:31:39 -0600 Subject: Repeated Names (Repeated Names) In-Reply-To: References: <1187264d-0906-7d76-1efd-13bb839e4ffc@timgolden.me.uk> Message-ID: Apologies. I interpreted your use of the word "fake" to imply the domain didn't really exist. In that case, I would have not expected a website to be up, nor an email to succeed (even with delays). S On Mon, Dec 18, 2017 at 5:12 AM, Jon Ribbens wrote: > On 2017-12-17, Skip Montanaro wrote: >>>> I've emailed the administrator of bbs.geek.nz, maybe he >>>> will be able to stop it. >>> >>> Thanks, Greg. We're actually blocking via that and related headers at >>> the gateway, which is why the mailing list is no longer seeing the >>> duplicates. I'm not sure any of us thought to email the news server >>> admin, though! >> >> I did; the address is fake. >> >> Worked for me. From the URL http://news.bbs.geek.nz/ > ... >> I just sent a note to that email address. No bounce yet. > > "No bounce" is not the same as "worked". You'll get a bounce message > when the mail server at your end gives up some time several days in > the future. Depending on how your mail server is configured, you > may get a "delayed" warning some time before that. > -- > https://mail.python.org/mailman/listinfo/python-list From rhodri at kynesim.co.uk Mon Dec 18 09:09:42 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 18 Dec 2017 14:09:42 +0000 Subject: Python Learning In-Reply-To: <87d13c413q.fsf@elektro.pacujo.net> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> Message-ID: <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> On 18/12/17 13:28, Marko Rauhamaa wrote: > However, I have been doing quite a bit of hiring, quite successfully, I > might add. I am not prejudiced one way or another. Your r?sum? doesn't > count. Your education doesn't count. What you can do for the team > counts, and that is measured during the interview process. While I agree with most of what you say, I disagree with you here. Your CV (r?sum?) does count, just not necessarily in the way most people expect. I haven't often been involved in hiring, but the few times I have we had more applicants than it was feasible to interview. We used CVs as the only thing we had to filter with, looking for *interesting* people. Exactly what "interesting" meant was somewhat arbitrary; we put one person through to interview because she was a cellist, and that would have given us a complete string quartet (she didn't get the job, sadly). -- Rhodri James *-* Kynesim Ltd From larry.martell at gmail.com Mon Dec 18 09:14:47 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 18 Dec 2017 09:14:47 -0500 Subject: Python Learning In-Reply-To: <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> Message-ID: On Mon, Dec 18, 2017 at 9:09 AM, Rhodri James wrote: > On 18/12/17 13:28, Marko Rauhamaa wrote: >> >> However, I have been doing quite a bit of hiring, quite successfully, I >> might add. I am not prejudiced one way or another. Your r?sum? doesn't >> count. Your education doesn't count. What you can do for the team >> counts, and that is measured during the interview process. > > > While I agree with most of what you say, I disagree with you here. Your CV > (r?sum?) does count, just not necessarily in the way most people expect. > > I haven't often been involved in hiring, but the few times I have we had > more applicants than it was feasible to interview. We used CVs as the only > thing we had to filter with, looking for *interesting* people. Exactly what > "interesting" meant was somewhat arbitrary; we put one person through to > interview because she was a cellist, and that would have given us a complete > string quartet (she didn't get the job, sadly). Yes, I once chose to interview someone because he had on his resume that he was an award winning duck decoy carver. He also did not get the job. From rosuav at gmail.com Mon Dec 18 09:19:01 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Dec 2017 01:19:01 +1100 Subject: Python Learning In-Reply-To: <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> Message-ID: On Tue, Dec 19, 2017 at 1:09 AM, Rhodri James wrote: > On 18/12/17 13:28, Marko Rauhamaa wrote: >> >> However, I have been doing quite a bit of hiring, quite successfully, I >> might add. I am not prejudiced one way or another. Your r?sum? doesn't >> count. Your education doesn't count. What you can do for the team >> counts, and that is measured during the interview process. > > > While I agree with most of what you say, I disagree with you here. Your CV > (r?sum?) does count, just not necessarily in the way most people expect. > > I haven't often been involved in hiring, but the few times I have we had > more applicants than it was feasible to interview. We used CVs as the only > thing we had to filter with, looking for *interesting* people. This is NORMALLY going to be the case. How many hours does it take to truly evaluate a candidate? You can't afford to interview a hundred people only to find that ninety of them are hopelessly unqualified. Somehow, you have to sift out the most likely candidates, and THEN you actually meet with them. But Marko is partly right too. Your CV/r?sum? isn't going to land you the job, nor is your education. But they might land you the interview. With the students I work with, there's a dedicated Careers Services team that help them to polish their portfolio projects, because a portfolio is *way* more indicative than a CV or a college degree; but even then, the best portfolio in the world is only good enough to get you as far as an interview. > Exactly what > "interesting" meant was somewhat arbitrary; we put one person through to > interview because she was a cellist, and that would have given us a complete > string quartet (she didn't get the job, sadly). Heh. Pity. That would be fun. ChrisA From nomail at com.invalid Mon Dec 18 10:27:28 2017 From: nomail at com.invalid (ast) Date: Mon, 18 Dec 2017 16:27:28 +0100 Subject: Problem with timeit In-Reply-To: <5a33d0fc$0$2087$b1db1813$d948b532@news.astraweb.com> References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> <5a33cd6c$0$3419$426a74cc@news.free.fr> <5a33d0fc$0$2087$b1db1813$d948b532@news.astraweb.com> Message-ID: <5a37de74$0$7169$426a74cc@news.free.fr> "Steve D'Aprano" a ?crit dans le message de news:5a33d0fc$0$2087$b1db1813$d948b532 at news.astraweb.com... > On Sat, 16 Dec 2017 12:25 am, ast wrote: > >> >> "Thomas Jollans" a ?crit dans le message de >> news:mailman.74.1513341235.14074.python-list at python.org... >>> On 2017-12-15 11:36, ast wrote: >> >> > > py> x = 123456**123456 > py> s = str(x) > py> len(s) > 628578 > I discovered that log functions from math module works with integers, whatever their size, there is no conversion to float. > import math > x = 123456**123456 > math.log10(x) 628577.7303641582 (instantaneous) so 628578 digits From rgacote at appropriatesolutions.com Mon Dec 18 10:45:04 2017 From: rgacote at appropriatesolutions.com (Ray Cote) Date: Mon, 18 Dec 2017 10:45:04 -0500 Subject: Recommended pypi caching proxy? Message-ID: Hello list: Looking to deploy a locally cached pypi proxy service. Is there a recommended/preferred pypi caching tool? I?ve found: - proxypypy - Flask-Pypi-Proxy - pypicache All of which seem to have generally the same functionality and all of which are a few years old. Recommendations from the crowd? ?Ray -- Raymond Cote, President Tokenize What Matters? voice: +1.603.924.6079 email: rgacote at AppropriateSolutions.com skype: ray.cote Schedule a meeting: https://calendly.com/ray_cote/60min/ From marko at pacujo.net Mon Dec 18 11:33:11 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Dec 2017 18:33:11 +0200 Subject: Python Learning References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> Message-ID: <878te03sjc.fsf@elektro.pacujo.net> Rhodri James : > I haven't often been involved in hiring, but the few times I have we > had more applicants than it was feasible to interview. You don't have to interview them all. Once you encounter an excellent candidate, you can close the deal. If you don't, you might lose them. You don't have to find the one pearl in a thousand. > We used CVs as the only thing we had to filter with, looking for > *interesting* people. For a developer position, we use a home assignment as a filter. There's no knowing who completes the assignment, but (1) it gives an idea what is expected of them and (2) it demonstrates interest from their part. I only take a look at the CV when I arrive at the interview so I have talking points with the candidate. > Exactly what "interesting" meant was somewhat arbitrary; we put one > person through to interview because she was a cellist, and that would > have given us a complete string quartet (she didn't get the job, > sadly). We want to hire for the job and not bring in extracurricular activities. However, one great way to stand out is a portfolio of GitHub projects. Several people have gotten an offer largely based on those (after they aced the technical interviews). For example, we just hired someone who had written a game in sed. That doesn't make him an "interesting person," nor do we look for game or sed developers. But that silly exercise deeply resonated with our team. We expect to have great synergy with him. Marko From larry.martell at gmail.com Mon Dec 18 11:45:23 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 18 Dec 2017 11:45:23 -0500 Subject: Python Learning In-Reply-To: <878te03sjc.fsf@elektro.pacujo.net> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> Message-ID: On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: > However, one great way to stand out is a portfolio of GitHub projects. > Several people have gotten an offer largely based on those (after they > aced the technical interviews). For example, we just hired someone who > had written a game in sed. That doesn't make him an "interesting > person," nor do we look for game or sed developers. But that silly > exercise deeply resonated with our team. We expect to have great synergy > with him. I have been excluded from even getting an interview because I did not have a portfolio of GitHub projects. I think that is a bad filter. I work 60-70 hours a week for pay, and I have a family and personal interests. From rosuav at gmail.com Mon Dec 18 12:05:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Dec 2017 04:05:49 +1100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> Message-ID: On Tue, Dec 19, 2017 at 3:45 AM, Larry Martell wrote: > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: >> However, one great way to stand out is a portfolio of GitHub projects. >> Several people have gotten an offer largely based on those (after they >> aced the technical interviews). For example, we just hired someone who >> had written a game in sed. That doesn't make him an "interesting >> person," nor do we look for game or sed developers. But that silly >> exercise deeply resonated with our team. We expect to have great synergy >> with him. > > I have been excluded from even getting an interview because I did not > have a portfolio of GitHub projects. I think that is a bad filter. I > work 60-70 hours a week for pay, and I have a family and personal > interests. Maybe not GitHub, but something else. Do you have, anywhere on the internet, a list of demo-worthy projects? Again drawing from the students I work with, they're encouraged to build an actual portfolio web site. Granted, they *are* full stack web developers, so this may not be applicable to everyone, but still, it's independent of GitHub. ChrisA From larry.martell at gmail.com Mon Dec 18 12:13:39 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 18 Dec 2017 12:13:39 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> Message-ID: On Mon, Dec 18, 2017 at 12:05 PM, Chris Angelico wrote: > On Tue, Dec 19, 2017 at 3:45 AM, Larry Martell wrote: >> On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: >>> However, one great way to stand out is a portfolio of GitHub projects. >>> Several people have gotten an offer largely based on those (after they >>> aced the technical interviews). For example, we just hired someone who >>> had written a game in sed. That doesn't make him an "interesting >>> person," nor do we look for game or sed developers. But that silly >>> exercise deeply resonated with our team. We expect to have great synergy >>> with him. >> >> I have been excluded from even getting an interview because I did not >> have a portfolio of GitHub projects. I think that is a bad filter. I >> work 60-70 hours a week for pay, and I have a family and personal >> interests. > > Maybe not GitHub, but something else. Do you have, anywhere on the > internet, a list of demo-worthy projects? Again drawing from the > students I work with, they're encouraged to build an actual portfolio > web site. Granted, they *are* full stack web developers, so this may > not be applicable to everyone, but still, it's independent of GitHub. Nothing I can put on the internet because the work I have done is either an embedded system or proprietary and used in house for a company, or part of a commercial project. I do have things I can show from my machine using my development environment, and I have offered that up, but for those who want to see something on GitHub it does not get that far. From rhodri at kynesim.co.uk Mon Dec 18 12:31:57 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 18 Dec 2017 17:31:57 +0000 Subject: Python Learning In-Reply-To: <878te03sjc.fsf@elektro.pacujo.net> References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> Message-ID: <575d5fbc-44ab-3786-b89b-fd5469ac29cd@kynesim.co.uk> On 18/12/17 16:33, Marko Rauhamaa wrote: > Rhodri James : >> I haven't often been involved in hiring, but the few times I have we >> had more applicants than it was feasible to interview. > > You don't have to interview them all. Once you encounter an excellent > candidate, you can close the deal. If you don't, you might lose them. > You don't have to find the one pearl in a thousand. > >> We used CVs as the only thing we had to filter with, looking for >> *interesting* people. > > For a developer position, we use a home assignment as a filter. There's > no knowing who completes the assignment, but (1) it gives an idea what > is expected of them and (2) it demonstrates interest from their part. I believe we have a standard set of C programming questions we throw at interviewees, on the same principle. One place I worked at used to request a hand-written cover letter with applications. This too was a filter, though not by graphological analysis as many people assumed (and took umbrage at). No, we were testing if you could follow instructions and take some degree of care. A hastily scribbled piece of paper with lots of crossings out didn't auger well for how careful you would be with the code base! >> Exactly what "interesting" meant was somewhat arbitrary; we put one >> person through to interview because she was a cellist, and that would >> have given us a complete string quartet (she didn't get the job, >> sadly). > > We want to hire for the job and not bring in extracurricular activities. > > However, one great way to stand out is a portfolio of GitHub projects. Er, isn't that an extracurricular activity? I certainly don't have time for it outside work. > Several people have gotten an offer largely based on those (after they > aced the technical interviews). For example, we just hired someone who > had written a game in sed. That doesn't make him an "interesting > person," nor do we look for game or sed developers. But that silly > exercise deeply resonated with our team. We expect to have great synergy > with him. In other words, you find him interesting because of that. -- Rhodri James *-* Kynesim Ltd From m at funkyhat.org Mon Dec 18 13:00:31 2017 From: m at funkyhat.org (Matt Wheeler) Date: Mon, 18 Dec 2017 18:00:31 +0000 (UTC) Subject: Recommended pypi caching proxy? In-Reply-To: References: Message-ID: On Mon, 18 Dec 2017, 15:45 Ray Cote, wrote: > Looking to deploy a locally cached pypi proxy service. > > Is there a recommended/preferred pypi caching tool? > I?ve found: > - proxypypy > - Flask-Pypi-Proxy > - pypicache > > All of which seem to have generally the same functionality and all of which > are a few years old. > Recommendations from the crowd? > In the past I've used https://github.com/devpi/devpi It may have many features you don't need if all you're after is a caching proxy, but I found it does that well and it appears to still be pretty active. > -- -- Matt Wheeler http://funkyh.at From gheskett at shentel.net Mon Dec 18 14:09:36 2017 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 18 Dec 2017 14:09:36 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> Message-ID: <201712181409.36624.gheskett@shentel.net> On Monday 18 December 2017 09:19:01 Chris Angelico wrote: > On Tue, Dec 19, 2017 at 1:09 AM, Rhodri James wrote: > > On 18/12/17 13:28, Marko Rauhamaa wrote: > >> However, I have been doing quite a bit of hiring, quite > >> successfully, I might add. I am not prejudiced one way or another. > >> Your r?sum? doesn't count. Your education doesn't count. What you > >> can do for the team counts, and that is measured during the > >> interview process. > > > > While I agree with most of what you say, I disagree with you here. > > Your CV (r?sum?) does count, just not necessarily in the way most > > people expect. > > > > I haven't often been involved in hiring, but the few times I have we > > had more applicants than it was feasible to interview. We used CVs > > as the only thing we had to filter with, looking for *interesting* > > people. > > This is NORMALLY going to be the case. How many hours does it take to > truly evaluate a candidate? You can't afford to interview a hundred > people only to find that ninety of them are hopelessly unqualified. > Somehow, you have to sift out the most likely candidates, and THEN you > actually meet with them. > > But Marko is partly right too. Your CV/r?sum? isn't going to land you > the job, nor is your education. But they might land you the interview. > With the students I work with, there's a dedicated Careers Services > team that help them to polish their portfolio projects, because a > portfolio is *way* more indicative than a CV or a college degree; but > even then, the best portfolio in the world is only good enough to get > you as far as an interview. > > > Exactly what > > "interesting" meant was somewhat arbitrary; we put one person > > through to interview because she was a cellist, and that would have > > given us a complete string quartet (she didn't get the job, sadly). > > Heh. Pity. That would be fun. > > ChrisA I'll have to agree with most of this about "interesting" people. But one thing I always note from the resume or CV is any certifications they may carry. I am a C.E.T., and that card laid in front of an HR/GM type has gotten me every job I've applied for since 1972, but sadly those are rare birds indeed as I've not in the 45 years since, encountered another such individual. So I've had to depend on their familiarity with a soldering iron and some scope probes to determine if they would be useful to me. That certification is required to get a business license for an electronics service business in Kalipornia, weeds out the fly by nighters there was a plague of back in the 60's _& 70's. There really ought to be a similar program for coders. I'd probably fail that one, but generally my code works, and does not crash. And I've learned a lot while fixing it if it does crash. :) Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From python at mrabarnett.plus.com Mon Dec 18 14:16:46 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 18 Dec 2017 19:16:46 +0000 Subject: [OT] Python and Excel Message-ID: Those who use Excel might find this interesting: Microsoft Considers Adding Python as an Official Scripting Language to Excel https://www.bleepingcomputer.com/news/microsoft/microsoft-considers-adding-python-as-an-official-scripting-language-to-excel/ From marko at pacujo.net Mon Dec 18 15:22:22 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Dec 2017 22:22:22 +0200 Subject: Python Learning References: <939425528@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> Message-ID: <8737474wht.fsf@elektro.pacujo.net> Larry Martell : > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: >> However, one great way to stand out is a portfolio of GitHub >> projects. Several people have gotten an offer largely based on those >> (after they aced the technical interviews). For example, we just >> hired someone who had written a game in sed. That doesn't make him an >> "interesting person," nor do we look for game or sed developers. But >> that silly exercise deeply resonated with our team. We expect to have >> great synergy with him. > > I have been excluded from even getting an interview because I did not > have a portfolio of GitHub projects. I think that is a bad filter. I > work 60-70 hours a week for pay, and I have a family and personal > interests. Personal programming projects are not a requirement. They are just a very effective advertising tool. As for 60?70 hours a week... sounds horrible. My sympathies. Marko From marko at pacujo.net Mon Dec 18 15:25:31 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Dec 2017 22:25:31 +0200 Subject: Python Learning References: <939425528@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> <575d5fbc-44ab-3786-b89b-fd5469ac29cd@kynesim.co.uk> Message-ID: <87y3lz3hs4.fsf@elektro.pacujo.net> Rhodri James : > On 18/12/17 16:33, Marko Rauhamaa wrote: >> Rhodri James : >>> Exactly what "interesting" meant was somewhat arbitrary; we put one >>> person through to interview because she was a cellist, and that >>> would have given us a complete string quartet (she didn't get the >>> job, sadly). >> >> We want to hire for the job and not bring in extracurricular >> activities. >> >> However, one great way to stand out is a portfolio of GitHub >> projects. > > Er, isn't that an extracurricular activity? I certainly don't have > time for it outside work. GitHub projects are directly applicable to our line of business. Music is not. Marko From rgaddi at highlandtechnology.invalid Mon Dec 18 16:05:10 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 18 Dec 2017 13:05:10 -0800 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> Message-ID: On 12/18/2017 08:45 AM, Larry Martell wrote: > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: >> However, one great way to stand out is a portfolio of GitHub projects. >> Several people have gotten an offer largely based on those (after they >> aced the technical interviews). For example, we just hired someone who >> had written a game in sed. That doesn't make him an "interesting >> person," nor do we look for game or sed developers. But that silly >> exercise deeply resonated with our team. We expect to have great synergy >> with him. > > I have been excluded from even getting an interview because I did not > have a portfolio of GitHub projects. I think that is a bad filter. I > work 60-70 hours a week for pay, and I have a family and personal > interests. > When I'm hiring I don't necessarily need a candidate to have an extensive open-source portfolio, but I need to see some kind of portfolio, just as a bar of "This is what I consider my good work to be." The idea that someone is going to have years of experience, but not a single page of code that they can let me look over always strikes me as odd. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From oliver.schoenborn at gmail.com Mon Dec 18 16:25:17 2017 From: oliver.schoenborn at gmail.com (oliver) Date: Mon, 18 Dec 2017 21:25:17 +0000 Subject: [OT] Python and Excel In-Reply-To: References: Message-ID: That would be amazing. I still have nightmares of when I had to create this big options analysis VBA program in Excel 2007. On Mon, Dec 18, 2017, 14:21 MRAB, wrote: > Those who use Excel might find this interesting: > > Microsoft Considers Adding Python as an Official Scripting Language to > Excel > > https://www.bleepingcomputer.com/news/microsoft/microsoft-considers-adding-python-as-an-official-scripting-language-to-excel/ > -- > https://mail.python.org/mailman/listinfo/python-list > -- Oliver My StackOverflow contributions My CodeProject articles My Github projects My SourceForget.net projects From python.list at tim.thechases.com Mon Dec 18 16:25:57 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 18 Dec 2017 15:25:57 -0600 Subject: __contains__ classmethod? Message-ID: <20171218152557.37fc0f7d@bigbox.christie.dr> Playing around, I had this (happens to be Py2, but gets the same result in Py3) code class X(object): ONE = "one" TWO = "two" _ALL = frozenset(v for k,v in locals().items() if k.isupper()) @classmethod def __contains__(cls, v): return v in cls._ALL print(dir(X)) print(X._ALL) Running this gives ['ONE', 'TWO', '_ALL', '__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] And then, depending on whether it's Py2 or Py3, I get either frozenset({'one', 'two'}) frozenset(['two', 'one']) Which I expect. Hey, look. There's a __contains__ method. And it has been specified as a @classmethod. So I want to test it: print("one" in X) However that fails with Traceback (most recent call last): File "x.py", line 10, in print("one" in X) TypeError: argument of type 'type' is not iterable My understanding was that "in" makes use of an available __contains__ but something seems to preventing Python from finding that. What's going on here? Thanks, -tkc From auriocus at gmx.de Mon Dec 18 16:27:07 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 18 Dec 2017 22:27:07 +0100 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Am 18.12.17 um 05:54 schrieb Bill: > Chris Angelico wrote: >> I don't know about vtables as needing to be in ANY programming course. >> They're part of a "let's dive into the internals of C++" course. You >> certainly don't need them to understand how things work in Python, >> because they don't exist; and I'm doubtful that you need to explain >> them even to C++ programmers. >> > Then how are you going to explain dynamic_cast? > You don't need to explain a vtable to explain dynamic_cast. Only if you want to become a compiler writer. It is not even required, vtables are just the most common implementation. dynamic_cast simply checks if the actual object that the pointer points to is an instance of a derived class, and then casts it into that. You could "explain" it with the following pseudo-code template T* dynamic_cast(base *input) { if (isinstanceof(base, *input)) { return (T*)input; } else { return nullptr; } } How that works (particularly the "isinstanceof") is not the business of the programmer - it is sufficient to know that the compiler somewhere stores this information for every object. Christian From rgacote at appropriatesolutions.com Mon Dec 18 16:47:24 2017 From: rgacote at appropriatesolutions.com (Ray Cote) Date: Mon, 18 Dec 2017 16:47:24 -0500 Subject: Recommended pypi caching proxy? In-Reply-To: References: Message-ID: On Mon, Dec 18, 2017 at 1:00 PM, Matt Wheeler wrote: > On Mon, 18 Dec 2017, 15:45 Ray Cote, > wrote: > >> Looking to deploy a locally cached pypi proxy service. >> >> Is there a recommended/preferred pypi caching tool? >> I?ve found: >> - proxypypy >> - Flask-Pypi-Proxy >> - pypicache >> >> All of which seem to have generally the same functionality and all of >> which >> are a few years old. >> Recommendations from the crowd? >> > > In the past I've used https://github.com/devpi/devpi > It may have many features you don't need if all you're after is a caching > proxy, but I found it does that well and it appears to still be pretty > active. > >> -- > > -- > Matt Wheeler > http://funkyh.at > Thanks for the recommendation. Will take a look at it. ?Ray -- Raymond Cote, President voice: +1.603.924.6079 email: rgacote at AppropriateSolutions.com skype: ray.cote Schedule a meeting: https://calendly.com/ray_cote/60min/ From __peter__ at web.de Mon Dec 18 16:48:56 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Dec 2017 22:48:56 +0100 Subject: __contains__ classmethod? References: <20171218152557.37fc0f7d@bigbox.christie.dr> Message-ID: Tim Chase wrote: > Playing around, I had this (happens to be Py2, but gets the same > result in Py3) code > > class X(object): > ONE = "one" > TWO = "two" > _ALL = frozenset(v for k,v in locals().items() if k.isupper()) > @classmethod > def __contains__(cls, v): > return v in cls._ALL > print(dir(X)) > print(X._ALL) > > Running this gives > > ['ONE', 'TWO', '_ALL', '__class__', '__contains__', '__delattr__', > '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', > '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', > '__lt__', '__module__', '__ne__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', > '__str__', '__subclasshook__', '__weakref__'] > > And then, depending on whether it's Py2 or Py3, I get either > > frozenset({'one', 'two'}) > frozenset(['two', 'one']) > > Which I expect. Hey, look. There's a __contains__ method. And it > has been specified as a @classmethod. So I want to test it: > > print("one" in X) > > However that fails with > > Traceback (most recent call last): > File "x.py", line 10, in > print("one" in X) > TypeError: argument of type 'type' is not iterable > > My understanding was that "in" makes use of an available __contains__ > but something seems to preventing Python from finding that. > > What's going on here? Like __next__ method is looked up in the class, and for the class X that would be its metaclass, type. So you have to adjust that: $ cat contains.py class XType(type): def __contains__(cls, v): print("metaclass") return v in cls._ALL class X(metaclass=XType): ONE = "one" TWO = "two" _ALL = frozenset(v for k, v in locals().items() if k.isupper()) @classmethod def __contains__(cls, v): print("instance") return v in cls print("one" in X, "one" in X()) print("three" in X, "three" in X()) $ python3 contains.py metaclass instance metaclass True True metaclass instance metaclass False False From gheskett at shentel.net Mon Dec 18 16:52:34 2017 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 18 Dec 2017 16:52:34 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> Message-ID: <201712181652.34433.gheskett@shentel.net> On Monday 18 December 2017 16:05:10 Rob Gaddi wrote: > On 12/18/2017 08:45 AM, Larry Martell wrote: > > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: > >> However, one great way to stand out is a portfolio of GitHub > >> projects. Several people have gotten an offer largely based on > >> those (after they aced the technical interviews). For example, we > >> just hired someone who had written a game in sed. That doesn't make > >> him an "interesting person," nor do we look for game or sed > >> developers. But that silly exercise deeply resonated with our team. > >> We expect to have great synergy with him. > > > > I have been excluded from even getting an interview because I did > > not have a portfolio of GitHub projects. I think that is a bad > > filter. I work 60-70 hours a week for pay, and I have a family and > > personal interests. > > When I'm hiring I don't necessarily need a candidate to have an > extensive open-source portfolio, but I need to see some kind of > portfolio, just as a bar of "This is what I consider my good work to > be." The idea that someone is going to have years of experience, but > not a single page of code that they can let me look over always > strikes me as odd. I've known Larry for years via another list. He has worked on a lot of stuff in the financial arena, wrapped in non-disclosure clauses that prevent him from even saying what color he dots the i's with, so he gets work as much by word of mouth as other more conventional paths. To not hire him because he doesn't have a big portfolio could be a mistake, Rob. Its up to you. > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From random832 at fastmail.com Mon Dec 18 16:55:10 2017 From: random832 at fastmail.com (Random832) Date: Mon, 18 Dec 2017 16:55:10 -0500 Subject: __contains__ classmethod? In-Reply-To: <20171218152557.37fc0f7d@bigbox.christie.dr> References: <20171218152557.37fc0f7d@bigbox.christie.dr> Message-ID: <1513634110.279038.1209285600.0C71F2AE@webmail.messagingengine.com> On Mon, Dec 18, 2017, at 16:25, Tim Chase wrote: > My understanding was that "in" makes use of an available __contains__ > but something seems to preventing Python from finding that. > > What's going on here? Most __ methods have to be an actual method on the class object, which means you have to use a metaclass. "one" in X() works, but to get "one" in X to work, you need: class M(type): def __contains__(cls, v): return v in cls._ALL class X(object, metaclass=M): ONE = "one" TWO = "two" _ALL = frozenset(v for k,v in locals().items() if k.isupper()) If you want *both* "one" in X and "one" in X() to work, I think you pretty much have to define it in both places. From larry.martell at gmail.com Mon Dec 18 17:33:46 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 18 Dec 2017 17:33:46 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> Message-ID: On Mon, Dec 18, 2017 at 4:05 PM, Rob Gaddi wrote: > On 12/18/2017 08:45 AM, Larry Martell wrote: >> >> On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: >>> >>> However, one great way to stand out is a portfolio of GitHub projects. >>> Several people have gotten an offer largely based on those (after they >>> aced the technical interviews). For example, we just hired someone who >>> had written a game in sed. That doesn't make him an "interesting >>> person," nor do we look for game or sed developers. But that silly >>> exercise deeply resonated with our team. We expect to have great synergy >>> with him. >> >> >> I have been excluded from even getting an interview because I did not >> have a portfolio of GitHub projects. I think that is a bad filter. I >> work 60-70 hours a week for pay, and I have a family and personal >> interests. >> > > When I'm hiring I don't necessarily need a candidate to have an extensive > open-source portfolio, but I need to see some kind of portfolio, just as a > bar of "This is what I consider my good work to be." The idea that someone > is going to have years of experience, but not a single page of code that > they can let me look over always strikes me as odd. I have lots of code and projects to show, but only on my computer. I once got a django/python job because I had a PHP app I did to show. But if they had not interviewed me because I had nothing on a public site they never would have seen it. From larry.martell at gmail.com Mon Dec 18 17:34:28 2017 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 18 Dec 2017 17:34:28 -0500 Subject: Python Learning In-Reply-To: <201712181652.34433.gheskett@shentel.net> References: <939425528@f38.n261.z1.binkp.net> <201712181652.34433.gheskett@shentel.net> Message-ID: On Mon, Dec 18, 2017 at 4:52 PM, Gene Heskett wrote: > On Monday 18 December 2017 16:05:10 Rob Gaddi wrote: > >> On 12/18/2017 08:45 AM, Larry Martell wrote: >> > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa > wrote: >> >> However, one great way to stand out is a portfolio of GitHub >> >> projects. Several people have gotten an offer largely based on >> >> those (after they aced the technical interviews). For example, we >> >> just hired someone who had written a game in sed. That doesn't make >> >> him an "interesting person," nor do we look for game or sed >> >> developers. But that silly exercise deeply resonated with our team. >> >> We expect to have great synergy with him. >> > >> > I have been excluded from even getting an interview because I did >> > not have a portfolio of GitHub projects. I think that is a bad >> > filter. I work 60-70 hours a week for pay, and I have a family and >> > personal interests. >> >> When I'm hiring I don't necessarily need a candidate to have an >> extensive open-source portfolio, but I need to see some kind of >> portfolio, just as a bar of "This is what I consider my good work to >> be." The idea that someone is going to have years of experience, but >> not a single page of code that they can let me look over always >> strikes me as odd. > > I've known Larry for years via another list. He has worked on a lot of > stuff in the financial arena, wrapped in non-disclosure clauses that > prevent him from even saying what color he dots the i's with, so he gets > work as much by word of mouth as other more conventional paths. True story. > To not hire him because he doesn't have a big portfolio could be a > mistake, Rob. Its up to you. Thank you my friend. From __peter__ at web.de Mon Dec 18 17:39:46 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Dec 2017 23:39:46 +0100 Subject: __contains__ classmethod? References: <20171218152557.37fc0f7d@bigbox.christie.dr> Message-ID: Peter Otten wrote: > Tim Chase wrote: > >> Playing around, I had this (happens to be Py2, but gets the same >> result in Py3) code >> >> class X(object): >> ONE = "one" >> TWO = "two" >> _ALL = frozenset(v for k,v in locals().items() if k.isupper()) >> @classmethod >> def __contains__(cls, v): >> return v in cls._ALL >> print(dir(X)) >> print(X._ALL) >> >> Running this gives >> >> ['ONE', 'TWO', '_ALL', '__class__', '__contains__', '__delattr__', >> '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', >> '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', >> '__lt__', '__module__', '__ne__', '__new__', '__reduce__', >> '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', >> '__str__', '__subclasshook__', '__weakref__'] >> >> And then, depending on whether it's Py2 or Py3, I get either >> >> frozenset({'one', 'two'}) >> frozenset(['two', 'one']) >> >> Which I expect. Hey, look. There's a __contains__ method. And it >> has been specified as a @classmethod. So I want to test it: >> >> print("one" in X) >> >> However that fails with >> >> Traceback (most recent call last): >> File "x.py", line 10, in >> print("one" in X) >> TypeError: argument of type 'type' is not iterable >> >> My understanding was that "in" makes use of an available __contains__ >> but something seems to preventing Python from finding that. >> >> What's going on here? > > Like __next__ method is looked up in the class, and for the class X that > would be its metaclass, type. Sorry, I realize that this sentence is impossible to understand. Random832 states the problem more clearly. [Digression] I mentioned the __next__() method specifically because I remembered that you could override its predecessor next() in the instance. However, the examples below demonstrate that this behaviour is limited to classic classes: >>> def demo(C): ... c = C() ... c.next = lambda: 42 ... for x in c: ... print x ... break ... >>> class A: ... def __iter__(self): ... return self ... def next(self): ... return "class" ... >>> demo(A) 42 >>> class B(A, object): pass ... >>> demo(B) class > So you have to adjust that: > > $ cat contains.py > class XType(type): > def __contains__(cls, v): > print("metaclass") > return v in cls._ALL > > > class X(metaclass=XType): > ONE = "one" > TWO = "two" > _ALL = frozenset(v for k, v in locals().items() if k.isupper()) > > @classmethod > def __contains__(cls, v): > print("instance") This should rather be print("class") > return v in cls > > print("one" in X, "one" in X()) > print("three" in X, "three" in X()) > $ python3 contains.py > metaclass > instance > metaclass > True True > metaclass > instance > metaclass > False False From rgaddi at highlandtechnology.invalid Mon Dec 18 17:54:16 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 18 Dec 2017 14:54:16 -0800 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <201712181652.34433.gheskett@shentel.net> Message-ID: On 12/18/2017 01:52 PM, Gene Heskett wrote: > On Monday 18 December 2017 16:05:10 Rob Gaddi wrote: > >> On 12/18/2017 08:45 AM, Larry Martell wrote: >>> On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa > wrote: >>>> However, one great way to stand out is a portfolio of GitHub >>>> projects. Several people have gotten an offer largely based on >>>> those (after they aced the technical interviews). For example, we >>>> just hired someone who had written a game in sed. That doesn't make >>>> him an "interesting person," nor do we look for game or sed >>>> developers. But that silly exercise deeply resonated with our team. >>>> We expect to have great synergy with him. >>> >>> I have been excluded from even getting an interview because I did >>> not have a portfolio of GitHub projects. I think that is a bad >>> filter. I work 60-70 hours a week for pay, and I have a family and >>> personal interests. >> >> When I'm hiring I don't necessarily need a candidate to have an >> extensive open-source portfolio, but I need to see some kind of >> portfolio, just as a bar of "This is what I consider my good work to >> be." The idea that someone is going to have years of experience, but >> not a single page of code that they can let me look over always >> strikes me as odd. > > I've known Larry for years via another list. He has worked on a lot of > stuff in the financial arena, wrapped in non-disclosure clauses that > prevent him from even saying what color he dots the i's with, so he gets > work as much by word of mouth as other more conventional paths. > > To not hire him because he doesn't have a big portfolio could be a > mistake, Rob. Its up to you. >> -- >> Rob Gaddi, Highland Technology -- www.highlandtechnology.com >> Email address domain is currently out of order. See above to fix. > > > Cheers, Gene Heskett > Not a big portfolio, anything. Shell scripts that you're using to simplify your home login. The garage door monitor you rigged up from an Arduino. The Python script I wrote to fill a USB stick with a randomly chosen selection of MP3s. I as well don't have a huge portfolio of GitHub projects that I spend my life maintaining, but I refuse to believe any of us get away with not writing any code outside out professional lives. Personally, I'd argue I can get a better read of a programmer from the 120 line toy they tossed off one day to solve an immediate need than I can from the 50 kLOC proprietary project they share with two other developers and are NDAed to the hilt on. And as for Larry in particular, he's posted a portfolio's worth of code to this mailing list just in trying to help folks through their issues. For an actual interview I'd want it cleaned up to what he'd consider to be acceptable documentation standards for a project, but "demonstrate competence" is a well-cleared bar. I just don't have any work at the moment that would justify bringing that big a cannon to bear. So I stick to my point. If you have literally nothing that you can show me at an interview, I'm dubious. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From lcargill99 at comcast.com Mon Dec 18 18:10:43 2017 From: lcargill99 at comcast.com (Les Cargill) Date: Mon, 18 Dec 2017 17:10:43 -0600 Subject: [OT] Python and Excel In-Reply-To: References: Message-ID: oliver wrote: > That would be amazing. I still have nightmares of when I had to create this > big options analysis VBA program in Excel 2007. > Odd - I haven't found VBA itself to be all that horrible. Yeah, it's got some serious weaknesses but it jut hasn't bit me badly, yet. Then again, it's not something I do a lot of. > On Mon, Dec 18, 2017, 14:21 MRAB, wrote: > >> Those who use Excel might find this interesting: >> >> Microsoft Considers Adding Python as an Official Scripting Language to >> Excel >> >> https://www.bleepingcomputer.com/news/microsoft/microsoft-considers-adding-python-as-an-official-scripting-language-to-excel/ >> -- >> https://mail.python.org/mailman/listinfo/python-list >> -- Les Cargill From lcargill99 at comcast.com Mon Dec 18 18:20:16 2017 From: lcargill99 at comcast.com (Les Cargill) Date: Mon, 18 Dec 2017 17:20:16 -0600 Subject: async serial port in Python. Message-ID: What I'd like to do is set up *some* sort of method in Python to asynchronously use callbacks to receive characters from a serial port or 20 serial ports. If I have to hook an event loop or even spawn a thread - fine! but it needs to allow for making things event-driven. For lack of a better term, I'd like this to at least have "select()/epoll() semantics". And then I'd like to extend that to TCP and UDP ports. Is this even possible? I keep running into "not done yet" stuff on this front, but I'm not very up on Python. It may be ... what's the term ... ? ... un-Pythonic, and I would accept that as an explanation. And no, I do not have a pet distro or version of Python. Any is fine with me. The Brent Welch book for Tcl has a totally complete example of this laid out in great detail. That's sooooo 15-20 years ago - try to catch up, guys :) -- Les Cargill From BILL_NOSPAM at Noway.net Mon Dec 18 19:05:56 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Mon, 18 Dec 2017 19:05:56 -0500 Subject: Python Learning In-Reply-To: References: <939425528@f38.n261.z1.binkp.net> <268249281@f38.n261.z1.binkp.net> Message-ID: Christian Gollwitzer wrote: > > You don't need to explain a vtable to explain dynamic_cast. Only if > you want to become a compiler writer. It is not even required, vtables > are just the most common implementation. > > dynamic_cast simply checks if the actual object that the pointer > points to is an instance of a derived class, and then casts it into > that. You could "explain" it with the following pseudo-code > > template > T* dynamic_cast(base *input) { > if (isinstanceof(base, *input)) { return (T*)input; } > else { return nullptr; } > } > > How that works (particularly the "isinstanceof") is not the business > of the programmer - it is sufficient to know that the compiler > somewhere stores this information for every object. > > Christian With that, the students would "boo you off the stage!"... and maybe accuse you of being a "know it all". ; ) The point of college is more about teaching students to think rather than in being efficient. I have little doubt that a tech school could "get through everything" much faster. Bill From johnpote at jptechnical.co.uk Mon Dec 18 19:06:01 2017 From: johnpote at jptechnical.co.uk (John Pote) Date: Tue, 19 Dec 2017 00:06:01 +0000 Subject: async serial port in Python. In-Reply-To: References: Message-ID: On 18/12/2017 23:20, Les Cargill wrote: > > What I'd like to do is set up *some* sort of method in Python to > asynchronously use callbacks to receive characters from a serial port > or 20 serial ports. > > If I have to hook an event loop or even spawn a thread - fine! but it > needs to allow for making things event-driven. For lack of a better > term, I'd like this to at least have "select()/epoll() semantics". > > And then I'd like to extend that to TCP and UDP ports. > > Is this even possible? I keep running into "not done yet" > stuff on this front, but I'm not very up on Python. It may > be ... what's the term ... ? ... un-Pythonic, and I would accept > that as an explanation. > > > And no, I do not have a pet distro or version of Python. Any is fine > with me. I've use Chris Liechti's pySerial very successfully several times on Python 2.7 and earlier and just a test with 3.6. Easy enough to access it from Python threads. I'm stuck with Windoze so have used COMx: port access to both PC native serial port (I have old kit) and USB virtual serial ports. No idea about xNix. From lcargill99 at comcast.com Mon Dec 18 19:16:51 2017 From: lcargill99 at comcast.com (Les Cargill) Date: Mon, 18 Dec 2017 18:16:51 -0600 Subject: async serial port in Python. In-Reply-To: References: Message-ID: Les Cargill wrote: > > What I'd like to do is set up *some* sort of method in Python to > asynchronously use callbacks to receive characters from a serial port > or 20 serial ports. > > If I have to hook an event loop or even spawn a thread - fine! but it > needs to allow for making things event-driven. For lack of a better > term, I'd like this to at least have "select()/epoll() semantics". > > And then I'd like to extend that to TCP and UDP ports. > > Is this even possible? I keep running into "not done yet" > stuff on this front, but I'm not very up on Python. It may > be ... what's the term ... ? ... un-Pythonic, and I would accept > that as an explanation. > > > And no, I do not have a pet distro or version of Python. Any is fine > with me. > > > > The Brent Welch book for Tcl has a totally complete example of this > laid out in great detail. That's sooooo 15-20 years ago - try to catch > up, guys :) > > > Update: Found this: http://pyserial-asyncio.readthedocs.io/en/latest/index.html Seems to work. It's still "experimental"? -- Les Cargill From python at mrabarnett.plus.com Mon Dec 18 19:16:59 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Dec 2017 00:16:59 +0000 Subject: __contains__ classmethod? In-Reply-To: <20171218152557.37fc0f7d@bigbox.christie.dr> References: <20171218152557.37fc0f7d@bigbox.christie.dr> Message-ID: <2486a3a0-d968-1649-4c1a-785e05d6cd84@mrabarnett.plus.com> On 2017-12-18 21:25, Tim Chase wrote: > Playing around, I had this (happens to be Py2, but gets the same > result in Py3) code > > class X(object): > ONE = "one" > TWO = "two" > _ALL = frozenset(v for k,v in locals().items() if k.isupper()) > @classmethod > def __contains__(cls, v): > return v in cls._ALL > print(dir(X)) > print(X._ALL) > > Running this gives > > ['ONE', 'TWO', '_ALL', '__class__', '__contains__', '__delattr__', > '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', > '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', > '__lt__', '__module__', '__ne__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', > '__str__', '__subclasshook__', '__weakref__'] > > And then, depending on whether it's Py2 or Py3, I get either > > frozenset({'one', 'two'}) > frozenset(['two', 'one']) > > Which I expect. Hey, look. There's a __contains__ method. And it > has been specified as a @classmethod. So I want to test it: > > print("one" in X) > > However that fails with > > Traceback (most recent call last): > File "x.py", line 10, in > print("one" in X) > TypeError: argument of type 'type' is not iterable > > My understanding was that "in" makes use of an available __contains__ > but something seems to preventing Python from finding that. > > What's going on here? > Maybe it's just because it's intended to be an instance method, like __getitem__. From namenobodywants at gmail.com Tue Dec 19 01:01:57 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Mon, 18 Dec 2017 22:01:57 -0800 (PST) Subject: correctness proof for alpha-beta algorithm Message-ID: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> hi all can anybody tell me where to look for a proof of the correctness of a minimax/negamax algorithm with alpha-beta pruning? thanks if you can help peace stm From tjreedy at udel.edu Tue Dec 19 01:15:30 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Dec 2017 01:15:30 -0500 Subject: correctness proof for alpha-beta algorithm In-Reply-To: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> Message-ID: On 12/19/2017 1:01 AM, namenobodywants at gmail.com wrote: > can anybody tell me where to look for a proof of the correctness of a minimax/negamax algorithm with alpha-beta pruning? thanks if you can help Where or how have you looked so far? How formal do you want? -- Terry Jan Reedy From nad at python.org Tue Dec 19 03:42:35 2017 From: nad at python.org (Ned Deily) Date: Tue, 19 Dec 2017 03:42:35 -0500 Subject: [RELEASE] Python 3.6.4 is now available Message-ID: <24E5A059-9558-4D15-B846-82A771FEC188@python.org> On behalf of the Python development community and the Python 3.6 release team, I am happy to announce the availability of Python 3.6.4, the fourth maintenance release of Python 3.6. Detailed information about the changes made in 3.6.4 can be found in the change log here: https://docs.python.org/3.6/whatsnew/changelog.html#python-3-6-4-final Please see "What?s New In Python 3.6" for more information about the new features in Python 3.6: https://docs.python.org/3.6/whatsnew/3.6.html You can download Python 3.6.4 here: https://www.python.org/downloads/release/python-364/ The next maintenance release of Python 3.6 is expected to follow in about 3 months, around the end of 2018-03. More information about the 3.6 release schedule can be found here: https://www.python.org/dev/peps/pep-0494/ Enjoy! -- Ned Deily nad at python.org -- [] From steve+python at pearwood.info Tue Dec 19 05:36:53 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 19 Dec 2017 21:36:53 +1100 Subject: Problem with timeit References: <5a33a5aa$0$10195$426a74cc@news.free.fr> <33201a4e-9af7-37bf-c092-ed82a70f1c5b@tjol.eu> <5a33cd6c$0$3419$426a74cc@news.free.fr> <5a33d0fc$0$2087$b1db1813$d948b532@news.astraweb.com> <5a37de74$0$7169$426a74cc@news.free.fr> Message-ID: <5a38ebc6$0$6319$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Dec 2017 02:27 am, ast wrote: > I discovered that log functions from math module > works with integers, whatever their size, there is > no conversion to float. > >> import math >> x = 123456**123456 >> math.log10(x) > 628577.7303641582 (instantaneous) > > so 628578 digits Nice! It also works with other bases: py> x = 10**1000000 py> math.log(x, 2) 3321928.0948873623 py> x.bit_length() 3321929 Today I learned. Thank you. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From mwild at sun.ac.za Tue Dec 19 08:58:44 2017 From: mwild at sun.ac.za (Wild, Marcel, Dr ) Date: Tue, 19 Dec 2017 13:58:44 +0000 Subject: binary decision diagrams (BDD) Message-ID: Hello every body, I'm new here and this is my first question. I really don't know anything about Python (I use Mathematica) but with the help of others learned that g=expr2bdd(f) makes the BDD g of a Boolean function f. But what is the easiest (fool-proof) way to print out the diagram of g (i.e. the usual binary tree) ? The integrity and confidentiality of this email is governed by these terms / Die integriteit en vertroulikheid van hierdie e-pos word deur die volgende bepalings gere?l. http://www.sun.ac.za/emaildisclaimer From rustompmody at gmail.com Tue Dec 19 09:57:40 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Dec 2017 06:57:40 -0800 (PST) Subject: [OT] Python and Excel In-Reply-To: References: Message-ID: On Tuesday, December 19, 2017 at 4:38:17 AM UTC+5:30, Les Cargill wrote: > oliver wrote: > > That would be amazing. I still have nightmares of when I had to create this > > big options analysis VBA program in Excel 2007. > > > > > Odd - I haven't found VBA itself to be all that horrible. Yeah, it's got > some serious weaknesses but it jut hasn't bit me badly, yet. Then again, > it's not something I do a lot of. In the era of Windows 95-98 I did some VBA ? I quite liked the experience Coming to libreoffice I find it boasts many languages which can program it But Ive never managed to make any headway Evidently documentation matters more than fancy language features [at least to me] From tjol at tjol.eu Tue Dec 19 10:11:07 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 19 Dec 2017 16:11:07 +0100 Subject: [OT] Python and Excel In-Reply-To: References: Message-ID: <69cef131-6e00-85c7-c942-0d9f27015ca3@tjol.eu> On 2017-12-18 20:16, MRAB wrote: > Those who use Excel might find this interesting: > > Microsoft Considers Adding Python as an Official Scripting Language to > Excel > https://www.bleepingcomputer.com/news/microsoft/microsoft-considers-adding-python-as-an-official-scripting-language-to-excel/ > I don't use Excel, but if this happens it could be really good news for IronPython. -- Thomas Jollans From Ziggy at Free.net Tue Dec 19 13:33:42 2017 From: Ziggy at Free.net (Ziggy) Date: Tue, 19 Dec 2017 18:33:42 GMT Subject: Tkinter,show pictures from the list of files in catalog-problem Message-ID: I have a problem with this code, it seems to work but.... first it shows the picture then supposed to iterate through file list and shows them each changed after 3seconds however show just the last one from list. https://paste.pound-python.org/show/txvB4IBtlUrn3TuB0rtu/ From rhodri at kynesim.co.uk Tue Dec 19 13:55:00 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 Dec 2017 18:55:00 +0000 Subject: Tkinter,show pictures from the list of files in catalog-problem In-Reply-To: References: Message-ID: <90098c9e-e3ff-d46a-ba04-5abbeed7129e@kynesim.co.uk> On 19/12/17 18:33, Ziggy wrote: > I have a problem with this code, it seems to work but.... first it shows > the picture then supposed to iterate through file list and shows them > each changed after 3seconds however show just the last one from list. > https://paste.pound-python.org/show/txvB4IBtlUrn3TuB0rtu/ Nope. Not following a link from someone I don't know (with all due respect) with a URL I don't immediately recognise. If you want help, post your code here, preferably trimmed down to the minimum you need to demonstrate the problem. -- Rhodri James *-* Kynesim Ltd From python at mrabarnett.plus.com Tue Dec 19 14:17:37 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Dec 2017 19:17:37 +0000 Subject: Tkinter,show pictures from the list of files in catalog-problem In-Reply-To: References: Message-ID: On 2017-12-19 18:33, Ziggy wrote: > I have a problem with this code, it seems to work but.... first it shows > the picture then supposed to iterate through file list and shows them > each changed after 3seconds however show just the last one from list. > https://paste.pound-python.org/show/txvB4IBtlUrn3TuB0rtu/ > The function called by .after should return to the tkinter's event loop. If you want to display a sequence of pictures, then the function should call .after to make it call the function again. Here's a slightly reworked version: import collections import os pictures = collections.deque() for folder, subfolders, files in os.walk('/home/vimart/Python/img/'): for file in files: pictures.append(os.path.join(folder, file)) canvas_width = 300 canvas_height =300 master = Tk() canvas = Canvas(master, width=canvas_width, height=canvas_height) canvas.pack() img = PhotoImage(file="sport.gif") canvas.create_image(20,20, anchor=NW, image=img) def change_img(): canvas.delete("all") canvas.img = PhotoImage(file=pictures.popleft()) canvas.create_image(20,20, anchor=NW, image=canvas.img) # If there's more to come, call again later. if pictures: master.after(3000, change_img) master.after(3000, change_img) mainloop() From alister.ware at ntlworld.com Tue Dec 19 15:21:52 2017 From: alister.ware at ntlworld.com (alister) Date: Tue, 19 Dec 2017 20:21:52 GMT Subject: What is wrong with this regex for matching emails? Message-ID: On Mon, 18 Dec 2017 07:57:27 +1100, Ben Finney wrote: > Peng Yu writes: > >> Hi, >> >> I would like to extract "abc at efg.hij.xyz". But it only shows ".hij". > > Others have address this question. I'll answer a separate one: > >> Does anybody see what is wrong with it? Thanks. > > One thing that's wrong with it is that it is far too restrictive. > >> email_regex = >> re.compile('[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)') > > This excludes a great many email addresses that are valid. Please don't > try to restrict a match for email addresses that will exclude actual > email addresses. > > For an authoritative guide to matching email addresses, see RFC 3696 ?3 > . > > A more correct match would boil down to: > > * Match any printable Unicode characters (not just ASCII). > > * Locate the *last* ?@? character. (An email address may contain more > than one ?@? character; you should allow any printable ASCII character > in the local part.) > > * Match the domain part as the text after the last ?@? character. Match > the local part as anything before that character. Reject an address > that has either of these empty. > > * Validate the domain by DNS request. Your program is not an authority > for what domains are valid; the only authority for that is the DNS. > > * Don't validate the local part at all. Your program is not an authority > for what local parts are accepted to the destination host; the only > authority for that is the destination mail host. At which point you have basicaly boiled your test down to @. which is rather pointless there are only 2 reasons why you would want an email anyway 1) Data mining, just to add to your mailing list- in which case even if it validates you still don't know if it is a fake address to prevent spam so validating is pointless 2) it is part of a registration process, in which case if it is incorrect the registration email will not be received & registration cannot be completed so self validating without any effort. -- OMNIVERSAL AWARENESS?? Oh, YEH!! First you need four GALLONS of JELL-O and a BIG WRENCH!! ... I think you drop th'WRENCH in the JELL-O as if it was a FLAVOR, or an INGREDIENT ... ... or ... I ... um ... WHERE'S the WASHING MACHINES? From namenobodywants at gmail.com Tue Dec 19 15:23:24 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Tue, 19 Dec 2017 12:23:24 -0800 (PST) Subject: correctness proof for alpha-beta algorithm In-Reply-To: References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> Message-ID: On Monday, December 18, 2017 at 10:16:07 PM UTC-8, Terry Reedy wrote: > Where or how have you looked so far? How formal do you want? i want full-on formal with lots of rigor and every possible detail spelled out; i've looked in a couple of books but my best lead so far is a paper by knuth called "an analysis of alpha-beta pruning" - what i need is along those lines but with just a few more of the details spelled out peace stm From hasan.diwan at gmail.com Tue Dec 19 15:43:29 2017 From: hasan.diwan at gmail.com (Hasan Diwan) Date: Tue, 19 Dec 2017 12:43:29 -0800 Subject: [Python-Dev] [RELEASE] Python 3.6.4 is now available In-Reply-To: <24E5A059-9558-4D15-B846-82A771FEC188@python.org> References: <24E5A059-9558-4D15-B846-82A771FEC188@python.org> Message-ID: Grats to all! On 19 December 2017 at 00:42, Ned Deily wrote: > On behalf of the Python development community and the Python 3.6 > release team, I am happy to announce the availability of Python 3.6.4, > the fourth maintenance release of Python 3.6. Detailed information > about the changes made in 3.6.4 can be found in the change log here: > > https://docs.python.org/3.6/whatsnew/changelog.html#python-3-6-4-final > > Please see "What?s New In Python 3.6" for more information about the > new features in Python 3.6: > > https://docs.python.org/3.6/whatsnew/3.6.html > > You can download Python 3.6.4 here: > > https://www.python.org/downloads/release/python-364/ > > The next maintenance release of Python 3.6 is expected to follow in > about 3 months, around the end of 2018-03. More information about the > 3.6 release schedule can be found here: > > https://www.python.org/dev/peps/pep-0494/ > > Enjoy! > > -- > Ned Deily > nad at python.org -- [] > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ > hasan.diwan%40gmail.com > -- OpenPGP: https://sks-keyservers.net/pks/lookup?op=get&search=0xFEBAD7FFD041BBA1 If you wish to request my time, please do so using http://bit.ly/hd1ScheduleRequest. Si vous voudrais faire connnaisance, allez a http://bit.ly/hd1ScheduleRequest. Sent from my mobile device Envoye de mon portable From rosuav at gmail.com Tue Dec 19 16:21:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Dec 2017 08:21:02 +1100 Subject: What is wrong with this regex for matching emails? In-Reply-To: References: Message-ID: On Wed, Dec 20, 2017 at 7:21 AM, alister via Python-list wrote: > On Mon, 18 Dec 2017 07:57:27 +1100, Ben Finney wrote: >> A more correct match would boil down to: >> >> * Match any printable Unicode characters (not just ASCII). >> >> * Locate the *last* ?@? character. (An email address may contain more >> than one ?@? character; you should allow any printable ASCII character >> in the local part.) >> >> * Match the domain part as the text after the last ?@? character. Match >> the local part as anything before that character. Reject an address >> that has either of these empty. >> >> * Validate the domain by DNS request. Your program is not an authority >> for what domains are valid; the only authority for that is the DNS. >> >> * Don't validate the local part at all. Your program is not an authority >> for what local parts are accepted to the destination host; the only >> authority for that is the destination mail host. > > At which point you have basicaly boiled your test down to > @. which is rather pointless Not quite. Firstly, I would exclude all whitespace from your matchable characters; even though technically you CAN have spaces in email addresses, that'll almost never happen, and it's a lot more common to delimit with whites. Secondly, there's actually no requirement to have a dot in the domain part (and Ben never said so). However, you can straight-forwardly validate the domain by attempting a lookup. rosuav at sikorsky:~$ dig +short mx ntlworld.com 1 mx.tb.ukmail.iss.as9143.net. 1 mx.mnd.ukmail.iss.as9143.net. rosuav at sikorsky:~$ dig +short mx benfinney.id.au 10 in1-smtp.messagingengine.com. 20 in2-smtp.messagingengine.com. rosuav at sikorsky:~$ dig +short mx dud.example.off.rosuav.com rosuav at sikorsky:~$ If there are no MX records for a domain, either the domain doesn't exist, or it doesn't receive mail. (Remove the "+short" for a more verbose report, in which case the failure state is a return code of NXDOMAIN.) > there are only 2 reasons why you would want an email anyway > > 1) Data mining, just to add to your mailing list- in which case even if > it validates you still don't know if it is a fake address to prevent spam > so validating is pointless > > 2) it is part of a registration process, in which case if it is incorrect > the registration email will not be received & registration cannot be > completed so self validating without any effort. 3) You're building a text display system (forum posts, text chat, etc, etc) and want to have web links and email addresses automatically become clickable 4) You ask a user to provide "contact information". If s/he provides an email address, you automatically send emails; if a phone number, you automatically send SMS/text messages; otherwise, you leave it up to a human to contact the user. Plenty of possibilities beyond those two. Don't assume there's nothing else that can be done just because your imagination can't come up with anything :) ChrisA From alister.ware at ntlworld.com Tue Dec 19 17:12:01 2017 From: alister.ware at ntlworld.com (alister) Date: Tue, 19 Dec 2017 22:12:01 GMT Subject: What is wrong with this regex for matching emails? References: Message-ID: On Wed, 20 Dec 2017 08:21:02 +1100, Chris Angelico wrote: > On Wed, Dec 20, 2017 at 7:21 AM, alister via Python-list > wrote: >> On Mon, 18 Dec 2017 07:57:27 +1100, Ben Finney wrote: >>> A more correct match would boil down to: >>> >>> * Match any printable Unicode characters (not just ASCII). >>> >>> * Locate the *last* ?@? character. (An email address may contain more >>> than one ?@? character; you should allow any printable ASCII >>> character in the local part.) >>> >>> * Match the domain part as the text after the last ?@? character. >>> Match >>> the local part as anything before that character. Reject an address >>> that has either of these empty. >>> >>> * Validate the domain by DNS request. Your program is not an authority >>> for what domains are valid; the only authority for that is the DNS. >>> >>> * Don't validate the local part at all. Your program is not an >>> authority >>> for what local parts are accepted to the destination host; the only >>> authority for that is the destination mail host. >> >> At which point you have basicaly boiled your test down to >> @. which is rather pointless > > Not quite. Firstly, I would exclude all whitespace from your matchable > characters; even though technically you CAN have spaces in email > addresses, that'll almost never happen, and it's a lot more common to > delimit with whites. Secondly, there's actually no requirement to have a > dot in the domain part (and Ben never said so). However, you can > straight-forwardly validate the domain by attempting a lookup. > > rosuav at sikorsky:~$ dig +short mx ntlworld.com 1 > mx.tb.ukmail.iss.as9143.net. > 1 mx.mnd.ukmail.iss.as9143.net. > rosuav at sikorsky:~$ dig +short mx benfinney.id.au 10 > in1-smtp.messagingengine.com. > 20 in2-smtp.messagingengine.com. > rosuav at sikorsky:~$ dig +short mx dud.example.off.rosuav.com > rosuav at sikorsky:~$ > > If there are no MX records for a domain, either the domain doesn't > exist, or it doesn't receive mail. (Remove the "+short" for a more > verbose report, in which case the failure state is a return code of > NXDOMAIN.) > >> there are only 2 reasons why you would want an email anyway >> >> 1) Data mining, just to add to your mailing list- in which case even if >> it validates you still don't know if it is a fake address to prevent >> spam so validating is pointless >> >> 2) it is part of a registration process, in which case if it is >> incorrect the registration email will not be received & registration >> cannot be completed so self validating without any effort. > > 3) You're building a text display system (forum posts, text chat, etc, > etc) and want to have web links and email addresses automatically become > clickable possible but again if people making the posts want to be contacted & will list a working email address, more likely it will be munged to stop the spammers from harvesting it. otherwise if an emaikl has to be given they will provide a valid looking fake. > > 4) You ask a user to provide "contact information". If s/he provides an > email address, you automatically send emails; if a phone number, you > automatically send SMS/text messages; otherwise, you leave it up to a > human to contact the user. > I can see auto detecting between a Tel no & an email may be a plausible desire, you now have 2 problems because not only are email address so difficult to validate that it is not worth the effort telephone numbers are also to variable to validate reliably (assuming an international audience) > Plenty of possibilities beyond those two. Don't assume there's nothing > else that can be done just because your imagination can't come up with > anything :) Indeed the most obvious other reason is scraping web pages Newsgroups & forums for email addresses to spam & I am sure no-one wants to help with that > > ChrisA -- I know you believe you understand what you think this fortune says, but I'm not sure you realize that what you are reading is not what it means. From random832 at fastmail.com Tue Dec 19 17:44:37 2017 From: random832 at fastmail.com (Random832) Date: Tue, 19 Dec 2017 17:44:37 -0500 Subject: What is wrong with this regex for matching emails? In-Reply-To: References: <1513579402.896660.1208374440.26EBC426@webmail.messagingengine.com> Message-ID: <1513723477.2337238.1210565552.6FD4418D@webmail.messagingengine.com> On Mon, Dec 18, 2017, at 02:01, Chris Angelico wrote: > Hmm, is that true? I was under the impression that the quoting rules > were impossible to match with a regex. Or maybe it's just that they're > impossible to match with a *standard* regex, but the extended > implementations (including Python's, possibly) are able to match them? What's impossible to match with a regex are the comments permitted by RFC822 (which are delimited by balanced parentheses - AIUI perl can do it, python can't.) Which are, according to my argument, not part of the address. > Anyhow, it is FAR from simple; and also, for the purpose of "detect > email addresses in text documents", not desirable. Same as with URL > detection - it's better to have a handful of weird cases that don't > autolink correctly than to mis-detect any address that's at the end of > a sentence, for instance. For that purpose, it's better to ignore the > RFC and just craft a regex that matches *common* email address > formats. Email addresses don't, according to the formal spec, allow a dot at the end of the domain part. I was half-seriously proposing that as an extension (since DNS names *do*). From steve+python at pearwood.info Tue Dec 19 18:28:13 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Dec 2017 10:28:13 +1100 Subject: correctness proof for alpha-beta algorithm References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> Message-ID: <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Dec 2017 07:23 am, namenobodywants at gmail.com wrote: > On Monday, December 18, 2017 at 10:16:07 PM UTC-8, Terry Reedy wrote: > >> Where or how have you looked so far? How formal do you want? > > i want full-on formal with lots of rigor and every possible detail spelled > out; i've looked in a couple of books but my best lead so far is a paper by > knuth called "an analysis of alpha-beta pruning" - what i need is along > those lines but with just a few more of the details spelled out Does this have anything specifically to do with Python programming? If not, why are you asking here? Do you think that Python programmers are especially well-known for their hard-core formal academic methodology? Have you tried searching on Google Scholar? We're pretty accepting of off-topic posts here, especially when they evolve naturally from an on-topic post. But in future, if you're going to *start* an off-topic thread from the first post, it would be polite to label it such with an "[OT]" or "Off-topic" prefix to the subject line. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From c.buhtz at posteo.jp Tue Dec 19 18:42:49 2017 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Wed, 20 Dec 2017 00:42:49 +0100 Subject: Python: asyncio and Tkinter Message-ID: <3z1ZG23Kc6z9rxF@submission02.posteo.de> I am looking for an "elegant" and "official" way to use asyncio in Tkinter applications. The goal is that the GUI is not freezing while doing some download-tasks (over 100 files from different locations). I am looking around on the web for solutions but couldn't find one. Only some workarounds with unknown and possible sideffects. I asked the same question on StackOverflow with a MWE On my current state I wouuld say there is not an official solution for this. asyncio and Tkinter are not build to work together without dirty hacks. Do you have other informations? I think about combining asyncio with multithreading so the asyncio event loop has it's own thread and is not blocking the GUI event loop. Or using only multithreading. From bgailer at gmail.com Tue Dec 19 18:56:10 2017 From: bgailer at gmail.com (bob gailer) Date: Tue, 19 Dec 2017 18:56:10 -0500 Subject: adding elif to for Message-ID: <825693ae-1c7f-2ad0-7b15-7504961520fa@gmail.com> Has any thought been given to adding elif to the for statement? for x in foo: ??? if y: break elif a==b: ??? something else: ??? something else as a shortcut to: for x in foo: ??? if y: break else: ??? if a==b: ??????? something else: ??????? something else bob gailer From BILL_NOSPAM at Noway.net Tue Dec 19 19:05:53 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Tue, 19 Dec 2017 19:05:53 -0500 Subject: adding elif to for In-Reply-To: References: <825693ae-1c7f-2ad0-7b15-7504961520fa@gmail.com> Message-ID: bob gailer wrote: > Has any thought been given to adding elif to the for statement? I don't think it is a good idea because it needlessly, from my point of view, embeds too much complexity into a single construct (making it more difficult to maintain, for instance). That's what language designer's do though--they kick ideas like that around. If you have a great idea, maybe propose a new language. > > for x in foo: > if y: break > elif a==b: > something > else: > something else > > as a shortcut to: > for x in foo: > if y: break > else: > if a==b: > something > else: > something else > bob gailer From skip.montanaro at gmail.com Tue Dec 19 19:16:04 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 19 Dec 2017 18:16:04 -0600 Subject: adding elif to for In-Reply-To: <825693ae-1c7f-2ad0-7b15-7504961520fa@gmail.com> References: <825693ae-1c7f-2ad0-7b15-7504961520fa@gmail.com> Message-ID: Has any thought been given to adding elif to the for statement? Time machine at work I think: https://docs.python.org/3/reference/compound_stmts.html#the-if-statement Skip From skip.montanaro at gmail.com Tue Dec 19 19:17:14 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 19 Dec 2017 18:17:14 -0600 Subject: adding elif to for In-Reply-To: References: <825693ae-1c7f-2ad0-7b15-7504961520fa@gmail.com> Message-ID: Apologies. Misread your question. Skip On Dec 19, 2017 6:16 PM, "Skip Montanaro" wrote: > > Has any thought been given to adding elif to the for statement? > > > Time machine at work I think: > > https://docs.python.org/3/reference/compound_stmts.html#the-if-statement > > Skip > From steve+python at pearwood.info Wed Dec 20 00:52:26 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Dec 2017 16:52:26 +1100 Subject: [META] Are the list admins honouring Posting Prohibited demands? Message-ID: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> This is possibly a question for the list admins... I notice that Lawrence D?Oliveiro has taken up labelling his posts with a demand that his posts are not to be posted to the Python-List mailing list. I also see that his posts are not showing up on the mailing list archive. Is this a coincidence or a direct consequence of his demand? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From greg.ewing at canterbury.ac.nz Wed Dec 20 03:27:14 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 20 Dec 2017 21:27:14 +1300 Subject: [META] Are the list admins honouring Posting Prohibited demands? In-Reply-To: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> References: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > I notice that Lawrence D?Oliveiro has taken up labelling his posts with a > demand that his posts are not to be posted to the Python-List mailing list. I don't think it's a demand. I gather that he has been banned from posting on the Python mailing lists, and I think he's just saying "I'm posting this here because I'm prohibited from posting on python-list." That's what I took it to mean, anyway. -- Greg From mail at timgolden.me.uk Wed Dec 20 04:16:06 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 20 Dec 2017 09:16:06 +0000 Subject: [META] Are the list admins honouring Posting Prohibited demands? In-Reply-To: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> References: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> Message-ID: <7383e28b-5f35-4888-4b8b-29dae6aac6c6@timgolden.me.uk> On 20/12/2017 05:52, Steve D'Aprano wrote: > This is possibly a question for the list admins... > > I notice that Lawrence D?Oliveiro has taken up labelling his posts with a > demand that his posts are not to be posted to the Python-List mailing list. > > I also see that his posts are not showing up on the mailing list archive. Is > this a coincidence or a direct consequence of his demand? I'm not going to comment on the specific situation of Lawrence D'O posts. What I will say is: * If someone were to ask specifically that we don't gateway their Usenet posts to the list, I can see no reason that we wouldn't honour that request. I'm not entirely sure about the reverse (list->Usenet) but AFAIK no-one's ever asked! I imagine it's possible. * At different times we have decided to hold or discard posts made by certain people or servers or matching certain criteria, whether they're made via the list or gatewayed in from Usenet. The reasons are various but are usually obvious. Sometimes this is permanent; sometimes it's temporary. * [I'm fairly sure] The Mailman software which runs the list will honour no-archive headers. That is, it will gateway a given Usenet post to the list but will not include it in the archive. TJG From robin at reportlab.com Wed Dec 20 04:25:57 2017 From: robin at reportlab.com (Robin Becker) Date: Wed, 20 Dec 2017 09:25:57 +0000 Subject: Python Templating Language In-Reply-To: References: Message-ID: On 17/12/2017 06:41, Abdur-Rahmaan Janhangeer wrote: > Hi all, > > Can somebody point out to me some py-based template languages interpreters > resources? > > Thank you ! > https://bitbucket.org/rptlab/preppy -- Robin Becker From arj.python at gmail.com Wed Dec 20 07:27:20 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 20 Dec 2017 16:27:20 +0400 Subject: Python Templating Language In-Reply-To: References: Message-ID: The sources of preppy are very nice! Thank you! On Wed, Dec 20, 2017 at 1:25 PM, Robin Becker wrote: > On 17/12/2017 06:41, Abdur-Rahmaan Janhangeer wrote: > >> Hi all, >> >> Can somebody point out to me some py-based template languages interpreters >> resources? >> >> Thank you ! >> >> https://bitbucket.org/rptlab/preppy > -- > Robin Becker > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed Dec 20 08:42:47 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Dec 2017 00:42:47 +1100 Subject: Python: asyncio and Tkinter In-Reply-To: <3z1ZG23Kc6z9rxF@submission02.posteo.de> References: <3z1ZG23Kc6z9rxF@submission02.posteo.de> Message-ID: On Wed, Dec 20, 2017 at 10:42 AM, wrote: > I am looking for an "elegant" and "official" way to use asyncio in > Tkinter applications. The goal is that the GUI is not freezing while > doing some download-tasks (over 100 files from different locations). > > ... > > I think about combining asyncio with multithreading so the asyncio > event loop has it's own thread and is not blocking the GUI event loop. > Or using only multithreading. I would recommend threading. You can run your GUI event loop on one thread, and your network I/O loop on another thread. Both threads spend the bulk of their time blocked on I/O, and you've limited yourself to a finite number of threads (as opposed to a pure threaded approach with every download is run on a separate thread), so resource consumption should be reasonable. ChrisA From jeanpierreda at gmail.com Wed Dec 20 08:48:43 2017 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 20 Dec 2017 05:48:43 -0800 Subject: binary decision diagrams In-Reply-To: References: Message-ID: On Mon, Dec 18, 2017 at 5:00 AM, Wild, Marcel, Dr wrote: > Hello everybody: > I really don't know anything about Python (I'm using Mathematica) but with the help of others learned that > > g=expr2bdd(f) > > makes the BDD (=binary decision diagram) g of a Boolean function f. But what is the easiest (fool-proof) way to print out a diagram of g ? Python doesn't come with support for (ro)bdds built-in. You're probably thinking of this library, which includes visualization instructions: http://pyeda.readthedocs.io/en/latest/bdd.html -- Devin From rustompmody at gmail.com Wed Dec 20 08:50:47 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 20 Dec 2017 05:50:47 -0800 (PST) Subject: [META] Are the list admins honouring Posting Prohibited demands? In-Reply-To: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> References: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> Message-ID: FYI: On Wednesday, December 20, 2017 at 11:22:52 AM UTC+5:30, Steve D'Aprano wrote: > This is possibly a question for the list admins... > > I notice that Lawrence D?Oliveiro has taken up labelling his posts with a > demand that his posts are not to be posted to the Python-List mailing list. Lawrence D?Oliveiro was banned on 30 Sept 2016 https://groups.google.com/d/msg/comp.lang.python/5dNmgPvXR7U/iRSEp4LrBQAJ > > I also see that his posts are not showing up on the mailing list archive. Is > this a coincidence or a direct consequence of his demand? Ban is supposed to have ended as of June 23 2017 (end of thread). Evidently not?? https://groups.google.com/d/msg/comp.lang.python/yQEarGwOl6M/1e-mJg3FBQAJ From tjol at tjol.eu Wed Dec 20 09:54:07 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 20 Dec 2017 15:54:07 +0100 Subject: [META] Are the list admins honouring Posting Prohibited demands? In-Reply-To: References: <5a39fa9a$0$6334$b1db1813$d948b532@news.astraweb.com> Message-ID: <1b87d570-78f1-0690-2a52-6473e322e5eb@tjol.eu> On 2017-12-20 14:50, Rustom Mody wrote: > FYI: > > On Wednesday, December 20, 2017 at 11:22:52 AM UTC+5:30, Steve D'Aprano wrote: >> This is possibly a question for the list admins... >> >> I notice that Lawrence D?Oliveiro has taken up labelling his posts with a >> demand that his posts are not to be posted to the Python-List mailing list. > > > Lawrence D?Oliveiro was banned on 30 Sept 2016 > https://groups.google.com/d/msg/comp.lang.python/5dNmgPvXR7U/iRSEp4LrBQAJ > > >> >> I also see that his posts are not showing up on the mailing list archive. Is >> this a coincidence or a direct consequence of his demand? > > > Ban is supposed to have ended as of June 23 2017 (end of thread). Evidently not?? Who knows. Sometimes posts of his turn up, sometimes people reply to posts of his that didn't turn up. > > https://groups.google.com/d/msg/comp.lang.python/yQEarGwOl6M/1e-mJg3FBQAJ > -- Thomas Jollans From larry.martell at gmail.com Wed Dec 20 10:27:57 2017 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 20 Dec 2017 10:27:57 -0500 Subject: Python Learning In-Reply-To: <8737474wht.fsf@elektro.pacujo.net> References: <939425528@f38.n261.z1.binkp.net> <87vah53rxy.fsf@elektro.pacujo.net> <87o9mw4j3i.fsf@elektro.pacujo.net> <87d13c413q.fsf@elektro.pacujo.net> <6b1a91cf-932c-ed89-fade-e175e66a4d54@kynesim.co.uk> <878te03sjc.fsf@elektro.pacujo.net> <8737474wht.fsf@elektro.pacujo.net> Message-ID: On Mon, Dec 18, 2017 at 3:22 PM, Marko Rauhamaa wrote: > > Larry Martell : > > > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: > >> However, one great way to stand out is a portfolio of GitHub > >> projects. Several people have gotten an offer largely based on those > >> (after they aced the technical interviews). For example, we just > >> hired someone who had written a game in sed. That doesn't make him an > >> "interesting person," nor do we look for game or sed developers. But > >> that silly exercise deeply resonated with our team. We expect to have > >> great synergy with him. > > > > I have been excluded from even getting an interview because I did not > > have a portfolio of GitHub projects. I think that is a bad filter. I > > work 60-70 hours a week for pay, and I have a family and personal > > interests. > > Personal programming projects are not a requirement. They are just a > very effective advertising tool. > > As for 60?70 hours a week... sounds horrible. My sympathies. Nah - I get paid by the hour and I love what I do. From geoff.bache at gmail.com Wed Dec 20 11:13:02 2017 From: geoff.bache at gmail.com (geoff.bache at gmail.com) Date: Wed, 20 Dec 2017 08:13:02 -0800 (PST) Subject: Problems with imports on multiple threads, with embedded Python Message-ID: <48311546-1f0a-4f86-8882-79ae3ba387fa@googlegroups.com> Hi all, I have a multithreaded application using an embedded Python 3.6.4 (upgraded from 3.6.2 today in the hope that the problem was now solved: it doesn't seem to be). The standard library is in a zip file. So long as only one thread is running Python at a time it seems to work fine. But there seems to be a problem with the module importing when several Python threads are active. I get a variety of errors indeterministically, usually indicating that some symbol hasn't been imported. This occurs both in my own code and in the standard library. The most frequent is probably this line: dt = datetime.strptime(dtStr, fromFmt) which produces AttributeError: module '_strptime' has no attribute '_strptime_datetime' at random. Does anyone have any insight into this problem? Regards, Geoff Bache From Ziggy at Free.net Wed Dec 20 12:07:57 2017 From: Ziggy at Free.net (Ziggy) Date: Wed, 20 Dec 2017 17:07:57 GMT Subject: Tkinter,show pictures from the list of files in catalog-problem References: Message-ID: On 2017-12-19, MRAB wrote: >> > The function called by .after should return to the tkinter's event loop. > If you want to display a sequence of pictures, then the function should > call .after to make it call the function again. > > Here's a slightly reworked version: Thanks. I like your solution, thanks to you I've learned about os.walk, indeed makes everything easy. Thanks again From kirillbalunov at gmail.com Wed Dec 20 14:43:09 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Wed, 20 Dec 2017 22:43:09 +0300 Subject: Using the variable type annotation syntax as a placeholder in a nonlocal scope? Message-ID: I've asked the same question on StackOverflow, but it seems to me that it is opinion based and will be ignored. So I ask for advice here: Since PEP 526 -- Syntax for Variable Annotations was approved, in Python 3.6+ it is possible to provide type hint information in the form *x: int*, also the PEP says "However, annotating a local variable will cause the interpreter to always make it local to the scope and leaves the variable uninitialized". Therefore in Python 3.6+ it is syntactically legal to write: def outer(): x: int def inner(): nonlocal x x = 10 inner() print(x) while the above snippet is semantically more equivalent to: def outer(): #x def inner(): nonlocal x x = 10 inner() print(x) Which is obviously a *SyntaxError: no binding for nonlocal 'x' found`*, sorry for the pun. Also there is nothing said about this style in PEP 8 and Python 3.6 docs. So should I consider this as a bug, or an implementation detail (side effect), or a wart, or a feature? To clarify the purpose of the question - we can not come to a consensus and I would like to hear your opinion and possible pitfalls, if any, if we choose to use this form in our codebase. With kind regards, -gdg From c.buhtz at posteo.jp Wed Dec 20 15:26:10 2017 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Wed, 20 Dec 2017 21:26:10 +0100 Subject: Python: asyncio and Tkinter In-Reply-To: References: <3z1ZG23Kc6z9rxF@submission02.posteo.de> Message-ID: <3z25rn0KgXz9rxP@submission02.posteo.de> X-Post: Dear Chris. On 2017-12-21 00:42 Chris Angelico wrote: > I would recommend threading. You can run your GUI event loop on one > thread, and your network I/O loop on another thread. Thank you very much for your answer. It also came to my mind to separate each loop in it's own thread. But I am for a way from being a professional in that topics. I created a minimal working example to ask that question on StackOVerflow, too. There is no multithreading in that example. Now I modified that example "based" on your solution. But the GUI is still freezing why my tasks are working. Your solution is a bit to complex for me and use some technics (the server think) I don't know. Could you please throw an eye on the current state of my code? From namenobodywants at gmail.com Wed Dec 20 15:56:52 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Wed, 20 Dec 2017 12:56:52 -0800 (PST) Subject: correctness proof for alpha-beta algorithm In-Reply-To: <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> Message-ID: <3c058232-8e2c-4a93-89ff-ebbbfd50523e@googlegroups.com> On Tuesday, December 19, 2017 at 3:28:39 PM UTC-8, Steve D'Aprano wrote: > Does this have anything specifically to do with Python programming? i'm working on a game-playing script (ie: in python), i want to incorporate pruning into my search algorithm, and i'd like to understand why it works; i'm not sure if that counts > If not, why are you asking here? Do you think that Python programmers are > especially well-known for their hard-core formal academic methodology? maybe i just think python programmers are smart or well-informed or something like that > We're pretty accepting of off-topic posts here, especially when they evolve > naturally from an on-topic post. But in future, if you're going to *start* an > off-topic thread from the first post, it would be polite to label it such > with an "[OT]" or "Off-topic" prefix to the subject line. can do From namenobodywants at gmail.com Wed Dec 20 16:00:27 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Wed, 20 Dec 2017 13:00:27 -0800 (PST) Subject: correctness proof for alpha-beta algorithm In-Reply-To: <87lghy18tv.fsf@nightsong.com> References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> <87lghy18tv.fsf@nightsong.com> Message-ID: On Tuesday, December 19, 2017 at 5:34:17 PM UTC-8, Paul Rubin wrote: > It frankly sounds like homework. https://en.wikipedia.org/wiki/Theorem From BILL_NOSPAM at Noway.net Wed Dec 20 16:37:44 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Wed, 20 Dec 2017 16:37:44 -0500 Subject: correctness proof for alpha-beta algorithm In-Reply-To: <3c058232-8e2c-4a93-89ff-ebbbfd50523e@googlegroups.com> References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> <3c058232-8e2c-4a93-89ff-ebbbfd50523e@googlegroups.com> Message-ID: namenobodywants at gmail.com wrote: > On Tuesday, December 19, 2017 at 3:28:39 PM UTC-8, Steve D'Aprano wrote: > >> Does this have anything specifically to do with Python programming? > i'm working on a game-playing script (ie: in python), i want to incorporate pruning into my search algorithm, and i'd like to understand why it works; i'm not sure if that counts Based upon your posts, I think you should just write your own. Then you can be sure that it will work. That's better than working with something that you don't understand. From steve+python at pearwood.info Wed Dec 20 18:33:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 21 Dec 2017 10:33:22 +1100 Subject: correctness proof for alpha-beta algorithm References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> <3c058232-8e2c-4a93-89ff-ebbbfd50523e@googlegroups.com> Message-ID: <5a3af343$0$6348$b1db1813$d948b532@news.astraweb.com> On Thu, 21 Dec 2017 08:37 am, Bill wrote: > namenobodywants at gmail.com wrote: >> On Tuesday, December 19, 2017 at 3:28:39 PM UTC-8, Steve D'Aprano wrote: >> >>> Does this have anything specifically to do with Python programming? >> i'm working on a game-playing script (ie: in python), i want to incorporate >> pruning into my search algorithm, and i'd like to understand why it works; >> i'm not sure if that counts > > Based upon your posts, I think you should just write your own. Then you > can be sure that it will work. How long did you say you've been programming? Perhaps you've heard of something we in the programming world call "bugs". -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From Irv at furrypants.com Wed Dec 20 18:56:33 2017 From: Irv at furrypants.com (Irv Kalb) Date: Wed, 20 Dec 2017 15:56:33 -0800 Subject: property decorator? Message-ID: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> I am trying to work through the concept of the @property decorator with respect to object oriented programming. I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance variables into method calls in an object. It seems like these two decorators are essentially fancy substitutes for traditional getter and setter methods. But, I'm having a hard time understanding why these names were chosen. I have the following example code: class Employee(): def __init__(self, name, salary): self.__name = name self.__salary = salary @property def salary(self): print('Getting salary of', self.__name, 'which is:', self.__salary) return self.__salary @salary.setter def salary(self, newSalary): print('Setting salary of', self.__name, 'to:', newSalary) self.__salary = newSalary # Test code: employee1 = Employee('Joe Schmoe', 99999) employee2 = Employee('Jane Smith', 123456) print(employee1.salary) print(employee2.salary) employee1.salary = 100000 employee2.salary = 222222 print(employee1.salary) print(employee2.salary) When it runs, I get the results I expect: Getting salary of Joe Schmoe which is: 99999 99999 Getting salary of Jane Smith which is: 123456 123456 Setting salary of Joe Schmoe to: 100000 Setting salary of Jane Smith to: 222222 Getting salary of Joe Schmoe which is: 100000 100000 Getting salary of Jane Smith which is: 222222 222222 My questions about this are really historical. From my reading, it looks like using an @property decorator is a reference to an older approach using a built in "property" function. But here goes: 1) Why were these decorator names chosen? These two names @property and @.setter don't seem to be very clear to me. At a minimum, they don't match. Wouldn't decorator names like @.getter and @.setter have been better - more explicit? 2) Alternatively, if the getter was going to use the @property decorator, then it would seem complimentary to have the decorator name for the associated setter function to have the word "property" in its also, something like @propertySetter. 3) If I create a method with the @property decorator, is there anything else that is implied about the name of the method other than you can now refer to the . - which calls the appropriate method? My guess/understanding is that in my example above, "salary" is considered the property name, which is how you would refer to it outside of the object. Inside the class, you use the property name as the name of both the setter and the getter methods. Is that the right way to think about it? Finally, it seems very odd to me that when you use the @property decorator and the @.setter, that both of the methods that are decorated need to have the same name (but of course different set of parameters.) As a teacher, this seems like it would be an extremely difficult concept to get across to students, as this does not work the same way as other Python functions (and methods). Without a decorator, the second function of the same name overrides an earlier function of the same name, as in this simple example: def myFunction( ): print('In first version of myFunction') def myFunction( ): print('In second version of myFunction') myFunction() Which prints: In second version of myFunction My most recent language before Python was ActionScript 3 (the language of Flash). It implemented a similar concept of being able to use what appeared to be an explicit data reference which turns into a method call, like this example (from StackOverflow): private var _loggy:String; public function get loggy ():String { return _loggy; } public function set loggy ( loggy:String ):void { // checking to make sure loggy's new value is kosher etc... _loggy = loggy; } This syntax made the concept easy to understand and implement in an ActionScript class (even though it also uses the same name for both function). I do NOT want to start any kind of language flame war. I am really just trying to understand the reasons behind why this concept is implemented in Python this way, so that I can wrap my head around it and teach it effectively in my classes. Irv From rgaddi at highlandtechnology.invalid Wed Dec 20 19:25:33 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 20 Dec 2017 16:25:33 -0800 Subject: property decorator? In-Reply-To: References: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> Message-ID: On 12/20/2017 03:56 PM, Irv Kalb wrote: > I am trying to work through the concept of the @property decorator with respect to object oriented programming. > > I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance variables into method calls in an object. It seems like these two decorators are essentially fancy substitutes for traditional getter and setter methods. But, I'm having a hard time understanding why these names were chosen. > > [snip] > > My questions about this are really historical. From my reading, it looks like using an @property decorator is a reference to an older approach using a built in "property" function. But here goes: > > 1) Why were these decorator names chosen? These two names @property and @.setter don't seem to be very clear to me. At a minimum, they don't match. Wouldn't decorator names like @.getter and @.setter have been better - more explicit? > > 2) Alternatively, if the getter was going to use the @property decorator, then it would seem complimentary to have the decorator name for the associated setter function to have the word "property" in its also, something like @propertySetter. > > 3) If I create a method with the @property decorator, is there anything else that is implied about the name of the method other than you can now refer to the . - which calls the appropriate method? My guess/understanding is that in my example above, "salary" is considered the property name, which is how you would refer to it outside of the object. Inside the class, you use the property name as the name of both the setter and the getter methods. Is that the right way to think about it? > > > Finally, it seems very odd to me that when you use the @property decorator and the @.setter, that both of the methods that are decorated need to have the same name (but of course different set of parameters.) As a teacher, this seems like it would be an extremely difficult concept to get across to students, as this does not work the same way as other Python functions (and methods). Without a decorator, the second function of the same name overrides an earlier function of the same name, as in this simple example: > > [snip] > > Irv > It's because of how Python implements decorators. When I write class C: def foobar(self): pass I create a binding in the local scope of class C with the name "foobar" that holds a function object. We call this a "local variable" in keeping with other languages, but it's not really the same as it would be in like C, it's a reference in the local namespace to some other object. When I decorate that foobar instead: class C: @property def foobar(self): pass That variable now, instead of referencing a function object, references an instance of type 'property' that holds a reference to the original foobar method as it's "_getter". When I expand that to class C: @property def foobar(self): return self.__foobar @foobar.setter def foobar(self, value): self.__foobar = value The second decoration calls the 'setter' method of the property instance stored in variable name foobar. That method assigns the new method to the "_setter" of that property instance and returns the updated property, which is assigned redundantly to the variable name foobar. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From cs at cskk.id.au Wed Dec 20 19:50:31 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 21 Dec 2017 11:50:31 +1100 Subject: property decorator? In-Reply-To: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> References: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> Message-ID: <20171221005031.GA12197@cskk.homeip.net> On 20Dec2017 15:56, Irv Kalb wrote: >I am trying to work through the concept of the @property decorator with respect to object oriented programming. > >I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance variables into method calls in an object. It seems like these two decorators are essentially fancy substitutes for traditional getter and setter methods. That is correct. In a "pure" OO environment, all internal state would be hidden, and accessed and modified by getters and setters, or by side effects of other methods. Python, like many languages, exposes the internal attributes of objects. Which is convenient, and I for one find pure "getter/setter" methods cumbersome and tedious. A property lets you do a few things: to present some state that lends itself to looking like a plain variable, as a variable; to put constraints on the values set on such a variable (eg to raise exceptions for forbidden values) or to have side effects (eg reducing a Semaphore's capacity might block until enough is released); and to promote something that was formerly a plain old attribute with a value into something more complex while keeping the previous API of accessing the attribute directly. >But, I'm having a hard time understanding why these names were chosen. [...] >My questions about this are really historical. From my reading, it looks like >using an @property decorator is a reference to an older approach using a built >in "property" function. Maybe so; I cannot speak to this. But a property is a well defined Python concept. The "property" decorator is a builtin function (well, a clas sinstance constructor) for creating one from a function, and seems pretty naturally named to me: https://docs.python.org/3/library/functions.html#property >But here goes: > >1) Why were these decorator names chosen? These two names @property and @.setter don't seem to be very clear to me. At a minimum, they don't match. Wouldn't decorator names like @.getter and @.setter have been better - more explicit? Yes, but there's a bootstrap issue: having @.getter work immediately implies that .getter is already an existing function, because the @ syntax applies a function to another function, returning a function. And "getter" is at the least a public name, possibly already in use for something else. Don't forget that @foo is a general system for wrapping functions, and that @property is just one example. So if you have a class: class Klass: @foo def method(self, bah): ... it creates the function "method", and then computes "foo(method)", which normally would return another function that itself calls the original "method", and defines "Klass.method" as that new function. So if you do this: class Klass: @property def method(self): return 3 That defines Klass.method as a property. Until it is a property, you can't talk about Klass.method.setter. And you need to be specific: "method.setter" is a setter for that specific property ("method"). You can't do this: @method.getter def method(self): return 3 because "method" is not yet defined when you say "method.getter". First you need to make it a property, which must be done with something _not_ named "method", because that name doesn't exist to start with. And that something is the builtin function "property", which is used to create properties via the decoator syntax. _After_ that property is made, _then_ you can talk about "method.setter" because properties have a ".setter" method which constructs property setting functions. Hoping this make the _process_ more clear, particularly that "method" isn't known to start with, therefore "method.getter" is not a name you can use. >2) Alternatively, if the getter was going to use the @property decorator, >then it would seem complimentary to have the decorator name for the >associated setter function to have the word "property" in its also, something >like @propertySetter. Because . is a property now, the existingence of a .setter function is implied; onemerely has to use it to define the setter method. >3) If I create a method with the @property decorator, is there anything else that is implied about the name of the method other than you can now refer to the . - which calls the appropriate method? It is the ability to refer to . which is what makes a property a property. As a property, it also has ..setter and ..deleter defined, which are functions which can be used as decorators to define setter and deleter methods. >My guess/understanding is that in my example above, "salary" is considered the >property name, which is how you would refer to it outside of the object. >Inside the class, you use the property name as the name of both the setter and >the getter methods. Is that the right way to think about it? Usually I think of the property "salary" as a "property", which looks like an attribute. Whether I access it from inside or outside the class is irrelevant. Because the property doesn't itself store any state, I'd usually have an internal "_salary" attribute for something simple like this. Other properties might have more complex state or very expressed as some computed value of other state (eg some hypothetical "payroll_tax" which might derive from the salary and not itself have separate state). >Finally, it seems very odd to me that when you use the @property decorator and >the @.setter, that both of the methods that are decorated need >to have the same name (but of course different set of parameters.) As a >teacher, this seems like it would be an extremely difficult concept to get >across to students, as this does not work the same way as other Python >functions (and methods). Actually, it works exactly like other Python functions and methods. You just need to exercise sufficient care. I can also redefine a method, and in the past have made bugs by defining the same method twice (and then changing the first definition, with no effect!) This kind of thing is what lint tools are good at catching, and what some coding styles help prevent (in this case, had I been using a style where all methods were defined in lexical order I might have readily noticed the repeated definition). >Without a decorator, the second function of the same name overrides an earlier >function of the same name, as in this simple example: > >def myFunction( ): > print('In first version of myFunction') > >def myFunction( ): > print('In second version of myFunction') > >myFunction() > >Which prints: In second version of myFunction Yes. A pitfall of a dynamic language where names may be redefined. Treat it as a general issue rather than special to properties (though as you say, it would be easy for a new person to forget the @salary.setter decoration). >My most recent language before Python was ActionScript 3 (the language of >Flash). It implemented a similar concept of being able to use what appeared >to be an explicit data reference which turns into a method call, like this >example (from StackOverflow): > >private var _loggy:String; > >public function get loggy ():String >{ > return _loggy; >} > >public function set loggy ( loggy:String ):void >{ > // checking to make sure loggy's new value is kosher etc... > _loggy = loggy; >} >This syntax made the concept easy to understand and implement in an ActionScript class (even though it also uses the same name for both function). That is kind of neat, though very specific to properties. The @decorator syntax if more general than that, and since it was possible to implement properties using it it is probably considered better to do so than to add further complexity to the language syntax. Which I'm inclined to agree with, though one can certainly argue the other way as well. Cheers, Cameron Simpson (formerly cs at zip.com.au) From pengyu.ut at gmail.com Wed Dec 20 20:42:04 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 20 Dec 2017 19:42:04 -0600 Subject: How to edit a function in an interactive python session? Message-ID: Hi, R has the function edit() which allows the editing of the definition of a function. Does python have something similar so that users can edit python functions on the fly? Thanks. https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit -- Regards, Peng From ben+python at benfinney.id.au Wed Dec 20 22:03:24 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 21 Dec 2017 14:03:24 +1100 Subject: How to edit a function in an interactive python session? References: Message-ID: <858tdwok8z.fsf@benfinney.id.au> Peng Yu writes: > R has the function edit() which allows the editing of the definition > of a function. Does python have something similar so that users can > edit python functions on the fly? Thanks. That would depend on which interactive tool you're using. The typical Python REPL [0] tools ? interactive ?python3?, the enhanced ?ipython3? tool, and so on ? do not, to my knowledge, retain the source code that you enter. They pass it immediately to the Python compiler, and receive back the compiled code object, and use that. The source code is discarded by the time the code is run. So any tool that does what you propose will need to keep that source code around indefinitely, in anticipation of being asked to edit and re-compile it. I think you're asking not for a REPL, but a tool at a higher level known as an IDE [1]. You can use any good IDE, such as Emacs, to edit code and run it interactively. [0] Read, Evaluate, Print, then Loop. [1] Interactive Development Environment. -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From ian.g.kelly at gmail.com Wed Dec 20 22:38:48 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 20 Dec 2017 21:38:48 -0600 Subject: property decorator? In-Reply-To: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> References: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> Message-ID: On Wed, Dec 20, 2017 at 5:56 PM, Irv Kalb wrote: > My questions about this are really historical. From my reading, it looks like using an @property decorator is a reference to an older approach using a built in "property" function. But here goes: > > 1) Why were these decorator names chosen? These two names @property and @.setter don't seem to be very clear to me. At a minimum, they don't match. Wouldn't decorator names like @.getter and @.setter have been better - more explicit? That wouldn't work because @.getter causes Python to look up the variable within the class scope and then its getter attribute. But hasn't been defined yet and won't be until after the getter has been created. > 2) Alternatively, if the getter was going to use the @property decorator, then it would seem complimentary to have the decorator name for the associated setter function to have the word "property" in its also, something like @propertySetter. Perhaps this could have been done, but unlike the getter, the setter is being defined on a property that now already exists. In this case has to be referenced somewhere within the decorator or else the setter property will simply replace the getter property, rather than augment and then replace it. I suppose what it boils down to is that there's no particular reason to look up "property" again since the getter already declared that this is a property. > 3) If I create a method with the @property decorator, is there anything else that is implied about the name of the method other than you can now refer to the . - which calls the appropriate method? My guess/understanding is that in my example above, "salary" is considered the property name, which is how you would refer to it outside of the object. Inside the class, you use the property name as the name of both the setter and the getter methods. Is that the right way to think about it? No, "salary" is the property name regardless of whether you're referring to it from inside or outside of the class definition. With the notable exceptions of super() and double-underscore name mangling, Python generally doesn't care about *where* an attribute or method reference is made from. > Finally, it seems very odd to me that when you use the @property decorator and the @.setter, that both of the methods that are decorated need to have the same name (but of course different set of parameters.) As a teacher, this seems like it would be an extremely difficult concept to get across to students, as this does not work the same way as other Python functions (and methods). Without a decorator, the second function of the same name overrides an earlier function of the same name, as in this simple example: Strictly speaking, they don't *need* to have the same name. This works: class Employee(): def __init__(self, name, salary): self.__name = name self.__salary = salary @property def salary_one(self): print('Getting salary of', self.__name, 'which is:', self.__salary) return self.__salary @salary_one.setter def salary_two(self, newSalary): print('Setting salary of', self.__name, 'to:', newSalary) self.__salary = newSalary The result would be that Employee has a get-only property named salary_one since it was never overwritten, and a get-set property named salary_two that combines the getter from salary_one with a new setter. If you wanted to, you could then: del salary_one and only salary_two would exist as in the usual case. But this is mostly just for demonstration of the object model; there's no practical reason to use different names for each. From steve+python at pearwood.info Wed Dec 20 22:39:37 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 21 Dec 2017 14:39:37 +1100 Subject: How to edit a function in an interactive python session? References: Message-ID: <5a3b2cfa$0$26915$b1db1813$eb6074ea@news.astraweb.com> On Thu, 21 Dec 2017 12:42 pm, Peng Yu wrote: > Hi, > > R has the function edit() which allows the editing of the definition > of a function. Does python have something similar so that users can > edit python functions on the fly? Thanks. > > https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit No. In the standard interactive interpreter, you can only re-enter the function, either re-typing it, or using the readline "history" to call up each line again. (This may not work under Windows.) iPython or Jupyter may offer extra editing functionality. Or you could try creating your own. This might be a good place to start: https://mail.python.org/pipermail/python-list/2014-September/677841.html http://code.activestate.com/recipes/578926-call-out-to-an-external-editor/ Read the full thread -- it has lots of useful information. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Wed Dec 20 22:44:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Dec 2017 14:44:49 +1100 Subject: property decorator? In-Reply-To: References: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> Message-ID: On Thu, Dec 21, 2017 at 2:38 PM, Ian Kelly wrote: > On Wed, Dec 20, 2017 at 5:56 PM, Irv Kalb wrote: >> 2) Alternatively, if the getter was going to use the @property decorator, then it would seem complimentary to have the decorator name for the associated setter function to have the word "property" in its also, something like @propertySetter. > > Perhaps this could have been done, but unlike the getter, the setter > is being defined on a property that now already exists. In this case > has to be referenced somewhere within the decorator or else the > setter property will simply replace the getter property, rather than > augment and then replace it. > > I suppose what it boils down to is that there's no particular reason > to look up "property" again since the getter already declared that > this is a property. It's more than that. It's actually not easy to locate something by its name while you're in process of setting it up. Consider: class Demo: @getter def foo(self): ... @setter def foo(self, value): ... Only one thing can be bound to Demo.foo, which means that that one thing has to be a property capable of calling on the getter and the setter. That means that when setter(foo) is called, it would need to locate the pre-existing "foo" property and augment it. That's actually pretty hard to do reliably (remember that there are many contexts in which this can be called). ChrisA From BILL_NOSPAM at Noway.net Wed Dec 20 23:40:15 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Wed, 20 Dec 2017 23:40:15 -0500 Subject: correctness proof for alpha-beta algorithm In-Reply-To: <5a3af343$0$6348$b1db1813$d948b532@news.astraweb.com> References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> <3c058232-8e2c-4a93-89ff-ebbbfd50523e@googlegroups.com> <5a3af343$0$6348$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Thu, 21 Dec 2017 08:37 am, Bill wrote: > >> namenobodywants at gmail.com wrote: >>> On Tuesday, December 19, 2017 at 3:28:39 PM UTC-8, Steve D'Aprano wrote: >>> >>>> Does this have anything specifically to do with Python programming? >>> i'm working on a game-playing script (ie: in python), i want to incorporate >>> pruning into my search algorithm, and i'd like to understand why it works; >>> i'm not sure if that counts >> Based upon your posts, I think you should just write your own. Then you >> can be sure that it will work. > How long did you say you've been programming? Perhaps you've heard of > something we in the programming world call "bugs". You're supposed to get rid those those. Use Raid! : ) > From rosuav at gmail.com Wed Dec 20 23:59:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Dec 2017 15:59:08 +1100 Subject: correctness proof for alpha-beta algorithm In-Reply-To: References: <4a5b4976-39e4-4fbe-a897-a47273ba5102@googlegroups.com> <5a39a08d$0$6320$b1db1813$d948b532@news.astraweb.com> <3c058232-8e2c-4a93-89ff-ebbbfd50523e@googlegroups.com> <5a3af343$0$6348$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Dec 21, 2017 at 3:40 PM, Bill wrote: > Steve D'Aprano wrote: >> >> On Thu, 21 Dec 2017 08:37 am, Bill wrote: >> >>> namenobodywants at gmail.com wrote: >>>> >>>> On Tuesday, December 19, 2017 at 3:28:39 PM UTC-8, Steve D'Aprano wrote: >>>> >>>>> Does this have anything specifically to do with Python programming? >>>> >>>> i'm working on a game-playing script (ie: in python), i want to >>>> incorporate >>>> pruning into my search algorithm, and i'd like to understand why it >>>> works; >>>> i'm not sure if that counts >>> >>> Based upon your posts, I think you should just write your own. Then you >>> can be sure that it will work. >> >> How long did you say you've been programming? Perhaps you've heard of >> something we in the programming world call "bugs". > > > You're supposed to get rid those those. Use Raid! : ) I tried using software RAID once, but my code was still buggy... ChrisA From rustompmody at gmail.com Thu Dec 21 00:06:07 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 20 Dec 2017 21:06:07 -0800 (PST) Subject: How to edit a function in an interactive python session? In-Reply-To: References: Message-ID: On Thursday, December 21, 2017 at 7:12:24 AM UTC+5:30, Peng Yu wrote: > Hi, > > R has the function edit() which allows the editing of the definition > of a function. Does python have something similar so that users can > edit python functions on the fly? Thanks. > > https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit Dunno What exactly you are asking And I suspect an ?impedance mismatch? between the answers you are receiving and what you seek. Firstly on briefly looking at the R-docs that you quote I see that it does not guarantee a faithful 'deparsing'? which I interpret as saying that R may present to you a different (looking) function on (re) editing than what you typed The real problem is that in the scale of religious dogmas python community puts inter-OS portability/stability etc over and above development environment This means that the tutorial is woefully inadequate (mostly by omission) in terms of recommending a suitable dev environment. And almost suggests that the basic interactive python shell is enough for writing/trying out python code. This is patently false An experienced programmer either: - Writes scripts (or GUI programs or web-apps or ...) using a full-featured editor like vim Or - Uses a dev-environment ? IDLE, emacs, pycharm, pydev, jupyter, org-babel? probably a dozen reasonable choices and hundreds of less reasonable ones In either of these cases the question that you ask does not arise because the code you are working on is always there "in another window" - one click away from being tried out - one click away from being edited (in its actual and not "deparsed" form) I tend to use emacs My students suffer me and my habits As an editor its really clunky obsolete and asinine But its not an editor; its an OS and in that sphere there is nothing else for competition However I would not make this recommendation for emacs over the net [Learning a dev-environment is like learning a musical instrument : not convenient over the net] To a beginner I would recommend IDLE by default unless there is significant data pushing another choice And if you try that you will see your question becomes automatically answered (or irrelevant) From kirillbalunov at gmail.com Thu Dec 21 04:49:27 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Thu, 21 Dec 2017 12:49:27 +0300 Subject: Fwd: property decorator? In-Reply-To: References: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> Message-ID: 2017-12-21 2:56 GMT+03:00 Irv Kalb : > My questions about this are really historical. From my reading, it looks > like using an @property decorator is a reference to an older approach using > a built in "property" function. But here goes: > > 1) Why were these decorator names chosen? These two names @property and > @.setter don't seem to be very clear to me. At a minimum, they don't > match. Wouldn't decorator names like @.getter and @.setter > have been better - more explicit? > > 2) Alternatively, if the getter was going to use the @property decorator, > then it would seem complimentary to have the decorator name for the > associated setter function to have the word "property" in its also, > something like @propertySetter. > > 3) If I create a method with the @property decorator, is there anything > else that is implied about the name of the method other than you can now > refer to the . - which calls the appropriate method? My > guess/understanding is that in my example above, "salary" is considered the > property name, which is how you would refer to it outside of the object. > Inside the class, you use the property name as the name of both the setter > and the getter methods. Is that the right way to think about it? > There are nothing special with decorators, the are simply functions which take at least one argument (of course they can be implemented as classes, but lets make things simple), and *`@decorator*` is a syntactic sugar for *`func = decorator(func)`*. As I see it, the primary idea to introduce them in Python was readability, and possibility for special syntax highlighting and nothing more. To sum it up, while* `property*` is often used as a decorator, the `*property`* built-in is actually a class. So it is not "*an older approach using a built in "property" function*" but in reality it is the same class as it was but can be applied with new decorator syntax. And defined in stdlib as *`class property(fget=None, fset=None, fdel=None, doc=None)`*. Finally, it seems very odd to me that when you use the @property decorator > and the @.setter, that both of the methods that are decorated > need to have the same name (but of course different set of parameters.) As > a teacher, this seems like it would be an extremely difficult concept to > get across to students, as this does not work the same way as other Python > functions (and methods). Without a decorator, the second function of the > same name overrides an earlier function of the same name, as in this simple > example: > This is not true, actually they all work the same way following *descriptor protocol* - the mechanism behind properties, methods, static methods, and others. It is not simple topic, but it essential, I will provide some references which can help you to grasp: Descriptor HowTo Guide brilliant tutorial by Raymond Hettinger, which is a part of official documentation. It is very well written, but if you need more on this topic this books helped me a lot: "*Python in a Nutshell, 2E by Alex Martelli*" while this book covers Python 2.5, the key idea of descriptors was introduced as a part of new style classes in Python 2.2. "*Python Cookbook, 3E by David Beazley and Brian K. Jones*" covers Python 3 with a lot of practical examples. "*Fluent Python by Luciano Ramalho*" especially Chapter 20, but my advise to read the book sequentially. With kind regards, -gdg From Winston.vijay at gsr-inc.com Thu Dec 21 08:11:26 2017 From: Winston.vijay at gsr-inc.com (Winston Manuel Vijay) Date: Thu, 21 Dec 2017 13:11:26 +0000 Subject: =?Windows-1252?Q?Regarding_the_error:_TypeError:_can=92t_pickle_=5Fthread?= =?Windows-1252?Q?.lock_objects?= Message-ID: <4328A44A7D09CB4B818774C0B09D7DE7E320E1D8@SRVEXCH-01.gsr-inc.local> Hi, It would be of immense help, if someone could provide a suitable solution or related information that helps to sort out the below stated issue- ? I had installed the Python version 3.6.4 ? Then I installed the package: Tensorflow ? Installed g2p.exe by downloading from GitHub ? Then tried running the below command- g2p-seq2seq --interactive --model (model_folder_path: is the path to an English model 2-layer LSTM with 512 hidden units CMU Sphinx dictionary downloaded from the CMU Sphinx website) Following the above procedure, I encountered the following error: TypeError: can?t pickle _thread.lock objects-please find the attached screenshot for your reference. Thanks, A.Winston Manuel Vijay ________________________________ This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. This email is sent for the intended recipient(s) only. If by an addressing or transmission error, this mail has been misdirected to you, you are requested to delete this mail immediately. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from GSR e-mail addresses may be monitored. From geoff.bache at gmail.com Thu Dec 21 09:41:46 2017 From: geoff.bache at gmail.com (geoff.bache at gmail.com) Date: Thu, 21 Dec 2017 06:41:46 -0800 (PST) Subject: Problems with imports on multiple threads, with embedded Python In-Reply-To: <4f339841-4d1c-4f72-bdd4-4c00eec35696@googlegroups.com> References: <48311546-1f0a-4f86-8882-79ae3ba387fa@googlegroups.com> <4f339841-4d1c-4f72-bdd4-4c00eec35696@googlegroups.com> Message-ID: <3f04b450-6d5e-49f5-af47-e7b5ca7fdd9e@googlegroups.com> On Thursday, 21 December 2017 00:33:54 UTC+1, Lawrence D?Oliveiro wrote: > On Thursday, December 21, 2017 at 5:13:33 AM UTC+13, geoff... at gmail.com wrote: > > > > I have a multithreaded application using an embedded Python 3.6.4 ... > > Avoid multithreading if you can. Is your application CPU-bound? If not, you are getting no benefit from it. Unfortunately that's not an option. As I say, Python is embedded and is only a part of what the application does. The multithreading is not there for the Python part but is a well-established fact in the application. From rafaeltfreire at gmail.com Thu Dec 21 10:05:33 2017 From: rafaeltfreire at gmail.com (rafaeltfreire at gmail.com) Date: Thu, 21 Dec 2017 07:05:33 -0800 (PST) Subject: Problem with assignment. Python error or mine? Message-ID: Dear community, I am having the following problem when I am assigning the elements of a vector below a certain number to zero or any other value. I am creating a new variable but Python edits the root variable. Why? import numpy as np X=np.arange(1, 10000, 1) #root variable x1=X x1[x1<10000]=0 print(X) Out[1]: array([ 0., 0., 0., ..., 0., 0., 0.]) Why????????? It is supposed to be the original value Thank you for your time Rafael From chololennon at hotmail.com Thu Dec 21 10:08:49 2017 From: chololennon at hotmail.com (Cholo Lennon) Date: Thu, 21 Dec 2017 12:08:49 -0300 Subject: property decorator? References: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> Message-ID: On 20/12/17 21:39, Stefan Ram wrote: > Irv Kalb writes: > about property decorators. > > The code > > @property > def salary(self): pass > > @salary.setter > def salary(self, newSalary): pass > > is an abbreviation for > > def salary_get(self): pass > salary = property( salary_get ) > > def salary_set(self, newSalary): pass > salary = salary.setter( salary_set ) > > . ?property? is a class, ?property( salaray )? constructs an > instance with salary_get as getter and no setter. Later, > ?salary.setter? adds ?salaray_set? as a setter to that > instance. > > One cannot use ?@salary.getter? instead of ?@property?, > because at that point in time, the instance ?salaray? does > not already exist. > Best answser IMHO, it's clear and concise. -- Cholo Lennon Bs.As. ARG From neilc at norwich.edu Thu Dec 21 10:19:20 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Thu, 21 Dec 2017 15:19:20 +0000 (UTC) Subject: Problem with assignment. Python error or mine? References: Message-ID: On 2017-12-21, rafaeltfreire at gmail.com wrote: > Dear community, I am having the following problem when I am > assigning the elements of a vector below a certain number to > zero or any other value. I am creating a new variable but > Python edits the root variable. Why? > > import numpy as np > > X=np.arange(1, 10000, 1) #root variable np.arange creates an object. The assignment makes X refer to that object. > x1=X X refers to the previous object, and then the assignment makes x1 refer to that same object. -- Neil Cerutti From rafaeltfreire at gmail.com Thu Dec 21 10:31:39 2017 From: rafaeltfreire at gmail.com (rafaeltfreire at gmail.com) Date: Thu, 21 Dec 2017 07:31:39 -0800 (PST) Subject: Problem with assignment. Python error or mine? In-Reply-To: References: Message-ID: Em quinta-feira, 21 de dezembro de 2017 16:21:57 UTC+1, Neil Cerutti escreveu: > On 2017-12-21, rafaeltfreire at gmail.com wrote: > > Dear community, I am having the following problem when I am > > assigning the elements of a vector below a certain number to > > zero or any other value. I am creating a new variable but > > Python edits the root variable. Why? > > > > import numpy as np > > > > X=np.arange(1, 10000, 1) #root variable > > np.arange creates an object. The assignment makes X refer to that > object. > > > x1=X > > X refers to the previous object, and then the assignment makes x1 > refer to that same object. > > -- > Neil Cerutti Ok, great thank you. I am kind of new in python. I use to program in MATLAB but I am trying to migrate. So, to fix it what should I do? because my X is an NMR spectrum of many samples. Thank you very much! Rafael From python at mrabarnett.plus.com Thu Dec 21 10:37:02 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Dec 2017 15:37:02 +0000 Subject: Problem with assignment. Python error or mine? In-Reply-To: References: Message-ID: On 2017-12-21 15:05, rafaeltfreire at gmail.com wrote: > Dear community, I am having the following problem when I am assigning the elements of a vector below a certain number to zero or any other value. > I am creating a new variable but Python edits the root variable. Why? > > import numpy as np > > X=np.arange(1, 10000, 1) #root variable > x1=X > x1[x1<10000]=0 > > print(X) > Out[1]: array([ 0., 0., 0., ..., 0., 0., 0.]) > > Why????????? It is supposed to be the original value > Thank you for your time > Rafael > Python never makes a copy unless you ask it to. What x1=X does is make the name x1 refer to the same object that X refers to. No copying. As you're using numpy, you can use the .copy method: x1 = X.copy() This makes the name x1 refer to a new copy of the object that X refers to. From someone at somewhere.invalid Thu Dec 21 12:17:21 2017 From: someone at somewhere.invalid (MarkA) Date: 21 Dec 2017 17:17:21 GMT Subject: Problem with assignment. Python error or mine? References: Message-ID: On Thu, 21 Dec 2017 07:05:33 -0800, rafaeltfreire wrote: >From docs.python.org: 8.10. copy ? Shallow and deep copy operations Source code: Lib/copy.py Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other. This module provides generic shallow and deep copy operations (explained below)... > Dear community, I am having the following problem when I am assigning > the elements of a vector below a certain number to zero or any other > value. > I am creating a new variable but Python edits the root variable. Why? > > import numpy as np > > X=np.arange(1, 10000, 1) #root variable x1=X x1[x1<10000]=0 > > print(X) > Out[1]: array([ 0., 0., 0., ..., 0., 0., 0.]) > > Why????????? It is supposed to be the original value Thank you for your > time Rafael -- MarkA We hang petty theives, and appoint the great theives to public office -- Aesop From python at bladeshadow.org Thu Dec 21 12:46:18 2017 From: python at bladeshadow.org (Python) Date: Thu, 21 Dec 2017 11:46:18 -0600 Subject: Python Learning In-Reply-To: References: Message-ID: <20171221174618.GQ30413@bladeshadow.org> On Fri, Dec 15, 2017 at 04:51:09PM -0500, Bill wrote: > >I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. > > > >Thanks all > > Are you sure you want to learn Python first? > Python does enough things "behind the scene" > that it makes me question the wisdom of that. > Other points of view are welcome, of course. > Learning the primitives of C++ first, may make for an easier transition. This suggestion seems completely backwards to me. One of Python's greatest strengths is its relative simplicity, as compared to lower level languages like C++ or assembly, or even other scripting languages like Perl (which is comparitively large lexicographically and syntactically). Part of the process of learning is being rewarded for what you have learned; Python does this exceptionally well by enabling the student to write useful programs with simple syntax in a very short time. Pyhon is extremely well suited to teaching basic programming skills like *using* data structures, flow control, subroutines, etc. *without* having to grasp more difficult concepts like addressing and pointers, static typing, low-level data structure implementation, etc.. Those topics would perhaps be better suited to a subsequent course, once the student has mastered (or at least gained familiarity) with some of the more introductory concents. From john_ladasky at sbcglobal.net Thu Dec 21 14:06:49 2017 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 21 Dec 2017 11:06:49 -0800 (PST) Subject: Problem with assignment. Python error or mine? In-Reply-To: References: Message-ID: <26a48310-48e5-44cd-9239-090057243c84@googlegroups.com> On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote: > Python never makes a copy unless you ask it to. > > What x1=X does is make the name x1 refer to the same object that X > refers to. No copying. Well, except with very simple, mutable data types like scalars... compare this: >>> x=5 >>> y=x >>> x,y (5, 5) >>> x+=1 >>> x,y (6, 5) To this: >>> a=[1,2,3] >>> b=a >>> a,b ([1, 2, 3], [1, 2, 3]) >>> a[1]=9 >>> a,b ([1, 9, 3], [1, 9, 3]) From duncan at invalid.invalid Thu Dec 21 14:27:42 2017 From: duncan at invalid.invalid (duncan smith) Date: Thu, 21 Dec 2017 19:27:42 +0000 Subject: Problem with assignment. Python error or mine? In-Reply-To: <26a48310-48e5-44cd-9239-090057243c84@googlegroups.com> References: <26a48310-48e5-44cd-9239-090057243c84@googlegroups.com> Message-ID: On 21/12/17 19:06, John Ladasky wrote: > On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote: > >> Python never makes a copy unless you ask it to. >> >> What x1=X does is make the name x1 refer to the same object that X >> refers to. No copying. > > Well, except with very simple, mutable data types like scalars... compare this: > >>>> x=5 >>>> y=x >>>> x,y > (5, 5) >>>> x+=1 >>>> x,y > (6, 5) > > To this: > >>>> a=[1,2,3] >>>> b=a >>>> a,b > ([1, 2, 3], [1, 2, 3]) >>>> a[1]=9 >>>> a,b > ([1, 9, 3], [1, 9, 3]) > Except ints aren't mutable and there's still no copying. For x += 1 (where x is e.g. an int) read x = x + 1 Duncan From kirillbalunov at gmail.com Thu Dec 21 14:29:16 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Thu, 21 Dec 2017 22:29:16 +0300 Subject: Problem with assignment. Python error or mine? In-Reply-To: <26a48310-48e5-44cd-9239-090057243c84@googlegroups.com> References: <26a48310-48e5-44cd-9239-090057243c84@googlegroups.com> Message-ID: 2017-12-21 22:06 GMT+03:00 John Ladasky : > On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote: > > > Python never makes a copy unless you ask it to. > > > > What x1=X does is make the name x1 refer to the same object that X > > refers to. No copying. > > Well, except with very simple, mutable data types like scalars... compare > this: > No copy means no copy, it is the rule! What you see is really new binding operation under the hood. 'x=1; x += 1', means calculate x+1 and bind it to the same name. Compare it to this example: >>> tpl = ((1,2),(3,4)) >>> tpl += ((1,2),) >>> tpl ((1, 2), (3, 4), (1, 2)) No copy, new binding to the same name :) With kind regards, -gdg From tjreedy at udel.edu Thu Dec 21 15:11:50 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Dec 2017 15:11:50 -0500 Subject: How to edit a function in an interactive python session? In-Reply-To: References: Message-ID: On 12/20/2017 8:42 PM, Peng Yu wrote: > R has the function edit() which allows the editing of the definition > of a function. Does python have something similar so that users can > edit python functions on the fly? Thanks. > > https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit In general, no. In general, it is not possible since the definition may not be in Python. (The equivalent must be true in R also.) In a decent Python IDE, like IDLE, that allows one to enter, retrieve, and edit complete statements, then yes for function definitions entered in the same session. It is also possible to edit multi-line code line-by-line in the standard REPL, but it is more painful and error prone. One can monkey-patch an edited function into an imported module written in Python. The original code can be copied from an editor and pasted into the REPL. -- Terry Jan Reedy From tjreedy at udel.edu Thu Dec 21 15:27:09 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Dec 2017 15:27:09 -0500 Subject: =?UTF-8?Q?Re:_Regarding_the_error:_TypeError:_can=e2=80=99t_pickle_?= =?UTF-8?Q?=5fthread.lock_objects?= In-Reply-To: <4328A44A7D09CB4B818774C0B09D7DE7E320E1D8@SRVEXCH-01.gsr-inc.local> References: <4328A44A7D09CB4B818774C0B09D7DE7E320E1D8@SRVEXCH-01.gsr-inc.local> Message-ID: On 12/21/2017 8:11 AM, Winston Manuel Vijay wrote: > Hi, > > It would be of immense help, if someone could provide a suitable solution or related information that helps to sort out the below stated issue- > > > ? I had installed the Python version 3.6.4 > > ? Then I installed the package: Tensorflow > > ? Installed g2p.exe by downloading from GitHub > > ? Then tried running the below command- > > g2p-seq2seq --interactive --model (model_folder_path: is the path to an English model 2-layer LSTM with 512 hidden units CMU Sphinx dictionary downloaded from the CMU Sphinx website) > > Following the above procedure, I encountered the following error: TypeError: can?t pickle _thread.lock objects-please find the attached screenshot for your reference. This is a text-only mailing list. One should copy and paste an entire traceback. That said, if Tensorflow or g2p are trying to pickle something that cannot be pickled, you would likely do better directing your inquiry to the authors. If you possible can, omit the following nonsensical garbage. When you submit to a public list like python-list, anyone in the world is an intended recipient and you implicitly authorize all of the listed activities. If you do not want that, don't submit. > ________________________________ > > This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. This email is sent for the intended recipient(s) only. If by an addressing or transmission error, this mail has been misdirected to you, you are requested to delete this mail immediately. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from GSR e-mail addresses may be monitored. > -- Terry Jan Reedy From hjp-python at hjp.at Thu Dec 21 15:49:53 2017 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 21 Dec 2017 21:49:53 +0100 Subject: What is wrong with this regex for matching emails? In-Reply-To: References: Message-ID: <20171221204953.c5iuxke4q6fwodru@hjp.at> On 2017-12-20 08:21:02 +1100, Chris Angelico wrote: > If there are no MX records for a domain, either the domain doesn't > exist, or it doesn't receive mail. This is not necessarily correct. An MTA has to fall back to A and AAAA records if no MX record exists, so a domain can receive mail without an MX record. This is rare, but I have seen it in the wild (although usually not for email addresses for people but for services (e.g. trouble ticket systems). hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From ranyafafi93 at gmail.com Thu Dec 21 17:54:17 2017 From: ranyafafi93 at gmail.com (Ranya) Date: Thu, 21 Dec 2017 23:54:17 +0100 Subject: Python bug report Message-ID: Hi, Am trying to use clr.AddReference and clr.AddReferenceToFile, but python(2.7) keeps making this error: Traceback (most recent call last): File "", line 1, in clr.AddReference("UnityEngine")AttributeError: 'module' object has no attribute 'AddReference' How can I fix this? Thanks in advance. From Irv at furrypants.com Thu Dec 21 19:54:04 2017 From: Irv at furrypants.com (Irv Kalb) Date: Thu, 21 Dec 2017 16:54:04 -0800 Subject: property decorator? In-Reply-To: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> References: <2DCEAAE6-DA1D-4D94-A070-5C69E464C8AE@furrypants.com> Message-ID: <3547D5E8-7209-43DB-8F69-632A652F18C8@furrypants.com> Thanks to Rob, Cameron, Ian, Chris and Kirill for the detailed explanations. Very helpful, Irv > On Dec 20, 2017, at 3:56 PM, Irv Kalb wrote: > > I am trying to work through the concept of the @property decorator with respect to object oriented programming. > > I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance variables into method calls in an object. It seems like these two decorators are essentially fancy substitutes for traditional getter and setter methods. But, I'm having a hard time understanding why these names were chosen. > > I have the following example code: > > > class Employee(): > > def __init__(self, name, salary): > self.__name = name > self.__salary = salary > > @property > def salary(self): > print('Getting salary of', self.__name, 'which is:', self.__salary) > return self.__salary > > @salary.setter > def salary(self, newSalary): > print('Setting salary of', self.__name, 'to:', newSalary) > self.__salary = newSalary > > > # Test code: > employee1 = Employee('Joe Schmoe', 99999) > employee2 = Employee('Jane Smith', 123456) > > print(employee1.salary) > print(employee2.salary) > > employee1.salary = 100000 > employee2.salary = 222222 > > print(employee1.salary) > print(employee2.salary) > > > When it runs, I get the results I expect: > > Getting salary of Joe Schmoe which is: 99999 > 99999 > Getting salary of Jane Smith which is: 123456 > 123456 > Setting salary of Joe Schmoe to: 100000 > Setting salary of Jane Smith to: 222222 > Getting salary of Joe Schmoe which is: 100000 > 100000 > Getting salary of Jane Smith which is: 222222 > 222222 > > > My questions about this are really historical. From my reading, it looks like using an @property decorator is a reference to an older approach using a built in "property" function. But here goes: > > 1) Why were these decorator names chosen? These two names @property and @.setter don't seem to be very clear to me. At a minimum, they don't match. Wouldn't decorator names like @.getter and @.setter have been better - more explicit? > > 2) Alternatively, if the getter was going to use the @property decorator, then it would seem complimentary to have the decorator name for the associated setter function to have the word "property" in its also, something like @propertySetter. > > 3) If I create a method with the @property decorator, is there anything else that is implied about the name of the method other than you can now refer to the . - which calls the appropriate method? My guess/understanding is that in my example above, "salary" is considered the property name, which is how you would refer to it outside of the object. Inside the class, you use the property name as the name of both the setter and the getter methods. Is that the right way to think about it? > > > Finally, it seems very odd to me that when you use the @property decorator and the @.setter, that both of the methods that are decorated need to have the same name (but of course different set of parameters.) As a teacher, this seems like it would be an extremely difficult concept to get across to students, as this does not work the same way as other Python functions (and methods). Without a decorator, the second function of the same name overrides an earlier function of the same name, as in this simple example: > > def myFunction( ): > print('In first version of myFunction') > > def myFunction( ): > print('In second version of myFunction') > > myFunction() > > Which prints: In second version of myFunction > > > > > My most recent language before Python was ActionScript 3 (the language of Flash). It implemented a similar concept of being able to use what appeared to be an explicit data reference which turns into a method call, like this example (from StackOverflow): > > private var _loggy:String; > > public function get loggy ():String > { > return _loggy; > } > > public function set loggy ( loggy:String ):void > { > // checking to make sure loggy's new value is kosher etc... > _loggy = loggy; > } > This syntax made the concept easy to understand and implement in an ActionScript class (even though it also uses the same name for both function). > > I do NOT want to start any kind of language flame war. I am really just trying to understand the reasons behind why this concept is implemented in Python this way, so that I can wrap my head around it and teach it effectively in my classes. > > Irv > > -- > https://mail.python.org/mailman/listinfo/python-list > From rustompmody at gmail.com Thu Dec 21 21:01:32 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 21 Dec 2017 18:01:32 -0800 (PST) Subject: Python Learning In-Reply-To: References: <20171221174618.GQ30413@bladeshadow.org> Message-ID: On Friday, December 22, 2017 at 12:12:58 AM UTC+5:30, Python wrote: > On Fri, Dec 15, 2017 at 04:51:09PM -0500, Bill wrote: > > >I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. > > > > > >Thanks all > > > > Are you sure you want to learn Python first? > > Python does enough things "behind the scene" > > that it makes me question the wisdom of that. > > Other points of view are welcome, of course. > > Learning the primitives of C++ first, may make for an easier transition. > > This suggestion seems completely backwards to me. In the locution "computer programming" there are two words One can choose which one emphasizes I guess?? My own teacher of programming used to relate that when his teacher taught him assembly language was "programming" and Fortran as "advanced" Obviously the world today is different from the 1960s But G?del's theorem remains true as ever: No formal system (aka language) is complete (suitable) for expressing everything From tjandacw at cox.net Fri Dec 22 08:41:00 2017 From: tjandacw at cox.net (Tim Williams) Date: Fri, 22 Dec 2017 05:41:00 -0800 (PST) Subject: Problem with assignment. Python error or mine? In-Reply-To: References: Message-ID: <7199a678-3e86-41c2-8539-238401dbd203@googlegroups.com> On Thursday, December 21, 2017 at 12:18:11 PM UTC-5, MarkA wrote: > On Thu, 21 Dec 2017 07:05:33 -0800, rafaeltfreire wrote: > From docs.python.org: > > 8.10. copy ? Shallow and deep copy operations > > Source code: Lib/copy.py > > Assignment statements in Python do not copy objects, they create bindings > between a target and an object. For collections that are mutable or > contain mutable items, a copy is sometimes needed so one can change one > copy without changing the other. This module provides generic shallow and > deep copy operations (explained below)... > > > > Dear community, I am having the following problem when I am assigning > > the elements of a vector below a certain number to zero or any other > > value. > > I am creating a new variable but Python edits the root variable. Why? > > > > import numpy as np > > > > X=np.arange(1, 10000, 1) #root variable x1=X x1[x1<10000]=0 > > > > print(X) > > Out[1]: array([ 0., 0., 0., ..., 0., 0., 0.]) > > > > Why????????? It is supposed to be the original value Thank you for your > > time Rafael > > > > -- > MarkA > > We hang petty theives, and appoint the great theives to public office > -- Aesop Shouldn't the OP just create a list for what he want's to do? X = list(np.arange(1, 10000, 1)) #root variable x1=X x1[x1<10000]=0 Then I think his other statements would do what he expects, no? From tjandacw at cox.net Fri Dec 22 08:52:10 2017 From: tjandacw at cox.net (Tim Williams) Date: Fri, 22 Dec 2017 05:52:10 -0800 (PST) Subject: Problem with assignment. Python error or mine? In-Reply-To: <7199a678-3e86-41c2-8539-238401dbd203@googlegroups.com> References: <7199a678-3e86-41c2-8539-238401dbd203@googlegroups.com> Message-ID: <4e823416-dc7f-4566-b1fa-155a745858e4@googlegroups.com> On Friday, December 22, 2017 at 8:41:29 AM UTC-5, Tim Williams wrote: > On Thursday, December 21, 2017 at 12:18:11 PM UTC-5, MarkA wrote: > > On Thu, 21 Dec 2017 07:05:33 -0800, rafaeltfreire wrote: > > From docs.python.org: > > > > 8.10. copy ? Shallow and deep copy operations > > > > Source code: Lib/copy.py > > > > Assignment statements in Python do not copy objects, they create bindings > > between a target and an object. For collections that are mutable or > > contain mutable items, a copy is sometimes needed so one can change one > > copy without changing the other. This module provides generic shallow and > > deep copy operations (explained below)... > > > > > > > Dear community, I am having the following problem when I am assigning > > > the elements of a vector below a certain number to zero or any other > > > value. > > > I am creating a new variable but Python edits the root variable. Why? > > > > > > import numpy as np > > > > > > X=np.arange(1, 10000, 1) #root variable x1=X x1[x1<10000]=0 > > > > > > print(X) > > > Out[1]: array([ 0., 0., 0., ..., 0., 0., 0.]) > > > > > > Why????????? It is supposed to be the original value Thank you for your > > > time Rafael > > > > > > > > -- > > MarkA > > > > We hang petty theives, and appoint the great theives to public office > > -- Aesop > > Shouldn't the OP just create a list for what he want's to do? > > X = list(np.arange(1, 10000, 1)) #root variable x1=X x1[x1<10000]=0 > > Then I think his other statements would do what he expects, no? Disregard what I just posted. I didn't think this through enough. From kirillbalunov at gmail.com Fri Dec 22 08:53:01 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Fri, 22 Dec 2017 16:53:01 +0300 Subject: Using the variable type annotation syntax as a placeholder in a nonlocal scope? In-Reply-To: References: Message-ID: Any suggestions? Thank you. With kind regards, -gdg On Dec 20, 2017 22:43, "Kirill Balunov" wrote: > I've asked the same question on StackOverflow, but it seems to me that it > is opinion based and will be ignored. So I ask for advice here: > > Since PEP 526 -- Syntax for Variable Annotations > was approved, in Python 3.6+ > it is possible to provide type hint information in the form *x: int*, > also the PEP says "However, annotating a local variable will cause the > interpreter to always make it local to the scope and leaves the variable > uninitialized". Therefore in Python 3.6+ it is syntactically legal to > write: > > def outer(): > x: int > def inner(): > nonlocal x > x = 10 > inner() > print(x) > > while the above snippet is semantically more equivalent to: > > def outer(): > #x > def inner(): > nonlocal x > x = 10 > inner() > print(x) > > Which is obviously a *SyntaxError: no binding for nonlocal 'x' found`*, > sorry for the pun. Also there is nothing said about this style in PEP 8 and > Python 3.6 docs. So should I consider this as a bug, or an implementation > detail (side effect), or a wart, or a feature? > > To clarify the purpose of the question - we can not come to a consensus > and I would like to hear your opinion and possible pitfalls, if any, if we > choose to use this form in our codebase. > > With kind regards, -gdg > > > From tjreedy at udel.edu Fri Dec 22 09:23:08 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 Dec 2017 09:23:08 -0500 Subject: Using the variable type annotation syntax as a placeholder in a nonlocal scope? In-Reply-To: References: Message-ID: On 12/22/2017 8:53 AM, Kirill Balunov wrote: > On Dec 20, 2017 22:43, "Kirill Balunov" wrote: >> Since PEP 526 -- Syntax for Variable Annotations >> was approved, in Python 3.6+ >> it is possible to provide type hint information in the form *x: int*, >> also the PEP says "However, annotating a local variable will cause the >> interpreter to always make it local to the scope and leaves the variable >> uninitialized". It is unitialized only if you do not initialize it. >> Therefore in Python 3.6+ it is syntactically legal to >> write: >> >> def outer(): >> x: int >> def inner(): >> nonlocal x >> x = 10 >> inner() >> print(x) Why would you write the above instead of >>> def f(): x:int = 10 print(x) >>> f() 10 >> while the above snippet is semantically more equivalent to: More equivalent than what? >> def outer(): >> #x >> def inner(): >> nonlocal x >> x = 10 >> inner() >> print(x) >> >> Which is obviously a *SyntaxError: no binding for nonlocal 'x' found`*, >> sorry for the pun. Also there is nothing said about this style in PEP 8 and >> Python 3.6 docs. So should I consider this as a bug, or an implementation >> detail (side effect), or a wart, or a feature? I don't understand the question. Maybe people on SO did not either. -- Terry Jan Reedy From andrewpate08 at gmail.com Fri Dec 22 09:48:16 2017 From: andrewpate08 at gmail.com (andrewpate08 at gmail.com) Date: Fri, 22 Dec 2017 06:48:16 -0800 (PST) Subject: Why "flat is better than nested"? In-Reply-To: References: Message-ID: On Monday, October 25, 2010 at 11:07:42 AM UTC+1, kj wrote: > In "The Zen of Python", one of the "maxims" is "flat is better than > nested"? Why? Can anyone give me a concrete example that illustrates > this point? > > TIA! > > ~kj > > PS: My question should not be construed as a defense for "nested". > I have no particular preference for either flat or nested; it all > depends on the situation; I would have asked the same question if > the maxim had been "nested is better than flat". I think there is a point where flat stops working. One of the products I work on has a 40-50 field datastructure - it is hard to work with and find the appropriate fields in. So I would say structured is better than flat but simple is better than to structured. From steve+python at pearwood.info Fri Dec 22 10:22:05 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Dec 2017 02:22:05 +1100 Subject: Why "flat is better than nested"? References: Message-ID: <5a3d231d$0$6336$b1db1813$d948b532@news.astraweb.com> On Sat, 23 Dec 2017 01:48 am, andrewpate08 at gmail.com wrote: > On Monday, October 25, 2010 at 11:07:42 AM UTC+1, kj wrote: >> In "The Zen of Python", one of the "maxims" is "flat is better than >> nested"? Why? Can anyone give me a concrete example that illustrates >> this point? >> >> TIA! >> >> ~kj >> >> PS: My question should not be construed as a defense for "nested". >> I have no particular preference for either flat or nested; it all >> depends on the situation; I would have asked the same question if >> the maxim had been "nested is better than flat". > > I think there is a point where flat stops working. One of the products I > work on has a 40-50 field datastructure - it is hard to work with and find > the appropriate fields in. So I would say structured is better than flat but > simple is better than to structured. Do you realise you are responding to a message more than seven years old? In any case, structured is not the opposite of flat. Nested is the opposite to flat, and unstructured is the opposite of structured. The two concepts are independent of each other: any data structure can be: - flat and structured; - flat and unstructured; - nested and structured; - nested and unstructured. Data can even be semi-structured; for example, mp3 files have some structured metadata (title, artist, track number, comment, etc), while data in the comment field itself is unstructured (free-form) text. Here is an example of iterating over a flat collection of numbers: values = [1, 2, 3, 4, 5, 6, 7, 8] for num in values: print(num) Here is the same, as a nested collection of numbers: values = [1, [2, [3, [4, [5, [6, [7, [8, []]]]]]]]] while values: num, values = values print(num) In Python, the first is much more efficient than the second. It is also easier to write, easier to read, and less likely for the programmer to mess up. A list or a dict is flat; a binary tree is nested. Structured and unstructured data can have two related but separate meanings. One is to distinguish between data with or without a pre-defined organization: - structured data: XML, JSON, YAML, databases, etc; - unstructured data: books, the body of emails, arbitrary web pages, etc. Dealing with unstructured data in this sense often means coming up with some sort of heuristic or "best guess" for picking out the useful information (say, based on regexes) then writing a scraper to pull part the data source looking for what you want. The meaning you seem to be using seems to be: - structured data has named fields (e.g. C struct, Pascal record, object with named attributes, Python named tuple, CSV file with descriptive column headers); - unstructured data does not name the fields (e.g. a plain tuple, CSV file without column headers) and you have to infer the meaning of each field from out-of-band knowledge (say, you read the documentation to find out that "column 7" is the score). -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jorge.conrado at cptec.inpe.br Fri Dec 22 10:36:48 2017 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Fri, 22 Dec 2017 13:36:48 -0200 Subject: plot map wit box axes Message-ID: Hi, I use the PYTHON and IDL. In IDL I can plot a grid map like a this figure (mapa.png). Please, I would like know how can I plot my figure using PYTHON with the box around the figure. Like this that I plot using the IDL. Thanks From hemantaphurailatpam at gmail.com Fri Dec 22 16:36:01 2017 From: hemantaphurailatpam at gmail.com (hemanta phurailatpam) Date: Fri, 22 Dec 2017 13:36:01 -0800 (PST) Subject: co-ordianate transformation with astropy Message-ID: <25b89d29-9ba8-4ba7-b4a2-0df376dc468b@googlegroups.com> I want to do co-ordinate transformation from earth-frame to equatorial frame. By entering date and time, I want to get RA(right ascension) and Dec(declination) wrt to equatorial frame. How do I do it? From none at invalid.com Fri Dec 22 17:16:06 2017 From: none at invalid.com (mm0fmf) Date: Fri, 22 Dec 2017 22:16:06 +0000 Subject: co-ordianate transformation with astropy In-Reply-To: <25b89d29-9ba8-4ba7-b4a2-0df376dc468b@googlegroups.com> References: <25b89d29-9ba8-4ba7-b4a2-0df376dc468b@googlegroups.com> Message-ID: On 22/12/2017 21:36, hemanta phurailatpam wrote: > I want to do co-ordinate transformation from earth-frame to equatorial frame. By entering date and time, I want to get RA(right ascension) and Dec(declination) wrt to equatorial frame. How do I do it? > How would you do it by hand? From tpadilha84 at gmail.com Fri Dec 22 17:18:29 2017 From: tpadilha84 at gmail.com (Thiago Padilha) Date: Fri, 22 Dec 2017 19:18:29 -0300 Subject: A convenient and powerful API for interacting with external commands Message-ID: Hello fellow Python users I've always used Python as shell scripting language to automate tasks in various projects, especially when doing complex work where Bash gets messy. While Python is a much more powerful language than Bash, I've always found the builtin subprocess.Popen APIs a bit inconvenient to invoke external commands, especially for creating pipelines and doing redirection. Surely one can use shell=True and Popen will invoke the shell, but this is not without drawbacks since one has to deal with shell-specific syntax particularities, such as argument quoting. To make shell scripting in Python more convenient, I've created a new module: https://github.com/tarruda/python-ush. The README and tests contains more detailed examples but here's an idea of how it looks like: import ush sh = ush.Shell() ls, sort = sh('ls', 'sort') # by default, wait for command to exit and return status code for each in # pipeline. stdin, stdout and stderr are inherited. ls_exit_code, sort_exit_code = (ls | sort)() # iterate output, line by line for f in ls | sort: print(f) # collect all output into a string str(ls('-la') | sort('--reverse')) # redirect stdout ls | sort | 'output.txt' # append output to a file (ls | sort | '+output.txt')() # redirect stdin ('input.txt' | sort)() # filename expansion ls('*.py', glob=True) The module is compatible with python 2 and 3, and should work on any Unix or Windows. Also, since it is implemented in a single file (~650 LOC) without dependencies, it should be easy to download and incorporate in a another project. Any feedback is appreciated From breamoreboy at gmail.com Fri Dec 22 17:55:31 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 22 Dec 2017 14:55:31 -0800 (PST) Subject: co-ordianate transformation with astropy In-Reply-To: <25b89d29-9ba8-4ba7-b4a2-0df376dc468b@googlegroups.com> References: <25b89d29-9ba8-4ba7-b4a2-0df376dc468b@googlegroups.com> Message-ID: On Friday, December 22, 2017 at 9:36:29 PM UTC, hemanta phurailatpam wrote: > I want to do co-ordinate transformation from earth-frame to equatorial frame. By entering date and time, I want to get RA(right ascension) and Dec(declination) wrt to equatorial frame. How do I do it? It looks as if you need astropy, specifically http://docs.astropy.org/en/stable/coordinates/transforming.html -- Kindest regards. Mark Lawrence. From pkpearson at nowhere.invalid Fri Dec 22 18:35:09 2017 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 22 Dec 2017 23:35:09 GMT Subject: Python bug report References: Message-ID: On Thu, 21 Dec 2017 23:54:17 +0100, Ranya wrote: > Hi, > Am trying to use clr.AddReference and clr.AddReferenceToFile, but > python(2.7) keeps making this error: > > Traceback (most recent call last): > File "", line 1, in > clr.AddReference("UnityEngine")AttributeError: 'module' object has > no attribute 'AddReference' > > How can I fix this? > Thanks in advance. What is clr? Whatever it is, it doesn't have the AddReference attribute that you seem to be expecting. -- To email me, substitute nowhere->runbox, invalid->com. From breamoreboy at gmail.com Fri Dec 22 18:56:07 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 22 Dec 2017 15:56:07 -0800 (PST) Subject: Python bug report In-Reply-To: References: Message-ID: <1aa2e88b-9ba8-4e3b-a2df-28f0a8af7f6e@googlegroups.com> On Friday, December 22, 2017 at 1:28:17 PM UTC, Ranya wrote: > Hi, > Am trying to use clr.AddReference and clr.AddReferenceToFile, but > python(2.7) keeps making this error: > > Traceback (most recent call last): > File "", line 1, in > clr.AddReference("UnityEngine")AttributeError: 'module' object has > no attribute 'AddReference' > > How can I fix this? > Thanks in advance. Are you actually using the IronPython clr module, have you downloaded by mistake the module of the same name from pypi, or do you have a module of the same name on your path? -- Kindest regards. Mark Lawrence. From pengyu.ut at gmail.com Fri Dec 22 22:35:53 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 22 Dec 2017 21:35:53 -0600 Subject: Where is ^ (symmetric_difference) documented in help()? Message-ID: Hi, I see the following two lines are the same. But I'd like to find where ^ is documented via the help() function (I am not looking for the document in html)? Does anybody know? Thanks. s.symmetric_difference(t) s ^ t -- Regards, Peng From dan at tombstonezero.net Fri Dec 22 22:41:47 2017 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 23 Dec 2017 03:41:47 +0000 (UTC) Subject: Where is ^ (symmetric_difference) documented in help()? References: Message-ID: On Fri, 22 Dec 2017 21:35:53 -0600, Peng Yu wrote: > Hi, I see the following two lines are the same. But I'd like to find > where ^ is documented via the help() function (I am not looking for > the document in html)? Does anybody know? Thanks. > > s.symmetric_difference(t) > s ^ t It's sort of documented in help(set): | __xor__(self, value, /) | Return self^value. HTH, Dan From pengyu.ut at gmail.com Fri Dec 22 23:01:04 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 22 Dec 2017 22:01:04 -0600 Subject: Why are both locals() and globals() set? Message-ID: Hi, The following example shows that both locals() and globals() are updated when x and f are defined. Shouldn't they be considered and global variable and functions only? Why does it make sense to set locals() as well? Thanks. $ cat ./main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: d = dict() d['l1'] = set(locals().keys()) d['g1'] = set(globals().keys()) x = 10 def f(): pass d['l2'] = set(locals().keys()) d['g2'] = set(globals().keys()) print d['l2'] - d['l1'] print d['g2'] - d['g1'] import os.path d['l3'] = set(locals().keys()) d['g3'] = set(globals().keys()) print d['l3'] - d['l2'] print d['g3'] - d['g2'] from os import path d['l4'] = set(locals().keys()) d['g4'] = set(globals().keys()) print d['l4'] - d['l3'] print d['g4'] - d['g3'] $ ./main.py set(['x', 'f']) set(['x', 'f']) set(['os']) set(['os']) set(['path']) set(['path']) -- Regards, Peng From pengyu.ut at gmail.com Fri Dec 22 23:50:28 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 22 Dec 2017 22:50:28 -0600 Subject: Where is ^ (symmetric_difference) documented in help()? In-Reply-To: References: Message-ID: Where is it documented that __xor__ and ^ is the same as symmetric_difference? Thanks. BTW, I am using to Python 2, your help message is different from mine. Do you use Python 3? On Fri, Dec 22, 2017 at 9:41 PM, Dan Sommers wrote: > On Fri, 22 Dec 2017 21:35:53 -0600, Peng Yu wrote: > >> Hi, I see the following two lines are the same. But I'd like to find >> where ^ is documented via the help() function (I am not looking for >> the document in html)? Does anybody know? Thanks. >> >> s.symmetric_difference(t) >> s ^ t > > It's sort of documented in help(set): > > | __xor__(self, value, /) > | Return self^value. > > HTH, > Dan > > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From steve+python at pearwood.info Fri Dec 22 23:50:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Dec 2017 15:50:36 +1100 Subject: Where is ^ (symmetric_difference) documented in help()? References: Message-ID: <5a3de09d$0$6330$b1db1813$d948b532@news.astraweb.com> On Sat, 23 Dec 2017 02:35 pm, Peng Yu wrote: > Hi, I see the following two lines are the same. But I'd like to find > where ^ is documented via the help() function (I am not looking for > the document in html)? Does anybody know? Thanks. > > s.symmetric_difference(t) > s ^ t You can call: help("^") (notice you need to quote the operator) but it only talks about the bitwise operators. I've just raised bug report for this: https://bugs.python.org/issue32412 -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Dec 23 00:30:32 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Dec 2017 16:30:32 +1100 Subject: Where is ^ (symmetric_difference) documented in help()? References: Message-ID: <5a3de9f9$0$26914$b1db1813$eb6074ea@news.astraweb.com> On Sat, 23 Dec 2017 03:50 pm, Peng Yu wrote: > Where is it documented that __xor__ and ^ is the same as > symmetric_difference? Thanks. You read https://docs.python.org/2/library/stdtypes.html#set to learn that ^ is the same as symmetric difference, and then read: https://docs.python.org/2/reference/datamodel.html#emulating-numeric-types to learn that you must override __xor__ to override the ^ operator. It isn't really clear from the documentation that the set operator ^ is implemented by __xor__ (and also __rxor__). Perhaps you can suggest a documentation patch? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From pengyu.ut at gmail.com Sat Dec 23 00:38:07 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 22 Dec 2017 23:38:07 -0600 Subject: What is the meaning of @@? Message-ID: Hi, I only can find the doc for @. What does @@ mean in python? -- Regards, Peng From steve+python at pearwood.info Sat Dec 23 00:58:29 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Dec 2017 16:58:29 +1100 Subject: Why are both locals() and globals() set? References: Message-ID: <5a3df085$0$6330$b1db1813$d948b532@news.astraweb.com> On Sat, 23 Dec 2017 03:01 pm, Peng Yu wrote: > Hi, The following example shows that both locals() and globals() are > updated when x and f are defined. Shouldn't they be considered and > global variable and functions only? Why does it make sense to set > locals() as well? Thanks. There are three places you can call locals() and globals(): (1) Inside a function: def function(): x = 1 L = locals() G = globals() print "id(L)=%d id(G)=%d" % (id(L), id(G)) (2) Inside a class definition: class Class(object): x = 1 L = locals() G = globals() print "id(L)=%d id(G)=%d" % (id(L), id(G)) (3) At the top level of a module (outside of any function or class): # module x = 1 L = locals() G = globals() print "id(L)=%d id(G)=%d" % (id(L), id(G)) If you try this, you will find that in #3, the dicts L and G have the same ID number. This means that at the module level, locals() and globals() are the same dict. This is (barely!) documented here: https://docs.python.org/2/reference/executionmodel.html#binding-of-names where it tells us that "The variables of the module code block are local and global" but not documented here: https://docs.python.org/2/library/functions.html#locals I've raised an issue for that too: https://bugs.python.org/issue32413 Also note that for technical reasons, assigning to locals() inside a function is not guaranteed to always work. The locals() dict returned is *sometimes* a copy of the actual local variables, and so assigning to it does not assign to the actual local variable. This is a tricky area of Python, where different versions and different implementations (such as CPython, IronPython, Jython, PyPy) may behave differently. By the way, using globals() and locals() is considered an "advanced" feature. If you want to set a variable, use ordinary assignment: # set a local x = 1 # to set a global from inside a function or class, declare it global global x x = 1 rather than trying to play around with globals() and locals(). -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Dec 23 01:03:47 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Dec 2017 17:03:47 +1100 Subject: What is the meaning of @@? References: Message-ID: <5a3df1c4$0$6315$b1db1813$d948b532@news.astraweb.com> On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote: > Hi, I only can find the doc for @. What does @@ mean in python? I don't think that @@ means anything yet. There was a proposal to use @@ for matrix exponentiation in Numpy, as @ is used for matrix multiplication, but that was left on hold to see whether it is really needed or not. Where did you find @@ in Python? (By the way, @ for matrix multiplication only works in Python 3.5 or better.) https://www.python.org/dev/peps/pep-0465/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ian.g.kelly at gmail.com Sat Dec 23 01:06:55 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 22 Dec 2017 23:06:55 -0700 Subject: What is the meaning of @@? In-Reply-To: References: Message-ID: @@ is a syntax error. Where did you encounter this? On Fri, Dec 22, 2017 at 10:38 PM, Peng Yu wrote: > Hi, I only can find the doc for @. What does @@ mean in python? > > -- > Regards, > Peng > -- > https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Sat Dec 23 13:55:33 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 23 Dec 2017 18:55:33 +0000 Subject: Why are both locals() and globals() set? In-Reply-To: References: Message-ID: <8f04497a-600f-28fc-e824-5022ea50dda6@mrabarnett.plus.com> On 2017-12-23 04:01, Peng Yu wrote: > Hi, The following example shows that both locals() and globals() are > updated when x and f are defined. Shouldn't they be considered and > global variable and functions only? Why does it make sense to set > locals() as well? Thanks. > It's "local" in the sense that it's in the current scope, so in a function it's local to that function, and in the main code of a module it's local to that module as well as being "global". [snip] From neptinizer101 at gmail.com Sat Dec 23 14:44:19 2017 From: neptinizer101 at gmail.com (G Yu) Date: Sat, 23 Dec 2017 11:44:19 -0800 (PST) Subject: acircle.getCenter() to (x,y) coordinates in Python Message-ID: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> My program has two circles: one stationary circle, drawn at a random location; and one moving circle, consistently drawn in the same place in the graphics window. The moving circle moves towards the stationary one. However, when the moving circle hits the stationary one (when the x-coordinates of the circles' centers are equal), I want the moving circle to stop moving and then disappear. I tried the command acircle.getCenter() to determine when the centers are equal, but it doesn't work; I suspect because the centers are never truly equal, and only come within something like .000001 pixels of each other. So to account for the approximation, I used the math function "isclose": move_moving_circle = True while move_moving_circle: moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E) time.sleep(0.01) if isclose(moving_circle.getCenter(), stationary_circle.getCenter(), rel_tol=1e-4, abs_tol=0.0): move_moving_circle= False else: move_moving_circle = True But this doesn't work. Apparently isclose can't be applied to points - only floating-point decimals. So now, I want to convert the output of "acircle.getCenter()" to Cartesian (x,y) coordinates for both circles. Then I can use the two circle centers' x-coordinates in the if statement. Currently, acircle.getCenter() outputs this: I don't understand/can't use the format that the locations are printed in. How do I convert the above format to "usable" Cartesian coordinates? Or is there a simpler way to solve this problem? Thanks! From breamoreboy at gmail.com Sat Dec 23 15:27:28 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 23 Dec 2017 12:27:28 -0800 (PST) Subject: plot map wit box axes In-Reply-To: References: Message-ID: <78615a5e-5981-4b80-ab6b-4198aeaf123d@googlegroups.com> On Friday, December 22, 2017 at 3:42:58 PM UTC, jorge.... at cptec.inpe.br wrote: > Hi, > > I use the PYTHON and IDL. In IDL I can plot a grid map like a this > figure (mapa.png). Please, I would like know how can I plot my figure > using PYTHON with the box around the figure. Like this that I plot using > the IDL. > > Thanks Sorry but we can't see the image as it gets stripped off this text only mailing list. What are you using to do the plot, matplotlib or smething else? Can you show us the code you've used or your interactive session in IDLE? -- Kindest regards. Mark Lawrence. From python at mrabarnett.plus.com Sat Dec 23 15:35:36 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 23 Dec 2017 20:35:36 +0000 Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> Message-ID: <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> On 2017-12-23 19:44, G Yu wrote: > My program has two circles: one stationary circle, drawn at a random location; and one moving circle, consistently drawn in the same place in the graphics window. > > The moving circle moves towards the stationary one. However, when the moving circle hits the stationary one (when the x-coordinates of the circles' centers are equal), I want the moving circle to stop moving and then disappear. > > I tried the command acircle.getCenter() to determine when the centers are equal, but it doesn't work; I suspect because the centers are never truly equal, and only come within something like .000001 pixels of each other. So to account for the approximation, I used the math function "isclose": > > move_moving_circle = True > > while move_moving_circle: > moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E) > time.sleep(0.01) > > if isclose(moving_circle.getCenter(), stationary_circle.getCenter(), rel_tol=1e-4, abs_tol=0.0): > move_moving_circle= False > > else: > move_moving_circle = True > > > But this doesn't work. Apparently isclose can't be applied to points - only floating-point decimals. > > > So now, I want to convert the output of "acircle.getCenter()" to Cartesian (x,y) coordinates for both circles. Then I can use the two circle centers' x-coordinates in the if statement. > > Currently, acircle.getCenter() outputs this: > > > > > I don't understand/can't use the format that the locations are printed in. > > How do I convert the above format to "usable" Cartesian coordinates? Or is there a simpler way to solve this problem? > You didn't say what graphics library you're using, but from a quick search on the internet I think the answer is to use the .getX and .getY methods of the Point object. You could calculate the distance between the 2 points, which is sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2). You can speed it up a little by omitting the sqrt and just remember that you're working with the square of the distance. Another point: why do they need to be so close to each other? Personally, I'd just say they collide when round(distance) < 1 or round(distance ** 2) < 1. From neptinizer101 at gmail.com Sat Dec 23 16:30:29 2017 From: neptinizer101 at gmail.com (G Yu) Date: Sat, 23 Dec 2017 13:30:29 -0800 (PST) Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> Message-ID: <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> I did try that. The problem is that I already declared a point moving_object_center = (-555,-555), because that's the point I used as the center to draw the moving_object circle itself. So the moving_object_center.getX() will return -555 no matter what I do. That's why I need to calculate the center using some attribute of the circle, not the center point - because the circle moves, but the point that I declared as the initial center point will never change. I'm not totally sure what you mean by "graphics library", but these are all the import statements I'm using at the beginning. from graphics import * import datetime import random from math import * From python at mrabarnett.plus.com Sat Dec 23 19:29:33 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 24 Dec 2017 00:29:33 +0000 Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> Message-ID: <3f0f0d74-202b-ebb7-fdfb-d88b5601c6cf@mrabarnett.plus.com> On 2017-12-23 21:30, G Yu wrote: > I did try that. The problem is that I already declared a point moving_object_center = (-555,-555), because that's the point I used as the center to draw the moving_object circle itself. So the moving_object_center.getX() will return -555 no matter what I do. > But your code has: moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E) so won't that move the circle and change what: moving_circle.getCenter() returns? > That's why I need to calculate the center using some attribute of the circle, not the center point - because the circle moves, but the point that I declared as the initial center point will never change. > The initial point won't change, but that's just where the circle was originally. Are you sure that it doesn't change? Have you printed out moving_circle.getCenter().getX() and moving_circle.getCenter().getY() and seen that they aren't changing? > I'm not totally sure what you mean by "graphics library", but these are all the import statements I'm using at the beginning. > > from graphics import * > import datetime > import random > from math import * > As far as I know, "graphics" isn't part of the standard CPython distribution from www.python.org. At least, I have CPython 3.6 for Windows, and "graphics" doesn't appear to be present. From gengyangcai at gmail.com Sat Dec 23 20:20:50 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 23 Dec 2017 17:20:50 -0800 (PST) Subject: Writing a chess-playing AI like Alphago in Python Message-ID: How many lines of code in Python would it take to create a Go-playing AI like AlphaGo ? Estimates ? From neptinizer101 at gmail.com Sat Dec 23 21:31:57 2017 From: neptinizer101 at gmail.com (G Yu) Date: Sat, 23 Dec 2017 18:31:57 -0800 (PST) Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> <3f0f0d74-202b-ebb7-fdfb-d88b5601c6cf@mrabarnett.plus.com> Message-ID: <0139c43c-e905-473c-b84c-85b0695faeb0@googlegroups.com> > But your code has: > > moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E) > > so won't that move the circle and change what: > > moving_circle.getCenter() > > returns? Yes, moving the circle changes the value of moving_circle.getCenter(). The problem is interpreting the output. The command gives , and I don't know how to determine the x-coordinate of the center from that output. This is my problem. I can't translate the .getCenter() output to Cartesian coordinates. > The initial point won't change, but that's just where the circle was > originally. > Are you sure that it doesn't change? Have you printed out > moving_circle.getCenter().getX() and moving_circle.getCenter().getY() > and seen that they aren't changing? Distinguish between the circle's center and the initial center point I declared. My program can output the former, but it's in a format that I don't understand: . As for the initial center point (I'll call it moving_circle_*initial*_center instead), it won't change at all throughout the program execution. I need to know the x- and y-coordinates of moving_circle.getCenter() at any point in time. I can't use the center of the circle *before* it started moving, because that value is static (in other words, moving_circle_initial_center.getX() and moving_circle_initial_center.getY() never change). From greg.ewing at canterbury.ac.nz Sat Dec 23 23:05:13 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 24 Dec 2017 17:05:13 +1300 Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: <0139c43c-e905-473c-b84c-85b0695faeb0@googlegroups.com> References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> <3f0f0d74-202b-ebb7-fdfb-d88b5601c6cf@mrabarnett.plus.com> <0139c43c-e905-473c-b84c-85b0695faeb0@googlegroups.com> Message-ID: G Yu wrote: > The command gives at 0x0000013E0D263668>, and I don't know how to determine the x-coordinate of > the center from that output. Try this in an interactive session: p = circle.getCenter() help(p) This should give you a page of text showing all the attributes and methods your point object has. Somewhere in there will almost certainly be something that tells you the coordinates. -- Greg From steve+python at pearwood.info Sat Dec 23 23:29:27 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 24 Dec 2017 15:29:27 +1100 Subject: Writing a chess-playing AI like Alphago in Python References: Message-ID: <5a3f2d28$0$6318$b1db1813$d948b532@news.astraweb.com> On Sun, 24 Dec 2017 12:20 pm, Cai Gengyang wrote: > How many lines of code in Python would it take to create a Go-playing AI > like AlphaGo ? Estimates ? Somewhere between 1 and 1 billion. How about you start by telling us: - do you mean AlphaGo or AlphaGo Zero? - how many lines of code AlphaGo [Zero] has; - in what language or languages; - is Python allowed to call out to libraries written in other languages, e.g. machine learning and neural net libraries, or databases, or does it have to implement *everything* from scratch? The Michi Go engine uses about 550 lines of Python: https://github.com/pasky/michi but I don't believe it does any machine learning. See also: https://github.com/rossumai/nochi https://medium.com/rossum/building-our-own-version-of-alphago-zero-b918642bd2b5 -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From Irv at furrypants.com Sun Dec 24 00:08:55 2017 From: Irv at furrypants.com (Irv Kalb) Date: Sat, 23 Dec 2017 21:08:55 -0800 Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> Message-ID: > On Dec 23, 2017, at 11:44 AM, G Yu wrote: > > My program has two circles: one stationary circle, drawn at a random location; and one moving circle, consistently drawn in the same place in the graphics window. > > > > Currently, acircle.getCenter() outputs this: > > > > > I don't understand/can't use the format that the locations are printed in. > > How do I convert the above format to "usable" Cartesian coordinates? Or is there a simpler way to solve this problem? > > Thanks! > -- > https://mail.python.org/mailman/listinfo/python-list > I found this document that looks like it described the "graphics" module that you are using (it does describe the getCenter call that you showed): http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf If this is the module, then Points are objects, and what you are seeing is the memory address of those points. Section 3.1 of the document describes how you can call the getX() and getY() methods on any point to get the x and y values: getX() Returns the x coordinate of a point. Example: xValue = aPoint.getX() getY() Returns the y coordinate of a point. Example: yValue = aPoint.getY() Therefore, it sounds like you need to take the Point object that you have, and call the getX method and alto the getY method to get the coordinates you want. Hope that helps, Irv From arj.python at gmail.com Sun Dec 24 11:39:59 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Dec 2017 20:39:59 +0400 Subject: Anaconda Navigator : Add App In-Reply-To: References: Message-ID: How to add apps to the navigator or which apps are available to be installed? Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com From python at mrabarnett.plus.com Sun Dec 24 13:51:02 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 24 Dec 2017 18:51:02 +0000 Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: <0139c43c-e905-473c-b84c-85b0695faeb0@googlegroups.com> References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> <3f0f0d74-202b-ebb7-fdfb-d88b5601c6cf@mrabarnett.plus.com> <0139c43c-e905-473c-b84c-85b0695faeb0@googlegroups.com> Message-ID: On 2017-12-24 02:31, G Yu wrote: >> But your code has: >> >> moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E) >> >> so won't that move the circle and change what: >> >> moving_circle.getCenter() >> >> returns? > > Yes, moving the circle changes the value of moving_circle.getCenter(). The problem is interpreting the output. The command gives , and I don't know how to determine the x-coordinate of the center from that output. This is my problem. I can't translate the .getCenter() output to Cartesian coordinates. > > > >> The initial point won't change, but that's just where the circle was >> originally. > >> Are you sure that it doesn't change? Have you printed out >> moving_circle.getCenter().getX() and moving_circle.getCenter().getY() >> and seen that they aren't changing? > > Distinguish between the circle's center and the initial center point I declared. My program can output the former, but it's in a format that I don't understand: . > > As for the initial center point (I'll call it moving_circle_*initial*_center instead), it won't change at all throughout the program execution. > > I need to know the x- and y-coordinates of moving_circle.getCenter() at any point in time. I can't use the center of the circle *before* it started moving, because that value is static (in other words, moving_circle_initial_center.getX() and moving_circle_initial_center.getY() never change). > I have already told you how to get the x and y coordinates. moving_circle.getCenter() returns the centre as a Point object. That Point object has .getX() and .getY() methods, which return the x and y coordinates respectively. From wrw at mac.com Sun Dec 24 15:21:21 2017 From: wrw at mac.com (William Ray Wing) Date: Sun, 24 Dec 2017 15:21:21 -0500 Subject: plot map wit box axes In-Reply-To: <78615a5e-5981-4b80-ab6b-4198aeaf123d@googlegroups.com> References: <78615a5e-5981-4b80-ab6b-4198aeaf123d@googlegroups.com> Message-ID: <45208F09-99FF-4C4C-B2A0-AD17D4791FFB@mac.com> > On Dec 23, 2017, at 3:27 PM, breamoreboy at gmail.com wrote: > > On Friday, December 22, 2017 at 3:42:58 PM UTC, jorge.... at cptec.inpe.br wrote: >> Hi, >> >> I use the PYTHON and IDL. In IDL I can plot a grid map like a this >> figure (mapa.png). Please, I would like know how can I plot my figure >> using PYTHON with the box around the figure. Like this that I plot using >> the IDL. >> >> Thanks > > Sorry but we can't see the image as it gets stripped off this text only mailing list. What are you using to do the plot, matplotlib or smething else? Can you show us the code you've used or your interactive session in IDLE? > I?m 90% sure the OP really meant IDL, not IDLE. IDL (Interactive Data Language) is a long-time competitor to MatLab, and is widely used in various parts of the scientific community. (Don?t know if it is still true, but for years ALL the published images from the Hubble telescope had been processed through IDL.) Bill > -- > Kindest regards. > > Mark Lawrence. > -- > https://mail.python.org/mailman/listinfo/python-list From pengyu.ut at gmail.com Sun Dec 24 20:33:08 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 24 Dec 2017 19:33:08 -0600 Subject: What is the meaning of @@? In-Reply-To: <5a3df1c4$0$6315$b1db1813$d948b532@news.astraweb.com> References: <5a3df1c4$0$6315$b1db1813$d948b532@news.astraweb.com> Message-ID: See for example this file. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/rnn_cell.py On Sat, Dec 23, 2017 at 12:03 AM, Steve D'Aprano wrote: > On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote: > >> Hi, I only can find the doc for @. What does @@ mean in python? > > I don't think that @@ means anything yet. > > There was a proposal to use @@ for matrix exponentiation in Numpy, as @ is > used for matrix multiplication, but that was left on hold to see whether it > is really needed or not. > > Where did you find @@ in Python? > > > (By the way, @ for matrix multiplication only works in Python 3.5 or better.) > > https://www.python.org/dev/peps/pep-0465/ > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From Richard at Damon-Family.org Sun Dec 24 20:55:19 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 24 Dec 2017 20:55:19 -0500 Subject: What is the meaning of @@? In-Reply-To: References: <5a3df1c4$0$6315$b1db1813$d948b532@news.astraweb.com> Message-ID: On 12/24/17 8:33 PM, Peng Yu wrote: > See for example this file. > > https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/rnn_cell.py > > On Sat, Dec 23, 2017 at 12:03 AM, Steve D'Aprano > wrote: >> On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote: >> >>> Hi, I only can find the doc for @. What does @@ mean in python? >> I don't think that @@ means anything yet. >> >> There was a proposal to use @@ for matrix exponentiation in Numpy, as @ is >> used for matrix multiplication, but that was left on hold to see whether it >> is really needed or not. >> >> Where did you find @@ in Python? >> >> >> (By the way, @ for matrix multiplication only works in Python 3.5 or better.) >> >> https://www.python.org/dev/peps/pep-0465/ >> >> >> >> -- >> Steve >> ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure >> enough, things got worse. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > Note, the @@ is inside a triple quoted string, so this is just part of a multi-line string. -- Richard Damon From ian.g.kelly at gmail.com Sun Dec 24 21:05:41 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 24 Dec 2017 20:05:41 -0600 Subject: What is the meaning of @@? In-Reply-To: References: <5a3df1c4$0$6315$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Dec 24, 2017 at 7:33 PM, Peng Yu wrote: > See for example this file. > > https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/rnn_cell.py > > On Sat, Dec 23, 2017 at 12:03 AM, Steve D'Aprano > wrote: >> On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote: >> >>> Hi, I only can find the doc for @. What does @@ mean in python? The examples there occur inside of a doc string, so that's not Python. It's part of the syntax of whatever software is used to generate the documentation for that code. From neptinizer101 at gmail.com Sun Dec 24 21:42:43 2017 From: neptinizer101 at gmail.com (G Yu) Date: Sun, 24 Dec 2017 18:42:43 -0800 (PST) Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> <3f0f0d74-202b-ebb7-fdfb-d88b5601c6cf@mrabarnett.plus.com> <0139c43c-e905-473c-b84c-85b0695faeb0@googlegroups.com> Message-ID: Ah, I get it now. I have to store the acircle.getCenter() in a point Point, and then access Point.getX() and Point.getY() separately. It was just that middle step that I was missing. Thanks so much! From caigy84 at gmail.com Mon Dec 25 06:15:43 2017 From: caigy84 at gmail.com (caigy84 at gmail.com) Date: Mon, 25 Dec 2017 03:15:43 -0800 (PST) Subject: Writing a chess-playing AI like Alphago in Python In-Reply-To: <5a3f2d28$0$6318$b1db1813$d948b532@news.astraweb.com> References: <5a3f2d28$0$6318$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sunday, December 24, 2017 at 1:26:22 PM UTC+8, Steve D'Aprano wrote: > On Sun, 24 Dec 2017 12:20 pm, Cai Gengyang wrote: > > > How many lines of code in Python would it take to create a Go-playing AI > > like AlphaGo ? Estimates ? > > Somewhere between 1 and 1 billion. > > How about you start by telling us: > > - do you mean AlphaGo or AlphaGo Zero? > > - how many lines of code AlphaGo [Zero] has; > > - in what language or languages; > > - is Python allowed to call out to libraries written in other > languages, e.g. machine learning and neural net libraries, > or databases, or does it have to implement *everything* > from scratch? > > > The Michi Go engine uses about 550 lines of Python: > > https://github.com/pasky/michi > > but I don't believe it does any machine learning. > > > See also: > > https://github.com/rossumai/nochi > > https://medium.com/rossum/building-our-own-version-of-alphago-zero-b918642bd2b5 > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > - do you mean AlphaGo or AlphaGo Zero? ----- AlphaGo > > - how many lines of code AlphaGo [Zero] has; ----- No Idea > > - in what language or languages; ----- Python > > - is Python allowed to call out to libraries written in other > languages, e.g. machine learning and neural net libraries, > or databases, or does it have to implement *everything* > from scratch? ----- Allowed to call out From nicco.9537 at gmail.com Mon Dec 25 08:36:16 2017 From: nicco.9537 at gmail.com (Nico Vogeli) Date: Mon, 25 Dec 2017 05:36:16 -0800 (PST) Subject: user input string to function Message-ID: Hi everybody. First ad foremost, happy Christmas! I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) import numpy as np import matplotlib.pyplot as plt import scipy.linalg from sympy.abc import o, h import sympy from sympy import symbols from scitools.StringFunction import StringFunction from sympy.plotting import plot x = symbols('x') def newton(x0, s, s2, tol, n = 20000): ''' N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren x0 = Startwert f = zu l?sende Funktion fx = Ableitung der Funktion ''' def f(a): y = s return y def fx(a): y = s2 return y a = x0 k = 0 while n > k: k += 1 b = a - f(a)/fx(a) print('x', k, '\n',b) print('Startwert -> x0', '\n', x0) print('Anzahl Iterationen', '\n', k) print('f(x~)', '\n', f(x)) print('N?herungswert -> x~', '\n', b) return x0, k, f(x), x (Please ignore all the input, they are used latter) Now the output looks like this: newton(2, 3*x**2, 6*x, 0.1, 2) x 1 -x/2 + 2 x 2 -x/2 + 2 Startwert -> x0 2 Anzahl Iterationen 2 f(x~) 3*x**2 N?herungswert -> x~ -x/2 + 2 Out[166]: (2, 2, 3*x**2, x) I notice that the x is not converted to an integer, because of the x = symplos('x') But I don't know how I could possibli change the code to work... Regards Nicco From rosuav at gmail.com Mon Dec 25 08:50:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Dec 2017 00:50:48 +1100 Subject: user input string to function In-Reply-To: References: Message-ID: On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli wrote: > Hi everybody. First ad foremost, happy Christmas! Same to you! > I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) > > def newton(x0, s, s2, tol, n = 20000): > ''' > N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren > x0 = Startwert > f = zu l?sende Funktion > fx = Ableitung der Funktion > > ''' > def f(a): > y = s > return y > > def fx(a): > y = s2 > return y > newton(2, 3*x**2, 6*x, 0.1, 2) > > I notice that the x is not converted to an integer, because of the x = symplos('x') > But I don't know how I could possibli change the code to work... The easiest way is to pass a *function* to newton(). It'd look like this: def newton(x0, f, fx, tol, n=20000): ... as before, but without the nested functions newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) At least, I think that's how you're doing things. Inside the nested functions, you use 'a', but outside, you use 'x'. Are those representing the same concept? If so, the lambda functions given here will have the same effect. Hope that helps! ChrisA From m at funkyhat.org Mon Dec 25 09:13:28 2017 From: m at funkyhat.org (Matt Wheeler) Date: Mon, 25 Dec 2017 14:13:28 +0000 (UTC) Subject: unabe to import /pyd file. In-Reply-To: <231c952f-3fdd-4519-bcf1-b7bb0ab0d968@googlegroups.com> References: <231c952f-3fdd-4519-bcf1-b7bb0ab0d968@googlegroups.com> Message-ID: On Fri, Dec 15, 2017, 09:58 wrote: > Hi, > > I have created one library file > "modified_python_automation_tcl.py"..Inside my library file I have set of > codes as follows. > > import sys > import time > from datetime import datetime > import re,sys,os,itertools,datetime,commands,logging,math,time,copy,inspect > from robot.api import logger > import unicodedata > sys.path.append('C:\Python27\Lib\lib-tk') > sys.path.append('C:\Python27\DLLs') > sys.path.append('C:\Python27\libs') > The fact that you're having to add these paths is the first sign that something is up, you shouldn't need to add the default paths to sys.path... from Tkinter import Tcl > tcl = Tcl() > . > . > . > . > . > . > > I am able to run the file from python IDLE.and able to source all kind of > .py and .pyd file...But the issue is coming when trying through robo > framework. > > > I am using robo-framework and have defined the > modified_python_automation_tcl.py file as the library file. and tryuing to > excute my testcase..but getting the below error.. > > > Someone please help me how to import .pyd files from robo framework > > > > C:\PCCAutomation > C:\Python27\Lib\lib-tk > C:\Python27\DLLs > C:\Python27\libs > CLASSPATH: > C:/apache-maven-3.3.9/boot/plexus-classworlds-2.5.2.jar > Acceptance.Tests.PCC.Automation 2.0.Spirent > And here we find the problem. You're running robotframework using the JAR distribution, right? That means that your Python is Jython, which doesn't support CPython extensions (i.e. .pyd) Unfortunately, according to a quick google, there is no support for Tkinter in Jython at all, so if you need a GUI you'll need to re-write your GUI in a library that Jython/Java can talk to. (other possible ways around this could be dropping this "plexus-classworlds" jar if you can and running robotframework from CPython* instead, or (in theory) using the robotframework remote library [ https://github.com/robotframework/RemoteInterface] to run the Java-dependent parts in Jython & the CPython-dependent parts in CPython (I've not used the remote library myself so don't know how easy it is to work with, but it should work either way around)) * pip install robotframework > -- -- Matt Wheeler http://funkyh.at From nicco.9537 at gmail.com Mon Dec 25 09:48:58 2017 From: nicco.9537 at gmail.com (Nico Vogeli) Date: Mon, 25 Dec 2017 06:48:58 -0800 (PST) Subject: user input string to function In-Reply-To: References: Message-ID: <8384056e-ac32-4cc7-9ddb-94601e37add5@googlegroups.com> Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: > On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli wrote: > > Hi everybody. First ad foremost, happy Christmas! > > Same to you! > > > I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) > > > > def newton(x0, s, s2, tol, n = 20000): > > ''' > > N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren > > x0 = Startwert > > f = zu l?sende Funktion > > fx = Ableitung der Funktion > > > > ''' > > def f(a): > > y = s > > return y > > > > def fx(a): > > y = s2 > > return y > > > > newton(2, 3*x**2, 6*x, 0.1, 2) > > > > I notice that the x is not converted to an integer, because of the x = symplos('x') > > But I don't know how I could possibli change the code to work... > > The easiest way is to pass a *function* to newton(). It'd look like this: > > def newton(x0, f, fx, tol, n=20000): > ... as before, but without the nested functions > > newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) > > At least, I think that's how you're doing things. Inside the nested > functions, you use 'a', but outside, you use 'x'. Are those > representing the same concept? If so, the lambda functions given here > will have the same effect. > > Hope that helps! > > ChrisA Hi Chris Thanks very much for your quick response! I was in a bit of a rush, so I confused the variables (don't worry, I just messed arround to try different things, the original code was al tidy with the variable). I tried your input, but now I get another error: File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, in newton b = x - f(x)/fx(x) TypeError: unsupported operand type(s) for /: 'function' and 'function' This did not occure befor I tried to implement the user input.. Thank you very much! Nicco From rosuav at gmail.com Mon Dec 25 09:57:34 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Dec 2017 01:57:34 +1100 Subject: user input string to function In-Reply-To: <8384056e-ac32-4cc7-9ddb-94601e37add5@googlegroups.com> References: <8384056e-ac32-4cc7-9ddb-94601e37add5@googlegroups.com> Message-ID: On Tue, Dec 26, 2017 at 1:48 AM, Nico Vogeli wrote: > Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: >> On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli wrote: >> > Hi everybody. First ad foremost, happy Christmas! >> >> Same to you! >> >> > I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) >> > >> > def newton(x0, s, s2, tol, n = 20000): >> > ''' >> > N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren >> > x0 = Startwert >> > f = zu l?sende Funktion >> > fx = Ableitung der Funktion >> > >> > ''' >> > def f(a): >> > y = s >> > return y >> > >> > def fx(a): >> > y = s2 >> > return y >> >> >> > newton(2, 3*x**2, 6*x, 0.1, 2) >> > >> > I notice that the x is not converted to an integer, because of the x = symplos('x') >> > But I don't know how I could possibli change the code to work... >> >> The easiest way is to pass a *function* to newton(). It'd look like this: >> >> def newton(x0, f, fx, tol, n=20000): >> ... as before, but without the nested functions >> >> newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) >> >> At least, I think that's how you're doing things. Inside the nested >> functions, you use 'a', but outside, you use 'x'. Are those >> representing the same concept? If so, the lambda functions given here >> will have the same effect. >> >> Hope that helps! >> >> ChrisA > > Hi Chris > > Thanks very much for your quick response! > I was in a bit of a rush, so I confused the variables (don't worry, I just messed arround to try different things, the original code was al tidy with the variable). > > I tried your input, but now I get another error: > > > File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, in newton > b = x - f(x)/fx(x) > > TypeError: unsupported operand type(s) for /: 'function' and 'function' > > This did not occure befor I tried to implement the user input.. Did you remove the nested functions? The lambda functions completely replace your "def f(a)" and "def fx(a)" functions. ChrisA From nicco.9537 at gmail.com Mon Dec 25 10:04:06 2017 From: nicco.9537 at gmail.com (Nico Vogeli) Date: Mon, 25 Dec 2017 07:04:06 -0800 (PST) Subject: user input string to function In-Reply-To: References: <8384056e-ac32-4cc7-9ddb-94601e37add5@googlegroups.com> Message-ID: <70862900-2410-4fb9-a9d9-78f3a8693319@googlegroups.com> Am Montag, 25. Dezember 2017 15:58:26 UTC+1 schrieb Chris Angelico: > On Tue, Dec 26, 2017 at 1:48 AM, Nico Vogeli wrote: > > Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: > >> On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli wrote: > >> > Hi everybody. First ad foremost, happy Christmas! > >> > >> Same to you! > >> > >> > I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) > >> > > >> > def newton(x0, s, s2, tol, n = 20000): > >> > ''' > >> > N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren > >> > x0 = Startwert > >> > f = zu l?sende Funktion > >> > fx = Ableitung der Funktion > >> > > >> > ''' > >> > def f(a): > >> > y = s > >> > return y > >> > > >> > def fx(a): > >> > y = s2 > >> > return y > >> > >> > >> > newton(2, 3*x**2, 6*x, 0.1, 2) > >> > > >> > I notice that the x is not converted to an integer, because of the x = symplos('x') > >> > But I don't know how I could possibli change the code to work... > >> > >> The easiest way is to pass a *function* to newton(). It'd look like this: > >> > >> def newton(x0, f, fx, tol, n=20000): > >> ... as before, but without the nested functions > >> > >> newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) > >> > >> At least, I think that's how you're doing things. Inside the nested > >> functions, you use 'a', but outside, you use 'x'. Are those > >> representing the same concept? If so, the lambda functions given here > >> will have the same effect. > >> > >> Hope that helps! > >> > >> ChrisA > > > > Hi Chris > > > > Thanks very much for your quick response! > > I was in a bit of a rush, so I confused the variables (don't worry, I just messed arround to try different things, the original code was al tidy with the variable). > > > > I tried your input, but now I get another error: > > > > > > File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, in newton > > b = x - f(x)/fx(x) > > > > TypeError: unsupported operand type(s) for /: 'function' and 'function' > > > > This did not occure befor I tried to implement the user input.. > > Did you remove the nested functions? The lambda functions completely > replace your "def f(a)" and "def fx(a)" functions. > > ChrisA I am so so sorry!! I just did not know what you meant by sested functions.. :P Thank you so much for helping me! You're great! Cheers and all the best! Nicco From rosuav at gmail.com Mon Dec 25 10:55:44 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Dec 2017 02:55:44 +1100 Subject: user input string to function In-Reply-To: <70862900-2410-4fb9-a9d9-78f3a8693319@googlegroups.com> References: <8384056e-ac32-4cc7-9ddb-94601e37add5@googlegroups.com> <70862900-2410-4fb9-a9d9-78f3a8693319@googlegroups.com> Message-ID: On Tue, Dec 26, 2017 at 2:04 AM, Nico Vogeli wrote: > Am Montag, 25. Dezember 2017 15:58:26 UTC+1 schrieb Chris Angelico: >> On Tue, Dec 26, 2017 at 1:48 AM, Nico Vogeli wrote: >> > Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: >> >> On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli wrote: >> >> > Hi everybody. First ad foremost, happy Christmas! >> >> >> >> Same to you! >> >> >> >> > I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) >> >> > >> >> > def newton(x0, s, s2, tol, n = 20000): >> >> > ''' >> >> > N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren >> >> > x0 = Startwert >> >> > f = zu l?sende Funktion >> >> > fx = Ableitung der Funktion >> >> > >> >> > ''' >> >> > def f(a): >> >> > y = s >> >> > return y >> >> > >> >> > def fx(a): >> >> > y = s2 >> >> > return y >> >> >> >> >> >> > newton(2, 3*x**2, 6*x, 0.1, 2) >> >> > >> >> > I notice that the x is not converted to an integer, because of the x = symplos('x') >> >> > But I don't know how I could possibli change the code to work... >> >> >> >> The easiest way is to pass a *function* to newton(). It'd look like this: >> >> >> >> def newton(x0, f, fx, tol, n=20000): >> >> ... as before, but without the nested functions >> >> >> >> newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) >> >> >> >> At least, I think that's how you're doing things. Inside the nested >> >> functions, you use 'a', but outside, you use 'x'. Are those >> >> representing the same concept? If so, the lambda functions given here >> >> will have the same effect. >> >> >> >> Hope that helps! >> >> >> >> ChrisA >> > >> > Hi Chris >> > >> > Thanks very much for your quick response! >> > I was in a bit of a rush, so I confused the variables (don't worry, I just messed arround to try different things, the original code was al tidy with the variable). >> > >> > I tried your input, but now I get another error: >> > >> > >> > File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, in newton >> > b = x - f(x)/fx(x) >> > >> > TypeError: unsupported operand type(s) for /: 'function' and 'function' >> > >> > This did not occure befor I tried to implement the user input.. >> >> Did you remove the nested functions? The lambda functions completely >> replace your "def f(a)" and "def fx(a)" functions. >> >> ChrisA > > I am so so sorry!! I just did not know what you meant by sested functions.. :P No need to apologize! That's why we have two-directional communication - I can ask you to clarify, you can ask me to clarify, and we get to a solution. The concept of passing functions around does take some getting used to, so there's no shame in not instantly understanding it. > Thank you so much for helping me! You're great! > > Cheers and all the best! My pleasure! Have yourself an awesome holiday season. ChrisA From nicco.9537 at gmail.com Mon Dec 25 12:49:02 2017 From: nicco.9537 at gmail.com (Nico Vogeli) Date: Mon, 25 Dec 2017 09:49:02 -0800 (PST) Subject: user input string to function In-Reply-To: References: <8384056e-ac32-4cc7-9ddb-94601e37add5@googlegroups.com> <70862900-2410-4fb9-a9d9-78f3a8693319@googlegroups.com> Message-ID: <464bdbff-7316-4101-8b21-eea71bc49bd7@googlegroups.com> Am Montag, 25. Dezember 2017 16:56:19 UTC+1 schrieb Chris Angelico: > On Tue, Dec 26, 2017 at 2:04 AM, Nico Vogeli wrote: > > Am Montag, 25. Dezember 2017 15:58:26 UTC+1 schrieb Chris Angelico: > >> On Tue, Dec 26, 2017 at 1:48 AM, Nico Vogeli wrote: > >> > Am Montag, 25. Dezember 2017 14:51:21 UTC+1 schrieb Chris Angelico: > >> >> On Tue, Dec 26, 2017 at 12:36 AM, Nico Vogeli wrote: > >> >> > Hi everybody. First ad foremost, happy Christmas! > >> >> > >> >> Same to you! > >> >> > >> >> > I want to let the use input a function (like x**2) and parse it after that through code (for my numeric class) > >> >> > > >> >> > def newton(x0, s, s2, tol, n = 20000): > >> >> > ''' > >> >> > N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren > >> >> > x0 = Startwert > >> >> > f = zu l?sende Funktion > >> >> > fx = Ableitung der Funktion > >> >> > > >> >> > ''' > >> >> > def f(a): > >> >> > y = s > >> >> > return y > >> >> > > >> >> > def fx(a): > >> >> > y = s2 > >> >> > return y > >> >> > >> >> > >> >> > newton(2, 3*x**2, 6*x, 0.1, 2) > >> >> > > >> >> > I notice that the x is not converted to an integer, because of the x = symplos('x') > >> >> > But I don't know how I could possibli change the code to work... > >> >> > >> >> The easiest way is to pass a *function* to newton(). It'd look like this: > >> >> > >> >> def newton(x0, f, fx, tol, n=20000): > >> >> ... as before, but without the nested functions > >> >> > >> >> newton(2, lambda x: 3*x**2, lambda x: 6*x, 0.1, 2) > >> >> > >> >> At least, I think that's how you're doing things. Inside the nested > >> >> functions, you use 'a', but outside, you use 'x'. Are those > >> >> representing the same concept? If so, the lambda functions given here > >> >> will have the same effect. > >> >> > >> >> Hope that helps! > >> >> > >> >> ChrisA > >> > > >> > Hi Chris > >> > > >> > Thanks very much for your quick response! > >> > I was in a bit of a rush, so I confused the variables (don't worry, I just messed arround to try different things, the original code was al tidy with the variable). > >> > > >> > I tried your input, but now I get another error: > >> > > >> > > >> > File "C:/Users/Nicco ZHAW/Desktop/Test GUI/Test Projekt.py", line 42, in newton > >> > b = x - f(x)/fx(x) > >> > > >> > TypeError: unsupported operand type(s) for /: 'function' and 'function' > >> > > >> > This did not occure befor I tried to implement the user input.. > >> > >> Did you remove the nested functions? The lambda functions completely > >> replace your "def f(a)" and "def fx(a)" functions. > >> > >> ChrisA > > > > I am so so sorry!! I just did not know what you meant by sested functions.. :P > > No need to apologize! That's why we have two-directional communication > - I can ask you to clarify, you can ask me to clarify, and we get to a > solution. > > The concept of passing functions around does take some getting used > to, so there's no shame in not instantly understanding it. > > > Thank you so much for helping me! You're great! > > > > Cheers and all the best! > > My pleasure! Have yourself an awesome holiday season. > > ChrisA Hello again So, I tried my best, was looking into the eval and exec function, but still no succsess.. Maybe it helps when I provide the code I want to implement: def newton_verfahren(self): if self.cB_1.currentText() == 'Newton': x0 = self.newton_x.text() f1 = self.func_1.text() f2 = self.func_2.text() tol = self.newton_tol.text() n = self.newton_n.text() k = Numerik_Funktionen.newton(int(x0), eval(f1), eval(f2), int(tol), int(n)) k1 = str(k[0]) k2 = str(k[1]) k3 = str(k[2]) self.ausgabe.setText('Startwert -> x0: '+ k1 + "\n" + 'Anzahl Iterationen: ' + k2 +"\n" + 'f(x~): ' + k3) Notice that cB_1 is a combobox, newton_x, func_1, func_2, newton_tol and newton_n are all QLineEdits. The code above doesn't work, so I've opend a 'test' file to just play around with the functions. Withs test, this return a correct value for the two x functions: from sympy import symbols x = symbols('x') f1 = eval(input('ssd ')) f2 = eval(input('fd ')) But now I get and error from the imported module in the line where the abs(f(x)) > tol. It states that the 'Pow' object is not callable. And now I don't know how to proceed, I can't figure out a way to make the call to the imported module: x = symbols('x') def newton(x0, f, fx, tol, n = 20000): ''' N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren x0 = Startwert f = zu l?sende Funktion fx = Ableitung der Funktion ''' x = x0 k = 0 while n > k and abs(f(x)) > tol: k += 1 x = x - f(x)/fx(x) print('x', k, '\n', x) print('Startwert -> x0', '\n', x0) print('Anzahl Iterationen', '\n', k) print('f(x~)', '\n', f(x)) print('N?herungswert -> x~', '\n', x) return x0, k, f(x), x Regards Nicco From python at mrabarnett.plus.com Mon Dec 25 13:31:26 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 25 Dec 2017 18:31:26 +0000 Subject: acircle.getCenter() to (x,y) coordinates in Python In-Reply-To: References: <3f03bec4-54e7-44ba-b2b4-0e9f91461cf1@googlegroups.com> <44bfe41e-8985-c98c-81cd-556e1b0b1297@mrabarnett.plus.com> <037947d3-70cc-425e-a711-c9cbf3a05d91@googlegroups.com> <3f0f0d74-202b-ebb7-fdfb-d88b5601c6cf@mrabarnett.plus.com> <0139c43c-e905-473c-b84c-85b0695faeb0@googlegroups.com> Message-ID: On 2017-12-25 02:42, G Yu wrote: > Ah, I get it now. I have to store the acircle.getCenter() in a point Point, and then access Point.getX() and Point.getY() separately. It was just that middle step that I was missing. Thanks so much! > It's not strictly true that you _have to_ store the result of acircle.getCenter(). You could call it twice: (acircle.getCenter().getX(), acircle.getCenter().getY()) or you could write a function for it: def as_cartesian(point): return point.getX(), point.getY() and call it: as_cartesian(acircle.getCenter()) Just pick whatever way makes the most sense. From szykcech at gmail.com Tue Dec 26 08:14:55 2017 From: szykcech at gmail.com (szykcech at gmail.com) Date: Tue, 26 Dec 2017 05:14:55 -0800 (PST) Subject: RegExp - please help me! Message-ID: Hi I use online Python reg exp editor https://pythex.org/ and I use option "multiline". I want to use my reg exp in Python script to generate automatically some part of my program written in C++ (database structure and serialization functions). In order to do this I need: 1) C++ struct name and 2) struct definition. Struct definition I need because some inline functions can appear bellow my struct definition and makes inappropriate further regexp filtering (against variables). So: I develop regexp which to my mind should work, but it doesn't and I don't know why. The broken regexp is like this: struct (.+)\s*{\s*(.+)\s*}; As you can see it has two groups: struct name and struct definition. It fails even for such simple structure: struct Structure { int mVariable1; QString mVariable2; bool mVariable3 }; Please help me with this regexp or tell me that I neeed do this in other way. thanks, happy Christmas, and happy New Year Szyk Cech From vlastimil.brom at gmail.com Tue Dec 26 10:27:32 2017 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 26 Dec 2017 16:27:32 +0100 Subject: RegExp - please help me! In-Reply-To: References: Message-ID: Hi, I can't comment, whether this is the right approach, as I have no experiences with C++, but for the matching regular expression itself, I believe, e.g. the following might work for your sample data (I am not sure, however, what other details or variants should be taken into account): (?s)struct (.+?)\s*\{\s*(.+?)\s*\}; i.e. you need to escape the metacharacters { } with a backslash \ and in the current form of the pattern, you also need the flag DOTALL - set via (?s) in the example above - in order to also match newlines with . (alternatively, you could use \n specifically in the pattern, where needed.) it is possible, that an online regex tester uses some flags implicitly. I believe, the non-greedy quantifiers are suitable here +? matching as little as possible, otherwise the pattern would match between the first and the last structs in the source text at once. It seems, the multiline flag is not needed here, as there are no affected metacharacters. hth, vbr ================= 2017-12-26 14:14 GMT+01:00, szykcech at gmail.com : > Hi > I use online Python reg exp editor https://pythex.org/ and I use option > "multiline". > I want to use my reg exp in Python script to generate automatically some > part of my program written in C++ (database structure and serialization > functions). In order to do this I need: 1) C++ struct name and 2) struct > definition. Struct definition I need because some inline functions can > appear bellow my struct definition and makes inappropriate further regexp > filtering (against variables). > > So: I develop regexp which to my mind should work, but it doesn't and I > don't know why. The broken regexp is like this: > struct (.+)\s*{\s*(.+)\s*}; > As you can see it has two groups: struct name and struct definition. > It fails even for such simple structure: > struct Structure > { > int mVariable1; > QString mVariable2; > bool mVariable3 > }; > > Please help me with this regexp or tell me that I neeed do this in other > way. > > thanks, happy Christmas, and happy New Year > Szyk Cech > -- > https://mail.python.org/mailman/listinfo/python-list > From pkpearson at nowhere.invalid Tue Dec 26 14:02:15 2017 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 26 Dec 2017 19:02:15 GMT Subject: RegExp - please help me! References: Message-ID: On Tue, 26 Dec 2017 05:14:55 -0800 (PST), szykcech at gmail.com wrote: [snip] > So: I develop regexp which to my mind should work, but it doesn't and > I don't know why. The broken regexp is like this: > struct (.+)\s*{\s*(.+)\s*}; [snip] You'll probably get better help faster if you can present your problem as a couple lines of code, and ask "Why does this print XXX, when I'm expecting it to print YYY?" (Sorry I'm not smart enough to give you an answer to your actual question.) -- To email me, substitute nowhere->runbox, invalid->com. From szykcech at gmail.com Tue Dec 26 14:14:32 2017 From: szykcech at gmail.com (szykcech at gmail.com) Date: Tue, 26 Dec 2017 11:14:32 -0800 (PST) Subject: RegExp - please help me! In-Reply-To: References: Message-ID: <77a5c366-183b-49c1-8f6a-ed78c68e338c@googlegroups.com> > (?s)struct (.+?)\s*\{\s*(.+?)\s*\}; Thank you Vlastimil Brom for regexp and for explanation! From szykcech at gmail.com Wed Dec 27 00:37:56 2017 From: szykcech at gmail.com (szykcech at gmail.com) Date: Tue, 26 Dec 2017 21:37:56 -0800 (PST) Subject: RegExp - please help me! (Posting On Python-List Prohibited) In-Reply-To: <58a94c42-8853-41f3-ba72-e76f09748a0c@googlegroups.com> References: <58a94c42-8853-41f3-ba72-e76f09748a0c@googlegroups.com> Message-ID: W dniu wtorek, 26 grudnia 2017 21:53:14 UTC+1 u?ytkownik Lawrence D?Oliveiro napisa?: > On Wednesday, December 27, 2017 at 2:15:21 AM UTC+13, szyk... at gmail.com wrote: > > struct (.+)\s*{\s*(.+)\s*}; > > You realize that ?.? matches anything? Whereas I think you want to match non-whitespace in those places. I realize that. I want skip white-spaces from the beginning and from the end and match entire body of C++ struct declaration (with white spaces inside as well). Maybe should I use "".strip(" ").strip("\t").strip("\n") function after matching? From lele at metapensiero.it Wed Dec 27 03:31:39 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 27 Dec 2017 09:31:39 +0100 Subject: RegExp - please help me! References: Message-ID: <87fu7wo9lg.fsf@metapensiero.it> szykcech at gmail.com writes: > Please help me with this regexp or tell me that I neeed do this in other way. I think that using regexps to parse those structures is fragile and difficult to get right[0], as there are lots of corner cases (comments, complex types, ...). I'd suggest using a tool designed to do that, for example pycparser[1], that provides the required infrastructure to parse C units into an AST: from there you can easily extract interesting pieces and write out in whatever format you need. As an example, I used it to extract[2] enums and defines from PostgreSQL C headers[3] and rewrite them as Python definitions[4]. Good luck, ciao, lele. [0] http://regex.info/blog/2006-09-15/247 [1] https://github.com/eliben/pycparser [2] https://github.com/lelit/pg_query/blob/master/tools/extract_enums.py [3] https://github.com/lfittl/libpg_query/blob/43ce2e8cdf54e4e1e8b0352e37adbd72e568e100/src/postgres/include/nodes/parsenodes.h [4] https://github.com/lelit/pg_query/blob/master/pg_query/enums/parsenodes.py -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From kirillbalunov at gmail.com Wed Dec 27 05:41:10 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Wed, 27 Dec 2017 13:41:10 +0300 Subject: Default annotations for variables Message-ID: Will there be any implications (or is it possible) if all variables will have an attribute *something like* `__type__` which by default will be initialized to *something like* `AnyType`. So in the case `x = 12` will be equivalent to `x: AnyType = 12`. x: int x = 12 x.__type__ # int a, b = 11, 12 a.__type__ # AnyType b.__type__ # AnyType And also in this case: class Dummy: a: int b: float c = [] Dummy.__annotations__ # will be {'a': int, 'b': float, 'c': AnyType} While I ask purely out of curiosity, I think this is not an off-topic for python-list. With kind regards, -gdg From rosuav at gmail.com Wed Dec 27 05:54:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Dec 2017 21:54:50 +1100 Subject: Default annotations for variables In-Reply-To: References: Message-ID: On Wed, Dec 27, 2017 at 9:41 PM, Kirill Balunov wrote: > Will there be any implications (or is it possible) if all variables will > have an attribute *something like* `__type__` which by default will be > initialized to *something like* `AnyType`. So in the case `x = 12` will be > equivalent to `x: AnyType = 12`. > > x: int > x = 12 > x.__type__ # int > > a, b = 11, 12 > a.__type__ # AnyType > b.__type__ # AnyType This won't work. When you say "a.__type__", it means "take the *value* referenced by a, and look up its __type__ attribute". So it's equivalent to writing: (11).__type__ (12).__type__ To query something about the *variable*, you have to look at its enclosing namespace. If these are at top level, you'd be looking at the module-level __annotations__ dictionary. That's also where x.__type__ would be - it's actually stored in __annotations__["x"]. > And also in this case: > > class Dummy: > a: int > b: float > c = [] > > Dummy.__annotations__ # will be {'a': int, 'b': float, 'c': AnyType} Now, this situation might be of some interest to the dataclass discussions. Currently, there's a limitation in that no single source has information about all three attributes; and that means that the order ["a", "b", "c"] is actually not stored anywhere. (Annotations are ordered within themselves; values are ordered within themselves; but annotations and values are separate.) There is definitely room to ask the question "can we get default annotations for any global or class-level name that gets assigned to without an annotation?". I fully expect that thread to be one of those gigantic ones, but have fun :) > While I ask purely out of curiosity, I think this is not an off-topic for > python-list. Absolutely, it's not off-topic! Though at some point it might need to migrate to python-ideas, if there's a proposal to actually change the language. But there's nothing wrong with asking the question here on python-list. ChrisA From kirillbalunov at gmail.com Wed Dec 27 06:19:09 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Wed, 27 Dec 2017 14:19:09 +0300 Subject: Default annotations for variables In-Reply-To: References: Message-ID: 2017-12-27 13:54 GMT+03:00 Chris Angelico : > This won't work. When you say "a.__type__", it means "take the *value* > referenced by a, and look up its __type__ attribute". So it's > equivalent to writing: > > (11).__type__ > (12).__type__ > Thank you for clarification, I understand that names don't have attributes :). But I did not find the right words to describe the idea. > To query something about the *variable*, you have to look at its > enclosing namespace. If these are at top level, you'd be looking at > the module-level __annotations__ dictionary. That's also where > x.__type__ would be - it's actually stored in __annotations__["x"]. > Here I was a bit knocked down by the IPython console. Strangely, but the ` __annotations__` is not initialized to a an empty dict when you start it, while in Python console it is. > There is definitely room to ask the question "can we get default > annotations for any global or class-level name that gets assigned to > without an annotation?". I fully expect that thread to be one of those > gigantic ones, but have fun :) > Yes this is exactly what I was about to ask :) With kind regards, -gdg From kirillbalunov at gmail.com Wed Dec 27 06:39:49 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Wed, 27 Dec 2017 14:39:49 +0300 Subject: Default annotations for variables In-Reply-To: References: Message-ID: 2017-12-27 14:19 GMT+03:00 Kirill Balunov : > Here I was a bit knocked down by the IPython console. Strangely, but the ` > __annotations__` is not initialized to a an empty dict when you start it, > while in Python console it is. > In addition, there are some imbalance without IPython. Since modules and classes define namespaces it is strange that: empty `module` -> has `__annotations__` defined to {}. empty `class` -> does not have `__annotations__` raises AttributeError. With kind regards, -gdg From skip.montanaro at gmail.com Wed Dec 27 09:58:51 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 27 Dec 2017 08:58:51 -0600 Subject: PyWin32 installer question Message-ID: I'm fiddling around with Appveyor, trying to build a Windows installer for SpamBayes. This is complicated by two facts: 1. I don't know squat about Windows. 2. I don't have access to a Windows command line. Consequently, every new attempt requires a change to appveyor.yml and a git push command. Rather slow going. My latest Appveyor build number is 59. Most of the changes were simple fixes for syntax errors. I got to the point where I (finally!) was able to successfully download the appropriate pywin32 installer, but executing it just hangs. I sort of assume it's asking os.devnull for something. Alas, I couldn't find any sort of command line flags for the installer itself in the pywin32 code. I've tried pywin32.exe /h but that just sits there (ignores that flag?) and pywin32.exe /? which produced some inscrutable output. Is there some way to coax it into giving me some help and exiting? Thanks, Skip From songofacandy at gmail.com Wed Dec 27 13:08:20 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Thu, 28 Dec 2017 03:08:20 +0900 Subject: Default annotations for variables In-Reply-To: References: Message-ID: typing's primary intention is "static" typing with tools like mypy. Introspection is not primary usage. Adding such information for every class, module, etc makes Python slower and fatter. But I want to make Python more swift and slim. INADA Naoki On Wed, Dec 27, 2017 at 8:39 PM, Kirill Balunov wrote: > 2017-12-27 14:19 GMT+03:00 Kirill Balunov : > >> Here I was a bit knocked down by the IPython console. Strangely, but the ` >> __annotations__` is not initialized to a an empty dict when you start it, >> while in Python console it is. >> > > In addition, there are some imbalance without IPython. Since modules and > classes define namespaces it is strange that: > > empty `module` -> has `__annotations__` defined to {}. > empty `class` -> does not have `__annotations__` raises AttributeError. > > With kind regards, -gdg > -- > https://mail.python.org/mailman/listinfo/python-list From exarkun at twistedmatrix.com Wed Dec 27 19:27:56 2017 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Wed, 27 Dec 2017 19:27:56 -0500 Subject: [ANN] txaws 0.5.0 Message-ID: Hello all, I'm pleased to announce the release of txAWS 0.5.0. txAWS is a library for interacting with Amazon Web Services (AWS) using Twisted. You can download the release from PyPI . Since the last release, the following enhancements have been made: Features > -------- > - txaws.s3.client.S3Client.get_bucket now accepts a ``prefix`` parameter > for > selecting a subset of S3 objects. (#78) > - txaws.ec2.client.EC2Client now has a ``get_console_output`` method > binding > the ``GetConsoleOutput`` API. (#82) Thanks to everyone who contributed and to Least Authority TFA GmbH for sponsoring my work on this release. Jean-Paul From duram at newsguy.com Wed Dec 27 21:58:48 2017 From: duram at newsguy.com (Duram) Date: Thu, 28 Dec 2017 00:58:48 -0200 Subject: Goto Message-ID: How to use goto in python? --- This email has been checked for viruses by AVG. http://www.avg.com From KP0089084 at TechMahindra.com Thu Dec 28 00:43:22 2017 From: KP0089084 at TechMahindra.com (Kirankumar Reddy Polu) Date: Thu, 28 Dec 2017 05:43:22 +0000 Subject: Python Software Installation - Failed Message-ID: <11ecac3a6d1b4730b49e7d58f3d764e5@HYDEXCHMBX005.TechMahindra.com> Hi, I am trying to install Python 3.6.4 in my laptop. I am getting the following error. I also attached failure log as well in the mail. I could not change the path. It is automatically installing in C drive. Might be, this is restricted drive, so we got errors. I am not sure, but let me know as well to do the path changes at D drive. Please suggest me to do the installation steps without failures of the attached logs. [cid:image001.png at 01D37FFA.E81295C0] Regards, Kiran Polu ============================================================================================================================ Disclaimer: This message and the information contained herein is proprietary and confidential and subject to the Tech Mahindra policy statement, you may review the policy at http://www.techmahindra.com/Disclaimer.html externally http://tim.techmahindra.com/tim/disclaimer.html internally within TechMahindra. ============================================================================================================================ From nicco.9537 at gmail.com Thu Dec 28 04:38:30 2017 From: nicco.9537 at gmail.com (Nico Vogeli) Date: Thu, 28 Dec 2017 01:38:30 -0800 (PST) Subject: GUI user input to function Message-ID: <9238b7ff-e75a-47ab-8c2d-b1b82a1b38e3@googlegroups.com> Hello again I think my question got lost in all the others raised, so here I am again :P So, I tried my best, was looking into the eval and exec function, but still no succsess.. Maybe it helps when I provide the code I want to implement: def newton_verfahren(self): if self.cB_1.currentText() == 'Newton': x0 = self.newton_x.text() f1 = self.func_1.text() f2 = self.func_2.text() tol = self.newton_tol.text() n = self.newton_n.text() k = Numerik_Funktionen.newton(int(x0), eval(f1), eval(f2), int(tol), int(n)) k1 = str(k[0]) k2 = str(k[1]) k3 = str(k[2]) self.ausgabe.setText('Startwert -> x0: '+ k1 + "\n" + 'Anzahl Iterationen: ' + k2 +"\n" + 'f(x~): ' + k3) Notice that cB_1 is a combobox, newton_x, func_1, func_2, newton_tol and newton_n are all QLineEdits. The code above doesn't work, so I've opend a 'test' file to just play around with the functions. Withs test, this return a correct value for the two x functions: from sympy import symbols x = symbols('x') f1 = eval(input('function 1 ')) f2 = eval(input('function 2 ')) But now I get and error from the imported module in the line where the abs(f(x)) > tol. It states that the 'Pow' object is not callable. And now I don't know how to proceed, I can't figure out a way to make the call to the imported module: x = symbols('x') def newton(x0, f, fx, tol, n = 20000): ''' N?herung zur l?sung einer Gleichung mit dem Newton-Verfahren x0 = Startwert f = zu l?sende Funktion fx = Ableitung der Funktion ''' x = x0 k = 0 while n > k and abs(f(x)) > tol: k += 1 x = x - f(x)/fx(x) print('x', k, '\n', x) print('Startwert -> x0', '\n', x0) print('Anzahl Iterationen', '\n', k) print('f(x~)', '\n', f(x)) print('N?herungswert -> x~', '\n', x) return x0, k, f(x), x Regards Nicco From jorge.conrado at cptec.inpe.br Thu Dec 28 06:43:42 2017 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Thu, 28 Dec 2017 09:43:42 -0200 Subject: Python goto Message-ID: Hi, I would like to know if there is a goto command or something similar that I can use in Python. Thanks, Conrado From rosuav at gmail.com Thu Dec 28 06:58:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Dec 2017 22:58:55 +1100 Subject: GUI user input to function In-Reply-To: <9238b7ff-e75a-47ab-8c2d-b1b82a1b38e3@googlegroups.com> References: <9238b7ff-e75a-47ab-8c2d-b1b82a1b38e3@googlegroups.com> Message-ID: On Thu, Dec 28, 2017 at 8:38 PM, Nico Vogeli wrote: > Withs test, this return a correct value for the two x functions: > > from sympy import symbols > > x = symbols('x') > f1 = eval(input('function 1 ')) > f2 = eval(input('function 2 ')) > What are you typing as input? It's hard to grok your code without knowing that. ChrisA From nicco.9537 at gmail.com Thu Dec 28 07:06:28 2017 From: nicco.9537 at gmail.com (Nico Vogeli) Date: Thu, 28 Dec 2017 04:06:28 -0800 (PST) Subject: GUI user input to function In-Reply-To: References: <9238b7ff-e75a-47ab-8c2d-b1b82a1b38e3@googlegroups.com> Message-ID: Am Donnerstag, 28. Dezember 2017 12:59:24 UTC+1 schrieb Chris Angelico: > On Thu, Dec 28, 2017 at 8:38 PM, Nico Vogeli wrote: > > Withs test, this return a correct value for the two x functions: > > > > from sympy import symbols > > > > x = symbols('x') > > f1 = eval(input('function 1 ')) > > f2 = eval(input('function 2 ')) > > > > What are you typing as input? It's hard to grok your code without knowing that. > > ChrisA I'm sorry! User input would look like this for example: x**2 + 3*x or x**3 Regards Nicco From ned at nedbatchelder.com Thu Dec 28 07:20:42 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 28 Dec 2017 07:20:42 -0500 Subject: Python goto In-Reply-To: References: Message-ID: <474715f5-dfcc-67b2-6a30-9b977882f5fe@nedbatchelder.com> On 12/28/17 6:43 AM, jorge.conrado at cptec.inpe.br wrote: > > > Hi, > > I would like to know if there is a goto command or something similar > that I can use in Python. > Python does not have a goto statement. You have to use structured statements: for, while, try/except, yield, return, etc. If you show an example of where you would like to use a goto, we can help find a different way. --Ned. From skip.montanaro at gmail.com Thu Dec 28 07:35:01 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 28 Dec 2017 06:35:01 -0600 Subject: Python goto In-Reply-To: <474715f5-dfcc-67b2-6a30-9b977882f5fe@nedbatchelder.com> References: <474715f5-dfcc-67b2-6a30-9b977882f5fe@nedbatchelder.com> Message-ID: Jorge> I would like to know if there is a goto command or something similar that Jorge> I can use in Python. Ned> Python does not have a goto statement. You have to use structured Ned> statements: for, while, try/except, yield, return, etc. Though it appears some wag has used function decorators to implement goto statements: https://pypi.python.org/pypi/goto-statement/1.1 Rather clever, it seems. Skip From rosuav at gmail.com Thu Dec 28 07:59:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Dec 2017 23:59:40 +1100 Subject: GUI user input to function In-Reply-To: References: <9238b7ff-e75a-47ab-8c2d-b1b82a1b38e3@googlegroups.com> Message-ID: On Thu, Dec 28, 2017 at 11:06 PM, Nico Vogeli wrote: > Am Donnerstag, 28. Dezember 2017 12:59:24 UTC+1 schrieb Chris Angelico: >> On Thu, Dec 28, 2017 at 8:38 PM, Nico Vogeli wrote: >> > Withs test, this return a correct value for the two x functions: >> > >> > from sympy import symbols >> > >> > x = symbols('x') >> > f1 = eval(input('function 1 ')) >> > f2 = eval(input('function 2 ')) >> > >> >> What are you typing as input? It's hard to grok your code without knowing that. >> >> ChrisA > > I'm sorry! User input would look like this for example: x**2 + 3*x or x**3 > Cool. That's an expression, but it isn't a function. To make that into a function, you need to prefix it with the lambda keyword. So you should be able to construct functions like this: f1 = eval("lambda x: " + input("function 1: ")) Then, when you type "x**3", Python evaluates "lambda x: x**3", which is a function. ChrisA From joanazpeitia at gmail.com Thu Dec 28 12:02:55 2017 From: joanazpeitia at gmail.com (joanazpeitia at gmail.com) Date: Thu, 28 Dec 2017 09:02:55 -0800 (PST) Subject: win32wnet.WNetAddConnection2 issue Message-ID: <09a5f001-c0b5-4eda-a6ab-b531287b68e6@googlegroups.com> Hi guys, I've seen a few posts about this topic but could not find the solution. I am trying to connect a drive to a network drive using win32wnet.WNetAddConnection2 but I might be missing something because it does not work. This is what I have. import os import win32api import win32wnet import win32netcon,win32wnet ynetworkPath = '\\\\LAMPSERVER_RB\\resources_server\\' znetworkPath = '\\\\LAMPSERVER\\lampserver\\_PROJECTS\\' yDrive = 'Y:' user='aa' password='bb' def mapResourcesDrive(): print ynetworkPath if (os.path.exists(yDrive)): print "Y drive is already mapped" if (os.path.exists(ynetworkPath)): print ynetworkPath, " is found..." print "Trying to map ", ynetworkPath, " on to ", yDrive, " ....." try: win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, yDrive, ynetworkPath, None, user, password) print "connection established succesfully" except: print "Unexpected error..." return -1 print "Mapping successful" return 1 else: print "Network path unreachable..." mapResourcesDrive() If anyone can give me an idea of why win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, yDrive, ynetworkPath, None, user, password) is not working owuld be much appreciatted. Many thanks, Joan From p.f.moore at gmail.com Thu Dec 28 12:15:23 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 28 Dec 2017 17:15:23 +0000 Subject: PyWin32 installer question In-Reply-To: References: Message-ID: When I took a quick look at the code, it seemed to be based on a pretty old version of Python. What version are you using? If it's 2.7 (or better still, Python 3!) then you should have pip available. In which case you may be better off using pypiwin32, which is a rebundling of pywin32 as a wheel. "python -m pip install pypiwin21" should work for you. You may need to force the version to be 219, as there's only Python 3.6 wheels for version 220 (do this as "python -m pip install pypiwin32==219") - but I don't think you'll need this, pip should limit itself to compatible wheels. Unfortunately, pywin32 is one of the worst extensions to install, as the project doesn't supply official wheels, and some of the COM stuff needs registration, which in the wininst script is handled by a post-install step, but I've no idea how you do that with a wheel - you may need to ask the project maintainers for advice. Paul On 27 December 2017 at 14:58, Skip Montanaro wrote: > I'm fiddling around with Appveyor, trying to build a Windows installer > for SpamBayes. This is complicated by two facts: > > 1. I don't know squat about Windows. > > 2. I don't have access to a Windows command line. > > Consequently, every new attempt requires a change to appveyor.yml and > a git push command. Rather slow going. My latest Appveyor build number > is 59. Most of the changes were simple fixes for syntax errors. > > I got to the point where I (finally!) was able to successfully > download the appropriate pywin32 installer, but executing it just > hangs. I sort of assume it's asking os.devnull for something. Alas, I > couldn't find any sort of command line flags for the installer itself > in the pywin32 code. I've tried > > pywin32.exe /h > > but that just sits there (ignores that flag?) and > > pywin32.exe /? > > which produced some inscrutable output. > > Is there some way to coax it into giving me some help and exiting? > > Thanks, > > Skip > -- > https://mail.python.org/mailman/listinfo/python-list From skip.montanaro at gmail.com Thu Dec 28 12:49:57 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 28 Dec 2017 11:49:57 -0600 Subject: PyWin32 installer question In-Reply-To: References: Message-ID: Thanks for the help, Paul. > When I took a quick look at the code, it seemed to be based on a > pretty old version of Python. What version are you using? Yes, last time a Windows installer was created, Python 2.5 was still in vogue. I switched things to 2.7 with (so far) no obvious problems. I eventually got past the pywin32 install hassles you referred to when I stumbled on the pypiwin32 package: https://pypi.python.org/pypi/pypiwin32/220 On the PyPI site, it does, indeed, look like only Python 3 is supported, but it seemed to download and install a 2.7 version. This is from my latest 32-bit build: pip install py2exe_py2 pypiwin32 Pillow lockfile Collecting py2exe_py2 Downloading py2exe_py2-0.6.9-cp27-none-win32.whl (134kB) Collecting pypiwin32 Downloading pypiwin32-219-cp27-none-win32.whl (6.7MB) Collecting Pillow Downloading Pillow-4.3.0-cp27-cp27m-win32.whl (1.3MB) Collecting lockfile Downloading lockfile-0.12.2-py2.py3-none-any.whl (I guess it fell back to 219 automatically. Clever tool, that pip...) So, I'm past that hurdle, and eventually got a successful 32-bit build: https://ci.appveyor.com/project/smontanaro/spambayes/build/job/5pflj8b6t3qn0naw/artifacts but now I'm fumbling around with 64-bit (my holy grail, as most Outlook users are running a 64-bit version, at least based on the install questions we get on the SpamBayes mailing list): pip install py2exe_py2 pypiwin32 Pillow lockfile Collecting py2exe_py2 Could not find a version that satisfies the requirement py2exe_py2 (from versions: ) That error message isn't telling me much about why the requirement isn't satisfied. The name of the wheel file suggests that it's architecture-independent: py2exe_py2-0.6.9-cp27-none-win32.whl Any idea what it's complaining about? Skip From alister.ware at ntlworld.com Thu Dec 28 14:39:47 2017 From: alister.ware at ntlworld.com (alister) Date: Thu, 28 Dec 2017 19:39:47 GMT Subject: Goto References: Message-ID: <7Mb1C.278680$gi3.141689@fx19.am4> On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: > How to use goto in python? > > --- > This email has been checked for viruses by AVG. > http://www.avg.com Dont! actually you cant - there isn't one* *at least not in the core language no doubt some sick person will have manager to hack together some sort of dodgy code to simulate it if you look hard enough) -- Bigmac's brother was reliably believed to be in the job of moving video recorders around in an informal way. (Only You Can Save Mankind) From ben+python at benfinney.id.au Thu Dec 28 16:42:16 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 29 Dec 2017 08:42:16 +1100 Subject: Goto References: Message-ID: <85h8samsw7.fsf@benfinney.id.au> Duram writes: > How to use goto in python? Step 0: what is goto in Python? Step 1: that's not something that exists in Python. So why are you asking how to use something that doesn't exist? -- \ ?[R]ightful liberty is unobstructed action, according to our | `\ will, within limits drawn around us by the equal rights of | _o__) others.? ?Thomas Jefferson, 1819 | Ben Finney From p.f.moore at gmail.com Thu Dec 28 17:28:04 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 28 Dec 2017 22:28:04 +0000 Subject: PyWin32 installer question In-Reply-To: References: Message-ID: On 28 December 2017 at 17:49, Skip Montanaro wrote: > pip install py2exe_py2 pypiwin32 Pillow lockfile > Collecting py2exe_py2 > Could not find a version that satisfies the requirement py2exe_py2 > (from versions: ) > > That error message isn't telling me much about why the requirement > isn't satisfied. > > The name of the wheel file suggests that it's architecture-independent: > > py2exe_py2-0.6.9-cp27-none-win32.whl > > Any idea what it's complaining about? That's not an architecture-independent file. The Wheel spec gives all the details, but "cp27" (as opposed to "py27") means it's CPython only (which usually means it's got a C extension) and "win32" is 32-bit only ("win_amd64" is the tag for 64-bit Windows). So the problem is that the py2exe_py2 maintainer doesn't supply a 64-bit build. You could ask the maintainers if they could supply a 64-bit build. You may be able to build your own copy, but without a Windows system, doing so on Appveyor will be a real pain. Another option is to use Christoph Gohlke's builds, from https://www.lfd.uci.edu/~gohlke/pythonlibs/#py2exe - you have to download the wheel file manually (the site doesn't support automated downloads) and then upload it to Appveyor somehow (maybe by keeping a copy of the wheel in the project repo). Also the version there is 0.6.10a1 which looks like an alpha rather than the last official release. So I guess there may be issues with that. Worst case scenario would be to switch to something other than py2exe - cx_Freeze seems similar and pretty good, and it *does* ship 64-bit Python 2.7 wheels. But that's obviously a non-trivial task. Welcome to the bad old days of trying to find Windows binaries for Python packages :-( I'd strongly recommend moving to Python 3, as the situation is immensely improved there - most projects ship Python 3 binary wheels, and "pip install" just works in many cases. But I appreciate that doesn't help much for you. Sorry - hopefully one of the other options above will help. Paul From python.list at tim.thechases.com Thu Dec 28 17:38:36 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 28 Dec 2017 16:38:36 -0600 Subject: Goto In-Reply-To: <85h8samsw7.fsf@benfinney.id.au> References: <85h8samsw7.fsf@benfinney.id.au> Message-ID: <20171228163836.3b89f320@bigbox.christie.dr> On 2017-12-29 08:42, Ben Finney wrote: > Duram writes: > > > How to use goto in python? > > Step 0: what is goto in Python? > > Step 1: that's not something that exists in Python. So why are you > asking how to use something that doesn't exist? so quick to shoot down a poor soul. http://entrian.com/goto/ Gives you both GOTO and COMEFROM ;-) -tkc From bc at freeuk.com Thu Dec 28 19:17:31 2017 From: bc at freeuk.com (bartc) Date: Fri, 29 Dec 2017 00:17:31 +0000 Subject: Goto In-Reply-To: References: <85h8samsw7.fsf@benfinney.id.au> Message-ID: On 28/12/2017 21:42, Ben Finney wrote: > Duram writes: > >> How to use goto in python? > > Step 0: what is goto in Python? > > Step 1: that's not something that exists in Python. So why are you > asking how to use something that doesn't exist? Goto exists in the form of the JUMP_ABSOLUTE byte-code. But it's not accessible from the language. -- bartc From ben+python at benfinney.id.au Thu Dec 28 19:35:32 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 29 Dec 2017 11:35:32 +1100 Subject: Goto References: <85h8samsw7.fsf@benfinney.id.au> Message-ID: <85d12ymkvf.fsf@benfinney.id.au> bartc writes: > But it's not accessible from the language. Another way to say that (and the way I said the same thing) is: It doesn't exist in Python. -- \ ?I went to the museum where they had all the heads and arms | `\ from the statues that are in all the other museums.? ?Steven | _o__) Wright | Ben Finney From rosuav at gmail.com Thu Dec 28 20:27:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Dec 2017 12:27:46 +1100 Subject: Goto In-Reply-To: References: <85h8samsw7.fsf@benfinney.id.au> Message-ID: On Fri, Dec 29, 2017 at 11:17 AM, bartc wrote: > On 28/12/2017 21:42, Ben Finney wrote: >> >> Duram writes: >> >>> How to use goto in python? >> >> >> Step 0: what is goto in Python? >> >> Step 1: that's not something that exists in Python. So why are you >> asking how to use something that doesn't exist? > > > Goto exists in the form of the JUMP_ABSOLUTE byte-code. > > But it's not accessible from the language. > That's an implementation detail in one implementation of Python (albeit the most popular one). It is not part of the language. ChrisA From breamoreboy at gmail.com Thu Dec 28 21:54:31 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 28 Dec 2017 18:54:31 -0800 (PST) Subject: Goto In-Reply-To: <7Mb1C.278680$gi3.141689@fx19.am4> References: <7Mb1C.278680$gi3.141689@fx19.am4> Message-ID: On Thursday, December 28, 2017 at 7:40:14 PM UTC, alister wrote: > On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: > > > How to use goto in python? > > > > --- > > This email has been checked for viruses by AVG. > > http://www.avg.com > > Dont! > actually you cant - there isn't one* > > *at least not in the core language no doubt some sick person will have > manager to hack together some sort of dodgy code to simulate it if you > look hard enough) > This http://entrian.com/goto/ has been around for almost 14 years. -- Kindest regards. Mark Lawrence. From ben+python at benfinney.id.au Thu Dec 28 22:27:58 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 29 Dec 2017 14:27:58 +1100 Subject: Goto References: <85h8samsw7.fsf@benfinney.id.au> <20171228163836.3b89f320@bigbox.christie.dr> Message-ID: <858tdmmcw1.fsf@benfinney.id.au> Tim Chase writes: > [third-party website] > Gives you [?] So, it's not in Python, it's a third-party (joke) package. Hence is probably not what Duram is asking about as ?goto in Python?. I'm still open to learning what Duram meant by ?goto in Python?. Rather than everyone else piling on with suggestions, can we let Duram answer? -- \ ?Think for yourselves and let others enjoy the privilege to do | `\ so too.? ?Voltaire, _Essay On Tolerance_ | _o__) | Ben Finney From breamoreboy at gmail.com Thu Dec 28 22:41:54 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 28 Dec 2017 19:41:54 -0800 (PST) Subject: Goto In-Reply-To: References: <85h8samsw7.fsf@benfinney.id.au> <20171228163836.3b89f320@bigbox.christie.dr> <858tdmmcw1.fsf@benfinney.id.au> Message-ID: <7735a2f9-1581-4de6-9c4a-d7792d940e5c@googlegroups.com> On Friday, December 29, 2017 at 3:28:23 AM UTC, Ben Finney wrote: > Tim Chase writes: > > > [third-party website] > > Gives you [?] > > So, it's not in Python, it's a third-party (joke) package. Hence is > probably not what Duram is asking about as ?goto in Python?. > > I'm still open to learning what Duram meant by ?goto in Python?. Rather > than everyone else piling on with suggestions, can we let Duram answer? > > -- > \ ?Think for yourselves and let others enjoy the privilege to do | > `\ so too.? ?Voltaire, _Essay On Tolerance_ | > _o__) | > Ben Finney Did you miss Tim's wink, which you've cut from your reply, or did you get out of bed on the wrong side this morning, or what? -- Kindest regards. Mark Lawrence. From kirillbalunov at gmail.com Fri Dec 29 04:34:08 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Fri, 29 Dec 2017 12:34:08 +0300 Subject: Creation of a metaclass for dataclass. Message-ID: I'm studying the meta-programming topic in Python, and as an exercise I'm trying to make a somewhat simplified version of dataclass. My goal in this exercise is to make the difference between annotated variables and usual ones to be as much transparent as possible. So I come with this code to obtain initial fields. It does not catch corner cases and as much as possible undressed to be short. So my question is there any visible pitfalls or am I doing something wrong from the early beginning? Two helpful functions not to clutter `__annotations__`: from typing import Any AnyType = Any def _is_not_dunder(name): return not ((len(name) > 4) and (name[:2] == name[-2:] == '__')) def _is_not_descriptor(obj): return not (hasattr(obj, '__get__') or hasattr(obj, '__set__') or hasattr(obj, '__delete__')) The special dict (class namespace) to inject usual variables in ` __annotations__` with default typehint - `AnyType`, and also keep their ordered appearance in the class body. class SpecialDict(dict): def __init__(self): super().__init__() super().__setitem__('__annotations__', {}) def __setitem__(self, key, value): if not (key in self) and _is_not_dunder(key) and _is_not_descriptor(value): self['__annotations__'][key] = AnyType super().__setitem__(key, value) Data meta-class which defines `__fields` from `__annotations__`: class DataMeta(type): @classmethod def __prepare__(metacls, cls, bases, **kwargs): _dict = SpecialDict() return _dict def __init__(cls, *args , **kwargs): super().__init__(*args) def __new__(metacls, cls, bases, clsdict): clsdict['__fields'] = tuple(clsdict['__annotations__'].items()) _cls = type.__new__(metacls, cls, bases, clsdict) return _cls And test class: class MyClass(metaclass=DataMeta): a: float barattr: int = 2 jik = 12 bzik: int =14 def foo(self, param): pass data = MyClass() a.__fields # (('a', float), ('barattr', int), ('jik', typing.Any), ('bzik', int)) Thank you! With kind regards, -gdg From none at invalid.com Fri Dec 29 04:49:50 2017 From: none at invalid.com (mm0fmf) Date: Fri, 29 Dec 2017 09:49:50 +0000 Subject: Goto In-Reply-To: References: <85h8samsw7.fsf@benfinney.id.au> <20171228163836.3b89f320@bigbox.christie.dr> Message-ID: On 28/12/2017 22:38, Tim Chase wrote: > On 2017-12-29 08:42, Ben Finney wrote: >> Duram writes: >> >>> How to use goto in python? >> >> Step 0: what is goto in Python? >> >> Step 1: that's not something that exists in Python. So why are you >> asking how to use something that doesn't exist? > > so quick to shoot down a poor soul. > > http://entrian.com/goto/ > > Gives you both GOTO and COMEFROM ;-) > > -tkc > > > > This! An awful lot of my early C++, C# and Python programs resembled FORTRAN66, it took effort to learn the Zen of each language. Now I can continue to write FORTRAN66 style programs in Python and unlearn all the good stuff. Thank you. And remember, a good programmer can write FORTRAN66 programs in any language! From alister.ware at ntlworld.com Fri Dec 29 04:52:48 2017 From: alister.ware at ntlworld.com (alister) Date: Fri, 29 Dec 2017 09:52:48 GMT Subject: Goto References: <7Mb1C.278680$gi3.141689@fx19.am4> Message-ID: On Thu, 28 Dec 2017 18:54:31 -0800, breamoreboy wrote: > On Thursday, December 28, 2017 at 7:40:14 PM UTC, alister wrote: >> On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: >> >> > How to use goto in python? >> > >> > --- >> > This email has been checked for viruses by AVG. >> > http://www.avg.com >> >> Dont! >> actually you cant - there isn't one* >> >> *at least not in the core language no doubt some sick person will have >> manager to hack together some sort of dodgy code to simulate it if you >> look hard enough) >> >> > This http://entrian.com/goto/ has been around for almost 14 years. ok ill admit i didn't look at all (because goto is a silly idea & unnecessary) -- The sunlights differ, but there is only one darkness. -- Ursula K. LeGuin, "The Dispossessed" From nicco.9537 at gmail.com Fri Dec 29 05:46:05 2017 From: nicco.9537 at gmail.com (Nico Vogeli) Date: Fri, 29 Dec 2017 02:46:05 -0800 (PST) Subject: GUI user input to function In-Reply-To: References: <9238b7ff-e75a-47ab-8c2d-b1b82a1b38e3@googlegroups.com> Message-ID: <6a4e1922-4ecc-444c-a4df-7b235f415c1e@googlegroups.com> Am Donnerstag, 28. Dezember 2017 14:00:14 UTC+1 schrieb Chris Angelico: > On Thu, Dec 28, 2017 at 11:06 PM, Nico Vogeli wrote: > > Am Donnerstag, 28. Dezember 2017 12:59:24 UTC+1 schrieb Chris Angelico: > >> On Thu, Dec 28, 2017 at 8:38 PM, Nico Vogeli wrote: > >> > Withs test, this return a correct value for the two x functions: > >> > > >> > from sympy import symbols > >> > > >> > x = symbols('x') > >> > f1 = eval(input('function 1 ')) > >> > f2 = eval(input('function 2 ')) > >> > > >> > >> What are you typing as input? It's hard to grok your code without knowing that. > >> > >> ChrisA > > > > I'm sorry! User input would look like this for example: x**2 + 3*x or x**3 > > > > Cool. That's an expression, but it isn't a function. To make that into > a function, you need to prefix it with the lambda keyword. > > So you should be able to construct functions like this: > > f1 = eval("lambda x: " + input("function 1: ")) > > Then, when you type "x**3", Python evaluates "lambda x: x**3", which > is a function. > > ChrisA Thank you very much! It now works perfectly fine now!! Thank you! Nicco From skip.montanaro at gmail.com Fri Dec 29 10:58:32 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 29 Dec 2017 09:58:32 -0600 Subject: PyWin32 installer question In-Reply-To: References: Message-ID: > That's not an architecture-independent file. The Wheel spec gives all > the details, but "cp27" (as opposed to "py27") means it's CPython only > (which usually means it's got a C extension) and "win32" is 32-bit > only ("win_amd64" is the tag for 64-bit Windows). So the problem is > that the py2exe_py2 maintainer doesn't supply a 64-bit build. Thanks. I'll shoot Thomas Heller an email... S From skip.montanaro at gmail.com Fri Dec 29 11:04:30 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 29 Dec 2017 10:04:30 -0600 Subject: PyWin32 installer question In-Reply-To: References: Message-ID: > Thanks. I'll shoot Thomas Heller an email... Actually, make that Christopher Toth. Seems he's the current maintainer. From p.f.moore at gmail.com Fri Dec 29 11:38:32 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 29 Dec 2017 16:38:32 +0000 Subject: PyWin32 installer question In-Reply-To: References: Message-ID: On 29 December 2017 at 16:04, Skip Montanaro wrote: >> Thanks. I'll shoot Thomas Heller an email... > > > Actually, make that Christopher Toth. Seems he's the current maintainer. If you get no joy there, then in a week or two, when I next get access to a system with a Python 2.x build environment on it, I can see if I can do a 64-bit build for you. Ping me if that would be a help. Paul From bc at freeuk.com Fri Dec 29 12:13:02 2017 From: bc at freeuk.com (bartc) Date: Fri, 29 Dec 2017 17:13:02 +0000 Subject: Goto In-Reply-To: References: <7Mb1C.278680$gi3.141689@fx19.am4> Message-ID: On 29/12/2017 09:52, alister wrote: > On Thu, 28 Dec 2017 18:54:31 -0800, breamoreboy wrote: > >> On Thursday, December 28, 2017 at 7:40:14 PM UTC, alister wrote: >>> On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: >>> >>>> How to use goto in python? >>>> >>>> --- >>>> This email has been checked for viruses by AVG. >>>> http://www.avg.com >>> >>> Dont! >>> actually you cant - there isn't one* >>> >>> *at least not in the core language no doubt some sick person will have >>> manager to hack together some sort of dodgy code to simulate it if you >>> look hard enough) >>> >>> >> This http://entrian.com/goto/ has been around for almost 14 years. > > ok ill admit i didn't look at all (because goto is a silly idea & > unnecessary) If you want to translate code from one language to another, and the source language uses gotos, or uses control structures not available in the target language, then gotos would be very useful in the latter. (gotos are frowned upon because they make program flow harder to see within a normal structured program. However examples of 'advanced' Python I've seen are such that I would rather contend with a few gotos.) -- bartc From grant.b.edwards at gmail.com Fri Dec 29 12:40:58 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 29 Dec 2017 17:40:58 +0000 (UTC) Subject: Python goto References: <474715f5-dfcc-67b2-6a30-9b977882f5fe@nedbatchelder.com> Message-ID: On 2017-12-28, Skip Montanaro wrote: > Though it appears some wag has used function decorators to implement > goto statements: > > https://pypi.python.org/pypi/goto-statement/1.1 > > Rather clever, it seems. That's brilliant! Not that I'd look kindly on anybody who used it on project I ended up working on... -- Grant Edwards grant.b.edwards Yow! My Aunt MAUREEN was a at military advisor to IKE & gmail.com TINA TURNER!! From rosuav at gmail.com Fri Dec 29 13:11:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Dec 2017 05:11:16 +1100 Subject: Goto In-Reply-To: References: <7Mb1C.278680$gi3.141689@fx19.am4> Message-ID: On Sat, Dec 30, 2017 at 4:13 AM, bartc wrote: > If you want to translate code from one language to another, and the source > language uses gotos, or uses control structures not available in the target > language, then gotos would be very useful in the latter. > As has already been said in this thread, a competent FORTRAN programmer can write FORTRAN code in any language. But if you want to actually write Python code, instead of writing FORTRAN code that gets run through a Python interpreter, you have to grok the Python way of doing things. You can't do that by mechanically transforming source code into the syntax of a different language. People who try to tell you that all programming languages are identical, just with different syntax, are doing you a disservice. Lisp is not Python is not REXX is not C is not DeScribe Macro Language. (Especially the latter. Do NOT try to write C code in DML. It'll look ugly. Trust me.) ChrisA From someone at somewhere.invalid Fri Dec 29 13:55:36 2017 From: someone at somewhere.invalid (MarkA) Date: 29 Dec 2017 18:55:36 GMT Subject: Goto References: Message-ID: On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: > How to use goto in python? > > --- > This email has been checked for viruses by AVG. > http://www.avg.com Rather than ask how to use an unavailable statement (GOTO), why not investigate why no modern languages use it? -- MarkA You can safely assume that you have created God in your own image when it turns out that God hates all the same people you do. -- Anne Lamott From tjreedy at udel.edu Fri Dec 29 14:25:05 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Dec 2017 14:25:05 -0500 Subject: PyWin32 installer question In-Reply-To: References: Message-ID: On 12/29/2017 11:38 AM, Paul Moore wrote: > On 29 December 2017 at 16:04, Skip Montanaro wrote: >>> Thanks. I'll shoot Thomas Heller an email... >> >> >> Actually, make that Christopher Toth. Seems he's the current maintainer. > > If you get no joy there, then in a week or two, when I next get access > to a system with a Python 2.x build environment on it, I can see if I > can do a 64-bit build for you. Ping me if that would be a help. I have not followed this thread, but there may be no need to. https://www.lfd.uci.edu/~gohlke/pythonlibs/ Christopher Gohlke, at UC Irvine, provides Windows cpxx wheels for about 300 packages, for 2.7, 3.4, 3.5, 3.6, 3.7, in win32 and win_amd64 versions (as applicable). PyWin32-221 is included, with all combinations. -- Terry Jan Reedy From bc at freeuk.com Fri Dec 29 15:03:37 2017 From: bc at freeuk.com (bartc) Date: Fri, 29 Dec 2017 20:03:37 +0000 Subject: Goto In-Reply-To: References: Message-ID: On 29/12/2017 18:55, MarkA wrote: > On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: > >> How to use goto in python? >> >> --- >> This email has been checked for viruses by AVG. >> http://www.avg.com > > Rather than ask how to use an unavailable statement (GOTO), why not > investigate why no modern languages use it? Golang uses goto. Lua didn't have goto but then added it. PHP also added goto to a later version. That's the extent of my one minutes' research; I guess a few other newish languages might use it (plus any I create myself, and pile of older languages). Why most newer, higher level languages don't, I don't know. Perhaps because the people who design them want to make programming harder? Or they are adept at doing without it, and expect everyone else to be equally so? Nothing wrong with goto when you have a throwaway program to finish and an approaching deadline. Overuse of goto in real applications would be a problem, but that's the same with any feature. In Python, you can define F as function, but then reassign any other arbitrary value to F, at any point in a program, at any time, and as many times as you like. That makes goto seem almost benign! (Except that Python would probably let you assign to labels...) -- bartc From rosuav at gmail.com Fri Dec 29 15:25:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Dec 2017 07:25:20 +1100 Subject: Goto In-Reply-To: References: Message-ID: On Sat, Dec 30, 2017 at 7:03 AM, bartc wrote: > On 29/12/2017 18:55, MarkA wrote: >> >> On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: >> >>> How to use goto in python? >>> >>> --- >>> This email has been checked for viruses by AVG. >>> http://www.avg.com >> >> >> Rather than ask how to use an unavailable statement (GOTO), why not >> investigate why no modern languages use it? > > > Golang uses goto. > > Lua didn't have goto but then added it. > > PHP also added goto to a later version. Ahh, great choice of example. "It's okay - PHP does it." ChrisA From bc at freeuk.com Fri Dec 29 15:46:14 2017 From: bc at freeuk.com (bartc) Date: Fri, 29 Dec 2017 20:46:14 +0000 Subject: Goto In-Reply-To: References: Message-ID: On 29/12/2017 20:25, Chris Angelico wrote: > On Sat, Dec 30, 2017 at 7:03 AM, bartc wrote: >> On 29/12/2017 18:55, MarkA wrote: >>> >>> On Thu, 28 Dec 2017 00:58:48 -0200, Duram wrote: >>> >>>> How to use goto in python? >>>> >>>> --- >>>> This email has been checked for viruses by AVG. >>>> http://www.avg.com >>> >>> >>> Rather than ask how to use an unavailable statement (GOTO), why not >>> investigate why no modern languages use it? >> >> >> Golang uses goto. >> >> Lua didn't have goto but then added it. >> >> PHP also added goto to a later version. > > Ahh, great choice of example. "It's okay - PHP does it." I don't know PHP, but I guess it has all the usual features that people can use to eliminate goto (ie. the ability to add extra, more convoluted code). So presumably adding it had a net benefit. Notice I said Lua and Golang also have it. Adding it to a language doesn't mean people are obliged to use it. -- bartc From darcy at VybeNetworks.com Fri Dec 29 16:03:16 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 29 Dec 2017 15:03:16 -0600 Subject: Goto In-Reply-To: References: Message-ID: On 12/29/2017 02:25 PM, Chris Angelico wrote: >> PHP also added goto to a later version. > > Ahh, great choice of example. "It's okay - PHP does it." I thought that that was a reason to not do it. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From rosuav at gmail.com Fri Dec 29 16:18:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Dec 2017 08:18:02 +1100 Subject: Goto In-Reply-To: References: Message-ID: On Sat, Dec 30, 2017 at 8:03 AM, D'Arcy Cain wrote: > On 12/29/2017 02:25 PM, Chris Angelico wrote: >>> PHP also added goto to a later version. >> >> Ahh, great choice of example. "It's okay - PHP does it." > > I thought that that was a reason to not do it. Often, yeah. Hence my comment that "hey, PHP has goto" is an excellent choice of example. ChrisA From bc at freeuk.com Fri Dec 29 17:56:21 2017 From: bc at freeuk.com (bartc) Date: Fri, 29 Dec 2017 22:56:21 +0000 Subject: Goto In-Reply-To: References: Message-ID: <8Kz1C.110376$9X4.85635@fx02.am4> On 29/12/2017 21:56, Stefan Ram wrote: > Chris Angelico writes: >> On Sat, Dec 30, 2017 at 8:03 AM, D'Arcy Cain wrote: >>> On 12/29/2017 02:25 PM, Chris Angelico wrote: >>>>> PHP also added goto to a later version. >>>> Ahh, great choice of example. "It's okay - PHP does it." >>> I thought that that was a reason to not do it. >> Often, yeah. Hence my comment that "hey, PHP has goto" is an excellent >> choice of example. > > I already wrote this before, recently, in some newsgroup (here?): > > Knuth's algorithm's often use "goto"'s. When translating them into > another language, it is helpful to be able to translate them as > direct as possible. Having to change the algorithm in one's head > to avoid "goto" while converting it to Python seems to be a > source of errors. > > When a language has a "goto", one can then translate Knuth's > algorithms more literally. One then can add tests. And /then/ > one can refactor step-by-step to an algorithm without "goto". > That sort of argument will never wash here: "/I/ can write code without ever using 'goto'. So nobody else should ever need to use it either". Forget about automatic code translators, automatic parser generators, automatic state machine translators, plus a host of other uses which goto could simplify. From bc at freeuk.com Fri Dec 29 18:12:22 2017 From: bc at freeuk.com (bartc) Date: Fri, 29 Dec 2017 23:12:22 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: <9Zz1C.185732$oD1.1720@fx44.am4> On 29/12/2017 21:55, Lawrence D?Oliveiro wrote: > On Saturday, December 30, 2017 at 9:03:50 AM UTC+13, bartc wrote: >> Why most newer, higher level languages don't, I don't know. Perhaps >> because the people who design them want to make programming harder? > > I don?t use gotos in C code. Why should it be ?harder? in a higher-level language? > Good for you. Looking at 14 million lines of Linux kernel sources, which are in C, over 100,000 of them use 'goto'. About one every 120 lines. My own low level sources use about one goto every 400 lines. It's hardly a lot. If one is used, it's because it was handy to use it, until such time as it can be replaced with proper logic. But such logic will usually be more convoluted. BTW, looking at 220,000 lines of CPython sources, in C (an old distribution I had to hand), there are 2600 gotos, about one every 85 lines. And those are the ones are directly visible as gotos, and not hidden behind macros. I understand that on Linux, the CPython dispatcher makes use of label pointers, using 'goto *opcode_targets[*next_instr++]' to do a faster byte-code dispatch than using switch. You I guess would have written it without that, and we'd all have to suffer 10% slower speed (or whatever) for your principles. That's assuming you could have got rid of the other 2600 gotos as well. -- bartc From skip.montanaro at gmail.com Fri Dec 29 18:42:44 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 29 Dec 2017 17:42:44 -0600 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: Looking at 14 million lines of Linux kernel sources, which are in C, over 100,000 of them use 'goto'. About one every 120 lines. Isn't C's goto statement restricted to the current function? I imagine setjmp and longjmp calls might be more insidious. Skip From python at mrabarnett.plus.com Fri Dec 29 19:09:12 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 30 Dec 2017 00:09:12 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <9Zz1C.185732$oD1.1720@fx44.am4> References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: <3582fd31-5499-37ed-dca2-a4ea3a2a7cd1@mrabarnett.plus.com> On 2017-12-29 23:12, bartc wrote: > On 29/12/2017 21:55, Lawrence D?Oliveiro wrote: >> On Saturday, December 30, 2017 at 9:03:50 AM UTC+13, bartc wrote: >>> Why most newer, higher level languages don't, I don't know. Perhaps >>> because the people who design them want to make programming harder? >> >> I don?t use gotos in C code. Why should it be ?harder? in a higher-level language? >> > > Good for you. > > Looking at 14 million lines of Linux kernel sources, which are in C, > over 100,000 of them use 'goto'. About one every 120 lines. > > My own low level sources use about one goto every 400 lines. It's hardly > a lot. If one is used, it's because it was handy to use it, until such > time as it can be replaced with proper logic. But such logic will > usually be more convoluted. > > BTW, looking at 220,000 lines of CPython sources, in C (an old > distribution I had to hand), there are 2600 gotos, about one every 85 > lines. And those are the ones are directly visible as gotos, and not > hidden behind macros. > > I understand that on Linux, the CPython dispatcher makes use of label > pointers, using 'goto *opcode_targets[*next_instr++]' to do a faster > byte-code dispatch than using switch. > > You I guess would have written it without that, and we'd all have to > suffer 10% slower speed (or whatever) for your principles. That's > assuming you could have got rid of the other 2600 gotos as well. > I too use goto in C code, principally to go to clean-up code after checking the result of a call. In Python, on the other hand, I have automatic garbage collection, exceptions, etc. It's OK for code that's close to the metal, but in high-level code? No. Python has managed for >25 years without it, and I've yet to see a convincing use-case. From tkadm30 at yandex.com Fri Dec 29 20:00:54 2017 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 29 Dec 2017 20:00:54 -0500 Subject: How to create a python extension module from a shared library? Message-ID: Hi all, I would like to extend uWSGI by creating a CPython extension module for the libuwsgi.so shared library included in the distribution. My goal is to use this automatically generated CPython module for extending uWSGI. I have summarized my current approach here: https://mail.python.org/pipermail/tutor/2017-December/112475.html So far, I have tried to use CFFI and pycparser to generate the Python bindings, however CFFI and pycparser doesn't handle C directives like #include and #define. I also attempted using clang to preprocess the "uwsgi.h" header found in the uWSGI distro with pycparser.parse_file() to generate a AST, however the generated AST object seems incorrect. Is there any way to reflect a shared library into a CPython module? I know that using "nm -D libuwsgi.so" I can get a list of available functions for this module. However, I have very little experience with ctypes and CFFI. Do I need to modify CFFI to allow it to parse a C header with libclang? I'm guessing CFFI/clang or ctypes should allow me to reflect the shared library, but I'm not sure about which method is the most appropriate. What do you think? Sincerely, Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From mikhailwas at gmail.com Fri Dec 29 20:02:08 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 30 Dec 2017 02:02:08 +0100 Subject: Goto Message-ID: MRAB wrote: > It's OK for code that's close to the metal, but in high-level code? No. > Python has managed for >25 years without it, and I've yet to see a > convincing use-case. "convincing" is a broad term I think, especially for syntax proposals ;) I think often one wish to use it just to avoid "if" blocks in obvious situations - no need to setup flags and indent/unindent code blocks. Apart from that, I personally would prefer it in such typical code: if a : a() goto "end" if b : b() goto "end" if c : c() goto "end" "end" I know I can do it with "elif", but "elif" is just not my cup of tea. For this case goto provides symmetrical and explicit look, which I value a lot. Mikhail From rustompmody at gmail.com Fri Dec 29 23:15:01 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 29 Dec 2017 20:15:01 -0800 (PST) Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: On Saturday, December 30, 2017 at 8:35:27 AM UTC+5:30, Lawrence D?Oliveiro wrote: > On Saturday, December 30, 2017 at 12:12:23 PM UTC+13, bartc wrote: > > Looking at 14 million lines of Linux kernel sources, which are in C, > > over 100,000 of them use 'goto'. About one every 120 lines. > > That kind of thing leads to spaghetti code. > > Here is an example I like to bring up: writing a Python extension module in C. As you know, this requires a lot of careful memory management to cope with errors and avoid either memory leaks or double-frees. The coding convention I came up with looks like this: > > ... initialize pointers to allocated storage to NULL ... > do /*once*/ > { > ... processing ... > allocate some storage; > if (error) > break; > ... more processing ... > allocate more storage; > if (error) > break; > ... even more processing ... > } > while (false); > ... free allocated storage ... > > Basically, it becomes possible to satisfy yourself, by inspection, that every possible control path through the above code will pass once, and only once, through the storage deallocation. > > Things get slightly more complicated where allocation has to happen in a loop. Actually, that?s where the interesting cases happen. My technique can be adapted to cope elegantly with this, too--see the code. Bizarre how religions proliferate? I wonder how many people who quote Dijkstra have read "goto statement considered harmful". And that short letter was negative, aka "Don?t use goto!? The more positive answer to the question: ?Ok so then how to program?? was "Structured Programming" I am ready to bet that an even tinier percentage has ever seen that tome And if one really got the gist of structuredness: mapping an automaton with state = label transition = goto is really the most clean structured mapping One can do almost as well with a switch and (case) labels You can make a virtue of the fact that python has neither I call it blind religious genuflecting BTW there can be quite good reasons for not putting? goto into a language especially interpreted ones is that gotos tend to make semantics non compositional: ie Say S? S? are two statements in the source language composed together into a larger source statement S? ? S? which translates into T? ? T? Egs of S? ? S? could be ifthenelse sequencing etc T? ? T? could be assembly code for S? followed by code for S? (for a compiler) Or action of S? followed by action of S? (for interpreter) Now if S? , S? has gotos jumping into each other this "homomorphic tree transforming model" becomes messed up However in the face of exceptions? that are quite close to gotos I dont think this logic would apply Finally I would like to quote my teacher of programming who made a statement that altered my next 30 years of programming life: ?What the goto does to control structure, the assignment does to data structure? ? The most important decisions for a language designer are what to leave out ? Nicklaus Wirth ? The original objectives of the language (Ada) included reliability, readability of programs, formality of language definition, and even simplicity. Gradually these objectives have been sacrificed in favor of power, supposedly achieved by a plethora of features and notational conventions, many of them unnecessary and some of them, like exception handling, even dangerous C.A.R. Hoare Turing lecture: https://amturing.acm.org/award_winners/hoare_4622167.cfm From hjp-python at hjp.at Sat Dec 30 07:46:14 2017 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 30 Dec 2017 13:46:14 +0100 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: <20171230124614.kv32v54rkg3yv5gz@hjp.at> On 2017-12-29 19:09:35 -0500, Dennis Lee Bieber wrote: > On Fri, 29 Dec 2017 23:12:22 +0000, bartc declaimed the > following: > >Looking at 14 million lines of Linux kernel sources, which are in C, > >over 100,000 of them use 'goto'. About one every 120 lines. > > > > C is a language that predates the "structured programming" concepts of > the late 70/early 80. I don't think this is correct. Structured programming is much older: ALGOL 60 was already a block structured language and Dijkstra wrote "goto considered harmful" in the late 1960s. Pascal appeared in 1970, C in 1974. To me (who learned to program in BASIC on a CP/M machine), C is very much a structured programming language. If structured programming gained traction around 1980, it might even have been because structured languages like C with good performance became widely available. That said, C lacks exception handling (well, there is setjmp/longjmp, but ...) and multi-level break/continue, so goto is often the cleanest way to abort what you are doing and start to clean up. Python has exception handling, and that removes most of the cases where you would use goto in C (the rest is probably mostly in micro-optimizations: If you care about the run-time difference between a goto and a subroutine call, you probably shouldn't use Python in the first place). hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From bc at freeuk.com Sat Dec 30 09:41:09 2017 From: bc at freeuk.com (bartc) Date: Sat, 30 Dec 2017 14:41:09 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: On 30/12/2017 03:05, Lawrence D?Oliveiro wrote: > On Saturday, December 30, 2017 at 12:12:23 PM UTC+13, bartc wrote: >> Looking at 14 million lines of Linux kernel sources, which are in C, >> over 100,000 of them use 'goto'. About one every 120 lines. > > That kind of thing leads to spaghetti code. > > Here is an example I like to bring up: writing a Python extension module in C. As you know, this requires a lot of careful memory management to cope with errors and avoid either memory leaks or double-frees. The coding convention I came up with looks like this: > > ... initialize pointers to allocated storage to NULL ... > do /*once*/ > { > ... processing ... > allocate some storage; > if (error) > break; > ... more processing ... > allocate more storage; > if (error) > break; > ... even more processing ... > } > while (false); > ... free allocated storage ... > > Basically, it becomes possible to satisfy yourself, by inspection, that every possible control path through the above code will pass once, and only once, through the storage deallocation. > > Things get slightly more complicated where allocation has to happen in a loop. Actually, that?s where the interesting cases happen. My technique can be adapted to cope elegantly with this, too--see the code. > I tend to use goto to share small sequences of code: if cond1: A B elif cond2: C elif cond3: D B elif cond4: C ... Here, A, B, C, D represent small blocks of code. The conditions have to be tested in this order. B and C occur twice, so a goto is a quick way to reuse B and C without needing to duplicate code, or go through the upheaval of extracting them to functions. (And then the code develops so that the two Bs /are/ different, and then you have to get rid of the function. Or the second C was temporary anyway.) Any other way of doing it will obfuscate the structure: if cond1: A elif cond2 or (not cond3 and cond4): C elif cond3: D if cond1 or (not cond2 and cond3): B I can no longer be sure if this right. Plus executing A, C, D can change the conditions if they are tested again. (I had introduced a special language feature just for this kind of thing, but it was unsatisfactory. Goto was simpler and understood by everyone. And portable to any other language - that hasn't done away with goto. But it worked like this (not Python): a:=20 case a when 10 then fred:: println "one" when 20 then @fred println "two" end Output is "one" "two" when a is 20. fred:: names a block, and @fred 'calls' that block, without having to move it out of context. Actually this goes beyond what 'goto' can do, as it can also 'come back'. But as you can see, it looks a bit naff. A bit 1970s.) -- bartc From ranyafafi93 at gmail.com Sat Dec 30 11:26:25 2017 From: ranyafafi93 at gmail.com (Ranya) Date: Sat, 30 Dec 2017 17:26:25 +0100 Subject: CFG Python Message-ID: Let's say I vreated my own CFG in python, How can I check now if a sentence match this grammar (return true) or it doesn't match it (return false and the wrong element in the grammar), How can I do this ? From none at invalid.com Sat Dec 30 11:53:12 2017 From: none at invalid.com (mm0fmf) Date: Sat, 30 Dec 2017 16:53:12 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: On 30/12/2017 14:41, bartc wrote: > it looks a bit naff Understatement of 2017. From bc at freeuk.com Sat Dec 30 13:21:00 2017 From: bc at freeuk.com (bartc) Date: Sat, 30 Dec 2017 18:21:00 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: On 30/12/2017 16:53, mm0fmf wrote: > On 30/12/2017 14:41, bartc wrote: >> it looks a bit naff > > Understatement of 2017. I'm honest about my own ideas, but my remarks were about the use of special symbols such as "::" and "@". Before completely dismissing it however, you should look at how another language such as Python can achieve the same thing. Namely, take any block of code within a function, and allow it to be executed or shared from anywhere else in the function, with the minimum of disruption. If it looks better than what I'd come up with, then I'll use that instead. -- bartc From python at mrabarnett.plus.com Sat Dec 30 14:10:36 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 30 Dec 2017 19:10:36 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: <91306abc-55ea-bd82-4c2d-b9a2e80e2e5c@mrabarnett.plus.com> On 2017-12-30 18:21, bartc wrote: > On 30/12/2017 16:53, mm0fmf wrote: >> On 30/12/2017 14:41, bartc wrote: >>> it looks a bit naff >> >> Understatement of 2017. > > I'm honest about my own ideas, but my remarks were about the use of > special symbols such as "::" and "@". > > Before completely dismissing it however, you should look at how another > language such as Python can achieve the same thing. > > Namely, take any block of code within a function, and allow it to be > executed or shared from anywhere else in the function, with the minimum > of disruption. > > If it looks better than what I'd come up with, then I'll use that instead. > Perhaps what you want is something closer to a local named subroutine that can directly access the local variables. From ian.g.kelly at gmail.com Sat Dec 30 15:00:13 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 30 Dec 2017 14:00:13 -0600 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: On Sat, Dec 30, 2017 at 8:41 AM, bartc wrote: > (I had introduced a special language feature just for this kind of thing, > but it was unsatisfactory. Goto was simpler and understood by everyone. And > portable to any other language - that hasn't done away with goto. But it > worked like this (not Python): > > a:=20 > > case a > when 10 then > fred:: > println "one" > > when 20 then > @fred > println "two" > > end > > Output is "one" "two" when a is 20. > > fred:: names a block, and @fred 'calls' that block, without having to move > it out of context. Actually this goes beyond what 'goto' can do, as it can > also 'come back'. But as you can see, it looks a bit naff. A bit 1970s.) BASIC had this feature in the form of the GOSUB statement. Although it used an explicit rather than implicit RETURN. BASIC was an awful language for developing programs of any size, though. Without actual subroutines and with only one variable scope, most people developed the practice of using GOSUB and designating specific global variables as pseudo-arguments in order to have some limited form of parameter passing. That was the kind of environment where GOTO really, really sucks and produces the monstrous spaghetti code that gives it its bad reputation. With the restrictions of languages like C (i.e. only allowing GOTO within a function) and with a reasonable level of restraint, I don't think that the use of GOTO is really that big of a deal. From __peter__ at web.de Sat Dec 30 15:06:59 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 30 Dec 2017 21:06:59 +0100 Subject: CFG Python References: Message-ID: Ranya wrote: > Let's say I vreated my own CFG in python, How can I check now if a > sentence match this grammar (return true) or it doesn't match it (return > false and the wrong element in the grammar), How can I do this ? Remember, context free grammars may be fine, but context free questions aren't ;) Is this question nltk-related? If so, here's one way (using a grammar found at http://www.nltk.org/book/ch08.html): >>> import nltk >>> grammar = nltk.CFG.fromstring(""" ... S -> NP VP ... VP -> V NP | V NP PP ... PP -> P NP ... V -> "saw" | "ate" | "walked" ... NP -> "John" | "Mary" | "Bob" | Det N | Det N PP ... Det -> "a" | "an" | "the" | "my" ... N -> "man" | "dog" | "cat" | "telescope" | "park" ... P -> "in" | "on" | "by" | "with" ... """) >>> parser = nltk.RecursiveDescentParser(grammar) >>> def check(sentence, parser=parser): ... return parser.parse_one(sentence) is not None ... >>> check("Mary saw the telescope".split()) True >>> check("Mary saw the saw".split()) False >>> check("Mary saw the chicken".split()) Traceback (most recent call last): [...] ValueError: Grammar does not cover some of the input words: "'chicken'". From ben+python at benfinney.id.au Sat Dec 30 15:13:13 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 31 Dec 2017 07:13:13 +1100 Subject: CFG Python References: Message-ID: <85vagokm92.fsf@benfinney.id.au> Peter Otten <__peter__ at web.de> writes: > > Let's say I vreated my own CFG in python, How can I [?] > > Remember, context free grammars may be fine, but context free > questions aren't ;) +1 QotW -- \ ?The problem with television is that the people must sit and | `\ keep their eyes glued on a screen: the average American family | _o__) hasn't time for it.? ?_The New York Times_, 1939 | Ben Finney From wrw at mac.com Sat Dec 30 15:15:07 2017 From: wrw at mac.com (William Ray Wing) Date: Sat, 30 Dec 2017 15:15:07 -0500 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <20171230124614.kv32v54rkg3yv5gz@hjp.at> References: <9Zz1C.185732$oD1.1720@fx44.am4> <20171230124614.kv32v54rkg3yv5gz@hjp.at> Message-ID: <09BC94E9-D180-4F4F-8A46-946857769609@mac.com> > On Dec 30, 2017, at 7:46 AM, Peter J. Holzer wrote: > > On 2017-12-29 19:09:35 -0500, Dennis Lee Bieber wrote: >> On Fri, 29 Dec 2017 23:12:22 +0000, bartc declaimed the >> following: >>> Looking at 14 million lines of Linux kernel sources, which are in C, >>> over 100,000 of them use 'goto'. About one every 120 lines. >>> >> >> C is a language that predates the "structured programming" concepts of >> the late 70/early 80. > > I don't think this is correct. Structured programming is much older: > ALGOL 60 was already a block structured language and Dijkstra wrote > "goto considered harmful" in the late 1960s. Pascal appeared in 1970, C > in 1974. To me (who learned to program in BASIC on a CP/M machine), C > is very much a structured programming language. If structured > programming gained traction around 1980, it might even have been because > structured languages like C with good performance became widely > available. > > That said, C lacks exception handling (well, there is setjmp/longjmp, > but ...) and multi-level break/continue, so goto is often the cleanest > way to abort what you are doing and start to clean up. Python has > exception handling, and that removes most of the cases where you would > use goto in C (the rest is probably mostly in micro-optimizations: If > you care about the run-time difference between a goto and a subroutine > call, you probably shouldn't use Python in the first place). > > hp > I?ve been watching this discussion ebb and flow - and finally can?t resist pointing folks here at the famous essay: ?Real Programmers Don?t Use Pascal?. It has its own Wikipedia article at this point: https://en.wikipedia.org/wiki/Real_Programmers_Don't_Use_Pascal A copy of the original essay appears here: https://www.ee.ryerson.ca/~elf/hack/realmen.html Hopefully fun reading over a beer. Bill From ben.usenet at bsb.me.uk Sat Dec 30 15:36:18 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sat, 30 Dec 2017 20:36:18 +0000 Subject: Goto (Posting On Python-List Prohibited) References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: <877et47y2l.fsf@bsb.me.uk> bartc writes: > On 30/12/2017 16:53, mm0fmf wrote: >> On 30/12/2017 14:41, bartc wrote: >>> it looks a bit naff >> >> Understatement of 2017. > > I'm honest about my own ideas, but my remarks were about the use of > special symbols such as "::" and "@". > > Before completely dismissing it however, you should look at how > another language such as Python can achieve the same thing. > > Namely, take any block of code within a function, and allow it to be > executed or shared from anywhere else in the function, with the > minimum of disruption. That's what a local function does and it does it with the clean semantics of a function call. When this idea came up in comp.lang.c you could not see the point, yet you appear to have a use-case common enough that you have a solution worked out using gotos. > If it looks better than what I'd come up with, then I'll use that instead. What looks better is always going to be an unreliable and subjective measure, but calling a named function almost certainly scales better and will allow for better structuring (such as when one block needs to use another one). -- Ben. From rosuav at gmail.com Sat Dec 30 15:49:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Dec 2017 07:49:29 +1100 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <877et47y2l.fsf@bsb.me.uk> References: <9Zz1C.185732$oD1.1720@fx44.am4> <877et47y2l.fsf@bsb.me.uk> Message-ID: On Sun, Dec 31, 2017 at 7:36 AM, Ben Bacarisse wrote: > bartc writes: > >> On 30/12/2017 16:53, mm0fmf wrote: >>> On 30/12/2017 14:41, bartc wrote: >>>> it looks a bit naff >>> >>> Understatement of 2017. >> >> I'm honest about my own ideas, but my remarks were about the use of >> special symbols such as "::" and "@". >> >> Before completely dismissing it however, you should look at how >> another language such as Python can achieve the same thing. >> >> Namely, take any block of code within a function, and allow it to be >> executed or shared from anywhere else in the function, with the >> minimum of disruption. > > That's what a local function does and it does it with the clean > semantics of a function call. > The only downside that I can think of is performance - function calls can be a bit heavy-weight. I'd be curious to see what a "lightweight local function" would look like - it could have restrictive semantics like "can only be called from the function that constructed it" and then could behave like Bart's proposed "block of code". But I suspect it wouldn't have all that many uses, compared to a *real* closure, which can be passed around as its own entity. ChrisA From news at luegenpresse.edu Sat Dec 30 17:02:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sat, 30 Dec 2017 22:02:00 +0000 Subject: a nice editor in 100 lines Message-ID: class writerKl(object): def __init__(self): import tkinter from tkinter import messagebox from tkinter import filedialog from tkinter import Tk from tkinter import Menu from tkinter import END self.fileName = None self.saved = True self.app = tkinter.Tk() self.app.title("FenInst is another instance of the writerKl class") self.menuBar = tkinter.Menu(self.app) self.fileMenu = tkinter.Menu(self.menuBar, tearoff=0) self.fileMenu.add_command(label="New", command=self.newFile) self.fileMenu.add_command(label="Open", command=self.openFile) self.fileMenu.add_command(label="Save", command=self.saveFile) self.fileMenu.add_command(label="Save As", command=self.saveFileAs) self.fileMenu.add_separator() ; self.About = "A selfish tkinter text editor in 100 lines of python3 code.\n\n In fact this very ''About window'' also was modded using the selfish editor himself.\n\n Open the source ''writer.py'' to find out why this editor is seen as so 105x self-obsessed." self.fileMenu.add_command(label= "About", command=lambda: tkinter.messagebox.showinfo("About", self.About)) self.fileMenu.add_separator() self.fileMenu.add_command(label="Exit", command=self.onExit) self.menuBar.add_cascade( label="File", menu =self.fileMenu) self.app.config(menu=self.menuBar) self.app.bind('', self.newFile ) # key Bindings self.app.bind('', self.openFile) self.app.bind('', self.saveFile) self.app.bind('', self.setsavedFalse ) self.app.protocol("WM_DELETE_WINDOW", self.onExit) # save before exit? self.textf = tkinter.Text(self.app) # initializing text container self.textf.pack(expand=True, fill='both') # deploying text container self.textf.focus() self.app.mainloop() def newFile(self): import tkinter if not self.saved: save = self.promptToSave() if save: self.saveFile() elif self.save is None: return self.fileName = None self.textf.delete(0.0, tkinter.END) self.saved = True def openFile(self): import tkinter if not self.saved: self.save = self.promptToSave() if self.save: self.saveFile() elif self.save is None: return try: self.f = tkinter.filedialog.askopenfile( filetypes=[ ('all files', '*') , ('py files', '.py') ] ) if self.f: self.fileName = self.f.name self.t = self.f.read() self.textf.delete(0.0, tkinter.END) self.textf.insert(tkinter.END, self.t) self.saved = True except: tkinter.messagebox.showerror("Error", "Unable to open file.") def saveFile(self): import tkinter self.t = self.textf.get(0.0, tkinter.END) if self.fileName: self.f = open(self.fileName, "w") self.f.write(self.t) self.f.close() self.saved = True else: self.saveFileAs() def saveFileAs(self): import tkinter self.f = tkinter.filedialog.asksaveasfile(defaultextension=".txt", filetypes=[ ('all files', '*'),('py files', '.py') ]) self.t = self.textf.get(0.0, tkinter.END) if self.f: try: self.f.write(self.t) self.f.close( ) self.saved = True self.fileName=self.f.name except: tkinter.messagebox.showwarning("Error", "Unable to save file.") def onExit(self): import tkinter if not self.saved: self.save = self.promptToSave() if self.save: self.saveFile() elif self.save is None: return self.app.destroy() def setsavedFalse(self, key): import tkinter if (key.keysym.isalpha() or key.keysym.isdigit() or key.keysym in ["Return", "Tab", "Backspace", "Delete"]): self.saved = False # any key that changes text def promptToSave(self): import tkinter return tkinter.messagebox.askyesnocancel( "Save file?", "Do you want to save the current file?") if __name__ == '__main__' : import tkinter FenInst =writerKl() From news at luegenpresse.edu Sat Dec 30 17:03:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sat, 30 Dec 2017 22:03:00 +0000 Subject: Anaconda Navigator : Add App References: Message-ID: that is a very slow manager. too slow. From news at luegenpresse.edu Sat Dec 30 17:33:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sat, 30 Dec 2017 22:33:00 +0000 Subject: Tkinter,show pictures from the list of files in catalog-problem References: Message-ID: nothing works in ure soft everything breaks From bc at freeuk.com Sat Dec 30 17:43:36 2017 From: bc at freeuk.com (bartc) Date: Sat, 30 Dec 2017 22:43:36 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <877et47y2l.fsf@bsb.me.uk> References: <9Zz1C.185732$oD1.1720@fx44.am4> <877et47y2l.fsf@bsb.me.uk> Message-ID: <9EU1C.148541$6P.29172@fx13.am4> On 30/12/2017 20:36, Ben Bacarisse wrote: > bartc writes: > >> On 30/12/2017 16:53, mm0fmf wrote: >>> On 30/12/2017 14:41, bartc wrote: >>>> it looks a bit naff >>> >>> Understatement of 2017. >> >> I'm honest about my own ideas, but my remarks were about the use of >> special symbols such as "::" and "@". >> >> Before completely dismissing it however, you should look at how >> another language such as Python can achieve the same thing. >> >> Namely, take any block of code within a function, and allow it to be >> executed or shared from anywhere else in the function, with the >> minimum of disruption. > > That's what a local function does and it does it with the clean > semantics of a function call. > > When this idea came up in comp.lang.c you could not see the point, yet > you appear to have a use-case common enough that you have a solution > worked out using gotos. C doesn't in general have local functions. My own languages don't implement them properly. So I tend not to use them. >> If it looks better than what I'd come up with, then I'll use that instead. > > What looks better is always going to be an unreliable and subjective > measure, but calling a named function almost certainly scales better and > will allow for better structuring (such as when one block needs to use > another one). Using a local (or even non-local) function is what I'm trying to avoid, as I prefer to keep the code inline, and not disrupt it too much. You may also want to execute a block only temporarily, or as part of a short test. So you don't want to go to the trouble of hoisting a block of code into a local function. (And in C, which has local block scopes, there would be trouble with visibility of all the variables the block uses, unless the local function is untidily placed right where the original block was.) -- bartc From rosuav at gmail.com Sat Dec 30 18:14:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Dec 2017 10:14:11 +1100 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <9EU1C.148541$6P.29172@fx13.am4> References: <9Zz1C.185732$oD1.1720@fx44.am4> <877et47y2l.fsf@bsb.me.uk> <9EU1C.148541$6P.29172@fx13.am4> Message-ID: On Sun, Dec 31, 2017 at 9:43 AM, bartc wrote: > On 30/12/2017 20:36, Ben Bacarisse wrote: >> >> bartc writes: >> >>> On 30/12/2017 16:53, mm0fmf wrote: >>>> >>>> On 30/12/2017 14:41, bartc wrote: >>>>> >>>>> it looks a bit naff >>>> >>>> >>>> Understatement of 2017. >>> >>> >>> I'm honest about my own ideas, but my remarks were about the use of >>> special symbols such as "::" and "@". >>> >>> Before completely dismissing it however, you should look at how >>> another language such as Python can achieve the same thing. >>> >>> Namely, take any block of code within a function, and allow it to be >>> executed or shared from anywhere else in the function, with the >>> minimum of disruption. >> >> >> That's what a local function does and it does it with the clean >> semantics of a function call. >> >> When this idea came up in comp.lang.c you could not see the point, yet >> you appear to have a use-case common enough that you have a solution >> worked out using gotos. > > > C doesn't in general have local functions. My own languages don't implement > them properly. So I tend not to use them. > >>> If it looks better than what I'd come up with, then I'll use that >>> instead. >> >> >> What looks better is always going to be an unreliable and subjective >> measure, but calling a named function almost certainly scales better and >> will allow for better structuring (such as when one block needs to use >> another one). > > > Using a local (or even non-local) function is what I'm trying to avoid, as I > prefer to keep the code inline, and not disrupt it too much. > > You may also want to execute a block only temporarily, or as part of a short > test. So you don't want to go to the trouble of hoisting a block of code > into a local function. > > (And in C, which has local block scopes, there would be trouble with > visibility of all the variables the block uses, unless the local function is > untidily placed right where the original block was.) > Okay, so a low level language lacks certain facilities. Great. What has this to do with Python and goto? You *can* use nested functions. And they can do everything you need of these sub-blocks (albeit with some overhead). ChrisA From greg.ewing at canterbury.ac.nz Sat Dec 30 18:22:11 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 31 Dec 2017 12:22:11 +1300 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <9EU1C.148541$6P.29172@fx13.am4> References: <9Zz1C.185732$oD1.1720@fx44.am4> <877et47y2l.fsf@bsb.me.uk> <9EU1C.148541$6P.29172@fx13.am4> Message-ID: bartc wrote: > C doesn't in general have local functions. My own languages don't > implement them properly. So I tend not to use them. Looks like there's something circular going on here. You don't have much experience of using local functions, so you don't see a lot of value in them, so you haven't made the effort to implement them in your own languages, so you don't get much experience in using them. -- Greg From greg.ewing at canterbury.ac.nz Sat Dec 30 18:22:14 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 31 Dec 2017 12:22:14 +1300 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: Stefan Ram wrote: > BASIC has > > DEF FN... > > which /can/ define actual subroutines, limited to expressions. > > Now, what does this limitation remind me of? The equivalent limitation in Python is nowhere near as bad, since if you outgrow what lambda can do you can always use a def instead. BASIC didn't have that option (unless you were using one of the more advanced dialects, such as BBC BASIC, which had a PROC statement). -- Greg From greg.ewing at canterbury.ac.nz Sat Dec 30 18:26:28 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 31 Dec 2017 12:26:28 +1300 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: bartc wrote: > B and C occur twice, so a goto is a quick way to reuse B and C without > needing to duplicate code, This only works if the repeated part happens to be at the tail of each case. Any other situation and you're back to local functions. -- Greg From bc at freeuk.com Sat Dec 30 18:45:28 2017 From: bc at freeuk.com (bartc) Date: Sat, 30 Dec 2017 23:45:28 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: <8yV1C.295429$3J3.166915@fx37.am4> On 30/12/2017 23:26, Gregory Ewing wrote: > bartc wrote: >> B and C occur twice, so a goto is a quick way to reuse B and C without >> needing to duplicate code, > > This only works if the repeated part happens to be at the > tail of each case. IME that seems to be the most common situation. Any other situation and you're back to > local functions. -- Bartc From news at luegenpresse.edu Sat Dec 30 18:47:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sat, 30 Dec 2017 23:47:00 +0000 Subject: Python: asyncio and Tkinter References: <3z1ZG23Kc6z9rxF@submission02.posteo.de> <3z25rn0KgXz9rxP@submission02.posteo.de> Message-ID: this is kinda interesting. seems there is no easy way though From rosuav at gmail.com Sat Dec 30 18:54:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Dec 2017 10:54:36 +1100 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <8yV1C.295429$3J3.166915@fx37.am4> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> Message-ID: On Sun, Dec 31, 2017 at 10:45 AM, bartc wrote: > On 30/12/2017 23:26, Gregory Ewing wrote: >> >> bartc wrote: >>> >>> B and C occur twice, so a goto is a quick way to reuse B and C without >>> needing to duplicate code, >> >> >> This only works if the repeated part happens to be at the >> tail of each case. > > > IME that seems to be the most common situation. > I've written code that uses dirty tricks like that to avoid duplication. It's at least as much of a problem as actual duplication is. Generally, the 'goto' solution results in subsequent programmers (such as my future selves) staring at the code for 30-60 seconds to figure out what it's doing. I don't like to do that to myself, much less to people I actually admire and respect. ChrisA From python at mrabarnett.plus.com Sat Dec 30 19:11:03 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 31 Dec 2017 00:11:03 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> Message-ID: On 2017-12-30 23:22, Gregory Ewing wrote: > Stefan Ram wrote: >> BASIC has >> >> DEF FN... >> >> which /can/ define actual subroutines, limited to expressions. >> >> Now, what does this limitation remind me of? > > The equivalent limitation in Python is nowhere near as bad, > since if you outgrow what lambda can do you can always > use a def instead. BASIC didn't have that option (unless > you were using one of the more advanced dialects, such > as BBC BASIC, which had a PROC statement). > PROC wasn't really a statement, but a prefix for a procedure name. There was also another prefix, FN, for functions. DEF PROChello print "Hello world!" ENDPROC DEF FNsquare(x) = x * x They even had LOCAL variables and parameter lists. The Acorn Archimedes range had an improved version of BBC BASIC. From news at luegenpresse.edu Sat Dec 30 19:57:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 00:57:00 +0000 Subject: tkinter MP working like a charm Message-ID: from tkinter import * # I cant see anything wrong with this , it works like a charm from tkinter import messagebox # is there a serious concern doing things his way ? import asyncio , threading , random # goal is multi tasking with the GUI not freezing before loop completed # which is being achieved here ! def _asyncio_thread(async_loop): async_loop.run_until_complete(do_urls()) def do_work(async_loop): """ Button-Event-Handler starting stuff """ threading.Thread(target=_asyncio_thread, args=(async_loop,)).start() async def one_url(url): """ One task. """ sec = random.randint(1, 8) await asyncio.sleep(sec ) return 'url: {} --- sec: {}'.format(url, sec) async def do_urls(): """ Creating and starting 10 tasks. """ tasks = [one_url(url) for url in range(10)] completed, pending = await asyncio.wait(tasks) results = [task.result() for task in completed] print('\n'.join(results)) def do_nofreeze(): messagebox.showinfo(message='see, Tkinter is still responsive') def submain(async_loop): root = Tk() b1 = Button(master=root, text='do work', command= lambda:do_work( async_loop)).pack() b2 = Button(master=root, text='Frozen?', command=do_nofreeze ).pack() root.mainloop() if __name__ == '__main__': async_loop = asyncio.get_event_loop() # all in this loop submain(async_loop) From ben.usenet at bsb.me.uk Sat Dec 30 21:52:30 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 31 Dec 2017 02:52:30 +0000 Subject: Goto (Posting On Python-List Prohibited) References: <9Zz1C.185732$oD1.1720@fx44.am4> <877et47y2l.fsf@bsb.me.uk> <9EU1C.148541$6P.29172@fx13.am4> Message-ID: <87incnd2xd.fsf@bsb.me.uk> bartc writes: > On 30/12/2017 20:36, Ben Bacarisse wrote: >> bartc writes: >> >>> On 30/12/2017 16:53, mm0fmf wrote: >>>> On 30/12/2017 14:41, bartc wrote: >>>>> it looks a bit naff >>>> >>>> Understatement of 2017. >>> >>> I'm honest about my own ideas, but my remarks were about the use of >>> special symbols such as "::" and "@". >>> >>> Before completely dismissing it however, you should look at how >>> another language such as Python can achieve the same thing. >>> >>> Namely, take any block of code within a function, and allow it to be >>> executed or shared from anywhere else in the function, with the >>> minimum of disruption. >> >> That's what a local function does and it does it with the clean >> semantics of a function call. >> >> When this idea came up in comp.lang.c you could not see the point, yet >> you appear to have a use-case common enough that you have a solution >> worked out using gotos. > > C doesn't in general have local functions. My own languages don't > implement them properly. So I tend not to use them. But now you have good reason to change that. Properly implemented they do exactly what you want very neatly. You can stick with gotos, of course, but at least I hope you won't pour scorn on the idea of local function if it comes up again. >>> If it looks better than what I'd come up with, then I'll use that instead. >> >> What looks better is always going to be an unreliable and subjective >> measure, but calling a named function almost certainly scales better and >> will allow for better structuring (such as when one block needs to use >> another one). > > Using a local (or even non-local) function is what I'm trying to > avoid, as I prefer to keep the code inline, and not disrupt it too > much. That's what used to be called hacking. You write it one way and then spot that that block over there can be used here, but you don't tidy up the code, you just jump to it! In general, it is exactly the sort of goto use that gave gotos a bad name. Anyway, by their very nature, the blocks you are talking about should not be inline since they don't belong to any one execution path. (I hope you don't mind this annotation -- over at comp.lang.c I just remove text from my replies to you as is your preference, but people here will not have seen that exchange and I prefer to mark edits.) -- Ben. From jfong at ms4.hinet.net Sat Dec 30 23:57:05 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 30 Dec 2017 20:57:05 -0800 (PST) Subject: How to exec a string which has an embedded '\n'? Message-ID: I have a multiline string, something like '''...\nf.write('\n')\n...''' when pass to exec(), I got SyntaxError: EOL while scanning string literal How to get rid of it? Best Regards, Jach Fong From arj.python at gmail.com Sun Dec 31 00:02:18 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 31 Dec 2017 09:02:18 +0400 Subject: tkinter MP working like a charm In-Reply-To: References: Message-ID: for beginners import * is probably fine. Even if you are using most modules then too. else if module small maybe ok too just when you import just what you need, you save on resources . Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 31 Dec 2017 05:00, "Wu Xi" wrote: > from tkinter import * # I cant see > anything wrong with this , it works like a charm > from tkinter import messagebox # is there a > serious concern doing things his way ? > import asyncio , threading , random # goal is > multi tasking with the GUI not freezing before loop completed > # which is > being achieved here ! > def _asyncio_thread(async_loop): > async_loop.run_until_complete(do_urls()) > > def do_work(async_loop): > """ Button-Event-Handler starting stuff """ > threading.Thread(target=_asyncio_thread, args=(async_loop,)).start() > > async def one_url(url): > """ One task. """ > sec = random.randint(1, 8) > await asyncio.sleep(sec ) > return 'url: {} --- sec: {}'.format(url, sec) > > async def do_urls(): > """ Creating and starting 10 tasks. """ > tasks = [one_url(url) for url in range(10)] > completed, pending = await asyncio.wait(tasks) > results = [task.result() for task in completed] > print('\n'.join(results)) > > > def do_nofreeze(): > messagebox.showinfo(message='see, Tkinter is still responsive') > > def submain(async_loop): > root = Tk() > b1 = Button(master=root, text='do work', command= > lambda:do_work( async_loop)).pack() > b2 = Button(master=root, text='Frozen?', command=do_nofreeze > ).pack() > root.mainloop() > > > if __name__ == '__main__': > async_loop = asyncio.get_event_loop() # all in this loop > submain(async_loop) > > > -- > https://mail.python.org/mailman/listinfo/python-list > From arj.python at gmail.com Sun Dec 31 00:03:24 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 31 Dec 2017 09:03:24 +0400 Subject: a nice editor in 100 lines In-Reply-To: References: Message-ID: great ! maybe the next step is a syntax coloriser ^^_ Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 31 Dec 2017 02:05, "Wu Xi" wrote: > class writerKl(object): > def __init__(self): > import tkinter > from tkinter import messagebox > from tkinter import filedialog > from tkinter import Tk > from tkinter import Menu > from tkinter import END > > self.fileName = None > self.saved = True > self.app = tkinter.Tk() > self.app.title("FenInst is another instance of the writerKl > class") > > self.menuBar = tkinter.Menu(self.app) > self.fileMenu = tkinter.Menu(self.menuBar, tearoff=0) > self.fileMenu.add_command(label="New", > command=self.newFile) > self.fileMenu.add_command(label="Open", > command=self.openFile) > self.fileMenu.add_command(label="Save", > command=self.saveFile) > self.fileMenu.add_command(label="Save As", > command=self.saveFileAs) > self.fileMenu.add_separator() ; self.About = "A selfish > tkinter text editor in 100 lines of python3 code.\n\n In fact this very > ''About window'' also was modded using the selfish editor himself.\n\n Open > the source ''writer.py'' to find out why this editor is seen as so 105x > self-obsessed." > self.fileMenu.add_command(label= "About", command=lambda: > tkinter.messagebox.showinfo("About", self.About)) > self.fileMenu.add_separator() > self.fileMenu.add_command(label="Exit", command=self.onExit) > self.menuBar.add_cascade( label="File", menu =self.fileMenu) > self.app.config(menu=self.menuBar) > > self.app.bind('', self.newFile ) # key > Bindings > self.app.bind('', self.openFile) > self.app.bind('', self.saveFile) > self.app.bind('', self.setsavedFalse ) > self.app.protocol("WM_DELETE_WINDOW", self.onExit) # save > before exit? > > self.textf = tkinter.Text(self.app) # > initializing text container > self.textf.pack(expand=True, fill='both') # > deploying text container > self.textf.focus() > self.app.mainloop() > > def newFile(self): > import tkinter > if not self.saved: > save = self.promptToSave() > if save: self.saveFile() > elif self.save is None: return > self.fileName = None > self.textf.delete(0.0, tkinter.END) > self.saved = True > > def openFile(self): > import tkinter > if not self.saved: > self.save = self.promptToSave() > if self.save: > self.saveFile() > elif self.save is None: > return > try: > self.f = tkinter.filedialog.askopenfile( filetypes=[ ('all > files', '*') , ('py files', '.py') ] ) > if self.f: > self.fileName = self.f.name > self.t = self.f.read() > self.textf.delete(0.0, tkinter.END) > self.textf.insert(tkinter.END, self.t) > self.saved = True > except: tkinter.messagebox.showerror("Error", "Unable to > open file.") > > def saveFile(self): > import tkinter > self.t = self.textf.get(0.0, tkinter.END) > if self.fileName: > self.f = open(self.fileName, "w") > self.f.write(self.t) > self.f.close() > self.saved = True > else: self.saveFileAs() > > def saveFileAs(self): > import tkinter > self.f = tkinter.filedialog.asksaveasfile(defaultextension=".txt", > filetypes=[ ('all files', '*'),('py files', '.py') ]) > self.t = self.textf.get(0.0, tkinter.END) > if self.f: > try: > self.f.write(self.t) > self.f.close( ) > self.saved = True > self.fileName=self.f.name > except: tkinter.messagebox.showwarning("Error", "Unable to > save file.") > > def onExit(self): > import tkinter > if not self.saved: > self.save = self.promptToSave() > if self.save: self.saveFile() > elif self.save is None: return > self.app.destroy() > > def setsavedFalse(self, key): > import tkinter > if (key.keysym.isalpha() or key.keysym.isdigit() or key.keysym in > ["Return", "Tab", "Backspace", "Delete"]): self.saved = False # any key > that changes text > > def promptToSave(self): > import tkinter > return tkinter.messagebox.askyesnocancel( "Save file?", "Do > you want to save the current file?") > > > if __name__ == '__main__' : > import tkinter > FenInst =writerKl() > -- > https://mail.python.org/mailman/listinfo/python-list > From random832 at fastmail.com Sun Dec 31 00:25:36 2017 From: random832 at fastmail.com (Random832) Date: Sun, 31 Dec 2017 00:25:36 -0500 Subject: How to exec a string which has an embedded '\n'? In-Reply-To: References: Message-ID: <1514697936.456533.1220037056.708483ED@webmail.messagingengine.com> On Sat, Dec 30, 2017, at 23:57, jfong at ms4.hinet.net wrote: > I have a multiline string, something like '''...\nf.write('\n')\n...''' > when pass to exec(), I got > SyntaxError: EOL while scanning string literal > > How to get rid of it? Use \\n for this case, since you want the \n to be interpreted by the exec parser rather than the newline being part of the string. From rosuav at gmail.com Sun Dec 31 01:45:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Dec 2017 17:45:13 +1100 Subject: tkinter MP working like a charm In-Reply-To: References: Message-ID: On Sun, Dec 31, 2017 at 4:02 PM, Abdur-Rahmaan Janhangeer wrote: > for beginners import * is probably fine. Even if you are using most modules > then too. else if module small maybe ok too > > just when you import just what you need, you save on resources . > Actually no; the entire module still gets executed and loaded into memory. It's just about how you name things. ChrisA From arj.python at gmail.com Sun Dec 31 04:03:24 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 31 Dec 2017 13:03:24 +0400 Subject: tkinter MP working like a charm In-Reply-To: References: Message-ID: @Chris hum nice point it seems to be related to namespace convenience like 1 from x import * is likelier to cause conflicts than 2 import x Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 31 Dec 2017 05:00, "Wu Xi" wrote: > from tkinter import * # I cant see > anything wrong with this , it works like a charm > from tkinter import messagebox # is there a > serious concern doing things his way ? > import asyncio , threading , random # goal is > multi tasking with the GUI not freezing before loop completed > # which is > being achieved here ! > def _asyncio_thread(async_loop): > async_loop.run_until_complete(do_urls()) > > def do_work(async_loop): > """ Button-Event-Handler starting stuff """ > threading.Thread(target=_asyncio_thread, args=(async_loop,)).start() > > async def one_url(url): > """ One task. """ > sec = random.randint(1, 8) > await asyncio.sleep(sec ) > return 'url: {} --- sec: {}'.format(url, sec) > > async def do_urls(): > """ Creating and starting 10 tasks. """ > tasks = [one_url(url) for url in range(10)] > completed, pending = await asyncio.wait(tasks) > results = [task.result() for task in completed] > print('\n'.join(results)) > > > def do_nofreeze(): > messagebox.showinfo(message='see, Tkinter is still responsive') > > def submain(async_loop): > root = Tk() > b1 = Button(master=root, text='do work', command= > lambda:do_work( async_loop)).pack() > b2 = Button(master=root, text='Frozen?', command=do_nofreeze > ).pack() > root.mainloop() > > > if __name__ == '__main__': > async_loop = asyncio.get_event_loop() # all in this loop > submain(async_loop) > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Dec 31 04:19:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Dec 2017 20:19:10 +1100 Subject: tkinter MP working like a charm In-Reply-To: References: Message-ID: On Sun, Dec 31, 2017 at 8:03 PM, Abdur-Rahmaan Janhangeer wrote: > @Chris > > hum nice point > > it seems to be related to namespace convenience > > like > > 1 from x import * > > is likelier to cause conflicts than > > 2 import x This is correct. Also, when you read the code, you can instantly tell that "x.ALL" is not the same as the built-in "all" function, but it's less obvious if they're both just simple names. Some modules are designed to be star-imported (tkinter being one of them), but even there - and *definitely* for other modules - it's much clearer to use module imports. ChrisA From news at luegenpresse.edu Sun Dec 31 04:23:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 09:23:00 +0000 Subject: tkinter MP working like a charm References: Message-ID: OK, I never figured out that "import *" business... I was originally referring to the handling of multi-tasking via the root.mainloop() if __name__ == '__main__': async_loop = asyncio.get_event_loop() # all in this loop submain(async_loop) business , which some found a bit outlandish. I cannot see why, though. From news at luegenpresse.edu Sun Dec 31 04:51:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 09:51:00 +0000 Subject: a nice editor in 100 lines References: <2976c9ed-101d-4210-b15a-8d2c24f623b3@googlegroups.com> <44dfc401-8847-4a6d-b44d-7d7e2298dc40@googlegroups.com> Message-ID: wxjmfauth at gmail.com: > Le dimanche 31 d?cembre 2017 10:33:03 UTC+1, wxjm... at gmail.com a ?crit?: >> Le samedi 30 d?cembre 2017 23:02:41 UTC+1, Wu Xi a ?crit?: > Addendum > > This one is also not working. > > https://www.reddit.com/r/Python/comments/7murk2/a_python_ide_made_with_tkinter_it_should_be nice find! works smoothly here, except running the opened file kinda not path finding... gotta be easy to fix. From news at luegenpresse.edu Sun Dec 31 04:55:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 09:55:00 +0000 Subject: a nice editor in 100 lines References: <2976c9ed-101d-4210-b15a-8d2c24f623b3@googlegroups.com> <44dfc401-8847-4a6d-b44d-7d7e2298dc40@googlegroups.com> Message-ID: https://github.com/morten1982/crossviper > > nice find! > > > works smoothly here, except running the opened file kinda not path finding... gotta be easy to fix. > take that back in xterm mode , path is no problem. nice IDE ! From jfong at ms4.hinet.net Sun Dec 31 05:03:58 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 31 Dec 2017 02:03:58 -0800 (PST) Subject: How to exec a string which has an embedded '\n'? In-Reply-To: References: <1514697936.456533.1220037056.708483ED@webmail.messagingengine.com> Message-ID: Random832? 2017?12?31???? UTC+8??1?25?50???? > On Sat, Dec 30, 2017, at 23:57, jfong at ms4.hinet.net wrote: > > I have a multiline string, something like '''...\nf.write('\n')\n...''' > > when pass to exec(), I got > > SyntaxError: EOL while scanning string literal > > > > How to get rid of it? > > Use \\n for this case, since you want the \n to be interpreted by the exec parser rather than the newline being part of the string. Thank you, it's very helpful. This answer makes me think about '\' more thoughtful:-) --Jach From news at luegenpresse.edu Sun Dec 31 05:13:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 10:13:00 +0000 Subject: Mr. Conway in 50 lines of code Message-ID: import time , itertools __doc__=" Mr Conway_s Game Of Life simulation in python 2 and 3 " width = 55 ; height = 55 # size of life habitat , e.g. a simulated meteorite, bolide , etc. vmap = [['D' for w in range(width)] for h in range(height)] # D = Dead at first def neighbours(point): x,y = point yield x + 1 , y yield x - 1 , y yield x , y + 1 yield x , y - 1 # this is proof that life can emerge inside of computers and cellular automatons, yield x + 1 , y + 1 # and evolve through memory, attack other cells and morph into toads, pulsars, etc.. yield x + 1 , y - 1 yield x - 1 , y + 1 # spray your memory with space alien patterns and life evolution will start in your machine ! yield x - 1 , y - 1 def ageing(habitat): newstate = set() recalc = habitat | set(itertools.chain(*map(neighbours, habitat))) for point in recalc: count = sum((neigh in habitat) for neigh in neighbours( point)) if count == 3 or (count == 2 and point in habitat): # standard rule def. - a life cell having less than 2 alive neighbours will die newstate.add(point) return newstate glider = set([ (40,40) , (41,40) , (42,40) , (40,41) , (41,42) ]) # patterns of life: gliders, boats, guns, imps, toads, pulsars and so on previous = set([ ( 0, 0) , ( 1, 0) , ( 2, 0) , ( 0, 1) , ( 1, 2) ]) # offset on screen / place during last step in life for lifetime in range(300): # number of simulated lifetime steps (e.g. 300 / 0.1 sleep = 30 seconds) before death occurs try: time.sleep( 0.1 ) # slow it down previous = glider ; glider = ageing(glider) for tup in glider : el=tup ; xx=el[0] % width ; yy =el[1] % height ; vmap[xx][yy]='L' # Live cell has emerged for tup in previous : el=tup ; xx=el[0] % width ; yy =el[1] % height if tup not in glider : vmap[xx][yy]='D' # Dead cell # put more life patterns in this lifespan loop and let them evolutionize! vtxt = [''.join('*' if cell=='L' else ' ' for cell in row) for row in vmap] print('\033[H\033[J') # clear screen print('\n'.join(reversed(vtxt))) except: pass print("Simulated lifetime of the glider is over. May there live soon a new glider in the life habitat of your screen.") From bc at freeuk.com Sun Dec 31 07:33:48 2017 From: bc at freeuk.com (bartc) Date: Sun, 31 Dec 2017 12:33:48 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> Message-ID: On 30/12/2017 23:54, Chris Angelico wrote: > On Sun, Dec 31, 2017 at 10:45 AM, bartc wrote: >> On 30/12/2017 23:26, Gregory Ewing wrote: >>> >>> bartc wrote: >>>> >>>> B and C occur twice, so a goto is a quick way to reuse B and C without >>>> needing to duplicate code, >>> >>> >>> This only works if the repeated part happens to be at the >>> tail of each case. >> >> >> IME that seems to be the most common situation. >> > > I've written code that uses dirty tricks like that to avoid > duplication. It's at least as much of a problem as actual duplication > is. Generally, the 'goto' solution results in subsequent programmers > (such as my future selves) staring at the code for 30-60 seconds to > figure out what it's doing. I don't like to do that to myself, much > less to people I actually admire and respect. The problem is having to stare at the code for even longer to figure out the even dirtier tricks you had to use to avoid gotos. From rosuav at gmail.com Sun Dec 31 07:41:25 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Dec 2017 23:41:25 +1100 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> Message-ID: On Sun, Dec 31, 2017 at 11:33 PM, bartc wrote: > On 30/12/2017 23:54, Chris Angelico wrote: >> >> On Sun, Dec 31, 2017 at 10:45 AM, bartc wrote: >>> >>> On 30/12/2017 23:26, Gregory Ewing wrote: >>>> >>>> >>>> bartc wrote: >>>>> >>>>> >>>>> B and C occur twice, so a goto is a quick way to reuse B and C without >>>>> needing to duplicate code, >>>> >>>> >>>> >>>> This only works if the repeated part happens to be at the >>>> tail of each case. >>> >>> >>> >>> IME that seems to be the most common situation. >>> >> >> I've written code that uses dirty tricks like that to avoid >> duplication. It's at least as much of a problem as actual duplication >> is. Generally, the 'goto' solution results in subsequent programmers >> (such as my future selves) staring at the code for 30-60 seconds to >> figure out what it's doing. I don't like to do that to myself, much >> less to people I actually admire and respect. > > > The problem is having to stare at the code for even longer to figure out the > even dirtier tricks you had to use to avoid gotos. > Dirtier tricks like... named functions? ChrisA From bc at freeuk.com Sun Dec 31 09:20:09 2017 From: bc at freeuk.com (bartc) Date: Sun, 31 Dec 2017 14:20:09 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> Message-ID: On 31/12/2017 12:41, Chris Angelico wrote: > On Sun, Dec 31, 2017 at 11:33 PM, bartc wrote: >> On 30/12/2017 23:54, Chris Angelico wrote: >>> I've written code that uses dirty tricks like that to avoid >>> duplication. It's at least as much of a problem as actual duplication >>> is. Generally, the 'goto' solution results in subsequent programmers >>> (such as my future selves) staring at the code for 30-60 seconds to >>> figure out what it's doing. I don't like to do that to myself, much >>> less to people I actually admire and respect. >> >> >> The problem is having to stare at the code for even longer to figure out the >> even dirtier tricks you had to use to avoid gotos. >> > > Dirtier tricks like... named functions? I like to write clean and readable code. If I thought introducing functions, whether local or not, as a way of avoiding goto was worth doing, I would do so. So in this case I disagree with dragging in named functions and introducing an extra level of control flow just to avoid duplicating half a dozen lines of code. I would just duplicate those lines (with a comment that they have to match the other set so that they are maintained in sync). For other uses of goto, I've introduced (not in Python or C but my own stuff) features to avoid the need some of those uses. For example, extra loop controls, and loop controls that work with nested loops. I've also experimented with a feature intended purely to get to common clean-up code, but that had little advantage over using goto other than not writing 'goto', and thus avoiding some of the stigma (but you will also know it will do a one-off forward jump to a common point). (Actually, none of my code ever needs to use 'goto' anyway, as I can also write it as 'go to'. That's effective if anyone does a 'grep' on my code looking for 'goto' instances...) -- bartc From ben.usenet at bsb.me.uk Sun Dec 31 10:02:13 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 31 Dec 2017 15:02:13 +0000 Subject: Goto (Posting On Python-List Prohibited) References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> Message-ID: <87d12vc556.fsf@bsb.me.uk> bartc writes: > On 31/12/2017 12:41, Chris Angelico wrote: >> On Sun, Dec 31, 2017 at 11:33 PM, bartc wrote: >>> On 30/12/2017 23:54, Chris Angelico wrote: > >>>> I've written code that uses dirty tricks like that to avoid >>>> duplication. It's at least as much of a problem as actual duplication >>>> is. Generally, the 'goto' solution results in subsequent programmers >>>> (such as my future selves) staring at the code for 30-60 seconds to >>>> figure out what it's doing. I don't like to do that to myself, much >>>> less to people I actually admire and respect. >>> >>> The problem is having to stare at the code for even longer to figure out the >>> even dirtier tricks you had to use to avoid gotos. >> >> Dirtier tricks like... named functions? > > I like to write clean and readable code. If I thought introducing > functions, whether local or not, as a way of avoiding goto was worth > doing, I would do so. I think there's a problem with that. Standard C does not have them, you said your language does not implement them properly and I think you are new(ish) to Python. What language did you try them in? It may be that it was overly complex in that language. The idea is clean and simple. > So in this case I disagree with dragging in named functions and > introducing an extra level of control flow just to avoid duplicating > half a dozen lines of code. I would just duplicate those lines (with a > comment that they have to match the other set so that they are > maintained in sync). The suggestion was to use them to avoid gotos. If duplicating is a good idea (and it's a hard line to draw) then we are not talking about the same cases. Given the choice of "dragging in named functions" and dragging in named blocks and gotos, I would choose the functions every time. -- Ben. From rustompmody at gmail.com Sun Dec 31 10:30:26 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 31 Dec 2017 07:30:26 -0800 (PST) Subject: emacsclient does not select frame? Message-ID: With a lot of jumping through hoops Ive managed to get firefox to call emacs(client) and save links+description(title)+selection(in firefox; optional) into an org mode capture buffer. However the call to emacsclient does not raise the frame... At least not consistently? Currently my hack is to write my own shell wrapper to emacsclient doing wmctrl -c emacs emacsclient -c $* wmctrl -a emacs Is there some other thing I dont know to raise the emacs frame? Also the -c I am forced to use because without it, if there is not an existing frame (emacs started in --daemon mode) it does not work Emacs 25.1.1 Gnome-Unity From rustompmody at gmail.com Sun Dec 31 10:31:55 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 31 Dec 2017 07:31:55 -0800 (PST) Subject: emacsclient does not select frame? In-Reply-To: References: Message-ID: On Sunday, December 31, 2017 at 9:00:53 PM UTC+5:30, Rustom Mody wrote: > With a lot of jumping through hoops Ive managed to get firefox to > call emacs(client) and save links+description(title)+selection(in firefox; optional) into an org mode capture buffer. > > However the call to emacsclient does not raise the frame... At least not consistently? > > Currently my hack is to write my own shell wrapper to emacsclient doing > > wmctrl -c emacs > emacsclient -c $* > wmctrl -a emacs > > Is there some other thing I dont know to raise the emacs frame? > > Also the -c I am forced to use because without it, if there is not an existing > frame (emacs started in --daemon mode) it does not work > > > Emacs 25.1.1 > Gnome-Unity Oops Wrong list Apologies And happy new year! From breamoreboy at gmail.com Sun Dec 31 10:39:51 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 31 Dec 2017 07:39:51 -0800 (PST) Subject: Copy-on-write friendly Python garbage collection Message-ID: <10b9cfba-7611-4544-ae83-62969c47dcf4@googlegroups.com> An interesting write up on something that is incorporated into Python 3.7 https://engineering.instagram.com/copy-on-write-friendly-python-garbage-collection-ad6ed5233ddf -- Kindest regards. Mark Lawrence. From bc at freeuk.com Sun Dec 31 11:55:01 2017 From: bc at freeuk.com (bartc) Date: Sun, 31 Dec 2017 16:55:01 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <87d12vc556.fsf@bsb.me.uk> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> Message-ID: On 31/12/2017 15:02, Ben Bacarisse wrote: > bartc writes: > I think there's a problem with that. Standard C does not have them, you > said your language does not implement them properly (The real problem is I don't remember local functions being used anywhere else. It's an idiom I'm not used to and that apparently few other people use. Except perhaps in Python where they do to use advanced features over simpler ones.) and I think you are > new(ish) to Python. What language did you try them in? It may be that > it was overly complex in that language. The idea is clean and simple. It's not simple to implement. Not if you want full access to the non-static variables of the containing function(s). It doesn't sound that efficient either. >> So in this case I disagree with dragging in named functions and >> introducing an extra level of control flow just to avoid duplicating >> half a dozen lines of code. I would just duplicate those lines (with a >> comment that they have to match the other set so that they are >> maintained in sync). > > The suggestion was to use them to avoid gotos. If duplicating is a good > idea (and it's a hard line to draw) then we are not talking about the > same cases. Given the choice of "dragging in named functions" and > dragging in named blocks and gotos, I would choose the functions every > time. The blocks don't need to be dragged; they are already in place! It's funny because in c.l.c you're always advocating keep declarations as close to the point of use as possible. Here you appear to be saying the opposite: taking code away from the primary point of use. (Which is likely to cause problems if the code includes breaks, or gotos if the language has them.) I think there is a way to solve this pattern via special language features, while writing the main code primarily inline and in a natural structure, but I haven't found a satisfactory method yet. I don't think local functions is it. (And perhaps a solution lies outside the language such as within an editor, to allow sharing of the same block of code in multiple locations.) -- bartc From breamoreboy at gmail.com Sun Dec 31 12:01:54 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 31 Dec 2017 09:01:54 -0800 (PST) Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <87d12vc556.fsf@bsb.me.uk> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> Message-ID: <996f33d4-df8a-460b-bba1-8f43238588b0@googlegroups.com> On Sunday, December 31, 2017 at 3:02:41 PM UTC, Ben Bacarisse wrote: > bartc writes: > > > On 31/12/2017 12:41, Chris Angelico wrote: > >> On Sun, Dec 31, 2017 at 11:33 PM, bartc wrote: > >>> On 30/12/2017 23:54, Chris Angelico wrote: > > > >>>> I've written code that uses dirty tricks like that to avoid > >>>> duplication. It's at least as much of a problem as actual duplication > >>>> is. Generally, the 'goto' solution results in subsequent programmers > >>>> (such as my future selves) staring at the code for 30-60 seconds to > >>>> figure out what it's doing. I don't like to do that to myself, much > >>>> less to people I actually admire and respect. > >>> > >>> The problem is having to stare at the code for even longer to figure out the > >>> even dirtier tricks you had to use to avoid gotos. > >> > >> Dirtier tricks like... named functions? > > > > I like to write clean and readable code. If I thought introducing > > functions, whether local or not, as a way of avoiding goto was worth > > doing, I would do so. > > I think there's a problem with that. Standard C does not have them, you > said your language does not implement them properly and I think you are > new(ish) to Python. What language did you try them in? It may be that > it was overly complex in that language. The idea is clean and simple. > > > So in this case I disagree with dragging in named functions and > > introducing an extra level of control flow just to avoid duplicating > > half a dozen lines of code. I would just duplicate those lines (with a > > comment that they have to match the other set so that they are > > maintained in sync). > > The suggestion was to use them to avoid gotos. If duplicating is a good > idea (and it's a hard line to draw) then we are not talking about the > same cases. Given the choice of "dragging in named functions" and > dragging in named blocks and gotos, I would choose the functions every > time. > > > -- > Ben. I would use functions every time as a modern compiler can inline them, something described here https://en.wikipedia.org/wiki/Inline_expansion for the benefit of newbies. Further I've never once in 17 years of using Python been tearing my hair out over the lack of goto as there are numerous examples of how to avoid them. This thread is yet another storm in a thimble. -- Kindest regards. Mark Lawrence. From rosuav at gmail.com Sun Dec 31 12:06:43 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Jan 2018 04:06:43 +1100 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> Message-ID: On Mon, Jan 1, 2018 at 3:55 AM, bartc wrote: >> The suggestion was to use them to avoid gotos. If duplicating is a good >> idea (and it's a hard line to draw) then we are not talking about the >> same cases. Given the choice of "dragging in named functions" and >> dragging in named blocks and gotos, I would choose the functions every >> time. > > > The blocks don't need to be dragged; they are already in place! > > It's funny because in c.l.c you're always advocating keep declarations as > close to the point of use as possible. Here you appear to be saying the > opposite: taking code away from the primary point of use. I don't understand the issue here. All you need to do is add a "def" statement header in front of the block of code. And maybe indent it further, although if you're unifying "if/elif" subtrees, that'll cancel out the indentation level change. The block of code stays at or near its first use. Once again, Bart, you're scorning something that you don't have much (any?) experience with. Look at how the feature is used before you hate on it. ChrisA From news at luegenpresse.edu Sun Dec 31 13:16:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 18:16:00 +0000 Subject: Copy-on-write friendly Python garbage collection References: <10b9cfba-7611-4544-ae83-62969c47dcf4@googlegroups.com> Message-ID: breamoreboy at gmail.com: > An interesting write up on something that is incorporated into Python 3.7 https://engineering.instagram.com/copy-on-write-friendly-python-garbage-collection-ad6ed5233ddf kewl py 3.7 does not fully make install here, but it built and works, as far as I can tell From news at luegenpresse.edu Sun Dec 31 13:18:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 18:18:00 +0000 Subject: Copy-on-write friendly Python garbage collection References: <10b9cfba-7611-4544-ae83-62969c47dcf4@googlegroups.com> Message-ID: breamoreboy at gmail.com: > An interesting write up on something that is incorporated into Python 3.7 https://engineering.instagram.com/copy-on-write-friendly-python-garbage-collection-ad6ed5233ddf Appearantly, Erlang is the way to go, when it comes to web frameworks. From none at invalid.com Sun Dec 31 13:28:42 2017 From: none at invalid.com (mm0fmf) Date: Sun, 31 Dec 2017 18:28:42 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <996f33d4-df8a-460b-bba1-8f43238588b0@googlegroups.com> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> <996f33d4-df8a-460b-bba1-8f43238588b0@googlegroups.com> Message-ID: On 31/12/2017 17:01, breamoreboy at gmail.com wrote: > I would use functions every time as a modern compiler can inline them This > Further I've never once in 17 years of using Python been tearing my hair out over the lack of goto And this. (In my case only 6 years.) From bc at freeuk.com Sun Dec 31 13:56:02 2017 From: bc at freeuk.com (bartc) Date: Sun, 31 Dec 2017 18:56:02 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <996f33d4-df8a-460b-bba1-8f43238588b0@googlegroups.com> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> <996f33d4-df8a-460b-bba1-8f43238588b0@googlegroups.com> Message-ID: <5pa2C.399820$bH7.185636@fx38.am4> On 31/12/2017 17:01, breamoreboy at gmail.com wrote: >Further I've never once in 17 years of using Python been tearing my hair out over the lack of goto Neither have I over all the advanced features of Python I never use, and for double that number of years. Yet for some they will be as indispensable as they are incomprehensible to others. From news at luegenpresse.edu Sun Dec 31 13:58:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Sun, 31 Dec 2017 18:58:00 +0000 Subject: Copy-on-write friendly Python garbage collection References: <10b9cfba-7611-4544-ae83-62969c47dcf4@googlegroups.com> <87608mvifj.fsf@nightsong.com> Message-ID: they said they run the largest deployment of Django world-wide. be it as it may... many still consider the web guys to be the "funny people". Why did they not switch over to Erlang ? From bc at freeuk.com Sun Dec 31 14:29:03 2017 From: bc at freeuk.com (bartc) Date: Sun, 31 Dec 2017 19:29:03 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> Message-ID: <3Ua2C.146098$1x.72970@fx30.am4> On 31/12/2017 17:06, Chris Angelico wrote: > On Mon, Jan 1, 2018 at 3:55 AM, bartc wrote: >>> The suggestion was to use them to avoid gotos. If duplicating is a good >>> idea (and it's a hard line to draw) then we are not talking about the >>> same cases. Given the choice of "dragging in named functions" and >>> dragging in named blocks and gotos, I would choose the functions every >>> time. >> >> >> The blocks don't need to be dragged; they are already in place! >> >> It's funny because in c.l.c you're always advocating keep declarations as >> close to the point of use as possible. Here you appear to be saying the >> opposite: taking code away from the primary point of use. > > I don't understand the issue here. All you need to do is add a "def" > statement header in front of the block of code. And maybe indent it > further, although if you're unifying "if/elif" subtrees, that'll > cancel out the indentation level change. The block of code stays at or > near its first use. You'll need to give an example I think. Suppose I start with this: def fn(a): if a==1: print ("One") print ("Two") print ("Three") elif a==2: print ("Four") else: print ("Other") print ("One") print ("Two") print ("Three") I want to share the lines that print One Two Three, so I create an inline function, defined as close as possible to the original code: def fn2(a): if a==1: def F123(): print ("One") print ("Two") print ("Three") F123() elif a==2: print ("Four") else: print ("Other") F123() However, if I call this with fn2(3), it says that variable F123 has not been assigned. (I'm not sure what overheads are associated with nested functions. Presumably its byte-code is done once, but is there any other setup of F123 associated with each call of fn2()? Even when a==2 so that F123() is not called? A brief test [not using print()] showed it was a little slower having F123 inside fn2() - and outside the if-statement to make it work - than having F123 outside. And having to call F123() anyway instead of just having the inline code makes it a little slower too. Although this would need to be balanced by the cost of the alternative, whether a goto or whatever.) Note also that a goto, and a function call, don't do the same thing. The function will return, the goto won't. In my example all paths will return, in others this will have to be taken care of. -- bartc Don't forget that after turning a block into a def-function in-place, it will need to be followed by a call to it: if X: A B C elif ... else: A B C This becomes: if X: def F(): A B C F() elif... else F() (Is the def statement executed once during byte-code compilation? Or can it give different result each time depending on what globals are visible within F? Will there at least be a set-up overhead for F each time Note that calling a local function is not quite a drop-in replacement for > Once again, Bart, you're scorning something that you don't have much > (any?) experience with. Look at how the feature is used before you > hate on it. > > ChrisA > From bc at freeuk.com Sun Dec 31 14:33:33 2017 From: bc at freeuk.com (bartc) Date: Sun, 31 Dec 2017 19:33:33 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <3Ua2C.146098$1x.72970@fx30.am4> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> <3Ua2C.146098$1x.72970@fx30.am4> Message-ID: On 31/12/2017 19:29, bartc wrote: [Ignore the original, incomplete version of my post, which appears after the sig. I decided to actually try it out for real instead of just guessing! Good thing too.] From rosuav at gmail.com Sun Dec 31 14:37:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Jan 2018 06:37:02 +1100 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <3Ua2C.146098$1x.72970@fx30.am4> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> <3Ua2C.146098$1x.72970@fx30.am4> Message-ID: On Mon, Jan 1, 2018 at 6:29 AM, bartc wrote: > You'll need to give an example I think. Suppose I start with this: > > def fn(a): > if a==1: > print ("One") > print ("Two") > print ("Three") > elif a==2: > print ("Four") > else: > print ("Other") > print ("One") > print ("Two") > print ("Three") > > I want to share the lines that print One Two Three, so I create an inline > function, defined as close as possible to the original code: > > def fn2(a): > if a==1: > def F123(): > print ("One") > print ("Two") > print ("Three") > F123() > elif a==2: > print ("Four") > else: > print ("Other") > F123() > > However, if I call this with fn2(3), it says that variable F123 has not been > assigned. Right, so you'd move it one line up (or move the 'if' down to below the function definition), thus the larger block of code stays where it is. > Note also that a goto, and a function call, don't do the same thing. The > function will return, the goto won't. Not sure what you mean by "return", because what you effectively do is create a name for a block of code, and then use (call) that block of code more than once. That makes it easy to comprehend. With the goto, you have to go look at the body below to figure out what happens. ChrisA From ben.usenet at bsb.me.uk Sun Dec 31 17:09:16 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 31 Dec 2017 22:09:16 +0000 Subject: Goto (Posting On Python-List Prohibited) References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> Message-ID: <871sjaczxv.fsf@bsb.me.uk> bartc writes: > On 31/12/2017 15:02, Ben Bacarisse wrote: >> bartc writes: > >> I think there's a problem with that. Standard C does not have them, you >> said your language does not implement them properly > > (The real problem is I don't remember local functions being used > anywhere else. It's an idiom I'm not used to and that apparently few > other people use. Except perhaps in Python where they do to use > advanced features over simpler ones.) > > and I think you are >> new(ish) to Python. What language did you try them in? It may be that >> it was overly complex in that language. The idea is clean and simple. > > It's not simple to implement. Not if you want full access to the > non-static variables of the containing function(s). It doesn't sound > that efficient either. No, you missed the point and did not address the question. You said (now cut) | If I thought introducing functions, whether local or not, as a way of | avoiding goto was worth doing, I would do so. but I'm not sure you know if it's worth it or not. So here's my question again: what language (or languages) were you using when you concluded that it was not worth using local functions to avoid gotos? Maybe you had a bad experience from some language that did it badly. >>> So in this case I disagree with dragging in named functions and >>> introducing an extra level of control flow just to avoid duplicating >>> half a dozen lines of code. I would just duplicate those lines (with a >>> comment that they have to match the other set so that they are >>> maintained in sync). >> >> The suggestion was to use them to avoid gotos. If duplicating is a good >> idea (and it's a hard line to draw) then we are not talking about the >> same cases. Given the choice of "dragging in named functions" and >> dragging in named blocks and gotos, I would choose the functions every >> time. > > The blocks don't need to be dragged; they are already in place! > > It's funny because in c.l.c you're always advocating keep declarations > as close to the point of use as possible. Here you appear to be saying > the opposite: taking code away from the primary point of use. If a language allowed me to declare a local function at the point of first use, I'd do that, but there are special reasons why that is not a reasonable thing to do in most cases. None the less, it's not inconsistent to prefer one less than perfect option to another much less than perfect option. However, we're debating an entirely abstract notion. What is a typical use for this "re-use" goto idiom? Maybe I'll prefer the goto version over any of the alternatives when I see an actual use. > (Which is likely to cause problems if the code includes breaks, or > gotos if the language has them.) Good grief! That is exactly the sort of code you should not re-use by jumping to it. There are myriad potential problems and putting the code into a function will allow the compiler to diagnose lots of them. If you really are jumping to re-use code that includes gotos I suggest the whole thing needs re-design. -- Ben. From bc at freeuk.com Sun Dec 31 18:21:05 2017 From: bc at freeuk.com (bartc) Date: Sun, 31 Dec 2017 23:21:05 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: <871sjaczxv.fsf@bsb.me.uk> References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> <871sjaczxv.fsf@bsb.me.uk> Message-ID: On 31/12/2017 22:09, Ben Bacarisse wrote: > No, you missed the point and did not address the question. You said (now > cut) > > | If I thought introducing functions, whether local or not, as a way of > | avoiding goto was worth doing, I would do so. > > but I'm not sure you know if it's worth it or not. So here's my > question again: what language (or languages) were you using when you > concluded that it was not worth using local functions to avoid gotos? > Maybe you had a bad experience from some language that did it badly. What makes you think I had a bad experience? I posted a version using Python a few hours ago (which needs the local function to be moved to work properly). The same example works in my language (one of them anyway), but I still find a quick goto the simplest thing to do especially when the code is not complete so I don't know what will be added or changed or moved, which will be harder as soon a specific sequence is extracted into a function. Also, what would be the duplicated code is seen to 'belong' to one of the options, rather than be anonymous. (Here is the same example in my static language: https://pastebin.com/raw/dX2FNK7a fn1 uses goto. fn2 uses a local function (not very demanding here so it works). fn3 uses the special 'block-call' feature which I no longer use (but I haven't yet got rid of it). I prefer fn1 and fn3 because the code stays inline. If I had some inspiration for a better feature then I'd have fn4 and maybe fn5 too.) Within Python, I touched on performance issues in my earlier post. (A local function apparently involves an extra assignment - per function - each time the containing function is called.) >> (Which is likely to cause problems if the code includes breaks, or >> gotos if the language has them.) > > Good grief! That is exactly the sort of code you should not re-use by > jumping to it. There are myriad potential problems and putting the code > into a function will allow the compiler to diagnose lots of them. OK, forget the gotos then. But a block can still contain break or return (and in my syntax, several other loop controls). It loses context as soon as it's hoisted into a function. -- bartc From lawrencedo99 at gmail.com Sun Dec 31 18:48:24 2017 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 31 Dec 2017 15:48:24 -0800 (PST) Subject: Mr. Conway in 50 lines of code (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: <37655e02-18a3-4ae3-b54c-d0499fd3afbd@googlegroups.com> On Sunday, December 31, 2017 at 11:13:41 PM UTC+13, Wu Xi wrote: > yield x + 1 , y > yield x - 1 , y > yield x , y + 1 > yield x , y - 1 # this is proof that life can emerge inside of computers and cellular automatons, > > yield x + 1 , y + 1 # and evolve through memory, attack other cells and morph into toads, pulsars, etc.. > yield x + 1 , y - 1 > yield x - 1 , y + 1 # spray your memory with space alien patterns and life evolution will start in your machine ! > yield x - 1 , y - 1 for i in range(-1, 2) : for j in range(-1, 2) : if i != j : yield x + i, y + j #end if #end for #end for which is half the number of lines of code. From news at luegenpresse.edu Sun Dec 31 19:06:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Mon, 01 Jan 2018 00:06:00 +0000 Subject: tkinter MP working like a charm (Posting On Python-List Prohibited) References: <44bf5b2a-d37d-4dad-99ef-3a8c2c0729c4@googlegroups.com> Message-ID: Lawrence D?Oliveiro: > On Sunday, December 31, 2017 at 10:23:32 PM UTC+13, Wu Xi wrote: >> >> I was originally referring to the handling of multi-tasking... which >> some found a bit outlandish. >> >> I cannot see why, though. > > I just can?t help thinking that you are using two threads to handle what can be done with one. > my question is: is the event loop business done OK in the sample programme ? From news at luegenpresse.edu Sun Dec 31 19:34:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Mon, 01 Jan 2018 00:34:00 +0000 Subject: Python: asyncio and Tkinter (Posting On Python-List Prohibited) References: <3z1ZG23Kc6z9rxF@submission02.posteo.de> <3z25rn0KgXz9rxP@submission02.posteo.de> <13535b0b-5aa9-485c-8042-f17a6e037c9e@googlegroups.com> Message-ID: Lawrence D?Oliveiro: > On Sunday, December 31, 2017 at 12:47:21 PM UTC+13, Wu Xi wrote: >> this is kinda interesting. seems there is no easy way though > > If I could do it for GTK/GLib , I don?t see why Tk should be hard. ;) well, hard or no, but glibcoro is a no workie here. 2-3 chaos, as intended by Guido. From python at mrabarnett.plus.com Sun Dec 31 19:40:36 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 1 Jan 2018 00:40:36 +0000 Subject: Goto (Posting On Python-List Prohibited) In-Reply-To: References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> <871sjaczxv.fsf@bsb.me.uk> Message-ID: On 2017-12-31 23:21, bartc wrote: > On 31/12/2017 22:09, Ben Bacarisse wrote: > >> No, you missed the point and did not address the question. You said (now >> cut) >> >> | If I thought introducing functions, whether local or not, as a way of >> | avoiding goto was worth doing, I would do so. >> >> but I'm not sure you know if it's worth it or not. So here's my >> question again: what language (or languages) were you using when you >> concluded that it was not worth using local functions to avoid gotos? >> Maybe you had a bad experience from some language that did it badly. > > What makes you think I had a bad experience? I posted a version using > Python a few hours ago (which needs the local function to be moved to > work properly). > > The same example works in my language (one of them anyway), but I still > find a quick goto the simplest thing to do especially when the code is > not complete so I don't know what will be added or changed or moved, > which will be harder as soon a specific sequence is extracted into a > function. > > Also, what would be the duplicated code is seen to 'belong' to one of > the options, rather than be anonymous. > > (Here is the same example in my static language: > https://pastebin.com/raw/dX2FNK7a > > fn1 uses goto. fn2 uses a local function (not very demanding here so it > works). fn3 uses the special 'block-call' feature which I no longer use > (but I haven't yet got rid of it). > > I prefer fn1 and fn3 because the code stays inline. If I had some > inspiration for a better feature then I'd have fn4 and maybe fn5 too.) > The compiler could inline automatically, or you could be explicit: proc fn2(int a)= inline proc f123= println "One" println "Two" println "Three" end case a when 1 then f123() when 2 then println "Four" else println "Other" f123() esac end (or possibly "inline f123="). [snip] OT: if "case ... esac" and "if ... fi", why not "proc ... corp"? :-) From news at luegenpresse.edu Sun Dec 31 20:15:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Mon, 01 Jan 2018 01:15:00 +0000 Subject: you shortened it, but you broke it too... ;-) References: <37655e02-18a3-4ae3-b54c-d0499fd3afbd@googlegroups.com> <87vagmtpxe.fsf@nightsong.com> Message-ID: import time , itertools __doc__=" Mr Conway_s Game Of Life simulation in python 2 and 3 " width = 100 ; height = 50 # size of life habitat , e.g. a simulated meteorite, bolide , etc. vmap = [['D' for w in range(width)] for h in range(height)] # D = Dead at first def neighbours(point): x,y = point yield x + 1 , y yield x - 1 , y yield x , y + 1 yield x , y - 1 # this is proof that life can emerge inside of computers and cellular automatons, yield x + 1 , y + 1 # and evolve through memory, attack other cells and morph into toads, pulsars, etc.. yield x + 1 , y - 1 yield x - 1 , y + 1 # spray your memory with space alien patterns and life evolution will start in your machine ! yield x - 1 , y - 1 ''' for i in range(-1, 2) : for j in range(-1, 2) : if i != j : yield x + i, y + j ''' # yield from [(x+i, x+j) for i in [-1,1] for j in [-1,1]] def ageing(habitat): newstate = set() recalc = habitat | set(itertools.chain(*map(neighbours, habitat))) for point in recalc: count = sum((neigh in habitat) for neigh in neighbours( point)) if count == 3 or (count == 2 and point in habitat): # standard rule def. - a life cell having less than 2 alive neighbours will die newstate.add(point) return newstate glider = set([ (40,40) , (41,40) , (42,40) , (40,41) , (41,42) ]) # patterns of life: gliders, boats, guns, imps, toads, pulsars and so on previous = set([ ( 0, 0) , ( 1, 0) , ( 2, 0) , ( 0, 1) , ( 1, 2) ]) # offset on screen / place during last step in life for lifetime in range(300): # number of simulated lifetime steps (e.g. 300 / 0.1 sleep = 30 seconds) before death occurs try: time.sleep( 0.1 ) # slow it down previous = glider ; glider = ageing(glider) for tup in glider : el=tup ; xx=el[0] % width ; yy =el[1] % height ; vmap[xx][yy]='L' # Live cell has emerged for tup in previous : el=tup ; xx=el[0] % width ; yy =el[1] % height if tup not in glider : vmap[xx][yy]='D' # Dead cell # put more life patterns in this lifespan loop and let them evolutionize! vtxt = [''.join('*' if cell=='L' else ' ' for cell in row) for row in vmap] print('\033[H\033[J') # clear screen print('\n'.join(reversed(vtxt))) except: pass print("Simulated lifetime of the glider is over. May there live soon a new glider in the life habitat of your screen.") From ben.usenet at bsb.me.uk Sun Dec 31 20:19:12 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 01 Jan 2018 01:19:12 +0000 Subject: Goto (Posting On Python-List Prohibited) References: <9Zz1C.185732$oD1.1720@fx44.am4> <8yV1C.295429$3J3.166915@fx37.am4> <87d12vc556.fsf@bsb.me.uk> <871sjaczxv.fsf@bsb.me.uk> Message-ID: <87vagmbckv.fsf@bsb.me.uk> bartc writes: > On 31/12/2017 22:09, Ben Bacarisse wrote: > >> No, you missed the point and did not address the question. You said (now >> cut) >> >> | If I thought introducing functions, whether local or not, as a way of >> | avoiding goto was worth doing, I would do so. >> >> but I'm not sure you know if it's worth it or not. So here's my >> question again: what language (or languages) were you using when you >> concluded that it was not worth using local functions to avoid gotos? >> Maybe you had a bad experience from some language that did it badly. > > What makes you think I had a bad experience? Nothing. I was asking what experience you had that led to your conclusion. Knowing the language might explain the conclusion you came to. -- Ben. From jfong at ms4.hinet.net Sun Dec 31 20:26:06 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 31 Dec 2017 17:26:06 -0800 (PST) Subject: How to exec a string which has an embedded '\n'? (Posting On Python-List Prohibited) In-Reply-To: <31175816-d2ca-4e40-a2f3-ad27b63c616c@googlegroups.com> References: <1514697936.456533.1220037056.708483ED@webmail.messagingengine.com> <31175816-d2ca-4e40-a2f3-ad27b63c616c@googlegroups.com> Message-ID: <4391a3d0-1ef2-457f-8044-52fb159f1849@googlegroups.com> Lawrence D?Oliveiro? 2018?1?1???? UTC+8??7?56?02???? > On Sunday, December 31, 2017 at 11:04:19 PM UTC+13, jf... at ms4.hinet.net wrote: > > > > This answer makes me think about '\' more thoughtful:-) > > Python generating HTML containing JavaScript which generates HTML: > > out.write \ > ( > "\nfunction %(paramname)s_UpdateProjects()\n" > # /* refreshes the project list to show enabled and/or disabled projects as appropriate. */ > " {\n" > " var IncludeEnabled = document.forms[\"%(formname)s\"]." > "elements[\"%(paramname)s_show_enabled\"].checked\n" > " var IncludeDisabled = document.forms[\"%(formname)s\"]." > "elements[\"%(paramname)s_show_disabled\"].checked\n" > " var TheList = \"\"\n" > " for (var i = 0; i < %(paramname)s_ProjectList.length; ++i)\n" > " {\n" > " var ThisProject = %(paramname)s_ProjectList[i]\n" > " if (ThisProject.enabled ? IncludeEnabled : IncludeDisabled)\n" > " {\n" > " TheList += \"\\n\"\n" > " } /*if*/\n" > " } /*for*/\n" > " DocumentElt(\"%(formname)s_%(paramname)s_list\").innerHTML =\n" > " \"\\n\"\n" > " } /*%(paramname)s_UpdateProjects*/\n" > % > { > "formname" : FormName, > "paramname" : ParamName, > "on_selection_changed" : OnSelectionChanged, > } > ) I don't even dare to read through this code:-( How to run it? From tjreedy at udel.edu Sun Dec 31 20:52:41 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 Dec 2017 20:52:41 -0500 Subject: tkinter MP working like a charm In-Reply-To: References: Message-ID: On 12/30/2017 7:57 PM, Wu Xi wrote: > from tkinter import * # I cant see anything wrong with this , it works like a charm This imports about 200 names. A reader may not know which names are builtins and which are imports. There may also be accidental name conflicts. > from tkinter import messagebox # is there a serious concern doing things his way ? This is the normal way to import tkinter subpackages. > import asyncio , threading , random # goal is multi tasking with the GUI not freezing before loop completed > # which is being achieved here ! I verified that this works in 3.7.0a3 as I believe you intend. So it is possible to create and run a tk loop in the main thread and run async loop (created in the main thread) in a subthread. I don't think anyone knows when this will and will not work. What you show below is that asyncio.sleep and asyncio.wait work under this circumstance. Actually fetching even one url and making it readable from the main thread, so it can be displayed in a tk Text widget, would be even more impressive, and useful. > def _asyncio_thread(async_loop): > async_loop.run_until_complete(do_urls()) > > def do_work(async_loop): > """ Button-Event-Handler starting stuff """ > threading.Thread(target=_asyncio_thread, args=(async_loop,)).start() > > async def one_url(url): > """ One task. """ > sec = random.randint(1, 8) > await asyncio.sleep(sec ) > return 'url: {} --- sec: {}'.format(url, sec) > > async def do_urls(): > """ Creating and starting 10 tasks. """ > tasks = [one_url(url) for url in range(10)] > completed, pending = await asyncio.wait(tasks) > results = [task.result() for task in completed] > print('\n'.join(results)) > > def do_nofreeze(): > messagebox.showinfo(message='see, Tkinter is still responsive') > > def submain(async_loop): > root = Tk() > b1 = Button(master=root, text='do work', command= lambda:do_work( async_loop)).pack() > b2 = Button(master=root, text='Frozen?', command=do_nofreeze ).pack() .pack() returns None, and binding None to b1 and b2 is useless. Either skip the assignment or call .pack after the assignment. Button(master=root, text='do work', command= lambda:do_work( async_loop)).pack() b1 = Button(master=root, text='do work', command= lambda:do_work( async_loop)) b1.pack() Since b1 and b2 here are local variables not accessible output submain, do the former. If submain were a method, 'self.b1 = Button...' would make it easy to access the button from elsewhere, as for testing. (It is also possible to introspect root for its contents.) > root.mainloop() > > if __name__ == '__main__': > async_loop = asyncio.get_event_loop() # all in this loop > submain(async_loop) To do everything in the main thread, one can replace 'root.mainloop' with loop.run_forever (in the main thread) and repeated root.update calls. -- Terry Jan Reedy From news at luegenpresse.edu Sun Dec 31 21:35:00 2017 From: news at luegenpresse.edu (Wu Xi) Date: Mon, 01 Jan 2018 02:35:00 +0000 Subject: OK, now one main block only , but loop.run_forever() ? idk... References: Message-ID: from tkinter import * # I cant see anything wrong with the async_loop business here. It works like a charm. from tkinter import messagebox # is there a serious concern doing things his way ? import asyncio , threading , random # goal is multi tasking with the GUI not freezing before loop completed # which is being achieved here ! works in py 3.7 of 2018 def _asyncio_thread(async_loop): async_loop.run_until_complete(do_urls()) def do_work(async_loop): """ Button-Event-Handler starting stuff """ threading.Thread(target=_asyncio_thread, args=(async_loop,)).start() async def one_url(url): """ One task. """ global root sec = random.randint(1, 8) root.update() # more often await asyncio.sleep(sec ) return 'url: {} --- sec: {}'.format(url, sec) async def do_urls(): """ Creating and starting 10 tasks. """ tasks = [one_url(url) for url in range(10)] completed, pending = await asyncio.wait(tasks) results = [task.result() for task in completed] print('\n'.join(results)) def do_notfreeze(): messagebox.showinfo(message='see, Tkinter is still responsive') if __name__ == '__main__': global root async_loop = asyncio.get_event_loop() # all in this loop root = Tk() Button(master=root, text='do work', command= lambda:do_work( async_loop )).pack() Button(master=root, text='Frozen?', command= do_notfreeze ).pack() root.update() #async_loop.run_forever() # <---- uncomment, then it won"t work anymore root.mainloop() # how to replace ? # To do everything in the main thread, # one can replace 'root.mainloop' with loop.run_forever (in the main thread) # and repeated root.update calls.