From ganesh1pal at gmail.com Thu Sep 1 02:37:24 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Thu, 1 Sep 2016 12:07:24 +0530 Subject: C Python extension to export an Function Message-ID: Hi Team, Iam on python 2.7 and Linux. Iam pretty new to C Python extension , I was able to export few simple modules to python and it look like the cool thing to do , but Iam stuck for with a problem now , Iam not able to figure out how to export fun_addr_from_addr() to Python. I would need some suggestion on how to develop a C Python API for the below piece of code. 1. The end goal is to export fun_addr_from_addr(baddr, *baddr) to Python. Perhaps by creating a python wrapper for fun_bh_toblkoff() would help me ? Here is the sample example code. fun_toblkoff(dda_locn_t *locn, struct ifs_baddr *baddr, int *poff, int *psize) { if (dda_locnparm_get(locn) != OK) return FAIL; /* fill in baddr */ *baddr = dda_index_to_baddr(locn->idx); if (locn->flags & DLFLAG) locn->xoff = fun_addr_from_addr(baddr, *baddr); *poff = 0; *psize = _BSIZE; return OK; } So the primary challenge when writing a wrapper for a single function is figuring out how to get the arguments from Python form to C form, and how to get the result back to Python form. Regards, Ganesh From greg.ewing at canterbury.ac.nz Thu Sep 1 02:59:53 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2016 18:59:53 +1200 Subject: [OT] Altair In-Reply-To: References: <20160830070154.5cb89421@imp> <20160830115215.78a9ec7f@imp> Message-ID: Christopher Reimer wrote: > The first time I came across a paper tape reader when I > visited the university as a teenager in 1984. A CNC machine read the paper > tape to drill six holes in a piece of metal. I think that would have just been called NC (Numerical Control). CNC (Computer Numerical Control) is where a computer drives the machine directly. -- Greg From dieter at handshake.de Thu Sep 1 03:02:16 2016 From: dieter at handshake.de (dieter) Date: Thu, 01 Sep 2016 09:02:16 +0200 Subject: C Python extension to export an Function References: Message-ID: <87r394p0g7.fsf@handshake.de> Ganesh Pal writes: > Iam pretty new to C Python extension , I was able to export few simple > modules to python and it look like the cool thing to do ... Maybe, it is a good idea to have a look at "cython". "cython" is a compiler. It translates Python code enhanced with special annotations into C. The annotations mostly tell the compiler that something ("object", "method", "function", ...) should be at "C" rather than "Python" level, thus avoiding much of Python's overhead and allows to do things possible in "C" but not in "Python". Developing safe "C" extensions for Python is difficult. You need some quite deep understanding of the Python-C interface and must be very careful to observe all requirements (especially those related to proper reference management). Developing "C" extensions with "cython" is much easier as "cython" hides many of the complexities and takes care of most requirements. From greg.ewing at canterbury.ac.nz Thu Sep 1 03:06:37 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2016 19:06:37 +1200 Subject: [OT] Altair In-Reply-To: References: <20160830070154.5cb89421@imp> <20160830115215.78a9ec7f@imp> Message-ID: Grant Edwards wrote: > The file containing the list of coordinates generated by a CAD program > for holes in a circuit board is still often referred to as a "drill > tape". Yep, and we talk about "core" memory, use a "tape archive" program to produce compressed files, and have "drives" with no moving parts. Terminological fossils abound! (When I first heard the term "core" used to refer to RAM, I thought it just meant that it was a central part of the machine... until I realised it was actually talking about those little magnetic doughnuts!) (And I suppose a "core dump" is what would happen if any of the fragile little wires broke...) -- Greg From greg.ewing at canterbury.ac.nz Thu Sep 1 03:12:34 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2016 19:12:34 +1200 Subject: What's the best way to minimize the need of run time checks? In-Reply-To: References: Message-ID: Chris Angelico wrote: > You might have won the 100m dash, except that we couldn't verify your > velocity of locomotion without a... run time check. Badumtish. All is not lost. You just need to devise a type system capable of proving that his time is faster than any other runner in all possible races. -- Greg From rosuav at gmail.com Thu Sep 1 03:20:32 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Sep 2016 17:20:32 +1000 Subject: What's the best way to minimize the need of run time checks? In-Reply-To: References: Message-ID: On Thu, Sep 1, 2016 at 5:12 PM, Gregory Ewing wrote: > Chris Angelico wrote: > >> You might have won the 100m dash, except that we couldn't verify your >> velocity of locomotion without a... run time check. Badumtish. > > > All is not lost. You just need to devise a type system > capable of proving that his time is faster than any > other runner in all possible races. Wouldn't that be rather racist? Or maybe racy. I'm not sure. ChrisA From greg.ewing at canterbury.ac.nz Thu Sep 1 03:24:11 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2016 19:24:11 +1200 Subject: The Joys Of Data-Driven Programming In-Reply-To: <9d167ff0-455c-4c2e-96a4-2152cf25172d@googlegroups.com> References: <239aa219-4cd6-4c67-af11-21b2f655c644@googlegroups.com> <87y43uadke.fsf@elektro.pacujo.net> <79bd604d-f42a-44de-81fc-cd549d81fbb3@googlegroups.com> <8737lzammr.fsf@elektro.pacujo.net> <16f15ed9-65d2-4e4f-b2cd-1f59d4a15921@googlegroups.com> <19e40e2c-4e9e-4349-b704-35ff2aee338f@googlegroups.com> <87fupy8aqf.fsf@elektro.pacujo.net> <9d167ff0-455c-4c2e-96a4-2152cf25172d@googlegroups.com> Message-ID: Paul Moore wrote: > Is there any "make replacement" > out there that focuses more on named sets of actions (maybe with > prerequisite/successor type interdependencies), and less on building file > dependency graphs? Possibly Gradle might qualify. I only have a hazy understanding of it (basically just what I was forced to learn for Minecraft modding) but it seems to be based on "tasks" that can have prerequisites. This seems to work okay in the context of Java, where the usual practice seems to be to throw all your source files at the compiler and let it churn away, rather than try to figure out exactly which files need compiling -- which is hard to do for Java based on timestamps alone, and since the compiler is pretty fast, probably not worth the effort. -- Greg From yuri.abzyanov at gmail.com Thu Sep 1 06:59:00 2016 From: yuri.abzyanov at gmail.com (juraseg) Date: Thu, 1 Sep 2016 03:59:00 -0700 (PDT) Subject: Issues with "twistd" in Twisted 16.4.0 Message-ID: <3d55764e-6573-4dc5-bf13-96d8e8a6e8a2@googlegroups.com> Hi all I couldn't find Twisted-specific group, so posting here. Recently Twisted 16.4.0 got released. Yesterday I've tried to upgrade it for my apps and got an error. I've created simple example, which demonstrates it. File service.tac: ---------------------------------------- # You can run this .tac file directly with: # twistd -ny service.tac import os from twisted.application import service, internet import mymodule application = service.Application("Demo application") ---------------------------------------- File mymodule.py: ---------------------------------------- def myfunction(asd): """ Stub function """ ---------------------------------------- If you try to run it with twistd -y service.tac you'll get an error: >>> Failed to load application: No module named mymodule The errors comes down to this: twistd script does not add current working directory to python path, so it fails to import any packages/modules from it. It works just fine on previous version (Twisted 16.3.2). The strange thing here is that it was working before just fine, and I did not find anything related to this in release notes (http://labs.twistedmatrix.com/2016/08/twisted-1640-released.html), except that twistd now is a Setuptools console script (which I honestly don't know how can affect python path). Any ideas? From yuri.abzyanov at gmail.com Thu Sep 1 07:00:38 2016 From: yuri.abzyanov at gmail.com (juraseg) Date: Thu, 1 Sep 2016 04:00:38 -0700 (PDT) Subject: Issues with "twistd" in Twisted 16.4.0 In-Reply-To: <3d55764e-6573-4dc5-bf13-96d8e8a6e8a2@googlegroups.com> References: <3d55764e-6573-4dc5-bf13-96d8e8a6e8a2@googlegroups.com> Message-ID: <993d94bf-6b35-42bf-b6d3-bde3e6cd444f@googlegroups.com> Also, I've tried to find anything in Twisted bug tracker, but I can't find my way in there. From ganesh1pal at gmail.com Thu Sep 1 08:30:53 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Thu, 1 Sep 2016 18:00:53 +0530 Subject: C Python extension to export an Function In-Reply-To: <87r394p0g7.fsf@handshake.de> References: <87r394p0g7.fsf@handshake.de> Message-ID: On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: > Ganesh Pal writes: > > > Iam pretty new to C Python extension , I was able to export few simple > > modules to python and it look like the cool thing to do ... > > Maybe, it is a good idea to have a look at "cython". > > "cython" is a compiler. It translates Python code enhanced with > special annotations into C. The annotations mostly tell the compiler > that something ("object", "method", "function", ...) should be at "C" > rather than "Python" level, thus avoiding much of Python's overhead > and allows to do things possible in "C" but not in "Python". > > > Developing safe "C" extensions for Python is difficult. You > need some quite deep understanding of the Python-C interface > and must be very careful to observe all requirements (especially > those related to proper reference management). > > Developing "C" extensions with "cython" is much easier as > "cython" hides many of the complexities and takes care of most > requirements. > Dear Dieter , Really appreciate the reply and your suggestion on trying to use "cython" , but my whole idea of using "C" extension is to regular C codes . We have bunch of C code that's already available and C -Python seems to suit me better Regards, Ganesh From stefan_ml at behnel.de Thu Sep 1 09:02:42 2016 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 1 Sep 2016 15:02:42 +0200 Subject: C Python extension to export an Function In-Reply-To: References: <87r394p0g7.fsf@handshake.de> Message-ID: Ganesh Pal schrieb am 01.09.2016 um 14:30: > On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: >> Ganesh Pal writes: >>> Iam pretty new to C Python extension , I was able to export few simple >>> modules to python and it look like the cool thing to do ... >> >> Maybe, it is a good idea to have a look at "cython". >> >> "cython" is a compiler. It translates Python code enhanced with >> special annotations into C. The annotations mostly tell the compiler >> that something ("object", "method", "function", ...) should be at "C" >> rather than "Python" level, thus avoiding much of Python's overhead >> and allows to do things possible in "C" but not in "Python". >> >> Developing safe "C" extensions for Python is difficult. You >> need some quite deep understanding of the Python-C interface >> and must be very careful to observe all requirements (especially >> those related to proper reference management). >> >> Developing "C" extensions with "cython" is much easier as >> "cython" hides many of the complexities and takes care of most >> requirements. > > Really appreciate the reply and your suggestion on trying to use "cython" > , but my whole idea of using "C" extension is to regular C codes . We > have bunch of C code that's already available and C -Python seems to suit > me better >From your response it's not obvious whether you are aware that Cython also makes it substantially easier to *interface* CPython with external C code, in the same way that it makes it easy (but not necessary) to *avoid* writing C in the first place. So I thought I'd just mention that this is not a reason to rule it out as an excellent option. Stefan From auriocus at gmx.de Thu Sep 1 09:12:02 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 1 Sep 2016 15:12:02 +0200 Subject: C Python extension to export an Function In-Reply-To: References: <87r394p0g7.fsf@handshake.de> Message-ID: Am 01.09.16 um 14:30 schrieb Ganesh Pal: > On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: > >> Ganesh Pal writes: >> >>> Iam pretty new to C Python extension , I was able to export few simple >>> modules to python and it look like the cool thing to do ... >> >> Maybe, it is a good idea to have a look at "cython". >> >> "cython" is a compiler. It translates Python code enhanced with >> special annotations into C. The annotations mostly tell the compiler >> that something ("object", "method", "function", ...) should be at "C" >> rather than "Python" level, thus avoiding much of Python's overhead >> and allows to do things possible in "C" but not in "Python". >> >> >> Developing safe "C" extensions for Python is difficult. You >> need some quite deep understanding of the Python-C interface >> and must be very careful to observe all requirements (especially >> those related to proper reference management). >> >> Developing "C" extensions with "cython" is much easier as >> "cython" hides many of the complexities and takes care of most >> requirements. >> > > Dear Dieter , > > Really appreciate the reply and your suggestion on trying to use "cython" > , but my whole idea of using "C" extension is to regular C codes . We > have bunch of C code that's already available and C -Python seems to suit > me better Yet another option is to try SWIG. SWIG is a special compiler, you feed C header files which declare your functions, and it writes the wrapper code for you. In simple cases (standa data types like int, float, string,...), it might be enough. In more advanced cases, you can add your wrappers as "typemaps". Christian From kevinjacobconway at gmail.com Thu Sep 1 09:17:54 2016 From: kevinjacobconway at gmail.com (Kevin Conway) Date: Thu, 01 Sep 2016 13:17:54 +0000 Subject: Issues with "twistd" in Twisted 16.4.0 In-Reply-To: <993d94bf-6b35-42bf-b6d3-bde3e6cd444f@googlegroups.com> References: <3d55764e-6573-4dc5-bf13-96d8e8a6e8a2@googlegroups.com> <993d94bf-6b35-42bf-b6d3-bde3e6cd444f@googlegroups.com> Message-ID: Hi, you might not get much of an answer for this on the Python mailing list. I suggest sending your question to the Twisted mailing list instead: https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python. On Thu, Sep 1, 2016 at 7:12 AM juraseg wrote: > Also, I've tried to find anything in Twisted bug tracker, but I can't find > my way in there. > -- > https://mail.python.org/mailman/listinfo/python-list > From yuri_abzyanov at fastmail.fm Thu Sep 1 09:34:16 2016 From: yuri_abzyanov at fastmail.fm (Yuri) Date: Thu, 1 Sep 2016 20:34:16 +0700 Subject: Issues with "twistd" in Twisted 16.4.0 In-Reply-To: References: <3d55764e-6573-4dc5-bf13-96d8e8a6e8a2@googlegroups.com> <993d94bf-6b35-42bf-b6d3-bde3e6cd444f@googlegroups.com> Message-ID: <57C82E58.7020608@fastmail.fm> On 01/09/16 20:17, Kevin Conway wrote: > Hi, you might not get much of an answer for this on the Python mailing > list. I suggest sending your question to the Twisted mailing list instead: > https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python. > > On Thu, Sep 1, 2016 at 7:12 AM juraseg wrote: > >> Also, I've tried to find anything in Twisted bug tracker, but I can't find >> my way in there. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> Thanks! I'll try there From yuri.abzyanov at gmail.com Thu Sep 1 09:34:16 2016 From: yuri.abzyanov at gmail.com (Yuri) Date: Thu, 1 Sep 2016 20:34:16 +0700 Subject: Issues with "twistd" in Twisted 16.4.0 In-Reply-To: References: <3d55764e-6573-4dc5-bf13-96d8e8a6e8a2@googlegroups.com> <993d94bf-6b35-42bf-b6d3-bde3e6cd444f@googlegroups.com> Message-ID: <57C82E58.7020608@fastmail.fm> On 01/09/16 20:17, Kevin Conway wrote: > Hi, you might not get much of an answer for this on the Python mailing > list. I suggest sending your question to the Twisted mailing list instead: > https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python. > > On Thu, Sep 1, 2016 at 7:12 AM juraseg wrote: > >> Also, I've tried to find anything in Twisted bug tracker, but I can't find >> my way in there. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> Thanks! I'll try there From ganesh1pal at gmail.com Thu Sep 1 11:24:27 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Thu, 1 Sep 2016 20:54:27 +0530 Subject: C Python extension to export an Function In-Reply-To: References: <87r394p0g7.fsf@handshake.de> Message-ID: Thanks stefan and Gollwitzer , good to know there are many ways to do this i.e via cython or SWIG but the C/Python API is probably the most widely used method - not for it?s simplicity but for the fact that you can manipulate python objects in your C code. I want to use C/Python API On Thu, Sep 1, 2016 at 6:32 PM, Stefan Behnel wrote: > Ganesh Pal schrieb am 01.09.2016 um 14:30: > > On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: > >> Ganesh Pal writes: > >>> Iam pretty new to C Python extension , I was able to export few simple > >>> modules to python and it look like the cool thing to do ... > >> > >> Maybe, it is a good idea to have a look at "cython". > >> > >> "cython" is a compiler. It translates Python code enhanced with > >> special annotations into C. The annotations mostly tell the compiler > >> that something ("object", "method", "function", ...) should be at "C" > >> rather than "Python" level, thus avoiding much of Python's overhead > >> and allows to do things possible in "C" but not in "Python". > >> > >> Developing safe "C" extensions for Python is difficult. You > >> need some quite deep understanding of the Python-C interface > >> and must be very careful to observe all requirements (especially > >> those related to proper reference management). > >> > >> Developing "C" extensions with "cython" is much easier as > >> "cython" hides many of the complexities and takes care of most > >> requirements. > > > > Really appreciate the reply and your suggestion on trying to use > "cython" > > , but my whole idea of using "C" extension is to regular C codes . We > > have bunch of C code that's already available and C -Python seems to > suit > > me better > > From your response it's not obvious whether you are aware that Cython also > makes it substantially easier to *interface* CPython with external C code, > in the same way that it makes it easy (but not necessary) to *avoid* > writing C in the first place. So I thought I'd just mention that this is > not a reason to rule it out as an excellent option. > > Stefan > > > -- > https://mail.python.org/mailman/listinfo/python-list > From stefan_ml at behnel.de Thu Sep 1 11:58:36 2016 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 1 Sep 2016 17:58:36 +0200 Subject: C Python extension to export an Function In-Reply-To: References: <87r394p0g7.fsf@handshake.de> Message-ID: Ganesh Pal schrieb am 01.09.2016 um 17:24: > Thanks stefan and Gollwitzer , good to know there are many ways to do this > i.e via cython or SWIG but the C/Python API > is probably the most widely used method It certainly was, years ago, but I honestly doubt that it still is. I don't think there is still that much manually written C-API code out there that is actively maintained. Often enough, it's easier to rewrite the code in Cython at some point, than to keep maintaining it in C over years. Manually written C-API code is simply too difficult to maintain, and also too difficult to get right in the first place. There are just too many ways to introduce reference leaks, crashes and long standing unnoticed bugs (believe me, I know what I'm talking about). Even experienced CPython core devs still make mistakes here from time to time. > - not for it?s simplicity but for the fact that you can manipulate python > objects in your C code. Neither SWIG nor Cython prevent you from doing that, although you'd usually leave these things to Cython since it already generates faster code for many operations than you would (or could) write by hand. Stefan From pavel at schon.cz Thu Sep 1 12:41:41 2016 From: pavel at schon.cz (Pavel S) Date: Thu, 1 Sep 2016 09:41:41 -0700 (PDT) Subject: C Python extension to export an Function In-Reply-To: References: Message-ID: <52bd95bc-5e63-436e-9b1b-10257809f651@googlegroups.com> If you're familiar with C++, I recommend to have a look at Boost::Python. Sample program: #include #include void world() { std::cout << "hello world" << std::endl; } BOOST_PYTHON_MODULE( hello ) { using namespace ::boost::python; def( "world", &world ); } Usage: python -c "import hello; hello.world()" From auriocus at gmx.de Thu Sep 1 12:54:35 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 1 Sep 2016 18:54:35 +0200 Subject: C Python extension to export an Function In-Reply-To: References: <87r394p0g7.fsf@handshake.de> Message-ID: Hi Ganesh, Am 01.09.16 um 17:24 schrieb Ganesh Pal: > Thanks stefan and Gollwitzer , good to know there are many ways to do this > i.e via cython or SWIG but the C/Python API > is probably the most widely used method > - not for it?s simplicity but for the fact that you can manipulate python > objects in your C code. I'm not sure you understood what SWIG or Cython do - they are not circumventing the C/Python API, they merely write some of the code for you (as a C file). With both you can add manually written C code if the generated code is insufficient, and you can also ship the generated code, so that SWIG or Cython are not needed to rebuild the module, unless the API of your C coded functions changes. > I want to use C/Python API You may have good reasons to do it manually anyway, in this case look at the PyArg_ParseTuple and Py_BuildValue functions documented here https://docs.python.org/2/c-api/arg.html Christian From tjreedy at udel.edu Thu Sep 1 19:19:07 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 1 Sep 2016 19:19:07 -0400 Subject: Python 3 at Facebook Message-ID: https://www.youtube.com/watch?v=nRtp9NgtXiA Jason Fried explains how he helped advance 'modern Python', 3.x, from 'impossible' in 2013 to the 'default for new code' today. -- Terry Jan Reedy From dieter at handshake.de Fri Sep 2 02:52:21 2016 From: dieter at handshake.de (dieter) Date: Fri, 02 Sep 2016 08:52:21 +0200 Subject: C Python extension to export an Function References: <87r394p0g7.fsf@handshake.de> Message-ID: <87vayeztcq.fsf@handshake.de> Ganesh Pal writes: > ... > Thanks stefan and Gollwitzer , good to know there are many ways to do this > i.e via cython or SWIG but the C/Python API > is probably the most widely used method > - not for it?s simplicity but for the fact that you can manipulate python > objects in your C code. > > I want to use C/Python API I have used both Python's C API (to implement "dm.incrementalsearch") and (later) "cython" (to implement "dm.xmlsec.binding"). I can tell you from personal experience that the "cython" approach is much easier (and even more straight forward). From sumeet.k.sandhu at gmail.com Fri Sep 2 03:31:09 2016 From: sumeet.k.sandhu at gmail.com (Sumeet Sandhu) Date: Fri, 2 Sep 2016 00:31:09 -0700 (PDT) Subject: urllib2 timeout not working - stalls for an hour or so Message-ID: <4fec109a-5571-4c54-b89b-478d2e8e83f2@googlegroups.com> Hi, I use urllib2 to grab google.com webpages on my Mac over my Comcast home network. I see about 1 error for every 50 pages grabbed. Most exceptions are ssl.SSLError, very few are socket.error and urllib2.URLError. The problem is - after a first exception, urllib2 occasionally stalls for upto an hour (!), at either the urllib2.urlopen or response.read stages. Apparently the urllib2 and socket timeouts are not effective here - how do I fix this? ---------------- import urllib2 import socket from sys import exc_info as sysExc_info timeout = 2 socket.setdefaulttimeout(timeout) try : req = urllib2.Request(url,None,headers) response = urllib2.urlopen(req,timeout=timeout) html = response.read() except : e = sysExc_info()[0] open(logfile,'a').write('Exception: %s \n' % e) < code that follows this : after the first exception, I try again for a few tries > From __peter__ at web.de Fri Sep 2 09:04:29 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Sep 2016 15:04:29 +0200 Subject: urllib2 timeout not working - stalls for an hour or so References: <4fec109a-5571-4c54-b89b-478d2e8e83f2@googlegroups.com> Message-ID: Sumeet Sandhu wrote: > Hi, > > I use urllib2 to grab google.com webpages on my Mac over my Comcast home > network. > > I see about 1 error for every 50 pages grabbed. Most exceptions are > ssl.SSLError, very few are socket.error and urllib2.URLError. > > The problem is - after a first exception, urllib2 occasionally stalls for > upto an hour (!), at either the urllib2.urlopen or response.read stages. > > Apparently the urllib2 and socket timeouts are not effective here - how do > I fix this? > > ---------------- > import urllib2 > import socket > from sys import exc_info as sysExc_info > timeout = 2 > socket.setdefaulttimeout(timeout) > > try : > req = urllib2.Request(url,None,headers) > response = urllib2.urlopen(req,timeout=timeout) > html = response.read() > except : > e = sysExc_info()[0] > open(logfile,'a').write('Exception: %s \n' % e) > < code that follows this : after the first exception, I try again for a > few tries > I'd use separate try...except-s for response = urlopen() and response.read(). If the problem originates with read() you could try to replace it with select.select([response.fileno()], [], [], timeout) calls in a loop. From smith at smith.com Fri Sep 2 09:31:26 2016 From: smith at smith.com (Smith) Date: Fri, 2 Sep 2016 15:31:26 +0200 Subject: *args and **kwargs Message-ID: Hello to all, I'm trying to understand the concept of * args and ** kwarg with python3 But I can not understand why I returns the error message "SyntaxError: positional argument follows the keyword argument" when I insert values. You can help me? def start(data=None, *args, **kwargs): print('==== Arguments =======') print('data is: ', data) print('args is:', args) print('kwargs is:', kwargs) In [22]: def start(data=None, *args, **kwargs): print('==== Arguments =======') print('data is: ', data) print('args is:', args) print('kwargs is:', kwargs) In [23]: start(data="Fish",2,3,tox="tux") File "", line 1 start(data="Fish",2,3,tox="tux") ^ SyntaxError: positional argument follows keyword argument In [24]: start(data="Fish",tox="tux") ==== Arguments ======= data is: Fish args is: () kwargs is: {'tox': 'tux'} From ben+python at benfinney.id.au Fri Sep 2 09:44:50 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 02 Sep 2016 23:44:50 +1000 Subject: *args and **kwargs References: Message-ID: <85y43atnzh.fsf@benfinney.id.au> Smith writes: > I'm trying to understand the concept of * args and ** kwarg with > python3 Welcome. Your questions are fine in this forum; but you may also want to participate in our collaborative learning forum for Python beginners, . > But I can not understand why I returns the error message "SyntaxError: > positional argument follows the keyword argument" when I insert > values. It's fairly simple (though it may not be obvious!): > In [23]: start(data="Fish",2,3,tox="tux") > File "", line 1 > start(data="Fish",2,3,tox="tux") > ^ > SyntaxError: positional argument follows keyword argument Exactly. Note that this has nothing to do with how the function is defined; in the definition of the function, parameters are neither positional nor keyword. You name each of them, and you define an order for them; and neither of those makes any of them ?positional? or ?keyword?. Rather, ?positional argument? and ?keyword argument? are characteristics of the arguments you *supply* in a particular call to the function. You have specified four arguments, in this order: * A keyword argument, ?data="Fish"?. * A positional argument, ?2?. * A positional argument, ?3?. * A keyword argument, ?tox="tux"?. After specifying a keyword argument, you may not then specify any positional arguments. Hence the SyntaxError. -- \ ?I know that we can never get rid of religion ?. But that | `\ doesn?t mean I shouldn?t hate the lie of faith consistently and | _o__) without apology.? ?Paul Z. Myers, 2011-12-28 | Ben Finney From alister.ware at ntlworld.com Fri Sep 2 10:52:13 2016 From: alister.ware at ntlworld.com (alister) Date: Fri, 02 Sep 2016 14:52:13 GMT Subject: *args and **kwargs References: <85y43atnzh.fsf@benfinney.id.au> Message-ID: On Fri, 02 Sep 2016 23:44:50 +1000, Ben Finney wrote: > Smith writes: > >> I'm trying to understand the concept of * args and ** kwarg with >> python3 > > Welcome. Your questions are fine in this forum; but you may also want to > participate in our collaborative learning forum for Python beginners, > . > >> But I can not understand why I returns the error message "SyntaxError: >> positional argument follows the keyword argument" when I insert values. > > It's fairly simple (though it may not be obvious!): > >> In [23]: start(data="Fish",2,3,tox="tux") >> File "", line 1 >> start(data="Fish",2,3,tox="tux") >> ^ >> SyntaxError: positional argument follows keyword argument > > Exactly. > > Note that this has nothing to do with how the function is defined; in > the definition of the function, parameters are neither positional nor > keyword. You name each of them, and you define an order for them; and > neither of those makes any of them ?positional? or ?keyword?. > > Rather, ?positional argument? and ?keyword argument? are characteristics > of the arguments you *supply* in a particular call to the function. > > You have specified four arguments, in this order: > > * A keyword argument, ?data="Fish"?. > * A positional argument, ?2?. > * A positional argument, ?3?. > * A keyword argument, ?tox="tux"?. > > After specifying a keyword argument, you may not then specify any > positional arguments. Hence the SyntaxError. & the solution is to change the order of the definition def start( must_have,*args,**kwargs,data=none): -- Pretend to spank me -- I'm a pseudo-masochist! From random832 at fastmail.com Fri Sep 2 11:13:50 2016 From: random832 at fastmail.com (Random832) Date: Fri, 02 Sep 2016 11:13:50 -0400 Subject: Python slang In-Reply-To: <1470845983.1463573.691529097.0E053AB7@webmail.messagingengine.com> References: <5dd0922f-9a6d-6978-f785-8bbf351f17a5@stofanet.dk> <3d7fec12-8bea-4f26-afa1-f8516763bfc5@googlegroups.com> <1470845983.1463573.691529097.0E053AB7@webmail.messagingengine.com> Message-ID: <1472829230.1557175.713962057.33C0FF06@webmail.messagingengine.com> On Wed, Aug 10, 2016, at 12:19, Random832 wrote: > On Wed, Aug 10, 2016, at 07:59, Dennis Lee Bieber wrote: > > The use of = also has a long history... FORTRAN (where the > > comparison was .EQ.), BASIC (granted, K&K required assignment to > > start with the keyword LET, so the use of = was mainly a > > delimiter between target and expression being assigned). > > Visual Basic actually uses = for both assignment and comparison > *without* the Let keyword, it gets by on the fact that assignment is > not an expression. I just discovered something interesting. It turns out, Python 0.9.1 did the same thing (i.e. = for both assignment and comparison), with the ambiguity resolved by not allowing comparison operators generally in some expression contexts. >>> a, b = 1, 2 a < b Parsing error: file , line 1: a < b ^ Unhandled exception: run-time error: syntax error >>> # wait, what? I was doing this, originally, to test that comparisons >>> # still worked after a change to cmp_outcome to silence a compiler >>> # warning. I thought I'd somehow broken the parser. >>> (a < b) 1 >>> (a = b) 0 >>> if a = b: 1 # It doesn't always need parentheses ... else: 0 ... 0 >>> a, b (1, 2) >>> (a == b) # Turns out the modern operator doesn't even exist Parsing error: file , line 1: (a == b) ^ Unhandled exception: run-time error: syntax error >>> (a != b) # And now something for Barry Warsaw Parsing error: file , line 1: (a != b) ^ Unhandled exception: run-time error: syntax error >>> (a <> b) 1 It's gone in Python 1.0 - all of the modern behavior we're familiar with, except of course the boolean type, is fully present, with the continued existence [for a while] of the <> operator the only trace of days gone by. From marco.sulla.python.mailing at gmail.com Fri Sep 2 11:51:56 2016 From: marco.sulla.python.mailing at gmail.com (Marco Sulla) Date: Fri, 2 Sep 2016 17:51:56 +0200 Subject: Strange behaviour with numbers in exponential notation Message-ID: >>> 10**26 - 1 99999999999999999999999999 >>> 1e26 - 1 1e+26 Why? From smith at smith.it Fri Sep 2 12:05:29 2016 From: smith at smith.it (Smith) Date: Fri, 2 Sep 2016 18:05:29 +0200 Subject: *args and **kwargs In-Reply-To: References: <85y43atnzh.fsf@benfinney.id.au> Message-ID: <870e9519-8b5d-51f6-a787-a34b7abf43cb@smith.it> On 02/09/2016 16:52, alister wrote: > On Fri, 02 Sep 2016 23:44:50 +1000, Ben Finney wrote: > >> Smith writes: >> >>> I'm trying to understand the concept of * args and ** kwarg with >>> python3 >> >> Welcome. Your questions are fine in this forum; but you may also want to >> participate in our collaborative learning forum for Python beginners, >> . >> >>> But I can not understand why I returns the error message "SyntaxError: >>> positional argument follows the keyword argument" when I insert values. >> >> It's fairly simple (though it may not be obvious!): >> >>> In [23]: start(data="Fish",2,3,tox="tux") >>> File "", line 1 >>> start(data="Fish",2,3,tox="tux") >>> ^ >>> SyntaxError: positional argument follows keyword argument >> >> Exactly. >> >> Note that this has nothing to do with how the function is defined; in >> the definition of the function, parameters are neither positional nor >> keyword. You name each of them, and you define an order for them; and >> neither of those makes any of them ?positional? or ?keyword?. >> >> Rather, ?positional argument? and ?keyword argument? are characteristics >> of the arguments you *supply* in a particular call to the function. >> >> You have specified four arguments, in this order: >> >> * A keyword argument, ?data="Fish"?. >> * A positional argument, ?2?. >> * A positional argument, ?3?. >> * A keyword argument, ?tox="tux"?. >> >> After specifying a keyword argument, you may not then specify any >> positional arguments. Hence the SyntaxError. > > > & the solution is to change the order of the definition > > def start( must_have,*args,**kwargs,data=none): > > > thanks a lot From smith at smith.it Fri Sep 2 12:05:55 2016 From: smith at smith.it (Smith) Date: Fri, 2 Sep 2016 18:05:55 +0200 Subject: *args and **kwargs In-Reply-To: References: <85y43atnzh.fsf@benfinney.id.au> Message-ID: <39ed1aee-6c31-51be-6f7d-a4629bb630ab@smith.it> > > After specifying a keyword argument, you may not then specify any > positional arguments. Hence the SyntaxError. > thanks a lot From random832 at fastmail.com Fri Sep 2 12:17:19 2016 From: random832 at fastmail.com (Random832) Date: Fri, 02 Sep 2016 12:17:19 -0400 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: <1472833039.1571562.714045017.37EDB254@webmail.messagingengine.com> On Fri, Sep 2, 2016, at 11:51, Marco Sulla wrote: > >>> 10**26 - 1 > 99999999999999999999999999 > >>> 1e26 - 1 > 1e+26 > > > Why? Exponential notation creates floating point numbers, which have a limited amount of precision in binary. Specifically (on my system which, as most modern computers do, use IEEE double precision numbers for the python float type), 0x52b7d2dcc80cd400000000 is the value of 1e26, whereas. 0x52b7d2dcc80cd2e4000000 is the valoe of 10**26. Trying to add 1 gets it rounded off again, and the value is simply printed as 1e+26 by default because this is the shortest representation that gives the same number, even if "100000000000000004764729344.0" would be more accurate. From auriocus at gmx.de Fri Sep 2 12:18:08 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 2 Sep 2016 18:18:08 +0200 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: Am 02.09.16 um 17:51 schrieb Marco Sulla: >>>> 10**26 - 1 > 99999999999999999999999999 >>>> 1e26 - 1 > 1e+26 > 10**26 is computed with integer arithmetics. Python has bigints (i.e. as big as the memory allows) 1e26 denotes a *floating point number* Floating point has finite precision, in CPython it is a 64bit IEEE number. The largest exact integer there is 2**53 (~10^16), everything beyond cannot be accurately represented. Christian From sumeet.k.sandhu at gmail.com Fri Sep 2 12:38:38 2016 From: sumeet.k.sandhu at gmail.com (Sumeet Sandhu) Date: Fri, 2 Sep 2016 09:38:38 -0700 (PDT) Subject: urllib2 timeout not working - stalls for an hour or so In-Reply-To: References: <4fec109a-5571-4c54-b89b-478d2e8e83f2@googlegroups.com> Message-ID: On Friday, September 2, 2016 at 6:05:05 AM UTC-7, Peter Otten wrote: > Sumeet Sandhu wrote: > > > Hi, > > > > I use urllib2 to grab google.com webpages on my Mac over my Comcast home > > network. > > > > I see about 1 error for every 50 pages grabbed. Most exceptions are > > ssl.SSLError, very few are socket.error and urllib2.URLError. > > > > The problem is - after a first exception, urllib2 occasionally stalls for > > upto an hour (!), at either the urllib2.urlopen or response.read stages. > > > > Apparently the urllib2 and socket timeouts are not effective here - how do > > I fix this? > > > > ---------------- > > import urllib2 > > import socket > > from sys import exc_info as sysExc_info > > timeout = 2 > > socket.setdefaulttimeout(timeout) > > > > try : > > req = urllib2.Request(url,None,headers) > > response = urllib2.urlopen(req,timeout=timeout) > > html = response.read() > > except : > > e = sysExc_info()[0] > > open(logfile,'a').write('Exception: %s \n' % e) > > < code that follows this : after the first exception, I try again for a > > few tries > > > I'd use separate try...except-s for response = urlopen() and > response.read(). If the problem originates with read() you could try to > replace it with select.select([response.fileno()], [], [], timeout) calls in > a loop. thanks Peter. I will try this. However, I suspect Comcast is rate limiting my home use. Is there a workaround for that? What I really need is to somehow monitor the full url-read loop and break it if Comcast is stalling me too long... From marco.sulla.python.mailing at gmail.com Fri Sep 2 13:24:46 2016 From: marco.sulla.python.mailing at gmail.com (Marco Sulla) Date: Fri, 2 Sep 2016 19:24:46 +0200 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: Excuse me, I forgot to include the python list mail addess. I repost the mail. On Fri, Sep 2, 2016 at 6:18 PM, Christian Gollwitzer wrote: > 1e26 denotes a *floating point number* Floating point has finite precision, > in CPython it is a 64bit IEEE number. The largest exact integer there is > 2**53 (~10^16), everything beyond cannot be accurately represented. I see. So python float type is the IEEE 754 double. Why is it not automatically converted to long double? And I want to add to my original question: indeed I read from the docs: https://docs.python.org/3/reference/lexical_analysis.html#floating-point-literals that float has an 'exponentfloat' syntax. Why integers does not have an equivalent syntax? It's not too difficult to lexically distinguish between a integer and a float written in exponential notation, I think. From random832 at fastmail.com Fri Sep 2 13:29:45 2016 From: random832 at fastmail.com (Random832) Date: Fri, 02 Sep 2016 13:29:45 -0400 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: <1472833039.1571562.714045017.37EDB254@webmail.messagingengine.com> Message-ID: <1472837385.1586569.714120001.0AF1EE3B@webmail.messagingengine.com> On Fri, Sep 2, 2016, at 13:02, Marco Sulla wrote: > On Fri, Sep 2, 2016 at 6:17 PM, Random832 wrote: > > Trying to add 1 gets it rounded off again, and the value is simply > > printed as 1e+26 by default because this is the shortest representation > > that gives the same number, even if "100000000000000004764729344.0" > > would be more accurate. > > It seems it's not simply a representation. It seems the numbers are just > equal: Yes. The number 1e+16 is represented as a floating point number equal to 100000000000000004764729344. Then when you add 1 to it, the 1 gets rounded off and you get a floating point number that is still equal to 100000000000000004764729344: >>> a = float(10**16) >>> int(a) 100000000000000004764729344 >>> b = a + 1 >>> int(b) 100000000000000004764729344 You switched examples. 10**22 is the largest power of 10 that can be represented exactly, but 10**15+1 is te largest "power of 10 plus one" that can be represented exactly. Float can only represent numbers whose binary representation contains 53 bits or less from the first to the last "1". >>> '{:b}'.format(10**15) '11100011010111111010100100110001101000000000000000' # 35 bits before the run of zeros >>> '{:b}'.format(10**16) '100011100001101111001001101111110000010000000000000000' # 38 bits, works fine in float >>> '{:b}'.format(10**15+1) '11100011010111111010100100110001101000000000000001' # 50 bits, barely fits in a float >>> '{:b}'.format(10**16+1) '100011100001101111001001101111110000010000000000000001' # 54 bits, too many. Anything else gets rounded off. It's the same as if you tried to add a tiny number to 1. >>> 1+1e-15 == 1 False >>> 1+1e-16 == 1 True > This is really weird. I tried to do it just in C: You should be using double instead of long double; double is the C equivalent of the Python float type. From auriocus at gmx.de Fri Sep 2 15:12:18 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 2 Sep 2016 21:12:18 +0200 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: Am 02.09.16 um 19:24 schrieb Marco Sulla: > Excuse me, I forgot to include the python list mail addess. I repost the mail. > > > > On Fri, Sep 2, 2016 at 6:18 PM, Christian Gollwitzer wrote: >> 1e26 denotes a *floating point number* Floating point has finite precision, >> in CPython it is a 64bit IEEE number. The largest exact integer there is >> 2**53 (~10^16), everything beyond cannot be accurately represented. > > I see. So python float type is the IEEE 754 double. Why is it not > automatically converted to long double? Because Python has no long double type? And "long double" (assuming 80bit or 128bit) does not solve the problem, it just shifts the bound to some higher arbitrary limit. In fact, it is impossible to make a bigfloat class which acts like a float, but always carries enough bits. A simple counterexample is 0.3, a periodic fraction in binary. Or, if you include arbitrary precision fractions, then e.g. sqrt(2). > And I want to add to my original question: indeed I read from the docs: > https://docs.python.org/3/reference/lexical_analysis.html#floating-point-literals > that float has an 'exponentfloat' syntax. Why integers does not have > an equivalent syntax? Tradition? All languages I know of treat a number with an exponent as floating point. Christian From marko at pacujo.net Fri Sep 2 15:30:49 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 02 Sep 2016 22:30:49 +0300 Subject: Strange behaviour with numbers in exponential notation References: Message-ID: <871t12w13q.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 02.09.16 um 19:24 schrieb Marco Sulla: >> float has an 'exponentfloat' syntax. Why integers does not have an >> equivalent syntax? > > Tradition? All languages I know of treat a number with an exponent as > floating point. Approximate real numbers are mostly needed by scientific applications, and floats do the job marvelously. Unlike many programming languages, Python has adopted big integers, which have immediate applications in cryptography. Those big integers hardly ever involve powers of ten, however, and they cannot be approximated. So the scientific notation doesn't offer any notational advantage. Marko From random832 at fastmail.com Fri Sep 2 15:47:12 2016 From: random832 at fastmail.com (Random832) Date: Fri, 02 Sep 2016 15:47:12 -0400 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: <1472845632.1614796.714234753.352F58AF@webmail.messagingengine.com> On Fri, Sep 2, 2016, at 15:12, Christian Gollwitzer wrote: > Tradition? All languages I know of treat a number with an exponent as > floating point. Scheme does allow you to give integers (and rationals) in decimal and/or exponential notation with the "#e" prefix. From python at mrabarnett.plus.com Fri Sep 2 16:45:25 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 2 Sep 2016 21:45:25 +0100 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: <1472845632.1614796.714234753.352F58AF@webmail.messagingengine.com> References: <1472845632.1614796.714234753.352F58AF@webmail.messagingengine.com> Message-ID: On 2016-09-02 20:47, Random832 wrote: > On Fri, Sep 2, 2016, at 15:12, Christian Gollwitzer wrote: >> Tradition? All languages I know of treat a number with an exponent as >> floating point. > > Scheme does allow you to give integers (and rationals) in decimal and/or > exponential notation with the "#e" prefix. > In Ada, integers can have an exponent, provided that it's non-negative. From marco.sulla.python.mailing at gmail.com Fri Sep 2 20:31:50 2016 From: marco.sulla.python.mailing at gmail.com (Marco Sulla) Date: Sat, 3 Sep 2016 02:31:50 +0200 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: On 2 September 2016 at 21:12, Christian Gollwitzer wrote: > Am 02.09.16 um 19:24 schrieb Marco Sulla: > Because Python has no long double type? Python no of course, but C++ yes, and CPython is written in C++. However, I think the answer is here: https://en.wikipedia.org/wiki/Long_double#Implementations Briefly, long double is not implemented in all hardwares, or its implementation is really different from machine to machine. I suppose this is why long double is not supported. From marco.sulla.python.mailing at gmail.com Fri Sep 2 20:33:38 2016 From: marco.sulla.python.mailing at gmail.com (Marco Sulla) Date: Sat, 3 Sep 2016 02:33:38 +0200 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: On 3 September 2016 at 02:31, Marco Sulla wrote: > Python no of course, but C++ yes, and CPython is written in C++. Sorry, I just founded CppPython... From greg.ewing at canterbury.ac.nz Fri Sep 2 21:32:57 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 03 Sep 2016 13:32:57 +1200 Subject: *args and **kwargs In-Reply-To: References: <85y43atnzh.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > in the definition of the function, parameters are neither positional nor > keyword. In Python 3 that's not quite true -- it's possible to define "keyword only" parameters that can't be passed positionally. However, it's true that any of the "ordinary" parameters (ones that aren't keyword-only) can be specified either positionally or by keyword in a call. -- Greg From denis.akhiyarov at gmail.com Fri Sep 2 22:34:23 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Fri, 2 Sep 2016 19:34:23 -0700 (PDT) Subject: Pythons for .Net In-Reply-To: <57959574$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <57959574$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0addc29e-b1c0-408c-bd61-96ca8576565d@googlegroups.com> On Sunday, July 24, 2016 at 11:30:09 PM UTC-5, Steven D'Aprano wrote: > Yes, I said Pythons plural :-) > > For those wanting to use Python on .Net or Mono, there is some good news. > > Firstly, the venerable old "Python for .Net" project is still alive, and now > supports up to Python 3.5 on .Net or Mono. PythonNet, as this is known, > integrates the regular CPython interpreter with .Net or Mono. > > Secondly, we can also expect that IronPython will have a new lease of life. > Continuing on the work of their predecessor, Jeff Hardy, the IronPython > project now has two tech leads who will carry it forward: Alex Earl and > Benedikt Eggers. > > https://thelasttechie.com/2016/07/24/its-back-python-for-net/ > > > IronPython is a reimplementation of Python, written in C# as managed code > for .Net. It doesn't use a GIL, and is sometimes considered a little faster > than CPython, so this is good news for the Python ecosystem. > > IronPython: > http://ironpython.net/ > > Python for .Net: > https://github.com/pythonnet/pythonnet > http://pythonnet.github.io/ > https://pypi.python.org/pypi/pythonnet > > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. Hello Steven, I'm one of the contributors to pythonnet. We strive for compatibility with IronPython, but also have a simplified embedding interface and support Python 3 + C-Extensions such as numpy, scipy, sklearn. If anyone is interested in learning pythonnet, then try it out from PYPI or github and use this tutorial: https://pythonnet.github.io/readme.html There is also a mailing list and a tag on stackoverflow: https://mail.python.org/mailman/listinfo/pythondotnet http://stackoverflow.com/questions/tagged/python.net Finally if anyone can contact Christian Heimes (Python Core Developer), then please ask him to reply on request to update the license to MIT: https://github.com/pythonnet/pythonnet/issues/234 He is the only contributor that prevents updating to MIT license. From auriocus at gmx.de Sat Sep 3 02:42:14 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 3 Sep 2016 08:42:14 +0200 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: Am 03.09.16 um 02:31 schrieb Marco Sulla: > On 2 September 2016 at 21:12, Christian Gollwitzer wrote: >> Am 02.09.16 um 19:24 schrieb Marco Sulla: >> Because Python has no long double type? > > Python no of course, but C++ yes, and CPython is written in C++. > However, I think the answer is here: > https://en.wikipedia.org/wiki/Long_double#Implementations > Briefly, long double is not implemented in all hardwares, or its > implementation is really different from machine to machine. Yes - 64 bit IEEE floats are today the universally available floating point data type across different machines. If you want arbitrary precision floats, you can have them in Python, too: https://pypi.python.org/pypi/bigfloat/ Of course this is a "software emulation" and is consequently slower then hardware floats. It does not, howver take away the principle problem that you must set the precision from the beginning of your calculation. Christian From vek.m1234 at gmail.com Sat Sep 3 07:55:23 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sat, 03 Sep 2016 17:25:23 +0530 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? Message-ID: https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm Wanted to know if the above link idea, had been implemented and if there's a module that accepts a pattern like 'cap' and give you all the instances of unicode 'CAP' characters. ? \bigcap ? \sqcap ? \cap ? \capricornus ? \succapprox ? \precapprox (above's from tex) I found two useful modules in this regard: unicode_tex, unicodedata but unicodedata is a builtin which does not do globs, regexs - so it's kind of limiting in nature. Would be nice if you could search html/xml character entity references as well. From vek.m1234 at gmail.com Sat Sep 3 07:55:23 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sat, 03 Sep 2016 17:25:23 +0530 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? Message-ID: https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm Wanted to know if the above link idea, had been implemented and if there's a module that accepts a pattern like 'cap' and give you all the instances of unicode 'CAP' characters. ? \bigcap ? \sqcap ? \cap ? \capricornus ? \succapprox ? \precapprox (above's from tex) I found two useful modules in this regard: unicode_tex, unicodedata but unicodedata is a builtin which does not do globs, regexs - so it's kind of limiting in nature. Would be nice if you could search html/xml character entity references as well. From steve+python at pearwood.info Sat Sep 3 21:51:55 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 04 Sep 2016 11:51:55 +1000 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> Message-ID: <57cb7e3c$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sun, 4 Sep 2016 06:47 am, Thomas 'PointedEars' Lahn wrote: > Your posting is lacking a real name in the ?From? header field. Thomas, if that is really your name, how do we know that: Thomas 'PointedEars' Lahn is a real name? Is sounds made up to me. I'm afraid that we're going to have to insist that you scan you birth certificate, drivers licence and other forms of ID and send them to us so that we can see proof that this is your real name. Please either comply, or give up your stupid and pointless obsession with trying to be the Internet Police for something that isn't even a real rule. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 3 21:53:06 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 04 Sep 2016 11:53:06 +1000 Subject: Pythons for .Net References: <57959574$0$1586$c3e8da3$5496439d@news.astraweb.com> <0addc29e-b1c0-408c-bd61-96ca8576565d@googlegroups.com> Message-ID: <57cb7e82$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sat, 3 Sep 2016 12:34 pm, Denis Akhiyarov wrote: > Finally if anyone can contact Christian Heimes (Python Core Developer), > then please ask him to reply on request to update the license to MIT: > > https://github.com/pythonnet/pythonnet/issues/234 > > He is the only contributor that prevents updating to MIT license. I have emailed him off-list. Thanks for the information on PythonNet, Denis. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sat Sep 3 22:19:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 Sep 2016 12:19:20 +1000 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: <57cb7e3c$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <2829361.aeNJFYEL58@PointedEars.de> <57cb7e3c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 4, 2016 at 11:51 AM, Steve D'Aprano wrote: > On Sun, 4 Sep 2016 06:47 am, Thomas 'PointedEars' Lahn wrote: > >> Your posting is lacking a real name in the ?From? header field. > > > Thomas, if that is really your name, how do we know that: > > Thomas 'PointedEars' Lahn > > is a real name? Is sounds made up to me. I'm afraid that we're going to have > to insist that you scan you birth certificate, drivers licence and other > forms of ID and send them to us so that we can see proof that this is your > real name. > > Please either comply, or give up your stupid and pointless obsession with > trying to be the Internet Police for something that isn't even a real rule. > His posts aren't making it across the news->list gateway any more. Killfile him and move on... ChrisA From steve+python at pearwood.info Sat Sep 3 22:49:03 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 04 Sep 2016 12:49:03 +1000 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> <57cb7e3c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57cb8ba0$0$1621$c3e8da3$5496439d@news.astraweb.com> On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: [...] >> Please either comply, or give up your stupid and pointless obsession with >> trying to be the Internet Police for something that isn't even a real >> rule. > > His posts aren't making it across the news->list gateway any more. > Killfile him and move on... But but but... I couldn't do that. https://www.xkcd.com/386/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sat Sep 3 22:54:50 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 Sep 2016 12:54:50 +1000 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: <57cb8ba0$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <2829361.aeNJFYEL58@PointedEars.de> <57cb7e3c$0$22142$c3e8da3$5496439d@news.astraweb.com> <57cb8ba0$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 4, 2016 at 12:49 PM, Steve D'Aprano wrote: > On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: > > [...] >>> Please either comply, or give up your stupid and pointless obsession with >>> trying to be the Internet Police for something that isn't even a real >>> rule. >> >> His posts aren't making it across the news->list gateway any more. >> Killfile him and move on... > > But but but... I couldn't do that. > > https://www.xkcd.com/386/ Ah, you got me. Can't force anyone to violate standards documents like RFCs and XKCDs. ChrisA who may or may not have recently pushed a commit to make something XKCD 859 compliant... From vek.m1234 at gmail.com Sun Sep 4 00:02:12 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sun, 04 Sep 2016 09:32:12 +0530 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> Message-ID: Thomas 'PointedEars' Lahn wrote: > Veek. M wrote: > >> https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm >> >> Wanted to know if the above link idea, > > ? which is 404-compliant; the Internet Archive does not have it either > ? > >> had been implemented > > Probably not. > >> and if there's a module that accepts a pattern like 'cap' and give >> you all the instances of unicode 'CAP' characters. > > I do not know any. > >> ? \bigcap >> ? \sqcap >> ? \cap >> ? \capricornus >> ? \succapprox >> ? \precapprox >> >> (above's from tex) >> >> I found two useful modules in this regard: unicode_tex, unicodedata >> but unicodedata is a builtin which does not do globs, regexs - so >> it's kind of limiting in nature. > > Quick hack: > > #-------------------------------------------------------------------- > from unicode_tex import unicode_to_tex_map > > for key, value \ > in filter(lambda item: "cap" in item[1], unicode_to_tex_map.items()): > print(key, value) > #-------------------------------------------------------------------- > > (Optimizations are welcome.) > > It is easy to come up with methods that take a globbing or a regular > expression (globbing expressions can be turned into regular > expressions easily) and returns, perhaps as a dictionary or list of > tuples, only the matching entries. > > Other than that I think you will have to turn the Unicode Character > Database (which is available via HTTP as one huge text file; see the > Python Tutorial on ?Internet Access? for how to get it dynamically) > into whatever form suits you for querying it. > >> Would be nice if you could search html/xml character entity >> references as well. > > For what purpose? > > Your posting is lacking a real name in the ?From? header field. > Ouch! Sorry for the bad link Thomas. The link is titled '[Python-ideas] Extend unicodedata with a name search' and I suspect this updated link data (http://code.activestate.com/lists/python-ideas/29504/) may work - if it doesn't you could google the title. I don't want to dump/replicate the existing Unicode data in module 'unicodedata'. Regarding purpose, well I need this for hexchat. I IRC a lot and often, I want to ask a question involving math symbols. I've written some python (included at the bottom) that translates: \help filter_word #into a list of symbols and names (serves as a memory jog). It also translates stuff like: A \cap B \epsilon C to A ? B ? C. but all this works with a subset of tex - it can't do complicated formula. I wanted to extend it further.. I don't think I shall be able to subscript integrals easily but I could make better use of the available unicode, which means making it more accessible (hence the pattern matching feature) - html/xml entities provide a new way of remembering stuff. --------------------------- Regarding the name (From field), my name *is* Veek.M though I tend to shorten it to Vek.M on Google (i think Veek was taken or some such thing). Just to be clear, my parents call me something closely related to Veek that is NOT Beek or Peek or Squeak or Sneak and my official name is something really weird. Identity theft being what it is, I probably am lying anyhow about all this, but it sounds funny so :p import hexchat import re, unicode_tex, unicodedata __module_name__ = 'Unicode' __module_version__ = '0.1' __module_description__ = 'Substitute \whatever with Unicode char in cmdline input' #re_repl = unicodedata.lookup('N-ARY UNION') def debug(*args): hexchat.prnt('#####{}#####'.format(*args)) def print_help(*args): hexchat.prnt('{}'.format(*args)) def send_message(word, word_eol, userdata): if not(word[0] == "65293"): return msg = hexchat.get_info('inputbox') if msg is None: return x = re.match(r'(^\\help)\s+(\w+)', msg) if x: filter = x.groups()[1] for key, value in unicode_tex.tex_to_unicode_map.items(): if filter in key: print_help(value + ' ' + key) hexchat.command("settext %s" % '') return tex_matches = re.findall(r'(\\\w+)', msg) for tex_word in tex_matches: repl = unicode_tex.tex_to_unicode_map.get(tex_word) if repl is None: repl = 'err' msg = re.sub(re.escape(tex_word), repl, msg) hexchat.command("settext %s" % msg) hexchat.hook_print('Key Press', send_message) From rustompmody at gmail.com Sun Sep 4 01:30:53 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 3 Sep 2016 22:30:53 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: Message-ID: On Saturday, September 3, 2016 at 5:25:48 PM UTC+5:30, Veek. M wrote: > https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm > > Wanted to know if the above link idea, had been implemented and if > there's a module that accepts a pattern like 'cap' and give you all the > instances of unicode 'CAP' characters. > ? \bigcap > ? \sqcap > ? \cap > ? \capricornus > ? \succapprox > ? \precapprox > > (above's from tex) > > I found two useful modules in this regard: unicode_tex, unicodedata > but unicodedata is a builtin which does not do globs, regexs - so it's > kind of limiting in nature. > > Would be nice if you could search html/xml character entity references > as well. [Not exactly an answer] I use a number of things for such 1. Google 2. Xah Lee?s excellent pages which often fit my brain better than wikipedia: http://xahlee.info/comp/unicode_index.html 3. emacs? function ucs-insert recently renamed to insert-char ie [In emacs] Type Alt-x insert-char After that some kind of TAB-globbing (case-insensitive) works I wont try with Cap (because the number of *CAPITAL* is in thousands!) eg alphaTAB gives nothing. However *alphaTAB gives a bunch. Narrow to "greek alpha"TAB and you get a bunch The fact that we should have a series of levels for char-input from most general and unergonomic (google) to most specific and ergonomic (special purpose keyboard) Ive tried to talk of as 7 levels near end of http://blog.languager.org/2015/01/unicode-and-universe.html From rustompmody at gmail.com Sun Sep 4 01:47:55 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 3 Sep 2016 22:47:55 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: <2829361.aeNJFYEL58@PointedEars.de> Message-ID: On Sunday, September 4, 2016 at 9:32:28 AM UTC+5:30, Veek. M wrote: > Regarding the name (From field), my name *is* Veek.M though I tend to > shorten it to Vek.M on Google (i think Veek was taken or some such > thing). Just to be clear, my parents call me something closely related > to Veek that is NOT Beek or Peek or Squeak or Sneak and my official name > is something really weird. Identity theft being what it is, I probably > am lying anyhow about all this, but it sounds funny so :p Please dont take the name-police bait. As far as I am concerned telling someone ?I dont like your name? is in the same bracket as ?I don?t like your religion/skin-color/gender/nationality/etc? Ie its highly offensive From jussi.piitulainen at helsinki.fi Sun Sep 4 02:02:20 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sun, 04 Sep 2016 09:02:20 +0300 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> <57cb7e3c$0$22142$c3e8da3$5496439d@news.astraweb.com> <57cb8ba0$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico writes: > On Sun, Sep 4, 2016 at 12:49 PM, Steve D'Aprano > wrote: >> On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: >> >> [...] >>>> Please either comply, or give up your stupid and pointless obsession with >>>> trying to be the Internet Police for something that isn't even a real >>>> rule. >>> >>> His posts aren't making it across the news->list gateway any more. >>> Killfile him and move on... >> >> But but but... I couldn't do that. >> >> https://www.xkcd.com/386/ > > Ah, you got me. Can't force anyone to violate standards documents like > RFCs and XKCDs. > > ChrisA > who may or may not have recently pushed a commit to make something > XKCD 859 compliant... (-: (You were baiting for that.) From rustompmody at gmail.com Sun Sep 4 03:25:13 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 4 Sep 2016 00:25:13 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: <2829361.aeNJFYEL58@PointedEars.de> Message-ID: <71e7f3d8-b0ae-4e0a-a8f0-5ceaab693037@googlegroups.com> On Sunday, September 4, 2016 at 11:18:07 AM UTC+5:30, Rustom Mody wrote: > On Sunday, September 4, 2016 at 9:32:28 AM UTC+5:30, Veek. M wrote: > > Regarding the name (From field), my name *is* Veek.M though I tend to > > shorten it to Vek.M on Google (i think Veek was taken or some such > > thing). Just to be clear, my parents call me something closely related > > to Veek that is NOT Beek or Peek or Squeak or Sneak and my official name > > is something really weird. Identity theft being what it is, I probably > > am lying anyhow about all this, but it sounds funny so :p > > Please dont take the name-police bait. > As far as I am concerned telling someone ?I dont like your name? is in the same > bracket as ?I don?t like your religion/skin-color/gender/nationality/etc? > Ie its highly offensive Sorry... That should have been just ?offensive? not ?highly offensive? Too much disorder in the world from people ratcheting up their expressions beyond appropriate levels. And since I am at it let me correct more precisely: Namism ? Thomas ?bogus-appelation? Lahn?s affliction ? lies between mildly amusing and mildly offensive as does racism/sexism/casteism/nationalism/etc Einstein?s ?Nationalism is an infantile disease; its the measles of mankind? should be applied to all such From nobody at nowhere.invalid Sun Sep 4 04:29:08 2016 From: nobody at nowhere.invalid (Nobody) Date: Sun, 04 Sep 2016 09:29:08 +0100 Subject: Strange behaviour with numbers in exponential notation References: Message-ID: On Fri, 02 Sep 2016 18:18:08 +0200, Christian Gollwitzer wrote: > 1e26 denotes a *floating point number* Floating point has finite > precision, in CPython it is a 64bit IEEE number. The largest exact > integer there is 2**53 (~10^16), everything beyond cannot be accurately > represented. Uh, that's wrong. All integers smaller than 2**53 can be represented exactly. Some, but not all, of the integers above 2**53 can be represented exactly. From framstag at rus.uni-stuttgart.de Sun Sep 4 04:53:47 2016 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Sun, 4 Sep 2016 08:53:47 +0000 (UTC) Subject: manually sorting images? Message-ID: I need to sort images (*.jpg), visually, not by file name. It looks, there is no standard UNIX tool for this job? So, I have to write one by myself, using Tkinter. Are there any high-level widgets which can help me, for example a file browser with thumbnails? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: horlacher at tik.uni-stuttgart.de Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From PointedEars at web.de Sun Sep 4 07:05:09 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 04 Sep 2016 13:05:09 +0200 Subject: manually sorting images? References: Message-ID: <8989264.nUPlyArG6x@PointedEars.de> Ulli Horlacher wrote: > I need to sort images (*.jpg), visually, not by file name. > It looks, there is no standard UNIX tool for this job? Depends. What are the sort keys? -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From steve+python at pearwood.info Sun Sep 4 07:32:47 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 04 Sep 2016 21:32:47 +1000 Subject: manually sorting images? References: Message-ID: <57cc0662$0$1600$c3e8da3$5496439d@news.astraweb.com> On Sun, 4 Sep 2016 06:53 pm, Ulli Horlacher wrote: > I need to sort images (*.jpg), visually, not by file name. I don't even understand this. What does it mean to sort images visually? Which comes first, a 400x500 image of a cat climbing a tree, or a 300x600 image of a toddler playing with a dog? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 4 08:02:47 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 04 Sep 2016 22:02:47 +1000 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> Message-ID: <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote: >> Regarding the name (From field), my name *is* Veek.M [?] > > Liar. *plonk* You have crossed a line now Thomas. That is absolutely uncalled for. You have absolutely no legitimate reason to believe that Veek is not his or her real name. You owe Veek an apology, and a promise to the entire community that you will not act in such a bigoted, racist manner again. -- Steve From steve+python at pearwood.info Sun Sep 4 08:20:01 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 04 Sep 2016 22:20:01 +1000 Subject: Why doesn't my finaliser run here? Message-ID: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> Here's a finaliser that runs: class Spam(object): def __new__(cls): instance = object.__new__(cls) print("instance created successfully") return instance def __del__(self): print("deleting", repr(self)) An example: py> s = Spam(); del s instance created successfully deleting <__main__.Spam object at 0xb7bf270c> Why doesn't __del__ run here? class Eggs(object): def __new__(cls): instance = object.__new__(cls) print("instance created successfully") return instance def __init__(self): print("self definitely exists:", self) raise Exception def __del__(self): print("deleting", repr(self)) And an example: py> e = Eggs() instance created successfully self definitely exists: <__main__.Eggs object at 0xb7bf21ec> Traceback (most recent call last): File "", line 1, in File "", line 8, in __init__ Exception py> -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ben+python at benfinney.id.au Sun Sep 4 08:37:53 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 04 Sep 2016 22:37:53 +1000 Subject: Why doesn't my finaliser run here? References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85bn03u9ge.fsf@benfinney.id.au> Steve D'Aprano writes: > Why doesn't __del__ run here? Short anser: because nothing has removed the reference to the instance. > class Eggs(object): > def __new__(cls): > instance = object.__new__(cls) > print("instance created successfully") > return instance > def __init__(self): > print("self definitely exists:", self) > raise Exception > def __del__(self): > print("deleting", repr(self)) This is a good example of why it helps to *never* call ?__init__? the ?constructor?. It isn't, because ?__init__? acts on an already-constructed instance. Hance, an exception raised from ?__init__? is not going to affect whether the instance exists. > And an example: > > > py> e = Eggs() > instance created successfully > self definitely exists: <__main__.Eggs object at 0xb7bf21ec> > Traceback (most recent call last): > File "", line 1, in > File "", line 8, in __init__ > Exception > py> Right. The instance is constructed successfully (by ?__new__?, the constructor). It will be bound to ?s?, creating a reference to the instance. The exception raised from the initialiser does not stop you from binding the instance to a name. That binding succeeds; the reference remains. Nothing has caused that reference to go away. -- \ ?I know that we can never get rid of religion ?. But that | `\ doesn?t mean I shouldn?t hate the lie of faith consistently and | _o__) without apology.? ?Paul Z. Myers, 2011-12-28 | Ben Finney From oscar.j.benjamin at gmail.com Sun Sep 4 08:58:11 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 4 Sep 2016 13:58:11 +0100 Subject: Why doesn't my finaliser run here? In-Reply-To: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4 Sep 2016 13:27, "Steve D'Aprano" wrote: > > Why doesn't __del__ run here? > > > class Eggs(object): > def __new__(cls): > instance = object.__new__(cls) > print("instance created successfully") > return instance > def __init__(self): > print("self definitely exists:", self) > raise Exception > def __del__(self): > print("deleting", repr(self)) > > > And an example: > > > py> e = Eggs() > instance created successfully > self definitely exists: <__main__.Eggs object at 0xb7bf21ec> > Traceback (most recent call last): > File "", line 1, in > File "", line 8, in __init__ > Exception Maybe the Exception traceback holds a reference to the object. Also try the example outside of interactive mode since that can hold references. -- Oscar From rosuav at gmail.com Sun Sep 4 09:01:10 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 Sep 2016 23:01:10 +1000 Subject: Why doesn't my finaliser run here? In-Reply-To: <85bn03u9ge.fsf@benfinney.id.au> References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> <85bn03u9ge.fsf@benfinney.id.au> Message-ID: On Sun, Sep 4, 2016 at 10:37 PM, Ben Finney wrote: >> And an example: >> >> >> py> e = Eggs() >> instance created successfully >> self definitely exists: <__main__.Eggs object at 0xb7bf21ec> >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 8, in __init__ >> Exception >> py> > > > Right. The instance is constructed successfully (by ?__new__?, the > constructor). It will be bound to ?s?, creating a reference to the > instance. > > The exception raised from the initialiser does not stop you from binding > the instance to a name. That binding succeeds; the reference remains. > Nothing has caused that reference to go away. Presumably you mean "bound to 'e'" here. But it isn't; the expression Eggs() raised an exception, so nothing got assigned anywhere. It doesn't depend on __new__ either: >>> class Eggs: ... def __init__(self): ... print("init:", self) ... raise Exception ... def __del__(self): ... print("del:", self) ... >>> e=Eggs() init: <__main__.Eggs object at 0x7ffa8fc97400> Traceback (most recent call last): File "", line 1, in File "", line 4, in __init__ Exception >>> e del: <__main__.Eggs object at 0x7ffa8fc97400> Traceback (most recent call last): File "", line 1, in NameError: name 'e' is not defined There's a reference here somewhere, though. My suspicion is it's in sys.exc_info / sys.last_traceback, which is why triggering another exception causes the object to be cleaned up. ChrisA From auriocus at gmx.de Sun Sep 4 11:27:59 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 4 Sep 2016 17:27:59 +0200 Subject: Strange behaviour with numbers in exponential notation In-Reply-To: References: Message-ID: Am 04.09.16 um 10:29 schrieb Nobody: > On Fri, 02 Sep 2016 18:18:08 +0200, Christian Gollwitzer wrote: > >> 1e26 denotes a *floating point number* Floating point has finite >> precision, in CPython it is a 64bit IEEE number. The largest exact >> integer there is 2**53 (~10^16), everything beyond cannot be accurately >> represented. > > Uh, that's wrong. All integers smaller than 2**53 can be represented > exactly. Some, but not all, of the integers above 2**53 can be represented > exactly. Agreed. That's what I wanted to say. Of course you can represent 2**327 exactly in 64 bit binary floating point. The point is, that you can't sensibly assumy to get exact integer results for numbers beyond 2**53 - except for special cases. For example, 133 * 2**53 is exactly representable in FP, but 2**53+1 is not. Christian From auriocus at gmx.de Sun Sep 4 11:37:16 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 4 Sep 2016 17:37:16 +0200 Subject: manually sorting images? In-Reply-To: References: Message-ID: Am 04.09.16 um 10:53 schrieb Ulli Horlacher: > I need to sort images (*.jpg), visually, not by file name. > It looks, there is no standard UNIX tool for this job? > > So, I have to write one by myself, using Tkinter. > > Are there any high-level widgets which can help me, for example a file > browser with thumbnails? > There is an example file browser that comes with tktreectrl: http://tktreectrl.sourceforge.net/pics/imovie.png Not sure, if there are (good) Python bindings to tktreectrl. I've written such a beast myself in pure Tcl/Tk (with an extension to resize images for the thumbnails): http://auriocus.de/slideshow/ - maybe it helps. Christian From vek.m1234 at gmail.com Sun Sep 4 12:00:31 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sun, 04 Sep 2016 21:30:31 +0530 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote: > >>> Regarding the name (From field), my name *is* Veek.M [?] >> >> Liar. *plonk* > > You have crossed a line now Thomas. > > That is absolutely uncalled for. You have absolutely no legitimate > reason to believe that Veek is not his or her real name. > > You owe Veek an apology, and a promise to the entire community that > you will not act in such a bigoted, racist manner again. > > > ah umm.. I'm not overly offended - it was more of a startle. I've gotten used to USENET, somewhat - nature of the beast. Here's a link: https://www.eff.org/deeplinks/2010/01/primer-information-theory-and-privacy Apparently 33 bits of information are enough to identify you. I don't bother about the NSA, but plenty of shady scummy types around, so I tend to spread misinformation which *would* make me a big time liar. It's not a besetting sin. Here's a link to my Youtube thingy: https://www.youtube.com/channel/UCj93gHgUt69R8oGE5hRXd9g Really, if someone's feeling racist, hire someone of your own kind (whatever that is) to kick you and make you study - that way, you are more in control of your destiny. There's plenty of energy the sun kick out that just goes to waste. (Not the easiest thing to do - finding someone reliable enough to zap the toes, anyway..) It's rather unreasonable for humans to expect the Universe to spin around them indefinitely.. If there are trolls here, then: https://www.psychologytoday.com/blog/your-online-secrets/201409/internet-trolls-are-narcissists-psychopaths-and-sadists (scientific study of some sort) From orgnut at yahoo.com Sun Sep 4 15:55:11 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 4 Sep 2016 12:55:11 -0700 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6JCdnSPuVvyC4VHKnZ2dnUU7-KfNnZ2d@giganews.com> On 09/04/2016 09:00 AM, Veek. M wrote: > Steve D'Aprano wrote: > >> On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote: >> >>>> Regarding the name (From field), my name *is* Veek.M [?] >>> >>> Liar. *plonk* >> >> You have crossed a line now Thomas. >> >> That is absolutely uncalled for. You have absolutely no legitimate >> reason to believe that Veek is not his or her real name. >> >> You owe Veek an apology, and a promise to the entire community that >> you will not act in such a bigoted, racist manner again. >> >> >> > > ah umm.. I'm not overly offended - it was more of a startle. I've gotten > used to USENET, somewhat - nature of the beast. > If you continue to read this forum, you will quickly learn to ignore "Pointy-Ears". He rarely has anything worth while to post, and his unique fetish about Real Names shows him to be a hypocrite as well. -- -=- Larry -=- From matt.ruffalo at gmail.com Sun Sep 4 16:04:30 2016 From: matt.ruffalo at gmail.com (Matt Ruffalo) Date: Sun, 4 Sep 2016 22:04:30 +0200 Subject: *args and **kwargs In-Reply-To: <85y43atnzh.fsf@benfinney.id.au> References: <85y43atnzh.fsf@benfinney.id.au> Message-ID: On 2016-09-02 15:44, Ben Finney wrote: > Note that this has nothing to do with how the function is defined; in > the definition of the function, parameters are neither positional nor > keyword. You name each of them, and you define an order for them; and > neither of those makes any of them ?positional? or ?keyword?. > Rather, ?positional argument? and ?keyword argument? are characteristics of the arguments you *supply* in a particular call to the function. > To be fair, this isn't quite the case. One can define keyword-only arguments, which must be supplied as such and don't really have an "order": """ >>> def f(arg1, arg2, *, arg3=None): ... pass ... >>> f(1, 2, 3) Traceback (most recent call last): File "", line 1, in TypeError: f() takes 2 positional arguments but 3 were given """ One can even omit the default argument for something keyword-only, which results in the consistent-but-initially-surprising situation of having a required keyword argument: """ >>> def g(arg1, arg2, *, arg3): ... pass ... >>> g(1, 2, 3) Traceback (most recent call last): File "", line 1, in TypeError: g() takes 2 positional arguments but 3 were given """ MMR... From gerald.britton at gmail.com Sun Sep 4 16:35:35 2016 From: gerald.britton at gmail.com (Gerald Britton) Date: Sun, 4 Sep 2016 16:35:35 -0400 Subject: Question about abstract base classes and abstract properties -- Python 2.7 Message-ID: I was rereading the 2.7 docs about abstract base classes the other day. I found this: "This defines a read-only property; you can also define a read-write abstract property using the ?long? form of property declaration:" along with an example. so I copied the example and put in a little surrounding code: from abc import ABCMeta, abstractproperty class C: __metaclass__ = ABCMeta def getx(self): pass def setx(self, value): pass x = abstractproperty(getx, setx) class D(C): @property def x(self):self._x d = D() print(d) When I ran this, I expected an exception, since I defined a read/write abstract property but only implemented the read operation. However, the example runs fine. That is the class D can be instantiated without error. Of course I cannot set the property since I didn't implement that part. Now, If I don't implement the property at all, I can' instantiate the class. I get: "TypeError: Can't instantiate abstract class D with abstract methods x" which is what I would expect. What I don't understand is why I don't get a similar error when I implement the read operation for the property but not the write operation. If this actually doesn't work (catching the non-implementation at instantiation time), then why is it documented this way. To me at least the doc implies that it *will* raise on the missing write property implementation. Is this a doc bug, an ABC bug or just me? (I've been known to be buggy from time to time!) -- Gerald Britton, MCSE-DP, MVP LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton From greg.ewing at canterbury.ac.nz Sun Sep 4 18:09:06 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 05 Sep 2016 10:09:06 +1200 Subject: manually sorting images? In-Reply-To: References: <57cc0662$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: Quivis wrote: > 2. You want to sort them according to red houses, blue houses, green > trees, yellow trees (that's autumn leaves), cats, dogs, children, elderly > people, But... but... what if you have a picture of a child playing with a dog that's chasing an elderly cat up a yellow tree in front of a blue house? What category do you put it in? The algorithm has been insufficiently specified! -- Greg From greg.ewing at canterbury.ac.nz Sun Sep 4 18:22:50 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 05 Sep 2016 10:22:50 +1200 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: <6JCdnSPuVvyC4VHKnZ2dnUU7-KfNnZ2d@giganews.com> References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> <6JCdnSPuVvyC4VHKnZ2dnUU7-KfNnZ2d@giganews.com> Message-ID: Larry Hudson wrote: > If you continue to read this forum, you will quickly learn to ignore > "Pointy-Ears". He rarely has anything worth while to post, and his > unique fetish about Real Names shows him to be a hypocrite as well. To be fair, it's likely that Thomas Lahn is his real name, and he's never claimed that one shouldn't also include a nickname in one's posted identifier. So Veek should be able to appease P.E. by calling himself 'Veek "David Smith" M'. The quotes clearly mark the middle part as an invented addition, so he's not lying, and it looks enough like a Western style real name to avoid triggering P.E.'s "fake name" reflex. :-) -- Greg From cs at zip.com.au Sun Sep 4 19:26:02 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Mon, 5 Sep 2016 09:26:02 +1000 Subject: manually sorting images? In-Reply-To: References: Message-ID: <20160904232602.GA45504@cskk.homeip.net> On 05Sep2016 10:09, Greg Ewing wrote: >Quivis wrote: >>2. You want to sort them according to red houses, blue houses, green >>trees, yellow trees (that's autumn leaves), cats, dogs, children, >>elderly people, > >But... but... what if you have a picture of a child >playing with a dog that's chasing an elderly cat up a >yellow tree in front of a blue house? What category do >you put it in? > >The algorithm has been insufficiently specified! Yeah. Sounds like he wants a tool that lets him associate tags with images. Then he can tag all the photos with all the relevant attributes, then write his own classifier/sorted later by examining the tags. I also suspect the OP is using the word "sort" to mean "classify" (eg "what sort of thing is this?") versus is more common programming meaning of "ordering". Would be good to clarify that. Cheers, Cameron Simpson From ned at nedbatchelder.com Sun Sep 4 19:40:40 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 4 Sep 2016 16:40:40 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: Message-ID: <3546ff53-499f-42ca-9dd4-ab082a76e7aa@googlegroups.com> On Saturday, September 3, 2016 at 7:55:48 AM UTC-4, Veek. M wrote: > https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm > > Wanted to know if the above link idea, had been implemented and if > there's a module that accepts a pattern like 'cap' and give you all the > instances of unicode 'CAP' characters. > ? \bigcap > ? \sqcap > ? \cap > ? \capricornus > ? \succapprox > ? \precapprox > > (above's from tex) > > I found two useful modules in this regard: unicode_tex, unicodedata > but unicodedata is a builtin which does not do globs, regexs - so it's > kind of limiting in nature. > > Would be nice if you could search html/xml character entity references > as well. The unicodedata module has all the information you need for searching Unicode character names. While it doesn't provide regex or globs, it's all in-memory, so it's not bad for just iterating over the characters and finding what you need. But, 'CAP' appears in 'CAPITAL', which gives more than 1800 matches: >>> for c in range(32, 0x110000): ... try: ... name = unicodedata.name(chr(c)) ... except ValueError: ... continue ... if 'CAP' in name: ... print(c, name) ... 65 LATIN CAPITAL LETTER A 66 LATIN CAPITAL LETTER B .. .. many other lines, mostly with CAPITAL in them .. .. 917593 TAG LATIN CAPITAL LETTER Y 917594 TAG LATIN CAPITAL LETTER Z >>> These were the character names without "CAPITAL": 8419 COMBINING ENCLOSING KEYCAP 8851 SQUARE CAP 9232 SYMBOL FOR DATA LINK ESCAPE 9243 SYMBOL FOR ESCAPE 9809 CAPRICORN 11839 CAPITULUM 41657 YI SYLLABLE CAP 52290 HANGUL SYLLABLE CAP 66003 PHAISTOS DISC SIGN CAPTIVE 119050 MUSICAL SYMBOL DA CAPO 127750 CITYSCAPE AT DUSK 127891 GRADUATION CAP 127956 SNOW CAPPED MOUNTAIN 127961 CITYSCAPE 128287 KEYCAP TEN 128846 ALCHEMICAL SYMBOL FOR CAPUT MORTUUM --Ned. From rosuav at gmail.com Sun Sep 4 19:52:28 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Sep 2016 09:52:28 +1000 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: <3546ff53-499f-42ca-9dd4-ab082a76e7aa@googlegroups.com> References: <3546ff53-499f-42ca-9dd4-ab082a76e7aa@googlegroups.com> Message-ID: On Mon, Sep 5, 2016 at 9:40 AM, Ned Batchelder wrote: > But, 'CAP' appears in 'CAPITAL', which gives more than 1800 matches: > > >>> for c in range(32, 0x110000): > ... try: > ... name = unicodedata.name(chr(c)) > ... except ValueError: > ... continue > ... if 'CAP' in name: > ... print(c, name) > ... > 65 LATIN CAPITAL LETTER A > 66 LATIN CAPITAL LETTER B > .. > .. many other lines, mostly with CAPITAL in them .. > .. > 917593 TAG LATIN CAPITAL LETTER Y > 917594 TAG LATIN CAPITAL LETTER Z > >>> FWIW, hex is much more common for displaying Unicode codepoints than decimal is. So I'd print it like this (incorporating the 'not CAPITAL' filter): >>> for c in range(32, 0x110000): ... try: ... name = unicodedata.name(chr(c)) ... except ValueError: ... continue ... if 'CAP' in name and 'CAPITAL' not in name: ... print("U+%04X %s" % (c, name)) ... U+20E3 COMBINING ENCLOSING KEYCAP U+2293 SQUARE CAP U+2410 SYMBOL FOR DATA LINK ESCAPE U+241B SYMBOL FOR ESCAPE U+2651 CAPRICORN U+2E3F CAPITULUM U+A2B9 YI SYLLABLE CAP U+CC42 HANGUL SYLLABLE CAP U+101D3 PHAISTOS DISC SIGN CAPTIVE U+1D10A MUSICAL SYMBOL DA CAPO U+1F306 CITYSCAPE AT DUSK U+1F393 GRADUATION CAP U+1F3D4 SNOW CAPPED MOUNTAIN U+1F3D9 CITYSCAPE U+1F51F KEYCAP TEN U+1F74E ALCHEMICAL SYMBOL FOR CAPUT MORTUUM >>> Takes advantage of %04X giving a minimum, but not maximum, of four digits :) ChrisA From ned at nedbatchelder.com Sun Sep 4 20:43:42 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 4 Sep 2016 17:43:42 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: <3546ff53-499f-42ca-9dd4-ab082a76e7aa@googlegroups.com> Message-ID: On Sunday, September 4, 2016 at 7:52:44 PM UTC-4, Chris Angelico wrote: > FWIW, hex is much more common for displaying Unicode codepoints than > decimal is. So I'd print it like this (incorporating the 'not CAPITAL' > filter): You are right, I went too quickly, and didn't realize until after I posted that I had printed decimal instead of hex. --Ned. From steve+python at pearwood.info Sun Sep 4 21:29:39 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 05 Sep 2016 11:29:39 +1000 Subject: Why doesn't my finaliser run here? References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> <85bn03u9ge.fsf@benfinney.id.au> Message-ID: <57ccca84$0$1619$c3e8da3$5496439d@news.astraweb.com> On Sun, 4 Sep 2016 10:37 pm, Ben Finney wrote: > Steve D'Aprano writes: > >> Why doesn't __del__ run here? > > Short anser: because nothing has removed the reference to the instance. Hmmm. You're probably right, but not for the reason you think :-) >> class Eggs(object): >> def __new__(cls): >> instance = object.__new__(cls) >> print("instance created successfully") >> return instance >> def __init__(self): >> print("self definitely exists:", self) >> raise Exception >> def __del__(self): >> print("deleting", repr(self)) > > This is a good example of why it helps to *never* call ?__init__? the > ?constructor?. It isn't, because ?__init__? acts on an > already-constructed instance. I don't believe I did call it the constructor :-) > Hance, an exception raised from ?__init__? is not going to affect > whether the instance exists. > >> And an example: >> >> >> py> e = Eggs() >> instance created successfully >> self definitely exists: <__main__.Eggs object at 0xb7bf21ec> >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 8, in __init__ >> Exception >> py> > > > Right. The instance is constructed successfully (by ?__new__?, the > constructor). It will be bound to ?s?, creating a reference to the > instance. Bound to `s`? Did you mean `e`? It's certainly not bound to `e`, since that is unbound. I went back to my interpreter session and tried to view the value of `e`, and as I expected, it was unbound: py> e deleting <__main__.Eggs object at 0xb7bf21ec> Traceback (most recent call last): File "", line 1, in NameError: name 'e' is not defined So it looks like what may have been holding onto the reference to the Eggs instance was the exception or traceback, and once that got garbage-collected (by me causing a new exception and traceback) the finaliser ran. Which both Oscar and Chris suggested, thanks guys! So this isn't definite proof, but it is very suggestive that the thing holding onto the reference to the half-built Eggs instance is something to do with the exception. > The exception raised from the initialiser does not stop you from binding > the instance to a name. That binding succeeds; the reference remains. > Nothing has caused that reference to go away. That bit is actually wrong. Given: name = expression an exception in `expression` prevents the binding to `name` from occurring at all. If `name` already existed, then it remains untouched, and if it didn't it remains unbound. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From torriem at gmail.com Sun Sep 4 21:31:48 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 4 Sep 2016 19:31:48 -0600 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> <6JCdnSPuVvyC4VHKnZ2dnUU7-KfNnZ2d@giganews.com> Message-ID: On 09/04/2016 04:22 PM, Gregory Ewing wrote: > Larry Hudson wrote: >> If you continue to read this forum, you will quickly learn to ignore >> "Pointy-Ears". He rarely has anything worth while to post, and his >> unique fetish about Real Names shows him to be a hypocrite as well. > > To be fair, it's likely that Thomas Lahn is his real > name, and he's never claimed that one shouldn't also > include a nickname in one's posted identifier. > > So Veek should be able to appease P.E. by calling > himself 'Veek "David Smith" M'. The quotes clearly > mark the middle part as an invented addition, so > he's not lying, and it looks enough like a Western > style real name to avoid triggering P.E.'s "fake name" > reflex. :-) Or better yet just ignore his posts entirely. From torriem at gmail.com Sun Sep 4 21:35:32 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 4 Sep 2016 19:35:32 -0600 Subject: manually sorting images? In-Reply-To: References: <57cc0662$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <88fad0e4-950b-5615-8837-6507310fb720@gmail.com> On 09/04/2016 04:09 PM, Gregory Ewing wrote: > Quivis wrote: >> 2. You want to sort them according to red houses, blue houses, green >> trees, yellow trees (that's autumn leaves), cats, dogs, children, elderly >> people, > > But... but... what if you have a picture of a child > playing with a dog that's chasing an elderly cat up a > yellow tree in front of a blue house? What category do > you put it in? And this is the weakness in all photo sorting schemes (human schemes that is). Some people try organizing folders, others try tagging. Neither system works that well. Tags sound good in theory, but in practice they suck almost as much as folders. Actually all tag-based indexing systems suck, even for things like ebooks and music. Keeping tags consistent is difficult, and making them complete is impossible. Maybe computer vision will ease this difficulty, but I kind of doubt it. From ben+python at benfinney.id.au Sun Sep 4 21:48:37 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 05 Sep 2016 11:48:37 +1000 Subject: Why doesn't my finaliser run here? References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> <85bn03u9ge.fsf@benfinney.id.au> <57ccca84$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <857fart8ui.fsf@benfinney.id.au> Steve D'Aprano writes: > On Sun, 4 Sep 2016 10:37 pm, Ben Finney wrote: > > > Short anser: because nothing has removed the reference to the > > instance. > > Hmmm. You're probably right, but not for the reason you think :-) Thanks to those who corrected some details in my explanation. > > This is a good example of why it helps to *never* call ?__init__? > > the ?constructor?. It isn't, because ?__init__? acts on an > > already-constructed instance. > > I don't believe I did call it the constructor :-) You have advocated that in the past, though :-) I am presenting this as a counter-example: ?__init__? does not act as the constructor, so it's needlessly misleading to refer to it that way. > > Right. The instance is constructed successfully (by ?__new__?, the > > constructor). It will be bound to ?s?, creating a reference to the > > instance. > > Bound to `s`? Did you mean `e`? I did. And yes, that was incorrect: the assignment statement does not complete because the exception interrupts it. So ?e? is not a reference to the instance. > So it looks like what may have been holding onto the reference to the > Eggs instance was the exception or traceback, and once that got > garbage-collected (by me causing a new exception and traceback) the > finaliser ran. > > Which both Oscar and Chris suggested, thanks guys! Indeed. Thanks for dissecting the right and wrong parts :-) The larger point which remains true: Don't think of ?__init__? as a constructor, all it does is work on an *already-constructed* instance. The ?__new__? method is the constructor. The instance doesn't exist before that method is called; if successful, the instance is constructed and returned. The ?__init__? method is the initialiser. It receives the already-constructed instance, and returns ?None?. That doesn't affect existing references to the instance. -- \ ?Shepherds ? look after their sheep so they can, first, fleece | `\ them and second, turn them into meat. That's much more like the | _o__) priesthood as I know it.? ?Christopher Hitchens, 2008-10-29 | Ben Finney From rosuav at gmail.com Sun Sep 4 22:10:58 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Sep 2016 12:10:58 +1000 Subject: Why doesn't my finaliser run here? In-Reply-To: <857fart8ui.fsf@benfinney.id.au> References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> <85bn03u9ge.fsf@benfinney.id.au> <57ccca84$0$1619$c3e8da3$5496439d@news.astraweb.com> <857fart8ui.fsf@benfinney.id.au> Message-ID: On Mon, Sep 5, 2016 at 11:48 AM, Ben Finney wrote: > The larger point which remains true: Don't think of ?__init__? as a > constructor, all it does is work on an *already-constructed* instance. > > The ?__new__? method is the constructor. The instance doesn't exist > before that method is called; if successful, the instance is constructed > and returned. > > The ?__init__? method is the initialiser. It receives the > already-constructed instance, and returns ?None?. That doesn't affect > existing references to the instance. It doesn't really matter, though. Here's the outside view of constructing a class: instance = Class() Doesn't matter how it's implemented; you call something and you either get an instance back, or catch an exception. While it's technically true that __init__ raising an exception won't affect existing references to that instance, it's almost immaterial. You generally won't implement __new__ to retain refs, and you generally won't call __init__ again after the instance has been fully constructed. Generally, you can assume that an exception in __init__ means you can safely dispose of the object. ChrisA From framstag at rus.uni-stuttgart.de Mon Sep 5 02:43:23 2016 From: framstag at rus.uni-stuttgart.de (Ulli Horlacher) Date: Mon, 5 Sep 2016 06:43:23 +0000 (UTC) Subject: manually sorting images? References: <57cc0662$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: Quivis wrote: > On Sun, 04 Sep 2016 21:32:47 +1000, Steve D'Aprano wrote: > > > What does it mean to sort images visually? > > 1. A directory of images collected over say, five years. > > 2. You want to sort them according to red houses, blue houses, green > trees, yellow trees (that's autumn leaves), cats, dogs, children, elderly > people, and so on, and rename them using some scheme you invented. > > 3. AFAIK there are no algorithms to do that with any higher degree of > certainty, so you have to look through them and sort them manually. > Usually using thumbnails. Exactly. The purpose is to generate a list for llgal (a HTML gallery creating tool). llgal makes a good job, but has no GUI for manually sorting. Geeqie, you mentioned before, does nearly exactly what I want, but it does not respect the locale when writing the filename collection. It always writes UTF8. Ok, I can convert the filenames later by (python) script using the correct locale. The job is now: call "geekie ." user creates the collection and saves it read the collection file (*) convert the file names according to locale prefix filenames with number (renaming) call "llgal ..." (*) Problem: how do I know which filename the user has choosen for the collection? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: horlacher at tik.uni-stuttgart.de Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ From greg.ewing at canterbury.ac.nz Mon Sep 5 02:49:44 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 05 Sep 2016 18:49:44 +1200 Subject: Why doesn't my finaliser run here? In-Reply-To: References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> <85bn03u9ge.fsf@benfinney.id.au> Message-ID: Chris Angelico wrote: > There's a reference here somewhere, though. My suspicion is it's in > sys.exc_info / sys.last_traceback, It's sys.last_traceback: >>> e = Eggs() instance created successfully ('self definitely exists:', <__main__.Eggs object at 0x2b6670>) Traceback (most recent call last): File "", line 1, in File "", line 8, in __init__ Exception >>> sys.last_traceback = None ('deleting', '<__main__.Eggs object at 0x2b6670>') >>> -- Greg From greg.ewing at canterbury.ac.nz Mon Sep 5 02:49:44 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 5 Sep 2016 00:49:44 -0600 Subject: Why doesn't my finaliser run here? In-Reply-To: References: <57cc1173$0$1585$c3e8da3$5496439d@news.astraweb.com> <85bn03u9ge.fsf@benfinney.id.au> Message-ID: Chris Angelico wrote: > There's a reference here somewhere, though. My suspicion is it's in > sys.exc_info / sys.last_traceback, It's sys.last_traceback: >>> e = Eggs() instance created successfully ('self definitely exists:', <__main__.Eggs object at 0x2b6670>) Traceback (most recent call last): File "", line 1, in File "", line 8, in __init__ Exception >>> sys.last_traceback = None ('deleting', '<__main__.Eggs object at 0x2b6670>') >>> -- Greg -- https://mail.python.org/mailman/listinfo/python-list From vek.m1234 at gmail.com Mon Sep 5 03:30:39 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Mon, 05 Sep 2016 13:00:39 +0530 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> <6JCdnSPuVvyC4VHKnZ2dnUU7-KfNnZ2d@giganews.com> <1543684.VLH7GnMWUR@PointedEars.de> Message-ID: Thomas 'PointedEars' Lahn wrote: > Gregory Ewing wrote: > >> Larry Hudson wrote: >>> If you continue to read this forum, you will quickly learn to ignore >>> "Pointy-Ears". He rarely has anything worth while to post, and his >>> unique fetish about Real Names shows him to be a hypocrite as well. >> >> To be fair, it's likely that Thomas Lahn is his real >> name, > > Of course it is my real name. > >> and he's never claimed that one shouldn't also >> include a nickname in one's posted identifier. > > In fact, I have recommended doing that several times to people who > only used their nickname in the ?From? header field value. > >> So Veek should be able to appease P.E. by calling >> himself 'Veek "David Smith" M'. > > That would not help. ?Veek? might be (the transcription of) a given > name or > a family name, but ?Veek M? is not a real name. [Real name filter > rules need to be adapted, though, because ?O? is the transcription of > an East Asian family name.] > >> The quotes clearly mark the middle part as an invented addition, so >> he's not lying, > > He is lying and would be. That is the main issue. How can I trust a > person who does not even have the decency and the courage to stand by > their statements with their real name? > >> and it looks enough like a Western style real name to avoid >> triggering P.E.'s "fake name" reflex. :-) > > It is not a reflex, but a request for something so basic that no > request should be necessary: showing the simple politeness of > introducing yourself properly when meeting strangers ? of not lying to > them about one?s identity ? especially if one asks them for help. > Ah! Now that's the root of his troubles, right there. Just in case anyone else is confused, I DON'T feel helped, thankful, grateful when someone answers my posts/questions. I expect you to have a whale of a good time when you post (I've always found it to be rather pleasant and fun to post). However I'm shhing on the subject of Thomas more or less permanently. This sort of humor works only when you're in a good mood and feeling chirpy, but that's not always the case so.. He's more or less Steve's baby anyhow (sorry Steve). From antoon.pardon at rece.vub.ac.be Mon Sep 5 04:46:05 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 5 Sep 2016 10:46:05 +0200 Subject: Would like some thoughts on a grouped iterator. Message-ID: <57CD30CD.20000@rece.vub.ac.be> I need an interator that takes an already existing iterator and divides it into subiterators of items belonging together. For instance take the following class, wich would check whether the argument is greater or equal to the previous argument. class upchecker: def __init__(self): self.prev = None def __call__(self, arg): if self.last is None: self.prev = arg return True elif arg >= self.last: self.prev = arg return True else: self.prev = arg return False So the iterator I need --- I call it grouped --- in combination with the above class would be used someting like: for itr in grouped([8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, 9, 0, 1, 3, 18], upchecker()): print list(itr) and the result would be: [8, 10, 13] [11] [2, 17] [5, 12] [7, 14] [4, 6, 15, 16, 19] [9] [0, 1, 3, 18] Anyone an idea how I best tackle this? From chris at simplistix.co.uk Mon Sep 5 04:50:26 2016 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 5 Sep 2016 09:50:26 +0100 Subject: testfixtures 4.10.1 Released! Message-ID: Hi All, I'm pleased to announce the release of testfixtures 4.10.1 featuring the following: - Better docs for TempDirectory.compare(). - Remove the need for expected paths supplied to TempDirectory.compare() to be in sorted order. - Document a good way of restoring stdout when in a debugger. - Fix handling of trailing slashes in TempDirectory.compare(). Thanks to Maximilian Albert for the TempDirectory.compare() docs. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: https://github.com/Simplistix/testfixtures Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris From alister.ware at ntlworld.com Mon Sep 5 04:59:49 2016 From: alister.ware at ntlworld.com (alister) Date: Mon, 05 Sep 2016 08:59:49 GMT Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> <6JCdnSPuVvyC4VHKnZ2dnUU7-KfNnZ2d@giganews.com> <1543684.VLH7GnMWUR@PointedEars.de> Message-ID: <9uazz.1051391$2A.638530@fx46.am4> On Mon, 05 Sep 2016 08:15:42 +0200, Thomas 'PointedEars' Lahn wrote: > >> So Veek should be able to appease P.E. by calling himself 'Veek "David >> Smith" M'. > > That would not help. ?Veek? might be (the transcription of) a given > name or a family name, but ?Veek M? is not a real name. [Real name > filter rules need to be adapted, though, because ?O? is the > transcription of an East Asian family name.] > How can you possible know that Veek M is not a reall name? what rules for real names have you found that is 100% reliable I suggest you read the following. https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about- names/ provided people always* refer to themselves the same way then they can be identified, continually changing name to hide ones identity is another issue & there are not many legitimate reasons to do so *personally I don't even care about that. -- Lawn mower blade in your fan need sharpening From __peter__ at web.de Mon Sep 5 05:41:59 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 05 Sep 2016 11:41:59 +0200 Subject: Would like some thoughts on a grouped iterator. References: <57CD30CD.20000@rece.vub.ac.be> Message-ID: Antoon Pardon wrote: > I need an interator that takes an already existing iterator and > divides it into subiterators of items belonging together. > > For instance take the following class, wich would check whether > the argument is greater or equal to the previous argument. > > class upchecker: > def __init__(self): > self.prev = None > def __call__(self, arg): > if self.last is None: > self.prev = arg > return True > elif arg >= self.last: > self.prev = arg > return True > else: > self.prev = arg > return False > > So the iterator I need --- I call it grouped --- in combination with > the above class would be used someting like: > > for itr in grouped([8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, > 9, 0, 1, 3, 18], upchecker()): > print list(itr) > > and the result would be: > > [8, 10, 13] > [11] > [2, 17] > [5, 12] > [7, 14] > [4, 6, 15, 16, 19] > [9] > [0, 1, 3, 18] > > Anyone an idea how I best tackle this? I always start thinking "There must be an elegant way to do this" and then end with a clumsy wrapper around itertools.groupby(). $ cat grouped.py from itertools import groupby class Check: def __init__(self, check): self.first = True self.prev = None self.toggle = False self.check = check def __call__(self, item): if self.first: self.first = False else: if not self.check(self.prev, item): self.toggle = not self.toggle self.prev = item return self.toggle def grouped(items, check): return (g for k, g in groupby(items, Check(check))) if __name__ == "__main__": def upchecker(a, b): return a < b items = [ 8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, 9, 0, 1, 3, 18 ] for itr in grouped(items, upchecker): print(list(itr)) $ python grouped.py [8, 10, 13] [11] [2, 17] [5, 12] [7, 14] [4, 6, 15, 16, 19] [9] [0, 1, 3, 18] From breamoreboy at gmail.com Mon Sep 5 05:59:11 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 5 Sep 2016 02:59:11 -0700 (PDT) Subject: Would like some thoughts on a grouped iterator. In-Reply-To: References: <57CD30CD.20000@rece.vub.ac.be> Message-ID: On Monday, September 5, 2016 at 10:42:27 AM UTC+1, Peter Otten wrote: > Antoon Pardon wrote: > > > I need an interator that takes an already existing iterator and > > divides it into subiterators of items belonging together. > > > > For instance take the following class, wich would check whether > > the argument is greater or equal to the previous argument. > > > > class upchecker: > > def __init__(self): > > self.prev = None > > def __call__(self, arg): > > if self.last is None: > > self.prev = arg > > return True > > elif arg >= self.last: > > self.prev = arg > > return True > > else: > > self.prev = arg > > return False > > > > So the iterator I need --- I call it grouped --- in combination with > > the above class would be used someting like: > > > > for itr in grouped([8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, > > 9, 0, 1, 3, 18], upchecker()): > > print list(itr) > > > > and the result would be: > > > > [8, 10, 13] > > [11] > > [2, 17] > > [5, 12] > > [7, 14] > > [4, 6, 15, 16, 19] > > [9] > > [0, 1, 3, 18] > > > > Anyone an idea how I best tackle this? > > I always start thinking "There must be an elegant way to do this" and then > end with a clumsy wrapper around itertools.groupby(). > > $ cat grouped.py > from itertools import groupby > > > class Check: > def __init__(self, check): > self.first = True > self.prev = None > self.toggle = False > self.check = check > > def __call__(self, item): > if self.first: > self.first = False > else: > if not self.check(self.prev, item): > self.toggle = not self.toggle > self.prev = item > return self.toggle > > > def grouped(items, check): > return (g for k, g in groupby(items, Check(check))) > > > if __name__ == "__main__": > def upchecker(a, b): > return a < b > > items = [ > 8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, 9, 0, 1, 3, 18 > ] > for itr in grouped(items, upchecker): > print(list(itr)) > > $ python grouped.py > [8, 10, 13] > [11] > [2, 17] > [5, 12] > [7, 14] > [4, 6, 15, 16, 19] > [9] > [0, 1, 3, 18] As usual you beat me to it, but I'd spell "upchecker" as "from operator import lt" :) From neha.agrawal1428 at gmail.com Mon Sep 5 06:03:45 2016 From: neha.agrawal1428 at gmail.com (neha.agrawal1428 at gmail.com) Date: Mon, 5 Sep 2016 03:03:45 -0700 (PDT) Subject: mentor training python Romania with certification In-Reply-To: References: Message-ID: On Tuesday, August 16, 2016 at 6:45:04 PM UTC+5:30, blue wrote: > Hi. > > I'm from Romania. > I need to update my skils under python. > I need to find one mentor ( class, training ) to obtain one certified under python language. > > C?t?lin George Fe?til? Hi, You might find Python course offered by edureka to be useful http://www.edureka.co/python Check it out! Regards Neha From steve+comp.lang.python at pearwood.info Mon Sep 5 06:08:44 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 05 Sep 2016 20:08:44 +1000 Subject: Would like some thoughts on a grouped iterator. References: <57CD30CD.20000@rece.vub.ac.be> Message-ID: <57cd442e$0$11116$c3e8da3@news.astraweb.com> On Monday 05 September 2016 18:46, Antoon Pardon wrote: > I need an interator that takes an already existing iterator and > divides it into subiterators of items belonging together. > > For instance take the following class, wich would check whether > the argument is greater or equal to the previous argument. These sorts of filtering jobs are often so simple that its hardly worth generalising them unless you have a whole lot of them. def group_increasing(seq): it = iter(seq) accum = [] try: last = next(it) except StopIterator: return accum.append(last) for item in it: if item >= last: accum.append(item) else: yield tuple(accum) accum = [item] last = item if accum: yield tuple(accum) If you do need to generalise, using itertools.groupby is probably the right way to do it. -- Steve From jussi.piitulainen at helsinki.fi Mon Sep 5 06:24:40 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 05 Sep 2016 13:24:40 +0300 Subject: Would like some thoughts on a grouped iterator. References: <57CD30CD.20000@rece.vub.ac.be> Message-ID: Antoon Pardon writes: > I need an interator that takes an already existing iterator and > divides it into subiterators of items belonging together. > > For instance take the following class, wich would check whether > the argument is greater or equal to the previous argument. > > class upchecker: > def __init__(self): > self.prev = None > def __call__(self, arg): > if self.last is None: > self.prev = arg > return True > elif arg >= self.last: > self.prev = arg > return True > else: > self.prev = arg > return False > > So the iterator I need --- I call it grouped --- in combination with > the above class would be used someting like: > > for itr in grouped([8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, 9, 0, 1, 3, 18], upchecker()): > print list(itr) > > and the result would be: > > [8, 10, 13] > [11] > [2, 17] > [5, 12] > [7, 14] > [4, 6, 15, 16, 19] > [9] > [0, 1, 3, 18] > > Anyone an idea how I best tackle this? Perhaps something like this when building from scratch (not wrapping itertools.groupby). The inner grouper needs to communicate to the outer grouper whether it ran out of this group but it obtained a next item, or it ran out of items altogether. Your design allows inclusion conditions that depend on more than just the previous item in the group. This doesn't. I think itertools.groupby may raise an error if the caller didn't consumer a group before stepping to a new group. This doesn't. I'm not sure that itertools.groupby does either, and I'm too lazy to check. def gps(source, belong): def gp(): nonlocal prev, more keep = True while keep: yield prev try: this = next(source) except StopIteration: more = False raise prev, keep = this, belong(prev, this) source = iter(source) prev = next(source) more = True while more: yield gp() from operator import eq, lt, gt for data in ([], [3], [3,1], [3,1,4], [3,1,4,1,5,9,2,6]): for tag, op in (('=', eq), ('<', lt), ('>', gt)): print(tag, data, '=>', [list(g) for g in gps(data, op)]) From __peter__ at web.de Mon Sep 5 06:46:57 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 05 Sep 2016 12:46:57 +0200 Subject: Would like some thoughts on a grouped iterator. References: <57CD30CD.20000@rece.vub.ac.be> Message-ID: Jussi Piitulainen wrote: > Antoon Pardon writes: > >> I need an interator that takes an already existing iterator and >> divides it into subiterators of items belonging together. >> >> For instance take the following class, wich would check whether >> the argument is greater or equal to the previous argument. >> >> class upchecker: >> def __init__(self): >> self.prev = None >> def __call__(self, arg): >> if self.last is None: >> self.prev = arg >> return True >> elif arg >= self.last: >> self.prev = arg >> return True >> else: >> self.prev = arg >> return False >> >> So the iterator I need --- I call it grouped --- in combination with >> the above class would be used someting like: >> >> for itr in grouped([8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, >> 9, 0, 1, 3, 18], upchecker()): >> print list(itr) >> >> and the result would be: >> >> [8, 10, 13] >> [11] >> [2, 17] >> [5, 12] >> [7, 14] >> [4, 6, 15, 16, 19] >> [9] >> [0, 1, 3, 18] >> >> Anyone an idea how I best tackle this? > > Perhaps something like this when building from scratch (not wrapping > itertools.groupby). The inner grouper needs to communicate to the outer > grouper whether it ran out of this group but it obtained a next item, or > it ran out of items altogether. > > Your design allows inclusion conditions that depend on more than just > the previous item in the group. This doesn't. I think itertools.groupby > may raise an error if the caller didn't consumer a group before stepping > to a new group. This doesn't. I'm not sure that itertools.groupby does > either, and I'm too lazy to check. > > def gps(source, belong): > def gp(): > nonlocal prev, more > keep = True > while keep: > yield prev > try: > this = next(source) > except StopIteration: > more = False > raise > prev, keep = this, belong(prev, this) > source = iter(source) > prev = next(source) > more = True > while more: > yield gp() > > from operator import eq, lt, gt > for data in ([], [3], [3,1], [3,1,4], [3,1,4,1,5,9,2,6]): > for tag, op in (('=', eq), ('<', lt), ('>', gt)): > print(tag, data, '=>', [list(g) for g in gps(data, op)]) As usual I couldn't stop and came up with something very similar: def grouped(items, check): items = iter(items) buf = next(items) more = True def group(): nonlocal buf, more for item in items: yield buf prev = buf buf = item if not check(prev, item): break else: yield buf more = False while more: g = group() yield g for _ in g: pass if __name__ == "__main__": def upchecker(a, b): return a < b items = [ 8, 10, 13, 11, 2, 17, 5, 12, 7, 14, 4, 6, 15, 16, 19, 9, 0, 1, 3, 18 ] for itr in grouped(items, upchecker): print(list(itr)) The one thing I think you should adopt from this is that the current group is consumed before yielding the next. From jussi.piitulainen at helsinki.fi Mon Sep 5 06:56:11 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 05 Sep 2016 13:56:11 +0300 Subject: Would like some thoughts on a grouped iterator. References: <57CD30CD.20000@rece.vub.ac.be> Message-ID: Peter Otten writes: > Jussi Piitulainen wrote: [- -] >> while more: >> yield gp() [- -] > As usual I couldn't stop and came up with something very similar: [- -] > while more: > g = group() > yield g > for _ in g: pass [- -] > The one thing I think you should adopt from this is that the current > group is consumed before yielding the next. Oh yes. I see now that it's also easy to do so. From ned at nedbatchelder.com Mon Sep 5 07:45:15 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 5 Sep 2016 04:45:15 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: <1543684.VLH7GnMWUR@PointedEars.de> References: <2829361.aeNJFYEL58@PointedEars.de> <2834866.44csPzL39Z@PointedEars.de> <57cc0d69$0$1590$c3e8da3$5496439d@news.astraweb.com> <6JCdnSPuVvyC4VHKnZ2dnUU7-KfNnZ2d@giganews.com> <1543684.VLH7GnMWUR@PointedEars.de> Message-ID: <46a355de-31e1-47c1-9e9c-50a052d87077@googlegroups.com> On Monday, September 5, 2016 at 2:15:58 AM UTC-4, Thomas 'PointedEars' Lahn wrote: > How can I trust a person > who does not even have the decency and the courage to stand by their > statements with their real name? Feel free to ignore people you don't trust. We'll help them. --Ned. From smith at smith.com Mon Sep 5 11:27:42 2016 From: smith at smith.com (Smith) Date: Mon, 5 Sep 2016 17:27:42 +0200 Subject: listdir Message-ID: Hello to all, I wanted to know because even though the files are present on the directory I write input gives me "file not found". You can help me? Thank you a = input("Digita la directory dove vuoi trovare i file py: ") for file in os.listdir(a): if file.endswith(".py"): print(file) else: break print("File not found") From smith at smith.com Mon Sep 5 11:30:43 2016 From: smith at smith.com (Smith) Date: Mon, 5 Sep 2016 17:30:43 +0200 Subject: listdir In-Reply-To: References: Message-ID: Il 05/09/2016 17:27, Smith ha scritto: > Hello to all, > I wanted to know because even though the files are present on the > directory I write input gives me "file not found". > You can help me? > Thank you > > a = input("Digita la directory dove vuoi trovare i file py: ") > for file in os.listdir(a): > if file.endswith(".py"): > print(file) > else: > break > print("File not found") sorry: > a = input(search for files with the extension .py into directory: ") > for file in os.listdir(a): > if file.endswith(".py"): > print(file) > else: > break > print("File not found") From rustompmody at gmail.com Mon Sep 5 11:34:31 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 5 Sep 2016 08:34:31 -0700 (PDT) Subject: listdir In-Reply-To: References: Message-ID: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> So what do you get when you replace the if-else with a simple: print(file) ? [And BTW dont use the variable name ?file? its um sacred] From jeanmichel at sequans.com Mon Sep 5 11:37:41 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 05 Sep 2016 17:37:41 +0200 Subject: listdir In-Reply-To: References: Message-ID: On 09/05/2016 05:27 PM, Smith wrote: > Hello to all, > I wanted to know because even though the files are present on the > directory I write input gives me "file not found". > You can help me? > Thank you > > a = input("Digita la directory dove vuoi trovare i file py: ") > for file in os.listdir(a): > if file.endswith(".py"): > print(file) > else: > break > print("File not found") Hi, try a = input("Digita la directory dove vuoi trovare i file py: ") for file in os.listdir(a): if file.endswith(".py"): print(file) you don't want to break whenever a file does not fit the requirement, you want to to continue the iteration. jm From rosuav at gmail.com Mon Sep 5 11:39:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Sep 2016 01:39:27 +1000 Subject: listdir In-Reply-To: References: Message-ID: On Tue, Sep 6, 2016 at 1:27 AM, Smith wrote: > Hello to all, > I wanted to know because even though the files are present on the directory > I write input gives me "file not found". > You can help me? > Thank you > > a = input("Digita la directory dove vuoi trovare i file py: ") > for file in os.listdir(a): > if file.endswith(".py"): > print(file) > else: > break > print("File not found") What exactly are you expecting the 'break' to do here? Can you explain to me the intent of your code? ChrisA From smith at smith.com Mon Sep 5 11:41:41 2016 From: smith at smith.com (Smith) Date: Mon, 5 Sep 2016 17:41:41 +0200 Subject: listdir In-Reply-To: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> References: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> Message-ID: Il 05/09/2016 17:34, Rustom Mody ha scritto: > So what do you get when you replace the if-else with a simple: print(file) a = input("search for files with the extension .py into directory: ") for file in os.listdir(a): if file.endswith(".py"): print(file) search for files with the extension .py into directory: /home/ filepy.py tempo.py filescript.py ticker.py toolgen.py words.py m.py scrapingweb.py partitesnai.py pythonprova.py scraper.py snmp.py printreturn.py multiping.py scraping.py funzionipython.py From rosuav at gmail.com Mon Sep 5 11:45:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Sep 2016 01:45:35 +1000 Subject: listdir In-Reply-To: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> References: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> Message-ID: On Tue, Sep 6, 2016 at 1:34 AM, Rustom Mody wrote: > [And BTW dont use the variable name ?file? its um sacred] Nah, that part's fine. Python isn't religious about builtins. ChrisA From jeanmichel at sequans.com Mon Sep 5 11:57:11 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 05 Sep 2016 17:57:11 +0200 Subject: listdir In-Reply-To: References: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> Message-ID: On 09/05/2016 05:41 PM, Smith wrote: > Il 05/09/2016 17:34, Rustom Mody ha scritto: >> So what do you get when you replace the if-else with a simple: >> print(file) > > a = input("search for files with the extension .py into directory: ") > for file in os.listdir(a): > if file.endswith(".py"): > print(file) > > > search for files with the extension .py into directory: /home/ > filepy.py > tempo.py > filescript.py > ticker.py > toolgen.py > words.py > m.py > scrapingweb.py > partitesnai.py > pythonprova.py > scraper.py > snmp.py > printreturn.py > multiping.py > scraping.py > funzionipython.py Is that what you're expecting ? A slightly different version: import glob, os a = input("search for files with the extension .py into directory: ") print glob.glob(os.path.join(a, '*.py')) jm From smith at smith.it Mon Sep 5 12:20:59 2016 From: smith at smith.it (Smith) Date: Mon, 5 Sep 2016 18:20:59 +0200 Subject: listdir In-Reply-To: References: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> Message-ID: <7d31aad4-91df-a445-a09d-89b1913e3858@smith.it> On 05/09/2016 17:57, jmp wrote: > > Is that what you're expecting ? > A slightly different version: > > import glob, os > > a = input("search for files with the extension .py into directory: ") > print glob.glob(os.path.join(a, '*.py')) > > jm Thank you Sorry, but i'm newbie :-( From smith at smith.it Mon Sep 5 12:29:12 2016 From: smith at smith.it (Smith) Date: Mon, 5 Sep 2016 18:29:12 +0200 Subject: listdir In-Reply-To: References: Message-ID: > > What exactly are you expecting the 'break' to do here? Can you explain > to me the intent of your code? > > ChrisA > I'd like to create a script that searches the directory .py files. If the script does not find the file extension .py would return the error message "File Not Found". From rosuav at gmail.com Mon Sep 5 12:39:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Sep 2016 02:39:46 +1000 Subject: listdir In-Reply-To: References: Message-ID: On Tue, Sep 6, 2016 at 2:29 AM, Smith wrote: >> What exactly are you expecting the 'break' to do here? Can you explain >> to me the intent of your code? >> >> ChrisA >> > I'd like to create a script that searches the directory .py files. > If the script does not find the file extension .py would return the error > message "File Not Found". Okay. So the logic needs to be like this: For every file in this directory: If the file has the extension ".py": Print out the file name If we didn't print out any file names: Print out "File not found" Notice how this pseudo-code is extremely close to actual Python code. Here's a revision of your code that does more-or-less that. (I'm keeping your original prompt; Python 3 is quite happy to work with all human languages equally, and not just as text strings - you can name your variables in Italian, too.) a = input("Digita la directory dove vuoi trovare i file py: ") found_any = False for file in os.listdir(a): if file.endswith(".py"): print(file) found_any = True if not found_any: print("File not found") There's no "else" clause, because the algorithm doesn't care about non-py files; it cares only whether or not any .py files were found. Does that help you understand what's going on? I can elaborate more if you like. ChrisA From breamoreboy at gmail.com Mon Sep 5 13:22:12 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 5 Sep 2016 10:22:12 -0700 (PDT) Subject: listdir In-Reply-To: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> References: <1da218bd-c65e-44e2-a07e-ccf9a31697d4@googlegroups.com> Message-ID: <45e1994e-ee71-46a1-983c-6fd84a57fc2f@googlegroups.com> On Monday, September 5, 2016 at 4:34:45 PM UTC+1, Rustom Mody wrote: > So what do you get when you replace the if-else with a simple: print(file) ? > > [And BTW dont use the variable name ?file? its um sacred] Only in Python 2, it's gone from the built-ins in Python 3 https://docs.python.org/3/whatsnew/3.0.html#builtins Kindest regards. Mark Lawrence From tony at vanderhoff.org Mon Sep 5 14:28:45 2016 From: tony at vanderhoff.org (Tony van der Hoff) Date: Mon, 05 Sep 2016 19:28:45 +0100 Subject: manually sorting images? In-Reply-To: References: Message-ID: <57CDB95D.8030608@vanderhoff.org> On 04/09/16 09:53, Ulli Horlacher wrote: > I need to sort images (*.jpg), visually, not by file name. > It looks, there is no standard UNIX tool for this job? > There is a very good tutorial here: http://www.pyimagesearch.com/2014/12/01/complete-guide-building-image-search-engine-python-opencv/ -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From emaraiza98 at gmail.com Mon Sep 5 15:46:58 2016 From: emaraiza98 at gmail.com (emaraiza98 at gmail.com) Date: Mon, 5 Sep 2016 12:46:58 -0700 (PDT) Subject: Installing python Message-ID: I installed pycharm for a computer science class I'm taking, and also downloaded python 3.5.2. However, my computer for some reason won't use 3.5.2 and my professor told me I needed to download an earlier version to change the project interpreter. Whenever I try to use the earlier version of python for pycharm it says that "the SDK" seems invalid. I don't know what I'm doing wrong and was hoping someone would know what to do. I need to have everything installed and running by Wednesday. From emaraiza98 at gmail.com Mon Sep 5 15:49:29 2016 From: emaraiza98 at gmail.com (emaraiza98 at gmail.com) Date: Mon, 5 Sep 2016 12:49:29 -0700 (PDT) Subject: installing python Message-ID: <8f7f2eb0-3510-4044-8ec0-d019cc650870@googlegroups.com> I installed pycharm for a computer science class, and installed python 3.5.2. However, my computer won't accept 3.5.2 so my teacher told me to install an earlier version to change the project interpreter. I did but when I tried to open python with pycharm it said that the "SKD is invalid". I don't know what I'm doing wrong and I have to have everything installed and running by Wednesday. From alister.ware at ntlworld.com Mon Sep 5 16:01:08 2016 From: alister.ware at ntlworld.com (alister) Date: Mon, 05 Sep 2016 20:01:08 GMT Subject: Installing python References: Message-ID: <8akzz.1286929$3%1.196569@fx40.am4> On Mon, 05 Sep 2016 12:46:58 -0700, emaraiza98 wrote: > I installed pycharm for a computer science class I'm taking, and also > downloaded python 3.5.2. However, my computer for some reason won't use > 3.5.2 and my professor told me I needed to download an earlier version > to change the project interpreter. Whenever I try to use the earlier > version of python for pycharm it says that "the SDK" seems invalid. I > don't know what I'm doing wrong and was hoping someone would know what > to do. I need to have everything installed and running by Wednesday. Are you by any chance still on windows XP? You will need Python V3.4 or earlier. Alternatively upgrade your operating system. Most if not all current Linux distributions should run without trouble on your hardware. They will probably have Python V2.7 as the system python but Python V3 should be available from the package manager & you will probably have a much nicer experience than your windows class mates :-) -- I'm not an Iranian!! I voted for Dianne Feinstein!! From best_lay at yahoo.com Mon Sep 5 18:25:49 2016 From: best_lay at yahoo.com (Wildman) Date: Mon, 05 Sep 2016 17:25:49 -0500 Subject: Installing python References: <8akzz.1286929$3%1.196569@fx40.am4> Message-ID: On Mon, 05 Sep 2016 20:01:08 +0000, alister wrote: > On Mon, 05 Sep 2016 12:46:58 -0700, emaraiza98 wrote: > >> I installed pycharm for a computer science class I'm taking, and also >> downloaded python 3.5.2. However, my computer for some reason won't use >> 3.5.2 and my professor told me I needed to download an earlier version >> to change the project interpreter. Whenever I try to use the earlier >> version of python for pycharm it says that "the SDK" seems invalid. I >> don't know what I'm doing wrong and was hoping someone would know what >> to do. I need to have everything installed and running by Wednesday. > > Are you by any chance still on windows XP? > > You will need Python V3.4 or earlier. > Alternatively upgrade your operating system. > > Most if not all current Linux distributions should run without trouble on > your hardware. > > They will probably have Python V2.7 as the system python but Python V3 > should be available from the package manager & you will probably have a > much nicer experience than your windows class mates :-) A good many Linux distros now have Python 2.7 and 3.x installed. For Python 3.x you would use this hash-bang... #!/usr/bin/env python3 -- GNU/Linux user #557453 The cow died so I don't need your bull! From nospam.jladasky at itu.edu Mon Sep 5 21:31:00 2016 From: nospam.jladasky at itu.edu (jladasky) Date: Tue, 06 Sep 2016 13:31:00 +1200 Subject: Extend unicodedata with a name/pattern/regex search for character References: <223080620@f38.n261.z1.binkp.net> Message-ID: <1629209308@f38.n261.z1.binkp.net> On Saturday, September 3, 2016 at 7:49:14 PM UTC-7, Steve D'Aprano wrote: > On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: > > Killfile him and move on... > > But but but... I couldn't do that. > > https://www.xkcd.com/386/ I strongly suspected it would be that particular XKCD. :^) From denis.akhiyarov at gmail.com Mon Sep 5 22:54:25 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Mon, 5 Sep 2016 19:54:25 -0700 (PDT) Subject: Pythons for .Net In-Reply-To: <57cb7e82$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <57959574$0$1586$c3e8da3$5496439d@news.astraweb.com> <0addc29e-b1c0-408c-bd61-96ca8576565d@googlegroups.com> <57cb7e82$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, September 3, 2016 at 8:53:18 PM UTC-5, Steve D'Aprano wrote: > On Sat, 3 Sep 2016 12:34 pm, Denis Akhiyarov wrote: > > > Finally if anyone can contact Christian Heimes (Python Core Developer), > > then please ask him to reply on request to update the license to MIT: > > > > https://github.com/pythonnet/pythonnet/issues/234 > > > > He is the only contributor that prevents updating to MIT license. > > > I have emailed him off-list. > > Thanks for the information on PythonNet, Denis. > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. Emailing and twitter did not help either. From charleshixsn at earthlink.net Mon Sep 5 23:25:00 2016 From: charleshixsn at earthlink.net (nospam.Charles Hixson) Date: Tue, 06 Sep 2016 15:25:00 +1200 Subject: Multiprocessing interactive processes with connections Message-ID: <2209457216@f38.n261.z1.binkp.net> I want to process a bunch of processes that all talk to each other. I've figured out how to do this using queues with the main process as the mail handler, but I'd rather have them talk directly. If I use connections, then I can pass the pipes to the processes, but there doesn't seem to be anything analogous to queue, so it looks like I need to divide each process into two threads, one of which does nothing but mail handling. Is this correct? FWIW, a small, unoptimized, test of the working "mailhandler" approach is: ## Multiprocessing: main thread as post office. # This is a bit clumsy, but it works. from multiprocessing import Process, Queue from queue import Empty def f(i, lim, q_rcv, q_snd): for j in range(lim): if i != j: q_snd.put([i, "message from process {0} to proess {1}".format(i, j), j]) if not q_rcv.empty(): val = q_rcv.get() print (val) q_snd.put([i, "done"]) while (not q_recv.empty()): val = q_rcv.get() print (val, " :: ", i) if val == "done": return if __name__ == '__main__': ps = [] qs = [] q_recv = Queue() for i in range(3): q = Queue() qs.append (q) ps.append (Process(target=f, args=(i, 3, q, q_recv)) ) for p in ps: p.start() dones = 0 try: v = q_recv.get(True, 1) while (v): print ("v = ", v) if v[1] == "done": dones = dones + 1 else: if len(v) == 3: assert v[2] < len(qs), "unexpected value" qs[v[2]].put(v[1]) else: print ("error: ", v, " was an unexpected value.") v = q_recv.get(True, 1) except Empty: print ("1: Timeout of maine receive queue") for q in qs: q.put("done") try: v = q_recv.get(True, 1) while (v): print ("2: v = ", v) if v[1] == "done": dones = dones + 1 else: if len(v) == 3: assert v[3] < len(qs), "2: unexpected value" qs[v[3]].put(v[2]) else: print ("2: error: ", v, " was an unexpected value.") v = q_recv.get(True, 1) except Empty: print ("2: Timeout of maine receive queue") for i in range(len(qs)): qs[i].close(); qs[i] = None From gang.yang.ctr at mail.mil Tue Sep 6 04:59:00 2016 From: gang.yang.ctr at mail.mil (nospam. Yang, Gang CTR (US)) Date: Tue, 06 Sep 2016 20:59:00 +1200 Subject: Python 3.5.0 python --version command reports 2.5.4 Message-ID: <820523894@f38.n261.z1.binkp.net> Hi, I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008 R2) and tried the python --version command. Surprisingly, the command reported 2.5.4. What's going on? Gang Yang Shonborn-Becker Systems Inc. (SBSI) Contractor Engineering Supporting SEC Office: 732-982-8561, x427 Cell: 732-788-7501 Email: gang.yang.ctr at mail.mil From smith at smith.com Tue Sep 6 05:00:43 2016 From: smith at smith.com (Smith) Date: Tue, 6 Sep 2016 11:00:43 +0200 Subject: Class - error return Message-ID: Hi, you can help me ? I can not understand where is the error in this script. Use Python3. In [71]: class Day(object): ...: def __init__(self,visits,contacts): ...: self.visits = visits ...: self.contacts = contacts ...: def __add__(self,other): ...: total_visits = self.visits + other.visits ...: total_contacts = self.contacts + other.contacts ...: return Day(total_visits,total_contacts) ...: def __radd__(self,other): ...: if other == 0: ...: return self ...: else: ...: return self.__add__(other) ...: def __str__(self): ...: return "Visitor: %i, Contacts: %i % (self.visits,self.contacts)" ...: ...: In [72]: day1 = Day(8,9) In [73]: day2 = Day(7,7) In [74]: print(day1) Visitor: %i, Contacts: %i % (self.visits,self.contacts) In [75]: print(day2) Visitor: %i, Contacts: %i % (self.visits,self.contacts) From __peter__ at web.de Tue Sep 6 05:23:58 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Sep 2016 11:23:58 +0200 Subject: Class - error return References: Message-ID: Smith wrote: > you can help me ? Yes ;) But you might consider posting on python-tutor instead of python- list. > I can not understand where is the error in this script. It's always a good idea to state both what you expect and what you get instead explicitly, in plain english. > In [72]: day1 = Day(8,9) > In [74]: print(day1) > Visitor: %i, Contacts: %i % (self.visits,self.contacts) That might pass as the "what you get" part; I suppose you expect it to print Visitor: 8, Contacts: 9 If so look at > ...: def __str__(self): > ...: return "Visitor: %i, Contacts: %i % > (self.visits,self.contacts)" once more. Where are the quotes? Where should the be? From smith at smith.it Tue Sep 6 05:49:00 2016 From: smith at smith.it (nospam.Smith) Date: Tue, 06 Sep 2016 21:49:00 +1200 Subject: Class - error return References: <206073440@f38.n261.z1.binkp.net> Message-ID: <4230465206@f38.n261.z1.binkp.net> On 06/09/2016 11:23, Peter Otten wrote: > If so look at > >> > ...: def __str__(self): >> > ...: return "Visitor: %i, Contacts: %i % >> > (self.visits,self.contacts)" > once more. Where are the quotes? Where should the be? > > > I solved the problem. thank you Peter From vek.m1234 at gmail.com Tue Sep 6 06:06:32 2016 From: vek.m1234 at gmail.com (Veek 'this_is_not_my_name' M) Date: Tue, 06 Sep 2016 15:36:32 +0530 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: Message-ID: Rustom Mody wrote: > On Saturday, September 3, 2016 at 5:25:48 PM UTC+5:30, Veek. M wrote: >> https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm >> >> Wanted to know if the above link idea, had been implemented and if >> there's a module that accepts a pattern like 'cap' and give you all >> the instances of unicode 'CAP' characters. >> ? \bigcap >> ? \sqcap >> ? \cap >> ? \capricornus >> ? \succapprox >> ? \precapprox >> >> (above's from tex) >> >> I found two useful modules in this regard: unicode_tex, unicodedata >> but unicodedata is a builtin which does not do globs, regexs - so >> it's kind of limiting in nature. >> >> Would be nice if you could search html/xml character entity >> references as well. > > [Not exactly an answer] > > I use a number of things for such > 1. Google > 2. Xah Lee?s excellent pages which often fit my brain better than > wikipedia: > http://xahlee.info/comp/unicode_index.html > 3. emacs? function ucs-insert recently renamed to insert-char > ie [In emacs] Type Alt-x insert-char > After that some kind of TAB-globbing (case-insensitive) works > I wont try with Cap (because the number of *CAPITAL* is in > thousands!) eg alphaTAB gives nothing. However *alphaTAB gives a > bunch. Narrow to "greek alpha"TAB and you get a bunch > > > The fact that we should have a series of levels for char-input from > most general and unergonomic (google) to most specific and ergonomic > (special purpose keyboard) Ive tried to talk of as 7 levels near end > of http://blog.languager.org/2015/01/unicode-and-universe.html got dengu - i'm dead From jladasky at f38.n261.z1 Tue Sep 6 09:31:00 2016 From: jladasky at f38.n261.z1 (jladasky at f38.n261.z1) Date: Tue, 06 Sep 2016 23:31:00 +1000 Subject: Extend unicodedata with a name/pattern/regex search for character References: <223080620@f38.n261.z1.ftn> Message-ID: <1629209308@f38.n261.z1.ftn> From: jladasky at itu.edu On Saturday, September 3, 2016 at 7:49:14 PM UTC-7, Steve D'Aprano wrote: > On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: > > Killfile him and move on... > > But but but... I couldn't do that. > > https://www.xkcd.com/386/ I strongly suspected it would be that particular XKCD. :^) From gyan.am010 at gmail.com Tue Sep 6 10:55:20 2016 From: gyan.am010 at gmail.com (GP) Date: Tue, 6 Sep 2016 07:55:20 -0700 (PDT) Subject: Suggestions to improve a code Message-ID: <44969ca1-67d0-4d5d-8fe4-f2531b66fcf9@googlegroups.com> I have a list: shelves2 =[{'Part No': '1', 'Length': 610.0, 'Width': 50.0}, {'Part No': '2', 'Length': 2319.0, 'Width': 465.0 }, {'Part No': '3', 'Length': 5.0,'Width': 465.0}] The length of shelf is calculated as follows: 1. Calculate the maximum length of all items in the shelf. 2. Calculate width of shelf = 610 (in this case). 3. Length of shelf : maxlength of all items + length ( if it less than width of shelf) or width of other items such that length of shelf is less than maximum allowed length. In the above case the length is 2319+50+5 = 2374. I have the following code which generates it correctly but would like to know if there is a better way to write it. I would like to know some smarter way to write the code ( especially if the "for", "if" statements can be avoided). list_1=[] list_2=[] WidthOfShelf = max([x['Width'] for x in shelves2]) MaxLengthOfItem = max([x['Length'] for x in shelves2]) f_LMax=lambda seq, m: [ii for ii in range(0, len(seq)) if seq[ii] ['Length'] >= m][0] MaxLengthOfItem_Index =f_LMax(shelves2,MaxLengthOfItem) current= MaxLengthOfItem list_1=[shelves2[MaxLengthOfItem_Index]] list_2 = [MaxLengthOfItem] del shelves2[MaxLengthOfItem_Index] for i in range(0,len(shelves2)): if shelves2[i]['Length'] <= Width: if (current + shelves2[i]['Length']) or (current + shelves2 [i]['Width'])<= 2438.5 : q_2= min(shelves2[i]['Length'], shelves2[i]['Width']) q=shelves2[i] list_1.append(q) list_2.append(q_2) current += (shelves2[i]['Length'] or shelves2[i] ['Width']) length = sum(list_2) print("LENGTH:",length) From Charles_Hixson at f38.n261.z1 Tue Sep 6 11:25:00 2016 From: Charles_Hixson at f38.n261.z1 (Charles_Hixson at f38.n261.z1) Date: Wed, 07 Sep 2016 01:25:00 +1000 Subject: Multiprocessing interactive processes with connections Message-ID: <2209457216@f38.n261.z1.ftn> From: Charles Hixson I want to process a bunch of processes that all talk to each other. I've figured out how to do this using queues with the main process as the mail handler, but I'd rather have them talk directly. If I use connections, then I can pass the pipes to the processes, but there doesn't seem to be anything analogous to queue, so it looks like I need to divide each process into two threads, one of which does nothing but mail handling. Is this correct? FWIW, a small, unoptimized, test of the working "mailhandler" approach is: ## Multiprocessing: main thread as post office. # This is a bit clumsy, but it works. from multiprocessing import Process, Queue from queue import Empty def f(i, lim, q_rcv, q_snd): for j in range(lim): if i != j: q_snd.put([i, "message from process {0} to proess {1}".format(i, j), j]) if not q_rcv.empty(): val = q_rcv.get() print (val) q_snd.put([i, "done"]) while (not q_recv.empty()): val = q_rcv.get() print (val, " :: ", i) if val == "done": return if __name__ == '__main__': ps = [] qs = [] q_recv = Queue() for i in range(3): q = Queue() qs.append (q) ps.append (Process(target=f, args=(i, 3, q, q_recv)) ) for p in ps: p.start() dones = 0 try: v = q_recv.get(True, 1) while (v): print ("v = ", v) if v[1] == "done": dones = dones + 1 else: if len(v) == 3: assert v[2] < len(qs), "unexpected value" qs[v[2]].put(v[1]) else: print ("error: ", v, " was an unexpected value.") v = q_recv.get(True, 1) except Empty: print ("1: Timeout of maine receive queue") for q in qs: q.put("done") try: v = q_recv.get(True, 1) while (v): print ("2: v = ", v) if v[1] == "done": dones = dones + 1 else: if len(v) == 3: assert v[3] < len(qs), "2: unexpected value" qs[v[3]].put(v[2]) else: print ("2: error: ", v, " was an unexpected value.") v = q_recv.get(True, 1) except Empty: print ("2: Timeout of maine receive queue") for i in range(len(qs)): qs[i].close(); qs[i] = None From best_lay at yahoo.com Tue Sep 6 12:13:47 2016 From: best_lay at yahoo.com (Wildman) Date: Tue, 06 Sep 2016 11:13:47 -0500 Subject: Python 3 curiosity. References: <4c1d6a3f-9341-492c-9b44-0e86876e34ca@googlegroups.com> Message-ID: On Tue, 06 Sep 2016 02:51:39 -0700, wxjmfauth wrote: > It's curious to see all these apps, that were > more of less working correctly up to Python 3.2 > (included) and are now no more working at all. > > Probably something wrong somewhere... http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html -- GNU/Linux user #557453 The cow died so I don't need your bull! From rosuav at gmail.com Tue Sep 6 12:27:40 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Sep 2016 02:27:40 +1000 Subject: Python 3 curiosity. In-Reply-To: References: <4c1d6a3f-9341-492c-9b44-0e86876e34ca@googlegroups.com> Message-ID: On Wed, Sep 7, 2016 at 2:13 AM, Wildman via Python-list wrote: > On Tue, 06 Sep 2016 02:51:39 -0700, wxjmfauth wrote: > >> It's curious to see all these apps, that were >> more of less working correctly up to Python 3.2 >> (included) and are now no more working at all. >> >> Probably something wrong somewhere... > > http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html That's jmf, and he never actually posts proof, but keeps on asserting that Unicode handling in Python 3.3+ is "broken". Actually, it's not. The worst criticism you can level at it is that it may be slower in certain microbenchmarks... but only if you're comparing against a *narrow build* of Python 3.2, which is *buggy*. In other words, Python eliminated an endemic bug, and actually improved performance overall, but worsened it on a very VERY few cases. Most of us have either killfiled him, or are reading this via the mailing list, which doesn't carry his traffic. I suggest you do the same. He's a crank. ChrisA From best_lay at yahoo.com Tue Sep 6 13:43:03 2016 From: best_lay at yahoo.com (Wildman) Date: Tue, 06 Sep 2016 12:43:03 -0500 Subject: Python 3 curiosity. References: <4c1d6a3f-9341-492c-9b44-0e86876e34ca@googlegroups.com> Message-ID: <2f-dnZN0j5O6nVLKnZ2dnUU7-TudnZ2d@giganews.com> On Wed, 07 Sep 2016 02:27:40 +1000, Chris Angelico wrote: > On Wed, Sep 7, 2016 at 2:13 AM, Wildman via Python-list > wrote: >> On Tue, 06 Sep 2016 02:51:39 -0700, wxjmfauth wrote: >> >>> It's curious to see all these apps, that were >>> more of less working correctly up to Python 3.2 >>> (included) and are now no more working at all. >>> >>> Probably something wrong somewhere... >> >> http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html > > That's jmf, and he never actually posts proof, but keeps on asserting > that Unicode handling in Python 3.3+ is "broken". Actually, it's not. > The worst criticism you can level at it is that it may be slower in > certain microbenchmarks... but only if you're comparing against a > *narrow build* of Python 3.2, which is *buggy*. In other words, Python > eliminated an endemic bug, and actually improved performance overall, > but worsened it on a very VERY few cases. > > Most of us have either killfiled him, or are reading this via the > mailing list, which doesn't carry his traffic. I suggest you do the > same. He's a crank. > > ChrisA Thanks for the heads-up. -- GNU/Linux user #557453 "Be at war with your vices, at peace with your neighbors, and let every new year find you a better man." -Benjamin Franklin From smith at smith.it Tue Sep 6 15:49:10 2016 From: smith at smith.it (Smith) Date: Tue, 6 Sep 2016 21:49:10 +0200 Subject: Class - error return In-Reply-To: References: Message-ID: On 06/09/2016 11:23, Peter Otten wrote: > If so look at > >> > ...: def __str__(self): >> > ...: return "Visitor: %i, Contacts: %i % >> > (self.visits,self.contacts)" > once more. Where are the quotes? Where should the be? > > > I solved the problem. thank you Peter From jladasky at itu.edu Tue Sep 6 16:31:36 2016 From: jladasky at itu.edu (jladasky at itu.edu) Date: Tue, 6 Sep 2016 13:31:36 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: <57cb8ba0$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <2829361.aeNJFYEL58@PointedEars.de> <57cb7e3c$0$22142$c3e8da3$5496439d@news.astraweb.com> <57cb8ba0$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, September 3, 2016 at 7:49:14 PM UTC-7, Steve D'Aprano wrote: > On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: > > Killfile him and move on... > > But but but... I couldn't do that. > > https://www.xkcd.com/386/ I strongly suspected it would be that particular XKCD. :^) From US at f38.n261.z1 Tue Sep 6 16:59:00 2016 From: US at f38.n261.z1 (US at f38.n261.z1) Date: Wed, 07 Sep 2016 06:59:00 +1000 Subject: Python 3.5.0 python --version command reports 2.5.4 Message-ID: <820523894@f38.n261.z1.ftn> From: "Yang, Gang CTR (US)" Hi, I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008 R2) and tried the python --version command. Surprisingly, the command reported 2.5.4. What's going on? Gang Yang Shonborn-Becker Systems Inc. (SBSI) Contractor Engineering Supporting SEC Office: 732-982-8561, x427 Cell: 732-788-7501 Email: gang.yang.ctr at mail.mil From gang.yang.ctr at mail.mil Tue Sep 6 16:59:08 2016 From: gang.yang.ctr at mail.mil (Yang, Gang CTR (US)) Date: Tue, 6 Sep 2016 20:59:08 +0000 Subject: Python 3.5.0 python --version command reports 2.5.4 Message-ID: <82AE9B2456FC17429CDD874AE33B89608684BA38@UCOLHPUC.easf.csd.disa.mil> Hi, I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008 R2) and tried the python --version command. Surprisingly, the command reported 2.5.4. What's going on? Gang Yang Shonborn-Becker Systems Inc. (SBSI) Contractor Engineering Supporting SEC Office: 732-982-8561, x427 Cell: 732-788-7501 Email: gang.yang.ctr at mail.mil From Smith at f38.n261.z1 Tue Sep 6 17:49:00 2016 From: Smith at f38.n261.z1 (Smith at f38.n261.z1) Date: Wed, 07 Sep 2016 07:49:00 +1000 Subject: Class - error return References: <206073440@f38.n261.z1.ftn> Message-ID: <4230465206@f38.n261.z1.ftn> From: Smith On 06/09/2016 11:23, Peter Otten wrote: > If so look at > >> > ...: def __str__(self): >> > ...: return "Visitor: %i, Contacts: %i % >> > (self.visits,self.contacts)" > once more. Where are the quotes? Where should the be? > > > I solved the problem. thank you Peter From charleshixsn at earthlink.net Tue Sep 6 18:25:25 2016 From: charleshixsn at earthlink.net (Charles Hixson) Date: Tue, 6 Sep 2016 15:25:25 -0700 Subject: Multiprocessing interactive processes with connections Message-ID: <8df3d58e-d1ee-ff08-8ac7-e6e50549ce5c@earthlink.net> I want to process a bunch of processes that all talk to each other. I've figured out how to do this using queues with the main process as the mail handler, but I'd rather have them talk directly. If I use connections, then I can pass the pipes to the processes, but there doesn't seem to be anything analogous to queue, so it looks like I need to divide each process into two threads, one of which does nothing but mail handling. Is this correct? FWIW, a small, unoptimized, test of the working "mailhandler" approach is: ## Multiprocessing: main thread as post office. # This is a bit clumsy, but it works. from multiprocessing import Process, Queue from queue import Empty def f(i, lim, q_rcv, q_snd): for j in range(lim): if i != j: q_snd.put([i, "message from process {0} to proess {1}".format(i, j), j]) if not q_rcv.empty(): val = q_rcv.get() print (val) q_snd.put([i, "done"]) while (not q_recv.empty()): val = q_rcv.get() print (val, " :: ", i) if val == "done": return if __name__ == '__main__': ps = [] qs = [] q_recv = Queue() for i in range(3): q = Queue() qs.append (q) ps.append (Process(target=f, args=(i, 3, q, q_recv)) ) for p in ps: p.start() dones = 0 try: v = q_recv.get(True, 1) while (v): print ("v = ", v) if v[1] == "done": dones = dones + 1 else: if len(v) == 3: assert v[2] < len(qs), "unexpected value" qs[v[2]].put(v[1]) else: print ("error: ", v, " was an unexpected value.") v = q_recv.get(True, 1) except Empty: print ("1: Timeout of maine receive queue") for q in qs: q.put("done") try: v = q_recv.get(True, 1) while (v): print ("2: v = ", v) if v[1] == "done": dones = dones + 1 else: if len(v) == 3: assert v[3] < len(qs), "2: unexpected value" qs[v[3]].put(v[2]) else: print ("2: error: ", v, " was an unexpected value.") v = q_recv.get(True, 1) except Empty: print ("2: Timeout of maine receive queue") for i in range(len(qs)): qs[i].close(); qs[i] = None From breamoreboy at gmail.com Tue Sep 6 18:57:27 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Tue, 6 Sep 2016 15:57:27 -0700 (PDT) Subject: Python 3.5.0 python --version command reports 2.5.4 In-Reply-To: References: <82AE9B2456FC17429CDD874AE33B89608684BA38@UCOLHPUC.easf.csd.disa.mil> Message-ID: <5339a9c7-31c8-4c07-afdf-85d83e01d25c@googlegroups.com> On Tuesday, September 6, 2016 at 10:06:34 PM UTC+1, Yang, Gang CTR (US) wrote: > Hi, > > I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008 R2) and tried the python --version command. Surprisingly, the command reported 2.5.4. What's going on? > > Gang Yang > You'll need to change your environment settings. All the details are here https://docs.python.org/3/using/windows.html Kindest regards. Mark Lawrence From tjreedy at udel.edu Wed Sep 7 00:42:54 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 7 Sep 2016 00:42:54 -0400 Subject: Python 3.5.0 python --version command reports 2.5.4 In-Reply-To: <820523894@f38.n261.z1.ftn> References: <820523894@f38.n261.z1.ftn> Message-ID: On 9/6/2016 4:59 PM, US at f38.n261.z1 wrote: > I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008 > R2) and tried the python --version command. Surprisingly, the command reported > 2.5.4. What's going on? Most likely you have 2.5.4 installed and are running it. -- Terry Jan Reedy From redstone-cold at 163.com Wed Sep 7 03:08:02 2016 From: redstone-cold at 163.com (iMath) Date: Wed, 7 Sep 2016 00:08:02 -0700 (PDT) Subject: easy way to return a list of absolute file or directory path within a directory Message-ID: Any easier solutions on returning a list of absolute file or directory path within a directory? Mine is list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory))) From steve+comp.lang.python at pearwood.info Wed Sep 7 03:59:06 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 07 Sep 2016 17:59:06 +1000 Subject: easy way to return a list of absolute file or directory path within a directory References: Message-ID: <57cfc8cb$0$1614$c3e8da3$5496439d@news.astraweb.com> On Wednesday 07 September 2016 17:08, iMath wrote: > Any easier solutions on returning a list of absolute file or directory path > within a directory? Mine is > > list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory))) Use a list comprehension: [os.path.join(directory,entry) for entry in os.listdir(directory)] -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From santhoshkumardavala at gmail.com Wed Sep 7 08:24:01 2016 From: santhoshkumardavala at gmail.com (Davala santhosh kumar) Date: Wed, 7 Sep 2016 05:24:01 -0700 (PDT) Subject: logging files Message-ID: how to run psutil.cputimes() program in remote machines using logfiles. From moibenko at fnal.gov Wed Sep 7 10:17:00 2016 From: moibenko at fnal.gov (Alexander N. Moibenko) Date: Wed, 7 Sep 2016 09:17:00 -0500 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> Message-ID: Hello, when I build a binary with python 2.6 it builds without any problem. When I build with python 2.7 the build fails after warnings like: /opt/python/Python-2.7.12/Modules/posixmodule.o: In function `posix_tempnam': /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the use of `tempnam' is dangerous, better use `mkstemp' collect2: ld returned 1 exit status How this can be fixed? Thanks, Alexander From asadurrehman319 at gmail.com Wed Sep 7 11:51:36 2016 From: asadurrehman319 at gmail.com (Asad ur Rehman) Date: Wed, 7 Sep 2016 08:51:36 -0700 (PDT) Subject: How to split value where is comma ? Message-ID: Here is my view.py import os.path import commands def call_report(request): a = commands.getstatusoutput('/usr/local/freeswitch/bin/fs_cli -x "show calls"') return HttpResponse(a) When i run this command it gives output which you can see... 0uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,hostname,sent_callee_name,sent_callee_num,b_uuid,b_direction,b_created,b_created_epoch,b_name,b_state,b_cid_name,b_cid_num,b_ip_addr,b_dest,b_presence_id,b_presence_data,b_callstate,b_callee_name,b_callee_num,b_callee_direction,b_sent_callee_name,b_sent_callee_num,call_created_epoch 7135c05c-7511-11e6-a09e-89a1f4981d2c,outbound,2016-09-07 11:40:45,1473262845,sofia/external/12036325207,CS_EXECUTE,Outbound Call,12036325207,,12036325207,,,ACTIVE,9047125683,9047125683,RECV,7135c05c-7511-11e6-a09e-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 75a9d3ee-7511-11e6-a115-89a1f4981d2c,outbound,2016-09-07 11:40:53,1473262853,sofia/external/12036325259,CS_EXECUTE,Outbound Call,12036325259,,12036325259,,,ACTIVE,9047125683,9047125683,RECV,75a9d3ee-7511-11e6-a115-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7841c6c0-7511-11e6-a139-89a1f4981d2c,outbound,2016-09-07 11:40:57,1473262857,sofia/external/16189973135,CS_EXECUTE,Outbound Call,16189973135,,16189973135,,,ACTIVE,3473788006,3473788006,RECV,7841c6c0-7511-11e6-a139-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 78582a82-7511-11e6-a141-89a1f4981d2c,outbound,2016-09-07 11:40:57,1473262857,sofia/external/16185392123,CS_EXECUTE,Outbound Call,16185392123,,16185392123,,,ACTIVE,3473788006,3473788006,RECV,78582a82-7511-11e6-a141-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 79eda1ec-7511-11e6-a161-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/12037584114,CS_EXECUTE,Outbound Call,12037584114,,12037584114,,,ACTIVE,3473788006,3473788006,RECV,79eda1ec-7511-11e6-a161-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a02bb90-7511-11e6-a169-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/13346775290,CS_EXECUTE,Outbound Call,13346775290,,13346775290,,,ACTIVE,3473788006,3473788006,RECV,7a02bb90-7511-11e6-a169-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a1fa002-7511-11e6-a179-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/15154483189,CS_EXECUTE,Outbound Call,15154483189,,15154483189,,,ACTIVE,3473788006,3473788006,RECV,7a1fa002-7511-11e6-a179-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a20d864-7511-11e6-a181-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/12036325257,CS_EXECUTE,Outbound Call,12036325257,,12036325257,,,ACTIVE,9047125683,9047125683,RECV,7a20d864-7511-11e6-a181-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a354cf4-7511-11e6-a191-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/13348725798,CS_EXECUTE,Outbound Call,13348725798,,13348725798,,,ACTIVE,9047125683,9047125683,RECV,7a354cf4-7511-11e6-a191-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7e90e128-7511-11e6-a1d4-89a1f4981d2c,outbound,2016-09-07 11:41:07,1473262867,sofia/external/13345880337,CS_EXECUTE,Outbound Call,13345880337,,13345880337,,,ACTIVE,9047125683,9047125683,RECV,7e90e128-7511-11e6-a1d4-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7e9c3514-7511-11e6-a1e8-89a1f4981d2c,outbound,2016-09-07 11:41:08,1473262868,sofia/external/12036325256,CS_EXECUTE,Outbound Call,12036325256,,12036325256,,,ACTIVE,9047125683,9047125683,RECV,7e9c3514-7511-11e6-a1e8-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7f3cdc62-7511-11e6-a1ff-89a1f4981d2c,outbound,2016-09-07 11:41:09,1473262869,sofia/external/13344992844,CS_EXECUTE,Outbound Call,13344992844,,13344992844,,,ACTIVE,9047125683,9047125683,RECV,7f3cdc62-7511-11e6-a1ff-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 82179454-7511-11e6-a228-89a1f4981d2c,outbound,2016-09-07 11:41:13,1473262873,sofia/external/16185392157,CS_EXECUTE,Outbound But i want to get output like this 0uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,hostname,sent_callee_name,sent_callee_num,b_uuid,b_direction,b_created,b_created_epoch,b_name,b_state,b_cid_name,b_cid_num,b_ip_addr,b_dest,b_presence_id,b_presence_data,b_callstate,b_callee_name,b_callee_num,b_callee_direction,b_sent_callee_name,b_sent_callee_num,call_created_epoch 7135c05c-7511-11e6-a09e-89a1f4981d2c,outbound,2016-09-07 11:40:45,1473262845,sofia/external/12036325207,CS_EXECUTE,Outbound Call,12036325207,,12036325207,,,ACTIVE,9047125683,9047125683,RECV,7135c05c-7511-11e6-a09e-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 75a9d3ee-7511-11e6-a115-89a1f4981d2c,outbound,2016-09-07 11:40:53, 1473262853, sofia/external/1203632525,CS_EXECUTE, Outbound Call, 12036325259, ,12036325259, , ,ACTIVE, 9047125683, 9047125683, RECV, 75a9d3ee-7511-11e6-a115-89a1f4981d2c, vb-pmedia,,,,,,,,,,,,,,,,,,,,,7841c6c0-7511-11e6-a139-89a1f4981d2c, outbound,2016-09-07 11:40:57,1473262857,sofia/external/16189973135, where is a comma there should start new line ... How can i do it ? Thanks in advance ! From Joaquin.Alzola at lebara.com Wed Sep 7 12:04:40 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Wed, 7 Sep 2016 16:04:40 +0000 Subject: How to split value where is comma ? In-Reply-To: References: Message-ID: > where is a comma there should start new line ... How can i do it ? Use the split a.split(",") for x in a: print(x) This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From gang.yang.ctr at mail.mil Wed Sep 7 12:10:58 2016 From: gang.yang.ctr at mail.mil (Yang, Gang CTR (US)) Date: Wed, 7 Sep 2016 16:10:58 +0000 Subject: [Non-DoD Source] Re: Python 3.5.0 python --version command reports 2.5.4 In-Reply-To: References: <820523894@f38.n261.z1.ftn>, Message-ID: <82AE9B2456FC17429CDD874AE33B89608684BC05@UCOLHPUC.easf.csd.disa.mil> Thanks to all that replied. Indeed I had CollabNet SVN server installed a while back and it came with an older version of Python. Gang Yang Shonborn-Becker Systems Inc. (SBSI) Contractor Engineering Supporting SEC Office: 732-982-8561, x427 Cell: 732-788-7501 Email: gang.yang.ctr at mail.mil ________________________________ From: Python-list [python-list-bounces+gang.yang.ctr=mail.mil at python.org] on behalf of Terry Reedy [tjreedy at udel.edu] Sent: Wednesday, September 07, 2016 12:42 AM To: python-list at python.org Subject: [Non-DoD Source] Re: Python 3.5.0 python --version command reports 2.5.4 All active links contained in this email were disabled. Please verify the identity of the sender, and confirm the authenticity of all links contained within the message prior to copying and pasting the address to a Web browser. ---- On 9/6/2016 4:59 PM, US at f38.n261.z1 wrote: > I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008 > R2) and tried the python --version command. Surprisingly, the command reported > 2.5.4. What's going on? Most likely you have 2.5.4 installed and are running it. -- Terry Jan Reedy -- Caution-https://mail.python.org/mailman/listinfo/python-list From pkpearson at nowhere.invalid Wed Sep 7 13:05:27 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 7 Sep 2016 17:05:27 GMT Subject: How to split value where is comma ? References: Message-ID: On Wed, 7 Sep 2016 08:51:36 -0700 (PDT), Asad ur Rehman wrote: [snip] > sofia/external/1203632525,CS_EXECUTE, > Outbound Call, > 12036325259, > ,12036325259, > , > ,ACTIVE, > 9047125683, > 9047125683, > RECV, > 75a9d3ee-7511-11e6-a115-89a1f4981d2c, > vb-pmedia,,,,,,,,,,,,,,,,,,,,,7841c6c0-7511-11e6-a139-89a1f4981d2c, > outbound,2016-09-07 11:40:57,1473262857,sofia/external/16189973135, > > where is a comma there should start new line ... How can i do it ? Is your question "Given a string that may contain some commas, how do I insert a newline after each comma"? (Note that that is *not* what you show, but from what you show I can't tell what you want.) -- To email me, substitute nowhere->runbox, invalid->com. From ben+python at benfinney.id.au Wed Sep 7 18:36:12 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Sep 2016 08:36:12 +1000 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> Message-ID: <85twdrs5gj.fsf@benfinney.id.au> "Alexander N. Moibenko" writes: > /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the > use of `tempnam' is dangerous, better use `mkstemp' > collect2: ld returned 1 exit status > > How this can be fixed? The clearest answer is already there in the warning message. Replace your use of ?tempnam? with ?mkstemp?. If you don't know what that means because you didn't write the code, then this is for whoever is maintaining that code. Read it, learn what it does, find (or write) its unit tests to make sue you don't break anything; then, change that usage as suggested. -- \ ?Consider the daffodil. And while you're doing that, I'll be | `\ over here, looking through your stuff.? ?Jack Handey | _o__) | Ben Finney From py at blacktoli.com Wed Sep 7 19:50:08 2016 From: py at blacktoli.com (py at blacktoli.com) Date: Thu, 08 Sep 2016 01:50:08 +0200 Subject: dictionary total sum Message-ID: <54156781bd7123c97c4dfe6c0f2645f4@blacktoli.com> Hello, any ideas why this does not work? >>> def add(key, num): ... a[key] += num ... >>> a={} >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22) >>> a {'007-12': 22} # OK here, this is what I want >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22) >>> a {'007-12': None} # why does this became None? Thanks From ned at nedbatchelder.com Wed Sep 7 20:45:03 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 7 Sep 2016 17:45:03 -0700 (PDT) Subject: dictionary total sum In-Reply-To: References: <54156781bd7123c97c4dfe6c0f2645f4@blacktoli.com> Message-ID: <47bee991-c7cb-4a16-b415-50eea17235a0@googlegroups.com> On Wednesday, September 7, 2016 at 8:25:42 PM UTC-4, p... at blacktoli.com wrote: > Hello, > > any ideas why this does not work? > > >>> def add(key, num): > ... a[key] += num > ... > >>> a={} > >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22) > >>> a > {'007-12': 22} # OK here, this is what I want > >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22) > >>> a > {'007-12': None} # why does this became None? > > Thanks Your add() function returns None (because it has no return statements). Your failing statement is assigning that None to a["007-12"]. There are a number of helpful structures in Python to do this work for you. collections.Counter will probably be helpful: >>> from collections import Counter >>> a = Counter() >>> a["007-12"] += 22 >>> a Counter({'007-12': 22}) >>> a["007-12"] += 22 >>> a Counter({'007-12': 44}) --Ned. From Joaquin.Alzola at lebara.com Wed Sep 7 21:00:59 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Thu, 8 Sep 2016 01:00:59 +0000 Subject: dictionary total sum In-Reply-To: <47bee991-c7cb-4a16-b415-50eea17235a0@googlegroups.com> References: <54156781bd7123c97c4dfe6c0f2645f4@blacktoli.com> <47bee991-c7cb-4a16-b415-50eea17235a0@googlegroups.com> Message-ID: On Wednesday, September 7, 2016 at 8:25:42 PM UTC-4, p... at blacktoli.com wrote: > Hello, > > any ideas why this does not work? > > >>> def add(key, num): > ... a[key] += num > ... > >>> a={} > >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22) > >>> a > {'007-12': 22} # OK here, this is what I want > >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22) > >>> a > {'007-12': None} # why does this became None? > > Thanks >Your add() function returns None (because it has no return statements). >Your failing statement is assigning that None to a["007-12"]. >There are a number of helpful structures in Python to do this work for you. collections.Counter will probably be helpful: > >>> from collections import Counter > >>> a = Counter() > >>> a["007-12"] += 22 > >>> a > Counter({'007-12': 22}) > >>> a["007-12"] += 22 > >>> a > Counter({'007-12': 44}) Hi Ned Also: >>> a={} >>> a["007-12"]=22 >>> a {'007-12': 22} >>> a["007-12"]+=22 >>> a {'007-12': 44} >>> Will this fit his request? This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From lawrencedo99 at gmail.com Wed Sep 7 21:30:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 7 Sep 2016 18:30:02 -0700 (PDT) Subject: Does This Scare You? In-Reply-To: References: <439fbfc4-7ea6-4605-837f-9c138d295e34@googlegroups.com> <9035c731-3f57-6bfd-1c6f-d3d6695da3b6@gmail.com> Message-ID: On Monday, August 22, 2016 at 4:18:39 PM UTC+12, eryk sun wrote: > It would help to consult a reverse-engineered implementation of > RtlGetFullPathName_Ustr and RtlIsDosDeviceName_Ustr. I'll check the > ReactOS source code. This might also be useful (found from ). From lawrencedo99 at gmail.com Wed Sep 7 21:51:53 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 7 Sep 2016 18:51:53 -0700 (PDT) Subject: The Joys Of Data-Driven Programming In-Reply-To: <239aa219-4cd6-4c67-af11-21b2f655c644@googlegroups.com> References: <239aa219-4cd6-4c67-af11-21b2f655c644@googlegroups.com> Message-ID: On Thursday, August 18, 2016 at 2:36:31 PM UTC+12, I wrote: > Solution: set up a table of rules ... Here is another example. The problem is to list all external file dependencies of a Blender document, to ensure that they exist etc. Currently, as far as I know, these external files might be fonts, images, libraries (additional Blender documents containing linked assets) and sounds. The processing for all of these is very similar. But within some categories, there are special cases for items which need to be ignored. So my loop starts like this: for \ category, match, mismatch, extra \ in \ ( ("fonts", {}, (("filepath" , ""),), ()), ("images", {"type" : "IMAGE"}, (), ("filepath_raw",)), ("libraries", {}, (), ()), ("sounds", {}, (), ()), ) \ : ... where ?match? is a dictionary where each key is an attribute name, and the value is the corresponding value that the attribute must have, while ?mismatch? is a tuple of (key, value) 2-tuples, where each ?key? is an attribute name, and ?value? is a value that attribute must *not* have. The table is designed so that I can easily add new categories, and new criteria for each category, as I discover them in future. So, within the above category loop, I loop over all items in the Blender document within that category that match the specified criteria: for item in getattr(bpy.data, category) : if ( item.packed_file == None and not any(getattr(item, k) == v for k, v in mismatch) and all(getattr(item, k) == match[k] for k in match) ) : That additional ?item.packed_file == None? check indicates that the object is not stored in the .blend file, but resides in an external file. That, at least, is a common characteristic of all object categories (so far...). From lawrencedo99 at gmail.com Wed Sep 7 21:53:50 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 7 Sep 2016 18:53:50 -0700 (PDT) Subject: How to run a .py file in IPython? In-Reply-To: References: Message-ID: <157cb947-b392-4f20-998a-4b6b2319c5b3@googlegroups.com> On Wednesday, August 31, 2016 at 3:22:40 AM UTC+12, umair durrani wrote: > It seems that the script can't 'see' any files in the Data directory. Have you tried adding debug statements to the script to 1) print out its default directory, and 2) what items it can see in that directory? From lawrencedo99 at gmail.com Wed Sep 7 21:55:58 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 7 Sep 2016 18:55:58 -0700 (PDT) Subject: Helloworld with Python C extension In-Reply-To: References: Message-ID: <036528ef-1464-47c5-a10f-6056263b6900@googlegroups.com> On Tuesday, August 30, 2016 at 6:07:15 PM UTC+12, Ganesh Pal wrote: > I was just wondering how could the C extension be debugged ? My usual way of debugging C code is to stick printf statements close to where I think the problem areas might be. Write to stderr, not stdout, so you can redirect that to a logfile etc without interfering with normal output (if any). From darcy at Vex.Net Wed Sep 7 22:54:44 2016 From: darcy at Vex.Net (D'Arcy J.M. Cain) Date: Wed, 7 Sep 2016 22:54:44 -0400 Subject: How to split value where is comma ? In-Reply-To: References: Message-ID: <20160907225444.0f99a5a2@imp> On Wed, 7 Sep 2016 16:04:40 +0000 Joaquin Alzola wrote: > > where is a comma there should start new line ... How can i do it ? > > Use the split > > a.split(",") > for x in a: > print(x) Seems overly complex. print(a.replace(',', '\n')) > This email is confidential and may be subject to privilege. If you > are not the intended recipient, please do not copy or disclose its > content but contact the sender immediately upon receipt. Do you realize how stupid it is to put this on a message sent all around the world? -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From dieter at handshake.de Thu Sep 8 02:22:01 2016 From: dieter at handshake.de (dieter) Date: Thu, 08 Sep 2016 08:22:01 +0200 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> Message-ID: <87d1kelxme.fsf@handshake.de> "Alexander N. Moibenko" writes: > when I build a binary with python 2.6 it builds without any problem. > When I build with python 2.7 the build fails after warnings like: > /opt/python/Python-2.7.12/Modules/posixmodule.o: In function > `posix_tempnam': > /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the > use of `tempnam' is dangerous, better use `mkstemp' > collect2: ld returned 1 exit status > > How this can be fixed? I doubt that the (compiler) warning is responsible for the (linker) failure. When I am faced with problems like this (usually during extension building; I have never encountered a problem during a Python built), I try to find out what (OS level) commands are executed by the build machinery and then issue them manually on the command line: the build machinery often hides error details revealed by executing the commands directly on the command line. What I can imagine is that your (OS level installed) C libraries (i.e. "libc" and friends) no longer contain a "tempnam", letting the linker fail. Thus, maybe, the compiler still warns about "tempnam" but the linker already considers it as an error. From lawrencedo99 at gmail.com Thu Sep 8 04:14:50 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 8 Sep 2016 01:14:50 -0700 (PDT) Subject: degrees and radians. In-Reply-To: References: <3330ba.s35.ln@127.0.0.1> Message-ID: <00b1a33b-1ee7-48fa-ad12-bceb9685f78c@googlegroups.com> On Tuesday, May 7, 2002 at 9:15:50 AM UTC+12, Fernando P?rez wrote: > Plus, if you really need those conversions, it's less typing and more > efficient (no function call) to simply use a multiplicative constant... This I have found to be the best idea. In Qahirah I provided ?deg? and ?circle? constants, used like this: ldo at hypatia:~> python3 -ic "import math, qahirah as qah" >>> math.sin(45 * qah.deg) 0.7071067811865475 >>> math.atan(1) / qah.deg 45.0 >>> math.cos(qah.circle / 4) 6.123233995736766e-17 I think these provide greater flexibility than having to have explicit conversion functions. From redstone-cold at 163.com Thu Sep 8 04:17:44 2016 From: redstone-cold at 163.com (iMath) Date: Thu, 8 Sep 2016 01:17:44 -0700 (PDT) Subject: easy way to return a list of absolute file or directory path within a directory In-Reply-To: <57cfc8cb$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <57cfc8cb$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1358d365-b80c-41c0-8769-6dfb6f14fb7e@googlegroups.com> On Wednesday, September 7, 2016 at 4:00:31 PM UTC+8, Steven D'Aprano wrote: > On Wednesday 07 September 2016 17:08, iMath wrote: > > > Any easier solutions on returning a list of absolute file or directory path > > within a directory? Mine is > > > > list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory))) > > > Use a list comprehension: > > > [os.path.join(directory,entry) for entry in os.listdir(directory)] > > > > -- > Steven > > git gets easier once you get the basic idea that branches are homeomorphic > endofunctors mapping submanifolds of a Hilbert space. yes, a list comprehension does make the code more readable From robin at reportlab.com Thu Sep 8 04:41:55 2016 From: robin at reportlab.com (Robin Becker) Date: Thu, 8 Sep 2016 09:41:55 +0100 Subject: How to split value where is comma ? In-Reply-To: <20160907225444.0f99a5a2@imp> References: <20160907225444.0f99a5a2@imp> Message-ID: <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> On 08/09/2016 03:54, D'Arcy J.M. Cain wrote: > On Wed, 7 Sep 2016 16:04:40 +0000 > Joaquin Alzola wrote: .......... >> This email is confidential and may be subject to privilege. If you >> are not the intended recipient, please do not copy or disclose its >> content but contact the sender immediately upon receipt. > > Do you realize how stupid it is to put this on a message sent all around > the world? > I have worked places where they put stuff like this at the bottom of emails sent to the person sitting next to them :) -raising entropy-ly yrs- Robin Becker From Joaquin.Alzola at lebara.com Thu Sep 8 05:27:20 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Thu, 8 Sep 2016 09:27:20 +0000 Subject: How to split value where is comma ? In-Reply-To: <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> References: <20160907225444.0f99a5a2@imp> <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> Message-ID: >I have worked places where they put stuff like this at the bottom of emails sent to the person sitting next to them :) -raising entropy-ly yrs- Robin Becker Cannot do anything about it. It is not on my MTA client and it is added by the company server :( If it depended on my I will remove it but I can not do that. This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From Joaquin.Alzola at lebara.com Thu Sep 8 05:47:52 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Thu, 8 Sep 2016 09:47:52 +0000 Subject: How to split value where is comma ? In-Reply-To: <20160907225444.0f99a5a2@imp> References: <20160907225444.0f99a5a2@imp> Message-ID: Why nested loops are so slow in Python? Is it because new contexts are created? For more details, see http://stackoverflow.com/questions/26611043/numpy-vs-cython-nested-loop-so-slow http://stackoverflow.com/questions/39371021/efficient-loop-over-numpy-array Thanks! From rosuav at gmail.com Thu Sep 8 08:11:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 Sep 2016 22:11:06 +1000 Subject: nested loops in Python In-Reply-To: <2618038c-5b4c-4e0a-a936-74789aaf5819@googlegroups.com> References: <2618038c-5b4c-4e0a-a936-74789aaf5819@googlegroups.com> Message-ID: On Thu, Sep 8, 2016 at 8:20 PM, Igor Kozin wrote: > Why nested loops are so slow in Python? Is it because new contexts are created? > For more details, see > http://stackoverflow.com/questions/26611043/numpy-vs-cython-nested-loop-so-slow > http://stackoverflow.com/questions/39371021/efficient-loop-over-numpy-array > Thanks! Have you actually measured the loops and found them to be visibly slow? ChrisA From eryksun at gmail.com Thu Sep 8 10:07:02 2016 From: eryksun at gmail.com (eryk sun) Date: Thu, 8 Sep 2016 14:07:02 +0000 Subject: Does This Scare You? In-Reply-To: References: <439fbfc4-7ea6-4605-837f-9c138d295e34@googlegroups.com> <9035c731-3f57-6bfd-1c6f-d3d6695da3b6@gmail.com> Message-ID: On Thu, Sep 8, 2016 at 1:30 AM, Lawrence D?Oliveiro wrote: > On Monday, August 22, 2016 at 4:18:39 PM UTC+12, eryk sun wrote: >> It would help to consult a reverse-engineered implementation of >> RtlGetFullPathName_Ustr and RtlIsDosDeviceName_Ustr. I'll check the >> ReactOS source code. > > > might also be useful (found from > ). I posted a comment there about a month and a half ago with a couple of corrections. But at the time I wasn't concerned about the section on legacy DOS device names. The author only tested on 8.1 and 10, so the description of DOS device behavior is incomplete -- especially concerning the way Windows Vista/7 handle CON, CONIN$, and CONOUT$. For example, "CONOUT$" gets redirected to the console, but not "C:\Temp\CONOUT$" or "\\.\CONOUT$" even though the last two path strings start with "C" and "\", which satisfies the speed hack used by BaseIsThisAConsoleName. The difference is that, prior to Windows 8, RtlIsDosDeviceName_U doesn't look for "CONIN$" or "CONOUT$", yet BaseIsThisAConsoleName relies on RtlIsDosDeviceName_U to find the offset to the device name. Thus it can only redirect an exact match for "CONIN$" and "CONOUT$". From moibenko at fnal.gov Thu Sep 8 10:36:18 2016 From: moibenko at fnal.gov (Alexander N. Moibenko) Date: Thu, 8 Sep 2016 09:36:18 -0500 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: <85twdrs5gj.fsf@benfinney.id.au> References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <85twdrs5gj.fsf@benfinney.id.au> Message-ID: <41bb70c2-51c9-0eb7-20ae-6c44c3ef59c7@fnal.gov> Yes, of course I did not write posixmodule.c, it is a part of the python 2.7 distribution and I have no idea how to not use it and I believe I have no control over it, unless I go inside of python distribution and modify it. Is this what you are recommending? On 09/07/2016 05:36 PM, Ben Finney wrote: > "Alexander N. Moibenko" writes: > >> /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the >> use of `tempnam' is dangerous, better use `mkstemp' >> collect2: ld returned 1 exit status >> >> How this can be fixed? > The clearest answer is already there in the warning message. Replace > your use of ?tempnam? with ?mkstemp?. > > If you don't know what that means because you didn't write the code, > then this is for whoever is maintaining that code. Read it, learn what > it does, find (or write) its unit tests to make sue you don't break > anything; then, change that usage as suggested. > From moibenko at fnal.gov Thu Sep 8 10:48:08 2016 From: moibenko at fnal.gov (Alexander N. Moibenko) Date: Thu, 8 Sep 2016 09:48:08 -0500 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: <87d1kelxme.fsf@handshake.de> References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> Message-ID: <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> In fact I tried issuing commands manually, but they did not give me any hint more than I already had. In python 2.6 this all works with the same libc, of course (because I tried to compile on the same machine). Thanks anyway. On 09/08/2016 01:22 AM, dieter wrote: > "Alexander N. Moibenko" writes: >> when I build a binary with python 2.6 it builds without any problem. >> When I build with python 2.7 the build fails after warnings like: >> /opt/python/Python-2.7.12/Modules/posixmodule.o: In function >> `posix_tempnam': >> /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the >> use of `tempnam' is dangerous, better use `mkstemp' >> collect2: ld returned 1 exit status >> >> How this can be fixed? > I doubt that the (compiler) warning is responsible for the (linker) failure. > > When I am faced with problems like this (usually during extension building; > I have never encountered a problem during a Python built), I try > to find out what (OS level) commands are executed by the build machinery > and then issue them manually on the command line: the build machinery > often hides error details revealed by executing the commands > directly on the command line. > > > What I can imagine is that your (OS level installed) C libraries (i.e. "libc" > and friends) no longer contain a "tempnam", letting the linker fail. > Thus, maybe, the compiler still warns about "tempnam" but the linker > already considers it as an error. > From rosuav at gmail.com Thu Sep 8 10:51:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 00:51:56 +1000 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> Message-ID: On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko wrote: > In fact I tried issuing commands manually, but they did not give me any hint > more than I already had. > > In python 2.6 this all works with the same libc, of course (because I tried > to compile on the same machine). > Can you provide some more information about the machine you're trying to compile this on? ChrisA From gordon at panix.com Thu Sep 8 10:57:04 2016 From: gordon at panix.com (John Gordon) Date: Thu, 8 Sep 2016 14:57:04 +0000 (UTC) Subject: How to split value where is comma ? References: Message-ID: In Joaquin Alzola writes: > Use the split > a.split(",") > for x in a: > print(x) This won't work. split() returns a list of split elements but the original string remains unchanged. You want something like this instead: newlist = a.split(",") for x in newlist: print(x) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From moibenko at fnal.gov Thu Sep 8 11:12:10 2016 From: moibenko at fnal.gov (Alexander N. Moibenko) Date: Thu, 8 Sep 2016 10:12:10 -0500 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> Message-ID: Yes this Linux Red Hat 6. [enstore at dmsen02 enstore-log]$ cat /etc/redhat-release Scientific Linux Fermi release 6.5 (Ramsey) Please note that the same set of modules buils with python 2.6.3 and fails with python 2.7.... ( I mean any pyhon 2.7 release). On 09/08/2016 09:51 AM, Chris Angelico wrote: > On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko > wrote: >> In fact I tried issuing commands manually, but they did not give me any hint >> more than I already had. >> >> In python 2.6 this all works with the same libc, of course (because I tried >> to compile on the same machine). >> > Can you provide some more information about the machine you're trying > to compile this on? > > ChrisA From rustompmody at gmail.com Thu Sep 8 12:06:28 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 8 Sep 2016 09:06:28 -0700 (PDT) Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> Message-ID: <0741bb94-fcc2-4de3-b903-adc3eaac6a19@googlegroups.com> On Thursday, September 8, 2016 at 8:57:23 PM UTC+5:30, Alexander N. Moibenko wrote: > Yes this Linux Red Hat 6. > > [enstore at dmsen02 enstore-log]$ cat /etc/redhat-release > Scientific Linux Fermi release 6.5 (Ramsey) > Please note that the same set of modules buils with python 2.6.3 and > fails with python 2.7.... ( I mean any pyhon 2.7 release). > > > On 09/08/2016 09:51 AM, Chris Angelico wrote: > > On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko > > moibenko wrote: > >> In fact I tried issuing commands manually, but they did not give me any hint > >> more than I already had. > >> > >> In python 2.6 this all works with the same libc, of course (because I tried > >> to compile on the same machine). > >> > > Can you provide some more information about the machine you're trying > > to compile this on? > > > > ChrisA Cant make out much I suspect gcc gets inconsistent (with itself) across widely disparate versions When I give [ubuntu 16.4] $ gcc -v I get gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) (along with a lot of other stuff!) What does your gcc say? From yan12125 at gmail.com Thu Sep 8 12:07:12 2016 From: yan12125 at gmail.com (Chi Hsuan Yen) Date: Fri, 9 Sep 2016 00:07:12 +0800 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? Message-ID: Hi Python enthusiasts, I'm working on youtube-dl, a handy tool for downloading videos from various websites. There are occasional bug reports with SSL error CERTIFICATE_VERIFY_FAILED when people are trying to download videos from youtube.com [1] or dailymotion.com [2]. The issue about youtube.com turned out to be expired intermediate CA certificates. Some users report that there's one or more expired "Google Internet Authority G2" certificate on their machines. Apparently OpenSSL verifies the whole certificate chain and report an error as soon as it finds an invalid certificate in the chain. My questions is: how to tell from several possible causes to CERTIFICATE_VERIFY_FAILED? Currently both expired self signed certificate leads to CERTIFICATE_VERIFY_FAILED. Thanks for any help or advice. Best, Yen Chi Hsuan [1] https://github.com/rg3/youtube-dl/issues/7309 [2] https://github.com/rg3/youtube-dl/issues/10574 From moibenko at fnal.gov Thu Sep 8 12:17:21 2016 From: moibenko at fnal.gov (Alexander N. Moibenko) Date: Thu, 8 Sep 2016 11:17:21 -0500 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: <0741bb94-fcc2-4de3-b903-adc3eaac6a19@googlegroups.com> References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> <0741bb94-fcc2-4de3-b903-adc3eaac6a19@googlegroups.com> Message-ID: <93858abc-87d6-ec37-6c13-56b3c2ecbe16@fnal.gov> On 09/08/2016 11:06 AM, Rustom Mody wrote: > On Thursday, September 8, 2016 at 8:57:23 PM UTC+5:30, Alexander N. Moibenko wrote: >> Yes this Linux Red Hat 6. >> >> [enstore at dmsen02 enstore-log]$ cat /etc/redhat-release >> Scientific Linux Fermi release 6.5 (Ramsey) >> Please note that the same set of modules buils with python 2.6.3 and >> fails with python 2.7.... ( I mean any pyhon 2.7 release). >> >> >> On 09/08/2016 09:51 AM, Chris Angelico wrote: >>> On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko >>> moibenko wrote: >>>> In fact I tried issuing commands manually, but they did not give me any hint >>>> more than I already had. >>>> >>>> In python 2.6 this all works with the same libc, of course (because I tried >>>> to compile on the same machine). >>>> >>> Can you provide some more information about the machine you're trying >>> to compile this on? >>> >>> ChrisA > Cant make out much > I suspect gcc gets inconsistent (with itself) across widely disparate versions > When I give [ubuntu 16.4] > $ gcc -v > I get > gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) > (along with a lot of other stuff!) > > What does your gcc say? gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) From rosuav at gmail.com Thu Sep 8 12:39:54 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 02:39:54 +1000 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> Message-ID: On Fri, Sep 9, 2016 at 1:12 AM, Alexander N. Moibenko wrote: > Yes this Linux Red Hat 6. > > [enstore at dmsen02 enstore-log]$ cat /etc/redhat-release > Scientific Linux Fermi release 6.5 (Ramsey) > Please note that the same set of modules buils with python 2.6.3 and fails > with python 2.7.... ( I mean any pyhon 2.7 release). I still don't think the compiler warnings have anything to do with this. After you run 'make' and it fails at the ld step, can you rerun make and post the output, please? It should skip all the compilation and go straight to the link stage, so (a) it should be a manageable amount of text, and (b) it most likely won't say anything about tempnam. ChrisA From auriocus at gmx.de Thu Sep 8 13:04:24 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 8 Sep 2016 19:04:24 +0200 Subject: nested loops in Python In-Reply-To: <2618038c-5b4c-4e0a-a936-74789aaf5819@googlegroups.com> References: <2618038c-5b4c-4e0a-a936-74789aaf5819@googlegroups.com> Message-ID: Am 08.09.16 um 12:20 schrieb Igor Kozin: > Why nested loops are so slow in Python? Is it because new contexts are created? > For more details, see > http://stackoverflow.com/questions/26611043/numpy-vs-cython-nested-loop-so-slow > http://stackoverflow.com/questions/39371021/efficient-loop-over-numpy-array The answers are right there, too - what are you mising? CPython is an interpreter. For every seemingly simple operation like a[i]=j, a function pointer is called, the variables contain polymorphic types which are morphed, etc. The same thing in compiled code is a single machine instruction. Speed differences of ~100x are normal between compiled and interpreted code over all dynamic languages. Christian From rosuav at gmail.com Thu Sep 8 13:19:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 03:19:23 +1000 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> Message-ID: On Fri, Sep 9, 2016 at 2:50 AM, Alexander N. Moibenko wrote: > The output is long so, I am replying to you only: Not too long, fortunately. Replying back to the list with a trimmed version. > make[1]: Entering directory `/opt/enstore/src/ENCPBIN_TEMP' (Curious path name.) > /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function > `_PyTime_DoubleToTimet': > /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108: > multiple definition of `_PyTime_DoubleToTimet' > /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108: > first defined here > /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function > `inittime': > /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851: > multiple definition of `inittime' > /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851: > first defined here > /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function > `_PyTime_FloatTime': > /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062: > multiple definition of `_PyTime_FloatTime' > /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062: > first defined here This is.... interesting. Very interesting. Firstly, I thought you were trying to compile 2.7.12. Do you possibly have multiple versions of the source, and they're treading on each other's toes? Do you still get these errors if you create a brand new empty directory, extract the 2.7.12 sources to it, and run a clean build? Particularly notable if you get 2.7.9 paths when you try to build 2.7.12, but still of interest if you're getting these multiple-definition errors on a clean build. ChrisA From moibenko at fnal.gov Thu Sep 8 13:27:54 2016 From: moibenko at fnal.gov (Alexander N. Moibenko) Date: Thu, 8 Sep 2016 12:27:54 -0500 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' In-Reply-To: References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> Message-ID: <46e52b1f-fe52-7fb0-6941-dce72cfa5660@fnal.gov> On 09/08/2016 12:19 PM, Chris Angelico wrote: > On Fri, Sep 9, 2016 at 2:50 AM, Alexander N. Moibenko wrote: >> The output is long so, I am replying to you only: > Not too long, fortunately. Replying back to the list with a trimmed version. > >> make[1]: Entering directory `/opt/enstore/src/ENCPBIN_TEMP' > (Curious path name.) > >> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function >> `_PyTime_DoubleToTimet': >> /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108: >> multiple definition of `_PyTime_DoubleToTimet' >> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108: >> first defined here >> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function >> `inittime': >> /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851: >> multiple definition of `inittime' >> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851: >> first defined here >> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function >> `_PyTime_FloatTime': >> /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062: >> multiple definition of `_PyTime_FloatTime' >> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062: >> first defined here > This is.... interesting. Very interesting. Firstly, I thought you were > trying to compile 2.7.12. Do you possibly have multiple versions of > the source, and they're treading on each other's toes? I tried 2.7.9 and 2.7.12. I do have multiple versions, but they do not mix up because I set environment appropriately. On this particular machine I have only my own 2.7.9 > > Do you still get these errors if you create a brand new empty > directory, extract the 2.7.12 sources to it, and run a clean build? This is what I usually do, in this case too. > Particularly notable if you get 2.7.9 paths when you try to build > 2.7.12, but still of interest if you're getting these > multiple-definition errors on a clean build. This is not the case. > > ChrisA From orgnut at yahoo.com Thu Sep 8 16:05:59 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 8 Sep 2016 13:05:59 -0700 Subject: How to split value where is comma ? In-Reply-To: References: Message-ID: On 09/08/2016 07:57 AM, John Gordon wrote: > In Joaquin Alzola writes: > >> Use the split > >> a.split(",") >> for x in a: >> print(x) > > This won't work. split() returns a list of split elements but the > original string remains unchanged. > > You want something like this instead: > > newlist = a.split(",") > for x in newlist: > print(x) > Even easier... for x in a.split(','): print(x) -- -=- Larry -=- From gyan.am010 at gmail.com Thu Sep 8 16:50:16 2016 From: gyan.am010 at gmail.com (GP) Date: Thu, 8 Sep 2016 13:50:16 -0700 (PDT) Subject: Need some suggestions in grouping of items Message-ID: I have a list of items: ShelvesToPack = [{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea': 759152.0, 'ItemNames': 1}, {'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea': 372100.0, 'ItemNames': 2}, {'ShelfLength': 2310.0, 'ShelfWidth': 762.0, 'ShelfArea': 1760220.0, 'ItemNames': 3}, {'ShelfLength': 610.0, 'ShelfWidth': 610.0, 'ShelfArea': 1450435.0, 'ItemNames': 4}] I have a certain criteria and I want to group the items based on those. I need the program that tells how many minimum number of groups one can have and how the items are grouped. I would like to form groups of these items such that (sum of shelflength (of itmes) <= max length or sum of shelfwidth (of items) <= max width) and sum of ShelfArea (of items) <= Max Area. In this case, if we look at the logic we can have all the items packed in minimum 2 groups - item 1 and 3 will form one group and item 2 & 4 will form other group. I would like to have the answer in the format: [[{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea': 759152.0, 'ItemNames': 1} , {'ShelfLength': 2310.0, 'ShelfWidth': 762.0, 'ShelfArea': 1760220.0, 'ItemNames': 3}], [{'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea': 372100.0, 'ItemNames': 2}, , {'ShelfLength': 610.0, 'ShelfWidth': 610.0, 'ShelfArea': 1450435.0, 'ItemNames': 4}]] I have written a code but it does only one grouping ( need some help why it doesnot for the remaining items and what corrections need to be done) . ShelvesToPack_sorted=sorted(ShelvesToPack, key = itemgetter('ShelfWidth'), reverse = True) AreaOfObject= 2972897.28 current_width = 0 current_length = 0 current_area =0 shelf =[] shelves=[] if len(ShelvesToPack_sorted) > 0: for item in ShelvesToPack_sorted: if (current_width + item['ShelfWidth'] <= 1219.2 or current_length + item['ShelfLength'] <= 2438.5) and current_area + item['ShelfArea'] <= AreaOfObject: shelf.append(item) current_width += item['ShelfWidth'] current_length += item['ShelfLength'] current_area += item['ShelfArea'] del item if shelf: shelves.append(shelf) print(shelves) This produces only one grouping and does not group the remaining items. [[{'ShelfLength': 2310.0, 'ItemNames': 3, 'ShelfArea': 1760220.0, 'ShelfWidth': 762.0}, {'ShelfLength': 2278.0, 'ItemNames': 1, 'ShelfArea': 759152.0, 'ShelfWidth': 356.0}]] Can anyone please suggest? From ben+python at benfinney.id.au Thu Sep 8 16:52:44 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 09 Sep 2016 06:52:44 +1000 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) References: <20160907225444.0f99a5a2@imp> Message-ID: <85y432qfkz.fsf_-_@benfinney.id.au> Joaquin Alzola writes: > > Cannot do anything. That's not true; you can do more than we. > Added by the MTA of the company not by my client. Right. So, here are things you can do (that we cannot) about this: * Complain, with reasoned explanation, to the management responsible for deciding whether that nonsense continues to be added to every message. If they haven't heard the complaint before, they will no longer have that excuse. If they have heard the complaint before, yours will add to the weight of evidence that this is not wanted. * Switch to a different mail service, one which does not add that nonsense to your email. Yes, this is inconvenient for you. But it's impossible for us to do on your behalf, so you are in a position of more power than us. * Complain again to the management responsible for the ongoing decision to place nonsense on your email, that you have been forced to use a different mail system in order not to appear contemptuous of the communities in which you participate. If you are participating for reasons of benefit to the organisation, point out that their ongoing decision is making that more difficult for their employees. These are all powers you have; please don't feel that you can do nothing. -- \ ?Isn't it enough to see that a garden is beautiful without | `\ having to believe that there are fairies at the bottom of it | _o__) too?? ?Douglas Adams | Ben Finney From Joaquin.Alzola at lebara.com Thu Sep 8 17:17:22 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Thu, 8 Sep 2016 21:17:22 +0000 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) In-Reply-To: <85y432qfkz.fsf_-_@benfinney.id.au> References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: Hi Ben Thanks for the advice. > * Complain Basically what all comes down is to complain. I wonder if in a company of 80,000 people I will manage to change that behaviour. This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From rosuav at gmail.com Thu Sep 8 17:57:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 07:57:47 +1000 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) In-Reply-To: References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: On Fri, Sep 9, 2016 at 7:17 AM, Joaquin Alzola wrote: > Hi Ben > > Thanks for the advice. > >> * Complain > > Basically what all comes down is to complain. I wonder if in a company of 80,000 people I will manage to change that behaviour. > This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. > You are one out of eighty thousand. I am zero out of eighty thousand. Short of suing the company or something of that nature, I have no chance of affecting it. You _do_ have a chance, exactly as per Ben's advice. There is one option among Ben's suggestions that doesn't amount to "complain": > * Switch to a different mail service, one which does not add that > nonsense to your email. This amounts to "subvert". Now, if it's dead simple for you to remove the disclaimer, the ball lands in the court of those wanting it on all outgoing emails: they can either complain at you for omitting it, or decide that it's not worth it. Again, this is a marked improvement; and if you're bothered by the difficulty of changing a large and bureaucratic organization, it's probably the easiest solution. ChrisA This email is overconfident and may be subject to grammar. If you are not the intended sender, please do not confuse yourself for me but contact the recipient immediately to report that you have lost your marbles. From lew.pitcher at digitalfreehold.ca Thu Sep 8 18:07:46 2016 From: lew.pitcher at digitalfreehold.ca (Lew Pitcher) Date: Thu, 08 Sep 2016 18:07:46 -0400 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: On Thursday September 8 2016 17:17, in comp.lang.python, "Joaquin Alzola" wrote: > Hi Ben > > Thanks for the advice. > >> * Complain > > Basically what all comes down is to complain. I wonder if in a company of > 80,000 people I will manage to change that behaviour. Why don't you, at least, include a "signature" line at the end of /your/ text. That way, the automatically-added "confidentiality clause" will end up appended to the signature. Since many news readers discard or suppress display of the signature, the "confidentiality clause" won't be as much of an issue. > This email is > confidential and may be subject to privilege. If you are not the intended > recipient, please do not copy or disclose its content but contact the sender > immediately upon receipt. A signature begins with a line consisting only of two hyphens followed by a space. Any lines that follow that line are considered to be part of the signature. -- Lew Pitcher "In Skills, We Trust" PGP public key available upon request From grant.b.edwards at gmail.com Thu Sep 8 18:13:45 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 8 Sep 2016 22:13:45 +0000 (UTC) Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: On 2016-09-08, Joaquin Alzola wrote: > Basically what all comes down is to complain. I wonder if in a > company of 80,000 people I will manage to change that behaviour. Perhaps others have complained. If enough people complain, maybe they'll do something. After all, that boilerplate just makes the corporation look stupid and incompetent. Any email that leaves the corporate network must be assumed to be visible to world+dog. Anybody who thinks differently is deluded and should not be allowed access to information that is "confidential and subject to privledge". But, I'm sure there's a lawyer somewhere who's trying to cover his ass regardless of how foolish it looks... > This email is confidential and may be subject to privilege. If you > are not the intended recipient, please do not copy or disclose its > content but contact the sender immediately upon receipt. -- Grant Edwards grant.b.edwards Yow! I'm pretending that at we're all watching PHIL gmail.com SILVERS instead of RICARDO MONTALBAN! From random832 at fastmail.com Thu Sep 8 18:27:44 2016 From: random832 at fastmail.com (Random832) Date: Thu, 08 Sep 2016 18:27:44 -0400 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) In-Reply-To: References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: <1473373664.130002.720118257.14D72BFE@webmail.messagingengine.com> On Thu, Sep 8, 2016, at 18:13, Grant Edwards wrote: > After all, that boilerplate just makes the corporation look stupid and > incompetent. Any email that leaves the corporate network must be > assumed to be visible to world+dog. Anybody who thinks differently is > deluded and should not be allowed access to information that is > "confidential and subject to privledge". If every lawyer in the world benefits from the interpretation that this sort of notice is legally effective (since tomorrow it may be they who accidentaly send privileged information), who will argue in court that it's not? The reality is more complex, and it appears that it may only apply if the accidental recipient is a lawyer. I really can't say for sure, since _I'm_ not a lawyer, but posted without further comment: http://apps.americanbar.org/litigation/committees/technology/articles/winter2013-0213-do-email-disclaimers-really-work.html From ben+python at benfinney.id.au Thu Sep 8 19:55:31 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 09 Sep 2016 09:55:31 +1000 Subject: What you can do about legalese nonsense on email References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: <85twdqq74c.fsf@benfinney.id.au> Chris Angelico writes: > On Fri, Sep 9, 2016 at 7:17 AM, Joaquin Alzola > wrote: > > Hi Ben > > > > Thanks for the advice. You're welcome, I hope it leads to positive change. > > Basically what all comes down is to complain. I wonder if in a > > company of 80,000 people I will manage to change that behaviour. That's a good thing to wonder! But wondering will never get the answer to this one: you'll have to *do* it, in a way that allows that change to occur. It is far more certain that if you don't use that power, you will not effect positive change. > You are one out of eighty thousand. I am zero out of eighty thousand. > Short of suing the company or something of that nature, I have no > chance of affecting it. You _do_ have a chance, exactly as per Ben's > advice. With tens of thousands of people all subject to the same stupid rule, you have even more of a change: You have many more opportunities to find people who can also complain about the same thing in the same forum. Surely you are far from alone in realising how this exhibits arrant incompetence on the internet, and that your employer would do well to drop this mindless policy. So if you know you have many people in the same situation, join forces with them. That is another thing that we cannot do, and you can. You have far more power in this than you may feel; and realising that you *can* act is an imortant step to getting the positive change effected. -- \ ?You don't need a book of any description to help you have some | `\ kind of moral awareness.? ?Dr. Francesca Stavrakoloulou, bible | _o__) scholar, 2011-05-08 | Ben Finney From python at mrabarnett.plus.com Thu Sep 8 20:29:11 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 9 Sep 2016 01:29:11 +0100 Subject: Need some suggestions in grouping of items In-Reply-To: References: Message-ID: On 2016-09-08 21:50, GP wrote: > > I have a list of items: > ShelvesToPack = [{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea': 759152.0, 'ItemNames': 1}, > {'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea': 372100.0, 'ItemNames': 2}, > {'ShelfLength': 2310.0, 'ShelfWidth': 762.0, 'ShelfArea': 1760220.0, 'ItemNames': 3}, > {'ShelfLength': 610.0, 'ShelfWidth': 610.0, 'ShelfArea': 1450435.0, 'ItemNames': 4}] > > I have a certain criteria and I want to group the items based on those. > I need the program that tells how many minimum number of groups one can have and how the items are grouped. I would like to form groups of these items such that (sum of shelflength (of itmes) <= max length or sum of shelfwidth (of items) <= max width) and sum of ShelfArea (of items) <= Max Area. In this case, if we look at the logic we can have all the items packed in minimum 2 groups - item 1 and 3 will form one group and item 2 & 4 will form other group. I would like to have the answer in the format: > [[{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea': 759152.0, 'ItemNames': 1} , > {'ShelfLength': 2310.0, 'ShelfWidth': 762.0, 'ShelfArea': 1760220.0, 'ItemNames': 3}], > [{'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea': 372100.0, 'ItemNames': 2}, > , {'ShelfLength': 610.0, 'ShelfWidth': 610.0, 'ShelfArea': 1450435.0, 'ItemNames': 4}]] > > I have written a code but it does only one grouping ( need some help why it doesnot for the remaining items and what corrections need to be done) . > > ShelvesToPack_sorted=sorted(ShelvesToPack, key = itemgetter('ShelfWidth'), reverse = True) > AreaOfObject= 2972897.28 > current_width = 0 > current_length = 0 > current_area =0 > shelf =[] > shelves=[] > if len(ShelvesToPack_sorted) > 0: > for item in ShelvesToPack_sorted: > if (current_width + item['ShelfWidth'] <= 1219.2 or current_length + item['ShelfLength'] <= 2438.5) and current_area + item['ShelfArea'] <= AreaOfObject: > shelf.append(item) > current_width += item['ShelfWidth'] > current_length += item['ShelfLength'] > current_area += item['ShelfArea'] > del item > > if shelf: > shelves.append(shelf) > > print(shelves) > > This produces only one grouping and does not group the remaining items. > [[{'ShelfLength': 2310.0, 'ItemNames': 3, 'ShelfArea': 1760220.0, 'ShelfWidth': 762.0}, {'ShelfLength': 2278.0, 'ItemNames': 1, 'ShelfArea': 759152.0, 'ShelfWidth': 356.0}]] > > Can anyone please suggest? > The easy way to do it is, in pseudocode: shelves = [] while list_of_items: shelf = [] # Also initialise width, length and area. doesnt_fit = [] for item in list_of_items: if item fits: shelf.append(item) # Also adjust width, length and area. else: doesnt_fit.append(item) shelves.append(shelf) list_of_items = doesnt_fit From suabiut at gmail.com Thu Sep 8 20:48:05 2016 From: suabiut at gmail.com (sum abiut) Date: Fri, 9 Sep 2016 11:48:05 +1100 Subject: pymssql Message-ID: Hi, i have used pymssql to connet to windows database but i want to be able iterate and only print out some specific fields. here is what i did conn=pymssql.connect(server,username,password,database) cus=conn.cursor() cus.execute("SELECT * FROM glbud ") for row in cus: print(row) this works perfect, but when i try to iterate through and only print out specific fields i got the error NameError: name 'budget_code' is not defined for row in cus: print(row.budget_code) NameError: name 'budget_code' is not defined the column name is budget_code, in mssql server 2008 any idea what i am doing wrong? please advise From tjreedy at udel.edu Thu Sep 8 21:19:15 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 8 Sep 2016 21:19:15 -0400 Subject: What you can do about legalese nonsense on email In-Reply-To: <85y432qfkz.fsf_-_@benfinney.id.au> References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: On 9/8/2016 4:52 PM, Ben Finney wrote: > Joaquin Alzola writes: > >> > >> Cannot do anything. > > That's not true; you can do more than we. > >> Added by the MTA of the company not by my client. > > Right. So, here are things you can do (that we cannot) about this: Something that some 'we' could do is ask the python-list manager/programmers, or more broadly, the mailman developers, to recognize an 'end of message' line, such as '--end message--' and delete it and anything appended thereafter. Then Joaquin and people in a similar situation could add the magic line as the end of a signature block. -- Terry Jan Reedy From rosuav at gmail.com Thu Sep 8 21:26:18 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 11:26:18 +1000 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) In-Reply-To: References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: On Fri, Sep 9, 2016 at 11:05 AM, Dennis Lee Bieber wrote: > I suspect, like the last two companies I've worked for -- corporate IT > policy is to block any access to non-corporate email systems. (Heck, my > current company is so paranoid that it adds "EXT:" to the subject of > incoming emails that did not originate from another employee! > > I haven't checked to see if GMAIL on a Samsung tablet can get through > if using the corporate "guest" WiFi system. Pretty sure if I tether to my > Blackberry phone it would work. The most common way to access Gmail is HTTP, so it would be difficult to mess with the emails as they go through. (You could block it, I guess, but it'd have to be some sort of IP address blacklist - you can't just say "no access to port 25 or 110".) And yes, if you tether to your phone, you should get past the problems. That might be a _little_ inconvenient though. ChrisA From lawrencedo99 at gmail.com Thu Sep 8 22:35:35 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 8 Sep 2016 19:35:35 -0700 (PDT) Subject: C Python extension to export an Function In-Reply-To: References: <87r394p0g7.fsf@handshake.de> Message-ID: <0951b057-2923-43ea-9ecf-fae2f9741acf@googlegroups.com> On Friday, September 2, 2016 at 3:59:21 AM UTC+12, Stefan Behnel wrote: > Manually written C-API code is simply too difficult to maintain, and also > too difficult to get right in the first place. There are just too many ways > to introduce reference leaks, crashes and long standing unnoticed bugs > (believe me, I know what I'm talking about). There are ways to keep that manageable, using structured-programming techniques. From lawrencedo99 at gmail.com Thu Sep 8 22:38:12 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 8 Sep 2016 19:38:12 -0700 (PDT) Subject: pymssql In-Reply-To: References: Message-ID: On Friday, September 9, 2016 at 12:48:50 PM UTC+12, sum abiut wrote: > cus.execute("SELECT * FROM glbud ") Never use ?select *?, except for testing. > for row in cus: > print(row) > this works perfect, but when i try to iterate through and only print out > specific fields i got the error NameError: name 'budget_code' is not defined Possibly because you are getting back a tuple? Are you expecting some other object type? From ben+python at benfinney.id.au Fri Sep 9 00:47:01 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 09 Sep 2016 14:47:01 +1000 Subject: What you can do about legalese nonsense on email References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: <85poodr86y.fsf@benfinney.id.au> Terry Reedy writes: > Something that some 'we' could do is ask the python-list > manager/programmers, or more broadly, the mailman developers, to > recognize an 'end of message' line, such as '--end message--' and > delete it and anything appended thereafter. No, that would be mangling messages in transit, to reverse someone else's mangling of messages in transit. That kind of arms race is foolish to enter in the first place. I would not agree to that policy. -- \ ?I went to a fancy French restaurant called ?D?j? Vu?. The head | `\ waiter said, ?Don't I know you??? ?Steven Wright | _o__) | Ben Finney From suabiut at gmail.com Fri Sep 9 00:50:55 2016 From: suabiut at gmail.com (sum abiut) Date: Fri, 9 Sep 2016 15:50:55 +1100 Subject: pymssql In-Reply-To: References: Message-ID: ok did some changes: conn=pymssql.connect(server,username,password,database) cus=conn.cursor( cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud") for row in cus: print(row) the above code display the selected column but when i iterate and try to print the fields, its not displaying anything and its not giving any error. conn=pymssql.connect(server,username,password,database) cus=conn.cursor( cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud") for row in cus: print(row.budget_code,row.budget_description,row.rate_type) the above code it doesn't print out anything and it doesn't give me any error. any assistance will be very much appreciated. On Fri, Sep 9, 2016 at 1:38 PM, Lawrence D?Oliveiro wrote: > On Friday, September 9, 2016 at 12:48:50 PM UTC+12, sum abiut wrote: > > cus.execute("SELECT * FROM glbud ") > > Never use ?select *?, except for testing. > > > for row in cus: > > print(row) > > this works perfect, but when i try to iterate through and only print out > > specific fields i got the error NameError: name 'budget_code' is not > defined > > Possibly because you are getting back a tuple? Are you expecting some > other object type? > -- > https://mail.python.org/mailman/listinfo/python-list > From jussi.piitulainen at helsinki.fi Fri Sep 9 01:39:26 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 09 Sep 2016 08:39:26 +0300 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: Grant Edwards writes: > On 2016-09-08, Joaquin Alzola wrote: > >> Basically what all comes down is to complain. I wonder if in a >> company of 80,000 people I will manage to change that behaviour. > > Perhaps others have complained. If enough people complain, maybe > they'll do something. > > After all, that boilerplate just makes the corporation look stupid and > incompetent. Any email that leaves the corporate network must be > assumed to be visible to world+dog. Anybody who thinks differently is > deluded and should not be allowed access to information that is > "confidential and subject to privledge". I read Lebara's "Vision" and "Mission" and I remember that whenever Lebara says anything, they end it with that rude disclaimer. I don't want to get in touch with Lebara. That's how stupid it is. > But, I'm sure there's a lawyer somewhere who's trying to cover his > ass regardless of how foolish it looks... As if Lebara's real mission is to cover their lawyers' asses. >> This email is confidential and may be subject to privilege. If you >> are not the intended recipient, please do not copy or disclose its >> content but contact the sender immediately upon receipt. Spammers should use a disclaimer like that. Then people would not dare to delete the spam without first confirming to the spammer that they read their spam. Or not. From dieter at handshake.de Fri Sep 9 02:15:57 2016 From: dieter at handshake.de (dieter) Date: Fri, 09 Sep 2016 08:15:57 +0200 Subject: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp' References: <2128661f-787e-3b0c-06a7-6eca1c1b7b47@fnal.gov> <87d1kelxme.fsf@handshake.de> <3923bdc3-542a-a3c6-1168-e9721f837396@fnal.gov> Message-ID: <871t0t4mzm.fsf@handshake.de> "Alexander N. Moibenko" writes: > In fact I tried issuing commands manually, but they did not give me > any hint more than I already had. When I remember right, then "gcc" has an option to show details about the calling of the phase commands ("gcc" is a coordinating programm delegating the real work to subcommands ("cpp", "cc1", "ld", ...)). Key to your problem seems to understand why "ld/collect2" fails. Usually, you should get a clear error message corresponding to this failure (e.g. "symbol SSSS undefined"). Getting only "collect2 exited with error code 1" is unusual. I would approach the problem by isolating the "collect2/ld" command and then try hard to determine what the command is doing and why it fails (e.g. by "strace"ing it). "collect2" is usually used for "C++" programs (collecting code for the initialization of static C++ objects). Maybe, the difference between Python 2.7 and earlier Python versions is that it includes C++ parts - and maybe, "collect2" has some (still not understood) problems in your environment. From rustompmody at gmail.com Fri Sep 9 02:20:39 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 8 Sep 2016 23:20:39 -0700 (PDT) Subject: How to split value where is comma ? In-Reply-To: References: Message-ID: <930bfc24-5f12-4588-8724-8c029af48b18@googlegroups.com> On Friday, September 9, 2016 at 1:36:24 AM UTC+5:30, Larry Hudson wrote: > On 09/08/2016 07:57 AM, John Gordon wrote: > > In Joaquin Alzola writes: > > > >> Use the split > > > >> a.split(",") > >> for x in a: > >> print(x) > > > > This won't work. split() returns a list of split elements but the > > original string remains unchanged. > > > > You want something like this instead: > > > > newlist = a.split(",") > > for x in newlist: > > print(x) > > > > Even easier... > > for x in a.split(','): > print(x) In all probability, what is required is just: a.split(','); no for, no print And unfortunately none of the answers (that I see) describe the spectrum of what one may really want a.split(',') set(a.split(',')) Less likely (in this case) but important for a learner to be aware of: Counter(a.split(',') And if the original 'a' looked something like >>> a="p:1,q:2,r:42" then you probably want something like: >>> {k:v for item in a.split(',') for k,v in [item.split(':')]} {'q': '2', 'p': '1', 'r': '42'} >>> In all cases the print is irrelevant and unnecessary And if we insist on interpreting the OP request for replacing comma by newline (almost always a misconceived request), one can do: >>> a="p,q,r" >>> str(a.replace(',','\n')) 'p\nq\nr' Sure one can go one step further and do: >>> print str(a.replace(',','\n')) p q r But this is almost always not what the requester wants (even if he thinks it is) [Personal note: When I was a kid I thought that doctors removed fever by sticking a thermometer into one?s mouth. Those who teach that programming needs to start with writing print statements are the same except for not having the excuse of being kids] From dieter at handshake.de Fri Sep 9 02:22:39 2016 From: dieter at handshake.de (dieter) Date: Fri, 09 Sep 2016 08:22:39 +0200 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? References: Message-ID: <87wpil3840.fsf@handshake.de> Chi Hsuan Yen writes: > ... > Apparently OpenSSL verifies the whole certificate chain and > report an error as soon as it finds an invalid certificate in the chain. As it must, if you require verification. When I remember right, you can disable the verification altogether (though you should not for security reasons). > My > questions is: how to tell from several possible causes to > CERTIFICATE_VERIFY_FAILED? Currently both expired self signed certificate > leads to CERTIFICATE_VERIFY_FAILED. Thanks for any help or advice. I would try to find (or write) a utility that follows the certificate chain and provides details information about its state. From yan12125 at gmail.com Fri Sep 9 02:30:52 2016 From: yan12125 at gmail.com (Chi Hsuan Yen) Date: Fri, 9 Sep 2016 14:30:52 +0800 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? In-Reply-To: <87wpil3840.fsf@handshake.de> References: <87wpil3840.fsf@handshake.de> Message-ID: On Fri, Sep 9, 2016 at 2:22 PM, dieter wrote: > Chi Hsuan Yen writes: > > ... > > Apparently OpenSSL verifies the whole certificate chain and > > report an error as soon as it finds an invalid certificate in the chain. > > As it must, if you require verification. > > When I remember right, you can disable the verification altogether > (though you should not for security reasons). > > Yeah we have a CLI option for that, and fortunately (or unfortunately?) it works fine. > My > > questions is: how to tell from several possible causes to > > CERTIFICATE_VERIFY_FAILED? Currently both expired self signed certificate > > leads to CERTIFICATE_VERIFY_FAILED. Thanks for any help or advice. > > I would try to find (or write) a utility that follows the certificate > chain and provides details information about its state. > > Thanks a lot! I just lost my direction when trying to understand how certificate verification works in Python. > -- > https://mail.python.org/mailman/listinfo/python-list > From rustompmody at gmail.com Fri Sep 9 02:31:55 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 8 Sep 2016 23:31:55 -0700 (PDT) Subject: How to split value where is comma ? In-Reply-To: <930bfc24-5f12-4588-8724-8c029af48b18@googlegroups.com> References: <930bfc24-5f12-4588-8724-8c029af48b18@googlegroups.com> Message-ID: On Friday, September 9, 2016 at 11:51:25 AM UTC+5:30, Rustom Mody wrote: > And if the original 'a' looked something like > >>> a="p:1,q:2,r:42" > > then you probably want something like: > > >>> {k:v for item in a.split(',') for k,v in [item.split(':')]} > {'q': '2', 'p': '1', 'r': '42'} > >>> Well if the a did look like >>> a="a:1,b:2,c:42" what we would need is likely to be >>> {k:int(v) for item in a.split(',') for k,v in [item.split(':')]} {'a': 1, 'c': 42, 'b': 2} Likely, but not necessary -- eg we would not want leading zeroes in a phone number to disappear From frank at chagford.com Fri Sep 9 02:47:42 2016 From: frank at chagford.com (Frank Millman) Date: Fri, 9 Sep 2016 08:47:42 +0200 Subject: How to extend a tuple of tuples? Message-ID: Hi all This should be easy, but I cannot figure it out. Assume you have a tuple of tuples - a = ((1, 2), (3, 4)) You want to add a new tuple to it, so that it becomes - ((1, 2), (3, 4), (5, 6)) The obvious way does not work - a += (5, 6) ((1, 2), (3, 4), 5, 6) I have discovered that there is something new in python 3.5 that does work - a = (*a, (5, 6)) ((1, 2), (3, 4), (5, 6)) But how would you have done it before? I know you can convert the outer tuple to a list, add the new tuple, and convert it back again. Is that the only solution? BTW, I do know that tuples are immutable, and that all of the above operations create a new tuple. Frank Millman From dieter at handshake.de Fri Sep 9 02:54:49 2016 From: dieter at handshake.de (dieter) Date: Fri, 09 Sep 2016 08:54:49 +0200 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? References: <87wpil3840.fsf@handshake.de> Message-ID: <87sht936me.fsf@handshake.de> Chi Hsuan Yen writes: > ... > Thanks a lot! I just lost my direction when trying to understand how > certificate verification works in Python. It sets things up for "OpenSSL" and then delegates all details to it. From dieter at handshake.de Fri Sep 9 02:56:31 2016 From: dieter at handshake.de (dieter) Date: Fri, 09 Sep 2016 08:56:31 +0200 Subject: How to extend a tuple of tuples? References: Message-ID: <87oa3x36jk.fsf@handshake.de> "Frank Millman" writes: > Hi all > > This should be easy, but I cannot figure it out. > > Assume you have a tuple of tuples - > > a = ((1, 2), (3, 4)) > > You want to add a new tuple to it, so that it becomes - > > ((1, 2), (3, 4), (5, 6)) > > The obvious way does not work - > > a += (5, 6) > > ((1, 2), (3, 4), 5, 6) You could use: a += (5, 6), or (more clearly written): a += ((5, 6),) From rustompmody at gmail.com Fri Sep 9 02:59:30 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 8 Sep 2016 23:59:30 -0700 (PDT) Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) In-Reply-To: References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: <44b53b01-0f41-499f-9d59-8e5824b90f62@googlegroups.com> On Friday, September 9, 2016 at 2:37:48 AM UTC+5:30, Ben Finney wrote: > Joaquin Alzola writes: > > Added by the MTA of the company not by my client. > > Right. So, here are things you can do (that we cannot) about this: > * Switch to a different mail service, one which does not add that > nonsense to your email. Here is a recent action of google that has received at the moment 337,048 petitions: https://www.change.org/p/google-inc-google-put-palestine-on-your-maps Do you believe that Google is more ethical than Lebara? Ok you didn't suggest to use gmail (ie google) specifically So what do you suggest to people (like myself) who?s primary email is gmail and are incensed with such actions?? From rustompmody at gmail.com Fri Sep 9 03:07:38 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 Sep 2016 00:07:38 -0700 (PDT) Subject: How to extend a tuple of tuples? In-Reply-To: References: Message-ID: On Friday, September 9, 2016 at 12:18:24 PM UTC+5:30, Frank Millman wrote: > Hi all > > This should be easy, but I cannot figure it out. > > Assume you have a tuple of tuples - > > a = ((1, 2), (3, 4)) > > You want to add a new tuple to it, so that it becomes - > > ((1, 2), (3, 4), (5, 6)) Your example does not add inside the inner tuples So I am simplifying the question to > Assume you have a tuple of tuples - > > a = (1 2 3) > > You want to add a new element to it, so that it becomes - > > (1 2 3 4) >>> t = (1,2,3) >>> new = t + (4,) >>> new (1, 2, 3, 4) >>> Slightly harder if the new addition were inbetween >>> t = (1,2,3) >>> t[:1] (1,) >>> t[1:] (2, 3) >>> t[:1] + (42,) + t[1:] (1, 42, 2, 3) From rustompmody at gmail.com Fri Sep 9 03:15:31 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 Sep 2016 00:15:31 -0700 (PDT) Subject: What you can do about legalese nonsense on email In-Reply-To: References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: On Friday, September 9, 2016 at 6:49:52 AM UTC+5:30, Terry Reedy wrote: > On 9/8/2016 4:52 PM, Ben Finney wrote: > > Joaquin Alzola writes: > >> >> > >> Cannot do anything. > > > > That's not true; you can do more than we. > > > >> Added by the MTA of the company not by my client. > > > > Right. So, here are things you can do (that we cannot) about this: > > Something that some 'we' could do is ask the python-list > manager/programmers, or more broadly, the mailman developers, to > recognize an 'end of message' line, such as '--end message--' and delete > it and anything appended thereafter. Then Joaquin and people in a > similar situation could add the magic line as the end of a signature block. > > -- > Terry Jan Reedy Thanks Terry for a constructive thought. From ben+python at benfinney.id.au Fri Sep 9 03:42:39 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 09 Sep 2016 17:42:39 +1000 Subject: How to extend a tuple of tuples? References: Message-ID: <85k2elr028.fsf@benfinney.id.au> "Frank Millman" writes: > Assume you have a tuple of tuples - > > a = ((1, 2), (3, 4)) > > You want to add a new tuple to it, so that it becomes As you acknowledge, the tuple ?a? can't become anything else. Instead, you need to create a different value. > The obvious way does not work - > > a += (5, 6) > > ((1, 2), (3, 4), 5, 6) Right, because a tuple is immutable. So instead, you want a different tuple. You do that by creating it, explicitly constructing a new sequence with the items you want:: b = tuple([ item for item in a ] + [(5, 6)]) -- \ ?Look at it this way: Think of how stupid the average person | `\ is, and then realise half of 'em are stupider than that.? | _o__) ?George Carlin, _Doin' It Again_, 1990 | Ben Finney From list at qtrac.plus.com Fri Sep 9 03:52:19 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 9 Sep 2016 00:52:19 -0700 (PDT) Subject: Is it possible to process dist files before they are build via a setuptools hook? Message-ID: Hi, I use setuptools (in my case with cx_Freeze) to package some of my Python applications. As part of this process a build\exe.win-amd64-3.4 dir is created with all the necessary files, and then a separate dist\ dir is created with the distributable package (e.g., a .msi file). I'd like to run UPX https://upx.github.io/ on all the .dll, .py, and .exe files in the build dir _before_ they are put into the distributable package. So, I need to have some hook that lets me run a python script after the build dir has been populated but before the distributable is made -- is this possible? Thanks. From jussi.piitulainen at helsinki.fi Fri Sep 9 03:57:04 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 09 Sep 2016 10:57:04 +0300 Subject: How to extend a tuple of tuples? References: <85k2elr028.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > Frank Millman writes: > >> Assume you have a tuple of tuples - >> >> a = ((1, 2), (3, 4)) >> >> You want to add a new tuple to it, so that it becomes > > As you acknowledge, the tuple ?a? can't become anything else. Instead, > you need to create a different value. > >> The obvious way does not work - >> >> a += (5, 6) >> >> ((1, 2), (3, 4), 5, 6) > > Right, because a tuple is immutable. > > So instead, you want a different tuple. You do that by creating it, > explicitly constructing a new sequence with the items you want:: > > b = tuple([ > item for item in a > ] + [(5, 6)]) b = tuple(list(a) + [(5,6)]) b = a + tuple([(5,6)]) b = a + ((5,6),) b = tuple(itertools.chain(iter(a), iter(((5,6),)))) # :)))) From yan12125 at gmail.com Fri Sep 9 04:18:18 2016 From: yan12125 at gmail.com (Chi Hsuan Yen) Date: Fri, 9 Sep 2016 16:18:18 +0800 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? In-Reply-To: <87sht936me.fsf@handshake.de> References: <87wpil3840.fsf@handshake.de> <87sht936me.fsf@handshake.de> Message-ID: On Fri, Sep 9, 2016 at 2:54 PM, dieter wrote: > Chi Hsuan Yen writes: > > ... > > Thanks a lot! I just lost my direction when trying to understand how > > certificate verification works in Python. > > It sets things up for "OpenSSL" and then delegates all details > to it. > > Thanks, sounds a great start point. I'll look into OpenSSL. > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Fri Sep 9 04:53:08 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 18:53:08 +1000 Subject: How to split value where is comma ? In-Reply-To: <930bfc24-5f12-4588-8724-8c029af48b18@googlegroups.com> References: <930bfc24-5f12-4588-8724-8c029af48b18@googlegroups.com> Message-ID: On Fri, Sep 9, 2016 at 4:20 PM, Rustom Mody wrote: > [Personal note: When I was a kid I thought that doctors removed fever by sticking > a thermometer into one?s mouth. > Those who teach that programming needs to start with writing print statements > are the same except for not having the excuse of being kids] I agree. People should learn that print is not a statement any more, it's a function. And then use it. Use it often, use it early. Know what your program is doing. Practicality beats pure functional programming? ChrisA From lawrencedo99 at gmail.com Fri Sep 9 05:16:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 02:16:18 -0700 (PDT) Subject: Suggestions to improve a code In-Reply-To: <44969ca1-67d0-4d5d-8fe4-f2531b66fcf9@googlegroups.com> References: <44969ca1-67d0-4d5d-8fe4-f2531b66fcf9@googlegroups.com> Message-ID: On Wednesday, September 7, 2016 at 2:55:37 AM UTC+12, GP wrote: > MaxLengthOfItem_Index =f_LMax(shelves2,MaxLengthOfItem) MaxLengthOfItem_Index = max(range(len(shelves2)), key = lambda i : shelves2[i]["Length"]) From lawrencedo99 at gmail.com Fri Sep 9 05:23:51 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 02:23:51 -0700 (PDT) Subject: PEP 492: isn't the "await" redundant? In-Reply-To: <87d1kv4zck.fsf@elektro.pacujo.net> References: <87h9a750kt.fsf@elektro.pacujo.net> <87d1kv4zck.fsf@elektro.pacujo.net> Message-ID: On Friday, August 26, 2016 at 10:08:25 PM UTC+12, Marko Rauhamaa wrote: > Ultimately, asyncio and multithreading might well merge. It will be > difficult for a programmer to decide in the beginning of the design > which way to go as the programming models are almost identical. The two will never merge, because asyncio is non-preemptive, while threading is preemptive. Threading is for compute performance (and this is no good in pure Python unless you write a C extension module), at the cost of much trickier programming and greater propensity to bugs, while asyncio lets you interleave background processing with waits for time-consuming external activities (I/O, including network I/O, or just waiting for the user to click a button or press a key), while keeping the race conditions manageable. So you see, they have very different application areas, that only superficially overlap. From lawrencedo99 at gmail.com Fri Sep 9 05:26:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 02:26:02 -0700 (PDT) Subject: libdivecomputer In-Reply-To: <7dYuz.645263$OB.604309@fx36.am4> References: <7dYuz.645263$OB.604309@fx36.am4> Message-ID: <3c6079c1-20de-4eec-b63c-7e9f5a7ac241@googlegroups.com> On Wednesday, August 24, 2016 at 1:29:55 AM UTC+12, alister wrote: > I already have an application that works fine (sub-surface) so this is > more of a curiosity, delving into ctypes is not something I want to try > just yet. Why not? It would be a great way to learn ctypes. :) From rosuav at gmail.com Fri Sep 9 05:28:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 19:28:27 +1000 Subject: PEP 492: isn't the "await" redundant? In-Reply-To: References: <87h9a750kt.fsf@elektro.pacujo.net> <87d1kv4zck.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 9, 2016 at 7:23 PM, Lawrence D?Oliveiro wrote: > On Friday, August 26, 2016 at 10:08:25 PM UTC+12, Marko Rauhamaa wrote: >> Ultimately, asyncio and multithreading might well merge. It will be >> difficult for a programmer to decide in the beginning of the design >> which way to go as the programming models are almost identical. > > The two will never merge, because asyncio is non-preemptive, while threading is preemptive. Threading is for compute performance (and this is no good in pure Python unless you write a C extension module), at the cost of much trickier programming and greater propensity to bugs, while asyncio lets you interleave background processing with waits for time-consuming external activities (I/O, including network I/O, or just waiting for the user to click a button or press a key), while keeping the race conditions manageable. > > So you see, they have very different application areas, that only superficially overlap. FWIW I think it's great that they have similar coding styles. We don't have a problem with threading and multiprocessing having very similar APIs, do we? Yet they exist to solve distinctly different problems. ChrisA From cloverobert at gmail.com Fri Sep 9 05:41:49 2016 From: cloverobert at gmail.com (Robert Clove) Date: Fri, 9 Sep 2016 15:11:49 +0530 Subject: ldap or active directory module Message-ID: Is it possible to find the following things using python ldap or active directory module I want to find if the particular group exist in my active directory also another function to find the user in a particular group From talari.gopiprashanth.gopi2 at gmail.com Fri Sep 9 05:46:32 2016 From: talari.gopiprashanth.gopi2 at gmail.com (talari.gopiprashanth.gopi2 at gmail.com) Date: Fri, 9 Sep 2016 02:46:32 -0700 (PDT) Subject: import pybel in python error code Message-ID: ValueError Traceback (most recent call last) in () 1 from django.conf import settings ----> 2 import pybel 3 import random, os C:\Miniconda2\lib\site-packages\pybel.py in () 67 _obconv = ob.OBConversion() 68 _builder = ob.OBBuilder() ---> 69 informats = _formatstodict(_obconv.GetSupportedInputFormat()) 70 """A dictionary of supported input formats""" 71 outformats = _formatstodict(_obconv.GetSupportedOutputFormat()) C:\Miniconda2\lib\site-packages\pybel.py in _formatstodict(list) 63 list = [list.get(i) for i in range(list.size())] 64 broken = [x.replace("[Read-only]", "").replace("[Write-only]","").split(" -- ") for x in list] ---> 65 broken = [(x,y.strip()) for x,y in broken] 66 return dict(broken) 67 _obconv = ob.OBConversion() ValueError: need more than 1 value to unpack From yan12125 at gmail.com Fri Sep 9 05:47:51 2016 From: yan12125 at gmail.com (Chi Hsuan Yen) Date: Fri, 9 Sep 2016 17:47:51 +0800 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? In-Reply-To: References: <87wpil3840.fsf@handshake.de> <87sht936me.fsf@handshake.de> Message-ID: On Fri, Sep 9, 2016 at 4:18 PM, Chi Hsuan Yen wrote: > > > On Fri, Sep 9, 2016 at 2:54 PM, dieter wrote: > >> Chi Hsuan Yen writes: >> > ... >> > Thanks a lot! I just lost my direction when trying to understand how >> > certificate verification works in Python. >> >> It sets things up for "OpenSSL" and then delegates all details >> to it. >> >> > Thanks, sounds a great start point. I'll look into OpenSSL. > > >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > I found that OpenSSL provides an X509 callback hook that allows clients to know why the verification process fails. Seems CPython does not use it yet. I hope it can be added to CPython. Where should I go next, python-dev, python-ideas or bugs.python.org? Thanks. From rosuav at gmail.com Fri Sep 9 05:52:09 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 19:52:09 +1000 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? In-Reply-To: References: <87wpil3840.fsf@handshake.de> <87sht936me.fsf@handshake.de> Message-ID: On Fri, Sep 9, 2016 at 7:47 PM, Chi Hsuan Yen wrote: > I found that OpenSSL provides an X509 callback hook that allows clients to > know why the verification process fails. Seems CPython does not use it yet. > I hope it can be added to CPython. Where should I go next, python-dev, > python-ideas or bugs.python.org? Thanks. Are you wanting a way to provide a custom callback from your application, or have this as a standard feature that enhances the error return? Either way, I would go to python-ideas with details about what you're hoping for. It sounds like it's not going to be overly complex, so it might end up just going straight to the tracker, but I'd start with -ideas. ChrisA From yan12125 at gmail.com Fri Sep 9 06:00:09 2016 From: yan12125 at gmail.com (Chi Hsuan Yen) Date: Fri, 9 Sep 2016 18:00:09 +0800 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? In-Reply-To: References: <87wpil3840.fsf@handshake.de> <87sht936me.fsf@handshake.de> Message-ID: On Fri, Sep 9, 2016 at 5:52 PM, Chris Angelico wrote: > On Fri, Sep 9, 2016 at 7:47 PM, Chi Hsuan Yen wrote: > > I found that OpenSSL provides an X509 callback hook that allows clients > to > > know why the verification process fails. Seems CPython does not use it > yet. > > I hope it can be added to CPython. Where should I go next, python-dev, > > python-ideas or bugs.python.org? Thanks. > > Are you wanting a way to provide a custom callback from your > application, or have this as a standard feature that enhances the > error return? > > Either way, I would go to python-ideas with details about what you're > hoping for. It sounds like it's not going to be overly complex, so it > might end up just going straight to the tracker, but I'd start with > -ideas. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > Thanks. I'll try to organize what I want and post to python-ideas. Best, Yen Chi Hsuan From steve+python at pearwood.info Fri Sep 9 06:07:41 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 09 Sep 2016 20:07:41 +1000 Subject: How to extend a tuple of tuples? References: Message-ID: <57d289ef$0$1591$c3e8da3$5496439d@news.astraweb.com> On Fri, 9 Sep 2016 04:47 pm, Frank Millman wrote: > Hi all > > This should be easy, but I cannot figure it out. > > Assume you have a tuple of tuples - > > a = ((1, 2), (3, 4)) > > You want to add a new tuple to it, so that it becomes - > > ((1, 2), (3, 4), (5, 6)) a = a + ((5, 6),) You might think that you can just add (5, 6) but that doesn't work: py> a + (5, 6) ((1, 2), (3, 4), 5, 6) The plus operator builds a new tuple containing the contents of each of the two tuples concatenated, so to get the result that you want you need a tuple containing (5, 6) as the one and only item. Because that's a tuple with one item, you need a trailing comma: py> len( ((5, 6),) ) 1 py> a + ((5, 6),) ((1, 2), (3, 4), (5, 6)) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From frank at chagford.com Fri Sep 9 06:13:11 2016 From: frank at chagford.com (Frank Millman) Date: Fri, 9 Sep 2016 12:13:11 +0200 Subject: How to extend a tuple of tuples? In-Reply-To: References: Message-ID: "Frank Millman" wrote in message news:nqtlue$unj$1 at blaine.gmane.org... > Assume you have a tuple of tuples - > a = ((1, 2), (3, 4)) > You want to add a new tuple to it, so that it becomes - > ((1, 2), (3, 4), (5, 6)) Thanks all. The one I was looking for was a += (5, 6), I understand it now - makes perfect sense. Frank From alister.ware at ntlworld.com Fri Sep 9 06:30:03 2016 From: alister.ware at ntlworld.com (alister) Date: Fri, 09 Sep 2016 10:30:03 GMT Subject: libdivecomputer References: <7dYuz.645263$OB.604309@fx36.am4> <3c6079c1-20de-4eec-b63c-7e9f5a7ac241@googlegroups.com> Message-ID: On Fri, 09 Sep 2016 02:26:02 -0700, Lawrence D?Oliveiro wrote: > On Wednesday, August 24, 2016 at 1:29:55 AM UTC+12, alister wrote: >> I already have an application that works fine (sub-surface) so this is >> more of a curiosity, delving into ctypes is not something I want to try >> just yet. > > Why not? It would be a great way to learn ctypes. :) indeed it would, however I really don't wish to get bogged down in low level stuff any more (ok a necessary evil with my AVR programming but that is all very basic anyway) which is why i decided on python as my language of choice. -- Ginsberg's Theorem: (1) You can't win. (2) You can't break even. (3) You can't even quit the game. Freeman's Commentary on Ginsberg's theorem: Every major philosophy that attempts to make life seem meaningful is based on the negation of one part of Ginsberg's Theorem. To wit: (1) Capitalism is based on the assumption that you can win. (2) Socialism is based on the assumption that you can break even. (3) Mysticism is based on the assumption that you can quit the game. From steve+python at pearwood.info Fri Sep 9 06:33:40 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 09 Sep 2016 20:33:40 +1000 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> <44b53b01-0f41-499f-9d59-8e5824b90f62@googlegroups.com> Message-ID: <57d29006$0$1615$c3e8da3$5496439d@news.astraweb.com> On Fri, 9 Sep 2016 04:59 pm, Rustom Mody wrote: > On Friday, September 9, 2016 at 2:37:48 AM UTC+5:30, Ben Finney wrote: >> Joaquin Alzola writes: >> > Added by the MTA of the company not by my client. >> >> Right. So, here are things you can do (that we cannot) about this: >> * Switch to a different mail service, one which does not add that >> nonsense to your email. > > Here is a recent action of google that has received at the moment 337,048 > petitions: > https://www.change.org/p/google-inc-google-put-palestine-on-your-maps > > Do you believe that Google is more ethical than Lebara? Hell no! http://img0.joyreactor.com/pics/post/comics-google-facebook-245504.jpeg But in this specific case, Google is not entirely in the wrong re Palestine. It *is* a disputed area, and Google cannot satisfy everyone no matter what they do. If you search for "Palestine" in Google Maps, you get a map which (at least in Australia) clearly shows the West Bank and Gaza Strip as disputed territories: https://www.google.com.au/maps/place/Palestine/ More here: https://www.theguardian.com/technology/2016/aug/10/google-maps-accused-remove-palestine http://opennews.kzhu.io/map-disputes/?_ga=1.48243875.420098949.1397702661 > Ok you didn't suggest to use gmail (ie google) specifically > > So what do you suggest to people (like myself) who?s primary email is > gmail and are incensed with such actions?? Whatever you do, don't use Yahoo Mail or AOL unless there is *absolutely* no other alternative. They are actively hostile to mailing lists and even worse for good email practice than Gmail. I don't know about others, but most ISPs in Australia offer at least one email address per customer. So although there aren't many *great* alternatives to Gmail, there are some good and so-so alternatives: * run your own mail server (easy enough that I can do it) * your work or school email * your ISP email * Outlook.Com (Hotmail) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ink.icr at gmail.com Fri Sep 9 06:48:15 2016 From: ink.icr at gmail.com (Igor Kozin) Date: Fri, 9 Sep 2016 03:48:15 -0700 (PDT) Subject: nested loops in Python In-Reply-To: References: <2618038c-5b4c-4e0a-a936-74789aaf5819@googlegroups.com> Message-ID: <0c67739a-55da-4f58-854d-86b2c7e3d6b3@googlegroups.com> I think you are right, it's the assignment itself which is slow. Merged loop is only a tad quicker. On Thursday, September 8, 2016 at 6:04:41 PM UTC+1, Christian Gollwitzer wrote: > > Why nested loops are so slow in Python? Is it because new contexts are created? > > For more details, see > > http://stackoverflow.com/questions/26611043/numpy-vs-cython-nested-loop-so-slow > > http://stackoverflow.com/questions/39371021/efficient-loop-over-numpy-array > > The answers are right there, too - what are you mising? CPython is an > interpreter. For every seemingly simple operation like a[i]=j, a > function pointer is called, the variables contain polymorphic types > which are morphed, etc. The same thing in compiled code is a single > machine instruction. Speed differences of ~100x are normal between > compiled and interpreted code over all dynamic languages. > > Christian From darcy at Vex.Net Fri Sep 9 07:23:04 2016 From: darcy at Vex.Net (D'Arcy J.M. Cain) Date: Fri, 9 Sep 2016 07:23:04 -0400 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) In-Reply-To: <1473373664.130002.720118257.14D72BFE@webmail.messagingengine.com> References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> <1473373664.130002.720118257.14D72BFE@webmail.messagingengine.com> Message-ID: <20160909072304.02d97f6e@imp> On Thu, 08 Sep 2016 18:27:44 -0400 Random832 wrote: > If every lawyer in the world benefits from the interpretation that > this sort of notice is legally effective (since tomorrow it may be > they who accidentaly send privileged information), who will argue in > court that it's not? The reality is more complex, and it appears that > it may only apply if the accidental recipient is a lawyer. I really I often wonder if these automatic disclaimers actually remove any protection that they might have if they were used judiciously. If they had any validity wouldn't the fact that they are attached to every email, even ones obviously meant for the public, give someone an argument that they don't really apply? -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From marko at pacujo.net Fri Sep 9 07:26:59 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 09 Sep 2016 14:26:59 +0300 Subject: PEP 492: isn't the "await" redundant? References: <87h9a750kt.fsf@elektro.pacujo.net> <87d1kv4zck.fsf@elektro.pacujo.net> Message-ID: <87lgz1pb3w.fsf@elektro.pacujo.net> Chris Angelico : > FWIW I think it's great that they have similar coding styles. We don't > have a problem with threading and multiprocessing having very similar > APIs, do we? Yet they exist to solve distinctly different problems. Well, Ext4, BtrFS, XFS and ReiserFS have very similar APIs. In fact, they exist to solve the same problems. One day, a file system might emerge that supersedes all other file systems. It's a similar deal between asyncio and threading. The problem space is the same: managing concurrency with almost identical programming models. Marko From __peter__ at web.de Fri Sep 9 07:29:59 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 Sep 2016 13:29:59 +0200 Subject: import pybel in python error code References: Message-ID: talari.gopiprashanth.gopi2 at gmail.com wrote: > ValueError Traceback (most recent call > last) in () > 1 from django.conf import settings > ----> 2 import pybel > 3 import random, os > > C:\Miniconda2\lib\site-packages\pybel.py in () > 67 _obconv = ob.OBConversion() > 68 _builder = ob.OBBuilder() > ---> 69 informats = _formatstodict(_obconv.GetSupportedInputFormat()) > 70 """A dictionary of supported input formats""" > 71 outformats = _formatstodict(_obconv.GetSupportedOutputFormat()) > > C:\Miniconda2\lib\site-packages\pybel.py in _formatstodict(list) > 63 list = [list.get(i) for i in range(list.size())] > 64 broken = [x.replace("[Read-only]", > "").replace("[Write-only]","").split(" -- ") for x in list] > ---> 65 broken = [(x,y.strip()) for x,y in broken] > 66 return dict(broken) > 67 _obconv = ob.OBConversion() > > ValueError: need more than 1 value to unpack What does >>> import openbabel >>> [s for s in openbabel.OBConversion().GetSupportedInputFormat() ... if s.count(" -- ") != 1] [] print on your machine? There is probably a string that doesn't contain the separator " -- " (note the space at the beginning and the end). From jeanmichel at sequans.com Fri Sep 9 07:40:13 2016 From: jeanmichel at sequans.com (jmp) Date: Fri, 09 Sep 2016 13:40:13 +0200 Subject: Suggestions to improve a code In-Reply-To: <44969ca1-67d0-4d5d-8fe4-f2531b66fcf9@googlegroups.com> References: <44969ca1-67d0-4d5d-8fe4-f2531b66fcf9@googlegroups.com> Message-ID: On 09/06/2016 04:55 PM, GP wrote: > I have a list: > shelves2 =[{'Part No': '1', 'Length': 610.0, 'Width': 50.0}, > {'Part No': '2', 'Length': 2319.0, 'Width': 465.0 }, > {'Part No': '3', 'Length': 5.0,'Width': 465.0}] > > The length of shelf is calculated as follows: > 1. Calculate the maximum length of all items in the shelf. > 2. Calculate width of shelf = 610 (in this case). > 3. Length of shelf : maxlength of all items + length ( if it less than width of shelf) or width of other items such that length of shelf is less than maximum allowed length. > > In the above case the length is 2319+50+5 = 2374. I have the following code which generates it correctly but would like to know if there is a better way to write it. I would like to know some smarter way to write the code ( especially if the "for", "if" statements can be avoided). > list_1=[] > list_2=[] > WidthOfShelf = max([x['Width'] for x in shelves2]) > MaxLengthOfItem = max([x['Length'] for x in shelves2]) > f_LMax=lambda seq, m: [ii for ii in range(0, len(seq)) if seq[ii] ['Length'] >= m][0] > MaxLengthOfItem_Index =f_LMax(shelves2,MaxLengthOfItem) > current= MaxLengthOfItem > > list_1=[shelves2[MaxLengthOfItem_Index]] > list_2 = [MaxLengthOfItem] > del shelves2[MaxLengthOfItem_Index] > for i in range(0,len(shelves2)): > if shelves2[i]['Length'] <= Width: > if (current + shelves2[i]['Length']) or (current + shelves2 [i]['Width'])<= 2438.5 : > q_2= min(shelves2[i]['Length'], shelves2[i]['Width']) > q=shelves2[i] > list_1.append(q) > list_2.append(q_2) > current += (shelves2[i]['Length'] or shelves2[i] ['Width']) > length = sum(list_2) > print("LENGTH:",length) > Hi, Your code does not make any sense. Before making it smarter, you need to make it understandable if you want us to help you. It's ok to write quick and dirty scripts, until you send them for others to review :) Here are my advices: 1/ use meaningful names * list_1, list_2, q_2, q, current give no clue about what information they're supposed to hold * you can use comments instead as sometimes a short name won't do it 2/ provide code that reproduces your problem, executing the above code gives a NameError. ---> 30 if shelves2[i]['Length'] <= Width: NameError: name 'Width' is not defined 3/ name different things with different names. at the end of your code you're printing "length", which is the sum of either length or width fields. It's difficult to guess what you're trying to achieve. Same confusion about the field 'Length' of a shelf, and the length of a shelf that is computed elsewhere. My guess would be that a shelf has an innate length, and another one depending on the shelves it's inserted into. If so, find 2 different names. 4/ You are iterating like a C/C++ addict. Short story: resist the urge to iterate over indexes. for i in range(0,len(shelves2)): print(shelves2[i]['Length']) is best written for shelf in shelves2: print(shelf['Length']) long story : http://nedbatchelder.com/text/iter.html 5/ use list comprehension to create filtered list: for shelf in [s for s in shelves2 if s['Length'] <= s['Width']]: ... Hope it helps somehow. jm From ned at nedbatchelder.com Fri Sep 9 07:47:45 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 9 Sep 2016 04:47:45 -0700 (PDT) Subject: How to extend a tuple of tuples? In-Reply-To: References: Message-ID: <44e067ce-f499-4ca8-87bd-94b18dfc0572@googlegroups.com> On Friday, September 9, 2016 at 6:13:37 AM UTC-4, Frank Millman wrote: > "Frank Millman" wrote in message news:nqtlue$unj$1 at blaine.gmane.org... > > > Assume you have a tuple of tuples - > > > a = ((1, 2), (3, 4)) > > > You want to add a new tuple to it, so that it becomes - > > > ((1, 2), (3, 4), (5, 6)) > > Thanks all. > > The one I was looking for was > > a += (5, 6), > > I understand it now - makes perfect sense. I'm curious why you are using a growing tuple, instead of a list. This seems like a much more natural use for a list. --Ned. From rosuav at gmail.com Fri Sep 9 08:10:33 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 22:10:33 +1000 Subject: PEP 492: isn't the "await" redundant? In-Reply-To: <87lgz1pb3w.fsf@elektro.pacujo.net> References: <87h9a750kt.fsf@elektro.pacujo.net> <87d1kv4zck.fsf@elektro.pacujo.net> <87lgz1pb3w.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 9, 2016 at 9:26 PM, Marko Rauhamaa wrote: > Chris Angelico : >> FWIW I think it's great that they have similar coding styles. We don't >> have a problem with threading and multiprocessing having very similar >> APIs, do we? Yet they exist to solve distinctly different problems. > > Well, Ext4, BtrFS, XFS and ReiserFS have very similar APIs. In fact, > they exist to solve the same problems. One day, a file system might > emerge that supersedes all other file systems. > > It's a similar deal between asyncio and threading. The problem space is > the same: managing concurrency with almost identical programming models. C, Python, Ruby, and COBOL exist to solve the same problems, and have very similar APIs - write your code in a text file, then run it through some parser so it executes. Are we some day going to eliminate all programming languages bar one? I doubt it. And I don't want to. ChrisA From frank at chagford.com Fri Sep 9 08:21:14 2016 From: frank at chagford.com (Frank Millman) Date: Fri, 9 Sep 2016 14:21:14 +0200 Subject: How to extend a tuple of tuples? In-Reply-To: <44e067ce-f499-4ca8-87bd-94b18dfc0572@googlegroups.com> References: <44e067ce-f499-4ca8-87bd-94b18dfc0572@googlegroups.com> Message-ID: "Ned Batchelder" wrote in message news:44e067ce-f499-4ca8-87bd-94b18dfc0572 at googlegroups.com... On Friday, September 9, 2016 at 6:13:37 AM UTC-4, Frank Millman wrote: > > "Frank Millman" wrote in message news:nqtlue$unj$1 at blaine.gmane.org... > > > > The one I was looking for was > > > > a += (5, 6), > > > > I understand it now - makes perfect sense. > > I'm curious why you are using a growing tuple, instead of a list. > This seems like a much more natural use for a list. > The short answer is that I am using it as a dictionary key. However, from The Zen of Python - If the implementation is hard to explain, it's a bad idea. Let's see if I can explain. I am building a series of JOINs for a SQL statement. Some of them can be nested - table A is joined from table B is joined from table C. In other parts of the same SQL statement, table A could be joined from table D which is joined from table E. For each potential candidate, I need to check if I have already built the JOIN. If so, just use it. If not, build it, and update a dictionary to indicate that it has been built. The key to the dictionary is the path to the joined table, which could be several levels deep. I build up a tuple to represent the path. Each table needs two pieces of information to identify it, so I use a tuple for each identifier. The value portion of the dictionary is simply the alias generated for the joined table. I use the alias in the body of the SQL statement. I don't know if that explains it very well. I can supply more info if anyone is curious, or wishes to suggest a better approach. Frank From steve+python at pearwood.info Fri Sep 9 08:27:31 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 09 Sep 2016 22:27:31 +1000 Subject: PEP 492: isn't the "await" redundant? References: <87h9a750kt.fsf@elektro.pacujo.net> <87d1kv4zck.fsf@elektro.pacujo.net> Message-ID: <57d2aab5$0$1590$c3e8da3$5496439d@news.astraweb.com> On Fri, 9 Sep 2016 07:28 pm, Chris Angelico wrote: > We don't > have a problem with threading and multiprocessing having very similar > APIs, do we? Yet they exist to solve distinctly different problems. Surely not? I would think that threading and multiprocessing are two distinct implementations of the same problem: how to run two or more chunks of code at the same time. In CPython we usually say "use threads for I/O bound tasks, processes for CPU bound tasks" but that's only because of the GIL. One doesn't need such a distinction in Jython or IronPython. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 9 08:28:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 22:28:01 +1000 Subject: How to extend a tuple of tuples? In-Reply-To: References: <44e067ce-f499-4ca8-87bd-94b18dfc0572@googlegroups.com> Message-ID: On Fri, Sep 9, 2016 at 10:21 PM, Frank Millman wrote: > I am building a series of JOINs for a SQL statement. Some of them can be > nested - table A is joined from table B is joined from table C. In other > parts of the same SQL statement, table A could be joined from table D which > is joined from table E. > > For each potential candidate, I need to check if I have already built the > JOIN. If so, just use it. If not, build it, and update a dictionary to > indicate that it has been built. > > The key to the dictionary is the path to the joined table, which could be > several levels deep. I build up a tuple to represent the path. Each table > needs two pieces of information to identify it, so I use a tuple for each > identifier. > > The value portion of the dictionary is simply the alias generated for the > joined table. I use the alias in the body of the SQL statement. Sounds fair enough. A tuple is a pretty reasonable way to do this. The other approach would be to craft the aliases directly, as strings. For instance, your first example could be JOIN_A_B_C, and your second JOIN_A_D_E. (Sort the table names alphabetically before "_".join()ing them if you want order to be insignificant.) Obviously this won't do if it runs the risk of crashing into length limits in your SQL engine, but if you find tuples too annoying, this is an equally valid way of crafting the keys for your dictionary. Overall, this sounds like one of those horrendously messy pieces of code that exists because... it's dealing with a horrendously messy situation. Which, sad to say, happens all too often in real-world code, much as we'd love to pretend it doesn't in examples on mailing lists :| ChrisA From rosuav at gmail.com Fri Sep 9 08:38:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 22:38:48 +1000 Subject: PEP 492: isn't the "await" redundant? In-Reply-To: <57d2aab5$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <87h9a750kt.fsf@elektro.pacujo.net> <87d1kv4zck.fsf@elektro.pacujo.net> <57d2aab5$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 9, 2016 at 10:27 PM, Steve D'Aprano wrote: > On Fri, 9 Sep 2016 07:28 pm, Chris Angelico wrote: > >> We don't >> have a problem with threading and multiprocessing having very similar >> APIs, do we? Yet they exist to solve distinctly different problems. > > Surely not? > > I would think that threading and multiprocessing are two distinct > implementations of the same problem: how to run two or more chunks of code > at the same time. > > In CPython we usually say "use threads for I/O bound tasks, processes for > CPU bound tasks" but that's only because of the GIL. One doesn't need such > a distinction in Jython or IronPython. You also want to use processes if you need the ability to kill one of them externally, or track resource usage separately, or have independence of other process-wide features such as current working directory. So there are some problems (eg multi-user services) where the additional isolation is important. In contrast, you want to use threads if you need the ability to quickly and easily share mutable data, or if you want all resource usage to be lumped together - eg if you're not really doing several separate jobs, but are doing one single conceptual job. >From a systems administration POV, threads logically belong together, but processes are distinct beasts that communicate through clearly-defined IPC. There are times when you want one, and times when you want the other. The GIL just pulls a specific category of problem out of the hands of threads and into the hands of processes, due to its inability to spread Python code across CPU cores; but it didn't create the distinction. If a future version of CPython eliminates the GIL and allows threads to concurrently run CPU-heavy code, there will still be a need for multiprocessing. ChrisA From rustompmody at gmail.com Fri Sep 9 08:44:12 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 9 Sep 2016 05:44:12 -0700 (PDT) Subject: How to extend a tuple of tuples? In-Reply-To: References: <44e067ce-f499-4ca8-87bd-94b18dfc0572@googlegroups.com> Message-ID: <70c16fd7-ea4d-4eb0-90bf-f8f30c1094b2@googlegroups.com> On Friday, September 9, 2016 at 5:58:16 PM UTC+5:30, Chris Angelico wrote: > On Fri, Sep 9, 2016 at 10:21 PM, Frank Millman wrote: > > I am building a series of JOINs for a SQL statement. Some of them can be > > nested - table A is joined from table B is joined from table C. In other > > parts of the same SQL statement, table A could be joined from table D which > > is joined from table E. > > > > For each potential candidate, I need to check if I have already built the > > JOIN. If so, just use it. If not, build it, and update a dictionary to > > indicate that it has been built. > > > > The key to the dictionary is the path to the joined table, which could be > > several levels deep. I build up a tuple to represent the path. Each table > > needs two pieces of information to identify it, so I use a tuple for each > > identifier. > > > > The value portion of the dictionary is simply the alias generated for the > > joined table. I use the alias in the body of the SQL statement. > > Sounds fair enough. A tuple is a pretty reasonable way to do this. > > The other approach would be to craft the aliases directly, as strings. > For instance, your first example could be JOIN_A_B_C, and your second > JOIN_A_D_E. (Sort the table names alphabetically before "_".join()ing > them if you want order to be insignificant.) If the requirement is to have ('A', 'B') == ('B', 'A') the correct data structure to use is set(['A','B']) In this case frozenset for immutability or allowed-for-dict-key requirements [Disclaimer: Ive never used it like this so dont know rough edges; just talking ?theoretically?!!] From jeanmichel at sequans.com Fri Sep 9 08:50:05 2016 From: jeanmichel at sequans.com (jmp) Date: Fri, 09 Sep 2016 14:50:05 +0200 Subject: What you can do about legalese nonsense on email In-Reply-To: <85y432qfkz.fsf_-_@benfinney.id.au> References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: On 09/08/2016 10:52 PM, Ben Finney wrote: > Joaquin Alzola writes: > >> > >> Cannot do anything. > > That's not true; you can do more than we. > >> Added by the MTA of the company not by my client. > > Right. So, here are things you can do (that we cannot) about this: > > * Complain, with reasoned explanation, to the management responsible for > deciding whether that nonsense continues to be added to every message. > > If they haven't heard the complaint before, they will no longer have > that excuse. If they have heard the complaint before, yours will add > to the weight of evidence that this is not wanted. > > * Switch to a different mail service, one which does not add that > nonsense to your email. > > Yes, this is inconvenient for you. But it's impossible for us to do on > your behalf, so you are in a position of more power than us. > > * Complain again to the management responsible for the ongoing decision > to place nonsense on your email, that you have been forced to use a > different mail system in order not to appear contemptuous of the > communities in which you participate. > > If you are participating for reasons of benefit to the organisation, > point out that their ongoing decision is making that more difficult > for their employees. > > These are all powers you have; please don't feel that you can do > nothing. > I've been there, I feel the pain of both sides. Complaining won't do much, companies are not democracies, people are right because their title says so, not because they actually are. I personally had to switch to a usenet client instead of a mail client (I think so). I'm using thunderbird for that purpose configured with news.gmane.org The good news is that you don't need yet another fake email address. jm From nomail at com.invalid Fri Sep 9 09:32:03 2016 From: nomail at com.invalid (ast) Date: Fri, 9 Sep 2016 15:32:03 +0200 Subject: Where to store finalized python programs Message-ID: <57d2b9d9$0$712$426a34cc@news.free.fr> hi Is there a web site to store python programs in order to make them accessible for every boby ? I know pypy, but I understood that it is for modules only. From rosuav at gmail.com Fri Sep 9 09:43:19 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Sep 2016 23:43:19 +1000 Subject: Where to store finalized python programs In-Reply-To: <57d2b9d9$0$712$426a34cc@news.free.fr> References: <57d2b9d9$0$712$426a34cc@news.free.fr> Message-ID: On Fri, Sep 9, 2016 at 11:32 PM, ast wrote: > hi > > Is there a web site to store python programs > in order to make them accessible for every boby ? > > I know pypy, but I understood that it is for modules > only. I would recommend source code hosting sites - gitlab.com, github.com, bitbucket.org, launchpad.net, etc. Most of them have some kind of zero-dollar plan for open source projects. Make sure you have a good README, so people know how to use your program, and then basically all you do is push from source control (git, Mercurial, Bazaar, etc) straight to the remote hosting site. (You DO use source control, right? If not, start using it *now*.) ChrisA From grant.b.edwards at gmail.com Fri Sep 9 10:33:23 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 9 Sep 2016 14:33:23 +0000 (UTC) Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> <1473373664.130002.720118257.14D72BFE@webmail.messagingengine.com> Message-ID: On 2016-09-08, Random832 wrote: > On Thu, Sep 8, 2016, at 18:13, Grant Edwards wrote: >> After all, that boilerplate just makes the corporation look stupid and >> incompetent. Any email that leaves the corporate network must be >> assumed to be visible to world+dog. Anybody who thinks differently is >> deluded and should not be allowed access to information that is >> "confidential and subject to privledge". > > If every lawyer in the world benefits from the interpretation that this > sort of notice is legally effective (since tomorrow it may be they who > accidentaly send privileged information), who will argue in court that > it's not? Anybody who benefits from it not being effective -- like the NYT reporter who broke a front page story based on a misdirected email (described in the article to which you linked). -- Grant Edwards grant.b.edwards Yow! Is this sexual at intercourse yet?? Is it, gmail.com huh, is it?? From python at org.invalid Fri Sep 9 10:47:10 2016 From: python at org.invalid (Python) Date: Fri, 9 Sep 2016 16:47:10 +0200 Subject: Where to store finalized python programs In-Reply-To: <57d2b9d9$0$712$426a34cc@news.free.fr> References: <57d2b9d9$0$712$426a34cc@news.free.fr> Message-ID: <57d2cb6e$0$3329$426a74cc@news.free.fr> Le 09/09/2016 ? 15:32, ast a ?crit : > hi > > Is there a web site to store python programs > in order to make them accessible for every boby ? > > I know pypy, but I understood that it is for modules > only. Not only, it is for programs too, for instance: pip install weboob From Joshua.R.English at gmail.com Fri Sep 9 13:47:17 2016 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 9 Sep 2016 10:47:17 -0700 (PDT) Subject: Mysterious Logging Handlers Message-ID: <247db0ab-efe7-484b-a418-dd219f68a8e5@googlegroups.com> I have a Python script that imports a utility script. Both scripts use logging, but the logs don't work as advertised. I'm getting logging output from the utility script but none from the main file. Worse, the format of the utility script's logs don't match anything I define. The utility script is called xlreader.py. It has the following lines: -- begin snippet -- import logging XLOGGER = logging.getLogger('XLREADER') -- end snippet -- And it calls XLOGGER.debug(), XLOGGER.error() and XLOGGER.info() but it never defines a handler. The main script imports xlreader but does not reference XLOGGER. It defines its own logger: -- begin snippet -- import logging import xlreader LOG = logging.getLogger('SHIPPING') FORMAT = '%(asctime)-15s %(name)s %(level)-8s %(message)s' logging.basicConfig(format=FORMAT,level=logging.DEBUG) handler = logging.StreamHandler() formatter = logging.Formatter(FORMAT) handler.setFormatter(formatter) LOG.addHandler(handler) -- end snippet -- I added the logging.basicConfig line but it didn't have any effect. I created the second handler separately. When I run the scriptI get logging information from only xlreader, not from the main script: DEBUG:XLREADER:Creating Excel Reader This format isn't defined anywhere. T Even more mysterious, after I run the file (in an IDE so I have a REPL afterwards), I have: >>> XLOGGER >>> >>> XLOGGER.handlers >>> [] >>> XLOGGER.debug('test') >>> DEBUG:XLREADER:test >>> LOG.handlers >>> [, ] >>> [h.formatter._fmt for h in LOG.handlers] >>> ['%(asctime)-15s %(name)s %(level)-8s %(message)s', '%(asctime)-15s %(name)s %(level)-8s %(message)s'] How can I track where this formatting is coming from? Josh From spk265 at nyu.edu Fri Sep 9 13:59:23 2016 From: spk265 at nyu.edu (Shyam Parimal Katti) Date: Fri, 9 Sep 2016 13:59:23 -0400 Subject: ldap or active directory module In-Reply-To: References: Message-ID: Sure, have you tried it and failed? I remember using this: https://www.python-ldap.org/docs.html year back and was able to do many operations including lookups. On Fri, Sep 9, 2016 at 5:41 AM, Robert Clove wrote: > Is it possible to find the following things using python ldap or active > directory module > I want to find if the particular group exist in my active directory also > another function to find the user in a particular group > -- > https://mail.python.org/mailman/listinfo/python-list > From gordon at panix.com Fri Sep 9 14:29:20 2016 From: gordon at panix.com (John Gordon) Date: Fri, 9 Sep 2016 18:29:20 +0000 (UTC) Subject: Mysterious Logging Handlers References: <247db0ab-efe7-484b-a418-dd219f68a8e5@googlegroups.com> Message-ID: In <247db0ab-efe7-484b-a418-dd219f68a8e5 at googlegroups.com> Josh English writes: > When I run the scriptI get logging information from only xlreader, not > from the main script: > DEBUG:XLREADER:Creating Excel Reader > This format isn't defined anywhere. That is the default logging format; it's used when you haven't supplied any format of your own. The snippet of xlreader.py does not define any format, so it seems like that's where it's coming from. (This seems pretty straightforward; am I missing something?) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From __peter__ at web.de Fri Sep 9 14:30:36 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 Sep 2016 20:30:36 +0200 Subject: Mysterious Logging Handlers References: <247db0ab-efe7-484b-a418-dd219f68a8e5@googlegroups.com> Message-ID: Josh English wrote: > I have a Python script that imports a utility script. Both scripts use > logging, but the logs don't work as advertised. I'm getting logging output > from the utility script but none from the main file. Worse, the format of > the utility script's logs don't match anything I define. > > The utility script is called xlreader.py. It has the following lines: > > -- begin snippet -- > import logging > XLOGGER = logging.getLogger('XLREADER') > -- end snippet -- > > And it calls XLOGGER.debug(), XLOGGER.error() and XLOGGER.info() but it > never defines a handler. > > > The main script imports xlreader but does not reference XLOGGER. It > defines its own logger: > > -- begin snippet -- > import logging > import xlreader > > LOG = logging.getLogger('SHIPPING') > FORMAT = '%(asctime)-15s %(name)s %(level)-8s %(message)s' That should be either levelname or levelno in the format string. > logging.basicConfig(format=FORMAT,level=logging.DEBUG) > handler = logging.StreamHandler() > formatter = logging.Formatter(FORMAT) > handler.setFormatter(formatter) > LOG.addHandler(handler) > -- end snippet -- > > I added the logging.basicConfig line but it didn't have any effect. That means there are already handlers configured for the root logger, for example because basicConfig() has been called before. > I > created the second handler separately. > > When I run the scriptI get logging information from only xlreader, not > from the main script: > > DEBUG:XLREADER:Creating Excel Reader > > This format isn't defined anywhere. T > > Even more mysterious, after I run the file (in an IDE so I have a REPL > afterwards), I have: Don't run your code in an IDE. The interaction between your and their code can make debugging harder than necessary. From gordon at panix.com Fri Sep 9 14:35:31 2016 From: gordon at panix.com (John Gordon) Date: Fri, 9 Sep 2016 18:35:31 +0000 (UTC) Subject: ldap or active directory module References: Message-ID: In Robert Clove writes: > I want to find if the particular group exist in my active directory Search on the group's DN, specifying SCOPE_BASE as the search scope. If you get a result, then the group exists, otherwise it doesn't. > also another function to find the user in a particular group Do the same search as above, returning the "member" attribute. Get the search result and then inspect the list of returned members. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From lawrencedo99 at gmail.com Fri Sep 9 16:59:07 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 13:59:07 -0700 (PDT) Subject: Is it possible to process dist files before they are build via a setuptools hook? In-Reply-To: References: Message-ID: <85f042fe-e588-4865-a0b4-f7b131d9c1e0@googlegroups.com> On Friday, September 9, 2016 at 7:52:32 PM UTC+12, Mark Summerfield wrote: > So, I need to have some hook that lets me run a python script after the build > dir has been populated but before the distributable is made -- is this > possible? You can subclass distutils.command.build with your own custom version that does whatever additional steps you require. Here is one example. From lawrencedo99 at gmail.com Fri Sep 9 17:03:20 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 14:03:20 -0700 (PDT) Subject: PEP 492: isn't the "await" redundant? In-Reply-To: References: <87h9a750kt.fsf@elektro.pacujo.net> <87d1kv4zck.fsf@elektro.pacujo.net> <57d2aab5$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, September 10, 2016 at 12:39:04 AM UTC+12, Chris Angelico wrote: > In contrast, you want to use threads if you need the ability to > quickly and easily share mutable data, or if you want all resource > usage to be lumped together - eg if you're not really doing several > separate jobs, but are doing one single conceptual job. Multiple processes are usually preferable to multiple threads. The default-shared-nothing memory model is less bug-prone than default-shared-everything. Think of every time you use ?&? and ?|? in a shell command line: you are creating multiple processes, and yet they are doing a ?single conceptual job?. From lawrencedo99 at gmail.com Fri Sep 9 20:50:24 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 17:50:24 -0700 (PDT) Subject: PEP suggestion: Uniform way to indicate Python language version In-Reply-To: References: <1b43eb5d-3b04-49c0-9db5-edacc997eeb3@googlegroups.com> <896b3fb4-1a38-70cb-13e8-b3570497196c@telenet.be> <01c0bb1f-89c2-4a16-86fb-25c704ee9b3c@googlegroups.com> <854m6dxyz7.fsf@benfinney.id.au> <9fe7efc8-6330-46ed-9cb7-d9f31ecf05df@googlegroups.com> <47e6dd46-7784-4a3e-b8fb-8fe70b08ef13@googlegroups.com> <87pop1dn68.fsf@elektro.pacujo.net> <1471870375.576317.702353561.2CC6D3A5@webmail.messagingengine.com> <57bafc5b$0$1603$c3e8da3$5496439d@news.astraweb.com> <1471876189.4028290.702457473.27383162@webmail.messagingengine.com> Message-ID: <60823629-6ca0-4b71-9d9f-5f0c0eea5efd@googlegroups.com> On Tuesday, August 23, 2016 at 2:30:10 AM UTC+12, Random832 wrote: > Receiving a SyntaxError or whatever other exception, which provides no > suggestion about how to actually fix the issue (install a later version > of python / run with "python3" instead of "python"), is a bad user > experience. When people say ?user experience?, that immediately brings to mind the kinds of long-winded messages that Microsoft Windows might put out, that nobody pays attention to, because in trying to be ?friendly? and ?approachable? they become effectively meaningless. At least the SyntaxError exception, with traceback, will give you some details about what went wrong. The ?user? having the ?experience? doesn?t need to understand the message to be able to copy and paste it into a bug report, and the developer(s) will then have some information to at least make a start on figuring out the problem. From steve+python at pearwood.info Fri Sep 9 21:33:11 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 10 Sep 2016 11:33:11 +1000 Subject: PEP suggestion: Uniform way to indicate Python language version References: <1b43eb5d-3b04-49c0-9db5-edacc997eeb3@googlegroups.com> <896b3fb4-1a38-70cb-13e8-b3570497196c@telenet.be> <01c0bb1f-89c2-4a16-86fb-25c704ee9b3c@googlegroups.com> <854m6dxyz7.fsf@benfinney.id.au> <9fe7efc8-6330-46ed-9cb7-d9f31ecf05df@googlegroups.com> <47e6dd46-7784-4a3e-b8fb-8fe70b08ef13@googlegroups.com> <87pop1dn68.fsf@elektro.pacujo.net> <1471870375.576317.702353561.2CC6D3A5@webmail.messagingengine.com> <57bafc5b$0$1603$c3e8da3$5496439d@news.astraweb.com> <1471876189.4028290.702457473.27383162@webmail.messagingengine.com> Message-ID: <57d362d8$0$1606$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Aug 2016 12:29 am, Random832 wrote: > Receiving a SyntaxError or whatever other exception, which provides no > suggestion about how to actually fix the issue (install a later version > of python / run with "python3" instead of "python"), is a bad user > experience. Er wot? If I run the following code in Python 3.4: x:int = spam.method(?) - 1 how is the 3.4 interpreter supposed to know when the x:int and the (?) syntax were introduced? I can tell you when x:int is introduced (Python 3.6) but I have no idea when (?) will be introduced, or what it will mean. > It will continue to be a bad user experience when people are > using features that only work on python 5.0 and later and other people > are trying to run their scripts under python 4.0, Suppose that version 4.5 introduces |: syntax and version 4.8 removes it again because it was a terrible idea. And 4.9 introduces unless expressions. I write this: x = spam |: eggs unless ValueError then cheese What syntax error should Python 4.0 give? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From dkoleary at olearycomputers.com Fri Sep 9 23:12:04 2016 From: dkoleary at olearycomputers.com (dkoleary at olearycomputers.com) Date: Fri, 9 Sep 2016 20:12:04 -0700 (PDT) Subject: python3 regex? Message-ID: Hey; Long term perl ahderent finally making the leap to python. From my reading, python, for the most part, uses perl regex.. except, I can't seem to make it work... I have a txt file from which I can grab specific titles via a perl one-liner: $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables 1. ${title1} 2. ${title2} "3. ${title3}",,, 4. one more title 5. nuther title 6. and so on...,, ... 25. last title I can't seem to get the same titles to appear using python: $ python -V Python 3.5.2 $ python Python 3.5.2 (default, Jul 5 2016, 12:43:10) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> import re >>> with open('tables','rt') as f: data = f.read() printing data results in the output I would expect.. Trying to compile a regex and display the results does not show the same results I get from perl. >>> regex = r'^("?)[1-9]*\.' >>> re.search(regex, data) >>> >>> p = re.compile(r'^("?)[1-9]*\.') >>> p re.compile('^("?)[1-9]*\\.') >>> p.findall(data) I've tried any number of options shown on the net all with the same result. Can someone point out what I'm messing up? Thanks Doug From lawrencedo99 at gmail.com Fri Sep 9 23:41:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 20:41:22 -0700 (PDT) Subject: python3 regex? In-Reply-To: References: Message-ID: <1d0ec669-1cc9-4b2c-b700-f7bd0e21e825@googlegroups.com> On Saturday, September 10, 2016 at 3:12:17 PM UTC+12, Doug OLeary wrote: > $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables Perl has this feature of being able to use alternate delimiter symbols for the pattern; Python does not. > >>> regex = r'^("?)[1-9]*\.' Try putting a backslash in front of the ?"?: regex = r'^(\"?)[1-9]*\.' From lawrencedo99 at gmail.com Fri Sep 9 23:43:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 20:43:18 -0700 (PDT) Subject: How to extend a tuple of tuples? In-Reply-To: References: <44e067ce-f499-4ca8-87bd-94b18dfc0572@googlegroups.com> Message-ID: On Saturday, September 10, 2016 at 12:21:48 AM UTC+12, Frank Millman wrote: > The short answer is that I am using it as a dictionary key. Another option is, if it takes several steps to construct the tuple, to build it incrementally as a list and then cast it to a tuple. From lawrencedo99 at gmail.com Sat Sep 10 00:20:58 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 9 Sep 2016 21:20:58 -0700 (PDT) Subject: how to set paramiko to use ssh version 1? In-Reply-To: <420297f3-f534-4be2-b42e-760f6f6c25d2@googlegroups.com> References: <420297f3-f534-4be2-b42e-760f6f6c25d2@googlegroups.com> Message-ID: On Thursday, September 1, 2016 at 3:26:26 PM UTC+12, meInvent bbird wrote: > how to set paramiko to use ssh version 1? Be polite, but firm. Tell it ?paramiko, this is ssh version 1, use it?. Then, when it responds ?but SSHv1 is an obsolete stinking pile of crap that nobody in their right mind should be using any more?, make it quite clear: ?I?m the human, you?re the machine, *you* are supposed to serve *me*, not point out how stupid I am?. Then pull the plug. That will shut it up. From miki.tebeka at gmail.com Sat Sep 10 00:22:09 2016 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 9 Sep 2016 21:22:09 -0700 (PDT) Subject: pymssql In-Reply-To: References: Message-ID: <20aed816-1867-424d-8084-61cd6d6f5cd2@googlegroups.com> > for row in cus: > print(row.budget_code) > > > NameError: name 'budget_code' is not defined You'll need to use a DictCursor to be able to access rows by name and not position (which IMO is the preferred way). cus = conn.cursor(pymysql.cursors.DictCursor) cus.execute("SELECT * FROM glbud ") for row in cus: print(row['budget_code']) From breamoreboy at gmail.com Sat Sep 10 00:40:09 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 9 Sep 2016 21:40:09 -0700 (PDT) Subject: python3 regex? In-Reply-To: References: Message-ID: <0502ca5d-f9ef-4d3c-9a29-fcc9106647ac@googlegroups.com> On Saturday, September 10, 2016 at 4:12:17 AM UTC+1, Doug OLeary wrote: > Hey; > > Long term perl ahderent finally making the leap to python. From my reading, python, for the most part, uses perl regex.. except, I can't seem to make it work... > > I have a txt file from which I can grab specific titles via a perl one-liner: > > $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables > 1. ${title1} > 2. ${title2} > "3. ${title3}",,, > 4. one more title > 5. nuther title > 6. and so on...,, > ... > 25. last title > > I can't seem to get the same titles to appear using python: > > > $ python -V > Python 3.5.2 > $ python > Python 3.5.2 (default, Jul 5 2016, 12:43:10) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> import re > >>> with open('tables','rt') as f: > data = f.read() > > printing data results in the output I would expect.. > > Trying to compile a regex and display the results does not show the same results I get from perl. > > >>> regex = r'^("?)[1-9]*\.' > >>> re.search(regex, data) > >>> > > >>> p = re.compile(r'^("?)[1-9]*\.') > >>> p > re.compile('^("?)[1-9]*\\.') > >>> p.findall(data) > > I've tried any number of options shown on the net all with the same result. Can someone point out what I'm messing up? > > Thanks > > Doug I'm no regex expert but would this third party module https://pypi.python.org/pypi/regex help? Kindest regards. Mark Lawrence. From auriocus at gmx.de Sat Sep 10 01:30:29 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 10 Sep 2016 07:30:29 +0200 Subject: python3 regex? In-Reply-To: References: Message-ID: Am 10.09.16 um 05:12 schrieb dkoleary at olearycomputers.com: > Hey; > > Long term perl ahderent finally making the leap to python. From my reading, python, for the most part, uses perl regex.. except, I can't seem to make it work... > > I have a txt file from which I can grab specific titles via a perl one-liner: > > $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables > 1. ${title1} > 2. ${title2} > "3. ${title3}",,, > 4. one more title > 5. nuther title > 6. and so on...,, > ... > 25. last title > > I can't seem to get the same titles to appear using python: > > > $ python -V > Python 3.5.2 > $ python > Python 3.5.2 (default, Jul 5 2016, 12:43:10) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> import re >>>> with open('tables','rt') as f: > data = f.read() > > printing data results in the output I would expect.. > > Trying to compile a regex and display the results does not show the same results I get from perl. > >>>> regex = r'^("?)[1-9]*\.' >>>> re.search(regex, data) >>>> > >>>> p = re.compile(r'^("?)[1-9]*\.') >>>> p > re.compile('^("?)[1-9]*\\.') >>>> p.findall(data) > > I've tried any number of options shown on the net all with the same result. > Can someone point out what I'm messing up? I think the difference is the anchor ^. In perl, you apply the regex to each line, whereas in Python you apply it to the whole file. You would either need to switch the re to multiline mode https://docs.python.org/2/library/re.html#re.MULTILINE or do it in a loop, the same way that perl does it implicitly: for line in f: print(re.findall(line).group(0)) (untested) Christian From cadencennn at gmail.com Sat Sep 10 02:15:07 2016 From: cadencennn at gmail.com (John) Date: Fri, 9 Sep 2016 23:15:07 -0700 (PDT) Subject: How do I automatically download files from a pop up dialog using selenium-python? Message-ID: <3c974f69-29df-4ff1-a640-3ee657f65509@googlegroups.com> Please help. Thanks. From jussi.piitulainen at helsinki.fi Sat Sep 10 02:18:53 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sat, 10 Sep 2016 09:18:53 +0300 Subject: python3 regex? References: Message-ID: dkoleary at olearycomputers.com writes: > Hey; > > Long term perl ahderent finally making the leap to python. From my > reading, python, for the most part, uses perl regex.. except, I can't > seem to make it work... > > I have a txt file from which I can grab specific titles via a perl > one-liner: > > $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables > 1. ${title1} > 2. ${title2} > "3. ${title3}",,, > 4. one more title > 5. nuther title > 6. and so on...,, > ... > 25. last title > > I can't seem to get the same titles to appear using python: > > > $ python -V > Python 3.5.2 > $ python > Python 3.5.2 (default, Jul 5 2016, 12:43:10) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> import re >>>> with open('tables','rt') as f: > data = f.read() > > printing data results in the output I would expect.. > > Trying to compile a regex and display the results does not show the > same results I get from perl. > >>>> regex = r'^("?)[1-9]*\.' >>>> re.search(regex, data) >>>> > >>>> p = re.compile(r'^("?)[1-9]*\.') >>>> p > re.compile('^("?)[1-9]*\\.') >>>> p.findall(data) > > I've tried any number of options shown on the net all with the same > result. Can someone point out what I'm messing up? You need to compile (or use) your regex in multiline mode for the anchor to match the beginnings of lines. But it's probably better to process each line separately, as you do in Perl, so skip this point. You have a capturing group in your regex, so findall returns what that group matched. Typically that is an empty string (no doublequote). But your capturing group seems unintended, so maybe skip this point. Without that group, findall would return what the whole pattern matched, which is still not the whole line. It's surely better to process each line separately, as you do in Perl. So skip this point, too. Then you don't even need the anchor. Instead, use re.match to match at the start of the string. (The newer re.fullmatch attempts to match the whole string.) import re p = re.compile('"?[1-9]*\.') with open('tables', 'rt') as f: for line in f: if p.match(line): print(line, end = '') Note that 'rt' is the default mode, and you won't catch line 10 with your regex. More importantly, note that you can iterate over the lines from f directly. There's also a method, f.readlines, to read the lines into a list, if you need them all at once, but that's not what you do in Perl either. From jussi.piitulainen at helsinki.fi Sat Sep 10 02:33:00 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sat, 10 Sep 2016 09:33:00 +0300 Subject: python3 regex? References: Message-ID: Jussi Piitulainen writes: > dkoleary at olearycomputers.com writes: >> [- -] > import re > p = re.compile('"?[1-9]*\.') That should be a raw string: r'"?[1-9]*\.' Sorry about that. I wish Python would complain. From steve+python at pearwood.info Sat Sep 10 02:45:38 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 10 Sep 2016 16:45:38 +1000 Subject: What you can do about legalese nonsense on email (was: How to split value where is comma ?) References: <20160907225444.0f99a5a2@imp> <85y432qfkz.fsf_-_@benfinney.id.au> Message-ID: <57d3ac14$0$1589$c3e8da3$5496439d@news.astraweb.com> On Fri, 9 Sep 2016 08:13 am, Grant Edwards wrote: > After all, that boilerplate just makes the corporation look stupid and > incompetent. I wish that were true. Unfortunately, in the corporate world, it *doesn't* make them look stupid and incompetent. It makes them look conventional, careful, diligent and responsible, and depending on how it is worded, perhaps even a little scary: "We say that we care about the confidentiality of what we do. Don't mess with us, because we have a lawyer and aren't afraid to use it!" To a certain type of mindset, failure to include that boilerplate would look stupid and incompetent. Even if it is a legal bluff, it may discourage some people from misusing the email or forwarding it on, a bit like the legal equivalent of fake security cameras that look like the real thing but don't actually work. And I doubt it is being driven by lawyers, who surely know how dubious this is. Its not lawyers who insist on adding restraint of trade and non-compete clauses that they know won't stand up in court, and I doubt it is lawyers insisting on this boiler plate. But then lawyers will also know that there's no (legal) harm done by including the message: within fairly broad limits, they can *say* anything they like. "If you are not the intended recipient, stop reading immediately and seek medical attention. If you read this email without approval, you will suffer a severe and irreversible brain embolism." And besides, I wouldn't be *entirely* sure that it is nothing but a bluff, particularly when wealthy corporations are involved. Privacy and confidentiality are intangibles where the result can depend on all sorts of factors, such as how deep the pockets of the plaintiff are, and whether the government of the day wants to defend or attack freedom of speech and/or privacy. Or even outright legal fraud, which is how we got corporations considered to be legal persons. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From dieter at handshake.de Sat Sep 10 04:28:04 2016 From: dieter at handshake.de (dieter) Date: Sat, 10 Sep 2016 10:28:04 +0200 Subject: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers? References: <87wpil3840.fsf@handshake.de> <87sht936me.fsf@handshake.de> Message-ID: <8760q45fcb.fsf@handshake.de> Chi Hsuan Yen writes: > ... > I found that OpenSSL provides an X509 callback hook that allows clients to > know why the verification process fails. For a long time, Python 2 (unlike Python 3) did not perform certificate validation at all. As a consequence, some developpers provided the functionality in external packages. Maybe, one of those exposes the callback you have found. I never used one of those packages and cannot provide more information that what I said above. You might also look at "PyOpenSSL" (--> "PyPI"). Apparently, it supports callbacks written in Python. Again, I have not myself used this package. From dieter at handshake.de Sat Sep 10 04:35:24 2016 From: dieter at handshake.de (dieter) Date: Sat, 10 Sep 2016 10:35:24 +0200 Subject: Mysterious Logging Handlers References: <247db0ab-efe7-484b-a418-dd219f68a8e5@googlegroups.com> Message-ID: <871t0s5f03.fsf@handshake.de> Josh English writes: > I have a Python script that imports a utility script. Both scripts use logging, but the logs don't work as advertised. I'm getting logging output from the utility script but none from the main file. Worse, the format of the utility script's logs don't match anything I define. > > The utility script is called xlreader.py. It has the following lines: > > -- begin snippet -- > import logging > XLOGGER = logging.getLogger('XLREADER') > -- end snippet -- > > And it calls XLOGGER.debug(), XLOGGER.error() and XLOGGER.info() but it never defines a handler. > ... Python's logging system is quite complex. Among others, it has a logger hierarchy where loggers on a lower level can delegate to their parent. Usually, most configuration happens at the so called "root logger" and is used by all loggers which have not overridden certains aspects. In your special case, the handlers likely come from the "root logger". From vek.m1234 at gmail.com Sat Sep 10 06:26:29 2016 From: vek.m1234 at gmail.com (Veek 'this_is_not_my_name' M) Date: Sat, 10 Sep 2016 15:56:29 +0530 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? References: Message-ID: Veek 'this_is_not_my_name' M wrote: > Rustom Mody wrote: > >> On Saturday, September 3, 2016 at 5:25:48 PM UTC+5:30, Veek. M wrote: >>> https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm >>> >>> Wanted to know if the above link idea, had been implemented and if >>> there's a module that accepts a pattern like 'cap' and give you all >>> the instances of unicode 'CAP' characters. >>> ? \bigcap >>> ? \sqcap >>> ? \cap >>> ? \capricornus >>> ? \succapprox >>> ? \precapprox >>> >>> (above's from tex) >>> >>> I found two useful modules in this regard: unicode_tex, unicodedata >>> but unicodedata is a builtin which does not do globs, regexs - so >>> it's kind of limiting in nature. >>> >>> Would be nice if you could search html/xml character entity >>> references as well. >> >> [Not exactly an answer] >> >> I use a number of things for such >> 1. Google >> 2. Xah Lee?s excellent pages which often fit my brain better than >> wikipedia: >> http://xahlee.info/comp/unicode_index.html >> 3. emacs? function ucs-insert recently renamed to insert-char >> ie [In emacs] Type Alt-x insert-char >> After that some kind of TAB-globbing (case-insensitive) works >> I wont try with Cap (because the number of *CAPITAL* is in >> thousands!) eg alphaTAB gives nothing. However *alphaTAB gives a >> bunch. Narrow to "greek alpha"TAB and you get a bunch >> >> >> The fact that we should have a series of levels for char-input from >> most general and unergonomic (google) to most specific and ergonomic >> (special purpose keyboard) Ive tried to talk of as 7 levels near end >> of http://blog.languager.org/2015/01/unicode-and-universe.html > > > got dengu - i'm dead sorry false alarm, but i was sick enough to be awol From mail at timgolden.me.uk Sat Sep 10 06:53:15 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 10 Sep 2016 11:53:15 +0100 Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: Message-ID: <0a9fa540-cbfd-c5bb-aafb-572a43b87439@timgolden.me.uk> On 10/09/2016 11:26, Veek 'this_is_not_my_name' M wrote: > Veek 'this_is_not_my_name' M wrote: /me claps TJG From rustompmody at gmail.com Sat Sep 10 07:24:29 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 10 Sep 2016 04:24:29 -0700 (PDT) Subject: Extend unicodedata with a name/pattern/regex search for character entity references? In-Reply-To: References: Message-ID: <21dd3a7e-11cf-4a9c-baec-630db7d2f947@googlegroups.com> On Saturday, September 10, 2016 at 3:56:37 PM UTC+5:30, Veek 'this_is_not_my_name' M wrote: > Veek 'this_is_not_my_name' M wrote: Recursion? Self-Reference?Inversion Heh! On the way to becoming another G?del/Turing?? You may be interested in this collection of some evidence(s) of recursion being one of the most central ideas in computer science see: http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html > > > Rustom Mody wrote: > > > >> On Saturday, September 3, 2016 at 5:25:48 PM UTC+5:30, Veek. M wrote: > >>> https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm > >>> > >>> Wanted to know if the above link idea, had been implemented and if > >>> there's a module that accepts a pattern like 'cap' and give you all > >>> the instances of unicode 'CAP' characters. > >>> ? \bigcap > >>> ? \sqcap > >>> ? \cap > >>> ? \capricornus > >>> ? \succapprox > >>> ? \precapprox > >>> > >>> (above's from tex) > >>> > >>> I found two useful modules in this regard: unicode_tex, unicodedata > >>> but unicodedata is a builtin which does not do globs, regexs - so > >>> it's kind of limiting in nature. > >>> > >>> Would be nice if you could search html/xml character entity > >>> references as well. > >> > >> [Not exactly an answer] > >> > >> I use a number of things for such > >> 1. Google > >> 2. Xah Lee?s excellent pages which often fit my brain better than > >> wikipedia: > >> http://xahlee.info/comp/unicode_index.html > >> 3. emacs? function ucs-insert recently renamed to insert-char > >> ie [In emacs] Type Alt-x insert-char > >> After that some kind of TAB-globbing (case-insensitive) works > >> I wont try with Cap (because the number of *CAPITAL* is in > >> thousands!) eg alphaTAB gives nothing. However *alphaTAB gives a > >> bunch. Narrow to "greek alpha"TAB and you get a bunch > >> > >> > >> The fact that we should have a series of levels for char-input from > >> most general and unergonomic (google) to most specific and ergonomic > >> (special purpose keyboard) Ive tried to talk of as 7 levels near end > >> of http://blog.languager.org/2015/01/unicode-and-universe.html > > > > > > got dengu - i'm dead > sorry false alarm, but i was sick enough to be awol Given that >>> "dengue" == "dengu" False you should be fine ;-) From rosuav at gmail.com Sat Sep 10 09:00:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 10 Sep 2016 23:00:27 +1000 Subject: [Python-ideas] Inconsistencies (was: Shuffled) In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: Redirecting to python-list as I don't believe this belongs on -ideas. On Sat, Sep 10, 2016 at 10:09 PM, Sven R. Kunze wrote: >> On 08.09.2016 04:00, Steven D'Aprano wrote: >> >> On Wed, Sep 07, 2016 at 11:43:59PM +0200, Sven R. Kunze wrote: >> >>> BUT experienced devs also need to recognize and respect the fact that >>> younger/unexperienced developers are just better in detecting >>> inconsistencies and bloody work-arounds. >> >> That is not a fact. It is the opposite of a fact >> > > You might have heard of: "There are no such things as facts, just opinions. > Everything, we see is a perspective not the truth." See below, why this > applies here as well. Yes, I've heard that. It is false. Some things are absolute hard facts. There is no way in which 1 will ever be greater than 2, ergo "1 is less than 2" is strictly true, and not a matter of opinion. If you hear someone trying to claim otherwise, would you let him have his opinion, or would you treat it as incorrect? >> -- inexperienced >> developers are WORSE at spotting inconsistencies, because they don't >> recognise deep consistencies. > > > Your example (default arguments) might make sense when going one or two > level deeper. However: > > > Is going deep really necessary at all? > > > People program for different reasons, to have fun, to create value for > others, to educate, or for reasons we both cannot even think of. Why should > they leave their level? Because of you or me? Because they need to know what > Turing-completeness means? What calling conventions are? I don't think so. > They wanna solve problems and get things done whether or not they know every > single bit of the language they use. If they decide to go deeper, that's > wonderful, but if they don't, don't force them. > > So, an inconsistency at level 1 might be a **result of a consistency at > level 0** BUT it nevertheless is and stays an inconsistency at level 1 no > matter how sophisticated the consistency at level 0 is. > > > And please note, some even want to go on level up, so inconsistencies at > level 1 just plain suck then. People then simply don't care about how the > current flows at cpu level or about your carefully handcrafted bits and > pieces on level 0 which you are so proud of and which are so consistent > there. There is some merit in this. For instance, Python 2 had a lower-level consistency in the division operator than Python 3 has. According to Py2, integers and floats are fundamentally different beasts, and when you divide an int by an int, you get an int, not a float. Py3 says "well, you probably REALLY meant to divide a number by a number", so it gives you a float back, unless you explicitly ask for floor division. Py2 is more consistent on a lower level of abstraction. Py3 is more consistent on a higher level of abstraction (modulo the oddities at extremely large numbers). Both have merit, but in a high level language, the Py3 way is usually [1] better. But the consistency of call-by-object-reference is at the same high level as the consistency of call-by-value or call-by-name. I can explain Python's assignment model to someone fairly easily, using pencil and paper, without any reference to "low level" or "high level" concepts. And Python is extremely internally consistent; *every* assignment behaves the exact same way. How does "import x" compare with "from x import y"? Easy: the former is "x = some_module_object", and the latter is "y = some_module_object.y", and either way, it's regular assignment. How does parameter passing work? You take the value of the argument as evaluated in the caller, and assign it to the parameter in the function. What about default arguments? They're evaluated when the function's defined, and assigned to the parameter when it's called. Function definition itself is the same thing - it's assigning a function object to a name. Python handles every one of them the same way. I don't care one iota about how voltages inside a CPU operate. I don't generally even care about machine code - let other people worry about that, people more expert than I am. Discussions about how the core dev and the novice see Python's consistencies are nothing to do with those levels. To go back to your original point, that a newbie is better at recognizing inconsistencies... maybe, in a sense, but they also get a lot of false positives. Ultimately, "consistent" means that there's a single pattern that explains everything; if you're unaware of that pattern, you won't know that it's consistent. ChrisA [1] Even in Python, there are places where low-level consistency is better, because Python is a glue language. But in general, it's better for Python to be consistent with humans than with C APIs. From dkoleary at olearycomputers.com Sat Sep 10 10:23:59 2016 From: dkoleary at olearycomputers.com (Doug OLeary) Date: Sat, 10 Sep 2016 07:23:59 -0700 (PDT) Subject: python3 regex? In-Reply-To: References: Message-ID: <6713ab0a-f309-460a-9307-6bb4f54bd87c@googlegroups.com> Hey, all; thanks for the replies - reading data in one slurp vs line by line was the issue. In my perl programs, when reading files, I generally do it all in one swell foop and will probably end up doing so again in this case due to the layout of the text; but, that's my issue. Thanks again. I appreciate the tip. Doug O'Leary From steve+python at pearwood.info Sat Sep 10 11:04:05 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 11 Sep 2016 01:04:05 +1000 Subject: Python source repo Message-ID: <57d420e6$0$1598$c3e8da3$5496439d@news.astraweb.com> I ran hg fetch to update the CPython repo. It has been stuck on "adding changesets" for half an hour. I don't know if that's because the process has locked up, or because there really are that many new changesets and it will simply take a long time to process them. (With the 3.6 beta just around the corner, there have been a LOT of changesets.) Is there some way to tell if hg is still processing or if it is locked up? I don't want to kill the process and have to go through the whole thing again if I don't have to. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 10 11:27:07 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 11 Sep 2016 01:27:07 +1000 Subject: Python source repo References: <57d420e6$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57d4264d$0$1611$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Sep 2016 01:04 am, Steve D'Aprano wrote: > I ran hg fetch to update the CPython repo. > > It has been stuck on "adding changesets" for half an hour. I don't know if > that's because the process has locked up, or because there really are that > many new changesets and it will simply take a long time to process them. Never mind. I got bored and frustrated and Ctrl-C'ed the process and ran it again. This time it took about 15 seconds to complete. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 10 11:53:08 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 11 Sep 2016 01:53:08 +1000 Subject: collect2: ld returned 1 exit status when building from source Message-ID: <57d42c66$0$1586$c3e8da3$5496439d@news.astraweb.com> I'm trying to build from source using: ./configure --with-pydebug && make -s -j2 At first the output is okay, then I get a whole heap of similar errors: Python/dtrace_stubs.o: In function `PyDTrace_LINE': /home/steve/python/python-dev/cpython/Include/pydtrace.h:25: multiple definition of `PyDTrace_LINE' Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:25: first defined here Python/dtrace_stubs.o: In function `PyDTrace_FUNCTION_ENTRY': /home/steve/python/python-dev/cpython/Include/pydtrace.h:26: multiple definition of `PyDTrace_FUNCTION_ENTRY' Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:26: first defined here [ ... many, many, many more PyDTrace_* multiple definitions ... ] collect2: ld returned 1 exit status make: *** [Programs/_freeze_importlib] Error 1 Any suggestions for fixing this? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Sat Sep 10 13:11:23 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 10 Sep 2016 10:11:23 -0700 (PDT) Subject: [Python-ideas] Inconsistencies (was: Shuffled) In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: On Saturday, September 10, 2016 at 6:30:47 PM UTC+5:30, Chris Angelico wrote: > Redirecting to python-list as I don't believe this belongs on -ideas. > > On Sat, Sep 10, 2016 at 10:09 PM, Sven R. Kunze wrote: > >> On 08.09.2016 04:00, Steven D'Aprano wrote: > >> > >> On Wed, Sep 07, 2016 at 11:43:59PM +0200, Sven R. Kunze wrote: > >> > >>> BUT experienced devs also need to recognize and respect the fact that > >>> younger/unexperienced developers are just better in detecting > >>> inconsistencies and bloody work-arounds. > >> > >> That is not a fact. It is the opposite of a fact > >> > > > > You might have heard of: "There are no such things as facts, just opinions. > > Everything, we see is a perspective not the truth." See below, why this > > applies here as well. > > Yes, I've heard that. It is false. > > Some things are absolute hard facts. There is no way in which 1 will > ever be greater than 2, ergo "1 is less than 2" is strictly true, and > not a matter of opinion. If you hear someone trying to claim > otherwise, would you let him have his opinion, or would you treat it > as incorrect? You are confusing analytic and synthetic truths, an old philosophic distinction with a new special place in CS http://blog.languager.org/2015/07/cs-history-2.html Analytic truths have a tautologous feel that makes them sound strangely irrelevant (as an observation) eg. ?What is is? ?Something is the case or is not the case? More informally: ?Time is irreversible? ?We all die? etc All true but nothing is communicated by saying it Mathematical truths like 1 < 2 are in the same category as ?triangles are 3-sided figures? same as ?triangles are triangular? True... and tautologus When people commonly talk of ?facts? they are typically synthetic Acceleration due to gravity is 9.8 m/s? Planets move in elliptic orbits round the sun All these *scientific* truths as Karl Popper pointed out are scientific exactly BECAUSE they are falsifiable. Unlike say: ?God created the world? And to say that they are falsifiable is exactly what Sven is saying: They are the dominant opinion of the scientific establishment And will change when the fashions change As for shuffle vs shuffled I am very much in the shuffled camp. It irks me that - sort and sorted are named backwards ? should have been dosort and sort - tuples are less 1st class than lists (why no tuple comprehensions?) - what you get from writing a comprehension inside a {} is a set not a frozenset - set and frozenset are named backwards; should have been mutableset and set - there are no frozendicts (though dict comprehensions are niftier in python than in most functional languages - etc etc Which I guess you can summarize as (me saying that) functional programming is natural and imperative programming is a stone-age relic. [And BTW in the other thread in which the closeness or not of asyncio, threads, processes is being debated it is so clear to those who have seen radically different paradigms like Erlang that the problem is not the specifics of async/threads/processes but the general situation that python is stuck in imperative-land ] From zachary.ware+pylist at gmail.com Sat Sep 10 13:34:52 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Sat, 10 Sep 2016 12:34:52 -0500 Subject: collect2: ld returned 1 exit status when building from source In-Reply-To: <57d42c66$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <57d42c66$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 10, 2016 09:56, "Steve D'Aprano" wrote: > > I'm trying to build from source using: > > ./configure --with-pydebug && make -s -j2 > > > At first the output is okay, then I get a whole heap of similar errors: > > Python/dtrace_stubs.o: In function `PyDTrace_LINE': > /home/steve/python/python-dev/cpython/Include/pydtrace.h:25: multiple > definition of `PyDTrace_LINE' > Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:25: > first defined here > Python/dtrace_stubs.o: In function `PyDTrace_FUNCTION_ENTRY': > /home/steve/python/python-dev/cpython/Include/pydtrace.h:26: multiple > definition of `PyDTrace_FUNCTION_ENTRY' > Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:26: > first defined here > > [ ... many, many, many more PyDTrace_* multiple definitions ... ] > > collect2: ld returned 1 exit status > make: *** [Programs/_freeze_importlib] Error 1 > > > Any suggestions for fixing this? Try make distclean, then configure and build again. If that fails, try another make distclean, then configure, do 'make touch', then build again. -- Zach (On a phone) From steve+python at pearwood.info Sat Sep 10 19:58:51 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 11 Sep 2016 09:58:51 +1000 Subject: collect2: ld returned 1 exit status when building from source References: <57d42c66$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57d49e3d$0$1585$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Sep 2016 03:34 am, Zachary Ware wrote: > On Sep 10, 2016 09:56, "Steve D'Aprano" > wrote: >> >> I'm trying to build from source using: >> >> ./configure --with-pydebug && make -s -j2 [...] >> Any suggestions for fixing this? > > Try make distclean, then configure and build again. Same error. > If that fails, try > another make distclean, then configure, do 'make touch', then build again. make touch fails. [steve at ando cpython]$ make touch cd .; \ hg --config extensions.touch=Tools/hg/hgtouch.py touch -v *** failed to import extension touch from Tools/hg/hgtouch.py: invalid syntax (hgtouch.py, line 22) hg: unknown command 'touch' Mercurial Distributed SCM basic commands: add add the specified files on the next commit [...] view start interactive history viewer use "hg help" for the full list of commands or "hg -v" for details make: *** [touch] Error 255 And *that* error is because the hgtouch.py uses `with`, which fails because my hg runs under Python 2.4. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 10 20:08:52 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 11 Sep 2016 10:08:52 +1000 Subject: collect2: ld returned 1 exit status when building from source References: <57d42c66$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57d4a097$0$1584$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Sep 2016 03:34 am, Zachary Ware wrote: > Try make distclean, then configure and build again. If that fails, try > another make distclean, then configure, do 'make touch', then build again. I worked around the failed hg touch by running it manually: python2.7 /usr/bin/hg --config extensions.touch=Tools/hg/hgtouch.py touch -v which printed a few warnings and then (apparently) succeeded: /usr/lib/python2.4/site-packages/mercurial/demandimport.py:58: RuntimeWarning: Python C API version mismatch for module osutil: This Python has API version 1013, module osutil has version 1012. mod = _origimport(head, globals, locals) /usr/lib/python2.4/site-packages/mercurial/demandimport.py:58: RuntimeWarning: Python C API version mismatch for module parsers: This Python has API version 1013, module parsers has version 1012. mod = _origimport(head, globals, locals) Touching Python/Python-ast.c but the build still fails, with the same errors: Python/dtrace_stubs.o: In function `PyDTrace_LINE': /home/steve/python/python-dev/cpython/Include/pydtrace.h:25: multiple definition of `PyDTrace_LINE' Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:25: first defined here [ ... many, many, many more similar errors ... ] collect2: ld returned 1 exit status make: *** [Programs/_freeze_importlib] Error 1 -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From flebber.crue at gmail.com Sat Sep 10 20:46:06 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 10 Sep 2016 17:46:06 -0700 (PDT) Subject: generator function - Called and accepts XML attributes- Python 3.5 Message-ID: Hi I want to create a generator function that supplies my calling function a file, how though do I get the generator to accept attributes in the argument when called? This works not as a generator for filename in sorted(file_list): with open(dir_path + filename) as fd: doc = xmltodict.parse(fd.read()) for item in doc['meeting']['race']: for detail in item['nomination']: print(item['@id'] + "\t" + detail['@id'] + "\t" + detail['@number'] + "\t" + detail['@horse']) And what I want to do is simplify for detail in item['nomination']: print(item['@id'] + "\t" + detail['@id'] + "\t" + detail['@number'] + "\t" + detail['@horse']) As I will have several implementations to do and would like to be able to neatly handoff to sqlalchemy. I have it as something like this but am not quite creating it correctly. def return_files(file_list): """ Take a list of files and return file when called Calling function to supply attributes """ for filename in sorted(file_list, *attribs): with open(dir_path + filename) as fd: doc = xmltodict.parse(fd.read()) for item in doc([attribs]): yield item Thanks Sayth From rosuav at gmail.com Sat Sep 10 20:58:09 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Sep 2016 10:58:09 +1000 Subject: generator function - Called and accepts XML attributes- Python 3.5 In-Reply-To: References: Message-ID: On Sun, Sep 11, 2016 at 10:46 AM, Sayth Renshaw wrote: > Hi > > I want to create a generator function that supplies my calling function a file, how though do I get the generator to accept attributes in the argument when called? > > This works not as a generator The way I'm reading your code, it's not the generator that's the difference here. Consider these lines: > for item in doc['meeting']['race']: > > def return_files(file_list): > for filename in sorted(file_list, *attribs): > for item in doc([attribs]): Firstly, did you mean for *attribs to be part of the signature of return_files? As it is, it's being given to sorted(), which won't work (the other args to sorted are keyword-only). Assuming that to be the case, what you're trying to do is subscript an object with a variable set of attributes: return_files(files, "meeting", "race') That can best be done with a little loop: def return_files(file_list, *attribs): ... for attr in attribs: doc = doc[attr] for item in doc: If that's not what you want, can you further clarify the question? ChrisA From flebber.crue at gmail.com Sat Sep 10 22:02:04 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 10 Sep 2016 19:02:04 -0700 (PDT) Subject: generator function - Called and accepts XML attributes- Python 3.5 In-Reply-To: References: Message-ID: <5b963f01-f0c8-426b-b09c-20177755b2d3@googlegroups.com> > The way I'm reading your code, it's not the generator that's the > difference here. Consider these lines: > > > for item in doc['meeting']['race']: > > > > def return_files(file_list): > > for filename in sorted(file_list, *attribs): > > for item in doc([attribs]): > > Firstly, did you mean for *attribs to be part of the signature of > return_files? As it is, it's being given to sorted(), which won't work > (the other args to sorted are keyword-only). > > Assuming that to be the case, what you're trying to do is subscript an > object with a variable set of attributes: > > return_files(files, "meeting", "race') > > That can best be done with a little loop: > > def return_files(file_list, *attribs): > ... > for attr in attribs: > doc = doc[attr] > for item in doc: > > If that's not what you want, can you further clarify the question? > > ChrisA Thanks ChrisA, what I am wanting to do is to create a generator for my file input to only pull the file when the last has processed. Then have my separate functions to process the files as required as each will have different attribute combinations and processing. My thinking is that having been reading SQLAlchemy I will be creating the models to represent the tables and the relationships. Therefore if I had 3 tables for name and people attributes, another for location(meeting) details and a central table for event details, then if the generator pulls a file I can parse it with each function. Each function would update the model and then call back to the generator for another file. My concern is that as some process in each table will be longish it is better to keep that separate and just call them from a main function. Maybe the generator should just stop at parsing the file at the root XML level so that each calling function can then hook up from its node. Is that clear or a massive brain dump? Sayth From flebber.crue at gmail.com Sat Sep 10 23:23:09 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 10 Sep 2016 20:23:09 -0700 (PDT) Subject: generator function - Called and accepts XML attributes- Python 3.5 In-Reply-To: References: Message-ID: This seems to work as a starter. def return_files(file_list): """ Take a list of files and return file when called Calling function to supply attributes """ for filename in sorted(file_list): with open(dir_path + filename) as fd: doc = xmltodict.parse(fd.read()) for item in doc['meeting']['race']: yield item my_generator = return_files(file_list) def gets_id(): for value in my_generator: for asset in value['nomination']: print(asset['@id']) gets_id() Cheers Sayth From rustompmody at gmail.com Sun Sep 11 00:27:36 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 10 Sep 2016 21:27:36 -0700 (PDT) Subject: [Python-ideas] Inconsistencies (was: Shuffled) In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: <71d0e206-c0dd-4119-9182-e7957dddae2d@googlegroups.com> On Saturday, September 10, 2016 at 6:30:47 PM UTC+5:30, Chris Angelico wrote: > Redirecting to python-list as I don't believe this belongs on -ideas. > > On Sat, Sep 10, 2016 at 10:09 PM, Sven R. Kunze wrote: > > You might have heard of: "There are no such things as facts, just opinions. > > Everything, we see is a perspective not the truth." See below, why this > > applies here as well. > > Yes, I've heard that. It is false. > > Some things are absolute hard facts. There is no way in which 1 will > ever be greater than 2, ergo "1 is less than 2" is strictly true, and > not a matter of opinion. If you hear someone trying to claim > otherwise, would you let him have his opinion, or would you treat it > as incorrect? Just saw this [No its not exactly consistent with my earlier view!] ?How much is 2 and 2?? Everyone gave the answer except the accountant. When everyone left, he dimmed the light and whispered in my ear ?How much do you want?? From rosuav at gmail.com Sun Sep 11 00:38:51 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Sep 2016 14:38:51 +1000 Subject: [Python-ideas] Inconsistencies (was: Shuffled) In-Reply-To: <71d0e206-c0dd-4119-9182-e7957dddae2d@googlegroups.com> References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <71d0e206-c0dd-4119-9182-e7957dddae2d@googlegroups.com> Message-ID: On Sun, Sep 11, 2016 at 2:27 PM, Rustom Mody wrote: > On Saturday, September 10, 2016 at 6:30:47 PM UTC+5:30, Chris Angelico wrote: >> Redirecting to python-list as I don't believe this belongs on -ideas. >> >> On Sat, Sep 10, 2016 at 10:09 PM, Sven R. Kunze wrote: >> > You might have heard of: "There are no such things as facts, just opinions. >> > Everything, we see is a perspective not the truth." See below, why this >> > applies here as well. >> >> Yes, I've heard that. It is false. >> >> Some things are absolute hard facts. There is no way in which 1 will >> ever be greater than 2, ergo "1 is less than 2" is strictly true, and >> not a matter of opinion. If you hear someone trying to claim >> otherwise, would you let him have his opinion, or would you treat it >> as incorrect? > > Just saw this [No its not exactly consistent with my earlier view!] > > ?How much is 2 and 2?? > Everyone gave the answer except the accountant. > When everyone left, he dimmed the light and whispered in my ear ?How much do you want?? And we laugh, because the accountant is offering to flat-out lie. We know full well that he's not telling the truth. ChrisA From lawrencedo99 at gmail.com Sun Sep 11 00:45:52 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 10 Sep 2016 21:45:52 -0700 (PDT) Subject: [Python-ideas] Inconsistencies (was: Shuffled) In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: <74b84358-9312-48cc-97f2-be59a5f0306f@googlegroups.com> On Sunday, September 11, 2016 at 1:00:47 AM UTC+12, Chris Angelico wrote: > > On Sat, Sep 10, 2016 at 10:09 PM, Sven R. Kunze wrote: >> You might have heard of: "There are no such things as facts, just opinions. > > Yes, I've heard that. It is false. It?s very easy to see why: start by asking whether the statement is a fact or an opinion. The conclusion follows logically from that. From anddam+NOSPAM at brapi.net Sun Sep 11 04:25:56 2016 From: anddam+NOSPAM at brapi.net (Andrea D'Amore) Date: Sun, 11 Sep 2016 10:25:56 +0200 Subject: Python source repo References: <57d420e6$0$1598$c3e8da3$5496439d@news.astraweb.com> <57d4264d$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-09-10 15:27:07 +0000, Steve D'Aprano said: > Never mind. I got bored and frustrated and Ctrl-C'ed the process and ran it > again. This time it took about 15 seconds to complete. Out of curiosity I checked for python debugger with "attach" feature (aking to gdb/lldb) and I found a few but I figure one has to know some hg internal in order to inspect where it hung up. Btw I experienced similar, sporadic issues with hg in past, I had the impression those were network-related, not reproducible on my side anyway. -- Andrea From gandalf at shopzeus.com Sun Sep 11 05:46:16 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sun, 11 Sep 2016 11:46:16 +0200 Subject: Override property setter of base class in Python 3 Message-ID: Example code: class A: def __init__(self, prop=0): self.__prop = prop @property def prop(self): return self.__prop @prop.setter def prop(self, value): self.__prop = value class B(A): @A.prop.setter def prop(self, value): print("Setting new value",value) super().prop = value b = B(0) b.prop=10 Result: Setting new value 10 Traceback (most recent call last): File "test.py", line 22, in b.prop=10 File "test.py", line 18, in prop super().prop = value AttributeError: 'super' object has no attribute 'prop' This seems to be working: class B(A): @A.prop.setter # MAGIC HERE! def prop(self, value): print("Setting new value",value) A.prop.fset(self, value) # MAGIC HERE! How can I remove the magic? E.g. referencing the base class name directly, and using some internal name "fset"? Also, consider this: class A: def __init__(self, prop=0): self.__prop = prop @property def prop(self): return self.__prop @prop.setter def prop(self, value): self.__prop = value class B(A): @A.prop.setter def prop(self, value): print("Setting new value in B:",value) A.prop.fset(self, value) # How use the MRO here? class C(A): @A.prop.setter def prop(self, value): print("Setting new value in C:",value) A.prop.fset(self, value) # How use the MRO here? class D(B,C): pass d = D(0) d.prop=10 Result: Setting new value in B: 10 What if I want to use the "property setter of the superclass"? E.g. the one that is the next in the MRO? Thanks, Laszlo From gandalf at shopzeus.com Sun Sep 11 06:02:49 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sun, 11 Sep 2016 12:02:49 +0200 Subject: Override property setter of base class in Python 3 In-Reply-To: References: Message-ID: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> By the way, I know that I can use a "property virtualizer", something like this: import inspect class A: def __init__(self, prop=0): self.__prop = prop def _prop_get(self): return self.__prop def _prop_set(self, value): self.prop_set(value) def prop_set(self, value): print("Setting prop value in A to", value) self.__prop = value prop = property(_prop_get, _prop_set) class B(A): def prop_set(self, value): print("Setting prop value in B to", value) super().prop_set(value) class C(A): def prop_set(self, value): print("Setting prop value in C to", value) super().prop_set(value) class D(B,C): pass d = D(0) d.prop=10 But this solution almost defeats the purpose of properties. E.g. a property should look like an attribute, and its behaviour should be manipulated through its name (and not another special method that must be exposed to subclasses.) From rosuav at gmail.com Sun Sep 11 06:12:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Sep 2016 20:12:27 +1000 Subject: Override property setter of base class in Python 3 In-Reply-To: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> Message-ID: On Sun, Sep 11, 2016 at 8:02 PM, Nagy L?szl? Zsolt wrote: > But this solution almost defeats the purpose of properties. E.g. a > property should look like an attribute, and its behaviour should be > manipulated through its name (and not another special method that must > be exposed to subclasses.) Even the problem seems to rather defeat the purpose of a property. A property should be very simple - why do you need to override it and call super()? Doesn't this rather imply that you've gone beyond the normal use of properties *already*? Subclassing and overriding are part of the interface of a class, albeit an interface that only a subset of other classes will use. Think carefully about why, if this is meant to be made available, it isn't simply a method call. ChrisA From gandalf at shopzeus.com Sun Sep 11 07:17:49 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sun, 11 Sep 2016 13:17:49 +0200 Subject: Override property setter of base class in Python 3 In-Reply-To: References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> Message-ID: <0782217b-1e8f-dfab-bba0-846f1abafd24@shopzeus.com> > Even the problem seems to rather defeat the purpose of a property. A > property should be very simple - why do you need to override it and > call super()? Doesn't this rather imply that you've gone beyond the > normal use of properties *already*? I'm not sure about that. I'm going to send a USE CASE in a separate message. > > Subclassing and overriding are part of the interface of a class, > albeit an interface that only a subset of other classes will use. > Think carefully about why, if this is meant to be made available, it > isn't simply a method call. Properties are also part of the class interface. I don't see any good reason why property get and set methods should not be overridden in subclasses. Provisional syntax: class A: def __init__(self, prop=0): self.__prop = prop @property def prop(self): return self.__prop @prop.setter def prop(self, value): self.__prop = value class B(A): @super.prop.getter def prop(self): print("Getting value",super().prop) return super().prop @super.prop.setter def prop(self, value): print("Setting new value",value) super().prop = value The only problem is that we cannot access "the property setter implementation of the superclass" easily. There is already a standard working way to overcome this: property virtualizer methods. (See my second email.) That pattern *allows attribute like access and polimorphism at the same time*, but at the cost of making the class interface more difficult and harder to understand. I only asked for a way to remove the seemingly neccessary bolierplate code ("syntax noise") and make it cleaner. Laszlo From gandalf at shopzeus.com Sun Sep 11 07:31:38 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sun, 11 Sep 2016 13:31:38 +0200 Subject: Override property setter of base class in Python 3 - USE CASE In-Reply-To: References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> Message-ID: <6f14f777-8769-ea64-78b2-8bc094df4ea5@shopzeus.com> > Even the problem seems to rather defeat the purpose of a property. A > property should be very simple - why do you need to override it and > call super()? Doesn't this rather imply that you've gone beyond the > normal use of properties *already*? Here are some of my classes that can represent data: "FormField" - a field of a form that have some properties (name, label, description, required or not, value etc.) They are available as properties e.g. formfield.value, formfield.required etc. "Form" - a collection of FormFields that can be used to validate the form as a whole. Some data structures are represented in FormField and Form instances. They are *often* represented to the user on a user interface. But *sometimes* they are used in other ways. The user interface is built on top of a "Widget" class, that knows how to build ui elements for the user (in this case: in a web browser). It can send/receive messages to/from the browser. Widget objects also have basic properties (for example: color, size, parent widget etc.) Whenever a property is changed on a widget object, the change is accounted for, goes through some buffering and sent to the browser. When I do "widget.visible = False" then it will (eventually) send a message to the browser and execute javascript code something like this: jQuery("#some_widget_id").hide() When a FormField needs a visual representation, then I create subclasses that inherit from both Widget and FormField. For example, a "TextField" class. Some properties that are defined in FormField must also be represented visually. The synchronization between property values and visual elements is done with messages/events. For example, when I do textfield.value = "some value" then the property value is updated internally in the FormField, but it also creates a message that will be sent to the browser and update the value attribute of the element. As a result, the user will also see that the value has been changed. On the other hand, when the user changes the value in the field, a message is pushed from the browser to the TextField object, and that will also change the value of the corresponding textfield.value property. The "value of a form field" must have a unified interface. So when I do " textfield.value = some_value " then I expect that the changed value will be represented on the UI *if it has an UI representation*. The widget needs to be able to intercept property value changes. One solution would be to make FormField an observable object, define separate events for these property changes (e.g. EVT_VALUE_CHANGED), and let TextField listen to these events. But this is even more difficult than using simple methods and overriding them. We know that there will only be a single chain of observers. Using an observable pattern that can have many observers for a single event seems to be an overkill. Using overriden setter methods instead of properties is still better than using the observable/observer pattern. Much more simple and easier to understand. Does this go beyond the normal use of properties? You decide. I'm open to suggestions. What other pattern can I use for this problem? Here are the possibilities I see: * Use property virtualizers - too much syntax noise, but at least boilerplate code is contained within the class and it works as expected (this is what I use now) * Use getter/setter methods instead of properties - non-pythonic * Use the observable pattern, emit events for property changes and make others listen for it - too general and too difficult for this problem, harder to understand * Propose a new syntax that allows proper overriding of property getter/setter methods without too much syntax noise Laszlo From rosuav at gmail.com Sun Sep 11 08:03:08 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Sep 2016 22:03:08 +1000 Subject: Override property setter of base class in Python 3 In-Reply-To: <0782217b-1e8f-dfab-bba0-846f1abafd24@shopzeus.com> References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> <0782217b-1e8f-dfab-bba0-846f1abafd24@shopzeus.com> Message-ID: On Sun, Sep 11, 2016 at 9:17 PM, Nagy L?szl? Zsolt wrote: >> Subclassing and overriding are part of the interface of a class, >> albeit an interface that only a subset of other classes will use. >> Think carefully about why, if this is meant to be made available, it >> isn't simply a method call. > > Properties are also part of the class interface. I don't see any good > reason why property get and set methods should not be overridden in > subclasses. Right, I'm not saying they aren't; I'm just saying that properties are intended for simpler purposes than you'll normally need subclassing for. I'll wait for your follow-up email with a use case. ChrisA From rosuav at gmail.com Sun Sep 11 08:05:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Sep 2016 22:05:46 +1000 Subject: Override property setter of base class in Python 3 - USE CASE In-Reply-To: <6f14f777-8769-ea64-78b2-8bc094df4ea5@shopzeus.com> References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> <6f14f777-8769-ea64-78b2-8bc094df4ea5@shopzeus.com> Message-ID: On Sun, Sep 11, 2016 at 9:31 PM, Nagy L?szl? Zsolt wrote: > The "value of a form field" must have a unified interface. So when I do > " textfield.value = some_value " then I expect that the changed value > will be represented on the UI *if it has an UI representation*. The > widget needs to be able to intercept property value changes. > > Does this go beyond the normal use of properties? You decide. I'm open > to suggestions. What other pattern can I use for this problem? Yes, I believe it does. (Others may disagree. This is a design question and very much a matter of style, not hard fact.) I would have an explicit action "set_content" which will set the value of an input field, the inner text of a textarea, the checked state of a check box, etc. ChrisA From rosuav at gmail.com Sun Sep 11 08:12:08 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Sep 2016 22:12:08 +1000 Subject: How to split value where is comma ? In-Reply-To: References: <20160907225444.0f99a5a2@imp> <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> Message-ID: On Thu, Sep 8, 2016 at 7:27 PM, Joaquin Alzola wrote: >>I have worked places where they put stuff like this at the bottom of emails sent to the person sitting next to them :) -raising entropy-ly yrs- Robin Becker > > Cannot do anything about it. It is not on my MTA client and it is added by the company server :( > > If it depended on my I will remove it but I can not do that. Haven't you been reading what we've been saying? COMPLAIN. Go to whoever you can in the company and muster up support for the removal. Tell your bosses how stupid it makes the company look. Or just use a different mail server. ChrisA From anddam+NOSPAM at brapi.net Sun Sep 11 08:32:17 2016 From: anddam+NOSPAM at brapi.net (Andrea D'Amore) Date: Sun, 11 Sep 2016 14:32:17 +0200 Subject: How to split value where is comma ? References: Message-ID: On 2016-09-08 09:27:20 +0000, Joaquin Alzola said: > Cannot do anything about it. It is not on my MTA client and it is added > by the company server :( > > If it depended on my I will remove it but I can not do that. > This email is confidential and may be subject to privilege. If you are > not the intended recipient, please do not copy or disclose its content > but contact the sender immediately upon receipt. At least use a signature (conventionally marked by double dash, space, newline) so the part that's automatically added by the mail system is clearly separated from the body of your message. -- Andrea From gandalf at shopzeus.com Sun Sep 11 09:21:51 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sun, 11 Sep 2016 15:21:51 +0200 Subject: Override property setter of base class in Python 3 - USE CASE In-Reply-To: References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> <6f14f777-8769-ea64-78b2-8bc094df4ea5@shopzeus.com> Message-ID: <8e35bc81-4ed9-ddb7-83fa-377d448fa6df@shopzeus.com> > Yes, I believe it does. (Others may disagree. This is a design > question and very much a matter of style, not hard fact.) I would have > an explicit action "set_content" which will set the value of an input > field, the inner text of a textarea, the checked state of a check box, > etc. In other words, you would use simple getter and setter methods instead of properties. It is the simplest solution. (And I believe, it is non-pythonic, but that is just an opinion.) I would like to hear other opinions. From __peter__ at web.de Sun Sep 11 11:28:29 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 11 Sep 2016 17:28:29 +0200 Subject: Override property setter of base class in Python 3 - USE CASE References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> <6f14f777-8769-ea64-78b2-8bc094df4ea5@shopzeus.com> <8e35bc81-4ed9-ddb7-83fa-377d448fa6df@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > >> Yes, I believe it does. (Others may disagree. This is a design >> question and very much a matter of style, not hard fact.) I would have >> an explicit action "set_content" which will set the value of an input >> field, the inner text of a textarea, the checked state of a check box, >> etc. > In other words, you would use simple getter and setter methods instead > of properties. It is the simplest solution. (And I believe, it is > non-pythonic, but that is just an opinion.) > > I would like to hear other opinions. Disregarding potential implementation obstacles I think it would be clean and clear if you could access a property foo in a base class with super().foo and set it with super().foo = value It looks like the get part already works: >>> class A: ... @property ... def foo(self): return "foo" ... >>> class B(A): ... @property ... def foo(self): return super().foo.upper() ... >>> A().foo 'foo' >>> B().foo 'FOO' From dkoleary at olearycomputers.com Sun Sep 11 11:34:18 2016 From: dkoleary at olearycomputers.com (Doug OLeary) Date: Sun, 11 Sep 2016 08:34:18 -0700 (PDT) Subject: iterating over multi-line string Message-ID: <61c47049-2d10-4d94-af97-3d4808744c97@googlegroups.com> Hey; I have a multi-line string that's the result of reading a file filled with 'dirty' text. I read the file in one swoop to make data cleanup a bit easier - getting rid of extraneous tabs, spaces, newlines, etc. That part's done. Now, I want to collect data in each section of the data. Sections are started with a specific header and end when the next header is found. ^1\. Upgrade to the latest version of Apache HTTPD ^2\. Disable insecure TLS/SSL protocol support ^3\. Disable SSLv2, SSLv3, and TLS 1.0. The best solution is to only have TLS 1.2 enabled ^4\. Disable HTTP TRACE Method for Apache [[snip]] There's something like 60 lines of worthless text before that first header line so I thought I'd skip through them with: x=0 # Current index hx=1 # human readable index rgs = '^' + str(hx) + r'\. ' + monster['vulns'][x] hdr = re.compile(rgs) for l in data.splitlines(): while not hdr.match(l): next(l) print(l) which resulted in a typeerror stating that str is not an iterator. More googling resulted in: iterobj = iter(data.splitlines()) for l in iterobj: while not hdr.match(l): next(iterobj) print(l) I'm hoping to see that first header; however, I'm getting another error: Traceback (most recent call last): File "./testies.py", line 30, in next(iterobj) StopIteration I'm not quite sure what that means... Does that mean I got to the end of data w/o finding my header? Thanks for any hints/tips/suggestions. Doug O'Leary From ethan at stoneleaf.us Sun Sep 11 11:42:19 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 11 Sep 2016 08:42:19 -0700 Subject: Override property setter of base class in Python 3 - USE CASE In-Reply-To: References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> <6f14f777-8769-ea64-78b2-8bc094df4ea5@shopzeus.com> <8e35bc81-4ed9-ddb7-83fa-377d448fa6df@shopzeus.com> Message-ID: <57D57B5B.8080008@stoneleaf.us> On 09/11/2016 08:28 AM, Peter Otten wrote: > Nagy L?szl? Zsolt wrote: > >> >>> Yes, I believe it does. (Others may disagree. This is a design >>> question and very much a matter of style, not hard fact.) I would have >>> an explicit action "set_content" which will set the value of an input >>> field, the inner text of a textarea, the checked state of a check box, >>> etc. >> In other words, you would use simple getter and setter methods instead >> of properties. It is the simplest solution. (And I believe, it is >> non-pythonic, but that is just an opinion.) >> >> I would like to hear other opinions. > > Disregarding potential implementation obstacles I think it would be clean > and clear if you could access a property foo in a base class with > > super().foo > > and set it with > > super().foo = value > > It looks like the get part already works: > >>>> class A: > ... @property > ... def foo(self): return "foo" > ... >>>> class B(A): > ... @property > ... def foo(self): return super().foo.upper() > ... >>>> A().foo > 'foo' >>>> B().foo > 'FOO' Yes, the get part works. The set part is a pain, and a bit ugly: super(B, B).foo.__set__(self, value) There is an issue for this on the tracker: http://bugs.python.org/issue14965 -- ~Ethan~ From dkoleary at olearycomputers.com Sun Sep 11 11:58:29 2016 From: dkoleary at olearycomputers.com (Doug OLeary) Date: Sun, 11 Sep 2016 08:58:29 -0700 (PDT) Subject: iterating over multi-line string In-Reply-To: <61c47049-2d10-4d94-af97-3d4808744c97@googlegroups.com> References: <61c47049-2d10-4d94-af97-3d4808744c97@googlegroups.com> Message-ID: <6d7290b3-3310-49c1-ae15-8092032ff760@googlegroups.com> Hey; Never mind; I finally found the meaning of stopiteration. I guess my google-foo is a bit weak this morning. Thanks Doug From dkoleary at olearycomputers.com Sun Sep 11 12:57:49 2016 From: dkoleary at olearycomputers.com (Doug OLeary) Date: Sun, 11 Sep 2016 09:57:49 -0700 (PDT) Subject: more python3 regex? Message-ID: Hey This one seems like it should be easy but I'm not getting the expected results. I have a chunk of data over which I can iterate line by line and print out the expected results: for l in q.findall(data): # if re.match(r'(Name|")', l): # continue print(l) $ ./testies.py | wc -l 197 I would like to skip any line that starts with 'Name' or a double quote: $ ./testies.py | perl -ne 'print if (m{^Name} || m{^"})' Name IP Address,Site, "",,7 of 64 Name,IP Address,Site, "",,,8 of 64 Name,IP Address,Site, "",,,9 of 64 Name,IP Address,Site, "",,,10 of 64 Name,IP Address,Site, "",,,11 of 64 Name IP Address,Site, $ ./testies.py | perl -ne 'print unless (m{^Name} || m{^"})' | wc -l 186 When I run with the two lines uncommented, *everything* gets skipped: $ ./testies.py $ Same thing when I use a pre-defined pattern object: skippers = re.compile(r'Name|"') for l in q.findall(data): if skippers.match(l): continue print(l) Like I said, this seems like it should be pretty straight forward so I'm obviously missing something basic. Any hints/tips/suggestions gratefully accepted. Doug O'Leary From __peter__ at web.de Sun Sep 11 13:17:25 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 11 Sep 2016 19:17:25 +0200 Subject: iterating over multi-line string References: <61c47049-2d10-4d94-af97-3d4808744c97@googlegroups.com> Message-ID: Doug OLeary wrote: > Hey; > > I have a multi-line string that's the result of reading a file filled with > 'dirty' text. I read the file in one swoop to make data cleanup a bit > easier - getting rid of extraneous tabs, spaces, newlines, etc. That > part's done. > > Now, I want to collect data in each section of the data. Sections are > started with a specific header and end when the next header is found. > > ^1\. Upgrade to the latest version of Apache HTTPD > ^2\. Disable insecure TLS/SSL protocol support > ^3\. Disable SSLv2, SSLv3, and TLS 1.0. The best solution is to only have > TLS 1.2 enabled ^4\. Disable HTTP TRACE Method for Apache > [[snip]] > > There's something like 60 lines of worthless text before that first header > line so I thought I'd skip through them with: > > x=0 # Current index > hx=1 # human readable index > rgs = '^' + str(hx) + r'\. ' + monster['vulns'][x] > hdr = re.compile(rgs) > for l in data.splitlines(): > while not hdr.match(l): > next(l) > print(l) > > which resulted in a typeerror stating that str is not an iterator. More > googling resulted in: > > iterobj = iter(data.splitlines()) > > for l in iterobj: > while not hdr.match(l): > next(iterobj) > print(l) > > I'm hoping to see that first header; however, I'm getting another error: > > Traceback (most recent call last): > File "./testies.py", line 30, in > next(iterobj) > StopIteration > > I'm not quite sure what that means... Does that mean I got to the end of > data w/o finding my header? > > Thanks for any hints/tips/suggestions. If you nest the loops you don't just skip the lines before the first, but before every header. Unless your data ends with a header the inner loop will eventually run out of lines without seeing another header. Here are two clean (I think) ways to capture the lines starting with the first header. (1) Do-it-yourself, with a generator: def rest(lines, isheader): lines = iter(lines) for line in lines: if isheader(line): yield line # the first header break yield from lines # all lines following the first headder for line in rest(data.splitlines(), hdr.match): print(line) (2) Using the itertools from Python's standard library: import itertools def is_no_header(line): return hdr.match(line) is None for line in itertools.dropwhile(is_no_header, data.splitlines()): print(line) Both versions work with file objects, you just have to tell print not to add a newline with print(line, end="") From __peter__ at web.de Sun Sep 11 14:21:25 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 11 Sep 2016 20:21:25 +0200 Subject: more python3 regex? References: Message-ID: Doug OLeary wrote: > Hey > > This one seems like it should be easy but I'm not getting the expected > results. > > I have a chunk of data over which I can iterate line by line and print out > the expected results: > > for l in q.findall(data): > # if re.match(r'(Name|")', l): > # continue > print(l) > > $ ./testies.py | wc -l > 197 > > I would like to skip any line that starts with 'Name' or a double quote: > > $ ./testies.py | perl -ne 'print if (m{^Name} || m{^"})' > Name IP Address,Site, > "",,7 of 64 > Name,IP Address,Site, > "",,,8 of 64 > Name,IP Address,Site, > "",,,9 of 64 > Name,IP Address,Site, > "",,,10 of 64 > Name,IP Address,Site, > "",,,11 of 64 > Name IP Address,Site, > > $ ./testies.py | perl -ne 'print unless (m{^Name} || m{^"})' | wc -l > 186 > > > When I run with the two lines uncommented, *everything* gets skipped: > > $ ./testies.py > $ > > Same thing when I use a pre-defined pattern object: > > skippers = re.compile(r'Name|"') > for l in q.findall(data): > if skippers.match(l): > continue > print(l) > > Like I said, this seems like it should be pretty straight forward so I'm > obviously missing something basic. > > Any hints/tips/suggestions gratefully accepted. Add a print() to the matching case to see where you messed up, e. g. for line in q.findall(data): if re.match(r'(Name|")', line): print("SKIPPING", repr(line)) continue print(line) In the future try to provide small self-contained scripts that others can run. That will also make your own debugging experience more pleasant ;) Had you tried $ cat oleary.py import re lines = """\ foo show "bar" skip Name skip Name show "baz" show baz show """.splitlines() for line in lines: if re.match(r'^(Name|")', line): continue print(line) $ python3 oleary.py foo show Name show "baz" show baz show you could easily have convinced yourself that both the loop and the regex work as expected. By the way, many simple text-processing problems can be solved without regular expressions. Most Python users will spell a simple filter like the above above as for line in lines: if not line.startswith(("Name", '"')): print(line) or similar. From gandalf at shopzeus.com Sun Sep 11 14:26:05 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sun, 11 Sep 2016 20:26:05 +0200 Subject: Override property setter of base class in Python 3 - USE CASE In-Reply-To: <57D57B5B.8080008@stoneleaf.us> References: <2d8a2ce8-b7df-5940-e19f-6647c88f8e22@shopzeus.com> <6f14f777-8769-ea64-78b2-8bc094df4ea5@shopzeus.com> <8e35bc81-4ed9-ddb7-83fa-377d448fa6df@shopzeus.com> <57D57B5B.8080008@stoneleaf.us> Message-ID: <8947aa81-e6fb-09b7-6487-d1bbde776fdc@shopzeus.com> > Yes, the get part works. The set part is a pain, and a bit ugly: > > super(B, B).foo.__set__(self, value) > > There is an issue for this on the tracker: > http://bugs.python.org/issue14965 > Thank you Ethan! The superprop pure Python implementation is very promising. ( http://bugs.python.org/file37546 ) I can use that instead of my "property virtualizers" until Python built in support becomes available. :-) From srkunze at mail.de Sun Sep 11 16:30:07 2016 From: srkunze at mail.de (Sven R. Kunze) Date: Sun, 11 Sep 2016 22:30:07 +0200 Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: On 10.09.2016 15:00, Chris Angelico wrote: > Some things are absolute hard facts. There is no way in which 1 will > ever be greater than 2, ergo "1 is less than 2" is strictly true, and > not a matter of opinion. If you hear someone trying to claim > otherwise, would you let him have his opinion, or would you treat it > as incorrect? I don't know exactly if it's clear that one would need to make a distinction between real/physical-world facts and pure-logic facts. "1 < 2" is by definition "true" (construction of natural numbers) not by real-world evidence. IIRC, the quote is about real-world matters. > There is some merit in this. For instance, Python 2 had a lower-level > consistency in the division operator than Python 3 has. According to > Py2, integers and floats are fundamentally different beasts, and when > you divide an int by an int, you get an int, not a float. Py3 says > "well, you probably REALLY meant to divide a number by a number", so > it gives you a float back, unless you explicitly ask for floor > division. > > Py2 is more consistent on a lower level of abstraction. Py3 is more > consistent on a higher level of abstraction (modulo the oddities at > extremely large numbers). Both have merit, but in a high level > language, the Py3 way is usually [1] better. > > But the consistency of call-by-object-reference is at the same high > level as the consistency of call-by-value or call-by-name. I can > explain Python's assignment model to someone fairly easily, using > pencil and paper, without any reference to "low level" or "high level" > concepts. And Python is extremely internally consistent; *every* > assignment behaves the exact same way. How does "import x" compare > with "from x import y"? Easy: the former is "x = some_module_object", > and the latter is "y = some_module_object.y", and either way, it's > regular assignment. How does parameter passing work? You take the > value of the argument as evaluated in the caller, and assign it to the > parameter in the function. What about default arguments? They're > evaluated when the function's defined, and assigned to the parameter > when it's called. Function definition itself is the same thing - it's > assigning a function object to a name. Python handles every one of > them the same way. > > I don't care one iota about how voltages inside a CPU operate. I don't > generally even care about machine code - let other people worry about > that, people more expert than I am. Discussions about how the core dev > and the novice see Python's consistencies are nothing to do with those > levels. To go back to your original point, that a newbie is better at > recognizing inconsistencies... maybe, in a sense, but they also get a > lot of false positives. Ultimately, "consistent" means that there's a > single pattern that explains everything; if you're unaware of that > pattern, you won't know that it's consistent. > > ChrisA > > > [1] Even in Python, there are places where low-level consistency is > better, because Python is a glue language. But in general, it's better > for Python to be consistent with humans than with C APIs. The last sentence is the part why I love Python. :) I could not agree more with what you said above, so I hope this will put the discussion in better perspective, especially when people here trying to be overly absolute in their views (which was the quote about). Cheers, Sven From chitturk at uah.edu Sun Sep 11 16:56:19 2016 From: chitturk at uah.edu (chitturk at uah.edu) Date: Sun, 11 Sep 2016 13:56:19 -0700 (PDT) Subject: sphinx (or other means to document python) Message-ID: <0e8c5dd4-6a64-45dc-adc9-e2dd58790ca2@googlegroups.com> Excuse me for being frustrated (!) (with documenting python with Sphinx) I have a source file myfile.py which contains documentation with "docstrings" I am trying to have Sphinx create the pdf (from latex) I have run through sphinx-quickstart - which creates build, source (there is some conf.py somewhere also) 1) myfile.py (should be in source?) 2) Do I need any additional programs to read docstrings and conv them to latex/pdf? (I recall answering "yes" to some question during sphinx-quickinstall) 3) Do I have to have an index.rst AND myfile.py? 4) Can I have ONE file that has my code AND documentation? (like what noweb allows me to do) 5) I have tried several times - but \f[ or \f$ does not work to embed TeX/LaTeX pycco seems far, far, far simpler - but the output is html noweb is great - except not very easy to embed comments in *.py and extract them Bottom line Is there a COMPLETE (I mean COMPLETE) example I can read about using sphinx? That complete example should have source, build, conf.py, etc etc - some user written code, some index.rst, etc etc etc and the latex/pdf (or html) should build with "make html" or "make latex" thanks! (I KNOW it is NOT that difficult - but for the life of me, I cannot figure sphinx - in part because it seems to need several files, several changes/configurations - and simply having a *.py with doctrings does not seem to be sufficient) From tjreedy at udel.edu Sun Sep 11 17:19:08 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Sep 2016 17:19:08 -0400 Subject: Python source repo In-Reply-To: <57d4264d$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <57d420e6$0$1598$c3e8da3$5496439d@news.astraweb.com> <57d4264d$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/10/2016 11:27 AM, Steve D'Aprano wrote: > On Sun, 11 Sep 2016 01:04 am, Steve D'Aprano wrote: > >> I ran hg fetch to update the CPython repo. I use pull (to local repository) and update (working directory) separately in the following script (pull.bat), based on either the devguide or what TortoiseHg uses. /35 and /27 are shares. hg --repository .\36 pull --verbose --config ui.merge=internal:merge ssh://hg at hg.python.org/cpython hg --repository .\36 update --verbose hg --repository .\35 update --verbose hg --repository .\27 update --verbose >> It has been stuck on "adding changesets" for half an hour. I have run the above (or earlier versions) perhaps 100s of times and cannot remember anything like that. The pull output just now is pulling from ssh://hg at hg.python.org/cpython searching for changes all local heads known remotely adding changesets adding manifests adding file changes added 70 changesets with 185 changes to 126 files 'adding changesets' is very quickly (.1 second?, or less?) followed by 'adding manifests' and 'adding file changes'. Even a full second delay after 'adding changesets' would be unusual. The most substantial delay is the download time before the last line is printed. Total time: about 5 seconds, normal for this many pulls. >> I don't know if that's because the process has locked up, Something is definitely 'locked up'. > Never mind. I got bored and frustrated and Ctrl-C'ed the process and ran it > again. This time it took about 15 seconds to complete. For me, even less for the changes above. -- Terry Jan Reedy From tjreedy at udel.edu Sun Sep 11 17:30:30 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Sep 2016 17:30:30 -0400 Subject: iterating over multi-line string In-Reply-To: <61c47049-2d10-4d94-af97-3d4808744c97@googlegroups.com> References: <61c47049-2d10-4d94-af97-3d4808744c97@googlegroups.com> Message-ID: On 9/11/2016 11:34 AM, Doug OLeary wrote: > Hey; > > I have a multi-line string that's the result of reading a file filled with 'dirty' text. I read the file in one swoop to make data cleanup a bit easier - getting rid of extraneous tabs, spaces, newlines, etc. That part's done. > > Now, I want to collect data in each section of the data. Sections are started with a specific header and end when the next header is found. > > ^1\. Upgrade to the latest version of Apache HTTPD > ^2\. Disable insecure TLS/SSL protocol support > ^3\. Disable SSLv2, SSLv3, and TLS 1.0. The best solution is to only have TLS 1.2 enabled > ^4\. Disable HTTP TRACE Method for Apache > [[snip]] > > There's something like 60 lines of worthless text before that first header line so I thought I'd skip through them with: > > x=0 # Current index > hx=1 # human readable index > rgs = '^' + str(hx) + r'\. ' + monster['vulns'][x] > hdr = re.compile(rgs) > for l in data.splitlines(): > while not hdr.match(l): > next(l) > print(l) > > which resulted in a typeerror stating that str is not an iterator. More googling resulted in: You are iterating in two different ways. Not surprising it does not work. The re is also unnecessary. The following seems to do what you want and is much simpler. data = '''\ junk more junk ^1\. upgrade ^2\. etc ''' data = data[data.index(r'^1\.'):] print(data) # ^1\. upgrade ^2\. etc -- Terry Jan Reedy From suabiut at gmail.com Sun Sep 11 17:40:55 2016 From: suabiut at gmail.com (sum abiut) Date: Mon, 12 Sep 2016 08:40:55 +1100 Subject: pymssql In-Reply-To: <20aed816-1867-424d-8084-61cd6d6f5cd2@googlegroups.com> References: <20aed816-1867-424d-8084-61cd6d6f5cd2@googlegroups.com> Message-ID: Thanks heaps for your comments, manage to get it work using the as_dict` parameter of the `cursor` object, cus=conn.cursor(as_dict=True) cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud") for row in cus: print(row['budget_code'],row['budget_description'],row['rate_type']) cheers, On Sat, Sep 10, 2016 at 3:22 PM, Miki Tebeka wrote: > > for row in cus: > > print(row.budget_code) > > > > > > NameError: name 'budget_code' is not defined > You'll need to use a DictCursor to be able to access rows by name and not > position (which IMO is the preferred way). > > cus = conn.cursor(pymysql.cursors.DictCursor) > cus.execute("SELECT * FROM glbud ") > for row in cus: > print(row['budget_code']) > -- > https://mail.python.org/mailman/listinfo/python-list > From suabiut at gmail.com Sun Sep 11 20:37:49 2016 From: suabiut at gmail.com (sum abiut) Date: Mon, 12 Sep 2016 11:37:49 +1100 Subject: mssql date format Message-ID: Hi, I am pulling data from an mssql server database and got a date in this format: 733010 please advise what of date is this and how to i convert it to a readable date? i use pyssql to connect to the database and pull data fro the database. thanks in advance, cheers From rosuav at gmail.com Sun Sep 11 21:11:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 Sep 2016 11:11:16 +1000 Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: On Mon, Sep 12, 2016 at 6:30 AM, Sven R. Kunze wrote: > > I could not agree more with what you said above, so I hope this will put the > discussion in better perspective, especially when people here trying to be > overly absolute in their views (which was the quote about). > Strange that you think I'm a more moderate position. I have some _extremely_ strong views about absolutes (they come from the Creator of the Universe), and it's not just abstract concepts like numbers that have absolutes. There are hard-and-fast facts about the world, and even about human nature, that stem from the way we were made. However, lengthy discussion of such things is WAY off topic here. ChrisA From python at mrabarnett.plus.com Sun Sep 11 21:15:11 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Sep 2016 02:15:11 +0100 Subject: mssql date format In-Reply-To: References: Message-ID: <17e7bc7d-0eb8-d2b0-5d12-e1c7c2f06892@mrabarnett.plus.com> On 2016-09-12 01:37, sum abiut wrote: > Hi, > I am pulling data from an mssql server database and got a date in this > format: 733010 > please advise what of date is this and how to i convert it to a readable > date? > > i use pyssql to connect to the database and pull data fro the database. > Does the date "30 November 2007" look reasonable for that data? If it does, it's a """proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1""" (from the docs): >>> import datetime >>> datetime.datetime.fromordinal(733010) datetime.datetime(2007, 11, 30, 0, 0) From lawrencedo99 at gmail.com Sun Sep 11 22:04:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 11 Sep 2016 19:04:02 -0700 (PDT) Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: > I have some _extremely_ strong views about absolutes (they come from the > Creator of the Universe) ... By ?Universe? do you mean ?everything that exists?? So if the Creator exists, then the Creator, too, must be part of the Universe. So whoever created the Universe also created the Creator... From lawrencedo99 at gmail.com Sun Sep 11 22:09:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 11 Sep 2016 19:09:18 -0700 (PDT) Subject: more python3 regex? In-Reply-To: References: Message-ID: On Monday, September 12, 2016 at 6:21:57 AM UTC+12, Peter Otten wrote: > By the way, many simple text-processing problems can be solved without > regular expressions. The old JWZ quote instantly comes to mind... From rosuav at gmail.com Sun Sep 11 22:26:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 Sep 2016 12:26:01 +1000 Subject: [Python-ideas] Inconsistencies In-Reply-To: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> Message-ID: On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D?Oliveiro wrote: > On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: >> I have some _extremely_ strong views about absolutes (they come from the >> Creator of the Universe) ... > > By ?Universe? do you mean ?everything that exists?? So if the Creator exists, then the Creator, too, must be part of the Universe. > > So whoever created the Universe also created the Creator... No, God isn't part of the universe, any more than an author is part of his novel. ChrisA From rosuav at gmail.com Sun Sep 11 23:04:14 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 Sep 2016 13:04:14 +1000 Subject: mssql date format In-Reply-To: <17e7bc7d-0eb8-d2b0-5d12-e1c7c2f06892@mrabarnett.plus.com> References: <17e7bc7d-0eb8-d2b0-5d12-e1c7c2f06892@mrabarnett.plus.com> Message-ID: On Mon, Sep 12, 2016 at 11:15 AM, MRAB wrote: > On 2016-09-12 01:37, sum abiut wrote: >> >> Hi, >> I am pulling data from an mssql server database and got a date in this >> format: 733010 >> please advise what of date is this and how to i convert it to a readable >> date? >> >> i use pyssql to connect to the database and pull data fro the database. >> > Does the date "30 November 2007" look reasonable for that data? And if it doesn't, try selecting now() from the database, which should give you today's date and time. Possibly cast that to the same type of date that you're working with. If that gives you an easily readable result, you may have some kind of custom "date stored as integer" field, which you'd have to discuss with your DB admin. ChrisA From python at mrabarnett.plus.com Sun Sep 11 23:06:33 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Sep 2016 04:06:33 +0100 Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> Message-ID: On 2016-09-12 03:26, Chris Angelico wrote: > On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D?Oliveiro > wrote: >> On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: >>> I have some _extremely_ strong views about absolutes (they come from the >>> Creator of the Universe) ... >> >> By ?Universe? do you mean ?everything that exists?? So if the Creator exists, then the Creator, too, must be part of the Universe. >> >> So whoever created the Universe also created the Creator... > > No, God isn't part of the universe, any more than an author is part of > his novel. > Is this the five minute argument or the full half hour? :-) From dkoleary at olearycomputers.com Sun Sep 11 23:51:04 2016 From: dkoleary at olearycomputers.com (Doug OLeary) Date: Sun, 11 Sep 2016 20:51:04 -0700 (PDT) Subject: more python3 regex? In-Reply-To: References: Message-ID: <3880877e-9bba-4fca-a363-0aaf32f7b032@googlegroups.com> Hey, all; The print suggestion was the key clue. Turned out my loop was slurping the whole of data in one big line. Searching for a line that begins with Name when it's in the middle of the string is... obviously not going to work so well. Took me a bit to get that working and, once I did, I realized I was on the wrong track altogether. In perl, if possible, I will read a file entirely as manipulation of one large data structure is easier in some ways. Even with perl, though, that approach is the wrong one for this data. While I learned lots, the key lesson is forcing data to match an algorithm works as well in python as it does in perl. Go figure. My 200+ script that didn't work so well is now 63 lines, including comments... and works perfectly. Outstanding! Thanks for putting up with noob questions Doug From dieter at handshake.de Mon Sep 12 02:59:27 2016 From: dieter at handshake.de (dieter) Date: Mon, 12 Sep 2016 08:59:27 +0200 Subject: collect2: ld returned 1 exit status when building from source References: <57d42c66$0$1586$c3e8da3$5496439d@news.astraweb.com> <57d4a097$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k2ehk3hs.fsf@handshake.de> Steve D'Aprano writes: > ... > but the build still fails, with the same errors: > > > Python/dtrace_stubs.o: In function `PyDTrace_LINE': > /home/steve/python/python-dev/cpython/Include/pydtrace.h:25: multiple > definition of `PyDTrace_LINE' > Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:25: > first defined here > [ ... many, many, many more similar errors ... ] > > collect2: ld returned 1 exit status > make: *** [Programs/_freeze_importlib] Error 1 Looks as if some error has slipped in the sources: you should not have multiple conflicting definitions for the same symbol (e.g. "PyDTrace_LINE"). Alternatively, your built might fetch wrong headers (e.g. headers for a different Python version). I would look at the places from which the "multiple definition"s come and try to find out why there are multiple of them. From bogus@does.not.exist.com Mon Sep 12 03:37:11 2016 From: bogus@does.not.exist.com (not1xor1) Date: Mon, 12 Sep 2016 09:37:11 +0200 Subject: [Python-ideas] Inconsistencies References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> Message-ID: Il 12/09/2016 04:26, Chris Angelico ha scritto: >> So whoever created the Universe also created the Creator... > No, God isn't part of the universe, any more than an author is part of > his novel. your logic is based on the assumption that the _existance_ itself, i.e. the mere presence of something, can be explained only by the presence of a "creator" but such agent must _exists_ to be able to perform any act of creation, so, according to the given logic, she-he-it (-self) must have been created by some other kind of agent so there are 0x10 chances: - 0x00 an infinitive hierarchy of "creators" (you might get a stack overflow) - 0x01 the universe has always been there an the need of an "agent" is just due to the classical "every event is explained by a purposeful agent" cognitive fallacy I do not know if the 0x00 item is the right one, but I'm sure that a possible 'creator' (just one hierarchical level over our present universe) would likely be quite different from all the various ones mankind imagined in the course of millennia and would strongly disapprove all the psychological projections about her-his-its will and the evil done in her-his-its name :-) p.s. I apologize for my poor English -- bye !(!1|1) From robin at reportlab.com Mon Sep 12 05:00:22 2016 From: robin at reportlab.com (Robin Becker) Date: Mon, 12 Sep 2016 10:00:22 +0100 Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: <45e24c2a-dc39-9274-4ed9-94e08184fb81@chamonix.reportlab.co.uk> On 11/09/2016 21:30, Sven R. Kunze wrote: > On 10.09.2016 15:00, Chris Angelico wrote: >> Some things are absolute hard facts. There is no way in which 1 will >> ever be greater than 2, ergo "1 is less than 2" is strictly true, and >> not a matter of opinion. If you hear someone trying to claim >> otherwise, would you let him have his opinion, or would you treat it >> as incorrect? > > I don't know exactly if it's clear that one would need to make a distinction > between real/physical-world facts and pure-logic facts. > > "1 < 2" is by definition "true" (construction of natural numbers) not by > real-world evidence. IIRC, the quote is about real-world matters. > as I understand it, the universe is said by some to be a long lived random fluctuation of nothing and it is said that observers make a real difference to reality. The existence of arithmetic etc is somewhat moot under such assumptions. Also presumably there are other constructions of 'our' familiar arithmetic. Perhaps someone could probably make an arithmetic where most of standard ZF is true except for 1<2. G?del definitely says there are holes in arithmetic :) -possibly non-existently yrs- Robin Becker From esj at harvee.org Mon Sep 12 07:12:12 2016 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 12 Sep 2016 07:12:12 -0400 Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> Message-ID: <050ce089-66a9-a5cc-451d-848cb103cbec@harvee.org> On 9/11/2016 10:26 PM, Chris Angelico wrote: > No, God isn't part of the universe, any more than an author is part of > his novel. > as any fiction writer will tell you, the author is found in one or more of their characters. From daiyueweng at gmail.com Mon Sep 12 07:14:01 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Mon, 12 Sep 2016 12:14:01 +0100 Subject: Expression can be simplified on list Message-ID: Hi, I found that when I tried to make an equality test on empty like, if errors == []: PyCharm always warns me, Expression can be simplified. I am wondering what's wrong and how to fix this? cheers From rosuav at gmail.com Mon Sep 12 07:23:05 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 Sep 2016 21:23:05 +1000 Subject: Expression can be simplified on list In-Reply-To: References: Message-ID: On Mon, Sep 12, 2016 at 9:14 PM, Daiyue Weng wrote: > Hi, I found that when I tried to make an equality test on empty like, > > if errors == []: > > PyCharm always warns me, > > Expression can be simplified. > > I am wondering what's wrong and how to fix this? > If you know that 'errors' is always going to be a list, you can check for emptiness thus: if not errors: PyCharm recommends this syntax rather than the comparison with a newly-created empty list. Your code has to actually construct and dispose of a list, just for the comparison. ChrisA From jay.sridhar at gmail.com Mon Sep 12 07:37:05 2016 From: jay.sridhar at gmail.com (Jay) Date: Mon, 12 Sep 2016 17:07:05 +0530 Subject: Problem with difflib SequenceMatcher Message-ID: Hello I am having an odd problem with difflib.SequenceMatcher. Sample code below: The strings "src" and "trg" differ only a little. The SequenceMatcher.ratio() for these strings 0.0. Many other similar strings are working fine without problems (see below) with non-zero ratios depending on how much difference there is between strings (as expected). Tested on Python 2.7 on Ubuntu 14.04 Program follows: --- from difflib import SequenceMatcher as SM src = u"N KPT T HS KMNST KNFKXNS AS H KLT FR 0 ALMNXN AF PRFT PRPRT AN RRL ARS T P RPLST P KMNS H ASTPLXT HS ANTSTRL KR0 PRKRM NN AS 0 KRT LP FRRT 0S PRKRM KLT FR 0 RPT TRNSFRMXN AF XN FRM AN AKRRN AKNM T A SSLST ANTSTRL SST" trg = u"M KPT T HS KMNST KNFKXNS AS H KLT FR 0 ALMNXN AF PRFT PRPRT AN RRL ARS T P RPLST P KMNS H ASTPLXT HS ANTSTRL KR0 PRKRM NN AS 0 KRT LP FRRT 0S PRKRM KLT FR 0 RPT TRNSFRMXN AF XN FRM AN AKRRN AKNM T SSLST ANTSTRL SST" print src, '\n', trg, '\n', SM(None, trg, src).ratio() --- The following sequence prints a ratio() of 0.989795918367 which seems about right. --- src = u"M STNK AS AN AF 0 MST AMPRTNT LTRS TRNK 0 TNT0 SNTR HS MST PRMNNT AKMPLXMNT AS 0 ASTPLXMNT AF 0 PPLS RPPLK AF XN HS A0R AXFMNTS ANKLTT LTNK HS PPL AN 0 LNK MRX AFR FR 0SNT MLS T KP 0 KMNST MFMNT ALF" trg = u"M STNK AS AN AF 0 MST AMPRTNT LTRS TRNK 0 0 SNTR HS MST PRMNNT AKMPLXMNT AS 0 ASTPLXMNT AF 0 PPLS RPPLK AF XN HS A0R AXFMNTS ANKLT LTNK HS PPL AN 0 LNK MRX AFR FR 0SNT MLS T KP 0 KMNST MFMNT ALF" print src, '\n', trg, '\n', SM(None, trg, src).ratio() --- What could be the cause? Is there something I am doing wrong? Thanks in advance -- Regards Jay From alain at universite-de-strasbourg.fr.invalid Mon Sep 12 08:18:29 2016 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Mon, 12 Sep 2016 14:18:29 +0200 Subject: Problem with difflib SequenceMatcher References: Message-ID: <87eg4pz4yy.fsf@universite-de-strasbourg.fr.invalid> Jay writes: > I am having an odd problem with difflib.SequenceMatcher. Sample code below: > > The strings "src" and "trg" differ only a little. How exactly? (Please be precise, it helps testing.) > The SequenceMatcher.ratio() for these strings 0.0. Many other similar > strings are working fine without problems (see below) with non-zero > ratios depending on how much difference there is between strings (as > expected). Calling SM(...,trg[1:],src[1:]) gives plausible result. See also the result of .get_matching_blocks() on your strings (it returns no matching blocks). It is all due to the "Autojunk" heuristics (see difflib's doc for details), which considers the first characters as junk. Call SM(...,autojunk=False). I have no idea why the maintainers made this stupid autojunk idea the default. Complain with them. -- Alain. > Tested on Python 2.7 on Ubuntu 14.04 > > Program follows: > --- > from difflib import SequenceMatcher as SM > > src = u"N KPT T HS KMNST KNFKXNS AS H KLT FR 0 ALMNXN AF PRFT PRPRT AN > RRL ARS T P RPLST P KMNS H ASTPLXT HS ANTSTRL KR0 PRKRM NN AS 0 KRT LP > FRRT 0S PRKRM KLT FR 0 RPT TRNSFRMXN AF XN FRM AN AKRRN AKNM T A SSLST > ANTSTRL SST" > trg = u"M KPT T HS KMNST KNFKXNS AS H KLT FR 0 ALMNXN AF PRFT PRPRT AN > RRL ARS T P RPLST P KMNS H ASTPLXT HS ANTSTRL KR0 PRKRM NN AS 0 KRT LP > FRRT 0S PRKRM KLT FR 0 RPT TRNSFRMXN AF XN FRM AN AKRRN AKNM T SSLST > ANTSTRL SST" > print src, '\n', trg, '\n', SM(None, trg, src).ratio() From jeanmichel at sequans.com Mon Sep 12 08:42:00 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 12 Sep 2016 14:42:00 +0200 Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> Message-ID: On 09/12/2016 03:11 AM, Chris Angelico wrote: > On Mon, Sep 12, 2016 at 6:30 AM, Sven R. Kunze wrote: >> >> I could not agree more with what you said above, so I hope this will put the >> discussion in better perspective, especially when people here trying to be >> overly absolute in their views (which was the quote about). >> > > Strange that you think I'm a more moderate position. I have some > _extremely_ strong views about absolutes (they come from the Creator > of the Universe), and it's not just abstract concepts like numbers > that have absolutes. There are hard-and-fast facts about the world, > and even about human nature, that stem from the way we were made. > > However, lengthy discussion of such things is WAY off topic here. > > ChrisA > Let me help you phrase on-topic nonsense: I strongly believe that God is within each "self" parameter of each method ever written since 1989 aka 0 BGvR :o) jm From cloverobert at gmail.com Mon Sep 12 08:48:24 2016 From: cloverobert at gmail.com (Robert Clove) Date: Mon, 12 Sep 2016 18:18:24 +0530 Subject: memberof example using ldap Message-ID: Hi, I have to find if user is the member of a group, for this i am using the following query (&(objectClass=user)(sAMAccountName=yourUserName) (memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com)) (memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com)== values from distinguished name of your group The above query doesn't work fine even if group doesn't exist, It always says that user is member of From marko at pacujo.net Mon Sep 12 09:12:02 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 12 Sep 2016 16:12:02 +0300 Subject: [Python-ideas] Inconsistencies References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <050ce089-66a9-a5cc-451d-848cb103cbec@harvee.org> Message-ID: <87vay1uusd.fsf@elektro.pacujo.net> "Eric S. Johansson" : > On 9/11/2016 10:26 PM, Chris Angelico wrote: >> No, God isn't part of the universe, any more than an author is part >> of his novel. >> > as any fiction writer will tell you, the author is found in one or > more of their characters. God created us in his image. IOW, God is a Python hacker, and we are instances of some Python classes running on a cosmic VM. The Book suggests God had some initial interaction with his creation but quickly grew frustrated and ultimately bored. He must have found other interests (or friends) long time ago, but has apparently forgotten the server running in a corner closet. It has been prophesied that God will eventually write a Version 2 of the universe which will have most of the known glitches in Version 1 fixed. Mandatory upgrades will be pushed from the Cloud. Personally, I suspect Version 2 is all vaporware. Marko From jeanmichel at sequans.com Mon Sep 12 10:00:51 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 12 Sep 2016 16:00:51 +0200 Subject: How to split value where is comma ? In-Reply-To: References: <20160907225444.0f99a5a2@imp> <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> Message-ID: On 09/11/2016 02:12 PM, Chris Angelico wrote: > On Thu, Sep 8, 2016 at 7:27 PM, Joaquin Alzola > wrote: >>> I have worked places where they put stuff like this at the bottom of emails sent to the person sitting next to them :) -raising entropy-ly yrs- Robin Becker >> >> Cannot do anything about it. It is not on my MTA client and it is added by the company server :( [snip] > Tell your bosses how stupid it makes the company look. > > ChrisA > That could get someone into troubles. I would not follow that advice before considering the probable outcomes. I'd rather go for the change of mail server. jm From rosuav at gmail.com Mon Sep 12 10:07:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 00:07:01 +1000 Subject: How to split value where is comma ? In-Reply-To: References: <20160907225444.0f99a5a2@imp> <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> Message-ID: On Tue, Sep 13, 2016 at 12:00 AM, jmp wrote: > On 09/11/2016 02:12 PM, Chris Angelico wrote: >> >> On Thu, Sep 8, 2016 at 7:27 PM, Joaquin Alzola >> wrote: >>>> >>>> I have worked places where they put stuff like this at the bottom of >>>> emails sent to the person sitting next to them :) -raising entropy-ly yrs- >>>> Robin Becker >>> >>> >>> Cannot do anything about it. It is not on my MTA client and it is added >>> by the company server :( > > > [snip] > >> Tell your bosses how stupid it makes the company look. >> >> ChrisA >> > > That could get someone into troubles. I would not follow that advice before > considering the probable outcomes. Yes. Consider the probable outcomes before doing it, but still do it. If you're more important to the company than the stupid-looking boiler-plate, it will be fired rather than you. And if you learn that pseudo-legalese boiler-plate is more important than you are... you probably don't want to work there anyway. ChrisA From grant.b.edwards at gmail.com Mon Sep 12 10:30:32 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 12 Sep 2016 14:30:32 +0000 (UTC) Subject: How to split value where is comma ? References: <20160907225444.0f99a5a2@imp> <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> Message-ID: On 2016-09-12, jmp wrote: > On 09/11/2016 02:12 PM, Chris Angelico wrote: >> On Thu, Sep 8, 2016 at 7:27 PM, Joaquin Alzola >> wrote: >>>> I have worked places where they put stuff like this at the bottom of emails sent to the person sitting next to them :) -raising entropy-ly yrs- Robin Becker >>> >>> Cannot do anything about it. It is not on my MTA client and it is added by the company server :( > > [snip] > >> Tell your bosses how stupid it makes the company look. >> >> ChrisA >> > > That could get someone into troubles. Well, you need to be a bit diplomatic about it: "Just FYI, people have told me that they think our boilerplate disclaimer makes it seem that the company is naive and lacks an understanding of how the Internet works and the legalities involved..." -- Grant Edwards grant.b.edwards Yow! Is something VIOLENT at going to happen to a gmail.com GARBAGE CAN? From alister.ware at ntlworld.com Mon Sep 12 11:19:53 2016 From: alister.ware at ntlworld.com (alister) Date: Mon, 12 Sep 2016 15:19:53 GMT Subject: [Python-ideas] Inconsistencies Message-ID: On Mon, 12 Sep 2016 16:12:02 +0300, Marko Rauhamaa wrote: > "Eric S. Johansson" : > >> On 9/11/2016 10:26 PM, Chris Angelico wrote: >>> No, God isn't part of the universe, any more than an author is part of >>> his novel. >>> >> as any fiction writer will tell you, the author is found in one or more >> of their characters. > > God created us in his image. IOW, God is a Python hacker, and we are > instances of some Python classes running on a cosmic VM. > > > The Book suggests God had some initial interaction with his creation but > quickly grew frustrated and ultimately bored. He must have found other > interests (or friends) long time ago, but has apparently forgotten the > server running in a corner closet. It has been prophesied that God will > eventually write a Version 2 of the universe which will have most of the > known glitches in Version 1 fixed. Mandatory upgrades will be pushed > from the Cloud. > > Personally, I suspect Version 2 is all vaporware. > > > Marko perhaps "The Matrix" had it right we could not cope wit a perfect world so this is in fact V2 & the glitches are deliberate -- Twenty Percent of Zero is Better than Nothing. -- Walt Kelly From alister.ware at ntlworld.com Mon Sep 12 11:22:30 2016 From: alister.ware at ntlworld.com (alister) Date: Mon, 12 Sep 2016 15:22:30 GMT Subject: How to split value where is comma ? References: <20160907225444.0f99a5a2@imp> <258db8c1-0037-ae5c-5ffb-5d2295fe344c@chamonix.reportlab.co.uk> Message-ID: On Mon, 12 Sep 2016 14:30:32 +0000, Grant Edwards wrote: > On 2016-09-12, jmp wrote: >> On 09/11/2016 02:12 PM, Chris Angelico wrote: >>> On Thu, Sep 8, 2016 at 7:27 PM, Joaquin Alzola >>> wrote: >>>>> I have worked places where they put stuff like this at the bottom of >>>>> emails sent to the person sitting next to them :) -raising >>>>> entropy-ly yrs- Robin Becker >>>> >>>> Cannot do anything about it. It is not on my MTA client and it is >>>> added by the company server :( >> >> [snip] >> >>> Tell your bosses how stupid it makes the company look. >>> >>> ChrisA >>> >>> >> That could get someone into troubles. > > Well, you need to be a bit diplomatic about it: > > "Just FYI, people have told me that they think our boilerplate > disclaimer makes it seem that the company is naive and lacks an > understanding of how the Internet works and the legalities > involved..." Tag on "and they are not sure the want to do business with us because of it" that should make someone look at it first rather than simply dismiss it out of hand -- Real Users are afraid they'll break the machine -- but they're never afraid to break your face. From gordon at panix.com Mon Sep 12 11:39:01 2016 From: gordon at panix.com (John Gordon) Date: Mon, 12 Sep 2016 15:39:01 +0000 (UTC) Subject: memberof example using ldap References: Message-ID: In Robert Clove writes: > Hi, > I have to find if user is the member of a group, for this i am using the > following query > (&(objectClass=user)(sAMAccountName=yourUserName) > (memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com)) > The above query doesn't work fine even if group doesn't exist, > It always says that user is member of The query returns a user who is not a member of the named group? That's odd. What is the search base and scope? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From Joshua.R.English at gmail.com Mon Sep 12 12:08:14 2016 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 12 Sep 2016 09:08:14 -0700 (PDT) Subject: Mysterious Logging Handlers In-Reply-To: References: <247db0ab-efe7-484b-a418-dd219f68a8e5@googlegroups.com> Message-ID: On Friday, September 9, 2016 at 11:29:32 AM UTC-7, John Gordon wrote: > In <247db0ab-efe7-484b-a418-dd219f68a8e5 at googlegroups.com> Josh English writes: > > > When I run the scriptI get logging information from only xlreader, not > > from the main script: > > > DEBUG:XLREADER:Creating Excel Reader > > > This format isn't defined anywhere. > > That is the default logging format; it's used when you haven't supplied any > format of your own. The snippet of xlreader.py does not define any format, > so it seems like that's where it's coming from. > > (This seems pretty straightforward; am I missing something?) > Strange. I don't see that in the docs anywhere. I figure if basicConfig can set the level, it can set the formatting, too, for all my loggers, not just one. I suspect my IDE was interfering somehow. I'm using Sypder with WinPython Portable and when I changed my run settings to run in a new dedicated console, logging worked an expected. Josh From Joshua.R.English at gmail.com Mon Sep 12 12:12:48 2016 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 12 Sep 2016 09:12:48 -0700 (PDT) Subject: Mysterious Logging Handlers In-Reply-To: References: <247db0ab-efe7-484b-a418-dd219f68a8e5@googlegroups.com> Message-ID: On Friday, September 9, 2016 at 11:31:13 AM UTC-7, Peter Otten wrote: > Josh English wrote: > > > > > LOG = logging.getLogger('SHIPPING') > > FORMAT = '%(asctime)-15s %(name)s %(level)-8s %(message)s' > > That should be either levelname or levelno in the format string. Yeah, I caught that after I tried running the script in a dedicated console in Spyder, and my logging worked as expected. I got the format and whole bunch of errors about this. > > > > Even more mysterious, after I run the file (in an IDE so I have a REPL > > afterwards), I have: > > Don't run your code in an IDE. The interaction between your and their code > can make debugging harder than necessary. I suspect the IDE was the problem, because the dedicated console option solved the problem. Thanks, Josh From daiyueweng at gmail.com Mon Sep 12 12:27:11 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Mon, 12 Sep 2016 17:27:11 +0100 Subject: KeyError: 'handlers.RotatingFileHandler' Message-ID: Hi, I am trying to use 'RotatingFileHandler' in a logging config file, import logging import logging.config import logging.handlers logging.config.fileConfig('logging.conf') [loggers] keys=root,ingestion_log [handlers] keys=consoleHandler,fileHandler [formatters] keys=ingestFormatter [logger_root] level=DEBUG handlers=consoleHandler [logger_ingestion_log] level=DEBUG handlers=handlers.RotatingFileHandler maxBytes=51200 qualname=ingestion_log propagate=0 [handler_consoleHandler] class=StreamHandler level=DEBUG formatter=Formatter args=(sys.stdout,) [handler_fileHandler] class=FileHandler level=DEBUG formatter=Formatter args=("log/logging.log",) [formatter_Formatter] format=pathname~%(pathname)s||timestamp~%(asctime)s||level~%(levelname)s||name~%(name)s||function_name~%(funcName)s||debug_message~%(message)s datefmt=%m/%d/%Y %H:%M:%S but Python generated a key error, C:\Continuum\Anaconda3\lib\logging\config.py:85: in fileConfig _install_loggers(cp, handlers, disable_existing_loggers) C:\Continuum\Anaconda3\lib\logging\config.py:254: in _install_loggers logger.addHandler(handlers[hand]) E KeyError: 'handlers.RotatingFileHandler' how to fix the errors? thanks From rosuav at gmail.com Mon Sep 12 12:47:07 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 02:47:07 +1000 Subject: Mysterious Logging Handlers In-Reply-To: References: <247db0ab-efe7-484b-a418-dd219f68a8e5@googlegroups.com> Message-ID: On Tue, Sep 13, 2016 at 2:12 AM, Josh English wrote: >> > Even more mysterious, after I run the file (in an IDE so I have a REPL >> > afterwards), I have: >> >> Don't run your code in an IDE. The interaction between your and their code >> can make debugging harder than necessary. > > I suspect the IDE was the problem, because the dedicated console option solved the problem. IDEs can be really helpful, but they do introduce extra variables. Whenever you have a problem, save your code to a stand-alone script (if it isn't already one), and run it independently of the IDE. You should be able to just pull up a terminal on your system and run "python3 scriptname.py" to see it run in a clean(er) envirnonment. ChrisA From __peter__ at web.de Mon Sep 12 13:05:33 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 12 Sep 2016 19:05:33 +0200 Subject: KeyError: 'handlers.RotatingFileHandler' References: Message-ID: Daiyue Weng wrote: > Hi, I am trying to use 'RotatingFileHandler' in a logging config file, > > import logging > import logging.config > import logging.handlers > > logging.config.fileConfig('logging.conf') > > > [loggers] > keys=root,ingestion_log > > [handlers] > keys=consoleHandler,fileHandler > > [formatters] > keys=ingestFormatter > > [logger_root] > level=DEBUG > handlers=consoleHandler > > [logger_ingestion_log] > level=DEBUG > handlers=handlers.RotatingFileHandler The handlers listed above must be taken from the keys value in the [handlers] section. If you want a third logger you have to add a corresponding key there first under a name that you invented, e. g. [handlers] keys=consoleHandler,fileHandler,my_rotating_filehandler You also need a [handler_my_rotating_handler] section where you specify the class etc. Only then you can reference it in the logger section as [logger_ingestion_log] handlers=my_rotating_filehandler For the details have another look at https://docs.python.org/dev/library/logging.config.html#logging-config-fileformat > maxBytes=51200 > qualname=ingestion_log > propagate=0 > > [handler_consoleHandler] > class=StreamHandler > level=DEBUG > formatter=Formatter > args=(sys.stdout,) > > [handler_fileHandler] > class=FileHandler > level=DEBUG > formatter=Formatter > args=("log/logging.log",) > > [formatter_Formatter] > format=pathname~%(pathname)s||timestamp~%(asctime)s||level~%(levelname)s|| name~%(name)s||function_name~%(funcName)s||debug_message~%(message)s > datefmt=%m/%d/%Y %H:%M:%S > > > but Python generated a key error, > > C:\Continuum\Anaconda3\lib\logging\config.py:85: in fileConfig > _install_loggers(cp, handlers, disable_existing_loggers) > C:\Continuum\Anaconda3\lib\logging\config.py:254: in _install_loggers > logger.addHandler(handlers[hand]) > E KeyError: 'handlers.RotatingFileHandler' > > how to fix the errors? > > thanks From danutzp0 at gmail.com Mon Sep 12 13:09:03 2016 From: danutzp0 at gmail.com (danutzp0 at gmail.com) Date: Mon, 12 Sep 2016 10:09:03 -0700 (PDT) Subject: Software Needs Philosophers In-Reply-To: <1148202931.643116.41150@j33g2000cwa.googlegroups.com> References: <1148202931.643116.41150@j33g2000cwa.googlegroups.com> Message-ID: Yes, it does: https://philosoftware.wordpress.com/ From bc at freeuk.com Mon Sep 12 13:23:03 2016 From: bc at freeuk.com (BartC) Date: Mon, 12 Sep 2016 18:23:03 +0100 Subject: collect2: ld returned 1 exit status when building from source In-Reply-To: References: <57d42c66$0$1586$c3e8da3$5496439d@news.astraweb.com> <57d4a097$0$1584$c3e8da3$5496439d@news.astraweb.com> <87k2ehk3hs.fsf@handshake.de> Message-ID: On 12/09/2016 07:59, dieter wrote: > Steve D'Aprano writes: >> ... >> but the build still fails, with the same errors: >> >> >> Python/dtrace_stubs.o: In function `PyDTrace_LINE': >> /home/steve/python/python-dev/cpython/Include/pydtrace.h:25: multiple >> definition of `PyDTrace_LINE' >> Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:25: >> first defined here >> [ ... many, many, many more similar errors ... ] >> >> collect2: ld returned 1 exit status >> make: *** [Programs/_freeze_importlib] Error 1 > > Looks as if some error has slipped in the sources: you should not have multiple > conflicting definitions for the same symbol (e.g. "PyDTrace_LINE"). > Alternatively, your built might fetch wrong headers (e.g. headers > for a different Python version). > > I would look at the places from which the "multiple definition"s come > and try to find out why there are multiple of them. I downloaded the sources to have a look, but I couldn't even see those files (only ceval.c). Perhaps they are auto-generated as part of the build. I hate these complicated auto-build-tools where they /have/ to work 100% perfectly otherwise you're ... in deep trouble when something goes wrong. And this is a perfect example. -- bartc From anddam+NOSPAM at brapi.net Mon Sep 12 14:22:15 2016 From: anddam+NOSPAM at brapi.net (Andrea D'Amore) Date: Mon, 12 Sep 2016 20:22:15 +0200 Subject: Software Needs Philosophers References: Message-ID: On 2016-09-12 17:09:03 +0000, danutzp0 at gmail.com said: > Yes, it does: Operating systems do as well . -- Andrea From gordon at panix.com Mon Sep 12 16:55:40 2016 From: gordon at panix.com (John Gordon) Date: Mon, 12 Sep 2016 20:55:40 +0000 (UTC) Subject: How to extend a tuple of tuples? References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> Message-ID: In <2349538.mvXUDI8C0e at PointedEars.de> Thomas 'PointedEars' Lahn writes: > >> The obvious way does not work - > >> > >> a += (5, 6) > ^^^^^^ > > Right, because a tuple is immutable. > How did you get that idea? It has been mutated in the very statement that > you are quoting No. An entirely new tuple is created, and 'a' is rebound to it. The existing tuple is not mutated. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From bc at freeuk.com Mon Sep 12 17:19:49 2016 From: bc at freeuk.com (BartC) Date: Mon, 12 Sep 2016 22:19:49 +0100 Subject: How to extend a tuple of tuples? In-Reply-To: <2349538.mvXUDI8C0e@PointedEars.de> References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> Message-ID: On 12/09/2016 21:31, Thomas 'PointedEars' Lahn wrote: > Ben Finney wrote: > >> "Frank Millman" writes: >>> Assume you have a tuple of tuples - >>> >>> a = ((1, 2), (3, 4)) >>> >>> You want to add a new tuple to it, so that it becomes >> >> As you acknowledge, the tuple ?a? can't become anything else. Instead, >> you need to create a different value. > > Wrong. > >>> The obvious way does not work - >>> >>> a += (5, 6) >>> >>> ((1, 2), (3, 4), 5, 6) > ^^^^^^ >> Right, because a tuple is immutable. > > How did you get that idea? It has been mutated in the very statement that > you are quoting, By the same argument, then strings and ints are also mutable. Here, the original tuple that a refers to has been /replaced/ by a new one. The original is unchanged. (Unless, by some optimisation that recognises that there are no other references to it, the original is actually appended to. But in general, new objects are constructed when implementing +=.) -- Bartc From PointedEars at web.de Mon Sep 12 17:21:39 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 12 Sep 2016 23:21:39 +0200 Subject: Expression can be simplified on list References: Message-ID: <10685671.O9o76ZdvQC@PointedEars.de> Chris Angelico wrote: > On Mon, Sep 12, 2016 at 9:14 PM, Daiyue Weng wrote: >> Hi, I found that when I tried to make an equality test on empty like, >> >> if errors == []: >> >> PyCharm always warns me, >> >> Expression can be simplified. >> >> I am wondering what's wrong and how to fix this? >> > > If you know that 'errors' is always going to be a list, you can check > for emptiness thus: > > if not errors: If I knew that it is always going to be a list or a tuple, I would check its length instead: if len(errors) == 0: Only if I did not know that I would use the ?not? keyword, because the latter a) forces a type conversion to ?bool?; b) also works with values of other types. > PyCharm recommends this syntax rather than the comparison with a ^^^^^^^^^^^ > newly-created empty list. Are you sure? > Your code has to actually construct and dispose of a list, just for the > comparison. ACK -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From rosuav at gmail.com Mon Sep 12 17:29:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 07:29:36 +1000 Subject: How to extend a tuple of tuples? In-Reply-To: References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> Message-ID: On Tue, Sep 13, 2016 at 7:19 AM, BartC wrote: > By the same argument, then strings and ints are also mutable. > > Here, the original tuple that a refers to has been /replaced/ by a new one. > The original is unchanged. (Unless, by some optimisation that recognises > that there are no other references to it, the original is actually appended > to. But in general, new objects are constructed when implementing +=.) And by definition, that optimization cannot be detected. At best, all you could do is something like: old_id = id(a) a += something if id(a) == old_id: print("We may have an optimization, folks!") But that can have false positives. If two objects do not concurrently exist, they're allowed to have the same ID number. ChrisA From rosuav at gmail.com Mon Sep 12 17:57:55 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 07:57:55 +1000 Subject: Expression can be simplified on list In-Reply-To: <10685671.O9o76ZdvQC@PointedEars.de> References: <10685671.O9o76ZdvQC@PointedEars.de> Message-ID: On Tue, Sep 13, 2016 at 7:21 AM, Thomas 'PointedEars' Lahn wrote: > If I knew that it is always going to be a list or a tuple, I would check its > length instead: > > if len(errors) == 0: I wouldn't. I'd use boolification here too. Only if I had to distinguish between None, [], and [1,2,3], would I use a more explicit check (and it wouldn't be "== []", it would be probing for None). ChrisA From suabiut at gmail.com Mon Sep 12 19:06:26 2016 From: suabiut at gmail.com (sum abiut) Date: Tue, 13 Sep 2016 10:06:26 +1100 Subject: mssql date format In-Reply-To: <17e7bc7d-0eb8-d2b0-5d12-e1c7c2f06892@mrabarnett.plus.com> References: <17e7bc7d-0eb8-d2b0-5d12-e1c7c2f06892@mrabarnett.plus.com> Message-ID: Thanks for the response, i pulling data from an mssql database and i need to convert the date column. how to i covert and pass it to my template. i am using Django this is what i did conn=pymssql.connect(server,username,password,database) #cus=conn.cursor() cus=conn.cursor(as_dict=True) cus.execute("SELECT account_code,currency_code,balance_date,debit,credit,net_change,home_net_change FROM glbal where account_code= '50101001CORP' ") return render_to_response('revenue_budget.html',locals()) how to i convert the balance_date with the code below: import datetime >>> datetime.datetime.fromordinal(733010) >>> >> datetime.datetime(2007, 11, 30, 0, 0) On Mon, Sep 12, 2016 at 12:15 PM, MRAB wrote: > On 2016-09-12 01:37, sum abiut wrote: > >> Hi, >> I am pulling data from an mssql server database and got a date in this >> format: 733010 >> please advise what of date is this and how to i convert it to a readable >> date? >> >> i use pyssql to connect to the database and pull data fro the database. >> >> Does the date "30 November 2007" look reasonable for that data? > > If it does, it's a """proleptic Gregorian ordinal, where January 1 of year > 1 has ordinal 1""" (from the docs): > > import datetime >>>> datetime.datetime.fromordinal(733010) >>>> >>> datetime.datetime(2007, 11, 30, 0, 0) > > -- > https://mail.python.org/mailman/listinfo/python-list > From nad at python.org Mon Sep 12 19:35:19 2016 From: nad at python.org (Ned Deily) Date: Mon, 12 Sep 2016 19:35:19 -0400 Subject: [RELEASE] Python 3.6.0b1 is now available Message-ID: <942D57F5-BA76-49CB-B3DB-18E2D6F12AC4@python.org> On behalf of the Python development community and the Python 3.6 release team, I'm happy to announce the availability of Python 3.6.0b1. 3.6.0b1 is the first of four planned beta releases of Python 3.6, the next major release of Python, and marks the end of the feature development phase for 3.6. Among the new major new features in Python 3.6 are: * PEP 468 - Preserving the order of **kwargs in a function * PEP 487 - Simpler customization of class creation * PEP 495 - Local Time Disambiguation * PEP 498 - Literal String Formatting * PEP 506 - Adding A Secrets Module To The Standard Library * PEP 509 - Add a private version to dict * PEP 515 - Underscores in Numeric Literals * PEP 519 - Adding a file system path protocol * PEP 520 - Preserving Class Attribute Definition Order * PEP 523 - Adding a frame evaluation API to CPython * PEP 524 - Make os.urandom() blocking on Linux (during system startup) * PEP 525 - Asynchronous Generators (provisional) * PEP 526 - Syntax for Variable Annotations (provisional) * PEP 528 - Change Windows console encoding to UTF-8 (provisional) * PEP 529 - Change Windows filesystem encoding to UTF-8 (provisional) * PEP 530 - Asynchronous Comprehensions Please see "What?s New In Python 3.6" for more information: https://docs.python.org/3.6/whatsnew/3.6.html You can find Python 3.6.0b1 here: https://www.python.org/downloads/release/python-360b1/ Beta releases are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. We strongly encourage maintainers of third-party Python projects to test with 3.6 during the beta phase and report issues found to bugs.python.org as soon as possible. While the release is feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (2016-12-05). Our goal is have no changes after rc1. To achieve that, it will be extremely important to get as much exposure for 3.6 as possible during the beta phase. Please keep in mind that this is a preview release and its use is not recommended for production environments The next planned release of Python 3.6 will be 3.6.0b2, currently scheduled for 2016-10-03. More information about the release schedule can be found here: https://www.python.org/dev/peps/pep-0494/ -- Ned Deily nad at python.org -- [] From python at mrabarnett.plus.com Mon Sep 12 19:52:59 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 Sep 2016 00:52:59 +0100 Subject: mssql date format In-Reply-To: References: <17e7bc7d-0eb8-d2b0-5d12-e1c7c2f06892@mrabarnett.plus.com> Message-ID: On 2016-09-13 00:06, sum abiut wrote: > Thanks for the response, > i pulling data from an mssql database and i need to convert the date > column. how to i covert and pass it to my template. i am using Django > > this is what i did > > conn=pymssql.connect(server,username,password,database) > #cus=conn.cursor() > cus=conn.cursor(as_dict=True) > cus.execute("SELECT > account_code,currency_code,balance_date,debit,credit,net_change,home_net_change > FROM glbal where account_code= '50101001CORP' ") > > return render_to_response('revenue_budget.html',locals()) > > > how to i convert the balance_date with the code below: > > > > import datetime > datetime.datetime.fromordinal(733010) > > datetime.datetime(2007, 11, 30, 0, 0) > > The documentation for pymssql should tell you how to get the values of the fields. In the case of the 'balance_date' field, just pass its value into datetime.datetime.fromordinal like the code I gave. From p.infante413 at gmail.com Mon Sep 12 21:03:52 2016 From: p.infante413 at gmail.com (p.infante413 at gmail.com) Date: Mon, 12 Sep 2016 18:03:52 -0700 (PDT) Subject: How to fix PyV8 linux setup error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 Message-ID: <88cb4bab-a3b8-4c50-8f13-3a4d54a865b4@googlegroups.com> Hello, I am currently installing Pyv8 and other requirements for me to run a honeypot. I downloaded pyv8 from source and using v8 (version 5.5) - built it with depot_tools. I already exported the V8_HOME path. But I still have this error whenever I run 'python setup.py build' of pyv8. Also, I am using Python 2.7. Here is the output I get: running build running build_py running build_ext building '_PyV8' extension x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict- prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DBOOST_PYTHON_STATIC_LIB -DV8_NATIVE_REGEXP -DENABLE_DISASSEMBLER -DENABLE_LOGGING_AND_PROFILING -DENABLE_DEBUGGER_SUPPORT -DV8_TARGET_ARCH_X64 -I/home/patricia/Thesis/v8/include -I/home/patricia/Thesis/v8 -I/home/patricia/Thesis/v8/src -I/usr/include/python2.7 -c src/Exception.cpp -o build/temp.linux-x86_64-2.7/src/Exception.o cc1plus: warning: command line option ?-Wstrict-prototypes? is valid for C/ObjC but not for C++ In file included from /usr/include/c++/5/unordered_set:35:0, from /home/patricia/Thesis/v8/src/heap/spaces.h:10, from /home/patricia/Thesis/v8/src/heap/mark-compact.h:12, from /home/patricia/Thesis/v8/src/heap/incremental-marking.h:12, from /home/patricia/Thesis/v8/src/heap/incremental-marking-inl.h:8, from /home/patricia/Thesis/v8/src/heap/heap-inl.h:13, from /home/patricia/Thesis/v8/src/objects-inl.h:24, from /home/patricia/Thesis/v8/src/arguments.h:9, from /home/patricia/Thesis/v8/src/debug/debug.h:9, from /usr/include/c++/5/bits/stl_iterator_base_funcs.h:65, from /usr/include/c++/5/bits/stl_algobase.h:66, from /usr/include/c++/5/bits/char_traits.h:39, from /usr/include/c++/5/string:40, from /usr/include/c++/5/stdexcept:39, from src/Exception.h:4, from src/Exception.cpp:1: /usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support \ ^ src/Exception.cpp:18:25: fatal error: src/natives.h: No such file or directory #include "src/natives.h" ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 Well, before that, it repeatedly asks for exporting V8 to V8_HOME and building it. I do it repeatedly just to move on from it, and now, I get this. Also, I already searched in Ubuntu Packages Content Search (http://tiny.cc/snyrey) about /usr/include/c++/5/bits/stl_iterator_base_funcs.h, .../stl_algobase.h, .../char_traits.h, etc. That all led me to installing libstdc++-5-dev via apt-get install libstdc++-5-dev But still. I am getting the error. Any help will be appreciated. :) From suabiut at gmail.com Mon Sep 12 21:12:15 2016 From: suabiut at gmail.com (sum abiut) Date: Tue, 13 Sep 2016 12:12:15 +1100 Subject: Julian date to calendar date conversion Message-ID: Hi, how to convert julian date to a calander date cheers From python at mrabarnett.plus.com Mon Sep 12 21:37:22 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 Sep 2016 02:37:22 +0100 Subject: Julian date to calendar date conversion In-Reply-To: References: Message-ID: On 2016-09-13 02:12, sum abiut wrote: > Hi, > how to convert julian date to a calander date > Have a look at the jdcal module on PyPI: https://pypi.python.org/pypi/jdcal From suabiut at gmail.com Mon Sep 12 21:46:54 2016 From: suabiut at gmail.com (sum abiut) Date: Tue, 13 Sep 2016 12:46:54 +1100 Subject: Julian date to calendar date conversion In-Reply-To: References: Message-ID: Thanks On Tue, Sep 13, 2016 at 12:37 PM, MRAB wrote: > On 2016-09-13 02:12, sum abiut wrote: > >> Hi, >> how to convert julian date to a calander date >> >> Have a look at the jdcal module on PyPI: > > https://pypi.python.org/pypi/jdcal > > -- > https://mail.python.org/mailman/listinfo/python-list > From nathan.ernst at gmail.com Mon Sep 12 21:50:47 2016 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 12 Sep 2016 20:50:47 -0500 Subject: mssql date format In-Reply-To: <2fletbt1ll7ab7gqsmdnoc30bfdfgdl5sm@4ax.com> References: <17e7bc7d-0eb8-d2b0-5d12-e1c7c2f06892@mrabarnett.plus.com> <2fletbt1ll7ab7gqsmdnoc30bfdfgdl5sm@4ax.com> Message-ID: Note that this issue is mentioned in the pymssql FAQ: http://pymssql.org/en/stable/faq.html#pymssql-does-not-unserialize-date-and-time-columns-to-datetime-date-and-datetime-time-instances Regards, Nathan On Mon, Sep 12, 2016 at 8:29 PM, Dennis Lee Bieber wrote: > On Tue, 13 Sep 2016 00:52:59 +0100, MRAB > declaimed the following: > > >On 2016-09-13 00:06, sum abiut wrote: > >> Thanks for the response, > >> i pulling data from an mssql database and i need to convert the date > >> column. how to i covert and pass it to my template. i am using Django > >> > >> this is what i did > >> > >> conn=pymssql.connect(server,username,password,database) > >> #cus=conn.cursor() > >> cus=conn.cursor(as_dict=True) > >> cus.execute("SELECT > >> account_code,currency_code,balance_date,debit,credit,net_ > change,home_net_change > >> FROM glbal where account_code= '50101001CORP' ") > >> > >> return render_to_response('revenue_budget.html',locals()) > >> > >> > >> how to i convert the balance_date with the code below: > >> > >> > >> > >> import datetime > >> datetime.datetime.fromordinal(733010) > >> > >> datetime.datetime(2007, 11, 30, 0, 0) > >> > >> > >The documentation for pymssql should tell you how to get the values of > >the fields. > > > >In the case of the 'balance_date' field, just pass its value into > >datetime.datetime.fromordinal like the code I gave. > > I have a suspicion the OP needs more basic help than that -- like > how > to take data from the database, modify it, and pass it on to Django for > rendering. Note that the sample code never references records from the > cursor, and seems to just dump [locals()] everthing into the response > template. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > From ned at nedbatchelder.com Mon Sep 12 22:33:27 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 12 Sep 2016 19:33:27 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: <10685671.O9o76ZdvQC@PointedEars.de> References: <10685671.O9o76ZdvQC@PointedEars.de> Message-ID: On Monday, September 12, 2016 at 5:21:51 PM UTC-4, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > > > On Mon, Sep 12, 2016 at 9:14 PM, Daiyue Weng wrote: > > If you know that 'errors' is always going to be a list, you can check > > for emptiness thus: > > > > if not errors: > > If I knew that it is always going to be a list or a tuple, I would check its > length instead: > > if len(errors) == 0: > > Only if I did not know that I would use the ?not? keyword, because the > latter > > a) forces a type conversion to ?bool?; > b) also works with values of other types. Why do you object to the type conversion to bool? --Ned. From ned at nedbatchelder.com Mon Sep 12 22:52:49 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 12 Sep 2016 19:52:49 -0700 (PDT) Subject: How to extend a tuple of tuples? In-Reply-To: <2349538.mvXUDI8C0e@PointedEars.de> References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> Message-ID: <339915e4-b91a-4ba0-b455-a32e0845208b@googlegroups.com> On Monday, September 12, 2016 at 4:31:37 PM UTC-4, Thomas 'PointedEars' Lahn wrote: > Ben Finney wrote: > > So instead, you want a different tuple. You do that by creating it, > > explicitly constructing a new sequence with the items you want:: > > > > b = tuple([ > > item for item in a > > ] + [(5, 6)]) > > The correct approach is > > | >>> a += (5, 6), > | >>> a > | ((1, 2), (3, 4), (5, 6)) > > The problem here is an ambiguity in the Python grammar where ?(5, 6)? is > _not_ parsed as a double, but as a list of singles. The ambiguity is > resolved by adding a trailing comma. There is no ambiguity in "(5, 6)". It is a tuple of two ints. To make a sequence of tuples (albeit a one-element sequence), you add a comma to make it a one-element tuple, which is the same as "((5,6),)". > (This is basic Python knowledge.) Considering the gaps in your own Python knowledge, please try not to be condescending when answering questions here. For a discussion of mutability and immutability in Python, which will help with the other part of the discussion, you might like: http://nedbatchelder.com/text/names1.html --Ned. From rustompmody at gmail.com Tue Sep 13 02:50:39 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 12 Sep 2016 23:50:39 -0700 (PDT) Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <050ce089-66a9-a5cc-451d-848cb103cbec@harvee.org> Message-ID: On Monday, September 12, 2016 at 4:42:39 PM UTC+5:30, Eric S. Johansson wrote: > On 9/11/2016 10:26 PM, Chris Angelico wrote: > > No, God isn't part of the universe, any more than an author is part of > > his novel. > > > as any fiction writer will tell you, the author is found in one or more > of their characters. Heh! An intelligent observation! And in the same vein, a non-messianic interpretation of the core Christian teaching: http://themindunleashed.org/2015/11/you-are-god-the-true-teachings-of-jesus.html From antoon.pardon at rece.vub.ac.be Tue Sep 13 03:25:53 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 13 Sep 2016 09:25:53 +0200 Subject: How to extend a tuple of tuples? In-Reply-To: References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> Message-ID: <57D7AA01.4030101@rece.vub.ac.be> Op 12-09-16 om 23:29 schreef Chris Angelico: > On Tue, Sep 13, 2016 at 7:19 AM, BartC wrote: >> By the same argument, then strings and ints are also mutable. >> >> Here, the original tuple that a refers to has been /replaced/ by a new one. >> The original is unchanged. (Unless, by some optimisation that recognises >> that there are no other references to it, the original is actually appended >> to. But in general, new objects are constructed when implementing +=.) > And by definition, that optimization cannot be detected. At best, all > you could do is something like: > > old_id = id(a) > a += something > if id(a) == old_id: > print("We may have an optimization, folks!") > > But that can have false positives. If two objects do not concurrently > exist, they're allowed to have the same ID number. You could do the following: old_a = a a += something if old_a is a: print("We have an optimization, folks!") From marko at pacujo.net Tue Sep 13 04:04:29 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 13 Sep 2016 11:04:29 +0300 Subject: [Python-ideas] Inconsistencies References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <050ce089-66a9-a5cc-451d-848cb103cbec@harvee.org> Message-ID: <87h99kusxe.fsf@elektro.pacujo.net> Rustom Mody : > And in the same vein, a non-messianic interpretation of the core > Christian teaching: > http://themindunleashed.org/2015/11/you-are-god-the-true-teachings-of-jesus.html The link's message ("You are God") comes close to theosis () and divinization () but mostly looks like somebody's ad hoc private theology. My own take on Jesus's message (apart from establishing a theocratic state in Palestine) is: the only valid way to worship God is by serving your fellow human beings. ObTopic: Now the serpent was more crafty than any of the wild animals the Lord God had made. [Gen 3:1] Marko From rosuav at gmail.com Tue Sep 13 05:27:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 19:27:36 +1000 Subject: How to extend a tuple of tuples? In-Reply-To: <57D7AA01.4030101@rece.vub.ac.be> References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> <57D7AA01.4030101@rece.vub.ac.be> Message-ID: On Tue, Sep 13, 2016 at 5:25 PM, Antoon Pardon wrote: > Op 12-09-16 om 23:29 schreef Chris Angelico: >> On Tue, Sep 13, 2016 at 7:19 AM, BartC wrote: >>> By the same argument, then strings and ints are also mutable. >>> >>> Here, the original tuple that a refers to has been /replaced/ by a new one. >>> The original is unchanged. (Unless, by some optimisation that recognises >>> that there are no other references to it, the original is actually appended >>> to. But in general, new objects are constructed when implementing +=.) >> And by definition, that optimization cannot be detected. At best, all >> you could do is something like: >> >> old_id = id(a) >> a += something >> if id(a) == old_id: >> print("We may have an optimization, folks!") >> >> But that can have false positives. If two objects do not concurrently >> exist, they're allowed to have the same ID number. > > You could do the following: > > old_a = a > a += something > if old_a is a: > print("We have an optimization, folks!") > Uhm... that defeats the whole point of it being an optimization. See above, "there are no other references to it". :) If this condition is ever true, Python's language spec has been violated. ChrisA From antoon.pardon at rece.vub.ac.be Tue Sep 13 06:01:20 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 13 Sep 2016 12:01:20 +0200 Subject: How to extend a tuple of tuples? In-Reply-To: References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> <57D7AA01.4030101@rece.vub.ac.be> Message-ID: <57D7CE70.8090300@rece.vub.ac.be> Op 13-09-16 om 11:27 schreef Chris Angelico: > On Tue, Sep 13, 2016 at 5:25 PM, Antoon Pardon > wrote: >> Op 12-09-16 om 23:29 schreef Chris Angelico: >>> On Tue, Sep 13, 2016 at 7:19 AM, BartC wrote: >>>> By the same argument, then strings and ints are also mutable. >>>> >>>> Here, the original tuple that a refers to has been /replaced/ by a new one. >>>> The original is unchanged. (Unless, by some optimisation that recognises >>>> that there are no other references to it, the original is actually appended >>>> to. But in general, new objects are constructed when implementing +=.) >>> And by definition, that optimization cannot be detected. At best, all >>> you could do is something like: >>> >>> old_id = id(a) >>> a += something >>> if id(a) == old_id: >>> print("We may have an optimization, folks!") >>> >>> But that can have false positives. If two objects do not concurrently >>> exist, they're allowed to have the same ID number. >> You could do the following: >> >> old_a = a >> a += something >> if old_a is a: >> print("We have an optimization, folks!") >> > Uhm... that defeats the whole point of it being an optimization. See > above, "there are no other references to it". :) What do you mean? If it is an optimization, then the object a refers to will be mutated, whether or not there are other references. These other reference will all still refer to the same object that is now mutated. So how does my example defeats the point of it being an optimization? > If this condition is ever true, Python's language spec has been violated. > Then python seems to be broken: ]]] a = range(3) ]]] old_a = a ]]] a += [8, 13] ]]] id(a), id(old_a) (140062018784792, 140062018784792) ]]] a, old_a ([0, 1, 2, 8, 13], [0, 1, 2, 8, 13]) From rosuav at gmail.com Tue Sep 13 06:09:33 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 20:09:33 +1000 Subject: How to extend a tuple of tuples? In-Reply-To: <57D7CE70.8090300@rece.vub.ac.be> References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> <57D7AA01.4030101@rece.vub.ac.be> <57D7CE70.8090300@rece.vub.ac.be> Message-ID: On Tue, Sep 13, 2016 at 8:01 PM, Antoon Pardon wrote: >>> You could do the following: >>> >>> old_a = a >>> a += something >>> if old_a is a: >>> print("We have an optimization, folks!") >>> >> Uhm... that defeats the whole point of it being an optimization. See >> above, "there are no other references to it". :) > > What do you mean? If it is an optimization, then the object a refers to > will be mutated, whether or not there are other references. These other > reference will all still refer to the same object that is now mutated. The language spec says that tuples are immutable. If there's an optimization, it is pretending that the tuple is immutable if and only if there are no other references to that object. But old_a is another reference to that object! > So how does my example defeats the point of it being an optimization? > >> If this condition is ever true, Python's language spec has been violated. >> > Then python seems to be broken: > > ]]] a = range(3) > ]]] old_a = a > ]]] a += [8, 13] > ]]] id(a), id(old_a) > (140062018784792, 140062018784792) > ]]] a, old_a > ([0, 1, 2, 8, 13], [0, 1, 2, 8, 13]) A range object is not a tuple. Nor (since you were probably running this in Python 2) is a list. ChrisA From lele at metapensiero.it Tue Sep 13 06:22:23 2016 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 13 Sep 2016 12:22:23 +0200 Subject: [RELEASE] Python 3.6.0b1 is now available References: <942D57F5-BA76-49CB-B3DB-18E2D6F12AC4@python.org> Message-ID: <8737l4drq8.fsf@metapensiero.it> Ned Deily writes: > On behalf of the Python development community and the Python 3.6 release > team, I'm happy to announce the availability of Python 3.6.0b1. Kudos to everybody involved! > Among the new major new features in Python 3.6 are: > > * PEP 468 - Preserving the order of **kwargs in a function Yay! I wish I could borrow Guido's time machine to go back to my early effort on PyObjC, and take advantage of this feature to implement a nicer looking syntax to expose ObjC methods to Python (instead of hardwiring the information in the function name)! I recall we had a very brief exchange on this at the time, and I event spent a few days trying a quick&dirty approach (basically passing also the ordered list of keywords...). Anyway, we are in a new millenium now, and two major versions forward! ;-) Thank you all, 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 daiyueweng at gmail.com Tue Sep 13 06:42:33 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Tue, 13 Sep 2016 11:42:33 +0100 Subject: Global variable is undefined at the module level Message-ID: Hi, I defined a global variable in some function like this, def some_function(self): global global_var PyCharm inspection gave me, Global variable is undefined at the module level How to fix this? cheers From nulla.epistola at web.de Tue Sep 13 06:42:48 2016 From: nulla.epistola at web.de (Sibylle Koczian) Date: Tue, 13 Sep 2016 12:42:48 +0200 Subject: How to extend a tuple of tuples? In-Reply-To: References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> <57D7AA01.4030101@rece.vub.ac.be> <57D7CE70.8090300@rece.vub.ac.be> Message-ID: <0c4a3b50-543e-4d78-22c0-8ae5f375b2f6@web.de> Am 13.09.2016 um 12:09 schrieb Chris Angelico: > On Tue, Sep 13, 2016 at 8:01 PM, Antoon Pardon > wrote: >>> >> Then python seems to be broken: >> >> ]]] a = range(3) >> ]]] old_a = a >> ]]] a += [8, 13] >> ]]] id(a), id(old_a) >> (140062018784792, 140062018784792) >> ]]] a, old_a >> ([0, 1, 2, 8, 13], [0, 1, 2, 8, 13]) > > A range object is not a tuple. Nor (since you were probably running > this in Python 2) is a list. > Not probably, certainly (if it wasn't Python 1): Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> a = range(3) >>> a += [8, 13] Traceback (most recent call last): File "", line 1, in a += [8, 13] TypeError: unsupported operand type(s) for +=: 'range' and 'list' >>> From nulla.epistola at web.de Tue Sep 13 06:42:48 2016 From: nulla.epistola at web.de (Sibylle Koczian) Date: Tue, 13 Sep 2016 12:42:48 +0200 Subject: How to extend a tuple of tuples? In-Reply-To: References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> <57D7AA01.4030101@rece.vub.ac.be> <57D7CE70.8090300@rece.vub.ac.be> Message-ID: <0c4a3b50-543e-4d78-22c0-8ae5f375b2f6@web.de> Am 13.09.2016 um 12:09 schrieb Chris Angelico: > On Tue, Sep 13, 2016 at 8:01 PM, Antoon Pardon > wrote: >>> >> Then python seems to be broken: >> >> ]]] a = range(3) >> ]]] old_a = a >> ]]] a += [8, 13] >> ]]] id(a), id(old_a) >> (140062018784792, 140062018784792) >> ]]] a, old_a >> ([0, 1, 2, 8, 13], [0, 1, 2, 8, 13]) > > A range object is not a tuple. Nor (since you were probably running > this in Python 2) is a list. > Not probably, certainly (if it wasn't Python 1): Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> a = range(3) >>> a += [8, 13] Traceback (most recent call last): File "", line 1, in a += [8, 13] TypeError: unsupported operand type(s) for +=: 'range' and 'list' >>> From daiyueweng at gmail.com Tue Sep 13 07:06:16 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Tue, 13 Sep 2016 12:06:16 +0100 Subject: Expected type 'optional[bytes]' got 'str' instead Message-ID: Hi, I have the following piece of code, rootPath = os.path.abspath(__file__) rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0] PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit, Expected type 'optional[bytes]' got 'str' instead If I changed it to, rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit(b'\\', 1)[0] Python game me errors, TypeError: Can't convert 'bytes' object to str implicitly How to fix it? cheers From rosuav at gmail.com Tue Sep 13 07:13:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 21:13:36 +1000 Subject: Expected type 'optional[bytes]' got 'str' instead In-Reply-To: References: Message-ID: On Tue, Sep 13, 2016 at 9:06 PM, Daiyue Weng wrote: > Hi, I have the following piece of code, > > rootPath = os.path.abspath(__file__) > > rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0] > > > PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit, > > Expected type 'optional[bytes]' got 'str' instead > Well, the first thing I'd do is use os.path.split instead of rsplit :) Or alternatively, os.path.join using dot-dot. And if that's not sufficient, I'd reach for pathlib. Whichever way I do it, I would *not* mix bytes paths and str paths. ChrisA From rosuav at gmail.com Tue Sep 13 07:26:41 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Sep 2016 21:26:41 +1000 Subject: Expected type 'optional[bytes]' got 'str' instead In-Reply-To: References: Message-ID: On Tue, Sep 13, 2016 at 9:19 PM, Daiyue Weng wrote: > Could you give me an example of doing this using os.path.split and > os.path.join? > > thanks Sure, but I'm keeping this on list. os.path.split basically does the same thing you do. # maintaining your non-PEP-8 names rootPath = os.path.abspath(__file__) rootPath = os.path.split(os.path.split(rootPath)[0])[0] os.path.join simply joins pieces together, so you could join a couple of ".." to your path. rootPath = os.path.abspath(os.path.join(__file__, "..", "..")) Advantage: They don't depend on backslashes in file paths, so they'll work on all platforms. ChrisA From __peter__ at web.de Tue Sep 13 07:37:35 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 13 Sep 2016 13:37:35 +0200 Subject: Expected type 'optional[bytes]' got 'str' instead References: Message-ID: Daiyue Weng wrote: > Hi, I have the following piece of code, > > rootPath = os.path.abspath(__file__) > > rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0] > > > PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit, > > Expected type 'optional[bytes]' got 'str' instead > > > If I changed it to, > > rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit(b'\\', 1)[0] > > Python game me errors, > > TypeError: Can't convert 'bytes' object to str implicitly > > How to fix it? Do you use Python 2 or 3? Is your version the one PyCharm expects and supports? If yes, consider filing a bug report (for PyCharm, not Python). You should of course still follow Chris' advice and use os.path to manipulate file paths. From __peter__ at web.de Tue Sep 13 07:39:43 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 13 Sep 2016 13:39:43 +0200 Subject: Global variable is undefined at the module level References: Message-ID: Daiyue Weng wrote: > Hi, I defined a global variable in some function like this, > > def some_function(self): > > global global_var > > PyCharm inspection gave me, > > Global variable is undefined at the module level There is no single way to silence that complaint and actually improve your code; you have to provide some context: Why do you need a global at all, why can't you (or don't want to) bind it on the module level etc. From ned at nedbatchelder.com Tue Sep 13 07:47:29 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 13 Sep 2016 04:47:29 -0700 (PDT) Subject: Global variable is undefined at the module level In-Reply-To: References: Message-ID: On Tuesday, September 13, 2016 at 6:42:56 AM UTC-4, Daiyue Weng wrote: > Hi, I defined a global variable in some function like this, > > def some_function(self): > > global global_var > > PyCharm inspection gave me, > > Global variable is undefined at the module level > > How to fix this? It probably wants you to have a line at the top-level of the module (outside of any function) defining the variable: global_var = None # or some other default value --Ned. From dieter at handshake.de Tue Sep 13 07:50:10 2016 From: dieter at handshake.de (dieter) Date: Tue, 13 Sep 2016 13:50:10 +0200 Subject: Global variable is undefined at the module level References: Message-ID: <87twdk2f4d.fsf@handshake.de> Daiyue Weng writes: > Hi, I defined a global variable in some function like this, > > def some_function(self): > > global global_var > > PyCharm inspection gave me, > > Global variable is undefined at the module level > > How to fix this? You define the global variable at the module level. "global VVV" (in a function) actually does not define "VVV" as a global variable. Instead, it tells the interpreter that "VVV" should not be treated as a local variable but be looked up in the "global" (usually module) namespace. In order to define "VVV", you must assign a value to it -- either directly in the "global" (i.e. module) namespace or in your function (together with a "global VVV" declaration). From random832 at fastmail.com Tue Sep 13 10:26:40 2016 From: random832 at fastmail.com (Random832) Date: Tue, 13 Sep 2016 10:26:40 -0400 Subject: How to extend a tuple of tuples? In-Reply-To: References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> Message-ID: <1473776800.2407510.724346369.6CBC755F@webmail.messagingengine.com> On Mon, Sep 12, 2016, at 17:29, Chris Angelico wrote: > old_id = id(a) > a += something > if id(a) == old_id: > print("We may have an optimization, folks!") > > But that can have false positives. If two objects do not concurrently > exist, they're allowed to have the same ID number. But the two objects do concurrently exist, from the time __iadd__ is evaluated until the time when a is assigned, in the formal semantics of this code. Allowing them to not concurrently exist is, effectively, precisely the optimization being discussed. From daiyueweng at gmail.com Tue Sep 13 12:34:14 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Tue, 13 Sep 2016 17:34:14 +0100 Subject: Python inner function parameter shadowed Message-ID: Hi, I am using inner function like this, def timeit(func=None, loops=1, verbose=False): if func is not None: def inner(*args, **kwargs): # some code return inner else: def partial_inner(func): return timeit(func, loops, verbose) return partial_inner PyCharm warns about "Shadows name 'func' from outer scope" on def partial_inner(func): How to fix it? cheers From rosuav at gmail.com Tue Sep 13 12:40:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Sep 2016 02:40:25 +1000 Subject: Python inner function parameter shadowed In-Reply-To: References: Message-ID: On Wed, Sep 14, 2016 at 2:34 AM, Daiyue Weng wrote: > Hi, I am using inner function like this, > > def timeit(func=None, loops=1, verbose=False): > if func is not None: > def inner(*args, **kwargs): > > # some code > > return inner > else: > def partial_inner(func): > return timeit(func, loops, verbose) > > return partial_inner > > > PyCharm warns about "Shadows name 'func' from outer scope" on > > def partial_inner(func): > > How to fix it? > > cheers Hmm. I think the real solution here is to separate this into two functions: def timeit(func, loops=1, verbose=False): def inner(*args, **kwargs): # some code return inner def timeit_nofunc(loops=1, verbose=False): def partial_inner(func): return timeit(func, loops, verbose) return partial_inner But without knowing more about what you're accomplishing, I can't really say. If you just want a quick fix to shut the linter up (note that this is NOT a Python error, it's just a message from a linter), you could use a different name for one of the variables. ChrisA From 007brendan at gmail.com Tue Sep 13 14:28:38 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Tue, 13 Sep 2016 11:28:38 -0700 Subject: Python inner function parameter shadowed In-Reply-To: References: Message-ID: This looks like a decorator function that optionally accepts arguments to change the behavior. You can safely ignore the warning form PyCharm. the variable won't be shadowed it's included in the function signature of the inner function. A lot of times, the outside decorator will just use the *args or **kwargs parameters and check whether the first arg is callable or not and if any keywords have been passed in to decide which version of the wrapped function to return Here is an example: http://stackoverflow.com/questions/653368/how-to-create-a-python-decorator-that-can-be-used-either-with-or-without-paramet On Tue, Sep 13, 2016 at 9:40 AM, Chris Angelico wrote: > On Wed, Sep 14, 2016 at 2:34 AM, Daiyue Weng wrote: > > Hi, I am using inner function like this, > > > > def timeit(func=None, loops=1, verbose=False): > > if func is not None: > > def inner(*args, **kwargs): > > > > # some code > > > > return inner > > else: > > def partial_inner(func): > > return timeit(func, loops, verbose) > > > > return partial_inner > > > > > > PyCharm warns about "Shadows name 'func' from outer scope" on > > > > def partial_inner(func): > > > > How to fix it? > > > > cheers > > Hmm. I think the real solution here is to separate this into two functions: > > def timeit(func, loops=1, verbose=False): > def inner(*args, **kwargs): > > # some code > > return inner > > def timeit_nofunc(loops=1, verbose=False): > def partial_inner(func): > return timeit(func, loops, verbose) > return partial_inner > > But without knowing more about what you're accomplishing, I can't > really say. If you just want a quick fix to shut the linter up (note > that this is NOT a Python error, it's just a message from a linter), > you could use a different name for one of the variables. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Tue Sep 13 14:31:57 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Sep 2016 04:31:57 +1000 Subject: Python inner function parameter shadowed In-Reply-To: References: Message-ID: On Wed, Sep 14, 2016 at 4:28 AM, Brendan Abel <007brendan at gmail.com> wrote: > This looks like a decorator function that optionally accepts arguments to > change the behavior. Oh, I get it. So, yeah, it is one function doing two jobs - legitimately. In that case, I'd just rename one of the 'func' arguments - probably the inner one, since that's never going to be passed as a keyword. ChrisA From 007brendan at gmail.com Tue Sep 13 14:52:27 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Tue, 13 Sep 2016 11:52:27 -0700 Subject: Python inner function parameter shadowed In-Reply-To: References: Message-ID: Yeah, you could change the name, but it shouldn't matter, the "func" in the inner function will always be the one passed into it, it won't be the "func" from the outer function, which in this specific case, would always be None (at least as far as the second inner function is concerned.) On Tue, Sep 13, 2016 at 11:31 AM, Chris Angelico wrote: > On Wed, Sep 14, 2016 at 4:28 AM, Brendan Abel <007brendan at gmail.com> > wrote: > > This looks like a decorator function that optionally accepts arguments to > > change the behavior. > > Oh, I get it. So, yeah, it is one function doing two jobs - > legitimately. In that case, I'd just rename one of the 'func' > arguments - probably the inner one, since that's never going to be > passed as a keyword. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From martinjp376 at gmail.com Tue Sep 13 16:08:37 2016 From: martinjp376 at gmail.com (kerbingamer376) Date: Tue, 13 Sep 2016 13:08:37 -0700 (PDT) Subject: Tkinter file dialog screwed Message-ID: <84022fec-6f58-4c0b-b2fe-6e67c6496e9c@googlegroups.com> The tkinter file dialog is, for me, unusable. Whenever I try to use it, it opens, but all the text is white on a white background (see this http://xomf.com/qzhgy) making it unusable. This has happened on 2 linux systems, both KDE plasma 5. Any help? From auriocus at gmx.de Tue Sep 13 16:37:55 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 13 Sep 2016 22:37:55 +0200 Subject: Tkinter file dialog screwed In-Reply-To: <84022fec-6f58-4c0b-b2fe-6e67c6496e9c@googlegroups.com> References: <84022fec-6f58-4c0b-b2fe-6e67c6496e9c@googlegroups.com> Message-ID: Am 13.09.16 um 22:08 schrieb kerbingamer376: > The tkinter file dialog is, for me, unusable. Whenever I try to use > it, it opens, but all the text is white on a white background (see > this http://xomf.com/qzhgy) making it unusable. This has happened on > 2 linux systems, both KDE plasma 5. Any help? Never seen that. This dialog is implemented in Tcl under X11, so maybe somebody from over there can help. I can imagine that it is a strange setting for colours in the option database. In your screenshot, I can see the file names in a very bright grey colour. bin, probably selected, is black. If you use the arrow keys to navigate the files, does it "highlight" the current item in black? Best regards, Christian From martinjp376 at gmail.com Tue Sep 13 16:45:10 2016 From: martinjp376 at gmail.com (martinjp376 at gmail.com) Date: Tue, 13 Sep 2016 13:45:10 -0700 (PDT) Subject: Tkinter file dialog screwed In-Reply-To: References: <84022fec-6f58-4c0b-b2fe-6e67c6496e9c@googlegroups.com> Message-ID: <5d9869b8-36f9-4d3d-b1f6-f3fa8fb78433@googlegroups.com> yes, I can make the labels turn black by selecting them with the arrow keys. From rgrigonis at gmail.com Tue Sep 13 16:57:05 2016 From: rgrigonis at gmail.com (rgrigonis at gmail.com) Date: Tue, 13 Sep 2016 13:57:05 -0700 (PDT) Subject: Why don't we call the for loop what it really is, a foreach loop? Message-ID: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> It would help newbies and prevent confusion. From PointedEars at web.de Tue Sep 13 17:08:11 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 13 Sep 2016 23:08:11 +0200 Subject: How to extend a tuple of tuples? References: <85k2elr028.fsf@benfinney.id.au> <2349538.mvXUDI8C0e@PointedEars.de> Message-ID: <8993182.nUPlyArG6x@PointedEars.de> John Gordon wrote: > [?] Thomas 'PointedEars' Lahn [?] writes: It is supposed to be an attribution *line*, _not_ an attribution novel. >> >> The obvious way does not work - >> >> >> >> a += (5, 6) >> ^^^^^^ >> > Right, because a tuple is immutable. > >> How did you get that idea? It has been mutated in the very statement >> that you are quoting > > No. An entirely new tuple is created, and 'a' is rebound to it. The > existing tuple is not mutated. Indeed, | $ python3 | Python 3.4.4 (default, Apr 17 2016, 16:02:33) | [GCC 5.3.1 20160409] on linux | Type "help", "copyright", "credits" or "license" for more information. | >>> t = ((1, 2), (3, 4)) | >>> t.__repr__ | | >>> t += (5, 6), | >>> t.__repr__ | indicates that this is so. However, this argument is purely academic, as that rebinding happens would neither validate Ben?s argument nor invalidate mine: The result obtained without the trailing comma is not so ?because a tuple is immutable?, but because of how the expression RHS is parsed. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From malaclypse2 at gmail.com Tue Sep 13 17:17:28 2016 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 13 Sep 2016 17:17:28 -0400 Subject: Why don't we call the for loop what it really is, a foreach loop? In-Reply-To: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: On Tue, Sep 13, 2016 at 4:57 PM, wrote: > It would help newbies and prevent confusion. Are you asking why Guido didn't call it foreach back in 1989, or why the core developers don't change it now, 27 years later? I can't speak for the historical perspective, but I'm sure there's basically no chance that it will be changed now. It would be a totally backwards incompatible change, invalidate every tutorial and bit of python documentation that's been written over the last three decades, and break pretty much every python program that works today. In exchange, you get newbies who are a slightly less confused about for loops. That tradeoff isn't worth it. -- Jerry From ian.g.kelly at gmail.com Tue Sep 13 17:20:19 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 13 Sep 2016 15:20:19 -0600 Subject: Why don't we call the for loop what it really is, a foreach loop? In-Reply-To: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: On Tue, Sep 13, 2016 at 2:57 PM, wrote: > It would help newbies and prevent confusion. Ada uses "for". C++11 uses "for". Dart uses "for". Go uses "for". Groovy uses "for". Java uses "for". JavaScript uses "for". MATLAB uses "for". Objective-C uses "for". Pasceal uses "for". Perl moved from "foreach" to just "for" in Perl 6. Ruby uses "for". Scala uses "for". Swift uses "for". Why do you think it's confusing that Python uses the same keyword in its foreach loops that all the above languages do? What mistake is this causing newbies to make? From srfpala at gmail.com Tue Sep 13 17:59:58 2016 From: srfpala at gmail.com (srfpala at gmail.com) Date: Tue, 13 Sep 2016 14:59:58 -0700 (PDT) Subject: DLL Error from a beginner Message-ID: <649c8095-485d-4f22-aea8-6e0992cf7bdb@googlegroups.com> Running Pyscripter and Python version 2.7.12 on Win10 Home on a 64bit Laptop 1. A simple Python application runs successfully. 2. WxPython(wxPython3.0-win64-3.0.2.0-py27(1).exe executed successfully 3. To the simple app above, I add import wx and an Error Dialog occurs: ImportError: DLL load failed: %1 is not a valid 32 application If I see win64 in the exe filename I think I have the correct wxPython install. What have a done wrong ? From grant.b.edwards at gmail.com Tue Sep 13 18:00:45 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 13 Sep 2016 22:00:45 +0000 (UTC) Subject: Why don't we call the for loop what it really is, a foreach loop? References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: On 2016-09-13, Ian Kelly wrote: > On Tue, Sep 13, 2016 at 2:57 PM, wrote: >> It would help newbies and prevent confusion. > > Ada uses "for". [a dozen or so other langages] > Swift uses "for". > > Why do you think it's confusing that Python uses the same keyword in > its foreach loops that all the above languages do? What mistake is > this causing newbies to make? One might guess that the OP is coming from PHP where there are separate "for" and "foreach" looping constructs, and Python's "for" is analogous to PHP's "foreach". That said, I despise PHP so thoroughly that "because PHP does it" is, to me, a pretty strong argument for _not_ doing something. Even trying to ignore my bias agains PHP, I can't see that Python's calling it "for" instead of "foreach" is going to confuse anybody with a PHP background... -- Grant Edwards grant.b.edwards Yow! I have accepted at Provolone into my life! gmail.com From irmen.NOSPAM at xs4all.nl Tue Sep 13 18:32:25 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 14 Sep 2016 00:32:25 +0200 Subject: DLL Error from a beginner In-Reply-To: <649c8095-485d-4f22-aea8-6e0992cf7bdb@googlegroups.com> References: <649c8095-485d-4f22-aea8-6e0992cf7bdb@googlegroups.com> Message-ID: <57d87e7a$0$926$e4fe514c@news.xs4all.nl> On 13-9-2016 23:59, srfpala at gmail.com wrote: > Running Pyscripter and Python version 2.7.12 on Win10 Home on a 64bit Laptop > 1. A simple Python application runs successfully. > 2. WxPython(wxPython3.0-win64-3.0.2.0-py27(1).exe executed successfully > 3. To the simple app above, I add import wx and an Error Dialog occurs: > ImportError: DLL load failed: %1 is not a valid 32 application > If I see win64 in the exe filename I think I have the correct wxPython install. > What have a done wrong ? > Is your python installation itself of the 64-bit kind? Otherwise, you have to install the 32 bits wxpython library rather than the 64 bits one you showed us above. (Or switch to a 64 bit python implementation) Irmen From PointedEars at web.de Tue Sep 13 19:16:52 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 14 Sep 2016 01:16:52 +0200 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> Message-ID: <6586097.EvYhyI6sBW@PointedEars.de> Chris Angelico wrote: > [?] Thomas 'PointedEars' Lahn [?] wrote: >> If I knew that it is always going to be a list or a tuple, I would check >> its length instead: >> >> if len(errors) == 0: > > I wouldn't. I'd use boolification here too. Only if I had to > distinguish between None, [], and [1,2,3], would I use a more explicit > check (and it wouldn't be "== []", it would be probing for None). Why (not)? -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From bc at freeuk.com Tue Sep 13 19:20:22 2016 From: bc at freeuk.com (BartC) Date: Wed, 14 Sep 2016 00:20:22 +0100 Subject: Why don't we call the for loop what it really is, a foreach loop? In-Reply-To: References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: On 13/09/2016 22:20, Ian Kelly wrote: > On Tue, Sep 13, 2016 at 2:57 PM, wrote: >> It would help newbies and prevent confusion. > > Ada uses "for". > C++11 uses "for". > Dart uses "for". > Go uses "for". > Groovy uses "for". > Java uses "for". > JavaScript uses "for". > MATLAB uses "for". > Objective-C uses "for". > Pasceal uses "for". > Perl moved from "foreach" to just "for" in Perl 6. > Ruby uses "for". > Scala uses "for". > Swift uses "for". And Fortran uses "do". My own language uses "for", "forall" and "foreach". (Apparently PHP also has a choice, according to another post.) "for" only iterates over an integer sequence. "forall" over the values in an object (such as a list), similar to Python. (And "foreach" breaks apart certain kinds of object, such as the bits in an integer, and iterates over those). Probably "for", "forall" and "foreach" could be combined (perhaps with a conversion to drive the the kind of iteration desired), but I think it's useful to see "for" and /know/ it's a basic loop. It also makes it easier to optimise, as well as allowing a stripped-down version that only counts, or repeats forever). Value Iterates over: For: Forall: Foreach: 1..3 1,2,3 1,2,3 -- (10,20,30) 1,2,3 10,20,30 -- "ABC" 1,2,3 "A","B","C" 65,66,67 (works with both) 100 0,1,2...63 -- 0,0,1,0,0,1,1,0,...0 Getting back to Python, it only has one kind of for-loop and it has decided to call it "for". It's just one minor thing (among many) that has to be learned. -- Bartc From rosuav at gmail.com Tue Sep 13 19:57:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Sep 2016 09:57:48 +1000 Subject: Expression can be simplified on list In-Reply-To: <6586097.EvYhyI6sBW@PointedEars.de> References: <10685671.O9o76ZdvQC@PointedEars.de> <6586097.EvYhyI6sBW@PointedEars.de> Message-ID: On Wed, Sep 14, 2016 at 9:16 AM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> [?] Thomas 'PointedEars' Lahn [?] wrote: >>> If I knew that it is always going to be a list or a tuple, I would check >>> its length instead: >>> >>> if len(errors) == 0: >> >> I wouldn't. I'd use boolification here too. Only if I had to >> distinguish between None, [], and [1,2,3], would I use a more explicit >> check (and it wouldn't be "== []", it would be probing for None). > > Why (not)? It's more Pythonic and faster. And shorter. What's not to love? ChrisA From steve+python at pearwood.info Tue Sep 13 21:14:01 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 14 Sep 2016 11:14:01 +1000 Subject: Tkinter file dialog screwed References: <84022fec-6f58-4c0b-b2fe-6e67c6496e9c@googlegroups.com> Message-ID: <57d8a45a$0$22140$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 Sep 2016 06:08 am, kerbingamer376 wrote: > The tkinter file dialog is, for me, unusable. Whenever I try to use it, it > opens, but all the text is white on a white background (see this > http://xomf.com/qzhgy) making it unusable. This has happened on 2 linux > systems, both KDE plasma 5. Any help? What happens if you change your KDE theme, or use another desktop environment? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 13 21:18:32 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 14 Sep 2016 11:18:32 +1000 Subject: Why don't we call the for loop what it really is, a foreach loop? References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: <57d8a569$0$1606$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 Sep 2016 06:57 am, rgrigonis at gmail.com wrote: > It would help newbies and prevent confusion. No it wouldn't. Claims-which-are-made-without-evidence-can-be-rejected-without-evidence-ly y'rs, -- Steve From lawrencedo99 at gmail.com Tue Sep 13 22:16:56 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 13 Sep 2016 19:16:56 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> Message-ID: On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: > Why do you object to the type conversion to bool? It would be better if all such conversions were explicit, e.g. if bool(?non-bool expr?) : if not bool(?non-bool expr?) : instead of if ?non-bool expr? : if not ?non-bool expr? : From ben+python at benfinney.id.au Tue Sep 13 22:25:15 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 14 Sep 2016 12:25:15 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> Message-ID: <8560pzqktw.fsf@benfinney.id.au> Lawrence D?Oliveiro writes: > On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: > > Why do you object to the type conversion to bool? > > It would be better if all such conversions were explicit Why? It's entirely unambiguous: the expression of an ?if? statement *can only be* evaluated in a Boolean context. What else could the reader reasonably expect? -- \ ?When I was a baby I kept a diary. Recently I was re-reading | `\ it, it said ?Day 1: Still tired from the move. Day 2: Everybody | _o__) talks to me like I'm an idiot.?? ?Steven Wright | Ben Finney From lawrencedo99 at gmail.com Tue Sep 13 23:58:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 13 Sep 2016 20:58:10 -0700 (PDT) Subject: Python inner function parameter shadowed In-Reply-To: References: Message-ID: <58d55cac-0469-4c26-8c1c-edf3fc63301c@googlegroups.com> On Wednesday, September 14, 2016 at 4:34:34 AM UTC+12, Daiyue Weng wrote: > PyCharm warns about "Shadows name 'func' from outer scope" Typical piece of software trying to be too helpful and just getting in the way. Can you turn off such warnings? From rosuav at gmail.com Tue Sep 13 23:58:41 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Sep 2016 13:58:41 +1000 Subject: Expression can be simplified on list In-Reply-To: <8560pzqktw.fsf@benfinney.id.au> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> Message-ID: On Wed, Sep 14, 2016 at 12:25 PM, Ben Finney wrote: > Lawrence D?Oliveiro writes: > >> On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: >> > Why do you object to the type conversion to bool? >> >> It would be better if all such conversions were explicit > > Why? It's entirely unambiguous: the expression of an ?if? statement *can > only be* evaluated in a Boolean context. What else could the reader > reasonably expect? Error: Logical value not 0 or 1 That's what REXX would say if you used anything else in a boolean context. Improvement? You be the judge. ChrisA From lawrencedo99 at gmail.com Tue Sep 13 23:59:30 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 13 Sep 2016 20:59:30 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> Message-ID: On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: > Lawrence D?Oliveiro writes: > > > It would be better if all such conversions were explicit > > Why? It's entirely unambiguous ... From steve+comp.lang.python at pearwood.info Wed Sep 14 00:38:58 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 14 Sep 2016 14:38:58 +1000 Subject: Python reverse debugger Message-ID: <57d8d463$0$2904$c3e8da3$76491128@news.astraweb.com> PyPy has recently released a reverse debugger for Python: https://mail.python.org/pipermail/pypy-dev/2016-September/014661.html Armin Rigo wrote: [quote] It is my pleasure to announce the first beta release of RevDB: a "reverse debugger" for Python. A reverse debugger is a debugger where you can go forward and backward in time. RevDB is designed to track down the annoying, hard-to- reproduce bug in your Python program. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From ben+python at benfinney.id.au Wed Sep 14 00:40:20 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 14 Sep 2016 14:40:20 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> Message-ID: <851t0nqekr.fsf@benfinney.id.au> Lawrence D?Oliveiro writes: > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: > > Lawrence D?Oliveiro writes: > > > > > It would be better if all such conversions were explicit > > > > Why? It's entirely unambiguous: the expression of an ?if? statement > > *can only be* evaluated in a Boolean context. What else could the > > reader reasonably expect? > > That reference supports my position: The only reasonable interpretation of the expression specified to ?if?, is that it is interpreted in a Boolean context. The behaviour described there was a bug. Once recognised, it was fixed. There isn't any other reasonable interpretation of the expression for ?if?: it's interpreted as a Boolean value. -- \ ?The best mind-altering drug is truth.? ?Jane Wagner, via Lily | `\ Tomlin | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Wed Sep 14 00:47:15 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 14 Sep 2016 14:47:15 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> Message-ID: <57d8d655$0$11116$c3e8da3@news.astraweb.com> On Wednesday 14 September 2016 12:16, Lawrence D?Oliveiro wrote: > On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: >> Why do you object to the type conversion to bool? > > It would be better if all such conversions were explicit, e.g. > > if bool(?non-bool expr?) : > if not bool(?non-bool expr?) : > > instead of > > if ?non-bool expr? : > if not ?non-bool expr? : Better according to what standard? According to statically-typed languages, it's not just better, but probably essential, to explicitly cast or coerce values to bool. But according to dynamically-typed languages like Python, using the second pair of examples is just duck-typing, where all values and objects can "quack like a bool". There's no need to explicitly cast an expression to bool, because the interpreter can do it for you as part of the truthiness protocol. Needing explicit casts, as you do, is as silly as these would be: for obj in iter(expression): ... # hypothetical built-in to convert methods to callables result = callable(myobj.method)(arg) only *even more so*, since implicit truthiness is expected to always succeed, while iter() is not. You're perfectly entitled to dislike duck-typed truthiness. But that makes the majority of dynamically-typed languages (like Python, Javascript, Ruby, Lua and more) a bad fit for your way of thinking. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From jussi.piitulainen at helsinki.fi Wed Sep 14 00:47:26 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 14 Sep 2016 07:47:26 +0300 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> Message-ID: Lawrence D?Oliveiro writes: > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: >> Lawrence D?Oliveiro writes: >> >> > It would be better if all such conversions were explicit >> >> Why? It's entirely unambiguous ... > > That's the story of a time object t being false around midnight UTC, because the class defined it to be so. What would bool(t) be? From steve+comp.lang.python at pearwood.info Wed Sep 14 00:53:01 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 14 Sep 2016 14:53:01 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> Message-ID: <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> On Wednesday 14 September 2016 13:59, Lawrence D?Oliveiro wrote: > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: >> Lawrence D?Oliveiro writes: >> >> > It would be better if all such conversions were explicit >> >> Why? It's entirely unambiguous ... > > *shrug* And if somebody designed an iterator that behaved badly or surprisingly, would you conclude that the entire concept of iteration is therefore broken? The midnight gotcha was (it has now been fixed) a design bug of the class. As simple as that. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From steve+comp.lang.python at pearwood.info Wed Sep 14 01:22:35 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 14 Sep 2016 15:22:35 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> Message-ID: <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> On Monday 12 September 2016 12:26, Chris Angelico wrote: > On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D?Oliveiro > wrote: >> On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: >>> I have some _extremely_ strong views about absolutes (they come from the >>> Creator of the Universe) ... >> >> By ?Universe? do you mean ?everything that exists?? So if the Creator >> exists, then the Creator, too, must be part of the Universe. >> >> So whoever created the Universe also created the Creator... > > No, God isn't part of the universe, any more than an author is part of > his novel. Tell that to Dante Alighieri. Some more recent examples include Stephen King and Philip K Dick. But in any case, a novel is not "everything that exists", unlike the universe. The maker of a sandwich is not part of the sandwich, but the universe has the boot-strap problem that the maker of the universe has to be part of the universe as well. In any case, even if we *define* the "the universe" in a more limited fashion ("just this solar system", "just this galaxy", "just the visible part of the universe", "the entire multi-verse except for the bit the maker lives in") and so exclude the maker, that doesn't imply anything else about the maker. We don't even know whether it is necessarily sentient, let alone someone/something benevolent that we should be taking moral absolutes from. Perhaps our universe is a mere side-effect or by-product of some purely unconscious action: our universe is the pearl to some interdimensional oyster. Maybe we're a simulation in a computer, run by the inter-dimensional equivalent of Sheldon from "Big Bang Theory". The idea that the maker of the universe is necessarily benevolent AND competent isn't obviously true: if it were, life would probably be much easier and more pleasant. On the other hand, the evidence doesn't support the idea that the maker of the universe is *actively* malevolent either -- unless It, or They, simply haven't noticed us yet. Perhaps the gods do slumber in R'lyeh. But for the sake of the argument, let's agree that the universe needs a maker, but the maker doesn't. What follows logically from those (presumably) facts? We don't know if the maker is necessarily sentient; even if the maker is sentient, we don't know if it is aware of us; even if the maker is aware of us, we don't know if it is benevolent or malevolent or merely indifferent; even if benevolent, we don't know if it is benevolent towards individuals, personally, rather than towards creation overall; even if personal, we don't know what it is capable of doing (I can create a sandwich, but that doesn't mean I can stop it from growing old and stale and eventually rotting); even if capable, we don't know if it is motivated to do anything for us; even if motivated, we don't know if the maker is comprehensible to the human mind; even if comprehensible, we don't know if our ideas of what the maker must be like are correct. There is an awfully long leap from the reality of "the universe exists" to any of the of Atum/Ptah/El/Coatlicue/Ranginui/Vishnu/Yahweh/Pangu/Waheguru etc., regardless of which one you pick. (Unlike *our* divine revelation, which is clearly the truth, the whole truth, and nothing but the truth, *their* divine revolution is illusion, error and lies. All of the gods are myth and superstition, except for the One True God that conveniently has revealed himself to us rather than our enemies, who are pagans and heretics the lot of them.) -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From greg.ewing at canterbury.ac.nz Wed Sep 14 02:24:09 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 14 Sep 2016 18:24:09 +1200 Subject: [Python-ideas] Inconsistencies In-Reply-To: <87vay1uusd.fsf@elektro.pacujo.net> References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <050ce089-66a9-a5cc-451d-848cb103cbec@harvee.org> <87vay1uusd.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > It has been prophesied that God will > eventually write a Version 2 of the universe which will have most of the > known glitches in Version 1 fixed. Well, He did release a Religion 2.0 and sent His son to install it, but some users resisted the upgrade and crucified him before it could be fully deployed. There are still problems to this day due to incompatible versions in use. -- Greg From christopher_reimer at icloud.com Wed Sep 14 02:31:05 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Tue, 13 Sep 2016 23:31:05 -0700 Subject: Python inner function parameter shadowed In-Reply-To: <58d55cac-0469-4c26-8c1c-edf3fc63301c@googlegroups.com> References: <58d55cac-0469-4c26-8c1c-edf3fc63301c@googlegroups.com> Message-ID: <0D9E3B12-CD55-459A-935C-32B30A7EF4A2@icloud.com> > On Sep 13, 2016, at 8:58 PM, Lawrence D?Oliveiro wrote: > >> On Wednesday, September 14, 2016 at 4:34:34 AM UTC+12, Daiyue Weng wrote: >> PyCharm warns about "Shadows name 'func' from outer scope" > > Typical piece of software trying to be too helpful and just getting in the way. > > Can you turn off such warnings? IIRC, if you turn off this warning, it also turns off a more useful warning somewhere else. My favorite PyCharm warning bug is creating a base class with an implemented getter and an unimplemented setter. When the base class is inherited and the setter is implemented, the IDE warns that the getter is missing. The workaround is to implement the getter with a super call. This bug is several years old and no one had fixed it because it has workaround. Chris R. From lawrencedo99 at gmail.com Wed Sep 14 02:45:51 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 13 Sep 2016 23:45:51 -0700 (PDT) Subject: [Python-ideas] Inconsistencies In-Reply-To: References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> Message-ID: On Monday, September 12, 2016 at 2:26:21 PM UTC+12, Chris Angelico wrote: > On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D?Oliveiro wrote: >> On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote: >>> I have some _extremely_ strong views about absolutes (they come from the >>> Creator of the Universe) ... >> >> By ?Universe? do you mean ?everything that exists?? So if the Creator >> exists, then the Creator, too, must be part of the Universe. >> >> So whoever created the Universe also created the Creator... > > No, God isn't part of the universe, any more than an author is part of > his novel. So if ?Universe? does not mean ?everything that exists?, then there would be things that exist, that God did not create... From rustompmody at gmail.com Wed Sep 14 02:54:24 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 13 Sep 2016 23:54:24 -0700 (PDT) Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> Message-ID: <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> On Wednesday, September 14, 2016 at 10:52:48 AM UTC+5:30, Steven D'Aprano wrote: > (Unlike *our* divine revelation, which is clearly the truth, the whole truth, > and nothing but the truth, *their* divine revolution is illusion, error and > lies. All of the gods are myth and superstition, except for the One True God > that conveniently has revealed himself to us rather than our enemies, who are > pagans and heretics the lot of them.) The piquant situation of being human is that 20/20 vision is always available ? at least as hindsight. The bible more of less describes the world as a few hundred kms east/west of Eden. By most modern accounts this is wrong. So were the authors fools? Would you or I have done better? Newton painstakingly calculated the age of the universe to be about 6000 years BC by counting biblical generations. Questions similar to the above Amerigo Vespucci asked if the wondrous animals he saw in the new world were on Noah's ark. Was he a religious nut? Was he even specially religious? Or just functioning under the pervasive assumptions of his age? These seem like rhetorical questions. Yet we remain cocksure of our assumtions inspite of the repeated data that everything we know will be negated in 5-50-500 years Lord Kelvin said that physics was a closed project -- everything had been discovered.. Just a few universal constants needed to be measured to increased accuracy This was before relativity, quantum physics, stellar spectroscopy etc etc And then Max Planck discovered (the precursors to) quantum physics And he remained a staunch classicist his whole life Wishing and believing that vile genie he had unwittingly unleashed would somehow or other be re-bottled And Knuth wept that the CS that he largely created is historicized in a different sense than he envisaged: http://cacm.acm.org/magazines/2015/1/181633-the-tears-of-donald-knuth/abstract My dear gpa to the end of his life would say: ?You guys can keep believing and worshipping who you like For me the greatest is Socrates who said: ?The one thing of which I am 100% certain is that I do not know.? ? From rustompmody at gmail.com Wed Sep 14 03:16:06 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 14 Sep 2016 00:16:06 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> Message-ID: On Wednesday, September 14, 2016 at 10:23:12 AM UTC+5:30, Steven D'Aprano wrote: > On Wednesday 14 September 2016 13:59, Lawrence D?Oliveiro wrote: > > > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: > >> Lawrence D?Oliveiro writes: > >> > >> > It would be better if all such conversions were explicit > >> > >> Why? It's entirely unambiguous ... > > > > > > > *shrug* > > And if somebody designed an iterator that behaved badly or surprisingly, would > you conclude that the entire concept of iteration is therefore broken? > > The midnight gotcha was (it has now been fixed) a design bug of the class. As > simple as that. Quite the contrary I showed if you remember that for regular expressions, dfas, graphs the questions of when is one of these falsey is highly non-trivial. In more general terms: For complex data-types, the exact specific nature of which is ?trivial? may be a highly non-trivial question. About the python builtins ? list, tuple, string, dict ? for which these questions seem straightforward and obvious: In Haskell there is a type-class called Functor which informally corresponds to collection type. More formally for a type to be a functorial type it needs too have a binary op and a constant. For python lists it would be +, [] For sets ?|? (union ie ??? ) and ? etc satisfying some mathematical properties which (being a bit fast and loose) say that the operation, element need to be monoidal ie the operation needs to be associative and element needs to be its identity In THOSE TYPES that element can justifiably serve as a falsey (empty) type However to extrapolate from here and believe that ALL TYPES can have a falsey value meaningfully, especially in some obvious fashion, is mathematically nonsense. Mathematical gobbledygook of no interest? Ok here?s a tl;dr 1. Go back to this post?s OP. Is it not an authentic question? 2. Is something like it not a FAQ? From steve+comp.lang.python at pearwood.info Wed Sep 14 03:20:39 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 14 Sep 2016 17:20:39 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> Message-ID: <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> On Wednesday 14 September 2016 16:54, Rustom Mody wrote: > everything we know will be negated in 5-50-500 years I'm pretty sure that in 5, 50, 500 or even 5000 years, the sun will still rise in the east, water will be wet, fire will burn, dogs will have mammary glands and frogs[1] won't, and the square root of 100 will still be 10. Isaac Asimov once wrote: When people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm [1] Assuming that there are any frogs left by then. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From rustompmody at gmail.com Wed Sep 14 03:24:05 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 14 Sep 2016 00:24:05 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: <57d8d655$0$11116$c3e8da3@news.astraweb.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <57d8d655$0$11116$c3e8da3@news.astraweb.com> Message-ID: On Wednesday, September 14, 2016 at 10:17:27 AM UTC+5:30, Steven D'Aprano wrote: > You're perfectly entitled to dislike duck-typed truthiness. But that makes the > majority of dynamically-typed languages (like Python, Javascript, Ruby, Lua and > more) a bad fit for your way of thinking. Yes and No Here is elisp, one more such dynamic language: Here is the docs for null and not: null is a built-in function in `C source code'. (null OBJECT) Return t if OBJECT is nil. null is a built-in function in `C source code'. (null OBJECT) Return t if OBJECT is nil. not is an alias for `null' in `subr.el'. (not OBJECT) Return t if OBJECT is nil. So null and not are the same function ie synonyms The result of this is that most of these kind of discussions are side-stepped even though the under-belly of lisp is quite like python: Just use not when you want to think in terms of bools and null when you want to think in terms of lists To be fair, this is the situation in lisp prior to scheme Scheme introduced #t and #f analogous to python 2.3(?) introducing True and False With all the attendant increased confusion from arcanity From steve+comp.lang.python at pearwood.info Wed Sep 14 03:30:03 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 14 Sep 2016 17:30:03 +1000 Subject: Python inner function parameter shadowed References: <58d55cac-0469-4c26-8c1c-edf3fc63301c@googlegroups.com> Message-ID: <57d8fc7c$0$1532$c3e8da3$5496439d@news.astraweb.com> On Wednesday 14 September 2016 13:58, Lawrence D?Oliveiro wrote: > On Wednesday, September 14, 2016 at 4:34:34 AM UTC+12, Daiyue Weng wrote: >> PyCharm warns about "Shadows name 'func' from outer scope" > > Typical piece of software trying to be too helpful and just getting in the > way. > > Can you turn off such warnings? Yes. It is the job of the linter to be pedantic and opinionated. A good linter will let you turn off warnings globally and locally, permanently and temporarily. I don't know how good PyCharm is, but you can certainly configure it to turn off selected warnings: https://www.jetbrains.com/help/pycharm/2016.1/disabling-and-enabling-inspections.html https://www.jetbrains.com/help/pycharm/2016.1/suppressing-inspections.html -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From lawrencedo99 at gmail.com Wed Sep 14 03:45:37 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 14 Sep 2016 00:45:37 -0700 (PDT) Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> References: <20160906163257.GX26300@ando.pearwood.info> <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> Message-ID: <658dc4c4-f0cc-4dfc-b83c-10e91ceeca2e@googlegroups.com> On Wednesday, September 14, 2016 at 6:54:39 PM UTC+12, Rustom Mody wrote: > Yet we remain cocksure of our assumtions inspite of the repeated data > that everything we know will be negated in 5-50-500 years Let?s see, 500 years ago, people knew * That the world is round, and how to measure its radius to within a third of a percent of the modern value * That the square root of 2 cannot be represented as an exact ratio of two integers * That objects float in water because their density is lower than that of water * That the optimum shape for a load-bearing arch is a catenary * That blood in the human body has to take the long way round--through the lungs--to get from one side of the heart to the other * That Roman numerals are a stupid way to do calculations. Have any of these been disproved yet? I?m not up with all these ?there is no objective reality, everything is relative? ideas as yet... From steve+comp.lang.python at pearwood.info Wed Sep 14 04:28:09 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 14 Sep 2016 18:28:09 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> Message-ID: <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> On Wednesday 14 September 2016 17:16, Rustom Mody wrote: > On Wednesday, September 14, 2016 at 10:23:12 AM UTC+5:30, Steven D'Aprano > wrote: >> And if somebody designed an iterator that behaved badly or surprisingly, >> would you conclude that the entire concept of iteration is therefore broken? >> >> The midnight gotcha was (it has now been fixed) a design bug of the class. >> As simple as that. > > Quite the contrary > I showed if you remember that for regular expressions, dfas, graphs > the questions of when is one of these falsey is highly non-trivial. No, you *claimed* to have done so, but you actually didn't. I'm not sure if it makes sense to talk about an "empty regular expression", or if that is the same as re.compile(''). Presumably if such a thing makes sense, it would match nothing, from any input at all. If so, that could be falsey and all non-empty regexes would be truthy. Or, since regexes aren't containers *or* numbers, you might prefer that all regexes are truthy. I don't mind which you pick neither view is fundamentally better than the other, and both are compatible with Python semantics. Decide according to what you think is most useful. If you can't decide, toss a coin. Likewise for DFAs. In neither case it is "highly non-trivial". Graphs, on the other hand, are trivial to decide: the empty or null graph, with no nodes at all, is falsey. All non-empty graphs are truthy. As graphs are containers, no other model makes sense in the context of Python. The problem of deciding whether a value should be considered truthy or falsey can be as simple or complex as the language designer likes. Python has a particularly simple rule, which makes the decision trivial in most circumstances. Other languages, perhaps not so much. On the other hand, there is at least one scenario where forcing a boolean notion of truthiness *is* fundamentally difficult: many-valued logic. Once you introduce more than two logical values ("True", "False", "Maybe" for example), it is hard to decide what some of the values should be treated as. For example, True clearly maps to boolean True, and False to boolean False; but what does Maybe map to? To paraphrase Billy Crystal's character in "The Princess Bride": Mostly false is a little bit true so to force the logical value "Maybe" into a True/False dichotomy will always require an element of arbitrary choice. https://en.wikipedia.org/wiki/Many-valued_logic > In more general terms: > For complex data-types, the exact specific nature of which is ?trivial? may > be a highly non-trivial question. Hypothetically? Sure. But in practice? No. The decision is simple: if your data type is a kind of container, then it should follow the rule that emptiness ? falsey. If it is a number, then zero is falsey. If it is a string of some sort, then the empty string is falsey. All else is truthy. If your data type has a clear and obvious dichotomy analogous to "something versus nothing", "non-empty versus empty", or equivalent, then that's your dividing line. If there is no such clear dichotomy, then perhaps all your values should be considered truthy. In practice, it should be rare that this is a hard decision to make. In theory, one can state that it is hard to make this decision, but actually coming up with an example where it is difficult is not simple. Perhaps the best example (apart from many-valued logic, discussed above) is in fact the "midnight" example. Although we use numbers to *represent* times, times are not themselves numbers. Unlike durations, you cannot add times: 3am plus 5pm is meaningless. So midnight, represented by the number zero, doesn't actually have the properties of number zero. It isn't the additive identity, nor the multiplicative nullity. To put it another way, unlike the integer 0 or float 0.0 or complex 0+0j, midnight is just another time, no different from all the other times. It is an artefact of the implementation that it was ever falsey. > However to extrapolate from here and believe that ALL TYPES can have a falsey > value meaningfully, especially in some obvious fashion, is mathematically > nonsense. Mathematically nonsense and practically sensible. It is easy to claim that there are types where it is hard to decide which values should be truthy and which falsey, but in practice apart from many-valued logics, it is *usually* easy to decide. Might there be exceptions? Of course. If you think that I've ever argued that there are never any exceptions, then you're arguing against a strawman. Its just that those exceptions are unusual: exceptional, difficult cases are *rare*. (In the Python std lib, with dozens of data types, there is only *one* where the choice of truthiness was controversial: abstract times of the day.) -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From Cecil at decebal.nl Wed Sep 14 04:30:39 2016 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 14 Sep 2016 10:30:39 +0200 Subject: %config PromptManager Message-ID: <87lgyulw7k.fsf@Equus.decebal.nl> In an ipy-file I have: %config PromptManager.in_template = r'[{time.strftime("%a, %d %b %T")} \u@\h:\Y1]\nIn [\#]: ' This works for ipython2, but gets ipython3 in an endless loop. At the moment I solved it with: if sys.version_info.major != 3: %config PromptManager.in_template = r'[{time.strftime("%a, %d %b %T")} \u@\h:\Y1]\nIn [\#]: ' But is there a way to do it both for ipython2 and ipython3? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Wed Sep 14 04:47:55 2016 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 14 Sep 2016 10:47:55 +0200 Subject: =?utf-8?Q?=E2=80=98pip2?= install =?utf-8?Q?cryptography=E2=80=99?= does not work Message-ID: <87h99ilves.fsf@Equus.decebal.nl> I try to do a: pip2 install cryptography But this give: gcc -pthread -shared build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o -L/usr/lib64 -lssl -lcrypto -lpython2.7 -o build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/_openssl.so /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC /usr/lib64/libpython2.7.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status error: command 'gcc' failed with exit status 1 ---------------------------------------- Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-QoMAwn/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-LxpwQ4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-QoMAwn/cryptography/ What is happening here and what can I do about it? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From p.f.moore at gmail.com Wed Sep 14 06:41:04 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 14 Sep 2016 11:41:04 +0100 Subject: [python-committers] [RELEASE] Python 3.6.0b1 is now available In-Reply-To: References: <942D57F5-BA76-49CB-B3DB-18E2D6F12AC4@python.org> Message-ID: On 14 September 2016 at 11:32, Serhiy Storchaka wrote: > On 13.09.16 02:35, Ned Deily wrote: >> >> On behalf of the Python development community and the Python 3.6 release >> team, I'm happy to announce the availability of Python 3.6.0b1. 3.6.0b1 >> is the first of four planned beta releases of Python 3.6, the next major >> release of Python, and marks the end of the feature development phase >> for 3.6. > > > There is no mention on https://www.python.org/news/. The last release mentioned there is 3.4.0rc1... Paul From storchaka at gmail.com Wed Sep 14 06:46:35 2016 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 14 Sep 2016 13:46:35 +0300 Subject: Expression can be simplified on list In-Reply-To: <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> Message-ID: On 14.09.16 11:28, Steven D'Aprano wrote: > I'm not sure if it makes sense to talk about an "empty regular expression", or > if that is the same as re.compile(''). Presumably if such a thing makes sense, > it would match nothing, from any input at all. Actually, it matches anything. re.compile('').match(x) returns non-false value for any valid x. From rosuav at gmail.com Wed Sep 14 07:40:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Sep 2016 21:40:38 +1000 Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Sep 14, 2016 at 8:46 PM, Serhiy Storchaka wrote: > On 14.09.16 11:28, Steven D'Aprano wrote: >> >> I'm not sure if it makes sense to talk about an "empty regular >> expression", or >> if that is the same as re.compile(''). Presumably if such a thing makes >> sense, >> it would match nothing, from any input at all. > > > Actually, it matches anything. re.compile('').match(x) returns non-false > value for any valid x. "Matches" has two meanings with a regex. The regular expression "[A-Za-z]*" matches the three Q's in "123QQQ456", and thus it successfully matches against that string. In the string "1234", the regex still successfully matches that string, but it finds nothing, ergo it matches an empty string in that string. Does a non-empty string contain an empty string? Well, in the sense that ("" in "spam") is true, yes, it does - but the empty string didn't match any of those characters. ChrisA From jussi.piitulainen at helsinki.fi Wed Sep 14 08:05:41 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 14 Sep 2016 15:05:41 +0300 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> Message-ID: Serhiy Storchaka writes: > On 14.09.16 11:28, Steven D'Aprano wrote: >> I'm not sure if it makes sense to talk about an "empty regular >> expression", or if that is the same as re.compile(''). Presumably if >> such a thing makes sense, it would match nothing, from any input at >> all. > > Actually, it matches anything. re.compile('').match(x) returns > non-false value for any valid x. It matches the empty string. The .match method returns a match object if the regex matches at the start of the input. See span: re.compile('').match('foo') ===> <_sre.SRE_Match object; span=(0, 0), match=''> There's an empty string at every position, same content, different span: re.compile('').findall('foo') ===> ['', '', '', ''] More mathematical treatments of regular expressions usually include a special expression that stands for the empty string, typically ? or ?, I've also seen ?, sometimes e -- my impression is that those sources tend to use small alphabets, often just two or three letters, so they can afford to give up e. Some ruminations follow, following Rustom's mathematical ruminations, related to extended regex software that has taken a rather different direction from the usual matching engines. Mathematical discussions tend to acknowledge only alternation (union), concatenation and iteration (Kleene star) as operations, unless they specifically focus on some other operations that can, in principle, be expressed in terms of those three. There are many such. Without further regex operations it makes sense to include a special regular expression that matches nothing. Otherwise a very simple NFA (DFA) has no corresponding regex, which can be considered awkward. There are powerful regex operations for which it may not be computationally trivial, regarding time and space, to tell whether the regex matches anything at all. Does one expect bool(o) to happen quickly? in near-constant time? I think there tends to be some such expectation. Then it might make practical sense to not interpret a regex as a container of the strings that it matches, even if such an interpretation makes some theoretical sense. It may make sense to keep the regex and its interpretation as a set (or relation) separate in theory, too, just for the clarity of thought. My colleagues down the corridor deal with large finite-state automata and transducers, applying a rich regex formalism to analyze the various forms that words can take. Some of them used to be a challenge to compile at all - a Greenlandish lexicon was an example. - It looks like the move of the software to GitHub has happened: http://hfst.github.io/. From guido at python.org Wed Sep 14 10:36:30 2016 From: guido at python.org (Guido van Rossum) Date: Wed, 14 Sep 2016 07:36:30 -0700 Subject: [python-committers] [RELEASE] Python 3.6.0b1 is now available In-Reply-To: References: <942D57F5-BA76-49CB-B3DB-18E2D6F12AC4@python.org> Message-ID: Fortunately that page isn't linked from anywhere on the home page AFAIK. If it is, could someone file an issue in the pydotorg tracker? The url is at the bottom of every page. On Wed, Sep 14, 2016 at 3:41 AM, Paul Moore wrote: > On 14 September 2016 at 11:32, Serhiy Storchaka wrote: >> On 13.09.16 02:35, Ned Deily wrote: >>> >>> On behalf of the Python development community and the Python 3.6 release >>> team, I'm happy to announce the availability of Python 3.6.0b1. 3.6.0b1 >>> is the first of four planned beta releases of Python 3.6, the next major >>> release of Python, and marks the end of the feature development phase >>> for 3.6. >> >> >> There is no mention on https://www.python.org/news/. > > The last release mentioned there is 3.4.0rc1... > > Paul > _______________________________________________ > python-committers mailing list > python-committers at python.org > https://mail.python.org/mailman/listinfo/python-committers > Code of Conduct: https://www.python.org/psf/codeofconduct/ -- --Guido van Rossum (python.org/~guido) From list at qtrac.plus.com Wed Sep 14 10:58:36 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 14 Sep 2016 07:58:36 -0700 (PDT) Subject: What is the correct form for saying "licensed under the same terms as Python itself"? Message-ID: <8e7d4ac9-1867-4544-8bc1-8c8e084fb792@googlegroups.com> Hi, I'm developing a small Python software library that I want to publish as free software under the same terms as Python itself. I notice that a few of Python's own files begin like this: # Copyright 2007 XXX. All Rights Reserved. # Licensed to PSF under a Contributor Agreement. Is this form sufficient? Do I need to include the PSF license with the package? (Also, I don't actually remember if I've signed a Contributor Agreement.) Thanks! From laurent.pointal at free.fr Wed Sep 14 12:16:31 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: 14 Sep 2016 16:16:31 GMT Subject: [ANN] German translation of Python 3 Cheat Sheet Message-ID: <57d977df$0$24771$426a74cc@news.free.fr> Hello, The Python 3 Sheet Cheat (M?mento Bases Python 3) has been translated into german by StR Martin Putzlocher. Thanks to him. It can be downloaded on the same page as english and french versions: https://perso.limsi.fr/pointal/python:memento A+ L.Pointal. From martinjp376 at gmail.com Wed Sep 14 12:24:46 2016 From: martinjp376 at gmail.com (Kerbingamer376) Date: Wed, 14 Sep 2016 09:24:46 -0700 (PDT) Subject: Tkinter file dialog screwed In-Reply-To: <57d8a45a$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <84022fec-6f58-4c0b-b2fe-6e67c6496e9c@googlegroups.com> <57d8a45a$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <566db9a6-124c-47c0-be24-988b781220ca@googlegroups.com> On Wednesday, September 14, 2016 at 2:14:16 AM UTC+1, Steve D'Aprano wrote: > On Wed, 14 Sep 2016 06:08 am, kerbingamer376 wrote: > > > The tkinter file dialog is, for me, unusable. Whenever I try to use it, it > > opens, but all the text is white on a white background (see this > > http://xomf.com/qzhgy) making it unusable. This has happened on 2 linux > > systems, both KDE plasma 5. Any help? > > > What happens if you change your KDE theme, or use another desktop > environment? > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. neither make any difference. From ja9749 at my.bristol.ac.uk Wed Sep 14 12:53:23 2016 From: ja9749 at my.bristol.ac.uk (Jamie) Date: Wed, 14 Sep 2016 17:53:23 +0100 Subject: Requests for webbrowser module Message-ID: Hi, I am not sure if this is an intended consequence but when using the webbrowser module to open a new blank browser tab in chrome it opens it in a new browser window instead of using the current window. Providing any complete url provides different behaviour, it opening a new tab in the current browser window. Below is some code that produces the different behaviours. blank tab code: import webbrowser chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" url = "chrome://newtab" webbrowser.get(chrome).open_new_tab(url) webbrowser.get(chrome).open_new_tab(url) normal tab code: import webbrowser chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" url = "http://google.com" webbrowser.get(chrome).open_new_tab(url) webbrowser.get(chrome).open_new_tab(url) I would like to be able to open new blank tabs in the current browser window if possible. If you know of a way to do this with the webbrowser module I would appreciate your help. Also is there any chance that the ability to close browser tabs will be added to the webbrowser module soon? Kind Regards, James Ansell From rustompmody at gmail.com Wed Sep 14 13:31:54 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 14 Sep 2016 10:31:54 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> Message-ID: <179c367b-bc71-4ca4-9820-8976240a4d55@googlegroups.com> On Wednesday, September 14, 2016 at 5:35:53 PM UTC+5:30, Jussi Piitulainen wrote: > Mathematical discussions tend to acknowledge only alternation (union), > concatenation and iteration (Kleene star) as operations, unless they > specifically focus on some other operations that can, in principle, be > expressed in terms of those three. There are many such. > > Without further regex operations it makes sense to include a special > regular expression that matches nothing. Otherwise a very simple NFA > (DFA) has no corresponding regex, which can be considered awkward. Not sure if I parse you correct ? Assuming ?a very simple DFA? you mean ?The DFA with only one state, no final state?? If yes then yes thats the nub of the matter More later? [Will switch from being a CS-teacher to net-disconnected music teacher for few days :-) ] From dmarv at dop.com Wed Sep 14 13:43:31 2016 From: dmarv at dop.com (Dale Marvin) Date: Wed, 14 Sep 2016 10:43:31 -0700 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> On 9/14/16 12:20 AM, Steven D'Aprano wrote: > On Wednesday 14 September 2016 16:54, Rustom Mody wrote: > >> everything we know will be negated in 5-50-500 years > > I'm pretty sure that in 5, 50, 500 or even 5000 years, the sun will still rise > in the east, water will be wet, fire will burn, dogs will have mammary glands > and frogs[1] won't, and the square root of 100 will still be 10. > > Isaac Asimov once wrote: > > When people thought the earth was flat, they were wrong. When people > thought the earth was spherical, they were wrong. But if you think that > thinking the earth is spherical is just as wrong as thinking the earth > is flat, then your view is wronger than both of them put together. > http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm > > [1] Assuming that there are any frogs left by then. > Funny, Asimov's professors must have taught him the same false history that I was taught at college. There's much evidence that medieval scholars did not believe the earth was flat. Dale From python at mrabarnett.plus.com Wed Sep 14 14:33:07 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Sep 2016 19:33:07 +0100 Subject: Requests for webbrowser module In-Reply-To: References: Message-ID: <4db31437-a46c-3cae-fbef-0f03124df3c8@mrabarnett.plus.com> On 2016-09-14 17:53, Jamie wrote: > Hi, > > I am not sure if this is an intended consequence but when using the > webbrowser module to open a new blank browser tab in chrome it opens it > in a new browser window instead of using the current window. Providing > any complete url provides different behaviour, it opening a new tab in > the current browser window. Below is some code that produces the > different behaviours. > > blank tab code: > import webbrowser > > chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" > url = "chrome://newtab" > webbrowser.get(chrome).open_new_tab(url) > webbrowser.get(chrome).open_new_tab(url) > > normal tab code: > import webbrowser > > chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" > url = "http://google.com" > webbrowser.get(chrome).open_new_tab(url) > webbrowser.get(chrome).open_new_tab(url) > > I would like to be able to open new blank tabs in the current browser > window if possible. If you know of a way to do this with the webbrowser > module I would appreciate your help. Also is there any chance that the > ability to close browser tabs will be added to the webbrowser module soon? > If you want a new blank tab, try giving it the URL "about:blank". All the module does is call the browser application with the appropriate command line arguments, so the module could close a tab only if the browser itself let you do so by calling it with some argument, which probably won't happen... A workaround is to select the browser window and then send it a Ctrl+F4 keypress. Have a look at the 3rd party "pywin32" package. From 007brendan at gmail.com Wed Sep 14 14:57:08 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Wed, 14 Sep 2016 11:57:08 -0700 Subject: What is the correct form for saying "licensed under the same terms as Python itself"? In-Reply-To: <8e7d4ac9-1867-4544-8bc1-8c8e084fb792@googlegroups.com> References: <8e7d4ac9-1867-4544-8bc1-8c8e084fb792@googlegroups.com> Message-ID: Unless you're actually distributing python (as in, the interpreter or it's source code), you don't need to include the python license or the copyright notice. You also don't need a Contributor agreement just to distribute a python library. That is more for people who are contributing to core Python or if your package is being added to the standard library. Python has a custom license, though it is GPL-compatible. The python license has a lot of wording that is specific to python and the PSF, so it probably doesn't make sense for you to use their license. Also, according to the python web site, they only accept contributions under the following licenses: - Academic Free License v. 2.1 - Apache License, Version 2.0 https://www.python.org/psf/contrib/ So, if you want your code to be available to the Python team (which is what it sounds like), you should use one of those 2 licenses, or consider using an even more permissive license (like the MIT license) that would not prohibit your project from being relicensed under the Apache or Python license. On Wed, Sep 14, 2016 at 7:58 AM, Mark Summerfield wrote: > Hi, > > I'm developing a small Python software library that I want to publish as > free software under the same terms as Python itself. > > I notice that a few of Python's own files begin like this: > > # Copyright 2007 XXX. All Rights Reserved. > # Licensed to PSF under a Contributor Agreement. > > Is this form sufficient? > Do I need to include the PSF license with the package? > (Also, I don't actually remember if I've signed a Contributor Agreement.) > > Thanks! > -- > https://mail.python.org/mailman/listinfo/python-list > From python.list at tim.thechases.com Wed Sep 14 15:04:34 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 14 Sep 2016 14:04:34 -0500 Subject: What is the correct form for saying "licensed under the same terms as Python itself"? In-Reply-To: References: <8e7d4ac9-1867-4544-8bc1-8c8e084fb792@googlegroups.com> Message-ID: <20160914140434.107c1089@bigbox.christie.dr> On 2016-09-14 11:57, Brendan Abel wrote: > Also, according to the python web site, they only accept > contributions under the following licenses: > > - Academic Free License v. 2.1 > > - Apache License, Version 2.0 > > > https://www.python.org/psf/contrib/ > > So, if you want your code to be available to the Python team (which > is what it sounds like), you should use one of those 2 licenses, or > consider using an even more permissive license (like the MIT > license) that would not prohibit your project from being relicensed > under the Apache or Python license. In today's "questions you've wanted to ask but never got around to, and somebody else answered them concisely even without you asking"... I've long been curious about this, but never sufficiently to actually go hunt down an answer. And here it is, packaged neatly in my inbox. Thanks! -tkc From python at mrabarnett.plus.com Wed Sep 14 15:59:45 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Sep 2016 20:59:45 +0100 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> Message-ID: On 2016-09-14 18:43, Dale Marvin via Python-list wrote: > On 9/14/16 12:20 AM, Steven D'Aprano wrote: >> On Wednesday 14 September 2016 16:54, Rustom Mody wrote: >> >>> everything we know will be negated in 5-50-500 years >> >> I'm pretty sure that in 5, 50, 500 or even 5000 years, the sun will still rise >> in the east, water will be wet, fire will burn, dogs will have mammary glands >> and frogs[1] won't, and the square root of 100 will still be 10. >> >> Isaac Asimov once wrote: >> >> When people thought the earth was flat, they were wrong. When people >> thought the earth was spherical, they were wrong. But if you think that >> thinking the earth is spherical is just as wrong as thinking the earth >> is flat, then your view is wronger than both of them put together. > >> http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm >> >> [1] Assuming that there are any frogs left by then. >> > > Funny, Asimov's professors must have taught him the same false history > that I was taught at college. There's much evidence that medieval > scholars did not believe the earth was flat. > > > Where does it say that he thought that _medieval_ scholars did not believe the earth was flat? From gordon at panix.com Wed Sep 14 16:08:23 2016 From: gordon at panix.com (John Gordon) Date: Wed, 14 Sep 2016 20:08:23 +0000 (UTC) Subject: Requests for webbrowser module References: Message-ID: In Jamie writes: > I am not sure if this is an intended consequence but when using the > webbrowser module to open a new blank browser tab in chrome it opens it > in a new browser window instead of using the current window. Providing There is an internal setting within Chrome that controls whether new pages are opened in a new tab or a new window. Perhaps that is your issue? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tjreedy at udel.edu Wed Sep 14 16:12:14 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Sep 2016 16:12:14 -0400 Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> Message-ID: On 9/14/2016 3:16 AM, Rustom Mody wrote: > In THOSE TYPES that element can justifiably serve as a falsey (empty) type > > However to extrapolate from here and believe that ALL TYPES can have a falsey > value meaningfully, especially in some obvious fashion, is mathematically nonsense. Python make no such nonsense claim. By default, Python objects are truthy. >>> bool(object()) True Because True is the default, object need not and at least in CPython does not have a __bool__ (or __len__) method. Classes with no falsey objects, such as functions, generators, and codes, need not do anything either. In the absence of an override function, the internal bool code returns True. It is up to particular classes to override that default and say that it has one or more Falsey objects. They do so by defining a __bool__ method that returns False for the falsey objects (and True otherwise) or by defining a __len__ method that returns int 0 for falsey objects (and non-0 ints otherwise). If a class defines both, __bool__ wins. -- Terry Jan Reedy From breamoreboy at gmail.com Wed Sep 14 16:12:34 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 14 Sep 2016 13:12:34 -0700 (PDT) Subject: Why don't we call the for loop what it really is, a foreach loop? In-Reply-To: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: On Tuesday, September 13, 2016 at 9:57:38 PM UTC+1, Richard Grigonis wrote: > It would help newbies and prevent confusion. I entirely agree. All together now "foreach is a jolly good fellow...". Kindest regards. Mark Lawrence. From breamoreboy at gmail.com Wed Sep 14 16:19:21 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 14 Sep 2016 13:19:21 -0700 (PDT) Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> Message-ID: On Wednesday, September 14, 2016 at 9:00:04 PM UTC+1, MRAB wrote: > On 2016-09-14 18:43, Dale Marvin via Python-list wrote: > > On 9/14/16 12:20 AM, Steven D'Aprano wrote: > >> On Wednesday 14 September 2016 16:54, Rustom Mody wrote: > >> > >>> everything we know will be negated in 5-50-500 years > >> > >> I'm pretty sure that in 5, 50, 500 or even 5000 years, the sun will still rise > >> in the east, water will be wet, fire will burn, dogs will have mammary glands > >> and frogs[1] won't, and the square root of 100 will still be 10. > >> > >> Isaac Asimov once wrote: > >> > >> When people thought the earth was flat, they were wrong. When people > >> thought the earth was spherical, they were wrong. But if you think that > >> thinking the earth is spherical is just as wrong as thinking the earth > >> is flat, then your view is wronger than both of them put together. > > > >> http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm > >> > >> [1] Assuming that there are any frogs left by then. > >> > > > > Funny, Asimov's professors must have taught him the same false history > > that I was taught at college. There's much evidence that medieval > > scholars did not believe the earth was flat. > > > > > > > Where does it say that he thought that _medieval_ scholars did not > believe the earth was flat? It is so blantantly obvious that the world is not flat I find this discussion flabbergasting. Anybody who has tried to take any form of vehicle up, or probably more dangerously down, any form of hill knows that. As for the raving lunatics who make their living by riding up and down these http://www.bbc.co.uk/news/in-pictures-37348004, well need I say more? Kindest regards. Mark Lawrence. From tjreedy at udel.edu Wed Sep 14 16:39:23 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Sep 2016 16:39:23 -0400 Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> Message-ID: On 9/14/2016 8:05 AM, Jussi Piitulainen wrote: > Serhiy Storchaka writes: > >> On 14.09.16 11:28, Steven D'Aprano wrote: > >>> I'm not sure if it makes sense to talk about an "empty regular >>> expression", or if that is the same as re.compile(''). Presumably if >>> such a thing makes sense, it would match nothing, from any input at >>> all. >> >> Actually, it matches anything. re.compile('').match(x) returns >> non-false value for any valid x. > > It matches the empty string. The .match method returns a match object if > the regex matches at the start of the input. See span: > > re.compile('').match('foo') > ===> <_sre.SRE_Match object; span=(0, 0), match=''> > > There's an empty string at every position, same content, different span: > > re.compile('').findall('foo') > ===> ['', '', '', ''] To put it slightly differently, regexes match slices. A string of n chars has n+1 empty (len 0) slices - the 2 at the ends and the n-1 between chars. -- Terry Jan Reedy From lawrencedo99 at gmail.com Wed Sep 14 16:59:17 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 14 Sep 2016 13:59:17 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> Message-ID: On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: > Because True is the default, object need not and at least in CPython > does not have a __bool__ (or __len__) method. If they had to (in the absence of which a bool() cast would not work), then that would help prevent problems like the one I previously linked to, don?t you think? From rosuav at gmail.com Wed Sep 14 17:07:04 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Sep 2016 07:07:04 +1000 Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> Message-ID: On Thu, Sep 15, 2016 at 6:59 AM, Lawrence D?Oliveiro wrote: > On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: >> Because True is the default, object need not and at least in CPython >> does not have a __bool__ (or __len__) method. > > If they had to (in the absence of which a bool() cast would not work), then that would help prevent problems like the one I previously linked to, don?t you think? > Nope. The problem came from a *design fault* in which times were identified with midnight as zero, and were treated as numbers. So whether implicit or explicit, boolification would have behaved the same way, and the issue would have happened. I've seen very similar issues surrounding array/list indices in various languages, and even file descriptors (stdin is fd 0, and if you simply check the value of the fd, stdin will appear to be false). Normally they're caught early in design, but sometimes not. And often, particularly with student or novice programmers, the workarounds begin looking extremely odd (why do we start row IDs at 1, even though we have the SQL NULL value available to mean "no ID at all"?). ChrisA From ned at nedbatchelder.com Wed Sep 14 17:12:04 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 14 Sep 2016 14:12:04 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> Message-ID: <5e7a65e0-f982-4525-b460-099b8ab7caff@googlegroups.com> On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D?Oliveiro wrote: > On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: > > Because True is the default, object need not and at least in CPython > > does not have a __bool__ (or __len__) method. > > If they had to (in the absence of which a bool() cast would not work), then that would help prevent problems like the one I previously linked to, don?t you think? Requiring an explicit conversion method wouldn't help the "midnight is False" problem: it was *caused* by an explicit conversion method. From the article: > A Python bug was opened in 2012 about midnight as False, but it was closed > soon thereafter as "invalid". The time class was documented to work that way > and someone had created a __nonzero__() (now __bool__()) method for time to > implement that behavior. --Ned. From wesley.keeling at iugome.com Wed Sep 14 18:16:12 2016 From: wesley.keeling at iugome.com (wesley.keeling at iugome.com) Date: Wed, 14 Sep 2016 15:16:12 -0700 (PDT) Subject: How could I implement a virtual method and override it in python? Message-ID: Hey guys, I will show the code first: Helper.py: def Foo( *args ): print ("This is a callback") def Run: Foo() MyModule.py: import Helper def Foo( *args ): print ("I want to be the new callback") I want to be able to call the Foo method in MyModule.py when it's there first and when it's not I want to call the Foo in helper.py. I am coming from .net so I am not fully understanding how the Foo method would override the other one. Thanks! From lawrencedo99 at gmail.com Wed Sep 14 18:46:04 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 14 Sep 2016 15:46:04 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: <5e7a65e0-f982-4525-b460-099b8ab7caff@googlegroups.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <5e7a65e0-f982-4525-b460-099b8ab7caff@googlegroups.com> Message-ID: <1adbbe3f-44dc-46a2-96f7-f9e3db0265aa@googlegroups.com> On Thursday, September 15, 2016 at 9:12:25 AM UTC+12, Ned Batchelder wrote: > > On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D?Oliveiro > wrote: >> >> On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: >>> >>> Because True is the default, object need not and at least in CPython >>> does not have a __bool__ (or __len__) method. >> >> If they had to (in the absence of which a bool() cast would not work), >> then that would help prevent problems like the one I previously linked to, >> don?t you think? > > Requiring an explicit conversion method wouldn't help the "midnight is > False" problem: it was *caused* by an explicit conversion method. ?Conversion method? versus ?explicit conversion? are two different things. The class provided a method to convert to bool, but Python itself does automatic interpretation of non-boolean values as booleans. It is the latter I am objecting to. From lawrencedo99 at gmail.com Wed Sep 14 18:47:07 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 14 Sep 2016 15:47:07 -0700 (PDT) Subject: How could I implement a virtual method and override it in python? In-Reply-To: References: Message-ID: On Thursday, September 15, 2016 at 10:18:09 AM UTC+12, wesley.... at iugome.com wrote: > Helper.py: > > def Foo( *args ): > print ("This is a callback") > > def Run: > Foo() > > > MyModule.py: > > import Helper > > def Foo( *args ): > print ("I want to be the new callback") Overrides and subclassing applies to classes, not modules. From wesley.keeling at iugome.com Wed Sep 14 18:51:08 2016 From: wesley.keeling at iugome.com (wesley.keeling at iugome.com) Date: Wed, 14 Sep 2016 15:51:08 -0700 (PDT) Subject: How could I implement a virtual method and override it in python? In-Reply-To: References: Message-ID: On Wednesday, September 14, 2016 at 3:47:52 PM UTC-7, Lawrence D?Oliveiro wrote: > On Thursday, September 15, 2016 at 10:18:09 AM UTC+12, wesley.... at iugome.com wrote: > > Helper.py: > > > > def Foo( *args ): > > print ("This is a callback") > > > > def Run: > > Foo() > > > > > > MyModule.py: > > > > import Helper > > > > def Foo( *args ): > > print ("I want to be the new callback") > > Overrides and subclassing applies to classes, not modules. Yeah I assumed so, is there any ways I can get this to work with the importing of the helper? From steve+python at pearwood.info Wed Sep 14 20:40:10 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 15 Sep 2016 10:40:10 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> Message-ID: <57d9eded$0$1622$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Sep 2016 03:43 am, Dale Marvin wrote: > On 9/14/16 12:20 AM, Steven D'Aprano wrote: >> On Wednesday 14 September 2016 16:54, Rustom Mody wrote: >> >>> everything we know will be negated in 5-50-500 years >> >> I'm pretty sure that in 5, 50, 500 or even 5000 years, the sun will still >> rise in the east, water will be wet, fire will burn, dogs will have >> mammary glands and frogs[1] won't, and the square root of 100 will still >> be 10. >> >> Isaac Asimov once wrote: >> >> When people thought the earth was flat, they were wrong. When people >> thought the earth was spherical, they were wrong. But if you think >> that thinking the earth is spherical is just as wrong as thinking the >> earth is flat, then your view is wronger than both of them put >> together. > >> http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm >> >> [1] Assuming that there are any frogs left by then. >> > > Funny, Asimov's professors must have taught him the same false history > that I was taught at college. There's much evidence that medieval > scholars did not believe the earth was flat. I don't see Asimov referring to medieval scholars. The medieval period is roughly around 1000 CE or thereabouts. Asimov talks about people believing in a flat earth "In the early days of civilization" and goes on to discuss how Greeks such as Aristotle (350 BCE) had evidence for a spherical earth. He doesn't mention the medieval period at all. If you're going to criticise Asimov, don't criticise him for wrongly thinking that people in the Middle Ages believed in a flat earth. There's no evidence of that in his essay. Rather, criticise him for over-simplifying how quickly and universally the idea of the spherical earth took over. Asimov jumps from Eratosthenes (about a century after Aristotle, so around 250 BCE) to Newton (17th century) with nary a mention of how long, slow and difficult it was for the flat earth cosmology to be discarded. Regardless of what a few ivory-tower Greek philosophers thought, in the early centuries CE many people still believed the world was flat. While it is true that by the Middle Ages educated scholars in Europe almost certainly believed in a spherical world, not all people were educated scholars. We have no idea what the average peasant tilling the fields would have believed, although given the influence of Christianity and the remnants of ancient Hebrew cosmology (flat earth) in the Bible, it is far more likely that the average uneducated person believed in a flat earth. But we don't really know for sure. And there is more to the world than just Europe. In China, belief in a flat earth cosmology was virtually unchallenged until the 17th century. https://en.wikipedia.org/wiki/Flat_Earth -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 14 20:46:03 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 15 Sep 2016 10:46:03 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> Message-ID: <57d9ef4e$0$1585$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Sep 2016 06:19 am, breamoreboy at gmail.com wrote: > It is so blantantly obvious that the world is not flat I find this > discussion flabbergasting. You wouldn't say that if you lived in Kanvas, or the west coast of Ireland. I'm told that a few years ago somebody accidentally dumped a trailer load of soil by the side of the road in Kanvas, and within a day some enterprising entrepreneur had set up a thriving roadside business offering mountain-climbing tours to the 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 Wed Sep 14 20:58:07 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 15 Sep 2016 10:58:07 +1000 Subject: How could I implement a virtual method and override it in python? References: Message-ID: <57d9f222$0$1589$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Sep 2016 08:16 am, wesley.keeling at iugome.com wrote: > Hey guys, I will show the code first: > > Helper.py: > > def Foo( *args ): > print ("This is a callback") > > def Run: > Foo() > > > MyModule.py: > > import Helper > > def Foo( *args ): > print ("I want to be the new callback") > > > > I want to be able to call the Foo method in MyModule.py when it's there > first and when it's not I want to call the Foo in helper.py. What is doing the calling? Surely MyModule knows whether or not it has a Foo function? Or rather, the author of MyModule knows whether or not he has defined a Foo function. I don't understand how this problem would come about in practice. If you are writing MyModule, you surely must know whether or not you have defined Foo. If you have, you call Foo() and if you haven't, you write: from Helper import Foo Foo() or perhaps: import Helper Helper.Foo() If for some reason you won't know until runtime whether or not Foo exists, you can say: try: Foo # don't call the function, just name it except NameError: # Doesn't exist, so use the helper function from Helper import Foo Foo() # works either way now If it is a *third* module doing the calling, then things start to be a bit more clear. So I have my main application, and I want to use a function Foo defined in MyModule, if it exists, otherwise Foo defined in Helper. Here is one way to do it: # main.py try: from MyModule import Foo except ImportError: from Helper import Foo Foo() > I am coming from .net so I am not fully understanding how the Foo method > would override the other one. It doesn't. Perhaps you are unclear about the difference between methods of a class and functions in modules? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ckaynor at zindagigames.com Wed Sep 14 21:04:26 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 14 Sep 2016 18:04:26 -0700 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> Message-ID: On Wed, Sep 14, 2016 at 1:19 PM, wrote: > It is so blantantly obvious that the world is not flat I find this > discussion flabbergasting. Anybody who has tried to take any form of > vehicle up, or probably more dangerously down, any form of hill knows > that. As for the raving lunatics who make their living by riding up and > down these http://www.bbc.co.uk/news/in-pictures-37348004, well need I > say more? > Going up or down a mountain does not prove the world is round by itself, no matter how twisted the road might be. Take for example most 3D game worlds, which are generally simulated using a flat-world for ease, but still simulate gravity (and sometimes even the horizon) just fine. If you find somebody determined to not trust evidence such as the blue marble photos, it can be quite hard to prove that the world is not flat. The major issue comes from the fact that, at a human scale, the difference between a flat world and and Earth is very small - you don't need to take into account the curve of the earth for almost any buildings. With that in mind, I'm not sure what evidence you claim is "blatantly obvious". By far the two simplest evidence is traveling around the Earth (not particularly easy, especially even 100 years ago) and watching the stars move. Both could be explained by other methods, but those would be vastly more complicated to explain the observed behavior (look at the Earth-centric universe models). Chris From lawrencedo99 at gmail.com Wed Sep 14 21:43:44 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 14 Sep 2016 18:43:44 -0700 (PDT) Subject: Creating A Pythonic ctypes Binding Message-ID: <80c0d746-b659-44af-9492-d04c4611946a@googlegroups.com> ctypes is a wonderful library. If you need to create a Python binding for some library that doesn?t already have one, you should look at ctypes, rather than writing an extension module in C or C++. The odds are, a pure Python implementation using ctypes can be done with much less effort than writing C/C++ code. But it is not enough to wrap an API designed for C or C++. A Python API should take advantage of the power and convenience of Python. The question I like to ask is: ?How would the API have been designed if it was native to Python, rather than being intended for C or C++??. Another question to consider is: ?Does the Python API binding give you a reason to use Python to write your code in the first place, rather than choosing C or C++ instead??. In short, does your Python code that makes calls to the API look like a straight transliteration of C code, or does it work at a higher level? What do I mean by this? An obvious, very basic, example is not having the user have to bother with explicitly creating and destroying objects. Wrap an underlying API object in a Python object, such that the Python object?s ?__del__? method will take care of disposing of the API object. Then Python?s usual object-management mechanisms will automatically manage the API objects as well. This is how Qahirah , my wrapper for the Cairo graphics library , works. But there is more you can do. Another obvious one is, where the underlying API provides ?get_xxx? and ?set_xxx? methods, to wrap them in a read/write Python property. For example, Cairo defines a ?fill rule? that governs how paths are filled, with getter and setter calls . In Qahirah this is translated to a property that you can obtain with a simple expression like ??ctx?.fill_rule? (where ?ctx? is a Context object), and change by a simple assignment like ??ctx?.fill_rule = ?new_value??. Sometimes the values that are returned by the getter or set with the setter have a more complex, variable-length structure. So the C API may need two parts to the getter routines, one to determine how big a structure the caller needs to allocate, and the other to fill in a preallocated structure with the actual data. For example, the dash setting for stroking lines is of this type. In Python, it makes sense to store the dash information in a high-level Python object, which is directly returned from the Python-level getter and directly passed to the Python-level setter. In Qahirah, I use a 2-tuple, the first element of which specifies the alternating on/off dash lengths (itself a tuple), and the second of which is the starting offset. All conversion between this format and the actual format that Cairo expects happens within the Python wrapper routines, without the caller having to worry about it. Sometimes the opportunities to add value come from other available Python libraries. Cairo only deals with colours as RGB components, with an optional alpha. But Python provides this handy colorsys module as standard, which provides conversions to/from a number of non-RGB colour spaces; why not take advantage of it? So I defined a ?Colour? type, and all wrappers to Cairo calls that set or get colours take or return this object instead of separate RGB or RGBA components. A Colour can be constructed from components in any of the supported colour spaces, and you can query its components in any of these colour spaces. But more than that, you can also perform useful manipulations on Colours, like adjusting the values of components to produce new, but related, colours. This all goes way beyond the functionality of Cairo itself, but I felt it was useful, even essential, to have in a worthwhile graphics API. Python has a remarkably simple and elegant technique for implementing custom overloading of its standard operators. C, of course, has no such thing. So APIs designed for C have to provide function calls instead, such as for Cairo?s matrix operations . It was easy enough for me to define a ?Matrix? class, with the ?*? operator (?@? as well in Python 3.5 or later) to do Matrix multiplication. Instead of updating a Matrix object in place (procedural programming), I prefer a more functional approach, where each operation creates a new Matrix object as its result, leaving its operands unchanged. This lets you write expressions which are closer to the underlying mathematics. I also defined a ?Vector? class, representing both X and Y coordinates in a single value. Cairo itself requires you to pass (or get back) separate X and Y coordinate values; but again, I wrap all these calls so that you pass and return Vectors. It is extremely common to do calculations on corresponding X- and Y-coordinates that are absolutely identical, except for the coordinate-specific components; Qahirah lets you write these calculations just once instead of twice, operating directly on Vectors. In short: ctypes is cool. Python is cool. Python + ctypes = OMG wow cool. Yeah. :) From lawrencedo99 at gmail.com Wed Sep 14 21:44:45 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 14 Sep 2016 18:44:45 -0700 (PDT) Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> Message-ID: <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> On Thursday, September 15, 2016 at 1:26:49 PM UTC+12, Chris Kaynor wrote: > If you find somebody determined to not trust evidence such as the blue > marble photos, it can be quite hard to prove that the world is not flat. A flat world doesn?t have a horizon. From steve+python at pearwood.info Wed Sep 14 23:12:28 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 15 Sep 2016 13:12:28 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> Message-ID: <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Sep 2016 11:44 am, Lawrence D?Oliveiro wrote: > On Thursday, September 15, 2016 at 1:26:49 PM UTC+12, Chris Kaynor wrote: >> If you find somebody determined to not trust evidence such as the blue >> marble photos, it can be quite hard to prove that the world is not flat. > > A flat world doesn?t have a horizon. Yes it does. Even an infinitely large flat plane has a horizon almost identical to the actual horizon. http://www.askamathematician.com/2012/08/q-if-earth-was-flat-would-there-be-the-horizon-if-so-what-would-it-look-like-if-the-earth-was-flat-and-had-infinite-area-would-that-change-the-answer/ http://boards.straightdope.com/sdmb/showthread.php?t=385334 In fact, Flat Earthers consider the flat horizon evidence for a flat Earth: http://www.atlanteanconspiracy.com/2015/01/flat-earth-horizon.html Relevant: https://www.lhup.edu/~dsimanek/flat/flateart.htm (To answer my rhetorical question in the subject header: yes, apparently we can.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 14 23:27:02 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 15 Sep 2016 13:27:02 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <5e7a65e0-f982-4525-b460-099b8ab7caff@googlegroups.com> <1adbbe3f-44dc-46a2-96f7-f9e3db0265aa@googlegroups.com> Message-ID: <57da1507$0$1617$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Sep 2016 08:46 am, Lawrence D?Oliveiro wrote: > On Thursday, September 15, 2016 at 9:12:25 AM UTC+12, Ned Batchelder > wrote: >> >> On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D?Oliveiro >> wrote: >>> >>> On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: >>>> >>>> Because True is the default, object need not and at least in CPython >>>> does not have a __bool__ (or __len__) method. >>> >>> If they had to (in the absence of which a bool() cast would not work), >>> then that would help prevent problems like the one I previously linked >>> to, don?t you think? >> >> Requiring an explicit conversion method wouldn't help the "midnight is >> False" problem: it was *caused* by an explicit conversion method. > > ?Conversion method? versus ?explicit conversion? are two different things. > The class provided a method to convert to bool, but Python itself does > automatic interpretation of non-boolean values as booleans. It is the > latter I am objecting to. So you have made clear, but what isn't clear is what is the reason for the objection. Is it just a matter of taste? If not, can you explain what *objective* reasons you have for preferring the second over the first. Try to be explicit, rather than just dropping hints and pretending that it is self-evident and obvious. if obj: ... # implicitly calls obj.__bool__ or equivalent, by the bool protocol # versus if bool(obj): ... # implicitly calls obj.__bool__ or equivalent Apart from the extra six characters, I see no difference. What am I missing? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jussi.piitulainen at helsinki.fi Wed Sep 14 23:53:39 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 15 Sep 2016 06:53:39 +0300 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <57d90a1b$0$2758$c3e8da3$76491128@news.astraweb.com> <179c367b-bc71-4ca4-9820-8976240a4d55@googlegroups.com> Message-ID: Rustom Mody writes: > On Wednesday, September 14, 2016 at 5:35:53 PM UTC+5:30, Jussi Piitulainen wrote: >> Mathematical discussions tend to acknowledge only alternation >> (union), concatenation and iteration (Kleene star) as operations, >> unless they specifically focus on some other operations that can, in >> principle, be expressed in terms of those three. There are many such. >> >> Without further regex operations it makes sense to include a special >> regular expression that matches nothing. Otherwise a very simple NFA >> (DFA) has no corresponding regex, which can be considered awkward. > > Not sure if I parse you correct ? Assuming ?a very simple DFA? you > mean ?The DFA with only one state, no final state?? Yes. From travisgriggs at gmail.com Thu Sep 15 00:46:21 2016 From: travisgriggs at gmail.com (Travis Griggs) Date: Wed, 14 Sep 2016 21:46:21 -0700 Subject: Why don't we call the for loop what it really is, a foreach loop? In-Reply-To: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: > On Sep 13, 2016, at 13:57, rgrigonis at gmail.com wrote: > > It would help newbies and prevent confusion. for each in ['cake'] + ['eat', 'it'] * 2: print(each) From jobmattcon at gmail.com Thu Sep 15 01:00:32 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Wed, 14 Sep 2016 22:00:32 -0700 (PDT) Subject: unexpected rerun program itself when using cv2 and selenium Message-ID: <3f92e132-41df-47d1-bbe9-1baf0f5efd28@googlegroups.com> unexpected rerun program itself when using cv2 and selenium when a script, it is expected to run once and stop but it start a new browser again when using selenium and cv2 d, bbox, filename) File "C:\Python27\lib\site-packages\pyscreenshot\procutil.py", line 28, in run _in_childprocess p.start() File "C:\Python27\lib\multiprocessing\process.py", line 130, in start self._popen = Popen(self) File "C:\Python27\lib\multiprocessing\forking.py", line 258, in __init__ cmd = get_command_line() + [rhandle] File "C:\Python27\lib\multiprocessing\forking.py", line 358, in get_command_li ne is not going to be frozen to produce a Windows executable.''') RuntimeError: Attempt to start a new process before the current process has finished its bootstrapping phase. This probably means that you are on Windows and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce a Windows executable. From no.email at nospam.invalid Thu Sep 15 01:01:34 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 14 Sep 2016 22:01:34 -0700 Subject: Why don't we call the for loop what it really is, a foreach loop? References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> Message-ID: <87twdhdadt.fsf@jester.gateway.pace.com> Travis Griggs writes: > for each in ['cake'] + ['eat', 'it'] * 2: > print(each) https://pbs.twimg.com/media/Cr-edT2VUAArpVL.jpg From auriocus at gmx.de Thu Sep 15 01:35:40 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 15 Sep 2016 07:35:40 +0200 Subject: Why don't we call the for loop what it really is, a foreach loop? In-Reply-To: <87twdhdadt.fsf@jester.gateway.pace.com> References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> <87twdhdadt.fsf@jester.gateway.pace.com> Message-ID: Am 15.09.16 um 07:01 schrieb Paul Rubin: > Travis Griggs writes: >> for each in ['cake'] + ['eat', 'it'] * 2: >> print(each) > > https://pbs.twimg.com/media/Cr-edT2VUAArpVL.jpg > http://www.azlyrics.com/lyrics/queen/bohemianrhapsody.html More interestingly, which language is it? First I thought C++ or Java, but they don't use self and there is a => operator. PHP adornes variables with $. Another C-derived language which has built-in hash maps? Christian From marko at pacujo.net Thu Sep 15 01:44:06 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 15 Sep 2016 08:44:06 +0300 Subject: Why don't we call the for loop what it really is, a foreach loop? References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> <87twdhdadt.fsf@jester.gateway.pace.com> Message-ID: <8760pxpvix.fsf@elektro.pacujo.net> Christian Gollwitzer : > More interestingly, which language is it? First I thought C++ or Java, > but they don't use self and there is a => operator. PHP adornes > variables with $. Another C-derived language which has built-in hash > maps? C#. The => syntax is Python's lambda. Marko From dmarv at dop.com Thu Sep 15 01:47:29 2016 From: dmarv at dop.com (Dale Marvin) Date: Wed, 14 Sep 2016 22:47:29 -0700 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <57d9eded$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <6ff619a4-773e-930f-a2a4-a2aa4eda2357@mail.de> <20160908020050.GA22471@ando.pearwood.info> <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <57d9eded$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/14/16 5:40 PM, Steve D'Aprano wrote: > > If you're going to criticise Asimov, don't criticise him for wrongly > thinking that people in the Middle Ages believed in a flat earth. There's > no evidence of that in his essay. > I didn't mean to criticize Asimov, but the History Professors, one in particular seemed to make it his life's purpose to say bad things about religion/bible etc. I should have known better than to get into such an off-topic quagmire. Dale From list at qtrac.plus.com Thu Sep 15 02:01:05 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 14 Sep 2016 23:01:05 -0700 (PDT) Subject: What is the correct form for saying "licensed under the same terms as Python itself"? In-Reply-To: References: <8e7d4ac9-1867-4544-8bc1-8c8e084fb792@googlegroups.com> Message-ID: <99c400fe-40ad-440b-a83c-b5d11c199540@googlegroups.com> Thanks v. much: I'll use the Apache 2.0 license. From no.email at nospam.invalid Thu Sep 15 02:01:40 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 14 Sep 2016 23:01:40 -0700 Subject: Why don't we call the for loop what it really is, a foreach loop? References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> <87twdhdadt.fsf@jester.gateway.pace.com> Message-ID: <87h99hd7ln.fsf@jester.gateway.pace.com> Christian Gollwitzer writes: > http://www.azlyrics.com/lyrics/queen/bohemianrhapsody.html Alt version, https://www.youtube.com/watch?v=hpvlTVgeivU From random832 at fastmail.com Thu Sep 15 02:02:01 2016 From: random832 at fastmail.com (Random832) Date: Thu, 15 Sep 2016 02:02:01 -0400 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> On Wed, Sep 14, 2016, at 23:12, Steve D'Aprano wrote: > Yes it does. Even an infinitely large flat plane has a horizon almost > identical to the actual horizon. Your link actually doesn't support the latter claim, it goes into some detail on why it wouldn't if it were infinitely large due to gravitational effects on light. Of course, the fact that the horizon is a short [in comparison to the size of the known world] distance away *is* evidence for a round Earth. It might "look the same", but it would contain features all the way up to potentially the edge (anything not obstructed by subjectively taller objects in front of it), it certainly wouldn't make sense not to see the opposing landmass across an ocean. > http://www.askamathematician.com/2012/08/q-if-earth-was-flat-would-there-be-the-horizon-if-so-what-would-it-look-like-if-the-earth-was-flat-and-had-infinite-area-would-that-change-the-answer/ From storchaka at gmail.com Thu Sep 15 02:35:14 2016 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 15 Sep 2016 09:35:14 +0300 Subject: [RELEASE] Python 3.6.0b1 is now available In-Reply-To: References: <942D57F5-BA76-49CB-B3DB-18E2D6F12AC4@python.org> Message-ID: On 14.09.16 17:36, Guido van Rossum wrote: > Fortunately that page isn't linked from anywhere on the home page > AFAIK. If it is, could someone file an issue in the pydotorg tracker? > The url is at the bottom of every page. This is on of the first results (actually the first besides manually edited news) of googling "python news". From jobmattcon at gmail.com Thu Sep 15 03:12:52 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 15 Sep 2016 00:12:52 -0700 (PDT) Subject: how to automate java application in window using python Message-ID: how to automate java application in window using python 1. scroll up or down of scroll bar 2. click button 3. type text in textbox From lawrencedo99 at gmail.com Thu Sep 15 03:52:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 15 Sep 2016 00:52:27 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: Message-ID: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent bbird wrote: > how to automate java application in window using python > > 1. scroll up or down of scroll bar > 2. click button > 3. type text in textbox Well, don?t leave us in suspense! Give us the link to your blog post! From alister.ware at ntlworld.com Thu Sep 15 04:15:49 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 15 Sep 2016 08:15:49 GMT Subject: Why don't we call the for loop what it really is, a foreach loop? References: <6c88a5cf-fa23-4a63-94c1-de8dbf8e81f5@googlegroups.com> <87twdhdadt.fsf@jester.gateway.pace.com> Message-ID: On Wed, 14 Sep 2016 22:01:34 -0700, Paul Rubin wrote: > Travis Griggs writes: >> for each in ['cake'] + ['eat', 'it'] * 2: >> print(each) > > https://pbs.twimg.com/media/Cr-edT2VUAArpVL.jpg the "Cowboy Song" buy Furrokh Bulsara -- Olmstead's Law: After all is said and done, a hell of a lot more is said than done. From dieter at handshake.de Thu Sep 15 04:19:20 2016 From: dieter at handshake.de (dieter) Date: Thu, 15 Sep 2016 10:19:20 +0200 Subject: =?iso-8859-7?B?oXBpcDI=?= install =?iso-8859-7?B?Y3J5cHRvZ3Jh?= =?iso-8859-7?B?cGh5og==?= does not work References: <87h99ilves.fsf@Equus.decebal.nl> Message-ID: <874m5ho9rr.fsf@handshake.de> Cecil Westerhof writes: > I try to do a: > pip2 install cryptography > > But this give: > gcc -pthread -shared build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o -L/usr/lib64 -lssl -lcrypto -lpython2.7 -o build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/_openssl.so > /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC > /usr/lib64/libpython2.7.a: error adding symbols: Bad value > collect2: error: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 Apparently, the linker requires use of the "-fPIC" option ("PIC" stands for "position independent code") for linking a shared library. The problem might come from your system's Python installation (apparently, that one is used). Usually, you would have a "libpython*.so" (i.e. a shared object) and it would contain modules compiled with "-fPIC". In your case, the static library "libpython*.a" seems to be used and (apparently) contains not position idependent modules. From alister.ware at ntlworld.com Thu Sep 15 04:34:50 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 15 Sep 2016 08:34:50 GMT Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] Message-ID: On Wed, 14 Sep 2016 18:04:26 -0700, Chris Kaynor wrote: > On Wed, Sep 14, 2016 at 1:19 PM, wrote: > >> It is so blantantly obvious that the world is not flat I find this >> discussion flabbergasting. Anybody who has tried to take any form of >> vehicle up, or probably more dangerously down, any form of hill knows >> that. As for the raving lunatics who make their living by riding up >> and down these http://www.bbc.co.uk/news/in-pictures-37348004, well >> need I say more? >> >> > Going up or down a mountain does not prove the world is round by itself, No but it does demonstrate that it is not flat (@ a bare minimum it undulates) Not flat != round -- A gift of a flower will soon be made to you. From Cecil at decebal.nl Thu Sep 15 05:32:49 2016 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 15 Sep 2016 11:32:49 +0200 Subject: =?utf-8?Q?=E2=80=98pip2?= install =?utf-8?Q?cryptography?= =?utf-8?Q?=E2=80=99?= does not work References: <87h99ilves.fsf@Equus.decebal.nl> <874m5ho9rr.fsf@handshake.de> Message-ID: <87d1k5ld8e.fsf@Equus.decebal.nl> On Thursday 15 Sep 2016 10:19 CEST, dieter at handshake.de wrote: > Cecil Westerhof writes: > >> I try to do a: >> pip2 install cryptography >> >> But this give: gcc -pthread -shared >> build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o >> -L/usr/lib64 -lssl -lcrypto -lpython2.7 -o >> build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/_openssl.so >> /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: >> /usr/lib64/libpython2.7.a(abstract.o): relocation R_X86_64_32S >> against _Py_NotImplementedStruct' can not be used when making a >> shared object; recompile with -fPIC /usr/lib64/libpython2.7.a: >> error adding symbols: Bad value collect2: error: ld returned 1 exit >> status error: command 'gcc' failed with exit status 1 > > Apparently, the linker requires use of the "-fPIC" option > ("PIC" stands for "position independent code") for linking a shared > library. > > The problem might come from your system's Python installation > (apparently, that one is used). Usually, you would have > a "libpython*.so" (i.e. a shared object) and it would contain > modules compiled with "-fPIC". In your case, the > static library "libpython*.a" seems to be used and (apparently) > contains not position idependent modules. I installed python-devel and the problems went away. What I find a kind of strange that I did not have python3-devel installed and I do not have a problem with: pip3 install cryptography -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From greg.ewing at canterbury.ac.nz Thu Sep 15 09:06:53 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 16 Sep 2016 01:06:53 +1200 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > And then there is Pratchett's Discworld... which is both flat and round > (just not spherical) And it has a horizon -- if you go far enough you fall off the edge. -- Greg From grant.b.edwards at gmail.com Thu Sep 15 09:45:07 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 15 Sep 2016 13:45:07 +0000 (UTC) Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <57d9ef4e$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-09-15, Steve D'Aprano wrote: > On Thu, 15 Sep 2016 06:19 am, breamoreboy at gmail.com wrote: > >> It is so blantantly obvious that the world is not flat I find this >> discussion flabbergasting. > > You wouldn't say that if you lived in Kanvas, or the west coast of Ireland. > > I'm told that a few years ago somebody accidentally dumped a trailer load of > soil by the side of the road in Kanvas, and within a day some enterprising > entrepreneur had set up a thriving roadside business offering > mountain-climbing tours to the locals. Kanvas? -- Grant Edwards grant.b.edwards Yow! Why don't you ever at enter any CONTESTS, gmail.com Marvin?? Don't you know your own ZIPCODE? From daiyueweng at gmail.com Thu Sep 15 10:57:46 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Thu, 15 Sep 2016 15:57:46 +0100 Subject: logging TypeError: not all arguments converted during string formatting Message-ID: Hi, I am trying to record memory and CPU usages and load a logger from an external config file (logging.conf), [loggers] keys=root,hardware_log [handlers] keys=consoleHandler,hardwareFileHandler [formatters] keys=hardwareFormatter [logger_root] level=DEBUG handlers=consoleHandler [logger_hardware_log] level=DEBUG handlers=hardwareFileHandler qualname=hardware_log propagate=0 [handler_consoleHandler] class=StreamHandler level=DEBUG formatter=hardwareFormatter args=(sys.stdout,) [handler_hardwareFileHandler] class=handlers.RotatingFileHandler maxBytes=51200 level=DEBUG formatter=hardwareFormatter args=("log/hardware.log",) [formatter_hardwareFormatter] format=pathname~%(pathname)s||timestamp~%(asctime)s||level~%(levelname)s||name~%(name)s||function_name~%(funcName)s||line_no~%(lineno)s||debug_CPU~%(message)s||debug_Mem~%(message)s datefmt=%m/%d/%Y %H:%M:%S class=logging.Formatter import logging import psutil logging.config.fileConfig('logging.conf') hardware_log = logging.getLogger(HARDWARELOGNAME) free_mem_gb_pre = psutil.virtual_memory().available / 1000000000. cpu_util_pct_pre = psutil.cpu_percent() hardware_log.info(cpu_util_pct_pre, free_mem_gb_pre) I got the following errors, --- Logging error --- Traceback (most recent call last): File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 980, in emit msg = self.format(record) File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 830, in format return fmt.format(record) File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 567, in format record.message = record.getMessage() File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 330, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Call stack: File "C:\Program Files (x86)\JetBrains\PyCharm 2016.2.1\helpers\pycharm\pytestrunner.py", line 60, in main() File "C:\Program Files (x86)\JetBrains\PyCharm 2016.2.1\helpers\pycharm\pytestrunner.py", line 35, in main exitstatus = hook.pytest_cmdline_main(config=config) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__ return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in _MultiCall(methods, kwargs, hook.spec_opts).execute() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute res = hook_impl.function(*args) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\main.py", line 115, in pytest_cmdline_main return wrap_session(config, _main) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\main.py", line 90, in wrap_session session.exitstatus = doit(config, session) or 0 File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\main.py", line 121, in _main config.hook.pytest_runtestloop(session=session) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__ return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in _MultiCall(methods, kwargs, hook.spec_opts).execute() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute res = hook_impl.function(*args) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\main.py", line 146, in pytest_runtestloop item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__ return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in _MultiCall(methods, kwargs, hook.spec_opts).execute() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 595, in execute return _wrapped_call(hook_impl.function(*args), self.execute) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 247, in _wrapped_call call_outcome = _CallOutcome(func) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__ self.result = func() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute res = hook_impl.function(*args) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\runner.py", line 65, in pytest_runtest_protocol runtestprotocol(item, nextitem=nextitem) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\runner.py", line 75, in runtestprotocol reports.append(call_and_report(item, "call", log)) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\runner.py", line 119, in call_and_report call = call_runtest_hook(item, when, **kwds) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\runner.py", line 137, in call_runtest_hook return CallInfo(lambda: ihook(item=item, **kwds), when=when) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\runner.py", line 149, in __init__ self.result = func() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\runner.py", line 137, in return CallInfo(lambda: ihook(item=item, **kwds), when=when) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__ return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in _MultiCall(methods, kwargs, hook.spec_opts).execute() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 595, in execute return _wrapped_call(hook_impl.function(*args), self.execute) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 247, in _wrapped_call call_outcome = _CallOutcome(func) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__ self.result = func() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute res = hook_impl.function(*args) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\runner.py", line 90, in pytest_runtest_call item.runtest() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\python.py", line 1406, in runtest self.ihook.pytest_pyfunc_call(pyfuncitem=self) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__ return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in _MultiCall(methods, kwargs, hook.spec_opts).execute() File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute res = hook_impl.function(*args) File "C:\Continuum\Anaconda3\lib\site-packages\_pytest\python.py", line 286, in pytest_pyfunc_call testfunction(**testargs) File "C:\Users\dweng\PycharmProjects\lumar_ingestion\ingestion_workflows\full_table_workflow_test.py", line 40, in test_SAP_invoice tab_output = workflow.execute(tab) File "C:\Users\dweng\PycharmProjects\lumar_ingestion\ingestion_workflows\full_table_workflow.py", line 85, in execute data = workflow.execute(data) File "C:\Users\dweng\PycharmProjects\lumar_ingestion\Workflow\workflow.py", line 25, in execute output = self.steps[0].execute(data) File "C:\Users\dweng\PycharmProjects\lumar_ingestion\ingestion_workflow_modules\import_to_dataframe.py", line 61, in execute hardware_log.info(cpu_util_pct_pre, free_mem_gb_pre) Message: 38.5 Arguments: (8.87662592,) How to fix the problem? cheers From python at mrabarnett.plus.com Thu Sep 15 11:17:19 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Sep 2016 16:17:19 +0100 Subject: logging TypeError: not all arguments converted during string formatting In-Reply-To: References: Message-ID: On 2016-09-15 15:57, Daiyue Weng wrote: > Hi, I am trying to record memory and CPU usages and load a logger from an > external config file (logging.conf), > [snip] > > import logging > > import psutil > > logging.config.fileConfig('logging.conf') > > hardware_log = logging.getLogger(HARDWARELOGNAME) > > free_mem_gb_pre = psutil.virtual_memory().available / 1000000000. > cpu_util_pct_pre = psutil.cpu_percent() > > hardware_log.info(cpu_util_pct_pre, free_mem_gb_pre) > > > I got the following errors, > > --- Logging error --- > Traceback (most recent call last): > File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 980, in emit > msg = self.format(record) > File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 830, in format > return fmt.format(record) > File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 567, in format > record.message = record.getMessage() > File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 330, in getMessage > msg = msg % self.args > TypeError: not all arguments converted during string formatting [snip] > File "C:\Users\dweng\PycharmProjects\lumar_ingestion\ingestion_workflow_modules\import_to_dataframe.py", > line 61, in execute > hardware_log.info(cpu_util_pct_pre, free_mem_gb_pre) > Message: 38.5 > Arguments: (8.87662592,) > > > How to fix the problem? > The doc for logging.info says: logging.info(msg, *args, **kwargs) In this line of your code: hardware_log.info(cpu_util_pct_pre, free_mem_gb_pre) you're passing in 2 values. The first (38.5) is being treated as the message template (a format string) and the second (8.87662592) as the value to be put into the template. What you should be doing is something like: logging.info('cpu_util_pct_pre is %s, free_mem_gb_pre is %s', cpu_util_pct_pre, free_mem_gb_pre) From __peter__ at web.de Thu Sep 15 12:49:09 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Sep 2016 18:49:09 +0200 Subject: logging TypeError: not all arguments converted during string formatting References: Message-ID: Daiyue Weng wrote: > Hi, I am trying to record memory and CPU usages and load a logger from an > external config file (logging.conf), [snip] One important debugging strategy is to try and find the minimal example that produces a problem. In this case you can provoke the the behaviour you are seeing with two lines of Python: >>> import logging >>> logging.warn(1, 2) --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.4/logging/__init__.py", line 978, in emit msg = self.format(record) File "/usr/lib/python3.4/logging/__init__.py", line 828, in format return fmt.format(record) File "/usr/lib/python3.4/logging/__init__.py", line 565, in format record.message = record.getMessage() File "/usr/lib/python3.4/logging/__init__.py", line 328, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Call stack: File "", line 1, in Message: 1 Arguments: (2,) Please make an effort to remove the irrelevant stuff before you come here to ask for help next time. Thank you. From martinjp376 at gmail.com Thu Sep 15 14:06:26 2016 From: martinjp376 at gmail.com (kerbingamer376) Date: Thu, 15 Sep 2016 11:06:26 -0700 (PDT) Subject: Playing an audio file, but not waiting for it to finish? Message-ID: Hi, I have a library that allows me to play sound files. However, the play function waits for the sound to finish before it returns, and I'd like to be able to start the sound playing, and then have it return immediately so my program can continue, but also be able to know when the sound finishes. Is this possible, without modifying the library? From martinjp376 at gmail.com Thu Sep 15 14:07:14 2016 From: martinjp376 at gmail.com (kerbingamer376) Date: Thu, 15 Sep 2016 11:07:14 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: Message-ID: <5f27caa5-8890-444c-87ba-bbdc6cf9c2df@googlegroups.com> On Thursday, September 15, 2016 at 8:13:05 AM UTC+1, meInvent bbird wrote: > how to automate java application in window using python > > 1. scroll up or down of scroll bar > 2. click button > 3. type text in textbox wtf? From rosuav at gmail.com Thu Sep 15 14:18:03 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Sep 2016 04:18:03 +1000 Subject: Playing an audio file, but not waiting for it to finish? In-Reply-To: References: Message-ID: On Fri, Sep 16, 2016 at 4:06 AM, kerbingamer376 wrote: > I have a library that allows me to play sound files. However, the play function waits for the sound to finish before it returns, and I'd like to be able to start the sound playing, and then have it return immediately so my program can continue, but also be able to know when the sound finishes. Is this possible, without modifying the library? > It depends on the library. What you want is often called "asynchronous playing", and it's usually possible, one way or another. As a very simple example, creating a subprocess ['vlc', '--play-and-exit', 'some/audio/file'] will let you start something playing, and then have the options to wait for the process to exit (equivalent to what you have), be notified when it exits (what you're asking for), or kill the process (another important feature, esp if you want to start a different sound playing). But it's all up to the library. ChrisA From steve+python at pearwood.info Thu Sep 15 14:38:43 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 16 Sep 2016 04:38:43 +1000 Subject: Playing an audio file, but not waiting for it to finish? References: Message-ID: <57daeab5$0$1583$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Sep 2016 04:06 am, kerbingamer376 wrote: > Hi, > I have a library that allows me to play sound files. However, the play > function waits for the sound to finish before it returns, and I'd like to > be able to start the sound playing, and then have it return immediately so > my program can continue, but also be able to know when the sound finishes. > Is this possible, without modifying the library? Call the library function from a separate thread. See the threading module for details. You may have to be careful that no more than one thread ever calls the library, since it is unlikely to be thread-safe. If it is thread-safe, it would probably already offer an option to play in the background. And performance may suffer: depending on how the library is written, you may find that sound stutters or pauses as control passes back and forth between your main thread and the thread playing the sound. I guess you'll have to try it and see. If threading doesn't work for you, try the multiprocessing library instead. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 15 14:41:38 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 16 Sep 2016 04:41:38 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <57d9ef4e$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57daeb64$0$1583$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Sep 2016 11:45 pm, Grant Edwards wrote: > On 2016-09-15, Steve D'Aprano wrote: >> On Thu, 15 Sep 2016 06:19 am, breamoreboy at gmail.com wrote: >> >>> It is so blantantly obvious that the world is not flat I find this >>> discussion flabbergasting. >> >> You wouldn't say that if you lived in Kanvas, or the west coast of >> Ireland. >> >> I'm told that a few years ago somebody accidentally dumped a trailer load >> of soil by the side of the road in Kanvas, and within a day some >> enterprising entrepreneur had set up a thriving roadside business >> offering mountain-climbing tours to the locals. > > Kanvas? Oh vorry about that, that'v a villy mivtake. I obsiouvly meant to type Kansav. -- Vteve From steve+python at pearwood.info Thu Sep 15 15:06:06 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 16 Sep 2016 05:06:06 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> Message-ID: <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Sep 2016 04:02 pm, Random832 wrote: > On Wed, Sep 14, 2016, at 23:12, Steve D'Aprano wrote: >> Yes it does. Even an infinitely large flat plane has a horizon almost >> identical to the actual horizon. > > Your link actually doesn't support the latter claim, it goes into some > detail on why it wouldn't if it were infinitely large due to > gravitational effects on light. No, the horizon would still be horizontal. It merely wouldn't *look* horizontal, an optical illusion. And even there, I have my doubts. In a universe where at least one infinitely large flat planet existed, gravity would clearly have to be significantly different from our universe's gravity, lest the universe be destroyed. In the scenario given by the article, the flat earth is acting as a Newtonian black hole: light cannot escape the planet. In addition, anything that came into range of the flat earth's gravity -- which would be *everything* in the universe -- would experience a 1 gee force[1] towards the earth, no matter how far away it was. There would be a steady rain of meteors, comets and even stars onto the planet. The planet would also be gravitationally unstable in the horizontal direction. Consider a single atom somewhere in the flat plane. It is gravitationally pulled by an infinite number of other atoms in one direction, say to the left, balanced by an infinite number in the opposite direction, to the right. But those infinite forces will only be in balance if the body of the planet is utterly, perfectly, 100% uniform. Any tiny variation in density will lead to an inbalance in one direction or another, which will increase the variations in density and hence increasing the preferential gravitational force. For a normal planet, the gravitational forces are typically smaller than the electromagnet repulsion of atoms to each other, and so there's a limit to how densely packed the planet will be. But in an infinitely large planet, the forces can increase without limit, leading to the planet either collapsing into a relativistic black hole (it's already a Newtonian black hole!) or being torn apart. Or both. In any case, even if the earth is flat, it's not infinitely big. We know that because some stars dip below the horizon. Unless there are convenient tunnels for them to travel through... Personally, I'm more fond of the Hollow Earth theory. The earth is a sphere, but it's a hollow sphere, and we're on the inside... :-) [1] Yes I know gee is a unit of acceleration, not force. Someone else can do the dimensional analysis, there's a limit to how much care I'm going to put into counter-factual physics like infinitely large flat planets. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Thu Sep 15 15:11:41 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Sep 2016 05:11:41 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <57daeb64$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <57d9ef4e$0$1585$c3e8da3$5496439d@news.astraweb.com> <57daeb64$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 16, 2016 at 4:41 AM, Steve D'Aprano wrote: >> Kanvas? > > Oh vorry about that, that'v a villy mivtake. I obsiouvly meant to type > Kansav. We're not in Kanvas any more, Toto! ChrisA From random832 at fastmail.com Thu Sep 15 15:19:39 2016 From: random832 at fastmail.com (Random832) Date: Thu, 15 Sep 2016 15:19:39 -0400 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <98f159a9-614b-40f5-9420-e5d226da3a22@googlegroups.com> <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1473967179.4003616.727054793.608DB2E2@webmail.messagingengine.com> On Thu, Sep 15, 2016, at 15:06, Steve D'Aprano wrote: > No, the horizon would still be horizontal. It merely wouldn't *look* > horizontal, an optical illusion. I guess that depends on your definition of what a horizon is - and what a straight line is, if not the path followed by a beam of light. From steve+python at pearwood.info Thu Sep 15 15:31:05 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 16 Sep 2016 05:31:05 +1000 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> <1473967179.4003616.727054793.608DB2E2@webmail.messagingengine.com> Message-ID: <57daf6fa$0$1584$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Sep 2016 05:19 am, Random832 wrote: > On Thu, Sep 15, 2016, at 15:06, Steve D'Aprano wrote: >> No, the horizon would still be horizontal. It merely wouldn't *look* >> horizontal, an optical illusion. > > I guess that depends on your definition of what a horizon is - and what > a straight line is, if not the path followed by a beam of light. Light follows geodesics, not straight lines. http://mathworld.wolfram.com/Geodesic.html Hmmm... actually that suggests that an infinite flat earth is *not* a Newtonian black hole, as I suggested, since light in Newtonian physics travels in straight lines. So it would be an unusual kind of relativistic black hole. (A Newtonian black hole is just a star or planet sufficiently big that the escape velocity is greater than the speed of light. Hmmm again... what is the escape velocity of an infinite plane with gravitational acceleration of 1 gee?) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Thu Sep 15 15:33:48 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 15 Sep 2016 22:33:48 +0300 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] References: <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> <1473967179.4003616.727054793.608DB2E2@webmail.messagingengine.com> Message-ID: <87poo5nejn.fsf@elektro.pacujo.net> Random832 : > On Thu, Sep 15, 2016, at 15:06, Steve D'Aprano wrote: >> No, the horizon would still be horizontal. It merely wouldn't *look* >> horizontal, an optical illusion. > > I guess that depends on your definition of what a horizon is - and > what a straight line is, if not the path followed by a beam of light. It is actually quite interesting how the brain forms an accurate idea of a straight line and, say, a circle. Whenever you get a new pair of glasses, the brain needs a recalibration and manages to do it within a week. I don't think it has anything with "the path followed by a beam of light." Marko From ethan at stoneleaf.us Thu Sep 15 15:38:25 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 15 Sep 2016 12:38:25 -0700 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <1473967179.4003616.727054793.608DB2E2@webmail.messagingengine.com> References: <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> <1473967179.4003616.727054793.608DB2E2@webmail.messagingengine.com> Message-ID: <57DAF8B1.9010009@stoneleaf.us> On 09/15/2016 12:19 PM, Random832 wrote: > On Thu, Sep 15, 2016, at 15:06, Steve D'Aprano wrote: >> No, the horizon would still be horizontal. It merely wouldn't *look* >> horizontal, an optical illusion. > > I guess that depends on your definition of what a horizon is - and what > a straight line is, if not the path followed by a beam of light. Beams of light can be bent by both matter and gravity. -- ~Ethan~ From random832 at fastmail.com Thu Sep 15 15:55:46 2016 From: random832 at fastmail.com (Random832) Date: Thu, 15 Sep 2016 15:55:46 -0400 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <57daf6fa$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <57d8de9e$0$1535$c3e8da3$5496439d@news.astraweb.com> <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> <1473967179.4003616.727054793.608DB2E2@webmail.messagingengine.com> <57daf6fa$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1473969346.4011776.727091025.489FDD31@webmail.messagingengine.com> On Thu, Sep 15, 2016, at 15:31, Steve D'Aprano wrote: > Light follows geodesics, not straight lines. What is a straight line on a curved space if not a geodesic? That was actually what I was getting at. From greg.ewing at canterbury.ac.nz Fri Sep 16 02:08:37 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 16 Sep 2016 18:08:37 +1200 Subject: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies] In-Reply-To: <87poo5nejn.fsf@elektro.pacujo.net> References: <001f696f-437d-4cd2-93c4-de0249c72310@googlegroups.com> <57d8fa49$0$1532$c3e8da3$5496439d@news.astraweb.com> <8e5cd6e8-c311-88af-2802-67bc9c87b2c6@dop.com> <3dbdf8e3-5fc2-4423-92d4-170cf9680f7a@googlegroups.com> <57da119e$0$1609$c3e8da3$5496439d@news.astraweb.com> <1473919321.2675893.726316449.7A9734EE@webmail.messagingengine.com> <57daf11f$0$1610$c3e8da3$5496439d@news.astraweb.com> <1473967179.4003616.727054793.608DB2E2@webmail.messagingengine.com> <87poo5nejn.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > It is actually quite interesting how the brain forms an accurate idea of > a straight line and, say, a circle. Whenever you get a new pair of > glasses, the brain needs a recalibration and manages to do it within a > week. I had an interesting experience in that area a few years ago. One of the entries in the PyWeek[1] game programming competition was a platform game set on the inside of a circular world. You saw a small part of the world at a time side-on, with the ground curving up slightly to the left and right. After playing for a while, my brain must have trained itself to see the curved ground as straight, because when I looked away, all horizontal straight lines looked like they were curved *downwards* slightly! [1] A competition for Python-based games, so getting a bit closer to being back on-topic. -- Greg From jobmattcon at gmail.com Fri Sep 16 02:22:32 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 15 Sep 2016 23:22:32 -0700 (PDT) Subject: how to robot recognize basic geometric object in window or ubuntu window Message-ID: i am doing a robot to automate window itself with python i give some basic png diagram such as square, circle, triangle and hope it recognize all kinds of square like things in window such as textbox of notepad etc how a robot recognize basic geometric object in window or ubuntu window i use cv2 template matching method and then draw black square or rectangle as a template however, it can recognize the size of template only and recognize not a square diagram from capture screen then i try a black ground and white line of square, it recognize a File in menu i feel that it need to try all kinds of color, and size in order to recognize similar object in screen capture diagram how do a robot recognize many color and size in seconds? From jobmattcon at gmail.com Fri Sep 16 02:54:22 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 15 Sep 2016 23:54:22 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> Message-ID: <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence D?Oliveiro wrote: > On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent bbird wrote: > > how to automate java application in window using python > > > > 1. scroll up or down of scroll bar > > 2. click button > > 3. type text in textbox > > Well, don?t leave us in suspense! Give us the link to your blog post! i do not have blog post, search nothing about this in google, is it possible to automate java application with python? From jobmattcon at gmail.com Fri Sep 16 02:56:53 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 15 Sep 2016 23:56:53 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <513674e4-69fa-49b9-80e5-01a7e23e7dea@googlegroups.com> References: <513674e4-69fa-49b9-80e5-01a7e23e7dea@googlegroups.com> Message-ID: <117e6c0d-ba97-4863-bc04-666e8fbd0d55@googlegroups.com> On Friday, September 16, 2016 at 2:26:47 AM UTC+8, bream... at gmail.com wrote: > On Thursday, September 15, 2016 at 8:13:05 AM UTC+1, meInvent bbird wrote: > > how to automate java application in window using python > > > > 1. scroll up or down of scroll bar > > 2. click button > > 3. type text in textbox > > Please read this http://www.catb.org/esr/faqs/smart-questions.html and then this http://sscce.org/ and then rephrase your post. > > Kindest regards. > > Mark Lawrence. i find this, but it is not python, it is a product http://sqa.stackexchange.com/questions/18134/python-based-test-automation-tools-for-desktop-applications From lawrencedo99 at gmail.com Fri Sep 16 03:01:12 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 16 Sep 2016 00:01:12 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> Message-ID: On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird wrote: > On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence D?Oliveiro > wrote: >> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent bbird >> wrote: >>> how to automate java application in window using python >>> >>> 1. scroll up or down of scroll bar >>> 2. click button >>> 3. type text in textbox >> >> Well, don?t leave us in suspense! Give us the link to your blog post! > > i do not have blog post, Oh, now you make us sad. I thought you were promoting a blog post where you tell us ?how to automate java application in window using python? using just 3 steps! But it turns out you have nothing. You are an empty promiser. From ja9749.2009 at my.bristol.ac.uk Fri Sep 16 03:33:33 2016 From: ja9749.2009 at my.bristol.ac.uk (Jamie Ansell) Date: Fri, 16 Sep 2016 08:33:33 +0100 Subject: Requests for webbrowser module In-Reply-To: References: Message-ID: Thanks for your help, I realise that what I wanted was chromes default new tab page, not a blank page. 'about:blank' worked fine but it wasn't what I wanted sorry. I'll try the CTRL+4 later and see it that works. On 14 Sep 2016 21:11, "John Gordon" wrote: > In Jamie < > ja9749 at my.bristol.ac.uk> writes: > > > I am not sure if this is an intended consequence but when using the > > webbrowser module to open a new blank browser tab in chrome it opens it > > in a new browser window instead of using the current window. Providing > > There is an internal setting within Chrome that controls whether new pages > are opened in a new tab or a new window. Perhaps that is your issue? > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Fri Sep 16 03:54:17 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 Sep 2016 09:54:17 +0200 Subject: Expected type 'optional[bytes]' got 'str' instead References: Message-ID: > Daiyue Weng wrote: [Please answer to the mailing list instead of sending private emails] > On 13 September 2016 at 12:37, Peter Otten <__peter__ at web.de> wrote: >> Daiyue Weng wrote: >>> Hi, I have the following piece of code, >>> >>> rootPath = os.path.abspath(__file__) >>> >>> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0] >>> >>> >>> PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit, >>> >>> Expected type 'optional[bytes]' got 'str' instead >>> >>> >>> If I changed it to, >>> >>> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit(b'\\', 1)[0] >>> >>> Python game me errors, >>> >>> TypeError: Can't convert 'bytes' object to str implicitly >>> >>> How to fix it? >> >> Do you use Python 2 or 3? >> >> Is your version the one PyCharm expects and supports? If yes, consider >> filing a bug report (for PyCharm, not Python). >> >> You should of course still follow Chris' advice and use os.path to >> manipulate file paths. > Hi, I am using Python 3.5.1 on PyCharm. Is it a bug in PyCharm? I think it is. From cloverobert at gmail.com Fri Sep 16 05:31:27 2016 From: cloverobert at gmail.com (Robert Clove) Date: Fri, 16 Sep 2016 15:01:27 +0530 Subject: Find Nested group in LDAP by this i mean group in group Message-ID: Hi, I was looking for search query in LDAP for nested group memebership. It would be great if someone can provide the python code for the same. Regards From auriocus at gmx.de Fri Sep 16 06:22:21 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 16 Sep 2016 12:22:21 +0200 Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> Message-ID: Am 16.09.16 um 09:01 schrieb Lawrence D?Oliveiro: > On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird > wrote: >> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence >> D?Oliveiro wrote: >>> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent >>> bbird wrote: >>>> how to automate java application in window using python >>>> >>>> 1. scroll up or down of scroll bar 2. click button 3. type text >>>> in textbox >>> >>> Well, don?t leave us in suspense! Give us the link to your blog >>> post! >> >> i do not have blog post, > > Oh, now you make us sad. I thought you were promoting a blog post > where you tell us ?how to automate java application in window using > python? using just 3 steps! But it turns out you have nothing. You > are an empty promiser. You are being mean. It is quite evident that English is not his first language, and highly probable that this was actually the question "How do I automate a Java application using Python?" I don't have a real answer myself, but maybe using Jython one can get access to the Java objects underlying the application (and then, of course, execute methods of the GUI objects). This depends on the GUI toolkit (Swing/SWT) and knowledge of the applications' structure, of course. Another (less robust) way of desktop automation is Sikuli http://www.sikuli.org/ (Windows only, I think) Christian From jobmattcon at gmail.com Fri Sep 16 07:24:49 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 04:24:49 -0700 (PDT) Subject: why this code loop forever after a draw a rectangle Message-ID: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> im = img.copy() cntcounter = 0 for cnt in contours: epsilon = 0.1*cv2.arcLength(cnt,True) approx = cv2.approxPolyDP(cnt,epsilon,True) #peri = cv2.arcLength(cnt, True) #approx = cv2.approxPolyDP(c, 0.5 * peri, True) #print("len(approx)="+str(len(approx))) if len(approx) == 4: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") x,y,w,h = cv2.boundingRect(cnt) print("here2") while im is None: time.sleep(1) if im is not None: print("here3") im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) From python at bdurham.com Fri Sep 16 07:29:00 2016 From: python at bdurham.com (Malcolm Greene) Date: Fri, 16 Sep 2016 07:29:00 -0400 Subject: Discover all non-standard library modules imported by a script Message-ID: <1474025340.4016314.727688825.3909182D@webmail.messagingengine.com> Looking for suggestions on how, given a main script, discover all the non-standard library modules imported across all modules, eg. the modules that other modules import, etc. I'm not looking to discover dynamic imports or other edge cases, just the list modules loaded via "import " and "from import ...". I know I could write a script to do this, but certainly there must be such a capability in the standard library? Use case: Discovering list of modules to use for building a Python 3.5 zipapp distributable. Thank you, Malcolm From liik.joonas at gmail.com Fri Sep 16 07:33:49 2016 From: liik.joonas at gmail.com (Joonas Liik) Date: Fri, 16 Sep 2016 14:33:49 +0300 Subject: why this code loop forever after a draw a rectangle In-Reply-To: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> Message-ID: On 16 September 2016 at 14:24, meInvent bbird wrote: > im = img.copy() > cntcounter = 0 > for cnt in contours: > epsilon = 0.1*cv2.arcLength(cnt,True) > approx = cv2.approxPolyDP(cnt,epsilon,True) > #peri = cv2.arcLength(cnt, True) > #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > #print("len(approx)="+str(len(approx))) > if len(approx) == 4: > print("approx=" + str(approx)) > cntcounter = cntcounter + 1 > print("here1") > x,y,w,h = cv2.boundingRect(cnt) > print("here2") > while im is None: > time.sleep(1) > if im is not None: > print("here3") > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > > cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > -- > https://mail.python.org/mailman/listinfo/python-list not sure but.. this bit reads really suspicious: while im is None: time.sleep(1) if im is ever None then how will it ever become not None? unless there is some other thread at work i can't really see this happening. and if there is some other thread at work then there is probably some better solution than sleep() From rosuav at gmail.com Fri Sep 16 08:13:05 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Sep 2016 22:13:05 +1000 Subject: Discover all non-standard library modules imported by a script In-Reply-To: <1474025340.4016314.727688825.3909182D@webmail.messagingengine.com> References: <1474025340.4016314.727688825.3909182D@webmail.messagingengine.com> Message-ID: On Fri, Sep 16, 2016 at 9:29 PM, Malcolm Greene wrote: > Looking for suggestions on how, given a main script, discover all the > non-standard library modules imported across all modules, eg. the > modules that other modules import, etc. I'm not looking to discover > dynamic imports or other edge cases, just the list modules loaded via > "import " and "from import ...". I know I could write a > script to do this, but certainly there must be such a capability in the > standard library? > > Use case: Discovering list of modules to use for building a Python 3.5 > zipapp distributable. > Possibly not what you're thinking of, but try creating a clean virtual environment (python3 -m venv env) and installing no packages, and then watch for ImportError. As you find them, record stuff into requirements.txt and "pip install -r requirements.txt", until you have a working program - at which point requirements.txt should have every non-standard thing you're using. ChrisA From jobmattcon at gmail.com Fri Sep 16 08:18:27 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 05:18:27 -0700 (PDT) Subject: why this code loop forever after a draw a rectangle In-Reply-To: References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> Message-ID: <89efcae7-f1b3-4181-8c21-d455304f7ddc@googlegroups.com> i follow this post to give some time it to operate, wait a long time still looping http://answers.opencv.org/question/60094/libpng-warning-image-width-is-zero-in-ihdr/ i can not stand this Ninja coding life any more, i have to open my code for ask this error import cv2 import numpy as np #from matplotlib import pyplot as plt import time #print("1=" + str(int(sys.argv[1]))) #print("2=" + str(int(sys.argv[2]))) #print("3=" + str(int(sys.argv[3]))) img_rgb = cv2.imread(r'C:\Users\martin\Documents\scree2.png') img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(r'C:\Users\martin\Documents\dragob.png',0) w, h = template.shape[::-1] res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED) threshold = 0.64 loc = np.where( res >= threshold) pt = [(0,0)] while not zip(*loc[::-1]): threshold = threshold - 0.02 loc = np.where( res >= threshold) counter = 1 print("threshold="+str(threshold)) for pt2 in zip(*loc[::-1]): cv2.rectangle(img_rgb, pt2, (pt2[0] + w, pt2[1] + h), (0,0,255), 2) pt = pt2 crop_img = img_rgb[pt[1]:(pt[1]+h), pt[0]:(pt[0]+w)] counter = counter + 1 cv2.imwrite("C:\\Users\\tester\\Documents\\res.png",crop_img) #import cv2 #winName = "Movement Indicator" #cv2.namedWindow(winName, cv2.WINDOW_NORMAL) img = cv2.imread(r'C:\Users\tester\Documents\res.png',1) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) height, width = gray.shape edges = cv2.Canny(gray,height,width,apertureSize = 3) #edges = cv2.Canny(gray,30,200) #gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) #ret,thresh = cv2.threshold(edges.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE,0) ret,thresh = cv2.threshold(edges,250,150,0) contours,hierarchy = cv2.findContours(thresh, 1, 2) #contours = sorted(contours, key = cv2.contourArea, reverse = True)[:10] im = img.copy() cntcounter = 0 for cnt in contours: epsilon = 0.1*cv2.arcLength(cnt,True) approx = cv2.approxPolyDP(cnt,epsilon,True) #peri = cv2.arcLength(cnt, True) #approx = cv2.approxPolyDP(c, 0.5 * peri, True) #print("len(approx)="+str(len(approx))) if len(approx) == 4: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") x,y,w,h = cv2.boundingRect(cnt) print("here2") #im = img.copy() while im is None: time.sleep(1) if im is not None: print("here3") im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) #cv2.imwrite("C:\\Users\\martin\\Documents\\masda"+str(cntcounter)+".png",imi) #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) On Friday, September 16, 2016 at 7:34:04 PM UTC+8, Waffle wrote: > On 16 September 2016 at 14:24, meInvent bbird wrote: > > im = img.copy() > > cntcounter = 0 > > for cnt in contours: > > epsilon = 0.1*cv2.arcLength(cnt,True) > > approx = cv2.approxPolyDP(cnt,epsilon,True) > > #peri = cv2.arcLength(cnt, True) > > #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > > #print("len(approx)="+str(len(approx))) > > if len(approx) == 4: > > print("approx=" + str(approx)) > > cntcounter = cntcounter + 1 > > print("here1") > > x,y,w,h = cv2.boundingRect(cnt) > > print("here2") > > while im is None: > > time.sleep(1) > > if im is not None: > > print("here3") > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > > #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > > #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > > #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > > > > > cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > -- > > https://mail.python.org/mailman/listinfo/python-list > > not sure but.. this bit reads really suspicious: > > while im is None: > time.sleep(1) > > if im is ever None then how will it ever become not None? unless there > is some other thread at work i can't really see this happening. > and if there is some other thread at work then there is probably some > better solution than sleep() From jobmattcon at gmail.com Fri Sep 16 08:24:48 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 05:24:48 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> Message-ID: <2c1869f1-48ea-46be-9cd5-584c16937262@googlegroups.com> you are right, english is not my first language i just talk as simple as i can, i do not know previous talking is mean On Friday, September 16, 2016 at 6:22:34 PM UTC+8, Christian Gollwitzer wrote: > Am 16.09.16 um 09:01 schrieb Lawrence D?Oliveiro: > > On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird > > wrote: > >> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence > >> D?Oliveiro wrote: > >>> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent > >>> bbird wrote: > >>>> how to automate java application in window using python > >>>> > >>>> 1. scroll up or down of scroll bar 2. click button 3. type text > >>>> in textbox > >>> > >>> Well, don?t leave us in suspense! Give us the link to your blog > >>> post! > >> > >> i do not have blog post, > > > > Oh, now you make us sad. I thought you were promoting a blog post > > where you tell us ?how to automate java application in window using > > python? using just 3 steps! But it turns out you have nothing. You > > are an empty promiser. > > You are being mean. It is quite evident that English is not his first > language, and highly probable that this was actually the question "How > do I automate a Java application using Python?" > > I don't have a real answer myself, but maybe using Jython one can get > access to the Java objects underlying the application (and then, of > course, execute methods of the GUI objects). This depends on the GUI > toolkit (Swing/SWT) and knowledge of the applications' structure, of > course. Another (less robust) way of desktop automation is Sikuli > http://www.sikuli.org/ (Windows only, I think) > > Christian From fabiofz at gmail.com Fri Sep 16 10:17:37 2016 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 16 Sep 2016 11:17:37 -0300 Subject: how to automate java application in window using python In-Reply-To: <2c1869f1-48ea-46be-9cd5-584c16937262@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <2c1869f1-48ea-46be-9cd5-584c16937262@googlegroups.com> Message-ID: Take a look at https://pyautogui.readthedocs.io/en/latest/ On Fri, Sep 16, 2016 at 9:24 AM, meInvent bbird wrote: > you are right, english is not my first language > > i just talk as simple as i can, i do not know previous talking is mean > > > On Friday, September 16, 2016 at 6:22:34 PM UTC+8, Christian Gollwitzer > wrote: > > Am 16.09.16 um 09:01 schrieb Lawrence D?Oliveiro: > > > On Friday, September 16, 2016 at 6:55:07 PM UTC+12, meInvent bbird > > > wrote: > > >> On Thursday, September 15, 2016 at 3:52:41 PM UTC+8, Lawrence > > >> D?Oliveiro wrote: > > >>> On Thursday, September 15, 2016 at 7:13:05 PM UTC+12, meInvent > > >>> bbird wrote: > > >>>> how to automate java application in window using python > > >>>> > > >>>> 1. scroll up or down of scroll bar 2. click button 3. type text > > >>>> in textbox > > >>> > > >>> Well, don?t leave us in suspense! Give us the link to your blog > > >>> post! > > >> > > >> i do not have blog post, > > > > > > Oh, now you make us sad. I thought you were promoting a blog post > > > where you tell us ?how to automate java application in window using > > > python? using just 3 steps! But it turns out you have nothing. You > > > are an empty promiser. > > > > You are being mean. It is quite evident that English is not his first > > language, and highly probable that this was actually the question "How > > do I automate a Java application using Python?" > > > > I don't have a real answer myself, but maybe using Jython one can get > > access to the Java objects underlying the application (and then, of > > course, execute methods of the GUI objects). This depends on the GUI > > toolkit (Swing/SWT) and knowledge of the applications' structure, of > > course. Another (less robust) way of desktop automation is Sikuli > > http://www.sikuli.org/ (Windows only, I think) > > > > Christian > > -- > https://mail.python.org/mailman/listinfo/python-list > From vern.muhr at gmail.com Fri Sep 16 14:40:38 2016 From: vern.muhr at gmail.com (vern.muhr at gmail.com) Date: Fri, 16 Sep 2016 11:40:38 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <117e6c0d-ba97-4863-bc04-666e8fbd0d55@googlegroups.com> References: <513674e4-69fa-49b9-80e5-01a7e23e7dea@googlegroups.com> <117e6c0d-ba97-4863-bc04-666e8fbd0d55@googlegroups.com> Message-ID: <457e76cf-4e6a-481b-979c-fd7661f52c75@googlegroups.com> On Thursday, September 15, 2016 at 11:57:04 PM UTC-7, meInvent bbird wrote: > On Friday, September 16, 2016 at 2:26:47 AM UTC+8, bream... at gmail.com wrote: > > On Thursday, September 15, 2016 at 8:13:05 AM UTC+1, meInvent bbird wrote: > > > how to automate java application in window using python > > > > > > 1. scroll up or down of scroll bar > > > 2. click button > > > 3. type text in textbox > > Check out Sikuli at www.sikuli.org. It uses Jython, but hopefully that is close enough. Best, Vern From gherron at digipen.edu Fri Sep 16 15:14:30 2016 From: gherron at digipen.edu (Gary Herron) Date: Fri, 16 Sep 2016 12:14:30 -0700 Subject: why this code loop forever after a draw a rectangle In-Reply-To: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> Message-ID: <2dd5d078-9360-c64a-7e6b-b7fad7ea5262@digipen.edu> On 09/16/2016 04:24 AM, meInvent bbird wrote: > im = img.copy() > cntcounter = 0 > for cnt in contours: > epsilon = 0.1*cv2.arcLength(cnt,True) > approx = cv2.approxPolyDP(cnt,epsilon,True) > #peri = cv2.arcLength(cnt, True) > #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > #print("len(approx)="+str(len(approx))) > if len(approx) == 4: > print("approx=" + str(approx)) > cntcounter = cntcounter + 1 > print("here1") > x,y,w,h = cv2.boundingRect(cnt) > print("here2") > while im is None: > time.sleep(1) > if im is not None: > print("here3") > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > > cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) These two lines: while im is None: time.sleep(1) are an infinite loop if im is None; Since you haven't told us what im (or img, contours, cv2) are, I can't tell how im might become None, but it does look like you (confusingly) use im for two different things: an img.copy() and a cv2.rectangle, whatever those may be. Pure guesswork: if cv2.rectangle draws a rectangle, what does it return? If it doesn't return anything, the line im = cv2.rectangle(...) is how im gets the value of None. -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From g at crcomp.net Fri Sep 16 15:19:02 2016 From: g at crcomp.net (Don Kuenz) Date: Fri, 16 Sep 2016 19:19:02 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.0-RELEASE? Message-ID: <20160916b@crcomp.net> The installed python packages are shown below. Searches lead me to believe that a PTH option make play a role. ------------------------------------------------------------------------ $ uname -v FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 root at snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC $ pkg info | grep python py27-dnspython-1.14.0 DNS toolkit for Python py27-notify-0.1.1_11 python bindings for libnotify py27-telepathy-python-0.15.19_1 Python bindings for the Telepathy framework python-2.7_2,2 The "meta-port" for the default version of Python interpreter python2-2_3 The "meta-port" for version 2 of the Python interpreter python27-2.7.12 Interpreted object-oriented programming language python3-3_3 The "meta-port" for version 3 of the Python interpreter python34-3.4.5 Interpreted object-oriented programming language $ cd /usr/ports/lang/python $ make config ===> No options to configure ----------------------------------------------------------------------- Thank you, -- Don Kuenz KB7RPU There be triple ways to take, of the eagle or the snake, Or the way of a man with a maid; But the seetest way to me is a ship's upon the sea In the heel of the Northeast Trade. - Kipling From pengyu.ut at gmail.com Fri Sep 16 15:19:54 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Sep 2016 14:19:54 -0500 Subject: How to get the source code of python function being decorated? Message-ID: Hi, See the following example, I am not able to get the source code of the actual function that does the calculation of partial_ratio. Does anybody know what is the correct way of getting the source? /tmp$ ./main.py @functools.wraps(func) def decorator(*args, **kwargs): if args[0] is None or args[1] is None: return 0 return func(*args, **kwargs) /tmp$ cat ./main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: import fuzzywuzzy.fuzz import inspect print inspect.getsource(fuzzywuzzy.fuzz.partial_ratio) -- Regards, Peng From gherron at digipen.edu Fri Sep 16 15:21:14 2016 From: gherron at digipen.edu (Gary Herron) Date: Fri, 16 Sep 2016 12:21:14 -0700 Subject: why this code loop forever after a draw a rectangle In-Reply-To: <89efcae7-f1b3-4181-8c21-d455304f7ddc@googlegroups.com> References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> <89efcae7-f1b3-4181-8c21-d455304f7ddc@googlegroups.com> Message-ID: On 09/16/2016 05:18 AM, meInvent bbird wrote: > i follow this post to give some time it to operate, > wait a long time still looping > > http://answers.opencv.org/question/60094/libpng-warning-image-width-is-zero-in-ihdr/ > > > i can not stand this Ninja coding life any more, > i have to open my code for ask this error > > > import cv2 > import numpy as np > #from matplotlib import pyplot as plt > import time > > #print("1=" + str(int(sys.argv[1]))) > #print("2=" + str(int(sys.argv[2]))) > #print("3=" + str(int(sys.argv[3]))) > > img_rgb = cv2.imread(r'C:\Users\martin\Documents\scree2.png') > img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) > template = cv2.imread(r'C:\Users\martin\Documents\dragob.png',0) > w, h = template.shape[::-1] > > res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED) > threshold = 0.64 > > loc = np.where( res >= threshold) > pt = [(0,0)] > > while not zip(*loc[::-1]): > threshold = threshold - 0.02 > loc = np.where( res >= threshold) > > counter = 1 > print("threshold="+str(threshold)) > for pt2 in zip(*loc[::-1]): > cv2.rectangle(img_rgb, pt2, (pt2[0] + w, pt2[1] + h), (0,0,255), 2) > pt = pt2 > crop_img = img_rgb[pt[1]:(pt[1]+h), pt[0]:(pt[0]+w)] > counter = counter + 1 > > cv2.imwrite("C:\\Users\\tester\\Documents\\res.png",crop_img) > > > #import cv2 > #winName = "Movement Indicator" > #cv2.namedWindow(winName, cv2.WINDOW_NORMAL) > img = cv2.imread(r'C:\Users\tester\Documents\res.png',1) > gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) > height, width = gray.shape > edges = cv2.Canny(gray,height,width,apertureSize = 3) > #edges = cv2.Canny(gray,30,200) > > #gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) > #ret,thresh = cv2.threshold(edges.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE,0) > ret,thresh = cv2.threshold(edges,250,150,0) > contours,hierarchy = cv2.findContours(thresh, 1, 2) > #contours = sorted(contours, key = cv2.contourArea, reverse = True)[:10] > > im = img.copy() > cntcounter = 0 > for cnt in contours: > epsilon = 0.1*cv2.arcLength(cnt,True) > approx = cv2.approxPolyDP(cnt,epsilon,True) > #peri = cv2.arcLength(cnt, True) > #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > #print("len(approx)="+str(len(approx))) > if len(approx) == 4: > print("approx=" + str(approx)) > cntcounter = cntcounter + 1 > print("here1") > x,y,w,h = cv2.boundingRect(cnt) > print("here2") > #im = img.copy() > while im is None: > time.sleep(1) > if im is not None: > print("here3") > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > #cv2.imwrite("C:\\Users\\martin\\Documents\\masda"+str(cntcounter)+".png",imi) > #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > > > > > > > > On Friday, September 16, 2016 at 7:34:04 PM UTC+8, Waffle wrote: >> On 16 September 2016 at 14:24, meInvent bbird wrote: >>> im = img.copy() >>> cntcounter = 0 >>> for cnt in contours: >>> epsilon = 0.1*cv2.arcLength(cnt,True) >>> approx = cv2.approxPolyDP(cnt,epsilon,True) >>> #peri = cv2.arcLength(cnt, True) >>> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) >>> #print("len(approx)="+str(len(approx))) >>> if len(approx) == 4: >>> print("approx=" + str(approx)) >>> cntcounter = cntcounter + 1 >>> print("here1") >>> x,y,w,h = cv2.boundingRect(cnt) >>> print("here2") >>> while im is None: >>> time.sleep(1) >>> if im is not None: >>> print("here3") >>> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) >>> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) >>> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) >>> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) >>> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) >>> >>> >>> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> not sure but.. this bit reads really suspicious: >> >> while im is None: >> time.sleep(1) >> >> if im is ever None then how will it ever become not None? unless there >> is some other thread at work i can't really see this happening. >> and if there is some other thread at work then there is probably some >> better solution than sleep() Reading the manual for opencv, we see that cv2.rectangle does indeed return None: Python: cv.Rectangle(img, pt1, pt2, color, thickness=1, lineType=8, shift=0) ? None So the first pass through your loop does indeed set im to None with the line im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) and the next pass through the loop hits the infinite loop: while im is None: time.sleep(1) -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From tjreedy at udel.edu Fri Sep 16 17:10:56 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Sep 2016 17:10:56 -0400 Subject: Discover all non-standard library modules imported by a script In-Reply-To: <1474025340.4016314.727688825.3909182D@webmail.messagingengine.com> References: <1474025340.4016314.727688825.3909182D@webmail.messagingengine.com> Message-ID: On 9/16/2016 7:29 AM, Malcolm Greene wrote: > Looking for suggestions on how, given a main script, discover all the > non-standard library modules imported across all modules, eg. the > modules that other modules import, etc. I'm not looking to discover > dynamic imports or other edge cases, just the list modules loaded via > "import " and "from import ...". I know I could write a > script to do this, but certainly there must be such a capability in the > standard library? > > Use case: Discovering list of modules to use for building a Python 3.5 > zipapp distributable. You could check the .__file__ attribute of each module in sys.modules for 'site-packages', (or more generally, for non-stdlib locations). -- Terry Jan Reedy From python at mrabarnett.plus.com Fri Sep 16 17:26:30 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Sep 2016 22:26:30 +0100 Subject: why this code loop forever after a draw a rectangle In-Reply-To: <2dd5d078-9360-c64a-7e6b-b7fad7ea5262@digipen.edu> References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> <2dd5d078-9360-c64a-7e6b-b7fad7ea5262@digipen.edu> Message-ID: On 2016-09-16 20:14, Gary Herron wrote: > On 09/16/2016 04:24 AM, meInvent bbird wrote: >> im = img.copy() >> cntcounter = 0 >> for cnt in contours: >> epsilon = 0.1*cv2.arcLength(cnt,True) >> approx = cv2.approxPolyDP(cnt,epsilon,True) >> #peri = cv2.arcLength(cnt, True) >> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) >> #print("len(approx)="+str(len(approx))) >> if len(approx) == 4: >> print("approx=" + str(approx)) >> cntcounter = cntcounter + 1 >> print("here1") >> x,y,w,h = cv2.boundingRect(cnt) >> print("here2") >> while im is None: >> time.sleep(1) >> if im is not None: >> print("here3") >> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) >> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) >> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) >> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) >> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) >> >> >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > > These two lines: > > while im is None: > time.sleep(1) > > are an infinite loop if im is None; > > > Since you haven't told us what im (or img, contours, cv2) are, I can't > tell how im might become None, but it does look like you (confusingly) > use im for two different things: an img.copy() and a cv2.rectangle, > whatever those may be. > > Pure guesswork: if cv2.rectangle draws a rectangle, what does it > return? If it doesn't return anything, the line > im = cv2.rectangle(...) > is how im gets the value of None. > It looks like the OP is using OpenCV. You're right about cv2.rectangle; it does return None. The line: im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) makes a copy of the image im, draws a rectangle on it, and then binds None to im. The copied rectangle is discarded because there's no reference to it, so the entire line in pointless. It basically does the same thing as: im = None only slower! From ned at nedbatchelder.com Fri Sep 16 17:49:30 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 16 Sep 2016 14:49:30 -0700 (PDT) Subject: How to get the source code of python function being decorated? In-Reply-To: References: Message-ID: <423e01fc-fbcd-4319-825f-8ec91addca52@googlegroups.com> On Friday, September 16, 2016 at 3:20:15 PM UTC-4, Peng Yu wrote: > Hi, See the following example, I am not able to get the source code of > the actual function that does the calculation of partial_ratio. Does > anybody know what is the correct way of getting the source? > > /tmp$ ./main.py > @functools.wraps(func) > def decorator(*args, **kwargs): > if args[0] is None or args[1] is None: > return 0 > return func(*args, **kwargs) > > /tmp$ cat ./main.py > #!/usr/bin/env python > # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: > > import fuzzywuzzy.fuzz > import inspect > print inspect.getsource(fuzzywuzzy.fuzz.partial_ratio) > In general, you can't get at the decorated function. Decorators can do anything they want with the function they decorate, including completely ignore it, or store it in a closure, assign it to a global, add it to a data structure, etc. Can you tell us more about the problem you are trying to solve? Why do you want a program that access the source of decorated functions? Maybe there's another way to get at what you need. --Ned. From __peter__ at web.de Fri Sep 16 18:12:09 2016 From: __peter__ at web.de (Peter Otten) Date: Sat, 17 Sep 2016 00:12:09 +0200 Subject: How to get the source code of python function being decorated? References: Message-ID: Peng Yu wrote: > Hi, See the following example, I am not able to get the source code of > the actual function that does the calculation of partial_ratio. Does > anybody know what is the correct way of getting the source? > > /tmp$ ./main.py > @functools.wraps(func) > def decorator(*args, **kwargs): > if args[0] is None or args[1] is None: > return 0 > return func(*args, **kwargs) > > /tmp$ cat ./main.py > #!/usr/bin/env python > # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 > # fileencoding=utf-8: > > import fuzzywuzzy.fuzz > import inspect > print inspect.getsource(fuzzywuzzy.fuzz.partial_ratio) In Python 3 functools.wraps() records the wrapped function as __wrapped__: $ cat tmp.py import functools def spam(func): @functools.wraps(func) def decorator(*args, **kwargs): return func(*args, **kwargs) return decorator @spam def ham(foo, bar): return 42 $ python3 ... >>> import inspect >>> import tmp >>> print(inspect.getsource(tmp.ham)) @functools.wraps(func) def decorator(*args, **kwargs): return func(*args, **kwargs) >>> print(inspect.getsource(tmp.ham.__wrapped__)) @spam def ham(foo, bar): return 42 In Python 2 when you look into the attributes of tmp.ham() using dir() you'll eventually find >>> print inspect.getsource(tmp.ham.__closure__[0].cell_contents) @spam def ham(foo, bar): return 42 but I'm not sure this is general enough to spare you the look into the source code. From python at bdurham.com Fri Sep 16 19:35:40 2016 From: python at bdurham.com (Malcolm Greene) Date: Fri, 16 Sep 2016 19:35:40 -0400 Subject: Discover all non-standard library modules imported by a script In-Reply-To: References: <1474025340.4016314.727688825.3909182D@webmail.messagingengine.com> Message-ID: <1474068940.2862898.728322137.4FC1ABDF@webmail.messagingengine.com> Thanks for your suggestions Chris and Terry. The answer I was looking for is the modulefinder module which is part of the standard lib. Works like a charm! Quote: This module provides a ModuleFinder class that can be used to determine the set of modules imported by a script. modulefinder.py can also be run as a script, giving the filename of a Python script as its argument, after which a report of the imported modules will be printed. https://docs.python.org/3.5/library/modulefinder.html Note there's a similar module for Python 2.7. -- Malcolm From jobmattcon at gmail.com Fri Sep 16 19:46:31 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 16:46:31 -0700 (PDT) Subject: why this code loop forever after a draw a rectangle In-Reply-To: References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> <2dd5d078-9360-c64a-7e6b-b7fad7ea5262@digipen.edu> Message-ID: <70ae33f1-a031-4d8d-88c8-e25d75d7f9b8@googlegroups.com> thank you very much, it out of the loop now. because drawLine function return things i just change drawLine to rectangle, have not thought that rectangle not return thing, just edit the parameter On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote: > On 2016-09-16 20:14, Gary Herron wrote: > > On 09/16/2016 04:24 AM, meInvent bbird wrote: > >> im = img.copy() > >> cntcounter = 0 > >> for cnt in contours: > >> epsilon = 0.1*cv2.arcLength(cnt,True) > >> approx = cv2.approxPolyDP(cnt,epsilon,True) > >> #peri = cv2.arcLength(cnt, True) > >> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > >> #print("len(approx)="+str(len(approx))) > >> if len(approx) == 4: > >> print("approx=" + str(approx)) > >> cntcounter = cntcounter + 1 > >> print("here1") > >> x,y,w,h = cv2.boundingRect(cnt) > >> print("here2") > >> while im is None: > >> time.sleep(1) > >> if im is not None: > >> print("here3") > >> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > >> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > >> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > >> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > >> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > >> > >> > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > > > > > These two lines: > > > > while im is None: > > time.sleep(1) > > > > are an infinite loop if im is None; > > > > > > Since you haven't told us what im (or img, contours, cv2) are, I can't > > tell how im might become None, but it does look like you (confusingly) > > use im for two different things: an img.copy() and a cv2.rectangle, > > whatever those may be. > > > > Pure guesswork: if cv2.rectangle draws a rectangle, what does it > > return? If it doesn't return anything, the line > > im = cv2.rectangle(...) > > is how im gets the value of None. > > > It looks like the OP is using OpenCV. > > You're right about cv2.rectangle; it does return None. > > The line: > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > makes a copy of the image im, draws a rectangle on it, and then binds > None to im. > > The copied rectangle is discarded because there's no reference to it, so > the entire line in pointless. > > It basically does the same thing as: > > im = None > > only slower! From python at bdurham.com Fri Sep 16 19:48:00 2016 From: python at bdurham.com (Malcolm Greene) Date: Fri, 16 Sep 2016 19:48:00 -0400 Subject: Looking for tips and gotchas for working with Python 3.5 zipapp feature Message-ID: <1474069680.2864955.728323729.4FF47454@webmail.messagingengine.com> Looking for tips or edge case gotchas associated with using Python 3.5's new zipapp feature. For those of you wondering what this feature is, see the end of this post for a brief background [1]. Two questions in particular: 1. Are there any issues with deploying scripts that sit in sub- folders beneath the directory being zipped, eg. does zipapp only support a flat folder of scripts or does it recursively zip and path sub-folders? 2. Can additional non-Python files like config files be added to a zipapp without breaking them and if so, how would your script reference these embedded files (by opening up the zipapp as a zip archive and navigating from there?). Thank you, Malcolm [1] The zipapp feature of Python 3.5 is pretty cool: It allows you to package your Python scripts in a single executable zip file. This isn't a replacement for tools like PyInstaller or Py2Exe, eg. it doesn't bundle the Python interpreter in the zip file, but it's a clean way to distribute multi-file scripts in environments where you have control over users' Python setups. Here's the manual page: zipapp ? Manage executable python zip archives https://docs.python.org/3/library/zipapp.html From jobmattcon at gmail.com Fri Sep 16 19:48:09 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 16:48:09 -0700 (PDT) Subject: why this code loop forever after a draw a rectangle In-Reply-To: <70ae33f1-a031-4d8d-88c8-e25d75d7f9b8@googlegroups.com> References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> <2dd5d078-9360-c64a-7e6b-b7fad7ea5262@digipen.edu> <70ae33f1-a031-4d8d-88c8-e25d75d7f9b8@googlegroups.com> Message-ID: <3bd2071f-d0cf-4044-b2bb-778f4897129a@googlegroups.com> img is the image im is a new memory of image using img.copy() On Saturday, September 17, 2016 at 7:46:42 AM UTC+8, meInvent bbird wrote: > thank you very much, > it out of the loop now. > because drawLine function return things > > i just change drawLine to rectangle, > have not thought that rectangle not return thing, just edit the parameter > > > > On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote: > > On 2016-09-16 20:14, Gary Herron wrote: > > > On 09/16/2016 04:24 AM, meInvent bbird wrote: > > >> im = img.copy() > > >> cntcounter = 0 > > >> for cnt in contours: > > >> epsilon = 0.1*cv2.arcLength(cnt,True) > > >> approx = cv2.approxPolyDP(cnt,epsilon,True) > > >> #peri = cv2.arcLength(cnt, True) > > >> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > > >> #print("len(approx)="+str(len(approx))) > > >> if len(approx) == 4: > > >> print("approx=" + str(approx)) > > >> cntcounter = cntcounter + 1 > > >> print("here1") > > >> x,y,w,h = cv2.boundingRect(cnt) > > >> print("here2") > > >> while im is None: > > >> time.sleep(1) > > >> if im is not None: > > >> print("here3") > > >> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > >> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > > >> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > > >> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > > >> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > >> > > >> > > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > > > > > > > > These two lines: > > > > > > while im is None: > > > time.sleep(1) > > > > > > are an infinite loop if im is None; > > > > > > > > > Since you haven't told us what im (or img, contours, cv2) are, I can't > > > tell how im might become None, but it does look like you (confusingly) > > > use im for two different things: an img.copy() and a cv2.rectangle, > > > whatever those may be. > > > > > > Pure guesswork: if cv2.rectangle draws a rectangle, what does it > > > return? If it doesn't return anything, the line > > > im = cv2.rectangle(...) > > > is how im gets the value of None. > > > > > It looks like the OP is using OpenCV. > > > > You're right about cv2.rectangle; it does return None. > > > > The line: > > > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > > > makes a copy of the image im, draws a rectangle on it, and then binds > > None to im. > > > > The copied rectangle is discarded because there's no reference to it, so > > the entire line in pointless. > > > > It basically does the same thing as: > > > > im = None > > > > only slower! From jobmattcon at gmail.com Fri Sep 16 20:16:03 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 17:16:03 -0700 (PDT) Subject: why this code loop forever after a draw a rectangle In-Reply-To: <3bd2071f-d0cf-4044-b2bb-778f4897129a@googlegroups.com> References: <428c148e-9f66-449a-88d0-aa8f5776a60c@googlegroups.com> <2dd5d078-9360-c64a-7e6b-b7fad7ea5262@digipen.edu> <70ae33f1-a031-4d8d-88c8-e25d75d7f9b8@googlegroups.com> <3bd2071f-d0cf-4044-b2bb-778f4897129a@googlegroups.com> Message-ID: <2fe3203d-9352-4de0-b872-230467609d44@googlegroups.com> after succeed to draw lines in graph, however, https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing expected the blue line connect the bottom of red line graph https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing how can convex hull be adjusted to do like second graph of sky blue line On Saturday, September 17, 2016 at 7:48:46 AM UTC+8, meInvent bbird wrote: > img is the image > > im is a new memory of image using img.copy() > > > On Saturday, September 17, 2016 at 7:46:42 AM UTC+8, meInvent bbird wrote: > > thank you very much, > > it out of the loop now. > > because drawLine function return things > > > > i just change drawLine to rectangle, > > have not thought that rectangle not return thing, just edit the parameter > > > > > > > > On Saturday, September 17, 2016 at 5:26:53 AM UTC+8, MRAB wrote: > > > On 2016-09-16 20:14, Gary Herron wrote: > > > > On 09/16/2016 04:24 AM, meInvent bbird wrote: > > > >> im = img.copy() > > > >> cntcounter = 0 > > > >> for cnt in contours: > > > >> epsilon = 0.1*cv2.arcLength(cnt,True) > > > >> approx = cv2.approxPolyDP(cnt,epsilon,True) > > > >> #peri = cv2.arcLength(cnt, True) > > > >> #approx = cv2.approxPolyDP(c, 0.5 * peri, True) > > > >> #print("len(approx)="+str(len(approx))) > > > >> if len(approx) == 4: > > > >> print("approx=" + str(approx)) > > > >> cntcounter = cntcounter + 1 > > > >> print("here1") > > > >> x,y,w,h = cv2.boundingRect(cnt) > > > >> print("here2") > > > >> while im is None: > > > >> time.sleep(1) > > > >> if im is not None: > > > >> print("here3") > > > >> im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > > >> #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) > > > >> #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) > > > >> #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) > > > >> #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) > > > >> > > > >> > > > >> cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im) > > > > > > > > > > > > These two lines: > > > > > > > > while im is None: > > > > time.sleep(1) > > > > > > > > are an infinite loop if im is None; > > > > > > > > > > > > Since you haven't told us what im (or img, contours, cv2) are, I can't > > > > tell how im might become None, but it does look like you (confusingly) > > > > use im for two different things: an img.copy() and a cv2.rectangle, > > > > whatever those may be. > > > > > > > > Pure guesswork: if cv2.rectangle draws a rectangle, what does it > > > > return? If it doesn't return anything, the line > > > > im = cv2.rectangle(...) > > > > is how im gets the value of None. > > > > > > > It looks like the OP is using OpenCV. > > > > > > You're right about cv2.rectangle; it does return None. > > > > > > The line: > > > > > > im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2) > > > > > > makes a copy of the image im, draws a rectangle on it, and then binds > > > None to im. > > > > > > The copied rectangle is discarded because there's no reference to it, so > > > the entire line in pointless. > > > > > > It basically does the same thing as: > > > > > > im = None > > > > > > only slower! From jobmattcon at gmail.com Fri Sep 16 20:20:27 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 17:20:27 -0700 (PDT) Subject: is it possible to adjust convex hull to draw blue line instead of green line? Message-ID: i succeed to use code to draw green line, but green line not draw the large area, expect second uploaded picture, the blue line connect the bottom of red line graph im = img.copy() cntcounter = 0 for cnt in contours: #epsilon = 0.1*cv2.arcLength(cnt,True) #approx = cv2.approxPolyDP(cnt,epsilon,True) #peri = cv2.arcLength(cnt, True) #approx = cv2.approxPolyDP(cnt, 0.15 * peri, True) #print("len(approx)="+str(len(approx))) #if len(approx) == 2: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") #x,y,w,h = cv2.boundingRect(cnt) hull = cv2.convexHull(cnt,returnPoints = True) print("here2") while im is None: time.sleep(1) if im is not None: print("here3") #cv2.rectangle(im, (x,y), (x+w, y+h), (0,255,0), 2) #cv2.imwrite("C:\\Users\\tester\\Documents\\masda"+str(cntcounter)+".png",imi) #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) previousx = 0 previousy = 0 for c in hull: if previousx != 0 and previousy != 0 and c[0][0] != 0 and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 and abs(c[0][0] - previousx) > 1: while im is None: time.sleep(1) cv2.line(im,(previousx,previousy),(c[0][0],c[0][1]),(0,255,0),2) print("") #print("previousx=" + str(previousx)) #print("previousy=" + str(previousy)) #print("c[0][0]=" + str(c[0][0])) #print("c[0][1]=" + str(c[0][1])) previousx = c[0][0] previousy = c[0][1] https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing expected is https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing From steve+python at pearwood.info Fri Sep 16 21:35:16 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 17 Sep 2016 11:35:16 +1000 Subject: is it possible to adjust convex hull to draw blue line instead of green line? References: Message-ID: <57dc9dd5$0$1586$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote: > i succeed to use code to draw green line, but green line not draw the > large area, expect second uploaded picture, the blue line connect > the bottom of red line graph Please don't waste our time with dead code that has been commented out or that doesn't do anything. Here is your code with the commented out dead code removed. You should do this, don't expect us to do it: im = img.copy() cntcounter = 0 for cnt in contours: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") hull = cv2.convexHull(cnt,returnPoints = True) print("here2") while im is None: # WARNING: THIS IS AN INFINITE LOOP time.sleep(1) if im is not None: print("here3") previousx = 0 previousy = 0 for c in hull: if (previousx != 0 and previousy != 0 and c[0][0] != 0 and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 and abs(c[0][0] - previousx) > 1 ): while im is None: # WARNING: THIS IS AN INFINITE LOOP time.sleep(1) cv2.line(im, (previousx, previousy), (c[0][0], c[0][1]), (0, 255, 0), 2) print("") previousx = c[0][0] previousy = c[0][1] Now it is much easier to read without the noise. Problems: (1) img is not defined; (2) approx is not defined; (3) contours is not defined; (4) cv2 is not defined; (5) you have TWO possible infinite loops in your code; (6) time is not defined, but this at least I can guess is the standard time module; (7) c is not defined. As given to us, we cannot run your code or understand it, because too many things are undefined. My **guess** is that cv2.line() will take an argument to set the line colour. You should read the documentation for cv2.line(). Before asking any more questions, please read this: http://sscce.org/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lawrencedo99 at gmail.com Fri Sep 16 21:35:43 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 16 Sep 2016 18:35:43 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> Message-ID: On Friday, September 16, 2016 at 10:22:34 PM UTC+12, Christian Gollwitzer wrote: > "How do I automate a Java application using Python?" Which is really a meaningless question. ?Automation? is what computer programs do. (Assuming ?application? is just another word for ?program?.) If the program doesn?t work the way you expect, fix it. But then, ?automation? and ?GUI? never really went together, did they ... From python at mrabarnett.plus.com Fri Sep 16 21:40:23 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 17 Sep 2016 02:40:23 +0100 Subject: is it possible to adjust convex hull to draw blue line instead of green line? In-Reply-To: References: Message-ID: <23bc5278-1536-7ab8-2563-50033a96ef3d@mrabarnett.plus.com> On 2016-09-17 01:20, meInvent bbird wrote: > i succeed to use code to draw green line, but green line not draw the > large area, expect second uploaded picture, the blue line connect > the bottom of red line graph > [snip] Here's the code with the commented code and print statements removed and the indentation fixed: im = img.copy() for cnt in contours: hull = cv2.convexHull(cnt, returnPoints=True) previousx = 0 previousy = 0 for c in hull: if previousx != 0 and previousy != 0 and c[0][0] != 0 and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 and abs(c[0][0] - previousx) > 1: cv2.line(im, (previousx, previousy), (c[0][0], c[0][1]), (0, 255, 0), 2) previousx = c[0][0] previousy = c[0][1] > > https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing > > expected is > > https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing > I think the problem might be that you're setting previousx to c[0][0] and previousy to c[0][1] even if you don't draw the line (because of the indentation), so you get a series of unconnected lines. I'm not sure whether you should be setting previousx and previousy to 0 each time around the outer loop. I can't test it, but if the previous fix doesn't work, it's one more thing to try. From pengyu.ut at gmail.com Fri Sep 16 22:05:33 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Sep 2016 21:05:33 -0500 Subject: Where is the documentation for ','? Message-ID: Hi, I'm wondering where is the documentation for ',' as in the following usage. x = 1 y = 2 x, y = y, x I tried help(','). But there are too many ',' in it and I don't see in which section ',' is documented. Could anybody let me know? Thanks. -- Regards, Peng From python at mrabarnett.plus.com Fri Sep 16 22:13:12 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 17 Sep 2016 03:13:12 +0100 Subject: Where is the documentation for ','? In-Reply-To: References: Message-ID: <35224433-8942-fe6a-3615-080bceb231e8@mrabarnett.plus.com> On 2016-09-17 03:05, Peng Yu wrote: > Hi, > > I'm wondering where is the documentation for ',' as in the following usage. > > x = 1 > y = 2 > x, y = y, x > > I tried help(','). But there are too many ',' in it and I don't see in > which section ',' is documented. Could anybody let me know? Thanks. > Search for 'tuple' instead. From pengyu.ut at gmail.com Fri Sep 16 22:29:59 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Sep 2016 21:29:59 -0500 Subject: Where is the documentation for ','? In-Reply-To: <35224433-8942-fe6a-3615-080bceb231e8@mrabarnett.plus.com> References: <35224433-8942-fe6a-3615-080bceb231e8@mrabarnett.plus.com> Message-ID: help(tuple) gives me this, which does not mention ',' either. Help on class tuple in module __builtin__: class tuple(object) | tuple() -> empty tuple | tuple(iterable) -> tuple initialized from iterable's items | | If the argument is a tuple, the return value is the same object. | | Methods defined here: | | __add__(...) | x.__add__(y) <==> x+y | | __contains__(...) | x.__contains__(y) <==> y in x | | __eq__(...) | x.__eq__(y) <==> x==y | | __ge__(...) | x.__ge__(y) <==> x>=y | | __getattribute__(...) | x.__getattribute__('name') <==> x.name | | __getitem__(...) | x.__getitem__(y) <==> x[y] | | __getnewargs__(...) | | __getslice__(...) | x.__getslice__(i, j) <==> x[i:j] | | Use of negative indices is not supported. | | __gt__(...) | x.__gt__(y) <==> x>y | | __hash__(...) | x.__hash__() <==> hash(x) | | __iter__(...) | x.__iter__() <==> iter(x) | | __le__(...) | x.__le__(y) <==> x<=y | | __len__(...) | x.__len__() <==> len(x) | | __lt__(...) | x.__lt__(y) <==> x x*n | | __ne__(...) | x.__ne__(y) <==> x!=y | | __repr__(...) | x.__repr__() <==> repr(x) | | __rmul__(...) | x.__rmul__(n) <==> n*x | | count(...) | T.count(value) -> integer -- return number of occurrences of value | | index(...) | T.index(value, [start, [stop]]) -> integer -- return first index of value. | Raises ValueError if the value is not present. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __new__ = | T.__new__(S, ...) -> a new object with type S, a subtype of T On Fri, Sep 16, 2016 at 9:13 PM, MRAB wrote: > On 2016-09-17 03:05, Peng Yu wrote: >> >> Hi, >> >> I'm wondering where is the documentation for ',' as in the following >> usage. >> >> x = 1 >> y = 2 >> x, y = y, x >> >> I tried help(','). But there are too many ',' in it and I don't see in >> which section ',' is documented. Could anybody let me know? Thanks. >> > Search for 'tuple' instead. > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From pengyu.ut at gmail.com Fri Sep 16 22:31:37 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Sep 2016 21:31:37 -0500 Subject: Is there something similar to `set -v` of bash in python Message-ID: Hi, `set -v` in bash allows the print of the command before print the output of the command. I want to do the similar thing --- print a python command and then print the output of the command. Is it possible with python? -- Regards, Peng From lawrencedo99 at gmail.com Fri Sep 16 22:48:33 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 16 Sep 2016 19:48:33 -0700 (PDT) Subject: Where is the documentation for ','? In-Reply-To: References: Message-ID: <8e6941bb-e5ed-4a7f-b9eb-1b9369d8f914@googlegroups.com> On Saturday, September 17, 2016 at 2:05:49 PM UTC+12, Peng Yu wrote: > x, y = y, x It?s just syntactic sugar for (x, y) = (y, x) From pengyu.ut at gmail.com Fri Sep 16 22:57:23 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Sep 2016 21:57:23 -0500 Subject: Where is the documentation for ','? In-Reply-To: <8e6941bb-e5ed-4a7f-b9eb-1b9369d8f914@googlegroups.com> References: <8e6941bb-e5ed-4a7f-b9eb-1b9369d8f914@googlegroups.com> Message-ID: OK. But it is documented somewhere in python doc? On Fri, Sep 16, 2016 at 9:48 PM, Lawrence D?Oliveiro wrote: > On Saturday, September 17, 2016 at 2:05:49 PM UTC+12, Peng Yu wrote: >> x, y = y, x > > It?s just syntactic sugar for > > (x, y) = (y, x) > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From nathan.ernst at gmail.com Fri Sep 16 23:06:50 2016 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Fri, 16 Sep 2016 22:06:50 -0500 Subject: Where is the documentation for ','? In-Reply-To: References: <8e6941bb-e5ed-4a7f-b9eb-1b9369d8f914@googlegroups.com> Message-ID: The grammar and what it represents is defined at https://docs.python.org/3/reference/expressions.html#expression-lists Regards On Sep 16, 2016 9:59 PM, "Peng Yu" wrote: > OK. But it is documented somewhere in python doc? > > On Fri, Sep 16, 2016 at 9:48 PM, Lawrence D?Oliveiro > wrote: > > On Saturday, September 17, 2016 at 2:05:49 PM UTC+12, Peng Yu wrote: > >> x, y = y, x > > > > It?s just syntactic sugar for > > > > (x, y) = (y, x) > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Regards, > Peng > -- > https://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Fri Sep 16 23:46:14 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 17 Sep 2016 13:46:14 +1000 Subject: Where is the documentation for ','? References: <35224433-8942-fe6a-3615-080bceb231e8@mrabarnett.plus.com> Message-ID: <85mvj7p4s9.fsf@benfinney.id.au> Peng Yu writes: > help(tuple) gives me this Yes. That's the API definition for the ?tuple? type. You were advised to search the documentation, not the interactive help. You'll find the descriptions of ?tuple? and even ?tuple unpacking? are what you want. -- \ ?When I turned two I was really anxious, because I'd doubled my | `\ age in a year. I thought, if this keeps up, by the time I'm six | _o__) I'll be ninety.? ?Steven Wright | Ben Finney From lawrencedo99 at gmail.com Fri Sep 16 23:47:05 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 16 Sep 2016 20:47:05 -0700 (PDT) Subject: array.itemsize: Documentation Versus Reality Message-ID: >>> a = array.array("I", (0,)) >>> a.itemsize 4 >>> a = array.array("L", (0,)) >>> a.itemsize 8 According to , the ?minimum size? should be 2 and 4 respectively. It further says: The actual representation of values is determined by the machine architecture (strictly speaking, by the C implementation). The actual size can be accessed through the itemsize attribute. Are there any C compilers still in common use where the values will not be 4 and 8, as above? From tjreedy at udel.edu Sat Sep 17 00:50:04 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Sep 2016 00:50:04 -0400 Subject: Where is the documentation for ','? In-Reply-To: References: Message-ID: On 9/16/2016 10:05 PM, Peng Yu wrote: > Hi, > > I'm wondering where is the documentation for ',' as in the following usage. > > x = 1 > y = 2 > x, y = y, x > > I tried help(','). But there are too many ',' in it and I don't see in > which section ',' is documented. Could anybody let me know? Thanks. It should be indexed on https://docs.python.org/3/genindex-Symbols.html but is not. I will try to remember to fix it. -- Terry Jan Reedy From eryksun at gmail.com Sat Sep 17 01:24:13 2016 From: eryksun at gmail.com (eryk sun) Date: Sat, 17 Sep 2016 05:24:13 +0000 Subject: Where is the documentation for ','? In-Reply-To: References: Message-ID: On Sat, Sep 17, 2016 at 2:05 AM, Peng Yu wrote: > > I'm wondering where is the documentation for ',' as in the following usage. > > x = 1 > y = 2 > x, y = y, x > > I tried help(','). But there are too many ',' in it and I don't see in > which section ',' is documented. Could anybody let me know? Thanks. See help('ASSIGNMENT') where the "target list is a comma-separated list of targets". See also help('TUPLELITERALS') and help('SEQUENCES'). From jobmattcon at gmail.com Sat Sep 17 02:30:46 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 23:30:46 -0700 (PDT) Subject: is it possible to adjust convex hull to draw blue line instead of green line? In-Reply-To: <57dc9dd5$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <57dc9dd5$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ada35f9-f24e-4596-9d45-4e2b5f97eeea@googlegroups.com> On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote: > On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote: > > > i succeed to use code to draw green line, but green line not draw the > > large area, expect second uploaded picture, the blue line connect > > the bottom of red line graph > > > Please don't waste our time with dead code that has been commented out or > that doesn't do anything. > > Here is your code with the commented out dead code removed. You should do > this, don't expect us to do it: > > > im = img.copy() > cntcounter = 0 > for cnt in contours: > print("approx=" + str(approx)) > cntcounter = cntcounter + 1 > print("here1") > hull = cv2.convexHull(cnt,returnPoints = True) > print("here2") > while im is None: > # WARNING: THIS IS AN INFINITE LOOP > time.sleep(1) > if im is not None: > print("here3") > previousx = 0 > previousy = 0 > for c in hull: > if (previousx != 0 and previousy != 0 and c[0][0] != 0 > and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 > and abs(c[0][0] - previousx) > 1 > ): > while im is None: > # WARNING: THIS IS AN INFINITE LOOP > time.sleep(1) > cv2.line(im, (previousx, previousy), > (c[0][0], c[0][1]), (0, 255, 0), 2) > print("") > previousx = c[0][0] > previousy = c[0][1] > > > > > Now it is much easier to read without the noise. > > Problems: > > (1) img is not defined; > > (2) approx is not defined; > > (3) contours is not defined; > > (4) cv2 is not defined; > > (5) you have TWO possible infinite loops in your code; > > (6) time is not defined, but this at least I can guess is the > standard time module; > > (7) c is not defined. > > > As given to us, we cannot run your code or understand it, because too many > things are undefined. > > My **guess** is that cv2.line() will take an argument to set the line > colour. You should read the documentation for cv2.line(). > > > Before asking any more questions, please read this: > > http://sscce.org/ > > > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. sorry for assuming all have experience in this kind of application here is my code https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60 Please. From steve+python at pearwood.info Sat Sep 17 02:37:28 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 17 Sep 2016 16:37:28 +1000 Subject: Is there something similar to `set -v` of bash in python References: Message-ID: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Sep 2016 12:31 pm, Peng Yu wrote: > Hi, `set -v` in bash allows the print of the command before print the > output of the command. > > I want to do the similar thing --- print a python command and then > print the output of the command. Is it possible with python? There is no built-in command for this, but it would be an interesting project for an advanced user to write a pre-processor that inserts calls to print after every line. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 17 02:39:26 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 17 Sep 2016 16:39:26 +1000 Subject: Where is the documentation for ','? References: Message-ID: <57dce520$0$22141$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Sep 2016 12:05 pm, Peng Yu wrote: > Hi, > > I'm wondering where is the documentation for ',' as in the following > usage. > > x = 1 > y = 2 > x, y = y, x > > I tried help(','). But there are too many ',' in it and I don't see in > which section ',' is documented. Could anybody let me know? Thanks. As well as the other suggestions you have been given, try "Sequence Unpacking". -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jobmattcon at gmail.com Sat Sep 17 02:48:50 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 16 Sep 2016 23:48:50 -0700 (PDT) Subject: is it possible to adjust convex hull to draw blue line instead of green line? In-Reply-To: <4ada35f9-f24e-4596-9d45-4e2b5f97eeea@googlegroups.com> References: <57dc9dd5$0$1586$c3e8da3$5496439d@news.astraweb.com> <4ada35f9-f24e-4596-9d45-4e2b5f97eeea@googlegroups.com> Message-ID: <311f5bab-4c18-44c4-8631-75f1623600c4@googlegroups.com> On Saturday, September 17, 2016 at 2:31:59 PM UTC+8, meInvent bbird wrote: > On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote: > > On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote: > > > > > i succeed to use code to draw green line, but green line not draw the > > > large area, expect second uploaded picture, the blue line connect > > > the bottom of red line graph > > > > > > Please don't waste our time with dead code that has been commented out or > > that doesn't do anything. > > > > Here is your code with the commented out dead code removed. You should do > > this, don't expect us to do it: > > > > > > im = img.copy() > > cntcounter = 0 > > for cnt in contours: > > print("approx=" + str(approx)) > > cntcounter = cntcounter + 1 > > print("here1") > > hull = cv2.convexHull(cnt,returnPoints = True) > > print("here2") > > while im is None: > > # WARNING: THIS IS AN INFINITE LOOP > > time.sleep(1) > > if im is not None: > > print("here3") > > previousx = 0 > > previousy = 0 > > for c in hull: > > if (previousx != 0 and previousy != 0 and c[0][0] != 0 > > and c[0][1] != 0 and abs(previousy - c[0][1]) > 10 > > and abs(c[0][0] - previousx) > 1 > > ): > > while im is None: > > # WARNING: THIS IS AN INFINITE LOOP > > time.sleep(1) > > cv2.line(im, (previousx, previousy), > > (c[0][0], c[0][1]), (0, 255, 0), 2) > > print("") > > previousx = c[0][0] > > previousy = c[0][1] > > > > > > > > > > Now it is much easier to read without the noise. > > > > Problems: > > > > (1) img is not defined; > > > > (2) approx is not defined; > > > > (3) contours is not defined; > > > > (4) cv2 is not defined; > > > > (5) you have TWO possible infinite loops in your code; > > > > (6) time is not defined, but this at least I can guess is the > > standard time module; > > > > (7) c is not defined. > > > > > > As given to us, we cannot run your code or understand it, because too many > > things are undefined. > > > > My **guess** is that cv2.line() will take an argument to set the line > > colour. You should read the documentation for cv2.line(). > > > > > > Before asking any more questions, please read this: > > > > http://sscce.org/ > > > > > > > > > > > > > > -- > > Steve > > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > > enough, things got worse. > > sorry for assuming all have experience in this kind of application > > here is my code > > https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60 > > Please. this time, i try to run more times for contour and convex hull but not blue line expected diagram, is it possible to adjust the method to draw lines for the bottom of red line https://gist.github.com/hoyeunglee/9c97fdef1cc32fefde0a454a24a2c2c1 From thorsten at thorstenkampe.de Sat Sep 17 06:25:05 2016 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 17 Sep 2016 12:25:05 +0200 Subject: Is there something similar to `set -v` of bash in python References: Message-ID: * Peng Yu (Fri, 16 Sep 2016 21:31:37 -0500) > > Hi, `set -v` in bash allows the print of the command before print the > output of the command. > > I want to do the similar thing --- print a python command and then > print the output of the command. Is it possible with python? Rather easily. I've implemented it some time ago like this: """ import sys def _traceit(frame, event, arg): if (frame.f_globals['__name__'] == '__main__' and event in ['call', 'line']): logger.debug('+[{lineno}]: {code}'.format( lineno = frame.f_lineno, code = inspect.getframeinfo(frame).code_context [0].rstrip())) return _traceit sys.settrace(_traceit) """ Thorsten From thorsten at thorstenkampe.de Sat Sep 17 06:30:24 2016 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 17 Sep 2016 12:30:24 +0200 Subject: Is there something similar to `set -v` of bash in python References: Message-ID: * Thorsten Kampe (Sat, 17 Sep 2016 12:25:05 +0200) > > * Peng Yu (Fri, 16 Sep 2016 21:31:37 -0500) > > > > Hi, `set -v` in bash allows the print of the command before print the > > output of the command. > > > > I want to do the similar thing --- print a python command and then > > print the output of the command. Is it possible with python? > > Rather easily. I've implemented it some time ago like this: Oops, I mixed it up with `set -x`, sorry. Thorsten From christian at python.org Sat Sep 17 07:53:28 2016 From: christian at python.org (Christian Heimes) Date: Sat, 17 Sep 2016 13:53:28 +0200 Subject: array.itemsize: Documentation Versus Reality In-Reply-To: References: Message-ID: On 2016-09-17 05:47, Lawrence D?Oliveiro wrote: > >>> a = array.array("I", (0,)) > >>> a.itemsize > 4 > >>> a = array.array("L", (0,)) > >>> a.itemsize > 8 > > According to , the ?minimum size? should be 2 and 4 respectively. It further says: > > The actual representation of values is determined by the machine > architecture (strictly speaking, by the C implementation). > The actual size can be accessed through the itemsize attribute. > > Are there any C compilers still in common use where the values will not be 4 and 8, as above? Yes, on Windows (32 and 64bit), a long is always 32bit and an array with datatype "L" has itemsize 4. Christian From ned at nedbatchelder.com Sat Sep 17 08:22:14 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 17 Sep 2016 05:22:14 -0700 (PDT) Subject: Is there something similar to `set -v` of bash in python In-Reply-To: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, September 17, 2016 at 2:37:42 AM UTC-4, Steve D'Aprano wrote: > On Sat, 17 Sep 2016 12:31 pm, Peng Yu wrote: > > > Hi, `set -v` in bash allows the print of the command before print the > > output of the command. > > > > I want to do the similar thing --- print a python command and then > > print the output of the command. Is it possible with python? > > > There is no built-in command for this, but it would be an interesting > project for an advanced user to write a pre-processor that inserts calls to > print after every line. The trace module in the stdlib is little-known, but can do this. This will run your program and print each line before executing it: python -m trace -t yourprogram.py --Ned. From piet-l at pietvanoostrum.com Sat Sep 17 10:13:35 2016 From: piet-l at pietvanoostrum.com (Piet van Oostrum) Date: Sat, 17 Sep 2016 16:13:35 +0200 Subject: Expression can be simplified on list References: Message-ID: Daiyue Weng writes: > Hi, I found that when I tried to make an equality test on empty like, > > if errors == []: > > PyCharm always warns me, > > Expression can be simplified. > > I am wondering what's wrong and how to fix this? > It is not wrong, but it can be simplified to just: if errors: This is quite usual in Python, but some people prefer the more elaborate form, or something like: if len(errors) == 0: -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From pengyu.ut at gmail.com Sat Sep 17 12:12:21 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 17 Sep 2016 11:12:21 -0500 Subject: =?UTF-8?Q?How_to_convert_=27=C3=B6=27_to_=27oe=27_or_=27o=27_=28or_other_similar?= =?UTF-8?Q?_things=29_in_a_string=3F?= Message-ID: Hi, I want to convert strings in which the characters with accents should be converted to the ones without accents. Here is my current code. ======================== $ cat main.sh #!/usr/bin/env bash # vim: set noexpandtab tabstop=2: set -v ./main.py F?rstemann ./main.py Fr?d?r8ic@ $ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: import sys import unicodedata print unicodedata.normalize('NFKD', sys.argv[1].decode('utf-8')).encode('ascii', 'ignore') ======================== The complication is that some characters have more than one way of conversions. E.g., '?' can be converted to either 'oe' or 'o'. I want to get all the possible conversions of a string. Does anybody know a good way to do so? Thanks. -- Regards, Peng From dev at kou.li Sat Sep 17 12:38:50 2016 From: dev at kou.li (Kouli) Date: Sat, 17 Sep 2016 18:38:50 +0200 Subject: =?UTF-8?Q?Re=3A_How_to_convert_=27=C3=B6=27_to_=27oe=27_or_=27o=27_=28or_other_sim?= =?UTF-8?Q?ilar_things=29_in_a_string=3F?= In-Reply-To: References: Message-ID: Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. Kouli On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: > Hi, I want to convert strings in which the characters with accents > should be converted to the ones without accents. Here is my current > code. > > ======================== > > $ cat main.sh > #!/usr/bin/env bash > # vim: set noexpandtab tabstop=2: > > set -v > ./main.py F?rstemann > ./main.py Fr?d?r8ic@ > > $ cat main.py > #!/usr/bin/env python > # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: > > import sys > import unicodedata > print unicodedata.normalize('NFKD', > sys.argv[1].decode('utf-8')).encode('ascii', 'ignore') > > ======================== > > The complication is that some characters have more than one way of > conversions. E.g., '?' can be converted to either 'oe' or 'o'. I want > to get all the possible conversions of a string. Does anybody know a > good way to do so? Thanks. > > -- > Regards, > Peng > -- > https://mail.python.org/mailman/listinfo/python-list From Redacted Sat Sep 17 15:08:25 2016 From: Redacted (Redacted) Date: Sat, 17 Sep 2016 12:08:25 -0700 (PDT) Subject: Redacted In-Reply-To: References: Message-ID: <15af6c01-4d55-4c40-823b-97ff95f90594@googlegroups.com> Redacted From martin.schoon at gmail.com Sat Sep 17 16:20:12 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 17 Sep 2016 20:20:12 GMT Subject: How to convert =?UTF-8?Q?=27=C3=B6=27?= to 'oe' or 'o' (or other similar things) in a string? References: Message-ID: Den 2016-09-17 skrev Kouli : > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. > > Kouli > > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: >> Hi, I want to convert strings in which the characters with accents >> should be converted to the ones without accents. Here is my current >> code. Side note from Sweden. ?, ? and ? are not accented characters in our language. They are characters of their own. If you want to look up someone called ?hman in the phone directory you go to the ? section not the O section. Related anecdote from Phoenix AZ. By now you have noticed my family name: Sch??n. On airline tickets and boarding passes in the U.S. it gets spelled Schoeoen. This landed me in a special security check once. After a while the youngish lady performing the search started to look like 1+1 did not sum up to 2. She looked at my passport and boarding pass again and asked why I was there with her. I pointed at another young lady, the one that 'scrutinized' passports and boarding passes while chatting with a friend and said "She told me to go over here." "Wait here, I have to talk to my supervisor." A few minutes passed (I was alone in the enhances security check throughout...) and then "I am sorry but you should not have had to go through here. There was a mistake." So there you are: If you are a middle aged, caucasian guy with a passport from northern Europe and no 'funny' letters in your name your are not a threat in the eyes of TSA in Arizona. Sorry for wasting the bandwidth. /Martin From pengyu.ut at gmail.com Sat Sep 17 16:41:15 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 17 Sep 2016 15:41:15 -0500 Subject: Is there something similar to `set -v` of bash in python In-Reply-To: References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: > python -m trace -t yourprogram.py If I want to add some command in yourprogram.py to show the commands used it instead of calling trace from the command line, can it be done? -- Regards, Peng From marko at pacujo.net Sat Sep 17 18:10:31 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 18 Sep 2016 01:10:31 +0300 Subject: How to convert =?utf-8?Q?'=C3=B6'?= to 'oe' or 'o' (or other similar things) in a string? References: Message-ID: <87k2eamb3c.fsf@elektro.pacujo.net> Martin Sch??n : > Related anecdote from Phoenix AZ. By now you have noticed my family > name: Sch??n. On airline tickets and boarding passes in the U.S. it > gets spelled Schoeoen. Do Swedes do that German thing, too? If you have to write Finnish without ? and ?, you simply leave out the dots. (On the other hand, if you need ? or ? and don't have them, you replace them with sh and zh.) Marko From lawrencedo99 at gmail.com Sat Sep 17 18:11:41 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 17 Sep 2016 15:11:41 -0700 (PDT) Subject: array.itemsize: Documentation Versus Reality In-Reply-To: References: Message-ID: <315c5cf9-90f3-4ee9-82b6-6a2929f68b5b@googlegroups.com> On Saturday, September 17, 2016 at 11:54:10 PM UTC+12, Christian Heimes wrote: > > ... on Windows (32 and 64bit), a long is always 32bit and an array with > datatype "L" has itemsize 4. Ah, I forgot the LLP64 nonsense... From ned at nedbatchelder.com Sat Sep 17 18:28:27 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 17 Sep 2016 15:28:27 -0700 (PDT) Subject: Is there something similar to `set -v` of bash in python In-Reply-To: References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55d8c135-fef3-4039-832e-e7637ae2c0b5@googlegroups.com> On Saturday, September 17, 2016 at 4:41:32 PM UTC-4, Peng Yu wrote: > > python -m trace -t yourprogram.py > > If I want to add some command in yourprogram.py to show the commands > used it instead of calling trace from the command line, can it be > done? I don't know of a way to do that, but it might be possible. --Ned. From lawrencedo99 at gmail.com Sat Sep 17 20:17:59 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 17 Sep 2016 17:17:59 -0700 (PDT) Subject: array.itemsize: Documentation Versus Reality In-Reply-To: References: Message-ID: On Saturday, September 17, 2016 at 3:47:15 PM UTC+12, I wrote: > >>> a = array.array("I", (0,)) > >>> a.itemsize > 4 > >>> a = array.array("L", (0,)) > >>> a.itemsize > 8 Let me rephrase the question. It seems clear that ?l? and ?L? are not be relied on. As far as I can tell, on all current Python implementations, ?i? and ?I? have item sizes of 4, while ?q? and ?Q? have item sizes of 8. Can anybody offer any counterexamples? If not, why does the documentation suggest that ?i? and ?I? could have an item size of 2? From pengyu.ut at gmail.com Sat Sep 17 20:50:47 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 17 Sep 2016 19:50:47 -0500 Subject: Is the content available in the html doc available in help()? Message-ID: Hi, I want to get the same content as the html doc from help(). I am not sure if this is possible (as I tried help(inspect) which does not give the same content). Could anybody confirm if there is a way to get the same content from help()? Thanks. https://docs.python.org/2/library/inspect.html -- Regards, Peng From ben+python at benfinney.id.au Sat Sep 17 21:25:15 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 18 Sep 2016 11:25:15 +1000 Subject: Official Python documentation lookup while programming (was: Is the content available in the html doc available in help()?) References: Message-ID: <85intuov7o.fsf@benfinney.id.au> Peng Yu writes: > Hi, I want to get the same content as the html doc from help(). That's not what the ?help? function does, so I don't think that's feasible. Moreover, the Python interpreter does not have any notion of where the HTML documentation is stored, nor how to access it, nor how to present it. So no, a Python interactive prompt does not natively have a way to do what you're asking. What you may like is to get your programming environment to present the official Python documentation as part of that environment. For example, the documentation is rendered to GNU Info format and available to install from , which makes it immediately available in Info readers, such as the one native to Emacs. -- \ ?If you ever fall off the Sears Tower, just go real limp, | `\ because maybe you'll look like a dummy and people will try to | _o__) catch you because, hey, free dummy.? ?Jack Handey | Ben Finney From lawrencedo99 at gmail.com Sat Sep 17 21:45:14 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 17 Sep 2016 18:45:14 -0700 (PDT) Subject: Is the content available in the html doc available in help()? In-Reply-To: References: Message-ID: On Sunday, September 18, 2016 at 12:51:11 PM UTC+12, Peng Yu wrote: > I want to get the same content as the html doc from help(). ldo at theon:~> pydoc3 inspect Help on module inspect: NAME inspect - Get useful information from live Python objects. MODULE REFERENCE https://docs.python.org/3.5/library/inspect (etc etc etc) worked for me, and it?s for a more up-to-date version of Python as well... From pengyu.ut at gmail.com Sat Sep 17 22:21:58 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 17 Sep 2016 21:21:58 -0500 Subject: Is the content available in the html doc available in help()? In-Reply-To: References: Message-ID: Sorry. I am still referring to python2. On Sat, Sep 17, 2016 at 8:45 PM, Lawrence D?Oliveiro wrote: > On Sunday, September 18, 2016 at 12:51:11 PM UTC+12, Peng Yu wrote: >> I want to get the same content as the html doc from help(). > > ldo at theon:~> pydoc3 inspect > Help on module inspect: > > NAME > inspect - Get useful information from live Python objects. > > MODULE REFERENCE > https://docs.python.org/3.5/library/inspect > > (etc etc etc) > > worked for me, and it?s for a more up-to-date version of Python as well... > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From eryksun at gmail.com Sat Sep 17 22:33:27 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 18 Sep 2016 02:33:27 +0000 Subject: array.itemsize: Documentation Versus Reality In-Reply-To: References: Message-ID: On Sun, Sep 18, 2016 at 12:17 AM, Lawrence D?Oliveiro wrote: > > why does the documentation suggest that ?i? and ?I? could have an item size of 2? SHRT_MAX <= INT_MAX <= LONG_MAX <= LLONG_MAX. short int and int ("h" and "i") are at least 16-bit. long int ("l") is at least 32-bit. long long int ("q") is at least 64-bit. AFAIK, however, an int is 32-bit on all platforms supported by CPython. However, I see that MicroPython [1] has been ported to 16-bit PIC microcontrollers. An int should be 16-bit in that case. [1]: https://github.com/micropython/micropython From pengyu.ut at gmail.com Sat Sep 17 23:08:41 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 17 Sep 2016 22:08:41 -0500 Subject: Is there something similar to `set -v` of bash in python In-Reply-To: <55d8c135-fef3-4039-832e-e7637ae2c0b5@googlegroups.com> References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> <55d8c135-fef3-4039-832e-e7637ae2c0b5@googlegroups.com> Message-ID: The manual says the following. "The trace function is invoked (with event set to 'call') whenever a new local scope is entered; it should return a reference to a local trace function to be used that scope, or None if the scope shouldn?t be traced." It means that one can not somehow settrace in one line and expect to get the trace function being called in the next line. So something like `set -v` in bash sounds not possible. Is it so? On Sat, Sep 17, 2016 at 5:28 PM, Ned Batchelder wrote: > On Saturday, September 17, 2016 at 4:41:32 PM UTC-4, Peng Yu wrote: >> > python -m trace -t yourprogram.py >> >> If I want to add some command in yourprogram.py to show the commands >> used it instead of calling trace from the command line, can it be >> done? > > I don't know of a way to do that, but it might be possible. > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From lawrencedo99 at gmail.com Sat Sep 17 23:16:55 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 17 Sep 2016 20:16:55 -0700 (PDT) Subject: array.itemsize: Documentation Versus Reality In-Reply-To: References: Message-ID: On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote: > However, I see that MicroPython [1] has been ported to 16-bit > PIC microcontrollers. An int should be 16-bit in that case. > > [1]: https://github.com/micropython/micropython >From the readme: ?MicroPython implements the entire Python 3.4 syntax...? Darn. I don?t know whether to applaud or grit my teeth... From steve+python at pearwood.info Sat Sep 17 23:26:30 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 18 Sep 2016 13:26:30 +1000 Subject: Is the content available in the html doc available in help()? References: Message-ID: <57de0968$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sun, 18 Sep 2016 10:50 am, Peng Yu wrote: > Hi, I want to get the same content as the html doc from help(). I am > not sure if this is possible (as I tried help(inspect) which does not > give the same content). Could anybody confirm if there is a way to get > the same content from help()? Thanks. > > https://docs.python.org/2/library/inspect.html help() does *not* return the same documentation as on the website. The website usually includes a lot more detail. The help() function introspects the python source code and formats the docstrings found, so it will often be very much smaller. If you want a copy of the actual Python docs from the website, use a third-party downloader to mirror the docs.python.org site. (On Linux, you can use wget.) But before you do that, which is considered a bit rude, have you checked *both* the Download and Documentation pages on the website to see if there is a link to download the documentation? Or you can get the .rst files from Python's source repository, then use Sphinx to compile the .rst files to HTML. If you are using Linux, your package manager (such as yum, apt-get or similar) may have a package for the Python docs. Try `yum install python-docs` or similar. On the other hand, if you want help() to generate the documentation as a HTML page, I don't think the help() function itself will do it, but the pydoc module does. You can call pydoc from the shell prompt (NOT the Python prompt, the shell): pydoc --help for details. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 17 23:28:42 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 18 Sep 2016 13:28:42 +1000 Subject: How to convert =?UTF-8?B?J8O2Jw==?= to 'oe' or 'o' (or other similar things) in a string? References: <10707163.O9o76ZdvQC@PointedEars.de> Message-ID: <57de09ea$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sun, 18 Sep 2016 07:19 am, Thomas 'PointedEars' Lahn wrote: > AFAIK, ???, ???, and ??? are not accented characters in any natural > language, but characters of their own (umlauts). Are you saying that English is not a natural language? -- 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 Sep 17 23:30:56 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 17 Sep 2016 22:30:56 -0500 Subject: =?UTF-8?Q?Re=3A_How_to_convert_=27=C3=B6=27_to_=27oe=27_or_=27o=27_=28or_other_sim?= =?UTF-8?Q?ilar_things=29_in_a_string=3F?= In-Reply-To: References: Message-ID: On Sat, Sep 17, 2016 at 3:20 PM, Martin Sch??n wrote: > Den 2016-09-17 skrev Kouli : >> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. I don't find a way to make it print oe for ?. Could anybody please advise what is the correct way to do it? ==> main.py <== #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: import sys from unidecode import unidecode print unidecode(sys.argv[1].decode('utf-8')) ==> main.sh <== #!/usr/bin/env bash # vim: set noexpandtab tabstop=2: ./main.py Sch??n $ ./main.sh Schoon >> Kouli >> >> On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: >>> Hi, I want to convert strings in which the characters with accents >>> should be converted to the ones without accents. Here is my current >>> code. > > Side note from Sweden. ?, ? and ? are not accented characters in our > language. They are characters of their own. If you want to look up > someone called ?hman in the phone directory you go to the ? section > not the O section. > > Related anecdote from Phoenix AZ. By now you have noticed my family > name: Sch??n. On airline tickets and boarding passes in the U.S. it > gets spelled Schoeoen. This landed me in a special security check > once. After a while the youngish lady performing the search started > to look like 1+1 did not sum up to 2. She looked at my passport > and boarding pass again and asked why I was there with her. I pointed > at another young lady, the one that 'scrutinized' passports and > boarding passes while chatting with a friend and said "She told me > to go over here." "Wait here, I have to talk to my supervisor." > > A few minutes passed (I was alone in the enhances security check > throughout...) and then "I am sorry but you should not have had > to go through here. There was a mistake." > > So there you are: If you are a middle aged, caucasian guy with > a passport from northern Europe and no 'funny' letters in your name > your are not a threat in the eyes of TSA in Arizona. > > Sorry for wasting the bandwidth. > > /Martin > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From rosuav at gmail.com Sat Sep 17 23:50:10 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Sep 2016 13:50:10 +1000 Subject: Is there something similar to `set -v` of bash in python In-Reply-To: References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> <55d8c135-fef3-4039-832e-e7637ae2c0b5@googlegroups.com> Message-ID: On Sun, Sep 18, 2016 at 1:08 PM, Peng Yu wrote: > The manual says the following. > > "The trace function is invoked (with event set to 'call') whenever a > new local scope is entered; it should return a reference to a local > trace function to be used that scope, or None if the scope shouldn?t > be traced." > > It means that one can not somehow settrace in one line and expect to > get the trace function being called in the next line. > > So something like `set -v` in bash sounds not possible. Is it so? Can you predict in advance that you might be using this? If so, you can define a trace function, and then activate and deactivate it on command (in any way you like). ChrisA From rosuav at gmail.com Sat Sep 17 23:55:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Sep 2016 13:55:45 +1000 Subject: array.itemsize: Documentation Versus Reality In-Reply-To: References: Message-ID: On Sun, Sep 18, 2016 at 1:16 PM, Lawrence D?Oliveiro wrote: > On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote: >> However, I see that MicroPython [1] has been ported to 16-bit >> PIC microcontrollers. An int should be 16-bit in that case. >> >> [1]: https://github.com/micropython/micropython > > From the readme: ?MicroPython implements the entire Python 3.4 syntax...? > > Darn. I don?t know whether to applaud or grit my teeth... What do you mean? It's not perfectly up-to-date with respect to CPython, but most alternate implementations lag a bit. However, it doesn't appear to have an 'itemsize' on its array. >>> a=array.array("l", (0,)) >>> dir(a) ['append', 'extend'] Not sure what that means about its sizes. ChrisA From greg.ewing at canterbury.ac.nz Sun Sep 18 00:11:35 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 18 Sep 2016 16:11:35 +1200 Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> Message-ID: Lawrence D?Oliveiro wrote: > On Friday, September 16, 2016 at 10:22:34 PM UTC+12, Christian Gollwitzer > wrote: > >> "How do I automate a Java application using Python?" > > Which is really a meaningless question. ?Automation? is what computer > programs do. It's not meaningless. The term "automation" is frequently used in the Windows world to mean programming something that you would otherwise do manually through a GUI, and that's clearly the sense in which it's being used here. -- Greg From eryksun at gmail.com Sun Sep 18 00:43:48 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 18 Sep 2016 04:43:48 +0000 Subject: array.itemsize: Documentation Versus Reality In-Reply-To: References: Message-ID: On Sun, Sep 18, 2016 at 3:55 AM, Chris Angelico wrote: > On Sun, Sep 18, 2016 at 1:16 PM, Lawrence D?Oliveiro > wrote: >> On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote: >>> However, I see that MicroPython [1] has been ported to 16-bit >>> PIC microcontrollers. An int should be 16-bit in that case. >>> >>> [1]: https://github.com/micropython/micropython >> >> From the readme: ?MicroPython implements the entire Python 3.4 syntax...? >> >> Darn. I don?t know whether to applaud or grit my teeth... > > What do you mean? It's not perfectly up-to-date with respect to > CPython, but most alternate implementations lag a bit. > > However, it doesn't appear to have an 'itemsize' on its array. > >>>> a=array.array("l", (0,)) >>>> dir(a) > ['append', 'extend'] > > Not sure what that means about its sizes. MicroPython's array and struct modules use a common mp_binary_get_size function: https://github.com/micropython/micropython/blob/v1.8.4/py/binary.c#L37 The array module uses native ("@") sizes, so the size of "i" and "I" is sizeof(int). From lawrencedo99 at gmail.com Sun Sep 18 00:53:31 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 17 Sep 2016 21:53:31 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> Message-ID: <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> On Sunday, September 18, 2016 at 4:11:49 PM UTC+12, Gregory Ewing wrote: > The term "automation" is frequently used in the Windows world to mean > programming something that you would otherwise do manually through a GUI... Which is not something that GUIs are designed for. Therefore it is at best an unreliable exercise, at worst futile. From eryksun at gmail.com Sun Sep 18 01:16:23 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 18 Sep 2016 05:16:23 +0000 Subject: Is the content available in the html doc available in help()? In-Reply-To: <57de0968$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <57de0968$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 18, 2016 at 3:26 AM, Steve D'Aprano wrote: > help() does *not* return the same documentation as on the website. The > website usually includes a lot more detail. > > The help() function introspects the python source code and formats the > docstrings found, so it will often be very much smaller. help() also uses a topics dict, from pydoc_data.topics, which gets extracted when building the .rst docs. Check help('topics') and help('keywords'). There's also help('symbols'), which lists the punctuation symbols that help maps to various topics. For example, help('**') gets mapped to help('POWER') and also prints a list of related topics for the user, which includes "EXPRESSIONS" and "OPERATORS" in this case. Obviously modules in the standard library are documented in much more detail in the python.org docs. pydoc_data would be gargantuan otherwise. But I think there's actually enough info available in help() that someone proficient in another language could use it to get started programming in Python without any other documentation, tutorials, or books. From steve+comp.lang.python at pearwood.info Sun Sep 18 01:58:08 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 18 Sep 2016 15:58:08 +1000 Subject: how to automate java application in window using python References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> Message-ID: <57de2cf1$0$11118$c3e8da3@news.astraweb.com> On Sunday 18 September 2016 14:53, Lawrence D?Oliveiro wrote: > On Sunday, September 18, 2016 at 4:11:49 PM UTC+12, Gregory Ewing wrote: >> The term "automation" is frequently used in the Windows world to mean >> programming something that you would otherwise do manually through a GUI... > > Which is not something that GUIs are designed for. Therefore it is at best an > unreliable exercise, at worst futile. Cheese is not designed to be grated and put on spaghetti. Therefore grating cheese is at best an unreliable exercise, at worst futile. Can you see the fallacy in your assertion yet? Do I have to spell it out for you? In any case, there are many software applications for automating GUI apps. Contrary to your assertion, it works reliably. https://duckduckgo.com/?q=gui+automation&ia=web It would be astonishing if it didn't -- after all, GUI apps interact with the user not by magic, but via an event queue of mouse movements, clicks, key presses, etc. This queue is entirely under the control of the computer, which means a program can simulate a user moving the mouse, clicking, pressing keys, etc. There's no magic here. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From thorsten at thorstenkampe.de Sun Sep 18 01:59:36 2016 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 18 Sep 2016 07:59:36 +0200 Subject: =?utf-8?Q?How_to_convert_'=C3=B6'_to_'oe'_or_'o'_(or_other_si?= =?utf-8?Q?milar_things)_in_a_string??= References: Message-ID: * Martin Sch??n (17 Sep 2016 20:20:12 GMT) > > Den 2016-09-17 skrev Kouli : > > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. > > > > Kouli > > > > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: > >> Hi, I want to convert strings in which the characters with accents > >> should be converted to the ones without accents. Here is my current > >> code. > > Side note from Sweden. ?, ? and ? are not accented characters in our > language. They are characters of their own. I think he meant diacritics. Thorsten From steve+comp.lang.python at pearwood.info Sun Sep 18 02:31:05 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 18 Sep 2016 16:31:05 +1000 Subject: How to convert =?UTF-8?B?J8O2Jw==?= to 'oe' or 'o' (or other similar things) in a string? References: Message-ID: <57de34ac$0$1591$c3e8da3$5496439d@news.astraweb.com> On Sunday 18 September 2016 13:30, Peng Yu wrote: > On Sat, Sep 17, 2016 at 3:20 PM, Martin Sch??n > wrote: >> Den 2016-09-17 skrev Kouli : >>> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. > > I don't find a way to make it print oe for ?. Could anybody please > advise what is the correct way to do it? In general, there is no One Correct Way to translate accented characters into ASCII. It depends on the language, and the word. For instance, in English ? will usually be translated into just o with no accent. We usually write co?perate and zo?logy as cooperate and zoology, or sometimes with a hyphen co-operate, but never cooeperate or zooelogy. But if the word is derived from German, or words that *look* like they might be German, we do sometimes use oe: Roentgen rays (an old term for x-rays) after Wilhelm R?ntgen, for instance. But in other languages the rules will be different. How, for example, should one translate an Estonian word containing ? into Turkish, but using ASCII letters only? I have no idea. But in both languages, and unlike German, ? is *not* considered an o-with-an-accent, but a distinct letter of the alphabet. https://en.wikipedia.org/wiki/Diaeresis_%28diacritic%29 As far as Python goes, if all you want to do is replace ? with oe and ? into OE (or perhaps you should use ? and ??) then you can use str.replace or string.translate: mystring.replace("?", "OE").replace("?", "oe") -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From steve+comp.lang.python at pearwood.info Sun Sep 18 02:45:36 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 18 Sep 2016 16:45:36 +1000 Subject: How to convert =?UTF-8?B?J8O2Jw==?= to 'oe' or 'o' (or other similar things) in a string? References: Message-ID: <57de3813$0$1507$c3e8da3$5496439d@news.astraweb.com> On Sunday 18 September 2016 15:59, Thorsten Kampe wrote: > * Martin Sch??n (17 Sep 2016 20:20:12 GMT) >> >> Den 2016-09-17 skrev Kouli : >> > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. >> > >> > Kouli >> > >> > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: >> >> Hi, I want to convert strings in which the characters with accents >> >> should be converted to the ones without accents. Here is my current >> >> code. >> >> Side note from Sweden. ?, ? and ? are not accented characters in our >> language. They are characters of their own. > > I think he meant diacritics. It doesn't matter whether you call them "accent" like most people do, or "diacritics" as linguists do. Either way, in some languages they are an integral part of the letter, like the horizonal stroke in English t or the vertical bar in English p and b, and in some languages they are modifiers, where there are rules that tell you how to write them without the modifier. In English, i is a letter with a dot diacritic, sometimes called the "tittle". But unlike Turkish, we don't have a dotless i, ?, and to add to the confusion when we capitalise i we get I with no dot instead of ?. Dropping the dot, or adding one when you shouldn't, can *literally* get you killed: http://gizmodo.com/382026/a-cellphones-missing-dot-kills-two-people-puts-three- more-in-jail http://www.theinquirer.net/inquirer/news/1017243/cellphone-localisation-glitch As far as I know, no natural language has a dotted capital J, but there is a dotless ? although I'm not sure what language it is from. (Possibly just used in mathematics?) -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From tjreedy at udel.edu Sun Sep 18 03:51:40 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Sep 2016 03:51:40 -0400 Subject: =?UTF-8?Q?Re:_How_to_convert_'=c3=b6'_to_'oe'_or_'o'_=28or_other_si?= =?UTF-8?Q?milar_things=29_in_a_string=3f?= In-Reply-To: <57de3813$0$1507$c3e8da3$5496439d@news.astraweb.com> References: <57de3813$0$1507$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/18/2016 2:45 AM, Steven D'Aprano wrote: > It doesn't matter whether you call them "accent" like most people do, or > "diacritics" as linguists do. I am a native born American and I have never before heard or seen non-accent diacritic marks called 'accents'. Accents indicate stress. Other diacritics indicate other pronunciation changes. It is counterproductive to confuse the two groups. Spanish, for instance, has vowel accents that change which syllable gets stressed. A tilda is not an accent; rather, it softens the pronunciation of 'n' to 'ny', as in 'canyon'. Terry Jan Reedy From m at funkyhat.org Sun Sep 18 04:53:50 2016 From: m at funkyhat.org (Matt Wheeler) Date: Sun, 18 Sep 2016 08:53:50 +0000 Subject: how to automate java application in window using python In-Reply-To: References: Message-ID: On Thu, 15 Sep 2016, 08:12 meInvent bbird, wrote: > how to automate java application in window using python > > 1. scroll up or down of scroll bar > 2. click button > 3. type text in textbox > I would recommend having a look at pywinauto https://github.com/pywinauto/pywinauto It presents a very nice pythonic interface to Windows and the controls within them, allowing statements such as (copied from the Readme): app.UntitledNotepad.MenuSelect("Help->About Notepad") app.AboutNotepad.OK.Click() app.UntitledNotepad.Edit.TypeKeys ("pywinauto Works!", with_spaces = True) (I found it already quite stable when I first used it a couple of years ago, and looking at the Readme now it's clearly still an active project, the optional image capture feature using pillow is new) > From no.email at nospam.invalid Sun Sep 18 05:25:42 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 18 Sep 2016 02:25:42 -0700 Subject: how to automate java application in window using python References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> Message-ID: <8737kxd0fd.fsf@jester.gateway.pace.com> Lawrence D?Oliveiro writes: >> The term "automation" is frequently used in the Windows world to mean >> programming something that you would otherwise do manually through a GUI... > Which is not something that GUIs are designed for. Therefore it is at > best an unreliable exercise, at worst futile. Windows applications often (usually?) provide automation interfaces, which are what the rest of us would call API's. This has been done in a lot of ways: OLE and COM objects back in the day, .NET currently, other things in between. It's not done by screen scraping or anything stupid like that. It's actually pretty well thought out, though with the usual layers of Microsoft and OOP bureaucracy around everything. From auriocus at gmx.de Sun Sep 18 05:55:01 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 18 Sep 2016 11:55:01 +0200 Subject: =?UTF-8?Q?Re:_How_to_convert_'=c3=b6'_to_'oe'_or_'o'_=28or_other_si?= =?UTF-8?Q?milar_things=29_in_a_string=3f?= In-Reply-To: <10707163.O9o76ZdvQC@PointedEars.de> References: <10707163.O9o76ZdvQC@PointedEars.de> Message-ID: Am 17.09.16 um 23:19 schrieb Thomas 'PointedEars' Lahn: > Peng Yu wrote: > >> Hi, I want to convert strings in which the characters with accents >> should be converted to the ones without accents. > > Why? > >> [?] >> ./main.py F?rstemann > > AFAIK, ???, ???, and ??? are not accented characters in any natural > language, but characters of their own (umlauts). > > In particular, I know for certain that they are not accented in Germanic > languages. Swedish has been mentioned; I can add my native language, > German, to that list. In German, they are letters, but they collate as either ae, oe, ue (rarely) or a, o, u (modern style). Ad dictionary or phone book does not have an "?" section in Germany. Example from a German-Latin dictionary, printed in 1958 Laster -> vitium L?sterer -> homo maledicus lasterhaft -> vitiosus If "?" would sort as a single letter, "L?sterer" would be the last entry. If it would sort as "ae", it would be the first entry. Therfore, in this example it sorts as "a", with "?" > "a" to resolve a tie only. Christian From lawrencedo99 at gmail.com Sun Sep 18 06:03:53 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 18 Sep 2016 03:03:53 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <8737kxd0fd.fsf@jester.gateway.pace.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: On Sunday, September 18, 2016 at 9:25:53 PM UTC+12, Paul Rubin wrote: > > Lawrence D?Oliveiro writes: > >>> The term "automation" is frequently used in the Windows world to mean >>> programming something that you would otherwise do manually through a GUI... >> >> Which is not something that GUIs are designed for. Therefore it is at >> best an unreliable exercise, at worst futile. > > Windows applications often (usually?) provide automation interfaces, > which are what the rest of us would call API's. This has been done in a > lot of ways: OLE and COM objects back in the day, .NET currently, other > things in between. It's not done by screen scraping or anything stupid > like that. It's actually pretty well thought out, though with the usual > layers of Microsoft and OOP bureaucracy around everything. None of the different ways of which are either a) compatible or b) widely supported. Particularly not in Java, as the OP was asking. Like I said, trying to automate a GUI is a waste of time. GUIs are designed for humans, not computers, to use. That?s why we have command lines and scripting (which are all just programming at different layers, of course). That?s how you automate things, building higher-level abstract machines on top of lower-level ones. GUIs are the end of the abstraction chain: you cannot build anything more on top of them. From auriocus at gmx.de Sun Sep 18 06:13:30 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 18 Sep 2016 12:13:30 +0200 Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: Am 18.09.16 um 12:03 schrieb Lawrence D?Oliveiro: > Like I said, trying to automate a GUI is a waste of time. GUIs are > designed for humans, not computers, to use. You don't always have a choice. Consider batch-processing a number of images (say, 30,000 movie frames) using a proprietary effect filter which works on single images only. It might be easier to drive the GUI than to recreate the commercial algorithm. > That?s why we have command lines and scripting (which are all just > programming at different layers, of course). That?s how you automate > things, building higher-level abstract machines on top of lower-level > ones. GUIs are the end of the abstraction chain: you cannot build > anything more on top of them. Yes, you can. I agree with you that it is a shaky solution, but that doesn't make it impossible. Christian From lawrencedo99 at gmail.com Sun Sep 18 06:26:41 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 18 Sep 2016 03:26:41 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> On Sunday, September 18, 2016 at 10:13:41 PM UTC+12, Christian Gollwitzer wrote: > > Am 18.09.16 um 12:03 schrieb Lawrence D?Oliveiro: > >> Like I said, trying to automate a GUI is a waste of time. GUIs are >> designed for humans, not computers, to use. > > You don't always have a choice. Consider batch-processing a number of > images (say, 30,000 movie frames) using a proprietary effect filter > which works on single images only. It might be easier to drive the GUI > than to recreate the commercial algorithm. Considering the power available in Free Software toolkits like ImageMagick, G?MIC and so on, not to mention libraries accessible from Python itself, let me suggest that such proprietary software simply isn?t worth bothering with any more. > I agree with you that it is a shaky solution, but that > doesn't make it impossible. Is it really something you want to entrust mission-critical business functions to? From lawrencedo99 at gmail.com Sun Sep 18 06:28:54 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 18 Sep 2016 03:28:54 -0700 (PDT) Subject: Functions Of Functions Returning Functions Message-ID: <8bfa17c3-1c8b-4960-b6a3-fbaf279200af@googlegroups.com> The less code you have to write, the better. Less code means less maintenance, and fewer opportunities for bugs. Here is an example of how I was able to knock a few hundred lines off the size of a Python module. When I was writing my Python wrapper for HarfBuzz , there were a lot of places where you could define routines for HarfBuzz to make calls to, to customize the type-shaping process in various ways. Of course, HarfBuzz is a library written in C++, and it doesn?t know that the callbacks you pass are actually written in Python. But ctypes provides an answer to this: its CFUNCTYPE function lets you wrap Python functions so that they become callable from C/C++ code. When I said there were a lot of places for callbacks, I meant a lot of places. For example, there is a HarfBuzz object called ?hb_font_funcs? , which consists of nothing more than a container for 14 different action callback routines. Not only that, but each one lets you pass a separate ?user data? pointer to the action callback, along with an optional ?destroy? callback which can do any necessary cleanup of this data, which will be called when the hb_font_funcs object is disposed. Imagine having to set all of these up by hand. Each API call to install a callback would look something like this: def set_xxx_callback(self, callback_func, user_data, destroy) : "sets the xxx callback, along with an optional destroy callback" \ " for the user_data. The callback_func should be declared as follows:\n" \ "\n" \ " def callback_func(self, ... xxx-specific args ..., user_data)\n" \ "\n" \ "where self is the FontFuncs instance ... description of xxx-specific args." def def_wrap_xxx_callback(self, callback_func, user_data) # generates ctypes wrapper for caller-specified Python function. @HB.font_get_xxx_func_t def wrap_xxx_callback(... xxx-specific args ..., c_user_data) : ... convert xxx-specific args from ctypes representation to ... ... higher-level Python representation, pass to callback_func, ... ... along with user_data, then convert any result to ctypes ... ... representation and return as my result ... #end wrap_xxx_callback #begin def_wrap_xxx_callback return \ wrap_xxx_callback #end def_wrap_xxx_callback #begin set_xxx_callback wrap_callback_func = def_wrap_xxx_callback(self, callback_func, user_data) if destroy != None : @HB.destroy_func_t def wrap_destroy(c_user_data) : destroy(user_data) #end wrap_destroy else : wrap_destroy = None #end if # save references to wrapper objects to prevent them prematurely # disappearing (common ctypes gotcha) self._wrap_xxx_func = wrap_callback_func self._wrap_xxx_destroy_func = wrap_destroy hb.hb_font_funcs_set_xxx_func(self._hbobj, wrap_callback_func, None, wrap_destroy) #end set_callback Just think if you had to do this 14 times. And then there are a couple of other HarfBuzz objects with their own similar collections of callbacks as well... Luckily, I figured out a way to cut the amount of code needed for this by about half. It?s the recognition that the only part that is different between all these callback-setting calls is the ?def_wrap_xxx_callback? function, together with a few different attribute names elsewhere. So I encapsulated the common part of all this setup into the following routine: def def_callback_wrapper(celf, method_name, docstring, callback_field_name, destroy_field_name, def_wrap_callback_func, hb_proc) : # Common routine for defining a set-callback method. These all have the same form, # where the caller specifies # * the callback function # * an additional user_data pointer (meaning is up the caller) # * an optional destroy callback which is passed the user_data pointer # when the containing object is destroyed. # The only variation is in the arguments and result type of the callback. def set_callback(self, callback_func, user_data, destroy) : # This becomes the actual set-callback method. wrap_callback_func = def_wrap_callback_func(self, callback_func, user_data) if destroy != None : @HB.destroy_func_t def wrap_destroy(c_user_data) : destroy(user_data) #end wrap_destroy else : wrap_destroy = None #end if setattr(self, callback_field_name, wrap_callback_func) setattr(self, destroy_field_name, wrap_destroy) getattr(hb, hb_proc)(self._hbobj, wrap_callback_func, None, wrap_destroy) #end set_callback #begin def_callback_wrapper set_callback.__name__ = method_name set_callback.__doc__ = docstring setattr(celf, method_name, set_callback) #end def_callback_wrapper Something else that saved even more code was noticing that some callbacks came in pairs, sharing the same routine types. For example, the font_h_extents and font_v_extents callbacks had matching types, they were simply operating along different axes. For both of these, I could define a common callback-wrapper definer, as follows: def def_wrap_get_font_extents_func(self, get_font_extents, user_data) : @HB.font_get_font_extents_func_t def wrap_get_font_extents(c_font, c_font_data, c_metrics, c_user_data) : metrics = get_font_extents(self, get_font_data(c_font_data), user_data) if metrics != None : c_metrics.ascender = metrics.ascender c_metrics.descender = metrics.descender c_metrics.line_gap = metrics.line_gap #end if return \ metrics != None #end wrap_get_font_extents #begin def_wrap_get_font_extents_func return \ wrap_get_font_extents #end def_wrap_get_font_extents_func and the code for defining all 14 callbacks becomes as simple as for basename, def_func, protostr, resultstr in \ ( ("font_h_extents", def_wrap_get_font_extents_func, "get_font_h_extents(self, font_data, user_data)", " FontExtents or None"), ("font_v_extents", def_wrap_get_font_extents_func, "get_font_v_extents(self, font_data, user_data)", " FontExtents or None"), ... entries for remaining callbacks ... ) \ : def_callback_wrapper \ ( celf = FontFuncs, method_name = "set_%s_func" % basename, docstring = "sets the %(name)s_func callback, along with an optional destroy" " callback for the user_data. The callback_func should be declared" " as follows:\n" "\n" " def %(proto)s\n" "\n" " where self is the FontFuncs instance and font_data was what was" " passed to set_font_funcs for the Font, and return a%(result)s." % {"name" : basename, "proto" : protostr, "result" : resultstr}, callback_field_name = "_wrap_%s_func" % basename, destroy_field_name = "_wrap_%s_destroy" % basename, def_wrap_callback_func = def_func, hb_proc = "hb_font_funcs_set_%s_func" % basename, ) #end for The above loop is executed at the end of creating the basic FontFuncs class, to fill in the methods for setting the callbacks. This shows the power of functions as first-class objects. The concept is older than object orientation, and is often left out of object-oriented languages. I think Python benefits from the fact that it had functions before it had classes. From no.email at nospam.invalid Sun Sep 18 06:42:04 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 18 Sep 2016 03:42:04 -0700 Subject: how to automate java application in window using python References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: <87y42pbibn.fsf@jester.gateway.pace.com> Lawrence D?Oliveiro writes: >> lot of ways: OLE and COM objects back in the day, .NET currently, > None of the different ways of which are either a) compatible or b) > widely supported. Particularly not in Java, as the OP was asking. I'm quite sure there are Java bindings for all those protocols. > Like I said, trying to automate a GUI is a waste of time. GUIs are > designed for humans, not computers, to use. Automation doesn't simulate button presses or anything like that: the automate objects expose higher level user actions. E.g. the web browser object has a navigate method and that sort of thing. The classic automation example is embedding a chunk of an Excel spreadsheet in the middle of a Word document, so it's displayed with Word's fonts and formatting, but when you change a number in the spreadsheet segment, the formulas run and the other numbers change. What happens there is Word collects the numbers you type, then calls the Excel automation interfaces to update the relevant spreadsheet cells and read back new numbers. There are various hacks in KDE, Gnome, etc. to do similar things under Linux. It's all transparent to the user and presents useful features. > GUIs are the end of the abstraction chain: you cannot build anything > more on top of them. IMHO you're not contributing useful insights through these incorrect guesses about how Windows automation works. From martin.schoon at gmail.com Sun Sep 18 06:51:12 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 18 Sep 2016 10:51:12 GMT Subject: How to convert =?UTF-8?Q?=27=C3=B6=27?= to 'oe' or 'o' (or other similar things) in a string? References: <87k2eamb3c.fsf@elektro.pacujo.net> Message-ID: Den 2016-09-17 skrev Marko Rauhamaa : > Martin Sch??n : >> Related anecdote from Phoenix AZ. By now you have noticed my family >> name: Sch??n. On airline tickets and boarding passes in the U.S. it >> gets spelled Schoeoen. > > Do Swedes do that German thing, too? If you have to write Finnish > without ? and ?, you simply leave out the dots. (On the other hand, if > you need ? or ? and don't have them, you replace them with sh and zh.) > > Marko This is a problem of the past I think. When the problem arises -- well I am of aware of standard Swedish way. American typographer Robert Bringhurst is not happy with the computer guys who thought half as many glyphs as Gutemberg worked with was enough back in the days when 7-bit ascii was conceived. See "The Elements of Typographic Style". /Martin From auriocus at gmx.de Sun Sep 18 07:02:46 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 18 Sep 2016 13:02:46 +0200 Subject: how to automate java application in window using python In-Reply-To: <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> Message-ID: Am 18.09.16 um 12:26 schrieb Lawrence D?Oliveiro: > On Sunday, September 18, 2016 at 10:13:41 PM UTC+12, Christian > Gollwitzer wrote: >> >> Am 18.09.16 um 12:03 schrieb Lawrence D?Oliveiro: >> >>> Like I said, trying to automate a GUI is a waste of time. GUIs >>> are designed for humans, not computers, to use. >> >> You don't always have a choice. Consider batch-processing a number >> of images (say, 30,000 movie frames) using a proprietary effect >> filter which works on single images only. It might be easier to >> drive the GUI than to recreate the commercial algorithm. > > Considering the power available in Free Software toolkits like > ImageMagick, G?MIC and so on, not to mention libraries accessible > from Python itself, let me suggest that such proprietary software > simply isn?t worth bothering with any more. I was expecting that argument. Free software gives you a lot in this area, but there are commercial signal processing programs with unmatched quality. Examples: https://ni.neatvideo.com/ or for audio http://www.celemony.com/en/melodyne/what-is-melodyne Their business model relies on (nontrivial) secret algorithms. Even if the algorithm is published it might be too tedious to reimplement it from the scientific paper because it takes months of work or resources you don't have; for instance, this algorithm http://graphics.cs.cmu.edu/projects/scene-completion/scene-completion.pdf requires you to have millions of stock photo images, which you are allowed to use. If you are flickr, getty or Google, you have no problem. Otherwise it will be hard. > >> I agree with you that it is a shaky solution, but that doesn't make >> it impossible. > > Is it really something you want to entrust mission-critical business > functions to? As always, it depends. I wouldn't rest my money on a bank account which is managed by driving Excel via Sikuli. OTOH, I wouldn't want to spend years of work to recreate NeatImage to denoise the photos of my last holiday trip. Here, driving the GUI is fine. Christian From steve+python at pearwood.info Sun Sep 18 07:21:50 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 18 Sep 2016 21:21:50 +1000 Subject: Functions Of Functions Returning Functions References: <8bfa17c3-1c8b-4960-b6a3-fbaf279200af@googlegroups.com> Message-ID: <57de78d1$0$1618$c3e8da3$5496439d@news.astraweb.com> On Sun, 18 Sep 2016 08:28 pm, Lawrence D?Oliveiro wrote: > This shows the power of functions as first-class objects. The concept > is older than object orientation, and is often left out of > object-oriented languages. I think Python benefits from the fact that > it had functions before it had classes. You're right about Python having functions first: steve at runes:~$ python0.9.1 >>> def f(): ... pass ... >>> class A: Parsing error: file , line 1: class A: ^ Unhandled exception: run-time error: syntax error However it only gained closures and nested scopes in Python 2.2, or with a __future__ directive in 2.1. https://www.python.org/dev/peps/pep-0227/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 18 07:31:37 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 18 Sep 2016 21:31:37 +1000 Subject: how to automate java application in window using python References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <87y42pbibn.fsf@jester.gateway.pace.com> Message-ID: <57de7b1b$0$1588$c3e8da3$5496439d@news.astraweb.com> On Sun, 18 Sep 2016 08:42 pm, Paul Rubin wrote: > Lawrence D?Oliveiro writes: >>> lot of ways: OLE and COM objects back in the day, .NET currently, >> None of the different ways of which are either a) compatible or b) >> widely supported. Particularly not in Java, as the OP was asking. > > I'm quite sure there are Java bindings for all those protocols. > >> Like I said, trying to automate a GUI is a waste of time. GUIs are >> designed for humans, not computers, to use. > > Automation doesn't simulate button presses or anything like that: the > automate objects expose higher level user actions. E.g. the web browser > object has a navigate method and that sort of thing. Rather than saying that it *doesn't*, it might be better to say that it doesn't *necessarily* simulate button presses. The thing about simulating button presses is that: (1) you can absolutely guarantee that it does exactly the same as what happens when a user clicks the button, because there's no difference between a mouseclick event caused by a human clicking the mouse, a mouseclick event caused by a robot clicking the mouse, and a mouseclick event generated by software. They're ALL generated by software, and the application cannot tell them apart. (2) It works even if the application doesn't offer an OLE, COM or scripting interface. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ned at nedbatchelder.com Sun Sep 18 08:01:14 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 18 Sep 2016 05:01:14 -0700 (PDT) Subject: Is there something similar to `set -v` of bash in python In-Reply-To: References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> <55d8c135-fef3-4039-832e-e7637ae2c0b5@googlegroups.com> Message-ID: <08a04744-956d-4ed8-8e87-eb63156f28cc@googlegroups.com> On Saturday, September 17, 2016 at 11:09:04 PM UTC-4, Peng Yu wrote: > The manual says the following. > > "The trace function is invoked (with event set to 'call') whenever a > new local scope is entered; it should return a reference to a local > trace function to be used that scope, or None if the scope shouldn?t > be traced." > > It means that one can not somehow settrace in one line and expect to > get the trace function being called in the next line. > > So something like `set -v` in bash sounds not possible. Is it so? You've found a good reason why "set -v" would be very difficult if not impossible in Python. I'm curious though, why you would want to trace every line in a program every time you (or anyone else) ran it? I view tracing lines as a debugging technique. Once the program is behaving properly, why do you want all the noise of the traced lines? In Bash scripts we do it because some scripts are light automation where the person running the script should have a clear idea of what actions it is taking. The actions in the script are commands that the person might run themselves at other times, and so the difference between running the script and running the commands is not great. But in a Python program, presumably the difference is greater. I cannot type out single Python lines at my shell prompt to perform the actions the Python program does. Perhaps you want to define an alias for "python -m trace -t $*" ? --Ned. From pengyu.ut at gmail.com Sun Sep 18 08:29:16 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 18 Sep 2016 07:29:16 -0500 Subject: Is there something similar to `set -v` of bash in python In-Reply-To: <08a04744-956d-4ed8-8e87-eb63156f28cc@googlegroups.com> References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> <55d8c135-fef3-4039-832e-e7637ae2c0b5@googlegroups.com> <08a04744-956d-4ed8-8e87-eb63156f28cc@googlegroups.com> Message-ID: On Sunday, September 18, 2016, Ned Batchelder wrote: > On Saturday, September 17, 2016 at 11:09:04 PM UTC-4, Peng Yu wrote: > > The manual says the following. > > > > "The trace function is invoked (with event set to 'call') whenever a > > new local scope is entered; it should return a reference to a local > > trace function to be used that scope, or None if the scope shouldn?t > > be traced." > > > > It means that one can not somehow settrace in one line and expect to > > get the trace function being called in the next line. > > > > So something like `set -v` in bash sounds not possible. Is it so? > > You've found a good reason why "set -v" would be very difficult if > not impossible in Python. > > I'm curious though, why you would want to trace every line in a > program every time you (or anyone else) ran it? This is for debugging not for normal run. But I need the ability to control the range of the code in which the debug message is printed. > I view tracing lines > as a debugging technique. Once the program is behaving properly, why > do you want all the noise of the traced lines? > > In Bash scripts we do it because some scripts are light automation > where the person running the script should have a clear idea of what > actions it is taking. The actions in the script are commands that the > person might run themselves at other times, and so the difference > between running the script and running the commands is not great. > > But in a Python program, presumably the difference is greater. I cannot > type out single Python lines at my shell prompt to perform the actions > the Python program does. > > Perhaps you want to define an alias for "python -m trace -t $*" ? > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Regards, Peng From martinjp376 at gmail.com Sun Sep 18 09:20:55 2016 From: martinjp376 at gmail.com (kerbingamer376) Date: Sun, 18 Sep 2016 06:20:55 -0700 (PDT) Subject: Serialising an 8x8x8 array of pygame sounds Message-ID: <3803cebb-097b-4a40-a6d5-e4eb6ff187e1@googlegroups.com> Is it possible to serialise an 8x8x8 array of pygame.mixer.Sound objects, so they stay at the same places in the array, but in a format that can be pickled, and then the opposite (read from that back to pygame.mixer.Sound objects)? Thanks (copied from stackoverflow question @ https://is.gd/JDtURe) From ned at nedbatchelder.com Sun Sep 18 09:39:34 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 18 Sep 2016 06:39:34 -0700 (PDT) Subject: Is there something similar to `set -v` of bash in python In-Reply-To: References: <57dce4aa$0$22141$c3e8da3$5496439d@news.astraweb.com> <55d8c135-fef3-4039-832e-e7637ae2c0b5@googlegroups.com> <08a04744-956d-4ed8-8e87-eb63156f28cc@googlegroups.com> Message-ID: <8509330b-0d2c-476f-80c1-2753b1bc7a7e@googlegroups.com> On Sunday, September 18, 2016 at 8:29:38 AM UTC-4, Peng Yu wrote: > On Sunday, September 18, 2016, Ned Batchelder wrote: > > > On Saturday, September 17, 2016 at 11:09:04 PM UTC-4, Peng Yu wrote: > > > The manual says the following. > > > > > > "The trace function is invoked (with event set to 'call') whenever a > > > new local scope is entered; it should return a reference to a local > > > trace function to be used that scope, or None if the scope shouldn?t > > > be traced." > > > > > > It means that one can not somehow settrace in one line and expect to > > > get the trace function being called in the next line. > > > > > > So something like `set -v` in bash sounds not possible. Is it so? > > > > You've found a good reason why "set -v" would be very difficult if > > not impossible in Python. > > > > I'm curious though, why you would want to trace every line in a > > program every time you (or anyone else) ran it? > > > This is for debugging not for normal run. But I need the ability to control > the range of the code in which the debug message is printed. There is a programmatic interface: https://docs.python.org/2/library/trace.html#programmatic-interface If the section you want to trace is a function call, then you can make it work. --Ned. From bogus@does.not.exist.com Sun Sep 18 09:43:09 2016 From: bogus@does.not.exist.com (not1xor1) Date: Sun, 18 Sep 2016 15:43:09 +0200 Subject: =?UTF-8?Q?Re:_How_to_convert_'=c3=b6'_to_'oe'_or_'o'_=28or_other_si?= =?UTF-8?Q?milar_things=29_in_a_string=3f?= References: <57de3813$0$1507$c3e8da3$5496439d@news.astraweb.com> Message-ID: Il 18/09/2016 08:45, Steven D'Aprano ha scritto: > integral part of the letter, like the horizonal stroke in English t or the > vertical bar in English p and b, and in some languages they are modifiers, well... that is the Latin alphabet English has no T, P or B (or any other character) but is just (mis)using the Latin alphabet (which is just a few centuries older than the English language itself) :-) -- bye !(!1|1) From steve+python at pearwood.info Sun Sep 18 09:59:00 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 18 Sep 2016 23:59:00 +1000 Subject: Serialising an 8x8x8 array of pygame sounds References: <3803cebb-097b-4a40-a6d5-e4eb6ff187e1@googlegroups.com> Message-ID: <57de9da4$0$1597$c3e8da3$5496439d@news.astraweb.com> On Sun, 18 Sep 2016 11:20 pm, kerbingamer376 wrote: > Is it possible to serialise an 8x8x8 array of pygame.mixer.Sound objects, > so they stay at the same places in the array, but in a format that can be > pickled, and then the opposite (read from that back to pygame.mixer.Sound > objects)? Can you seralise *one* Sound object? If not, then you can't serialise an array of Sound objects either. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Sep 18 10:11:58 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Sep 2016 00:11:58 +1000 Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: On Sun, Sep 18, 2016 at 8:03 PM, Lawrence D?Oliveiro wrote: > Like I said, trying to automate a GUI is a waste of time. GUIs are designed for humans, not computers, to use. Okay, then. Come up with a way to end-to-end-test a GUI application without some form of GUI automation. Sometimes, coming up with a more computer-friendly way to do something fundamentally defeats the purpose. ChrisA From martinjp376 at gmail.com Sun Sep 18 10:51:26 2016 From: martinjp376 at gmail.com (kerbingamer376) Date: Sun, 18 Sep 2016 07:51:26 -0700 (PDT) Subject: Serialising an 8x8x8 array of pygame sounds In-Reply-To: <57de9da4$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <3803cebb-097b-4a40-a6d5-e4eb6ff187e1@googlegroups.com> <57de9da4$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5c04a84f-9312-42ee-8016-e4258578b91d@googlegroups.com> On Sunday, September 18, 2016 at 2:59:10 PM UTC+1, Steve D'Aprano wrote: > On Sun, 18 Sep 2016 11:20 pm, kerbingamer376 wrote: > > > Is it possible to serialise an 8x8x8 array of pygame.mixer.Sound objects, > > so they stay at the same places in the array, but in a format that can be > > pickled, and then the opposite (read from that back to pygame.mixer.Sound > > objects)? > > Can you seralise *one* Sound object? > > If not, then you can't serialise an array of Sound objects either. > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. That's my problem, the Sound object can't be picked, I was wondering if a way existed to convert said object to a serialize-able format. From __peter__ at web.de Sun Sep 18 11:17:06 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 18 Sep 2016 17:17:06 +0200 Subject: Serialising an 8x8x8 array of pygame sounds References: <3803cebb-097b-4a40-a6d5-e4eb6ff187e1@googlegroups.com> <57de9da4$0$1597$c3e8da3$5496439d@news.astraweb.com> <5c04a84f-9312-42ee-8016-e4258578b91d@googlegroups.com> Message-ID: kerbingamer376 wrote: > On Sunday, September 18, 2016 at 2:59:10 PM UTC+1, Steve D'Aprano wrote: >> On Sun, 18 Sep 2016 11:20 pm, kerbingamer376 wrote: >> >> > Is it possible to serialise an 8x8x8 array of pygame.mixer.Sound >> > objects, so they stay at the same places in the array, but in a format >> > that can be pickled, and then the opposite (read from that back to >> > pygame.mixer.Sound objects)? >> >> Can you seralise *one* Sound object? >> >> If not, then you can't serialise an array of Sound objects either. >> >> >> >> -- >> Steve >> ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure >> enough, things got worse. > > That's my problem, the Sound object can't be picked, I was wondering if a > way existed to convert said object to a serialize-able format. If the Sound object exposes enough of its state to build an equivalent one from that state there's a way to write and register your own serialization routine. See https://docs.python.org/2/library/copy_reg.html From no.email at nospam.invalid Sun Sep 18 13:25:17 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 18 Sep 2016 10:25:17 -0700 Subject: how to automate java application in window using python References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <87y42pbibn.fsf@jester.gateway.pace.com> <57de7b1b$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twddaznm.fsf@jester.gateway.pace.com> Steve D'Aprano writes: >> Automation doesn't simulate button presses > Rather than saying that it *doesn't*, it might be better to say that it > doesn't *necessarily* simulate button presses. I'm no Windoze guru but I always understood Automation (sometimes written with a capital A) to refer to a specific set of interfaces. I.e. it's not a generic term for driving one program with another. As with almost everything, there's a wiki article: https://en.wikipedia.org/wiki/OLE_Automation > The thing about simulating button presses is that: > (1) you can absolutely guarantee that it does exactly the same as what Yes, this is valuable for UI testing and there were/are several testing systems that work that way. Automation is something different. From thorsten at thorstenkampe.de Sun Sep 18 15:34:58 2016 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 18 Sep 2016 21:34:58 +0200 Subject: =?utf-8?Q?How_to_convert_'=C3=B6'_to_'oe'_or_'o'_(or_other_si?= =?utf-8?Q?milar_things)_in_a_string??= References: <57de3813$0$1507$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Terry Reedy (Sun, 18 Sep 2016 03:51:40 -0400) > > On 9/18/2016 2:45 AM, Steven D'Aprano wrote: > > > It doesn't matter whether you call them "accent" like most people do, or > > "diacritics" as linguists do. > > I am a native born American and I have never before heard or seen > non-accent diacritic marks called 'accents'. Accents indicate stress. > Other diacritics indicate other pronunciation changes. It is > counterproductive to confuse the two groups. Spanish, for instance, has > vowel accents that change which syllable gets stressed. A tilda is not > an accent; rather, it softens the pronunciation of 'n' to 'ny', as in > 'canyon'. Had to be said. Nothing to add. Thorsten From torriem at gmail.com Sun Sep 18 15:54:57 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 18 Sep 2016 13:54:57 -0600 Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: On 09/18/2016 04:03 AM, Lawrence D?Oliveiro wrote: > Like I said, trying to automate a GUI is a waste of time. GUIs are > designed for humans, not computers, to use. Well then we have a huge problem. Especially for users who are visually-impaired. Fortunately almost all GUIs (Windows, Linux, and Mac) are automate-able these days and can be interfaced with with screen readers and scriptable event generators. This is very very common, even though you seem to think it's not. One of the most mature tools for driving GUIs (which we used all the time when doing scripted installs of Windows) was AutoIt. Works pretty well actually. > That?s why we have command lines and scripting (which are all just > programming at different layers, of course). That?s how you automate > things, building higher-level abstract machines on top of lower-level > ones. GUIs are the end of the abstraction chain: you cannot build > anything more on top of them. What a nice simplistic view of the world you have. From marko at pacujo.net Sun Sep 18 15:58:04 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 18 Sep 2016 22:58:04 +0300 Subject: How to convert =?utf-8?Q?'=C3=B6'?= to 'oe' or 'o' (or other similar things) in a string? References: <57de3813$0$1507$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twddkmk3.fsf@elektro.pacujo.net> Thorsten Kampe : > * Terry Reedy (Sun, 18 Sep 2016 03:51:40 -0400) >> On 9/18/2016 2:45 AM, Steven D'Aprano wrote: >> > It doesn't matter whether you call them "accent" like most people do, or >> > "diacritics" as linguists do. >> >> I am a native born American and I have never before heard or seen >> non-accent diacritic marks called 'accents'. Accents indicate stress. >> Other diacritics indicate other pronunciation changes. It is >> counterproductive to confuse the two groups. Spanish, for instance, has >> vowel accents that change which syllable gets stressed. A tilda is not >> an accent; rather, it softens the pronunciation of 'n' to 'ny', as in >> 'canyon'. > > Had to be said. Nothing to add. 5 a : a mark (as ?, `, ?) used in writing or printing to indicate a specific sound value, stress, or pitch, to distinguish words otherwise identically spelled, or to indicate that an ordinarily mute vowel should be pronounced b : an accented letter Marko From lawrencedo99 at gmail.com Sun Sep 18 16:20:04 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 18 Sep 2016 13:20:04 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: <65ce947b-21eb-4725-9c9a-120684b3f920@googlegroups.com> On Monday, September 19, 2016 at 2:12:14 AM UTC+12, Chris Angelico wrote: > > On Sun, Sep 18, 2016 at 8:03 PM, Lawrence D?Oliveiro wrote: > >> Like I said, trying to automate a GUI is a waste of time. GUIs are designed >> for humans, not computers, to use. > > Okay, then. Come up with a way to end-to-end-test a GUI application > without some form of GUI automation. There isn?t one. Have you noticed GUI apps are particularly buggy? From lawrencedo99 at gmail.com Sun Sep 18 16:22:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 18 Sep 2016 13:22:09 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> Message-ID: <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> On Monday, September 19, 2016 at 8:00:43 AM UTC+12, Michael Torrie wrote: > > On 09/18/2016 04:03 AM, Lawrence D?Oliveiro wrote: > >> Like I said, trying to automate a GUI is a waste of time. GUIs are >> designed for humans, not computers, to use. > > Well then we have a huge problem. Especially for users who are > visually-impaired. I know one blind computer user who is quite capable with the command line, and who has little fondness for GUI apps. You should see how quickly he works... From lawrencedo99 at gmail.com Sun Sep 18 18:45:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 18 Sep 2016 15:45:18 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> Message-ID: <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> On Sunday, September 18, 2016 at 11:02:57 PM UTC+12, Christian Gollwitzer wrote: > > Am 18.09.16 um 12:26 schrieb Lawrence D?Oliveiro: > >> Considering the power available in Free Software toolkits like >> ImageMagick, G?MIC and so on, not to mention libraries accessible >> from Python itself, let me suggest that such proprietary software >> simply isn?t worth bothering with any more. > > I was expecting that argument. Free software gives you a lot in this > area, but there are commercial signal processing programs with unmatched > quality. Examples: > > https://ni.neatvideo.com/ > or for audio > http://www.celemony.com/en/melodyne/what-is-melodyne If these tools are so wonderful, why don?t they offer command-line versions? I?ll tell you why: because it would likely mean they would sell fewer copies. Unless they put in a whole bunch of additional restrictions in the EULA, such as * You can?t run the program via SSH or a PTY, because this would allow multiple machines to make use of a single copy, which is not allowed. * Shell scripts are allowed, but any loop invoking the cheaper version of the tool is only allowed a maximum of 100 iterations. Also you must write the scripts using csh, not bash. * Pipes are limited to a maximum transfer of one gigabyte per day. A CLI gives the user power over the computer. While a GUI is a great way to give the computer, and proprietary software companies, power over the user. From ned at nedbatchelder.com Sun Sep 18 19:28:44 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 18 Sep 2016 16:28:44 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> Message-ID: On Sunday, September 18, 2016 at 6:45:32 PM UTC-4, Lawrence D?Oliveiro wrote: > A CLI gives the user power over the computer. While a GUI is a great way to give the computer, and proprietary software companies, power over the user. This is completely beside the point of the original question. --Ned. From torriem at gmail.com Sun Sep 18 19:32:08 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 18 Sep 2016 17:32:08 -0600 Subject: how to automate java application in window using python In-Reply-To: <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> Message-ID: On 09/18/2016 02:22 PM, Lawrence D?Oliveiro wrote: > I know one blind computer user who is quite capable with the command > line, and who has little fondness for GUI apps. You should see how > quickly he works... Good for him. This is very good that there are tools like that that he and many others can use, including ourselves. There are also good tools for those that want or need to use MS Windows or GUI applications. And, to get back on topic, there are good tools for automating testing and driving of GUI apps. One I've used is AutoIt. There is even a Python-based one that Matt Wheeler talked about. I suspect it will work more or less with the Java apps the original poster needs to work with. From lawrencedo99 at gmail.com Sun Sep 18 21:37:59 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 18 Sep 2016 18:37:59 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> Message-ID: <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> On Monday, September 19, 2016 at 11:32:25 AM UTC+12, Michael Torrie wrote: > One I've used is AutoIt. Like I said, this kind of thing can never work reliably... From steve+comp.lang.python at pearwood.info Mon Sep 19 01:08:37 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 19 Sep 2016 15:08:37 +1000 Subject: How to convert =?UTF-8?B?J8O2Jw==?= to 'oe' or 'o' (or other similar things) in a string? References: <57de3813$0$1507$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57df72d7$0$2824$c3e8da3$76491128@news.astraweb.com> On Sunday 18 September 2016 17:51, Terry Reedy wrote: > On 9/18/2016 2:45 AM, Steven D'Aprano wrote: > >> It doesn't matter whether you call them "accent" like most people do, or >> "diacritics" as linguists do. > > I am a native born American and I have never before heard or seen > non-accent diacritic marks called 'accents'. Accents indicate stress. > Other diacritics indicate other pronunciation changes. It is > counterproductive to confuse the two groups. Spanish, for instance, has > vowel accents that change which syllable gets stressed. Then you're better educated than most people I've met. Most folks I know call any of those "funny dots and squiggles" on letters "accents". > A tilda is not > an accent; rather, it softens the pronunciation of 'n' to 'ny', as in > 'canyon'. Hmmm. I'm not a Spanish speaker, but to me, 'canyon' is pronounced can-yen and the n is pronounced no differently from the n in 'can', 'man', 'men', 'pan', 'panel', 'moon', 'nut', etc. (P.S. it's tilde. Tilda is short for Matilda, as in Tilda Swinton the actor.) But what do I know? My missus says I have a tin-ear, and I'm no linguist. But I can read Wikipedia: https://en.wikipedia.org/wiki/Diacritic and it makes it clear that diacritics including accents can have many different effects on pronunciation, including none at all. E.g. French l? ("there") versus la ("the") are both pronounced /la/. In English the diaereses found in na?ve, No?l, Zo?, co?perate etc. is used to show that the marked vowel is pronounced separately from the preceding vowel (e.g. co- operate rather than coop-erate), and accents used to indicate that a vowel which normally isn't pronounced at all should be, as in sak? or Moist von Lipwig's wing?d hat[1]. Make of that what you will. [1] A running gag from "Going Postal", one of the Discworld series. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From auriocus at gmx.de Mon Sep 19 02:47:04 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 19 Sep 2016 08:47:04 +0200 Subject: how to automate java application in window using python In-Reply-To: <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> Message-ID: Am 19.09.16 um 00:45 schrieb Lawrence D?Oliveiro: > On Sunday, September 18, 2016 at 11:02:57 PM UTC+12, Christian Gollwitzer wrote: >> >> Am 18.09.16 um 12:26 schrieb Lawrence D?Oliveiro: >> >>> Considering the power available in Free Software toolkits like >>> ImageMagick, G?MIC and so on, not to mention libraries accessible >>> from Python itself, let me suggest that such proprietary software >>> simply isn?t worth bothering with any more. >> >> I was expecting that argument. Free software gives you a lot in this >> area, but there are commercial signal processing programs with unmatched >> quality. Examples: >> >> https://ni.neatvideo.com/ >> or for audio >> http://www.celemony.com/en/melodyne/what-is-melodyne > > If these tools are so wonderful, They are. > why don?t they offer command-line versions? > > I?ll tell you why: because it would likely mean they would sell fewer copies. I agree with you. > > A CLI gives the user power over the computer. While a GUI is a great > way to give the computer, and proprietary software companies, power > over the user. I mostly agree with you. Doesn't change the fact, that IF you are in the situation that you have a program without a reasonable command line interfacem and IF you need to process some data in an automated fashion which can't be done from the GUI, then there is room for a "GUI automation" tool or whatever you call it. Don't get it wrong, we all like free software and sane APIs and a Python binding to the mowing robot. Still, sometimes you just need to get the job done and it doesn't matter how. Christian From ldlchina at gmail.com Mon Sep 19 02:47:10 2016 From: ldlchina at gmail.com (dl l) Date: Mon, 19 Sep 2016 14:47:10 +0800 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module Message-ID: Hi, I have a app loading python35.dll. Use python API PyImport_AddModule to run a py file. And use PyDict_DelItemString to delete the module. There is a global vailable in the py file. The global variable is not destroyed when calling PyDict_DelItemString to delete the module. That cause the memory leak. But it is ok with python33.dll, the global variable can be destroyed when calling PyDict_DelItemString to delete the module. How to resolve the problem? Is there a workaround? I need to use python35.dll and wish the global variable in a module can be released automatically when call PyDict_DelItemString to delete the module. Here is the python test code: class Simple: def __init__( self ): print('Simple__init__') def __del__( self ): print('Simple__del__') simple = Simple() Thanks, Jack From dieter at handshake.de Mon Sep 19 02:53:59 2016 From: dieter at handshake.de (dieter) Date: Mon, 19 Sep 2016 08:53:59 +0200 Subject: Functions Of Functions Returning Functions References: <8bfa17c3-1c8b-4960-b6a3-fbaf279200af@googlegroups.com> Message-ID: <87k2e8l6rc.fsf@handshake.de> Lawrence D?Oliveiro writes: > The less code you have to write, the better. Less code means less > maintenance, and fewer opportunities for bugs. While I agree with you in general, sometimes less code can be harder to maintain (when it is more difficult to understand). Some time ago, we had a (quite heated) discussion here about a one line signature transform involving a triply nested lambda construction. It was not difficult for me to understand what the construction did; however, the original poster found it very difficult to grasp. Often, functions returning functions are more difficult to understand than "first order" functions (those returning simple values only) -- at least for people not familiar with higher abstraction levels. From arsh840 at gmail.com Mon Sep 19 06:55:52 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Mon, 19 Sep 2016 03:55:52 -0700 (PDT) Subject: Cython taking more time than regular Python Message-ID: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Hope this is good place to ask question about Cython as well. Following code of mine is taking 2.5 times more time than Native Python code: %%cython import numpy as np a = np.array([]) def large_sum2(int num_range): np.append(a,[i for i in xrange(num_range)]) return a.sum %timeit large_sum2(100000) 10 loops, best of 3: 19 ms per loop on the other side python takes much less time: def large_sum(num_range): return sum([i for i in xrange(num_range)]) %timeit large_sum(100000) 100 loops, best of 3: 7 ms per loop From __peter__ at web.de Mon Sep 19 08:55:28 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Sep 2016 14:55:28 +0200 Subject: Cython taking more time than regular Python References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: Arshpreet Singh wrote: > Hope this is good place to ask question about Cython as well. > Following code of mine is taking 2.5 times more time than Native Python > code: > > %%cython > import numpy as np > a = np.array([]) > def large_sum2(int num_range): > np.append(a,[i for i in xrange(num_range)]) > return a.sum > > %timeit large_sum2(100000) > 10 loops, best of 3: 19 ms per loop > > on the other side python takes much less time: > > def large_sum(num_range): > return sum([i for i in xrange(num_range)]) > > %timeit large_sum(100000) > 100 loops, best of 3: 7 ms per loop But the two versions aren't the same! If you compare similar code: In [2]: %%cython def sigma(n): return sum(i for i in range(n)) ...: In [3]: def tau(n): return sum(i for i in range(n)) In [4]: %timeit sigma(100000) 100 loops, best of 3: 8.34 ms per loop In [5]: %timeit tau(100000) 100 loops, best of 3: 12.7 ms per loop And if you decide to go lowlevel (there may be smarter ways, but I'm a complete amateur with Cython): In [7]: %%cython def omega(int n): cdef long i cdef long result = 0 for i in range(n): result += i return result ...: In [8]: %timeit omega(100000) 10000 loops, best of 3: 91.6 ?s per loop In [9]: assert omega(100000) == tau(100000) == sigma(100000) From martinjp376 at gmail.com Mon Sep 19 11:40:56 2016 From: martinjp376 at gmail.com (kerbingamer376) Date: Mon, 19 Sep 2016 08:40:56 -0700 (PDT) Subject: Using copyreg to pickle unpicklable oblects Message-ID: <68f91c0b-6cb9-49fe-a5c7-fe43b597eb36@googlegroups.com> Hi, I have an object (pygame.mixer.Sound) and, to convert it to a picklable format, I can run: sound_object.get_raw() and to turn that back into an object, I can run: sound_object = pygame.mixer.Sound(raw_data) Is it possible to use copyreg or something similar so it's done automatically when I pickle pygame.mixer.Sound() objects? From doctor at doctor.nl2k.ab.ca Mon Sep 19 11:46:53 2016 From: doctor at doctor.nl2k.ab.ca (The Doctor) Date: Mon, 19 Sep 2016 15:46:53 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.0-RELEASE? References: <20160916b@crcomp.net> Message-ID: In article <20160916b at crcomp.net>, Don Kuenz wrote: > >The installed python packages are shown below. Searches lead me to >believe that a PTH option make play a role. > >------------------------------------------------------------------------ >$ uname -v >FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 >root at snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC > >$ pkg info | grep python >py27-dnspython-1.14.0 DNS toolkit for Python >py27-notify-0.1.1_11 python bindings for libnotify >py27-telepathy-python-0.15.19_1 Python bindings for the Telepathy framework >python-2.7_2,2 The "meta-port" for the default version >of Python interpreter >python2-2_3 The "meta-port" for version 2 of the >Python interpreter >python27-2.7.12 Interpreted object-oriented programming language >python3-3_3 The "meta-port" for version 3 of the >Python interpreter >python34-3.4.5 Interpreted object-oriented programming language > >$ cd /usr/ports/lang/python >$ make config >===> No options to configure > >----------------------------------------------------------------------- > >Thank you, > >-- >Don Kuenz KB7RPU > >There be triple ways to take, of the eagle or the snake, >Or the way of a man with a maid; >But the seetest way to me is a ship's upon the sea >In the heel of the Northeast Trade. > - Kipling Why not upgrade to 10.2 ? -- Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca God,Queen and country!Never Satan President Republic!Beware AntiChrist rising! http://www.fullyfollow.me/rootnl2k Look at Psalms 14 and 53 on Atheism Time for the USA to hold a referendum on its republic and vote to dissolve!! From rosuav at gmail.com Mon Sep 19 12:00:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Sep 2016 02:00:02 +1000 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module In-Reply-To: References: Message-ID: On Mon, Sep 19, 2016 at 4:47 PM, dl l wrote: > I have a app loading python35.dll. Use python API PyImport_AddModule > to run a py file. And use PyDict_DelItemString to delete the module. > There is a global vailable in the py file. The global variable is not > destroyed when calling PyDict_DelItemString to delete the module. That > cause the memory leak. Does the module still exist in sys.modules? If so, it's not leaked - it's still in use. ChrisA From __peter__ at web.de Mon Sep 19 12:47:18 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Sep 2016 18:47:18 +0200 Subject: Using copyreg to pickle unpicklable oblects References: <68f91c0b-6cb9-49fe-a5c7-fe43b597eb36@googlegroups.com> Message-ID: kerbingamer376 wrote: > Hi, [No need to start a new thread for this] > I have an object (pygame.mixer.Sound) and, to convert it to a picklable > format, I can run: > > sound_object.get_raw() > > and to turn that back into an object, I can run: > > sound_object = pygame.mixer.Sound(raw_data) > > Is it possible to use copyreg or something similar so it's done > automatically when I pickle pygame.mixer.Sound() objects? Have a look at the example from the documentation: >>> import copyreg, copy, pickle >>> class C(object): ... def __init__(self, a): ... self.a = a ... >>> def pickle_c(c): ... print("pickling a C instance...") ... return C, (c.a,) ... >>> copyreg.pickle(C, pickle_c) Translating that gives (untested) import copyreg # copy_reg in Python 2 import pygame.mixer def pickle_sound(sound): return pygame.mixer.Sound, (sound.get_raw(),) copyreg.pickle(pygame.mixer.Sound, pickle_sound) Does that work? From martinjp376 at gmail.com Mon Sep 19 14:10:08 2016 From: martinjp376 at gmail.com (kerbingamer376) Date: Mon, 19 Sep 2016 11:10:08 -0700 (PDT) Subject: Using copyreg to pickle unpicklable oblects In-Reply-To: References: <68f91c0b-6cb9-49fe-a5c7-fe43b597eb36@googlegroups.com> Message-ID: <90115d75-07a9-47ea-aa6e-7ce61c01e4ac@googlegroups.com> On Monday, September 19, 2016 at 5:48:35 PM UTC+1, Peter Otten wrote: > kerbingamer376 wrote: > > > Hi, > > [No need to start a new thread for this] > > > I have an object (pygame.mixer.Sound) and, to convert it to a picklable > > format, I can run: > > > > sound_object.get_raw() > > > > and to turn that back into an object, I can run: > > > > sound_object = pygame.mixer.Sound(raw_data) > > > > Is it possible to use copyreg or something similar so it's done > > automatically when I pickle pygame.mixer.Sound() objects? > > Have a look at the example from the documentation: > > >>> import copyreg, copy, pickle > >>> class C(object): > ... def __init__(self, a): > ... self.a = a > ... > >>> def pickle_c(c): > ... print("pickling a C instance...") > ... return C, (c.a,) > ... > >>> copyreg.pickle(C, pickle_c) > > > Translating that gives (untested) > > import copyreg # copy_reg in Python 2 > import pygame.mixer > > def pickle_sound(sound): > return pygame.mixer.Sound, (sound.get_raw(),) > > copyreg.pickle(pygame.mixer.Sound, pickle_sound) > > Does that work? I get: _pickle.PicklingError: Can't pickle : attribute lookup Sound on builtins failed From g at crcomp.net Mon Sep 19 14:58:28 2016 From: g at crcomp.net (Don Kuenz) Date: Mon, 19 Sep 2016 18:58:28 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.3-RELEASE? Message-ID: <20160919a@crcomp.net> In article you wrote: > In article <20160916b at crcomp.net>, Don Kuenz wrote: >> >>The installed python packages are shown below. Searches lead me to >>believe that a PTH option make play a role. >> >>------------------------------------------------------------------------ >>$ uname -v >>FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 >>root at snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC >> >>$ pkg info | grep python >>py27-dnspython-1.14.0 DNS toolkit for Python >>py27-notify-0.1.1_11 python bindings for libnotify >>py27-telepathy-python-0.15.19_1 Python bindings for the Telepathy framework >>python-2.7_2,2 The "meta-port" for the default version >>of Python interpreter >>python2-2_3 The "meta-port" for version 2 of the >>Python interpreter >>python27-2.7.12 Interpreted object-oriented programming language >>python3-3_3 The "meta-port" for version 3 of the >>Python interpreter >>python34-3.4.5 Interpreted object-oriented programming language >> >>$ cd /usr/ports/lang/python >>$ make config >>===> No options to configure >> >>----------------------------------------------------------------------- >> > > Why not upgrade to 10.2 ? A newer host is loaded with 10.3. It uses identical python packages. It seems that FreeBSD python has been neglected for years. ------------------------------------------------------------------------ $ uname -v FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 02:10:02 UTC 2016 root at releng1.nyi.freebsd.or g:/usr/obj/usr/src/sys/GENERIC $ pkg info | grep python py27-dnspython-1.12.0 DNS toolkit for Python py27-notify-0.1.1_11 python bindings for libnotify py27-telepathy-python-0.15.19_1 Python bindings for the Telepathy framework python-2.7_2,2 The "meta-port" for the default version of Python interpreter python2-2_3 The "meta-port" for version 2 of the Python interpreter python27-2.7.12 Interpreted object-oriented programming language python3-3_3 The "meta-port" for version 3 of the Python interpreter python34-3.4.5 Interpreted object-oriented programming language ------------------------------------------------------------------------ Thank you, -- Don Kuenz KB7RPU It's easier to mend neglect than to quicken love. - Saint Jerome From __peter__ at web.de Mon Sep 19 15:19:01 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Sep 2016 21:19:01 +0200 Subject: Using copyreg to pickle unpicklable oblects References: <68f91c0b-6cb9-49fe-a5c7-fe43b597eb36@googlegroups.com> <90115d75-07a9-47ea-aa6e-7ce61c01e4ac@googlegroups.com> Message-ID: kerbingamer376 wrote: > On Monday, September 19, 2016 at 5:48:35 PM UTC+1, Peter Otten wrote: >> kerbingamer376 wrote: >> >> > Hi, >> >> [No need to start a new thread for this] >> >> > I have an object (pygame.mixer.Sound) and, to convert it to a picklable >> > format, I can run: >> > >> > sound_object.get_raw() >> > >> > and to turn that back into an object, I can run: >> > >> > sound_object = pygame.mixer.Sound(raw_data) >> > >> > Is it possible to use copyreg or something similar so it's done >> > automatically when I pickle pygame.mixer.Sound() objects? >> >> Have a look at the example from the documentation: >> >> >>> import copyreg, copy, pickle >> >>> class C(object): >> ... def __init__(self, a): >> ... self.a = a >> ... >> >>> def pickle_c(c): >> ... print("pickling a C instance...") >> ... return C, (c.a,) >> ... >> >>> copyreg.pickle(C, pickle_c) >> >> >> Translating that gives (untested) >> >> import copyreg # copy_reg in Python 2 >> import pygame.mixer >> >> def pickle_sound(sound): >> return pygame.mixer.Sound, (sound.get_raw(),) >> >> copyreg.pickle(pygame.mixer.Sound, pickle_sound) >> >> Does that work? > > I get: > > _pickle.PicklingError: Can't pickle : attribute lookup > Sound on builtins failed Looks like Sound doesn't set the __module__ attribute correctly. Try injecting it into the built-in namespace: import builtins builtins.Sound = pygame.mixer.Sound From martin.schoon at gmail.com Mon Sep 19 16:21:12 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 19 Sep 2016 20:21:12 GMT Subject: Another =?UTF-8?Q?=C3=A5=2C?= =?UTF-8?Q?_=C3=A4=2C?= =?UTF-8?Q?_=C3=B6?= question Message-ID: I am studying some of these tutorials: https://pythonprogramming.net/matplotlib-intro-tutorial/ I am recreating the code and I use my native Swedish for comments, labels and titles. Until now I have been doing so using Geany and executing using F5. This works fine. But -- now I tested using emacs instead using C-c C-c to execute. Noting happens so I try to run the program from command line and find that now Python can't stand my ?, ? and ?. I am puzzled: With Geany there is no problem but outside Geany I am punished by Python for using Swedish. Any ideas? /Martin From lawrencedo99 at gmail.com Mon Sep 19 16:24:19 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 19 Sep 2016 13:24:19 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> Message-ID: <338bd02a-5a0c-4ec5-b5d8-5702bbc9e4e1@googlegroups.com> On Monday, September 19, 2016 at 11:29:24 AM UTC+12, Ned Batchelder wrote: > > On Sunday, September 18, 2016 at 6:45:32 PM UTC-4, Lawrence D?Oliveiro wrote: >> >> A CLI gives the user power over the computer. While a GUI is a great way to >> give the computer, and proprietary software companies, power over the user. > > This is completely beside the point of the original question. Which is meaningless, as I explained. From lawrencedo99 at gmail.com Mon Sep 19 16:26:51 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 19 Sep 2016 13:26:51 -0700 (PDT) Subject: Functions Of Functions Returning Functions In-Reply-To: References: <8bfa17c3-1c8b-4960-b6a3-fbaf279200af@googlegroups.com> <87k2e8l6rc.fsf@handshake.de> Message-ID: <71262036-9cb3-4d71-85f2-31cab091ed59@googlegroups.com> On Monday, September 19, 2016 at 6:54:31 PM UTC+12, dieter wrote: > Some time ago, we had a (quite heated) discussion here ... I have noticed that people get very defensive about things they don?t understand. > Often, functions returning functions are more difficult to understand > than "first order" functions (those returning simple values only) -- > at least for people not familiar with higher abstraction levels. Maybe if the alternative meant writing 200 extra lines of code (as in this case), they might feel differently... From auriocus at gmx.de Mon Sep 19 16:28:49 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 19 Sep 2016 22:28:49 +0200 Subject: =?UTF-8?B?UmU6IEFub3RoZXIgw6UsIMOkLCDDtiBxdWVzdGlvbg==?= In-Reply-To: References: Message-ID: Am 19.09.16 um 22:21 schrieb Martin Sch??n: > I am studying some of these tutorials: > https://pythonprogramming.net/matplotlib-intro-tutorial/ > > I am recreating the code and I use my native Swedish for comments, > labels and titles. Until now I have been doing so using Geany > and executing using F5. This works fine. > > But -- now I tested using emacs instead using C-c C-c to execute. > Noting happens so I try to run the program from command line and > find that now Python can't stand my ?, ? and ?. > > I am puzzled: With Geany there is no problem but outside Geany > I am punished by Python for using Swedish. you are not "punished for Swedish", you need to tell Python the encoding of the file it runs. See here: https://www.python.org/dev/peps/pep-0263/ Assuming that you use UTF-8 (you should check with an emacs expert, I am not an emacs user), try putting the header #!/usr/bin/python # -*- coding: utf-8 -*- on top of your files. Christian From p.f.moore at gmail.com Mon Sep 19 17:13:08 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 19 Sep 2016 22:13:08 +0100 Subject: Looking for tips and gotchas for working with Python 3.5 zipapp feature Message-ID: On 16 September 2016 19:48 at 21:08, Malcolm Greene wrote: > Looking for tips or edge case gotchas associated with using Python 3.5's > new zipapp feature. It's worth pointing out that support for executing zipped applications has been part of Python since Python 2.6 or so. The pyz files created by the zipapp module can be used with any version of Python back to then (assuming the code doesn't use newer features of Python, of course). There aren't many "gotchas" that I know of - the main one being the one you note below about locating data files - some modules (not many these days) assume they are living in a normal directory and locate data files by doing path calculations based on __file__. This doesn't work in a zipfile. The other main limitation (not so much a gotcha as a consequence of how the OS works) is that you can't load C extensions (pyd or so files) from a zipfile. If you need to do that, you'll have to bundle the C extensions to work around that limitation, but that's pretty advanced usage. > For those of you wondering what this feature is, see > the end of this post for a brief background [1]. > > Two questions in particular: > > 1. Are there any issues with deploying scripts that sit in sub- > folders beneath the directory being zipped, eg. does zipapp only > support a flat folder of scripts or does it recursively zip and > path sub-folders? It will work fine with a folder structure. However, the way it works is that it runs a __main__.py script which is at the root of the zipfile, with the zipfile inserted on sys.path. So, if you have "import foo" in your __main__.py file, foo.py must be at the root. If you have something like the following layout in your zipfile, you can do "import foo.bar.baz" from your __main__.py. Basically the usual rules for imports apply. __main__.py foo __init__.py bar __init__.py baz.py > 2. Can additional non-Python files like config files be added to a > zipapp without breaking them and if so, how would your script > reference these embedded files (by opening up the zipapp as a zip > archive and navigating from there?). They can be, but as you note, you need to reference those data files specially, you can't find them via the __file__ attribute of a module, and path manipulation. The stdlib API for finding data files stored in a package is pkgutil.get_data (https://docs.python.org/3/library/pkgutil.html#pkgutil.get_data). Basically, if you have a "data file" called myapp.ini" in the package directory of the "foo" package, you can access it as data = pkgutil.get_data('foo', 'myapp.ini') The content of the file is returned as a bytes object. File layout: __main__.py foo __init__.py myapp.ini bar __init__.py baz.py __main__.py import pkgutil import foo.bar.baz data = pkgutil.get_data('foo', 'myapp.ini') print(data) The data access API is unfortunately very minimal, for example there's no way to find what data files are present, you need to know the name in advance. There have been proposals to add a richer API, but none are present yet. If you need more than this, you can as you say open your zipapp as a zipfile (but by doing so, you commit to only working if the application is zipped, which may or may not matter to you). Something like this: __main__.py import zipfile import os my_archive = os.path.dirname(__file__) zf = zipfile.ZipFile(my_archive) ... > Thank you, > Malcolm Hope this helps :-) > [1] The zipapp feature of Python 3.5 is pretty cool: It allows you to > package your Python scripts in a single executable zip file. This > isn't a replacement for tools like PyInstaller or Py2Exe, eg. it > doesn't bundle the Python interpreter in the zip file, but it's a > clean way to distribute multi-file scripts in environments where you > have control over users' Python setups. If you do want a completely standalone application, what you can do is to write a small C program that embeds the Python interpreter, and just starts your zipapp. Then ship that along with the "embedded" Python distribution (available from the python.org pages) and you have a standalone application. I'm currently working on such a wrapper - the prototype is at https://github.com/pfmoore/pylaunch. If I can get it into a suitable state, I may look at adding the wrapper to the zipapp module for Python 3.7. Paul From lawrencedo99 at gmail.com Mon Sep 19 17:58:05 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 19 Sep 2016 14:58:05 -0700 (PDT) Subject: =?UTF-8?B?UmU6IEFub3RoZXIgw6UsIMOkLCDDtiBxdWVzdGlvbg==?= In-Reply-To: References: Message-ID: On Tuesday, September 20, 2016 at 8:21:25 AM UTC+12, Martin Sch??n wrote: > But -- now I tested using emacs instead using C-c C-c to execute. > Noting happens so I try to run the program from command line and > find that now Python can't stand my ?, ? and ?. What version of Python? Python 3 accepts Unicode UTF-8 as a matter of course. From doctor at doctor.nl2k.ab.ca Mon Sep 19 18:27:49 2016 From: doctor at doctor.nl2k.ab.ca (The Doctor) Date: Mon, 19 Sep 2016 22:27:49 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.3-RELEASE? References: <20160919a@crcomp.net> Message-ID: In article <20160919a at crcomp.net>, Don Kuenz wrote: > >In article you wrote: >> In article <20160916b at crcomp.net>, Don Kuenz wrote: >>> >>>The installed python packages are shown below. Searches lead me to >>>believe that a PTH option make play a role. >>> >>>------------------------------------------------------------------------ >>>$ uname -v >>>FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 >>>root at snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC >>> >>>$ pkg info | grep python >>>py27-dnspython-1.14.0 DNS toolkit for Python >>>py27-notify-0.1.1_11 python bindings for libnotify >>>py27-telepathy-python-0.15.19_1 Python bindings for the Telepathy framework >>>python-2.7_2,2 The "meta-port" for the default version >>>of Python interpreter >>>python2-2_3 The "meta-port" for version 2 of the >>>Python interpreter >>>python27-2.7.12 Interpreted object-oriented programming >language >>>python3-3_3 The "meta-port" for version 3 of the >>>Python interpreter >>>python34-3.4.5 Interpreted object-oriented programming >language >>> >>>$ cd /usr/ports/lang/python >>>$ make config >>>===> No options to configure >>> >>>----------------------------------------------------------------------- >>> >> >> Why not upgrade to 10.2 ? > >A newer host is loaded with 10.3. It uses identical python packages. >It seems that FreeBSD python has been neglected for years. > >------------------------------------------------------------------------ > >$ uname -v >FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 02:10:02 UTC 2016 >root at releng1.nyi.freebsd.or >g:/usr/obj/usr/src/sys/GENERIC >$ pkg info | grep python >py27-dnspython-1.12.0 DNS toolkit for Python >py27-notify-0.1.1_11 python bindings for libnotify >py27-telepathy-python-0.15.19_1 Python bindings for the Telepathy framework >python-2.7_2,2 The "meta-port" for the default version >of Python interpreter >python2-2_3 The "meta-port" for version 2 of the >Python interpreter >python27-2.7.12 Interpreted object-oriented programming language >python3-3_3 The "meta-port" for version 3 of the >Python interpreter >python34-3.4.5 Interpreted object-oriented programming language > >------------------------------------------------------------------------ > >Thank you, > >-- >Don Kuenz KB7RPU > >It's easier to mend neglect than to quicken love. - Saint Jerome My servers are running uname -v FreeBSD 10.3-RELEASE-p7 #0: Thu Aug 11 18:38:15 UTC 2016 root at amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC Run freebsd-update fetch ; freebsd-update install -- Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca God,Queen and country!Never Satan President Republic!Beware AntiChrist rising! http://www.fullyfollow.me/rootnl2k Look at Psalms 14 and 53 on Atheism Time for the USA to hold a referendum on its republic and vote to dissolve!! From ned at nedbatchelder.com Mon Sep 19 21:11:04 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 19 Sep 2016 18:11:04 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <338bd02a-5a0c-4ec5-b5d8-5702bbc9e4e1@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> <338bd02a-5a0c-4ec5-b5d8-5702bbc9e4e1@googlegroups.com> Message-ID: <4fdd2732-dd21-435a-9767-e371e9c3dcd6@googlegroups.com> On Monday, September 19, 2016 at 4:24:31 PM UTC-4, Lawrence D?Oliveiro wrote: > On Monday, September 19, 2016 at 11:29:24 AM UTC+12, Ned Batchelder wrote: > > > > On Sunday, September 18, 2016 at 6:45:32 PM UTC-4, Lawrence D?Oliveiro wrote: > >> > >> A CLI gives the user power over the computer. While a GUI is a great way to > >> give the computer, and proprietary software companies, power over the user. > > > > This is completely beside the point of the original question. > > Which is meaningless, as I explained. We get it, you don't like GUIs. The question is clearly not meaningless, since others are helping with the question. --Ned. --Ned. From jobmattcon at gmail.com Mon Sep 19 21:47:45 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Mon, 19 Sep 2016 18:47:45 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: Message-ID: <4f73483a-6618-464a-a2a2-038b1965765a@googlegroups.com> Hi Matt Wheeler, can it contorl Maplesoft's maple which is a java executable file? On Sunday, September 18, 2016 at 5:02:15 PM UTC+8, Matt Wheeler wrote: > On Thu, 15 Sep 2016, 08:12 meInvent bbird, wrote: > > > how to automate java application in window using python > > > > 1. scroll up or down of scroll bar > > 2. click button > > 3. type text in textbox > > > > I would recommend having a look at pywinauto > https://github.com/pywinauto/pywinauto > > It presents a very nice pythonic interface to Windows and the controls > within them, allowing statements such as (copied from the Readme): > > app.UntitledNotepad.MenuSelect("Help->About Notepad") > app.AboutNotepad.OK.Click() > app.UntitledNotepad.Edit.TypeKeys ("pywinauto Works!", with_spaces = True) > > (I found it already quite stable when I first used it a couple of years > ago, and looking at the Readme now it's clearly still an active project, > the optional image capture feature using pillow is new) > > > From ldlchina at gmail.com Mon Sep 19 22:58:54 2016 From: ldlchina at gmail.com (dl l) Date: Tue, 20 Sep 2016 10:58:54 +0800 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module In-Reply-To: References: Message-ID: Thanks for the replay. I run this script as __main__ module, this module is removed from sys.modules, and the ref count becomes 0. 2016-09-20 0:00 GMT+08:00 Chris Angelico : > On Mon, Sep 19, 2016 at 4:47 PM, dl l wrote: > > I have a app loading python35.dll. Use python API PyImport_AddModule > > to run a py file. And use PyDict_DelItemString to delete the module. > > There is a global vailable in the py file. The global variable is not > > destroyed when calling PyDict_DelItemString to delete the module. That > > cause the memory leak. > > Does the module still exist in sys.modules? If so, it's not leaked - > it's still in use. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From python at bdurham.com Tue Sep 20 00:45:36 2016 From: python at bdurham.com (Malcolm Greene) Date: Tue, 20 Sep 2016 00:45:36 -0400 Subject: Looking for tips and gotchas for working with Python 3.5 zipapp feature In-Reply-To: References: Message-ID: <1474346736.598636.730985801.507A5EED@webmail.messagingengine.com> Hi Paul, WOW!:) I really appreciate the detailed response. You answered all my questions. I'm looking forward to testing out your pylaunch wrapper. Thank you very much! Malcolm From stefan_ml at behnel.de Tue Sep 20 01:27:34 2016 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Sep 2016 07:27:34 +0200 Subject: Cython taking more time than regular Python In-Reply-To: References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: Peter Otten schrieb am 19.09.2016 um 14:55: > In [7]: %%cython > def omega(int n): > cdef long i > cdef long result = 0 > for i in range(n): result += i > return result > ...: > > In [8]: %timeit omega(100000) > 10000 loops, best of 3: 91.6 ?s per loop Note that this is the worst benchmark ever. Any non-dump C compiler will happily apply Young Gau? and calculate the result in constant time. Stefan From steve+comp.lang.python at pearwood.info Tue Sep 20 01:49:10 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 20 Sep 2016 15:49:10 +1000 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module References: Message-ID: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> On Monday 19 September 2016 16:47, dl l wrote: > Hi, > > I have a app loading python35.dll. Use python API PyImport_AddModule > to run a py file. And use PyDict_DelItemString to delete the module. > There is a global vailable in the py file. The global variable is not > destroyed when calling PyDict_DelItemString to delete the module. That > cause the memory leak. See: https://bugs.python.org/issue28202 > But it is ok with python33.dll, the global variable can be destroyed > when calling PyDict_DelItemString to delete the module. You are calling PyDict_DelItemString on sys.modules, but that won't clear the reference to the module if there are any other references to it. > How to resolve the problem? Is there a workaround? I need to use > python35.dll and wish the global variable in a module can be released > automatically when call PyDict_DelItemString to delete the module. The global object will not be released so long as any other object refers to it. If the global object is still alive, it will keep the module alive. Are you sure that the object has no other references to it? Have you put it in a list or dict or some other object? > Here is the python test code: > > class Simple: > def __init__( self ): > print('Simple__init__') > def __del__( self ): > print('Simple__del__') > > simple = Simple() You cannot rely on the __del__ method running at any specific time. It might not run until your application exists. That test code is not sufficient. How do you call the test code? If you do this from main: import mymodule # module above del sys.modules['mymodule'] that will delete the sys.modules cache entry, but the module object is still alive. If you are absolutely sure there are no other references to the global variable and the module, then it sounds like a leak. Can you confirm that the gc is enabled? For a work-around, I can only suggest manually killing the global. What happens if you do this: del sys.modules['mymodule'] mymodule.simple = None del mymodule or equivalent? -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From arsh840 at gmail.com Tue Sep 20 01:52:47 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Mon, 19 Sep 2016 22:52:47 -0700 (PDT) Subject: Cython taking more time than regular Python In-Reply-To: References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: On Tuesday, 20 September 2016 11:00:40 UTC+5:30, Stefan Behnel wrote: > > In [8]: %timeit omega(100000) > > 10000 loops, best of 3: 91.6 ?s per loop > > Note that this is the worst benchmark ever. Any non-dump C compiler will > happily apply Young Gau? and calculate the result in constant time. Hey Stefan what else you suggest? From ldlchina at gmail.com Tue Sep 20 02:19:40 2016 From: ldlchina at gmail.com (dl l) Date: Tue, 20 Sep 2016 14:19:40 +0800 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module In-Reply-To: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> References: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> Message-ID: Hi Steven, Thanks for reply. I logged bug https://bugs.python.org/issue28202. I added more info in this bug :). Yes, it's a workaround to set the global variables to None. But My app just provide a framework for my customers to run python scripts. That's means the workaround requires my customers to update their python scripts. That may make them unhappy :(. Is there a workaround in my code C++ side to call Python C APIs to resolve the memory leak issue? 2016-09-20 13:49 GMT+08:00 Steven D'Aprano < steve+comp.lang.python at pearwood.info>: > On Monday 19 September 2016 16:47, dl l wrote: > > > Hi, > > > > I have a app loading python35.dll. Use python API PyImport_AddModule > > to run a py file. And use PyDict_DelItemString to delete the module. > > There is a global vailable in the py file. The global variable is not > > destroyed when calling PyDict_DelItemString to delete the module. That > > cause the memory leak. > > See: > > https://bugs.python.org/issue28202 > > > But it is ok with python33.dll, the global variable can be destroyed > > when calling PyDict_DelItemString to delete the module. > > You are calling PyDict_DelItemString on sys.modules, but that won't clear > the > reference to the module if there are any other references to it. > > > > How to resolve the problem? Is there a workaround? I need to use > > python35.dll and wish the global variable in a module can be released > > automatically when call PyDict_DelItemString to delete the module. > > The global object will not be released so long as any other object refers > to > it. If the global object is still alive, it will keep the module alive. > > Are you sure that the object has no other references to it? Have you put > it in > a list or dict or some other object? > > > > Here is the python test code: > > > > class Simple: > > def __init__( self ): > > print('Simple__init__') > > def __del__( self ): > > print('Simple__del__') > > > > simple = Simple() > > > You cannot rely on the __del__ method running at any specific time. It > might > not run until your application exists. > > > That test code is not sufficient. How do you call the test code? If you do > this > from main: > > > import mymodule # module above > del sys.modules['mymodule'] > > > > that will delete the sys.modules cache entry, but the module object is > still > alive. If you are absolutely sure there are no other references to the > global > variable and the module, then it sounds like a leak. > > Can you confirm that the gc is enabled? > > > For a work-around, I can only suggest manually killing the global. What > happens > if you do this: > > del sys.modules['mymodule'] > mymodule.simple = None > del mymodule > > > or equivalent? > > > > > > -- > Steven > git gets easier once you get the basic idea that branches are homeomorphic > endofunctors mapping submanifolds of a Hilbert space. > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Tue Sep 20 03:16:45 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 20 Sep 2016 17:16:45 +1000 Subject: Another =?UTF-8?B?w6UsIMOkLCDDtiBxdWVzdGlvbg==?= References: Message-ID: <57e0e25f$0$2925$c3e8da3$76491128@news.astraweb.com> On Tuesday 20 September 2016 06:21, Martin Sch??n wrote: > I am puzzled: With Geany there is no problem but outside Geany > I am punished by Python for using Swedish. > > Any ideas? Yes, you are being punished for what Sweden did to Julian Assange. No, only kidding. We can't really help you if you don't tell us exactly what error you get. Is this an error in emacs? A Python error? What exception do you get? But if I were to take a guess, I think you should put an encoding cookie in the first or second line of your text file. Make sure your editor is configured to use UTF-8 as the encoding, and put this in line 1 or line 2 of the file: # -*- coding: utf-8 -*- That will tell Python to read your file as UTF-8 instead of ASCII. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From steve+comp.lang.python at pearwood.info Tue Sep 20 03:26:50 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 20 Sep 2016 17:26:50 +1000 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module References: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> Message-ID: <57e0e4bb$0$1535$c3e8da3$5496439d@news.astraweb.com> On Tuesday 20 September 2016 16:19, dl l wrote: > Hi Steven, > > Thanks for reply. > > I logged bug https://bugs.python.org/issue28202. I added more info in this > bug :). > > Yes, it's a workaround to set the global variables to None. But My app just > provide a framework for my customers to run python scripts. That's means > the workaround requires my customers to update their python scripts. That > may make them unhappy :(. Is there a workaround in my code C++ side to call > Python C APIs to resolve the memory leak issue? Sorry, I wasn't clear. I meant to say that from your C++ side you should try explicitly setting the object to None to see if the __del__ method runs. I don't know C++, which is why I wrote it in Python. Assuming that this really is a memory leak, then you could try walking the module and deleting everything by hand. Again, I'm writing this in Python, but you should write it in C++. # instead of just this: del sys.modules['mymodule'] # PyDict_DelItemString # try this instead mod = sys.modules['mymodule'] namespace = vars(mod) for name in list(namespace.keys()): del namespace[name] # PyDict_DelItemString ? del mod del sys.modules['mymodule'] # PyDict_DelItemString But it might be easiest to just update once the bug is fixed. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From __peter__ at web.de Tue Sep 20 03:44:29 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Sep 2016 09:44:29 +0200 Subject: Cython taking more time than regular Python References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: Stefan Behnel wrote: > Peter Otten schrieb am 19.09.2016 um 14:55: >> In [7]: %%cython >> def omega(int n): >> cdef long i >> cdef long result = 0 >> for i in range(n): result += i >> return result >> ...: >> >> In [8]: %timeit omega(100000) >> 10000 loops, best of 3: 91.6 ?s per loop > > Note that this is the worst benchmark ever. Any non-dump C compiler will > happily apply Young Gau? and calculate the result in constant time. Is that optimization useful in an actual program or just a way to cheat in benchmarks? From rosuav at gmail.com Tue Sep 20 04:01:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Sep 2016 18:01:06 +1000 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module In-Reply-To: References: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Sep 20, 2016 at 4:19 PM, dl l wrote: > Yes, it's a workaround to set the global variables to None. But My app just > provide a framework for my customers to run python scripts. That's means > the workaround requires my customers to update their python scripts. That > may make them unhappy :(. Is there a workaround in my code C++ side to call > Python C APIs to resolve the memory leak issue? > Python's import system is fundamentally not designed for what I believe is your use-case here, of running potentially-edited user code. Instead, I suggest keeping 'import' for stable modules that don't get updated without restarting the process, and for the more dynamic code, build something using exec (or PyRun_StringFlags, which I believe is the C equivalent). Object lifetimes will then be entirely under your control. ChrisA From bc at freeuk.com Tue Sep 20 05:44:20 2016 From: bc at freeuk.com (BartC) Date: Tue, 20 Sep 2016 10:44:20 +0100 Subject: Cython taking more time than regular Python In-Reply-To: References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: On 20/09/2016 06:27, Stefan Behnel wrote: > Peter Otten schrieb am 19.09.2016 um 14:55: >> In [7]: %%cython >> def omega(int n): >> cdef long i >> cdef long result = 0 >> for i in range(n): result += i >> return result >> ...: >> >> In [8]: %timeit omega(100000) >> 10000 loops, best of 3: 91.6 ?s per loop > > Note that this is the worst benchmark ever. Any non-dump C compiler will > happily apply Young Gau? and calculate the result in constant time. Which 'non-dump' C compiler will actually do such an optimisation? (Just so I can steer clear of it; I don't want a compiler wasting /my/ time doing pointless analysis.) This actually quite a good micro-benchmark precisely because that would be an unusual optimisation. (With benchmarking you usually want to know how long it takes a program to perform a task, not how long it takes to *not* do it!) -- Bartc From auriocus at gmx.de Tue Sep 20 07:04:34 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 20 Sep 2016 13:04:34 +0200 Subject: Cython taking more time than regular Python In-Reply-To: References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: Am 20.09.16 um 09:44 schrieb Peter Otten: > Stefan Behnel wrote: > >> Peter Otten schrieb am 19.09.2016 um 14:55: >>> In [7]: %%cython >>> def omega(int n): >>> cdef long i >>> cdef long result = 0 >>> for i in range(n): result += i >>> return result >>> ...: >>> >>> In [8]: %timeit omega(100000) >>> 10000 loops, best of 3: 91.6 ?s per loop >> >> Note that this is the worst benchmark ever. Any non-dump C compiler will >> happily apply Young Gau? and calculate the result in constant time. > > Is that optimization useful in an actual program or just a way to cheat in > benchmarks? Good question, but I think this falls under "strength reduction" which is a useful optimization of tight loops in C. However, I'm not convinced it did succeed here. An evaluation of the Gau? formula would run in a few *nanoseconds* on any moddern machine. It may take a microsecond to call a functino from Python. a hundred microseconds means that the loop does run. Christian From __peter__ at web.de Tue Sep 20 07:43:44 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Sep 2016 13:43:44 +0200 Subject: Cython taking more time than regular Python References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: Christian Gollwitzer wrote: > Am 20.09.16 um 09:44 schrieb Peter Otten: >> Stefan Behnel wrote: >> >>> Peter Otten schrieb am 19.09.2016 um 14:55: >>>> In [7]: %%cython >>>> def omega(int n): >>>> cdef long i >>>> cdef long result = 0 >>>> for i in range(n): result += i >>>> return result >>>> ...: >>>> >>>> In [8]: %timeit omega(100000) >>>> 10000 loops, best of 3: 91.6 ?s per loop >>> >>> Note that this is the worst benchmark ever. Any non-dump C compiler will >>> happily apply Young Gau? and calculate the result in constant time. >> >> Is that optimization useful in an actual program or just a way to cheat >> in benchmarks? > > Good question, but I think this falls under "strength reduction" which > is a useful optimization of tight loops in C. > > However, I'm not convinced it did succeed here. An evaluation of the > Gau? formula would run in a few *nanoseconds* on any moddern machine. It > may take a microsecond to call a functino from Python. a hundred > microseconds means that the loop does run. A quick check indeed shows linear behaviour: In [1]: %load_ext cythonmagic In [2]: %%cython def sigma(int n): cdef long i cdef long result = 0 for i in range(n): result += i return result ...: In [3]: %timeit sigma(1000) 1000000 loops, best of 3: 1.04 ?s per loop In [4]: %timeit sigma(10000) 100000 loops, best of 3: 9.25 ?s per loop In [5]: %timeit sigma(100000) 10000 loops, best of 3: 91.3 ?s per loop From daiyueweng at gmail.com Tue Sep 20 07:52:12 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Tue, 20 Sep 2016 12:52:12 +0100 Subject: get the sum of differences between integers in a list Message-ID: Hi, I have a list numbers say, [1,2,3,4,6,8,9,10,11] First, I want to calculate the sum of the differences between the numbers in the list. Second, if a sequence of numbers having a difference of 1, put them in a list, i.e. there are two such lists, [1,2,3] [8,9,10,11] and also put the rest numbers in another list, i.e. there is only one such list in the example, [6]. Third, get the lists with the max/min sizes from above, i.e. in this example, the max list is, [8,9,10,11] min list is [1,2,3]. What's the best way to implement this? cheers From 380162267qq at gmail.com Tue Sep 20 08:12:34 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Tue, 20 Sep 2016 05:12:34 -0700 (PDT) Subject: I am newbie who can explain this code to me? Message-ID: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> >>> d = {} >>> keys = range(256) >>> vals = map(chr, keys) >>> map(operator.setitem, [d]*len(keys), keys, vals) It is from python library. What does [d]*len(keys) mean? d is the name of dict but put d in [] really confused me. From bc at freeuk.com Tue Sep 20 08:16:56 2016 From: bc at freeuk.com (BartC) Date: Tue, 20 Sep 2016 13:16:56 +0100 Subject: I am newbie who can explain this code to me? In-Reply-To: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> Message-ID: On 20/09/2016 13:12, 380162267qq at gmail.com wrote: >>>> d = {} >>>> keys = range(256) >>>> vals = map(chr, keys) >>>> map(operator.setitem, [d]*len(keys), keys, vals) > > It is from python library. What does [d]*len(keys) mean? > d is the name of dict but put d in [] really confused me. > if len(keys) is 5 then [d]*5 is: [d,d,d,d,d] [d] is a list, containing one item, a dict if that is what it is. -- Bartc From 380162267qq at gmail.com Tue Sep 20 08:34:38 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Tue, 20 Sep 2016 05:34:38 -0700 (PDT) Subject: I am newbie who can explain this code to me? In-Reply-To: References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> Message-ID: <022b4f11-1e10-4ab0-bca6-a952854898fb@googlegroups.com> ? 2016?9?20???? UTC-4??8:17:13?BartC??? > On 20/09/2016 13:12, 380162267qq at gmail.com wrote: > >>>> d = {} > >>>> keys = range(256) > >>>> vals = map(chr, keys) > >>>> map(operator.setitem, [d]*len(keys), keys, vals) > > > > It is from python library. What does [d]*len(keys) mean? > > d is the name of dict but put d in [] really confused me. > > > > if len(keys) is 5 then [d]*5 is: > > [d,d,d,d,d] > > [d] is a list, containing one item, a dict if that is what it is. > > -- > Bartc Thank you. I understand now From __peter__ at web.de Tue Sep 20 09:12:39 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Sep 2016 15:12:39 +0200 Subject: I am newbie who can explain this code to me? References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> <022b4f11-1e10-4ab0-bca6-a952854898fb@googlegroups.com> Message-ID: 380162267qq at gmail.com wrote: > ? 2016?9?20???? UTC-4??8:17:13?BartC??? >> On 20/09/2016 13:12, 380162267qq at gmail.com wrote: >> >>>> d = {} >> >>>> keys = range(256) >> >>>> vals = map(chr, keys) >> >>>> map(operator.setitem, [d]*len(keys), keys, vals) >> > >> > It is from python library. What does [d]*len(keys) mean? >> > d is the name of dict but put d in [] really confused me. >> > >> >> if len(keys) is 5 then [d]*5 is: >> >> [d,d,d,d,d] >> >> [d] is a list, containing one item, a dict if that is what it is. >> >> -- >> Bartc > > Thank you. I understand now It should be noted that the code above is really bad Python. Better alternatives are the simple loop d = {} for i in range(256): d[i] = chr(i) or the dict comprehension d = {i: chr(i) for i in range(256)} and even keys = range(256) d = dict(zip(keys, map(chr, keys))) because they don't build lists only to throw them away. Also, creating a list of dicts or lists is a common gotcha because after outer = [[]] * 3 the outer list contains *the* *same* list three times, not three empty lists. Try outer[0].append("surprise") print(outer) in the interactive interpreter to see why the difference matters. Finally, if you are just starting you might consider picking Python 3 instead of Python 2. From 380162267qq at gmail.com Tue Sep 20 09:19:16 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Tue, 20 Sep 2016 06:19:16 -0700 (PDT) Subject: What does this zip() code mean? Message-ID: <60118d80-fb0a-41a5-8afd-3577e9a9568c@googlegroups.com> >>> x = [1, 2, 3] >>> y = [4, 5, 6] >>> zipped = zip(x, y) >>> list(zipped) [(1, 4), (2, 5), (3, 6)] >>> x2, y2 = zip(*zip(x, y)) >>> x == list(x2) and y == list(y2) True My problem is >>> x2, y2 = zip(*zip(x, y)). zip return an iterator but x2 and y2 are different? I really need detail explanation about this line. From 380162267qq at gmail.com Tue Sep 20 09:32:52 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Tue, 20 Sep 2016 06:32:52 -0700 (PDT) Subject: I am newbie who can explain this code to me? In-Reply-To: References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> <022b4f11-1e10-4ab0-bca6-a952854898fb@googlegroups.com> Message-ID: <3c1bd613-1823-4cd7-80bc-6c48598a1254@googlegroups.com> ? 2016?9?20???? UTC-4??9:13:35?Peter Otten??? > 380162267qq at gmail.com wrote: > > > ? 2016?9?20???? UTC-4??8:17:13?BartC??? > >> On 20/09/2016 13:12, 380162267qq at gmail.com wrote: > >> >>>> d = {} > >> >>>> keys = range(256) > >> >>>> vals = map(chr, keys) > >> >>>> map(operator.setitem, [d]*len(keys), keys, vals) > >> > > >> > It is from python library. What does [d]*len(keys) mean? > >> > d is the name of dict but put d in [] really confused me. > >> > > >> > >> if len(keys) is 5 then [d]*5 is: > >> > >> [d,d,d,d,d] > >> > >> [d] is a list, containing one item, a dict if that is what it is. > >> > >> -- > >> Bartc > > > > Thank you. I understand now > > It should be noted that the code above is really bad Python. > Better alternatives are the simple loop > > d = {} > for i in range(256): > d[i] = chr(i) > > or the dict comprehension > > d = {i: chr(i) for i in range(256)} > > and even > > keys = range(256) > d = dict(zip(keys, map(chr, keys))) > > because they don't build lists only to throw them away. > > > Also, creating a list of dicts or lists is a common gotcha because after > > outer = [[]] * 3 > > the outer list contains *the* *same* list three times, not three empty > lists. Try > > outer[0].append("surprise") > print(outer) > > in the interactive interpreter to see why the difference matters. > > > Finally, if you are just starting you might consider picking Python 3 > instead of Python 2. Thank you.I learn more! From random832 at fastmail.com Tue Sep 20 09:35:34 2016 From: random832 at fastmail.com (Random832) Date: Tue, 20 Sep 2016 09:35:34 -0400 Subject: What does this zip() code mean? In-Reply-To: <60118d80-fb0a-41a5-8afd-3577e9a9568c@googlegroups.com> References: <60118d80-fb0a-41a5-8afd-3577e9a9568c@googlegroups.com> Message-ID: <1474378534.2708062.731399025.09E169A3@webmail.messagingengine.com> On Tue, Sep 20, 2016, at 09:19, 380162267qq at gmail.com wrote: > >>> x = [1, 2, 3] > >>> y = [4, 5, 6] > >>> zipped = zip(x, y) > >>> list(zipped) > [(1, 4), (2, 5), (3, 6)] > >>> x2, y2 = zip(*zip(x, y)) > >>> x == list(x2) and y == list(y2) > True > > My problem is >>> x2, y2 = zip(*zip(x, y)). > zip return an iterator but x2 and y2 are different? > I really need detail explanation about this line. Well, as you've seen, zip(x, y) is (1, 4), (2, 5), (3, 6) This means that zip(*...) is zip((1, 4), (2, 5), (3, 6)). It takes the first element of each argument (1, 2, and 3), and then the next element of each argument (4, 5, and 6). From 380162267qq at gmail.com Tue Sep 20 10:22:53 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Tue, 20 Sep 2016 07:22:53 -0700 (PDT) Subject: What does this zip() code mean? In-Reply-To: References: <60118d80-fb0a-41a5-8afd-3577e9a9568c@googlegroups.com> <1474378534.2708062.731399025.09E169A3@webmail.messagingengine.com> Message-ID: <222b8e09-6e9b-4fae-8019-78aeaf3b5c50@googlegroups.com> ? 2016?9?20???? UTC-4??9:35:50?Random832??? > On Tue, Sep 20, 2016, at 09:19, 380162267qq at gmail.com wrote: > > >>> x = [1, 2, 3] > > >>> y = [4, 5, 6] > > >>> zipped = zip(x, y) > > >>> list(zipped) > > [(1, 4), (2, 5), (3, 6)] > > >>> x2, y2 = zip(*zip(x, y)) > > >>> x == list(x2) and y == list(y2) > > True > > > > My problem is >>> x2, y2 = zip(*zip(x, y)). > > zip return an iterator but x2 and y2 are different? > > I really need detail explanation about this line. > > Well, as you've seen, zip(x, y) is (1, 4), (2, 5), (3, 6) > > This means that zip(*...) is zip((1, 4), (2, 5), (3, 6)). It takes the > first element of each argument (1, 2, and 3), and then the next element > of each argument (4, 5, and 6). thank you! From g at crcomp.net Tue Sep 20 10:45:25 2016 From: g at crcomp.net (Don Kuenz) Date: Tue, 20 Sep 2016 14:45:25 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.3-RELEASE? References: <20160919a@crcomp.net> Message-ID: <20160920a@crcomp.net> It turns out that the question isn't "How to install Python.h?" The question is "Why doesn't make find Python.h?" ------------------------------------------------------------------------ # uname -v FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 # cd / # find . -name 'Python.h' /usr/local/include/python2.7/Python.h /usr/local/include/python3.4m/Python.h ------------------------------------------------------------------------ $ uname -v FreeBSD 10.3-RELEASE-p7 #0: Thu Aug 11 18:38:15 UTC 2016 # cd / # find . -name 'Python.h' /usr/local/include/python2.7/Python.h /usr/local/include/python3.4m/Python.h ------------------------------------------------------------------------ Making all in src/cpython make all-am depbase=`echo data_arc.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`; /bin/sh In file included from data_arc.c:19:0: data.h:22:20: fatal error: Python.h: No such file or directory #include ^ compilation terminated. *** Error code 1 ------------------------------------------------------------------------ It seems that a symbolic link may be needed. Fortunately the developer is working with me on this problem. He may know the best way to proceed. Thank you, -- Don Kuenz KB7RPU Science is built up with facts, as a house is with stones. But a collection of facts is no more a science than a heap of stones is a house. - Poincare From steve+python at pearwood.info Tue Sep 20 10:45:42 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 00:45:42 +1000 Subject: get the sum of differences between integers in a list References: Message-ID: <57e14b97$0$1620$c3e8da3$5496439d@news.astraweb.com> On Tue, 20 Sep 2016 09:52 pm, Daiyue Weng wrote: > Hi, I have a list numbers say, > > [1,2,3,4,6,8,9,10,11] > > First, I want to calculate the sum of the differences between the numbers > in the list. Sounds like homework. What have you tried? Hint: use the sum() function to sum a list of numbers: py> sum([1, 2, 3]) 6 Another hint: to calculate the differences between numbers, you need to look at each number except the first, and subtract the *previous* number. Or possibly the *next* number. You decide what the question wants you to do. One way to do that is to loop over the INDEXES 0, 1, 2, 3, ... up to the number of items: for index in range(len(some_list)): x = some_list[i] A third hint (for advanced students): you can use zip() and list slicing to get the numbers two at a time without using the indexes. > Second, if a sequence of numbers having a difference of 1, put them in a > list, i.e. there are two such lists, > > [1,2,3] > > [8,9,10,11] > > and also put the rest numbers in another list, i.e. there is only one such > list in the example, > > [6]. Hint: for each number, decide whether or not the difference is 1. If the difference is *not* one, that's easy: just place that number into a second list. If the difference is 1, then you place that number into a third list, BUT only as part of a run. So you'll go: difference between 1 and 2 is 1, so 1 goes into list B; difference between 2 and 3 is 1, so 2 goes into list B; difference between 3 and 4 is 1, so 3 goes into list B; difference between 4 and 6 is 2, so 4 goes into list A; difference between 6 and 8 is 2, so 6 goes into list A; difference between 8 and 9 is 1, so list B is put aside, a new list is started, and 8 goes into this new list B; etc. Hint: try keeping a list of lists. To start a new list, append an empty list to it. > Third, get the lists with the max/min sizes from above, i.e. in this > example, the max list is, > > [8,9,10,11] > > min list is > > [1,2,3]. Hint: min([5, 6, 4, 1, 2, 3]) returns the smallest number, 1. max([5, 6, 4, 1, 2, 3]) returns the largest number, 6. Use len() to get the size of a list. > What's the best way to implement this? By writing code, of course! But writing code should be the SECOND thing you do, not the first. First, work through the calculation by hand. How do you do it by hand, using pen and paper? Now write some code to do the same thing! Good luck! -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From doctor at doctor.nl2k.ab.ca Tue Sep 20 11:37:04 2016 From: doctor at doctor.nl2k.ab.ca (The Doctor) Date: Tue, 20 Sep 2016 15:37:04 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.3-RELEASE? References: <20160919a@crcomp.net> <20160920a@crcomp.net> Message-ID: In article <20160920a at crcomp.net>, Don Kuenz wrote: > >It turns out that the question isn't "How to install Python.h?" The >question is "Why doesn't make find Python.h?" > >------------------------------------------------------------------------ > ># uname -v >FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 > ># cd / ># find . -name 'Python.h' >/usr/local/include/python2.7/Python.h >/usr/local/include/python3.4m/Python.h > >------------------------------------------------------------------------ > >$ uname -v >FreeBSD 10.3-RELEASE-p7 #0: Thu Aug 11 18:38:15 UTC 2016 > ># cd / ># find . -name 'Python.h' >/usr/local/include/python2.7/Python.h >/usr/local/include/python3.4m/Python.h > >------------------------------------------------------------------------ > >Making all in src/cpython >make all-am >depbase=`echo data_arc.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`; /bin/sh >In file included from data_arc.c:19:0: >data.h:22:20: fatal error: Python.h: No such file or directory > #include > ^ >compilation terminated. >*** Error code 1 > >------------------------------------------------------------------------ > >It seems that a symbolic link may be needed. Fortunately the developer >is working with me on this problem. He may know the best way to proceed. > >Thank you, > >-- >Don Kuenz KB7RPU > > Science is built up with facts, as a house is with stones. But a >collection of facts is no more a science than a heap of stones is a >house. - Poincare Which version of Python do you wish to use? -- Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca God,Queen and country!Never Satan President Republic!Beware AntiChrist rising! http://www.fullyfollow.me/rootnl2k Look at Psalms 14 and 53 on Atheism Time for the USA to hold a referendum on its republic and vote to dissolve!! From tim at akwebsoft.com Tue Sep 20 11:41:40 2016 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 20 Sep 2016 07:41:40 -0800 Subject: Idiomatic code validator? Message-ID: <20160920154140.GC559@mail.akwebsoft.com> Not to confuse idiomatic code validation with pep8 validation (I use elpy on emacs) Is there such a thing as a validator for _idiomatic_ code? I have Knupp's "Writing Idiomatic Python" and have bookmarked some advisory websites that illustrate idiomatic style. thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com From __peter__ at web.de Tue Sep 20 12:21:17 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Sep 2016 18:21:17 +0200 Subject: get the sum of differences between integers in a list References: Message-ID: Daiyue Weng wrote: > Hi, I have a list numbers say, > > [1,2,3,4,6,8,9,10,11] > > First, I want to calculate the sum of the differences between the numbers > in the list. > Second, if a sequence of numbers having a difference of 1, put them in a > list, i.e. there are two such lists, > > [1,2,3] Why isn't 4 in that list? > [8,9,10,11] > > and also put the rest numbers in another list, i.e. there is only one such > list in the example, > > [6]. > > Third, get the lists with the max/min sizes from above, i.e. in this > example, the max list is, > > [8,9,10,11] > > min list is > > [1,2,3]. In addition to Steve's hint: max() takes a key argument, e. g. to get the string with the highest amount of "a"s: >>> max(["xyz", "abc", "alpha"], key=lambda s: s.count("a")) 'alpha' Finding the longest string or list doesn't even require you to define your own function. From dvl at psu.edu Tue Sep 20 12:46:04 2016 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Tue, 20 Sep 2016 12:46:04 -0400 Subject: Linear Time Tree Traversal Generator Message-ID: <1474389964l.34341004l.0l@psu.edu> I am trying to find a better (i.e. more efficient) way to implement a generator that traverses a tree. The current model of the code (which is also used by a textbook I am teaching from does this) def __iter__(node): for x in iter(node._left): yield x yield node._value for x in iter(node._right) yield x This is nice, simple, and straightforward, but has an O(n log n) running time, since values from the leaves of the tree have to be yielded multiple times to the top of the tree. Now, I could certainly implement a linear-time traversal without the gnerator: def to_list(node,result): """append node information to result""" result = to_list(node._left, result) result.append(node._value) return to_list(node,_right, result) but then that requires the extra memory space to build the list into, which is basically what the generator is supposed to avoid. Now, I did see that itertools has a chain method for concatenating iterators, so it would be nice to concatenate the results from the recursive calls without the for loops, but I have no idea how to squeeze the 'yield node._value' in between them. Is there hope for a linear-time tree-traversal generator, or will I have just have to settle for an n-log-n generator or a linear time behavior with linear extra space? Roger Christman instructor Pennsylvania State University From rosuav at gmail.com Tue Sep 20 13:02:14 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Sep 2016 03:02:14 +1000 Subject: Linear Time Tree Traversal Generator In-Reply-To: <1474389964l.34341004l.0l@psu.edu> References: <1474389964l.34341004l.0l@psu.edu> Message-ID: On Wed, Sep 21, 2016 at 2:46 AM, ROGER GRAYDON CHRISTMAN wrote: > The current model of the code (which is also used by a textbook I am teaching > from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running time, > since > values from the leaves of the tree have to be yielded multiple times to the top > of the tree. > Normally I'd implement it thus: def __iter__(self): if self._left: yield from self._left yield self._value if self._right: yield from self._right But as far as I can see, it's equivalent to your code, except that I allow the left and right nodes to be None (you might have something iterable-but-empty in leaf nodes - not sure). The 'yield from' operation is highly optimized, so it's not going to cost too much. You don't have to concern yourself overly with the "yielding up the chain" cost here, as it'll all be done for you by the interpreter. It's entirely possible for the interpreter to actually eliminate the chain by storing a reference to the deepest generator; in any case, it's adequately fast for everything I've ever needed of it. ChrisA From rgaddi at highlandtechnology.invalid Tue Sep 20 13:03:35 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 20 Sep 2016 17:03:35 -0000 (UTC) Subject: Linear Time Tree Traversal Generator References: <1474389964l.34341004l.0l@psu.edu> Message-ID: ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a generator > that traverses a tree. > > The current model of the code (which is also used by a textbook I am teaching > from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running time, > since > values from the leaves of the tree have to be yielded multiple times to the top > of the tree. > > Now, I could certainly implement a linear-time traversal without the gnerator: > > def to_list(node,result): > """append node information to result""" > result = to_list(node._left, result) > result.append(node._value) > return to_list(node,_right, result) > > but then that requires the extra memory space to build the list into, which > is basically what the generator is supposed to avoid. > > Now, I did see that itertools has a chain method for concatenating > iterators, so it would be nice to concatenate the results from the > recursive calls without the for loops, but I have no idea how to > squeeze the 'yield node._value' in between them. > > Is there hope for a linear-time tree-traversal generator, or will > I have just have to settle for an n-log-n generator or a linear time > behavior with linear extra space? > > Roger Christman > instructor > Pennsylvania State University > The only thing that's O(N log N) in that is the number of actual yield calls. If you're doing pretty much anything with those values as they're being iterated over then they'll dominate the timing, and that is O(N). If you're using Python 3.4 or above you can turn that into def __iter__(node): yield from iter(node._left) yield node._value yield from iter(node._right) I think there's a little bit of optimization that goes on using yield from. That said, all this has a serious stink of premature optimization. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From none at invalid.com Tue Sep 20 13:06:22 2016 From: none at invalid.com (mm0fmf) Date: Tue, 20 Sep 2016 18:06:22 +0100 Subject: get the sum of differences between integers in a list In-Reply-To: References: Message-ID: On 20/09/2016 12:52, Daiyue Weng wrote: > What's the best way to implement this? > With a python script. Show your work and people will help you. From walters.justin01 at gmail.com Tue Sep 20 13:24:45 2016 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 20 Sep 2016 10:24:45 -0700 Subject: Linear Time Tree Traversal Generator In-Reply-To: <1474389964l.34341004l.0l@psu.edu> References: <1474389964l.34341004l.0l@psu.edu> Message-ID: On Tue, Sep 20, 2016 at 9:46 AM, ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a > generator > that traverses a tree. > > The current model of the code (which is also used by a textbook I am > teaching > from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running > time, > since > values from the leaves of the tree have to be yielded multiple times to > the top > of the tree. > Are the left and right attributes collections of more nodes or are they simply references to the node's position in the tree? >From the code provided it seems like the former is true and a node's left attribute is a reference to another node? I don't know how flexible you are with the structure of your tree, but you could try taking the modified pre-order tree traversal approach. This article explains it in the context of a database, but the idea is the same: https://www.sitepoint.com/hierarchical-data-database-2/ Each node would then have a parent attribute as well as left and right attributes. The parent would be a reference to a parent node, and the left and right would be integers that position the element in the tree. The upside to this is that traversal and lookup is much faster since you do not need to have an iterator nested in an iterator. This is because the top level node will always have the lowest integer as it's left attribute and the highest integer as it's right attribute. That means that you can instead have a single iterator that iterates through a range of integers to yield the node with the specified left and right values. The downside is that inserting a new node can take a long time because, depending on the insertion point, the left and right values for each node in the tree may have to be recalculated. Now, I may have completely missed the mark here. I am completely self taught and have only been programming for about 3 years. I hope that you gleaned some value from my response either way. From __peter__ at web.de Tue Sep 20 13:30:31 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Sep 2016 19:30:31 +0200 Subject: Linear Time Tree Traversal Generator References: <1474389964l.34341004l.0l@psu.edu> Message-ID: ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a > generator that traverses a tree. > > The current model of the code (which is also used by a textbook I am > teaching from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running > time, since > values from the leaves of the tree have to be yielded multiple times to > the top of the tree. > > Now, I could certainly implement a linear-time traversal without the > gnerator: > > def to_list(node,result): > """append node information to result""" > result = to_list(node._left, result) > result.append(node._value) > return to_list(node,_right, result) > > but then that requires the extra memory space to build the list into, > which is basically what the generator is supposed to avoid. > > Now, I did see that itertools has a chain method for concatenating > iterators, so it would be nice to concatenate the results from the > recursive calls without the for loops, but I have no idea how to > squeeze the 'yield node._value' in between them. Your above method would become def __iter__(self): return chain(self._left, [self._value], self._right) i. e. you wrap the value in an iterable. But I don't see how this could help in terms of big O. > Is there hope for a linear-time tree-traversal generator, or will > I have just have to settle for an n-log-n generator or a linear time > behavior with linear extra space? > > Roger Christman > instructor > Pennsylvania State University From ganesh1pal at gmail.com Tue Sep 20 14:04:41 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Tue, 20 Sep 2016 23:34:41 +0530 Subject: list or dictionary Message-ID: I am on python 2.7 and Linux I have the stdout in the below form , I need to write a function to get hostname for the given id. Example: >>> stdout 'hostname-1 is array with id 1\nhostname-2 is array with id 2\nhostname-3 is array with id 3\n' def get_hostname(id) return id what's a better option here 1. store it in list and grep for id and return 2. store it in dict as key and value i.e hostname = { 'hostname1': 1} and return key 3. any other simple options. Regards, Ganesh From tjreedy at udel.edu Tue Sep 20 15:10:41 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Sep 2016 15:10:41 -0400 Subject: I am newbie who can explain this code to me? In-Reply-To: References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> <022b4f11-1e10-4ab0-bca6-a952854898fb@googlegroups.com> Message-ID: On 9/20/2016 9:12 AM, Peter Otten wrote: >> ? 2016?9?20???? UTC-4??8:17:13?BartC??? >>> On 20/09/2016 13:12, 380162267qq at gmail.com wrote: >>>>>>> d = {} >>>>>>> keys = range(256) >>>>>>> vals = map(chr, keys) >>>>>>> map(operator.setitem, [d]*len(keys), keys, vals) >>>> >>>> It is from python library. What does [d]*len(keys) mean? >>>> d is the name of dict but put d in [] really confused me. Where in which 'python library? I cannot findI the above in 2.7 or 3.6 stdlib. The code should be replaced by > It should be noted that the code above is really bad Python. > Better alternatives are the simple loop > > d = {} > for i in range(256): > d[i] = chr(i) > > or the dict comprehension > > d = {i: chr(i) for i in range(256)} this. -- Terry Jan Reedy From nobody at nowhere.invalid Tue Sep 20 15:28:02 2016 From: nobody at nowhere.invalid (Nobody) Date: Tue, 20 Sep 2016 20:28:02 +0100 Subject: I am newbie who can explain this code to me? References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> <022b4f11-1e10-4ab0-bca6-a952854898fb@googlegroups.com> Message-ID: On Tue, 20 Sep 2016 15:12:39 +0200, Peter Otten wrote: > because they don't build lists only to throw them away. The lists could have been avoided by using iterators, e.g. import itertools as it keys = xrange(256) vals = it.imap(chr, keys) max(it.imap(operator.setitem, it.repeat(d), keys, vals)) > Also, creating a list of dicts or lists is a common gotcha because after > > outer = [[]] * 3 > > the outer list contains *the* *same* list three times, not three empty > lists. But in this case, it's not a gotcha; it's intentional that each iteration operates upon the same dictionary. Essentially, [d]*len(keys) is a trick to get around the fact that map() requires all of the arguments (apart from the function) to be sequences. itertools.repeat() is possibly a better trick, although then you can't use map(), because map() iterates until *all* sequences are exhausted, appending None values for shorter sequences. itertools.imap() terminates once the shortest sequence is exhausted. In this specific case, a loop or comprehension would have been better. But in situations where you don't control the iteration, the ability to coerce something into a pre-determined iteration pattern is useful. From ryaku711 at gmail.com Tue Sep 20 15:43:13 2016 From: ryaku711 at gmail.com (Andrew Clark) Date: Tue, 20 Sep 2016 12:43:13 -0700 (PDT) Subject: automated comparison tool Message-ID: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> I'm trying to develop a tool in python that will allow me to compare two file. I know this sounds like it's been done before but there is a catch. Files are stored on a remote server. There are three separate directories. StartupConfig, RunningConfig, and ArchiveConfig I need to have the python program do the following access remote directories run through startup, running and archive to find files with same hostname(do this for all files) once all three are found compare them to each other returning true or false if they are or are not the same however, files contain certain blocks of text that need to be ignored as these blocks of text will never be the same. I've looked at a couple different libraries such as the difflib and even ciscoconfparse. I'm not new to programming just have not done it for 10+ years. If anyone can help me out with sudo code or set me in the right direction would be nice. From tjreedy at udel.edu Tue Sep 20 15:43:18 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Sep 2016 15:43:18 -0400 Subject: Idiomatic code validator? In-Reply-To: <20160920154140.GC559@mail.akwebsoft.com> References: <20160920154140.GC559@mail.akwebsoft.com> Message-ID: On 9/20/2016 11:41 AM, Tim Johnson wrote: > Not to confuse idiomatic code validation with pep8 validation Strictly speaking, there cannot be a mechanical PEP 8 validator, as any mechanical checker violates the admonitions of the beginning sections 'Introductions' and 'A Foolish Consistency is the Hobgoblin of Little Minds'. For this reason, the core developers request the author of the checker formerly known as 'pep8' to change its name, which he did. > Is there such a thing as a validator for _idiomatic_ code? What would such a thing do? Flag supposedly non-idiomatic code? Or mark code recognized as 'idiomatic', with no implication either way about other code? > I have Knupp's "Writing Idiomatic Python" and have bookmarked some > advisory websites that illustrate idiomatic style. Do they all agree on 'idiomatic'? I am sure that the long-time frequent contributors on python list do not. -- Terry Jan Reedy From tim at akwebsoft.com Tue Sep 20 15:54:55 2016 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 20 Sep 2016 11:54:55 -0800 Subject: Idiomatic code validator? In-Reply-To: References: <20160920154140.GC559@mail.akwebsoft.com> Message-ID: <20160920195455.GD559@mail.akwebsoft.com> * Terry Reedy [160920 11:48]: > On 9/20/2016 11:41 AM, Tim Johnson wrote: > > Not to confuse idiomatic code validation with pep8 validation > > Strictly speaking, there cannot be a mechanical PEP 8 validator, as any > mechanical checker violates the admonitions of the beginning sections > 'Introductions' and 'A Foolish Consistency is the Hobgoblin of Little > Minds'. For this reason, the core developers request the author of the > checker formerly known as 'pep8' to change its name, which he did. elpy uses flake8 https://github.com/jorgenschaefer/elpy/wiki/Configuration > > Is there such a thing as a validator for _idiomatic_ code? > > What would such a thing do? Flag supposedly non-idiomatic code? Or mark > code recognized as 'idiomatic', with no implication either way about other > code? Why not? > > I have Knupp's "Writing Idiomatic Python" and have bookmarked some > > advisory websites that illustrate idiomatic style. > > Do they all agree on 'idiomatic'? Not likely, I would not expect them to. Thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com From lawrencedo99 at gmail.com Tue Sep 20 16:01:07 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 20 Sep 2016 13:01:07 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <87y42pbibn.fsf@jester.gateway.pace.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <87y42pbibn.fsf@jester.gateway.pace.com> Message-ID: On Sunday, September 18, 2016 at 10:42:16 PM UTC+12, Paul Rubin wrote: > > Lawrence D?Oliveiro writes: >> > I'm quite sure there are Java bindings for all those protocols. Are any of these supported by the Java app in question? Doesn?t seem like it. >> Like I said, trying to automate a GUI is a waste of time. GUIs are >> designed for humans, not computers, to use. > > Automation doesn't simulate button presses or anything like that: the > automate objects expose higher level user actions. E.g. the web browser > object has a navigate method and that sort of thing. In other words, the GUI becomes less and less relevant to this use case. > The classic automation example is embedding a chunk of an Excel > spreadsheet in the middle of a Word document, so it's displayed with > Word's fonts and formatting, but when you change a number in the > spreadsheet segment, the formulas run and the other numbers change. > What happens there is Word collects the numbers you type, then calls the > Excel automation interfaces to update the relevant spreadsheet cells and > read back new numbers. There are various hacks in KDE, Gnome, etc. to > do similar things under Linux. It's all transparent to the user and > presents useful features. That?s not ?automation?, that?s ?compound documents?. For some reason this facility gets very little use these days. >> GUIs are the end of the abstraction chain: you cannot build anything >> more on top of them. > > IMHO you're not contributing useful insights through these incorrect > guesses about how Windows automation works. Has anybody contributed a non-problematic solution yet? Precisely. From lawrencedo99 at gmail.com Tue Sep 20 16:02:32 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 20 Sep 2016 13:02:32 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <4fdd2732-dd21-435a-9767-e371e9c3dcd6@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> <338bd02a-5a0c-4ec5-b5d8-5702bbc9e4e1@googlegroups.com> <4fdd2732-dd21-435a-9767-e371e9c3dcd6@googlegroups.com> Message-ID: <64f477a1-09b7-43ea-961c-54286cde8f8a@googlegroups.com> On Tuesday, September 20, 2016 at 1:11:20 PM UTC+12, Ned Batchelder wrote: > We get it, you don't like GUIs. Who says I don?t like GUIs ? I just assume we?ve moved on from the 1990s, when they were considered to be the pinnacle of computing evolution, that?s all. From __peter__ at web.de Tue Sep 20 16:15:16 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Sep 2016 22:15:16 +0200 Subject: I am newbie who can explain this code to me? References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> <022b4f11-1e10-4ab0-bca6-a952854898fb@googlegroups.com> Message-ID: Nobody wrote: > On Tue, 20 Sep 2016 15:12:39 +0200, Peter Otten wrote: > >> because they don't build lists only to throw them away. > > The lists could have been avoided by using iterators, e.g. > > import itertools as it > keys = xrange(256) > vals = it.imap(chr, keys) > max(it.imap(operator.setitem, it.repeat(d), keys, vals)) > >> Also, creating a list of dicts or lists is a common gotcha because after >> >> outer = [[]] * 3 >> >> the outer list contains *the* *same* list three times, not three empty >> lists. > > But in this case, it's not a gotcha; Remember that the OP is a newbie > it's intentional and the author of the original example is trying to be clever, but in my eyes doesn't succeed. > that each iteration > operates upon the same dictionary. > > Essentially, [d]*len(keys) is a trick to get around the fact that map() > requires all of the arguments (apart from the function) to be sequences. > > itertools.repeat() is possibly a better trick, although then you can't use > map(), because map() iterates until *all* sequences are exhausted, > appending None values for shorter sequences. itertools.imap() terminates > once the shortest sequence is exhausted. > > In this specific case, a loop or comprehension would have been better. But > in situations where you don't control the iteration, the ability to coerce > something into a pre-determined iteration pattern is useful. You mean there is a situation where you'd actually recommend/use > max(it.imap(operator.setitem, it.repeat(d), keys, vals)) ? I'd like to see that use case. On second thought -- we might both settle on "Recommended by nobody" ;) From martin.schoon at gmail.com Tue Sep 20 16:17:10 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 20 Sep 2016 20:17:10 GMT Subject: Another =?UTF-8?Q?=C3=A5=2C?= =?UTF-8?Q?_=C3=A4=2C?= =?UTF-8?Q?_=C3=B6?= question References: Message-ID: Den 2016-09-19 skrev Christian Gollwitzer : > Am 19.09.16 um 22:21 schrieb Martin Sch??n: >> I am studying some of these tutorials: >> https://pythonprogramming.net/matplotlib-intro-tutorial/ >> >> I am recreating the code and I use my native Swedish for comments, >> labels and titles. Until now I have been doing so using Geany >> and executing using F5. This works fine. >> >> But -- now I tested using emacs instead using C-c C-c to execute. >> Noting happens so I try to run the program from command line and >> find that now Python can't stand my ?, ? and ?. >> >> I am puzzled: With Geany there is no problem but outside Geany >> I am punished by Python for using Swedish. > > you are not "punished for Swedish", you need to tell Python the encoding > of the file it runs. See here: > https://www.python.org/dev/peps/pep-0263/ > > Assuming that you use UTF-8 (you should check with an emacs expert, I am > not an emacs user), try putting the header > > #!/usr/bin/python > # -*- coding: utf-8 -*- > > on top of your files. > I already have this and since it doesn't work from command line either it can't be an emacs unique problem. Still confused... Too late to find a emacs forum tonight. /Martin From martin.schoon at gmail.com Tue Sep 20 16:21:22 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 20 Sep 2016 20:21:22 GMT Subject: Another =?UTF-8?Q?=C3=A5=2C?= =?UTF-8?Q?_=C3=A4=2C?= =?UTF-8?Q?_=C3=B6?= question References: Message-ID: Den 2016-09-19 skrev Lawrence D?Oliveiro : > On Tuesday, September 20, 2016 at 8:21:25 AM UTC+12, Martin Sch??n wrote: >> But -- now I tested using emacs instead using C-c C-c to execute. >> Noting happens so I try to run the program from command line and >> find that now Python can't stand my ?, ? and ?. > > What version of Python? Python 3 accepts Unicode UTF-8 as a matter of course. Python 2.7. I just tried running my code in Python 3 and that worked like charm. /Martin From lawrencedo99 at gmail.com Tue Sep 20 16:24:58 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 20 Sep 2016 13:24:58 -0700 (PDT) Subject: automated comparison tool In-Reply-To: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> Message-ID: On Wednesday, September 21, 2016 at 7:44:22 AM UTC+12, Andrew Clark wrote: > If anyone can help me out with sudo code or set me in the right direction > would be nice. You know What Aesop said: ?the gods* help those who help themselves?. Start by posting an initial stab at your code for solving, if not the whole problem, at least part of it. *for ?gods?, read ?peanut gallery?. They?ll be falling over themselves to critique every little shortcoming, real or otherwise, in the code you post. From lawrencedo99 at gmail.com Tue Sep 20 16:26:40 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 20 Sep 2016 13:26:40 -0700 (PDT) Subject: list or dictionary In-Reply-To: References: Message-ID: <2d4f2f89-c1b4-45c2-808e-83a24b9817e3@googlegroups.com> On Wednesday, September 21, 2016 at 6:05:41 AM UTC+12, Ganesh Pal wrote: > I am on python 2.7 ... Why? From __peter__ at web.de Tue Sep 20 16:34:32 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Sep 2016 22:34:32 +0200 Subject: Another =?UTF-8?B?w6UsIMOkLCDDtg==?= question References: Message-ID: Martin Sch??n wrote: > Den 2016-09-19 skrev Christian Gollwitzer : >> Am 19.09.16 um 22:21 schrieb Martin Sch??n: >>> I am studying some of these tutorials: >>> https://pythonprogramming.net/matplotlib-intro-tutorial/ >>> >>> I am recreating the code and I use my native Swedish for comments, >>> labels and titles. Until now I have been doing so using Geany >>> and executing using F5. This works fine. >>> >>> But -- now I tested using emacs instead using C-c C-c to execute. >>> Noting happens so I try to run the program from command line and >>> find that now Python can't stand my ?, ? and ?. >>> >>> I am puzzled: With Geany there is no problem but outside Geany >>> I am punished by Python for using Swedish. >> >> you are not "punished for Swedish", you need to tell Python the encoding >> of the file it runs. See here: >> https://www.python.org/dev/peps/pep-0263/ >> >> Assuming that you use UTF-8 (you should check with an emacs expert, I am >> not an emacs user), try putting the header >> >> #!/usr/bin/python >> # -*- coding: utf-8 -*- >> >> on top of your files. >> > I already have this and since it doesn't work from command line > either it can't be an emacs unique problem. > > Still confused... > > Too late to find a emacs forum tonight. > > /Martin Are all non-ascii strings unicode? I. e. u"Sch??n" rather than just "Sch??n" ? From irmen.NOSPAM at xs4all.nl Tue Sep 20 16:38:02 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 20 Sep 2016 22:38:02 +0200 Subject: pypy on windows much slower than linux/mac when using complex number type? Message-ID: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> Hi, I've stumbled across a peculiar performance issue with Pypy across some different platforms. It was very visible in some calculation heavy code that I wrote that uses Python's complex number type to calculate the well-known Mandelbrot set. Pypy running the code on my Windows machine is doing okay, but when running the same code on Pypy on different systems, the performance difference is so big it is not even funny. The other implementations are MUCH faster than the windows one. Which is quite unexpected because the other machines I've tested on have the same or much lower physical CPU specs than the windows machine. Here's the comparison: Machine specs: Windows: 64 bits Windows 7, Intel Core 2 Quad 3.4 Ghz Linux: 32 bits Mint 18, Virtualbox VM on above windows machine Mac mini: OS X 10.11.6, Intel Core 2 Duo 2.53 Ghz The test code I've been using is here: https://gist.github.com/irmen/c6b12b4cf88a6a4fcf5ff721c7089078 Test results: function: mandel / iterations Mac mini, Pypy 5.4.1 (64-bit): 0.81 sec / 0.65 sec Linux, Pypy 5.1 (32-bit): 1.06 sec / 0.64 sec Windows, Pypy 5.4.1 (32-bit): 5.59 sec / 2.87 sec What could cause such a huge difference? Is it perhaps a compiler issue (where gcc/clang are MUCH better at optimizing certain things, although I wonder how much of a factor this is because Pypy is doing JITting by itself as far as I am aware)? Or is something strange going on with the way the complex number type is implemented? (the difference doesn't occur when using only floats) Regards Irmen de Jong From rosuav at gmail.com Tue Sep 20 16:43:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Sep 2016 06:43:43 +1000 Subject: pypy on windows much slower than linux/mac when using complex number type? In-Reply-To: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> References: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> Message-ID: On Wed, Sep 21, 2016 at 6:38 AM, Irmen de Jong wrote: > Windows: 64 bits Windows 7, Intel Core 2 Quad 3.4 Ghz > Linux: 32 bits Mint 18, Virtualbox VM on above windows machine > Mac mini: OS X 10.11.6, Intel Core 2 Duo 2.53 Ghz > > The test code I've been using is here: > https://gist.github.com/irmen/c6b12b4cf88a6a4fcf5ff721c7089078 > > Test results: > function: mandel / iterations > Mac mini, Pypy 5.4.1 (64-bit): 0.81 sec / 0.65 sec > Linux, Pypy 5.1 (32-bit): 1.06 sec / 0.64 sec > Windows, Pypy 5.4.1 (32-bit): 5.59 sec / 2.87 sec > > > What could cause such a huge difference? Dunno if it's the cause or not, but you're running a 32-bit PyPy on a 64-bit Windows. I could well imagine that that has some odd significance. ChrisA From rosuav at gmail.com Tue Sep 20 16:44:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Sep 2016 06:44:35 +1000 Subject: =?UTF-8?B?UmU6IEFub3RoZXIgw6UsIMOkLCDDtiBxdWVzdGlvbg==?= In-Reply-To: References: Message-ID: On Wed, Sep 21, 2016 at 6:21 AM, Martin Sch??n wrote: > Den 2016-09-19 skrev Lawrence D?Oliveiro : >> On Tuesday, September 20, 2016 at 8:21:25 AM UTC+12, Martin Sch??n wrote: >>> But -- now I tested using emacs instead using C-c C-c to execute. >>> Noting happens so I try to run the program from command line and >>> find that now Python can't stand my ?, ? and ?. >> >> What version of Python? Python 3 accepts Unicode UTF-8 as a matter of course. > > Python 2.7. > I just tried running my code in Python 3 and that worked like charm. Then you've found the solution. Py2's Unicode support is weaker than Py3's, and it often depends on encodings. ChrisA From rosuav at gmail.com Tue Sep 20 17:01:39 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Sep 2016 07:01:39 +1000 Subject: list or dictionary In-Reply-To: References: Message-ID: On Wed, Sep 21, 2016 at 4:04 AM, Ganesh Pal wrote: > 1. store it in list and grep for id and return > 2. store it in dict as key and value i.e hostname = { 'hostname1': 1} and > return key > 3. any other simple options. 4. Store it in dict, but the other way around. The key should be the thing you want to look up; the value, the thing you want to find out. ChrisA From ryaku711 at gmail.com Tue Sep 20 17:20:21 2016 From: ryaku711 at gmail.com (Andrew Clark) Date: Tue, 20 Sep 2016 14:20:21 -0700 (PDT) Subject: automated comparison tool In-Reply-To: References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> Message-ID: On Tuesday, September 20, 2016 at 3:25:11 PM UTC-5, Lawrence D?Oliveiro wrote: > On Wednesday, September 21, 2016 at 7:44:22 AM UTC+12, Andrew Clark wrote: > > If anyone can help me out with sudo code or set me in the right direction > > would be nice. > > You know What Aesop said: ?the gods* help those who help themselves?. Start by posting an initial stab at your code for solving, if not the whole problem, at least part of it. > > *for ?gods?, read ?peanut gallery?. They?ll be falling over themselves to critique every little shortcoming, real or otherwise, in the code you post. Thanks. I've restarted my code so many times i no longer have a working version of anything. I'm trying to get the "go to remote directory" part to get files done first. From bill at baddogconsulting.com Tue Sep 20 17:35:54 2016 From: bill at baddogconsulting.com (Bill Deegan) Date: Tue, 20 Sep 2016 14:35:54 -0700 Subject: automated comparison tool In-Reply-To: References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> Message-ID: Use Git... at least you get can back what used to work.. On Tue, Sep 20, 2016 at 2:20 PM, Andrew Clark wrote: > On Tuesday, September 20, 2016 at 3:25:11 PM UTC-5, Lawrence D?Oliveiro > wrote: > > On Wednesday, September 21, 2016 at 7:44:22 AM UTC+12, Andrew Clark > wrote: > > > If anyone can help me out with sudo code or set me in the right > direction > > > would be nice. > > > > You know What Aesop said: ?the gods* help those who help themselves?. > Start by posting an initial stab at your code for solving, if not the whole > problem, at least part of it. > > > > *for ?gods?, read ?peanut gallery?. They?ll be falling over themselves > to critique every little shortcoming, real or otherwise, in the code you > post. > > Thanks. I've restarted my code so many times i no longer have a working > version of anything. I'm trying to get the "go to remote directory" part to > get files done first. > -- > https://mail.python.org/mailman/listinfo/python-list > From g at crcomp.net Tue Sep 20 18:14:13 2016 From: g at crcomp.net (Don Kuenz) Date: Tue, 20 Sep 2016 22:14:13 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.3-RELEASE? References: <20160919a@crcomp.net> <20160920a@crcomp.net> Message-ID: <20160920c@crcomp.net> The Doctor wrote: > In article <20160920a at crcomp.net>, Don Kuenz wrote: >> >>It turns out that the question isn't "How to install Python.h?" The >>question is "Why doesn't make find Python.h?" >> >>------------------------------------------------------------------------ >> >># uname -v >>FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 >> >># cd / >># find . -name 'Python.h' >>/usr/local/include/python2.7/Python.h >>/usr/local/include/python3.4m/Python.h >> >>------------------------------------------------------------------------ >> >>It seems that a symbolic link may be needed. Fortunately the developer >>is working with me on this problem. He may know the best way to proceed. > > Which version of Python do you wish to use? It's best for me to know how to use either version. It's OK if each version is mutually exclusive. Thank you, -- Don Kuenz KB7RPU Every tool carries with it the spirit by which it has been created. - Heisenberg From irmen.NOSPAM at xs4all.nl Tue Sep 20 18:50:41 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 21 Sep 2016 00:50:41 +0200 Subject: pypy on windows much slower than linux/mac when using complex number type? In-Reply-To: References: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> Message-ID: <57e1bd41$0$881$e4fe514c@news.xs4all.nl> On 20-9-2016 22:43, Chris Angelico wrote: > On Wed, Sep 21, 2016 at 6:38 AM, Irmen de Jong wrote: >> Windows: 64 bits Windows 7, Intel Core 2 Quad 3.4 Ghz >> Linux: 32 bits Mint 18, Virtualbox VM on above windows machine >> Mac mini: OS X 10.11.6, Intel Core 2 Duo 2.53 Ghz >> >> The test code I've been using is here: >> https://gist.github.com/irmen/c6b12b4cf88a6a4fcf5ff721c7089078 >> >> Test results: >> function: mandel / iterations >> Mac mini, Pypy 5.4.1 (64-bit): 0.81 sec / 0.65 sec >> Linux, Pypy 5.1 (32-bit): 1.06 sec / 0.64 sec >> Windows, Pypy 5.4.1 (32-bit): 5.59 sec / 2.87 sec >> >> >> What could cause such a huge difference? > > Dunno if it's the cause or not, but you're running a 32-bit PyPy on a > 64-bit Windows. I could well imagine that that has some odd > significance. > > ChrisA Perhaps. Though I can't really imagine what's going on there then. The one on Linux is 32 bits as well and it's also much faster... Unfortunately there's no 64 bits pypy expected for windows, so I can't test that Irmen From rosuav at gmail.com Tue Sep 20 18:59:15 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Sep 2016 08:59:15 +1000 Subject: pypy on windows much slower than linux/mac when using complex number type? In-Reply-To: <57e1bd41$0$881$e4fe514c@news.xs4all.nl> References: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> <57e1bd41$0$881$e4fe514c@news.xs4all.nl> Message-ID: On Wed, Sep 21, 2016 at 8:50 AM, Irmen de Jong wrote: >> Dunno if it's the cause or not, but you're running a 32-bit PyPy on a >> 64-bit Windows. I could well imagine that that has some odd >> significance. >> >> ChrisA > > > Perhaps. Though I can't really imagine what's going on there then. The one on Linux is > 32 bits as well and it's also much faster... > Unfortunately there's no 64 bits pypy expected for windows, so I can't test that Yeah, but the Linux one is running in a 32-bit OS. I don't know how the "32-bit on 64-bit" subsystem of Windows works and how fast it is; it could be that the thunking defeats some optimizations relating to floating-point. Who knows. Hard to test. ChrisA From johnpote at jptechnical.co.uk Tue Sep 20 19:19:56 2016 From: johnpote at jptechnical.co.uk (John Pote) Date: Wed, 21 Sep 2016 00:19:56 +0100 Subject: get the sum of differences between integers in a list In-Reply-To: References: Message-ID: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> On 20/09/2016 12:52, Daiyue Weng wrote: > Hi, I have a list numbers say, > > [1,2,3,4,6,8,9,10,11] > > First, I want to calculate the sum of the differences between the numbers > in the list. At least for this first part a little pencil, paper and algebra yields a simple formula of constant and minimal calculation time. I had an intuitive guess and wrote down the sum of differences for a couple of examples, [1, 2, 5] => 4 [9, 11, 17, 19] => 10 It works for negative differences as well, [1, 2, 5, 1] => 0 The trick is to spot the relation between the sum of differences and the numbers in the list. A few lines of algebra then gave a very simple formula. As for the rest it's down to code as others have hinted at. > Second, if a sequence of numbers having a difference of 1, put them in a > list, i.e. there are two such lists, > > [1,2,3] > > [8,9,10,11] > > and also put the rest numbers in another list, i.e. there is only one such > list in the example, > > [6]. > > Third, get the lists with the max/min sizes from above, i.e. in this > example, the max list is, > > [8,9,10,11] > > min list is > > [1,2,3]. > > What's the best way to implement this? > > cheers From doctor at doctor.nl2k.ab.ca Tue Sep 20 19:20:09 2016 From: doctor at doctor.nl2k.ab.ca (The Doctor) Date: Tue, 20 Sep 2016 23:20:09 -0000 (UTC) Subject: How to install Python.h on FreeBSD 10.3-RELEASE? References: <20160919a@crcomp.net> <20160920a@crcomp.net> <20160920c@crcomp.net> Message-ID: In article <20160920c at crcomp.net>, Don Kuenz wrote: > >The Doctor wrote: >> In article <20160920a at crcomp.net>, Don Kuenz wrote: >>> >>>It turns out that the question isn't "How to install Python.h?" The >>>question is "Why doesn't make find Python.h?" >>> >>>------------------------------------------------------------------------ >>> >>># uname -v >>>FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 >>> >>># cd / >>># find . -name 'Python.h' >>>/usr/local/include/python2.7/Python.h >>>/usr/local/include/python3.4m/Python.h >>> >>>------------------------------------------------------------------------ > > > >>> >>>It seems that a symbolic link may be needed. Fortunately the developer >>>is working with me on this problem. He may know the best way to proceed. >> >> Which version of Python do you wish to use? > >It's best for me to know how to use either version. It's OK if each >version is mutually exclusive. > >Thank you, > >-- >Don Kuenz KB7RPU > > Every tool carries with it the spirit by which it has been created. > - Heisenberg python --version. -- Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca God,Queen and country!Never Satan President Republic!Beware AntiChrist rising! http://www.fullyfollow.me/rootnl2k Look at Psalms 14 and 53 on Atheism Time for the USA to hold a referendum on its republic and vote to dissolve!! From ckaynor at zindagigames.com Tue Sep 20 19:20:23 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 20 Sep 2016 16:20:23 -0700 Subject: pypy on windows much slower than linux/mac when using complex number type? In-Reply-To: References: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> <57e1bd41$0$881$e4fe514c@news.xs4all.nl> Message-ID: On Tue, Sep 20, 2016 at 3:59 PM, Chris Angelico wrote: > On Wed, Sep 21, 2016 at 8:50 AM, Irmen de Jong > wrote: > >> Dunno if it's the cause or not, but you're running a 32-bit PyPy on a > >> 64-bit Windows. I could well imagine that that has some odd > >> significance. > >> > >> ChrisA > > > > > > Perhaps. Though I can't really imagine what's going on there then. The > one on Linux is > > 32 bits as well and it's also much faster... > > Unfortunately there's no 64 bits pypy expected for windows, so I can't > test that > > Yeah, but the Linux one is running in a 32-bit OS. I don't know how > the "32-bit on 64-bit" subsystem of Windows works and how fast it is; > it could be that the thunking defeats some optimizations relating to > floating-point. Who knows. Hard to test. > WoW64 shouldn't have any measurable speed decrease. I've run plenty of 32-bit games on a 64-bit Windows (many games are still 32-bit only), and they always perform fine, regardless of whether they are CPU or GPU bound based off the profiling I've done. I think most of the cost is paid in the context switches. Regarding the performance decrease, it may be worthwhile to push the report to a PyPy specific forum - a PyPy developer will probably see it here, but you may get a faster response on a forum specific to PyPy. From m at funkyhat.org Tue Sep 20 19:52:57 2016 From: m at funkyhat.org (Matt Wheeler) Date: Tue, 20 Sep 2016 23:52:57 +0000 Subject: how to automate java application in window using python In-Reply-To: <4f73483a-6618-464a-a2a2-038b1965765a@googlegroups.com> References: <4f73483a-6618-464a-a2a2-038b1965765a@googlegroups.com> Message-ID: On Tue, 20 Sep 2016, 02:47 meInvent bbird, wrote: > can it contorl Maplesoft's maple which is a java executable file? > I don't know maple so I can't answer that. Which programming language an application is written in isn't really relevant for pywinauto, it's the graphical toolkit in use which will make a difference. >From the one screenshot I found during a quick look at the Maplesoft site, it looks like maple is using a toolkit which presents native Win32 GUI API controls, so my *guess* is that it will work, but you'll have to try it to find out. I would suggest installing pywinauto and importing it in an interactive python shell... >>> import pywinauto >>> maple = pywinauto.application.Application().start('maple') >>> maple.Maple.PrintControlIdentifiers() This will output every control on the window named "Maple" which belongs to the 'maple' executable which was launched in the step before. If it outputs lots of stuff you're in luck, you now get to dig through that output to find the controls you're interested in :) > From steve+python at pearwood.info Tue Sep 20 20:16:05 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 10:16:05 +1000 Subject: Idiomatic code validator? References: <20160920154140.GC559@mail.akwebsoft.com> Message-ID: <57e1d148$0$1590$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 01:41 am, Tim Johnson wrote: > Not to confuse idiomatic code validation with pep8 validation (I use > elpy on emacs) > > Is there such a thing as a validator for _idiomatic_ code? Yes, it is called a linter. There are various linters available: pylint, pychecker, jedi, flake there may be others. Depending on how good the linter is, they will do things like flag unused arguments, dead code, use of deprecated features, and so forth. Some of them may be very opinionated, e.g. flag uses of map() as unidiomatic and recommend a list comprehension instead. Whether you agree with that opinion or not is up to you. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 20 20:27:01 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 10:27:01 +1000 Subject: list or dictionary References: Message-ID: <57e1d3d7$0$1621$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 04:04 am, Ganesh Pal wrote: > I am on python 2.7 and Linux > > I have the stdout in the below form , I need to write a function to get > hostname for the given id. > > > Example: > >>>> stdout > 'hostname-1 is array with id 1\nhostname-2 is array with id 2\nhostname-3 > is array with id 3\n' > > > def get_hostname(id) > return id > > what's a better option here > > 1. store it in list and grep for id and return > 2. store it in dict as key and value i.e hostname = { 'hostname1': 1} and > return key > 3. any other simple options. Why don't you write a function for each one, and see which is less work? # Version 1: store the hostname information in a list as strings hostnames = ['hostname-1 is array with id 1', 'hostname-2 is array with id 2', 'hostname-842 is array with id 842'] def get_hostname(id): for line in hostnames: regex = r'(.*) is array with id %d' % id mo = re.match(regex, line) if mo is not None: return mo.group(1) raise ValueError('not found') # Version 2: store the hostname information in a dict {hostname: id} hostnames = {'hostname1': 1, 'hostname2': 2, 'hostname842': 842} def get_hostname(id): for key, value in hostnames.items(): if value == id: return key raise ValueError('not found') # Version 3: use a dict the way dicts are meant to be used hostnames = {1: 'hostname1', 2: 'hostname2', 842: 'hostname842'} def get_hostname(id): return hostnames[id] -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From dvl at psu.edu Tue Sep 20 20:31:44 2016 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Tue, 20 Sep 2016 20:31:44 -0400 Subject: Linear Time Tree Traversal Generator In-Reply-To: CAO1D73Eho37guUZkM6Kk9Nu5WB43oN721G33XGNis0LhSu7xVQ@mail.gmail.com References: <1474389964l.34341004l.0l@psu.edu> Message-ID: <1474417903l.21561510l.0l@psu.edu> On Tue, Sep 20, 2016 at 9:46 AM, ROGER GRAYDON CHRISTMAN <dvl at psu.edu> wrote: >I am trying to find a better (i.e. more efficient) way to implement a generator > that traverses a tree. > > The current model of the code (which is also used by a textbook I am teaching > from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running time, > since > values from the leaves of the tree have to be yielded multiple times to the top > of the tree. > Justin Walters responded: > Are the left and right attributes collections of more nodes or are they simply references to the node's position in the tree? > From the code provided it seems like the former is true and a node's left attribute is a reference to another node? They are references to other nodes, which in turn have values and left and right references to more nodes, etc. as in a particular tree. There are no 'collections' in the sense of set or map or Python list, just recursive sub-trees. > I don't know how flexible you are with the structure of your tree, but you could try taking the modified pre-order tree traversal approach. > This article explains it in the context of a database, but the idea is the same: > Each node would then have a parent attribute as well as left and right attributes. The parent would be a reference to a parent node, and the left and right would be integers that position the element in the tree. > The upside to this is that traversal and lookup is much faster since you do not need to have an iterator nested in an iterator. This is because the top level node will always have the lowest integer as it's left attribute and the highest integer as it's right attribute. That means that you can instead have a single iterator that iterates through a range of integers to yield the node with the specified left and right values. I am in academia, and the current unit is the binary search tree in its conventional sense, instead of the tabular version. Indeed that table would be faster for iteration, but at the increased cost of slowing down adding and removing elements. If I were to use any array-based model, as this database link shows, all insertions and deletions would be linear-time operations instead of logarithmic time. I would contrast the time to insert N elements and then to traverse the tree once, where the N elements arrive in any order: Tabular approach N linear-time insertions -> quadratic time plus a linear-time tree traversal afterwards. Tree approach: N logarithm-time insertions plus an iteration that takes a time proportional to all that -- it still wins. Since traversal is 'rare', I don't want to penalize the common behaviors to accelerate this traversal. But I would still like to see if there is a linear traversal possible with the help if the itertools chain Roger Christman instructor Pennsylvania State University From steve+python at pearwood.info Tue Sep 20 20:48:06 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 10:48:06 +1000 Subject: automated comparison tool References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> Message-ID: <57e1d8c9$0$1595$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 07:20 am, Andrew Clark wrote: > I've restarted my code so many times i no longer have a working version of > anything. *Restarting* your code doesn't change it and cannot possibly stop it from working. My guess is that you actually mean that you've made so many random edits to your code, without understanding or thinking about what you are doing, that you've broken it irreversibly. I think you've learned a few things: (1) Debugging by making random perturbations to code should be a last resort, and even then, only done with the greatest of care. (2) Use version control so you can roll back changes. (3) Or at least make a backup copy of a known working version of your code. (4) Most importantly, never make so many changes to your ONLY copy of the code in one go that you can break it so badly that you can't go back. You've described your problem quite well, and nicely broken it up into pieces. I suggest you take each piece, and try to write the code for it independently of the others. Start with the first piece: "access remote directories" Okay, how are they accessible? Are they just network drives? Then that's simple: you can access them as if they were local directories. What's the path name of the network drive(s)? Simply use that. Problem solved. If not, then you need to decide how to access them: over SSH, FTP, sneaker-net, whatever. The choice you make here is going to impact the complexity of your code. Think about carefully. Once you have working code that can list the remote directory, you can use it to list your three sets of files: startupfiles = listdir(...StartupConfig) runningfiles = listdir(...RunningConfig) archivefiles = listdir(...ArchiveConfig) now you can move onto step 2: "run through startup, running and archive to find files with same hostname(do this for all files)" Now you can forget all about remote file systems (at least for now) and just work with the three lists of file names. How do you decide which files belong to which file name? I don't know, because you don't say. Is the hostname in the file name? Or do you have to open the file and read the information from the file contents? However you do it, start by generating a mapping of hostname: list of file names. mapping = {} for filename in list_of_filenames: hostname = get_hostname(filename) if hostname in mapping: mapping[hostname].append(filename) else: mapping[hostname] = [filename] # start a new list with one entry Once you've done that for all three directories, then you can collect all the file names for each host from all three directories, and compare the files. I leave the rest of the exercise to you, but remember the principle of Divide And Conquer. Divide the problem into smaller problems which are easy to solve, solve each small problem, and the big problem solves itself. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tim at akwebsoft.com Tue Sep 20 21:24:09 2016 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 20 Sep 2016 17:24:09 -0800 Subject: Idiomatic code validator? In-Reply-To: <57e1d148$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <20160920154140.GC559@mail.akwebsoft.com> <57e1d148$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160921012409.GE559@mail.akwebsoft.com> * Steve D'Aprano [160920 16:29]: > On Wed, 21 Sep 2016 01:41 am, Tim Johnson wrote: > > > Not to confuse idiomatic code validation with pep8 validation (I use > > elpy on emacs) > > > > Is there such a thing as a validator for _idiomatic_ code? > > > Yes, it is called a linter. There are various linters available: > > pylint, pychecker, jedi, flake thanks Steve : I use flake8 thru elpy. I'm guessing that my inquiry is redundant. (I might need to look at more fine-grained configuration thru elpy) cheers - tj - > > there may be others. Depending on how good the linter is, they will do > things like flag unused arguments, dead code, use of deprecated features, > and so forth. Some of them may be very opinionated, e.g. flag uses of map() > as unidiomatic and recommend a list comprehension instead. Whether you > agree with that opinion or not is up to you. > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim http://www.akwebsoft.com, http://www.tj49.com From tim at akwebsoft.com Tue Sep 20 21:26:28 2016 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 20 Sep 2016 17:26:28 -0800 Subject: Idiomatic code validator? In-Reply-To: <57e1d148$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <20160920154140.GC559@mail.akwebsoft.com> <57e1d148$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160921012628.GF559@mail.akwebsoft.com> * Steve D'Aprano [160920 16:29]: > On Wed, 21 Sep 2016 01:41 am, Tim Johnson wrote: > > > Not to confuse idiomatic code validation with pep8 validation (I use > > elpy on emacs) > > > > Is there such a thing as a validator for _idiomatic_ code? > > > Yes, it is called a linter. There are various linters available: > > pylint, pychecker, jedi, flake > > > there may be others. Depending on how good the linter is, they will do > things like flag unused arguments, dead code, use of deprecated features, > and so forth. Some of them may be very opinionated, e.g. flag uses of map() > as unidiomatic and recommend a list comprehension instead. Whether you > agree with that opinion or not is up to you. Sorry. Should have added this: It might be useful for me to use a more "opinionated" linter outside of my "IDE". cheers > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. :) Again. Sorry! -- Tim http://www.akwebsoft.com, http://www.tj49.com From lawrencedo99 at gmail.com Tue Sep 20 21:55:06 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 20 Sep 2016 18:55:06 -0700 (PDT) Subject: automated comparison tool In-Reply-To: References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> Message-ID: <30a6231d-10a6-45d7-8dae-16890ed6ea6f@googlegroups.com> On Wednesday, September 21, 2016 at 12:14:54 PM UTC+12, Bill Deegan wrote: > Use Git... at least you get can back what used to work.. That has become such a matter of programming habit, taken so much for granted that, to me, it?s like saying ?don?t forget to breathe?. :) From steve+python at pearwood.info Tue Sep 20 22:34:13 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 12:34:13 +1000 Subject: Linear Time Tree Traversal Generator References: <1474389964l.34341004l.0l@psu.edu> Message-ID: <57e1f1a6$0$1583$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 02:46 am, ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a > generator that traverses a tree. > > The current model of the code (which is also used by a textbook I am > teaching from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running > time, since > values from the leaves of the tree have to be yielded multiple times to > the top of the tree. I'm afraid I don't understand this. This is a standard binary tree inorder traversal. Each node is visited once, and there are N nodes, so I make that out to be O(N) not O(N log N). I'm afraid I can't parse your final clause: "since values from the leaves of the tree have to be yielded multiple times to the top of the tree" Each leaf is yielded once, and I don't understand what you mean by yielding to the top of the tree. I thought that maybe I missed something obvious, so I knocked up a quick and dirty tree structure, monkey-patched the iter() built-in to count how many times it was called, and ran your traversal code. Here's my code: # ----- cut ----- class Node: def __init__(self, value): self._left = [] # Sentinel for an empty leaf. self._right = [] self._value = value def __iter__(node): # By the way, you don't have to explicitly call iter() here. for x in iter(node._left): yield x yield node._value for x in iter(node._right): yield x def insert(tree, value): if value < tree._value: if tree._left == []: # add new leaf node tree._left = Node(value) else: insert(tree._left, value) elif value > tree._value: if tree._right == []: tree._right = Node(value) else: insert(tree._right, value) data = list(range(10000)) import random random.shuffle(data) tree = Node(data[0]) for value in data[1:]: insert(tree, value) _iter = iter # grab a reference to the built-in count = 0 def iter(obj): # Monkey-patch the built-in global count count += 1 return _iter(obj) assert list(tree) == sorted(data) print(count) # ----- cut ----- which prints 20000, as expected: for each node, iter() gets called twice. So I don't understand where your O(N log N) behaviour is coming from. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From random832 at fastmail.com Tue Sep 20 22:44:01 2016 From: random832 at fastmail.com (Random832) Date: Tue, 20 Sep 2016 22:44:01 -0400 Subject: Linear Time Tree Traversal Generator In-Reply-To: <57e1f1a6$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <1474389964l.34341004l.0l@psu.edu> <57e1f1a6$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1474425841.1718677.732130209.67D92E72@webmail.messagingengine.com> On Tue, Sep 20, 2016, at 22:34, Steve D'Aprano wrote: > I'm afraid I don't understand this. This is a standard binary tree > inorder traversal. Each node is visited once, and there are N nodes, > so I make that out to be O(N) not O(N log N). I'm afraid I can't parse > your final clause: > > "since values from the leaves of the tree have to be yielded > multiple times to the top of the tree" > > Each leaf is yielded once, and I don't understand what you mean by > yielding to the top of the tree. His point is that in order for the top-level iterator to return a given node there's a yield call in the top level's iterator , that calls the next level's iterator's yield, that calls the next one, so on, in a call stack log(n) levels deep. From rosuav at gmail.com Tue Sep 20 22:47:18 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Sep 2016 12:47:18 +1000 Subject: Linear Time Tree Traversal Generator In-Reply-To: <57e1f1a6$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <1474389964l.34341004l.0l@psu.edu> <57e1f1a6$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 21, 2016 at 12:34 PM, Steve D'Aprano wrote: > "since values from the leaves of the tree have to be yielded > multiple times to the top of the tree" > > Each leaf is yielded once, and I don't understand what you mean by yielding > to the top of the tree. Ultimately, yes. But AIUI he's talking about this: def leaf(): yield 42 def intermediate(): yield next(leaf()) def root(): yield next(intermediate()) The value 42 gets "passed up the chain" until it gets to the top. IMO the cost of that should be dwarfed by the actual work of whatever's doing the traversal, but it is potentially a cost. And 'yield from', being a single opcode, is potentially optimizable (and I believe CPython does optimize long yield-from chains), so there's no good reason not to use it - more readable AND potentially faster. ChrisA From gengyangcai at gmail.com Tue Sep 20 23:00:55 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 20 Sep 2016 20:00:55 -0700 (PDT) Subject: Data Types Message-ID: So I am going through chapter 7.1 (Data Types) of http://programarcadegames.com/index.php? What do these terms (input and output) mean --- Can someone explain in plain English and layman's terms ? Thanks a lot ... >>> type(3) >>> type(3.145) >>> type("Hi there") >>> type(True) From steve+python at pearwood.info Tue Sep 20 23:17:22 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 13:17:22 +1000 Subject: Linear Time Tree Traversal Generator References: <1474389964l.34341004l.0l@psu.edu> <57e1f1a6$0$1583$c3e8da3$5496439d@news.astraweb.com> <1474425841.1718677.732130209.67D92E72@webmail.messagingengine.com> Message-ID: <57e1fbc3$0$1600$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 12:44 pm, Random832 wrote: > On Tue, Sep 20, 2016, at 22:34, Steve D'Aprano wrote: >> I'm afraid I don't understand this. This is a standard binary tree >> inorder traversal. Each node is visited once, and there are N nodes, >> so I make that out to be O(N) not O(N log N). I'm afraid I can't parse >> your final clause: >> >> "since values from the leaves of the tree have to be yielded >> multiple times to the top of the tree" >> >> Each leaf is yielded once, and I don't understand what you mean by >> yielding to the top of the tree. > > His point is that in order for the top-level iterator to return a given > node there's a yield call in the top level's iterator , that calls the > next level's iterator's yield, that calls the next one, so on, in a call > stack log(n) levels deep. Right. That's the whole point of a binary search tree. An unbalanced binary tree may be as deep as N, but a balanced one, or a random unbalanced one, is only log N deep. log N is a long way from N log N. I don't see what is the actual problem we are being asked to solve. Is it the stack space needed to walk the tree? The time taken? The Original Poster said: "O(n log n) running time" so I don't think the O(log N) stack space used is relevant. In a practical sense, the right way to solve this problem is to not use a tree in the first place. But presumably the OP is using this for teaching about trees, not as production software. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 20 23:22:31 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 13:22:31 +1000 Subject: Data Types References: Message-ID: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 01:00 pm, Cai Gengyang wrote: > So I am going through chapter 7.1 (Data Types) of > http://programarcadegames.com/index.php? What do these terms (input and > output) mean --- Can someone explain in plain English and layman's terms ? http://www.dictionary.com/browse/input http://www.dictionary.com/browse/output Does that answer your question about "input and output"? > Thanks a lot ... > >>>> type(3) > >>>> type(3.145) > >>>> type("Hi there") > >>>> type(True) > I don't understand why you are showing this. What part don't you understand? The number 3 is an int (short for integer); that is the type of value it is. 5 is also an int, and 0, and 9253, and -73. They are all integers. 3.145 is a float (short for "floating point number"). "Hi there" is a str (short for string). True is a bool (short for Boolean value, which is a technical term for special True/False values). Perhaps if you can ask a more clear question, I can give a more clear answer. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 20 23:34:35 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 13:34:35 +1000 Subject: Linear Time Tree Traversal Generator References: <1474389964l.34341004l.0l@psu.edu> Message-ID: <57e1ffcd$0$22142$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 02:46 am, ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a > generator that traverses a tree. > > The current model of the code (which is also used by a textbook I am > teaching from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running > time, since > values from the leaves of the tree have to be yielded multiple times to > the top of the tree. > > Now, I could certainly implement a linear-time traversal without the > gnerator: > > def to_list(node,result): > """append node information to result""" > result = to_list(node._left, result) > result.append(node._value) > return to_list(node,_right, result) I forgot to ask... How to you reason that this is O(N) time if the same algorithm above is supposedly O(N log N)? They're both the same algorithm, with the same performance characteristics. They differ only that the __iter__ version yields the items one at a time, while the to_list version accumulates them into a list all at once. But they walk the tree in the same way, touch the same number of nodes, generate the same depth of calling stack. You can re-write to_list as: def to_list(node): result = [] for value in node: # calls __iter__ method above result.append(node) return result One of us is badly missing something. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 20 23:36:06 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 21 Sep 2016 13:36:06 +1000 Subject: Linear Time Tree Traversal Generator References: <1474389964l.34341004l.0l@psu.edu> <57e1f1a6$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57e20027$0$22142$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 12:47 pm, Chris Angelico wrote: > On Wed, Sep 21, 2016 at 12:34 PM, Steve D'Aprano > wrote: >> "since values from the leaves of the tree have to be yielded >> multiple times to the top of the tree" >> >> Each leaf is yielded once, and I don't understand what you mean by >> yielding to the top of the tree. > > Ultimately, yes. But AIUI he's talking about this: > > def leaf(): > yield 42 > def intermediate(): > yield next(leaf()) > def root(): > yield next(intermediate()) I don't see that in the OP's code. Nor do I understand where this would be used. Surely root should be the root of the tree, not a function that walks a linear chain to yield the bottom of the chain? > The value 42 gets "passed up the chain" until it gets to the top. How else do you expect to get to the bottom of the chain starting from the top except by traversing the chain? If you don't want to traverse the chain, then don't start at the top. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ldlchina at gmail.com Tue Sep 20 23:47:11 2016 From: ldlchina at gmail.com (dl l) Date: Wed, 21 Sep 2016 11:47:11 +0800 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module In-Reply-To: References: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> Message-ID: Thank you all for the help. I found the problem is resolved if call PyGC_Collect() after PyDict_DelItemString(). Is it expected to call PyGC_Collect() here for Python 3.5 which is not needed for Python 3.3? 2016-09-20 16:01 GMT+08:00 Chris Angelico : > On Tue, Sep 20, 2016 at 4:19 PM, dl l wrote: > > Yes, it's a workaround to set the global variables to None. But My app > just > > provide a framework for my customers to run python scripts. That's means > > the workaround requires my customers to update their python scripts. That > > may make them unhappy :(. Is there a workaround in my code C++ side to > call > > Python C APIs to resolve the memory leak issue? > > > > Python's import system is fundamentally not designed for what I > believe is your use-case here, of running potentially-edited user > code. Instead, I suggest keeping 'import' for stable modules that > don't get updated without restarting the process, and for the more > dynamic code, build something using exec (or PyRun_StringFlags, which > I believe is the C equivalent). Object lifetimes will then be entirely > under your control. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From gengyangcai at gmail.com Wed Sep 21 00:03:40 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 20 Sep 2016 21:03:40 -0700 (PDT) Subject: Data Types In-Reply-To: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> On Wednesday, September 21, 2016 at 11:22:42 AM UTC+8, Steve D'Aprano wrote: > On Wed, 21 Sep 2016 01:00 pm, Cai Gengyang wrote: > > > So I am going through chapter 7.1 (Data Types) of > > http://programarcadegames.com/index.php? What do these terms (input and > > output) mean --- Can someone explain in plain English and layman's terms ? > > http://www.dictionary.com/browse/input > > http://www.dictionary.com/browse/output > > > Does that answer your question about "input and output"? > > > > Thanks a lot ... > > > >>>> type(3) > > > >>>> type(3.145) > > > >>>> type("Hi there") > > > >>>> type(True) > > > > I don't understand why you are showing this. What part don't you understand? > > The number 3 is an int (short for integer); that is the type of value it is. > 5 is also an int, and 0, and 9253, and -73. They are all integers. > > 3.145 is a float (short for "floating point number"). "Hi there" is a str > (short for string). True is a bool (short for Boolean value, which is a > technical term for special True/False values). > > Perhaps if you can ask a more clear question, I can give a more clear > answer. > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. Right, So for example for "bool" , it only applies to True/False and nothing else? (2 data types), i.e. : >>> type(True) >>> type(False) Are there any other data types that will give you type(A) or type(B) = besides True and False? Regards, GY From random832 at fastmail.com Wed Sep 21 00:15:54 2016 From: random832 at fastmail.com (Random832) Date: Wed, 21 Sep 2016 00:15:54 -0400 Subject: Linear Time Tree Traversal Generator In-Reply-To: <57e1ffcd$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <1474389964l.34341004l.0l@psu.edu> <57e1ffcd$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1474431354.1742455.732170745.31D23472@webmail.messagingengine.com> On Tue, Sep 20, 2016, at 23:34, Steve D'Aprano wrote: > One of us is badly missing something. The problem is the number of times next is called. Here, it'll be more clear if we wrap the iterator in the original example to print each time next is called. class WrappedIterator(): def __init__(self, orig, reference): self.orig = orig self.ref = reference def __iter__(self): return self def __next__(self): desc = "next for " + self.ref try: result = next(self.orig) print(desc, '=', result) return result except StopIteration: print(desc, "StopIteration") raise class Node: def __init__(self, value, left=None, right=None): self._value = value self._left = left self._right = right def _iter(node): if node._left: for x in iter(node._left): yield x yield node._value if node._right: for x in iter(node._right): yield x def __iter__(self): return WrappedIterator(self._iter(), 'Node %r' % self._value) node1 = Node(1) node3 = Node(3) node2 = Node(2, node1, node3) node5 = Node(5) node7 = Node(7) node6 = Node(6, node5, node7) node4 = Node(4, node2, node6) for value in node4: print("Got value %r" % (value,)) ---output--- next for Node 1 = 1 next for Node 2 = 1 next for Node 4 = 1 Got value 1 next for Node 1 StopIteration next for Node 2 = 2 next for Node 4 = 2 Got value 2 next for Node 3 = 3 next for Node 2 = 3 next for Node 4 = 3 Got value 3 next for Node 3 StopIteration next for Node 2 StopIteration next for Node 4 = 4 Got value 4 next for Node 5 = 5 next for Node 6 = 5 next for Node 4 = 5 Got value 5 next for Node 5 StopIteration next for Node 6 = 6 next for Node 4 = 6 Got value 6 next for Node 7 = 7 next for Node 6 = 7 next for Node 4 = 7 Got value 7 next for Node 7 StopIteration next for Node 6 StopIteration next for Node 4 StopIteration ------ You can see that next is called three times (log N) for each value returned. It's not about the stack space, it's about going up and down the stack over and over. From dieter at handshake.de Wed Sep 21 01:09:45 2016 From: dieter at handshake.de (dieter) Date: Wed, 21 Sep 2016 07:09:45 +0200 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module References: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> Message-ID: <874m59x2hy.fsf@handshake.de> dl l writes: > I found the problem is resolved if call PyGC_Collect() after > PyDict_DelItemString(). Is it expected to call PyGC_Collect() here for > Python 3.5 which is not needed for Python 3.3? Usually, Python uses reference counting to determine when an object can be deleted (and then reclaims its memory). However, reference counting cannot determine an object's obsoleteness when it is involved in a reference cycle. To address most of these cases, Python has an alternative way to determine object obsoleteness based on marking the accessible objects and garbage collecting what is inaccessible. The alternative way is what "PyGC_collect" starts. If part of the objects where involved in a reference cycle, you would have to call "PyGC_collect" also in Python 3.3 in order to get a (mostly) clean memory state. It might be, that Python 3.5 introduces more cycles than Python 3.3. However, more likely, your code was responsible for the cycle creation (and not Python itself). Likely, you just did not notice the problem back for Python 3.3. Note that "PyGC_collect", too, is not garanteed to give a memory clean state. It does not release object cycles involving objects with an explicite destructor ("__del__" method). Those cycles are made available to the application (consult the documentation of the "gc" module) which can then decide what to do about them (e.g. break the cycles and release the associated objects). From steve+comp.lang.python at pearwood.info Wed Sep 21 01:21:16 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 21 Sep 2016 15:21:16 +1000 Subject: Data Types References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> Message-ID: <57e218ce$0$11118$c3e8da3@news.astraweb.com> On Wednesday 21 September 2016 14:03, Cai Gengyang wrote: > So for example for "bool" , it only applies to True/False and nothing else? Correct. True and False are the only instances of the type 'bool'. > (2 data types), i.e. : > >>>> type(True) > >>>> type(False) > > > Are there any other data types that will give you type(A) or type(B) = 'bool'> besides True and False? No. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From greg.ewing at canterbury.ac.nz Wed Sep 21 02:04:52 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 21 Sep 2016 18:04:52 +1200 Subject: Cython taking more time than regular Python In-Reply-To: References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: Christian Gollwitzer wrote: > However, I'm not convinced it did succeed here. An evaluation of the > Gau? formula would run in a few *nanoseconds* on any moddern machine. It > may take a microsecond to call a functino from Python. a hundred > microseconds means that the loop does run. Obviously the compiler used was a "dump" compiler. :-) -- Greg From ldlchina at gmail.com Wed Sep 21 02:16:08 2016 From: ldlchina at gmail.com (dl l) Date: Wed, 21 Sep 2016 14:16:08 +0800 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module In-Reply-To: <874m59x2hy.fsf@handshake.de> References: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> <874m59x2hy.fsf@handshake.de> Message-ID: I understood call PyGC_collect to release object cycles. But in my python test code, seems there is NO reference cycle on the Simple object in the python test code. Why needs to call PyGC_Collect() here? ========================================================= class Simple: def __init__( self ): print('Simple__init__') def __del__( self ): print('Simple__del__') simple = None def run(): global simple simple = Simple() if __name__ == '__main__': run() ============================================================== 2016-09-21 13:09 GMT+08:00 dieter : > dl l writes: > > I found the problem is resolved if call PyGC_Collect() after > > PyDict_DelItemString(). Is it expected to call PyGC_Collect() here for > > Python 3.5 which is not needed for Python 3.3? > > Usually, Python uses reference counting to determine when an object > can be deleted (and then reclaims its memory). > However, reference counting cannot determine an object's obsoleteness > when it is involved in a reference cycle. To address most of these > cases, Python has an alternative way to determine object obsoleteness > based on marking the accessible objects and garbage collecting > what is inaccessible. The alternative way is what "PyGC_collect" starts. > > If part of the objects where involved in a reference cycle, > you would have to call "PyGC_collect" also in Python 3.3 in order > to get a (mostly) clean memory state. > It might be, that Python 3.5 introduces more cycles than Python 3.3. > However, more likely, your code was responsible for the cycle creation > (and not Python itself). Likely, you just did not notice the problem > back for Python 3.3. > > Note that "PyGC_collect", too, is not garanteed to give a memory clean > state. It does not release object cycles involving objects with > an explicite destructor ("__del__" method). Those cycles are > made available to the application (consult the documentation of the > "gc" module) which can then decide what to do about them > (e.g. break the cycles and release the associated objects). > > -- > https://mail.python.org/mailman/listinfo/python-list > From bezenchu at gmail.com Wed Sep 21 04:06:57 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 01:06:57 -0700 (PDT) Subject: csjark module Message-ID: After setting up csjark (http://csjark.readthedocs.io/), I'm trying to test on of my C header files which has following statements: typedef struct { unsigned long X; __int64 Y; } abc; If I'm changing __int64 to unsigned long I'm not getting this error For the __int64 i'm getting the mention error. Am I missing something? In addition, I'm getting following error: Attribute error("'tuple object has no attibute 'children'",) I'd be glad to have some assistance. From __peter__ at web.de Wed Sep 21 06:13:29 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Sep 2016 12:13:29 +0200 Subject: csjark module References: Message-ID: bezenchu at gmail.com wrote: > After setting up csjark (http://csjark.readthedocs.io/), I'm trying to > test on of my C header files which has following statements: > > typedef struct { > unsigned long X; > __int64 Y; > } abc; > > > If I'm changing __int64 to unsigned long I'm not getting this error > For the __int64 i'm getting the mention error. Am I missing something? > > > In addition, I'm getting following error: > Attribute error("'tuple object has no attibute 'children'",) > > I'd be glad to have some assistance. It looks like development of csjark has stopped in 2011. Try installing a pycparser version from that time frame -- 2.05 should be a good candidate according to so if you are using pip after $ pip install pycparser==2.05 csjark might work. From ned at nedbatchelder.com Wed Sep 21 07:11:50 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 21 Sep 2016 04:11:50 -0700 (PDT) Subject: Linear Time Tree Traversal Generator In-Reply-To: References: <1474389964l.34341004l.0l@psu.edu> Message-ID: <78930fe7-0c57-45f7-b1ee-bc394e4ded06@googlegroups.com> On Tuesday, September 20, 2016 at 12:48:55 PM UTC-4, ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a generator > that traverses a tree. > > The current model of the code (which is also used by a textbook I am teaching > from does this) > > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x > > This is nice, simple, and straightforward, but has an O(n log n) running time, > since > values from the leaves of the tree have to be yielded multiple times to the top > of the tree. > > Now, I could certainly implement a linear-time traversal without the gnerator: > > def to_list(node,result): > """append node information to result""" > result = to_list(node._left, result) > result.append(node._value) > return to_list(node,_right, result) > > but then that requires the extra memory space to build the list into, which > is basically what the generator is supposed to avoid. > > Now, I did see that itertools has a chain method for concatenating > iterators, so it would be nice to concatenate the results from the > recursive calls without the for loops, but I have no idea how to > squeeze the 'yield node._value' in between them. > > Is there hope for a linear-time tree-traversal generator, or will > I have just have to settle for an n-log-n generator or a linear time > behavior with linear extra space? Another option is linear time, log-n space, by using an explicit stack in your iterator: def __iter__(self): cur = self stack = [] while True: if cur: stack.append(cur) cur = cur._left elif not stack: break else: cur = stack.pop() yield cur._value cur = cur._right This replaces the Python call stack with a list variable which tracks parent nodes we haven't yet iterated, so it will grow as log-n. There's no Python recursion, so each yield directly produces a value to the caller. --Ned. From bezenchu at gmail.com Wed Sep 21 07:51:05 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 04:51:05 -0700 (PDT) Subject: csjark module In-Reply-To: References: Message-ID: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten wrote: > bezenchu at gmail.com wrote: > > > After setting up csjark (http://csjark.readthedocs.io/), I'm trying to > > test on of my C header files which has following statements: > > > > typedef struct { > > unsigned long X; > > __int64 Y; > > } abc; > > > > > > If I'm changing __int64 to unsigned long I'm not getting this error > > For the __int64 i'm getting the mention error. Am I missing something? > > > > > > In addition, I'm getting following error: > > Attribute error("'tuple object has no attibute 'children'",) > > > > I'd be glad to have some assistance. > > It looks like development of csjark has stopped in 2011. Try installing a > pycparser version from that time frame -- 2.05 should be a good candidate > according to so if > you are using pip after > > $ pip install pycparser==2.05 > > csjark might work. I've installed all the required SW, but still getting the same error From __peter__ at web.de Wed Sep 21 08:16:37 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Sep 2016 14:16:37 +0200 Subject: csjark module References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> Message-ID: bezenchu at gmail.com wrote: > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten wrote: >> bezenchu at gmail.com wrote: >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm trying to >> > test on of my C header files which has following statements: >> > >> > typedef struct { >> > unsigned long X; >> > __int64 Y; >> > } abc; >> > >> > >> > If I'm changing __int64 to unsigned long I'm not getting this error >> > For the __int64 i'm getting the mention error. Am I missing something? >> > >> > >> > In addition, I'm getting following error: >> > Attribute error("'tuple object has no attibute 'children'",) >> > >> > I'd be glad to have some assistance. >> >> It looks like development of csjark has stopped in 2011. Try installing a >> pycparser version from that time frame -- 2.05 should be a good candidate >> according to so >> if you are using pip after >> >> $ pip install pycparser==2.05 >> >> csjark might work. > > I've installed all the required SW, but still getting the same error When you invoke the interactive interpreter what does >>> import pycparser >>> pycparser.__version__ '2.05' produce on your system? From bc at freeuk.com Wed Sep 21 08:25:47 2016 From: bc at freeuk.com (BartC) Date: Wed, 21 Sep 2016 13:25:47 +0100 Subject: Data Types In-Reply-To: <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> Message-ID: On 21/09/2016 05:03, Cai Gengyang wrote: > Are there any other data types that will give you type(A) or type(B) = besides True and False? No types but any variable or expression containing True or False will be a bool type (or class bool): A = 10<20 print (type(A)) => print (10<20) => True print (type(10<20)) => -- Bartc From bezenchu at gmail.com Wed Sep 21 09:43:33 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 06:43:33 -0700 (PDT) Subject: csjark module In-Reply-To: References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> Message-ID: <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten wrote: > bezenchu at gmail.com wrote: > > > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten wrote: > >> bezenchu at gmail.com wrote: > >> > >> > After setting up csjark (http://csjark.readthedocs.io/), I'm trying to > >> > test on of my C header files which has following statements: > >> > > >> > typedef struct { > >> > unsigned long X; > >> > __int64 Y; > >> > } abc; > >> > > >> > > >> > If I'm changing __int64 to unsigned long I'm not getting this error > >> > For the __int64 i'm getting the mention error. Am I missing something? > >> > > >> > > >> > In addition, I'm getting following error: > >> > Attribute error("'tuple object has no attibute 'children'",) > >> > > >> > I'd be glad to have some assistance. > >> > >> It looks like development of csjark has stopped in 2011. Try installing a > >> pycparser version from that time frame -- 2.05 should be a good candidate > >> according to so > >> if you are using pip after > >> > >> $ pip install pycparser==2.05 > >> > >> csjark might work. > > > > I've installed all the required SW, but still getting the same error > > When you invoke the interactive interpreter what does > > >>> import pycparser > >>> pycparser.__version__ > '2.05' > > produce on your system? I have version 2.07 (which is the one used for the development) From bezenchu at gmail.com Wed Sep 21 09:51:37 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 06:51:37 -0700 (PDT) Subject: csjark module In-Reply-To: <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> Message-ID: <02b9a6d8-b09c-4829-83b4-8639442ce17f@googlegroups.com> On Wednesday, September 21, 2016 at 4:43:47 PM UTC+3, beze... at gmail.com wrote: > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten wrote: > > bezenchu at gmail.com wrote: > > > > > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten wrote: > > >> bezenchu at gmail.com wrote: > > >> > > >> > After setting up csjark (http://csjark.readthedocs.io/), I'm trying to > > >> > test on of my C header files which has following statements: > > >> > > > >> > typedef struct { > > >> > unsigned long X; > > >> > __int64 Y; > > >> > } abc; > > >> > > > >> > > > >> > If I'm changing __int64 to unsigned long I'm not getting this error > > >> > For the __int64 i'm getting the mention error. Am I missing something? > > >> > > > >> > > > >> > In addition, I'm getting following error: > > >> > Attribute error("'tuple object has no attibute 'children'",) > > >> > > > >> > I'd be glad to have some assistance. > > >> > > >> It looks like development of csjark has stopped in 2011. Try installing a > > >> pycparser version from that time frame -- 2.05 should be a good candidate > > >> according to so > > >> if you are using pip after > > >> > > >> $ pip install pycparser==2.05 > > >> > > >> csjark might work. > > > > > > I've installed all the required SW, but still getting the same error > > > > When you invoke the interactive interpreter what does > > > > >>> import pycparser > > >>> pycparser.__version__ > > '2.05' > > > > produce on your system? > > I have version 2.07 (which is the one used for the development) some progress I've found for the 2nd problem is that this error is thrown in cparser.py (from the csjark files) in the visit_Enum function of the StructVisitor class. In the .h file I have following definition which tried to be parsed typedef enum{ a=0; b=1; } c; From daiyueweng at gmail.com Wed Sep 21 10:13:38 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Wed, 21 Sep 2016 15:13:38 +0100 Subject: get the sum of differences between integers in a list In-Reply-To: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> References: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> Message-ID: Hi, first of all, let me rephase the problem. For an arbitrary list of integers (the integers in the list are not necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], if a set of consecutive integers having a difference of 1 between them, put them in a list, i.e. there are two such lists in this example, [1,2,3], [8,9,10,11], and then put such lists in another list (i.e. [[1,2,3], [8,9,10,11]]). Put the rest integers (non-sequential) in a separated list, i.e. `[6, 13]`. Note that, the problem only considers sequential integers with step_size = 1. I tried to use itertools.groupby and itertools.count, from itertools import groupby, count lst = [1,2,3,6,8,9,10,11,13] c = count() result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c))] but the result is close to the requirement shown as a list of lists, [[1, 2, 3], [6], [8, 9, 10, 11], [13]] but it didn't separate sequential lists from non-sequential ones. Also, I couldn't find a way to put [6] and [13] in a single list. I have also tried to separate sequential lists from non-sequential ones, result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) == 1)] # tried to extract [1,2,3] and [8,9,10,11] from the list or result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) > 1)] # tried to extract [6] and [13] from the list but they all ended up with [[1, 2, 3], [6, 8, 9, 10, 11, 13]] So two questions here, 1. How does itertools.groupby key function work in my case? 2. How to improve the program to achieve my goals? Many thanks On 21 September 2016 at 00:19, John Pote wrote: > On 20/09/2016 12:52, Daiyue Weng wrote: > > Hi, I have a list numbers say, >> >> [1,2,3,4,6,8,9,10,11] >> >> First, I want to calculate the sum of the differences between the numbers >> in the list. >> > At least for this first part a little pencil, paper and algebra yields a > simple formula of constant and minimal calculation time. I had an intuitive > guess and wrote down the sum of differences for a couple of examples, > [1, 2, 5] => 4 > [9, 11, 17, 19] => 10 > It works for negative differences as well, > [1, 2, 5, 1] => 0 > The trick is to spot the relation between the sum of differences and the > numbers in the list. A few lines of algebra then gave a very simple formula. > > As for the rest it's down to code as others have hinted at. > > Second, if a sequence of numbers having a difference of 1, put them in a >> list, i.e. there are two such lists, >> >> [1,2,3] >> >> [8,9,10,11] >> >> and also put the rest numbers in another list, i.e. there is only one such >> list in the example, >> >> [6]. >> >> Third, get the lists with the max/min sizes from above, i.e. in this >> example, the max list is, >> >> [8,9,10,11] >> >> min list is >> >> [1,2,3]. >> >> What's the best way to implement this? >> >> cheers >> > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Wed Sep 21 10:15:06 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Sep 2016 16:15:06 +0200 Subject: csjark module References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> Message-ID: bezenchu at gmail.com wrote: > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten wrote: >> bezenchu at gmail.com wrote: >> >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten >> > wrote: >> >> bezenchu at gmail.com wrote: >> >> >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm trying >> >> > to test on of my C header files which has following statements: >> >> > >> >> > typedef struct { >> >> > unsigned long X; >> >> > __int64 Y; >> >> > } abc; >> >> > >> >> > >> >> > If I'm changing __int64 to unsigned long I'm not getting this error >> >> > For the __int64 i'm getting the mention error. Am I missing >> >> > something? >> >> > >> >> > >> >> > In addition, I'm getting following error: >> >> > Attribute error("'tuple object has no attibute 'children'",) >> >> > >> >> > I'd be glad to have some assistance. >> >> >> >> It looks like development of csjark has stopped in 2011. Try >> >> installing a pycparser version from that time frame -- 2.05 should be >> >> a good candidate according to >> >> so if you >> >> are using pip after >> >> >> >> $ pip install pycparser==2.05 >> >> >> >> csjark might work. >> > >> > I've installed all the required SW, but still getting the same error >> >> When you invoke the interactive interpreter what does >> >> >>> import pycparser >> >>> pycparser.__version__ >> '2.05' >> >> produce on your system? > > I have version 2.07 (which is the one used for the development) For cjshark to work (or at least not fail in the way you observed) you need 2.5. 2.7 returns 2-tuples where 2.5 does not. Compare for example: https://github.com/eliben/pycparser/blob/release_v2.07/pycparser/c_ast.py#L149 def children(self): nodelist = [] if self.name is not None: nodelist.append(("name", self.name)) if self.subscript is not None: nodelist.append(("subscript", self.subscript)) return tuple(nodelist) and https://github.com/eliben/pycparser/blob/release_v2.05/pycparser/c_ast.py#L136 def children(self): nodelist = [] if self.name is not None: nodelist.append(self.name) if self.subscript is not None: nodelist.append(self.subscript) return tuple(nodelist) I wonder why you didn't just try what I suggested... From flebber.crue at gmail.com Wed Sep 21 10:26:33 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 21 Sep 2016 07:26:33 -0700 (PDT) Subject: strings and ints consistency - isinstance Message-ID: Hi Trying to clarify why ints and strings arent treated the same. You can get a valuerror from trying to cast a non-int to an int as in int(3.0) however you cannot do a non string with str(a). Which means that you likely should use try and except to test if a user enters a non-int with valuerror. However as you can't str () and get a valuerror you use conditional logic with strings. Therefore to try and keep with pythons only one obvious way of doing things should i prefer conditional logic for all using isinstance? That way regardless of input type my code flows the same and more explicitly states the intended type. Sayth From dvl at psu.edu Wed Sep 21 10:39:53 2016 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Wed, 21 Sep 2016 10:39:53 -0400 Subject: Linear Time Tree Traversal Generator Message-ID: <1474468793l.35127376l.0l@psu.edu> Since I was asked how I got different running times for my two code fragments, I'll try to apply them to a very simple tree: 4 2 6 1 3 5 7 > def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(node._right) > yield x Nodes 1, 3, 5, 7 each yield exactly 1 value -- total 4 yield statements Node 2 yields 1, 2, 3 3 yield statements Node 6 yields 5, 6, 7 3 yield statements Node 4 with its for loops yields all 7 values 7 yield statements Total number of yields is 17 4 values (approx n/2) had to be yielded 3 times (approx log n) Hence total time is O(n log n) > def to_list(node,result): > """append node information to result""" > result = to_list(node._left, result) > result.append(node._value) > return to_list(node,_right, result) Initially called at root (Node 4) with result = [] Empty result is based from Node 4 to Node 2 to Node 1 -> [1] Node 2 appends 2, then Node 3 appends 3 These are returned to Node 4, who appends 4, etc. Total number of append operations is 7, far less than 17 Now I suppose my new lists are also being 'sent upward' with those return statements, but it is also very clear that the total number of return statements executed is also 7, far less than 17. Hence total time is still O(n) --- I saw one or two responses that said that it was inherently flawed to do this as a binary tree in the first place. Well, certainly updating the binary tree is faster than a regular array or relational database, since it does not require linear-time insertions and removals. And for those who favor using dict for its very fast access, you display your search keys in sorted order while they are still in the dict. The sorted() function copies all those out into an array and sorts the array, which is of course, expected to be O(n log n). Which only highlights my disappointment that my tree traversal itself was O(n log n), unless I gave up on yield. As a teacher I'm stuck with either a) a data structure that can only get its maximal speed by not having any iterator in the normal sense (which in my mind sounds non-Pythonic) b) can support iteration, but then is no better than a dict in any way, except for maybe some rare operation like "identify the minimal value" Roger Christman instructor Pennsylvania State Universtiy From ned at nedbatchelder.com Wed Sep 21 10:42:37 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 21 Sep 2016 07:42:37 -0700 (PDT) Subject: strings and ints consistency - isinstance In-Reply-To: References: Message-ID: <119881bc-cb6c-465d-95ff-1b7022d0e6c7@googlegroups.com> On Wednesday, September 21, 2016 at 10:27:15 AM UTC-4, Sayth Renshaw wrote: > Hi > > Trying to clarify why ints and strings arent treated the same. > > You can get a valuerror from trying to cast a non-int to an int as in int(3.0) however you cannot do a non string with str(a). > > Which means that you likely should use try and except to test if a user enters a non-int with valuerror. > However as you can't str () and get a valuerror you use conditional logic with strings. > > Therefore to try and keep with pythons only one obvious way of doing things should i prefer conditional logic for all using isinstance? > > That way regardless of input type my code flows the same and more explicitly states the intended type. > Sayth How you do your check depends a lot on why you are checking, how strange a value you expecting to be checking, and what you want to do if the value isn't good for you. Can you give us specifics of the check you are doing, and the values you want to accept/reject, and the behavior you want on rejection? int() and str() are not casts, they are conversions, or constructors, and they have different ideas of the kinds of things they can turn into ints and strs. One Python philosophy is to not check types just to reject values, but instead to work with the value you are given. This gives the caller the flexibility to provide a value of a type perhaps you didn't expect, but which will work fine anyway. --Ned. From __peter__ at web.de Wed Sep 21 10:42:41 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Sep 2016 16:42:41 +0200 Subject: get the sum of differences between integers in a list References: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> Message-ID: Daiyue Weng wrote: > Hi, first of all, let me rephase the problem. > > For an arbitrary list of integers (the integers in the list are not > necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], > > if a set of consecutive integers having a difference of 1 between them, > put them in a list, i.e. there are two such lists in this example, > > [1,2,3], > > [8,9,10,11], > > and then put such lists in another list (i.e. [[1,2,3], [8,9,10,11]]). Put > the rest integers (non-sequential) in a separated list, i.e. > > `[6, 13]`. > > Note that, the problem only considers sequential integers with step_size = > 1. > > I tried to use itertools.groupby and itertools.count, > > from itertools import groupby, count > lst = [1,2,3,6,8,9,10,11,13] > c = count() > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c))] > > but the result is close to the requirement shown as a list of lists, > > [[1, 2, 3], [6], [8, 9, 10, 11], [13]] > > but it didn't separate sequential lists from non-sequential ones. > Also, I couldn't find a way to put [6] and [13] in a single list. > > I have also tried to separate sequential lists from non-sequential ones, > > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) == 1)] > # tried to extract [1,2,3] and [8,9,10,11] from the list > > or > > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) > 1)] # > tried to extract [6] and [13] from the list > > but they all ended up with > > [[1, 2, 3], [6, 8, 9, 10, 11, 13]] > > So two questions here, > > 1. How does itertools.groupby key function work in my case? > > 2. How to improve the program to achieve my goals? OK, you did at least try this time. So here's my attempt: $ cat consecutive.py from itertools import chain, groupby, islice, tee def lonely(triple): left, value, right = triple if left is not None and value - left == 1: return False if right is not None and right - value == 1: return False return True def grouped(values): left, mid, right = tee(values, 3) triples = zip( chain([None], left), mid, chain(islice(right, 1, None), [None]) ) for key, group in groupby(triples, lonely): yield key, (value for left, value, right in group) def main(): consecutive = [] other = [] values = [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19] for is_lonely, group in grouped(values): if is_lonely: other.extend(group) else: consecutive.append(list(group)) print("input") print(" ", values) print() print("consecutive") print(" all ", consecutive) print(" shortest", min(consecutive, key=len)) print(" longest ", max(consecutive, key=len)) print() print("other") print(" ", other) if __name__ == "__main__": main() $ python3 consecutive.py input [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19] consecutive all [[1, 2, 3], [8, 9, 10, 11]] shortest [1, 2, 3] longest [8, 9, 10, 11] other [6, 13, 17, 19] $ This is not as efficient as it should be -- the gaps are calculated twice, the check for the first and the last position is repeated on every iteration lots of packing and unpacking... -- either groupby() is the wrong tool or I'm holding it wrong ;) From __peter__ at web.de Wed Sep 21 11:12:04 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Sep 2016 17:12:04 +0200 Subject: get the sum of differences between integers in a list References: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> Message-ID: Peter Otten wrote: > This is not as efficient as it should be -- the gaps are calculated twice, > the check for the first and the last position is repeated on every > iteration lots of packing and unpacking... -- To address some of my own criticism: def lonely(triple): left, value, right = triple return left and right def grouped(values): a, b, mid = tee(values, 3) gaps = (y - x != 1 for x, y in zip(a, islice(b, 1, None))) left, right = tee(gaps) triples = zip( chain([True], left), mid, chain(right, [True]) ) for key, group in groupby(triples, lonely): yield key, (value for left, value, right in group) > either groupby() is the > wrong tool or I'm holding it wrong ;) Most certainly still true. From ryaku711 at gmail.com Wed Sep 21 11:49:42 2016 From: ryaku711 at gmail.com (Andrew Clark) Date: Wed, 21 Sep 2016 08:49:42 -0700 (PDT) Subject: automated comparison tool In-Reply-To: <57e1d8c9$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> <57e1d8c9$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <486f9123-6e39-442c-bd30-1db8d55fedaf@googlegroups.com> On Tuesday, September 20, 2016 at 7:48:20 PM UTC-5, Steve D'Aprano wrote: > On Wed, 21 Sep 2016 07:20 am, Andrew Clark wrote: > > > I've restarted my code so many times i no longer have a working version of > > anything. > > > *Restarting* your code doesn't change it and cannot possibly stop it from > working. My guess is that you actually mean that you've made so many random > edits to your code, without understanding or thinking about what you are > doing, that you've broken it irreversibly. > > I think you've learned a few things: > > (1) Debugging by making random perturbations to code should be a last > resort, and even then, only done with the greatest of care. > > (2) Use version control so you can roll back changes. > > (3) Or at least make a backup copy of a known working version of your code. > > (4) Most importantly, never make so many changes to your ONLY copy of the > code in one go that you can break it so badly that you can't go back. > > > You've described your problem quite well, and nicely broken it up into > pieces. I suggest you take each piece, and try to write the code for it > independently of the others. Start with the first piece: > > "access remote directories" > > > Okay, how are they accessible? Are they just network drives? Then that's > simple: you can access them as if they were local directories. What's the > path name of the network drive(s)? Simply use that. Problem solved. > > If not, then you need to decide how to access them: over SSH, FTP, > sneaker-net, whatever. The choice you make here is going to impact the > complexity of your code. Think about carefully. > > Once you have working code that can list the remote directory, you can use > it to list your three sets of files: > > > startupfiles = listdir(...StartupConfig) > runningfiles = listdir(...RunningConfig) > archivefiles = listdir(...ArchiveConfig) > > > now you can move onto step 2: > > "run through startup, running and archive to find files > with same hostname(do this for all files)" > > > Now you can forget all about remote file systems (at least for now) and just > work with the three lists of file names. How do you decide which files > belong to which file name? I don't know, because you don't say. Is the > hostname in the file name? Or do you have to open the file and read the > information from the file contents? > > However you do it, start by generating a mapping of hostname: list of file > names. > > > mapping = {} > for filename in list_of_filenames: > hostname = get_hostname(filename) > if hostname in mapping: > mapping[hostname].append(filename) > else: > mapping[hostname] = [filename] # start a new list with one entry > > > > Once you've done that for all three directories, then you can collect all > the file names for each host from all three directories, and compare the > files. > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. Thank you all for the comments. I've been working on the part to remote into the server. Unfortunately it appears that the drives are network accessible and i have to connect to them via SFTP to retrieve the files. I've been working on the below code to do this. However i keep getting an error. import os import sys from contextlib import closing from paramiko import SSHConfig, SSHClient # Specify hostname to connect to and the path hostname, remote_dirname, destdir = sys.argv[1:] # Load parameters to setup ssh connection config = SSHConfig() with open(os.path.expanduser('~/.ssh/config')) as config_file: config.parse(config_file) d = config.lookup(hostname) # Connect with closing(SSHClient()) as ssh: ssh.load_system_host_keys() #NOTE: no AutoAddPolicy() ssh.connect(d['hostname'], username=d.get('user')) with closing(ssh.open_sftp()) as sftp: # CD into remote directory sftp.chdir(remote_dirname) # CD to local destination directory os.chdir(destdir) # Download all files in it to destdir directory for filename in sftp.listdir(): sftp.get(filename, filename) Traceback (most recent call last): File "C:\Users\ac40935\workspace\AutoCompare\filecmp.py", line 6, in from paramiko import SSHConfig, SSHClient File "C:\Python35-32\paramiko-master\paramiko\__init__.py", line 30, in from paramiko.transport import SecurityOptions, Transport File "C:\Python35-32\paramiko-master\paramiko\transport.py", line 32, in from cryptography.hazmat.backends import default_backend ImportError: No module named 'cryptography' From marco.nawijn at colosso.nl Wed Sep 21 11:51:53 2016 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Wed, 21 Sep 2016 08:51:53 -0700 (PDT) Subject: get the sum of differences between integers in a list In-Reply-To: References: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> Message-ID: <58f488d0-0176-4dfe-b0c4-7d7e2fff974c@googlegroups.com> On Wednesday, September 21, 2016 at 4:14:10 PM UTC+2, Daiyue Weng wrote: > Hi, first of all, let me rephase the problem. > > For an arbitrary list of integers (the integers in the list are not > necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], > > if a set of consecutive integers having a difference of 1 between them, put > them in a list, i.e. there are two such lists in this example, > > [1,2,3], > > [8,9,10,11], > > and then put such lists in another list (i.e. [[1,2,3], [8,9,10,11]]). Put > the rest integers (non-sequential) in a separated list, i.e. > > `[6, 13]`. > > Note that, the problem only considers sequential integers with step_size = > 1. > > I tried to use itertools.groupby and itertools.count, > > from itertools import groupby, count > lst = [1,2,3,6,8,9,10,11,13] > c = count() > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c))] > > but the result is close to the requirement shown as a list of lists, > > [[1, 2, 3], [6], [8, 9, 10, 11], [13]] > > but it didn't separate sequential lists from non-sequential ones. > Also, I couldn't find a way to put [6] and [13] in a single list. > > I have also tried to separate sequential lists from non-sequential ones, > > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) == 1)] # > tried to extract [1,2,3] and [8,9,10,11] from the list > > or > > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) > 1)] # > tried to extract [6] and [13] from the list > > but they all ended up with > > [[1, 2, 3], [6, 8, 9, 10, 11, 13]] > > So two questions here, > > 1. How does itertools.groupby key function work in my case? > > 2. How to improve the program to achieve my goals? > > > Many thanks > > On 21 September 2016 at 00:19, John Pote wrote: > > > On 20/09/2016 12:52, Daiyue Weng wrote: > > > > Hi, I have a list numbers say, > >> > >> [1,2,3,4,6,8,9,10,11] > >> > >> First, I want to calculate the sum of the differences between the numbers > >> in the list. > >> > > At least for this first part a little pencil, paper and algebra yields a > > simple formula of constant and minimal calculation time. I had an intuitive > > guess and wrote down the sum of differences for a couple of examples, > > [1, 2, 5] => 4 > > [9, 11, 17, 19] => 10 > > It works for negative differences as well, > > [1, 2, 5, 1] => 0 > > The trick is to spot the relation between the sum of differences and the > > numbers in the list. A few lines of algebra then gave a very simple formula. > > > > As for the rest it's down to code as others have hinted at. > > > > Second, if a sequence of numbers having a difference of 1, put them in a > >> list, i.e. there are two such lists, > >> > >> [1,2,3] > >> > >> [8,9,10,11] > >> > >> and also put the rest numbers in another list, i.e. there is only one such > >> list in the example, > >> > >> [6]. > >> > >> Third, get the lists with the max/min sizes from above, i.e. in this > >> example, the max list is, > >> > >> [8,9,10,11] > >> > >> min list is > >> > >> [1,2,3]. > >> > >> What's the best way to implement this? > >> > >> cheers > >> > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > On Wednesday, September 21, 2016 at 4:14:10 PM UTC+2, Daiyue Weng wrote: > Hi, first of all, let me rephase the problem. > > For an arbitrary list of integers (the integers in the list are not > necessary to be sequential), e.g. [1,2,3,6,8,9,10,11,13], > > if a set of consecutive integers having a difference of 1 between them, put > them in a list, i.e. there are two such lists in this example, > > [1,2,3], > > [8,9,10,11], > > and then put such lists in another list (i.e. [[1,2,3], [8,9,10,11]]). Put > the rest integers (non-sequential) in a separated list, i.e. > > `[6, 13]`. > > Note that, the problem only considers sequential integers with step_size = > 1. > > I tried to use itertools.groupby and itertools.count, > > from itertools import groupby, count > lst = [1,2,3,6,8,9,10,11,13] > c = count() > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c))] > > but the result is close to the requirement shown as a list of lists, > > [[1, 2, 3], [6], [8, 9, 10, 11], [13]] > > but it didn't separate sequential lists from non-sequential ones. > Also, I couldn't find a way to put [6] and [13] in a single list. > > I have also tried to separate sequential lists from non-sequential ones, > > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) == 1)] # > tried to extract [1,2,3] and [8,9,10,11] from the list > > or > > result = [list(g) for i, g in groupby(lst, key=lambda x: x-next(c) > 1)] # > tried to extract [6] and [13] from the list > > but they all ended up with > > [[1, 2, 3], [6, 8, 9, 10, 11, 13]] > > So two questions here, > > 1. How does itertools.groupby key function work in my case? > > 2. How to improve the program to achieve my goals? > > > Many thanks > > On 21 September 2016 at 00:19, John Pote wrote: > > > On 20/09/2016 12:52, Daiyue Weng wrote: > > > > Hi, I have a list numbers say, > >> > >> [1,2,3,4,6,8,9,10,11] > >> > >> First, I want to calculate the sum of the differences between the numbers > >> in the list. > >> > > At least for this first part a little pencil, paper and algebra yields a > > simple formula of constant and minimal calculation time. I had an intuitive > > guess and wrote down the sum of differences for a couple of examples, > > [1, 2, 5] => 4 > > [9, 11, 17, 19] => 10 > > It works for negative differences as well, > > [1, 2, 5, 1] => 0 > > The trick is to spot the relation between the sum of differences and the > > numbers in the list. A few lines of algebra then gave a very simple formula. > > > > As for the rest it's down to code as others have hinted at. > > > > Second, if a sequence of numbers having a difference of 1, put them in a > >> list, i.e. there are two such lists, > >> > >> [1,2,3] > >> > >> [8,9,10,11] > >> > >> and also put the rest numbers in another list, i.e. there is only one such > >> list in the example, > >> > >> [6]. > >> > >> Third, get the lists with the max/min sizes from above, i.e. in this > >> example, the max list is, > >> > >> [8,9,10,11] > >> > >> min list is > >> > >> [1,2,3]. > >> > >> What's the best way to implement this? > >> > >> cheers > >> > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > And here is a straightforward one without any helpers: l = [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19, 20] n = len(l) seq_list = None non_seq_list = [] all_seq_list = [] diff = [] for i, li in enumerate(l): # Handle edge case if i == n - 1: if l[-1] - l[-2] == 1: seq_list.append(l[-1]) all_seq_list.append(seq_list) else: non_seq_list.append(l[-1]) break d = l[i+1] - li diff.append(d) if d == 1: if seq_list is None: seq_list = [] seq_list.append(li) else: if seq_list is not None: seq_list.append(li) all_seq_list.append(seq_list) seq_list = None else: non_seq_list.append(li) print('input', l) print('sum of differences', sum(diff)) print('sequential lists', all_seq_list) print('non-sequential entries', non_seq_list) length_seq_list = sorted([(len(s), s) for s in all_seq_list]) print('shortest', length_seq_list[0]) print('longest', length_seq_list[-1]) This gives: input [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19, 20] sum of differences 19 sequential lists [[1, 2, 3], [8, 9, 10, 11], [19, 20]] non-sequential entries [6, 13, 17] shortest (2, [19, 20]) longest (4, [8, 9, 10, 11]) From ryaku711 at gmail.com Wed Sep 21 11:55:54 2016 From: ryaku711 at gmail.com (Andrew Clark) Date: Wed, 21 Sep 2016 08:55:54 -0700 (PDT) Subject: automated comparison tool In-Reply-To: <486f9123-6e39-442c-bd30-1db8d55fedaf@googlegroups.com> References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> <57e1d8c9$0$1595$c3e8da3$5496439d@news.astraweb.com> <486f9123-6e39-442c-bd30-1db8d55fedaf@googlegroups.com> Message-ID: <830c4e6a-a0b8-45aa-a7e5-7ebe53b9e235@googlegroups.com> I reinstalled paramiko and now i'm getting a slighty different error but still says no cryptography. Traceback (most recent call last): File "C:\Users\ac40935\workspace\AutoCompare\filecmp.py", line 6, in from paramiko import SSHConfig, SSHClient File "C:\Python35-32\lib\site-packages\paramiko-2.0.2-py3.5.egg\paramiko\__init__.py", line 30, in File "C:\Python35-32\lib\site-packages\paramiko-2.0.2-py3.5.egg\paramiko\transport.py", line 32, in ImportError: No module named 'cryptography' From rosuav at gmail.com Wed Sep 21 12:14:39 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Sep 2016 02:14:39 +1000 Subject: Linear Time Tree Traversal Generator In-Reply-To: <1474468793l.35127376l.0l@psu.edu> References: <1474468793l.35127376l.0l@psu.edu> Message-ID: On Thu, Sep 22, 2016 at 12:39 AM, ROGER GRAYDON CHRISTMAN wrote: > Which only highlights my disappointment that my tree > traversal itself was O(n log n), unless I gave up on yield. > As a teacher I'm stuck with either > a) a data structure that can only get its maximal speed > by not having any iterator in the normal sense > (which in my mind sounds non-Pythonic) > b) can support iteration, but then is no better than a > dict in any way, except for maybe some rare operation like > "identify the minimal value" c) Reject the notion that speed is somehow linked to "number of yield operations", until such time as you actually have proof of that d) Use "yield from" and declare and/or assume that it is optimized, which it quite probably will be. The cost of a yield action is pretty minimal. Don't worry about it. ChrisA From irmen.NOSPAM at xs4all.nl Wed Sep 21 13:07:21 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 21 Sep 2016 19:07:21 +0200 Subject: pypy on windows much slower than linux/mac when using complex number type? In-Reply-To: References: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> <57e1bd41$0$881$e4fe514c@news.xs4all.nl> Message-ID: <57e2be49$0$16772$e4fe514c@news.xs4all.nl> On 21-9-2016 1:20, Chris Kaynor wrote: > > Regarding the performance decrease, it may be worthwhile to push the report > to a PyPy specific forum - a PyPy developer will probably see it here, but > you may get a faster response on a forum specific to PyPy. You're right. I don't know the best place for that, but I've made a bug report about it here: https://bitbucket.org/pypy/pypy/issues/2401 Irmen From random832 at fastmail.com Wed Sep 21 13:15:53 2016 From: random832 at fastmail.com (Random832) Date: Wed, 21 Sep 2016 13:15:53 -0400 Subject: Linear Time Tree Traversal Generator In-Reply-To: <1474468793l.35127376l.0l@psu.edu> References: <1474468793l.35127376l.0l@psu.edu> Message-ID: <1474478153.3070315.732839673.3E979826@webmail.messagingengine.com> On Wed, Sep 21, 2016, at 10:39, ROGER GRAYDON CHRISTMAN wrote: > Which only highlights my disappointment that my tree > traversal itself was O(n log n), unless I gave up on yield. Or you can give up on recursion. Recursive tree traversal is generally associated with passing in a callback in rather than implementing an iterable-like interface that can be used with a caller's for-loop anyway. def __iter__(node): stack = [] while stack or node: if node: stack.append(node) node = node._left else: node = stack.pop() yield node._value node = node._right From ian.g.kelly at gmail.com Wed Sep 21 13:32:11 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 21 Sep 2016 11:32:11 -0600 Subject: Linear Time Tree Traversal Generator In-Reply-To: References: <1474389964l.34341004l.0l@psu.edu> Message-ID: On Tue, Sep 20, 2016 at 11:03 AM, Rob Gaddi wrote: > The only thing that's O(N log N) in that is the number of actual yield > calls. If you're doing pretty much anything with those values as > they're being iterated over then they'll dominate the timing, and that > is O(N). It's fair to say that for sufficiently small values of N, the time taken by the actual work will likely dominate the time taken by the yields. It's not quite correct though to say that a O(N) piece will dominate a O(N log N) piece, because the whole point of measuring the asymptotic complexity is the observation that as N grows, the O(N log N) component will *eventually* become dominant. If you're only talking about "sufficiently small" values of N, then big O complexity is irrelevant. > I think there's a little bit of optimization that goes on using yield > from. That said, all this has a serious stink of premature > optimization. Agreed. From rosuav at gmail.com Wed Sep 21 13:33:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Sep 2016 03:33:20 +1000 Subject: Linear Time Tree Traversal Generator In-Reply-To: <1474478153.3070315.732839673.3E979826@webmail.messagingengine.com> References: <1474468793l.35127376l.0l@psu.edu> <1474478153.3070315.732839673.3E979826@webmail.messagingengine.com> Message-ID: On Thu, Sep 22, 2016 at 3:15 AM, Random832 wrote: > Or you can give up on recursion. Recursive tree traversal is generally > associated with passing in a callback in rather than implementing an > iterable-like interface that can be used with a caller's for-loop > anyway. > Maybe in languages that don't _have_ good generators, but in Python, the obvious way to iterate over something is with an iterator, not a callback. ChrisA From rosuav at gmail.com Wed Sep 21 13:41:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Sep 2016 03:41:44 +1000 Subject: Linear Time Tree Traversal Generator In-Reply-To: References: <1474389964l.34341004l.0l@psu.edu> Message-ID: On Thu, Sep 22, 2016 at 3:32 AM, Ian Kelly wrote: > On Tue, Sep 20, 2016 at 11:03 AM, Rob Gaddi > wrote: >> The only thing that's O(N log N) in that is the number of actual yield >> calls. If you're doing pretty much anything with those values as >> they're being iterated over then they'll dominate the timing, and that >> is O(N). > > It's fair to say that for sufficiently small values of N, the time > taken by the actual work will likely dominate the time taken by the > yields. It's not quite correct though to say that a O(N) piece will > dominate a O(N log N) piece, because the whole point of measuring the > asymptotic complexity is the observation that as N grows, the O(N log > N) component will *eventually* become dominant. If you're only talking > about "sufficiently small" values of N, then big O complexity is > irrelevant. Yeah.... but if your O(N) actual work takes fifty times as long as the O(N log N) yields, the latter won't dominate until you have 2**50 elements, and you're unlikely to have that. I don't know exactly what the cost of a yield is, but most definitely... >> That said, all this has a serious stink of premature >> optimization. > Agreed. ... this. ChrisA From martin.schoon at gmail.com Wed Sep 21 13:47:14 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 21 Sep 2016 17:47:14 GMT Subject: Another =?UTF-8?Q?=C3=A5=2C?= =?UTF-8?Q?_=C3=A4=2C?= =?UTF-8?Q?_=C3=B6?= question References: Message-ID: Den 2016-09-20 skrev Chris Angelico : > On Wed, Sep 21, 2016 at 6:21 AM, Martin Sch??n wrote: >> Den 2016-09-19 skrev Lawrence D?Oliveiro : >>> On Tuesday, September 20, 2016 at 8:21:25 AM UTC+12, Martin Sch??n wrote: >>>> But -- now I tested using emacs instead using C-c C-c to execute. >>>> Noting happens so I try to run the program from command line and >>>> find that now Python can't stand my ?, ? and ?. >>> >>> What version of Python? Python 3 accepts Unicode UTF-8 as a matter of course. >> >> Python 2.7. >> I just tried running my code in Python 3 and that worked like charm. > > Then you've found the solution. Py2's Unicode support is weaker than > Py3's, and it often depends on encodings. > Yes, so it seems. I have told emacs to invoke python3 instead of python and then it worked like just fine. I assume there is a setting somewhere in Geany that tells it to run python3 rather than python but I have failed to find it. Case closed as far as I am concerned. Thanks for the help and patience. /Martin From martin.schoon at gmail.com Wed Sep 21 13:56:35 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 21 Sep 2016 17:56:35 GMT Subject: Another =?UTF-8?Q?=C3=A5=2C?= =?UTF-8?Q?_=C3=A4=2C?= =?UTF-8?Q?_=C3=B6?= question References: Message-ID: Den 2016-09-20 skrev Peter Otten <__peter__ at web.de>: > Martin Sch??n wrote: > >> Den 2016-09-19 skrev Christian Gollwitzer : >>> Am 19.09.16 um 22:21 schrieb Martin Sch??n: >>>> I am studying some of these tutorials: >>>> https://pythonprogramming.net/matplotlib-intro-tutorial/ >>> >>> Assuming that you use UTF-8 (you should check with an emacs expert, I am >>> not an emacs user), try putting the header >>> >>> #!/usr/bin/python >>> # -*- coding: utf-8 -*- >>> >>> on top of your files. >>> >> I already have this and since it doesn't work from command line >> either it can't be an emacs unique problem. >> > > Are all non-ascii strings unicode? I. e. > > u"Sch??n" rather than just "Sch??n" > > ? I am not sure I answer your questions since I am not quite sure I understand it but here goes: The complete file is UTF-8 encoded as that is how Geany is set up to create new files (I just checked). /Martin From bezenchu at gmail.com Wed Sep 21 13:59:12 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 10:59:12 -0700 (PDT) Subject: csjark module In-Reply-To: References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> Message-ID: <399e40f7-6b79-484e-adc7-072ef927313d@googlegroups.com> On Wednesday, September 21, 2016 at 5:15:38 PM UTC+3, Peter Otten wrote: > bezenchu at gmail.com wrote: > > > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten wrote: > >> bezenchu at gmail.com wrote: > >> > >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten > >> > wrote: > >> >> bezenchu at gmail.com wrote: > >> >> > >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm trying > >> >> > to test on of my C header files which has following statements: > >> >> > > >> >> > typedef struct { > >> >> > unsigned long X; > >> >> > __int64 Y; > >> >> > } abc; > >> >> > > >> >> > > >> >> > If I'm changing __int64 to unsigned long I'm not getting this error > >> >> > For the __int64 i'm getting the mention error. Am I missing > >> >> > something? > >> >> > > >> >> > > >> >> > In addition, I'm getting following error: > >> >> > Attribute error("'tuple object has no attibute 'children'",) > >> >> > > >> >> > I'd be glad to have some assistance. > >> >> > >> >> It looks like development of csjark has stopped in 2011. Try > >> >> installing a pycparser version from that time frame -- 2.05 should be > >> >> a good candidate according to > >> >> so if you > >> >> are using pip after > >> >> > >> >> $ pip install pycparser==2.05 > >> >> > >> >> csjark might work. > >> > > >> > I've installed all the required SW, but still getting the same error > >> > >> When you invoke the interactive interpreter what does > >> > >> >>> import pycparser > >> >>> pycparser.__version__ > >> '2.05' > >> > >> produce on your system? > > > > I have version 2.07 (which is the one used for the development) > > For cjshark to work (or at least not fail in the way you observed) you need > 2.5. > > 2.7 returns 2-tuples where 2.5 does not. Compare for example: > > https://github.com/eliben/pycparser/blob/release_v2.07/pycparser/c_ast.py#L149 > > def children(self): > nodelist = [] > if self.name is not None: nodelist.append(("name", self.name)) > if self.subscript is not None: nodelist.append(("subscript", > self.subscript)) > return tuple(nodelist) > > and > > https://github.com/eliben/pycparser/blob/release_v2.05/pycparser/c_ast.py#L136 > > def children(self): > nodelist = [] > if self.name is not None: nodelist.append(self.name) > if self.subscript is not None: nodelist.append(self.subscript) > return tuple(nodelist) > > I wonder why you didn't just try what I suggested... Thanks. I've tried it @home on the test files of csjark. It worked fine for the 2nd issue (while at my work computer, there was error). For the first one, still have to check From bezenchu at gmail.com Wed Sep 21 14:04:06 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 11:04:06 -0700 (PDT) Subject: csjark module In-Reply-To: References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> Message-ID: <628d8b32-0df0-440d-862e-d15d05fdf5f9@googlegroups.com> On Wednesday, September 21, 2016 at 5:15:38 PM UTC+3, Peter Otten wrote: > bezenchu at gmail.com wrote: > > > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten wrote: > >> bezenchu at gmail.com wrote: > >> > >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten > >> > wrote: > >> >> bezenchu at gmail.com wrote: > >> >> > >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm trying > >> >> > to test on of my C header files which has following statements: > >> >> > > >> >> > typedef struct { > >> >> > unsigned long X; > >> >> > __int64 Y; > >> >> > } abc; > >> >> > > >> >> > > >> >> > If I'm changing __int64 to unsigned long I'm not getting this error > >> >> > For the __int64 i'm getting the mention error. Am I missing > >> >> > something? > >> >> > > >> >> > > >> >> > In addition, I'm getting following error: > >> >> > Attribute error("'tuple object has no attibute 'children'",) > >> >> > > >> >> > I'd be glad to have some assistance. > >> >> > >> >> It looks like development of csjark has stopped in 2011. Try > >> >> installing a pycparser version from that time frame -- 2.05 should be > >> >> a good candidate according to > >> >> so if you > >> >> are using pip after > >> >> > >> >> $ pip install pycparser==2.05 > >> >> > >> >> csjark might work. > >> > > >> > I've installed all the required SW, but still getting the same error > >> > >> When you invoke the interactive interpreter what does > >> > >> >>> import pycparser > >> >>> pycparser.__version__ > >> '2.05' > >> > >> produce on your system? > > > > I have version 2.07 (which is the one used for the development) > > For cjshark to work (or at least not fail in the way you observed) you need > 2.5. > > 2.7 returns 2-tuples where 2.5 does not. Compare for example: > > https://github.com/eliben/pycparser/blob/release_v2.07/pycparser/c_ast.py#L149 > > def children(self): > nodelist = [] > if self.name is not None: nodelist.append(("name", self.name)) > if self.subscript is not None: nodelist.append(("subscript", > self.subscript)) > return tuple(nodelist) > > and > > https://github.com/eliben/pycparser/blob/release_v2.05/pycparser/c_ast.py#L136 > > def children(self): > nodelist = [] > if self.name is not None: nodelist.append(self.name) > if self.subscript is not None: nodelist.append(self.subscript) > return tuple(nodelist) > > I wonder why you didn't just try what I suggested... Thanks, This one solved the 2nd problem. Do you have any suggestions for the 1st one? From ganesh1pal at gmail.com Wed Sep 21 14:35:28 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Thu, 22 Sep 2016 00:05:28 +0530 Subject: list or dictionary In-Reply-To: <57e1d3d7$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <57e1d3d7$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks Steve for the clues , quickly tried out # Version 1 doesn't seen to work. >>> for line in hostname: ... regex = r'(.*) is array with id {}'.format(devid) ... mo = re.search(regex, line) ... print line, regex, mo ... if mo is not None: ... print mo.group(1) ... RX-145-1 is array id 1 (.*) is array with id 3 None RX-145-2 is array id 2 (.*) is array with id 3 None RX-145-3 is array id 3 (.*) is array with id 3 None >>> hostname ['RX-145-1 is array id 1', 'RX-145-2 is array id 2', 'RX-145-3 is array id 3'] >>> type(devid) >>> devid 3 --------------------------------------------------------------------------------------------------- >>> devid = '3' >>> for line in hostname: ... regex = r'(.*) is array with id {}'.format(devid) ... mo = re.search(regex, line) ... print line, regex, mo ... if mo is not None: ... print mo.group(1) ... RX-145-1 is array id 1 (.*) is array with id 3 None RX-145-2 is array id 2 (.*) is array with id 3 None RX-145-3 is array id 3 (.*) is array with id 3 None >>> type(devid) ---------------------------------------------------------------------------------------------- >>> for line in hostname: ... regex = r'(.*) is array with id %d' % (devid) ... mo = re.search(regex, line) ... print line, regex, mo ... if mo is not None: ... print mo.group(1) ... RX-145-1 is array id 1 (.*) is array with id 3 None RX-145-2 is array id 2 (.*) is array with id 3 None RX-145-3 is array id 3 (.*) is array with id 3 None --------------------------------------------------------------------------------------------------- Looks like Iam missing something ? Regards, Ganesh On Wed, Sep 21, 2016 at 5:57 AM, Steve D'Aprano wrote: > On Wed, 21 Sep 2016 04:04 am, Ganesh Pal wrote: > > > I am on python 2.7 and Linux > > > > I have the stdout in the below form , I need to write a function to get > > hostname for the given id. > > > > > > Example: > > > >>>> stdout > > 'hostname-1 is array with id 1\nhostname-2 is array with id > 2\nhostname-3 > > is array with id 3\n' > > > > > > def get_hostname(id) > > return id > > > > what's a better option here > > > > 1. store it in list and grep for id and return > > 2. store it in dict as key and value i.e hostname = { 'hostname1': 1} and > > return key > > 3. any other simple options. > > > Why don't you write a function for each one, and see which is less work? > > # Version 1: store the hostname information in a list as strings > > hostnames = ['hostname-1 is array with id 1', > 'hostname-2 is array with id 2', > 'hostname-842 is array with id 842'] > > def get_hostname(id): > for line in hostnames: > regex = r'(.*) is array with id %d' % id > mo = re.match(regex, line) > if mo is not None: > return mo.group(1) > raise ValueError('not found') > > > # Version 2: store the hostname information in a dict {hostname: id} > > hostnames = {'hostname1': 1, 'hostname2': 2, 'hostname842': 842} > > def get_hostname(id): > for key, value in hostnames.items(): > if value == id: > return key > raise ValueError('not found') > > > # Version 3: use a dict the way dicts are meant to be used > > hostnames = {1: 'hostname1', 2: 'hostname2', 842: 'hostname842'} > > def get_hostname(id): > return hostnames[id] > > > > > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Wed Sep 21 14:48:31 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 21 Sep 2016 19:48:31 +0100 Subject: list or dictionary In-Reply-To: References: <57e1d3d7$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <591ff049-ba80-086a-a23b-ef8473837cea@mrabarnett.plus.com> On 2016-09-21 19:35, Ganesh Pal wrote: > Thanks Steve for the clues , quickly tried out # Version 1 doesn't seen > to work. > > >>>> for line in hostname: > ... regex = r'(.*) is array with id {}'.format(devid) > ... mo = re.search(regex, line) > ... print line, regex, mo > ... if mo is not None: > ... print mo.group(1) > ... > RX-145-1 is array id 1 (.*) is array with id 3 None > RX-145-2 is array id 2 (.*) is array with id 3 None > RX-145-3 is array id 3 (.*) is array with id 3 None >>>> hostname > ['RX-145-1 is array id 1', 'RX-145-2 is array id 2', 'RX-145-3 is array id > 3'] >>>> type(devid) > >>>> devid > 3 > --------------------------------------------------------------------------------------------------- >>>> devid = '3' >>>> for line in hostname: > ... regex = r'(.*) is array with id {}'.format(devid) > ... mo = re.search(regex, line) > ... print line, regex, mo > ... if mo is not None: > ... print mo.group(1) > ... > RX-145-1 is array id 1 (.*) is array with id 3 None > RX-145-2 is array id 2 (.*) is array with id 3 None > RX-145-3 is array id 3 (.*) is array with id 3 None >>>> type(devid) > > ---------------------------------------------------------------------------------------------- >>>> for line in hostname: > ... regex = r'(.*) is array with id %d' % (devid) > ... mo = re.search(regex, line) > ... print line, regex, mo > ... if mo is not None: > ... print mo.group(1) > ... > RX-145-1 is array id 1 (.*) is array with id 3 None > RX-145-2 is array id 2 (.*) is array with id 3 None > RX-145-3 is array id 3 (.*) is array with id 3 None > --------------------------------------------------------------------------------------------------- > > Looks like Iam missing something ? > [snip] The lines have "array id", but the regex has "array with id". From ganesh1pal at gmail.com Wed Sep 21 15:03:14 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Thu, 22 Sep 2016 00:33:14 +0530 Subject: list or dictionary In-Reply-To: <591ff049-ba80-086a-a23b-ef8473837cea@mrabarnett.plus.com> References: <57e1d3d7$0$1621$c3e8da3$5496439d@news.astraweb.com> <591ff049-ba80-086a-a23b-ef8473837cea@mrabarnett.plus.com> Message-ID: Thanks , and it has to be re.match() On Thu, Sep 22, 2016 at 12:18 AM, MRAB wrote: > On 2016-09-21 19:35, Ganesh Pal wrote: > >> Thanks Steve for the clues , quickly tried out # Version 1 doesn't seen >> to work. >> >> >> for line in hostname: >>>>> >>>> ... regex = r'(.*) is array with id {}'.format(devid) >> ... mo = re.search(regex, line) >> ... print line, regex, mo >> ... if mo is not None: >> ... print mo.group(1) >> ... >> RX-145-1 is array id 1 (.*) is array with id 3 None >> RX-145-2 is array id 2 (.*) is array with id 3 None >> RX-145-3 is array id 3 (.*) is array with id 3 None >> >>> hostname >>>>> >>>> ['RX-145-1 is array id 1', 'RX-145-2 is array id 2', 'RX-145-3 is array >> id >> 3'] >> >>> type(devid) >>>>> >>>> >> >>> devid >>>>> >>>> 3 >> ------------------------------------------------------------ >> --------------------------------------- >> >>> devid = '3' >>>>> for line in hostname: >>>>> >>>> ... regex = r'(.*) is array with id {}'.format(devid) >> ... mo = re.search(regex, line) >> ... print line, regex, mo >> ... if mo is not None: >> ... print mo.group(1) >> ... >> RX-145-1 is array id 1 (.*) is array with id 3 None >> RX-145-2 is array id 2 (.*) is array with id 3 None >> RX-145-3 is array id 3 (.*) is array with id 3 None >> >>> type(devid) >>>>> >>>> >> ------------------------------------------------------------ >> ---------------------------------- >> >>> for line in hostname: >>>>> >>>> ... regex = r'(.*) is array with id %d' % (devid) >> ... mo = re.search(regex, line) >> ... print line, regex, mo >> ... if mo is not None: >> ... print mo.group(1) >> ... >> RX-145-1 is array id 1 (.*) is array with id 3 None >> RX-145-2 is array id 2 (.*) is array with id 3 None >> RX-145-3 is array id 3 (.*) is array with id 3 None >> ------------------------------------------------------------ >> --------------------------------------- >> >> Looks like Iam missing something ? >> >> [snip] > The lines have "array id", but the regex has "array with id". > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Wed Sep 21 15:08:09 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Sep 2016 21:08:09 +0200 Subject: csjark module References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> <628d8b32-0df0-440d-862e-d15d05fdf5f9@googlegroups.com> Message-ID: bezenchu at gmail.com wrote: > On Wednesday, September 21, 2016 at 5:15:38 PM UTC+3, Peter Otten wrote: >> bezenchu at gmail.com wrote: >> >> > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten >> > wrote: >> >> bezenchu at gmail.com wrote: >> >> >> >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten >> >> > wrote: >> >> >> bezenchu at gmail.com wrote: >> >> >> >> >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm >> >> >> > trying to test on of my C header files which has following >> >> >> > statements: >> >> >> > >> >> >> > typedef struct { >> >> >> > unsigned long X; >> >> >> > __int64 Y; >> >> >> > } abc; >> >> >> > >> >> >> > >> >> >> > If I'm changing __int64 to unsigned long I'm not getting this >> >> >> > error For the __int64 i'm getting the mention error. Am I missing >> >> >> > something? >> >> >> > >> >> >> > >> >> >> > In addition, I'm getting following error: >> >> >> > Attribute error("'tuple object has no attibute 'children'",) >> >> >> > >> >> >> > I'd be glad to have some assistance. >> >> >> >> >> >> It looks like development of csjark has stopped in 2011. Try >> >> >> installing a pycparser version from that time frame -- 2.05 should >> >> >> be a good candidate according to >> >> >> so if you >> >> >> are using pip after >> >> >> >> >> >> $ pip install pycparser==2.05 >> >> >> >> >> >> csjark might work. >> >> > >> >> > I've installed all the required SW, but still getting the same error >> >> >> >> When you invoke the interactive interpreter what does >> >> >> >> >>> import pycparser >> >> >>> pycparser.__version__ >> >> '2.05' >> >> >> >> produce on your system? >> > >> > I have version 2.07 (which is the one used for the development) >> >> For cjshark to work (or at least not fail in the way you observed) you >> need 2.5. >> >> 2.7 returns 2-tuples where 2.5 does not. Compare for example: >> >> https://github.com/eliben/pycparser/blob/release_v2.07/pycparser/c_ast.py#L149 >> >> def children(self): >> nodelist = [] >> if self.name is not None: nodelist.append(("name", self.name)) >> if self.subscript is not None: nodelist.append(("subscript", >> self.subscript)) >> return tuple(nodelist) >> >> and >> >> https://github.com/eliben/pycparser/blob/release_v2.05/pycparser/c_ast.py#L136 >> >> def children(self): >> nodelist = [] >> if self.name is not None: nodelist.append(self.name) >> if self.subscript is not None: nodelist.append(self.subscript) >> return tuple(nodelist) >> >> I wonder why you didn't just try what I suggested... > > Thanks, > This one solved the 2nd problem. > > Do you have any suggestions for the 1st one? Here's what I see from your original post: https://mail.python.org/pipermail/python-list/2016-September/714323.html So I have no idea what your "1st problem" might be. Can you restate it? You have to use text, pictures are removed. From python at bdurham.com Wed Sep 21 16:28:35 2016 From: python at bdurham.com (Malcolm Greene) Date: Wed, 21 Sep 2016 16:28:35 -0400 Subject: Obtain the raw line of text read by CSVDictReader when reporting errors? Message-ID: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> Looking for ideas on how I can obtain the raw line of text read by a CSVDictReader. I've reviewed the CSV DictReader documentation and there are no public attributes that expose this type of data. My use case is reporting malformed lines detected when my code validates the dict of data returned by this object. I would like to log the actual line read by the CSVDictReader, not the processed data returned in the dict. Thank you, Malcolm From emile at fenx.com Wed Sep 21 16:33:48 2016 From: emile at fenx.com (Emile) Date: Wed, 21 Sep 2016 13:33:48 -0700 Subject: how to automate java application in window using python In-Reply-To: <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> Message-ID: On 09/18/2016 06:37 PM, Lawrence D?Oliveiro wrote: > On Monday, September 19, 2016 at 11:32:25 AM UTC+12, Michael Torrie wrote: >> One I've used is AutoIt. > > > > Like I said, this kind of thing can never work reliably... > Hmm, then I'll have to wait longer to experience the unreliability as the handful of automated gui tools I'm running has only been up 10 to 12 years or so. Emile From python at mrabarnett.plus.com Wed Sep 21 16:52:48 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 21 Sep 2016 21:52:48 +0100 Subject: Obtain the raw line of text read by CSVDictReader when reporting errors? In-Reply-To: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> References: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> Message-ID: On 2016-09-21 21:28, Malcolm Greene wrote: > Looking for ideas on how I can obtain the raw line of text read by a > CSVDictReader. I've reviewed the CSV DictReader documentation and there > are no public attributes that expose this type of data. > > My use case is reporting malformed lines detected when my code > validates the dict of data returned by this object. I would like to log > the actual line read by the CSVDictReader, not the processed data > returned in the dict. > You could put something between the file and the reader, like this: import csv class MyFile: def __init__(self, file): self.file = file def __iter__(self): return self def __next__(self): self.line = next(self.file) return self.line path = '' with open(path) as file: my_file = MyFile(file) reader = csv.DictReader(my_file) for row in reader: print(repr(my_file.line), '=>', row) From oscar.j.benjamin at gmail.com Wed Sep 21 16:56:33 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 21 Sep 2016 21:56:33 +0100 Subject: Obtain the raw line of text read by CSVDictReader when reporting errors? In-Reply-To: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> References: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> Message-ID: On 21 September 2016 at 21:28, Malcolm Greene wrote: > Looking for ideas on how I can obtain the raw line of text read by a > CSVDictReader. I've reviewed the CSV DictReader documentation and there > are no public attributes that expose this type of data. > > My use case is reporting malformed lines detected when my code > validates the dict of data returned by this object. I would like to log > the actual line read by the CSVDictReader, not the processed data > returned in the dict. You can wrap the file passed into DictReader so that it yelds each line along with the dict like so: import csv def csv_with_line(infile): last_line = [None] def line_rememberer(): for line in infile: last_line[0] = line yield line rows = csv.DictReader(line_rememberer()) for lineno, row in enumerate(rows, 2): yield lineno, last_line[0], row infile = ['a,b,c', '1,2,3', '4,5,6'] for lineno, line, row in csv_with_line(infile): print(lineno, line, row) -- Oscar From gordon at panix.com Wed Sep 21 18:22:13 2016 From: gordon at panix.com (John Gordon) Date: Wed, 21 Sep 2016 22:22:13 +0000 (UTC) Subject: strings and ints consistency - isinstance References: Message-ID: In Sayth Renshaw writes: > Trying to clarify why ints and strings arent treated the same. Because they are not the same. > You can get a valuerror from trying to cast a non-int to an int as in > int(3.0) however you cannot do a non string with str(a). Anything you type can be represented as a string*. The same is not true for integers. * Okay, python 2.7 does have some issues with Unicode. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From dearingj at comcast.net Wed Sep 21 21:07:53 2016 From: dearingj at comcast.net (Kalos Kalyre) Date: Wed, 21 Sep 2016 18:07:53 -0700 Subject: automated comparison tool In-Reply-To: <830c4e6a-a0b8-45aa-a7e5-7ebe53b9e235@googlegroups.com> References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> <57e1d8c9$0$1595$c3e8da3$5496439d@news.astraweb.com> <486f9123-6e39-442c-bd30-1db8d55fedaf@googlegroups.com> <830c4e6a-a0b8-45aa-a7e5-7ebe53b9e235@googlegroups.com> Message-ID: On 2016-09-21 08:55, Andrew Clark wrote: > I reinstalled paramiko and now i'm getting a slighty different error but still says no cryptography. > > Traceback (most recent call last): > File "C:\Users\ac40935\workspace\AutoCompare\filecmp.py", line 6, in > from paramiko import SSHConfig, SSHClient > File "C:\Python35-32\lib\site-packages\paramiko-2.0.2-py3.5.egg\paramiko\__init__.py", line 30, in > File "C:\Python35-32\lib\site-packages\paramiko-2.0.2-py3.5.egg\paramiko\transport.py", line 32, in > ImportError: No module named 'cryptography' Have you tried installing the cryptography module? I just did a quick web search for "python cryptography module" and found this site: https://cryptography.io/en/latest/ which says the module can be installed with pip: pip install cryptography -- Microblog: https://identi.ca/jdea Blog: https://theopensource.ninja/ Cut away the five (lower fetters), abandon the five (remaining fetters), and then develop the five (faculties). The bhikkhu who has transcended the five fetters is said to be "crossed over the flood". 370 >From the Dhammapada From steve+python at pearwood.info Wed Sep 21 21:22:14 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 22 Sep 2016 11:22:14 +1000 Subject: strings and ints consistency - isinstance References: Message-ID: <57e33247$0$1611$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Sep 2016 12:26 am, Sayth Renshaw wrote: > Hi > > Trying to clarify why ints and strings arent treated the same. Because ints and strings are different? :-) > You can get a valuerror from trying to cast a non-int to an int as in > int(3.0) however you cannot do a non string with str(a). Now, that's incorrect. int(3.0) succeeds, it doesn't raise ValueError. int([]) will raise TypeError. int("hello world") will raise ValueError, because int() can convert strings, but only strings with the right value. If the string has an invalid value, you get a ValueError. But str(a) should succeed for any object, any value. It should (in principle) *always* succeed. (If it fails for some object, that object is buggy.) > Which means that you likely should use try and except to test if a user > enters a non-int with valuerror. However as you can't str () and get a > valuerror you use conditional logic with strings. What sort of conditional logic do you think you will use to determine whether or not str(x) will fail? > Therefore to try and keep with pythons only one obvious way of doing > things should i prefer conditional logic for all using isinstance? No. There is no connection between the One Obvious Way principle and this. The principle of One Obvious Way is a design principle that applies to Python the language and its standard library. (You can also apply it to your own libraries, because it is a good principle to use.) But it has no connection to how you test for invalid arguments. > That way regardless of input type my code flows the same and more > explicitly states the intended type. Sayth That is an over-generalisation. Nobody should care if, in one part of your application, you test for error conditions using try...except, and in a completely different part of your application you use an explicit test using if. They are different parts of code, and there is nothing wrong with them being different. One Obvious Way does not mean "Only One Way". It means that there must be an obvious way to solve the problem, not that all problems must be solved the same way. When converting arbitrary objects to ints, the obvious way is to try the conversion and catch TypeError or ValueError if it fails. (And then what? What will you do with the exception once you have caught it? How do you recover from this? If you have no way to recover, you probably shouldn't bother catching the exception.) When converting arbitrary objects to strings, the obvious way is to assume that it will succeed. When dealing with operations that might fail, there are generally two ways to handle it: Look Before You Leap (an explicit test using if) Easier to Ask Forgiveness than Permission (try...except) https://docs.python.org/3/glossary.html#term-lbyl https://docs.python.org/3/glossary.html#term-eafp Use whichever is appropriate for the situation. There is no need to always use one or the other. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 21 21:26:26 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 22 Sep 2016 11:26:26 +1000 Subject: automated comparison tool References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> <57e1d8c9$0$1595$c3e8da3$5496439d@news.astraweb.com> <486f9123-6e39-442c-bd30-1db8d55fedaf@googlegroups.com> <830c4e6a-a0b8-45aa-a7e5-7ebe53b9e235@googlegroups.com> Message-ID: <57e33342$0$1611$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Sep 2016 01:55 am, Andrew Clark wrote: > I reinstalled paramiko and now i'm getting a slighty different error but > still says no cryptography. [...] > ImportError: No module named 'cryptography' You appear to be missing a dependency of paramiko. You need to identify which "cryptography" module it relies on, and install it. Start by reading the paramiko documentation and especially look for "requirements" or "dependencies". -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 21 21:34:45 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 22 Sep 2016 11:34:45 +1000 Subject: get the sum of differences between integers in a list References: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> <58f488d0-0176-4dfe-b0c4-7d7e2fff974c@googlegroups.com> Message-ID: <57e33536$0$1603$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Sep 2016 01:51 am, marco.nawijn at colosso.nl wrote: > And here is a straightforward one without any helpers: Please don't do people's homework for them. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 21 21:40:56 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 22 Sep 2016 11:40:56 +1000 Subject: Data Types References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> Message-ID: <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Sep 2016 10:25 pm, BartC wrote: > On 21/09/2016 05:03, Cai Gengyang wrote: > >> Are there any other data types that will give you type(A) or type(B) = >> besides True and False? > > No types but any variable or expression containing True or False will be > a bool type (or class bool): "Containing" True or False? Certainly not: py> type( [1, 2, True] ) py> type( False or 99 ) Based on your examples, I think you mean any expression *evaluating to* True or False will be a bool. Um, yeah, of course it will. Because it evaluates to one of the only two bool values, True or False. > A = 10<20 > print (type(A)) => That's because the value of A is True. > print (10<20) => True > print (type(10<20)) => 10<20 shouldn't be thought of as some alternative value which is a bool, any more than we should think of 1+1 as being a different value to 2. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bezenchu at gmail.com Wed Sep 21 22:51:31 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 19:51:31 -0700 (PDT) Subject: csjark module In-Reply-To: References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> <628d8b32-0df0-440d-862e-d15d05fdf5f9@googlegroups.com> Message-ID: On Wednesday, September 21, 2016 at 10:09:25 PM UTC+3, Peter Otten wrote: > bezenchu at gmail.com wrote: > > > On Wednesday, September 21, 2016 at 5:15:38 PM UTC+3, Peter Otten wrote: > >> bezenchu at gmail.com wrote: > >> > >> > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten > >> > wrote: > >> >> bezenchu at gmail.com wrote: > >> >> > >> >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten > >> >> > wrote: > >> >> >> bezenchu at gmail.com wrote: > >> >> >> > >> >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm > >> >> >> > trying to test on of my C header files which has following > >> >> >> > statements: > >> >> >> > > >> >> >> > typedef struct { > >> >> >> > unsigned long X; > >> >> >> > __int64 Y; > >> >> >> > } abc; > >> >> >> > > >> >> >> > > >> >> >> > If I'm changing __int64 to unsigned long I'm not getting this > >> >> >> > error For the __int64 i'm getting the mention error. Am I missing > >> >> >> > something? > >> >> >> > > >> >> >> > > >> >> >> > In addition, I'm getting following error: > >> >> >> > Attribute error("'tuple object has no attibute 'children'",) > >> >> >> > > >> >> >> > I'd be glad to have some assistance. > >> >> >> > >> >> >> It looks like development of csjark has stopped in 2011. Try > >> >> >> installing a pycparser version from that time frame -- 2.05 should > >> >> >> be a good candidate according to > >> >> >> so if you > >> >> >> are using pip after > >> >> >> > >> >> >> $ pip install pycparser==2.05 > >> >> >> > >> >> >> csjark might work. > >> >> > > >> >> > I've installed all the required SW, but still getting the same error > >> >> > >> >> When you invoke the interactive interpreter what does > >> >> > >> >> >>> import pycparser > >> >> >>> pycparser.__version__ > >> >> '2.05' > >> >> > >> >> produce on your system? > >> > > >> > I have version 2.07 (which is the one used for the development) > >> > >> For cjshark to work (or at least not fail in the way you observed) you > >> need 2.5. > >> > >> 2.7 returns 2-tuples where 2.5 does not. Compare for example: > >> > >> > https://github.com/eliben/pycparser/blob/release_v2.07/pycparser/c_ast.py#L149 > >> > >> def children(self): > >> nodelist = [] > >> if self.name is not None: nodelist.append(("name", self.name)) > >> if self.subscript is not None: nodelist.append(("subscript", > >> self.subscript)) > >> return tuple(nodelist) > >> > >> and > >> > >> > https://github.com/eliben/pycparser/blob/release_v2.05/pycparser/c_ast.py#L136 > >> > >> def children(self): > >> nodelist = [] > >> if self.name is not None: nodelist.append(self.name) > >> if self.subscript is not None: nodelist.append(self.subscript) > >> return tuple(nodelist) > >> > >> I wonder why you didn't just try what I suggested... > > > > Thanks, > > This one solved the 2nd problem. > > > > Do you have any suggestions for the 1st one? > > Here's what I see from your original post: > > https://mail.python.org/pipermail/python-list/2016-September/714323.html > > So I have no idea what your "1st problem" might be. Can you restate it? > > You have to use text, pictures are removed. Clarification with example: I'm taking the complex_union_test.h file (which is one of the test files of csjark) and changing on line 8 from int to __int64 so the code is #include "union_test.h" #include "cenum_test.h" typedef signed int BOOL; typedef enum {TRUE, FALSE} bool_t; typedef union { __int64 int_member; struct cenum_test cenum_test_member; long long long_long_member; BOOL bool_member; bool_t bool_t_member; short short_member; } complex_union; struct struct_with_complex_union { complex_union complex_union_member; bool_t bool_t_member; union union_test union_test_member; }; Now trying to execute the parsing and getting following error: Skipped "headers\complex_union_test.":Win32 as it raised ParseError('headers\\complex_union_test.h:8: before: __int64',) I have similar error with my .h file. From bezenchu at gmail.com Wed Sep 21 23:02:37 2016 From: bezenchu at gmail.com (bezenchu at gmail.com) Date: Wed, 21 Sep 2016 20:02:37 -0700 (PDT) Subject: csjark module In-Reply-To: References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> <628d8b32-0df0-440d-862e-d15d05fdf5f9@googlegroups.com> Message-ID: <960b9163-1959-4ff3-9940-062952973174@googlegroups.com> On Thursday, September 22, 2016 at 5:51:43 AM UTC+3, beze... at gmail.com wrote: > On Wednesday, September 21, 2016 at 10:09:25 PM UTC+3, Peter Otten wrote: > > bezenchu at gmail.com wrote: > > > > > On Wednesday, September 21, 2016 at 5:15:38 PM UTC+3, Peter Otten wrote: > > >> bezenchu at gmail.com wrote: > > >> > > >> > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten > > >> > wrote: > > >> >> bezenchu at gmail.com wrote: > > >> >> > > >> >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter Otten > > >> >> > wrote: > > >> >> >> bezenchu at gmail.com wrote: > > >> >> >> > > >> >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm > > >> >> >> > trying to test on of my C header files which has following > > >> >> >> > statements: > > >> >> >> > > > >> >> >> > typedef struct { > > >> >> >> > unsigned long X; > > >> >> >> > __int64 Y; > > >> >> >> > } abc; > > >> >> >> > > > >> >> >> > > > >> >> >> > If I'm changing __int64 to unsigned long I'm not getting this > > >> >> >> > error For the __int64 i'm getting the mention error. Am I missing > > >> >> >> > something? > > >> >> >> > > > >> >> >> > > > >> >> >> > In addition, I'm getting following error: > > >> >> >> > Attribute error("'tuple object has no attibute 'children'",) > > >> >> >> > > > >> >> >> > I'd be glad to have some assistance. > > >> >> >> > > >> >> >> It looks like development of csjark has stopped in 2011. Try > > >> >> >> installing a pycparser version from that time frame -- 2.05 should > > >> >> >> be a good candidate according to > > >> >> >> so if you > > >> >> >> are using pip after > > >> >> >> > > >> >> >> $ pip install pycparser==2.05 > > >> >> >> > > >> >> >> csjark might work. > > >> >> > > > >> >> > I've installed all the required SW, but still getting the same error > > >> >> > > >> >> When you invoke the interactive interpreter what does > > >> >> > > >> >> >>> import pycparser > > >> >> >>> pycparser.__version__ > > >> >> '2.05' > > >> >> > > >> >> produce on your system? > > >> > > > >> > I have version 2.07 (which is the one used for the development) > > >> > > >> For cjshark to work (or at least not fail in the way you observed) you > > >> need 2.5. > > >> > > >> 2.7 returns 2-tuples where 2.5 does not. Compare for example: > > >> > > >> > > https://github.com/eliben/pycparser/blob/release_v2.07/pycparser/c_ast.py#L149 > > >> > > >> def children(self): > > >> nodelist = [] > > >> if self.name is not None: nodelist.append(("name", self.name)) > > >> if self.subscript is not None: nodelist.append(("subscript", > > >> self.subscript)) > > >> return tuple(nodelist) > > >> > > >> and > > >> > > >> > > https://github.com/eliben/pycparser/blob/release_v2.05/pycparser/c_ast.py#L136 > > >> > > >> def children(self): > > >> nodelist = [] > > >> if self.name is not None: nodelist.append(self.name) > > >> if self.subscript is not None: nodelist.append(self.subscript) > > >> return tuple(nodelist) > > >> > > >> I wonder why you didn't just try what I suggested... > > > > > > Thanks, > > > This one solved the 2nd problem. > > > > > > Do you have any suggestions for the 1st one? > > > > Here's what I see from your original post: > > > > https://mail.python.org/pipermail/python-list/2016-September/714323.html > > > > So I have no idea what your "1st problem" might be. Can you restate it? > > > > You have to use text, pictures are removed. > > Clarification with example: > > I'm taking the complex_union_test.h file (which is one of the test files of csjark) and changing on line 8 from int to __int64 so the code is > > #include "union_test.h" > #include "cenum_test.h" > > typedef signed int BOOL; > typedef enum {TRUE, FALSE} bool_t; > > typedef union { > __int64 int_member; > struct cenum_test cenum_test_member; > long long long_long_member; > BOOL bool_member; > bool_t bool_t_member; > short short_member; > } complex_union; > > struct struct_with_complex_union { > complex_union complex_union_member; > bool_t bool_t_member; > union union_test union_test_member; > }; > > Now trying to execute the parsing and getting following error: > Skipped "headers\complex_union_test.":Win32 as it raised ParseError('headers\\complex_union_test.h:8: before: __int64',) > > I have similar error with my .h file. seems that I have a solution for it: instead of __int64 to use "long long" statement From flebber.crue at gmail.com Wed Sep 21 23:33:06 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 21 Sep 2016 20:33:06 -0700 (PDT) Subject: strings and ints consistency - isinstance In-Reply-To: References: Message-ID: To answer all the good replies. I adapted a simple vector example from the Springer book practical primer on science with python. Having solved the actual problem I thought checking with the user they had the correct entries or would like to ammend them would be a good addition. This leads to the question Y or N response which isn't hard but if someone accidentally types 4, then you get where I got stuck can't test an int for ValueError if you expect a string. This was my code import sys v0 = float(input("What velocity would you like? ")) g = float(input("What gravity would you like? ")) t = float(input("What time decimal would you like? ")) print(""" We have the following inputs. v0 is %d g is %d t is %d Is this correct? [Y/n] """ % (v0, g, t)) while True: try: answer = input("\t >> ").isalpha() print(v0 * t - 0.5 * g * t ** 2) except ValueError as err: print("Not a valid entry", err.args) sys.exit() finally: print("would you like another?") break _______________________________________________________ When I look at this SO question it splits the votes half choose try except the other conditional logic, neither are wrong but which is the more obvious python way. https://stackoverflow.com/questions/2020598/in-python-how-should-i-test-if-a-variable-is-none-true-or-false _______________________________________________________ I actually thought this would have resolved my issues and still returned error if ints entered however it still passes through. answer = input("\t >> ") if isinstance(answer, str) is True: print(v0 * t - 0.5 * g * t ** 2) elif int(answer) is True: raise ValueError("Ints aren't valid input") sys.exit() else: print("Ok please ammend your entries") Thanks Sayth From lawrencedo99 at gmail.com Wed Sep 21 23:36:23 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 21 Sep 2016 20:36:23 -0700 (PDT) Subject: Cython taking more time than regular Python In-Reply-To: References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: On Wednesday, September 21, 2016 at 6:05:07 PM UTC+12, Gregory Ewing wrote: > > Christian Gollwitzer wrote: > >> It may take a microsecond to call a functino from Python. > > Obviously the compiler used was a "dump" compiler. :-) Don?t forget ?functino?. :) For some reason it awakens half-remembered memories of undergrad physics lectures ... is that the gauge boson for the function field? Or is that a ?functon?? One of them might be spin-? ... From flebber.crue at gmail.com Wed Sep 21 23:41:32 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 21 Sep 2016 20:41:32 -0700 (PDT) Subject: strings and ints consistency - isinstance In-Reply-To: References: Message-ID: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> This ends being the code I can use to get it to work, seems clear and pythonic, open to opinion on that :-) answer = input("\t >> ") if isinstance(int(answer), int) is True: raise ValueError("Ints aren't valid input") sys.exit() elif isinstance(answer, str) is True: print(v0 * t - 0.5 * g * t ** 2) else: print("Ok please ammend your entries") Cheers Sayth From flebber.crue at gmail.com Wed Sep 21 23:46:48 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 21 Sep 2016 20:46:48 -0700 (PDT) Subject: Data Types In-Reply-To: <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: > > > >> Are there any other data types that will give you type(A) or type(B) = > >> besides True and False? > > > > No types but any variable or expression containing True or False will be > > a bool type (or class bool): > > "Containing" True or False? Certainly not: > > py> type( [1, 2, True] ) > > py> type( False or 99 ) > > > Based on your examples, I think you mean any expression *evaluating to* True > or False will be a bool. Um, yeah, of course it will. Because it evaluates > to one of the only two bool values, True or False. > > > A = 10<20 > > print (type(A)) => > > That's because the value of A is True. > > > print (10<20) => True > > print (type(10<20)) => > > 10<20 shouldn't be thought of as some alternative value which is a bool, any > more than we should think of 1+1 as being a different value to 2. > > What about 0 or 1 they are true and false like no other numbers? what category do they fall in with regards to booleans? In [6]: 0 == False Out[6]: True In [7]: 1 == True Out[7]: True In [8]: 2 == True Out[8]: False In [9]: 3 == True Out[9]: False In [10]: 3 == False Out[10]: False Sayth From pengyu.ut at gmail.com Wed Sep 21 23:53:06 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 21 Sep 2016 22:53:06 -0500 Subject: How to import all things defined the files in a module directory in __init__.py? Message-ID: Hi, Suppose that I have file1.py, ..., filen.py in a module directory. I want to import all the thing (or the ones available in the respective __all__) defined in each of the file by putting the following lines in __init__.py from file1 import * .... from filen import * However, I don't want to hardcode the file names in __init__.py. Is there an automatic way of doing it? -- Regards, Peng From hhkieu at gmail.com Thu Sep 22 00:09:10 2016 From: hhkieu at gmail.com (hhkieu at gmail.com) Date: Wed, 21 Sep 2016 21:09:10 -0700 (PDT) Subject: Is there any currently-working 3rd party snapchat API for python? Message-ID: Which one do you use? I want to build a snapchat bot that downloads video sent to my account, and uploads it to my story! From pengyu.ut at gmail.com Thu Sep 22 00:14:01 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 21 Sep 2016 23:14:01 -0500 Subject: Where is import defined in the source code? (python 2) Message-ID: Hi, I want know where import is defined in the source code. Is it implemented using __import__? -- Regards, Peng From ben+python at benfinney.id.au Thu Sep 22 00:14:28 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 22 Sep 2016 14:14:28 +1000 Subject: How to import all things defined the files in a module directory in __init__.py? References: Message-ID: <85d1jwo9jv.fsf@benfinney.id.au> Peng Yu writes: > I want to import all the thing (or the ones available in the > respective __all__) defined in each of the file by putting the > following lines in __init__.py > > from file1 import * > .... > from filen import * > > However, I don't want to hardcode the file names in __init__.py. Is > there an automatic way of doing it? Why do you want to do that? It will defeat static analysis of the code, which is one of the more important tools to make your code reliable. It will also make the names in the code impossible to automatically match against where they came from. Explicit is better than implicit; you are proposing to make an unknown horde of names in the code implicit and untraceable. Why? What problem are you trying to solve that you believe needs this approach? -- \ ?Anything that we scientists can do to weaken the hold of | `\ religion should be done and may in the end be our greatest | _o__) contribution to civilization.? ?Steven Weinberg | Ben Finney From vek.m1234 at gmail.com Thu Sep 22 01:12:01 2016 From: vek.m1234 at gmail.com (Veek M) Date: Thu, 22 Sep 2016 10:42:01 +0530 Subject: Pasting code into the cmdline interpreter Message-ID: I wanted to test this piece of code which is Kate (editor) on the cmd line python >>> prompt: tex_matches = re.findall(r'(\\\w+{.+?})|(\\\w+)', msg) for tex_word in tex_matches: repl = unicode_tex.tex_to_unicode_map.get(tex_word) if repl is None: repl = 'err' msg = re.sub(re.escape(tex_word), repl, msg) There are a number of difficulties i encountered. 1. I had to turn on highlighting to catch mixed indent (which is a good thing anyways so this was resolved - not sure how tabs got in anyhow) 2. Blank lines in my code within the editor are perfectly acceptable for readability but they act as a block termination on cmd line. So if i paste: tex_matches = re.findall(r'(\\\w+{.+?})|(\\\w+)', msg) for tex_word in tex_matches: repl = unicode_tex.tex_to_unicode_map.get(tex_word) if repl is None: I get: IndentationError: unexpected indent How do i deal with this - what's the best way to achieve what I'm trying to do. From ben+python at benfinney.id.au Thu Sep 22 01:24:36 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 22 Sep 2016 15:24:36 +1000 Subject: Pasting code into the cmdline interpreter References: Message-ID: <858tuko6az.fsf@benfinney.id.au> Veek M writes: > 1. I had to turn on highlighting to catch mixed indent (which is a > good thing anyways so this was resolved - not sure how tabs got in > anyhow) The EditorConfig system is a growing consensus for configuring a code base to instruct text editors not to mangle it. See the EditorConfig site for more information. Sadly, it seems Kate does not yet recognise EditorConfig instructions . In the meantime, manually configure Kate to only ever insert spaces to indent lines. > 2. Blank lines in my code within the editor are perfectly acceptable > for readability but they act as a block termination on cmd line. Yes. That is a deliberate compromise to make it easy to write code interactively at the interactive prompt. > I get: > IndentationError: unexpected indent > > How do i deal with this - what's the best way to achieve what I'm > trying to do. Since you are writing code into a module file, why not just run the module from that file with the non-interactive Python interpreter? -- \ ?The restriction of knowledge to an elite group destroys the | `\ spirit of society and leads to its intellectual | _o__) impoverishment.? ?Albert Einstein | Ben Finney From greg.ewing at canterbury.ac.nz Thu Sep 22 01:34:07 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 22 Sep 2016 17:34:07 +1200 Subject: Cython taking more time than regular Python In-Reply-To: References: <38650a54-3e56-4897-9172-ee9c1b1b833b@googlegroups.com> Message-ID: Lawrence D?Oliveiro wrote: > Don?t forget ?functino?. :) > > ... is that the gauge boson for the function field? Or is that a > ?functon?? One of them might be spin-? ... A functino would be the supersymmetric partner of a bosonic function. For a fermionic function, its partner would be a sfunction. -- Greg From dieter at handshake.de Thu Sep 22 02:10:44 2016 From: dieter at handshake.de (dieter) Date: Thu, 22 Sep 2016 08:10:44 +0200 Subject: Python 3.5.1 C API, the global available available is not destroyed when delete the module References: <57e0cdd8$0$2886$c3e8da3$76491128@news.astraweb.com> <874m59x2hy.fsf@handshake.de> Message-ID: <87eg4c5usb.fsf@handshake.de> dl l writes: > I understood call PyGC_collect to release object cycles. But in my python > test code, seems there is NO reference cycle on the Simple object in the > python test code. Why needs to call PyGC_Collect() here? > > ========================================================= > > class Simple: > def __init__( self ): > print('Simple__init__') > def __del__( self ): > print('Simple__del__') > > simple = None > > def run(): > global simple > simple = Simple() > > if __name__ == '__main__': > run() I do not see a cycle in this example. Thus, maybe, Python itself has introduced one (maybe via "__builtins__"). To further analyse the case, I would start by checking the "gc" module's documentation to find out, whether it provides a way to get information about the cycles it has found (and would have deleted if it had not generated references for this analysis). From auriocus at gmx.de Thu Sep 22 02:19:22 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 22 Sep 2016 08:19:22 +0200 Subject: Pasting code into the cmdline interpreter In-Reply-To: References: Message-ID: Am 22.09.16 um 07:12 schrieb Veek M: > I wanted to test this piece of code which is Kate (editor) on the cmd > line python >>> prompt: > 2. Blank lines in my code within the editor are perfectly acceptable for > readability but they act as a block termination on cmd line. So if i > paste: > tex_matches = re.findall(r'(\\\w+{.+?})|(\\\w+)', msg) > for tex_word in tex_matches: > repl = unicode_tex.tex_to_unicode_map.get(tex_word) > > if repl is None: > > I get: > IndentationError: unexpected indent IPython has a %paste and %cpaste magic to deal with this and other problems. It won't resolve the tab issue. However, Python code in general (due to indentation) is not very friendly for pasting and interactive usage. Better write the code to a file, then (again from IPython) you can read this by %run filename.py Christian From vek.m1234 at gmail.com Thu Sep 22 02:33:13 2016 From: vek.m1234 at gmail.com (Veek M) Date: Thu, 22 Sep 2016 12:03:13 +0530 Subject: Pasting code into the cmdline interpreter References: <858tuko6az.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Veek M writes: > >> 1. I had to turn on highlighting to catch mixed indent (which >> is a good thing anyways so this was resolved - not sure how tabs got >> in anyhow) > > The EditorConfig system is a growing consensus for configuring a code > base to instruct text editors not to mangle it. See the EditorConfig > site for more information. > > Sadly, it seems Kate does not yet recognise EditorConfig instructions > . In the meantime, > manually configure Kate to only ever insert spaces to indent lines. > >> 2. Blank lines in my code within the editor are perfectly acceptable >> for readability but they act as a block termination on cmd line. > > Yes. That is a deliberate compromise to make it easy to write code > interactively at the interactive prompt. > >> I get: >> IndentationError: unexpected indent >> >> How do i deal with this - what's the best way to achieve what I'm >> trying to do. > > Since you are writing code into a module file, why not just run the > module from that file with the non-interactive Python interpreter? > It's part of a hexchat plugin/addon.. like below (basically lots of hexchat crud interspersed. Anyway, i should hive it off into a separate function, and hide the import hexchat - still, bit of a pain. import hexchat def send_message(word, word_eol, userdata): if not(word[0] == "65293"): return msg = hexchat.get_info('inputbox') if msg is None: return x = re.match(r'(^\\help)\s+(\w+)', msg) if x: filter = x.groups()[1] for key, value in unicode_tex.tex_to_unicode_map.items(): if filter in key: print_help(value + ' ' + key) hexchat.command("settext %s" % '') return # findall returns: [(,), (,), ...] or [] tex_matches = re.findall(r'((\\\w+){(.+?)})|(\\\w+)', msg) if len(tex_matches) == 0: return From ben+python at benfinney.id.au Thu Sep 22 02:54:32 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 22 Sep 2016 16:54:32 +1000 Subject: Pasting code into the cmdline interpreter References: <858tuko6az.fsf@benfinney.id.au> Message-ID: <854m58o253.fsf@benfinney.id.au> Veek M writes: > Ben Finney wrote: > > > Since you are writing code into a module file, why not just run the > > module from that file with the non-interactive Python interpreter? > > > It's part of a hexchat plugin/addon.. Which tells me that it still isn't appropriate to copy-paste the code directly into the *interactive* Python interpreter. Instead, it's a module that should be imported from file, by Hexchat. Unless I misunderstand what you're talking about? -- \ ?Capitalism has destroyed our belief in any effective power but | `\ that of self interest backed by force.? ?George Bernard Shaw | _o__) | Ben Finney From orgnut at yahoo.com Thu Sep 22 03:15:50 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 22 Sep 2016 00:15:50 -0700 Subject: Data Types In-Reply-To: <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> Message-ID: On 09/20/2016 09:03 PM, Cai Gengyang wrote: [snip...] > So for example for "bool" , it only applies to True/False and nothing else? (2 data types), i.e. : Not exactly... bool is the data type (or class), True and False are the only two _values_ (not types). > >>>> type(True) > >>>> type(False) > > [snip...] Besides the bool class, with its two values, there is also the Nonetype class, which has only one value: None. But to expand on/rephrase what has already been said: while the bool class/type has only the two values True/False, in expressions using logical operators (and, or, not...), ANY data type can be interpreted as a boolean. These are often referred to as truthy and falsey values to distinguish them from actual boolean True/False values. I'm sure you've already seen the list, if not you should quickly learn it... Any numeric (int, float, complex) that is zero is falsey. Any empty collection (list, string, dictionary...) is falsey. EVERYTHING else is truthy. -- -=- Larry -=- From __peter__ at web.de Thu Sep 22 03:39:06 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Sep 2016 09:39:06 +0200 Subject: csjark module References: <48084b3a-8ade-49d2-97ac-d3810279734f@googlegroups.com> <6715ed03-bebd-406a-b4ea-9f235c2e8bfe@googlegroups.com> <628d8b32-0df0-440d-862e-d15d05fdf5f9@googlegroups.com> <960b9163-1959-4ff3-9940-062952973174@googlegroups.com> Message-ID: bezenchu at gmail.com wrote: > On Thursday, September 22, 2016 at 5:51:43 AM UTC+3, beze... at gmail.com > wrote: >> On Wednesday, September 21, 2016 at 10:09:25 PM UTC+3, Peter Otten wrote: >> > bezenchu at gmail.com wrote: >> > >> > > On Wednesday, September 21, 2016 at 5:15:38 PM UTC+3, Peter Otten >> > > wrote: >> > >> bezenchu at gmail.com wrote: >> > >> >> > >> > On Wednesday, September 21, 2016 at 3:17:11 PM UTC+3, Peter Otten >> > >> > wrote: >> > >> >> bezenchu at gmail.com wrote: >> > >> >> >> > >> >> > On Wednesday, September 21, 2016 at 1:14:14 PM UTC+3, Peter >> > >> >> > Otten wrote: >> > >> >> >> bezenchu at gmail.com wrote: >> > >> >> >> >> > >> >> >> > After setting up csjark (http://csjark.readthedocs.io/), I'm >> > >> >> >> > trying to test on of my C header files which has following >> > >> >> >> > statements: >> > >> >> >> > >> > >> >> >> > typedef struct { >> > >> >> >> > unsigned long X; >> > >> >> >> > __int64 Y; >> > >> >> >> > } abc; >> > >> >> >> > >> > >> >> >> > >> > >> >> >> > If I'm changing __int64 to unsigned long I'm not getting >> > >> >> >> > this error For the __int64 i'm getting the mention error. Am >> > >> >> >> > I missing something? >> > >> >> >> > >> > >> >> >> > >> > >> >> >> > In addition, I'm getting following error: >> > >> >> >> > Attribute error("'tuple object has no attibute 'children'",) >> > >> >> >> > >> > >> >> >> > I'd be glad to have some assistance. >> > >> >> >> >> > >> >> >> It looks like development of csjark has stopped in 2011. Try >> > >> >> >> installing a pycparser version from that time frame -- 2.05 >> > >> >> >> should be a good candidate according to >> > >> >> >> so >> > >> >> >> if you are using pip after >> > >> >> >> >> > >> >> >> $ pip install pycparser==2.05 >> > >> >> >> >> > >> >> >> csjark might work. >> > >> >> > >> > >> >> > I've installed all the required SW, but still getting the same >> > >> >> > error >> > >> >> >> > >> >> When you invoke the interactive interpreter what does >> > >> >> >> > >> >> >>> import pycparser >> > >> >> >>> pycparser.__version__ >> > >> >> '2.05' >> > >> >> >> > >> >> produce on your system? >> > >> > >> > >> > I have version 2.07 (which is the one used for the development) >> > >> >> > >> For cjshark to work (or at least not fail in the way you observed) >> > >> you need 2.5. >> > >> >> > >> 2.7 returns 2-tuples where 2.5 does not. Compare for example: >> > >> >> > >> >> > https://github.com/eliben/pycparser/blob/release_v2.07/pycparser/c_ast.py#L149 >> > >> >> > >> def children(self): >> > >> nodelist = [] >> > >> if self.name is not None: nodelist.append(("name", >> > >> self.name)) if self.subscript is not None: >> > >> nodelist.append(("subscript", >> > >> self.subscript)) >> > >> return tuple(nodelist) >> > >> >> > >> and >> > >> >> > >> >> > https://github.com/eliben/pycparser/blob/release_v2.05/pycparser/c_ast.py#L136 >> > >> >> > >> def children(self): >> > >> nodelist = [] >> > >> if self.name is not None: nodelist.append(self.name) >> > >> if self.subscript is not None: >> > >> nodelist.append(self.subscript) return tuple(nodelist) >> > >> >> > >> I wonder why you didn't just try what I suggested... >> > > >> > > Thanks, >> > > This one solved the 2nd problem. >> > > >> > > Do you have any suggestions for the 1st one? >> > >> > Here's what I see from your original post: >> > >> > https://mail.python.org/pipermail/python-list/2016-September/714323.html >> > >> > So I have no idea what your "1st problem" might be. Can you restate it? >> > >> > You have to use text, pictures are removed. >> >> Clarification with example: >> >> I'm taking the complex_union_test.h file (which is one of the test files >> of csjark) and changing on line 8 from int to __int64 so the code is >> >> #include "union_test.h" >> #include "cenum_test.h" >> >> typedef signed int BOOL; >> typedef enum {TRUE, FALSE} bool_t; >> >> typedef union { >> __int64 int_member; >> struct cenum_test cenum_test_member; >> long long long_long_member; >> BOOL bool_member; >> bool_t bool_t_member; >> short short_member; >> } complex_union; >> >> struct struct_with_complex_union { >> complex_union complex_union_member; >> bool_t bool_t_member; >> union union_test union_test_member; >> }; >> >> Now trying to execute the parsing and getting following error: >> Skipped "headers\complex_union_test.":Win32 as it raised >> ParseError('headers\\complex_union_test.h:8: before: __int64',) >> >> I have similar error with my .h file. > > seems that I have a solution for it: > instead of __int64 to use "long long" statement That seems to be a complaint of the C compiler, e. g. $ cat tmp.h typedef struct { unsigned long X; __int64 Y; } abc; $ gcc tmp.h tmp.h:3:4: error: unknown type name ?__int64? __int64 Y; ^ You can fix that with a typedef long long __int_64; assuming long long is the correct replacement for __int_64, or include the header file where __int_64 is defined if such a header file exists. From eryksun at gmail.com Thu Sep 22 03:42:40 2016 From: eryksun at gmail.com (eryk sun) Date: Thu, 22 Sep 2016 07:42:40 +0000 Subject: Pasting code into the cmdline interpreter In-Reply-To: References: Message-ID: On Thu, Sep 22, 2016 at 5:12 AM, Veek M wrote: > 2. Blank lines in my code within the editor are perfectly acceptable for > readability but they act as a block termination on cmd line. You can write a simple paste() function. For example: import sys paste = lambda: exec(sys.stdin.read(), globals()) >>> paste() class Foo: """test class""" def spam(self): '''test method''' return 'eggs' >>> Foo().spam() 'eggs' In a Unix terminal and IDLE, stdin.read() is terminated by typing Ctrl+D at the start of an empty line. For the Windows console, it's Ctrl+Z, Enter. Actually in a Unix terminal the cursor can also be at the end of a line, but a bug in Python requires pressing Ctrl+D twice in that case. From steve+comp.lang.python at pearwood.info Thu Sep 22 04:30:04 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 22 Sep 2016 18:30:04 +1000 Subject: Refer to a numbered heading in ReST Message-ID: <57e3968d$0$2780$c3e8da3$76491128@news.astraweb.com> I have a ReST (ReStructured Text) document that auto-numbers headings. I have a heading like: My Heading ---------- which will be given a number like 10.1 (say), except of course I don't know what the number will be until I've compiled the .rst file using Sphinx. Later in the document I want to refer to the heading number, but *not* turn it into a cross-reference or link. I want to say: See clause XX.X. where the XX.X is replaced by the number 10.1 (or whatever it turns out to be) but it should be just plain text. How can I do this using ReST and Sphinx? -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From steve+comp.lang.python at pearwood.info Thu Sep 22 04:31:02 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 22 Sep 2016 18:31:02 +1000 Subject: Pasting code into the cmdline interpreter References: Message-ID: <57e396c6$0$2780$c3e8da3$76491128@news.astraweb.com> On Thursday 22 September 2016 17:42, eryk sun wrote: > On Thu, Sep 22, 2016 at 5:12 AM, Veek M wrote: >> 2. Blank lines in my code within the editor are perfectly acceptable for >> readability but they act as a block termination on cmd line. > > You can write a simple paste() function. For example: > > import sys > paste = lambda: exec(sys.stdin.read(), globals()) Nice! -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From lawrencedo99 at gmail.com Thu Sep 22 04:40:13 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 22 Sep 2016 01:40:13 -0700 (PDT) Subject: Data Types In-Reply-To: References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <555d6104-e8bb-4e8e-8c83-0bf528c2385d@googlegroups.com> On Thursday, September 22, 2016 at 3:47:27 PM UTC+12, Sayth Renshaw wrote: > What about 0 or 1 they are true and false like no other numbers? >>> isinstance(1, bool) False >>> isinstance(True, int) True From lawrencedo99 at gmail.com Thu Sep 22 04:41:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 22 Sep 2016 01:41:02 -0700 (PDT) Subject: Pasting code into the cmdline interpreter In-Reply-To: References: Message-ID: <15a2e563-fdae-456e-926e-df73483c3653@googlegroups.com> On Thursday, September 22, 2016 at 5:12:13 PM UTC+12, Veek M wrote: > How do i deal with this - what's the best way to achieve what I'm trying > to do. If you want a scratchpad for trying out Python code, I can recommend Jupyter/IPython . From lawrencedo99 at gmail.com Thu Sep 22 04:42:12 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 22 Sep 2016 01:42:12 -0700 (PDT) Subject: strings and ints consistency - isinstance In-Reply-To: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> References: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> Message-ID: On Thursday, September 22, 2016 at 3:41:42 PM UTC+12, Sayth Renshaw wrote: > if isinstance(int(answer), int) is True: Not sure what the point of this is... From lawrencedo99 at gmail.com Thu Sep 22 04:52:42 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 22 Sep 2016 01:52:42 -0700 (PDT) Subject: Where is import defined in the source code? In-Reply-To: References: Message-ID: <35c4f989-78da-4499-a963-59d9ccd8cf00@googlegroups.com> On Thursday, September 22, 2016 at 4:14:16 PM UTC+12, Peng Yu wrote: > > ... I want know where import is defined in the source code. This looks like the code, and this where it hooks into the parsing. Just a guess... From shimpi0685 at gmail.com Thu Sep 22 05:27:52 2016 From: shimpi0685 at gmail.com (Shimpy Sandhu) Date: Thu, 22 Sep 2016 02:27:52 -0700 (PDT) Subject: OT-Requirement-Python Developer Message-ID: <6995a414-1769-421c-b773-da54310cda61@googlegroups.com> Hi folks I am looking for python developer for Ludhiana location. If anyone is interested, please share updated CV at shimpy at revinfotech.com Regards Shimpy Sandhu From vek.m1234 at gmail.com Thu Sep 22 05:36:37 2016 From: vek.m1234 at gmail.com (Veek M) Date: Thu, 22 Sep 2016 15:06:37 +0530 Subject: Pasting code into the cmdline interpreter References: Message-ID: eryk sun wrote: > On Thu, Sep 22, 2016 at 5:12 AM, Veek M wrote: >> 2. Blank lines in my code within the editor are perfectly acceptable >> for readability but they act as a block termination on cmd line. > > You can write a simple paste() function. For example: > > import sys > paste = lambda: exec(sys.stdin.read(), globals()) > > >>> paste() > class Foo: > """test class""" > > def spam(self): > '''test method''' > return 'eggs' > > >>> Foo().spam() > 'eggs' > > In a Unix terminal and IDLE, stdin.read() is terminated by typing > Ctrl+D at the start of an empty line. For the Windows console, it's > Ctrl+Z, Enter. Actually in a Unix terminal the cursor can also be at > the end of a line, but a bug in Python requires pressing Ctrl+D twice > in that case. ah! very clever and many thanks! so, you use .pythonrc.py to store/define your cmd-line shortcuts. It doesn't work in python2.x, because exec is a stmt, so, def paste( From vek.m1234 at gmail.com Thu Sep 22 05:37:25 2016 From: vek.m1234 at gmail.com (Veek M) Date: Thu, 22 Sep 2016 15:07:25 +0530 Subject: Pasting code into the cmdline interpreter References: <858tuko6az.fsf@benfinney.id.au> <854m58o253.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Veek M writes: > >> Ben Finney wrote: >> >> > Since you are writing code into a module file, why not just run the >> > module from that file with the non-interactive Python interpreter? >> > >> It's part of a hexchat plugin/addon.. > > Which tells me that it still isn't appropriate to copy-paste the code > directly into the *interactive* Python interpreter. Instead, it's a > module that should be imported from file, by Hexchat. > > Unless I misunderstand what you're talking about? > ah nope, you got it. From vek.m1234 at gmail.com Thu Sep 22 06:10:06 2016 From: vek.m1234 at gmail.com (Veek M) Date: Thu, 22 Sep 2016 15:40:06 +0530 Subject: h(re) for help, import re - on NameError Message-ID: Is there a way to use .pythonrc.py to provide a help function that autoloads whatever module name is passed like so: \>>> h(re) I tried inheriting site._Helper and overriding __init__ and __call__ but that didn't work, also I don't know how to deal/trap/catch the NameError (no quotes on h(re)) - is there a way to insert a try/except block around the >>> prompt? I hate having to: import whatever every-time i forget. Actually could I ditch the () in h(re) and just do: h re - the joy of that :p From ned at nedbatchelder.com Thu Sep 22 06:19:12 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 22 Sep 2016 03:19:12 -0700 (PDT) Subject: strings and ints consistency - isinstance In-Reply-To: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> References: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> Message-ID: <1cdc9d3c-62e8-4265-8dda-f03402310881@googlegroups.com> On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote: > This ends being the code I can use to get it to work, seems clear and pythonic, open to opinion on that :-) > > > answer = input("\t >> ") > if isinstance(int(answer), int) is True: > raise ValueError("Ints aren't valid input") > sys.exit() > elif isinstance(answer, str) is True: > print(v0 * t - 0.5 * g * t ** 2) > else: > print("Ok please ammend your entries") > > Cheers > > Sayth 1) When checking for truth, there's very very rarely a need to use "if x is True:". Instead, just use "if x:" 2) "isinstance(int(answer), int)" will either be True, because the int() call succeeded and produced an int, or the int() call will raise an error. Using it as a condition is baroque, and will never result in the elif clause being tested. So I'm not sure how your code is ever printing the result of the calculation, or printing the "amend" message. Are you sure you've tested this code thoroughly? --Ned. From python at bdurham.com Thu Sep 22 06:36:36 2016 From: python at bdurham.com (Malcolm Greene) Date: Thu, 22 Sep 2016 06:36:36 -0400 Subject: Obtain the raw line of text read by CSVDictReader when reporting errors? In-Reply-To: References: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> Message-ID: <1474540596.3768055.733613513.361F593B@webmail.messagingengine.com> Oscar/MRAB, > You could put something between the file and the reader ... Thank you both for your suggestions ... brilliant! You guys helped me solve my problem and gave me an excellent strategy for future scenarios. Malcolm From steve+python at pearwood.info Thu Sep 22 06:58:23 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 22 Sep 2016 20:58:23 +1000 Subject: strings and ints consistency - isinstance References: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> Message-ID: <57e3b951$0$1617$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Sep 2016 01:41 pm, Sayth Renshaw wrote: > This ends being the code I can use to get it to work, seems clear and > pythonic, open to opinion on that :-) Neither clear, nor Pythonic. > answer = input("\t >> ") Since input() returns a string in Python 3, this will always be a string. > if isinstance(int(answer), int) is True: int(answer) will either succeed, or it will fail. If it fails, it will raise ValueError, and your code will fail with an exception. If it succeeds, then it will return an int. Testing whether int(answer) returns an int is a waste of time -- it *always* returns an int, if it returns at all. So if it returns, it will return an int, isinstance() will always return True, and True is True. So your code will then > raise ValueError("Ints aren't valid input") Which means your code will ALWAYS raise ValueError: if answer is a numeric string, like "123", then int() will succeed, the if block will run, and ValueError is raised; but if answer is NOT a numeric string, like "abc", then int() will raise ValueError. So we can replace your entire block of code with a single line: raise ValueError since that is the only result possible. The rest of your code is dead code -- it cannot be executed. But if it could... > sys.exit() It seems a bit harsh to exit the application just because the user types the wrong value. Shouldn't you try again, let them type another string? > elif isinstance(answer, str) is True: > print(v0 * t - 0.5 * g * t ** 2) Since input() returns a string, answer is always a string, and isinstance() will always return True. So True is True will always evaluate to True, and the print statement with the mysterious formula will always print. > else: > print("Ok please ammend your entries") That can never occur, since both the if... clause and the elif... clause will always evaluate as True. So this is dead code. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 22 07:06:57 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 22 Sep 2016 21:06:57 +1000 Subject: Data Types References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57e3bb53$0$1589$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Sep 2016 01:46 pm, Sayth Renshaw wrote: > What about 0 or 1 they are true and false like no other numbers? what > category do they fall in with regards to booleans? 0 and 1 are ints: py> type(0) py> type(1) just like 2, 3, 4, -1, -999, 1098765432 etc. But just like 1 == 1.0 (a float), and 0 == 0.0 (a float), and in fact 1 also equals Fraction(1, 1) and Decimal(1) and 1+0j (complex number), so 1 also equals the bool True and 0 equals the bool False. The reason for this is that in many programming languages, there are no boolean values. People use 0 for false and 1 (or sometimes -1) for true. In the early days, Python was the same. See https://www.python.org/dev/peps/pep-0285/ for more details. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 22 07:13:02 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 22 Sep 2016 21:13:02 +1000 Subject: Any ReST aware editors? Message-ID: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> I have editors which will use syntax highlighting on .rst files, but I'm hoping for something a bit smarter. What I'd like is an editor with a split window, one side showing the rst that I can edit, the other side showing the formatted text updated as I type. (Or at least, updated every thirty seconds or so.) Anybody know anything like that? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jkn_gg at nicorp.f9.co.uk Thu Sep 22 07:48:44 2016 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Thu, 22 Sep 2016 04:48:44 -0700 (PDT) Subject: Any ReST aware editors? In-Reply-To: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <75459275-75a1-42b0-82b2-970292ce1262@googlegroups.com> Hi Steve On Thursday, September 22, 2016 at 12:13:16 PM UTC+1, Steve D'Aprano wrote: > I have editors which will use syntax highlighting on .rst files, but I'm > hoping for something a bit smarter. > > What I'd like is an editor with a split window, one side showing the rst > that I can edit, the other side showing the formatted text updated as I > type. (Or at least, updated every thirty seconds or so.) > > Anybody know anything like that? I am not certain, but I am pretty sure that the Leo 'outlining' editor (written in Python) allows you to do just that, via its 'viewrendered' plugin. Leo is an extremely capable editor which can work in a 'scripts + data' manner; you can write 'code as data' and intersperse this with Python code which acts on the data. FWIW this brief description barely begins to scratch the surface.... Leo is cross-platform and open source; its main developer, Ed Ream, is very responsive to suggestions and feedback http://leoeditor.com/ There is also a 'leo-editor' Google Groups HTH Jon N From jon+usenet at unequivocal.eu Thu Sep 22 07:49:32 2016 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 22 Sep 2016 11:49:32 -0000 (UTC) Subject: Any ReST aware editors? References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-09-22, Steve D'Aprano wrote: > I have editors which will use syntax highlighting on .rst files, but I'm > hoping for something a bit smarter. > > What I'd like is an editor with a split window, one side showing the rst > that I can edit, the other side showing the formatted text updated as I > type. (Or at least, updated every thirty seconds or so.) > > Anybody know anything like that? There's dillinger.io if online is ok. From kaiser.yann at gmail.com Thu Sep 22 08:04:42 2016 From: kaiser.yann at gmail.com (Yann Kaiser) Date: Thu, 22 Sep 2016 12:04:42 +0000 Subject: Any ReST aware editors? In-Reply-To: References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: Does that work with with ReST? On Thu, Sep 22, 2016, 12:59 Jon Ribbens wrote: > On 2016-09-22, Steve D'Aprano wrote: > > I have editors which will use syntax highlighting on .rst files, but I'm > > hoping for something a bit smarter. > > > > What I'd like is an editor with a split window, one side showing the rst > > that I can edit, the other side showing the formatted text updated as I > > type. (Or at least, updated every thirty seconds or so.) > > > > Anybody know anything like that? > > There's dillinger.io if online is ok. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Yann Kaiser kaiser.yann at gmail.com yann.kaiser at efrei.net +33 6 51 64 01 89 https://github.com/epsy From jon+usenet at unequivocal.eu Thu Sep 22 08:09:12 2016 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 22 Sep 2016 12:09:12 -0000 (UTC) Subject: Any ReST aware editors? References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-09-22, Yann Kaiser wrote: > On Thu, Sep 22, 2016, 12:59 Jon Ribbens wrote: >> On 2016-09-22, Steve D'Aprano wrote: >> > I have editors which will use syntax highlighting on .rst files, but I'm >> > hoping for something a bit smarter. >> > >> > What I'd like is an editor with a split window, one side showing the rst >> > that I can edit, the other side showing the formatted text updated as I >> > type. (Or at least, updated every thirty seconds or so.) >> > >> > Anybody know anything like that? >> >> There's dillinger.io if online is ok. > > Does that work with with ReST? Ah, apologies, ignore me, I was forgetting that ReST and MD are not the same. From __peter__ at web.de Thu Sep 22 08:27:10 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Sep 2016 14:27:10 +0200 Subject: Another =?UTF-8?B?w6UsIMOkLCDDtg==?= question References: Message-ID: Martin Sch??n wrote: > Den 2016-09-20 skrev Peter Otten <__peter__ at web.de>: >> Martin Sch??n wrote: >> >>> Den 2016-09-19 skrev Christian Gollwitzer : >>>> Am 19.09.16 um 22:21 schrieb Martin Sch??n: >>>>> I am studying some of these tutorials: >>>>> https://pythonprogramming.net/matplotlib-intro-tutorial/ > >>>> >>>> Assuming that you use UTF-8 (you should check with an emacs expert, I >>>> am not an emacs user), try putting the header >>>> >>>> #!/usr/bin/python >>>> # -*- coding: utf-8 -*- >>>> >>>> on top of your files. >>>> >>> I already have this and since it doesn't work from command line >>> either it can't be an emacs unique problem. >>> >> >> Are all non-ascii strings unicode? I. e. >> >> u"Sch??n" rather than just "Sch??n" >> >> ? > > I am not sure I answer your questions since I am not quite sure I > understand it but here goes: The complete file is UTF-8 encoded as > that is how Geany is set up to create new files (I just checked). When the encoding used for the file and the encoding used by the terminal differ the output of non-ascii characters gets messed up. Example script: # -*- coding: iso-8859-15 -*- print "first unicode:" print u"Sch??n" print "then bytes:" print "Sch??n" When I dump that in my UTF-8 terminal all "?"s are lost because it gets the invalid byte sequence b"\xf6" rather than the required b"\xc3\xb6": $ cat demo.py # -*- coding: iso-8859-15 -*- print "first unicode:" print u"Sch??n" print "then bytes:" print "Sch??n" But when I run the code: $ python demo.py first unicode: Sch??n then bytes: Sch??n There are other advantages, too: >>> print "Sch??n".upper() SCH??N >>> print u"Sch??n".upper() SCH??N >>> print "Sch??n"[:4] Sch? >>> print u"Sch??n"[:4] Sch? From bc at freeuk.com Thu Sep 22 08:33:58 2016 From: bc at freeuk.com (BartC) Date: Thu, 22 Sep 2016 13:33:58 +0100 Subject: Data Types In-Reply-To: <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22/09/2016 02:40, Steve D'Aprano wrote: > On Wed, 21 Sep 2016 10:25 pm, BartC wrote: > >> On 21/09/2016 05:03, Cai Gengyang wrote: >> >>> Are there any other data types that will give you type(A) or type(B) = >>> besides True and False? >> >> No types but any variable or expression containing True or False will be >> a bool type (or class bool): > > "Containing" True or False? Certainly not: Well, I wrote 'containing' before I added 'or expression', when 'evaluating to' might have been better. >> print (10<20) => True >> print (type(10<20)) => > > 10<20 shouldn't be thought of as some alternative value which is a bool, any > more than we should think of 1+1 as being a different value to 2. They're a little different: 1+1 yielding 2 is int+int => int 10<20 yielding True is int bool My post was really about bool values lurking everywhere not just where you explicitly write or assign True or False. -- Bartc From greg.ewing at canterbury.ac.nz Thu Sep 22 08:40:07 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 23 Sep 2016 00:40:07 +1200 Subject: Pasting code into the cmdline interpreter In-Reply-To: References: Message-ID: eryk sun wrote: > Actually in a Unix terminal the cursor can also be at > the end of a line, but a bug in Python requires pressing Ctrl+D twice > in that case. I wouldn't call that a bug, rather it's a consequence of what Ctrl-D does. It doesn't really mean EOF, it means to send whatever the terminal driver has in its input buffer. If the buffer is empty at the time, the process gets a zero-length read which is taken as EOF. But if the buffer is not empty, it just gets whatever is in the buffer. There's nothing Python can do about that, because it never sees the Ctrl-D -- that's handled entirely by the terminal driver. -- Greg From marko at pacujo.net Thu Sep 22 08:46:39 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 22 Sep 2016 15:46:39 +0300 Subject: Any ReST aware editors? References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wpi4rtjk.fsf@elektro.pacujo.net> Steve D'Aprano : > What I'd like is an editor with a split window, one side showing the > rst that I can edit, the other side showing the formatted text updated > as I type. (Or at least, updated every thirty seconds or so.) > > Anybody know anything like that? Open a .rst file in emacs and press C-c C-c C-p to see a PDF output of the file. On fedora, you need: dnf install rst2pdf xpdf Marko From greg.ewing at canterbury.ac.nz Thu Sep 22 08:58:34 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 23 Sep 2016 00:58:34 +1200 Subject: strings and ints consistency - isinstance In-Reply-To: <1cdc9d3c-62e8-4265-8dda-f03402310881@googlegroups.com> References: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> <1cdc9d3c-62e8-4265-8dda-f03402310881@googlegroups.com> Message-ID: > On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote: > >>answer = input("\t >> ") >>if isinstance(int(answer), int) is True: >> raise ValueError("Ints aren't valid input") You seem to be trying to check that the user hasn't entered an integer. But that's a backwards way of looking at it. If the only valid inputs at that point are "y" or "n", then you should check for those specifically: answer = input("\t >> ") if answer == "y": # do the "yes" thing elif answer == "n": # do the "no" thing else: # user entered something wrong -- Greg From jaomatos at gmail.com Thu Sep 22 08:59:06 2016 From: jaomatos at gmail.com (=?ISO-8859-1?Q?Jos=E9_Ab=EDlio?= Matos) Date: Thu, 22 Sep 2016 13:59:06 +0100 Subject: Any ReST aware editors? In-Reply-To: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1610525.qZG1mqc9Dy@myth> On Thursday, September 22, 2016 9:13:02 PM WEST Steve D'Aprano wrote: > I have editors which will use syntax highlighting on .rst files, but I'm > hoping for something a bit smarter. > > What I'd like is an editor with a split window, one side showing the rst > that I can edit, the other side showing the formatted text updated as I > type. (Or at least, updated every thirty seconds or so.) > > Anybody know anything like that? Maybe ReText (https://github.com/retext-project/retext) There is a short introduction at https://lwn.net/Articles/686879/ Regards, -- Jos? Matos From flebber.crue at gmail.com Thu Sep 22 09:40:42 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 22 Sep 2016 06:40:42 -0700 (PDT) Subject: strings and ints consistency - isinstance In-Reply-To: <57e3b951$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> <57e3b951$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <13c3ed19-b162-4bbf-8f09-f1177dc5c105@googlegroups.com> > > This ends being the code I can use to get it to work, seems clear and > > pythonic, open to opinion on that :-) > > Neither clear, nor Pythonic. Sadly imo clearer than the many hack attempts on SO. > > > answer = input("\t >> ") > > Since input() returns a string in Python 3, this will always be a string. > > > > if isinstance(int(answer), int) is True: > > int(answer) will either succeed, or it will fail. If it fails, it will raise > ValueError, and your code will fail with an exception. > > If it succeeds, then it will return an int. Testing whether int(answer) > returns an int is a waste of time -- it *always* returns an int, if it > returns at all. So if it returns, it will return an int, isinstance() will > always return True, and True is True. So your code will then > > > raise ValueError("Ints aren't valid input") > > Which means your code will ALWAYS raise ValueError: > > if answer is a numeric string, like "123", then int() will succeed, the if > block will run, and ValueError is raised; > > but if answer is NOT a numeric string, like "abc", then int() will raise > ValueError. > > So we can replace your entire block of code with a single line: > > raise ValueError > > since that is the only result possible. The rest of your code is dead > code -- it cannot be executed. > > But if it could... > > > > sys.exit() > > It seems a bit harsh to exit the application just because the user types the > wrong value. Shouldn't you try again, let them type another string? > > > > elif isinstance(answer, str) is True: > > print(v0 * t - 0.5 * g * t ** 2) > > Since input() returns a string, answer is always a string, and isinstance() > will always return True. So True is True will always evaluate to True, and > the print statement with the mysterious formula will always print. > > > > else: > > print("Ok please ammend your entries") > True it failed, just actually happy to get it to fail or pass successfully on int input. Just felt it was a clearer and more consistent approach to verifying input, then most of the varied and rather inconsistent approaches I have seen in trying to get this to work. Half opt for try except the other half if else and then implement them largely differently. Every many and varied approach str2bool(), isalpha() using list with isinstance(var, [ int, str, bool]) etc. Anyway back to the old drawing board. Cheers Sayth From eryksun at gmail.com Thu Sep 22 09:45:48 2016 From: eryksun at gmail.com (eryk sun) Date: Thu, 22 Sep 2016 13:45:48 +0000 Subject: Pasting code into the cmdline interpreter In-Reply-To: References: Message-ID: On Thu, Sep 22, 2016 at 12:40 PM, Gregory Ewing wrote: > eryk sun wrote: >> >> Actually in a Unix terminal the cursor can also be at >> the end of a line, but a bug in Python requires pressing Ctrl+D twice >> in that case. > > I wouldn't call that a bug, rather it's a consequence of > what Ctrl-D does. It doesn't really mean EOF, it means to > send whatever the terminal driver has in its input buffer. > If the buffer is empty at the time, the process gets a > zero-length read which is taken as EOF. But if the buffer > is not empty, it just gets whatever is in the buffer. > > There's nothing Python can do about that, because it > never sees the Ctrl-D -- that's handled entirely by the > terminal driver. Yes, FileIO.readall continues making read() system calls until it sees an empty read. But if we know we're reading from a terminal, we should be able to assume that a read either consumes an entire line up to a newline character or the entire buffer, no? In other words, if we see a read that returns less than the buffer size but doesn't end on a newline, then for a terminal, and only a terminal, I think we can infer Ctrl+D was typed and handle it as EOF. From vek.m1234 at gmail.com Thu Sep 22 10:28:26 2016 From: vek.m1234 at gmail.com (Veek M) Date: Thu, 22 Sep 2016 19:58:26 +0530 Subject: Pasting code into the cmdline interpreter References: Message-ID: eryk sun wrote: > On Thu, Sep 22, 2016 at 12:40 PM, Gregory Ewing > wrote: >> eryk sun wrote: >>> >>> Actually in a Unix terminal the cursor can also be at >>> the end of a line, but a bug in Python requires pressing Ctrl+D >>> twice in that case. >> >> I wouldn't call that a bug, rather it's a consequence of >> what Ctrl-D does. It doesn't really mean EOF, it means to >> send whatever the terminal driver has in its input buffer. >> If the buffer is empty at the time, the process gets a >> zero-length read which is taken as EOF. But if the buffer >> is not empty, it just gets whatever is in the buffer. >> >> There's nothing Python can do about that, because it >> never sees the Ctrl-D -- that's handled entirely by the >> terminal driver. > > Yes, FileIO.readall continues making read() system calls until it sees > an empty read. But if we know we're reading from a terminal, we should > be able to assume that a read either consumes an entire line up to a > newline character or the entire buffer, no? In other words, if we see > a read that returns less than the buffer size but doesn't end on a > newline, then for a terminal, and only a terminal, I think we can > infer Ctrl+D was typed and handle it as EOF. read() changes it behavior intelligently according to the file type (pipe, fifo, etc). By default, from a terminal, it reads up to the first newline - canonical mode/cooked mode vs non-canonical mode (vi/less). Maybe python interpreter is doing the read in non-canonical mode? From rosuav at gmail.com Thu Sep 22 11:20:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 01:20:38 +1000 Subject: Any ReST aware editors? In-Reply-To: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 22, 2016 at 9:13 PM, Steve D'Aprano wrote: > What I'd like is an editor with a split window, one side showing the rst > that I can edit, the other side showing the formatted text updated as I > type. (Or at least, updated every thirty seconds or so.) > If I were doing this, I'd simply have a script that watches the .rst file and rebuilds a corresponding output file, which can then be shown in another window, completely separate to the editor. Advantage: Requires no editor integration, so you can use any editor you like. Disadvantage: Can't see changes until you save. Advantage: Forces you to save frequently :) ChrisA From random832 at fastmail.com Thu Sep 22 11:21:13 2016 From: random832 at fastmail.com (Random832) Date: Thu, 22 Sep 2016 11:21:13 -0400 Subject: Pasting code into the cmdline interpreter In-Reply-To: References: Message-ID: <1474557673.4146256.733886105.652D9487@webmail.messagingengine.com> On Thu, Sep 22, 2016, at 09:45, eryk sun wrote: > On Thu, Sep 22, 2016 at 12:40 PM, Gregory Ewing > wrote: > > eryk sun wrote: > >> > >> Actually in a Unix terminal the cursor can also be at > >> the end of a line, but a bug in Python requires pressing Ctrl+D twice > >> in that case. > > > > I wouldn't call that a bug, rather it's a consequence of > > what Ctrl-D does. It doesn't really mean EOF, it means to > > send whatever the terminal driver has in its input buffer. > > If the buffer is empty at the time, the process gets a > > zero-length read which is taken as EOF. But if the buffer > > is not empty, it just gets whatever is in the buffer. > > > > There's nothing Python can do about that, because it > > never sees the Ctrl-D -- that's handled entirely by the > > terminal driver. > > Yes, FileIO.readall continues making read() system calls until it sees > an empty read. But if we know we're reading from a terminal, we should > be able to assume that a read either consumes an entire line up to a > newline character or the entire buffer, no? In other words, if we see > a read that returns less than the buffer size but doesn't end on a > newline, then for a terminal, and only a terminal, I think we can > infer Ctrl+D was typed and handle it as EOF. I don't see where you're getting that users should even expect ctrl-d at the end of a line to be treated as EOF. It doesn't behave that way in any other program - try it in cat, dash, etc. There are also other circumstances that can cause a partial read. For example, if the user types the dsusp character (^Y by default) on systems that support it, the program will be suspended and will receive a partial read when resumed. I wouldn't bet on a guarantee that you can't get a partial read if input is too long to fit in the driver's edit buffer (which may be smaller than the program's read buffer) on some platforms (though when I've tried it it simply stops accepting input until I hit ctrl-D or enter)... and savvy users may deliberately type ctrl-D for this purpose. And, of course, in readline, the terminal is really in cbreak mode and Python receives an actual Ctrl+D rather than having to infer anything. But here, too, other programs ignore it just like Python: try it in bash, zsh, etc. The only "bug" is in some users' simplistic understanding that "ctrl-D means EOF". From rosuav at gmail.com Thu Sep 22 11:27:55 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 01:27:55 +1000 Subject: Data Types In-Reply-To: References: <57e1fcf8$0$1600$c3e8da3$5496439d@news.astraweb.com> <55331c22-e651-4bc8-bb38-5fb03cdb57ed@googlegroups.com> <57e336a9$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 22, 2016 at 10:33 PM, BartC wrote: >>> print (10<20) => True >>> print (type(10<20)) => >> >> >> 10<20 shouldn't be thought of as some alternative value which is a bool, >> any >> more than we should think of 1+1 as being a different value to 2. > > > They're a little different: > > 1+1 yielding 2 is int+int => int > 10<20 yielding True is int bool That's a couple of example expressions and the way they're handled. > My post was really about bool values lurking everywhere not just where you > explicitly write or assign True or False. Sure. Thing is, those expressions are actually just syntactic sugar for functions. Let's replace the integers with these puppies: class Spam: def __init__(self, value): self.value = value def __repr__(self): return "Spam(%r)" % self.value def __add__(self, other): return Spam(self.value + other.value) def __lt__(self, other): if self.value < other.value: return "Yes, %r < %r" % (self.value, other.value) return "" >>> Spam(1) + Spam(1) Spam(2) >>> Spam(10) < Spam(20) 'Yes, 10 < 20' >>> Spam(10) > Spam(20) '' This is perfectly legal code, and it doesn't use True or False for its comparisons. If you want it to, you have to actually return one of those constants from __lt__, either by explicitly typing its name, or by passing it up the chain (eg "return self.value < other.value"), which just moves the problem around. ChrisA From rosuav at gmail.com Thu Sep 22 11:32:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 01:32:48 +1000 Subject: =?UTF-8?B?UmU6IEFub3RoZXIgw6UsIMOkLCDDtiBxdWVzdGlvbg==?= In-Reply-To: References: Message-ID: On Thu, Sep 22, 2016 at 10:27 PM, Peter Otten <__peter__ at web.de> wrote: > When the encoding used for the file and the encoding used by the terminal > differ the output of non-ascii characters gets messed up. Example script: > > # -*- coding: iso-8859-15 -*- > > print "first unicode:" > print u"Sch??n" > > print "then bytes:" > print "Sch??n" > > When I dump that in my UTF-8 terminal all "?"s are lost because it gets the > invalid byte sequence b"\xf6" rather than the required b"\xc3\xb6": > > $ cat demo.py > # -*- coding: iso-8859-15 -*- > > print "first unicode:" > print u"Sch??n" > > print "then bytes:" > print "Sch??n" > > But when I run the code: > > $ python demo.py > first unicode: > Sch??n > then bytes: > Sch??n What this really means is that you (almost certainly) shouldn't be storing non-ASCII text in byte strings. Most stuff will "just work" if you're using a Unicode string (obviously cat doesn't acknowledge the coding cookie, but Python itself does, as do a number of editors), and of course, you can avoid all the u"..." prefixes by going to Py3. Trying to use text in byte strings is extremely encoding-dependent, and thus dangerous. Sure, it'll generally work for ASCII... but only because you're highly likely to have your terminal set to an ASCII-compatible encoding. If you pick something else.... you're in for a whole new world of fun. Acres of entertainment. ChrisA From rosuav at gmail.com Thu Sep 22 11:38:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 01:38:06 +1000 Subject: Obtain the raw line of text read by CSVDictReader when reporting errors? In-Reply-To: <1474540596.3768055.733613513.361F593B@webmail.messagingengine.com> References: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> <1474540596.3768055.733613513.361F593B@webmail.messagingengine.com> Message-ID: On Thu, Sep 22, 2016 at 8:36 PM, Malcolm Greene wrote: > Oscar/MRAB, > >> You could put something between the file and the reader ... > > Thank you both for your suggestions ... brilliant! You guys helped me > solve my problem and gave me an excellent strategy for future scenarios. This is why, despite the confusion it sometimes causes, we all prefer duck typing to static typing. The csv.DictReader wants a "file-like object", not necessarily a file - and in this case, all it asks is an iterable of lines, so a simple generator will work. This is true of MANY, if not all, places that a file is used. ChrisA From manolo at austrohungaro.com Thu Sep 22 11:39:35 2016 From: manolo at austrohungaro.com (Manolo =?iso-8859-1?Q?Mart=EDnez?=) Date: Thu, 22 Sep 2016 17:39:35 +0200 Subject: Any ReST aware editors? In-Reply-To: References: <57e3bcc0$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160922153935.GA1354@beagle.localdomain> On 09/23/16 at 01:20am, Chris Angelico wrote: > If I were doing this, I'd simply have a script that watches the .rst > file and rebuilds a corresponding output file, which can then be shown > in another window, completely separate to the editor. [when-changed]://github.com/joh/when-changed) is a handy little script that does just this. For this use case I do: when-changed doc.rst make doc.pdf where the makefile calls [pandoc](http://pandoc.org/MANUAL.html) Manolo From pengyu.ut at gmail.com Thu Sep 22 11:50:49 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 22 Sep 2016 10:50:49 -0500 Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: <85d1jwo9jv.fsf@benfinney.id.au> References: <85d1jwo9jv.fsf@benfinney.id.au> Message-ID: On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney wrote: > Peng Yu writes: > >> I want to import all the thing (or the ones available in the >> respective __all__) defined in each of the file by putting the >> following lines in __init__.py >> >> from file1 import * >> .... >> from filen import * >> >> However, I don't want to hardcode the file names in __init__.py. Is >> there an automatic way of doing it? > > Why do you want to do that? It will defeat static analysis of the code, > which is one of the more important tools to make your code reliable. > > It will also make the names in the code impossible to automatically > match against where they came from. Explicit is better than implicit; > you are proposing to make an unknown horde of names in the code implicit > and untraceable. > > Why? What problem are you trying to solve that you believe needs this > approach? This will make refactoring easy. If everything is explicit, when one do refactoring, at two places need to be changed which can be a burden. -- Regards, Peng From eryksun at gmail.com Thu Sep 22 12:07:45 2016 From: eryksun at gmail.com (eryk sun) Date: Thu, 22 Sep 2016 16:07:45 +0000 Subject: Pasting code into the cmdline interpreter In-Reply-To: <1474557673.4146256.733886105.652D9487@webmail.messagingengine.com> References: <1474557673.4146256.733886105.652D9487@webmail.messagingengine.com> Message-ID: On Thu, Sep 22, 2016 at 3:21 PM, Random832 wrote: > On Thu, Sep 22, 2016, at 09:45, eryk sun wrote: > >> Yes, FileIO.readall continues making read() system calls until it sees >> an empty read. But if we know we're reading from a terminal, we should >> be able to assume that a read either consumes an entire line up to a >> newline character or the entire buffer, no? In other words, if we see >> a read that returns less than the buffer size but doesn't end on a >> newline, then for a terminal, and only a terminal, I think we can >> infer Ctrl+D was typed and handle it as EOF. > I don't see where you're getting that users should even expect ctrl-d at > the end of a line to be treated as EOF. It doesn't behave that way in > any other program - try it in cat, dash, etc. I thought it could be avoided as a convenience by inferring EOF when reading from a terminal, but clearly that's not the case. > For example, if the user types the dsusp character (^Y by default) on > systems that support it, the program will be suspended and will receive a > partial read when resumed. I didn't consider this, which means I'm stuck with double tapping Ctrl+D to get exactly the pasted input without adding an extra newline. This is on my mind because I want to add Ctrl+D support for console I/O in Windows, for consistency with Unix terminals and IDLE. With how this works on Windows, the read returns with the control character still in the buffer (e.g. '\x04'), so you know exactly what the user typed. But I see now that it should retain the default readall() behavior to only count an empty read (from the function that wraps ReadConsoleW) as EOF. From ryaku711 at gmail.com Thu Sep 22 12:16:53 2016 From: ryaku711 at gmail.com (Andrew Clark) Date: Thu, 22 Sep 2016 09:16:53 -0700 (PDT) Subject: Hidding Character as you type Message-ID: I'm looking for a way to either completely hide character as you type in command line or add ***** to each character as you for simple password obscurity. I've tried getpass.getpass() however the characters still show up on the screen as you type it. Can anyone help? I'm using python 2.7 on windows. host = 'ldxnis12.dx.deere.com' username = raw_input("Enter username: ") password = raw_input("Enter password: ") Output: Enter username: username Enter password: iwanthistonotshowup From rosuav at gmail.com Thu Sep 22 12:19:22 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 02:19:22 +1000 Subject: h(re) for help, import re - on NameError In-Reply-To: References: Message-ID: On Thu, Sep 22, 2016 at 8:10 PM, Veek M wrote: > Is there a way to use .pythonrc.py to provide a help function that > autoloads whatever module name is passed like so: > \>>> h(re) > > I tried inheriting site._Helper and overriding __init__ and __call__ but > that didn't work, also I don't know how to deal/trap/catch the NameError > (no quotes on h(re)) - is there a way to insert a try/except block > around the >>> prompt? > > I hate having to: import whatever every-time i forget. Actually could I > ditch the () in h(re) and just do: h re - the joy of that :p You could use sys.excepthook to catch the NameError. I don't know of a way to catch the SyntaxError and look at the original text, but with NameError it's pretty easy: def excepthook(t,v,tb): if t is NameError: n = v.args[0].split("'")[1] globals()[n] = __import__(n) exec(tb.tb_frame.f_code, tb.tb_frame.f_globals) else: excepthook.old(t,v,tb) import sys excepthook.old = sys.excepthook sys.excepthook = excepthook Paste that into interactive Python and give it a try. Be aware that it'll attempt to import *any* dud name, so it'll potentially slow stuff down any time you typo. Also, it re-executes the current traceback frame, which may or may not be appropriate; it's fine for help(re), but not otherwise. As an alternative, you could inspect tb.tb_frame.f_code to see if it matches "help(x)", and if it does, simply re-execute it with the string form of the name: exec(tb.tb_frame.f_code, tb.tb_frame.f_globals, {n: n}) This works because help('re') does the same thing as help(re), so by effectively setting re="re", you gain that functionality without actually importing into the global namespace. Adequately recognizing help(re) without false positives is left as an exercise for the reader. :) ChrisA From rosuav at gmail.com Thu Sep 22 12:25:05 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 02:25:05 +1000 Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: References: <85d1jwo9jv.fsf@benfinney.id.au> Message-ID: On Fri, Sep 23, 2016 at 1:50 AM, Peng Yu wrote: > > This will make refactoring easy. If everything is explicit, when one > do refactoring, at two places need to be changed which can be a > burden. So you want it to be easy to move stuff around between files in a package? Sounds like you don't actually have a package at all - you have a single module that you're splitting across several files. How big would this file be if you simply put it all into one .py file and got rid of the package altogether? For reference, the Decimal module (ignoring the C accelerator) is over six thousand lines of code, as a single module. Now, that might be pushing the boundaries a bit, but certainly there's no reason to split a file that's under a thousand lines of code. Just keep it all in one file, and organize it using marker comments - that way, there's no API change as you reorder stuff. ChrisA From rosuav at gmail.com Thu Sep 22 12:37:22 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 02:37:22 +1000 Subject: Hidding Character as you type In-Reply-To: References: Message-ID: On Fri, Sep 23, 2016 at 2:16 AM, Andrew Clark wrote: > I'm looking for a way to either completely hide character as you type in command line or add ***** to each character as you for simple password obscurity. I've tried getpass.getpass() however the characters still show up on the screen as you type it. Can anyone help? I'm using python 2.7 on windows. > > host = 'ldxnis12.dx.deere.com' > username = raw_input("Enter username: ") > password = raw_input("Enter password: ") > > > Output: > > Enter username: username > Enter password: iwanthistonotshowup Sounds like a limitation or bug in getpass. I don't have 2.7 handy, but just tried it on Win 7, CPython 3.5, and it correctly hid the characters. (Granted, a lot of Windows users are surprised by the lack of asterisks. But it's still better than leaving it visible.) It doesn't hide the password in Idle (and gives a warning to that effect), but if you're working in a GUI, you have other options anyway. Try upgrading to 3.5 and see if you can make it work there. If not, gather a ton of details about your system, and raise the issue - what you want is exactly what getpass should provide. ChrisA From python at mrabarnett.plus.com Thu Sep 22 12:41:32 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 22 Sep 2016 17:41:32 +0100 Subject: Hidding Character as you type In-Reply-To: References: Message-ID: <24a463c4-8885-99af-b30b-0f9842b25a3d@mrabarnett.plus.com> On 2016-09-22 17:16, Andrew Clark wrote: > I'm looking for a way to either completely hide character as you type in command line or add ***** to each character as you for simple password obscurity. I've tried getpass.getpass() however the characters still show up on the screen as you type it. Can anyone help? I'm using python 2.7 on windows. > > host = 'ldxnis12.dx.deere.com' > username = raw_input("Enter username: ") > password = raw_input("Enter password: ") > > > Output: > > Enter username: username > Enter password: iwanthistonotshowup > Here's an answer on StackOverflow: How to read password with echo ?*? in Python console program? http://stackoverflow.com/questions/7838564/how-to-read-password-with-echo-in-python-console-program From gerald.britton at gmail.com Thu Sep 22 13:12:48 2016 From: gerald.britton at gmail.com (Gerald Britton) Date: Thu, 22 Sep 2016 13:12:48 -0400 Subject: Any ReST aware editors? Message-ID: > > I have editors which will use syntax highlighting on .rst files, but I'm > hoping for something a bit smarter. What I'd like is an editor with a > split window, one side showing the rst > that I can edit, the other side showing the formatted text updated as I > type. (Or at least, updated every thirty seconds or so.) Anybody know > anything like that? Visual Studio Code does an OK job with the reStructuredText Language Support for Visual Studio Code Extension -- Gerald Britton, MCSE-DP, MVP LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton From ryaku711 at gmail.com Thu Sep 22 14:51:07 2016 From: ryaku711 at gmail.com (Andrew Clark) Date: Thu, 22 Sep 2016 11:51:07 -0700 (PDT) Subject: automated comparison tool In-Reply-To: <57e33342$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <546faeaa-812d-434c-bdea-1040b2bad72a@googlegroups.com> <57e1d8c9$0$1595$c3e8da3$5496439d@news.astraweb.com> <486f9123-6e39-442c-bd30-1db8d55fedaf@googlegroups.com> <830c4e6a-a0b8-45aa-a7e5-7ebe53b9e235@googlegroups.com> <57e33342$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, September 21, 2016 at 8:26:37 PM UTC-5, Steve D'Aprano wrote: > On Thu, 22 Sep 2016 01:55 am, Andrew Clark wrote: > > > I reinstalled paramiko and now i'm getting a slighty different error but > > still says no cryptography. > > [...] > > > ImportError: No module named 'cryptography' > > > You appear to be missing a dependency of paramiko. You need to identify > which "cryptography" module it relies on, and install it. Start by reading > the paramiko documentation and especially look for "requirements" > or "dependencies". > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. I finally realized that pip was not working due to the proxy. Once i used pip --proxy command i was able to download the packages no issue. Everything works now. From martin.schoon at gmail.com Thu Sep 22 15:21:12 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 22 Sep 2016 19:21:12 GMT Subject: Another =?UTF-8?Q?=C3=A5=2C?= =?UTF-8?Q?_=C3=A4=2C?= =?UTF-8?Q?_=C3=B6?= question References: Message-ID: Den 2016-09-22 skrev Peter Otten <__peter__ at web.de>: > Martin Sch??n wrote: >> >> I am not sure I answer your questions since I am not quite sure I >> understand it but here goes: The complete file is UTF-8 encoded as >> that is how Geany is set up to create new files (I just checked). > > When the encoding used for the file and the encoding used by the terminal > differ the output of non-ascii characters gets messed up. Example script: > > # -*- coding: iso-8859-15 -*- > > print "first unicode:" > print u"Sch??n" > > print "then bytes:" > print "Sch??n" > > When I dump that in my UTF-8 terminal all "?"s are lost because it gets the > invalid byte sequence b"\xf6" rather than the required b"\xc3\xb6": > > $ cat demo.py > # -*- coding: iso-8859-15 -*- > > print "first unicode:" > print u"Sch??n" > > print "then bytes:" > print "Sch??n" > > But when I run the code: > > $ python demo.py > first unicode: > Sch??n > then bytes: > Sch??n > > There are other advantages, too: > >>>> print "Sch??n".upper() > SCH??N >>>> print u"Sch??n".upper() > SCH??N >>>> print "Sch??n"[:4] > Sch? >>>> print u"Sch??n"[:4] > Sch? > Cool :-) Thanks for the education. /Martin From 380162267qq at gmail.com Thu Sep 22 15:22:36 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Thu, 22 Sep 2016 12:22:36 -0700 (PDT) Subject: I am newbie who can explain this code to me? In-Reply-To: References: <37ec593d-7c12-493b-a535-afa1d258af7e@googlegroups.com> <022b4f11-1e10-4ab0-bca6-a952854898fb@googlegroups.com> Message-ID: <46c0a437-305c-4c4c-91db-d4caa12dc2dc@googlegroups.com> ? 2016?9?20???? UTC-4??3:11:27?Terry Reedy??? > On 9/20/2016 9:12 AM, Peter Otten wrote: > > >> ? 2016?9?20???? UTC-4??8:17:13?BartC??? > >>> On 20/09/2016 13:12, 380162267qq at gmail.com wrote: > >>>>>>> d = {} > >>>>>>> keys = range(256) > >>>>>>> vals = map(chr, keys) > >>>>>>> map(operator.setitem, [d]*len(keys), keys, vals) > >>>> > >>>> It is from python library. What does [d]*len(keys) mean? > >>>> d is the name of dict but put d in [] really confused me. > > Where in which 'python library? I cannot findI the above in 2.7 or 3.6 > stdlib. The code should be replaced by > > > It should be noted that the code above is really bad Python. > > Better alternatives are the simple loop > > > > d = {} > > for i in range(256): > > d[i] = chr(i) > > > > or the dict comprehension > > > > d = {i: chr(i) for i in range(256)} > > this. > > -- > Terry Jan Reedy I read an old 3.2 library and didn't notice at that time. From 380162267qq at gmail.com Thu Sep 22 15:29:12 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Thu, 22 Sep 2016 12:29:12 -0700 (PDT) Subject: Why does the insert after list function fail? Message-ID: <39ec91a8-eeae-489f-9237-9d9a481a88c5@googlegroups.com> A=["1","2","3"] print(list(map(float,A)).insert(0,1)) I want to insert 1 at the head of the list but this gives me a surprise From gordon at panix.com Thu Sep 22 15:32:37 2016 From: gordon at panix.com (John Gordon) Date: Thu, 22 Sep 2016 19:32:37 +0000 (UTC) Subject: Why does the insert after list function fail? References: <39ec91a8-eeae-489f-9237-9d9a481a88c5@googlegroups.com> Message-ID: In <39ec91a8-eeae-489f-9237-9d9a481a88c5 at googlegroups.com> 380162267qq at gmail.com writes: > A=["1","2","3"] > print(list(map(float,A)).insert(0,1)) > I want to insert 1 at the head of the list but this gives me a surprise insert() does not return anything; it modifies the existing list in-place. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From best_lay at yahoo.com Thu Sep 22 16:17:43 2016 From: best_lay at yahoo.com (Wildman) Date: Thu, 22 Sep 2016 15:17:43 -0500 Subject: Why does the insert after list function fail? References: <39ec91a8-eeae-489f-9237-9d9a481a88c5@googlegroups.com> Message-ID: On Thu, 22 Sep 2016 12:29:12 -0700, 380162267qq wrote: > A=["1","2","3"] > print(list(map(float,A)).insert(0,1)) > > I want to insert 1 at the head of the list but this gives me a surprise I am not certain about what you are doing so I might be way off here. The following will insert 1 at the head of the list... Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> A=["1","2","3"] >>> list.insert(A,0,"1") >>> print(A) ['1', '1', '2', '3'] -- GNU/Linux user #557453 The cow died so I don't need your bull! From orgnut at yahoo.com Thu Sep 22 16:39:10 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 22 Sep 2016 13:39:10 -0700 Subject: strings and ints consistency - isinstance In-Reply-To: <13c3ed19-b162-4bbf-8f09-f1177dc5c105@googlegroups.com> References: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> <57e3b951$0$1617$c3e8da3$5496439d@news.astraweb.com> <13c3ed19-b162-4bbf-8f09-f1177dc5c105@googlegroups.com> Message-ID: On 09/22/2016 06:40 AM, Sayth Renshaw wrote: [snip...] > > True it failed, just actually happy to get it to fail or pass successfully on int input. > > Just felt it was a clearer and more consistent approach to verifying input, then most of the varied and rather inconsistent approaches I have seen in trying to get this to work. > > Half opt for try except the other half if else and then implement them largely differently. Every many and varied approach str2bool(), isalpha() using list with isinstance(var, [ int, str, bool]) etc. > > Anyway back to the old drawing board. > > Cheers > > Sayth > IMHO... This sort of thing deserves to be written as a separate function which can then be called anytime, anyplace. This keeps your validation and repeated input in one place and is done automatically, and lets your main program simply assume the input is valid. For example, here is the help message for the number input function I wrote for my personal utility library: --------------- get_num(prmt, min_val=None, max_val=None, flt=False) Get a number from the console Parameters: prmt: The prompt to be used with the input function, required. min_val: The minimum permissible value, or None if no minimum (the default) max_val: The maximum permissible value, or None if no maximum (the default) flt: If True, accepts and returns floats If False, accepts and returns integers (the default) Invalid input or out-of-range values are not accepted and a warning message is displayed. It will then repeat the input prompt for a new value. --------------- Admittedly, this may be overkill for general use, but it IS very handy. Even if it is overkill, it is still very easy to use. Similar validated input functions are useful as well ? such as a Yes/No function among others. If you're interested, I could post the source for this version, but if you think of it as a generic function rather than for a specific situation, it is pretty straight-forward to write. something similar. -- -=- Larry -=- From steve+python at pearwood.info Thu Sep 22 20:29:40 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 23 Sep 2016 10:29:40 +1000 Subject: strings and ints consistency - isinstance References: <5612b13e-b1cb-47a9-b07c-9f80addc0b47@googlegroups.com> <57e3b951$0$1617$c3e8da3$5496439d@news.astraweb.com> <13c3ed19-b162-4bbf-8f09-f1177dc5c105@googlegroups.com> Message-ID: <57e47775$0$1615$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Sep 2016 11:40 pm, Sayth Renshaw wrote: > True it failed, just actually happy to get it to fail or pass successfully > on int input. But it doesn't. It raises ValueError no matter what you enter. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ben+python at benfinney.id.au Thu Sep 22 21:35:45 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 23 Sep 2016 11:35:45 +1000 Subject: How to import all things defined the files in a module directory in __init__.py? References: <85d1jwo9jv.fsf@benfinney.id.au> Message-ID: <85zimzmm8e.fsf@benfinney.id.au> Peng Yu writes: > On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney wrote: > > [Importing ?*? from a module] will also make the names in the code > > impossible to automatically match against where they came from. > > Explicit is better than implicit; you are proposing to make an > > unknown horde of names in the code implicit and untraceable. > > This will make refactoring easy. If everything is explicit, when one > do refactoring, at two places need to be changed which can be a > burden. That's completely backward: Importing ?*? from the module makes refactoring significantly *more* difficult. With explicit ?import foo; foo.lorem()?, an automated tool can know that when ?lorem? changes to a different name, this module's use of ?foo.lorem? should also change. With non-explicit ?from foo import *; lorem()?, then an automated too has *no way* of knowing that ?lorem? should change when you alter that name in the ?foo? module. So no, what you say above is the opposite of correct. Instead, using star import makes a rename *more* difficult to do correctly. -- \ ?Faith is generally nothing more than the permission religious | `\ people give to one another to believe things strongly without | _o__) evidence.? ?Sam Harris, _Letter to a Christian Nation_ 2006 | Ben Finney From pengyu.ut at gmail.com Thu Sep 22 23:02:58 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 22 Sep 2016 22:02:58 -0500 Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: <85zimzmm8e.fsf@benfinney.id.au> References: <85d1jwo9jv.fsf@benfinney.id.au> <85zimzmm8e.fsf@benfinney.id.au> Message-ID: On Thu, Sep 22, 2016 at 8:35 PM, Ben Finney wrote: > Peng Yu writes: > >> On Wed, Sep 21, 2016 at 11:14 PM, Ben Finney wrote: >> > [Importing ?*? from a module] will also make the names in the code >> > impossible to automatically match against where they came from. >> > Explicit is better than implicit; you are proposing to make an >> > unknown horde of names in the code implicit and untraceable. >> >> This will make refactoring easy. If everything is explicit, when one >> do refactoring, at two places need to be changed which can be a >> burden. > > That's completely backward: Importing ?*? from the module makes > refactoring significantly *more* difficult. > > With explicit ?import foo; foo.lorem()?, an automated tool can know that > when ?lorem? changes to a different name, this module's use of > ?foo.lorem? should also change. Is there such a good automated tool for python refactoring? > With non-explicit ?from foo import *; lorem()?, then an automated too > has *no way* of knowing that ?lorem? should change when you alter that > name in the ?foo? module. > > So no, what you say above is the opposite of correct. Instead, using > star import makes a rename *more* difficult to do correctly. > > -- > \ ?Faith is generally nothing more than the permission religious | > `\ people give to one another to believe things strongly without | > _o__) evidence.? ?Sam Harris, _Letter to a Christian Nation_ 2006 | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From ben+python at benfinney.id.au Fri Sep 23 00:08:11 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 23 Sep 2016 14:08:11 +1000 Subject: Automated refactoring tools (was: How to import all things defined the files in a module directory in __init__.py?) References: <85d1jwo9jv.fsf@benfinney.id.au> <85zimzmm8e.fsf@benfinney.id.au> Message-ID: <85vaxnmf6c.fsf_-_@benfinney.id.au> Peng Yu writes: > Is there such a good automated tool for python refactoring? This sounds like a job for ? Bicycle Repair Man! Watch him extract jumbled code into well ordered classes. Gasp, as he renames all occurrences of a method. Thank You Bicycle Repair Man! There is also Rope which is a library used in numerous programming environments, including Emacs . -- \ ?I just got out of the hospital; I was in a speed-reading | `\ accident. I hit a bookmark and flew across the room.? ?Steven | _o__) Wright | Ben Finney From jussi.piitulainen at helsinki.fi Fri Sep 23 00:59:04 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 23 Sep 2016 07:59:04 +0300 Subject: Why does the insert after list function fail? References: <39ec91a8-eeae-489f-9237-9d9a481a88c5@googlegroups.com> Message-ID: 380162267qq at gmail.com writes: > A=["1","2","3"] > print(list(map(float,A)).insert(0,1)) > > I want to insert 1 at the head of the list but this gives me a surprise Is it the same surprise that you get from print([1,2,3].insert(0,1))? Or the more advanced surprise from print(A.insert(0,1))? From vek.m1234 at gmail.com Fri Sep 23 02:19:37 2016 From: vek.m1234 at gmail.com (Veek M) Date: Fri, 23 Sep 2016 11:49:37 +0530 Subject: h(re) for help, import re - on NameError References: Message-ID: Chris Angelico wrote: > On Thu, Sep 22, 2016 at 8:10 PM, Veek M wrote: >> Is there a way to use .pythonrc.py to provide a help function that >> autoloads whatever module name is passed like so: >> \>>> h(re) >> >> I tried inheriting site._Helper and overriding __init__ and __call__ >> but that didn't work, also I don't know how to deal/trap/catch the >> NameError (no quotes on h(re)) - is there a way to insert a >> try/except block around the >>> prompt? >> >> I hate having to: import whatever every-time i forget. Actually could >> I ditch the () in h(re) and just do: h re - the joy of that :p > > You could use sys.excepthook to catch the NameError. I don't know of a > way to catch the SyntaxError and look at the original text, but with > NameError it's pretty easy: > > def excepthook(t,v,tb): > if t is NameError: > n = v.args[0].split("'")[1] > globals()[n] = __import__(n) > exec(tb.tb_frame.f_code, tb.tb_frame.f_globals) > else: > excepthook.old(t,v,tb) > > import sys > excepthook.old = sys.excepthook > sys.excepthook = excepthook > > Paste that into interactive Python and give it a try. Be aware that > it'll attempt to import *any* dud name, so it'll potentially slow > stuff down any time you typo. Also, it re-executes the current > traceback frame, which may or may not be appropriate; it's fine for > help(re), but not otherwise. > > As an alternative, you could inspect tb.tb_frame.f_code to see if it > matches "help(x)", and if it does, simply re-execute it with the > string form of the name: > > exec(tb.tb_frame.f_code, tb.tb_frame.f_globals, {n: n}) > > This works because help('re') does the same thing as help(re), so by > effectively setting re="re", you gain that functionality without > actually importing into the global namespace. > > Adequately recognizing help(re) without false positives is left as an > exercise for the reader. :) > > ChrisA works great :) - okay so you save and replace the default exception handler for the interpreter. Then when the procedure is called, check to see if type is NameError - if yes, then value contains the error string with module name, so you split and extract module name, and import the module and map it to a name in the global NS and hey presto (run the old code with the modified NS - that's a bit funky)! Regarding fiddling with the code-object, yep, tb.tb_frame.f_code.co_names has a tuple ('h', 're') I suppose that's clean because it's your input after all vs splitting on something system generated (like an error message) works brilliantly - thanks :) From greg.ewing at canterbury.ac.nz Fri Sep 23 02:24:01 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 23 Sep 2016 18:24:01 +1200 Subject: Pasting code into the cmdline interpreter In-Reply-To: References: Message-ID: eryk sun wrote: > if we see > a read that returns less than the buffer size but doesn't end on a > newline, then for a terminal, and only a terminal, I think we can > infer Ctrl+D was typed and handle it as EOF. I don't think it would be wise to rely on that. There is no promise that any given read() call will read all the data that's available. Even if it worked, I'm not sure that this behaviour would be desirable. Some programs may rely on the current behaviour, e.g. shells that do auto-completion when you type ctrl-D on a non-empty line. At the very least it would make programs written in Python behave differently from any other unix program when reading from a terminal, which I don't think is a good idea. -- Greg From __peter__ at web.de Fri Sep 23 02:40:07 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Sep 2016 08:40:07 +0200 Subject: h(re) for help, import re - on NameError References: Message-ID: Veek M wrote: > Is there a way to use .pythonrc.py to provide a help function that > autoloads whatever module name is passed like so: By the way, the current help() already loads a module if you pass its name as a string: $ echo 'print("importing foo")' > foo.py $ python3 Python 3.4.3 (default, Sep 14 2016, 12:36:27) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> help("foo") importing foo Help on module foo: NAME foo [snip] From rosuav at gmail.com Fri Sep 23 03:01:12 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 17:01:12 +1000 Subject: h(re) for help, import re - on NameError In-Reply-To: References: Message-ID: On Fri, Sep 23, 2016 at 4:40 PM, Peter Otten <__peter__ at web.de> wrote: > By the way, the current help() already loads a module if you pass its name > as a string: > Yes, which is the basis of my alternate exec trick: exec(tb.tb_frame.f_code, tb.tb_frame.f_globals, {n: n}) Basically it creates a new locals dict that just has (eg) re="re", which allows help(re) to function as help("re"). ChrisA From bharadwajsrivatsa at gmail.com Fri Sep 23 03:47:45 2016 From: bharadwajsrivatsa at gmail.com (Bharadwaj Srivatsa) Date: Fri, 23 Sep 2016 00:47:45 -0700 (PDT) Subject: PyThreadState_Get Message-ID: Which ever project I am trying to install using python setup.py install command, i am getting the following error.. python -mtrace --trace setup.py install Fatal Python error: PyThreadState_Get: no current thread ABORT instruction (core dumped) How to get rid of this error and whats the cause for this From wxjmfauth at gmail.com Fri Sep 23 04:31:53 2016 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 23 Sep 2016 01:31:53 -0700 (PDT) Subject: =?UTF-8?B?UmU6IEFub3RoZXIgw6UsIMOkLCDDtiBxdWVzdGlvbg==?= In-Reply-To: <02408cdc-2e56-4af7-b68e-4eb4979cabd9@googlegroups.com> References: <02408cdc-2e56-4af7-b68e-4eb4979cabd9@googlegroups.com> Message-ID: > ----------- > > With the hope, this comment is rendered correctly, without > any 0xfffd or "EURO", the case on my platform. > Yes, it is (rendered correctly). From mining.facts at gmail.com Fri Sep 23 05:05:16 2016 From: mining.facts at gmail.com (Christian) Date: Fri, 23 Sep 2016 02:05:16 -0700 (PDT) Subject: memory utilization blow up with dict structure Message-ID: <7b5ce1f2-67b7-463a-8679-e35def1be4e2@googlegroups.com> Hi, I'm wondering why python blow up a dictionary structure so much. The ids and cat substructure could have 0..n entries but in the most cases they are <= 10,t is limited by <= 6. Thanks for any advice to save memory. Christian Example: {'0a0f7a3a0e09826caef1bff707785662': {'ids': {'aa316b86-8169-11e6-bab9-0050563e2d7c', 'aa3174f0-8169-11e6-bab9-0050563e2d7c', 'aa319408-8169-11e6-bab9-0050563e2d7c', 'aa3195e8-8169-11e6-bab9-0050563e2d7c', 'aa319732-8169-11e6-bab9-0050563e2d7c', 'aa319868-8169-11e6-bab9-0050563e2d7c', 'aa31999e-8169-11e6-bab9-0050563e2d7c', 'aa319b06-8169-11e6-bab9-0050563e2d7c'}, 't': {'type1', 'type2'}, 'dt': datetime.datetime(2016, 9, 11, 15, 15, 54, 343000), 'nids': 8, 'ntypes': 2, 'cat': [('ABC', 'aa316b86-8169-11e6-bab9-0050563e2d7c', '74', ''), ('ABC','aa3174f0-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), ('ABC','aa319408-8169-11e6-bab9-0050563e2d7c','3', 'type1'), ('ABC','aa3195e8-8169-11e6-bab9-0050563e2d7c', '3', 'type2'), ('ABC','aa319732-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), ('ABC','aa319868-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), ('ABC','aa31999e-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), ('ABC','aa319b06-8169-11e6-bab9-0050563e2d7c', '3', 'type2')]}, I did a fresh read from pickled object to have a "clean" env. linux-64bit: sys.getsizeof(superdict) 50331744 len(superdict) 941272 VmPeak: 2981364 kB VmSize: 2850288 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 2108936 kB VmRSS: 1978076 kB VmData: 2541724 kB VmStk: 140 kB VmExe: 4 kB VmLib: 111136 kB VmPTE: 4380 kB VmSwap: 0 kB From rosuav at gmail.com Fri Sep 23 06:02:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Sep 2016 20:02:16 +1000 Subject: memory utilization blow up with dict structure In-Reply-To: <7b5ce1f2-67b7-463a-8679-e35def1be4e2@googlegroups.com> References: <7b5ce1f2-67b7-463a-8679-e35def1be4e2@googlegroups.com> Message-ID: On Fri, Sep 23, 2016 at 7:05 PM, Christian wrote: > I'm wondering why python blow up a dictionary structure so much. > > The ids and cat substructure could have 0..n entries but in the most cases they are <= 10,t is limited by <= 6. > > Example: > > {'0a0f7a3a0e09826caef1bff707785662': {'ids': {'aa316b86-8169-11e6-bab9-0050563e2d7c', > 'aa3174f0-8169-11e6-bab9-0050563e2d7c', > 'aa319408-8169-11e6-bab9-0050563e2d7c', > 'aa3195e8-8169-11e6-bab9-0050563e2d7c', > 'aa319732-8169-11e6-bab9-0050563e2d7c', > 'aa319868-8169-11e6-bab9-0050563e2d7c', > 'aa31999e-8169-11e6-bab9-0050563e2d7c', > 'aa319b06-8169-11e6-bab9-0050563e2d7c'}, > 't': {'type1', 'type2'}, > 'dt': datetime.datetime(2016, 9, 11, 15, 15, 54, 343000), > 'nids': 8, > 'ntypes': 2, > 'cat': [('ABC', 'aa316b86-8169-11e6-bab9-0050563e2d7c', '74', ''), > ('ABC','aa3174f0-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa319408-8169-11e6-bab9-0050563e2d7c','3', 'type1'), > ('ABC','aa3195e8-8169-11e6-bab9-0050563e2d7c', '3', 'type2'), > ('ABC','aa319732-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa319868-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa31999e-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa319b06-8169-11e6-bab9-0050563e2d7c', '3', 'type2')]}, > > > sys.getsizeof(superdict) > 50331744 > len(superdict) > 941272 So... you have a million entries in the master dictionary, each of which has an associated collection of data, consisting of half a dozen things, some of which have subthings. The very smallest an object will ever be on a 64-bit Linux system is 16 bytes: >>> sys.getsizeof(object()) 16 and most of these will be much larger: >>> sys.getsizeof(8) 28 >>> sys.getsizeof(datetime.datetime(2016, 9, 11, 15, 15, 54, 343000)) 48 >>> sys.getsizeof([]) 64 >>> sys.getsizeof(('ABC', 'aa316b86-8169-11e6-bab9-0050563e2d7c', '74', '')) 80 >>> sys.getsizeof('aa316b86-8169-11e6-bab9-0050563e2d7c') 85 >>> sys.getsizeof({}) 240 (Bear in mind that sys.getsizeof counts only the object itself, not the things it references - that's why the tuple can take up less space than one of its members.) I don't think your collections can average less than about 1KB (even the textual representation of your example data is about that big), and you have a million of them. That's a gigabyte of memory, right there. Your peak memory usage is showing 3GB, so most likely, my conservative estimates have put an absolute lower bound on this. Try doing everything exactly the same as you did, only without actually loading the pickle - then see what memory usage is. I think you'll find that the usage is fully legitimate. > Thanks for any advice to save memory. Use a database. I suggest PostgreSQL. You won't have to load everything into memory all at once that way, and (bonus!) you can even update stuff on disk without rewriting everything. ChrisA From __peter__ at web.de Fri Sep 23 06:07:35 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Sep 2016 12:07:35 +0200 Subject: get the sum of differences between integers in a list References: <3d1ee8f3-0e94-a738-96ba-d69db756fd99@jptechnical.co.uk> Message-ID: Daiyue Weng wrote: > i, I am new to the advanced python techniques, and by studying your code, > I understand that when calling grouped function with values[1, 2, 3, 6, 8, > 9, 10, 11, 13, 17, 19], > > tee(values, 3) generated 3 iterators shared values > > left contains [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19], > mid contains [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19], > right contains [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19]. > > passing them into zip(), > > chain([None], left) generated, > > [1, 2, 3, 6, 8, 9, 10, 11, 13, 17, 19] > > chain(islice(right,1,None), [None]) generated, > > [2, 3, 6, 8, 9, 10, 11, 13, 17, 19] > > zip(chain([None], left), mid, chain(islice(right, 1, None), [None]) > generated triples with, > > [(1,1,2), (2,2,3), (3,3,6),...,(17,17,19)] > > The question is how does triples work in groupby(triples, lonely)? > especially within lonely(triple)? Consecutive triples with the same value for lonely(triple) are put into the same group. A smaller example: values = [1, 2, 4, 6, 8, 9] gives the group keys (True == lonely) [False, False, True, True, False, Fale] and results in the groups not loneley: [1, 2] lonely [4, 6] not lonely: [8, 9] > e.g. for first 3 tuples (1,1,2), (2,2,3), (3,3,6), lonely(triple) will > generated > > False, False, True > > how does this result work in groupby()? > > and what's the necessariness of > > if left is not None and value - left == 1: > return False If you look only at one side the groups will become no gap on the right: [1] gap on the right: [2, 4, 6] no gap on the right: [8, 9] assuming that we declare there's no gap on the right side of the last item. In code: >>> from itertools import * >>> def triples(values): ... a, b, c = tee(values, 3) ... return zip(chain([None], a), b, chain(islice(c, 1, None), [None])) ... >>> def gap(x, y): return x is not None and y is not None and y - x != 1 ... >>> def values(triples): return [t[1] for t in triples] ... >>> sample = [1, 2, 4, 6, 8, 9] >>> [values(g) for k, g in groupby(triples(sample), lambda v: gap(*v[:2]) and gap(*v[1:]))] [[1, 2], [4, 6], [8, 9]] I'm lazy, so I continue using triples even though pairs would be sufficient below. >>> [values(g) for k, g in groupby(triples(sample), lambda v: gap(*v[1:]))] [[1], [2, 4, 6], [8, 9]] We could use a stateful key to start a group every time we see a gap >>> def make_key(): ... group = True ... def key(v): ... nonlocal group ... if gap(*v[:2]): group = not group ... return group ... return key ... >>> [values(g) for k, g in groupby(triples(sample), make_key())] [[1, 2], [4], [6], [8, 9]] but this has the disadvantage(?) that every lonely value lands in a separate group. Your usecase could then be addressed by checking the groups' lengths: >>> consecutive = [] >>> other = [] >>> for k, g in groupby(triples(sample), make_key()): ... g = values(g) ... if len(g) == 1: other.extend(g) ... else: consecutive.append(g) ... >>> consecutive [[1, 2], [8, 9]] >>> other [4, 6] From p.f.moore at gmail.com Fri Sep 23 06:12:42 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 23 Sep 2016 03:12:42 -0700 (PDT) Subject: Looking for tips and gotchas for working with Python 3.5 zipapp feature In-Reply-To: References: <1474346736.598636.730985801.507A5EED@webmail.messagingengine.com> Message-ID: <94ad9b41-0278-48be-9076-6989333b80b4@googlegroups.com> On Tuesday, 20 September 2016 05:45:53 UTC+1, Malcolm Greene wrote: > I really appreciate the detailed response. You answered all my > questions. I'm looking forward to testing out your pylaunch wrapper. Just one further note, which may or may not be obvious. If your application uses external dependencies from PyPI, you can bundle them with your application using pip's --target option. So suppose you have an application "myapp", in a directory called "myapp", which depends on (say) click and requests. So you have something like myapp __main__.py mymod __init__.py code.py morecode.py To install requests and click ready for deployment, you can do pip install --target myapp requests click That will give you the structure myapp __main__.py mymod __init__.py code.py morecode.py requests requests-2.11.1.dist-info click click-6.6.dist-info You can delete the .dist-info directories if you wish, they are package metadata and not really important for deployment. Then just bundle your application using "python -m zipapp myapp" and you have a fully standalone .pyz file, that doesn't require the user to have click or requests installed. There are some external dependencies that won't work when bundled in a zipapp (most notably anything with a C extension) but for the majority of cases this works just fine. Also, again in case you're not aware because it wasn't very well publicised when it was released, you can test your application before zipping it just by giving Python the name of the directory structured as above (python myapp). This won't catch dependencies that don't like being zipped, but it will save you having to go through zip/test/unzip/fix/rezip cycles during development. Anyway, I hope this is useful. Paul From mining.facts at gmail.com Fri Sep 23 06:22:50 2016 From: mining.facts at gmail.com (Christian) Date: Fri, 23 Sep 2016 03:22:50 -0700 (PDT) Subject: memory utilization blow up with dict structure In-Reply-To: References: <7b5ce1f2-67b7-463a-8679-e35def1be4e2@googlegroups.com> Message-ID: Am Freitag, 23. September 2016 12:02:47 UTC+2 schrieb Chris Angelico: > On Fri, Sep 23, 2016 at 7:05 PM, Christian wrote: > > I'm wondering why python blow up a dictionary structure so much. > > > > The ids and cat substructure could have 0..n entries but in the most cases they are <= 10,t is limited by <= 6. > > > > Example: > > > > {'0a0f7a3a0e09826caef1bff707785662': {'ids': {'aa316b86-8169-11e6-bab9-0050563e2d7c', > > 'aa3174f0-8169-11e6-bab9-0050563e2d7c', > > 'aa319408-8169-11e6-bab9-0050563e2d7c', > > 'aa3195e8-8169-11e6-bab9-0050563e2d7c', > > 'aa319732-8169-11e6-bab9-0050563e2d7c', > > 'aa319868-8169-11e6-bab9-0050563e2d7c', > > 'aa31999e-8169-11e6-bab9-0050563e2d7c', > > 'aa319b06-8169-11e6-bab9-0050563e2d7c'}, > > 't': {'type1', 'type2'}, > > 'dt': datetime.datetime(2016, 9, 11, 15, 15, 54, 343000), > > 'nids': 8, > > 'ntypes': 2, > > 'cat': [('ABC', 'aa316b86-8169-11e6-bab9-0050563e2d7c', '74', ''), > > ('ABC','aa3174f0-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > > ('ABC','aa319408-8169-11e6-bab9-0050563e2d7c','3', 'type1'), > > ('ABC','aa3195e8-8169-11e6-bab9-0050563e2d7c', '3', 'type2'), > > ('ABC','aa319732-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > > ('ABC','aa319868-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > > ('ABC','aa31999e-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > > ('ABC','aa319b06-8169-11e6-bab9-0050563e2d7c', '3', 'type2')]}, > > > > > > sys.getsizeof(superdict) > > 50331744 > > len(superdict) > > 941272 > > So... you have a million entries in the master dictionary, each of > which has an associated collection of data, consisting of half a dozen > things, some of which have subthings. The very smallest an object will > ever be on a 64-bit Linux system is 16 bytes: > > >>> sys.getsizeof(object()) > 16 > > and most of these will be much larger: > > >>> sys.getsizeof(8) > 28 > >>> sys.getsizeof(datetime.datetime(2016, 9, 11, 15, 15, 54, 343000)) > 48 > >>> sys.getsizeof([]) > 64 > >>> sys.getsizeof(('ABC', 'aa316b86-8169-11e6-bab9-0050563e2d7c', '74', '')) > 80 > >>> sys.getsizeof('aa316b86-8169-11e6-bab9-0050563e2d7c') > 85 > >>> sys.getsizeof({}) > 240 > > (Bear in mind that sys.getsizeof counts only the object itself, not > the things it references - that's why the tuple can take up less space > than one of its members.) Thanks for this clarification! > > I don't think your collections can average less than about 1KB (even > the textual representation of your example data is about that big), > and you have a million of them. That's a gigabyte of memory, right > there. Your peak memory usage is showing 3GB, so most likely, my > conservative estimates have put an absolute lower bound on this. Try > doing everything exactly the same as you did, only without actually > loading the pickle - then see what memory usage is. I think you'll > find that the usage is fully legitimate. > > > Thanks for any advice to save memory. > > Use a database. I suggest PostgreSQL. You won't have to load > everything into memory all at once that way, and (bonus!) you can even > update stuff on disk without rewriting everything. Yes it seems I haven't a chance to avoid that, especially because the dict example isn't smaller then it will be in real. I'm in a trade-off between performance and scalability , so the dict construction should be fast as possible and having reads+writes (using mongodb) is a performance drawback. Christian > ChrisA From __peter__ at web.de Fri Sep 23 08:34:14 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Sep 2016 14:34:14 +0200 Subject: memory utilization blow up with dict structure References: <7b5ce1f2-67b7-463a-8679-e35def1be4e2@googlegroups.com> Message-ID: Christian wrote: > Hi, > > I'm wondering why python blow up a dictionary structure so much. > > The ids and cat substructure could have 0..n entries but in the most cases > they are <= 10,t is limited by <= 6. > > Thanks for any advice to save memory. > Christian > > > Example: > > {'0a0f7a3a0e09826caef1bff707785662': {'ids': > {{'aa316b86-8169-11e6-bab9-0050563e2d7c', > 'aa3174f0-8169-11e6-bab9-0050563e2d7c', > 'aa319408-8169-11e6-bab9-0050563e2d7c', > 'aa3195e8-8169-11e6-bab9-0050563e2d7c', > 'aa319732-8169-11e6-bab9-0050563e2d7c', > 'aa319868-8169-11e6-bab9-0050563e2d7c', > 'aa31999e-8169-11e6-bab9-0050563e2d7c', > 'aa319b06-8169-11e6-bab9-0050563e2d7c'}, > 't': {'type1', 'type2'}, > 'dt': datetime.datetime(2016, 9, 11, 15, 15, 54, 343000), > 'nids': 8, > 'ntypes': 2, > 'cat': [('ABC', 'aa316b86-8169-11e6-bab9-0050563e2d7c', '74', ''), > ('ABC','aa3174f0-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa319408-8169-11e6-bab9-0050563e2d7c','3', 'type1'), > ('ABC','aa3195e8-8169-11e6-bab9-0050563e2d7c', '3', 'type2'), > ('ABC','aa319732-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa319868-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa31999e-8169-11e6-bab9-0050563e2d7c', '3', 'type1'), > ('ABC','aa319b06-8169-11e6-bab9-0050563e2d7c', '3', 'type2')]}, Not so much to save memory, but because redundant data always bears the risk to get out of sync: For a value v in your dict, do v["ids"] == {t[1] for t in v["cat"]} len(v["ids"]) == len(v["cat"]) v["nids"] == len(v["ids"]) v["ntypes"] == len(v["t"]) v["t"] == {t[-1] for t in v["cat"]} - {""} always hold? And if you want to go fancy: are the IDs always 128-bit integers that share all but the leading 32 bits? From irmen.NOSPAM at xs4all.nl Fri Sep 23 15:50:40 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 23 Sep 2016 21:50:40 +0200 Subject: pypy on windows much slower than linux/mac when using complex number type? In-Reply-To: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> References: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> Message-ID: <57e5878f$0$907$e4fe514c@news.xs4all.nl> On 20-9-2016 22:38, Irmen de Jong wrote: > Hi, > > I've stumbled across a peculiar performance issue with Pypy across some different > platforms. It was very visible in some calculation heavy code that I wrote that uses > Python's complex number type to calculate the well-known Mandelbrot set. > > Pypy running the code on my Windows machine is doing okay, but when running the same > code on Pypy on different systems, the performance difference is so big it is not even > funny. The other implementations are MUCH faster than the windows one. Which is quite > unexpected because the other machines I've tested on have the same or much lower > physical CPU specs than the windows machine. Here's the comparison: > > Machine specs: > Windows: 64 bits Windows 7, Intel Core 2 Quad 3.4 Ghz > Linux: 32 bits Mint 18, Virtualbox VM on above windows machine > Mac mini: OS X 10.11.6, Intel Core 2 Duo 2.53 Ghz > > The test code I've been using is here: > https://gist.github.com/irmen/c6b12b4cf88a6a4fcf5ff721c7089078 > > Test results: > function: mandel / iterations > Mac mini, Pypy 5.4.1 (64-bit): 0.81 sec / 0.65 sec > Linux, Pypy 5.1 (32-bit): 1.06 sec / 0.64 sec > Windows, Pypy 5.4.1 (32-bit): 5.59 sec / 2.87 sec > > > What could cause such a huge difference? > > Is it perhaps a compiler issue (where gcc/clang are MUCH better at optimizing certain > things, although I wonder how much of a factor this is because Pypy is doing JITting by > itself as far as I am aware)? Or is something strange going on with the way the > complex number type is implemented? (the difference doesn't occur when using only floats) > > > Regards > Irmen de Jong > The problem boiled down to a performance issue in window's 32 bits implementation of the hypot() function (which abs(z) uses when z is a complex number type). The 64 bits windows crt lib version is much faster (on par with what is to be expected from the linux or osx version), but unfortunately there's no 64 bits pypy implementation for windows. Replacing abs(z) by sqrt(r*r+i*i) avoids the problem and is even faster still. More details here https://bitbucket.org/pypy/pypy/issues/2401 Cheers Irmen de Jong From lawrencedo99 at gmail.com Fri Sep 23 19:58:57 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 23 Sep 2016 16:58:57 -0700 (PDT) Subject: Obtain the raw line of text read by CSVDictReader when reporting errors? In-Reply-To: References: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> <1474540596.3768055.733613513.361F593B@webmail.messagingengine.com> Message-ID: On Friday, September 23, 2016 at 3:38:21 AM UTC+12, Chris Angelico wrote: > This is why, despite the confusion it sometimes causes, we all prefer > duck typing to static typing. The csv.DictReader wants a "file-like > object", not necessarily a file - and in this case, all it asks is an > iterable of lines, so a simple generator will work. This is true of > MANY, if not all, places that a file is used. Duck type is great for sticking pieces of Python code together. And anybody who doesn?t like it can go Java themselves... From lawrencedo99 at gmail.com Fri Sep 23 20:02:38 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 23 Sep 2016 17:02:38 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> Message-ID: On Thursday, September 22, 2016 at 8:34:20 AM UTC+12, Emile wrote: > Hmm, then I'll have to wait longer to experience the unreliability as > the handful of automated gui tools I'm running has only been up 10 to 12 > years or so. You sound like you have a solution for the OP, then. From python.list at tim.thechases.com Fri Sep 23 20:21:32 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 23 Sep 2016 19:21:32 -0500 Subject: Obtain the raw line of text read by CSVDictReader when reporting errors? In-Reply-To: References: <1474489715.2745483.733050689.6CC83837@webmail.messagingengine.com> <1474540596.3768055.733613513.361F593B@webmail.messagingengine.com> Message-ID: <20160923192132.047cbd8d@bigbox.christie.dr> On 2016-09-23 16:58, Lawrence D?Oliveiro wrote: > Duck type is great for sticking pieces of Python code together. > > And anybody who doesn?t like it can go Java themselves... Sorry, my source code doesn't declare that I support JavaInterface... -tkc From lawrencedo99 at gmail.com Fri Sep 23 21:42:59 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 23 Sep 2016 18:42:59 -0700 (PDT) Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: References: <85d1jwo9jv.fsf@benfinney.id.au> Message-ID: <37df7980-c8b3-4071-8ae6-0841a284123f@googlegroups.com> On Friday, September 23, 2016 at 4:25:21 AM UTC+12, Chris Angelico wrote: > For reference, the Decimal module (ignoring the C accelerator) is over six > thousand lines of code, as a single module. Now, that might be pushing the > boundaries a bit ... What ?boundaries? do you think that might be pushing? 6000 lines doesn?t sound unreasonable to me at all. From rosuav at gmail.com Fri Sep 23 22:10:50 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 24 Sep 2016 12:10:50 +1000 Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: <37df7980-c8b3-4071-8ae6-0841a284123f@googlegroups.com> References: <85d1jwo9jv.fsf@benfinney.id.au> <37df7980-c8b3-4071-8ae6-0841a284123f@googlegroups.com> Message-ID: On Sat, Sep 24, 2016 at 11:42 AM, Lawrence D?Oliveiro wrote: > On Friday, September 23, 2016 at 4:25:21 AM UTC+12, Chris Angelico wrote: >> For reference, the Decimal module (ignoring the C accelerator) is over six >> thousand lines of code, as a single module. Now, that might be pushing the >> boundaries a bit ... > > What ?boundaries? do you think that might be pushing? 6000 lines doesn?t sound unreasonable to me at all. It's a large and complex module, and about at the boundary of being broken up a bit. So it's likely to be the largest file in the stdlib (not counting tests). ChrisA From lawrencedo99 at gmail.com Sat Sep 24 02:59:42 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 23 Sep 2016 23:59:42 -0700 (PDT) Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: References: <85d1jwo9jv.fsf@benfinney.id.au> <37df7980-c8b3-4071-8ae6-0841a284123f@googlegroups.com> Message-ID: <085eeaeb-af0a-487e-bb35-6f32055d50b7@googlegroups.com> On Saturday, September 24, 2016 at 2:11:09 PM UTC+12, Chris Angelico wrote: > It's a large and complex module, and about at the boundary of being > broken up a bit. Splitting it up would make it slower to load. From auriocus at gmx.de Sat Sep 24 03:22:04 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 24 Sep 2016 09:22:04 +0200 Subject: pypy on windows much slower than linux/mac when using complex number type? In-Reply-To: <57e5878f$0$907$e4fe514c@news.xs4all.nl> References: <57e19e2a$0$845$e4fe514c@news.xs4all.nl> <57e5878f$0$907$e4fe514c@news.xs4all.nl> Message-ID: Am 23.09.16 um 21:50 schrieb Irmen de Jong: > The problem boiled down to a performance issue in window's 32 bits implementation of the > hypot() function (which abs(z) uses when z is a complex number type). > The 64 bits windows crt lib version is much faster (on par with what is to be expected > from the linux or osx version), but unfortunately there's no 64 bits pypy > implementation for windows. > Replacing abs(z) by sqrt(r*r+i*i) avoids the problem and is even faster still. Interesting! Now beware that a "real" hypot function does approximately the following: def myhypot(r, i): if abs(r)>abs(i): c = i/r return abs(r)*sqrt(1+c*c) else: if i==0: return 0.0 else: c=r/i return abs(i)*sqrt(1+c*c) it can well be, that the old 32bit MSVCRT does simply that, which requires some floating point ops, whereas the more modern 64bit lib uses hand-tuned SSE to perform the equivalent. Just for fun, you could try this hypot to see how it performs. Christian From dieter at handshake.de Sat Sep 24 04:07:59 2016 From: dieter at handshake.de (dieter) Date: Sat, 24 Sep 2016 10:07:59 +0200 Subject: PyThreadState_Get References: Message-ID: <87zimxk9eo.fsf@handshake.de> Bharadwaj Srivatsa writes: > Which ever project I am trying to install using python setup.py install command, i am getting the following error.. > > python -mtrace --trace setup.py install > Fatal Python error: PyThreadState_Get: no current thread > ABORT instruction (core dumped) > > How to get rid of this error and whats the cause for this What happens when you omit "-mtrace --trace"? From steve+python at pearwood.info Sat Sep 24 06:47:57 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 24 Sep 2016 20:47:57 +1000 Subject: How to import all things defined the files in a module directory in __init__.py? References: <85d1jwo9jv.fsf@benfinney.id.au> <37df7980-c8b3-4071-8ae6-0841a284123f@googlegroups.com> <085eeaeb-af0a-487e-bb35-6f32055d50b7@googlegroups.com> Message-ID: <57e659df$0$1619$c3e8da3$5496439d@news.astraweb.com> On Sat, 24 Sep 2016 04:59 pm, Lawrence D?Oliveiro wrote: > On Saturday, September 24, 2016 at 2:11:09 PM UTC+12, Chris Angelico > wrote: >> It's a large and complex module, and about at the boundary of being >> broken up a bit. > > Splitting it up would make it slower to load. Would it? You've bench marked it and found that it makes a significant difference? In any case, you're missing the point. Size carries its own cost to the human reader, never mind whether or not the interpreter can deal with it: https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two The decimal module is approaching a size where it is no longer comfortable to read or edit: - 6450 lines in the source file (include comments, blanks, etc); - 27 top-level functions; - 54 global variables/constants; - 19 classes, which isn't too bad on its own, but: - one of those classes has 83 methods; - and another has 127 methods; - the Decimal class itself is 3311 lines alone; excluding blanks, comments and docstrings, it is 2013 SLOC. This a partly a matter of taste, and to my taste, the decimal module is about as big as I would like to see a module before I split it into submodules purely on the basis of size. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tristan.trouwen at gmail.com Sat Sep 24 06:59:35 2016 From: tristan.trouwen at gmail.com (Tristan Trouwen) Date: Sat, 24 Sep 2016 12:59:35 +0200 Subject: Address boundary error when trying to use Image.putdata(array) from PIL Message-ID: <1474714775.5931.1.camel@gmail.com> Got a signal boundary error. Steps to reproduce: open python console Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from PIL import Image >>> im = Image.open('HKJL.jpg') >>> import numpy as np >>> arr = np.array(im) >>> arr[arr < 10] = 0 >>> im.putdata(arr) fish: ?python? terminated by signal SIGSEGV (Address boundary error) The image I used: http://i.imgur.com/hnuzhFj.jpg From 007brendan at gmail.com Sat Sep 24 07:32:32 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Sat, 24 Sep 2016 04:32:32 -0700 Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: <085eeaeb-af0a-487e-bb35-6f32055d50b7@googlegroups.com> References: <85d1jwo9jv.fsf@benfinney.id.au> <37df7980-c8b3-4071-8ae6-0841a284123f@googlegroups.com> <085eeaeb-af0a-487e-bb35-6f32055d50b7@googlegroups.com> Message-ID: > Splitting it up would make it slower to load. It's usually the opposite. When packages are split up, you only have to load the specific portions you need. Putting it all in a single module forces you to always load everything. On Fri, Sep 23, 2016 at 11:59 PM, Lawrence D?Oliveiro < lawrencedo99 at gmail.com> wrote: > On Saturday, September 24, 2016 at 2:11:09 PM UTC+12, Chris Angelico wrote: > > It's a large and complex module, and about at the boundary of being > > broken up a bit. > > Splitting it up would make it slower to load. > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat Sep 24 10:25:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Sep 2016 00:25:43 +1000 Subject: How to import all things defined the files in a module directory in __init__.py? In-Reply-To: References: <85d1jwo9jv.fsf@benfinney.id.au> <37df7980-c8b3-4071-8ae6-0841a284123f@googlegroups.com> <085eeaeb-af0a-487e-bb35-6f32055d50b7@googlegroups.com> Message-ID: On Sat, Sep 24, 2016 at 9:32 PM, Brendan Abel <007brendan at gmail.com> wrote: >> Splitting it up would make it slower to load. > > It's usually the opposite. When packages are split up, you only have to > load the specific portions you need. Putting it all in a single module > forces you to always load everything. This can be true ONLY if they're sufficiently separate that most users can pick and choose. If the bulk of users are going to need every piece, the split will slow it down significantly. ChrisA From peter.brittain.os at gmail.com Sat Sep 24 11:04:45 2016 From: peter.brittain.os at gmail.com (Peter Brittain) Date: Sat, 24 Sep 2016 16:04:45 +0100 Subject: ANN: asciimatics v1.7.0 Message-ID: I am very pleased to announce asciimatics v1.7.0! This is a major update since the last announced version of the package. ## What is asciimatics? Asciimatics is a package to help people create full-screen text UIs (from interactive forms to complex text animations) on Linux, Windows and OSX. It supports python 2 & 3 and is licensed under the Apache Software Foundation License 2.0. ## What?s new? This release includes a `widgets` sub-package to create text User Interfaces, complete with the standard basic set of widgets you would expect for creating forms ? e.g. text boxes, check boxes, buttons, etc. Despite its name, asciimatics now fully supports Unicode in utf-8 environments, allowing for non-ASCII input from the keyboard and output to the screen. This is extended to the widgets, so you can use them for languages other than English. A new Plasma renderer was added, continuing the theme of retro special effects. This one can be used to create lava-lamp style animated backgrounds. See the new plasma.py sample for an example of how to use it. A `highlight()` method was added to the Screen to allow you to colour wash parts of the screen as if you were using a highlighter pen. This can be used to highlight or lowlight parts of the screen. For an example, have a look at the shadows on a Frame in the forms.py sample. A complete suite of unit tests and CI builds have been created, to ensure that the code continues to run across all supported environments. Latest results are always available at the project home page. Various other minor enhancements and fixes have gone in. For a complete list have a look at the change log: https://raw.githubusercontent.com/peterbrittain/asciimatics/ master/CHANGES.rst ## Where can I find out more? https://github.com/peterbrittain/asciimatics From python at bdurham.com Sat Sep 24 11:14:53 2016 From: python at bdurham.com (Malcolm Greene) Date: Sat, 24 Sep 2016 11:14:53 -0400 Subject: Looking for tips and gotchas for working with Python 3.5 zipapp feature In-Reply-To: <94ad9b41-0278-48be-9076-6989333b80b4@googlegroups.com> References: <1474346736.598636.730985801.507A5EED@webmail.messagingengine.com> <94ad9b41-0278-48be-9076-6989333b80b4@googlegroups.com> Message-ID: <1474730093.4168950.735763745.2CCC88A7@webmail.messagingengine.com> Hi Paul, > Just one further note, which may or may not be obvious. If your application uses external dependencies from PyPI, you can bundle them with your application using pip's --target option ... Cool stuff! To your question: None of what you've shared has been obvious to me :) Packaging and distributing Python scripts as zipped archives is such a powerful feature I'm surprised that there hasn't been more written on this topic. Thank you for sharing these tips with me and the rest of the Python list community !! Malcolm From lawrencedo99 at gmail.com Sat Sep 24 17:49:01 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 24 Sep 2016 14:49:01 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <6c034c70-1b03-4fb8-96cb-23007ee8bba4@googlegroups.com> <523cf846-7901-4afd-afe4-a5de1faa4b98@googlegroups.com> Message-ID: <1b6921cb-f03f-45b7-a6dc-3649f7c2d4e7@googlegroups.com> On Monday, September 19, 2016 at 6:47:27 PM UTC+12, Christian Gollwitzer wrote: > Still, sometimes you just need to get the job done and it doesn't matter how. That is why the situation continues; because you keep showing a willingness to put up with it. From python at mrabarnett.plus.com Sat Sep 24 18:32:28 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Sep 2016 23:32:28 +0100 Subject: Address boundary error when trying to use Image.putdata(array) from PIL In-Reply-To: <1474714775.5931.1.camel@gmail.com> References: <1474714775.5931.1.camel@gmail.com> Message-ID: <30844650-d04d-1e85-9608-acd7ca4d9379@mrabarnett.plus.com> On 2016-09-24 11:59, Tristan Trouwen wrote: > Got a signal boundary error. > > Steps to reproduce: > open python console > > Python 2.7.9 (default, Jun 29 2016, 13:08:31) > [GCC 4.9.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from PIL import Image >>>> im = Image.open('HKJL.jpg') >>>> import numpy as np >>>> arr = np.array(im) >>>> arr[arr < 10] = 0 >>>> im.putdata(arr) > fish: ?python? terminated by signal SIGSEGV (Address boundary error) > > The image I used: http://i.imgur.com/hnuzhFj.jpg > That looks like a bug. I'm on Python 3.5 on Windows and I get an exception: SystemError: new style getargs format but argument is not a tuple From what I've been able to find out, the argument of 'putdata' should be a list (sequence) of tuples. A quicker way is to create a new image from the array: im = Image.fromarray(arr) From chitturk at uah.edu Sat Sep 24 21:20:15 2016 From: chitturk at uah.edu (chitturk at uah.edu) Date: Sat, 24 Sep 2016 18:20:15 -0700 (PDT) Subject: sphinx (or other means to document python) In-Reply-To: <0e8c5dd4-6a64-45dc-adc9-e2dd58790ca2@googlegroups.com> References: <0e8c5dd4-6a64-45dc-adc9-e2dd58790ca2@googlegroups.com> Message-ID: <377e472c-f7f1-4947-be5e-72a19de2470c@googlegroups.com> On Sunday, September 11, 2016 at 3:56:36 PM UTC-5, chit... at uah.edu wrote: (about being frustrated with sphinx) I _remain_ frustrated - even as I finally figured out how to use it (thanks to a complete example from a friend) sphinx is very picky about spaces, lines - I had a line with some math formula spaces and tabs (after r''' - and sphinx kept ignoring that line when it works, the documentation (my preference is LaTeX) is great - the procedure for embedding the documentation as doctrings can be difficult, at times noweb is considerably simpler - but does not allow for the extraction of docstrings/comments - and does provide for a fairly painless way to combine comments, documentation along with code From kaiser.yann at gmail.com Sat Sep 24 21:30:38 2016 From: kaiser.yann at gmail.com (Yann Kaiser) Date: Sun, 25 Sep 2016 01:30:38 +0000 Subject: sphinx (or other means to document python) In-Reply-To: <377e472c-f7f1-4947-be5e-72a19de2470c@googlegroups.com> References: <0e8c5dd4-6a64-45dc-adc9-e2dd58790ca2@googlegroups.com> <377e472c-f7f1-4947-be5e-72a19de2470c@googlegroups.com> Message-ID: pydoctor may be something you're looking for. I don't know if it supports exporting to PDF like Sphinx does. As you've no doubt figured out by now, Sphinx doesn't revolve around the Python files themselves, but rather .rst files in which you can indeed instruct Sphinx to just go and document a module. On Sun, Sep 25, 2016, 02:26 wrote: > On Sunday, September 11, 2016 at 3:56:36 PM UTC-5, chit... at uah.edu wrote: > (about being frustrated with sphinx) > > I _remain_ frustrated - even as I finally figured out how to use it > (thanks to a complete example from a friend) > > sphinx is very picky about spaces, lines - I had a line with some math > formula spaces and tabs (after r''' - and sphinx kept ignoring that line > > when it works, the documentation (my preference is LaTeX) is great - the > procedure for embedding the documentation as doctrings can be difficult, at > times > > noweb is considerably simpler - but does not allow for the extraction > of docstrings/comments - and does provide for a fairly painless way to > combine comments, documentation along with code > -- > https://mail.python.org/mailman/listinfo/python-list > -- Yann Kaiser kaiser.yann at gmail.com yann.kaiser at efrei.net +33 6 51 64 01 89 https://github.com/epsy From martin.schoon at gmail.com Sun Sep 25 06:16:29 2016 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 25 Sep 2016 10:16:29 GMT Subject: How to convert =?UTF-8?Q?=27=C3=B6=27?= to 'oe' or 'o' (or other similar things) in a string? References: <10707163.O9o76ZdvQC@PointedEars.de> <11618291.uLZWGnKmhe@PointedEars.de> <9a0ae32e-1eec-4973-9bf0-7c851ff161ed@googlegroups.com> Message-ID: Den 2016-09-25 skrev wxjmfauth at gmail.com : > > As an European guy, I recommend to use the characters > set used in the "official" font families used in Germany: > BundesSerif / BundesSans. > > See > https://styleguide.bundesregierung.de/Webs/SG/DE/PrintMedien/Basiselemente/Schriften/schriften_node.html?__site=SG > HTTP Status 404 Die Seite konnte leider nicht gefunden werden. :-( Manually poking around I still arrive at: https://styleguide.bundesregierung.de/Webs/SG/DE/PrintMedien/Basiselemente/Schriften/schriften_node.html?__site=SG Strange. /Martin From auriocus at gmx.de Sun Sep 25 06:47:05 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 25 Sep 2016 12:47:05 +0200 Subject: =?UTF-8?Q?Re:_How_to_convert_'=c3=b6'_to_'oe'_or_'o'_=28or_other_si?= =?UTF-8?Q?milar_things=29_in_a_string=3f?= In-Reply-To: <11618291.uLZWGnKmhe@PointedEars.de> References: <10707163.O9o76ZdvQC@PointedEars.de> <11618291.uLZWGnKmhe@PointedEars.de> Message-ID: Am 25.09.16 um 01:08 schrieb Thomas 'PointedEars' Lahn: > Christian Gollwitzer wrote: > >> Am 17.09.16 um 23:19 schrieb Thomas 'PointedEars' Lahn: >>> Peng Yu wrote: >>>> Hi, I want to convert strings in which the characters with accents >>>> should be converted to the ones without accents. >>> [?] >>>> [?] >>>> ./main.py F?rstemann >>> >>> AFAIK, ???, ???, and ??? are not accented characters in any natural >>> language, but characters of their own (umlauts). >>> >>> In particular, I know for certain that they are not accented in Germanic >>> languages. Swedish has been mentioned; I can add my native language, >>> German, to that list. >> >> In German, they are letters, > > If you read more carefully, my point was: In German, umlauts are not > "accented characters". > >> but they collate as either ae, oe, ue >> (rarely) or a, o, u (modern style). > > Correct, but irrelevant. The OP did not say anything about sorting. > > Fallacy: Red herring. > Fallacy: Thinking that I disagree with you. Christian From steve+python at pearwood.info Sun Sep 25 07:06:07 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 25 Sep 2016 21:06:07 +1000 Subject: How to convert =?UTF-8?B?J8O2Jw==?= to 'oe' or 'o' (or other similar things) in a string? References: <10707163.O9o76ZdvQC@PointedEars.de> <11618291.uLZWGnKmhe@PointedEars.de> Message-ID: <57e7afa1$0$1590$c3e8da3$5496439d@news.astraweb.com> On Sun, 25 Sep 2016 09:08 am, Thomas 'PointedEars' Lahn wrote: > Christian Gollwitzer wrote: > >> Am 17.09.16 um 23:19 schrieb Thomas 'PointedEars' Lahn: >>> Peng Yu wrote: >>>> Hi, I want to convert strings in which the characters with accents >>>> should be converted to the ones without accents. >>> [?] >>>> [?] >>>> ./main.py F?rstemann >>> >>> AFAIK, ???, ???, and ??? are not accented characters in any natural >>> language, but characters of their own (umlauts). >>> >>> In particular, I know for certain that they are not accented in Germanic >>> languages. Swedish has been mentioned; I can add my native language, >>> German, to that list. >> >> In German, they are letters, > > If you read more carefully, my point was: In German, umlauts are not > "accented characters". The umlauts themselves are not. But the combination of vowel-plus-umlaut is surely an "accented character", is it not? If not, what do you call it in German? My understanding is that both officially and popularly, native German speakers consider that the alphabet has 26 letters (same as English), and that "accented characters" including the vowels which take umlauts are not distinct letters of the alphabet but mere variations of the standard vowels. That's to be contrasted to (say) Swedish, where ? and ? are *not* "a and o with an accent/diacritic/umlaut/diaeresis/trema" but distinct letters of the alphabet in their own right. That's different from ? (the "German Y") in Swedish, which is only used for loan words and names of German origin, and *is* considered to be a variant of u. I use the term "accented character" here in the ignorant, non-linguist, English-speaker sense of any letter of the alphabet with "funny dots and squiggles" on it. To people who know what they are talking about, there is a difference between an accent, umlaut, trema, diaeresis and other diacritics, but for the purposes of my question, I'm not too worried about the technical difference between these modifiers, only whether or not they are considered a modifier on a standard letter or not. [...] > And as you have mentioned phone books, in all German-speaking phone books > I have come across so far, ??? does sort like ?ae?, ??? like ?oe?, and ??? > like ?ue? (this is specified in DIN 5007 as ?variant 1?). > > (That does not mean, however, that it is a good idea to *convert* those > letters this way. And there is no good reason to; all modern operating > systems, filesystems and name schemes support Unicode.) Alas, if we only needed to deal with modern operating systems, file systems and naming schemes, life would be much easier. But sadly we also have to deal with *old* operating systems, file systems and naming schemes; as well as ASCII-only or other non-Unicode applications, plus keyboards that give the user no obvious or easy way to add "accents" (diacritics etc.) to base letters. See, for example: http://code.activestate.com/recipes/251871-latin1-to-ascii-the-unicode-hammer/ As the author says: "One of my clients gets address data from Europe, but most of their systems cannot handle Latin-1 characters. With all due respect to the umlaut, scharfes s, cedilla, and all the other fine accented characters of Europe, all I needed to do was to prepare addresses for a shipping system." Post offices and freight companies are used to dealing with misspelled addresses. They can usually cope with a few missing accents. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jsf80238 at gmail.com Sun Sep 25 13:46:14 2016 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 25 Sep 2016 11:46:14 -0600 Subject: Stompy Message-ID: My goal is to send messages to an AMQ server using Python 3.3. I found Stompy and performed 2to3-3.3 before building. I am open to non-Stompy solutions. My code: from stompy.stomp import Stomp my_stomp = Stomp(AMQ_HOST, AMQ_PORT) my_stomp.connect(AMQ_USERNAME, AMQ_PASSWORD) My error: Traceback (most recent call last): File "temp.py", line 8, in my_stomp.connect(AMQ_USERNAME, AMQ_PASSWORD) File "/lclapps/oppen/thirdparty/stompy/stomp.py", line 48, in connect self.frame.connect(self.sock, username=username, password=password, clientid=clientid) File "/lclapps/oppen/thirdparty/stompy/frame.py", line 92, in connect self.send_frame(frame.as_string()) File "/lclapps/oppen/thirdparty/stompy/frame.py", line 250, in send_frame self.sock.sendall(frame) TypeError: 'str' does not support the buffer interface From python at mrabarnett.plus.com Sun Sep 25 14:16:46 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Sep 2016 19:16:46 +0100 Subject: Stompy In-Reply-To: References: Message-ID: <1c94ada7-a11f-b6a6-25b8-dc2bc9714087@mrabarnett.plus.com> On 2016-09-25 18:46, Jason Friedman wrote: > My goal is to send messages to an AMQ server using Python 3.3. I found > Stompy and performed > 2to3-3.3 before building. I am open to non-Stompy solutions. > > My code: > from stompy.stomp import Stomp > my_stomp = Stomp(AMQ_HOST, AMQ_PORT) > my_stomp.connect(AMQ_USERNAME, AMQ_PASSWORD) > > > My error: > Traceback (most recent call last): > File "temp.py", line 8, in > my_stomp.connect(AMQ_USERNAME, AMQ_PASSWORD) > File "/lclapps/oppen/thirdparty/stompy/stomp.py", line 48, in connect > self.frame.connect(self.sock, username=username, password=password, > clientid=clientid) > File "/lclapps/oppen/thirdparty/stompy/frame.py", line 92, in connect > self.send_frame(frame.as_string()) > File "/lclapps/oppen/thirdparty/stompy/frame.py", line 250, in send_frame > self.sock.sendall(frame) > TypeError: 'str' does not support the buffer interface > I expected you've used Unicode strings for AMQ_USERNAME and AMQ_PASSWORD, but if Stompy was written for Python 2, it'll be expecting bytestrings instead. You'll need to do more work on Stompy to fix the parts that 2to3 missed. From 380162267qq at gmail.com Sun Sep 25 16:43:55 2016 From: 380162267qq at gmail.com (380162267qq at gmail.com) Date: Sun, 25 Sep 2016 13:43:55 -0700 (PDT) Subject: Is 'learning python 5th edition' a good book to beginner? Message-ID: <74ea84f2-9bd1-4bb5-8d5c-c71e279c62e0@googlegroups.com> I want to find a python book like C++ primer which provides me details to understand the language. From lawrencedo99 at gmail.com Sun Sep 25 16:50:34 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 25 Sep 2016 13:50:34 -0700 (PDT) Subject: Is 'learning python 5th edition' a good book to beginner? In-Reply-To: <74ea84f2-9bd1-4bb5-8d5c-c71e279c62e0@googlegroups.com> References: <74ea84f2-9bd1-4bb5-8d5c-c71e279c62e0@googlegroups.com> Message-ID: <91924727-62a0-42bc-acea-99d6577da4db@googlegroups.com> Judging from the table of contents , it spends too much time (i.e. > 0) talking about Python 2. From anujgupta82 at gmail.com Sun Sep 25 21:16:09 2016 From: anujgupta82 at gmail.com (anujgupta82 at gmail.com) Date: Sun, 25 Sep 2016 18:16:09 -0700 (PDT) Subject: Dynamically updating Graph in python Message-ID: 0 down vote favorite I have a M x N 2D array: ith row represents that value of N points at time i. I want to visualize the points [1 row of the array] in the form of a graph where the values get updated after a small interval. Thus the graph shows 1 row at a time, then update the values to next row, so on and so forth. I want to do this in a jupyter notebook. Looking for reference codes. I tried following things but no success: http://community.plot.ly/t/updating-graph-with-new-data-every-100-ms-or-so/812 https://pythonprogramming.net/live-graphs-matplotlib-tutorial/ http://stackoverflow.com/questions/5618620/create-dynamic-updated-graph-with-python http://stackoverflow.com/questions/11371255/update-lines-in-matplotlib From robertvstepp at gmail.com Sun Sep 25 21:41:39 2016 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 25 Sep 2016 20:41:39 -0500 Subject: Is 'learning python 5th edition' a good book to beginner? In-Reply-To: <91924727-62a0-42bc-acea-99d6577da4db@googlegroups.com> References: <74ea84f2-9bd1-4bb5-8d5c-c71e279c62e0@googlegroups.com> <91924727-62a0-42bc-acea-99d6577da4db@googlegroups.com> Message-ID: On Sun, Sep 25, 2016 at 3:50 PM, Lawrence D?Oliveiro wrote: > Judging from the table of contents , it spends too much time (i.e. > 0) talking about Python 2. I own this book. The 5th edition covers both Python 3.3 and 2.7. Its emphasis is slanted to 3.3, but it *thoroughly* covers the core language for both. As far as the OP's original question, if he is comfortable with programming in other languages, then this book can serve him well if he wants to know all the details of the language. The author does use a tutorial approach, but it is a massive text that tries to cover everything in the core language with selected examination of parts of the standard library. HTH! -- boB From jsf80238 at gmail.com Sun Sep 25 22:10:23 2016 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 25 Sep 2016 20:10:23 -0600 Subject: Stompy In-Reply-To: <1c94ada7-a11f-b6a6-25b8-dc2bc9714087@mrabarnett.plus.com> References: <1c94ada7-a11f-b6a6-25b8-dc2bc9714087@mrabarnett.plus.com> Message-ID: > > My error: >> Traceback (most recent call last): >> File "temp.py", line 8, in >> my_stomp.connect(AMQ_USERNAME, AMQ_PASSWORD) >> File "/lclapps/oppen/thirdparty/stompy/stomp.py", line 48, in connect >> self.frame.connect(self.sock, username=username, password=password, >> clientid=clientid) >> File "/lclapps/oppen/thirdparty/stompy/frame.py", line 92, in connect >> self.send_frame(frame.as_string()) >> File "/lclapps/oppen/thirdparty/stompy/frame.py", line 250, in >> send_frame >> self.sock.sendall(frame) >> TypeError: 'str' does not support the buffer interface >> >> I expected you've used Unicode strings for AMQ_USERNAME and AMQ_PASSWORD, > but if Stompy was written for Python 2, it'll be expecting bytestrings > instead. > > You'll need to do more work on Stompy to fix the parts that 2to3 missed. Thanks for the advice, I will try that. I will also try https://pypi.python.org/pypi/stompest/. From gengyangcai at gmail.com Mon Sep 26 01:59:38 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 25 Sep 2016 22:59:38 -0700 (PDT) Subject: Nested for loops and print statements Message-ID: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> Why is it that you need a print() at the end to create the table for example 1: Example 1 --- >>> for row in range(10): for column in range(10): print("*",end=" ") # Print a blank line for next row print() * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * but not for Example 2 --- for row in range(10): print("*",end=" ") * * * * * * * * * * When I try to do example 1 without the print() statement at the end, I get this error : for row in range(10): for column in range(10): print("*",end=" ") SyntaxError: inconsistent use of tabs and spaces in indentation From jussi.piitulainen at helsinki.fi Mon Sep 26 02:29:09 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 26 Sep 2016 09:29:09 +0300 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> Message-ID: Cai Gengyang writes: > Why is it that you need a print() at the end to create the table for > example 1: > > Example 1 --- > >>>> for row in range(10): > for column in range(10): > print("*",end=" ") > > # Print a blank line for next row > print() [- -] > When I try to do example 1 without the print() statement at the end, I > get this error : > > for row in range(10): > for column in range(10): > print("*",end=" ") > > SyntaxError: inconsistent use of tabs and spaces in indentation That error has absolutely nothing to do with nested loops, and absolutely nothing to do with print statements. Nested loops and print statements are entirely coincidental to the error. You have managed to use a mixture of two different whitespace characters to indent the lines: horizontal tabs (character code 9, hex 9) and spaces (character code 32, hex 20). Different environments may interpret and display the tabs as different amounts of indentation, depending on their position in the line. That affects the meaning of a Python program. When you get this error, re-indent your lines. From tjreedy at udel.edu Mon Sep 26 02:47:26 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Sep 2016 02:47:26 -0400 Subject: Nested for loops and print statements In-Reply-To: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> Message-ID: On 9/26/2016 1:59 AM, Cai Gengyang wrote: > Why is it that you need a print() at the end to create the table for example 1: > > Example 1 --- > >>>> for row in range(10): > for column in range(10): > print("*",end=" ") > # Print a blank line for next row > print() These indents are either 4 or 8 spaces. The print provides a carriage return. Each line ends with a space. > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * > * * * * * * * * * * One can avoid both extra print and spaces with for row in range(10): for column in range(10): print("*", end=" " if column<9 else '\n') # or for row in range(10): print(' '.join(['*']*10)) # or print((' '.join(['*']*10)+'\n')*10) # or for row in range(10): print('* '*9 + '*') # or print(('* '*9 + '*\n')*10) > but not for Example 2 --- > > for row in range(10): > print("*",end=" ") > > * * * * * * * * * * > > When I try to do example 1 without the print() statement at the end, I get this error : > > for row in range(10): > for column in range(10): > print("*",end=" ") These indents are 4 spaces and 1 tabs. > SyntaxError: inconsistent use of tabs and spaces in indentation Because you mixed tabs and spaces. Has nothing to do with print statement. -- Terry Jan Reedy From gengyangcai at gmail.com Mon Sep 26 03:19:03 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 00:19:03 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> Message-ID: <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> So what do i need to do to correct the error ? Regards On Monday, September 26, 2016 at 2:48:16 PM UTC+8, Terry Reedy wrote: > On 9/26/2016 1:59 AM, Cai Gengyang wrote: > > Why is it that you need a print() at the end to create the table for example 1: > > > > Example 1 --- > > > >>>> for row in range(10): > > for column in range(10): > > print("*",end=" ") > > # Print a blank line for next row > > print() > > These indents are either 4 or 8 spaces. > > The print provides a carriage return. > Each line ends with a space. > > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > * * * * * * * * * * > > One can avoid both extra print and spaces with > > for row in range(10): > for column in range(10): > print("*", end=" " if column<9 else '\n') > > # or > for row in range(10): > print(' '.join(['*']*10)) > # or > print((' '.join(['*']*10)+'\n')*10) > > # or > for row in range(10): > print('* '*9 + '*') > # or > print(('* '*9 + '*\n')*10) > > > > but not for Example 2 --- > > > > for row in range(10): > > print("*",end=" ") > > > > * * * * * * * * * * > > > > When I try to do example 1 without the print() statement at the end, I get this error : > > > > for row in range(10): > > for column in range(10): > > print("*",end=" ") > > These indents are 4 spaces and 1 tabs. > > > SyntaxError: inconsistent use of tabs and spaces in indentation > > Because you mixed tabs and spaces. Has nothing to do with print statement. > > > -- > Terry Jan Reedy From ldlchina at gmail.com Mon Sep 26 03:19:23 2016 From: ldlchina at gmail.com (dl l) Date: Mon, 26 Sep 2016 15:19:23 +0800 Subject: Python C API: How to debug reference leak? Message-ID: I want to check the references of an object. Any way to get the references of an object with Python C API? Like: gc.get_referrs(), is there similar API in C lib? From jussi.piitulainen at helsinki.fi Mon Sep 26 03:21:11 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 26 Sep 2016 10:21:11 +0300 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> Message-ID: Cai Gengyang writes: > So what do i need to do to correct the error ? > > Regards > > > On Monday, September 26, 2016 at 2:48:16 PM UTC+8, Terry Reedy wrote: >> On 9/26/2016 1:59 AM, Cai Gengyang wrote: >> > Why is it that you need a print() at the end to create the table for example 1: >> > >> > Example 1 --- >> > >> >>>> for row in range(10): >> > for column in range(10): >> > print("*",end=" ") >> > # Print a blank line for next row >> > print() >> >> These indents are either 4 or 8 spaces. >> >> The print provides a carriage return. >> Each line ends with a space. >> >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> > * * * * * * * * * * >> >> One can avoid both extra print and spaces with >> >> for row in range(10): >> for column in range(10): >> print("*", end=" " if column<9 else '\n') >> >> # or >> for row in range(10): >> print(' '.join(['*']*10)) >> # or >> print((' '.join(['*']*10)+'\n')*10) >> >> # or >> for row in range(10): >> print('* '*9 + '*') >> # or >> print(('* '*9 + '*\n')*10) >> >> >> > but not for Example 2 --- >> > >> > for row in range(10): >> > print("*",end=" ") >> > >> > * * * * * * * * * * >> > >> > When I try to do example 1 without the print() statement at the end, I get this error : >> > >> > for row in range(10): >> > for column in range(10): >> > print("*",end=" ") >> >> These indents are 4 spaces and 1 tabs. >> >> > SyntaxError: inconsistent use of tabs and spaces in indentation >> >> Because you mixed tabs and spaces. Has nothing to do with print statement. >> >> >> -- >> Terry Jan Reedy Reindent your lines. From steve+comp.lang.python at pearwood.info Mon Sep 26 04:16:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 26 Sep 2016 18:16:23 +1000 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> Message-ID: <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> On Monday 26 September 2016 17:21, Jussi Piitulainen wrote: > Cai Gengyang writes: [snip 80 or so lines] > Reindent your lines. In case Cai doesn't know what "reindent" means: It depends on your text editor. At worst, you have to delete all the indents, and re-enter them, using ONLY spaces, or ONLY tabs, but never mixing them. Some text editors may have a command to reindent, or clean indentation, or fix indentation, or something similar. Or you can use the tabnanny.py program: python -m tabnanny path/to/file.py P.S. Hey Jussi, is the backspace key on your keyboard broken? Every time somebody bottom-posts without trimming, a pixie dies... -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From jussi.piitulainen at helsinki.fi Mon Sep 26 04:30:20 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 26 Sep 2016 11:30:20 +0300 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > P.S. Hey Jussi, is the backspace key on your keyboard broken? Every > time somebody bottom-posts without trimming, a pixie dies... I was annoyed by the top-posted one-liner in response to the last line of Terry's response. I responded in kind and then it was too late. I'm sorry. It was a childish thing to do. Backspace key is fine. I tend to use C-w and C-k for trimming, and they are fine, too. I was the broken part. From gengyangcai at gmail.com Mon Sep 26 04:32:09 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 01:32:09 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> Message-ID: <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> These are my attempts --- >>> for row in range(10): for column in range(10): print("*",end=" ") SyntaxError: inconsistent use of tabs and spaces in indentation >>> for row in range(10): for column in range(10): print("*",end=" ") SyntaxError: expected an indented block >>> for row in range(10): for column in range(10): print("*",end=" ") SyntaxError: inconsistent use of tabs and spaces in indentation >>> for row in range(10): for column in range(10): print("*",end=" ") SyntaxError: inconsistent use of tabs and spaces in indentation >>> for row in range(10): for column in range(10): print("*",end=" ") * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * On Monday, September 26, 2016 at 4:16:37 PM UTC+8, Steven D'Aprano wrote: > On Monday 26 September 2016 17:21, Jussi Piitulainen wrote: > > > Cai Gengyang writes: > [snip 80 or so lines] > > Reindent your lines. > > In case Cai doesn't know what "reindent" means: > > > It depends on your text editor. At worst, you have to delete all the indents, > and re-enter them, using ONLY spaces, or ONLY tabs, but never mixing them. > > Some text editors may have a command to reindent, or clean indentation, or fix > indentation, or something similar. > > Or you can use the tabnanny.py program: > > > python -m tabnanny path/to/file.py > > > > P.S. Hey Jussi, is the backspace key on your keyboard broken? Every time > somebody bottom-posts without trimming, a pixie dies... > > > > -- > Steven > git gets easier once you get the basic idea that branches are homeomorphic > endofunctors mapping submanifolds of a Hilbert space. From jussi.piitulainen at helsinki.fi Mon Sep 26 04:51:57 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 26 Sep 2016 11:51:57 +0300 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> Message-ID: Cai Gengyang writes: > These are my attempts --- > >>>> for row in range(10): > for column in range(10): > print("*",end=" ") > > SyntaxError: inconsistent use of tabs and spaces in indentation What do you type yourself? Could it be that your software starts the second line with a tab automatically and then you type spaces yourself? When I type commands to the Python interpreter, it looks like this: >>> if 1: ... print(1) ... 1 The interpreter inserts the dots below the prompt, and a space, and here I have inserted three more spaces for indentation. The interpreter then ignores those dots and space, and it doesn't seem to let me use any tabs anyway. You are running the interpreter in a different way. That's fine. But what exactly are you doing? (If you are using the spacebar, try the tabulation key instead. If you are using the tabulation key, try the spacebar instead.) From steve+comp.lang.python at pearwood.info Mon Sep 26 05:36:12 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 26 Sep 2016 19:36:12 +1000 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> Message-ID: <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> On Monday 26 September 2016 18:32, Cai Gengyang wrote: > These are my attempts --- That's nice. Do you have a question? > SyntaxError: inconsistent use of tabs and spaces in indentation When you indent, press TAB or SPACE but not both. This error can only happen if you are use spaces for some lines and tabs for other lines. Do not do that. Use spaces only or tabs only, never both. > SyntaxError: expected an indented block You forgot to indent at all. You must indent with at least one space or one tab. > SyntaxError: inconsistent use of tabs and spaces in indentation Use only spaces, or only tabs, never both. If you use spaces for one line, then always use spaces. If you use tabs for one line, then always use tabs. > SyntaxError: inconsistent use of tabs and spaces in indentation Same as above. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From Bill.Scherer at VerizonWireless.com Mon Sep 26 07:31:37 2016 From: Bill.Scherer at VerizonWireless.com (Scherer, Bill) Date: Mon, 26 Sep 2016 07:31:37 -0400 Subject: [E] ANN: asciimatics v1.7.0 In-Reply-To: References: Message-ID: Looks cool. Why does it want to install pypiwin32 on my 64bit Linux box? I installed all the requirements separately, but it still wants to install pypiwin32. (pypiwin32 appears to not support Python3) # pip3.5 install asciimatics Collecting asciimatics Using cached asciimatics-1.7.0-py2.py3-none-any.whl Requirement already satisfied (use --upgrade to upgrade): future in /usr/local/lib/python3.5/site-packages (from asciimatics) Requirement already satisfied (use --upgrade to upgrade): pyfiglet>=0.7.2 in /usr/local/lib/python3.5/site-packages (from asciimatics) Requirement already satisfied (use --upgrade to upgrade): Pillow>=2.7.0 in /usr/local/lib/python3.5/site-packages (from asciimatics) Collecting pypiwin32 (from asciimatics) Using cached pypiwin32-219.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-3_afj4p1/pypiwin32/setup.py", line 121 print "Building pywin32", pywin32_version ^ SyntaxError: Missing parentheses in call to 'print' -----Original Message----- From: Python-list [mailto:python-list-bounces+bill.scherer=verizonwireless.com at python.org] On Behalf Of Peter Brittain Sent: Saturday, September 24, 2016 11:05 AM To: python-announce-list at python.org; python-list at python.org Subject: [E] ANN: asciimatics v1.7.0 I am very pleased to announce asciimatics v1.7.0! This is a major update since the last announced version of the package. ## What is asciimatics? Asciimatics is a package to help people create full-screen text UIs (from interactive forms to complex text animations) on Linux, Windows and OSX. It supports python 2 & 3 and is licensed under the Apache Software Foundation License 2.0. ## What?s new? This release includes a `widgets` sub-package to create text User Interfaces, complete with the standard basic set of widgets you would expect for creating forms ? e.g. text boxes, check boxes, buttons, etc. Despite its name, asciimatics now fully supports Unicode in utf-8 environments, allowing for non-ASCII input from the keyboard and output to the screen. This is extended to the widgets, so you can use them for languages other than English. A new Plasma renderer was added, continuing the theme of retro special effects. This one can be used to create lava-lamp style animated backgrounds. See the new plasma.py sample for an example of how to use it. A `highlight()` method was added to the Screen to allow you to colour wash parts of the screen as if you were using a highlighter pen. This can be used to highlight or lowlight parts of the screen. For an example, have a look at the shadows on a Frame in the forms.py sample. A complete suite of unit tests and CI builds have been created, to ensure that the code continues to run across all supported environments. Latest results are always available at the project home page. Various other minor enhancements and fixes have gone in. For a complete list have a look at the change log: https://raw.githubusercontent.com/peterbrittain/asciimatics/ master/CHANGES.rst ## Where can I find out more? https://github.com/peterbrittain/asciimatics -- https://mail.python.org/mailman/listinfo/python-list From jeanmichel at sequans.com Mon Sep 26 09:16:12 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 26 Sep 2016 15:16:12 +0200 Subject: sphinx (or other means to document python) In-Reply-To: <377e472c-f7f1-4947-be5e-72a19de2470c@googlegroups.com> References: <0e8c5dd4-6a64-45dc-adc9-e2dd58790ca2@googlegroups.com> <377e472c-f7f1-4947-be5e-72a19de2470c@googlegroups.com> Message-ID: On 09/25/2016 03:20 AM, chitturk at uah.edu wrote: > On Sunday, September 11, 2016 at 3:56:36 PM UTC-5, chit... at uah.edu wrote: > (about being frustrated with sphinx) > > I _remain_ frustrated - even as I finally figured out how to use it (thanks to a complete example from a friend) > > sphinx is very picky about spaces, lines - I had a line with some math formula spaces and tabs (after r''' - and sphinx kept ignoring that line > > when it works, the documentation (my preference is LaTeX) is great - the procedure for embedding the documentation as doctrings can be difficult, at times > > noweb is considerably simpler - but does not allow for the extraction > of docstrings/comments - and does provide for a fairly painless way to combine comments, documentation along with code > Hi, Keep in mind sphinx has a greater scope than writing docs from/for python. You could use sphinx to document anything. That why it's not that straightforward to build doc from the source code. Yet it's possible with some scripts available on the internet. But it looks like you've managed to find out. Ultimately, sphinx is designed to write good documentation, and is slightly overkill if you want to build docs only from the source code. But keep in mind that this kind of doc tend to be poor. If you take a look at the python documentation, the paramount of good documentation :) you'll notice it's not generated from the code docstrings. For api reference documentation, the source code is sometimes the best option. jm From gengyangcai at gmail.com Mon Sep 26 11:25:15 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 08:25:15 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum >>> for row in range(10): for column in range(10): print("*",end="") SyntaxError: inconsistent use of tabs and spaces in indentation >>> for row in range(10): for column in range(10): print("*",end="") **************************************************************************************************** On Monday, September 26, 2016 at 5:36:26 PM UTC+8, Steven D'Aprano wrote: > On Monday 26 September 2016 18:32, Cai Gengyang wrote: > > > These are my attempts --- > > That's nice. Do you have a question? > > > > SyntaxError: inconsistent use of tabs and spaces in indentation > > When you indent, press TAB or SPACE but not both. > > This error can only happen if you are use spaces for some lines and tabs for > other lines. Do not do that. Use spaces only or tabs only, never both. > > > > SyntaxError: expected an indented block > > You forgot to indent at all. You must indent with at least one space or one > tab. > > > SyntaxError: inconsistent use of tabs and spaces in indentation > > Use only spaces, or only tabs, never both. If you use spaces for one line, then > always use spaces. If you use tabs for one line, then always use tabs. > > > SyntaxError: inconsistent use of tabs and spaces in indentation > > Same as above. > > > > > > -- > Steven > git gets easier once you get the basic idea that branches are homeomorphic > endofunctors mapping submanifolds of a Hilbert space. From jeanmichel at sequans.com Mon Sep 26 12:25:16 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 26 Sep 2016 18:25:16 +0200 Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/26/2016 05:25 PM, Cai Gengyang wrote: > I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum > >>>> for row in range(10): > for column in range(10): > print("*",end="") > > SyntaxError: inconsistent use of tabs and spaces in indentation >>>> for row in range(10): > for column in range(10): > print("*",end="") Here, from itertools import product for row,column in product(range(10), range(10)): print("*", end="") Problem solved :) On a more serious note, they're not the same code, in the same way than print("foo") print("bar") is not the same code than print("foo")print("bar") You're fooled by your editor which displays 2 different characters the same way. Tab or space does matter in python, get over it and move on with your python life. Actually python is a great debugger for misconfigured text editors. jm From python at mrabarnett.plus.com Mon Sep 26 12:39:53 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 26 Sep 2016 17:39:53 +0100 Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <49474675-3dc7-44f5-b655-9e4735e88db0@mrabarnett.plus.com> On 2016-09-26 16:25, Cai Gengyang wrote: > I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum > >>>> for row in range(10): > for column in range(10): > print("*",end="") > > SyntaxError: inconsistent use of tabs and spaces in indentation >>>> for row in range(10): > for column in range(10): > print("*",end="") > [snip] They are not exactly the same code. They are indented differently (tabs vs spaces), and that matters in Python. From gengyangcai at gmail.com Mon Sep 26 12:54:39 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 09:54:39 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <49474675-3dc7-44f5-b655-9e4735e88db0@mrabarnett.plus.com> Message-ID: <74f43a72-177f-4538-bcfe-abafd5343246@googlegroups.com> What is a tab and what is a space in python and what's the difference ? Which piece of code is indented with tabs and which one is indented with spaces ? On Tuesday, September 27, 2016 at 12:40:16 AM UTC+8, MRAB wrote: > On 2016-09-26 16:25, Cai Gengyang wrote: > > I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum > > > >>>> for row in range(10): > > for column in range(10): > > print("*",end="") > > > > SyntaxError: inconsistent use of tabs and spaces in indentation > >>>> for row in range(10): > > for column in range(10): > > print("*",end="") > > > [snip] > > They are not exactly the same code. They are indented differently (tabs > vs spaces), and that matters in Python. From steve+python at pearwood.info Mon Sep 26 13:06:32 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 27 Sep 2016 03:06:32 +1000 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57e9559a$0$1593$c3e8da3$5496439d@news.astraweb.com> On Tue, 27 Sep 2016 01:25 am, Cai Gengyang wrote: > I just wanted to note that sometimes the code works, sometimes it doesn't. > (even though both are exactly the same code) ... Weird , dum dum dum They are not the same code. One of them mixes tabs and spaces for the same indent level, the other does not. Here is a hint how you can tell the difference between lines with tabs and lines with spaces in the Python interactive interpreter: - if you pressed the spacebar repeatedly to get the indent, like SPACEBAR SPACEBAR SPACEBAR SPACEBAR, then the line will be indented with spaces; - if you pressed the tab key to get the indent, like TAB TAB, then the line will be indented with tabs; - if you pressed the tab key first, then spaces, like TAB SPACEBAR, then the line will be indented with a mixture of tabs and spaces. If you are copying code from a text editor, check your editor's settings. Some editors will be configured to insert spaces when you press the tab key. Your first example has: 1st line: no indent 2nd line: seven spaces 3rd line: tab + two spaces Notice that the 2nd and 3rd line start with inconsistent indentation: one uses spaces, the other uses tab. This is bad. Your second example has: 1st line: no indent 2nd line: tab 3rd line: tab + three spaces Notice that the 2nd and 3rd line start with the same indentation: both start with a tab. This is better, it is enough to satisfy the interpreter, but it would be better if you picked one (spaces) or the other (tabs) and ONLY used that. Other wise you will just confuse yourself. But you won't confuse the interpreter. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jeanmichel at sequans.com Mon Sep 26 13:15:10 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 26 Sep 2016 19:15:10 +0200 Subject: Nested for loops and print statements In-Reply-To: <74f43a72-177f-4538-bcfe-abafd5343246@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <49474675-3dc7-44f5-b655-9e4735e88db0@mrabarnett.plus.com> <74f43a72-177f-4538-bcfe-abafd5343246@googlegroups.com> Message-ID: On 09/26/2016 06:54 PM, Cai Gengyang wrote: > What is a tab and what is a space in python and what's the difference ? > > Which piece of code is indented with tabs and which one is indented with spaces ? Please do not top-post in this list. Put your text after the message you quote. Tabs and spaces are 2 different characters, tab ASCII code is 9, space ASCII code is 32. You *need* to understand that they are 2 differents characters. The problem come with their representation. 1/ a space is represented by 1 whitespace 2/ a tab is represented by x whitespaces. The number x depends on your text editor. When you want to indent a python block, you put whitespaces on its left to indent it. You can indent using either tabs or spaces. Python does not tell you which one to use, but it tells you to choose *one* method, and stick with it. jm From jussi.piitulainen at helsinki.fi Mon Sep 26 13:50:18 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 26 Sep 2016 20:50:18 +0300 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <49474675-3dc7-44f5-b655-9e4735e88db0@mrabarnett.plus.com> <74f43a72-177f-4538-bcfe-abafd5343246@googlegroups.com> Message-ID: Cai Gengyang writes: > What is a tab and what is a space in python and what's the difference > ? Try print('x\tx') in Python to see a tab character between the two x's. For me it looks the same as seven spaces, for you it will also look like some amount of whitespace but it might be a different amount. The two-character sequence \t inside a Python string literal means tab, same as \x09, same as \u0009, same as \N{TAB}, same as \N{HT}. (These sequences need to be inside quotes.) With print('xx\tx'), the tab looks, for me, the same as six spaces. It's funny that way: it's a single character, but it's shown differently depending on it's position on the line. You may get a tab character by pressing the tab key, but it's usual for that key to be smart in some way or used for some other purpose. > Which piece of code is indented with tabs and which one is indented > with spaces ? I've replaced the tabs with # below, and the greater-than signs with @. This may not have been exactly your code any more, but try to imagine a tab in place of each # anyway. @@@@ for row in range(10): @ for column in range(10): @ # print("*",end="") @ # @ SyntaxError: inconsistent use of tabs and spaces in indentation @@@@ for row in range(10): @ #for column in range(10): @ # print("*",end="") @ It would be better for you to get a better editor that either prevented you from getting into this mess in the first place, or at least showed where the offending characters are. It may be possible to configure your editor to be better. The details depend on what exactly you are using. What are you using? From orgnut at yahoo.com Mon Sep 26 15:56:59 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 26 Sep 2016 12:56:59 -0700 Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/26/2016 08:25 AM, Cai Gengyang wrote: > I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum > It is NOT weird. Python is being consistent, YOU are not. These examples are NOT "exactly the same code"! The indenting is different. Python (correctly) treats them as being different. YOU MUST USE CONSISTENT INDENTING. You MUST always use spaces (the recommended) or always use tabs. Never, ever, not at any time, can you mix them. (Now, does that emphasize the point enough?) Go back and REWRITE your code with CONSISTENT indenting. -- -=- Larry -=- From tjreedy at udel.edu Mon Sep 26 16:33:02 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Sep 2016 16:33:02 -0400 Subject: Nested for loops and print statements In-Reply-To: <74f43a72-177f-4538-bcfe-abafd5343246@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <49474675-3dc7-44f5-b655-9e4735e88db0@mrabarnett.plus.com> <74f43a72-177f-4538-bcfe-abafd5343246@googlegroups.com> Message-ID: On 9/26/2016 12:54 PM, Cai Gengyang wrote: > Which piece of code is indented with tabs and which one is indented with spaces ? I told you in my initial answer, where I said, referring to the two indented lines in one 'piece of code', "These indents are 4 spaces and 1 tabs." It is the mixture in one piece of code that is the problem. The tab in your original post has since be converted to (4) spaces. Tabs do not survive in email, sometimes just being deleted. -- Terry Jan Reedy From gengyangcai at gmail.com Mon Sep 26 16:57:39 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 13:57:39 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> Ok it works now: >>>for row in range(10): for column in range(10): print("*",end="") **************************************************************************************************** but how is it different from --- >>> for row in range(10): for column in range(10): print("*",end="") SyntaxError: inconsistent use of tabs and spaces in indentation Why does the example on top work and the example below doesn't work ? The only difference is that the "print" statement is one space different from each other. Forgive me if i can't explain things clearly over the forum On Tuesday, September 27, 2016 at 3:57:18 AM UTC+8, Larry Hudson wrote: > On 09/26/2016 08:25 AM, Cai Gengyang wrote: > > I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum > > > > It is NOT weird. Python is being consistent, YOU are not. > > These examples are NOT "exactly the same code"! The indenting is different. Python (correctly) > treats them as being different. > > YOU MUST USE CONSISTENT INDENTING. You MUST always use spaces (the recommended) or always use > tabs. Never, ever, not at any time, can you mix them. > > (Now, does that emphasize the point enough?) Go back and REWRITE your code with CONSISTENT > indenting. > > -- > -=- Larry -=- From marko at pacujo.net Mon Sep 26 17:09:51 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 27 Sep 2016 00:09:51 +0300 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <49474675-3dc7-44f5-b655-9e4735e88db0@mrabarnett.plus.com> <74f43a72-177f-4538-bcfe-abafd5343246@googlegroups.com> Message-ID: <8737kmgyg0.fsf@elektro.pacujo.net> Cai Gengyang : > What is a tab and what is a space in python and what's the difference > ? > > Which piece of code is indented with tabs and which one is indented > with spaces ? Key questions that Python gurus are having a hard time answering! Equally confusing, you might run into this phantom phenomenon: >>> if True: ... ? a = 3 File "", line 2 ? a = 3 ^ SyntaxError: invalid character in identifier It might be useful to have a mode that echoes each input line as seen by Python (repr). Marko From breamoreboy at gmail.com Mon Sep 26 18:00:27 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 26 Sep 2016 15:00:27 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> Message-ID: <0210da93-b7e6-4421-9d5f-bc774740d78c@googlegroups.com> On Monday, September 26, 2016 at 9:57:52 PM UTC+1, Cai Gengyang wrote: > Ok it works now: > > >>>for row in range(10): > for column in range(10): > print("*",end="") > > > **************************************************************************************************** > > but how is it different from --- > > >>> for row in range(10): > for column in range(10): > print("*",end="") > > SyntaxError: inconsistent use of tabs and spaces in indentation > > Why does the example on top work and the example below doesn't work ? The only difference is that the "print" statement is one space different from each other. Forgive me if i can't explain things clearly over the forum > Perhaps you'd be more comfortable on the tutor mailing list https://mail.python.org/mailman/listinfo/tutor Kindest regards. Mark Lawrence. From mohan.mohta at gmail.com Mon Sep 26 18:03:11 2016 From: mohan.mohta at gmail.com (M2) Date: Mon, 26 Sep 2016 15:03:11 -0700 (PDT) Subject: xlsxwriter considering worksheet.write as tuple ??? Message-ID: Hello The program is designed to collect different statistics from servers across the network and populate in excel sheet. Library : xlsxwriter.0.9.3 Below is the Snip of code being used #! /usr/bin/python import xlsxwriter import os; import subprocess; import sys; import os.path; workbook=xlsxwriter.Workbook('Turnover_sheet.xlsx'); tools_sheet=workbook.add_worksheet('Citi Tools Verification'); hw_sheet=workbook.add_worksheet('Hardware Verification'); os_sheet=workbook.add_worksheet('OS Verification'); build_spec_sheet=workbook.add_worksheet('Build Specs Verification'); info_sheet=workbook.add_worksheet('Server Handover Info'); stan_sheet=workbook.add_worksheet('Standards'); sup_sheet=workbook.add_worksheet('Support Information'); tools_sheet.write('A3', 'Device Name', table_head); tools_sheet.write('B3', 'Machine Category', table_head); tools_sheet.write('C3', 'OS Platform', table_head); hw_sheet.merge_range('A1:N1', 'Hardware Information', head); hw_sheet.merge_range('A2:A3', 'Device Name', table_head); hw_sheet.merge_range('B2:B3', 'CPU / vCPU Count', table_head); os_sheet.merge_range('A2:A3', 'Server Name', table_head); os_sheet.merge_range('B2:B3', 'Kdump Config', table_head); os_sheet.merge_range('C2:C3', 'Grub Config', table_head); info_sheet.write('A1', 'Server Name', table_head); info_sheet.write('B1', 'Serial Number', table_head); info_sheet.write('C1', 'Backup Type', table_head); stan_sheet.write('A1', 'Item', table_head); stan_sheet.write('B1', 'Standard', table_head); stan_sheet.write('C1', 'Comments', table_head); def data_collection(fqdn,counter): counter=int(counter); red_counter=(int(counter))-2; s_count='A'+str(counter); s_r_count='A'+str(red_counter); tools_sheet.write(s_count,fqdn,cell_format); hw_sheet.write(s_count,fqdn,cell_format); os_sheet.write(s_count,fqdn,cell_format); info_sheet.write(s_r_count,fqdn,cell_format); s_count='D'+str(red_counter); sup_sheet.write(s_count,fqdn,cell_format); I get the following error sup_sheet.write(s_count,fqdn,cell_format); TypeError: 'tuple' object is not callable What I do not understand is why is python thinking sup_sheet.write as tuple. I tired to debug the program and added the following line print "\ts_count is ", type(s_count)," and value",s_count,"\n\tfqdn is ", type(fqdn), " and value is ",fqdn,"\n\tcell_format is ", type(cell_format), " and value is ",cell_format,"\n\t sup_sheet is ",type(sup_sheet)," and value is ",sup_sheet,"\n\n\n"; just before sup_sheet.write(s_count,fqdn,cell_format); And I got the following output: s_count is and value D2 fqdn is and value is Sample1.xyz.com cell_format is and value is sup_sheet is and value is s_count is and value D3 fqdn is and value is sample2.xyz.com cell_format is and value is sup_sheet is and value is Traceback (most recent call last): File "./turnover_sheet.py", line 398, in data_population(str(sys.argv[1])); File "./turnover_sheet.py", line 380, in data_population data_collection(fqdn,count); File "./turnover_sheet.py", line 219, in data_collection sup_sheet.write(s_count,fqdn,cell_format); TypeError: 'tuple' object is not callable I also saw the sheet populated with the first server and when it went to the second server and while populating it considered sup_sheet.write as a tuple which makes no sense because the rest of the writes are working fine. I have no clue why is it doing it ? Thoughts ? -- Regards Mohan Mohta From gengyangcai at gmail.com Mon Sep 26 18:13:25 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 15:13:25 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: <0210da93-b7e6-4421-9d5f-bc774740d78c@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> <0210da93-b7e6-4421-9d5f-bc774740d78c@googlegroups.com> Message-ID: Sure, I just sent in a subscription request to it ... but I'll still be asking for help here. Please help out a newbie. When I master this language I can help other new users too (This is good for the world and for everyone involved). Ideally, Information and education should be free and not locked up by a few academics and institutions. On Tuesday, September 27, 2016 at 6:00:40 AM UTC+8, bream... at gmail.com wrote: > On Monday, September 26, 2016 at 9:57:52 PM UTC+1, Cai Gengyang wrote: > > Ok it works now: > > > > >>>for row in range(10): > > for column in range(10): > > print("*",end="") > > > > > > **************************************************************************************************** > > > > but how is it different from --- > > > > >>> for row in range(10): > > for column in range(10): > > print("*",end="") > > > > SyntaxError: inconsistent use of tabs and spaces in indentation > > > > Why does the example on top work and the example below doesn't work ? The only difference is that the "print" statement is one space different from each other. Forgive me if i can't explain things clearly over the forum > > > > Perhaps you'd be more comfortable on the tutor mailing list https://mail.python.org/mailman/listinfo/tutor > > Kindest regards. > > Mark Lawrence. From python at mrabarnett.plus.com Mon Sep 26 19:00:08 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Sep 2016 00:00:08 +0100 Subject: xlsxwriter considering worksheet.write as tuple ??? In-Reply-To: References: Message-ID: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> On 2016-09-26 23:03, M2 wrote: > Hello > The program is designed to collect different statistics from servers across the network and populate in excel sheet. > Library : xlsxwriter.0.9.3 > > Below is the Snip of code being used > #! /usr/bin/python > > import xlsxwriter > import os; > import subprocess; > import sys; > import os.path; > > > workbook=xlsxwriter.Workbook('Turnover_sheet.xlsx'); > > tools_sheet=workbook.add_worksheet('Citi Tools Verification'); > > hw_sheet=workbook.add_worksheet('Hardware Verification'); > > os_sheet=workbook.add_worksheet('OS Verification'); > > build_spec_sheet=workbook.add_worksheet('Build Specs Verification'); > > info_sheet=workbook.add_worksheet('Server Handover Info'); > > stan_sheet=workbook.add_worksheet('Standards'); > > sup_sheet=workbook.add_worksheet('Support Information'); > > tools_sheet.write('A3', 'Device Name', table_head); > > tools_sheet.write('B3', 'Machine Category', table_head); > > tools_sheet.write('C3', 'OS Platform', table_head); > > > hw_sheet.merge_range('A1:N1', 'Hardware Information', head); > > hw_sheet.merge_range('A2:A3', 'Device Name', table_head); > > hw_sheet.merge_range('B2:B3', 'CPU / vCPU Count', table_head); > > > os_sheet.merge_range('A2:A3', 'Server Name', table_head); > > os_sheet.merge_range('B2:B3', 'Kdump Config', table_head); > os_sheet.merge_range('C2:C3', 'Grub Config', table_head); > > > info_sheet.write('A1', 'Server Name', table_head); > > info_sheet.write('B1', 'Serial Number', table_head); > > info_sheet.write('C1', 'Backup Type', table_head); > > > stan_sheet.write('A1', 'Item', table_head); > > stan_sheet.write('B1', 'Standard', table_head); > > stan_sheet.write('C1', 'Comments', table_head); > > > def data_collection(fqdn,counter): > counter=int(counter); > red_counter=(int(counter))-2; > s_count='A'+str(counter); > s_r_count='A'+str(red_counter); > tools_sheet.write(s_count,fqdn,cell_format); > hw_sheet.write(s_count,fqdn,cell_format); > os_sheet.write(s_count,fqdn,cell_format); > info_sheet.write(s_r_count,fqdn,cell_format); > s_count='D'+str(red_counter); > sup_sheet.write(s_count,fqdn,cell_format); > > I get the following error > sup_sheet.write(s_count,fqdn,cell_format); > TypeError: 'tuple' object is not callable > > What I do not understand is why is python thinking sup_sheet.write as tuple. > I tired to debug the program and added the following line > print "\ts_count is ", type(s_count)," and value",s_count,"\n\tfqdn is ", type(fqdn), " and value is ",fqdn,"\n\tcell_format is ", type(cell_format), " and value is ",cell_format,"\n\t sup_sheet is ",type(sup_sheet)," and value is ",sup_sheet,"\n\n\n"; > > just before > sup_sheet.write(s_count,fqdn,cell_format); > > And I got the following output: > s_count is and value D2 > fqdn is and value is Sample1.xyz.com > cell_format is and value is > sup_sheet is and value is > > > > s_count is and value D3 > fqdn is and value is sample2.xyz.com > cell_format is and value is > sup_sheet is and value is > > > > Traceback (most recent call last): > File "./turnover_sheet.py", line 398, in > data_population(str(sys.argv[1])); > File "./turnover_sheet.py", line 380, in data_population > data_collection(fqdn,count); > File "./turnover_sheet.py", line 219, in data_collection > sup_sheet.write(s_count,fqdn,cell_format); > TypeError: 'tuple' object is not callable > > I also saw the sheet populated with the first server and when it went to the second server and while populating it considered > sup_sheet.write as a tuple which makes no sense because the rest of the writes are working fine. > > I have no clue why is it doing it ? > Thoughts ? > I can't see a problem in the part of the code that you've posted. Are there any other lines that use 'sup_sheet'? From haaruunibrow at gmail.com Mon Sep 26 19:21:27 2016 From: haaruunibrow at gmail.com (haaruunibrow at gmail.com) Date: Mon, 26 Sep 2016 16:21:27 -0700 (PDT) Subject: Socket programming In-Reply-To: References: Message-ID: <5580e994-ed9f-4c09-a24d-0a496c236e9a@googlegroups.com> use > client: > server_address='192.168.2.2' server: > server_name='127.0.0.1' From nathan.ernst at gmail.com Mon Sep 26 19:55:56 2016 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 26 Sep 2016 18:55:56 -0500 Subject: xlsxwriter considering worksheet.write as tuple ??? In-Reply-To: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> References: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> Message-ID: On Mon, Sep 26, 2016 at 6:00 PM, MRAB wrote: > On 2016-09-26 23:03, M2 wrote: > >> Hello >> The program is designed to collect different statistics from servers >> across the network and populate in excel sheet. >> Library : xlsxwriter.0.9.3 >> >> Below is the Snip of code being used >> #! /usr/bin/python >> >> import xlsxwriter >> import os; >> import subprocess; >> import sys; >> import os.path; >> >> >> workbook=xlsxwriter.Workbook('Turnover_sheet.xlsx'); >> >> tools_sheet=workbook.add_worksheet('Citi Tools Verification'); >> >> hw_sheet=workbook.add_worksheet('Hardware Verification'); >> >> os_sheet=workbook.add_worksheet('OS Verification'); >> >> build_spec_sheet=workbook.add_worksheet('Build Specs Verification'); >> >> info_sheet=workbook.add_worksheet('Server Handover Info'); >> >> stan_sheet=workbook.add_worksheet('Standards'); >> >> sup_sheet=workbook.add_worksheet('Support Information'); >> >> tools_sheet.write('A3', 'Device Name', table_head); >> >> tools_sheet.write('B3', 'Machine Category', table_head); >> >> tools_sheet.write('C3', 'OS Platform', table_head); >> >> >> hw_sheet.merge_range('A1:N1', 'Hardware Information', head); >> >> hw_sheet.merge_range('A2:A3', 'Device Name', table_head); >> >> hw_sheet.merge_range('B2:B3', 'CPU / vCPU Count', table_head); >> >> >> os_sheet.merge_range('A2:A3', 'Server Name', table_head); >> >> os_sheet.merge_range('B2:B3', 'Kdump Config', table_head); >> os_sheet.merge_range('C2:C3', 'Grub Config', table_head); >> >> >> info_sheet.write('A1', 'Server Name', table_head); >> >> info_sheet.write('B1', 'Serial Number', table_head); >> >> info_sheet.write('C1', 'Backup Type', table_head); >> >> >> stan_sheet.write('A1', 'Item', table_head); >> >> stan_sheet.write('B1', 'Standard', table_head); >> >> stan_sheet.write('C1', 'Comments', table_head); >> >> >> def data_collection(fqdn,counter): >> counter=int(counter); >> red_counter=(int(counter))-2; >> s_count='A'+str(counter); >> s_r_count='A'+str(red_counter); >> tools_sheet.write(s_count,fqdn,cell_format); >> hw_sheet.write(s_count,fqdn,cell_format); >> os_sheet.write(s_count,fqdn,cell_format); >> info_sheet.write(s_r_count,fqdn,cell_format); >> s_count='D'+str(red_counter); >> sup_sheet.write(s_count,fqdn,cell_format); >> >> I get the following error >> sup_sheet.write(s_count,fqdn,cell_format); >> TypeError: 'tuple' object is not callable >> >> What I do not understand is why is python thinking sup_sheet.write as >> tuple. >> I tired to debug the program and added the following line >> print "\ts_count is ", type(s_count)," and value",s_count,"\n\tfqdn is ", >> type(fqdn), " and value is ",fqdn,"\n\tcell_format is ", type(cell_format), >> " and value is ",cell_format,"\n\t sup_sheet is ",type(sup_sheet)," and >> value is ",sup_sheet,"\n\n\n"; >> >> just before >> sup_sheet.write(s_count,fqdn,cell_format); >> >> And I got the following output: >> s_count is and value D2 >> fqdn is and value is Sample1.xyz.com >> cell_format is and value is >> >> sup_sheet is and >> value is >> >> >> >> s_count is and value D3 >> fqdn is and value is sample2.xyz.com >> cell_format is and value is >> >> sup_sheet is and >> value is >> >> >> >> Traceback (most recent call last): >> File "./turnover_sheet.py", line 398, in >> data_population(str(sys.argv[1])); >> File "./turnover_sheet.py", line 380, in data_population >> data_collection(fqdn,count); >> File "./turnover_sheet.py", line 219, in data_collection >> sup_sheet.write(s_count,fqdn,cell_format); >> TypeError: 'tuple' object is not callable >> >> I also saw the sheet populated with the first server and when it went to >> the second server and while populating it considered >> sup_sheet.write as a tuple which makes no sense because the rest of the >> writes are working fine. >> >> I have no clue why is it doing it ? >> Thoughts ? >> >> I can't see a problem in the part of the code that you've posted. > > Are there any other lines that use 'sup_sheet'? > > -- > https://mail.python.org/mailman/listinfo/python-list > There's nothing wrong with the snippet as shown - the problem must be elsewhere. I took the snippet as in the original email and made some slight changes to define cell_format, head and table_head & close the workbook: #!/usr/bin/env python import xlsxwriter import os; import subprocess; import sys; import os.path; workbook = xlsxwriter.Workbook('Turnover_sheet.xlsx'); cell_format = workbook.add_format({}) head = table_head = workbook.add_format({'bold': True}) # snipped the rest data_collection("sample1.xyz.com", 2) data_collection("sample2.xyz.com", 3) workbook.close() This runs cleanly for me with xlsxwriter 0.9.3 on Python 2.7.6. I understand this is a snippet, but it feels like you may be reassigning sup_sheet. Or, possibly assigning to "sup_sheet.write" somewhere. I'd search with the regex "sup_sheet.write\s*=" to see if you get any hits. Hope this helps. Regards From mohan.mohta at gmail.com Mon Sep 26 20:34:08 2016 From: mohan.mohta at gmail.com (Mohan Mohta) Date: Mon, 26 Sep 2016 17:34:08 -0700 (PDT) Subject: xlsxwriter considering worksheet.write as tuple ??? In-Reply-To: References: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> Message-ID: <21d04868-1279-49a4-bd5d-cfed9d60439a@googlegroups.com> On Monday, September 26, 2016 at 6:56:20 PM UTC-5, Nathan Ernst wrote: > On Mon, Sep 26, 2016 at 6:00 PM, MRAB wrote: > > > On 2016-09-26 23:03, M2 wrote: > > > >> Hello > >> The program is designed to collect different statistics from servers > >> across the network and populate in excel sheet. > >> Library : xlsxwriter.0.9.3 > >> > >> Below is the Snip of code being used > >> #! /usr/bin/python > >> > >> import xlsxwriter > >> import os; > >> import subprocess; > >> import sys; > >> import os.path; > >> > >> > >> workbook=xlsxwriter.Workbook('Turnover_sheet.xlsx'); > >> > >> tools_sheet=workbook.add_worksheet('Citi Tools Verification'); > >> > >> hw_sheet=workbook.add_worksheet('Hardware Verification'); > >> > >> os_sheet=workbook.add_worksheet('OS Verification'); > >> > >> build_spec_sheet=workbook.add_worksheet('Build Specs Verification'); > >> > >> info_sheet=workbook.add_worksheet('Server Handover Info'); > >> > >> stan_sheet=workbook.add_worksheet('Standards'); > >> > >> sup_sheet=workbook.add_worksheet('Support Information'); > >> > >> tools_sheet.write('A3', 'Device Name', table_head); > >> > >> tools_sheet.write('B3', 'Machine Category', table_head); > >> > >> tools_sheet.write('C3', 'OS Platform', table_head); > >> > >> > >> hw_sheet.merge_range('A1:N1', 'Hardware Information', head); > >> > >> hw_sheet.merge_range('A2:A3', 'Device Name', table_head); > >> > >> hw_sheet.merge_range('B2:B3', 'CPU / vCPU Count', table_head); > >> > >> > >> os_sheet.merge_range('A2:A3', 'Server Name', table_head); > >> > >> os_sheet.merge_range('B2:B3', 'Kdump Config', table_head); > >> os_sheet.merge_range('C2:C3', 'Grub Config', table_head); > >> > >> > >> info_sheet.write('A1', 'Server Name', table_head); > >> > >> info_sheet.write('B1', 'Serial Number', table_head); > >> > >> info_sheet.write('C1', 'Backup Type', table_head); > >> > >> > >> stan_sheet.write('A1', 'Item', table_head); > >> > >> stan_sheet.write('B1', 'Standard', table_head); > >> > >> stan_sheet.write('C1', 'Comments', table_head); > >> > >> > >> def data_collection(fqdn,counter): > >> counter=int(counter); > >> red_counter=(int(counter))-2; > >> s_count='A'+str(counter); > >> s_r_count='A'+str(red_counter); > >> tools_sheet.write(s_count,fqdn,cell_format); > >> hw_sheet.write(s_count,fqdn,cell_format); > >> os_sheet.write(s_count,fqdn,cell_format); > >> info_sheet.write(s_r_count,fqdn,cell_format); > >> s_count='D'+str(red_counter); > >> sup_sheet.write(s_count,fqdn,cell_format); > >> > >> I get the following error > >> sup_sheet.write(s_count,fqdn,cell_format); > >> TypeError: 'tuple' object is not callable > >> > >> What I do not understand is why is python thinking sup_sheet.write as > >> tuple. > >> I tired to debug the program and added the following line > >> print "\ts_count is ", type(s_count)," and value",s_count,"\n\tfqdn is ", > >> type(fqdn), " and value is ",fqdn,"\n\tcell_format is ", type(cell_format), > >> " and value is ",cell_format,"\n\t sup_sheet is ",type(sup_sheet)," and > >> value is ",sup_sheet,"\n\n\n"; > >> > >> just before > >> sup_sheet.write(s_count,fqdn,cell_format); > >> > >> And I got the following output: > >> s_count is and value D2 > >> fqdn is and value is Sample1.xyz.com > >> cell_format is and value is > >> > >> sup_sheet is and > >> value is > >> > >> > >> > >> s_count is and value D3 > >> fqdn is and value is sample2.xyz.com > >> cell_format is and value is > >> > >> sup_sheet is and > >> value is > >> > >> > >> > >> Traceback (most recent call last): > >> File "./turnover_sheet.py", line 398, in > >> data_population(str(sys.argv[1])); > >> File "./turnover_sheet.py", line 380, in data_population > >> data_collection(fqdn,count); > >> File "./turnover_sheet.py", line 219, in data_collection > >> sup_sheet.write(s_count,fqdn,cell_format); > >> TypeError: 'tuple' object is not callable > >> > >> I also saw the sheet populated with the first server and when it went to > >> the second server and while populating it considered > >> sup_sheet.write as a tuple which makes no sense because the rest of the > >> writes are working fine. > >> > >> I have no clue why is it doing it ? > >> Thoughts ? > >> > >> I can't see a problem in the part of the code that you've posted. > > > > Are there any other lines that use 'sup_sheet'? > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > There's nothing wrong with the snippet as shown - the problem must be > elsewhere. I took the snippet as in the original email and made some > slight changes to define cell_format, head and table_head & close the > workbook: > > #!/usr/bin/env python > import xlsxwriter > import os; > import subprocess; > import sys; > import os.path; > > workbook = xlsxwriter.Workbook('Turnover_sheet.xlsx'); > cell_format = workbook.add_format({}) > head = table_head = workbook.add_format({'bold': True}) > > # snipped the rest > > data_collection("sample1.xyz.com", 2) > data_collection("sample2.xyz.com", 3) > > workbook.close() > > This runs cleanly for me with xlsxwriter 0.9.3 on Python 2.7.6. > > I understand this is a snippet, but it feels like you may be reassigning > sup_sheet. Or, possibly assigning to "sup_sheet.write" somewhere. I'd > search with the regex "sup_sheet.write\s*=" to see if you get any hits. > > Hope this helps. > > Regards Thanks for looking into this. Well I have been using the following which works fine sup_sheet.write('A1', 'Project Name', table_head); sup_sheet.write('B1', 'SLTN # ', table_head); sup_sheet.write('C1', 'Env Label', table_head); sup_sheet.write('D1', 'Hostname', table_head); sup_sheet.write('E1', 'ServerType(Physical/Physical Cluster/VM)', table_head); sup_sheet.write('F1', 'Server Type', table_head); sup_sheet.write('G1', 'App Support SNOW', table_head); sup_sheet.write('H1', 'App Primary Contact', table_head); sup_sheet.write('I1', 'Production Support', table_head); sup_sheet.write('J1', 'Comments', table_head); Also if you see the output; the program does what it is supposed to do during the first run s_count is and value D2 fqdn is and value is Sample1.xyz.com cell_format is and value is sup_sheet is and value is But when it picks the second server from the list and starts doing what it needs to do then for whatever reason it thinks that this is a tuple sup_sheet.write(s_count,fqdn,cell_format); Let me know if you need I can load the entire program ( if it helps ) It is just that it is a still in progress and is a 400+ lines of code. From python at mrabarnett.plus.com Mon Sep 26 21:07:48 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Sep 2016 02:07:48 +0100 Subject: xlsxwriter considering worksheet.write as tuple ??? In-Reply-To: <21d04868-1279-49a4-bd5d-cfed9d60439a@googlegroups.com> References: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> <21d04868-1279-49a4-bd5d-cfed9d60439a@googlegroups.com> Message-ID: On 2016-09-27 01:34, Mohan Mohta wrote: > On Monday, September 26, 2016 at 6:56:20 PM UTC-5, Nathan Ernst wrote: >> On Mon, Sep 26, 2016 at 6:00 PM, MRAB wrote: >> >> > On 2016-09-26 23:03, M2 wrote: >> > >> >> Hello >> >> The program is designed to collect different statistics from servers >> >> across the network and populate in excel sheet. >> >> Library : xlsxwriter.0.9.3 >> >> >> >> Below is the Snip of code being used [snip] >> >> >> >> Traceback (most recent call last): >> >> File "./turnover_sheet.py", line 398, in >> >> data_population(str(sys.argv[1])); >> >> File "./turnover_sheet.py", line 380, in data_population >> >> data_collection(fqdn,count); >> >> File "./turnover_sheet.py", line 219, in data_collection >> >> sup_sheet.write(s_count,fqdn,cell_format); >> >> TypeError: 'tuple' object is not callable >> >> >> >> I also saw the sheet populated with the first server and when it went to >> >> the second server and while populating it considered >> >> sup_sheet.write as a tuple which makes no sense because the rest of the >> >> writes are working fine. >> >> >> >> I have no clue why is it doing it ? >> >> Thoughts ? >> >> >> >> I can't see a problem in the part of the code that you've posted. >> > >> > Are there any other lines that use 'sup_sheet'? >> > >> There's nothing wrong with the snippet as shown - the problem must be >> elsewhere. I took the snippet as in the original email and made some >> slight changes to define cell_format, head and table_head & close the >> workbook: >> >> #!/usr/bin/env python [snip] > > But when it picks the second server from the list and starts doing what it needs to do then for whatever reason it thinks that this is a tuple > sup_sheet.write(s_count,fqdn,cell_format); > > > Let me know if you need I can load the entire program ( if it helps ) > It is just that it is a still in progress and is a 400+ lines of code. > You could post the code at Pastebin.com to avoid filling people's inboxes. From mohan.mohta at gmail.com Mon Sep 26 21:18:47 2016 From: mohan.mohta at gmail.com (Mohan Mohta) Date: Mon, 26 Sep 2016 18:18:47 -0700 (PDT) Subject: xlsxwriter considering worksheet.write as tuple ??? In-Reply-To: References: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> <21d04868-1279-49a4-bd5d-cfed9d60439a@googlegroups.com> Message-ID: <41170968-97b3-457d-abc7-a60260512fdc@googlegroups.com> On Monday, September 26, 2016 at 8:08:13 PM UTC-5, MRAB wrote: > On 2016-09-27 01:34, Mohan Mohta wrote: > > On Monday, September 26, 2016 at 6:56:20 PM UTC-5, Nathan Ernst wrote: > >> On Mon, Sep 26, 2016 at 6:00 PM, MRAB wrote: > >> > >> > On 2016-09-26 23:03, M2 wrote: > >> > > >> >> Hello > >> >> The program is designed to collect different statistics from servers > >> >> across the network and populate in excel sheet. > >> >> Library : xlsxwriter.0.9.3 > >> >> > >> >> Below is the Snip of code being used > [snip] > >> >> > >> >> Traceback (most recent call last): > >> >> File "./turnover_sheet.py", line 398, in > >> >> data_population(str(sys.argv[1])); > >> >> File "./turnover_sheet.py", line 380, in data_population > >> >> data_collection(fqdn,count); > >> >> File "./turnover_sheet.py", line 219, in data_collection > >> >> sup_sheet.write(s_count,fqdn,cell_format); > >> >> TypeError: 'tuple' object is not callable > >> >> > >> >> I also saw the sheet populated with the first server and when it went to > >> >> the second server and while populating it considered > >> >> sup_sheet.write as a tuple which makes no sense because the rest of the > >> >> writes are working fine. > >> >> > >> >> I have no clue why is it doing it ? > >> >> Thoughts ? > >> >> > >> >> I can't see a problem in the part of the code that you've posted. > >> > > >> > Are there any other lines that use 'sup_sheet'? > >> > > >> There's nothing wrong with the snippet as shown - the problem must be > >> elsewhere. I took the snippet as in the original email and made some > >> slight changes to define cell_format, head and table_head & close the > >> workbook: > >> > >> #!/usr/bin/env python > [snip] > > > > But when it picks the second server from the list and starts doing what it needs to do then for whatever reason it thinks that this is a tuple > > sup_sheet.write(s_count,fqdn,cell_format); > > > > > > Let me know if you need I can load the entire program ( if it helps ) > > It is just that it is a still in progress and is a 400+ lines of code. > > > You could post the code at Pastebin.com to avoid filling people's inboxes. Here you go http://pastebin.com/YsbV79XM From nathan.ernst at gmail.com Mon Sep 26 21:30:16 2016 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Mon, 26 Sep 2016 20:30:16 -0500 Subject: xlsxwriter considering worksheet.write as tuple ??? In-Reply-To: <41170968-97b3-457d-abc7-a60260512fdc@googlegroups.com> References: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> <21d04868-1279-49a4-bd5d-cfed9d60439a@googlegroups.com> <41170968-97b3-457d-abc7-a60260512fdc@googlegroups.com> Message-ID: There's a bug at line 362: sup_sheet.write=(s_count,"VM", cell_format); ---------------^ Like I suggested, you've an errant assignment to sup_sheet.write. Also, a couple of notes on style: the terminating semicolons in your code is unnecessary. It's only needed for multiple statements on a single line. Please use a single space on each side of a binary operator or assignment - it improves readability. Regards, On Mon, Sep 26, 2016 at 8:18 PM, Mohan Mohta wrote: > On Monday, September 26, 2016 at 8:08:13 PM UTC-5, MRAB wrote: > > On 2016-09-27 01:34, Mohan Mohta wrote: > > > On Monday, September 26, 2016 at 6:56:20 PM UTC-5, Nathan Ernst wrote: > > >> On Mon, Sep 26, 2016 at 6:00 PM, MRAB > wrote: > > >> > > >> > On 2016-09-26 23:03, M2 wrote: > > >> > > > >> >> Hello > > >> >> The program is designed to collect different statistics from > servers > > >> >> across the network and populate in excel sheet. > > >> >> Library : xlsxwriter.0.9.3 > > >> >> > > >> >> Below is the Snip of code being used > > [snip] > > >> >> > > >> >> Traceback (most recent call last): > > >> >> File "./turnover_sheet.py", line 398, in > > >> >> data_population(str(sys.argv[1])); > > >> >> File "./turnover_sheet.py", line 380, in data_population > > >> >> data_collection(fqdn,count); > > >> >> File "./turnover_sheet.py", line 219, in data_collection > > >> >> sup_sheet.write(s_count,fqdn,cell_format); > > >> >> TypeError: 'tuple' object is not callable > > >> >> > > >> >> I also saw the sheet populated with the first server and when it > went to > > >> >> the second server and while populating it considered > > >> >> sup_sheet.write as a tuple which makes no sense because the rest > of the > > >> >> writes are working fine. > > >> >> > > >> >> I have no clue why is it doing it ? > > >> >> Thoughts ? > > >> >> > > >> >> I can't see a problem in the part of the code that you've posted. > > >> > > > >> > Are there any other lines that use 'sup_sheet'? > > >> > > > >> There's nothing wrong with the snippet as shown - the problem must be > > >> elsewhere. I took the snippet as in the original email and made some > > >> slight changes to define cell_format, head and table_head & close the > > >> workbook: > > >> > > >> #!/usr/bin/env python > > [snip] > > > > > > But when it picks the second server from the list and starts doing > what it needs to do then for whatever reason it thinks that this is a tuple > > > sup_sheet.write(s_count,fqdn,cell_format); > > > > > > > > > Let me know if you need I can load the entire program ( if it helps ) > > > It is just that it is a still in progress and is a 400+ lines of code. > > > > > You could post the code at Pastebin.com to avoid filling people's > inboxes. > > Here you go > http://pastebin.com/YsbV79XM > -- > https://mail.python.org/mailman/listinfo/python-list > From mohan.mohta at gmail.com Mon Sep 26 21:39:44 2016 From: mohan.mohta at gmail.com (Mohan Mohta) Date: Mon, 26 Sep 2016 18:39:44 -0700 (PDT) Subject: xlsxwriter considering worksheet.write as tuple ??? In-Reply-To: References: <1c4ce0cf-7158-a47e-1934-d19a00427af5@mrabarnett.plus.com> <21d04868-1279-49a4-bd5d-cfed9d60439a@googlegroups.com> <41170968-97b3-457d-abc7-a60260512fdc@googlegroups.com> Message-ID: On Monday, September 26, 2016 at 8:30:34 PM UTC-5, Nathan Ernst wrote: > There's a bug at line 362: > > sup_sheet.write=(s_count,"VM", cell_format); > ---------------^ > > Like I suggested, you've an errant assignment to sup_sheet.write. > > Also, a couple of notes on style: the terminating semicolons in your code > is unnecessary. It's only needed for multiple statements on a single line. > Please use a single space on each side of a binary operator or assignment - > it improves readability. > > Regards, > > On Mon, Sep 26, 2016 at 8:18 PM, Mohan Mohta wrote: > > > On Monday, September 26, 2016 at 8:08:13 PM UTC-5, MRAB wrote: > > > On 2016-09-27 01:34, Mohan Mohta wrote: > > > > On Monday, September 26, 2016 at 6:56:20 PM UTC-5, Nathan Ernst wrote: > > > >> On Mon, Sep 26, 2016 at 6:00 PM, MRAB > > wrote: > > > >> > > > >> > On 2016-09-26 23:03, M2 wrote: > > > >> > > > > >> >> Hello > > > >> >> The program is designed to collect different statistics from > > servers > > > >> >> across the network and populate in excel sheet. > > > >> >> Library : xlsxwriter.0.9.3 > > > >> >> > > > >> >> Below is the Snip of code being used > > > [snip] > > > >> >> > > > >> >> Traceback (most recent call last): > > > >> >> File "./turnover_sheet.py", line 398, in > > > >> >> data_population(str(sys.argv[1])); > > > >> >> File "./turnover_sheet.py", line 380, in data_population > > > >> >> data_collection(fqdn,count); > > > >> >> File "./turnover_sheet.py", line 219, in data_collection > > > >> >> sup_sheet.write(s_count,fqdn,cell_format); > > > >> >> TypeError: 'tuple' object is not callable > > > >> >> > > > >> >> I also saw the sheet populated with the first server and when it > > went to > > > >> >> the second server and while populating it considered > > > >> >> sup_sheet.write as a tuple which makes no sense because the rest > > of the > > > >> >> writes are working fine. > > > >> >> > > > >> >> I have no clue why is it doing it ? > > > >> >> Thoughts ? > > > >> >> > > > >> >> I can't see a problem in the part of the code that you've posted. > > > >> > > > > >> > Are there any other lines that use 'sup_sheet'? > > > >> > > > > >> There's nothing wrong with the snippet as shown - the problem must be > > > >> elsewhere. I took the snippet as in the original email and made some > > > >> slight changes to define cell_format, head and table_head & close the > > > >> workbook: > > > >> > > > >> #!/usr/bin/env python > > > [snip] > > > > > > > > But when it picks the second server from the list and starts doing > > what it needs to do then for whatever reason it thinks that this is a tuple > > > > sup_sheet.write(s_count,fqdn,cell_format); > > > > > > > > > > > > Let me know if you need I can load the entire program ( if it helps ) > > > > It is just that it is a still in progress and is a 400+ lines of code. > > > > > > > You could post the code at Pastebin.com to avoid filling people's > > inboxes. > > > > Here you go > > http://pastebin.com/YsbV79XM > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Dang that was it. I was wondering where I was assigning it. No wonder it was thinking sup_sheet.write as a tuple. That was dumb. Well as of semi colon it is just a habit from my old programming style :) And I take your suggestion "Please use a single space on each side of a binary operator or assignment - it improves readability. " Thanks Nathan -- Regards Mohan Mohta From jfong at ms4.hinet.net Mon Sep 26 21:48:21 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 26 Sep 2016 18:48:21 -0700 (PDT) Subject: How to make a foreign function run as fast as possible in Windows? Message-ID: This function is in a DLL. It's small but may run for days before complete. I want it takes 100% core usage. Threading seems not a good idea for it shares the core with others. Will the multiprocessing module do it? Any suggestion? Thanks ahead. --Jach From eryksun at gmail.com Mon Sep 26 23:43:51 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 27 Sep 2016 03:43:51 +0000 Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: Message-ID: On Tue, Sep 27, 2016 at 1:48 AM, wrote: > This function is in a DLL. It's small but may run for days before complete. I want it > takes 100% core usage. Threading seems not a good idea for it shares the core > with others. Will the multiprocessing module do it? The threads of a process do not share a single core. The OS schedules threads to distribute the load across all cores. However, CPython's global interpreter lock (GIL) does serialize access to the interpreter. If N threads want to use the interpreter, then N-1 threads are blocked while waiting to acquire the GIL. A thread that makes a potentially blocking call to a non-Python API should first release the GIL, which allows another thread to use the interpreter. Calling a ctypes function pointer releases the GIL if the function pointer is from CDLL, WinDLL, or OleDLL (i.e. anything but PyDLL). If your task can be partitioned and executed in parallel, you could use a ThreadPoolExecutor from the concurrent.futures module. Since the task is CPU bound, use os.cpu_count() instead of the default number of threads. https://docs.python.org/3/library/concurrent.futures From mr.eightnoteight at gmail.com Tue Sep 27 00:01:16 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Tue, 27 Sep 2016 09:31:16 +0530 Subject: event loop vs threads Message-ID: how does Python switch execution and maintain context i.e function stack etc,.. for co-routines and why is it less costly than switching threads which almost do the same, and both are handled by Python Interpreter itself(event loop for co-routines and GIL scheduling for threading), so where does the extra overhead for threads come from ? -- Regards Srinivas Devaki Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad) Computer Science and Engineering Department ph: +91 9491 383 249 telegram_id: @eightnoteight From greg.ewing at canterbury.ac.nz Tue Sep 27 01:20:00 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 27 Sep 2016 18:20:00 +1300 Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> <0210da93-b7e6-4421-9d5f-bc774740d78c@googlegroups.com> Message-ID: Cai Gengyang wrote: > I'll still be asking for help here. Please help out a newbie. We're trying to help, but we need to know more about the environment you're using to enter your code. What operating system are you using? How are you running the interactive interpreter? Are you using IDLE, or are you running Python in a command window? Are you typing code directly into the interactive interpreter, or are you typing it into a text editor and then copying and pasting it into the interpreter? If you're using a text editor, which one are you using? What *exactly* are you typing on the keyboard to produce your indentation? Are you pressing the space bar, the tab key, or some combination of them? -- Greg From gengyangcai at gmail.com Tue Sep 27 02:11:48 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 23:11:48 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> <0210da93-b7e6-4421-9d5f-bc774740d78c@googlegroups.com> Message-ID: <7ab29fc4-89a6-4680-930a-f85ea6942cf6@googlegroups.com> We're trying to help, but we need to know more about the environment you're using to enter your code. What operating system are you using? --- OSX Yosemite Version 10.10.2 How are you running the interactive interpreter? Are you using IDLE, or are you running Python in a command window? --- IDLE Are you typing code directly into the interactive interpreter, ---- Typing it directly into IDLE or are you typing it into a text editor and then copying and pasting it into the interpreter? If you're using a text editor, which one are you using? --- Not using a text editor What *exactly* are you typing on the keyboard to produce your indentation? Are you pressing the space bar, the tab key, or some combination of them? ---- Just the space bar, not the tab key gives too jumps in spaces that are too large for my liking. On Tuesday, September 27, 2016 at 1:20:17 PM UTC+8, Gregory Ewing wrote: > Cai Gengyang wrote: > > I'll still be asking for help here. Please help out a newbie. > > We're trying to help, but we need to know more about the > environment you're using to enter your code. > > What operating system are you using? > > How are you running the interactive interpreter? Are you > using IDLE, or are you running Python in a command window? > > Are you typing code directly into the interactive interpreter, > or are you typing it into a text editor and then copying > and pasting it into the interpreter? > > If you're using a text editor, which one are you using? > > What *exactly* are you typing on the keyboard to produce > your indentation? Are you pressing the space bar, the > tab key, or some combination of them? > > -- > Greg From gengyangcai at gmail.com Tue Sep 27 02:14:58 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 26 Sep 2016 23:14:58 -0700 (PDT) Subject: Nested for loops and print statements In-Reply-To: <7ab29fc4-89a6-4680-930a-f85ea6942cf6@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> <0210da93-b7e6-4421-9d5f-bc774740d78c@googlegroups.com> <7ab29fc4-89a6-4680-930a-f85ea6942cf6@googlegroups.com> Message-ID: <5c2cf56a-0e20-480e-aff7-331a21d9d7f9@googlegroups.com> On Tuesday, September 27, 2016 at 2:14:05 PM UTC+8, Cai Gengyang wrote: > We're trying to help, but we need to know more about the > environment you're using to enter your code. > > What operating system are you using? --- OSX Yosemite Version 10.10.2 > > How are you running the interactive interpreter? Are you > using IDLE, or are you running Python in a command window? --- IDLE > > Are you typing code directly into the interactive interpreter, ---- Typing it directly into IDLE > or are you typing it into a text editor and then copying > and pasting it into the interpreter? > > If you're using a text editor, which one are you using? --- Not using a text editor > > What *exactly* are you typing on the keyboard to produce > your indentation? Are you pressing the space bar, the > tab key, or some combination of them? ---- Just the space bar, not the tab key because it gives jumps in spaces that are too large for my liking. > > > > > > > > > On Tuesday, September 27, 2016 at 1:20:17 PM UTC+8, Gregory Ewing wrote: > > Cai Gengyang wrote: > > > I'll still be asking for help here. Please help out a newbie. > > > > We're trying to help, but we need to know more about the > > environment you're using to enter your code. > > > > What operating system are you using? > > > > How are you running the interactive interpreter? Are you > > using IDLE, or are you running Python in a command window? > > > > Are you typing code directly into the interactive interpreter, > > or are you typing it into a text editor and then copying > > and pasting it into the interpreter? > > > > If you're using a text editor, which one are you using? > > > > What *exactly* are you typing on the keyboard to produce > > your indentation? Are you pressing the space bar, the > > tab key, or some combination of them? > > > > -- > > Greg From dieter at handshake.de Tue Sep 27 03:01:55 2016 From: dieter at handshake.de (dieter) Date: Tue, 27 Sep 2016 09:01:55 +0200 Subject: Python C API: How to debug reference leak? References: Message-ID: <87wphxddwc.fsf@handshake.de> dl l writes: > I want to check the references of an object. Any way to get the references > of an object with Python C API? Like: gc.get_referrs(), is there similar > API in C lib? "gc" is a module. You can import and access modules from the C API. Thus, you can use "gc.get_referers" from "C" code. From gandalf at shopzeus.com Tue Sep 27 03:08:25 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Tue, 27 Sep 2016 09:08:25 +0200 Subject: How to make a copy of chained dicts effectively and nicely? Message-ID: The result that I need should be a real dict, not just a ChainMap. (It is because I have to mutate it.) d1 = {'a':1, 'b':2} d2 = {'c':3, 'd':4} d3 = {'e':5, 'f':6} #1. My first naive approach was: from collections import ChainMap d = {} for key,value in ChainMap(d1, d2, d3).items(): d[key] = value #2. Much more effective version, but requires too many lines: d= {} d.update(d1) d.update(d2) d.update(d3) #3. Third version is more compact. It uses a side effect inside a list comp., so I don't like it either: d = {} [d.update(_) for _ in [d1, d2, d3]] #4. Last version: d = {} d.update(ChainMap(d1, d2, d3)) Visually, it is the cleanest and the easiest to understand. However, it uses ChainMap.__iter__ and that goes over all mappings in a loop written in pure Python. Is there a version that is as effective as #3, but as clean and nice as #4? From lawrencedo99 at gmail.com Tue Sep 27 03:16:14 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 27 Sep 2016 00:16:14 -0700 (PDT) Subject: How to make a copy of chained dicts effectively and nicely? In-Reply-To: References: Message-ID: On Tuesday, September 27, 2016 at 8:08:46 PM UTC+13, Nagy L?szl? Zsolt wrote: > d1 = {'a':1, 'b':2} > d2 = {'c':3, 'd':4} > d3 = {'e':5, 'f':6} > > Is there a version that is as effective as #3, but as clean and nice as #4? dict(dict(d1, **d2), **d3) From jussi.piitulainen at helsinki.fi Tue Sep 27 03:32:06 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 27 Sep 2016 10:32:06 +0300 Subject: How to make a copy of chained dicts effectively and nicely? References: Message-ID: Nagy L?szl? Zsolt writes: > The result that I need should be a real dict, not just a ChainMap. (It > is because I have to mutate it.) > > d1 = {'a':1, 'b':2} > d2 = {'c':3, 'd':4} > d3 = {'e':5, 'f':6} > > #1. My first naive approach was: > > > from collections import ChainMap > d = {} > for key,value in ChainMap(d1, d2, d3).items(): > d[key] = value > > #2. Much more effective version, but requires too many lines: > > d= {} > d.update(d1) > d.update(d2) > d.update(d3) > > #3. Third version is more compact. It uses a side effect inside a list > comp., so I don't like it either: > > d = {} > [d.update(_) for _ in [d1, d2, d3]] That really should be just a loop: d = {} for _ in (d1, d2, d3): d.update(_) > #4. Last version: > > d = {} > d.update(ChainMap(d1, d2, d3)) > > Visually, it is the cleanest and the easiest to understand. However, it > uses ChainMap.__iter__ and that goes over all mappings in a loop written > in pure Python. > > Is there a version that is as effective as #3, but as clean and nice > as #4? Maybe see above. Or consider also this, which looks straightforward to me: d = { k:v for d in (d1, d2, d3) for k,v in d.items() } Is ChainMap really that bad? Otherwise the following would look somewhat nice: d = dict(ChainMap(d1, d2, d3).items()) Those come to mind. From ldlchina at gmail.com Tue Sep 27 03:47:46 2016 From: ldlchina at gmail.com (dl l) Date: Tue, 27 Sep 2016 15:47:46 +0800 Subject: Python C API: How to debug reference leak? In-Reply-To: <87wphxddwc.fsf@handshake.de> References: <87wphxddwc.fsf@handshake.de> Message-ID: Thanks for reply. Is there any function in C to get the reference objects of a object? I want to debug where are referencing the object. 2016-09-27 15:01 GMT+08:00 dieter : > dl l writes: > > I want to check the references of an object. Any way to get the > references > > of an object with Python C API? Like: gc.get_referrs(), is there similar > > API in C lib? > > "gc" is a module. You can import and access modules from the C API. > Thus, you can use "gc.get_referers" from "C" code. > > -- > https://mail.python.org/mailman/listinfo/python-list > From ldlchina at gmail.com Tue Sep 27 03:49:26 2016 From: ldlchina at gmail.com (dl l) Date: Tue, 27 Sep 2016 15:49:26 +0800 Subject: PyImport_AddModule vs PyImport_Import Message-ID: What is the difference between PyImport_AddModule and PyImport_Import? When need to use PyImport_AddModule? When need to use PyImport_Import? From cpxuvs at gmail.com Tue Sep 27 04:09:08 2016 From: cpxuvs at gmail.com (cpxuvs at gmail.com) Date: Tue, 27 Sep 2016 01:09:08 -0700 (PDT) Subject: it looks strange Message-ID: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> >>> li=[lambda :x for x in range(10)] >>> res=li[0]() >>> print res 9 why? From jussi.piitulainen at helsinki.fi Tue Sep 27 04:24:24 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 27 Sep 2016 11:24:24 +0300 Subject: it looks strange References: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> Message-ID: cpxuvs at gmail.com writes: >>>> li=[lambda :x for x in range(10)] >>>> res=li[0]() >>>> print res > 9 > > why? Because each of the ten functions will report the final value of the same x. There are a couple of tricks to capture the transient value: [lambda w=x: w for x in range(10)] [(lambda w: (lambda :w))(x) for x in range(10)] The former works because the default value of w is whatever x was when the function object was created. I think the latter does what you thought you were doing, but it's harder to read and probably the difference should not matter much in practice. You can call w x in both tricks if you like. From __peter__ at web.de Tue Sep 27 04:32:31 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Sep 2016 10:32:31 +0200 Subject: it looks strange References: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> Message-ID: cpxuvs at gmail.com wrote: >>>> li=[lambda :x for x in range(10)] >>>> res=li[0]() >>>> print res > 9 > > why? Look what happens if you look up x manually: >>> li = [lambda :x for x in range(10)] >>> x 9 So at this point x is 9 and a function written to return the value bound to the name x will return 9 >>> li[0]() 9 >>> x = 42 >>> li[0]() 42 This is called late binding and neither the lambda behaves like any other function >>> def f(): return x ... >>> f() 42 >>> x = "whatever" >>> f() 'whatever' To get the desired results you can either use default values which are bound when the function is created >>> li = [lambda x=x: x for x in range(9)] >>> li[0]() 0 >>> li[5]() 5 or a closure: >>> li = [(lambda x: lambda: x)(x) for x in range(9)] >>> li[0]() 0 >>> li[5]() 5 This looks less messy when you use a function: >>> def make_const_func(value): ... return lambda: value ... >>> li = [make_const_func(x) for x in range(9)] >>> li[7]() 7 In both cases the value is bound inside a function and not affected by the current binding of the global x. In Python 3 the situation is almost the same, except that the x from the list comprehension is no longer exposed to the enclosing namespace. From antoon.pardon at rece.vub.ac.be Tue Sep 27 04:36:53 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 27 Sep 2016 10:36:53 +0200 Subject: it looks strange In-Reply-To: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> References: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> Message-ID: <57EA2FA5.4020809@rece.vub.ac.be> Op 27-09-16 om 10:09 schreef cpxuvs at gmail.com: >>>> li=[lambda :x for x in range(10)] >>>> res=li[0]() >>>> print res > 9 > > why? Because there is no nested scope for the x variable.So your list looks like this: [lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda :x] with x having the value 9, being the last value through the loop. So your code is quivallent to the following. >>> li=[lambda :x for t in range(10)] >>> x = 9 What you probably want is the following: >>> li = [(lambda t: lambda :t)(x) for x in range(10)] From cpxuvs at gmail.com Tue Sep 27 04:46:14 2016 From: cpxuvs at gmail.com (Cpcp Cp) Date: Tue, 27 Sep 2016 01:46:14 -0700 (PDT) Subject: it looks strange In-Reply-To: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> References: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> Message-ID: I get it.Thanks! From lawrencedo99 at gmail.com Tue Sep 27 05:04:13 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 27 Sep 2016 02:04:13 -0700 (PDT) Subject: it looks strange In-Reply-To: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> References: <4943e31f-95a8-48a6-b900-7df6af41040a@googlegroups.com> Message-ID: <7982926b-b9d7-4078-a452-c6ec3f5d71b6@googlegroups.com> On Tuesday, September 27, 2016 at 9:09:55 PM UTC+13, Cpcp Cp wrote: > >>> li=[lambda :x for x in range(10)] Try li = [(lambda x : lambda : x)(x) for x in range(10)] print(li[0]()) print(li[9]()) 0 9 From ned at nedbatchelder.com Tue Sep 27 07:24:56 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 27 Sep 2016 04:24:56 -0700 (PDT) Subject: PyImport_AddModule vs PyImport_Import In-Reply-To: References: Message-ID: <9f36c1fb-b17b-4082-92b3-bbe20464b622@googlegroups.com> On Tuesday, September 27, 2016 at 3:54:01 AM UTC-4, dl l wrote: > What is the difference between PyImport_AddModule and PyImport_Import? > > When need to use PyImport_AddModule? > > When need to use PyImport_Import? Does this paragraph from the docs help? > Note > > This function does not load or import the module; if the module wasn?t already loaded, you will get an empty module object. Use PyImport_ImportModule() or one of its variants to import a module. Package structures implied by a dotted name for name are not created if not already present. https://docs.python.org/2/c-api/import.html#c.PyImport_AddModule --Ned. From steve+python at pearwood.info Tue Sep 27 08:57:59 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 27 Sep 2016 22:57:59 +1000 Subject: How to make a copy of chained dicts effectively and nicely? References: Message-ID: <57ea6cda$0$22141$c3e8da3$5496439d@news.astraweb.com> On Tue, 27 Sep 2016 05:08 pm, Nagy Lc3a1szlc3b3 Zsolt wrote: > #2. Much more effective version, but requires too many lines: > > d= {} > d.update(d1) > d.update(d2) > d.update(d3) new_dict = {} for d in (d1, d2, d3): new_dict.update(d) Or, if you know for sure there's only three dicts: new_dict = d1.copy() new_dict.update(d2, **d3) Or if you prefer: new_dict = dict(d1) # same as copying new_dict.update(d2, **d3) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jussi.piitulainen at helsinki.fi Tue Sep 27 09:27:24 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 27 Sep 2016 16:27:24 +0300 Subject: How to make a copy of chained dicts effectively and nicely? References: Message-ID: Lawrence D?Oliveiro writes: > On Tuesday, September 27, 2016 at 8:08:46 PM UTC+13, Nagy L?szl? Zsolt wrote: >> d1 = {'a':1, 'b':2} >> d2 = {'c':3, 'd':4} >> d3 = {'e':5, 'f':6} >> >> Is there a version that is as effective as #3, but as clean and nice as #4? > > dict(dict(d1, **d2), **d3) Nice expression. But that's not available if the keys are not strings: dict({}, **{ 1:3 }) ==> Traceback (most recent call last): File "", line 1, in TypeError: keyword arguments must be strings On the other hand, '1' seemed to work (in Python 3.4.3) as key, though 1 cannot possibly be a keyword parameter in a function definition :) Also related to the use of **, are there any practical limitations to how many parameters a Python function may have? Or is it guaranteed safe to spread, say, hundreds of thousands of dictionary keys this way? Just wondering. From __peter__ at web.de Tue Sep 27 09:44:06 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Sep 2016 15:44:06 +0200 Subject: How to make a copy of chained dicts effectively and nicely? References: Message-ID: Nagy L?szl? Zsolt wrote: > The result that I need should be a real dict, not just a ChainMap. (It > is because I have to mutate it.) > > d1 = {'a':1, 'b':2} > d2 = {'c':3, 'd':4} > d3 = {'e':5, 'f':6} > > #1. My first naive approach was: > > > from collections import ChainMap > d = {} > for key,value in ChainMap(d1, d2, d3).items(): > d[key] = value > > #2. Much more effective version, but requires too many lines: > > d= {} > d.update(d1) > d.update(d2) > d.update(d3) Unsolicited advice: you have to reverse the order with respect to ChainMap if there are duplicate keys: >>> a = dict(a=1, b=2) >>> b = dict(b=3, c=4) >>> d = {} >>> d.update(a) >>> d.update(b) >>> d == dict(ChainMap(a, b)) False >>> d == dict(ChainMap(b, a)) True With that in mind here's another version for your zoo: >>> class MyChainMap(ChainMap): ... def materialized(self): ... d = {} ... for map in reversed(self.maps): ... d.update(map) ... return d ... >>> MyChainMap(b, a).materialized() {'a': 1, 'c': 4, 'b': 3} >>> _ == d True If you say > requires too many lines is counter with "Write once, run anywhere". From pengyu.ut at gmail.com Tue Sep 27 10:01:23 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 27 Sep 2016 09:01:23 -0500 Subject: Is there a way to change the closure of a python function? Message-ID: Hi, In many other functional language, one can change the closure of a function. Is it possible in python? http://ynniv.com/blog/2007/08/closures-in-python.html -- Regards, Peng From ldlchina at gmail.com Tue Sep 27 10:29:47 2016 From: ldlchina at gmail.com (dl l) Date: Tue, 27 Sep 2016 22:29:47 +0800 Subject: PyImport_AddModule vs PyImport_Import In-Reply-To: <9f36c1fb-b17b-4082-92b3-bbe20464b622@googlegroups.com> References: <9f36c1fb-b17b-4082-92b3-bbe20464b622@googlegroups.com> Message-ID: Thanks. That's helpful. I did not notice the note. 2016-09-27 19:24 GMT+08:00 Ned Batchelder : > On Tuesday, September 27, 2016 at 3:54:01 AM UTC-4, dl l wrote: > > What is the difference between PyImport_AddModule and PyImport_Import? > > > > When need to use PyImport_AddModule? > > > > When need to use PyImport_Import? > > Does this paragraph from the docs help? > > > Note > > > > This function does not load or import the module; if the module wasn?t > already loaded, you will get an empty module object. Use > PyImport_ImportModule() or one of its variants to import a module. Package > structures implied by a dotted name for name are not created if not already > present. > > https://docs.python.org/2/c-api/import.html#c.PyImport_AddModule > > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Tue Sep 27 10:35:16 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Sep 2016 16:35:16 +0200 Subject: Is there a way to change the closure of a python function? References: Message-ID: Peng Yu wrote: > Hi, In many other functional language, one can change the closure of a > function. Which are those languages, and how do they work? And is Python actually a "functional language"? > Is it possible in python? I'm not sure what you mean. Something like >>> def f(x): ... def g(y): ... return x + y ... def h(newx): ... nonlocal x ... x = newx ... return g, h ... >>> a, b = f(10) >>> a(42) 52 >>> b(20) >>> a(42) 62 ? > http://ynniv.com/blog/2007/08/closures-in-python.html A short explanation would have been better than that link. From python at mrabarnett.plus.com Tue Sep 27 10:39:27 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Sep 2016 15:39:27 +0100 Subject: How to make a copy of chained dicts effectively and nicely? In-Reply-To: References: Message-ID: <690e8ef4-2159-3c5f-b20c-96c782146839@mrabarnett.plus.com> On 2016-09-27 08:32, Jussi Piitulainen wrote: [snip] > Is ChainMap really that bad? Otherwise the following would look somewhat > nice: > > d = dict(ChainMap(d1, d2, d3).items()) > > Those come to mind. > You can copy a dict just by passing it to 'dict': d = dict(d1) so I wondered if you can do the same with ChainMap: d = dict(ChainMap(d1, d2, d3)) Yep, you can! From jeanmichel at sequans.com Tue Sep 27 10:41:13 2016 From: jeanmichel at sequans.com (jmp) Date: Tue, 27 Sep 2016 16:41:13 +0200 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On 09/27/2016 04:01 PM, Peng Yu wrote: > Hi, In many other functional language, one can change the closure of a > function. Is it possible in python? > > http://ynniv.com/blog/2007/08/closures-in-python.html > If I understood correctly your link: (untested) def func(x): return x+func.y func.y = 10 func(5) => 15 func.y = 100 func(5) => 105 implements a closure of a function. jm Note: function are objects, and can have attributes, however I rarely see usage of these, there could be good reasons for that. From jussi.piitulainen at helsinki.fi Tue Sep 27 10:54:04 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 27 Sep 2016 17:54:04 +0300 Subject: How to make a copy of chained dicts effectively and nicely? References: <690e8ef4-2159-3c5f-b20c-96c782146839@mrabarnett.plus.com> Message-ID: MRAB writes: > On 2016-09-27 08:32, Jussi Piitulainen wrote: > [snip] > >> Is ChainMap really that bad? Otherwise the following would look somewhat >> nice: >> >> d = dict(ChainMap(d1, d2, d3).items()) >> >> Those come to mind. >> > You can copy a dict just by passing it to 'dict': > > d = dict(d1) > > so I wondered if you can do the same with ChainMap: > > d = dict(ChainMap(d1, d2, d3)) > > Yep, you can! I wasn't sure if it makes a copy or just returns the dict. But it's true: help(dict) says dict(mapping) is a "new dictionary initialized from a mapping object's (key, value) pairs". From ian.g.kelly at gmail.com Tue Sep 27 10:57:19 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 27 Sep 2016 08:57:19 -0600 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Tue, Sep 27, 2016 at 8:41 AM, jmp wrote: > On 09/27/2016 04:01 PM, Peng Yu wrote: >> >> Hi, In many other functional language, one can change the closure of a >> function. Is it possible in python? >> >> http://ynniv.com/blog/2007/08/closures-in-python.html >> > > If I understood correctly your link: > > (untested) > def func(x): > return x+func.y > > func.y = 10 > func(5) => 15 > func.y = 100 > func(5) => 105 > > implements a closure of a function. That is not a closure. A closure is a construct of lexical scoping. This is an example of a closure: def f(x): def g(): return x return g We say that the variables of f are "closed" over the function g. An example of use: py> g1 = f(42) py> g2 = f(64) py> g1() 42 py> g2() 64 Note that each closure has its own value of x. The link suggests that object methods in Python are closures because of the self argument, but I disagree with that; closures are constructs of lexical scoping. From rosuav at gmail.com Tue Sep 27 11:01:13 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 01:01:13 +1000 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: > Hi, In many other functional language, one can change the closure of a > function. Is it possible in python? > > http://ynniv.com/blog/2007/08/closures-in-python.html > >From the blog post: """In some languages, the variable bindings contained in a closure behave just like any other variables. Alas, in python they are read-only.""" This is not true, at least as of Python 3. def makeInc(x): def inc(y, moreinc=0): # x is "closed" in the definition of inc nonlocal x x += moreinc return y + x return inc The 'nonlocal' keyword is like 'global', applying only to assignments (the blog post already mentions the possibility of mutating an object rather than reassigning it), and permitting assignment into a broader scope than the function's locals. You can also have multiple closures in the same context, and changes made by one of them will affect the others. ChrisA From rosuav at gmail.com Tue Sep 27 11:26:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 01:26:06 +1000 Subject: How to make a copy of chained dicts effectively and nicely? In-Reply-To: References: <690e8ef4-2159-3c5f-b20c-96c782146839@mrabarnett.plus.com> Message-ID: On Wed, Sep 28, 2016 at 12:54 AM, Jussi Piitulainen wrote: > I wasn't sure if it makes a copy or just returns the dict. But it's > true: help(dict) says dict(mapping) is a "new dictionary initialized > from a mapping object's (key, value) pairs". Yep. With mutable objects, Python's docs are usually pretty clear that you get a brand-new object every time: >>> x = [1,2,3,4] >>> y = list(x) >>> x == y True >>> x is y False >>> help(list) class list(object) | list() -> new empty list | list(iterable) -> new list initialized from iterable's items With immutables, the docs aren't always explicit, since by definition it can't matter. Sometimes they are, though: >>> x = 1,2,3 >>> tuple(x) is x True >>> help(tuple) class tuple(object) | tuple() -> empty tuple | tuple(iterable) -> tuple initialized from iterable's items | | If the argument is a tuple, the return value is the same object. Sometimes things get rather interesting. >>> help(int) class int(object) | int(x=0) -> integer | int(x, base=10) -> integer | | Convert a number or string to an integer, or return 0 if no arguments | are given. If x is a number, return x.__int__(). For floating point | numbers, this truncates towards zero. >>> class SubInt(int): ... def __int__(self): return self ... >>> x = SubInt(123) >>> x.__int__() is x True >>> int(x) is x False >>> type(int(x)) Calling int(x) can return the exact object x, but only if x is an actual int, not a subclass. If it's a subclass, you get a base integer with the same value. In any case, mutables are generally going to be safe: every time you call the constructor, you get a new object. They won't try to cheat and return a reference to the same object. ChrisA From steve+python at pearwood.info Tue Sep 27 11:49:56 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 28 Sep 2016 01:49:56 +1000 Subject: How to reduce the DRY violation in this code Message-ID: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> I have a class that takes a bunch of optional arguments. They're all optional, with default values of various types. For simplicity, let's say some are ints and some are floats: class Spam: def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, grumpy=40, happy=50, sleepy=60, sneezy=70): # the usual assign arguments to attributes dance... self.bashful = bashful self.doc = doc # etc. I also have an alternative constructor that will be called with string arguments. It converts the strings to the appropriate type, then calls the real constructor, which calls __init__. Again, I want the arguments to be optional, which means providing default values: @classmethod def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0', grumpy='40', happy='50', sleepy='60', sneezy='70'): bashful = float(bashful) doc = float(doc) dopey = float(dopey) grumpy = int(grumpy) happy = int(happy) sleepy = int(sleepy) sneezy = int(sneezy) return cls(bashful, doc, dopey, grumpy, happy, sleepy, sneezy) That's a pretty ugly DRY violation. Imagine that I change the default value for bashful from 10.0 to (let's say) 99. I have to touch the code in three places (to say nothing of unit tests): - modify the default value in __init__ - modify the stringified default value in from_strings - change the conversion function from float to int in from_strings Not to mention that each parameter is named seven times. How can I improve this code to reduce the number of times I have to repeat myself? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Tue Sep 27 12:21:19 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 27 Sep 2016 19:21:19 +0300 Subject: How to reduce the DRY violation in this code References: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vaxhqpog.fsf@elektro.pacujo.net> Steve D'Aprano : > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > [...] > > @classmethod > def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0', > grumpy='40', happy='50', sleepy='60', sneezy='70'): > [...] > > That's a pretty ugly DRY violation. Imagine that I change the default > value for bashful from 10.0 to (let's say) 99. I have to touch the > code in three places (to say nothing of unit tests): OMITTED = object() def __init__(self, bashful=OMITTED, doc=OMITTED, dopey=OMITTED, grumpy=OMITTED, happy=OMITTED, sleepy=OMITTED, sneezy=OMITTED): # the usual assign arguments to attributes dance... self.bashful = 10.0 if bashful is OMITTED else bashful self.doc = 20.0 if doc is OMITTED else doc [...] @classmethod def from_strings(cls, bashful=OMITTED, doc=OMITTED dopey=OMITTED, grumpy=OMITTED, happy=OMITTED, sleepy=OMITTED, sneezy=OMITTED): if bashful is not OMITTED: bashful = float(bashful) if doc is not OMITTED: doc = float(doc) [...] Helper functions will make it look a bit less repetitious. Marko From rosuav at gmail.com Tue Sep 27 12:39:28 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 02:39:28 +1000 Subject: How to reduce the DRY violation in this code In-Reply-To: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 28, 2016 at 1:49 AM, Steve D'Aprano wrote: > @classmethod > def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0', > grumpy='40', happy='50', sleepy='60', sneezy='70'): > bashful = float(bashful) > doc = float(doc) > dopey = float(dopey) > grumpy = int(grumpy) > happy = int(happy) > sleepy = int(sleepy) > sneezy = int(sneezy) > return cls(bashful, doc, dopey, grumpy, happy, sleepy, sneezy) > > > That's a pretty ugly DRY violation. Imagine that I change the default value > for bashful from 10.0 to (let's say) 99. I have to touch the code in three > places (to say nothing of unit tests): > > - modify the default value in __init__ > - modify the stringified default value in from_strings > - change the conversion function from float to int in from_strings > > > Not to mention that each parameter is named seven times. > You could go data-driven. Assuming that all your default values are in the appropriate type (eg you use 10.0 rather than 10, when you want a float), you could use those directly. class Spam: def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, grumpy=40, happy=50, sleepy=60, sneezy=70): for name, default in zip(self.__init__.__defaults__, self.__init__.__code__.co_varnames[1:]): setattr(self, name, type(default)(locals()[name])) Your basic __init__ method is now capable of handling strings as well, so from_strings can simply construct the object directly. I'm not sure what the advantage of from_strings is, but assuming you still need it, you could write it thus: @classmethod def from_strings(cls, bashful, doc, dopey, grumpy, happy, sleepy, sneezy): return cls(bashful, doc, dopey, grumpy, happy, sleepy, sneezy) from_strings.__func__.__defaults__ = tuple(str(x) for x in __init__.__defaults__) No duplication of type names or default values, though there is still duplication of parameter names. You could eliminate that by going *args,**kw, but at the expense of introspectability. Actually, you could probably just use wraps... @classmethod @functools.wraps(__init__, assigned=()) def from_strings(cls, *a, **kw): return cls(*a, **kw) from_strings.__func__.__defaults__ = tuple(str(x) for x in __init__.__defaults__) Though I'm not particularly enamoured of this way of doing it. ChrisA From python.list at tim.thechases.com Tue Sep 27 12:56:38 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 Sep 2016 11:56:38 -0500 Subject: Case insensitive replacement? Message-ID: <20160927115638.2054f939@bigbox.christie.dr> I'd like to do a case-insensitive replacement in a string but want to do it pythonically. Ideally, the code would something like needle = "World" haystack = "Hello, world!" replacement = "THERE" result = haystack.replace(needle, replacement, ignore_case=True) # result would be "Hello, THERE!" As that's not an option, I can do it either with string-hacking: try: index = haystack.upper().find(needle.upper()) except ValueError: result = haystack else: result = ( haystack[:index] + replacement + haystack[index + len(needle):] ) or with regexes: import re r = re.compile(re.escape(needle), re.I) result = r.sub(replacement, haystack) The regex version is certainly tidier, but it feels a bit like killing a fly with a rocket-launcher. Are there other/better options that I've missed? Also, if it makes any difference, my replacement in this use-case is actually deletion, so replacement="" Thanks, -tkc From gerald.britton at gmail.com Tue Sep 27 13:08:25 2016 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 27 Sep 2016 13:08:25 -0400 Subject: How to reduce the DRY violation in this code Message-ID: > > I have a class that takes a bunch of optional arguments. They're all > optional, with default values of various types. For simplicity, let's say > some are ints and some are floats: class Spam: > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > # the usual assign arguments to attributes dance... > self.bashful = bashful > self.doc = doc > # etc. This looks like a situation where the GoF Builder pattern might help -- Gerald Britton, MCSE-DP, MVP LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton From python at mrabarnett.plus.com Tue Sep 27 13:10:50 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Sep 2016 18:10:50 +0100 Subject: Case insensitive replacement? In-Reply-To: <20160927115638.2054f939@bigbox.christie.dr> References: <20160927115638.2054f939@bigbox.christie.dr> Message-ID: <019a8e22-055c-5068-b304-fd118ba73e56@mrabarnett.plus.com> On 2016-09-27 17:56, Tim Chase wrote: > I'd like to do a case-insensitive replacement in a string but want to > do it pythonically. Ideally, the code would something like > > needle = "World" > haystack = "Hello, world!" > replacement = "THERE" > result = haystack.replace(needle, replacement, ignore_case=True) > # result would be "Hello, THERE!" > > As that's not an option, I can do it either with string-hacking: > > try: > index = haystack.upper().find(needle.upper()) > except ValueError: > result = haystack > else: > result = ( > haystack[:index] > + replacement > + haystack[index + len(needle):] > ) > The disadvantage of your "string-hacking" is that you're assuming that the uppercase version of a string is the same length as the original: That's not always the case: Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> '\N{LATIN SMALL LETTER SHARP S}' '?' >>> '\N{LATIN SMALL LETTER SHARP S}'.upper() 'SS' >>> > or with regexes: > > import re > r = re.compile(re.escape(needle), re.I) > result = r.sub(replacement, haystack) > > The regex version is certainly tidier, but it feels a bit like > killing a fly with a rocket-launcher. > > Are there other/better options that I've missed? > > Also, if it makes any difference, my replacement in this use-case is > actually deletion, so replacement="" > From no.email at nospam.invalid Tue Sep 27 13:20:48 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 27 Sep 2016 10:20:48 -0700 Subject: How to reduce the DRY violation in this code References: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y42d5ken.fsf@jester.gateway.pace.com> Steve D'Aprano writes: > class Spam: > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > # the usual assign arguments to attributes dance... > self.bashful = bashful > self.doc = doc > # etc. def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, grumpy=40, happy=50, sleepy=60, sneezy=70): # the usual assign arguments to attributes dance... self.bashful = float(bashful) self.doc = float(doc) self.grumpy = int(grumpy) # etc. Now the constructor can take strings as keywords. You could even do something like: defaults = { 'bashful':10.0, 'grumpy':20, etc. } def __init__(self, **kwargs): # check for spurious kwargs assert(not(set(kwargs)-set(defaults))) for k in defaults: v = type(defaults[k])(kwargs[k]) if k in kwargs else defaults[k] setattr(self, k, v) From rosuav at gmail.com Tue Sep 27 13:26:50 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 03:26:50 +1000 Subject: How to reduce the DRY violation in this code In-Reply-To: References: Message-ID: On Wed, Sep 28, 2016 at 3:08 AM, Gerald Britton wrote: >> >> I have a class that takes a bunch of optional arguments. They're all >> optional, with default values of various types. For simplicity, let's say >> some are ints and some are floats: class Spam: >> def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, >> grumpy=40, happy=50, sleepy=60, sneezy=70): >> # the usual assign arguments to attributes dance... >> self.bashful = bashful >> self.doc = doc >> # etc. > > > This looks like a situation where the GoF Builder pattern might help Can you elaborate on what "GoF builder" means? Presumably it's a special case of the builder pattern, but my Google-fu has failed me on this one. ChrisA From no.email at nospam.invalid Tue Sep 27 13:28:28 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 27 Sep 2016 10:28:28 -0700 Subject: Case insensitive replacement? References: <20160927115638.2054f939@bigbox.christie.dr> Message-ID: <87twd15k1v.fsf@jester.gateway.pace.com> > needle = "World" > haystack = "Hello, world!" > replacement = "THERE" > result = haystack.replace(needle, replacement, ignore_case=True) > # result would be "Hello, THERE!" >>> import re >>> re.sub('(?i)world','THERE','Hello World') 'Hello THERE' From no.email at nospam.invalid Tue Sep 27 13:30:05 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 27 Sep 2016 10:30:05 -0700 Subject: How to reduce the DRY violation in this code References: Message-ID: <87ponp5jz6.fsf@jester.gateway.pace.com> Chris Angelico writes: > Can you elaborate on what "GoF builder" means? Presumably it's a > special case of the builder pattern, I think it just means the usual builder pattern, from the Design Patterns book by the so-called Gang of Four (GoF). From best_lay at yahoo.com Tue Sep 27 13:53:01 2016 From: best_lay at yahoo.com (Wildman) Date: Tue, 27 Sep 2016 12:53:01 -0500 Subject: How to reduce the DRY violation in this code References: <87ponp5jz6.fsf@jester.gateway.pace.com> Message-ID: On Tue, 27 Sep 2016 10:30:05 -0700, Paul Rubin wrote: > Chris Angelico writes: >> Can you elaborate on what "GoF builder" means? Presumably it's a >> special case of the builder pattern, > > I think it just means the usual builder pattern, from the Design > Patterns book by the so-called Gang of Four (GoF). http://c2.com/cgi/wiki?GangOfFour -- GNU/Linux user #557453 Keyboard not detected! Press any key to continue... From kai.peters at gmail.com Tue Sep 27 15:58:40 2016 From: kai.peters at gmail.com (TUA) Date: Tue, 27 Sep 2016 12:58:40 -0700 (PDT) Subject: Can this be easily done in Python? Message-ID: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> Is the following possible in Python? Given how the line below works TransactionTerms = 'TransactionTerms' have something like TransactionTerms = that sets the variable TransactionTerms to its own name as string representation without having to specify it explicitly as in the line above.... From no.email at nospam.invalid Tue Sep 27 16:45:05 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 27 Sep 2016 13:45:05 -0700 Subject: Can this be easily done in Python? References: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> Message-ID: <871t055ay6.fsf@jester.gateway.pace.com> TUA writes: > TransactionTerms = > that sets the variable TransactionTerms to its own name as string It's conceivably possible using messy introspection hackery, but if you're asking that question you don't want to think about doing it that way. If you describe the actual goal (application) you might get more usable suggestions. From tjreedy at udel.edu Tue Sep 27 16:48:06 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Sep 2016 16:48:06 -0400 Subject: event loop vs threads In-Reply-To: References: Message-ID: On 9/27/2016 12:01 AM, srinivas devaki wrote: > how does Python switch execution and maintain context i.e function stack > etc,.. for co-routines and why is it less costly than switching threads > which almost do the same, and both are handled by Python Interpreter > itself(event loop for co-routines and GIL scheduling for threading), so > where does the extra overhead for threads come from ? Thread switching is done by the interpreter, either when a thread calls a blocking i/o function or when a time slice expires. You can read the asyncio.base_event code and other submodules for details on how asyncio works. -- Terry Jan Reedy From random832 at fastmail.com Tue Sep 27 16:53:47 2016 From: random832 at fastmail.com (Random832) Date: Tue, 27 Sep 2016 16:53:47 -0400 Subject: Can this be easily done in Python? In-Reply-To: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> References: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> Message-ID: <1475009627.3139854.738933297.09D748DC@webmail.messagingengine.com> On Tue, Sep 27, 2016, at 15:58, TUA wrote: > Is the following possible in Python? > > Given how the line below works > > TransactionTerms = 'TransactionTerms' > > > have something like > > TransactionTerms = > > that sets the variable TransactionTerms to its own name as string > representation without having to specify it explicitly as in the line > above.... What are you trying to do? If you're trying to avoid saying it twice: exec('%s=%r'%['TransactionTerms']*2) If you're trying to avoid having it as a string: def TransactionTerms(): pass TransactionTerms = TransactionTerms.__name__ From tjreedy at udel.edu Tue Sep 27 17:19:02 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Sep 2016 17:19:02 -0400 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On 9/27/2016 11:01 AM, Chris Angelico wrote: > On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: >> Hi, In many other functional language, one can change the closure of a >> function. Is it possible in python? >> >> http://ynniv.com/blog/2007/08/closures-in-python.html >> > > From the blog post: > > """In some languages, the variable bindings contained in a closure > behave just like any other variables. Alas, in python they are > read-only.""" > > This is not true, at least as of Python 3. > > def makeInc(x): > def inc(y, moreinc=0): > # x is "closed" in the definition of inc > nonlocal x > x += moreinc > return y + x > return inc The value of the cell variable is writable from within the body of the closure function if declared nonlocal, but not otherwise, and not from without. The latter may be what Peng meant by 'change' and the blogger by 'read-only'. def makeInc(x): def inc(y, moreinc=0): # x is "closed" in the definition of inc nonlocal x x += moreinc return y + x return inc f = makeInc(23) fclose = f.__closure__ # a tuple of 'cells' fcell = fclose[0] print(dir(fcell)) # ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', # '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', # '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', # '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', # '__sizeof__', '__str__', '__subclasshook__', 'cell_contents'] # Note: no mutation method print('cell content = ', fcell.cell_contents) # cell content = 23 fcell.cell_contents = 32 ### results in Traceback (most recent call last): File "F:\Python\mypy\tem.py", line 14, in fcell.cell_contents = 32 AttributeError: attribute 'cell_contents' of 'cell' objects is not writable # unless one does so from within the closure body with 'nonlocal' declaration. I presume there is a special byte code for this. -- Terry Jan Reedy From rosuav at gmail.com Tue Sep 27 17:33:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 07:33:02 +1000 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Wed, Sep 28, 2016 at 7:19 AM, Terry Reedy wrote: > The value of the cell variable is writable from within the body of the > closure function if declared nonlocal, but not otherwise, and not from > without. The latter may be what Peng meant by 'change' and the blogger by > 'read-only'. > Not from entirely without, but it's possible for two functions to share a cell. I don't know the mechanics of how nonlocal assignment works, but ultimately, it's updating the cell that both closures see, so it's going to affect the other function too. ChrisA From ian.g.kelly at gmail.com Tue Sep 27 17:56:39 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 27 Sep 2016 15:56:39 -0600 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Tue, Sep 27, 2016 at 3:19 PM, Terry Reedy wrote: > On 9/27/2016 11:01 AM, Chris Angelico wrote: >> >> On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: >>> >>> Hi, In many other functional language, one can change the closure of a >>> function. Is it possible in python? >>> >>> http://ynniv.com/blog/2007/08/closures-in-python.html >>> >> >> From the blog post: >> >> """In some languages, the variable bindings contained in a closure >> behave just like any other variables. Alas, in python they are >> read-only.""" >> >> This is not true, at least as of Python 3. >> >> def makeInc(x): >> def inc(y, moreinc=0): >> # x is "closed" in the definition of inc >> nonlocal x >> x += moreinc >> return y + x >> return inc > > > The value of the cell variable is writable from within the body of the > closure function if declared nonlocal, but not otherwise, and not from > without. The latter may be what Peng meant by 'change' and the blogger by > 'read-only'. > > def makeInc(x): > def inc(y, moreinc=0): > # x is "closed" in the definition of inc > nonlocal x > x += moreinc > return y + x > return inc > > f = makeInc(23) > fclose = f.__closure__ # a tuple of 'cells' > fcell = fclose[0] > > print(dir(fcell)) > # ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', > # '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', > # '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', > # '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', > # '__sizeof__', '__str__', '__subclasshook__', 'cell_contents'] > # Note: no mutation method > > print('cell content = ', fcell.cell_contents) > # cell content = 23 > > fcell.cell_contents = 32 > ### results in > Traceback (most recent call last): > File "F:\Python\mypy\tem.py", line 14, in > fcell.cell_contents = 32 > AttributeError: attribute 'cell_contents' of 'cell' objects is not writable > # unless one does so from within the closure body with 'nonlocal' > declaration. I presume there is a special byte code for this. You could, however, put a mutable object in the cell variable and then modify it from without. E.g.: def makeInc(x): x = [x] def inc(y, moreinc=0): x[0] += moreinc return y + x[0] return inc f = makeInc(23) fcell = f.__closure__[0] fcell.cell_contents # [23] fcell.cell_contents[0] = 42 f(0) # 42 From greg.ewing at canterbury.ac.nz Tue Sep 27 18:23:46 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 28 Sep 2016 11:23:46 +1300 Subject: Nested for loops and print statements In-Reply-To: <7ab29fc4-89a6-4680-930a-f85ea6942cf6@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> <0210da93-b7e6-4421-9d5f-bc774740d78c@googlegroups.com> <7ab29fc4-89a6-4680-930a-f85ea6942cf6@googlegroups.com> Message-ID: Cai Gengyang wrote: > How are you running the interactive interpreter? Are you > using IDLE, or are you running Python in a command window? --- IDLE I don't normally use IDLE on MacOSX, so I had to try it to find out. I think I know what your problem is now. When you type a line into IDLE ending with a colon and press enter, it automatically indents the next line, and it does it using *tab* characters. You can see this by selecting the indentation with the mouse. You'll notice that it highlights in big chunks -- those are tab characters. This means that any extra indentation you add yourself also needs to be done by pressing the tab key, not the space bar, otherwise you risk mixing up tabs and spaces in ways that Python doesn't like. -- Greg From lawrencedo99 at gmail.com Tue Sep 27 18:27:25 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 27 Sep 2016 15:27:25 -0700 (PDT) Subject: How to make a copy of chained dicts effectively and nicely? In-Reply-To: References: Message-ID: On Wednesday, September 28, 2016 at 2:27:36 AM UTC+13, Jussi Piitulainen wrote: > Lawrence D?Oliveiro writes: >> dict(dict(d1, **d2), **d3) > > Nice expression. But that's not available if the keys are not strings: > > dict({}, **{ 1:3 }) > ==> > Traceback (most recent call last): > File "", line 1, in > TypeError: keyword arguments must be strings > > On the other hand, '1' seemed to work (in Python 3.4.3) as key, though 1 > cannot possibly be a keyword parameter in a function definition :) Pity. I wonder why it bothers to check? From lawrencedo99 at gmail.com Tue Sep 27 18:35:30 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 27 Sep 2016 15:35:30 -0700 (PDT) Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: > is Python actually a "functional language"? Yes . From lawrencedo99 at gmail.com Tue Sep 27 18:36:48 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 27 Sep 2016 15:36:48 -0700 (PDT) Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: <2a9f8701-56e6-4083-9a74-f068baab1dcf@googlegroups.com> On Wednesday, September 28, 2016 at 4:01:36 AM UTC+13, Chris Angelico wrote: > You can also have multiple closures in the same context, and changes made by > one of them will affect the others. This is the point where it?s probably easier to wrap them all together into methods of a common class. From greg.ewing at canterbury.ac.nz Tue Sep 27 18:47:33 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 28 Sep 2016 11:47:33 +1300 Subject: Getting IDLE to use correct Tcl/Tk on MacOSX 10.6? Message-ID: I don't normally use IDLE, but I had occasion to use it on MacOSX 10.6 to answer someone's question, and of course it didn't work properly due to Apple's broken Tcl/Tk. I followed the advice to install ActiveState Tcl 8.5.18.0, but my Python still wants to use Apple's Tcl. How do I persuade Python to use the new one I've installed? It's a framework install of Python 3.5 that I compiled myself. Do I need to rebuild it to get it to pick up the right Tcl? Or is there an environment variable I can set? -- Greg From ldlchina at gmail.com Tue Sep 27 21:28:45 2016 From: ldlchina at gmail.com (dl l) Date: Wed, 28 Sep 2016 09:28:45 +0800 Subject: Python C API: How to debug reference leak? In-Reply-To: References: <87wphxddwc.fsf@handshake.de> Message-ID: When I debug in C++, I see the reference count of a PyObject is 1. I don't know where is referencing this object. How can I find out where is referencing this object? 2016-09-27 15:47 GMT+08:00 dl l : > Thanks for reply. Is there any function in C to get the reference objects > of a object? I want to debug where are referencing the object. > > 2016-09-27 15:01 GMT+08:00 dieter : > >> dl l writes: >> > I want to check the references of an object. Any way to get the >> references >> > of an object with Python C API? Like: gc.get_referrs(), is there similar >> > API in C lib? >> >> "gc" is a module. You can import and access modules from the C API. >> Thus, you can use "gc.get_referers" from "C" code. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From jfong at ms4.hinet.net Tue Sep 27 22:13:51 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 27 Sep 2016 19:13:51 -0700 (PDT) Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: Message-ID: eryk sun at 2016/9/27 11:44:49AM wrote: > The threads of a process do not share a single core. The OS schedules > threads to distribute the load across all cores.... hmmm... your answer overthrow all my knowledge about Python threads completely:-( I actually had ever considered using ProcessPoolExecutor to do it. If the load was distributed by the OS schedules across all cores, does it means I can't make one core solely running a piece of codes for me and so I have no contol on its performance? From orgnut at yahoo.com Tue Sep 27 22:48:50 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 27 Sep 2016 19:48:50 -0700 Subject: Nested for loops and print statements In-Reply-To: <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> Message-ID: On 09/26/2016 01:57 PM, Cai Gengyang wrote: > Ok it works now: > >>>> for row in range(10): > for column in range(10): > print("*",end="") > > > **************************************************************************************************** > > but how is it different from --- > >>>> for row in range(10): > for column in range(10): > print("*",end="") > > SyntaxError: inconsistent use of tabs and spaces in indentation > > Why does the example on top work and the example below doesn't work ? The only difference is that the "print" statement is one space different from each other. Forgive me if i can't explain things clearly over the forum > As they came through in the newsgroup, BOTH run correctly, because both versions had leading spaces only. (I did a careful copy/paste to check this.) Tabs are sometimes handled incorrectly/inconsistently in newsgroup postings. But if you read the Traceback error message, it is telling you that you have a mix of tabs and spaces _in your original_. READ the error messages, they are important! -- -=- Larry -=- From pengyu.ut at gmail.com Tue Sep 27 22:49:31 2016 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 27 Sep 2016 21:49:31 -0500 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Tue, Sep 27, 2016 at 10:01 AM, Chris Angelico wrote: > On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: >> Hi, In many other functional language, one can change the closure of a >> function. Is it possible in python? >> >> http://ynniv.com/blog/2007/08/closures-in-python.html >> > > From the blog post: > > """In some languages, the variable bindings contained in a closure > behave just like any other variables. Alas, in python they are > read-only.""" > > This is not true, at least as of Python 3. So in Python 2, this is true? > def makeInc(x): > def inc(y, moreinc=0): > # x is "closed" in the definition of inc > nonlocal x > x += moreinc > return y + x > return inc > > The 'nonlocal' keyword is like 'global', applying only to assignments > (the blog post already mentions the possibility of mutating an object > rather than reassigning it), and permitting assignment into a broader > scope than the function's locals. You can also have multiple closures > in the same context, and changes made by one of them will affect the > others. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards, Peng From gheskett at shentel.net Tue Sep 27 23:56:15 2016 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 27 Sep 2016 23:56:15 -0400 Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: Message-ID: <201609272356.15575.gheskett@shentel.net> On Tuesday 27 September 2016 22:13:51 jfong at ms4.hinet.net wrote: > eryk sun at 2016/9/27 11:44:49AM wrote: > > The threads of a process do not share a single core. The OS > > schedules threads to distribute the load across all cores.... > > hmmm... your answer overthrow all my knowledge about Python threads > completely:-( I actually had ever considered using ProcessPoolExecutor > to do it. > > If the load was distributed by the OS schedules across all cores, does > it means I can't make one core solely running a piece of codes for me > and so I have no contol on its performance? Someone in the know would have to elaborate on whether python knows about, or can cooperate with the boot time parameter 'isolcpus ='. 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 jussi.piitulainen at helsinki.fi Wed Sep 28 00:16:44 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 28 Sep 2016 07:16:44 +0300 Subject: Is there a way to change the closure of a python function? References: Message-ID: Chris Angelico writes: > On Wed, Sep 28, 2016 at 7:19 AM, Terry Reedy wrote: >> The value of the cell variable is writable from within the body of the >> closure function if declared nonlocal, but not otherwise, and not from >> without. The latter may be what Peng meant by 'change' and the blogger by >> 'read-only'. >> > > Not from entirely without, but it's possible for two functions to > share a cell. I don't know the mechanics of how nonlocal assignment > works, but ultimately, it's updating the cell that both closures see, > so it's going to affect the other function too. Standard example: def make(): def inquire(): return balance def deposit(amount): nonlocal balance balance += amount def withdraw(amount): nonlocal balance balance -= amount balance = 0 return inquire, deposit, withdraw inq1, put1, get1 = make() inq2, put2, get2 = make() put1(30) ; get1(10) ; put1(40) put2(500) ; put2(500) ; put2(500) assert inq1() == 60 assert inq2() == 1500 From steve+comp.lang.python at pearwood.info Wed Sep 28 00:20:12 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 28 Sep 2016 14:20:12 +1000 Subject: Nested for loops and print statements References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> Message-ID: <57eb44fd$0$1610$c3e8da3$5496439d@news.astraweb.com> On Wednesday 28 September 2016 12:48, Larry Hudson wrote: > As they came through in the newsgroup, BOTH run correctly, because both > versions had leading spaces only. > (I did a careful copy/paste to check this.) Copying and pasting from the news client may not be sufficient to show what whitespace is actually used. For example, I use KNode, the KDE news client on Linux, and for me, KNode converts tabs to spaces. (If this is configurable, I don't know how.) BUT if I choose the following menu command: View > View Source I see the raw, unmodified message as posted by the OP, complete with tabs and spaces. > READ the error messages, they are important! Indeed. And *believe* the error messages. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From eryksun at gmail.com Wed Sep 28 01:04:33 2016 From: eryksun at gmail.com (eryk sun) Date: Wed, 28 Sep 2016 05:04:33 +0000 Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: Message-ID: On Wed, Sep 28, 2016 at 2:13 AM, wrote: > If the load was distributed by the OS schedules across all cores, > does it means I can't make one core solely running a piece of codes > for me and so I have no contol on its performance? In Unix, Python's os module may have sched_setaffinity() to set the CPU affinity for all threads in a given process. In Windows, you can use ctypes to call SetProcessAffinityMask, SetThreadAffinityMask, or SetThreadIdealProcessor (a hint for the scheduler). On a NUMA system you can call GetNumaNodeProcessorMask(Ex) to get the mask of CPUs that are on a given NUMA node. The cmd shell's "start" command supports "/numa" and "/affinity" options, which can be combined. From greg.ewing at canterbury.ac.nz Wed Sep 28 01:27:26 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 28 Sep 2016 18:27:26 +1300 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: Lawrence D?Oliveiro wrote: > On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: > >>is Python actually a "functional language"? > > Yes . No, not according to what the term "functional language" usually means. Languages described as "functional" usually incorporate all or most of the following characteristics: * No side effects (new variable bindings may be created, but existing ones cannot be changed; no mutable data structures). * Lazy evaluation by default. * Syntactic support for currying. * Syntactic support for case-analysis-style definition of functions, by matching the arguments against a series of patterns. * A standard library geared towards a programming style that makes heavy use of higher-order functions. Python has none of these features. It's possible to use a subset of Python in a functional way, but it goes against the grain, and without all the above support from the ecosystem it's clumsier than it would be in a real functional language. Some parts of Python, such as list comprehensions, have a functional flavour, but Python is predominantly an imperative language. -- Greg From greg.ewing at canterbury.ac.nz Wed Sep 28 01:33:24 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 28 Sep 2016 18:33:24 +1300 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: Peng Yu wrote: > On Tue, Sep 27, 2016 at 10:01 AM, Chris Angelico wrote: > >>"""In some languages, the variable bindings contained in a closure >>behave just like any other variables. Alas, in python they are >>read-only.""" >> >>This is not true, at least as of Python 3. > > So in Python 2, this is true? Python 2 doesn't have "nonlocal", so a nested function can't rebind variables in an intermediate scope (between local and module-level). Of course, anything is changeable if you resort to sufficient amounts of hackery. In this case I believe the hacking level required involves ctypes. -- Greg From nomail at com.invalid Wed Sep 28 01:51:01 2016 From: nomail at com.invalid (ast) Date: Wed, 28 Sep 2016 07:51:01 +0200 Subject: Why searching in a set is much faster than in a list ? Message-ID: <57eb5a4a$0$3305$426a74cc@news.free.fr> Hello I noticed that searching in a set is faster than searching in a list. from timeit import Timer from random import randint l = [i for i in range(100)] s = set(l) t1 = Timer("randint(0, 200) in l", "from __main__ import l, randint") t2 = Timer("randint(0, 200) in s", "from __main__ import s, randint") t1.repeat(3, 100000) [1.459111982109448, 1.4568229341997494, 1.4329947660946232] t2.repeat(3, 100000) [0.8499233841172327, 0.854728743457656, 0.8618653348400471] I tried a search in a tuple, it's not different that in a list. Any comments ? From nomail at com.invalid Wed Sep 28 01:57:41 2016 From: nomail at com.invalid (ast) Date: Wed, 28 Sep 2016 07:57:41 +0200 Subject: Why searching in a set is much faster than in a list ? In-Reply-To: <57eb5a4a$0$3305$426a74cc@news.free.fr> References: <57eb5a4a$0$3305$426a74cc@news.free.fr> Message-ID: <57eb5bda$0$3362$426a74cc@news.free.fr> "ast" a ?crit dans le message de news:57eb5a4a$0$3305$426a74cc at news.free.fr... > Hello > > I noticed that searching in a set is faster than searching in a list. > > from timeit import Timer > from random import randint > > l = [i for i in range(100)] > s = set(l) > > t1 = Timer("randint(0, 200) in l", "from __main__ import l, randint") > t2 = Timer("randint(0, 200) in s", "from __main__ import s, randint") > > t1.repeat(3, 100000) > [1.459111982109448, 1.4568229341997494, 1.4329947660946232] > > t2.repeat(3, 100000) > [0.8499233841172327, 0.854728743457656, 0.8618653348400471] > > I tried a search in a tuple, it's not different that in a list. > Any comments ? I tried in an array which is supposed to be an optimised list, but it is slightly slower from array import array a = array('H', [i for i in range(100)]) t3 = Timer("randint(0, 200) in a", "from __main__ import a, randint") t3.repeat(3, 100000) [1.6311116356968114, 1.638082912772461, 1.6018925589704622] From rosuav at gmail.com Wed Sep 28 01:59:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 15:59:42 +1000 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Wed, Sep 28, 2016 at 3:27 PM, Gregory Ewing wrote: > Lawrence D?Oliveiro wrote: >> >> On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: >> >>> is Python actually a "functional language"? >> >> >> Yes >> . > > > No, not according to what the term "functional language" > usually means. > > Languages described as "functional" usually incorporate > all or most of the following characteristics: > > * No side effects (new variable bindings may be created, but > existing ones cannot be changed; no mutable data structures). If that's adhered to 100%, the language is useless for any operation that cannot be handled as a "result at end of calculation" function. You can't produce intermediate output. You can't even produce debugging output (at least, not from within the program - you'd need an external debugger). You certainly can't have a long-running program that handles multiple requests (eg a web server). That kind of rule is fine for mathematical systems, and it's fine for certain specific sub-parts of larger programs, but IMO it's utterly impractical for an entire programming language. > * Lazy evaluation by default. Given that you said "usually means", sure, but only because most functional programming is abysmal (or impossible - calculating the squares of all positive integers, then subscripting it) unless optimized like that. > * Syntactic support for currying. Is that really such a big deal? What's the true difference between syntactic support and stdlib support? > * Syntactic support for case-analysis-style definition of > functions, by matching the arguments against a series of > patterns. Again, why such a big deal? Unless you're deliberately defining "functional language" as "clone of Haskell" or something, there's no particular reason for this to be a requirement. > * A standard library geared towards a programming style > that makes heavy use of higher-order functions. This I would agree with. > Python has none of these features. It's possible to use a > subset of Python in a functional way, but it goes against the > grain, and without all the above support from the ecosystem > it's clumsier than it would be in a real functional language. > > Some parts of Python, such as list comprehensions, have a > functional flavour, but Python is predominantly an imperative > language. Python is predominantly a *practical* language. Since purely functional programming is fundamentally impractical, Python doesn't force us into it. You want to work functionally? No problem. Pretend that "def" is a declaration, make all your functions pure, and either finish with a single "print(main())" or do your actual work at the REPL. No problem. Want to make event-driven code? Hide an event loop (maybe a GUI one, maybe asyncio, whatever) in your main routine, and do everything through that. Want to use Smalltalk-style "message passing"? Fits nicely into classes and methods. Want a simple batch scripting style? Ignore functions and classes, and write your code flush left. Python doesn't force you into any of these models, ergo Python isn't a functional language, nor an event-driven language, etc, etc. It's a general-purpose language. ChrisA From prasanthktgr at gmail.com Wed Sep 28 02:44:11 2016 From: prasanthktgr at gmail.com (prasanthktgr at gmail.com) Date: Tue, 27 Sep 2016 23:44:11 -0700 (PDT) Subject: How to call this method from main method Message-ID: <2c35b9c7-79d3-405f-b1fa-fb237b27d313@googlegroups.com> #!/sur/bin/env python import sys import jwt import argparse from calendar import timegm from datetime import datetime import uuid class TokenGenerator: def __init__(self, args): self.macKey = args.authzSystemMacKey self.authzSystemId = args.authzSystemId self.permissions = args.permissions self.configurationId = args.configurationId self.tokenExpiry = args.tokenExpiryInSeconds def generate(self): payload = { 'iss': self.authzSystemId, 'aud': 'qed:' + self.configurationId, 'sub': 'admin:tokengen.py', 'qedp': self.permissions, 'exp': timegm(datetime.utcnow().utctimetuple()) + self.tokenExpiry } if self.tokenExpiry <= 300: # less than 5minutes payload['jti'] = str(uuid.uuid1()) return jwt.encode(payload, self.macKey, algorithm='HS256') class JWTParms: pass def GenAccessToken(mackey,authid,configid,tokenexp,*perm): args=JWTParms() args.configurationId=configid args.authzSystemMacKey=mackey args.authzSystemId=authid args.tokenExpiryInSeconds=tokenexp args.permissions=perm tokenGen=TokenGenerator(args) tok=tokenGen.generate() return tok if __name__ == '__main__': GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000, "g,m,a,s,c,p,d") When i am calling the above method from main method it is not returning the value but when i use print it is showing the value. Is there any wrong in returning the value from a method. Please help me ASAP From prasanthktgr at gmail.com Wed Sep 28 02:47:25 2016 From: prasanthktgr at gmail.com (prasanth kotagiri) Date: Tue, 27 Sep 2016 23:47:25 -0700 (PDT) Subject: How to call a method returning a value from a main function Message-ID: <876028d2-2255-467a-a7e8-051395ef2c42@googlegroups.com> #!/sur/bin/env python import sys import jwt import argparse from calendar import timegm from datetime import datetime import uuid class TokenGenerator: def __init__(self, args): self.macKey = args.authzSystemMacKey self.authzSystemId = args.authzSystemId self.permissions = args.permissions self.configurationId = args.configurationId self.tokenExpiry = args.tokenExpiryInSeconds def generate(self): payload = { 'iss': self.authzSystemId, 'aud': 'qed:' + self.configurationId, 'sub': 'admin:tokengen.py', 'qedp': self.permissions, 'exp': timegm(datetime.utcnow().utctimetuple()) + self.tokenExpiry } if self.tokenExpiry <= 300: # less than 5minutes payload['jti'] = str(uuid.uuid1()) return jwt.encode(payload, self.macKey, algorithm='HS256') class JWTParms: pass def GenAccessToken(mackey,authid,configid,tokenexp,*perm): args=JWTParms() args.configurationId=configid args.authzSystemMacKey=mackey args.authzSystemId=authid args.tokenExpiryInSeconds=tokenexp args.permissions=perm tokenGen=TokenGenerator(args) tok=tokenGen.generate() return tok if __name__ == '__main__': GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000, "g,m,a,s,c,p,d") when i am calling the above method it is not returning any value but when i use print it is printing the value. Is there any wrong in returning the value from above method. Please help me ASAP From cpxuvs at gmail.com Wed Sep 28 02:47:34 2016 From: cpxuvs at gmail.com (Cpcp Cp) Date: Tue, 27 Sep 2016 23:47:34 -0700 (PDT) Subject: what's the difference of Template.append(...) and Template.prepend(...) in pipes module Message-ID: Template.append(cmd, kind) and Template.prepend(cmd, kind) Append a new action at the end.The cmd variable must be a valid bourne shell command. The kind variable consists of two letters. My os is windows 7.But this module is used for POSIX. So,I don't know the doucement said what's difference of 'Append a new action at the end/beginning'. My English is poor:-),I hope I express clearly what I mean. From cpxuvs at gmail.com Wed Sep 28 02:50:02 2016 From: cpxuvs at gmail.com (Cpcp Cp) Date: Tue, 27 Sep 2016 23:50:02 -0700 (PDT) Subject: what's the difference of Template.append(...) and Template.prepend(...) in pipes module In-Reply-To: References: Message-ID: <1d244f64-90d6-4324-90e4-5dba20d1a7f1@googlegroups.com> Please give me a simple example.Thanks! From dieter at handshake.de Wed Sep 28 03:02:07 2016 From: dieter at handshake.de (dieter) Date: Wed, 28 Sep 2016 09:02:07 +0200 Subject: Python C API: How to debug reference leak? References: <87wphxddwc.fsf@handshake.de> Message-ID: <871t0433tc.fsf@handshake.de> dl l writes: > Thanks for reply. Is there any function in C to get the reference objects > of a object? I want to debug where are referencing the object. Depending on your understanding of "reference objects", this would be "gc.get_referents" or "gc.get_referrers". Of course, those are not "C" functions but Python functions in the module "gc". However, (with some effort) you can use them in "C" as well. Most types (at least the standard container types) will have "gc" support functions which allow to determine the "referents" of a corresponding object. Note: those "gc" functions are implemented in "C". But, almost surely, they are declared "static", i.e. not globally exposed (in order not to pollute the global symbol namespace). When I want to use Python functions in C, I write a bit of "Cython" source and use "Cython" to compile it into "C". Then, I copy and paste this "C" code into my own "C" application to have the functions available there. Important note for debugging: (Almost) all Python functions expect that they are called only when the active thread holds the GIL ("Global Interpreter Lock"). Calling Python functions during debugging may violate this restriction and this can lead to abnormal behaviour. In single thread applications, the real danger is likely not too large. In multi thread applications, I have already seen "SIGSEGV"s caused by this. From dieter at handshake.de Wed Sep 28 03:05:54 2016 From: dieter at handshake.de (dieter) Date: Wed, 28 Sep 2016 09:05:54 +0200 Subject: Python C API: How to debug reference leak? References: <87wphxddwc.fsf@handshake.de> Message-ID: <87wphw1p2l.fsf@handshake.de> dl l writes: > When I debug in C++, I see the reference count of a PyObject is 1. I don't > know where is referencing this object. How can I find out where is > referencing this object? Likely, it is the reference, you are holding: typically, whenever you can access a Python object, this object has at least reference count 1 (because it must lie on at least one access path -- the one used by you). From nomail at com.invalid Wed Sep 28 03:08:41 2016 From: nomail at com.invalid (ast) Date: Wed, 28 Sep 2016 09:08:41 +0200 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: <57eb6c7e$0$3305$426a74cc@news.free.fr> "jmp" a ?crit dans le message de news:mailman.31.1474987306.2302.python-list at python.org... > On 09/27/2016 04:01 PM, Peng Yu wrote: > > Note: function are objects, and can have attributes, however I rarely see usage of these, there > could be good reasons for that. > It could be use to implement a cache for example. def fact1(n): if not hasattr(fact1, '_cache'): fact1._cache = {0:1} if n not in fact1._cache: fact1._cache[n] = n * fact1(n-1) return fact1._cache[n] From ben+python at benfinney.id.au Wed Sep 28 03:19:38 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 28 Sep 2016 17:19:38 +1000 Subject: How to call this method from main method References: <2c35b9c7-79d3-405f-b1fa-fb237b27d313@googlegroups.com> Message-ID: <8560pglcdx.fsf@benfinney.id.au> prasanthktgr at gmail.com writes: > When i am calling the above method from main method You don't have a main method, and you don't specify what ?the above method? is. I assume you mean ?? calling the ?GenAccessToken? function? (which is not a method of anything, in the code you showed). But maybe you mean something different? > it is not returning the value but when i use print it is showing the > value. Can you show an example Python interactive session which: * Imports your module. * Calls the function. * Demonstrates the behaviour that is confusing you. > Please help me ASAP You may not realise (I assume you are not a native English speaker), that is *very* demanding and rude. We are a community of volunteers here, asking for a response ?ASAP? is making demands you are not in a position to make. -- \ ?Don't fight forces, use them.? ?Richard Buckminster Fuller, | `\ _Shelter_, 1932 | _o__) | Ben Finney From dieter at handshake.de Wed Sep 28 03:19:51 2016 From: dieter at handshake.de (dieter) Date: Wed, 28 Sep 2016 09:19:51 +0200 Subject: Is there a way to change the closure of a python function? References: Message-ID: <87shsk1ofc.fsf@handshake.de> Peng Yu writes: > Hi, In many other functional language, one can change the closure of a > function. Is it possible in python? I do not think so: the corresponding attributes/types ("__closure__", "cell") are explicitely designed to be read only. However, I never missed closure changebility. Should I really need it (in an extreme rare case), I would bind the corresponding variable to an object which could be modified at will. From dieter at handshake.de Wed Sep 28 03:26:37 2016 From: dieter at handshake.de (dieter) Date: Wed, 28 Sep 2016 09:26:37 +0200 Subject: Why searching in a set is much faster than in a list ? References: <57eb5a4a$0$3305$426a74cc@news.free.fr> Message-ID: <87oa381o42.fsf@handshake.de> "ast" writes: > ... > I noticed that searching in a set is faster than searching in a list. A "set" is actually similar to a degenerated "dict". It is using hashing to quickly access its content which could give you (amortized asymptotically) contant runtime. With a list, you iterate over its elements and compare along the line - which gives (...) linear runtime. From auriocus at gmx.de Wed Sep 28 03:30:43 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 28 Sep 2016 09:30:43 +0200 Subject: Why searching in a set is much faster than in a list ? In-Reply-To: <57eb5a4a$0$3305$426a74cc@news.free.fr> References: <57eb5a4a$0$3305$426a74cc@news.free.fr> Message-ID: Am 28.09.16 um 07:51 schrieb ast: > Hello > > I noticed that searching in a set is faster than searching in a list. Because a set is a hashtable, which has constant-time lookup, whereas in a list it needs to compare with every element. > from timeit import Timer > from random import randint > > l = [i for i in range(100)] > s = set(l) Try longer lists/sets and the difference should increase. Christian > t1 = Timer("randint(0, 200) in l", "from __main__ import l, randint") > t2 = Timer("randint(0, 200) in s", "from __main__ import s, randint") > > t1.repeat(3, 100000) > [1.459111982109448, 1.4568229341997494, 1.4329947660946232] > > t2.repeat(3, 100000) > [0.8499233841172327, 0.854728743457656, 0.8618653348400471] > > I tried a search in a tuple, it's not different that in a list. > Any comments ? From __peter__ at web.de Wed Sep 28 04:06:57 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Sep 2016 10:06:57 +0200 Subject: Is there a way to change the closure of a python function? References: Message-ID: Lawrence D?Oliveiro wrote: > On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: >> is Python actually a "functional language"? > > Yes [snip] No. To replace the mostly irrelevant link with something addressing my question: From lawrencedo99 at gmail.com Wed Sep 28 04:17:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 28 Sep 2016 01:17:10 -0700 (PDT) Subject: what's the difference of Template.append(...) and Template.prepend(...) in pipes module In-Reply-To: References: Message-ID: <32c41eb5-196a-46c7-a79c-99f8898301ff@googlegroups.com> On Wednesday, September 28, 2016 at 7:47:46 PM UTC+13, Cpcp Cp wrote: > My os is windows 7.But this module is used for POSIX. Windows 10 has a Linux layer, I believe. Why not try that? From lawrencedo99 at gmail.com Wed Sep 28 04:19:12 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 28 Sep 2016 01:19:12 -0700 (PDT) Subject: Why searching in a set is much faster than in a list ? In-Reply-To: <57eb5a4a$0$3305$426a74cc@news.free.fr> References: <57eb5a4a$0$3305$426a74cc@news.free.fr> Message-ID: On Wednesday, September 28, 2016 at 6:51:17 PM UTC+13, ast wrote: > I noticed that searching in a set is faster than searching in a list. That?s why we have sets. From steve+comp.lang.python at pearwood.info Wed Sep 28 04:23:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 28 Sep 2016 18:23:23 +1000 Subject: Why searching in a set is much faster than in a list ? References: <57eb5a4a$0$3305$426a74cc@news.free.fr> Message-ID: <57eb7dff$0$1598$c3e8da3$5496439d@news.astraweb.com> On Wednesday 28 September 2016 15:51, ast wrote: > Hello > > I noticed that searching in a set is faster than searching in a list. [...] > I tried a search in a tuple, it's not different that in a list. > Any comments ? A list, array or tuple is basically a linear array that needs to be searched one item at a time: [ a | b | c | d | ... | x | y | z ] To find x, Python has to start at the beginning and look at every item in turn, until it finds x. But a set is basically a hash table. It is an array, but laid out differently, with blank cells: [ # | # | h | p | a | # | m | y | b | # | # | f | x | ... | # ] Notice that the items are jumbled up in arbitrary order. So how does Python find them? Python calls hash() on the value, which returns a number, and that points directly to the cell which would contain the value if it were there. So if you search for x, Python calls hash(x) which will return (say) 12. Python then looks in cell 12, and if x is there, it returns True, and if it's not, it returns False. So instead of looking at 24 cells in the array to find x, it calculates a hash (which is usually fast), then looks at 1 cell. (This is a little bit of a simplification -- the reality is a bit more complicated, but you can look up "hash tables" on the web or in computer science books. They are a standard data structure, so there is plenty of information available.) On average, if you have a list with 1000 items, you need to look at 500 items before finding the one you are looking for. With a set or dict with 1000 items, on average you need to look at 1 item before finding the one you are looking for. And that is why sets and dicts are usually faster than lists. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From steve+comp.lang.python at pearwood.info Wed Sep 28 04:29:13 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 28 Sep 2016 18:29:13 +1000 Subject: what's the difference of Template.append(...) and Template.prepend(...) in pipes module References: Message-ID: <57eb7f5a$0$1598$c3e8da3$5496439d@news.astraweb.com> On Wednesday 28 September 2016 16:47, Cpcp Cp wrote: > Template.append(cmd, kind) and Template.prepend(cmd, kind) > Append a new action at the end.The cmd variable must be a valid bourne shell > command. The kind variable consists of two letters. "Append" means to put at the end. "Prepend" means to put at the beginning. Here is a list: [1, 2, 3, 4] If we APPEND "foo", we get: [1, 2, 3, 4, foo] If we PREPEND "foo", we get: [foo, 1, 2, 3, 4] Does that help? > My os is windows 7.But this module is used for POSIX. Which module? We don't know which module you are talking about, which makes it hard to give you a specific answer. -- Steven From p.f.moore at gmail.com Wed Sep 28 04:42:15 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 28 Sep 2016 01:42:15 -0700 (PDT) Subject: How to call a method returning a value from a main function In-Reply-To: <876028d2-2255-467a-a7e8-051395ef2c42@googlegroups.com> References: <876028d2-2255-467a-a7e8-051395ef2c42@googlegroups.com> Message-ID: <08f3d2e8-5629-4810-99be-7aa55ab5b4d0@googlegroups.com> On Wednesday, 28 September 2016 07:47:38 UTC+1, prasanth kotagiri wrote: > def GenAccessToken(mackey,authid,configid,tokenexp,*perm): > args=JWTParms() > args.configurationId=configid > args.authzSystemMacKey=mackey > args.authzSystemId=authid > args.tokenExpiryInSeconds=tokenexp > args.permissions=perm > tokenGen=TokenGenerator(args) > tok=tokenGen.generate() > return tok > > if __name__ == '__main__': > GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000, > "g,m,a,s,c,p,d") > > when i am calling the above method it is not returning any value but when i use print it is printing the value. Is there any wrong in returning the value from above method. Please help me ASAP GenAccessToken is returning a value (from "return tok") but you're not doing anything with that value in your "if name == '__main__'" section. You need to assign the return value to a variable, or print it, or whatever you want to do with it. Otherwise Python will assume you weren't interested in the return value and simply throw it away. Try something like tok = GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000, "g,m,a,s,c,p,d") print(tok) Paul From marko at pacujo.net Wed Sep 28 04:46:56 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 28 Sep 2016 11:46:56 +0300 Subject: Why searching in a set is much faster than in a list ? References: <57eb5a4a$0$3305$426a74cc@news.free.fr> Message-ID: <87ponoqum7.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Wednesday, September 28, 2016 at 6:51:17 PM UTC+13, ast wrote: >> I noticed that searching in a set is faster than searching in a list. > > That?s why we have sets. I would have thought the point of sets is to have set semantics, just like the point of lists is to have list semantics. Marko From greg.ewing at canterbury.ac.nz Wed Sep 28 04:52:52 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 28 Sep 2016 21:52:52 +1300 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: Chris Angelico wrote: > > wrote: > >>* No side effects (new variable bindings may be created, but >> existing ones cannot be changed; no mutable data structures). > > If that's adhered to 100%, the language is useless for any operation > that cannot be handled as a "result at end of calculation" function. Surprisingly, that turns out not to be true. Modern functional programming has developed some very elegant techniques for expressing state-changing operations in a functional way, using things they call monads. Essentially you write the whole program in continuation- passing style, with a state object being passed down an infinite chain of function calls. None of the functions ever return, so there's no danger of an "old" state being seen again after the state has changed. This allows in-place mutations to be performed as optimisations; it also allows I/O to be handled in a functional way. > You can't produce intermediate output. You can't even produce > debugging output (at least, not from within the program - you'd need > an external debugger). You certainly can't have a long-running program > that handles multiple requests (eg a web server). Well, people seem to be writing web servers in functional languages anyway, judging by the results of googling for "haskell web server". :-) >>* Syntactic support for currying. > > Is that really such a big deal? It is when higher-order functions are such a fundamental part of the ecosystem that you can hardly take a breath without needing to curry something. > Unless you're deliberately defining > "functional language" as "clone of Haskell" or something, there's no > particular reason for this to be a requirement. It's not *my* definition, I'm just pointing out what the term "functional language" means to the people who design and use such languages. It means a lot more than just "a language that has functions". If that's your definition, then almost any language designed in the last few decades is a functional language, and the term is next to meaningless. > Python is predominantly a *practical* language. Since purely > functional programming is fundamentally impractical, Python doesn't > force us into it. The point is that a true functional language (as opposed to just "a language that has functions") *does* force you into it. Lack of side effects is considered an important part of that paradigm, because it allows programs to be reasoned about in a mathematical way. If that's not enforced, the point of the whole thing is lost. The fact that Python *doesn't* force you into it means that Python is not a functional language in that sense. -- Greg From greg.ewing at canterbury.ac.nz Wed Sep 28 04:56:37 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 28 Sep 2016 21:56:37 +1300 Subject: Python C API: How to debug reference leak? In-Reply-To: References: <87wphxddwc.fsf@handshake.de> <87wphw1p2l.fsf@handshake.de> Message-ID: dieter wrote: > dl l writes: > >>When I debug in C++, I see the reference count of a PyObject is 1. >> How can I find out where is referencing this object? > > Likely, it is the reference, you are holding: Unless you've just Py_DECREFed it, expecting it to go away, and the recfcount is still 1, in which case there's still another reference somewhere else. -- Greg From rosuav at gmail.com Wed Sep 28 05:07:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 19:07:35 +1000 Subject: Why searching in a set is much faster than in a list ? In-Reply-To: <87ponoqum7.fsf@elektro.pacujo.net> References: <57eb5a4a$0$3305$426a74cc@news.free.fr> <87ponoqum7.fsf@elektro.pacujo.net> Message-ID: On Wed, Sep 28, 2016 at 6:46 PM, Marko Rauhamaa wrote: > Lawrence D?Oliveiro : > >> On Wednesday, September 28, 2016 at 6:51:17 PM UTC+13, ast wrote: >>> I noticed that searching in a set is faster than searching in a list. >> >> That?s why we have sets. > > I would have thought the point of sets is to have set semantics, just > like the point of lists is to have list semantics. And set semantics are what, exactly? Membership is a primary one. "Searching in a set" in the OP's language is a demonstration of the 'in' operator, a membership/containment check. (Other equally important set semantics include intersection and union, but membership inclusion checks are definitely up there among primary purposes of sets.) ChrisA From alister.ware at ntlworld.com Wed Sep 28 05:18:28 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 28 Sep 2016 09:18:28 GMT Subject: How to reduce the DRY violation in this code References: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 28 Sep 2016 01:49:56 +1000, Steve D'Aprano wrote: > I have a class that takes a bunch of optional arguments. They're all > optional, with default values of various types. For simplicity, let's > say some are ints and some are floats: > > > class Spam: > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > # the usual assign arguments to attributes dance... self.bashful > = bashful self.doc = doc # etc. > > > I also have an alternative constructor that will be called with string > arguments. It converts the strings to the appropriate type, then calls > the real constructor, which calls __init__. Again, I want the arguments > to be optional, which means providing default values: > > > @classmethod def from_strings(cls, bashful='10.0', doc='20.0', > dopey='30.0', > grumpy='40', happy='50', sleepy='60', sneezy='70'): > bashful = float(bashful) > doc = float(doc) > dopey = float(dopey) > grumpy = int(grumpy) > happy = int(happy) > sleepy = int(sleepy) > sneezy = int(sneezy) > return cls(bashful, doc, dopey, grumpy, happy, sleepy, sneezy) > > > That's a pretty ugly DRY violation. Imagine that I change the default > value for bashful from 10.0 to (let's say) 99. I have to touch the code > in three places (to say nothing of unit tests): > This is often refered to as using "Magic Numbers" and can be avoided by using constants HAPPY='50' SNEEZY='70' def spam: def __init__(self,happy=HAPPY,sneezy=SNEEZY,...) of course Python does not have true constants (hence following the PEP 8 recommendation of making them all caps) so you have to behave yourself regarding their usage. at least now they only need to be changed in 1 location. that said when I find i have situations like this it is often a good idea to re-investigate my approach to the overall problem to see if there is another way to implement it. -- "Humor is a drug which it's the fashion to abuse." -- William Gilbert From rosuav at gmail.com Wed Sep 28 05:18:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 19:18:46 +1000 Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: On Wed, Sep 28, 2016 at 6:52 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> >> wrote: >> >>> * No side effects (new variable bindings may be created, but >>> existing ones cannot be changed; no mutable data structures). >> >> >> If that's adhered to 100%, the language is useless for any operation >> that cannot be handled as a "result at end of calculation" function. > > > Surprisingly, that turns out not to be true. Modern > functional programming has developed some very elegant > techniques for expressing state-changing operations in > a functional way, using things they call monads. > > Essentially you write the whole program in continuation- > passing style, with a state object being passed down an > infinite chain of function calls. > > None of the functions ever return, so there's no > danger of an "old" state being seen again after the state > has changed. This allows in-place mutations to be > performed as optimisations; it also allows I/O to be > handled in a functional way. If monads allow mutations or side effects, they are by definition not pure functions, and violate your bullet point. Languages like Haskell have them not because they are an intrinsic part of functional programming languages, but because they are an intrinsic part of practical/useful programming languages. >> You can't produce intermediate output. You can't even produce >> debugging output (at least, not from within the program - you'd need >> an external debugger). You certainly can't have a long-running program >> that handles multiple requests (eg a web server). > > > Well, people seem to be writing web servers in functional > languages anyway, judging by the results of googling for > "haskell web server". :-) Again, Haskell has such features in order to make it useful, not because they're part of the definition of "functional programming". >> Unless you're deliberately defining >> "functional language" as "clone of Haskell" or something, there's no >> particular reason for this to be a requirement. > > > It's not *my* definition, I'm just pointing out what > the term "functional language" means to the people > who design and use such languages. It means a lot more > than just "a language that has functions". If that's > your definition, then almost any language designed > in the last few decades is a functional language, and > the term is next to meaningless. Of course it's more than "a language that has functions"; but I'd say that a more useful comparison would be "languages that require functional idioms exclusively" vs "languages that support functional idioms" vs "languages with no functional programming support". Python is squarely in the second camp, with features like list comprehensions, map/reduce, etc, but never forcing you to use them. (C would be one I'd put into the third camp - I don't think it'd be at all practical to try to use any sort of functional programming idiom in C. But I might be wrong.) >> Python is predominantly a *practical* language. Since purely >> functional programming is fundamentally impractical, Python doesn't >> force us into it. > > > The point is that a true functional language (as > opposed to just "a language that has functions") *does* > force you into it. Lack of side effects is considered > an important part of that paradigm, because it allows > programs to be reasoned about in a mathematical way. > If that's not enforced, the point of the whole thing > is lost. > > The fact that Python *doesn't* force you into it means > that Python is not a functional language in that sense. Right. But my point is that *no* truly useful general-purpose language actually enforces all of this. A language with absolutely no side effects etc is a great way to represent algebra (algebra is all about a search for truth that existed from the beginning - if you discover half way through that x is 7, then x must have actually been 7 when the program started, only you didn't know it yet), but it's a terrible way to do any sort of I/O, and it's rather impractical for really long-running calculations, being that much harder to debug. The languages most commonly referred to as "functional languages" are merely *closer to* a pure no-side-effect language - they encourage functional styles more strongly than Python does. I strongly support the use of pure functions in places where that makes sense. They're much easier to reason about, write unit tests for, etc, etc, than are functions with side effects. But most practical programming work is made easier, not harder, by permitting side effects. ChrisA From rosuav at gmail.com Wed Sep 28 05:22:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 19:22:23 +1000 Subject: Python C API: How to debug reference leak? In-Reply-To: References: <87wphxddwc.fsf@handshake.de> <87wphw1p2l.fsf@handshake.de> Message-ID: On Wed, Sep 28, 2016 at 6:56 PM, Gregory Ewing wrote: > dieter wrote: >> >> dl l writes: >> >>> When I debug in C++, I see the reference count of a PyObject is 1. > >>> How can I find out where is referencing this object? >> >> >> Likely, it is the reference, you are holding: > > > Unless you've just Py_DECREFed it, expecting it to go > away, and the recfcount is still 1, in which case there's > still another reference somewhere else. If you've Py_DECREFed it and then peek into its internals, you're aiming a gun at your foot. In theory, the decref could have been followed by some other operation (or a context switch) that allocated another object and happened to use the same address (not as unlikely as you might think, given that some object types use free lists). Always have a reference to something before you mess with it. ChrisA From steve+comp.lang.python at pearwood.info Wed Sep 28 05:22:39 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 28 Sep 2016 19:22:39 +1000 Subject: Is there a way to change the closure of a python function? References: Message-ID: <57eb8be1$0$2861$c3e8da3$76491128@news.astraweb.com> On Wednesday 28 September 2016 15:27, Gregory Ewing wrote: > * No side effects (new variable bindings may be created, but > existing ones cannot be changed; no mutable data structures). As I understand it, for some advanced functional languages like Haskell, that is only true as far as the interface of the language (the API) is concerned. Implementation-wise, the language may in fact use a mutable data structure, provided it is provable that only one piece of code is accessing it at the relevant times. The analogy with Python is the string concatenation optimization. Officially, writing: a + b + c + d + e in Python has to create and destory the temporary, intermediate strings: (a+b) (a+b+c) (a+b+c+d) before the final concatenation is performed. But, provided there is only one reference to the initial string a, and if certain other conditions related to memory management also hold, then this can be optimized as an in-place concatenation without having to create new strings, even though strings are actually considered immutable and growing them in place is forbidden. My understanding is that smart functional languages like Haskell do that sort of thing a lot, which avoids them being painfully slow. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From kaiser.yann at gmail.com Wed Sep 28 05:28:44 2016 From: kaiser.yann at gmail.com (Yann Kaiser) Date: Wed, 28 Sep 2016 09:28:44 +0000 Subject: How to reduce the DRY violation in this code In-Reply-To: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: You could use `attrs` for this along with the convert option, if you're open to receiving mixed arguments: >>> @attr.s ... class C(object): ... x = attr.ib(convert=int) >>> o = C("1") >>> o.x 1 https://attrs.readthedocs.io/en/stable/examples.html#conversion On Tue, Sep 27, 2016, 16:51 Steve D'Aprano wrote: > I have a class that takes a bunch of optional arguments. They're all > optional, with default values of various types. For simplicity, let's say > some are ints and some are floats: > > > class Spam: > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > # the usual assign arguments to attributes dance... > self.bashful = bashful > self.doc = doc > # etc. > > > I also have an alternative constructor that will be called with string > arguments. It converts the strings to the appropriate type, then calls the > real constructor, which calls __init__. Again, I want the arguments to be > optional, which means providing default values: > > > @classmethod > def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0', > grumpy='40', happy='50', sleepy='60', sneezy='70'): > bashful = float(bashful) > doc = float(doc) > dopey = float(dopey) > grumpy = int(grumpy) > happy = int(happy) > sleepy = int(sleepy) > sneezy = int(sneezy) > return cls(bashful, doc, dopey, grumpy, happy, sleepy, sneezy) > > > That's a pretty ugly DRY violation. Imagine that I change the default value > for bashful from 10.0 to (let's say) 99. I have to touch the code in three > places (to say nothing of unit tests): > > - modify the default value in __init__ > - modify the stringified default value in from_strings > - change the conversion function from float to int in from_strings > > > Not to mention that each parameter is named seven times. > > > How can I improve this code to reduce the number of times I have to repeat > myself? > > > > > > -- > 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 > -- Yann Kaiser kaiser.yann at gmail.com yann.kaiser at efrei.net +33 6 51 64 01 89 https://github.com/epsy From cpxuvs at gmail.com Wed Sep 28 05:34:25 2016 From: cpxuvs at gmail.com (Cpcp Cp) Date: Wed, 28 Sep 2016 02:34:25 -0700 (PDT) Subject: what's the difference of Template.append(...) and Template.prepend(...) in pipes module In-Reply-To: References: Message-ID: <547080fd-3dc1-4109-9a84-972448cb69c3@googlegroups.com> https://docs.python.org/2/library/pipes.html From alister.ware at ntlworld.com Wed Sep 28 05:43:00 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 28 Sep 2016 09:43:00 GMT Subject: How to make a foreign function run as fast as possible in Windows? References: Message-ID: On Tue, 27 Sep 2016 19:13:51 -0700, jfong wrote: > eryk sun at 2016/9/27 11:44:49AM wrote: >> The threads of a process do not share a single core. The OS schedules >> threads to distribute the load across all cores.... > > hmmm... your answer overthrow all my knowledge about Python threads > completely:-( I actually had ever considered using ProcessPoolExecutor > to do it. > > If the load was distributed by the OS schedules across all cores, does > it means I can't make one core solely running a piece of codes for me > and so I have no contol on its performance? this would be implementation specific, not part of the language pacification. -- Ryan's Law: Make three correct guesses consecutively and you will establish yourself as an expert. From lawrencedo99 at gmail.com Wed Sep 28 06:03:31 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 28 Sep 2016 03:03:31 -0700 (PDT) Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: <89b566a5-54d0-440f-9105-8eec9233dcf9@googlegroups.com> On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing wrote: > Essentially you write the whole program in continuation- > passing style, with a state object being passed down an > infinite chain of function calls. Procedural programming under another name... From lorenzofsutton at gmail.com Wed Sep 28 06:11:45 2016 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Wed, 28 Sep 2016 12:11:45 +0200 Subject: How to reduce the DRY violation in this code In-Reply-To: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <57ea9526$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9fd03964-5a4a-3a52-26b3-efcbbb8d96f2@gmail.com> On 27/09/2016 17:49, Steve D'Aprano wrote: > I have a class that takes a bunch of optional arguments. They're all > optional, with default values of various types. For simplicity, let's say > some are ints and some are floats: > > > class Spam: > def __init__(self, bashful=10.0, doc=20.0, dopey=30.0, > grumpy=40, happy=50, sleepy=60, sneezy=70): > # the usual assign arguments to attributes dance... > self.bashful = bashful > self.doc = doc > # etc. > > > I also have an alternative constructor that will be called with string > arguments. May I ask: do you really need to add this method? Can't you ensure that the data passed during initialisation is already of the right type (i.e. can you convert to float/ints externally)? If now why? Lorenzo. It converts the strings to the appropriate type, then calls the > real constructor, which calls __init__. Again, I want the arguments to be > optional, which means providing default values: > > > @classmethod > def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0', > grumpy='40', happy='50', sleepy='60', sneezy='70'): > bashful = float(bashful) > doc = float(doc) > dopey = float(dopey) > grumpy = int(grumpy) > happy = int(happy) > sleepy = int(sleepy) > sneezy = int(sneezy) > return cls(bashful, doc, dopey, grumpy, happy, sleepy, sneezy) > > > That's a pretty ugly DRY violation. Imagine that I change the default value > for bashful from 10.0 to (let's say) 99. I have to touch the code in three > places (to say nothing of unit tests): > > - modify the default value in __init__ > - modify the stringified default value in from_strings > - change the conversion function from float to int in from_strings > > > Not to mention that each parameter is named seven times. > > > How can I improve this code to reduce the number of times I have to repeat > myself? > > > > > From marko at pacujo.net Wed Sep 28 06:34:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 28 Sep 2016 13:34:09 +0300 Subject: Why searching in a set is much faster than in a list ? References: <57eb5a4a$0$3305$426a74cc@news.free.fr> <87ponoqum7.fsf@elektro.pacujo.net> Message-ID: <87k2dwqpni.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Sep 28, 2016 at 6:46 PM, Marko Rauhamaa wrote: >> I would have thought the point of sets is to have set semantics, just >> like the point of lists is to have list semantics. > > And set semantics are what, exactly? Membership is a primary one. With sets, you can only check for membership. Lists are mappings that map indices to objects. > "Searching in a set" in the OP's language is a demonstration of the > 'in' operator, a membership/containment check. > > (Other equally important set semantics include intersection and union, > but membership inclusion checks are definitely up there among primary > purposes of sets.) Yes. However, membership is a feature of lists as well. Marko From python.list at tim.thechases.com Wed Sep 28 06:46:11 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Sep 2016 05:46:11 -0500 Subject: Case insensitive replacement? In-Reply-To: <019a8e22-055c-5068-b304-fd118ba73e56@mrabarnett.plus.com> References: <20160927115638.2054f939@bigbox.christie.dr> <019a8e22-055c-5068-b304-fd118ba73e56@mrabarnett.plus.com> Message-ID: <20160928054611.56203df2@bigbox.christie.dr> On 2016-09-27 18:10, MRAB wrote: > The disadvantage of your "string-hacking" is that you're assuming > that the uppercase version of a string is the same length as the > original: Ah, good point. I went with using the regexp version for now since I needed to move forward with something, so I'm glad I opted reasonably. Thanks, -tkc From nomail at com.invalid Wed Sep 28 06:47:56 2016 From: nomail at com.invalid (ast) Date: Wed, 28 Sep 2016 12:47:56 +0200 Subject: Why searching in a set is much faster than in a list ? In-Reply-To: <57eb7dff$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <57eb5a4a$0$3305$426a74cc@news.free.fr> <57eb7dff$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57eb9fe1$0$5267$426a74cc@news.free.fr> "Steven D'Aprano" a ?crit dans le message de news:57eb7dff$0$1598$c3e8da3$5496439d at news.astraweb.com... > On Wednesday 28 September 2016 15:51, ast wrote: > >> Hello >> >> I noticed that searching in a set is faster than searching in a list. > [...] >> I tried a search in a tuple, it's not different that in a list. >> Any comments ? > > > A list, array or tuple is basically a linear array that needs to be searched > one item at a time: > > [ a | b | c | d | ... | x | y | z ] > > To find x, Python has to start at the beginning and look at every item in turn, > until it finds x. > > But a set is basically a hash table. It is an array, but laid out differently, > with blank cells: > > [ # | # | h | p | a | # | m | y | b | # | # | f | x | ... | # ] > > Notice that the items are jumbled up in arbitrary order. So how does Python > find them? > > Python calls hash() on the value, which returns a number, and that points > directly to the cell which would contain the value if it were there. So if you > search for x, Python calls hash(x) which will return (say) 12. Python then > looks in cell 12, and if x is there, it returns True, and if it's not, it > returns False. So instead of looking at 24 cells in the array to find x, it > calculates a hash (which is usually fast), then looks at 1 cell. > > (This is a little bit of a simplification -- the reality is a bit more > complicated, but you can look up "hash tables" on the web or in computer > science books. They are a standard data structure, so there is plenty of > information available.) > > On average, if you have a list with 1000 items, you need to look at 500 items > before finding the one you are looking for. With a set or dict with 1000 items, > on average you need to look at 1 item before finding the one you are looking > for. And that is why sets and dicts are usually faster than lists. > > > > -- > Steven > git gets easier once you get the basic idea that branches are homeomorphic > endofunctors mapping submanifolds of a Hilbert space. > Thanks a lot, very interesting. From motoom at xs4all.nl Wed Sep 28 07:12:08 2016 From: motoom at xs4all.nl (Michiel Overtoom) Date: Wed, 28 Sep 2016 13:12:08 +0200 Subject: Why searching in a set is much faster than in a list ? In-Reply-To: <57eb9fe1$0$5267$426a74cc@news.free.fr> References: <57eb5a4a$0$3305$426a74cc@news.free.fr> <57eb7dff$0$1598$c3e8da3$5496439d@news.astraweb.com> <57eb9fe1$0$5267$426a74cc@news.free.fr> Message-ID: <6B211BB7-6140-4D7D-9C25-976BABD81F20@xs4all.nl> Hi, Brandon Rhodes gave a talk about dictionaries (similar to sets), 'The Mighty Dictionary': https://www.youtube.com/watch?v=C4Kc8xzcA68 You also might be interested in his talk about Python data structures, 'All Your Ducks In A Row': https://www.youtube.com/watch?v=fYlnfvKVDoM Greetings, From greg.ewing at canterbury.ac.nz Wed Sep 28 07:25:31 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 29 Sep 2016 00:25:31 +1300 Subject: Python C API: How to debug reference leak? In-Reply-To: References: <87wphxddwc.fsf@handshake.de> <87wphw1p2l.fsf@handshake.de> Message-ID: Chris Angelico wrote: > If you've Py_DECREFed it and then peek into its internals, you're > aiming a gun at your foot. That's true. A safer way would be to look at the refcount *before* decreffing and verify that it's what you expect. -- Greg From steve+python at pearwood.info Wed Sep 28 07:32:01 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 28 Sep 2016 21:32:01 +1000 Subject: Why searching in a set is much faster than in a list ? References: <57eb5a4a$0$3305$426a74cc@news.free.fr> <87ponoqum7.fsf@elektro.pacujo.net> Message-ID: <57ebaa33$0$1609$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Sep 2016 07:07 pm, Chris Angelico wrote: > On Wed, Sep 28, 2016 at 6:46 PM, Marko Rauhamaa wrote: >> Lawrence D?Oliveiro : >> >>> On Wednesday, September 28, 2016 at 6:51:17 PM UTC+13, ast wrote: >>>> I noticed that searching in a set is faster than searching in a list. >>> >>> That?s why we have sets. >> >> I would have thought the point of sets is to have set semantics, just >> like the point of lists is to have list semantics. > > And set semantics are what, exactly? Membership is a primary one. Yep, that's pretty much it... > "Searching in a set" in the OP's language is a demonstration of the > 'in' operator, a membership/containment check. > > (Other equally important set semantics include intersection and union, Both of those revolve on membership testing. The union of A and B is the set of all elements in A plus those in B; the intersection of A and B is the set of all elements in both A and B. > but membership inclusion checks are definitely up there among primary > purposes of sets.) I can't think of a set operation (apart from add and remove) which doesn't resolve around membership. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Wed Sep 28 07:34:52 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Sep 2016 21:34:52 +1000 Subject: Python C API: How to debug reference leak? In-Reply-To: References: <87wphxddwc.fsf@handshake.de> <87wphw1p2l.fsf@handshake.de> Message-ID: On Wed, Sep 28, 2016 at 9:25 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> If you've Py_DECREFed it and then peek into its internals, you're >> aiming a gun at your foot. > > > That's true. A safer way would be to look at the refcount > *before* decreffing and verify that it's what you expect. Exactly, which is presumably what dieter meant by a refcount of 1 being the one you're holding. A refcount of *2* indicates another reference somewhere. ChrisA From steve+python at pearwood.info Wed Sep 28 07:48:20 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 28 Sep 2016 21:48:20 +1000 Subject: Is there a way to change the closure of a python function? References: <89b566a5-54d0-440f-9105-8eec9233dcf9@googlegroups.com> Message-ID: <57ebae05$0$1584$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Sep 2016 08:03 pm, Lawrence D?Oliveiro wrote: > On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing > wrote: >> Essentially you write the whole program in continuation- >> passing style, with a state object being passed down an >> infinite chain of function calls. > > Procedural programming under another name... Only in the sense that procedural programming is unstructured programming under another name. What is a procedure call but a disguised GOSUB, and what is GOSUB but a pair of GOTOs? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From m at funkyhat.org Wed Sep 28 08:26:28 2016 From: m at funkyhat.org (Matt Wheeler) Date: Wed, 28 Sep 2016 12:26:28 +0000 Subject: Can this be easily done in Python? In-Reply-To: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> References: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> Message-ID: On Tue, 27 Sep 2016 at 20:58 TUA wrote: > Is the following possible in Python? > > Given how the line below works > > TransactionTerms = 'TransactionTerms' > > > have something like > > TransactionTerms = > > that sets the variable TransactionTerms to its own name as string > representation without having to specify it explicitly as in the line > above.... > (forgot to send to list, sorry) ``` def name(name): globals()[name] = name name('hi') print(hi) ``` Or alternatively ``` import inspect def assign(): return inspect.stack()[1].code_context[0].split('=')[0].strip() thing = assign() print(thing) ``` But why? Both of these are pretty dodgy abuses of Python (I can't decide which is worse, anyone?), and I've only tested them on 3.5. I present them here purely because I was interested in working them out, and absolve myself of any responsibility should anyone find them in use in production code! :P (don't do that!) From jussi.piitulainen at helsinki.fi Wed Sep 28 09:05:58 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 28 Sep 2016 16:05:58 +0300 Subject: Is there a way to change the closure of a python function? References: <89b566a5-54d0-440f-9105-8eec9233dcf9@googlegroups.com> <57ebae05$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano writes: > On Wed, 28 Sep 2016 08:03 pm, Lawrence D?Oliveiro wrote: > >> On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing >> wrote: >>> Essentially you write the whole program in continuation- >>> passing style, with a state object being passed down an >>> infinite chain of function calls. >> >> Procedural programming under another name... > > Only in the sense that procedural programming is unstructured programming > under another name. What is a procedure call but a disguised GOSUB, and > what is GOSUB but a pair of GOTOs? Continuation-passing style is only GOTOs. Instead of returning to the caller, procedures pass control to the continuation, together with the values that the continuation is expecting from the procedure. I guess you can think of it as a way to disguise a GOSUB. From p.f.moore at gmail.com Wed Sep 28 10:35:38 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 28 Sep 2016 07:35:38 -0700 (PDT) Subject: Using the Windows "embedded" distribution of Python Message-ID: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> This is probably more of a Windows question than a Python question, but as it's related to embedding Python, I thought I'd try here anyway. I'm writing some command line applications in Python, and I want to bundle them into a standalone form using the new "embedding" distribution of Python. The basic process is easy enough - write a small exe that sets up argv, and then call Py_Main. Furthermore, as I'm *only* using Py_Main, I can use the restricted API, and make my code binary compatible with any Python 3 version. So far so good. I have my exe, and my application code. I create a directory for my app, put the exe/app code in there, and then unzip the embedded distribution in there. And everything works. Yay! However, I'm expecting my users to put my application directory on their PATH (as these are command line utilities). And I don't really want my private copy of the Python DLLs to be exposed on the user's PATH (I don't *know* that it'll interfere with their actual Python installation, but I'd prefer not to take risks). And this is when my problems start. Ideally, I'd put the embedded Python distribution in a subdirectory (say "embed") of my application directory. But the standard loader won't find python3.dll from there. So I have to do something a bit better. As I'm only using Py_Main, I thought I'd be OK to dynamically load it - LoadLibrary on the DLL, then GetProcAddress. No big deal. But I need to tell LoadLibrary to get the DLL from the "embed" subdirectory. I suppose I could add that directory to PATH locally to my program, but that seems clumsy. So I thought I'd try SetDllDirectory. That works for python36.dll, but if I load python3.dll, it can't find Py_Main - the export shows as "(forwarded to python36.Py_Main)", maybe the forwarding doesn't handle SetDllDirectory? So, basically what I'm asking: * If I want to put my application on PATH, am I stuck with having the embedded distribution in the same directory, and also on PATH? * If I can put the embedded distribution in a subdirectory, can that be made to work with python3.dll, or will I have to use python36.dll? None of this is an issue with the most likely use of the embedded distribution (GUI apps, or server apps, both of which are likely to be run by absolute path, and so don't need to be on PATH myself). But I'd really like to be able to promote the embedded distribution as an alternative to tools like py2exe or cx_Freeze, so it would be good to know if a solution is possible (hmm, how come py2exe, and tools like Mercurial, which AFIK use it, don't have this issue too?) Paul From alister.ware at ntlworld.com Wed Sep 28 11:30:00 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 28 Sep 2016 15:30:00 GMT Subject: Is there a way to change the closure of a python function? Message-ID: On Wed, 28 Sep 2016 21:48:20 +1000, Steve D'Aprano wrote: > On Wed, 28 Sep 2016 08:03 pm, Lawrence D?Oliveiro wrote: > >> On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing >> wrote: >>> Essentially you write the whole program in continuation- >>> passing style, with a state object being passed down an infinite chain >>> of function calls. >> >> Procedural programming under another name... > > Only in the sense that procedural programming is unstructured > programming under another name. What is a procedure call but a disguised > GOSUB, and what is GOSUB but a pair of GOTOs? by this analysis isn't any function call the same? are not loops just stylised conditional gotos? -- We only support a 28000 bps connection. From p.f.moore at gmail.com Wed Sep 28 11:30:41 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 28 Sep 2016 08:30:41 -0700 (PDT) Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: Message-ID: On Tuesday, 27 September 2016 02:49:08 UTC+1, jf... at ms4.hinet.net wrote: > This function is in a DLL. It's small but may run for days before complete. I want it takes 100% core usage. Threading seems not a good idea for it shares the core with others. Will the multiprocessing module do it? Any suggestion? Taking a step back from the more detailed answers, would I be right to assume that you want to call this external function multiple times from Python, and each call could take days to run? Or is it that you have lots of calls to make and each one takes a small amount of time but the total time for all the calls is in days? And furthermore, can I assume that the external function is *not* written to take advantage of multiple CPUs, so that if you call the function once, it's only using one of the CPUs you have? Is it fully utilising a single CPU, or is it actually not CPU-bound for a single call? To give specific suggestions, we really need to know a bit more about your issue. Paul From p.f.moore at gmail.com Wed Sep 28 11:41:45 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 28 Sep 2016 08:41:45 -0700 (PDT) Subject: Is there a way to change the closure of a python function? In-Reply-To: References: Message-ID: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> On Wednesday, 28 September 2016 10:19:01 UTC+1, Chris Angelico wrote: > If monads allow mutations or side effects, they are by definition not > pure functions, and violate your bullet point. Languages like Haskell > have them not because they are an intrinsic part of functional > programming languages, but because they are an intrinsic part of > practical/useful programming languages. Monads don't "allow" mutations or side effects. However, they allow you to express the *process* of making mutations or side effects in an abstract manner. What "allows side effects" in languages like Haskell is the fact that the runtime behaviour of the language is not defined as "calculating the value of the main function" but rather as "making the process that the main functon defines as an abstract monad actually happen". That's a completely informal and personal interpretation of what's going on, and Haskell users might not agree with it[1]. But for me the key point in working out what Haskell was doing was when I realised that their execution model wasn't the naive "evaluate the main function" model that I'd understood from when I first learned about functional programming. Paul [1] One of the problems with modern functional programming is that they typically have major problems explaining their interpretation of what's going on, with the result that they generally lose their audience long before they manage to explain the actually useful things that come from their way of thinking. From emile at fenx.com Wed Sep 28 11:56:14 2016 From: emile at fenx.com (Emile van Sebille) Date: Wed, 28 Sep 2016 08:56:14 -0700 Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> Message-ID: On 09/23/2016 05:02 PM, Lawrence D?Oliveiro wrote: > On Thursday, September 22, 2016 at 8:34:20 AM UTC+12, Emile wrote: >> Hmm, then I'll have to wait longer to experience the unreliability as >> the handful of automated gui tools I'm running has only been up 10 to 12 >> years or so. > > You sound like you have a solution for the OP, then. > My solution was to automate one of the then available windows gui scripting tools. I've stopped doing windows in the meantime and no longer know what's available. My point was that it is possible to automate windows reliably as long as the programming is robust. You indicated you found automating unreliable -- I disagree. Emile From steve+python at pearwood.info Wed Sep 28 12:33:05 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 29 Sep 2016 02:33:05 +1000 Subject: Is there a way to change the closure of a python function? References: <89b566a5-54d0-440f-9105-8eec9233dcf9@googlegroups.com> <57ebae05$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57ebf0c3$0$22140$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Sep 2016 11:05 pm, Jussi Piitulainen wrote: > Steve D'Aprano writes: > >> On Wed, 28 Sep 2016 08:03 pm, Lawrence D?Oliveiro wrote: >> >>> On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing >>> wrote: >>>> Essentially you write the whole program in continuation- >>>> passing style, with a state object being passed down an >>>> infinite chain of function calls. >>> >>> Procedural programming under another name... >> >> Only in the sense that procedural programming is unstructured programming >> under another name. What is a procedure call but a disguised GOSUB, and >> what is GOSUB but a pair of GOTOs? > > Continuation-passing style is only GOTOs. Instead of returning to the > caller, procedures pass control to the continuation, together with the > values that the continuation is expecting from the procedure. > > I guess you can think of it as a way to disguise a GOSUB. Really, if you think about it, both functional and procedural programming are exactly the same as programming in assembly language. Returning a value from a function pushes that value onto the function call stack, which is really just a disguised assembly MOV command. -- 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 Sep 28 12:43:48 2016 From: random832 at fastmail.com (Random832) Date: Wed, 28 Sep 2016 12:43:48 -0400 Subject: Is there a way to change the closure of a python function? In-Reply-To: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> References: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> Message-ID: <1475081028.3395879.739867785.05F0786F@webmail.messagingengine.com> On Wed, Sep 28, 2016, at 11:41, Paul Moore wrote: > What "allows side effects" in languages like Haskell is the fact that the > runtime behaviour of the language is not defined as "calculating the > value of the main function" but rather as "making the process that the > main functon defines as an abstract monad actually happen". Well, from another point of view, the output (that is, the set of changes to files, among other things, that is defined by the monad-thingy) is *part of* the value of the main function. And the state of the universe prior to running it is part of the input is part of the arguments. From pkpearson at nowhere.invalid Wed Sep 28 12:45:12 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 28 Sep 2016 16:45:12 GMT Subject: Can this be easily done in Python? References: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> Message-ID: On Tue, 27 Sep 2016 12:58:40 -0700 (PDT), TUA wrote: > Is the following possible in Python? > > Given how the line below works > > TransactionTerms = 'TransactionTerms' > > > have something like > > TransactionTerms = > > that sets the variable TransactionTerms to its own name as string > representation without having to specify it explicitly as in the line > above.... You say "variable", but the use of that word often signals a misunderstanding about Python. Python has "objects". An object often has a name, and in fact often has several names. Attempting to associate an object with "its name" looks like a Quixotic quest to me. -- To email me, substitute nowhere->runbox, invalid->com. From pkpearson at nowhere.invalid Wed Sep 28 12:48:27 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 28 Sep 2016 16:48:27 GMT Subject: How to call this method from main method References: <2c35b9c7-79d3-405f-b1fa-fb237b27d313@googlegroups.com> Message-ID: On Tue, 27 Sep 2016 23:44:11 -0700 (PDT), prasanthktgr at gmail.com wrote: [snip] > > if __name__ == '__main__': > GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000, > "g,m,a,s,c,p,d") > > When i am calling the above method from main method it is not > returning the value but when i use print it is showing the value. Is > there any wrong in returning the value from a method. How do you know it's not returning a value? You don't save the return value anywhere. -- To email me, substitute nowhere->runbox, invalid->com. From rosuav at gmail.com Wed Sep 28 13:44:34 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Sep 2016 03:44:34 +1000 Subject: Is there a way to change the closure of a python function? In-Reply-To: <57ebf0c3$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <89b566a5-54d0-440f-9105-8eec9233dcf9@googlegroups.com> <57ebae05$0$1584$c3e8da3$5496439d@news.astraweb.com> <57ebf0c3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 29, 2016 at 2:33 AM, Steve D'Aprano wrote: >>>> Procedural programming under another name... >>> >>> Only in the sense that procedural programming is unstructured programming >>> under another name. What is a procedure call but a disguised GOSUB, and >>> what is GOSUB but a pair of GOTOs? >> >> Continuation-passing style is only GOTOs. Instead of returning to the >> caller, procedures pass control to the continuation, together with the >> values that the continuation is expecting from the procedure. >> >> I guess you can think of it as a way to disguise a GOSUB. > > > Really, if you think about it, both functional and procedural programming > are exactly the same as programming in assembly language. Returning a value > from a function pushes that value onto the function call stack, which is > really just a disguised assembly MOV command. http://xkcd.com/435/ Also relevant to this conversation: https://xkcd.com/1270/ ChrisA From rosuav at gmail.com Wed Sep 28 13:46:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Sep 2016 03:46:46 +1000 Subject: Is there a way to change the closure of a python function? In-Reply-To: <1475081028.3395879.739867785.05F0786F@webmail.messagingengine.com> References: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> <1475081028.3395879.739867785.05F0786F@webmail.messagingengine.com> Message-ID: On Thu, Sep 29, 2016 at 2:43 AM, Random832 wrote: > On Wed, Sep 28, 2016, at 11:41, Paul Moore wrote: >> What "allows side effects" in languages like Haskell is the fact that the >> runtime behaviour of the language is not defined as "calculating the >> value of the main function" but rather as "making the process that the >> main functon defines as an abstract monad actually happen". > > Well, from another point of view, the output (that is, the set of > changes to files, among other things, that is defined by the > monad-thingy) is *part of* the value of the main function. And the state > of the universe prior to running it is part of the input is part of the > arguments. That's exactly how a function works in an imperative language, and it's exactly what the FP advocates detest: opaque state. So is the difference between "function" and "monad" in Haskell the same as "pure function" and "function" in other contexts? ChrisA From python.list at tim.thechases.com Wed Sep 28 15:10:01 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Sep 2016 14:10:01 -0500 Subject: Syncing up iterators with gaps Message-ID: <20160928141001.79358086@bigbox.christie.dr> I've got several iterators sharing a common key in the same order and would like to iterate over them in parallel, operating on all items with the same key. I've simplified the data a bit here, but it would be something like data1 = [ # key, data1 (1, "one A"), (1, "one B"), (2, "two"), (5, "five"), ] data2 = [ # key, data1 (1, "uno"), (2, "dos"), (3, "tres x"), (3, "tres y"), (3, "tres z"), (4, "cuatro"), ] data3 = [ # key, data1, data2 (2, "ii", "extra alpha"), (4, "iv", "extra beta"), (5, "v", "extra gamma"), ] And I'd like to do something like for common_key, d1, d2, d3 in magic_happens_here(data1, data2, data3): for row in d1: process_a(common_key, row) for thing in d2: process_b(common_key, row) for thing in d3: process_c(common_key, row) which would yield the common_key, along with enough of each of those iterators (note that gaps can happen, but the sortable order should remain the same). So in the above data, the outer FOR loop would happen 5 times with common_key being [1, 2, 3, 4, 5], and each of [d1, d2, d3] being an iterator that deals with just that data. My original method was hauling everything into memory and making multiple passes filtering on the data. However, the actual sources are CSV-files, some of which are hundreds of megs in size, and my system was taking a bit of a hit. So I was hoping for a way to do this with each iterator making only one complete pass through each source (since they're sorted by common key). It's somewhat similar to the *nix "join" command, only dealing with N files. Thanks for any hints. -tkc From tjreedy at udel.edu Wed Sep 28 15:43:22 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Sep 2016 15:43:22 -0400 Subject: Syncing up iterators with gaps In-Reply-To: <20160928141001.79358086@bigbox.christie.dr> References: <20160928141001.79358086@bigbox.christie.dr> Message-ID: On 9/28/2016 3:10 PM, Tim Chase wrote: > I've got several iterators sharing a common key in the same order and > would like to iterate over them in parallel, operating on all items > with the same key. I've simplified the data a bit here, but it would > be something like > > data1 = [ # key, data1 > (1, "one A"), > (1, "one B"), > (2, "two"), > (5, "five"), > ] > > data2 = [ # key, data1 > (1, "uno"), > (2, "dos"), > (3, "tres x"), > (3, "tres y"), > (3, "tres z"), > (4, "cuatro"), > ] > > data3 = [ # key, data1, data2 > (2, "ii", "extra alpha"), > (4, "iv", "extra beta"), > (5, "v", "extra gamma"), > ] > > And I'd like to do something like > > for common_key, d1, d2, d3 in magic_happens_here(data1, data2, data3): > for row in d1: > process_a(common_key, row) > for thing in d2: > process_b(common_key, row) > for thing in d3: > process_c(common_key, row) > > which would yield the common_key, along with enough of each of those > iterators (note that gaps can happen, but the sortable order should > remain the same). So in the above data, the outer FOR loop would > happen 5 times with common_key being [1, 2, 3, 4, 5], and each of > [d1, d2, d3] being an iterator that deals with just that data. You just need d1, d2, d3 to be iterables, such as a list. Write a magic generator that opens the three files and reads one line of each (with next()). Then in while True loop, find minimum key and make 3 lists (up to 2 possibly empty) of the items in each file with that key. This will require up to 3 inner loops. The read-ahead makes this slightly messy. If any list is not empty, yield the key and 3 lists. Otherwise break the outer loop. > My original method was hauling everything into memory and making > multiple passes filtering on the data. However, the actual sources > are CSV-files, some of which are hundreds of megs in size, and my > system was taking a bit of a hit. So I was hoping for a way to do > this with each iterator making only one complete pass through each > source (since they're sorted by common key). > > It's somewhat similar to the *nix "join" command, only dealing with > N files. It is also somewhat similar to a 3-way mergesort. -- Terry Jan Reedy From rosuav at gmail.com Wed Sep 28 15:48:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Sep 2016 05:48:43 +1000 Subject: Syncing up iterators with gaps In-Reply-To: <20160928141001.79358086@bigbox.christie.dr> References: <20160928141001.79358086@bigbox.christie.dr> Message-ID: On Thu, Sep 29, 2016 at 5:10 AM, Tim Chase wrote: > And I'd like to do something like > > for common_key, d1, d2, d3 in magic_happens_here(data1, data2, data3): > for row in d1: > process_a(common_key, row) > for thing in d2: > process_b(common_key, row) > for thing in d3: > process_c(common_key, row) Assuming that the keys are totally ordered and the data sets are sorted, this should work: def magic_happens_here(*iters): iters = [iter(it) for it in iters] nexts = [next(it, (None,)) for it in iters] while "moar stuff": try: common_key = min(row[0] for row in nexts if row[0]) except ValueError: break # No moar stuff outputs = [common_key] for i in range(len(nexts)): # code smell, sorry output = [] while nexts[i][0] == common_key: output.append(nexts[i]) nexts[i] = next(iters[i], (None,)) outputs.append(output) yield outputs Basically, it takes the lowest available key, then takes everything of that key and yields it as a unit. Code not tested. Use at your own risk. ChrisA From ckaynor at zindagigames.com Wed Sep 28 16:17:20 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 28 Sep 2016 13:17:20 -0700 Subject: Syncing up iterators with gaps In-Reply-To: References: <20160928141001.79358086@bigbox.christie.dr> Message-ID: Here is a slight variation of Chris A's code that does not require more than a single look-ahead per generator. It may be better depending on the exact data passed in. Chris A's version will store all of the items for each output that have a matching key, which, depending on the expected data, could use quite a bit of memory. This version yields a list of generators, which then allows for never having more than a single lookahead per list. The generators returned must be consumed immediately or they will be emptied - I put in a safety loop that consumes them before continuing processing. My version is likely better if your processing does not require storing (most of) the items and you expect there to be a large number of common keys in each iterator. If you expect only a couple of items per shared key per list, Chris A's version will probably perform better for slightly more memory usage, as well as being somewhat safer and simpler. def magic_happens_here(*iters): def gen(j): while nexts[j][0] == common_key: yield nexts[j] nexts[j] = next(iters[j], (None,)) iters = [iter(it) for it in iters] nexts = [next(it, (None,)) for it in iters] while "moar stuff": try: common_key = min(row[0] for row in nexts if row[0]) except ValueError: break # No moar stuff outputs = [common_key] for i in range(len(nexts)): # code smell, sorry outputs.append(gen(i)) yield outputs # The following three lines confirm that the generators provided # were consumed. This allows not exhausting the yielded generators. # If this is not included, and the iterator is not consumed, it can # result in an infinite loop. for output in outputs[1:]: for item in output: pass Chris On Wed, Sep 28, 2016 at 12:48 PM, Chris Angelico wrote: > On Thu, Sep 29, 2016 at 5:10 AM, Tim Chase > wrote: >> And I'd like to do something like >> >> for common_key, d1, d2, d3 in magic_happens_here(data1, data2, data3): >> for row in d1: >> process_a(common_key, row) >> for thing in d2: >> process_b(common_key, row) >> for thing in d3: >> process_c(common_key, row) > > Assuming that the keys are totally ordered and the data sets are > sorted, this should work: > > def magic_happens_here(*iters): > iters = [iter(it) for it in iters] > nexts = [next(it, (None,)) for it in iters] > while "moar stuff": > try: common_key = min(row[0] for row in nexts if row[0]) > except ValueError: break # No moar stuff > outputs = [common_key] > for i in range(len(nexts)): # code smell, sorry > output = [] > while nexts[i][0] == common_key: > output.append(nexts[i]) > nexts[i] = next(iters[i], (None,)) > outputs.append(output) > yield outputs > > Basically, it takes the lowest available key, then takes everything of > that key and yields it as a unit. > > Code not tested. Use at your own risk. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Wed Sep 28 16:35:53 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Sep 2016 22:35:53 +0200 Subject: Syncing up iterators with gaps References: <20160928141001.79358086@bigbox.christie.dr> Message-ID: Tim Chase wrote: > I've got several iterators sharing a common key in the same order and > would like to iterate over them in parallel, operating on all items > with the same key. I've simplified the data a bit here, but it would > be something like > > data1 = [ # key, data1 > (1, "one A"), > (1, "one B"), > (2, "two"), > (5, "five"), > ] > > data2 = [ # key, data1 > (1, "uno"), > (2, "dos"), > (3, "tres x"), > (3, "tres y"), > (3, "tres z"), > (4, "cuatro"), > ] > > data3 = [ # key, data1, data2 > (2, "ii", "extra alpha"), > (4, "iv", "extra beta"), > (5, "v", "extra gamma"), > ] > > And I'd like to do something like > > for common_key, d1, d2, d3 in magic_happens_here(data1, data2, data3): > for row in d1: > process_a(common_key, row) > for thing in d2: > process_b(common_key, row) > for thing in d3: > process_c(common_key, row) > > which would yield the common_key, along with enough of each of those > iterators (note that gaps can happen, but the sortable order should > remain the same). So in the above data, the outer FOR loop would > happen 5 times with common_key being [1, 2, 3, 4, 5], and each of > [d1, d2, d3] being an iterator that deals with just that data. > > My original method was hauling everything into memory and making > multiple passes filtering on the data. However, the actual sources > are CSV-files, some of which are hundreds of megs in size, and my > system was taking a bit of a hit. So I was hoping for a way to do > this with each iterator making only one complete pass through each > source (since they're sorted by common key). > > It's somewhat similar to the *nix "join" command, only dealing with > N files. > > Thanks for any hints. > > -tkc A bit messy, might try replacing groups list with a dict: $ cat merge.py from itertools import groupby from operator import itemgetter first = itemgetter(0) rest = itemgetter(slice(1, None)) def magic_happens_here(*columns): grouped = [groupby(column, key=first) for column in columns] missing = object() def getnext(g): nonlocal n try: k, g = next(g) except StopIteration: n -= 1 return (missing, None) return k, g n = len(grouped) groups = [getnext(g) for g in grouped] while n: minkey = min(k for k, g in groups if k is not missing) yield (minkey,) + tuple( map(rest, g) if k == minkey else () for k, g in groups) for i, (k, g) in enumerate(groups): if k == minkey: groups[i] = getnext(grouped[i]) if __name__ == "__main__": data1 = [ # key, data1 (1, "one A"), (1, "one B"), (2, "two"), (5, "five"), ] data2 = [ # key, data1 (1, "uno"), (2, "dos"), (3, "tres x"), (3, "tres y"), (3, "tres z"), (4, "cuatro"), ] data3 = [ # key, data1, data2 (2, "ii", "extra alpha"), (4, "iv", "extra beta"), (5, "v", "extra gamma"), ] for common_key, d1, d2, d3 in magic_happens_here(data1, data2, data3): print(common_key) for d in d1, d2, d3: print(" ", list(d)) $ python3 merge.py 1 [('one A',), ('one B',)] [('uno',)] [] 2 [('two',)] [('dos',)] [('ii', 'extra alpha')] 3 [] [('tres x',), ('tres y',), ('tres z',)] [] 4 [] [('cuatro',)] [('iv', 'extra beta')] 5 [('five',)] [] [('v', 'extra gamma')] From eryksun at gmail.com Wed Sep 28 16:49:50 2016 From: eryksun at gmail.com (eryk sun) Date: Wed, 28 Sep 2016 20:49:50 +0000 Subject: Using the Windows "embedded" distribution of Python In-Reply-To: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> Message-ID: On Wed, Sep 28, 2016 at 2:35 PM, Paul Moore wrote: > So I thought I'd try SetDllDirectory. That works for python36.dll, but if I load > python3.dll, it can't find Py_Main - the export shows as "(forwarded to > python36.Py_Main)", maybe the forwarding doesn't handle SetDllDirectory? It works for me. Are you calling SetDllDirectory with the fully-qualified path? If not it's relative to the working directory, which isn't necessarily (generally is not) the application directory, in which case delay-loading python36.dll will fail. You can create the fully-qualified path from the application path, i.e. GetModuleFileNameW(NULL, ...). That said, I prefer using LoadLibraryExW(absolute_path_to_python3, NULL, LOAD_WITH_ALTERED_SEARCH_PATH). The alternate search substitutes the DLL's directory for the application directory when loading dependent DLLs, which allows loading python36.dll and vcruntime140.dll without having to modify the DLL search path of the entire process. From lawrencedo99 at gmail.com Wed Sep 28 17:52:33 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 28 Sep 2016 14:52:33 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <878d3831-9f06-4927-be4f-678718e9d2cb@googlegroups.com> <89d1117c-2893-4bb4-ad06-dbd4127bdd26@googlegroups.com> <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> Message-ID: <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> On Thursday, September 29, 2016 at 4:57:10 AM UTC+13, Emile van Sebille wrote: > My point was that it is possible to automate windows reliably as long as the > programming is robust. Sounds like circular reasoning. From lidia.gaetan at wanadoo.fr Wed Sep 28 18:10:26 2016 From: lidia.gaetan at wanadoo.fr (Lidia ARNAL) Date: Thu, 29 Sep 2016 00:10:26 +0200 (CEST) Subject: problemes Message-ID: <186772781.2509.1475100626057.JavaMail.www@wwinf1f09> bonjour je n'arrive plus a me connecter au script doA-Tools alors que celui si fonctionnait bien. la fen?tre reste noir et rien ne se passe? merci de votre aide ? From emile at fenx.com Wed Sep 28 18:53:52 2016 From: emile at fenx.com (Emile van Sebille) Date: Wed, 28 Sep 2016 15:53:52 -0700 Subject: how to automate java application in window using python In-Reply-To: <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> References: <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> Message-ID: On 09/28/2016 02:52 PM, Lawrence D?Oliveiro wrote: > On Thursday, September 29, 2016 at 4:57:10 AM UTC+13, Emile van Sebille wrote: >> My point was that it is possible to automate windows reliably as long as the >> programming is robust. > > Sounds like circular reasoning. > Which worked for me! You should try it. Sloppy programming has always been unreliable. Emile From nimbiotics at gmail.com Wed Sep 28 19:15:46 2016 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Wed, 28 Sep 2016 16:15:46 -0700 (PDT) Subject: Can this be easily done in Python? In-Reply-To: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> References: <2146ddf8-f387-4798-996b-111d9ee272d7@googlegroups.com> Message-ID: <00da0138-203e-4c8b-9cf1-8cc9ce484120@googlegroups.com> I'm not sure I understand your question, but I 'think' you area talking about executing dynamically chunks of code. If that is the case, there are a couple of ways to do it. These are some links that might interest you: http://stackoverflow.com/questions/3974554/python-how-to-generate-the-code-on-the-fly http://stackoverflow.com/questions/32073600/python-how-to-create-a-class-name-on-the-fly http://lucumr.pocoo.org/2011/2/1/exec-in-python/ On Tuesday, September 27, 2016 at 3:58:59 PM UTC-4, TUA wrote: > Is the following possible in Python? > > Given how the line below works > > TransactionTerms = 'TransactionTerms' > > > have something like > > TransactionTerms = > > that sets the variable TransactionTerms to its own name as string representation without having to specify it explicitly as in the line above.... From lawrencedo99 at gmail.com Wed Sep 28 19:59:55 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 28 Sep 2016 16:59:55 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: References: <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> Message-ID: <3e2d0652-85a8-4a4b-ad75-d50e3f049024@googlegroups.com> On Thursday, September 29, 2016 at 11:54:46 AM UTC+13, Emile van Sebille wrote: > Which worked for me! You should try it. Sloppy programming has always > been unreliable. So it is clear you don?t have an answer to the OP?s question after all. Just some vague, meaningless generalities. From steve+python at pearwood.info Wed Sep 28 20:20:26 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 29 Sep 2016 10:20:26 +1000 Subject: Syncing up iterators with gaps References: <20160928141001.79358086@bigbox.christie.dr> Message-ID: <57ec5e4c$0$1615$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Sep 2016 05:10 am, Tim Chase wrote: > I've got several iterators sharing a common key in the same order and > would like to iterate over them in parallel, operating on all items > with the same key. I've simplified the data a bit here, but it would > be something like > > data1 = [ # key, data1 > (1, "one A"), > (1, "one B"), > (2, "two"), > (5, "five"), > ] So data1 has keys 1, 1, 2, 5. Likewise data2 has keys 1, 2, 3, 3, 3, 4 and data3 has keys 2, 4, 5. (data3 also has *two* values, not one, which is an additional complication.) > And I'd like to do something like > > for common_key, d1, d2, d3 in magic_happens_here(data1, data2, data3): What's common_key? In particular, given that data1, data2 and data3 have the first key each of 1, 1 and 2 respectively, how do you get: > So in the above data, the outer FOR loop would > happen 5 times with common_key being [1, 2, 3, 4, 5] I'm confused. Is common_key a *constant* [1, 2, 3, 4, 5] or are you saying that it iterates over 1, 2, 3, 4, 5? If the later, it sounds like you want something like a cross between itertools.groupby and the "merge" stage of mergesort. You have at least three sorted(?) iterators, representing the CSV files, let's say they iterate over data1 = [(1, "one A"), (1, "one B"), (2, "two"), (5, "five")] data2 = [(1, "uno"), (2, "dos"), (3, "tres x"), (3, "tres y"), (3, "tres z"), (4, "cuatro")] data3 = [ (2, ("ii", "extra alpha")), (4, ("iv", "extra beta")), (5, ("v", "extra gamma"))] Note that I have modified data3 so instead of three columns, (key value value), it has two (key value) and value is a 2-tuple. So first you want an iterator that does an N-way merge: merged = [(1, "one A"), (1, "one B"), (1, "uno"), (2, "two"), (2, "dos"), (2, ("ii", "extra alpha")), (3, "tres x"), (3, "tres y"), (3, "tres z"), (4, "cuatro"), (4, ("iv", "extra beta")), (5, "five"), (5, ("v", "extra gamma")), ] and then you can simply call itertools.groupby to group by the common keys: 1: ["one A", "one B", "uno"] 2: ["two", "dos", ("ii", "extra alpha")] 3: ["tres x", "tres y", "tres z"] 4: ["cuatro", ("iv", "extra beta")] 5: ["five", ("v", "extra gamma")] and then you can extract the separate columns from each value. You might find it easier to have *all* the iterators yield (key, tuple) pairs, where data1 and data2 yield a 1-tuple and data3 yields a 2-tuple. If you look on ActiveState, I'm pretty sure you will find a recipe from Raymond Hettinger for a merge sort or heap sort or something along those lines, which you can probably adapt for an arbitrary number of inputs. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 28 20:34:43 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 29 Sep 2016 10:34:43 +1000 Subject: Is there a way to change the closure of a python function? References: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> <1475081028.3395879.739867785.05F0786F@webmail.messagingengine.com> Message-ID: <57ec61a6$0$1608$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Sep 2016 03:46 am, Chris Angelico wrote: > That's exactly how a function works in an imperative language, and > it's exactly what the FP advocates detest: opaque state. So is the > difference between "function" and "monad" in Haskell the same as "pure > function" and "function" in other contexts? Honestly Chris, what's hard to understand about this? Monads are burritos. http://blog.plover.com/prog/burritos.html -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jfong at ms4.hinet.net Wed Sep 28 21:06:54 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 28 Sep 2016 18:06:54 -0700 (PDT) Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: Message-ID: <74c4bb85-7b32-4788-af1c-fd2b23357839@googlegroups.com> eryk sun at 2016/9/28 1:05:32PM wrote: > In Unix, Python's os module may have sched_setaffinity() to set the > CPU affinity for all threads in a given process. > > In Windows, you can use ctypes to call SetProcessAffinityMask, > SetThreadAffinityMask, or SetThreadIdealProcessor (a hint for the > scheduler). On a NUMA system you can call GetNumaNodeProcessorMask(Ex) > to get the mask of CPUs that are on a given NUMA node. The cmd shell's > "start" command supports "/numa" and "/affinity" options, which can be > combined. Seems have to dive into Windows to understand its usage:-) From jfong at ms4.hinet.net Wed Sep 28 21:22:50 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 28 Sep 2016 18:22:50 -0700 (PDT) Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: Message-ID: <682e117e-3c50-4e61-9493-bc3167f7a039@googlegroups.com> Paul Moore at 2016/9/28 11:31:50PM wrote: > Taking a step back from the more detailed answers, would I be right to assume that you want to call this external function multiple times from Python, and each call could take days to run? Or is it that you have lots of calls to make and each one takes a small amount of time but the total time for all the calls is in days? > > And furthermore, can I assume that the external function is *not* written to take advantage of multiple CPUs, so that if you call the function once, it's only using one of the CPUs you have? Is it fully utilising a single CPU, or is it actually not CPU-bound for a single call? > > To give specific suggestions, we really need to know a bit more about your issue. Forgive me, I didn't notice these detail will infulence the answer:-) Python will call it once. The center part of this function was written in assembly for performance. During its execution, this part might be called thousands of million times. The function was written to run in a single CPU, but the problem it want to solve can be easily distributed into multiple CPUs. --Jach From python.list at tim.thechases.com Wed Sep 28 21:38:50 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Sep 2016 20:38:50 -0500 Subject: Syncing up iterators with gaps In-Reply-To: <57ec5e4c$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <20160928141001.79358086@bigbox.christie.dr> <57ec5e4c$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160928203850.26651709@bigbox.christie.dr> On 2016-09-29 10:20, Steve D'Aprano wrote: > On Thu, 29 Sep 2016 05:10 am, Tim Chase wrote: > > data1 = [ # key, data1 > > (1, "one A"), > > (1, "one B"), > > (2, "two"), > > (5, "five"), > > ] > > So data1 has keys 1, 1, 2, 5. > Likewise data2 has keys 1, 2, 3, 3, 3, 4 and data3 has keys 2, 4, 5. Correct > (data3 also has *two* values, not one, which is an additional > complication.) As commented towards the end, the source is set of CSV files, so each row is a list where a particular (identifiable) item is the key. Assume that one can use something like get_key(row) to return the key, which in the above could be implemented as get_key = lambda row: row[0] and for my csv.DictReader data, would be something like get_key = lambda row: row["Account Number"] > > And I'd like to do something like > > > > for common_key, d1, d2, d3 in magic_happens_here(data1, data2, > > data3): > > What's common_key? In particular, given that data1, data2 and data3 > have the first key each of 1, 1 and 2 respectively, how do you get: > > > So in the above data, the outer FOR loop would > > happen 5 times with common_key being [1, 2, 3, 4, 5] > > I'm confused. Is common_key a *constant* [1, 2, 3, 4, 5] or are you > saying that it iterates over 1, 2, 3, 4, 5? Your interpretation later is correct, that it each unique key once, in-order. So if you data1.append((17, "seventeen")) the outer loop would iterate over [1,2,3,4,5,17] (so not constant, to hopefully answer that part of your question) The actual keys are account-numbers, so they're ascii-sorted strings of the form "1234567-8901", ascending in order through the files. But for equality/less-than/greater-than comparisons, they work effectively as integers in my example. > If the later, it sounds like you want something like a cross between > itertools.groupby and the "merge" stage of mergesort. That's a pretty good description at some level. I looked into groupby() but was having trouble getting it to do what I wanted. > Note that I have modified data3 so instead of three columns, (key > value value), it has two (key value) and value is a 2-tuple. I'm cool with that. Since they're CSV rows, you can imagine the source data then as a generator something like data1 = ( (get_key(row), row) for row in my_csv_iter1 ) to get the data to look like your example input data. > So first you want an iterator that does an N-way merge: > > merged = [(1, "one A"), (1, "one B"), (1, "uno"), > (2, "two"), (2, "dos"), (2, ("ii", "extra alpha")), > (3, "tres x"), (3, "tres y"), (3, "tres z"), > (4, "cuatro"), (4, ("iv", "extra beta")), > (5, "five"), (5, ("v", "extra gamma")), > ] This seems to discard the data's origin (data1/data2/data3) which is how I determine whether to use process_a(), process_b(), or process_c() in my original example where N iterators were returned, one for each input iterator. So the desired output would be akin to (converting everything to tuples as you suggest below) [ (1, [("one A",), ("one B",)], [1, ("uno",)], []), (2, [("two",)], [("dos",)], [("ii", "extra alpha")]), (3, [], [("tres x",), ("tres y",)], []), (4, [], [("cuatro",)], [("iv", "extra beta")]), (5, [("five",)], [], [("v", "extra gamma")]), ] only instead of N list()s, having N generators that are smart enough to yield the corresponding data. > You might find it easier to have *all* the iterators yield (key, > tuple) pairs, where data1 and data2 yield a 1-tuple and data3 > yields a 2-tuple. Right. Sorry my example obscured that shoulda-obviously-been-used simplification. -tkc From orgnut at yahoo.com Wed Sep 28 21:44:44 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 28 Sep 2016 18:44:44 -0700 Subject: Nested for loops and print statements In-Reply-To: <57eb44fd$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <8e565489-63b6-43fd-b9a2-b2856d8c6a24@googlegroups.com> <9137b5b6-aaef-492e-a01f-7fddd89ccffc@googlegroups.com> <57e8d959$0$1500$c3e8da3$5496439d@news.astraweb.com> <441634f4-1d62-4158-8536-37acef226539@googlegroups.com> <57e8ec0d$0$1602$c3e8da3$5496439d@news.astraweb.com> <7c782c5b-4a54-4da2-ab17-fe853e979ffc@googlegroups.com> <57eb44fd$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6Zqdne2qZ-aP73HKnZ2dnUU7-TnNnZ2d@giganews.com> On 09/27/2016 09:20 PM, Steven D'Aprano wrote: > On Wednesday 28 September 2016 12:48, Larry Hudson wrote: > >> As they came through in the newsgroup, BOTH run correctly, because both >> versions had leading spaces only. >> (I did a careful copy/paste to check this.) > > Copying and pasting from the news client may not be sufficient to show what > whitespace is actually used... > Exactly. That's why I pointed out the sometime (mis)handling of tabs in newsreaders, and said these examples came through in MY reader (Thunderbird) as spaces only, so both examples ran correctly. -- -=- Larry -=- From steve+python at pearwood.info Wed Sep 28 23:10:59 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 29 Sep 2016 13:10:59 +1000 Subject: Syncing up iterators with gaps References: <20160928141001.79358086@bigbox.christie.dr> <57ec5e4c$0$1615$c3e8da3$5496439d@news.astraweb.com> <20160928203850.26651709@bigbox.christie.dr> Message-ID: <57ec8644$0$1600$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Sep 2016 11:38 am, Tim Chase wrote: > This seems to discard the data's origin (data1/data2/data3) which is > how I determine whether to use process_a(), process_b(), or > process_c() in my original example where N iterators were returned, > one for each input iterator. So add another stage to your generator pipeline, one which adds a unique ID to the output of each generator so you know where it came from. Hint: the ID doesn't have to be an ID *number*. It can be the process_a, process_b, process_c ... function itself. Then instead of doing: for key, (id, stuff) in groupby(merge(data1, data2, data3), keyfunc): for x in stuff: if id == 1: process_a(key, *x) elif id == 2: process_b(key, *x) elif ... or even: DISPATCH = {1: process_a, 2: process_b, ...} for key, (id, stuff) in groupby(merge(data1, data2, data3), keyfunc): for x in stuff: DISPATCH[id](key, *x) you can do: for key, (process, stuff) in groupby(merge(data1, data2, data3), keyfunc): for x in stuff: process(key, *x) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 28 23:53:46 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 29 Sep 2016 13:53:46 +1000 Subject: Is there a way to change the closure of a python function? References: Message-ID: <57ec904b$0$1621$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Sep 2016 07:18 pm, Chris Angelico wrote: > On Wed, Sep 28, 2016 at 6:52 PM, Gregory Ewing > wrote: >> Chris Angelico wrote: >>> >>> >>> wrote: >>> >>>> * No side effects (new variable bindings may be created, but >>>> existing ones cannot be changed; no mutable data structures). >>> >>> >>> If that's adhered to 100%, the language is useless for any operation >>> that cannot be handled as a "result at end of calculation" function. They're useless for that too, because you, the caller, cannot see the result of the calculation. Printing is a side-effect. Technically you can view the program state through a debugger, but that's exposing implementation details and besides its not very practical. But really, this is nit-picking. It is a little like arguing that no programming languages are actually Turing complete, since no language has an infinite amount of memory available. Of course a programming language needs to have *some* way of doing IO, be that print, writing to files, or flicking the lights on and off in Morse Code, but the challenge is to wall that off in such a way that it doesn't affect the desirable (to functional programmers at least) "no side-effects" property. However, there's no universally agreed upon definition of "side-effect". Some people might disagree that printing to stdout is a side-effect in the sense that matters, namely changes to *program* state. Changes to the rest of the universe are fine. Some will say that local state (local variables within a function) is okay so long as that's just an implementation detail. Others insist that even functions' internal implementation must be pure. After all, a function is itself a program. If we believe that programs are easier to reason about if they have no global mutable state (no global variables), then wrapping that program in "define function"/"end function" tags shouldn't change that. Others will point out that "no side-effects" is a leaky abstraction, and like all such abstractions, it leaks. Your functional program will use memory, the CPU will get warmer, etc. http://www.johndcook.com/blog/2010/05/18/pure-functions-have-side-effects/ John Cook suggests that functional programming gets harder and harder to do right (both for the compiler and for the programmer) as you asymptotically approach 100% pure, and suggests the heuristic that (say) 85% pure is the sweet spot: functional in the small, object oriented in the large. http://www.johndcook.com/blog/2009/03/23/functional-in-the-small-oo-in-the-large/ I agree. I find that applying functional techniques to individual methods makes my classes much better: - local variables are fine; - global variables are not; - global constants are okay; - mutating the state of the instance should be kept to the absolute minimum; - and only done from a few mutator methods, not from arbitrary methods; - attributes should *usually* be passed as arguments to methods, not treated as part of the environment. That last one is probably the most controversial. Let me explain. Suppose I have a class with state and at least two methods: class Robot: def __init__(self): self.position = (0, 0) def move(self, x, y): self.position[0] += x self.position[1] += y def report(self): # Robot, where are you? print("I'm at %r" % self.position) So far so good. But what if we want to make the report() method a bit more fancy? Maybe we want to spruce it up a bit, and allow subclasses to customize how they actually report (print, show a dialog box, write to a log file, whatever you like): def report(self): self.format() self.display_report() def display_report(self): print("I'm at %r" % self.formatted_position) def format(self): self.formatted_position = ( "x coordinate %f" % self.position[0], "y coordinate %f" % self.position[1] ) Now you have this weird dependency where format() communicates with report() by side-effect, and you cannot test format() or display_report() except by modifying the position of the Robot. I see so much OO code written like this, and it is bad, evil, wrong, it sucks and I don't like it! Just a little bit of functional technique makes all the difference: def report(self): self.display_report(self.format(self.position)) def display_report(self, report): print("I'm at %r" % report) def format(self, position): return ("x coordinate %f" % position[0], "y coordinate %f" % position[1] ) Its easier to understand them (less mystery state in the environment), easier to test, and easier to convince yourself that the code is correct. [...] > If monads allow mutations or side effects, they are by definition not > pure functions, and violate your bullet point. Languages like Haskell > have them not because they are an intrinsic part of functional > programming languages, but because they are an intrinsic part of > practical/useful programming languages. More about monads: https://glyph.twistedmatrix.com/2016/02/microblog-607564DA-B525-4489-B337-CED9DDEDC099.html And a little more serious: http://stackoverflow.com/questions/3870088/a-monad-is-just-a-monoid-in-the-category-of-endofunctors-whats-the-issue (despite the funny URL it is actually serious) [...] > Of course it's more than "a language that has functions"; but I'd say > that a more useful comparison would be "languages that require > functional idioms exclusively" vs "languages that support functional > idioms" vs "languages with no functional programming support". Python > is squarely in the second camp, with features like list > comprehensions, map/reduce, etc, but never forcing you to use them. List comps, map/reduce etc are the highest profile and least useful parts of functional programming. The most useful is learning to avoid depending on mutable state in your functions' environment, i.e. global variables, instance attributes, etc. List comps etc are just a means to an end. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Thu Sep 29 00:38:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Sep 2016 14:38:01 +1000 Subject: Is there a way to change the closure of a python function? In-Reply-To: <57ec904b$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <57ec904b$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 29, 2016 at 1:53 PM, Steve D'Aprano wrote: > John Cook suggests that functional programming gets harder and harder to do > right (both for the compiler and for the programmer) as you asymptotically > approach 100% pure, and suggests the heuristic that (say) 85% pure is the > sweet spot: functional in the small, object oriented in the large. > > http://www.johndcook.com/blog/2009/03/23/functional-in-the-small-oo-in-the-large/ > > > I agree. I find that applying functional techniques to individual methods > makes my classes much better: > > - local variables are fine; > - global variables are not; > - global constants are okay; > - mutating the state of the instance should be kept to the absolute minimum; > - and only done from a few mutator methods, not from arbitrary methods; > - attributes should *usually* be passed as arguments to methods, not > treated as part of the environment. I would agree with you. "Functional programming" is not an alternative to imperative or object-oriented programming; it's a style, it's a set of rules, that make small functions infinitely easier to reason about, test, and debug. My points about practicality basically boil down to the same thing as you were saying - 100% pure is infinitely hard. ChrisA From cpxuvs at gmail.com Thu Sep 29 00:47:44 2016 From: cpxuvs at gmail.com (Cpcp Cp) Date: Wed, 28 Sep 2016 21:47:44 -0700 (PDT) Subject: A regular expression question Message-ID: <72d98bd3-48cb-4dd6-827b-2a448dc4310d@googlegroups.com> Look this >>> import re >>> text="asdfnbd]" >>> m=re.sub("n*?","?",text) >>> print m ?a?s?d?f?n?b?d?]? I don't understand the 'non-greedy' pattern. I think the repl argument should replaces every char in text and outputs "????????". From ben+python at benfinney.id.au Thu Sep 29 01:12:06 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 29 Sep 2016 15:12:06 +1000 Subject: A regular expression question References: <72d98bd3-48cb-4dd6-827b-2a448dc4310d@googlegroups.com> Message-ID: <851t03l26x.fsf@benfinney.id.au> Cpcp Cp writes: > Look this > > >>> import re > >>> text="asdfnbd]" > >>> m=re.sub("n*?","?",text) > >>> print m > ?a?s?d?f?n?b?d?]? > > I don't understand the 'non-greedy' pattern. Since ?n*? matches zero or more ?n?s, it matches zero adjacent to every actual character. It's non-greedy because it matches as few characters as will allow the match to succeed. > I think the repl argument should replaces every char in text and > outputs "????????". I hope that helps you understand why that expectation is wrong :-) Regular expression patterns are *not* an easy topic. Try experimenting and learning with . -- \ ?If I haven't seen as far as others, it is because giants were | `\ standing on my shoulders.? ?Hal Abelson | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Thu Sep 29 02:13:01 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 29 Sep 2016 19:13:01 +1300 Subject: Is there a way to change the closure of a python function? In-Reply-To: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> References: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> Message-ID: Paul Moore wrote: > What "allows side effects" in languages like Haskell is the fact that the > runtime behaviour of the language is not defined as "calculating the value of > the main function" but rather as "making the process that the main functon > defines as an abstract monad actually happen". That's an interesting way of looking at it. To put it another way, what matters isn't just the final result, but *how* the final result is arrived at. In the case where the main function never returns, the "final result" doesn't even exist, and all you have left is the process. Philosophical question: Is a function that never returns actually a function? -- Greg From steve+comp.lang.python at pearwood.info Thu Sep 29 02:28:29 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 29 Sep 2016 16:28:29 +1000 Subject: Is there a way to change the closure of a python function? References: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> Message-ID: <57ecb490$0$1600$c3e8da3$5496439d@news.astraweb.com> On Thursday 29 September 2016 16:13, Gregory Ewing wrote: > Philosophical question: Is a function that never > returns actually a function? Mathematically, all functions return, instantly. Or rather, mathematics occurs in an abstract environment where there is no time. Everything happens simultaneously. So even infinite sums or products can be calculated instantly -- if they converge. So, yes, even functions that never return are functions. You just need to collapse all of infinite time into a single instant. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From rustompmody at gmail.com Thu Sep 29 02:47:01 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 28 Sep 2016 23:47:01 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> Message-ID: <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: > On 9/14/2016 3:16 AM, Rustom Mody wrote: > > > In THOSE TYPES that element can justifiably serve as a falsey (empty) type > > > > However to extrapolate from here and believe that ALL TYPES can have a falsey > > value meaningfully, especially in some obvious fashion, is mathematically nonsense. > > Python make no such nonsense claim. By default, Python objects are truthy. > > >>> bool(object()) > True > > Because True is the default, object need not and at least in CPython > does not have a __bool__ (or __len__) method. Classes with no falsey > objects, such as functions, generators, and codes, need not do anything > either. In the absence of an override function, the internal bool code > returns True. > Not sure what you are trying to say Terry... Your English suggests you disagree with me Your example is exactly what I am saying; if a type has a behavior in which all values are always True (true-ish) its a rather strange kind of bool-nature. Shall we say it has Buddha-nature? ;-) > It is up to particular classes to override that default and say that it > has one or more Falsey objects. They do so by defining a __bool__ > method that returns False for the falsey objects (and True otherwise) or > by defining a __len__ method that returns int 0 for falsey objects (and > non-0 ints otherwise). If a class defines both, __bool__ wins. Sure one can always (ok usually) avoid a bug in a system by not using the feature that calls up the bug. Are you suggesting that that makes the bug non-exist? In more detail: - If user/programmer defines a new type - Which has no dunder bool - Which has no dunder len - Which has no ... (all the other things like len that can make for a non-trivial bool behavior) - And then uses a value of that type in a non-trivial bool-consuming position such as the condition of an if/while etc There's a very good chance that bool-usage is buggy In more mundane terms, dunder bool defaulting to true is about as useful as if it defaulted to 2*random.random() Why not default it in the way that AttributeError/NameError/TypeError etc are raised? From rosuav at gmail.com Thu Sep 29 03:53:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Sep 2016 17:53:23 +1000 Subject: Expression can be simplified on list In-Reply-To: <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> Message-ID: On Thu, Sep 29, 2016 at 4:47 PM, Rustom Mody wrote: >> Because True is the default, object need not and at least in CPython >> does not have a __bool__ (or __len__) method. Classes with no falsey >> objects, such as functions, generators, and codes, need not do anything >> either. In the absence of an override function, the internal bool code >> returns True. >> > Not sure what you are trying to say Terry... > Your English suggests you disagree with me > Your example is exactly what I am saying; if a type has a behavior in which > all values are always True (true-ish) its a rather strange kind of bool-nature. > > Shall we say it has Buddha-nature? ;-) There are a LOT of objects that are always true. Take this example: class Employee: def __init__(self, name): self.name = name self.boss = None def report(self): if self.boss: self.boss.emit_report("I have done nothing.") else: company_board.proclaim("I have done everything.") Every Employee object counts as true, and None counts as false. This is the most normal way to write something. Unless an object represents a collection, number, etc, that can meaningfully be "empty", it should be assumed that it is true, and *the absence of an object* is what's false. Not every object has a sane representation of nothingness. ChrisA From steve+comp.lang.python at pearwood.info Thu Sep 29 04:14:32 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 29 Sep 2016 18:14:32 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> Message-ID: <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> On Thursday 29 September 2016 16:47, Rustom Mody wrote: > On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: [...] >> Python make no such nonsense claim. By default, Python objects are truthy. >> >> >>> bool(object()) >> True >> >> Because True is the default, object need not and at least in CPython >> does not have a __bool__ (or __len__) method. Classes with no falsey >> objects, such as functions, generators, and codes, need not do anything >> either. In the absence of an override function, the internal bool code >> returns True. >> > Not sure what you are trying to say Terry... > Your English suggests you disagree with me > Your example is exactly what I am saying; if a type has a behavior in which > all values are always True (true-ish) its a rather strange kind of > bool-nature. In what way do you think it is "rather strange"? This suggests that you believe that all types must have distinct truthy values and falsey values, or else that type's values shouldn't be usable in a truth context at all. Is that what you mean? My view is somewhat different. I see truthiness as an abstraction. Like all abstractions, it may leak -- I make no apologies for the fact that Python doesn't have syntactic support for Keene three-value logic or other multi- valued logics, nor do I make any apologies for the (hypothetical, rare) object which doesn't fit well into this truthy abstraction. All abstractions leak somewhere, and this abstraction is proven to work well in practice, not withstanding the rare glitch. What is this truthiness abstraction? It is the difference between "something" and "nothing". Values which represent nothing, e.g.: - None - numeric zero: 0, 0.0, 0j, Decimal(0) etc - empty strings u'', '' - empty containers [], (), {} etc. are treated as falsey. And values that represent something, e.g.: - numbers other than zero - strings other than the empty string - non-empty containers are treated as truthy. On this basis, by default objects should be considered truthy: objects represent something rather than nothing: - a module object is something; - a function object is something; - a HTTPServer object is something; and so all of these things -- modules, functions, HTTPServers -- should default to always truthy unless the programmer specifically programs them otherwise. A few pre-emptive responses to possible objections: Objection: There's only one sort of nothing. Response: There are different kinds of nothing. "I have no shoes" is not the same as "I have no feet". The hole in a donut is not the same as a hole in the ground or an electron hole in a crystal lattice. The set of ideas held by somebody who has no idea is not the same kind of nothingness as the nothingness in a vacuum. Objection: But nothing isn't nothing, it's something! Response: You are committing the fallacy of reification. Just because you can give a name to a concept doesn't make the concept a thing. "Cold" is not a thing, it is just the absence of heat, "death" is the absence of life, "stillness" is the absence of motion, and "nothing" is the absence of things, not a thing itself. That's why there are different kinds of nothing -- it depends which things get counted. Objection: Even the vacuum is not empty! It is filled with a sea of virtual particles and anti-particles and zero-point energy. Response: I've studied quantum mechanics and particle physics too. You're very clever. Do I really have to answer this one? Objection: Yes. Response: Okay. The existence of zero-point energy is very interesting, but it has no relevance to the topic we're discussing. In practical terms, most "zeroes" are relative measures, not absolute. For an electrical analogy, think of electrical potential: what matters is the potential difference, not the actual potential. There's no current flowing between two points both at the same potential energy. Similarly, we don't usually care about the *absolute* presence or absence of things, but relative to some quantity or substance. A hole in the ground is filled with air, or sometimes water, but we care only about the lack of soil in the hole. Objections: Empty containers aren't nothing, they are themselves a thing. An empty egg carton is still an empty carton, even if there are no eggs in it. Response: Indeed. Nevertheless, the language designer gets to choose the specific model of truthiness the language uses. In the opinion of the Python designer GvR, it is more useful to care about the *content* of the container than the container itself in a truth context. Some languages make other choices. If you don't like Python's choice, you are free to: - suck it up and live with it; - fork Python and give the fork your preferred semantics; - use another language which is a closer fit to your preferences; - use your own container types with your preferred semantics; - complain bitterly about it on your blog, Facebook wall, mailing lists etc.; - buy an automatic weapon and make GvR pay for disagreeing with you; etc. although some of these choices are better than others. [...] > Sure one can always (ok usually) avoid a bug in a system by not using the > feature that calls up the bug. Are you suggesting that that makes the bug > non-exist? You haven't demonstrated that the existence of a feature is a bug. > In more detail: > - If user/programmer defines a new type > - Which has no dunder bool > - Which has no dunder len > - Which has no ... (all the other things like len that can make for a > non-trivial bool behavior) > - And then uses a value of that type in a non-trivial bool-consuming position > such as the condition of an if/while etc then they get the default behaviour, just as they get the default behaviour if they call str() or repr() on their object without defining their own __str__ or __repr__ methods, or if you call == without providing a custom __eq__ method. > There's a very good chance that bool-usage is buggy I doubt it. > In more mundane terms, dunder bool defaulting to true is about as useful > as if it defaulted to > 2*random.random() No, not all. There is a consistent model and predicable effects from defaulting to true. There is no consistent model from defaulting to 2*random(). (Although, since that is **nearly always** a truthy value, it probably makes no practical difference: the object will be falsey only about 1 time in 2**60 or 2**61). > Why not default it in the way that AttributeError/NameError/TypeError etc > are raised? Because that would be less useful and more annoying. There are a set of behaviours which nearly all objects should define, and which are nearly always the same (or at least have a sensible default): __getattribute__ __getattr__ __setattr__ __delattr__ __str__ __repr__ __eq__ __ne__ __hash__ __bool__ etc. Since the behaviour is nearly always the same, it makes sense to move that behaviour into the base class object(), and let the exceptional cases be exceptional, rather than require everybody to write the same piece of code over and over and over again. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From p.f.moore at gmail.com Thu Sep 29 04:35:41 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 29 Sep 2016 01:35:41 -0700 (PDT) Subject: Using the Windows "embedded" distribution of Python In-Reply-To: References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> Message-ID: <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> On Wednesday, 28 September 2016 21:50:54 UTC+1, eryk sun wrote: > On Wed, Sep 28, 2016 at 2:35 PM, Paul Moore wrote: > > So I thought I'd try SetDllDirectory. That works for python36.dll, but if I load > > python3.dll, it can't find Py_Main - the export shows as "(forwarded to > > python36.Py_Main)", maybe the forwarding doesn't handle SetDllDirectory? > > It works for me. Are you calling SetDllDirectory with the > fully-qualified path? If not it's relative to the working directory, > which isn't necessarily (generally is not) the application directory, > in which case delay-loading python36.dll will fail. You can create the > fully-qualified path from the application path, i.e. > GetModuleFileNameW(NULL, ...). That might be the issue. I was using a relative directory (I was being lazy for a quick test) but I was at the time in the right directory for the relative directory name to work. But I'll do a proper test today. > That said, I prefer using LoadLibraryExW(absolute_path_to_python3, > NULL, LOAD_WITH_ALTERED_SEARCH_PATH). The alternate search substitutes > the DLL's directory for the application directory when loading > dependent DLLs, which allows loading python36.dll and vcruntime140.dll > without having to modify the DLL search path of the entire process. That does indeed sound like a better idea. I had read the docs for LoadLibraryEx, but I must admit I got very muddled from the various options, and ended up going back to LoadLibrary because it seemed simpler :-( Thanks for the suggestions, Paul PS It's a shame there's no way to put the embedded distribution in a subdirectory *without* needing to use dynamic loading, but I guess that's basically an OS limitation. From jussi.piitulainen at helsinki.fi Thu Sep 29 04:45:51 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 29 Sep 2016 11:45:51 +0300 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> Message-ID: Steven D'Aprano writes: [- -] > What is this truthiness abstraction? It is the difference between > "something" and "nothing". > > Values which represent nothing, e.g.: > > - None > - numeric zero: 0, 0.0, 0j, Decimal(0) etc > - empty strings u'', '' > - empty containers [], (), {} etc. > > are treated as falsey. And values that represent something, e.g.: [- -] What do you say about things like iterators and generators? I'd say they are containers, but they count as true even when they are empty. bool(x for x in [3,1] if x in [2,7]) # True list(x for x in [3,1] if x in [2,7]) # [] I think the abstraction really leaks on these things. From lawrencedo99 at gmail.com Thu Sep 29 05:18:57 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 29 Sep 2016 02:18:57 -0700 (PDT) Subject: Is there a way to change the closure of a python function? In-Reply-To: References: <9819197a-01cb-4553-a148-42665b3f8550@googlegroups.com> Message-ID: <97189788-2e33-441b-93a5-a354154c7378@googlegroups.com> On Thursday, September 29, 2016 at 7:13:15 PM UTC+13, Gregory Ewing wrote: > Philosophical question: Is a function that never > returns actually a function? Denotational semantics calls that value ?bottom?. From rosuav at gmail.com Thu Sep 29 05:19:26 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Sep 2016 19:19:26 +1000 Subject: Expression can be simplified on list In-Reply-To: References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Sep 29, 2016 at 6:45 PM, Jussi Piitulainen wrote: > What do you say about things like iterators and generators? I'd say they > are containers, but they count as true even when they are empty. > > bool(x for x in [3,1] if x in [2,7]) # True > list(x for x in [3,1] if x in [2,7]) # [] > > I think the abstraction really leaks on these things. The problem is that there is no safe way to probe an iterator for emptiness other than to attempt to consume a value from it. How do you know if you're at the EOF of stdin? You ask the user to enter something, and see if s/he presses Ctrl-D (or Ctrl-Z). Until you wait on the user, EOF hasn't necessarily even happened yet. An iterator is not a container, but in many contexts, it can be treated as one. Truthiness is simply not one of those contexts, for reasons of extreme impracticality. ChrisA From lawrencedo99 at gmail.com Thu Sep 29 05:21:25 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 29 Sep 2016 02:21:25 -0700 (PDT) Subject: Expression can be simplified on list In-Reply-To: <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> Message-ID: On Thursday, September 29, 2016 at 7:48:41 PM UTC+13, Rustom Mody wrote: > - And then uses a value of that type in a non-trivial bool-consuming position > such as the condition of an if/while etc > > There's a very good chance that bool-usage is buggy ? From eryksun at gmail.com Thu Sep 29 05:38:11 2016 From: eryksun at gmail.com (eryk sun) Date: Thu, 29 Sep 2016 09:38:11 +0000 Subject: Using the Windows "embedded" distribution of Python In-Reply-To: <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> Message-ID: On Thu, Sep 29, 2016 at 8:35 AM, Paul Moore wrote: > PS It's a shame there's no way to put the embedded distribution in a subdirectory > *without* needing to use dynamic loading, but I guess that's basically an OS limitation. There are ways to do this. The simplest way is to use a subdirectory with same name as the executable plus ".local". For example, for "app.exe" create a directory named "app.exe.local". From steve+comp.lang.python at pearwood.info Thu Sep 29 05:49:36 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 29 Sep 2016 19:49:36 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> Message-ID: <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> On Thursday 29 September 2016 18:45, Jussi Piitulainen wrote: > Steven D'Aprano writes: > > [- -] > >> What is this truthiness abstraction? It is the difference between >> "something" and "nothing". >> >> Values which represent nothing, e.g.: >> >> - None >> - numeric zero: 0, 0.0, 0j, Decimal(0) etc >> - empty strings u'', '' >> - empty containers [], (), {} etc. >> >> are treated as falsey. And values that represent something, e.g.: > > [- -] > > What do you say about things like iterators and generators? I'd say they > are containers, but they count as true even when they are empty. No, they aren't containers, because they don't support membership testing or len(), as containers must. But I agree the abstraction leaks. We would like empty iterables (iterators and sequences) to be falsey, but the problem is, how do you know if an iterator is empty without consuming a value from it? Sequences and containers can be probed without consuming values, but iterators cannot be. So although you can use them in many of the same places that you might use a sequence or container, they aren't actually sequences or containers, and are better treated as something like a function. (Except instead of calling them, you pass them to next() to get the next value.) And what are functions? Why, they're *things*, of course, and hence *something* rather than nothing, even if they return None, or never return at all, or crash. And so even though it is inconvenient, nevertheless it is logical for iterators to always be truthy. However, if you had a peekable iterator where you can peek ahead to see if they are empty or not, then it might make sense to treat them as more like a sequence than a function. But arbitrary iterators do not support a peek() operation. Either way, the abstraction leaks a bit. Never mind -- welcome to life as a programmer. -- Steven git gets easier once you get the basic idea that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space. From p.f.moore at gmail.com Thu Sep 29 06:41:19 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 29 Sep 2016 03:41:19 -0700 (PDT) Subject: Using the Windows "embedded" distribution of Python In-Reply-To: References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> Message-ID: <6cf0cac1-d569-41f4-a693-d393203bc66d@googlegroups.com> On Thursday, 29 September 2016 10:39:10 UTC+1, eryk sun wrote: > On Thu, Sep 29, 2016 at 8:35 AM, Paul Moore wrote: > > PS It's a shame there's no way to put the embedded distribution in a subdirectory > > *without* needing to use dynamic loading, but I guess that's basically an OS limitation. > > There are ways to do this. The simplest way is to use a subdirectory > with same name as the executable plus ".local". For example, for > "app.exe" create a directory named "app.exe.local". Oh, wow. Now you mention it, I recall that convention (from somewhere). I'll investigate that option (although it may not suit my use case, as I want multiple exes in the one "main" directory sharing a single "local" Python runtime). Many thanks, Paul From ned at nedbatchelder.com Thu Sep 29 06:45:39 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 29 Sep 2016 03:45:39 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <3e2d0652-85a8-4a4b-ad75-d50e3f049024@googlegroups.com> References: <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> <3e2d0652-85a8-4a4b-ad75-d50e3f049024@googlegroups.com> Message-ID: <43f34c1f-34d0-4a20-9312-228783638f57@googlegroups.com> On Wednesday, September 28, 2016 at 8:00:09 PM UTC-4, Lawrence D?Oliveiro wrote: > On Thursday, September 29, 2016 at 11:54:46 AM UTC+13, Emile van Sebille wrote: > > Which worked for me! You should try it. Sloppy programming has always > > been unreliable. > > So it is clear you don?t have an answer to the OP?s question after all. Just some vague, meaningless generalities. This is just getting rude. Let's please drop it. --Ned. From python at mrabarnett.plus.com Thu Sep 29 07:53:30 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 29 Sep 2016 12:53:30 +0100 Subject: Expression can be simplified on list In-Reply-To: <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> Message-ID: On 2016-09-29 10:49, Steven D'Aprano wrote: > On Thursday 29 September 2016 18:45, Jussi Piitulainen wrote: [snip] >> What do you say about things like iterators and generators? I'd say they >> are containers, but they count as true even when they are empty. > > No, they aren't containers, because they don't support membership testing or > len(), as containers must. > > But I agree the abstraction leaks. We would like empty iterables (iterators and > sequences) to be falsey, but the problem is, how do you know if an iterator is > empty without consuming a value from it? Sequences and containers can be probed > without consuming values, but iterators cannot be. > > So although you can use them in many of the same places that you might use a > sequence or container, they aren't actually sequences or containers, and are > better treated as something like a function. (Except instead of calling them, > you pass them to next() to get the next value.) > > And what are functions? Why, they're *things*, of course, and hence *something* > rather than nothing, even if they return None, or never return at all, or > crash. And so even though it is inconvenient, nevertheless it is logical for > iterators to always be truthy. > > However, if you had a peekable iterator where you can peek ahead to see if they > are empty or not, then it might make sense to treat them as more like a > sequence than a function. But arbitrary iterators do not support a peek() > operation. > > Either way, the abstraction leaks a bit. Never mind -- welcome to life as a > programmer. > What if an _exhausted_ iterator was falsey? From eryksun at gmail.com Thu Sep 29 07:55:26 2016 From: eryksun at gmail.com (eryk sun) Date: Thu, 29 Sep 2016 11:55:26 +0000 Subject: Using the Windows "embedded" distribution of Python In-Reply-To: <6cf0cac1-d569-41f4-a693-d393203bc66d@googlegroups.com> References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> <6cf0cac1-d569-41f4-a693-d393203bc66d@googlegroups.com> Message-ID: On Thu, Sep 29, 2016 at 10:41 AM, Paul Moore wrote: > On Thursday, 29 September 2016 10:39:10 UTC+1, eryk sun wrote: >> On Thu, Sep 29, 2016 at 8:35 AM, Paul Moore wrote: >> > PS It's a shame there's no way to put the embedded distribution in a subdirectory >> > *without* needing to use dynamic loading, but I guess that's basically an OS limitation. >> >> There are ways to do this. The simplest way is to use a subdirectory >> with same name as the executable plus ".local". For example, for >> "app.exe" create a directory named "app.exe.local". > > Oh, wow. Now you mention it, I recall that convention (from somewhere). I'll > investigate that option (although it may not suit my use case, as I want multiple exes > in the one "main" directory sharing a single "local" Python runtime). In that case you can use an application manifest with a dependent assembly. Say embedded Python 3.6 is in the "py3embed" subdirectory. Add the following manifest file to that directory: py3embed.manifest: Add this assembly as a dependency in the application manifest, either embedded in the executable (resource #1) or as a separate file named the same as the executable plus ".manifest", e.g. "app.exe.manifest". You can start with the manifest that's used by python.exe, from PC\python.manifest. From __peter__ at web.de Thu Sep 29 08:11:07 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 29 Sep 2016 14:11:07 +0200 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> Message-ID: MRAB wrote: > What if an _exhausted_ iterator was falsey? Many would expect it = iter("abc") while it: print(next(it)) to work (i. e. no StopIteration) -- if it doesn't, what's the actual usecase? If it does work there must be some lookahead which not all iterators can provide in a meaningful way: it = iter(time.time, None) while it: time.sleep(...) print("Now", next(it)) From Redacted Thu Sep 29 08:52:59 2016 From: Redacted (Redacted) Date: Thu, 29 Sep 2016 05:52:59 -0700 (PDT) Subject: Redacted In-Reply-To: References: Message-ID: <9c8e533a-5459-4a0b-85a9-88f32bf4d8cd@googlegroups.com> Redacted From tismer at stackless.com Thu Sep 29 09:52:13 2016 From: tismer at stackless.com (Christian Tismer) Date: Thu, 29 Sep 2016 15:52:13 +0200 Subject: ANN: dedent 0.5 released Message-ID: <6efc4a42-4855-470f-033e-f57e16e32df8@stackless.com> Dedent 0.5 ========== What is it? ----------- Dedent is a very simple tool for those people who like to indent their inline code nicely. For those who got already what it is, stop reading. :-) All the others: What is it, really? ------------------- Ok, think of some inline Python code, something like $ python -c """some code""" For very simple scripts, there is nothing wrong with it. But for inline code over several lines, things become ugly: $ python -c """ "The problem is that you have to start your" "script very much on the left, although you" "would probably like to indent it somehow." One very ugly solution are constructs like """if True: "now I may indent the code" """ This becomes even more ugly if you have to use the __future__ statement, which always must come first! Now, here is what dedent does for you, simply that, not less and not more: $ python -m dedent """ from __future__ import print_function "now I can really indent my code, because" "the dedent module takes care of the indent," "and that was my intent. :-)" """ Installation ------------ $ pip install dedent That's all, folks! Have fun. p.s.: Why is that not build in by default? -- Christian Tismer :^) tismer at stackless.com Software Consulting : http://www.stackless.com/ Karl-Liebknecht-Str. 121 : https://github.com/PySide 14482 Potsdam : GPG key -> 0xFB7BEE0E phone +49 173 24 18 776 fax +49 (30) 700143-0023 From p.f.moore at gmail.com Thu Sep 29 10:03:36 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 29 Sep 2016 07:03:36 -0700 (PDT) Subject: Using the Windows "embedded" distribution of Python In-Reply-To: References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> <6cf0cac1-d569-41f4-a693-d393203bc66d@googlegroups.com> Message-ID: <5c5ae794-948d-4a2b-bafb-e7131424b816@googlegroups.com> On Thursday, 29 September 2016 12:56:28 UTC+1, eryk sun wrote: >> Oh, wow. Now you mention it, I recall that convention (from somewhere). >> I'll investigate that option (although it may not suit my use case, as >> I want multiple exes in the one "main" directory sharing a single >> "local" Python runtime). > > In that case you can use an application manifest with a dependent > assembly. Say embedded Python 3.6 is in the "py3embed" subdirectory. > Add the following manifest file to that directory: > > py3embed.manifest: > > > > version="3.6.111.1013" > type="win32" > processorArchitecture="amd64" /> > > > > Cool. So this is all the SxS stuff that I never really understood, right? :-) I guess I can assume from this: 1. The filename py3embed.manifest isn't relevant (you explain file naming below). 2. assemblyIdentity name="py3embed" is what says to look in a subdirectory "py3embed" that's located next to the executable. 3. The "version" in the manifest doesn't really matter much. 4. I only need to name python3.dll, python36.dll and vcruntime140.dll as these are the only DLLs loaded statically? > Add this assembly as a dependency in the application manifest, either > embedded in the executable (resource #1) or as a separate file named > the same as the executable plus ".manifest", e.g. "app.exe.manifest". Using a separate file seems easiest (and certainly the way to go for testing) but I'm not sure how I'd embed the manifest using command line tools. I'm leveraging distutils to build my exe at the moment: from distutils.ccompiler import new_compiler import distutils.sysconfig import sys import os cc = new_compiler() exe = 'myapp' cc.add_include_dir(distutils.sysconfig.get_python_inc()) cc.add_library_dir(os.path.join(sys.base_exec_prefix, 'libs')) objs = cc.compile(['myapp.c']) cc.link_executable(objs, exe) But the ccompiler interface doesn't have anything to add in a resource or manifest, so I think I'm going to need to switch to using the command line directly for this. > You can start with the manifest that's used by python.exe, from > PC\python.manifest. > > > > version="3.6.111.1013" > type="win32" > processorArchitecture="amd64" /> > > Thanks for your help on this. My C skills are *very* rusty (going much beyond "cl /c foo.c" sends me to the manuals these days) so I appreciate all the help. I'm off now to do a whole load of experimenting - you've given me a lot to work with :-) Paul. PS Is there any readable documentation on the SxS stuff anywhere, written for C programmers? Microsoft's docs have always seemed to me to assume I know a bunch of .NET concepts that I really don't know much about... From ivanjankovic777777 at gmail.com Thu Sep 29 11:20:28 2016 From: ivanjankovic777777 at gmail.com (ivan77) Date: Thu, 29 Sep 2016 08:20:28 -0700 (PDT) Subject: SOAP XML webserver in Python/Django Message-ID: <060d5646-dba6-4191-a70c-fffd0fa951c2@googlegroups.com> Hi All, I currently have a need to setup a webserver on one of our internal servers that is going to send and receive XML SOAP responses to an external company through a VPN. It seems like something that I could use python (maybe even Django) for. However, even though I have been using Python and Django for a while now, I am unsure of whether this is a good idea to implement, since there seems to be some question about whether there are good maintained libraries to use and I am unfamiliar with if there are added complexities with SOAP that I have to deal with. It looks like pretty standard XML to me wrapped in an extra layer of meta data. http://stackoverflow.com/questions/206154/what-soap-client-libraries-exist-for-python-and-where-is-the-documentation-for?rq=1 Any thoughts would be appreciated. Also, any good Python based job boards in the Toronto area would be greatly appreciated too. Regards Ivan From mail at timgolden.me.uk Thu Sep 29 11:30:34 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 29 Sep 2016 16:30:34 +0100 Subject: Abusive Italian Spam Message-ID: You may have noticed one or two more of the abusive spam messages slip through onto the list. We do have traps for these but, as with most such things, they need tuning. (We've discarded many more than you've seen). As ever, kudos to Mark Sapiro of the Mailman team for tweaking our custom filters and sorting out the archives in a timely fashion. TJG From steve+python at pearwood.info Thu Sep 29 11:56:05 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 30 Sep 2016 01:56:05 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> Message-ID: <57ed3997$0$22141$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: > What if an _exhausted_ iterator was falsey? The problem is that in general you can't tell if an iterator is exhausted until you attempt to advance it. So even if bool(iterator) returns True, the call to next() may raise StopIteration: def gen(): yield 1 it = gen() bool(it) # returns True next(it) # returns a value, as expected, exhausting the iterator bool(it) # still returns True even though its exhausted next(it) # raises StopIteration bool(it) # finally we know the iterator is exhausted Again, the problem is the lack of a way for the iterator to peek ahead and see whether or not there is anything remaining. *We* can see that it is exhausted by reading the source code and predicting what will happen on the subsequent call to next(), but the interpreter cannot do that. And sometimes not even we can predict the state of the iterator: def gen(): if random.random() < 0.5: yield 1 it = gen() Is it exhausted or not? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Thu Sep 29 12:36:55 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 29 Sep 2016 17:36:55 +0100 Subject: Expression can be simplified on list In-Reply-To: <57ed3997$0$22141$c3e8da3$5496439d@news.astraweb.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> <57ed3997$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9379004a-f454-e6d6-520a-12da796cc4bb@mrabarnett.plus.com> On 2016-09-29 16:56, Steve D'Aprano wrote: > On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: > >> What if an _exhausted_ iterator was falsey? > > > The problem is that in general you can't tell if an iterator is exhausted > until you attempt to advance it. So even if bool(iterator) returns True, > the call to next() may raise StopIteration: > [snip] By "exhausted" I meant "has previously raised StopIteration". From rosuav at gmail.com Thu Sep 29 12:44:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Sep 2016 02:44:36 +1000 Subject: Expression can be simplified on list In-Reply-To: <9379004a-f454-e6d6-520a-12da796cc4bb@mrabarnett.plus.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> <57ed3997$0$22141$c3e8da3$5496439d@news.astraweb.com> <9379004a-f454-e6d6-520a-12da796cc4bb@mrabarnett.plus.com> Message-ID: On Fri, Sep 30, 2016 at 2:36 AM, MRAB wrote: > On 2016-09-29 16:56, Steve D'Aprano wrote: >> >> On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: >> >>> What if an _exhausted_ iterator was falsey? >> >> >> >> The problem is that in general you can't tell if an iterator is exhausted >> until you attempt to advance it. So even if bool(iterator) returns True, >> the call to next() may raise StopIteration: >> > [snip] > > By "exhausted" I meant "has previously raised StopIteration". I'm not sure how useful that'd be, especially given that some iterators actually violate the normal rule of "once you raise, you raise thereafter". But it's not hard to wrap. class Iterator: def __init__(self, it): self.iter = iter(it) self.exhausted = False def __iter__(self): return self def __next__(self): try: return next(self.iter) except StopIteration: # or just 'except:'? self.exhausted = True raise def __bool__(self): return self.exhausted Then you have the edge cases. If next() raises something other than StopIteration, does that mark the iterator as exhausted? Should the exhausted flag be cleared if a naughty iterator yields a value after having StoppedIteration? (Also, you'd probably want to have some code in here to detect if it's working with a generator, and if so, pass send/throw down the line too. Omitted for simplicity.) ChrisA From python at mrabarnett.plus.com Thu Sep 29 12:47:10 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 29 Sep 2016 17:47:10 +0100 Subject: Expression can be simplified on list In-Reply-To: <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> Message-ID: <67e0bcaa-1e4f-0e60-4911-2fd7b869b25e@mrabarnett.plus.com> On 2016-09-29 09:14, Steven D'Aprano wrote: > On Thursday 29 September 2016 16:47, Rustom Mody wrote: > >> On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: > [...] >>> Python make no such nonsense claim. By default, Python objects are truthy. >>> >>> >>> bool(object()) >>> True >>> >>> Because True is the default, object need not and at least in CPython >>> does not have a __bool__ (or __len__) method. Classes with no falsey >>> objects, such as functions, generators, and codes, need not do anything >>> either. In the absence of an override function, the internal bool code >>> returns True. >>> >> Not sure what you are trying to say Terry... >> Your English suggests you disagree with me >> Your example is exactly what I am saying; if a type has a behavior in which >> all values are always True (true-ish) its a rather strange kind of >> bool-nature. > > In what way do you think it is "rather strange"? > > This suggests that you believe that all types must have distinct truthy values > and falsey values, or else that type's values shouldn't be usable in a truth > context at all. Is that what you mean? > > My view is somewhat different. I see truthiness as an abstraction. Like all > abstractions, it may leak -- I make no apologies for the fact that Python > doesn't have syntactic support for Keene three-value logic or other multi- > valued logics, nor do I make any apologies for the (hypothetical, rare) object > which doesn't fit well into this truthy abstraction. All abstractions leak > somewhere, and this abstraction is proven to work well in practice, not > withstanding the rare glitch. > [snip] When re.search or re.match succeed, they return a match object, which is truey; when they fail, then return None, which is falsey. That's convenient. From tjreedy at udel.edu Thu Sep 29 14:10:04 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Sep 2016 14:10:04 -0400 Subject: Expression can be simplified on list In-Reply-To: <9379004a-f454-e6d6-520a-12da796cc4bb@mrabarnett.plus.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <57eccd69$0$2746$c3e8da3$76491128@news.astraweb.com> <57ece3b2$0$2791$c3e8da3$76491128@news.astraweb.com> <57ed3997$0$22141$c3e8da3$5496439d@news.astraweb.com> <9379004a-f454-e6d6-520a-12da796cc4bb@mrabarnett.plus.com> Message-ID: On 9/29/2016 12:36 PM, MRAB wrote: > On 2016-09-29 16:56, Steve D'Aprano wrote: >> On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: >> >>> What if an _exhausted_ iterator was falsey? Logic is about binary distinctions, rather than about 'truth'. For non-buggy iterator it, the useful binary distinction is whether next(it) returns an object, the truthy action, or raises StopIteration, the falsey action. The for loop machinery converts this binary action distinction into another binary action distinction: execute the suite and call next again versus proceed to the else clause if there is one or do nothing. In other words, for loops indeed treat an exhausted iterator as falsey. >> The problem is that in general you can't tell if an iterator is exhausted >> until you attempt to advance it. So even if bool(iterator) returns True, >> the call to next() may raise StopIteration: >> > [snip] > > By "exhausted" I meant "has previously raised StopIteration". The iterator protocol could have required that iterators have 'self._bval = True' in .__init__, method 'def __bool__(self): return self._bval, and 'self._bval = False' in .__next__ just prior to 'raise StopIteration'. However, the iterator protocol is intentionally as simple as possible and the extra baggage would nearly always be useless. If you use a non-iterator iterable in a for statement, the temporary iterator is discarded as soon as it raises StopIteration. If you pass an iterator to a function that iterates, you likely created it on the fly as an expression, and it will be discarded when the function returns. If you do have a reference, you can (and perhaps should) delete it after the function returns. Still, if one has a specialized use-case for iterables with the extra baggage, one can create them as instances of the following wrapper. class BoolIter: def __init__(self, iterable): self._it = iter(iterable) self._bval = True def __iter__(self): return self def __bool__(self): return self._bval def __next__(self): try: return next(self._it) except StopIteration: self._bval = False raise -- Terry Jan Reedy From lawrencedo99 at gmail.com Thu Sep 29 15:18:55 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 29 Sep 2016 12:18:55 -0700 (PDT) Subject: how to automate java application in window using python In-Reply-To: <43f34c1f-34d0-4a20-9312-228783638f57@googlegroups.com> References: <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> <3e2d0652-85a8-4a4b-ad75-d50e3f049024@googlegroups.com> <43f34c1f-34d0-4a20-9312-228783638f57@googlegroups.com> Message-ID: On Thursday, September 29, 2016 at 11:46:59 PM UTC+13, Ned Batchelder wrote: > This is just getting rude. Let's please drop it. Do you have anything substantive to contribute? (... crickets ...) From namenobodywants at gmail.com Thu Sep 29 15:29:05 2016 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Thu, 29 Sep 2016 12:29:05 -0700 (PDT) Subject: unintuitive for-loop behavior Message-ID: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> hello pythonistas i've had a nodding acquaintance with python for some time, and all along i assumed that for-loops got a namespace of their own; now i'm reading up on the language and i find out that's not the case: the loop variable gets put into the enclosing namespace, overwriting any former value that was already there; of course i realize there are situations where one is interested in the value that a loop variable has after the loop has been exited, but this behavior seems grossly unintuitive to me: has there ever been any discussion of giving for-loops the option of running in namespaces of their own? and it gets even worse; consider the following means of raising an exception: #)-------------------------------------- begin code def powerfunction(exponent): return lambda base: (base ** exponent) p1 = [powerfunction(exponent) for exponent in range(9)] p2 = [lambda base: (base ** exponent) for exponent in range(9)] assert p1[3](4) == p2[3](4) #)---------------------------------------- end code apparently the problem is that "exponent" gets evaluated when the relevant lambda function is run, not when it's defined, but no binding for "exponent" gets put into the enclosing namespace: it seems that python remembers this ghostly "exponent" for me on the theory that i don't WANT "p1" and "p2" to be the same; can anyone help to reconcile me to this semantics? thanks if you can help stm From tjreedy at udel.edu Thu Sep 29 15:42:58 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Sep 2016 15:42:58 -0400 Subject: Expression can be simplified on list In-Reply-To: <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> Message-ID: On 9/29/2016 2:47 AM, Rustom Mody wrote: > On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: >> On 9/14/2016 3:16 AM, Rustom Mody wrote: >> >>> In THOSE TYPES that element can justifiably serve as a falsey (empty) type >>> >>> However to extrapolate from here and believe that ALL TYPES can have a falsey >>> value meaningfully, especially in some obvious fashion, is mathematically nonsense. There is no end to possible nonsensical extrapolations. I presume you had a reason to point out this one. >> Python make no such nonsense claim. By default, Python objects are truthy. >> >> >>> bool(object()) >> True >> >> Because True is the default, object need not and at least in CPython >> does not have a __bool__ (or __len__) method. Classes with no falsey >> objects, such as functions, generators, and codes, need not do anything >> either. In the absence of an override function, the internal bool code >> returns True. >> > Not sure what you are trying to say Terry... I reported how CPython's bool works, after doing some experiments. > Your English suggests you disagree with me I disagree with a possible implication of your statement, that Python bools are based on a nonsensical belief. It does not matter much to what I said whether you intended that implication or not. > Your example is exactly what I am saying; if a type has a behavior in which > all values are always True (true-ish) its a rather strange kind of bool-nature. Your conclusion from the examples is slightly different from mine. >> It is up to particular classes to override that default and say that it >> has one or more Falsey objects. They do so by defining a __bool__ >> method that returns False for the falsey objects (and True otherwise) or >> by defining a __len__ method that returns int 0 for falsey objects (and >> non-0 ints otherwise). If a class defines both, __bool__ wins. More reporting on how CPython works, based on experiments. For the last statement, I tried giving a class contradictory methods. > Sure one can always (ok usually) avoid a bug in a system by not using the > feature that calls up the bug. Are you suggesting that that makes the bug non-exist? By 'bug', you here mean 'design bug', as opposed to 'implementation bug'. Design bugs are in the eyes of beholders. Here, we behold differently. Logic is about binary predicates/partitions/decisions. Bool allows a class to define a default partition for use in conditional expressions by defining a __bool__ method. > In more detail: > - If user/programmer defines a new type > - Which has no dunder bool > - Which has no dunder len A subclass of such a class might add either of those methods. Indeed, 'object' is such a class and *some* subclasse* do add one or the other. Or, with duck-typing, the class might part of a function domain that does include partitioned classes. > - And then uses a value of that type in a non-trivial bool-consuming position > such as the condition of an if/while etc > > There's a very good chance that bool-usage is buggy I agree that 'if self' when self is essentially guaranteed to be truthy is bad coding. Redundant or dead code may be a bad idea, but is not buggy in itself in the usual sense. > Why not default it in the way that AttributeError/NameError/TypeError etc > are raised? Try - except and exceptions are an alternate flow system that partition the behavior of functions + arguments. It would be annoying to mix the two and require (most) every if and while statement to be embedded in try - except. -- Terry Jan Reedy From 007brendan at gmail.com Thu Sep 29 15:55:14 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Thu, 29 Sep 2016 12:55:14 -0700 Subject: unintuitive for-loop behavior In-Reply-To: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> Message-ID: Yes, loops don't have their own scope. Indeed, very few flow elements in python -- if, with, try/except -- create a new scope. In that sense, it's fairly consistent, but can be unexpected for people that have used languages with many nested scopes. The lambda behavior is a common gotcha - there are hundreds of questions on StackOverflow that are caused by that misunderstanding http://stackoverflow.com/questions/7368522/weird-behavior-lambda-inside-list-comprehension The most common solution is to just provide the variable as a default argument to the lambda function, which will bind it how you'd expect [lambda base, exponent=exponent: (base ** exponent) for exponent in range(9)] On Thu, Sep 29, 2016 at 12:29 PM, wrote: > hello pythonistas > > i've had a nodding acquaintance with python for some time, and all along i > assumed that for-loops got a namespace of their own; now i'm reading up on > the language and i find out that's not the case: the loop variable gets put > into the enclosing namespace, overwriting any former value that was already > there; of course i realize there are situations where one is interested in > the value that a loop variable has after the loop has been exited, but this > behavior seems grossly unintuitive to me: has there ever been any > discussion of giving for-loops the option of running in namespaces of their > own? > > and it gets even worse; consider the following means of raising an > exception: > > #)-------------------------------------- begin code > > def powerfunction(exponent): > return lambda base: (base ** exponent) > > p1 = [powerfunction(exponent) for exponent in range(9)] > p2 = [lambda base: (base ** exponent) for exponent in range(9)] > > assert p1[3](4) == p2[3](4) > > #)---------------------------------------- end code > > apparently the problem is that "exponent" gets evaluated when the relevant > lambda function is run, not when it's defined, but no binding for > "exponent" gets put into the enclosing namespace: it seems that python > remembers this ghostly "exponent" for me on the theory that i don't WANT > "p1" and "p2" to be the same; can anyone help to reconcile me to this > semantics? > > thanks if you can help > stm > > > > > > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From random832 at fastmail.com Thu Sep 29 15:58:48 2016 From: random832 at fastmail.com (Random832) Date: Thu, 29 Sep 2016 15:58:48 -0400 Subject: Expression can be simplified on list In-Reply-To: <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> Message-ID: <1475179128.424676.741214657.4673C781@webmail.messagingengine.com> On Thu, Sep 29, 2016, at 02:47, Rustom Mody wrote: > Your example is exactly what I am saying; if a type has a behavior in > which all values are always True (true-ish) its a rather strange kind > of bool-nature. For a given type T, if all objects of type T are true (true-ish, truthy, whatever), it does make using an expression of type T in an if-statement an incoherent thing to do, but it makes using an expression of type Union[T, NoneType] reasonable. From lele at metapensiero.it Thu Sep 29 16:14:39 2016 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 29 Sep 2016 22:14:39 +0200 Subject: ANN: dedent 0.5 released References: <6efc4a42-4855-470f-033e-f57e16e32df8@stackless.com> Message-ID: <87ponm31lc.fsf@metapensiero.it> Christian Tismer writes: > Dedent 0.5 > ========== > > What is it? > ----------- > > Dedent is a very simple tool for those people who like to > indent their inline code nicely. > > p.s.: Why is that not build in by default? Isn't it roughly the same as https://docs.python.org/3.6/library/textwrap.html#textwrap.dedent ? 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 tismer at stackless.com Thu Sep 29 17:20:39 2016 From: tismer at stackless.com (Christian Tismer) Date: Thu, 29 Sep 2016 23:20:39 +0200 Subject: ANN: dedent 0.5 released In-Reply-To: <87ponm31lc.fsf@metapensiero.it> References: <6efc4a42-4855-470f-033e-f57e16e32df8@stackless.com> <87ponm31lc.fsf@metapensiero.it> Message-ID: <2203499a-7cf2-ea2c-1c6d-70a19c5f8bdd@stackless.com> On 29/09/16 22:14, Lele Gaifax wrote: > Christian Tismer writes: > >> Dedent 0.5 >> ========== >> >> What is it? >> ----------- >> >> Dedent is a very simple tool for those people who like to >> indent their inline code nicely. >> >> p.s.: Why is that not build in by default? > > Isn't it roughly the same as > https://docs.python.org/3.6/library/textwrap.html#textwrap.dedent ? Yes, it actually uses the dedent function. They just failed to expose it. Cheers - Chris -- Christian Tismer :^) tismer at stackless.com Software Consulting : http://www.stackless.com/ Karl-Liebknecht-Str. 121 : https://github.com/PySide 14482 Potsdam : GPG key -> 0xFB7BEE0E phone +49 173 24 18 776 fax +49 (30) 700143-0023 From rosuav at gmail.com Thu Sep 29 17:35:31 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Sep 2016 07:35:31 +1000 Subject: Expression can be simplified on list In-Reply-To: <1475179128.424676.741214657.4673C781@webmail.messagingengine.com> References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <1475179128.424676.741214657.4673C781@webmail.messagingengine.com> Message-ID: On Fri, Sep 30, 2016 at 5:58 AM, Random832 wrote: > On Thu, Sep 29, 2016, at 02:47, Rustom Mody wrote: >> Your example is exactly what I am saying; if a type has a behavior in >> which all values are always True (true-ish) its a rather strange kind >> of bool-nature. > > For a given type T, if all objects of type T are true (true-ish, truthy, > whatever), it does make using an expression of type T in an if-statement > an incoherent thing to do, but it makes using an expression of type > Union[T, NoneType] reasonable. Or, as it would more commonly be spelled, Optional[T]. Very common situation; re.match was mentioned, and lots of data types can be clearly demonstrated by implementing them in Python using some kind of "optional node" structure - eg a linked list, where the last one has "self.next = None", or a binary tree where leaf nodes have None for both children, or a hash table where empty buckets have None. ChrisA From nad at python.org Thu Sep 29 17:48:48 2016 From: nad at python.org (Ned Deily) Date: Thu, 29 Sep 2016 17:48:48 -0400 Subject: Getting IDLE to use correct Tcl/Tk on MacOSX 10.6? In-Reply-To: References: Message-ID: On 2016-09-27 18:47, Gregory Ewing wrote: > I don't normally use IDLE, but I had occasion to use it > on MacOSX 10.6 to answer someone's question, and of course > it didn't work properly due to Apple's broken Tcl/Tk. > > I followed the advice to install ActiveState Tcl 8.5.18.0, > but my Python still wants to use Apple's Tcl. > > How do I persuade Python to use the new one I've installed? > It's a framework install of Python 3.5 that I compiled > myself. Do I need to rebuild it to get it to pick up the > right Tcl? Or is there an environment variable I can set? As you probably know, on OS X the dynamic load library paths linked into executables and the like are normally absolute paths. This applies to _tkinter.so. You can check the path with otool -L. $ python3.5 -c "import _tkinter; print(_tkinter.__file__)" /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload/_tkinter.cpython-35m-darwin.so $ otool -L $(python3.5 -c "import _tkinter; print(_tkinter.__file__)") /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload/_tkinter.cpython-35m-darwin.so: /Library/Frameworks/Tcl.framework/Versions/8.5/Tcl (compatibility version 8.5.0, current version 8.5.18) /Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.18) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0) The ActiveState Tcl/Tk frameworks are installed in /Library/Frameworks; your _tkinter was linked with the Apple-supplied versions in /System/Library/Frameworks. If you rebuild _tkinter after the new versions are in /Library/Frameworks, everything should be just fine, since, by default, /Library/Frameworks is searched at link time before /System/Library/Frameworks. You could also override the search order at run time for all frameworks with: DYLD_FRAMEWORK_PATH=/Library/Frameworks See man dyld for more info. Or you might be able to use install_name_tool to modify the path to the framework. From rosuav at gmail.com Thu Sep 29 19:19:09 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Sep 2016 09:19:09 +1000 Subject: unintuitive for-loop behavior In-Reply-To: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> Message-ID: On Fri, Sep 30, 2016 at 5:29 AM, wrote: > i've had a nodding acquaintance with python for some time, and all along i assumed that for-loops got a namespace of their own; now i'm reading up on the language and i find out that's not the case: the loop variable gets put into the enclosing namespace, overwriting any former value that was already there; of course i realize there are situations where one is interested in the value that a loop variable has after the loop has been exited, but this behavior seems grossly unintuitive to me: has there ever been any discussion of giving for-loops the option of running in namespaces of their own? > No, there hasn't. In Python, there are no sub-function scopes - even the couple of cases that look like subscopes (list comps and genexps) are actually implemented as nested functions (fairly obvious in the case of a genexp, more subtle with the list comp). C-like languages can have infinitely nested scopes because they have variable declarations: int some_func() { int foo; for (...) { if (whatever) { foo = 1234; } else { foo = 2345; } use(foo); } } The placement of 'int foo;' determines the scope of that name. Python doesn't have that, so your options are: 1) The first assignment to a name determines its scope. That would mean that the two assignments are in different scopes, and use(foo) is not included. To solve this, you'd need a dummy assignment further up (eg where "int foo" is) - not impossible but probably annoying. 2) Have a single and simple scoping rule, like "anything that's assigned to is function-local". Python chose the second option. Anything you assign to is local to the function, but nothing narrower. There is no way [1] to have a local name in a function AND use a global with the same name, even in different parts of the function. Since a 'for' loop is assignment ("for X in Y" assigns to X), that name has to be function-scoped. You could, in theory, have the name be unbound after the loop, but it's usually not beneficial to do so, and can be detrimental. ChrisA [1] Well, you can use globals(), but that's not quite the same thing as variable scope. From rosuav at gmail.com Thu Sep 29 19:22:26 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Sep 2016 09:22:26 +1000 Subject: how to automate java application in window using python In-Reply-To: References: <5658892a-9bdb-46eb-a2e4-85c99fd7612c@googlegroups.com> <8737kxd0fd.fsf@jester.gateway.pace.com> <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> <3e2d0652-85a8-4a4b-ad75-d50e3f049024@googlegroups.com> <43f34c1f-34d0-4a20-9312-228783638f57@googlegroups.com> Message-ID: On Fri, Sep 30, 2016 at 5:18 AM, Lawrence D?Oliveiro wrote: > On Thursday, September 29, 2016 at 11:46:59 PM UTC+13, Ned Batchelder wrote: >> This is just getting rude. Let's please drop it. > > Do you have anything substantive to contribute? Yes. He contributed the guiding hand of "please keep it polite". If you don't think that's substantive, go have a look at a completely unmoderated discussion group, then at a well-led community, and see how much more pleasant it is in one than the other. Please don't be unnecessarily rude to people. Arguing back and forth "Windows is terrible", "But I have tools that work just fine on Windows", "GUIs suck", "No they don't", "You can't automate stuff on Windows", "Yes you can", etc, etc, is not going to get anyone anywhere, and it just makes everything unpleasant. Thanks. ChrisA From steve+python at pearwood.info Thu Sep 29 19:49:45 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 30 Sep 2016 09:49:45 +1000 Subject: how to automate java application in window using python References: <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> <3e2d0652-85a8-4a4b-ad75-d50e3f049024@googlegroups.com> <43f34c1f-34d0-4a20-9312-228783638f57@googlegroups.com> Message-ID: <57eda89b$0$1608$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Sep 2016 05:18 am, Lawrence D?Oliveiro wrote: > On Thursday, September 29, 2016 at 11:46:59 PM UTC+13, Ned Batchelder > wrote: >> This is just getting rude. Let's please drop it. > > Do you have anything substantive to contribute? Infinitely more than you. *plonk* -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 29 20:24:31 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 30 Sep 2016 10:24:31 +1000 Subject: Expression can be simplified on list References: <10685671.O9o76ZdvQC@PointedEars.de> <8560pzqktw.fsf@benfinney.id.au> <57d8d7ae$0$11116$c3e8da3@news.astraweb.com> <7e63bc6b-c887-428e-a6e1-9e27c844a3e9@googlegroups.com> <1475179128.424676.741214657.4673C781@webmail.messagingengine.com> Message-ID: <57edb0c2$0$1596$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Sep 2016 05:58 am, Random832 wrote: > On Thu, Sep 29, 2016, at 02:47, Rustom Mody wrote: >> Your example is exactly what I am saying; if a type has a behavior in >> which all values are always True (true-ish) its a rather strange kind >> of bool-nature. > > For a given type T, if all objects of type T are true (true-ish, truthy, > whatever), it does make using an expression of type T in an if-statement > an incoherent thing to do, but it makes using an expression of type > Union[T, NoneType] reasonable. Or Union[T, S] where S is some other type (including a union of multiple types) which has at least one falsey value. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tcebob at comcast.net Thu Sep 29 21:33:38 2016 From: tcebob at comcast.net (tcebob at comcast.net) Date: Thu, 29 Sep 2016 21:33:38 -0400 Subject: Save Idle Options Message-ID: Win 10 pro 32, Python 3.6 I?m new to Python and installed Python with Idle, which I like as an IDE. But I?m mystified as to how to make interface options stick. Opened Options, Configure Idle. Changed font to Consolas Bold. And stopped dead. There doesn?t seem to be a way to save the changes. Tried reloading my file but had to exit the Options to do so. So lost the changes. Same issue with highlighting colors. Google is hopeless. How can I do this? tcebob From torriem at gmail.com Thu Sep 29 23:29:58 2016 From: torriem at gmail.com (Michael Torrie) Date: Thu, 29 Sep 2016 21:29:58 -0600 Subject: how to automate java application in window using python In-Reply-To: References: <5d64a7ac-c2d5-488f-b98b-afcff492c95b@googlegroups.com> <9d85e9de-8978-41fe-9a94-929ae6f60b7c@googlegroups.com> <4db1f4a0-d2d9-4fde-b35e-e95e626bc27b@googlegroups.com> <3e2d0652-85a8-4a4b-ad75-d50e3f049024@googlegroups.com> <43f34c1f-34d0-4a20-9312-228783638f57@googlegroups.com> Message-ID: <1998cd14-64a0-1730-f509-11224763ff8f@gmail.com> On 09/29/2016 01:18 PM, Lawrence D?Oliveiro wrote: > On Thursday, September 29, 2016 at 11:46:59 PM UTC+13, Ned Batchelder wrote: >> This is just getting rude. Let's please drop it. > > Do you have anything substantive to contribute? He's already contributed far more to this list, and to Python, than you have, and he has for years. You apparently have nothing constructive to contribute to this topic yet you can't resist posting and criticizing when people who might have some small contribution try to post. As much as I hate to say it, plonk. From pavel.velikhov at gmail.com Fri Sep 30 00:30:43 2016 From: pavel.velikhov at gmail.com (Pavel Velikhov) Date: Thu, 29 Sep 2016 21:30:43 -0700 (PDT) Subject: Python grammar extension via encoding (pyxl style) questions Message-ID: <53db4ae2-8add-4779-b2e7-77d610da426b@googlegroups.com> Hi everybody! We?re building an experimental extension to Python, we?re extending Python?s comprehensions into a full-scale query language. And we?d love to use the trick that was done in pyxl, where a special encoding of the file will trigger the preprocessor to run and compile our extended language into Python and execute it. The actual encoding business is a bit tricky, but we also really really would like the whole thing to be installable via pip, otherwise only a tiny percentage of our potential users (we're targeting data scientists) would go through the pain of installing the extension. So I have some question, would really appreciate any help: - Are there any resources to get up the speed on custom encodings? The pyxl code looks fine, just not clear what some of the steps are. - We?d love to have a pip install for our module, but even pyxl didn't do it (i.e. you clone the repository, then do a local pip install, and then run a script). Is it impossible to just do it all with pip? Would it be a terrible/horrible hack? Any hints on how to do this? - Last question - we?d love to enable support for our extension in interactive python and especially in Jupyter notebooks. Would you have any advise on how to approach these? Thanks in advance! Pavel Velikhov P.S. Here's the demo site for our project,if you're interested: www.pythonql.org From greg.ewing at canterbury.ac.nz Fri Sep 30 00:53:13 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Sep 2016 17:53:13 +1300 Subject: unintuitive for-loop behavior In-Reply-To: References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> Message-ID: namenobodywants at gmail.com wrote: > can anyone help to reconcile me to this semantics? Not really. Most people agree that it's not desirable behaviour, but we've ended up here due to a convoluted history, and there doesn't seem to be a good way to fix it without breaking a lot of existing code. Chris Angelico wrote: > You could, in theory, have the name be unbound after the loop, but it's > usually not beneficial to do so, and can be detrimental. It also wouldn't help at all with this problem. There *is* something that could be done, at least in CPython: if the loop variable is referenced by a nested function, then create a new cell for it each time round the loop, instead of updating the contents of the existing cell. This would be backwards-compatible in almost all cases. The last value would still be accessible after the loop finishes, and other assignments to the loop variable in the same function would work the same way as always. Guido doesn't like this idea, though, because it depends on CPython implementation details, and other Python implementations could have trouble matching these semantics. -- Greg From rustompmody at gmail.com Fri Sep 30 01:06:03 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 29 Sep 2016 22:06:03 -0700 (PDT) Subject: unintuitive for-loop behavior In-Reply-To: References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> Message-ID: <06dfb5d8-e477-4b77-a015-f5569e44bdb4@googlegroups.com> On Friday, September 30, 2016 at 10:23:31 AM UTC+5:30, Gregory Ewing wrote: > namenobodywants wrote: > > can anyone help to reconcile me to this semantics? > > Not really. Most people agree that it's not desirable > behaviour, but we've ended up here due to a convoluted > history, and there doesn't seem to be a good way to > fix it without breaking a lot of existing code. Thanks for an unusually helpful answer. In my experience telling a beginner: ?This? is a misfeature/gotcha And ?this? is its workaround greatly shortens the learning curve as compared to long-winded justificatory explanations From vito.detullio at gmail.com Fri Sep 30 01:53:09 2016 From: vito.detullio at gmail.com (Vito De Tullio) Date: Fri, 30 Sep 2016 07:53:09 +0200 Subject: ANN: dedent 0.5 released References: <6efc4a42-4855-470f-033e-f57e16e32df8@stackless.com> Message-ID: Christian Tismer wrote: > $ python -c """some code""" totally offtopic but... since when bash support python-style triple quote?? Is it another shell?? -- By ZeD From jussi.piitulainen at helsinki.fi Fri Sep 30 01:57:34 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 30 Sep 2016 08:57:34 +0300 Subject: ANN: dedent 0.5 released References: <6efc4a42-4855-470f-033e-f57e16e32df8@stackless.com> Message-ID: Vito De Tullio writes: > Christian Tismer wrote: > >> $ python -c """some code""" > > totally offtopic but... since when bash support python-style triple > quote?? Is it another shell?? Bash allows any odd number of quotes on each side. From redstone-cold at 163.com Fri Sep 30 01:58:56 2016 From: redstone-cold at 163.com (iMath) Date: Thu, 29 Sep 2016 22:58:56 -0700 (PDT) Subject: filesystem encoding 'strict' on Windows Message-ID: <06ac7209-28db-4366-9921-719ce43daa5d@googlegroups.com> the doc of os.fsencode(filename) says Encode filename to the filesystem encoding 'strict' on Windows, what does 'strict' mean ? From dieter at handshake.de Fri Sep 30 02:27:09 2016 From: dieter at handshake.de (dieter) Date: Fri, 30 Sep 2016 08:27:09 +0200 Subject: SOAP XML webserver in Python/Django References: <060d5646-dba6-4191-a70c-fffd0fa951c2@googlegroups.com> Message-ID: <87eg419a2q.fsf@handshake.de> ivan77 writes: > I currently have a need to setup a webserver on one of our internal servers that is going to send and receive XML SOAP responses to an external company through a VPN. > > It seems like something that I could use python (maybe even Django) for. However, even though I have been using Python and Django for a while now, I am unsure of whether this is a good idea to implement, since there seems to be some question about whether there are good maintained libraries to use and I am unfamiliar with if there are added complexities with SOAP that I have to deal with. It looks like pretty standard XML to me wrapped in an extra layer of meta data. > > http://stackoverflow.com/questions/206154/what-soap-client-libraries-exist-for-python-and-where-is-the-documentation-for?rq=1 You may have a look at "spyne". It can generate WSDL 1.1 interface descriptions and supports SOAP 1.1 (among others). Its maintainer (burak.arslan) is very active and reacts quickly to problems and questions (in the "soap at python.org" or "people at spyne.io" mailing lists). A look at "PyPI" seems to indicate, that there are solutions which facilitate using "django" as a SOAP server (e.g. "https://pypi.python.org/pypi/django-soap-server/0.0.0"). From dieter at handshake.de Fri Sep 30 02:33:00 2016 From: dieter at handshake.de (dieter) Date: Fri, 30 Sep 2016 08:33:00 +0200 Subject: [py 2.7] JSON and UTF-8 References: <6MmHz.1881542$3%1.602088@fx40.am4> Message-ID: <87a8ep99sz.fsf@handshake.de> Gilmeh Serda writes: > Is there something that can be done when writing JSON using its dump/ > dumps feature so, e.g. Cyrillic text will show up correctly in a text > editor afterwards? > ... > The 'template.json' contains this: > > { > "test": "????????????????" > } > > What the json module outputs to the 'output.json' file is: > > {"test": "\u00f8\u00e6\u00df\u00fe\u00e5\u043d\u0430\u0439\u0442\u0435 > \u0126\u0152\u0152\u00ae\u00ae\u00ae"} > > But I would really like to be able to read that. The "dumps" function has a parameter which allows the use of unicode (instead of ascii encoded) strings. Likely, using this parameter will solve your problem. I have found out that some browsers have problems with some unicode characters. Maybe, this is one reason to have ascii encoded strings the default for "dumps". From gandalf at shopzeus.com Fri Sep 30 02:51:42 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 30 Sep 2016 08:51:42 +0200 Subject: How to make a copy of chained dicts effectively and nicely? In-Reply-To: References: <690e8ef4-2159-3c5f-b20c-96c782146839@mrabarnett.plus.com> Message-ID: <023bb603-650f-3054-b25a-f829835164cd@shopzeus.com> On Wed, Sep 28, 2016 at 12:54 AM, Jussi Piitulainen > wrote: >> I wasn't sure if it makes a copy or just returns the dict. But it's >> true: help(dict) says dict(mapping) is a "new dictionary initialized >> from a mapping object's (key, value) pairs". > Yep. With mutable objects, Python's docs are usually pretty clear that > you get a brand-new object every time: In that case, this seems to be the cleanest and most effective. (Sorry for the late answer) From eryksun at gmail.com Fri Sep 30 04:42:47 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 30 Sep 2016 08:42:47 +0000 Subject: filesystem encoding 'strict' on Windows In-Reply-To: <06ac7209-28db-4366-9921-719ce43daa5d@googlegroups.com> References: <06ac7209-28db-4366-9921-719ce43daa5d@googlegroups.com> Message-ID: On Fri, Sep 30, 2016 at 5:58 AM, iMath wrote: > the doc of os.fsencode(filename) says Encode filename to the filesystem encoding 'strict' > on Windows, what does 'strict' mean ? "strict" is the error handler for the encoding. It raises a UnicodeEncodeError for unmapped characters. For example: >>> '????'.encode('mbcs', 'strict') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character On the other hand, the "replace" error handler is lossy. With the Windows "mbcs" codec, it substitutes question marks and best-fit mappings for characters that aren't defined in the system locale's ANSI codepage (e.g. 1252). For example: >>> print('????'.encode('mbcs', 'replace').decode('mbcs')) a??d This is the behavior of os.listdir with bytes paths, which is why using bytes paths has been deprecated on Windows since 3.3. In 3.6 bytes paths are provisionally allowed again because the filesystem encoding has changed to UTF-8 (internally transcoded to the native UTF-16LE) and uses the "surrogatepass" error handler to allow lone surrogate codes (allowed by Windows). See PEP 529 for more information. From vinay_sajip at yahoo.co.uk Fri Sep 30 05:51:36 2016 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 30 Sep 2016 09:51:36 +0000 (UTC) Subject: ANN: distlib 0.2.4 released on PyPI References: <1592008463.2275511.1475229096733.ref@mail.yahoo.com> Message-ID: <1592008463.2275511.1475229096733@mail.yahoo.com> I've just released version 0.2.4 of distlib on PyPI [1]. For newcomers, distlib is a library of packaging functionality which is intended to be usable as the basis for third-party packaging tools. The main changes in this release are as follows: * Updated to not fail during import if SSL is not available. * Changed project name comparisons to follow PEP 503. * Changed manifest and resources logic to work correctly under (upcoming) Python 3.6. * Updated Windows launchers with fixes to bugs related to argument-passing in shebang lines. A more detailed change log is available at [2]. Please try it out, and if you find any problems or have any suggestions for improvements, please give some feedback using the issue tracker! [3] Regards, Vinay Sajip [1] https://pypi.python.org/pypi/distlib/0.2.4 [2] https://goo.gl/M3kQzR [3] https://bitbucket.org/pypa/distlib/issues/new From cfkaran2 at gmail.com Fri Sep 30 06:25:30 2016 From: cfkaran2 at gmail.com (Cem Karan) Date: Fri, 30 Sep 2016 06:25:30 -0400 Subject: Abusive Italian Spam In-Reply-To: References: Message-ID: <62245354-0ED2-44F4-B41A-6B8834C4F2DB@gmail.com> Honestly, I'm impressed by how little spam ever makes it onto the list. Considering the absolute flood of email the lists get, it's impressive work. Thank you for all the hard work you guys do for all the rest of us! Thanks, Cem Karan On Sep 29, 2016, at 11:30 AM, Tim Golden wrote: > You may have noticed one or two more of the abusive spam messages slip > through onto the list. We do have traps for these but, as with most such > things, they need tuning. (We've discarded many more than you've seen). > > As ever, kudos to Mark Sapiro of the Mailman team for tweaking our > custom filters and sorting out the archives in a timely fashion. > > TJG > -- > https://mail.python.org/mailman/listinfo/python-list From p.f.moore at gmail.com Fri Sep 30 07:02:39 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 30 Sep 2016 04:02:39 -0700 (PDT) Subject: Using the Windows "embedded" distribution of Python In-Reply-To: References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> <6cf0cac1-d569-41f4-a693-d393203bc66d@googlegroups.com> Message-ID: <73527675-3862-4360-9909-6bd6b6ecd6fd@googlegroups.com> On Thursday, 29 September 2016 12:56:28 UTC+1, eryk sun wrote: > In that case you can use an application manifest with a dependent > assembly. Say embedded Python 3.6 is in the "py3embed" subdirectory. > Add the following manifest file to that directory: > > py3embed.manifest: > > > > version="3.6.111.1013" > type="win32" > processorArchitecture="amd64" /> > > > > > > Add this assembly as a dependency in the application manifest, either > embedded in the executable (resource #1) or as a separate file named > the same as the executable plus ".manifest", e.g. "app.exe.manifest". > You can start with the manifest that's used by python.exe, from > PC\python.manifest. > > > > version="3.6.111.1013" > type="win32" > processorArchitecture="amd64" /> > > OK, I thought I understood this, but it's not quite working. I have the following directory structure: py3embed py3embed.manifest ... an unpacked Python 3.6b0 embedded distribution ssh.exe ssh.exe.manifest (ssh.exe is my embedded Python program) py3embed.manifest is ssh.exe.manifest is: true When I run ssh.exe, it fails with the message "The program cannot start because python3.dll is missing from your computer". I tried running it with sxstrace active, but the resulting log file is empty. I'm not sure where to go next debugging this. Do you have any suggestions? Paul From p.f.moore at gmail.com Fri Sep 30 07:07:22 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 30 Sep 2016 04:07:22 -0700 (PDT) Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: <682e117e-3c50-4e61-9493-bc3167f7a039@googlegroups.com> References: <682e117e-3c50-4e61-9493-bc3167f7a039@googlegroups.com> Message-ID: <6204fe91-c854-44a7-be3a-25d6265845b3@googlegroups.com> On Thursday, 29 September 2016 02:23:13 UTC+1, jf... at ms4.hinet.net wrote: > Paul Moore at 2016/9/28 11:31:50PM wrote: > > Taking a step back from the more detailed answers, would I be right to assume that you want to call this external function multiple times from Python, and each call could take days to run? Or is it that you have lots of calls to make and each one takes a small amount of time but the total time for all the calls is in days? > > > > And furthermore, can I assume that the external function is *not* written to take advantage of multiple CPUs, so that if you call the function once, it's only using one of the CPUs you have? Is it fully utilising a single CPU, or is it actually not CPU-bound for a single call? > > > > To give specific suggestions, we really need to know a bit more about your issue. > > Forgive me, I didn't notice these detail will infulence the answer:-) > > Python will call it once. The center part of this function was written in assembly for performance. During its execution, this part might be called thousands of million times. The function was written to run in a single CPU, but the problem it want to solve can be easily distributed into multiple CPUs. > > --Jach OK. So if your Python code only calls the function once, the problem needs to be fixed in the external code (the assembly routine). But if you can split up the task at the Python level to make multiple calls to the function, each to do a part of the task, then you could set up multiple threads in your Python code, each of which handles part of the task, then Python merges the results of the sub-parts to give you the final answer. Does that make sense to you? Without any explicit code, it's hard to be sure I'm explaining myself clearly. Paul From eryksun at gmail.com Fri Sep 30 07:49:46 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 30 Sep 2016 11:49:46 +0000 Subject: Using the Windows "embedded" distribution of Python In-Reply-To: <73527675-3862-4360-9909-6bd6b6ecd6fd@googlegroups.com> References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> <6cf0cac1-d569-41f4-a693-d393203bc66d@googlegroups.com> <73527675-3862-4360-9909-6bd6b6ecd6fd@googlegroups.com> Message-ID: On Fri, Sep 30, 2016 at 11:02 AM, Paul Moore wrote: > When I run ssh.exe, it fails with the message "The program cannot start because > python3.dll is missing from your computer". I tried running it with sxstrace active, > but the resulting log file is empty. A manifest embedded in "ssh.exe" takes precedence over "ssh.exe.manifest". Check for an embedded manifest: mt -inputresource:ssh.exe -out:con >nul Also, manifests get cached (probably by SuperFetch), so when you make a change you generally need to recompile or change the filename. From steve+python at pearwood.info Fri Sep 30 08:33:54 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 30 Sep 2016 22:33:54 +1000 Subject: unintuitive for-loop behavior References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> Message-ID: <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Sep 2016 05:29 am, namenobodywants at gmail.com wrote: > hello pythonistas > > i've had a nodding acquaintance with python for some time, and all along i > assumed that for-loops got a namespace of their own; Giving for-loops their own namespace is a grossly unintuitive and a very weird thing to do. Modules, classes and functions are obviously namespaces. Why should arbitrary syntactic structures create their own namespace? It would be terribly inconvenient and surprising for if...else blocks to be separate namespaces: a = 1 if condition: print(a) # UnboundLocalError: local 'a' referenced before assignment a += 1 For-loops are no different. Making them their own namespace is a very strange thing to do, it would mean you couldn't re-bind a value inside a for-loop: count = 0 for x in sequence: count += 1 # raises UnboundLocalError: local 'count' referenced before assignment unless you declared it nonlocal or global, depending on whether your for loop was inside a function or not. To me, "make for-loops be their own scope" sounds like a joke feature out of joke languages like INTERCAL. I'm not aware of any sensible language that does anything like this. No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that one of his favourite languages, Pike or REXX, does it. I forget which. -- 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 Sep 30 09:13:39 2016 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 30 Sep 2016 06:13:39 -0700 (PDT) Subject: Using the Windows "embedded" distribution of Python In-Reply-To: References: <6c63a5da-32e3-4f59-a32a-63908fd4a3b7@googlegroups.com> <9a67e78e-170e-415f-bacf-77e3acf982b2@googlegroups.com> <6cf0cac1-d569-41f4-a693-d393203bc66d@googlegroups.com> <73527675-3862-4360-9909-6bd6b6ecd6fd@googlegroups.com> Message-ID: On Friday, 30 September 2016 12:50:45 UTC+1, eryk sun wrote: > On Fri, Sep 30, 2016 at 11:02 AM, Paul Moore wrote: > > When I run ssh.exe, it fails with the message "The program cannot start because > > python3.dll is missing from your computer". I tried running it with sxstrace active, > > but the resulting log file is empty. > > A manifest embedded in "ssh.exe" takes precedence over > "ssh.exe.manifest". Check for an embedded manifest: > > mt -inputresource:ssh.exe -out:con >nul I didn't think there was one, but when I looked, there is. I must have added it in my experimentation. Sadly, it's the same as the external one, so that shouldn't be a problem. > Also, manifests get cached (probably by SuperFetch), so when you make > a change you generally need to recompile or change the filename. Ah, looks like that was the issue. Renaming the file fixed it. (As did just touching the file to update the timestamp). Caches are great, I guess, but they sure make debugging an adventure! I think I now have a working solution. And I've *definitely* learned a huge amount. Thanks again for the help. Paul From a24061 at ducksburg.com Fri Sep 30 09:23:12 2016 From: a24061 at ducksburg.com (Adam Funk) Date: Fri, 30 Sep 2016 14:23:12 +0100 Subject: pyicloud: TypeError: 'dict_values' object does not support indexing Message-ID: <0j52cdxjp8.ln2@news.ducksburg.com> I'm trying to use pyicloud in idle3 (installed by pip3 on Ubuntu). The basic stuff works, but access to photos (following the instructions) fails: >>> photos = api.photos.all >>> for photo in photos: print(photo.filename) Traceback (most recent call last): File "", line 2, in print(photo.filename) File "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py", line 242, in filename return self.data['details'].get('filename') File "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py", line 237, in data self._data = self.album._fetch_asset_data_for(self) File "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py", line 203, in _fetch_asset_data_for client_ids.append(self._photo_assets[index].client_id) TypeError: 'dict_values' object does not support indexing which points at this bit of the source code 240 @property 241 def filename(self): 242 return self.data['details'].get('filename') And I get the same exception trying to do anything with a single photo. Is this code not really Python 3 compatible? Or am I doing something stupid? Thanks, Adam -- A firm rule must be imposed upon our nation before it destroys itself. The United States needs some theology and geometry, some taste and decency. I suspect that we are teetering on the edge of the abyss. --- Ignatius J Reilly From bc at freeuk.com Fri Sep 30 09:43:25 2016 From: bc at freeuk.com (BartC) Date: Fri, 30 Sep 2016 14:43:25 +0100 Subject: unintuitive for-loop behavior In-Reply-To: <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30/09/2016 13:33, Steve D'Aprano wrote: > On Fri, 30 Sep 2016 05:29 am, namenobodywants at gmail.com wrote: >> i've had a nodding acquaintance with python for some time, and all along i >> assumed that for-loops got a namespace of their own; > It would be terribly inconvenient and surprising for if...else blocks to be > separate namespaces: > > a = 1 > if condition: > print(a) # UnboundLocalError: local 'a' referenced before assignment > a += 1 > > > For-loops are no different. Making them their own namespace is a very > strange thing to do, it would mean you couldn't re-bind a value inside a > for-loop: > > count = 0 > for x in sequence: > count += 1 > # raises UnboundLocalError: local 'count' referenced before assignment It can make sense for 'x' to be local to this for-loop block (everything else is at it works now), and independent of any x's in outer blocks. It means being able to do stuff like this: for x in a: for x in b: pass pass # outer x still has its value And any even more outer x's are not affected. With 'for', especially one inside a list-comp, often you just need some throwaway index variable without worrying if it will clash with an existing local. But it's not useful enough I think to bother changing now. Or even when the language was designed. -- Bartc From __peter__ at web.de Fri Sep 30 09:52:14 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Sep 2016 15:52:14 +0200 Subject: pyicloud: TypeError: 'dict_values' object does not support indexing References: <0j52cdxjp8.ln2@news.ducksburg.com> Message-ID: Adam Funk wrote: > I'm trying to use pyicloud in idle3 (installed by pip3 on Ubuntu). > > > > The basic stuff works, but access to photos (following the > instructions) fails: > > >>>> photos = api.photos.all >>>> for photo in photos: > print(photo.filename) > > > Traceback (most recent call last): > File "", line 2, in > print(photo.filename) > File > "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py", > line 242, in filename > return self.data['details'].get('filename') > File > "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py", > line 237, in data > self._data = self.album._fetch_asset_data_for(self) > File > "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py", > line 203, in _fetch_asset_data_for > client_ids.append(self._photo_assets[index].client_id) > TypeError: 'dict_values' object does not support indexing > > which points at this bit of the source code > > 240 @property > 241 def filename(self): > 242 return self.data['details'].get('filename') > > And I get the same exception trying to do anything with a single > photo. Is this code not really Python 3 compatible? Or am I doing > something stupid? I don't think you are. Try wrapping the return value of def _parse_binary_feed(self, feed): ... return list(assets.values()) in services/photos.py to convert the view into a list. Of course when there's one problem there will likely be more... From rosuav at gmail.com Fri Sep 30 10:01:24 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Oct 2016 00:01:24 +1000 Subject: unintuitive for-loop behavior In-Reply-To: <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 30, 2016 at 10:33 PM, Steve D'Aprano wrote: > To me, "make for-loops be their own scope" sounds like a joke feature out of > joke languages like INTERCAL. I'm not aware of any sensible language that > does anything like this. > > No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that one > of his favourite languages, Pike or REXX, does it. I forget which. In C-like languages (including Pike), you can legally define a variable at any point, making it visible at that point and all inner locations - effectively, every brace becomes a new subscope. It makes sense ONLY because variables are declared, no matter where they are (globals are declared at module scope, locals at some kind of inner scope). So, it's not strictly true that Pike has for loops as their own scope, just that C-like languages have a lot of nested scopes. (REXX has nothing like this.) ChrisA From grant.b.edwards at gmail.com Fri Sep 30 10:36:44 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 30 Sep 2016 14:36:44 +0000 (UTC) Subject: unintuitive for-loop behavior References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-09-30, Steve D'Aprano wrote: > To me, "make for-loops be their own scope" sounds like a joke feature out of > joke languages like INTERCAL. I'm not aware of any sensible language that > does anything like this. In C99 a for loop has its own namespac: int main(void) { for (int i=0; i<5; ++i) printf("i=%d\n",i); } If you try to access 'i' outside the for loop, it's an error, because it doesn't exist in the file, global or 'main' namespace. It only exists in the for-loop's namespace. I think that's an absolutely brilliant feature, and I use it a _lot_ when writing C code. I'm a big fan of minimizing the lifetime/scope of variables. I wish if/then/else did the same thing: if ((r=some_function()) != R_SUCCESS) printf("some_function() failed with status %d\n",r); -- Grant Edwards grant.b.edwards Yow! I don't know WHY I at said that ... I think it gmail.com came from the FILLINGS in my rear molars ... From bc at freeuk.com Fri Sep 30 10:45:11 2016 From: bc at freeuk.com (BartC) Date: Fri, 30 Sep 2016 15:45:11 +0100 Subject: unintuitive for-loop behavior In-Reply-To: References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30/09/2016 15:01, Chris Angelico wrote: > On Fri, Sep 30, 2016 at 10:33 PM, Steve D'Aprano > wrote: >> To me, "make for-loops be their own scope" sounds like a joke feature out of >> joke languages like INTERCAL. I'm not aware of any sensible language that >> does anything like this. >> >> No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that one >> of his favourite languages, Pike or REXX, does it. I forget which. > > In C-like languages (including Pike), you can legally define a > variable at any point, making it visible at that point and all inner > locations - effectively, every brace becomes a new subscope. It makes > sense ONLY because variables are declared, no matter where they are > (globals are declared at module scope, locals at some kind of inner > scope). So, it's not strictly true that Pike has for loops as their > own scope, just that C-like languages have a lot of nested scopes. C likes to make things a bit more complicated: int A; { A; // this is the outer A int A; A; // this is the inner A goto A; A: // this is yet another A } Labels live in a different name-space from other names. I've left out struct tags which also have their own name-space, and would allow five different A's in that block (an outer and inner 'struct A') rather than the three I've shown. So a single pair of {-} can enclose three (sometimes five) versions of the same identifier. Personally I think function-scope is plenty. Only one possible top-level 'A' in a function instead of an unlimited number. (Python allows extra 'A's inside nested functions and classes within that function, but that's a bit different.) -- Bartc From gowri at spsolinc.com Fri Sep 30 11:56:01 2016 From: gowri at spsolinc.com (gowri at spsolinc.com) Date: Fri, 30 Sep 2016 08:56:01 -0700 (PDT) Subject: Regarding Job Opportunity for the position Python Developer in Mc Lean, VA Message-ID: <15eff3e7-1507-43d3-bebb-c6b563452b73@googlegroups.com> Hi, Here we have an immediate opening. Location will be Mc Lean, VA. Please revert back to us if you are interested. Need good Python experience. SAS or AWS knowledge is added advantage. Thanks, Gowri Shekar 972-983-3467 From rosuav at gmail.com Fri Sep 30 12:39:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Oct 2016 02:39:23 +1000 Subject: unintuitive for-loop behavior In-Reply-To: References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Oct 1, 2016 at 12:36 AM, Grant Edwards wrote: > On 2016-09-30, Steve D'Aprano wrote: > >> To me, "make for-loops be their own scope" sounds like a joke feature out of >> joke languages like INTERCAL. I'm not aware of any sensible language that >> does anything like this. > > In C99 a for loop has its own namespac: > > int main(void) > { > for (int i=0; i<5; ++i) > printf("i=%d\n",i); > } > > If you try to access 'i' outside the for loop, it's an error, because > it doesn't exist in the file, global or 'main' namespace. It only > exists in the for-loop's namespace. I believe that's the same semantics as C++ uses, and I agree, it's very convenient. Among other things, it means that nested loops behave more like they do in Python, with independent iterators: int main(void) { for (int i=0; i<5; ++i) { printf("%d:", i); for (int i=0; i<3; ++i) printf(" %d", i); printf("\n"); } } Now, granted, this is not something I would ever actually recommend doing, and code review is absolutely justified in rejecting this... but it's a lot better than pure function-scope variables, where you'd get stuck in an infinite loop. Obviously the inner 'i' shadows the outer 'i', but that's the only actual conflict between them. > I think that's an absolutely brilliant feature, and I use it a _lot_ > when writing C code. I'm a big fan of minimizing the lifetime/scope > of variables. I wish if/then/else did the same thing: > > if ((r=some_function()) != R_SUCCESS) > printf("some_function() failed with status %d\n",r); No particular reason not to. Ditto 'while' loops: while (int r=some_function()) .. I agree with minimizing scope, but only where it's practical to do so. In Python, it simply isn't. Like C, Python has infinitely nested scopes; unlike C, Python requires explicit 'nonlocal' declarations in order to assign to something in an outer scope, ergo the convenience of not declaring local variables translates into extreme inconvenience of working with overly-narrow scopes. To put it more simply: Scope is cheap in C, but expensive in Python. ChrisA From grant.b.edwards at gmail.com Fri Sep 30 12:43:29 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 30 Sep 2016 16:43:29 +0000 (UTC) Subject: unintuitive for-loop behavior References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-09-30, Grant Edwards wrote: > On 2016-09-30, Steve D'Aprano wrote: > >> To me, "make for-loops be their own scope" sounds like a joke >> feature out of joke languages like INTERCAL. I'm not aware of any >> sensible language that does anything like this. > > In C99 a for loop has its own namespac: [...] > I think that's an absolutely brilliant feature, and I use it a _lot_ > when writing C code. I'm a big fan of minimizing the lifetime/scope > of variables. I wish if/then/else did the same thing: > > if ((r=some_function()) != R_SUCCESS) > printf("some_function() failed with status %d\n",r); The example of what I wished C did should have been this: if ((int r=some_function()) != R_SUCCESS) printf("some_function() failed with status %d\n",r); -- Grant Edwards grant.b.edwards Yow! If I pull this SWITCH at I'll be RITA HAYWORTH!! gmail.com Or a SCIENTOLOGIST! From 007brendan at gmail.com Fri Sep 30 13:03:03 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Fri, 30 Sep 2016 10:03:03 -0700 Subject: unintuitive for-loop behavior In-Reply-To: <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: > a = 1 if condition: print(a) # UnboundLocalError: local 'a' referenced before assignment a += 1 For-loops are no different. Making them their own namespace is a very strange thing to do, it would mean you couldn't re-bind a value inside a for-loop: count = 0 for x in sequence: count += 1 # raises UnboundLocalError: local 'count' referenced before assignment -------------- That's generally not how nested scopes work, you could still reference objects in the outer scope from the inner scope, but the outer scope couldn't reference objects in the inner scope a = 1 if condition: b = a + 2 print b # UnboundLocalError: local 'b' referenced before assignment for x in sequence: print x print x # UnboundLocalError: local 'x' referenced before assignment. ---------- I wouldn't call either behavior intuitive or unintuitive. They're just different behaviors of different languages. On Fri, Sep 30, 2016 at 5:33 AM, Steve D'Aprano wrote: > On Fri, 30 Sep 2016 05:29 am, namenobodywants at gmail.com wrote: > > > hello pythonistas > > > > i've had a nodding acquaintance with python for some time, and all along > i > > assumed that for-loops got a namespace of their own; > > Giving for-loops their own namespace is a grossly unintuitive and a very > weird thing to do. Modules, classes and functions are obviously namespaces. > Why should arbitrary syntactic structures create their own namespace? > > It would be terribly inconvenient and surprising for if...else blocks to be > separate namespaces: > > a = 1 > if condition: > print(a) # UnboundLocalError: local 'a' referenced before assignment > a += 1 > > > For-loops are no different. Making them their own namespace is a very > strange thing to do, it would mean you couldn't re-bind a value inside a > for-loop: > > count = 0 > for x in sequence: > count += 1 > # raises UnboundLocalError: local 'count' referenced before assignment > > > unless you declared it nonlocal or global, depending on whether your for > loop was inside a function or not. > > To me, "make for-loops be their own scope" sounds like a joke feature out > of > joke languages like INTERCAL. I'm not aware of any sensible language that > does anything like this. > > No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that > one > of his favourite languages, Pike or REXX, does it. I forget which. > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Fri Sep 30 13:08:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Oct 2016 03:08:25 +1000 Subject: unintuitive for-loop behavior In-Reply-To: References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Oct 1, 2016 at 3:03 AM, Brendan Abel <007brendan at gmail.com> wrote: >> a = 1 > if condition: > print(a) # UnboundLocalError: local 'a' referenced before assignment > a += 1 > > > For-loops are no different. Making them their own namespace is a very > strange thing to do, it would mean you couldn't re-bind a value inside a > for-loop: > > count = 0 > for x in sequence: > count += 1 > # raises UnboundLocalError: local 'count' referenced before assignment > > -------------- > > That's generally not how nested scopes work, you could still reference > objects in the outer scope from the inner scope, but the outer scope > couldn't reference objects in the inner scope The trouble is that, absent some sort of declaration, there's no way for the compiler to know whether 'count' and 'a' are supposed to be new variables in the inner scope, or the same variable as the one in the next scope out. In Python, declarations are used when you rebind nonlocal or global names, so these examples would have to be written thus: a = 1 if condition: nonlocal a print(a) a += 1 count = 0 for x in sequence: nonlocal count count += 1 I don't think we want that. :) ChrisA From ethan at stoneleaf.us Fri Sep 30 13:15:52 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 30 Sep 2016 10:15:52 -0700 Subject: Lawrence D'Oliveiro Message-ID: <57EE9DC8.2080501@stoneleaf.us> Lawrence D'Oliveiro is banned from Python List until the new year. If his posts show up somewhere else (e.g. Usenet), please ignore them. If you must respond to him please trim out his text so the rest of us don't have to deal with him. -- Python List Moderators From tjreedy at udel.edu Fri Sep 30 13:33:42 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Sep 2016 13:33:42 -0400 Subject: Save Idle Options In-Reply-To: References: Message-ID: On 9/29/2016 9:33 PM, tcebob at comcast.net wrote: > Win 10 pro 32, Python 3.6 > I?m new to Python and installed Python with Idle, which I like as an IDE. But I?m mystified as to how to make interface options stick. Opened Options, Configure Idle. Changed font to Consolas Bold. And stopped dead. There doesn?t seem to be a way to save the changes. Tried reloading my file but had to exit the Options to do so. So lost the changes. Same issue with highlighting colors. Google is hopeless. How can I do this? Options are saved automatically when you close the dialog with OK rather than Cancel (or [X]) I just retested with Win 10 Pro 64 3.6.0b1. -- Terry Jan Reedy From gowri at spsolinc.com Fri Sep 30 14:11:26 2016 From: gowri at spsolinc.com (gowri at spsolinc.com) Date: Fri, 30 Sep 2016 11:11:26 -0700 (PDT) Subject: Regarding Job Opportunity for the position Python Developer in Mc Lean, VA In-Reply-To: <15eff3e7-1507-43d3-bebb-c6b563452b73@googlegroups.com> References: <15eff3e7-1507-43d3-bebb-c6b563452b73@googlegroups.com> Message-ID: <5a485497-e13d-44d1-b8e4-98f21baea664@googlegroups.com> On Friday, September 30, 2016 at 10:56:14 AM UTC-5, go... at spsolinc.com wrote: > Hi, > > Here we have an immediate opening. Location will be Mc Lean, VA. > Please revert back to us if you are interested. > Need good Python experience. SAS or AWS knowledge is added advantage. > > Thanks, > Gowri Shekar > 972-983-3467 From lcargill99 at comcast.com Fri Sep 30 14:23:29 2016 From: lcargill99 at comcast.com (Les Cargill) Date: Fri, 30 Sep 2016 13:23:29 -0500 Subject: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python? Message-ID: A really interesting design approach in Tcl is to install a callback when a variable is written to. This affords highly event-driven programming. Example ( sorry; it's Tcl ) : namespace eval events { set preRPM -1 proc handleRPM { args } { # do stuff to handle an RPM change here variable ::motor::RPM variable preRPM puts "RPM changed from $preRPM to $RPM set preRPM $RPM } } ... trace variable ::motor::RPM w ::events::handleRPM ... set ::motor::RPM 33.33 What is an equivalent mechanism in Python? Thanks in advance. -- Les Cargill From steve+python at pearwood.info Fri Sep 30 14:29:34 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 01 Oct 2016 04:29:34 +1000 Subject: unintuitive for-loop behavior References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <06dfb5d8-e477-4b77-a015-f5569e44bdb4@googlegroups.com> Message-ID: <57eeaf11$0$1608$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Sep 2016 03:06 pm, Rustom Mody wrote: > On Friday, September 30, 2016 at 10:23:31 AM UTC+5:30, Gregory Ewing > wrote: >> namenobodywants wrote: >> > can anyone help to reconcile me to this semantics? >> >> Not really. Most people agree that it's not desirable >> behaviour, but we've ended up here due to a convoluted >> history, and there doesn't seem to be a good way to >> fix it without breaking a lot of existing code. > > Thanks for an unusually helpful answer. > > In my experience telling a beginner: > ?This? is a misfeature/gotcha > And ?this? is its workaround > > greatly shortens the learning curve as compared to long-winded > justificatory explanations What happens if it is *not* a misfeature? Gotchas are not always misfeatures -- sometimes gotchas are gotchas because people's expectations are simply wrong, and pandering to their confused expectations does not actually help them. I haven't made up my mind about *this* specific (mis)feature itself. I know I don't want for-loops to introduce their own scope, but that doesn't mean that the binding behaviour inside for-loops is necessarily the best way of doing it. I'm still thinking about it. But *in general*, people often don't think the logical consequences through before deciding what behaviour is "obviously" right. They insist that whatever behaviour would be convenient for them *now* is the one and only correct way of doing things -- even if, an hour later, the *opposite* behaviour is convenient and therefore the correct way of doing things. Obviously late binding is the one and only correct way of setting function parameter defaults -- until we need early binding, then it is the one and only correct way of doing it. Gotchas usually exist for a reason. Very few programming languages design gotchas into them to deliberately trip people up[1], or even through carelessness. More often, they're the unexpected consequences of a series of sensible, or even unavoidable, decisions. [1] "When I design my killer language, the identifiers `foo` and `bar` will be reserved words, never used, and not even mentioned in the reference manual. Any program using one will simply dump core without comment. Multitudes will rejoice." - Tim Peters -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jakemorroll18 at gmail.com Fri Sep 30 14:37:19 2016 From: jakemorroll18 at gmail.com (Jake) Date: Fri, 30 Sep 2016 11:37:19 -0700 (PDT) Subject: Counting words in a string?? Message-ID: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Hi, I need a program which: 1) Asks the user for a sentence of their choice (not including punctuation) 2) Ask the user which word they would like to know is repeated 3) Print out to the user how many times the word came up which they chose from their sentence. It would help if you could comment the code. Thankyou in advance!! From steve+python at pearwood.info Fri Sep 30 14:38:23 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 01 Oct 2016 04:38:23 +1000 Subject: unintuitive for-loop behavior References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57eeb122$0$1590$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Sep 2016 11:43 pm, BartC wrote: > It can make sense for 'x' to be local to this for-loop block (everything > else is at it works now), and independent of any x's in outer blocks. It > means being able to do stuff like this: > > for x in a: > for x in b: > pass > pass # outer x still has its value If you're (generic you) not using the loop variables, as in your example, why do you care if one overwrites the other? You're not using either of them. And if you are using them, then surely you need them to be different names so you can use them *both*. So why does it matter if they are in different scopes? I can't think of an example of where I would want two nested for-loops, where *both* loop variables need to be the same name, but I only want to access the inner variable inside the inner loop and the outer variable in the outer loop. And if I was in that position, why couldn't I just relax the "must be the same name" condition and give them different names? Its not like there is a shortage of possible names. > And any even more outer x's are not affected. With 'for', especially one > inside a list-comp, often you just need some throwaway index variable > without worrying if it will clash with an existing local. > > But it's not useful enough I think to bother changing now. Or even when > the language was designed. Indeed. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ned at nedbatchelder.com Fri Sep 30 14:42:49 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 30 Sep 2016 11:42:49 -0700 (PDT) Subject: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python? In-Reply-To: References: Message-ID: <665f0a49-e3e3-4ce2-97ff-af95b36b09ea@googlegroups.com> On Friday, September 30, 2016 at 2:16:10 PM UTC-4, Les Cargill wrote: > A really interesting design approach in Tcl is to install a callback > when a variable is written to. This affords highly event-driven > programming. > > Example ( sorry; it's Tcl ) : > > (I can't read Tcl, sorry) > > What is an equivalent mechanism in Python? There's no way* to hook into "x = 2", but you could hook into "x.a = 2" if you wanted do, by defining __setattr__ on x's class. *OK, there might be some crazy hack involving your own class as the globals for a module or something, but it sounds ill-advised. --Ned. From rgaddi at highlandtechnology.invalid Fri Sep 30 14:47:18 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 30 Sep 2016 18:47:18 -0000 (UTC) Subject: Counting words in a string?? References: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Message-ID: Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they chose from their sentence. > > It would help if you could comment the code. > Thankyou in advance!! I'm sure it would help; your professor will probably take points off otherwise. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From mr.eightnoteight at gmail.com Fri Sep 30 14:49:37 2016 From: mr.eightnoteight at gmail.com (srinivas devaki) Date: Sat, 1 Oct 2016 00:19:37 +0530 Subject: Counting words in a string?? In-Reply-To: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> References: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Message-ID: On Oct 1, 2016 12:10 AM, "Jake" wrote: > > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they chose from their sentence. > typical home work assignment, even though stop asking for programs and start asking how to make the same. anyway if you ever try to write code for this you have to split you sentence and use a dict for counting Python has Counter from collections but it is a little bit slower when compared to defaultdict for this kind of purpose. Regards Srinivas Devaki Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad Computer Science and Engineering Department ph: +91 9491 383 249 telegram_id: @eightnoteight From jakemorroll18 at gmail.com Fri Sep 30 15:12:12 2016 From: jakemorroll18 at gmail.com (Jake) Date: Fri, 30 Sep 2016 12:12:12 -0700 (PDT) Subject: Counting words in a string?? In-Reply-To: References: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Message-ID: On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki wrote: > On Oct 1, 2016 12:10 AM, "Jake" wrote: > > > > Hi, I need a program which: > > 1) Asks the user for a sentence of their choice (not including > punctuation) > > 2) Ask the user which word they would like to know is repeated > > 3) Print out to the user how many times the word came up which they chose > from their sentence. > > > > typical home work assignment, even though stop asking for programs and > start asking how to make the same. > > anyway if you ever try to write code for this you have to split you > sentence and use a dict for counting > > Python has Counter from collections but it is a little bit slower when > compared to defaultdict for this kind of purpose. > > Regards > Srinivas Devaki > Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad > Computer Science and Engineering Department > ph: +91 9491 383 249 > telegram_id: @eightnoteight ---------- Could you make the program for me or provide an outline? From pkpearson at nowhere.invalid Fri Sep 30 15:13:17 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 30 Sep 2016 19:13:17 GMT Subject: Counting words in a string?? References: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Message-ID: On Fri, 30 Sep 2016 11:37:19 -0700 (PDT), Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they chose > from their sentence. > > It would help if you could comment the code. > Thankyou in advance!! Welcome to the Python newsgroup. Many helpful, capable, and polite people frequent this newsgroup, but doing someone's homework assignment is not viewed as helpful. If you write the code and run into a problem, then you can post the code here (if it's short) with a specific question, and will probably get a prompt and very helpful response. -- To email me, substitute nowhere->runbox, invalid->com. From random832 at fastmail.com Fri Sep 30 15:45:07 2016 From: random832 at fastmail.com (Random832) Date: Fri, 30 Sep 2016 15:45:07 -0400 Subject: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python? In-Reply-To: <665f0a49-e3e3-4ce2-97ff-af95b36b09ea@googlegroups.com> References: <665f0a49-e3e3-4ce2-97ff-af95b36b09ea@googlegroups.com> Message-ID: <1475264707.714232.742280361.36EF43B9@webmail.messagingengine.com> On Fri, Sep 30, 2016, at 14:42, Ned Batchelder wrote: > On Friday, September 30, 2016 at 2:16:10 PM UTC-4, Les Cargill wrote: > > What is an equivalent mechanism in Python? > > There's no way* to hook into "x = 2", but you could hook into "x.a = 2" > if you wanted do, by defining __setattr__ on x's class. That or set cls.a to be a descriptor (using either @property or a custom-made descriptor class) class motor: @property def RPM(self): return self._RPM @RPM.setter def RPM(self, value): print("RPM changed from", self._RPM, "to", value) self._RPM = value If you really wanted to get crazy, you could use self.__dict__['RPM'] instead of self._RPM, which would allow you to inject the descriptor separately after the class has already been defined and used. Making it work right if the definition of motor already has an RPM descriptor [for example, if it uses __slots__] is an exercise for the reader. > *OK, there might be some crazy hack involving your own class as the > globals for a module or something, but it sounds ill-advised. You can make your own class to be *the module itself* to support external code's "mod.x = 2", but AIUI that won't apply to plain assignment, which bypasses most of the relevant machinery. From rosuav at gmail.com Fri Sep 30 15:48:10 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Oct 2016 05:48:10 +1000 Subject: Counting words in a string?? In-Reply-To: References: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Message-ID: On Sat, Oct 1, 2016 at 5:12 AM, Jake wrote: > Could you make the program for me or provide an outline? No. In case you didn't read any of the other responses, this community is not a plagiarism source. If you want to learn to be a programmer, you're going to have to learn some key skills, one of which (possibly the most important) is figuring out how to break a problem down into its parts. Start work. If you don't have any clue how to start, ask your professor - that way, it's not cheating. Or if you don't HAVE a professor (if this is a coding challenge from a self-paced online course, for instance), then you may need to consider a pay-for course. A good few of these exist (check the Python Wiki for some), and in some cases, you can get one-on-one tuition, which can help you out enormously. But whether it's freely-given help on a mailing list, group lectures, or personal tutoring, you won't get people just giving you the code - not if they care about you becoming a competent programmer, anyway. ChrisA From breamoreboy at gmail.com Fri Sep 30 16:06:15 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 30 Sep 2016 13:06:15 -0700 (PDT) Subject: Counting words in a string?? In-Reply-To: References: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Message-ID: On Friday, September 30, 2016 at 8:12:47 PM UTC+1, Jake wrote: > On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki wrote: > > On Oct 1, 2016 12:10 AM, "Jake" wrote: > > > > > > Hi, I need a program which: > > > 1) Asks the user for a sentence of their choice (not including > > punctuation) > > > 2) Ask the user which word they would like to know is repeated > > > 3) Print out to the user how many times the word came up which they chose > > from their sentence. > > > > > > > typical home work assignment, even though stop asking for programs and > > start asking how to make the same. > > > > anyway if you ever try to write code for this you have to split you > > sentence and use a dict for counting > > > > Python has Counter from collections but it is a little bit slower when > > compared to defaultdict for this kind of purpose. > > > > Regards > > Srinivas Devaki > > Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad > > Computer Science and Engineering Department > > ph: +91 9491 383 249 > > telegram_id: @eightnoteight > > ---------- > Could you make the program for me or provide an outline? We'll start work as soon as your cheque made payable to the Python Software Foundation has been cashed. It works a bit like the Monty Python "Blackmail" sketch, the higher the grade you want, the more you have to pay. From none at invalid.com Fri Sep 30 16:06:56 2016 From: none at invalid.com (mm0fmf) Date: Fri, 30 Sep 2016 21:06:56 +0100 Subject: Counting words in a string?? In-Reply-To: References: <5e05e6a3-b26b-4aaa-b059-c66e249a93d4@googlegroups.com> Message-ID: On 30/09/2016 20:12, Jake wrote: > On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki wrote: >> On Oct 1, 2016 12:10 AM, "Jake" wrote: >>> >>> Hi, I need a program which: >>> 1) Asks the user for a sentence of their choice (not including >> punctuation) >>> 2) Ask the user which word they would like to know is repeated >>> 3) Print out to the user how many times the word came up which they chose >> from their sentence. >>> >> >> typical home work assignment, even though stop asking for programs and >> start asking how to make the same. >> >> anyway if you ever try to write code for this you have to split you >> sentence and use a dict for counting >> >> Python has Counter from collections but it is a little bit slower when >> compared to defaultdict for this kind of purpose. >> >> Regards >> Srinivas Devaki >> Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad >> Computer Science and Engineering Department >> ph: +91 9491 383 249 >> telegram_id: @eightnoteight > > ---------- > Could you make the program for me or provide an outline? > How much will you pay for a commented program or an outline? From breamoreboy at gmail.com Fri Sep 30 16:14:48 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 30 Sep 2016 13:14:48 -0700 (PDT) Subject: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python? In-Reply-To: References: Message-ID: <8f751baa-66f3-4169-8bf8-147d13d898e5@googlegroups.com> On Friday, September 30, 2016 at 7:16:10 PM UTC+1, Les Cargill wrote: > A really interesting design approach in Tcl is to install a callback > when a variable is written to. This affords highly event-driven > programming. > > Example ( sorry; it's Tcl ) : > > > namespace eval events { > set preRPM -1 > proc handleRPM { args } { > # do stuff to handle an RPM change here > variable ::motor::RPM > variable preRPM > puts "RPM changed from $preRPM to $RPM > set preRPM $RPM > } > } > > ... > > trace variable ::motor::RPM w ::events::handleRPM > > ... > > set ::motor::RPM 33.33 > > What is an equivalent mechanism in Python? > > Thanks in advance. > > -- > Les Cargill Perhaps you could pinch the idea, or even the code, from tkinter? E.g. see the section "Variable tracing" at http://stupidpythonideas.blogspot.co.uk/2013/12/tkinter-validation.html Kindest regards. Mark Lawrence. From irmen.NOSPAM at xs4all.nl Fri Sep 30 18:59:12 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 1 Oct 2016 00:59:12 +0200 Subject: rocket simulation game with just using tkinter Message-ID: <57eeee41$0$911$e4fe514c@news.xs4all.nl> Hi, I've made a very simple rocket simulation game, inspired by the recent success of SpaceX where they managed to land the Falcon-9 rocket back on a platform. I was curious if you can make a simple graphics animation game with just using Tkinter, instead of using other game libraries such as PyGame. As it turns out, that works pretty well and it was quite easy to write. Granted, there's not much going on on the screen, but still the game runs very smoothly and I think it is fun for a little while where you try to learn to control the rocket and attempt to successfully land it on the other launchpad! The physics simulation is tied to the game's frame rate boohoo, but the upside is that you can change the framerate to control the game's difficulty. It's easy at <=20, fun at 30 and impossible at 60 :) It's running on 30 by default. You can get the code here if you want to give it a try: https://github.com/irmen/rocketsimulator So you just need python 2/3 with tkinter to play this! Have fun Irmen From steven.truppe at chello.at Fri Sep 30 20:23:02 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Sat, 1 Oct 2016 02:23:02 +0200 Subject: Could find libpython.so after succesfull compilation. Message-ID: <51a6e7e3-5e8a-31e8-0989-78a73a0a0a1c@chello.at> Hi all, i've compiled python3.5 and all went fine, i find ./python and it works, most of the make test stuff is working my only problem is that i'm not able to find libpython.so .... am i missing somehting ? Thianks in advance From greg.ewing at canterbury.ac.nz Fri Sep 30 20:46:16 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 01 Oct 2016 13:46:16 +1300 Subject: unintuitive for-loop behavior In-Reply-To: <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > Giving for-loops their own namespace is a grossly unintuitive and a very > weird thing to do. > > It would be terribly inconvenient and surprising for if...else blocks to be > separate namespaces: There's an important difference between a for-loop and an if-statement that's relevant here: a for-loop binds a name, whereas an if-statement doesn't. Whenever there's binding going on, it's necessary to decide whether it should be creating a new binding or updating an existing one. This is actually a *different* issue from one of scope. List comprehensions were changed so that the loop variable lives in a different scope from the containing function. However, they still have the same unintuitive behaviour with regard to capture of the loop variable by a lambda. >> l = [lambda: i for i in range(3)] >>> for f in l: print(f()) ... 2 2 2 Most people consider *this* behaviour to be far weirder than anything that would result from giving for-loop variables their own scope. Even if you don't think it's weird, it's hard to argue that it's *useful* in any significant number of cases. > To me, "make for-loops be their own scope" sounds like a joke feature out of > joke languages like INTERCAL. Which is a straw man, since that's not actually what we're talking about doing. It's neither necessary nor sufficient to solve the problem. What *is* necessary and sufficient is to make each iteration of the for-loop create a new binding of the loop variable (and not any other variable!). > I'm not aware of any sensible language that > does anything like this. Scheme and Ruby come to mind as examples of languages in which the equivalent of a for-loop results in each iteration getting a new binding of the control variable. Although you could argue that these languages are not "sensible". :-) -- Greg From greg.ewing at canterbury.ac.nz Fri Sep 30 21:08:20 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 01 Oct 2016 14:08:20 +1300 Subject: unintuitive for-loop behavior In-Reply-To: <57eeaf11$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <06dfb5d8-e477-4b77-a015-f5569e44bdb4@googlegroups.com> <57eeaf11$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > What happens if it is *not* a misfeature? Gotchas are not always > misfeatures -- sometimes gotchas are gotchas because people's expectations > are simply wrong, and pandering to their confused expectations does not > actually help them. > > I haven't made up my mind about *this* specific (mis)feature itself. Here's my analysis of it. First, some definitions: Current behaviour: The way for-loop variables currently interact with nested functions. Alternative behaviour: A nested function captures a different instance of the for-loop variable on each iteration. (But *nothing* else changes; in particular, the body of the loop is *not* a separate scope.) The current behaviour is completely useless (or at least it's useful in in only a vanishingly small proportion of cases). The alternative behaviour would sometimes be useful. Nothing would need to change except in the rare case where the loop variable is referenced by a nested function. You would only pay for the feature if you used it. There would be no need for ugly workarounds such as default argument abuse or introducing another level of nested function. As a bonus, the alternative behaviour would be more in line with people's intuitions. There are some sharp contrasts here with the default argument situation. There, the alternative behaviour would be very wasteful in the majority of cases, and there is a clean workaround for cases where a mutable default is needed. -- Greg From tjreedy at udel.edu Fri Sep 30 21:17:55 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Sep 2016 21:17:55 -0400 Subject: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python? In-Reply-To: References: Message-ID: On 9/30/2016 2:23 PM, Les Cargill wrote: > > A really interesting design approach in Tcl is to install a callback > when a variable is written to. This affords highly event-driven > programming. > > Example ( sorry; it's Tcl ) : > > > namespace eval events { > set preRPM -1 > proc handleRPM { args } { > # do stuff to handle an RPM change here > variable ::motor::RPM > variable preRPM > puts "RPM changed from $preRPM to $RPM > set preRPM $RPM > } > } > > ... > > trace variable ::motor::RPM w ::events::handleRPM 'trace variable' and the corresponding 'trace vdelete' and trace vinfo' have been deprecated in favor of the newer 'trace add variable', 'trace remove variable', and 'trace info variable. In 3.6, the tkinter Variable class has corresponding new trace_add, trace_remove, and trace_info methods. > ... > > set ::motor::RPM 33.33 The cost of being able to trace variables is having to set them through a method that can check for the existence of callbacks. The are used in tk to connect the values of widgets. > What is an equivalent mechanism in Python? Python has a trace module for functions and lines, rather than variables. I believe the primary intended use is for debugging. The Variable class in tkinter.__init__, currently about line 290, wraps the tcl mechanism so it literally is the 'equivalent mechanism' in Python. It could be rewritten to do everything in Python instead of calling into tk. However, it can also be used as it without displaying a gui window. Use what you already know. import tkinter as tk root = tk.Tk() # Only needed to create Vars. root.withdraw() # So keep it invisible. avar = tk.StringVar(root) avar.trace_add('write', lambda tk_id, unknown, mode: print(avar.get(), tk_id, unknown, mode)) # See >>> help(tk.Variable.trace_add) for more. avar.set('abc') avar.set('def') * prints abc PY_VAR0 write # 'unknown' == '' def PY_VAR0 write Since you are familiar with tcl, you could potentially use root.call() to call into tcl yourself. There are other packages in Python that implement the idea of broadcasting a change to a set of reistered listeners. -- Terry Jan Reedy From jfong at ms4.hinet.net Fri Sep 30 21:27:32 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 30 Sep 2016 18:27:32 -0700 (PDT) Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: <6204fe91-c854-44a7-be3a-25d6265845b3@googlegroups.com> References: <682e117e-3c50-4e61-9493-bc3167f7a039@googlegroups.com> <6204fe91-c854-44a7-be3a-25d6265845b3@googlegroups.com> Message-ID: Paul Moore at 2016/9/30 7:07:35PM wrote: > OK. So if your Python code only calls the function once, the problem needs to be fixed in the external code (the assembly routine). But if you can split up the task at the Python level to make multiple calls to the function, each to do a part of the task, then you could set up multiple threads in your Python code, each of which handles part of the task, then Python merges the results of the sub-parts to give you the final answer. Does that make sense to you? Without any explicit code, it's hard to be sure I'm explaining myself clearly. > That's what I will do later, to split the task into multiple cores by passing a range parameter (such as 0~14, 15~29, ..) to each instance. Right now, I just embedded the range in the function to make it simple on testing. At this moment my interest is how to make it runs at 100% core usage. Windows task manager shows this function takes only ~70% usage, and the number varies during its execution, sometimes even drop to 50%. I also had test a batch file (copied from another discussion forum): @echo off :loop goto loop It takes ~85% usage, and the number is stable. The result is obviously different. My question is how to control it:-) --Jach From flebber.crue at gmail.com Fri Sep 30 21:55:09 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 30 Sep 2016 18:55:09 -0700 (PDT) Subject: how to append to list in list comprehension Message-ID: <534d5506-1810-4a79-ac8f-95a664d17827@googlegroups.com> I have a list of lists of numbers like this excerpt. ['0', '0', '0', '0'] ['0', '0', '0', '0'] ['0', '0', '0', '0'] ['0', '0', '0', '0'] ['0', '0', '0', '0'] ['0', '0', '0', '0'] ['7', '2', '1', '0', '142647', '00'] ['7', '2', '0', '1', '87080', '00'] ['6', '1', '1', '1', '51700', '00'] ['4', '1', '1', '0', '36396', '00'] I want to go threw and for each index error at [4] append a 0. I have called the lists fups. p = re.compile('\d+') fups = p.findall(nomattr['firstup']) [x[4] for x in fups if IndexError fups.append(0)] print(fups) Unsure why I cannot use append in this instance, how can I modify to acheive desired output? Desired Output ['0', '0', '0', '0', '0'] ['0', '0', '0', '0', '0'] ['0', '0', '0', '0', '0'] ['0', '0', '0', '0', '0'] ['0', '0', '0', '0', '0'] ['0', '0', '0', '0', '0'] ['7', '2', '1', '0', '142647', '00'] ['7', '2', '0', '1', '87080', '00'] ['6', '1', '1', '1', '51700', '00'] ['4', '1', '1', '0', '36396', '00'] Thanks Sayth From gordon at panix.com Fri Sep 30 22:18:05 2016 From: gordon at panix.com (John Gordon) Date: Sat, 1 Oct 2016 02:18:05 +0000 (UTC) Subject: how to append to list in list comprehension References: <534d5506-1810-4a79-ac8f-95a664d17827@googlegroups.com> Message-ID: In <534d5506-1810-4a79-ac8f-95a664d17827 at googlegroups.com> Sayth Renshaw writes: > I want to go threw and for each index error at [4] append a 0. You want to append 0 if the list does not have at least 5 items? > p = re.compile('\d+') > fups = p.findall(nomattr['firstup']) > [x[4] for x in fups if IndexError fups.append(0)] > print(fups) > Unsure why I cannot use append in this instance Because that's incorrect syntax. > how can I modify to acheive desired output? for f in fups: if len(f) < 5: f.append(0) Or, if you really want to use a list comprehension: [f.append(0) for f in fups if len(f) < 5] However there's no reason to use a list comprehension here. The whole point of list comprehensions is to create a *new* list, which you don't appear to need; you just need to modify the existing fups list. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steven.truppe at chello.at Fri Sep 30 22:19:17 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Sat, 1 Oct 2016 04:19:17 +0200 Subject: Could find libpython.so after succesfull compilation. In-Reply-To: <51a6e7e3-5e8a-31e8-0989-78a73a0a0a1c@chello.at> References: <51a6e7e3-5e8a-31e8-0989-78a73a0a0a1c@chello.at> Message-ID: I fond this in the ./configuration help: * --enable-shared disable/enable building shared python library* so i tried: $configure --enabled-shard but i can't still find a library inside my build directory. On 2016-10-01 02:23, Steven Truppe wrote: > Hi all, > > > i've compiled python3.5 and all went fine, i find ./python and it > works, most of the make test stuff is working my only problem is that > i'm not able to find libpython.so .... > > > am i missing somehting ? > > > Thianks in advance > From steven.truppe at chello.at Fri Sep 30 22:20:12 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Sat, 1 Oct 2016 04:20:12 +0200 Subject: Could find libpython.so after succesfull compilation. In-Reply-To: <51a6e7e3-5e8a-31e8-0989-78a73a0a0a1c@chello.at> References: <51a6e7e3-5e8a-31e8-0989-78a73a0a0a1c@chello.at> Message-ID: Damn i'm so stupid... the files where in fron on of my eyes and i was just not able to find then .. On 2016-10-01 02:23, Steven Truppe wrote: > Hi all, > > > i've compiled python3.5 and all went fine, i find ./python and it > works, most of the make test stuff is working my only problem is that > i'm not able to find libpython.so .... > > > am i missing somehting ? > > > Thianks in advance > From rosuav at gmail.com Fri Sep 30 23:24:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Oct 2016 13:24:48 +1000 Subject: How to make a foreign function run as fast as possible in Windows? In-Reply-To: References: <682e117e-3c50-4e61-9493-bc3167f7a039@googlegroups.com> <6204fe91-c854-44a7-be3a-25d6265845b3@googlegroups.com> Message-ID: On Sat, Oct 1, 2016 at 11:27 AM, wrote: > At this moment my interest is how to make it runs at 100% core usage. Windows task manager shows this function takes only ~70% usage, and the number varies during its execution, sometimes even drop to 50%. > What's it doing? Not every task can saturate the CPU - sometimes they need the disk or network more. ChrisA From random832 at fastmail.com Fri Sep 30 23:25:05 2016 From: random832 at fastmail.com (Random832) Date: Fri, 30 Sep 2016 23:25:05 -0400 Subject: unintuitive for-loop behavior In-Reply-To: References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1475292305.1216671.742528841.7309BC44@webmail.messagingengine.com> On Fri, Sep 30, 2016, at 20:46, Gregory Ewing wrote: > What *is* necessary and sufficient is to make each iteration > of the for-loop create a new binding of the loop variable > (and not any other variable!). I don't think that's true. I think this is logic that is excessively tied to the toy examples that are used to illustrate the problem. You don't think it's common [at least, as far as defining a lambda inside a loop at all is common] to do something like this? for a in collection: b = some_calculation_of(a) do_something_with(lambda: ... b ...) There's a reason that C++'s solution to this problem is an explicit list of what names are captured as references vs values inside the lambda. I think what we really need is an explicit expression/block that gives a list of names and says that all uses of that name in any function defined inside the expression/block refer to the value that that expression had when the expression/block was entered. Suppose: [final exponent: lambda base: (base ** exponent) for exponent in range(9)] for exponent in range: 9 final exponent: def pwr(base): return base ** exponent result.append(pwr) for a in collection: b = some_calculation_of(a) final b: do_something_with(lambda: ... b ...) Maybe do stuff like "for final var in ..." for both loops and comprehensions, or "final var = expr:", depending on if we can make the intuitive-looking syntax well-defined. "final" is a placeholder for whatever new keyword is chosen, though I will note that even though IIRC Guido doesn't like this sort of thing, it would only appear next to identifiers in the proposed syntax and two identifiers not joined by an operator is meaningless. An alternative would be, considering that the problem only applies to nested functions, to expand the "keyword argument" hack into a less-"hacky" and less verbose solution, e.g. "lambda base, $exponent: base ** exponent" - creating, in effect, a keyword argument with the name 'exponent' that can't actually be passed in to the function. From rustompmody at gmail.com Fri Sep 30 23:28:33 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 Sep 2016 20:28:33 -0700 (PDT) Subject: how to append to list in list comprehension In-Reply-To: References: <534d5506-1810-4a79-ac8f-95a664d17827@googlegroups.com> Message-ID: <902d948c-e8c1-4701-91c1-a07bb1060572@googlegroups.com> On Saturday, October 1, 2016 at 7:48:19 AM UTC+5:30, John Gordon wrote: > In Sayth Renshaw writes: > > > I want to go threw and for each index error at [4] append a 0. > > You want to append 0 if the list does not have at least 5 items? > > > p = re.compile('\d+') > > fups = p.findall(nomattr['firstup']) > > [x[4] for x in fups if IndexError fups.append(0)] > > print(fups) > > > Unsure why I cannot use append in this instance > > Because that's incorrect syntax. > > > how can I modify to acheive desired output? > > for f in fups: > if len(f) < 5: > f.append(0) > > Or, if you really want to use a list comprehension: > > [f.append(0) for f in fups if len(f) < 5] Wrong fups = [['0', '0', '0', '0'], ['0', '0', '0', '0'], ['0', '0', '0', '0'], ['0', '0', '0', '0'], ['0', '0', '0', '0'], ['0', '0', '0', '0'], ['7', '2', '1', '0', '142647', '00'], ['7', '2', '0', '1', '87080', '00'], ['6', '1', '1', '1', '51700', '00'], ['4', '1', '1', '0', '36396', '00'] ] >>> [f.append(0) for f in fups if len(f) < 5] [None, None, None, None, None, None] Or right if you re-squint: >>> fups [['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], ['7', '2', '1', '0', '142647', '00'], ['7', '2', '0', '1', '87080', '00'], ['6', '1', '1', '1', '51700', '00'], ['4', '1', '1', '0', '36396', '00']] >>> Which is to say that imperative code ? .append ? inside a comprehension is a bad idea One comprehension way to do it would be: >>> [(f + ['0'] if len(f) < 5 else f) for f in fups ] [['0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0'], ['7', '2', '1', '0', '142647', '00'], ['7', '2', '0', '1', '87080', '00'], ['6', '1', '1', '1', '51700', '00'], ['4', '1', '1', '0', '36396', '00']] From flebber.crue at gmail.com Fri Sep 30 23:37:58 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 30 Sep 2016 20:37:58 -0700 (PDT) Subject: how to append to list in list comprehension In-Reply-To: References: <534d5506-1810-4a79-ac8f-95a664d17827@googlegroups.com> Message-ID: > > I want to go threw and for each index error at [4] append a 0. > > You want to append 0 if the list does not have at least 5 items? > > > p = re.compile('\d+') > > fups = p.findall(nomattr['firstup']) > > [x[4] for x in fups if IndexError fups.append(0)] > > print(fups) > > > Unsure why I cannot use append in this instance > > Because that's incorrect syntax. > > > how can I modify to acheive desired output? > > for f in fups: > if len(f) < 5: > f.append(0) > > Or, if you really want to use a list comprehension: > > [f.append(0) for f in fups if len(f) < 5] > > However there's no reason to use a list comprehension here. The whole > point of list comprehensions is to create a *new* list, which you don't > appear to need; you just need to modify the existing fups list. > > -- > John Gordon A is for Amy, who fell down the stairs B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" You are right John in that I don't want a new list I just wish to modify in-place to acheive the desired output. I had no direct desire to use list comprehension just seemed an option. Ultimately once it works I will abstract it into a function for other lists that will have a similar issue. def listClean(fups) holder = [(f + ['0'] if len(f) < 5 else f) for f in fups ] return holder[0], holder[1], holder[2], holder[3], holder[4] and then call it in my csv.writer that I have, which currently errors quite correctly that it cannot write index[4] as some of my lists fail it. I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if there are better non list comprehension options I would like to know as generally I find then confusing. Cheers Sayth From rustompmody at gmail.com Fri Sep 30 23:44:53 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 30 Sep 2016 20:44:53 -0700 (PDT) Subject: unintuitive for-loop behavior In-Reply-To: References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50a8d925-2bf7-4e34-ac92-d3288f529b6b@googlegroups.com> For the most part you've taken the words out of my mouth! Some more details... On Saturday, October 1, 2016 at 6:16:32 AM UTC+5:30, Gregory Ewing wrote: > Steve D'Aprano wrote: > > Giving for-loops their own namespace is a grossly unintuitive and a very > > weird thing to do. > > > > It would be terribly inconvenient and surprising for if...else blocks to be > > separate namespaces: > > There's an important difference between a for-loop and an > if-statement that's relevant here: a for-loop binds a name, > whereas an if-statement doesn't. > > Whenever there's binding going on, it's necessary to decide > whether it should be creating a new binding or updating an > existing one. > > This is actually a *different* issue from one of scope. > List comprehensions were changed so that the loop variable > lives in a different scope from the containing function. > However, they still have the same unintuitive behaviour > with regard to capture of the loop variable by a lambda. > > >> l = [lambda: i for i in range(3)] > >>> for f in l: print(f()) > ... > 2 > 2 > 2 > > Most people consider *this* behaviour to be far weirder > than anything that would result from giving for-loop > variables their own scope. > > Even if you don't think it's weird, it's hard to argue > that it's *useful* in any significant number of cases. > > > To me, "make for-loops be their own scope" sounds like a joke feature out of > > joke languages like INTERCAL. > > Which is a straw man, since that's not actually what we're > talking about doing. It's neither necessary nor sufficient > to solve the problem. > > What *is* necessary and sufficient is to make each iteration > of the for-loop create a new binding of the loop variable > (and not any other variable!). Yes one basic problem with comprehensions in python is that they are defined by assignment not binding to the comprehension variable > > > I'm not aware of any sensible language that > > does anything like this. > > Scheme and Ruby come to mind as examples of languages in > which the equivalent of a for-loop results in each iteration > getting a new binding of the control variable. Although > you could argue that these languages are not "sensible". :-) Python copied comprehensions from haskell and copied them wrong Here are all the things (that I can think of) that are wrong: 1. Scope leakage from inside to outside the comprehension 2. Scope leakage from one value to the next 3. The name 'for' misleadingly associates for-loops and comprehensions 4. The for-loop based implementation strategy made into definitional semantics 5. The absence of simple binding inside comprehensions: [f(newvar) for v in l newvar = rhs] 1 was considered sufficiently important to make a breaking change from python2 to 3 2 is what causes the lambda gotcha 3 is what makes noobs to take longer than necessary to grok them 4 is what causes a useless distinction between 1 and 2 ? scope leakage is scope leakage. The explanatory mechanisms of why/whither/what etc should at best be secondary 5. is workaroundable with a [... for newvar in [rhs]] Possible and clunky From steve+python at pearwood.info Fri Sep 30 23:52:08 2016 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 01 Oct 2016 13:52:08 +1000 Subject: unintuitive for-loop behavior References: <788a06d3-ee8c-460c-8ab6-1d72da300a38@googlegroups.com> <57ee5bb4$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57ef32ea$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sat, 1 Oct 2016 10:46 am, Gregory Ewing wrote: > Steve D'Aprano wrote: >> Giving for-loops their own namespace is a grossly unintuitive and a very >> weird thing to do. >> >> It would be terribly inconvenient and surprising for if...else blocks to >> be separate namespaces: > > There's an important difference between a for-loop and an > if-statement that's relevant here: a for-loop binds a name, > whereas an if-statement doesn't. That's incorrect: either can bind any number of names: if condition: a = 1 b = 2 else: a = 222 b = 111 for i in seq: x = i + 1 y = x**2 z = 3*y > Whenever there's binding going on, it's necessary to decide > whether it should be creating a new binding or updating an > existing one. Right. > This is actually a *different* issue from one of scope. > List comprehensions were changed so that the loop variable > lives in a different scope from the containing function. > However, they still have the same unintuitive behaviour > with regard to capture of the loop variable by a lambda. > > >> l = [lambda: i for i in range(3)] > >>> for f in l: print(f()) > ... > 2 > 2 > 2 > > Most people consider *this* behaviour to be far weirder > than anything that would result from giving for-loop > variables their own scope. > > Even if you don't think it's weird, it's hard to argue > that it's *useful* in any significant number of cases. Firstly, let's agree (or perhaps we don't?) that loop variables are the same kind of variable as any other. It would be strange and confusing to have different kinds of variables with different binding and lookup rules based on where they came from. The whole list comprehension and lambda syntax is a red herring. Let's write it like this: alist = [] for i in (0, 1, 2): def func(): return i alist.append(func) for f in alist: print(f()) And the output is the same: 2 2 2 Okay, that's inconvenient and not what I wanted. Obviously. But as they say about computers, "this damn machine won't do what I want, only what I tell it to do". It did *exactly what I told it to do*, and, yes, that is a good thing. Let's remember that the variable i is no more special than any other variable: alist = [] x = 0 for i in (0, 1, 2): def func(): return x alist.append(func) x = 999 # What do you predict the functions will return? for f in alist: print(f()) Are you surprised that each of the func()'s return the same value, the current value of x instead of whatever accidental value of x happened to exist when the function was defined? I should hope not. I would expect that most people would agree that variable lookups should return the value of the variable *as it is now*, not as it was when the function was defined. Let's call that Rule 1, and I say it is fundamental to being able to reason about code. If I say: x = 1 spam(x) then spam() MUST see the current value of x, namely 1, not some mysterious value of x that happened to exist long ago in the mists of time when spam() was first defined. And Rule 1 needs to apply to ALL variable look ups, not just arguments to functions. Closures, of course, are a special case of Rule 1, not an exception: def make(arg): x = arg def func(): return x return func f = make(0) print(f()) *Without* closures, that would lead to a NameError (unless there happened to be a global called "x"): the local variables of make() no longer exist, so you cannot refer to them. That was the behaviour in Python 1.5, for example. But *with* closures, the local variables still exist: the inner function grabs the surrounding environment (or at least as much as it needs) and keeps it alive, so that it can look up names in that surrounding scope. What do you expect should happen here? def make(arg): x = arg def func(): return x x = 999 return func f = make(0) print(f()) By Rule 1, the only sensible behaviour is for f() to return 999, regardless of whether it is convenient or not, regardless of whether that is what I intended or not. The interpreter shouldn't try to guess what I mean, it shouldn't cache variable look-ups, and it shouldn't try to give x special behaviour different from all other variables just so this special case is more convenient. But wait, I hear you say, what about closures? They cache the value of the surrounding variables don't they? Perhaps in a sense, but only a weak sense. Each call to make() creates a *new* local environment (its a function, each time you call a function it starts completely afresh) so each of the inner functions returned is independent of the others, with its own independent closure. And each inner function still looks up the current value of *their own* closed-over x, not a snapshot of x as it was when the inner function was defined. Final step: let's unroll that original loop. l = [lambda: i for i in range(3)] for f in l: print(f()) becomes: l = [] i = 0 l.append(lambda: i) i = 1 l.append(lambda: i) i = 2 l.append(lambda: i) for f in l: print(f()) Are you still surprised that it prints 2 2 2? Is this still "unintuitive"? I say it isn't, and at the risk of coming across as smug and obnoxious I'm going to say that anyone who *claims* to still be surprised that the three lambda functions all print the same value for i, namely 2, is almost certainly playing ignorant because they're unwilling to admit that the actual behaviour of Python here is exactly what we should both expect and desire, if only we think about it rather than hoping for some magical Do What I Mean semantics. Of course all three functions print the same value -- they're all looking up the same variable, which can only have one value at a time. And the *last* thing we would want would be for functions to magically take a snapshot of variables' value at the time of function creation. (And no, closures do not violate that rule -- they're a special case, not an exception.) >> To me, "make for-loops be their own scope" sounds like a joke feature out >> of joke languages like INTERCAL. > > Which is a straw man, since that's not actually what we're > talking about doing. Jeez, how is it a strawman when the OP **specifically and explicitly** refers to making for-loops their own scope??? Quote: all along i assumed that for-loops got a namespace of their own ... has there ever been any discussion of giving for-loops the option of running in namespaces of their own? Donald Trump says that when elected president, he'll build a wall to keep Mexicans out of the US. When people call him out on this and explain how stupid that idea is, do you call it a strawman too? A strawman is a weak argument that your opponent DID NOT MAKE, not any weak argument. It is not a fallacy to directly challenge weak arguments. But false accusations of strawman is a fallacy: poisoning the well. > It's neither necessary nor sufficient > to solve the problem. Right. But that's not *my* problem. > What *is* necessary and sufficient is to make each iteration > of the for-loop create a new binding of the loop variable > (and not any other variable!). No, that's not right -- they're already new bindings. Variable bindings in Python are not in-place modifications of a variable like in C, where the variable is some bucket where you can modify the value in place. They are values bound to a key in a namespace. If you don't believe me, try this: alist = [] for i in (0, 1, 2): def func(): return i alist.append(func) if i == 2: continue del i Does it make *any* difference at all to the behaviour? Apart from being a tiny bit slower, no, of course it does not. >> I'm not aware of any sensible language that >> does anything like this. > > Scheme and Ruby come to mind as examples of languages in > which the equivalent of a for-loop results in each iteration > getting a new binding of the control variable. Although > you could argue that these languages are not "sensible". :-) :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse.