From no.email at nospam.invalid Wed Jun 1 00:16:41 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 31 May 2016 21:16:41 -0700 Subject: Efficient handling of fast, real-time hex data References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> Message-ID: <87h9ddee6u.fsf@jester.gateway.pace.com> jladasky at itu.edu writes: > high rate, about 5,000 16-bit unsigned integers per second.... > Using PySerial to handle UART over USB. Intel Core i7-4790K CPU @ > 4.00GHz. This really should not be an issue. That's not such a terribly high speed, and there's enough buffering in the kernel that you shouldn't lose anything. From greg.ewing at canterbury.ac.nz Wed Jun 1 00:37:01 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 01 Jun 2016 16:37:01 +1200 Subject: Efficient handling of fast, real-time hex data In-Reply-To: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> Message-ID: jladasky at itu.edu wrote: > So, how can I take the byte sequence <0x01 0x02 0x03 0x04 0x05 0x06 \n> that > Serial.readline() returns to me, Using readline() to read binary data doesn't sound like a good idea -- what happens if one of the data bytes happens to be 0x0a? If you're going binary, it would be better to ditch the newlines and read a fixed number of bytes each time. Regarding speed, if struct.unpack or numpy isn't fast enough, you may need to deal with the data in bigger chunks. Although if you're not doing a huge amount of processing with them, I'd expect it to be plenty fast enough. I just did a quick test, and I was able to unpack about 700,000 random 6-byte strings per second on a 2.8GHz Xeon. -- Greg From muhammadaliaskari at gmail.com Wed Jun 1 00:50:33 2016 From: muhammadaliaskari at gmail.com (Muhammad Ali) Date: Tue, 31 May 2016 21:50:33 -0700 (PDT) Subject: Self Learning Fortran Programming Message-ID: <07380e97-c11b-4790-9bb5-a7e90617281b@googlegroups.com> Hello, I am interested in Python programming, however, it will be my first serious attempt towards coding/simulation/programming. My back ground is Physics, no practical experience with programming languages. So, this post is for the valuable suggestions from the experts that how can I start self learning Python from scratch to advanced level in minimum time. For this, please recommend Python version, literature, text books, websites, video lectures, your personnel tips, etc. In addition, you may also add some extra suggestions for shell script writing as well. You may recommend for both Linux and Windows operating systems. Looking for your posts. Thank you. From joel.goldstick at gmail.com Wed Jun 1 01:47:30 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 1 Jun 2016 01:47:30 -0400 Subject: Self Learning Fortran Programming In-Reply-To: <07380e97-c11b-4790-9bb5-a7e90617281b@googlegroups.com> References: <07380e97-c11b-4790-9bb5-a7e90617281b@googlegroups.com> Message-ID: start here: https://www.python.org/about/gettingstarted/ On Wed, Jun 1, 2016 at 12:50 AM, Muhammad Ali wrote: > > Hello, > > I am interested in Python programming, however, it will be my first serious attempt towards coding/simulation/programming. My back ground is Physics, no practical experience with programming languages. > > So, this post is for the valuable suggestions from the experts that how can I start self learning Python from scratch to advanced level in minimum time. For this, please recommend Python version, literature, text books, websites, video lectures, your personnel tips, etc. In addition, you may also add some extra suggestions for shell script writing as well. You may recommend for both Linux and Windows operating systems. > > Looking for your posts. > > Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From dieter at handshake.de Wed Jun 1 03:50:56 2016 From: dieter at handshake.de (dieter) Date: Wed, 01 Jun 2016 09:50:56 +0200 Subject: Manipulate GIL to have Python thread work with pthread native ones References: <1727544946.3450439.1464671782195.JavaMail.zimbra@alumni.sjtu.edu.cn> Message-ID: <87y46pz6sf.fsf@handshake.de> qshhnkf at alumni.sjtu.edu.cn writes: ... Python/C++ integration ... When I learn about a task to integrate Python with C or C++, I first think of "cython". "cython" facilitates those integrations. Especially, it has annotations to control the GIL. I have used "cython" for the implementation of a Python binding to the XML security library. The result ist "dm.xmlsec.binding". There, I use both ("cython") annotations to release the GIL when passing over control from Python to C; as well as ("cython") features to implement a callback from C to Python. From alexandre.horta at gmail.com Wed Jun 1 03:59:43 2016 From: alexandre.horta at gmail.com (Alexandre Paloschi Horta) Date: Wed, 1 Jun 2016 00:59:43 -0700 (PDT) Subject: variable argument unpacking In-Reply-To: <436682ac-ec56-4286-a36e-d5697a9fd83c@googlegroups.com> References: <436682ac-ec56-4286-a36e-d5697a9fd83c@googlegroups.com> Message-ID: <5a371f6a-175d-4546-9cb9-5e6e25f2da64@googlegroups.com> The way you defined the function: def a(a = 1, b = 2, c = 3, *d, **e): print(a, b, c) print(d) print(e) a, b and c are positional arguments. d will be filled with the excess arguments and e will receive a dictionary, if supplied. One thing is the function definition, another is the function call. If you pass a number of arguments, the first three will be assigned to a, b and c no matter what, even if you supplied defaults. Peter's solution turns a, b and c into keyword arguments. That way you can call the function with an arbitrary number of arguments and a, b and c will keep the default values, unless you be explicit about the values you want to assign to a, b and c. From stephen_tucker at sil.org Wed Jun 1 04:40:50 2016 From: stephen_tucker at sil.org (Stephen Tucker) Date: Wed, 1 Jun 2016 09:40:50 +0100 Subject: Self Learning Fortran Programming In-Reply-To: References: <07380e97-c11b-4790-9bb5-a7e90617281b@googlegroups.com> Message-ID: Hi, there, Muhammad, I have found Learning Python by Mark Lutz helpful. The fourth edition covers both Python 2.6 and 3.x. Although it is a text book for a course that Mark delivers, there are useful summaries of the various functions and methods for strings, integers, etc at various spots in the book. Stephen Tucker. Virus-free. www.avast.com <#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2> On Wed, Jun 1, 2016 at 6:47 AM, Joel Goldstick wrote: > start here: > > > https://www.python.org/about/gettingstarted/ > > On Wed, Jun 1, 2016 at 12:50 AM, Muhammad Ali > wrote: > > > > Hello, > > > > I am interested in Python programming, however, it will be my first > serious attempt towards coding/simulation/programming. My back ground is > Physics, no practical experience with programming languages. > > > > So, this post is for the valuable suggestions from the experts that how > can I start self learning Python from scratch to advanced level in minimum > time. For this, please recommend Python version, literature, text books, > websites, video lectures, your personnel tips, etc. In addition, you may > also add some extra suggestions for shell script writing as well. You may > recommend for both Linux and Windows operating systems. > > > > Looking for your posts. > > > > Thank you. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Wed Jun 1 05:22:45 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 1 Jun 2016 05:22:45 -0400 Subject: Recommendation for Object-Oriented systems to study In-Reply-To: References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> Message-ID: On 5/31/2016 1:52 PM, Ankush Thakur wrote: > Hi Terry, > > Can you point me towards the source code? For IDLE 3.4.4 or 3.5.1: /Lib/idlelib/help.py, at least on Windows. > by "after reading it carefully", do you mean you or me? :D You. I wrote it and already read it carefully. >> Beyond "pick a module with classes that interest you", I can suggest >> idlelib.help, which I helped to write. If you ask, after reading it >> carefully, I will point out what I consider positive features. -- Terry Jan Reedy From steve at pearwood.info Wed Jun 1 10:59:48 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 00:59:48 +1000 Subject: Don't put your software in the public domain Message-ID: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> ... because it is extremely unlikely to work. If you actually want your users to be legally able to use your software without a commercial licence, use a recognised open licence like the MIT licence. Public domain dedications are on extremely shaky ground and give your users no protection. http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html -- Steven From ganesh1pal at gmail.com Wed Jun 1 11:39:35 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Wed, 1 Jun 2016 21:09:35 +0530 Subject: re.search - Pattern matching review In-Reply-To: References: Message-ID: Thanks works fine : ) From marko at pacujo.net Wed Jun 1 11:44:25 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 01 Jun 2016 18:44:25 +0300 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8760tskj6u.fsf@elektro.pacujo.net> Steven D'Aprano : > ... because it is extremely unlikely to work. If you actually want > your users to be legally able to use your software without a > commercial licence, use a recognised open licence like the MIT > licence. Public domain dedications are on extremely shaky ground and > give your users no protection. > > http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html http://www.wtfpl.net/faq/ I say, abolish the copyright from the laws altogether. Marko From aaron.christensen at gmail.com Wed Jun 1 11:58:01 2016 From: aaron.christensen at gmail.com (Aaron Christensen) Date: Wed, 1 Jun 2016 11:58:01 -0400 Subject: Breaking down network range to individual networks Message-ID: Hello, Does anyone know about a feature of ipaddress that will take the following network range: "10.224.16.0-10.224.23.0" and convert it to individual networks? I am trying to figure out the best way to take a network range and break it up into the largest possible networks. I started working out some things on paper but I don't want to get too far ahead of myself in case there is a function or easy way that already does this. Thank you for your help! Aaron ------------------------------------------------------------- Pasted some brainstorming below to show that I am actively working this and not just asking before trying. ipaddress.ip_network('10.224.16.0/24') - (ipaddress.ip_network(' 10.224.23.0/24')) IPv4Network IPv4Network('10.224.16.0/24').compare_networks(IPv4Network('10.224.23.0/24') ) str(ipaddress.IPv4Address('192.168.0.1')) IPv4Address('10.224.16.0') + 3 ipaddress.ip_address('10.224.16.0') + 256 0.0.x=0.0 /24 x + 0 /23 x + 1 = 0.0.0.0 /22 x + 3 = 0.0.0.0 1 can be /18 if x = 0 2 can be /19 if x = 0, 32 4 can be /20 if x = 0, 16, 32, 48 8 can be /21 if x = 0, 8, 16, 24, 32, 40, 48, 56 16 can be /22 if x = 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60 32 can be /23 if x = 0 through 62 64 can be /24 if x = 0 though 255 10.224.255.0 start > can be odd > /24 even > /24/23 0 > /22/21/20/19/18... 4 > /22 8 > /22/21 12 > /22 16 > /22/21/20 20 > /22 24 > /22/21 28 > /22 32 > /22/21/20/19 36 > /22 40 > /22/21 44 > /22 48 > /22/21/20 From phd at phdru.name Wed Jun 1 12:01:30 2016 From: phd at phdru.name (Oleg Broytman) Date: Wed, 1 Jun 2016 18:01:30 +0200 Subject: SQLObject 3.0.0 Message-ID: <20160601160130.GA13414@phdru.name> Hello! I'm pleased to announce version 3.0.0, the first stable release of branch 3.0 of SQLObject. What's new in SQLObject ======================= Features -------- * Support for Python 2 and Python 3 with one codebase! (Python version >= 3.4 currently required.) Minor features -------------- * PyDispatcher (>=2.0.4) was made an external dependency. Development ----------- * Source code was made flake8-clean. Documentation ------------- * Documentation is published at http://sqlobject.readthedocs.org/ in Sphinx format. Contributors for this release are Ian Cordasco, Neil Muller, Lukasz Dobrzanski, Gregor Horvath, Nathan Edwards. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Python 2.6, 2.7 or 3.4+ is required. Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: https://pypi.python.org/pypi/SQLObject/3.0.0 News and changes: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From pkpearson at nowhere.invalid Wed Jun 1 12:12:52 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 1 Jun 2016 16:12:52 GMT Subject: Self Learning Fortran Programming References: <07380e97-c11b-4790-9bb5-a7e90617281b@googlegroups.com> Message-ID: On Tue, 31 May 2016 21:50:33 -0700 (PDT), Muhammad Ali wrote: > > I am interested in Python programming, [snip] Just out of curiosity, why do you seem to be confused about whether your interest is in FORTRAN or Python? -- To email me, substitute nowhere->runbox, invalid->com. From lists at mostrom.pp.se Wed Jun 1 13:13:31 2016 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Wed, 01 Jun 2016 19:13:31 +0200 Subject: Recommendation for GUI lib? Message-ID: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> I want to write a few programs with a GUI but I don't want to use Tk. Instead I'm looking for some other library, I've tried to look around and also asked a few but I don't really know what to use. Do you have any recommendations? Primary platforms are OS X and Linux. I, of course, want to have "standard" widgets but a "calendar view"/"date picker" is a plus. = jem From foxprone.r52 at gmail.com Wed Jun 1 13:35:57 2016 From: foxprone.r52 at gmail.com (Anup reni) Date: Wed, 1 Jun 2016 23:05:57 +0530 Subject: Storing data in mysql Message-ID: How to store this 3 dimensional data in Mysql database for plotting on map? ? From jladasky at itu.edu Wed Jun 1 14:03:02 2016 From: jladasky at itu.edu (jladasky at itu.edu) Date: Wed, 1 Jun 2016 11:03:02 -0700 (PDT) Subject: Efficient handling of fast, real-time hex data In-Reply-To: References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> Message-ID: On Tuesday, May 31, 2016 at 9:37:18 PM UTC-7, Gregory Ewing wrote: > > So, how can I take the byte sequence <0x01 0x02 0x03 0x04 0x05 0x06 \n> that > > Serial.readline() returns to me, > > Using readline() to read binary data doesn't sound like > a good idea -- what happens if one of the data bytes > happens to be 0x0a? > > If you're going binary, it would be better to ditch the > newlines and read a fixed number of bytes each time. Hi Greg, Of course you're correct. In my very first version of this system, I piggybacked the transmission of data on the routines that I used to transmit text. That won't be a permanent state of affairs. I guess that I should have posted my example string without the newline, which I will of course strip off before parsing the string into 16-bit integers. Also, now that I've verified that the CPU's at both ends of the line are little-endian, I should have swapped every other byte. :^) One common data transmission error I've seen in other systems is added/dropped bytes. I'm not sure whether to expect this problem with a USB/UART setup. I may add a CRC-8 error-checking byte in place of the newline. > Regarding speed, if struct.unpack or numpy isn't fast > enough, you may need to deal with the data in bigger > chunks. > > Although if you're not doing a huge amount of processing > with them, I'd expect it to be plenty fast enough. > I just did a quick test, and I was able to unpack > about 700,000 random 6-byte strings per second on > a 2.8GHz Xeon. That's an encouraging speed. I'm sure that I'm not doing everything as efficiently as possible yet. I've done some Multiprocessing work before. To speed things up further, I might implement the live graphics in one process and the I/O in another. From muhammadaliaskari at gmail.com Wed Jun 1 14:41:55 2016 From: muhammadaliaskari at gmail.com (Muhammad Ali) Date: Wed, 1 Jun 2016 11:41:55 -0700 (PDT) Subject: Self Learning Fortran Programming In-Reply-To: References: <07380e97-c11b-4790-9bb5-a7e90617281b@googlegroups.com> Message-ID: <0edad38c-59c6-4dbb-bce3-aa1fb01e8a57@googlegroups.com> I don't know how to change the title now, but I am looking for python. From lawrencedo99 at gmail.com Wed Jun 1 16:45:33 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 13:45:33 -0700 (PDT) Subject: Don't put your software in the public domain In-Reply-To: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <92eb87cb-04be-4e69-9387-6d3cb0e2ceaa@googlegroups.com> On Thursday, June 2, 2016 at 3:00:05 AM UTC+12, Steven D'Aprano wrote: > ... because it is extremely unlikely to work. Which is why CC0 https://creativecommons.org/publicdomain/zero/1.0/ was invented. From gokoproject at gmail.com Wed Jun 1 17:00:45 2016 From: gokoproject at gmail.com (John Wong) Date: Wed, 1 Jun 2016 17:00:45 -0400 Subject: Don't put your software in the public domain In-Reply-To: <92eb87cb-04be-4e69-9387-6d3cb0e2ceaa@googlegroups.com> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <92eb87cb-04be-4e69-9387-6d3cb0e2ceaa@googlegroups.com> Message-ID: On Wed, Jun 1, 2016 at 4:45 PM, Lawrence D?Oliveiro wrote: > On Thursday, June 2, 2016 at 3:00:05 AM UTC+12, Steven D'Aprano wrote: > > ... because it is extremely unlikely to work. > > Which is why CC0 https://creativecommons.org/publicdomain/zero/1.0/ was > invented. > -- > This does not solve the dependency copyright issue. From lawrencedo99 at gmail.com Wed Jun 1 17:16:12 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 14:16:12 -0700 (PDT) Subject: Yet Another Cairo API Binding Message-ID: Thought I would mention Qahirah , which is yet another binding for the Cairo graphics library. People using Cairo with Python are probably familiar with Pycairo. Qahirah is similar to Pycairo in some ways, but differs importantly in several others: * It is implemented entirely in Python, using the ctypes module. This offers advantages: automatic support for passing arguments by keyword, and argument names appearing in help() output. * It tries to operate at a higher level than the actual C-centric Cairo API, taking advantage of Python?s powerful data-manipulation facilities. This is explained in the README. * Because it is pure Python, the abstractions it implements are ?leaky?. As Guido van Rossum has made clear, ?We?re all consenting adults here?. If you want to bypass Qahirah?s facilities and make calls directly to the underlying Cairo library, there is nothing to prevent you from doing so. Whether your code will still work with a future version of Qahirah is another matter... I have also published some examples of Qahirah in action. And if you know IPython/Jupyter, here are some interactive notebooks illustrating various 2D graphics concepts using Qahirah. From lawrencedo99 at gmail.com Wed Jun 1 17:44:23 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 14:44:23 -0700 (PDT) Subject: reduction In-Reply-To: References: Message-ID: On Wednesday, June 1, 2016 at 2:22:42 AM UTC+12, Fillmore wrote: > ['a','b','c','l'] => 0 # If "l" is in my data I have a zero > ['a','b','c'] => 1 # or a more generic match will do the job for entry in \ ( ['a','b','c','l'], ['a','b','c'], ) \ : flag = int(not any(m == "l" for m in this_list)) ... # flag is the 1/0 code you?re looking for ... #end for From python at mrabarnett.plus.com Wed Jun 1 18:06:50 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 1 Jun 2016 23:06:50 +0100 Subject: reduction In-Reply-To: References: Message-ID: <9c1c2001-ab34-4a13-e8bf-958f8b74883f@mrabarnett.plus.com> On 2016-06-01 22:44, Lawrence D?Oliveiro wrote: > On Wednesday, June 1, 2016 at 2:22:42 AM UTC+12, Fillmore wrote: >> ['a','b','c','l'] => 0 # If "l" is in my data I have a zero >> ['a','b','c'] => 1 # or a more generic match will do the job > > for entry in \ > ( > ['a','b','c','l'], > ['a','b','c'], > ) \ > : > flag = int(not any(m == "l" for m in this_list)) > ... # flag is the 1/0 code you?re looking for ... > #end for > What is "this_list"? The main 'for' loop has "entry". A shorter way is to use sets: for entry in \ ( ['a','b','c','l'], ['a','b','c'], ) \ : flag = int("l" not in set(entry)) ... # flag is the 1/0 code you?re looking for ... #end for From lawrencedo99 at gmail.com Wed Jun 1 19:32:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 16:32:27 -0700 (PDT) Subject: reduction In-Reply-To: References: <9c1c2001-ab34-4a13-e8bf-958f8b74883f@mrabarnett.plus.com> Message-ID: <10558c5a-c746-4096-a610-5b3e8d786c1c@googlegroups.com> On Thursday, June 2, 2016 at 10:07:21 AM UTC+12, MRAB wrote: > What is "this_list"? The main 'for' loop has "entry". Sorry. :) for entry in \ ( ['a','b','c','l'], ['a','b','c'], ) \ : flag = int(not any(m == "l" for m in entry)) ... # flag is the 1/0 code you?re looking for ... #end for From lawrencedo99 at gmail.com Wed Jun 1 19:39:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 16:39:27 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: Message-ID: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> On Friday, May 20, 2016 at 4:43:56 AM UTC+12, Herkermer Sherwood wrote: > Most keywords in Python make linguistic sense, but using "else" in for and > while structures is kludgy and misleading. My objection is not to the choice of keyword, it?s to the whole design of the loop construct. It turns out C-style for-loops ?for (init; test; incr) ...? are very versatile. If my loop has more than one exit, I use the endless form ?for (;;)? and do an explicit ?break? for every exit condition. Also, they let me declare a variable that is scoped to the loop, that is initialized just once before the loop starts, e.g. for (int loopvar = initial_value;;) { if (loopvar == limit) break; ... processing ... if (found_what_im_looking_for) break; ++loopvar; } /*for*/ I wish I could do this in Python... From lawrencedo99 at gmail.com Wed Jun 1 20:17:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 17:17:27 -0700 (PDT) Subject: How to create development Python environment on Linux. In-Reply-To: References: <815aa265-45c4-40a4-860d-beb89cd9a78e@googlegroups.com> Message-ID: <1833e379-3401-4d1b-9551-2760c72e01af@googlegroups.com> On Tuesday, May 17, 2016 at 4:26:23 AM UTC+12, Zachary Ware wrote: > Not what you asked for, but I would encourage you to look into whether > it's possible for you to use Python 3 instead of Python 2 for what > you're doing. If it's possible, starting with Python 3 will save you > several headaches in the future. Let me add my vote for this. > sys.prefix is baked in at compile time of the python interpreter ... ldo at theon:~> ~/virtualenv/jupyter/bin/python -c "import sys; print(sys.prefix)" /home/ldo/virtualenv/jupyter From lawrencedo99 at gmail.com Wed Jun 1 20:29:08 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 17:29:08 -0700 (PDT) Subject: Manipulate GIL to have Python thread work with pthread native ones In-Reply-To: References: <1727544946.3450439.1464671782195.JavaMail.zimbra@alumni.sjtu.edu.cn> Message-ID: <7321998e-43c1-4d00-8695-87d42f32cb15@googlegroups.com> On Tuesday, May 31, 2016 at 10:14:31 PM UTC+12, qsh... at alumni.sjtu.edu.cn wrote: > PyGILState_Ensure/PyGILState_Release. Without a running sample, it is a > little bit hard to understand how Python thread and the native pthread > interact. Python threads *are* native threads (at least on Linux). The place to release the GIL is where you are a) not making any Python API calls and b) doing something CPU-intensive. Point a) is essential. Here is one of my example extension modules. It doesn?t actually do any multithreading, but I put in the Py_{BEGIN,END}_ALLOW_THREADS calls where I thought it made sense to have them anyway. From marcwbrooks at gmail.com Wed Jun 1 20:30:50 2016 From: marcwbrooks at gmail.com (Marc Brooks) Date: Wed, 1 Jun 2016 20:30:50 -0400 Subject: How to create development Python environment on Linux. In-Reply-To: <1833e379-3401-4d1b-9551-2760c72e01af@googlegroups.com> References: <815aa265-45c4-40a4-860d-beb89cd9a78e@googlegroups.com> <1833e379-3401-4d1b-9551-2760c72e01af@googlegroups.com> Message-ID: I am pretty sure (but not 100%) that the pip that virtualenv installs when it first creates the virtualenv is the version of pip installed on the system. Here's the process I used to bootstrap a new Python 2.7 dev environment. 1. Download and install the latest version of pip as sudo so it's system wide. 2. Install virtualenv and virtualenvwrapper (a collection of utilities scripts/aliases for virtualenv). 3. Update my .bash_profile to source the virtualenvwrapper script. Then for any new virtualenvs I just type 'mkvirtualenv ' I can update the version of pip in the virtualenv or run pip install for any of my required libraries at that point. One wrinkle that can come up is if you want to use virtualenvwrapper and you are not using bash. Fish (another moderately popular shell) has an addon that mimics the macros that virtualenvwrapper provides. Mar On Wed, Jun 1, 2016 at 8:17 PM, Lawrence D?Oliveiro wrote: > On Tuesday, May 17, 2016 at 4:26:23 AM UTC+12, Zachary Ware wrote: > > Not what you asked for, but I would encourage you to look into whether > > it's possible for you to use Python 3 instead of Python 2 for what > > you're doing. If it's possible, starting with Python 3 will save you > > several headaches in the future. > > Let me add my vote for this. > > > sys.prefix is baked in at compile time of the python interpreter ... > > ldo at theon:~> ~/virtualenv/jupyter/bin/python -c "import sys; > print(sys.prefix)" > /home/ldo/virtualenv/jupyter > -- > https://mail.python.org/mailman/listinfo/python-list > From mrak at sightlineinnovation.com Wed Jun 1 20:55:14 2016 From: mrak at sightlineinnovation.com (Marcin Rak) Date: Wed, 1 Jun 2016 17:55:14 -0700 (PDT) Subject: Beginner Question Message-ID: Hi to all I have a beginner question to which I have not found an answer I was able to understand. Could someone explain why the following program: def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2)) print(f(3)) gives us the following result: [1] [1,2] [1,2,3] How can this be, if we never catch the returned L when we call it, and we never pass it on back to f??? Any help is appreciated. Marcin From robertvstepp at gmail.com Wed Jun 1 21:42:34 2016 From: robertvstepp at gmail.com (boB Stepp) Date: Wed, 1 Jun 2016 20:42:34 -0500 Subject: Beginner Question In-Reply-To: References: Message-ID: On Wed, Jun 1, 2016 at 7:55 PM, Marcin Rak wrote: > Hi to all > > I have a beginner question to which I have not found an answer I was able to understand. Could someone explain why the following program: > > def f(a, L=[]): > L.append(a) > return L > > print(f(1)) > print(f(2)) > print(f(3)) > > gives us the following result: > > [1] > [1,2] > [1,2,3] > > How can this be, if we never catch the returned L when we call it, and we never pass it on back to f??? This comes up rather frequently. In fact, if you just copy your function (Which is used in the official Python tutuorial.) and paste it into Google you will get some relevant hits. One such is: https://pythonconquerstheuniverse.wordpress.com/category/python-gotchas/ As the link will explain the behavior you observe is a consequence of two things: When Python assigns the default argument for the empty list and that lists are *mutable*. Enjoy! -- boB From fillmore_remove at hotmail.com Wed Jun 1 22:32:53 2016 From: fillmore_remove at hotmail.com (Fillmore) Date: Wed, 01 Jun 2016 22:32:53 -0400 Subject: reduction References: Message-ID: Thank you, guys. Your suggestions are avaluable. I think I'll go with the tree On 05/31/2016 10:22 AM, Fillmore wrote: > > My problem. I have lists of substrings associated to values: > > ['a','b','c','g'] => 1 > ['a','b','c','h'] => 1 > ['a','b','c','i'] => 1 > ['a','b','c','j'] => 1 > ['a','b','c','k'] => 1 > ['a','b','c','l'] => 0 # <- Black sheep!!! > ['a','b','c','m'] => 1 > ['a','b','c','n'] => 1 > ['a','b','c','o'] => 1 > ['a','b','c','p'] => 1 > > I can check a bit of data against elements in this list > and determine whether the value to be associated to the data is 1 or 0. > > I would like to make my matching algorithm smarter so I can > reduce the total number of lists: > > ['a','b','c','l'] => 0 # If "l" is in my data I have a zero > ['a','b','c'] => 1 # or a more generic match will do the job > > I am trying to think of a way to perform this "reduction", but > I have a feeling I am reinventing the wheel. > > Is this a common problem that is already addressed by an existing module? > > I realize this is vague. Apologies for that. > > thank you From steve+comp.lang.python at pearwood.info Wed Jun 1 23:38:04 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 13:38:04 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <92eb87cb-04be-4e69-9387-6d3cb0e2ceaa@googlegroups.com> Message-ID: <574faa1d$0$1522$c3e8da3$5496439d@news.astraweb.com> On Thursday 02 June 2016 07:00, John Wong wrote: > On Wed, Jun 1, 2016 at 4:45 PM, Lawrence D?Oliveiro > wrote: > >> On Thursday, June 2, 2016 at 3:00:05 AM UTC+12, Steven D'Aprano wrote: >> > ... because it is extremely unlikely to work. >> >> Which is why CC0 https://creativecommons.org/publicdomain/zero/1.0/ was >> invented. >> -- >> > > This does not solve the dependency copyright issue. I do not know what the dependency copyright issue is. -- Steve From steve+comp.lang.python at pearwood.info Wed Jun 1 23:43:26 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 13:43:26 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <92eb87cb-04be-4e69-9387-6d3cb0e2ceaa@googlegroups.com> Message-ID: <574fab60$0$1506$c3e8da3$5496439d@news.astraweb.com> On Thursday 02 June 2016 06:45, Lawrence D?Oliveiro wrote: > On Thursday, June 2, 2016 at 3:00:05 AM UTC+12, Steven D'Aprano wrote: >> ... because it is extremely unlikely to work. > > Which is why CC0 https://creativecommons.org/publicdomain/zero/1.0/ was > invented. Very true. The purpose of CC0 is, in a nutshell, to say: "Put this in the public domain if possible, and if not, have a liberal licence to use it for anything you want, with no warranty." But the question is, since putting things into the public domain is legally dubious, the first part is very likely not possible, which makes it just a more complicated way of saying: "... have a liberal licence to use it for anything you want, with no warranty." -- Steve From steve+comp.lang.python at pearwood.info Wed Jun 1 23:44:30 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 13:44:30 +1000 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: <574faba0$0$1506$c3e8da3$5496439d@news.astraweb.com> On Thursday 02 June 2016 09:39, Lawrence D?Oliveiro wrote: > Also, they let me declare a variable that is scoped to the loop Why do you want variables scoped to the loop? -- Steve From steve+comp.lang.python at pearwood.info Wed Jun 1 23:53:59 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 13:53:59 +1000 Subject: Beginner Question References: Message-ID: <574fadda$0$22141$c3e8da3$5496439d@news.astraweb.com> On Thursday 02 June 2016 10:55, Marcin Rak wrote: > Hi to all > > I have a beginner question to which I have not found an answer I was able to > understand. Could someone explain why the following program: > > def f(a, L=[]): > L.append(a) > return L The default value is set once, and once only, so you get the same list each time, not a new empty list. Default values in Python are sort of like this: HIDDEN_DEFAULT_VALUE = [] # initialised once def f(a, L): if L is not defined: L = HIDDEN_DEFAULT_VALUE L.append(a) return L except that HIDDEN_DEFAULT_VALUE is not actually a global variable. Every function gets its own storage for defaults. The technical term for this is "early binding of default values". If you want to get a new, fresh list each time ("late binding of default values") you should use a sentinel value: def f(a, L=None): if L is None: L = [] # new, fresh list each time L.append(a) return L -- Steve From ikorot01 at gmail.com Thu Jun 2 00:21:33 2016 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 2 Jun 2016 00:21:33 -0400 Subject: Beginner Question In-Reply-To: References: Message-ID: Hi, guys, On Wed, Jun 1, 2016 at 9:42 PM, boB Stepp wrote: > On Wed, Jun 1, 2016 at 7:55 PM, Marcin Rak wrote: >> Hi to all >> >> I have a beginner question to which I have not found an answer I was able to understand. Could someone explain why the following program: >> >> def f(a, L=[]): >> L.append(a) >> return L >> >> print(f(1)) >> print(f(2)) >> print(f(3)) >> >> gives us the following result: >> >> [1] >> [1,2] >> [1,2,3] >> >> How can this be, if we never catch the returned L when we call it, and we never pass it on back to f??? I think the OP question here is: Why it is printing the array? There is no line like: t = f(1) print t So, why the first print does print the list? The return value should be thrown away... Thank you. > > This comes up rather frequently. In fact, if you just copy your > function (Which is used in the official Python tutuorial.) and paste > it into Google you will get some relevant hits. One such is: > > https://pythonconquerstheuniverse.wordpress.com/category/python-gotchas/ > > As the link will explain the behavior you observe is a consequence of > two things: When Python assigns the default argument for the empty > list and that lists are *mutable*. > > Enjoy! > > > -- > boB > -- > https://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Thu Jun 2 01:20:18 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 15:20:18 +1000 Subject: Beginner Question References: Message-ID: <574fc214$0$1585$c3e8da3$5496439d@news.astraweb.com> On Thursday 02 June 2016 14:21, Igor Korot wrote: > Hi, guys, > > On Wed, Jun 1, 2016 at 9:42 PM, boB Stepp wrote: >> On Wed, Jun 1, 2016 at 7:55 PM, Marcin Rak >> wrote: >>> Hi to all >>> >>> I have a beginner question to which I have not found an answer I was able >>> to understand. Could someone explain why the following program: >>> >>> def f(a, L=[]): >>> L.append(a) >>> return L >>> >>> print(f(1)) >>> print(f(2)) >>> print(f(3)) >>> >>> gives us the following result: >>> >>> [1] >>> [1,2] >>> [1,2,3] >>> >>> How can this be, if we never catch the returned L when we call it, and we >>> never pass it on back to f??? > > I think the OP question here is: > > Why it is printing the array? Because he calls the function, then prints the return result. print(f(1)) calls f(1), which returns [1], then prints [1]. Then he calls: print(f(2)) which returns [1, 2] (but he expects [2]), then prints it. And so on. > There is no line like: > > t = f(1) > print t Correct. But there are lines: print(f(1)) print(f(2)) print(f(3)) -- Steve From lawrencedo99 at gmail.com Thu Jun 2 01:44:00 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 22:44:00 -0700 (PDT) Subject: Recommendation for Object-Oriented systems to study In-Reply-To: References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> <201605291812.u4TI9dqP037317@mx0a-001b2d01.pphosted.com> Message-ID: <48967b8e-773b-472d-8a1a-89135e78e4f5@googlegroups.com> On Monday, May 30, 2016 at 7:17:47 AM UTC+12, Alan Evangelista wrote: > - Java forces everything to be implemented in OO model (classes) After you have spend a few months battering your head against the rigidity and verbosity of Java, you will run back to Python with a sense of relief. What a joy it is to use a language where functions are first-class objects... From lawrencedo99 at gmail.com Thu Jun 2 01:50:55 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 22:50:55 -0700 (PDT) Subject: What's going on here? In-Reply-To: References: Message-ID: On Monday, May 23, 2016 at 9:47:15 AM UTC+12, DFS wrote: > def splitrange(b,e,g): > sr=[] > for i in range(b,e,g): > bg=i;eg=min(e,bg+g-1) > sr.append((bg,eg)) > return sr To be more in keeping with the Python ethos, I would take out the ?-1?. From lawrencedo99 at gmail.com Thu Jun 2 01:57:47 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 1 Jun 2016 22:57:47 -0700 (PDT) Subject: Finding .so files without setting LD_LIBRARY_PATH In-Reply-To: References: <1463002764.2579.26.camel@mad-scientist.net> Message-ID: <04017c15-4044-4ceb-aead-7d6a26c66602@googlegroups.com> On Thursday, May 12, 2016 at 9:51:02 AM UTC+12, Paul Smith wrote: > ... here's the problem: because LD_LIBRARY_PATH is in > Python's environment it is also passed down to programs invoked by > Python. That means if I (for example) invoke subprocess.call(['ssh', > ...]) then it fails because the system ssh is looking for the system > libcrypto.so, and when it finds the Python libcrypto.so instead > (because of LD_LIBRARY_PATH) it fails. That?s easy enough to fix: you can pass a custom environment down to subprocesses by using the ?env? argument to the various subprocess calls . From greg.ewing at canterbury.ac.nz Thu Jun 2 02:41:29 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 02 Jun 2016 18:41:29 +1200 Subject: Don't put your software in the public domain In-Reply-To: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html From that: > It might be ruled to create a global licence for unrestricted use. That > licence might or might not then be adjudicated to be revocable by subsequent > copyright owners (heirs, divorcing spouses, creditors). If that's possible, then could said heirs, divorcing spouses and creditors also revoke supposedly permanent rights granted under an explicit licence? Or is putting the word "irrevocable" in the licence enough to prevent that? -- Greg From greg.ewing at canterbury.ac.nz Thu Jun 2 02:50:34 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 02 Jun 2016 18:50:34 +1200 Subject: Efficient handling of fast, real-time hex data In-Reply-To: References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> Message-ID: jladasky at itu.edu wrote: > One common data transmission error I've seen in other systems is > added/dropped bytes. I may add a CRC-8 error-checking byte in place of the > newline. Also maybe add a start byte with a known value at the beginning of each packet to help resynchronise if you get out of step. -- Greg From alister.ware at ntlworld.com Thu Jun 2 04:13:51 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 02 Jun 2016 08:13:51 GMT Subject: Efficient handling of fast, real-time hex data References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> Message-ID: <3VR3z.159311$Zt1.11158@fx33.am4> On Thu, 02 Jun 2016 18:50:34 +1200, Gregory Ewing wrote: > jladasky at itu.edu wrote: >> One common data transmission error I've seen in other systems is >> added/dropped bytes. I may add a CRC-8 error-checking byte in place of >> the newline. > > Also maybe add a start byte with a known value at the beginning of each > packet to help resynchronise if you get out of step. No maybe about it if you are sending a binary stream you need to be able to reliably signal the start AND finish of the data stream (either send the length in the message start or have a fixed msg. length) after a lot of experimenting to ensure reliability you will probably have reinvented something like intelhex or x-modem -- The work [of software development] is becoming far easier (i.e. the tools we're using work at a higher level, more removed from machine, peripheral and operating system imperatives) than it was twenty years ago, and because of this, knowledge of the internals of a system may become less accessible. We may be able to dig deeper holes, but unless we know how to build taller ladders, we had best hope that it does not rain much. -- Paul Licker From lawrencedo99 at gmail.com Thu Jun 2 04:22:53 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 01:22:53 -0700 (PDT) Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <85h9de6lp4.fsf@benfinney.id.au> Message-ID: <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: > (Note that ?__init__? is not a constructor, because it operates on the > *already constructed* instance, and does not return anything. Believe it or not, that *is* what ?constructor? means in every OO language. Technically it should be called the ?initializer?, but ?constructor? is the accepted term for the special method that is called to initialize a newly-allocated class instance. > Python's classes implement the constructor as ?__new__?, and you very rarely > need to bother with that.) Python?s ?__new__? goes beyond the capabilities of ?constructors? in conventional OO languages. From lawrencedo99 at gmail.com Thu Jun 2 04:26:31 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 01:26:31 -0700 (PDT) Subject: Do you think a DB based on Coroutine and AsyncIO is a good idea? I have written a demo on GitHub. In-Reply-To: <05be7408-a54f-4f42-853b-4595f64d55fd@googlegroups.com> References: <907ba907-022a-4478-a0a5-bb240193b290@googlegroups.com> <05be7408-a54f-4f42-853b-4595f64d55fd@googlegroups.com> Message-ID: <28f2fdcb-9dd6-4717-bf34-a5b0b2df0f5c@googlegroups.com> On Thursday, May 26, 2016 at 8:56:44 AM UTC+12, jimz... at gmail.com wrote: > I think in-process DB is quite popular in less serious development, e.g. SQLite. ?less serious?!? It?s the world?s most popular DBMS! There?s likely a copy in your pocket or purse right now. From foxprone.r52 at gmail.com Thu Jun 2 04:27:02 2016 From: foxprone.r52 at gmail.com (Anup reni) Date: Thu, 2 Jun 2016 13:57:02 +0530 Subject: 2d matrix into Nx3 column data Message-ID: i would like to transform this: -1 0-0.8 0.64 -0.36-0.4 0.16 -0.84 0.0 0 -1.00 0.4 0.16 -0.84 0.8 0.64 -0.36 to something like this: x y result id 1 -0.8 -1 0.642 -0.8 0 -0.363 -0.4 -1 0.164 -0.4 0 -0.845 0.0 -1 0.006 0.0 0 -1.007 0.4 -1 0.168 0.4 0 -0.849 0.8 -1 0.6410 0.8 0 -0.36 From lawrencedo99 at gmail.com Thu Jun 2 04:28:29 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 01:28:29 -0700 (PDT) Subject: [Python-Dev] Python 3.6.0a1 is now available In-Reply-To: References: <28E1448B-F604-48EB-B4E4-0AE2528C8383@python.org> <-7150763876064620774@unknownmsgid> <6a1fba2d-0313-59ec-c4f9-62f4206f84d4@gmail.com> Message-ID: <1c266872-16cb-4b18-8690-8050aea44544@googlegroups.com> On Tuesday, May 24, 2016 at 8:10:48 PM UTC+12, Terry Reedy wrote: > I don't know what will happen if 'Windows 10' continues indefinitely, > even as it mutates internally. As Microsoft adds more and more Linux APIs, maybe you could migrate to using those. ;) From steve+comp.lang.python at pearwood.info Thu Jun 2 04:56:46 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 18:56:46 +1000 Subject: Just for fun: creating zombies with Python Message-ID: <574ff4dd$0$1530$c3e8da3$5496439d@news.astraweb.com> Just for fun, I thought I'd create some zombie processes using Linux. (This will probably only work on POSIX-compliant operating systems. I don't know that Windows has zombies.) I started with the C code given here: https://en.wikipedia.org/wiki/Zombie_process#Examples and re-wrote it into Python: steve at runes:~$ cat zombie.py import os, sys, time pids = [None]*10 for i in range(9, -1, -1): pids[i] = os.fork() if pids[i] == 0: time.sleep(i+1) os._exit(0) for i in range(9, -1, -1): os.waitpid(pids[i], 0) If you run that script on Linux, and watch the process list using (say) top, you will see the number of zombies grow up to a maximum of nine, then drop back down to (hopefully) zero. -- Steve From gheskett at wdtv.com Thu Jun 2 05:41:40 2016 From: gheskett at wdtv.com (Gene Heskett) Date: Thu, 2 Jun 2016 05:41:40 -0400 Subject: Efficient handling of fast, real-time hex data In-Reply-To: <3VR3z.159311$Zt1.11158@fx33.am4> References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> <3VR3z.159311$Zt1.11158@fx33.am4> Message-ID: <201606020541.40945.gheskett@wdtv.com> On Thursday 02 June 2016 04:13:51 alister wrote: > On Thu, 02 Jun 2016 18:50:34 +1200, Gregory Ewing wrote: > > jladasky at itu.edu wrote: > >> One common data transmission error I've seen in other systems is > >> added/dropped bytes. I may add a CRC-8 error-checking byte in place > >> of the newline. > > > > Also maybe add a start byte with a known value at the beginning of > > each packet to help resynchronise if you get out of step. > > No maybe about it > if you are sending a binary stream you need to be able to reliably > signal the start AND finish of the data stream (either send the length > in the message start or have a fixed msg. length) > > after a lot of experimenting to ensure reliability you will probably > have reinvented something like intelhex or x-modem > Neither of which can handle that last packet well unless the last packet is padded out to be a fill packet and the filler bytes thrown away in the receiver. For that reason alone, zmodem wins because it does both.. zmodem in its present linux implementation must have in window size set explicitely on the invocation command line to match the default packet size of the receiving device, which is usually the size of its disk sector. That way, when its talking to rzsz on a 256 byte sector box, it will be forced to do the checksum checks to match what rzsz can do. Otherwise the linux version of zmodem will only check the checksums every 8 kilobytes. That of course will fail if the line speed overruns the receiver, and of course the receiver is sending error restart requests, not a good way to make any real speed. My target box is running nitros9 and somehow bit rot has destroyed the 7 wire protocol flow controls, so I have to restrict the data rate to 4800 baud. Doing both the window size limit and the low baud rate, I have moved an 80 track disk image built on this machine, to that machine without any errors several times. Slow, and hard on the coffee pot staying awake while effectively watching paint dry, but it worked. Now we have a better method that works at 112 kbaud, much better. You can load a program direct from a virtual disk image "mounted" for use with disk descriptors that point at the disk image on this hard drive at a load speed approaching loading it from a real floppy on that machine. > The work [of software development] is becoming far easier (i.e. the > tools we're using work at a higher level, more removed from machine, > peripheral and operating system imperatives) than it was twenty years > ago, and because > of this, knowledge of the internals of a system may become less > accessible. > We may be able to dig deeper holes, but unless we know how to build > taller ladders, we had best hope that it does not rain much. > -- Paul Licker Paul is absolutely correct. 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 lawrencedo99 at gmail.com Thu Jun 2 05:43:42 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 02:43:42 -0700 (PDT) Subject: Just for fun: creating zombies with Python In-Reply-To: <574ff4dd$0$1530$c3e8da3$5496439d@news.astraweb.com> References: <574ff4dd$0$1530$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, June 2, 2016 at 8:57:13 PM UTC+12, Steven D'Aprano wrote: > os.waitpid(pids[i], 0) One of the first lessons you learn, when messing about with spawning processes on Linux(-compatible) systems in languages other than a shell, is ALWAYS GOBBLE YOUR ZOMBIE CHILDREN! From johnhpote at o2.co.uk Thu Jun 2 06:35:03 2016 From: johnhpote at o2.co.uk (John Pote) Date: Thu, 2 Jun 2016 11:35:03 +0100 Subject: Recommendation for GUI lib? In-Reply-To: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: On 01/06/2016 18:13, Jan Erik Mostr?m wrote: > I want to write a few programs with a GUI but I don't want to use Tk. > Instead I'm looking for some other library, I've tried to look around > and also asked a few but I don't really know what to use. I've used wxPython (www.wxpython.org) for a few GUI projects and found it ok. It's a wrapper for the wxWidgets C++ library. There's even a reasonable free GUI builder, wxGlade, which I use as I prefer constructing GUI's that way rather than writing raw wxPython code. Never tried any of the paid for GUI builders. Disadvantage is the download page only provides builds for Python 2.6 or 2.7. Does anyone know how Project Phoenix is coming on? http://wxpython.org/Phoenix/ItsAlive/ shows wxPython working with Python 3.2. Comments on how stable it is and how easy to install would be helpful. John > > Do you have any recommendations? Primary platforms are OS X and Linux. > > I, of course, want to have "standard" widgets but a "calendar > view"/"date picker" is a plus. > > = jem From nick.a.sarbicki at gmail.com Thu Jun 2 07:09:20 2016 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Thu, 02 Jun 2016 11:09:20 +0000 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: > > > > > > Do you have any recommendations? Primary platforms are OS X and Linux. > > > > I, of course, want to have "standard" widgets but a "calendar > > view"/"date picker" is a plus. > I generally use PyQt which is one of two (the other being pyside) python wrappers for the Qt libraries. PyQt is the only one I know which currently supports Qt5+ so gets my vote. There are loads of resources around - works well on all operating systems (with most Qt5 having some focus on mobile). It comes with a ton of utilities and a really nice GUI editor ( https://en.wikipedia.org/wiki/Qt_Creator). There are a lot of resources around and, as predicted, already has some examples of date pickers: http://www.eurion.net/python-snippets/snippet/Calendar_Date%20picker.html - Nick. From ben+python at benfinney.id.au Thu Jun 2 07:19:16 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 02 Jun 2016 21:19:16 +1000 Subject: Storing data in mysql References: Message-ID: <85r3cf6dor.fsf@benfinney.id.au> Anup reni writes: > How to store this 3 dimensional data in Mysql database for plotting on > map? You have not asked a question relevant to Python. You have asked a question much more to do with MySQL. Perhaps take the discussion to a discussion forum for MySQL instead? -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From muhammadaliaskari at gmail.com Thu Jun 2 07:22:45 2016 From: muhammadaliaskari at gmail.com (Muhammad Ali) Date: Thu, 2 Jun 2016 04:22:45 -0700 (PDT) Subject: Python on Windows with linux environment Message-ID: Hi, I use windows regularly, however, I use linux for only my research work at supercomputer. In my research field (materials science) most of the scripts are being written in python with linux based system. Could I installed such linux based python on my window 7? So that I can use those linux based scripts written in python and I can also write my own scripts/code without entirely changing my operating system from windows to linux. Looking for your valuable suggestions. Thank you. From Deborah.Martin at kognitio.com Thu Jun 2 07:30:54 2016 From: Deborah.Martin at kognitio.com (Deborah Martin) Date: Thu, 2 Jun 2016 11:30:54 +0000 Subject: Python on Windows with linux environment In-Reply-To: References: Message-ID: Try Cygwin at http://www.cygwin.com Regards, Deborah -----Original Message----- From: Python-list [mailto:python-list-bounces+deborah.martin=kognitio.com at python.org] On Behalf Of Muhammad Ali Sent: 02 June 2016 12:23 To: python-list at python.org Subject: Python on Windows with linux environment Hi, I use windows regularly, however, I use linux for only my research work at supercomputer. In my research field (materials science) most of the scripts are being written in python with linux based system. Could I installed such linux based python on my window 7? So that I can use those linux based scripts written in python and I can also write my own scripts/code without entirely changing my operating system from windows to linux. Looking for your valuable suggestions. Thank you. -- https://mail.python.org/mailman/listinfo/python-list This e-mail and any files transmitted with it are strictly confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, please delete this e-mail immediately. Any unauthorised distribution or copying is strictly prohibited. Whilst Kognitio endeavours to prevent the transmission of viruses via e-mail, we cannot guarantee that any e-mail or attachment is free from computer viruses and you are strongly advised to undertake your own anti-virus precautions. Kognitio grants no warranties regarding performance, use or quality of any e-mail or attachment and undertakes no liability for loss or damage, howsoever caused. From oscar.j.benjamin at gmail.com Thu Jun 2 07:37:03 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 2 Jun 2016 12:37:03 +0100 Subject: Python on Windows with linux environment In-Reply-To: References: Message-ID: On 2 June 2016 at 12:22, Muhammad Ali wrote: > I use windows regularly, however, I use linux for only my research work at supercomputer. In my research field (materials science) most of the scripts are being written in python with linux based system. Could I installed such linux based python on my window 7? So that I can use those linux based scripts written in python and I can also write my own scripts/code without entirely changing my operating system from windows to linux. Python code usually runs the same on Windows as it does on Linux. What makes you think that you need Linux to run this code? -- Oscar From steve at pearwood.info Thu Jun 2 07:56:44 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 02 Jun 2016 21:56:44 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57501efe$0$1583$c3e8da3$5496439d@news.astraweb.com> On Thu, 2 Jun 2016 04:41 pm, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html > > From that: >> It might be ruled to create a global licence for unrestricted use. That > > licence might or might not then be adjudicated to be revocable by > > subsequent copyright owners (heirs, divorcing spouses, creditors). > > If that's possible, then could said heirs, divorcing spouses > and creditors also revoke supposedly permanent rights granted > under an explicit licence? Or is putting the word "irrevocable" > in the licence enough to prevent that? Ask a real lawyer :-) This is why we should use licences that have been written and vetted by actual lawyers. They're the experts. -- Steven From rosuav at gmail.com Thu Jun 2 08:04:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Jun 2016 22:04:02 +1000 Subject: Don't put your software in the public domain In-Reply-To: <57501efe$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <57501efe$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jun 2, 2016 at 9:56 PM, Steven D'Aprano wrote: > On Thu, 2 Jun 2016 04:41 pm, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >> >>> http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html >> >> From that: >>> It might be ruled to create a global licence for unrestricted use. That >> > licence might or might not then be adjudicated to be revocable by >> > subsequent copyright owners (heirs, divorcing spouses, creditors). >> >> If that's possible, then could said heirs, divorcing spouses >> and creditors also revoke supposedly permanent rights granted >> under an explicit licence? Or is putting the word "irrevocable" >> in the licence enough to prevent that? > > Ask a real lawyer :-) > > This is why we should use licences that have been written and vetted by > actual lawyers. They're the experts. I honestly don't see why people want to put their code into the public domain, when the MIT license is pretty close to that anyway. What's the point? ChrisA From alanoe at linux.vnet.ibm.com Thu Jun 2 08:15:34 2016 From: alanoe at linux.vnet.ibm.com (Alan Evangelista) Date: Thu, 2 Jun 2016 09:15:34 -0300 Subject: Recommendation for Object-Oriented systems to study In-Reply-To: <48967b8e-773b-472d-8a1a-89135e78e4f5@googlegroups.com> References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> <201605291812.u4TI9dqP037317@mx0a-001b2d01.pphosted.com> <48967b8e-773b-472d-8a1a-89135e78e4f5@googlegroups.com> Message-ID: <201606021215.u52CFRGH000798@mx0a-001b2d01.pphosted.com> On 06/02/2016 02:44 AM, Lawrence D?Oliveiro wrote: > On Monday, May 30, 2016 at 7:17:47 AM UTC+12, Alan Evangelista wrote: >> - Java forces everything to be implemented in OO model (classes) > After you have spend a few months battering your head against the rigidity and verbosity of Java, > you will run back to Python with a sense of relief. The point was which programming language was better to teach object oriented concepts, rigidity and verbosity has nothing to do with this. Most of this discussion has leaned towards other criteria beyond adherence to OO paradigm (eg static typing vs dynamic typing and personal taste), so I have chosen to not continue it. For some reason, Java still one of the most used programming languages to teach OO in universities. In real life projects, people has the freedom to choose whatever they prefer, though. =) Regards, Alan Evangelista From omar.aboumrad at gmail.com Thu Jun 2 08:25:43 2016 From: omar.aboumrad at gmail.com (Omar Abou Mrad) Date: Thu, 2 Jun 2016 15:25:43 +0300 Subject: EuroPython 2016 Keynote: Paul Hildebrandt In-Reply-To: <574D900F.90806@europython.eu> References: <574D900F.90806@europython.eu> Message-ID: Quick note: blog and conference schedule links in the europython.eu site's custom 404 page are incorrect. https://ep2016.europython.eu/en/foobarbaz/ On Tue, May 31, 2016 at 4:22 PM, M.-A. Lemburg wrote: > We are pleased to announce our next keynote speaker for EuroPython > 2016: > > > *** Paul Hildebrandt *** > > > > About Paul Hildebrandt > ---------------------- > > Paul Hildebrandt has been a Senior Engineer with Walt Disney Animation > Studios (WDAS) since 1996, and has worked in both Systems and Software > engineering. His current title is Senior Software Engineer and Product > Owner for the Playback tools among his primary duties is spending time > working with the artists, understanding their needs, and designing > tools to assist them. If he is lucky, he gets to write code. > > Hildebrandt was born and raised in Anaheim, California. He received > his BSEE with a focus on Computing from California Polytechnic > University Pomona. He resides outside of Los Angeles with his wife and > three boys. > > The Keynote: Inside the Hat: Python @ Walt Disney Animation Studios > ------------------------------------------------------------------- > > The Walt Disney Animation Studios has a long history of creating > acclaimed animated films and continues to be an industry leader with > regards to artistic achievements, storytelling excellence, and > cutting-edge innovations. Since the 1923 release of ?Snow White? > they?ve been pushing forward technology in the art of movie > making. This push continues in the modern day with classics such as > Oscar winning box office hits ?Big Hero 6? and ?Frozen? and Oscar > nominated hits ?Wreck-It Ralph?, ?Tangled?, ?Bolt?, ?Treasure Planet?, > and ?Dinosaur?. > > One of the most common questions I get when attending Python > conferences is ?Why are you here?? People seem confused that > technology, especially Python is used in the making of animated > films. > > Paul will give you some background on the Walt Disney Animation > Studios and talk about where specifically Python comes into play. > > > With gravitational regards, > -- > EuroPython 2016 Team > http://ep2016.europython.eu/ > http://www.europython-society.org/ > > > PS: Please forward or retweet to help us reach all interested parties: > https://twitter.com/europython/status/737633789116088320 > Thanks. > -- > https://mail.python.org/mailman/listinfo/python-list > From marko at pacujo.net Thu Jun 2 08:26:19 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 02 Jun 2016 15:26:19 +0300 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <57501efe$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wpm7ixp0.fsf@elektro.pacujo.net> Chris Angelico : > I honestly don't see why people want to put their code into the public > domain, when the MIT license is pretty close to that anyway. What's > the point? Why did I put my book translation into the public domain ()? Because that's what I felt like doing. If the author has one right to their work, it is relinquishing all rights to that work. All works will eventually fall into the public domain anyway; all we are talking about is the possibility of expediting the inevitable. Marko From paul.nospam at rudin.co.uk Thu Jun 2 08:29:58 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 02 Jun 2016 13:29:58 +0100 Subject: Python on Windows with linux environment References: Message-ID: <87d1nz4vuh.fsf@rudin.co.uk> Deborah Martin writes: > Try Cygwin at http://www.cygwin.com > Or use the new windows subsystem for linux: https://blogs.windows.com/buildingapps/2016/03/30/run-bash-on-ubuntu-on-windows/ From alister.ware at ntlworld.com Thu Jun 2 08:30:40 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 02 Jun 2016 12:30:40 GMT Subject: Efficient handling of fast, real-time hex data References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> <3VR3z.159311$Zt1.11158@fx33.am4> <201606020541.40945.gheskett@wdtv.com> Message-ID: On Thu, 02 Jun 2016 05:41:40 -0400, Gene Heskett wrote: > On Thursday 02 June 2016 04:13:51 alister wrote: > >> On Thu, 02 Jun 2016 18:50:34 +1200, Gregory Ewing wrote: >> > jladasky at itu.edu wrote: >> >> One common data transmission error I've seen in other systems is >> >> added/dropped bytes. I may add a CRC-8 error-checking byte in place >> >> of the newline. >> > >> > Also maybe add a start byte with a known value at the beginning of >> > each packet to help resynchronise if you get out of step. >> >> No maybe about it if you are sending a binary stream you need to be >> able to reliably signal the start AND finish of the data stream (either >> send the length in the message start or have a fixed msg. length) >> >> after a lot of experimenting to ensure reliability you will probably >> have reinvented something like intelhex or x-modem >> > Neither of which can handle that last packet well unless the last packet > is padded out to be a fill packet and the filler bytes thrown away in > the receiver. The examples quoted were for examples of binary transfer protocols & not intended to be an exhaustive list. > >> The work [of software development] is becoming far easier (i.e. the >> tools we're using work at a higher level, more removed from machine, >> peripheral and operating system imperatives) than it was twenty years >> ago, and because of this, knowledge of the internals of a system may >> become less accessible. >> We may be able to dig deeper holes, but unless we know how to build >> taller ladders, we had best hope that it does not rain much. >> -- Paul Licker > > Paul is absolutely correct. > > Cheers, Gene Heskett ^^^^ like that quote -- Under deadline pressure for the next week. If you want something, it can wait. Unless it's blind screaming paroxysmally hedonistic... From robin at reportlab.com Thu Jun 2 08:52:34 2016 From: robin at reportlab.com (Robin Becker) Date: Thu, 2 Jun 2016 13:52:34 +0100 Subject: Don't put your software in the public domain In-Reply-To: References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52f7eb8f-547c-1985-f234-a5f68596c12f@chamonix.reportlab.co.uk> On 02/06/2016 07:41, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html > > From that: >> It might be ruled to create a global licence for unrestricted use. That >> licence might or might not then be adjudicated to be revocable by subsequent >> copyright owners (heirs, divorcing spouses, creditors). ..... I'm surprised the tax man doesn't have a say; if I disclaim any property/right in the UK it might be thought of as an attempt to evade death duties, taxes always outlive death :( -- Robin Becker From mrak at sightlineinnovation.com Thu Jun 2 09:10:56 2016 From: mrak at sightlineinnovation.com (Marcin Rak) Date: Thu, 2 Jun 2016 06:10:56 -0700 (PDT) Subject: Beginner Question In-Reply-To: References: Message-ID: That linked help clear up my confusion...yes you really have to know how things work internally to understand why things happen the way they happen. Thanks again to all From mal at europython.eu Thu Jun 2 09:13:40 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 2 Jun 2016 15:13:40 +0200 Subject: EuroPython 2016 Keynote: Paul Hildebrandt In-Reply-To: References: <574D900F.90806@europython.eu> Message-ID: <57503104.8010202@europython.eu> On 02.06.2016 14:25, Omar Abou Mrad wrote: > Quick note: blog and conference schedule links in the > europython.eu site's custom 404 page are incorrect. > > https://ep2016.europython.eu/en/foobarbaz/ Thanks. Should be fixed now. > On Tue, May 31, 2016 at 4:22 PM, M.-A. Lemburg wrote: > >> We are pleased to announce our next keynote speaker for EuroPython >> 2016: >> >> >> *** Paul Hildebrandt *** >> >> >> >> About Paul Hildebrandt >> ---------------------- >> >> Paul Hildebrandt has been a Senior Engineer with Walt Disney Animation >> Studios (WDAS) since 1996, and has worked in both Systems and Software >> engineering. His current title is Senior Software Engineer and Product >> Owner for the Playback tools among his primary duties is spending time >> working with the artists, understanding their needs, and designing >> tools to assist them. If he is lucky, he gets to write code. >> >> Hildebrandt was born and raised in Anaheim, California. He received >> his BSEE with a focus on Computing from California Polytechnic >> University Pomona. He resides outside of Los Angeles with his wife and >> three boys. >> >> The Keynote: Inside the Hat: Python @ Walt Disney Animation Studios >> ------------------------------------------------------------------- >> >> The Walt Disney Animation Studios has a long history of creating >> acclaimed animated films and continues to be an industry leader with >> regards to artistic achievements, storytelling excellence, and >> cutting-edge innovations. Since the 1923 release of ?Snow White? >> they?ve been pushing forward technology in the art of movie >> making. This push continues in the modern day with classics such as >> Oscar winning box office hits ?Big Hero 6? and ?Frozen? and Oscar >> nominated hits ?Wreck-It Ralph?, ?Tangled?, ?Bolt?, ?Treasure Planet?, >> and ?Dinosaur?. >> >> One of the most common questions I get when attending Python >> conferences is ?Why are you here?? People seem confused that >> technology, especially Python is used in the making of animated >> films. >> >> Paul will give you some background on the Walt Disney Animation >> Studios and talk about where specifically Python comes into play. >> >> >> With gravitational regards, >> -- >> EuroPython 2016 Team >> http://ep2016.europython.eu/ >> http://www.europython-society.org/ >> >> >> PS: Please forward or retweet to help us reach all interested parties: >> https://twitter.com/europython/status/737633789116088320 >> Thanks. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- Marc-Andre Lemburg Director EuroPython Society http://www.europython-society.org/ http://www.malemburg.com/ From ikorot01 at gmail.com Thu Jun 2 09:38:38 2016 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 2 Jun 2016 09:38:38 -0400 Subject: Beginner Question In-Reply-To: <574fc214$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <574fc214$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven, On Thu, Jun 2, 2016 at 1:20 AM, Steven D'Aprano wrote: > On Thursday 02 June 2016 14:21, Igor Korot wrote: > >> Hi, guys, >> >> On Wed, Jun 1, 2016 at 9:42 PM, boB Stepp wrote: >>> On Wed, Jun 1, 2016 at 7:55 PM, Marcin Rak >>> wrote: >>>> Hi to all >>>> >>>> I have a beginner question to which I have not found an answer I was able >>>> to understand. Could someone explain why the following program: >>>> >>>> def f(a, L=[]): >>>> L.append(a) >>>> return L >>>> >>>> print(f(1)) >>>> print(f(2)) >>>> print(f(3)) >>>> >>>> gives us the following result: >>>> >>>> [1] >>>> [1,2] >>>> [1,2,3] >>>> >>>> How can this be, if we never catch the returned L when we call it, and we >>>> never pass it on back to f??? >> >> I think the OP question here is: >> >> Why it is printing the array? > > Because he calls the function, then prints the return result. > > print(f(1)) > > calls f(1), which returns [1], then prints [1]. > > Then he calls: > > print(f(2)) > > which returns [1, 2] (but he expects [2]), then prints it. And so on. > > >> There is no line like: >> >> t = f(1) >> print t > > Correct. But there are lines: > > print(f(1)) > print(f(2)) > print(f(3)) I think you missed the point. Compare: def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2)) print(f(3)) vs. def f(a, L=[]): L.append(a) return L t = f(1) print t t = f(2) print t t = f(3) print t For people that comes from C/C++/Java, the first syntax is kind of weird: you return a value from the function but the caller does not save it anywhere. Especially since the return is not a basic type and most of them are not familiar with scalar vs list context (sorry for the Perl terminology here) Thank you. > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list From kwa at kuwata-lab.com Thu Jun 2 10:04:50 2016 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Thu, 2 Jun 2016 23:04:50 +0900 Subject: [Q] ImportError by __import__() on Python >= 3.4 Message-ID: Hi, I have a trouble around __import__(). The following sample code works well on Python <= 3.3, but it raises ImportError on Python >= 3.4. ## importtest.py import sys, os, shutil def test(name): try: ## create 'foo/__init__.py' file os.mkdir(name) with open(name + "/__init__.py", 'w') as f: f.write("X=1") f.flush() ## ipmort 'foo' module mod = __import__(name) finally: if os.path.isdir(name): shutil.rmtree(name) test("foo") # no errors test("bar") # may raise error on Python >= 3.4. Why? Output Example: ### No errors (Python <= 3.3) ubuntu$ export PYTHONPATH=. ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.3 importtest.py; done ### ImportError (Python >= 3.4) ubuntu$ export PYTHONPATH=. ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.4 importtest.py; done Traceback (most recent call last): File "tmp/importtest.py", line 19, in test("bar") # may raise error on Python >= 3.4. Why? File "tmp/importtest.py", line 13, in test mod = __import__(name) ImportError: No module named 'bar' Please give me any advices or hints. Thanks. -- regards, makoto From marcwbrooks at gmail.com Thu Jun 2 10:10:43 2016 From: marcwbrooks at gmail.com (Marc Brooks) Date: Thu, 2 Jun 2016 10:10:43 -0400 Subject: Python on Windows with linux environment In-Reply-To: References: Message-ID: Others have mentioned Cygwin or the new subsystem. The other two options a number of Python develops that I work use are to (1) install vmware/virtualbox and run linux in a vm or (2) install the packaged binaries, such as Anaconda from Continuum Analytics. One issue I had when using cygwin was that it was sometimes a bit more annoying to get libraries installed, since it couldn't use any pre-compiled binaries for Windows. I don't know if that's still the case, since this was a few years back and I'm doing my dev work on a mac nowadays. Marc On Thu, Jun 2, 2016 at 7:22 AM, Muhammad Ali wrote: > > Hi, > > I use windows regularly, however, I use linux for only my research work at > supercomputer. In my research field (materials science) most of the scripts > are being written in python with linux based system. Could I installed such > linux based python on my window 7? So that I can use those linux based > scripts written in python and I can also write my own scripts/code without > entirely changing my operating system from windows to linux. > > Looking for your valuable suggestions. > > Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list > From michael.selik at gmail.com Thu Jun 2 10:15:45 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 02 Jun 2016 14:15:45 +0000 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: Message-ID: On Thu, Jun 2, 2016 at 10:06 AM Makoto Kuwata wrote: > os.mkdir(name) > with open(name + "/__init__.py", 'w') as f: > f.write("X=1") > f.flush() > > Please give me any advices or hints. > This wasn't your question, but you don't need to flush the file. The ``with`` statement will automatically flush and close your file for you after you exit the block. From michael.selik at gmail.com Thu Jun 2 10:31:19 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 02 Jun 2016 14:31:19 +0000 Subject: 2d matrix into Nx3 column data In-Reply-To: References: Message-ID: On Thu, Jun 2, 2016 at 4:57 AM Anup reni wrote: > i would like to transform this: > > -1 0-0.8 0.64 -0.36-0.4 0.16 -0.84 > 0.0 0 -1.00 > 0.4 0.16 -0.84 > 0.8 0.64 -0.36 > > to something like this: > > x y result > id 1 -0.8 -1 0.642 -0.8 0 -0.363 -0.4 -1 > 0.164 -0.4 0 -0.845 0.0 -1 0.006 0.0 0 -1.007 0.4 -1 > 0.168 0.4 0 -0.849 0.8 -1 0.6410 0.8 0 -0.36 > It's hard to read your example. Could you write it out more simply? Perhaps with comma separators instead of spaces? It might help to also give some context around why you want to make the transformation. From michael.selik at gmail.com Thu Jun 2 10:44:49 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 02 Jun 2016 14:44:49 +0000 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <85h9de6lp4.fsf@benfinney.id.au> <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> Message-ID: On Thu, Jun 2, 2016 at 4:26 AM Lawrence D?Oliveiro wrote: > On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: > > (Note that ?__init__? is not a constructor, because it operates on the > > *already constructed* instance, and does not return anything. > > Believe it or not, that *is* what ?constructor? means in every OO > language. Technically it should be called the ?initializer?, but > ?constructor? is the accepted term for the special method that is called to > initialize a newly-allocated class instance. > Perhaps a Pythonista may have different jargon? Since we have two different words (initializer, constructor), we may as well give them different meanings so that they are maximally useful in conversation. From Joaquin.Alzola at lebara.com Thu Jun 2 11:45:22 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Thu, 2 Jun 2016 15:45:22 +0000 Subject: Matplotlib X-axis dates Message-ID: Hi Guys Have been all day looking for a solution on the x-axis and the time plot. The output that I get is this with all the dates shift to the right overlapping each other. http://postimg.org/image/fs4tx83or/ I want the x-axis to start at 0 and to finish after the 3 entries on the DB. X Axis should show (and it does but shift one over each other to the right): 2016-06-02 11:15:00 2016-06-02 11:20:00 2016-06-02 11:25:00 Data on the Cassandra DB: cqlsh:lebara_diameter_codes> select * from nl_lebara_diameter_codes; country | service | date | errorcode2001 | errorcode3056 | errorcode4010 | errorcode4012 | errorcode4998 | errorcode4999 | errorcode5012 ---------+---------+---------------------------------+---------------+---------------+---------------+---------------+---------------+---------------+--------------- NL | gprs | 2016-06-02 11:15:00.000000+0000 | 3061 | 0 | 1 | 0 | 0 | 50 | 741 NL | gprs | 2016-06-02 11:20:00.000000+0000 | 3204 | 0 | 9 | 0 | 0 | 56 | 725 NL | gprs | 2016-06-02 11:25:00.000000+0000 | 3044 | 0 | 8 | 0 | 0 | 64 | 722 Code: sql = country_sql("NL",ago.strftime('%Y-%m-%d %H:%M:%S'),"gprs") result = sql.sql_statement_range() for i in result: country = i.country service = i.service x_list.append(i.date) code_2001.append(i.errorcode2001) code_4012.append(i.errorcode4012) code_4998.append(i.errorcode4998) code_4999.append(i.errorcode4999) code_5012.append(i.errorcode5012) code_3056.append(i.errorcode3056) code_4010.append(i.errorcode4010) print(x_list) --> Output is [datetime.datetime(2016, 6, 2, 11, 15), datetime.datetime(2016, 6, 2, 11, 20), datetime.datetime(2016, 6, 2, 11, 25)] #date_nump=date2num([i for i in x_list]) date_nump=date2num(x_list) print(date_nump) --> output is [ 736117.46875 736117.47222222 736117.47569444] fig = plt.figure(figsize=(12,6)) ax = fig.add_subplot(111) ax.set_title(country.upper() + " " + service,fontsize=16, fontweight='bold') plt.plot(np.array(code_2001),label="2001") plt.plot(np.array(code_3056),label="3056") plt.plot(np.array(code_4010),label="4010") plt.plot(np.array(code_4012),label="4012") plt.plot(np.array(code_4998),label="4998") plt.plot(np.array(code_4999),label="4999") plt.plot(np.array(code_5012),label="5012") lgd = plt.legend(loc='center left', bbox_to_anchor=(1, 0.5)) ax.set_xscale('linear') ax.set_xticks(date_nump) ax.set_xticklabels(num2date(date_nump)) #ax.xaxis.set_major_locator(HourLocator(byhour=range(0,24,2))) ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d %H:%M:%S')) #ax.xaxis.set_minor_locator(MinuteLocator()) ax.grid(True,linestyle='-',color='0.75') plt.gcf().autofmt_xdate(bottom=0.2, rotation=30, ha='right') plt.ylabel('Total Amount',fontsize=12, fontweight='bold') plt.xlabel('Date/Time',fontsize=12, fontweight='bold') plt.gca().set_ylim(bottom=0) plt.savefig('testplot.png',bbox_extra_artists=(lgd,), bbox_inches='tight') plt.show() 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 best_lay at yahoo.com Thu Jun 2 12:38:56 2016 From: best_lay at yahoo.com (Wildman) Date: Thu, 02 Jun 2016 11:38:56 -0500 Subject: Python on Windows with linux environment References: Message-ID: On Thu, 02 Jun 2016 04:22:45 -0700, Muhammad Ali wrote: > Hi, > > I use windows regularly, however, I use linux for only my research work at supercomputer. In my research field (materials science) most of the scripts are being written in python with linux based system. Could I installed such linux based python on my window 7? So that I can use those linux based scripts written in python and I can also write my own scripts/code without entirely changing my operating system from windows to linux. > > Looking for your valuable suggestions. > > Thank you. There is coLinux and andLinux. -- GNU/Linux user #557453 The cow died so I don't need your bull! From esj at harvee.org Thu Jun 2 13:04:45 2016 From: esj at harvee.org (Eric S. Johansson) Date: Thu, 2 Jun 2016 13:04:45 -0400 Subject: Python on Windows with linux environment In-Reply-To: References: Message-ID: <50ab8154-ac2c-a613-99de-d922e87b65f1@harvee.org> On 6/2/2016 12:38 PM, Wildman via Python-list wrote: > On Thu, 02 Jun 2016 04:22:45 -0700, Muhammad Ali wrote: > >> Hi, >> >> I use windows regularly, however, I use linux for only my research work at supercomputer. In my research field (materials science) most of the scripts are being written in python with linux based system. Could I installed such linux based python on my window 7? So that I can use those linux based scripts written in python and I can also write my own scripts/code without entirely changing my operating system from windows to linux. >> >> Looking for your valuable suggestions. >> >> Thank you. > There is coLinux and andLinux. those are both mostly dead (it seems). I went the cygwin route. still sucks but a bit less than straight windows. From steve at pearwood.info Thu Jun 2 13:36:14 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 03 Jun 2016 03:36:14 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <85h9de6lp4.fsf@benfinney.id.au> <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> Message-ID: <57506e90$0$1602$c3e8da3$5496439d@news.astraweb.com> On Thu, 2 Jun 2016 06:22 pm, Lawrence D?Oliveiro wrote: > On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: >> (Note that ?__init__? is not a constructor, because it operates on the >> *already constructed* instance, and does not return anything. > > Believe it or not, that *is* what ?constructor? means in every OO > language. I don't believe it. C# is an OO language, and it distinguishes constructors and initialisers: https://msdn.microsoft.com/en-us/library/bb397680.aspx (although they don't seem to mean quite the same as what they mean in Python). Objective C is also an OO language, and it calls `init` the initializer: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/index.html#//apple_ref/occ/instm/NSObject/init The documentation doesn't specifically give a name to the `alloc` method, but since it allocates memory for the instance, "allocator" is the obvious term. https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/index.html#//apple_ref/occ/clm/NSObject/alloc And `new` merely calls alloc, then init. (Although I'm lead to understand that in older versions of Cocoa, `new` handled both allocation and initialisation.) https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/index.html#//apple_ref/occ/clm/NSObject/new Smalltalk, the grand-daddy of OOP languages, doesn't even have constructors (at least not in the modern OOP sense): http://www.slideshare.net/SmalltalkWorld/stoop-008fun-withsmalltalkmodel http://image.slidesharecdn.com/stoop-008-funwithsmalltalkmodel-101025144609-phpapp02/95/8-oop-smalltalk-model-3-638.jpg?cb=1422578644 Any method can be used to create an object, there is no reserved name for such a method. Python is an OO language, what does it say? The glossary doesn't define *either* constructor or initialiser (or initializer): https://docs.python.org/3/glossary.html and the docs for __new__ and __init__ don't refer to them by either name: https://docs.python.org/3/reference/datamodel.html#basic-customization The docs do refer to the "object constructor expression", but that's the call to the class, not the special method. And the term "initialiser" or "initializer" is frequently used by Python developers to refer to __init__: https://rosettacode.org/wiki/Classes#Python > Technically it should be called the ?initializer?, but > ?constructor? is the accepted term for the special method that is called > to initialize a newly-allocated class instance. Not in Python circles it isn't. But since the constructor/initialiser methods are so closely linked, many people are satisfied to speak loosely and refer to "the constructor" as either, unless they specifically wish to distinguish between __new__ and __init__. -- Steven From ian.g.kelly at gmail.com Thu Jun 2 13:55:16 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 2 Jun 2016 11:55:16 -0600 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <57506e90$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <85h9de6lp4.fsf@benfinney.id.au> <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> <57506e90$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jun 2, 2016 at 11:36 AM, Steven D'Aprano wrote: > On Thu, 2 Jun 2016 06:22 pm, Lawrence D?Oliveiro wrote: > >> On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: >>> (Note that ?__init__? is not a constructor, because it operates on the >>> *already constructed* instance, and does not return anything. >> >> Believe it or not, that *is* what ?constructor? means in every OO >> language. > > I don't believe it. > > C# is an OO language, and it distinguishes constructors and initialisers: > > https://msdn.microsoft.com/en-us/library/bb397680.aspx > > (although they don't seem to mean quite the same as what they mean in > Python). Indeed. The "constructor" in that example is the equivalent of the Python __init__ method. The "initializer" is not a part of the class at all but just a syntactic sugar for creating an instance and setting some of its properties at the same time in a single statement. It's very similar to the C array initializer syntax, e.g.: int myArray[] = {1, 2, 3, 4, 5}; From sohcahtoa82 at gmail.com Thu Jun 2 14:02:49 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 2 Jun 2016 11:02:49 -0700 (PDT) Subject: Beginner Question In-Reply-To: References: <574fc214$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, June 2, 2016 at 6:38:56 AM UTC-7, Igor Korot wrote: > Steven, > > On Thu, Jun 2, 2016 at 1:20 AM, Steven D'Aprano > wrote: > > On Thursday 02 June 2016 14:21, Igor Korot wrote: > > > >> Hi, guys, > >> > >> On Wed, Jun 1, 2016 at 9:42 PM, boB Stepp wrote: > >>> On Wed, Jun 1, 2016 at 7:55 PM, Marcin Rak > >>> wrote: > >>>> Hi to all > >>>> > >>>> I have a beginner question to which I have not found an answer I was able > >>>> to understand. Could someone explain why the following program: > >>>> > >>>> def f(a, L=[]): > >>>> L.append(a) > >>>> return L > >>>> > >>>> print(f(1)) > >>>> print(f(2)) > >>>> print(f(3)) > >>>> > >>>> gives us the following result: > >>>> > >>>> [1] > >>>> [1,2] > >>>> [1,2,3] > >>>> > >>>> How can this be, if we never catch the returned L when we call it, and we > >>>> never pass it on back to f??? > >> > >> I think the OP question here is: > >> > >> Why it is printing the array? > > > > Because he calls the function, then prints the return result. > > > > print(f(1)) > > > > calls f(1), which returns [1], then prints [1]. > > > > Then he calls: > > > > print(f(2)) > > > > which returns [1, 2] (but he expects [2]), then prints it. And so on. > > > > > >> There is no line like: > >> > >> t = f(1) > >> print t > > > > Correct. But there are lines: > > > > print(f(1)) > > print(f(2)) > > print(f(3)) > > I think you missed the point. > > Compare: > > def f(a, L=[]): > L.append(a) > return L > > print(f(1)) > print(f(2)) > print(f(3)) > > vs. > > def f(a, L=[]): > L.append(a) > return L > > t = f(1) > print t > t = f(2) > print t > t = f(3) > print t > > For people that comes from C/C++/Java, the first syntax is kind of weird: > you return a value from the function but the caller does not save it anywhere. > Especially since the return is not a basic type and most of them are > not familiar > with scalar vs list context (sorry for the Perl terminology here) > > Thank you. > > > > > > > > > > -- > > Steve > > > > -- > > https://mail.python.org/mailman/listinfo/python-list I came from C/C++/Java, and the first syntax makes perfect sense to me. You're just taking the result of a function and directly passing it as a parameter to another. There's nothing confusing about that. C/C++/Java let you do it. From joel.goldstick at gmail.com Thu Jun 2 14:03:34 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 2 Jun 2016 14:03:34 -0400 Subject: Python on Windows with linux environment In-Reply-To: <50ab8154-ac2c-a613-99de-d922e87b65f1@harvee.org> References: <50ab8154-ac2c-a613-99de-d922e87b65f1@harvee.org> Message-ID: On Thu, Jun 2, 2016 at 1:04 PM, Eric S. Johansson wrote: > On 6/2/2016 12:38 PM, Wildman via Python-list wrote: >> On Thu, 02 Jun 2016 04:22:45 -0700, Muhammad Ali wrote: >> >>> Hi, >>> >>> I use windows regularly, however, I use linux for only my research work at supercomputer. In my research field (materials science) most of the scripts are being written in python with linux based system. Could I installed such linux based python on my window 7? So that I can use those linux based scripts written in python and I can also write my own scripts/code without entirely changing my operating system from windows to linux. >>> >>> Looking for your valuable suggestions. >>> >>> Thank you. >> There is coLinux and andLinux. > > those are both mostly dead (it seems). I went the cygwin route. still > sucks but a bit less than straight windows. > > -- > https://mail.python.org/mailman/listinfo/python-list Although the OP is using Windows 7, according to recent articles, Ubuntu is teaming with MS for Windows 10 to include a bash shell, presumably with the package management of Ubuntu (debian), with pip goodness and virtualenv and virtualenvwrapper. That route should make W10 and linux (ubuntu) nearly identical environments to deal with -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From Joaquin.Alzola at lebara.com Thu Jun 2 15:25:29 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Thu, 2 Jun 2016 19:25:29 +0000 Subject: Matplotlib X-axis dates Message-ID: >plt.plot(np.array(code_2001),label="2001") Simple solution: ax.plot(date_nump,np.array(code_2001),label="2001") Didn't see it until I took a rest. 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 rgaddi at highlandtechnology.invalid Thu Jun 2 16:09:10 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 2 Jun 2016 20:09:10 -0000 (UTC) Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: Lawrence D?Oliveiro wrote: > On Friday, May 20, 2016 at 4:43:56 AM UTC+12, Herkermer Sherwood wrote: >> Most keywords in Python make linguistic sense, but using "else" in for and >> while structures is kludgy and misleading. > > My objection is not to the choice of keyword, it?s to the whole design of the loop construct. > > It turns out C-style for-loops ?for (init; test; incr) ...? are very versatile. If my loop has more than one exit, I use the endless form ?for (;;)? and do an explicit ?break? for every exit condition. > > Also, they let me declare a variable that is scoped to the loop, that is initialized just once before the loop starts, e.g. > > for (int loopvar = initial_value;;) > { > if (loopvar == limit) > break; > ... processing ... > if (found_what_im_looking_for) > break; > ++loopvar; > } /*for*/ > > I wish I could do this in Python... loopvar = initial_value while True: do_your_loop_things if you_want_to_break_then_just: break loopvar += 1 Although your loop is really the _canonical_ use case for for loopvar in range(initial_value, limit+1): processing if found_what_im_looking_for: break else: do_whatever_it_is_you_do_when_its_not_found The limited variable scoping is the only thing missing, and you can get around that by telling yourself you're not going to use that variable again, and then believing you on the matter. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rgaddi at highlandtechnology.invalid Thu Jun 2 16:13:43 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 2 Jun 2016 20:13:43 -0000 (UTC) Subject: Recommendation for GUI lib? References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: Nick Sarbicki wrote: >> >> >> > >> > Do you have any recommendations? Primary platforms are OS X and Linux. >> > >> > I, of course, want to have "standard" widgets but a "calendar >> > view"/"date picker" is a plus. >> > > I generally use PyQt which is one of two (the other being pyside) python > wrappers for the Qt libraries. > > PyQt is the only one I know which currently supports Qt5+ so gets my vote. > There are loads of resources around - works well on all operating systems > (with most Qt5 having some focus on mobile). It comes with a ton of > utilities and a really nice GUI editor ( > https://en.wikipedia.org/wiki/Qt_Creator). > > There are a lot of resources around and, as predicted, already has some > examples of date pickers: > > http://www.eurion.net/python-snippets/snippet/Calendar_Date%20picker.html > > - Nick. I use PySide rather than PyQt, but definitely count me as another vote for Qt as the toolkit of choice. I started out on wx, but when I needed to move to Python3 it wasn't able to come with me. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From ikorot01 at gmail.com Thu Jun 2 16:22:22 2016 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 2 Jun 2016 16:22:22 -0400 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: Hi, On Thu, Jun 2, 2016 at 4:13 PM, Rob Gaddi wrote: > Nick Sarbicki wrote: > >>> >>> >>> > >>> > Do you have any recommendations? Primary platforms are OS X and Linux. >>> > >>> > I, of course, want to have "standard" widgets but a "calendar >>> > view"/"date picker" is a plus. >>> >> >> I generally use PyQt which is one of two (the other being pyside) python >> wrappers for the Qt libraries. >> >> PyQt is the only one I know which currently supports Qt5+ so gets my vote. >> There are loads of resources around - works well on all operating systems >> (with most Qt5 having some focus on mobile). It comes with a ton of >> utilities and a really nice GUI editor ( >> https://en.wikipedia.org/wiki/Qt_Creator). >> >> There are a lot of resources around and, as predicted, already has some >> examples of date pickers: >> >> http://www.eurion.net/python-snippets/snippet/Calendar_Date%20picker.html >> >> - Nick. > > I use PySide rather than PyQt, but definitely count me as another vote > for Qt as the toolkit of choice. I started out on wx, but when I needed > to move to Python3 it wasn't able to come with me. Phoenix - wxPython for python 3 is coming out soon (the official release). But I believe you can already build pre-release Phoenix and start working with it. Of course its not ready yet, but a lot of stuff already been ported. Thank you. > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. > -- > https://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Thu Jun 2 16:46:46 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 2 Jun 2016 14:46:46 -0600 Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: On Thu, Jun 2, 2016 at 2:09 PM, Rob Gaddi wrote: > The limited variable scoping is the only thing missing, and you can get > around that by telling yourself you're not going to use that variable > again, and then believing you on the matter. Or you can actually limit the variable scope using a function: def the_loop(): for loopvar in range(initial_value, limit+1): processing if found_what_im_looking_for: return it do_whatever_it_is_you_do_when_its_not_found thing_i_was_looking_for = the_loop() From bc at freeuk.com Thu Jun 2 16:52:13 2016 From: bc at freeuk.com (BartC) Date: Thu, 2 Jun 2016 21:52:13 +0100 Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: On 02/06/2016 21:09, Rob Gaddi wrote: > Lawrence D?Oliveiro wrote: > >> On Friday, May 20, 2016 at 4:43:56 AM UTC+12, Herkermer Sherwood wrote: >>> Most keywords in Python make linguistic sense, but using "else" in for and >>> while structures is kludgy and misleading. >> >> My objection is not to the choice of keyword, it?s to the whole design of the loop construct. >> >> It turns out C-style for-loops ?for (init; test; incr) ...? are very versatile. If my loop has more than one exit, I use the endless form ?for (;;)? and do an explicit ?break? for every exit condition. >> >> Also, they let me declare a variable that is scoped to the loop, that is initialized just once before the loop starts, e.g. I've had plenty of discussions on c.l.c on how much I dislike C's 'for' statement! > >> for (int loopvar = initial_value;;) >> { >> if (loopvar == limit) >> break; >> ... processing ... >> if (found_what_im_looking_for) >> break; >> ++loopvar; >> } /*for*/ >> >> I wish I could do this in Python... > > loopvar = initial_value > while True: > do_your_loop_things > if you_want_to_break_then_just: > break > loopvar += 1 One major objection was that C's 'for' isn't really a for-statement at all (as it is understood in most other languages that haven't just copied C's version), but is closer to a 'while' statement. Simple iterative for-loops are more of a DIY effort: for (i=0; i The limited variable scoping is the only thing missing, That's just part of a general feature of C where each block can have its own scope. So you can have dozens of 'i' variables within each function, provided each is defined in a separate block. (I couldn't see the point of that either!) -- Bartc From random832 at fastmail.com Thu Jun 2 17:18:21 2016 From: random832 at fastmail.com (Random832) Date: Thu, 02 Jun 2016 17:18:21 -0400 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <57506e90$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <85h9de6lp4.fsf@benfinney.id.au> <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> <57506e90$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1464902301.3337770.626326969.25D8DFDE@webmail.messagingengine.com> On Thu, Jun 2, 2016, at 13:36, Steven D'Aprano wrote: > On Thu, 2 Jun 2016 06:22 pm, Lawrence D?Oliveiro wrote: > > > On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: > >> (Note that ?__init__? is not a constructor, because it operates on the > >> *already constructed* instance, and does not return anything. > > > > Believe it or not, that *is* what ?constructor? means in every OO > > language. > > I don't believe it. > > C# is an OO language, and it distinguishes constructors and initialisers: > > https://msdn.microsoft.com/en-us/library/bb397680.aspx The methods described on that page as "constructors" operate *precisely* as Lawrence said. An "initializer" as that page discusses is not a method but is a kind of expression, with no analogue in Python, which compiles to multiple operations and 'returns' a value to be assigned to a variable. A hypothetical Python analogue to the C# expression 'new c() { a = 1, b = 2 }', an "initializer", might compile to the following bytecode: LOAD_GLOBAL (c); CALL_FUNCTION 0; DUP_TOP; LOAD_CONST (1); ROT_TWO; STORE_ATTR (a); DUP_TOP; LOAD_CONST (2); ROT_TWO; STORE_ATTR (b); i.e. yielding into the surrounding expression context an instance of type 'c' which has been constructed and then subsequently had two of its attributes (in C#'s case, fields and/or properties) set (or .Add methods called, in the case of collection initializers) > > Technically it should be called the ?initializer?, but > > ?constructor? is the accepted term for the special method that is called > > to initialize a newly-allocated class instance. > > Not in Python circles it isn't. I suspect that the basis on which people refuse to accept it is a (completely incorrect) sense that "constructor" has an inherent meaning as allocating a new object, when no-one's been able to document that it is used *anywhere*, Python or otherwise, in that sense. (I also inherently dislike the notion that any given language community should get to unilaterally decide, even if there were any such agreement, what a term means, denying us a common way to talk about concepts shared between languages to no benefit) Your "python circles" seem to consist of people who are ignorant of how other languages actually work and who want to believe that python is special [i.e. in this case that python's __init__ is somehow different in operation from C++ or C#'s or Java's constructors] when it is not. I think it's more or less the same crowd, and the same motivation, as the "python doesn't have variables" folks, and should be likewise ignored. > But since the constructor/initialiser methods are so closely linked, many > people are satisfied to speak loosely and refer to "the constructor" as > either, unless they specifically wish to distinguish between __new__ and > __init__. Where there is looseness, it comes from the fact that because __init__ is always called even if __new__ returns a pre-existing object people often place code in __new__ which mutates the object to be returned, acting somewhat like a traditional constructor by assigning attributes etc. But it is __init__ that acts like the thing that is called a constructor in many languages, and no-one's produced a single example of a language which uses "constructor" for something which allocates memory. Now, where "constructor" *does* often get misused, it is for the new-expression in other languages, and for type.__call__ in Python, people speak as if they're "calling the constructor" (rather than calling something which ultimately calls both __new__ and __init__). But from a class-definition perspective, __init__ is the one and only thing that should be called a constructor. The fact that many languages don't have any way to override object allocation, and therefore no analogue to __new__, also contributes to this conclusion. In these languages, new-expressions (or the like) are the only way to call a constructor, so people associate object allocation with constructors. From maillist at schwertberger.de Thu Jun 2 17:57:22 2016 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Thu, 2 Jun 2016 23:57:22 +0200 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: On 02.06.2016 12:35, John Pote wrote: > I've used wxPython (www.wxpython.org) for a few GUI projects and found > it ok. It's a wrapper for the wxWidgets C++ library. There's even a > reasonable free GUI builder, wxGlade, which I use as I prefer > constructing GUI's that way rather than writing raw wxPython code. > Never tried any of the paid for GUI builders. > Disadvantage is the download page only provides builds for Python 2.6 > or 2.7. > > Does anyone know how Project Phoenix is coming on? > http://wxpython.org/Phoenix/ItsAlive/ shows wxPython working with > Python 3.2. > Comments on how stable it is and how easy to install would be helpful. I have been using Phoenix now for half a year and are very happy with it. A release is on its way. For most platforms there are snapshot builds which are easy to install. See e.g. https://groups.google.com/d/msg/wxpython-users/soHFLOrerVs/MSijBTQ6KAAJ The snapshot installation does not include the demo and the .chm help file (yet?). These and the book I found to be the most helpful resources (much more usable than online reference documentation as e.g. with Qt). I think that wxGlade is the most promising Python GUI builder and I'm confident that it will see improvements to increase usability. I have tried some others from time to time, including also QtCreator, but none was really convincing. Regards, Dietmar From marko at pacujo.net Thu Jun 2 18:20:55 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 03 Jun 2016 01:20:55 +0300 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <85h9de6lp4.fsf@benfinney.id.au> <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> <57506e90$0$1602$c3e8da3$5496439d@news.astraweb.com> <1464902301.3337770.626326969.25D8DFDE@webmail.messagingengine.com> Message-ID: <87oa7j9qrc.fsf@elektro.pacujo.net> Random832 : > But from a class-definition perspective, __init__ is the one and only > thing that should be called a constructor. Not arguing agaist that, but from the *user's* perspective, I see the class itself is the constructor function: class C: pass c = C() You could say that the class statement in Python little else than syntactic sugar for creating an object constructor. For example, instead of: import math class Point: def __init__(self, x, y): self.x = x self.y = y def rotate(self, angle): self.x, self.y = ( self.x * math.cos(angle) - self.y * math.sin(angle), self.x * math.sin(angle) + self.y * math.cos(angle)) you could write: import math, types def Point(x, y): def rotate(angle): nonlocal x, y x, y = ( x * math.cos(angle) - y * math.sin(angle), x * math.sin(angle) + y * math.cos(angle)) return types.SimpleNamespace(rotate=rotate) > The fact that many languages don't have any way to override object > allocation, and therefore no analogue to __new__, also contributes to > this conclusion. I see no point in Python having __new__, either. In fact, I can see the point in C++ but not in Python. Marko From esj at harvee.org Thu Jun 2 18:27:29 2016 From: esj at harvee.org (Eric S. Johansson) Date: Thu, 2 Jun 2016 18:27:29 -0400 Subject: Python on Windows with linux environment In-Reply-To: References: <50ab8154-ac2c-a613-99de-d922e87b65f1@harvee.org> Message-ID: On 6/2/2016 2:03 PM, Joel Goldstick wrote: > Although the OP is using Windows 7, according to recent articles, > Ubuntu is teaming with MS for Windows 10 to include a bash shell, > presumably with the package management of Ubuntu (debian), with pip > goodness and virtualenv and virtualenvwrapper. That route should make > W10 and linux (ubuntu) nearly identical environments to deal with had forgotten about that. it should be released end of july and I am looking forward to the update! in the meantime, I'm suffering with cygwin :-) From chris at simplistix.co.uk Thu Jun 2 19:34:15 2016 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 2 Jun 2016 16:34:15 -0700 Subject: xlwt 1.1.1 released! Message-ID: <61a5bc56-ed51-5a83-bb37-c6442559a40b@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlwt 1.1.1. This release contains the following: - Fix SST BIFF record in Python 3. - Fix for writing ExternSheetRecord in Python 3. - Add the ability to insert bitmap images from buffers as well as files. - Official support for Python 3.5. Thanks to "thektulu" and Lele Gaifax for the Python 3 fixes. Thanks to Ross Golder for the support for inserting images from buffers. If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlwt/issues There's also details of all things Python and Excel related here: http://www.python-excel.org/ NB: If you would like to become the maintainer of xlwt, please get in touch! Neither myself nor John Machin have much time to drive things forward nowadays, hence the year or so between each release... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From kwa at kuwata-lab.com Thu Jun 2 19:54:00 2016 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Fri, 3 Jun 2016 08:54:00 +0900 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: Message-ID: On Thu, Jun 2, 2016 at 11:15 PM, Michael Selik wrote: > > > On Thu, Jun 2, 2016 at 10:06 AM Makoto Kuwata wrote: > >> os.mkdir(name) >> with open(name + "/__init__.py", 'w') as f: >> f.write("X=1") >> f.flush() >> >> Please give me any advices or hints. >> > > This wasn't your question, but you don't need to flush the file. The > ``with`` statement will automatically flush and close your file for you > after you exit the block. > Thanks. I'm sure that with-statement close file, but not sure whether it flushes or not. Any hints or advices for ogiginal question? -- regards, makoto From python at mrabarnett.plus.com Thu Jun 2 20:31:02 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 3 Jun 2016 01:31:02 +0100 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: Message-ID: <07867e05-0763-5a2e-b3b1-906bcf3fb1f0@mrabarnett.plus.com> On 2016-06-02 15:04, Makoto Kuwata wrote: > Hi, > > I have a trouble around __import__(). > The following sample code works well on Python <= 3.3, > but it raises ImportError on Python >= 3.4. > > > ## importtest.py > import sys, os, shutil > > def test(name): > try: > ## create 'foo/__init__.py' file > os.mkdir(name) > with open(name + "/__init__.py", 'w') as f: > f.write("X=1") > f.flush() > ## ipmort 'foo' module > mod = __import__(name) > finally: > if os.path.isdir(name): > shutil.rmtree(name) > > test("foo") # no errors > test("bar") # may raise error on Python >= 3.4. Why? > > > Output Example: > > ### No errors (Python <= 3.3) > ubuntu$ export PYTHONPATH=. > ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.3 importtest.py; done > > ### ImportError (Python >= 3.4) > ubuntu$ export PYTHONPATH=. > ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.4 importtest.py; done > Traceback (most recent call last): > File "tmp/importtest.py", line 19, in > test("bar") # may raise error on Python >= 3.4. Why? > File "tmp/importtest.py", line 13, in test > mod = __import__(name) > ImportError: No module named 'bar' > > > Please give me any advices or hints. > Thanks. > Things to try: Does the order matter? If you try "bar" then "foo" does "foo" fail? Does the directory matter? Is there something called "bar" in the directory already? What does the created "bar" directory contain? Does it really contain only "__init__.py"? You're testing the script 3 times; on which iteration does it fail? From lawrencedo99 at gmail.com Thu Jun 2 21:05:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 18:05:09 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote: > One major objection was that C's 'for' isn't really a for-statement at > all (as it is understood in most other languages that haven't just > copied C's version), but is closer to a 'while' statement. Apart from having local loop variables that get initialized just once. Not something you can fake with a ?while? statement. That?s what makes C?s for-statement so versatile. From lawrencedo99 at gmail.com Thu Jun 2 21:08:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 18:08:10 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> On Friday, June 3, 2016 at 8:09:21 AM UTC+12, Rob Gaddi wrote: > Although your loop is really the _canonical_ use case for > > for loopvar in range(initial_value, limit+1): > processing > if found_what_im_looking_for: > break > else: > do_whatever_it_is_you_do_when_its_not_found The reason why I don?t like this is that there are two ways out of the Python for-statement, and they are written quite differently. Why the asymmetry? Logically, all ways out of a loop are of equal significance. From lawrencedo99 at gmail.com Thu Jun 2 21:11:19 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 18:11:19 -0700 (PDT) Subject: Don't put your software in the public domain In-Reply-To: <87wpm7ixp0.fsf@elektro.pacujo.net> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <57501efe$0$1583$c3e8da3$5496439d@news.astraweb.com> <87wpm7ixp0.fsf@elektro.pacujo.net> Message-ID: <4de00f0c-9649-43d7-baf5-798db651b747@googlegroups.com> On Friday, June 3, 2016 at 12:26:33 AM UTC+12, Marko Rauhamaa wrote: > If the author has one right to their work, it is relinquishing all rights to > that work. In Europe, you don?t have that right. > All works will eventually fall into the public domain anyway... Not if certain large corporations have anything to say about it. From lawrencedo99 at gmail.com Thu Jun 2 21:13:25 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 18:13:25 -0700 (PDT) Subject: Recommendation for Object-Oriented systems to study In-Reply-To: References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> <201605291812.u4TI9dqP037317@mx0a-001b2d01.pphosted.com> <48967b8e-773b-472d-8a1a-89135e78e4f5@googlegroups.com> <201606021215.u52CFRGH000798@mx0a-001b2d01.pphosted.com> Message-ID: On Friday, June 3, 2016 at 12:16:02 AM UTC+12, Alan Evangelista wrote: > The point was which programming language was better to teach object oriented > concepts... Object-orientation is not an end in itself. The point is what programming languages you should be exposed to, to get an idea of how to do PROGRAMMING. From chris at simplistix.co.uk Thu Jun 2 21:56:55 2016 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 2 Jun 2016 18:56:55 -0700 Subject: xlrd 0.9.4 released! Message-ID: <92f1ca45-f519-54e8-932e-1d8c0b32baaa@simplistix.co.uk> Hi All, Well, I've finally called it and tagged current master of xlrd as 1.0.0: http://pypi.python.org/pypi/xlrd/1.0.0 This release includes the following changes since the last release: - Official support, such as it is, is now for 2.6, 2.7, 3.3+ - Fixes a bug in looking up non-lowercase sheet filenames by ensuring that the sheet targets are transformed the same way as the component_names dict keys. - Fixes a bug for ragged_rows=False when merged cells increases the number of columns in the sheet. This requires all rows to be extended to ensure equal row lengths that match the number of columns in the sheet. - Fixes to enable reading of SAP-generated .xls files. - support BIFF4 files with missing FORMAT records. - support files with missing WINDOW2 record. - Empty cells are now always unicode strings, they were a bytestring on Python2 and a unicode string on Python3. - Fix for inlineStr attribute without child. - Fix for a zoom of None causes problems on Python 3. - Fix parsing of bad dimensions. - Fix xlsx sheet->comments relationship. Thanks to the following for their contributions to this release: - Lars-Erik Hannelius - Deshi Xiao - Stratos Moro - Volker Diels-Grabsch - John McNamara - Ville Skytt? - Patrick Fuller - Dragon Dave McKee - Gunnlaugur ??r Briem If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlrd/issues Full details of all things Python and Excel related can be found here: http://www.python-excel.org/ NB: If you would like to become the maintainer of xlwt, please get in touch! Neither myself nor John Machin have much time to drive things forward nowadays, hence the year or so between each release... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Thu Jun 2 21:57:31 2016 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 2 Jun 2016 18:57:31 -0700 Subject: xlrd 1.0.0 released! In-Reply-To: <92f1ca45-f519-54e8-932e-1d8c0b32baaa@simplistix.co.uk> References: <92f1ca45-f519-54e8-932e-1d8c0b32baaa@simplistix.co.uk> Message-ID: <060dd4d0-cc82-a849-2041-45768b548eab@simplistix.co.uk> Ugh, and once again, this time with a corrected title... On 02/06/2016 18:56, Chris Withers wrote: > Hi All, > > Well, I've finally called it and tagged current master of xlrd as 1.0.0: > > http://pypi.python.org/pypi/xlrd/1.0.0 > > This release includes the following changes since the last release: > > - Official support, such as it is, is now for 2.6, 2.7, 3.3+ > > - Fixes a bug in looking up non-lowercase sheet filenames by ensuring > that the sheet targets are transformed the same way as the > component_names dict keys. > > - Fixes a bug for ragged_rows=False when merged cells increases the > number of columns in the sheet. This requires all rows to be extended > to ensure equal row lengths that match the number of columns in the > sheet. > > - Fixes to enable reading of SAP-generated .xls files. > > - support BIFF4 files with missing FORMAT records. > > - support files with missing WINDOW2 record. > > - Empty cells are now always unicode strings, they were a bytestring > on Python2 and a unicode string on Python3. > > - Fix for inlineStr attribute without child. > > - Fix for a zoom of None causes problems on Python 3. > > - Fix parsing of bad dimensions. > > - Fix xlsx sheet->comments relationship. > > Thanks to the following for their contributions to this release: > > - Lars-Erik Hannelius > - Deshi Xiao > - Stratos Moro > - Volker Diels-Grabsch > - John McNamara > - Ville Skytt? > - Patrick Fuller > - Dragon Dave McKee > - Gunnlaugur ??r Briem > > If you find any problems, please ask about them on the > python-excel at googlegroups.com list, or submit an issue on GitHub: > > https://github.com/python-excel/xlrd/issues > > Full details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > NB: If you would like to become the maintainer of xlwt, please get in > touch! Neither myself nor John Machin have much time to drive things > forward nowadays, hence the year or so between each release... > > cheers, > > Chris > From lawrencedo99 at gmail.com Thu Jun 2 22:47:32 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 2 Jun 2016 19:47:32 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote: > Simple iterative for-loops are more of a DIY effort... There is one case that Python handles more nicely than C. And that is iterating over a fixed set of values. E.g. in Python for rendering in (False, True) : ... #end for versus the (slightly) more long-winded C: for (bool rendering = false;;) { ... if (rendering) break; rendering = true; } /*for*/ From muhammadaliaskari at gmail.com Fri Jun 3 00:02:22 2016 From: muhammadaliaskari at gmail.com (Muhammad Ali) Date: Thu, 2 Jun 2016 21:02:22 -0700 (PDT) Subject: Python on Windows with linux environment In-Reply-To: References: <50ab8154-ac2c-a613-99de-d922e87b65f1@harvee.org> Message-ID: <430b4bf9-e6d9-4368-bbcf-568fdc3c93d7@googlegroups.com> On Friday, June 3, 2016 at 6:27:50 AM UTC+8, Eric S. Johansson wrote: > On 6/2/2016 2:03 PM, Joel Goldstick wrote: > > Although the OP is using Windows 7, according to recent articles, > > Ubuntu is teaming with MS for Windows 10 to include a bash shell, > > presumably with the package management of Ubuntu (debian), with pip > > goodness and virtualenv and virtualenvwrapper. That route should make > > W10 and linux (ubuntu) nearly identical environments to deal with > > had forgotten about that. it should be released end of july and I am > looking forward to the update! in the meantime, I'm suffering with > cygwin :-) Please send me the link through which I can get regular updates about this new release. From bob.martin at excite.com Fri Jun 3 07:14:05 2016 From: bob.martin at excite.com (Bob Martin) Date: Fri, 03 Jun 2016 07:14:05 BST Subject: Recommendation for Object-Oriented systems to study References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> Message-ID: in 760378 20160602 131534 Alan Evangelista wrote: >On 06/02/2016 02:44 AM, Lawrence D???Oliveiro wrote: >> On Monday, May 30, 2016 at 7:17:47 AM UTC+12, Alan Evangelista wrote: >>> - Java forces everything to be implemented in OO model (classes) >> After you have spend a few months battering your head against the rigidity and verbosity of Java, >> you will run back to Python with a sense of relief. > >The point was which programming language was better to teach object oriented concepts, >rigidity and verbosity has nothing to do with this. Most of this discussion has leaned towards >other criteria beyond adherence to OO paradigm (eg static typing vs dynamic typing and >personal taste), so I have chosen to not continue it. > >For some reason, Java still one of the most used programming languages to teach OO >in universities. In real life projects, people has the freedom to choose whatever they >prefer, though. =) Rarely; the employer usually decides which language(s) to use. From p.h.phan2006 at gmail.com Fri Jun 3 05:07:37 2016 From: p.h.phan2006 at gmail.com (Phuong Phan) Date: Fri, 3 Jun 2016 18:07:37 +0900 Subject: Recommendation for Object-Oriented systems to study In-Reply-To: References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> Message-ID: Hi All, I think you all are very professional programmer and or working in IT industry, teaching programming and so on. So I think it is quite funny that you spent time to discuss about this topic. I am not pro like you guys. I like programming. And when I think to develop my career as an IT engineer, I also do not know which language I should start, although, I know a bit C, Perl, Visual Basic. Luckily I found a free course on edX teaching computer science using Python. I really surprised that Python is so easy to learn. I like the beautiful simplicity at the beginning of learning Python. Really impressive to me. However, when I have chance to learn and work with other languages such as C# and C++. I found that they are also supercool. At that time it is clear to me that there is no best language. Each language has its good points. It is up to you to use/explore it and develop it too. So again, it is funny to me to ask which language should learn first, or which language should be used to teach/learn OO. Now if someone asks me which language should learn first, I would say it is C, definitely and no doubt C. By the way, now I bought some books about Python, OpenCV, and Robotics. Time to enjoy Python now. Regards, Phuong (By the way, I do not like snake image of Python much :-)) On Fri, Jun 3, 2016 at 2:14 PM, Bob Martin wrote: > in 760378 20160602 131534 Alan Evangelista > wrote: > >On 06/02/2016 02:44 AM, Lawrence D?Oliveiro wrote: > >> On Monday, May 30, 2016 at 7:17:47 AM UTC+12, Alan Evangelista wrote: > >>> - Java forces everything to be implemented in OO model (classes) > >> After you have spend a few months battering your head against the > rigidity and verbosity of Java, > >> you will run back to Python with a sense of relief. > > > >The point was which programming language was better to teach object > oriented concepts, > >rigidity and verbosity has nothing to do with this. Most of this > discussion has leaned towards > >other criteria beyond adherence to OO paradigm (eg static typing vs > dynamic typing and > >personal taste), so I have chosen to not continue it. > > > >For some reason, Java still one of the most used programming languages to > teach OO > >in universities. In real life projects, people has the freedom to choose > whatever they > >prefer, though. =) > > Rarely; the employer usually decides which language(s) to use. > > -- > https://mail.python.org/mailman/listinfo/python-list > > From bc at freeuk.com Fri Jun 3 05:23:54 2016 From: bc at freeuk.com (BartC) Date: Fri, 3 Jun 2016 10:23:54 +0100 Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: On 03/06/2016 02:05, Lawrence D?Oliveiro wrote: > On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote: >> One major objection was that C's 'for' isn't really a for-statement at >> all (as it is understood in most other languages that haven't just >> copied C's version), but is closer to a 'while' statement. > > Apart from having local loop variables that get initialized just once. Not something you can fake with a ?while? statement. It's not hard. For: for (int A=B; C; D) {BODY} you just write: {int A=B; while (C) { BODY; D; } } > > That?s what makes C?s for-statement so versatile. > That's if you're into that. I've only ever use local variables with function-wide scope. If your concern is with optimising, other languages can just have a rule about the validity of a for-loop index variable when the loop terminates. That's impossible in C because, it being so general purpose, there is no such thing as a for-loop index: a=0; b=1; for (c=2; d References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> Message-ID: On 03/06/2016 03:47, Lawrence D?Oliveiro wrote: > On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote: >> Simple iterative for-loops are more of a DIY effort... > > There is one case that Python handles more nicely than C. And that is iterating over a fixed set of values. E.g. in Python > > for rendering in (False, True) : > ... > #end for > > versus the (slightly) more long-winded C: > > for (bool rendering = false;;) > { > ... > if (rendering) > break; > rendering = true; > } /*for*/ > Just one case? Python is miles away from a C 'for'. There's: - C's for loop, a glorified while loop where you have specify every single detail: for (i=a; i<=b; ++i), including writing your nominated loop index three times. - A 'traditional' for loop, which iterates over the integers A to B or 0 to N-1 without having to spell out everything: for i=a,b - A 'forall' kind of loop which iterates over a set of values, which is what Python has: for i in x: -- Bartc From steve at pearwood.info Fri Jun 3 05:53:34 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 03 Jun 2016 19:53:34 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> On Thu, 2 Jun 2016 04:41 pm, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html > > From that: >> It might be ruled to create a global licence for unrestricted use. That > > licence might or might not then be adjudicated to be revocable by > > subsequent copyright owners (heirs, divorcing spouses, creditors). > > If that's possible, then could said heirs, divorcing spouses > and creditors also revoke supposedly permanent rights granted > under an explicit licence? Or is putting the word "irrevocable" > in the licence enough to prevent that? Further thoughts on this question... A licence is something like a contract, in that it is binding on both parties unless mutually agreed by both parties. With something like the MIT licence, there's no action that the licensee (the user of the software) can do to void the contract. And since there is no expiry date, the licence lasts forever, hence the author cannot unilaterally cancel the licence. Even if subsequent copyright owners (heirs etc) stop distributing the software to *new* users, existing licensees still have the right to distribute the software. On the other hand, the GPL can be revoked, since the licence requires the users to do something: if you distribute software based on the GPLed code, you must also distribute the source code under the same licence terms. If the user fails to do so, then one of two things happen: (1) If the GPL licence is valid, then they are in breach of the licence terms, the licence is revoked, and they are not legally permitted to distribute or use the software; (2) If, as some people insist, the GPL licence is not valid, then they have no valid licence, and are not legally permitted to distribute or use the software. That's why, for all the talk about the GPL never being held up in court, *nobody* has ever challenged it in court. If they did, and failed, then they would be in breach of copyright. If they succeeded, they would still be in breach of copyright. Any user of GPLed software who challenged it would be shooting themselves in the head: *either way*, win or lose, they would be in breach of copyright law. (Reminder: I am not a lawyer and this is not legal advice.) -- Steven From mal at europython.eu Fri Jun 3 06:00:18 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 3 Jun 2016 12:00:18 +0200 Subject: =?UTF-8?Q?EuroPython_2016_Keynote:_Ga=c3=abl_Varoquaux?= Message-ID: <57515532.7080807@europython.eu> We are pleased to announce our final keynote speaker for EuroPython 2016: *** Ga?l Varoquaux *** About Ga?l Varoquaux -------------------- Ga?l Varoquaux is an INRIA faculty researcher working on data science for brain imaging in the Neurospin brain research institute (Paris, France). His research focuses on modeling and mining brain activity in relation to cognition. Years before the NSA, he was hoping to make bleeding-edge data processing available across new fields, and he has been working on a mastermind plan building easy-to-use open-source software in Python. He is a core developer of scikit-learn, joblib, Mayavi and nilearn, a nominated member of the PSF, and often teaches scientific computing with Python using the scipy lecture notes. The Keynote: Scientist meets web dev: how Python became the language of data --------------------------------------------------------------- Python started as a scripting language, but now it is the new trend everywhere and in particular for data science, the latest rage of computing. It didn?t get there by chance: tools and concepts built by nerdy scientists and geek sysadmins provide foundations for what is said to be the sexiest job: data scientist. "In my talk I?ll give a personal perspective, historical and technical, on the progress of the scientific Python ecosystem, from numerical physics to data mining. I will discuss low-level technical aspects, such as how the Python world makes it easy to move large chunks of number across code, touch upon current exciting developments in scikit-learn and joblib, but also talk about softer topics, such as project dynamics or documentation, as software?s success is determined by people." With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/738669507724595200 Thanks. From gandalf at shopzeus.com Fri Jun 3 08:10:22 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 3 Jun 2016 14:10:22 +0200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: > > In Python 3, that will be automatic and you don't need to worry about it. I'm using Python 3. I'm aware of old style and new style classes in Python 2. > > > [...] >> class BootstrapDesktop(BootstrapWidget, BaseDesktop): >> def __init__(self, appserver, session): >> # there is NOTHING else here, it just connects bootstrap widget >> implementation with desktop methods >> super(BootstrapDesktop, self).__init__(appserver, session) > The correct way to do that is to simply not define an __init__ method at > all. But I have to initialize some default attributes. I could put them into a method called something else, but that would have the same problem. The question I put up is not specific to constructors, initializers or whatever. It was a general question about super() being used in a hierarchy with different signatures of the same method. I'm not sure why everybody started to discuss __init__ and __new__ :-) > Raymond Hettinger gives an excellent presentation where he describes various > problems with MI and gives solutions for them. I think this might be it: > > http://pyvideo.org/video/1094/the-art-of-subclassing-0 I'm going to get back when I'm done with this video. It will take some hours. :-) >> There is a single class (Widget) that has changed the signature of the >> constructor. > Is this your code? Then simply fix Widget. MI in Python is cooperative: all > the classes have to be designed for MI. It seems that Widget is not. > (Possibly I have misdiagnosed the problem, and the fault lies elsewhere.) If I knew what would be a good fix, I would do it. Somebody else suggested to always use *args and **kwargs. That would be cooperative for sure. But then It would be much harder to document the code (with Sphinx for example), or use the syntax analyzer of an IDE (say PyCharm) and have code completion. (Although the later is not a good argument against the language itself.) > Even if you got your wish, you couldn't use it until you're using Python 3.6 > or higher. Yes, I know. I do this for fun, not for money. > That's overly strict. As Raymond shows, it is easy to deal with > changing method signatures in *cooperative* classes. I must watch that for sure. > Perhaps you are unaware that manually calling the superclass method does not > work correctly in cases of multiple inheritance? You end up either missing > classes, and not calling their method, or calling them twice. That's why > you need to use a proper linearisation algorithm, as used by super. > > See this explanation of C3 linearisation here: > > https://www.python.org/download/releases/2.3/mro/ I do not use diamond shapes in my hierarchy, I guess that does not affect me. I may be wrong. Thank you! Laszlo From gandalf at shopzeus.com Fri Jun 3 08:14:33 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 3 Jun 2016 14:14:33 +0200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <425660d4-7bc8-a2ea-f76b-0bafa953af8f@shopzeus.com> > Raymond Hettinger gives an excellent presentation where he describes various > problems with MI and gives solutions for them. I think this might be it: > > http://pyvideo.org/video/1094/the-art-of-subclassing-0 This is a much better version from one year later: https://www.youtube.com/watch?v=miGolgp9xq8 From ben+python at benfinney.id.au Fri Jun 3 08:21:22 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 03 Jun 2016 22:21:22 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85k2i65upp.fsf@benfinney.id.au> Nagy L?szl? Zsolt writes: > > [...] > >> class BootstrapDesktop(BootstrapWidget, BaseDesktop): > >> def __init__(self, appserver, session): > >> # there is NOTHING else here, it just connects bootstrap widget > >> implementation with desktop methods > >> super(BootstrapDesktop, self).__init__(appserver, session) > > The correct way to do that is to simply not define an __init__ method at > > all. > But I have to initialize some default attributes. Then the statement ?there is NOTHING else here? must be false. Either the custom ?__init__? does something useful, or it doesn't. > > See this explanation of C3 linearisation here: > > > > https://www.python.org/download/releases/2.3/mro/ > I do not use diamond shapes in my hierarchy, I guess that does not > affect me. I may be wrong. With classes all inheriting ultimately from ?object? (as all Python 3 classes do, and as all current Python 2 classes should), mutliple inheritance inevitably places your classes in a diamond inheritance pattern. And, what's more, you can't know when writing a class whether it participates in a multiple inheritance hierarchy! So in practice you must write every class so that it will behave well in a diamond inheritance pattern. All this is covered in Raymond Hettinger's material, so it's best that I just leave you to read that. -- \ ?If the arguments in favor of atheism upset you, explain why | `\ they?re wrong. If you can?t do that, that?s your problem.? | _o__) ?Amanda Marcotte, 2015-02-13 | Ben Finney From esj at harvee.org Fri Jun 3 08:27:30 2016 From: esj at harvee.org (Eric S. Johansson) Date: Fri, 3 Jun 2016 08:27:30 -0400 Subject: Python on Windows with linux environment In-Reply-To: <430b4bf9-e6d9-4368-bbcf-568fdc3c93d7@googlegroups.com> References: <50ab8154-ac2c-a613-99de-d922e87b65f1@harvee.org> <430b4bf9-e6d9-4368-bbcf-568fdc3c93d7@googlegroups.com> Message-ID: <90c9e426-53c6-4b49-6b9e-a782fd00fc82@harvee.org> On 6/3/2016 12:02 AM, Muhammad Ali wrote: > On Friday, June 3, 2016 at 6:27:50 AM UTC+8, Eric S. Johansson wrote: >> On 6/2/2016 2:03 PM, Joel Goldstick wrote: >>> Although the OP is using Windows 7, according to recent articles, >>> Ubuntu is teaming with MS for Windows 10 to include a bash shell, >>> presumably with the package management of Ubuntu (debian), with pip >>> goodness and virtualenv and virtualenvwrapper. That route should make >>> W10 and linux (ubuntu) nearly identical environments to deal with >> had forgotten about that. it should be released end of july and I am >> looking forward to the update! in the meantime, I'm suffering with >> cygwin :-) > > Please send me the link through which I can get regular updates about this new release. switch to windows 10 and wait. MS will cram an update into your machine :-) From steve at pearwood.info Fri Jun 3 08:47:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 03 Jun 2016 22:47:13 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <85h9de6lp4.fsf@benfinney.id.au> <52defc17-a6e6-4f7e-a91d-4e1e3b263b55@googlegroups.com> <57506e90$0$1602$c3e8da3$5496439d@news.astraweb.com> <1464902301.3337770.626326969.25D8DFDE@webmail.messagingengine.com> Message-ID: <57517c53$0$1601$c3e8da3$5496439d@news.astraweb.com> On Fri, 3 Jun 2016 07:18 am, Random832 wrote: > On Thu, Jun 2, 2016, at 13:36, Steven D'Aprano wrote: [...] >> But since the constructor/initialiser methods are so closely linked, many >> people are satisfied to speak loosely and refer to "the constructor" as >> either, unless they specifically wish to distinguish between __new__ and >> __init__. > > Where there is looseness, it comes from the fact that because __init__ > is always called even if __new__ returns a pre-existing object That's not quite correct. __init__ is not always called: If __new__() does not return an instance of cls, then the new instance?s __init__() method will not be invoked. https://docs.python.org/3/reference/datamodel.html#object.__new__ > people > often place code in __new__ which mutates the object to be returned, > acting somewhat like a traditional constructor by assigning attributes > etc. > > But it is __init__ that acts like the thing that is called a constructor > in many languages, and no-one's produced a single example of a language > which uses "constructor" for something which allocates memory. Yes you have: Python. Like it or not, it is common usage to call __new__ the constructor and __init__ the initialiser. Even if the official docs are agnostic on the issue, it is still widespread (but not universal) in the Python community. I have only come across two languages that split the "constructor" into two methods, Objective C and Python. That does make Python rather special compared to most other OO languages. Objective C calls the part that allocates memory "alloc" (and is presumably known as "the allocator") and the part which initialises it "init". "init" is explicitly and officially known as the initialiser. Here's that link again in case you missed it. https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/index.html#//apple_ref/occ/instm/NSObject/init Even if you dismiss Python, you can't dispute that the official Apple docs for Cocoa refer to initialiser rather than constructor. Python also follows that pattern of splitting the "constructor" into two: __new__ and __init__. Until Python 2.2 introduced new-style classes, it was common to refer to __init__ as the constructor. For instance, I have the Python Pocket Reference from Python 1.5 which describes __init__ as: Constructor: initialize the new instance, self. When object and new-style classes were introduced, people wanted to distinguish them. Since __new__ constructs the object, and __init__ initialises it (even in old-style classes __init__ is said to *initialise* the instance), it seems natural to call __new__ the constructor and __init__ the initialiser. Perhaps we ought to have called them the allocator and the initialiser. If you want to lead the push for that terminology, please be my guest. -- Steven From mbg1708 at planetmail.com Fri Jun 3 08:56:10 2016 From: mbg1708 at planetmail.com (mbg1708 at planetmail.com) Date: Fri, 3 Jun 2016 05:56:10 -0700 (PDT) Subject: Storing data in mysql In-Reply-To: References: Message-ID: On Thursday, 2 June 2016 09:51:59 UTC+1, Anup reni wrote: > How to store this 3 dimensional data in Mysql database for plotting on map? > ? Actually, this looks like a question about the use of the SQL standard. I really like Joe Celko's book "Instant SQL Programming".....which provides LOTS of advice about portable SQL....likely across multiple SQL platforms..... ....and of course, both the question and my answer have nothing to do with Python or plotting or maps. From gandalf at shopzeus.com Fri Jun 3 08:57:52 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 3 Jun 2016 14:57:52 +0200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <85k2i65upp.fsf@benfinney.id.au> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <85k2i65upp.fsf@benfinney.id.au> Message-ID: >> But I have to initialize some default attributes. > Then the statement ?there is NOTHING else here? must be false. Either > the custom ?__init__? does something useful, or it doesn't. Well... the custom __init__ method with nothing else just a super() call was expressed there to show the super() call explicitly, and to emphasize that in that particular class, super() is used instead of an explicit base method call. It is not a pattern to be followed, just syntactic sugar for the sake of the example. So you are right: the custom __init__ in the BootstrapDesktop class is not really needed, and does not do anything useful in that particular class. My original statement was this: "I have to initialize some default attributes", and for that I need to pass arguments. The truthness of this statement is not affected by adding a useless override of a method (with the very same parameters). Even though I see that you are right in what you wrote, I think I don't understand the point because it seem unrelated. > All this is covered in Raymond Hettinger's material, so it's best that I > just leave you to read that. > Is it available in written form? I have tried to watch the video, but the sound quality is so poor that I cannot understand. I have tried to search for a better one, but that is a different one. :-( From torriem at gmail.com Fri Jun 3 09:14:30 2016 From: torriem at gmail.com (Michael Torrie) Date: Fri, 3 Jun 2016 07:14:30 -0600 Subject: Don't put your software in the public domain In-Reply-To: <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jun 3, 2016 04:57, "Steven D'Aprano" wrote: > (1) If the GPL licence is valid, then they are in breach of the licence > terms, the licence is revoked, and they are not legally permitted to > distribute or use the software; > > (2) If, as some people insist, the GPL licence is not valid, then they have > no valid licence, and are not legally permitted to distribute or use the > software. > > That's why, for all the talk about the GPL never being held up in court, > *nobody* has ever challenged it in court. If they did, and failed, then > they would be in breach of copyright. If they succeeded, they would still > be in breach of copyright. Any user of GPLed software who challenged it > would be shooting themselves in the head: *either way*, win or lose, they > would be in breach of copyright law. I'm not sure this is completely right. The GPL explicitly says one doesn't have to agree to the GPL to use the software. The GPL only comes into affect when distribution is involved. So challenging the legitimacy of the GPL in court (which certainly has happened in Germany) wouldn't prevent one from using the GPL software. Only from distributing it. From gandalf at shopzeus.com Fri Jun 3 10:06:12 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 3 Jun 2016 16:06:12 +0200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> That's overly strict. As Raymond shows, it is easy to deal with >> changing method signatures in *cooperative* classes. > I must watch that for sure. All right, I have read this: https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ There is still something I don't get: how to create cooperative classes when some base classes share some of the parameters? Here is an example modified from Raymond's post: class A: def __init__(self, param1, param2, **kwds): self.param1 = param1 self.param2 = param2 super().__init__(**kwds) class B: def __init__(self, param1, param3, **kwds): self.param1 = param1 self.param3 = param3 super().__init__(**kwds) class X(A,B): def __init__(self, param1, param2, param3, **kwds): print("param1=",param1,"param2=",param2,"param3=",param3) super().__init__(param1=param1,param2=param2,param3=param3,**kwds) print(X.__mro__) x = X(1,2,3) Result: (, , , ) param1= 1 param2= 2 param3= 3 Traceback (most recent call last): File "test.py", line 20, in x = X(1,2,3) File "test.py", line 17, in __init__ super().__init__(param1=param1,param2=param2,param3=param3,**kwds) File "test.py", line 5, in __init__ super().__init__(**kwds) TypeError: __init__() missing 1 required positional argument: 'param1' I could only find this as a solution: class Root: def __init__(self, **kwds): pass class A(Root): def __init__(self, **kwds): self.param1 = kwds['param1'] self.param2 = kwds['param2'] super().__init__(**kwds) class B(Root): def __init__(self, **kwds): self.param1 = kwds['param1'] self.param3 = kwds['param3'] super().__init__(**kwds) class X(A,B): def __init__(self, param1, param2, param3, **kwds): print("param1=",param1,"param2=",param2,"param3=",param3) super().__init__(param1=param1,param2=param2,param3=param3,**kwds) X(1,2,3) But then self documentation and code completion becomes very problematic: http://i.imgur.com/wzlh8uy.png From flebber.crue at gmail.com Fri Jun 3 10:20:24 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 3 Jun 2016 07:20:24 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? Message-ID: Very briefly because I hope to shot down eloquently. Python is beautiful and is supposed to be a duck typed language, Yes? Then if I create and assign to a new variable with a list action why does the duck not quack? It feels wrong to spend a line writing what is already obvious def getsMeet(files=file_list): """Get a File or List of Files. From the list of files determine what meetings exist and prepare them to be parsed """ pyqFiles = [] for filename in sorted(file_list): pyqFiles = pyqFiles.append(pq(filename=my_dir + filename)) return pyqFiles Here I have to write that pyqFiles is a list before I take an explicit list action and append to it, if i create a variable and make it quack a list isn't it a list? Assuming the answer is going to be that some methods apply to multiple types if not then what is happening? Sayth PS I am really having a lot of fun coding. From flebber.crue at gmail.com Fri Jun 3 10:24:42 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 3 Jun 2016 07:24:42 -0700 (PDT) Subject: Recommendation for Object-Oriented systems to study In-Reply-To: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> Message-ID: On Monday, 30 May 2016 00:42:17 UTC+10, Ankush Thakur wrote: > Hello, > > I'm a self-taught programmer who has managed to claw his way out of Python basics and even covered the intermediate parts. But I feel I have a ton of theory in my head and would like to see some smallish applications in action. More specifically, I'm looking for Object Oriented designs that will help me cement my knowledge and expose me to best practices that books never cover. I have half a mind to start reading up the Django or Pandas source code, but I don't want to overwhelm myself. > > Can somebody recommend smaller and simpler projects I can learn from? And if I can pick the brains of the creator, bonus points! > > Thanks in advance! > > Ankush Hi Ankush Can I refer you to a book, which isn't about object oriented design its actually about functional design, please wait though its one of the best books I am reading haven't made it to the end yet :-) The author has written several books and about python object oriented design, but in writing about functional python it forces him to talk about when functional is good or bad and which parts of the language respond best to which approach, plus its clearly and straightforwardly written. Its functional python programming by Steven Lott. Cheers Sayth From paul.nospam at rudin.co.uk Fri Jun 3 10:34:47 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 03 Jun 2016 15:34:47 +0100 Subject: I'm wrong or Will we fix the ducks limp? References: Message-ID: <87mvn22veg.fsf@rudin.co.uk> Sayth Renshaw writes: > Very briefly because I hope to shot down eloquently. > > Python is beautiful and is supposed to be a duck typed language, Yes? > > Then if I create and assign to a new variable with a list action why > does the duck not quack? > > It feels wrong to spend a line writing what is already obvious > The problem is that you think that *variables* have a type. This isn't the case. Objects have a type. A variable is a name by which you can refer to an object. There are various ways in which you can associate a object with a variable, the most obvious being an assignment statement. From ian.g.kelly at gmail.com Fri Jun 3 10:39:00 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Jun 2016 08:39:00 -0600 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 3, 2016 at 8:06 AM, Nagy L?szl? Zsolt wrote: > >>> That's overly strict. As Raymond shows, it is easy to deal with >>> changing method signatures in *cooperative* classes. >> I must watch that for sure. > > All right, I have read this: > > https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ > > There is still something I don't get: how to create cooperative classes > when some base classes share some of the parameters? Why do they need to share the same parameter? Part of cooperative design is that you can't really design each class in a vacuum; you need to take the other classes they might get combined with into account. Perhaps you can extract that parameter into another base class that is shared by both: class Root: def __init__(self, *, param1, **kwds): self.param1 = param1 super().__init__(**kwds) class A(Root): def __init__(self, *, param2, **kwds): self.param2 = param2 super().__init__(**kwds) class B(Root): def __init__(self, *, param3, **kwds): self.param3 = param3 super().__init__(**kwds) class X(A, B): pass A and B can both depend on having param1 without stomping on each other because they both inherit Root which requires it. From flebber.crue at gmail.com Fri Jun 3 11:04:39 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 3 Jun 2016 08:04:39 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <87mvn22veg.fsf@rudin.co.uk> References: <87mvn22veg.fsf@rudin.co.uk> Message-ID: <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> > The problem is that you think that *variables* have a type. This isn't > the case. Objects have a type. A variable is a name by which you can > refer to an object. There are various ways in which you can associate a > object with a variable, the most obvious being an assignment statement. So at the point I create the variable it refers to an object. More correctly when I create the variable and assign a list action to the variable I believe I should be creating a reference to a list object in one motion; however python would like me to create the object first before creating a reference to it, is that the catch? I am not allowed to create references to an object at the same time I create the object is that correct? Sayth From michael.selik at gmail.com Fri Jun 3 11:33:11 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 03 Jun 2016 15:33:11 +0000 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 3, 2016 at 10:41 AM Ian Kelly wrote: > On Fri, Jun 3, 2016 at 8:06 AM, Nagy L?szl? Zsolt > wrote: > > There is still something I don't get: how to create cooperative classes > > when some base classes share some of the parameters? > > Why do they need to share the same parameter? > Is the problem that the attribute or parameter has the same name in both base classes, but has different meanings in each? If so, and you're in control of every class in the inheritance hierarchy, perhaps you can come up with more specific names so that the bases no longer share the same attribute. If you can't change the base classes, I've got some other solutions, but they're more involved, so I'll wait to hear back. From ian.g.kelly at gmail.com Fri Jun 3 11:35:06 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Jun 2016 09:35:06 -0600 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: On Fri, Jun 3, 2016 at 9:04 AM, Sayth Renshaw wrote: > > >> The problem is that you think that *variables* have a type. This isn't >> the case. Objects have a type. A variable is a name by which you can >> refer to an object. There are various ways in which you can associate a >> object with a variable, the most obvious being an assignment statement. > > So at the point I create the variable it refers to an object. > > More correctly when I create the variable and assign a list action to the variable I believe I should be creating a reference to a list object in one motion; however python would like me to create the object first before creating a reference to it, is that the catch? > > I am not allowed to create references to an object at the same time I create the object is that correct? I'd say leave references out of this. They don't correspond 1:1 with variables, and bringing them up is only going to confuse the issue. When you call the append method you're not "assigning a list action" to the variable. You're just trying to call a method named "append". That could be the list append method. Or it could be the array append method. Or the deque append method. Or you may have written your own class with an append method. How is the interpreter supposed to know which one you mean? In general, it can't, so it doesn't try. You have to create an object before you can start doing anything it. From flebber.crue at gmail.com Fri Jun 3 11:50:28 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 3 Jun 2016 08:50:28 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: That totally makes sense I was just double checking, had hoped I could create a variable assign it to a list and append in one stroke. Thanks Sayth From rgaddi at highlandtechnology.invalid Fri Jun 3 11:52:29 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 3 Jun 2016 15:52:29 -0000 (UTC) Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> Message-ID: Lawrence D?Oliveiro wrote: > On Friday, June 3, 2016 at 8:09:21 AM UTC+12, Rob Gaddi wrote: >> Although your loop is really the _canonical_ use case for >> >> for loopvar in range(initial_value, limit+1): >> processing >> if found_what_im_looking_for: >> break >> else: >> do_whatever_it_is_you_do_when_its_not_found > > The reason why I don?t like this is that there are two ways out of the Python for-statement, and they are written quite differently. Why the asymmetry? Logically, all ways out of a loop are of equal significance. I wouldn't say that at all. One is early termination due to success. The other is that you've run out of things to try, and exit due to exhaustion of the iterator. They're two very different cases, the same as if I had wrapped the loop in a function: def roundabout(): for var in iterable: if successful(var): return var raise ValueError("Nothing works; all is lost") -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From m at funkyhat.org Fri Jun 3 11:54:39 2016 From: m at funkyhat.org (Matt Wheeler) Date: Fri, 03 Jun 2016 15:54:39 +0000 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: Hi, On Fri, 3 Jun 2016, 16:04 Sayth Renshaw, wrote: > > So at the point I create the variable it refers to an object. > It's best to think of them as names, rather than variables, as names in python don't behave quite how you'll expect variables to if you're coming from some other languages. More correctly when I create the variable and assign a list action to the > variable I believe I should be creating a reference to a list object in one > motion; however python would like me to create the object first before > creating a reference to it, is that the catch? > I'm not 100% sure what you mean by "assign a list action to the variable". `[]` is an empty list literal. Putting that in your code will create a new empty list object every time it's reached. `name =` assigns a new name which refers to the thing to the right of it. My best guess as to the source of your confusion is that you're not seeing the list as an object (let me know if I'm wrong). A list is an object just the same as the items you want to put in it, it's just a different type, it's not special syntax built into the language. That means you need to create one if you want it to be there. I am not allowed to create references to an object at the same time I > create the object is that correct? > That's exactly what `name = []` is doing (see above). > Assuming the answer is going to be that some methods apply to multiple types if not then what is happening? [from your first email] If you want to see it like this that might help. Any number of classes and not just the builtin list is likely to have an append method. Even if that were not true, expecting name.append() in a context where name doesn't exist to somehow magically create a list object for you, assign a name to it and then call the method you asked for would involve quite a few leaps of logic, faith or something. Consider a situation where you actually intended to create an instance of a different type which also has an `.append()` method, but somehow that went wrong (you spelt the name incorrectly, perhaps), which is preferable: Magic list creation mode: >>> name = OtherClassWithAppendMethod() >>> naem.append('this') Great. Now we have our desired OtherClassWithAppendMethod instance, which is empty, and a useless list which contains the stuff that should have been given to `name`. No errors, just a bug that's really really fun to track down. Regular boring Python: >>> name = OtherClassWithAppendMethod() >>> naem.append('this') NameError: name 'naem' is not defined > From gandalf at shopzeus.com Fri Jun 3 11:59:24 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 3 Jun 2016 17:59:24 +0200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <36545ac2-0aab-3ee6-fb60-c539c9c7c95a@shopzeus.com> > Is the problem that the attribute or parameter has the same name in both > base classes, but has different meanings in each? If they had different meanings, a simple rename would solve the problem. They have the same meaning. > If you can't change the base classes, I've got some other solutions, but > they're more involved, so I'll wait to hear back. One possible solution being encapsulating an object instead of inheriting from it? Fortunately, I can change all of the classes, and extracting the common parameter into a common base class worked. Problem solved. Thank you for all your help! Cooperative classes are fantastic! :-) From michael.selik at gmail.com Fri Jun 3 12:04:18 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 03 Jun 2016 16:04:18 +0000 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: On Fri, Jun 3, 2016 at 11:58 AM Sayth Renshaw wrote: > That totally makes sense I was just double checking, had hoped I could > create a variable assign it to a list and append in one stroke. > In fact you can! It's called a "list comprehension" pyqFiles = [pq(my_dir + filename) for filename in sorted(file_list)] From pkpearson at nowhere.invalid Fri Jun 3 12:05:43 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 3 Jun 2016 16:05:43 GMT Subject: I'm wrong or Will we fix the ducks limp? References: Message-ID: On Fri, 3 Jun 2016 07:20:24 -0700 (PDT), Sayth Renshaw wrote: [snip] > pyqFiles = [] > for filename in sorted(file_list): > pyqFiles = pyqFiles.append(pq(filename=my_dir + filename)) > > return pyqFiles [snip] > PS I am really having a lot of fun coding. To have even more fun, note that the above can be replaced by [untested]: return [pq(filename=my_dir + filename) for filename in sorted(file_list)] (By the way, the "pf = pf.append(thing)" construction is weird. All you need is pf.append(thing).) -- To email me, substitute nowhere->runbox, invalid->com. From gandalf at shopzeus.com Fri Jun 3 12:11:12 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 3 Jun 2016 18:11:12 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: Message-ID: <46f79572-b9ae-4898-13b4-97c2c5589e45@shopzeus.com> > def getsMeet(files=file_list): > """Get a File or List of Files. > > From the list of files determine > what meetings exist and prepare them > to be parsed > """ > pyqFiles = [] > for filename in sorted(file_list): > pyqFiles = pyqFiles.append(pq(filename=my_dir + filename)) > > return pyqFiles This may not be the answer you are seeking, but how about: def getsMeet(files=file_list): return [pq(filename=my_dir + filename) for filename in sorted(file_list)] If you can use any iterable instead of a list, then you can also consider using a generator: def getsMeet(files=file_list): for filename in sorted(file_list): yield pq(filename=my_dir + filename) for pg_obj in getsMeet(my_file_list): process(pg_obj) This way you do not need to construct a list at all, and it won't create all pq objects in advance. From lawrencedo99 at gmail.com Fri Jun 3 12:15:55 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 3 Jun 2016 09:15:55 -0700 (PDT) Subject: Don't put your software in the public domain In-Reply-To: <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, June 3, 2016 at 9:53:47 PM UTC+12, Steven D'Aprano wrote: > A licence is something like a contract... A licence is quite different from a contract. A contract requires some indication of explicit agreement by both parties, a licence does not. That?s why Free Software licences only have to say something like ?by using this software, you agree to the following terms...?, because if the user doesn?t accept the licence, then they have no licence. EULAs for proprietary software, on the other hand, try to have it both ways, by having a clause like the above, as well as requiring you to click an ?I Agree? button or some such. From lawrencedo99 at gmail.com Fri Jun 3 12:17:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 3 Jun 2016 09:17:22 -0700 (PDT) Subject: Recommendation for Object-Oriented systems to study In-Reply-To: References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> Message-ID: On Friday, June 3, 2016 at 9:12:19 PM UTC+12, Phuong Phan wrote: > However, when I have chance to learn and work with other languages such as > C# and C++. I found that they are also supercool. Have you been exposed to Lisp yet? From lawrencedo99 at gmail.com Fri Jun 3 12:22:11 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 3 Jun 2016 09:22:11 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> Message-ID: <1c46f375-ad3a-4a82-ad11-f72fd604a53a@googlegroups.com> On Friday, June 3, 2016 at 9:33:32 PM UTC+12, BartC wrote: > On 03/06/2016 03:47, Lawrence D?Oliveiro wrote: >> On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote: >>> Simple iterative for-loops are more of a DIY effort... >> >> There is one case that Python handles more nicely than C. > > Just one case? Python is miles away from a C 'for'. Yes, just one case. In Python you write a loop with one exit in one way, a loop with two exits in a different way, and a loop with more than two exits in yet another entirely different way. Can you say ?cognitive burden?? The for-statement in C handles most of my looping requirements. I rarely use while-loops, and do-whiles almost not at all--not for looping, anyway . From lawrencedo99 at gmail.com Fri Jun 3 12:24:31 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 3 Jun 2016 09:24:31 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> Message-ID: <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> On Saturday, June 4, 2016 at 3:52:42 AM UTC+12, Rob Gaddi wrote: > Lawrence D?Oliveiro wrote: > >> The reason why I don?t like this is that there are two ways out of the >> Python for-statement, and they are written quite differently. Why the >> asymmetry? Logically, all ways out of a loop are of equal significance. > > I wouldn't say that at all. One is early termination due to success. > The other is that you've run out of things to try, and exit due to > exhaustion of the iterator. They're two very different cases... Different in what way? A loop exit is a loop exit. It causes termination of the loop. From michael.selik at gmail.com Fri Jun 3 12:28:20 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 03 Jun 2016 16:28:20 +0000 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <36545ac2-0aab-3ee6-fb60-c539c9c7c95a@shopzeus.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <36545ac2-0aab-3ee6-fb60-c539c9c7c95a@shopzeus.com> Message-ID: On Fri, Jun 3, 2016 at 12:01 PM Nagy L?szl? Zsolt wrote: > > Is the problem that the attribute or parameter has the same name in > both base classes, but has different meanings in each? > If they had different meanings, a simple rename would solve the problem. > Sometimes finding a good name ain't so simple. > If you can't change the base classes, I've got some other solutions, but > > they're more involved, so I'll wait to hear back. > One possible solution being encapsulating an object instead of > inheriting from it? > That's one option, creating a wrapper class that dispatches almost everything to the contained class, except with one renamed attribute/method. From ankush.thakur53 at gmail.com Fri Jun 3 13:24:34 2016 From: ankush.thakur53 at gmail.com (Ankush Thakur) Date: Fri, 3 Jun 2016 10:24:34 -0700 (PDT) Subject: Recommendation for Object-Oriented systems to study In-Reply-To: References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> Message-ID: <8154a110-8aed-45be-b668-3a9ddf2b9ced@googlegroups.com> On Friday, June 3, 2016 at 7:54:55 PM UTC+5:30, Sayth Renshaw wrote: > On Monday, 30 May 2016 00:42:17 UTC+10, Ankush Thakur wrote: > > Hello, > > > > I'm a self-taught programmer who has managed to claw his way out of Python basics and even covered the intermediate parts. But I feel I have a ton of theory in my head and would like to see some smallish applications in action. More specifically, I'm looking for Object Oriented designs that will help me cement my knowledge and expose me to best practices that books never cover. I have half a mind to start reading up the Django or Pandas source code, but I don't want to overwhelm myself. > > > > Can somebody recommend smaller and simpler projects I can learn from? And if I can pick the brains of the creator, bonus points! > > > > Thanks in advance! > > > > Ankush > > Hi Ankush > > Can I refer you to a book, which isn't about object oriented design its actually about functional design, please wait though its one of the best books I am reading haven't made it to the end yet :-) > > The author has written several books and about python object oriented design, but in writing about functional python it forces him to talk about when functional is good or bad and which parts of the language respond best to which approach, plus its clearly and straightforwardly written. > > Its functional python programming by Steven Lott. > > Cheers > > Sayth Thanks, Sayth. Functional programming is indeed a very interesting paradigm, but I hear that Python's functional paradigms are cramped at best. I will learn a pure functional language later, but for now I'm looking for good old objects. Best, Ankush From ankush.thakur53 at gmail.com Fri Jun 3 13:28:42 2016 From: ankush.thakur53 at gmail.com (Ankush Thakur) Date: Fri, 3 Jun 2016 10:28:42 -0700 (PDT) Subject: Recommendation for Object-Oriented systems to study In-Reply-To: References: <53b21136-68ce-485c-8ccb-d6d28dace9c5@googlegroups.com> Message-ID: <837c6b65-deea-412f-b08a-763e19d5cdfd@googlegroups.com> On Wednesday, June 1, 2016 at 2:53:22 PM UTC+5:30, Terry Reedy wrote: > On 5/31/2016 1:52 PM, Ankush Thakur wrote: > > Hi Terry, > > > > Can you point me towards the source code? > > For IDLE 3.4.4 or 3.5.1: /Lib/idlelib/help.py, at least on > Windows. > > > by "after reading it carefully", do you mean you or me? :D > > You. I wrote it and already read it carefully. > > >> Beyond "pick a module with classes that interest you", I can suggest > >> idlelib.help, which I helped to write. If you ask, after reading it > >> carefully, I will point out what I consider positive features. > > -- > Terry Jan Reedy All right, it's a deal! Here's a link I found: https://github.com/python/cpython/blob/master/Lib/idlelib/help.py. Can I write to you with questions I might have? :) Best, Ankush From python at mrabarnett.plus.com Fri Jun 3 14:15:52 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 3 Jun 2016 19:15:52 +0100 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: <07867e05-0763-5a2e-b3b1-906bcf3fb1f0@mrabarnett.plus.com> Message-ID: <60d42dc5-f966-1baf-f044-bb7c07f58172@mrabarnett.plus.com> On 2016-06-03 06:48, Makoto Kuwata wrote: > On Fri, Jun 3, 2016 at 9:31 AM, MRAB > wrote: > > On 2016-06-02 15:04, Makoto Kuwata wrote: > > Hi, > > I have a trouble around __import__(). > The following sample code works well on Python <= 3.3, > but it raises ImportError on Python >= 3.4. > > > ## importtest.py > import sys, os, shutil > > def test(name): > try: > ## create 'foo/__init__.py' file > os.mkdir(name) > with open(name + "/__init__.py", 'w') as f: > f.write("X=1") > f.flush() > ## ipmort 'foo' module > mod = __import__(name) > finally: > if os.path.isdir(name): > shutil.rmtree(name) > > test("foo") # no errors > test("bar") # may raise error on Python >= 3.4. Why? > > > Output Example: > > ### No errors (Python <= 3.3) > ubuntu$ export PYTHONPATH=. > ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.3 > importtest.py; done > > ### ImportError (Python >= 3.4) > ubuntu$ export PYTHONPATH=. > ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.4 > importtest.py; done > Traceback (most recent call last): > File "tmp/importtest.py", line 19, in > test("bar") # may raise error on Python >= 3.4. Why? > File "tmp/importtest.py", line 13, in test > mod = __import__(name) > ImportError: No module named 'bar' > > > Please give me any advices or hints. > Thanks. > > Things to try: > > Does the order matter? If you try "bar" then "foo" does "foo" fail? > > > Yes. Name is not matter. Order is matter. > > > Does the directory matter? > > > No. I created "foo" and "bar" directories in order to create python > module. > > > Is there something called "bar" in the directory already? > > > No. Sample script removes directories every time. > > > What does the created "bar" directory contain? Does it really > contain only "__init__.py"? > > > Yes. See sample script for detail. > > You're testing the script 3 times; on which iteration does it fail? > > > Because sometimes script will fail and sometimes will work file. > It sounds like it's some kind of race condition, e.g. it hasn't finished writing the file before it does the import. From ben+python at benfinney.id.au Fri Jun 3 16:16:27 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 04 Jun 2016 06:16:27 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <85k2i65upp.fsf@benfinney.id.au> Message-ID: <85fusu58pw.fsf@benfinney.id.au> Nagy L?szl? Zsolt writes: > So you are right: the custom __init__ in the BootstrapDesktop class is > not really needed, and does not do anything useful in that particular > class. I disagree: setting initial attributes is a normal and useful case for defining a custom initialiser. > My original statement was this: "I have to initialize some default > attributes", and for that I need to pass arguments. Yes. If you need to initialise the instance, that's what a custom ?__init__? is for. > The truthness of this statement is not affected by adding a useless > override of a method (with the very same parameters). Even though I > see that you are right in what you wrote, I think I don't understand > the point because it seem unrelated. My point was rather that if the custom initialiser does *nothing* except call the superclass's initialiser, then there's no purpose to writing the custom initialiser. If you're writing a custom initialiser that handles two additional parameters, then those parameters should not be present when you call the super() method's initialiser:: # You specified Python 3, which allows simpler syntax. class LoremIpsum: def __init__(self, spam, *args, **kwargs): do_something_important_with(spam) super().__init__(*args, **kwargs) class DolorSitAmet(LoremIpsum): def __init__(self, spam, eggs=4, beans=None, *args, **kwargs): self.eggs = eggs self.beans = beans super().__init__(spam, *args, **kwargs) So the sub-class follows the Liskov Substitution Principle: every DolorSitAmet instance should be substitutable for LoremIpsum instances, and users that only expect a LoremIpsum instance should not need to know any difference. This entails that its methods (in this case the initialiser) will accept the same parameters as ?LoremIpsum.__init__?, and do the same things with those parameters. We make that explicit by omitting the *additional* parameters that we already handled, ?eggs? and ?beans?, from the next call in the chain. -- \ ?The difference between religions and cults is determined by | `\ how much real estate is owned.? ?Frank Zappa | _o__) | Ben Finney From ben+python at benfinney.id.au Fri Jun 3 16:19:15 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 04 Jun 2016 06:19:15 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <36545ac2-0aab-3ee6-fb60-c539c9c7c95a@shopzeus.com> Message-ID: <85bn3i58l8.fsf@benfinney.id.au> Nagy L?szl? Zsolt writes: > Fortunately, I can change all of the classes, and extracting the > common parameter into a common base class worked. This is why Liskov's Substitution Principle is good: Thinking of it as a law helps lead to better design. In this case, the same parameter doing different things in different sub-classes meant that instances of those sub-classes had difficulty substituting for the superclass. Interrogating the design against the LSP reveals that. > Problem solved. Thank you for all your help! > Cooperative classes are fantastic! :-) I'm glad you discovered them :-) -- \ ?Truth is stranger than fiction, but it is because fiction is | `\ obliged to stick to possibilities, truth isn't.? ?Mark Twain, | _o__) _Following the Equator_ | Ben Finney From nobody at nowhere.invalid Fri Jun 3 16:58:55 2016 From: nobody at nowhere.invalid (Nobody) Date: Fri, 03 Jun 2016 21:58:55 +0100 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 03 Jun 2016 09:15:55 -0700, Lawrence D?Oliveiro wrote: >> [quoted text muted] > > A licence is quite different from a contract. A contract requires some > indication of explicit agreement by both parties, a licence does not. More precisely, it requires "mutual consideration", i.e. each party must provide something of value to the other. If a party doesn't provide something of value, they can't claim any harm in the event of a breach, as they haven't lost anything (failure to receive what the other party promised doesn't count, as it didn't belong to the recipient to start with). This is why you sometimes see contracts where one party pays a nominal sum (e.g. one pound/dollar/euro) in return for assets which may have significant value but also significant liabilities attached. The fact that they paid /something/ allows them to enforce the contract. OTOH, a Free software licence is unilateral; the author grants the user certain rights, with the user providing nothing in return. From ian.g.kelly at gmail.com Fri Jun 3 17:53:58 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Jun 2016 15:53:58 -0600 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <85fusu58pw.fsf@benfinney.id.au> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <85k2i65upp.fsf@benfinney.id.au> <85fusu58pw.fsf@benfinney.id.au> Message-ID: On Fri, Jun 3, 2016 at 2:16 PM, Ben Finney wrote: > If you're writing a custom initialiser that handles two additional > parameters, then those parameters should not be present when you call > the super() method's initialiser:: > > # You specified Python 3, which allows simpler syntax. > > class LoremIpsum: > def __init__(self, spam, *args, **kwargs): > do_something_important_with(spam) > super().__init__(*args, **kwargs) > > class DolorSitAmet(LoremIpsum): > def __init__(self, spam, eggs=4, beans=None, *args, **kwargs): > self.eggs = eggs > self.beans = beans > super().__init__(spam, *args, **kwargs) Except that since we're discussing design for multiple inheritance, the positional argument "spam" is inappropriate. All arguments should be passed by keyword; the DolorSitAmet.__init__ method cannot be certain that LoremIpsum will be the next class in the MRO, and the actual next class might not expect spam to be the first positional argument. From flebber.crue at gmail.com Fri Jun 3 19:06:55 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 3 Jun 2016 16:06:55 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: <66e791bf-9ea2-499a-8490-db67a0d3ba61@googlegroups.com> On Saturday, 4 June 2016 02:04:43 UTC+10, Michael Selik wrote: > > > That totally makes sense I was just double checking, had hoped I could > > create a variable assign it to a list and append in one stroke. > > > > In fact you can! It's called a "list comprehension" > > pyqFiles = [pq(my_dir + filename) for filename in sorted(file_list)] Actually thats where I was coming from I can create a list with a list comprehension in one go, but I cant create a list with an append method pf.append(thing) in one go . Sayth From flebber.crue at gmail.com Fri Jun 3 19:09:41 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 3 Jun 2016 16:09:41 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: Message-ID: <10961e83-b9cd-4e7a-b16e-1d29377958d3@googlegroups.com> > > pyqFiles = [] > > for filename in sorted(file_list): > > pyqFiles = pyqFiles.append(pq(filename=my_dir + filename)) > > > > return pyqFiles > > [snip] > > PS I am really having a lot of fun coding. > > To have even more fun, note that the above can be replaced by [untested]: > > return [pq(filename=my_dir + filename) > for filename in sorted(file_list)] > > (By the way, the "pf = pf.append(thing)" construction is weird. > All you need is pf.append(thing).) > > -- > I got the pf = pf.append(thing) from doing pandas because in pandas its not an inplace function. Sayth From flebber.crue at gmail.com Fri Jun 3 19:11:04 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Fri, 3 Jun 2016 16:11:04 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <46f79572-b9ae-4898-13b4-97c2c5589e45@shopzeus.com> Message-ID: <31e5eacf-6083-4791-b92d-1084287dc035@googlegroups.com> > > def getsMeet(files=file_list): > > """Get a File or List of Files. > > > > From the list of files determine > > what meetings exist and prepare them > > to be parsed > > """ > > pyqFiles = [] > > for filename in sorted(file_list): > > pyqFiles = pyqFiles.append(pq(filename=my_dir + filename)) > > > > return pyqFiles > This may not be the answer you are seeking, but how about: > > def getsMeet(files=file_list): > return [pq(filename=my_dir + filename) for filename in sorted(file_list)] > > If you can use any iterable instead of a list, then you can also > consider using a generator: > > def getsMeet(files=file_list): > for filename in sorted(file_list): > yield pq(filename=my_dir + filename) > > for pg_obj in getsMeet(my_file_list): > process(pg_obj) > > This way you do not need to construct a list at all, and it won't create all pq objects in advance. Ok now that is cool and definitely I need to play with that a little more. Sayth From 114piyush at gmail.com Fri Jun 3 19:14:30 2016 From: 114piyush at gmail.com (Piyush Verma) Date: Sat, 4 Jun 2016 04:44:30 +0530 Subject: Catch exception with message? Message-ID: Generally we catch exception using except Exception as e: But sometimes, we see same type of exception is present with different message.Is there a way to capture same exception with message filtering? Please help me to do this. Regards, ~Piyush From ian.g.kelly at gmail.com Fri Jun 3 20:25:18 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Jun 2016 18:25:18 -0600 Subject: Catch exception with message? In-Reply-To: References: Message-ID: try: something except Exception as e: if e.args[0] == message_of_interest: handle_it else: raise On Fri, Jun 3, 2016 at 5:14 PM, Piyush Verma <114piyush at gmail.com> wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type of exception is present with different > message.Is there a way to capture same exception with message > filtering? Please help me to do this. > > Regards, > ~Piyush > -- > https://mail.python.org/mailman/listinfo/python-list From cs at zip.com.au Fri Jun 3 20:31:23 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sat, 4 Jun 2016 10:31:23 +1000 Subject: Catch exception with message? In-Reply-To: References: Message-ID: <20160604003123.GA62560@cskk.homeip.net> On 04Jun2016 04:44, Piyush Verma <114piyush at gmail.com> wrote: >Generally we catch exception using >except Exception as e: > >But sometimes, we see same type of exception is present with different >message.Is there a way to capture same exception with message >filtering? Please help me to do this. Quick note: you almost never was to catch "Exception", you almost always want to catch a particular Exception subtype such as ValueError. Regarding your questuon: sure. Just examine the message. For example: try: ... except SomeException as e: if e.message == 'some specific string': ... handle that ... elif e.message.startswith('some prefix'): ... handle that ... elif ... ... else: # exception _not_ handled, reraise it for someone further out # to handle correctly raise Cheers, Cameron Simpson From random832 at fastmail.com Fri Jun 3 20:42:19 2016 From: random832 at fastmail.com (Random832) Date: Fri, 03 Jun 2016 20:42:19 -0400 Subject: Catch exception with message? In-Reply-To: References: Message-ID: <1465000939.1726478.627518305.3BB72ED4@webmail.messagingengine.com> On Fri, Jun 3, 2016, at 19:14, Piyush Verma wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type of exception is present with different > message.Is there a way to capture same exception with message > filtering? Please help me to do this. The message is meant to be human-readable, and may change without warning. Is there no other property on the exceptions you want to catch that can be used to distinguish them? (errno, perhaps?) What's your specific use case? From ben+python at benfinney.id.au Fri Jun 3 20:44:09 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 04 Jun 2016 10:44:09 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <85k2i65upp.fsf@benfinney.id.au> <85fusu58pw.fsf@benfinney.id.au> Message-ID: <85wpm54wbq.fsf@benfinney.id.au> Ian Kelly writes: > Except that since we're discussing design for multiple inheritance, > the positional argument "spam" is inappropriate. All arguments should > be passed by keyword; the DolorSitAmet.__init__ method cannot be > certain that LoremIpsum will be the next class in the MRO, and the > actual next class might not expect spam to be the first positional > argument. You're right. That also allows us to stop handling unknown positional arguments. This does make it troublesome to design the function signature though, and I can see why people balk at how to deal with the semantics of ?super? in Python 2:: class LoremIpsum(object): def __init__(self, **kwargs): spam = kwargs.pop('spam') do_something_important_with(spam) super(LoremIpsum, self).__init__(**kwargs) class DolorSitAmet(LoremIpsum): def __init__(self, **kwargs): self.eggs = kwargs.pop('eggs') self.beans = kwargs.pop('beans') super(DolorSitAmet, self).__init__(**kwargs) That's awful :-( because the initialiser's signature no longer shows any sign of which parameters matter for this class. It also sucks to need ?dict.pop('name')?, instead of just ?name?. Keyword-only parameters make this easier and clearer:: class LoremIpsum: def __init__(self, *, spam, **kwargs): spam = kwargs.pop('spam') do_something_important_with(spam) super().__init__(**kwargs) class DolorSitAmet(LoremIpsum): def __init__(self, *, eggs=4, beans=None, **kwargs): self.eggs = eggs self.beans = beans super().__init__(**kwargs) I guess that's yet another reason to advocate Python 3 for all new code. -- \ ?One time a cop pulled me over for running a stop sign. He | `\ said, ?Didn't you see the stop sign?? I said, ?Yeah, but I | _o__) don't believe everything I read.?? ?Steven Wright | Ben Finney From ben+python at benfinney.id.au Fri Jun 3 20:48:33 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 04 Jun 2016 10:48:33 +1000 Subject: Catch exception with message? References: Message-ID: <85shwt4w4e.fsf@benfinney.id.au> Piyush Verma <114piyush at gmail.com> writes: > But sometimes, we see same type of exception is present with different > message.Is there a way to capture same exception with message > filtering? Please help me to do this. That's a nasty code smell. Why would you want your code to behave differently depending on what the text of the message is? The message should not change the semantic meaning of the exception type. If there are exceptions that *mean* different things (i.e. that require different handling), they should be different types. See the Python 3 standard exception hierarchy for a good example. -- \ ?The greatest tragedy in mankind's entire history may be the | `\ hijacking of morality by religion.? ?Arthur C. Clarke, 1991 | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Fri Jun 3 21:06:21 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 04 Jun 2016 13:06:21 +1200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: Nagy L?szl? Zsolt wrote: > I do not use diamond shapes in my hierarchy, I guess that does not > affect me. I may be wrong. If there are no diamonds, there is no need to use super. Explicit inherited method calls, done correctly, will work fine. The only downside is that if your inheritance hierarchy changes, you need to review all your inherited calls to make sure they're still correct. The use of super to address that issue seems attractive. However, super is only applicable if some rather stringent requirements are met: 1. All the methods must have compatible signatures. 2. Except for 3 below, all classes participating in the hierarchy must use super for a given method if any of them do, including any future subclasses. 3. There must be a class at the top of the hierarchy that does *not* make super calls, to terminate the chain. 4. It must not matter what order the methods in a super chain are called. This is because you cannot predict which method a given super call will invoke. It could belong to a subclass of the class making the call. If you can't satisfy *all* of these reqirements, then you can't use super. Sorry, but that's just the way super is. -- Greg From lawrencedo99 at gmail.com Fri Jun 3 21:10:30 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 3 Jun 2016 18:10:30 -0700 (PDT) Subject: Don't put your software in the public domain In-Reply-To: References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5db5bb61-96a3-439b-b78c-853c9ed878de@googlegroups.com> On Saturday, June 4, 2016 at 8:58:19 AM UTC+12, Nobody wrote: > On Fri, 03 Jun 2016 09:15:55 -0700, Lawrence D?Oliveiro wrote: > > >> [quoted text muted] > > > > A licence is quite different from a contract. A contract requires some > > indication of explicit agreement by both parties, a licence does not. > > More precisely, it requires "mutual consideration", i.e. each party must > provide something of value to the other. If a party doesn't provide > something of value, they can't claim any harm in the event of a breach, as > they haven't lost anything (failure to receive what the other party > promised doesn't count, as it didn't belong to the recipient to start with). Thanks for clarifying that. > This is why you sometimes see contracts where one party pays a nominal sum > (e.g. one pound/dollar/euro) in return for assets which may have > significant value but also significant liabilities attached. The fact that > they paid /something/ allows them to enforce the contract. I wonder about the point of that, though; I have heard of cases where the judge ruled that the contract had been breached, and awarded damages of one pound/dollar/euro. So other than winning a symbolic victory, what was the point? From greg.ewing at canterbury.ac.nz Fri Jun 3 21:10:50 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 04 Jun 2016 13:10:50 +1200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <85k2i65upp.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > With classes all inheriting ultimately from ?object? (as all Python 3 > classes do, and as all current Python 2 classes should), mutliple > inheritance inevitably places your classes in a diamond inheritance > pattern. That's usually harmless, though, because object provides very little functionality of its own. -- Greg From steve at pearwood.info Fri Jun 3 22:02:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 12:02:13 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <575236a6$0$22142$c3e8da3$5496439d@news.astraweb.com> On Fri, 3 Jun 2016 11:14 pm, Michael Torrie wrote: > I'm not sure this is completely right. The GPL explicitly says one doesn't > have to agree to the GPL to use the software. The GPL only comes into > affect when distribution is involved. Yes, you're right, I was unclear. See https://opensource.org/licenses/GPL-2.0 in particular clause 5. The GNU Library General Public License will be similar. I was thinking about the difference between a user of the software (as in programmers and developers) versus *end-users* of the software who merely use the finished product, but neglected to make that explicit. Sorry about that. Mere use of the code as an end-user does not require that you make the source code available: the GPL states "The act of running the Program is not restricted", which is blanket permission (a licence?) to run the GPLed code. (I am surprised that it takes so little to grant end-user usage rights, but IANAL and presumably the FSF's lawyers consider that sufficient. Perhaps there are common law usage rights involved.) I intended to refer to users of the GPL software as developers, that is, those who incorporate The Program (the GPLed code) in their own code. For those people, you need a licence to copy, distribute and modify the GPLed code. And *that* comes with restrictions: if you distribute the copied or modified code, then you must abide by the terms of the GPL, which is to give *your* users the same licence as the GPL offers. If you don't, then you have no right to copy, distribute or modify the code, and are in breach of copyright. > So challenging the legitimacy of the > GPL in court (which certainly has happened in Germany) wouldn't prevent > one from using the GPL software. Only from distributing it. Are you referring to Welte vs Sitecom? I wasn't aware of that until now. If so, this case found that the GPL was valid, and enforced the terms of the GPL against Sitecom. There have been many times that the Software Freedom Law Center (SFLC) has had to force companies to comply with the GPL. There has been at least one time that they actually had to take legal action to force compliance (against Monsoon Multimedia, Inc, on behalf of Busybox). Normally infringers back down when caught, but Monsoon dug their heels in and refused to budge. So the SFLC took them to court. Not surprisingly, Monsoon settled out of court rather than risk a bigger penalty from a judge. As the SFLC Legal Director Daniel B. Ravicher said: In all of our years of doing open source license enforcement work, we?ve never come across any party that thought it was in their best interest to test the GPL in court, and Monsoon was no exception. http://torquemag.io/2013/03/busybox/ They preferred to pay a financial settlement (in other words, a fine) and come into compliance, rather than risk having a judge tell them they were infringing copyright. -- Steven From tjreedy at udel.edu Fri Jun 3 22:12:37 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 3 Jun 2016 22:12:37 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: Message-ID: On 6/3/2016 10:20 AM, Sayth Renshaw wrote: > Very briefly because I hope to shot down eloquently. > > Python is beautiful and is supposed to be a duck typed language, Yes? > > Then if I create and assign to a new variable with a list action why does the duck not quack? > > It feels wrong to spend a line writing what is already obvious > > def getsMeet(files=file_list): > """Get a File or List of Files. > > From the list of files determine > what meetings exist and prepare them > to be parsed > """ > pyqFiles = [] > for filename in sorted(file_list): The parameter name if files, not file_list. The latter is just the default. > pyqFiles = pyqFiles.append(pq(filename=my_dir + filename)) > > return pyqFiles You can replace the body with return [pq(filename=my_dir+filename) for filename in sorted(files)] where files is any iterable of file names. -- Terry Jan Reedy From steve at pearwood.info Fri Jun 3 22:12:40 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 12:12:40 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57523919$0$1599$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 02:15 am, Lawrence D?Oliveiro wrote: > On Friday, June 3, 2016 at 9:53:47 PM UTC+12, Steven D'Aprano wrote: > >> A licence is something like a contract... > > A licence is quite different from a contract. A contract requires some > indication of explicit agreement by both parties, a licence does not. That's a very good point. In the USA: A license is a unilateral abrogation of rights. The licensor has, by law, the ability to enforce certain rights against the licensee, and the license functions as a promise not to enforce those rights. [...] if the conditions are violated, which essentially makes it a contract. As further discussed below, a contract requires mutual agreement and bilateral consideration. It is likely that a court, in the U.S. or abroad, would recognize the GPL as a contract. And further: There must be an offer, acceptance of that offer, and something of value exchanged. "Taking the case: Is the GPL enforceable?", Jason B Wacha, Santa Clara High Technology Law Journal, Vol. 21 Issue 2. http://digitalcommons.law.scu.edu/cgi/viewcontent.cgi?article=1380&context=chtlj In the case of the GPL, the offer is the right to copy, distribute and modify the software, acceptance is the act of copying, distributing or modifying the software. The exchange does not have to be monetary. In exchange for the right to copy, distribute and modify the software, the licensee agrees to keep copyright notices intact, insert certain required notices, and redistribute the code only under the conditions of the license. This is sufficient consideration, at least under US contract law. In Europe and particularly Germany, things are different, as the German courts don't recognise licences as a thing[1]. The GPL would have to be treated as a contract, or not be legally meaningful. But that doesn't hurt the GPL: if it is found to be invalid, then the infringing licensee finds themselves with only their limited rights under copyright law, which most certainly does not include the right to make unlimited copies and distribute them. As Wacha writes in the same paper: But what if, for some reason, a court held the GPL to be an unenforceable license? [...] the licensee (who received the code) reverts back to her common law rights. That means that she has the rights to use the program (i.e., to copy into memory as necessary to run it) and to make a backup copy. What disappears are the restrictions and other limitations in the GPL. But these will be the only rights a licensee has-she would have no right to distribute, and no right to modify. So for a user, challenging the validity of the GPL is a dangerous game. > That?s why Free Software licences only have to say something like ?by > using this software, you agree to the following terms...?, because if the > user doesn?t accept the licence, then they have no licence. Right. > EULAs for proprietary software, on the other hand, try to have it both > ways, by having a clause like the above, as well as requiring you to click > an ?I Agree? button or some such. I have no comment on whether or not that makes EULA a contract, or whether it is relevant to the discussion. Wacha has some things to say about "clickwrap licences", see the URL above. -- Steven From steve at pearwood.info Fri Jun 3 22:20:47 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 12:20:47 +1000 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> <1c46f375-ad3a-4a82-ad11-f72fd604a53a@googlegroups.com> Message-ID: <57523b00$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 02:22 am, Lawrence D?Oliveiro wrote: > In Python you write a loop with one exit in one way, a loop with two exits > in a different way, and a loop with more than two exits in yet another > entirely different way. Can you say ?cognitive burden?? Yes I can, but I don't see the point. In Python, you write a loop with one exit one way: for x in seq: do_something() and a loop with two or more exits a *trivially different* way: for x in seq: do_something() if condition: break if another_condition: break You can put as many or as few break statements in the loop as you like, whether it is zero or one or ten or a thousand, the for-loop is written the same way, with a slight difference only when going from the "no early exit" case to "at least one early exit" case. How is this a cognitive burden? Programming is about composing code from smaller components in this way. Here is how you add two numbers: result = a + b and three numbers: result = a + b + c and four numbers: result = a + b + c + d This isn't three or more different ways to add numbers, depending on how many numbers you have to add. It is ONE way to add, composed as many times as you need it. For-loops are no different: you can exit the loop by reaching the end and exiting, or you can exit early by using break. The number of breaks is just composition. -- Steven From steve at pearwood.info Fri Jun 3 22:28:33 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 12:28:33 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57523cd3$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 06:58 am, Nobody wrote: > OTOH, a Free software licence is unilateral; the author grants the user > certain rights, with the user providing nothing in return. That's not the case with the GPL. The GPL requires the user (not the end-user, who merely avails themselves of their common law right to run the software, but the developer user, who copies, distributes and modifies the code) to do certain things in return for the right to copy, distribute and modify the code: - you must forgo your right to keep your derived work a trade secret; - you must keep copyright licences intact; - you must attach certain notices (the GPL itself); - you must make the source code to your derived work available to your users, in certain ways (e.g. distributed together with the application) but not others (locked in a filing cabinet at the bottom of a disused mineshaft in Patagonia). The courts in Germany have already found that the GPL satisfies the conditions to be considered a contract; it is likely that so would US courts. -- Steven From steve at pearwood.info Fri Jun 3 22:31:47 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 12:31:47 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <66e791bf-9ea2-499a-8490-db67a0d3ba61@googlegroups.com> Message-ID: <57523d93$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 09:06 am, Sayth Renshaw wrote: > I cant create a list with an append method pf.append(thing) in one go . Correct. You cannot append to a list until the list exists. Nor can you uppercase a string until the string exists: s = "hello world" s = s.uppercase() Nor can you add one to a number until the number exists. x = 0 x += 1 Why should lists be different? How is Python supposed to know pf is a list with an append method if pf doesn't exist? # pf = [] pf.append(thing) -- Steven From steve at pearwood.info Fri Jun 3 22:38:22 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 12:38:22 +1000 Subject: Catch exception with message? References: Message-ID: <57523f1f$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 09:14 am, Piyush Verma wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type of exception is present with different > message. That suggests that whoever wrote the code doesn't know what they're doing. Intentionally giving the same error message for different exception types is poor design. > Is there a way to capture same exception with message > filtering? Please help me to do this. Error messages are not part of the public API of Python's built-ins and standard library. That means that error messages are subject to change at any time, without warning. There is no backwards compatibility requirement for the error message to stay the same. In principle that means that the same function might use a different error message each time you run it. But in practice, it means that even bug-fix releases of Python can change error messages. So don't do this, it is a terrible idea. You should never rely on the error message of an exception. But if you insist: try: something() except Exception as e: if e.args[0] = "An error occurred": print("could you be any less specific?") -- Steven From christopher_reimer at icloud.com Fri Jun 3 22:50:47 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 03 Jun 2016 19:50:47 -0700 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <57523d93$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <66e791bf-9ea2-499a-8490-db67a0d3ba61@googlegroups.com> <57523d93$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <448b41e0-9719-e31f-e5b8-9bd81ef87e63@icloud.com> On 6/3/2016 7:31 PM, Steven D'Aprano wrote: > On Sat, 4 Jun 2016 09:06 am, Sayth Renshaw wrote: > >> I cant create a list with an append method pf.append(thing) in one go . > Correct. You cannot append to a list until the list exists. > > Nor can you uppercase a string until the string exists: > > s = "hello world" > s = s.uppercase() >>> s = "hello world".upper() >>> print(s) HELLO WORLD This works in Python 3. Not sure if s.uppercase() was meant as an example for a different language. Chris R. From steve at pearwood.info Fri Jun 3 22:51:42 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 12:51:42 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5752423f$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 11:06 am, Gregory Ewing wrote: > Nagy L?szl? Zsolt wrote: >> I do not use diamond shapes in my hierarchy, I guess that does not >> affect me. I may be wrong. > > If there are no diamonds, In Python 3, or Python 2 with new-style classes, there are ALWAYS diamonds when you use multiple inheritance. > there is no need to use super. Except then you are precluding others from integrating your classes into their class hierarchies. > Explicit inherited method calls, done correctly, will > work fine. > > The only downside is that if your inheritance hierarchy > changes, you need to review all your inherited calls > to make sure they're still correct. > > The use of super to address that issue seems attractive. > However, super is only applicable if some rather stringent > requirements are met: > > 1. All the methods must have compatible signatures. > > 2. Except for 3 below, all classes participating in the > hierarchy must use super for a given method if any of > them do, including any future subclasses. > > 3. There must be a class at the top of the hierarchy > that does *not* make super calls, to terminate the chain. Normally that will be object. Sometimes you need to prevent messages reaching object. But to my mind, that's a code-smell, and indicates you're doing something wrong. "Something wrong" may be multiple inheritance itself. There is a reason why most languages don't allow MI at all, or only allow a much restricted subset of it, in the form of mixins or traits. And in fact, even using inheritance alone is harder than it seems. Composition is just as powerful and usually easier to work with. [...] > If you can't satisfy *all* of these reqirements, then > you can't use super. Sorry, but that's just the way > super is. If you can't use super, then chances are you can't use *anything*, including manual calls to superclass methods. There's nothing magical about the use of super itself. If you have problems with super, then you have two choices: (1) Manually walk the MRO making the same calls that super would have made, in which case you'll have the same problems super did. (2) DON'T walk the MRO making the same calls that super would have made, in which case you will have all the problems that super solves. Namely, you will either miss calling superclass methods, or you will call them two many times. In a straight linear single inheritance class hierarchy, walking the MRO is trivial whether you use super or not, but not using super restricts you to never using super. But in MI, not using super almost certainly means you're doing it wrong. (If you're lucky, you can get away with it if the methods you fail to call aren't needed, or do nothing, and the methods you call twice are harmless.) -- Steven From steve at pearwood.info Fri Jun 3 23:00:22 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 13:00:22 +1000 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> Message-ID: <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 02:24 am, Lawrence D?Oliveiro wrote: > On Saturday, June 4, 2016 at 3:52:42 AM UTC+12, Rob Gaddi wrote: >> Lawrence D?Oliveiro wrote: >> >>> The reason why I don?t like this is that there are two ways out of the >>> Python for-statement, and they are written quite differently. Why the >>> asymmetry? Logically, all ways out of a loop are of equal significance. >> >> I wouldn't say that at all. One is early termination due to success. >> The other is that you've run out of things to try, and exit due to >> exhaustion of the iterator. They're two very different cases... > > Different in what way? A loop exit is a loop exit. It causes termination > of the loop. You can exit a loop because you have run out of items to process, or you can exit the loop because a certain condition has been met. The canonical example is a search, where you need to process differently depending on whether a match was found or not. In pseudo-code: for item in items: if condition(item): # found match, exit loop break if match was found: process match else: no match -- Steven From lawrencedo99 at gmail.com Fri Jun 3 23:41:40 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 3 Jun 2016 20:41:40 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <57523b00$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> <1c46f375-ad3a-4a82-ad11-f72fd604a53a@googlegroups.com> <57523b00$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, June 4, 2016 at 2:22:18 PM UTC+12, Steven D'Aprano wrote: > and a loop with two or more exits a *trivially different* way: > > for x in seq: > do_something() > if condition: > break > if another_condition: > break But that loop has 3 exits, written in two different ways. Why the special case? From lawrencedo99 at gmail.com Fri Jun 3 23:43:20 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 3 Jun 2016 20:43:20 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> On Saturday, June 4, 2016 at 3:00:36 PM UTC+12, Steven D'Aprano wrote: > You can exit a loop because you have run out of items to process, or you can > exit the loop because a certain condition has been met. But why should they be expressed differently? item_iter = iter(items) while True : item = next(item_iter, None) if item == None : break if is_what_i_want(item) : break #end while From ian.g.kelly at gmail.com Sat Jun 4 01:05:35 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Jun 2016 23:05:35 -0600 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jun 3, 2016 7:12 PM, "Gregory Ewing" wrote: > > 4. It must not matter what order the methods in a super > chain are called. This is because you cannot predict > which method a given super call will invoke. It could > belong to a subclass of the class making the call. It can't belong to a subclass; the MRI guarantees that. But it's not necessarily a superclass either. From 114piyush at gmail.com Sat Jun 4 02:39:19 2016 From: 114piyush at gmail.com (Piyush Verma) Date: Sat, 4 Jun 2016 12:09:19 +0530 Subject: Catch exception with message? In-Reply-To: <1465000939.1726478.627518305.3BB72ED4@webmail.messagingengine.com> References: <1465000939.1726478.627518305.3BB72ED4@webmail.messagingengine.com> Message-ID: Below is exception type and it is user defined exception. I do not see error number in exception stack. What other option we can use as filter in below exception apart from message? UserDefinedException: User defined message: {} #012 File "/opt/cio/lib/python2.7/site-packages/manager.py", line 1100, in create_from_abc #012 yield self.create(x, name, description) #012 File "/opt/cio/lib/python2.7/site-packages/manager.py", line 1132, in create #012 'errors.create.type_not_supported.{0}'.format(abc['type']), On Sat, Jun 4, 2016 at 6:12 AM, Random832 wrote: > On Fri, Jun 3, 2016, at 19:14, Piyush Verma wrote: >> Generally we catch exception using >> except Exception as e: >> >> But sometimes, we see same type of exception is present with different >> message.Is there a way to capture same exception with message >> filtering? Please help me to do this. > > The message is meant to be human-readable, and may change without > warning. Is there no other property on the exceptions you want to catch > that can be used to distinguish them? (errno, perhaps?) What's your > specific use case? > -- > https://mail.python.org/mailman/listinfo/python-list From paul.nospam at rudin.co.uk Sat Jun 4 03:20:24 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 04 Jun 2016 08:20:24 +0100 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87inxp4dzb.fsf@rudin.co.uk> Lawrence D?Oliveiro writes: > On Friday, June 3, 2016 at 9:53:47 PM UTC+12, Steven D'Aprano wrote: > >> A licence is something like a contract... > > A licence is quite different from a contract. A contract requires some > indication of explicit agreement by both parties, a licence does not. That?s > why Free Software licences only have to say something like ?by using this > software, you agree to the following terms...?, because if the user doesn?t > accept the licence, then they have no licence. But that's exactly what a contract is - an agreement. The licence is an example, on the one side the copyright holder is agreeing not to sue the user for copyright infringment and on the other the user is agreeing to only use the code according to the terms. > > EULAs for proprietary software, on the other hand, try to have it both > ways, by having a clause like the above, as well as requiring you to > click an ?I Agree? button or some such. You can agree a contract by conduct... From paul.nospam at rudin.co.uk Sat Jun 4 03:24:19 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 04 Jun 2016 08:24:19 +0100 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87eg8d4dss.fsf@rudin.co.uk> Nobody writes: > On Fri, 03 Jun 2016 09:15:55 -0700, Lawrence D?Oliveiro wrote: > >>> [quoted text muted] >> >> A licence is quite different from a contract. A contract requires some >> indication of explicit agreement by both parties, a licence does not. > > More precisely, it requires "mutual consideration", i.e. each party must > provide something of value to the other. Don't confuse consideration with agreement - they're seperate legal concepts. Agreement is certainly necessary in pretty much all jurisdictions. Consideration is required in most common law jurisdiction (England, the US, most of the commonwealth) but not in many continental legal systems. > OTOH, a Free software licence is unilateral; the author grants the user > certain rights, with the user providing nothing in return. Nope - the user promises to abide by the terms of the licence. This is a very common kind of consideration. From paul.nospam at rudin.co.uk Sat Jun 4 04:04:16 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 04 Jun 2016 09:04:16 +0100 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <5db5bb61-96a3-439b-b78c-853c9ed878de@googlegroups.com> Message-ID: <878tyl4by7.fsf@rudin.co.uk> Lawrence D?Oliveiro writes: > I wonder about the point of that, though; I have heard of cases where > the judge ruled that the contract had been breached, and awarded > damages of one pound/dollar/euro. So other than winning a symbolic > victory, what was the point? Damages for breach of contract are supposed to reflect the loss you suffered as a result. A nominal award is basically saying, yes - the other guy has failed to fulfil his contractual promise, but you haven't actually suffered any real loss as a result. From marko at pacujo.net Sat Jun 4 04:24:03 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 04 Jun 2016 11:24:03 +0300 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <87eg8d4dss.fsf@rudin.co.uk> Message-ID: <87a8j19xb0.fsf@elektro.pacujo.net> Paul Rudin : > Don't confuse consideration with agreement - they're seperate legal > concepts. > > Agreement is certainly necessary in pretty much all jurisdictions. > Consideration is required in most common law jurisdiction (England, > the US, most of the commonwealth) but not in many continental legal > systems. Thankfully, I live in a jurisdiction where things are simpler. I've actually successfully represented a relative in a court of law without any legal training. In Finland, it is common for families to have a printed copy of the law on the bookshelf. Families traditionally sort out things like inheritances without the involvement of lawyers. Nowadays, the law is available online, of course. Marko From steve at pearwood.info Sat Jun 4 05:12:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 19:12:16 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <66e791bf-9ea2-499a-8490-db67a0d3ba61@googlegroups.com> <57523d93$0$1587$c3e8da3$5496439d@news.astraweb.com> <448b41e0-9719-e31f-e5b8-9bd81ef87e63@icloud.com> Message-ID: <57529b71$0$1597$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 12:50 pm, Christopher Reimer wrote: >> Nor can you uppercase a string until the string exists: >> >> s = "hello world" >> s = s.uppercase() > > >>> s = "hello world".upper() > >>> print(s) > HELLO WORLD "hello world" creates a string. Then you call .upper() on that string. Perhaps a better example (demonstrating the impossibility) would be: s = .upper() but I thought that would not be clear. > This works in Python 3. Not sure if s.uppercase() was meant as an > example for a different language. Nope, just not the clearest example. -- Steven From steve at pearwood.info Sat Jun 4 05:27:44 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 19:27:44 +1000 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> <1c46f375-ad3a-4a82-ad11-f72fd604a53a@googlegroups.com> <57523b00$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57529f12$0$1612$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 01:41 pm, Lawrence D?Oliveiro wrote: > On Saturday, June 4, 2016 at 2:22:18 PM UTC+12, Steven D'Aprano wrote: >> and a loop with two or more exits a *trivially different* way: >> >> for x in seq: >> do_something() >> if condition: >> break >> if another_condition: >> break > > But that loop has 3 exits, written in two different ways. Why the special > case? Is that a serious question? Are you really questioning the need for for-loops to stop iterating when they reach the end of the sequence or iterator? I'll give you the benefit of the doubt and assume you're not trolling. A for-loop without "the special case" as you put it, would be an infinite loop that loops forever unless you explicitly checked for an undefined value: for x in [1, 2, 3]: print(x, end='') # prints 1 2 3 UNDEFINED UNDEFINED UNDEFINED UNDEFINED ... meaning practically every loop would have to be written as: for x in seq: if x is UNDEFINED: break process(x) But at least now you don't have the cognitive burden of remembering that for-loops are intended to loop over a finite number of items, then stop. Alternatively, we could just have the for-loop raise an exception when it passes the end of the sequence. For extra programming machismo, have it dump core. Thus the programmer would be responsible for (somehow!) determining how many times it is safe to loop. This wouldn't be too onerous for sequences: biggest = len(seq) - 1: if biggest > -1: for i, x in enumerate(seq): process(x) if i == biggest: break but I leave dealing with iterators as an exercise for the masochistic. -- Steven From ned at nedbatchelder.com Sat Jun 4 07:37:01 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 4 Jun 2016 04:37:01 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> Message-ID: <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> On Friday, June 3, 2016 at 11:43:33 PM UTC-4, Lawrence D?Oliveiro wrote: > On Saturday, June 4, 2016 at 3:00:36 PM UTC+12, Steven D'Aprano wrote: > > You can exit a loop because you have run out of items to process, or you can > > exit the loop because a certain condition has been met. > > But why should they be expressed differently? > > item_iter = iter(items) > while True : > item = next(item_iter, None) > if item == None : > break > if is_what_i_want(item) : > break > #end while Do you actually write loops like this? If this appeared in a code review, first we'd have a conversation about what this code was meant to do, and then I would ask, "Why aren't you using a for loop?" I suspect most Python programmers would be similarly confused about why you aren't using one of the central constructs of the language. What's next? "Why have both if and while? A goto will work for both!" --Ned. From cl at isbd.net Sat Jun 4 07:40:37 2016 From: cl at isbd.net (cl at isbd.net) Date: Sat, 4 Jun 2016 12:40:37 +0100 Subject: Is there any way to use the logging module adding nothing to a message Message-ID: I want to use Python to handle the stdout logging that comes from syncthing. When you run syncthing it logs to stdout in a fairly standard format with date, time, ERROR/WARNING/INFO etc. so I don't want to add these. I just want to be able to write the log to a file with appropriate rotation etc. If I do:- f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 'a', 1000000, 4) f.setLevel(logging.DEBUG) formatter = logging.Formatter('%(message)s') f.setFormatter(formatter) log.addHandler(f) Will I get just the message with no extras added by the logging module? -- Chris Green ? From greg.ewing at canterbury.ac.nz Sat Jun 4 07:50:24 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 04 Jun 2016 23:50:24 +1200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <5752423f$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <5752423f$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 4 Jun 2016 11:06 am, Gregory Ewing wrote: > >>there is no need to use super. > > Except then you are precluding others from integrating your classes into > their class hierarchies. And if you *do* use super, you're precluding integrating them into other hierarchies that *don't* use super. You can't win. -- Greg From greg.ewing at canterbury.ac.nz Sat Jun 4 07:52:59 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 04 Jun 2016 23:52:59 +1200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > > It can't belong to a subclass; the MRI guarantees that. But it's not > necessarily a superclass either. Er, yes, what I really meant to say was that it could be a class that got introduced into the MRO as a result of someone else subclassing your class. So when you make a super call, you really have *no idea* what it's going to call. -- Greg From ben+python at benfinney.id.au Sat Jun 4 07:55:47 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 04 Jun 2016 21:55:47 +1000 Subject: Is there any way to use the logging module adding nothing to a message References: Message-ID: <85inxp418c.fsf@benfinney.id.au> cl at isbd.net writes: > If I do:- > > f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 'a', 1000000, 4) > f.setLevel(logging.DEBUG) > formatter = logging.Formatter('%(message)s') > f.setFormatter(formatter) > log.addHandler(f) > > Will I get just the message with no extras added by the logging module? Yuo have the code, and presumably the system on which to test it. What's the answer? -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From cl at isbd.net Sat Jun 4 08:14:33 2016 From: cl at isbd.net (cl at isbd.net) Date: Sat, 4 Jun 2016 13:14:33 +0100 Subject: Is there any way to use the logging module adding nothing to a message References: <85inxp418c.fsf@benfinney.id.au> Message-ID: <9ata2d-cb.ln1@esprimo.zbmc.eu> Ben Finney wrote: > cl at isbd.net writes: > > > If I do:- > > > > f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 'a', 1000000, 4) > > f.setLevel(logging.DEBUG) > > formatter = logging.Formatter('%(message)s') > > f.setFormatter(formatter) > > log.addHandler(f) > > > > Will I get just the message with no extras added by the logging module? > > Yuo have the code, and presumably the system on which to test it. What's > the answer? > Very true, I thought the code was going to be much longer than that. :-) ... and the answer is, yes, with the above I just get the message text which is what I want. -- Chris Green ? From bc at freeuk.com Sat Jun 4 08:55:50 2016 From: bc at freeuk.com (BartC) Date: Sat, 4 Jun 2016 13:55:50 +0100 Subject: for / while else doesn't make sense In-Reply-To: <1c46f375-ad3a-4a82-ad11-f72fd604a53a@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> <1c46f375-ad3a-4a82-ad11-f72fd604a53a@googlegroups.com> Message-ID: On 03/06/2016 17:22, Lawrence D?Oliveiro wrote: > On Friday, June 3, 2016 at 9:33:32 PM UTC+12, BartC wrote: >> On 03/06/2016 03:47, Lawrence D?Oliveiro wrote: >>> On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote: >>>> Simple iterative for-loops are more of a DIY effort... >>> >>> There is one case that Python handles more nicely than C. >> >> Just one case? Python is miles away from a C 'for'. > > Yes, just one case. In Python you write a loop with one exit in one way, a loop with two exits in a different way, and a loop with more than two exits in yet another entirely different way. Can you say ?cognitive burden?? You mean like this: while True: if a: break while True: if a: break ... if b: break while True: if a: break ... if b: break ... if c: break > The for-statement in C handles most of my looping requirements. (Yeah, you might find that does 'if' and 'goto' does as well! As well as most other control flow statements including multi-level breaks.) -- Bartc From kwa at kuwata-lab.com Sat Jun 4 09:16:29 2016 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sat, 4 Jun 2016 22:16:29 +0900 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: <60d42dc5-f966-1baf-f044-bb7c07f58172@mrabarnett.plus.com> References: <07867e05-0763-5a2e-b3b1-906bcf3fb1f0@mrabarnett.plus.com> <60d42dc5-f966-1baf-f044-bb7c07f58172@mrabarnett.plus.com> Message-ID: On Sat, Jun 4, 2016 at 3:15 AM, MRAB wrote: > On 2016-06-03 06:48, Makoto Kuwata wrote: > > On Fri, Jun 3, 2016 at 9:31 AM, MRAB > python at mrabarnett.plus.com>> wrote: >> >> On 2016-06-02 15:04, Makoto Kuwata wrote: >> >> Hi, >> >> I have a trouble around __import__(). >> The following sample code works well on Python <= 3.3, >> but it raises ImportError on Python >= 3.4. >> >> >> ## importtest.py >> import sys, os, shutil >> >> def test(name): >> try: >> ## create 'foo/__init__.py' file >> os.mkdir(name) >> with open(name + "/__init__.py", 'w') as f: >> f.write("X=1") >> f.flush() >> ## ipmort 'foo' module >> mod = __import__(name) >> finally: >> if os.path.isdir(name): >> shutil.rmtree(name) >> >> test("foo") # no errors >> test("bar") # may raise error on Python >= 3.4. Why? >> >> >> Output Example: >> >> ### No errors (Python <= 3.3) >> ubuntu$ export PYTHONPATH=. >> ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.3 >> importtest.py; done >> >> ### ImportError (Python >= 3.4) >> ubuntu$ export PYTHONPATH=. >> ubuntu$ for x in 1 2 3 ; do /usr/bin/python3.4 >> importtest.py; done >> Traceback (most recent call last): >> File "tmp/importtest.py", line 19, in >> test("bar") # may raise error on Python >= 3.4. Why? >> File "tmp/importtest.py", line 13, in test >> mod = __import__(name) >> ImportError: No module named 'bar' >> >> >> Please give me any advices or hints. >> Thanks. >> >> Things to try: >> >> Does the order matter? If you try "bar" then "foo" does "foo" fail? >> >> >> Yes. Name is not matter. Order is matter. >> >> >> Does the directory matter? >> >> >> No. I created "foo" and "bar" directories in order to create python >> module. >> >> >> Is there something called "bar" in the directory already? >> >> >> No. Sample script removes directories every time. >> >> >> What does the created "bar" directory contain? Does it really >> contain only "__init__.py"? >> >> >> Yes. See sample script for detail. >> >> You're testing the script 3 times; on which iteration does it fail? >> >> >> Because sometimes script will fail and sometimes will work file. >> >> It sounds like it's some kind of race condition, e.g. it hasn't finished > writing the file before it does the import. > Maybe. I want to know why it happens on Python >= 3.4 and not on Python <= 3.3. It happens on both Linux (ubuntu 14.04) and MacOSX (El Captain). -- regards, makoto From steve at pearwood.info Sat Jun 4 09:46:43 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jun 2016 23:46:43 +1000 Subject: Multiple inheritance, super() and changing signature References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5752dbc4$0$1596$c3e8da3$5496439d@news.astraweb.com> On Sat, 4 Jun 2016 09:52 pm, Gregory Ewing wrote: > Ian Kelly wrote: >> >> It can't belong to a subclass; the MRI guarantees that. But it's not >> necessarily a superclass either. > > Er, yes, what I really meant to say was that it could > be a class that got introduced into the MRO as a result > of someone else subclassing your class. > > So when you make a super call, you really have *no idea* > what it's going to call. That's the nature of inheritance in a MI world. If you try to specify a particular superclass manually, you're in the position of the archetypal drunk looking for his lost car keys under a street light "because the light is better here". Sure, you always know which class you're calling, but sometimes its the wrong class! That's the mind-twisting part of MI. Just because your class inherits from K, doesn't mean that you should be calling K's methods. Until you (generic you) come to terms with that, you're going to struggle with MI regardless of what you do. It might help to read Michele Simionato's articles about super, multiple inheritance and related topics. Michele has been working with issues related to MI for many years and has a lot to say about them. Things to know about super: Part 1 http://www.artima.com/weblogs/viewpost.jsp?thread=236275 Part 2 http://www.artima.com/weblogs/viewpost.jsp?thread=236278 Part 3 http://www.artima.com/weblogs/viewpost.jsp?thread=237121 The wonders of super: http://www.artima.com/weblogs/viewpost.jsp?thread=281127 Mixins considered harmful: Part 1 http://www.artima.com/weblogs/viewpost.jsp?thread=246341 Part 2 http://www.artima.com/weblogs/viewpost.jsp?thread=246483 Part 3 http://www.artima.com/weblogs/viewpost.jsp?thread=254367 Part 4 http://www.artima.com/weblogs/viewpost.jsp?thread=254507 Traits as an alternative to MI and mixins: http://www.artima.com/weblogs/viewpost.jsp?thread=246488 Generic functions as an alternative to mixins: http://www.artima.com/weblogs/viewpost.jsp?thread=237764 The Method Resolution Order: https://www.python.org/download/releases/2.3/mro/ Michele wrote: "... the problem is multiple inheritance itself. Inheritance makes your code heavily coupled and difficult to follow (spaghetti inheritance). I have not found a real life problem yet that I could not solve with single inheritance + composition/delegation in a better and more maintainable way than using multiple inheritance." and I think that is the most valuable lesson here. MI itself is, if not an anti-pattern, at least a dangerous one. -- Steven From gandalf at shopzeus.com Sat Jun 4 10:42:39 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sat, 4 Jun 2016 16:42:39 +0200 Subject: Multiple inheritance, super() and changing signature In-Reply-To: <5752dbc4$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <5752dbc4$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: > > Things to know about super: > Part 1 http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > Part 2 http://www.artima.com/weblogs/viewpost.jsp?thread=236278 > Part 3 http://www.artima.com/weblogs/viewpost.jsp?thread=237121 > > The wonders of super: > http://www.artima.com/weblogs/viewpost.jsp?thread=281127 > > Mixins considered harmful: > Part 1 http://www.artima.com/weblogs/viewpost.jsp?thread=246341 > Part 2 http://www.artima.com/weblogs/viewpost.jsp?thread=246483 > Part 3 http://www.artima.com/weblogs/viewpost.jsp?thread=254367 > Part 4 http://www.artima.com/weblogs/viewpost.jsp?thread=254507 > > Traits as an alternative to MI and mixins: > http://www.artima.com/weblogs/viewpost.jsp?thread=246488 > > Generic functions as an alternative to mixins: > http://www.artima.com/weblogs/viewpost.jsp?thread=237764 > > The Method Resolution Order: > https://www.python.org/download/releases/2.3/mro/ > Very good links! This will be a good recreational reading for the next two days. From pkpearson at nowhere.invalid Sat Jun 4 12:44:04 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 4 Jun 2016 16:44:04 GMT Subject: Catch exception with message? References: Message-ID: On Sat, 4 Jun 2016 04:44:30 +0530, Piyush Verma <114piyush at gmail.com> wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type of exception is present with different > message.Is there a way to capture same exception with message > filtering? Please help me to do this. Just to make sure, . . . are you aware that "except Exception" is generally not what you want to do, that you generally want to say "except ValueError" or "except KeyError" or "except UnicdeDecodeError" or something specific like that? Maybe that's where to find the specificity you seek. -- To email me, substitute nowhere->runbox, invalid->com. From tjreedy at udel.edu Sat Jun 4 15:12:07 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 4 Jun 2016 15:12:07 -0400 Subject: Don't put your software in the public domain In-Reply-To: <87a8j19xb0.fsf@elektro.pacujo.net> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <87eg8d4dss.fsf@rudin.co.uk> <87a8j19xb0.fsf@elektro.pacujo.net> Message-ID: On 6/4/2016 4:24 AM, Marko Rauhamaa wrote: > Paul Rudin : > >> Don't confuse consideration with agreement - they're seperate legal >> concepts. >> >> Agreement is certainly necessary in pretty much all jurisdictions. >> Consideration is required in most common law jurisdiction (England, >> the US, most of the commonwealth) but not in many continental legal >> systems. > > Thankfully, I live in a jurisdiction where things are simpler. I've > actually successfully represented a relative in a court of law without > any legal training. > > In Finland, it is common for families to have a printed copy of the law > on the bookshelf. How wonderful that 'the law' can fit in a book. English-speaking common law commentaries once had Blackstone's 4 volume Commentaries (https://en.wikipedia.org/wiki/William_Blackstone#Commentaries_on_the_Laws_of_England), but bookshelve of statute laws seem to have overwhelmed that, at least in the US. > Families traditionally sort out things like > inheritances without the involvement of lawyers. Nowadays, the law is > available online, of course. For free, I presume. I just discovered that the Delaware Code is now online http://delcode.delaware.gov/index.shtml. -- Terry Jan Reedy From vonpupp at gmail.com Sat Jun 4 15:55:30 2016 From: vonpupp at gmail.com (Albert) Date: Sat, 4 Jun 2016 12:55:30 -0700 (PDT) Subject: Anyone know a donation app codebase? Message-ID: Hello, Anyone knows a donation app whose code is available on github or similar made in python (could be django, flask, or any other web framework). Thank you very much. From ben+python at benfinney.id.au Sat Jun 4 17:02:16 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 05 Jun 2016 07:02:16 +1000 Subject: Anyone know a donation app codebase? References: Message-ID: <8560to4qhz.fsf@benfinney.id.au> Albert writes: > Anyone knows a donation app whose code is available on github or > similar made in python (could be django, flask, or any other web > framework). Search for Python libraries on the Python Package Index . What you are (I think) looking for can be called a ?payment? handler . If that's not right you can try different search terms. -- \ ?My, your, his, hers, ours, theirs, its. I'm, you're, he's, | `\ she's, we're, they're, it's.? ?anonymous, alt.sysadmin.recovery | _o__) | Ben Finney From marko at pacujo.net Sat Jun 4 17:26:30 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 05 Jun 2016 00:26:30 +0300 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <87eg8d4dss.fsf@rudin.co.uk> <87a8j19xb0.fsf@elektro.pacujo.net> Message-ID: <87twh88x2x.fsf@elektro.pacujo.net> Terry Reedy : > On 6/4/2016 4:24 AM, Marko Rauhamaa wrote: >> In Finland, it is common for families to have a printed copy of the >> law on the bookshelf. > > How wonderful that 'the law' can fit in a book. Must be abridged, although I'm not sure. >> Families traditionally sort out things like inheritances without the >> involvement of lawyers. Nowadays, the law is available online, of >> course. > > For free, I presume. I just discovered that the Delaware Code is now > online http://delcode.delaware.gov/index.shtml. Yes, for free. California, too, has posted its laws online. However, the traditions are different in that American laws aren't the whole story: you'll also have to know the precedents. Precedents play a role in Finland, as well, but here laws tend to be more specific and precedents don't bind courts so strongly. AFAIK, American precedents are *not* freely available. Precedent databases are available only for a fee to law firms. Thus, only lawyers can hope to know what the de-facto law is. The online statutes don't give you nearly enough information. (I once tried to figure out who was supposed to yield in a tricky merging situation in California. The California Vehicle Code didn't seem to provide any principle that would have given the right answer. While perusing the laws, I did notice that the DMV driving recommendations for a large part don't seem to be based on the Vehicle Code. For example, I couldn't find any mention of interleaving in the Code.) Marko From johnhpote at o2.co.uk Sat Jun 4 19:08:54 2016 From: johnhpote at o2.co.uk (John Pote) Date: Sun, 5 Jun 2016 00:08:54 +0100 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: On 02/06/2016 22:57, Dietmar Schwertberger wrote: > On 02.06.2016 12:35, John Pote wrote: >> I've used wxPython (www.wxpython.org) for a few GUI projects and >> found it ok. It's a wrapper for the wxWidgets C++ library. There's >> even a reasonable free GUI builder, wxGlade, which I use as I prefer >> constructing GUI's that way rather than writing raw wxPython code. >> Never tried any of the paid for GUI builders. >> Disadvantage is the download page only provides builds for Python 2.6 >> or 2.7. >> >> Does anyone know how Project Phoenix is coming on? >> http://wxpython.org/Phoenix/ItsAlive/ shows wxPython working with >> Python 3.2. >> Comments on how stable it is and how easy to install would be helpful. > I have been using Phoenix now for half a year and are very happy with > it. A release is on its way. For most platforms there are snapshot > builds which are easy to install. > > See e.g. > https://groups.google.com/d/msg/wxpython-users/soHFLOrerVs/MSijBTQ6KAAJ > > > The snapshot installation does not include the demo and the .chm help > file (yet?). These and the book I found to be the most helpful > resources (much more usable than online reference documentation as > e.g. with Qt). > > > I think that wxGlade is the most promising Python GUI builder and I'm > confident that it will see improvements to increase usability. I have > tried some others from time to time, including also QtCreator, but > none was really convincing. > > Regards, > > Dietmar > Qt and Qt Creator often come up in searches for Python GUI libraries. I need to decide weather to upgrade to wxPython.Phoenix and Python 3.5 (as soon as I upgrade to win 7!) or switch to Qt which I don't know at all. It would be interesting to hear your experiences of trying Qt and why you've stuck with wxPython in the end. Thanks, John From lawrencedo99 at gmail.com Sat Jun 4 19:39:52 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 4 Jun 2016 16:39:52 -0700 (PDT) Subject: Catch exception with message? In-Reply-To: References: Message-ID: <15db1dce-b144-496a-9ed0-8e3ebf447f9c@googlegroups.com> On Sunday, June 5, 2016 at 4:44:17 AM UTC+12, Peter Pearson wrote: > ... are you aware that "except Exception" is generally not what you want to > do ... Agree. Always make your ?except?-matching as specific as possible. From lawrencedo99 at gmail.com Sat Jun 4 23:17:53 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 4 Jun 2016 20:17:53 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: On Saturday, June 4, 2016 at 3:55:12 AM UTC+12, Matt Wheeler wrote: > It's best to think of them as names, rather than variables, as names in > python don't behave quite how you'll expect variables to if you're coming > from some other languages. I have made heavy use of Python as well as many other languages, and I don?t know what you mean. What ?other languages? are you thinking of? Are variables like little boxes? Yes they are. But they are all the same size, while objects may be large (even very large) or small. That is why variables hold, not objects, but references to objects. (This makes no difference for immutable objects, only mutable ones.) From lawrencedo99 at gmail.com Sat Jun 4 23:20:44 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 4 Jun 2016 20:20:44 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <57529f12$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <54595ce1-1639-4c39-8cbb-e285f1bcd0c4@googlegroups.com> <1c46f375-ad3a-4a82-ad11-f72fd604a53a@googlegroups.com> <57523b00$0$22142$c3e8da3$5496439d@news.astraweb.com> <57529f12$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: <828e33ff-b3d5-449e-97c3-482fe0b46c68@googlegroups.com> On Saturday, June 4, 2016 at 9:27:58 PM UTC+12, Steven D'Aprano wrote: > Are you really questioning the need for for-loops to stop iterating > when they reach the end of the sequence or iterator? I just want to point out how you turn a discussion about the behaviour of loops into one about the behaviour of for-loops specifically. > I'll give you the benefit of the doubt and assume you're not trolling. Please, do not make this personal. That?s a sign of running out of rational things to say. From lawrencedo99 at gmail.com Sat Jun 4 23:29:19 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 4 Jun 2016 20:29:19 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> Message-ID: On Saturday, June 4, 2016 at 11:37:18 PM UTC+12, Ned Batchelder wrote: > On Friday, June 3, 2016 at 11:43:33 PM UTC-4, Lawrence D?Oliveiro wrote: > > On Saturday, June 4, 2016 at 3:00:36 PM UTC+12, Steven D'Aprano wrote: > > > You can exit a loop because you have run out of items to process, or you can > > > exit the loop because a certain condition has been met. > > > > But why should they be expressed differently? > > > > item_iter = iter(items) > > while True : > > item = next(item_iter, None) > > if item == None : > > break > > if is_what_i_want(item) : > > break > > #end while > > Do you actually write loops like this? Is that a non-trolling question? Yes. All the time. > If this appeared in a code review, first we'd have a conversation about > what this code was meant to do ... I would hope not. > ...and then I would ask, "Why aren't you using a for loop?" ... and then I would ask, ?Didn?t you read my previous postings where I pointed out the issues with them?? Here is another example: see the section ?Looping on Field Breaks?. A while-True scales gracefully to complex situations like that. I much prefer universal, adaptable constructs, rather than having to remember different solutions for special cases. > I suspect most Python programmers would be similarly confused about > why you aren't using one of the central constructs of the language. When a language has good and bad parts, it behooves the wise programmer to concentrate on the good parts and try to ignore the bad. Python?s for-loops have their uses?I *did* point this out too, did you not notice??but they are best confined to the situations that they are good at. > What's next? "Why have both if and while? A goto will work for both!" Passive-aggression aside, funny you should mention that. I use a goto-free structured-programming style in my C code, as exemplified here . I find it reduces problems with forgetting to free memory, or freeing it twice. From random832 at fastmail.com Sat Jun 4 23:46:34 2016 From: random832 at fastmail.com (Random832) Date: Sat, 04 Jun 2016 23:46:34 -0400 Subject: Don't put your software in the public domain In-Reply-To: <575236a6$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <575236a6$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465098394.960291.628179457.5889267B@webmail.messagingengine.com> On Fri, Jun 3, 2016, at 22:02, Steven D'Aprano wrote: > (I am surprised that it takes so little to grant end-user usage > rights, but IANAL and presumably the FSF's lawyers consider that > sufficient. Perhaps there are common law usage rights involved.) Technically, there are statutory usage rights; 17 USC 117 (a) (1): (a)Making of Additional Copy or Adaptation by Owner of Copy.?Notwithstanding the provisions of section 106, it is not an infringement for the owner of a copy of a computer program to make or authorize the making of another copy or adaptation of that computer program provided: (1) that such a new copy or adaptation is created as an essential step in the utilization of the computer program in conjunction with a machine and that it is used in no other manner, or (2) that such new copy or adaptation is for archival purposes only and that all archival copies are destroyed in the event that continued possession of the computer program should cease to be rightful. The proprietary software industry's continued ability to make demands in an EULA rests on a rather shaky (though less than it was in the box-full-of-disks days) theory that buying software does not in fact make you the "owner of a copy", something that open-source types don't tend to claim regarding their own software. (IANAL either of course) From rustompmody at gmail.com Sat Jun 4 23:54:17 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 4 Jun 2016 20:54:17 -0700 (PDT) Subject: Coding systems are political (was Exended ASCII and code pages) In-Reply-To: References: <8737p589bo.fsf@elektro.pacujo.net> <57475CB5.7010102@lucidity.plus.com> <87pos8y14e.fsf@elektro.pacujo.net> <5747c071$0$1593$c3e8da3$5496439d@news.astraweb.com> <87fut4xc8w.fsf@elektro.pacujo.net> <5747ed83$0$1620$c3e8da3$5496439d@news.astraweb.com> <8760u0x9qu.fsf@elektro.pacujo.net> <574819d8$0$1598$c3e8da3$5496439d@news.astraweb.com> <1464357085.645851.620574537.560EAC9E@webmail.messagingengine.com> <1464365340.674161.620708793.4CE81D69@webmail.messagingengine.com> <37c8a09e-f18b-44ab-8650-0146924bbb9e@googlegroups.com> <574a8021$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <90693cdd-efdf-45da-ae30-350939902fc7@googlegroups.com> On Monday, May 30, 2016 at 12:16:55 AM UTC+5:30, Terry Reedy wrote: > On 5/29/2016 2:12 AM, Rustom Mody wrote: > > > In short that a ? costs more than a $ is a combination of the factors > > - a natural cause -- there are a million chars to encode (lets assume that the > > million of Unicode is somehow God-given AS A SET) > > - an artificial political one -- out of the million-factorial permutations of > > that million, the one that the Unicode consortium chose is towards satisfying the > > equation: Keep ASCII users undisturbed and happy > > From the Python developer viewpoint, Unicode might as well be a fact of > nature. I also note that in English text, a (phoneme) char conveys > about 6 bits of information, while in Chinese text, a (word) char > conveys perhaps 15 bits of information. So I argue that Python 3.3+'s > FSR is being fair in using 1 byte for the first and most often 2 bytes > for the other. Almost a fact of nature -- thats right Im making no complaint against python Or unicode for that matter. Bismarck's well-known quote: Politics is the art of the possible not so well-known additional clause "... the art of the second best" Unicode's relation to ASCII is analogous to C++ relation to C. Ask a typical C++ programmer about style/paradigm etc and you'll hear something unctuous about how C-style is terrible. Then ask why the question of C arises at all when its so unfit and obsolete ie why build C++ on a C base And you'll get vague, philosophical BS on pragmatism etc In short when it suits exploit C, when it suits abuse it. Unicode is likewise: The whole point of unicode is to go beyond ASCII And yet ASCII is allocated the prime real-estate of the lowest 128 of ASCII -- all the control-char wastage preserved intact From steve at pearwood.info Sun Jun 5 02:35:39 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 05 Jun 2016 16:35:39 +1000 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> Message-ID: <5753c83d$0$1616$c3e8da3$5496439d@news.astraweb.com> On Sun, 5 Jun 2016 01:29 pm, Lawrence D?Oliveiro wrote: > On Saturday, June 4, 2016 at 11:37:18 PM UTC+12, Ned Batchelder wrote: >> On Friday, June 3, 2016 at 11:43:33 PM UTC-4, Lawrence D?Oliveiro wrote: >> > On Saturday, June 4, 2016 at 3:00:36 PM UTC+12, Steven D'Aprano wrote: >> > > You can exit a loop because you have run out of items to process, or >> > > you can exit the loop because a certain condition has been met. >> > >> > But why should they be expressed differently? >> > >> > item_iter = iter(items) >> > while True : >> > item = next(item_iter, None) >> > if item == None : >> > break >> > if is_what_i_want(item) : >> > break >> > #end while >> >> Do you actually write loops like this? > > Is that a non-trolling question? Yes. All the time. Really? Well, you'd fail my code review, because that code is broken. If items contains None, your loop will silently end early. That's a bug. >> If this appeared in a code review, first we'd have a conversation about >> what this code was meant to do ... > > I would hope not. Clearly. Nevertheless, its a conversation that needs to be had. >> ...and then I would ask, "Why aren't you using a for loop?" > > ... and then I would ask, ?Didn?t you read my previous postings where I > pointed out the issues with them?? I don't think that very many people would agree with you or consider them problems at all. They're more like features than problems. Your objections to for-loops feel kind of like "I don't like bread knives because they make it too easy to slice bread". Okay, you don't like for-loops, because they make looping a fixed number of times with an optional early exit too much of a "cognitive burden" for you. You have my sympathy, but nobody else I've come across in nearly two decades of Python programming finds them a cognitive burden. > Here is > another example: see the section ?Looping on Field Breaks?. That section was written by you and is not independent confirmation that others agree with your issues with for-loops. > A while-True scales gracefully to complex situations like that. Graceful like a hippopotamus. I don't know that the situation is complex, your description is pretty clear and to the point: Consider the following scenario: your sales company database has a table of employees, and also a table of sales made by each employee. You want to loop over these sale entries, and produce some per-employee statistics. but the while loop you have certainly is complex. If I understand your intent correctly, then I think this is both more elegant and likely faster than the while loop you use: # Beware of bugs in the following code: # I have only proven it is correct, I haven't tested it. rows = db_iter( db = db, cmd = "select employees.name, sales.amount, sales.date from" " employees left join sales on employees.id = sales.employee_id" " order by employees.name, sales.date" ) default = {'total sales': 0.0, 'number of sales': 0, 'earliest date': None, 'latest date': None} prev_employee_name = None stats = {} for (employee_name, amount, date) in rows: if (employee_name != prev_employee_name and prev_employee_name is not None): # Print the previous employee's stats report(prev_employee_name, stats) # and prepare for the next employee. previous_employee_name = employee_name stats = default.copy() stats['total sales'] += amount stats['number of sales'] += 1 if stats['earliest date'] is None: stats['earliest date'] = date stats['latest date'] = date if prev_employee_name is not None: report(prev_employee_name, stats) No breaks needed at all, which makes it much more understandable: you know instantly from looking at the code that it processes every record exactly once, then exits. But it is a *tiny* bit ugly, due to the need to print the last employee's statistics after the loop is completed. We can fix that in two ways: (1) Give up the requirement to print each employee's stats as they are completed, and print them all at the end; or (2) Put a sentinel at the end of rows. The first may not be suitable for extremely large data sets, but it is especially elegant: rows = db_iter( ... # as above ) default = {'total sales': 0.0, 'number of sales': 0, 'earliest date': None, 'latest date': None} stats = {} for (employee_name, amount, date) in rows: record = stats.setdefault(employee_name, default.copy()) stats['total sales'] += amount stats['number of sales'] += 1 if stats['earliest date'] is None: stats['earliest date'] = date stats['latest date'] = date for employee_name in stats: report(employee_name, stats[employee_name]) As you now have all the statistics available, you can look for under-performing or over-performing sales people, run comparisons between staff, etc. Solution (2) using a sentinel gets rid of the need to print anything outside of the loop by simply ensuring that the very last record is a meaningless sentinel that can be ignored: from itertools import chain rows = db_iter( ... # as above ) default = {'total sales': 0.0, 'number of sales': 0, 'earliest date': None, 'latest date': None} prev_employee_name = None stats = {} for (employee_name, amount, date) in chain(rows, ('', 0, None)): if (employee_name != prev_employee_name and prev_employee_name is not None): # Print the previous employee's stats report(prev_employee_name, stats) # and prepare for the next employee. previous_employee_name = employee_name stats = default.copy() stats['total sales'] += amount stats['number of sales'] += 1 if stats['earliest date'] is None: stats['earliest date'] = date stats['latest date'] = date Again, there are no breaks needed, so you know that every record is processed exactly once, and all but the last (the sentinel) is printed. -- Steven From steve at pearwood.info Sun Jun 5 02:37:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 05 Jun 2016 16:37:13 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> On Sun, 5 Jun 2016 01:17 pm, Lawrence D?Oliveiro wrote: > On Saturday, June 4, 2016 at 3:55:12 AM UTC+12, Matt Wheeler wrote: >> It's best to think of them as names, rather than variables, as names in >> python don't behave quite how you'll expect variables to if you're coming >> from some other languages. > > I have made heavy use of Python as well as many other languages, and I > don?t know what you mean. What ?other languages? are you thinking of? > > Are variables like little boxes? Yes they are. That's *exactly* what variables in Python are not like. > But they are all the same > size, while objects may be large (even very large) or small. That is why > variables hold, not objects, but references to objects. No they don't. You are confusing the implementation with the programming model. Following the assignment: x = 99 if you print(x), do you see something like "reference 0x12345"? No. Do you have to dereference that reference to get the value of x? No. At the Python level, the value of x is 99, not some invisible, untouchable reference to 99. There is no analog to dereferencing in Python, nothing like print(x^). You bind values (that is, objects) directly to names, and names (variables) hold their value, not a reference to their value. The fact that for some implementations that is implemented using references of some sort or another (e.g. pointers in CPython) is an implementation detail which is irrelevant to the language and its execution model. -- Steven From list at qtrac.plus.com Sun Jun 5 02:47:31 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Sat, 4 Jun 2016 23:47:31 -0700 (PDT) Subject: Spread a class over multiple files Message-ID: Sometimes I want to spread a class over multiple files. My primary use case is when I create a "Model" class to reflect an entire SQL database. I want a model instance to provide a single point of access to the database, but the database has many tables each requiring its own methods since they differ in their structure, purpose, validation needs, etc. A secondary use case is when I create "MainWindow" classes in GUI programming and have lots of methods to reflect all the actions (e.g., menu options and toolbar actions, plus interaction with the main widget(s)). To meet these needs I've devised an approach that I think is easy to use and understand and which doesn't use any tricky or hard to maintain code. My question is -- are there nicer/better ways to achieve this? Here's a summary of my approach. A fuller discussion is on my website: https://www.qtrac.eu/pyclassmulti.html # Lib.py # This provides the two functions (both decorators) used to support my approach def add_methods_from(*modules): def decorator(Class): for module in modules: for method in getattr(module, "__methods__"): setattr(Class, method.__name__, method) return Class return decorator def register_method(methods): # A decorator used purely for its side-effect def register_method(method): methods.append(method) return method # Unchanged and not strictly necessary return register_method # Model.py # This provides my model but some methods are in separate files import Lib import _ModelConfig import _ModelOutput @Lib.add_methods_from(_ModelConfig, _ModelOutput) class Model: ... def small_method(self): ... # _ModelConfig # _ModelOutput has the same structure so not shown import Lib __methods__ = [] # self is a Model @Lib.register_method(__methods__) def config(self): ... So, that's the overall pattern of my solution. I know that I could use functools partial, e.g., register_method = functools.partial(Lib.register_method, __methods__) ... @register_method def config(self): ... So, is there a nicer/better way? Could I cleanly avoid the explicit imports (e.g., import _ModelConfig), without resorting to stack frame hacks or similar? From ictezy at gmail.com Sun Jun 5 02:53:34 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sat, 4 Jun 2016 23:53:34 -0700 (PDT) Subject: Operator precedence problem Message-ID: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> >>> 2 ** 3 ** 2 Answer is 512 Why not 64? Order is right-left or left-right? From list at qtrac.plus.com Sun Jun 5 02:55:00 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Sat, 4 Jun 2016 23:55:00 -0700 (PDT) Subject: Spreading a class over multiple files Message-ID: Sometimes I want to spread a class over multiple files. My primary use case is when I create a "Model" class to reflect an entire SQL database. I want a model instance to provide a single point of access to the database, but the database has many tables each requiring its own methods since they differ in their structure, purpose, validation needs, etc. A secondary use case is when I create "MainWindow" classes in GUI programming and have lots of methods to reflect all the actions (e.g., menu options and toolbar actions, plus interaction with the main widget(s)). To meet these needs I've devised an approach that I think is easy to use and understand and which doesn't use any tricky or hard to maintain code. My question is -- are there nicer/better ways to achieve this? Here's a summary of my approach. A fuller discussion is on my website: https://www.qtrac.eu/pyclassmulti.html # Lib.py # This provides the two functions (both decorators) used to support my approach def add_methods_from(*modules): def decorator(Class): for module in modules: for method in getattr(module, "__methods__"): setattr(Class, method.__name__, method) return Class return decorator def register_method(methods): # A decorator used purely for its side-effect def register_method(method): methods.append(method) return method # Unchanged and not strictly necessary return register_method # Model.py # This provides my model but some methods are in separate files import Lib import _ModelConfig import _ModelOutput @Lib.add_methods_from(_ModelConfig, _ModelOutput) class Model: ... def small_method(self): ... # _ModelConfig.py # _ModelOutput has the same structure so not shown import Lib __methods__ = [] # self is a Model register_method = Lib.register_method(__methods__) @register_method def config(self): ... So, that's the overall pattern of my solution. Is there a nicer/better way? Could I cleanly avoid the explicit imports (e.g., import _ModelConfig), without resorting to stack frame hacks or similar? From gherron at digipen.edu Sun Jun 5 03:04:43 2016 From: gherron at digipen.edu (Gary Herron) Date: Sun, 5 Jun 2016 00:04:43 -0700 Subject: Operator precedence problem In-Reply-To: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> Message-ID: <5753CF0B.9040906@digipen.edu> On 06/04/2016 11:53 PM, ICT Ezy wrote: >>>> 2 ** 3 ** 2 > Answer is 512 > Why not 64? > Order is right-left or left-right? Evidently right to left, but you already figured that out. Python 3.5.1+ (default, Mar 30 2016, 22:46:26) [GCC 5.3.1 20160330] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 2 ** 3 ** 2 512 >>> 2 ** (3 ** 2) 512 >>> (2 ** 3) ** 2 64 >>> Here's the relevant documentation page: https://docs.python.org/3/reference/expressions.html Look for "... except for exponentiation, which groups from right to left" Gary Herron -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From gherron at digipen.edu Sun Jun 5 03:18:08 2016 From: gherron at digipen.edu (Gary Herron) Date: Sun, 5 Jun 2016 00:18:08 -0700 Subject: Spreading a class over multiple files In-Reply-To: References: Message-ID: <5753D230.7060902@digipen.edu> On 06/04/2016 11:55 PM, Mark Summerfield wrote: > Sometimes I want to spread a class over multiple files. There?s and easy way to do this in Python using what's called a Mixin class and (multiple) inheritance: (See https://en.wikipedia.org/wiki/Mixin for more information.) In one file, say extras.py class ExtraMethodsMixin: def extra_1(...): ... def extra_2(...): ... In the main class file: from extras import ExtraMethodsMixin class MainClass(ExtraMethodsMixin): def __init__(...): ... # and so on The result will be essentially the same as if all three methods were defined in MainCLass. Gary Herron -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 > > My primary use case is when I create a "Model" class to reflect an entire SQL database. I want a model instance to provide a single point of access to > the database, but the database has many tables each requiring its own methods since they differ in their structure, purpose, validation needs, etc. > > A secondary use case is when I create "MainWindow" classes in GUI programming and have lots of methods to reflect all the actions (e.g., menu options > and toolbar actions, plus interaction with the main widget(s)). > > To meet these needs I've devised an approach that I think is easy to use and understand and which doesn't use any tricky or hard to maintain code. > > My question is -- are there nicer/better ways to achieve this? > > Here's a summary of my approach. A fuller discussion is on my website: > https://www.qtrac.eu/pyclassmulti.html > > # Lib.py > # This provides the two functions (both decorators) used to support my approach > def add_methods_from(*modules): > def decorator(Class): > for module in modules: > for method in getattr(module, "__methods__"): > setattr(Class, method.__name__, method) > return Class > return decorator > > def register_method(methods): # A decorator used purely for its side-effect > def register_method(method): > methods.append(method) > return method # Unchanged and not strictly necessary > return register_method > > # Model.py > # This provides my model but some methods are in separate files > import Lib > import _ModelConfig > import _ModelOutput > > @Lib.add_methods_from(_ModelConfig, _ModelOutput) > class Model: > ... > def small_method(self): > ... > > # _ModelConfig.py # _ModelOutput has the same structure so not shown > import Lib > > __methods__ = [] # self is a Model > register_method = Lib.register_method(__methods__) > > @register_method > def config(self): > ... > So, that's the overall pattern of my solution. > > Is there a nicer/better way? Could I cleanly avoid the explicit imports (e.g., import _ModelConfig), without resorting to stack frame hacks or similar? From rustompmody at gmail.com Sun Jun 5 03:34:54 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 5 Jun 2016 00:34:54 -0700 (PDT) Subject: Lineendings (was Everything good about Python except GUI IDE?) In-Reply-To: References: <64a6599c-fae1-469d-bcee-875165b3cc7d@googlegroups.com> <56d294f8$0$1604$c3e8da3$5496439d@news.astraweb.com> <62084c14-abd1-4214-af08-70ce8449c83e@googlegroups.com> <6dq5db5j0hg2evl7t334ftdm5sk8n5itge@4ax.com> <93t5db9sib9ldgktrt7523fnis4tgq2uev@4ax.com> <9064f06c-cbd5-4bf4-98d7-24bed0e78c10@googlegroups.com> <90f65ae1-c3d8-4a36-bc9f-860403a0633c@googlegroups.com> <56d39335$0$1622$c3e8da3$5496439d@news.astraweb.com> <92074551-a917-43d2-b72f-f184798ab7e8@googlegroups.com> <47e3847b-1fe5-4319-9de9-5d64c996195a@googlegroups.com> Message-ID: <8652f9e6-83bd-4b02-b631-f2b345265e14@googlegroups.com> Just came across this new data (for me) to this old question: On Monday, February 29, 2016 at 8:05:33 AM UTC+5:30, Ben Finney wrote: > Rustom Mody writes: > > > On Monday, February 29, 2016 at 7:33:18 AM UTC+5:30, Chris Angelico wrote: > > > Never has for any of my projects. Examples please? Actual real > > > problems? I've been using git for years, on mixed platforms for a lot > > > of that, and not had a single problem. > > > > Pragmatically: As I said just search stackoverflow for git:crlf > > Don't ask Chris to *guess* which search results are representative of > what you're asserting. Please provide concrete examples that demonstrate > specifically what you're describing. A graphic description of the problem: http://www.hanselman.com/blog/YoureJustAnotherCarriageReturnLineFeedInTheWall.aspx Along with a solution that is not universally working https://bugs.eclipse.org/bugs/show_bug.cgi?id=342372 From __peter__ at web.de Sun Jun 5 03:35:44 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Jun 2016 09:35:44 +0200 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> Message-ID: ICT Ezy wrote: >>>> 2 ** 3 ** 2 > Answer is 512 > Why not 64? > Order is right-left or left-right? ** is a special case: """ The power operator ** binds less tightly than an arithmetic or bitwise unary operator on its right, that is, 2**-1 is 0.5. """ https://docs.python.org/3.5/reference/expressions.html#id21 Here's a little demo: $ cat arithdemo.py class A: def __init__(self, value): self.value = str(value) def __add__(self, other): return self._op(other, "+") def __pow__(self, other): return self._op(other, "**") def __repr__(self): return self.value def _op(self, other, op): return A("({} {} {})".format(self.value, op, other.value)) $ python3 -i arithdemo.py >>> A(1) + A(2) + A(3) ((1 + 2) + 3) >>> A(1) ** A(2) ** A(3) (1 ** (2 ** 3)) From __peter__ at web.de Sun Jun 5 03:40:19 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Jun 2016 09:40:19 +0200 Subject: Spreading a class over multiple files References: Message-ID: Mark Summerfield wrote: > Sometimes I want to spread a class over multiple files. > > My primary use case is when I create a "Model" class to reflect an entire > SQL database. I want a model instance to provide a single point of access > to > the database, but the database has many tables each requiring its own > methods since they differ in their structure, purpose, validation needs, > etc. In other words, a God Class http://c2.com/cgi/wiki?GodClass > My question is -- are there nicer/better ways to achieve this? Use composition. From marko at pacujo.net Sun Jun 5 04:01:31 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 05 Jun 2016 11:01:31 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k2i483ok.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 5 Jun 2016 01:17 pm, Lawrence D?Oliveiro wrote: >> Are variables like little boxes? Yes they are. > > That's *exactly* what variables in Python are not like. Of course they are. Or, rather, the little-box mental model is no worse than any other. You could also think of variables as pegs, references as leashes, and objects as cute puppies. One puppy could be held with multiple leashes hung on separate pegs. Some puppies hold leashes in their mouths. Every leash is tied to a puppy or a special wooden post called None. >> But they are all the same size, while objects may be large (even very >> large) or small. That is why variables hold, not objects, but >> references to objects. > > No they don't. You are confusing the implementation with the > programming model. The easiest way to understand the references of Java, Python, Lisp and others is through an underlying implementation. I really haven't seen a better abstract model presented. (An alternate model could be the semantics of lambda calculus, which doesn't have a data model at all! Instead, the semantics are given through the execution model: a form is repeatedly transformed to new forms until no transformation is allowed by the rules. That kind of model would not suit Python, though, because Python's little boxes can be assigned to.) > Following the assignment: > > x = 99 > > if you print(x), do you see something like "reference 0x12345"? No. Irrelevant. The statement "print(x)" does not print a variable but the result of the evaluation of the given expression. > There is no analog to dereferencing in Python, nothing like print(x^). True, variables are not first-class objects in Python. (However, Guido could add first-class status to variables to Python with the snap of his fingers in a 100%-backwards-compatible manner.) > You bind values (that is, objects) directly to names, and names > (variables) hold their value, not a reference to their value. That mental model seems more confusing than the little-box one. > The fact that for some implementations that is implemented using > references of some sort or another (e.g. pointers in CPython) is an > implementation detail which is irrelevant to the language and its > execution model. The references cannot be removed from Python's data model. In fact, they haven't been: The value of an immutable container object that contains a REFERENCE to a mutable object can change when the latter?s value is changed; [...] Some objects contain REFERENCES to other objects; these are called containers. Examples of containers are tuples, lists and dictionaries. The REFERENCES are part of a container?s value. In most cases, when we talk about the value of a container, we imply the values, not the identities of the contained objects; however, when we talk about the mutability of a container, only the identities of the immediately contained objects are implied. So, if an immutable container (like a tuple) contains a REFERENCE to a mutable object, its value changes if that mutable object is changed. Types affect almost all aspects of object behavior. Even the importance of object identity is affected in some sense: for immutable types, operations that compute new values may actually return a REFERENCE to any existing object with the same type and value, while for mutable objects this is not allowed. E.g., after a = 1; b = 1, a and b may or may not REFER to the same object with the value one, depending on the implementation, but after c = []; d = [], c and d are guaranteed to REFER to two different, unique, newly created empty lists. (Note that c = d = [] assigns the same object to both c and d.) [etc etc] (capitalization is mine) Marko From list at qtrac.plus.com Sun Jun 5 04:14:02 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Sun, 5 Jun 2016 01:14:02 -0700 (PDT) Subject: Spreading a class over multiple files In-Reply-To: References: <5753D230.7060902@digipen.edu> Message-ID: You're quite right! For some reason I have a blind-spot about mixins, but they are the perfect solution. Thanks:-) From danish21h at gmail.com Sun Jun 5 06:56:00 2016 From: danish21h at gmail.com (Danish Hussain) Date: Sun, 5 Jun 2016 03:56:00 -0700 (PDT) Subject: Taking two and more data frames and extracting data on unique keys in python Message-ID: 1 down vote favorite Its a bit long question have patience. firstly I have 2 data frames one in which i have name of a guy and pages liked by him in columns. So no. of columns will be different for different person here is the example. 1st column is the name of user.Then pages liked by him is stored across the row.So no. of columns for 'random guy' will be different from 'mank rion'. 'BlackBick' , '500 Startups' e.t.c are name of the page. let say name of this data frame is User_page random guy BlackBuck GiveMeSport Analytics Ninja mank nion DJ CHETAS Celina Jaitly Gurkeerat Singh pop rajuel WOW Editions 500 Startups Biswapati Sarkar Roshan ghai MensXP No Abuse the smartian Now I have another Data frame in which is kind of same as upper one but in the place of page's name there is a category of page.you might now there are different category of pages on fb. so let say 'BlacBuck''s category is 'Transport/Freight'. There are pages with same name and different category.That is why i cant use name directly as key this is how my data frame looks like.Let say name of this data frame User_category. random guy Transport/Freight Sport Insurance Company mank nion Arts/Entertainment Actress Actor/Director pop rajuel Concert Tour App Page Actor/Director Roshan ghai News/Media Website Community Public Figure Now I have two more Data frames. one in which I have name of fb pages as 1st column and 162 more columns with some tag for each page there is value 1 for i*j element if ith page comes in to jth tag otherwise left empty so it will look like.let say name of this dataframe is Page_tag name of page tag 1 tag2 tag3 BlackBuck 1 1 GiveMeSport 1 1 Analytics Ninja 1 1 DJ CHETAS 1 1 the another one have name of categories as 1st column and same 162 as further. like this. let say name of this dataframe is Category_tag. category_name tag 1 tag2 tag3 Sport 1 1 App Page 1 1 Actor/Director 1 Public Figure 1 1 Now what I have to get the tag counts for each user from pages he has liked. for that first I have to first check that the page which he has liked where exist in data frame of Page_tag which is 3rd dataframe in my question if it exist there take the counts of tags that how many times a specific tags appeared for that user.this is first step if not found the name of page as no. of pages in Page_tag dataframe(3rd one) is limited. I will go to category of page (from 2nd dataframe in this question) for the pages which are left out and for that category i will count the tags count for the specific user from dataframe named Category_tags(4th dataframe in this question) and sum the tag count and my output something like this. Output username tag1 tag2 tag3 random guy 1 2 2 mank nion 2 1 3 pop rajuel 4 0 2 Roshan ghai 0 2 1 a i*j element on this dataframe shows no. times that the jth tag appears for ith user. I have written code for this and more in R i am stuck in this particular step. The code of R wasnt optimal as i used loops many time. I wanted to rhis optimally, hopefully can be done in pandas. Please me know if clarification is needed. Any help will be appreciated. Thank you. From steve at pearwood.info Sun Jun 5 06:57:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 05 Jun 2016 20:57:45 +1000 Subject: Spreading a class over multiple files References: <5753D230.7060902@digipen.edu> Message-ID: <575405ab$0$1583$c3e8da3$5496439d@news.astraweb.com> On Sun, 5 Jun 2016 06:14 pm, Mark Summerfield wrote: > You're quite right! For some reason I have a blind-spot about mixins, but > they are the perfect solution. Thanks:-) They really aren't :-) Just yesterday on an unrelated thread I linked to a long discussion about multiple inheritance, mixins and traits. See links here: https://mail.python.org/pipermail/python-list/2016-June/709808.html To my mind, if you have to split a class over multiple files, it probably does too much. The "God Class" that Peter referred to is an anti-pattern: https://en.wikipedia.org/wiki/God_object but if you still need to split your class over multiple files, this is how I would do it: # file a.py class Zeus_King_Of_The_Gods: # *wink* from b import throw_lightening from c import turn_into_a_shower_of_gold def turn_into_animal(self, animal='bull'): ... # file b.py def throw_lightening(self): ... # file c.py def turn_into_a_shower_of_gold(self): ... Notice that in files b and c you define the functions with an explicit self, even though they are at the top level. -- Steven From mal at europython.eu Sun Jun 5 06:58:41 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 5 Jun 2016 12:58:41 +0200 Subject: EuroPython 2016: Hot Topics Call for Proposals is Open ! Message-ID: <575405E1.9070601@europython.eu> We are happy to announce that we?ve opened our second Call for Proposals. This call is limited to hot topics and most recent developments in software and technology and will run until June 12. *** Proposal Submission Page *** https://ep2016.europython.eu/en/speakers/hot-topics-cfp/ Why is there a second call ? ---------------------------- Planning a big conference is a challenge: On one hand people like to know what will be on our talk schedule to make up their mind and make travel arrangements early. On the other hand technology is progressing at enormous speed these days. So we have given this some thought and decided to split the Call for Proposals in two phases, with the second just weeks before the conference. Submit your hot topic talk -------------------------- This CFP is reserved for: * hot topics * emerging technologies * brand new developments in software & hardware * recent results in research and science Some suggestions for topics: * Exciting new hardware & Internet of Things * Robotics * Virtual Reality * AI & Deep Learning The second call will be open for nine days only: Saturday June 4th 0:00 to Sunday June 12th 24:00 CEST. The program work group will then select the most exciting and intriguing submissions and will notify the winners on short notice. Submit your poster or run a help desk ------------------------------------- Since we still have a few slots left, we are also looking for more posters and help desks - these are not limited to hot topics. Get a ticket discount --------------------- For talks, posters, help desks we will give out a 25% discount coupon valid for one conference ticket. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/739409571031187456 Thanks. From ned at nedbatchelder.com Sun Jun 5 07:29:24 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 5 Jun 2016 04:29:24 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> Message-ID: <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> On Saturday, June 4, 2016 at 11:29:30 PM UTC-4, Lawrence D?Oliveiro wrote: > On Saturday, June 4, 2016 at 11:37:18 PM UTC+12, Ned Batchelder wrote: > > On Friday, June 3, 2016 at 11:43:33 PM UTC-4, Lawrence D?Oliveiro wrote: > > > On Saturday, June 4, 2016 at 3:00:36 PM UTC+12, Steven D'Aprano wrote: > > > > You can exit a loop because you have run out of items to process, or you can > > > > exit the loop because a certain condition has been met. > > > > > > But why should they be expressed differently? > > > > > > item_iter = iter(items) > > > while True : > > > item = next(item_iter, None) > > > if item == None : > > > break > > > if is_what_i_want(item) : > > > break > > > #end while > > > > Do you actually write loops like this? > > Is that a non-trolling question? Yes. All the time. OK. The best I can say is that you seem to think very differently about your code than I do. Re-implementing the logic of iteration just so you can make the two end conditions look similar seems like a very bad trade-off to me. It adds more lines, and more names, and as Steven points out, more opportunities to introduce errors. > When a language has good and bad parts, it behooves the wise programmer to concentrate on the good parts and try to ignore the bad. > > Python?s for-loops have their uses?I *did* point this out too, did you not notice??but they are best confined to the situations that they are good at. I'm not sure what part of Python you are putting in the "bad" category. This example didn't involve for/else, so are you saying that break statements inside for-loops are a bad part? IIRC, this started as a comparison of Python's for loops and C's. Do you also write C for-loops as while statements if they have a break in them, to make both of those end conditions similar? I'm not trolling, I'm trying to understand your unusual approach. --Ned. From marko at pacujo.net Sun Jun 5 07:43:07 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 05 Jun 2016 14:43:07 +0300 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> Message-ID: <878tyj97zo.fsf@elektro.pacujo.net> Ned Batchelder : > On Saturday, June 4, 2016 at 11:29:30 PM UTC-4, Lawrence D?Oliveiro wrote: >> > > item_iter = iter(items) >> > > while True : >> > > item = next(item_iter, None) >> > > if item == None : >> > > break >> > > if is_what_i_want(item) : >> > > break >> > > #end while > > OK. The best I can say is that you seem to think very differently > about your code than I do. Re-implementing the logic of iteration just > so you can make the two end conditions look similar seems like a very > bad trade-off to me. It adds more lines, and more names, and as Steven > points out, more opportunities to introduce errors. I often experiment with different loop constructs to find the one most pleasing to the eye. Working directly off iterators is quite rare but a while-vs-for consideration is frequent. Also, should the stepping part be in the beginning, middle or end of the loop body? > I'm not sure what part of Python you are putting in the "bad" > category. This example didn't involve for/else, so are you saying that > break statements inside for-loops are a bad part? It takes time to acclimatize to a new programming language. Initially, you tend to shun odd-looking constructs like comprehensions. Then, you might overdo constructs like lambdas and maps. Eventually, you'll find a style the suits both you and the language. Marko From vonpupp at gmail.com Sun Jun 5 09:02:04 2016 From: vonpupp at gmail.com (Albert) Date: Sun, 5 Jun 2016 06:02:04 -0700 (PDT) Subject: Anyone know a donation app codebase? In-Reply-To: References: <8560to4qhz.fsf@benfinney.id.au> Message-ID: <1973b5af-79c5-4bf5-a13f-4532e1f16a71@googlegroups.com> Thank you for your answer Ben, That is not exactly what I am looking for. I am interested in knowing if there are any python (django, flask, etc) opensource projects for managing donations, similar to catarse [1] (ruby) and [2] (ruby). [1]: https://github.com/catarse/catarse [2]: https://github.com/danielweinmann/unlock Any suggestion please? On Saturday, June 4, 2016 at 6:02:51 PM UTC-3, Ben Finney wrote: > Albert writes: > > > Anyone knows a donation app whose code is available on github or > > similar made in python (could be django, flask, or any other web > > framework). > > Search for Python libraries on the Python Package Index > . > > What you are (I think) looking for can be called a ?payment? handler > . > If that's not right you can try different search terms. > > -- > \ ?My, your, his, hers, ours, theirs, its. I'm, you're, he's, | > `\ she's, we're, they're, it's.? ?anonymous, alt.sysadmin.recovery | > _o__) | > Ben Finney From ictezy at gmail.com Sun Jun 5 11:05:51 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 5 Jun 2016 08:05:51 -0700 (PDT) Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> Message-ID: <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> On Sunday, June 5, 2016 at 1:06:21 PM UTC+5:30, Peter Otten wrote: > ICT Ezy wrote: > > >>>> 2 ** 3 ** 2 > > Answer is 512 > > Why not 64? > > Order is right-left or left-right? > > ** is a special case: > > """ > The power operator ** binds less tightly than an arithmetic or bitwise unary > operator on its right, that is, 2**-1 is 0.5. > """ > https://docs.python.org/3.5/reference/expressions.html#id21 > > Here's a little demo: > > $ cat arithdemo.py > class A: > def __init__(self, value): > self.value = str(value) > def __add__(self, other): > return self._op(other, "+") > def __pow__(self, other): > return self._op(other, "**") > def __repr__(self): > return self.value > def _op(self, other, op): > return A("({} {} {})".format(self.value, op, other.value)) > $ python3 -i arithdemo.py > >>> A(1) + A(2) + A(3) > ((1 + 2) + 3) > >>> A(1) ** A(2) ** A(3) > (1 ** (2 ** 3)) Thank you very much for your explanation From python at mrabarnett.plus.com Sun Jun 5 11:08:47 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 5 Jun 2016 16:08:47 +0100 Subject: Lineendings (was Everything good about Python except GUI IDE?) In-Reply-To: <8652f9e6-83bd-4b02-b631-f2b345265e14@googlegroups.com> References: <64a6599c-fae1-469d-bcee-875165b3cc7d@googlegroups.com> <62084c14-abd1-4214-af08-70ce8449c83e@googlegroups.com> <6dq5db5j0hg2evl7t334ftdm5sk8n5itge@4ax.com> <93t5db9sib9ldgktrt7523fnis4tgq2uev@4ax.com> <9064f06c-cbd5-4bf4-98d7-24bed0e78c10@googlegroups.com> <90f65ae1-c3d8-4a36-bc9f-860403a0633c@googlegroups.com> <56d39335$0$1622$c3e8da3$5496439d@news.astraweb.com> <92074551-a917-43d2-b72f-f184798ab7e8@googlegroups.com> <47e3847b-1fe5-4319-9de9-5d64c996195a@googlegroups.com> <8652f9e6-83bd-4b02-b631-f2b345265e14@googlegroups.com> Message-ID: <3b910b4c-ee54-f714-2b31-ec0b1078bdd8@mrabarnett.plus.com> On 2016-06-05 08:34, Rustom Mody wrote: > Just came across this new data (for me) to this old question: > > On Monday, February 29, 2016 at 8:05:33 AM UTC+5:30, Ben Finney wrote: >> Rustom Mody writes: >> >> > On Monday, February 29, 2016 at 7:33:18 AM UTC+5:30, Chris Angelico wrote: >> > > Never has for any of my projects. Examples please? Actual real >> > > problems? I've been using git for years, on mixed platforms for a lot >> > > of that, and not had a single problem. >> > >> > Pragmatically: As I said just search stackoverflow for git:crlf >> >> Don't ask Chris to *guess* which search results are representative of >> what you're asserting. Please provide concrete examples that demonstrate >> specifically what you're describing. > > A graphic description of the problem: > http://www.hanselman.com/blog/YoureJustAnotherCarriageReturnLineFeedInTheWall.aspx > > Along with a solution that is not universally working > https://bugs.eclipse.org/bugs/show_bug.cgi?id=342372 > Years ago, I was making PPD (PostScript Printer Description) files for Mac and PC. The spec. stated that the line endings could be CR, LF or CR+LF. All went well until one day someone reported that they wouldn't install on a Mac, which they had done previously. It turned out that the Mac had a newer version of MacOS, which now insisted that the line endings be CR only... From ictezy at gmail.com Sun Jun 5 11:18:06 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 5 Jun 2016 08:18:06 -0700 (PDT) Subject: how to work await x operator? Message-ID: <23eb1050-f9ed-4bfc-8626-cd3bea329066@googlegroups.com> how to work await x Await expression operator? pl explain any one ... From marko at pacujo.net Sun Jun 5 11:21:52 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 05 Jun 2016 18:21:52 +0300 Subject: how to work await x operator? References: <23eb1050-f9ed-4bfc-8626-cd3bea329066@googlegroups.com> Message-ID: <87oa7f7jan.fsf@elektro.pacujo.net> ICT Ezy : > how to work await x Await expression operator? > pl explain any one ... A coroutine can't be called directly. A call to a coroutine must be prefixed with the "async" keyword. That allows Python to perform a context switch between coroutines in case the coroutine needs to wait for the operation to complete. Marko From uri at speedy.net Sun Jun 5 12:05:16 2016 From: uri at speedy.net (Uri Even-Chen) Date: Sun, 5 Jun 2016 19:05:16 +0300 Subject: Operator precedence problem In-Reply-To: <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> Message-ID: My suggestion: Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 + 5, without parentheses. Always add parentheses - 2 ** (3 ** 2) (or (2 ** 3) **2) or (2 * 4) + 5 (or 2 * (4 + 5)). *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ On Sun, Jun 5, 2016 at 6:05 PM, ICT Ezy wrote: > On Sunday, June 5, 2016 at 1:06:21 PM UTC+5:30, Peter Otten wrote: > > ICT Ezy wrote: > > > > >>>> 2 ** 3 ** 2 > > > Answer is 512 > > > Why not 64? > > > Order is right-left or left-right? > > > > ** is a special case: > > > > """ > > The power operator ** binds less tightly than an arithmetic or bitwise > unary > > operator on its right, that is, 2**-1 is 0.5. > > """ > > https://docs.python.org/3.5/reference/expressions.html#id21 > > > > Here's a little demo: > > > > $ cat arithdemo.py > > class A: > > def __init__(self, value): > > self.value = str(value) > > def __add__(self, other): > > return self._op(other, "+") > > def __pow__(self, other): > > return self._op(other, "**") > > def __repr__(self): > > return self.value > > def _op(self, other, op): > > return A("({} {} {})".format(self.value, op, other.value)) > > $ python3 -i arithdemo.py > > >>> A(1) + A(2) + A(3) > > ((1 + 2) + 3) > > >>> A(1) ** A(2) ** A(3) > > (1 ** (2 ** 3)) > > Thank you very much for your explanation > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Jun 5 12:24:37 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jun 2016 02:24:37 +1000 Subject: Operator precedence problem In-Reply-To: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> Message-ID: On Sun, Jun 5, 2016 at 4:53 PM, ICT Ezy wrote: >>>> 2 ** 3 ** 2 > Answer is 512 > Why not 64? > Order is right-left or left-right? This example follows the mathematical standard; you start from the "top" (the right hand side), and work your way down. >>> (3**3) % 10 7 >>> (3**3**3) % 10 7 >>> (3**3**3**3) % 10 .... waiting...... https://en.wikipedia.org/wiki/Graham%27s_number ChrisA From random832 at fastmail.com Sun Jun 5 13:19:33 2016 From: random832 at fastmail.com (Random832) Date: Sun, 05 Jun 2016 13:19:33 -0400 Subject: Operator precedence problem In-Reply-To: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> Message-ID: <1465147173.2666461.628499265.4DB6AD8F@webmail.messagingengine.com> On Sun, Jun 5, 2016, at 02:53, ICT Ezy wrote: > >>> 2 ** 3 ** 2 > Answer is 512 > Why not 64? > Order is right-left or left-right? You're mixing up order of evaluation with operator associativity. The ** operator is right-to-left associative, this means x ** y ** z == x ** (y ** z). Evaluation is left to right, where it matters [i.e. if one or more of the elements here were an expression with side effects]: first x is evaluated, then tmp=y**z, then x**tmp. These are two entirely different concepts. From random832 at fastmail.com Sun Jun 5 13:42:22 2016 From: random832 at fastmail.com (Random832) Date: Sun, 05 Jun 2016 13:42:22 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> On Sun, Jun 5, 2016, at 02:37, Steven D'Aprano wrote: > No they don't. You are confusing the implementation with the programming > model. > > Following the assignment: > > x = 99 > > if you print(x), do you see something like "reference 0x12345"? No. > > Do you have to dereference that reference to get the value of x? No. > > At the Python level, the value of x is 99, not some invisible, > untouchable reference to 99. Sure, but that is the value of the object referenced by x, it is not a property of x itself. x = y = 999; z = int('999') x is y # True x is z # False How would you describe the difference between x and y, and z? This is not a mere implementation detail [though, the fact that for int in particular I had to go higher than 99 to get this result is - I wouldn't have had this problem with strings, and I *couldn't* have had this problem with lists]. The fact that two objects can have the same value while being different objects, and that two variables can point to the same object, are part of the programming model. Immutable objects do tend to blur the line, since implementations are permitted to make them the same even when they're apparently independent. The fact that == is an operator distinct from 'is' inherently means that variables contain references, not objects. There is, obviously, only one value in my example. If variables contained objects, then my example would have three objects, none more or less distinct. They contain references, and that is the only way there are two objects, and that is the only model in which there are two of anything. [but, hey, at least we can agree that Python has variables.] > There is no analog to dereferencing in Python, nothing like print(x^). I don't see where anyone said there was. I think you've inferred meaning to the statement "python variables contain references" that it does not actually have. > You bind values (that is, objects) Values are not objects. x and z have the same value, and their objects are identical but distinct, but they are different because they point (or refer, or by your weird terminology "bind") to different objects. > directly to names, and names (variables) hold their value, not a > reference to their value. They hold a reference to an object. The object holds the value. > The fact that for some implementations that is implemented using > references of some sort or another (e.g. pointers in CPython) is an > implementation detail which is irrelevant to the language and its > execution model. From random832 at fastmail.com Sun Jun 5 13:53:26 2016 From: random832 at fastmail.com (Random832) Date: Sun, 05 Jun 2016 13:53:26 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <87k2i483ok.fsf@elektro.pacujo.net> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <87k2i483ok.fsf@elektro.pacujo.net> Message-ID: <1465149206.2672380.628512985.25519878@webmail.messagingengine.com> On Sun, Jun 5, 2016, at 04:01, Marko Rauhamaa wrote: > You could also think of variables as pegs, references as leashes, and > objects as cute puppies. One puppy could be held with multiple leashes > hung on separate pegs. Some puppies hold leashes in their mouths. Every > leash is tied to a puppy or a special wooden post called None. You've got it all wrong about what's special about None. The object is just another puppy. There *is* a variable called None [getattr(__builtins__, 'None')] which holds a leash tied to that puppy, but it's rarely used, since everyone knows how to find that puppy directly [None is a keyword]. But nothing's special about the object itself, no more than any other object. Of course, as the fact that I had to use __builtins__ shows, the "pegs" are a fiction. At least, as long as we consider that frames and modules are just another kind of puppy. Though I suppose technically frames are an implementation detail. From tjreedy at udel.edu Sun Jun 5 13:59:22 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 5 Jun 2016 13:59:22 -0400 Subject: Spreading a class over multiple files In-Reply-To: References: Message-ID: On 6/5/2016 2:55 AM, Mark Summerfield wrote: > Sometimes I want to spread a class over multiple files. My experience with trying to work with two do-all classes in idlelib has engendered a dislike for such. It is hard to find things in a kitchen-sink class. To switch IDLE from being a multi-window application to having multiple panes in a single window, both must be refactored. > My primary use case is when I create a "Model" class to reflect an > entire SQL database. I want a model instance to provide a single > point of access to the database, but the database has many tables > each requiring its own methods since they differ in their structure, > purpose, validation needs, etc. I would consider a master database ('Model') class, a base table class, and a subclass class for each table or group of similar tables. > A secondary use case is when I create "MainWindow" classes in GUI > programming and have lots of methods to reflect all the actions > (e.g., menu options and toolbar actions, plus interaction with the > main widget(s)). With tk and tkinter, at least, implementation functions do not have to be in the same file as the menu or toolbar definitions. -- Terry Jan Reedy From marko at pacujo.net Sun Jun 5 15:20:44 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 05 Jun 2016 22:20:44 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <87k2i483ok.fsf@elektro.pacujo.net> <1465149206.2672380.628512985.25519878@webmail.messagingengine.com> Message-ID: <87inxn788j.fsf@elektro.pacujo.net> Random832 : > On Sun, Jun 5, 2016, at 04:01, Marko Rauhamaa wrote: >> You could also think of variables as pegs, references as leashes, and >> objects as cute puppies. One puppy could be held with multiple >> leashes hung on separate pegs. Some puppies hold leashes in their >> mouths. Every leash is tied to a puppy or a special wooden post >> called None. > > You've got it all wrong about what's special about None. The object is > just another puppy. There *is* a variable called None > [getattr(__builtins__, 'None')] which holds a leash tied to that > puppy, but it's rarely used, since everyone knows how to find that > puppy directly [None is a keyword]. But nothing's special about the > object itself, no more than any other object. I say None is a wooden post, you say None is a puppy. What piece of Python code could put our dispute to rest? Marko From ben+python at benfinney.id.au Sun Jun 5 15:24:23 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Jun 2016 05:24:23 +1000 Subject: Anyone know a donation app codebase? References: <8560to4qhz.fsf@benfinney.id.au> <1973b5af-79c5-4bf5-a13f-4532e1f16a71@googlegroups.com> Message-ID: <851t4b4exk.fsf@benfinney.id.au> Albert writes: > Thank you for your answer Ben, You're welcome. Please note that top-posting is poor etiquette for discussions; instead, interleave your response like a written dialogue. See . > That is not exactly what I am looking for. I am interested in knowing > if there are any python (django, flask, etc) opensource projects for > managing donations Again, PyPI is the place to search . > Any suggestion please? I hope that helps. -- \ ?It seems intuitively obvious to me, which means that it might | `\ be wrong.? ?Chris Torek | _o__) | Ben Finney From marko at pacujo.net Sun Jun 5 15:38:16 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 05 Jun 2016 22:38:16 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> Message-ID: <87eg8b77fb.fsf@elektro.pacujo.net> Random832 : > On Sun, Jun 5, 2016, at 02:37, Steven D'Aprano wrote: >> You bind values (that is, objects) > > Values are not objects. x and z have the same value, and their objects > are identical but distinct, but they are different because they point > (or refer, or by your weird terminology "bind") to different objects. Terminological disputes are not very useful. However, note that your use of the word "value" is not the only one: Assignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects The returned value (if any) is used as an argument to construct StopIteration and becomes the StopIteration.value attribute. The type of the exception is the exception instance?s class, the value is the instance itself. while on the other hand, Every object has an identity, a type and a value. The operators <, >, ==, >=, <=, and != compare the values of two objects. The objects do not need to have the same type. IOW, sometimes the word "value" is a synonym of "object," at other times it refers to the specific characteristics of an object. The latter concept is not defined very clearly: The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. (The value of an immutable container object that contains a reference to a mutable object can change when the latter?s value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value, it is more subtle.) An object?s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable. Marko From random832 at fastmail.com Sun Jun 5 17:16:26 2016 From: random832 at fastmail.com (Random832) Date: Sun, 05 Jun 2016 17:16:26 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <87inxn788j.fsf@elektro.pacujo.net> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <87k2i483ok.fsf@elektro.pacujo.net> <1465149206.2672380.628512985.25519878@webmail.messagingengine.com> <87inxn788j.fsf@elektro.pacujo.net> Message-ID: <1465161386.2706373.628623897.408287CF@webmail.messagingengine.com> On Sun, Jun 5, 2016, at 15:20, Marko Rauhamaa wrote: > I say None is a wooden post, you say None is a puppy. > > What piece of Python code could put our dispute to rest? isinstance(None, object) Anyway, I read the "wooden post" claim as suggesting that a reference to None is somehow different from other references, as null in C# or Java is different from an object reference in those languages. From cs at zip.com.au Sun Jun 5 18:41:34 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Mon, 6 Jun 2016 08:41:34 +1000 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <10961e83-b9cd-4e7a-b16e-1d29377958d3@googlegroups.com> References: <10961e83-b9cd-4e7a-b16e-1d29377958d3@googlegroups.com> Message-ID: <20160605224134.GA82303@cskk.homeip.net> On 03Jun2016 16:09, Sayth Renshaw wrote: >> (By the way, the "pf = pf.append(thing)" construction is weird. >> All you need is pf.append(thing).) > >I got the pf = pf.append(thing) from doing pandas because in pandas its not an >inplace function. In Python this doesn't do what you think. The convention with most Python methods is that methods which perform an in-place action return None, which means the above assignment will unbind "pf", binding it to None instead. BTW, the short answer to why you can't just say pf.append(thing) and have "pf" be a list is that ".append" is not _inherently_ a list method i.e. the langauge does not specify that name as special. You can have another type where .append does somehing else. Therefore, the deduction that pf is uspposed to be a list may not be made. Cheers, Cameron Simpson From torriem at gmail.com Sun Jun 5 19:47:57 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 5 Jun 2016 17:47:57 -0600 Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> Message-ID: On 06/05/2016 10:05 AM, Uri Even-Chen wrote: > My suggestion: Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 > + 5, without parentheses. Always add parentheses - 2 ** (3 ** 2) (or (2 ** > 3) **2) or (2 * 4) + 5 (or 2 * (4 + 5)). I can understand using parenthesis when operator precedence isn't working the way you want or expect, but I certainly would not recommend using it for basic arithmetic with multiplication, division, addition and subtraction. The rules of precedence for multiplication and division are well known and well-understood. If a language failed to implement them that would be a bug. I think for the simple things extraneous parenthesis makes expressions more difficult for a human to parse because he will tend to second guess himself owing to extra parens. From lawrencedo99 at gmail.com Sun Jun 5 19:50:38 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 5 Jun 2016 16:50:38 -0700 (PDT) Subject: Yet Another Cairo API Binding In-Reply-To: References: Message-ID: On Thursday, June 2, 2016 at 9:16:25 AM UTC+12, I wrote: > Thought I would mention Qahirah , which is > yet another binding for the Cairo graphics > library. To add to this, I have bindings for Pixman (examples at ) and FreeType (examples at ). Of course, everybody wants to see pretty pictures. So have a look here , here and here . From greg.ewing at canterbury.ac.nz Sun Jun 5 21:08:07 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 06 Jun 2016 13:08:07 +1200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <87k2i483ok.fsf@elektro.pacujo.net> <1465149206.2672380.628512985.25519878@webmail.messagingengine.com> Message-ID: Random832 wrote: > There *is* a variable called None > [getattr(__builtins__, 'None')] which holds a leash tied to that puppy > ... But nothing's special about the object > itself, no more than any other object. The only special-ish thing about it is that it's unique -- there will never be another one like it, no matter how much dog breeding you do. Fortunately, it's also immortal. It's not the only puppy with that property, though. For instance, there's the pair True and False, born of the same litter but of quite opposite temperaments. And type, the ancient mother of all canines. -- Greg From lawrencedo99 at gmail.com Sun Jun 5 21:25:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 5 Jun 2016 18:25:18 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> Message-ID: On Sunday, June 5, 2016 at 3:18:05 PM UTC+12, I wrote: > (This makes no difference for immutable objects, only mutable ones.) I retract this part. Thanks, Marko, for showing me where I was wrong. :) From lawrencedo99 at gmail.com Sun Jun 5 21:28:12 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 5 Jun 2016 18:28:12 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <87k2i483ok.fsf@elektro.pacujo.net> <1465149206.2672380.628512985.25519878@webmail.messagingengine.com> Message-ID: On Monday, June 6, 2016 at 1:08:21 PM UTC+12, Gregory Ewing wrote: > The only special-ish thing about [None] is that it's unique -- > there will never be another one like it, no matter how > much dog breeding you do. Fortunately, it's also immortal. Maybe not immortal, but it seems to have 533 lives. Anybody who writes a C extension module for Python knows that Py_None is an object just like any other, and has to be treated the same in terms of managing its reference counts. (That?s how many unbalanced calls I had to make to Py_DECREF(Py_None) before it crashed Python.) From ictezy at gmail.com Sun Jun 5 23:23:24 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 5 Jun 2016 20:23:24 -0700 (PDT) Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> Message-ID: On Monday, June 6, 2016 at 5:18:21 AM UTC+5:30, Michael Torrie wrote: > On 06/05/2016 10:05 AM, Uri Even-Chen wrote: > > My suggestion: Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 > > + 5, without parentheses. Always add parentheses - 2 ** (3 ** 2) (or (2 ** > > 3) **2) or (2 * 4) + 5 (or 2 * (4 + 5)). > > I can understand using parenthesis when operator precedence isn't > working the way you want or expect, but I certainly would not recommend > using it for basic arithmetic with multiplication, division, addition > and subtraction. The rules of precedence for multiplication and division > are well known and well-understood. If a language failed to implement > them that would be a bug. I think for the simple things extraneous > parenthesis makes expressions more difficult for a human to parse > because he will tend to second guess himself owing to extra parens. Thank you very much for your explanation From ictezy at gmail.com Sun Jun 5 23:23:59 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 5 Jun 2016 20:23:59 -0700 (PDT) Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <1465147173.2666461.628499265.4DB6AD8F@webmail.messagingengine.com> Message-ID: On Sunday, June 5, 2016 at 10:49:49 PM UTC+5:30, Random832 wrote: > On Sun, Jun 5, 2016, at 02:53, ICT Ezy wrote: > > >>> 2 ** 3 ** 2 > > Answer is 512 > > Why not 64? > > Order is right-left or left-right? > > You're mixing up order of evaluation with operator associativity. The ** > operator is right-to-left associative, this means x ** y ** z == x ** (y > ** z). Evaluation is left to right, where it matters [i.e. if one or > more of the elements here were an expression with side effects]: first x > is evaluated, then tmp=y**z, then x**tmp. These are two entirely > different concepts. Thank you very much for your explanation From ictezy at gmail.com Sun Jun 5 23:24:57 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 5 Jun 2016 20:24:57 -0700 (PDT) Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> Message-ID: On Sunday, June 5, 2016 at 9:36:20 PM UTC+5:30, Uri Even-Chen wrote: > My suggestion: Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 > + 5, without parentheses. Always add parentheses - 2 ** (3 ** 2) (or (2 ** > 3) **2) or (2 * 4) + 5 (or 2 * (4 + 5)). > > > *Uri Even-Chen* > [image: photo] Phone: +972-54-3995700 > Email: uri at speedy.net > Website: http://www.speedysoftware.com/uri/en/ > > > > On Sun, Jun 5, 2016 at 6:05 PM, ICT Ezy wrote: > > > On Sunday, June 5, 2016 at 1:06:21 PM UTC+5:30, Peter Otten wrote: > > > ICT Ezy wrote: > > > > > > >>>> 2 ** 3 ** 2 > > > > Answer is 512 > > > > Why not 64? > > > > Order is right-left or left-right? > > > > > > ** is a special case: > > > > > > """ > > > The power operator ** binds less tightly than an arithmetic or bitwise > > unary > > > operator on its right, that is, 2**-1 is 0.5. > > > """ > > > https://docs.python.org/3.5/reference/expressions.html#id21 > > > > > > Here's a little demo: > > > > > > $ cat arithdemo.py > > > class A: > > > def __init__(self, value): > > > self.value = str(value) > > > def __add__(self, other): > > > return self._op(other, "+") > > > def __pow__(self, other): > > > return self._op(other, "**") > > > def __repr__(self): > > > return self.value > > > def _op(self, other, op): > > > return A("({} {} {})".format(self.value, op, other.value)) > > > $ python3 -i arithdemo.py > > > >>> A(1) + A(2) + A(3) > > > ((1 + 2) + 3) > > > >>> A(1) ** A(2) ** A(3) > > > (1 ** (2 ** 3)) > > > > Thank you very much for your explanation > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Thank you very much for your explanation From steve at pearwood.info Sun Jun 5 23:52:09 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 06 Jun 2016 13:52:09 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> Message-ID: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> On Mon, 6 Jun 2016 03:42 am, Random832 wrote: > On Sun, Jun 5, 2016, at 02:37, Steven D'Aprano wrote: >> No they don't. You are confusing the implementation with the programming >> model. >> >> Following the assignment: >> >> x = 99 >> >> if you print(x), do you see something like "reference 0x12345"? No. >> >> Do you have to dereference that reference to get the value of x? No. >> >> At the Python level, the value of x is 99, not some invisible, >> untouchable reference to 99. > > Sure, but that is the value of the object referenced by x, it is not a > property of x itself. You need to be clear about what you are referring to. x itself is the object 99. When we say "x + 1", we expect to get 100. x is not some reference to 99, it is 99, just like Barrack Obama is not a reference to the President of the United States, he is the POTUS. The *name* "x" is an entity which is bound to (i.e. a reference to) the object 99, in some specific namespace, at some specific time. The name itself is an English word consisting of a single letter, "x". Its implementation in Python is likely to be a str, "x", used as a key in some namespace (often a dict). The name itself doesn't have any numeric value, just as the English words "Barrack Obama" themselves are not a person. There are contexts where we need to refer to names themselves in Python, but they are comparatively rare. You will usually recognise them from context, occasionally implicitly, but usually explicitly by talking about "the name x" or "x" in quotes rather than x. In code, it will usually involve eval or exec, or sometimes a namespace lookup: method = vars(self)[methodname.upper()] Likewise, it is rare to refer to the words rather than the person Barrack Obama, but when you do, it is usually easy to recognise because you will generally refer to "Barrack Obama" in quotes. We might say: "x" is a single-letter name and x is an int one less than 100 but you normally wouldn't say: x is a single-letter name and x is an int one less than 100 unless your aim is to cause confusion. This is no different from the issue in plain English that words have meaning, and when we use a word, we normally expect them to be interpreted according to that meaning, and rarely as an abstract word. When we do, we normally put it in quotation marks, or explicitly state that we are referring to it as a word: A cat is a four-legged carnivorous mammal that purrs. "Cat" is a three-letter word; the word cat is of unknown origin. > x = y = 999; z = int('999') > x is y # True > x is z # False > > How would you describe the difference between x and y, and z? The names x and y are bound to the same object. The name z is bound to a distinct object with equal value. > This is not a mere implementation detail Of course it is. An implementation might be clever enough to recognise that int('999') is the same as 999 and reuse the same int object. An implementation might cache *all* ints, regardless of size, or do no caching at all. The part of that example which is not implementation defined is that given x = y = 999, the language requires that x and y be the same object. > [though, the fact that for int in > particular I had to go higher than 99 to get this result is - I wouldn't > have had this problem with strings, Really? py> a = b = "cat"; c = str("cat") py> a is b is c True But again, this is an implementation detail. The caching of strings depends on the version and implementation, and the string itself. > and I *couldn't* have had this > problem with lists]. The fact that two objects can have the same value > while being different objects, and that two variables can point to the > same object, are part of the programming model. Right. But that's actually not relevant to the question. [...] > The fact that == is an operator distinct from 'is' inherently means that > variables contain references, not objects. No, you are mixing levels of explanation and conflating implementation and interface. Would you insist that because we can say that the words Barack Obama contain eleven letters that the the United States has two words as a president? That Michelle Obama is married to two words rather than a man? Of course not. At least, if you are going to make that argument, then you are so confused that I'm not even going to discuss this with you. Imagine a horrendously memory profligate implementation that implemented variables using the fixed memory location model "variables are boxes". When I write: x = y = 999; z = 999 the interpreter creates three boxes "x", "y", "z". All three boxes need to be big enough for an int object, which in this case is about 12 bytes. Actually a bit bigger, as you will see: let's say 16 bytes, because the implementation needs (say) four bytes for an object identity tag. All three boxes get *mostly* the same content, namely the 12 byte object 999, but the x and y boxes get the identity tag (lets say) 633988994, and the z box gets the identity tag 633988995. `x == y` is implemented the usual way (calling int.__eq__), while `x is y` is implemented by testing whether the first four bytes of each box are equal. This would be a horribly profligate (and slow) implementation. Parameter passing into functions would occur via copying; it would be even more horribly slow because every mutation to an object would require a scan of all the objects, so as to update all of the boxes. But speed and efficiency is not part of the Python language model, its a quality of implementation issue, and besides, Moore's Law will make everything fast eventually. (Wishful thinking.) As inefficient and awful as this module is, it would still be Python, as the interface (the programming model) is the same. (Give or take a few bugs.) > There is, obviously, only one value in my example. There is nothing "obvious" about that at all. There is only one abstract number in use, namely 999, but there are two objects. What counts as the value? Is it the object, or the numeric value? Before you answer, consider the value of x and y given: x = Widget(part='123xy', colour='red') y = x.copy() just to make it clear that they are distinct objects. I would be unhappy with any definition of "value" that says that x and y don't have values, just because they are Widgets rather than strings or numbers, or the values are undefined. The question "the value of x?" is tricky, as we have to decide whether we mean the value of the variable or the value of the object. The value of the variable, I believe, must be identified with the object bound to that variable. What else could it be? Surely we would want: w = 999+0j x = 999 y = 999.0 z = Decimal("999.0000") to be distinguished: the variables aren't the same, they are bound to objects of different types, and surely we want "the value of w" to be understood as different from "the value of x" at least sometimes. Those four variables are numerically equal, but may not even compare equal, e.g. Decimal("999.0") == 999.0 returns False in 2.5. In principle, two numerically equal values might even raise TypeError on comparison. So there is nothing *obvious* about talking about value. I think that, under usual circumstances, the best way to understand "the value of x" is to distinguish between two cases: if x refers to the name, normally written "the value of the variable 'x'" but sometimes implied by the context, then the answer should be the object bound to 'x'. But if x refers to the variable, as in "the value of x", it refers to some type-specific definition of value, e.g. the numeric value. So your example has two values, which happen to be equal as they have the same, er, numeric value. (Sometimes words get used with different contexts. We need more words.) > If variables > contained objects, then my example would have three objects, Certainly not. x = y = 999 is required to bind the same object to x and y. > none more or less distinct. They contain references, If your variable x were a reference, then we would expect type(x) to return something like "Reference", but it doesn't, it returns int. (Why do I say this? We say "x is an int" after "x = 999", and type(x) returns int. So if "x is a reference", then type(x) ought to return Reference. If you *don't* say "x is an int", well, frankly, I don't believe you. See below.) If x were a reference to 999, then we would need to dereference x to get to the 999, but we don't. We don't write: print(dereference(x) + 1) to get 1000, we write print(x+1). If x + 1 is 1000, what is the value of x? (a) 999 (b) some invisible, intangible, untouchable reference to 999 If your answer is (b), then your view of Python programming is obfuscatory and muddled and I cannot understand how you can effectively reason about your code. If you look at an expression like x.y.z['k'] = [999] and reason like this: "x is a reference to a Spam object, so x.y is a reference to a reference to an Eggs object, so x.y.z is a reference to a reference to a reference to a dict, so x.y.z['k'] is a reference to a reference to a reference to a dict containing a reference to a key 'k' which maps to a reference to a list containing a reference to 999." then I cannot imagine how you get any work done. I don't believe you do. I believe you reason about the code just like I do: "x is a Spam object, so x.y is an Eggs object, so x.y.z is a dict, so x.y.z['k'] is a dict with key 'k' which maps to a list containing 999." So I'll be frank: anyone who says that "variables are references" surely doesn't behave as if that were true. They don't program as if variables were references, they don't reason about the code as if the variables were references, and they certainly don't talk about code as if they were references. They behave as if variables are the values (objects) bound to them, just as I have argued all along. (Except for the occasional and unusual situation where "peeking under the bonnet" into the implementation actually is helpful -- such cases do exist, such as a list which contains itself. Python's object model is an abstraction, and all abstractions leak. Sometimes we cannot help but talk about the implementation, in order to understand the leaks.) >> There is no analog to dereferencing in Python, nothing like print(x^). > > I don't see where anyone said there was. I think you've inferred meaning > to the statement "python variables contain references" that it does not > actually have. Of course it does, if you are talking about the Python variable model rather than the implementation. I'm perfectly happy for people to say that Python variables are implemented as references to objects. That's completely unobjectional, as it is true for all implementations I know of, and it will likely be true for any future implementations as well. We can be even more concrete and say that CPython variables are implemented as pointers to objects. But that's not the same as talking about the Python model. If you look at Python code, and read "x = 999", and don't think of x as now being 999, then I cannot fathom your mindset. You're thinking about code is an obfuscatory manner that is of no use to me. (In that case, I wonder why you don't go all the way to thinking about x as some sequence of bits: in Python 2.7, 96 bits.) >> You bind values (that is, objects) > > Values are not objects. x and z have the same value, and their objects > are identical but distinct, "Identical but distinct" is a contradiction according to the way object identity is defined in Python. > but they are different because they point > (or refer, or by your weird terminology "bind") to different objects. "Bind" is not weird terminology. It is a standard term in widespread use in computer science, particularly object oriented languages. https://en.wikipedia.org/wiki/Name_binding https://en.wikipedia.org/wiki/Late_binding https://en.wikipedia.org/wiki/Binding#In_computing -- Steven From torriem at gmail.com Mon Jun 6 00:01:29 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 5 Jun 2016 22:01:29 -0600 Subject: Everything good about Python except GUI IDE? In-Reply-To: <87twkoa4nt.fsf@elektro.pacujo.net> References: <64a6599c-fae1-469d-bcee-875165b3cc7d@googlegroups.com> <56d294f8$0$1604$c3e8da3$5496439d@news.astraweb.com> <56d5c4b6$0$1591$c3e8da3$5496439d@news.astraweb.com> <87y4a2ax8g.fsf@elektro.pacujo.net> <56d64730$0$1589$c3e8da3$5496439d@news.astraweb.com> <87egbtbfmy.fsf@elektro.pacujo.net> <878u21uw7p.fsf@elektro.pacujo.net> <87twkoa4nt.fsf@elektro.pacujo.net> Message-ID: On 03/02/2016 03:36 PM, Marko Rauhamaa wrote: > Requirements for what I have in mind: > > 1. It would have to be and feel like real Python. > > 2. External commands should be available as callable Python functions. > > 3. Functions/commands should return streams. (Generators, maybe?) > > 4. Pipelines should have an intuitive syntax (but still be valid > Python). > > Requirements 3 and 4 apply to regular Python code as well. I've thought about this before and even tried my hand at creating a nice library for doing this sort of thing with Python. Generators seem like a natural analog for the shell pipes. However there is one big problem with them and that is they can only deal with one stream at a time. Whereas in shell programming there are 2 streams that you can use and connect simultaneously. For example I can simultaneously pipe standard out from a program to another command whilst piping standard error to another. I never figured out a way to emulate this idea of piping multiple streams. In the end I decided that Python's superior text processing facilities eliminated 90% of the reason to use pipes. And for the other 10%, generators worked extremely well and efficiently. http://www.dabeaz.com/generators/Generators.pdf When I was doing a lot of shell scripting in Python I wrote my own wrapper routine to launch programs and obtain stdout and stderr, which I could process with generator filters and that worked fairly elegantly for many things. Kind of a half-way approach but it worked well. From random832 at fastmail.com Mon Jun 6 00:08:08 2016 From: random832 at fastmail.com (Random832) Date: Mon, 06 Jun 2016 00:08:08 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> On Sun, Jun 5, 2016, at 23:52, Steven D'Aprano wrote: > Certainly not. x = y = 999 is required to bind the same object to x and > y. My statement was that if two variables can be bound to the same object, then variables *cannot* contain objects. The object has to exist somewhere, and this requirement means that the variables cannot be where the objects live. > If your variable x were a reference, then we would expect type(x) to > return > something like "Reference", but it doesn't, it returns int. No we would not. You are once again inferring meaning that people's statements don't actually carry. From torriem at gmail.com Mon Jun 6 00:21:48 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 5 Jun 2016 22:21:48 -0600 Subject: Everything good about Python except GUI IDE? In-Reply-To: References: <64a6599c-fae1-469d-bcee-875165b3cc7d@googlegroups.com> <56d294f8$0$1604$c3e8da3$5496439d@news.astraweb.com> <56d5c4b6$0$1591$c3e8da3$5496439d@news.astraweb.com> <87y4a2ax8g.fsf@elektro.pacujo.net> <56d64730$0$1589$c3e8da3$5496439d@news.astraweb.com> <87egbtbfmy.fsf@elektro.pacujo.net> <878u21uw7p.fsf@elektro.pacujo.net> <87twkoa4nt.fsf@elektro.pacujo.net> Message-ID: On 06/05/2016 10:01 PM, Michael Torrie wrote: > I've thought about this before and even tried my hand at creating a nice > library for doing this sort of thing with Python. Generators seem like > a natural analog for the shell pipes. However there is one big problem > with them and that is they can only deal with one stream at a time. > Whereas in shell programming there are 2 streams that you can use and > connect simultaneously. For example I can simultaneously pipe standard > out from a program to another command whilst piping standard error to > another. I never figured out a way to emulate this idea of piping > multiple streams. When I say that Python generators can only deal with one stream at a time I mean within the context of generator syntax: for x in gen(gen(gen(...))) Obviously I could write a function that returns two generators. It's just that you can't nest them cleanly. Not that bash's syntax is particularly clean when you are messing with standard error as well as standard out. From lawrencedo99 at gmail.com Mon Jun 6 01:46:42 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 5 Jun 2016 22:46:42 -0700 (PDT) Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> Message-ID: <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> On Monday, June 6, 2016 at 4:06:20 AM UTC+12, Uri Even-Chen wrote: > Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 > + 5, without parentheses. That leads to the code equivalent of . From nobody at nowhere.invalid Mon Jun 6 01:54:03 2016 From: nobody at nowhere.invalid (Nobody) Date: Mon, 06 Jun 2016 06:54:03 +0100 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <57523cd3$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 04 Jun 2016 12:28:33 +1000, Steven D'Aprano wrote: >> OTOH, a Free software licence is unilateral; the author grants the user >> certain rights, with the user providing nothing in return. > > That's not the case with the GPL. > > The GPL requires the user (not the end-user, who merely avails themselves > of their common law right to run the software, but the developer user, who > copies, distributes and modifies the code) to do certain things in return > for the right to copy, distribute and modify the code: The GPL places limitations on the granted licence. That isn't the same thing as requiring the distributor to do something "in return". This is why the (relatively few) cases where GPL infringements have resulted in litigation, the legal basis of the litigation is copyright infringement, not breach of contract. From greg.ewing at canterbury.ac.nz Mon Jun 6 02:37:53 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 06 Jun 2016 18:37:53 +1200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > The *name* "x" is an entity which is bound to (i.e. a reference to) the > object 99, in some specific namespace, at some specific time. The name > itself is an English word consisting of a single letter, "x". This is one reason why the term "name" is not good subsitute for the term "variable". The string "x" is not the same thing as the variable x, a fact that's obscured if you call the variable a "name". A better analogy along the presidential line would be the name "President of the United States". That name can refer to different people at different times, so there must be some piece of state in the world that records the association between the character string "President of the United States" and the person who currently holds that office. It's that piece of state that the OP is calling a "box". I don't know what form it actually takes, probably an official piece of paper somewhere, which may well be kept in a box. But the box doesn't contain Barack Obama himself, it only contains something that refers to him. -- Greg From archana.sonavane at gmail.com Mon Jun 6 02:50:02 2016 From: archana.sonavane at gmail.com (archana.sonavane at gmail.com) Date: Sun, 5 Jun 2016 23:50:02 -0700 (PDT) Subject: Would like to see output of each block of python Message-ID: <13be0e24-1c49-469f-9b68-abcddf324d06@googlegroups.com> Hi Team, I would like to see output of each block of python. Don't have any idea about python. What is command to see the output of each code block. #!/usr/bin/env python ######################################## # # ganglia-api.py - Ganglia Metric API # ######################################## from settings import LOGFILE, PIDFILE, API_SERVER, HEARTBEAT import os import sys import glob import re import logging import socket import select import datetime import time import SocketServer from xml.etree import ElementTree from xml.parsers.expat import ExpatError from urllib import quote from threading import Thread import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options __version__ = '1.0.16' define("port", default=8080, help="run on the given port", type=int) logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s[%(process)d] %(levelname)s - %(message)s", filename=LOGFILE) global logger logger = logging.getLogger("ganglia-api") class Elem: def __init__(self, elem): self.elem = elem def __getattr__(self, name): return self.elem.get(name.upper()) class NullElem: def __getattr__(self, name): return None class ApiMetric: tag_re = re.compile("\s+") def id(self): group = self.group if self.group is not None else "" id_elements = [self.environment, self.grid.name, self.cluster.name, self.host.name, group, self.name] return str.lower(".".join(filter(lambda (e): e is not None, id_elements))) def api_dict(self): type, units = ApiMetric.metric_type(self.type, self.units, self.slope) metric = {'environment': self.environment, 'service': self.grid.name, 'cluster': self.cluster.name, 'host': self.host.name, 'id': self.id(), 'metric': self.name, 'instance': self.instance, 'group': self.group, 'title': self.title, 'tags': ApiMetric.parse_tags(self.host.tags), 'description': self.desc, 'sum': self.sum, 'num': self.num, 'value': ApiMetric.is_num(self.val), 'units': units, 'type': type, 'sampleTime': datetime.datetime.fromtimestamp( int(self.host.reported) + int(self.host.tn) - int(self.tn)).isoformat() + ".000Z", 'graphUrl': self.graph_url, 'dataUrl': self.data_url} return dict(filter(lambda (k, v): v is not None, metric.items())) @staticmethod def parse_tags(tag_string): if tag_string is None: return None else: tags = ApiMetric.tag_re.split(tag_string) if "unspecified" in tags: return list() else: return tags @staticmethod def metric_type(type, units, slope): if units == 'timestamp': return 'timestamp', 's' if 'int' in type or type == 'float' or type == 'double': return 'gauge', units if type == 'string': return 'text', units return 'undefined', units @staticmethod def is_num(val): try: return int(val) except ValueError: pass try: return float(val) except ValueError: return val def __str__(self): return "%s %s %s %s %s %s" % ( self.environment, self.grid.name, self.cluster.name, self.host.name, self.group, self.name) class Metric(Elem, ApiMetric): def __init__(self, elem, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment Elem.__init__(self, elem) self.metadata = dict() for extra_data in elem.findall("EXTRA_DATA"): for extra_elem in extra_data.findall("EXTRA_ELEMENT"): name = extra_elem.get("NAME") if name: self.metadata[name] = extra_elem.get('VAL') original_metric_name = self.name try: self.metadata['NAME'], self.metadata['INSTANCE'] = self.name.split('-', 1) except ValueError: self.metadata['INSTANCE'] = '' if self.name in ['fs_util', 'inode_util']: if self.instance == 'rootfs': self.metadata['INSTANCE'] = '/' else: self.metadata['INSTANCE'] = '/' + '/'.join(self.instance.split('-')) params = {"environment": self.environment, "service": self.grid.name, "cluster": self.cluster.name, "host": self.host.name, "metric": original_metric_name} url = '%s/ganglia/api/v1/metrics?' % API_SERVER for (k, v) in params.items(): if v is not None: url += "&%s=%s" % (k, quote(v)) self.data_url = url params = {"c": self.cluster.name, "h": self.host.name, "v": "0", "m": original_metric_name, "r": "1day", "z": "default", "vl": self.units.replace('%', 'percent'), "ti": self.title} url = '%sgraph.php?' % self.grid.authority for (k, v) in params.items(): if v is not None: url += "&%s=%s" % (k, quote(v)) self.graph_url = url def __getattr__(self, name): try: if self.metadata.has_key(name.upper()): return self.metadata[name.upper()] else: return Elem.__getattr__(self, name) except AttributeError: return None def html_dir(self): return 'ganglia-' + self.environment + '-' + self.grid.name # Artificial metric generated from the Host class HeartbeatMetric(ApiMetric): def __init__(self, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment self.val = int(host.tn) self.tn = 0 self.tags = host.tags self.name = "heartbeat" self.group = "ganglia" self.title = "Ganglia Agent Heartbeat" self.desc = "Ganglia agent heartbeat in seconds" self.type = 'uint16' self.units = 'seconds' self.slope = 'both' def __getattr__(self, name): return None class GangliaGmetad: hostname = "localhost" def __init__(self, environment, service, xml_port, interactive_port): self.environment = environment self.service = service self.xml_port = xml_port self.interactive_port = interactive_port def read_data_from_port(self, host, port, send=None): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((host, port)) r, w, x = select.select([sock], [], [], 2) if not r: sock.close() return except socket.error, e: logger.warning('Could not open socket to %s:%d - %s', host, port, e) return try: if send is not None: sock.send(send) except socket.error, e: logger.warning('Could not send to %s:%d - %s', host, port, e) return buffer = "" while True: try: data = sock.recv(8192) except socket.error, e: logger.warning('Could not receive data from %s:%d - %s', host, port, e) return if not data: break buffer += data.decode("ISO-8859-1") sock.close() return buffer def read_xml_data(self): return self.read_data_from_port(self.hostname, self.xml_port) def read_xml_metrics(self): result = list() xml_data = self.read_xml_data() if xml_data: try: ganglia = ElementTree.XML(xml_data) except UnicodeEncodeError: logging.error('Could not parse XML data') return result else: return result for grid_elem in ganglia.findall("GRID"): grid = Elem(grid_elem) for cluster_elem in grid_elem.findall("CLUSTER"): cluster = Elem(cluster_elem) for host_elem in cluster_elem.findall("HOST"): host = Elem(host_elem) result.append(HeartbeatMetric(host, cluster, grid, self.environment)) for metric_elem in host_elem.findall("METRIC"): result.append(Metric(metric_elem, host, cluster, grid, self.environment)) return result def read_interactive_data(self): return self.read_data_from_port(self.hostname, self.interactive_port, '/?filter=summary\r\n') def read_interactive_metrics(self): result = list() interactive_data = self.read_interactive_data() if interactive_data: try: ganglia = ElementTree.XML(interactive_data) except ExpatError, e: logging.error('Could not parse XML data: %s', e) return result else: return result for grid_elem in ganglia.findall("GRID"): grid = Elem(grid_elem) for cluster_elem in grid_elem.findall("CLUSTER"): cluster = Elem(cluster_elem) for metric_elem in cluster_elem.findall("METRICS"): result.append(Metric(metric_elem, NullElem(), cluster, grid, self.environment)) return result def read_metrics(self): xml_metrics = self.read_xml_metrics() interactive_metrics = self.read_interactive_metrics() xml_metrics.extend(interactive_metrics) return xml_metrics class GangliaConfig: GANGLIA_PATH = '/etc/ganglia' def __init__(self): self.env_service_dict = self.parse_ganglia_config() def parse_ganglia_config(self): logger.info("Parsing ganglia configurations") result = dict() for file in glob.glob(os.path.join(GangliaConfig.GANGLIA_PATH, 'gmetad-*-*.conf')): m = re.search('gmetad-(\S+)-(\S+).conf', file) environment = m.group(1) service = m.group(2) xml_port = 0 interactive_port = 0 f = open(file).readlines() for line in f: m = re.search('xml_port\s+(\d+)', line) if m: xml_port = int(m.group(1)) m = re.search('interactive_port\s+(\d+)', line) if m: interactive_port = int(m.group(1)) ports = GangliaGmetad(environment, service, xml_port, interactive_port) result[(environment, service)] = ports logger.info('Found gmetad-%s-%s.conf with ports %d and %d', environment, service, ports.xml_port, ports.interactive_port) return result def get_gmetad_config(self): return self.env_service_dict.values() def get_gmetad_for(self, environment, service): def is_match(gmetad): env_match = (not environment) or (gmetad.environment in environment) service_match = (not service) or (gmetad.service in service) return env_match and service_match return filter(is_match, self.env_service_dict.values()) class GmetadData(): def __init__(self): self.data = dict() def update(self, gmetad): logger.info(" getting metrics for %s %s", gmetad.environment, gmetad.service) gmetad_metrics = gmetad.read_metrics() logger.info(" updated %d metrics for %s %s", len(gmetad_metrics), gmetad.environment, gmetad.service) self.data[(gmetad.environment, gmetad.service)] = gmetad_metrics return len(gmetad_metrics) def metrics_for(self, environment, service): try: return self.data[(environment, service)] except KeyError: return list() def metrics(self, gmetad): return self.metrics_for(gmetad.environment, gmetad.service) class GangliaPollThread(Thread): def run(self): while True: self.update_ganglia_data() def update_ganglia_data(self): gmetad_list = ganglia_config.get_gmetad_config() logger.info("Updating data from gmetad...") total_metrics = 0 for counter, gmetad in enumerate(gmetad_list): metrics_for_gmetad = ganglia_data.update(gmetad) total_metrics += metrics_for_gmetad logger.debug(" (%d/%d) updated %d metrics for %s %s", counter + 1, len(gmetad_list), metrics_for_gmetad, gmetad.environment, gmetad.service) time.sleep(0.2) logger.info("Done (found %d metrics)", total_metrics) if HEARTBEAT: os.system('/opt/alerta/sbin/alert-sender.py --heartbeat --origin ganglia-api --tag %s --quiet' % __version__) class ApiHandler(tornado.web.RequestHandler): def get(self): start = time.time() environment = self.get_arguments("environment") service = self.get_arguments("service") metric_list = self.get_arguments("metric") group_list = self.get_arguments("group") host_list = self.get_arguments("host") cluster_list = self.get_arguments("cluster") def emptyOrContains(list, value): return len(list) == 0 or value in list def is_match(metric): return (emptyOrContains(metric_list, metric.name) and emptyOrContains(group_list, metric.group) and emptyOrContains(host_list, metric.host.name) and emptyOrContains(cluster_list, metric.cluster.name)) gmetad_list = ganglia_config.get_gmetad_for(environment, service) metric_dicts = list() for gmetad in gmetad_list: metrics = ganglia_data.metrics(gmetad) for metric in filter(is_match, metrics): metric_dicts.append(metric.api_dict()) output_dict = { "metrics": metric_dicts, "status": "ok", "total": len(metric_dicts), "localTime": datetime.datetime.now().isoformat(), "time": "%.3f" % (time.time() - start) } self.write({"response": output_dict}) def main(): logger.info("Starting up Ganglia metric API v%s", __version__) # Write pid file if not already running if os.path.isfile(PIDFILE): pid = open(PIDFILE).read() try: os.kill(int(pid), 0) logging.error('Process with pid %s already exists, exiting', pid) sys.exit(1) except OSError: pass file(PIDFILE, 'w').write(str(os.getpid())) global ganglia_config ganglia_config = GangliaConfig() global ganglia_data ganglia_data = GmetadData() poll_thread = GangliaPollThread() poll_thread.daemon = True poll_thread.start() tornado.options.parse_command_line() application = tornado.web.Application([ (r"/ganglia/api/v1/metrics", ApiHandler), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main() From archana.sonavane at gmail.com Mon Jun 6 02:57:57 2016 From: archana.sonavane at gmail.com (Archana Sonavane) Date: Sun, 5 Jun 2016 23:57:57 -0700 (PDT) Subject: Urgent - Would like to see output of each block of python Message-ID: Hi Team, I don't have any idea about python scripts, i have ganglia tool python scripts. I would like see the output of each code block, could you please guide. The code as follows: #!/usr/bin/env python ######################################## # # ganglia-api.py - Ganglia Metric API # ######################################## from settings import LOGFILE, PIDFILE, API_SERVER, HEARTBEAT import os import sys import glob import re import logging import socket import select import datetime import time import SocketServer from xml.etree import ElementTree from xml.parsers.expat import ExpatError from urllib import quote from threading import Thread import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options __version__ = '1.0.16' define("port", default=8080, help="run on the given port", type=int) logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s[%(process)d] %(levelname)s - %(message)s", filename=LOGFILE) global logger logger = logging.getLogger("ganglia-api") class Elem: def __init__(self, elem): self.elem = elem def __getattr__(self, name): return self.elem.get(name.upper()) class NullElem: def __getattr__(self, name): return None class ApiMetric: tag_re = re.compile("\s+") def id(self): group = self.group if self.group is not None else "" id_elements = [self.environment, self.grid.name, self.cluster.name, self.host.name, group, self.name] return str.lower(".".join(filter(lambda (e): e is not None, id_elements))) def api_dict(self): type, units = ApiMetric.metric_type(self.type, self.units, self.slope) metric = {'environment': self.environment, 'service': self.grid.name, 'cluster': self.cluster.name, 'host': self.host.name, 'id': self.id(), 'metric': self.name, 'instance': self.instance, 'group': self.group, 'title': self.title, 'tags': ApiMetric.parse_tags(self.host.tags), 'description': self.desc, 'sum': self.sum, 'num': self.num, 'value': ApiMetric.is_num(self.val), 'units': units, 'type': type, 'sampleTime': datetime.datetime.fromtimestamp( int(self.host.reported) + int(self.host.tn) - int(self.tn)).isoformat() + ".000Z", 'graphUrl': self.graph_url, 'dataUrl': self.data_url} return dict(filter(lambda (k, v): v is not None, metric.items())) @staticmethod def parse_tags(tag_string): if tag_string is None: return None else: tags = ApiMetric.tag_re.split(tag_string) if "unspecified" in tags: return list() else: return tags @staticmethod def metric_type(type, units, slope): if units == 'timestamp': return 'timestamp', 's' if 'int' in type or type == 'float' or type == 'double': return 'gauge', units if type == 'string': return 'text', units return 'undefined', units @staticmethod def is_num(val): try: return int(val) except ValueError: pass try: return float(val) except ValueError: return val def __str__(self): return "%s %s %s %s %s %s" % ( self.environment, self.grid.name, self.cluster.name, self.host.name, self.group, self.name) class Metric(Elem, ApiMetric): def __init__(self, elem, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment Elem.__init__(self, elem) self.metadata = dict() for extra_data in elem.findall("EXTRA_DATA"): for extra_elem in extra_data.findall("EXTRA_ELEMENT"): name = extra_elem.get("NAME") if name: self.metadata[name] = extra_elem.get('VAL') original_metric_name = self.name try: self.metadata['NAME'], self.metadata['INSTANCE'] = self.name.split('-', 1) except ValueError: self.metadata['INSTANCE'] = '' if self.name in ['fs_util', 'inode_util']: if self.instance == 'rootfs': self.metadata['INSTANCE'] = '/' else: self.metadata['INSTANCE'] = '/' + '/'.join(self.instance.split('-')) params = {"environment": self.environment, "service": self.grid.name, "cluster": self.cluster.name, "host": self.host.name, "metric": original_metric_name} url = '%s/ganglia/api/v1/metrics?' % API_SERVER for (k, v) in params.items(): if v is not None: url += "&%s=%s" % (k, quote(v)) self.data_url = url params = {"c": self.cluster.name, "h": self.host.name, "v": "0", "m": original_metric_name, "r": "1day", "z": "default", "vl": self.units.replace('%', 'percent'), "ti": self.title} url = '%sgraph.php?' % self.grid.authority for (k, v) in params.items(): if v is not None: url += "&%s=%s" % (k, quote(v)) self.graph_url = url def __getattr__(self, name): try: if self.metadata.has_key(name.upper()): return self.metadata[name.upper()] else: return Elem.__getattr__(self, name) except AttributeError: return None def html_dir(self): return 'ganglia-' + self.environment + '-' + self.grid.name # Artificial metric generated from the Host class HeartbeatMetric(ApiMetric): def __init__(self, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment self.val = int(host.tn) self.tn = 0 self.tags = host.tags self.name = "heartbeat" self.group = "ganglia" self.title = "Ganglia Agent Heartbeat" self.desc = "Ganglia agent heartbeat in seconds" self.type = 'uint16' self.units = 'seconds' self.slope = 'both' def __getattr__(self, name): return None class GangliaGmetad: hostname = "localhost" def __init__(self, environment, service, xml_port, interactive_port): self.environment = environment self.service = service self.xml_port = xml_port self.interactive_port = interactive_port def read_data_from_port(self, host, port, send=None): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((host, port)) r, w, x = select.select([sock], [], [], 2) if not r: sock.close() return except socket.error, e: logger.warning('Could not open socket to %s:%d - %s', host, port, e) return try: if send is not None: sock.send(send) except socket.error, e: logger.warning('Could not send to %s:%d - %s', host, port, e) return buffer = "" while True: try: data = sock.recv(8192) except socket.error, e: logger.warning('Could not receive data from %s:%d - %s', host, port, e) return if not data: break buffer += data.decode("ISO-8859-1") sock.close() return buffer def read_xml_data(self): return self.read_data_from_port(self.hostname, self.xml_port) def read_xml_metrics(self): result = list() xml_data = self.read_xml_data() if xml_data: try: ganglia = ElementTree.XML(xml_data) except UnicodeEncodeError: logging.error('Could not parse XML data') return result else: return result for grid_elem in ganglia.findall("GRID"): grid = Elem(grid_elem) for cluster_elem in grid_elem.findall("CLUSTER"): cluster = Elem(cluster_elem) for host_elem in cluster_elem.findall("HOST"): host = Elem(host_elem) result.append(HeartbeatMetric(host, cluster, grid, self.environment)) for metric_elem in host_elem.findall("METRIC"): result.append(Metric(metric_elem, host, cluster, grid, self.environment)) return result def read_interactive_data(self): return self.read_data_from_port(self.hostname, self.interactive_port, '/?filter=summary\r\n') def read_interactive_metrics(self): result = list() interactive_data = self.read_interactive_data() if interactive_data: try: ganglia = ElementTree.XML(interactive_data) except ExpatError, e: logging.error('Could not parse XML data: %s', e) return result else: return result for grid_elem in ganglia.findall("GRID"): grid = Elem(grid_elem) for cluster_elem in grid_elem.findall("CLUSTER"): cluster = Elem(cluster_elem) for metric_elem in cluster_elem.findall("METRICS"): result.append(Metric(metric_elem, NullElem(), cluster, grid, self.environment)) return result def read_metrics(self): xml_metrics = self.read_xml_metrics() interactive_metrics = self.read_interactive_metrics() xml_metrics.extend(interactive_metrics) return xml_metrics class GangliaConfig: GANGLIA_PATH = '/etc/ganglia' def __init__(self): self.env_service_dict = self.parse_ganglia_config() def parse_ganglia_config(self): logger.info("Parsing ganglia configurations") result = dict() for file in glob.glob(os.path.join(GangliaConfig.GANGLIA_PATH, 'gmetad-*-*.conf')): m = re.search('gmetad-(\S+)-(\S+).conf', file) environment = m.group(1) service = m.group(2) xml_port = 0 interactive_port = 0 f = open(file).readlines() for line in f: m = re.search('xml_port\s+(\d+)', line) if m: xml_port = int(m.group(1)) m = re.search('interactive_port\s+(\d+)', line) if m: interactive_port = int(m.group(1)) ports = GangliaGmetad(environment, service, xml_port, interactive_port) result[(environment, service)] = ports logger.info('Found gmetad-%s-%s.conf with ports %d and %d', environment, service, ports.xml_port, ports.interactive_port) return result def get_gmetad_config(self): return self.env_service_dict.values() def get_gmetad_for(self, environment, service): def is_match(gmetad): env_match = (not environment) or (gmetad.environment in environment) service_match = (not service) or (gmetad.service in service) return env_match and service_match return filter(is_match, self.env_service_dict.values()) class GmetadData(): def __init__(self): self.data = dict() def update(self, gmetad): logger.info(" getting metrics for %s %s", gmetad.environment, gmetad.service) gmetad_metrics = gmetad.read_metrics() logger.info(" updated %d metrics for %s %s", len(gmetad_metrics), gmetad.environment, gmetad.service) self.data[(gmetad.environment, gmetad.service)] = gmetad_metrics return len(gmetad_metrics) def metrics_for(self, environment, service): try: return self.data[(environment, service)] except KeyError: return list() def metrics(self, gmetad): return self.metrics_for(gmetad.environment, gmetad.service) class GangliaPollThread(Thread): def run(self): while True: self.update_ganglia_data() def update_ganglia_data(self): gmetad_list = ganglia_config.get_gmetad_config() logger.info("Updating data from gmetad...") total_metrics = 0 for counter, gmetad in enumerate(gmetad_list): metrics_for_gmetad = ganglia_data.update(gmetad) total_metrics += metrics_for_gmetad logger.debug(" (%d/%d) updated %d metrics for %s %s", counter + 1, len(gmetad_list), metrics_for_gmetad, gmetad.environment, gmetad.service) time.sleep(0.2) logger.info("Done (found %d metrics)", total_metrics) if HEARTBEAT: os.system('/opt/alerta/sbin/alert-sender.py --heartbeat --origin ganglia-api --tag %s --quiet' % __version__) class ApiHandler(tornado.web.RequestHandler): def get(self): start = time.time() environment = self.get_arguments("environment") service = self.get_arguments("service") metric_list = self.get_arguments("metric") group_list = self.get_arguments("group") host_list = self.get_arguments("host") cluster_list = self.get_arguments("cluster") def emptyOrContains(list, value): return len(list) == 0 or value in list def is_match(metric): return (emptyOrContains(metric_list, metric.name) and emptyOrContains(group_list, metric.group) and emptyOrContains(host_list, metric.host.name) and emptyOrContains(cluster_list, metric.cluster.name)) gmetad_list = ganglia_config.get_gmetad_for(environment, service) metric_dicts = list() for gmetad in gmetad_list: metrics = ganglia_data.metrics(gmetad) for metric in filter(is_match, metrics): metric_dicts.append(metric.api_dict()) output_dict = { "metrics": metric_dicts, "status": "ok", "total": len(metric_dicts), "localTime": datetime.datetime.now().isoformat(), "time": "%.3f" % (time.time() - start) } self.write({"response": output_dict}) def main(): logger.info("Starting up Ganglia metric API v%s", __version__) # Write pid file if not already running if os.path.isfile(PIDFILE): pid = open(PIDFILE).read() try: os.kill(int(pid), 0) logging.error('Process with pid %s already exists, exiting', pid) sys.exit(1) except OSError: pass file(PIDFILE, 'w').write(str(os.getpid())) global ganglia_config ganglia_config = GangliaConfig() global ganglia_data ganglia_data = GmetadData() poll_thread = GangliaPollThread() poll_thread.daemon = True poll_thread.start() tornado.options.parse_command_line() application = tornado.web.Application([ (r"/ganglia/api/v1/metrics", ApiHandler), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main() From clp2 at rebertia.com Mon Jun 6 03:05:35 2016 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 6 Jun 2016 00:05:35 -0700 Subject: Urgent - Would like to see output of each block of python In-Reply-To: References: Message-ID: On Sun, Jun 5, 2016 at 11:57 PM, Archana Sonavane wrote: > Hi Team, > > I don't have any idea about python scripts, i have ganglia tool python scripts. > > I would like see the output of each code block, could you please guide. > > The code as follows: With regard to your Subject line, please don't attempt to mark posts as "urgent". See http://www.catb.org/esr/faqs/smart-questions.html#urgent Regards, Chris From archana.sonavane at gmail.com Mon Jun 6 03:05:54 2016 From: archana.sonavane at gmail.com (Archana Sonavane) Date: Mon, 6 Jun 2016 00:05:54 -0700 (PDT) Subject: Would like to see python script output Message-ID: <4a1f7cb5-2d61-4f4b-a883-bd1f19c74f87@googlegroups.com> Hello, I have ganglia python script, i would like to see output of each code block. Could you please guide. I don't have any idea about python. My scripts as follows: #!/usr/bin/env python ######################################## # # ganglia-api.py - Ganglia Metric API # ######################################## from settings import LOGFILE, PIDFILE, API_SERVER, HEARTBEAT import os import sys import glob import re import logging import socket import select import datetime import time import SocketServer from xml.etree import ElementTree from xml.parsers.expat import ExpatError from urllib import quote from threading import Thread import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options __version__ = '1.0.16' define("port", default=8080, help="run on the given port", type=int) logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s[%(process)d] %(levelname)s - %(message)s", filename=LOGFILE) global logger logger = logging.getLogger("ganglia-api") class Elem: def __init__(self, elem): self.elem = elem def __getattr__(self, name): return self.elem.get(name.upper()) class NullElem: def __getattr__(self, name): return None class ApiMetric: tag_re = re.compile("\s+") def id(self): group = self.group if self.group is not None else "" id_elements = [self.environment, self.grid.name, self.cluster.name, self.host.name, group, self.name] return str.lower(".".join(filter(lambda (e): e is not None, id_elements))) def api_dict(self): type, units = ApiMetric.metric_type(self.type, self.units, self.slope) metric = {'environment': self.environment, 'service': self.grid.name, 'cluster': self.cluster.name, 'host': self.host.name, 'id': self.id(), 'metric': self.name, 'instance': self.instance, 'group': self.group, 'title': self.title, 'tags': ApiMetric.parse_tags(self.host.tags), 'description': self.desc, 'sum': self.sum, 'num': self.num, 'value': ApiMetric.is_num(self.val), 'units': units, 'type': type, 'sampleTime': datetime.datetime.fromtimestamp( int(self.host.reported) + int(self.host.tn) - int(self.tn)).isoformat() + ".000Z", 'graphUrl': self.graph_url, 'dataUrl': self.data_url} return dict(filter(lambda (k, v): v is not None, metric.items())) @staticmethod def parse_tags(tag_string): if tag_string is None: return None else: tags = ApiMetric.tag_re.split(tag_string) if "unspecified" in tags: return list() else: return tags @staticmethod def metric_type(type, units, slope): if units == 'timestamp': return 'timestamp', 's' if 'int' in type or type == 'float' or type == 'double': return 'gauge', units if type == 'string': return 'text', units return 'undefined', units @staticmethod def is_num(val): try: return int(val) except ValueError: pass try: return float(val) except ValueError: return val def __str__(self): return "%s %s %s %s %s %s" % ( self.environment, self.grid.name, self.cluster.name, self.host.name, self.group, self.name) class Metric(Elem, ApiMetric): def __init__(self, elem, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment Elem.__init__(self, elem) self.metadata = dict() for extra_data in elem.findall("EXTRA_DATA"): for extra_elem in extra_data.findall("EXTRA_ELEMENT"): name = extra_elem.get("NAME") if name: self.metadata[name] = extra_elem.get('VAL') original_metric_name = self.name try: self.metadata['NAME'], self.metadata['INSTANCE'] = self.name.split('-', 1) except ValueError: self.metadata['INSTANCE'] = '' if self.name in ['fs_util', 'inode_util']: if self.instance == 'rootfs': self.metadata['INSTANCE'] = '/' else: self.metadata['INSTANCE'] = '/' + '/'.join(self.instance.split('-')) params = {"environment": self.environment, "service": self.grid.name, "cluster": self.cluster.name, "host": self.host.name, "metric": original_metric_name} url = '%s/ganglia/api/v1/metrics?' % API_SERVER for (k, v) in params.items(): if v is not None: url += "&%s=%s" % (k, quote(v)) self.data_url = url params = {"c": self.cluster.name, "h": self.host.name, "v": "0", "m": original_metric_name, "r": "1day", "z": "default", "vl": self.units.replace('%', 'percent'), "ti": self.title} url = '%sgraph.php?' % self.grid.authority for (k, v) in params.items(): if v is not None: url += "&%s=%s" % (k, quote(v)) self.graph_url = url def __getattr__(self, name): try: if self.metadata.has_key(name.upper()): return self.metadata[name.upper()] else: return Elem.__getattr__(self, name) except AttributeError: return None def html_dir(self): return 'ganglia-' + self.environment + '-' + self.grid.name # Artificial metric generated from the Host class HeartbeatMetric(ApiMetric): def __init__(self, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment self.val = int(host.tn) self.tn = 0 self.tags = host.tags self.name = "heartbeat" self.group = "ganglia" self.title = "Ganglia Agent Heartbeat" self.desc = "Ganglia agent heartbeat in seconds" self.type = 'uint16' self.units = 'seconds' self.slope = 'both' def __getattr__(self, name): return None class GangliaGmetad: hostname = "localhost" def __init__(self, environment, service, xml_port, interactive_port): self.environment = environment self.service = service self.xml_port = xml_port self.interactive_port = interactive_port def read_data_from_port(self, host, port, send=None): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((host, port)) r, w, x = select.select([sock], [], [], 2) if not r: sock.close() return except socket.error, e: logger.warning('Could not open socket to %s:%d - %s', host, port, e) return try: if send is not None: sock.send(send) except socket.error, e: logger.warning('Could not send to %s:%d - %s', host, port, e) return buffer = "" while True: try: data = sock.recv(8192) except socket.error, e: logger.warning('Could not receive data from %s:%d - %s', host, port, e) return if not data: break buffer += data.decode("ISO-8859-1") sock.close() return buffer def read_xml_data(self): return self.read_data_from_port(self.hostname, self.xml_port) def read_xml_metrics(self): result = list() xml_data = self.read_xml_data() if xml_data: try: ganglia = ElementTree.XML(xml_data) except UnicodeEncodeError: logging.error('Could not parse XML data') return result else: return result for grid_elem in ganglia.findall("GRID"): grid = Elem(grid_elem) for cluster_elem in grid_elem.findall("CLUSTER"): cluster = Elem(cluster_elem) for host_elem in cluster_elem.findall("HOST"): host = Elem(host_elem) result.append(HeartbeatMetric(host, cluster, grid, self.environment)) for metric_elem in host_elem.findall("METRIC"): result.append(Metric(metric_elem, host, cluster, grid, self.environment)) return result def read_interactive_data(self): return self.read_data_from_port(self.hostname, self.interactive_port, '/?filter=summary\r\n') def read_interactive_metrics(self): result = list() interactive_data = self.read_interactive_data() if interactive_data: try: ganglia = ElementTree.XML(interactive_data) except ExpatError, e: logging.error('Could not parse XML data: %s', e) return result else: return result for grid_elem in ganglia.findall("GRID"): grid = Elem(grid_elem) for cluster_elem in grid_elem.findall("CLUSTER"): cluster = Elem(cluster_elem) for metric_elem in cluster_elem.findall("METRICS"): result.append(Metric(metric_elem, NullElem(), cluster, grid, self.environment)) return result def read_metrics(self): xml_metrics = self.read_xml_metrics() interactive_metrics = self.read_interactive_metrics() xml_metrics.extend(interactive_metrics) return xml_metrics class GangliaConfig: GANGLIA_PATH = '/etc/ganglia' def __init__(self): self.env_service_dict = self.parse_ganglia_config() def parse_ganglia_config(self): logger.info("Parsing ganglia configurations") result = dict() for file in glob.glob(os.path.join(GangliaConfig.GANGLIA_PATH, 'gmetad-*-*.conf')): m = re.search('gmetad-(\S+)-(\S+).conf', file) environment = m.group(1) service = m.group(2) xml_port = 0 interactive_port = 0 f = open(file).readlines() for line in f: m = re.search('xml_port\s+(\d+)', line) if m: xml_port = int(m.group(1)) m = re.search('interactive_port\s+(\d+)', line) if m: interactive_port = int(m.group(1)) ports = GangliaGmetad(environment, service, xml_port, interactive_port) result[(environment, service)] = ports logger.info('Found gmetad-%s-%s.conf with ports %d and %d', environment, service, ports.xml_port, ports.interactive_port) return result def get_gmetad_config(self): return self.env_service_dict.values() def get_gmetad_for(self, environment, service): def is_match(gmetad): env_match = (not environment) or (gmetad.environment in environment) service_match = (not service) or (gmetad.service in service) return env_match and service_match return filter(is_match, self.env_service_dict.values()) class GmetadData(): def __init__(self): self.data = dict() def update(self, gmetad): logger.info(" getting metrics for %s %s", gmetad.environment, gmetad.service) gmetad_metrics = gmetad.read_metrics() logger.info(" updated %d metrics for %s %s", len(gmetad_metrics), gmetad.environment, gmetad.service) self.data[(gmetad.environment, gmetad.service)] = gmetad_metrics return len(gmetad_metrics) def metrics_for(self, environment, service): try: return self.data[(environment, service)] except KeyError: return list() def metrics(self, gmetad): return self.metrics_for(gmetad.environment, gmetad.service) class GangliaPollThread(Thread): def run(self): while True: self.update_ganglia_data() def update_ganglia_data(self): gmetad_list = ganglia_config.get_gmetad_config() logger.info("Updating data from gmetad...") total_metrics = 0 for counter, gmetad in enumerate(gmetad_list): metrics_for_gmetad = ganglia_data.update(gmetad) total_metrics += metrics_for_gmetad logger.debug(" (%d/%d) updated %d metrics for %s %s", counter + 1, len(gmetad_list), metrics_for_gmetad, gmetad.environment, gmetad.service) time.sleep(0.2) logger.info("Done (found %d metrics)", total_metrics) if HEARTBEAT: os.system('/opt/alerta/sbin/alert-sender.py --heartbeat --origin ganglia-api --tag %s --quiet' % __version__) class ApiHandler(tornado.web.RequestHandler): def get(self): start = time.time() environment = self.get_arguments("environment") service = self.get_arguments("service") metric_list = self.get_arguments("metric") group_list = self.get_arguments("group") host_list = self.get_arguments("host") cluster_list = self.get_arguments("cluster") def emptyOrContains(list, value): return len(list) == 0 or value in list def is_match(metric): return (emptyOrContains(metric_list, metric.name) and emptyOrContains(group_list, metric.group) and emptyOrContains(host_list, metric.host.name) and emptyOrContains(cluster_list, metric.cluster.name)) gmetad_list = ganglia_config.get_gmetad_for(environment, service) metric_dicts = list() for gmetad in gmetad_list: metrics = ganglia_data.metrics(gmetad) for metric in filter(is_match, metrics): metric_dicts.append(metric.api_dict()) output_dict = { "metrics": metric_dicts, "status": "ok", "total": len(metric_dicts), "localTime": datetime.datetime.now().isoformat(), "time": "%.3f" % (time.time() - start) } self.write({"response": output_dict}) def main(): logger.info("Starting up Ganglia metric API v%s", __version__) # Write pid file if not already running if os.path.isfile(PIDFILE): pid = open(PIDFILE).read() try: os.kill(int(pid), 0) logging.error('Process with pid %s already exists, exiting', pid) sys.exit(1) except OSError: pass file(PIDFILE, 'w').write(str(os.getpid())) global ganglia_config ganglia_config = GangliaConfig() global ganglia_data ganglia_data = GmetadData() poll_thread = GangliaPollThread() poll_thread.daemon = True poll_thread.start() tornado.options.parse_command_line() application = tornado.web.Application([ (r"/ganglia/api/v1/metrics", ApiHandler), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main() From dieter at handshake.de Mon Jun 6 03:16:19 2016 From: dieter at handshake.de (dieter) Date: Mon, 06 Jun 2016 09:16:19 +0200 Subject: Spread a class over multiple files References: Message-ID: <87twh66b3w.fsf@handshake.de> Mark Summerfield writes: > Sometimes I want to spread a class over multiple files. When I run into such a use case, I use (multiple) inheritance -- with "mixin class"es. Each "mixin class" handles some important aspect and is only loosely coupled with maybe a common base class and the other aspects. The main application class integrates the mixin classes via inheritance -- when it needs to handle the respective aspect. Each mixin class can be implemented in its own file. From archana.sonavane at gmail.com Mon Jun 6 04:11:17 2016 From: archana.sonavane at gmail.com (Archana Sonavane) Date: Mon, 6 Jun 2016 01:11:17 -0700 (PDT) Subject: Urgent - Would like to see output of each block of python In-Reply-To: References: Message-ID: On Monday, June 6, 2016 at 12:35:55 PM UTC+5:30, Chris Rebert wrote: > On Sun, Jun 5, 2016 at 11:57 PM, Archana Sonavane > wrote: > > Hi Team, > > > > I don't have any idea about python scripts, i have ganglia tool python scripts. > > > > I would like see the output of each code block, could you please guide. > > > > The code as follows: > > > With regard to your Subject line, please don't attempt to mark posts > as "urgent". > See http://www.catb.org/esr/faqs/smart-questions.html#urgent > > Regards, > Chris Ok.. Sorry, next time will take care. From marko at pacujo.net Mon Jun 6 04:13:51 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 06 Jun 2016 11:13:51 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <87k2i483ok.fsf@elektro.pacujo.net> <1465149206.2672380.628512985.25519878@webmail.messagingengine.com> <87inxn788j.fsf@elektro.pacujo.net> <1465161386.2706373.628623897.408287CF@webmail.messagingengine.com> Message-ID: <87y46in39c.fsf@elektro.pacujo.net> Random832 : > On Sun, Jun 5, 2016, at 15:20, Marko Rauhamaa wrote: >> I say None is a wooden post, you say None is a puppy. >> >> What piece of Python code could put our dispute to rest? > > isinstance(None, object) Well, the wooden post is an object as are all puppies. It's bad enough to objectify sentient beings; I just don't have the heart to put a cute, fluffy puppy in the role of None. The fact that CPython does that could be considered animal cruelty. Marko From info at egenix.com Mon Jun 6 04:30:54 2016 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 6 Jun 2016 10:30:54 +0200 Subject: ANN: eGenix PyRun - One file Python Runtime 2.2.1 Message-ID: <575534BE.2010304@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix PyRun - One file Python Runtime Version 2.2.1 An easy-to-use single file relocatable Python run-time - available for Linux, Mac OS X and Unix platforms, with support for Python 2.6, 2.7, 3.4 and * now also for Python 3.5 * This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-PyRun-2.2.1-GA.html ________________________________________________________________________ INTRODUCTION eGenix PyRun is our open source, one file, no installation version of Python, making the distribution of a Python interpreter to run based scripts and applications to Unix based systems as simple as copying a single file. eGenix PyRun's executable only needs 11MB for Python 2 and 13MB for Python 3, but still supports most Python application and scripts - and it can be compressed to just 3-4MB using upx, if needed. Compared to a regular Python installation of typically 100MB on disk, eGenix PyRun is ideal for applications and scripts that need to be distributed to several target machines, client installations or customers. It makes "installing" Python on a Unix based system as simple as copying a single file. eGenix has been using eGenix PyRun internally in the mxODBC Connect Server product since 2008 with great success and decided to make it available as a stand-alone open-source product. We provide both the source archive to build your own eGenix PyRun, as well as pre-compiled binaries for Linux, FreeBSD and Mac OS X, as 32- and 64-bit versions. The binaries can be downloaded manually, or you can let our automatic install script install-pyrun take care of the installation: ./install-pyrun dir and you're done. Please see the product page for more details: http://www.egenix.com/products/python/PyRun/ ________________________________________________________________________ NEWS This minor level release of eGenix PyRun comes with the following enhancements: Enhancements / Changes ---------------------- * Fixed support for -u command line option with Python 3. Since this is used by pip since version 8.0, it also removes issues with pip. * Removed ensurepip package from PyRun since this only works with access to the bundled whl files. This is incompatible with the frozen nature of packages in PyRun. * Added support for setting the OpenSSL path to the Makefile and have it look in /usr/local/ssl before reverting to system dirs to make it easier to link against more recent builds of OpenSSL. * Linking against OpenSSL 1.0.2 now on Mac OS X for the precompiled pyrun binaries. You may have to set your shared linker path to point to the right OpenSSL version. install-pyrun Quick Install Enhancements --------------------------------------------- eGenix PyRun includes a shell script called install-pyrun, which greatly simplifies installation of PyRun. It works much like the virtualenv shell script used for creating new virtual environments (except that there's nothing virtual about PyRun environments). https://downloads.egenix.com/python/install-pyrun With the script, an eGenix PyRun installation is as simple as running: ./install-pyrun targetdir This will automatically detect the platform, download and install the right pyrun version into targetdir. We have updated this script since the last release: * Fixed install-pyrun to work with new PyPI package URL scheme (see https://bitbucket.org/pypa/pypi/issues/438/backwards-compatible-un-hashed-package). The options --pip-version=latest et al. should now work again. * Updated install-pyrun to default to eGenix PyRun 2.2.1 and its feature set. For a complete list of changes, please see the eGenix PyRun Changelog: http://www.egenix.com/products/python/PyRun/changelog.html ________________________________________________________________________ LICENSE eGenix PyRun is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use eGenix PyRun in both commercial and non-commercial settings without fee or charge. Please see our license page for more details: http://www.egenix.com/products/python/PyRun/license.html The package comes with full source code. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing eGenix PyRun can be found at: http://www.egenix.com/products/python/PyRun/ As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on other platforms, such as Solaris, AIX, HP-UX, etc. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about eGenix PyRun, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/python/PyRun/ About eGenix (http://www.egenix.com/): eGenix is a Python software project, consulting and product company delivering expert services and professional quality products for companies, Python users and developers. We specialize in database driven applications, large scale software designs and integration. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Jun 06 2016) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From antoon.pardon at rece.vub.ac.be Mon Jun 6 05:23:16 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 6 Jun 2016 11:23:16 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57554104.7030605@rece.vub.ac.be> Op 06-06-16 om 05:52 schreef Steven D'Aprano: > On Mon, 6 Jun 2016 03:42 am, Random832 wrote: > >> On Sun, Jun 5, 2016, at 02:37, Steven D'Aprano wrote: >>> No they don't. You are confusing the implementation with the programming >>> model. >>> >>> Following the assignment: >>> >>> x = 99 >>> >>> if you print(x), do you see something like "reference 0x12345"? No. >>> >>> Do you have to dereference that reference to get the value of x? No. >>> >>> At the Python level, the value of x is 99, not some invisible, >>> untouchable reference to 99. >> Sure, but that is the value of the object referenced by x, it is not a >> property of x itself. > You need to be clear about what you are referring to. > > x itself is the object 99. When we say "x + 1", we expect to get 100. x is > not some reference to 99, it is 99, just like Barrack Obama is not a > reference to the President of the United States, he is the POTUS. x is not the object 99. x is a variable that refers to an object that has the value 99. That python starts looking for that object and uses its value when your do arithmatics doesn't contradict that variables refer to objects. A reference is not pointer. When you use a reference parameter in Pascal, it behave like an ordinary parameter within the procedure block, you don't have to treat it like a pointer. From list at qtrac.plus.com Mon Jun 6 05:50:20 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 6 Jun 2016 02:50:20 -0700 (PDT) Subject: Trying to pass sys.argv as (int argc, char **argv) using ctypes Message-ID: <6a5f4f7b-37e1-42dd-b024-be3411659930@googlegroups.com> Hi, I have a setup roughly like this: import ctypes import sys Lib = ctypes.cdll.LoadLibrary("libthing") c_char_pp = ctypes.POINTER(ctypes.c_char_p) LibOpen = Lib.Open LibOpen.argtypes = (ctypes.c_int, # argc c_char_pp) # argv LibOpen.restype = ctypes.c_int argc = ctypes.c_int(len(sys.argv)) Args = ctypes.c_char_p * len(sys.argv) args = Args(*[ctypes.c_char_p(arg.encode("utf-8")) for arg in sys.argv]) argv = ctypes.pointer(args) LibOpen(argc, ctypes.byref(argv)) But when run it produces an error: ctypes.ArgumentError: argument 2: : expected LP_c_char_p instance instead of pointer to LP_c_char_p_Array_1 or this if I use LibOpen(argc, argv): ctypes.ArgumentError: argument 2: : expected LP_c_char_p instance instead of LP_c_char_p_Array_1 I understand what it is telling me; but I don't know or understand ctypes well enough to fix it. I guess I need to convert the array pointer to a char ** pointer? Can anyone tell me, or point me to info that would help? Thanks! From marko at pacujo.net Mon Jun 6 06:10:19 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 06 Jun 2016 13:10:19 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <57554104.7030605@rece.vub.ac.be> Message-ID: <87twh6mxv8.fsf@elektro.pacujo.net> Antoon Pardon : > A reference is not pointer. When you use a reference parameter in > Pascal, it behave like an ordinary parameter within the procedure > block, you don't have to treat it like a pointer. The word "reference" as used in the Python standards documentation is not the same as "reference parameter in Pascal." Even more confusing, we have "The Python Language Reference," which uses the word in yet a third meaning! Python's reference *is* indeed a pointer, even though there's usually no need to bring the word "pointer" in the discussion. A "reference", "pointer", "arrow", "leash", "morphism" etc are abstract thingies that connect a starting point to an endpoint. (No wonder Java, whose terminology involves references as well, sports a NullPointerException.) Marko From rosuav at gmail.com Mon Jun 6 07:57:49 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jun 2016 21:57:49 +1000 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> Message-ID: On Mon, Jun 6, 2016 at 2:08 PM, Random832 wrote: > My statement was that if two variables can be bound to the same object, > then variables *cannot* contain objects. The object has to exist > somewhere, and this requirement means that the variables cannot be where > the objects live. Then the problem is with your notion of containment. Have a think about TARDISes, and the place the Narnians got to after the Last Battle, and Bags of Holding, and various other related concepts. It's perfectly possible for something to be 'inside' more than one thing at once. ChrisA From bc at freeuk.com Mon Jun 6 08:35:57 2016 From: bc at freeuk.com (BartC) Date: Mon, 6 Jun 2016 13:35:57 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/06/2016 07:37, Steven D'Aprano wrote: > On Sun, 5 Jun 2016 01:17 pm, Lawrence D?Oliveiro wrote: > >> On Saturday, June 4, 2016 at 3:55:12 AM UTC+12, Matt Wheeler wrote: >>> It's best to think of them as names, rather than variables, as names in >>> python don't behave quite how you'll expect variables to if you're coming >>> from some other languages. >> >> I have made heavy use of Python as well as many other languages, and I >> don?t know what you mean. What ?other languages? are you thinking of? >> >> Are variables like little boxes? Yes they are. > > That's *exactly* what variables in Python are not like. People can imagine a box around a variable name if they like. The confusion might arise when they think the value attached to the name is in the same box. But often, for variables holding or referring to simple scalar values, it doesn't matter. > >> But they are all the same >> size, while objects may be large (even very large) or small. That is why >> variables hold, not objects, but references to objects. > > No they don't. You are confusing the implementation with the programming > model. > > Following the assignment: > > x = 99 > > if you print(x), do you see something like "reference 0x12345"? No. Nearly every high level language will perform an automatic dereference in such cases, between the written name of the variable (that sometimes corresponds to its /address/), and its value (for example, the contents of that address). In Python there might well be a double dereference, from name to location, which contains an object reference, and from the object reference to the value that is printed. While Python can give you access to the object reference rather than the object value, AFAIK you can't get the location where that object reference is stored for that variable. All you have is the name. So for Python it makes more sense to have two boxes, one for the name, and another for the object value. With an arrow between the two. (Among other things, this allows same object to be shared between several variables: multiple boxed variable names all pointing to the same object box.) But again, in the case of simple, immutable types, and where the variable always keeps the same type as is usually the case, there is no real problem in showing "x" and "99" in the same box, or "99" in the box and "x" immediately outside: x:[99] instead of: x:[0x12345] -> 0x12345:[99] -- Bartc From paul.nospam at rudin.co.uk Mon Jun 6 08:36:32 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 06 Jun 2016 13:36:32 +0100 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <57523cd3$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twh6335b.fsf@rudin.co.uk> Nobody writes: > On Sat, 04 Jun 2016 12:28:33 +1000, Steven D'Aprano wrote: > >>> OTOH, a Free software licence is unilateral; the author grants the user >>> certain rights, with the user providing nothing in return. >> >> That's not the case with the GPL. >> >> The GPL requires the user (not the end-user, who merely avails themselves >> of their common law right to run the software, but the developer user, who >> copies, distributes and modifies the code) to do certain things in return >> for the right to copy, distribute and modify the code: > > The GPL places limitations on the granted licence. That isn't the same > thing as requiring the distributor to do something "in return". > The distributor grants the licence. > This is why the (relatively few) cases where GPL infringements have > resulted in litigation, the legal basis of the litigation is copyright > infringement, not breach of contract. Right, but the defence is that the licence grants permission to use; so that's where the law if contract comes into it. You have to figure out whether the use in question falls within the licence terms. So if someone brings an action for copyright infringement you can argue at least some of: 1. Copyright doesn't subsist in the copied material. 2. You didn't copy it. 3. One of the legal defences (fair use etc.) applies. 4. You had the permission of the copyright owner (i.e. a licence to copy in these circumstances). In the last case we're essentially into contract law. From michael.selik at gmail.com Mon Jun 6 09:03:20 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 06 Jun 2016 13:03:20 +0000 Subject: Would like to see python script output In-Reply-To: <4a1f7cb5-2d61-4f4b-a883-bd1f19c74f87@googlegroups.com> References: <4a1f7cb5-2d61-4f4b-a883-bd1f19c74f87@googlegroups.com> Message-ID: On Mon, Jun 6, 2016 at 3:12 AM Archana Sonavane wrote: > I have ganglia python script, i would like to see output of each code > block. > > Could you please guide. I don't have any idea about python. > Do you know how to run a Python script? Have you read through the Python tutorial? https://docs.python.org/3/tutorial/ From michael.selik at gmail.com Mon Jun 6 09:17:04 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 06 Jun 2016 13:17:04 +0000 Subject: Anyone know a donation app codebase? In-Reply-To: <851t4b4exk.fsf@benfinney.id.au> References: <8560to4qhz.fsf@benfinney.id.au> <1973b5af-79c5-4bf5-a13f-4532e1f16a71@googlegroups.com> <851t4b4exk.fsf@benfinney.id.au> Message-ID: On Sun, Jun 5, 2016 at 3:26 PM Ben Finney wrote: > Albert writes: > > > Thank you for your answer Ben, > > You're welcome. Please note that top-posting is poor etiquette for > discussions; instead, interleave your response like a written dialogue. > See . > > > That is not exactly what I am looking for. I am interested in knowing > > if there are any python (django, flask, etc) opensource projects for > > managing donations > > Again, PyPI is the place to search > https://pypi.python.org/pypi?:action=search&term=django%20donation&submit=search > >. > I tried the Google search engine. Looking up the phrase "python managing donations catarse" the 2nd search result was this a website which appears to list several packages in different programming languages. http://seedingfactory.com/index.html%3Fp=634.html From michael.selik at gmail.com Mon Jun 6 09:18:31 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 06 Jun 2016 13:18:31 +0000 Subject: Taking two and more data frames and extracting data on unique keys in python In-Reply-To: References: Message-ID: On Sun, Jun 5, 2016 at 7:05 AM Danish Hussain wrote: > Please me know if clarification is needed. > Could you clarify what your question is? Did you encounter an error while coding the solution? From chris at simplistix.co.uk Mon Jun 6 09:25:50 2016 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 6 Jun 2016 08:25:50 -0500 Subject: errorhandler 2.0.0 Released! Message-ID: <286b8a23-0df4-1081-b477-7d9ada03f566@simplistix.co.uk> Hi All, errorhandler is a tiny but useful logging handler for the python logging framework. It lets you tell when logging above a certain level has occurred, even if it's not in code you can control. I'm pleased to announce the release of errorhandler 2.0.0 featuring the following: - Support for Python 3 - Documentation on Read The Docs - Continuous testing using Travis CI - Code coverage reporting through Coveralls 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/errorhandler Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pavel at schon.cz Mon Jun 6 09:42:34 2016 From: pavel at schon.cz (Pavel S) Date: Mon, 6 Jun 2016 06:42:34 -0700 (PDT) Subject: errorhandler 2.0.0 Released! In-Reply-To: References: <286b8a23-0df4-1081-b477-7d9ada03f566@simplistix.co.uk> Message-ID: Hi, can you explain, why is the attribute 'fired' class-level and not instance-level? There must be good reason for modifying class attribute from instance. Dne pond?l? 6. ?ervna 2016 15:26:08 UTC+2 Chris Withers napsal(a): > Hi All, > > errorhandler is a tiny but useful logging handler for the python logging > framework. It lets you tell when logging above a certain level has > occurred, even if it's not in code you can control. > > I'm pleased to announce the release of errorhandler 2.0.0 featuring the > following: > > - Support for Python 3 > > - Documentation on Read The Docs > > - Continuous testing using Travis CI > > - Code coverage reporting through Coveralls > > 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/errorhandler > > Any questions, please do ask on the Testing in Python list or on the > Simplistix open source mailing list... > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk From eryksun at gmail.com Mon Jun 6 09:47:11 2016 From: eryksun at gmail.com (eryk sun) Date: Mon, 6 Jun 2016 13:47:11 +0000 Subject: Trying to pass sys.argv as (int argc, char **argv) using ctypes In-Reply-To: <6a5f4f7b-37e1-42dd-b024-be3411659930@googlegroups.com> References: <6a5f4f7b-37e1-42dd-b024-be3411659930@googlegroups.com> Message-ID: On Mon, Jun 6, 2016 at 9:50 AM, Mark Summerfield wrote: > > Lib = ctypes.cdll.LoadLibrary("libthing") Use ctypes.CDLL('libthing'). It's simpler, plus it's the only way to pass the handle, mode, and use_errno parameters if you need them. > LibOpen.restype = ctypes.c_int This line isn't required because c_int is the default result type. > argc = ctypes.c_int(len(sys.argv)) ctypes automatically converts integer arguments that are passed by value. You only need to create a c_int when you're passing by reference. > Args = ctypes.c_char_p * len(sys.argv) The argv array in ANSI C should have length `argc + 1`. There's a final null terminator, even though it's redundant given the argc count. > args = Args(*[ctypes.c_char_p(arg.encode("utf-8")) > for arg in sys.argv]) There's no need to create a list just to unpack it. You can use a for loop to populate the array directly. Also, you don't have to manually instantiate c_char_p instances when storing the elements of a c_char_p array; the base type's getfunc will convert Python byte strings. Also, since the function signature isn't `const char **`, you should use ctypes.create_string_buffer just in case the function expects to be able to modify the argv strings. This requires switching from using c_char_p to a more generic POINTER(c_char). > argv = ctypes.pointer(args) > LibOpen(argc, ctypes.byref(argv)) C array arguments are passed as a pointer to the first element. You don't have to manually create a pointer. And if you do, certainly you shouldn't pass it by reference. That mistakenly passes a pointer to the pointer to the first element of the argv array (which is a pointer to the first character in the first string argument). Naturally you get the following error: > expected LP_c_char_p instance instead of pointer to LP_c_char_p_Array_1 Due to limitations in ctypes you also get the following error when you pass the pointer by value: > expected LP_c_char_p instance instead of LP_c_char_p_Array_1 Only passing the array directly is special cased for this to work. Try the following code: import sys import ctypes lib = ctypes.CDLL('libthing') LP_c_char = ctypes.POINTER(ctypes.c_char) LP_LP_c_char = ctypes.POINTER(LP_c_char) lib.LibOpen.argtypes = (ctypes.c_int, # argc LP_LP_c_char) # argv argc = len(sys.argv) argv = (LP_c_char * (argc + 1))() for i, arg in enumerate(sys.argv): enc_arg = arg.encode('utf-8') argv[i] = ctypes.create_string_buffer(enc_arg) lib.LibOpen(argc, argv) From random832 at fastmail.com Mon Jun 6 09:57:01 2016 From: random832 at fastmail.com (Random832) Date: Mon, 06 Jun 2016 09:57:01 -0400 Subject: Operator precedence problem In-Reply-To: <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> Message-ID: <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> On Mon, Jun 6, 2016, at 01:46, Lawrence D?Oliveiro wrote: > On Monday, June 6, 2016 at 4:06:20 AM UTC+12, Uri Even-Chen wrote: > > Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 > > + 5, without parentheses. > > That leads to the code equivalent of > . Okay, can we settle on, as a principle, "the basic arithmetic operators (not to include **) are the only ones whose precedence can be presumed to be obvious to all readers, and other expressions may/should have parentheses to make it more clear, even when not strictly necessary to the meaning of the expression"? Sure, it's obvious to _me_ that << and >> have higher precedence than & and |, and that "and" has a higher precedence than "or", but can I assume the other people know this? And I don't know offhand the relative precedence of non-conceptually-related groups of operators, except that I'm pretty sure "and" and "or" have very low precedence. [To keep this on-topic, let's assume that this discussion has a goal of getting something along the lines of "always/sometimes/never use "unnecessary" parentheses" into PEP7/PEP8. Speaking of, did you know that C has lower precedence for the bitwise operators &^| than for comparisons? That was something that tripped me up for a very long time and undermined my confidence as to other aspects of the bitwise operators] From list at qtrac.plus.com Mon Jun 6 10:08:23 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 6 Jun 2016 07:08:23 -0700 (PDT) Subject: Trying to pass sys.argv as (int argc, char **argv) using ctypes In-Reply-To: References: <6a5f4f7b-37e1-42dd-b024-be3411659930@googlegroups.com> Message-ID: Thanks, that works! And also thanks for the excellent explanations of each part. From marko at pacujo.net Mon Jun 6 10:22:56 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 06 Jun 2016 17:22:56 +0300 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> Message-ID: <87inxmmm67.fsf@elektro.pacujo.net> Random832 : > Sure, it's obvious to _me_ that << and >> have higher precedence than & > and |, and that "and" has a higher precedence than "or", but can I > assume the other people know this? No need to assume. Just read the spec: lambda Lambda expression if ? else Conditional expression or Boolean OR and Boolean AND not x Boolean NOT in, not in, is, is not, <, <=, >, >=, !=, == Comparisons, including membership tests and identity tests | Bitwise OR ^ Bitwise XOR & Bitwise AND <<, >> Shifts +, - Addition and subtraction *, @, /, //, % Multiplication, matrix multiplication division, remainder [5] +x, -x, ~x Positive, negative, bitwise NOT ** Exponentiation [6] await x Await expression x[index], x[index:index], x(arguments...), x.attribute Subscription, slicing, call, attribute reference (expressions...), [expressions...], {key: value...}, {expressions...} Binding or tuple display, list display, dictionary display, set display > [To keep this on-topic, let's assume that this discussion has a goal of > getting something along the lines of "always/sometimes/never use > "unnecessary" parentheses" into PEP7/PEP8. Speaking of, did you know > that C has lower precedence for the bitwise operators &^| than for > comparisons? That was something that tripped me up for a very long time > and undermined my confidence as to other aspects of the bitwise > operators] Yes, I happened to know that. Python's the same way. However, no need to memorize. It's all there in the spec. Same as with stdlib functions. Keep checking the spec. You *can* assume other people have read the spec. Even more importantly, you can assume the Python interpreter complies with the spec. Marko From jfine2358 at gmail.com Mon Jun 6 10:32:35 2016 From: jfine2358 at gmail.com (jfine2358 at gmail.com) Date: Mon, 6 Jun 2016 07:32:35 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: Message-ID: On Friday, June 3, 2016 at 3:20:42 PM UTC+1, Sayth Renshaw wrote: > pyqFiles = [] > for filename in sorted(file_list): > pyqFiles = pyqFiles.append(pq(filename=my_dir + filename)) This won't end well. The return value from [].append(...) is None. >>> [].append(0) is None True The first time through the loop pqFiles is set to the return value of pqFile.append(...), which is None. The second time through, you'll get: AttributeError: 'NoneType' object has no attribute 'append' -- Jonathan From random832 at fastmail.com Mon Jun 6 10:35:47 2016 From: random832 at fastmail.com (Random832) Date: Mon, 06 Jun 2016 10:35:47 -0400 Subject: Operator precedence problem In-Reply-To: <87inxmmm67.fsf@elektro.pacujo.net> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> Message-ID: <1465223747.1077208.629311025.666B5AF8@webmail.messagingengine.com> On Mon, Jun 6, 2016, at 10:22, Marko Rauhamaa wrote: > You *can* assume other people have read the spec. Even more importantly, > you can assume the Python interpreter complies with the spec. I can assume the python interpreter will accept tabs as indents too, that doesn't make it good style. Requiring people to constantly flip between my code and the language reference to understand it is also not good style. From grant.b.edwards at gmail.com Mon Jun 6 10:42:02 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 6 Jun 2016 14:42:02 +0000 (UTC) Subject: OT: limit number of connections from browser to my server? References: Message-ID: On 2016-05-16, Grant Edwards wrote: [...] > Is there any way to limit the number of connections a browser uses to > download a web page? Browser writers seems to assume that all https > servers are massively parallel server farms with hardware crypto > support. In case anybody is still wondering about this... Various experiments have shown that if you try limit the number of connections, browsers will fall over and not load the page completely. You have to allow as many parallel connecitons as some addle-headed browser devleoper wants to open -- no matter how counter-productive it is. I added chunked transfer encoding support to my web server so that all connections can be kept open and re-used. I also added a sepearte thread to handle SSL handshaking at a lower priority so that opening a new SSL connection doesn't block servicing requests on already open connections. Warm page loads are now around 1.8 seconds for all three browsers (IE, Chrome, Firefox -- I don't have access to Safari). On IE and Chrome, the above changes reduced cold page load times from 10-20 seconds to around 4.5 seconds. Apparently, IE and Chrome are sane enough to send reuqests on any idle idle connection. So, the entire page loads via the first connection once its SSL handshake completes (which takes 3.5 seconds). They still insist on opening 4-6 connections (a process which continues for 10-15 seconds after the page has finished loading), but only the first one actually gets used for the initial page load. Cold load time for Firefox is still 20 seconds. Firefox seems to be unable to pull its head out of it's arse and will sit there for 15 seconds waiting for that 6th connection to open while ignoring the five idle connections it already has open. The only thing I can think of to help cold page loads with Firefox is to reduce the number of requests it has to send: 1) Pre-process CSS and HTML files to embed images as base64 data instead of having the browser fetch them separately. 2) Use preprocessing or server-side includes so that Javascript is embedded in the main page HTML instead of being fetched separately. There are still 1-2 files that for logistical reasons I want to keep separate, so perhaps adding Cache-Control headers to tell the browser it can cache those files will help in cases where there are no open connections but it's not the absolute first time the browser has seen the device. If I could get one particular file (jQuery-min) to be cached, that would reduce warm page loads by 60% also. -- Grant Edwards grant.b.edwards Yow! I have seen these EGG at EXTENDERS in my Supermarket gmail.com ... I have read the INSTRUCTIONS ... From marko at pacujo.net Mon Jun 6 10:55:25 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 06 Jun 2016 17:55:25 +0300 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> <1465223747.1077208.629311025.666B5AF8@webmail.messagingengine.com> Message-ID: <87eg8amko2.fsf@elektro.pacujo.net> Random832 : > On Mon, Jun 6, 2016, at 10:22, Marko Rauhamaa wrote: >> You *can* assume other people have read the spec. Even more >> importantly, you can assume the Python interpreter complies with the >> spec. > > I can assume the python interpreter will accept tabs as indents too, > that doesn't make it good style. > > Requiring people to constantly flip between my code and the language > reference to understand it is also not good style. I cannot guess at people's familiarity with the spec. In fact, there's nobody in the world who masters the whole standard library, for example. That's not a reason to start avoiding parts of the stdlib functions. BTW, whenever I'm programming Python, I have the stdlib refererence open next to the editor. Believe me, I keep consulting the spec all the time. Operator precedence is a small table, of course, and it is not bad style to assume familiarity with it. Marko From jon+usenet at unequivocal.co.uk Mon Jun 6 11:03:05 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 6 Jun 2016 15:03:05 -0000 (UTC) Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> Message-ID: On 2016-06-06, Marko Rauhamaa wrote: > Random832 : >> Sure, it's obvious to _me_ that << and >> have higher precedence than & >> and |, and that "and" has a higher precedence than "or", but can I >> assume the other people know this? > > No need to assume. Just read the spec: The spec tells you the overlap between the set of all people who will ever read your code and the set of people who have memorised the entire list of operator precedences in the spec? That's one impressive spec. > You *can* assume other people have read the spec. Even more importantly, > you can assume the Python interpreter complies with the spec. Obviously the latter is true (or at least, it's true except when it's false). The former however is not true. You should put brackets around expressions when it's at all unclear what the meaning is. You could think of them a bit like "active comments" I suppose. From marko at pacujo.net Mon Jun 6 11:22:42 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 06 Jun 2016 18:22:42 +0300 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> Message-ID: <87a8iymjel.fsf@elektro.pacujo.net> Jon Ribbens : > On 2016-06-06, Marko Rauhamaa wrote: >> You *can* assume other people have read the spec. Even more >> importantly, you can assume the Python interpreter complies with the >> spec. > > Obviously the latter is true (or at least, it's true except when it's > false). The former however is not true. Well, of course nobody knows the whole spec. However, you should write your code assuming they do. Different people have different gaps in their knowledge: * Somebody might not be aware of chained comparisons: a < b < c * Somebody might not know of the "else" branch of a "for" statement. * Somebody might not know of the if-else expression: a if b else c However, there's no need to avoid those facilities that are there for people to use them. What people are unclear about they can check in the spec, which is readily available. > You should put brackets around expressions when it's at all unclear > what the meaning is. You could think of them a bit like "active > comments" I suppose. Your code should keep noise to the minimum. Marko From jon+usenet at unequivocal.co.uk Mon Jun 6 11:27:47 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 6 Jun 2016 15:27:47 -0000 (UTC) Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> <87a8iymjel.fsf@elektro.pacujo.net> Message-ID: On 2016-06-06, Marko Rauhamaa wrote: > Jon Ribbens : >> On 2016-06-06, Marko Rauhamaa wrote: >>> You *can* assume other people have read the spec. Even more >>> importantly, you can assume the Python interpreter complies with the >>> spec. >> >> Obviously the latter is true (or at least, it's true except when it's >> false). The former however is not true. > > Well, of course nobody knows the whole spec. However, you should write > your code assuming they do. That sounds like bad advice to me I'm afraid. Assume they're moderately competent, sure. Assume they know 100% of the entire spec in all its detail? That's an assumption that will be false pretty much 100% of the time. >> You should put brackets around expressions when it's at all unclear >> what the meaning is. You could think of them a bit like "active >> comments" I suppose. > > Your code should keep noise to the minimum. Sensible and beneficial comments aren't "noise". From steve at pearwood.info Mon Jun 6 11:42:42 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jun 2016 01:42:42 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> Message-ID: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> On Mon, 6 Jun 2016 02:08 pm, Random832 wrote: > On Sun, Jun 5, 2016, at 23:52, Steven D'Aprano wrote: >> Certainly not. x = y = 999 is required to bind the same object to x and >> y. > > My statement was that if two variables can be bound to the same object, > then variables *cannot* contain objects. The object has to exist > somewhere, I could dispute that assertion, e.g. consider what happens when you simulate a Python interpreter in your brain. What is the location of the objects then? As best as we can tell from neuroscience, memories are distributed across fairly large swaths of neurons. But that's not the point. Even if you were right that objects must exist at a single well-defined location, that is strictly irrelevant. That's implementation, not interface. There is nothing in the specification of the Python virtual machine and the execution model that requires objects have a single location. That's just the way they happen to be easy to write on current generation computers. > and this requirement means that the variables cannot be where > the objects live. I don't care. That's just implementation. There is nothing in the Python programming language that says "x = 999" makes x an indirect reference to 999. The very thought is absurd. I have tried to see things from your perspective. I completely agree that, at the implementation level, Python variables are implemented as references (in CPython, pointers) to objects. We all agree on that. Yay! We have partial agreement! But it really, truly is absurd to insist that AT THE PYTHON LEVEL variables are references. That's as foolish as insisting that the President of the United States is two words with eleven letters, not a man. Surely you can acknowledge that the language we use to explain things will depend on the level of physical phenomena we are looking at? If we can't agree on that, then there's no point in continuing this conversation. At the Python virtual machine level, x is the object 999. This is the most important level, because we're actually talking about Python code. The whole point of this is to understand what the Python VM does, so we can reason about code. Every thing else is, in general, obfuscation, to a lesser or greater degree. At the C implementation level, x is an entry in a hash table, a pointer pointing at an object in the heap. Occasionally it is useful to bring the discussion down to this level, but not often. At the assembly language level, x is probably a 32-bit or 64-bit word, depending on whether you have a 32-bit or 64-bit build. Assigning to a variable is a matter of copying memory from one location to another. At a lower level still (machine code? microcode?), we don't copy memory, we flip bits. x will be a series of bits. There's not much interesting to say at this level: whether x is 999 or a HTTPServer object or None, it's still just a series of bits. At the hardware level, considered as a DRAM unit (other types of memory use different implementations), x is a set of microscopic capacitors holding tiny electric charges representing either a "high" or "low" charge, i.e. bits. At the hardware level below that, we have to start talking about the properties of impure silicon, electrons in atomic shells, so-called electron holes, etc. Given x = 999, x will be any of a large number of sets of electron distributions, involving millions(?) of electrons. A few thousand more or less in any one specific chunk of silicon will make no difference: there are many, many physical states that x could be. And below that, we start talking about quantum probability functions, and surely we can agree that it is absurd to say that Python variables are really quantum probability functions! Can you at least met me there? Can we agree that, while it is absolutely true and correct that Python variables are really implemented as quantum waves, this fact is of absolutely no use to anyone trying to understand what a snippet of Python code does? >> If your variable x were a reference, then we would expect type(x) to >> return >> something like "Reference", but it doesn't, it returns int. > > No we would not. You are once again inferring meaning that people's > statements don't actually carry. In the plain English meaning of the words, if is an int, then it behaves as an int, and if you use introspection on it, it will look like an int. If x is a string, then it similarly behaves as, and looks like, a string. So if x is a reference, what should it behave as? A wheelbarrow? I cannot help that you want to describe x as being a reference while denying that it behaves as a reference or can be introspected as looking like a reference. You could equally say it is really, actually a set of bits, or charges in an integrated circuit, or electrons in atomic shells. -- Steven From rosuav at gmail.com Mon Jun 6 11:57:34 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jun 2016 01:57:34 +1000 Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> <87a8iymjel.fsf@elektro.pacujo.net> Message-ID: On Tue, Jun 7, 2016 at 1:27 AM, Jon Ribbens wrote: >>> You should put brackets around expressions when it's at all unclear >>> what the meaning is. You could think of them a bit like "active >>> comments" I suppose. >> >> Your code should keep noise to the minimum. > > Sensible and beneficial comments aren't "noise". In that case, please never insult the intelligence of your future readers by including any of these parentheses: x = 1 + (2 * 3) value = 77 if (x % 2) else (70*7) And if your readers have to figure out what 3**3**3 is interpreted as, there should be an interactive interpreter around. Or here - try something cute: >>> 2**2**-1 ChrisA From steve at pearwood.info Mon Jun 6 11:59:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jun 2016 01:59:52 +1000 Subject: Don't put your software in the public domain References: <574ef865$0$1618$c3e8da3$5496439d@news.astraweb.com> <5751539f$0$1586$c3e8da3$5496439d@news.astraweb.com> <57523cd3$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57559dfa$0$1614$c3e8da3$5496439d@news.astraweb.com> On Mon, 6 Jun 2016 03:54 pm, Nobody wrote: > On Sat, 04 Jun 2016 12:28:33 +1000, Steven D'Aprano wrote: > >>> OTOH, a Free software licence is unilateral; the author grants the user >>> certain rights, with the user providing nothing in return. >> >> That's not the case with the GPL. >> >> The GPL requires the user (not the end-user, who merely avails themselves >> of their common law right to run the software, but the developer user, >> who copies, distributes and modifies the code) to do certain things in >> return for the right to copy, distribute and modify the code: > > The GPL places limitations on the granted licence. That isn't the same > thing as requiring the distributor to do something "in return". Read the GPL. I already linked to it. The GPL explicitly and implicitly requires that the distributor do certain things, and avoid doing others. It implicitly requires that the distribute give up their right to keep the code a trade secret. (It cannot be a trade secret if it is released under a FOSS licence.) It explicitly requires the distributor to make the source code available under the GPL. All these things are sufficient to make the GPL a contract. All this is covered in my previous post that links to a paper on the enforceability of the GPL, written by an actual lawyer. If you haven't read that, please don't argue until you do. Its all covered in the paper. > This is why the (relatively few) cases where GPL infringements have > resulted in litigation, the legal basis of the litigation is copyright > infringement, not breach of contract. That's factually incorrect. The only case (that I know of) where the GPL was actually fought out in front of a judge was in Germany, and it was treated as a breach of contract. The GPL is legally a contract, and if the distributor fails to live up to their end of the contract (namely, the requirement to publish their program under the GPL), then they have no right to distribute, copy or modify the GPLed code. If they do, then they are infringing copyright. Again, this is all covered in the paper. -- Steven From jon+usenet at unequivocal.co.uk Mon Jun 6 12:05:09 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 6 Jun 2016 16:05:09 -0000 (UTC) Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> <87a8iymjel.fsf@elektro.pacujo.net> Message-ID: On 2016-06-06, Chris Angelico wrote: > On Tue, Jun 7, 2016 at 1:27 AM, Jon Ribbens > wrote: >>>> You should put brackets around expressions when it's at all unclear >>>> what the meaning is. You could think of them a bit like "active >>>> comments" I suppose. >>> >>> Your code should keep noise to the minimum. >> >> Sensible and beneficial comments aren't "noise". > > In that case, please never insult the intelligence of your future > readers by including any of these parentheses: > > x = 1 + (2 * 3) I'm not sure what your point is. Yes, obviously you can take anything to ridiculous extremes - that's why I said "sensible". > value = 77 if (x % 2) else (70*7) I'm not convinced that one isn't actually a good idea. It does seem to aid the readability (especially if you space '70 * 7' properly). If the expressions were any more complex then it would be even more likely to be a good idea. > And if your readers have to figure out what 3**3**3 is interpreted as, > there should be an interactive interpreter around. Or here - try > something cute: > >>>> 2**2**-1 I can't tell now if you're agreeing with me or disagreeing, because you started out sounding like you were disagreeing but then provided an example that helps prove my point. From steve at pearwood.info Mon Jun 6 12:19:47 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jun 2016 02:19:47 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> On Mon, 6 Jun 2016 04:37 pm, Gregory Ewing wrote: > Steven D'Aprano wrote: >> The *name* "x" is an entity which is bound to (i.e. a reference to) the >> object 99, in some specific namespace, at some specific time. The name >> itself is an English word consisting of a single letter, "x". > > This is one reason why the term "name" is not good subsitute > for the term "variable". The string "x" is not the same thing > as the variable x, a fact that's obscured if you call the > variable a "name". I never said that the string "x" is the same thing as the variable x. I made it clear, well I thought it was clear, that the *implementation* of names in CPython uses string keys in dictionaries, but that's not what a name is. A name is just a abstract, human-readable label. We prefer meaningful names like "x" or "number_of_pages", but an interpreter could use 64-bit cryptographic hashes or UUIDs or whatever it likes. (A Python interpreter would have to find some way to map those UUIDs back to human readable strings, so that we can call vars() or globals() or equivalent and see the names we expect. But another language need not do that.) > A better analogy along the presidential line would be the > name "President of the United States". That name can refer > to different people at different times, so there must be > some piece of state in the world that records the association > between the character string "President of the United States" > and the person who currently holds that office. How ironic, after telling me off for saying that variables were strings (which I didn't do), you're now talking about the POTUS being a "character string". You are right that there must be some piece of state that associates the label "POTUS" or "Barack Obama" with the man. That's the essential feature of a name binding. In human languages, we generally use words for labels. (Sometimes we use numbers, as in "Prisoner 23848".) But we also need to distinguish between talking about the POTUS and talking about the *label* "POTUS", and the usual way of doing that in English is as I just did, but putting it in quotation marks, or referring to it as "the word POTUS", or some other equivalent phrase. > It's that piece of state that the OP is calling a "box". > I don't know what form it actually takes, probably an > official piece of paper somewhere, which may well be > kept in a box. But the box doesn't contain Barack Obama > himself, it only contains something that refers to him. Yes. And? Two points: (1) When we refer to Barack Obama, we're not referring to his birth certificate, and when we refer to the POTUS, we're not referring to this hypothetical box where the official piece of paper resides. We're referring to the man. Just as when we refer to the x in "x = 999", we mean 999, not some analogue to a birth certificate or certificate of being president. (2) The "variables are like boxes" metaphor applies to static languages like C and Pascal, where the compiler has knowledge of what variables will exist. Such languages allocate space for the variables at compile time, usually using fixed memory locations on the stack, or in registers, but rarely dynamically in the heap. That's exactly what Python doesn't do. -- Steven From rosuav at gmail.com Mon Jun 6 12:21:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jun 2016 02:21:35 +1000 Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> <87a8iymjel.fsf@elektro.pacujo.net> Message-ID: On Tue, Jun 7, 2016 at 2:05 AM, Jon Ribbens wrote: > On 2016-06-06, Chris Angelico wrote: >> On Tue, Jun 7, 2016 at 1:27 AM, Jon Ribbens >> wrote: >>>>> You should put brackets around expressions when it's at all unclear >>>>> what the meaning is. You could think of them a bit like "active >>>>> comments" I suppose. >>>> >>>> Your code should keep noise to the minimum. >>> >>> Sensible and beneficial comments aren't "noise". >> >> In that case, please never insult the intelligence of your future >> readers by including any of these parentheses: >> >> x = 1 + (2 * 3) > > I'm not sure what your point is. Yes, obviously you can take anything > to ridiculous extremes - that's why I said "sensible". Earlier in this thread, it was suggested that parens always be used, even for this kind of example. >> value = 77 if (x % 2) else (70*7) > > I'm not convinced that one isn't actually a good idea. It does seem > to aid the readability (especially if you space '70 * 7' properly). > If the expressions were any more complex then it would be even more > likely to be a good idea. Hmm, I still think not. But if you want the parens, at least acknowledge that they're not to enforce/remind of operator precedence. >> And if your readers have to figure out what 3**3**3 is interpreted as, >> there should be an interactive interpreter around. Or here - try >> something cute: >> >>>>> 2**2**-1 > > I can't tell now if you're agreeing with me or disagreeing, because > you started out sounding like you were disagreeing but then provided > an example that helps prove my point. My point is that if you're not sure, you grab interactive Python and give it a quick whirl. Usually easier AND quicker than the alternatives. ChrisA From __peter__ at web.de Mon Jun 6 12:38:31 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 06 Jun 2016 18:38:31 +0200 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Random832 : > >> Sure, it's obvious to _me_ that << and >> have higher precedence than & >> and |, and that "and" has a higher precedence than "or", but can I >> assume the other people know this? > > No need to assume. Just read the spec: > > lambda Lambda expression > if ? else Conditional expression > or Boolean OR > and Boolean AND > not x Boolean NOT > in, not in, is, is not, <, <=, >, >=, !=, == > Comparisons, including membership tests and identity > tests > | Bitwise OR > ^ Bitwise XOR > & Bitwise AND > <<, >> Shifts > +, - Addition and subtraction > *, @, /, //, % Multiplication, matrix multiplication division, > remainder [5] > +x, -x, ~x Positive, negative, bitwise NOT > ** Exponentiation [6] > await x Await expression > x[index], x[index:index], x(arguments...), x.attribute > Subscription, slicing, call, attribute reference > (expressions...), [expressions...], {key: value...}, {expressions...} > Binding or tuple display, list display, dictionary > display, set display > > or-precedence> > >> [To keep this on-topic, let's assume that this discussion has a goal of >> getting something along the lines of "always/sometimes/never use >> "unnecessary" parentheses" into PEP7/PEP8. Speaking of, did you know >> that C has lower precedence for the bitwise operators &^| than for >> comparisons? That was something that tripped me up for a very long time >> and undermined my confidence as to other aspects of the bitwise >> operators] > > Yes, I happened to know that. Python's the same way. It's not. From the page you linked to: """ Unlike C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. """ > However, no need to memorize. It's all there in the spec. Same as with > stdlib functions. Keep checking the spec. Nah, I usually try it in the interactive interpreter: $ python3 -c 'print(1 < 3 & 2)' True $ echo 'main() { printf("%d\n", 1 < 3 & 2); }' | tcc -run - 0 (tcc invocation courtesy of google/stackoverflow) > You *can* assume other people have read the spec. Even more importantly, > you can assume the Python interpreter complies with the spec. From grant.b.edwards at gmail.com Mon Jun 6 12:51:52 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 6 Jun 2016 16:51:52 +0000 (UTC) Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> <87a8iymjel.fsf@elektro.pacujo.net> Message-ID: On 2016-06-06, Chris Angelico wrote: > On Tue, Jun 7, 2016 at 1:27 AM, Jon Ribbens > wrote: >>>> You should put brackets around expressions when it's at all >>>> unclear what the meaning is. You could think of them a bit like >>>> "active comments" I suppose. >>> >>> Your code should keep noise to the minimum. >> >> Sensible and beneficial comments aren't "noise". > > In that case, please never insult the intelligence of your future > readers by including any of these parentheses: > > x = 1 + (2 * 3) > value = 77 if (x % 2) else (70*7) Just for the record, I don't have any problem at all with any of those parens. I don't think they're at all insulting, they don't slow down comprehension, and they make clear the intent of the writer. I'm not sure I would include all of them if _I_ were writing the code, but in this specific example, I think they're fine. That said, I have seen lots of cases where fully parenthising an expression would harm readability... -- Grant Edwards grant.b.edwards Yow! My nose feels like a at bad Ronald Reagan movie ... gmail.com From random832 at fastmail.com Mon Jun 6 12:57:28 2016 From: random832 at fastmail.com (Random832) Date: Mon, 06 Jun 2016 12:57:28 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> On Mon, Jun 6, 2016, at 12:19, Steven D'Aprano wrote: > (2) The "variables are like boxes" metaphor applies to static languages > like > C and Pascal, where the compiler has knowledge of what variables will > exist. Such languages allocate space for the variables at compile time, > usually using fixed memory locations on the stack, or in registers, but > rarely dynamically in the heap. As you're so fond of pointing out, those are implementation details. And CPython does it too (using frame objects rather than the stack, but the relevant point here is that it *does* have knowledge of what variables will exist), for local variables. > That's exactly what Python doesn't do. And anyway, the fact that the "boxes" are dynamically allocated rather than "fixed memory locations on the stack"* doesn't stop them from being boxes (if you prefer Marko's analogy, "Some puppies hold leashes in their mouths"). Attributes and list items and dictionary keys and values are also boxes. *isn't the whole point of it being a stack that they're not fixed? I assume you meant fixed offsets from the stack frame. From pkpearson at nowhere.invalid Mon Jun 6 12:58:20 2016 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 6 Jun 2016 16:58:20 GMT Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> Message-ID: On Mon, 6 Jun 2016 02:24:37 +1000, Chris Angelico wrote: > On Sun, Jun 5, 2016 at 4:53 PM, ICT Ezy wrote: >>>>> 2 ** 3 ** 2 >> Answer is 512 >> Why not 64? >> Order is right-left or left-right? > > This example follows the mathematical standard; you start from the > "top" (the right hand side), and work your way down. [snip] This is almost certainly why top-down was the desirable choice. And as for why mathematicians chose top-down (probably long before any programming-language designer faced the decision), note that this convention allows you to write both (a**b)**c and a**(b**c) without parentheses, making expressions cleaner than otherwise: bc (a**b)**c = a c b a**(b**c) = a -- To email me, substitute nowhere->runbox, invalid->com. From jon+usenet at unequivocal.co.uk Mon Jun 6 13:02:05 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 6 Jun 2016 17:02:05 -0000 (UTC) Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <87inxmmm67.fsf@elektro.pacujo.net> <87a8iymjel.fsf@elektro.pacujo.net> Message-ID: On 2016-06-06, Chris Angelico wrote: > On Tue, Jun 7, 2016 at 2:05 AM, Jon Ribbens > wrote: >> On 2016-06-06, Chris Angelico wrote: >>> In that case, please never insult the intelligence of your future >>> readers by including any of these parentheses: >>> >>> x = 1 + (2 * 3) >> >> I'm not sure what your point is. Yes, obviously you can take anything >> to ridiculous extremes - that's why I said "sensible". > > Earlier in this thread, it was suggested that parens always be used, > even for this kind of example. Ok, but it wasn't me that said that, and I don't agree with it. >>> value = 77 if (x % 2) else (70*7) >> >> I'm not convinced that one isn't actually a good idea. It does seem >> to aid the readability (especially if you space '70 * 7' properly). >> If the expressions were any more complex then it would be even more >> likely to be a good idea. > > Hmm, I still think not. But if you want the parens, at least > acknowledge that they're not to enforce/remind of operator precedence. That depends on your point of view. I suppose the above without parentheses could theoretically be taken to mean: value = (77 if (x % 2) else 70) * 7 although I would agree that people would be unlikely to assume that was the meaning so they are not required under that heading. >> I can't tell now if you're agreeing with me or disagreeing, because >> you started out sounding like you were disagreeing but then provided >> an example that helps prove my point. > > My point is that if you're not sure, you grab interactive Python and > give it a quick whirl. Usually easier AND quicker than the > alternatives. It's never easier and quicker than the meaning of the code simply being obvious by looking at it, which is the point. From steve at pearwood.info Mon Jun 6 13:07:22 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jun 2016 03:07:22 +1000 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> Message-ID: <5755adcc$0$1605$c3e8da3$5496439d@news.astraweb.com> On Mon, 6 Jun 2016 11:57 pm, Random832 wrote: > Okay, can we settle on, as a principle, "the basic arithmetic operators > (not to include **) are the only ones whose precedence can be presumed > to be obvious to all readers, Agreed. > and other expressions may/should have > parentheses to make it more clear, even when not strictly necessary to > the meaning of the expression"? Sure, why not? So long as it is a "should" and not a "must". > Sure, it's obvious to _me_ that << and >> have higher precedence than & > and |, and that "and" has a higher precedence than "or", Do they? https://docs.python.org/2/reference/expressions.html#operator-precedence Blimey, you're right. I always thought `and` and `or` had the same precedence. And now that I know better, I have no doubt that I will forget it again. -- Steven From rustompmody at gmail.com Mon Jun 6 13:14:36 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 6 Jun 2016 10:14:36 -0700 (PDT) Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> Message-ID: <9bf80496-6111-4d9b-a8c2-41c16e684fe2@googlegroups.com> On Monday, June 6, 2016 at 7:27:18 PM UTC+5:30, Random832 wrote: > On Mon, Jun 6, 2016, at 01:46, Lawrence D?Oliveiro wrote: > > On Monday, June 6, 2016 at 4:06:20 AM UTC+12, Uri Even-Chen wrote: > > > Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 > > > + 5, without parentheses. > > > > That leads to the code equivalent of > > . > > Okay, can we settle on, as a principle, "the basic arithmetic operators > (not to include **) are the only ones whose precedence can be presumed > to be obvious to all readers, and other expressions may/should have > parentheses to make it more clear, even when not strictly necessary to > the meaning of the expression"? > > Sure, it's obvious to _me_ that << and >> have higher precedence than & > and |, and that "and" has a higher precedence than "or", but can I > assume the other people know this? And I don't know offhand the relative > precedence of non-conceptually-related groups of operators, except that > I'm pretty sure "and" and "or" have very low precedence. > > [To keep this on-topic, let's assume that this discussion has a goal of > getting something along the lines of "always/sometimes/never use > "unnecessary" parentheses" into PEP7/PEP8. Speaking of, did you know > that C has lower precedence for the bitwise operators &^| than for > comparisons? That was something that tripped me up for a very long time > and undermined my confidence as to other aspects of the bitwise > operators] Kernghan/Thomson/Ritchie (dont remember which) actually admitted to the fact that these precedences are wrong I believe there are necessary (maybe not sufficient) conditions for a precedence table ? : A ? A ? B ? : B ? B ? C then ? should be lower than ? because otherwise (x ? y) ? z comes out type-wrong Of course these rules are usually more informal than rigorous -- both in programming and in math eg in C there is really not much of any type but int Still if we informally treat < : A ? A ? Bool (A is some kind of numeric) +,* : A ? A ? A &&, || : Bool ? Bool ? Bool then it follows that +,* < <= etc && || is the natural precedence table The mistake that C creators made was to treat bitwise operators as *logical* rather than as *arithmetic* From random832 at fastmail.com Mon Jun 6 14:44:12 2016 From: random832 at fastmail.com (Random832) Date: Mon, 06 Jun 2016 14:44:12 -0400 Subject: Operator precedence problem In-Reply-To: <5755adcc$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <5755adcc$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465238652.1130239.629575665.537F855D@webmail.messagingengine.com> On Mon, Jun 6, 2016, at 13:07, Steven D'Aprano wrote: > Blimey, you're right. I always thought `and` and `or` had the same > precedence. And now that I know better, I have no doubt that I will > forget > it again. A good way to remember it is that "and" is analogous to multiplication, and "or" is analogous to addition. Which is, I assume, _why_ they have the same precedence. (why ^ is between | and &, though, is a mystery to me.) From marko at pacujo.net Mon Jun 6 14:49:43 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 06 Jun 2016 21:49:43 +0300 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <5755adcc$0$1605$c3e8da3$5496439d@news.astraweb.com> <1465238652.1130239.629575665.537F855D@webmail.messagingengine.com> Message-ID: <87wpm25f08.fsf@elektro.pacujo.net> Random832 : > A good way to remember it is that "and" is analogous to > multiplication, and "or" is analogous to addition. Which is, I assume, > _why_ they have the same precedence. (why ^ is between | and &, > though, is a mystery to me.) APL had a good way of remembering operator precedence: every operator was equal and the evaluation order was from right to left. Marko From steve at pearwood.info Mon Jun 6 14:59:18 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jun 2016 04:59:18 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> Message-ID: <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> On Tue, 7 Jun 2016 02:57 am, Random832 wrote: > On Mon, Jun 6, 2016, at 12:19, Steven D'Aprano wrote: >> (2) The "variables are like boxes" metaphor applies to static languages >> like >> C and Pascal, where the compiler has knowledge of what variables will >> exist. Such languages allocate space for the variables at compile time, >> usually using fixed memory locations on the stack, or in registers, but >> rarely dynamically in the heap. > > As you're so fond of pointing out, those are implementation details. I believe that both C and Pascal specify that they are statically declared languages with a variable model broadly as I have described it above, the "box" model. There may be implementation-dependent details I've glossed over (I don't know the entire Pascal and C specifications by heart), but I think I'm on fairly solid ground to say that a language that is just like C except that it allocates variables in a hash table at runtime, using runtime lookups for variable access, would not satisfy the C89 or C99 standards. In any case, the point is that there are behavioural differences between a static "box" model and a dynamic "name binding" mode for variables. Python uses the later, not the former. You couldn't implement Python with a strictly static box model, since you have to support `exec`. > And > CPython does it too (using frame objects rather than the stack, but the > relevant point here is that it *does* have knowledge of what variables > will exist), for local variables. A very good point, however that *is* an implementation detail: Jython and IronPython don't have that limitation, as CPython does, and so their locals() is a proper namespace. But even in CPython 2, you can create local variables dynamically: py> def test(): ... exec("x = 1") ... print(x) ... py> test() 1 Though that doesn't work in Python 3. >> That's exactly what Python doesn't do. > > And anyway, the fact that the "boxes" are dynamically allocated rather > than "fixed memory locations on the stack"* doesn't stop them from being > boxes "Variables as boxes" is a long-standing, well-known metaphor for the C and Pascal variable model, one where the value is copied into the box (metaphorically), or to be more precise, where variables have fixed locations and on assignment values are copied to that location. Python is not like that, and using the same metaphor for two completely different models is a sure way to get obfuscation and confusion rather than understanding. Weren't you the one who just a few days ago complained about Python folks unilaterally redefining established terms in contradiction of how those terms are used by the rest of the programming community? The broader programming community understands "variables as boxes" to mean fixed size boxes in fixed locations with assignment-as-copying, as used by C and Pascal. I don't think it is helpful for you to invent your own metaphor of Python-style variables being boxes. > (if you prefer Marko's analogy, "Some puppies hold leashes in > their mouths"). I don't know what Marko's analogy is. Puppies with leashes? What? > Attributes and list items and dictionary keys and values > are also boxes. They're not boxes in the sense of the "variables are boxes" model. I don't know what other sense you intend the metaphor to be understood. > *isn't the whole point of it being a stack that they're not fixed? I > assume you meant fixed offsets from the stack frame. Yes, thank you for the correction. (That's not sarcasm.) -- Steven From maillist at schwertberger.de Mon Jun 6 15:04:42 2016 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Mon, 6 Jun 2016 21:04:42 +0200 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: On 05.06.2016 01:08, John Pote wrote: > Qt and Qt Creator often come up in searches for Python GUI libraries. > I need to decide weather to upgrade to wxPython.Phoenix and Python 3.5 > (as soon as I upgrade to win 7!) or switch to Qt which I don't know at > all. It would be interesting to hear your experiences of trying Qt and > why you've stuck with wxPython in the end. Python 2.7 and wx are working well under Win 7. But there are other problems like e.g. some bugs that I faced with the Win 32 extensions. For many libraries you can no longer expect first class support with 2.7. I have been using wxPython on the desktop since around 2000. Porting my main desktop application with several MB GUI related code to another toolkit is certainly not an option. The lack of a Python 3 compatible wxPython did hold me back from moving to Python 3 for some years, but when I tried last year, I was positively surprised as it took only one evening to port my application. OK, then it took me some evenings to implement e.g. Metafile support for Phoenix. Nowadays almost all features from the classic wxPython should be available in Phoenix as well. Even though Phoenix is not yet released, I did not face any instabilities (except maybe that the virtual grid is a bit more picky than it used to be when it comes to dynamic grid cell attributes). I'm using Qt sometimes for small apps on my mobiles (Sailfish OS and, before that, Maemo). I don't see a reason to change from wx to Qt on the desktop. I'm not convinced about whether Qt Widgets have too much of a future at all. The 'traditional' development has moved out of the focus of the Qt team a long time ago (when Trolltech was aquired by Nokia). The suggestion is to use QML now, but there's no pythonic way to develop QML / Qt Quick based GUIs as there's no C++ API which could be used as base for this. OK, Qt has one advantage: using Quamash you can integrate the asyncio and the qt main loops. Without Python 3 support there has not yet been a need to have this for wx... Qt Designer is certainly a good GUI builder, but not more than that. When you actually want to use the designed GUI in Python, you will find that this needs almost as much know how and work as if you did the GUI in code. Regards, Dietmar From python at mrabarnett.plus.com Mon Jun 6 15:17:56 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 6 Jun 2016 20:17:56 +0100 Subject: Operator precedence problem In-Reply-To: <1465238652.1130239.629575665.537F855D@webmail.messagingengine.com> References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <5755adcc$0$1605$c3e8da3$5496439d@news.astraweb.com> <1465238652.1130239.629575665.537F855D@webmail.messagingengine.com> Message-ID: <7935293c-177b-f720-bff4-65d5b7d6dd16@mrabarnett.plus.com> On 2016-06-06 19:44, Random832 wrote: > On Mon, Jun 6, 2016, at 13:07, Steven D'Aprano wrote: >> Blimey, you're right. I always thought `and` and `or` had the same >> precedence. And now that I know better, I have no doubt that I will >> forget >> it again. > > A good way to remember it is that "and" is analogous to multiplication, > and "or" is analogous to addition. Which is, I assume, _why_ they have > the same precedence. (why ^ is between | and &, though, is a mystery to > me.) > In Pascal, "and" has the same precedence as "*" and "or" has the same precedence as "+". From ben.usenet at bsb.me.uk Mon Jun 6 16:09:17 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 06 Jun 2016 21:09:17 +0100 Subject: Operator precedence problem References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <9bf80496-6111-4d9b-a8c2-41c16e684fe2@googlegroups.com> Message-ID: <877fe29j0y.fsf@bsb.me.uk> Rustom Mody writes: > Kernghan/Thomson/Ritchie (dont remember which) actually admitted to the > fact that these precedences are wrong > The mistake that C creators made was to treat bitwise operators as > *logical* rather than as *arithmetic* It was more that they did not take the opportunity to change them. C grew out of B, and B had only the one form of & and |. These were bitwise operators but, since they they were more often used for logical combinations of tests, it made sense to give them low precedence. When && and || were added to C, & and | should probably have been "bumped up", but when you have a bunch of people who already know B (and a bunch of B code you might be converting to C) it's easy to see why you might not make that change. After all, it's not like the language is going to used for much more than this experimental Unix thingy! -- Ben. From random832 at fastmail.com Mon Jun 6 17:13:01 2016 From: random832 at fastmail.com (Random832) Date: Mon, 06 Jun 2016 17:13:01 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> On Mon, Jun 6, 2016, at 14:59, Steven D'Aprano wrote: > "Variables as boxes" is a long-standing, well-known metaphor for the C > and > Pascal variable model, one where the value is copied into the box > (metaphorically), or to be more precise, where variables have fixed > locations and on assignment values are copied to that location. I don't think that's "to be more precise" at all. I think that is an entirely different model. The box metaphor as I understand it involves a lot of boxes, which may contain arrows (call them pointers, references, or whatever) emerging from them pointing to other boxes, which are all free-floating with no implication that any of them are fixed locations or are not dynamically allocated. The most classic use of it, after all, is for Lisp, in which two boxes glued together represent a cons cell, something absolutely nobody would accuse of having a fixed location. Google "lisp box diagram" for any number of examples. What does a diagram of *your* "variables as boxes" model look like? > The broader programming community Between this and the argument about "constructor" terminology, clearly you and I see "the broader programming community" very differently. > understands "variables as boxes" to mean fixed size boxes in fixed > locations with assignment-as-copying, as used by C and Pascal. I don't > think it is helpful for you to invent your own metaphor of Python- > style variables being boxes. > > (if you prefer Marko's analogy, "Some puppies hold leashes in > > their mouths"). > > I don't know what Marko's analogy is. Puppies with leashes? What? It was a couple days ago in this thread, in a reply to a post by you. On Sun, Jun 5, 2016, at 04:01, Marko Rauhamaa wrote: M> You could also think of variables as pegs, references as leashes, and M> objects as cute puppies. One puppy could be held with multiple leashes M> hung on separate pegs. Some puppies hold leashes in their mouths. Every M> leash is tied to a puppy or a special wooden post called None. (I disagreed with him on "None" needing to be a special wooden post for the analogy to work) R> > Attributes and list items and dictionary keys and values R> > are also boxes. S> S> They're not boxes in the sense of the "variables are boxes" model. I would say 'yes they are', but clearly *your* "broader programming community's" version of the ""variables are boxes" model" is different from everyone else's. I don't think continuing this discussion is likely to be productive. From marko at pacujo.net Mon Jun 6 17:47:19 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 07 Jun 2016 00:47:19 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> Message-ID: <87shwq56s8.fsf@elektro.pacujo.net> Random832 : > The box metaphor as I understand it involves a lot of boxes, which may > contain arrows (call them pointers, references, or whatever) emerging > from them pointing to other boxes, which are all free-floating with no > implication that any of them are fixed locations or are not > dynamically allocated. When I first studied Java, I quickly made a realization that Java's . (dot) is C's -> (arrow) That's all there was to it. You could replace Java with Python. Where a C programmer would write: x->y->z a Python programmer would express the same as: x.y.z > The most classic use of it, after all, is for Lisp, in which two boxes > glued together represent a cons cell, something absolutely nobody > would accuse of having a fixed location. Google "lisp box diagram" for > any number of examples. There doesn't seem to be any way to introduce Lisp/Java/Python's data model except through lower-level programming concepts. > On Sun, Jun 5, 2016, at 04:01, Marko Rauhamaa wrote: > M> You could also think of variables as pegs, references as leashes, > M> and objects as cute puppies. One puppy could be held with multiple > M> leashes hung on separate pegs. Some puppies hold leashes in their > M> mouths. Every leash is tied to a puppy or a special wooden post > M> called None. > > (I disagreed with him on "None" needing to be a special wooden post for > the analogy to work) That's not an analogy -- that's an abstract data model! Note: no boxes! However, there are strings attached. Now you can truly *bind* objects to variables. Seriously, though, it is notable that the high-level programming languages pretty unanimously refuse to make variables first-class objects. I wonder why. Python (et al) can closely emulate pointers to variables with arrays: >>> def double_it(it): ... it[0] *= 2 ... >>> it = [7] >>> double_it(it) >>> it[0] 14 >>> double_it(it) >>> it[0] 28 although that would be bad style in Python, which can return tuples. Marko From bc at freeuk.com Mon Jun 6 17:55:26 2016 From: bc at freeuk.com (BartC) Date: Mon, 6 Jun 2016 22:55:26 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/06/2016 17:19, Steven D'Aprano wrote: > (2) The "variables are like boxes" metaphor applies to static languages like > C and Pascal, where the compiler has knowledge of what variables will > exist. Such languages allocate space for the variables at compile time, > usually using fixed memory locations on the stack, or in registers, but > rarely dynamically in the heap. That's exactly what Python doesn't do. With sane programs of the kind I would write, variables appear in the source code: a = b Thus they are known to the compiler and can be given special treatment compared to any that there might be in an exec() string. That the language allows the internal entries required for such names to be 'deleted', or not to create them at all in code such as: if cond: b = 10 (when cond is false) is another matter. A disassembly will clearly show the name "b". And it would be ludicrous to suggest that here: pass # 1 a = 0 # 2 pass # 3 "a" doesn't exist at all at line 1 or at the start of line 2, and only comes fully into existence by line 3. "a" exists by name in the byte-code as well as the source code from the start. a is a variable. -- Bartc From michael.selik at gmail.com Mon Jun 6 18:28:00 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 06 Jun 2016 22:28:00 +0000 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: Message-ID: On Thu, Jun 2, 2016 at 10:06 AM Makoto Kuwata wrote: > I have a trouble around __import__(). > The docs for __import__ strongly recommend that you use importlib instead https://docs.python.org/3.5/library/importlib.html#importlib.import_module The docs for ``importlib.import_module`` suggest that you use ``invalidate_caches`` if you are importing dynamically generated files. https://docs.python.org/3.5/library/importlib.html#importlib.invalidate_caches I think you'll find this fixes your bug. From greg.ewing at canterbury.ac.nz Mon Jun 6 19:21:29 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 07 Jun 2016 11:21:29 +1200 Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> Message-ID: Peter Pearson wrote: > c > b > a**(b**c) = a Also, in mathematical texts it's usually written with the c smaller than the b, and the b smaller than the a, which helps to make the precedence clear. We can't do that in Python, unforunately. Unless we allow writing the source in html... -- Greg From greg.ewing at canterbury.ac.nz Mon Jun 6 19:27:34 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 07 Jun 2016 11:27:34 +1200 Subject: Operator precedence problem In-Reply-To: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> <5755adcc$0$1605$c3e8da3$5496439d@news.astraweb.com> <1465238652.1130239.629575665.537F855D@webmail.messagingengine.com> <7935293c-177b-f720-bff4-65d5b7d6dd16@mrabarnett.plus.com> Message-ID: MRAB wrote: > In Pascal, "and" has the same precedence as "*" and "or" has the same > precedence as "+". Which was annoying, because it gave them higher precedence than the comparison operators, so instead of a = b and c > d you had to write (a = b) and (c > d) -- Greg From lawrencedo99 at gmail.com Mon Jun 6 20:51:24 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 6 Jun 2016 17:51:24 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <878tyj97zo.fsf@elektro.pacujo.net> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> Message-ID: <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> On Sunday, June 5, 2016 at 11:43:20 PM UTC+12, Marko Rauhamaa wrote: > I often experiment with different loop constructs to find the one most > pleasing to the eye. Working directly off iterators is quite rare but a > while-vs-for consideration is frequent. Also, should the stepping part > be in the beginning, middle or end of the loop body? It is nice to have a common, versatile looping form which can be arranged in different ways to suit the problem at hand. That?s why I like the C-style for-statement. Here?s another example , for the consideration of those who don?t seem too familiar with looping: while True : while True : line = next(input_line, None) if line != None : if len(include_stack) == 0 : linenr += 1 #end if break #end if if len(include_stack) == 0 : break input_line = include_stack.pop() #end while if line == None or ... line contains something special ... : ... if line == None : break ... process special line ... ... replace with None to indicate it?s been processed ... #end if if line != None : ... process regular line ... #end if #end while From lawrencedo99 at gmail.com Mon Jun 6 20:53:46 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 6 Jun 2016 17:53:46 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <878tyj97zo.fsf@elektro.pacujo.net> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> Message-ID: <9021ff59-16bf-4c47-bb80-2ff47809c9a7@googlegroups.com> On Sunday, June 5, 2016 at 11:43:20 PM UTC+12, Marko Rauhamaa wrote: > Then, you might overdo constructs like lambdas and maps. Who says you can have too many lambdas? From lawrencedo99 at gmail.com Mon Jun 6 22:15:29 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 6 Jun 2016 19:15:29 -0700 (PDT) Subject: Everything good about Python except GUI IDE? In-Reply-To: <64a6599c-fae1-469d-bcee-875165b3cc7d@googlegroups.com> References: <64a6599c-fae1-469d-bcee-875165b3cc7d@googlegroups.com> Message-ID: On Sunday, February 28, 2016 at 12:19:21 AM UTC+13, wrong.a... at gmail.com wrote: > I have some VB forms with more than a hundred objects. If I cannot drag and > drop text boxes, list boxes, labels, etc., it will be too much work to create > that with several lines of code for each object. You mean you had to drag and drop every single one of those objects? You couldn?t script their creation automatically? And you are asking for a Python equivalent that will make you work just as hard? From dan at tombstonezero.net Mon Jun 6 23:34:27 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Tue, 7 Jun 2016 03:34:27 -0000 (UTC) Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> Message-ID: On Mon, 06 Jun 2016 17:51:24 -0700, Lawrence D?Oliveiro wrote: > It is nice to have a common, versatile looping form which can be > arranged in different ways to suit the problem at hand. That?s why I > like the C-style for-statement. [example snipped] I used to write a lot of assembly code, for a lot of different CPUs, and they all had a common, versatile looping form which could be arranged in different ways to suit the problem at hand. On most chips, it was (and still is) called JMP. The trouble began with multiple conditional branching, call stack maintenance, and those other higher level abstractions that made my assembly code so hard to follow. Why on Earth would I use something so complicated as a DJNZ instruction when a common, versatile sequence of decrement, test, and branch-on-not-zero instructions was available? And who needed a C-level for statment, let alone local variables and a language-runtime-maintained function call stack when I had a handful of common, versatile CPU registers? http://www.catb.org/jargon/html/story-of-mel.html From ian.g.kelly at gmail.com Tue Jun 7 00:35:33 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 6 Jun 2016 22:35:33 -0600 Subject: for / while else doesn't make sense In-Reply-To: <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> Message-ID: On Mon, Jun 6, 2016 at 6:51 PM, Lawrence D?Oliveiro wrote: > On Sunday, June 5, 2016 at 11:43:20 PM UTC+12, Marko Rauhamaa wrote: >> I often experiment with different loop constructs to find the one most >> pleasing to the eye. Working directly off iterators is quite rare but a >> while-vs-for consideration is frequent. Also, should the stepping part >> be in the beginning, middle or end of the loop body? > > It is nice to have a common, versatile looping form which can be arranged in different ways to suit the problem at hand. That?s why I like the C-style for-statement. > > Here?s another example , for the consideration of those who don?t seem too familiar with looping: A 500-line function? Yikes, what an eyesore. When you have to include #end comments in order to visually match things up, that should be a smell that your code is excessively complex. It took me a lot of scrolling up and down just to figure out what the scopes of the variables were. > while True : > while True : > line = next(input_line, None) > if line != None : > if len(include_stack) == 0 : > linenr += 1 > #end if > break > #end if > if len(include_stack) == 0 : > break > input_line = include_stack.pop() > #end while > if line == None or ... line contains something special ... : > ... > if line == None : > break > ... process special line ... > ... replace with None to indicate it?s been processed ... > #end if > if line != None : > ... process regular line ... > #end if > #end while def generate_lines(): nonlocal input_line while True: try: # Note input_line appears to be an iterator, not a string # as suggested by the name. yield next(input_line) except StopIteration: if include_stack: input_line = include_stack.pop() else: return for line in generate_lines(): if not include_stack: linenr += 1 if ... line contains something special ...: ... process special line ... else: ... process regular line ... Much simpler than the nested while loop hell above, and not a single break needed (if you don't count the return, that is; in any case each loop has a single exit point). I'd be tempted to refactor input_line and include_stack into some sort of input context class and make generate_lines a method of the class in order to avoid having those variables be (effectively) global, but my goal was to keep this as close to the original in design as possible. From greg.ewing at canterbury.ac.nz Tue Jun 7 01:42:33 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 07 Jun 2016 17:42:33 +1200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Even if you were right that objects must exist at > a single well-defined location, that is strictly irrelevant. That's > implementation, not interface. We're talking about mental models. Sure, you could come up with some kind of Tardis-like mental model where objects exist in more than one location at once. But why would you bother going to such mental contortions? There is a much more straightforward model that's vastly easier to reason about, because it aligns with our intuitions, which are based on the way things behave in the actual universe we live in. -- Greg From greg.ewing at canterbury.ac.nz Tue Jun 7 02:20:07 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 07 Jun 2016 18:20:07 +1200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I never said that the string "x" is the same thing as the variable x. Maybe you didn't, but some people insist we shouldn't use the term "variable" when talking about python, but use "name" instead. I was pointing out that those two words don't have the same connotations. -- Greg From greg.ewing at canterbury.ac.nz Tue Jun 7 02:33:11 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 07 Jun 2016 18:33:11 +1200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I think I'm on > fairly solid ground to say that a language that is just like C except that > it allocates variables in a hash table at runtime, using runtime lookups > for variable access, would not satisfy the C89 or C99 standards. I wouldn't be so sure about that. Modern C standards are pretty careful to avoid making any promises about how things are laid out in memory, etc. It wouldn't surprise me much if you could come up with such an implementation that adheres to the strict letter of the standard. It also wouldn't surprise me if that implementation failed to run a large proportion of real C code out there, though... -- Greg From gamesbook at gmail.com Tue Jun 7 02:42:14 2016 From: gamesbook at gmail.com (derek) Date: Mon, 6 Jun 2016 23:42:14 -0700 (PDT) Subject: xlrd 1.0.0 released! In-Reply-To: <060dd4d0-cc82-a849-2041-45768b548eab@simplistix.co.uk> References: <92f1ca45-f519-54e8-932e-1d8c0b32baaa@simplistix.co.uk> <060dd4d0-cc82-a849-2041-45768b548eab@simplistix.co.uk> Message-ID: <95bbdf54-6963-4ed0-8702-0c1eff20eb5c@googlegroups.com> Gmail and the Gmail Digest only ever show the 0.9.4 tag - not sure if this a big issue or not (but I know I would like to the 1.0.0 tag to be proudly displayed!) On Friday, 3 June 2016 03:57:35 UTC+2, Chris Withers wrote: > > Ugh, and once again, this time with a corrected title... > > > On 02/06/2016 18:56, Chris Withers wrote: > > Hi All, > > > > Well, I've finally called it and tagged current master of xlrd as 1.0.0: > > > > http://pypi.python.org/pypi/xlrd/1.0.0 > > > > This release includes the following changes since the last release: > > > > - Official support, such as it is, is now for 2.6, 2.7, 3.3+ > > > > - Fixes a bug in looking up non-lowercase sheet filenames by ensuring > > that the sheet targets are transformed the same way as the > > component_names dict keys. > > > > - Fixes a bug for ragged_rows=False when merged cells increases the > > number of columns in the sheet. This requires all rows to be extended > > to ensure equal row lengths that match the number of columns in the > > sheet. > > > > - Fixes to enable reading of SAP-generated .xls files. > > > > - support BIFF4 files with missing FORMAT records. > > > > - support files with missing WINDOW2 record. > > > > - Empty cells are now always unicode strings, they were a bytestring > > on Python2 and a unicode string on Python3. > > > > - Fix for inlineStr attribute without child. > > > > - Fix for a zoom of None causes problems on Python 3. > > > > - Fix parsing of bad dimensions. > > > > - Fix xlsx sheet->comments relationship. > > > > Thanks to the following for their contributions to this release: > > > > - Lars-Erik Hannelius > > - Deshi Xiao > > - Stratos Moro > > - Volker Diels-Grabsch > > - John McNamara > > - Ville Skytt? > > - Patrick Fuller > > - Dragon Dave McKee > > - Gunnlaugur ??r Briem > > > > If you find any problems, please ask about them on the > > python... at googlegroups.com list, or submit an issue on > GitHub: > > > > https://github.com/python-excel/xlrd/issues > > > > Full details of all things Python and Excel related can be found here: > > > > http://www.python-excel.org/ > > > > NB: If you would like to become the maintainer of xlwt, please get in > > touch! Neither myself nor John Machin have much time to drive things > > forward nowadays, hence the year or so between each release... > > > > cheers, > > > > Chris > > > > From rosuav at gmail.com Tue Jun 7 02:55:51 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jun 2016 16:55:51 +1000 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jun 7, 2016 at 4:33 PM, Gregory Ewing wrote: > Steven D'Aprano wrote: >> >> I think I'm on >> fairly solid ground to say that a language that is just like C except that >> it allocates variables in a hash table at runtime, using runtime lookups >> for variable access, would not satisfy the C89 or C99 standards. > > > I wouldn't be so sure about that. Modern C standards are > pretty careful to avoid making any promises about how > things are laid out in memory, etc. > > It wouldn't surprise me much if you could come up with > such an implementation that adheres to the strict letter > of the standard. It also wouldn't surprise me if that > implementation failed to run a large proportion of > real C code out there, though... Without having read any of the specs, my guess is you could be C89/C99 compliant putting all your "simple variables" into the hash table - int, char, float, double, etc - but keep all your arrays and structs in "real memory". There's no reason a CPU couldn't be built with fifty million registers available, and the compiler could just put all those scalars into registers (assuming you never take their addresses, in which case they then need to have them). ChrisA From greg.ewing at canterbury.ac.nz Tue Jun 7 03:03:14 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 07 Jun 2016 19:03:14 +1200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <87shwq56s8.fsf@elektro.pacujo.net> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> <87shwq56s8.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > [concerning leashed puppies] > Note: no boxes! However, there are strings attached. Now you can truly > *bind* objects to variables. If you wanted to really bind them good and proper, you'd use duct tape (or "duck tape" as some people call it -- arguably more appropriate in this context!) > Seriously, though, it is notable that the high-level programming > languages pretty unanimously refuse to make variables first-class > objects. I wonder why. That's an interesting question. One reason might be that in the absence of static type analysis, assigning to a variable holding a reference to another variable would be ambiguous. For example, suppose Python had an & operator that gives you an object referring to a variable somehow. Then, after a = 42 b = 17 c = &a c = &b does 'c' now hold a reference to the variable 'b', or does it still hold a reference to 'a' and 'a' now holds a reference to 'b'? Somehow these two operations would have to be spelled different ways, which means you would need to know whether you were dealing with a variable reference or not. So they wouldn't really be first-class, in the sense of being treated on an equal footing with ordinary variables. -- Greg From nick.a.sarbicki at gmail.com Tue Jun 7 03:22:28 2016 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Tue, 07 Jun 2016 07:22:28 +0000 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: > > Qt Designer is certainly a good GUI builder, but not more than that. > When you actually want to use the designed GUI in Python, you will find > that this needs almost as much know how and work as if you did the GUI > in code. > I think that's a bit of an unfair statement. Sure conversion can be a bit of a pain and there is some setup for getting the classes working. But that is generally a small static piece of code you can find all over the net, which is then usable for most projects. The code you get from Qt creator however can be a huge bulk of the work which you thankfully don't need to nitpick over much at all. Yes understanding how it works helps a lot and I'd recommend anyone to have a look at how to build a decent GUI with Qt. But for me, once past the understanding, coding GUIs by hand is about as dull as it gets. Qt creator definitely makes the work go faster. - Nick. > From lawrencedo99 at gmail.com Tue Jun 7 03:52:42 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 00:52:42 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> Message-ID: <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> On Tuesday, June 7, 2016 at 4:36:37 PM UTC+12, Ian wrote: > A 500-line function? Yikes, what an eyesore. When you have to include > #end comments in order to visually match things up, that should be a > smell that your code is excessively complex. Feel free to come up with a simpler version. > def generate_lines(): > nonlocal input_line > while True: > try: > # Note input_line appears to be an iterator, not a string > # as suggested by the name. > yield next(input_line) > except StopIteration: > if include_stack: > input_line = include_stack.pop() > else: > return > > for line in generate_lines(): > if not include_stack: > linenr += 1 > if ... line contains something special ...: > ... process special line ... > else: > ... process regular line ... Wow, that?s only twice the length of the code you?re replacing. Well done. From lawrencedo99 at gmail.com Tue Jun 7 03:53:31 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 00:53:31 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> Message-ID: On Tuesday, June 7, 2016 at 3:34:39 PM UTC+12, Dan Sommers wrote: > I used to write a lot of assembly code, for a lot of different CPUs, and > they all had a common, versatile looping form which could be arranged in > different ways to suit the problem at hand. On most chips, it was (and > still is) called JMP. The trouble began with multiple conditional > branching, call stack maintenance, and those other higher level > abstractions that made my assembly code so hard to follow. You?ll notice I don?t use gotos in my code. Next red-herring example, please... From marko at pacujo.net Tue Jun 7 03:56:55 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 07 Jun 2016 10:56:55 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> <87shwq56s8.fsf@elektro.pacujo.net> Message-ID: <8760tlmny0.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> Seriously, though, it is notable that the high-level programming >> languages pretty unanimously refuse to make variables first-class >> objects. I wonder why. > > That's an interesting question. One reason might be > that in the absence of static type analysis, assigning > to a variable holding a reference to another variable > would be ambiguous. For example, suppose Python had > an & operator that gives you an object referring to > a variable somehow. Then, after > > a = 42 > b = 17 > c = &a > c = &b > > does 'c' now hold a reference to the variable 'b', or > does it still hold a reference to 'a' and 'a' now > holds a reference to 'b'? If variables were ordinary mutable objects, you'd need a syntax of dereferencing, just like in C. Variable objects would be highly analogous to single-element arrays, little boxes if you will. > Somehow these two operations would have to be spelled different ways, > which means you would need to know whether you were dealing with a > variable reference or not. So they wouldn't really be first-class, in > the sense of being treated on an equal footing with ordinary > variables. It's not that ambiguous. >>> a = 3 >>> c = &a >>> c >>> *c 3 >>> c is a False >>> *c is a True >>> c is &a True >>> a = 4 >>> *c 4 >>> *c is a True >>> c = &c >>> c >>> *c >>> **c Marko From marko at pacujo.net Tue Jun 7 04:00:17 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 07 Jun 2016 11:00:17 +0300 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> Message-ID: <871t49mnse.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Tuesday, June 7, 2016 at 4:36:37 PM UTC+12, Ian wrote: >> A 500-line function? Yikes, what an eyesore. When you have to include >> #end comments in order to visually match things up, that should be a >> smell that your code is excessively complex. > > [...] > > Wow, that?s only twice the length of the code you?re replacing. Well > done. I understand you are hurt when your code is criticized bluntly. However, you *did* stick your head out. I, too, insist that every function/method must be visible at once in the editor window. Marko From steve+comp.lang.python at pearwood.info Tue Jun 7 04:36:58 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jun 2016 18:36:58 +1000 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> Message-ID: <575687ac$0$2839$c3e8da3$76491128@news.astraweb.com> On Tuesday 07 June 2016 17:52, Lawrence D?Oliveiro wrote: > On Tuesday, June 7, 2016 at 4:36:37 PM UTC+12, Ian wrote: >> A 500-line function? Yikes, what an eyesore. When you have to include >> #end comments in order to visually match things up, that should be a >> smell that your code is excessively complex. > > Feel free to come up with a simpler version. If I could work out what your convoluted version is supposed to do, I might give it a try. [...] >> def generate_lines(): >> nonlocal input_line [snip code] > Wow, that?s only twice the length of the code you?re replacing. Well done. I count 18 lines in your version using while loops, excluding comments, but including placeholder ... lines, compared to 17 lines in Ian's version. How do you get "twice the length"? Ian's version is also much simpler: there are no breaks and no variables being assigned to None so you can detect the end of the loop, and only three `if`s instead of six in your version. That makes Ian's objectively less complex than your example, assuming it does the same thing. (Although I'm a bit dubious about the use of nonlocal.) -- Steve From jussi.piitulainen at helsinki.fi Tue Jun 7 04:41:11 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 07 Jun 2016 11:41:11 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> <87shwq56s8.fsf@elektro.pacujo.net> <8760tlmny0.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Gregory Ewing : > >> Marko Rauhamaa wrote: >>> Seriously, though, it is notable that the high-level programming >>> languages pretty unanimously refuse to make variables first-class >>> objects. I wonder why. >> >> That's an interesting question. One reason might be >> that in the absence of static type analysis, assigning >> to a variable holding a reference to another variable >> would be ambiguous. For example, suppose Python had >> an & operator that gives you an object referring to >> a variable somehow. Then, after >> >> a = 42 >> b = 17 >> c = &a >> c = &b >> >> does 'c' now hold a reference to the variable 'b', or >> does it still hold a reference to 'a' and 'a' now >> holds a reference to 'b'? > > If variables were ordinary mutable objects, you'd need a syntax of > dereferencing, just like in C. Variable objects would be highly > analogous to single-element arrays, little boxes if you will. I've had this little piece lying around ever since there last was a discussion about assignments as expressions. It abuses the ** operator to store values in boxes; the value of 'expression ** x' is the value of 'expression', with the side effect that afterwards the value of x.it (the dereferencing!) is also whatever the value of 'expression' was. class Box(object): '''Read ** as as and x.it as whatever was saved as x.''' def __init__(self, init = None): self.it = init def __rpow__(self, it): # f() ** self self.it = it return self.it data = iter('pi?si?nt?sesti ee n?en') from string import ascii_letters as ascii x, y = Box(), Box() while (next(data) ** x in ascii and next(data) ** y in ascii): print(x.it, y.it) # Prints one line: p i There's a further test case in that file, saving the regex match object during the expression that tests whether there was a match object. Not entirely satisfactory, but perhaps mildly interesting. import re beg = re.compile(r'start=(\w+)') end = re.compile(r'finis=(\w+)') b, e = Box(), Box() for k, line in enumerate(('xxx', '# start=eka rivi', 'ween', 'ween', '# finis=vika rivi', 'xxx')): if not b.it and beg.search(line) ** b: print(k, b.it.group(1)) elif b.it and end.search(line) ** e: print(k, e.it.group(1)) break elif b.it: print(k, line) # Prints four lines: # 1 eka # 2 ween # 3 ween # 4 vika From krrikjagz at gmail.com Tue Jun 7 05:43:51 2016 From: krrikjagz at gmail.com (karthik jagilinki) Date: Tue, 7 Jun 2016 02:43:51 -0700 (PDT) Subject: How to implement semaphores in python? Message-ID: <689c997b-bafc-49a4-9932-1b36f375d932@googlegroups.com> Hello All, I need some help with semaphore implementation between two programs in python. I'd be glad if anyone can give me some help. From dpalao.python at gmail.com Tue Jun 7 06:12:14 2016 From: dpalao.python at gmail.com (David Palao) Date: Tue, 7 Jun 2016 12:12:14 +0200 Subject: How to implement semaphores in python? In-Reply-To: <689c997b-bafc-49a4-9932-1b36f375d932@googlegroups.com> References: <689c997b-bafc-49a4-9932-1b36f375d932@googlegroups.com> Message-ID: Hi, Have you checked this https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Semaphore ? Best 2016-06-07 11:43 GMT+02:00 karthik jagilinki : > Hello All, > > I need some help with semaphore implementation between two programs in python. I'd be glad if anyone can give me some help. > -- > https://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Tue Jun 7 06:18:17 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jun 2016 20:18:17 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57569f6a$0$11124$c3e8da3@news.astraweb.com> On Tuesday 07 June 2016 15:42, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Even if you were right that objects must exist at >> a single well-defined location, that is strictly irrelevant. That's >> implementation, not interface. > > We're talking about mental models. Sure, you could come up > with some kind of Tardis-like mental model where objects > exist in more than one location at once. But why would > you bother going to such mental contortions? Because (self-recursive data structures like lists that contain themselves aside), that's actually a much more simple mental model than the pointer model. Its how natural language works. Compare: "Greg kicked the penguin." with: "The person whose name is Greg kicked the penguin." Both say the same thing. The first uses the word 'Greg' as a direct stand-in for the person Greg himself, the man. 'Greg' (the word) is used to mean the person Greg, it is not used as "a word that refers to the person". The second emphasises the fact that 'Greg' is a name, not a person, and is a form of indirection. It uses 'Greg' as 'a word that refers to the person', not the person itself. We almost always prefer sentences of the first type rather than the second. x = 999 Why should we say "x is a reference to 999" when "x is 999" is simpler, shorter, explains the semantics of the code, and is arguably more correct? Given that in Python code, x behaves like an int, and looks like an int, and we treat it like an int, applying int operations such as + to it, and we discuss it as if it were an int, why on earth would we bother going to such mental contortions as to insist that its actually a reference? Here's a thought experiment for you. Suppose in Python 3.6, Guido announces that Python will support a form of high-level pointer (not the scary, dangerous low-level pointer of C) called "reference". There will be a dereference operator, ^, and a "reference to" operator, @. We'll be able to treat references as first-class values: x = 999 y = @x print(y) => prints "ref --> 999" print(type(y)) => prints "reference" print(y^ + 1) => prints 1000 Do we say: "x is 999, and y is a reference to x" or would you prefer: "x is a reference to 999, and y is a reference to a reference to x"? We users of languages like Python get all the advantages of references, dynamic allocation of variables, indirection etc. with none of the pain, or at least hardly any. We rarely need to care about the fact that the interpreter uses indirect references under the hood, because the Python language itself doesn't require us to care. When we assign "x = 999", we treat x as if it were an int, just like the code says it is. When we assign "x = []", we treat x as if it were a list, just like the code says. Why should we insist that x isn't actually an int, or a list, but an invisible, untouchable, unseen reference? By the way, I believe that these people claiming that x is a reference do not, in general, use that language in real life. I would be willing to bet that you say "x is 999" just like I do. -- Steve From bc at freeuk.com Tue Jun 7 06:49:13 2016 From: bc at freeuk.com (BartC) Date: Tue, 7 Jun 2016 11:49:13 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <8760tlmny0.fsf@elektro.pacujo.net> References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> <87shwq56s8.fsf@elektro.pacujo.net> <8760tlmny0.fsf@elektro.pacujo.net> Message-ID: On 07/06/2016 08:56, Marko Rauhamaa wrote: > Gregory Ewing : > >> Marko Rauhamaa wrote: >>> Seriously, though, it is notable that the high-level programming >>> languages pretty unanimously refuse to make variables first-class >>> objects. I wonder why. >> >> That's an interesting question. One reason might be >> that in the absence of static type analysis, assigning >> to a variable holding a reference to another variable >> would be ambiguous. For example, suppose Python had >> an & operator that gives you an object referring to >> a variable somehow. Then, after >> >> a = 42 >> b = 17 >> c = &a >> c = &b >> >> does 'c' now hold a reference to the variable 'b', or >> does it still hold a reference to 'a' and 'a' now >> holds a reference to 'b'? c points to b. For the latter part of your statement to be true, the last line might have to be something like: *c = &b >> Somehow these two operations would have to be spelled different ways, >> which means you would need to know whether you were dealing with a >> variable reference or not. So they wouldn't really be first-class, in >> the sense of being treated on an equal footing with ordinary >> variables. > > It's not that ambiguous. > > >>> a = 3 > >>> c = &a > >>> c > > >>> *c > 3 > >>> c is a > False > >>> *c is a > True > >>> c is &a > True > >>> a = 4 > >>> *c > 4 > >>> *c is a > True > >>> c = &c > >>> c > > >>> *c > > >>> **c > Here are some results in another, non-Python language. While the object reference module is similar to Python's, the language retains explicit pointers which can be used for variable references. In this code, ^x means pointer to x, x^ means dereference c, while := is assignment and = means equality: a := 3 c := ^a println c # refvar: 02176228 println c = a # error (compare pointer to int) println c = ^a # True a := 4 println c^ # 4 c^ := 12 println a # 12 c := ^c println c # refvar: 02176248 println c^ # refvar: 02176248 println c^^ # refvar: 02176248 Associating a pointer value to a variable symbol table entry is a separate step. But a pointer needn't point at just a named variable: a := (10,20,30,40,50) c := ^a[3] println c^ # 30 (was 1-based) c^ := 77 println a # (10,20,77,40,50) And here is the above example: a := 42 b := 17 c := ^a c^ := ^b println a # refvar: 21A16F0 println a^ # 17 -- Bartc From hemla21 at gmail.com Tue Jun 7 07:25:54 2016 From: hemla21 at gmail.com (Heli) Date: Tue, 7 Jun 2016 04:25:54 -0700 (PDT) Subject: reshape and keep x,y,z ordering Message-ID: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> Hello, I have a question regarding reshaping numpy array. I either have a 1D array that I need to reshape to a 3D array or a 3D array to reshape to a 1d numpy array. In both of these cases it is assumed that data follows x,y,z ordering. and I use the following to reshape the numpy array. new_1d_array=np.reshape(3d.transpose(),(3d_nx*3d_ny*3d_nz,)) new_3d_array=np.reshape(1d,((3d_x,3d_y,3d_z)).transpose()) My question is if there is anyway that reshape would keep x,y,z ordering that would not require transpose? and if there is a better more efficient way to do this? Thanks alot, From ian.g.kelly at gmail.com Tue Jun 7 07:52:42 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Jun 2016 05:52:42 -0600 Subject: for / while else doesn't make sense In-Reply-To: <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> Message-ID: On Tue, Jun 7, 2016 at 1:52 AM, Lawrence D?Oliveiro wrote: > Wow, that?s only twice the length of the code you?re replacing. Well done. Huh? The example that you posted was 17 lines, excluding comments. My replacement code is 17 lines, excluding comments. Where are you getting "twice the length" from? From dan at tombstonezero.net Tue Jun 7 08:27:49 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Tue, 7 Jun 2016 12:27:49 -0000 (UTC) Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> Message-ID: On Tue, 07 Jun 2016 00:53:31 -0700, Lawrence D?Oliveiro wrote: > On Tuesday, June 7, 2016 at 3:34:39 PM UTC+12, Dan Sommers wrote: > >> I used to write a lot of assembly code, for a lot of different CPUs, and >> they all had a common, versatile looping form which could be arranged in >> different ways to suit the problem at hand. On most chips, it was (and >> still is) called JMP. The trouble began with multiple conditional >> branching, call stack maintenance, and those other higher level >> abstractions that made my assembly code so hard to follow. > > You?ll notice I don?t use gotos in my code. I notice plenty of break statements scattered throughout your loop bodies. Mixing the loop's exit conditions in with the logic is equally unstructured. > Next red-herring example, please... I didn't say anything about a red-herring. Please stick to the topic at hand. From antoon.pardon at rece.vub.ac.be Tue Jun 7 08:32:24 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 7 Jun 2016 14:32:24 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <57569f6a$0$11124$c3e8da3@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> Message-ID: <5756BED8.2000304@rece.vub.ac.be> Op 07-06-16 om 12:18 schreef Steven D'Aprano: > We're talking about mental models. Sure, you could come up > with some kind of Tardis-like mental model where objects > exist in more than one location at once. But why would > you bother going to such mental contortions? > Because (self-recursive data structures like lists that contain themselves > aside), that's actually a much more simple mental model than the pointer model. > Its how natural language works. Compare: > > "Greg kicked the penguin." > > with: > > "The person whose name is Greg kicked the penguin." > > Both say the same thing. The first uses the word 'Greg' as a direct stand-in > for the person Greg himself, the man. 'Greg' (the word) is used to mean the > person Greg, it is not used as "a word that refers to the person". > > The second emphasises the fact that 'Greg' is a name, not a person, and is a > form of indirection. It uses 'Greg' as 'a word that refers to the person', not > the person itself. We almost always prefer sentences of the first type rather > than the second. Yes almost. But the second is more accurate and sometimes the extra accuracy matters. Like often enough the difference between numbers and numerals when people say they want to work with binary numbers. > x = 999 > > Why should we say "x is a reference to 999" when "x is 999" is simpler, > shorter, explains the semantics of the code, and is arguably more correct? > > Given that in Python code, x behaves like an int, and looks like an int, and we > treat it like an int, applying int operations such as + to it, and we discuss > it as if it were an int, why on earth would we bother going to such mental > contortions as to insist that its actually a reference? Because you are putting blinders on by only looking at a simple type like an int. By looking only at ints, you are totally obscuring the difference in asignment semantics beween C and python. And by obscuring that difference you are inviting the confused inquiries later, on whether argument passing in python is by value or by reference. Sure talk about "x is 999" when you are talking about a piece of code, but when you are explaining assignment semantics or other particulars of the language saying things like that is taking a shortcut that often enough will cause confusions later. > Here's a thought experiment for you. Suppose in Python 3.6, Guido announces > that Python will support a form of high-level pointer (not the scary, dangerous > low-level pointer of C) called "reference". There will be a dereference > operator, ^, and a "reference to" operator, @. We'll be able to treat > references as first-class values: That makes very little sense in python. > We users of languages like Python get all the advantages of references, dynamic > allocation of variables, indirection etc. with none of the pain, or at least > hardly any. We rarely need to care about the fact that the interpreter uses > indirect references under the hood, because the Python language itself doesn't > require us to care. When we assign "x = 999", we treat x as if it were an int, > just like the code says it is. When we assign "x = []", we treat x as if it > were a list, just like the code says. Why should we insist that x isn't > actually an int, or a list, but an invisible, untouchable, unseen reference? That doesn't change the fact that when you have to explain the language semantics, making it clear that variables are essentials references and that an assigment just changes such a reference and doesn't do a copy. > By the way, I believe that these people claiming that x is a reference do not, > in general, use that language in real life. I would be willing to bet that you > say "x is 999" just like I do. So what? People use shortcuts in language all the time, because often enough the context makes it clear how the shortcut is to be understood. That people often use the shortcut "x is 999" doesn't make the statement wrong that variables are essentially references in Python. From joel.goldstick at gmail.com Tue Jun 7 08:48:05 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 7 Jun 2016 08:48:05 -0400 Subject: reshape and keep x,y,z ordering In-Reply-To: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> References: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> Message-ID: On Tue, Jun 7, 2016 at 7:25 AM, Heli wrote: > Hello, > > I have a question regarding reshaping numpy array. > > I either have a 1D array that I need to reshape to a 3D array or a 3D array to reshape to a 1d numpy array. > > In both of these cases it is assumed that data follows x,y,z ordering. > > and I use the following to reshape the numpy array. > > > new_1d_array=np.reshape(3d.transpose(),(3d_nx*3d_ny*3d_nz,)) > > > new_3d_array=np.reshape(1d,((3d_x,3d_y,3d_z)).transpose()) > > My question is if there is anyway that reshape would keep x,y,z ordering that would not require transpose? and if there is a better more efficient way to do this? > > Thanks alot, > -- > https://mail.python.org/mailman/listinfo/python-list Sorry, I can't help, others may be able to help you here. But there is also a numpy specific mailing list you might try -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From michael.selik at gmail.com Tue Jun 7 09:16:37 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 07 Jun 2016 13:16:37 +0000 Subject: reshape and keep x,y,z ordering In-Reply-To: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> References: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> Message-ID: On Tue, Jun 7, 2016 at 7:31 AM Heli wrote: > Hello, > I have a question regarding reshaping numpy array. > > I either have a 1D array that I need to reshape to a 3D array or a 3D > array to reshape to a 1d numpy array. > > In both of these cases it is assumed that data follows x,y,z ordering. > and I use the following to reshape the numpy array. > > new_1d_array=np.reshape(3d.transpose(),(3d_nx*3d_ny*3d_nz,)) > > new_3d_array=np.reshape(1d,((3d_x,3d_y,3d_z)).transpose()) > > My question is if there is anyway that reshape would keep x,y,z ordering > that would not require transpose? and if there is a better more efficient > way to do this? >>> a = np.arange(9).reshape(3,3) >>> a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> a.flatten() array([0, 1, 2, 3, 4, 5, 6, 7, 8]) >>> a.flatten('F') array([0, 3, 6, 1, 4, 7, 2, 5, 8]) Does this work for you? The flatten method normally goes row by row, but you can specify FORTRAN style column by column flattening. From hemla21 at gmail.com Tue Jun 7 09:37:50 2016 From: hemla21 at gmail.com (Heli) Date: Tue, 7 Jun 2016 06:37:50 -0700 (PDT) Subject: reshape and keep x,y,z ordering In-Reply-To: References: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> Message-ID: <66c545f1-c031-467d-ba55-e530b1d8891d@googlegroups.com> Thanks Michael, This did the trick. array.flatten('F') works exactly as I need. Thanks a lot, From random832 at fastmail.com Tue Jun 7 11:14:30 2016 From: random832 at fastmail.com (Random832) Date: Tue, 07 Jun 2016 11:14:30 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> <87shwq56s8.fsf@elektro.pacujo.net> Message-ID: <1465312470.1376520.630519945.7DA4FE0E@webmail.messagingengine.com> On Tue, Jun 7, 2016, at 03:03, Gregory Ewing wrote: > a = 42 > b = 17 > c = &a > c = &b > > does 'c' now hold a reference to the variable 'b', or > does it still hold a reference to 'a' and 'a' now > holds a reference to 'b'? It'd have to be spelled *c = &b, or c.value = &b or c.setvalue(&b), or something like that, to mean the latter. > Somehow these two operations would have to be spelled > different ways, which means you would need to know > whether you were dealing with a variable reference or > not. So they wouldn't really be first-class, in the > sense of being treated on an equal footing with > ordinary variables. Er, how would that make them not first class? Lots of operations need to be spelled differently, that's why we have so many operators, attribute lookup syntax, etc. "Assign to the variable object that is in this variable" would be a distinct operation from "Assign to this variable", just like "add one to this value" or "call this function" etc. From random832 at fastmail.com Tue Jun 7 11:33:40 2016 From: random832 at fastmail.com (Random832) Date: Tue, 07 Jun 2016 11:33:40 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5756BED8.2000304@rece.vub.ac.be> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> Message-ID: <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> On Tue, Jun 7, 2016, at 08:32, Antoon Pardon wrote: > > Here's a thought experiment for you. Suppose in Python 3.6, Guido announces > > that Python will support a form of high-level pointer (not the scary, dangerous > > low-level pointer of C) called "reference". There will be a dereference > > operator, ^, and a "reference to" operator, @. We'll be able to treat > > references as first-class values: > > That makes very little sense in python. Why not? If you prefer, think of it something like: class ItemPtr: def __init__(self, obj, key): self.obj = obj self.key = key def ___setvalue___(self, value): self.obj[self.key] = value def ___getvalue___(self) return self.obj[self.key] @(foo[bar]) returns ItemPtr(foo, bar) @baz where bar is a global variable returns ItemPtr(globals(), 'baz') @quux where quux is local returns a cell object (any local that is used in such an expression becomes a cell variable as with any local that is used in a closure), and the cell type shall have these methods added to it. @(foo.bar) returns AttrPtr(foo, 'bar') where AttrPtr is a similarly defined type. We could even support a kind of "pointer arithmetic" for ItemPtr to list-like containers: def __add__(self, offset): return ItemPtr(self.obj, self.key + offset) def __getitem__(self, offset): return self.obj[self.key + offset] From steve at pearwood.info Tue Jun 7 12:03:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 08 Jun 2016 02:03:11 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> Message-ID: <5756f040$0$1591$c3e8da3$5496439d@news.astraweb.com> On Tue, 7 Jun 2016 10:32 pm, Antoon Pardon wrote: > That people often use the shortcut "x is 999" doesn't make the statement > wrong that variables are essentially references in Python. No, I'm sorry, you're wrong, variables are essentially arrays of bits in Python. -- Steven From maillist at schwertberger.de Tue Jun 7 14:08:28 2016 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Tue, 7 Jun 2016 20:08:28 +0200 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: On 07.06.2016 09:22, Nick Sarbicki wrote: > I think that's a bit of an unfair statement. Sure conversion can be a > bit of a pain and there is some setup for getting the classes working. > But that is generally a small static piece of code you can find all > over the net, which is then usable for most projects. The small static piece will just import the GUI. Still then, if the GUI actually serves a purpose, you need to address all the controls and events yourself. At that point, you will soon find that you need to know as much as if you created the GUI in code. Anway, for GUI development I recommend using a good debugger like that of Wing IDE. Just set a breakpoint or wait for an exception and then write the GUI in the debugger utilizing the introspection features. > But for me, once past the understanding, coding GUIs by hand is about > as dull as it gets. Qt creator definitely makes the work go faster. For starting into wxPython I did use wxDesigner. For the first steps into Qt (PySide at that time), I did use Qt Creator. But beyond the the first steps and getting used to sizers, currently you're better off with coding the GUI, probably utilizing your previous code for copy&paste (or with wxPython, copy&paste from the demo). Still, I would like to see a decent GUI builder with RAD features enabling also newcomers to write GUI programs. Most GUI programs just need a form to enter something and a start or save button to trigger the action. The steep learning curve for Python GUIs is holding back many people from using Python for e.g. measurement automatization. It's almost impossible to 'sell' a console-only environment in corporate environments. And the process that is required to implement a GUI using Qt Designer is not much of an improvement either. IMHO, as of today the only GUI builder that could be developed into this RAD direction is wxGlade. For Qt Designer it would be possible to bridge the gap by adapting an IDE, though (like Eric tries). Regards, Dietmar From nivaemail at gmail.com Tue Jun 7 15:28:59 2016 From: nivaemail at gmail.com (Ni Va) Date: Tue, 7 Jun 2016 12:28:59 -0700 (PDT) Subject: conception heritage or interface to multiprotocol read/write Message-ID: <83b94178-4af1-44af-a0bb-2f8105b3881d@googlegroups.com> Hi, In industrial project many protocols are often used for read/write goal at arrival. I would like to implement the better designed conception to enable read/write feature my main program. Example be abale to read/write on opc, s7 or others protocoles. If you have advices about this. Thank you Best Regards From r.koebler at yahoo.de Tue Jun 7 17:45:32 2016 From: r.koebler at yahoo.de (Roland Koebler) Date: Tue, 7 Jun 2016 23:45:32 +0200 Subject: Recommendation for GUI lib? In-Reply-To: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: <20160607214532.GA17231@localhost> Hi, the two "big" GUI toolkits on Linux are GTK+ and Qt. Both are free, have Python bindings and a graphical GUI designer, and both have ports for Windows and Mac OS X. Qt does have a better cross-platform- support and supports more platforms, but GTK+3 also works for Linux, Mac OS X and Windows. I myself prefer and recommend GTK+ (http://www.gtk.org), with Glade (https://glade.gnome.org/) as GUI-builder. I'm using it with Python for many years now. The major downside is, that the GTK+-documentation is mainly written for C, but there are many tutorials about Python + GTK+ out there, e.g. https://python-gtk-3-tutorial.readthedocs.io/. But be sure to use GTK+3 and the PyGObject/PyGI-binding and not the old PyGTK-binding (and ideally Python 3). You may also have a look at https://wiki.gnome.org/Projects/GTK+/OSX/Python You can also try Qt (http://qt.io), and one of its Python-bindings. But I was never happy with Qt and think some GUI-concepts of GTK+ are much better than the ones of Qt, and I like Glade much more than the Qt designer. best regards Roland From lawrencedo99 at gmail.com Tue Jun 7 17:57:06 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 14:57:06 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> Message-ID: On Wednesday, June 8, 2016 at 12:28:02 AM UTC+12, Dan Sommers wrote: > I notice plenty of break statements scattered throughout your loop > bodies. Mixing the loop's exit conditions in with the logic is equally > unstructured. Is this the old ?structured-programming-is-mathematically-equivalent-to-gotos? red herring again? From lawrencedo99 at gmail.com Tue Jun 7 17:58:26 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 14:58:26 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> Message-ID: <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> On Tuesday, June 7, 2016 at 11:53:46 PM UTC+12, Ian wrote: > On Tue, Jun 7, 2016 at 1:52 AM, Lawrence D?Oliveiro wrote: >> Wow, that?s only twice the length of the code you?re replacing. Well done. > > Huh? The example that you posted was 17 lines, excluding comments. My > replacement code is 17 lines, excluding comments. Where are you > getting "twice the length" from? Maybe not twice. But your code for dealing with the include stack was 16 lines, as opposed to 13 in mine. While elsewhere, you were criticizing my code for already being so terribly large... From marko at pacujo.net Tue Jun 7 18:06:53 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 08 Jun 2016 01:06:53 +0300 Subject: for / while else doesn't make sense References: <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> Message-ID: <87shwo4ps2.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > While elsewhere, you were criticizing my code for already being so > terribly large... Code can be large, only no function should be longer than ~70 lines or wider than 79 columns. If your function grows above that limit, you should refactor it and break it into multiple subroutines. Marko From lawrencedo99 at gmail.com Tue Jun 7 18:07:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 15:07:10 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <871t49mnse.fsf@elektro.pacujo.net> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <871t49mnse.fsf@elektro.pacujo.net> Message-ID: <64698d39-4a55-45f2-a7a1-1755eac44ed7@googlegroups.com> On Tuesday, June 7, 2016 at 8:00:31 PM UTC+12, Marko Rauhamaa wrote: > I understand you are hurt when your code is criticized bluntly. However, > you *did* stick your head out. Don?t worry, I am not the thin-skinned type. > I, too, insist that every function/method must be visible at once in the > editor window. >From subprocess.py in the Python 3.5 distribution: if _mswindows: # # Windows methods # def _get_handles(self, stdin, stdout, stderr): """Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite """ if stdin is None and stdout is None and stderr is None: return (-1, -1, -1, -1, -1, -1) p2cread, p2cwrite = -1, -1 c2pread, c2pwrite = -1, -1 errread, errwrite = -1, -1 if stdin is None: p2cread = _winapi.GetStdHandle(_winapi.STD_INPUT_HANDLE) if p2cread is None: p2cread, _ = _winapi.CreatePipe(None, 0) p2cread = Handle(p2cread) _winapi.CloseHandle(_) elif stdin == PIPE: p2cread, p2cwrite = _winapi.CreatePipe(None, 0) p2cread, p2cwrite = Handle(p2cread), Handle(p2cwrite) elif stdin == DEVNULL: p2cread = msvcrt.get_osfhandle(self._get_devnull()) elif isinstance(stdin, int): p2cread = msvcrt.get_osfhandle(stdin) else: # Assuming file-like object p2cread = msvcrt.get_osfhandle(stdin.fileno()) p2cread = self._make_inheritable(p2cread) if stdout is None: c2pwrite = _winapi.GetStdHandle(_winapi.STD_OUTPUT_HANDLE) if c2pwrite is None: _, c2pwrite = _winapi.CreatePipe(None, 0) c2pwrite = Handle(c2pwrite) _winapi.CloseHandle(_) elif stdout == PIPE: c2pread, c2pwrite = _winapi.CreatePipe(None, 0) c2pread, c2pwrite = Handle(c2pread), Handle(c2pwrite) elif stdout == DEVNULL: c2pwrite = msvcrt.get_osfhandle(self._get_devnull()) elif isinstance(stdout, int): c2pwrite = msvcrt.get_osfhandle(stdout) else: # Assuming file-like object c2pwrite = msvcrt.get_osfhandle(stdout.fileno()) c2pwrite = self._make_inheritable(c2pwrite) if stderr is None: errwrite = _winapi.GetStdHandle(_winapi.STD_ERROR_HANDLE) if errwrite is None: _, errwrite = _winapi.CreatePipe(None, 0) errwrite = Handle(errwrite) _winapi.CloseHandle(_) elif stderr == PIPE: errread, errwrite = _winapi.CreatePipe(None, 0) errread, errwrite = Handle(errread), Handle(errwrite) elif stderr == STDOUT: errwrite = c2pwrite elif stderr == DEVNULL: errwrite = msvcrt.get_osfhandle(self._get_devnull()) elif isinstance(stderr, int): errwrite = msvcrt.get_osfhandle(stderr) else: # Assuming file-like object errwrite = msvcrt.get_osfhandle(stderr.fileno()) errwrite = self._make_inheritable(errwrite) return (p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) Is that ?visible at once? in your editor window? From lawrencedo99 at gmail.com Tue Jun 7 18:08:38 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 15:08:38 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <87shwo4ps2.fsf@elektro.pacujo.net> References: <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> <87shwo4ps2.fsf@elektro.pacujo.net> Message-ID: <82e4fddc-5bf0-4b94-be07-7b5a24967e48@googlegroups.com> On Wednesday, June 8, 2016 at 10:07:05 AM UTC+12, Marko Rauhamaa wrote: > Lawrence D?Oliveiro: >> While elsewhere, you were criticizing my code for already being so >> terribly large... > > Code can be large, only no function should be longer than ~70 lines or > wider than 79 columns. If your function grows above that limit, you > should refactor it and break it into multiple subroutines. It already had lots of subfunctions, in case you hadn?t noticed... From torriem at gmail.com Tue Jun 7 18:34:42 2016 From: torriem at gmail.com (Michael Torrie) Date: Tue, 7 Jun 2016 16:34:42 -0600 Subject: Recommendation for GUI lib? In-Reply-To: <20160607214532.GA17231@localhost> References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> <20160607214532.GA17231@localhost> Message-ID: Accidentally didn't reply to the list... On 06/07/2016 03:45 PM, Roland Koebler via Python-list wrote: > You can also try Qt (http://qt.io), and one of its Python-bindings. > But I was never happy with Qt and think some GUI-concepts of GTK+ are much > better than the ones of Qt, and I like Glade much more than the Qt designer. Yes there are some concepts in regards to GUI layout that are different from Qt and GTK. Particularly how widgets are packed into boxes and how they resize. At first I didn't like the Qt model with its "spring" spacer thing. But I got used to it and found it was actually more flexible than GTK's packing method. Just a slightly different way of thinking about layout is all. I think the GTK bindings are a bit more comfortable in Python that Qt's are. Often times Qt apps turn out more like C++ apps transliterated into Python. They don't quite feel as "pythonic" as the GTK+ apps. Both are excellent toolkits. I think Qt is more complete and has more batteries included, particularly on the other platforms. For example, vector graphics. GTK+ defers that to Cairo. All that said, I still prefer GTK also. From ian.g.kelly at gmail.com Tue Jun 7 19:11:19 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Jun 2016 17:11:19 -0600 Subject: for / while else doesn't make sense In-Reply-To: <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> Message-ID: On Tue, Jun 7, 2016 at 3:58 PM, Lawrence D?Oliveiro wrote: > On Tuesday, June 7, 2016 at 11:53:46 PM UTC+12, Ian wrote: >> On Tue, Jun 7, 2016 at 1:52 AM, Lawrence D?Oliveiro wrote: > >>> Wow, that?s only twice the length of the code you?re replacing. Well done. >> >> Huh? The example that you posted was 17 lines, excluding comments. My >> replacement code is 17 lines, excluding comments. Where are you >> getting "twice the length" from? > > Maybe not twice. But your code for dealing with the include stack was 16 lines, as opposed to 13 in mine. Well, I don't know how you're counting that. All the code for dealing with the include stack is in the generate_lines function, which is 10 lines long. The remaining code is then simpler for not having to deal with it. In the original version, I can't identify which lines are "dealing with the include stack" because they're so intertwined. For example, all the sporadic code checking for line == None or line != None only need to exist because of the include stack. From harrison.chudleigh1 at education.nsw.gov.au Tue Jun 7 20:17:24 2016 From: harrison.chudleigh1 at education.nsw.gov.au (Harrison Chudleigh) Date: Wed, 8 Jun 2016 10:17:24 +1000 Subject: Possible PEP - two dimensional arrays? Message-ID: I was programming a computer game and found that while 1D arrays can be created using the module array, there is no module for two-dimensional arrays, unlike languages like C. Currently, the closest thing Python has to a 2D array is a dictionary containing lists. I propose that a module , 2DArray, be added to the standard library. This module will include: Assignment and retrieval on items on a two-dimensional, finite rectangular grid. Types are integer, float, character and string. Resizing the grid - parameters are old size and new size. Any new elements are initialized with a value of 0 for int, 0.0 for float and ' ' for string and character arrays. Removing elements. The parameter is the location. After removal, the value returned is 0 for int, 0.0 for float and ' ' for string and character arrays. A function, pop(), which removes elements from the grid and then returns them. Is this idea PEPable? ******************************************************************************* This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. From no.email at nospam.invalid Tue Jun 7 20:28:39 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Jun 2016 17:28:39 -0700 Subject: Possible PEP - two dimensional arrays? References: Message-ID: <8737oobk20.fsf@jester.gateway.pace.com> Harrison Chudleigh writes: > Currently, the closest thing Python has to a 2D array is a dictionary > containing lists. Tuples work fine: d = {} d[2,3] = 5 # etc... > Is this idea PEPable? I don't think it would get any traction. If you're doing something numerical that needs 2d arrays, numpy supports them. Actually, looking at your application, numpy might be what you want. From ned at nedbatchelder.com Tue Jun 7 20:31:48 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 7 Jun 2016 17:31:48 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <64698d39-4a55-45f2-a7a1-1755eac44ed7@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <871t49mnse.fsf@elektro.pacujo.net> <64698d39-4a55-45f2-a7a1-1755eac44ed7@googlegroups.com> Message-ID: <435147d0-ae1f-4095-a49c-1d032278179f@googlegroups.com> On Tuesday, June 7, 2016 at 6:07:23 PM UTC-4, Lawrence D?Oliveiro wrote: > On Tuesday, June 7, 2016 at 8:00:31 PM UTC+12, Marko Rauhamaa wrote: > > I understand you are hurt when your code is criticized bluntly. However, > > you *did* stick your head out. > > Don?t worry, I am not the thin-skinned type. > > > I, too, insist that every function/method must be visible at once in the > > editor window. > > From subprocess.py in the Python 3.5 distribution: > > if _mswindows: > # > # Windows methods > # > def _get_handles(self, stdin, stdout, stderr): > """Construct and return tuple with IO objects: > > ... 8< snip 8< ... > > errwrite = self._make_inheritable(errwrite) > > return (p2cread, p2cwrite, > c2pread, c2pwrite, > errread, errwrite) > > Is that ?visible at once? in your editor window? Lawrence, Marko didn't write that function. Marko didn't claim that all functions fit in a window, just that he wants his to. Lawrence writes code in an unusual style, not a style I would write in, but we aren't going to be able to change his mind. It seems like this discussion has gone beyond the productive stage. We aren't going to come to consensus on coding style. --Ned. From ned at nedbatchelder.com Tue Jun 7 20:38:13 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 7 Jun 2016 17:38:13 -0700 (PDT) Subject: Possible PEP - two dimensional arrays? In-Reply-To: References: Message-ID: <117c8a99-56eb-4369-9392-40d25d70697c@googlegroups.com> On Tuesday, June 7, 2016 at 8:19:33 PM UTC-4, Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Python has to > a 2D array is a dictionary containing lists. > > I propose that a module , 2DArray, be added to the standard library. This > module will include: > Assignment and retrieval on items on a two-dimensional, finite rectangular > grid. Types are integer, float, character and string. > Resizing the grid - parameters are old size and new size. Any new elements > are initialized with a value of 0 for int, 0.0 for float and ' ' for string > and character arrays. > Removing elements. The parameter is the location. After removal, the value > returned is 0 for int, 0.0 for float and ' ' for string and character > arrays. > A function, pop(), which removes elements from the grid and then returns > them. > > Is this idea PEPable? People who need arrays like this generally use numpy, which has good support for N-dimensional arrays and all of the operations you'd like on them. I don't think Python would consider adding something like this to the standard library since numpy is available. --Ned. From rgaddi at highlandtechnology.invalid Tue Jun 7 20:45:34 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 8 Jun 2016 00:45:34 -0000 (UTC) Subject: Possible PEP - two dimensional arrays? References: Message-ID: Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Python has to > a 2D array is a dictionary containing lists. > > I propose that a module , 2DArray, be added to the standard library. This > module will include: > Assignment and retrieval on items on a two-dimensional, finite rectangular > grid. Types are integer, float, character and string. > Resizing the grid - parameters are old size and new size. Any new elements > are initialized with a value of 0 for int, 0.0 for float and ' ' for string > and character arrays. > Removing elements. The parameter is the location. After removal, the value > returned is 0 for int, 0.0 for float and ' ' for string and character > arrays. > A function, pop(), which removes elements from the grid and then returns > them. > > Is this idea PEPable? > ******************************************************************************* > This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. You're looking for numpy. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From lawrencedo99 at gmail.com Tue Jun 7 21:25:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 18:25:09 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <435147d0-ae1f-4095-a49c-1d032278179f@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <871t49mnse.fsf@elektro.pacujo.net> <64698d39-4a55-45f2-a7a1-1755eac44ed7@googlegroups.com> <435147d0-ae1f-4095-a49c-1d032278179f@googlegroups.com> Message-ID: On Wednesday, June 8, 2016 at 12:32:01 PM UTC+12, Ned Batchelder wrote: > On Tuesday, June 7, 2016 at 6:07:23 PM UTC-4, Lawrence D?Oliveiro wrote: > > On Tuesday, June 7, 2016 at 8:00:31 PM UTC+12, Marko Rauhamaa wrote: > > > I understand you are hurt when your code is criticized bluntly. However, > > > you *did* stick your head out. > > > > Don?t worry, I am not the thin-skinned type. > > > > > I, too, insist that every function/method must be visible at once in the > > > editor window. > > > > From subprocess.py in the Python 3.5 distribution: > > > > if _mswindows: > > # > > # Windows methods > > # > > def _get_handles(self, stdin, stdout, stderr): > > """Construct and return tuple with IO objects: > > > > ... 8< snip 8< ... > > > > errwrite = self._make_inheritable(errwrite) > > > > return (p2cread, p2cwrite, > > c2pread, c2pwrite, > > errread, errwrite) > > > > Is that ?visible at once? in your editor window? > > Lawrence, Marko didn't write that function. Marko didn't claim that all > functions fit in a window, just that he wants his to. Given that he was (presumably) commenting on my code, naturally I understood his statement to apply to code that he had not written. From lawrencedo99 at gmail.com Tue Jun 7 21:29:46 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 18:29:46 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <435147d0-ae1f-4095-a49c-1d032278179f@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <871t49mnse.fsf@elektro.pacujo.net> <64698d39-4a55-45f2-a7a1-1755eac44ed7@googlegroups.com> <435147d0-ae1f-4095-a49c-1d032278179f@googlegroups.com> Message-ID: <7fb81ccb-f80b-4e7c-b9e7-40923ec9f60c@googlegroups.com> On Wednesday, June 8, 2016 at 12:32:01 PM UTC+12, Ned Batchelder wrote: > Lawrence writes code in an unusual style... ?Unusual? I can deal with. But when some people react with outrage, then it becomes clear they view my code as a personal attack. From ned at nedbatchelder.com Tue Jun 7 21:40:17 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 7 Jun 2016 18:40:17 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <7fb81ccb-f80b-4e7c-b9e7-40923ec9f60c@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <871t49mnse.fsf@elektro.pacujo.net> <64698d39-4a55-45f2-a7a1-1755eac44ed7@googlegroups.com> <435147d0-ae1f-4095-a49c-1d032278179f@googlegroups.com> <7fb81ccb-f80b-4e7c-b9e7-40923ec9f60c@googlegroups.com> Message-ID: On Tuesday, June 7, 2016 at 9:29:59 PM UTC-4, Lawrence D?Oliveiro wrote: > On Wednesday, June 8, 2016 at 12:32:01 PM UTC+12, Ned Batchelder wrote: > > > Lawrence writes code in an unusual style... > > ?Unusual? I can deal with. But when some people react with outrage, then it becomes clear they view my code as a personal attack. This is why we should drop it. It doesn't seem like people are trying to understand each other, just score points and prove each other wrong. That isn't going to lead anywhere good. --Ned. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Tue Jun 7 22:09:14 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Wed, 8 Jun 2016 03:09:14 +0100 Subject: pandas.datetime addition: What's wrong? Message-ID: Hi all! What's wrong with this? import pandas as pd x=pd.to_datetime("20160501") x+pd.DateOffset(days=1) Timestamp('2016-05-02 00:00:00', tz=None) x.__add__(pd.DateOffset(days=1)) NotImplemented More generally I have a class derived from pandas.datetime and I want to implement its own __add__ that at a given point call super __add__. For example: class C(pandas.datetime): ... def __add__(self,n): ... r=super(C,self).__add__(pd.DateOffset(days=n)) ... BTW, in the last line is it needed and how to "cast" self to pandas.datetime? Thanks for any help From lawrencedo99 at gmail.com Tue Jun 7 22:31:29 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 7 Jun 2016 19:31:29 -0700 (PDT) Subject: Creating A Pythonic API Binding Message-ID: <1ffd4be3-7d88-41f3-8f4a-46086224212a@googlegroups.com> The wrong way: ldo at theon:~> python2 Python 2.7.11+ (default, May 9 2016, 15:54:33) [GCC 5.3.1 20160429] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pymtp >>> mtp = pymtp.MTP() >>> mtp.connect() Device 0 (VID=04e8 and PID=6860) is a blah blah blah >>> topdirs = dict((t.name, t) for t in mtp.get_parent_folders()) >>> alldirs = mtp.get_folder_list() >>> photos_root = topdirs["DCIM"] >>> photos_dir = list(f for f in alldirs.values() if f.name == "Camera" and f.parent_id == photos_root.folder_id)[0] >>> print(list(f for f in mtp.get_filelisting() if f.parent_id == photos_dir.folder_id)) [IMG_20150502_141333.jpg (5184), IMG_20150502_141336.jpg (5185), etc] >>> mtp.disconnect() >>>^D The right way : ldo at theon:~> python3 Python 3.5.1+ (default, May 9 2016, 11:00:17) [GCC 5.3.1 20160429] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import mtpy >>> dev = mtpy.get_raw_devices()[0].open() Device 0 (VID=04e8 and PID=6860) is a blah blah blah >>> p = dev.get_descendant_by_path("/DCIM/Camera") >>> p.get_children() [, , etc] >>> dev.close() >>>^D From python at mrabarnett.plus.com Tue Jun 7 23:08:59 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 8 Jun 2016 04:08:59 +0100 Subject: pandas.datetime addition: What's wrong? In-Reply-To: References: Message-ID: On 2016-06-08 03:09, Paulo da Silva wrote: > Hi all! > > What's wrong with this? > > import pandas as pd > x=pd.to_datetime("20160501") > > x+pd.DateOffset(days=1) > Timestamp('2016-05-02 00:00:00', tz=None) > > x.__add__(pd.DateOffset(days=1)) > NotImplemented > > > More generally I have a class derived from pandas.datetime and I want to > implement its own __add__ that at a given point call super __add__. > > For example: > > class C(pandas.datetime): > ... > def __add__(self,n): > ... > r=super(C,self).__add__(pd.DateOffset(days=n)) > ... > BTW, in the last line is it needed and how to "cast" self to > pandas.datetime? > > Thanks for any help > When you have x+y, it tries x.__add__(y). If that fails, it then tries y.__radd__(x). Does that mean that the calculation above is actually implemented by the DateOffset class? Does pd.to_datetime return a datetime instance? I suspect what's happening is that it's returning NotImplemented because you're adding a DateOffset instance (from the pandas module) to a datetime instance returned by pd.to_datetime (from the datetime module), and the datetime class doesn't know about the DateOffset class. By calling the dunder method directly, you're not giving Python the opportunity to try the other dunder method. From ethan at stoneleaf.us Wed Jun 8 00:13:53 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 07 Jun 2016 21:13:53 -0700 Subject: for / while else doesn't make sense In-Reply-To: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> Message-ID: <57579B81.3020409@stoneleaf.us> On 06/01/2016 04:39 PM, Lawrence D?Oliveiro wrote: [multiple apparent trolls redacted] This thread is dead. Please stop beating it. -- ~Ethan~ From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Wed Jun 8 01:18:18 2016 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Wed, 8 Jun 2016 06:18:18 +0100 Subject: pandas.datetime addition: What's wrong? References: Message-ID: ?s 04:08 de 08-06-2016, MRAB escreveu: > On 2016-06-08 03:09, Paulo da Silva wrote: >> Hi all! >> ... >> >> More generally I have a class derived from pandas.datetime and I want to >> implement its own __add__ that at a given point call super __add__. >> >> For example: >> >> class C(pandas.datetime): >> ... >> def __add__(self,n): >> ... >> r=super(C,self).__add__(pd.DateOffset(days=n)) >> ... >> BTW, in the last line is it needed and how to "cast" self to >> pandas.datetime? >> ... > When you have x+y, it tries x.__add__(y). If that fails, it then tries > y.__radd__(x). That's it! > > Does that mean that the calculation above is actually implemented by the > DateOffset class? It seems so. Using __radd__ it works. > > Does pd.to_datetime return a datetime instance? Yes. > I still have the problem of self being C (not pandas.datetime). I tried self.__class__=pandas.datetime but it says something like "__class__ assignment: only for heap types" I don't know what this means. Using a new object op=pandas.datetime(self.year,self.month,self.day) works but it's too heavy :-) Thank you very much. From marko at pacujo.net Wed Jun 8 01:24:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 08 Jun 2016 08:24:09 +0300 Subject: for / while else doesn't make sense References: <7d453116-c02a-4211-836e-518f571c29a3@googlegroups.com> <4aafb237-4c41-4c0f-98ec-f71841c36bc1@googlegroups.com> <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <871t49mnse.fsf@elektro.pacujo.net> <64698d39-4a55-45f2-a7a1-1755eac44ed7@googlegroups.com> Message-ID: <87h9d445ja.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Tuesday, June 7, 2016 at 8:00:31 PM UTC+12, Marko Rauhamaa wrote: >> I, too, insist that every function/method must be visible at once in the >> editor window. > > From subprocess.py in the Python 3.5 distribution: > [...] > Is that ?visible at once? in your editor window? At home, no; at work, yes. Anyway, I didn't write that piece of code so my insisting doesn't affect it one way or another. Marko From marko at pacujo.net Wed Jun 8 01:27:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 08 Jun 2016 08:27:27 +0300 Subject: for / while else doesn't make sense References: <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> <87shwo4ps2.fsf@elektro.pacujo.net> <82e4fddc-5bf0-4b94-be07-7b5a24967e48@googlegroups.com> Message-ID: <87d1ns45ds.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Wednesday, June 8, 2016 at 10:07:05 AM UTC+12, Marko Rauhamaa wrote: >> Lawrence D?Oliveiro: > >>> While elsewhere, you were criticizing my code for already being so >>> terribly large... >> >> Code can be large, only no function should be longer than ~70 lines >> or wider than 79 columns. If your function grows above that limit, >> you should refactor it and break it into multiple subroutines. > > It already had lots of subfunctions, in case you hadn?t noticed... I didn't take a look at your code. Someone mentioned you had a 500-line function. Marko From greg.ewing at canterbury.ac.nz Wed Jun 8 01:59:24 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Jun 2016 17:59:24 +1200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <5755a2a5$0$1611$c3e8da3$5496439d@news.astraweb.com> <1465232248.1109132.629464689.31293D92@webmail.messagingengine.com> <5755c809$0$1622$c3e8da3$5496439d@news.astraweb.com> <1465247581.1161240.629720825.10FE129E@webmail.messagingengine.com> <87shwq56s8.fsf@elektro.pacujo.net> <1465312470.1376520.630519945.7DA4FE0E@webmail.messagingengine.com> Message-ID: Random832 wrote: > Er, how would that make them not first class? They wouldn't be as transparent as references in C++, which you just assign to like any other variable. That works because C++ makes a distinction between initialisation and assignment. It's not so easy to separate those in Python. > "Assign to the variable object that is in this > variable" would be a distinct operation from "Assign to this variable", > just like "add one to this value" or "call this function" etc. That would be like pointers in C that you have to explicitly dereference. I'm not sure whether C could be described as having "first class variables", though. If transparency is not required, you can easily create wrapper objects in Python that refer to an attribute or element of an object. -- Greg From tjreedy at udel.edu Wed Jun 8 03:07:50 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 8 Jun 2016 03:07:50 -0400 Subject: Possible PEP - two dimensional arrays? In-Reply-To: References: Message-ID: On 6/7/2016 8:17 PM, Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Python has to > a 2D array is a dictionary containing lists. A list of lists is standard if one is not using numpy, indexed as, for instance 'board[i][j]' A tuple of tuples can be used for static 2d array. I expect people have also used a list of arrays, though for most games, the space saving is not enough, plus a list of list is more flexible, in that one can put a 'piece' on and 'square'. > I propose that a module , 2DArray, be added to the standard library. This > module will include: > Assignment and retrieval on items on a two-dimensional, finite rectangular > grid. Types are integer, float, character and string. > Resizing the grid - parameters are old size and new size. Any new elements > are initialized with a value of 0 for int, 0.0 for float and ' ' for string > and character arrays. > Removing elements. The parameter is the location. After removal, the value > returned is 0 for int, 0.0 for float and ' ' for string and character > arrays. > A function, pop(), which removes elements from the grid and then returns > them. You could create your own class based on a list of arrays, and even publish it. -- Terry Jan Reedy From jobmattcon at gmail.com Wed Jun 8 03:31:29 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Wed, 8 Jun 2016 00:31:29 -0700 (PDT) Subject: how to extract a variable as parameter which has index using by a for loop? Message-ID: b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] b[21][0:1]+b[21][1:2] b[21][1:2]+b[21][2:3] b[21][0:1]+b[21][2:3] originally, mmm = 5 H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] how to extract b[i][0:1] and b[i][1:2] as parameters? def node(mmm, b[i][0:1], b[i][1:2]): H2 = [MM[mmm][A+B] for i in range(len(b))] return H2 node(5, b[i][0:1], b[i][1:2]) From antoon.pardon at rece.vub.ac.be Wed Jun 8 03:53:57 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 8 Jun 2016 09:53:57 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> Message-ID: <5757CF15.4010002@rece.vub.ac.be> Op 07-06-16 om 17:33 schreef Random832: > On Tue, Jun 7, 2016, at 08:32, Antoon Pardon wrote: >>> Here's a thought experiment for you. Suppose in Python 3.6, Guido announces >>> that Python will support a form of high-level pointer (not the scary, dangerous >>> low-level pointer of C) called "reference". There will be a dereference >>> operator, ^, and a "reference to" operator, @. We'll be able to treat >>> references as first-class values: >> That makes very little sense in python. > Why not? If you prefer, think of it something like: The fact that you can make it somehow work, doesn't mean it makes much sense. If you don't like the limitation of the assignment semantics in python, it seems more interresting to change that, than to work around what we have now. Python could go the simula route, which has two kinds of assignment. One with the python semantics and one with C semantics. Let as use := for the C sematics assignment and <- for the python sematics assignment. We could then do something like the following. ls := [5, 8, 13, 21] a <- ls[2] a := 34 print ls # [5, 8, 34, 21] Now it may very well be possible to achieve the same results with what you have in mind, but in my mind it makes not much sense in trying to achieve the semantics of a copy assignment by building extra indirection on top of reference assignments. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Wed Jun 8 04:08:01 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 8 Jun 2016 10:08:01 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5756f040$0$1591$c3e8da3$5496439d@news.astraweb.com> References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <5756f040$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5757D261.1060006@rece.vub.ac.be> Op 07-06-16 om 18:03 schreef Steven D'Aprano: > On Tue, 7 Jun 2016 10:32 pm, Antoon Pardon wrote: > >> That people often use the shortcut "x is 999" doesn't make the statement >> wrong that variables are essentially references in Python. > No, I'm sorry, you're wrong, variables are essentially arrays of bits in > Python. No they are not. The difference between variables as references and variables as containers is an abstract notions that comes to light in the semantics of the assignment, however these semantics are implemented. Talking about arrays of bits is talking about a specific implementation. You seem unable to think of a reference as an abstract model. -- Antoon Pardon From wxjmfauth at gmail.com Wed Jun 8 04:13:16 2016 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 8 Jun 2016 01:13:16 -0700 (PDT) Subject: Possible PEP - two dimensional arrays? In-Reply-To: References: Message-ID: <91fcebe4-2153-4ffa-8056-76180ed3ca43@googlegroups.com> Lists (list of lists) in action. >>> sys.version '3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)]' >>> >>> zz = vecmat.NewMat(3, 2) >>> zz[0][0] = 1.0; zz[0][1] = 2.0 >>> zz[1][0] = 3.0; zz[1][1] = 4.0 >>> zz[2][0] = 5.0; zz[2][1] = 5.0 >>> zz [[1.0, 2.0], [3.0, 4.0], [5.0, 5.0]] >>> vmio.pr(zz, 'zz=') zz= ( 1.00000e+000 2.00000e+000 ) ( 3.00000e+000 4.00000e+000 ) ( 5.00000e+000 5.00000e+000 ) >>> aa, b, cc = svdecomp.SVDecomp(zz) >>> bb = vecmat.VecToDiagMat(b) >>> cct = vecmat.TransposeMat(cc) >>> vmio.pr(aa, 'aa=') aa= ( 6.91451e-001 -2.42761e-001 ) ( 4.73049e-001 -5.59698e-001 ) ( -5.46004e-001 -7.92342e-001 ) >>> vmio.pr(bb, 'bb=') bb= ( 8.25102e-001 0.00000e+000 ) ( 0.00000e+000 8.90613e+000 ) >>> vmio.pr(cct, 'cct=') cct= ( -7.50721e-001 6.60619e-001 ) ( -6.60619e-001 -7.50721e-001 ) >>> rr = vecmat.MatMulMatMulMat(aa, bb, cct) >>> vmio.pr(rr, 'rr=') rr= ( 1.00000e+000 2.00000e+000 ) ( 3.00000e+000 4.00000e+000 ) ( 5.00000e+000 5.00000e+000 ) >>> From steve+comp.lang.python at pearwood.info Wed Jun 8 04:47:41 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 08 Jun 2016 18:47:41 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <87mvn22veg.fsf@rudin.co.uk> <13108bea-6750-443b-bee8-0532aba8b338@googlegroups.com> <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> Message-ID: <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> On Wednesday 08 June 2016 17:53, Antoon Pardon wrote: > Python could go the simula route, which has two kinds of > assignment. One with the python semantics and one with C > semantics. > > Let as use := for the C sematics assignment and <- for the > python sematics assignment. We could then do something like > the following. > > ls := [5, 8, 13, 21] > a <- ls[2] > a := 34 > print ls # [5, 8, 34, 21] What you seem to be describing is similar to reference parameter semantics from Pascal. Assignment doesn't work that way in C, or Python. In C, pointers can be used to simulate those semantics, but you have to explicitly dereference the pointer when you assign. Using C assignment, with an array: # excuse any minor syntax errors, my C is rusty int A[4] = {5, 8, 13, 21}; int n n = A[2]; n = 34; the array A does not change. Assignment *copies* the value into the variable. To get the semantics you are after, you need to use a pointer with an explicit dereference: int *p; p = &A[2]; *p = 34; which will now change the value of the array. If you leave the dereference out: p = 34; you are setting p to point to address 34, whatever that is. Now, the point is, in order to deserve the term "first class", you the programmer shouldn't have to care about manual dereferencing. In C, you do, so while you can get "reference variables" in C, they're only third class. In Pascal, they're second class, because you can get reference variables but only for function/procedure parameters. Pascal doesn't generalise that to allow references to any arbitrary variable. And of course Python doesn't have reference variables either. There is nothing you can do in Python to get this effect: a = 1 b = a b = 99 assert a == 99 although you can almost fake it using lists: a = [1] b = a b[0] = 99 assert a == [99] -- Steve From steve+comp.lang.python at pearwood.info Wed Jun 8 04:56:43 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 08 Jun 2016 18:56:43 +1000 Subject: how to extract a variable as parameter which has index using by a for loop? References: Message-ID: <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com> On Wednesday 08 June 2016 17:31, meInvent bbird wrote: > b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in > range(m)] > b[21][0:1]+b[21][1:2] > b[21][1:2]+b[21][2:3] > b[21][0:1]+b[21][2:3] > > > originally, > > mmm = 5 > H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] This is a mess. I don't understand what you are trying to do. You have these variable names that don't mean anything, like "b" and "H2", and others which aren't defined, like MM. I don't understand what you are trying to accomplish, or the purpose of your code. > how to extract b[i][0:1] and b[i][1:2] as parameters? I don't understand the question. > def node(mmm, b[i][0:1], b[i][1:2]): > H2 = [MM[mmm][A+B] for i in range(len(b))] > return H2 > > node(5, b[i][0:1], b[i][1:2]) Explain what node() is supposed to do, in English. Don't write any code yet. What is its purpose? What does it return? What arguments does it need to take in order to perform its purpose? -- Steve From steve+comp.lang.python at pearwood.info Wed Jun 8 05:04:24 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 08 Jun 2016 19:04:24 +1000 Subject: Creating A Pythonic API Binding References: <1ffd4be3-7d88-41f3-8f4a-46086224212a@googlegroups.com> Message-ID: <5757df9a$0$1504$c3e8da3$5496439d@news.astraweb.com> On Wednesday 08 June 2016 12:31, Lawrence D?Oliveiro wrote: > The wrong way: [...] > The right way : That's quite good. A few minor issues: I don't understand why you have a method that returns files called "get_children". And I would expect that if you passed a relative file name to create_folder() it should create a folder relative to (1) the current working directory, if the Device has such a concept; (2) your home or user directory, if the Device has such a concept; or (3) relative to the photos directory. Not relative to the root of the Device, that is very surprising. Also, it would be good if you could make dev a context manager, so that you don't have to manually close them: with mtpy.get_raw_devices()[0].open() as dev: p = dev.get_descendant_by_path("/DCIM/Camera") p.get_children() # dev is automatically closed But other than that, it looks quite nice. Thank you for posting the link. -- Steve From jobmattcon at gmail.com Wed Jun 8 05:20:42 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Wed, 8 Jun 2016 02:20:42 -0700 (PDT) Subject: how to extract a variable as parameter which has index using by a for loop? In-Reply-To: <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com> References: <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com> Message-ID: <190a4224-d05e-44e7-afba-0495e5dba59c@googlegroups.com> just extract b[i][0:1] and b[i][1:2] out of for loop but i depend on for loop def node(mmm, A, B): H2 = [MM[mmm][A+B] for i in range(len(b))] return H2 node(5, b[i][0:1], b[i][1:2]) it is not convenient to disclose in detail just expect to discuss from the view of programming On Wednesday, June 8, 2016 at 4:56:56 PM UTC+8, Steven D'Aprano wrote: > On Wednesday 08 June 2016 17:31, meInvent bbird wrote: > > > b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in > > range(m)] > > b[21][0:1]+b[21][1:2] > > b[21][1:2]+b[21][2:3] > > b[21][0:1]+b[21][2:3] > > > > > > originally, > > > > mmm = 5 > > H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] > > This is a mess. I don't understand what you are trying to do. You have these > variable names that don't mean anything, like "b" and "H2", and others which > aren't defined, like MM. I don't understand what you are trying to accomplish, > or the purpose of your code. > > > > how to extract b[i][0:1] and b[i][1:2] as parameters? > > I don't understand the question. > > > > def node(mmm, b[i][0:1], b[i][1:2]): > > H2 = [MM[mmm][A+B] for i in range(len(b))] > > return H2 > > > > node(5, b[i][0:1], b[i][1:2]) > > Explain what node() is supposed to do, in English. Don't write any code yet. > What is its purpose? What does it return? What arguments does it need to take > in order to perform its purpose? > > > -- > Steve From antoon.pardon at rece.vub.ac.be Wed Jun 8 05:41:20 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 8 Jun 2016 11:41:20 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5757E840.80805@rece.vub.ac.be> Op 08-06-16 om 10:47 schreef Steven D'Aprano: > On Wednesday 08 June 2016 17:53, Antoon Pardon wrote: > >> Python could go the simula route, which has two kinds of >> assignment. One with the python semantics and one with C >> semantics. >> >> Let as use := for the C sematics assignment and <- for the >> python sematics assignment. We could then do something like >> the following. >> >> ls := [5, 8, 13, 21] >> a <- ls[2] >> a := 34 >> print ls # [5, 8, 34, 21] > What you seem to be describing is similar to reference parameter semantics from > Pascal. Assignment doesn't work that way in C, or Python. I disagree. In python the assignment does work similar to the reference parameter semantics in pascal. See the following A = range[4] B = A B[2] = 5 print A # [0, 1, 5, 2] This is exactly the result you would get with B as a reference parameter in pascal. > And of course Python doesn't have reference variables either. There is nothing > you can do in Python to get this effect: > > a = 1 > b = a > b = 99 > assert a == 99 It is true that you can't get such an effect in python, but that doesn't imply that python doesn't have reference variables (as an abstract notion). Because having reference variables doesn't imply you can have that effect. If all you have is reference variables and assignments just change what object is refered to, you can't have such an effect either. -- Antoon Pardon. From liik.joonas at gmail.com Wed Jun 8 05:48:31 2016 From: liik.joonas at gmail.com (Joonas Liik) Date: Wed, 8 Jun 2016 12:48:31 +0300 Subject: how to extract a variable as parameter which has index using by a for loop? In-Reply-To: <190a4224-d05e-44e7-afba-0495e5dba59c@googlegroups.com> References: <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com> <190a4224-d05e-44e7-afba-0495e5dba59c@googlegroups.com> Message-ID: On 8 June 2016 at 12:20, meInvent bbird wrote: > just extract b[i][0:1] and b[i][1:2] out of for loop > > but i depend on for loop > > def node(mmm, A, B): > H2 = [MM[mmm][A+B] for i in range(len(b))] > return H2 > > node(5, b[i][0:1], b[i][1:2]) > > it is not convenient to disclose in detail > just expect to discuss from the view of programming > > On Wednesday, June 8, 2016 at 4:56:56 PM UTC+8, Steven D'Aprano wrote: >> On Wednesday 08 June 2016 17:31, meInvent bbird wrote: >> >> > b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in >> > range(m)] >> > b[21][0:1]+b[21][1:2] >> > b[21][1:2]+b[21][2:3] >> > b[21][0:1]+b[21][2:3] >> > >> > >> > originally, >> > >> > mmm = 5 >> > H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] >> >> This is a mess. I don't understand what you are trying to do. You have these >> variable names that don't mean anything, like "b" and "H2", and others which >> aren't defined, like MM. I don't understand what you are trying to accomplish, >> or the purpose of your code. >> >> >> > how to extract b[i][0:1] and b[i][1:2] as parameters? >> >> I don't understand the question. >> >> >> > def node(mmm, b[i][0:1], b[i][1:2]): >> > H2 = [MM[mmm][A+B] for i in range(len(b))] >> > return H2 >> > >> > node(5, b[i][0:1], b[i][1:2]) >> >> Explain what node() is supposed to do, in English. Don't write any code yet. >> What is its purpose? What does it return? What arguments does it need to take >> in order to perform its purpose? >> >> >> -- >> Steve > -- > https://mail.python.org/mailman/listinfo/python-list for a start.. a few things to improve readability.. (as well as perf maybe) b[i][0:1]+b[i][1:2] == b[i][0]+b[i][1] possibly dependant of on the data type of b[i] possibly.. b[i][0]+b[i][1] == b[i][0:2] also.. >> > b[21][0:1]+b[21][1:2] >> > b[21][1:2]+b[21][2:3] >> > b[21][0:1]+b[21][2:3] this is.. really confusing.. usually when you add things you would assign the result to something or use it in another way.. so this code looks like it is totally useless. it might not be 100% useless but if it is.. it is such horrible code u rly need to burn it with fire . since u use b[21] 6 times here you should just extract it as a separate variable eg.. b21 = b[21] A = b21[0:1]+b21[1:2] B = b21[1:2]+b21[2:3] C = b21[0:1]+b21[2:3] that is ofc if now this is rly interesting.. i think there is a big misunderstanding about what function arguments are.. def node(mmm, b[i][0:1], b[i][1:2]): H2 = [MM[mmm][A+B] for i in range(len(b))] return H2 node(5, b[i][0:1], b[i][1:2]) if i can guess your intent correctly.. what you actually want is sth like def node(mmm, b01, b12): # b01 = b[i][0:1]; b12 = b[i][1:2] # since you obviously omitted some code you might want to take in some other params as well.. like the variable ?b? for example. # i hope this is at least a little helpful, it really is hard to give constructive feedback if you cant even post the actual code nor can you give any info about what you are attempting to do H2 = [MM[mmm][A+B] for i in range(len(b))] return H2 node(5, b[i][0:1], b[i][1:2]) also it helps to give meaningful names to things, i guarantee next week even you will be having trouble reading this code... /now what the heck was that MM thing.. i wonder.. i could totally fix it if i only named it sth decent../ From kwa at kuwata-lab.com Wed Jun 8 05:52:05 2016 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Wed, 8 Jun 2016 18:52:05 +0900 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: Message-ID: On Tue, Jun 7, 2016 at 7:28 AM, Michael Selik wrote: > On Thu, Jun 2, 2016 at 10:06 AM Makoto Kuwata wrote: > >> I have a trouble around __import__(). >> > > The docs for __import__ strongly recommend that you use importlib instead > https://docs.python.org/3.5/library/importlib.html#importlib.import_module > > The docs for ``importlib.import_module`` suggest that you use > ``invalidate_caches`` if you are importing dynamically generated files. > > https://docs.python.org/3.5/library/importlib.html#importlib.invalidate_caches > > I think you'll find this fixes your bug. > Great! I replaced '__import__()' in my code with 'importlib.invalidate_cache(); importlib.import_module()' and found it worked very well. Thank you very much. -- regards, makoto From bc at freeuk.com Wed Jun 8 06:33:15 2016 From: bc at freeuk.com (BartC) Date: Wed, 8 Jun 2016 11:33:15 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> Message-ID: On 08/06/2016 10:41, Antoon Pardon wrote: > Op 08-06-16 om 10:47 schreef Steven D'Aprano: >> On Wednesday 08 June 2016 17:53, Antoon Pardon wrote: >> >>> Python could go the simula route, which has two kinds of >>> assignment. One with the python semantics and one with C >>> semantics. >>> >>> Let as use := for the C sematics assignment and <- for the >>> python sematics assignment. We could then do something like >>> the following. >>> >>> ls := [5, 8, 13, 21] >>> a <- ls[2] >>> a := 34 >>> print ls # [5, 8, 34, 21] >> What you seem to be describing is similar to reference parameter semantics from >> Pascal. Assignment doesn't work that way in C, or Python. > > I disagree. In python the assignment does work similar to the reference parameter > semantics in pascal. See the following > > A = range[4] > B = A > B[2] = 5 > print A # [0, 1, 5, 2] (Did you mean range(4) and [0, 1, 5, 3]?) > This is exactly the result you would get with B as a reference parameter in pascal. I can't remember exactly how Pascal worked. But your assignment to B[2] is an in-place modification. That sort of thing Python can do (when allowed as some things are not mutable) with its existing reference system. But a 'proper' reference allows a complete replacement of what it refers to. That would mean being able to do: B = "Cat" print A # "Cat" No tricks involving in-place updates such as assigning to list elements are needed. -- Bartc From rocky at gnu.org Wed Jun 8 06:38:47 2016 From: rocky at gnu.org (rocky) Date: Wed, 8 Jun 2016 03:38:47 -0700 (PDT) Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy Message-ID: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> For those who are interested in experimenting with parser systems in Python, there has been one around for a long while. But in my opinion it was a bit lacking in graded example demonstrating how to use it. So in the recently in spark_parser 1.3.0 [1], I've beefed up the examples a little. In addition to the example programs which give the classic arithmetic expression evaluator, I now include the beginnings of a full Python 2.6 language. The semantic routines just reformat the input which was parsed into a tree and spit that back out formatted according to predefined rules. Included is the grammar file from the 2.6.9 distribution. For those who want to go further and see a full production-like example, see the uncompyle6 github repository[2] which uses this. It reads bytecode from Python versions 2.3 to 3.5 or so and produces the corresponding Python 2 or Python 3 source code. Alternatively if you want to understand how uncompyle6 works, such as to improve it or fix bugs, you'll probably need to understand how the parser system it uses works. [1] https://pypi.python.org/pypi/spark_parser/1.3.0 [2] https://github.com/rocky/python-uncompyle6 From antoon.pardon at rece.vub.ac.be Wed Jun 8 07:01:47 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 8 Jun 2016 13:01:47 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> Message-ID: <5757FB1B.5000502@rece.vub.ac.be> Op 08-06-16 om 12:33 schreef BartC: > On 08/06/2016 10:41, Antoon Pardon wrote: >> Op 08-06-16 om 10:47 schreef Steven D'Aprano: >>> On Wednesday 08 June 2016 17:53, Antoon Pardon wrote: >>> >>>> Python could go the simula route, which has two kinds of >>>> assignment. One with the python semantics and one with C >>>> semantics. >>>> >>>> Let as use := for the C sematics assignment and <- for the >>>> python sematics assignment. We could then do something like >>>> the following. >>>> >>>> ls := [5, 8, 13, 21] >>>> a <- ls[2] >>>> a := 34 >>>> print ls # [5, 8, 34, 21] >>> What you seem to be describing is similar to reference parameter >>> semantics from >>> Pascal. Assignment doesn't work that way in C, or Python. >> >> I disagree. In python the assignment does work similar to the >> reference parameter >> semantics in pascal. See the following >> >> A = range[4] >> B = A >> B[2] = 5 >> print A # [0, 1, 5, 2] > > (Did you mean range(4) and [0, 1, 5, 3]?) Yes, sorry about that. > > But a 'proper' reference allows a complete replacement of what it > refers to. That would mean being able to do: > > B = "Cat" > print A # "Cat" > > No tricks involving in-place updates such as assigning to list > elements are needed. No it doesn't mean that. It means that if you mutate the object through one variable, you can see the result of that mutation through the other variable. But if the assignment doesn't mutate, you can't have such effect through assignment. In python, you can sometimes simulate a mutating assignment and then we get this. >>> A = [8, 5, 3, 2] >>> B = A >>> B[:] = [3, 5, 8, 13] >>> A [3, 5, 8, 13] From bc at freeuk.com Wed Jun 8 08:34:54 2016 From: bc at freeuk.com (BartC) Date: Wed, 8 Jun 2016 13:34:54 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> Message-ID: On 08/06/2016 12:01, Antoon Pardon wrote: > Op 08-06-16 om 12:33 schreef BartC: >> But a 'proper' reference allows a complete replacement of what it >> refers to. That would mean being able to do: >> >> B = "Cat" >> print A # "Cat" >> >> No tricks involving in-place updates such as assigning to list >> elements are needed. > > No it doesn't mean that. It means that if you mutate the object through one variable, > you can see the result of that mutation through the other variable. But if the > assignment doesn't mutate, you can't have such effect through assignment. > > In python, you can sometimes simulate a mutating assignment and then we get this. > > >>> A = [8, 5, 3, 2] > >>> B = A > >>> B[:] = [3, 5, 8, 13] > >>> A > [3, 5, 8, 13] Well, it then becomes necessary to separate a mutating assignment (a[i]=b) where the left-hand-size modifies part of a larger object, from a full assignment (a=b) which replaces a whole object (the value of a) with another. So you have partial updates and full updates. A proper reference will be able to do both via the reference. Python can only do a partial update and the reason is that the reference points to the object, not the variable; there is no way to change the variable to link it with another, distinct object. If the object is a list, then that can be modified to any extent, even replacing the contents completely, but it will still be a list. In the case of an int or string, then it's impossible to change. So there are limitations to what can be done. Getting back to Pascal (as I /can/ remember how reference parameters work for integers), assigning to a reference integer parameter in a function will change the caller's version. Python can only emulate that by passing a one-element list or using some such trick. Affecting readability and, likely, performance. -- Bartc From rustompmody at gmail.com Wed Jun 8 08:36:58 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 8 Jun 2016 05:36:58 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> Message-ID: <5b3d2ee1-6108-4ab2-af67-98c5e5cc58b6@googlegroups.com> On Wednesday, June 8, 2016 at 4:32:33 PM UTC+5:30, Antoon Pardon wrote: > It means that if you mutate the object through one variable, > you can see the result of that mutation through the other variable. But if the > assignment doesn't mutate, you can't have such effect through assignment. > Its called aliasing: https://en.wikipedia.org/wiki/Aliasing_%28computing%29 And is the principal reason why we need to talk in terms of pointer/references/box-n-arrows etc > In python, you can sometimes simulate a mutating assignment and then we get this. > > >>> A = [8, 5, 3, 2] > >>> B = A > >>> B[:] = [3, 5, 8, 13] > >>> A > [3, 5, 8, 13] Neat example -- thanks -- something for my tomorrow class More telling than the one I usually use to talk of this stuff which runs thus: >>> a=[[1,2,],[1,2]] >>> a [[1, 2], [1, 2]] >>> inner=[1,2] >>> b=[inner,inner] >>> b [[1, 2], [1, 2]] # So a and b look the same >>> a == b True # So even python thinks them the same # But Uh... oh... >>> a[0][0]=3 >>> a [[3, 2], [1, 2]] >>> b[0][0]=3 >>> b [[3, 2], [3, 2]] # They dont behave the same! From gandalf at shopzeus.com Wed Jun 8 09:02:23 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Wed, 8 Jun 2016 15:02:23 +0200 Subject: Recursive type annotations Message-ID: <8e439d4f-182d-334d-ffbe-8c39856cdd33@shopzeus.com> class Test: def test(self, child : Test): pass NameError: name 'Test' is not defined I understand that the class "Test" is not defined until the class definition is executed. But it is very very common to build recursive data structures, and I have concrete use case where the IDE did not recognize the type of the argument, and as a result it forgot to rename some method calls when I auto-refactored the name of the method. I'm not an expert, but I believe that these annotations are not used by the byte compiler for anything. This is just pure syntax introduced for the person who reads the code. Is there a known obsticle that would prevent us from detecting recursive type annotations? (E.g. bind the annotation to the class that is being defined.) Thanks, Laszlo From jon+usenet at unequivocal.co.uk Wed Jun 8 09:11:24 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Wed, 8 Jun 2016 13:11:24 -0000 (UTC) Subject: Recursive type annotations References: <8e439d4f-182d-334d-ffbe-8c39856cdd33@shopzeus.com> Message-ID: On 2016-06-08, Nagy L?szl? Zsolt wrote: > class Test: > def test(self, child : Test): > pass > > NameError: name 'Test' is not defined I think you can fix this by using a string annotation as follows: class Test: def test(self, child: "Test"): pass From michael.selik at gmail.com Wed Jun 8 09:24:29 2016 From: michael.selik at gmail.com (Michael Selik) Date: Wed, 08 Jun 2016 13:24:29 +0000 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: Message-ID: By the way, why choose to write, import, and delete modules? I'd think exec'ing code would be sufficient. On Wed, Jun 8, 2016, 5:52 AM Makoto Kuwata wrote: > On Tue, Jun 7, 2016 at 7:28 AM, Michael Selik > wrote: > >> On Thu, Jun 2, 2016 at 10:06 AM Makoto Kuwata wrote: >> >>> I have a trouble around __import__(). >>> >> >> The docs for __import__ strongly recommend that you use importlib instead >> https://docs.python.org/3.5/library/importlib.html#importlib.import_module >> >> The docs for ``importlib.import_module`` suggest that you use >> ``invalidate_caches`` if you are importing dynamically generated files. >> >> https://docs.python.org/3.5/library/importlib.html#importlib.invalidate_caches >> >> I think you'll find this fixes your bug. >> > > Great! > I replaced '__import__()' in my code with 'importlib.invalidate_cache(); > importlib.import_module()' > and found it worked very well. > Thank you very much. > > -- > regards, > makoto > > From gandalf at shopzeus.com Wed Jun 8 09:31:18 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Wed, 8 Jun 2016 15:31:18 +0200 Subject: Recursive type annotations In-Reply-To: References: <8e439d4f-182d-334d-ffbe-8c39856cdd33@shopzeus.com> Message-ID: <7de91f01-4b8c-8f29-294a-4f2f6909bc89@shopzeus.com> >> pass >> >> NameError: name 'Test' is not defined > I think you can fix this by using a string annotation as follows: > > class Test: > def test(self, child: "Test"): > pass Yes, you are right. It is not directly written in the official documentation ( https://docs.python.org/3/library/typing.html ), but it is in the PEP 0484, section "Forward references". Thanks! Laszlo From antoon.pardon at rece.vub.ac.be Wed Jun 8 10:18:22 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 8 Jun 2016 16:18:22 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> Message-ID: <5758292E.2020600@rece.vub.ac.be> Op 08-06-16 om 14:34 schreef BartC: > > So you have partial updates and full updates. A proper reference will > be able to do both via the reference. Python can only do a partial > update and the reason is that the reference points to the object, not > the variable; there is no way to change the variable to link it with > another, distinct object. > > If the object is a list, then that can be modified to any extent, even > replacing the contents completely, but it will still be a list. In the > case of an int or string, then it's impossible to change. So there are > limitations to what can be done. > > Getting back to Pascal (as I /can/ remember how reference parameters > work for integers), assigning to a reference integer parameter in a > function will change the caller's version. Python can only emulate > that by passing a one-element list or using some such trick. Affecting > readability and, likely, performance. > I don't see why we should determine what a /proper/ reference can do, based on what it does in one specific language. You can do something like that in simula, but only because simula has two kinds of assignments. One kind that is simular to python and one that is similar to C. The one that is similar that python is the reference assignment. I don't see why the variables in python wouldn't be reference variables, just because python lacks the "normal" assignment from simula. It is possible to write simula programs that almost exclusively use reference assignments. Limiting yourself like that, would also not allow you to do /proper/ referencing. It seems weird to refuse to call something a /proper/ reference, while what is missing is not a reference assignment but a mutating assignment. -- Antoon Pardon. From ian.g.kelly at gmail.com Wed Jun 8 10:58:22 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Jun 2016 08:58:22 -0600 Subject: Recursive type annotations In-Reply-To: <7de91f01-4b8c-8f29-294a-4f2f6909bc89@shopzeus.com> References: <8e439d4f-182d-334d-ffbe-8c39856cdd33@shopzeus.com> <7de91f01-4b8c-8f29-294a-4f2f6909bc89@shopzeus.com> Message-ID: On Wed, Jun 8, 2016 at 7:31 AM, Nagy L?szl? Zsolt wrote: > >>> pass >>> >>> NameError: name 'Test' is not defined >> I think you can fix this by using a string annotation as follows: >> >> class Test: >> def test(self, child: "Test"): >> pass > Yes, you are right. It is not directly written in the official > documentation ( https://docs.python.org/3/library/typing.html ), but it > is in the PEP 0484, section "Forward references". That link specifically documents the typing module. Forward references don't really have anything to do with the typing module and are best covered by the documentation of the static checker in use. Here's where the MyPy documentation covers it: http://mypy.readthedocs.io/en/latest/kinds_of_types.html#class-name-forward-references From marko at pacujo.net Wed Jun 8 12:37:46 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 08 Jun 2016 19:37:46 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> Message-ID: <871t474ox1.fsf@elektro.pacujo.net> Antoon Pardon : > You can do something like that in simula, but only because > simula has two kinds of assignments. One kind that is > simular to python and one that is similar to C. > The one that is similar that python is the reference assignment. I see Python as doing the exact same thing with variables as C. What is different is that in Python, every expression evaluates to a pointer. Thus, you can only assign pointers to variables. Marko From robin at reportlab.com Wed Jun 8 12:50:41 2016 From: robin at reportlab.com (Robin Becker) Date: Wed, 8 Jun 2016 17:50:41 +0100 Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy In-Reply-To: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> References: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> Message-ID: On 08/06/2016 11:38, rocky wrote: ........... > [1] https://pypi.python.org/pypi/spark_parser/1.3.0 ....... the page above shows one can implement a time travel machine as it boldly states "The original version of this was written by John Aycock and was described in his 1988 paper: ?Compiling Little Languages in Python? at the 7th International Python Conference." I suppose those early primitive pythons had some issue with integers as wackypedia states that "Python was conceived in the late 1980s[1] and its implementation was started in December 1989[2] by Guido van Rossum at CWI in the Netherlands" so that Aycocks's paper must have been at the -1st Python Conference -parallely yrs- Robin Becker From redstone-cold at 163.com Wed Jun 8 12:51:13 2016 From: redstone-cold at 163.com (iMath) Date: Wed, 8 Jun 2016 09:51:13 -0700 (PDT) Subject: Design an encrypted time-limited API on Client/Server side Message-ID: <3cef557f-bb1c-490a-a9ff-4c136cfdef2c@googlegroups.com> ?I am planning design an encrypted time-limited API on both Client and Server sides, the server side is written in Django, the client side is a GUI program which call the API by import requests c = requests.post("http://127.0.0.1:8000/VideoParser/", data={'videoUrl': videoUrl }) The way it call the API is desperately exposed to those who can use network traffic capturing tools like wireshark and fiddler, while I don't want anyone else could call the API with their customized videoUrl, and if people made the post call with the same parameters 2 minutes later after the client initially made the call, the call should be valid or expired, so how to design the encrypted time-limited API on both Client and Server side in this case ? P.S. I think add an identifier to the post data could prevent them using the API import requests c = requests.post("http://127.0.0.1:8000/VideoParser/", data={'videoUrl': videoUrl, 'identifier':value_of_identifier }) provided there is something encrypted in the value_of_identifier and it changes with each call, but I don't know how to get started, any idea ? It would be better to show some code , I really don't know which modules to use and how to start to write code. From Joaquin.Alzola at lebara.com Wed Jun 8 13:04:11 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Wed, 8 Jun 2016 17:04:11 +0000 Subject: Design an encrypted time-limited API on Client/Server side In-Reply-To: <3cef557f-bb1c-490a-a9ff-4c136cfdef2c@googlegroups.com> References: <3cef557f-bb1c-490a-a9ff-4c136cfdef2c@googlegroups.com> Message-ID: > I am planning design an encrypted time-limited API on both Client and Server sides, If you want client/server communitation in an encypted way you can use the ssl module. 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 bc at freeuk.com Wed Jun 8 13:29:06 2016 From: bc at freeuk.com (BartC) Date: Wed, 8 Jun 2016 18:29:06 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> Message-ID: On 08/06/2016 15:18, Antoon Pardon wrote: > Op 08-06-16 om 14:34 schreef BartC: >> >> So you have partial updates and full updates. A proper reference will >> be able to do both via the reference. Python can only do a partial >> update and the reason is that the reference points to the object, not >> the variable; there is no way to change the variable to link it with >> another, distinct object. >> >> If the object is a list, then that can be modified to any extent, even >> replacing the contents completely, but it will still be a list. In the >> case of an int or string, then it's impossible to change. So there are >> limitations to what can be done. >> >> Getting back to Pascal (as I /can/ remember how reference parameters >> work for integers), assigning to a reference integer parameter in a >> function will change the caller's version. Python can only emulate >> that by passing a one-element list or using some such trick. Affecting >> readability and, likely, performance. >> > I don't see why we should determine what a /proper/ reference > can do, based on what it does in one specific language. Because there are some things that such references can do that Python can't do with its object reference model, not without some difficulty or having to write convoluted code. And it doesn't really depend on the language as the differences are easy to demonstrate, provided the language still has something along the lines of: a = b to do normal assignment. (1) Reference parameters def fn(&x): x=1000 a="ABC" fn(a) print (a) # should produce 1000 I've used "&" here as a device to make the 'x' param work as though it was passed by reference. That is, an /additional/ reference to the one Python might already use behind the scenes. (2) Replace (not just modify) a variable's value and type indirectly a = 17 p = &a *p = "Dog" print a # should be "Dog" Here "&" and "*" are used to indicate possible 'reference'/dereference operations. With the last example, then this Python code: a = 17 p = a Might result in the following internal structures: 0x300:a:[pyref:0x10020] Variable 0x400:p:[pyref:0x10020] Variable 0x10020:[int: 17] Object With the p = &a version, it would be more like: 0x300:a:[pyref:0x10020] Variable 0x400:p:[pyref:0x10040] Variable 0x10020:[int: 17] Object 0x10040:[varref: 0x300] Object It's that 0x300 reference to 'a' itself, not just the object linked to it, that is what Python can't do. -- Bartc From rocky at gnu.org Wed Jun 8 14:32:13 2016 From: rocky at gnu.org (rocky) Date: Wed, 8 Jun 2016 11:32:13 -0700 (PDT) Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy In-Reply-To: References: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> Message-ID: On Wednesday, June 8, 2016 at 12:50:57 PM UTC-4, Robin Becker wrote: > On 08/06/2016 11:38, rocky wrote: > ........... > > [1] https://pypi.python.org/pypi/spark_parser/1.3.0 > ....... > the page above shows one can implement a time travel machine as it boldly states > > "The original version of this was written by John Aycock and was described in > his 1988 paper: ?Compiling Little Languages in Python? at the 7th International > Python Conference." > > I suppose those early primitive pythons had some issue with integers as > wackypedia states that > > "Python was conceived in the late 1980s[1] and its implementation was started in > December 1989[2] by Guido van Rossum at CWI in the Netherlands" > > so that Aycocks's paper must have been at the -1st Python Conference > -parallely yrs- > Robin Becker Sorry that should have been 1998 which would make more sense for the 7th conference if the 1st one was around 2001. I've corrected the date in [1] https://pypi.python.org/pypi/spark_parser/1.3.0 The automated tests in the package just don't catch stuff like this. But I'm sure there are also other mistakes as well in there so feel free to let me know. From torriem at gmail.com Wed Jun 8 14:59:04 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 8 Jun 2016 12:59:04 -0600 Subject: Possible PEP - two dimensional arrays? In-Reply-To: References: Message-ID: On 06/07/2016 06:17 PM, Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Python has to > a 2D array is a dictionary containing lists. I think you meant to say a list of lists. Which is actually analogous to how C implements them. From ben+python at benfinney.id.au Wed Jun 8 16:26:58 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jun 2016 06:26:58 +1000 Subject: MAthematical formula terms make for terrible names in a program (was: What's good for mathematical formulas can be bad for program code (was: how to extract a variable as parameter which has index using by a for loop?)) References: <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85eg871l65.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > On Wednesday 08 June 2016 17:31, meInvent bbird wrote: > > > H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] > > This is a mess. I don't understand what you are trying to do. You have > these variable names that don't mean anything, like "b" and "H2", and > others which aren't defined, like MM. I don't understand what you are > trying to accomplish, or the purpose of your code. The nice thing about mathematical formulas is that one has latitude, in the accompanying academic paper, to define at length the single-character names. This means the formulas are briefer to write by hand on the blackboard, and the reader can refer to the author's extensive explanation of what the character means. Mathematicians (and other scientists), please don't attempt to cram meaning into single-letter names in your program code. None of the above advantages apply, and we get only the disadvantages Steven describes. Instead, choose meaningful names that someone who knows that meaning has at least a better-than-random chance of remembering. -- \ ?The fundamental principle of science, the definition almost, | `\ is this: the sole test of the validity of any idea is | _o__) experiment.? ?Richard P. Feynman | Ben Finney From ben+python at benfinney.id.au Wed Jun 8 16:28:20 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jun 2016 06:28:20 +1000 Subject: how to extract a variable as parameter which has index using by a for loop? References: <5757ddcd$0$1520$c3e8da3$5496439d@news.astraweb.com> <190a4224-d05e-44e7-afba-0495e5dba59c@googlegroups.com> Message-ID: <85a8iv1l3v.fsf@benfinney.id.au> meInvent bbird writes: > it is not convenient to disclose in detail > just expect to discuss from the view of programming It is not convenient to discuss programming without a good understanding of what the program is meant to do. (Also, please don't top-post, instead post your responses interleaved .) -- \ ?The most dangerous man to any government is the man who is | `\ able to think things out for himself, without regard to the | _o__) prevailing superstitions and taboos.? ?Henry L. Mencken | Ben Finney From maillist at schwertberger.de Wed Jun 8 17:36:59 2016 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Wed, 8 Jun 2016 23:36:59 +0200 Subject: Recommendation for GUI lib? In-Reply-To: <20160607214532.GA17231@localhost> References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> <20160607214532.GA17231@localhost> Message-ID: <9c24a85f-0bb4-5728-c8cb-a9a3e6ca9f6d@schwertberger.de> On 07.06.2016 23:45, Roland Koebler via Python-list wrote: > Both are free, have Python bindings and a graphical GUI designer, and both > have ports for Windows and Mac OS X. Qt does have a better cross-platform- > support and supports more platforms, but GTK+3 also works for Linux, Mac > OS X and Windows. What is the current state and quality of GTK for Windows and Mac OS? IIRC it's not too long that Wing IDE was moved from PyGTK to Qt due to the problems under Windows and MacOS. Regards, Dietmar From nevzat.guler at gmail.com Wed Jun 8 18:11:01 2016 From: nevzat.guler at gmail.com (nevzat.guler at gmail.com) Date: Wed, 8 Jun 2016 15:11:01 -0700 (PDT) Subject: movie from pictures Message-ID: Dear Users, I am trying to combine several pictures to create a movie file. I create the pictures in a loop. I would like to add each picture to a movie within the loop, like it is done in MATLAB. However, it is also acceptable to create all the picture in the loop, afterwards use some ffmpeg command to combine them into a picture. I actually tried the latter option but i ran into trouble with paths because the picture location and python code are in different places. The former method is also better because I would like to use variable name for the picture names, instead of their given name, which are long and have spaces, special characters in them.. I will appreciate any guidance here. From greg.ewing at canterbury.ac.nz Wed Jun 8 18:22:45 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 09 Jun 2016 10:22:45 +1200 Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy In-Reply-To: References: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> Message-ID: Robin Becker wrote: > "Python was conceived in the late 1980s[1] and its implementation was > started in December 1989[2] by Guido van Rossum at CWI in the Netherlands" > > so that Aycocks's paper must have been at the -1st Python Conference When the time machine was invented, Guido thought it would be fun to go back and hold a Python conference a little before Python actually existed, to mess with future historians trying to put together a timeline for Python development. -- Greg From lawrencedo99 at gmail.com Wed Jun 8 20:32:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 8 Jun 2016 17:32:10 -0700 (PDT) Subject: movie from pictures In-Reply-To: References: Message-ID: <7e57c662-a6c2-441d-a46e-49458439250f@googlegroups.com> On Thursday, June 9, 2016 at 10:11:16 AM UTC+12, Nev wrote: > ... afterwards use some ffmpeg command to combine them into a picture. This is a very common use case for FFmpeg. 1) Generate your frames in some high-quality lossless format, like PNG. 2) Name them sequentially ?0001.png?, ?0002.png? etc. (Assuming 4 digits is enough here.) 3) Use an FFmpeg command like ffmpeg -i /input-dir/%04d.png ?output settings? ?output filename? to generate the final movie. By keeping the full-quality frames from step 2, you can retry step 3 with different encoding settings to see which works best. You can even try two-pass encoding for best quality. From lawrencedo99 at gmail.com Wed Jun 8 20:34:57 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 8 Jun 2016 17:34:57 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <87d1ns45ds.fsf@elektro.pacujo.net> References: <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> <87shwo4ps2.fsf@elektro.pacujo.net> <82e4fddc-5bf0-4b94-be07-7b5a24967e48@googlegroups.com> <87d1ns45ds.fsf@elektro.pacujo.net> Message-ID: <54890c12-388e-4923-888f-bd611a0c2076@googlegroups.com> On Wednesday, June 8, 2016 at 5:27:41 PM UTC+12, Marko Rauhamaa wrote: > Someone mentioned you had a 500-line function. In my undergraduate Comp Sci classes, we used to discuss arbitrary rules like limiting functions to n lines. With real-world experience, it soon became clear that such rules were a waste of time. A function should be just as big as it needs to be, no more, no less. The same with a class, or a module. Or whatever other constructs your language may have. From lawrencedo99 at gmail.com Wed Jun 8 22:49:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 8 Jun 2016 19:49:09 -0700 (PDT) Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <871t474ox1.fsf@elektro.pacujo.net> References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> Message-ID: On Thursday, June 9, 2016 at 4:37:58 AM UTC+12, Marko Rauhamaa wrote: > I see Python as doing the exact same thing with variables as C. > > What is different is that in Python, every expression evaluates to a > pointer. Thus, you can only assign pointers to variables. Yup. I think some people are getting confused over assignment to simple variables as opposed to more complex expressions on the LHS of assignments in Python. For example, given a = [1, 2, 3, 4] compare the different effects of b = a b = a[:] b[:] = a # assuming b already has an appropriate initial value not to mention other possibilities... From chris at simplistix.co.uk Thu Jun 9 01:17:23 2016 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 9 Jun 2016 00:17:23 -0500 Subject: xlwt 1.1.2 released! Message-ID: <8a1ef71e-a11d-03da-b432-c9b85d48814a@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlwt 1.1.2. This release contains the following: - Fix failure in style compression under Python 3. - Documentation tweaks. If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlwt/issues There's also details of all things Python and Excel related here: http://www.python-excel.org/ NB: If you would like to become the maintainer of xlwt, please get in touch! Neither myself nor John Machin have much time to drive things forward nowadays, hence the year or so between each release... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Thu Jun 9 01:30:52 2016 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 9 Jun 2016 00:30:52 -0500 Subject: xlutils 2.0.0 released! Message-ID: Hi All, I'm pleased to announce the release of xlutils 2.0.0: http://pypi.python.org/pypi/xlutils/2.0.0 This release has a couple of small changes: - Updated documentation. - Move to virtualenv/pip based development. - Move to Read The Docs for documentation. - Use Travis CI for testing and releases. - Use features of newer testfixtures in xlutils.view.CheckerView. - Python 3 compatibility. Full docs here: http://xlutils.readthedocs.org/ Details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From lawrencedo99 at gmail.com Thu Jun 9 01:36:43 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 8 Jun 2016 22:36:43 -0700 (PDT) Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy In-Reply-To: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> References: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> Message-ID: On Wednesday, June 8, 2016 at 10:39:00 PM UTC+12, rocky wrote: > In addition to the example programs which give the classic arithmetic > expression evaluator, I now include the beginnings of a full Python 2.6 > language. Does anybody bother with LR(k) parsers any more? From jobmattcon at gmail.com Thu Jun 9 02:02:05 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Wed, 8 Jun 2016 23:02:05 -0700 (PDT) Subject: run code error with numpy and scipy Message-ID: <62df152e-8fc6-47c5-aa44-f2da4094c140@googlegroups.com> when i run code in window has an error not a valid win32 dll then i install scipy first in this site, then install numpy-mkl all python 2.7 and win32 http://www.lfd.uci.edu/~gohlke/pythonlibs/ then i run code below, got error , and captured screen in this link https://drive.google.com/file/d/0Bxs_ao6uuBDUQXROd2VqSURGa00/view?usp=sharing import numpy as np from scipy.sparse.linalg import svds from functools import partial from scipy.sparse import csr_matrix def emsvd(Y, k=None, tol=1E-3, maxiter=None): if k is None: svdmethod = partial(np.linalg.svd, full_matrices=False) else: svdmethod = partial(svds, k=k) if maxiter is None: maxiter = np.inf muhat = np.nanmean(Y, axis=0, keepdims=1) valid = np.isfinite(Y) Y_hat = np.where(valid, Y, muhat) halt = False ii = 1 v_prev = 0 while not halt: U, s, Vt = svdmethod(Y_hat - muhat) Y_hat[~valid] = (U.dot(np.diag(s)).dot(Vt) + muhat)[~valid] muhat = Y_hat.mean(axis=0, keepdims=1) v = s.sum() if ii >= maxiter or ((v - v_prev) / v_prev) < tol: halt = True ii += 1 v_prev = v return Y_hat, muhat, U, s, Vt A = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]]) emsvd(A) np.nanmean(A, axis=0, keepdims=1) From ben+python at benfinney.id.au Thu Jun 9 02:27:52 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jun 2016 16:27:52 +1000 Subject: run code error with numpy and scipy References: <62df152e-8fc6-47c5-aa44-f2da4094c140@googlegroups.com> Message-ID: <85r3c6zxjr.fsf@benfinney.id.au> meInvent bbird writes: > when i run code in window has an error not a valid win32 dll Simplify the example, to diagnose it. What is the *simplest* example code that shows the problem? In other words, remove statements from the example until the problem no longer happens. Then add back *one* statement to make it happen, and present that example. -- \ ?I have had a perfectly wonderful evening, but this wasn't it.? | `\ ?Groucho Marx | _o__) | Ben Finney From davidbenny2000 at gmail.com Thu Jun 9 02:52:24 2016 From: davidbenny2000 at gmail.com (Ho Yeung Lee) Date: Wed, 8 Jun 2016 23:52:24 -0700 (PDT) Subject: which library has map reduce and how to use it for this case Message-ID: <1ca428db-ea39-4964-a662-df2701580bd2@googlegroups.com> i got M1 to M5 and V6 operator and would like to do a full combination and result will also act among each other, map reduce attract my application how to use this in this example? actually below is like vlookup then example is op3(op2(op1(x->y, y->z)), x->z) search which combinations will result in a column result is 1 M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=1 M1['02']=1 M1['10']=1 M1['11']=1 M1['12']=1 M1['20']=1 M1['21']=1 M1['22']=1 M2['00']=0 M2['01']=0 M2['02']=1 M2['10']=0 M2['11']=1 M2['12']=1 M2['20']=1 M2['21']=1 M2['22']=1 M3['00']=0 M3['01']=0 M3['02']=0 M3['10']=0 M3['11']=1 M3['12']=1 M3['20']=0 M3['21']=1 M3['22']=1 M4['00']=0 M4['01']=1 M4['02']=0 M4['10']=1 M4['11']=1 M4['12']=1 M4['20']=0 M4['21']=1 M4['22']=1 M5['00']=0 M5['01']=0 M5['02']=0 M5['10']=0 M5['11']=1 M5['12']=1 M5['20']=0 M5['21']=1 M5['22']=1 V6['00']=1 V6['01']=1 V6['02']=1 V6['10']=1 V6['11']=1 V6['12']=1 V6['20']=0 V6['21']=1 V6['22']=1 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] b[21][0:1]+b[21][1:2] b[21][1:2]+b[21][2:3] b[21][0:1]+b[21][2:3] #def node(mmm, A): #H2 = [MM[mmm][b[i][0:1]+b[i][1:2]] for i in range(len(b))] #return H2 #node(5, b[i][0:1]+b[i][1:2]) H2 = [MM[5][b[i][0:1]+b[i][1:2]] for i in range(len(b))] H3 = [MM[5][b[i][0:1]+b[i][1:2]] for i in range(len(b))] [str(k)+str(v) for k, v in zip(H2, H3)] import itertools deep = 3 finalresult = [] def DFS(H2, H3, b, deep, mresult) mylist = [i for i in range(0,7-1)] for aa,bb in itertools.combinations(mylist, 2): print(aa,bb) if deep == 3: #op0, op1 op1xy = [MM[aa][b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [MM[aa][b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [MM[aa][b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [MM[bb][b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [MM[bb][b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [MM[bb][b[i][0:1]+b[i][2:3]] for i in range(len(b))] mresult.append(op1xy) mresult.append(op1yz) mresult.append(op1xz) mresult.append(op2xy) mresult.append(op2yz) mresult.append(op2xz) else: H1 = H2 H9 = H3 ba = b b = [str(k)+str(v) for k, v in zip(H2, H3)] DFS(H1, H9, b) b = ba DFS(0, 0, 0, 3, finalresult) From dieter at handshake.de Thu Jun 9 02:55:34 2016 From: dieter at handshake.de (dieter) Date: Thu, 09 Jun 2016 08:55:34 +0200 Subject: Design an encrypted time-limited API on Client/Server side References: <3cef557f-bb1c-490a-a9ff-4c136cfdef2c@googlegroups.com> Message-ID: <87oa7a7swp.fsf@handshake.de> iMath writes: > ?I am planning design an encrypted time-limited API on both Client and Server sides, the server side is written in Django, the client side is a GUI program which call the API by > import requests > c = requests.post("http://127.0.0.1:8000/VideoParser/", data={'videoUrl': videoUrl }) > The way it call the API is desperately exposed to those who can use network traffic capturing tools like wireshark and fiddler You could require the "https" protocol to prevent this. > while I don't want anyone else could call the API with their customized videoUrl, and if people made the post call with the same parameters 2 minutes later after the client initially made the call, the call should be valid or expired, so how to design the encrypted time-limited API on both Client and Server side in this case ? There is a general concept of "one-time-url" to handle cases such as this one. These are urls which can be used just once. Usually, they have associated an expiration date and an uuid. The uuid is used on the server to maintain state (still unused, already used); the expiration date allows state cleanup. From gandalf at shopzeus.com Thu Jun 9 03:28:34 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 09:28:34 +0200 Subject: what is wrong with this property setter Message-ID: class Test: def __init__(self): self._parent = None @property def parent(self): return self._parent @parent.setter def set_parent(self, new_parent): self._parent = new_parent p, c = Test(), Test() c.parent = p >py -3 test.py Traceback (most recent call last): File "test.py", line 15, in c.parent = p AttributeError: can't set attribute BTW this does work, but it is not that elegant: class Test: def __init__(self): self._parent = None def get_parent(self): return self._parent def set_parent(self, new_parent): self._parent = new_parent parent = property(get_parent, set_parent) p, c = Test(), Test() c.parent = p From antoon.pardon at rece.vub.ac.be Thu Jun 9 03:30:41 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 09:30:41 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <871t474ox1.fsf@elektro.pacujo.net> References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> Message-ID: <57591B21.7050509@rece.vub.ac.be> Op 08-06-16 om 18:37 schreef Marko Rauhamaa: > Antoon Pardon : > >> You can do something like that in simula, but only because >> simula has two kinds of assignments. One kind that is >> simular to python and one that is similar to C. >> The one that is similar that python is the reference assignment. > I see Python as doing the exact same thing with variables as C. > > What is different is that in Python, every expression evaluates to a > pointer. Thus, you can only assign pointers to variables. Then you think wrong. Python has no pointers, that is an implementation detail. In python when you have two variables, and you assign one to the other you then have two variables that share an object. In C when you have two variables and you assign one to the other you then have two variable each refering to their own object that are copies of each other. And yes that sharing of variables in python can be simulated by copying pointers in C. Maybe the simularities between variables in python can be made isomorphic with a specific subset of pointer operations in C. The fact is that such an isomorphism would be limited to specific pointer operations and would not extend to how variable generally behave in C. In a rather straight forward environment with classes/structs that have an x and y attribute, the following lines behave differently in C and Python. A.x = 1; A.y = 2; B = A; B.x = 3; B.y = 4; In C the variable A will still be x:1, y:2. In Python the variable A will be x:3, y:4. So no, Python doesn't do the exact same thing with variables as C. -- Antoon Pardon. From steve+comp.lang.python at pearwood.info Thu Jun 9 03:36:30 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 09 Jun 2016 17:36:30 +1000 Subject: I'm wrong or Will we fix the ducks limp? References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> Message-ID: <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> On Wednesday 08 June 2016 19:41, Antoon Pardon wrote: >> What you seem to be describing is similar to reference parameter semantics >> from Pascal. Assignment doesn't work that way in C, or Python. > > I disagree. In python the assignment does work similar to the reference > parameter semantics in pascal. See the following > > A = range[4] > B = A > B[2] = 5 > print A # [0, 1, 5, 2] > > This is exactly the result you would get with B as a reference parameter in > pascal. It might be the same result, but it is a different cause. Your example demonstrates object mutation, not assignment. Although Python uses the same syntax X = X for both name binding (assignment) and item assignment, item assignment is a *mutator method*: it calls B.__setitem__, which modifies B in place. Since the name A is bound to the same object, it is hardly surprising that A shows the same change. But since you think that assignment in Python behaves like Pascal var parameters (reference variables), you should be able to write a "swap" procedure that swaps two arguments. That's the definitive test for reference parameters, since it works in all languages with reference parameters (e.g. Pascal, Basic and C++), and doesn't work in any language without them (or equivalent, like Algol's pass-by-name parameters). The Pythonic way to swap two variables is to use tuple unpacking: a, b = b, a but that uses a completely different mechanism to get the same effect. "Reference parameter" is all about mechanism. I want to see the Python equivalent of Pascal's var parameters: procedure swap(var a:integer; var b:integer); var temp: integer; begin temp := a; a := b; b := a; end; (or the Algol equivalent, a slightly different mechanism), and then see it called like this: a = 1 b = 2 swap(a, b) # absolutely NOT `a, b = swap(a, b)` assert a == 2 and b == 1 without passing in or making use of hard-coded parameter names. That is my challenge to you: if you can write such a function, in pure Python, which swaps two parameters given as ordinary arguments (passing their names as strings does not count), then I will cheerfully apologise for doubting you, admit that I was wrong, and publicly acknowledge that Python does have reference variables just like you said. If you cannot meet that challenge, then I would like you to acknowledge that whatever Python variables are, and however Python's assignment works, it is *not* the same as Pascal's reference variables, and so calling Python variables "reference variables" is misleading and an abuse of a well-established term from computer science since long before Python even existed. Are you willing to accept that challenge? Or are you going to try to weasel out of it by changing the definition of reference parameter to mean "whatever I want it to mean to avoid admitting I was wrong"? >> And of course Python doesn't have reference variables either. There is >> nothing you can do in Python to get this effect: >> >> a = 1 >> b = a >> b = 99 >> assert a == 99 > > It is true that you can't get such an effect in python, but that doesn't > imply that python doesn't have reference variables (as an abstract notion). > Because having reference variables doesn't imply you can have that effect. Ah, well that answers that question. Weasel out it is. -- Steve From list at qtrac.plus.com Thu Jun 9 03:49:20 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 9 Jun 2016 00:49:20 -0700 (PDT) Subject: what is wrong with this property setter In-Reply-To: References: Message-ID: <6ed933ba-65ff-4160-9f8f-ba56471962c0@googlegroups.com> On Thursday, June 9, 2016 at 8:28:47 AM UTC+1, Nagy L?szl? Zsolt wrote: > class Test: > def __init__(self): > self._parent = None > > @property > def parent(self): > return self._parent > > @parent.setter > def set_parent(self, new_parent): > self._parent = new_parent > > > p, c = Test(), Test() > c.parent = p > > >py -3 test.py > > Traceback (most recent call last): > File "test.py", line 15, in > c.parent = p > AttributeError: can't set attribute > > BTW this does work, but it is not that elegant: > > class Test: > def __init__(self): > self._parent = None > > def get_parent(self): > return self._parent > > def set_parent(self, new_parent): > self._parent = new_parent > > parent = property(get_parent, set_parent) > > > p, c = Test(), Test() > c.parent = p Change the name of the setter from set_parent to parent, i.e., @parent.setter def parent(self, new_parent): ... That works for me on Python 3.4. From antoon.pardon at rece.vub.ac.be Thu Jun 9 03:50:26 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 09:50:26 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> Message-ID: <57591FC2.6080408@rece.vub.ac.be> Op 08-06-16 om 19:29 schreef BartC: > I don't see why we should determine what a /proper/ reference >> can do, based on what it does in one specific language. > > Because there are some things that such references can do that Python > can't do with its object reference model, not without some difficulty > or having to write convoluted code. So? Maybe you have the wrong idea of what a reference is/can do? A reference is an alias. What you can do with that depends of the work environment. That you can do different things in an evironment that has a copy assignment than in an environment where you don't doesn't make the aliases go away. -- Antoon Pardon From steve+comp.lang.python at pearwood.info Thu Jun 9 03:52:29 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 09 Jun 2016 17:52:29 +1000 Subject: what is wrong with this property setter References: Message-ID: <5759203e$0$11119$c3e8da3@news.astraweb.com> On Thursday 09 June 2016 17:28, Nagy L?szl? Zsolt wrote: > class Test: Are you using Python 3 or 2? In Python 2, property doesn't work correctly with classes unless they inherit from object (directly or indirectly). > def __init__(self): > self._parent = None > > @property > def parent(self): > return self._parent > > @parent.setter > def set_parent(self, new_parent): > self._parent = new_parent If you use the "setter" method, you must use the same name, in this case "parent", for each part of the property. If you want to give your getters and setters different names, you have to use the older property API: class Test(object): def get_parent(self): ... def set_parent(self, value): ... parent = property(get_parent, set_parent) The reason why your code doesn't work is because of the way decorator syntax is defined. You have: @property def parent(self): ... which becomes: parent = property(parent) Then you have: @parent.setter def set_parent(self, new_parent): which becomes: set_parent = parent.setter(set_parent) which leaves you with TWO property objects, not one: (1) parent has a getter but no setter; (2) set_parent has a getter and setter (I think). -- Steve From __peter__ at web.de Thu Jun 9 04:01:13 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jun 2016 10:01:13 +0200 Subject: what is wrong with this property setter References: Message-ID: Nagy L?szl? Zsolt wrote: > class Test: > def __init__(self): > self._parent = None > > @property > def parent(self): > return self._parent > > @parent.setter > def set_parent(self, new_parent): > self._parent = new_parent > > > p, c = Test(), Test() > c.parent = p > >>py -3 test.py > > Traceback (most recent call last): > File "test.py", line 15, in > c.parent = p > AttributeError: can't set attribute Does this interactive session help you solve it yourself? $ python3 -i test.py Traceback (most recent call last): File "test.py", line 15, in c.parent = p AttributeError: can't set attribute >>> [n for n in dir(p) if not n.startswith("_")] ['parent', 'set_parent'] >>> p.set_parent = 42 >>> p.parent 42 Spoiler below if you don't see the light. > @parent.setter > def set_parent(self, new_parent): > self._parent = new_parent This creates a settable property with the name "set_parent" and leaves the read-only property "parent" alone. To fix your class change the above to @parent.setter def parent(self, new_parent): self._parent = new_parent From steve+comp.lang.python at pearwood.info Thu Jun 9 04:19:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 09 Jun 2016 18:19:23 +1000 Subject: for / while else doesn't make sense References: <48de4319-7c8a-419a-978c-3cff46f3490a@googlegroups.com> <57524448$0$1615$c3e8da3$5496439d@news.astraweb.com> <12226874-a705-47b1-859c-e9bed59ac6bb@googlegroups.com> <6c3b3d2e-bfc0-4c0e-ab81-55ec672f06c9@googlegroups.com> <7eb86c69-e0c5-4a4e-b35e-d8404bbebf9f@googlegroups.com> <878tyj97zo.fsf@elektro.pacujo.net> <6fde6944-918a-443e-b44f-0c7a69604a44@googlegroups.com> <1da21ea9-cfa8-4fae-960c-e753c9cc185e@googlegroups.com> <4a643983-c64e-483a-8e23-3c1485b89475@googlegroups.com> <87shwo4ps2.fsf@elektro.pacujo.net> <82e4fddc-5bf0-4b94-be07-7b5a24967e48@googlegroups.com> <87d1ns45ds.fsf@elektro.pacujo.net> <54890c12-388e-4923-888f-bd611a0c2076@googlegroups.com> Message-ID: <5759268d$0$2886$c3e8da3$76491128@news.astraweb.com> On Thursday 09 June 2016 10:34, Lawrence D?Oliveiro wrote: > In my undergraduate Comp Sci classes, we used to discuss arbitrary rules like > limiting functions to n lines. With real-world experience, it soon became > clear that such rules were a waste of time. A function should be just as big > as it needs to be, no more, no less. The same with a class, or a module. Or > whatever other constructs your language may have. The opposite of "arbitrary limits" is not "no limits". An arbitrary limit like "500 lines is the maximum size a function may be" is clearly arbitrary and not very helpful. (Also too high.) Better is to understand that there is no hard cut-off between "acceptable" and "too long", but we can still judge that all else being equal, long functions are worse than short functions. The real problem is complexity of functions. The more complex they are, the harder they are to write correctly, and the harder to maintain, and the more likely that they have bugs. The length of a function is a very crude measure of complexity, but it *is* a measure of complexity, and people are right to look at long functions as a code smell and a sign that the function probably does too much, or is badly written, or that it could do with some refactoring to simplify it. Not in *every* case, but I've never yet seen a long (> 200 lines) function that wasn't improved by refactoring or splitting. -- Steve From gandalf at shopzeus.com Thu Jun 9 04:31:37 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 10:31:37 +0200 Subject: what is wrong with this property setter In-Reply-To: References: Message-ID: >> @parent.setter >> def set_parent(self, new_parent): >> self._parent = new_parent > This creates a settable property with the name "set_parent" and leaves the > read-only property "parent" alone. Yes, and more. That property will also have a get method! Is it intentional? From __peter__ at web.de Thu Jun 9 05:00:45 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jun 2016 11:00:45 +0200 Subject: what is wrong with this property setter References: Message-ID: Nagy L?szl? Zsolt wrote: > >>> @parent.setter >>> def set_parent(self, new_parent): >>> self._parent = new_parent >> This creates a settable property with the name "set_parent" and leaves >> the read-only property "parent" alone. > Yes, and more. That property will also have a get method! Is it > intentional? It's a logical effect of how the setter() method works. The above is syntactic sugar for def set_parent(...): ... set_parent = parent.setter(set_parent) and parent.setter() creates a new property basically like this def setter(self, fset): return property(self.fget, fset, ...) Not very elegant, but I don't see a cleaner alternative. From gandalf at shopzeus.com Thu Jun 9 05:04:46 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 11:04:46 +0200 Subject: UserList - which methods needs to be overriden? Message-ID: Hi, I would like to create a collections.UserList subclass that can notify others when the list is mutated. I'm not sure which methods I need to override. I have checked the sources, and it seems difficult to figure out which methods needs to be overriden. For example, MutableSequence.extend is just a for loop that calls append(). Also, the clear() method just calls pop() until the sequence becomes empty. But UserList overrides extend, so if I ever want to know when the list is modified, I need to override extend() too. There are lots of base classes (UserList, MutableSequence, Sequence ) etc and some mutating methods might be inherited from those. I'll also have to do this for UserDict (which is a MutableMapping, which is a Mapping). Is there a way to easily find out which methods of are mutating the collection? Other than going over the source and checking all (normal and inherited) methods? And finally: set is a built in container type, but we don't have a UserSet in collections. Was it ever proposed to be added to collections? Thanks, Laszlo From bc at freeuk.com Thu Jun 9 05:10:37 2016 From: bc at freeuk.com (BartC) Date: Thu, 9 Jun 2016 10:10:37 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <57591FC2.6080408@rece.vub.ac.be> Message-ID: On 09/06/2016 08:50, Antoon Pardon wrote: > Op 08-06-16 om 19:29 schreef BartC: >> I don't see why we should determine what a /proper/ reference >>> can do, based on what it does in one specific language. >> >> Because there are some things that such references can do that Python >> can't do with its object reference model, not without some difficulty >> or having to write convoluted code. > > So? Maybe you have the wrong idea of what a reference is/can do? Maybe. Maybe in all the languages I've been implementing for three decades have implemented references and pointers wrongly. > A reference is an alias. Not really. My address is not an alias for my house (the latter is a 2-storey brick building, the former is a few lines on an envelope). A reference and what it refers to are a little different. (What /I/ call an alias is demonstrated by a language feature I used to implement like this: int a int b @ a a := 18 println b # 18 b := 21 println a # 21 Here, b is a synonym for a; another name for the same variable.) > What you can do with that depends of the > work environment. That you can do different things in an evironment > that has a copy assignment than in an environment where you don't > doesn't make the aliases go away. Well, all my implementations of references and pointers meet Steven D'Apranso' swap() challenge (see his post in this thread about 90 minutes before this one). And in fact, my new languages have a built-in swap operator that internally depends on the kinds of references that Python doesn't have. -- Bartc From gandalf at shopzeus.com Thu Jun 9 05:15:12 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 11:15:12 +0200 Subject: what is wrong with this property setter In-Reply-To: References: Message-ID: <897fc4dd-5018-b6ec-0723-be7322717e38@shopzeus.com> >> Yes, and more. That property will also have a get method! Is it >> intentional? > It's a logical effect of how the setter() method works. The above is > syntactic sugar for > > def set_parent(...): > ... > set_parent = parent.setter(set_parent) > > and parent.setter() creates a new property basically like this > > def setter(self, fset): > return property(self.fget, fset, ...) This I could not find, because property is a built-in. But I believe you. :-) > > Not very elegant, but I don't see a cleaner alternative. It can be used to define an alternative setter for the same property, but it is bad practice. Thank you for the clarification. From marko at pacujo.net Thu Jun 9 05:19:31 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 09 Jun 2016 12:19:31 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <57591B21.7050509@rece.vub.ac.be> Message-ID: <87inxipvmk.fsf@elektro.pacujo.net> Antoon Pardon : > Op 08-06-16 om 18:37 schreef Marko Rauhamaa: >> I see Python as doing the exact same thing with variables as C. >> >> What is different is that in Python, every expression evaluates to a >> pointer. Thus, you can only assign pointers to variables. > > Then you think wrong. Python has no pointers, that is an > implementation detail. Call it what you want, but the semantics of Python is only understandable through references (pointers, handles, leashes, addresses) to objects. Furthermore, there is no expression in Python that would evaluate to a reference to a variable. While variables may (or may not) be objects, they definitely are *not* first-class objects because of this important limitation. > In python when you have two variables, and you assign one to the other > you then have two variables that share an object. When you say A and B "share" an object, I say A and B contain a pointer (= reference) to the same object. It's simply a question of terminology, although I haven't seen "sharing" used in this context. A "reference" would be a great word (as in "reference counting"), but you recently have wanted to use that word for variables. > In C when you have two variables and you assign one to the other you > then have two variable each refering to their own object that are > copies of each other. Maybe you didn't quite understand what I have written above. In C, expressions can evaluate to values of these types (simplified): int long double pointer struct void (debatable) However, note that C does *not* have any expression that would evaluate to an object of these types: char short float array function Now, Python all expressions yield references: [] evaluates to a reference (= pointer) to a fresh empty array 1 + 2 evaluates to a reference (= pointer) to an integer 1 / 2 evaluates to a reference (= pointer) to a float ".".join evaluates to a reference (= pointer) to a function Both languages provide the syntax: lvalue = expression In light of the languages' respective expression semantics, the semantics of the assignment statements coincide. Both languages evaluate the expression ("rvalue") and place the result in the left-hand slot ("lvalue"). > And yes that sharing of variables in python can be simulated by > copying pointers in C. A "pointer" is an abstract concept both in C and Python. C does have a much richer pointer semantics than Python. For example, C provides pointer arithmetics. > Maybe the simularities between variables in python can be made > isomorphic with a specific subset of pointer operations in C. Now we are talking. "Isomorphic" is the only useful meaning of sameness. > In a rather straight forward environment with classes/structs that > have an x and y attribute, the following lines behave differently > in C and Python. > > A.x = 1; > A.y = 2; > > B = A; > > B.x = 3; > B.y = 4; > > In C the variable A will still be x:1, y:2. > In Python the variable A will be x:3, y:4. > > So no, Python doesn't do the exact same thing with variables as C. The difference is not in the variables but in the expressions. In Python, 1 evaluates to a pointer; in C, it evaluates to an int. Furthermore, in Python, A evaluates to a pointer; in C, it evaluates to a struct. Marko From __peter__ at web.de Thu Jun 9 05:40:03 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jun 2016 11:40:03 +0200 Subject: UserList - which methods needs to be overriden? References: Message-ID: Nagy L?szl? Zsolt wrote: > I would like to create a collections.UserList subclass that can notify > others when the list is mutated. I'm not sure which methods I need to > override. I have checked the sources, and it seems difficult to figure > out which methods needs to be overriden. For example, > MutableSequence.extend is just a for loop that calls append(). Also, the > clear() method just calls pop() until the sequence becomes empty. But > UserList overrides extend, so if I ever want to know when the list is > modified, I need to override extend() too. There are lots of base > classes (UserList, MutableSequence, Sequence ) etc and some mutating > methods might be inherited from those. I'll also have to do this for > UserDict (which is a MutableMapping, which is a Mapping). > > Is there a way to easily find out which methods of are mutating the > collection? Other than going over the source and checking all (normal > and inherited) methods? How about set(dir(collections.UserList)) - set(dir(collections.Sequence)) > And finally: set is a built in container type, but we don't have a > UserSet in collections. Was it ever proposed to be added to collections? I thought it was the other way round and UserList/UserDict were only kept for backwards-compatibility, but don't find anything in the docs to support this... From antoon.pardon at rece.vub.ac.be Thu Jun 9 05:46:31 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 11:46:31 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> References: <5753c89b$0$1616$c3e8da3$5496439d@news.astraweb.com> <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57593AF7.3080505@rece.vub.ac.be> Op 09-06-16 om 09:36 schreef Steven D'Aprano: > On Wednesday 08 June 2016 19:41, Antoon Pardon wrote: > >>> What you seem to be describing is similar to reference parameter semantics >>> from Pascal. Assignment doesn't work that way in C, or Python. >> I disagree. In python the assignment does work similar to the reference >> parameter semantics in pascal. See the following >> >> A = range[4] >> B = A >> B[2] = 5 >> print A # [0, 1, 5, 2] >> >> This is exactly the result you would get with B as a reference parameter in >> pascal. > It might be the same result, but it is a different cause. > > Your example demonstrates object mutation, not assignment. Generally assignment and mutation don't contradict each other. So IMO the cause is the same, a mutation. In some languages you can mutate your variable through an assignment and in others you can't. > But since you think that assignment in Python behaves like Pascal var > parameters (reference variables), you should be able to write a "swap" > procedure that swaps two arguments. That's the definitive test for reference > parameters, since it works in all languages with reference parameters (e.g. > Pascal, Basic and C++), and doesn't work in any language without them (or > equivalent, like Algol's pass-by-name parameters). It works in those languages because their the assignment mutates the variable that is assigned to. It is the fact that one can mutate a variable through an alias that makes it a reference variable, that is how it was already used in smalltalk. So because in python assignments don't mutate, you can't write a "swap" procedure in python, but AFAIR neither could you in smalltalk. You are confusing what it is that makes something a reference, with how an assignment can have an effect on a reference. It makes no sense to expect you can do the same with reference assignments as you can do with mutating assignments. > That is my challenge to you: if you can write such a function, in pure Python, > which swaps two parameters given as ordinary arguments (passing their names as > strings does not count), then I will cheerfully apologise for doubting you, > admit that I was wrong, and publicly acknowledge that Python does have > reference variables just like you said. > > If you cannot meet that challenge, then I would like you to acknowledge that > whatever Python variables are, and however Python's assignment works, it is > *not* the same as Pascal's reference variables, and so calling Python variables > "reference variables" is misleading and an abuse of a well-established term > from computer science since long before Python even existed. Your challenge, shows that you don't fully understand what reference variables are. The behaviour you see in Pascal, doesn't depend (alone) on the parameter being a reference parameter. It also depends on the fact that the assignment in pascal mutates the variable that is assigned to. Variables are references if they are aliases, so that if you mutate through one alias, the mutation is visible through other aliases. So your challenge comes down to expecting me to mutate something by means that in python don't allow mutation. > Are you willing to accept that challenge? > > Or are you going to try to weasel out of it by changing the definition of > reference parameter to mean "whatever I want it to mean to avoid admitting I > was wrong"? I am using reference as it was already use by smalltalk. > >> It is true that you can't get such an effect in python, but that doesn't >> imply that python doesn't have reference variables (as an abstract notion). >> Because having reference variables doesn't imply you can have that effect. > Ah, well that answers that question. Weasel out it is. That is presuming you have the right understanding. From __peter__ at web.de Thu Jun 9 05:49:57 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jun 2016 11:49:57 +0200 Subject: what is wrong with this property setter References: <897fc4dd-5018-b6ec-0723-be7322717e38@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > >>> Yes, and more. That property will also have a get method! Is it >>> intentional? >> It's a logical effect of how the setter() method works. The above is >> syntactic sugar for >> >> def set_parent(...): >> ... >> set_parent = parent.setter(set_parent) >> >> and parent.setter() creates a new property basically like this >> >> def setter(self, fset): >> return property(self.fget, fset, ...) > This I could not find, because property is a built-in. But I believe > you. :-) If you can read C: https://hg.python.org/cpython/file/tip/Objects/descrobject.c#l1183 https://hg.python.org/cpython/file/tip/Objects/descrobject.c#l1265 From antoon.pardon at rece.vub.ac.be Thu Jun 9 05:55:35 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 11:55:35 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <57591FC2.6080408@rece.vub.ac.be> Message-ID: <57593D17.807@rece.vub.ac.be> Op 09-06-16 om 11:10 schreef BartC: > On 09/06/2016 08:50, Antoon Pardon wrote: >> Op 08-06-16 om 19:29 schreef BartC: >>> I don't see why we should determine what a /proper/ reference >>>> can do, based on what it does in one specific language. >>> >>> Because there are some things that such references can do that Python >>> can't do with its object reference model, not without some difficulty >>> or having to write convoluted code. >> >> So? Maybe you have the wrong idea of what a reference is/can do? > > Maybe. Maybe in all the languages I've been implementing for three > decades have implemented references and pointers wrongly. Then I assume you haven't heard of smalltalk. > Well, all my implementations of references and pointers meet Steven > D'Apranso' swap() challenge (see his post in this thread about 90 > minutes before this one). Yes and that seems to confuses assignments with mutations. The swap challenge is based on the assumptions that assignment mutates. You and Steven are expecting particular behaviour from the assignment that is acutually depending on behaviour that mutates. So if the assignment doesn't mutate, you can't expect that behaviour from an assignment. -- Antoon Pardon From paul.nospam at rudin.co.uk Thu Jun 9 06:00:37 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 09 Jun 2016 11:00:37 +0100 Subject: I'm wrong or Will we fix the ducks limp? References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> Message-ID: <87k2hy1y2i.fsf@rudin.co.uk> Marko Rauhamaa writes: > Antoon Pardon : > >> You can do something like that in simula, but only because >> simula has two kinds of assignments. One kind that is >> simular to python and one that is similar to C. >> The one that is similar that python is the reference assignment. > > I see Python as doing the exact same thing with variables as C. I'm not sure that's a good mental model of what's going on. A variable declaration in C carries semantics of memory allocation to hold the value. This isn't so in python > > What is different is that in Python, every expression evaluates to a > pointer. Thus, you can only assign pointers to variables. > I don't think that's really right - every expression evaluates to an object. Whether or not that object can be accessed through some variable or not depends on how the expression is used. From silver0346 at gmail.com Thu Jun 9 06:02:21 2016 From: silver0346 at gmail.com (silver0346 at gmail.com) Date: Thu, 9 Jun 2016 03:02:21 -0700 (PDT) Subject: OrderedDict In-Reply-To: <32f4717a-2f7a-4b31-9933-6907716e190c@googlegroups.com> References: <7522e947-03d5-46e4-a74a-e5b312da47ad@googlegroups.com> <32f4717a-2f7a-4b31-9933-6907716e190c@googlegroups.com> Message-ID: <5ea73f6a-c77d-4301-a336-1cfc6fc42b3f@googlegroups.com> On Friday, May 20, 2016 at 7:15:38 AM UTC+2, silve... at gmail.com wrote: > On Wednesday, May 18, 2016 at 2:25:16 PM UTC+2, Peter Otten wrote: > > Chris Angelico wrote: > > > > > On Wed, May 18, 2016 at 7:28 PM, Peter Otten <__peter__ at web.de> wrote: > > >> I don't see an official way to pass a custom dict type to the library, > > >> but if you are not afraid to change its source code the following patch > > >> will allow you to access the value of dictionaries with a single entry as > > >> d[0]: > > >> > > >> $ diff -u py2b_xmltodict/local/lib/python2.7/site-packages/xmltodict.py > > >> py2_xmltodict/local/lib/python2.7/site-packages/xmltodict.py > > >> --- py2b_xmltodict/local/lib/python2.7/site-packages/xmltodict.py > > >> 2016-05-18 11:18:44.000000000 +0200 > > >> +++ py2_xmltodict/local/lib/python2.7/site-packages/xmltodict.py > > >> 2016-05-18 11:11:13.417665697 +0200 @@ -35,6 +35,13 @@ > > >> __version__ = '0.10.1' > > >> __license__ = 'MIT' > > >> > > >> +_OrderedDict = OrderedDict > > >> +class OrderedDict(_OrderedDict): > > >> + def __getitem__(self, key): > > >> + if key == 0: > > >> + [result] = self.values() > > >> + return result > > >> + return _OrderedDict.__getitem__(self, key) > > >> > > >> class ParsingInterrupted(Exception): > > >> pass > > > > > > Easier than patching might be monkeypatching. > > > > > > class OrderedDict(OrderedDict): > > > ... getitem code as above ... > > > xmltodict.OrderedDict = OrderedDict > > > > > > Try it, see if it works. > > > > It turns out I was wrong on (at least) two accounts: > > > > - xmltodict does offer a way to specify the dict type > > - the proposed dict implementation will not solve the OP's problem > > > > Here is an improved fix which should work: > > > > > > $ cat sample.xml > > > > > > > > > > > > > > $ cat sample2.xml > > > > > > > > > > > > > > > > $ cat demo.py > > import collections > > import sys > > import xmltodict > > > > > > class MyOrderedDict(collections.OrderedDict): > > def __getitem__(self, key): > > if key == 0 and len(self) == 1: > > return self > > return super(MyOrderedDict, self).__getitem__(key) > > > > > > def main(): > > filename = sys.argv[1] > > with open(filename) as f: > > doc = xmltodict.parse(f.read(), dict_constructor=MyOrderedDict) > > > > print "doc:\n{}\n".format(doc) > > print "package-id: {}".format( > > doc['profiles']['profile']['package'][0]['@package-id']) > > > > > > if __name__ == "__main__": > > main() > > $ python demo.py sample.xml > > doc: > > MyOrderedDict([(u'profiles', MyOrderedDict([(u'profile', > > MyOrderedDict([(u'@id', u'visio02'), (u'@revision', u'2015051501'), > > (u'package', MyOrderedDict([(u'@package-id', u'0964-gpg4win')]))]))]))]) > > > > package-id: 0964-gpg4win > > $ python demo.py sample2.xml > > doc: > > MyOrderedDict([(u'profiles', MyOrderedDict([(u'profile', > > MyOrderedDict([(u'@id', u'visio02'), (u'@revision', u'2015051501'), > > (u'package', [MyOrderedDict([(u'@package-id', u'0964-gpg4win')]), > > MyOrderedDict([(u'@package-id', u'0965-gpg4win')])])]))]))]) > > > > package-id: 0964-gpg4win > > I have tested the first solution. Works nice. Before I used xml.etree to parse 2000 xml files. > > Execution time decrease from more then 5 min to 20 sec. Great. On weekend I will test the solution with the own class. > > Many thanks. Hi all, tests with solution with the own class successful. Nice inspiration. I use this solution in my django script. Many thanks. From marko at pacujo.net Thu Jun 9 06:03:55 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 09 Jun 2016 13:03:55 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> <57593AF7.3080505@rece.vub.ac.be> Message-ID: <87eg86ptkk.fsf@elektro.pacujo.net> Antoon Pardon : > Your challenge, shows that you don't fully understand what reference > variables are. The behaviour you see in Pascal, doesn't depend (alone) > on the parameter being a reference parameter. It also depends on the > fact that the assignment in pascal mutates the variable that is > assigned to. Variables are references if they are aliases, so that if > you mutate through one alias, the mutation is visible through other > aliases. So your challenge comes down to expecting me to mutate > something by means that in python don't allow mutation. I think bringing Pascal in this discussion is only confusing matters. Let me repeat the abstract Python data model I gave a couple of days back: - there are labeled *pegs* ("variables") - there are *puppies* ("objects") - each peg has one *leash* hanging from it - each leash is tied to a puppy - each puppy can have zero one or more leashes tied to it - some puppies can hold leashes in their *mouths* - some puppies can take hold of new leashes and let go of leashes I'm not joking. Everybody is arguing about preconceived notions tied to terminology. The peg-leash-puppy model is accurate and extensive. We can now give semantics to Python's execution model. For example, - every rvalue expression evaluates to a leash - the lvalue expression identifies a peg or a mouth - the assignment statement hangs a leash on a peg or in a mouth Marko From antoon.pardon at rece.vub.ac.be Thu Jun 9 06:19:35 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 12:19:35 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <87inxipvmk.fsf@elektro.pacujo.net> References: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <57591B21.7050509@rece.vub.ac.be> <87inxipvmk.fsf@elektro.pacujo.net> Message-ID: <575942B7.5030905@rece.vub.ac.be> Op 09-06-16 om 11:19 schreef Marko Rauhamaa: > >> In a rather straight forward environment with classes/structs that >> have an x and y attribute, the following lines behave differently >> in C and Python. >> >> A.x = 1; >> A.y = 2; >> >> B = A; >> >> B.x = 3; >> B.y = 4; >> >> In C the variable A will still be x:1, y:2. >> In Python the variable A will be x:3, y:4. >> >> So no, Python doesn't do the exact same thing with variables as C. > The difference is not in the variables but in the expressions. In > Python, > > 1 > > evaluates to a pointer; in C, it evaluates to an int. Furthermore, in > Python, > > A > > evaluates to a pointer; in C, it evaluates to a struct. If a variable evaluates to something different, in different languages, the variable don't do the exact same thing in the different languages. From gandalf at shopzeus.com Thu Jun 9 06:40:56 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 12:40:56 +0200 Subject: UserList - which methods needs to be overriden? In-Reply-To: References: Message-ID: <917ca9c4-aef1-6681-ec70-62de8916117d@shopzeus.com> >> Is there a way to easily find out which methods of are mutating the >> collection? Other than going over the source and checking all (normal >> and inherited) methods? > How about > > set(dir(collections.UserList)) - set(dir(collections.Sequence)) Thanks. It narrows down the list of possible methods to be examined. > I thought it was the other way round and UserList/UserDict were only kept > for backwards-compatibility, but don't find anything in the docs to support > this... Are you saying that for any new project, I should subclass from list and dict, instead of UserList and UserDict? From bc at freeuk.com Thu Jun 9 06:42:17 2016 From: bc at freeuk.com (BartC) Date: Thu, 9 Jun 2016 11:42:17 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <87eg86ptkk.fsf@elektro.pacujo.net> References: <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> <57593AF7.3080505@rece.vub.ac.be> <87eg86ptkk.fsf@elektro.pacujo.net> Message-ID: On 09/06/2016 11:03, Marko Rauhamaa wrote: > Antoon Pardon : > >> Your challenge, shows that you don't fully understand what reference >> variables are. The behaviour you see in Pascal, doesn't depend (alone) >> on the parameter being a reference parameter. It also depends on the >> fact that the assignment in pascal mutates the variable that is >> assigned to. Variables are references if they are aliases, so that if >> you mutate through one alias, the mutation is visible through other >> aliases. So your challenge comes down to expecting me to mutate >> something by means that in python don't allow mutation. > > I think bringing Pascal in this discussion is only confusing matters. > > Let me repeat the abstract Python data model I gave a couple of days > back: > > - there are labeled *pegs* ("variables") > > - there are *puppies* ("objects") > > - each peg has one *leash* hanging from it > > - each leash is tied to a puppy > > - each puppy can have zero one or more leashes tied to it > > - some puppies can hold leashes in their *mouths* > > - some puppies can take hold of new leashes and let go of leashes > > I'm not joking. Everybody is arguing about preconceived notions tied to > terminology. The peg-leash-puppy model is accurate and extensive. > > We can now give semantics to Python's execution model. For example, > > - every rvalue expression evaluates to a leash > > - the lvalue expression identifies a peg or a mouth > > - the assignment statement hangs a leash on a peg or in a mouth And to implement swap() you need a leash that can be tied to a peg. (Here, I'm assuming 'hanging from' and 'tied to' suggest that a leash is uni-directional. But it's possible to imagine that a different part of a peg is used to hang an out-going leash, compared to tying an incoming one. Just like the puppies have necks to tie incoming leashes to (via collars to avoid cruelty) and mouths for out-going ones.) -- Bartc From bc at freeuk.com Thu Jun 9 06:48:33 2016 From: bc at freeuk.com (BartC) Date: Thu, 9 Jun 2016 11:48:33 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <57591FC2.6080408@rece.vub.ac.be> <57593D17.807@rece.vub.ac.be> Message-ID: On 09/06/2016 10:55, Antoon Pardon wrote: > Op 09-06-16 om 11:10 schreef BartC: >> On 09/06/2016 08:50, Antoon Pardon wrote: >>> Op 08-06-16 om 19:29 schreef BartC: >>>> I don't see why we should determine what a /proper/ reference >>>>> can do, based on what it does in one specific language. >>>> >>>> Because there are some things that such references can do that Python >>>> can't do with its object reference model, not without some difficulty >>>> or having to write convoluted code. >>> >>> So? Maybe you have the wrong idea of what a reference is/can do? >> >> Maybe. Maybe in all the languages I've been implementing for three >> decades have implemented references and pointers wrongly. > > Then I assume you haven't heard of smalltalk. > >> Well, all my implementations of references and pointers meet Steven >> D'Apranso' swap() challenge (see his post in this thread about 90 >> minutes before this one). > > Yes and that seems to confuses assignments with mutations. > The swap challenge is based on the assumptions that assignment > mutates. > > You and Steven are expecting particular behaviour from the assignment > that is acutually depending on behaviour that mutates. So if the assignment > doesn't mutate, you can't expect that behaviour from an assignment. > What does it matter? If swap() can be implemented via such a function, then it means that the language has such capability, which can be useful in different scenarios. If it can't, then the language hasn't. Python doesn't have it so it can't implement swap like that. There's no need to bring references into it at all. (A good thing as I've lost track of what it is you are arguing about! Are you staying references exist or they don't, that Python has them or it hasn't, or what? Meanwhile those of us of who sometimes have to implement these things can just get on with it.) -- Bartc From bc at freeuk.com Thu Jun 9 06:53:50 2016 From: bc at freeuk.com (BartC) Date: Thu, 9 Jun 2016 11:53:50 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> <57593AF7.3080505@rece.vub.ac.be> Message-ID: On 09/06/2016 10:46, Antoon Pardon wrote: > Op 09-06-16 om 09:36 schreef Steven D'Aprano: >> Your example demonstrates object mutation, not assignment. > > Generally assignment and mutation don't contradict each other. > So IMO the cause is the same, a mutation. In some languages you > can mutate your variable through an assignment and in others you > can't. I think this is what is confusing you. Mutation is like repairing or customising my car. Full assignment is like buying a new car. The two are very different, even though they might involve the same "=" operator. Python object references work like the registration (license) plate on a car. Whatever you do via that, it will be the same car. Full references require the address of the house. -- Bartc From davidbenny2000 at gmail.com Thu Jun 9 06:55:09 2016 From: davidbenny2000 at gmail.com (Ho Yeung Lee) Date: Thu, 9 Jun 2016 03:55:09 -0700 (PDT) Subject: why it is like stop running after a 3 seconds Message-ID: <35cd5920-1fbb-441f-9fc6-2f3f2e5f8568@googlegroups.com> i write a program, it is like forever loop but i only restrict it to run 2 level recursively, why it is slow, where is the problem? M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=1 M1['02']=1 M1['10']=2 M1['11']=2 M1['12']=1 M1['20']=1 M1['21']=2 M1['22']=1 M2['00']=0 M2['01']=1 M2['02']=2 M2['10']=1 M2['11']=2 M2['12']=1 M2['20']=1 M2['21']=1 M2['22']=1 M3['00']=0 M3['01']=2 M3['02']=2 M3['10']=1 M3['11']=2 M3['12']=1 M3['20']=0 M3['21']=1 M3['22']=0 M4['00']=2 M4['01']=2 M4['02']=0 M4['10']=2 M4['11']=1 M4['12']=2 M4['20']=0 M4['21']=1 M4['22']=2 M5['00']=0 M5['01']=1 M5['02']=2 M5['10']=1 M5['11']=1 M5['12']=1 M5['20']=1 M5['21']=1 M5['22']=2 V6['00']=1 V6['01']=2 V6['02']=1 V6['10']=2 V6['11']=1 V6['12']=1 V6['20']=2 V6['21']=2 V6['22']=0 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) else: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) return path path = [] mresult = DFS(b, 2, 2, mylist, path) From jussi.piitulainen at helsinki.fi Thu Jun 9 06:56:58 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 09 Jun 2016 13:56:58 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> <57593AF7.3080505@rece.vub.ac.be> Message-ID: BartC writes: > On 09/06/2016 10:46, Antoon Pardon wrote: >> Op 09-06-16 om 09:36 schreef Steven D'Aprano: > >>> Your example demonstrates object mutation, not assignment. >> >> Generally assignment and mutation don't contradict each other. >> So IMO the cause is the same, a mutation. In some languages you >> can mutate your variable through an assignment and in others you >> can't. > > I think this is what is confusing you. > > Mutation is like repairing or customising my car. > > Full assignment is like buying a new car. Nice. [- -] From antoon.pardon at rece.vub.ac.be Thu Jun 9 07:08:32 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 13:08:32 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <57591FC2.6080408@rece.vub.ac.be> <57593D17.807@rece.vub.ac.be> Message-ID: <57594E30.7060603@rece.vub.ac.be> Op 09-06-16 om 12:48 schreef BartC: > > What does it matter? > > If swap() can be implemented via such a function, then it means that > the language has such capability, which can be useful in different > scenarios. > > If it can't, then the language hasn't. > > Python doesn't have it so it can't implement swap like that. > > There's no need to bring references into it at all. Whether a language can implement a swap procedure like that is not the same question as whether the language variables are references or not. Since the topic was whether or not python has reference variables, is seems there is no need to bring this swap procedure into it at all, instead of turning it around and pretending it was about the swap procedure. From antoon.pardon at rece.vub.ac.be Thu Jun 9 07:19:18 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 13:19:18 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <1465148542.2670061.628500777.62F1EFE1@webmail.messagingengine.com> <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> <57593AF7.3080505@rece.vub.ac.be> Message-ID: <575950B6.3080807@rece.vub.ac.be> Op 09-06-16 om 12:53 schreef BartC: > On 09/06/2016 10:46, Antoon Pardon wrote: >> Op 09-06-16 om 09:36 schreef Steven D'Aprano: > >>> Your example demonstrates object mutation, not assignment. >> >> Generally assignment and mutation don't contradict each other. >> So IMO the cause is the same, a mutation. In some languages you >> can mutate your variable through an assignment and in others you >> can't. > > I think this is what is confusing you. > > Mutation is like repairing or customising my car. > > Full assignment is like buying a new car. I think you are confused. Full assignment of C struct or Pascal record is the same as mutating all individual attributes. You don't get a new record/instance as in Python. You replace the value of the attributes with something else. As far a language semantics are concerned, you get the (new) car at scope entry, all assigments later are mutations. You may think of assignment as like buying a new car, that is not how the semantics of languages like pascal and C are defined. From lists at juliensalort.org Thu Jun 9 07:46:03 2016 From: lists at juliensalort.org (Julien Salort) Date: Thu, 9 Jun 2016 13:46:03 +0200 Subject: I'm wrong or Will we fix the ducks limp? References: <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <57591B21.7050509@rece.vub.ac.be> Message-ID: <1mokwuv.1rvlipllo6ji2N%lists@juliensalort.org> Antoon Pardon wrote: > A.x = 1; > A.y = 2; > > B = A; > > B.x = 3; > B.y = 4; > > > In C the variable A will still be x:1, y:2. > In Python the variable A will be x:3, y:4. But it would, if you had written instead: A->x = 1; A->y = 2; B = A; B->x = 3; B->y = 4; which backs indeed the C pointer analogy... -- Julien Salort Entia non sunt multiplicanda praeter necessitatem http://www.juliensalort.org From bc at freeuk.com Thu Jun 9 08:17:32 2016 From: bc at freeuk.com (BartC) Date: Thu, 9 Jun 2016 13:17:32 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> <57593AF7.3080505@rece.vub.ac.be> <575950B6.3080807@rece.vub.ac.be> Message-ID: On 09/06/2016 12:19, Antoon Pardon wrote: > Op 09-06-16 om 12:53 schreef BartC: >> On 09/06/2016 10:46, Antoon Pardon wrote: >>> Op 09-06-16 om 09:36 schreef Steven D'Aprano: >> >>>> Your example demonstrates object mutation, not assignment. >>> >>> Generally assignment and mutation don't contradict each other. >>> So IMO the cause is the same, a mutation. In some languages you >>> can mutate your variable through an assignment and in others you >>> can't. >> >> I think this is what is confusing you. >> >> Mutation is like repairing or customising my car. >> >> Full assignment is like buying a new car. > > I think you are confused. Full assignment of C struct or > Pascal record is the same as mutating all individual > attributes. You don't get a new record/instance as in > Python. You replace the value of the attributes with > something else. > > As far a language semantics are concerned, you get the > (new) car at scope entry, all assigments later are > mutations. > > You may think of assignment as like buying a new car, > that is not how the semantics of languages like pascal > and C are defined. Static languages like C and Pascal don't make for a good comparison. C is just too low level: anything is possible so can be twisted any way. A bit like assembly. C variables have a fixed type, which you can't change by assignment (so a Ford can't change to a different marque). But being low-level, assignment in C is just copying N bytes from A to B. Which is also what happens when, instead of copying a whole struct, you mutate all of it by assigning the fields one by one. Python assignments are bit more sophisticated, and there are real differences between full assignment (where a variable ends up with a different object reference) and mutation (where it might be the same, but modified, object). -- Bartc From bc at freeuk.com Thu Jun 9 08:25:28 2016 From: bc at freeuk.com (BartC) Date: Thu, 9 Jun 2016 13:25:28 +0100 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <57591FC2.6080408@rece.vub.ac.be> <57593D17.807@rece.vub.ac.be> <57594E30.7060603@rece.vub.ac.be> Message-ID: On 09/06/2016 12:08, Antoon Pardon wrote: > Op 09-06-16 om 12:48 schreef BartC: >> >> What does it matter? >> >> If swap() can be implemented via such a function, then it means that >> the language has such capability, which can be useful in different >> scenarios. >> >> If it can't, then the language hasn't. >> >> Python doesn't have it so it can't implement swap like that. >> >> There's no need to bring references into it at all. > > Whether a language can implement a swap procedure like that is > not the same question as whether the language variables are > references or not. Now /you're/ turning it around. I'm not interested in the internal references that Python currently uses. (I've called them /object references/.) I'm talking about a different kind of reference, possible /name references/, they would make possible new things .... > Since the topic was whether or not python has reference variables, > is seems there is no need to bring this swap procedure into it at all, > instead of turning it around and pretending it was about the > swap procedure. ... such as implementing a function that can exchange the values of its caller's two arguments. In bytecode, Python might need to swap variables using: load a load b store a store b (which can get inefficient if swapping a[i+j-1] and b[j-i+1]). A name reference would allow: loadref a loadref b swap -- Bartc From peter.heitzer at rz.uni-regensburg.de Thu Jun 9 08:30:32 2016 From: peter.heitzer at rz.uni-regensburg.de (Peter Heitzer) Date: 9 Jun 2016 12:30:32 GMT Subject: Tie dictionary to database table? Message-ID: In Perl there exists the tie mechanism for key/value type databases like Berkeley db. Are there any python modules that can do the same for a column of a mysql table? Given the following table users: ( username char(16) not null unique, email char(128), fullname char(64) ) What I would like is if I write email['frank']='frank at middle-of-nowhere.org' in my python script it generates a statement like update users set email='frank at middle-of-nowhere.org' where username='frank'; Any hints to already existing modules are highly appreciated. and have -- Dipl.-Inform(FH) Peter Heitzer, peter.heitzer at rz.uni-regensburg.de From antoon.pardon at rece.vub.ac.be Thu Jun 9 08:35:29 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 14:35:29 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <1mokwuv.1rvlipllo6ji2N%lists@juliensalort.org> References: <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <57591B21.7050509@rece.vub.ac.be> <1mokwuv.1rvlipllo6ji2N%lists@juliensalort.org> Message-ID: <57596291.2090705@rece.vub.ac.be> Op 09-06-16 om 13:46 schreef Julien Salort: > Antoon Pardon wrote: > >> A.x = 1; >> A.y = 2; >> >> B = A; >> >> B.x = 3; >> B.y = 4; >> >> >> In C the variable A will still be x:1, y:2. >> In Python the variable A will be x:3, y:4. > But it would, if you had written instead: > > A->x = 1; > A->y = 2; > > B = A; > > B->x = 3; > B->y = 4; > > which backs indeed the C pointer analogy... Yes, what is your point? I know there is a C pointer analogy with Python variables. The fact that there is an analogy between C pointers and Python variables, is not enough to conclude that C variables and Python variables behave exactly the same. Normal structs are a kind of variable too in C. If you have to ignore those in order to show similarities, then the variables in general don't behave exactly the same. From malitician at gmail.com Thu Jun 9 08:41:39 2016 From: malitician at gmail.com (lee) Date: Thu, 9 Jun 2016 05:41:39 -0700 (PDT) Subject: google sheet and google app engine(GAE) python Message-ID: how do connect my google sheet and my GAE application made in python so that i can read , update and delete cells , any step by instruction for newbie? From antoon.pardon at rece.vub.ac.be Thu Jun 9 08:48:03 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 14:48:03 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <57591FC2.6080408@rece.vub.ac.be> <57593D17.807@rece.vub.ac.be> <57594E30.7060603@rece.vub.ac.be> Message-ID: <57596583.7030102@rece.vub.ac.be> Op 09-06-16 om 14:25 schreef BartC: > On 09/06/2016 12:08, Antoon Pardon wrote: >> Op 09-06-16 om 12:48 schreef BartC: >>> >>> What does it matter? >>> >>> If swap() can be implemented via such a function, then it means that >>> the language has such capability, which can be useful in different >>> scenarios. >>> >>> If it can't, then the language hasn't. >>> >>> Python doesn't have it so it can't implement swap like that. >>> >>> There's no need to bring references into it at all. >> >> Whether a language can implement a swap procedure like that is >> not the same question as whether the language variables are >> references or not. > > Now /you're/ turning it around. > > I'm not interested in the internal references that Python currently > uses. (I've called them /object references/.) > > I'm talking about a different kind of reference, possible /name > references/, they would make possible new things .... That you talk about something different, doesn't make others wrong when they use the label "reference" for what they are talking about. If someone writes that variables in python are references or reference variables, then there is an historical meaning for the label "reference" that makes this statement true. Protesting the statment because you think of something different when you read "reference", just means you didn't understand the original statement. From sunnycemetery at gmail.com Thu Jun 9 08:50:32 2016 From: sunnycemetery at gmail.com (Grady Martin) Date: Thu, 9 Jun 2016 08:50:32 -0400 Subject: for / while else doesn't make sense In-Reply-To: References: Message-ID: <20160609125032.GP1607@slim> On 2016?05?19? 11?02?, Ian Kelly wrote: >"else" makes sense from a certain point of view, but I think that >logic may not be communicated well. At the start of each loop >iteration, the loop construct makes a test for whether the loop should >continue or not. If that test ever fails (i.e. if the condition of the >while loop is false), the else block is executed instead. Thank you for the concise explanation. (I enjoy new tools.) As alluded to elsewhere, this distinction makes sense when loop breaking is involved. From marko at pacujo.net Thu Jun 9 08:56:29 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 09 Jun 2016 15:56:29 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <87k2hy1y2i.fsf@rudin.co.uk> Message-ID: <878tyeplky.fsf@elektro.pacujo.net> Paul Rudin : > Marko Rauhamaa writes: >> What is different is that in Python, every expression evaluates to a >> pointer. Thus, you can only assign pointers to variables. > > I don't think that's really right - every expression evaluates to an > object. The object is only an intermediate result; what is returned is a pointer (to an object), without an exception. That's not a matter of implementation. It's an essential part of Python's data model. (However, since "pointer" is evokes passions among crowds, it is better to use the neutral word "leash".) Marko From __peter__ at web.de Thu Jun 9 08:58:20 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jun 2016 14:58:20 +0200 Subject: UserList - which methods needs to be overriden? References: <917ca9c4-aef1-6681-ec70-62de8916117d@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > >>> Is there a way to easily find out which methods of are mutating the >>> collection? Other than going over the source and checking all (normal >>> and inherited) methods? >> How about >> >> set(dir(collections.UserList)) - set(dir(collections.Sequence)) > Thanks. It narrows down the list of possible methods to be examined. > >> I thought it was the other way round and UserList/UserDict were only kept >> for backwards-compatibility, but don't find anything in the docs to >> support this... > Are you saying that for any new project, I should subclass from list and > dict, instead of UserList and UserDict? Using the built-in list or dict is problematic because sometimes the subclass methods are ignored when the internal data is accessed (sorry, I don't have an example). I thought you should subclass MutableSequence instead of UserList, but I may have been wrong. While you minimize your effort -- just add methods until you can instantiate your subclass -- the resulting class will not be very efficient. How detailed is your change notification? If it's always the same method invocation you may be able to create wrappers like def whatever(self, *args): try: return super().whatever(*args) finally: self.changed() automatically, and the base class, be it list or UserList or whatever becomes a detail that can be chosen on a case by case basis. From antoon.pardon at rece.vub.ac.be Thu Jun 9 08:59:01 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Jun 2016 14:59:01 +0200 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <57591c7f$0$1522$c3e8da3$5496439d@news.astraweb.com> <57593AF7.3080505@rece.vub.ac.be> <575950B6.3080807@rece.vub.ac.be> Message-ID: <57596815.4000503@rece.vub.ac.be> Op 09-06-16 om 14:17 schreef BartC: > On 09/06/2016 12:19, Antoon Pardon wrote: >> Op 09-06-16 om 12:53 schreef BartC: >>> On 09/06/2016 10:46, Antoon Pardon wrote: >>>> Op 09-06-16 om 09:36 schreef Steven D'Aprano: >>> >>>>> Your example demonstrates object mutation, not assignment. >>>> >>>> Generally assignment and mutation don't contradict each other. >>>> So IMO the cause is the same, a mutation. In some languages you >>>> can mutate your variable through an assignment and in others you >>>> can't. >>> >>> I think this is what is confusing you. >>> >>> Mutation is like repairing or customising my car. >>> >>> Full assignment is like buying a new car. >> >> I think you are confused. Full assignment of C struct or >> Pascal record is the same as mutating all individual >> attributes. You don't get a new record/instance as in >> Python. You replace the value of the attributes with >> something else. >> >> As far a language semantics are concerned, you get the >> (new) car at scope entry, all assigments later are >> mutations. >> >> You may think of assignment as like buying a new car, >> that is not how the semantics of languages like pascal >> and C are defined. > > Static languages like C and Pascal don't make for a good comparison. C > is just too low level: anything is possible so can be twisted any way. > A bit like assembly. But this "low" level is needed to make a swap work. > > C variables have a fixed type, which you can't change by assignment > (so a Ford can't change to a different marque). But being low-level, > assignment in C is just copying N bytes from A to B. Which is also > what happens when, instead of copying a whole struct, you mutate all > of it by assigning the fields one by one. Exactly and it is this mutating that makes a swap procedure possible in the languages that come up here. > > Python assignments are bit more sophisticated, and there are real > differences between full assignment (where a variable ends up with a > different object reference) and mutation (where it might be the same, > but modified, object). Yes and it is this difference that makes it impossible to write a swap procedure, despite the variables in python being reference variables. Make up what ever kind of reference you wil. If your assignment will only change references and won't mutate, you will not be able to write a swap procedure. From walters.justin01 at gmail.com Thu Jun 9 09:09:11 2016 From: walters.justin01 at gmail.com (justin walters) Date: Thu, 9 Jun 2016 06:09:11 -0700 Subject: Tie dictionary to database table? In-Reply-To: References: Message-ID: It looks like you might be looking for an ORM. Have you checked out sqlalchemy? From marko at pacujo.net Thu Jun 9 09:13:01 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 09 Jun 2016 16:13:01 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <57591B21.7050509@rece.vub.ac.be> <87inxipvmk.fsf@elektro.pacujo.net> <575942B7.5030905@rece.vub.ac.be> Message-ID: <874m92pkte.fsf@elektro.pacujo.net> Antoon Pardon : > Op 09-06-16 om 11:19 schreef Marko Rauhamaa: >> The difference is not in the variables but in the expressions. In >> Python, >> >> 1 >> >> evaluates to a pointer; in C, it evaluates to an int. Furthermore, in >> Python, >> >> A >> >> evaluates to a pointer; in C, it evaluates to a struct. > > If a variable evaluates to something different, in different > languages, the variable don't do the exact same thing in > the different languages. In fact, it turns out that the variables are evaluated identically in both C and Python. In both cases, a variable evaluates to the value the variable is holding at the moment. However, since all Python expressions evaluate into pointers, there's no way to assign anything but a pointer to a variable. In C, expression evaluation is much more diverse, as is variable typing. Since Python variable is always holding a pointer, its straightforward evaluation results in a pointer, closing the circle. Marko From beliavsky at aol.com Thu Jun 9 09:28:00 2016 From: beliavsky at aol.com (beliavsky at aol.com) Date: Thu, 9 Jun 2016 06:28:00 -0700 (PDT) Subject: Intel Distribution for Python In-Reply-To: <31116921-144f-498e-873f-63510c6b8c63@googlegroups.com> References: <31116921-144f-498e-873f-63510c6b8c63@googlegroups.com> Message-ID: <4f103f0e-75ea-430a-8b3d-65e4d33e1ae4@googlegroups.com> Intel has released Beta Update 1 of its Python distribution: "What's New! Jupyter* notebook interface Neural network APIs support for pyDAAL Optimized random number generation features for numpy.random package" From gandalf at shopzeus.com Thu Jun 9 09:33:32 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 15:33:32 +0200 Subject: UserList - which methods needs to be overriden? In-Reply-To: References: <917ca9c4-aef1-6681-ec70-62de8916117d@shopzeus.com> Message-ID: <7cdb398f-b3f2-9a3c-b444-2229f8496e2f@shopzeus.com> > Using the built-in list or dict is problematic because sometimes the > subclass methods are ignored when the internal data is accessed (sorry, I > don't have an example). Are you suggesting that I should use UserList and UserDict instead of list and dict? What is the truth? Was UserDict left in collections for backward compatibility, or not? > > How detailed is your change notification? If it's always the same method > invocation you may be able to create wrappers like > > def whatever(self, *args): > try: > return super().whatever(*args) > finally: > self.changed() > > automatically, and the base class, be it list or UserList or whatever > becomes a detail that can be chosen on a case by case basis. My actual solution looks like this: class ObservableCollection(Observable): @contextmanager def notify(self): self.notify_observers(EVT_BEFORE_COLLECTION_CHANGED) yield self.notify_observers(EVT_AFTER_COLLECTION_CHANGED) class ObservableList(ObservableCollection, list): __slots__ = [] def remove(self, value): with self.notify(): super().remove(value) def clear(self): with self.notify(): super().clear() def pop(self): with self.notify(): return super().pop() It seems to be working with the built in list, dict and set types. There must be a better way! Something like this: @wrap_notify('remove', 'clear', 'append', 'insert', 'sort'): class ObservableList(ObservableCollection, list): pass I just can't find out the right syntax. From python at mrabarnett.plus.com Thu Jun 9 09:52:11 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 9 Jun 2016 14:52:11 +0100 Subject: run code error with numpy and scipy In-Reply-To: <62df152e-8fc6-47c5-aa44-f2da4094c140@googlegroups.com> References: <62df152e-8fc6-47c5-aa44-f2da4094c140@googlegroups.com> Message-ID: On 2016-06-09 07:02, meInvent bbird wrote: > when i run code in window has an error not a valid win32 dll > > then i install scipy first in this site, then install numpy-mkl > all python 2.7 and win32 > > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > then i run code below, got error , and captured screen in this link > > https://drive.google.com/file/d/0Bxs_ao6uuBDUQXROd2VqSURGa00/view?usp=sharing > [snip] You're entering it at the interactive Python prompt. When it sees the blank line, it thinks you've finished entering the function, so it complains when the next line is indented. (Things are slightly different when working interactively than when running from a file.) You should put the code into a file and then run that. From gandalf at shopzeus.com Thu Jun 9 09:55:16 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 15:55:16 +0200 Subject: UserList - which methods needs to be overriden? In-Reply-To: <7cdb398f-b3f2-9a3c-b444-2229f8496e2f@shopzeus.com> References: <917ca9c4-aef1-6681-ec70-62de8916117d@shopzeus.com> <7cdb398f-b3f2-9a3c-b444-2229f8496e2f@shopzeus.com> Message-ID: <13f5d47e-39e2-76ce-e0c6-195a4bd25e7b@shopzeus.com> > @wrap_notify('remove', 'clear', 'append', 'insert', 'sort'): > class ObservableList(ObservableCollection, list): > pass > > I just can't find out the right syntax. > > All right, this is working. from contextlib import contextmanager class ObservableCollection: @contextmanager def notify(cls): print("notify before change") yield print("notify after change") def wrap_notify(cls, basecls, method_names): for method_name in method_names: orig = getattr(basecls, method_name) def modified(self, *args, **kwargs): with self.notify(): return orig(self,*args,**kwargs) setattr(cls, method_name, modified) return cls class ObservableDict(ObservableCollection, dict): __slots__ = [] wrap_notify(ObservableDict, dict, ['update', '__delitem__', '__setitem__']) # many others... class ObservableList(ObservableCollection, list): __slots__ = [] wrap_notify(ObservableList, list, ['append', 'pop']) # many others... d = ObservableDict() d[1] = 2 print(d) But I'm still not 100% satisfied. wrap_notify is not a class decorator. Is there a way to make a class decorator that gets the class as its first parameter? It would be very nice: def wrap_notify(cls, method_names): class Wrapped(cls): pass for method_name in method_names: orig = getattr(Wrapped, method_name) def modified(self, *args, **kwargs): with self.notify(): return orig(self,*args,**kwargs) setattr(cls, method_name, modified) return Wrapped @wrap_notify(['update', '__delitem__', '__setitem__']) # many others... class ObservableDict(ObservableCollection, dict): __slots__ = [] @wrap_notify(['append', 'pop']) # many others... class ObservableList(ObservableCollection, list): __slots__ = [] And finally: is this Pythonic, or a horrible mess? Would it be better to duplicate the body of each method one by one? From paul.nospam at rudin.co.uk Thu Jun 9 10:09:13 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 09 Jun 2016 15:09:13 +0100 Subject: I'm wrong or Will we fix the ducks limp? References: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <87k2hy1y2i.fsf@rudin.co.uk> <878tyeplky.fsf@elektro.pacujo.net> Message-ID: <87eg861mk6.fsf@rudin.co.uk> Marko Rauhamaa writes: > Paul Rudin : > >> Marko Rauhamaa writes: >>> What is different is that in Python, every expression evaluates to a >>> pointer. Thus, you can only assign pointers to variables. >> >> I don't think that's really right - every expression evaluates to an >> object. > > The object is only an intermediate result; what is returned is a pointer > (to an object), without an exception. That's not a matter of > implementation. It's an essential part of Python's data model. > Well - the language has no explicit notion of "pointer", so I'm not sure it's really correct to say that it's an essential part of the data model. The way variables are used to reference the objects associated with them from time to time has some similarities with pointer semantics in other languages. But actually it's better (IMO) to just talk in the terms the language specification uses. There are names and objects, and mechanisms by which names come to refer to objects according to the execution model. > (However, since "pointer" is evokes passions among crowds, it is better > to use the neutral word "leash".) Talk of pointers is potentially confusing, because it carries baggage from other languages which doesn't necessary map precisely onto the python execution model. (The underlying cpython implementation, is neither here nor there - we could in theory implement python in some other language which lacks a pointer type.) From __peter__ at web.de Thu Jun 9 10:13:31 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jun 2016 16:13:31 +0200 Subject: UserList - which methods needs to be overriden? References: <917ca9c4-aef1-6681-ec70-62de8916117d@shopzeus.com> <7cdb398f-b3f2-9a3c-b444-2229f8496e2f@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > >> Using the built-in list or dict is problematic because sometimes the >> subclass methods are ignored when the internal data is accessed (sorry, I >> don't have an example). > Are you suggesting that I should use UserList and UserDict instead of > list and dict? What is the truth? Was UserDict left in collections for > backward compatibility, or not? > >> >> How detailed is your change notification? If it's always the same method >> invocation you may be able to create wrappers like >> >> def whatever(self, *args): >> try: >> return super().whatever(*args) >> finally: >> self.changed() >> >> automatically, and the base class, be it list or UserList or whatever >> becomes a detail that can be chosen on a case by case basis. > My actual solution looks like this: > > > class ObservableCollection(Observable): > @contextmanager > def notify(self): > self.notify_observers(EVT_BEFORE_COLLECTION_CHANGED) > yield > self.notify_observers(EVT_AFTER_COLLECTION_CHANGED) > > class ObservableList(ObservableCollection, list): > __slots__ = [] > > def remove(self, value): > with self.notify(): super().remove(value) > > def clear(self): > with self.notify(): super().clear() > > def pop(self): > with self.notify(): return super().pop() > > It seems to be working with the built in list, dict and set types. > > There must be a better way! Something like this: > > @wrap_notify('remove', 'clear', 'append', 'insert', 'sort'): > class ObservableList(ObservableCollection, list): > pass > > I just can't find out the right syntax. [Looks like you made progress while I struggled to come up with the following. I'll post it anyway.] $ cat observable_list.py from contextlib import contextmanager EVT_BEFORE_COLLECTION_CHANGED = "EVT_BEFORE_COLLECTION_CHANGED" EVT_AFTER_COLLECTION_CHANGED = "EVT_AFTER_COLLECTION_CHANGED" class Observable: def notify_observers(self, message): print(message) def wrap_notify(*names): def wrap_methods(cls): for name in names: method = wrap_method(getattr(cls, name), name) setattr(cls, name, method) return cls return wrap_methods def wrap_method(method, name): def wrapped_method(self, *args, **kw): with self.notify(): return method(self, *args, **kw) return wrapped_method class ObservableCollection(Observable): @contextmanager def notify(self): self.notify_observers(EVT_BEFORE_COLLECTION_CHANGED) yield self.notify_observers(EVT_AFTER_COLLECTION_CHANGED) @wrap_notify('remove', 'clear', 'append', 'insert', 'sort') class ObservableList(ObservableCollection, list): pass items = ObservableList() items.append(42) items.append(41) items.sort() print(items) $ python3 observable_list.py EVT_BEFORE_COLLECTION_CHANGED EVT_AFTER_COLLECTION_CHANGED EVT_BEFORE_COLLECTION_CHANGED EVT_AFTER_COLLECTION_CHANGED EVT_BEFORE_COLLECTION_CHANGED EVT_AFTER_COLLECTION_CHANGED [41, 42] From mal at europython.eu Thu Jun 9 10:33:18 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 9 Jun 2016 16:33:18 +0200 Subject: EuroPython 2016 Keynotes Message-ID: <57597E2E.8080103@europython.eu> We are pleased to announce our keynote schedule for EuroPython 2016: * Monday: Rachel Willmer & Nicholas Tollervey * Tuesday: Paul Hildebrandt * Wednesday: Jameson Rollins * Thursday: Naomi Ceder * Friday: Ga?l Varoquaux More information about our keynoters is available on the keynote schedule page and the blog posts for each keynote: *** EuroPython 2016 Keynotes *** https://ep2016.europython.eu/en/events/keynotes/ We have also updated the schedule accordingly: *** EuroPython 2016 Schedule *** https://ep2016.europython.eu/p3/schedule/ep2016/ With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/740868506862915584 Thanks. From marko at pacujo.net Thu Jun 9 11:14:10 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 09 Jun 2016 18:14:10 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <87k2hy1y2i.fsf@rudin.co.uk> <878tyeplky.fsf@elektro.pacujo.net> <87eg861mk6.fsf@rudin.co.uk> Message-ID: <87y46eo0n1.fsf@elektro.pacujo.net> Paul Rudin : > Marko Rauhamaa writes: >> The object is only an intermediate result; what is returned is a >> pointer (to an object), without an exception. That's not a matter of >> implementation. It's an essential part of Python's data model. > > Well - the language has no explicit notion of "pointer", [...] it's > better (IMO) to just talk in the terms the language specification > uses. The spec () uses the terms *identity* and *reference*, which are one-to-one. > There are names and objects, and mechanisms by which names come to > refer to objects according to the execution model. The spec as well as Python itself uses the word "name" for various strings: >>> "x".__class__.__name__ 'str' >>> __name__ '__main__' So your "names" are *variables*. Your "mechanisms" are *references*. Your "objects" are *objects*. > Talk of pointers is potentially confusing, because it carries baggage > from other languages which doesn't necessary map precisely onto the > python execution model. Unfortunately, virtually every word is overloaded and full of preconceived notions. Hence: "pegs", "leashes", "puppies". The main thing is to keep those three concepts apart from each other. Two notions will not suffice. Marko From nevzat.guler at gmail.com Thu Jun 9 11:54:16 2016 From: nevzat.guler at gmail.com (Nev) Date: Thu, 9 Jun 2016 08:54:16 -0700 (PDT) Subject: movie from pictures In-Reply-To: <7e57c662-a6c2-441d-a46e-49458439250f@googlegroups.com> References: <7e57c662-a6c2-441d-a46e-49458439250f@googlegroups.com> Message-ID: <16301530-a24b-42c6-bcf6-007c4eb85aca@googlegroups.com> Thank you for your reply. I tried something like this in python code: from subprocess import call call(["ffmpeg -framerate 4/1 -start_number 1 -i C:\\Projects\\data2\\img_%05d.png -c:v libx264 -r 30 -pix_fmt yuv420p C:\\Projects\\data2\\movie.mp4"]) But it did not work. I get FileNotFoundError: [WinError 2] The system cannot find the file specified.. On the other hand, in-loop solution would be more preferable since it lets me to use variable names of the images and paths.. From paul.nospam at rudin.co.uk Thu Jun 9 12:22:26 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 09 Jun 2016 17:22:26 +0100 Subject: I'm wrong or Will we fix the ducks limp? References: <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <87k2hy1y2i.fsf@rudin.co.uk> <878tyeplky.fsf@elektro.pacujo.net> <87eg861mk6.fsf@rudin.co.uk> <87y46eo0n1.fsf@elektro.pacujo.net> Message-ID: <874m921ge5.fsf@rudin.co.uk> Marko Rauhamaa writes: > Paul Rudin : > >> Marko Rauhamaa writes: >>> The object is only an intermediate result; what is returned is a >>> pointer (to an object), without an exception. That's not a matter of >>> implementation. It's an essential part of Python's data model. >> >> Well - the language has no explicit notion of "pointer", [...] it's >> better (IMO) to just talk in the terms the language specification >> uses. > > The spec () > uses the terms *identity* and *reference*, which are one-to-one. identity isn't the same thing as a name, identity is an inherent property of an object - many names may refer to the same object. Similarly reference doesn't mean the same thing as identity. A reference to an object can occur, for example: ["foo"] The list refers to the string. There's no name involved anywhere. Both the list and the string have an identity, but that's essentially irrelevant to the fact that the list has a reference to the string. > >> There are names and objects, and mechanisms by which names come to >> refer to objects according to the execution model. > > The spec as well as Python itself uses the word "name" for various > strings: > > >>> "x".__class__.__name__ > 'str' > >>> __name__ > '__main__' > __name__ is not the same thing as what the spec means when it talks of a name. It's certainly true that a class declaration creates a binding from that name to an object representing the class. But other names can equally well refer to the same object: >>> class Foo: ... pass ... >>> Bar = Foo >>> x = Bar() >>> x.__class__.__name__ 'Foo' >>> > > So your "names" are *variables*. Informally yes, but "variable" has no meaning in the language reference. > > Your "mechanisms" are *references*. > Nope - when I spoke of mechanisms I was talking about the different operational semantics by which a given names can be bound to an object. Once such an binding has occured then I agree that the name refers to the object in question. > Your "objects" are *objects*. > I think I probably agree, but I'm not sure what you're saying - "object" means something in the language reference - that's what I'm talking about. >> Talk of pointers is potentially confusing, because it carries baggage >> from other languages which doesn't necessary map precisely onto the >> python execution model. > > Unfortunately, virtually every word is overloaded and full of > preconceived notions. Hence: "pegs", "leashes", "puppies". > > The main thing is to keep those three concepts apart from each other. > Two notions will not suffice. > Well - adding more things is confusing in IMO - we have a language reference, let's just use the terms in the language reference. From paul.nospam at rudin.co.uk Thu Jun 9 12:48:15 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 09 Jun 2016 17:48:15 +0100 Subject: I'm wrong or Will we fix the ducks limp? References: <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <87k2hy1y2i.fsf@rudin.co.uk> <878tyeplky.fsf@elektro.pacujo.net> <87eg861mk6.fsf@rudin.co.uk> <87y46eo0n1.fsf@elektro.pacujo.net> <874m921ge5.fsf@rudin.co.uk> Message-ID: <87ziquz4ts.fsf@rudin.co.uk> Paul Rudin writes: > Marko Rauhamaa writes: >> So your "names" are *variables*. > > Informally yes, but "variable" has no meaning in the language reference. > ... err sorry, actually not correct - but irrelevant to the point under discussion. From gandalf at shopzeus.com Thu Jun 9 12:52:59 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 9 Jun 2016 18:52:59 +0200 Subject: UserList - which methods needs to be overriden? In-Reply-To: References: <917ca9c4-aef1-6681-ec70-62de8916117d@shopzeus.com> <7cdb398f-b3f2-9a3c-b444-2229f8496e2f@shopzeus.com> Message-ID: > [Looks like you made progress while I struggled to come up with the > following. I'll post it anyway.] Your version is much better. Thanks! :-) From gordon at panix.com Thu Jun 9 13:59:10 2016 From: gordon at panix.com (John Gordon) Date: Thu, 9 Jun 2016 17:59:10 +0000 (UTC) Subject: why it is like stop running after a 3 seconds References: <35cd5920-1fbb-441f-9fc6-2f3f2e5f8568@googlegroups.com> Message-ID: In <35cd5920-1fbb-441f-9fc6-2f3f2e5f8568 at googlegroups.com> Ho Yeung Lee writes: > i write a program, it is like forever loop > but i only restrict it to run 2 level recursively, I don't think the restriction is working. There is "if deep > 0:" at the top of the function, but the recursive calls aren't inside that if block. DFS keeps calling itself with smaller and smaller values of deep. -- 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 random832 at fastmail.com Thu Jun 9 14:36:54 2016 From: random832 at fastmail.com (Random832) Date: Thu, 09 Jun 2016 14:36:54 -0400 Subject: I'm wrong or Will we fix the ducks limp? In-Reply-To: <57591B21.7050509@rece.vub.ac.be> References: <5754f36b$0$1619$c3e8da3$5496439d@news.astraweb.com> <1465186088.3554819.628831041.19D0DC8D@webmail.messagingengine.com> <575599f4$0$1595$c3e8da3$5496439d@news.astraweb.com> <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <57591B21.7050509@rece.vub.ac.be> Message-ID: <1465497414.2026372.633057497.567E0A75@webmail.messagingengine.com> On Thu, Jun 9, 2016, at 03:30, Antoon Pardon wrote: > Then you think wrong. Python has no pointers, that is an implementation > detail. Nonsense. A binary number referring to a memory address is an implementation detail. A pointer/reference/arrow-thingy-on-a-diagram is the thing it is an implementation detail *of*. From __peter__ at web.de Thu Jun 9 14:58:05 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jun 2016 20:58:05 +0200 Subject: movie from pictures References: <7e57c662-a6c2-441d-a46e-49458439250f@googlegroups.com> <16301530-a24b-42c6-bcf6-007c4eb85aca@googlegroups.com> Message-ID: Nev wrote: > Thank you for your reply. I tried something like this in python code: > > from subprocess import call > call(["ffmpeg -framerate 4/1 -start_number 1 -i > C:\\Projects\\data2\\img_%05d.png -c:v libx264 -r 30 -pix_fmt yuv420p > C:\\Projects\\data2\\movie.mp4"]) > > But it did not work. I get FileNotFoundError: [WinError 2] The system > cannot find the file specified.. You have to pass the command-line arguments as separate items in the list: call(["ffmpeg", "-framerate", "4/1", "-start_number", "1", "-i", "C:\\Projects\\data2\\img_%05d.png", ... # and so on ]) > On the other hand, in-loop solution would be more preferable since it lets > me to use variable names of the images and paths.. From python at mrabarnett.plus.com Thu Jun 9 15:25:32 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 9 Jun 2016 20:25:32 +0100 Subject: movie from pictures In-Reply-To: References: <7e57c662-a6c2-441d-a46e-49458439250f@googlegroups.com> <16301530-a24b-42c6-bcf6-007c4eb85aca@googlegroups.com> Message-ID: On 2016-06-09 19:58, Peter Otten wrote: > Nev wrote: > >> Thank you for your reply. I tried something like this in python code: >> >> from subprocess import call >> call(["ffmpeg -framerate 4/1 -start_number 1 -i >> C:\\Projects\\data2\\img_%05d.png -c:v libx264 -r 30 -pix_fmt yuv420p >> C:\\Projects\\data2\\movie.mp4"]) >> >> But it did not work. I get FileNotFoundError: [WinError 2] The system >> cannot find the file specified.. > > You have to pass the command-line arguments as separate items in the list: > > call(["ffmpeg", > "-framerate", "4/1", > "-start_number", "1", > "-i", "C:\\Projects\\data2\\img_%05d.png", > ... # and so on > ]) > You should also give it the full path of ffmpeg. >> On the other hand, in-loop solution would be more preferable since it lets >> me to use variable names of the images and paths.. From marko at pacujo.net Thu Jun 9 15:35:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 09 Jun 2016 22:35:09 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <87k2hy1y2i.fsf@rudin.co.uk> <878tyeplky.fsf@elektro.pacujo.net> <87eg861mk6.fsf@rudin.co.uk> <87y46eo0n1.fsf@elektro.pacujo.net> <874m921ge5.fsf@rudin.co.uk> Message-ID: <87bn3a2m1e.fsf@elektro.pacujo.net> Paul Rudin : > Marko Rauhamaa writes: >> The spec () >> uses the terms *identity* and *reference*, which are one-to-one. > > identity isn't the same thing as a name, identity is an inherent > property of an object - many names may refer to the same object. x is y if and only if id(x) == id(y) However, sorry for muddling the discussion by bringing in the identity. I'll leave it out for now. >> So your "names" are *variables*. > > Informally yes, but "variable" has no meaning in the language reference. Really? How do you interpret these, then? Although the definition of assignment implies that overlaps between the left-hand side and the right-hand side are ?simultaneous? (for example a, b = b, a swaps two variables), overlaps within the collection of assigned-to variables occur left-to-right, sometimes resulting in confusion. Assignments to __debug__ are illegal. The value for the built-in variable is determined when the interpreter starts. The public names defined by a module are determined by checking the module?s namespace for a variable named __all__ It would be impossible to assign to a global variable without global, although free variables may refer to globals without being declared global. >> Unfortunately, virtually every word is overloaded and full of >> preconceived notions. Hence: "pegs", "leashes", "puppies". >> >> The main thing is to keep those three concepts apart from each other. >> Two notions will not suffice. > > Well - adding more things is confusing in IMO - we have a language > reference, let's just use the terms in the language reference. I have quoted "the language reference" quite a bit. Your turn. You would be correct that there is something of an faux elitism going around that is influencing the language spec as well to a degree. It appears some people consider "variables," "assignments," "pointers" etc to be too riff-raff. So people want to say Python is unlike C and has "names," "bindings," "references" etc. There's no shame in stating directly that Python has variables just like C even though Python's variables are not first-class. There's no difference between binding and assignment. And a reference is a synonym to a pointer. Python still has good stuff C doesn't, or even Java. Marko From ethan at stoneleaf.us Thu Jun 9 15:53:37 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jun 2016 12:53:37 -0700 Subject: PyCon Keynote Message-ID: <5759C941.8040900@stoneleaf.us> There were many good talks and presentations at PyCon 2016, but if you can only watch one, this is the one to watch: https://www.youtube.com/watch?v=bSfe5M_zG2s -- ~Ethan~ From michael.selik at gmail.com Thu Jun 9 18:38:28 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 09 Jun 2016 22:38:28 +0000 Subject: UserList - which methods needs to be overriden? In-Reply-To: References: Message-ID: On Thu, Jun 9, 2016 at 5:07 AM Nagy L?szl? Zsolt wrote: > I would like to create a collections.UserList subclass that can notify > others when the list is mutated. > Why not subclass MutableSequence instead? The ABC will tell you which methods to override (the abstract ones). The mixin methods rely on those overrides. from collections.abc import MutableSequence def noisy(message): def decorator(func): def wrapper(*args, **kwargs): print(message) return func(*args, **kwargs) return wrapper return decorator class NoisyList(MutableSequence): def __init__(self, *args, **kwargs): self.contents = list(*args, **kwargs) def __getitem__(self, index): return self.contents[index] def __len__(self): return len(self.contents) @noisy('set') def __setitem__(self, index, value): self.contents[index] = value @noisy('del') def __delitem__(self, index): del self.contents[index] @noisy('insert') def insert(self, index, value): self.contents.insert(index, value) From michael.selik at gmail.com Thu Jun 9 18:40:35 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 09 Jun 2016 22:40:35 +0000 Subject: Tie dictionary to database table? In-Reply-To: References: Message-ID: On Thu, Jun 9, 2016 at 9:10 AM justin walters wrote: > It looks like you might be looking for an ORM. Have you checked out > sqlalchemy? > An ORM might be overkill. If you just want a persistent dictionary, just use the shelve module. https://docs.python.org/3/library/shelve.html From michael.selik at gmail.com Thu Jun 9 18:44:47 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 09 Jun 2016 22:44:47 +0000 Subject: which library has map reduce and how to use it for this case In-Reply-To: <1ca428db-ea39-4964-a662-df2701580bd2@googlegroups.com> References: <1ca428db-ea39-4964-a662-df2701580bd2@googlegroups.com> Message-ID: I like using Yelp's mrjob module (https://github.com/Yelp/mrjob) to run Python on Hadoop. On Thu, Jun 9, 2016 at 2:56 AM Ho Yeung Lee wrote: > [... a bunch of code ...] If you want to describe a map-reduce problem, start with the data. What does a record of your input data look like? Then think about your mapper. What key-value pairs will you extract from each line of data? Then think about your reducer. For a single key and its associated values, what will you calculate? From kwa at kuwata-lab.com Thu Jun 9 19:33:03 2016 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Fri, 10 Jun 2016 08:33:03 +0900 Subject: [Q] ImportError by __import__() on Python >= 3.4 In-Reply-To: References: Message-ID: On Wed, Jun 8, 2016 at 10:24 PM, Michael Selik wrote: > By the way, why choose to write, import, and delete modules? I'd think > exec'ing code would be sufficient. > > In order to test my own framework for web application. It loads controller classes lazily. In other words, it loads python module only when it is required. For example: mappings = [ (r'/api/hello', 'myapp1.api.hello.Hello'), # myapp1/api/hello.py will be loaded lazily ] app = WSGIApplication(mappings) In order to test this framework, it is necessary to create and load python module file dynamically. -- regars, makoto From jobmattcon at gmail.com Thu Jun 9 20:58:44 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 9 Jun 2016 17:58:44 -0700 (PDT) Subject: how to solve memory Message-ID: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=2 M1['02']=1 M1['10']=1 M1['11']=1 M1['12']=1 M1['20']=1 M1['21']=1 M1['22']=2 M2['00']=0 M2['01']=1 M2['02']=1 M2['10']=1 M2['11']=1 M2['12']=1 M2['20']=1 M2['21']=1 M2['22']=1 M3['00']=2 M3['01']=2 M3['02']=2 M3['10']=0 M3['11']=2 M3['12']=1 M3['20']=0 M3['21']=1 M3['22']=2 M4['00']=1 M4['01']=2 M4['02']=1 M4['10']=2 M4['11']=2 M4['12']=2 M4['20']=0 M4['21']=1 M4['22']=2 M5['00']=0 M5['01']=1 M5['02']=1 M5['10']=0 M5['11']=2 M5['12']=1 M5['20']=0 M5['21']=1 M5['22']=1 V6['00']=1 V6['01']=1 V6['02']=2 V6['10']=1 V6['11']=2 V6['12']=1 V6['20']=1 V6['21']=2 V6['22']=2 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: b = [] #print(len(list(itertools.combinations(initlist, 2)))) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) else: #print(len(list(itertools.combinations(initlist, 2)))) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) return path path = [] mresult = DFS(b, 2, 2, mylist, path) From davidbenny2000 at gmail.com Thu Jun 9 21:07:04 2016 From: davidbenny2000 at gmail.com (Ho Yeung Lee) Date: Thu, 9 Jun 2016 18:07:04 -0700 (PDT) Subject: which library has map reduce and how to use it for this case In-Reply-To: References: <1ca428db-ea39-4964-a662-df2701580bd2@googlegroups.com> Message-ID: input are these six operators, output is finding full column of 27 elements add together is 54 i got memory error when searching this, i have difficulty in understanding map reduce and transforming my program into map reduce problem M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=2 M1['02']=1 M1['10']=1 M1['11']=1 M1['12']=1 M1['20']=1 M1['21']=1 M1['22']=2 M2['00']=0 M2['01']=1 M2['02']=1 M2['10']=1 M2['11']=1 M2['12']=1 M2['20']=1 M2['21']=1 M2['22']=1 M3['00']=2 M3['01']=2 M3['02']=2 M3['10']=0 M3['11']=2 M3['12']=1 M3['20']=0 M3['21']=1 M3['22']=2 M4['00']=1 M4['01']=2 M4['02']=1 M4['10']=2 M4['11']=2 M4['12']=2 M4['20']=0 M4['21']=1 M4['22']=2 M5['00']=0 M5['01']=1 M5['02']=1 M5['10']=0 M5['11']=2 M5['12']=1 M5['20']=0 M5['21']=1 M5['22']=1 V6['00']=1 V6['01']=1 V6['02']=2 V6['10']=1 V6['11']=2 V6['12']=1 V6['20']=1 V6['21']=2 V6['22']=2 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: b = [] #print(len(list(itertools.combinations(initlist, 2)))) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) else: #print(len(list(itertools.combinations(initlist, 2)))) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) return path path = [] mresult = DFS(b, 2, 2, mylist, path) Michael Selik? 2016?6?10???? UTC+8??6?45?14???? > I like using Yelp's mrjob module (https://github.com/Yelp/mrjob) to run > Python on Hadoop. > > On Thu, Jun 9, 2016 at 2:56 AM Ho Yeung Lee > wrote: > > > [... a bunch of code ...] > > > If you want to describe a map-reduce problem, start with the data. What > does a record of your input data look like? > > Then think about your mapper. What key-value pairs will you extract from > each line of data? > > Then think about your reducer. For a single key and its associated values, > what will you calculate? From torriem at gmail.com Thu Jun 9 21:12:48 2016 From: torriem at gmail.com (Michael Torrie) Date: Thu, 9 Jun 2016 19:12:48 -0600 Subject: how to solve memory In-Reply-To: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> Message-ID: <5bb40548-fcbe-34a2-54e3-275d11fb042b@gmail.com> On 06/09/2016 06:58 PM, meInvent bbird wrote: > Do you have a question for the list? If so, please state what it is, and describe what you are doing and what isn't working. If you can boil it down to a dozen lines of run-able, self-contained code that illustrates the problem, that is helpful too. From jobmattcon at gmail.com Fri Jun 10 00:59:19 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 9 Jun 2016 21:59:19 -0700 (PDT) Subject: how to solve memory In-Reply-To: References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <5bb40548-fcbe-34a2-54e3-275d11fb042b@gmail.com> Message-ID: On Friday, June 10, 2016 at 9:13:13 AM UTC+8, Michael Torrie wrote: > On 06/09/2016 06:58 PM, meInvent bbird wrote: > > > > Do you have a question for the list? If so, please state what it is, and > describe what you are doing and what isn't working. If you can boil it > down to a dozen lines of run-able, self-contained code that illustrates > the problem, that is helpful too. there are six operator, and a logic table initial in b variable aa[b[j][i]] [aa[b[i][0:1]+b[i][2:3] are just like vlookup to find output of each operator acting on first column and second column, second column and third column , first column and third column and searching a output columns which is result sum is 27*2 and record the path if succeed, it record the path and output any path which has result is 27*2 described before op1(op2(op3(op1(op2(),),op1(op2(),))), op1(op2(),)) there are two cases, first cases b are logic table later case are for six operators acting on the result column from previous result before recursive call From jussi.piitulainen at helsinki.fi Fri Jun 10 01:31:50 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 10 Jun 2016 08:31:50 +0300 Subject: I'm wrong or Will we fix the ducks limp? References: <57569f6a$0$11124$c3e8da3@news.astraweb.com> <5756BED8.2000304@rece.vub.ac.be> <1465313620.1380508.630546953.7F7E755D@webmail.messagingengine.com> <5757CF15.4010002@rece.vub.ac.be> <5757dbaf$0$1615$c3e8da3$5496439d@news.astraweb.com> <5757E840.80805@rece.vub.ac.be> <5757FB1B.5000502@rece.vub.ac.be> <5758292E.2020600@rece.vub.ac.be> <871t474ox1.fsf@elektro.pacujo.net> <87k2hy1y2i.fsf@rudin.co.uk> <878tyeplky.fsf@elektro.pacujo.net> <87eg861mk6.fsf@rudin.co.uk> <87y46eo0n1.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Paul Rudin wrote: >> Talk of pointers is potentially confusing, because it carries baggage >> from other languages which doesn't necessary map precisely onto the >> python execution model. > > Unfortunately, virtually every word is overloaded and full of > preconceived notions. Hence: "pegs", "leashes", "puppies". > > The main thing is to keep those three concepts apart from each other. > Two notions will not suffice. Does a new leash appear when a puppy is tied to a peg? Apparently. Is it possible to tie two puppies to the same peg? Apparently not. Why not? Is the leash left dangling in the neck of a puppy if another puppy is tied to its peg? What if the puppy is tied again to the same peg, is there then the new leash from its neck to the peg, and the old leash left dangling? Is it possible to leave the leash tied to the peg but untie the puppy? Apparently not. It's also not possible to look at the puppy and follow all the leashes to find all the pegs where the puppy is tied. The real third thing is not a thing but a relationship: being tied to. From peter.heitzer at rz.uni-regensburg.de Fri Jun 10 03:30:48 2016 From: peter.heitzer at rz.uni-regensburg.de (Peter Heitzer) Date: 10 Jun 2016 07:30:48 GMT Subject: Tie dictionary to database table? References: Message-ID: Michael Selik wrote: >On Thu, Jun 9, 2016 at 9:10 AM justin walters >wrote: >> It looks like you might be looking for an ORM. Have you checked out >> sqlalchemy? >> >An ORM might be overkill. If you just want a persistent dictionary, just >use the shelve module. https://docs.python.org/3/library/shelve.html That looks like tie in Perl. Unfortunately I have to use mysql as database and I need concurrent read/write as the table may be modified by other processes. Meanwhile I have analized my demans a bit and modified the task so that I need not read values but rather make updates to the tables. -- Dipl.-Inform(FH) Peter Heitzer, peter.heitzer at rz.uni-regensburg.de From auriocus at gmx.de Fri Jun 10 03:38:47 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 10 Jun 2016 09:38:47 +0200 Subject: Tie dictionary to database table? In-Reply-To: References: Message-ID: Am 10.06.16 um 09:30 schrieb Peter Heitzer: > Michael Selik wrote: >> An ORM might be overkill. If you just want a persistent dictionary, just >> use the shelve module. https://docs.python.org/3/library/shelve.html > That looks like tie in Perl. Unfortunately I have to use mysql as database > and I need concurrent read/write as the table may be modified by other > processes. > Meanwhile I have analized my demans a bit and modified the task so that I > need not read values but rather make updates to the tables. It wouldn't be that difficult to roll your own thing which does that; you just need to define __setitem__ and __getitem__ in your class which translates between the SQL call and the Python code. Christian From gandalf at shopzeus.com Fri Jun 10 04:04:38 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 10 Jun 2016 10:04:38 +0200 Subject: UserList - which methods needs to be overriden? In-Reply-To: References: Message-ID: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> 2016.06.10. 0:38 keltez?ssel, Michael Selik ?rta: > On Thu, Jun 9, 2016 at 5:07 AM Nagy L?szl? Zsolt > wrote: > > I would like to create a collections.UserList subclass that can notify > others when the list is mutated. > > > Why not subclass MutableSequence instead? The ABC will tell you which > methods to override (the abstract ones). The mixin methods rely on > those overrides. I'm not sure wich one is the best. Peter wrote that UserList was left in collections only for backward compatiblity. This might be a point against using UserList. The thing with MutableSequence is that it is quite inefficient. For example, it implements clear() by calling pop() in a loop. It implements extend() by calling append() in a loop. And we all know that the built-in extend() method of the list object is much more efficient. It is true that by overriding the abstract methods, I'll get a functional list like object, but we all know that There should be one-- and preferably only one --obvious way to do it. Which one is that? :-) From robin at reportlab.com Fri Jun 10 04:33:05 2016 From: robin at reportlab.com (Robin Becker) Date: Fri, 10 Jun 2016 09:33:05 +0100 Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy In-Reply-To: References: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> Message-ID: <73515c1e-5d48-45b1-a43d-6297de0faa34@chamonix.reportlab.co.uk> On 08/06/2016 19:32, rocky wrote: .......... > > Sorry that should have been 1998 which would make more sense for the 7th conference if the 1st one was around 2001. I've corrected the date in [1] https://pypi.python.org/pypi/spark_parser/1.3.0 > > The automated tests in the package just don't catch stuff like this. But I'm sure there are also other mistakes as well in there so feel free to let me know. > not a big deal; I like the spark parser :) -- Robin Becker From __peter__ at web.de Fri Jun 10 04:37:05 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 10 Jun 2016 10:37:05 +0200 Subject: UserList - which methods needs to be overriden? References: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> Message-ID: Nagy L?szl? Zsolt wrote: > I'm not sure wich one is the best. Peter wrote that UserList was left in > collections only for backward compatiblity. This might be a point I'll take that back. I looked around and found no evidence for my claim. Only MutableString was removed during the transition to Python 3. Sorry for the confusion. From maxischmeii at gmail.com Fri Jun 10 06:11:05 2016 From: maxischmeii at gmail.com (Maxime S) Date: Fri, 10 Jun 2016 12:11:05 +0200 Subject: UserList - which methods needs to be overriden? In-Reply-To: References: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> Message-ID: 2016-06-10 10:37 GMT+02:00 Peter Otten <__peter__ at web.de>: > > Nagy L?szl? Zsolt wrote: > > > I'm not sure wich one is the best. Peter wrote that UserList was left in > > collections only for backward compatiblity. This might be a point > > I'll take that back. I looked around and found no evidence for my claim. > Only MutableString was removed during the transition to Python 3. > > Sorry for the confusion. > > Up to Python 2.6, the docs of UserList had a note stating that: This module is available for backward compatibility only. If you are writing code that does not need to work with versions of Python earlier than Python 2.2, please consider subclassing directly from the built-in list type. This was changed in Python 2.7 to: When Python 2.2 was released, many of the use cases for this class were subsumed by the ability to subclass list directly. However, a handful of use cases remain. So I think the intention was that the ability to subclass list would remove the need to subclass UserList, but it was later realised that it is not totally the case. From peter.heitzer at rz.uni-regensburg.de Fri Jun 10 06:56:24 2016 From: peter.heitzer at rz.uni-regensburg.de (Peter Heitzer) Date: 10 Jun 2016 10:56:24 GMT Subject: Tie dictionary to database table? References: Message-ID: Christian Gollwitzer wrote: >Am 10.06.16 um 09:30 schrieb Peter Heitzer: >> Michael Selik wrote: >>> An ORM might be overkill. If you just want a persistent dictionary, just >>> use the shelve module. https://docs.python.org/3/library/shelve.html >> That looks like tie in Perl. Unfortunately I have to use mysql as database >> and I need concurrent read/write as the table may be modified by other >> processes. >> Meanwhile I have analized my demans a bit and modified the task so that I >> need not read values but rather make updates to the tables. >It wouldn't be that difficult to roll your own thing which does that; >you just need to define __setitem__ and __getitem__ in your class which >translates between the SQL call and the Python code. That's a good idea. -- Dipl.-Inform(FH) Peter Heitzer, peter.heitzer at rz.uni-regensburg.de From alister.ware at ntlworld.com Fri Jun 10 07:18:18 2016 From: alister.ware at ntlworld.com (alister) Date: Fri, 10 Jun 2016 11:18:18 GMT Subject: for / while else doesn't make sense Message-ID: <_lx6z.1194262$z22.146690@fx36.am4> On Thu, 09 Jun 2016 18:19:23 +1000, Steven D'Aprano wrote: > On Thursday 09 June 2016 10:34, Lawrence D?Oliveiro wrote: > >> In my undergraduate Comp Sci classes, we used to discuss arbitrary >> rules like limiting functions to n lines. With real-world experience, >> it soon became clear that such rules were a waste of time. A function >> should be just as big as it needs to be, no more, no less. The same >> with a class, or a module. Or whatever other constructs your language >> may have. > > The opposite of "arbitrary limits" is not "no limits". > > An arbitrary limit like "500 lines is the maximum size a function may > be" is clearly arbitrary and not very helpful. (Also too high.) > > Better is to understand that there is no hard cut-off between > "acceptable" and "too long", but we can still judge that all else being > equal, long functions are worse than short functions. > > The real problem is complexity of functions. The more complex they are, > the harder they are to write correctly, and the harder to maintain, and > the more likely that they have bugs. > > The length of a function is a very crude measure of complexity, but it > *is* a measure of complexity, and people are right to look at long > functions as a code smell and a sign that the function probably does too > much, or is badly written, > or that it could do with some refactoring to simplify it. Not in *every* > case, but I've never yet seen a long (> 200 lines) function that wasn't > improved by refactoring or splitting. Or more simply a hard fixed RULE (MUST be less than X lines) is Bad. a flexible GUIDELINE on the other hand is reasonable. after all an efficient function could be be X=1 lines, abriatrily spliting this could make the final function less readable & possibly even longer in total. -- Puns are little "plays on words" that a certain breed of person loves to spring on you and then look at you in a certain self-satisfied way to indicate that he thinks that you must think that he is by far the cleverest person on Earth now that Benjamin Franklin is dead, when in fact what you are thinking is that if this person ever ends up in a lifeboat, the other passengers will hurl him overboard by the end of the first day even if they have plenty of food and water. -- Dave Barry, "Why Humor is Funny" From __peter__ at web.de Fri Jun 10 08:25:22 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 10 Jun 2016 14:25:22 +0200 Subject: Tie dictionary to database table? References: Message-ID: Peter Heitzer wrote: > Christian Gollwitzer wrote: >>Am 10.06.16 um 09:30 schrieb Peter Heitzer: >>> Michael Selik wrote: >>>> An ORM might be overkill. If you just want a persistent dictionary, >>>> just use the shelve module. >>>> https://docs.python.org/3/library/shelve.html >>> That looks like tie in Perl. Unfortunately I have to use mysql as >>> database and I need concurrent read/write as the table may be modified >>> by other processes. >>> Meanwhile I have analized my demans a bit and modified the task so that >>> I need not read values but rather make updates to the tables. > >>It wouldn't be that difficult to roll your own thing which does that; >>you just need to define __setitem__ and __getitem__ in your class which >>translates between the SQL call and the Python code. > That's a good idea. There's an old recipe for sqlite3 http://code.activestate.com/recipes/576638-draft-for-an-sqlite3-based-dbm/ that you might adapt. From marko at pacujo.net Fri Jun 10 08:31:11 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 10 Jun 2016 15:31:11 +0300 Subject: for / while else doesn't make sense References: <_lx6z.1194262$z22.146690@fx36.am4> Message-ID: <87shwlns34.fsf@elektro.pacujo.net> alister : > Or more simply a hard fixed RULE (MUST be less than X lines) is Bad. It's not X lines, it's "you must see the whole function at once." If your display can show 1,500 lines at once, that's your limit. Mine shows 70. > a flexible GUIDELINE on the other hand is reasonable. There are rare exceptions to every rule. > after all an efficient function could be be X=1 lines, abriatrily > spliting this could make the final function less readable & possibly > even longer in total. Splitting functions requires taste and skill but, when done properly, guarantees easier reading and higher quality. As you refactor your function, you notice clumsy and questionable idioms and end up tidying the logic up in the process. Marko From alister.ware at ntlworld.com Fri Jun 10 09:06:20 2016 From: alister.ware at ntlworld.com (alister) Date: Fri, 10 Jun 2016 13:06:20 GMT Subject: for / while else doesn't make sense References: <_lx6z.1194262$z22.146690@fx36.am4> <87shwlns34.fsf@elektro.pacujo.net> Message-ID: On Fri, 10 Jun 2016 15:31:11 +0300, Marko Rauhamaa wrote: > alister : > >> Or more simply a hard fixed RULE (MUST be less than X lines) is Bad. > > It's not X lines, it's "you must see the whole function at once." > > If your display can show 1,500 lines at once, that's your limit. Mine > shows 70. > >> a flexible GUIDELINE on the other hand is reasonable. > > There are rare exceptions to every rule. > >> after all an efficient function could be be X=1 lines, abriatrily >> spliting this could make the final function less readable & possibly >> even longer in total. > > Splitting functions requires taste and skill but, when done properly, > guarantees easier reading and higher quality. As you refactor your > function, you notice clumsy and questionable idioms and end up tidying > the logic up in the process. > > > Marko you think I am arguing? i am not (excpet possibly on symantics) your "you must see the whole function on one page" stipulation should be treated as guidance & not a rule preferably it should read "You 'SHOULD' be able to see the whole function on one page. and as you quite rightly state there are always exceptions as enshrined in the zen "Practicality beats Purity" -- Must I hold a candle to my shames? -- William Shakespeare, "The Merchant of Venice" From michael.selik at gmail.com Fri Jun 10 09:18:56 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 10 Jun 2016 13:18:56 +0000 Subject: UserList - which methods needs to be overriden? In-Reply-To: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> References: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> Message-ID: On Fri, Jun 10, 2016, 4:05 AM Nagy L?szl? Zsolt wrote: > 2016.06.10. 0:38 keltez?ssel, Michael Selik ?rta: > > On Thu, Jun 9, 2016 at 5:07 AM Nagy L?szl? Zsolt > wrote: > >> I would like to create a collections.UserList subclass that can notify >> others when the list is mutated. >> > > Why not subclass MutableSequence instead? The ABC will tell you which > methods to override (the abstract ones). The mixin methods rely on those > overrides. > > I'm not sure wich one is the best. Peter wrote that UserList was left in > collections only for backward compatiblity. This might be a point against > using UserList. The thing with MutableSequence is that it is quite > inefficient. For example, it implements clear() by calling pop() in a loop. > It implements extend() by calling append() in a loop. And we all know that > the built-in extend() method of the list object is much more efficient. It > is true that by overriding the abstract methods, I'll get a functional list > like object, but we all know that > > There should be one-- and preferably only one --obvious way to do it. > > > Which one is that? :-) > The easiest, most beautiful way that is sufficiently fast. Use MutableSequence until you discover that extend is actually the bottleneck in your program. > From michael.selik at gmail.com Fri Jun 10 09:23:35 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 10 Jun 2016 13:23:35 +0000 Subject: UserList - which methods needs to be overriden? In-Reply-To: References: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> Message-ID: On Fri, Jun 10, 2016 at 9:18 AM Michael Selik wrote: > > > On Fri, Jun 10, 2016, 4:05 AM Nagy L?szl? Zsolt > wrote: > >> 2016.06.10. 0:38 keltez?ssel, Michael Selik ?rta: >> >> On Thu, Jun 9, 2016 at 5:07 AM Nagy L?szl? Zsolt >> wrote: >> >>> I would like to create a collections.UserList subclass that can notify >>> others when the list is mutated. >>> >> >> Why not subclass MutableSequence instead? The ABC will tell you which >> methods to override (the abstract ones). The mixin methods rely on those >> overrides. >> >> The thing with MutableSequence is that it is quite inefficient. For >> example, it implements clear() by calling pop() in a loop. It implements >> extend() by calling append() in a loop. And we all know that the built-in >> extend() method of the list object is much more efficient. >> > If you find that extend is indeed a bottleneck, there's an easy fix. class NoisyList(MutableSequence): @noisy('extend') def extend(self, iterable): self.container.extend(iterable) From ian.g.kelly at gmail.com Fri Jun 10 10:00:43 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 10 Jun 2016 08:00:43 -0600 Subject: for / while else doesn't make sense In-Reply-To: <87shwlns34.fsf@elektro.pacujo.net> References: <_lx6z.1194262$z22.146690@fx36.am4> <87shwlns34.fsf@elektro.pacujo.net> Message-ID: On Jun 10, 2016 6:37 AM, "Marko Rauhamaa" wrote: > > alister : > > > Or more simply a hard fixed RULE (MUST be less than X lines) is Bad. > > It's not X lines, it's "you must see the whole function at once." > > If your display can show 1,500 lines at once, that's your limit. Mine > shows 70. I disagree on that point. For a typical-size display, it's a reasonable guideline. But just because your 1500-line function fits in a single screen does not make it readable. In particular, if the function is deeply nested, then it quickly becomes difficult to discern which code aligns with which. A similar principle informs us that 70-100 columns is a reasonable line length limit for readability even if your display can fit much more. From michael.selik at gmail.com Fri Jun 10 10:03:39 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 10 Jun 2016 14:03:39 +0000 Subject: which library has map reduce and how to use it for this case In-Reply-To: References: <1ca428db-ea39-4964-a662-df2701580bd2@googlegroups.com> Message-ID: On Thu, Jun 9, 2016, 9:11 PM Ho Yeung Lee wrote: > input are these six operators, output is finding full column of 27 > elements add together is 54 > > i got memory error when searching this, > > i have difficulty in understanding map reduce and transforming my program > into map reduce problem > Why do you think you need map-reduce? You'll need to explain the problem in more detail. Instead of talking about operators and columns, what is the actual, real-world problem? > From steve at pearwood.info Fri Jun 10 10:07:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 11 Jun 2016 00:07:12 +1000 Subject: how to solve memory References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> Message-ID: <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote: [snip unreadable code] I just ran your code, and it almost crashed my computer. I think it is quite rude to post code without an explanation of what the problem is. I'm afraid that your code is virtually unreadable to me. It is too verbose, the indentation is awful (single space indents is impossible for me to track by eye) and it makes too much work out of simple operations. And none of the variable names mean anything. I've started to simplify and clean the code, and got to the following, which I hope you will agree is easier to read and more compact: import itertools M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, '12': 1, '20': 1, '21': 1, '22': 2} M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, '12': 1, '20': 1, '21': 1, '22': 1} M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, '12': 1, '20': 0, '21': 1, '22': 2} M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, '12': 2, '20': 0, '21': 1, '22': 2} M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, '12': 1, '20': 0, '21': 1, '22': 1} # Why V instead of M? V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, '12': 1, '20': 1, '21': 2, '22': 2} MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6} m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] mylist = [MM[i] for i in range(6)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]] for i in range(len(b))] op1yz = [aa[b[i][1:2]] for i in range(len(b))] op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))] op2xy = [bb[b[i][0:1]] for i in range(len(b))] op2yz = [bb[b[i][1:2]] for i in range(len(b))] op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz]) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.extend([op1xy, op2xy]) initlist.extend([op1xy, op2xy]) if deep == maxx: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) path = DFS(b, deep-1, maxx, sourceoperators, path) return path path = [] mresult = DFS(b, 2, 2, mylist, path) Unfortunate, in cleaning up your code, I have changed something, because my version and your version do not do the same thing. After nearly crashing my computer running your version, I am not going to spend the time trying to debug this. If you want our help, I suggest that you clean up the code. Currently it is an incomprehensible mess to me. Even after the cleanup, I have no idea what this piece of code is supposed to do or what it is calculating. Can you explain the purpose of the code? What is it calculating? Can you show the expected results? What does "DFS" mean? Why do you have M1 - M5 but then a mysterious V6? I can see you are calculating *something* to do with permutations of 0 1 2, but I don't understand what. I think I can see one problem: DFS is a recursive function, but it never ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is zero. So I expect that you will have an infinite loop that just recurses over and over, until you run out of memory or hit the recursion limit. -- Steven From steve at pearwood.info Fri Jun 10 10:27:05 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 11 Jun 2016 00:27:05 +1000 Subject: for / while else doesn't make sense References: <_lx6z.1194262$z22.146690@fx36.am4> <87shwlns34.fsf@elektro.pacujo.net> Message-ID: <575ace3b$0$1610$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Jun 2016 12:00 am, Ian Kelly wrote: > On Jun 10, 2016 6:37 AM, "Marko Rauhamaa" wrote: >> If your display can show 1,500 lines at once, that's your limit. Mine >> shows 70. > > I disagree on that point. For a typical-size display, it's a reasonable > guideline. But just because your 1500-line function fits in a single > screen does not make it readable. I disagree. I have a 2000 inch monitor, and by using a narrow proportional font set to 5pt, I can display the entire Python standard library including tests on screen at once. Then it's just a matter of using my trusty 4" reflecting telescope to zoom in on any part of the screen I like. This is much more convenient than opening a single file at a time, or using a tabbed interface, it is much more efficient to just swivel the telescope and jump to the correct part of the code, and it rarely takes me more than ten or fifteen minutes to find it. And I can read the code in perfect clarity, provided I don't nudge or touch the telescope in any way, or breathe too hard. Apart from "rn" which tends to look like an "m", and its a bit hard to tell the difference between 0 and 0 or 1 I and l, or S and 5, and to be honest periods and commas are completely invisible, but that's a small price to pay for the extra efficiency of having all 641 thousand lines of code on screen all at once. -- Steven From __peter__ at web.de Fri Jun 10 10:41:43 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 10 Jun 2016 16:41:43 +0200 Subject: Almost crashing computer, was Re: how to solve memory References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I just ran your code, and it almost crashed my computer. When you suspect that a script may consume a lot of memory (the subject might have been a hint) ulimit (bash internal) helps you prevent that your linux machine becomes unresponsive. $ ulimit -v 200000 $ python3 tmp2.py > /dev/null Traceback (most recent call last): File "tmp2.py", line 134, in mresult = DFS(b, 2, 2, mylist, path) File "tmp2.py", line 125, in DFS path = DFS(b, deep-1, maxx, sourceoperators, path) File "tmp2.py", line 129, in DFS b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) File "tmp2.py", line 129, in b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) MemoryError From gordon at panix.com Fri Jun 10 10:46:30 2016 From: gordon at panix.com (John Gordon) Date: Fri, 10 Jun 2016 14:46:30 +0000 (UTC) Subject: how to solve memory References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> Message-ID: In <4f853aa2-cc00-480b-9fd7-79b05cbd4889 at googlegroups.com> meInvent bbird writes: > https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing I already responded to your earlier post about this program. Did you read it? -- 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 jobmattcon at gmail.com Fri Jun 10 11:00:44 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 08:00:44 -0700 (PDT) Subject: how to solve memory In-Reply-To: <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7cc811f2-b90d-401d-beae-041b1fdff1af@googlegroups.com> i put final part of code inside one more space and add constraint deep > 0 but still memory error and print the deep number to see, it do not run infinity again V6 is just my superstitution, because V is disable 6 is separation i run your version directly, it has key = '0' error M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=1 M1['02']=2 M1['10']=1 M1['11']=1 M1['12']=2 M1['20']=2 M1['21']=2 M1['22']=2 M2['00']=0 M2['01']=0 M2['02']=2 M2['10']=0 M2['11']=1 M2['12']=2 M2['20']=2 M2['21']=2 M2['22']=2 M3['00']=0 M3['01']=0 M3['02']=0 M3['10']=0 M3['11']=1 M3['12']=2 M3['20']=0 M3['21']=2 M3['22']=2 M4['00']=0 M4['01']=1 M4['02']=0 M4['10']=1 M4['11']=1 M4['12']=1 M4['20']=0 M4['21']=1 M4['22']=2 M5['00']=0 M5['01']=0 M5['02']=0 M5['10']=0 M5['11']=1 M5['12']=2 M5['20']=0 M5['21']=2 M5['22']=2 V6['00']=2 V6['01']=2 V6['02']=2 V6['10']=1 V6['11']=2 V6['12']=2 V6['20']=0 V6['21']=1 V6['22']=2 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path = DFS(b, deep-1, maxx, sourceoperators, path) else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path = DFS(b, deep-1, maxx, sourceoperators, path) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote: > On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote: > > [snip unreadable code] > > I just ran your code, and it almost crashed my computer. I think it is quite > rude to post code without an explanation of what the problem is. > > > I'm afraid that your code is virtually unreadable to me. It is too verbose, > the indentation is awful (single space indents is impossible for me to > track by eye) and it makes too much work out of simple operations. And none > of the variable names mean anything. > > I've started to simplify and clean the code, and got to the following, which > I hope you will agree is easier to read and more compact: > > > > import itertools > M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 2} > M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 1} > M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 2} > M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, > '12': 2, '20': 0, '21': 1, '22': 2} > M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 1} > # Why V instead of M? > V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, > '12': 1, '20': 1, '21': 2, '22': 2} > > MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6} > m = 3 > b = [str(i)+str(j)+str(k) for i in range(m) > for j in range(m) for k in range(m)] > mylist = [MM[i] for i in range(6)] > > def DFS(b, deep, maxx, sourceoperators, path): > initlist = [] > if deep > 0: > print("deep=", deep) > for aa,bb in itertools.combinations(sourceoperators, 2): > print(aa,bb) > if deep == maxx: > finalresult = [] > op1xy = [aa[b[i][0:1]] for i in range(len(b))] > op1yz = [aa[b[i][1:2]] for i in range(len(b))] > op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))] > op2xy = [bb[b[i][0:1]] for i in range(len(b))] > op2yz = [bb[b[i][1:2]] for i in range(len(b))] > op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op1yz) == 54: > path.append([(deep, aa, "yz")]) > if sum(op1xz) == 54: > path.append([(deep, aa, "xz")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > if sum(op2yz) == 54: > path.append([(deep, bb, "yz")]) > if sum(op2xz) == 54: > path.append([(deep, bb, "xz")]) > initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz]) > else: > level = [] > for j in range(len(b)): > op1xy = [aa[b[j][i]] for i in range(len(b[j]))] > op2xy = [bb[b[j][i]] for i in range(len(b[j]))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > level.extend([op1xy, op2xy]) > initlist.extend([op1xy, op2xy]) > if deep == maxx: > b = [] > for aaa,bbb in itertools.combinations(initlist, 2): > b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) > path = DFS(b, deep-1, maxx, sourceoperators, path) > return path > > path = [] > mresult = DFS(b, 2, 2, mylist, path) > > > > Unfortunate, in cleaning up your code, I have changed something, because my > version and your version do not do the same thing. > > After nearly crashing my computer running your version, I am not going to > spend the time trying to debug this. If you want our help, I suggest that > you clean up the code. Currently it is an incomprehensible mess to me. Even > after the cleanup, I have no idea what this piece of code is supposed to do > or what it is calculating. > > Can you explain the purpose of the code? What is it calculating? Can you > show the expected results? What does "DFS" mean? Why do you have M1 - M5 > but then a mysterious V6? > > I can see you are calculating *something* to do with permutations of 0 1 2, > but I don't understand what. > > I think I can see one problem: DFS is a recursive function, but it never > ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is > zero. So I expect that you will have an infinite loop that just recurses > over and over, until you run out of memory or hit the recursion limit. > > > > -- > Steven From jobmattcon at gmail.com Fri Jun 10 11:03:50 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 08:03:50 -0700 (PDT) Subject: run code error with numpy and scipy In-Reply-To: References: <62df152e-8fc6-47c5-aa44-f2da4094c140@googlegroups.com> Message-ID: <8bfd6ba6-b3c8-427a-bc22-734e49a24318@googlegroups.com> On Thursday, June 9, 2016 at 9:52:43 PM UTC+8, MRAB wrote: > On 2016-06-09 07:02, meInvent bbird wrote: > > when i run code in window has an error not a valid win32 dll > > > > then i install scipy first in this site, then install numpy-mkl > > all python 2.7 and win32 > > > > http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > > > then i run code below, got error , and captured screen in this link > > > > https://drive.google.com/file/d/0Bxs_ao6uuBDUQXROd2VqSURGa00/view?usp=sharing > > > [snip] > You're entering it at the interactive Python prompt. > > When it sees the blank line, it thinks you've finished entering the > function, so it complains when the next line is indented. (Things are > slightly different when working interactively than when running from a > file.) > > You should put the code into a file and then run that. thank you i will try it. From jobmattcon at gmail.com Fri Jun 10 11:08:57 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 08:08:57 -0700 (PDT) Subject: how to solve memory In-Reply-To: References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> Message-ID: <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> On Friday, June 10, 2016 at 10:46:43 PM UTC+8, John Gordon wrote: > In <4f853aa2-cc00-480b-9fd7-79b05cbd4889 at googlegroups.com> meInvent bbird writes: > > > https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing > > I already responded to your earlier post about this program. Did you > read it? > > -- > 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" sorry i missed your reply post, i find post by me and search your name, no this name is your name changed in previous post? could you post the link here? is it an email or google group post? From jobmattcon at gmail.com Fri Jun 10 11:23:57 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 08:23:57 -0700 (PDT) Subject: how to solve memory In-Reply-To: <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote: > On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote: > > [snip unreadable code] > > I just ran your code, and it almost crashed my computer. I think it is quite > rude to post code without an explanation of what the problem is. > > > I'm afraid that your code is virtually unreadable to me. It is too verbose, > the indentation is awful (single space indents is impossible for me to > track by eye) and it makes too much work out of simple operations. And none > of the variable names mean anything. > > I've started to simplify and clean the code, and got to the following, which > I hope you will agree is easier to read and more compact: > > > > import itertools > M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 2} > M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 1} > M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 2} > M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, > '12': 2, '20': 0, '21': 1, '22': 2} > M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 1} > # Why V instead of M? > V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, > '12': 1, '20': 1, '21': 2, '22': 2} > > MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6} > m = 3 > b = [str(i)+str(j)+str(k) for i in range(m) > for j in range(m) for k in range(m)] > mylist = [MM[i] for i in range(6)] > > def DFS(b, deep, maxx, sourceoperators, path): > initlist = [] > if deep > 0: > print("deep=", deep) > for aa,bb in itertools.combinations(sourceoperators, 2): > print(aa,bb) > if deep == maxx: > finalresult = [] > op1xy = [aa[b[i][0:1]] for i in range(len(b))] > op1yz = [aa[b[i][1:2]] for i in range(len(b))] > op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))] > op2xy = [bb[b[i][0:1]] for i in range(len(b))] > op2yz = [bb[b[i][1:2]] for i in range(len(b))] > op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op1yz) == 54: > path.append([(deep, aa, "yz")]) > if sum(op1xz) == 54: > path.append([(deep, aa, "xz")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > if sum(op2yz) == 54: > path.append([(deep, bb, "yz")]) > if sum(op2xz) == 54: > path.append([(deep, bb, "xz")]) > initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz]) > else: > level = [] > for j in range(len(b)): > op1xy = [aa[b[j][i]] for i in range(len(b[j]))] > op2xy = [bb[b[j][i]] for i in range(len(b[j]))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > level.extend([op1xy, op2xy]) > initlist.extend([op1xy, op2xy]) > if deep == maxx: > b = [] > for aaa,bbb in itertools.combinations(initlist, 2): > b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) > path = DFS(b, deep-1, maxx, sourceoperators, path) > return path > > path = [] > mresult = DFS(b, 2, 2, mylist, path) > > > > Unfortunate, in cleaning up your code, I have changed something, because my > version and your version do not do the same thing. > > After nearly crashing my computer running your version, I am not going to > spend the time trying to debug this. If you want our help, I suggest that > you clean up the code. Currently it is an incomprehensible mess to me. Even > after the cleanup, I have no idea what this piece of code is supposed to do > or what it is calculating. > > Can you explain the purpose of the code? What is it calculating? Can you > show the expected results? What does "DFS" mean? Why do you have M1 - M5 > but then a mysterious V6? > > I can see you are calculating *something* to do with permutations of 0 1 2, > but I don't understand what. > > I think I can see one problem: DFS is a recursive function, but it never > ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is > zero. So I expect that you will have an infinite loop that just recurses > over and over, until you run out of memory or hit the recursion limit. > > > > -- > Steven i recorded a video to show what i am searching for https://drive.google.com/file/d/0Bxs_ao6uuBDUbjFxbjJReXZoNHc/view?usp=sharing something i hide because i invented some math, hope your mercy. From marko at pacujo.net Fri Jun 10 12:13:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 10 Jun 2016 19:13:09 +0300 Subject: for / while else doesn't make sense References: <_lx6z.1194262$z22.146690@fx36.am4> <87shwlns34.fsf@elektro.pacujo.net> Message-ID: <87mvmtnht6.fsf@elektro.pacujo.net> Ian Kelly : > On Jun 10, 2016 6:37 AM, "Marko Rauhamaa" wrote: >> If your display can show 1,500 lines at once, that's your limit. Mine >> shows 70. > > I disagree on that point. For a typical-size display, it's a > reasonable guideline. The point I'm making is that if I'm accusing you for writing functions that are too long (they don't fit on my editor window), you can counter that they fit perfectly well on yours. No-one has 1,500-line editor windows, I suppose. However, screen sizes have been going up and some people prefer to turn their screens into portrait mode (tried it, made my neck hurt). Years back, I had 24 lines on the screen. As screen sizes have gone up, I've allowed for longer functions as well. Now I'm at 70. Of course, most functions tend to be much shorter. Marko From gordon at panix.com Fri Jun 10 12:26:40 2016 From: gordon at panix.com (John Gordon) Date: Fri, 10 Jun 2016 16:26:40 +0000 (UTC) Subject: how to solve memory References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> Message-ID: In <8a1c372e-bd6c-4923-8ae1-8f129ec749e4 at googlegroups.com> meInvent bbird writes: > > I already responded to your earlier post about this program. Did you > > read it? > sorry i missed your reply post, > i find post by me and search your name, no this name > is your name changed in previous post? My comment was that the recursive calls weren't indented in the "if deep > 0" block, therefore DFS was being called infinitely with smaller and smaller values of deep. But it appears you have fixed that 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 mauricioliveiraguarda at gmail.com Fri Jun 10 17:07:41 2016 From: mauricioliveiraguarda at gmail.com (maurice) Date: Fri, 10 Jun 2016 14:07:41 -0700 (PDT) Subject: fast dictionary initialization Message-ID: Hi. If I have already a list of values, let's call it valuesList and the keysList, both same sized lists, what is the easiest/quickest way to initialize a dictionary with those keys and list, in terms of number of lines perhaps? example: valuesList = [1,2,3] keysList = ['1','2','3'] So the dictionary can basically convert string to int: dictionary = {'1':1, '2':2, '3':3} Thanks From random832 at fastmail.com Fri Jun 10 17:15:46 2016 From: random832 at fastmail.com (Random832) Date: Fri, 10 Jun 2016 17:15:46 -0400 Subject: fast dictionary initialization In-Reply-To: References: Message-ID: <1465593346.2349149.634242025.11CE5139@webmail.messagingengine.com> pOn Fri, Jun 10, 2016, at 17:07, maurice wrote: > Hi. If I have already a list of values, let's call it valuesList and the > keysList, both same sized lists, what is the easiest/quickest way to > initialize a dictionary with those keys and list, in terms of number of > lines perhaps? > > example: > valuesList = [1,2,3] > keysList = ['1','2','3'] > > So the dictionary can basically convert string to int: > > dictionary = {'1':1, '2':2, '3':3} dict(zip(keysList, valuesList)) From wrightalexw at gmail.com Fri Jun 10 17:31:56 2016 From: wrightalexw at gmail.com (alex wright) Date: Fri, 10 Jun 2016 17:31:56 -0400 Subject: movie from pictures In-Reply-To: References: <7e57c662-a6c2-441d-a46e-49458439250f@googlegroups.com> <16301530-a24b-42c6-bcf6-007c4eb85aca@googlegroups.com> Message-ID: I find shlex.split to be most useful to make my arguments a list in these cases. On Jun 9, 2016 3:28 PM, "MRAB" wrote: > On 2016-06-09 19:58, Peter Otten wrote: > >> Nev wrote: >> >> Thank you for your reply. I tried something like this in python code: >>> >>> from subprocess import call >>> call(["ffmpeg -framerate 4/1 -start_number 1 -i >>> C:\\Projects\\data2\\img_%05d.png -c:v libx264 -r 30 -pix_fmt yuv420p >>> C:\\Projects\\data2\\movie.mp4"]) >>> >>> But it did not work. I get FileNotFoundError: [WinError 2] The system >>> cannot find the file specified.. >>> >> >> You have to pass the command-line arguments as separate items in the list: >> >> call(["ffmpeg", >> "-framerate", "4/1", >> "-start_number", "1", >> "-i", "C:\\Projects\\data2\\img_%05d.png", >> ... # and so on >> ]) >> >> You should also give it the full path of ffmpeg. > > On the other hand, in-loop solution would be more preferable since it lets >>> me to use variable names of the images and paths.. >>> >> > -- > https://mail.python.org/mailman/listinfo/python-list > From mad.scientist.jr at gmail.com Fri Jun 10 18:52:39 2016 From: mad.scientist.jr at gmail.com (mad scientist jr) Date: Fri, 10 Jun 2016 15:52:39 -0700 (PDT) Subject: i'm a python newbie & wrote my first script, can someone critique it? Message-ID: Is this group appropriate for that kind of thing? (If not sorry for posting this here.) So I wanted to start learning Python, and there is soooo much information online, which is a little overwhelming. I really learn best from doing, especially if it's something actually useful. I needed to create a bunch of empty folders, so I figured it was a good exercise to start learning Python. Now that it's done, I am wondering what kind of things I could do better. Here is the code: # WELCOME TO MY FIRST PYTHON SCRIPT! # FIRST OF ALL, IT ***WORKS***!!! YAY! # I AM A VBA AND JAVASCRIPT PROGRAMMER, # SO IT IS PROBABLY NOT VERY "PYTHONIC", # SO PLEASE FEEL FREE TO TEAR THE SCRIPT A NEW ONE # AFTER YOU ARE SHOCKED BY THIS BAD CODE, # ALL I ASK IS THAT IF YOU THINK SOMETHING IS BAD, # PLEASE POST AN EXAMPLE OF THE "CORRECT" WAY OF DOING IT # COMING FROM VBA, I KNOW A LITTLE OOP, # BUT NOT C++ C# JAVA STUFF LIKE "INTERFACES" AND "ABSTRACT BASE CLASSES" # SO IF YOU GET INTO SUCH TERMINOLOGY MY EYES MIGHT START TO GLAZE OVER # UNLESS YOU CARE TO EXPLAIN THAT TOO ############################################################################################################################################################ # GLOBAL VALUES sForPythonVersion="3" #sFolderPathTemplate = "c:\\myscripts\\MP3 Disc " sFolderPathTemplate = "c:\\temp\\MP3 Disc " iFromCount = 1 iToCount = 250 iCountWidth = 3 ################################################################################################################################################################ # SUPPORT FUNCTIONS # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN ENGLISH!) #PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or isinstance(myVar, unicode) ) #PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr) return isinstance(myVar, str) # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// # THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY STEPS" def strip_one_space(s): if s.endswith(" "): s = s[:-1] if s.startswith(" "): s = s[1:] return s # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// def get_exact_python_version(): import sys sVersion = ".".join(map(str, sys.version_info[:3])) sVersion = sVersion.strip() return sVersion # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// # TO DO: RETURN TO THE LEFT OF FIRST "." def get_python_version(): sVersion = get_exact_python_version() return sVersion[0:1] # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// # CHECK PYTHON VERSION, IF IT'S WRONG THEN GRACEFULLY EXIT BEFORE IT BLOWS UP # (DAMN, PYTHON 2.x STILL COMPLAINS WITH SYNTAX ERRORS!!) # MAYBE THIS COULD STILL BE USEFUL FOR CHECKING THE SUB-VERSION, IN THAT CASE # TO DO: MORE GRANULAR CHECK, EG IF VERSION >= 3.5.0 def exit_if_wrong_python_version(sRightVersion): import os sCurrentVersion = get_python_version() if (sCurrentVersion != sRightVersion): print("" + "Wrong Python version (" + sCurrentVersion + "), this script should be run using Python " + sRightVersion + ".x. Exiting..." ) os._exit(0) # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// def get_script_filename(): import os return os.path.basename(__file__) # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// def get_timestamp(): import datetime return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// def create_folder(sPath): import os import errno #if not os.path.exists(directory): # os.makedirs(directory) try: os.makedirs(sPath, exist_ok=True) except OSError as exception: #if exception.errno != errno.EEXIST: print("ERROR #" + str(exception.errno) + "IN makedirs") raise # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// def create_folders(sFolderPathTemplate:str="", iFromCount:int=1, iToCount:int=0, iCountWidth:int=0): # MAKE SURE TEMPLATE'S A STRING. OH, IS THIS NOT "PYTHONIC"? WELL IT'S MORE READABLE if is_string(sFolderPathTemplate) == False: iFromCount = 1; iToCount = 0; sName = "" sCount = "" iLoop = iFromCount while (iLoop <= iToCount) and (len(sFolderPathTemplate) > 0): sCount = "{0}".format(iLoop) if (iCountWidth > 0): sCount = sCount.zfill(iCountWidth) sName = sFolderPathTemplate.replace("", sCount) create_folder(sName) iLoop = iLoop + 1 ############################################################################################################################################################ # MAIN LOGIC def main(): # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- # MAKE SURE PYTHON VERSION IS CORRECT exit_if_wrong_python_version(sForPythonVersion) print("PYTHON VERSION (" + get_exact_python_version() + ") MATCHES REQUIRED VERSION (" + sForPythonVersion + ")") #print("get_python_version returns \"" + get_python_version() + "\"") #print("get_exact_python_version returns \"" + get_exact_python_version() + "\"") # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- # PRINT START TIMESTAMP print("" + get_timestamp() + " " + get_script_filename() + " STARTED.") # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- # DO WHAT WE CAME TO DO # IT'S PROBABLY BAD FORM TO REFERENCE GLOBAL VARIABLES INSIDE THE SCOPE OF A FUNCTION? # BUT I WANT TO MAKE IT EASY TO CONFIGURE THE SCRIPT JUST BY CHANGING A COUPLE OF LINES # AT THE TOP, WITHOUT HAVING TO SEARCH THROUGH THE CODE create_folders( sFolderPathTemplate, iFromCount, iToCount, iCountWidth) # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- # NOW FINISH print("" + get_timestamp() + " " + get_script_filename() + " FINISHED.") #import os #os._exit(0) ############################################################################################################################################################ main() From christopher_reimer at icloud.com Fri Jun 10 19:05:28 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 10 Jun 2016 16:05:28 -0700 Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: References: Message-ID: Sent from my iPhone > On Jun 10, 2016, at 3:52 PM, mad scientist jr wrote: > . > Now that it's done, I am wondering what kind of things I could do better. This is Python, not BASIC. Lay off on the CAP LOCK key and delete all the comments and separation blocks. No one is going to find your code in all that noise. Chris R. From python.list at tim.thechases.com Fri Jun 10 19:20:14 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 10 Jun 2016 18:20:14 -0500 Subject: fast dictionary initialization In-Reply-To: References: Message-ID: <20160610182014.0a9182a9@bigbox.christie.dr> On 2016-06-10 14:07, maurice wrote: > example: > valuesList = [1,2,3] > keysList = ['1','2','3'] > > So the dictionary can basically convert string to int: > > dictionary = {'1':1, '2':2, '3':3} A couple similar options: The most straightforward translation of your description: opt1 = dict(zip(keysList, valuesList)) print(opt1["2"]) And one where you generate the strings on the fly: opt2 = dict((str(i), i) for i in range(1, 4)) print(opt2["2"]) And one where you use the int() function instead of a mapping because the whole idea of storing a dict worth of string-numbers-to-numbers seems somewhat silly to me: print(int("2")) -tkc From jobmattcon at gmail.com Fri Jun 10 19:23:47 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 16:23:47 -0700 (PDT) Subject: how to solve memory In-Reply-To: <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <28a63efe-9096-4914-8cce-2dc1861d3776@googlegroups.com> i put final part of code inside one more space and add constraint deep > 0 but still memory error and print the deep number to see, it do not run infinity again V6 is just my superstitution, because V is disable 6 is separation i run your version directly, it has key = '0' error M1 = {} M2 = {} M3 = {} M4 = {} M5 = {} V6 = {} M1['00']=0 M1['01']=1 M1['02']=1 M1['10']=2 M1['11']=2 M1['12']=1 M1['20']=1 M1['21']=1 M1['22']=1 M2['00']=0 M2['01']=1 M2['02']=1 M2['10']=1 M2['11']=2 M2['12']=2 M2['20']=1 M2['21']=1 M2['22']=1 M3['00']=0 M3['01']=1 M3['02']=1 M3['10']=0 M3['11']=1 M3['12']=2 M3['20']=0 M3['21']=2 M3['22']=2 M4['00']=0 M4['01']=1 M4['02']=0 M4['10']=1 M4['11']=2 M4['12']=2 M4['20']=0 M4['21']=1 M4['22']=1 M5['00']=0 M5['01']=1 M5['02']=1 M5['10']=2 M5['11']=1 M5['12']=2 M5['20']=0 M5['21']=2 M5['22']=1 V6['00']=1 V6['01']=1 V6['02']=2 V6['10']=1 V6['11']=1 V6['12']=1 V6['20']=2 V6['21']=2 V6['22']=2 MM = {} MM[0] = M1 MM[1] = M2 MM[2] = M3 MM[3] = M4 MM[4] = M5 MM[5] = V6 m = 3 b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] import itertools deep = 3 final = [] mylist = [MM[i] for i in range(0,7-1)] b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)] def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) initlist.append(op1xy) initlist.append(op1yz) initlist.append(op1xz) initlist.append(op2xy) initlist.append(op2yz) initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) level.append(op1xy) level.append(op2xy) initlist.append(op1xy) initlist.append(op2xy) if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote: > On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote: > > [snip unreadable code] > > I just ran your code, and it almost crashed my computer. I think it is quite > rude to post code without an explanation of what the problem is. > > > I'm afraid that your code is virtually unreadable to me. It is too verbose, > the indentation is awful (single space indents is impossible for me to > track by eye) and it makes too much work out of simple operations. And none > of the variable names mean anything. > > I've started to simplify and clean the code, and got to the following, which > I hope you will agree is easier to read and more compact: > > > > import itertools > M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 2} > M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, > '12': 1, '20': 1, '21': 1, '22': 1} > M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 2} > M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, > '12': 2, '20': 0, '21': 1, '22': 2} > M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, > '12': 1, '20': 0, '21': 1, '22': 1} > # Why V instead of M? > V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, > '12': 1, '20': 1, '21': 2, '22': 2} > > MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6} > m = 3 > b = [str(i)+str(j)+str(k) for i in range(m) > for j in range(m) for k in range(m)] > mylist = [MM[i] for i in range(6)] > > def DFS(b, deep, maxx, sourceoperators, path): > initlist = [] > if deep > 0: > print("deep=", deep) > for aa,bb in itertools.combinations(sourceoperators, 2): > print(aa,bb) > if deep == maxx: > finalresult = [] > op1xy = [aa[b[i][0:1]] for i in range(len(b))] > op1yz = [aa[b[i][1:2]] for i in range(len(b))] > op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))] > op2xy = [bb[b[i][0:1]] for i in range(len(b))] > op2yz = [bb[b[i][1:2]] for i in range(len(b))] > op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op1yz) == 54: > path.append([(deep, aa, "yz")]) > if sum(op1xz) == 54: > path.append([(deep, aa, "xz")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > if sum(op2yz) == 54: > path.append([(deep, bb, "yz")]) > if sum(op2xz) == 54: > path.append([(deep, bb, "xz")]) > initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz]) > else: > level = [] > for j in range(len(b)): > op1xy = [aa[b[j][i]] for i in range(len(b[j]))] > op2xy = [bb[b[j][i]] for i in range(len(b[j]))] > if sum(op1xy) == 54: > path.append([(deep, aa, "xy")]) > if sum(op2xy) == 54: > path.append([(deep, bb, "xy")]) > level.extend([op1xy, op2xy]) > initlist.extend([op1xy, op2xy]) > if deep == maxx: > b = [] > for aaa,bbb in itertools.combinations(initlist, 2): > b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) > path = DFS(b, deep-1, maxx, sourceoperators, path) > return path > > path = [] > mresult = DFS(b, 2, 2, mylist, path) > > > > Unfortunate, in cleaning up your code, I have changed something, because my > version and your version do not do the same thing. > > After nearly crashing my computer running your version, I am not going to > spend the time trying to debug this. If you want our help, I suggest that > you clean up the code. Currently it is an incomprehensible mess to me. Even > after the cleanup, I have no idea what this piece of code is supposed to do > or what it is calculating. > > Can you explain the purpose of the code? What is it calculating? Can you > show the expected results? What does "DFS" mean? Why do you have M1 - M5 > but then a mysterious V6? > > I can see you are calculating *something* to do with permutations of 0 1 2, > but I don't understand what. > > I think I can see one problem: DFS is a recursive function, but it never > ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is > zero. So I expect that you will have an infinite loop that just recurses > over and over, until you run out of memory or hit the recursion limit. > > > > -- > Steven From jobmattcon at gmail.com Fri Jun 10 19:31:06 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 16:31:06 -0700 (PDT) Subject: how to solve memory In-Reply-To: References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> Message-ID: it is quite ridiculous, this time i am sure that i put correct indentation and add a else statement to make sure recursive call inside the if statement , it still memory error, where is the memory error? is itertools.combinations so big for the list? if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print "" else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print "" return path On Saturday, June 11, 2016 at 12:26:55 AM UTC+8, John Gordon wrote: > In <8a1c372e-bd6c-4923-8ae1-8f129ec749e4 at googlegroups.com> meInvent bbird writes: > > > > I already responded to your earlier post about this program. Did you > > > read it? > > > sorry i missed your reply post, > > i find post by me and search your name, no this name > > is your name changed in previous post? > > My comment was that the recursive calls weren't indented in the > "if deep > 0" block, therefore DFS was being called infinitely with smaller > and smaller values of deep. But it appears you have fixed that 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 python at mrabarnett.plus.com Fri Jun 10 20:33:54 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Jun 2016 01:33:54 +0100 Subject: how to solve memory In-Reply-To: References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> Message-ID: On 2016-06-11 00:31, meInvent bbird wrote: > it is quite ridiculous, > this time i am sure that i put correct indentation > and add a else statement to make sure recursive call inside the > if statement , it still memory error, > > where is the memory error? > > is itertools.combinations so big for the list? > [snip] How long is initlist? When I ran the code, it said over 100_000 items. How many combinations would there be? Over 10_000_000_000. That's how long the list 'b' would be. You'll need 10s of gigabytes of memory and a lot of patience! From marcwbrooks at gmail.com Fri Jun 10 20:51:01 2016 From: marcwbrooks at gmail.com (Marc Brooks) Date: Fri, 10 Jun 2016 20:51:01 -0400 Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: References: Message-ID: The structure of your program is really not that Pythonic. I'd recommend you take a look at PEP 8. https://www.python.org/dev/peps/pep-0008/ It's not perfect, but it's a good start to get a feel for how to structure your Python work. Marc On Fri, Jun 10, 2016 at 7:05 PM, Christopher Reimer < christopher_reimer at icloud.com> wrote: > > > Sent from my iPhone > > > On Jun 10, 2016, at 3:52 PM, mad scientist jr < > mad.scientist.jr at gmail.com> wrote: > > . > > Now that it's done, I am wondering what kind of things I could do better. > > This is Python, not BASIC. Lay off on the CAP LOCK key and delete all the > comments and separation blocks. No one is going to find your code in all > that noise. > > Chris R. > -- > https://mail.python.org/mailman/listinfo/python-list > From rocky at gnu.org Fri Jun 10 20:56:12 2016 From: rocky at gnu.org (rocky) Date: Fri, 10 Jun 2016 17:56:12 -0700 (PDT) Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy In-Reply-To: References: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> <73515c1e-5d48-45b1-a43d-6297de0faa34@chamonix.reportlab.co.uk> Message-ID: On Friday, June 10, 2016 at 4:33:28 AM UTC-4, Robin Becker wrote: > On 08/06/2016 19:32, rocky wrote: > .......... > > > > Sorry that should have been 1998 which would make more sense for the 7th conference if the 1st one was around 2001. I've corrected the date in [1] https://pypi.python.org/pypi/spark_parser/1.3.0 > > > > The automated tests in the package just don't catch stuff like this. But I'm sure there are also other mistakes as well in there so feel free to let me know. > > > not a big deal; I like the spark parser :) > -- > Robin Becker It is cool for how small in code size, how general, (more general than LL or LR), and how fast it works for well-crafted grammars. Surprisingly little was needed to make it work on Python 3 (as well as addition on Python 2). It has however long been neglected. John stopped working on it around 2002 or so without having put it on Pypy. Since it wasn't it's own package, so you had to find some other project (with possibly varying versions of the program) and copy the spark.py file from that or download the "0.7 pre-alpha" version of 2002 from John's website and possibly modify it if you have Python 3. Ok. So I've got that addressed by putting it in pypy. But the other basic area of neglect as documentation. John's paper I find woefully inadequate. Most of the projects on John's site that say they use SPARK are now dead links. And using the various uncompyle/decompyle programs as a tutorial for the parser is a bit whacky too as these are very complicated, and not intended as a tutorial. I've only started to address this by putting together some simple examples. And on http://github.com/rocky/python-spark there is now a wiki to try to address some of this as well. In the wiki for http://github.com/rocky/python-uncompyle6 I've extracted the documentation for the table-driven formatting, but more is needed here as well. So if you or other like this and know to to use it, please consider beefing up the wiki. Thanks. From rocky at gnu.org Fri Jun 10 21:00:22 2016 From: rocky at gnu.org (rocky) Date: Fri, 10 Jun 2016 18:00:22 -0700 (PDT) Subject: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy In-Reply-To: References: <00f242f0-8673-42ca-965b-1a07d323252f@googlegroups.com> Message-ID: On Thursday, June 9, 2016 at 1:36:56 AM UTC-4, Lawrence D?Oliveiro wrote: > On Wednesday, June 8, 2016 at 10:39:00 PM UTC+12, rocky wrote: > > > In addition to the example programs which give the classic arithmetic > > expression evaluator, I now include the beginnings of a full Python 2.6 > > language. > > Does anybody bother with LR(k) parsers any more? I don't understand. Python itself I think does. And By the way, SPARK is an Early-Algorithm parser [1], so it is a little more general than LL or LR parsers. [1] https://en.wikipedia.org/wiki/Earley_parser From joel.goldstick at gmail.com Fri Jun 10 21:02:31 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 10 Jun 2016 21:02:31 -0400 Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: References: Message-ID: On Fri, Jun 10, 2016 at 6:52 PM, mad scientist jr wrote: > Is this group appropriate for that kind of thing? > (If not sorry for posting this here.) > > So I wanted to start learning Python, and there is soooo much information online, which is a little overwhelming. I really learn best from doing, especially if it's something actually useful. I needed to create a bunch of empty folders, so I figured it was a good exercise to start learning Python. > Now that it's done, I am wondering what kind of things I could do better. > Here is the code: > > # WELCOME TO MY FIRST PYTHON SCRIPT! > # FIRST OF ALL, IT ***WORKS***!!! YAY! > # I AM A VBA AND JAVASCRIPT PROGRAMMER, > # SO IT IS PROBABLY NOT VERY "PYTHONIC", > # SO PLEASE FEEL FREE TO TEAR THE SCRIPT A NEW ONE > # AFTER YOU ARE SHOCKED BY THIS BAD CODE, > # ALL I ASK IS THAT IF YOU THINK SOMETHING IS BAD, > # PLEASE POST AN EXAMPLE OF THE "CORRECT" WAY OF DOING IT > # COMING FROM VBA, I KNOW A LITTLE OOP, > # BUT NOT C++ C# JAVA STUFF LIKE "INTERFACES" AND "ABSTRACT BASE CLASSES" > # SO IF YOU GET INTO SUCH TERMINOLOGY MY EYES MIGHT START TO GLAZE OVER > # UNLESS YOU CARE TO EXPLAIN THAT TOO > > Ditch the uppercase comments. ############################################################################################################################################################ > # GLOBAL VALUES > sForPythonVersion="3" > #sFolderPathTemplate = "c:\\myscripts\\MP3 Disc " > sFolderPathTemplate = "c:\\temp\\MP3 Disc " > iFromCount = 1 > iToCount = 250 > iCountWidth = 3 > Python has guidelines for naming things. Don't use camel case. Use lower case and put underscores between words. Globals are a bad idea. If you don't know why, they are even a worse idea > ################################################################################################################################################################ > # SUPPORT FUNCTIONS > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN ENGLISH!) > #PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or isinstance(myVar, unicode) ) > #PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr) > return isinstance(myVar, str) I'm not sure why you want to test for type. > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY STEPS" > def strip_one_space(s): > if s.endswith(" "): s = s[:-1] > if s.startswith(" "): s = s[1:] > return s This may be from some book, but it could be done: s.strip() > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_exact_python_version(): > import sys > sVersion = ".".join(map(str, sys.version_info[:3])) > sVersion = sVersion.strip() > return sVersion > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # TO DO: RETURN TO THE LEFT OF FIRST "." > def get_python_version(): > sVersion = get_exact_python_version() > return sVersion[0:1] > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # CHECK PYTHON VERSION, IF IT'S WRONG THEN GRACEFULLY EXIT BEFORE IT BLOWS UP > # (DAMN, PYTHON 2.x STILL COMPLAINS WITH SYNTAX ERRORS!!) > # MAYBE THIS COULD STILL BE USEFUL FOR CHECKING THE SUB-VERSION, IN THAT CASE > # TO DO: MORE GRANULAR CHECK, EG IF VERSION >= 3.5.0 > def exit_if_wrong_python_version(sRightVersion): > import os > sCurrentVersion = get_python_version() > if (sCurrentVersion != sRightVersion): > print("" + > "Wrong Python version (" + > sCurrentVersion + > "), this script should be run using Python " + > sRightVersion + > ".x. Exiting..." > ) > os._exit(0) > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_script_filename(): > import os > return os.path.basename(__file__) > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_timestamp(): > import datetime > return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > def create_folder(sPath): > import os > import errno > #if not os.path.exists(directory): > # os.makedirs(directory) > try: > os.makedirs(sPath, exist_ok=True) > except OSError as exception: > #if exception.errno != errno.EEXIST: > print("ERROR #" + str(exception.errno) + "IN makedirs") > raise > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > def create_folders(sFolderPathTemplate:str="", iFromCount:int=1, iToCount:int=0, iCountWidth:int=0): > # MAKE SURE TEMPLATE'S A STRING. OH, IS THIS NOT "PYTHONIC"? WELL IT'S MORE READABLE > if is_string(sFolderPathTemplate) == False: > iFromCount = 1; iToCount = 0; > > sName = "" > sCount = "" > iLoop = iFromCount > while (iLoop <= iToCount) and (len(sFolderPathTemplate) > 0): > sCount = "{0}".format(iLoop) > if (iCountWidth > 0): > sCount = sCount.zfill(iCountWidth) > sName = sFolderPathTemplate.replace("", sCount) > create_folder(sName) > iLoop = iLoop + 1 > > ############################################################################################################################################################ > # MAIN LOGIC > > def main(): > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # MAKE SURE PYTHON VERSION IS CORRECT > exit_if_wrong_python_version(sForPythonVersion) > print("PYTHON VERSION (" + get_exact_python_version() + ") MATCHES REQUIRED VERSION (" + sForPythonVersion + ")") > #print("get_python_version returns \"" + get_python_version() + "\"") > #print("get_exact_python_version returns \"" + get_exact_python_version() + "\"") > > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # PRINT START TIMESTAMP > print("" + get_timestamp() + " " + get_script_filename() + " STARTED.") > > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # DO WHAT WE CAME TO DO > # IT'S PROBABLY BAD FORM TO REFERENCE GLOBAL VARIABLES INSIDE THE SCOPE OF A FUNCTION? > # BUT I WANT TO MAKE IT EASY TO CONFIGURE THE SCRIPT JUST BY CHANGING A COUPLE OF LINES > # AT THE TOP, WITHOUT HAVING TO SEARCH THROUGH THE CODE > create_folders( > sFolderPathTemplate, > iFromCount, > iToCount, > iCountWidth) > > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # NOW FINISH > print("" + get_timestamp() + " " + get_script_filename() + " FINISHED.") > #import os > #os._exit(0) > > ############################################################################################################################################################ > > main() > -- > https://mail.python.org/mailman/listinfo/python-list I gave up. I'm happy you want to learn python, and have such enthusiasm, but you should practice some more -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From greg.ewing at canterbury.ac.nz Fri Jun 10 21:17:45 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 11 Jun 2016 13:17:45 +1200 Subject: for / while else doesn't make sense In-Reply-To: <575ace3b$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <_lx6z.1194262$z22.146690@fx36.am4> <87shwlns34.fsf@elektro.pacujo.net> <575ace3b$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I have a 2000 inch monitor, and by using a narrow proportional > font set to 5pt, I can display the entire Python standard library including > tests on screen at once. Then it's just a matter of using my trusty 4" > reflecting telescope to zoom in on any part of the screen I like. You may think you're joking, but this sounds remarkably similar to microfiche... http://www.wisegeek.org/what-is-microfiche.htm -- Greg From orgnut at yahoo.com Sat Jun 11 00:00:02 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 10 Jun 2016 21:00:02 -0700 Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: References: Message-ID: On 06/10/2016 03:52 PM, mad scientist jr wrote: > Is this group appropriate for that kind of thing? > (If not sorry for posting this here.) > > So I wanted to start learning Python, and there is soooo much information online, which is a little overwhelming. I really learn best from doing, especially if it's something actually useful. I needed to create a bunch of empty folders, so I figured it was a good exercise to start learning Python. > Now that it's done, I am wondering what kind of things I could do better. > Here is the code: > It is FAR too complicated -- it's BASIC written Python. Python is MUCH easier. First a couple of general comments... Drop the Hungarian notation!! Python uses dynamic typing. Variables do NOT have a type, the data they hold have types, but not the variable itself. ANY variable can hod ANY data type at ANY time. And Python uses duck typing -- get used to it. Generally you should put all the imports at the beginning of the program, NOT in each function. A possible exception could be if an import is only used in one function. > ############################################################################################################################################################ > # GLOBAL VALUES > sForPythonVersion="3" > #sFolderPathTemplate = "c:\\myscripts\\MP3 Disc " > sFolderPathTemplate = "c:\\temp\\MP3 Disc " > iFromCount = 1 > iToCount = 250 > iCountWidth = 3 > Drop the from the template string. (More on this below.) > ################################################################################################################################################################ > # SUPPORT FUNCTIONS > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN ENGLISH!) > #PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or isinstance(myVar, unicode) ) > #PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr) > return isinstance(myVar, str) > Not necessary. > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY STEPS" > def strip_one_space(s): > if s.endswith(" "): s = s[:-1] > if s.startswith(" "): s = s[1:] > return s > ??? Is this used anyplace? Delete it. > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_exact_python_version(): > import sys > sVersion = ".".join(map(str, sys.version_info[:3])) > sVersion = sVersion.strip() > return sVersion > sys.version_info[:3] by itself gives a three-element tuple. Probably easier to use than the string version. A couple alternatives: sys.version[:5] or perhaps a bit safer -- sys.version.split()[0] both directly give you the string version. (Note this uses version not version_info.) > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # TO DO: RETURN TO THE LEFT OF FIRST "." > def get_python_version(): > sVersion = get_exact_python_version() > return sVersion[0:1] > Probably unnecessary as a function. A simple sVersion[0] in-line might be easier. > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # CHECK PYTHON VERSION, IF IT'S WRONG THEN GRACEFULLY EXIT BEFORE IT BLOWS UP > # (DAMN, PYTHON 2.x STILL COMPLAINS WITH SYNTAX ERRORS!!) > # MAYBE THIS COULD STILL BE USEFUL FOR CHECKING THE SUB-VERSION, IN THAT CASE > # TO DO: MORE GRANULAR CHECK, EG IF VERSION >= 3.5.0 > def exit_if_wrong_python_version(sRightVersion): > import os > sCurrentVersion = get_python_version() > if (sCurrentVersion != sRightVersion): > print("" + > "Wrong Python version (" + > sCurrentVersion + > "), this script should be run using Python " + > sRightVersion + > ".x. Exiting..." > ) > os._exit(0) > Get used to Python string formatting... print("Wrong Python version ({}), this script should be run using " "Python {}.x, Exiting...".format(sCurrentVersion, sRightVersion)) Notice how I split the long single-line string into two shorter strings on two lines relying on the automatic string concatenation in Python. "string1 " "string2" becomes "string1 string2". Any whitespace (spaces, tabs, newlines) are ignored and the two strings are stuck together. Also the common use is sys.exit() instead of os._exit(). > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_script_filename(): > import os > return os.path.basename(__file__) > sys.argv[0] > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_timestamp(): > import datetime > return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > def create_folder(sPath): > import os > import errno > #if not os.path.exists(directory): > # os.makedirs(directory) > try: > os.makedirs(sPath, exist_ok=True) > except OSError as exception: > #if exception.errno != errno.EEXIST: > print("ERROR #" + str(exception.errno) + "IN makedirs") > raise > > # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > def create_folders(sFolderPathTemplate:str="", iFromCount:int=1, iToCount:int=0, iCountWidth:int=0): > # MAKE SURE TEMPLATE'S A STRING. OH, IS THIS NOT "PYTHONIC"? WELL IT'S MORE READABLE > if is_string(sFolderPathTemplate) == False: > iFromCount = 1; iToCount = 0; More readable? The pythonic version would be simply to not use this at all. Now, which is more readable -- this crap or blank lines? > > sName = "" > sCount = "" This is not BASIC, you don't need to pre-declare your variables. > iLoop = iFromCount > while (iLoop <= iToCount) and (len(sFolderPathTemplate) > 0): Why check for the template? It's a global variable, you know it's valid. If not, you deserve your errors. > sCount = "{0}".format(iLoop) > if (iCountWidth > 0): > sCount = sCount.zfill(iCountWidth) > sName = sFolderPathTemplate.replace("", sCount) VERY tricky here, but... sCount = "{{:0{}}.format(iCountWidth)" if iCountWidth else "{}" sName = "{} {}".format(sFolderPathTemplate, sCount).format(iLoop) More direct... if iCountWidth: fmt = "{{:0{}}}".format(iCountWidth) sCount = fmt.format(iLoop) else: sCount = str(iLoop) sName = "{} {}".format(sFolderPathTemplate, sCount) Note this assumes the has been deleted from the template string as noted above. > create_folder(sName) > iLoop = iLoop + 1 More convenient and more pythonic: iLoop += 1 > > ############################################################################################################################################################ > # MAIN LOGIC > > def main(): > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # MAKE SURE PYTHON VERSION IS CORRECT > exit_if_wrong_python_version(sForPythonVersion) > print("PYTHON VERSION (" + get_exact_python_version() + ") MATCHES REQUIRED VERSION (" + sForPythonVersion + ")") > #print("get_python_version returns \"" + get_python_version() + "\"") > #print("get_exact_python_version returns \"" + get_exact_python_version() + "\"") Perhaps unnecessary to check the version, but YMMV... However, the exit_if_wrong_python_version() aborts with an error message, why bother to state that the version is good? If it isn't the program doesn't run anyway. > > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # PRINT START TIMESTAMP > print("" + get_timestamp() + " " + get_script_filename() + " STARTED.") > > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # DO WHAT WE CAME TO DO > # IT'S PROBABLY BAD FORM TO REFERENCE GLOBAL VARIABLES INSIDE THE SCOPE OF A FUNCTION? > # BUT I WANT TO MAKE IT EASY TO CONFIGURE THE SCRIPT JUST BY CHANGING A COUPLE OF LINES > # AT THE TOP, WITHOUT HAVING TO SEARCH THROUGH THE CODE > create_folders( > sFolderPathTemplate, > iFromCount, > iToCount, > iCountWidth) As you say, these are all global variables and are therefore already available to the create_folders() function, so why bother passing them as parameters? Your reason for globals here is probably valid, especially since they are used as constants rather than variables. But in general (in all programming languages) it is usually better and safer to avoid globals if possible. > > # ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # NOW FINISH > print("" + get_timestamp() + " " + get_script_filename() + " FINISHED.") > #import os > #os._exit(0) Yes, your exit() is redundant and you are correct to comment it out. But again I suggest that you get used to using print formatting, it is really versatile. -- -=- Larry -=- From m at funkyhat.org Sat Jun 11 00:28:50 2016 From: m at funkyhat.org (Matt Wheeler) Date: Sat, 11 Jun 2016 04:28:50 +0000 Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: References: Message-ID: First of all welcome :) The other suggestions you've received so far are good so I won't repeat them... (note that in particular I've reused the names you've chosen in your program where I've given code examples, but that's purely for clarity and I agree with the others who've said you should use a more pythonic naming convention) On Fri, 10 Jun 2016, 23:52 mad scientist jr, wrote: > Is this group appropriate for that kind of thing? > (If not sorry for posting this here.) > > So I wanted to start learning Python, and there is soooo much information > online, which is a little overwhelming. I really learn best from doing, > especially if it's something actually useful. I needed to create a bunch of > empty folders, so I figured it was a good exercise to start learning Python. > Now that it's done, I am wondering what kind of things I could do better. > Here is the code: > > # WELCOME TO MY FIRST PYTHON SCRIPT! > # FIRST OF ALL, IT ***WORKS***!!! YAY! > # I AM A VBA AND JAVASCRIPT PROGRAMMER, > # SO IT IS PROBABLY NOT VERY "PYTHONIC", > # SO PLEASE FEEL FREE TO TEAR THE SCRIPT A NEW ONE > # AFTER YOU ARE SHOCKED BY THIS BAD CODE, > # ALL I ASK IS THAT IF YOU THINK SOMETHING IS BAD, > # PLEASE POST AN EXAMPLE OF THE "CORRECT" WAY OF DOING IT > # COMING FROM VBA, I KNOW A LITTLE OOP, > # BUT NOT C++ C# JAVA STUFF LIKE "INTERFACES" AND "ABSTRACT BASE CLASSES" > # SO IF YOU GET INTO SUCH TERMINOLOGY MY EYES MIGHT START TO GLAZE OVER > # UNLESS YOU CARE TO EXPLAIN THAT TOO > Don't worry, Python doesn't have "interfaces" like Java (though it does have multiple inheritance instead, which is more powerful), and it's not necessary to learn about advanced things like abstract classes until you're comfortable :) > > > ############################################################################################################################################################ > # GLOBAL VALUES > sForPythonVersion="3" > #sFolderPathTemplate = "c:\\myscripts\\MP3 Disc " > sFolderPathTemplate = "c:\\temp\\MP3 Disc " > It's possible in Python to use forward slashes in paths, even on Windows, which would allow you to avoid the double slashes above (and can make your code more easily ported to other OSes, which pretty universally use a '/' in paths. I would also suggest you use python's string formatting capabilities instead here (see below where I use this FOLDER_TEMPLATE string): FOLDER_TEMPLATE = 'C:/temp/MP3 Disk {count:03}' iFromCount = 1 > iToCount = 250 > iCountWidth = 3 > > > ################################################################################################################################################################ > # SUPPORT FUNCTIONS > > # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN > ENGLISH!) > #PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or > isinstance(myVar, unicode) ) > #PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr) > return isinstance(myVar, str) > I know this one's been asked already but I think it deserves expanding on. In general in Python it's recommended that you don't try too hard (if at all) to check types of things. Think about what purpose this serves. Pythonic programs follow what's known as "duck typing". i.e. if it quacks like a duck then we can treat it like it's a duck. This lets you write code which expects, for example something like a string, or a dict or list, but isn't strictly bound to those types. That allows other programmers to create their own classes, perhaps a subclass of dict or list, or some unconnected class which just happens to be list-like enough, and it can just work with your code. Of course there are places where you do need to check the type of something, but if you think you need to it's always worth really asking yourself why you think that. (I think this is particularly true when it comes to `str`. Most classes can be represented one way or another as a string, so why not let people pass you anything if you're going to read it as a string anyway? Refusing to accept a non-string is more work for you and more work for them for little benefit) # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY > STEPS" > def strip_one_space(s): > if s.endswith(" "): s = s[:-1] > if s.startswith(" "): s = s[1:] > return s > > # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_exact_python_version(): > import sys > Imports belong at the top of the file unless there's a good reason you don't always want the module imported (e.g. if it's really large or doesn't exist on all the systems your program runs on and isn't a strict requirement). `sys` or `os` definitely don't fall into that category (and I see you've imported them more than once!) sVersion = ".".join(map(str, sys.version_info[:3])) > sVersion = sVersion.strip() > return sVersion > > # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # TO DO: RETURN TO THE LEFT OF FIRST "." > def get_python_version(): > sVersion = get_exact_python_version() > return sVersion[0:1] > Why not just look up sys.version_info[0] instead of having this function? # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > # CHECK PYTHON VERSION, IF IT'S WRONG THEN GRACEFULLY EXIT BEFORE IT BLOWS > UP > # (DAMN, PYTHON 2.x STILL COMPLAINS WITH SYNTAX ERRORS!!) > # MAYBE THIS COULD STILL BE USEFUL FOR CHECKING THE SUB-VERSION, IN THAT > CASE > # TO DO: MORE GRANULAR CHECK, EG IF VERSION >= 3.5.0 > def exit_if_wrong_python_version(sRightVersion): > import os > sCurrentVersion = get_python_version() > if (sCurrentVersion != sRightVersion): > print("" + > "Wrong Python version (" + > sCurrentVersion + > "), this script should be run using Python " + > sRightVersion + > ".x. Exiting..." > ) > os._exit(0) Better would be just let it crash. That way you can see a stacktrace and work out how to fix it. There's a place for doing version checking like this, but small single-purpose scripts should be small and easy to follow. (I have a feeling you should be using sys.exit() rather than os._exit() too, maybe someone else can confirm) # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_script_filename(): > import os return os.path.basename(__file__) > This function's name is nearly as long as the code you're abstracting. Is it worth having a function for this? # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > def get_timestamp(): > import datetime > return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d > %H:%M:%S') > > # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > def create_folder(sPath): > import os > import errno > #if not os.path.exists(directory): > # os.makedirs(directory) > try: > os.makedirs(sPath, exist_ok=True) > except OSError as exception: > #if exception.errno != errno.EEXIST: > print("ERROR #" + str(exception.errno) + "IN makedirs") > raise > If you're targetting Python 3 only you should be able to choose the more specific subclasses of OSError such as FileExistsError rather than worrying about the errno. If you want to catch *some* of OSError's subclasses but not others that's possible like: try: ... except (FileExistsError, IsADirectoryError) as e: ... raise # > ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > def create_folders(sFolderPathTemplate:str="", iFromCount:int=1, > iToCount:int=0, iCountWidth:int=0): > # MAKE SURE TEMPLATE'S A STRING. OH, IS THIS NOT "PYTHONIC"? WELL IT'S > MORE READABLE > if is_string(sFolderPathTemplate) == False: > iFromCount = 1; iToCount = 0; > > sName = "" > sCount = "" > There's no need to initialize variables before they are used > iLoop = iFromCount > while (iLoop <= iToCount) and (len(sFolderPathTemplate) > 0): > sCount = "{0}".format(iLoop) > str(iLoop) would have done fine > if (iCountWidth > 0): > sCount = sCount.zfill(iCountWidth) > sName = sFolderPathTemplate.replace("", sCount) > create_folder(sName) > iLoop = iLoop + 1 > But in Python it's not necessary to manage your own loops like this. It would be better rewritten as a for loop: for i in range(1, iToCount + 1): create_folder(FOLDER_TEMPLATE.format(count=i)) Note I haven't had to deal with padding the counter as the format spec in FOLDER_TEMPLATE deals with that, I don't need to manually increment a loop counter, for and range are working together to give me that. ############################################################################################################################################################ > # MAIN LOGIC > > def main(): > # > ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # MAKE SURE PYTHON VERSION IS CORRECT > exit_if_wrong_python_version(sForPythonVersion) > print("PYTHON VERSION (" + get_exact_python_version() + ") MATCHES > REQUIRED VERSION (" + sForPythonVersion + ")") > Look up string formatting (things like `'Python version: {}. Required version: {}'.format(get_exact_python_version(), sForPythonVersion)`) as an alternative to using + multiple times. It makes things more manageable and is much more powerful. #print("get_python_version returns \"" + get_python_version() > + "\"") > #print("get_exact_python_version returns \"" + > get_exact_python_version() + "\"") > > # > ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # PRINT START TIMESTAMP > print("" + get_timestamp() + " " + get_script_filename() + " STARTED.") > > # > ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # DO WHAT WE CAME TO DO > # IT'S PROBABLY BAD FORM TO REFERENCE GLOBAL VARIABLES INSIDE THE > SCOPE OF A FUNCTION? > # BUT I WANT TO MAKE IT EASY TO CONFIGURE THE SCRIPT JUST BY CHANGING > A COUPLE OF LINES > # AT THE TOP, WITHOUT HAVING TO SEARCH THROUGH THE CODE > create_folders( > sFolderPathTemplate, > iFromCount, > iToCount, > iCountWidth) > > # > ---------------------------------------------------------------------------------------------------------------------------------------------------------------- > # NOW FINISH > print("" + get_timestamp() + " " + get_script_filename() + " > FINISHED.") > If you were using a *NIX OS I would suggest dropping your start and end timestamps and just calling your script via the 'time' command, but apparently Windows doesn't have that :( however I would perhaps move them out of your `main()` function and wrapping the `main()` call below with them instead. I don't feel like they are really "part of the program". That may just be my taste though. #import os > #os._exit(0) > > > ############################################################################################################################################################ > > main() > This is good, you've not just put your logic in the body of the script, it could be slightly better though. The standard pattern goes: if __name__ == '__main__': main() Which means if you were to import your script as a library `main()` won't be run, allowing you to reuse functions easily, and making writing tests much easier. > From jobmattcon at gmail.com Sat Jun 11 00:43:27 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 21:43:27 -0700 (PDT) Subject: how to solve memory In-Reply-To: References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> Message-ID: this time i remove redundant which not add full column sum already has beeb 27*2 but it always has syntax error, indentation error, where is wrong? def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, b, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, b, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, b, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, b, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, b, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, b, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, b[j], "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, b[j], "xy")]) else: initlist.append(op2xy) level.append(op1xy) level.append(op2xy) print("initlist=") print(len(initlist) if deep == maxx: if deep > 0: b = [] for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print("") print("path=") print(len(path)) else: if deep > 0: for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) print("deep=") print(deep) path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) else: print("") print("path=") print(len(path)) return path On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote: > On 2016-06-11 00:31, meInvent bbird wrote: > > it is quite ridiculous, > > this time i am sure that i put correct indentation > > and add a else statement to make sure recursive call inside the > > if statement , it still memory error, > > > > where is the memory error? > > > > is itertools.combinations so big for the list? > > > [snip] > > How long is initlist? > > When I ran the code, it said over 100_000 items. > > How many combinations would there be? > > Over 10_000_000_000. > > That's how long the list 'b' would be. > > You'll need 10s of gigabytes of memory and a lot of patience! From jobmattcon at gmail.com Sat Jun 11 01:18:30 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 22:18:30 -0700 (PDT) Subject: how to solve memory In-Reply-To: References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> Message-ID: i use a version having better indentation, and then remove redundant which if sum column == 54 , do not add this column into initlist and add deep > 0 before recursive call and print number of initlist is 118,XXX but it is still running, where it run , and why run a very long time def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, "xy")]) else: initlist.append(op2xy) level.extend([op1xy, op2xy]) if deep == maxx: b = [] print("initlist=") print(len(initlist)) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) if deep > 0: path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote: > On 2016-06-11 00:31, meInvent bbird wrote: > > it is quite ridiculous, > > this time i am sure that i put correct indentation > > and add a else statement to make sure recursive call inside the > > if statement , it still memory error, > > > > where is the memory error? > > > > is itertools.combinations so big for the list? > > > [snip] > > How long is initlist? > > When I ran the code, it said over 100_000 items. > > How many combinations would there be? > > Over 10_000_000_000. > > That's how long the list 'b' would be. > > You'll need 10s of gigabytes of memory and a lot of patience! From jobmattcon at gmail.com Sat Jun 11 01:55:54 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 22:55:54 -0700 (PDT) Subject: how to solve memory In-Reply-To: References: <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> Message-ID: <2f9dc62c-7999-410e-9448-01cfcb62a273@googlegroups.com> i use sage cloud to run, it killed my program i checked total memory is large, how much memory it need, 8GB*10, 80GB? top - 05:55:16 up 10:05, 1 user, load average: 0.35, 0.63, 0.56 Tasks: 13 total, 1 running, 12 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.5 us, 0.4 sy, 0.0 ni, 99.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 26755056 total, 6317696 used, 20437360 free, 611836 buffers KiB Swap: 67108860 total, 468688 used, 66640172 free. 1223512 cached Mem def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, b, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, b, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, b, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, b, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, b, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, b, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, b[j], "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, b[j], "xy")]) else: initlist.append(op2xy) level.extend([op1xy, op2xy]) if deep == maxx: b = [] print("initlist=") print(len(initlist)) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) if deep > 0: path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote: > On 2016-06-11 00:31, meInvent bbird wrote: > > it is quite ridiculous, > > this time i am sure that i put correct indentation > > and add a else statement to make sure recursive call inside the > > if statement , it still memory error, > > > > where is the memory error? > > > > is itertools.combinations so big for the list? > > > [snip] > > How long is initlist? > > When I ran the code, it said over 100_000 items. > > How many combinations would there be? > > Over 10_000_000_000. > > That's how long the list 'b' would be. > > You'll need 10s of gigabytes of memory and a lot of patience! From jobmattcon at gmail.com Sat Jun 11 02:19:40 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 10 Jun 2016 23:19:40 -0700 (PDT) Subject: which library has map reduce and how to use it for this case In-Reply-To: References: <1ca428db-ea39-4964-a662-df2701580bd2@googlegroups.com> Message-ID: <5195692f-8669-4cd7-a107-e97a52a45eb9@googlegroups.com> there are six operator, and a logic table initial in b variable aa[b[j][i]] [aa[b[i][0:1]+b[i][2:3] are just like vlookup to find output of each operator acting on first column and second column, second column and third column , first column and third column and searching a output columns which is result sum is 27*2 and record the path if succeed, it record the path and output any path which has result is 27*2 described before op1(op2(op3(op1(op2(),),op1(op2(),))), op1(op2(),)) there are two cases, first cases b are logic table later case are for six operators acting on the result column from previous result before recursive call def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, b, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, b, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, b, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, b, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, b, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, b, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, b[j], "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, b[j], "xy")]) else: initlist.append(op2xy) level.extend([op1xy, op2xy]) if deep == maxx: b = [] print("initlist=") print(len(initlist)) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) if deep > 0: path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Friday, June 10, 2016 at 10:04:09 PM UTC+8, Michael Selik wrote: > On Thu, Jun 9, 2016, 9:11 PM Ho Yeung Lee wrote: > > > input are these six operators, output is finding full column of 27 > > elements add together is 54 > > > > i got memory error when searching this, > > > > i have difficulty in understanding map reduce and transforming my program > > into map reduce problem > > > > Why do you think you need map-reduce? > > You'll need to explain the problem in more detail. Instead of talking about > operators and columns, what is the actual, real-world problem? > > > From lists at mostrom.pp.se Sat Jun 11 03:58:56 2016 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Sat, 11 Jun 2016 09:58:56 +0200 Subject: Recommendation for GUI lib? In-Reply-To: References: <24ECEF58-FF95-4B7B-9A7B-2B16800AD959@mostrom.pp.se> Message-ID: <571D5710-D33F-4CFB-8352-D0075074226A@mostrom.pp.se> Thanks everybody for your answers. I really appreciate your answers and I do have a few things to investigate later this summer (after finishing my current "excursion" into Java, and trying to learn KDB/Q). = jem From dfnsonfsduifb at gmx.de Sat Jun 11 07:37:24 2016 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 11 Jun 2016 13:37:24 +0200 Subject: pytz and Python timezones Message-ID: Hi there, first off, let me admit that I have a hard time comprehensively wrapping my head around timezones. Everything around them is much more complicated than it seems, IMO. That said, I'm trying to do things the "right" way and stumbled upon some weird issue which I can't explain. I'm unsure what is happening here. I try to create a localized timestamp in the easiest possible way. So, intuitively, I did this: datetime.datetime(2016,1,1,0,0,0,tzinfo=pytz.timezone("Europe/Berlin")) Which gives me: datetime.datetime(2016, 1, 1, 0, 0, tzinfo=) Uuuuuh... what? This here: pytz.timezone("Europe/Berlin").localize(datetime.datetime(2016,1,1)) Gives me the expected result of: datetime.datetime(2016, 1, 1, 0, 0, tzinfo=) Can someone explain what's going on here and why I end up with the weird "00:53" timezone? Is this a bug or am I doing things wrong? Thanks, Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From irmen.NOSPAM at xs4all.nl Sat Jun 11 08:24:37 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 11 Jun 2016 14:24:37 +0200 Subject: pytz and Python timezones In-Reply-To: References: Message-ID: <575c0304$0$5818$e4fe514c@news.xs4all.nl> On 11-6-2016 13:37, Johannes Bauer wrote: > Hi there, > > first off, let me admit that I have a hard time comprehensively wrapping > my head around timezones. Everything around them is much more > complicated than it seems, IMO. They might not seem complicated, but actually they are. Mindbogglingly so: https://www.youtube.com/watch?v=-5wpm-gesOY > pytz.timezone("Europe/Berlin").localize(datetime.datetime(2016,1,1)) > > Gives me the expected result of: > > datetime.datetime(2016, 1, 1, 0, 0, tzinfo= CET+1:00:00 STD>) > > Can someone explain what's going on here and why I end up with the weird > "00:53" timezone? Is this a bug or am I doing things wrong? I ran into the same issue a while ago and have since accepted that "the right way to do it" is indeed not passing a tzinfo into the datetime constructor, but to always use the second form with tz.localize(datetime). I suppose it is a problem (not so much a bug) caused by the way timezones are done internally in pytz and/or datetime but haven't looked into the details. Mostly because of what is said the video I linked above :) Irmen From michael.selik at gmail.com Sat Jun 11 12:44:17 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 11 Jun 2016 16:44:17 +0000 Subject: which library has map reduce and how to use it for this case In-Reply-To: <5195692f-8669-4cd7-a107-e97a52a45eb9@googlegroups.com> References: <1ca428db-ea39-4964-a662-df2701580bd2@googlegroups.com> <5195692f-8669-4cd7-a107-e97a52a45eb9@googlegroups.com> Message-ID: > > On Friday, June 10, 2016 at 10:04:09 PM UTC+8, Michael Selik wrote: > > You'll need to explain the problem in more detail. Instead of talking > about operators and columns, what is the actual, real-world problem? On Sat, Jun 11, 2016 at 2:21 AM meInvent bbird wrote: > there are six operator, and a logic table initial in b variable > I wasn't asking about the algorithm. I was asking what the task is. If you explain your research question that will help me (and I assume, the rest of the mailing list) understand your problem better. Maybe we can suggest a better algorithm. Give us some context: What data is being input? What is the desired output? What decision will be made based on this calculation? From kliateni at gmail.com Sat Jun 11 13:26:46 2016 From: kliateni at gmail.com (Karim) Date: Sat, 11 Jun 2016 19:26:46 +0200 Subject: movie from pictures In-Reply-To: References: <7e57c662-a6c2-441d-a46e-49458439250f@googlegroups.com> <16301530-a24b-42c6-bcf6-007c4eb85aca@googlegroups.com> Message-ID: <575C49D6.5020204@gmail.com> On 10/06/2016 23:31, alex wright wrote: > I find shlex.split to be most useful to make my arguments a list in these > cases. > On Jun 9, 2016 3:28 PM, "MRAB" wrote: > >> On 2016-06-09 19:58, Peter Otten wrote: >> >>> Nev wrote: >>> >>> Thank you for your reply. I tried something like this in python code: >>>> from subprocess import call >>>> call(["ffmpeg -framerate 4/1 -start_number 1 -i >>>> C:\\Projects\\data2\\img_%05d.png -c:v libx264 -r 30 -pix_fmt yuv420p >>>> C:\\Projects\\data2\\movie.mp4"]) >>>> >>>> But it did not work. I get FileNotFoundError: [WinError 2] The system >>>> cannot find the file specified.. >>>> >>> You have to pass the command-line arguments as separate items in the list: >>> >>> call(["ffmpeg", >>> "-framerate", "4/1", >>> "-start_number", "1", >>> "-i", "C:\\Projects\\data2\\img_%05d.png", >>> ... # and so on >>> ]) >>> >>> You should also give it the full path of ffmpeg. >> On the other hand, in-loop solution would be more preferable since it lets >>>> me to use variable names of the images and paths.. >>>> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> Why not use the split() method on the string of the command line. Karim From mad.scientist.jr at gmail.com Sat Jun 11 13:59:44 2016 From: mad.scientist.jr at gmail.com (mad scientist jr) Date: Sat, 11 Jun 2016 10:59:44 -0700 (PDT) Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: References: Message-ID: <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> Thanks to everyone for your replies. I see my script was as horrific as I feared, but I read all the responses and made a few changes. I'm not 100% sold on not checking types, but took it out, because it made sense that other programmers might want to use some custom type with my functions for their own nefarious purposes. One question I have is, can someone point me to a full listing of all the error types I can trap for? It seems like a Pandora's box, trying to think of all the things that could go wrong, which is why I originally just printed the error #. Is it better to not trap errors, and let the stack trace tell what went wrong? Does it give all the information on the error type etc.? Anyway, for those charitable (or masochistic, or both) enough to critique my code again, here is the updated version: # For Python 3.x # This script creates multiple numbered empty folders # in the desired location. To change the folder names # or location, edit function get_default_options. ############################################################################### # REFERENCE MODULES ############################################################################### import datetime import os import errno import sys ############################################################################### # SUPPORT FUNCTIONS ############################################################################### # returns: dictionary containing options for this script def get_default_options(): dict = { "s_for_python_version": "3", "s_folder_path_template": "C:/temp/test/MP3 Disk {count:03}", "i_from_count": 3, "i_to_count": 7, } return dict # returns: string containing exact version #, eg "3.5.1" # TODO: update to use # sys.version_info[:3] by itself gives a three-element tuple. # Probably easier to use than thestring version. # A couple alternatives: # sys.version[:5] or perhaps a bit safer -- sys.version.split()[0] both directly give you the # string version. (Note this uses version not version_info.) def get_exact_python_version(): s_version = ".".join(map(str, sys.version_info[:3])) s_version = s_version.strip() return s_version # returns: string containing general version #, eg "3" # TODO: return to the left of first "." def get_general_python_version(): s_version = get_exact_python_version() return s_version[0] # checks python version # if it's wrong then gracefully exit before it blows up # (damn, python 2.x still complains with syntax errors!!) # # receives: # s_right_version (string) = python version # to check against # # TODO: more granular check, eg if version >= 3.5.0 def exit_if_wrong_python_version(s_right_version): s_current_version = get_general_python_version() if (s_current_version != s_right_version): print( "Wrong Python version ({}), " "this script should be run using " "Python {}.x, Exiting..." "".format(s_current_version, s_right_version)) sys.exit() # SAME AS os._exit(0) # assists in script readability # returns: string containing name of the current script def get_script_filename(): return sys.argv[0] # returns: string containing the current date/time in the format eg 2016-05-22 13:01:55 def get_timestamp(): return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') # creates a folder at the specified path # receives: # s_path (string) = full path of folder to create def create_folder(s_path): try: os.makedirs(s_path, exist_ok=True) except (FileExistsError, IsADirectoryError) as e: print("FileExistsError IN makedirs") raise return False except OSError as exception: print("ERROR #" + str(exception.errno) + "IN makedirs") raise return False print("" + get_timestamp() + " " + "Created folder: " + s_path + "") # creates multiple numbered folders named per template # receives: # s_folder_path_template (string) = template containing full path of folder to create, # where "{count:n}" is replaced by the folder count (n digits) # i_from_count (int) = number to begin counting at # i_to_count (int) = number to stop counting after # # returns: count of folders created, 0 if error or none def create_folders( s_folder_path_template:str="", i_from_count:int=1, i_to_count:int=0 ): i_count=0 for i_loop in range(i_from_count, i_to_count + 1): create_folder(s_folder_path_template.format(count=i_loop)) i_count += 1 return i_count ############################################################################### # MAIN LOGIC ############################################################################### def main(): options_dict = get_default_options() exit_if_wrong_python_version(options_dict["s_for_python_version"]) print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") print("" + get_timestamp() + " " + get_script_filename() + " started.") i_total_created = create_folders( options_dict["s_folder_path_template"], options_dict["i_from_count"], options_dict["i_to_count"]) print("" + get_timestamp() + " " + str(i_total_created) + " folders created.") print("" + get_timestamp() + " " + get_script_filename() + " finished.") ############################################################################### # GLOBAL CODE (minimal!) ############################################################################### if __name__ == '__main__': main() From mad.scientist.jr at gmail.com Sat Jun 11 14:14:00 2016 From: mad.scientist.jr at gmail.com (mad scientist jr) Date: Sat, 11 Jun 2016 11:14:00 -0700 (PDT) Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> References: <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> Message-ID: <804a90c3-dab2-4cea-b591-06401c055e37@googlegroups.com> For those who don't want to have to wade through comments, here is a version without so many comments: # For Python 3.x # This script creates multiple numbered empty folders # in the desired location. To change the folder names # or location, edit function get_default_options. import datetime import os import errno import sys ############################################################################### # EDIT VALUES HERE TO CUSTOMIZE THE OUTPUT def get_default_options(): dict = { "s_for_python_version": "3", "s_folder_path_template": "C:/temp/test/MP3 Disk {count:03}", "i_from_count": 3, "i_to_count": 7, } return dict ############################################################################### def get_exact_python_version(): s_version = ".".join(map(str, sys.version_info[:3])) s_version = s_version.strip() return s_version def get_general_python_version(): s_version = get_exact_python_version() return s_version[0] def exit_if_wrong_python_version(s_right_version): s_current_version = get_general_python_version() if (s_current_version != s_right_version): print( "Wrong Python version ({}), " "this script should be run using " "Python {}.x, Exiting..." "".format(s_current_version, s_right_version)) sys.exit() def get_script_filename(): return sys.argv[0] def get_timestamp(): return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') def create_folder(s_path): try: os.makedirs(s_path, exist_ok=True) except (FileExistsError, IsADirectoryError) as e: print("FileExistsError IN makedirs") raise return False except OSError as exception: print("ERROR #" + str(exception.errno) + "IN makedirs") raise return False print("" + get_timestamp() + " " + "Created folder: " + s_path + "") def create_folders( s_folder_path_template:str="", i_from_count:int=1, i_to_count:int=0 ): i_count=0 for i_loop in range(i_from_count, i_to_count + 1): create_folder(s_folder_path_template.format(count=i_loop)) i_count += 1 return i_count def main(): options_dict = get_default_options() exit_if_wrong_python_version(options_dict["s_for_python_version"]) print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") print("" + get_timestamp() + " " + get_script_filename() + " started.") i_total_created = create_folders( options_dict["s_folder_path_template"], options_dict["i_from_count"], options_dict["i_to_count"]) print("" + get_timestamp() + " " + str(i_total_created) + " folders created.") print("" + get_timestamp() + " " + get_script_filename() + " finished.") if __name__ == '__main__': main() From marcwbrooks at gmail.com Sat Jun 11 14:18:05 2016 From: marcwbrooks at gmail.com (Marc Brooks) Date: Sat, 11 Jun 2016 18:18:05 +0000 Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: <804a90c3-dab2-4cea-b591-06401c055e37@googlegroups.com> References: <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> <804a90c3-dab2-4cea-b591-06401c055e37@googlegroups.com> Message-ID: Look into docstrings. They will make your code much more readable to a Python reader. On Sat, Jun 11, 2016 at 2:16 PM mad scientist jr wrote: > For those who don't want to have to wade through comments, here is a > version without so many comments: > > # For Python 3.x > # This script creates multiple numbered empty folders > # in the desired location. To change the folder names > # or location, edit function get_default_options. > > import datetime > import os > import errno > import sys > > > ############################################################################### > # EDIT VALUES HERE TO CUSTOMIZE THE OUTPUT > def get_default_options(): > dict = { > "s_for_python_version": "3", > "s_folder_path_template": "C:/temp/test/MP3 Disk {count:03}", > "i_from_count": 3, > "i_to_count": 7, > } > return dict > > ############################################################################### > > def get_exact_python_version(): > s_version = ".".join(map(str, sys.version_info[:3])) > s_version = s_version.strip() > return s_version > > def get_general_python_version(): > s_version = get_exact_python_version() > return s_version[0] > > def exit_if_wrong_python_version(s_right_version): > s_current_version = get_general_python_version() > if (s_current_version != s_right_version): > print( > "Wrong Python version ({}), " > "this script should be run using " > "Python {}.x, Exiting..." > "".format(s_current_version, s_right_version)) > sys.exit() > > def get_script_filename(): > return sys.argv[0] > > def get_timestamp(): > return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d > %H:%M:%S') > > def create_folder(s_path): > try: > os.makedirs(s_path, exist_ok=True) > except (FileExistsError, IsADirectoryError) as e: > print("FileExistsError IN makedirs") > raise > return False > except OSError as exception: > print("ERROR #" + str(exception.errno) + "IN makedirs") > raise > return False > print("" + get_timestamp() + " " + "Created folder: " + s_path + "") > > def create_folders( > s_folder_path_template:str="", > i_from_count:int=1, > i_to_count:int=0 > ): > i_count=0 > for i_loop in range(i_from_count, i_to_count + 1): > create_folder(s_folder_path_template.format(count=i_loop)) > i_count += 1 > > return i_count > > def main(): > options_dict = get_default_options() > exit_if_wrong_python_version(options_dict["s_for_python_version"]) > > > print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") > print("" + get_timestamp() + " " + get_script_filename() + " started.") > > i_total_created = create_folders( > options_dict["s_folder_path_template"], > options_dict["i_from_count"], > options_dict["i_to_count"]) > > print("" + get_timestamp() + " " + str(i_total_created) + " folders > created.") > print("" + get_timestamp() + " " + get_script_filename() + " > finished.") > > if __name__ == '__main__': > main() > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Sat Jun 11 14:41:18 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Jun 2016 19:41:18 +0100 Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> References: <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> Message-ID: On 2016-06-11 18:59, mad scientist jr wrote: > Thanks to everyone for your replies. I see my script was as horrific as I feared, but I read all the responses and made a few changes. I'm not 100% sold on not checking types, but took it out, because it made sense that other programmers might want to use some custom type with my functions for their own nefarious purposes. > > One question I have is, can someone point me to a full listing of all the error types I can trap for? It seems like a Pandora's box, trying to think of all the things that could go wrong, which is why I originally just printed the error #. Is it better to not trap errors, and let the stack trace tell what went wrong? Does it give all the information on the error type etc.? > Catch those exceptions that you can do something about. If, say, it complains that it can't create a folder, you'll need to decide what you should do about it. You might decide that the best way to handle it is to report it to the user and then continue, or report it to the user and then stop. Do whatever makes most sense. If it complains about something unexpected, it's probably best to report it and then just stop, i.e. let unknown exceptions propagate. As Python is an extensible language, there'll never be a complete list of exceptions; just catch what you're prepared to handle. > Anyway, for those charitable (or masochistic, or both) enough to critique my code again, here is the updated version: > > # For Python 3.x > > # This script creates multiple numbered empty folders > # in the desired location. To change the folder names > # or location, edit function get_default_options. > Drop the next 3 comment lines. They add visual clutter, and no useful info. > ############################################################################### > # REFERENCE MODULES > ############################################################################### > import datetime > import os > import errno > import sys > > ############################################################################### > # SUPPORT FUNCTIONS > ############################################################################### > > # returns: dictionary containing options for this script > def get_default_options(): > dict = { > "s_for_python_version": "3", > "s_folder_path_template": "C:/temp/test/MP3 Disk {count:03}", > "i_from_count": 3, > "i_to_count": 7, > } > return dict > > # returns: string containing exact version #, eg "3.5.1" > # TODO: update to use > # sys.version_info[:3] by itself gives a three-element tuple. > # Probably easier to use than thestring version. > # A couple alternatives: > # sys.version[:5] or perhaps a bit safer -- sys.version.split()[0] both directly give you the > # string version. (Note this uses version not version_info.) > def get_exact_python_version(): > s_version = ".".join(map(str, sys.version_info[:3])) The string produced by the preceding line won't start or end with any whitespace, so the next line is pointless. > s_version = s_version.strip() > return s_version > > # returns: string containing general version #, eg "3" > # TODO: return to the left of first "." > def get_general_python_version(): It's called the "major" version. You're going the long way round! The simplest way to get it is directly from sys.version_info. > s_version = get_exact_python_version() > return s_version[0] > > # checks python version > # if it's wrong then gracefully exit before it blows up > # (damn, python 2.x still complains with syntax errors!!) > # > # receives: > # s_right_version (string) = python version # to check against > # > # TODO: more granular check, eg if version >= 3.5.0 > def exit_if_wrong_python_version(s_right_version): > s_current_version = get_general_python_version() The conditions of 'if' statements don't need to be wrapped in (...). > if (s_current_version != s_right_version): > print( > "Wrong Python version ({}), " > "this script should be run using " > "Python {}.x, Exiting..." > "".format(s_current_version, s_right_version)) > sys.exit() # SAME AS os._exit(0) > > # assists in script readability > # returns: string containing name of the current script > def get_script_filename(): > return sys.argv[0] > > # returns: string containing the current date/time in the format eg 2016-05-22 13:01:55 > def get_timestamp(): > return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') datetime instances have a .strftime method, so you can shorten that to: return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') > > # creates a folder at the specified path > # receives: > # s_path (string) = full path of folder to create > def create_folder(s_path): > try: > os.makedirs(s_path, exist_ok=True) > except (FileExistsError, IsADirectoryError) as e: There's little point in catching an exception, printing a message, and then re-raising the exception. The exception's traceback already gives you much more information that the printed message. > print("FileExistsError IN makedirs") > raise You'll never get here because you've just re-raised the exception. > return False > except OSError as exception: Similar remarks to above. > print("ERROR #" + str(exception.errno) + "IN makedirs") > raise > return False The initial ""+ is pointless. > print("" + get_timestamp() + " " + "Created folder: " + s_path + "") > > # creates multiple numbered folders named per template > # receives: > # s_folder_path_template (string) = template containing full path of folder to create, > # where "{count:n}" is replaced by the folder count (n digits) > # i_from_count (int) = number to begin counting at > # i_to_count (int) = number to stop counting after > # > # returns: count of folders created, 0 if error or none > def create_folders( > s_folder_path_template:str="", > i_from_count:int=1, > i_to_count:int=0 > ): > i_count=0 > for i_loop in range(i_from_count, i_to_count + 1): > create_folder(s_folder_path_template.format(count=i_loop)) > i_count += 1 > > return i_count > > ############################################################################### > # MAIN LOGIC > ############################################################################### > > def main(): > options_dict = get_default_options() > exit_if_wrong_python_version(options_dict["s_for_python_version"]) > There's an easier to make the repeated string: "+" * 79 > print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") The initial ""+ is pointless. > print("" + get_timestamp() + " " + get_script_filename() + " started.") > > i_total_created = create_folders( > options_dict["s_folder_path_template"], > options_dict["i_from_count"], > options_dict["i_to_count"]) > > print("" + get_timestamp() + " " + str(i_total_created) + " folders created.") > print("" + get_timestamp() + " " + get_script_filename() + " finished.") > > ############################################################################### > # GLOBAL CODE (minimal!) > ############################################################################### > if __name__ == '__main__': > main() > From mrak at sightlineinnovation.com Sat Jun 11 19:44:32 2016 From: mrak at sightlineinnovation.com (Marcin Rak) Date: Sat, 11 Jun 2016 16:44:32 -0700 (PDT) Subject: the global keyword: Message-ID: Hi to all. I have the following file named Solver.py: ***************************************** from Test import some_function, my_print from Test import test_var some_function() my_print() print(test_var) ***************************************** and I have the following Test.py: ***************************************** test_var = 5 def some_function(): global test_var test_var = 44 print("f {0}".format(test_var)) def my_print(): print(test_var) ***************************************** Would you believe it that when I run Solver.py I get the following output: f 44 44 5 So my question is, how the heck is it possible that I get 5 as the last value printed? the global test_var (global to Test.py) I set to 44 when I ran some_function()??? does anyone have a clue they could throw my way? Much thanks From random832 at fastmail.com Sat Jun 11 19:50:49 2016 From: random832 at fastmail.com (Random832) Date: Sat, 11 Jun 2016 19:50:49 -0400 Subject: the global keyword: In-Reply-To: References: Message-ID: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote: > So my question is, how the heck is it possible that I get 5 as the last > value printed? the global test_var (global to Test.py) I set to 44 when I > ran some_function()??? does anyone have a clue they could throw my way? Importing a variable from a module copies its value into your own module's variable. Updates to the source module's variable will not be reflected in your module. From python at mrabarnett.plus.com Sat Jun 11 20:09:13 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 12 Jun 2016 01:09:13 +0100 Subject: the global keyword: In-Reply-To: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> Message-ID: On 2016-06-12 00:50, Random832 wrote: > On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote: >> So my question is, how the heck is it possible that I get 5 as the last >> value printed? the global test_var (global to Test.py) I set to 44 when I >> ran some_function()??? does anyone have a clue they could throw my way? > > Importing a variable from a module copies its value into your own > module's variable. Updates to the source module's variable will not be > reflected in your module. > Not true. Importing doesn't copy the value. Importing a name creates a new name in the local scope that refers to the same object that the imported name referred to. From mrak at sightlineinnovation.com Sat Jun 11 20:12:21 2016 From: mrak at sightlineinnovation.com (Marcin Rak) Date: Sat, 11 Jun 2016 17:12:21 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> Message-ID: <852bae21-5b2d-49da-8ae6-70e75cbf2d15@googlegroups.com> On Saturday, 11 June 2016 18:51:11 UTC-5, Random832 wrote: > On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote: > > So my question is, how the heck is it possible that I get 5 as the last > > value printed? the global test_var (global to Test.py) I set to 44 when I > > ran some_function()??? does anyone have a clue they could throw my way? > > Importing a variable from a module copies its value into your own > module's variable. Updates to the source module's variable will not be > reflected in your module. As I suspected. Nice to have it confirmed. So it copies any imported variable that is of simple type (string, int, float...) What about variables that are user defined classes? Are they referenced or copied? From mrak at sightlineinnovation.com Sat Jun 11 20:13:26 2016 From: mrak at sightlineinnovation.com (Marcin Rak) Date: Sat, 11 Jun 2016 17:13:26 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> Message-ID: On Saturday, 11 June 2016 19:09:29 UTC-5, MRAB wrote: > On 2016-06-12 00:50, Random832 wrote: > > On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote: > >> So my question is, how the heck is it possible that I get 5 as the last > >> value printed? the global test_var (global to Test.py) I set to 44 when I > >> ran some_function()??? does anyone have a clue they could throw my way? > > > > Importing a variable from a module copies its value into your own > > module's variable. Updates to the source module's variable will not be > > reflected in your module. > > > Not true. Importing doesn't copy the value. > > Importing a name creates a new name in the local scope that refers to > the same object that the imported name referred to. If that's the case, how is it that I get 5 for test_var??? From lawrencedo99 at gmail.com Sat Jun 11 21:16:38 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 11 Jun 2016 18:16:38 -0700 (PDT) Subject: pytz and Python timezones In-Reply-To: References: Message-ID: <518d89b7-1d8c-4b2a-b21a-af82a07f6faf@googlegroups.com> On Saturday, June 11, 2016 at 11:37:38 PM UTC+12, Johannes Bauer wrote: > I try to create a localized timestamp in the easiest possible way. Localized timestamps are perhaps not as easy as you think. > So, intuitively, I did this: > > datetime.datetime(2016,1,1,0,0,0,tzinfo=pytz.timezone("Europe/Berlin")) > > Which gives me: > > datetime.datetime(2016, 1, 1, 0, 0, tzinfo= LMT+0:53:00 STD>) > > Uuuuuh... what? A careful reading of indicates that those classes expect their attributes to already be in local time. I don?t think they have the smarts to examine the tzinfo you pass them and decide which of possibly several sections of historical information might apply to them. So you ended up with it being interpreted according to the oldest section of the ?Europe/Berlin? timezone data (the one up to April 1893). Anyway, that?s my guess. > This here: > > pytz.timezone("Europe/Berlin").localize(datetime.datetime(2016,1,1)) > > Gives me the expected result of: > > datetime.datetime(2016, 1, 1, 0, 0, tzinfo= CET+1:00:00 STD>) Clearly pytz has much more smarts about handling local times. My general rule about dates/times is: always work in UTC. Convert to local dates/times only for display purposes. From random832 at fastmail.com Sat Jun 11 21:26:51 2016 From: random832 at fastmail.com (Random832) Date: Sat, 11 Jun 2016 21:26:51 -0400 Subject: the global keyword: In-Reply-To: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> Message-ID: <1465694811.1095074.634975433.1DCA574A@webmail.messagingengine.com> On Sat, Jun 11, 2016, at 20:09, MRAB wrote: > Not true. Importing doesn't copy the value. > > Importing a name creates a new name in the local scope that refers to > the same object that the imported name referred to. Yes, the value of a variable is a reference to an object. Can we not have another round of this right now? From random832 at fastmail.com Sat Jun 11 21:27:47 2016 From: random832 at fastmail.com (Random832) Date: Sat, 11 Jun 2016 21:27:47 -0400 Subject: the global keyword: In-Reply-To: <852bae21-5b2d-49da-8ae6-70e75cbf2d15@googlegroups.com> References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> <852bae21-5b2d-49da-8ae6-70e75cbf2d15@googlegroups.com> Message-ID: <1465694867.1095176.634975593.0EA97CFC@webmail.messagingengine.com> On Sat, Jun 11, 2016, at 20:12, Marcin Rak wrote: > What about variables that are user defined classes? Are they referenced > or copied? It will reference the same object, but if the variable is reassigned in the original module it will still not update the imported variable. From jobmattcon at gmail.com Sat Jun 11 21:38:37 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Sat, 11 Jun 2016 18:38:37 -0700 (PDT) Subject: how to record path in well format and easy to read? Message-ID: <3724db74-de67-446f-a856-fc9389033ffd@googlegroups.com> https://gist.github.com/hoyeunglee/3fea29ed4aadb5dbc11c41f9a36070dc i discover my code can not record the path because i do recursive call at the end of function however, i want to do full combination at the end of function before calling recursive call, for seeing the result path, choose call recursive call in each else statement which means when it is not found yet, it will continue recursive call this time, i use binary for simple case, but final result show only 4 records, first two do not have ok, third and fourth can not see ok, it become [...] how to show this [...] ? is there any method to record the path in well format and easy to read ? because in 3 valued case, i do not know name of operators, i can only record the full column From lawrencedo99 at gmail.com Sat Jun 11 23:15:03 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 11 Jun 2016 20:15:03 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> Message-ID: On Sunday, June 12, 2016 at 11:51:11 AM UTC+12, Random832 wrote: > Importing a variable from a module copies its value into your own > module's variable. Every name in Python is a variable, and can be assigned to to change its value at any time. From steve at pearwood.info Sat Jun 11 23:38:20 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 12 Jun 2016 13:38:20 +1000 Subject: the global keyword: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> <1465694811.1095074.634975433.1DCA574A@webmail.messagingengine.com> Message-ID: <575cd92d$0$1588$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Jun 2016 11:26 am, Random832 wrote: > On Sat, Jun 11, 2016, at 20:09, MRAB wrote: >> Not true. Importing doesn't copy the value. >> >> Importing a name creates a new name in the local scope that refers to >> the same object that the imported name referred to. MRAB is correct here. > Yes, the value of a variable is a reference to an object. Can we not > have another round of this right now? Sure, if you stop spreading misinformation about variables in Python and cease the insanity of claiming that the value of a variable is not the value you assign to it, but some invisible, unreachable "reference". x = 999 The value of x is 999, not some invisible reference. x = [] The value of x is an empty list, not some invisible reference. -- Steven From ned at nedbatchelder.com Sat Jun 11 23:41:12 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 11 Jun 2016 20:41:12 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> Message-ID: <3daac184-ffa0-4f6b-879c-736153372292@googlegroups.com> On Saturday, June 11, 2016 at 8:13:50 PM UTC-4, Marcin Rak wrote: > On Saturday, 11 June 2016 19:09:29 UTC-5, MRAB wrote: > > On 2016-06-12 00:50, Random832 wrote: > > > On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote: > > >> So my question is, how the heck is it possible that I get 5 as the last > > >> value printed? the global test_var (global to Test.py) I set to 44 when I > > >> ran some_function()??? does anyone have a clue they could throw my way? > > > > > > Importing a variable from a module copies its value into your own > > > module's variable. Updates to the source module's variable will not be > > > reflected in your module. > > > > > Not true. Importing doesn't copy the value. > > > > Importing a name creates a new name in the local scope that refers to > > the same object that the imported name referred to. > > If that's the case, how is it that I get 5 for test_var??? Assignment makes a name refer to a value: x = 12 # Now x refers to 12 More than one name can refer to a value: x = 12 y = x # Now x and y both refer to 12 Re-assigning one name doesn't affect other names referring to the old value: x = 12 y = x x = 24 # Now x refers to 24, and y still refers to 12 Each module has its own globals (this makes the name "global" a bit of a misnomer. Importing a name from a module is an assignment statement in disguise, and each module has its own names: # Test.py test_var = 5 # Solver.py from Test import test_var # This import is effectively: # Solver.test_var = Test.test_var # # Now Test.test_var and Solver.test_var both refer to 5 Reassigning one name doesn't affect other names referring to the old value: # Test.py global test_var test_var = 44 # Test.test_var refers to 44 # Solver.test_var still refers to 5 After all of your code is run, the test_var in Solver.py is still 5. A longer explanation is at http://bit.ly/pynames1 that may help. --Ned. From ned at nedbatchelder.com Sat Jun 11 23:48:18 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 11 Jun 2016 20:48:18 -0700 (PDT) Subject: the global keyword: In-Reply-To: <575cd92d$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> <1465694811.1095074.634975433.1DCA574A@webmail.messagingengine.com> <575cd92d$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, June 11, 2016 at 11:38:33 PM UTC-4, Steven D'Aprano wrote: > On Sun, 12 Jun 2016 11:26 am, Random832 wrote: > > > On Sat, Jun 11, 2016, at 20:09, MRAB wrote: > >> Not true. Importing doesn't copy the value. > >> > >> Importing a name creates a new name in the local scope that refers to > >> the same object that the imported name referred to. > > MRAB is correct here. > > > > Yes, the value of a variable is a reference to an object. Can we not > > have another round of this right now? > > Sure, if you stop spreading misinformation about variables in Python and > cease the insanity of claiming that the value of a variable is not the > value you assign to it, but some invisible, unreachable "reference". > > x = 999 > > The value of x is 999, not some invisible reference. > > x = [] > > The value of x is an empty list, not some invisible reference. We just went through all this. It's clear to me that there are different ways of looking at these underlying mechanisms, and different people find truth in different ways of describing them. The virtual world we live in is complex because of the differing levels of abstraction that are possible. Some of this disagreement is really a matter of choosing different abstractions to focus on. Most importantly, it's clear to me that we aren't going to come to some simple consensus, certainly not by throwing around words like "insanity." Perhaps at least in this thread we can limit ourselves to addressing the OP and their question directly, rather than fighting with each other over which answer is correct? --Ned. From jobmattcon at gmail.com Sun Jun 12 00:55:03 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Sat, 11 Jun 2016 21:55:03 -0700 (PDT) Subject: how to record path in well format and easy to read? In-Reply-To: <3724db74-de67-446f-a856-fc9389033ffd@googlegroups.com> References: <3724db74-de67-446f-a856-fc9389033ffd@googlegroups.com> Message-ID: <0ce8e8d6-e852-4bfc-941a-1db27dbafb20@googlegroups.com> https://gist.github.com/hoyeunglee/350ac2dd496f7c1c95a428f847e6f2b1 then can not run deep 3 in python sagecloud >>> mresult = DFS(b, 3, 3, mylist, path) ('deep=', 3) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) initlist= 18 path= 18 here is caseA ('deep=', 2) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) ) ... retu({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) initlist= 790 path= 936 ('deep=', 1) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) initlist= 1549682 path= 1870866 Killed On Sunday, June 12, 2016 at 9:38:51 AM UTC+8, meInvent bbird wrote: > https://gist.github.com/hoyeunglee/3fea29ed4aadb5dbc11c41f9a36070dc > > i discover my code can not record the path > > because i do recursive call at the end of function > however, i want to do full combination at the end of function before calling > recursive call, > > for seeing the result path, choose call recursive call in each else statement > which means when it is not found yet, it will continue recursive call > > this time, i use binary for simple case, > > but final result show only 4 records, first two do not have ok, > > third and fourth can not see ok, it become [...] > > how to show this [...] ? > > is there any method to record the path in well format and easy to read ? > > because in 3 valued case, i do not know name of operators, i can only record the full column From jobmattcon at gmail.com Sun Jun 12 01:19:09 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Sat, 11 Jun 2016 22:19:09 -0700 (PDT) Subject: how to record path in well format and easy to read? In-Reply-To: <0ce8e8d6-e852-4bfc-941a-1db27dbafb20@googlegroups.com> References: <3724db74-de67-446f-a856-fc9389033ffd@googlegroups.com> <0ce8e8d6-e852-4bfc-941a-1db27dbafb20@googlegroups.com> Message-ID: <93e4ea20-5d82-4bc0-99b4-584071b95214@googlegroups.com> i forget why i do combination of 2 operators now i change not to use combination of 2 operators https://gist.github.com/hoyeunglee/58df4c41a63a2f37e153cbdbc03c16bf i run mresult = DFS(b, 2, 2, mylist, path) it do not have deep 2 and deep 1 in the path they only separated in the list however, i had already assigned in this format path.append([caseA,path2]) before return path, what's wrong with it? On Sunday, June 12, 2016 at 12:55:17 PM UTC+8, meInvent bbird wrote: > https://gist.github.com/hoyeunglee/350ac2dd496f7c1c95a428f847e6f2b1 > > then can not run deep 3 in python sagecloud > > >>> mresult = DFS(b, 3, 3, mylist, path) > ('deep=', 3) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) > ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) > initlist= > 18 > path= > 18 > here is caseA > ('deep=', 2) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) > ) > ... retu({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) > ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) > initlist= > 790 > path= > 936 > ('deep=', 1) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 0, '01': 0}) > ({'11': 1, '10': 1, '00': 0, '01': 1}, {'11': 1, '10': 0, '00': 1, '01': 1}) > ({'11': 1, '10': 0, '00': 0, '01': 0}, {'11': 1, '10': 0, '00': 1, '01': 1}) > initlist= > 1549682 > path= > 1870866 > Killed > > > On Sunday, June 12, 2016 at 9:38:51 AM UTC+8, meInvent bbird wrote: > > https://gist.github.com/hoyeunglee/3fea29ed4aadb5dbc11c41f9a36070dc > > > > i discover my code can not record the path > > > > because i do recursive call at the end of function > > however, i want to do full combination at the end of function before calling > > recursive call, > > > > for seeing the result path, choose call recursive call in each else statement > > which means when it is not found yet, it will continue recursive call > > > > this time, i use binary for simple case, > > > > but final result show only 4 records, first two do not have ok, > > > > third and fourth can not see ok, it become [...] > > > > how to show this [...] ? > > > > is there any method to record the path in well format and easy to read ? > > > > because in 3 valued case, i do not know name of operators, i can only record the full column From pavlovevidence at gmail.com Sun Jun 12 03:01:48 2016 From: pavlovevidence at gmail.com (pavlovevidence at gmail.com) Date: Sun, 12 Jun 2016 00:01:48 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: Message-ID: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> On Thursday, May 19, 2016 at 9:43:56 AM UTC-7, Herkermer Sherwood wrote: > Most keywords in Python make linguistic sense, but using "else" in for and > while structures is kludgy and misleading. I am under the assumption that > this was just utilizing an already existing keyword. Adding another like > "andthen" would not be good. > > But there is already a reserved keyword that would work great here. > "finally". It is already a known keyword used in try blocks, but would work > perfectly here. Best of all, it would actually make sense. > > Unfortunately, it wouldn't follow the semantics of try/except/else/finally. > > Is it better to follow the semantics used elsewhere in the language, or > have the language itself make sense semantically? > > I think perhaps "finally" should be added to for and while to do the same > thing as "else". What do you think? I agree it's not the clearest name, but it does behave consistent with if...else. "finally" has a strong connotation for code that is guaranteed to be executed on the way out regardless of an exception, so it wouldn't be appropriate for this even if it were clearer (though it isn't IMO). Here's how I make sense of for...else. Consider this loop: for item in seq: if pred(item): use(item) break else: not_found() This particular loop functions as a kind of a dynamic if...elif...else statement. You can see that if you unroll the loop: if pred(seq[0]): use(seq[0]) elif pred(seq[1]): use(seq[1]) elif pred(seq[2]): use(seq[2]) else: not_found() You will note that the else block is the same in both the rolled and unrolled versions, and has exactly the same meaning and usage. As for a more appropriate keyword, I don't like the examples I saw skimming this thread; neither "finally" nor "then" communicates that the block would executed conditionally. If you want my opinion, you might as well use something explicit and unambiguous, like "if_exhausted", for the block; and you might as well add an "if_broken" block while you're at it (though it's not quite as useful since in most cases you could just put the code before the break). Since it's only occasionally useful, there's no real need to make the keyword short. If you really want my opinion, it probably shouldn't be in the language at all, even though I happily use it from time to time, and my code is better for it. But it's not useful enough that the language would really suffer without it, and it would save some users from something that can be quite confusing. -- Carl Banks From vincent.vande.vyvre at telenet.be Sun Jun 12 03:20:44 2016 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sun, 12 Jun 2016 09:20:44 +0200 Subject: AttributeError into a bloc try-except AttributeError In-Reply-To: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> Message-ID: <575D0D4C.5080106@telenet.be> Hi, I have a strange behaviour in my code. In an interactive session, the result is as expected: Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> a = None >>> try: ... _ = a.value ... except AttributeError: ... print('OK') ... OK >>> But not in my code: def call_settings_dialog(self): try: _ = self.video.category self.core.artelive.configure_downloading(self.video) except AttributeError: self.core.artetv.configure_downloading(self.video) and ... Traceback (most recent call last): File "/home/vincent/qarte-3/trunk/loadingscheduler.py", line 240, in call_settings_dialog _ = self.video.category AttributeError: 'TVItem' object has no attribute 'category' I have two types of video, one with an attribute category handled by a module 'artelive' and an other without this attribute handled by an other module, that's the reason of this code. From vincent.vande.vyvre at telenet.be Sun Jun 12 04:30:23 2016 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sun, 12 Jun 2016 10:30:23 +0200 Subject: AttributeError into a bloc try-except AttributeError In-Reply-To: <575D0D4C.5080106@telenet.be> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575D0D4C.5080106@telenet.be> Message-ID: <575D1D9F.3030909@telenet.be> Le 12/06/16 09:20, Vincent Vande Vyvre a ?crit : > Hi, > > I have a strange behaviour in my code. > > In an interactive session, the result is as expected: > > Python 3.4.3 (default, Oct 14 2015, 20:28:29) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> a = None > >>> try: > ... _ = a.value > ... except AttributeError: > ... print('OK') > ... > OK > >>> > > But not in my code: > > def call_settings_dialog(self): > try: > _ = self.video.category > self.core.artelive.configure_downloading(self.video) > except AttributeError: > self.core.artetv.configure_downloading(self.video) > > and ... > > Traceback (most recent call last): > File "/home/vincent/qarte-3/trunk/loadingscheduler.py", line 240, in > call_settings_dialog > _ = self.video.category > AttributeError: 'TVItem' object has no attribute 'category' > > I have two types of video, one with an attribute category handled by a > module 'artelive' and an other without this attribute handled by an > other module, that's the reason of this code. ... I have just rewrite the line "_ = self.video.category" and the problem disappears. Vincent From steve+comp.lang.python at pearwood.info Sun Jun 12 06:06:38 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 12 Jun 2016 20:06:38 +1000 Subject: for / while else doesn't make sense References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> Message-ID: <575d3430$0$11108$c3e8da3@news.astraweb.com> On Sunday 12 June 2016 17:01, pavlovevidence at gmail.com wrote: > On Thursday, May 19, 2016 at 9:43:56 AM UTC-7, Herkermer Sherwood wrote: >> Most keywords in Python make linguistic sense, but using "else" in for and >> while structures is kludgy and misleading. I am under the assumption that >> this was just utilizing an already existing keyword. Adding another like >> "andthen" would not be good. [...] >> I think perhaps "finally" should be added to for and while to do the same >> thing as "else". What do you think? > > I agree it's not the clearest name, but it does behave consistent with > if...else. Er, not really. if condition: print "A" else: print "B" Exactly one of "A" or "B", but NEVER both, will be printed. for item in sequence: print "A" else: print "B" Normally we would expect that both "A" and "B" will be printed. There will be a variable number of "A"s printed, zero or more, and exactly one "B", but the point is that in general BOTH will run, which is the opposite of if...else. The actual semantics are: - run the for block - THEN unconditionally run the "else" block The only way to skip running the "else" block is to jump out of the entire for...else statement, using `return`, `raise` or `break`. > Here's how I make sense of for...else. Consider this loop: > > for item in seq: > if pred(item): > use(item) > break > else: > not_found() That's the major intended use of "else", but note that it is NOT paired with the `if`. You can have: def func(): for item in seq: if pred(item): use(item) if condition: return something else: different_use(item) continue do_more() break else: not_found() or any of an infinite number of other combinations. You can't really understand for...else correctly if you think of the "else" being partnered with an "if" inside the loop. What if there is no "if"? Or ten of them? Of if they all already have "else" clauses? > This particular loop functions as a kind of a dynamic if...elif...else > statement. You can see that if you unroll the loop: > > > if pred(seq[0]): > use(seq[0]) > elif pred(seq[1]): > use(seq[1]) > elif pred(seq[2]): > use(seq[2]) > else: > not_found() They are only equivalent because of the "break". Take the break out, unroll the loop, and what you have is: if pred(seq[0]): use(seq[0]) if pred(seq[1]): use(seq[1]) if pred(seq[2]): use(seq[2]) not_found() Put the break back in, and you have: if pred(seq[0]): use(seq[0]) GOTO foo # not actual Python syntax, but see below if pred(seq[1]): use(seq[1]) GOTO foo if pred(seq[2]): use(seq[2]) GOTO foo not_found() label: foo Admittedly GOTO isn't Python syntax, but this actually is the way that the bytecode is done: the else clause is executed unconditionally, and a break jumps past the else clause. In Python 3.3, "break" is compiled to a JUMP_ABSOLUTE bytecode. You can see this for yourself using the dis module, e.g.: import dis code = compile(""" for i in seq: this() if condition: break that() else: another() print("done") """, "", "exec") dis.dis(code) > You will note that the else block is the same in both the rolled and unrolled > versions, and has exactly the same meaning and usage. But not in the general case. Only certain specific uses of for...else behave as you suggest. > As for a more appropriate keyword, I don't like the examples I saw skimming > this thread; neither "finally" nor "then" communicates that the block would > executed conditionally. The block isn't executed conditionally. The block is executed UNCONDITIONALLY. The only way to avoid executing the "else" block is to jump past it, using a return, raise of break. > If you want my opinion, you might as well use something explicit and > unambiguous, like "if_exhausted", for the block; But that is exactly what the else clause is NOT. That is an incredibly common mistake that people make, thinking that the "else" clause executes when the sequence is exhausted. At first, it *seems* to be the case: py> seq = [] py> for item in seq: ... print("not empty!") ... else: ... print("empty") ... empty but that wrong. py> seq = [1, 2] py> for item in seq: ... print("not empty!") ... else: ... print("empty") ... not empty! not empty! empty py> print(seq) # not exhausted [1, 2] The else clause has nothing to do with whether or not the for block runs, or whether it is empty, or whether the iterable is exhausted after the loop is complete. The else clause simple runs directly after the for block, unless you skip it by using the Python equivalent of a GOTO. > If you really want my opinion, it probably shouldn't be in the language at > all, even though I happily use it from time to time, and my code is better > for it. o_O > But it's not useful enough that the language would really suffer > without it, and it would save some users from something that can be quite > confusing. As confusing as threads? As confusing as multiple inheritance? As confusing as asynchronous programming? If you have seen as many beginners ask "why do I always get 100 heads or 100 tails?" as I have: count_heads = 0 coin = random.choose(['heads', 'tails']) for i in range(100): if coin == 'heads': count_heads += 1 print("number of heads:", count_heads) print("number of tails:", 100 - count_heads) then you will understand that "confusing" is often a matter of experience and understanding. Once you have the correct understanding of "for...else", there is nothing confusing about it. -- Steve From peter.volkov at gmail.com Sun Jun 12 08:09:31 2016 From: peter.volkov at gmail.com (Peter Volkov) Date: Sun, 12 Jun 2016 15:09:31 +0300 Subject: how to handle surrogate encoding: read from fs write to database Message-ID: Hi, everybody. What is a best practice to deal with filenames in python3? The problem is that os.walk(src_dir), os.listdir(src_dir), ... return "surrogate" strings as filenames. It is impossible to assume that they are normal strings that could be print()'ed on unicode terminal or saved as as string into database (mongodb) as they'll issue UnicodeEncodeError on surrogate character. So, how to handle this situation? The first solution I found was to convert filenames to bytes and use them. But that's not nice. Once I need to compare filename with some string I'll have to convert strings to bytes. Also Bytes() objects are base64 encoded in mongo shell and thus they are hard to read, *e.g. "binary" : BinData(0,"c29tZSBiaW5hcnkgdGV4dA==")*. Finally PEP 383 states that using bytes does not work in windows (btw, why?). Another option I found is to work with filenames as surrogate strings but enc them to 'latin-1' before printing/saving into database: filename.encode(fse, errors='surrogateescape').decode('latin-1') This way I like more since latin symbols are clearly visible in mongo shell. Yet I doubt this is best solution. Ideally I would like to send surrogate strings to database or to terminal as is and let db/terminal handle them. IOW let terminal print garbage where surrogate letters appear. Is this possible in python? So what do you think: is usage unicode strings and explicit conversion to latin-1 a good option? Also related question: is it possible to detect surrogate symbols in strings? I found suggestion to use re.compile('[\ud800-\uefff]+'). Yet all this stuff feels to hacky for me, so I would like some confirmation that this is the right way. Thanks in advance and sorry for touching this matter again. Too many discussions and not evident what is the current state of art here. -- Peter. From drekin at gmail.com Sun Jun 12 08:56:05 2016 From: drekin at gmail.com (=?UTF-8?B?QWRhbSBCYXJ0b8Wh?=) Date: Sun, 12 Jun 2016 14:56:05 +0200 Subject: Altering sys.argv on startup in Python 2 Message-ID: Hello, I'm trying to employ code like https://code.activestate.com/recipes/572200/ at Python 2 startup. The problem is that sys.argv isn't polulated yet when sitecustomize is executed. Is there any way around? I was thinking about something like temporarily chaning sys.modules['sys'] or sys.__dict__ to something that runs my code on PySys_SetArgv, but that doesn't work since PySys_SetArgv doesn't invoke any hooks like __setitem__ on sys.__dict__. So is there any way how to automatically run my code after sys.argv was set but before executing the main script (in Python 2)? Regards, Adam Barto? From ictezy at gmail.com Sun Jun 12 11:10:27 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 12 Jun 2016 08:10:27 -0700 (PDT) Subject: Indentation example? Message-ID: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> Pl explain with an example the following phase "Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation" (in 2.1.8. Indentation of Tutorial.) I want to teach my student that point using some examples. Pl help me any body? From carl at oddbird.net Sun Jun 12 11:13:16 2016 From: carl at oddbird.net (Carl Meyer) Date: Sun, 12 Jun 2016 09:13:16 -0600 Subject: pytz and Python timezones In-Reply-To: References: Message-ID: <575D7C0C.5020107@oddbird.net> Hi Johannes, On 06/11/2016 05:37 AM, Johannes Bauer wrote: > I try to create a localized timestamp > in the easiest possible way. So, intuitively, I did this: > > datetime.datetime(2016,1,1,0,0,0,tzinfo=pytz.timezone("Europe/Berlin")) That is indeed intuitive, but unfortunately (due to a misunderstanding between the original authors of Python's datetime module and the author of pytz about how timezone-aware datetimes should work in Python) it is not correct. The correct way to create a localized datetime using pytz is this: tz = pytz.timezone('Europe/Berlin') dt = tz.localize(datetime.datetime(2016, 1, 1, 0, 0, 0) This is documented prominently in the pytz documentation: http://pytz.sourceforge.net/ > Which gives me: > > datetime.datetime(2016, 1, 1, 0, 0, tzinfo= LMT+0:53:00 STD>) > > Uuuuuh... what? When you create a pytz timezone object, it encompasses all historical UTC offsets that have ever been in effect in that location. When you pass a datetime to the `localize()` method of that timezone object, it is able to figure out which actual UTC offset was in effect at that local time in that location, and apply the correct "version" of itself to that datetime. However, no such logic is built into the datetime module itself. So when you just apply a pytz timezone directly to the tzinfo property of a datetime, pytz by default falls back to the first entry in its historical table of UTC offsets for that location. For most locations, that is something called "LMT" or Local Mean Time, which is the customary time in use at that location prior to the standardization of timezones. And in most locations, LMT is offset from UTC by a strange number of minutes. That's why you see "LMT" and the odd 53-minute offset above. > This here: > > pytz.timezone("Europe/Berlin").localize(datetime.datetime(2016,1,1)) > > Gives me the expected result of: > > datetime.datetime(2016, 1, 1, 0, 0, tzinfo= CET+1:00:00 STD>) > > Can someone explain what's going on here and why I end up with the weird > "00:53" timezone? Is this a bug or am I doing things wrong? It is not a bug in pytz or in datetime, in that it is intended behavior, although that behavior is unfortunately obscure, bug-prone, and little-understood. If you are masochistic enough to want to understand how this bad situation came to be, and what might be done about it, you can read through PEPs 431 and 495. Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From listoamugongo at hotmail.com Sun Jun 12 11:39:54 2016 From: listoamugongo at hotmail.com (Listo Amugongo) Date: Sun, 12 Jun 2016 16:39:54 +0100 Subject: is there a big in python 3.5.1 shell? Message-ID: In my attarchment above is a screenshot of my session. Screenshot describtion: In my first elif function (first code block) I deliberately programmed an indention error.i did it purposely to make my point clear and the point is Python 3.5.1 shell* gives a synatax error after I run the elif function. It does not matter how correctly you indent your code block.however this is not the case when I code in Python 3.5.1 which I open using the windows command Line prompt c:\python. I?m new to Python and I?m wondering if there?s something I don?t know or doing wrong.Furthermore the Python shell won?t display the continuation line three dots(?).which is also not the case in Python 3.5.1. Any feedback will be highly regarded. Sent from Mail for Windows 10 From mad.scientist.jr at gmail.com Sun Jun 12 12:04:09 2016 From: mad.scientist.jr at gmail.com (mad scientist jr) Date: Sun, 12 Jun 2016 09:04:09 -0700 (PDT) Subject: i'm a python newbie & wrote my first script, can someone critique it? In-Reply-To: References: <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> Message-ID: Thanks for your reply! On Saturday, June 11, 2016 at 2:41:39 PM UTC-4, MRAB wrote: > Drop the next 3 comment lines. They add visual clutter, and no useful info. > > ############################################################################### > > # REFERENCE MODULES > > ############################################################################### I'm not going to argue minor points at length, because others have said the same thing here, but I will push back a little and explain that what you guys consider visual clutter, I find helps me to visually break up and quickly identify sections in my code, which is why I like those separators. > There's an easier to make the repeated string: "+" * 79 > > print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") Thanks, that's a good tip. In this case I might prefer showing the full line of +s because that way, wysiwyg, it's just easier to visualize the output. Thanks again for the input. . . I will further digest what you all said and study some more (including the docstrings) From steve at pearwood.info Sun Jun 12 12:06:02 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 13 Jun 2016 02:06:02 +1000 Subject: Indentation example? References: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> Message-ID: <575d886b$0$1601$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jun 2016 01:10 am, ICT Ezy wrote: > Pl explain with an example the following phase > "Indentation cannot be split over multiple physical lines using > backslashes; the whitespace up to the first backslash determines the > indentation" (in 2.1.8. Indentation of Tutorial.) I want to teach my > student that point using some examples. Pl help me any body? Good indentation: def function(): # four spaces per indent print("hello") print("goodbye") Bad indentation: def function(): # four spaces per indent print("hello") # four spaces \ print("goodbye") # two spaces, then backslash, then two more The second example will be a SyntaxError. -- Steven From ned at nedbatchelder.com Sun Jun 12 12:15:43 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 12 Jun 2016 09:15:43 -0700 (PDT) Subject: Indentation example? In-Reply-To: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> References: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> Message-ID: On Sunday, June 12, 2016 at 11:10:39 AM UTC-4, ICT Ezy wrote: > Pl explain with an example the following phase > "Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation" (in 2.1.8. Indentation of Tutorial.) > I want to teach my student that point using some examples. > Pl help me any body? For what it's worth, that sentence isn't in the tutorial, it's in the reference manual, which has to mention all sorts of edge cases that most people will likely never encounter. I've never seen someone try to make indentation work in that way with a backslash. If I were you, I wouldn't mention it to your students, it might just confuse them further. --Ned. From ictezy at gmail.com Sun Jun 12 12:23:32 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 12 Jun 2016 09:23:32 -0700 (PDT) Subject: Indentation example? In-Reply-To: <575d886b$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> <575d886b$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1c100d68-7f64-45c5-9737-e3b8c84df6e5@googlegroups.com> On Sunday, June 12, 2016 at 9:36:16 PM UTC+5:30, Steven D'Aprano wrote: > On Mon, 13 Jun 2016 01:10 am, ICT Ezy wrote: > > > Pl explain with an example the following phase > > "Indentation cannot be split over multiple physical lines using > > backslashes; the whitespace up to the first backslash determines the > > indentation" (in 2.1.8. Indentation of Tutorial.) I want to teach my > > student that point using some examples. Pl help me any body? > > > Good indentation: > > def function(): > # four spaces per indent > print("hello") > print("goodbye") > > > Bad indentation: > > def function(): > # four spaces per indent > print("hello") # four spaces > \ > print("goodbye") # two spaces, then backslash, then two more > > > The second example will be a SyntaxError. > > > > -- > Steven Thank you very much your example From ictezy at gmail.com Sun Jun 12 12:24:23 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 12 Jun 2016 09:24:23 -0700 (PDT) Subject: Indentation example? In-Reply-To: References: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> Message-ID: <216ac8e5-dbc0-49af-b541-bfc30a34939b@googlegroups.com> On Sunday, June 12, 2016 at 9:46:00 PM UTC+5:30, Ned Batchelder wrote: > On Sunday, June 12, 2016 at 11:10:39 AM UTC-4, ICT Ezy wrote: > > Pl explain with an example the following phase > > "Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation" (in 2.1.8. Indentation of Tutorial.) > > I want to teach my student that point using some examples. > > Pl help me any body? > > For what it's worth, that sentence isn't in the tutorial, it's in the > reference manual, which has to mention all sorts of edge cases that most > people will likely never encounter. > > I've never seen someone try to make indentation work in that way with a > backslash. If I were you, I wouldn't mention it to your students, it might > just confuse them further. > > --Ned. Thank for your advice me From ictezy at gmail.com Sun Jun 12 12:25:56 2016 From: ictezy at gmail.com (ICT Ezy) Date: Sun, 12 Jun 2016 09:25:56 -0700 (PDT) Subject: Indentation example? In-Reply-To: <575d886b$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> <575d886b$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <49bbd24a-5294-414c-a2c6-68742ec7b3d5@googlegroups.com> On Sunday, June 12, 2016 at 9:36:16 PM UTC+5:30, Steven D'Aprano wrote: > On Mon, 13 Jun 2016 01:10 am, ICT Ezy wrote: > > > Pl explain with an example the following phase > > "Indentation cannot be split over multiple physical lines using > > backslashes; the whitespace up to the first backslash determines the > > indentation" (in 2.1.8. Indentation of Tutorial.) I want to teach my > > student that point using some examples. Pl help me any body? > > > Good indentation: > > def function(): > # four spaces per indent > print("hello") > print("goodbye") > > > Bad indentation: > > def function(): > # four spaces per indent > print("hello") # four spaces > \ > print("goodbye") # two spaces, then backslash, then two more > > > The second example will be a SyntaxError. > > > > -- > Steven Thank you very much your example From steve at pearwood.info Sun Jun 12 12:50:24 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 13 Jun 2016 02:50:24 +1000 Subject: how to handle surrogate encoding: read from fs write to database References: Message-ID: <575d92d2$0$1605$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Jun 2016 10:09 pm, Peter Volkov wrote: > Hi, everybody. > > What is a best practice to deal with filenames in python3? The problem is > that os.walk(src_dir), os.listdir(src_dir), ... return "surrogate" strings > as filenames. Can you give an example? > It is impossible to assume that they are normal strings that > could be print()'ed on unicode terminal or saved as as string into > database (mongodb) as they'll issue UnicodeEncodeError on surrogate > character. So, how to handle this situation? Use a better OS :-) I believe that Mac OS X handles this the right way. If I understand correctly, its preferred file system, HFS+, will only allow valid UTF-8 strings as file names. So you cannot get invalid Unicode strings containing surrogates on Apple systems (unless you read from a non-HFS+ disk). I think Windows also gets it almost write: NTFS uses UTF-16, and (I think) only allow valid Unicode file names. Its only Unix file systems, including Linux, that allows arbitrary bytes (except for / and \0) in file names, so file names can be invalid Unicode, including surrogates. All the terminals I know of on Linux will print "bad" file names. They will be ugly, with control characters inside them, or invisible characters that cannot even be seen, but they will print. > The first solution I found was to convert filenames to bytes and use them. I think that's the only real solution. The file names on disk actually are bytes, and they're invalid Unicode, so it shouldn't surprise you if the only way to deal with them losslessly is to keep them as bytes. Another way is to simply refuse to process those files. Filenames with broken Unicode are, arguably, broken and shouldn't be allowed. It's your application, you can specify how files have to be named. Even if your operating system allows it, your application can refuse to deal with them: either just skip those files, or raise an error, or insist that the user renames them to something usable. Perhaps you can even repair the file name yourself, by deleting or replacing the surrogates. > But that's not nice. Once I need to compare filename with some string I'll > have to convert strings to bytes. That's not hard. 'my filename.txt'.encode('utf-8') # or whatever encoding your file system uses > Also Bytes() objects are base64 encoded > in mongo shell and thus they are hard to read, Use a better database :-) > *e.g. "binary" : > BinData(0,"c29tZSBiaW5hcnkgdGV4dA==")*. Finally PEP 383 states that using > bytes does not work in windows (btw, why?). Windows file systems, at least NTFS, uses UTF-16 file names. But that shouldn't matter to you: all that means is that when you read files names from Windows, you should never see any surrogates. (I think. I don't have access to a Windows machine I can test this.) > Another option I found is to work with filenames as surrogate strings but > enc them to 'latin-1' before printing/saving into database: > filename.encode(fse, errors='surrogateescape').decode('latin-1') Do you want mojibake? Because that's how you get mojibake. py> '?Py'.encode('utf-8').decode('latin1') '??Py' py> '??'.encode('utf-8').decode('latin1') '???\x89' You are mapping the full range of 1114112 distinct Unicode code points into just 256 Latin-1 characters. Bad Things happen. > This way I like more since latin symbols are clearly visible in mongo > shell. Yet I doubt this is best solution. It certainly isn't. > Ideally I would like to send surrogate strings to database or to terminal > as is and let db/terminal handle them. IOW let terminal print garbage > where surrogate letters appear. Is this possible in python? That's nothing to do with Python, it depends on the database, and the terminal. > So what do you think: is usage unicode strings and explicit conversion to > latin-1 a good option? Absolutely not. > Also related question: is it possible to detect surrogate symbols in > strings? any('\uD800' <= c <= '\uDFFF' for c in the_string) -- Steven From random832 at fastmail.com Sun Jun 12 13:51:17 2016 From: random832 at fastmail.com (Random832) Date: Sun, 12 Jun 2016 13:51:17 -0400 Subject: Altering sys.argv on startup in Python 2 In-Reply-To: References: Message-ID: <1465753877.2756405.635360577.2969D1BA@webmail.messagingengine.com> On Sun, Jun 12, 2016, at 08:56, Adam Barto? wrote: > Hello, > > I'm trying to employ code like > https://code.activestate.com/recipes/572200/ > at Python 2 startup. The problem is that sys.argv isn't polulated yet > when > sitecustomize is executed. Is there any way around? I was thinking about > something like temporarily chaning sys.modules['sys'] or sys.__dict__ to > something that runs my code on PySys_SetArgv, but that doesn't work since > PySys_SetArgv doesn't invoke any hooks like __setitem__ on sys.__dict__. > So > is there any way how to automatically run my code after sys.argv was set > but before executing the main script (in Python 2)? >From what I can tell, if you create a path hook in sitecustomize.py, argv will have been set before the hook is called for the script. So, for example: import sys edit_done = False def argv_setter_hook(path): global edit_done if edit_done: return try: argv = sys.argv except AttributeError: pass else: argv[:] = get_unicode_argv() edit_done = True raise ImportError # let the real import machinery do its work sys.path_hooks[:0] = [argv_setter_hook] From random832 at fastmail.com Sun Jun 12 13:59:44 2016 From: random832 at fastmail.com (Random832) Date: Sun, 12 Jun 2016 13:59:44 -0400 Subject: how to handle surrogate encoding: read from fs write to database In-Reply-To: <575d92d2$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <575d92d2$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465754384.2757439.635371065.0CA15995@webmail.messagingengine.com> On Sun, Jun 12, 2016, at 12:50, Steven D'Aprano wrote: > I think Windows also gets it almost write: NTFS uses UTF-16, and (I > think) only allow valid Unicode file names. Nope. Windows allows any sequence of 16-bit units (except for a dozen or so ASCII characters) in filenames. Of course, you're not particularly _likely_ to encounter invalid surrogates, since nothing is going to create them without deliberately setting out to (unlike Linux where 'invalid' filenames will be created by any program using the 'wrong' locale). From random832 at fastmail.com Sun Jun 12 14:01:48 2016 From: random832 at fastmail.com (Random832) Date: Sun, 12 Jun 2016 14:01:48 -0400 Subject: Altering sys.argv on startup in Python 2 In-Reply-To: <1465753877.2756405.635360577.2969D1BA@webmail.messagingengine.com> References: <1465753877.2756405.635360577.2969D1BA@webmail.messagingengine.com> Message-ID: <1465754508.2758007.635374417.65E6032E@webmail.messagingengine.com> On Sun, Jun 12, 2016, at 13:51, Random832 wrote: > if edit_done: > return this should of course be raise ImportError - an artifact of some refactoring I did on the example. From random832 at fastmail.com Sun Jun 12 14:01:56 2016 From: random832 at fastmail.com (Random832) Date: Sun, 12 Jun 2016 14:01:56 -0400 Subject: Altering sys.argv on startup in Python 2 Message-ID: <1465754516.2757994.635374417.2AF754D9@webmail.messagingengine.com> On Sun, Jun 12, 2016, at 13:51, Random832 wrote: > if edit_done: > return this should of course be raise ImportError - an artifact of some refactoring I did on the example. From joel.goldstick at gmail.com Sun Jun 12 14:07:59 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 12 Jun 2016 14:07:59 -0400 Subject: is there a big in python 3.5.1 shell? In-Reply-To: References: Message-ID: On Sun, Jun 12, 2016 at 11:39 AM, Listo Amugongo wrote: > In my attarchment above is a screenshot of my session. > Screenshot describtion: > In my first elif function (first code block) I deliberately programmed an indention error.i did it purposely to make my point clear and the point is Python 3.5.1 shell* gives a synatax error after I run the elif function. > It does not matter how correctly you indent your code block.however this is not the case when I code in Python 3.5.1 which I open using the windows command Line prompt c:\python. > > I?m new to Python and I?m wondering if there?s something I don?t know or doing wrong.Furthermore the Python shell won?t display the continuation line three dots(?).which is also not the case in Python 3.5.1. > Any feedback will be highly regarded. > > Sent from Mail for Windows 10 > > -- > https://mail.python.org/mailman/listinfo/python-list Welcome. You can't do attachments in this list. Most people won't see them. Just cut and paste your code in your text -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From mrak at sightlineinnovation.com Sun Jun 12 14:31:42 2016 From: mrak at sightlineinnovation.com (Marcin Rak) Date: Sun, 12 Jun 2016 11:31:42 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> <1465694811.1095074.634975433.1DCA574A@webmail.messagingengine.com> <575cd92d$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: Much thanks to all for their time, but Ned in particular...I learned something new about Python!! On Saturday, 11 June 2016 22:48:32 UTC-5, Ned Batchelder wrote: > On Saturday, June 11, 2016 at 11:38:33 PM UTC-4, Steven D'Aprano wrote: > > On Sun, 12 Jun 2016 11:26 am, Random832 wrote: > > > > > On Sat, Jun 11, 2016, at 20:09, MRAB wrote: > > >> Not true. Importing doesn't copy the value. > > >> > > >> Importing a name creates a new name in the local scope that refers to > > >> the same object that the imported name referred to. > > > > MRAB is correct here. > > > > > > > Yes, the value of a variable is a reference to an object. Can we not > > > have another round of this right now? > > > > Sure, if you stop spreading misinformation about variables in Python and > > cease the insanity of claiming that the value of a variable is not the > > value you assign to it, but some invisible, unreachable "reference". > > > > x = 999 > > > > The value of x is 999, not some invisible reference. > > > > x = [] > > > > The value of x is an empty list, not some invisible reference. > > We just went through all this. It's clear to me that there are different > ways of looking at these underlying mechanisms, and different people find > truth in different ways of describing them. The virtual world we live in > is complex because of the differing levels of abstraction that are possible. > Some of this disagreement is really a matter of choosing different > abstractions to focus on. > > Most importantly, it's clear to me that we aren't going to come to some > simple consensus, certainly not by throwing around words like "insanity." > > Perhaps at least in this thread we can limit ourselves to addressing the > OP and their question directly, rather than fighting with each other over > which answer is correct? > > --Ned. From michael.selik at gmail.com Sun Jun 12 14:44:53 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 12 Jun 2016 18:44:53 +0000 Subject: for / while else doesn't make sense In-Reply-To: <575d3430$0$11108$c3e8da3@news.astraweb.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> Message-ID: On Sun, Jun 12, 2016 at 6:11 AM Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > - run the for block > - THEN unconditionally run the "else" block > Saying "unconditionally" is a bit misleading here. As you say, it's conditioned on completing the loop without break/return/raise. From random832 at fastmail.com Sun Jun 12 14:46:55 2016 From: random832 at fastmail.com (Random832) Date: Sun, 12 Jun 2016 14:46:55 -0400 Subject: the global keyword: In-Reply-To: References: <1465689049.1080307.634938641.5F600BCB@webmail.messagingengine.com> Message-ID: <1465757215.2765181.635400889.38EA07BA@webmail.messagingengine.com> On Sat, Jun 11, 2016, at 23:15, Lawrence D?Oliveiro wrote: > On Sunday, June 12, 2016 at 11:51:11 AM UTC+12, Random832 wrote: > > Importing a variable from a module copies its value into your own > > module's variable. > > Every name in Python is a variable, and can be assigned to to change its > value at any time. Sure, but that doesn't really help explain this situation, since your statement doesn't make clear the fact that by importing foo.a into bar you are really merely assigning to bar.a rather than having continuous access to foo.a, unlike how importing things works in static languages. From random832 at fastmail.com Sun Jun 12 14:47:40 2016 From: random832 at fastmail.com (Random832) Date: Sun, 12 Jun 2016 14:47:40 -0400 Subject: the global keyword: Message-ID: <1465757260.2765216.635400889.237B0FEB@webmail.messagingengine.com> On Sat, Jun 11, 2016, at 23:15, Lawrence D?Oliveiro wrote: > On Sunday, June 12, 2016 at 11:51:11 AM UTC+12, Random832 wrote: > > Importing a variable from a module copies its value into your own > > module's variable. > > Every name in Python is a variable, and can be assigned to to change its > value at any time. Sure, but that doesn't really help explain this situation, since your statement doesn't make clear the fact that by importing foo.a into bar you are really merely assigning to bar.a rather than having continuous access to foo.a, unlike how importing things works in static languages. From fillmore_remove at hotmail.com Sun Jun 12 14:55:57 2016 From: fillmore_remove at hotmail.com (Fillmore) Date: Sun, 12 Jun 2016 14:55:57 -0400 Subject: loading trees... Message-ID: Hi, problem for today. I have a batch file that creates "trees of data". I can save these trees in the form of python code or serialize them with something like pickle. I then need to run a program that loads the whole forest in the form of a dict() where each item will point to a dynamically loaded tree. What's my best way to achieve this? Pickle? or creating curtom python code? or maybe I am just reinventing the wheel and there are better ways to achieve this? The idea is that I'll receive a bit of data, determine which tree is suitable for handling it, and dispatch the data to the right tree for further processing... Thanks From mrak at sightlineinnovation.com Sun Jun 12 14:56:18 2016 From: mrak at sightlineinnovation.com (Marcin Rak) Date: Sun, 12 Jun 2016 11:56:18 -0700 (PDT) Subject: base64.b64encode(data) Message-ID: Hi to everyone. Let's say I have some binary data, be it whatever, in the 'data' variable. After calling the following line b64_encoded_data = base64.b64encode(data) my b64_encoded_data variables holds, would you believe it, a string as bytes!. That is, the b64_encoded_data variable is of type 'bytes' and when you peek inside it's a string (made up of what seems to be only characters that exist in Base 64). Why isn't it a string yet? In fact, I now on that variable have to apply the decode('utf-8') method to get a string object holding the exact same sequence of characters as was held by b64_encoded_data bytes variable. I'm a little confused as to why I would even have to apply the .decode('utf-8') method - why doesn't base64.b64encode provide us with a result that is a 'str'? From bc at freeuk.com Sun Jun 12 15:07:52 2016 From: bc at freeuk.com (BartC) Date: Sun, 12 Jun 2016 20:07:52 +0100 Subject: the global keyword: In-Reply-To: References: Message-ID: On 12/06/2016 00:44, Marcin Rak wrote: > Hi to all. > > I have the following file named Solver.py: > ***************************************** > from Test import some_function, my_print > from Test import test_var > > some_function() > my_print() > print(test_var) > ***************************************** > > and I have the following Test.py: > ***************************************** > test_var = 5 > > def some_function(): > global test_var > test_var = 44 > print("f {0}".format(test_var)) > > def my_print(): > print(test_var) > ***************************************** > > Would you believe it that when I run Solver.py I get the following output: > f 44 > 44 > 5 > > So my question is, how the heck is it possible that I get 5 as the last value printed? the global test_var (global to Test.py) I set to 44 when I ran some_function()??? does anyone have a clue they could throw my way? I was puzzled too. Apparently importing stuff using 'from': from Test import a,b,c is equivalent to: import Test a = Test.a b = Test.b c = Test.c which I hadn't been aware of. Then the link between a and Test.a (eg. Test.test_var) is broken (unless Test.a is something like a list so both still refer to the same data. But assignment to either - not an in-place mod - will break the connection). Your code could be rewritten as: from Test import some_function, my_print import Test some_function() my_print() print(Test.test_var) Anyway, it shows Python doesn't have true cross-module globals. -- Bartc From marko at pacujo.net Sun Jun 12 15:08:54 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 12 Jun 2016 22:08:54 +0300 Subject: how to handle surrogate encoding: read from fs write to database References: <575d92d2$0$1605$c3e8da3$5496439d@news.astraweb.com> <1465754384.2757439.635371065.0CA15995@webmail.messagingengine.com> Message-ID: <87a8iq1ayh.fsf@elektro.pacujo.net> Random832 : > On Sun, Jun 12, 2016, at 12:50, Steven D'Aprano wrote: >> I think Windows also gets it almost write: NTFS uses UTF-16, and (I >> think) only allow valid Unicode file names. > > Nope. Windows allows any sequence of 16-bit units (except for a dozen or > so ASCII characters) in filenames. Also, somewhat related, Python allows strings to contain non-Unicode code points, namely code points in the surrogate hole. Thus, Python's native character set is a superset of Unicode. Marko From ned at nedbatchelder.com Sun Jun 12 15:25:46 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 12 Jun 2016 12:25:46 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: Message-ID: On Sunday, June 12, 2016 at 3:08:01 PM UTC-4, BartC wrote: > On 12/06/2016 00:44, Marcin Rak wrote: > > Hi to all. > > > > I have the following file named Solver.py: > > ***************************************** > > from Test import some_function, my_print > > from Test import test_var > > > > some_function() > > my_print() > > print(test_var) > > ***************************************** > > > > and I have the following Test.py: > > ***************************************** > > test_var = 5 > > > > def some_function(): > > global test_var > > test_var = 44 > > print("f {0}".format(test_var)) > > > > def my_print(): > > print(test_var) > > ***************************************** > > > > Would you believe it that when I run Solver.py I get the following output: > > f 44 > > 44 > > 5 > > > > So my question is, how the heck is it possible that I get 5 as the last value printed? the global test_var (global to Test.py) I set to 44 when I ran some_function()??? does anyone have a clue they could throw my way? > > I was puzzled too. Apparently importing stuff using 'from': > > from Test import a,b,c > > is equivalent to: > > import Test > > a = Test.a > b = Test.b > c = Test.c > > which I hadn't been aware of. Then the link between a and Test.a (eg. > Test.test_var) is broken (unless Test.a is something like a list so both > still refer to the same data. But assignment to either - not an in-place > mod - will break the connection). Just to clarify: there is no link directly between a and Test.a, except that both refer to the same object. Just as here there is no link between x and y: x = 12 y = x As I explained elsewhere in this thread, import statements behave exactly like assignments. The same reasoning that applies to multiple variables referring to integers applies to multiple names being imported across modules. --Ned. From marko at pacujo.net Sun Jun 12 15:26:43 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 12 Jun 2016 22:26:43 +0300 Subject: base64.b64encode(data) References: Message-ID: <871t421a4s.fsf@elektro.pacujo.net> Marcin Rak : > b64_encoded_data = base64.b64encode(data) > > my b64_encoded_data variables holds, would you believe it, a string as > bytes!. It doesn't much matter one way or another. The logic is that whenever you encode objects, you typically want the output as bytes. However, it's trivial to decode the bytes into a string if that's what you need. Marko From bc at freeuk.com Sun Jun 12 17:10:30 2016 From: bc at freeuk.com (BartC) Date: Sun, 12 Jun 2016 22:10:30 +0100 Subject: the global keyword: In-Reply-To: References: Message-ID: On 12/06/2016 20:25, Ned Batchelder wrote: > On Sunday, June 12, 2016 at 3:08:01 PM UTC-4, BartC wrote: >> On 12/06/2016 00:44, Marcin Rak wrote: >>> from Test import some_function, my_print >>> from Test import test_var >>> >>> some_function() >>> my_print() >>> print(test_var) >>> ***************************************** >>> >>> and I have the following Test.py: >>> ***************************************** >>> test_var = 5 >> from Test import a,b,c >> >> is equivalent to: >> >> import Test >> >> a = Test.a >> b = Test.b >> c = Test.c >> >> which I hadn't been aware of. Then the link between a and Test.a (eg. >> Test.test_var) is broken (unless Test.a is something like a list so both >> still refer to the same data. But assignment to either - not an in-place >> mod - will break the connection). > > Just to clarify: there is no link directly between a and Test.a, except that > both refer to the same object. OK, but I meant the link there have been if 'a' was in fact a synonym for Test.a. Just as here there is no link between x > and y: > > x = 12 > y = x (And that's a good illustration of why 'y' isn't a name reference to 'x', referring to the "...ducks limp" thread. But best not to rake it up again...) -- bartc From alzi at capella.uberspace.de Sun Jun 12 17:39:02 2016 From: alzi at capella.uberspace.de (Marc Dietz) Date: Sun, 12 Jun 2016 21:39:02 +0000 (UTC) Subject: Indentation example? References: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> Message-ID: On Sun, 12 Jun 2016 08:10:27 -0700 ICT Ezy wrote: > Pl explain with an example the following phase "Indentation cannot be > split over multiple physical lines using backslashes; the whitespace up > to the first backslash determines the indentation" (in 2.1.8. > Indentation of Tutorial.) > I want to teach my student that point using some examples. > Pl help me any body? Hi! This is my very first post inside the usenet. I hope I did understand this right, so here is my answer. :) I assume, that you do understand the concept of indentation inside Python code. You can concatenate lines with a backslash. These lines work as if they were only one line. For example: >>> print ("This is a very long"\ ... " line, that got "\ ... "diveded into three lines.") This is a very long line, that was diveded into three. >>> Because the lines get concatenated, one might think, that you could divide for example 16 spaces of indentation into one line of 8 spaces with a backslash and one line with 8 spaces and the actual code. Your posted text tells you though, that you can't do this. Instead the indentation would be considered to be only 8 spaces wide. I hope this helped a little. :) Cheers Marc. From michael.selik at gmail.com Sun Jun 12 21:10:19 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 13 Jun 2016 01:10:19 +0000 Subject: loading trees... In-Reply-To: References: Message-ID: On Sun, Jun 12, 2016 at 3:01 PM Fillmore wrote: > What's my best way to achieve this? > What are your criteria for "best"? > The idea is that I'll receive a bit of data, determine which tree is > suitable for handling it, and dispatch the data to the right tree for > further processing. > How do you determine which tree is suitable? Does it require knowledge of the whole tree? How big are the trees? How long does pickle take to load those trees? How frequently does data arrive? How long does it take you to determine the tree? How long is acceptable? From jobmattcon at gmail.com Sun Jun 12 21:35:35 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Sun, 12 Jun 2016 18:35:35 -0700 (PDT) Subject: yatel install error Message-ID: <3ee14fa3-6fec-4402-af48-fa1fc6839313@googlegroups.com> sudo apt-get install python-dev libatlas-base-dev gfortran pip install yatel Cleaning up... Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_martin/yatel/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-HwGsHy-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_martin/yatel Traceback (most recent call last): File "/usr/bin/pip", line 9, in load_entry_point('pip==1.5.4', 'console_scripts', 'pip')() File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 235, in main return command.main(cmd_args) File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 161, in main text = '\n'.join(complete_log) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72: ordinal not in range(128) From jobmattcon at gmail.com Sun Jun 12 21:38:36 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Sun, 12 Jun 2016 18:38:36 -0700 (PDT) Subject: how to use yatel with redis? Message-ID: <98a02b3d-d95b-43ab-b6b7-1ad06ab99068@googlegroups.com> my code is https://gist.github.com/hoyeunglee/58df4c41a63a2f37e153cbdbc03c16bf would like to apply itertools.combinations to use redis to use hard disk as memory rather than using ram(real memory) as memory def edge_gen(self): # we combine haplotypes by two for hap0, hap1 in itertools.combinations(self.haplotypes_cache.values(), 2): w = weight.weight("hamming", hap0, hap1) haps_id = hap0.hap_id, hap1.hap_id yield dom.Edge(w, haps_id) From steve at pearwood.info Sun Jun 12 22:12:09 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 13 Jun 2016 12:12:09 +1000 Subject: for / while else doesn't make sense References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> Message-ID: <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jun 2016 04:44 am, Michael Selik wrote: > On Sun, Jun 12, 2016 at 6:11 AM Steven D'Aprano < > steve+comp.lang.python at pearwood.info> wrote: > >> - run the for block >> - THEN unconditionally run the "else" block >> > > Saying "unconditionally" is a bit misleading here. As you say, it's > conditioned on completing the loop without break/return/raise. It's also conditional on the OS not killing the Python process, conditional on the CPU not catching fire, conditional on the user not turning the power of, and conditional on the sun not exploding and disintegrating the entire earth. In the absence of any event which interferes with the normal execution of code by the Python VM, and in the absence of one of a very few explicit "JUMP" statements which explicitly jump out of the compound for...else statement, the else clause is unconditionally executed after the for clause. Happy now? -- Steven From steve at pearwood.info Sun Jun 12 22:22:40 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 13 Jun 2016 12:22:40 +1000 Subject: base64.b64encode(data) References: Message-ID: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jun 2016 04:56 am, Marcin Rak wrote: > Hi to everyone. > > Let's say I have some binary data, be it whatever, in the 'data' variable. > After calling the following line > > b64_encoded_data = base64.b64encode(data) > > my b64_encoded_data variables holds, would you believe it, a string as > bytes!. That's because base64 is a bytes-to-bytes transformation. It has nothing to do with unicode encodings. > That is, the b64_encoded_data variable is of type 'bytes' and when you > peek inside it's a string (made up of what seems to be only characters > that exist in Base 64). If you print or otherwise display bytes, for the convenience of human beings, those bytes are displayed as if they were ASCII. E.g. the byte 0x61 is displayed as 'a'. Good idea? Bad idea? I can see arguments either way, but that's how it is. Naturally after base64 encoding some bytes, you will be left with only bytes in base64. That's the whole point of it. > Why isn't it a string yet? *shrug* For backwards compatibility, probably, or for historical reasons, or because the person who write the base64 module thought that this was the most useful behaviour. I can promise you that had he chosen the opposite behaviour, that it returns a str instead of bytes, there would be people complaining "why do I have to use encode('ascii') to get bytes?". > In fact, I now on > that variable have to apply the decode('utf-8') method to get a string > object holding the exact same sequence of characters as was held by > b64_encoded_data bytes variable. You could also use decode('ascii'), which is probably more "correct", as the base64 data shouldn't include anything which isn't ASCII. -- Steven From larry at hastings.org Sun Jun 12 23:16:12 2016 From: larry at hastings.org (Larry Hastings) Date: Sun, 12 Jun 2016 20:16:12 -0700 Subject: [RELEASED] Python 3.4.5rc1 and Python 3.5.2rc1 are now available Message-ID: <575E257C.5020808@hastings.org> On behalf of the Python development community and the Python 3.4 and Python 3.5 release teams, I'm pleased to announce the availability of Python 3.4.5rc1 and Python 3.5.2rc1. Python 3.4 is now in "security fixes only" mode. This is the final stage of support for Python 3.4. All changes made to Python 3.4 since Python 3.4.4 should be security fixes only; conventional bug fixes are not accepted. Also, Python 3.4.5rc1 and all future releases of Python 3.4 will only be released as source code--no official binary installers will be produced. Python 3.5 is still in active "bug fix" mode. Python 3.5.2rc1 contains many incremental improvements over Python 3.5.1. Both these releases are "release candidates". They should not be considered the final releases, although the final releases should contain only minor differences. Python users are encouraged to test with these releases and report any problems they encounter. You can find Python 3.4.5rc1 here: https://www.python.org/downloads/release/python-345rc1/ And you can find Python 3.5.2rc1 here: https://www.python.org/downloads/release/python-352rc1/ Python 3.4.5 final and Python 3.5.2 final are both scheduled for release on June 26th, 2016. Happy Pythoneering, //arry/ From random832 at fastmail.com Sun Jun 12 23:20:57 2016 From: random832 at fastmail.com (Random832) Date: Sun, 12 Jun 2016 23:20:57 -0400 Subject: base64.b64encode(data) In-Reply-To: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> On Sun, Jun 12, 2016, at 22:22, Steven D'Aprano wrote: > That's because base64 is a bytes-to-bytes transformation. It has > nothing to do with unicode encodings. Nonsense. base64 is a binary-to-text encoding scheme. The output range is specifically chosen to be safe to transmit in text protocols. > > That is, the b64_encoded_data variable is of type 'bytes' and when > > you peek inside it's a string (made up of what seems to be only > > characters that exist in Base 64). > > If you print or otherwise display bytes, for the convenience of human > beings, those bytes are displayed as if they were ASCII. E.g. the byte > 0x61 is displayed as 'a'. Good idea? Bad idea? I can see arguments > either way, but that's how it is. There's absolutely no rational basis for choosing "0x41-0x5A, 0x61-0x7A, 0x30-0x39, 0x2B, 0x2F" as the output range except for what characters those values represent in ASCII. And if you needed to smuggle some binary data through an EBCDIC system in the same manner, you would naturally wish to convert it to the EBCDIC bytes corresponding to those same characters. From jobmattcon at gmail.com Sun Jun 12 23:29:35 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Sun, 12 Jun 2016 20:29:35 -0700 (PDT) Subject: how to search item in list of list Message-ID: <3bbfd254-93a8-4fb2-b110-8f9cc9f62d98@googlegroups.com> once a nested list have a word "node" then true else false def search(current_item): if isinstance(current_item, list): if len(current_item)==4: if [item for item in current_item if item[4] == "node"] != []: return True if True in [search(item) for item in current_item]: return True else: return False search(mresult) but it return false mresult = [[(2, {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {'11': 1, '10': 1, '00': 0, '01': 1} , ['000', '001', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2 , {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100', '101 ', '110', '111'], 'xz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, [' 000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {' 11': 1, '10': 0, '00': 0, '01': 0}, ['000', '001', '010', '011', '100', '101', ' 110', '111'], 'yz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, ['000' , '001', '010', '011', '100', '101', '110', '111'], 'xz', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110' , '111'], 'xy', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '0 01', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110', '1 11'], 'xz', 'start')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '01', ' 11', '11', '10', '11', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00' : 0, '01': 1}, ['00', '01', '10', '11', '11', '11', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '10', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '11', '10', '10', '10', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '11', '10', '11'], 'xy', 'n ode')]] From benjamin at python.org Sun Jun 12 23:35:25 2016 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 12 Jun 2016 20:35:25 -0700 Subject: [RELEASE] Python 2.7.12 release candidate 1 Message-ID: <1465788925.287521.635663601.5B6BD6AA@webmail.messagingengine.com> Python 2.7.12 release candidate 1 is now available for download. This is a preview release of the next bugfix release in the Python 2.7.x series. Assuming no horrible regressions are located, a final release will follow in two weeks. Downloads for 2.7.12rc1 can be found python.org: https://www.python.org/downloads/release/python-2712rc1/ The complete changelog may be viewed at https://hg.python.org/cpython/raw-file/v2.7.12rc1/Misc/NEWS Please test the pre-release and report any bugs to https://bugs.python.org Servus, Benjamin From rustompmody at gmail.com Sun Jun 12 23:46:04 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 12 Jun 2016 20:46:04 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, June 13, 2016 at 7:42:25 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 13 Jun 2016 04:44 am, Michael Selik wrote: > > > On Sun, Jun 12, 2016 at 6:11 AM Steven D'Aprano wrote: > > > >> - run the for block > >> - THEN unconditionally run the "else" block > >> > > > > Saying "unconditionally" is a bit misleading here. As you say, it's > > conditioned on completing the loop without break/return/raise. > > It's also conditional on the OS not killing the Python process, conditional > on the CPU not catching fire, conditional on the user not turning the power > of, and conditional on the sun not exploding and disintegrating the entire > earth. > > In the absence of any event which interferes with the normal execution of > code by the Python VM, and in the absence of one of a very few > explicit "JUMP" statements which explicitly jump out of the compound > for...else statement, the else clause is unconditionally executed after the > for clause. > > Happy now? Wholesale business of strawmen doing brisk business? From alanqueiros at gmail.com Sun Jun 12 23:55:55 2016 From: alanqueiros at gmail.com (alanqueiros at gmail.com) Date: Sun, 12 Jun 2016 20:55:55 -0700 (PDT) Subject: Overriding methods inherited from a superclass with methods from a mixin Message-ID: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> Hello there. I'm trying to override methods inherited from a superclass by methods defined in a mixin class. Here's an sscce: https://bpaste.net/show/6c7d8d590658 (never expires) I've had problems finding the proper way to do that, since at first the base class wasn't to the right and I've assumed the correct order was from left to right. It was previously suggested on IRC that the mixin should be a subclass of "Base"; that worked but I wasn't happy with it because the B class basically serves the purpose of "holding" a list of methods to be inherited and that should override the methods inherited from the "A" classes, so I didn't see why it should derive from "Base". I eventually found in an article that the problem was the ordering of the superclasses I was deriving from, which should be from right to left, the only article I could find that states that is this one: https://www.ianlewis.org/en/mixins-and-python Every single example of mixins in Python that I've read -except that one- (and I've seen literally dozens) has the base class to the left, although the other classes aren't overriding any methods (at least in most of them). That bpaste code is working perfectly for me and makes sense, but I don't really like it, and the people on IRC couldn't convince me the code is fine. I haven't used Python for some time so I don't feel confident to judge that code, and perhaps there's a better way to achieve that result. However, what really scared me is the obscurity of the mixins usage in Python, and the fact that every example except that single one gets it "wrong", including from notable pythonistas. Perhaps you guys could help me either convincing me that the bpaste code is OK, or perhaps coming up with a better solution for that problem. What matters to me is code re-usability in this case. I surely could re-implement the overrides in all "Z" classes separately, but that's what I'm trying to avoid. The requirements are: 1. I can't touch the "classes I don't have control over" (as per comment in code). 2. I don't want to pass the superclasses as parameters in the constructor. I see how you could solve the problem that way, but that would only increase the complexity of the code (PEP20). 3. I absolutely need to override methodX, I can't use composition and access the members another way unless I override methodX and access them there. This is to interface properly with other modules. 4. I need to be able to access A#.methodX in the "Z" classes methods. 5. I want to avoid using a factory. It's one of the most over-used patterns in my opinion, and I really don't like that. Please note that the bpaste code is just an example. The real problem is much bigger and involves multiple methods to override and more classes, so the solution has to scale accordingly. Thank you in advance. From jussi.piitulainen at helsinki.fi Mon Jun 13 01:13:43 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 13 Jun 2016 08:13:43 +0300 Subject: how to search item in list of list References: <3bbfd254-93a8-4fb2-b110-8f9cc9f62d98@googlegroups.com> Message-ID: meInvent bbird writes: > once a nested list have a word "node" then true else false > > def search(current_item): > if isinstance(current_item, list): > if len(current_item)==4: > if [item for item in current_item if item[4] == "node"] != []: > return True > if True in [search(item) for item in current_item]: > return True > else: > return False > > search(mresult) > > but it return false Your mresult is not really nested in the way you are trying to treat it. It looks like a list of lists of length 1, always containing a tuple of length 5, where the last element is a string that may be 'node'. You could just test each top-level item for item[0][4] == 'node'. (It might help to make your case analysis more explicit. Now there's an implicit return if current_item is not a list, and a fall-through to another test if the length of current_item is 4. The structure of the function should match the structure of the data.) Below is the output of pprint.pprint(mresult). Much easier to read (also less likely to break in transit - I had to fix an unfortunate line break to make the original valid Python at all). [[(2, {'00': 0, '01': 1, '10': 1, '11': 1}, ['000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {'00': 0, '01': 1, '10': 1, '11': 1}, ['000', '001', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2, {'00': 0, '01': 1, '10': 1, '11': 1}, ['000', '001', '010', '011', '100', '101 ', '110', '111'], 'xz', 'start')], [(2, {'00': 0, '01': 0, '10': 0, '11': 1}, ['000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {' 11': 1, '00': 0, '01': 0, '10': 0}, ['000', '001', '010', '011', '100', '101', ' 110', '111'], 'yz', 'start')], [(2, {'00': 0, '01': 0, '10': 0, '11': 1}, ['000', '001', '010', '011', '100', '101', '110', '111'], 'xz', 'start')], [(2, {'00': 1, '01': 1, '10': 0, '11': 1}, ['000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {'00': 1, '01': 1, '10': 0, '11': 1}, ['000', '0 01', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2, {'00': 1, '01': 1, '10': 0, '11': 1}, ['000', '001', '010', '011', '100', '101', '110', '1 11'], 'xz', 'start')], [(1, {'00': 0, '01': 1, '10': 1, '11': 1}, ['00', '01', ' 11', '11', '10', '11', '11', '11'], 'xy', 'node')], [(1, {'00': 0, '01': 1, '10': 1, '11': 1}, ['00', '01', '10', '11', '11', '11', '11', '11'], 'xy', 'node')], [(1, {'00': 0, '01': 1, '10': 1, '11': 1}, ['00', '00', '10', '10', '10', '10', '11', '11'], 'xy', 'node')], [(1, {'00': 0, '01': 1, '10': 1, '11': 1}, ['00', '00', '10', '11', '10', '10', '10', '11'], 'xy', 'node')], [(1, {'00': 0, '01': 1, '10': 1, '11': 1}, ['00', '00', '10', '10', '10', '11', '10', '11'], 'xy', 'node')]] From steve at pearwood.info Mon Jun 13 01:16:05 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 13 Jun 2016 15:16:05 +1000 Subject: base64.b64encode(data) References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> Message-ID: <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jun 2016 01:20 pm, Random832 wrote: > On Sun, Jun 12, 2016, at 22:22, Steven D'Aprano wrote: >> That's because base64 is a bytes-to-bytes transformation. It has >> nothing to do with unicode encodings. > > Nonsense. base64 is a binary-to-text encoding scheme. The output range > is specifically chosen to be safe to transmit in text protocols. "Safe to transmit in text protocols" surely should mean "any Unicode code point", since all of Unicode is text. What's so special about the base64 ones? Well, that depends on your context. For somebody who cares about sending bits over a physical wire, their idea of "text" is not Unicode, but a subset of ASCII *bytes*. The end result is that after you've base64ed your "binary" data, to get "text" data, what are you going to do with is? Treat it as Unicode code points? Probably not. Squirt it down a wire as bytes? Almost certainly. Looking at this from the high-level perspective of Python, that makes it conceptually bytes not text. Yes, I know that there's a terminology clash between communication engineers and the programmers who work in their world, and the rest of us. We use "text" to mean Unicode[1], they use "text" to mean "roughly 100 of the 128 bytes with the high-bit cleared, interpreted as ASCII". But those folks are unlikely to be asking why base64 encoding a bunch of bytes returns bytes. They *want* it to return bytes, because that's what they're going to squirt down the wire. If you gave them Unicode, encoded using (say) UTF-16 or UTF-32, they're likely to say "WTF are you giving me this binary data for? Look at all these NUL bytes, what am I supposed to do with them?!?!". (If they could cope with arbitrary bytes, they wouldn't have base64 encoded it.) And if you gave them UTF-8, well, how would anyone know? With base64 encoded data, it's all a subset of ASCII. Python defines a nice clean separation between text (Unicode) and binary data (bytes). Under that model, base64 is a transformation between unrestricted bytes 0...255 to a restricted subset of bytes that matches some ASCII encoded text. It shouldn't return a Unicode string, because that's an abstract text format and we can't make any assumptions about the implementation. Say you base64 encode some binary data: py> base64.b64encode(b'\x01A\x11\x16') b'AUERFg==' Suppose instead it returned the Unicode string 'AUERFg=='. That's all well and good, but what are you going to do with it? You can't transmit it over a serial cable, because that almost surely is going to expect bytes, so you have to encode it. You can't embed it in an email, because that also expects bytes. You could write it to a file. If the file is opened in binary mode, you have to encode the Unicode string to bytes before you can write it. If the file is opened in text mode, Python will accept your Unicode string and encode it for you, which could introduce non-base64 characters into the file. Consider if the file was opened using UTF-16: \x00A\x00U\x00E\x00R\x00F\x00g\x00=\x00= hardly counts as base64 in any meaningful sense. So while I complete accept your comment about "text protocols" in the context of the networking world, we're not in the networking world. We're in the high-level programming language world of Python, where text does not mean a subset of ASCII bytes, it means Unicode. And in *our* world, having base64 return text is a mistake. [1] Or at least we should, since the idea that only American English[2] counts as text cannot possibly survive in the 21st Century when we're connected to the entire world of different languages. Although I'd allow TRON as well, if you can actually find any TRON users outside of Japan.[3] [2] And only a subset of American English at that. [3] Or inside Japan for that matter. -- Steven From random832 at fastmail.com Mon Jun 13 01:33:13 2016 From: random832 at fastmail.com (Random832) Date: Mon, 13 Jun 2016 01:33:13 -0400 Subject: base64.b64encode(data) In-Reply-To: <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465795993.2881334.635716385.023A423E@webmail.messagingengine.com> On Mon, Jun 13, 2016, at 01:16, Steven D'Aprano wrote: > Suppose instead it returned the Unicode string 'AUERFg=='. That's all > well and good, but what are you going to do with it? You can't > transmit it over a serial cable, because that almost surely is going > to expect bytes, so you have to encode it. You can't embed it in an > email, because that also expects bytes. Unless you're using a library that expects to receive strings and encode them itself. Such as, in the example you so helpfully provide, a file opened in text mode. > You could write it to a file. If the file is opened in binary mode, > you have to encode the Unicode string to bytes before you can write > it. If the file is opened in text mode, Python will accept your > Unicode string and encode it for you, which could introduce non- > base64 characters into the file. Consider if the file was opened > using UTF-16: > > \x00A\x00U\x00E\x00R\x00F\x00g\x00=\x00= > > hardly counts as base64 in any meaningful sense. Why do you say these things like you assume I will agree with them. It doesn't, in fact, introduce non-base64 characters because base64 characters are *characters*, not *bytes* and UTF-16 (or EBCDIC or whatever) is a perfectly valid encoding of those *characters*, and the recipient will, naturally, open that file in text mode in the same encoding, and receive the same string, which it can then decode as base64. From marko at pacujo.net Mon Jun 13 02:45:35 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 13 Jun 2016 09:45:35 +0300 Subject: base64.b64encode(data) References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465795993.2881334.635716385.023A423E@webmail.messagingengine.com> Message-ID: <87oa75mvsg.fsf@elektro.pacujo.net> Random832 : > base64 characters are *characters*, not *bytes* Ok, I ran into the same surprise just two days ago. But is this a big deal? Marko From dieter at handshake.de Mon Jun 13 03:06:24 2016 From: dieter at handshake.de (dieter) Date: Mon, 13 Jun 2016 09:06:24 +0200 Subject: loading trees... References: Message-ID: <87fush1sb3.fsf@handshake.de> Fillmore writes: > Hi, problem for today. I have a batch file that creates "trees of data". > I can save these trees in the form of python code or serialize them with something > like pickle. > > I then need to run a program that loads the whole forest in the form of a dict() > where each item will point to a dynamically loaded tree. > > What's my best way to achieve this? Pickle? or creating curtom python code? Not sure about the "best". But one possibility would be to use the "ZODB" ("Zope Object DataBase"). The "ZODB" allows you to store rooted graph like data structures (among them forests) persitently. Nodes in this graph are loaded dynamically (and cached). It would be a bit difficult to use Python "dict"s directly, but the ZODB comes with "dict" like data structures which play well with the ZODB persistency (e.g. "BTrees.OOBTree"). From dieter at handshake.de Mon Jun 13 03:13:54 2016 From: dieter at handshake.de (dieter) Date: Mon, 13 Jun 2016 09:13:54 +0200 Subject: Overriding methods inherited from a superclass with methods from a mixin References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> Message-ID: <87bn351ryl.fsf@handshake.de> alanqueiros at gmail.com writes: > I'm trying to override methods inherited from a superclass by methods defined in a mixin class. > Here's an sscce: > https://bpaste.net/show/6c7d8d590658 (never expires) > > I've had problems finding the proper way to do that, since at first the base class wasn't to the right and I've assumed the correct order was from left to right. The class' MRO ("Method Resolution Order") determines in which order attributes are looked up. Either, you must order your base classes in such a way that the MRO controlled lookup finds the methods you want to be used or you must explicitely put a definition for those methods in your derived class (it may have the form "overridden_method = .overridden_method"). The rules to determine the MRO are complex. The "inspect" module contains a function ("get_mro") to show the MRO of a given class. Use it to get your inheritance order right. From __peter__ at web.de Mon Jun 13 03:59:26 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 13 Jun 2016 09:59:26 +0200 Subject: Overriding methods inherited from a superclass with methods from a mixin References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> Message-ID: alanqueiros at gmail.com wrote: > Hello there. > > I'm trying to override methods inherited from a superclass by methods > defined in a mixin class. Here's an sscce: > https://bpaste.net/show/6c7d8d590658 (never expires) > #the following represents classes I don't have control over > class Base(object): > def methodX(self): > print "methodX class Base" > > class A(Base): #inherits methodX > pass > > class A2(Base): #inherits methodX > pass > > class A3(Base): #inherits methodX > pass > > #the following represents classes I have control over > class B(object): > def methodX(self): > print "methodX class B" > > class Z(B,A): > def methodXfromA(self): > A.methodX(self) > > class Z2(B,A2): > pass > > class Z3(B,A3): > pass > > #what I need is to be able to quickly create these Z classes and override the > #methodX by the functionality in class B, while still being able to call > #class A.methodX > > Z().methodX(); > Z2().methodX(); > Z3().methodX(); > I've had problems finding the proper way to do that, since at first the > base class wasn't to the right and I've assumed the correct order was from > left to right. It was previously suggested on IRC that the mixin should be > a subclass of "Base"; that worked but I wasn't happy with it because the B > class basically serves the purpose of "holding" a list of methods to be > inherited and that should override the methods inherited from the "A" > classes, so I didn't see why it should derive from "Base". > > I eventually found in an article that the problem was the ordering of the > superclasses I was deriving from, which should be from right to left, the > only article I could find that states that is this one: > https://www.ianlewis.org/en/mixins-and-python > > Every single example of mixins in Python that I've read -except that one- > (and I've seen literally dozens) has the base class to the left, although > the other classes aren't overriding any methods (at least in most of > them). > > That bpaste code is working perfectly for me and makes sense, but I don't > really like it, and the people on IRC couldn't convince me the code is > fine. But the code is fine. Write unit tests to ensure that the correct method is called. Usually you use mixins to add methods. In that case the order of base classes doesn't matter. > I haven't used Python for some time so I don't feel confident to judge > that code, and perhaps there's a better way to achieve that result. > However, what really scared me is the obscurity of the mixins usage in > Python, and the fact that every example except that single one gets it > "wrong", including from notable pythonistas. > > Perhaps you guys could help me either convincing me that the bpaste code > is OK, or perhaps coming up with a better solution for that problem. What > matters to me is code re-usability in this case. I surely could > re-implement the overrides in all "Z" classes separately, but that's what > I'm trying to avoid. The requirements are: 1. I can't touch the "classes I > don't have control over" (as per comment in code). 2. I don't want to pass > the superclasses as parameters in the constructor. I see how you could > solve the problem that way, but that would only increase the complexity of > the code (PEP20). 3. I absolutely need to override methodX, I can't use > composition and access the members another way unless I override methodX > and access them there. This is to interface properly with other modules. > 4. I need to be able to access A#.methodX in the "Z" classes methods. 5. I > want to avoid using a factory. It's one of the most over-used patterns in > my opinion, and I really don't like that. That looks like you are actively excluding most alternatives ;) Here's one option that should also work (though I'm not sure if that is what you mean with point 2 of your list): def subclass(base): class Z(base): def methodX(self): print "overridden methodX" return Z Z = subclass(A) Z2 = subclass(A2) > Please note that the bpaste code is just an example. The real problem is > much bigger and involves multiple methods to override and more classes, so > the solution has to scale accordingly. From steve at pearwood.info Mon Jun 13 06:35:33 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 13 Jun 2016 20:35:33 +1000 Subject: base64.b64encode(data) References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465795993.2881334.635716385.023A423E@webmail.messagingengine.com> Message-ID: <575e8c77$0$1599$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jun 2016 03:33 pm, Random832 wrote: > Why do you say these things like you assume I will agree with them. Because I gave you the benefit of the doubt that you were a reasonable person open to good-faith discussion, rather than playing John Cleese's role in your own personal version of the Argument Sketch :-) I don't mind if you say "Well I'm a telecommunications engineer, and when we talk about text protocols, this is what I mean." If I ever find myself in a forum of telco engineers, I'll learn to use their definition too. But this is a Python forum, and Python 3 is a language that tries very, very hard to keep a clean separation between bytes and text, where text is understood to mean Unicode, not a subset of ASCII-encoded bytes. Python 2 was quite happy to let the two categories bleed into each other, with disastrous effects. When I first started using computers, the PC world assumed that "text" meant an ASCII-compatible subset of bytes. One character = one byte, and 'A' meant byte 0x41 (in hex; in decimal it would be 65). Most of our wire protocols make that same assumption, and some older file formats (like HTML) do the same. They're remnants from a bygone age where you could get away with calling the sequence of bytes 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 "text", because everyone[1] agreed on the same interpretation of those bytes, namely "Hello World!". But that's no longer the case, and hasn't been for, well to be honest it was *never* the case that 0x48 unambiguously meant 'H', and it is certainly not the case now. The bottom line is that critical use-cases for base64 involve transmitting bytes, not writing arbitrary Unicode, and that's why the base64 module is treated as a bytes to bytes transformation in Python. You can argue with me all you like, but the docs explicitly call it this: https://docs.python.org/3/library/codecs.html#binary-transforms and even in Python 2 it is called "str to str", where str is understood to be bytes-string, not Unicode: https://docs.python.org/2/library/codecs.html#standard-encodings And besides I've only paid for the ten minute argument. [1] Apart from those guys using IBM mainframes. And people in foreign parts, where they speak weird outlandish languages with bizarre characters, like England. And users of earlier versions of ASCII, or users of variants of ASCII that differ ever so slightly differently. -- Steven From arsh840 at gmail.com Mon Jun 13 06:54:27 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Mon, 13 Jun 2016 03:54:27 -0700 (PDT) Subject: passing dictionay as argument Message-ID: <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> I have to pass dictionary as function argument for following code: import authorize authorize.Configuration.configure( authorize.Environment.TEST, 'api_login_id', 'api_transaction_key', ) result = authorize.Transaction.sale({ 'amount': 40.00, 'credit_card': { 'card_number': '4111111111111111', 'expiration_date': '04/2014', 'card_code': '343', } }) result.transaction_response.trans_id I want to define 'credit-card' dictionary as argument in the function as follows but it returns syntax error: # define dictionary outside the function call: credit_card={ 'card_number': '4111111111111111', 'expiration_date': '04/2014', 'card_code': '343', } import authorize authorize.Configuration.configure( authorize.Environment.TEST, 'api_login_id', 'api_transaction_key', ) result = authorize.Transaction.sale({'amount': 40.00,credit_card}) result.transaction_response.trans_id it returns following error: result = authorize.Transaction.sale({40.00,credit_card}) TypeError: unhashable type: 'dict' Do I need to make changes in authorize.Transaction.sale() source code? From davisein at gmail.com Mon Jun 13 07:22:50 2016 From: davisein at gmail.com (David Navarro) Date: Mon, 13 Jun 2016 13:22:50 +0200 Subject: passing dictionay as argument In-Reply-To: <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> References: <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> Message-ID: To be equivalent to the other one it should be: result = authorize.Transaction.sale({'amount': 40.00, 'credit_card': credit_card}) In this line: result = authorize.Transaction.sale({40.00,credit_card}) You are not putting keys in the dictionary. If there are no keys Python creates a 'set literal'. The error you are seeing is failing to create the set (sets require all their elements to be hashable and dictionaries aren't). If you use the line at the beginning of the mail it should work. On 13 June 2016 at 12:54, Arshpreet Singh wrote: > I have to pass dictionary as function argument for following code: > > > import authorize > > authorize.Configuration.configure( > authorize.Environment.TEST, > 'api_login_id', > 'api_transaction_key', > ) > > result = authorize.Transaction.sale({ > 'amount': 40.00, > > 'credit_card': { > 'card_number': '4111111111111111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > > }) > > result.transaction_response.trans_id > > > > I want to define 'credit-card' dictionary as argument in the function as > follows but it returns syntax error: > > > > # define dictionary outside the function call: > credit_card={ > 'card_number': '4111111111111111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > > import authorize > > authorize.Configuration.configure( > authorize.Environment.TEST, > 'api_login_id', > 'api_transaction_key', > ) > > result = authorize.Transaction.sale({'amount': 40.00,credit_card}) > > result.transaction_response.trans_id > > it returns following error: > > result = authorize.Transaction.sale({40.00,credit_card}) > TypeError: unhashable type: 'dict' > > Do I need to make changes in authorize.Transaction.sale() source code? > -- > https://mail.python.org/mailman/listinfo/python-list > -- David Navarro Estruch From marco.nawijn at colosso.nl Mon Jun 13 07:36:57 2016 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Mon, 13 Jun 2016 04:36:57 -0700 (PDT) Subject: passing dictionay as argument In-Reply-To: <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> References: <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> Message-ID: On Monday, June 13, 2016 at 12:54:45 PM UTC+2, Arshpreet Singh wrote: > I have to pass dictionary as function argument for following code: > > > import authorize > > authorize.Configuration.configure( > authorize.Environment.TEST, > 'api_login_id', > 'api_transaction_key', > ) > > result = authorize.Transaction.sale({ > 'amount': 40.00, > > 'credit_card': { > 'card_number': '4111111111111111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > > }) > > result.transaction_response.trans_id > > > > I want to define 'credit-card' dictionary as argument in the function as follows but it returns syntax error: > > > > # define dictionary outside the function call: > credit_card={ > 'card_number': '4111111111111111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > > import authorize > > authorize.Configuration.configure( > authorize.Environment.TEST, > 'api_login_id', > 'api_transaction_key', > ) > > result = authorize.Transaction.sale({'amount': 40.00,credit_card}) > > result.transaction_response.trans_id > > it returns following error: > > result = authorize.Transaction.sale({40.00,credit_card}) > TypeError: unhashable type: 'dict' > > Do I need to make changes in authorize.Transaction.sale() source code? You explicitly need to specify the key for credit_card in the call to sale(..). I have not run the code myself, but I believe it will work like this: result = authorize.Transaction.sale({'amount': 40.00,'credit_card': credit_card}) From frank at chagford.com Mon Jun 13 07:39:35 2016 From: frank at chagford.com (Frank Millman) Date: Mon, 13 Jun 2016 13:39:35 +0200 Subject: passing dictionay as argument In-Reply-To: <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> References: <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> Message-ID: "Arshpreet Singh" wrote in message news:0b6372ce-3f16-431b-9e72-42d5c935df14 at googlegroups.com... > I have to pass dictionary as function argument for following code: [...] > result = authorize.Transaction.sale({ > 'amount': 40.00, > > 'credit_card': { > 'card_number': '4111111111111111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > [...] > I want to define 'credit-card' dictionary as argument in the function as > follows but it returns syntax error: > > # define dictionary outside the function call: > credit_card={ > 'card_number': '4111111111111111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > [...] > result = authorize.Transaction.sale({'amount': 40.00,credit_card}) Try this - result = authorize.Transaction.sale({'amount': 40.00, 'credit_card':credit_card}) Frank Millman From ian.g.kelly at gmail.com Mon Jun 13 09:17:59 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 13 Jun 2016 07:17:59 -0600 Subject: Overriding methods inherited from a superclass with methods from a mixin In-Reply-To: <87bn351ryl.fsf@handshake.de> References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> <87bn351ryl.fsf@handshake.de> Message-ID: On Mon, Jun 13, 2016 at 1:13 AM, dieter wrote: > alanqueiros at gmail.com writes: > >> I'm trying to override methods inherited from a superclass by methods defined in a mixin class. >> Here's an sscce: >> https://bpaste.net/show/6c7d8d590658 (never expires) >> >> I've had problems finding the proper way to do that, since at first the base class wasn't to the right and I've assumed the correct order was from left to right. > > The class' MRO ("Method Resolution Order") determines in which > order attributes are looked up. > Either, you must order your base classes in such a way that the MRO > controlled lookup finds the methods you want to be used or > you must explicitely put a definition for those methods in your > derived class (it may have the form "overridden_method = .overridden_method"). > > The rules to determine the MRO are complex. The "inspect" module contains > a function ("get_mro") to show the MRO of a given class. Use it > to get your inheritance order right. The details are complex, but there are two fairly simple principles that can be relied upon: 1) Subclasses always appear before their superclasses in the MRO. 2) When a class inherits from multiple base classes, they will always appear in the MRO in the order they appear in the class statement from left-to-right. Note that neither of these rules guarantee that the classes will appear *sequentially* in the MRO. So in the case of mixins, listing the mixin class first is absolutely correct: class Derived(Mixin, Base): pass This ensures that Mixin will always appear before Base in the MRO (and thus override Base's methods) for Derived and for any subclass of Derived. It is possible to concoct elaborate inheritance hierarchies in which it is not possible to come up with an MRO that will satisfy both 1) and 2) above. In such cases, it is also useful to know what Python will do. Fortunately, the answer to that is also simple: the type constructor will throw an exception. So this isn't something that really needs to be worried about. From long.0.yang at gmail.com Mon Jun 13 09:24:38 2016 From: long.0.yang at gmail.com (Long Yang) Date: Mon, 13 Jun 2016 21:24:38 +0800 Subject: Conversion: execfile --> exec Message-ID: The python 2.x command is as following: --------------------------- info = {} execfile(join('chaco', '__init__.py'), info) ------------------------------ But execfile has been removed in python 3.x. So my problem is how to convert the above to a 3.x based command? thanks very much From drekin at gmail.com Mon Jun 13 09:35:30 2016 From: drekin at gmail.com (=?UTF-8?B?QWRhbSBCYXJ0b8Wh?=) Date: Mon, 13 Jun 2016 15:35:30 +0200 Subject: Altering sys.argv on startup in Python 2 Message-ID: Thank you very much, the hook gets invoked at the right place. Adam Barto? From random832 at fastmail.com Mon Jun 13 09:36:06 2016 From: random832 at fastmail.com (Random832) Date: Mon, 13 Jun 2016 09:36:06 -0400 Subject: base64.b64encode(data) In-Reply-To: <575e8c77$0$1599$c3e8da3$5496439d@news.astraweb.com> References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465795993.2881334.635716385.023A423E@webmail.messagingengine.com> <575e8c77$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465824966.3931239.636067473.06E0521B@webmail.messagingengine.com> On Mon, Jun 13, 2016, at 06:35, Steven D'Aprano wrote: > But this is a Python forum, and Python 3 is a language that tries > very, very hard to keep a clean separation between bytes and text, Yes, but that doesn't mean that you're right about which side of that divide base64 output belongs on. > where text is understood to mean Unicode, not a subset of ASCII- > encoded bytes. Sure. But let's not pretend that U+0020 through U+007E *aren't* unicode characters. Base 64's output is characters. Those characters could be encoded as ASCII, as UTF-32, as EBCDIC, and they would still be the same characters. At http://pubs.opengroup.org/onlinepubs/9699919799/utilities/uuencode.html you can see in the rationale section a specific mention of using base64 with EBCDIC, and that the characters are all invariant across all EBCDIC encodings being part of the reason for base64 using the characters it does (as opposed to the historical uuencode algorithm's 0x20 through 0x5F, or as opposed to using some other non-alphanumeric characters than + / =) The fact that many historical standards do mix text with ASCII-encoded bytes and treat them interchangeably, as you said, does that you have to read carefully to see which one they mean. The problem with your argument, though, is that in base64's case it clearly *is* text. For example, from the original privacy-enhanced mail standards - the very first application of base64: RFC 989: "1. (Local_Form) The message text is created (e.g., via an editor) in the system's native character set, with lines delimited in accordance with local convention." RFC 1421: "A plaintext message is accepted in local form, using the host's native character set and line representation." And specifically in its description of base64 ("printable encoding"): "Proceeding from left to right, the bit string resulting from step 3 is encoded into characters which are universally representable at all sites, though not necessarily with the same bit patterns (e.g., although the character "E" is represented in an ASCII-based system as hexadecimal 45 and as hexadecimal C5 in an EBCDIC-based system, the local significance of the two representations is equivalent)." From python at mrabarnett.plus.com Mon Jun 13 10:11:07 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 13 Jun 2016 15:11:07 +0100 Subject: Conversion: execfile --> exec In-Reply-To: References: Message-ID: On 2016-06-13 14:24, Long Yang wrote: > The python 2.x command is as following: > --------------------------- > info = {} > execfile(join('chaco', '__init__.py'), info) > ------------------------------ > > But execfile has been removed in python 3.x. > So my problem is how to convert the above to a 3.x based command? > > thanks very much > Open the file and pass it to exec: info = {} with open(join('chaco', '__init__.py')) as file: exec(file.read(), info) From rustompmody at gmail.com Mon Jun 13 10:31:02 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 13 Jun 2016 07:31:02 -0700 (PDT) Subject: Conversion: execfile --> exec In-Reply-To: References: Message-ID: <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> On Monday, June 13, 2016 at 7:41:33 PM UTC+5:30, MRAB wrote: > On 2016-06-13 14:24, Long Yang wrote: > > The python 2.x command is as following: > > --------------------------- > > info = {} > > execfile(join('chaco', '__init__.py'), info) > > ------------------------------ > > > > But execfile has been removed in python 3.x. > > So my problem is how to convert the above to a 3.x based command? > > > > thanks very much > > > Open the file and pass it to exec: > > info = {} > with open(join('chaco', '__init__.py')) as file: > exec(file.read(), info) I wonder whether this should use importlib instead [yeah really wondering... not a rhetorical question] See slide 38-40 http://www.slideshare.net/pydanny/python-worst-practices From torriem at gmail.com Mon Jun 13 11:15:05 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 13 Jun 2016 09:15:05 -0600 Subject: base64.b64encode(data) In-Reply-To: <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/12/2016 11:16 PM, Steven D'Aprano wrote: > "Safe to transmit in text protocols" surely should mean "any Unicode code > point", since all of Unicode is text. What's so special about the base64 > ones? > > Well, that depends on your context. For somebody who cares about sending > bits over a physical wire, their idea of "text" is not Unicode, but a > subset of ASCII *bytes*. Not necessarily. The encoding of the text containing the results of the base64 encoding does not matter provided the letters and numbers used in base64 can be represented. I could take the text and paste it in an email and send it via UTF-8, or UTF-16. Won't make a difference provided the decoder can deal decode that specific unicode encoding. The other end could even cut and paste the base64 letters and numbers out of his email body and paste it into a decoder. How the letters and numbers got to him is immaterial and irrelevant. Sure in the context of email base64 data is usually sent using UTF-8 encoding these days. But there's no requirement that base64 data always has to be encoded in ASCII, UTF-8, or LATIN1. > The end result is that after you've base64ed your "binary" data, to > get "text" data, what are you going to do with is? Treat it as Unicode code > points? Probably not. Sure. Why not? Write it to a text file. Put it in an email. Place it in a word doc. Print it. Whatever. > Squirt it down a wire as bytes? Almost certainly. Sometimes yes. But not always. > Looking at this from the high-level perspective of Python, that makes it > conceptually bytes not text. I don't see how this is always the case. From a high-level python perspective it's definitely text. That's the whole point of base64! From rosuav at gmail.com Mon Jun 13 13:07:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jun 2016 03:07:35 +1000 Subject: base64.b64encode(data) In-Reply-To: References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jun 14, 2016 at 1:15 AM, Michael Torrie wrote: >> Looking at this from the high-level perspective of Python, that makes it >> conceptually bytes not text. > > I don't see how this is always the case. From a high-level python > perspective it's definitely text. That's the whole point of base64! Maybe what Python needs is an "ascii" type that's a subclass of both str and bytes, and requires that the contents be <0x80. It is text, so it can be combined with text strings; but it is also bytes, so when you combine it with bytes strings, it'll behave as most people expect. ChrisA From michael.selik at gmail.com Mon Jun 13 13:18:06 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 13 Jun 2016 17:18:06 +0000 Subject: Conversion: execfile --> exec In-Reply-To: <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> References: <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> Message-ID: On Mon, Jun 13, 2016, 10:36 AM Rustom Mody wrote: > On Monday, June 13, 2016 at 7:41:33 PM UTC+5:30, MRAB wrote: > > On 2016-06-13 14:24, Long Yang wrote: > > > The python 2.x command is as following: > > > --------------------------- > > > info = {} > > > execfile(join('chaco', '__init__.py'), info) > > > ------------------------------ > > > > > > But execfile has been removed in python 3.x. > > > So my problem is how to convert the above to a 3.x based command? > > > > > > thanks very much > > > > > Open the file and pass it to exec: > > > > info = {} > > with open(join('chaco', '__init__.py')) as file: > > exec(file.read(), info) > > > I wonder whether this should use importlib instead [yeah really > wondering... > not a rhetorical question] > > See slide 38-40 http://www.slideshare.net/pydanny/python-worst-practices The slides you're referencing are saying importlib is better than exec'ing an import. The question of this thread was more general. An import makes a module object, but exec'ing arbitrary source does not (unless it uses import). From michael.selik at gmail.com Mon Jun 13 13:32:30 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 13 Jun 2016 17:32:30 +0000 Subject: Overriding methods inherited from a superclass with methods from a mixin In-Reply-To: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> Message-ID: On Mon, Jun 13, 2016 at 12:01 AM wrote: > I haven't used Python for some time so I don't feel confident to judge > Yet, you are clearly judging the code you pasted as not OK. Perhaps you guys could help me either convincing me that the bpaste code is > OK > It would be helpful for you to explain why you think the code you pasted is not OK. To me it makes sense. English reads left-to-right, so method lookups go left-to-right (and children before parents) in the inheritance list. From rustompmody at gmail.com Mon Jun 13 13:45:50 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 13 Jun 2016 10:45:50 -0700 (PDT) Subject: Conversion: execfile --> exec In-Reply-To: References: <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> Message-ID: <9f4457b3-4f31-4285-ad66-eb4db87b8dd9@googlegroups.com> On Monday, June 13, 2016 at 10:48:33 PM UTC+5:30, Michael Selik wrote: > On Mon, Jun 13, 2016, 10:36 AM Rustom Mody wrote: > > > On Monday, June 13, 2016 at 7:41:33 PM UTC+5:30, MRAB wrote: > > > On 2016-06-13 14:24, Long Yang wrote: > > > > The python 2.x command is as following: > > > > --------------------------- > > > > info = {} > > > > execfile(join('chaco', '__init__.py'), info) > > > > ------------------------------ > > > > > > > > But execfile has been removed in python 3.x. > > > > So my problem is how to convert the above to a 3.x based command? > > > > > > > > thanks very much > > > > > > > Open the file and pass it to exec: > > > > > > info = {} > > > with open(join('chaco', '__init__.py')) as file: > > > exec(file.read(), info) > > > > > > I wonder whether this should use importlib instead [yeah really > > wondering... > > not a rhetorical question] > > > > See slide 38-40 http://www.slideshare.net/pydanny/python-worst-practices > > > The slides you're referencing are saying importlib is better than exec'ing > an import. The question of this thread was more general. An import makes a > module object, but exec'ing arbitrary source does not (unless it uses > import). True but the supplied code: info = {} execfile(join('chaco', '__init__.py'), info) looks (to me) like an intent to import the package chaco with no locals and globals -- Just guessing of course From alanqueiros at gmail.com Mon Jun 13 14:42:44 2016 From: alanqueiros at gmail.com (alanqueiros at gmail.com) Date: Mon, 13 Jun 2016 11:42:44 -0700 (PDT) Subject: Overriding methods inherited from a superclass with methods from a mixin In-Reply-To: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> Message-ID: <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> Thank you for your replies. I don't know if I'm quoting you correctly, I'm quite confused with Google Groups... not sure if it's a "forum", something like a mailing list, or both... or neither. > The class' MRO ("Method Resolution Order") determines in which > order attributes are looked up. > Either, you must order your base classes in such a way that the MRO > controlled lookup finds the methods you want to be used or > you must explicitely put a definition for those methods in your > derived class (it may have the form "overridden_method = .overridden_method"). > > The rules to determine the MRO are complex. The "inspect" module contains > a function ("get_mro") to show the MRO of a given class. Use it > to get your inheritance order right. OK, I'm going to read about the MRO rules. Thanks for the heads up on the inspect module. ---- > But the code is fine. Write unit tests to ensure that the correct method is > called. > > Usually you use mixins to add methods. In that case the order of base > classes doesn't matter. Yeah, I see that in most cases the order doesn't matter, but still I would think that since the correct order is from right to left, that should be the common practice. What if later on you want to expand a mixin and actually override a method? That could cause a situation that's a hell to debug, so people should just get used to keeping their (most) "base" classes to the right when doing multiple inheritance in my opinion. > That looks like you are actively excluding most alternatives ;) > > Here's one option that should also work (though I'm not sure if that is what > you mean with point 2 of your list): > > def subclass(base): > class Z(base): > def methodX(self): > print "overridden methodX" > return Z > > Z = subclass(A) > Z2 = subclass(A2) > Yes, that violates the second item :). That would increase the complexity of the code because I would need to know which A to use when instantiating the classes, and what I'm doing is exactly to simplify the usage of those classes. Of course some docs and perhaps a well tailored enum (or alike) to be passed as the parameter could help, but a factory could do just as well, however, that isn't going to fulfill my needs at all, and since I'm the one who's going to use the code most of the time, I don't care much about using something somewhat "unconventional". ---- > The details are complex, but there are two fairly simple principles > that can be relied upon: > > 1) Subclasses always appear before their superclasses in the MRO. > 2) When a class inherits from multiple base classes, they will always > appear in the MRO in the order they appear in the class statement from > left-to-right. > > Note that neither of these rules guarantee that the classes will > appear *sequentially* in the MRO. > > So in the case of mixins, listing the mixin class first is absolutely correct: > > class Derived(Mixin, Base): pass > > This ensures that Mixin will always appear before Base in the MRO (and > thus override Base's methods) for Derived and for any subclass of > Derived. > > It is possible to concoct elaborate inheritance hierarchies in which > it is not possible to come up with an MRO that will satisfy both 1) > and 2) above. In such cases, it is also useful to know what Python > will do. Fortunately, the answer to that is also simple: the type > constructor will throw an exception. So this isn't something that > really needs to be worried about. That's some very nice information you got there. I also like how Ian Lewis explained that, it may not be very technical and perhaps that "logic" is accidental, but it surely helps you remember the correct order when doing multiple inheritance. (That part about forgetting the brackets and thinking of the code as a lined-up hierarchy, so MyClass => Mixin2 => Mixin1 => BaseClass). In my opinion Python users should get used to that order. It doesn't matter if *atm* you're not overriding, if that's the correct way to do it, you should get used to it in my opinion because who know how you may need/want to expand your code in the future. Still, pretty much *no one* uses that order. A quick Google search returns (at least in my "bubble") many blog articles from "notable" Python users with that order wrong. As long as I can rely on that it's OK for me. I couldn't find anything "official" on that subject though (mixins that override). ---- > Yet, you are clearly judging the code you pasted as not OK. Actually, I didn't say (hard and fast) the code wasn't OK (if memory serves), I said I didn't like it -on a first superficial analysis-. Especially due the lack of recent experience with Python I was afraid I wasn't seeing some obvious caveat, thus I've basically asked you guys to tell me if the code is or isn't OK. > It would be helpful for you to explain why you think the code you pasted is > not OK. To me it makes sense. English reads left-to-right, so method > lookups go left-to-right (and children before parents) in the inheritance > list. Basically I wasn't very confident the code was OK because my intuition said the right way to order the classes I was inheriting from was from left to right. I don't see any sense in that analogy you made... sure English and most occidental languages read ltr, but I fail to see how it makes more sense to have the base class on the right and the mixins on the left. Basically, I think of the mixins like plugins of kinds, I'm "adding" functionality to that "base" class I'm inheriting from. Having them to the left sounds like a sandwich recipe that tells you to "slice the ham, put mayonnaise on it, and put it on the bread". I guess that's a lot to do with everyone's individual intuition sense, but I guess your intuition, albeit more correct for this specific case, is very different from the massive majority of people. Don't take my word for it, Google multi inheritance or mixin in Python and let me know if you find someone who thinks it's "natural" to do it that way. Most people just get that wrong without even knowing, and the only one I could find who gets that right simply states that at first that isn't intuitive at all. So you're the first person I've seen who thinks that's the intuitive way to do it. I'm not complaining or something, I totally don't mind that "rule", and as I said the way Ian put that will surely make it stick to my brain like a scar, but it sure as hell doesn't seem intuitive for me. Thank you guys for the help. I really appreciated it. I'll go with that code because it makes sense for this specific case now I'm convinced it's OK. From michael.selik at gmail.com Mon Jun 13 18:14:19 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 13 Jun 2016 22:14:19 +0000 Subject: Conversion: execfile --> exec In-Reply-To: <9f4457b3-4f31-4285-ad66-eb4db87b8dd9@googlegroups.com> References: <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> <9f4457b3-4f31-4285-ad66-eb4db87b8dd9@googlegroups.com> Message-ID: On Mon, Jun 13, 2016 at 1:51 PM Rustom Mody wrote: > looks (to me) like an intent to import the package chaco with no locals > and globals -- Just guessing of course > And without creating a module object. I suppose that means it doesn't get cached in sys.modules either. Not sure if that's a feature or a bug. From pankaj at openmindtechno.com Mon Jun 13 18:22:42 2016 From: pankaj at openmindtechno.com (pankaj at openmindtechno.com) Date: Mon, 13 Jun 2016 15:22:42 -0700 (PDT) Subject: Looking for Python Engineering Manager or Python experts for world's leading Artificial Intelligence Company in San Francisco,CA Message-ID: <42e66dfd-473a-4b4e-845e-a4a86e5a92bf@googlegroups.com> Hi, I am looking to hire for an excellent opportunity for an Python Engineering Manager or Python experts for world's leading Arti-0878ficial Intelligence Company in San Francisco,CA. Please do refer or contact me at cell 510-396-0878. Both Full time Perm and Contract opportunities are open. Appreciate any help. Thanks so much, Pankaj Director Best Practices Openmind Technologies Inc Cell 510-396-0878. From greg.ewing at canterbury.ac.nz Mon Jun 13 18:28:51 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 14 Jun 2016 10:28:51 +1200 Subject: Overriding methods inherited from a superclass with methods from a mixin In-Reply-To: <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> Message-ID: alanqueiros at gmail.com wrote: > I see that in most cases the order doesn't matter, but still I would > think that since the correct order is from right to left, that should be the > common practice. This order is only "correct" if overriding is what you want. That's not always going to be the case. The mixin might be intended to supply default functionality that can be overridden by the classes it's being mixed into. You can't say that one order is more correct than the other in general. > Basically, I > think of the mixins like plugins of kinds, I'm "adding" functionality to that > "base" class I'm inheriting from. Having them to the left sounds like a > sandwich recipe that tells you to "slice the ham, put mayonnaise on it, and > put it on the bread". To me it's more like adding seasoning to a dish. Normally you put the main ingredient in first, then add the salt and pepper. This is probably the way most people are thinking when they write the mixins after the main base class. -- Greg From michael.selik at gmail.com Mon Jun 13 18:50:50 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 13 Jun 2016 22:50:50 +0000 Subject: Overriding methods inherited from a superclass with methods from a mixin In-Reply-To: <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> Message-ID: On Mon, Jun 13, 2016 at 2:46 PM wrote: > Thank you for your replies. I don't know if I'm quoting you correctly, I'm > quite confused with Google Groups... not sure if it's a "forum", something > like a mailing list, or both... or neither. > Mailing list. A "forum" in the metaphorical sense, not the sense of phpBB. You're doing fine with quoting, though it would help to add who said what when quoting multiple people. since the correct order is from right to left, Did you mean left-to-right? Are you thinking of Java where there's only one parent class allowed and you specify any extra interfaces you're implementing afterwards? Because that's not what your code is doing. Still, pretty much *no one* uses that order [mixin1, mixin2, base]. A quick > Google search returns (at least in my "bubble") many blog articles from > "notable" Python users with that order wrong. > Do you mind providing links? I haven't seen anyone "notable" make this mistake. > > To me it makes sense. English reads left-to-right, so method > > lookups go left-to-right (and children before parents) in the inheritance > > list. > > Basically I wasn't very confident the code was OK because my intuition > said the right way to order the classes I was inheriting from was from left > to right. That is correct! Write them in the order you are prioritizing the definitions. Overrides before bases, left to right. > I don't see any sense in that analogy you made... sure English and most > occidental languages read ltr, but I fail to see how it makes more sense to > have the base class on the right and the mixins on the left. Basically, I > think of the mixins like plugins of kinds, I'm "adding" functionality to > that "base" class I'm inheriting from. That's not a good metaphor for what's actually happening. For more detail, check out Raymond's "super considered super" video ( https://www.youtube.com/watch?v=EiOglTERPEo). > Don't take my word for it, Google multi inheritance or mixin in Python and > let me know if you find someone who thinks it's "natural" to do it that way. This might be a bit of selection bias. People who think it makes sense might not have an incentive to write a blog post about it. People who don't like it will thus be more vocal. Ian Lewis seems to be ranked highly by Google ( https://www.ianlewis.org/en/mixins-and-python). I disagree with his assertion that "most people" read an inheritance hierarchy top-down with the bases at the left. I think of inheritance as a tree. Even if it is a diamond at some point, a depth-first-search of a tree isn't far off from the truth. The root (base) is at the bottom, in my mind, and the leaves are at the top. From greg.ewing at canterbury.ac.nz Mon Jun 13 19:04:40 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 14 Jun 2016 11:04:40 +1200 Subject: base64.b64encode(data) In-Reply-To: References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: Michael Torrie wrote: > On 06/12/2016 11:16 PM, Steven D'Aprano wrote: > >>Squirt it down a wire as bytes? Almost certainly. > > Sometimes yes. But not always. And even when the ultimate destination is a wire, a Python programmer is more likely to be accessing the wire through some high-level interface that accepts the payload to be sent as text in the form of a Python str object. -- Greg From greg.ewing at canterbury.ac.nz Mon Jun 13 19:12:19 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 14 Jun 2016 11:12:19 +1200 Subject: base64.b64encode(data) In-Reply-To: References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > Maybe what Python needs is an "ascii" type that's a subclass of both > str and bytes, and requires that the contents be <0x80. It is text, so > it can be combined with text strings; but it is also bytes, so when > you combine it with bytes strings, it'll behave as most people expect. That would be asking for trouble, I think. It would be letting back in a bit of the text/bytes confusion that Python 3 worked hard to get rid of. What happens if the bytes that you combine it with aren't in an ascii-compatible encoding? Nothing would detect that error. The only thing you might gain is a bit of efficiency by removing some encoding/decoding operations. But since the FSR, these are pretty cheap anyway when the characters are all ascii. They could maybe be made a bit cheaper still by arranging some way for a bytes object and an ascii-only str object to share underlying storage. -- Greg From alanqueiros at gmail.com Mon Jun 13 19:44:18 2016 From: alanqueiros at gmail.com (alanqueiros at gmail.com) Date: Mon, 13 Jun 2016 16:44:18 -0700 (PDT) Subject: Overriding methods inherited from a superclass with methods from a mixin In-Reply-To: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> Message-ID: On Monday, June 13, 2016 at 7:29:05 PM UTC-3, Gregory Ewing wrote: > > I see that in most cases the order doesn't matter, but still I would > > think that since the correct order is from right to left, that should be the > > common practice. > > This order is only "correct" if overriding is what you want. > That's not always going to be the case. The mixin might be > intended to supply default functionality that can be > overridden by the classes it's being mixed into. You > can't say that one order is more correct than the other > in general. Yes, but (I presume) ordering it rtl doesn't have any caveat, and the code gets 'future-proof' in case you want to override a method in a class that's intended to be used as a mixin. I for instance am making an effort to get used to the rtl order as quickly as possible. But sure, in most cases it's probably never going to make a difference. > > Basically, I > > think of the mixins like plugins of kinds, I'm "adding" functionality to that > > "base" class I'm inheriting from. Having them to the left sounds like a > > sandwich recipe that tells you to "slice the ham, put mayonnaise on it, and > > put it on the bread". > > To me it's more like adding seasoning to a dish. Normally > you put the main ingredient in first, then add the salt > and pepper. This is probably the way most people are > thinking when they write the mixins after the main base > class. Exactly. ---- On Monday, June 13, 2016 at 7:51:14 PM UTC-3, Michael Selik wrote: > > Thank you for your replies. I don't know if I'm quoting you correctly, I'm > > quite confused with Google Groups... not sure if it's a "forum", something > > like a mailing list, or both... or neither. > > > > Mailing list. A "forum" in the metaphorical sense, not the sense of phpBB. > You're doing fine with quoting, though it would help to add who said what > when quoting multiple people. > > > since the correct order is from right to left, > > > Did you mean left-to-right? > Are you thinking of Java where there's only one parent class allowed and > you specify any extra interfaces you're implementing afterwards? Because > that's not what your code is doing. Nope, I'm certainly not thinking of interfaces of abstract classes, I'm literally thinking about mixins. > > Still, pretty much *no one* uses that order [mixin1, mixin2, base]. A quick > > Google search returns (at least in my "bubble") many blog articles from > > "notable" Python users with that order wrong. > > > > Do you mind providing links? I haven't seen anyone "notable" make this > mistake. Not at all. Of course the snippets work because they're not overriding, but they all use an 'ltr' order. I feel somewhat bad about posting these links because I don't want to imply the code is wrong or something, since apparently there's no convention on that. So I'm publishing this list with all due respect to the programmers, and this only proves that it's probably more intuitive for most people to put is as [base,mixin]: class Request(BaseRequest, AcceptMixin, ETagRequestMixin, UserAgentMixin, AuthorizationMixin): http://stackoverflow.com/a/547714 class RealTestCase(BaseTestCase, MyMixin): http://nedbatchelder.com/blog/201210/multiple_inheritance_is_hard.html class TextBook(Book, IndexMixin): https://ahal.ca/blog/2014/when-would-you-use-python-mixin/ > > > To me it makes sense. English reads left-to-right, so method > > > > lookups go left-to-right (and children before parents) in the inheritance > > > list. > > > > Basically I wasn't very confident the code was OK because my intuition > > said the right way to order the classes I was inheriting from was from left > > to right. > > That is correct! Write them in the order you are prioritizing the > definitions. Overrides before bases, left to right. I'm sorry but it doesn't seem that obvious to me... It feels like building a house starting from the roof to me. Of course that's entirely subjective. > > I don't see any sense in that analogy you made... sure English and most > > occidental languages read ltr, but I fail to see how it makes more sense to > > have the base class on the right and the mixins on the left. Basically, I > > think of the mixins like plugins of kinds, I'm "adding" functionality to > > that "base" class I'm inheriting from. > > > That's not a good metaphor for what's actually happening. For more detail, > check out Raymond's "super considered super" video ( > https://www.youtube.com/watch?v=EiOglTERPEo). I'm going to take a look. Thank you for the link. > > Don't take my word for it, Google multi inheritance or mixin in Python and > > let me know if you find someone who thinks it's "natural" to do it that way. > > > This might be a bit of selection bias. People who think it makes sense > might not have an incentive to write a blog post about it. People who don't > like it will thus be more vocal. Yes, or maybe it's just my Google results that are biased. > Ian Lewis seems to be ranked highly by Google ( > https://www.ianlewis.org/en/mixins-and-python). > I disagree with his assertion that "most people" read an inheritance > hierarchy top-down with the bases at the left. I think of inheritance as a > tree. Even if it is a diamond at some point, a depth-first-search of a tree > isn't far off from the truth. The root (base) is at the bottom, in my mind, > and the leaves are at the top. Or maybe you're just very used to thinking like that :). I do understand your logic, but it's not something that happen "intuitively" for me. Thank you for your replies. From michael.selik at gmail.com Mon Jun 13 19:45:48 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 13 Jun 2016 23:45:48 +0000 Subject: for / while else doesn't make sense In-Reply-To: <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jun 12, 2016 at 10:16 PM Steven D'Aprano wrote: > On Mon, 13 Jun 2016 04:44 am, Michael Selik wrote: > > > On Sun, Jun 12, 2016 at 6:11 AM Steven D'Aprano < > > steve+comp.lang.python at pearwood.info> wrote: > > > >> - run the for block > >> - THEN unconditionally run the "else" block > >> > > > > Saying "unconditionally" is a bit misleading here. As you say, it's > > conditioned on completing the loop without break/return/raise. > > It's also conditional on the OS not killing the Python process, conditional > on the CPU not catching fire, conditional on the user not turning the power > of, and conditional on the sun not exploding and disintegrating the entire > earth. > > In the absence of any event which interferes with the normal execution of > code by the Python VM, and in the absence of one of a very few > explicit "JUMP" statements which explicitly jump out of the compound > for...else statement, the else clause is unconditionally executed after the > for clause. > > Happy now? > I think most folks assume that their program will not run as expected if the sun explodes. Saying that ``raise``, ``break``, and ``return`` are "one of a very few explicit JUMP statements" implies that they are obscure. Listing them in addition to the sun exploding suggests that you think they are similarly unlikely and should be ignored as too bizarre to consider. In contrast, I think raise, break, and return are quite common. Further, I think you do too, despite what you are trying to imply. Maybe I read the tone wrong. It's tough sometimes to hear someone's tone of voice in email. From michael.selik at gmail.com Mon Jun 13 20:13:38 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 14 Jun 2016 00:13:38 +0000 Subject: Overriding methods inherited from a superclass with methods from a mixin In-Reply-To: References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> Message-ID: On Mon, Jun 13, 2016 at 7:46 PM wrote: > I ... am making an effort to get used to the rtl order as quickly as > possible. > Funny, you keep saying right-to-left. I think the issue is you think the parent class is more important. Fight the power! Youth revolt! In Python, the children are in control. Now you can read it left-to-right, as is natural. I feel somewhat bad about posting these links > The StackOverflow answer had an upvoted comment that the BaseRequest should be written after the Mixins. The two blog posts read like conversation starters. I don't think the authors intended to write model code. A famous textbook getting it wrong would be more interesting. But even Knuth makes mistakes (https://en.wikipedia.org/wiki/Knuth_reward_check). From ben+python at benfinney.id.au Mon Jun 13 20:35:45 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 14 Jun 2016 10:35:45 +1000 Subject: Please use the Python Job Board for recruiting (was: [recruitment message]) In-Reply-To: <42e66dfd-473a-4b4e-845e-a4a86e5a92bf@googlegroups.com> (pankaj@openmindtechno.com's message of "Mon, 13 Jun 2016 15:22:42 -0700 (PDT)") References: <42e66dfd-473a-4b4e-845e-a4a86e5a92bf@googlegroups.com> Message-ID: <8537ogzjxa.fsf@benfinney.id.au> pankaj at openmindtechno.com writes: > I am looking to hire for an excellent opportunity Please do not use this forum for recruiting. Instead, use the Python Job Board maintained for that purpose. -- \ ?The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.? ?Henry L. Mencken | Ben Finney From random832 at fastmail.com Mon Jun 13 21:19:32 2016 From: random832 at fastmail.com (Random832) Date: Mon, 13 Jun 2016 21:19:32 -0400 Subject: base64.b64encode(data) In-Reply-To: References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1465867172.423010.636762145.61A99EF2@webmail.messagingengine.com> On Mon, Jun 13, 2016, at 19:12, Gregory Ewing wrote: > They could maybe be made a bit cheaper still by arranging > some way for a bytes object and an ascii-only str object > to share underlying storage. While we're at it, why not allow bytes to share storage with FSR latin-1 strings and the cached UTF-8 versions of strings? From steve at pearwood.info Mon Jun 13 22:43:35 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 14 Jun 2016 12:43:35 +1000 Subject: for / while else doesn't make sense References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Jun 2016 09:45 am, Michael Selik wrote: > On Sun, Jun 12, 2016 at 10:16 PM Steven D'Aprano > wrote: > >> On Mon, 13 Jun 2016 04:44 am, Michael Selik wrote: >> >> > On Sun, Jun 12, 2016 at 6:11 AM Steven D'Aprano < >> > steve+comp.lang.python at pearwood.info> wrote: >> > >> >> - run the for block >> >> - THEN unconditionally run the "else" block >> >> >> > >> > Saying "unconditionally" is a bit misleading here. As you say, it's >> > conditioned on completing the loop without break/return/raise. >> >> It's also conditional on the OS not killing the Python process, >> conditional on the CPU not catching fire, conditional on the user not >> turning the power of, and conditional on the sun not exploding and >> disintegrating the entire earth. >> >> In the absence of any event which interferes with the normal execution of >> code by the Python VM, and in the absence of one of a very few >> explicit "JUMP" statements which explicitly jump out of the compound >> for...else statement, the else clause is unconditionally executed after >> the for clause. >> >> Happy now? >> > > I think most folks assume that their program will not run as expected if > the sun explodes. On this list, I daresay somebody will insist that if their computer is on one of Jupiter's moons it will keep running fine and therefore I'm wrong. > Saying that ``raise``, ``break``, and ``return`` are "one of a very few > explicit JUMP statements" implies that they are obscure. What? No. How do you get that? If I tell you that Python has only two loop constructs, for and while, would that imply that they are rare and unusual? (Three if you count comprehensions as distinct from the for statement.) Python has only two conditional branches: if...elif..else, and the ternary if operator. Does that make them obscure? raise, break and return are all explicit JUMPs: they transfer execution to some place other than the next executable line. There are others, including continue, but they don't transfer execution past the for loop, so don't matter in this context. None of this implies that they are obscure. I'm sorry if you've never thought of a return or break as a JUMP before, but that's what they are. > Listing them in > addition to the sun exploding suggests that you think they are similarly > unlikely and should be ignored as too bizarre to consider. No. The sun exploding was me gently mocking you for your comment disputing the "unconditional" part. Yes, you are technically right that technically the "else" block will only run if no "break" is reached, and no "return" is reached, no exception is raised, also that os._exit or os.abort aren't called, the CPU doesn't catch fire, and the world isn't destroyed. If we try to enumerate all the things which could prevent the "else" block from running, we'll be here for decades. But, and this is the point that everyone seems to have missed, * every single one of those things* is completely independent of the for...else statement. *Including* the presence or absence of a "break". If you want to understand how Python statements work, you should understand them in isolation (as much as possible), which then allows you to extrapolate their behaviour in combination with other statements. Most lines of Python code are understandable in isolation, or at least close to isolation. You can get *very close* to a full understanding of Python by just reading one line at a time (with perhaps a bit of short term memory to remember if you are compiling a function, building a class, etc). E.g. you don't need to understand for loops to understand if...else. And vice versa: for...else has a well-defined meaning and operates in a simple fashion in isolation of other language features. Its not compulsory to put a "return" statement inside your for loop. Nor is it compulsory to put a "raise" inside it. And "break" is not compulsory either. If you think of for...else as being (in some sense) glued to break, then what are you going to make of code with for...else and no break? That's legal Python code, and somebody will write it, even if only by accident. If you think of for...else as being glued to an if inside the for block, then what are you going to make of code where the if already has an else? Or code that unconditionally breaks inside the loop? Again, that's legal code, even if useless. If you think that the for...else has to match an if inside the loop, you'll have to invent special rules for when there is no if, or ten of them, or they all are already matched with their own elses. If you start thinking of it as code which is run conditionally "only if no break was executed", that leads to people thinking of it in terms of some sort of hidden flag that Python keeps to tell whether or not a break was seen. A month or two ago, we had somebody, mislead by that mental model, asking whether Python should expose that flag so he could write code something like: for x in seq: do_stuff() else: do_something_else() if MAGIC_FLAG: print("break") (I don't quite remember all the details of the poster's question/proposal, but the details aren't important. What's important is that he had a misleading mental model of Python's for...else semantics that lead him to make *incorrect predictions* of what Python can, or will, do.) Somebody else suggested that "else" had the same semantics as "finally", in that it was always executed after the for loop except for the one special case of "break". And that mental model is wrong too. And another poster carefully unrolled the loop to show that the else matched up with the if inside the loop, and completely failed to deal with the case where the if already has a matching else. Or the case where there's no break. There's a simple mental model, one which has the advantage of actually matching the implementation: for...else executes else unconditionally, unless something, *anything*, (break, return, raise, the end of the world) prevents it. As far as I can see, that model works under all possible circumstances, now and in the future: one if or none, or even ten, with or without their own matching elses, break or no break, return, raise, even the end of the world. *wink* If Python 3.6 introduces a GOTO command, then my mental model of for...else doesn't need to change. (Neither will the implementation.) If Python 3.7 decides that functions can only have one exit, out the bottom of the function, and removes the "return" statement, then my mental model of for...else doesn't need to change either. All mental models are imperfect, but I think mine is the least imperfect of all those I've seen. I've struggled with understanding for...else for a very long time, and I've tried out various models over the years. Starting with the one implied by the name: for x in sequence: block else: # for...else is like if...else # one *or* the other runs but not both ... That mental model was ludicrously wrong, but I suffered under it for *years* and couldn't see why my for...else statements weren't doing what I wanted. I then moved to the mental model that else was linked to the presence of a break, but it always felt incomplete. I would write this: for x in sequence: block else: # only if no break occurs and then I would feel guilty for lying, because that comment is not, in fact, correct. Returning out of the function from inside the loop will also avoid running the else part, as will an exception. If you think about it, there are other ways that will prevent the else from running too. I leave them as an exercise for the reader :-) -- Steven From ictezy at gmail.com Mon Jun 13 23:43:36 2016 From: ictezy at gmail.com (ICT Ezy) Date: Mon, 13 Jun 2016 20:43:36 -0700 (PDT) Subject: Indentation example? In-Reply-To: References: <4b54489b-d57e-4180-b9cc-74815e0d846c@googlegroups.com> Message-ID: <1b830183-33f7-4fdc-a752-8645896bfffc@googlegroups.com> On Monday, June 13, 2016 at 3:09:15 AM UTC+5:30, Marc Dietz wrote: > On Sun, 12 Jun 2016 08:10:27 -0700 ICT Ezy wrote: > > > Pl explain with an example the following phase "Indentation cannot be > > split over multiple physical lines using backslashes; the whitespace up > > to the first backslash determines the indentation" (in 2.1.8. > > Indentation of Tutorial.) > > I want to teach my student that point using some examples. > > Pl help me any body? > > Hi! > > This is my very first post inside the usenet. I hope I did understand > this right, so here is my answer. :) > > I assume, that you do understand the concept of indentation inside Python > code. You can concatenate lines with a backslash. These lines work as if > they were only one line. For example: > > >>> print ("This is a very long"\ > ... " line, that got "\ > ... "diveded into three lines.") > This is a very long line, that was diveded into three. > >>> > > Because the lines get concatenated, one might think, that you could > divide for example 16 spaces of indentation into one line of 8 spaces > with a backslash and one line with 8 spaces and the actual code. > Your posted text tells you though, that you can't do this. Instead the > indentation would be considered to be only 8 spaces wide. > > I hope this helped a little. :) > > Cheers > Marc. Thank you very much your explaination here From nad at python.org Mon Jun 13 23:57:02 2016 From: nad at python.org (Ned Deily) Date: Mon, 13 Jun 2016 23:57:02 -0400 Subject: Python 3.6.0a2 is now available Message-ID: 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.0a2. 3.6.0a2 is the first of four planned alpha releases of Python 3.6, the next major release of Python. During the alpha phase, Python 3.6 remains under heavy development: additional features will be added and existing features may be modified or deleted. Please keep in mind that this is a preview release and its use is not recommended for production environments. You can find Python 3.6.0a2 here: https://www.python.org/downloads/release/python-360a2/ The next release of Python 3.6 will be 3.6.0a3, currently scheduled for 2016-07-11. Enjoy! --Ned -- Ned Deily nad at python.org -- [] From michael.selik at gmail.com Tue Jun 14 00:37:31 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 14 Jun 2016 04:37:31 +0000 Subject: for / while else doesn't make sense In-Reply-To: <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jun 13, 2016 at 10:46 PM Steven D'Aprano wrote: > On Tue, 14 Jun 2016 09:45 am, Michael Selik wrote: > > On Sun, Jun 12, 2016 at 10:16 PM Steven D'Aprano > > wrote: > >> On Mon, 13 Jun 2016 04:44 am, Michael Selik wrote: > >> > On Sun, Jun 12, 2016 at 6:11 AM Steven D'Aprano < > >> > steve+comp.lang.python at pearwood.info> wrote: > >> > > >> >> - run the for block > >> >> - THEN unconditionally run the "else" block > >> >> > >> > Saying "unconditionally" is a bit misleading here. As you say, it's > >> > conditioned on completing the loop without break/return/raise. > >> > >> It's also conditional on the OS not killing the Python process, > >> conditional on the CPU not catching fire, conditional on the user not > >> turning the power of, and conditional on the sun not exploding and > >> disintegrating the entire earth. > >> > >> In the absence of any event which interferes with the normal execution > of > >> code by the Python VM, and in the absence of one of a very few > >> explicit "JUMP" statements which explicitly jump out of the compound > >> for...else statement, the else clause is unconditionally executed after > >> the for clause. > > > Saying that ``raise``, ``break``, and ``return`` are "one of a very few > > explicit JUMP statements" implies that they are obscure. > > What? No. How do you get that? > The context. That was right after a list of several (mostly) oddball situations. In my experience, that pattern of speech is usually used to imply that everything listed is also exceptionally strange. There's a simple mental model, one which has the advantage of actually > matching the implementation: for...else executes else unconditionally, ... > If Python 3.6 introduces a GOTO command, then my mental model of > for...else doesn't need to change. > That's a good explanation. The documentation says, "A break statement executed in the first suite terminates the loop without executing the else clause?s suite." Do you think that qualification of "without executing the else clause" is unnecessary/redundant? Regardless of the implementation, I think that explanation -- if break, then skip the else-clause -- helps clarify the purpose. https://docs.python.org/3/reference/compound_stmts.html#the-for-statement else: # only if no break occurs > and then I would feel guilty for lying, because that comment is not, in > fact, correct. Returning out of the function from inside the loop will also > avoid running the else part, as will an exception. > I absolve you of guilt! :-) If you had written, "guaranteed to run if no break," then lawyers will come after you. If you had written "if and only if" some mathematicians might complain. As you wrote it, it's actually true. An "if and only if" logical statement has two parts: "if no break, run else-clause" and "if break, do not run else-clause". As you say, the first part is false. But you only made the latter claim. From orgnut at yahoo.com Tue Jun 14 00:45:42 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 13 Jun 2016 21:45:42 -0700 Subject: how to search item in list of list In-Reply-To: <3bbfd254-93a8-4fb2-b110-8f9cc9f62d98@googlegroups.com> References: <3bbfd254-93a8-4fb2-b110-8f9cc9f62d98@googlegroups.com> Message-ID: On 06/12/2016 08:29 PM, meInvent bbird wrote: > once a nested list have a word "node" then true else false > > def search(current_item): > if isinstance(current_item, list): > if len(current_item)==4: > if [item for item in current_item if item[4] == "node"] != []: > return True > if True in [search(item) for item in current_item]: > return True > else: > return False > > search(mresult) > > but it return false > > > mresult = [[(2, {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100', > '101', '110', '111'], 'xy', 'start')], [(2, {'11': 1, '10': 1, '00': 0, '01': 1} > , ['000', '001', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2 > , {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100', '101 > ', '110', '111'], 'xz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, [' > 000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {' > 11': 1, '10': 0, '00': 0, '01': 0}, ['000', '001', '010', '011', '100', '101', ' > 110', '111'], 'yz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, ['000' > , '001', '010', '011', '100', '101', '110', '111'], 'xz', 'start')], [(2, {'11': > 1, '10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110' > , '111'], 'xy', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '0 > 01', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2, {'11': 1, > '10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110', '1 > 11'], 'xz', 'start')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '01', ' > 11', '11', '10', '11', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00' > : 0, '01': 1}, ['00', '01', '10', '11', '11', '11', '11', '11'], 'xy', 'node')], > [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '10', > '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', > '00', '10', '11', '10', '10', '10', '11'], 'xy', 'node')], [(1, {'11': 1, '10': > 1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '11', '10', '11'], 'xy', 'n > ode')]] > I (manually) reformatted your list and found you have a missing left square bracket in the middle. But the way your list is formatted here I really can't tell you where it is -- you'll have to reformat it and/or use an editor that highlights matching brackets to find it yourself. Most programming editors have that bracket matching capability. -- -=- Larry -=- From owenpaul.po at gmail.com Tue Jun 14 04:15:38 2016 From: owenpaul.po at gmail.com (owenpaul.po at gmail.com) Date: Tue, 14 Jun 2016 01:15:38 -0700 (PDT) Subject: log file. Message-ID: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> I have a programme to pump out water from a sump and would like to log to a readable file when the pump operates. what is the easiest way to acheive this with python 3. From jussi.piitulainen at helsinki.fi Tue Jun 14 04:44:33 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 14 Jun 2016 11:44:33 +0300 Subject: log file. References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> Message-ID: owenpaul.po at gmail.com writes: > I have a programme to pump out water from a sump and would like to log > to a readable file when the pump operates. what is the easiest way to > acheive this with python 3. Depending on any number of details, the easiest may be to just print. Direct stdout and stderr to files when you run the program. From asimkostas at gmail.com Tue Jun 14 06:50:32 2016 From: asimkostas at gmail.com (asimkon) Date: Tue, 14 Jun 2016 13:50:32 +0300 Subject: mod_python compilation error in VS 2008 for py2.7.1 Message-ID: I would like to ask you a technical question regarding python module compilation for python 2.7.1. I want to compile mod_python library for Apache 2.2 and py2.7 on Win32 in order to use it for psp - py scripts that i have written. I tried to compile it using VS 2008 (VC++) and unfortunately i get an error on pyconfig.h (Py2.7/include) error C2632: int followed by int is illegal. This problem occurs when i try to run the bat file that exists on mod_python/dist folder. Any idea or suggestion what should i do in order to run it on Win 7 Pro (win 32) environment and produce the final apache executable module (.so). I have posted the same question here , but unfortunately i had had no luck! Additionally i give you the compilation instructions that i follow (used also MinGW-w64 and get the same error) in order to produce the final output! Compiling Open a command prompt with VS2008 support. The easiest way to do this is to use "Start | All Programs | Microsoft Visual Studio 2008 | Visual Studio Tools | Visual Studio 2008 Command Prompt". (This puts the VS2008 binaries in the path and sets up the lib/include environmental variables for the Platform SDK.) 1.cd to the mod_python\dist folder. 2.Tell mod_python where Apache is: set APACHESRC=C:\Apache 3. Run build_installer.bat. If it succeeds, an installer.exe will be created in a subfolder. Run that install the module. Kind Regards Kostas Asimakopoulos From alister.ware at ntlworld.com Tue Jun 14 07:39:04 2016 From: alister.ware at ntlworld.com (alister) Date: Tue, 14 Jun 2016 11:39:04 GMT Subject: for / while else doesn't make sense Message-ID: On Tue, 14 Jun 2016 12:43:35 +1000, Steven D'Aprano wrote: > > On this list, I daresay somebody will insist that if their computer is > on one of Jupiter's moons it will keep running fine and therefore I'm > wrong. > Anyone on a moon of Jupiter would not be able to get internet access (TCP/IP time-outs mean that even Mars is outside of internet range. The Moon at 1.3 light seconds might manage it ) so they could not be posting here ;-) -- Drink Canada Dry! You might not succeed, but it *__is* fun trying. From pavel at schon.cz Tue Jun 14 08:34:53 2016 From: pavel at schon.cz (Pavel S) Date: Tue, 14 Jun 2016 05:34:53 -0700 (PDT) Subject: mod_python compilation error in VS 2008 for py2.7.1 In-Reply-To: References: Message-ID: <1fc95d51-cac1-4906-8ef8-5b8227563f66@googlegroups.com> Have you considered to use rather WSGI-based solution? (for Apache Httpd is mod_wsgi). Mod_python is totally obsolete. From ian.g.kelly at gmail.com Tue Jun 14 09:51:25 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 14 Jun 2016 07:51:25 -0600 Subject: for / while else doesn't make sense In-Reply-To: References: Message-ID: On Tue, Jun 14, 2016 at 5:39 AM, alister wrote: > On Tue, 14 Jun 2016 12:43:35 +1000, Steven D'Aprano wrote: >> >> On this list, I daresay somebody will insist that if their computer is >> on one of Jupiter's moons it will keep running fine and therefore I'm >> wrong. >> > > Anyone on a moon of Jupiter would not be able to get internet access > (TCP/IP time-outs mean that even Mars is outside of internet range. The > Moon at 1.3 light seconds might manage it ) so they could not be posting > here ;-) Well, TCP might be problematic, but radio transmission from Jupiter would still be faster than RFC 1149, which in its only field test took an average of 5200 seconds to send round-trip pings over a distance of 3 miles. From rosuav at gmail.com Tue Jun 14 11:00:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jun 2016 01:00:45 +1000 Subject: for / while else doesn't make sense In-Reply-To: References: Message-ID: On Tue, Jun 14, 2016 at 11:51 PM, Ian Kelly wrote: > On Tue, Jun 14, 2016 at 5:39 AM, alister wrote: >> On Tue, 14 Jun 2016 12:43:35 +1000, Steven D'Aprano wrote: >>> >>> On this list, I daresay somebody will insist that if their computer is >>> on one of Jupiter's moons it will keep running fine and therefore I'm >>> wrong. >>> >> >> Anyone on a moon of Jupiter would not be able to get internet access >> (TCP/IP time-outs mean that even Mars is outside of internet range. The >> Moon at 1.3 light seconds might manage it ) so they could not be posting >> here ;-) > > Well, TCP might be problematic, but radio transmission from Jupiter > would still be faster than RFC 1149, which in its only field test took > an average of 5200 seconds to send round-trip pings over a distance of > 3 miles. And I'm sure someone could figure out a "netnews-over-UDP" system. After all, most people just post without thinking about responses anyway, which is exactly what UDP is great at... ChrisA From rustompmody at gmail.com Tue Jun 14 11:33:53 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jun 2016 08:33:53 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> On Tuesday, June 14, 2016 at 8:13:53 AM UTC+5:30, Steven D'Aprano wrote: > No. The sun exploding was me gently mocking you for your comment disputing > the "unconditional" part. Yes, you are technically right that technically > the "else" block will only run if no "break" is reached, and no "return" is > reached, no exception is raised, also that os._exit or os.abort aren't > called, the CPU doesn't catch fire, and the world isn't destroyed. > > If we try to enumerate all the things which could prevent the "else" block > from running, we'll be here for decades. But, and this is the point that > everyone seems to have missed, * every single one of those things* is > completely independent of the for...else statement. > > *Including* the presence or absence of a "break". This is real wild: A break that is inside a for is independent of the for?!?! Thats about as meaningful a statement as saying that the algebraic expression "x? + 1" has a value independent of "x" However see below > > If you want to understand how Python statements work, you should understand > them in isolation (as much as possible), which then allows you to > extrapolate their behaviour in combination with other statements. Most > lines of Python code are understandable in isolation, or at least close to > isolation. You can get *very close* to a full understanding of Python by > just reading one line at a time (with perhaps a bit of short term memory to > remember if you are compiling a function, building a class, etc). > > E.g. you don't need to understand for loops to understand if...else. > > And vice versa: for...else has a well-defined meaning and operates in a > simple fashion in isolation of other language features. Its not compulsory > to put a "return" statement inside your for loop. Nor is it compulsory to > put a "raise" inside it. And "break" is not compulsory either. This *desire* for what you call isolation is a standard tenet of semantics and is right It is called compositionality Inn programming: https://en.wikipedia.org/wiki/Denotational_semantics#Compositionality More general linguistics: https://en.wikipedia.org/wiki/Principle_of_compositionality However gotos break compositionality unless one introduces heavy artillery like continuations And break is a euphemism for goto From Joaquin.Alzola at lebara.com Tue Jun 14 12:53:30 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 14 Jun 2016 16:53:30 +0000 Subject: Multiple files reading Message-ID: Hi Guys I am doing program that reads into a directory for the files that were created the last 5 mins. (working) Inside those files there are 242 fields in each line separated by | (pipe). Each file has about 5k records and there are about 5 files per 5 mins. I will look for field 29 and 200 (Country, Diameter Error code). (split) I have 6 different countries (which I differentiate by field 29 which is the CountryCode). The thing is that I make it work but it goes slow. On the parent class I read the files all over for each Country 150k lines read (because I read 25k for each country which makes a total of 150k lines read). So the code even working is inefficient. I created classes such as: Read Files (Parent) - Country -- Service The dictionary that I am using in the classes: {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} Wanted help from your side on how to focus this just because I want to read the files once (not 6 times) and then use classes to get back the dictionary value ... I need just advice on steps to follow... Thanks J 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 owenpaul.po at gmail.com Tue Jun 14 14:06:15 2016 From: owenpaul.po at gmail.com (Paul Owen) Date: Tue, 14 Jun 2016 11:06:15 -0700 (PDT) Subject: log file. In-Reply-To: References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> Message-ID: <9b364049-c90d-40b0-b49c-e513ec67e9c7@googlegroups.com> I am very inexperienced at programming.! is there a lot of code needed to use those modules. regards paul. From gordon at panix.com Tue Jun 14 14:18:57 2016 From: gordon at panix.com (John Gordon) Date: Tue, 14 Jun 2016 18:18:57 +0000 (UTC) Subject: log file. References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> Message-ID: In <05d2df77-8cd0-467b-8ab3-54bf730d84c2 at googlegroups.com> owenpaul.po at gmail.com writes: > I have a programme to pump out water from a sump and would like to > log to a readable file when the pump operates. what is the easiest > way to acheive this with python 3. Are you asking for help with logging, or communicating with the pump? -- 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 python at mrabarnett.plus.com Tue Jun 14 15:32:12 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Jun 2016 20:32:12 +0100 Subject: Multiple files reading In-Reply-To: References: Message-ID: On 2016-06-14 17:53, Joaquin Alzola wrote: > Hi Guys > > I am doing program that reads into a directory for the files that were created the last 5 mins. (working) > > Inside those files there are 242 fields in each line separated by | (pipe). Each file has about 5k records and there are about 5 files per 5 mins. > > I will look for field 29 and 200 (Country, Diameter Error code). (split) > > I have 6 different countries (which I differentiate by field 29 which is the CountryCode). > > The thing is that I make it work but it goes slow. On the parent class I read the files all over for each Country 150k lines read (because I read 25k for each country which makes a total of 150k lines read). > So the code even working is inefficient. > > I created classes such as: > > Read Files (Parent) - Country -- Service > > The dictionary that I am using in the classes: {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} > > Wanted help from your side on how to focus this just because I want to read the files once (not 6 times) and then use classes to get back the dictionary value ... > > I need just advice on steps to follow... > Use a dict (or defaultdict) where the key is the country and the value is info (class?) related to that country. From owenpaul.po at gmail.com Tue Jun 14 15:54:20 2016 From: owenpaul.po at gmail.com (Paul Owen) Date: Tue, 14 Jun 2016 12:54:20 -0700 (PDT) Subject: log file. In-Reply-To: References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> Message-ID: <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> logging please. my pump programme works but I want to log the time etc. when the pump runs and stops. I am trying to improve the programme I am a novice! From Joaquin.Alzola at lebara.com Tue Jun 14 16:06:07 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 14 Jun 2016 20:06:07 +0000 Subject: Multiple files reading In-Reply-To: References: Message-ID: >> The dictionary that I am using in the classes: >> {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3', >> 'DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0 >> ,'5012':0}} >> >> Wanted help from your side on how to focus this just because I want to read the files once (not 6 times) and then use classes to get back the dictionary value ... >> >> I need just advice on steps to follow... >> >Use a dict (or defaultdict) where the key is the country and the value is info (class?) related to that country. Putting a dict for each country such as: self.dictionaryNL = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} self.dictionarySP = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} self.dictionaryUK = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} self.dictionaryFR = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} self.dictionaryDK = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} self.dictionaryGR = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} makes the trick but I have to repeat 6 time all the time. Now with that config I read only once the files saving 125k read lines. But as always I think it can be done better (just started to learn python about 8 month ago). Thanks for the tips. BR Joaquin 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 Tue Jun 14 16:07:35 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 14 Jun 2016 20:07:35 +0000 Subject: log file. In-Reply-To: <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> Message-ID: >logging please. Check this modules: import logging import logging.handlers 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 owenpaul.po at gmail.com Tue Jun 14 16:14:07 2016 From: owenpaul.po at gmail.com (Paul Owen) Date: Tue, 14 Jun 2016 13:14:07 -0700 (PDT) Subject: log file. In-Reply-To: References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> Message-ID: <3d6badc4-2ef4-40f0-828c-b172bfa2627e@googlegroups.com> thanks I will look at them. From joel.goldstick at gmail.com Tue Jun 14 16:23:57 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 14 Jun 2016 16:23:57 -0400 Subject: log file. In-Reply-To: <3d6badc4-2ef4-40f0-828c-b172bfa2627e@googlegroups.com> References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> <3d6badc4-2ef4-40f0-828c-b172bfa2627e@googlegroups.com> Message-ID: On Tue, Jun 14, 2016 at 4:14 PM, Paul Owen wrote: > thanks I will look at them. > -- > https://mail.python.org/mailman/listinfo/python-list If your program is called 'my_program.py' you can write print statements (or print functions in python 3) and when you run your program, those prints will show on your screen. If you want to save them to a log file do this: python my_program.py >> my_log_file.log When your program ends, open up my_log_file.log to see what happened. The two > characters will write to the file if it is new, or append to the file if it exists -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From Joaquin.Alzola at lebara.com Tue Jun 14 16:24:21 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 14 Jun 2016 20:24:21 +0000 Subject: log file. In-Reply-To: <3d6badc4-2ef4-40f0-828c-b172bfa2627e@googlegroups.com> References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> <3d6badc4-2ef4-40f0-828c-b172bfa2627e@googlegroups.com> Message-ID: >thanks I will look at them. As an example for your guide: ##log_handler### import sys import logging import logging.handlers from configfile_read import * def LogHandler(logger): CONFIG_FILE = ('./conf/' + 'config.ini') config = configfile(CONFIG_FILE) FORMAT = '%(asctime)-15s %(name)s %(levelname)s-%(levelno)s %(message)s' LOG_LEVEL = config.get("logging","Logging_Level") LOG_FILE = config.get("logging","Logging_File") LOG_DIRECTORY = config.get("logging","Logging_Directory") LOG_BYTES = config.get("logging","Logging_bytes") LOG_COUNT = config.get("logging","Logging_count") LEVEL = logging.getLevelName(LOG_LEVEL) logger.setLevel(LEVEL) handler = logging.handlers.RotatingFileHandler(LOG_DIRECTORY + LOG_FILE,maxBytes=int(LOG_BYTES),backupCount=int(LOG_COUNT)) handler.setFormatter(logging.Formatter(FORMAT)) return handler On each part of your code start a logger: logger = logging.getLogger('__main__.' + __name__) And in the main part: from log_handler import * #Logging Config Starts logger = logging.getLogger(__name__) logger.addHandler(LogHandler(logger)) #Logging Config Ends ####Config_parser where log parameters are taken#### import configparser import os, sys import logging import logging.handlers from log_handler import * logger = logging.getLogger('__main__.' + __name__) class configfile: def __init__(self,CONFIG_FILE): self.CONFIG_FILE = CONFIG_FILE if not os.path.isfile(self.CONFIG_FILE): logger.critical('File NOT found: %s' % CONFIG_FILE + '. This file is needed for the system to work') sys.exit() def get(self,general,parameter): config = configparser.ConfigParser() config.read(self.CONFIG_FILE) try: result = config.get(general,parameter) except configparser.NoSectionError as e: logger.critical('File %s is there but need information inside: %s'%(self.CONFIG_FILE,e)) sys.exit() logger.debug('Parameters pass to configparser-->' + general + ':' + parameter + ' with result-->' + result) return result testbedocg:/usr/local/statistics_server/conf # more config.ini [config] Host=172.1.1.1 Port=12346 [logging] #Possbile Values: CRITICAL ERROR WARNING INFO DEBUG NOTSET Logging_Level=DEBUG Logging_File=server_log.log Logging_Directory=./logs/ Logging_bytes=2097152 Logging_count=5 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 python at mrabarnett.plus.com Tue Jun 14 16:27:26 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Jun 2016 21:27:26 +0100 Subject: Multiple files reading In-Reply-To: References: Message-ID: <16c2be10-b688-2408-3796-fe0ea41ae068@mrabarnett.plus.com> On 2016-06-14 21:06, Joaquin Alzola wrote: > >> The dictionary that I am using in the classes: > >> {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3', > >> 'DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0 > >> ,'5012':0}} > >> > >> Wanted help from your side on how to focus this just because I want to read the files once (not 6 times) and then use classes to get back the dictionary value ... > >> > >> I need just advice on steps to follow... > >> > >Use a dict (or defaultdict) where the key is the country and the value is info (class?) related to that country. > > Putting a dict for each country such as: > self.dictionaryNL = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} > self.dictionarySP = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} > self.dictionaryUK = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} > self.dictionaryFR = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} > self.dictionaryDK = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} > self.dictionaryGR = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} > > makes the trick but I have to repeat 6 time all the time. Now with that config I read only once the files saving 125k read lines. > > But as always I think it can be done better (just started to learn python about 8 month ago). Thanks for the tips. > I think that what you're doing currently is scanning the files multiple times, once for each country, looking in the appropriate field for the country to see whether you should read or skip. What I meant was that you would have a dict of dicts, where the key was the country: self.dictionary = {} for country in ('NL', 'SP', 'UK', 'FR', 'DK', 'GR'): self.dictionary[country] = {'Country':'Empty','Service':'Empty','TimeStamp':'Empty','Ocg':'see3','DiameterCodes':{'2001':0,'4010':0,'4012':0,'4998':0,'4999':0,'5007':0,'5012':0}} You could then scan the files _once_, looking in the appropriate field for the country, and then updating the appropriate dictionary. From owenpaul.po at gmail.com Tue Jun 14 17:37:45 2016 From: owenpaul.po at gmail.com (Paul Owen) Date: Tue, 14 Jun 2016 14:37:45 -0700 (PDT) Subject: log file. In-Reply-To: References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> <3d6badc4-2ef4-40f0-828c-b172bfa2627e@googlegroups.com> Message-ID: Gmail Google+ Calendar Web more Inbox pump programme Paul Owen to?me 1 hour ago Details from gpiozero import LED,Button from signal import pause print ("Pump Programme Running") led = LED(17) low = Button (2) high = Button (3) high.when_pressed = led.on? low.when_released = led.off #as you can see I need a simple way to log when led(pump) runs hope seeing this helps. regards Paul. From Joaquin.Alzola at lebara.com Tue Jun 14 19:16:40 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 14 Jun 2016 23:16:40 +0000 Subject: Multiple files reading In-Reply-To: <16c2be10-b688-2408-3796-fe0ea41ae068@mrabarnett.plus.com> References: <16c2be10-b688-2408-3796-fe0ea41ae068@mrabarnett.plus.com> Message-ID: > What I meant was that you would have a dict of dicts, where the key was the country: Thanks MRAB I could not see that solution. That save me a lot of lines of code. Certainly my previous solution also manage to do that but yours is more clean-code wise. 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 rustompmody at gmail.com Tue Jun 14 21:29:14 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jun 2016 18:29:14 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> Message-ID: <11c8ce7a-d0f9-4fcd-98e6-65c40517dd4d@googlegroups.com> On Wednesday, June 15, 2016 at 4:58:05 AM UTC+5:30, Lawrence D?Oliveiro wrote: > On Wednesday, June 15, 2016 at 3:34:14 AM UTC+12, Rustom Mody wrote: > > > And break is a euphemism for goto > > Is this the old ?structured-programming-is-mathematically-equivalent-to-gotos? red herring again? Are you familiar with Duff's device? https://en.wikipedia.org/wiki/Duff%27s_device From steve at pearwood.info Tue Jun 14 23:12:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 15 Jun 2016 13:12:19 +1000 Subject: for / while else doesn't make sense References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> Message-ID: <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Jun 2016 01:33 am, Rustom Mody wrote: > On Tuesday, June 14, 2016 at 8:13:53 AM UTC+5:30, Steven D'Aprano wrote: >> No. The sun exploding was me gently mocking you for your comment >> disputing the "unconditional" part. Yes, you are technically right that >> technically the "else" block will only run if no "break" is reached, and >> no "return" is reached, no exception is raised, also that os._exit or >> os.abort aren't called, the CPU doesn't catch fire, and the world isn't >> destroyed. >> >> If we try to enumerate all the things which could prevent the "else" >> block from running, we'll be here for decades. But, and this is the point >> that everyone seems to have missed, * every single one of those things* >> is completely independent of the for...else statement. >> >> *Including* the presence or absence of a "break". > > This is real wild: A break that is inside a for is independent of the > for?!?! If that's what I said, you would be right to question me. But that's not what I said. It is legal syntax to have for...else without a break, or a break inside a for block with no else. And, if you really want to nitpick, you can even have a break statement without a for. (Just stick it inside a while loop instead.) I know that's it's great fun to pick at nits without making a good faith effort to communicate, but honestly Rustom, your following comments do suggest that you understood what I was saying. [...] > This *desire* for what you call isolation is a standard tenet of > semantics and is right > > It is called compositionality > > Inn programming: > https://en.wikipedia.org/wiki/Denotational_semantics#Compositionality > > More general linguistics: > https://en.wikipedia.org/wiki/Principle_of_compositionality Thanks for that. > However gotos break compositionality unless one introduces heavy artillery > like continuations > > And break is a euphemism for goto Sort of. A break is a jump, and a goto is a jump, but apart from that, they're not really the same thing. A goto can jump (almost) anywhere. Depending on the language, they can jump into the middle of functions, or into the middle of loops. That's what makes them powerful enough to break compositionality. But break can only jump to a single place: to the statement that follows the for...else compound statement. It's more like a return than a goto. You can reason about for...else without the break, then reason about what the break does. This isn't hard, and its what people do even in the common use-case: for x in seq: process(x) if condition: break else: fnord() spam() "If the condition is never true, then we loop through seq, calling process(x) each time, then call fnord(), then call spam(). If the condition becomes true at some point in the loop, we stop looping, and go straight to calling spam()." We can reason about the condition is true case separately from the condition is false case. And we can do so without imagining that there is an invisible "did_not_break" flag, or needing a second mental model to understand this ever-so-slightly more complex example: for x in seq: process(x) if condition: break else: foo() else: fnord() spam() -- Steven From steve at pearwood.info Tue Jun 14 23:16:47 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 15 Jun 2016 13:16:47 +1000 Subject: log file. References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> Message-ID: <5760c8a0$0$1609$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Jun 2016 05:54 am, Paul Owen wrote: > logging please. > > my pump programme works but I want to log the time etc. when the pump runs > and stops. > > I am trying to improve the programme > > I am a novice! As a novice, start with the simplest thing. Whenever the pump runs or stops, just call print: start(pump) print("Starting") ... stop(pump) print("Stopping") To log to a file instead, change the program to: import logging logging.basicConfig(filename='example.log',level=logging.DEBUG) start(pump) logging.info("Starting") ... stop(pump) logging.info("Stopping") More information in the logging tutorial: https://docs.python.org/2/howto/logging.html https://docs.python.org/3/howto/logging.html -- Steven From ablacktshirt at gmail.com Tue Jun 14 23:28:24 2016 From: ablacktshirt at gmail.com (Yubin Ruan) Date: Tue, 14 Jun 2016 20:28:24 -0700 (PDT) Subject: python regex: variable length of positive lookbehind assertion Message-ID: Hi everyone, I am struggling writing a right regex that match what I want: Problem Description: Given a string like this: >>>string = "false_head aaa bbb false_tail \ true_head some_text_here ccc ddd eee true_tail" I want to match the all the text surrounded by those " ", but only if those " " locate **in some distance** behind "true_head". That is, I expect to result to be like this: >>>import re >>>result = re.findall("the_regex",string) >>>print result ["ccc","ddd","eee"] How can I write a regex to match that? I have try to use the **positive lookbehind assertion** in python regex, but it does not allowed variable length of lookbehind. Thanks in advance, Ruan From rustompmody at gmail.com Tue Jun 14 23:38:03 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jun 2016 20:38:03 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <27b3af95-7aa9-4800-ac25-dc6da6ac566e@googlegroups.com> On Wednesday, June 15, 2016 at 8:42:33 AM UTC+5:30, Steven D'Aprano wrote: > On Wed, 15 Jun 2016 01:33 am, Rustom Mody wrote: > > > On Tuesday, June 14, 2016 at 8:13:53 AM UTC+5:30, Steven D'Aprano wrote: > >> No. The sun exploding was me gently mocking you for your comment > >> disputing the "unconditional" part. Yes, you are technically right that > >> technically the "else" block will only run if no "break" is reached, and > >> no "return" is reached, no exception is raised, also that os._exit or > >> os.abort aren't called, the CPU doesn't catch fire, and the world isn't > >> destroyed. > >> > >> If we try to enumerate all the things which could prevent the "else" > >> block from running, we'll be here for decades. But, and this is the point > >> that everyone seems to have missed, * every single one of those things* > >> is completely independent of the for...else statement. > >> > >> *Including* the presence or absence of a "break". > > > > This is real wild: A break that is inside a for is independent of the > > for?!?! > > If that's what I said, you would be right to question me. But that's not > what I said. > > It is legal syntax to have for...else without a break, or a break inside a > for block with no else. And, if you really want to nitpick, you can even > have a break statement without a for. (Just stick it inside a while loop > instead.) > > I know that's it's great fun to pick at nits without making a good faith > effort to communicate, but honestly Rustom, your following comments do > suggest that you understood what I was saying. > > > [...] > > This *desire* for what you call isolation is a standard tenet of > > semantics and is right > > > > It is called compositionality > > > > Inn programming: > > https://en.wikipedia.org/wiki/Denotational_semantics#Compositionality > > > > More general linguistics: > > https://en.wikipedia.org/wiki/Principle_of_compositionality > > Thanks for that. > > > > However gotos break compositionality unless one introduces heavy artillery > > like continuations > > > > And break is a euphemism for goto > > Sort of. A break is a jump, and a goto is a jump, but apart from that, > they're not really the same thing. A goto can jump (almost) anywhere. > Depending on the language, they can jump into the middle of functions, or > into the middle of loops. That's what makes them powerful enough to break > compositionality. But break can only jump to a single place: to the > statement that follows the for...else compound statement. It's more like a > return than a goto. > > You can reason about for...else without the break, then reason about what > the break does. This isn't hard, and its what people do even in the common > use-case: > > for x in seq: > process(x) > if condition: > break > else: > fnord() > spam() Yon need to take an example of the if condition: break nested inside some more ifs with those other conditions giving validity to the condition eg outer condition being say y != 0 Inner if being if x/y == 0 : break Now you would see that your reasoning about the inner needs potentially the FULL CONTEXT of the outer. This need to carry large context is the essential property of non-compositional semantics. From lawrencedo99 at gmail.com Tue Jun 14 23:51:26 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 14 Jun 2016 20:51:26 -0700 (PDT) Subject: loading trees... In-Reply-To: References: Message-ID: <677537e8-b0d3-418e-a1a2-3417b5ee9578@googlegroups.com> On Monday, June 13, 2016 at 6:56:07 AM UTC+12, Fillmore wrote: > I then need to run a program that loads the whole forest in the form of a > dict() where each item will point to a dynamically loaded tree. Store it in JSON form? I like language-neutral solutions. From lawrencedo99 at gmail.com Wed Jun 15 00:18:15 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 14 Jun 2016 21:18:15 -0700 (PDT) Subject: python regex: variable length of positive lookbehind assertion In-Reply-To: References: Message-ID: <32c42462-1a1a-4687-abf9-ede6f7e916ec@googlegroups.com> On Wednesday, June 15, 2016 at 3:28:37 PM UTC+12, Yubin Ruan wrote: > I want to match the all the text surrounded by those " ", You are trying to use regex (type 3 grammar) to parse HTML (type 2 grammar) ? No can do . From ablacktshirt at gmail.com Wed Jun 15 00:38:29 2016 From: ablacktshirt at gmail.com (Yubin Ruan) Date: Tue, 14 Jun 2016 21:38:29 -0700 (PDT) Subject: python regex: variable length of positive lookbehind assertion In-Reply-To: <32c42462-1a1a-4687-abf9-ede6f7e916ec@googlegroups.com> References: <32c42462-1a1a-4687-abf9-ede6f7e916ec@googlegroups.com> Message-ID: <738b82c0-e988-4b40-ac7c-2d46a940ea3b@googlegroups.com> On Wednesday, June 15, 2016 at 12:18:31 PM UTC+8, Lawrence D?Oliveiro wrote: > On Wednesday, June 15, 2016 at 3:28:37 PM UTC+12, Yubin Ruan wrote: > > > I want to match the all the text surrounded by those " ", > > You are trying to use regex (type 3 grammar) to parse HTML (type 2 grammar) ? > > No can do . Yes. I think you are correct. Thanks. From jussi.piitulainen at helsinki.fi Wed Jun 15 01:10:16 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 15 Jun 2016 08:10:16 +0300 Subject: python regex: variable length of positive lookbehind assertion References: Message-ID: Yubin Ruan writes: > Hi everyone, > I am struggling writing a right regex that match what I want: > > Problem Description: > > Given a string like this: > > >>>string = "false_head aaa bbb false_tail \ > true_head some_text_here ccc ddd eee true_tail" > > I want to match the all the text surrounded by those " ", but > only if those " " locate **in some distance** behind > "true_head". That is, I expect to result to be like this: > > >>>import re > >>>result = re.findall("the_regex",string) > >>>print result > ["ccc","ddd","eee"] > > How can I write a regex to match that? > I have try to use the **positive lookbehind assertion** in python regex, > but it does not allowed variable length of lookbehind. Don't. Don't even try to do it all in one regex. Keep your regexen simple and match in two steps. For example, capture all such elements together with your marker: re.findall(r'true_head|[^<]+', string) ==> ['aaa', 'bbb', 'true_head', 'ccc', 'ddd', 'eee'] Then filter the result in the obvious way (not involving any regex any more, unless needed to recognize the true 'true_head' again). I've kept the tags at this stage, so a possible 'true_head' won't look like 'true_head' yet. Another way is to find 'true_head' first (if you can recognize it safely before also recognizing the elements), and then capture the elements in the latter half only. From owenpaul.po at gmail.com Wed Jun 15 02:00:23 2016 From: owenpaul.po at gmail.com (Paul Owen) Date: Tue, 14 Jun 2016 23:00:23 -0700 (PDT) Subject: log file. In-Reply-To: <5760c8a0$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> <5760c8a0$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thank you Steven. that is just what I need. regards Paul. From paul.nospam at rudin.co.uk Wed Jun 15 02:45:28 2016 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 15 Jun 2016 07:45:28 +0100 Subject: log file. References: <05d2df77-8cd0-467b-8ab3-54bf730d84c2@googlegroups.com> <6f268d6f-3301-492c-976f-f537fa1e6d47@googlegroups.com> Message-ID: <86k2hr6jcn.fsf@rudin.co.uk> Joaquin Alzola writes: > 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. Probably not a good idea to send it to a publicly accessible resource then :) From quintin9g at gmail.com Wed Jun 15 02:54:34 2016 From: quintin9g at gmail.com (Edward Montague) Date: Tue, 14 Jun 2016 18:54:34 -1200 Subject: mayavi mlab mesh plot3d grid from mesh Message-ID: Hi, I'm wondering if there's any way to overlay a grid upon a mlab.mesh or mlab.surf graph. As an example of what I mean I shall attempt to attach a small file maya2.jpg . From vlastimil.brom at gmail.com Wed Jun 15 04:31:22 2016 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 15 Jun 2016 10:31:22 +0200 Subject: python regex: variable length of positive lookbehind assertion In-Reply-To: References: Message-ID: 2016-06-15 5:28 GMT+02:00 Yubin Ruan : > Hi everyone, > I am struggling writing a right regex that match what I want: > > Problem Description: > > Given a string like this: > > >>>string = "false_head aaa bbb false_tail \ > true_head some_text_here ccc ddd eee true_tail" > > I want to match the all the text surrounded by those " ", > but only if those " " locate **in some distance** behind "true_head". That is, I expect to result to be like this: > > >>>import re > >>>result = re.findall("the_regex",string) > >>>print result > ["ccc","ddd","eee"] > > How can I write a regex to match that? > I have try to use the **positive lookbehind assertion** in python regex, > but it does not allowed variable length of lookbehind. > > Thanks in advance, > Ruan > -- > https://mail.python.org/mailman/listinfo/python-list Hi, html-like data is generally not very suitable for parsing with regex, as was explained in the previous answers (especially if comments and nesting are massively involved). However, if this suits your data and the usecase, you can use regex with variable-length lookarounds in a much enhanced "regex" library for python https://pypi.python.org/pypi/regex your pattern might then simply have the form you most likely have intended, e.g.: >>> regex.findall(r"(?<=true_head.*)([^<]+)(?=.*true_tail)", "false_head aaa bbb false_tail true_head some_text_here ccc ddd eee true_tail fff another_false_tail") ['ccc', 'ddd', 'eee'] >>> If you are accustomed to use regular expressions, I'd certainly recommend this excellent library (besides unlimited lookarounds, there are repeated and recursive patterns, many unicode-related enhancements, powerful character set operations, even fuzzy matching and much more). hth, vbr From rustompmody at gmail.com Wed Jun 15 07:19:41 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 15 Jun 2016 04:19:41 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> On Wednesday, June 15, 2016 at 8:42:33 AM UTC+5:30, Steven D'Aprano wrote: > On Wed, 15 Jun 2016 01:33 am, Rustom Mody wrote: > > > On Tuesday, June 14, 2016 at 8:13:53 AM UTC+5:30, Steven D'Aprano wrote: > >> No. The sun exploding was me gently mocking you for your comment > >> disputing the "unconditional" part. Yes, you are technically right that > >> technically the "else" block will only run if no "break" is reached, and > >> no "return" is reached, no exception is raised, also that os._exit or > >> os.abort aren't called, the CPU doesn't catch fire, and the world isn't > >> destroyed. > >> > >> If we try to enumerate all the things which could prevent the "else" > >> block from running, we'll be here for decades. But, and this is the point > >> that everyone seems to have missed, * every single one of those things* > >> is completely independent of the for...else statement. > >> > >> *Including* the presence or absence of a "break". > > > > This is real wild: A break that is inside a for is independent of the > > for?!?! > > If that's what I said, you would be right to question me. But that's not > what I said. > > It is legal syntax to have for...else without a break, or a break inside a > for block with no else. And, if you really want to nitpick, you can even > have a break statement without a for. (Just stick it inside a while loop > instead.) > > I know that's it's great fun to pick at nits without making a good faith > effort to communicate, but honestly Rustom, your following comments do > suggest that you understood what I was saying. > > > [...] > > This *desire* for what you call isolation is a standard tenet of > > semantics and is right > > > > It is called compositionality > > > > Inn programming: > > https://en.wikipedia.org/wiki/Denotational_semantics#Compositionality > > > > More general linguistics: > > https://en.wikipedia.org/wiki/Principle_of_compositionality > > Thanks for that. > > > > However gotos break compositionality unless one introduces heavy artillery > > like continuations > > > > And break is a euphemism for goto > > Sort of. A break is a jump, and a goto is a jump, but apart from that, > they're not really the same thing. A goto can jump (almost) anywhere. > Depending on the language, they can jump into the middle of functions, or > into the middle of loops. That's what makes them powerful enough to break > compositionality. But break can only jump to a single place: to the > statement that follows the for...else compound statement. It's more like a > return than a goto. I thought there'd be many examples for showing that break is just goto in disguise... Evidently not So here is an example in more detail for why/how break=goto: http://blog.languager.org/2016/06/break-is-goto-in-disguise.html [Return/yield are more interesting and complicated...] From bc at freeuk.com Wed Jun 15 08:27:34 2016 From: bc at freeuk.com (BartC) Date: Wed, 15 Jun 2016 13:27:34 +0100 Subject: for / while else doesn't make sense In-Reply-To: <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> Message-ID: On 15/06/2016 12:19, Rustom Mody wrote: > On Wednesday, June 15, 2016 at 8:42:33 AM UTC+5:30, Steven D'Aprano wrote: >> Sort of. A break is a jump, and a goto is a jump, but apart from that, >> they're not really the same thing. A goto can jump (almost) anywhere. >> Depending on the language, they can jump into the middle of functions, or >> into the middle of loops. That's what makes them powerful enough to break >> compositionality. But break can only jump to a single place: to the >> statement that follows the for...else compound statement. It's more like a >> return than a goto. > > I thought there'd be many examples for showing that break is just goto in disguise... Evidently not > > So here is an example in more detail for why/how break=goto: > > http://blog.languager.org/2016/06/break-is-goto-in-disguise.html That example is nothing to do with break vs. goto. You've just replaced an erroneous goto with an erroneous break. It's to do with C (or C-like syntax if not C) using braces for compound statements at the same time as making them optional for a single statement. With the wrong indentation applied, that sort of error can easily be missed. Some tools may be able to pick that up. (Another kind of error (C seems to have plenty of capacity in this regard!) is forgetting the */ in a /* ... */ comment. Then code is mysteriously ignored until the end of the next /* ... */ comment. Although a syntax-highlighting editor will pick that up more easily.) -- Bartc From alister.ware at ntlworld.com Wed Jun 15 08:27:52 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 15 Jun 2016 12:27:52 GMT Subject: python regex: variable length of positive lookbehind assertion References: Message-ID: On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: > Hi everyone, > I am struggling writing a right regex that match what I want: > > Problem Description: > > Given a string like this: > > >>>string = "false_head aaa bbb false_tail \ > true_head some_text_here ccc ddd eee > true_tail" > > I want to match the all the text surrounded by those " ", > but only if those " " locate **in some distance** behind > "true_head". That is, I expect to result to be like this: > > >>>import re result = re.findall("the_regex",string) > >>>print result > ["ccc","ddd","eee"] > > How can I write a regex to match that? > I have try to use the **positive lookbehind assertion** in python regex, > but it does not allowed variable length of lookbehind. > > Thanks in advance, > Ruan don't try to use regex to parse html it wont work reliably i am surprised no one has mentioned beautifulsoup yet, which is probably what you require. -- What we anticipate seldom occurs; what we least expect generally happens. -- Bengamin Disraeli From rustompmody at gmail.com Wed Jun 15 08:44:13 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 15 Jun 2016 05:44:13 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> Message-ID: <47df9541-203b-47d9-bc0d-13b2df5c09cb@googlegroups.com> On Wednesday, June 15, 2016 at 5:57:51 PM UTC+5:30, BartC wrote: > On 15/06/2016 12:19, Rustom Mody wrote: > > On Wednesday, June 15, 2016 at 8:42:33 AM UTC+5:30, Steven D'Aprano wrote: > > >> Sort of. A break is a jump, and a goto is a jump, but apart from that, > >> they're not really the same thing. A goto can jump (almost) anywhere. > >> Depending on the language, they can jump into the middle of functions, or > >> into the middle of loops. That's what makes them powerful enough to break > >> compositionality. But break can only jump to a single place: to the > >> statement that follows the for...else compound statement. It's more like a > >> return than a goto. > > > > I thought there'd be many examples for showing that break is just goto in disguise... Evidently not > > > > So here is an example in more detail for why/how break=goto: > > > > http://blog.languager.org/2016/06/break-is-goto-in-disguise.html > > That example is nothing to do with break vs. goto. You've just replaced > an erroneous goto with an erroneous break. Precisely the point -- that that erroneous goto could be an erroneous break with minor changes to the code (One needs to be inside a break-able statement like for/while (or for C do/switch) > > It's to do with C (or C-like syntax if not C) using braces for compound > statements at the same time as making them optional for a single statement. > > With the wrong indentation applied, that sort of error can easily be > missed. Some tools may be able to pick that up. > > (Another kind of error (C seems to have plenty of capacity in this > regard!) is forgetting the */ in a /* ... */ comment. Then code is > mysteriously ignored until the end of the next /* ... */ comment. > Although a syntax-highlighting editor will pick that up more easily.) As the links point out there can be any amt of post-mortem analysis - gcc silently stopped dead code warnings - the misleading indent -- could be detected by tools - etc Doesnt change the fact that that misplaced goto could be a misplaced break And either did/would JUMP OVER critical code wrongly tl;dr: A rose by any name smells sweet A goto by any name goes-to From jussi.piitulainen at helsinki.fi Wed Jun 15 08:55:42 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 15 Jun 2016 15:55:42 +0300 Subject: python regex: variable length of positive lookbehind assertion References: Message-ID: alister writes: > On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: > >> Hi everyone, >> I am struggling writing a right regex that match what I want: >> >> Problem Description: >> >> Given a string like this: >> >> >>>string = "false_head aaa bbb false_tail \ >> true_head some_text_here ccc ddd eee >> true_tail" >> >> I want to match the all the text surrounded by those " ", >> but only if those " " locate **in some distance** behind >> "true_head". That is, I expect to result to be like this: >> >> >>>import re result = re.findall("the_regex",string) >> >>>print result >> ["ccc","ddd","eee"] >> >> How can I write a regex to match that? >> I have try to use the **positive lookbehind assertion** in python regex, >> but it does not allowed variable length of lookbehind. >> >> Thanks in advance, >> Ruan > > don't try to use regex to parse html it wont work reliably > i am surprised no one has mentioned beautifulsoup yet, which is probably > what you require. Nothing in the question indicates that the data is HTML. From cjwilliams43 at gmail.com Wed Jun 15 09:38:40 2016 From: cjwilliams43 at gmail.com (cjw) Date: Wed, 15 Jun 2016 06:38:40 -0700 (PDT) Subject: Python 3.6.0a2 is now available In-Reply-To: References: Message-ID: <2fac7f7a-00ed-456a-9240-04b09ef10d63@googlegroups.com> On Monday, 13 June 2016 23:57:20 UTC-4, 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.0a2. > 3.6.0a2 is the first of four planned alpha releases of Python 3.6, > the next major release of Python. During the alpha phase, Python 3.6 > remains under heavy development: additional features will be added > and existing features may be modified or deleted. Please keep in mind > that this is a preview release and its use is not recommended for > production environments. > > You can find Python 3.6.0a2 here: > > https://www.python.org/downloads/release/python-360a2/ > > The next release of Python 3.6 will be 3.6.0a3, currently scheduled for > 2016-07-11. > > Enjoy! > > --Ned > > -- > Ned Deily > nad at python.org -- [] I see that the Array Class now provides for data of the double type, this is good, but why is there no provision for data of the complex type? Is this omission intended? Colin W. From random832 at fastmail.com Wed Jun 15 09:51:37 2016 From: random832 at fastmail.com (Random832) Date: Wed, 15 Jun 2016 09:51:37 -0400 Subject: for / while else doesn't make sense In-Reply-To: <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> Message-ID: <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> On Wed, Jun 15, 2016, at 07:19, Rustom Mody wrote: > I thought there'd be many examples for showing that break is just goto in > disguise... Evidently not > > So here is an example in more detail for why/how break=goto: > > http://blog.languager.org/2016/06/break-is-goto-in-disguise.html So? So are loops. So is any "if" statement whose body isn't itself a one-line goto. Showing that break can be written as a goto is uninteresting because _any_ form of flow control can be written as a goto, and in particular it does not establish that break is in any way less structured than any other constructs that have keywords. C's for loop: for(i=0;i goto end;] [continue within body -> goto inc;] if(x) true_body; else false_body; is syntactic sugar for: if(!x) goto else; true_body; goto end; else: false_body; end: ; From rosuav at gmail.com Wed Jun 15 09:56:14 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jun 2016 23:56:14 +1000 Subject: for / while else doesn't make sense In-Reply-To: <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> Message-ID: On Wed, Jun 15, 2016 at 11:51 PM, Random832 wrote: > if(x) true_body; else false_body; > > is syntactic sugar for: > > if(!x) goto else; > true_body; > goto end; > else: false_body; > end: ; And I remember writing GW-BASIC code like this, because we didn't have block if. You could put a single statement after an if, but for anything bigger than that, it was "negate the condition and GOTO the bit after". ChrisA From ldompeling at casema.nl Wed Jun 15 10:15:13 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Wed, 15 Jun 2016 07:15:13 -0700 (PDT) Subject: GoPiGo distence sensor Message-ID: <24fc1dae-5411-44fa-89e2-d2859d27594f@googlegroups.com> I have a small robot on wheels named the GoPiGo. What I want is if the distence sensor read the same distence for let say 5 seconds then the GoPiGo go's backward. But I don't now how to program this in python. The Api functions for the GoPiGo are here: http://www.dexterindustries.com/GoPiGo/programming/python-programming-for-the-raspberry-pi-gopigo/ Can someone help me with this. From python at mrabarnett.plus.com Wed Jun 15 10:19:06 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Jun 2016 15:19:06 +0100 Subject: Python 3.6.0a2 is now available In-Reply-To: <2fac7f7a-00ed-456a-9240-04b09ef10d63@googlegroups.com> References: <2fac7f7a-00ed-456a-9240-04b09ef10d63@googlegroups.com> Message-ID: <087d80a4-edd1-30a7-a093-59099e9f398d@mrabarnett.plus.com> On 2016-06-15 14:38, cjw wrote: > On Monday, 13 June 2016 23:57:20 UTC-4, 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.0a2. >> 3.6.0a2 is the first of four planned alpha releases of Python 3.6, >> the next major release of Python. During the alpha phase, Python 3.6 >> remains under heavy development: additional features will be added >> and existing features may be modified or deleted. Please keep in mind >> that this is a preview release and its use is not recommended for >> production environments. >> >> You can find Python 3.6.0a2 here: >> >> https://www.python.org/downloads/release/python-360a2/ >> >> The next release of Python 3.6 will be 3.6.0a3, currently scheduled for >> 2016-07-11. >> > I see that the Array Class now provides for data of the double type, this is good, but why is there no provision for data of the complex type? > > Is this omission intended? > The Array class supports types that are available in C, and, up until now, the source code of CPython has been based on the C89 standard, which lacks a complex type. A complex type was added in the C99 standard. Coincidentally, there was recently a discussion on the python-dev list about whether to switch to C99. From rustompmody at gmail.com Wed Jun 15 10:20:41 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 15 Jun 2016 07:20:41 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> Message-ID: <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> On Wednesday, June 15, 2016 at 7:21:54 PM UTC+5:30, Random832 wrote: > On Wed, Jun 15, 2016, at 07:19, Rustom Mody wrote: > > I thought there'd be many examples for showing that break is just goto in > > disguise... Evidently not > > > > So here is an example in more detail for why/how break=goto: > > > > http://blog.languager.org/2016/06/break-is-goto-in-disguise.html > > So? > > So are loops. So is any "if" statement whose body isn't itself a > one-line goto. Showing that break can be written as a goto is > uninteresting because Where did the question of "break can be written as goto" come from? Sure all structured constructs have their unstructured counterparts And that is uninteresting as you say. Claim is that the damaging propensities of goto are replicable with break. Well to some extent... the goto can go from anywhere to anywhere within function scope, whereas the break's target-end is fixed -- the end of the loop/switch. However the starting end can be anywhere in there and that is a potential for unstructured damage From rustompmody at gmail.com Wed Jun 15 10:31:44 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 15 Jun 2016 07:31:44 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> Message-ID: On Wednesday, June 15, 2016 at 7:21:54 PM UTC+5:30, Random832 wrote: > On Wed, Jun 15, 2016, at 07:19, Rustom Mody wrote: > > I thought there'd be many examples for showing that break is just goto in > > disguise... Evidently not > > > > So here is an example in more detail for why/how break=goto: > > > > http://blog.languager.org/2016/06/break-is-goto-in-disguise.html > > So? > > So are loops. So is any "if" statement whose body isn't itself a > one-line goto. Showing that break can be written as a goto is > uninteresting because _any_ form of flow control can be written as a > goto, and in particular it does not establish that break is in any way > less structured than any other constructs that have keywords. Here is C.A.R Hoare's Turing award speech: https://www.cs.fsu.edu/~engelen/courses/COP4610/hoare.pdf in which (2nd last page) he claims that Ada is a threat to civilization... because it has something as terrible as exceptions. We may or may not agree with his threatening thoughts Which is different from seeing the simple fact that exceptions are unstructured From marko at pacujo.net Wed Jun 15 10:33:54 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 15 Jun 2016 17:33:54 +0300 Subject: python regex: variable length of positive lookbehind assertion References: Message-ID: <8737oemsh9.fsf@elektro.pacujo.net> Jussi Piitulainen : > alister writes: > >> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: >>> Given a string like this: >>> >>> >>>string = "false_head aaa bbb false_tail \ >>> true_head some_text_here ccc ddd eee >>> true_tail" >>> >>> I want to match the all the text surrounded by those " ", >>> [...] >> >> don't try to use regex to parse html it wont work reliably >> [...] > > Nothing in the question indicates that the data is HTML. And nothing in alister's answer suggests that. Marko From jussi.piitulainen at helsinki.fi Wed Jun 15 10:57:09 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 15 Jun 2016 17:57:09 +0300 Subject: python regex: variable length of positive lookbehind assertion References: <8737oemsh9.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> alister writes: >> >>> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: >>>> Given a string like this: >>>> >>>> >>>string = "false_head aaa bbb false_tail \ >>>> true_head some_text_here ccc ddd eee >>>> true_tail" >>>> >>>> I want to match the all the text surrounded by those " ", >>>> [...] >>> >>> don't try to use regex to parse html it wont work reliably >>> [...] >> >> Nothing in the question indicates that the data is HTML. > > And nothing in alister's answer suggests that. Now *I'm* surprised. From joel.goldstick at gmail.com Wed Jun 15 10:59:47 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 15 Jun 2016 10:59:47 -0400 Subject: GoPiGo distence sensor In-Reply-To: <24fc1dae-5411-44fa-89e2-d2859d27594f@googlegroups.com> References: <24fc1dae-5411-44fa-89e2-d2859d27594f@googlegroups.com> Message-ID: On Wed, Jun 15, 2016 at 10:15 AM, wrote: > I have a small robot on wheels named the GoPiGo. > What I want is if the distence sensor read the same distence for let say 5 seconds then the GoPiGo go's backward. > > But I don't now how to program this in python. > The Api functions for the GoPiGo are here: http://www.dexterindustries.com/GoPiGo/programming/python-programming-for-the-raspberry-pi-gopigo/ > > Can someone help me with this. > > -- > https://mail.python.org/mailman/listinfo/python-list You can start here: https://www.python.org/about/gettingstarted/ -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From python at mrabarnett.plus.com Wed Jun 15 11:00:10 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Jun 2016 16:00:10 +0100 Subject: GoPiGo distence sensor In-Reply-To: <24fc1dae-5411-44fa-89e2-d2859d27594f@googlegroups.com> References: <24fc1dae-5411-44fa-89e2-d2859d27594f@googlegroups.com> Message-ID: <14e59bbf-34aa-f83e-ab2f-a623c1380310@mrabarnett.plus.com> On 2016-06-15 15:15, ldompeling at casema.nl wrote: > I have a small robot on wheels named the GoPiGo. > What I want is if the distence sensor read the same distence for let say 5 seconds then the GoPiGo go's backward. > > But I don't now how to program this in python. > The Api functions for the GoPiGo are here: http://www.dexterindustries.com/GoPiGo/programming/python-programming-for-the-raspberry-pi-gopigo/ > > Can someone help me with this. > Check the distance at regular intervals, like the ticks of a clock. At each tick, check the distance. If the distance is the same as the previous measurement, increment a counter, else reset the counter. If the counter reaches a certain value, it means that the robot has been at that distance for that many ticks. (If it checks every second and the counter reaches 5, then it has been at that distance for 5 seconds ... approximately ...) From joel.goldstick at gmail.com Wed Jun 15 11:13:11 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 15 Jun 2016 11:13:11 -0400 Subject: GoPiGo distence sensor In-Reply-To: <14e59bbf-34aa-f83e-ab2f-a623c1380310@mrabarnett.plus.com> References: <24fc1dae-5411-44fa-89e2-d2859d27594f@googlegroups.com> <14e59bbf-34aa-f83e-ab2f-a623c1380310@mrabarnett.plus.com> Message-ID: On Wed, Jun 15, 2016 at 11:00 AM, MRAB wrote: > On 2016-06-15 15:15, ldompeling at casema.nl wrote: >> >> I have a small robot on wheels named the GoPiGo. >> What I want is if the distence sensor read the same distence for let say 5 >> seconds then the GoPiGo go's backward. >> >> But I don't now how to program this in python. >> The Api functions for the GoPiGo are here: >> http://www.dexterindustries.com/GoPiGo/programming/python-programming-for-the-raspberry-pi-gopigo/ >> >> Can someone help me with this. >> > Check the distance at regular intervals, like the ticks of a clock. > > At each tick, check the distance. > > If the distance is the same as the previous measurement, increment a > counter, else reset the counter. > > If the counter reaches a certain value, it means that the robot has been at > that distance for that many ticks. (If it checks every second and the > counter reaches 5, then it has been at that distance for 5 seconds ... > approximately ...) > > -- > https://mail.python.org/mailman/listinfo/python-list This reminds me of a toy called 'Big Trak' made by Milton Bradley in the 1980s https://en.wikipedia.org/wiki/Big_Trak -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From alister.ware at ntlworld.com Wed Jun 15 11:31:38 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 15 Jun 2016 15:31:38 GMT Subject: python regex: variable length of positive lookbehind assertion References: Message-ID: On Wed, 15 Jun 2016 15:55:42 +0300, Jussi Piitulainen wrote: > alister writes: > >> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: >> >>> Hi everyone, >>> I am struggling writing a right regex that match what I want: >>> >>> Problem Description: >>> >>> Given a string like this: >>> >>> >>>string = "false_head aaa bbb false_tail \ >>> true_head some_text_here ccc ddd eee >>> true_tail" >>> >>> I want to match the all the text surrounded by those " ", >>> but only if those " " locate **in some distance** behind >>> "true_head". That is, I expect to result to be like this: >>> >>> >>>import re result = re.findall("the_regex",string) print result >>> ["ccc","ddd","eee"] >>> >>> How can I write a regex to match that? >>> I have try to use the **positive lookbehind assertion** in python >>> regex, >>> but it does not allowed variable length of lookbehind. >>> >>> Thanks in advance, >>> Ruan >> >> don't try to use regex to parse html it wont work reliably i am >> surprised no one has mentioned beautifulsoup yet, which is probably >> what you require. > > Nothing in the question indicates that the data is HTML. the tags are a prety good indicator though even if it is not HTML the same advise stands for XML (the quote example would be invalid if it was XML) if it is neither for these formats but still using a similar tag structure then I would say that Reg ex is still unsuitable & the OP would need to write a full parser for the format if one does not already exist -- Farewell we call to hearth and hall! Though wind may blow and rain may fall, We must away ere break of day Far over wood and mountain tall. To Rivendell, where Elves yet dwell In glades beneath the misty fell, Through moor and waste we ride in haste, And whither then we cannot tell. With foes ahead, behind us dread, Beneath the sky shall be our bed, Until at last our toil be passed, Our journey done, our errand sped. We must away! We must away! We ride before the break of day! -- J. R. R. Tolkien From wrw at mac.com Wed Jun 15 11:47:20 2016 From: wrw at mac.com (William Ray Wing) Date: Wed, 15 Jun 2016 11:47:20 -0400 Subject: GoPiGo distence sensor In-Reply-To: References: <24fc1dae-5411-44fa-89e2-d2859d27594f@googlegroups.com> Message-ID: <0F618F06-727D-49CD-A1AB-10C0E83CAC58@mac.com> > On Jun 15, 2016, at 10:59 AM, Joel Goldstick wrote: > > On Wed, Jun 15, 2016 at 10:15 AM, wrote: >> I have a small robot on wheels named the GoPiGo. >> What I want is if the distence sensor read the same distence for let say 5 seconds then the GoPiGo go's backward. >> When I look at the API, I see two functions related to distance traveled. An encoder target function that presumably reads the numbers from an angular encoder on the drive shaft and allows you to specify a number for the encoder to seek, and a ?us_dist? function that seems to read the proximity to an object from an ultrasonic sensor. I?m going to assume you are referring to the numbers from this ultrasonic distance sensor. So, I think what you are saying is that if the numbers from the distance sensor are unchanged for 5 seconds (as would be the case if the GoPiGo were being blocked by something) then you want it to back up. As MRAB has commented, what you need to do is set up a delay loop that wakes up every second (or more frequently if you want more time resolution) and reads the number returned by the us_dist function. Compare it to the previous reading and if unchanged increment a counter. If it has changed, the robot has moved so clear the counter. If the counter reaches your five second trigger point, call a go_back function you write. -Bill >> But I don't now how to program this in python. >> The Api functions for the GoPiGo are here: http://www.dexterindustries.com/GoPiGo/programming/python-programming-for-the-raspberry-pi-gopigo/ >> >> Can someone help me with this. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > You can start here: https://www.python.org/about/gettingstarted/ > > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays > -- > https://mail.python.org/mailman/listinfo/python-list From random832 at fastmail.com Wed Jun 15 11:54:01 2016 From: random832 at fastmail.com (Random832) Date: Wed, 15 Jun 2016 11:54:01 -0400 Subject: for / while else doesn't make sense In-Reply-To: <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> Message-ID: <1466006041.357579.638625625.6C5C4E1D@webmail.messagingengine.com> On Wed, Jun 15, 2016, at 10:20, Rustom Mody wrote: > Claim is that the damaging propensities of goto are replicable with > break. The "damaging propensity" in this particular case simply comes from the fact that it's a statement that can appear in the body of an if statement (the real flaw that caused the bug here here was the optional braces of the if statement), which is just as true of anything else. It could have called a function that it shouldn't have called. But a lot of people do claim that break should be generally "considered harmful" just like goto and never used at all because of this isomorphism. From jussi.piitulainen at helsinki.fi Wed Jun 15 12:04:29 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 15 Jun 2016 19:04:29 +0300 Subject: python regex: variable length of positive lookbehind assertion References: Message-ID: alister writes: > On Wed, 15 Jun 2016 15:55:42 +0300, Jussi Piitulainen wrote: > >> alister writes: >> >>> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: >>> >>>> Hi everyone, >>>> I am struggling writing a right regex that match what I want: >>>> >>>> Problem Description: >>>> >>>> Given a string like this: >>>> >>>> >>>string = "false_head aaa bbb false_tail \ >>>> true_head some_text_here ccc ddd eee >>>> true_tail" >>>> >>>> I want to match the all the text surrounded by those " ", >>>> but only if those " " locate **in some distance** behind >>>> "true_head". That is, I expect to result to be like this: >>>> >>>> >>>import re result = re.findall("the_regex",string) print result >>>> ["ccc","ddd","eee"] >>>> >>>> How can I write a regex to match that? >>>> I have try to use the **positive lookbehind assertion** in python >>>> regex, >>>> but it does not allowed variable length of lookbehind. >>>> >>>> Thanks in advance, >>>> Ruan >>> >>> don't try to use regex to parse html it wont work reliably i am >>> surprised no one has mentioned beautifulsoup yet, which is probably >>> what you require. >> >> Nothing in the question indicates that the data is HTML. > > the tags are a prety good indicator though I can see how they point that way, but to me that alone seemed pretty weak. > even if it is not HTML the same advise stands for XML (the quote > example would be invalid if it was XML) It's not valid HTML either, for similar reasons. Or is it? I don't even want to know. > if it is neither for these formats but still using a similar tag > structure then I would say that Reg ex is still unsuitable & the OP > would need to write a full parser for the format if one does not > already exist That depends on details that weren't provided. I work with a data format that mixes element tags with line-oriented data records, and having a dedicated parser would be more of a hassle. A couple of very simple regexen are useful in making sure that start tags have a valid form and extracting attribute-value pairs from them. I'm not at all experiencing "two problems" here. Some uses of regex are good. (And now I may be about to experience the third problem. That makes me sad.) Anyway, I think you and another person guessed correctly that the OP is indeed really considering HTML, and then your suggestion is certainly helpful. From rustompmody at gmail.com Wed Jun 15 13:03:41 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 15 Jun 2016 10:03:41 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> <1466006041.357579.638625625.6C5C4E1D@webmail.messagingengine.com> Message-ID: On Wednesday, June 15, 2016 at 9:24:21 PM UTC+5:30, Random832 wrote: > On Wed, Jun 15, 2016, at 10:20, Rustom Mody wrote: > > Claim is that the damaging propensities of goto are replicable with > > break. > > The "damaging propensity" in this particular case simply comes from the > fact that it's a statement that can appear in the body of an if > statement (the real flaw that caused the bug here here was the optional > braces of the if statement), which is just as true of anything else. It > could have called a function that it shouldn't have called. People have adduced various reasons: 1. Optionality of braces 2. gcc silently non-mentioning dead code 3. indentation and braces mismatch -- were it python(ish) the second goto would be harmless dead code INSIDE the if 4. Careless merging 5. Culture of cut-paste 6. All kinds of soft questions -- code should be reviewed/pair-programmed/etc 7. Even more irrelevant soft point -- Apple is a bad company for being thus irresponsible 8. etc > > But a lot of people do claim that break should be generally "considered > harmful" just like goto and never used at all because of this > isomorphism. Minor point: I dont think isomorphism is correct As I said the goto can originate anywhere and target to anywhere (in function scope). Not break longjmp can scale function scopes but has other restrictions like respecting the stack, the setjmp-site needs to have been visited first. IOW different unstructured constructs have differing properties Major point: "Considered harmful" should be considered harmful :-) IOW cargo-cult programming without any understanding is worse than specific fads There are things -- eg automata -- where the most faithful rendering is with gotos: : labels for states, gotos for transitions. Any 'more structured' solution is usually more messy. OTOH Duff's device shows terrifyingly unstructured code with nary a goto/break in sight So break also has its uses. Lets just not pretend its structured From michael.selik at gmail.com Wed Jun 15 13:18:22 2016 From: michael.selik at gmail.com (Michael Selik) Date: Wed, 15 Jun 2016 17:18:22 +0000 Subject: for / while else doesn't make sense In-Reply-To: <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> Message-ID: On Wed, Jun 15, 2016, 10:28 AM Rustom Mody wrote: > Where did the question of "break can be written as goto" come from? > Stephen said the "else" in for-else was "unconditional". He argued that neither the presence nor absence of a break should be considered a condition, because we don't consider the occurrence or non-occurrence of an exception (goto) as a condition of whether to run the else-clause. > From bc at freeuk.com Wed Jun 15 13:27:25 2016 From: bc at freeuk.com (BartC) Date: Wed, 15 Jun 2016 18:27:25 +0100 Subject: for / while else doesn't make sense In-Reply-To: References: <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> <1466006041.357579.638625625.6C5C4E1D@webmail.messagingengine.com> Message-ID: On 15/06/2016 18:03, Rustom Mody wrote: > OTOH Duff's device shows terrifyingly unstructured code with nary a goto/break > in sight I agree, and these mostly originate in C. It's full of crude features that should have been pensioned off decades ago, but amazingly it is still around and highly influential! > So break also has its uses. Lets just not pretend its structured It's a short-circuit operator that gets you to the end of the current loop block. There's one here too: if a: b c else: d It's called 'else' and is unconditional (when you finish executing the 'c' line, you then skip to the end of the next block). This is another short-circuit operator: if a and b(c): d e (I assume Python has short-circuit evaluation; if not then plenty of languages do). When a is False, the b(c) function call is skipped.) If that's not enough, then 'return' in most languages will let you return early from a routine, skipping the rest of the function. -- Bartc From rgaddi at highlandtechnology.invalid Wed Jun 15 13:37:03 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 15 Jun 2016 17:37:03 -0000 (UTC) Subject: Bulk Adding Methods Pythonically Message-ID: I've got a whole lot of methods I want to add to my Channel class, all of which following nearly the same form. The below code works, but having to do the for loop outside of the main class definition feels kludgey. Am I missing some cleaner answer? I thought about just checking for all of it in __getattr__, but that's hacky too and doesn't docstring nicely. Python 3.4 class Channel: # Lots of stuff in here. ... # Add functions for a zillion different single channel measurements to # the Channel object. Relative measurements are more complex, and need to be # handled separately. for fnname, measparam in ( ('frequency', 'FREQ'), ('falltime', 'FTIM'), ('negduty', 'NDUT'), ('negwidth', 'NWID'), ('overshoot', 'OVER'), ('duty', 'PDUT'), ('period', 'PER'), ('preshoot', 'PRE'), ('width', 'PWID'), ('amplitude', 'VAMP'), ('mean', 'VAVG'), ('base', 'VBAS'), ('max', 'VMAX'), ('min', 'VMIN'), ('ptp', 'VPP'), ('rms', 'VRMS'), ('top', 'VTOP')): def measmaker(p): def inner(self, cursorarea=False): region = 'CREG' if cursorarea else 'SCR' return float(self.scope.query(':MEAS:AREA {reg};{meas}? {chan}'.format( reg = region, meas = p, chan = self.name ))) inner.__name__ = fnname inner.__doc__ = "Channel {} measurement".format(fnname) return inner setattr(Channel, fnname, measmaker(measparam)) -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From random832 at fastmail.com Wed Jun 15 13:41:01 2016 From: random832 at fastmail.com (Random832) Date: Wed, 15 Jun 2016 13:41:01 -0400 Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> Message-ID: <1466012461.379166.638733945.4672088E@webmail.messagingengine.com> On Wed, Jun 15, 2016, at 13:18, Michael Selik wrote: > On Wed, Jun 15, 2016, 10:28 AM Rustom Mody wrote: > > > Where did the question of "break can be written as goto" come from? > > > > Stephen said the "else" in for-else was "unconditional". He argued that > neither the presence nor absence of a break should be considered a > condition, because we don't consider the occurrence or non-occurrence of > an > exception (goto) as a condition of whether to run the else-clause. Okay... so why don't we consider the else in *if*-else unconditional? After all, the same logic applies: it only doesn't run if a statement defined to jump past it (in one case, the true part of the if statement - in the other case, a break) is run. From random832 at fastmail.com Wed Jun 15 14:21:57 2016 From: random832 at fastmail.com (Random832) Date: Wed, 15 Jun 2016 14:21:57 -0400 Subject: Bulk Adding Methods Pythonically In-Reply-To: References: Message-ID: <1466014917.388175.638768225.2DAFD4E9@webmail.messagingengine.com> On Wed, Jun 15, 2016, at 13:37, Rob Gaddi wrote: > I've got a whole lot of methods I want to add to my Channel class, all > of which following nearly the same form. The below code works, but > having to do the for loop outside of the main class definition feels > kludgey. Am I missing some cleaner answer? Inside the class definition you can add things to locals() [it returns the actual dictionary being used in class preparation], but I don't know if this can be relied on or is an implementation detail of CPython. Anyone know? But anyway, instead of using a loop, why not just define each one on its own line: def mkmeasure(fnname, measparam): ... class Channel: frequency = mkmeasure('frequency', 'FREQ') falltime = mkmeasure('falltime', 'FTIM') From rgaddi at highlandtechnology.invalid Wed Jun 15 14:39:08 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 15 Jun 2016 18:39:08 -0000 (UTC) Subject: Bulk Adding Methods Pythonically References: <1466014917.388175.638768225.2DAFD4E9@webmail.messagingengine.com> Message-ID: Random832 wrote: > On Wed, Jun 15, 2016, at 13:37, Rob Gaddi wrote: >> I've got a whole lot of methods I want to add to my Channel class, all >> of which following nearly the same form. The below code works, but >> having to do the for loop outside of the main class definition feels >> kludgey. Am I missing some cleaner answer? > > Inside the class definition you can add things to locals() [it returns > the actual dictionary being used in class preparation], but I don't know > if this can be relied on or is an implementation detail of CPython. > Anyone know? > > But anyway, instead of using a loop, why not just define each one on its > own line: > > def mkmeasure(fnname, measparam): > ... > > class Channel: > frequency = mkmeasure('frequency', 'FREQ') > falltime = mkmeasure('falltime', 'FTIM') Thought about it, but whenever I'm dropping 20-someodd of those there's inevitably some place where I screw up the replication of the quoted name and the bound name. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From vonpupp at gmail.com Wed Jun 15 14:54:31 2016 From: vonpupp at gmail.com (Albert) Date: Wed, 15 Jun 2016 11:54:31 -0700 (PDT) Subject: Anyone know a donation app codebase? In-Reply-To: References: <8560to4qhz.fsf@benfinney.id.au> <1973b5af-79c5-4bf5-a13f-4532e1f16a71@googlegroups.com> <851t4b4exk.fsf@benfinney.id.au> Message-ID: <8e7c7452-0681-43e4-8cb9-7821fff60488@googlegroups.com> On Monday, June 6, 2016 at 10:17:35 AM UTC-3, Michael Selik wrote: > On Sun, Jun 5, 2016 at 3:26 PM Ben Finney <> > wrote: > > > Albert <> writes: > > > > > Thank you for your answer Ben, > > > > You're welcome. Please note that top-posting is poor etiquette for > > discussions; instead, interleave your response like a written dialogue. > > See . > > > > > That is not exactly what I am looking for. I am interested in knowing > > > if there are any python (django, flask, etc) opensource projects for > > > managing donations > > > > Again, PyPI is the place to search > > > https://pypi.python.org/pypi?:action=search&term=django%20donation&submit=search > > >. > > > > I tried the Google search engine. Looking up the phrase "python managing > donations catarse" the 2nd search result was this a website which appears > to list several packages in different programming languages. > http://seedingfactory.com/index.html%3Fp=634.html Great, this looks very promising! Thank you very much to both for your time and good will to help me out. Regards. From ethan at stoneleaf.us Wed Jun 15 15:03:20 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Jun 2016 12:03:20 -0700 Subject: Bulk Adding Methods Pythonically In-Reply-To: References: Message-ID: <5761A678.8010003@stoneleaf.us> On 06/15/2016 10:37 AM, Rob Gaddi wrote: > I've got a whole lot of methods I want to add to my Channel class, all > of which following nearly the same form. The below code works, but > having to do the for loop outside of the main class definition feels > kludgey. Am I missing some cleaner answer? I thought about just > checking for all of it in __getattr__, but that's hacky too and doesn't > docstring nicely. Python 3.4 If I understand correctly: - you are creating one class (not several similar classes) - this class has several very similar functions - you (understandably!) don't want to write out these very similar functions one at a time If that is all correct, then, as Random suggested, move that loop into the class body and use locals() [1] to update the class dictionary. Just make sure and delete any temporary variables. Your other option is to put the code in a class decorator. -- ~Ethan~ [1] https://docs.python.org/3/library/functions.html#locals Yes, returning the class namespace is a language gaurantee. From wetlife at gmail.com Wed Jun 15 15:18:19 2016 From: wetlife at gmail.com (Kyle Thomas) Date: Wed, 15 Jun 2016 12:18:19 -0700 Subject: PEP8 needs revision Message-ID: To Whom It May Concern, Knuth's quote refers to the output of TeX, the programming language he authored. The quote cannot be interpreted to speak about formatting of source-code. One bit of evidence I can offer is that TeX's source only cares about multiple newlines in considering the multiplicity of whitespace. This means that Knuth's quote likely has little or no bearing on the format of source-code. Further, TeX, being a modal language, has two modes of outputting math: inline(like in a paragraph) and display. This is what the quote refers to. So, Knuth is quoted referring to the output of his language, not the format of its source. He wrote that a binary operator is printed before a line-break in inline-mode of TeX's output while that same operator is printed after the newline in display-mode. PEP8's reference to Knuth's quote as a definitive rule for formatting python source-code is inappropriate. Is PEP8 a joke at the expense pedantry common of those new to programming? PS: Knuth's quote was taken from The TeXbook, a text about his programming language. -Kyle From random832 at fastmail.com Wed Jun 15 15:39:35 2016 From: random832 at fastmail.com (Random832) Date: Wed, 15 Jun 2016 15:39:35 -0400 Subject: PEP8 needs revision In-Reply-To: References: Message-ID: <1466019575.403263.638845321.6A863290@webmail.messagingengine.com> On Wed, Jun 15, 2016, at 15:18, Kyle Thomas wrote: > To Whom It May Concern, > Knuth's quote refers to the output of TeX, the programming language he > authored. The quote cannot be interpreted to speak about formatting of > source-code. It speaks about what is more readable, and is mentioned in the context of a general discussion of readability. > One bit of evidence I can offer is that TeX's source only > cares about multiple newlines in considering the multiplicity of > whitespace. This means that Knuth's quote likely has little or no bearing > on the format of source-code. Yes but we're not talking about source code as computer code (Python's source doesn't care about whitespace within parenthesized expressions at all), we're talking about source code as human-readable information. Looking to other traditions of displaying human-readable information (mathematical typesetting traditions as described by Knuth) is entirely valid. He made that choice, one assumes, because it's what Mathematicians expect and like to see in their papers, and they want that because it is more readable. From fred at bristle.com Wed Jun 15 16:34:11 2016 From: fred at bristle.com (Fred Stluka) Date: Wed, 15 Jun 2016 16:34:11 -0400 Subject: Recommended courses/materials for Python/Django course... Message-ID: Python programmers, Any Python and/or Django courses/materials to recommend? I may be teaching a Python/Django class soon. My client may be willing to jumpstart by buying existing course materials (lecture slides, notes, homeworks, labs, reference links, any other materials). We'll certainly be happy to make use of any free materials. Do you have any Python and/or Django courses/materials to recommend? I've taken a quick look and found: - Main web sites: - [1]http://python.org - [2]https://djangoproject.com (excellent docs and tutorial!) - Free courses: - [3]https://developers.google.com/edu/python - Free/paid courses: - [4]http://learnpythonthehardway.org/book - Books - 2 Scoops of Django - Paid courses: - Coursera - Codecademy - Khan Academy - Udacity - edX - Alison - Lynda - NewCircle.com Any advice? Thanks! --Fred -------------------------------------------------------------------------- Fred Stluka -- [5]mailto:fred at bristle.com -- [6]http://bristle.com/~fred/ Bristle Software, Inc -- [7]http://bristle.com -- Glad to be of service! Open Source: Without walls and fences, we need no Windows or Gates. -------------------------------------------------------------------------- References Visible links 1. http://python.org/ 2. https://djangoproject.com/ 3. https://developers.google.com/edu/python 4. http://learnpythonthehardway.org/book 5. mailto:fred at bristle.com 6. http://bristle.com/~fred/ 7. http://bristle.com/ From bad_n_mad at yahoo.com Wed Jun 15 16:34:31 2016 From: bad_n_mad at yahoo.com (Chupo) Date: Wed, 15 Jun 2016 22:34:31 +0200 Subject: pip vs pip2 vs pip2.7? Message-ID: Hi everyone, this is my first post here. I've been using Python occasionally to accomplish some specific tasks but now I decided to study it more seriously. I am successfully using both Python 2.6.2 and Python 3.2.2 instaled on Windows. I installed 2.6.2 back in 2009. and 3.2.2 came along with the VPyton 5.74 MSI installer. There was no problems but today I decided to install Python 2.7.11 as the latest pre-3.x.x version and the first thing I noticed was the 'Scripts' folder which was not present in earlier versions, containing: easy_install.exe easy_install-2.7.exe pip.exe pip2.exe pip2.7.exe So my question is - which one should I use to install the Python packages? Should I just use pip, of pip2 or pip2.7 and what is the difference? Typing: pip list in command prompt says: >pip list pip (7.1.2) setuptools (18.2) You are using pip version 7.1.2, however version 8.1.2 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. >pip2 list and >pip2.7 list results in exactly the same - what is then purpose of three different 'pip*.exe' executables? I noticed both easy_install files are of the same size (89.448 bytes) and all 3 of the pip files are of the same size (89.420 bytes) as well. In fact, easy_install.exe and easy_install-2.7.exe are exactly the same compared by binary compare utility, and pip, pip2 & pip2.7 are exactly the same up to the single byte :-/ I am assuming multiple copies of the same file with different names are because of some compatibility issues but couldn't find any explanations so I hope someone can point me to some docs explaining the issue. -- Let There Be Light Custom LED driveri prema specifikacijama http://tinyurl.com/customleddriver Chupo From bad_n_mad at yahoo.com Wed Jun 15 16:40:51 2016 From: bad_n_mad at yahoo.com (Chupo) Date: Wed, 15 Jun 2016 22:40:51 +0200 Subject: python-2.7.11.msi destroys PATH env var? Message-ID: After installing Python 2.7.11 through python-2.7.11.msi Windows installer OS couldn't anymore detect antivirus software so after some investigation I found that PATH environment variable was completely removed from the system. I had to recreate the PATH var and add: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem; into the path so the WMI could detect antivirus again. Can anyone confirm the same problem? I marked 'Add python.exe to PATH' during the installation process. -- Let There Be Light Custom LED driveri prema specifikacijama http://tinyurl.com/customleddriver Chupo From random832 at fastmail.com Wed Jun 15 17:10:28 2016 From: random832 at fastmail.com (Random832) Date: Wed, 15 Jun 2016 17:10:28 -0400 Subject: pip vs pip2 vs pip2.7? In-Reply-To: References: Message-ID: <1466025028.422202.638932193.32A2CCC1@webmail.messagingengine.com> On Wed, Jun 15, 2016, at 16:34, Chupo via Python-list wrote: > I am assuming multiple copies of the same file with different names are > because of some compatibility issues but couldn't find any explanations > so I hope someone can point me to some docs explaining the issue. The idea is, if you have multiple python installations on your path, "pip" will find the first one, "pip2" will find the first python2 one (so if the first one was python3, or vice versa), and pip2.7 will find 2.7 even if e.g. 2.6 was before it on the path. It makes a bit more sense on Unix where all of these are in /usr/bin and only the primary "pip" [of whatever your main python installation] actually exists. From ethan at stoneleaf.us Wed Jun 15 17:13:29 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Jun 2016 14:13:29 -0700 Subject: PEP8 needs revision In-Reply-To: References: Message-ID: <5761C4F9.2050402@stoneleaf.us> On 06/15/2016 12:18 PM, Kyle Thomas wrote: > Knuth's quote refers to the output of TeX, the programming language he > authored. The quote cannot be interpreted to speak about formatting of > source-code. PEP 8 is primarily concerned with the readability of source code, so if Knuth was speaking about what code looks like when output then that would certainly seem to fit with PEP 8. -- ~Ethan~ From bad_n_mad at yahoo.com Wed Jun 15 18:17:44 2016 From: bad_n_mad at yahoo.com (Chupo) Date: Thu, 16 Jun 2016 00:17:44 +0200 Subject: pip vs pip2 vs pip2.7? References: <1466025028.422202.638932193.32A2CCC1@webmail.messagingengine.com> Message-ID: In article , Random832 says... > The idea is, if you have multiple python installations on your path, > "pip" will find the first one, "pip2" will find the first python2 one > (so if the first one was python3, or vice versa), and pip2.7 will find > 2.7 even if e.g. 2.6 was before it on the path. > > It makes a bit more sense on Unix where all of these are in /usr/bin and > only the primary "pip" [of whatever your main python installation] > actually exists. > Thank you very much for the reply! So I guess it will be safe if I just add only 2.7 installation dir to the PATH var and use 'pip'. -- Let There Be Light Custom LED driveri prema specifikacijama http://tinyurl.com/customleddriver Chupo From torriem at gmail.com Wed Jun 15 20:40:40 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 15 Jun 2016 18:40:40 -0600 Subject: python regex: variable length of positive lookbehind assertion In-Reply-To: References: <8737oemsh9.fsf@elektro.pacujo.net> Message-ID: <0a2f2355-1b2d-4bc7-0113-e35266cb3fd7@gmail.com> On 06/15/2016 08:57 AM, Jussi Piitulainen wrote: > Marko Rauhamaa writes: >> And nothing in alister's answer suggests that. > > Now *I'm* surprised. He simply said, here's a regex that can parse the example string the OP gave us (which maybe looked a bit like HTML, but like you say, may not be), but don't try to use this method to parse actual HTML because it won't work reliably. From steve at pearwood.info Wed Jun 15 21:19:44 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 16 Jun 2016 11:19:44 +1000 Subject: for / while else doesn't make sense References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> Message-ID: <5761feb1$0$1619$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Jun 2016 09:19 pm, Rustom Mody wrote: > On Wednesday, June 15, 2016 at 8:42:33 AM UTC+5:30, Steven D'Aprano wrote: >> On Wed, 15 Jun 2016 01:33 am, Rustom Mody wrote: [...] >> > And break is a euphemism for goto >> >> Sort of. A break is a jump, and a goto is a jump, but apart from that, >> they're not really the same thing. A goto can jump (almost) anywhere. >> Depending on the language, they can jump into the middle of functions, or >> into the middle of loops. That's what makes them powerful enough to break >> compositionality. But break can only jump to a single place: to the >> statement that follows the for...else compound statement. It's more like >> a return than a goto. > > I thought there'd be many examples for showing that break is just goto in > disguise... Evidently not > > So here is an example in more detail for why/how break=goto: > > http://blog.languager.org/2016/06/break-is-goto-in-disguise.html Quote: "For now lets just agree that break is not very different from goto" Let's not. Your argument seems to be: "I can use GOTO to jump outside of a loop. I can use BREAK to jump outside of a loop. Careless use of jumping out of a loop leads to a bug, regardless of whether that jump is written as GOTO or BREAK. Therefore GOTO and BREAK are the same thing." but you have failed to consider: "I can use GOTO to jump inside a loop. I *cannot* use BREAK to jump inside a loop. I can use GOTO to jump back to before the loop. I *cannot* use BREAK to jump back before the loop. In the most general case of completely unstructured programming, I can use GOTO to jump I can use GOTO to jump out of one function into the middle of another function, or any other arbitrary line of code anywhere in my program. I *cannot* do the same with BREAK." If you only consider the similarities, and not the differences, you would erroneously conclude that all sorts of things that are actually quite different are "similar". "Cars are actually not so different from the Space Shuttle. Here's video of the shuttle taxiing down the runway after returning from space. Here's a video of a car driving along a road. Careless driving can run over pedestrians, regardless of whether you are driving a car or taxiing a space shuttle. Therefore cars and space shuttles are not that different." Congratulations, you have discovered that mechanically replacing careless use of GOTO with careless use of BREAK doesn't necessarily make the code less buggy. That's a valuable lesson for cargo-cult programmers who think that its the *word* "goto" that causes bad things to happen, and changing the word magically will fix the bug. But to the rest of us, it's about as insightful as the discovery that mechanically replacing "x*5" with "x+x+x+x+x" won't fix the off-by-one error that you actually needed "x*6". -- Steven From jobmattcon at gmail.com Wed Jun 15 21:37:03 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Wed, 15 Jun 2016 18:37:03 -0700 (PDT) Subject: how to change itertools.combinations(initlist, 2) to parallel for running in multiprocessor environment? Message-ID: how to change itertools.combinations(initlist, 2) to parallel for running in multiprocessor environment? From steve at pearwood.info Wed Jun 15 21:38:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 16 Jun 2016 11:38:19 +1000 Subject: Bulk Adding Methods Pythonically References: <1466014917.388175.638768225.2DAFD4E9@webmail.messagingengine.com> Message-ID: <5762030b$0$1617$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jun 2016 04:39 am, Rob Gaddi wrote: >> class Channel: >> frequency = mkmeasure('frequency', 'FREQ') >> falltime = mkmeasure('falltime', 'FTIM') > > Thought about it, but whenever I'm dropping 20-someodd of those there's > inevitably some place where I screw up the replication of the quoted > name and the bound name. So? You have unit tests, right? Add one more test that checks the names. You can even add that to your class definition code: NAMES = ('frequency', 'falltime') THINGIES = ('FREQ', 'FTIM') class Channel: for name, thingy in zip(NAMES, THINGIES): locals()[name] = mkmeasure(name, thingy) assert all(getattr(Channel, name).__name__ == name for name in NAMES) But at the point that you have 20+ almost identical methods, you should take that as a cold-smell. Why do you have so many almost identical methods? (That doesn't mean it is *necessarily* wrong, only that you have to think carefully about whether it is or not.) -- Steven From steve at pearwood.info Wed Jun 15 21:40:42 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 16 Jun 2016 11:40:42 +1000 Subject: for / while else doesn't make sense References: <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <97fd5175-0cc4-449d-a56d-bf7e238cbea3@googlegroups.com> <1466006041.357579.638625625.6C5C4E1D@webmail.messagingengine.com> Message-ID: <5762039a$0$1617$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jun 2016 03:03 am, Rustom Mody wrote: > So break also has its uses. Lets just not pretend its structured What's your definition of "structured" that makes "break" unstructured? Suppose I have a language, L, with a keyword "fnord". How do I tell whether the fnord feature makes the language unstructured or not? -- Steven From jobmattcon at gmail.com Wed Jun 15 21:42:27 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Wed, 15 Jun 2016 18:42:27 -0700 (PDT) Subject: how to for loop append a list [] when using parallel programming Message-ID: how to for loop append a list [] when using parallel programming From lawrencedo99 at gmail.com Wed Jun 15 21:59:04 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 15 Jun 2016 18:59:04 -0700 (PDT) Subject: Bulk Adding Methods Pythonically In-Reply-To: References: Message-ID: On Thursday, June 16, 2016 at 5:37:14 AM UTC+12, Rob Gaddi wrote: > I've got a whole lot of methods I want to add to my Channel class, all > of which following nearly the same form. The below code works, but > having to do the for loop outside of the main class definition feels > kludgey. No, that?s fine. Table-driven programming is a good technique, and I?ve done this sort of thing myself. > for fnname, measparam in ( > ... > def measmaker(p): Since this function makes no direct reference to ?fnname? or ?measparam?, why not move the definition to before the loop so it gets executed just once? > def inner(self, cursorarea=False): > ... > return inner And there, ladies and gentlemen, you see the benefits of functions as first-class objects. :) > setattr(Channel, fnname, measmaker(measparam)) I would follow the loop with a ?del fnname, measparam, measmaker", just to avoid polluting your module namespace with leftover debris. From jladasky at itu.edu Wed Jun 15 22:54:31 2016 From: jladasky at itu.edu (jladasky at itu.edu) Date: Wed, 15 Jun 2016 19:54:31 -0700 (PDT) Subject: PyQt5: is the wrapper incomplete? Message-ID: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> I am developing a data acquisition system for a custom device that communicates over USB. On the host computer side, I am using PyQt5.4. My Linux box has both Qt4 and Qt5 installed on it. I assume that PyQt5.4 compiled on top of Qt5 automatically. I'm not sure how to check that. In any case, I used PySerial to handle the USB communication. I just noticed that Qt also has serial features. I need to give the completed program to other users, on Windows no less. If I can forego PySerial and use Qt's serial interface instead, it would simplify the installation. Now, the PyQt5 documentation implies that a module called QtSerial exists. But while I can write... from PyQt5.QtWidgets import (...), or from PyQt5.QtGui import (...), or from PyQt5.QtCore import (...), ...attempting to import from PyQt5.QtSerial raises an ImportError. I've tried many variations on the spelling, and I've tried various import statements to inspect the (very large and complex) PyQt5 namespace. I haven't found the QtSerial classes. Are they even there? Maybe the wrapping of the library is incomplete? Any guidance is appreciated, thanks! From lawrencedo99 at gmail.com Wed Jun 15 22:54:57 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 15 Jun 2016 19:54:57 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> Message-ID: On Thursday, June 16, 2016 at 1:51:54 AM UTC+12, Random832 wrote: > ... and in particular it does not establish that break is in any way > less structured than any other constructs that have keywords. Interesting that those who objected to my use of while-True-break loops could not come up with any unified alternative way of writing them. Every single example I posted had to be handled differently, as opposed to my common way of dealing with them. From lawrencedo99 at gmail.com Wed Jun 15 22:59:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 15 Jun 2016 19:59:22 -0700 (PDT) Subject: for / while else doesn't make sense In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> Message-ID: <4becfad1-f095-4f12-a4f4-bac9aa12b0db@googlegroups.com> On Thursday, June 16, 2016 at 2:32:00 AM UTC+12, Rustom Mody wrote: > Here is C.A.R Hoare's Turing award speech: > https://www.cs.fsu.edu/~engelen/courses/COP4610/hoare.pdf > > in which (2nd last page) he claims that Ada is a threat to civilization... > because it has something as terrible as exceptions. He was wrong about the dangers of Ada. It has been successfully used in many life-critical situations (e.g. the life support system on the International Space Station). He was a fan of the simplicity of Pascal, though that speech says nothing about C (and C++ hadn?t been invented yet...). In the end, I guess, Pascal proved too fiddly to do things in that C could manage easily. From gordon at panix.com Wed Jun 15 23:17:33 2016 From: gordon at panix.com (John Gordon) Date: Thu, 16 Jun 2016 03:17:33 +0000 (UTC) Subject: how to for loop append a list [] when using parallel programming References: Message-ID: In meInvent bbird writes: > how to for loop append a list [] when using parallel programming items = [] for item in parallelized_object_factory(): items.append(item) If you want a more specific answer, ask a more specific question. -- 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 jobmattcon at gmail.com Wed Jun 15 23:23:44 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Wed, 15 Jun 2016 20:23:44 -0700 (PDT) Subject: how to for loop append a list [] when using parallel programming In-Reply-To: References: Message-ID: <6693dceb-7704-4457-947b-21c423e4d232@googlegroups.com> is there like c# have concurrent list ? i find something these, but how can it pass an initlist list variable is it doing the same function as itertools.combinations ? def comb(n, initlist): # the argument n is the number of items to select res = list(itertools.combinations(initlist, n)) # create a list from the iterator return res #p = Pool(8) #times = range(0, len(initlist)+1) #values = p.map(comb, times) # pass the range as the sequence of arguments! #p.close() #p.join() On Thursday, June 16, 2016 at 11:17:47 AM UTC+8, John Gordon wrote: > In meInvent bbird writes: > > > how to for loop append a list [] when using parallel programming > > items = [] > for item in parallelized_object_factory(): > items.append(item) > > If you want a more specific answer, ask a more specific question. > > -- > 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 jussi.piitulainen at helsinki.fi Thu Jun 16 01:39:23 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 16 Jun 2016 08:39:23 +0300 Subject: python regex: variable length of positive lookbehind assertion References: <8737oemsh9.fsf@elektro.pacujo.net> <0a2f2355-1b2d-4bc7-0113-e35266cb3fd7@gmail.com> Message-ID: Michael Torrie writes: > On 06/15/2016 08:57 AM, Jussi Piitulainen wrote: >> Marko Rauhamaa writes: >>> And nothing in alister's answer suggests that. >> >> Now *I'm* surprised. > > He simply said, here's a regex that can parse the example string the OP > gave us (which maybe looked a bit like HTML, but like you say, may not > be), but don't try to use this method to parse actual HTML because it > won't work reliably. Interesting how differently we can read alister's answer. It was only two sentences, one of which Marko replaced with "[...]" before adding his own one-liner that is still quoted above. Let me quote alister's response in full here, the way I see it in Gnus: # don't try to use regex to parse html it wont work reliably # i am surprised no one has mentioned beautifulsoup yet, which is probably # what you require. That followed the fully quoted original message, and then there was an attributed citation from a Bengamin Disraeli, separated as a .sig. Where in alister's original response do you see a regex that can parse OP's example? I don't see any regex there. (The text where you seem to me to say that there is one is still quoted above in the normal way.) Instead of giving any direct answer to the question, alister expresses surprise at nobody having suggested an HTML parser. (Marko snipped that, but I've quoted alister's response in full above, so you can check it without looking up the original messages.) A surprise calls for an explanation. Or should I say that I felt that this particular expression of surprise seemed to me to call for an explanation, or in the very least that an explanation would not do much harm and might even be considered mildly interesting. And I saw a fully adequate explanation: that the question was not about parsing HTML. So I said so. From rustompmody at gmail.com Thu Jun 16 01:48:33 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 15 Jun 2016 22:48:33 -0700 (PDT) Subject: What is structured programming (was for/while else doesn't make sense) In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> Message-ID: <3d4a1a33-a404-47ff-ac89-7787311945c0@googlegroups.com> On Thursday, June 16, 2016 at 8:25:10 AM UTC+5:30, Lawrence D?Oliveiro wrote: > On Thursday, June 16, 2016 at 1:51:54 AM UTC+12, Random832 wrote: > > ... and in particular it does not establish that break is in any way > > less structured than any other constructs that have keywords. > > Interesting that those who objected to my use of while-True-break loops could > not come up with any unified alternative way of writing them. Every single > example I posted had to be handled differently, as opposed to my common way of > dealing with them. Thanks for raising the example of your code -- I hesitated to do so :-) It answers better than I could Steven's very interesting question: "What's your definition of structured?" Everyone -- including Steven -- who commented on it did so with a variation on "Ugh!" , "Yikes!" etc. If you (Steven) takes these subjective/emotional outbursts and tries to objectivize them -- "What's there to ugh about?" I believe you will come to some definition of structured. Of course we could give a more formal definition -- I am not sure that line is so interesting. Should admit that I tried to look up 'structured' and found precious little? So here is the formal definition I remember from decades ago: A structured flow-graph is one that has a single point of entry and exit. And is recursively made from smaller structured flow graphs With a finite set of 'graph combinators' A structured program is one who's flow graph is structured As I said I dont find this definition very useful since break is unstructured as is return, yield and much else. Cognitively though it's the other way round: goto/break-filled code is -- in some informal sense -- more unstructured than return-filled code. And Ian's yield based code cleans up -- at least to most of our eyes/noses! -- your break-based code. Note that in terms of the formal definition, yield jumps around more than return jumps around more than break. Yet informally we (at least I) think of the generator def gen(): yield 1 yield 2 yield 3 not in terms of control flow but as data: a lazy, space-non-wasting form of the list [1,2,3] So what's a USEFUL definition of structured?? Interesting question! ----------------- ? Which probably proves that I am fast getting into the generation for which the picturesque Tamil saying applies: "House says Go! Go! Grave says Come Come!" From lawrencedo99 at gmail.com Thu Jun 16 01:57:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 15 Jun 2016 22:57:02 -0700 (PDT) Subject: What is structured programming (was for/while else doesn't make sense) In-Reply-To: <3d4a1a33-a404-47ff-ac89-7787311945c0@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <3d4a1a33-a404-47ff-ac89-7787311945c0@googlegroups.com> Message-ID: <7180ce45-9e59-443b-8303-e9492af9752d@googlegroups.com> On Thursday, June 16, 2016 at 5:48:48 PM UTC+12, Rustom Mody wrote: > On Thursday, June 16, 2016 at 8:25:10 AM UTC+5:30, Lawrence D?Oliveiro wrote: > So here is the formal definition I remember from decades ago: > > A structured flow-graph is one that has a single point of entry and exit. > And is recursively made from smaller structured flow graphs > With a finite set of 'graph combinators' > > A structured program is one who's flow graph is structured > > As I said I dont find this definition very useful since > break is unstructured as is return, yield and much else. On the contrary, it fits in nicely. Imagine trying to represent your code as a Nassi-Shneiderman diagram. This consists (recursively) of nested and/or concatenated sub-diagrams. Each piece has one entry point at the top, and one exit point at the bottom. In particular, it is *not possible* to express a goto that jumps from one arbitrary point to another--everything must strictly nest. For example, a loop is entered at the top, and exited at the bottom. A ?break? in the loop can cut it short, but it cannot violate this rule. Even my C code follows this nesting principle, because it is goto-free. From marko at pacujo.net Thu Jun 16 02:03:04 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 16 Jun 2016 09:03:04 +0300 Subject: python regex: variable length of positive lookbehind assertion References: <8737oemsh9.fsf@elektro.pacujo.net> <0a2f2355-1b2d-4bc7-0113-e35266cb3fd7@gmail.com> Message-ID: <87inx9llgn.fsf@elektro.pacujo.net> Jussi Piitulainen : > Michael Torrie writes: > >> On 06/15/2016 08:57 AM, Jussi Piitulainen wrote: >>> Marko Rauhamaa writes: >>>> And nothing in alister's answer suggests that. >>> >>> Now *I'm* surprised. >> >> He simply said, here's a regex that can parse the example string the OP >> gave us (which maybe looked a bit like HTML, but like you say, may not >> be), but don't try to use this method to parse actual HTML because it >> won't work reliably. > > Interesting how differently we can read alister's answer. It was only > two sentences, one of which Marko replaced with "[...]" before adding > his own one-liner that is still quoted above. > [...] > > That followed the fully quoted original message, and then there was an > attributed citation from a Bengamin Disraeli, separated as a .sig. > > [...] > > A surprise calls for an explanation. Or should I say that I felt that > this particular expression of surprise seemed to me to call for an > explanation, or in the very least that an explanation would not do much > harm and might even be considered mildly interesting. And I saw a fully > adequate explanation: that the question was not about parsing HTML. So I > said so. This is so meta. Marko From vincent.vande.vyvre at telenet.be Thu Jun 16 03:15:57 2016 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Thu, 16 Jun 2016 09:15:57 +0200 Subject: PyQt5: is the wrapper incomplete? In-Reply-To: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> References: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> Message-ID: <5762522D.6060804@telenet.be> Le 16/06/2016 04:54, jladasky at itu.edu a ?crit : > I am developing a data acquisition system for a custom device that communicates over USB. On the host computer side, I am using PyQt5.4. My Linux box has both Qt4 and Qt5 installed on it. I assume that PyQt5.4 compiled on top of Qt5 automatically. I'm not sure how to check that. > > In any case, I used PySerial to handle the USB communication. I just noticed that Qt also has serial features. I need to give the completed program to other users, on Windows no less. If I can forego PySerial and use Qt's serial interface instead, it would simplify the installation. > > Now, the PyQt5 documentation implies that a module called QtSerial exists. But while I can write... > > from PyQt5.QtWidgets import (...), or > from PyQt5.QtGui import (...), or > from PyQt5.QtCore import (...), > > ...attempting to import from PyQt5.QtSerial raises an ImportError. > > I've tried many variations on the spelling, and I've tried various import statements to inspect the (very large and complex) PyQt5 namespace. I haven't found the QtSerial classes. Are they even there? Maybe the wrapping of the library is incomplete? > > Any guidance is appreciated, thanks! On Debian, this is a separate package python3-pyqt5.qtserialport, I don't know for other Linux After install you can use: from PyQt5.QtSeriaPort import QSerialPort Vincent From list at qtrac.plus.com Thu Jun 16 03:22:19 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 16 Jun 2016 00:22:19 -0700 (PDT) Subject: PyQt5: is the wrapper incomplete? In-Reply-To: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> References: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> Message-ID: On Thursday, June 16, 2016 at 3:54:53 AM UTC+1, jlad... at itu.edu wrote: > I am developing a data acquisition system for a custom device that communicates over USB. On the host computer side, I am using PyQt5.4. My Linux box has both Qt4 and Qt5 installed on it. I assume that PyQt5.4 compiled on top of Qt5 automatically. I'm not sure how to check that. In IDLE or at some other Python prompt or in a tiny test.py file: from PyQt5 import QtCore print(QtCore.qVersion()) > In any case, I used PySerial to handle the USB communication. I just noticed that Qt also has serial features. I need to give the completed program to other users, on Windows no less. If I can forego PySerial and use Qt's serial interface instead, it would simplify the installation. > > Now, the PyQt5 documentation implies that a module called QtSerial exists. But while I can write... > > from PyQt5.QtWidgets import (...), or > from PyQt5.QtGui import (...), or > from PyQt5.QtCore import (...), > > ...attempting to import from PyQt5.QtSerial raises an ImportError. > > I've tried many variations on the spelling, and I've tried various import statements to inspect the (very large and complex) PyQt5 namespace. I haven't found the QtSerial classes. Are they even there? Maybe the wrapping of the library is incomplete? In Ubuntu 14.04 there is no QtSerial or QtSerialPort. > Any guidance is appreciated, thanks! The best place to ask about the PyQt bindings is the PyQt mailing list: https://www.riverbankcomputing.com/mailman/listinfo/pyqt From list at qtrac.plus.com Thu Jun 16 03:25:04 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 16 Jun 2016 00:25:04 -0700 (PDT) Subject: PyQt5: is the wrapper incomplete? In-Reply-To: References: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> Message-ID: On Thursday, June 16, 2016 at 8:22:33 AM UTC+1, Mark Summerfield wrote: > On Thursday, June 16, 2016 at 3:54:53 AM UTC+1, jlad... at itu.edu wrote: > > I am developing a data acquisition system for a custom device that communicates over USB. On the host computer side, I am using PyQt5.4. My Linux box has both Qt4 and Qt5 installed on it. I assume that PyQt5.4 compiled on top of Qt5 automatically. I'm not sure how to check that. > > In IDLE or at some other Python prompt or in a tiny test.py file: > > from PyQt5 import QtCore > print(QtCore.qVersion()) > > > In any case, I used PySerial to handle the USB communication. I just noticed that Qt also has serial features. I need to give the completed program to other users, on Windows no less. If I can forego PySerial and use Qt's serial interface instead, it would simplify the installation. > > > > Now, the PyQt5 documentation implies that a module called QtSerial exists. But while I can write... > > > > from PyQt5.QtWidgets import (...), or > > from PyQt5.QtGui import (...), or > > from PyQt5.QtCore import (...), > > > > ...attempting to import from PyQt5.QtSerial raises an ImportError. > > > > I've tried many variations on the spelling, and I've tried various import statements to inspect the (very large and complex) PyQt5 namespace. I haven't found the QtSerial classes. Are they even there? Maybe the wrapping of the library is incomplete? > > In Ubuntu 14.04 there is no QtSerial or QtSerialPort. Sorry, my mistake, you have to install it as a separate package as Vincent explained. From jobmattcon at gmail.com Thu Jun 16 03:28:51 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 16 Jun 2016 00:28:51 -0700 (PDT) Subject: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool? Message-ID: <7c34b140-ac0d-4840-8c30-e967e83aae4a@googlegroups.com> is there like c# have concurrent list ? i find something these, but how can it pass an initlist list variable is it doing the same function as itertools.combinations ? def comb(n, initlist): # the argument n is the number of items to select res = list(itertools.combinations(initlist, n)) # create a list from the iterator return res #p = Pool(8) #times = range(0, len(initlist)+1) #values = p.map(comb, times) # pass the range as the sequence of arguments! #p.close() #p.join() From asimkostas at gmail.com Thu Jun 16 04:17:47 2016 From: asimkostas at gmail.com (asimkon) Date: Thu, 16 Jun 2016 11:17:47 +0300 Subject: mod_python compilation error Message-ID: Regarding my blog post , i would like to inform you that someone helped me to overcome this error but i got another one that i do not know it's meaning: error: [Errno 22] invalid mode ('wb') or filename: "dist\\mod_python-'{' \x9b\x9 c\xa4 \x98\xa4\x98\x9a\xa4\xe0\xa8\xe5\x9d\x9c\xab\x98\xa0 \xe0\xaa \x9c\xa9\xe0 \xab\x9c\xa8\xa0\xa1\xe3 \xe3 \x9c\xa5\xe0\xab\x9c\xa8\xa0\xa1\xe3 \x9c\xa4\xab\ xa6\xa2\xe3,\n\x9c\xa1\xab\x9c\xa2\xe2\xa9\xa0\xa3\xa6 \xa7\xa8\xe6\x9a\xa8\x98\ xa3\xa3\x98 \xe3 \x98\xa8\xae\x9c\xe5\xa6 \x9b\xe2\xa9\xa3\x9e\xaa \x9c\xa4\x9c\ xa8\x9a\x9c\xa0\xe9\xa4..win32-py2.7.exe" Any idea would help me a lot? Regards Kostas Asimakopoulos From gandalf at shopzeus.com Thu Jun 16 04:25:31 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Thu, 16 Jun 2016 10:25:31 +0200 Subject: python 3 + milter Message-ID: <701d3806-10dd-c754-fea9-628d55dfecb9@shopzeus.com> Does anyone know a module that can be used to write a before-queue, smtpd time milter with Python 3? Unfortunately, pymilter does not work with Python 3: Downloading https://pypi.python.org/packages/58/2f/d4799c9cade461177955ca19ade6ca55385286f066c0db9a0770a332ab8a/pymilter-1.0.tar.gz#md5=ec9b95fed2bc083d5f6a801bc150c253 Processing pymilter-1.0.tar.gz Writing /tmp/easy_install-_eqt8c9r/pymilter-1.0/setup.cfg Running pymilter-1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-_eqt8c9r/pymilter-1.0/egg-dist-tmp-o1n6sd1x miltermodule.c:349:1: error: unknown type name 'staticforward' staticforward struct smfiDesc description; /* forward declaration */ ^ miltermodule.c:349:15: error: expected identifier or '(' staticforward struct smfiDesc description; /* forward declaration */ ^ miltermodule.c:361:1: error: unknown type name 'staticforward' staticforward PyTypeObject milter_ContextType; ^ miltermodule.c:361:27: error: expected ';' after top level declarator staticforward PyTypeObject milter_ContextType; ^ I have a complete program that works with email.Message messages, but I don't know how to use it with postfix. A workaround would be to construct the message from python2 + pymilter, and start a subprocess for the message processing, but that is obviously bad. Thanks, Laszlo From steve+comp.lang.python at pearwood.info Thu Jun 16 04:30:10 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 16 Jun 2016 18:30:10 +1000 Subject: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool? References: <7c34b140-ac0d-4840-8c30-e967e83aae4a@googlegroups.com> Message-ID: <57626394$0$2780$c3e8da3$76491128@news.astraweb.com> On Thursday 16 June 2016 17:28, meInvent bbird wrote: > is there like c# have concurrent list ? What is a concurrent list? Can you link to the C# documentation for this? To me, "concurrent" describes a style of execution flow, and "list" describes a data structure. I am struggling to understand what "concurrent list" means. > i find something these, but how can it pass an initlist list variable initlist = ['a', 'b', 'c'] result = comb(n, initlist) # pass initlist > is it doing the same function as itertools.combinations ? It is calling itertools.combinations. So, yes, it is doing the same function as itertools.combinations. > def comb(n, initlist): # the argument n is the number of items to select > res = list(itertools.combinations(initlist, n)) # create a list from the > # iterator > return res This does not generate the combinations in parallel. It generates them one at a time, and then creates a list of them. This is an interesting question. Somebody could probably write a parallel version of combinations. But I don't know that it would be very useful -- the limiting factor on combinations is more likely to be memory, not time. Suppose you generate combinations of 100 items, taken 10 at a time. If I remember the formula for combinations correctly, the total number of combinations is: 100!/(10! * 90!) = 17310309456440 combinations in total. If each generated combination took just *one* byte of memory, that would require over 17 TB of RAM. -- Steve From ablacktshirt at gmail.com Thu Jun 16 04:34:33 2016 From: ablacktshirt at gmail.com (Yubin Ruan) Date: Thu, 16 Jun 2016 01:34:33 -0700 (PDT) Subject: Multiline parsing of python compiler demistification needed Message-ID: <930753e3-4c9c-45e9-9117-d340c033ac66@googlegroups.com> Hi, everyone, I have some problem understand the rule which the python compiler use to parsing the multiline string. Consider this snippet: str_1 = "foo" str_2 = "bar" print "A test case" + \ "str_1[%s] " + \ "str_2[%s] " % (str_1, str_2) Why would the snippet above give me an "TypeError: not all arguments converted during string formatting" while the one below not ? print "A test case" + \ "str_1[%s] " % str1 Obviously the first snippet have just one more line and one more argument to format than the second one. Isn't that unreasonable ? I couldn't find any clue about that. Anyone help ? I am using python 2.7.6 Also, I know the **Pythonic** way to play with multiline, which would be using triple quote or a pair of parenthesis to surround the multiline string to make it a **online** string. You don't have to show code in that respect. Thanks in advance! Ruan. From steve+comp.lang.python at pearwood.info Thu Jun 16 04:41:39 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 16 Jun 2016 18:41:39 +1000 Subject: Python 3.6.0a2 is now available References: <2fac7f7a-00ed-456a-9240-04b09ef10d63@googlegroups.com> <087d80a4-edd1-30a7-a093-59099e9f398d@mrabarnett.plus.com> Message-ID: <57626645$0$1531$c3e8da3$5496439d@news.astraweb.com> On Thursday 16 June 2016 14:36, Lawrence D?Oliveiro wrote: > On Thursday, June 16, 2016 at 2:19:33 AM UTC+12, MRAB wrote: > >> Coincidentally, there was recently a discussion on the python-dev list >> about whether to switch to C99. > > Only slightly less than a generation after it came out... You say that as if this is the first time that anyone has raised this issue. It comes up, oh, at least once a year, sometimes more. Like the last few dozen times, the answer is still no, we still can't switch to requiring C99 yet, as there are still users that rely on compilers with partial support for C99. But unlike previous times, now we can begin to use some C99 features, provided they are available on the important C compilers we support. https://mail.python.org/pipermail/python-dev/2016-June/144876.html You should read the whole thread before commenting: https://mail.python.org/pipermail/python-dev/2016-June/144816.html -- Steve From jobmattcon at gmail.com Thu Jun 16 04:45:37 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 16 Jun 2016 01:45:37 -0700 (PDT) Subject: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool? In-Reply-To: <57626394$0$2780$c3e8da3$76491128@news.astraweb.com> References: <7c34b140-ac0d-4840-8c30-e967e83aae4a@googlegroups.com> <57626394$0$2780$c3e8da3$76491128@news.astraweb.com> Message-ID: <90fdccc7-ead5-4a31-99d2-f1ad37ba496e@googlegroups.com> the name in c# is not called concurrent list, it is called blockingcollection dictionary called concurrent dictionary thread safe these kind of things https://msdn.microsoft.com/en-us/library/dd267312(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/dd997369(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/dd997305(v=vs.110).aspx On Thursday, June 16, 2016 at 4:30:33 PM UTC+8, Steven D'Aprano wrote: > On Thursday 16 June 2016 17:28, meInvent bbird wrote: > > > is there like c# have concurrent list ? > > What is a concurrent list? > > Can you link to the C# documentation for this? > > To me, "concurrent" describes a style of execution flow, and "list" describes a > data structure. I am struggling to understand what "concurrent list" means. > > > i find something these, but how can it pass an initlist list variable > > initlist = ['a', 'b', 'c'] > result = comb(n, initlist) # pass initlist > > > > is it doing the same function as itertools.combinations ? > > It is calling itertools.combinations. So, yes, it is doing the same function as > itertools.combinations. > > > > def comb(n, initlist): # the argument n is the number of items to select > > res = list(itertools.combinations(initlist, n)) # create a list from the > > # iterator > > return res > > This does not generate the combinations in parallel. It generates them one at a > time, and then creates a list of them. > > This is an interesting question. Somebody could probably write a parallel > version of combinations. But I don't know that it would be very useful -- the > limiting factor on combinations is more likely to be memory, not time. > > Suppose you generate combinations of 100 items, taken 10 at a time. If I > remember the formula for combinations correctly, the total number of > combinations is: > > 100!/(10! * 90!) = 17310309456440 > > combinations in total. If each generated combination took just *one* byte of > memory, that would require over 17 TB of RAM. > > > > -- > Steve From jobmattcon at gmail.com Thu Jun 16 04:47:21 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 16 Jun 2016 01:47:21 -0700 (PDT) Subject: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool? In-Reply-To: <57626394$0$2780$c3e8da3$76491128@news.astraweb.com> References: <7c34b140-ac0d-4840-8c30-e967e83aae4a@googlegroups.com> <57626394$0$2780$c3e8da3$76491128@news.astraweb.com> Message-ID: how can list be synchronized when multiprocessor working in it? will one thread updating non-updated version, but another processor updating the version? On Thursday, June 16, 2016 at 4:30:33 PM UTC+8, Steven D'Aprano wrote: > On Thursday 16 June 2016 17:28, meInvent bbird wrote: > > > is there like c# have concurrent list ? > > What is a concurrent list? > > Can you link to the C# documentation for this? > > To me, "concurrent" describes a style of execution flow, and "list" describes a > data structure. I am struggling to understand what "concurrent list" means. > > > i find something these, but how can it pass an initlist list variable > > initlist = ['a', 'b', 'c'] > result = comb(n, initlist) # pass initlist > > > > is it doing the same function as itertools.combinations ? > > It is calling itertools.combinations. So, yes, it is doing the same function as > itertools.combinations. > > > > def comb(n, initlist): # the argument n is the number of items to select > > res = list(itertools.combinations(initlist, n)) # create a list from the > > # iterator > > return res > > This does not generate the combinations in parallel. It generates them one at a > time, and then creates a list of them. > > This is an interesting question. Somebody could probably write a parallel > version of combinations. But I don't know that it would be very useful -- the > limiting factor on combinations is more likely to be memory, not time. > > Suppose you generate combinations of 100 items, taken 10 at a time. If I > remember the formula for combinations correctly, the total number of > combinations is: > > 100!/(10! * 90!) = 17310309456440 > > combinations in total. If each generated combination took just *one* byte of > memory, that would require over 17 TB of RAM. > > > > -- > Steve From jussi.piitulainen at helsinki.fi Thu Jun 16 04:50:21 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 16 Jun 2016 11:50:21 +0300 Subject: Multiline parsing of python compiler demistification needed References: <930753e3-4c9c-45e9-9117-d340c033ac66@googlegroups.com> Message-ID: Yubin Ruan writes: > Hi, everyone, I have some problem understand the rule which the python > compiler use to parsing the multiline string. > > Consider this snippet: > > str_1 = "foo" > str_2 = "bar" > > print "A test case" + \ > "str_1[%s] " + \ > "str_2[%s] " % (str_1, str_2) > > Why would the snippet above give me an "TypeError: not all arguments > converted during string formatting" while the one below not ? > > print "A test case" + \ > "str_1[%s] " % str1 > > Obviously the first snippet have just one more line and one more > argument to format than the second one. Isn't that unreasonable ? I > couldn't find any clue about that. Anyone help ? Multiline is irrelevant. What is happening is that % binds more tightly (has a higher precedence) than +. print "foo" + "bar %s" % "baz" ==> foobar baz print "foo %s" + "bar %s" % ("baz", "baz") ==> Traceback (most recent call last): File "", line 1, in TypeError: not all arguments converted during string formatting print ("foo %s" + "bar %s") % ("baz", "baz") ==> foo bazbar baz From __peter__ at web.de Thu Jun 16 04:55:12 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Jun 2016 10:55:12 +0200 Subject: Multiline parsing of python compiler demistification needed References: <930753e3-4c9c-45e9-9117-d340c033ac66@googlegroups.com> Message-ID: Yubin Ruan wrote: > Hi, everyone, I have some problem understand the rule which the python > compiler use to parsing the multiline string. > > Consider this snippet: > > str_1 = "foo" > str_2 = "bar" > > print "A test case" + \ > "str_1[%s] " + \ > "str_2[%s] " % (str_1, str_2) > > Why would the snippet above give me an "TypeError: not all arguments > converted during string formatting" while the one below not ? > > print "A test case" + \ > "str_1[%s] " % str1 > > Obviously the first snippet have just one more line and one more argument > to format than the second one. Isn't that unreasonable ? I couldn't find > any clue about that. Anyone help ? > > I am using python 2.7.6 > It doesn't matter into how many lines you break your statement. The % operator has higher precedence than +, so a + b % c is evaluated as a + (b % c). When c is a 2-tuple and b contains only one "%s" that inevitably fails: >>> "%s" + "%s" % (1, 2) Traceback (most recent call last): File "", line 1, in TypeError: not all arguments converted during string formatting > Also, I know the **Pythonic** way to play with multiline, which would be > using triple quote or a pair of parenthesis to surround the multiline > string to make it a **online** string. You don't have to show code in that > respect. Did you know that adjacent string literals are merged into one? Compare: >>> print "foo" + \ ... "%s" + \ ... "%s" % (1, 2) Traceback (most recent call last): File "", line 3, in TypeError: not all arguments converted during string formatting >>> print "foo" \ ... "%s" \ ... "%s" % (1, 2) foo12 From frank at chagford.com Thu Jun 16 05:00:29 2016 From: frank at chagford.com (Frank Millman) Date: Thu, 16 Jun 2016 11:00:29 +0200 Subject: Multiline parsing of python compiler demistification needed In-Reply-To: <930753e3-4c9c-45e9-9117-d340c033ac66@googlegroups.com> References: <930753e3-4c9c-45e9-9117-d340c033ac66@googlegroups.com> Message-ID: "Yubin Ruan" wrote in message news:930753e3-4c9c-45e9-9117-d340c033ac66 at googlegroups.com... > Hi, everyone, I have some problem understand the rule which the python > compiler use to parsing the multiline string. > > Consider this snippet: > > str_1 = "foo" > str_2 = "bar" > > print "A test case" + \ > "str_1[%s] " + \ > "str_2[%s] " % (str_1, str_2) > > Why would the snippet above give me an "TypeError: not all arguments > converted during string formatting" while the one below not ? This has nothing to do with multi-line strings. Try that as a single line - print "A test case " + "str_1[%s] " + "str_2[%s]" % (str_1, str_2) You will get the same error message. The reason is that the use of the '+' sign to concatenate strings requires that each sub-string is a valid string in its own right. The correct way to write it is - print "A test case " + "str_1[%s] " % (str_1) + "str_2[%s]" % (str_2) If you wrote it without the '+' signs, the answer would be different. Python treats contiguous strings as a single string, so you could write it like this - print "A test case " "str_1[%s] " "str_2[%s]" % (str_1, str_2) Frank Millman From rustompmody at gmail.com Thu Jun 16 07:12:52 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 16 Jun 2016 04:12:52 -0700 (PDT) Subject: What is structured programming (was for/while else doesn't make sense) In-Reply-To: <7180ce45-9e59-443b-8303-e9492af9752d@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <3d4a1a33-a404-47ff-ac89-7787311945c0@googlegroups.com> <7180ce45-9e59-443b-8303-e9492af9752d@googlegroups.com> Message-ID: <17c484d6-e741-4b24-bed0-cf19b57012a4@googlegroups.com> On Thursday, June 16, 2016 at 11:27:15 AM UTC+5:30, Lawrence D?Oliveiro wrote: > On Thursday, June 16, 2016 at 5:48:48 PM UTC+12, Rustom Mody wrote: > > On Thursday, June 16, 2016 at 8:25:10 AM UTC+5:30, Lawrence D?Oliveiro wrote: > > So here is the formal definition I remember from decades ago: > > > > A structured flow-graph is one that has a single point of entry and exit. > > And is recursively made from smaller structured flow graphs > > With a finite set of 'graph combinators' > > > > A structured program is one who's flow graph is structured > > > > As I said I dont find this definition very useful since > > break is unstructured as is return, yield and much else. > > On the contrary, it fits in nicely. Imagine trying to represent your code as a Nassi-Shneiderman diagram. This consists (recursively) of nested and/or concatenated sub-diagrams. Each piece has one entry point at the top, and one exit point at the bottom. In particular, it is *not possible* to express a goto that jumps from one arbitrary point to another--everything must strictly nest. > > For example, a loop is entered at the top, and exited at the bottom. A ?break? in the loop can cut it short, but it cannot violate this rule. > > Even my C code follows this nesting principle, because it is goto-free. Please see https://en.wikipedia.org/wiki/Nassi%E2%80%93Shneiderman_diagram | Nassi?Shneiderman diagrams have no representation for a GOTO statement. which seems to be what you are saying. But then next para goes on... | Nassi?Shneiderman diagrams are (almost) isomorphic with | flowcharts. Everything you can represent with a Nassi?Shneiderman | diagram you can also represent with a flowchart. For flowcharts | of programs, almost everything you can represent with a flowchart | you can also represent with a Nassi?Shneiderman diagram. The | exceptions are constructs like goto and the C programming | language break and continue statements for loops. which is in line with what I am saying, viz that break/continue/goto are same in the sense of being 'unstructured' and therefore do not fit into a structured framework like NSDs From asimkostas at gmail.com Thu Jun 16 07:27:27 2016 From: asimkostas at gmail.com (asimkostas at gmail.com) Date: Thu, 16 Jun 2016 04:27:27 -0700 (PDT) Subject: mod_python compilation error in VS 2008 for py2.7.1 In-Reply-To: <1fc95d51-cac1-4906-8ef8-5b8227563f66@googlegroups.com> References: <1fc95d51-cac1-4906-8ef8-5b8227563f66@googlegroups.com> Message-ID: <2b32d734-9f8f-4ceb-a9d6-f066ce6ecb2f@googlegroups.com> ?? ?????, 14 ??????? 2016 - 3:36:23 ?.?. UTC+3, ? ??????? Pavel S ??????: > Have you considered to use rather WSGI-based solution? (for Apache Httpd is mod_wsgi). Mod_python is totally obsolete. Regarding my blog post, i would like to inform you that someone helped me to overcome this error but i got another one that i do not know it's meaning: deleted #define ssize_t error: [Errno 22] invalid mode ('wb') or filename: "dist\\mod_python-'{' \x9b\x9 c\xa4 \x98\xa4\x98\x9a\xa4\xe0\xa8\xe5\x9d\x9c\xab\x98\xa0 \xe0\xaa \x9c\xa9\xe0 \xab\x9c\xa8\xa0\xa1\xe3 \xe3 \x9c\xa5\xe0\xab\x9c\xa8\xa0\xa1\xe3 \x9c\xa4\xab\ xa6\xa2\xe3,\n\x9c\xa1\xab\x9c\xa2\xe2\xa9\xa0\xa3\xa6 \xa7\xa8\xe6\x9a\xa8\x98\ xa3\xa3\x98 \xe3 \x98\xa8\xae\x9c\xe5\xa6 \x9b\xe2\xa9\xa3\x9e\xaa \x9c\xa4\x9c\ xa8\x9a\x9c\xa0\xe9\xa4..win32-py2.7.exe" Any idea would help me a lot? Attached file for more information! Regards Kostas Asimakopoulos From lists at juliensalort.org Thu Jun 16 11:53:02 2016 From: lists at juliensalort.org (Julien Salort) Date: Thu, 16 Jun 2016 17:53:02 +0200 Subject: Bulk Adding Methods Pythonically References: <5761A678.8010003@stoneleaf.us> Message-ID: <1moy6yz.d13evh1ofkjsiN%lists@juliensalort.org> Ethan Furman wrote: > If that is all correct, then, as Random suggested, move that loop into > the class body and use locals() [1] to update the class dictionary. > Just make sure and delete any temporary variables.[ [...] > [1] https://docs.python.org/3/library/functions.html#locals > Yes, returning the class namespace is a language gaurantee. But that says: "Note The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter." -- Julien Salort Entia non sunt multiplicanda praeter necessitatem http://www.juliensalort.org From random832 at fastmail.com Thu Jun 16 12:15:08 2016 From: random832 at fastmail.com (Random832) Date: Thu, 16 Jun 2016 12:15:08 -0400 Subject: Bulk Adding Methods Pythonically In-Reply-To: <5761A678.8010003@stoneleaf.us> References: <5761A678.8010003@stoneleaf.us> Message-ID: <1466093708.1546731.639770593.4D6E2982@webmail.messagingengine.com> On Wed, Jun 15, 2016, at 15:03, Ethan Furman wrote: > [1] https://docs.python.org/3/library/functions.html#locals > Yes, returning the class namespace is a language gaurantee. How do you get a guarantee from that text? I don't see any definition asserting that the "current local symbol table" is the class namespace (more specifically, the object returned by (metaclass).__prepare__, which will be copied into [not used as, for normal types] (class).__dict__). We *know* that "representing the current local symbol table" can and often does mean "copied from the local symbol table which is not a in fact a dictionary" rather than "being the local symbol table which is a real dictionary object" (that's *why*, after all, updating locals() doesn't work in the general case), nor does it mention any exemption to the warning about updating it. If there's a guarantee of this, it's somewhere else. From steve at pearwood.info Thu Jun 16 13:36:02 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 17 Jun 2016 03:36:02 +1000 Subject: Bulk Adding Methods Pythonically References: <5761A678.8010003@stoneleaf.us> <1moy6yz.d13evh1ofkjsiN%lists@juliensalort.org> Message-ID: <5762e384$0$1618$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Jun 2016 01:53 am, Julien Salort wrote: > Ethan Furman wrote: > >> If that is all correct, then, as Random suggested, move that loop into >> the class body and use locals() [1] to update the class dictionary. >> Just make sure and delete any temporary variables.[ > [...] >> [1] https://docs.python.org/3/library/functions.html#locals >> Yes, returning the class namespace is a language gaurantee. > > But that says: > "Note The contents of this dictionary should not be modified; changes > may not affect the values of local and free variables used by the > interpreter." That only applies to locals() inside a function. The intent of locals() inside a class is to be writable, and if the docs don't explicitly make that guarantee, they should. http://bugs.python.org/issue27335 -- Steven From ethan at stoneleaf.us Thu Jun 16 15:58:58 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Jun 2016 12:58:58 -0700 Subject: Bulk Adding Methods Pythonically In-Reply-To: <1466093708.1546731.639770593.4D6E2982@webmail.messagingengine.com> References: <5761A678.8010003@stoneleaf.us> <1466093708.1546731.639770593.4D6E2982@webmail.messagingengine.com> Message-ID: <20160616195858.GA5268@stoneleaf.us> On 06/16, Random832 wrote: > On Wed, Jun 15, 2016, at 15:03, Ethan Furman wrote: >> [1] https://docs.python.org/3/library/functions.html#locals >> Yes, returning the class namespace is a language gaurantee. > > How do you get a guarantee from that text? Oops, my bad -- the gaurantee is in the vars() description on the same page... although that still isn't very clear about during-class-construction; okay, I'll have to chime in on the issue Steven opened. -- ~Ethan~ From harrison.chudleigh1 at education.nsw.gov.au Thu Jun 16 18:25:20 2016 From: harrison.chudleigh1 at education.nsw.gov.au (Harrison Chudleigh) Date: Fri, 17 Jun 2016 08:25:20 +1000 Subject: Contradictory error messages in Python 3.4 - standard library issue! Message-ID: While working on a program, I ran into an error with the usage of the module tokenize. The following message was displayed. File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", line 467, in tokenize encoding, consumed = detect_encoding(readline) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", line 409, in detect_encoding if first.startswith(BOM_UTF8): TypeError: startswith first arg must be str or a tuple of str, not bytes Undaunted, I changed the error on line 409. The line then read: if first.startswith(BOM_UTF8): ******************************************************************************* This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. From harrison.chudleigh1 at education.nsw.gov.au Thu Jun 16 18:31:46 2016 From: harrison.chudleigh1 at education.nsw.gov.au (Harrison Chudleigh) Date: Fri, 17 Jun 2016 08:31:46 +1000 Subject: Re - Contradictory error messages in Python 3.4 - standard library issue! Message-ID: Sorry! I was trying to indent a line and accidentally sent only half of the message. As I was saying, I changed the line and reran the program. However, this produced another group of error messages. One was - File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", line 438, in open encoding, lines = detect_encoding(buffer.readline) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", line 409, in detect_encoding if first.startswith('BOM_UTF8'): TypeError: startswith first arg must be bytes or a tuple of bytes, not str. So, first the interpreter says startswith() takes strings, now it says it takes bytes? What should the module be doing? This is an error with the standard library of Python 3.4.1, Mac OS X. ******************************************************************************* This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. From ned at nedbatchelder.com Thu Jun 16 19:03:40 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 16 Jun 2016 16:03:40 -0700 (PDT) Subject: Re - Contradictory error messages in Python 3.4 - standard library issue! In-Reply-To: References: Message-ID: <2e631b7f-58b3-46b3-a07a-9730d0aa16f9@googlegroups.com> On Thursday, June 16, 2016 at 6:39:27 PM UTC-4, Harrison Chudleigh wrote: > Sorry! I was trying to indent a line and accidentally sent only half of the > message. > > As I was saying, I changed the line and reran the program. However, this > produced another group of error messages. One was - > File > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 438, in open > encoding, lines = detect_encoding(buffer.readline) > File > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 409, in detect_encoding > if first.startswith('BOM_UTF8'): > TypeError: startswith first arg must be bytes or a tuple of bytes, not str. > So, first the interpreter says startswith() takes strings, now it says it > takes bytes? What should the module be doing? > This is an error with the standard library of Python 3.4.1, Mac OS X. You shouldn't have to edit the stdlib files to get your program to work. It sounds like you are using values with the tokenize module that it isn't expecting. Can you show your code? --Ned. From m at funkyhat.org Thu Jun 16 19:38:19 2016 From: m at funkyhat.org (Matt Wheeler) Date: Thu, 16 Jun 2016 23:38:19 +0000 Subject: Re - Contradictory error messages in Python 3.4 - standard library issue! In-Reply-To: References: Message-ID: On Thu, 16 Jun 2016, 23:31 Harrison Chudleigh, < harrison.chudleigh1 at education.nsw.gov.au> wrote: > Sorry! I was trying to indent a line and accidentally sent only half of the > message. > It would be helpful if your reply was actually a reply to your previous message, to enable us to follow the thread of the conversation. As I was saying, I changed the line and reran the program. However, this > produced another group of error messages. One was - > >From what, to what? Just showing us stacktraces means we have to guess at the problem. File > > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 438, in open > encoding, lines = detect_encoding(buffer.readline) > File > > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 409, in detect_encoding > if first.startswith('BOM_UTF8'): > TypeError: startswith first arg must be bytes or a tuple of bytes, not str. > So, first the interpreter says startswith() takes strings, now it says it > takes bytes? What should the module be doing? > The reason you're getting seemingly contradictory error messages is that `.startswith()` is a method which belongs to the `first` object, and that object is a different type between the first and the second time it's called. Both the `bytes` and `str` types have a `startswith` method, but each one (understandably) only accepts an argument of the same type. Without actually seeing your code I can't guess what the cause of that is, but perhaps you need to decode a `bytes` object to a `str` or encode the other way around. From lawrencedo99 at gmail.com Thu Jun 16 21:53:11 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 16 Jun 2016 18:53:11 -0700 (PDT) Subject: What is structured programming (was for/while else doesn't make sense) In-Reply-To: <17c484d6-e741-4b24-bed0-cf19b57012a4@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <3d4a1a33-a404-47ff-ac89-7787311945c0@googlegroups.com> <7180ce45-9e59-443b-8303-e9492af9752d@googlegroups.com> <17c484d6-e741-4b24-bed0-cf19b57012a4@googlegroups.com> Message-ID: <2a91ecef-a71b-4523-8912-3511d7c8e211@googlegroups.com> On Thursday, June 16, 2016 at 11:13:14 PM UTC+12, Rustom Mody wrote: > Please see https://en.wikipedia.org/wiki/Nassi%E2%80%93Shneiderman_diagram > > | Nassi?Shneiderman diagrams are (almost) isomorphic with > | flowcharts. Everything you can represent with a Nassi?Shneiderman > | diagram you can also represent with a flowchart. > > which is in line with what I am saying, viz that break/continue/goto are same > in the sense of being 'unstructured' and therefore do not fit into a > structured framework like NSDs This is just a restatement of the ?structure theorem?, which proves that structured control statements are mathematically equivalent to gotos, and anything that can be expressed one way can be expressed the other way. True, but a complete red herring. From steve at pearwood.info Thu Jun 16 21:58:57 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 17 Jun 2016 11:58:57 +1000 Subject: Contradictory error messages in Python 3.4 - standard library issue! References: Message-ID: <57635963$0$1588$c3e8da3$5496439d@news.astraweb.com> Hi Harrison, and welcome! On Fri, 17 Jun 2016 08:25 am, Harrison Chudleigh wrote: > While working on a program, I ran into an error with the usage of the > module tokenize. So you have an error with the use of tokenize. Fair enough. But why do you imagine that the errors lies in the module itself, rather that your use of it? There are probably tens of thousands, maybe hundreds of thousands, of people using that module (directly or indirectly). The chances that you have identified a bug in the module that nobody else has seen before is pretty slim. And that certainly shouldn't be your first assumption. > The following message was displayed. > File > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 467, in tokenize > encoding, consumed = detect_encoding(readline) > File > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 409, in detect_encoding > if first.startswith(BOM_UTF8): > TypeError: startswith first arg must be str or a tuple of str, not bytes > Undaunted, I changed the error on line 409. The line then read: > > if first.startswith(BOM_UTF8): I'm not seeing any actual difference between the before and after: if first.startswith(BOM_UTF8): if first.startswith(BOM_UTF8): but in another email, you state that you changed it to: if first.startswith('BOM_UTF8'): Changing the source code of the standard library is almost never what you want to be do. I've been programming in Python for 20+ years, and the number of times I've edited the source code of the standard library to fix a program is exactly zero. But making random changes to the source code of the standard library without understanding what it is doing or why is NEVER what you want to do. All you have accomplished by editing the code is changing the situation from "one in a 100,000 chance of a bug in the standard library" to "certainly a bug in a non-standard module shared by absolutely nobody else in the world". Before we can help you, you MUST revert the module back to the way it was. You have introduced a bug to the module, but worse, you've now made it so that it is different from everyone else's tokenize module. Any errors you have received after making that change, or changes, are irrelevant. Then you need to show us how you are calling tokenize. Show us the ENTIRE traceback, starting with the line beginning "Traceback", not just the last line with the error message. Once we've seen that, we may be able to help you, or we may have more questions, but that's the bare minimum we need. -- Steven From lawrencedo99 at gmail.com Thu Jun 16 22:02:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 16 Jun 2016 19:02:09 -0700 (PDT) Subject: Method Chaining Message-ID: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> Some kinds of objects often receive a whole lot of method calls in sequence. In these situations, it is handy if each method call ends with ?return self?, so that you can chain the calls together. This is particularly common with graphics APIs, for instance. Example from , concisely expressing a complex drawing sequence: (g .move_to((p1 + p2a) / 2) .line_to(p1 + (p2 - p1) * frac) .line_to((p1 + p1a) / 2) .stroke() .move_to((p2 + p2a) / 2) .line_to(p2 + (p1 - p2) * frac) .line_to((p2 + p1a) / 2) .stroke() ) Another example , where an object requires setup calls that cannot all be expressed in the constructor: pattern = \ qah.Pattern.create_linear \ ( p0 = (0, 0), p1 = (pattern_length, 0), # base orientation is parallel to X-axis colour_stops = ( (0, Colour.from_hsva((0.475, 0.9, 0.8))), (1, Colour.from_hsva((0.975, 0.9, 0.8))), ) ).set_extend(CAIRO.EXTEND_REPEAT) In , a temporary drawing context is created, used to create the image pattern, and then discarded, without even having to give it a name: mask = qah.ImageSurface.create \ ( format = CAIRO.FORMAT_RGB24, dimensions = dimensions * scale ) (qah.Context.create(mask) .set_matrix(Matrix.scale(scale)) .set_source_colour(primary[component]) .set_operator(CAIRO.OPERATOR_SOURCE) .rectangle(spot) .fill() ) From steve at pearwood.info Thu Jun 16 22:39:14 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 17 Jun 2016 12:39:14 +1000 Subject: Method Chaining References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> Message-ID: <576362d3$0$1602$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Jun 2016 12:02 pm, Lawrence D?Oliveiro wrote: > Some kinds of objects often receive a whole lot of method calls in > sequence. In these situations, it is handy if each method call ends with > ?return self?, so that you can chain the calls together. This is > particularly common with graphics APIs, for instance. [...] Yes, this is design that (for example) Ruby classes tend to follow. It's not one that the Python builtins tend to follow, but of course people are free to return self from their own classes' methods if they like. As an alternative, you might find this simple adaptor useful: http://code.activestate.com/recipes/578770-method-chaining/ -- Steven From lawrencedo99 at gmail.com Thu Jun 16 23:59:05 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 16 Jun 2016 20:59:05 -0700 (PDT) Subject: Tie dictionary to database table? In-Reply-To: References: Message-ID: <44e1453f-58c1-4e4f-84fe-646262dfe5ac@googlegroups.com> On Friday, June 10, 2016 at 12:30:47 AM UTC+12, Peter Heitzer wrote: > What I would like is if I write > > email['frank']='frank at middle-of-nowhere.org' > > in my python script it generates a statement like > update users set email='frank at middle-of-nowhere.org' where username='frank'; That?s not a database, that?s a key-value store. From michael.selik at gmail.com Fri Jun 17 00:23:57 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 17 Jun 2016 04:23:57 +0000 Subject: Method Chaining In-Reply-To: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> Message-ID: On Thu, Jun 16, 2016 at 10:53 PM Lawrence D?Oliveiro wrote: > Example from , > concisely expressing a complex drawing sequence: > > (g > .move_to((p1 + p2a) / 2) > .line_to(p1 + (p2 - p1) * frac) > .line_to((p1 + p1a) / 2) > .stroke() > .move_to((p2 + p2a) / 2) > .line_to(p2 + (p1 - p2) * frac) > .line_to((p2 + p1a) / 2) > .stroke() > ) > Wouldn't that look nicer with the ``g`` repeated on every line, no extra indentation, and no extraneous parentheses? g.move_to((p1 + p2a) / 2) g.line_to(p1 + (p2 - p1) * frac) g.line_to((p1 + p1a) / 2) g.stroke() g.move_to((p2 + p2a) / 2) g.line_to(p2 + (p1 - p2) * frac) g.line_to((p2 + p1a) / 2) g.stroke() Sometimes it's hard to know when a function has a side-effect. I appreciate that these impure functions tend to return None. From lawrencedo99 at gmail.com Fri Jun 17 00:37:00 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 16 Jun 2016 21:37:00 -0700 (PDT) Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> Message-ID: <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> On Friday, June 17, 2016 at 4:24:24 PM UTC+12, Michael Selik wrote: > On Thu, Jun 16, 2016 at 10:53 PM Lawrence D?Oliveiro wrote: > > > Example from , > > concisely expressing a complex drawing sequence: > > > > (g > > .move_to((p1 + p2a) / 2) > > .line_to(p1 + (p2 - p1) * frac) > > .line_to((p1 + p1a) / 2) > > .stroke() > > .move_to((p2 + p2a) / 2) > > .line_to(p2 + (p1 - p2) * frac) > > .line_to((p2 + p1a) / 2) > > .stroke() > > ) > > Wouldn't that look nicer with the ``g`` repeated on every line, no extra > indentation, and no extraneous parentheses? > > g.move_to((p1 + p2a) / 2) > g.line_to(p1 + (p2 - p1) * frac) > g.line_to((p1 + p1a) / 2) > g.stroke() > g.move_to((p2 + p2a) / 2) > g.line_to(p2 + (p1 - p2) * frac) > g.line_to((p2 + p1a) / 2) > g.stroke() Clearly, no. From __peter__ at web.de Fri Jun 17 03:46:19 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 17 Jun 2016 09:46:19 +0200 Subject: Contradictory error messages in Python 3.4 - standard library issue! References: Message-ID: Harrison Chudleigh wrote: > While working on a program, I ran into an error with the usage of the > module tokenize. The following message was displayed. > File > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 467, in tokenize > encoding, consumed = detect_encoding(readline) > File > "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", > line 409, in detect_encoding > if first.startswith(BOM_UTF8): > TypeError: startswith first arg must be str or a tuple of str, not bytes > Undaunted, I changed the error on line 409. The line then read: > > if first.startswith(BOM_UTF8): As Steven says -- don't change the standard library. Your problem is likely that you are opening the file containing the code you want to tokenize in text mode. Compare: $ cat 42.py 42 $ python3 Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tokenize First with the file opened in text mode: >>> with open("42.py", "r") as f: ... for t in tokenize.tokenize(f.readline): print(t) ... Traceback (most recent call last): File "", line 2, in File "/usr/lib/python3.4/tokenize.py", line 468, in tokenize encoding, consumed = detect_encoding(readline) File "/usr/lib/python3.4/tokenize.py", line 408, in detect_encoding if first.startswith(BOM_UTF8): TypeError: startswith first arg must be str or a tuple of str, not bytes Now let's switch to binary mode: >>> with open("42.py", "rb") as f: ... for t in tokenize.tokenize(f.readline): print(t) ... TokenInfo(type=56 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), line='') TokenInfo(type=2 (NUMBER), string='42', start=(1, 0), end=(1, 2), line='42\n') TokenInfo(type=4 (NEWLINE), string='\n', start=(1, 2), end=(1, 3), line='42\n') TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='') From ned at nedbatchelder.com Fri Jun 17 04:13:23 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 17 Jun 2016 01:13:23 -0700 (PDT) Subject: Method Chaining In-Reply-To: <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> Message-ID: On Friday, June 17, 2016 at 12:37:14 AM UTC-4, Lawrence D?Oliveiro wrote: > On Friday, June 17, 2016 at 4:24:24 PM UTC+12, Michael Selik wrote: > > On Thu, Jun 16, 2016 at 10:53 PM Lawrence D?Oliveiro wrote: > > > > > Example from , > > > concisely expressing a complex drawing sequence: > > > > > > (g > > > .move_to((p1 + p2a) / 2) > > > .line_to(p1 + (p2 - p1) * frac) > > > .line_to((p1 + p1a) / 2) > > > .stroke() > > > .move_to((p2 + p2a) / 2) > > > .line_to(p2 + (p1 - p2) * frac) > > > .line_to((p2 + p1a) / 2) > > > .stroke() > > > ) > > > > Wouldn't that look nicer with the ``g`` repeated on every line, no extra > > indentation, and no extraneous parentheses? > > > > g.move_to((p1 + p2a) / 2) > > g.line_to(p1 + (p2 - p1) * frac) > > g.line_to((p1 + p1a) / 2) > > g.stroke() > > g.move_to((p2 + p2a) / 2) > > g.line_to(p2 + (p1 - p2) * frac) > > g.line_to((p2 + p1a) / 2) > > g.stroke() > > Clearly, no. To me, it's a toss-up. The chained version is nice in that it removes the repetition of "g". But the unchained version is more explicit, and avoids the awkward parenthesis. I think I would lean toward the unchained version. Clearly tastes can differ. --Ned. From lawrencedo99 at gmail.com Fri Jun 17 04:38:32 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 01:38:32 -0700 (PDT) Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> Message-ID: <9f4ac957-f29e-4433-813a-fbebb69fff37@googlegroups.com> On Friday, June 17, 2016 at 8:13:50 PM UTC+12, Ned Batchelder wrote: > But the unchained version is more explicit, and avoids > the awkward parenthesis. What if it had been the_context.move_to((p1 + p2a) / 2) the_context.line_to(p1 + (p2 - p1) * frac) the_context.line_to((p1 + p1a) / 2) the_context.stroke() the_context.move_to((p2 + p2a) / 2) the_context.line_to(p2 + (p1 - p2) * frac) the_context.line_to((p2 + p1a) / 2) the_context.stroke() ? From jussi.piitulainen at helsinki.fi Fri Jun 17 04:45:51 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 17 Jun 2016 11:45:51 +0300 Subject: Method Chaining References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <9f4ac957-f29e-4433-813a-fbebb69fff37@googlegroups.com> Message-ID: Lawrence D?Oliveiro writes: > On Friday, June 17, 2016 at 8:13:50 PM UTC+12, Ned Batchelder wrote: >> But the unchained version is more explicit, and avoids >> the awkward parenthesis. > > What if it had been > > the_context.move_to((p1 + p2a) / 2) > the_context.line_to(p1 + (p2 - p1) * frac) > the_context.line_to((p1 + p1a) / 2) > the_context.stroke() > the_context.move_to((p2 + p2a) / 2) > the_context.line_to(p2 + (p1 - p2) * frac) > the_context.line_to((p2 + p1a) / 2) > the_context.stroke() > > ? g = the_context g.move_to((p1 + p2a) / 2) g.line_to(p1 + (p2 - p1) * frac) g.line_to((p1 + p1a) / 2) g.stroke() g.move_to((p2 + p2a) / 2) g.line_to(p2 + (p1 - p2) * frac) g.line_to((p2 + p1a) / 2) g.stroke() From steve at pearwood.info Fri Jun 17 05:28:06 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 17 Jun 2016 19:28:06 +1000 Subject: Method Chaining References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> Message-ID: <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Jun 2016 06:13 pm, Ned Batchelder wrote: > To me, it's a toss-up. The chained version is nice in that it removes the > repetition of "g". But the unchained version is more explicit, and avoids > the awkward parenthesis. > > I think I would lean toward the unchained version. Clearly tastes can > differ. Indeed. For what it's worth, I'm ever-so-slightly leaning towards Lawrence's taste here. What Michael Selik earlier described as advantages of the explicit version: g.move_to((p1 + p2a) / 2) g.line_to(p1 + (p2 - p1) * frac) g.line_to((p1 + p1a) / 2) g.stroke() namely, "no extra indentation, and no extraneous parentheses", is to me a negative, not a positive. Since all these commands belong together in some sense, I like the chained version: (g.move_to((p1 + p2a) / 2) .line_to(p1 + (p2 - p1) * frac) .line_to((p1 + p1a) / 2) .stroke() ) as the parens and indentation more clearly mark this chunk of code as a unit. On the other hand, I like the fact that methods which are conceptually procedures that operate by side-effect return None. So it's hard to decide precisely which behaviour is better. Its very much a matter of taste. -- Steven From michael.selik at gmail.com Fri Jun 17 09:34:33 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 17 Jun 2016 13:34:33 +0000 Subject: Method Chaining In-Reply-To: <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 17, 2016 at 5:31 AM Steven D'Aprano wrote: > (g.move_to((p1 + p2a) / 2) > .line_to(p1 + (p2 - p1) * frac) > .line_to((p1 + p1a) / 2) > .stroke() > ) > > the parens and indentation more clearly mark this chunk of code as a > unit. I prefer reserving indentation for where they're required ("for", "while", "if", etc.). In this case, I'd use an extra blank line before and after. Or, better, I'd move the chunk of code into a function by itself. On the other hand, I like the fact that methods which are > conceptually procedures that operate by side-effect return None. > Exactly. The chained version looks like each method is returning a modified copy. The Pandas library isn't perfect, but it has a good consistency for methods returning copies unless explicitly "inplace=True", in which case the method returns None. Paraphrasing Jakob's law of user experience [0], it doesn't matter if your design is better. People are more familiar with the design of other libraries and will expect yours to behave the same way: impure methods return None, unless named "pop" or a similar standard. [0] https://www.nngroup.com/articles/end-of-web-design/ From rustompmody at gmail.com Fri Jun 17 12:32:10 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 17 Jun 2016 09:32:10 -0700 (PDT) Subject: What is structured programming (was for/while else doesn't make sense) In-Reply-To: <2a91ecef-a71b-4523-8912-3511d7c8e211@googlegroups.com> References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <3d4a1a33-a404-47ff-ac89-7787311945c0@googlegroups.com> <7180ce45-9e59-443b-8303-e9492af9752d@googlegroups.com> <17c484d6-e741-4b24-bed0-cf19b57012a4@googlegroups.com> <2a91ecef-a71b-4523-8912-3511d7c8e211@googlegroups.com> Message-ID: On Friday, June 17, 2016 at 7:23:27 AM UTC+5:30, Lawrence D?Oliveiro wrote: > On Thursday, June 16, 2016 at 11:13:14 PM UTC+12, Rustom Mody wrote: > > > Please see https://en.wikipedia.org/wiki/Nassi%E2%80%93Shneiderman_diagram > > > > | Nassi?Shneiderman diagrams are (almost) isomorphic with > > | flowcharts. Everything you can represent with a Nassi?Shneiderman > > | diagram you can also represent with a flowchart. > > > > which is in line with what I am saying, viz that break/continue/goto are same > > in the sense of being 'unstructured' and therefore do not fit into a > > structured framework like NSDs > > This is just a restatement of the ?structure theorem?, which proves that structured control statements are mathematically equivalent to gotos, and anything that can be expressed one way can be expressed the other way. > > True, but a complete red herring. I wonder whether "red herring" is your red herring You talk of THE structure theorem. Is there one? Wikipedia's https://en.wikipedia.org/wiki/Structured_program_theorem has a references section with some two dozen links. Many of these pull in significantly opposite direction with small changes in conditions/clauses/definitions etc. Here is a selection. Which is for you "THE theorem"? [WHILE means language of structured programs -- think prototypical Pascal FLOW is language of flowcharts] =================================== B?hm and Jacopini show that that WHILE is equivalent to FLOW by showing how to translate every program in FLOW into WHILE. [Reverse translation is trivial] However... Ashcroft and Manna [Translation of Goto to while] Can every flowchart program be translated into an equivalent while program without adding extra variables? (i.e., using only the original state vector). NO! [They go on] Bohm and Jacopini have shown that every FLOW program can be effectively translated into an equivalent WHILE program (WITH ONE WHILE statement) hence the topology of the program is changed... We (Ashcroft and Manna) show how to transform flowchart into while *preserving* topology. Knuth and Floyd: [Notes on avoiding goto statements] prove the existence of programs whose go to statements cannot be eliminated without introducing procedure calls. Kosaraju proved that it's possible to avoid adding additional variables in structured programming, as long as arbitrary-depth, multi-level breaks from loops are allowed.[1][14] Furthermore, Kosaraju proved that a strict hierarchy of programs exists, nowadays called the Kosaraju hierarchy, in that for every integer n, there exists a program containing a multi-level break of depth n that cannot be rewritten as program with multi-level breaks of depth less than n (without introducing additional variables) ================================= IOW when you say "mathematically equivalent" you can mean whatever you like!! Unless you clarify in what sense 'equivalent' From rustompmody at gmail.com Fri Jun 17 12:48:05 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 17 Jun 2016 09:48:05 -0700 (PDT) Subject: Method Chaining In-Reply-To: <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> On Friday, June 17, 2016 at 2:58:19 PM UTC+5:30, Steven D'Aprano wrote: > On Fri, 17 Jun 2016 06:13 pm, Ned Batchelder wrote: > > > To me, it's a toss-up. The chained version is nice in that it removes the > > repetition of "g". But the unchained version is more explicit, and avoids > > the awkward parenthesis. > > > > I think I would lean toward the unchained version. Clearly tastes can > > differ. > > Indeed. For what it's worth, I'm ever-so-slightly leaning towards Lawrence's > taste here. More than 'slightly' out here! One thing about python OOP that irritates me is the 'self.' clutter. With a Pascal/VB style with-statement its naturally taken care of Yeah I know there is this FAQ: https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments I consider it bogus if we allow with to mean something like: https://msdn.microsoft.com/en-us/library/wc500chb.aspx From hedgui at hedgui.com Fri Jun 17 12:51:43 2016 From: hedgui at hedgui.com (hedgui at hedgui.com) Date: Fri, 17 Jun 2016 09:51:43 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: References: Message-ID: <85a6078c-8028-431a-adfc-0cd915972b09@googlegroups.com> Pi simply is not 3.14159 Time to go to remedial school everyone. If I do something on one side of the equation, I have to do the same on the other side of the equation. With Pi, we are TAKING the diameter, so subtract the width of diameter from the circumference of the circle and you have an ellipse, now there is thousands of diameters. ?o I suggest that Pi is = D*-7 Don't forget to put the diameter back. From python at mrabarnett.plus.com Fri Jun 17 13:45:05 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Jun 2016 18:45:05 +0100 Subject: value of pi and 22/7 In-Reply-To: <85a6078c-8028-431a-adfc-0cd915972b09@googlegroups.com> References: <85a6078c-8028-431a-adfc-0cd915972b09@googlegroups.com> Message-ID: On 2016-06-17 17:51, hedgui at hedgui.com wrote: > Pi simply is not 3.14159 > > Time to go to remedial school everyone. > > If I do something on one side of the equation, I have to do the same on the other side of the equation. > > With Pi, we are TAKING the diameter, so subtract the width of diameter from the circumference of the circle and you have an ellipse, now there is thousands of diameters. ?o > > I suggest that Pi is = D*-7 > > Don't forget to put the diameter back. > You're replying to a post from March 2011. From no.email at nospam.invalid Fri Jun 17 14:49:30 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 17 Jun 2016 11:49:30 -0700 Subject: (repost) Advisory: HTTP Header Injection in Python urllib Message-ID: <87shwbmz0l.fsf@nightsong.com> The blog post below is from a couple days ago: http://blog.blindspotsecurity.com/2016/06/advisory-http-header-injection-in.html It reports that it's possible to inject fake http headers into requests sent by urllib2(python2) and urllib(python3), by getting the library to retrieve a url concocted to have a newline followed by other headers. A malicious site can do this by redirecting from a normal url to a concocted one. It gives examples of some exploits possible with this trick, against Redis and Memcached. There's a small HN thread here: https://news.ycombinator.com/item?id=11921568 Someone there mentions "Python 3.5.0+, 3.4.4+ and 2.7.9+ are not vulnerable" since there's been a patch, but some Linux distros still use older versions. I don't know the situation with python2 urllib or with the request library. The blog post criticizes Redis and Memcached for not using any authentication (since "safe" internal networks are often not safe) and makes the interesting claim that even services on localhost should use authentication these days. From info at wingware.com Fri Jun 17 16:35:12 2016 From: info at wingware.com (Wingware) Date: Fri, 17 Jun 2016 16:35:12 -0400 Subject: ANN: Wing IDE 5.1.12 released Message-ID: <57645F00.5050406@wingware.com> Hi, Wingware has released version 5.1.12 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE features a professional code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, context-sensitive auto-editing, goto-definition, find uses, refactoring, a powerful debugger, version control, unit testing, search, project management, and many other features. This release includes the following minor improvements: Updated German localization (thanks to Christoph Heitkamp) Fixed Configure Project for Django to work if Start Django Project was not used first Don't show deprecation warnings for inspect.getargspec for debug processes and Python Shell running with Python 3.5 Fixed failure to analyze files in the background 8 other minor bug fixes For details see http://wingware.com/news/2016-06-17 and http://wingware.com/pub/wingide/5.1.12/CHANGELOG.txt What's New in Wing 5.1: Wing IDE 5.1 adds multi-process and child process debugging, syntax highlighting in the shells, support for pytest, Find Symbol in Project, persistent time-stamped unit test results, auto-conversion of indents on paste, an XCode keyboard personality, support for Flask, Django 1.7 to 1.9, Python 3.5, and recent Google App Engine versions, improved auto-completion for PyQt, recursive snippet invocation, and many other minor features and improvements. Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature list: http://wingware.com/wingide/features Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From lawrencedo99 at gmail.com Fri Jun 17 18:22:50 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 15:22:50 -0700 (PDT) Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> Message-ID: <159a187d-1e60-49e7-a5e7-b11e1d65e68f@googlegroups.com> On Friday, June 17, 2016 at 8:13:50 PM UTC+12, Ned Batchelder wrote: > But the unchained version is more explicit, and avoids > the awkward parenthesis. You think of parentheses as ?awkward?? Because elsewhere I see people recommending you put them in even if you don?t need them, for ?clarity?. From lawrencedo99 at gmail.com Fri Jun 17 18:25:24 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 15:25:24 -0700 (PDT) Subject: Method Chaining In-Reply-To: <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> Message-ID: <687c72ec-c532-4823-9106-f74e30709ada@googlegroups.com> On Saturday, June 18, 2016 at 4:48:30 AM UTC+12, Rustom Mody wrote: > One thing about python OOP that irritates me is the 'self.' clutter. > With a Pascal/VB style with-statement its naturally taken care of I used to use ?with?-statements back in my Pascal days. Then I had this nasty bug where a piece of code I wrote didn?t mean what I thought it meant (which wasn?t supposed to happen in Pascal). For months I blamed the bug on the app API (HyperCard)... Once I realized my mistake, I went off ?with?-statements completely. From lawrencedo99 at gmail.com Fri Jun 17 18:26:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 15:26:09 -0700 (PDT) Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, June 18, 2016 at 1:35:06 AM UTC+12, Michael Selik wrote: > The chained version looks like each method is returning a modified > copy. As opposed to a modified original? From michael.selik at gmail.com Fri Jun 17 18:45:00 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 17 Jun 2016 22:45:00 +0000 Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 17, 2016, 6:42 PM Lawrence D?Oliveiro wrote: > On Saturday, June 18, 2016 at 1:35:06 AM UTC+12, Michael Selik wrote: > > > The chained version looks like each method is returning a modified > > copy. > > As opposed to a modified original? > Correct. Read the rationale for list.sort returning None. It's in the Python design FAQ. > From lawrencedo99 at gmail.com Fri Jun 17 19:07:15 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 16:07:15 -0700 (PDT) Subject: What is structured programming (was for/while else doesn't make sense) In-Reply-To: References: <9e7b6ded-15ad-490a-9842-b3da5d8a048d@googlegroups.com> <575d3430$0$11108$c3e8da3@news.astraweb.com> <575e167a$0$1608$c3e8da3$5496439d@news.astraweb.com> <575f6f58$0$1591$c3e8da3$5496439d@news.astraweb.com> <036dbf77-9483-4c71-a86b-f03cbf55cc3b@googlegroups.com> <5760c795$0$1609$c3e8da3$5496439d@news.astraweb.com> <26329884-d598-4f32-87b8-d75a3d109d20@googlegroups.com> <1465998697.330207.638463505.7EA18520@webmail.messagingengine.com> <3d4a1a33-a404-47ff-ac89-7787311945c0@googlegroups.com> <7180ce45-9e59-443b-8303-e9492af9752d@googlegroups.com> <17c484d6-e741-4b24-bed0-cf19b57012a4@googlegroups.com> <2a91ecef-a71b-4523-8912-3511d7c8e211@googlegroups.com> Message-ID: On Saturday, June 18, 2016 at 4:32:26 AM UTC+12, Rustom Mody wrote: > I wonder whether "red herring" is your red herring I wasn?t the one trying to draw a completely spurious equivalence between structured programming and gotos. From michael.selik at gmail.com Fri Jun 17 19:10:10 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 17 Jun 2016 23:10:10 +0000 Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 17, 2016, 6:44 PM Michael Selik wrote: > > > On Fri, Jun 17, 2016, 6:42 PM Lawrence D?Oliveiro > wrote: > >> On Saturday, June 18, 2016 at 1:35:06 AM UTC+12, Michael Selik wrote: >> >> > The chained version looks like each method is returning a modified >> > copy. >> >> As opposed to a modified original? >> > > Correct. Read the rationale for list.sort returning None. It's in the > Python design FAQ. > Sorry, I should have included the link. https://docs.python.org/2/faq/design.html#why-doesn-t-list-sort-return-the-sorted-list Even if we're talking about a non-mutation side-effect, I think the same rationale applies. From lawrencedo99 at gmail.com Fri Jun 17 19:10:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 16:10:27 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: References: <494876334.2671.1300383418538.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: <555089c9-91f7-4fe4-9264-67e30c3b0ccd@googlegroups.com> On Friday, March 18, 2011 at 8:21:36 AM UTC+13, Rotwang wrote: > sum_{j = 1}^\infty 10^{-j!} You forgot a ?\? in front of ?sum?. (Of course I had to try it in IPython...) From lawrencedo99 at gmail.com Fri Jun 17 19:12:56 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 16:12:56 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: References: Message-ID: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> On Saturday, March 19, 2011 at 3:16:41 AM UTC+13, Grant Edwards wrote: > > On 2011-03-18, peter wrote: > >> The Old Testament (1 Kings 7,23) says ... "And he made a molten sea, >> ten cubits from the one brim to the other: it was round all about, and >> his height was five cubits: and a line of thirty cubits did compass it >> round about. ". So pi=3. End Of. > > There's nothing wrong with that value. The measurements were given > with one significant digit, so the ratio of the two measurements > should only have one significant digit. I?m not sure how you can write ?30? with one digit... From ian.g.kelly at gmail.com Fri Jun 17 19:49:13 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 17 Jun 2016 17:49:13 -0600 Subject: value of pi and 22/7 In-Reply-To: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> Message-ID: On Jun 17, 2016 5:44 PM, "Lawrence D?Oliveiro" wrote: > > On Saturday, March 19, 2011 at 3:16:41 AM UTC+13, Grant Edwards wrote: > > > > On 2011-03-18, peter wrote: > > > >> The Old Testament (1 Kings 7,23) says ... "And he made a molten sea, > >> ten cubits from the one brim to the other: it was round all about, and > >> his height was five cubits: and a line of thirty cubits did compass it > >> round about. ". So pi=3. End Of. > > > > There's nothing wrong with that value. The measurements were given > > with one significant digit, so the ratio of the two measurements > > should only have one significant digit. > > I?m not sure how you can write ?30? with one digit... If I tell you that the speed of light is 300,000,000 m/s, do you think that measurement has 9 significant digits? If you do, then you would be wrong. By the way, you're also replying to posts that are more than 5 years old. From cspears2002 at yahoo.com Fri Jun 17 19:52:22 2016 From: cspears2002 at yahoo.com (Chris) Date: Fri, 17 Jun 2016 16:52:22 -0700 (PDT) Subject: best text editor for programming Python on a Mac Message-ID: I have been trying to write a simple Hello World script on my Mac at work with TextEdit. However, I keep getting this error message: SyntaxError: Non-ASCII character '\xe2' in hello_world.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details I am using TextEdit in plain text mode. The document was saved in UTF-8, and I still get the error message. I tried switching to Western ASCII encoding, but once I start typing, I get a message stating that the document can no longer be saved using its original Western (ASCII) encoding. Any suggestions for a good open source text editor for the Mac out there? For now, I am going to stick with vim. From ned at nedbatchelder.com Fri Jun 17 20:02:30 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 17 Jun 2016 17:02:30 -0700 (PDT) Subject: Method Chaining In-Reply-To: <159a187d-1e60-49e7-a5e7-b11e1d65e68f@googlegroups.com> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <159a187d-1e60-49e7-a5e7-b11e1d65e68f@googlegroups.com> Message-ID: <821e76c1-4c8b-4f1a-a0d5-00e17b0680aa@googlegroups.com> On Friday, June 17, 2016 at 6:23:12 PM UTC-4, Lawrence D?Oliveiro wrote: > On Friday, June 17, 2016 at 8:13:50 PM UTC+12, Ned Batchelder wrote: > > > But the unchained version is more explicit, and avoids > > the awkward parenthesis. > > You think of parentheses as ?awkward?? Because elsewhere I see people recommending you put them in even if you don?t need them, for ?clarity?. Parentheses are used for a number of different purposes. It won't be possible to make a sweeping statement about them everywhere. I use "extra" parentheses to make operator application order clearer where it isn't obvious to me, for example. --Ned. From lawrencedo99 at gmail.com Fri Jun 17 20:19:33 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 17:19:33 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On Saturday, June 18, 2016 at 11:52:35 AM UTC+12, Chris wrote: > SyntaxError: Non-ASCII character '\xe2' in hello_world.py on line 1, but no > encoding declared; see http://python.org/dev/peps/pep-0263/ for details The problem is the version of Python that comes with your Mac is obsolete. From ned at nedbatchelder.com Fri Jun 17 20:36:20 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 17 Jun 2016 17:36:20 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On Friday, June 17, 2016 at 8:19:46 PM UTC-4, Lawrence D?Oliveiro wrote: > On Saturday, June 18, 2016 at 11:52:35 AM UTC+12, Chris wrote: > > > SyntaxError: Non-ASCII character '\xe2' in hello_world.py on line 1, but no > > encoding declared; see http://python.org/dev/peps/pep-0263/ for details > > The problem is the version of Python that comes with your Mac is obsolete. That is not the problem. Python 2 can handle non-ASCII characters just fine. Chris: if you could show us the code in hello_world.py, we can help you get it working. --Ned. From python at mrabarnett.plus.com Fri Jun 17 20:58:58 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 18 Jun 2016 01:58:58 +0100 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <8db734be-a90b-d6db-07e9-75246649cfbf@mrabarnett.plus.com> On 2016-06-18 00:52, Chris via Python-list wrote: > I have been trying to write a simple Hello World script on my Mac at work with TextEdit. However, I keep getting this error message: > > SyntaxError: Non-ASCII character '\xe2' in hello_world.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details > > I am using TextEdit in plain text mode. The document was saved in UTF-8, and I still get the error message. I tried switching to Western ASCII encoding, but once I start typing, I get a message stating that the document can no longer be saved using its original Western (ASCII) encoding. > > Any suggestions for a good open source text editor for the Mac out there? For now, I am going to stick with vim. > Did you specify the encoding as described in the PEP? It should be something like: # -*- coding: utf-8 -*- as the first or second line. From steve at pearwood.info Fri Jun 17 21:00:15 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 18 Jun 2016 11:00:15 +1000 Subject: (repost) Advisory: HTTP Header Injection in Python urllib References: <87shwbmz0l.fsf@nightsong.com> Message-ID: <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Jun 2016 04:49 am, Paul Rubin wrote: > The blog post below is from a couple days ago: > > http://blog.blindspotsecurity.com/2016/06/advisory-http-header-injection-in.html > The blog post criticizes Redis and Memcached for not using any > authentication (since "safe" internal networks are often not safe) and > makes the interesting claim that even services on localhost should use > authentication these days. That's not quite what they say. They say that the problem is that "trusted internal networks" are often no safer than the Internet and shouldn't be trusted. It does also say: "Even an unauthenticated service listening on localhost is risky these days." but fall short of *explicitly* recommending that they should be authenticated. Although they do *implicitly* do so, by saying that "it wouldn't be hard" for such services to include a password. The author doesn't go into details of what sort of attacks against localhost they're talking about. An unauthenticated service running on localhost implies, to me, a single-user setup, where presumably the single-user has admin access to localhost. So I'm not really sure what "risk" they have -- e.g. I'm sure that I could do all sorts of bad things to localhost by exploiting http services. Or I could just go "sudo rm -rf /" [don't do this at home]. Or whatever evil thing I had in mind. But perhaps they mean a scenario where I'm running a service on localhost and offering it to other users on a local network. In which case it makes sense: trusted internal networks perhaps shouldn't be trusted. -- Steven From steve at pearwood.info Fri Jun 17 21:19:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 18 Jun 2016 11:19:23 +1000 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> Message-ID: <5764a19c$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Jun 2016 09:49 am, Ian Kelly wrote: > If I tell you that the speed of light is 300,000,000 m/s, do you think > that measurement has 9 significant digits? If you do, then you would be > wrong. Hmmm. If I tell you that some physical phenomenon [let's call it the speed of light] is 299,999,999 m/s, how many significant digits would I be using? What if I tell you that it's 300,000,001 m/s? What if the figure to nine significant digits *actually is* three followed by eight zeroes? For all that it is in widespread use, I think the concept of "significant figures" is inherently ambiguous. -- Steven From lawrencedo99 at gmail.com Fri Jun 17 21:50:28 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 18:50:28 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: <8db734be-a90b-d6db-07e9-75246649cfbf@mrabarnett.plus.com> Message-ID: <6f4c9f01-4173-460b-9819-0457be55ab12@googlegroups.com> On Saturday, June 18, 2016 at 12:59:16 PM UTC+12, MRAB wrote: > Did you specify the encoding as described in the PEP? Python 3 defaults to UTF-8. From steve at pearwood.info Fri Jun 17 21:55:15 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 18 Jun 2016 11:55:15 +1000 Subject: best text editor for programming Python on a Mac References: Message-ID: <5764aa04$0$1605$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Jun 2016 09:52 am, Chris wrote: > I have been trying to write a simple Hello World script on my Mac at work > with TextEdit. However, I keep getting this error message: > > SyntaxError: Non-ASCII character '\xe2' in hello_world.py on line 1, but > no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Have you tried declaring an encoding? Put this in the first line of your file: # -*- coding: utf-8 -*- This is a "magic cookie" that tells the interpreter you are using UTF-8. It's only needed if you include non-ASCII text in the file, as you appear to be doing for some reason. That might be sufficient to solve the problem. In theory it will be, so try that first, but just in case something more mysterious is going on, read on. > I am using TextEdit in plain text mode. The document was saved in UTF-8, > and I still get the error message. Are you *sure* it was UTF-8? Because I can't see likely way to get the byte \xE2 as the*first* non-ASCII byte in a UTF-8 document. The way UTF-8 works is that ASCII characters are encoded as the same bytes used by ASCII. But non-ASCII characters get encoded as multi-byte sequences of non-ASCII bytes. The first time Python sees a non-ASCII byte, it will complain. So if it is complaining about byte \xE2 in UTF-8, you must have a code point between U+10000 and U+10FFFF, which seems unlikely unless you're writing in Chinese, ancient Phoenician, or similar. Unless... are you using an emoji? That might do it. It's best if you show us your code. We may be able to diagnose the problem more easily once we see that. If it is possible that you're *not* using UTF-8 like you thought, then perhaps you have Smart Quotes turned on? If you type ' ' or " ", do you see curly quotes instead of foot/inch marks? The character the Python interpreter is complaining about appears to be a fancy quote of some sort. If I assume you're actually using the old default Macintosh encoding, I get a kind of curly quote: py> import unicodedata py> unicodedata.name(b'\xe2'.decode('MacRoman')) 'SINGLE LOW-9 QUOTATION MARK' which hints that when you type: print 'Hello World' in your file, you're seeing: print ?Hello World? or similar. Or possibly you're actually using a Western European encoding, like Latin-1, in which case you're probably using ?. py> unicodedata.name(b'\xe2'.decode('Latin-1')) 'LATIN SMALL LETTER A WITH CIRCUMFLEX' But that contradicts the error message that the editor gives you: > I tried switching to Western ASCII > encoding, but once I start typing, I get a message stating that the > document can no longer be saved using its original Western (ASCII) > encoding. > > Any suggestions for a good open source text editor for the Mac out there? > For now, I am going to stick with vim. I can only stress that if adding the magic encoding cookie to the file doesn't fix it, we'll need to see the source code to diagnose the problem. -- Steven From zachary.ware+pylist at gmail.com Fri Jun 17 21:59:14 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 17 Jun 2016 20:59:14 -0500 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On Jun 17, 2016 6:56 PM, "Chris via Python-list" wrote: > > I have been trying to write a simple Hello World script on my Mac at work with TextEdit. TextEdit is not just a simple text editor, it defaults to rich text mode. You can either attempt to get TextEdit out of rich text mode and into plain text mode, or use a different editor, like nano or vim (I'm pretty sure both are available by default). -- Zach (On a phone) From steve at pearwood.info Fri Jun 17 22:05:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 18 Jun 2016 12:05:11 +1000 Subject: best text editor for programming Python on a Mac References: <8db734be-a90b-d6db-07e9-75246649cfbf@mrabarnett.plus.com> <6f4c9f01-4173-460b-9819-0457be55ab12@googlegroups.com> Message-ID: <5764ac58$0$1620$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Jun 2016 11:50 am, Lawrence D?Oliveiro wrote: > On Saturday, June 18, 2016 at 12:59:16 PM UTC+12, MRAB wrote: > >> Did you specify the encoding as described in the PEP? > > Python 3 defaults to UTF-8. That doesn't mean that upgrading to Python 3 will fix the problem. It *may*, but since the details of what the precise problem are quite vague, it is difficult to be sure. We know its an encoding problem, because that's what the error message tells us, but beyond that, the symptoms reported are unclear. -- Steven From ethan at stoneleaf.us Fri Jun 17 22:27:08 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Jun 2016 19:27:08 -0700 Subject: value of pi and 22/7 In-Reply-To: <5764a19c$0$1603$c3e8da3$5496439d@news.astraweb.com> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <5764a19c$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5764B17C.3080809@stoneleaf.us> On 06/17/2016 06:19 PM, Steven D'Aprano wrote: > On Sat, 18 Jun 2016 09:49 am, Ian Kelly wrote: >> If I tell you that the speed of light is 300,000,000 m/s, do you think >> that measurement has 9 significant digits? If you do, then you would be >> wrong. > > Hmmm. > > If I tell you that some physical phenomenon [let's call it the speed of > light] is 299,999,999 m/s, how many significant digits would I be using? I know! I know! 9! > What if I tell you that it's 300,000,001 m/s? Oh! 9 again! > What if the figure to nine significant digits *actually is* three followed > by eight zeroes? Hmmm... thinking.... thinking... oh yeah! You put a bar over the last significant digit -- or you use scientific notation: 30e7 has two significant digits. > For all that it is in widespread use, I think the concept of "significant > figures" is inherently ambiguous. Not at all -- just have to keep your notations correct*. -- ~Ethan~ * Mine might be 30 years out of date, but maybe not. From random832 at fastmail.com Fri Jun 17 23:48:28 2016 From: random832 at fastmail.com (Random832) Date: Fri, 17 Jun 2016 23:48:28 -0400 Subject: value of pi and 22/7 In-Reply-To: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> Message-ID: <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> On Fri, Jun 17, 2016, at 19:12, Lawrence D?Oliveiro wrote: > I?m not sure how you can write ?30? with one digit... One *significant* digit. Though, as it happens, some ancient number systems, including Hebrew and Greek, have one set of digits for 1-9, one for 10-90, and one for 100-900. From random832 at fastmail.com Fri Jun 17 23:52:21 2016 From: random832 at fastmail.com (Random832) Date: Fri, 17 Jun 2016 23:52:21 -0400 Subject: (repost) Advisory: HTTP Header Injection in Python urllib In-Reply-To: <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1466221941.3662846.641269641.7FFA59B4@webmail.messagingengine.com> On Fri, Jun 17, 2016, at 21:00, Steven D'Aprano wrote: > The author doesn't go into details of what sort of attacks against > localhost they're talking about. An unauthenticated service running on > localhost implies, to me, a single-user setup, where presumably the > single-user has admin access to localhost. So I'm not really sure what > "risk" they have The issue - especially clearly in this context, which demonstrates a working exploit for this vulnerability - is cross-site request forgery. Which doesn't technically require the victim service to be HTTP (I remember a proof of concept a while back which would trick a browser into connecting to an IRC server), so long as it can ignore HTTP headers. From lawrencedo99 at gmail.com Sat Jun 18 00:30:16 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 17 Jun 2016 21:30:16 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: On Saturday, June 18, 2016 at 3:48:43 PM UTC+12, Random832 wrote: > > On Fri, Jun 17, 2016, at 19:12, Lawrence D?Oliveiro wrote: >> >> I?m not sure how you can write ?30? with one digit... > > One *significant* digit. Like some credulous past-Bronze-age tribespeople understood the concept of ?significant digits? ... I wonder what the quality of their workmanship was like, if a measurement accurate to one significant digit was considered sufficient ... I feel a new phrase coming on: ?good enough for Bible work?! From ian.g.kelly at gmail.com Sat Jun 18 01:18:25 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 17 Jun 2016 23:18:25 -0600 Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: On Fri, Jun 17, 2016 at 10:30 PM, Lawrence D?Oliveiro wrote: > On Saturday, June 18, 2016 at 3:48:43 PM UTC+12, Random832 wrote: >> >> On Fri, Jun 17, 2016, at 19:12, Lawrence D?Oliveiro wrote: >>> >>> I?m not sure how you can write ?30? with one digit... >> >> One *significant* digit. > > Like some credulous past-Bronze-age tribespeople understood the concept of ?significant digits? ... I don't see why they should need to in order to measure one thing as "thirty cubits" and another thing as "ten cubits" and write those numbers down. Remember, the cubit was based on the length of the forearm, so it's not like it was a terribly precise measurement to begin with; they might not have understood significant figures, but they probably wouldn't have been overly concerned about the difference between thirty and thirty-one. Check out the rest of the chapter. Every single measurement in it above seven is a multiple of ten. > I wonder what the quality of their workmanship was like, if a measurement accurate to one significant digit was considered sufficient ... You realize there can be a difference between the quality to which something is constructed and the precision of the measurements later used to describe it? "Threescore cubits long" is an impressive figure. "61 and a half cubits" doesn't do the job of communicating the scale any better, and ultimately amounts to wasted words in what was originally an oral tradition. From support at ecourierz.com Sat Jun 18 01:18:28 2016 From: support at ecourierz.com (support at ecourierz.com) Date: Fri, 17 Jun 2016 22:18:28 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: use notepad++ From timharig at eternal-september.org Sat Jun 18 01:47:02 2016 From: timharig at eternal-september.org (Tim Harig) Date: Sat, 18 Jun 2016 05:47:02 -0000 (UTC) Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <5764a19c$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-18, Steven D'Aprano wrote: > On Sat, 18 Jun 2016 09:49 am, Ian Kelly wrote: > >> If I tell you that the speed of light is 300,000,000 m/s, do you think >> that measurement has 9 significant digits? If you do, then you would be >> wrong. > What if the figure to nine significant digits *actually is* three followed > by eight zeroes? The you can either write it as 300000000. (notice the trailing decimal indicating that all of the zeros are indeed significant) or write it it scientific notation. > For all that it is in widespread use, I think the concept of "significant > figures" is inherently ambiguous. Only for those who do not understand it. The main problem I have with significant figures is that measurement accuracy is often not constrained to a decimal system. A scale that can measure in 1/5 units is more accurate than a scale that can measure only in whole units but it is not as accurate as a scale that can measure all 1/10 units. Therefore it effectively has a fractional number of significant figures. I could just cut my loses and express the lower number of significant figures but, I usually express the error explicitly instead: +- 0.2 units where +- looks like the ± html entity. From john_ladasky at sbcglobal.net Sat Jun 18 02:45:16 2016 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 17 Jun 2016 23:45:16 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: <8uh0rcFe12U4@mid.individual.net> References: <8uh0rcFe12U4@mid.individual.net> Message-ID: <19485d58-1407-4082-a9af-c2fdbd0dc080@googlegroups.com> On Friday, March 18, 2011 at 5:17:48 AM UTC-7, Neil Cerutti wrote: > RIIIIIIght. What's a cubit? > > -- > Neil Cerutti How long can you tread water? (Showing my age...) From diolu.remove_this_part at bigfoot.com Sat Jun 18 03:09:44 2016 From: diolu.remove_this_part at bigfoot.com (Olive) Date: Sat, 18 Jun 2016 09:09:44 +0200 Subject: Launching a process with stdout in the terminal and captured Message-ID: <20160618090944.4bceb1e0@bigfoot.com> I am here on Linux. I want to launch a process just like os.system, (output to a terminal in an unbuffered way so as to support interaction) and at the same time capturing the output of the process (analogous to the Unix tee command). I have found some tricks on the web, but is it a standard way to do that? Note that if it is possible I would prefer that the launched command see its standard output connected to a terminal (many command change their behaviour accordingly like 'ls', etc.). The main reason now is to run latex (with its interaction), I need the output to know where it has put its output {dvi,pdf} file (you can't guess it from the command line because you can launch latex without any argument and \input a file afterwards). Olivier From auriocus at gmx.de Sat Jun 18 03:56:42 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 18 Jun 2016 09:56:42 +0200 Subject: value of pi and 22/7 In-Reply-To: <5764a19c$0$1603$c3e8da3$5496439d@news.astraweb.com> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <5764a19c$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 18.06.16 um 03:19 schrieb Steven D'Aprano: > If I tell you that some physical phenomenon [let's call it the speed of > light] is 299,999,999 m/s, how many significant digits would I be using? > > What if I tell you that it's 300,000,001 m/s? > > What if the figure to nine significant digits *actually is* three followed > by eight zeroes? You can't read off the number of significant figures from a value itself, it must be given as a side information. It is a common way to indicate uncertainty estimes, however, by giving a number to as many decimal places as there are significant digits, i.e. to indicate the uncertainty as a power of ten. You need to use exponential notation to express that clearly, in that case: 3*10^8 -> (3 +/- 0.5) * 10^8 3.0 *10^8 -> (3.0 +/- 0.05)*10^8 For more accurate error estimates, the second notation is used. Another common way to express this is something like 3.42(3) which means 3.42 +/- 0.03 Note, however, that in current SI units the speed of light is known exactly: c = 299,792,458 m/s There is no error! This is possible because the unit metre is defined by this value from the unit second. Christian From eryksun at gmail.com Sat Jun 18 04:33:49 2016 From: eryksun at gmail.com (eryk sun) Date: Sat, 18 Jun 2016 08:33:49 +0000 Subject: Launching a process with stdout in the terminal and captured In-Reply-To: <20160618090944.4bceb1e0@bigfoot.com> References: <20160618090944.4bceb1e0@bigfoot.com> Message-ID: On Sat, Jun 18, 2016 at 7:09 AM, Olive wrote: > I am here on Linux. > ... > Note that if it is possible I would prefer that the launched command see its standard > output connected to a terminal Try pexpect. https://pypi.python.org/pypi/pexpect From marko at pacujo.net Sat Jun 18 04:35:20 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 18 Jun 2016 11:35:20 +0300 Subject: (repost) Advisory: HTTP Header Injection in Python urllib References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twgqx5br.fsf@elektro.pacujo.net> Steven D'Aprano : > "Even an unauthenticated service listening on localhost is risky these > days." > > but fall short of *explicitly* recommending that they should be > authenticated. Although they do *implicitly* do so, by saying that "it > wouldn't be hard" for such services to include a password. In the local case, one should consider using local domain sockets (AF_LOCAL), which can reliably identify the peer's credentials (SO_PASSCRED, SO_PEERCRED). Marko From tjreedy at udel.edu Sat Jun 18 05:09:09 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Jun 2016 05:09:09 -0400 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On 6/18/2016 3:04 AM, Michael Vilain via Python-list wrote: > In article , > support at ecourierz.com wrote: > >> use notepad++ To me, for programming only in Python, IDLE beats Notepad++. Some features noted below. > [pay no attention to the little windows troll behind the curtain] > > "best" is subjective. Anytime someone wants the "best", I ask "what > features are important to you that would make it the best" because I'm > pretty sure what I find important wouldn't be what they find important. > > Things I've seen in a bunch of straight editors: > > - syntax coloring > - parathesis/block matching > - auto indent > - expansion of keywords, variables, subroutines > - integrated documentation so you don't have to lookup the syntax and > arguments of a function > - integration with code management systems (svn, git, github) > - regular expression searching > - multi-file regular expression search/replace > - multi-pane/window diff/merge > - programmability (e.g. write/store macros to perform repeatable tasks) > - integrated compile, run & syntax checking (this is really a function > of an IDE) When compile of text in editor fails, the cursor is moved to the spot where indicated by the compiler. When compile succeeds but there is a runtime error, one can jump from traceback to any of the file and line specified in the traceback. This is *extremely* useful. When one runs the integrated grep over part of the directory tree, one can jump to any of the file/line hits. > - interactive debugger (program stepping, expression & variable > evaluation, breakpoints, watchpoints, macros) [this is why I like perl] > - extensibility to add features (lint or code formatting, special > framework, etc.) > What's the best? That's your homework. Write 500 describing what is the > Best editor and why. -- Terry Jan Reedy From marko at pacujo.net Sat Jun 18 05:40:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 18 Jun 2016 12:40:09 +0300 Subject: best text editor for programming Python on a Mac References: Message-ID: <87lh22x2bq.fsf@elektro.pacujo.net> Michael Vilain : > "best" is subjective. Anytime someone wants the "best", I ask "what > features are important to you that would make it the best" because I'm > pretty sure what I find important wouldn't be what they find > important. That's a bit like asking what gender, nationality and religion you'd prefer for yourself. I mean, having used emacs since the mid-1980's, everything just seems to be in the right place -- including typing this posting. > - syntax coloring > - parathesis/block matching > - auto indent Yes, in active use. > - expansion of keywords, variables, subroutines Never learned to need that. > - integrated documentation so you don't have to lookup the syntax and > arguments of a function I have seen that in action with eclipse and Java. It could never match having a web browser window next to the editor window: . It would be nice if python provided a full set of man pages as well as info documentation like C. Those are integrated into emacs. > - integration with code management systems (svn, git, github) > - regular expression searching > - multi-file regular expression search/replace > - multi-pane/window diff/merge > - programmability (e.g. write/store macros to perform repeatable tasks) Yes, in active use. > - integrated compile, run & syntax checking (this is really a function > of an IDE) > - interactive debugger (program stepping, expression & variable > evaluation, breakpoints, watchpoints, macros) [this is why I like perl] As far as Python goes, emacs does have some elementary support for pdb. Haven't found it all that practical, though. > - extensibility to add features (lint or code formatting, special > framework, etc.) Although they do exist for emacs, I'm not a big fan of special plugins of any sort. > What's the best? That's your homework. Write 500 describing what is > the Best editor and why. Emacs doesn't take up the whole screen. It integrates seamlessly with the Unix way of doing things (but has some trouble with non-Unix culture items like Java). It can be run perfectly fine in a text terminal session. It takes care of all of your typing needs: when you type, type in emacs. Shell, email, news, documentation (with ASCII graphics!), programming... Marko From lawrencedo99 at gmail.com Sat Jun 18 06:08:47 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 18 Jun 2016 03:08:47 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: <87lh22x2bq.fsf@elektro.pacujo.net> References: <87lh22x2bq.fsf@elektro.pacujo.net> Message-ID: <02c74528-caf4-4983-b737-e5ab91e67a7c@googlegroups.com> On Saturday, June 18, 2016 at 9:40:23 PM UTC+12, Marko Rauhamaa wrote: > Michael Vilain: > >> - expansion of keywords, variables, subroutines Reminds me of a story by a local CompSci lecturer who originally learned Java through an IDE with autocomplete. Then one day he sat down to write some Java code without the benefit of autocomplete, and realized he didn?t know the language at all. >> - integrated documentation so you don't have to lookup the syntax and >> arguments of a function > > I have seen that in action with eclipse and Java. It could never match > having a web browser window next to the editor window: https://docs.python.org/3/library/>. I do exactly the same. Here?s my story: I?ve lost track of the number of times I have seen people write (in several different languages) sequences like x = ... expression for x ... y = ... expression for y ... s = math.sqrt(x * x + y * y) instead of the more direct s = math.hypot(... expression for x ..., ... expression for y ...) Would this ?integrated documentation? to ?lookup the syntax and arguments of a function? point out that math.hypot is a better function to use in this case than math.sqrt? No. For that, you have to actually be able to read and understand the reference documentation. > Emacs doesn't take up the whole screen. It integrates seamlessly with > the Unix way of doing things (but has some trouble with non-Unix culture > items like Java). Also an Emacs user here, even used it with Java (for Android). From petef4+usenet at gmail.com Sat Jun 18 08:04:17 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Sat, 18 Jun 2016 13:04:17 +0100 Subject: Method Chaining References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> Message-ID: Rustom Mody writes: > On Friday, June 17, 2016 at 2:58:19 PM UTC+5:30, Steven D'Aprano wrote: >> On Fri, 17 Jun 2016 06:13 pm, Ned Batchelder wrote: >> >> > To me, it's a toss-up. The chained version is nice in that it >> > removes the repetition of "g". But the unchained version is more >> > explicit, and avoids the awkward parenthesis. >> > >> > I think I would lean toward the unchained version. Clearly tastes >> > can differ. >> >> Indeed. For what it's worth, I'm ever-so-slightly leaning towards >> Lawrence's taste here. > > More than 'slightly' out here! > One thing about python OOP that irritates me is the 'self.' clutter. > With a Pascal/VB style with-statement its naturally taken care of > > Yeah I know there is this FAQ: > https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments > > I consider it bogus if we allow with to mean something like: > https://msdn.microsoft.com/en-us/library/wc500chb.aspx One subtle difference between your two citations is that VB uses a leading dot. Might that lessening of ambiguity enable a future Python to allow this? class Foo: def .set(a): # equivalent to def set(self, a): .a = a # equivalent to self.a = a Unless it is in a with statement with obj: .a = 1 # equivalent to obj.a = 1 .total = .total + 1 # obj.total = obj.total + 1 -- Pete Forman From petef4+usenet at gmail.com Sat Jun 18 08:05:54 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Sat, 18 Jun 2016 13:05:54 +0100 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> Message-ID: Lawrence D?Oliveiro writes: > On Saturday, March 19, 2011 at 3:16:41 AM UTC+13, Grant Edwards wrote: >> >> On 2011-03-18, peter wrote: >> >>> The Old Testament (1 Kings 7,23) says ... "And he made a molten sea, >>> ten cubits from the one brim to the other: it was round all about, and >>> his height was five cubits: and a line of thirty cubits did compass it >>> round about. ". So pi=3. End Of. >> >> There's nothing wrong with that value. The measurements were given >> with one significant digit, so the ratio of the two measurements >> should only have one significant digit. > > I?m not sure how you can write ?30? with one digit... >>> int('U', 36) 30 -- Pete Forman From alister.ware at ntlworld.com Sat Jun 18 09:22:13 2016 From: alister.ware at ntlworld.com (alister) Date: Sat, 18 Jun 2016 13:22:13 GMT Subject: best text editor for programming Python on a Mac References: <87lh22x2bq.fsf@elektro.pacujo.net> Message-ID: <9Wb9z.62277$am6.25239@fx46.am4> On Sat, 18 Jun 2016 12:40:09 +0300, Marko Rauhamaa wrote: > >> - integrated documentation so you don't have to lookup the syntax and >> arguments of a function > > I have seen that in action with eclipse and Java. It could never match > having a web browser window next to the editor window: https://docs.python.org/3/library/>. > > It would be nice if python provided a full set of man pages as well as > info documentation like C. Those are integrated into emacs. > pydoc - I think Guido's time machine strikes again :-) pydoc - the Python documentation tool pydoc ... Show text documentation on something. may be the name of a Python keyword, topic, function, module, or package, or a dotted reference to a class or function within a module or module in a package. If contains a '/', it is used as the path to a Python source file to document. If name is 'keywords', 'topics', or 'modules', a listing of these things is displayed. pydoc -k Search for a keyword in the synopsis lines of all available modules. pydoc -p Start an HTTP server on the given port on the local machine. Port number 0 can be used to get an arbitrary unused port. pydoc -w ... Write out the HTML documentation for a module to a file in the current directory. If contains a '/', it is treated as a filename; if it names a directory, documentation is written for all the contents. as it uses docstrings it should work well with any reasonably well written module - (even your own) -- ... The prejudices people feel about each other disappear when they get to know each other. -- Kirk, "Elaan of Troyius", stardate 4372.5 From liik.joonas at gmail.com Sat Jun 18 10:05:25 2016 From: liik.joonas at gmail.com (Joonas Liik) Date: Sat, 18 Jun 2016 17:05:25 +0300 Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> Message-ID: On 18 June 2016 at 15:04, Pete Forman wrote: > Rustom Mody writes: > >> On Friday, June 17, 2016 at 2:58:19 PM UTC+5:30, Steven D'Aprano wrote: >>> On Fri, 17 Jun 2016 06:13 pm, Ned Batchelder wrote: >>> >>> > To me, it's a toss-up. The chained version is nice in that it >>> > removes the repetition of "g". But the unchained version is more >>> > explicit, and avoids the awkward parenthesis. >>> > >>> > I think I would lean toward the unchained version. Clearly tastes >>> > can differ. >>> >>> Indeed. For what it's worth, I'm ever-so-slightly leaning towards >>> Lawrence's taste here. >> >> More than 'slightly' out here! >> One thing about python OOP that irritates me is the 'self.' clutter. >> With a Pascal/VB style with-statement its naturally taken care of >> >> Yeah I know there is this FAQ: >> https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments >> >> I consider it bogus if we allow with to mean something like: >> https://msdn.microsoft.com/en-us/library/wc500chb.aspx > > One subtle difference between your two citations is that VB uses a > leading dot. Might that lessening of ambiguity enable a future Python to > allow this? > > class Foo: > def .set(a): # equivalent to def set(self, a): > .a = a # equivalent to self.a = a > > Unless it is in a with statement > > with obj: > .a = 1 # equivalent to obj.a = 1 > .total = .total + 1 # obj.total = obj.total + 1 > > -- > Pete Forman > -- > https://mail.python.org/mailman/listinfo/python-list the leading dot does not resolve the ambiguity that arises from: with ob_a: with ob_b: .attr_c = 42 # which object are we modifying right now? also refer to "javascript the bad parts" about all the edege cases that python would surely face. also with is allready used for context managers.. From robertvstepp at gmail.com Sat Jun 18 11:22:19 2016 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 18 Jun 2016 10:22:19 -0500 Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <5764a19c$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jun 18, 2016 at 12:47 AM, Tim Harig wrote: > > The main problem I have with significant figures is that measurement > accuracy is often not constrained to a decimal system. A scale that can > measure in 1/5 units is more accurate than a scale that can measure only > in whole units but it is not as accurate as a scale that can measure > all 1/10 units. Therefore it effectively has a fractional number of > significant figures. Probably in this type of discussion a more careful distinction between "precision" and "accuracy" should be made. A measuring instrument may allow for many significant digits in its reported result, giving it a high level of precision, but could, in fact, be giving an inaccurate measurement (How close it is to the "true" value.), especially if it is an instrument that has not been properly calibrated (Made to agree as well as possible with known standards.). boB From rustompmody at gmail.com Sat Jun 18 11:35:57 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 18 Jun 2016 08:35:57 -0700 (PDT) Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> Message-ID: On Saturday, June 18, 2016 at 5:34:30 PM UTC+5:30, Pete Forman wrote: > Rustom Mody writes: > > > On Friday, June 17, 2016 at 2:58:19 PM UTC+5:30, Steven D'Aprano wrote: > >> On Fri, 17 Jun 2016 06:13 pm, Ned Batchelder wrote: > >> > >> > To me, it's a toss-up. The chained version is nice in that it > >> > removes the repetition of "g". But the unchained version is more > >> > explicit, and avoids the awkward parenthesis. > >> > > >> > I think I would lean toward the unchained version. Clearly tastes > >> > can differ. > >> > >> Indeed. For what it's worth, I'm ever-so-slightly leaning towards > >> Lawrence's taste here. > > > > More than 'slightly' out here! > > One thing about python OOP that irritates me is the 'self.' clutter. > > With a Pascal/VB style with-statement its naturally taken care of > > > > Yeah I know there is this FAQ: > > https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments > > > > I consider it bogus if we allow with to mean something like: > > https://msdn.microsoft.com/en-us/library/wc500chb.aspx > > One subtle difference between your two citations is that VB uses a > leading dot. Might that lessening of ambiguity enable a future Python to > allow this? > > class Foo: > def .set(a): # equivalent to def set(self, a): > .a = a # equivalent to self.a = a > Chuckle! Heck Why not?! But no I did not think of this > Unless it is in a with statement > > with obj: > .a = 1 # equivalent to obj.a = 1 > .total = .total + 1 # obj.total = obj.total + 1 I intended only this much viz that the syntactic marker '.' disambiguates between ordinary variable and attribute As for what happens when there are nested references as mentioned by Waffle: Well these ambiguities have a venerable vintage in programming languages Starting from the dangling else to which declaration a variable refers to when there are nested scopes and much else ie "match-to-the-innermost" seems to be obvious enough From petef4+usenet at gmail.com Sat Jun 18 11:42:07 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Sat, 18 Jun 2016 16:42:07 +0100 Subject: Method Chaining References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> Message-ID: Joonas Liik writes: > On 18 June 2016 at 15:04, Pete Forman wrote: >> Rustom Mody writes: >> >>> On Friday, June 17, 2016 at 2:58:19 PM UTC+5:30, Steven D'Aprano wrote: >>>> On Fri, 17 Jun 2016 06:13 pm, Ned Batchelder wrote: >>>> >>>> > To me, it's a toss-up. The chained version is nice in that it >>>> > removes the repetition of "g". But the unchained version is more >>>> > explicit, and avoids the awkward parenthesis. >>>> > >>>> > I think I would lean toward the unchained version. Clearly tastes >>>> > can differ. >>>> >>>> Indeed. For what it's worth, I'm ever-so-slightly leaning towards >>>> Lawrence's taste here. >>> >>> More than 'slightly' out here! >>> One thing about python OOP that irritates me is the 'self.' clutter. >>> With a Pascal/VB style with-statement its naturally taken care of >>> >>> Yeah I know there is this FAQ: >>> https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments >>> >>> I consider it bogus if we allow with to mean something like: >>> https://msdn.microsoft.com/en-us/library/wc500chb.aspx >> >> One subtle difference between your two citations is that VB uses a >> leading dot. Might that lessening of ambiguity enable a future Python to >> allow this? >> >> class Foo: >> def .set(a): # equivalent to def set(self, a): >> .a = a # equivalent to self.a = a >> >> Unless it is in a with statement >> >> with obj: >> .a = 1 # equivalent to obj.a = 1 >> .total = .total + 1 # obj.total = obj.total + 1 >> >> -- >> Pete Forman >> -- >> https://mail.python.org/mailman/listinfo/python-list > > the leading dot does not resolve the ambiguity that arises from: > > with ob_a: > with ob_b: > .attr_c = 42 # which object are we modifying right now? > > also refer to "javascript the bad parts" about all the edege cases > that python would surely face. > also with is allready used for context managers.. Yes, I ought not to have lumped in the with proposal with that for self. Python's design FAQ clearly explains why the language does not need that form of "with". -- Pete Forman From MrJean1 at gmail.com Sat Jun 18 11:52:32 2016 From: MrJean1 at gmail.com (MrJean1) Date: Sat, 18 Jun 2016 08:52:32 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <4b36cae1-7732-490d-972e-0f0b78f9e6b0@googlegroups.com> Try TextWrangler from BareBones . I've been using that for years on MacOS X. /Jean From rustompmody at gmail.com Sat Jun 18 12:02:20 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 18 Jun 2016 09:02:20 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: <87lh22x2bq.fsf@elektro.pacujo.net> References: <87lh22x2bq.fsf@elektro.pacujo.net> Message-ID: <7c7cf963-33a9-4dcf-b6dd-e9b0137fa18e@googlegroups.com> On Saturday, June 18, 2016 at 3:10:23 PM UTC+5:30, Marko Rauhamaa wrote: > Michael Vilain : > > > "best" is subjective. Anytime someone wants the "best", I ask "what > > features are important to you that would make it the best" because I'm > > pretty sure what I find important wouldn't be what they find > > important. > > That's a bit like asking what gender, nationality and religion you'd > prefer for yourself. > > I mean, having used emacs since the mid-1980's, everything just seems to > be in the right place -- including typing this posting. > > > - syntax coloring > > - parathesis/block matching > > - auto indent > > Yes, in active use. > > > - expansion of keywords, variables, subroutines > > Never learned to need that. > > > - integrated documentation so you don't have to lookup the syntax and > > arguments of a function > > I have seen that in action with eclipse and Java. It could never match > having a web browser window next to the editor window: https://docs.python.org/3/library/>. > > It would be nice if python provided a full set of man pages as well as > info documentation like C. Those are integrated into emacs. > > > - integration with code management systems (svn, git, github) > > - regular expression searching > > - multi-file regular expression search/replace > > - multi-pane/window diff/merge > > - programmability (e.g. write/store macros to perform repeatable tasks) > > Yes, in active use. > > > - integrated compile, run & syntax checking (this is really a function > > of an IDE) > > - interactive debugger (program stepping, expression & variable > > evaluation, breakpoints, watchpoints, macros) [this is why I like perl] > > As far as Python goes, emacs does have some elementary support for pdb. > Haven't found it all that practical, though. > > > - extensibility to add features (lint or code formatting, special > > framework, etc.) > > Although they do exist for emacs, I'm not a big fan of special plugins > of any sort. > > > What's the best? That's your homework. Write 500 describing what is > > the Best editor and why. > > Emacs doesn't take up the whole screen. It integrates seamlessly with > the Unix way of doing things (but has some trouble with non-Unix culture > items like Java). It can be run perfectly fine in a text terminal > session. It takes care of all of your typing needs: when you type, type > in emacs. Shell, email, news, documentation (with ASCII graphics!), > programming... > > > Marko Having expatiatated all that you could have added some tips to OP on handling unicode in emacs :-) Some emacs tips [Note If recommending emacs ? recommender = sadist; blame is on first mention!] Emacs has a modeline at bottom which tells all sorts of things -- one of them the coding system (as it detects/decides) at the left corner. For latin-1 it should show a '1' and then there should be no problem If it shows 'U' then its utf-something (usually UTF-8) and you have a likely problem To force latin-1 type C-x RET f (ie control-X followed by return followed by an 'f') It will ask for what coding system to save file Say latin-1-unix [the unix is for LF line endings] And the U should change to 1 and you are done OTOH there may be a non-latin-1-able character it will complain and put the cursor on the offending char [ For that matter if I had to guess whats happened I'd hazard that you cut-pasted something from a pdf which converted ASCII quotes -- ' " -- into one of ? ? And unfortunately thats not very visible ] If this is the case emacs will helpfully tell you to do something about these In order to check for sure put the cursor on the char and type C-u C-x = eg On the ? I get ============================ position: 13 of 13 (92%), column: 0 character: ? (displayed as ?) (codepoint 8220, #o20034, #x201c) preferred charset: unicode (Unicode (ISO10646)) code point in charset: 0x201C script: symbol syntax: . which means: punctuation category: .:Base, c:Chinese, h:Korean, j:Japanese to input: type "C-x 8 RET HEX-CODEPOINT" or "C-x 8 RET NAME" buffer code: #xE2 #x80 #x9C file code: #xFF #xFE #x1C #x20 (encoded by coding system utf-16-le-unix) display: by this font (glyph code) xft:-DAMA-Ubuntu Mono-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1 (#x70) Character code properties: customize what to show name: LEFT DOUBLE QUOTATION MARK old-name: DOUBLE TURNED COMMA QUOTATION MARK general-category: Pi (Punctuation, Initial quote) decomposition: (8220) ('?') ================================ Yeah thats a mouthful but that the codepoint > 127 indicates you have a problem From steve at pearwood.info Sat Jun 18 12:02:43 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 19 Jun 2016 02:02:43 +1000 Subject: (repost) Advisory: HTTP Header Injection in Python urllib References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> <1466221941.3662846.641269641.7FFA59B4@webmail.messagingengine.com> Message-ID: <576570a4$0$1607$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Jun 2016 01:52 pm, Random832 wrote: > On Fri, Jun 17, 2016, at 21:00, Steven D'Aprano wrote: >> The author doesn't go into details of what sort of attacks against >> localhost they're talking about. An unauthenticated service running on >> localhost implies, to me, a single-user setup, where presumably the >> single-user has admin access to localhost. So I'm not really sure what >> "risk" they have > > The issue - especially clearly in this context, which demonstrates a > working exploit for this vulnerability - is cross-site request forgery. > Which doesn't technically require the victim service to be HTTP (I > remember a proof of concept a while back which would trick a browser > into connecting to an IRC server), so long as it can ignore HTTP > headers. Er, you may have missed that I'm talking about a single user setup. Are you suggesting that I can't trust myself not to forge a request that goes to a hostile site? It's all well and good to say that the application is vulnerable to X-site attacks, but how does that relate to a system where I'm the only user? -- Steven From dfnsonfsduifb at gmx.de Sat Jun 18 12:09:08 2016 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 18 Jun 2016 18:09:08 +0200 Subject: value of pi and 22/7 In-Reply-To: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> Message-ID: On 18.06.2016 01:12, Lawrence D?Oliveiro wrote: > I?m not sure how you can write ?30? with one digit... 3e1 has one significant digit. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From alister.ware at ntlworld.com Sat Jun 18 12:38:06 2016 From: alister.ware at ntlworld.com (alister) Date: Sat, 18 Jun 2016 16:38:06 GMT Subject: (repost) Advisory: HTTP Header Injection in Python urllib References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> <1466221941.3662846.641269641.7FFA59B4@webmail.messagingengine.com> <576570a4$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 19 Jun 2016 02:02:43 +1000, Steven D'Aprano wrote: > On Sat, 18 Jun 2016 01:52 pm, Random832 wrote: > >> On Fri, Jun 17, 2016, at 21:00, Steven D'Aprano wrote: >>> The author doesn't go into details of what sort of attacks against >>> localhost they're talking about. An unauthenticated service running on >>> localhost implies, to me, a single-user setup, where presumably the >>> single-user has admin access to localhost. So I'm not really sure what >>> "risk" they have >> >> The issue - especially clearly in this context, which demonstrates a >> working exploit for this vulnerability - is cross-site request forgery. >> Which doesn't technically require the victim service to be HTTP (I >> remember a proof of concept a while back which would trick a browser >> into connecting to an IRC server), so long as it can ignore HTTP >> headers. > > Er, you may have missed that I'm talking about a single user setup. Are > you suggesting that I can't trust myself not to forge a request that > goes to a hostile site? > > It's all well and good to say that the application is vulnerable to > X-site attacks, but how does that relate to a system where I'm the only > user? one possible reason I can think of is if for whatever reason your computer is infected by malware that malware could make use of the service. -- "The only way for a reporter to look at a politician is down." -- H.L. Mencken From random832 at fastmail.com Sat Jun 18 13:28:56 2016 From: random832 at fastmail.com (Random832) Date: Sat, 18 Jun 2016 13:28:56 -0400 Subject: (repost) Advisory: HTTP Header Injection in Python urllib In-Reply-To: <576570a4$0$1607$c3e8da3$5496439d@news.astraweb.com> References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> <1466221941.3662846.641269641.7FFA59B4@webmail.messagingengine.com> <576570a4$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1466270936.1206591.641594473.5759A310@webmail.messagingengine.com> On Sat, Jun 18, 2016, at 12:02, Steven D'Aprano wrote: > Er, you may have missed that I'm talking about a single user setup. > Are you suggesting that I can't trust myself not to forge a request > that goes to a hostile site? > > It's all well and good to say that the application is vulnerable to > X-site attacks, but how does that relate to a system where I'm the > only user? I don't think you understand what cross-site request forgery is, unless your definition of "single user setup" includes not connecting to the internet at all. The point is that one site causes the client to send a request (not desired by the user) to another site. That the client is a single-user system makes no difference. From no.email at nospam.invalid Sat Jun 18 16:43:11 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 18 Jun 2016 13:43:11 -0700 Subject: (repost) Advisory: HTTP Header Injection in Python urllib References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> <1466221941.3662846.641269641.7FFA59B4@webmail.messagingengine.com> <576570a4$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877fdm9qjk.fsf@jester.gateway.pace.com> Steven D'Aprano writes: >> The issue ... is cross-site request forgery. > Er, you may have missed that I'm talking about a single user setup. Are you > suggesting that I can't trust myself not to forge a request that goes to a > hostile site? I think the idea is you visit some website with malicious script that accesses your localhost resources from your browser. So it's not a matter of trusting yourself. Rather, it's one of trusting every website you visit, including the ad servers they transclude, etc. From ethan at stoneleaf.us Sat Jun 18 16:47:43 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Jun 2016 13:47:43 -0700 Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> Message-ID: <5765B36F.5010506@stoneleaf.us> On 06/18/2016 07:05 AM, Joonas Liik wrote: > On 18 June 2016 at 15:04, Pete Forman wrote: >> with obj: >> .a = 1 # equivalent to obj.a = 1 >> .total = .total + 1 # obj.total = obj.total + 1 > > the leading dot does not resolve the ambiguity that arises from: > > with ob_a: > with ob_b: > .attr_c = 42 # which object are we modifying right now? The innermost one. Why would it be anything else? -- ~Ethan~ From rosuav at gmail.com Sat Jun 18 17:20:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jun 2016 07:20:36 +1000 Subject: PyCon Keynote In-Reply-To: References: <5759C941.8040900@stoneleaf.us> Message-ID: On Sun, Jun 19, 2016 at 7:14 AM, Quivis wrote: > On Thu, 09 Jun 2016 12:53:37 -0700, Ethan Furman wrote: > >> https://www.youtube.com/watch?v=bSfe5M_zG2s > > Good example of how not to do a presentation. Embarrassing. > I turned it off after one minute. Strange. Must be in the eye of the beholder... I watched it, shared it with members of my family, then added it to our list of "watch these if you haven't". ChrisA From wrightalexw at gmail.com Sat Jun 18 18:25:25 2016 From: wrightalexw at gmail.com (alex wright) Date: Sat, 18 Jun 2016 18:25:25 -0400 Subject: PyCon Keynote In-Reply-To: References: <5759C941.8040900@stoneleaf.us> Message-ID: I enjoyed it. Skipped most of the intro video but I enjoyed the content of his talk. Shared with a co-worker as well. On Jun 18, 2016 5:23 PM, "Chris Angelico" wrote: > On Sun, Jun 19, 2016 at 7:14 AM, Quivis wrote: > > On Thu, 09 Jun 2016 12:53:37 -0700, Ethan Furman wrote: > > > >> https://www.youtube.com/watch?v=bSfe5M_zG2s > > > > Good example of how not to do a presentation. Embarrassing. > > I turned it off after one minute. > > Strange. Must be in the eye of the beholder... I watched it, shared it > with members of my family, then added it to our list of "watch these > if you haven't". > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From torriem at gmail.com Sat Jun 18 18:33:32 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 16:33:32 -0600 Subject: PyCon Keynote In-Reply-To: References: <5759C941.8040900@stoneleaf.us> Message-ID: On 06/18/2016 03:20 PM, Chris Angelico wrote: > On Sun, Jun 19, 2016 at 7:14 AM, Quivis wrote: >> On Thu, 09 Jun 2016 12:53:37 -0700, Ethan Furman wrote: >> >>> https://www.youtube.com/watch?v=bSfe5M_zG2s >> >> Good example of how not to do a presentation. Embarrassing. >> I turned it off after one minute. > > Strange. Must be in the eye of the beholder... I watched it, shared it > with members of my family, then added it to our list of "watch these > if you haven't". Indeed that was very good. Thanks for posting this, Ethan. It's neat to see the links between computer programming, logic, nature, life, and philosophy. He's a very good teacher and speaker. From torriem at gmail.com Sat Jun 18 19:06:13 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 17:06:13 -0600 Subject: PyCon Keynote In-Reply-To: References: <5759C941.8040900@stoneleaf.us> Message-ID: <68f843f6-820e-478b-892b-4bc6037ea61b@gmail.com> On 06/18/2016 04:33 PM, Michael Torrie wrote: > On 06/18/2016 03:20 PM, Chris Angelico wrote: >> On Sun, Jun 19, 2016 at 7:14 AM, Quivis wrote: >>> On Thu, 09 Jun 2016 12:53:37 -0700, Ethan Furman wrote: >>> >>>> https://www.youtube.com/watch?v=bSfe5M_zG2s >>> >>> Good example of how not to do a presentation. Embarrassing. >>> I turned it off after one minute. >> >> Strange. Must be in the eye of the beholder... I watched it, shared it >> with members of my family, then added it to our list of "watch these >> if you haven't". > > Indeed that was very good. Thanks for posting this, Ethan. It's neat to > see the links between computer programming, logic, nature, life, and > philosophy. He's a very good teacher and speaker. Does anyone know what kind of electric instrument he was playing and how it works? From torriem at gmail.com Sat Jun 18 19:07:05 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 17:07:05 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On 06/17/2016 05:52 PM, Chris via Python-list wrote: > Any suggestions for a good open source text editor for the Mac out > there? For now, I am going to stick with vim. Good choice. From lawrencedo99 at gmail.com Sat Jun 18 20:12:42 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 18 Jun 2016 17:12:42 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On Sunday, June 19, 2016 at 11:07:23 AM UTC+12, Michael Torrie wrote: > > On 06/17/2016 05:52 PM, Chris via Python-list wrote: >> >> Any suggestions for a good open source text editor for the Mac out >> there? For now, I am going to stick with vim. > > Good choice. The trouble with vim/vi/whatever, is that it doesn?t work like any other editor on Earth. Pull up any old GUI-based editor you like, for example Windows (shudder) Notepad. If there are N characters in your file, then the insertion point can be placed at N + 1 positions: in-between two adjacent characters, or before the first character, or after the last character. And this makes sense: anything you type is inserted at the insertion point. All rational text editors (and word processors) work this way. But not vi/vim. It only lets you place your cursor *on* a character, not *in-between* characters. That?s why you need two separate insertion commands, insert-before and insert-after. And one of those has the interesting side effect where, if you exit insertion mode without inserting anything, it doesn?t put you back in the same position as before. Why? As to why you need insertion commands at all, that?s another thing... From joel.goldstick at gmail.com Sat Jun 18 20:26:36 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 18 Jun 2016 20:26:36 -0400 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On Sat, Jun 18, 2016 at 8:12 PM, Lawrence D?Oliveiro wrote: > On Sunday, June 19, 2016 at 11:07:23 AM UTC+12, Michael Torrie wrote: >> >> On 06/17/2016 05:52 PM, Chris via Python-list wrote: >>> >>> Any suggestions for a good open source text editor for the Mac out >>> there? For now, I am going to stick with vim. >> >> Good choice. > > The trouble with vim/vi/whatever, is that it doesn?t work like any other editor on Earth. > > Pull up any old GUI-based editor you like, for example Windows (shudder) Notepad. If there are N characters in your file, then the insertion point can be placed at N + 1 positions: in-between two adjacent characters, or before the first character, or after the last character. And this makes sense: anything you type is inserted at the insertion point. All rational text editors (and word processors) work this way. > > But not vi/vim. It only lets you place your cursor *on* a character, not *in-between* characters. That?s why you need two separate insertion commands, insert-before and insert-after. And one of those has the interesting side effect where, if you exit insertion mode without inserting anything, it doesn?t put you back in the same position as before. Why? > > As to why you need insertion commands at all, that?s another thing... > -- > https://mail.python.org/mailman/listinfo/python-list I personally love vim. But its clearly an acquired taste. When you get good at it its pretty amazing -- and no mouse. The other thing about vim is that it is on every linux system, so you don't have to load your editor if you are ssh-ing to some machine -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From torriem at gmail.com Sat Jun 18 20:50:11 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 18:50:11 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <55237bfb-17d4-d7a6-5d81-1db0c38c7731@gmail.com> On 06/18/2016 06:12 PM, Lawrence D?Oliveiro wrote: > On Sunday, June 19, 2016 at 11:07:23 AM UTC+12, Michael Torrie > wrote: >> >> On 06/17/2016 05:52 PM, Chris via Python-list wrote: >>> >>> Any suggestions for a good open source text editor for the Mac >>> out there? For now, I am going to stick with vim. >> >> Good choice. > > The trouble with vim/vi/whatever, is that it doesn?t work like any > other editor on Earth. The fact that the OP is using vim would suggest this doesn't really matter to him all that much. > Pull up any old GUI-based editor you like, for example Windows > (shudder) Notepad. If there are N characters in your file, then the > insertion point can be placed at N + 1 positions: in-between two > adjacent characters, or before the first character, or after the last > character. And this makes sense: anything you type is inserted at the > insertion point. All rational text editors (and word processors) work > this way. Indeed, so does vi/vim. Why do you think otherwise? > But not vi/vim. It only lets you place your cursor *on* a character, > not *in-between* characters. That?s why you need two separate > insertion commands, insert-before and insert-after. And one of those > has the interesting side effect where, if you exit insertion mode > without inserting anything, it doesn?t put you back in the same > position as before. Why? > > As to why you need insertion commands at all, that?s another > thing... Having used vim for years and also normal editors including word processors, I have no idea what you're talking about by how insert works. It works the exactly the same. I put my cursor under a letter, hit insert, and I am inserting text before that letter, just like any other text editor. From torriem at gmail.com Sat Jun 18 21:01:03 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 19:01:03 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: <55237bfb-17d4-d7a6-5d81-1db0c38c7731@gmail.com> References: <55237bfb-17d4-d7a6-5d81-1db0c38c7731@gmail.com> Message-ID: <0c30da3d-4105-e5a1-b9af-f41940ac46b1@gmail.com> On 06/18/2016 06:50 PM, Michael Torrie wrote: > On 06/18/2016 06:12 PM, Lawrence D?Oliveiro wrote: >> But not vi/vim. It only lets you place your cursor *on* a character, >> not *in-between* characters. That?s why you need two separate >> insertion commands, insert-before and insert-after. And one of those >> has the interesting side effect where, if you exit insertion mode >> without inserting anything, it doesn?t put you back in the same >> position as before. Why? Nevermind I see what you are talking about. Doesn't bother me though. >> As to why you need insertion commands at all, that?s another >> thing... In it's day, the scriptability of ed depended on this feature. From torriem at gmail.com Sat Jun 18 22:09:11 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 20:09:11 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On 06/18/2016 06:12 PM, Lawrence D?Oliveiro wrote: > Pull up any old GUI-based editor you like, for example Windows > (shudder) Notepad. If there are N characters in your file, then the > insertion point can be placed at N + 1 positions: in-between two > adjacent characters, or before the first character, or after the last > character. And this makes sense: anything you type is inserted at the > insertion point. All rational text editors (and word processors) work > this way. > > But not vi/vim. It only lets you place your cursor *on* a character, > not *in-between* characters. That?s why you need two separate > insertion commands, insert-before and insert-after. And one of those > has the interesting side effect where, if you exit insertion mode > without inserting anything, it doesn?t put you back in the same > position as before. Why? In thinking about this, I think the answer is that in olden days no one had though of using the imaginary spaces between characters as a position. So we had: 0 1 2 3 4 5 6 7 8 9 H E L L O W O R L D 10 character cells, 10 cursor positions. Hence you had 10 places you could insert before (which works well for everything but appending to the string) or 10 places to insert after. So that distinction between insert and append was logical, and still is today, depending on your background and experience. It was later on that they figured out the N+1 thing you mentioned by ignoring the character cells: 0 1 2 3 4 5 6 7 8 9 10 H E L L O W O R L D That works well for interactive editing, but it doesn't lend itself as well to scripting and working with the contents of the text cells. Indeed the text cells aren't actually addressable directly in this scheme though conventionally the number immediately before the cell is used to index the cell. This can lead to confusion. For example, if the cursor is in position 10, that's not really part of the text, but it kind of appears like it is. I like that with vim I can see immediately whether there is trailing space on a line just by jumping to the end of the line ($) which will drop the cursor on the last actual character. So I guess it's just a matter of history. Perhaps it's a bit like big endian vs little endian. Neither system is inherently better; it's just what you get used to. And arguments can be made either way. From dpresley at midiowa.net Sat Jun 18 22:48:37 2016 From: dpresley at midiowa.net (drednot57) Date: Sat, 18 Jun 2016 19:48:37 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: My go to python editor is Dr. Python. Coded in Python with the wxPython GUI library, but I use Linux. From lawrencedo99 at gmail.com Sat Jun 18 22:51:57 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 18 Jun 2016 19:51:57 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <7fdf0a4d-64ef-495e-82ff-18707e3ca429@googlegroups.com> On Sunday, June 19, 2016 at 2:09:31 PM UTC+12, Michael Torrie wrote: > It was later on that they figured out the N+1 thing you mentioned by > ignoring the character cells: > > 0 1 2 3 4 5 6 7 8 9 10 > H E L L O W O R L D > > That works well for interactive editing, but it doesn't lend itself as > well to scripting and working with the contents of the text cells. Emacs scripting works perfectly well with this convention. > I like that with vim I can see immediately whether there is trailing > space on a line just by jumping to the end of the line ($) which will > drop the cursor on the last actual character. Emacs has an option (which I have enabled) which shows trailing white space throughout your entire file in bright red. And I have also defined a single keystroke that will get rid of it all. From torriem at gmail.com Sun Jun 19 00:54:16 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 22:54:16 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: <7fdf0a4d-64ef-495e-82ff-18707e3ca429@googlegroups.com> References: <7fdf0a4d-64ef-495e-82ff-18707e3ca429@googlegroups.com> Message-ID: On 06/18/2016 08:51 PM, Lawrence D?Oliveiro wrote: > On Sunday, June 19, 2016 at 2:09:31 PM UTC+12, Michael Torrie wrote: >> It was later on that they figured out the N+1 thing you mentioned by >> ignoring the character cells: >> >> 0 1 2 3 4 5 6 7 8 9 10 >> H E L L O W O R L D >> >> That works well for interactive editing, but it doesn't lend itself as >> well to scripting and working with the contents of the text cells. > > Emacs scripting works perfectly well with this convention. Yes that's true. Just saying though, it wasn't always obvious which is why ed chose to do it the way they did. vi, being somewhat compatible with ed's command structure, follows the same pattern. Two different ways of doing things. Let's not make the mistake of thinking one way is necessarily better. From torriem at gmail.com Sun Jun 19 00:56:10 2016 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Jun 2016 22:56:10 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: <7fdf0a4d-64ef-495e-82ff-18707e3ca429@googlegroups.com> References: <7fdf0a4d-64ef-495e-82ff-18707e3ca429@googlegroups.com> Message-ID: On 06/18/2016 08:51 PM, Lawrence D?Oliveiro wrote: > On Sunday, June 19, 2016 at 2:09:31 PM UTC+12, Michael Torrie wrote: >> It was later on that they figured out the N+1 thing you mentioned >> by ignoring the character cells: >> >> 0 1 2 3 4 5 6 7 8 9 10 H E L L O W O R L D >> >> That works well for interactive editing, but it doesn't lend itself >> as well to scripting and working with the contents of the text >> cells. > > Emacs scripting works perfectly well with this convention. > >> I like that with vim I can see immediately whether there is >> trailing space on a line just by jumping to the end of the line ($) >> which will drop the cursor on the last actual character. > > Emacs has an option (which I have enabled) which shows trailing white > space throughout your entire file in bright red. And I have also > defined a single keystroke that will get rid of it all. And I got it wrong anyway. Both ed and vim either put the cursor between characters (insert mode), or on the character (command mode). Probably made sense at the time. From lawrencedo99 at gmail.com Sun Jun 19 01:57:58 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 18 Jun 2016 22:57:58 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: <7fdf0a4d-64ef-495e-82ff-18707e3ca429@googlegroups.com> Message-ID: <9030e089-5087-4e0a-9b71-cda427c1ebc4@googlegroups.com> On Sunday, June 19, 2016 at 4:54:36 PM UTC+12, Michael Torrie wrote: > Two different ways of doing things. Let's not make the mistake of thinking one > way is necessarily better. When one leads to more complications, the answer is pretty clear... From auriocus at gmx.de Sun Jun 19 03:13:13 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 19 Jun 2016 09:13:13 +0200 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: Am 19.06.16 um 02:12 schrieb Lawrence D?Oliveiro: > The trouble with vim/vi/whatever, is that it doesn?t work like any > other editor on Earth. > > Pull up any old GUI-based editor you like, for example Windows > (shudder) Notepad. If there are N characters in your file, then the > insertion point can be placed at N + 1 positions: in-between two > adjacent characters, or before the first character, or after the last > character. > But not vi/vim. It only lets you place your cursor *on* a character, > not *in-between* characters. This is true if you use the text-mode version. I prefer gvim (actually macvim on the mac) which feels much more like a modern editor. Once you go to insert mode, you won't notice that it is special unless you hit Escape. You can place the cursor in between characters, as you said, you can backspace to join two lines together, you can push some buttons and menu entries to save files, a standard dialog comes up to choose a file etc. In the original vi, command mode was necessary to get this functionality - even to move the cursor or delete a character - but with gvim/macvim you get both a standard/modern interface in insert mode and the commands if you need them. > That?s why you need two separate > insertion commands, insert-before and insert-after. I rarely do "a" because pushing "i" and then cursor-right does the same in vim, even in the text mode variant you can move the cursor after the last character. Christian From lawrencedo99 at gmail.com Sun Jun 19 03:34:20 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 19 Jun 2016 00:34:20 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> On Sunday, June 19, 2016 at 7:13:26 PM UTC+12, Christian Gollwitzer wrote: > Am 19.06.16 um 02:12 schrieb Lawrence D?Oliveiro: > >> But not vi/vim. It only lets you place your cursor *on* a character, >> not *in-between* characters. > > This is true if you use the text-mode version. I prefer gvim (actually > macvim on the mac) which feels much more like a modern editor. Why not just use a modern editor, and be done with it? From rustompmody at gmail.com Sun Jun 19 03:47:59 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 00:47:59 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> References: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> Message-ID: <01ed9e07-c72e-4ec9-9fab-3e7d37abe082@googlegroups.com> On Sunday, June 19, 2016 at 1:04:37 PM UTC+5:30, Lawrence D?Oliveiro wrote: > On Sunday, June 19, 2016 at 7:13:26 PM UTC+12, Christian Gollwitzer wrote: > > > Am 19.06.16 um 02:12 schrieb Lawrence D?Oliveiro: > > > >> But not vi/vim. It only lets you place your cursor *on* a character, > >> not *in-between* characters. > > > > This is true if you use the text-mode version. I prefer gvim (actually > > macvim on the mac) which feels much more like a modern editor. > > Why not just use a modern editor, and be done with it? You say "Use a modern editor" And you use emacs?? Heh!! And its not just that emacs is one of the oldest pieces of software in use today that I am talking of Its decades of crud that really gets me eg. What do Control-X/C mean on any App of your choice today? And what do they mean in emacs? JFTR I am an emacs user for some 20+ years Its just that not only do my 20- year old students not tolerate emacs, of late they stop tolerating me if I use emacs!! What do they prefer as an editor? Gawd knows! Web browser maybe?? More likely a phone... From auriocus at gmx.de Sun Jun 19 03:57:07 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 19 Jun 2016 09:57:07 +0200 Subject: best text editor for programming Python on a Mac In-Reply-To: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> References: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> Message-ID: Am 19.06.16 um 09:34 schrieb Lawrence D?Oliveiro: > On Sunday, June 19, 2016 at 7:13:26 PM UTC+12, Christian Gollwitzer wrote: > >> Am 19.06.16 um 02:12 schrieb Lawrence D?Oliveiro: >> >>> But not vi/vim. It only lets you place your cursor *on* a character, >>> not *in-between* characters. >> >> This is true if you use the text-mode version. I prefer gvim (actually >> macvim on the mac) which feels much more like a modern editor. > > Why not just use a modern editor, and be done with it? Because you still *can* use the features it offers? For example, I do not know many editors which can autocomplete file names, this is very nice when you write scripts which refer to external files. Or pass a part of a script through an external program. Maybe I was unclear about the insert mode thing. gvim is a GUI program with toolbars and menus and mouse actions. It *is* a modern editor. It provides syntax highlighting, autocompletion, folding, tabbed windows, an error window to navigate compiler errors etc. There are not many editors out there that can compete, are free and not weird. But unlike "vim" in a console window, "gvim" (Linux) or "macvim" (OSX) behaves according to current interface design, it feels integrated to the platform. And yes, the insertion cursor is a vertical bar, not block, and sits between the characters. Christian From diolu.remove_this_part at bigfoot.com Sun Jun 19 04:29:39 2016 From: diolu.remove_this_part at bigfoot.com (Olive) Date: Sun, 19 Jun 2016 10:29:39 +0200 Subject: Launching a process with stdout in the terminal and captured References: <20160618090944.4bceb1e0@bigfoot.com> Message-ID: <20160619102939.3c5fbbac@bigfoot.com> eryk sun wrote: > On Sat, Jun 18, 2016 at 7:09 AM, Olive > wrote: > > I am here on Linux. > > ... > > Note that if it is possible I would prefer that the launched command see its standard > > output connected to a terminal > > Try pexpect. > > https://pypi.python.org/pypi/pexpect That's not what I am looking for. I want to let the end user intercat with the process, not my script. What I want is the content (after the process has exited) of all what it has written on standard output. Olive From lawrencedo99 at gmail.com Sun Jun 19 05:47:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 19 Jun 2016 02:47:10 -0700 (PDT) Subject: Launching a process with stdout in the terminal and captured In-Reply-To: <20160619102939.3c5fbbac@bigfoot.com> References: <20160618090944.4bceb1e0@bigfoot.com> <20160619102939.3c5fbbac@bigfoot.com> Message-ID: <4ae0249e-4588-4a2b-ba03-e38e6db69a76@googlegroups.com> On Sunday, June 19, 2016 at 8:29:50 PM UTC+12, Olive wrote: > > That's not what I am looking for. I want to let the end user intercat with the > process, not my script. What I want is the content (after the process has > exited) of all what it has written on standard output. Use the logging feature of screen . From petef4+usenet at gmail.com Sun Jun 19 06:16:45 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Sun, 19 Jun 2016 11:16:45 +0100 Subject: Method Chaining References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> Message-ID: Rustom Mody writes: > On Saturday, June 18, 2016 at 5:34:30 PM UTC+5:30, Pete Forman wrote: >> Rustom Mody writes: >> [snip] >> >> One subtle difference between your two citations is that VB uses a >> leading dot. Might that lessening of ambiguity enable a future Python to >> allow this? >> >> class Foo: >> def .set(a): # equivalent to def set(self, a): >> .a = a # equivalent to self.a = a >> > > Chuckle! Heck Why not?! > But no I did not think of this Why stop there? Another long standing bugbear can be addressed with this. class Foo: def .set(.a, b) # equivalent to def set(self, a): self.a = a .c += b # equivalent to self.c += b Explicitly, that is three new syntactic items. 1) . before a method name elides the first argument of self 2) . before an argument is shorthand for assign to a member 3) . before a variable in a method body replaces self. Earlier I had proposed a new use of "with" that would have changed the binding in (3) from self to something else. That was not a good idea for two reasons. Python already provides a reasonable way to achieve that, as described in the design FAQ. The second reason is that it subverts the current "with" statement which mandates its with_item to be a context expression. "as target" is optional and so syntactic discrimination is not possible. -- Pete Forman From petef4+usenet at gmail.com Sun Jun 19 06:41:44 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Sun, 19 Jun 2016 11:41:44 +0100 Subject: best text editor for programming Python on a Mac References: Message-ID: Joel Goldstick writes: > On Sat, Jun 18, 2016 at 8:12 PM, Lawrence D?Oliveiro > wrote: >> On Sunday, June 19, 2016 at 11:07:23 AM UTC+12, Michael Torrie wrote: >>> >>> On 06/17/2016 05:52 PM, Chris via Python-list wrote: >>>> >>>> Any suggestions for a good open source text editor for the Mac out >>>> there? For now, I am going to stick with vim. >>> >>> Good choice. >> >> The trouble with vim/vi/whatever, is that it doesn?t work like any >> other editor on Earth. >> >> Pull up any old GUI-based editor you like, for example Windows >> (shudder) Notepad. If there are N characters in your file, then the >> insertion point can be placed at N + 1 positions: in-between two >> adjacent characters, or before the first character, or after the last >> character. And this makes sense: anything you type is inserted at the >> insertion point. All rational text editors (and word processors) work >> this way. >> >> But not vi/vim. It only lets you place your cursor *on* a character, >> not *in-between* characters. That?s why you need two separate >> insertion commands, insert-before and insert-after. And one of those >> has the interesting side effect where, if you exit insertion mode >> without inserting anything, it doesn?t put you back in the same >> position as before. Why? >> >> As to why you need insertion commands at all, that?s another thing... >> -- >> https://mail.python.org/mailman/listinfo/python-list > > I personally love vim. But its clearly an acquired taste. When you > get good at it its pretty amazing -- and no mouse. The other thing > about vim is that it is on every linux system, so you don't have to > load your editor if you are ssh-ing to some machine Both emacs and vim are powerful tools in the hands of experienced users but I would recommend neither to someone starting out who is just looking for a code-aware editor. Emacs and vim are much more than editors. I'm composing this message using Emacs/Gnus on a Mac. TRAMP is invaluable to me for my daily work. -- Pete Forman From python.list at tim.thechases.com Sun Jun 19 07:36:09 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 19 Jun 2016 06:36:09 -0500 Subject: best text editor for programming Python on a Mac In-Reply-To: References: <7fdf0a4d-64ef-495e-82ff-18707e3ca429@googlegroups.com> Message-ID: <20160619063609.101b3f35@bigbox.christie.dr> On 2016-06-18 22:56, Michael Torrie wrote: > And I got it wrong anyway. Both ed and vim either put the cursor > between characters (insert mode), or on the character (command > mode). Probably made sense at the time. Correct for vi/vim, but not ed which has no real concept of a characterwise "insert mode". Rather, "insert mode" is where you enter one line at a time (using whatever your system's line-input function does for cursor display; with behavior possibly modified if you use `rlwrap`) until you finish entering your text by putting a lone period on a line. -tkc From liik.joonas at gmail.com Sun Jun 19 07:56:44 2016 From: liik.joonas at gmail.com (Joonas Liik) Date: Sun, 19 Jun 2016 14:56:44 +0300 Subject: Method Chaining In-Reply-To: <5765B36F.5010506@stoneleaf.us> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> <5765B36F.5010506@stoneleaf.us> Message-ID: On 18 June 2016 at 23:47, Ethan Furman wrote: > On 06/18/2016 07:05 AM, Joonas Liik wrote: >> >> On 18 June 2016 at 15:04, Pete Forman wrote: > > >>> with obj: >>> .a = 1 # equivalent to obj.a = 1 >>> .total = .total + 1 # obj.total = obj.total + 1 >> >> >> the leading dot does not resolve the ambiguity that arises from: >> >> with ob_a: >> with ob_b: >> .attr_c = 42 # which object are we modifying right now? > > > The innermost one. Why would it be anything else? > > -- > ~Ethan~ > > -- > https://mail.python.org/mailman/listinfo/python-list What if ob_b does not have attribute attr_c but ob_a does? This may be simple for a computer to solve - try looking it up on ob_b and fall back to ob_a if ob_b has no such attr.. but it is hard(er) to reason about for a human. You need to know about the inner structure of ob_b. not an issue for the person who writes it at first (unless 2 months have passed ) but a real pain if you are seeing that bit of code for the first time or are not intimately familiar with what ob_b is. Not unsolvable ofc, but makes it easier for obscure bugs to hide. From marko at pacujo.net Sun Jun 19 08:57:36 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 19 Jun 2016 15:57:36 +0300 Subject: best text editor for programming Python on a Mac References: Message-ID: <87r3btuyin.fsf@elektro.pacujo.net> Pete Forman : > Both emacs and vim are powerful tools in the hands of experienced > users but I would recommend neither to someone starting out who is > just looking for a code-aware editor. I don't know. I'm recommending emacs to everybody, especially the complete beginners, who don't yet have to unlearn anything. Marko From torriem at gmail.com Sun Jun 19 09:19:36 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 19 Jun 2016 07:19:36 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: On 06/19/2016 04:41 AM, Pete Forman wrote: > Both emacs and vim are powerful tools in the hands of experienced users > but I would recommend neither to someone starting out who is just > looking for a code-aware editor. In any case this doesn't matter here because the original poster already said he was using vim. Sticking with vim is a fine choice. From torriem at gmail.com Sun Jun 19 09:23:15 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 19 Jun 2016 07:23:15 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> References: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> Message-ID: On 06/19/2016 01:34 AM, Lawrence D?Oliveiro wrote: > On Sunday, June 19, 2016 at 7:13:26 PM UTC+12, Christian Gollwitzer wrote: > >> Am 19.06.16 um 02:12 schrieb Lawrence D?Oliveiro: >> >>> But not vi/vim. It only lets you place your cursor *on* a character, >>> not *in-between* characters. >> >> This is true if you use the text-mode version. I prefer gvim (actually >> macvim on the mac) which feels much more like a modern editor. > > Why not just use a modern editor, and be done with it? Why would you even suggest this to a vim user? What's your point? If you're not a vim user then you have no idea how vim benefits the person who is proficient in it and enjoys using it. There are many reasons to use vim. Since you're not really interested in these reasons I won't bother re-stating them here. I'm sure there are reasons you prefer a "modern editor" also. I can argue all day long about how arcane emacs is, and argue how wodnerful vim is, but I could never in seriousness suggest to an emacs user that he'd be better off using vim or a "modern editor." Nor should you. From antoon.pardon at rece.vub.ac.be Sun Jun 19 10:35:29 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 19 Jun 2016 16:35:29 +0200 Subject: the global keyword: In-Reply-To: References: Message-ID: <5766ADB1.6070907@rece.vub.ac.be> Op 12-06-16 om 23:10 schreef BartC: > On 12/06/2016 20:25, Ned Batchelder wrote: >> Just as here there is no link between x >> and y: >> >> x = 12 >> y = x > > (And that's a good illustration of why 'y' isn't a name reference to 'x', referring to the "...ducks limp" thread. But best not to rake it up again...) > I find this rather inaccurate reference to what your opposition is supposed to have states together with the remark best not to rake this up again, rather disingenuous From ethan at stoneleaf.us Sun Jun 19 11:01:53 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 19 Jun 2016 08:01:53 -0700 Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> <5765B36F.5010506@stoneleaf.us> Message-ID: <5766B3E1.2020807@stoneleaf.us> On 06/19/2016 04:56 AM, Joonas Liik wrote: > On 18 June 2016 at 23:47, Ethan Furman wrote: >> On 06/18/2016 07:05 AM, Joonas Liik wrote: >>> the leading dot does not resolve the ambiguity that arises from: >>> >>> with ob_a: >>> with ob_b: >>> .attr_c = 42 # which object are we modifying right now? >> >> >> The innermost one. Why would it be anything else? > > What if ob_b does not have attribute attr_c but ob_a does? Good question. I would say that _only_ the innermost with object is searched, and if it doesn't have the requested attribute an AttributeError is raised. Otherwise, as you say, it could be a nightmare to maintain. -- ~Ethan~ From torriem at gmail.com Sun Jun 19 11:14:21 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 19 Jun 2016 09:14:21 -0600 Subject: Method Chaining In-Reply-To: <5766B3E1.2020807@stoneleaf.us> References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> <5765B36F.5010506@stoneleaf.us> <5766B3E1.2020807@stoneleaf.us> Message-ID: On 06/19/2016 09:01 AM, Ethan Furman wrote: > On 06/19/2016 04:56 AM, Joonas Liik wrote: >> On 18 June 2016 at 23:47, Ethan Furman wrote: >>> On 06/18/2016 07:05 AM, Joonas Liik wrote: > >>>> the leading dot does not resolve the ambiguity that arises from: >>>> >>>> with ob_a: >>>> with ob_b: >>>> .attr_c = 42 # which object are we modifying right now? >>> >>> >>> The innermost one. Why would it be anything else? >> >> What if ob_b does not have attribute attr_c but ob_a does? > > Good question. I would say that _only_ the innermost with object is > searched, and if it doesn't have the requested attribute an > AttributeError is raised. Otherwise, as you say, it could be a > nightmare to maintain. But that wouldn't work either because it would make it impossible to *set* attributes on an object. If ob_a had attr_c but object ob_b did not, should it set the attribute on ob_b or overwrite the attribute on ob_a? Python's dynamic nature just doesn't lend itself to this kind of ambiguity. From ethan at stoneleaf.us Sun Jun 19 11:56:44 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 19 Jun 2016 08:56:44 -0700 Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> <5765B36F.5010506@stoneleaf.us> <5766B3E1.2020807@stoneleaf.us> Message-ID: <5766C0BC.1070009@stoneleaf.us> On 06/19/2016 08:14 AM, Michael Torrie wrote: > On 06/19/2016 09:01 AM, Ethan Furman wrote: >> On 06/19/2016 04:56 AM, Joonas Liik wrote: >>> On 18 June 2016 at 23:47, Ethan Furman wrote: >>>> On 06/18/2016 07:05 AM, Joonas Liik wrote: >>>>> the leading dot does not resolve the ambiguity that arises from: >>>>> >>>>> with ob_a: >>>>> with ob_b: >>>>> .attr_c = 42 # which object are we modifying right now? >>>> >>>> >>>> The innermost one. Why would it be anything else? >>> >>> What if ob_b does not have attribute attr_c but ob_a does? >> >> Good question. I would say that _only_ the innermost with object is >> searched, and if it doesn't have the requested attribute an >> AttributeError is raised. Otherwise, as you say, it could be a >> nightmare to maintain. > > But that wouldn't work either because it would make it impossible to > *set* attributes on an object. Sure it would, just like any 'this_thing.whatever = 9' works just fine if 'this_thing' doesn't already a `whatever` attribute. The only thing that would change is being able to omit the 'this_thing' portion; if you want to access an earlier 'with' obj, then you must be explicit: with ob_a: with ob_b: ob_a.whatever = 9 .something_else = 10 > Python's dynamic nature just doesn't lend itself to this kind of ambiguity. This is no more ambiguous than any other nested structure and, in some cases, even simpler. -- ~Ethan From rustompmody at gmail.com Sun Jun 19 12:03:56 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 09:03:56 -0700 (PDT) Subject: Method Chaining In-Reply-To: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <2dffea93-3dbd-4d04-93ed-6e02e3dd8660@googlegroups.com> <5765B36F.5010506@stoneleaf.us> <5766B3E1.2020807@stoneleaf.us> <5766C0BC.1070009@stoneleaf.us> Message-ID: <156b0b1b-8501-4d40-9ea3-3e8748b28dee@googlegroups.com> On Sunday, June 19, 2016 at 9:26:54 PM UTC+5:30, Ethan Furman wrote: > On 06/19/2016 08:14 AM, Michael Torrie wrote: > > On 06/19/2016 09:01 AM, Ethan Furman wrote: > >> On 06/19/2016 04:56 AM, Joonas Liik wrote: > >>> On 18 June 2016 at 23:47, Ethan Furman wrote: > >>>> On 06/18/2016 07:05 AM, Joonas Liik wrote: > > >>>>> the leading dot does not resolve the ambiguity that arises from: > >>>>> > >>>>> with ob_a: > >>>>> with ob_b: > >>>>> .attr_c = 42 # which object are we modifying right now? > >>>> > >>>> > >>>> The innermost one. Why would it be anything else? > >>> > >>> What if ob_b does not have attribute attr_c but ob_a does? > >> > >> Good question. I would say that _only_ the innermost with object is > >> searched, and if it doesn't have the requested attribute an > >> AttributeError is raised. Otherwise, as you say, it could be a > >> nightmare to maintain. > > > > But that wouldn't work either because it would make it impossible to > > *set* attributes on an object. > > Sure it would, just like any 'this_thing.whatever = 9' works just fine > if 'this_thing' doesn't already a `whatever` attribute. > > The only thing that would change is being able to omit the 'this_thing' > portion; if you want to access an earlier 'with' obj, then you must be > explicit: > > with ob_a: > with ob_b: > ob_a.whatever = 9 > .something_else = 10 > > > Python's dynamic nature just doesn't lend itself to this kind of ambiguity. > > This is no more ambiguous than any other nested structure and, in some > cases, even simpler. Yes to be clear the idea is mostly syntactic: with ob_a : .some ... .other ... (maybe set or get ie lhs or rhs) desugars to ob_a.some ... ob_a.other ... And for an outer with the reach does not include and inner with Just as in C if you have a nested switch the scope of the case-labels of the outer excludes the inner From rustompmody at gmail.com Sun Jun 19 12:20:58 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 09:20:58 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> On Sunday, June 19, 2016 at 6:49:55 PM UTC+5:30, Michael Torrie wrote: > On 06/19/2016 04:41 AM, Pete Forman wrote: > > Both emacs and vim are powerful tools in the hands of experienced users > > but I would recommend neither to someone starting out who is just > > looking for a code-aware editor. > > In any case this doesn't matter here because the original poster already > said he was using vim. Sticking with vim is a fine choice. In general I would agree with this line. In this case... Yes the OP said he was using vim And he could not handle a unicode encoding issue I gave an emacs solution to the issue not because I find editor-wars engaging but because I dont know how to do *this* with vi. I'd be surprised if vi actually cant do these: 1. Look under the unicode-hood to peek at what a char is -- C-u C-x = in emacs 2. Change file encoding -- C-x RET f in emacs Please do suggest vi-ways of handling this -- that would be useful! From joel.goldstick at gmail.com Sun Jun 19 13:16:32 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 19 Jun 2016 13:16:32 -0400 Subject: the global keyword: In-Reply-To: <5766ADB1.6070907@rece.vub.ac.be> References: <5766ADB1.6070907@rece.vub.ac.be> Message-ID: On Sun, Jun 19, 2016 at 10:35 AM, Antoon Pardon wrote: > Op 12-06-16 om 23:10 schreef BartC: >> On 12/06/2016 20:25, Ned Batchelder wrote: >>> Just as here there is no link between x >>> and y: >>> >>> x = 12 >>> y = x >> >> (And that's a good illustration of why 'y' isn't a name reference to 'x', referring to the "...ducks limp" thread. But best not to rake it up again...) >> > I find this rather inaccurate reference to what your opposition is > supposed to have states together with the remark best not to rake > this up again, rather disingenuous > -- > https://mail.python.org/mailman/listinfo/python-list People who understand global variables generally avoid using them at all costs. People who don't understand why globals create problems seem to want to use them, and then become baffled at the problems they cause. If you are learning python, very very low on your list of things to learn is global variables. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From auriocus at gmx.de Sun Jun 19 14:06:03 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 19 Jun 2016 20:06:03 +0200 Subject: best text editor for programming Python on a Mac In-Reply-To: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> Message-ID: Am 19.06.16 um 18:20 schrieb Rustom Mody: > I gave an emacs solution to the issue not because I find editor-wars engaging > but because I dont know how to do *this* with vi. > I'd be surprised if vi actually cant do these: > 1. Look under the unicode-hood to peek at what a char is -- C-u C-x = in emacs > 2. Change file encoding -- C-x RET f in emacs > > Please do suggest vi-ways of handling this -- that would be useful! > Changing the encoding is :set fileencoding=utf-8 for instance. This will recode the buffer to utf-8, the rendering should stay the same. Saving the file would now write a bytestream which has an utf-8 interpretation in accordance to the display. In any case, I'd suggest to install macvim on the Mac, instead of using the Apple-provided vim, because of it's GUI windows and overall better integration (file types, copy/paste etc.) Christian From rustompmody at gmail.com Sun Jun 19 14:13:04 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 11:13:04 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> Message-ID: On Sunday, June 19, 2016 at 11:36:17 PM UTC+5:30, Christian Gollwitzer wrote: > Am 19.06.16 um 18:20 schrieb Rustom Mody: > > I gave an emacs solution to the issue not because I find editor-wars engaging > > but because I dont know how to do *this* with vi. > > I'd be surprised if vi actually cant do these: > > 1. Look under the unicode-hood to peek at what a char is -- C-u C-x = in emacs > > 2. Change file encoding -- C-x RET f in emacs > > > > Please do suggest vi-ways of handling this -- that would be useful! > > > Changing the encoding is > > :set fileencoding=utf-8 I was suggesting something like :set fileencoding=latin-1 It does work in a way in the sense that a file that has chars that would not encode to latin-1 does give errors But only later when saving and not pinpointing where the error is [Or I am doing something wrong maybe] From pdorange at pas-de-pub-merci.mac.com Sun Jun 19 14:28:59 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Sun, 19 Jun 2016 20:28:59 +0200 Subject: [tkinter] widget size adjustment Message-ID: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> Hi, I got a small interface handle with tkinter / Gridmanager. I configure row and column to follow user window size adjustement, that' fine. but i do not know how to adjust the main widget : a canvas displaying a portion of a big image. I bind a resize event that works, but do not know what to do from that. Any clue or advice or tutorial ? -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From torriem at gmail.com Sun Jun 19 14:58:53 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 19 Jun 2016 12:58:53 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> Message-ID: On 06/19/2016 10:20 AM, Rustom Mody wrote: > Yes the OP said he was using vim > And he could not handle a unicode encoding issue I missed that part! I somehow thought the unicode issues were coming from his use of the built-in Mac text editor. In any case, I have never had unicode problems with vim. It seems to handle them just fine for me. I've never had a problem opening a UTF-8 file, using a unicode string literal, and running it in Python. > I gave an emacs solution to the issue not because I find editor-wars engaging > but because I dont know how to do *this* with vi. > I'd be surprised if vi actually cant do these: > 1. Look under the unicode-hood to peek at what a char is -- C-u C-x = in emacs When the cursor is over character, do command "ga" and it will show you the hex code for that character. http://vim.wikia.com/wiki/Showing_the_ASCII_value_of_the_current_character > 2. Change file encoding -- C-x RET f in emacs Display current encoding: :set fileencoding Set encoding to UTF-8: :set filenecoding=utf-8 > Please do suggest vi-ways of handling this -- that would be useful! From torriem at gmail.com Sun Jun 19 15:04:49 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 19 Jun 2016 13:04:49 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> Message-ID: <96f065cb-54b5-4b68-9fab-2029d0785367@gmail.com> On 06/19/2016 12:06 PM, Christian Gollwitzer wrote: > Am 19.06.16 um 18:20 schrieb Rustom Mody: >> I gave an emacs solution to the issue not because I find editor-wars engaging >> but because I dont know how to do *this* with vi. >> I'd be surprised if vi actually cant do these: >> 1. Look under the unicode-hood to peek at what a char is -- C-u C-x = in emacs >> 2. Change file encoding -- C-x RET f in emacs >> >> Please do suggest vi-ways of handling this -- that would be useful! >> > Changing the encoding is > > :set fileencoding=utf-8 > > for instance. This will recode the buffer to utf-8, the rendering should > stay the same. Saving the file would now write a bytestream which has an > utf-8 interpretation in accordance to the display. Actually it doesn't re-encode the buffer iteslf. Upon saving it will try to encode the buffer to that. There's another variable, just "encoding" that I think refers the buffer in memory. Not sure about that though. From bc at freeuk.com Sun Jun 19 17:20:59 2016 From: bc at freeuk.com (BartC) Date: Sun, 19 Jun 2016 22:20:59 +0100 Subject: the global keyword: In-Reply-To: References: <5766ADB1.6070907@rece.vub.ac.be> Message-ID: On 19/06/2016 15:35, Antoon Pardon wrote: > Op 12-06-16 om 23:10 schreef BartC: >> On 12/06/2016 20:25, Ned Batchelder wrote: >>> Just as here there is no link between x >>> and y: >>> >>> x = 12 >>> y = x >> >> (And that's a good illustration of why 'y' isn't a name reference to 'x', referring to the "...ducks limp" thread. But best not to rake it up again...) >> > I find this rather inaccurate reference to what your opposition is > supposed to have states together with the remark best not to rake > this up again, rather disingenuous > Sorry, haven't been able to parse that. What is inaccurate? What am I supposed to be opposed to? And why is it disingenuous? The original thread is still open to posts AFAIK if someone wants to discuss it further. -- bartc From greg.ewing at canterbury.ac.nz Sun Jun 19 18:14:24 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Jun 2016 10:14:24 +1200 Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: Lawrence D?Oliveiro wrote: > I feel a new phrase coming on: ?good enough for Bible work?! I understand there's a passage in the Bible somewhere that uses a 1 significant digit approximation to pi... -- Greg From torriem at gmail.com Sun Jun 19 18:15:48 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 19 Jun 2016 16:15:48 -0600 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <9d6fce0b-4d8b-6bd7-4ea4-807844d471a2@gmail.com> On 06/19/2016 03:21 PM, Quivis wrote: > On Sat, 18 Jun 2016 20:26:36 -0400, Joel Goldstick wrote: > >> that it is on every linux system > > No, it isn't! I can be *installed* on every Linux system, but that a > whole other can of worms. True vim is not. But vi should be. I'm not aware of any Linux distro which does not install it. Do you know of a distro that does not? Even Ubuntu with it's nano default editor installs vi, if I'm not mistaken. Some distros use a stripped-down version of vim (perhaps vim-tiny) instead of vi, but the command "vi" is always going to be there. Even on my embedded OpenWRT devices! From greg.ewing at canterbury.ac.nz Sun Jun 19 18:25:51 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Jun 2016 10:25:51 +1200 Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: Ian Kelly wrote: > Remember, the cubit was based on the length of the > forearm, so it's not like it was a terribly precise measurement to > begin with; Let's not sell them short. Just because it was based on a forearm doesn't mean they didn't have a precise standard for it, any more than people who measure things in "feet" do it by plonking down their own foot. No doubt it wasn't as precise as what we have nowadays, but it was probably a lot better than human body part variations. > they might not have understood significant figures, but > they probably wouldn't have been overly concerned about the difference > between thirty and thirty-one. If you're building something the size of a pyramid, that could add up to quite a lot of error. -- Greg From greg.ewing at canterbury.ac.nz Sun Jun 19 18:38:35 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Jun 2016 10:38:35 +1200 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: Michael Vilain wrote: > BBEdit has been around a long time and for it's price ($130) it does a > lot but it's falling behind the times. New versions aren't really adding > much in terms of new features. There's a free version of BBEdit called TextWrangler that's pretty good. I'm currently using it for all my Mac programming work. -- Greg From greg.ewing at canterbury.ac.nz Sun Jun 19 18:44:53 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Jun 2016 10:44:53 +1200 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: Lawrence D?Oliveiro wrote: > But not vi/vim. It only lets you place your cursor *on* a character, not > *in-between* characters. That's because the terminals it was designed to work on didn't have any way of displaying a cursor between two characters. Emacs is the same (except it doesn't go as far as having two different insertion modes -- you just think of the insertion point as being to the left of the character that the cursor is on). I would say that's about the *least* weird thing about vi[m] though... :-( -- Greg From steve at pearwood.info Sun Jun 19 21:32:48 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 20 Jun 2016 11:32:48 +1000 Subject: best text editor for programming Python on a Mac References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> Message-ID: <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jun 2016 04:58 am, Michael Torrie wrote: > When the cursor is over character, do command "ga" and it will show you > the hex code for that character. > > http://vim.wikia.com/wiki/Showing_the_ASCII_value_of_the_current_character /me cries Every time somebody refers to "the ASCII value" of non-ASCII characters, God kills a puppy. No wonder people find it so hard to understand Unicode. They have to unlearn a bunch of misapprehensions first. -- Steven From rustompmody at gmail.com Sun Jun 19 22:07:13 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 19:07:13 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, June 20, 2016 at 7:03:01 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 20 Jun 2016 04:58 am, Michael Torrie wrote: > > > When the cursor is over character, do command "ga" and it will show you > > the hex code for that character. > > > > http://vim.wikia.com/wiki/Showing_the_ASCII_value_of_the_current_character > > /me cries > > Every time somebody refers to "the ASCII value" of non-ASCII characters, God > kills a puppy. > > > No wonder people find it so hard to understand Unicode. They have to unlearn > a bunch of misapprehensions first. Ooooo! I LOVE crocodiles especially the crocodile-tears variety The title says get ASCII value; the first line of the writeup says ASCII or Unicode. If python were to do more than lip service to REALLY being a unicode age language why are things like this out of bounds even for discussion? http://blog.languager.org/2014/04/unicoded-python.html Note: Please make a distinction between - Any ONE of these suggestions; none of which need to be taken too seriously individually And - The simple barefaced fact that not a single lexeme from python3 apart from comments and identifiers allow elements from the set Unicode - ASCII. Of which comments are arguably not in the language And uncode identifiers are an opened pandora box with bigger disadvantages than advantages From steve at pearwood.info Sun Jun 19 22:07:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 20 Jun 2016 12:07:19 +1000 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: <57674fd8$0$1586$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jun 2016 08:25 am, Gregory Ewing wrote: > Ian Kelly wrote: >> Remember, the cubit was based on the length of the >> forearm, so it's not like it was a terribly precise measurement to >> begin with; > > Let's not sell them short. Just because it was based on a forearm > doesn't mean they didn't have a precise standard for it, any more > than people who measure things in "feet" do it by plonking down > their own foot. > > No doubt it wasn't as precise as what we have nowadays, but > it was probably a lot better than human body part variations. And let's not make the mistake of presentism, judging the past by the standards of the present. The biggest problem with the cubit is not that it is *inaccurate*, as that different places had their own idea of what a cubit was. I dare say that on any specific building site, the foreman would ensure that everyone was working with more or less the same idea of what a cubit was. But once you moved from one village or town to another, chances are that they were using a different idea of a cubit that was not quite the same as yours. To be honest, I don't actually know much about the situation in Ancient Egypt. For all I know, every tradesman did measure his bit of the pyramid by laying his forearm down on the rock and adjusting by eye. (But I doubt it.) And they did have two distinct measures, what we today call the "Royal cubit" and the "short cubit". So I expect that there actually was quite a bit of day to day confusion and frustration due to the lack of accurate and consistent measurements. One of the most underrated yet critical functions of government is to standardise weights and measures, and that function evolved very slowly over time. I doubt that the Egyptian Pharoahs cared about it, although their scribes probably did, a bit. If you look at, say, Medieval and even Renaissance Europe, one of the biggest problems people faced was the lack of standard definitions of units. Every village and town had their own idea of what a hogshead was, to say nothing of unscrupulous merchants who would deliberately underweigh or undermeasure. It was a big enough problem that governments eventually evolved entire bureaucracies to ensure that when you ordered 10000 yards of cloth, you got 10000 yards of cloth, and not an argument about what a yard actually is. But even today, we still have lack of agreement at the national level: 1,000,000 US gallons are about 832,674 UK gallons. Similarly for miles: US statute miles are ever-so-slightly less than UK miles. But at least the metric system is the same everywhere. >> they might not have understood significant figures, but >> they probably wouldn't have been overly concerned about the difference >> between thirty and thirty-one. > > If you're building something the size of a pyramid, that could > add up to quite a lot of error. Indeed. -- Steven From alexandre.horta at gmail.com Sun Jun 19 22:17:09 2016 From: alexandre.horta at gmail.com (Alexandre Paloschi Horta) Date: Sun, 19 Jun 2016 19:17:09 -0700 (PDT) Subject: Tox, pytest and pyperclip - System doesn't find clipboard Message-ID: Hi everyone. I'm having the following problem on an app I'm developing. I'm writing a software that uses the Pyperclip module. I'm using pytest for the tests. Everything worked well so far, as long as I run the tests via pytest. The thing is, I want to use Tox, and now things didn't work so well. When I run the tests via Tox, the following error happens on those tests that depend on pyperclip: self = .ClipboardUnavailable object at 0xb6a2246c> args = ('Small sample of text in the clipboard.',), kwargs = {} def __call__(self, *args, **kwargs): > raise PyperclipException(EXCEPT_MSG) E pyperclip.exceptions.PyperclipException: E Pyperclip could not find a copy/paste mechanism for your system. E For more information, please visit https://pyperclip.readthedocs.org On Linux, the pyperclip module depends on the existence of a way to access the copy/paste mechanism. Either one of those works: xclip, xsel, GTK or PyQT4. I noticed that on my machine pyperclip is using xclip, so I tried these configurations on tox.ini: [testenv] deps = py pytest pyperclip pluggy commands = py.test -vv whitelist_externals = /usr/bin/xclip [testenv] deps = py pytest pyperclip pluggy commands = py.test -vv /usr/bin/xclip whitelist_externals = /usr/bin/xclip [testenv] deps = py pytest pyperclip pluggy commands = py.test -vv [testenv:Linux] whitelist_externals = /usr/bin/xclip None worked. What am I doing wrong? Here are the software versions: pyperclip 1.5.27 pytest 2.9.1 python 3.4.2 Debian with Gnome From python.list at tim.thechases.com Sun Jun 19 22:41:48 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 19 Jun 2016 21:41:48 -0500 Subject: best text editor for programming Python on a Mac In-Reply-To: <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160619214148.78c07851@bigbox.christie.dr> On 2016-06-20 11:32, Steven D'Aprano wrote: > On Mon, 20 Jun 2016 04:58 am, Michael Torrie wrote: > > > When the cursor is over character, do command "ga" and it will > > show you the hex code for that character. > > > > http://vim.wikia.com/wiki/Showing_the_ASCII_value_of_the_current_character > > /me cries > > Every time somebody refers to "the ASCII value" of non-ASCII > characters, God kills a puppy. Though to be fair, vim and Unicode both have their origins around 1987, so for one to know of the other would have taken a bit of miraculous prognostication. Despite existing since then, I don't recall hearing much about Unicode as a *common* standard until the early 2000s, so that's defensibly ~13 years of (semi-)obscurity during parallel development. The "ga" mnemonic of "[g]a=ascii value" made much more sense in the historical context. Now that Vim supports Unicode, "ga" shows the ordinal value depending on the internal encoding. If that internal encoding is UTF or UCS encoded Unicode (whether 8-bit, 16-bit, or 32-bit, big-or-little endian), then it shows the code-point. If it's a one- or two-byte encoding, vim returns that index. So the mnemonic should become "ga=ascii value or unicode code point along with possible combing/composing-character code-points". Not as helpful a mnemonic. As an aside, Vim also provides a "g8" command to show the decomposed hex bytes of a UTF-8 byte sequence if you want those values instead. Both should handle combining/composing characters as well. -tkc For more details within vim: :help ga :help g8 :help encoding-values From steve at pearwood.info Sun Jun 19 23:29:26 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 20 Jun 2016 13:29:26 +1000 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jun 2016 12:07 pm, Rustom Mody wrote: > If python were to do more than lip service to REALLY being a unicode age > language why are things like this out of bounds even for discussion? > > http://blog.languager.org/2014/04/unicoded-python.html Quote: "Why do we have to write x!=y then argue about the status of x<>y when we can simply write x?y?" "Simply"? This is how I write x?y from scratch: - press the 'x' key on my keyboard - grab the mouse - move mouse to Start menu - pause and wait for "Utilities" submenu to appear - move mouse over "Utilities" submenu - pause and wait for "More Applications" submenu to appear - move mouse to "More Applications" submenu - move mouse to "Gnome charmap" - click - wait a second - move mouse to "Character Map" window - click on "Search" menu - click on "Find" menu item - release mouse - type "unequal" and press ENTER - press ENTER to dismiss the "Not Found" dialog - type "not equal" and press ENTER - press ESC to dismiss the Find dialog - grab the mouse - click the ? glyph - pause and swear when nothing happens - double-click the ? glyph - move the mouse to the "Copy" button - click "Copy" - visually search the task bar for my editor - click on the editor - invariably I end up accidentally moving the insertion point, so click after the 'x' - release the mouse - press Ctrl-V - press the 'y' key and I am done. Now, I accept that some of those steps could probably be streamlined. Better tooling would probably make it better, e.g. my editor could offer its own char map, which hopefully wouldn't suck like Open Office's inbuilt "Insert Special Character" function. It would be nice if the editor keep a cache of "Frequently Inserted Characters", because realistically there's only a set of about twenty or thirty that I use frequently. A programmer's editor could even offer a per-language palette of non-ASCII operators. Or there could be a keyboard shortcut which I probably wouldn't remember. If I could remember a seemingly infinite number of arbitrary keyboard commands, I'd use Emacs or Vi :-) In theory most Linux apps support an X mechanism for inserting characters that don't appear on the keyboard. Unfortunately, this gives no feedback when you get it wrong, and discoverablity is terrible. It's taken me many years to discover and learn the following: WIN o WIN o gives ? WIN m WIN u gives ? WIN s WIN s gives ? WIN . . gives ? (WIN is the Windows key) Getting back to ? I tried: WIN = WIN / WIN / WIN = WIN < WIN > WIN ! WIN = etc none of which do anything. Another example of missing tooling is the lack of a good keyboard application. Back in the 1980s, Apple Macs had a desk accessory that didn't just simulate the keyboard, but showed what characters were available. If you held down the Option key, the on-screen keyboard would display the characters each key would insert. This increased discoverability and made it practical for Hypertalk to accept non-ASCII synonyms such as ? for <= ? for >= ? for <> Without better tooling and more discoverability, non-ASCII characters as syntax are an anti-feature. -- Steven From flebber.crue at gmail.com Sun Jun 19 23:51:41 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sun, 19 Jun 2016 20:51:41 -0700 (PDT) Subject: lxml - SubElement dump root doesn't dump like Element dump does Message-ID: <8a1bbff2-14a4-4a1a-b53f-ca94f94d54bc@googlegroups.com> Afternoon Wondering has anyone much experience with lxml specifically objectify? When I pick up a file with lxml and use objectify dumping root works as expected actually better its quite nice. This is how i do it, file handling part left out for brevity. def getsMeet(file_list): for filename in sorted(file_list): filename=my_dir + filename yield filename def parseXML(): """ """ for file in getsMeet(file_list): with open(file) as f: xml = f.read() root = objectify.fromstring(xml) print(root.tag) print(objectify.dump(root)) race = objectify.SubElement(root,"race") print(objectify.dump(race)) parseXML() So the first call to print(objectify.dump(root)) gives as a sample. meeting = None [ObjectifiedElement] * id = '42977' * barriertrial = '0' * venue = 'Rosehill Gardens' * date = '2016-05-21T00:00:00' * gearchanges = '-1' * stewardsreport = '-1' * gearlist = '-1' * racebook = '0' * postracestewards = '0' * meetingtype = 'TAB' * rail = 'Timing - Electronic : Rail - +6m' * weather = 'Fine ' * trackcondition = 'Good 3 ' * nomsdeadline = '2016-05-16T11:00:00' * weightsdeadline = '2016-05-17T16:00:00' * acceptdeadline = '2016-05-18T09:00:00' * jockeydeadline = '2016-05-18T12:00:00' club = '' [StringElement] * abbrevname = 'Australian Turf Club' * code = '56398' * associationclass = '1' * website = 'http://' race = None [ObjectifiedElement] * id = '215411' * number = '1' * nomnumber = '9' Then I am confused when I want to repeat this but only for the subelement race I get a return but not as expected. This is my return race = '' [StringElement] so why do i not get all the elements of race as I do when i dump the root? Cheers Sayth PS I am referring to this documentation http://lxml.de/objectify.html#element-access-through-object-attributes From philb at philb.ca Mon Jun 20 00:30:48 2016 From: philb at philb.ca (Phil Boutros) Date: Mon, 20 Jun 2016 04:30:48 -0000 (UTC) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > Quote: > > "Why do we have to write x!=y then argue about the status of x<>y when we > can simply write x?y?" > > "Simply"? > > This is how I write x?y from scratch: To wrap this back full circle, here's how it's done on vim: Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? It's still probably a horrible idea to have it in a programming language, though, unless the original behaviour still also works. Phil -- AH#61 Wolf#14 BS#89 bus#1 CCB#1 SENS KOTC#4 philb at philb.ca http://philb.ca EKIII rides with me: http://eddiekieger.com From rustompmody at gmail.com Mon Jun 20 00:36:30 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 21:36:30 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4a3484ef-7922-462f-af89-4d2eeda5af03@googlegroups.com> On Monday, June 20, 2016 at 8:59:44 AM UTC+5:30, Steven D'Aprano wrote: > Without better tooling and more discoverability, non-ASCII characters as > syntax are an anti-feature. You need to decide which hat you have on - idealist - pragmatist >From a pragmatic pov nothing you are saying below is arguable. The argument starts because you are taking the moral high ground against a *title* and presumably the mnemonic (the 'a' in :ga) in the vi docs. Ignoring that the implementation and the doc-body are aligned with current practices > Getting back to ? I tried: > I have greater horror-stories to describe if you like On my recent ubuntu upgrade my keyboard broke -- totally ie cant type anything. Here's a detailed rundown... Upgrade complete; reboot -- NO KEYBOARD -- Yikes However login works in X -- after login ... GONE And ttys (Ctrl-Alt-F1 etc) fine; no issue. Searched around.. "Uninstall ibus" seems to be the advice... No go Some Unity issue it looks? Installed xfce (from tty) Again after few days (some upgrade dont remember which) keyboard broken Um Now what to install? gnome?? OMG! Created a new login... Problem gone... Well whats the problem?? Well whatever!! Finally by chance discovered that the problem was probably uim uim is an alternative to ibus I had installed it to make this work: https://github.com/rrthomas/pointless-xcompose which is aimed precisely at removing this pain: > This is how I write x?y from scratch: > > - press the 'x' key on my keyboard > - grab the mouse > - move mouse to Start menu > - pause and wait for "Utilities" submenu to appear > - move mouse over "Utilities" submenu > - pause and wait for "More Applications" submenu to appear > - move mouse to "More Applications" submenu > - move mouse to "Gnome charmap" > - click > - wait a second > - move mouse to "Character Map" window > - click on "Search" menu > - click on "Find" menu item > - release mouse > - type "unequal" and press ENTER > - press ENTER to dismiss the "Not Found" dialog > - type "not equal" and press ENTER > - press ESC to dismiss the Find dialog > - grab the mouse > - click the ? glyph > - pause and swear when nothing happens > - double-click the ? glyph > - move the mouse to the "Copy" button > - click "Copy" > - visually search the task bar for my editor > - click on the editor > - invariably I end up accidentally moving the insertion point, > so click after the 'x' > - release the mouse > - press Ctrl-V > - press the 'y' key > > and I am done. > So yeah... - Remedy worse than evil? Sure - Unpractical? of course. So also thought programmers in the 70s, when presented with possibility of using lowercase when everyone used FORTRAN, COBOL and PL/1 and programming meant CODING ON CODING SHEETS LIKE THIS BTW the maverick that offered this completely unnecessarily wasteful luxury was called Unix > In theory most Linux apps support an X mechanism for inserting characters > that don't appear on the keyboard. Unfortunately, this gives no feedback > when you get it wrong, and discoverablity is terrible. It's taken me many > years to discover and learn the following: > > WIN o WIN o gives ? > WIN m WIN u gives ? > WIN s WIN s gives ? > WIN . . gives ? > > (WIN is the Windows key) > Heres a small sample of what you get with xcompose [compose key can be anything; in my case its set to right-alt] COMP oo ? COMP mu ? COMP 12 ? COMP <> ? COMP => ? COMP -v ? COMP ^^i ? Likewise n ? Nifty when it works; nicely parameterisable -- just edit ~/.XCompose But mind your next upgrade :D COMP -^ ? > > > > http://blog.languager.org/2014/04/unicoded-python.html > > Quote: > > "Why do we have to write x!=y then argue about the status of x<>y when we > can simply write x?y?" > > "Simply"? > Early adopters by definition live on the bleeding edge So "not simple" today ? "not simple" tomorrow From rustompmody at gmail.com Mon Jun 20 00:41:44 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 21:41:44 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <4a3484ef-7922-462f-af89-4d2eeda5af03@googlegroups.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <4a3484ef-7922-462f-af89-4d2eeda5af03@googlegroups.com> Message-ID: On Monday, June 20, 2016 at 10:06:41 AM UTC+5:30, Rustom Mody wrote: > I have greater horror-stories to describe if you like > On my recent ubuntu upgrade my keyboard broke -- totally ie cant type anything. > Here's a detailed rundown... > > Upgrade complete; reboot -- NO KEYBOARD -- Yikes > However login works in X -- after login ... GONE > And ttys (Ctrl-Alt-F1 etc) fine; no issue. > > Searched around.. "Uninstall ibus" seems to be the advice... No go > Some Unity issue it looks? > Installed xfce (from tty) > > Again after few days (some upgrade dont remember which) keyboard broken > Um Now what to install? gnome?? OMG! > > Created a new login... Problem gone... > > Well whats the problem?? Well whatever!! > Finally by chance discovered that the problem was probably uim > uim is an alternative to ibus > I had installed it to make this work: > https://github.com/rrthomas/pointless-xcompose > > which is aimed precisely at removing this pain: Umm that comes across as an inversion and misrepresentation. uim got UNINSTALLED in the upgrade [I did it and forgot? it automatically happened?? Dont remember] No uim; no ibus; no input method evidently From rustompmody at gmail.com Mon Jun 20 01:03:15 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jun 2016 22:03:15 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, June 20, 2016 at 10:01:00 AM UTC+5:30, Phil Boutros wrote: > Steven D'Aprano wrote: > > > > Quote: > > > > "Why do we have to write x!=y then argue about the status of x<>y when we > > can simply write x?y?" > > > > "Simply"? > > > > This is how I write x?y from scratch: > > > To wrap this back full circle, here's how it's done on vim: > > Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? Are these 'shortcuts' parameterizable? > > It's still probably a horrible idea to have it in a programming > language, though, unless the original behaviour still also works. That goes without saying: Gradual evolutionary changes are more likely to be lasting than violent revolutionary ones. Which evolution is already happening: Fortress: https://umbilicus.wordpress.com/2009/10/16/fortress-parallel-by-default/ [unfortunately died along with its patron Sun microsystems] Agda: http://mazzo.li/posts/AgdaSort.html which is based on Haskell but cleans up -> to ? forall to ? In addition to allowing arbitrary operators like ? Julia: http://iaindunning.com/blog/julia-unicode.html And of course the original APL: http://aplwiki.com/FinnAplIdiomLibrary From ian.g.kelly at gmail.com Mon Jun 20 01:19:41 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Jun 2016 23:19:41 -0600 Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: On Sun, Jun 19, 2016 at 4:25 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> >> Remember, the cubit was based on the length of the >> forearm, so it's not like it was a terribly precise measurement to >> begin with; > > > Let's not sell them short. Just because it was based on a forearm > doesn't mean they didn't have a precise standard for it, any more > than people who measure things in "feet" do it by plonking down > their own foot. > > No doubt it wasn't as precise as what we have nowadays, but > it was probably a lot better than human body part variations. Sure, but I think you've missed my central point, which is not that they wouldn't have made reasonably precise measurements in construction, but only that the storytellers would have rounded things off for their audience. We still do the same thing today. A house appraisal will report its footprint to the nearest square foot, but most people when talking about it casually aren't going to say "my house is 1936 square feet". More likely they'll just say "about 1900 square feet", since past the first couple of digits nobody really cares. From lawrencedo99 at gmail.com Mon Jun 20 01:50:23 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 19 Jun 2016 22:50:23 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <5766ADB1.6070907@rece.vub.ac.be> Message-ID: <6e96235c-39c3-4afa-9c69-e5b911b6924d@googlegroups.com> On Monday, June 20, 2016 at 5:16:50 AM UTC+12, Joel Goldstick wrote: > People who understand global variables generally avoid using them at > all costs. I use them occasionally. > People who don't understand why globals create problems > seem to want to use them, and then become baffled at the problems they > cause. Haven?t encountered any ?baffling? problems with them yet. > If you are learning python, very very low on your list of > things to learn is global variables. Probably fair comment. ?nonlocal? is much more fun. ;) From lawrencedo99 at gmail.com Mon Jun 20 01:51:46 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 19 Jun 2016 22:51:46 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: <593039af-b15b-4186-9784-a8a4e7da2062@googlegroups.com> On Monday, June 20, 2016 at 10:26:03 AM UTC+12, Gregory Ewing wrote: > If you're building something the size of a pyramid, that could > add up to quite a lot of error. Particularly since so many of their neighbours had worked out how to do much better than that, thousands of years earlier... From random832 at fastmail.com Mon Jun 20 02:04:19 2016 From: random832 at fastmail.com (Random832) Date: Mon, 20 Jun 2016 02:04:19 -0400 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1466402659.590756.642556081.412E8163@webmail.messagingengine.com> On Mon, Jun 20, 2016, at 01:03, Rustom Mody wrote: > > Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? > > Are these 'shortcuts' parameterizable? They originate from RFC 1345, with the extension that they can be reversed if the reverse doesn't itself exist as a RFC 1345 combination. From __peter__ at web.de Mon Jun 20 02:19:00 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Jun 2016 08:19 +0200 Subject: lxml - SubElement dump root doesn't dump like Element dump does References: <8a1bbff2-14a4-4a1a-b53f-ca94f94d54bc@googlegroups.com> Message-ID: Sayth Renshaw wrote: > Afternoon > > Wondering has anyone much experience with lxml specifically objectify? > > When I pick up a file with lxml and use objectify dumping root works as > expected actually better its quite nice. This is how i do it, file > handling part left out for brevity. > > def getsMeet(file_list): > for filename in sorted(file_list): > filename=my_dir + filename > yield filename > > def parseXML(): > """ > """ > for file in getsMeet(file_list): > with open(file) as f: > xml = f.read() > > root = objectify.fromstring(xml) > print(root.tag) > print(objectify.dump(root)) > race = objectify.SubElement(root,"race") > print(objectify.dump(race)) > > > parseXML() > > So the first call to print(objectify.dump(root)) gives as a sample. > > meeting = None [ObjectifiedElement] > * id = '42977' > * barriertrial = '0' > * venue = 'Rosehill Gardens' > * date = '2016-05-21T00:00:00' > * gearchanges = '-1' > * stewardsreport = '-1' > * gearlist = '-1' > * racebook = '0' > * postracestewards = '0' > * meetingtype = 'TAB' > * rail = 'Timing - Electronic : Rail - +6m' > * weather = 'Fine ' > * trackcondition = 'Good 3 ' > * nomsdeadline = '2016-05-16T11:00:00' > * weightsdeadline = '2016-05-17T16:00:00' > * acceptdeadline = '2016-05-18T09:00:00' > * jockeydeadline = '2016-05-18T12:00:00' > club = '' [StringElement] > * abbrevname = 'Australian Turf Club' > * code = '56398' > * associationclass = '1' > * website = 'http://' > race = None [ObjectifiedElement] > * id = '215411' > * number = '1' > * nomnumber = '9' > > Then I am confused when I want to repeat this but only for the subelement > race I get a return but not as expected. > > This is my return > race = '' [StringElement] > > so why do i not get all the elements of race as I do when i dump the root? Because race is a new SubElement that you just created: >>> help(lxml.objectify.SubElement) Help on built-in function SubElement in module lxml.etree: SubElement(...) SubElement(_parent, _tag, attrib=None, nsmap=None, **_extra) Subelement factory. This function creates an element instance, and appends it to an existing element. >>> Existing subelements can be accessed as attributes. I'd say that's the very point of the lxml.objectify library ;) For example: >>> root = lxml.objectify.fromstring("onetwosecond b") >>> print(lxml.objectify.dump(root.b)) b = None [ObjectifiedElement] c = 'one' [StringElement] d = 'two' [StringElement] >>> print(lxml.objectify.dump(root.b[0])) b = None [ObjectifiedElement] c = 'one' [StringElement] d = 'two' [StringElement] >>> print(lxml.objectify.dump(root.b[1])) b = 'second b' [StringElement] > Cheers > > Sayth > PS I am referring to this documentation > http://lxml.de/objectify.html#element-access-through-object-attributes Read that again. From steve+comp.lang.python at pearwood.info Mon Jun 20 02:22:30 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 20 Jun 2016 16:22:30 +1000 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: <57678baa$0$1603$c3e8da3$5496439d@news.astraweb.com> On Monday 20 June 2016 15:19, Ian Kelly wrote: > Sure, but I think you've missed my central point, which is not that > they wouldn't have made reasonably precise measurements in > construction, but only that the storytellers would have rounded things > off for their audience. > > We still do the same thing today. A house appraisal will report its > footprint to the nearest square foot, but most people when talking > about it casually aren't going to say "my house is 1936 square feet". > More likely they'll just say "about 1900 square feet", since past the > first couple of digits nobody really cares. There's a difference though. Nobody has tried to legislate the value of pi to match your casual reference to "about 1900 square feet", but there's been at least one serious attempt to legislate the value of pi to match the implied value given by the Bible. And some very large percentage of people in the world, especially in but not limited to the USA, will dispute your suggestion that "storytellers would have rounded things off for their audience" on the basis that every single word in the Bible is the inerrant, literal word of the god known as God. If the Bible implies that pi is 3, then by gum, that means it is 3. Or at least, that's what they *say* they believe. In practice, the literalists accept that the Bible contains metaphors, stories, and other non-literal text the same as everyone else does, they just pick and choose[1] which bits they choose to accept as literal in ways that strike others as naive, stupid, out- dated or outright wicked. [1] To be fair, as we all do, as the ancient Hebrews unaccountably failed to mark up their texts using tags. -- Steve From flebber.crue at gmail.com Mon Jun 20 03:13:13 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 20 Jun 2016 00:13:13 -0700 (PDT) Subject: lxml - SubElement dump root doesn't dump like Element dump does In-Reply-To: References: <8a1bbff2-14a4-4a1a-b53f-ca94f94d54bc@googlegroups.com> Message-ID: Thanks your way makes more sense indeed. In the example they create and access I think I just got lost in their example. Sayth From marko at pacujo.net Mon Jun 20 03:32:43 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Jun 2016 10:32:43 +0300 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <593039af-b15b-4186-9784-a8a4e7da2062@googlegroups.com> Message-ID: <87eg7suxgk.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Monday, June 20, 2016 at 10:26:03 AM UTC+12, Gregory Ewing wrote: > >> If you're building something the size of a pyramid, that could >> add up to quite a lot of error. > > Particularly since so many of their neighbours had worked out how to > do much better than that, thousands of years earlier... Width/height ratio of the pyramid of Cheops was so close to ?/2 that UFO enthusiasts were convinced alien technology was used in the construction of the pyramids. The whole story involving cubits, drums and fingers is here: . This is the definite proof, that no god, astronaut or Atlantean wizard had any intention of coding Pi into one of the many pyramids erected in Egypt. Pi is simply a result of the measurement methods used in old Egypt! Marko From auriocus at gmx.de Mon Jun 20 03:37:22 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 20 Jun 2016 09:37:22 +0200 Subject: best text editor for programming Python on a Mac In-Reply-To: References: <9d6fce0b-4d8b-6bd7-4ea4-807844d471a2@gmail.com> Message-ID: Am 20.06.16 um 00:15 schrieb Michael Torrie: > On 06/19/2016 03:21 PM, Quivis wrote: >> On Sat, 18 Jun 2016 20:26:36 -0400, Joel Goldstick wrote: >> >>> that it is on every linux system >> >> No, it isn't! I can be *installed* on every Linux system, but that a >> whole other can of worms. > > True vim is not. But vi should be. I'm not aware of any Linux distro > which does not install it. Do you know of a distro that does not? That would be very strange, since vi is mandated by POSIX http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html Of course there are other options, like elvis or busybox, but unless you are building a minimalist POSIX system the most viable option would be to install vim. So practically every desktop Linux distro ships with vim. Christian From lawrencedo99 at gmail.com Mon Jun 20 03:57:14 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 20 Jun 2016 00:57:14 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, June 20, 2016 at 4:31:00 PM UTC+12, Phil Boutros wrote: > > Steven D'Aprano wrote: >> >> This is how I write x?y from scratch: > > > To wrap this back full circle, here's how it's done on vim: > > Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? Standard Linux sequence: compose-slash-equals (or compose-equals-slash). Works in every sensible editor, terminal emulator, text-input field in web browsers and other GUI apps. In short, everywhere. From lawrencedo99 at gmail.com Mon Jun 20 03:59:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 20 Jun 2016 00:59:22 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <8c3bd89d-b560-4adb-8c7e-c6de7b364ac3@googlegroups.com> On Monday, June 20, 2016 at 10:45:08 AM UTC+12, Gregory Ewing wrote: > > Lawrence D?Oliveiro wrote: > >> But not vi/vim. It only lets you place your cursor *on* a character, not >> *in-between* characters. > > That's because the terminals it was designed to work on > didn't have any way of displaying a cursor between two > characters. That?s a dumb excuse. I?ve been using full-screen editors since 1979, on VT52 and later VT100 and then VT220 terminals, until text-mode terminals became obsolete. They all worked the way Emacs does, and vi does not. From lawrencedo99 at gmail.com Mon Jun 20 04:01:21 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 20 Jun 2016 01:01:21 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: <87eg7suxgk.fsf@elektro.pacujo.net> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <593039af-b15b-4186-9784-a8a4e7da2062@googlegroups.com> <87eg7suxgk.fsf@elektro.pacujo.net> Message-ID: <8b99700a-6492-4982-a6a6-987e1761a5db@googlegroups.com> On Monday, June 20, 2016 at 7:32:54 PM UTC+12, Marko Rauhamaa wrote: > Width/height ratio of the pyramid of Cheops was so close to ?/2 that UFO > enthusiasts were convinced alien technology was used in the construction > of the pyramids. They were also able to get the bases of the pyramids horizontal to within about a centimetre. Amazing achievement, but entirely achievable with bronze-age technology. From flebber.crue at gmail.com Mon Jun 20 04:21:23 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 20 Jun 2016 01:21:23 -0700 (PDT) Subject: lxml - SubElement dump root doesn't dump like Element dump does In-Reply-To: References: <8a1bbff2-14a4-4a1a-b53f-ca94f94d54bc@googlegroups.com> Message-ID: <9c0595de-4e61-4f32-9a17-f1e2d53a12b0@googlegroups.com> On Monday, 20 June 2016 16:19:31 UTC+10, Peter Otten wrote: > Sayth Renshaw wrote: > > > Afternoon > > > > Wondering has anyone much experience with lxml specifically objectify? > > > > When I pick up a file with lxml and use objectify dumping root works as > > expected actually better its quite nice. This is how i do it, file > > handling part left out for brevity. > > > > def getsMeet(file_list): > > for filename in sorted(file_list): > > filename=my_dir + filename > > yield filename > > > > def parseXML(): > > """ > > """ > > for file in getsMeet(file_list): > > with open(file) as f: > > xml = f.read() > > > > root = objectify.fromstring(xml) > > print(root.tag) > > print(objectify.dump(root)) > > race = objectify.SubElement(root,"race") > > print(objectify.dump(race)) > > > > > > parseXML() > > > > So the first call to print(objectify.dump(root)) gives as a sample. > > > > meeting = None [ObjectifiedElement] > > * id = '42977' > > * barriertrial = '0' > > * venue = 'Rosehill Gardens' > > * date = '2016-05-21T00:00:00' > > * gearchanges = '-1' > > * stewardsreport = '-1' > > * gearlist = '-1' > > * racebook = '0' > > * postracestewards = '0' > > * meetingtype = 'TAB' > > * rail = 'Timing - Electronic : Rail - +6m' > > * weather = 'Fine ' > > * trackcondition = 'Good 3 ' > > * nomsdeadline = '2016-05-16T11:00:00' > > * weightsdeadline = '2016-05-17T16:00:00' > > * acceptdeadline = '2016-05-18T09:00:00' > > * jockeydeadline = '2016-05-18T12:00:00' > > club = '' [StringElement] > > * abbrevname = 'Australian Turf Club' > > * code = '56398' > > * associationclass = '1' > > * website = 'http://' > > race = None [ObjectifiedElement] > > * id = '215411' > > * number = '1' > > * nomnumber = '9' > > > > Then I am confused when I want to repeat this but only for the subelement > > race I get a return but not as expected. > > > > This is my return > > race = '' [StringElement] > > > > so why do i not get all the elements of race as I do when i dump the root? > > Because race is a new SubElement that you just created: > > >>> help(lxml.objectify.SubElement) > Help on built-in function SubElement in module lxml.etree: > > SubElement(...) > SubElement(_parent, _tag, attrib=None, nsmap=None, **_extra) > > Subelement factory. This function creates an element instance, and > appends it to an existing element. > > >>> > > Existing subelements can be accessed as attributes. I'd say that's the very > point of the lxml.objectify library ;) > > For example: > > >>> root = > lxml.objectify.fromstring("onetwosecond > b") > >>> print(lxml.objectify.dump(root.b)) > b = None [ObjectifiedElement] > c = 'one' [StringElement] > d = 'two' [StringElement] > >>> print(lxml.objectify.dump(root.b[0])) > b = None [ObjectifiedElement] > c = 'one' [StringElement] > d = 'two' [StringElement] > >>> print(lxml.objectify.dump(root.b[1])) > b = 'second b' [StringElement] > this actually seems quite powerful, I don't fully understand it yet though it seems I have just got an XML doc as a list of dicts so I can just slice and select as normal python. thanks for helping Sayth From alister.ware at ntlworld.com Mon Jun 20 04:30:48 2016 From: alister.ware at ntlworld.com (alister) Date: Mon, 20 Jun 2016 08:30:48 GMT Subject: best text editor for programming Python on a Mac References: <52cb588a-4b6d-4097-884c-8b38db42136e@googlegroups.com> Message-ID: On Sun, 19 Jun 2016 07:23:15 -0600, Michael Torrie wrote: > On 06/19/2016 01:34 AM, Lawrence D?Oliveiro wrote: >> On Sunday, June 19, 2016 at 7:13:26 PM UTC+12, Christian Gollwitzer >> wrote: >> >>> Am 19.06.16 um 02:12 schrieb Lawrence D?Oliveiro: >>> >>>> But not vi/vim. It only lets you place your cursor *on* a character, >>>> not *in-between* characters. >>> >>> This is true if you use the text-mode version. I prefer gvim (actually >>> macvim on the mac) which feels much more like a modern editor. >> >> Why not just use a modern editor, and be done with it? > > Why would you even suggest this to a vim user? What's your point? If > you're not a vim user then you have no idea how vim benefits the person > who is proficient in it and enjoys using it. There are many reasons to > use vim. Since you're not really interested in these reasons I won't > bother re-stating them here. I'm sure there are reasons you prefer a > "modern editor" also. > > I can argue all day long about how arcane emacs is, and argue how > wodnerful vim is, but I could never in seriousness suggest to an emacs > user that he'd be better off using vim or a "modern editor." Nor should > you. indeed The only thing EMACS lacks is a good text editor. Vi has two modes "beep repeatedly" and "break Everything" Although both the editors are extremely powerful they both suffer from over design. -- If at first you don't succeed, you are running about average. From bc at freeuk.com Mon Jun 20 06:21:59 2016 From: bc at freeuk.com (BartC) Date: Mon, 20 Jun 2016 11:21:59 +0100 Subject: the global keyword: In-Reply-To: References: <5766ADB1.6070907@rece.vub.ac.be> Message-ID: On 19/06/2016 18:16, Joel Goldstick wrote: > People who understand global variables generally avoid using them at > all costs. Then perhaps they don't understand that in Python, top-level functions, classes and imports are also globals. -- Bartc From steve+comp.lang.python at pearwood.info Mon Jun 20 06:24:03 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 20 Jun 2016 20:24:03 +1000 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5767c445$0$1611$c3e8da3$5496439d@news.astraweb.com> On Monday 20 June 2016 17:57, Lawrence D?Oliveiro wrote: > On Monday, June 20, 2016 at 4:31:00 PM UTC+12, Phil Boutros wrote: >> >> Steven D'Aprano wrote: >>> >>> This is how I write x?y from scratch: >> >> >> To wrap this back full circle, here's how it's done on vim: >> >> Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? > > Standard Linux sequence: compose-slash-equals (or compose-equals-slash). > Works in every sensible editor, terminal emulator, text-input field in web > browsers and other GUI apps. In short, everywhere. Everywhere compose is configured the way you expect. > Nice link, thank you, although missing a few things. Like how to query which key is the compose key, and how to specify a key other than CapsLock. But there's always Google, I suppose. According to that link: "By default this function is not assigned to any key." So... not so much "everywhere" as "by default, nowhere". -- Steve From antoon.pardon at rece.vub.ac.be Mon Jun 20 07:14:43 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 20 Jun 2016 13:14:43 +0200 Subject: the global keyword: In-Reply-To: References: <5766ADB1.6070907@rece.vub.ac.be> Message-ID: <5767D023.3000708@rece.vub.ac.be> Op 19-06-16 om 23:20 schreef BartC: > On 19/06/2016 15:35, Antoon Pardon wrote: >> Op 12-06-16 om 23:10 schreef BartC: >>> On 12/06/2016 20:25, Ned Batchelder wrote: >>>> Just as here there is no link between x >>>> and y: >>>> >>>> x = 12 >>>> y = x >>> >>> (And that's a good illustration of why 'y' isn't a name reference to >>> 'x', referring to the "...ducks limp" thread. But best not to rake >>> it up again...) >>> >> I find this rather inaccurate reference to what your opposition is >> supposed to have states together with the remark best not to rake >> this up again, rather disingenuous >> > > > Sorry, haven't been able to parse that. > > What is inaccurate? What am I supposed to be opposed to? And why is it > disingenuous? The original thread is still open to posts AFAIK if > someone wants to discuss it further. You are denying a position above. So you oppose the position being denied. However noone defended the position you denied. So denying a position here and thus suggesting there are people who defend that position is inaccurate. And it is disingenuous to inaccurately mention others people's position and then to try to screen yourself off from reactions by ending with: "Best not to rake it up again." -- Antoon Pardon From steve at pearwood.info Mon Jun 20 08:03:18 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 20 Jun 2016 22:03:18 +1000 Subject: the global keyword: References: <5766ADB1.6070907@rece.vub.ac.be> Message-ID: <5767db88$0$1585$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jun 2016 08:21 pm, BartC wrote: > On 19/06/2016 18:16, Joel Goldstick wrote: > >> People who understand global variables generally avoid using them at >> all costs. > > Then perhaps they don't understand that in Python, top-level functions, > classes and imports are also globals. But not global *variables*. They are generally used as per-module global *constants*, or at least near-constants. -- Steven From steve at pearwood.info Mon Jun 20 08:15:48 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 20 Jun 2016 22:15:48 +1000 Subject: the global keyword: References: <5766ADB1.6070907@rece.vub.ac.be> <5767D023.3000708@rece.vub.ac.be> Message-ID: <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jun 2016 09:14 pm, Antoon Pardon wrote: > Op 19-06-16 om 23:20 schreef BartC: >> On 19/06/2016 15:35, Antoon Pardon wrote: >>> Op 12-06-16 om 23:10 schreef BartC: >>>> On 12/06/2016 20:25, Ned Batchelder wrote: >>>>> Just as here there is no link between x >>>>> and y: >>>>> >>>>> x = 12 >>>>> y = x >>>> >>>> (And that's a good illustration of why 'y' isn't a name reference to >>>> 'x', referring to the "...ducks limp" thread. But best not to rake >>>> it up again...) >>>> >>> I find this rather inaccurate reference to what your opposition is >>> supposed to have states together with the remark best not to rake >>> this up again, rather disingenuous >>> >> >> >> Sorry, haven't been able to parse that. >> >> What is inaccurate? What am I supposed to be opposed to? And why is it >> disingenuous? The original thread is still open to posts AFAIK if >> someone wants to discuss it further. > > You are denying a position above. So you oppose the position being denied. > However noone defended the position you denied. I'm sorry Antoon, Bart only paid for the ten minute argument. Bart didn't say anyone had defended it. He made an observation: "that's a good illustration of why 'y' isn't a name reference to 'x'" which is factually correct. And this does refer to the "ducks limp" thread. Nothing he said was wrong or objectionable, and he didn't imply that anyone was taking the opposite position. > So denying a position here > and thus suggesting there are people who defend that position is > inaccurate. There's no "and thus" here. Sometimes people make observations and share them with the group. You'll notice that I'm taking a position here, but I'm not accusing you or anyone else of taking the contrary position (namely "nobody ever makes observations and shares them with the group"). > And it is disingenuous to inaccurately mention others people's position Bart did not mention anyone's position, accurately or inaccurately. > and then to try to screen yourself off from reactions by ending with: > "Best not to rake it up again." -- Steven From antoon.pardon at rece.vub.ac.be Mon Jun 20 09:04:47 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 20 Jun 2016 15:04:47 +0200 Subject: the global keyword: In-Reply-To: <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <5766ADB1.6070907@rece.vub.ac.be> <5767D023.3000708@rece.vub.ac.be> <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5767E9EF.70709@rece.vub.ac.be> Op 20-06-16 om 14:15 schreef Steven D'Aprano: > On Mon, 20 Jun 2016 09:14 pm, Antoon Pardon wrote: > >> Op 19-06-16 om 23:20 schreef BartC: >>> On 19/06/2016 15:35, Antoon Pardon wrote: >>>> Op 12-06-16 om 23:10 schreef BartC: >>>>> On 12/06/2016 20:25, Ned Batchelder wrote: >>>>>> Just as here there is no link between x >>>>>> and y: >>>>>> >>>>>> x = 12 >>>>>> y = x >>>>> (And that's a good illustration of why 'y' isn't a name reference to >>>>> 'x', referring to the "...ducks limp" thread. But best not to rake >>>>> it up again...) >>>>> >>>> I find this rather inaccurate reference to what your opposition is >>>> supposed to have states together with the remark best not to rake >>>> this up again, rather disingenuous >>>> >>> >>> Sorry, haven't been able to parse that. >>> >>> What is inaccurate? What am I supposed to be opposed to? And why is it >>> disingenuous? The original thread is still open to posts AFAIK if >>> someone wants to discuss it further. >> You are denying a position above. So you oppose the position being denied. >> However noone defended the position you denied. > I'm sorry Antoon, Bart only paid for the ten minute argument. > > Bart didn't say anyone had defended it. He made an observation: > > "that's a good illustration of why 'y' isn't a name reference to 'x'" > > which is factually correct. And this does refer to the "ducks limp" thread. > Nothing he said was wrong or objectionable, and he didn't imply that anyone > was taking the opposite position. If you mean the literal logical implication you are correct. But there is of course also the implicature. And his ending with "Best not to rake this up again" is a strong indication he was aware of the implicature. Because why is there a need to mention that one thing is a good illustration of something not being the case, unless people have been stating the opposite? Why should he be raking things up, if he is not stating something that is opposed by others? -- Antoon. From random832 at fastmail.com Mon Jun 20 09:26:49 2016 From: random832 at fastmail.com (Random832) Date: Mon, 20 Jun 2016 09:26:49 -0400 Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <1466429209.2588253.642901457.799A84BF@webmail.messagingengine.com> On Sun, Jun 19, 2016, at 18:44, Gregory Ewing wrote: > Lawrence D?Oliveiro wrote: > > But not vi/vim. It only lets you place your cursor *on* a character, not > > *in-between* characters. > > That's because the terminals it was designed to work on > didn't have any way of displaying a cursor between two > characters. Emacs is the same (except it doesn't go as > far as having two different insertion modes -- you just > think of the insertion point as being to the left of > the character that the cursor is on). So, basically, Emacs is *not* the same. The point is that in vim you can't position the normal-mode cursor in such a way that inserted characters are inserted at the end of the line. How the cursor is displayed has nothing to do with it. And, insertion is to the left of the character that the cursor is on in vim, too. That's why the "a" command moves the cursor. > I would say that's about the *least* weird thing about > vi[m] though... :-( From random832 at fastmail.com Mon Jun 20 09:29:17 2016 From: random832 at fastmail.com (Random832) Date: Mon, 20 Jun 2016 09:29:17 -0400 Subject: the global keyword: In-Reply-To: <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <5766ADB1.6070907@rece.vub.ac.be> <5767D023.3000708@rece.vub.ac.be> <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1466429357.2588517.642905033.340E5404@webmail.messagingengine.com> On Mon, Jun 20, 2016, at 08:15, Steven D'Aprano wrote: > Bart didn't say anyone had defended it. He made an observation: > > "that's a good illustration of why 'y' isn't a name reference to 'x'" > > which is factually correct. And this does refer to the "ducks limp" > thread. Except it doesn't. Because no-one on that thread made the claim that it is. There's absolutely nothing in the thread (except maybe earlier instances of him and you misrepresenting others' claims) about 'y' being a name reference to 'x', so there's nothing in that thread for it to reasonably refer to. > Nothing he said was wrong or objectionable, and he didn't imply that > anyone was taking the opposite position. Nonsense. From auriocus at gmx.de Mon Jun 20 09:36:46 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 20 Jun 2016 15:36:46 +0200 Subject: best text editor for programming Python on a Mac In-Reply-To: References: <1466429209.2588253.642901457.799A84BF@webmail.messagingengine.com> Message-ID: Am 20.06.16 um 15:26 schrieb Random832: > The point is that in vim you > can't position the normal-mode cursor in such a way that inserted > characters are inserted at the end of the line. But you can press i at the end of the line, then arrow-right, which positions the cursor over the empty space after the line, and type. Try it. In vim this works, because vim understands cursor keys. In original vi not (there were no cursor keys on the old terminals). Usually, when editing in vim, you don't leave the insert mode because you can use the "special" keys as well as mouse actions to perform usual editing tasks. Leaving insert mode is only necessary to run a command. Christian From mal at europython.eu Mon Jun 20 09:38:13 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 20 Jun 2016 15:38:13 +0200 Subject: EuroPython 2016: Conference Dinner and Party - Tickets available Message-ID: <5767F1C5.4090604@europython.eu> We all know that good food, drinks and music are essential for a perfect EuroPython conference and so we?ve arranged a nice dinner with local food and a party for Tuesday evening (July 19th). *** EuroPython Conference Dinner and Party *** https://ep2016.europython.eu/en/events/social-event/ If you want to join the fun, please go to the social event page, and then proceed to the registration form (the same you use to buy conference tickets). There?s a new entry available now called ?Pyntxos Social Event? which you can order using the form. Leave the conference tickets fields blank if you only want to purchase social event tickets. *** Buy Social Event Tickets *** https://ep2016.europython.eu/p3/cart/ We have 550 tickets available for the conference dinner and party, so please book early. The tickets are valid for one person. Please see the social events page for details of what is included in the ticket price. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/744884976940945408 Thanks. From rustompmody at gmail.com Mon Jun 20 09:48:30 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 20 Jun 2016 06:48:30 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: <1466429209.2588253.642901457.799A84BF@webmail.messagingengine.com> Message-ID: <5519d657-2405-4236-bfec-e5fbeb2b54f1@googlegroups.com> On Monday, June 20, 2016 at 7:06:57 PM UTC+5:30, Christian Gollwitzer wrote: > Am 20.06.16 um 15:26 schrieb Random832: > > The point is that in vim you > > can't position the normal-mode cursor in such a way that inserted > > characters are inserted at the end of the line. > > But you can press i at the end of the line, then arrow-right, which > positions the cursor over the empty space after the line, and type. Try > it. In vim this works, because vim understands cursor keys. In original > vi not (there were no cursor keys on the old terminals). Usually, when > editing in vim, you don't leave the insert mode because you can use the > "special" keys as well as mouse actions to perform usual editing tasks. > Leaving insert mode is only necessary to run a command. True and false (if one allows for vi = vim) In the default vi that comes with ubuntu (vi-tiny??) giving a arrow in insert mode enters all kinds of (control?) garbage. In (full) vim I guess its true From rustompmody at gmail.com Mon Jun 20 10:00:01 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 20 Jun 2016 07:00:01 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <1466402659.590756.642556081.412E8163@webmail.messagingengine.com> Message-ID: <2575d623-e9e8-430f-b243-c9e8c1f736f3@googlegroups.com> On Monday, June 20, 2016 at 11:34:36 AM UTC+5:30, Random832 wrote: > On Mon, Jun 20, 2016, at 01:03, Rustom Mody wrote: > > > Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? > > > > Are these 'shortcuts' parameterizable? > > They originate from RFC 1345, with the extension that they can be > reversed if the reverse doesn't itself exist as a RFC 1345 combination. Thanks! Useful reference even though old From auriocus at gmx.de Mon Jun 20 10:03:31 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 20 Jun 2016 16:03:31 +0200 Subject: best text editor for programming Python on a Mac In-Reply-To: <5519d657-2405-4236-bfec-e5fbeb2b54f1@googlegroups.com> References: <1466429209.2588253.642901457.799A84BF@webmail.messagingengine.com> <5519d657-2405-4236-bfec-e5fbeb2b54f1@googlegroups.com> Message-ID: Am 20.06.16 um 15:48 schrieb Rustom Mody: > On Monday, June 20, 2016 at 7:06:57 PM UTC+5:30, Christian Gollwitzer wrote: >> Am 20.06.16 um 15:26 schrieb Random832: >>> The point is that in vim you >>> can't position the normal-mode cursor in such a way that inserted >>> characters are inserted at the end of the line. >> >> But you can press i at the end of the line, then arrow-right, which >> positions the cursor over the empty space after the line, and type. Try >> it. In vim this works, because vim understands cursor keys. In original >> vi not (there were no cursor keys on the old terminals). Usually, when >> editing in vim, you don't leave the insert mode because you can use the >> "special" keys as well as mouse actions to perform usual editing tasks. >> Leaving insert mode is only necessary to run a command. > > True and false (if one allows for vi = vim) He wrote "in vim", which I assumed was on purpose. > In the default vi that comes with ubuntu (vi-tiny??) > giving a arrow in insert mode enters all kinds of (control?) garbage. Yes I know this crappy behaviour which has no place on a current desktop. Maybe it is just a setting? Try ":set nocompatible" which should turn on standard edit keys, if this is really a vim variant and not something else like elvis. > In (full) vim I guess its true Definitely. I wouldn't use an editor which requires me to learn special commands that are available as standard keys on a modern keyboard. Christian From grant.b.edwards at gmail.com Mon Jun 20 10:23:17 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 20 Jun 2016 14:23:17 +0000 (UTC) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-20, Phil Boutros wrote: > Steven D'Aprano wrote: >> >> Quote: >> >> "Why do we have to write x!=y then argue about the status of x<>y when we >> can simply write x?y?" >> >> "Simply"? >> >> This is how I write x?y from scratch: > > > To wrap this back full circle, here's how it's done on vim: > > Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? On any non-broken X11 system it's: = / I generally configure my system so that the right-hand "windows" key is . If I used it a lot, I'd probably configure the left hand one to be the same. > It's still probably a horrible idea to have it in a programming > language, though, unless the original behaviour still also works. Definitely. And we should allow overbar for logical inversion. I never did figure out the X11 compose sequence for the XOR symbol... -- Grant Edwards grant.b.edwards Yow! Somewhere in DOWNTOWN at BURBANK a prostitute is gmail.com OVERCOOKING a LAMB CHOP!! From steve at pearwood.info Mon Jun 20 10:53:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 21 Jun 2016 00:53:16 +1000 Subject: the global keyword: References: <5766ADB1.6070907@rece.vub.ac.be> <5767D023.3000708@rece.vub.ac.be> <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> <1466429357.2588517.642905033.340E5404@webmail.messagingengine.com> Message-ID: <5768035d$0$1622$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jun 2016 11:29 pm, Random832 wrote: > On Mon, Jun 20, 2016, at 08:15, Steven D'Aprano wrote: >> Bart didn't say anyone had defended it. He made an observation: >> >> "that's a good illustration of why 'y' isn't a name reference to 'x'" >> >> which is factually correct. And this does refer to the "ducks limp" >> thread. > > Except it doesn't. Because no-one on that thread made the claim that it > is. There's absolutely nothing in the thread (except maybe earlier > instances of him and you misrepresenting others' claims) about 'y' being > a name reference to 'x', so there's nothing in that thread for it to > reasonably refer to. The thread is a discussion about name binding and references. And what do you know, the hypothetical "name y is a reference to name x" is, amazingly, about name binding and references! Hence the connection between the two. You know, there's not actually a rule or law that says you have to automatically take the contrary position to everything I say. -- Steven From steve at pearwood.info Mon Jun 20 11:00:14 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 21 Jun 2016 01:00:14 +1000 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576804ff$0$1596$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Jun 2016 12:23 am, Grant Edwards wrote: > On 2016-06-20, Phil Boutros wrote: [...] >> Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? > > On any non-broken X11 system it's: = / Nope, doesn't work for me. I guess I've got a "broken" X11 system. Oh, I did learn one thing, thanks to Lawrence's earlier link: the compose key behaves as a dead-key, not a modifier. -- Steven From rustompmody at gmail.com Mon Jun 20 11:12:01 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 20 Jun 2016 08:12:01 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <576804ff$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <576804ff$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <39dcf5bf-6e01-4af4-b738-a9859b9edaf3@googlegroups.com> On Monday, June 20, 2016 at 8:30:25 PM UTC+5:30, Steven D'Aprano wrote: > On Tue, 21 Jun 2016 12:23 am, Grant Edwards wrote: > > > On 2016-06-20, Phil Boutros wrote: > [...] > >> Ctrl-K, =, ! (last two steps interchangeable). Done. Result: ? > > > > On any non-broken X11 system it's: = / > > Nope, doesn't work for me. I guess I've got a "broken" X11 system. > > Oh, I did learn one thing, thanks to Lawrence's earlier link: the compose > key behaves as a dead-key, not a modifier. > You need to say something like $ setxkbmap -option compose:menu then the windows menu key becomes the compose key Or $ setxkbmap -option compose:ralt then its the right-alt You can check whats currently the state of xkb with $ setxkbmap -print And you can clean up with a bare $ setkkb -option else these options 'pile-up' as a -print would show From ian.g.kelly at gmail.com Mon Jun 20 12:01:53 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Jun 2016 10:01:53 -0600 Subject: value of pi and 22/7 In-Reply-To: <57678baa$0$1603$c3e8da3$5496439d@news.astraweb.com> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <57678baa$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jun 20, 2016 at 12:22 AM, Steven D'Aprano wrote: > There's a difference though. Nobody has tried to legislate the value of pi to > match your casual reference to "about 1900 square feet", but there's been at > least one serious attempt to legislate the value of pi to match the implied > value given by the Bible. If you're referring the Indiana Pi Bill of 1897, it was actually a poorly conceived attempt to publish an amateur mathematician's claim of a way to square the circle. It had nothing to do with biblical interpretation and would have implied a value for pi of 3.2, not 3. https://en.wikipedia.org/wiki/Indiana_Pi_Bill I'm not aware of any other such legislative attempts. Snopes records one that allegedly occurred in Indiana but dismisses the claim as false. From ian.g.kelly at gmail.com Mon Jun 20 12:09:06 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Jun 2016 10:09:06 -0600 Subject: value of pi and 22/7 In-Reply-To: References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <57678baa$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jun 20, 2016 at 10:01 AM, Ian Kelly wrote: > I'm not aware of any other such legislative attempts. Snopes records > one that allegedly occurred in Indiana but dismisses the claim as > false. s/Indiana/Alabama From mnganele at gmail.com Mon Jun 20 13:00:52 2016 From: mnganele at gmail.com (Marie Nganele) Date: Mon, 20 Jun 2016 10:00:52 -0700 (PDT) Subject: sublime text interpreter not showing output Message-ID: <183b5e6f-2862-47e1-8b25-25c7c67024ed@googlegroups.com> hi. I'm new to python and trying to work with simple letter strings and the print command in my first python lessons. However, in my sublime text editor nothing but the time it takes to complete the build shows up, and sometimes not even that updates. How can I configure sublime text so that it shows me the output and execution time in my interpreter? From grant.b.edwards at gmail.com Mon Jun 20 13:53:11 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 20 Jun 2016 17:53:11 +0000 (UTC) Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: On 2016-06-19, Gregory Ewing wrote: > Lawrence D?Oliveiro wrote: > >> I feel a new phrase coming on: ?good enough for Bible work?! > > I understand there's a passage in the Bible somewhere that > uses a 1 significant digit approximation to pi... A lot of the time, 3 is a good-enough approximation of ? (it's less than 5% off). Yesterday I needed to know if the globe on a light fixture was 5", 6", or 7" diameter. Measure the circumference with a tape, divide by 3, and Bob's your uncle. Of course if you have to do that very often, you just by a diameter tape. :) -- Grant Edwards grant.b.edwards Yow! I think I am an at overnight sensation right gmail.com now!! From grant.b.edwards at gmail.com Mon Jun 20 14:06:03 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 20 Jun 2016 18:06:03 +0000 (UTC) Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <57674fd8$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-20, Steven D'Aprano wrote: > One of the most underrated yet critical functions of government is > to standardise weights and measures, and that function evolved very > slowly over time. I doubt that the Egyptian Pharoahs cared about it, Oh, I bet they did. How you measure things affects how much tax you collect -- and the people at the top of every government pay a lot of attention to that. The state doesn't check all those gas pumps against a volumetric flask every year to protect Joe Carowner. I've designed various sorts of measurement and instrumentation, and when a device is used for doing a measurement that affects how much tax gets paid, things get deadly serious. > although their scribes probably did, a bit. -- Grant Edwards grant.b.edwards Yow! Vote for ME -- I'm at well-tapered, half-cocked, gmail.com ill-conceived and TAX-DEFERRED! From marko at pacujo.net Mon Jun 20 14:52:49 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Jun 2016 21:52:49 +0300 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> Message-ID: <878txzvgji.fsf@elektro.pacujo.net> Gregory Ewing : > Lawrence D?Oliveiro wrote: > >> I feel a new phrase coming on: ?good enough for Bible work?! > > I understand there's a passage in the Bible somewhere that > uses a 1 significant digit approximation to pi... Yes: And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and a line of thirty cubits did compass it round about. [1 Kings 7:23] This and other entertaining stories in: Marko From best_lay at yahoo.com Mon Jun 20 18:24:29 2016 From: best_lay at yahoo.com (Wildman) Date: Mon, 20 Jun 2016 17:24:29 -0500 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <593039af-b15b-4186-9784-a8a4e7da2062@googlegroups.com> <87eg7suxgk.fsf@elektro.pacujo.net> <8b99700a-6492-4982-a6a6-987e1761a5db@googlegroups.com> Message-ID: <96idnWw48cOA8PXKnZ2dnUU7-N2dnZ2d@giganews.com> On Mon, 20 Jun 2016 01:01:21 -0700, Lawrence D?Oliveiro wrote: > On Monday, June 20, 2016 at 7:32:54 PM UTC+12, Marko Rauhamaa wrote: > >> Width/height ratio of the pyramid of Cheops was so close to ?/2 that UFO >> enthusiasts were convinced alien technology was used in the construction >> of the pyramids. > > They were also able to get the bases of the pyramids horizontal > to within about a centimetre. Amazing achievement, but entirely > achievable with bronze-age technology. I am not convinced on any of the theories on how the pyramids were built, or any other of the monolithic sites. But, I am in awe as to the fact that it was actually done. Just look at the numbers for the Great Pyramid. It is believed that it took 23 years for construction. It is estimated that there are somewhere between 2.0 to 2.4 million stones. I will use 2.0 million for the math... 23 * 365.25 * 24 * 60 / 2000000 = 6.04854 As you can see, a stone had to be cut, transported and put in place every 6 minutes 24 hours a day for 23 years. And if the stone count was actually 2.4 million, the time would be reduced to 5 minutes per stone. All I can say is wow! Another example is the fact that some ancient Central American cultures were able to lift and transport stones weighing up to 300 tons. We would have a very hard time doing that today with our modern machinery. I'm not trying to say that ET or $DIETY did it. I'm just point out the fact that something amazing was done. I keep an open mind to any possibility. Right now there is no actual proof to support any theory. -- 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 marko at pacujo.net Mon Jun 20 18:47:51 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 21 Jun 2016 01:47:51 +0300 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <593039af-b15b-4186-9784-a8a4e7da2062@googlegroups.com> <87eg7suxgk.fsf@elektro.pacujo.net> <8b99700a-6492-4982-a6a6-987e1761a5db@googlegroups.com> <96idnWw48cOA8PXKnZ2dnUU7-N2dnZ2d@giganews.com> Message-ID: <8737o7v5ns.fsf@elektro.pacujo.net> Wildman : > As you can see, a stone had to be cut, transported and put in place > every 6 minutes 24 hours a day for 23 years. And if the stone count > was actually 2.4 million, the time would be reduced to 5 minutes per > stone. All I can say is wow! It probably means mostly that the Nile produced enough grain to feed a lot more people than were needed to till the land. Feudal ownership produced public works and a working economy. Nowadays, very few people are needed to till the land, but so far the farmers have been content with the amenities and gadgets provided by the industry. It has somewhat similarly been shown how the slave trade of the 17th century was generated by maize, which was introduced to West Africa. The soil produced vastly more people, which the local warlords sold to European slave traders. Marko From harrison.chudleigh1 at education.nsw.gov.au Mon Jun 20 19:01:53 2016 From: harrison.chudleigh1 at education.nsw.gov.au (Harrison Chudleigh) Date: Tue, 21 Jun 2016 09:01:53 +1000 Subject: Re - bug in tokenize module Message-ID: Sorry. Only works with text files. But my point is still valid. ******************************************************************************* This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. From steve at pearwood.info Mon Jun 20 22:21:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 21 Jun 2016 12:21:19 +1000 Subject: Re - bug in tokenize module References: Message-ID: <5768a4a0$0$1619$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Jun 2016 09:01 am, Harrison Chudleigh wrote: > Sorry. Only works with text files. But my point is still valid. What point? Without context, how are we supposed to know what you're talking about? We're not mind-readers you know. -- Steven From arief at google.com Tue Jun 21 03:34:20 2016 From: arief at google.com (Ari Freund) Date: Tue, 21 Jun 2016 10:34:20 +0300 Subject: Proposal: named return values through dict initialization and unpacking Message-ID: I'd like to run this idea by the community to see if it's PEP worthy and hasn't been already rejected. Background Just as keyword arguments enhance code readability and diminish the risk of bugs, so too would named return values. Currently, we can write val1, val2, val3 = myfunc() but we must take care to order the variables correctly, i.e., in the same order as the corresponding values in myfunc's return statement. Getting it wrong may result in difficult-to-detect bugs. This problem would be alleviated if we could name the return values and disregard their order. My proposal consists of two parts. 1. Add a new form of assignment by dictionary unpacking. Suppose d is a dict whose keys are the strings 'var1', 'var2', 'var3'. Then the assignment var1, var2, var3 = **d would set the variables to the corresponding values. Order would not be important, so var3, var1, var2 = **d would have the same effect. Also, not all keys would need to participate; for example, var2 = **d would work just fine. It would be an error for the same name to appear more than once on the LHS of the assignment. It would be an error for a name on the LHS to not be a valid variable name or for there not to be a corresponding key in the dict. It would (possibly) be an error if the dict contained keys that are not strings (or are strings that cannot serve as variable names). 2. Extend the dict() form of dictionary initialization to allow an element to be a variable name, e.g., dict(var1, var2, var3, var4=33) would be equivalent to dict(var1=var1, var2=var2, var3=var3, var4=33) I believe each of the above is useful in its own right. Additionally, their combination yields reasonably streamlined named return value functionality, as in def RunShellCmd(cmd): exit_code, output = commands.getstatusoutput(cmd) # Here we need to get the order right. return dict(exit_code, output) output, exit_code = **RunShellCmd("ls .") # Here we don't care about order. From orgnut at yahoo.com Tue Jun 21 03:40:48 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 21 Jun 2016 00:40:48 -0700 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/19/2016 08:29 PM, Steven D'Aprano wrote: > On Mon, 20 Jun 2016 12:07 pm, Rustom Mody wrote: > [snip] > In theory most Linux apps support an X mechanism for inserting characters > that don't appear on the keyboard. Unfortunately, this gives no feedback > when you get it wrong, and discoverablity is terrible. It's taken me many > years to discover and learn the following: > > WIN o WIN o gives ? > WIN m WIN u gives ? > WIN s WIN s gives ? > WIN . . gives ? > > (WIN is the Windows key) > > Getting back to ? I tried: > > WIN = WIN / > WIN / WIN = > WIN < WIN > > WIN ! WIN = > > etc none of which do anything. > > Another example of missing tooling is the lack of a good keyboard > application. Back in the 1980s, Apple Macs had a desk accessory that didn't > just simulate the keyboard, but showed what characters were available. If > you held down the Option key, the on-screen keyboard would display the > characters each key would insert. This increased discoverability and made > it practical for Hypertalk to accept non-ASCII synonyms such as > > ? for <= > ? for >= > ? for <> > > Without better tooling and more discoverability, non-ASCII characters as > syntax are an anti-feature. > > > It sounds like you are almost, but not quite, describing the Linux Compose key. To get many of the 'special' characters, you first press the compose key and follow it with (usually) two characters. (That's ONE press of the compose key, not two like your first examples.) And yes, the unequal sign is =/ Here are some more examples (I'm not going to specify the key here, just assume these examples are prefixed with it): These are all pretty easy to remember. German umlauts a" o" u" give ? ? ? (or use uppercase) Spanish e?a (spelling?) and punctuations: n~ ?? !! --> ? ? ? French accents: e' e` e^ c, --> ? ? ? ? Money: c= l- y- c/ --> ? ? ? ? Math: =/ -: +- xx <= >= --> ? ? ? ? ? ? Superscripts: ^0 ^1 ^2 ^3 --> ? ? ? ? Simple fractions: 12 13 ... 78 --> ? ? ... ? Here's a cute one: CCCP --> ? (hammer & sickle) And like your first examples: oo mu ss --> ? ? ? Many MANY more obscure codes as well (have to look them up, or make a copy of this info.) Admittedly not much use in programming, but can be useful for other general text. Now, setting the compose key... Easy (but obscure) in Mint Linux (and I think Ubuntu is the same. I don't know about other distros.): From the menu, select Preferences->Keyboard->Layouts->Options->Position of Compose Key This opens a list of checkboxes with about a dozen choices -- select whatever you want (I use the Menu key). -- -=- Larry -=- From ian.g.kelly at gmail.com Tue Jun 21 04:01:00 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Jun 2016 02:01:00 -0600 Subject: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool? In-Reply-To: <90fdccc7-ead5-4a31-99d2-f1ad37ba496e@googlegroups.com> References: <7c34b140-ac0d-4840-8c30-e967e83aae4a@googlegroups.com> <57626394$0$2780$c3e8da3$76491128@news.astraweb.com> <90fdccc7-ead5-4a31-99d2-f1ad37ba496e@googlegroups.com> Message-ID: On Thu, Jun 16, 2016 at 2:45 AM, meInvent bbird wrote: > the name in c# is not called concurrent list, it is called > blockingcollection > > dictionary called concurrent dictionary > > thread safe these kind of things > > https://msdn.microsoft.com/en-us/library/dd267312(v=vs.110).aspx > > https://msdn.microsoft.com/en-us/library/dd997369(v=vs.110).aspx > > https://msdn.microsoft.com/en-us/library/dd997305(v=vs.110).aspx It sounds to me like you're looking for the Queue class: https://docs.python.org/3/library/queue.html Or possibly you want its multiprocessing equivalent, since it's not clear to me which kind of concurrency you're interested in: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue Also, please don't top-post on this mailing list. Trimming quotations and interleaving your replies is the accepted posting style here. From antoon.pardon at rece.vub.ac.be Tue Jun 21 04:08:41 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 21 Jun 2016 10:08:41 +0200 Subject: the global keyword: In-Reply-To: <5768035d$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <5766ADB1.6070907@rece.vub.ac.be> <5767D023.3000708@rece.vub.ac.be> <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> <1466429357.2588517.642905033.340E5404@webmail.messagingengine.com> <5768035d$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5768F609.2020508@rece.vub.ac.be> Op 20-06-16 om 16:53 schreef Steven D'Aprano: > On Mon, 20 Jun 2016 11:29 pm, Random832 wrote: > >> On Mon, Jun 20, 2016, at 08:15, Steven D'Aprano wrote: >>> Bart didn't say anyone had defended it. He made an observation: >>> >>> "that's a good illustration of why 'y' isn't a name reference to 'x'" >>> >>> which is factually correct. And this does refer to the "ducks limp" >>> thread. >> Except it doesn't. Because no-one on that thread made the claim that it >> is. There's absolutely nothing in the thread (except maybe earlier >> instances of him and you misrepresenting others' claims) about 'y' being >> a name reference to 'x', so there's nothing in that thread for it to >> reasonably refer to. > The thread is a discussion about name binding and references. And what do > you know, the hypothetical "name y is a reference to name x" is, amazingly, > about name binding and references! Hence the connection between the two. But being about name bindings and reference doesn't imply it is about name references. > You know, there's not actually a rule or law that says you have to > automatically take the contrary position to everything I say. There is also not a rule of law that says you have to automatically introduce semantic games into the discussion when someone else might have a point. -- Antoon. From steve+comp.lang.python at pearwood.info Tue Jun 21 04:28:25 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 21 Jun 2016 18:28:25 +1000 Subject: Marking a subtest as an expected failure Message-ID: <5768faaa$0$2846$c3e8da3$76491128@news.astraweb.com> I'm using unittest and the subtest context manager to run some tests: def test_spam(self): for i in range(100): for j in range(100): with self.subtest(i=i, j=j): self.assertEqual(spam(i, j), 999) Now, it turns out that spam(i, j) == 999 for all i, j *except* one or two exceptional cases. E.g. let's say spam(97, 83) != 999. And further, this is not a bug to be fixed, but an expected failure. I can write: def test_spam(self): for i in range(100): for j in range(100): with self.subtest(i=i, j=j): if (i, j) != (97, 83): self.assertEqual(spam(i, j), 999) but is there a nicer way to mark a specific subtest as an expected failure? I don't want the entire test_spam test to be counted as an expected failure, just that one subtest. https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests -- Steve From marko at pacujo.net Tue Jun 21 04:35:44 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 21 Jun 2016 11:35:44 +0300 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87shw7gcrj.fsf@elektro.pacujo.net> Larry Hudson : > It sounds like you are almost, but not quite, describing the Linux > Compose key. I have used Linux since the 1990's but don't know anything about "the Linux Compose key." (On the other hand, I have always specified my preferred keyboard layout with .Xmodmap.) > These are all pretty easy to remember. > German umlauts a" o" u" give ? ? ? (or use uppercase) > Spanish e?a (spelling?) and punctuations: n~ ?? !! --> ? ? ? > French accents: e' e` e^ c, --> ? ? ? ? > Money: c= l- y- c/ --> ? ? ? ? > Math: =/ -: +- xx <= >= --> ? ? ? ? ? ? > Superscripts: ^0 ^1 ^2 ^3 --> ? ? ? ? > Simple fractions: 12 13 ... 78 --> ? ? ... ? > Here's a cute one: CCCP --> ? (hammer & sickle) > And like your first examples: oo mu ss --> ? ? ? Trouble is, nobody's going to guess or memorize any of that stuff. The Chinese face analogous typing issues. They must have come up with productive solutions since demonstrably they can type quite fast. Marko From steve+comp.lang.python at pearwood.info Tue Jun 21 04:38:16 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 21 Jun 2016 18:38:16 +1000 Subject: value of pi and 22/7 References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <57678baa$0$1603$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5768fcfa$0$2845$c3e8da3$76491128@news.astraweb.com> On Tuesday 21 June 2016 02:01, Ian Kelly wrote: > On Mon, Jun 20, 2016 at 12:22 AM, Steven D'Aprano > wrote: >> There's a difference though. Nobody has tried to legislate the value of pi >> to match your casual reference to "about 1900 square feet", but there's been >> at least one serious attempt to legislate the value of pi to match the >> implied value given by the Bible. > > If you're referring the Indiana Pi Bill of 1897, it was actually a > poorly conceived attempt to publish an amateur mathematician's claim > of a way to square the circle. It had nothing to do with biblical > interpretation and would have implied a value for pi of 3.2, not 3. > > https://en.wikipedia.org/wiki/Indiana_Pi_Bill Thanks for the link, that's interesting. -- Steve From bc at freeuk.com Tue Jun 21 06:41:04 2016 From: bc at freeuk.com (BartC) Date: Tue, 21 Jun 2016 11:41:04 +0100 Subject: the global keyword: In-Reply-To: References: <5766ADB1.6070907@rece.vub.ac.be> <5767D023.3000708@rece.vub.ac.be> <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> <1466429357.2588517.642905033.340E5404@webmail.messagingengine.com> <5768035d$0$1622$c3e8da3$5496439d@news.astraweb.com> <5768F609.2020508@rece.vub.ac.be> Message-ID: On 21/06/2016 09:08, Antoon Pardon wrote: > Op 20-06-16 om 16:53 schreef Steven D'Aprano: >> You know, there's not actually a rule or law that says you have to >> automatically take the contrary position to everything I say. > > There is also not a rule of law that says you have to automatically introduce > semantic games into the discussion when someone else might have a point. Glancing at the ducks limp thread again (starting 3-Jun-2016), it seems it was you trying to persuade me that (1) the name references I'd implemented (and which allowed me to do extra things that Python couldn't) weren't name references at all; (2) that Python really did have name references when you tried hard enough to emulate them. What sort of semantic games were those then? -- bartc From rustompmody at gmail.com Tue Jun 21 06:46:25 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Jun 2016 03:46:25 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <87shw7gcrj.fsf@elektro.pacujo.net> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> Message-ID: <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> On Tuesday, June 21, 2016 at 2:05:55 PM UTC+5:30, Marko Rauhamaa wrote: > Larry Hudson : > > It sounds like you are almost, but not quite, describing the Linux > > Compose key. > > I have used Linux since the 1990's but don't know anything about "the > Linux Compose key." It used to be a real (aka hardware) key: See pics https://en.wikipedia.org/wiki/Compose_key#Occurrence_on_keyboards > (On the other hand, I have always specified my preferred keyboard layout with .Xmodmap.) If this is being given as advice its bad advice xmodmap is obsolete use xkb https://wiki.archlinux.org/index.php/X_KeyBoard_extension#xmodmap [Does this make life easier?? Didnt say so :-) ] This particularly nasty bug: h ttps://bugs.launchpad.net/ubuntu/+source/linux/+bug/998310 I believe I witnessed when I tried to use xmodmap From antoon.pardon at rece.vub.ac.be Tue Jun 21 07:01:29 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 21 Jun 2016 13:01:29 +0200 Subject: the global keyword: In-Reply-To: References: <5766ADB1.6070907@rece.vub.ac.be> <5767D023.3000708@rece.vub.ac.be> <5767de77$0$1604$c3e8da3$5496439d@news.astraweb.com> <1466429357.2588517.642905033.340E5404@webmail.messagingengine.com> <5768035d$0$1622$c3e8da3$5496439d@news.astraweb.com> <5768F609.2020508@rece.vub.ac.be> Message-ID: <57691E89.6040708@rece.vub.ac.be> Op 21-06-16 om 12:41 schreef BartC: > On 21/06/2016 09:08, Antoon Pardon wrote: >> Op 20-06-16 om 16:53 schreef Steven D'Aprano: > >>> You know, there's not actually a rule or law that says you have to >>> automatically take the contrary position to everything I say. >> >> There is also not a rule of law that says you have to automatically >> introduce >> semantic games into the discussion when someone else might have a point. > > Glancing at the ducks limp thread again (starting 3-Jun-2016), it > seems it was you trying to persuade me that (1) the name references > I'd implemented (and which allowed me to do extra things that Python > couldn't) weren't name references at all; (2) that Python really did > have name references when you tried hard enough to emulate them. > > What sort of semantic games were those then? If you can't stop yourself from raking that thread up again. Do it in the thread itself. If you do, could you start with pointing out where I write about "name references". I don't recall having used that. -- Antoon Pardon. From pushpanth2000 at gmail.com Tue Jun 21 07:03:16 2016 From: pushpanth2000 at gmail.com (Pushpanth Gundepalli) Date: Tue, 21 Jun 2016 04:03:16 -0700 (PDT) Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. Message-ID: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. From tal at bridge-dev.com Tue Jun 21 08:10:37 2016 From: tal at bridge-dev.com (Tal Zion) Date: Tue, 21 Jun 2016 15:10:37 +0300 Subject: Request for opinions: A cross language development tool Message-ID: <57692EBD.1060606@bridge-dev.com> * Hey! I would like to know your opinions about a project a friend and I have been developing for about a year now, which we really think could empower Python. Today Python is mostly used on servers. Many people who want to develop an app will choose Python to write the backend and develop frontends in Java, Swift, Javascript, etc. We think Python is great, and we don't see why we shouldn't be able to write a native iOS, Android or web app entirely in Python. After all, these languages share the same concepts, more or less (classes, functions, exceptions, etc) and what really separates them is syntax. We're proposing a new approach: developers will code in their favorite language, such as Python (woot woot!), and be able to import Java, Swift and Javascript code from Python, and use that code as if it were written in Python. Python code will run on just about any platform, including the web. ** So how does this magic work? We developed a new compiler platform called Bridge. At the heart of Bridge is the Bridge Extensible Code Representation (BECR). Code in any language is parsed into an AST and is then translated to the BECR. The BECR supports common programming concepts (if, for, while, etc) and it can also be extended to support new concepts in order to ease the translation from the source language. Therefore, the translation from the source language?s AST to the BECR is easy as it**merely translates syntax. Then, Bridge translates the BECR to LLVM IR and from there the code can be compiled to x86, arm, asm.js or any other LLVM backend*. *After code has been translated to BECR, it doesn?t matter what the source language was, and the syntax barriers that stopped languages from working together disappear. This means that once more languages will be translated to the BECR, they will be able to work seamlessly together. ** Today, we have a basic demo showing an Android app written in Python displaying native Android buttons and labels inside a native scroll view. In this demo, Python code can import Java classes and inherit from them. Soon Bridge will be released as an open source project. We?d love to hear your opinions about this project. We?re really excited and we can?t wait to see Python being used in more and more places! ** Thanks, Tal** * From auriocus at gmx.de Tue Jun 21 08:39:41 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 21 Jun 2016 14:39:41 +0200 Subject: Request for opinions: A cross language development tool In-Reply-To: References: <57692EBD.1060606@bridge-dev.com> Message-ID: Am 21.06.16 um 14:10 schrieb Tal Zion: > develop frontends in Java, Swift, Javascript, etc. > > So how does this magic work? We developed a new compiler platform called > Bridge. At the heart of Bridge is the Bridge Extensible Code > Representation (BECR). Code in any language is parsed into an AST and is > then translated to the BECR. [.....] > easy as it**merely translates syntax. Then, Bridge translates the BECR > to LLVM IR and from there the code can be compiled to x86, arm, asm.js > or any other LLVM backend*. So you have repeated .NET, or Parrot, or the JVM. What is new in your system that sets it apart from these? > Soon Bridge will be released as an open source project. We?d love to > hear your opinions about this project. We?re really excited and we can?t > wait to see Python being used in more and more places! Make sure you can do better than those: http://ironpython.net/ (Python on .NET) http://parrot.org/ (Python on the Perl-VM) http://www.jython.org/ (Python on the JVM) All of those projects promise a seamless integration of several languages in a single VM. ALl of them have failed in the sense that the languages have not converged onto that platform. Christian From greg.ewing at canterbury.ac.nz Tue Jun 21 08:52:40 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 22 Jun 2016 00:52:40 +1200 Subject: value of pi and 22/7 In-Reply-To: <878txzvgji.fsf@elektro.pacujo.net> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <878txzvgji.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > And he made a molten sea, ten cubits from the one brim to the other: > it was round all about, and his height was five cubits: and a line of > thirty cubits did compass it round about. [1 Kings 7:23] I think I know how that came about. It was actually filled with molten neutronium, and the gravitational field was distorting space enough to give a local circumference/diameter ratio of 3. -- Greg From marko at pacujo.net Tue Jun 21 09:08:07 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 21 Jun 2016 16:08:07 +0300 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> Message-ID: <87mvmeheq0.fsf@elektro.pacujo.net> Rustom Mody : > On Tuesday, June 21, 2016 at 2:05:55 PM UTC+5:30, Marko Rauhamaa wrote: >> (On the other hand, I have always specified my preferred keyboard >> layout with .Xmodmap.) > > If this is being given as advice I never gave it as advice. > its bad advice xmodmap is obsolete use xkb A coworker of mine went through the trouble of doing the xmodmap equivalent with setxkbmap. Thought of interviewing him about it one day. How-to's are really hard to come by: -- no good -- no good -- interesting but assumes root access -- no good etc etc > This particularly nasty bug: > https://bugs.launchpad.net/ubuntu/+source/linux/+bug/998310 I believe > I witnessed when I tried to use xmodmap I do run into that when I place my laptop on the docker. I know to expect it, wait for ten or so seconds, and I'm on my way. I'm guessing it has to do with the X server sending the keyboard map to every X window on the display. So Rustom, how do *you* produce, say, Hebrew or Spanish text, or your favorite math symbols? Marko From rustompmody at gmail.com Tue Jun 21 09:56:45 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Jun 2016 06:56:45 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <87mvmeheq0.fsf@elektro.pacujo.net> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> Message-ID: <29bbda44-4e04-49c1-bb32-1674dab5883e@googlegroups.com> On Tuesday, June 21, 2016 at 6:38:19 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > > On Tuesday, June 21, 2016 at 2:05:55 PM UTC+5:30, Marko Rauhamaa wrote: > >> (On the other hand, I have always specified my preferred keyboard > >> layout with .Xmodmap.) > > > > If this is being given as advice > > I never gave it as advice. > > > its bad advice xmodmap is obsolete use xkb > > A coworker of mine went through the trouble of doing the xmodmap > equivalent with setxkbmap. Thought of interviewing him about it one day. > > How-to's are really hard to come by: > > n_Xorg> -- no good > > -- no good > > d-layouts-xkb.html> -- interesting but assumes root access > > -- no > good > > etc etc > > > This particularly nasty bug: > > https://bugs.launchpad.net/ubuntu/+source/linux/+bug/998310 I believe > > I witnessed when I tried to use xmodmap > > I do run into that when I place my laptop on the docker. I know to > expect it, wait for ten or so seconds, and I'm on my way. I'm guessing > it has to do with the X server sending the keyboard map to every X > window on the display. > > So Rustom, how do *you* produce, say, Hebrew or Spanish text, or your > favorite math symbols? I wish I could say I have a good answer -- ATM dont However some ?-assed ones: Emacs: set-input-method (C-x RET C-\) greek And then typing abcdefghijklmnopqrstuvwxyz gives ????????????????;????????? [yeah that ; on q is curious] Spanish?? No idea But there seems to be a spanish input method that has these ????? Ive typed Hindi/Marathi/Tamil/Sanskrit/Gujarati and helped others with Bengali using devanagari-itrans/gujarati-itrans/tamil-itrans/bengali-itrans input methods. There are also the corresponding -inscript methods for those that type these fluently -- I am not one of those. I have some 15-20 lines of elisp that makes these itrans uses easier (for me) Math: So far Ive used tex input method -- Not satisfactory Search-n-cut-paste from google is better! My favorite goto for these are Xah Lee's pages: Starts here: http://xahlee.info/comp/unicode_index.html Some neat xah pages: http://xahlee.info/comp/unicode_matching_brackets.html http://xahlee.info/comp/unicode_arrows.html http://xahlee.info/comp/unicode_math_operators.html Some of this is replicatable at setxkbmap level [Note: these commands are dangerous as you can have a borked X system. Of course temporarily One safety catch is to keep setxkbmap -option in the bash history So (assuming up-arrow still works) goofups are correctable ] eg Doing $ setxkbmap -layout "us,apl(sax)" -option "grp:switch" gives an APL keyboard on shift-rAlt chord So abcdefghijklmnop chorded gives with RtAlt ?????_?????|??*???~??????? Along with RAlt-Shift ????????????????????????? I guess expert APLers may find this neat -- I am not one! So I use this emacs-mode https://github.com/lokedhs/gnu-apl-mode when using APL (mostly teaching) Then there is compose For this Ive a compose key set [With laptops and ubuntu-unity ths can get hard 1. Unity appropriates too many keys 2. Laptops have key shortage -- Ive just changed to CAPSLOCK to try out] Then install uim Then install https://github.com/rrthomas/pointless-xcompose The whole point of that is to edit that to get it to have those chars that one wants accessible and not others... Ive not got round to that! From tal at bridge-dev.com Tue Jun 21 10:06:04 2016 From: tal at bridge-dev.com (Tal Zion) Date: Tue, 21 Jun 2016 17:06:04 +0300 Subject: Request for opinions: A cross language development tool In-Reply-To: References: <57692EBD.1060606@bridge-dev.com> Message-ID: <576949CC.2070708@bridge-dev.com> On 06/21/2016 03:39 PM, Christian Gollwitzer wrote: > Am 21.06.16 um 14:10 schrieb Tal Zion: >> develop frontends in Java, Swift, Javascript, etc. > > >> So how does this magic work? We developed a new compiler platform called >> Bridge. At the heart of Bridge is the Bridge Extensible Code >> Representation (BECR). Code in any language is parsed into an AST and is >> then translated to the BECR. [.....] >> easy as it**merely translates syntax. Then, Bridge translates the BECR >> to LLVM IR and from there the code can be compiled to x86, arm, asm.js >> or any other LLVM backend*. > > So you have repeated .NET, or Parrot, or the JVM. What is new in your > system that sets it apart from these? > >> Soon Bridge will be released as an open source project. We?d love to >> hear your opinions about this project. We?re really excited and we can?t >> wait to see Python being used in more and more places! > > Make sure you can do better than those: > > http://ironpython.net/ (Python on .NET) > http://parrot.org/ (Python on the Perl-VM) > http://www.jython.org/ (Python on the JVM) > > All of those projects promise a seamless integration of several > languages in a single VM. ALl of them have failed in the sense that > the languages have not converged onto that platform. > > Christian Hi Christian, Thank you for your opinion, it is much appreciated. There are similarities but there are also a few important implementation differences: * It is easier to add languages to Bridge than it is to any of the above platforms: In order to make Python run on those platforms, those projects needed to write a compiler from Python to those platforms' respective intermediate languages. That is a very hard task. In Bridge, we provide the BECR, which makes it easy to re-use concepts implemented in other languages. For example, after we are done adding enough concepts to the BECR to compile 100% of Python's features, adding Ruby will be relatively easy as there are many similar concepts between the two languages. * Bridge enables Python code to interact with more languages through our external interfaces: Bridge code can interact with libraries not compiled to Bridge. So Python code will be able to call Swift, Objective-C, Java, and C code, to name a few, even if they weren't compiled to Bridge. * Bridge integrates with CPython in order to provide the same experience developers are used to: There are many Python modules written in C which are not usable in the above platforms. In Bridge you can use any CPython module. So when you are creating a Python list in Bridge, you are actually using CPython's list implementation. * Bridge makes Python faster: Python code compiled through Bridge is compiled to native code. Because we are leveraging LLVM's many optimizations, Python code will run faster than ever. * Bridge is more hackable: Using plugins, Bridge is much more accessible to community participation. Most importantly, Bridge will enable Python code to run on many new platforms (iOS, Android, web browsers..), while none of the above platforms provide this ability. We aren't looking to compete with CPython, but rather to complement it. Tal From daiyueweng at gmail.com Tue Jun 21 10:10:33 2016 From: daiyueweng at gmail.com (Daiyue Weng) Date: Tue, 21 Jun 2016 15:10:33 +0100 Subject: Cassandra multiprocessing can't pickle _thread.lock objects Message-ID: I tried to use Cassandra and multiprocessing to insert rows (dummy data) concurrently based on the examples in http://www.datastax.com/dev/blog/datastax-python-driver-multiprocessing-example-for-improved-bulk-data-throughput This is my code class QueryManager(object): concurrency = 100 # chosen to match the default in execute_concurrent_with_args def __init__(self, session, process_count=None): self.pool = Pool(processes=process_count, initializer=self._setup, initargs=(session,)) @classmethoddef _setup(cls, session): cls.session = session cls.prepared = cls.session.prepare(""" INSERT INTO test_table (key1, key2, key3, key4, key5) VALUES (?, ?, ?, ?, ?) """) def close_pool(self): self.pool.close() self.pool.join() def get_results(self, params): results = self.pool.map(_multiprocess_write, (params[n:n+self.concurrency] for n in range(0, len(params), self.concurrency))) return list(itertools.chain(*results)) @classmethoddef _results_from_concurrent(cls, params): return [results[1] for results in execute_concurrent_with_args(cls.session, cls.prepared, params)] def _multiprocess_write(params): return QueryManager._results_from_concurrent(params) if __name__ == '__main__': processes = 2 # connect cluster cluster = Cluster(contact_points=['127.0.0.1'], port=9042) session = cluster.connect() # database name is a concatenation of client_id and system_id keyspace_name = 'unit_test_0' # drop keyspace if it already exists in a cluster try: session.execute("DROP KEYSPACE IF EXISTS " + keyspace_name) except: pass create_keyspace_query = "CREATE KEYSPACE " + keyspace_name \ + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};" session.execute(create_keyspace_query) # use a session's keyspace session.set_keyspace(keyspace_name) # drop table if it already exists in the keyspace try: session.execute("DROP TABLE IF EXISTS " + "test_table") except: pass # create a table for invoices in the keyspace create_test_table = "CREATE TABLE test_table(" keys = "key1 text,\n" \ "key2 text,\n" \ "key3 text,\n" \ "key4 text,\n" \ "key5 text,\n" create_invoice_table_query += keys create_invoice_table_query += "PRIMARY KEY (key1))" session.execute(create_test_table) qm = QueryManager(session, processes) params = list() for row in range(100000): key = 'test' + str(row) params.append([key, 'test', 'test', 'test', 'test']) start = time.time() rows = qm.get_results(params) delta = time.time() - start log.info(fm('Cassandra inserts 100k dummy rows for ', delta, ' secs')) when I executed the code, I got the following error TypeError: can't pickle _thread.lock objects which pointed at self.pool = Pool(processes=process_count, initializer=self._setup, initargs=(session,)) I am wondering how to resolve the issue. cheers From rustompmody at gmail.com Tue Jun 21 10:11:27 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Jun 2016 07:11:27 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <29bbda44-4e04-49c1-bb32-1674dab5883e@googlegroups.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <29bbda44-4e04-49c1-bb32-1674dab5883e@googlegroups.com> Message-ID: <12b6e450-8ba9-48db-a099-8e4152a8b8f4@googlegroups.com> On Tuesday, June 21, 2016 at 7:27:00 PM UTC+5:30, Rustom Mody wrote: > Emacs: : > Math: So far Ive used tex input method -- Not satisfactory After "Random832" pointed me to RFC1345 I checked that emacs has an RFC1345 input method. It may be nicer than tex input method -- need to check However like everything unicode there is no attempt to distinguish the babel part of unicode and the universal part: http://blog.languager.org/2015/03/whimsical-unicode.html From rustompmody at gmail.com Tue Jun 21 10:29:04 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Jun 2016 07:29:04 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <87mvmeheq0.fsf@elektro.pacujo.net> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> Message-ID: <1df6872b-ac26-4ecc-b200-9e44a9e255cc@googlegroups.com> On Tuesday, June 21, 2016 at 6:38:19 PM UTC+5:30, Marko Rauhamaa wrote: > A coworker of mine went through the trouble of doing the xmodmap > equivalent with setxkbmap. Thought of interviewing him about it one day. > > How-to's are really hard to come by: > > n_Xorg> -- no good > > -- no good > > d-layouts-xkb.html> -- interesting but assumes root access > > -- no > good Regarding xkb: Some good advice given to me by Yuri Khan on emacs list https://lists.gnu.org/archive/html/help-gnu-emacs/2015-01/msg00332.html From Joaquin.Alzola at lebara.com Tue Jun 21 10:32:52 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Tue, 21 Jun 2016 14:32:52 +0000 Subject: Cassandra multiprocessing can't pickle _thread.lock objects In-Reply-To: References: Message-ID: >I tried to use Cassandra and multiprocessing to insert rows (dummy data) concurrently based on the examples in Same situation here. I was going to try this solution but on the reading side. Was even thinking of putting Spark-Cassandra just to avoid Python to do multiprocessing. 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 python.list at tim.thechases.com Tue Jun 21 11:08:19 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 21 Jun 2016 10:08:19 -0500 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <87shw7gcrj.fsf@elektro.pacujo.net> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> Message-ID: <20160621100819.49675391@bigbox.christie.dr> On 2016-06-21 11:35, Marko Rauhamaa wrote: > > These are all pretty easy to remember. > > German umlauts a" o" u" give ? ? ? (or use uppercase) > > Spanish e?a (spelling?) and punctuations: n~ ?? !! --> ? ? ? > > French accents: e' e` e^ c, --> ? ? ? ? > > Money: c= l- y- c/ --> ? ? ? ? > > Math: =/ -: +- xx <= >= --> ? ? ? ? ? ? > > Superscripts: ^0 ^1 ^2 ^3 --> ? ? ? ? > > Simple fractions: 12 13 ... 78 --> ? ? ... ? > > Here's a cute one: CCCP --> ? (hammer & sickle) > > And like your first examples: oo mu ss --> ? ? ? > > Trouble is, nobody's going to guess or memorize any of that stuff. I've been pleasantly surprised by how guessable most of them are. Occasionally I have to dig a bit deeper, but for diacritics, superscripts (using the "^", as well as subscripts using "_"), fractions, and arrows (either a "-" or a "|" followed by a character that looks like the arrow-head "<>v^") are all pretty easy to guess when you understand the patterns. -tkc From steve at pearwood.info Tue Jun 21 11:27:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 01:27:16 +1000 Subject: (repost) Advisory: HTTP Header Injection in Python urllib References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> <1466221941.3662846.641269641.7FFA59B4@webmail.messagingengine.com> <576570a4$0$1607$c3e8da3$5496439d@news.astraweb.com> <1466270936.1206591.641594473.5759A310@webmail.messagingengine.com> Message-ID: <57695cd5$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Jun 2016 03:28 am, Random832 wrote: > On Sat, Jun 18, 2016, at 12:02, Steven D'Aprano wrote: >> Er, you may have missed that I'm talking about a single user setup. >> Are you suggesting that I can't trust myself not to forge a request >> that goes to a hostile site? >> >> It's all well and good to say that the application is vulnerable to >> X-site attacks, but how does that relate to a system where I'm the >> only user? > > I don't think you understand what cross-site request forgery is, Possibly not. > unless > your definition of "single user setup" includes not connecting to the > internet at all. The point is that one site causes the client to send a > request (not desired by the user) to another site. That the client is a > single-user system makes no difference. Here's the link again, in case anyone missed it. http://blog.blindspotsecurity.com/2016/06/advisory-http-header-injection-in.html I've read it again, and it seems to me that the attack surface is pretty small. The attacker needs to know that you're running (let's say) memcache, AND the port you're running it on, AND that you are fetching URLs with something that allows X-site attacks, AND they have to fool you into fetching an appropriately crafted URL. From the article: "In our case, if we could fool an internal Python application into fetching a URL for us, then we could easily access memcached instances. Consider the URL: ..." and then they demonstrate an attack against memcache. Except, the author of the article knows the port that memcache is on, and he doesn't have to fool anyone into fetching a hostile URL. He just fetched it himself. "In our case, if we could fool a person into pointing a gun at their foot and pulling the trigger, we can blow their foot off. Here is a proof-of-concept..." (points gun at own foot and pulls trigger) Absent an actual attack that demonstrates the "fool an internal application" part, I don't think I'm going to lose too much sleep over this. My house has many dangerous items, like kitchen knives, power tools and the like. If somebody could fool me into, say, hitting myself on the head with a hammer, that would be bad. But until I see a demonstration of how somebody might do that, I'm not going to keep my hammer under lock and key. Maybe I'm missing something, but while I acknowledge the general position "here's a security flaw", and I accept that it needs to be fixed, I'm not seeing that this is a sufficiently realistic attack enough to justify requiring authentication for all internal services. -- Steven From steve at pearwood.info Tue Jun 21 11:56:31 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 01:56:31 +1000 Subject: base64.b64encode(data) References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> <575e4198$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465795993.2881334.635716385.023A423E@webmail.messagingengine.com> <575e8c77$0$1599$c3e8da3$5496439d@news.astraweb.com> <1465824966.3931239.636067473.06E0521B@webmail.messagingengine.com> Message-ID: <576963b1$0$1595$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jun 2016 11:36 pm, Random832 wrote: > On Mon, Jun 13, 2016, at 06:35, Steven D'Aprano wrote: >> But this is a Python forum, and Python 3 is a language that tries >> very, very hard to keep a clean separation between bytes and text, > > Yes, but that doesn't mean that you're right As you already know, but others might not, I asked on the Python-Dev list why b64encode has the behaviour it has: https://mail.python.org/pipermail/python-dev/2016-June/145166.html **Even if** your interpretation of RFC-989 etc are correct, Python is not bound to follow their interpretation. The RFC is a network protocol, Python is a programming language, and our libraries can do whatever makes sense for *programming*. And the people who migrated the Python 2 base64 lib to Python 3 thought that it made more sense to have the functions operate on bytes and return bytes. Other languages have made other choices: Microsoft's base64 library in C#, C++, F# and VB takes an array of bytes as input, and outputs a UTF-16 string: https://msdn.microsoft.com/en-us/library/dhx0d524%28v=vs.110%29.aspx Java's base64 encoder takes and returns bytes: https://docs.oracle.com/javase/8/docs/api/java/util/Base64.Encoder.html Javascript's Base64 encoder takes input as UTF-16 encoded text and returns the same: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding RFC 989 says that their unnamed "Encode to Printable Form" uses implementation independent characters: The bits resulting from the encryption operation are encoded into characters which are universally representable at all sites, though not necessarily with the same bit patterns (e.g., although the character "E" is represented in an ASCII-based system as hexadecimal 45 and as hexadecimal C5 in an EBCDIC-based system, the local significance of the two representations is equivalent). https://tools.ietf.org/html/rfc989 But I'm not sure how RFC 989 intends this to work in practice. If you encrypt and encode a message on an EBCDIC machine, and the output consists of an "E" (i.e. 0xC5, and you transmit it to an ASCII machine where you try to decode it, it will be interpreted as an eight-bit non-ASCII character, *not* as "E". In order for this to work, you need an additional step that transfers byte 0xC5 (EBCDIC "E") into byte 0x45 (ASCII "E") otherwise you get junk. That's okay for email, since email is sent in US-ASCII[1], so any EBCDIC machine wanting to send email must convert the header and bodies into US-ASCII, including any Base64 attachments. But the relevance of this to Python is pretty low. > At > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/uuencode.html Python's base64 module is not a re-implementation of the POSIX utility uuencode. The uuencode utility is an application, not a library. It has its own reasons for writing text files encoding using the local environment's default encoding, and it explicitly states that when moving such files to another system, they must be translated: [quote] If it was transmitted over a mail system or sent to a machine with a different codeset, it is assumed that, as for every other text file, some translation mechanism would convert it (by the time it reached a user on the other system) into an appropriate codeset. [end quote] In any case, the POSIX utility uuencode is free to implement whatever high-level behaviour its authors like, just as programming language designers are free to design their Base64 libraries to work how they like. [1] With a few exceptions, such as binary attachments, although not all mail servers can deal with them. -- Steven From jon+usenet at unequivocal.co.uk Tue Jun 21 12:09:02 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Tue, 21 Jun 2016 16:09:02 -0000 (UTC) Subject: (repost) Advisory: HTTP Header Injection in Python urllib References: <87shwbmz0l.fsf@nightsong.com> <57649d22$0$1603$c3e8da3$5496439d@news.astraweb.com> <1466221941.3662846.641269641.7FFA59B4@webmail.messagingengine.com> <576570a4$0$1607$c3e8da3$5496439d@news.astraweb.com> <1466270936.1206591.641594473.5759A310@webmail.messagingengine.com> <57695cd5$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-21, Steven D'Aprano wrote: > "In our case, if we could fool an internal Python application into fetching > a URL for us, then we could easily access memcached instances. Consider the > URL: ..." > > and then they demonstrate an attack against memcache. Except, the author of > the article knows the port that memcache is on, and he doesn't have to fool > anyone into fetching a hostile URL. He just fetched it himself. memcached, like most services, has a default port. If you know or can guess that memcached is in use then you probably know the right port already. Bear in mind that some very successful attacks rely on quite specific circumstances but bear fruit anyway if you can manage to do some sort of scripted attack against a large number of potential victims. > "In our case, if we could fool a person into pointing a gun at their foot > and pulling the trigger, we can blow their foot off. Here is a > proof-of-concept..." (points gun at own foot and pulls trigger) No, that's not a fair comparison at all. > Absent an actual attack that demonstrates the "fool an internal application" > part, I don't think I'm going to lose too much sleep over this. My house > has many dangerous items, like kitchen knives, power tools and the like. If > somebody could fool me into, say, hitting myself on the head with a hammer, > that would be bad. That's not a valid analogy either. A more appropriate analogy would be that if someone could get you to hit a specific ordinary-looking nail then your hammer will bounce off and hit you in the head. > Maybe I'm missing something, but while I acknowledge the general position > "here's a security flaw", and I accept that it needs to be fixed, I'm not > seeing that this is a sufficiently realistic attack enough to justify > requiring authentication for all internal services. I agree, although it is certainly something that people ought to bear in mind. And it is something that should certainly be fixed in Python. From steve at pearwood.info Tue Jun 21 12:25:03 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 02:25:03 +1000 Subject: Request for opinions: A cross language development tool References: <57692EBD.1060606@bridge-dev.com> Message-ID: <57696a61$0$1600$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Jun 2016 10:10 pm, Tal Zion wrote: > * > > Hey! > > I would like to know your opinions about a project a friend and I have > been developing for about a year now, which we really think could > empower Python. Today Python is mostly used on servers. Really? > Many people who > want to develop an app will choose Python to write the backend and > develop frontends in Java, Swift, Javascript, etc. We think Python is > great, and we don't see why we shouldn't be able to write a native iOS, > Android or web app entirely in Python. I'm not sure about iOS, but you can write desktop applications in Python, and Android apps in Python, and web apps, although it's probably true that most people will use HTML and Javascript for the front end. > After all, these languages share > the same concepts, more or less (classes, functions, exceptions, etc) > and what really separates them is syntax. We're proposing a new > approach: developers will code in their favorite language, such as > Python (woot woot!), and be able to import Java, Swift and Javascript > code from Python, and use that code as if it were written in Python. In a sense, this is bringing Python back to its roots as a glue language, for bringing C or Fortran libraries together. Be aware that there is a LOT of prior art here: Kivy (multi-platform Python framework) Julia's PyCall (allow Julia code to call Python code, and vice versa) https://www.euroscipy.org/2014/schedule/presentation/53/ Integrating Python with the .Net and Mono framework: - Python for .Net; - IronPython Integrating Python with Java: - Jython - JPype Integration with C++: - Boost - SWIG - Weave (part of SciPy) etc. So I think you may need to explain better exactly what your project does that the others don't do. > Python code will run on just about any platform, including the web. > > > ** > > So how does this magic work? We developed a new compiler platform called > Bridge. At the heart of Bridge is the Bridge Extensible Code > Representation (BECR). Code in any language is parsed into an AST and is > then translated to the BECR. The BECR supports common programming > concepts (if, for, while, etc) and it can also be extended to support > new concepts in order to ease the translation from the source language. > Therefore, the translation from the source language?s AST to the BECR is > easy as it**merely translates syntax. Then, Bridge translates the BECR > to LLVM IR and from there the code can be compiled to x86, arm, asm.js > or any other LLVM backend*. *After code has been translated to BECR, it > doesn?t matter what the source language was, and the syntax barriers > that stopped languages from working together disappear. This means that > once more languages will be translated to the BECR, they will be able to > work seamlessly together. Sounds very optimistic. It's not just *syntax* barriers that stop languages from working together. Consider: x += y; which is legal syntax in both C and Python (and probably a lot of other languages). But the *semantics* are not necessarily the same. They're likely to be different -- sometimes very different. > ** > > Today, we have a basic demo showing an Android app written in Python > displaying native Android buttons and labels inside a native scroll > view. In this demo, Python code can import Java classes and inherit from > them. That's nice. How do we see that demo? > Soon Bridge will be released as an open source project. We?d love to > hear your opinions about this project. We?re really excited and we can?t > wait to see Python being used in more and more places! > > > ** > > Thanks, Tal** > > * -- Steven From rantingrickjohnson at gmail.com Tue Jun 21 12:48:02 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 09:48:02 -0700 (PDT) Subject: [tkinter] widget size adjustment In-Reply-To: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> Message-ID: On Sunday, June 19, 2016 at 1:29:11 PM UTC-5, Pierre-Alain Dorange wrote: > I got a small interface handle with tkinter / Gridmanager. > I configure row and column to follow user window size > adjustement, that' fine. but i do not know how to adjust > the main widget : a canvas displaying a portion of a big > image. I bind a resize event that works, but do not know > what to do from that. > > Any clue or advice or tutorial ? I'm sorry, but your explanation is lacking, and could be the reason you have not received help so far. I'll attempt to guess what the problem is, and then you can refine the question if none of these solutions is what you're looking for. (1) If you want a widget to fill *ALL* of the available space within it's parent window, you'll need to set the appropriate options for the "pack" or "grid" geometry manager -- depending on which one you are using. Note: i won't bother discussing the "place" manager. (See CODE1 and CODE2 below) Pro tip: If your top-window *ONLY* contains a single child widget that fills the entire space, *ALWAYS* use pack! (2) If the contents of your canvas exceed the viewable portion of it's viewable area, then you'll need to add scroll-bars and set the scrollregion option so that you can view the "clipped portions". (See CODE3 below) (3) Or perhaps you want the canvas content(s) to resize dynamically as the canvas expands and contacts? (4) Something else entirely...? ============================================================ CODE EXAMPLES ============================================================ ## BEGIN: CODE1 ## import Tkinter as tk from Tkconstants import * root = tk.Tk() canvas = tk.Canvas(root, bg='red') canvas.pack(fill=BOTH, expand=YES, padx=5, pady=5) root.mainloop() ## END: CODE1 ## ## BEGIN: CODE2 ## import Tkinter as tk from Tkconstants import * root = tk.Tk() root.rowconfigure(1, weight=1) root.columnconfigure(1, weight=1) canvas = tk.Canvas(root, bg='red') canvas.pack(fill=BOTH, expand=YES, padx=5, pady=5) root.mainloop() ## END: CODE2 ## ## BEGIN: CODE3 ## import Tkinter as tk from Tkconstants import * # ROOT_MSG = """\ In the two windows below, observe the consequences of the canvas "scrollregion" option. The left window has scollregion set to contain the entire contents, whilst the right window has not configured the scrollregion at all, and as a result, the scrollbars are useless. """ # class MyCanvas(tk.Canvas): def __init__(self, master, **kw): self.frame = tk.Frame(master) self.frame.rowconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1) self.hbar = tk.Scrollbar(self.frame, orient=HORIZONTAL) self.block = tk.Frame(self.frame, width=18, height=18) self.block.grid(row=1, column=1) self.vbar = tk.Scrollbar(self.frame, orient=VERTICAL) tk.Canvas.__init__(self, self.frame, **kw) tk.Canvas.grid(self, row=0, column=0, sticky=N+S+E+W) self.hbar.configure(command=self.xview) self.vbar.configure(command=self.yview) self.config(yscrollcommand=self.vbar.set, xscrollcommand=self.hbar.set) self.hbar.grid(row=1, column=0, sticky=W+E) self.vbar.grid(row=0, column=1, sticky=N+S) # def fill_canvas_with_junk(canvas): sx = 5 for r_ in range(10): canvas.create_rectangle(sx, 5, sx+100, 3000, fill='gray') canvas.create_line(sx, 5, sx+100, 3000) sx += 200 # root = tk.Tk() root.geometry('+5+5') root.title('RootWindow (aka: BWFL)') w = tk.Label(root, text=ROOT_MSG, fg='red') w.pack(fill=BOTH, expand=YES) # top1 = tk.Toplevel(root) top1.geometry('400x300+5-50') top1.title('Example1 (clipped regions accessable)') canvas1 = MyCanvas(top1, bg='white') canvas1.frame.pack(fill=BOTH, expand=YES, padx=5, pady=5) fill_canvas_with_junk(canvas1) sx,sy,ex,ey = canvas1.bbox(ALL) canvas1['scrollregion'] = (0,0,ex+5,ey+5) # top2 = tk.Toplevel(root) top2.geometry('400x300-5-50') top2.title('Example2 (clipped regions *NOT* accessable)') canvas2 = MyCanvas(top2, bg='white') canvas2.frame.pack(fill=BOTH, expand=YES, padx=5, pady=5) fill_canvas_with_junk(canvas2) # root.mainloop() ## END: CODE3 ## PS: Hopefully there's no bugs in here :-) From torriem at gmail.com Tue Jun 21 13:02:38 2016 From: torriem at gmail.com (Michael Torrie) Date: Tue, 21 Jun 2016 11:02:38 -0600 Subject: Request for opinions: A cross language development tool In-Reply-To: <57692EBD.1060606@bridge-dev.com> References: <57692EBD.1060606@bridge-dev.com> Message-ID: On 06/21/2016 06:10 AM, Tal Zion wrote: > So how does this magic work? We developed a new compiler platform called > Bridge. At the heart of Bridge is the Bridge Extensible Code > Representation (BECR). Code in any language is parsed into an AST and is > then translated to the BECR. The BECR supports common programming > concepts (if, for, while, etc) and it can also be extended to support > new concepts in order to ease the translation from the source language. > Therefore, the translation from the source language?s AST to the BECR is > easy as it**merely translates syntax. Then, Bridge translates the BECR > to LLVM IR and from there the code can be compiled to x86, arm, asm.js > or any other LLVM backend*. *After code has been translated to BECR, it > doesn?t matter what the source language was, and the syntax barriers > that stopped languages from working together disappear. This means that > once more languages will be translated to the BECR, they will be able to > work seamlessly together. Sounds interesting. Is this demo posted somewhere along with the example Python code that generated the Android app? How do you solve the problem of object models differing between different languages and runtimes? For example, Python and C++ both can use multiple inheritance. Yet Java cannot. How do you bridge across that? How do you handle Python's dynamic nature? How do you handle conversion between types? A bridge like this is indeed the holy grail, and I've never seen anyone do it successfully before. Hence the skepticism expressed by others already this morning. From rgaddi at highlandtechnology.invalid Tue Jun 21 13:04:42 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 21 Jun 2016 17:04:42 -0000 (UTC) Subject: Bulk Adding Methods Pythonically References: <1466014917.388175.638768225.2DAFD4E9@webmail.messagingengine.com> <5762030b$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 16 Jun 2016 04:39 am, Rob Gaddi wrote: > >>> class Channel: >>> frequency = mkmeasure('frequency', 'FREQ') >>> falltime = mkmeasure('falltime', 'FTIM') >> >> Thought about it, but whenever I'm dropping 20-someodd of those there's >> inevitably some place where I screw up the replication of the quoted >> name and the bound name. > > So? You have unit tests, right? Add one more test that checks the names. You > can even add that to your class definition code: > > NAMES = ('frequency', 'falltime') > THINGIES = ('FREQ', 'FTIM') > > class Channel: > for name, thingy in zip(NAMES, THINGIES): > locals()[name] = mkmeasure(name, thingy) > > assert all(getattr(Channel, name).__name__ == name for name in NAMES) > > > But at the point that you have 20+ almost identical methods, you should take > that as a cold-smell. Why do you have so many almost identical methods? > > (That doesn't mean it is *necessarily* wrong, only that you have to think > carefully about whether it is or not.) > The context is that I've got an oscilloscope here on my desk with a USB cable around to my PC. There are a slew of different measurements that I can request it make of the waveform on a given channel (i.e. the cable connected to the front-panel connector marked "2"). I send it ASCII commands like ':MEAS:VAMP? CHAN1' and it sends me ASCII replies like '1.033e-01'. I'm trying to wrap an API around all this that allows me to treat channels as Channels and ask questions like: 0.1 < chan.amplitude() < 0.2 I could just implement all that as a lookup in __getattr__, I suppose. The efficiency hit would be invisible next to the time spent doing all that I/O. But it feels hacky compared to having inspectable methods with docstrings, like the sort of thing that future me will want to take past me behind the woodshed for. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rantingrickjohnson at gmail.com Tue Jun 21 13:04:50 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 10:04:50 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: Message-ID: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> On Sunday, June 12, 2016 at 2:08:01 PM UTC-5, BartC wrote: > Anyway, it shows Python doesn't have true cross-module globals. BS! You can inject symbols into sys.modules and achieve a true global. ## BEGIN: INTERACTIVE SESSION ## py> import sys py> def foo(): ... print 'My name is foo' py> sys.modules['__builtin__'].__dict__['foo_func'] = foo py> foo_func() My name is foo ## END: INTERACTIVE SESSION ## From tjreedy at udel.edu Tue Jun 21 13:12:24 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Jun 2016 13:12:24 -0400 Subject: Proposal: named return values through dict initialization and unpacking In-Reply-To: References: Message-ID: On 6/21/2016 3:34 AM, Ari Freund via Python-list wrote: > I'd like to run this idea by the community to see if it's PEP worthy and > hasn't been already rejected. > > Background > Just as keyword arguments enhance code readability and diminish the risk of > bugs, so too would named > return values. Currently, we can write > val1, val2, val3 = myfunc() > but we must take care to order the variables correctly, i.e., in the same > order as the corresponding > values in myfunc's return statement. Getting it wrong may result in > difficult-to-detect bugs. This > problem would be alleviated if we could name the return values and > disregard their order. > > My proposal consists of two parts. > > 1. Add a new form of assignment by dictionary unpacking. There was a recent (last couple of months?) discussion on python-ideas about dictionary unpacking. It does not seem too practical. But maybe you can find the thread -- Terry Jan Reedy From rantingrickjohnson at gmail.com Tue Jun 21 13:14:02 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 10:14:02 -0700 (PDT) Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: <9411cdf9-4a55-45ec-89e6-dfa22c7ed9c9@googlegroups.com> On Tuesday, June 21, 2016 at 6:03:28 AM UTC-5, Pushpanth Gundepalli wrote: > Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. Have you tried googling for "python interactive tutorial"? Someone had created one similar to Ruby's, but i cannot remember the site. The python.org website has an interactive shell you can play around with online, but it's no different than using Python on your machine -- not much advantage anyway. From random832 at fastmail.com Tue Jun 21 13:15:21 2016 From: random832 at fastmail.com (Random832) Date: Tue, 21 Jun 2016 13:15:21 -0400 Subject: the global keyword: In-Reply-To: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> Message-ID: <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> On Tue, Jun 21, 2016, at 13:04, Rick Johnson wrote: > On Sunday, June 12, 2016 at 2:08:01 PM UTC-5, BartC wrote: > > Anyway, it shows Python doesn't have true cross-module globals. > > BS! You can inject symbols into sys.modules and achieve a > true global. You can put a function or constant there, sure. But if you're using it as a variable, you'd have to do that *every* time (in which case what's the point) because reassigning to a builtin by name won't reassign the builtin, it'll create a new variable in the current context. From pdorange at pas-de-pub-merci.mac.com Tue Jun 21 13:24:44 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Tue, 21 Jun 2016 19:24:44 +0200 Subject: [tkinter] widget size adjustment References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> Message-ID: <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> Rick Johnson wrote: > I'm sorry, but your explanation is lacking, and could be > the reason you have not received help so far. Yes you're probably right. For my excuse i'm french and if i read english, i'm not fluent with it for writing... > I'll attempt > to guess what the problem is, and then you can refine the > question if none of these solutions is what you're looking > for. Thanks for you effort (and the code) > (3) Or perhaps you want the canvas content(s) to resize > dynamically as the canvas expands and contacts? That is more close to my needs. A picture is often better than words, here is a scren capture of my apps before and after resing the main window : It was a map viewer similar to online javascript mapviewer but in a local apps : with the main central part a canvas widget (with a PIL image put build and put in). I would resze the canvas according to the space available when the user resize the window. As you can see in the screen capture, when resize, the main map widget is not resized, only centered. For this apps i used widgets, assembled with the grid manager, so with cells (row and line coordinates). I allrady set the grid so that only the central cell (where the map is deisplayed) will be resize (all other row and colum do not resize). I'm a beginner with tkinter, and i could not found a way to get the cell size (the cell where the canvas widget is put). I think i can resize the canvas, but i can't find a way to get the available space after resize. Perhaps using the grid manager is not the godd idea for that ? I except it was more understandable. -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From rosuav at gmail.com Tue Jun 21 13:36:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jun 2016 03:36:45 +1000 Subject: Request for opinions: A cross language development tool In-Reply-To: <576949CC.2070708@bridge-dev.com> References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> Message-ID: On Wed, Jun 22, 2016 at 12:06 AM, Tal Zion wrote: > * Bridge makes Python faster: Python code compiled through Bridge is > compiled to native code. Because we are leveraging LLVM's many > optimizations, Python code will run faster than ever. Can you run *any* Python program through Bridge? Absolutely anything? Can you guarantee language compatibility? And if you can - what version of Python are you compatible with? ChrisA From steve at pearwood.info Tue Jun 21 13:50:24 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 03:50:24 +1000 Subject: Can math.atan2 return INF? Message-ID: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> Are there any circumstances where math.atan2(a, b) can return an infinity? I know it will return a NAN under some circumstances. -- Steven From tal at bridge-dev.com Tue Jun 21 14:01:14 2016 From: tal at bridge-dev.com (Tal Zion) Date: Tue, 21 Jun 2016 21:01:14 +0300 Subject: Request for opinions: A cross language development tool In-Reply-To: References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> Message-ID: <576980EA.2030103@bridge-dev.com> Bridge compiles Python modules into native code, which requires us to support Python *language* features (for, while, class, generators, etc) but it reuses CPython's libraries (list, dict, str, etc) so we don't implement those, and it also uses CPython's ast module in order to parse Python code. So once we are done supporting all of the language features, any Python code should work. Currently we have quite a few language features to implement, but we're working on it =) We're targeting Python 3.5. Tal On 06/21/2016 08:36 PM, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 12:06 AM, Tal Zion wrote: >> * Bridge makes Python faster: Python code compiled through Bridge is >> compiled to native code. Because we are leveraging LLVM's many >> optimizations, Python code will run faster than ever. > Can you run *any* Python program through Bridge? Absolutely anything? > Can you guarantee language compatibility? > > And if you can - what version of Python are you compatible with? > > ChrisA From pdorange at pas-de-pub-merci.mac.com Tue Jun 21 14:01:38 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Tue, 21 Jun 2016 20:01:38 +0200 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> Steven D'Aprano wrote: > Are there any circumstances where math.atan2(a, b) can return an infinity? > > I know it will return a NAN under some circumstances. atan or atan2 can't return INFINITE, it was the arc tangent of a value, then arc tangent can only be between -PI and +PI (is was an angle). I do not know under what circumstance atan2 can return NAN, atan2 taks 2 argument (y and x) and return the angle corresponding to y/x. If x is 0.0, atan2 return 0.0 (do not try to make the division). atan2 was used over atan to optimize and so that it can used the correct quadrant (for angle answer). -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From bc at freeuk.com Tue Jun 21 14:02:35 2016 From: bc at freeuk.com (BartC) Date: Tue, 21 Jun 2016 19:02:35 +0100 Subject: Request for opinions: A cross language development tool In-Reply-To: References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> Message-ID: On 21/06/2016 15:06, Tal Zion wrote: > * Bridge makes Python faster: Python code compiled through Bridge is > compiled to native code. Because we are leveraging LLVM's many > optimizations, Python code will run faster than ever. In that case forget any of your other claims. Making any Python code faster is useful in itself. But the problems are well-known. How do you turn: a = b + c into native code for example? (Since this can mean myriad different things, which you will not know until runtime, sometimes not until the line before. And not even then if 'a=b+c' is a run-time argument of 'exec()'. And one big advantage of Python is being able to try different things and run them instantly. It sounds like you will be using a complicated tool-chain performing a series of transformations, or does that all happen instantly too? -- Bartc From python at mrabarnett.plus.com Tue Jun 21 14:08:28 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 21 Jun 2016 19:08:28 +0100 Subject: Proposal: named return values through dict initialization and unpacking In-Reply-To: References: Message-ID: <1eee8456-4c2c-335a-b7e9-7a1be8c3d05a@mrabarnett.plus.com> On 2016-06-21 18:12, Terry Reedy wrote: > On 6/21/2016 3:34 AM, Ari Freund via Python-list wrote: >> I'd like to run this idea by the community to see if it's PEP worthy and >> hasn't been already rejected. >> >> Background >> Just as keyword arguments enhance code readability and diminish the risk of >> bugs, so too would named >> return values. Currently, we can write >> val1, val2, val3 = myfunc() >> but we must take care to order the variables correctly, i.e., in the same >> order as the corresponding >> values in myfunc's return statement. Getting it wrong may result in >> difficult-to-detect bugs. This >> problem would be alleviated if we could name the return values and >> disregard their order. >> >> My proposal consists of two parts. >> >> 1. Add a new form of assignment by dictionary unpacking. > > There was a recent (last couple of months?) discussion on python-ideas > about dictionary unpacking. It does not seem too practical. But maybe > you can find the thread > The thread was titled "Unpacking a dict" and it started on 25 May 2016. From michael.selik at gmail.com Tue Jun 21 14:08:58 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 21 Jun 2016 18:08:58 +0000 Subject: Proposal: named return values through dict initialization and unpacking In-Reply-To: References: Message-ID: On Tue, Jun 21, 2016, 10:14 AM Terry Reedy wrote: > On 6/21/2016 3:34 AM, Ari Freund via Python-list wrote: > > I'd like to run this idea by the community to see if it's PEP worthy and > > hasn't been already rejected. > > > There was a recent (last couple of months?) discussion on python-ideas > about dictionary unpacking. It does not seem too practical. But maybe > you can find the thread > There were a few related threads. I wrote a module to handle what I thought was the most important use case. https://github.com/selik/destructure > From rosuav at gmail.com Tue Jun 21 14:26:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jun 2016 04:26:38 +1000 Subject: Request for opinions: A cross language development tool In-Reply-To: <576980EA.2030103@bridge-dev.com> References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> <576980EA.2030103@bridge-dev.com> Message-ID: On Wed, Jun 22, 2016 at 4:01 AM, Tal Zion wrote: > Bridge compiles Python modules into native code, which requires us to > support Python *language* features (for, while, class, generators, etc) but > it reuses CPython's libraries (list, dict, str, etc) so we don't implement > those, and it also uses CPython's ast module in order to parse Python code. > So once we are done supporting all of the language features, any Python code > should work. Currently we have quite a few language features to implement, > but we're working on it =) We're targeting Python 3.5. Okay, so how do you handle exec and eval? ChrisA From tal at bridge-dev.com Tue Jun 21 14:30:45 2016 From: tal at bridge-dev.com (Tal Zion) Date: Tue, 21 Jun 2016 21:30:45 +0300 Subject: Request for opinions: A cross language development tool In-Reply-To: References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> <576980EA.2030103@bridge-dev.com> Message-ID: <576987D5.3030502@bridge-dev.com> We use CPython's implementation of exec and eval. Tal On 06/21/2016 09:26 PM, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 4:01 AM, Tal Zion wrote: >> Bridge compiles Python modules into native code, which requires us to >> support Python *language* features (for, while, class, generators, etc) but >> it reuses CPython's libraries (list, dict, str, etc) so we don't implement >> those, and it also uses CPython's ast module in order to parse Python code. >> So once we are done supporting all of the language features, any Python code >> should work. Currently we have quite a few language features to implement, >> but we're working on it =) We're targeting Python 3.5. > Okay, so how do you handle exec and eval? > > ChrisA From jussi.piitulainen at helsinki.fi Tue Jun 21 14:32:48 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 21 Jun 2016 21:32:48 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> Message-ID: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes: > Steven D'Aprano wrote: > >> Are there any circumstances where math.atan2(a, b) can return an infinity? >> >> I know it will return a NAN under some circumstances. > > atan or atan2 can't return INFINITE, it was the arc tangent of a > value, then arc tangent can only be between -PI and +PI (is was an > angle). > > I do not know under what circumstance atan2 can return NAN, atan2 taks > 2 argument (y and x) and return the angle corresponding to y/x. If x > is 0.0, atan2 return 0.0 (do not try to make the division). It seems to return NaN when either argument is NaN. It seems to return finite values when either argument is Inf or -Inf, and negative zeroes lead to different but finite answers. Wikipedia says ata2(0,0) is considered undefined traditionally and in symbolic maths but otherwise most computer implementations define it. Python seems to produce +-0.0 and +-pi for variously signed zeroes. I didn't see any mention of it ever being infinite, which makes sense given that arcus functions are supposed to return angles. The extreme case seemed to be the inclusion of -pi as a possible value. (I know nothing, I was just curious enough to play with this a bit.) From marko at pacujo.net Tue Jun 21 14:56:21 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 21 Jun 2016 21:56:21 +0300 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <1df6872b-ac26-4ecc-b200-9e44a9e255cc@googlegroups.com> Message-ID: <87twgmtlpm.fsf@elektro.pacujo.net> Rustom Mody : > Regarding xkb: > > Some good advice given to me by Yuri Khan on emacs list > https://lists.gnu.org/archive/html/help-gnu-emacs/2015-01/msg00332.html Well, not quite: * Find the XKB data directory. [Normally, this is /usr/share/X11/xkb.] * In its ?keycodes? subdirectory, create a file that is unlikely to be overwritten by a future version of XKB (e.g. by prefixing it with your initials). [Let?s name it ?rusi? for the sake of this example.] * In this file, paste the following: [...] You can see this advice requires root access. My coworker does assure me it can all be done with regular luser rights as well, but no web site seems to say how exactly. Marko From ben+python at benfinney.id.au Tue Jun 21 15:03:21 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 22 Jun 2016 05:03:21 +1000 Subject: Marking a subtest as an expected failure References: <5768faaa$0$2846$c3e8da3$76491128@news.astraweb.com> Message-ID: <858txyxt3a.fsf@benfinney.id.au> Steven D'Aprano writes: > def test_spam(self): > for i in range(100): > for j in range(100): > with self.subtest(i=i, j=j): > if (i, j) != (97, 83): > self.assertEqual(spam(i, j), 999) > > > but is there a nicer way to mark a specific subtest as an expected > failure? Expected failures and subtests are apparently not easily mixed using the current API. Digging into the ?unittest.case? module, the ?expectedFailure? decorator does its job by setting the test case's ?__unittest_expecting_failure__? attribute to ?True?. Perhaps you can get the subtest object from the context manager, and decide to set that magic attribute:: # ? with self.subtest(i=i, j=j) as subtest: if (i, j) == (97, 83): # The inhabitants of (97, 83) have always been trouble. subtest.__unittest_expecting_failure__ = True self.assertEqual(spam(i, j), 999) That attribute is undocumented though, so I don't know whether to consider that a nasty hack or a clever one. (Nor do I know whether it works as I expect.) You would be justified to report a bug that this interaction of useful features should really be easier to access. -- \ ?Try adding ?as long as you don't breach the terms of service ? | `\ according to our sole judgement? to the end of any cloud | _o__) computing pitch.? ?Simon Phipps, 2010-12-11 | Ben Finney From rosuav at gmail.com Tue Jun 21 15:28:59 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jun 2016 05:28:59 +1000 Subject: Request for opinions: A cross language development tool In-Reply-To: <576987D5.3030502@bridge-dev.com> References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> <576980EA.2030103@bridge-dev.com> <576987D5.3030502@bridge-dev.com> Message-ID: On Wed, Jun 22, 2016 at 4:30 AM, Tal Zion wrote: > We use CPython's implementation of exec and eval. > (Please don't keep top-posting.) Okay. So as I understand it, this requires the full CPython interpreter to be included at run-time; how does this help you work seamlessly with other languages? How is this different from simply having CPython (or PyPy, since you're messing with performance - PyPy JIT-compiles to native code, so it can be pretty fast), Ruby, etc, etc all installed and operating separately? Here's a concrete example. Python has several data types for storing numbers. Notably, int (which can store *any* integer), and float (which can store non-integers as well, but has roughly 53 bits of storage). JavaScript has only the latter. So how can the two interoperate correctly? Can Python code call a JavaScript function? Vice versa? And if not, how seamlessly are the languages actually able to work together? ChrisA From python.list at tim.thechases.com Tue Jun 21 15:42:06 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 21 Jun 2016 14:42:06 -0500 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <87twgmtlpm.fsf@elektro.pacujo.net> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <1df6872b-ac26-4ecc-b200-9e44a9e255cc@googlegroups.com> <87twgmtlpm.fsf@elektro.pacujo.net> Message-ID: <20160621144206.1ff4282a@bigbox.christie.dr> On 2016-06-21 21:56, Marko Rauhamaa wrote: > Rustom Mody : > > > Regarding xkb: > > > > Some good advice given to me by Yuri Khan on emacs list > > https://lists.gnu.org/archive/html/help-gnu-emacs/2015-01/msg00332.html > > Well, not quite: > > * Find the XKB data directory. [Normally, this > is /usr/share/X11/xkb.] > * In its ?keycodes? subdirectory, create a file that is unlikely > to be overwritten by a future version of XKB (e.g. by prefixing it > with your initials). [Let?s name it ?rusi? for the sake of this > example.] > * In this file, paste the following: > [...] > > You can see this advice requires root access. > > My coworker does assure me it can all be done with regular luser > rights as well, but no web site seems to say how exactly. I have a ~/.XCompose file that contains something like include "%L" : "?" U1F616 # CONFOUNDED FACE

: "?" U1F61B # FACE WITH STUCK-OUT TONGUE

: "?" U1F61B # FACE WITH STUCK-OUT TONGUE The "include" pulls in the system-wide file, before adding my own compose maps. -tkc From marko at pacujo.net Tue Jun 21 16:08:02 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 21 Jun 2016 23:08:02 +0300 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <1df6872b-ac26-4ecc-b200-9e44a9e255cc@googlegroups.com> <87twgmtlpm.fsf@elektro.pacujo.net> <20160621144206.1ff4282a@bigbox.christie.dr> Message-ID: <87poratie5.fsf@elektro.pacujo.net> Tim Chase : > I have a ~/.XCompose file that contains something like My Fedora 23 setup has === BEGIN /etc/X11/xinit/xinitrc-common================================= [...] userxkbmap=$HOME/.Xkbmap [...] if [ -r "$userxkbmap" ]; then setxkbmap $(cat "$userxkbmap") XKB_IN_USE=yes fi [...] === END /etc/X11/xinit/xinitrc-common=================================== A somewhat surprising and scary idiom! I suppose I could specify: ===BEGIN ~/.Xkbmap====================================================== -keymap /home/marko/.keys ===END ~/.Xkbmap======================================================== Then, I suppose I need to use xkbcomp to create ~/.keys Marko From auriocus at gmx.de Tue Jun 21 16:18:26 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 21 Jun 2016 22:18:26 +0200 Subject: [tkinter] widget size adjustment In-Reply-To: <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> Message-ID: Am 21.06.16 um 19:24 schrieb Pierre-Alain Dorange: > A picture is often better than words, here is a scren capture of my apps > before and after resing the main window : > > > It was a map viewer similar to online javascript mapviewer but in a > local apps : with the main central part a canvas widget (with a PIL > image put build and put in). > > I would resze the canvas according to the space available when the user > resize the window. > As you can see in the screen capture, when resize, the main map widget > is not resized, only centered. Perhaps your assumption is wrong. Maybe the canvas itself *is* resized, so the white space you see around the image is the background of the canvas. To test this easily, set a strong color for the background: blabla = tk.Canvas(..., bg='red') You should see red space appear when you resize the window. If you see white space, then the options are not set properly and the canvas is not resized. I assume that you want the following: Upon resizing the main window, the map image should be stretched to fill the space, right? Then you'll have to do that on your own. First, bind a Configure event to the canvas canvas.bind('', callback) The callback functino now gets called when the canvas needs to be redrawn. In that callback function, you get the new width and height from the event object. Resize the image accordingly (using a PIL function). Christian From larry.martell at gmail.com Tue Jun 21 16:54:28 2016 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 21 Jun 2016 16:54:28 -0400 Subject: pyinstaller Message-ID: Anyone here have any experience with pyinstaller? I am trying to use it, but I'm not having much success. I tried posting to the pyinstaller ML but it said my post had to be approved first, and that hasn't happened in a while. I'll post details if someone here thinks they can help. From rantingrickjohnson at gmail.com Tue Jun 21 17:03:02 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 14:03:02 -0700 (PDT) Subject: [tkinter] widget size adjustment In-Reply-To: <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <95ca9373-671a-4b8e-adeb-bd31d9c152eb@googlegroups.com> On Tuesday, June 21, 2016 at 12:24:56 PM UTC-5, Pierre-Alain Dorange wrote: > > > (3) Or perhaps you want the canvas content(s) to resize > > dynamically as the canvas expands and contacts? > > That is more close to my needs. > > A picture is often better than words, here is a scren > capture of my apps before and after resing the main window If your intention is to create a grid of images, then you need to understand two basic realities of transforming computer images. First there is stretching, and then there is resizing. Stretching will distort the image. Resizing will maintain the image integrity (in most cases). Have you considered these realities? For instance, it's easy to create an expanding grid of widgets with Tkinter, here is a simple example that uses a grid of buttons: ## BEGIN CODE ## import Tkinter as tk from Tkconstants import * # root = tk.Tk() root.title('Dynamic Grid') # for _ in range(3): root.rowconfigure(_, weight=1) root.columnconfigure(_, weight=1) # for row in range(3): for col in range(3): w = tk.Button(root, text='{0}-{1}'.format(row,col)) w.grid(row=row, column=col, sticky=N+S+W+E) # root.mainloop() However, what do you expect your images to do when the window is morphed: Stretch or Resize? From rantingrickjohnson at gmail.com Tue Jun 21 18:20:34 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 15:20:34 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> Message-ID: <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> On Tuesday, June 21, 2016 at 12:15:38 PM UTC-5, Random832 wrote: > You can put a function or constant there, sure. But if > you're using it as a variable, you'd have to do that > *every* time (in which case what's the point) Well, since the term "variable" has been so abused, using it in such a narrowly defined manner here creates a high probability of starting a semantics flame-war. (c) python-list Depending on the specific inputs, the "data a variable symbol is attached to" may indeed remain static throughout the entire life of the program -- Hmmm -- in that case, should we still call it a variable? I suppose it's a matter of deciding if reality defines a variable, or if programmer intent defines a variable. Metaphysical musings aside, i get your point. O:-). > because reassigning to a builtin by name won't reassign > the builtin, it'll create a new variable in the current > context. True. As can be demonstrated with this interactive session. py> import sys py> def foo(): ... print 'My name is Foo!' py> sys.modules['__builtin__'].__dict__['foo_func'] = foo py> foo() My name is Foo! py> foo = 'bar' py> foo 'bar' py> sys.modules['__builtin__'].__dict__['foo_func'] Storing dynamic data to global space is almost always foolish, and I'm a fan of name spaces. But i did not recommend such foolish action, i was merely replying to the assertion that "Python does have real globals". She does, you just have look under the tail! (sexual identity yet to be determined) Besides, Python's global statement is misleading to noobs. It's unfortunate that Python did not inject a symbol to represent the module level space. Something like "M" or "mod", or my personal favorite "MSFL"! (ModuleSpaceForLife) Then one could have added module-level symbols without all the semantic hubbub. MSFL.foo = 0 def iter_foo(): MSFL.foo += 1 Heck, when i see the global statement in Python code, i immediately pinch my nose, and run away. There may be legitimate uses for the global statement, but i've yet to see them. From rosuav at gmail.com Tue Jun 21 18:32:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jun 2016 08:32:23 +1000 Subject: the global keyword: In-Reply-To: <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> Message-ID: On Wed, Jun 22, 2016 at 8:20 AM, Rick Johnson wrote: > Then one could have added module-level symbols without all > the semantic hubbub. > > MSFL.foo = 0 > > def iter_foo(): > MSFL.foo += 1 > And don't forget that you would need to call this function as MSFL.iter_foo(). Module-level functions are globals too. ChrisA From bc at freeuk.com Tue Jun 21 19:15:49 2016 From: bc at freeuk.com (BartC) Date: Wed, 22 Jun 2016 00:15:49 +0100 Subject: the global keyword: In-Reply-To: <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> Message-ID: On 21/06/2016 23:20, Rick Johnson wrote: > On Tuesday, June 21, 2016 at 12:15:38 PM UTC-5, Random832 wrote: > Storing dynamic data to global space is almost always > foolish, and I'm a fan of name spaces. But i did not > recommend such foolish action, i was merely replying to the > assertion that "Python does have real globals". She does, > you just have look under the tail! How would you use this idea to solve the OP's problem? So, module M contains a top-variable G. Module A imports M, and wants to access the identical variable G, without having to write it as M.G. Assignments (not just in-place mods) to G in M will be reflected in A's G, and vice versa. I tried using your method but it didn't work: -------------------------------- M.py: -------------------------------- G = 5 print ("M:G=",G) def F(): global G G = 44 print ("M.F:G=",G) -------------------------------- -------------------------------- A.py (main module): -------------------------------- import sys sys.modules['__builtin__'].__dict__['G']=8888 import M print ("G=",G) M.F() print ("G=",G) -------------------------------- Output of running A.py: ('M:G=', 5) ('G=', 8888) ('M.F:G=', 44) ('G=', 8888) Using A.G in A.py instead, I get the correct output (values of 5,5,44,44 for G). > i was merely replying to the > assertion that "Python does have real globals". She does, > you just have look under the tail! You shouldn't need to do that (what looks like abusing the built-in namespace common to all modules). There is also the problem of inadvertently injecting a 'global' name that will clash with the internal module-scope names in some modules that are not intended to be exported. The 'from' mechanism deals with that, by creating an alias to the /value/ of an exported name without affecting identical names in other modules, but it has the problem of not being an alias for the name itself. -- Bartc From rantingrickjohnson at gmail.com Tue Jun 21 19:43:00 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 16:43:00 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> Message-ID: On Tuesday, June 21, 2016 at 5:32:43 PM UTC-5, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 8:20 AM, Rick Johnson: > > Then one could have added module-level symbols without all > > the semantic hubbub. > > > > MSFL.foo = 0 > > > > def iter_foo(): > > MSFL.foo += 1 > > > > And don't forget that you would need to call this function as > MSFL.iter_foo(). Module-level functions are globals too. That's true, you got me :-). A better implementation would be to only require the "resolution to module level" from *WITHIN* foreign scopes. Which would remove the redundancy of the top-level assignment/access. Here is a new version modglo = 0 def incr_modglo(): MSFL.modglo += 1 incr_modglo() print modglo ...as opposed to the neo-classical Python way of: modglo = 0 def incr_modglo(): global modglo modglo += 1 incr_modglo() print modglo ...which is implementing an antiquated quasi-state-machine pattern. Yuck! From rantingrickjohnson at gmail.com Tue Jun 21 19:50:53 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 16:50:53 -0700 (PDT) Subject: the global keyword: In-Reply-To: <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> Message-ID: <73124fac-0993-4194-8658-4f3b661d52dc@googlegroups.com> On Tuesday, June 21, 2016 at 5:20:53 PM UTC-5, Rick Johnson wrote: > py> import sys > py> def foo(): > ... print 'My name is Foo!' > py> sys.modules['__builtin__'].__dict__['foo_func'] = foo > py> foo() > My name is Foo! > py> foo = 'bar' > py> foo > 'bar' > py> sys.modules['__builtin__'].__dict__['foo_func'] > Oops. Made a innocent boo-boo here. Let me try again. py> import sys py> def foo(): ... print "Hey, my name is foo!" py> sys.modules['__builtin__'].__dict__['foo_func'] = foo py> foo_func() Hey, my name is foo! py> foo_func = 'bar' py> foo_func 'bar' py> sys.modules['__builtin__'].__dict__['foo_func'] From rantingrickjohnson at gmail.com Tue Jun 21 20:24:31 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Jun 2016 17:24:31 -0700 (PDT) Subject: the global keyword: In-Reply-To: References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> Message-ID: On Tuesday, June 21, 2016 at 6:16:09 PM UTC-5, BartC wrote: > On 21/06/2016 23:20, Rick Johnson wrote: > > On Tuesday, June 21, 2016 at 12:15:38 PM UTC-5, Random832 wrote: > > > Storing dynamic data to global space is almost always > > foolish, and I'm a fan of name spaces. But i did not > > recommend such foolish action, i was merely replying to the > > assertion that "Python does have real globals". She does, > > you just have look under the tail! > > How would you use this idea to solve the OP's problem? I never intended to solve the OP's problem, i was just replying to an unfounded assertion. But since you asked, i will. > I tried using your method but it didn't work: Of course not, the code is absurd. Here is one way (ugly). ============================================================ MODULE A.py ============================================================ """A long long time ago, in a galaxy far away...""" import sys import B sys.modules['__builtin__'].__dict__['BDFL'] = "GvR" print sys.modules['__builtin__'].__dict__['BDFL'] B.attack() print sys.modules['__builtin__'].__dict__['BDFL'] ============================================================ MODULE B.py ============================================================ """Module Episode B: Attack of the Rick!""" import sys def attack(): sys.modules['__builtin__'].__dict__['BDFL'] = 'Rick' ============================================================ OUTPUT FROM A.py ============================================================ GvR Rick Of course, nobody wants to write that much boiler plate over and over again. So if you search the archives for this string: PyModule(G.py): Now Python has REAL globals -- and their scoped to boot! (Kindly ignore the misspelling of "they're") ...you'll find a thread i authored, that includes an object exposing a global namespace named "G". Details of how to inject the symbol G are included. After you have this module installed, you can write the aforementioned code in a much simplier form: ============================================================ MODULE A.py ============================================================ """A long long time ago, in a galaxy far away...""" import sys import B G.BDFL = "GvR" print G.BDFL B.attack() print G.BDFL ============================================================ MODULE B.py ============================================================ """Module Episode B: Attack of the Rick!""" import sys def attack(): G.BDFL = 'Rick' Sweet! From steve at pearwood.info Tue Jun 21 21:35:05 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 11:35:05 +1000 Subject: Proposal: named return values through dict initialization and unpacking References: Message-ID: <5769eb4a$0$1610$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Jun 2016 05:34 pm, Ari Freund wrote: > I'd like to run this idea by the community to see if it's PEP worthy and > hasn't been already rejected. > > Background > Just as keyword arguments enhance code readability and diminish the risk > of bugs, so too would named > return values. I don't think that follows. Keyword arguments work well when a function has many optional arguments, say, ten or so, but it's rare for functions to have optional return values, and typically they only return a few values: usually one, sometimes two, rarely three. If your function has more than three return values, you really need to rethink the function. Chances are good that it is either doing too much, or you should be encapsulating some of the detail of what it returns into objects: # Ugly: fe, fi, fo, fum, spam, eggs, cheese, tomato, foo, bar, baz = func(arg) # Probably better: obj = func(arg) assert hasattr(obj, 'fe') assert hasattr(obj, 'fi') # etc. Of course, returning a dict of {key:value} pairs is a kind of encapsulation. > Currently, we can write > val1, val2, val3 = myfunc() > but we must take care to order the variables correctly, i.e., in the same > order as the corresponding > values in myfunc's return statement. Getting it wrong may result in > difficult-to-detect bugs. Most languages deal with that with type checking, which can eliminate many (but not all) of such bugs. Python 3 will encourage optional type checking too. Alternatively, this is one of the issues that TDD and unit-testing can solve. And in practice, help(func) should never be more than a few key presses away, so I just don't see this as being a sufficiently large problem in practice to deserve new syntax. Yes, I found it annoying for the longest time that I couldn't remember which order enumerate returned its values: index, item or item, index. But I had many solutions to turn to, and eventually I memorised it. > This > problem would be alleviated if we could name the return values and > disregard their order. > > My proposal consists of two parts. > > 1. Add a new form of assignment by dictionary unpacking. > Suppose d is a dict whose keys are the strings 'var1', 'var2', > 'var3'. Then the assignment > var1, var2, var3 = **d > would set the variables to the corresponding values. Order would > not > be important, so > var3, var1, var2 = **d > would have the same effect. But I don't want to use the horrible key names your function uses. I want to use names which makes sense for my application: width, counter, aardvark = **d but d is {'var1': x, 'var2': y, 'var3': z}. What am I to do? Seriously, this is a real problem for your proposal. It's one thing to be forced to use a function's ugly parameter names: result = somefunction(var1=width, var2=counter, var3=aardvark) It's another to be forced to use variables that match something the function sets. What if we're already using a variable with that name? What if we want to use a different name? Realistically, we would hope that functions will choose informative names, but informative names tend to be long. Or if they are short, they might be excessively generic. Your function might return: number_of_pages, number_of_sections, number_of_chapters but I might prefer to use: pagecount, sectioncount, chaptercount or even: npage, nsect, nchapt It is unacceptable if I have to do this: number_of_pages, number_of_sections, number_of_chapters = **func(args) npage, nsect, nchapt = (number_of_pages, number_of_sections, number_of_chapters) Whatever names your function uses, whether they are overly abstract, generic names like a, b, c or var1, var2, var3, or painfully detailed long names like number_of_pages_containing_requested_section_titles, the caller is generally going to want to use *something else* for the assignment target. By the way, we can already get pretty close to this today: d = func(args) npage, nsect, nchapt = (d[key] for key in 'number_of_pages number_of_sections number_of_chapters'.split()) > Also, not all keys would need to participate; for example, > var2 = **d > would work just fine. > It would be an error for the same name to appear more than once on > the LHS of the assignment. Is that necessary? I can currently do this: spam, eggs, spam, spam, cheese = func(args) > It would be an error for a name on the LHS to not be a valid > variable > name or for there not to > be a corresponding key in the dict. So I can't assign directly to legal assignment targets? # forbidden mylist[2], obj.foo, mydict['key'] = **func(args) This is looking less and less useful... > It would (possibly) be an error if the dict contained keys that are > not strings (or are strings > that cannot serve as variable names). > > 2. Extend the dict() form of dictionary initialization to allow an > element to be a variable name, e.g., > dict(var1, var2, var3, var4=33) > would be equivalent to > dict(var1=var1, var2=var2, var3=var3, var4=33) How is dict supposed to know what var1 etc. are? The dict constructor has no more magical insight into the caller's locals as any other function. Also, this is legal syntax now: d = {'a': 1} mydict = dict(d, spam=999) giving {'spam': 999, 'a': 1}. Your proposal would return: {'spam': 999, 'd': {'a': 1}} or would have an ambiguous case where the caller would never be sure which behaviour takes precedence. -- Steven From jfong at ms4.hinet.net Tue Jun 21 21:36:45 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 21 Jun 2016 18:36:45 -0700 (PDT) Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: Pushpanth Gundepalli at 2016/6/21 7:03:28PM wrote: > Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. Is this you want? http://pythontutor.com/ --Jach From steve at pearwood.info Tue Jun 21 21:38:26 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 11:38:26 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> Message-ID: <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Jun 2016 04:01 am, Pierre-Alain Dorange wrote: > Steven D'Aprano wrote: > >> Are there any circumstances where math.atan2(a, b) can return an >> infinity? >> >> I know it will return a NAN under some circumstances. > > atan or atan2 can't return INFINITE, it was the arc tangent of a value, > then arc tangent can only be between -PI and +PI (is was an angle). I should hope it wouldn't. That's why I'm asking. > I do not know under what circumstance atan2 can return NAN, atan2 taks 2 > argument (y and x) and return the angle corresponding to y/x. > If x is 0.0, atan2 return 0.0 (do not try to make the division). py> math.atan2(NAN, 0) nan I think that the only way it will return a NAN is if passed a NAN. -- Steven From steve at pearwood.info Tue Jun 21 21:40:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 11:40:45 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> Message-ID: <5769ec9e$0$22142$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Jun 2016 04:32 am, Jussi Piitulainen wrote: > pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes: > >> Steven D'Aprano wrote: >> >>> Are there any circumstances where math.atan2(a, b) can return an >>> infinity? [...] > I didn't see any mention of it ever being infinite, which makes sense > given that arcus functions are supposed to return angles. The extreme > case seemed to be the inclusion of -pi as a possible value. > > (I know nothing, I was just curious enough to play with this a bit.) Thanks, I'm in the same position as you, except that I'm in the position where I need it use the result, and if it ever returns INF my function will blow up. But it doesn't look like that can happen. -- Steven From steve at pearwood.info Tue Jun 21 22:48:59 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 12:48:59 +1000 Subject: Unexpected NANs in complex arithmetic Message-ID: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> I'm doing some arithmetic on complex numbers involving INFs, and getting unexpected NANs. py> INF = float('inf') py> z = INF + 3j py> z (inf+3j) py> -z (-inf-3j) So far, nothing unexpected has occurred. But: py> -1*z # should be the same as -z (-inf+nanj) And even more strange: py> 1*z (inf+nanj) Is this the right behaviour? If so, what's the justification for it? -- Steven From rosuav at gmail.com Tue Jun 21 22:57:55 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jun 2016 12:57:55 +1000 Subject: Unexpected NANs in complex arithmetic In-Reply-To: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jun 22, 2016 at 12:48 PM, Steven D'Aprano wrote: > I'm doing some arithmetic on complex numbers involving INFs, and getting > unexpected NANs. > > py> INF = float('inf') > py> z = INF + 3j > py> z > (inf+3j) > py> -z > (-inf-3j) > > So far, nothing unexpected has occurred. But: > > py> -1*z # should be the same as -z > (-inf+nanj) > > > And even more strange: > > py> 1*z > (inf+nanj) > > > > Is this the right behaviour? If so, what's the justification for it? I've no idea, so I Googled StackExchange [1] and found this: http://math.stackexchange.com/questions/585766/what-is-infinity-in-complex-plane-and-what-are-operation-with-infinity-extended Notably this: """ To some extent, +?+? and ???? also play this role on the real axis: they are not a destination, they are road signs that tell us to go in a certain direction and never stop. """ So when your real part is float("inf"), what you're really saying is "Go as far as you possibly can in the positive direction, then keep going (because you haven't run out of numbers yet), and tell me, what is 1*z tending towards?". Infinity isn't a number, and the imaginary part of your complex number isn't really a factor in figuring out where you're likely to end up with your multiplication. I guess that's a justification for it coming out as NaN. ChrisA [1] http://www.theallium.com/engineering/computer-programming-to-be-officially-renamed-googling-stackoverflow/ From cake240 at gmail.com Tue Jun 21 23:40:05 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Tue, 21 Jun 2016 20:40:05 -0700 (PDT) Subject: Operator Precedence/Boolean Logic Message-ID: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Hi There, I am a little confused as to how this is False: False==(False or True) I would think it is True because False==False is true. I think the parenthesis are confusing me. (False==False) or True This is True. Is it because False==False? And True==False is not True but that does not change that this is True. If someone could please explain as I am teaching Python to myself and am stuck on this that would be great. Thank you for your help! From cake240 at gmail.com Tue Jun 21 23:50:24 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Tue, 21 Jun 2016 20:50:24 -0700 (PDT) Subject: while Loops Message-ID: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> i=1 while i<=5: print(i) i=i+1 The result is: 1 2 3 4 5 Why is one of the results 5 since i=i+1? Should the maximum result be 4 since 4 +1=5? Thanks for your help! From dan at tombstonezero.net Tue Jun 21 23:54:27 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 22 Jun 2016 03:54:27 -0000 (UTC) Subject: Unexpected NANs in complex arithmetic References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 22 Jun 2016 12:57:55 +1000, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 12:48 PM, Steven D'Aprano wrote: >> I'm doing some arithmetic on complex numbers involving INFs, and getting >> unexpected NANs. >> >> py> INF = float('inf') >> py> z = INF + 3j >> py> z >> (inf+3j) [...] >> Is this the right behaviour? If so, what's the justification for it? > > I've no idea, so I Googled StackExchange [1] and found this: > > http://math.stackexchange.com/questions/585766/what-is-infinity-in-complex-plane-and-what-are-operation-with-infinity-extended > > Notably this: > > """ > To some extent, +?+? and ???? also play this role on the real axis: > they are not a destination, they are road signs that tell us to go in > a certain direction and never stop. > """ > > So when your real part is float("inf"), what you're really saying is > "Go as far as you possibly can in the positive direction, then keep > going (because you haven't run out of numbers yet), and tell me, what > is 1*z tending towards?". Infinity isn't a number, and the imaginary > part of your complex number isn't really a factor in figuring out > where you're likely to end up with your multiplication. I guess that's > a justification for it coming out as NaN. By the time Python returns a result for inf+3j, you're already in trouble (or perhaps Python is already in trouble). A complex number has a real part and an imaginary part, and inf isn't real (i.e., it's not an element of ?). From jlgimeno71 at gmail.com Tue Jun 21 23:56:21 2016 From: jlgimeno71 at gmail.com (Jorge Gimeno) Date: Tue, 21 Jun 2016 20:56:21 -0700 Subject: Fwd: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: On Tue, Jun 21, 2016 at 8:40 PM, Elizabeth Weiss wrote: > Hi There, > > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. > > I think the parenthesis are confusing me. > > (False==False) or True > > This is True. Is it because False==False? And True==False is not True but > that does not change that this is True. > > If someone could please explain as I am teaching Python to myself and am > stuck on this that would be great. > Thank you for your help! > -- > https://mail.python.org/mailman/listinfo/python-list > You have 2 comparisons here . The first is inside the parenthesis, (False or True) evaluates to True. What remains of the expression is False == True, which is False. -Jorge (Reposted because I replied to the OP directly, instead of to the list) From ben+python at benfinney.id.au Tue Jun 21 23:59:10 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 22 Jun 2016 13:59:10 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: <85y45xx4a9.fsf@benfinney.id.au> Elizabeth Weiss writes: > Hi There, Welcome! Your questions are fine here, but you may like to know that we also have a beginner-specific forum for collaborative tutoring . > I am a little confused as to how this is False: > False==(False or True) > > I would think it is True because False==False is true. What does ?(False or True)? evaluate to, when you try it in the REPL? > I think the parenthesis are confusing me. > (False==False) or True > > This is True. Is it because False==False? And True==False is not True > but that does not change that this is True. Heh. You express the confusion quite well :-) Try the component expressions in the REPL (the interactive interpreter session) and see if that helps:: >>> False or True ? >>> (False or True) ? >>> True == False ? >>> (True == False) ? >>> False == False ? >>> (False == False) ? Then, once you think you understand what those expressions evaluate to, look again at how those results would work in a more complex expression:: >>> False == (False or True) ? >>> (False == False) or True ? > Thank you for your help! I hope that helps. -- \ ?[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.? | _o__) ?Douglas Adams | Ben Finney From ben+python at benfinney.id.au Wed Jun 22 00:02:03 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 22 Jun 2016 14:02:03 +1000 Subject: while Loops References: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> Message-ID: <85twglx45g.fsf@benfinney.id.au> Elizabeth Weiss writes: > Why is one of the results 5 since i=i+1? What do you think ?i = i + 1? means? (Asking because your idea of what that means may be affecting how you expect the loop to behave.) > Should the maximum result be 4 since 4 +1=5? Try ?thinking like the computer?: perform the steps yourself, reading each statement as though you are the computer. Keep a pad and pencil at hand, and make notes on what changes as you go through. See what you-as-computer actually emit onto the paper, and see whether that matches what the Python session produces. -- \ ?The difference between a moral man and a man of honor is that | `\ the latter regrets a discreditable act, even when it has worked | _o__) and he has not been caught.? ?Henry L. Mencken | Ben Finney From best_lay at yahoo.com Wed Jun 22 00:04:23 2016 From: best_lay at yahoo.com (Wildman) Date: Tue, 21 Jun 2016 23:04:23 -0500 Subject: while Loops References: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> Message-ID: On Tue, 21 Jun 2016 20:50:24 -0700, Elizabeth Weiss wrote: > i=1 > while i<=5: > print(i) > i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 since 4 +1=5? > > Thanks for your help! The operator '<=' means less than or equal. To get the results you are expecting, you need to use '<' only. i=1 while i<5: print(i) i=i+1 1 2 3 4 -- GNU/Linux user #557453 The cow died so I don't need your bull! From rustompmody at gmail.com Wed Jun 22 00:04:44 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Jun 2016 21:04:44 -0700 (PDT) Subject: while Loops In-Reply-To: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> References: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> Message-ID: <9e389f1b-f5b7-4ee1-bb2d-1506e49d28b6@googlegroups.com> On Wednesday, June 22, 2016 at 9:20:35 AM UTC+5:30, Elizabeth Weiss wrote: > i=1 > while i<=5: > print(i) > i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 since 4 +1=5? > Not sure what your question is But I guess you are being tripped up by a pervasive and confusing pun which you are inadvertently(?) using in one line: a> i = i+1 b> 4+1 = 5 a> is an assignment statement IN the programming language python b> is a math statement ABOUT python a> in math is meaningless (unless i is ? or something) b> in programming is a syntax error If you feel you are confused thats good; most professional programmers are more confused and dont know it. The predecessor of python -- ABC -- wrote i = i+1 as PUT i+1 IN i Unfortunately python followed the mainstream and confusified it to i=i+1 From torriem at gmail.com Wed Jun 22 00:11:28 2016 From: torriem at gmail.com (Michael Torrie) Date: Tue, 21 Jun 2016 22:11:28 -0600 Subject: while Loops In-Reply-To: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> References: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> Message-ID: On 06/21/2016 09:50 PM, Elizabeth Weiss wrote: > i=1 > while i<=5: > print(i) > i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 since 4 +1=5? > > Thanks for your help! If you trace the execution through in your mind it should be come clear. While always checks the expression first before running the body of the loop. If, during the loop body, i was 4, it is then incremented to 5. Now the top of the while loop checks the expression and since i is 5, 5<=5 is true (5 is less than or equal to 5), so the body runs now, and prints out the value and then increments i by 6, making it 6. Now at the top of the while loop, 6 is clearly not less than or equal to 5, so the loop terminates there. Hope this helps. From steve+comp.lang.python at pearwood.info Wed Jun 22 02:02:55 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 16:02:55 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: <576a2a12$0$1534$c3e8da3$5496439d@news.astraweb.com> On Wednesday 22 June 2016 13:40, Elizabeth Weiss wrote: > Hi There, > > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. Remember that parentheses are always evaluated first. So Python evaluates: False or True first, which evaluates as True. Then it evaluates False == True, which is obviously False. Why is "False or True" True? Well, consider this question: Who is allowed on the rides at the amusement park? - people over 18, regardless of their height; - people under 18, if they are "this tall" (4ft 6in) or greater. Is Fred (16 years old, and 5ft 6in tall) allowed on the ride? Only if: - he is over 18, or taller than "this tall"; - which is "False or True" - which is True Does that help? -- Steve From dieter at handshake.de Wed Jun 22 02:13:57 2016 From: dieter at handshake.de (dieter) Date: Wed, 22 Jun 2016 08:13:57 +0200 Subject: Cassandra multiprocessing can't pickle _thread.lock objects References: Message-ID: <878txx4uoq.fsf@handshake.de> Daiyue Weng writes: > ... > I tried to use Cassandra and multiprocessing to insert rows (dummy data) > concurrently based on the examples in > ... > self.pool = Pool(processes=process_count, initializer=self._setup, > initargs=(session,)) > > I am wondering how to resolve the issue. "pickle" is used to serialize Python objects and later, usually in a different context, recreate the object from the serialization. Obviously, some objects can be so tightly coupled to the context that it makes it very difficult to recreate them faithfully. Examples are locks and files. Apparently, your framework uses pickle internally (to get objects from the current processor to the executing processors). As a consequence, you must ensure that those objects contain only pickleable objects (and especially no locks). In your code above, the look might come from "self" or "session". In the first case, a workaround might be that you put the look on the class (rather than the object) level; this way, the look would not be pickled. The second case would be more difficult. Likely, you would need to extract pickleable subobjects from your "session" and maybe recreate a session object from them on the destination processor. From steve+comp.lang.python at pearwood.info Wed Jun 22 02:17:16 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 16:17:16 +1000 Subject: Unexpected NANs in complex arithmetic References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576a2d6d$0$11089$c3e8da3@news.astraweb.com> On Wednesday 22 June 2016 13:54, Dan Sommers wrote: > By the time Python returns a result for inf+3j, you're already in > trouble (or perhaps Python is already in trouble). I don't see why. It is possible to do perfectly sensible arithmetic on INFs. > A complex number has > a real part and an imaginary part, and inf isn't real (i.e., it's not an > element of ?). That's okay, because floats are not the set ?. -- Steve From pdorange at pas-de-pub-merci.mac.com Wed Jun 22 02:18:52 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Wed, 22 Jun 2016 08:18:52 +0200 Subject: [tkinter] widget size adjustment References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> <95ca9373-671a-4b8e-adeb-bd31d9c152eb@googlegroups.com> Message-ID: <1mp8kba.1qilng31w1mmcdN%pdorange@pas-de-pub-merci.mac.com> Rick Johnson wrote: > However, what do you expect your images to do when the > window is morphed: Stretch or Resize? Resize. The map image is a (small) portion of a virtual infitine map of the world (build throught downloading tiles images from tile map servers) : user can drag the map to see a different portion. So i except the map to be resized to show a bigger portion of the whole map : no streching. -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From pdorange at pas-de-pub-merci.mac.com Wed Jun 22 02:21:02 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Wed, 22 Jun 2016 08:21:02 +0200 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1mp8kh1.153tmc61yolko1N%pdorange@pas-de-pub-merci.mac.com> Steven D'Aprano wrote: > py> math.atan2(NAN, 0) > nan > > I think that the only way it will return a NAN is if passed a NAN. yes of course if you pass an invalid argument (NAN is not a real value, atan2 except coordinate x,y), the result would be invalid... -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From no.email at nospam.invalid Wed Jun 22 02:25:50 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 21 Jun 2016 23:25:50 -0700 Subject: Unexpected NANs in complex arithmetic References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> <576a2d6d$0$11089$c3e8da3@news.astraweb.com> Message-ID: <87wplhwxht.fsf@nightsong.com> Steven D'Aprano writes: >> By the time Python returns a result for inf+3j, you're already in >> trouble (or perhaps Python is already in trouble). > I don't see why. It is possible to do perfectly sensible arithmetic on INFs. We sometimes think of the real line extended by +/- inf, or the complex plane extended by a single point at infinity. I'm not sure how to do sensible arithmetic on a number like inf+3j, that doesn't treat it as the same number as inf+4j. From auriocus at gmx.de Wed Jun 22 02:26:30 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 22 Jun 2016 08:26:30 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: Am 22.06.16 um 05:40 schrieb Elizabeth Weiss: > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. > > I think the parenthesis are confusing me. Are you thinking, by any chance, that "or" indicates a choice? Comparing False to either False "or" True? That is not the case. "or" is an operator. "False or True" is *computed* and gives True, which is then compared to False by "==". Python works in these steps: 1) False == (False or True) 2) False == (True) 3) False Christian From rosuav at gmail.com Wed Jun 22 02:30:49 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jun 2016 16:30:49 +1000 Subject: Unexpected NANs in complex arithmetic In-Reply-To: <576a2d6d$0$11089$c3e8da3@news.astraweb.com> References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> <576a2d6d$0$11089$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jun 22, 2016 at 4:17 PM, Steven D'Aprano wrote: > On Wednesday 22 June 2016 13:54, Dan Sommers wrote: > >> By the time Python returns a result for inf+3j, you're already in >> trouble (or perhaps Python is already in trouble). > > I don't see why. It is possible to do perfectly sensible arithmetic on INFs. Technically, arithmetic on INF is a short-hand for a limit. What is inf+1? Well, it's the limit of x+1 as x tends toward +?, which is ?. So inf+1 evaluates to inf. >>> inf = float("inf") >>> inf+1 inf What's 5-inf? Same again - the limit of 5-x as x tends toward +?. That's tending in the opposite direction, so we get infinity the other way: >>> 5-inf -inf So it's not really "doing arithmetic on infinity", as such. That said, I'm not entirely sure why "inf+3j" means we're already in trouble - Dan, can you elaborate? ISTM you should be able to do limit-based arithmetic, just the same. ChrisA From steve+comp.lang.python at pearwood.info Wed Jun 22 02:58:37 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 16:58:37 +1000 Subject: Unexpected NANs in complex arithmetic References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576a3720$0$1522$c3e8da3$5496439d@news.astraweb.com> On Wednesday 22 June 2016 12:57, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 12:48 PM, Steven D'Aprano > wrote: >> I'm doing some arithmetic on complex numbers involving INFs, and getting >> unexpected NANs. >> >> py> INF = float('inf') >> py> z = INF + 3j >> py> z >> (inf+3j) >> py> -z >> (-inf-3j) >> >> So far, nothing unexpected has occurred. But: >> >> py> -1*z # should be the same as -z >> (-inf+nanj) >> >> >> And even more strange: >> >> py> 1*z >> (inf+nanj) >> >> >> >> Is this the right behaviour? If so, what's the justification for it? > > I've no idea, so I Googled StackExchange [1] and found this: > > http://math.stackexchange.com/questions/585766/what-is-infinity-in-complex- plane-and-what-are-operation-with-infinity-extended Not actually very helpful, since complex is not modelled on the extended complex numbers. The complex data type has a large but finite number of infinities: ?INF+0.1j, ?INF+0.2j, ?INF+0.3j, etc, and a large but finite number of NANs. The extended complex numbers has a single infinity, and no NANs. > Notably this: > > """ > To some extent, +?+? and ???? also play this role on the real axis: > they are not a destination, they are road signs that tell us to go in > a certain direction and never stop. > """ > > So when your real part is float("inf"), what you're really saying is > "Go as far as you possibly can in the positive direction, then keep > going (because you haven't run out of numbers yet), and tell me, what > is 1*z tending towards?". In Real ? and Complex ? arithmetic, 1*z must equal z for all z's, or else arithmetic is inconsistent and anything is possible. That also applies to the extended ? and ?, both of which have a single infinity. Since neither ? nor ? have anything like NANs, there's no problem there. In extended ?, we cannot distinguish between different infinities: the entire complex plane is bent around in a sphere so that all the "infinities" are at a single point. That is *not* what the complex() data type models: py> INF+2j == INF+3j # two distinct infinities (there are many more) False IEEE-754 floats are not ?, and INF does double-duty as "a really big but finite number which has overflowed", and "an actual infinity, whatever that means". So long as you remember that INF can mean either of those, you can usually reason about the behaviour of IEEE-754 INF. The complex() type should, I expect, be treated more or less as a two-tuple of z = (x, y) where x and y are both floats. So: 1*(x+yj) should equal (1*x) + (1*y)j, which is well-defined. If y is finite, 1*y should remain finite even if x is INF. I would understand if 1*(NAN+2j) returned NAN+NANj. I'd disagree, but understand. But it makes no sense to me to introduce a NAN into a calculation just because you multiply by 1, even if it includes an INF. And multiplying by -1 should be identical to negating. > Infinity isn't a number, and the imaginary > part of your complex number isn't really a factor in figuring out > where you're likely to end up with your multiplication. If you consider ?+2j, that's equivalent to: - starting at the origin, move up two spaces, then to the right forever; which is clearly not the same as ?-2j: - starting at the origin, move down two spaces, then to the right forever. That's because the complex() plane tries to model ? with-INFs-and-NANs (note plurals) rather than the extended Complex plane, a.k.a. the Riemann sphere. If complex() were modelled after the extended complex plane, then all complex numbers with ?INF as either the real or imaginary part should be considered equal: INF+2j == INF-2j == INF+INFj == -INF-INFj Putting a NAN in their certainly doesn't accomplish that. > I guess that's > a justification for it coming out as NaN. > > ChrisA > > [1] > [http://www.theallium.com/engineering/computer-programming-to-be-officially- renamed-googling-stackoverflow/ From steve+comp.lang.python at pearwood.info Wed Jun 22 03:05:40 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 17:05:40 +1000 Subject: Unexpected NANs in complex arithmetic References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> <576a3720$0$1522$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576a38c5$0$2781$c3e8da3$76491128@news.astraweb.com> On Wednesday 22 June 2016 16:58, Steven D'Aprano wrote: > But it makes no sense to me to introduce a NAN into a calculation > just because you multiply by 1, even if it includes an INF. And multiplying > by -1 should be identical to negating. Ah, not one second after I hit send, it struck me -- Python is casting the non- complex factor to complex before doing the multiplication! So: 1*(INF+2j) which I was expanding into (1*INF) + (1*2j) = (INF+2j), gets performed by Python as: (1+0j)*(INF+2j) = 1*INF + 1*2j + 0j*INF + 0j*2j = INF + 2j + NANj - 0 = INF + NANj -- Steve From antoon.pardon at rece.vub.ac.be Wed Jun 22 03:14:34 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 22 Jun 2016 09:14:34 +0200 Subject: Unexpected NANs in complex arithmetic In-Reply-To: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576A3ADA.5060000@rece.vub.ac.be> Op 22-06-16 om 04:48 schreef Steven D'Aprano: > I'm doing some arithmetic on complex numbers involving INFs, and getting > unexpected NANs. > > py> INF = float('inf') > py> z = INF + 3j > py> z > (inf+3j) > py> -z > (-inf-3j) > > So far, nothing unexpected has occurred. But: > > py> -1*z # should be the same as -z > (-inf+nanj) What I remember from complex numbers is that a multiplication with a number that has |z| = 1, is equivallent with a rotation. So you should be able to get the polar representation of this "number", add in the angle of -1, being ?, and convert back to the cartesian representation. I think seen this way, the nan part makes perfect sense. Also the multiplication of a+bj with c+dj is (ac-bd)+(ad+bc)j With your "numbers" this gives. (inf*(-1) - 3*0) + (inf*0 + 3*(-1))j Again the nan part makes perfect sense. -- Antoon From jussi.piitulainen at helsinki.fi Wed Jun 22 03:14:51 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 22 Jun 2016 10:14:51 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: Christian Gollwitzer writes: > Am 22.06.16 um 05:40 schrieb Elizabeth Weiss: >> I am a little confused as to how this is False: >> >> False==(False or True) >> >> I would think it is True because False==False is true. >> >> I think the parenthesis are confusing me. > > Are you thinking, by any chance, that "or" indicates a choice? > Comparing False to either False "or" True? That is not the case. > > "or" is an operator. "False or True" is *computed* and gives True, > which is then compared to False by "==". Python works in these steps: > > 1) False == (False or True) > 2) False == (True) > 3) False Similarly: 1) "coffee" == ("coffee" or "tea") 2) "coffee" == "coffee" 3) True 1) "tea" == ("coffee" or "tea") 2) "tea" == "coffee" 3) False In programming languages that allow it, want("coffee" or "tea") is probably not intended. One has to (want("coffee") or want("tea")). I'm not trying to confuse. I'm trying to further illustrate how the programming language notation differs from ordinary structures of languages like English that may seem analogous until one learns that they aren't, quite. From lawrencedo99 at gmail.com Wed Jun 22 03:42:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 00:42:10 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> On Wednesday, June 22, 2016 at 3:40:22 PM UTC+12, Elizabeth Weiss wrote: > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. > > I think the parenthesis are confusing me. No, it is the meanings of the boolean operators in Python. The rules are: * boolean operators don?t have to operate on boolean values. The language spec says: ?...the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.? I feel that?s a needlessly complicated rule. It would have been simpler if boolean operators (and conditional expressions like in if-statements and while-statements) only allowed values of boolean types. But that?s one of the few warts in the design of Python... * the meaning of ?A or B? is: ?return A if it evaluates to true, else return B?. Correspondingly, the meaning of ?A and B? is: ?return A if it evaluates to false, else return B?. Does that give you enough clues to understand what is going on? From lawrencedo99 at gmail.com Wed Jun 22 03:55:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 00:55:02 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <1df6872b-ac26-4ecc-b200-9e44a9e255cc@googlegroups.com> <87twgmtlpm.fsf@elektro.pacujo.net> <20160621144206.1ff4282a@bigbox.christie.dr> Message-ID: <9d02c176-6c76-49b7-829b-cf64a939944d@googlegroups.com> On Wednesday, June 22, 2016 at 7:50:50 AM UTC+12, Tim Chase wrote: > > I have a ~/.XCompose file that contains something like > > include "%L" > : "?" U1F616 # CONFOUNDED FACE >

: "?" U1F61B # FACE WITH > STUCK-OUT TONGUE

: "?" U1F61B # > FACE WITH STUCK-OUT TONGUE > > > The "include" pulls in the system-wide file, before adding my own > compose maps. You may find your custom XCompose is ignored by certain GUI apps. This is because the GUI toolkits they are using need to be told to pull it in (seems like XCompose is interpreted by the client side X toolkits, not the server side). So I put the following lines in my .bashrc: export GTK_IM_MODULE=xim export QT_IM_MODULE=xim From alister.ware at ntlworld.com Wed Jun 22 04:37:07 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 22 Jun 2016 08:37:07 GMT Subject: while Loops References: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> Message-ID: On Tue, 21 Jun 2016 20:50:24 -0700, Elizabeth Weiss wrote: > i=1 while i<=5: > print(i) > i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 > since 4 +1=5? > > Thanks for your help! check you loop condition while i lest than or equal to 5 so the loop will run for the case when i= 5 -- Welcome to Utah. If you think our liquor laws are funny, you should see our underwear! From miki.tebeka at gmail.com Wed Jun 22 04:38:47 2016 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 22 Jun 2016 01:38:47 -0700 (PDT) Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: On Tuesday, June 21, 2016 at 2:03:28 PM UTC+3, Pushpanth Gundepalli wrote: > Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. IMO you can do that at https://www.codecademy.com/learn/python From nick.a.sarbicki at gmail.com Wed Jun 22 04:45:34 2016 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Wed, 22 Jun 2016 08:45:34 +0000 Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: On Wed, Jun 22, 2016 at 9:42 AM Miki Tebeka wrote: > IMO you can do that at https://www.codecademy.com/learn/python > Some people might think differently but I wouldn't recommend a python course which teaches 2.7 over 3.x. It bugs me that learnpythonthehardway and codecademy - probably 2 of the biggest platforms for learning python at the moment - both refuse to move to python 3. From gokoproject at gmail.com Wed Jun 22 04:51:18 2016 From: gokoproject at gmail.com (John Wong) Date: Wed, 22 Jun 2016 04:51:18 -0400 Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: On Wed, Jun 22, 2016 at 4:45 AM, Nick Sarbicki wrote: > On Wed, Jun 22, 2016 at 9:42 AM Miki Tebeka wrote: > > > IMO you can do that at https://www.codecademy.com/learn/python > > > > Some people might think differently but I wouldn't recommend a python > course which teaches 2.7 over 3.x. > > pythontutor does support Python 3. Haven't tried CA for a while. From oscar.j.benjamin at gmail.com Wed Jun 22 05:18:36 2016 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 22 Jun 2016 10:18:36 +0100 Subject: Unexpected NANs in complex arithmetic In-Reply-To: <576A3ADA.5060000@rece.vub.ac.be> References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> <576A3ADA.5060000@rece.vub.ac.be> Message-ID: On 22 June 2016 at 08:14, Antoon Pardon wrote: > Op 22-06-16 om 04:48 schreef Steven D'Aprano: >> I'm doing some arithmetic on complex numbers involving INFs, and getting >> unexpected NANs. >> >> py> INF = float('inf') >> py> z = INF + 3j >> py> z >> (inf+3j) >> py> -z >> (-inf-3j) >> >> So far, nothing unexpected has occurred. But: >> >> py> -1*z # should be the same as -z >> (-inf+nanj) > > Also the multiplication of a+bj with c+dj is (ac-bd)+(ad+bc)j > With your "numbers" this gives. > > (inf*(-1) - 3*0) + (inf*0 + 3*(-1))j > > Again the nan part makes perfect sense. This explains presumably how complex multiplication is implemented although it's not really a mathematical justification. The problem is that mathematically complex numbers distribute over addition. Complex floats (i.e. Python's complex type) for the most part distribute approximately over addition so that the expansion Antoon refers to will usually be correct up to floating point error: (1) (x1 + j*y1) * (x2 + j*y2) ~= (x1*x2 - y1*y2) + j*(x1*y2 + x2*y1) We can think of this as applying the distribution rule twice twice (once for each pair of brackets). If the first complex number is real it should have zero real part i.e. y1 = 0. This leads to (2) (x1 + j*y1) * (x2 + j*y2) = x1 * (x2 + j*y2) = x1*x2 + j*x1*y2 which is I think the kind of formula Steve is expecting when being surprised above. However we also have using the full distributed formula (1): (3) (x1 + j*y1)*(x2 + j*y2) = x1*x2 - 0*y2 + j*(x1*y2 + x2*0) If y2 and x2 are real then the RHSs of (3) and (2) are equivalent. However in your example x2 is infinity. In essence the problem is that the set of numbers represented by Python's complex type is the set of complex numbers plus a few infinities/nans. The special values break the distributivity of addition so that the algebra implicit in the implementation of the complex type doesn't hold. To see that infinities/nans break distribution over addition consider: inf = inf*1 = inf*(3-2) = inf*3-inf*2 = inf-inf = nan If you did want to change these cases to match some particular idea of the infinities as limits then special casing for pure real or imaginary complex numbers (e.g. using (2) for complex numbers with zero imaginary part) would probably lead to the results Steve expects. I'm not really sure what the gain is though since we can't really do robust algebra with infinities anyway. -- Oscar From bc at freeuk.com Wed Jun 22 05:24:14 2016 From: bc at freeuk.com (BartC) Date: Wed, 22 Jun 2016 10:24:14 +0100 Subject: the global keyword: In-Reply-To: References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> Message-ID: On 22/06/2016 01:24, Rick Johnson wrote: > On Tuesday, June 21, 2016 at 6:16:09 PM UTC-5, BartC wrote: >> I tried using your method but it didn't work: > ...you'll find a thread i authored, that includes an object > exposing a global namespace named "G". Details of how to > inject the symbol G are included. After you have this module > installed, Oh, after you have that installed. Naturally I skipped straight to your code and got: NameError: global name 'G' is not defined > G.BDFL = "GvR" But even if it worked, I don't think this two-parter counts as a 'global variable' as it is understood. I might as well just create my own G module containing: BDFL="GvR" and import it in both A and B. Then I can also write G.BDFL in those modules. But remember the point was avoid having to write Test.test_var. (Perhaps your method dispenses with having to create such a module and to have to explicitly import it into each module.) -- Bartc From python.list at tim.thechases.com Wed Jun 22 07:09:32 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 22 Jun 2016 06:09:32 -0500 Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <9d02c176-6c76-49b7-829b-cf64a939944d@googlegroups.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <1df6872b-ac26-4ecc-b200-9e44a9e255cc@googlegroups.com> <87twgmtlpm.fsf@elektro.pacujo.net> <20160621144206.1ff4282a@bigbox.christie.dr> <9d02c176-6c76-49b7-829b-cf64a939944d@googlegroups.com> Message-ID: <20160622060932.0685ceac@bigbox.christie.dr> On 2016-06-22 00:55, Lawrence D?Oliveiro wrote: > On Wednesday, June 22, 2016 at 7:50:50 AM UTC+12, Tim Chase wrote: >> I have a ~/.XCompose file that contains something like > > You may find your custom XCompose is ignored by certain GUI apps. > This is because the GUI toolkits they are using need to be told to > pull it in (seems like XCompose is interpreted by the client side X > toolkits, not the server side). So I put the following lines in > my .bashrc: > > export GTK_IM_MODULE=xim > export QT_IM_MODULE=xim Ah, I knew that I'd had issues at some point with it not working but couldn't remember what I'd done to get it working. This was it. (grepping for "XCompose" in my config files didn't turn up anything) Thanks for adding the missing element. -tkc From mal at europython.eu Wed Jun 22 08:31:03 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 22 Jun 2016 14:31:03 +0200 Subject: EuroPython 2016 Conference App - Ready for installation Message-ID: <576A8507.7040109@europython.eu> We are proud to announce our very own mobile app for the EuroPython 2016 conference: *** EuroPython 2016 Conference App *** https://ep2016.europython.eu/en/events/conference-app/ Engage with the conference and its attendees -------------------------------------------- The mobile app gives you access to the conference schedule (even offline), helps you in planing your conference experience and provides a rich social engagement platform for all attendees. You can create a profile within the app (or link this to your existing social accounts), share messages and photos, and easily reach out to other fellow attendees. Vital for all EuroPython attendees ---------------------------------- We?d like to make use of the app to keep you updated by sending regular updates of the schedule and inform you of important announcements via push notifications, so please consider downloading it. Thanks. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/745593770561933313 Thanks. From steve at pearwood.info Wed Jun 22 09:23:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 23:23:52 +1000 Subject: EuroPython 2016 Conference App - Ready for installation References: <576A8507.7040109@europython.eu> Message-ID: <576a9169$0$1584$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Jun 2016 10:31 pm, M.-A. Lemburg wrote: > You can create a profile within the app (or link this to your existing > social accounts), share messages and photos, and easily reach out to > other fellow attendees. o_O I have no words. -- Steven From steve at pearwood.info Wed Jun 22 09:27:58 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 22 Jun 2016 23:27:58 +1000 Subject: Is signed zero always available? Message-ID: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> Both IEEE-754 floats and Decimals support signed zeroes, that is -0.0 and 0.0 are two distinct (but equal) values. (There is only one int zero: -0 and 0 are the same value.) Signed Decimal zero should always be available. What about signed float zero? Are there any platforms where Python is available that don't support signed zeroes? -- Steven From random832 at fastmail.com Wed Jun 22 10:10:38 2016 From: random832 at fastmail.com (Random832) Date: Wed, 22 Jun 2016 10:10:38 -0400 Subject: Operator Precedence/Boolean Logic In-Reply-To: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: <1466604638.4113235.645273577.469F2790@webmail.messagingengine.com> On Tue, Jun 21, 2016, at 23:40, Elizabeth Weiss wrote: > Hi There, > > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. "False or True" is True, and then it reduces to "False == True" which is false. There's no "x == (y or z)" construct to compare x separately to both y and z, the "or" will evaluate to the first one that's true and then is used in the rest of the expression. If you wanted to write "x == y or x == z" with only a single x, you'd do "x in (y, z)". From grant.b.edwards at gmail.com Wed Jun 22 10:19:32 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 22 Jun 2016 14:19:32 +0000 (UTC) Subject: Is signed zero always available? References: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-22, Steven D'Aprano wrote: > Both IEEE-754 floats and Decimals support signed zeroes, that is -0.0 and > 0.0 are two distinct (but equal) values. > > (There is only one int zero: -0 and 0 are the same value.) Is that guaranteed by Python, or just a side-effect of the implementation? Back in the days when Python used native C integers I think the latter. Now that Python implements it's own arbitrary-length ints, it may be the former. > Signed Decimal zero should always be available. What about signed float > zero? Are there any platforms where Python is available that don't support > signed zeroes? -- Grant Edwards grant.b.edwards Yow! This ASEXUAL PIG at really BOILS my BLOOD gmail.com ... He's so ... so ... URGENT!! From random832 at fastmail.com Wed Jun 22 10:34:48 2016 From: random832 at fastmail.com (Random832) Date: Wed, 22 Jun 2016 10:34:48 -0400 Subject: Is signed zero always available? In-Reply-To: References: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1466606088.4117582.645299713.03DA7658@webmail.messagingengine.com> On Wed, Jun 22, 2016, at 10:19, Grant Edwards wrote: > Is that guaranteed by Python, or just a side-effect of the > implementation? Back in the days when Python used native C integers I > think the latter. AIUI, native C integers have never reliably supported signed zero even with representations that naively seem to have it. There's no well-defined way to detect it - no int version of copysign, for instance - and implementations are free to erase the distinction on every load/store or define one of them to be a trap representation. From jsutar at gmail.com Wed Jun 22 10:46:35 2016 From: jsutar at gmail.com (Jignesh Sutar) Date: Wed, 22 Jun 2016 14:46:35 +0000 Subject: Summary grid Message-ID: Say I have list of data as given in the example code below, I want to find all the unique categories (alphabetic letters) and unique IDs (numbers) and then produce a summary grid as manually entered in the "results". How could I code this? Many thanks in advance, Jignesh data= ["A.1", "A.2", "A.3", "B.1", "C.2", "C.3", "D.4", "E.5", "E.6"] cols=[] rows=[] for item in data: i=item.split(".") if i[0] not in cols: cols.append(i[0]) if i[1] not in rows: rows.append(i[1]) print cols print rows results= [["Row/Col", "A", "B", "C", "D", "E"], [1, 1, 1, 0, 0, 0], [2, 1, 0, 1, 0, 0], [3, 1, 0, 1, 0, 0], [4, 0, 0, 0, 1, 0], [5, 0, 0, 0, 0, 1], [6, 0, 0, 0, 0, 1]] From grant.b.edwards at gmail.com Wed Jun 22 10:59:48 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 22 Jun 2016 14:59:48 +0000 (UTC) Subject: Is signed zero always available? References: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> <1466606088.4117582.645299713.03DA7658@webmail.messagingengine.com> Message-ID: On 2016-06-22, Random832 wrote: > On Wed, Jun 22, 2016, at 10:19, Grant Edwards wrote: > >> Is that guaranteed by Python, or just a side-effect of the >> implementation? Back in the days when Python used native C >> integers I think the latter. > > AIUI, native C integers have never reliably supported signed zero > even with representations that naively seem to have it. There's no > well-defined way to detect it - no int version of copysign, for > instance - and implementations are free to erase the distinction on > every load/store or define one of them to be a trap representation. It's been almost 25 years since I used hardware that supported signed zero integers (CDC 6600). I don't recall there being a C compiler available. We used Pascal and assembly, though I think FORTRAN was what most people used. I don't recall whether the Pascal implementation exposed the existence of -0 to the user or not. I'm pretty certain there wasn't a Python implementation... -- Grant Edwards grant.b.edwards Yow! Loni Anderson's hair at should be LEGALIZED!! gmail.com From ben.usenet at bsb.me.uk Wed Jun 22 11:34:14 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 22 Jun 2016 16:34:14 +0100 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d1n9kzk9.fsf@bsb.me.uk> Steven D'Aprano writes: > On Wed, 22 Jun 2016 04:01 am, Pierre-Alain Dorange wrote: >> I do not know under what circumstance atan2 can return NAN, atan2 taks 2 >> argument (y and x) and return the angle corresponding to y/x. >> If x is 0.0, atan2 return 0.0 (do not try to make the division). > > py> math.atan2(NAN, 0) > nan > > I think that the only way it will return a NAN is if passed a NAN. That seems to be the case but I was a little surprised to find that >>> math.atan2(INF, INF) 0.7853981633974483 I would have expected NaN since atan2(INF, INF) could be thought of as the limit of atan2(x, y) which could be any value in the range. And I'd have guessed atan2(0, 0) would have been NaN too but >>> math.atan2(0, 0) 0.0 -- Ben. From jussi.piitulainen at helsinki.fi Wed Jun 22 11:43:19 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 22 Jun 2016 18:43:19 +0300 Subject: Summary grid References: Message-ID: Jignesh Sutar writes: > Say I have list of data as given in the example code below, I want to find > all the unique categories (alphabetic letters) and unique IDs (numbers) and > then produce a summary grid as manually entered in the "results". How could > I code this? > > Many thanks in advance, > Jignesh > > > data= ["A.1", "A.2", "A.3", "B.1", "C.2", "C.3", "D.4", "E.5", "E.6"] > > cols=[] > rows=[] > for item in data: > i=item.split(".") > if i[0] not in cols: cols.append(i[0]) > if i[1] not in rows: rows.append(i[1]) Instead of indexing, consider: it, em = item.split(".") (Except with names like col, row :) > print cols > print rows > > results= > [["Row/Col", "A", "B", "C", "D", "E"], > [1, 1, 1, 0, 0, 0], > [2, 1, 0, 1, 0, 0], > [3, 1, 0, 1, 0, 0], > [4, 0, 0, 0, 1, 0], > [5, 0, 0, 0, 0, 1], > [6, 0, 0, 0, 0, 1]] Once you have the column, row name, the key structure will be nested loops. Each row is constructed by looping over the column names. The table itself is constructed by looping over the row names. The following counts the items with collections.Counter, which should be good for you to know about, and extracts the names from the keys. (A key cannot be a list but it can be a tuple; the original string would also work.) Then it's efficient to find out how many times an item occurred. You *can* do that by querying your original list, but that will be slower if the list is long. A Counter is a special kind of dict. This program uses Python 3 (you are still on 2) and higher-level idiom than yours, hides the crucial nested loop inside list comprehensions, and doesn't include the names in the resulting table, but you should get the idea and adapt. from collections import Counter contents = Counter(tuple(datum.split('.')) for datum in data) colnames = sorted(set(k for k, r in contents.keys())) rownames = sorted(set(r for k, r in contents.keys())) table = [[contents[k, r] for k in colnames] for r in rownames] for r, row in zip(rownames, table): print(r, row) From __peter__ at web.de Wed Jun 22 11:44:04 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Jun 2016 17:44:04 +0200 Subject: Summary grid References: Message-ID: Jignesh Sutar wrote: > Say I have list of data as given in the example code below, I want to find > all the unique categories (alphabetic letters) and unique IDs (numbers) > and then produce a summary grid as manually entered in the "results". How > could I code this? > > Many thanks in advance, > Jignesh > > > data= ["A.1", "A.2", "A.3", "B.1", "C.2", "C.3", "D.4", "E.5", "E.6"] > > cols=[] > rows=[] > for item in data: > i=item.split(".") > if i[0] not in cols: cols.append(i[0]) > if i[1] not in rows: rows.append(i[1]) > > print cols > print rows > > results= > [["Row/Col", "A", "B", "C", "D", "E"], > [1, 1, 1, 0, 0, 0], > [2, 1, 0, 1, 0, 0], > [3, 1, 0, 1, 0, 0], > [4, 0, 0, 0, 1, 0], > [5, 0, 0, 0, 0, 1], > [6, 0, 0, 0, 0, 1]] $ cat pivot_jignesh.py def add(x, y): return x + y def pivot( data, accu=add, default=0, empty=0, origin=""): rows = {} columnkeys = set() for rowkey, columnkey, value in data: column = rows.setdefault(rowkey, {}) column[columnkey] = accu(column.get(columnkey, default), value) columnkeys.add(columnkey) columnkeys = sorted(columnkeys) result = [ [origin] + columnkeys ] for rowkey in sorted(rows): row = rows[rowkey] result.append([rowkey] + [row.get(ck, empty) for ck in columnkeys]) return result if __name__ == "__main__": import pprint data = ["A.1", "A.2", "A.3", "B.1", "C.2", "C.3", "D.4", "E.5", "E.6"] data = (item.split(".") for item in data) data = ((int(row), column, 1) for column, row in data) pprint.pprint(pivot(data, origin="Row/Col")) $ python pivot_jignesh.py [['Row/Col', 'A', 'B', 'C', 'D', 'E'], [1, 1, 1, 0, 0, 0], [2, 1, 0, 1, 0, 0], [3, 1, 0, 1, 0, 0], [4, 0, 0, 0, 1, 0], [5, 0, 0, 0, 0, 1], [6, 0, 0, 0, 0, 1]] $ From gordon at panix.com Wed Jun 22 12:03:02 2016 From: gordon at panix.com (John Gordon) Date: Wed, 22 Jun 2016 16:03:02 +0000 (UTC) Subject: while Loops References: <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> Message-ID: In <0cf9a94e-b84c-460d-b03d-edf6a941adc0 at googlegroups.com> Elizabeth Weiss writes: > Why is one of the results 5 since i=i+1? Should the maximum result > be 4 since 4 +1=5? "while i<=5" means "while i is less than or equal to 5". So the loop will keep going at 5, and only stop when i is 6. -- 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 random832 at fastmail.com Wed Jun 22 12:19:46 2016 From: random832 at fastmail.com (Random832) Date: Wed, 22 Jun 2016 12:19:46 -0400 Subject: Can math.atan2 return INF? In-Reply-To: <87d1n9kzk9.fsf@bsb.me.uk> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> Message-ID: <1466612386.4142308.645389729.149CF4CD@webmail.messagingengine.com> On Wed, Jun 22, 2016, at 11:34, Ben Bacarisse wrote: > Steven D'Aprano writes: > > I think that the only way it will return a NAN is if passed a NAN. > > That seems to be the case but I was a little surprised to find that > > >>> math.atan2(INF, INF) > 0.7853981633974483 > > I would have expected NaN since atan2(INF, INF) could be thought of as > the limit of atan2(x, y) which could be any value in the range. And I'd > have guessed atan2(0, 0) would have been NaN too but > > >>> math.atan2(0, 0) > 0.0 In C, the result of atan2(0, 0) [for any sign of zero] may be implementation-dependent: "A domain error may occur if both arguments are zero." In CPython, though, they're explicitly handled as special cases by the m_atan2 function. The results match that of the x87 FPATAN instruction, and presumably the IEEE standard (the same results are prescribed in the IEC 60559 appendix of the C standard) http://www.charlespetzold.com/blog/2008/09/180741.html mentions Intel's rationale (in short, it's because 0+0j is a real number). From jeanmichel at sequans.com Wed Jun 22 12:20:37 2016 From: jeanmichel at sequans.com (jmp) Date: Wed, 22 Jun 2016 18:20:37 +0200 Subject: Summary grid In-Reply-To: References: Message-ID: On 06/22/2016 04:46 PM, Jignesh Sutar wrote: > Say I have list of data as given in the example code below, I want to find > all the unique categories (alphabetic letters) and unique IDs (numbers) and > then produce a summary grid as manually entered in the "results". How could > I code this? > > Many thanks in advance, > Jignesh > > > data= ["A.1", "A.2", "A.3", "B.1", "C.2", "C.3", "D.4", "E.5", "E.6"] > > cols=[] > rows=[] > for item in data: > i=item.split(".") > if i[0] not in cols: cols.append(i[0]) > if i[1] not in rows: rows.append(i[1]) > > print cols > print rows > > results= > [["Row/Col", "A", "B", "C", "D", "E"], > [1, 1, 1, 0, 0, 0], > [2, 1, 0, 1, 0, 0], > [3, 1, 0, 1, 0, 0], > [4, 0, 0, 0, 1, 0], > [5, 0, 0, 0, 0, 1], > [6, 0, 0, 0, 0, 1]] > Easily done using only builtins and list comprehension: data= ["A.1", "A.2", "A.3", "B.1", "C.2", "C.3", "D.4", "E.5", "E.6"] # python magic with the "zip" function # "set" will take care of removing duplicates categories, ids = map(set, zip(*[d.split('.') for d in data])) results = [] for id_ in sorted(map(int,ids)): results.append([data.count("%s.%d" % (cat, id_)) for cat in sorted(categories)]) print results If you don't really understand the zip function: http://nedbatchelder.com/text/iter.html The whole presentation is worth reading. Cheers, Jm From 8smolen at tds.net Wed Jun 22 12:41:34 2016 From: 8smolen at tds.net (Michael Smolen) Date: Wed, 22 Jun 2016 10:41:34 -0600 Subject: Setting up Python WinXP Message-ID: <9A23634ACEF945E0A0370DE977E54348@mike> Folks: I can't wait to start programming with Python. However, I am having difficulty installing on my XP operating system. I downloaded Python-3.4.5ci as that seems like the version that will run on my operating system. The latest version will not as per mention on the website. I downloaded the compacted version (*.tar), converted it to a *.tgz and extracted the software into a folder Python-3.4.5ci. That subdirectory contains numerous files (11) and 13 subdirectories. The README file states that "On Windows, see PCbuild/readme.txt.". That link was not found. So, I am clueless on what I need to do to successfully install Python3.4 on my computer. Any advice would be greatly appreciated. mike From jrgulizia at scola.org Wed Jun 22 12:59:49 2016 From: jrgulizia at scola.org (Joe Gulizia) Date: Wed, 22 Jun 2016 16:59:49 +0000 Subject: OT?: Where can I find python programming material in different languages? Message-ID: Potentially Off Topic I am looking for python programming related blogs, papers, videos in Swahili, Tagalog, Somali, Javanese (Indonesian?), Lithuanian, Pashto, Bulgarian, Farsi, Amharic, Georgian, Kazakh, and Tamil. Although blogs are not online I am looking for material that is not easily and freely available via the Web (or requires a subscription). I found the Python in languages other than English lists....Would those be the best places to start? Thank you From bc at freeuk.com Wed Jun 22 13:10:14 2016 From: bc at freeuk.com (BartC) Date: Wed, 22 Jun 2016 18:10:14 +0100 Subject: Setting up Python WinXP In-Reply-To: References: <9A23634ACEF945E0A0370DE977E54348@mike> Message-ID: On 22/06/2016 17:41, Michael Smolen wrote: > Folks: > I can't wait to start programming with Python. However, I am having difficulty installing on my XP operating system. I downloaded Python-3.4.5ci as that seems like the version that will run on my operating system. The latest version will not as per mention on the website. I downloaded the compacted version (*.tar), converted it to a *.tgz and extracted the software into a folder Python-3.4.5ci. That subdirectory contains numerous files (11) and 13 subdirectories. The README file states that "On Windows, see PCbuild/readme.txt.". That link was not found. > > So, I am clueless on what I need to do to successfully install Python3.4 on my computer. Any advice would be greatly appreciated. > mike > If you've got .tar and .tgz files then that doesn't sound like a Windows binary. (I assume you want to download a ready-to-run binary release and not try and build it from sources which I understand is not trivial.) Google for 'python download for windows'. You're looking for a self-installing executable or a .msi file. -- Bartc From irmen.NOSPAM at xs4all.nl Wed Jun 22 13:13:54 2016 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 22 Jun 2016 19:13:54 +0200 Subject: Setting up Python WinXP In-Reply-To: References: <9A23634ACEF945E0A0370DE977E54348@mike> Message-ID: <576ac753$0$5815$e4fe514c@news.xs4all.nl> On 22-6-2016 18:41, Michael Smolen wrote: > Folks: > I can't wait to start programming with Python. However, I am having difficulty installing on my XP operating system. I downloaded Python-3.4.5ci as that seems like the version that will run on my operating system. The latest version will not as per mention on the website. I downloaded the compacted version (*.tar), converted it to a *.tgz and extracted the software into a folder Python-3.4.5ci. That subdirectory contains numerous files (11) and 13 subdirectories. The README file states that "On Windows, see PCbuild/readme.txt.". That link was not found. > > So, I am clueless on what I need to do to successfully install Python3.4 on my computer. Any advice would be greatly appreciated. > mike > Don't try to install from the source archive which it seems you have downloaded. Get the MSI installer instead from https://www.python.org/downloads/windows/ I think you want to get the Python 3.4.3 "windows x86 msi installer", its about one third down the page. That being said, you probably already noticed that to stay with the game, XP isn't going to cut it anymore as it is no longer supported by Microsoft. Irmen From pdorange at pas-de-pub-merci.mac.com Wed Jun 22 13:18:02 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Wed, 22 Jun 2016 19:18:02 +0200 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> Message-ID: <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> Ben Bacarisse wrote: > >>> math.atan2(INF, INF) > 0.7853981633974483 > > I would have expected NaN since atan2(INF, INF) could be thought of as > the limit of atan2(x, y) which could be any value in the range. And I'd > have guessed atan2(0, 0) would have been NaN too but i'm not a math expert, but the limit of atan2 would be 45?, so pi/4 radians (0,7854). As x,y are coordinates, the both infinite would tend toward 45?. x only infinite would be 0? (0 radians) y only infinite woudl be 180? (pi/2 radians) -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From zachary.ware+pylist at gmail.com Wed Jun 22 13:19:17 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 22 Jun 2016 12:19:17 -0500 Subject: Setting up Python WinXP In-Reply-To: <9A23634ACEF945E0A0370DE977E54348@mike> References: <9A23634ACEF945E0A0370DE977E54348@mike> Message-ID: Hi Michael, On Wed, Jun 22, 2016 at 11:41 AM, Michael Smolen <8smolen at tds.net> wrote: > Folks: > I can't wait to start programming with Python. Welcome to Python! > However, I am having difficulty installing on my XP operating system. This unsolicited advice is rather beside the point, but I would highly recommend moving away from XP if you have any say in the matter. Linux Mint (or other distro of your choice) is easy to install and use, is free in whatever sense of the word you'd like to use, and will be much more secure than XP, which is no longer supported by Microsoft (this is why it's not supported by Python 3.5+, either). An upgrade to a newer version of Windows is also a good idea, but more costly. > I downloaded Python-3.4.5ci I'm not sure what you mean by 3.4.5ci; do you mean 3.4.5rc1? 3.4.5rc1 is pre-release software; 3.4.5 will be released in a week or so. However, it won't include binary installers for Windows since Python 3.4 is now in security-fix-only mode. > as that seems like the version that will run on my operating system. The latest version will not as per mention on the website. I downloaded the compacted version (*.tar), converted it to a *.tgz and extracted the software into a folder Python-3.4.5ci. That subdirectory contains numerous files (11) and 13 subdirectories. The README file states that "On Windows, see PCbuild/readme.txt.". That link was not found. > > So, I am clueless on what I need to do to successfully install Python3.4 on my computer. Any advice would be greatly appreciated. If you're stuck with XP, stick with Python 3.4.4, and download the installer from here: https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi Hope this helps, -- Zach From pdorange at pas-de-pub-merci.mac.com Wed Jun 22 13:42:44 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Wed, 22 Jun 2016 19:42:44 +0200 Subject: [tkinter] widget size adjustment References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <1mp9f05.15v6sv1tfesoiN%pdorange@pas-de-pub-merci.mac.com> Christian Gollwitzer wrote: > Perhaps your assumption is wrong. Maybe the canvas itself *is* resized, > so the white space you see around the image is the background of the > canvas. To test this easily, set a strong color for the background: > > blabla = tk.Canvas(..., bg='red') > > You should see red space appear when you resize the window. If you see > white space, then the options are not set properly and the canvas is not > resized. I've allready a background by not displayed, so the canvas is not automatilly resized. > > I assume that you want the following: Upon resizing the main window, the > map image should be stretched to fill the space, right? Then you'll have > to do that on your own. First, bind a Configure event to the canvas > > canvas.bind('', callback) I do this, the callback is called when window was resized, but unfortunnally i was not able to get the "available space (in pixels)". event.width and event.height just return the actual canvas size... not useful canvas.winfo_width() return the actual canvas size... not useful just note that it works when user resize down, the returned values correspond to the visual portion of the canvas. But do not work when enlarge... canvas.winfo_reqwidth() just return the size when the canvas was originally created... not useful... > > The callback functino now gets called when the canvas needs to be > redrawn. In that callback function, you get the new width and height > from the event object. Resize the image accordingly (using a PIL function). I miss something, here event.width just return me the canvas size, not resized... The full code was on github : the tkinter code is in pmx.py the canvas class was TMap GUI was created in main_gui.__init__() callback function was main_gui.resize() -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From rosuav at gmail.com Wed Jun 22 14:09:58 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jun 2016 04:09:58 +1000 Subject: OT?: Where can I find python programming material in different languages? In-Reply-To: References: Message-ID: On Thu, Jun 23, 2016 at 2:59 AM, Joe Gulizia wrote: > Potentially Off Topic > Not at all off topic! A very reasonable question. > > I am looking for python programming related blogs, papers, videos in Swahili, Tagalog, Somali, Javanese (Indonesian?), Lithuanian, Pashto, Bulgarian, Farsi, Amharic, Georgian, Kazakh, and Tamil. Although blogs are not online I am looking for material that is not easily and freely available via the Web (or requires a subscription). I found the Python in languages other than English lists....Would those be the best places to start? > Here's a good start: https://wiki.python.org/moin/Languages The Python wiki tries to maintain a list of these kinds of things. ChrisA From ben.usenet at bsb.me.uk Wed Jun 22 15:17:22 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 22 Jun 2016 20:17:22 +0100 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <87inx1janx.fsf@bsb.me.uk> pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes: > Ben Bacarisse wrote: > >> >>> math.atan2(INF, INF) >> 0.7853981633974483 >> >> I would have expected NaN since atan2(INF, INF) could be thought of as >> the limit of atan2(x, y) which could be any value in the range. And I'd >> have guessed atan2(0, 0) would have been NaN too but > > i'm not a math expert, but the limit of atan2 would be 45?, so pi/4 > radians (0,7854). > As x,y are coordinates, the both infinite would tend toward 45?. The limit of atan2(x, x) is as you describe, but there is no reason to pick that one case. lim{x->oo,y->oo}atan2(x, y) is undefined unless a relationship is given between x and y and you get get any result you like in the range of atan2 by choosing one or other relationship. -- Ben. From python at lucidity.plus.com Wed Jun 22 15:43:46 2016 From: python at lucidity.plus.com (Erik) Date: Wed, 22 Jun 2016 20:43:46 +0100 Subject: Operator Precedence/Boolean Logic In-Reply-To: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: <576AEA72.1040904@lucidity.plus.com> On 22/06/16 04:40, Elizabeth Weiss wrote: > I am a little confused as to how this is False: > > False==(False or True) Other people have explained why the expression evaluates as it does - the sub-expression "False or True" evaluates to True (as one of the operands is truthy). Your expression then becomes "False == True", which is of course false. To get the construct you were expecting (is the thing on the left hand side equal to one of the things on the right hand side), you can use Python's "in" keyword to "search" a collection (list, tuple, set, dictionary etc) that contains the things you are trying to match: >>> False in (False, True) # tuple >>> False in [False, True] # list >>> False in {False, True} # set >>> False in {False: None, True: None} # dict HTH, E. From lawrencedo99 at gmail.com Wed Jun 22 15:50:50 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 12:50:50 -0700 (PDT) Subject: Can math.atan2 return INF? In-Reply-To: <87inx1janx.fsf@bsb.me.uk> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> Message-ID: On Thursday, June 23, 2016 at 7:17:37 AM UTC+12, Ben Bacarisse wrote: > The limit of atan2(x, x) is as you describe, but there is no reason to > pick that one case. It?s what?s called a ?non-removable discontinuity?. The value you pick at that point will be consistent with approaching it from one particular direction, not from any other. From auriocus at gmx.de Wed Jun 22 16:18:12 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 22 Jun 2016 22:18:12 +0200 Subject: [tkinter] widget size adjustment In-Reply-To: <1mp9f05.15v6sv1tfesoiN%pdorange@pas-de-pub-merci.mac.com> References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> <1mp9f05.15v6sv1tfesoiN%pdorange@pas-de-pub-merci.mac.com> Message-ID: Am 22.06.16 um 19:42 schrieb Pierre-Alain Dorange: > Christian Gollwitzer wrote: > >> Perhaps your assumption is wrong. Maybe the canvas itself *is* resized, >> so the white space you see around the image is the background of the >> canvas. To test this easily, set a strong color for the background: >> >> blabla = tk.Canvas(..., bg='red') >> >> You should see red space appear when you resize the window. If you see >> white space, then the options are not set properly and the canvas is not >> resized. > > I've allready a background by not displayed, so the canvas is not > automatilly resized. If you do not see the background, then indeed the canvas is not resized, which means the gridding options are wrong. Looking at your code, I see this: self.map.grid(row=1,column=1,rowspan=4,columnspan=2,padx=2,pady=2) Here, you do not specify any sticky options, which means it should default to centering. Try adding NSEW sticky options. >> I assume that you want the following: Upon resizing the main window, the >> map image should be stretched to fill the space, right? Then you'll have >> to do that on your own. First, bind a Configure event to the canvas >> >> canvas.bind('', callback) > > I do this, the callback is called when window was resized, but > unfortunnally i was not able to get the "available space (in pixels)". > > event.width and event.height just return the actual canvas size... not > useful This is a consequence of the missing grid options. On resize, the canvas is only moved which also triggers the Configure event. If you set the grid options correctly, you should get the new size. You will then need to compute an updated image. Christian From pdorange at pas-de-pub-merci.mac.com Wed Jun 22 16:53:08 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Wed, 22 Jun 2016 22:53:08 +0200 Subject: [tkinter] widget size adjustment References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> <1mp9f05.15v6sv1tfesoiN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <1mp9ou7.1ifps191o2fj76N%pdorange@pas-de-pub-merci.mac.com> Christian Gollwitzer wrote: > > If you do not see the background, then indeed the canvas is not resized, > which means the gridding options are wrong. Looking at your code, I see > this: > > self.map.grid(row=1,column=1,rowspan=4,columnspan=2,padx=2,pady=2) > > Here, you do not specify any sticky options, which means it should > default to centering. Try adding NSEW sticky options. That's magic ! It works just fine... If i do understand NSEW sticky option make the widget autoadjust to the available space. The default option is just CENTERED... I do not explore this, i just thought NSEW was also CENTERED. Many Thanks. -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From auriocus at gmx.de Wed Jun 22 17:05:39 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 22 Jun 2016 23:05:39 +0200 Subject: [tkinter] widget size adjustment In-Reply-To: <1mp9ou7.1ifps191o2fj76N%pdorange@pas-de-pub-merci.mac.com> References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> <1mp9f05.15v6sv1tfesoiN%pdorange@pas-de-pub-merci.mac.com> <1mp9ou7.1ifps191o2fj76N%pdorange@pas-de-pub-merci.mac.com> Message-ID: Am 22.06.16 um 22:53 schrieb Pierre-Alain Dorange: > Christian Gollwitzer wrote: >> If you do not see the background, then indeed the canvas is not resized, >> which means the gridding options are wrong. Looking at your code, I see >> this: >> >> self.map.grid(row=1,column=1,rowspan=4,columnspan=2,padx=2,pady=2) >> >> Here, you do not specify any sticky options, which means it should >> default to centering. Try adding NSEW sticky options. > > That's magic ! > It works just fine... :) > If i do understand NSEW sticky option make the widget autoadjust to the > available space. The default option is just CENTERED... I do not explore > this, i just thought NSEW was also CENTERED. IMHO the sticky options in grid are actually very intuitive, once you understand them. The widget gets "pinned" on each side that is mentioned in the sticky set. If it is not pinned in one direction, then it is centered. So, for instance sticky=N means pin it on top (North), but neither south, east nor west. This means, the widget is aligned to the top of the cell and centered in left-right direction, but does not resize. Whereas, sticky=NS means pin it north and south, which is stretching in vertical direction to fill the height, center in left-right. sticky=NSEW pins it at all four sides which consequently stretches it in both directions. BTW, the Tkinter wrapper is a bit clumsy for this option. In the original Tk, the sticky option is just a string. You can still pass that and do sticky='nsew' instead of the clumsy sticky=Tkinter.N+Tkinter.S+Tkinter.E+Tkinter.W Christian From 8smolen at tds.net Wed Jun 22 17:16:02 2016 From: 8smolen at tds.net (Michael Smolen) Date: Wed, 22 Jun 2016 15:16:02 -0600 Subject: Zachary, Iremen, and BartC Message-ID: <8E8E4CC713B94EB7A2CE2037FB5CD8DF@mike> Thanks!!! With your advice and suggestions I finally got Python installed. I used windows x86 MS Installer and it worked with three clicks. Thanks again, and again, and .... mike From zachary.ware+pylist at gmail.com Wed Jun 22 17:18:29 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 22 Jun 2016 16:18:29 -0500 Subject: [tkinter] widget size adjustment In-Reply-To: References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> <1mp9f05.15v6sv1tfesoiN%pdorange@pas-de-pub-merci.mac.com> <1mp9ou7.1ifps191o2fj76N%pdorange@pas-de-pub-merci.mac.com> Message-ID: On Wed, Jun 22, 2016 at 4:05 PM, Christian Gollwitzer wrote: > BTW, the Tkinter wrapper is a bit clumsy for this option. In the original > Tk, the sticky option is just a string. You can still pass that and do > > sticky='nsew' > > instead of the clumsy > > sticky=Tkinter.N+Tkinter.S+Tkinter.E+Tkinter.W There are constants in tkinter for this: NSEW, NS, NE, NW, SE, SW, and EW. -- Zach From lawrencedo99 at gmail.com Wed Jun 22 17:20:47 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 14:20:47 -0700 (PDT) Subject: value of pi and 22/7 In-Reply-To: <96idnWw48cOA8PXKnZ2dnUU7-N2dnZ2d@giganews.com> References: <91940d31-1ff4-4267-9b07-445eca35d234@googlegroups.com> <1466221708.3660642.641268921.0131CAF9@webmail.messagingengine.com> <593039af-b15b-4186-9784-a8a4e7da2062@googlegroups.com> <87eg7suxgk.fsf@elektro.pacujo.net> <8b99700a-6492-4982-a6a6-987e1761a5db@googlegroups.com> <96idnWw48cOA8PXKnZ2dnUU7-N2dnZ2d@giganews.com> Message-ID: <7ec322a6-db95-430b-b578-97b954cccca4@googlegroups.com> On Tuesday, June 21, 2016 at 10:24:46 AM UTC+12, Wildman wrote: > I am not convinced on any of the theories on how the pyramids > were built, or any other of the monolithic sites. ?Reality is that which, when you stop believing in it, doesn?t go away.? -- Philip K Dick From auriocus at gmx.de Wed Jun 22 17:47:30 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 22 Jun 2016 23:47:30 +0200 Subject: [tkinter] widget size adjustment In-Reply-To: References: <1mp3y55.17n7bwiavn734N%pdorange@pas-de-pub-merci.mac.com> <1mp7jid.15cud5vvfqykvN%pdorange@pas-de-pub-merci.mac.com> <1mp9f05.15v6sv1tfesoiN%pdorange@pas-de-pub-merci.mac.com> <1mp9ou7.1ifps191o2fj76N%pdorange@pas-de-pub-merci.mac.com> Message-ID: Am 22.06.16 um 23:18 schrieb Zachary Ware: > On Wed, Jun 22, 2016 at 4:05 PM, Christian Gollwitzer wrote: >> BTW, the Tkinter wrapper is a bit clumsy for this option. In the original >> Tk, the sticky option is just a string. You can still pass that and do >> >> sticky='nsew' >> >> instead of the clumsy >> >> sticky=Tkinter.N+Tkinter.S+Tkinter.E+Tkinter.W > > There are constants in tkinter for this: NSEW, NS, NE, NW, SE, SW, and EW. Yes, but this means that not only the combinations with three are missing (NEW = stretch left-right and align at the top etc.), but also you need to remember the exact order that the author of Tkinter has set. I'm still thinking that passing a string is more in the spirit of Tk; do sticky='snew' or sticky='news' if you wish, which actually works. Plus you save the module prefix (unless you do "from tkinter import *"). I'm not getting the rationale behind these constants. Why should I do side=Tk.LEFT instead of side='left' ? There are more points where Tkinter feels clunky compared to Tk in Tcl. For instance, gridding widgets with row and columnspan options can be done in Tcl in ASCII-art using -, x and ^ to indicate extensions: grid .a - grid .b .c grid ^ x This defines a 3x2 grid where .a extends to the right (columnspan=2), .b extends downwards (rowspan =2), and the bottom right place is empty. The same thing in Python requires to do explicit row/column-counting a.grid(row=0, column=0, columnspan=2) b.grid(row=1, column=0, rowspan=2) c.grid(row=1, column=1) This gets increasingly uglier with the number of widgets in a frame. If grid were a standalone function, as it is in Tk, it would not be difficult to provide something similar to the Tcl code. For whatever reason it was decided that it should be a method of the widgets to be placed and thus accepts only a single widget. Christian From kw429 at cornell.edu Wed Jun 22 18:49:56 2016 From: kw429 at cornell.edu (Ke Wang) Date: Wed, 22 Jun 2016 15:49:56 -0700 (PDT) Subject: Why my process cannot terminate when Pipe Connection is closed Message-ID: import multiprocessing as mp def send(conn): """send obj to pipe""" for i in range(10): conn.send(i) print("send:", i) conn.close() def transform(func, conn): """receive input from pipe, transform it""" try: while True: i = conn.recv() print('transform:', func(i)) except EOFError: conn.close() c_1, c_2 = mp.Pipe() p1 = mp.Process(target=send, args=(c_1,)) p2 = mp.Process(target=transform, args=(lambda x: x ** 2, c_2,)) p1.start() p2.start() p1.join() p2.join() In python documentation it's stated, recv() Blocks until there its something to receive. Raises EOFError if there is nothing left to receive and the other end was closed. But why this code doesn't terminate? From christopher_reimer at icloud.com Wed Jun 22 18:50:59 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 22 Jun 2016 15:50:59 -0700 Subject: Is signed zero always available? In-Reply-To: References: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> <1466606088.4117582.645299713.03DA7658@webmail.messagingengine.com> Message-ID: <285A7071-5102-4516-BD3E-79C291023705@icloud.com> > On Jun 22, 2016, at 7:59 AM, Grant Edwards wrote: > >> On 2016-06-22, Random832 wrote: >>> On Wed, Jun 22, 2016, at 10:19, Grant Edwards wrote: >>> >>> Is that guaranteed by Python, or just a side-effect of the >>> implementation? Back in the days when Python used native C >>> integers I think the latter. >> >> AIUI, native C integers have never reliably supported signed zero >> even with representations that naively seem to have it. There's no >> well-defined way to detect it - no int version of copysign, for >> instance - and implementations are free to erase the distinction on >> every load/store or define one of them to be a trap representation. > > It's been almost 25 years since I used hardware that supported signed > zero integers (CDC 6600). I don't recall there being a C compiler > available. We used Pascal and assembly, though I think FORTRAN was > what most people used. I don't recall whether the Pascal > implementation exposed the existence of -0 to the user or not. When I took mathematics in college, the following was true: -1 * 0 = 0 I would probably have gotten rapped on the knuckles by my instructors if I answered -0. Zero was zero. No plus or minus about that. No discussion of signed integers ever mentioned signed zero. Did I miss something in college? Or did -0 represent zero volts on the negative rail of an op-amp in electronics? Thank you, Chris R. From dan at tombstonezero.net Wed Jun 22 18:54:48 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 22 Jun 2016 22:54:48 -0000 (UTC) Subject: Unexpected NANs in complex arithmetic References: <5769fc9b$0$1622$c3e8da3$5496439d@news.astraweb.com> <576a2d6d$0$11089$c3e8da3@news.astraweb.com> Message-ID: On Wed, 22 Jun 2016 16:30:49 +1000, Chris Angelico wrote: > On Wed, Jun 22, 2016 at 4:17 PM, Steven D'Aprano > wrote: >> On Wednesday 22 June 2016 13:54, Dan Sommers wrote: >> >>> By the time Python returns a result for inf+3j, you're already in >>> trouble (or perhaps Python is already in trouble). >> >> I don't see why. It is possible to do perfectly sensible arithmetic on INFs. > > Technically, arithmetic on INF is a short-hand for a limit. What is > inf+1? Well, it's the limit of x+1 as x tends toward +?, which is ?. > So inf+1 evaluates to inf. > >>>> inf = float("inf") >>>> inf+1 > inf > > What's 5-inf? Same again - the limit of 5-x as x tends toward +?. > That's tending in the opposite direction, so we get infinity the other > way: > >>>> 5-inf > -inf > > So it's not really "doing arithmetic on infinity", as such. That said, > I'm not entirely sure why "inf+3j" means we're already in trouble - > Dan, can you elaborate? ISTM you should be able to do limit-based > arithmetic, just the same. What does (or can) inf+3j mean, and how can that be meaningfully different from inf+4j, or 3+infj? My mental model for math's ? and Python's complex() is the points on a plane plus a single infinity.? The quantity inf+3j is not a point on the plane, nor is it that single infinity. To support inf+3j and 4+infj, Python's complex() would have to be the points on a plane plus four "lines of infinity" plus something to handle the intersections of the lines. Maybe it's me, but that model creates more problems than it solves. ? Yes, I understand that math's ? and Python's complex() are different. From michael.selik at gmail.com Wed Jun 22 20:34:51 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 23 Jun 2016 00:34:51 +0000 Subject: Is signed zero always available? In-Reply-To: <285A7071-5102-4516-BD3E-79C291023705@icloud.com> References: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> <1466606088.4117582.645299713.03DA7658@webmail.messagingengine.com> <285A7071-5102-4516-BD3E-79C291023705@icloud.com> Message-ID: On Wed, Jun 22, 2016 at 4:53 PM Christopher Reimer < christopher_reimer at icloud.com> wrote: > > On Jun 22, 2016, at 7:59 AM, Grant Edwards > wrote: > > > >> On 2016-06-22, Random832 wrote: > >>> On Wed, Jun 22, 2016, at 10:19, Grant Edwards wrote: > >>> > >>> Is that guaranteed by Python, or just a side-effect of the > >>> implementation? Back in the days when Python used native C > >>> integers I think the latter. > >> > >> AIUI, native C integers have never reliably supported signed zero > >> even with representations that naively seem to have it. There's no > >> well-defined way to detect it - no int version of copysign, for > >> instance - and implementations are free to erase the distinction on > >> every load/store or define one of them to be a trap representation. > > > > It's been almost 25 years since I used hardware that supported signed > > zero integers (CDC 6600). I don't recall there being a C compiler > > available. We used Pascal and assembly, though I think FORTRAN was > > what most people used. I don't recall whether the Pascal > > implementation exposed the existence of -0 to the user or not. > > When I took mathematics in college, the following was true: > > -1 * 0 = 0 > > I would probably have gotten rapped on the knuckles by my instructors if I > answered -0. Zero was zero. No plus or minus about that. No discussion of > signed integers ever mentioned signed zero. > > Did I miss something in college? > I can't remember where I came across the concept. It might have been in calculus. Zero can be thought of as the asymptotic value of 1/n as n approaches infinity. If so, then negative zero would be the asymptote of -1/n as n approaches infinity. From lawrencedo99 at gmail.com Wed Jun 22 20:55:06 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 17:55:06 -0700 (PDT) Subject: Why my process cannot terminate when Pipe Connection is closed In-Reply-To: References: Message-ID: On Thursday, June 23, 2016 at 10:50:10 AM UTC+12, Ke Wang wrote: > Raises EOFError if there is nothing left to receive and the other end was > closed. Does the parent process have to close the sending end of the pipe as well? Otherwise the receiver never gets EOF as long as one process still has it open. From steve at pearwood.info Wed Jun 22 21:16:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 11:16:36 +1000 Subject: Is signed zero always available? References: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> <1466606088.4117582.645299713.03DA7658@webmail.messagingengine.com> <285A7071-5102-4516-BD3E-79C291023705@icloud.com> Message-ID: <576b3874$0$1608$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Jun 2016 08:50 am, Christopher Reimer wrote: > When I took mathematics in college, the following was true: > > -1 * 0 = 0 > > I would probably have gotten rapped on the knuckles by my instructors if I > answered -0. Zero was zero. No plus or minus about that. No discussion of > signed integers ever mentioned signed zero. > > Did I miss something in college? Yes. In IEEE-754 floating point maths, zero can represent two distinct concepts: actual mathematical zero, and the result of a calculation which ought to be small but non-zero, but due to the limitations of a fixed data size, underflows to zero. Ideally, we would want *three* zeroes, representing underflow to zero but positive, underflow to zero but negative, and true mathematical zero. Inconveniently, the standard floating point format leads to *two* different representations of zero, one which is all zero bits, and one which is all zero bits except for the sign bit. So the behaviour of IEEE-754 zeroes is a mix of "treat them as the result of underflow" and "treat them as zero". For example, the standard mandates that -0.0 must compare equal to 0.0, and that in regular arithmetic there's no difference between the two: x+0.0 and x-0.0 are the same. But that doesn't mean that they are always treated the same. For instance, consider 1/x, where x is one of the zeroes. If we treat them as "very small numbers which have underflowed", then 1/x should be "very big numbers which will overflow", and IEEE-754 mandates two special values to represent overflow: INF and -INF. So 1/0.0 may return INF, and 1/-0.0 may return -INF. (I say "may" rather than "will", because the standard allows that behaviour to be configurable: you can specify whether to get ?INF or to signal divide by zero. Unfortunately although most CPUs and FPUs support this behaviour, support for it in compilers is mostly poor.) But where signed zeroes really become useful is when dealing with branch cuts for complex elementary functions: http://people.freebsd.org/~das/kahan86branch.pdf -- Steven From rustompmody at gmail.com Wed Jun 22 22:01:55 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jun 2016 19:01:55 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <29bbda44-4e04-49c1-bb32-1674dab5883e@googlegroups.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <29bbda44-4e04-49c1-bb32-1674dab5883e@googlegroups.com> Message-ID: <5ccc9a34-d682-44df-a6ad-ae219562c59a@googlegroups.com> On Tuesday, June 21, 2016 at 7:27:00 PM UTC+5:30, Rustom Mody wrote: > > > n_Xorg> -- no good You probably want this: https://wiki.archlinux.org/index.php/X_KeyBoard_extension#Editing_the_layout > > So Rustom, how do *you* produce, say, Hebrew or Spanish text, or your > > favorite math symbols? > > I wish I could say I have a good answer -- ATM dont > However some ?-assed ones: > > > Emacs: > set-input-method (C-x RET C-\) greek > And then typing > abcdefghijklmnopqrstuvwxyz > gives > ????????????????;????????? > [yeah that ; on q is curious] > > Spanish?? No idea > But there seems to be a spanish input method that > has these ????? > > Ive typed Hindi/Marathi/Tamil/Sanskrit/Gujarati and helped others with Bengali > using devanagari-itrans/gujarati-itrans/tamil-itrans/bengali-itrans input > methods. There are also the corresponding -inscript methods for those that > type these fluently -- I am not one of those. > > I have some 15-20 lines of elisp that makes these itrans uses easier (for me) ... etc A couple of people wrote me off list thanking me for emacs-unicode knowhow So remembered that there is one method -- yes clunky -- that I use most -- forgot to mention -- C-x 8 RET ie insert-char? Which takes the name (or hex) of the unicode char. Nice thing is there is some amount of Tab-*-completion available which makes it possible to fish around for chars after knowing/remembering part of the name So with ? showing TAB? Superscr? expands to SUPERSCRIPT One more ? gives ====================== Click on a completion to select it. In this buffer, type RET to select the completion near point. Possible completions are: SUPERSCRIPT CLOSING PARENTHESIS SUPERSCRIPT DIGIT EIGHT SUPERSCRIPT DIGIT FIVE SUPERSCRIPT DIGIT FOUR SUPERSCRIPT DIGIT NINE SUPERSCRIPT DIGIT ONE SUPERSCRIPT DIGIT SEVEN SUPERSCRIPT DIGIT SIX SUPERSCRIPT DIGIT THREE SUPERSCRIPT DIGIT TWO SUPERSCRIPT DIGIT ZERO SUPERSCRIPT EIGHT SUPERSCRIPT EQUALS SIGN SUPERSCRIPT FIVE SUPERSCRIPT FOUR SUPERSCRIPT HYPHEN-MINUS SUPERSCRIPT LATIN SMALL LETTER I SUPERSCRIPT LATIN SMALL LETTER N SUPERSCRIPT LEFT PARENTHESIS SUPERSCRIPT MINUS SUPERSCRIPT NINE SUPERSCRIPT ONE SUPERSCRIPT OPENING PARENTHESIS SUPERSCRIPT PLUS SIGN SUPERSCRIPT RIGHT PARENTHESIS SUPERSCRIPT SEVEN SUPERSCRIPT SIX SUPERSCRIPT THREE SUPERSCRIPT TWO SUPERSCRIPT ZERO ================================ Adding a d narrows to SUPERSCRIPT DIGIT One more ? narrows to Possible completions are: SUPERSCRIPT DIGIT EIGHT SUPERSCRIPT DIGIT FIVE SUPERSCRIPT DIGIT FOUR SUPERSCRIPT DIGIT NINE SUPERSCRIPT DIGIT ONE SUPERSCRIPT DIGIT SEVEN SUPERSCRIPT DIGIT SIX SUPERSCRIPT DIGIT THREE SUPERSCRIPT DIGIT TWO SUPERSCRIPT DIGIT ZERO * can also be used as glob for parts of the name one does not remember So since there are zillions of chars that are some kind of ARROW One can write Right*arrow? Still too many Narrow further to Right*Double*Arrow? And we get Possible completions are: RIGHT DOUBLE ARROW RIGHT DOUBLE ARROW WITH ROUNDED HEAD RIGHT DOUBLE ARROW WITH STROKE RIGHTWARDS DOUBLE ARROW RIGHTWARDS DOUBLE ARROW FROM BAR RIGHTWARDS DOUBLE ARROW WITH STROKE RIGHTWARDS DOUBLE ARROW WITH VERTICAL STROKE RIGHTWARDS DOUBLE ARROW-TAIL RIGHTWARDS DOUBLE DASH ARROW etc =================== ? Steven will be mighty pleased to note that it used to be called ucs-insert For which now the help page gives: "This function is obsolete since 24.3; use `insert-char' instead." ? Courtesy Xah Lee: http://xahlee.info/comp/unicode_computing_symbols.html From lawrencedo99 at gmail.com Wed Jun 22 22:07:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 19:07:18 -0700 (PDT) Subject: ASCII or Unicode? (was best text editor for programming Python on a Mac) In-Reply-To: <5ccc9a34-d682-44df-a6ad-ae219562c59a@googlegroups.com> References: <242caeee-f489-4956-8261-680fe49f402d@googlegroups.com> <576747c1$0$1585$c3e8da3$5496439d@news.astraweb.com> <57676318$0$1621$c3e8da3$5496439d@news.astraweb.com> <87shw7gcrj.fsf@elektro.pacujo.net> <956e1073-b256-4ebc-96b0-737efd4556d3@googlegroups.com> <87mvmeheq0.fsf@elektro.pacujo.net> <29bbda44-4e04-49c1-bb32-1674dab5883e@googlegroups.com> <5ccc9a34-d682-44df-a6ad-ae219562c59a@googlegroups.com> Message-ID: <4687e066-1550-4916-9279-b145367c96d3@googlegroups.com> On Thursday, June 23, 2016 at 2:02:18 PM UTC+12, Rustom Mody wrote: > So remembered that there is one method -- yes clunky -- that I use most -- > forgot to mention -- C-x 8 RET > ie insert-char? > > Which takes the name (or hex) of the unicode char. A handy tool for looking up names and codes is the unicode(1) command . From grant.b.edwards at gmail.com Wed Jun 22 22:48:52 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 23 Jun 2016 02:48:52 +0000 (UTC) Subject: Is signed zero always available? References: <576a925f$0$1597$c3e8da3$5496439d@news.astraweb.com> <1466606088.4117582.645299713.03DA7658@webmail.messagingengine.com> <285A7071-5102-4516-BD3E-79C291023705@icloud.com> Message-ID: On 2016-06-22, Christopher Reimer wrote: >> On Jun 22, 2016, at 7:59 AM, Grant Edwards wrote: >> >>> On 2016-06-22, Random832 wrote: >>>> On Wed, Jun 22, 2016, at 10:19, Grant Edwards wrote: >>>> >>>> Is that guaranteed by Python, or just a side-effect of the >>>> implementation? Back in the days when Python used native C >>>> integers I think the latter. >>> >>> AIUI, native C integers have never reliably supported signed zero >>> even with representations that naively seem to have it. There's no >>> well-defined way to detect it - no int version of copysign, for >>> instance - and implementations are free to erase the distinction on >>> every load/store or define one of them to be a trap representation. >> >> It's been almost 25 years since I used hardware that supported signed >> zero integers (CDC 6600). I don't recall there being a C compiler >> available. We used Pascal and assembly, though I think FORTRAN was >> what most people used. I don't recall whether the Pascal >> implementation exposed the existence of -0 to the user or not. > > When I took mathematics in college, the following was true: > > -1 * 0 = 0 Well, we're talking about computers and programming languages, not mathematics. > I would probably have gotten rapped on the knuckles by my instructors > if I answered -0. Zero was zero. No plus or minus about that. No > discussion of signed integers ever mentioned signed zero. > > Did I miss something in college? If you took computer architecture courses, then yes, you missed the chapters on machine representation of integers. If you build a CPU that uses either 1's compliment or signed magnitude representations then there is a postive zero and a negative zero. If you design it to use 2's complement, then there is only a positive zero. 1's complement and signed-magnitude are excedingly rare these days, but used to be much more common. -- Grant From orgnut at yahoo.com Wed Jun 22 23:12:36 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 22 Jun 2016 20:12:36 -0700 Subject: Operator Precedence/Boolean Logic In-Reply-To: <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> Message-ID: On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: [snip] > I feel that?s a needlessly complicated rule. It would have been simpler if boolean operators (and conditional expressions like in if-statements and while-statements) only allowed values of boolean types. But that?s one of the few warts in the design of Python... > Wart?? I *strongly* disagree. I find it one of the strengths of Python, it enhances Python's expressiveness. Of course, everyone is entitled to their own opinion...and this is mine. -- -=- Larry -=- From steve at pearwood.info Wed Jun 22 23:59:29 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 13:59:29 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> Message-ID: <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: > On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: > [snip] >> I feel that?s a needlessly complicated rule. It would have been simpler >> if boolean operators (and conditional expressions like in if-statements >> and while-statements) only allowed values of boolean types. But that?s >> one of the few warts in the design of Python... >> > > Wart?? I *strongly* disagree. I find it one of the strengths of Python, > it enhances Python's > expressiveness. Of course, everyone is entitled to their own > opinion...and this is mine. Allowing any value as a truth value is just applying the principle of duck-typing to booleans. There are a pair of canonical truth values, namely True and False, but any object can quack like a truth value. We often call them: - true and false (as opposed to True and False); - true-like and false-like; - truthy and falsey values. Among the builtins, there's a general principle: - values that represent something should be truthy; - values that represent nothing should be falsey. So we have falsey values: - None - zeroes (0, 0.0, 0j, etc) - empty dict {} - empty sets and frozensets - empty strings '' and b'' (in Python 2: u'' and '') - empty lists, tuples and other sequences and truthy values: - object - non-zero numbers - non-empty dicts - non-empty sets and frozensets - non-empty strings - non-empty sequences This is an improvement over other languages like Javascript, Ruby, etc where the division between truthy and falsey appears to be fairly arbitrary. -- Steven From steve at pearwood.info Wed Jun 22 23:59:46 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 13:59:46 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> Message-ID: <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Jun 2016 05:17 am, Ben Bacarisse wrote: > pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes: > >> Ben Bacarisse wrote: >> >>> >>> math.atan2(INF, INF) >>> 0.7853981633974483 >>> >>> I would have expected NaN since atan2(INF, INF) could be thought of as >>> the limit of atan2(x, y) which could be any value in the range. And I'd >>> have guessed atan2(0, 0) would have been NaN too but >> >> i'm not a math expert, but the limit of atan2 would be 45?, so pi/4 >> radians (0,7854). >> As x,y are coordinates, the both infinite would tend toward 45?. > > The limit of atan2(x, x) is as you describe, but there is no reason to > pick that one case. Given: x = INF y = INF assert x == y there is a reason to pick atan2(y, x) = pi/4: Since x == y, the answer should be the same as for any other pair of x == y. It might not be a *great* reason, but it's a reason. -- Steven From cake240 at gmail.com Thu Jun 23 00:17:03 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Wed, 22 Jun 2016 21:17:03 -0700 (PDT) Subject: Break and Continue: While Loops Message-ID: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> CODE #1: i=0 while 1==1: print(i) i=i+1 if i>=5: print("Breaking") break ------ I understand that i=0 and i will only be printed if 1=1 The results of this is 0 1 2 3 4 Breaking Why is Breaking going to be printed if i only goes up to 4? It does say if i>=5? Shouldn't this mean that the results should be: 0 1 2 3 4 5 CODE #2: i=0 while True: i=i+1 if i==2: print("Skipping 2") continue if i==5: print("Breaking") break print(i) ------ Questions: 1. what does the word True have to do with anything here? 2. i=i+1- I never understand this. Why isn't it i=i+2? 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? 4. How is i equal to 2 or 5 if i=0? Thanks for all of your help! From cake240 at gmail.com Thu Jun 23 00:19:15 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Wed, 22 Jun 2016 21:19:15 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <85y45xx4a9.fsf@benfinney.id.au> Message-ID: On Tuesday, June 21, 2016 at 11:59:37 PM UTC-4, Ben Finney wrote: > Elizabeth Weiss > writes: > > > Hi There, > > Welcome! Your questions are fine here, but you may like to know that we > also have a beginner-specific forum for collaborative tutoring > . > > > I am a little confused as to how this is False: > > False==(False or True) > > > > I would think it is True because False==False is true. > > What does ?(False or True)? evaluate to, when you try it in the REPL? > > > I think the parenthesis are confusing me. > > (False==False) or True > > > > This is True. Is it because False==False? And True==False is not True > > but that does not change that this is True. > > Heh. You express the confusion quite well :-) > > Try the component expressions in the REPL (the interactive interpreter > session) and see if that helps:: > > >>> False or True > ? > >>> (False or True) > ? > >>> True == False > ? > >>> (True == False) > ? > >>> False == False > ? > >>> (False == False) > ? > > Then, once you think you understand what those expressions evaluate to, > look again at how those results would work in a more complex > expression:: > > >>> False == (False or True) > ? > >>> (False == False) or True > ? > > > Thank you for your help! > > I hope that helps. > > -- > \ ?[W]e are still the first generation of users, and for all that | > `\ we may have invented the net, we still don't really get it.? | > _o__) ?Douglas Adams | > Ben Finney Thank you, Ben! From cake240 at gmail.com Thu Jun 23 00:20:35 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Wed, 22 Jun 2016 21:20:35 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <85y45xx4a9.fsf@benfinney.id.au> Message-ID: <95faf9bf-f027-45a2-9078-1386789aa24b@googlegroups.com> On Tuesday, June 21, 2016 at 11:59:37 PM UTC-4, Ben Finney wrote: > Elizabeth Weiss > writes: > > > Hi There, > > Welcome! Your questions are fine here, but you may like to know that we > also have a beginner-specific forum for collaborative tutoring > . > > > I am a little confused as to how this is False: > > False==(False or True) > > > > I would think it is True because False==False is true. > > What does ?(False or True)? evaluate to, when you try it in the REPL? > > > I think the parenthesis are confusing me. > > (False==False) or True > > > > This is True. Is it because False==False? And True==False is not True > > but that does not change that this is True. > > Heh. You express the confusion quite well :-) > > Try the component expressions in the REPL (the interactive interpreter > session) and see if that helps:: > > >>> False or True > ? > >>> (False or True) > ? > >>> True == False > ? > >>> (True == False) > ? > >>> False == False > ? > >>> (False == False) > ? > > Then, once you think you understand what those expressions evaluate to, > look again at how those results would work in a more complex > expression:: > > >>> False == (False or True) > ? > >>> (False == False) or True > ? > > > Thank you for your help! > > I hope that helps. > > -- > \ ?[W]e are still the first generation of users, and for all that | > `\ we may have invented the net, we still don't really get it.? | > _o__) ?Douglas Adams | > Ben Finney Thank you, Ben! From cake240 at gmail.com Thu Jun 23 00:21:36 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Wed, 22 Jun 2016 21:21:36 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Message-ID: On Wednesday, June 22, 2016 at 3:15:02 AM UTC-4, Jussi Piitulainen wrote: > Christian Gollwitzer writes: > > > Am 22.06.16 um 05:40 schrieb Elizabeth Weiss: > >> I am a little confused as to how this is False: > >> > >> False==(False or True) > >> > >> I would think it is True because False==False is true. > >> > >> I think the parenthesis are confusing me. > > > > Are you thinking, by any chance, that "or" indicates a choice? > > Comparing False to either False "or" True? That is not the case. > > > > "or" is an operator. "False or True" is *computed* and gives True, > > which is then compared to False by "==". Python works in these steps: > > > > 1) False == (False or True) > > 2) False == (True) > > 3) False > > Similarly: > > 1) "coffee" == ("coffee" or "tea") > 2) "coffee" == "coffee" > 3) True > > 1) "tea" == ("coffee" or "tea") > 2) "tea" == "coffee" > 3) False > > In programming languages that allow it, want("coffee" or "tea") is > probably not intended. One has to (want("coffee") or want("tea")). > > I'm not trying to confuse. I'm trying to further illustrate how the > programming language notation differs from ordinary structures of > languages like English that may seem analogous until one learns that > they aren't, quite. Thanks, Jussi! Very helpful. From cake240 at gmail.com Thu Jun 23 00:22:09 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Wed, 22 Jun 2016 21:22:09 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> Message-ID: <03e02f64-f1db-437c-8e1e-20b122727c38@googlegroups.com> On Wednesday, June 22, 2016 at 3:42:24 AM UTC-4, Lawrence D?Oliveiro wrote: > On Wednesday, June 22, 2016 at 3:40:22 PM UTC+12, Elizabeth Weiss wrote: > > I am a little confused as to how this is False: > > > > False==(False or True) > > > > I would think it is True because False==False is true. > > > > I think the parenthesis are confusing me. > > No, it is the meanings of the boolean operators in Python. The rules are: > > * boolean operators don?t have to operate on boolean values. The language spec says: > > ?...the following values are interpreted as false: False, None, numeric > zero of all types, and empty strings and containers (including strings, > tuples, lists, dictionaries, sets and frozensets). All other values are > interpreted as true.? > > I feel that?s a needlessly complicated rule. It would have been simpler if boolean operators (and conditional expressions like in if-statements and while-statements) only allowed values of boolean types. But that?s one of the few warts in the design of Python... > > * the meaning of ?A or B? is: ?return A if it evaluates to true, else return B?. Correspondingly, the meaning of ?A and B? is: ?return A if it evaluates to false, else return B?. > > Does that give you enough clues to understand what is going on? Thanks, Lawrence! From cake240 at gmail.com Thu Jun 23 00:23:49 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Wed, 22 Jun 2016 21:23:49 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7f67743a-acae-4e02-91ab-86b4d5be5767@googlegroups.com> On Wednesday, June 22, 2016 at 11:59:44 PM UTC-4, Steven D'Aprano wrote: > On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: > > > On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: > > [snip] > >> I feel that?s a needlessly complicated rule. It would have been simpler > >> if boolean operators (and conditional expressions like in if-statements > >> and while-statements) only allowed values of boolean types. But that?s > >> one of the few warts in the design of Python... > >> > > > > Wart?? I *strongly* disagree. I find it one of the strengths of Python, > > it enhances Python's > > expressiveness. Of course, everyone is entitled to their own > > opinion...and this is mine. > > Allowing any value as a truth value is just applying the principle of > duck-typing to booleans. > > There are a pair of canonical truth values, namely True and False, but any > object can quack like a truth value. We often call them: > > - true and false (as opposed to True and False); > - true-like and false-like; > - truthy and falsey > > values. > > Among the builtins, there's a general principle: > > - values that represent something should be truthy; > - values that represent nothing should be falsey. > > So we have falsey values: > > - None > - zeroes (0, 0.0, 0j, etc) > - empty dict {} > - empty sets and frozensets > - empty strings '' and b'' (in Python 2: u'' and '') > - empty lists, tuples and other sequences > > and truthy values: > > - object > - non-zero numbers > - non-empty dicts > - non-empty sets and frozensets > - non-empty strings > - non-empty sequences > > This is an improvement over other languages like Javascript, Ruby, etc where > the division between truthy and falsey appears to be fairly arbitrary. > > > > > -- > Steven Thanks, Steven! From dan at tombstonezero.net Thu Jun 23 00:40:32 2016 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 23 Jun 2016 04:40:32 -0000 (UTC) Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 23 Jun 2016 13:59:46 +1000, Steven D'Aprano wrote: > Given: > > x = INF > y = INF > assert x == y > > there is a reason to pick atan2(y, x) = pi/4: > > Since x == y, the answer should be the same as for any other pair of x == y. When x == y == 0, then atan2(y, x) is 0. From lawrencedo99 at gmail.com Thu Jun 23 00:47:05 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 21:47:05 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> Message-ID: <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: > On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: >> * boolean operators don?t have to operate on boolean values. The >> language spec >> >> says: >> >> ?...the following values are interpreted as false: False, None, numeric >> zero of all types, and empty strings and containers (including strings, >> tuples, lists, dictionaries, sets and frozensets). All other values are >> interpreted as true.? >> >> I feel that?s a needlessly complicated rule. It would have been simpler if >> boolean operators (and conditional expressions like in if-statements and >> while-statements) only allowed values of boolean types. But that?s one of >> the few warts in the design of Python... > > Wart?? I *strongly* disagree. I find it one of the strengths of Python, > it enhances Python's expressiveness. Tightening it up would rule out a whole class of common errors, from misunderstanding (or forgetting) the rule about what exactly gets interpreted as true and what as false . From lawrencedo99 at gmail.com Thu Jun 23 00:49:17 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 21:49:17 -0700 (PDT) Subject: Break and Continue: While Loops In-Reply-To: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: <6cec22f0-6e6d-4588-99e3-fd2abbc696fa@googlegroups.com> On Thursday, June 23, 2016 at 4:17:23 PM UTC+12, Elizabeth Weiss wrote: > > i=0 > while 1==1: > print(i) > i=i+1 > if i>=5: > print("Breaking") > break > > Why is Breaking going to be printed if i only goes up to 4? It does say if > i>=5? Because you incremented i after printing its value, and before checking it. From lawrencedo99 at gmail.com Thu Jun 23 00:55:51 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 22 Jun 2016 21:55:51 -0700 (PDT) Subject: Multiline parsing of python compiler demistification needed In-Reply-To: <930753e3-4c9c-45e9-9117-d340c033ac66@googlegroups.com> References: <930753e3-4c9c-45e9-9117-d340c033ac66@googlegroups.com> Message-ID: On Thursday, June 16, 2016 at 8:34:46 PM UTC+12, Yubin Ruan wrote: > print "A test case" + \ > "str_1[%s] " + \ > "str_2[%s] " % (str_1, str_2) Try this: print \ ( "A test case" "str_1[%s] " "str_2[%s] " % (str_1, str_2) ) Python takes this nifty feature from C where multiple string literals in a row are implicitly concatenated into a single string. If you come from a Java or C# background, you probably didn?t know about this, because those languages neglected to include this facility. From rustompmody at gmail.com Thu Jun 23 01:00:10 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jun 2016 22:00:10 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> Message-ID: On Thursday, June 23, 2016 at 10:17:16 AM UTC+5:30, Lawrence D?Oliveiro wrote: > On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: > > On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: > >> * boolean operators don?t have to operate on boolean values. The > >> language spec > >> > >> says: > >> > >> ?...the following values are interpreted as false: False, None, numeric > >> zero of all types, and empty strings and containers (including strings, > >> tuples, lists, dictionaries, sets and frozensets). All other values are > >> interpreted as true.? > >> > >> I feel that?s a needlessly complicated rule. It would have been simpler if > >> boolean operators (and conditional expressions like in if-statements and > >> while-statements) only allowed values of boolean types. But that?s one of > >> the few warts in the design of Python... > > > > Wart?? I *strongly* disagree. I find it one of the strengths of Python, > > it enhances Python's expressiveness. > > Tightening it up would rule out a whole class of common errors, from misunderstanding (or forgetting) the rule about what exactly gets interpreted as true and what as false . I would not support "tightening up" But calling a wart a wart seems like a good idea to me IOW making the docs a little more honest: Along these lines: There are two bool types in Python A first class bool that is useful for amusement, confusion and one-upping noobs A second class bool -- also called truthy and falsey -- that is used all the time From rustompmody at gmail.com Thu Jun 23 01:05:56 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jun 2016 22:05:56 -0700 (PDT) Subject: Break and Continue: While Loops In-Reply-To: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On Thursday, June 23, 2016 at 9:47:23 AM UTC+5:30, Elizabeth Weiss wrote: > CODE #1: > > i=0 > while 1==1: > print(i) > i=i+1 > if i>=5: > print("Breaking") > break > > ------ > I understand that i=0 and i will only be printed if 1=1 > The results of this is > 0 > 1 > 2 > 3 > 4 > Breaking > > Why is Breaking going to be printed if i only goes up to 4? It does say if i>=5? Shouldn't this mean that the results should be: > 0 > 1 > 2 > 3 > 4 > 5 > > CODE #2: > > i=0 > while True: > i=i+1 > if i==2: > print("Skipping 2") > continue > if i==5: > print("Breaking") > break > print(i) > > ------ > > Questions: > 1. what does the word True have to do with anything here? > 2. i=i+1- I never understand this. Why isn't it i=i+2? > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > 4. How is i equal to 2 or 5 if i=0? > > Thanks for all of your help! I suggested in your other post (Subject While Loops) that the predecessor of python ABC's syntax for assignment would help unconfuse you ie the ASSIGNMENT x=y we write as PUT y IN x Using that rewrite your CODE 1 as PUT 0 in i while 1==1: print(i) PUT i+1 IN i if i>=5: print("Breaking") break Now try and rethink what that does Then repeat for your other examples that confuse From pushpanth2000 at gmail.com Thu Jun 23 01:35:34 2016 From: pushpanth2000 at gmail.com (Pushpanth Gundepalli) Date: Wed, 22 Jun 2016 22:35:34 -0700 (PDT) Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: <4d2803c0-9bc9-4ae5-b5dd-96bb113b7ba1@googlegroups.com> On Tuesday, June 21, 2016 at 4:33:28 PM UTC+5:30, Pushpanth Gundepalli wrote: > Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. Thank you for ur valuable suggestions.. Actually i have done practising the exercises on codeacademy, codingbat. But the thing is that i want to do a live project which wil help me to enchance my skills more.. I'm happy tht I'm able to understand and write small lines of code(i think it is a small achivement for me and it boost my confidence).. but i need to improve more on programming.. Also pls help me out on how I can get some real time projects to practice!! From andreas.roehler at online.de Thu Jun 23 02:34:41 2016 From: andreas.roehler at online.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=) Date: Thu, 23 Jun 2016 08:34:41 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> Message-ID: <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> On 23.06.2016 06:47, Lawrence D?Oliveiro wrote: > On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: >> On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: >>> * boolean operators don?t have to operate on boolean values. The >>> language spec >>> >>> says: >>> >>> ?...the following values are interpreted as false: False, None, numeric >>> zero of all types, and empty strings and containers (including strings, >>> tuples, lists, dictionaries, sets and frozensets). All other values are >>> interpreted as true.? >>> >>> I feel that?s a needlessly complicated rule. It would have been simpler if >>> boolean operators (and conditional expressions like in if-statements and >>> while-statements) only allowed values of boolean types. But that?s one of >>> the few warts in the design of Python... >> Wart?? I *strongly* disagree. I find it one of the strengths of Python, >> it enhances Python's expressiveness. > Tightening it up would rule out a whole class of common errors, from misunderstanding (or forgetting) the rule about what exactly gets interpreted as true and what as false . Indeed, why should the result of 4 - 4 have a different truth-value than 4 - 3 ? This implementation seems to be a legacy from languages without boolean types. From steve+comp.lang.python at pearwood.info Thu Jun 23 02:45:08 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 16:45:08 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> On Thursday 23 June 2016 14:40, Dan Sommers wrote: >> Since x == y, the answer should be the same as for any other pair of x == y. > > When x == y == 0, then atan2(y, x) is 0. /s/any other pair of x == y/any other pair of x y except for zero/ :-P Zero is exceptional in many ways. -- Steve From marko at pacujo.net Thu Jun 23 02:46:16 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 09:46:16 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> Message-ID: <878txwtnbb.fsf@elektro.pacujo.net> Andreas R?hler : > Indeed, why should the result of 4 - 4 have a different truth-value > than 4 - 3 ? This implementation seems to be a legacy from languages > without boolean types. In Lisp, only nil (= the empty list) is accepted as false, everything else is considered true. In Scheme, only #f (= False) is accepted as false, everything else is considered true even though there is also a dedicated #t for True. Marko From steve+comp.lang.python at pearwood.info Thu Jun 23 03:05:36 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 17:05:36 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> Message-ID: <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> On Thursday 23 June 2016 16:34, Andreas R?hler wrote: > Indeed, why should the result of 4 - 4 have a different truth-value than > 4 - 3 ? Because 4-4 is zero, which is "nothing", while 4-3 is one, which is "something". You might as well ask why False and True have different truth values. Ironically, in a manner of speaking you *did* ask that, since 4-3 == True and 4-4 == False. -- Steve From auriocus at gmx.de Thu Jun 23 03:11:36 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 23 Jun 2016 09:11:36 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> Message-ID: Am 23.06.16 um 05:12 schrieb Larry Hudson: > On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: >> I feel that?s a needlessly complicated rule. It would have been >> simpler if boolean operators (and conditional expressions like in >> if-statements and while-statements) only allowed values of boolean >> types. But that?s one of the few warts in the design of Python... >> > > Wart?? I *strongly* disagree. I find it one of the strengths of > Python, it enhances Python's expressiveness. Of course, everyone is > entitled to their own opinion...and this is mine. https://xkcd.com/1172/ Christian From steve+comp.lang.python at pearwood.info Thu Jun 23 03:20:15 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 17:20:15 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> Message-ID: <576b8db0$0$11122$c3e8da3@news.astraweb.com> On Thursday 23 June 2016 14:47, Lawrence D?Oliveiro wrote: > On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: >> On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: >>> * boolean operators don?t have to operate on boolean values. The >>> language spec >>> >>> says: >>> >>> ?...the following values are interpreted as false: False, None, numeric >>> zero of all types, and empty strings and containers (including strings, >>> tuples, lists, dictionaries, sets and frozensets). All other values are >>> interpreted as true.? >>> >>> I feel that?s a needlessly complicated rule. As I described in my earlier email, it isn't complicated, at least not the way builtins are modelled. >>> It would have been simpler if >>> boolean operators (and conditional expressions like in if-statements and >>> while-statements) only allowed values of boolean types. But that?s one of >>> the few warts in the design of Python... >> >> Wart?? I *strongly* disagree. I find it one of the strengths of Python, >> it enhances Python's expressiveness. > > Tightening it up would rule out a whole class of common errors, Hardly common. The only two exceptions I've seen are: - people surprised by midnight being false, but that is fixed in 3.5; - people surprised that empty or exhausted iterables don't evaluate as false and the first of those is pretty rare. But even if you were right, and I disagree that you are, "fixing" this would break backwards compatibility and cause vast amounts of working code to stop working. That is much worse than the "problem". > from > misunderstanding (or forgetting) the rule about what exactly gets interpreted > as true and what as false > . Or... we could fix time objects, as was done. -- Steve From laurent.pointal at free.fr Thu Jun 23 03:36:07 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Thu, 23 Jun 2016 09:36:07 +0200 Subject: Request for opinions: A cross language development tool References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> <576980EA.2030103@bridge-dev.com> Message-ID: <576b9167$0$5442$426a74cc@news.free.fr> Tal Zion wrote: > Bridge compiles Python modules into native code, What is "native", really microprocessor executable binary ? How do you adapt to diversity? > which requires us to > support Python *language* features (for, while, class, generators, etc) > but it reuses CPython's libraries (list, dict, str, etc) Hum, "etc" is important here, CPython libraries makes Python power ("batteries included"). And running such code on client side have *important* security concerns? I won't see people allowing automatically loaded Python scripts (or their binaries) execution on their system as is without a security layer. > so we don't > implement those, and it also uses CPython's ast module in order to parse > Python code. So once we are done supporting all of the language > features, any Python code should work. Supporting features is not only parsing code, it's providing same execution semantic. And its a reason it would be more complicated to use exactly same execution kernel to run other languages. > Currently we have quite a few > language features to implement, but we're working on it =) We're > targeting Python 3.5. You seem to start a new, potentially complex project (devil is in details), ignoring other works which already did same job: Apart from ironpython, parrot, jython, already listed, you can look at: Brython to run Python with a JavaScript/ECMAScript engine http://brython.info/ MicroPython to run Python on small embedded systems https://micropython.org/ Also look at https://wiki.python.org/moin/WebBrowserProgramming where there are many other projects of that kind. You want Python on the web browser, try to produce asm.js code, you will benefit of all work done on JavaScript engines, and of security layers. But? you will have to rewrite the batteries into pure Python mixed with asm.js code, this is huge work. Bon courage. A+ L.Pointal. > > Tal > > On 06/21/2016 08:36 PM, Chris Angelico wrote: >> On Wed, Jun 22, 2016 at 12:06 AM, Tal Zion wrote: >>> * Bridge makes Python faster: Python code compiled through Bridge is >>> compiled to native code. Because we are leveraging LLVM's many >>> optimizations, Python code will run faster than ever. >> Can you run *any* Python program through Bridge? Absolutely anything? >> Can you guarantee language compatibility? >> >> And if you can - what version of Python are you compatible with? >> >> ChrisA From antoon.pardon at rece.vub.ac.be Thu Jun 23 03:58:56 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 09:58:56 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576B96C0.2040106@rece.vub.ac.be> Op 23-06-16 om 05:59 schreef Steven D'Aprano: > On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: > >> On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: >> [snip] >>> I feel that?s a needlessly complicated rule. It would have been simpler >>> if boolean operators (and conditional expressions like in if-statements >>> and while-statements) only allowed values of boolean types. But that?s >>> one of the few warts in the design of Python... >>> >> Wart?? I *strongly* disagree. I find it one of the strengths of Python, >> it enhances Python's >> expressiveness. Of course, everyone is entitled to their own >> opinion...and this is mine. > Allowing any value as a truth value is just applying the principle of > duck-typing to booleans. What does that mean? As far as I understood, duck typing was that you could define any class with the same attributes and methods as an other, often a built in, at which point you could substitute instance of this new class anywhere you originally expected instance of the old class. My experience is that this doesn't work with booleans. When I need real booleans, encountering whatever else that can act like a boolean, is more often than not an indication something went wrong but the detection of it going wrong is delayed, because almost everything can act like a boolean. It is why I have sometime found the need to write: if flag is True: Because flag needed to be True, not truthy. -- Antoon Pardon From marko at pacujo.net Thu Jun 23 04:16:50 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 11:16:50 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> Message-ID: <87a8icgw0d.fsf@elektro.pacujo.net> Antoon Pardon : > It is why I have sometime found the need to write: > > if flag is True: > > Because flag needed to be True, not truthy. Then, you have found the correct idiom for your rare need. You might even want to consider: if flag is UP: ... elif flag is DOWN: ... else: assert flag is HALFMAST ... I don't particularly like Python's falsey/truthy semantics, but I can live with it. The biggest problem I have with it is the absence of an emptiness predicate. I'd like to be able to write: if not leftover.empty(): ... or even: if not empty(leftover): ... rather than having to say: if not leftover: ... or: if len(leftover) > 0: # no, I'd never write this ... Marko From antoon.pardon at rece.vub.ac.be Thu Jun 23 04:17:55 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 10:17:55 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> Message-ID: <576B9B33.2030903@rece.vub.ac.be> Op 23-06-16 om 09:05 schreef Steven D'Aprano: > On Thursday 23 June 2016 16:34, Andreas R?hler wrote: > >> Indeed, why should the result of 4 - 4 have a different truth-value than >> 4 - 3 ? > Because 4-4 is zero, which is "nothing", while 4-3 is one, which is > "something". No zero is not nothing. If zere is nothing and an empty list is nothing, I would expect zero to be an empty list or that they could be used interchangebly. For instance in a project of mine polling for information and receiving an empty list is different from receiving None. An empty list means there is currently no information available. None means The information streams came to an end. I rarely need tests where any truthy value will branch in one direction and any falsy value in the other. So IMO it is more hassle than it is worth. -- Antoon. From andreas.roehler at online.de Thu Jun 23 04:23:02 2016 From: andreas.roehler at online.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=) Date: Thu, 23 Jun 2016 10:23:02 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> Message-ID: <0027b7d7-3f27-43a9-89f8-31ca1ab4382a@online.de> On 23.06.2016 09:05, Steven D'Aprano wrote: > On Thursday 23 June 2016 16:34, Andreas R?hler wrote: > >> Indeed, why should the result of 4 - 4 have a different truth-value than >> 4 - 3 ? > Because 4-4 is zero, which is "nothing", Hmm, water freezes at zero degree celsius, because there is no temperature? > while 4-3 is one, which is > "something". > > You might as well ask why False and True have different truth values. > Ironically, in a manner of speaking you *did* ask that, since 4-3 == True and > 4-4 == False. > > From steve+comp.lang.python at pearwood.info Thu Jun 23 04:28:13 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 18:28:13 +1000 Subject: Break and Continue: While Loops References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: <576b9d9e$0$2761$c3e8da3$76491128@news.astraweb.com> On Thursday 23 June 2016 14:17, Elizabeth Weiss wrote: > CODE #2: > > i=0 > while True: > i=i+1 > if i==2: > print("Skipping 2") > continue > if i==5: > print("Breaking") > break > print(i) > > ------ > > Questions: > 1. what does the word True have to do with anything here? Consider: "while the pasta is too hard to eat, keep boiling it" "while you are feeling sick, stay in bed and drink plenty of fluids" "While" repeatedly takes a condition, decides if it is true or false, and then decides what to do. If you give it a condition True, that's *always* true, so it repeats forever unless you use "break" to escape from the loop. > 2. i=i+1- I never understand this. Why isn't it i=i+2? i = i + 1 increase i by one each time around the loop: i = 0, then 1, then 2, then 3, then 4... If you used i = i+2, it would increase by two each time around the loop: i = 0, then 2, then 4, then 6, then ... > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > 4. How is i equal to 2 or 5 if i=0? i starts off as 0. But then you increase it by 1 each time around the loop. Can I ask, have you learned about for loops yet? There seems to be a fashion among some teachers and educators to teach while loops before for loops. I think that is a terrible idea, while loops are so much more complicated than for loops. Try this example instead: for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: if i == 2: print("skipping") continue if i == 5: print("breaking") break print("i =", i) The main thing you need to know to understand this is that the line "for i in ..." sets i=0, then runs the indented block under it, then sets i=1 and runs the indented block, then sets i=2, and so forth. Run the code and see if it makes sense to you. Feel free to ask as many questions as you like! The line "for i in [0, 1, 2, ..." is a bit wordy and verbose. Can you imagine if you wanted to loop 1000 times? Fortunately Python has an abbreviated version: for i in range(10): if i == 2: print("skipping") continue if i == 5: print("breaking") break print("i =", i) -- Steve From andreas.roehler at online.de Thu Jun 23 04:32:20 2016 From: andreas.roehler at online.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=) Date: Thu, 23 Jun 2016 10:32:20 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576B9B33.2030903@rece.vub.ac.be> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> Message-ID: <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> On 23.06.2016 10:17, Antoon Pardon wrote: > Op 23-06-16 om 09:05 schreef Steven D'Aprano: >> On Thursday 23 June 2016 16:34, Andreas R?hler wrote: >> >>> Indeed, why should the result of 4 - 4 have a different truth-value than >>> 4 - 3 ? >> Because 4-4 is zero, which is "nothing", while 4-3 is one, which is >> "something". > No zero is not nothing. If zere is nothing and an empty list is nothing, > I would expect zero to be an empty list or that they could be used interchangebly. > > There is a fundamental diff between zero and emptiness. Zero is just a relation in the realm of integers. It tells being in the midst between positiv and negativ infinity. Number one tells being one unit towards positiv infinity in relation to negativ infinity. And so on. Whilst emptiness tells about non-existence. From steve+comp.lang.python at pearwood.info Thu Jun 23 04:48:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 18:48:23 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> Message-ID: <576ba258$0$11110$c3e8da3@news.astraweb.com> On Thursday 23 June 2016 18:17, Antoon Pardon wrote: > No zero is not nothing. I think you have just disagreed with about four thousand years of mathematicians and accountants. In fact, mathematicians were so hung up about zero being nothing, that it took about three thousand years before they accepted zero as a number (thanks to Indian mathematicians, via Arab mathematicians). > If zere is nothing and an empty list is nothing, > I would expect zero to be an empty list or that they could be used > interchangebly. You must have real trouble with statically typed languages then. Some of them won't even let you add 0.0 + 1 (since 0.0 is a float and 1 is an int). > For instance in a project of mine polling for information and > receiving an empty list is different from receiving None. Okay. How is this relevant to the question of bools? If Python had "real bools" (in, say, the Pascal sense) you would still need to distinguish None from an empty list: if info is None: print("done") elif info: # duck-typing version # "real bools" version uses "info != []" instead print("processing...") else: print("nothing to process") In fact, in this case chances are you probably don't even care to distinguish between empty and non-empty lists. What (I imagine) you probably care about is None versus any list: if info is None: print("done") else: for item in info: print("processing...") > I rarely need tests where any truthy value will branch in one > direction and any falsy value in the other. That's reasonable. Few people do, except in the general case that they write some code that accepts any arbitrary truthy value. But more often, you expect that you are inspecting an object of some specific type, say, a sequence (list, tuple, deque, etc): if seq: process() else: handle_empty_case() or a mapping (dict, UserDict, etc): if mapping: process() else: handle_empty_case() or a Widget: if widget: process() else: handle_empty_case() where you ask the object in question whether or not it should be considered empty ("nothing") or not ("something"), rather than having to call a type- specific piece of code for each one: if len(seq) == 0: ... if mapping.isempty(): ... if widget.isnullwidget(): ... It's just duck-typing. Bools have certain behaviour in certain contexts, and *all* objects get the opportunity to quack like a bool in that context. -- Steve From lawrencedo99 at gmail.com Thu Jun 23 04:53:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 23 Jun 2016 01:53:18 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <87a8icgw0d.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> Message-ID: <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: > if len(leftover) > 0: # no, I'd never write this > ... I regularly write ?len(leftover) != 0?. Why not? From antoon.pardon at rece.vub.ac.be Thu Jun 23 05:01:18 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 11:01:18 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <87a8icgw0d.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> Message-ID: <576BA55E.9030208@rece.vub.ac.be> Op 23-06-16 om 10:16 schreef Marko Rauhamaa: > I don't particularly like Python's falsey/truthy semantics, but I can > live with it. The biggest problem I have with it is the absence of an > emptiness predicate. I'd like to be able to write: > > if not leftover.empty(): > ... > > or even: > > if not empty(leftover): > ... > > rather than having to say: > > if not leftover: > ... > > or: > > if len(leftover) > 0: # no, I'd never write this > ... Well if I have to test for emptyness, I always write if len(seq) > 0: Because this will throw an exception when len can't apply to seq and so this will catch possible bugs sooner than writing: if not seq. -- Antoon Pardon From marko at pacujo.net Thu Jun 23 05:07:57 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 12:07:57 +0300 Subject: Request for opinions: A cross language development tool References: <57692EBD.1060606@bridge-dev.com> <576949CC.2070708@bridge-dev.com> <576980EA.2030103@bridge-dev.com> <576b9167$0$5442$426a74cc@news.free.fr> Message-ID: <8760t0gtn6.fsf@elektro.pacujo.net> Laurent Pointal : > Tal Zion wrote: >> Bridge compiles Python modules into native code, > > What is "native", really microprocessor executable binary ? How do you > adapt to diversity? They don't need to adapt to different CPU types. They can list supported targets. Also, they could generate, say, C code to achieve a great level of portability. > And running such code on client side have *important* security > concerns That's no different for any C program running on your system. It has access to *everything* in the vast collection of OS libraries through direct linking and dlopen(3). In fact, that's no different for any interpreted Python module loaded in from PyPI. >> so we don't implement those, and it also uses CPython's ast module in >> order to parse Python code. So once we are done supporting all of the >> language features, any Python code should work. > > Supporting features is not only parsing code, it's providing same > execution semantic. I think that's where the native code comes in. > You seem to start a new, potentially complex project (devil is in > details), ignoring other works which already did same job: Let them. Some of the greatest things have come about that way. > this is huge work. > > Bon courage. That's the attitude! Marko From marko at pacujo.net Thu Jun 23 05:10:54 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 12:10:54 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> Message-ID: <871t3ogti9.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: >> if len(leftover) > 0: # no, I'd never write this >> ... > > I regularly write ?len(leftover) != 0?. Why not? The __len__ method is not guaranteed to execute in O(1). See: Marko From steve+comp.lang.python at pearwood.info Thu Jun 23 05:17:25 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 19:17:25 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> Message-ID: <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> On Thursday 23 June 2016 18:32, Andreas R?hler wrote: > There is a fundamental diff between zero and emptiness. In English, "emptiness" implies a container (real or figurative). The container is not "something or nothing", it is the *contents* being referred to. "This shopping bag is empty" doesn't mean the shopping bag is nothing. It means that the set of items in the bad is the null set, i.e. there are ZERO items in the bag. "My fridge is empty" doesn't mean that the fridge is nothing. It means that the set of items in the fridge is the null set, i.e. there are ZERO items in the fridge. "That guy's head is empty" doesn't mean his head is nothing, it means that the set of thoughts in his head is the null set, i.e. he has ZERO thoughts. (This, of course, should be read figuratively, not literally.) > Zero is just a relation in the realm of integers. It tells being in the > midst between positiv and negativ infinity. No, zero is not "a relation". It is an integer, and a very special one. - zero is neither positive nor negative; - zero is the additive identity: n+0 == n - zero is multiplicative nullity; n*0 == 0 - division by zero is undefined. It is an artifact of the way we draw the number line (a *picture*) that zero is halfway between positive and negative: <----------------------+------------------------> -4 -3 -2 -1 0 1 2 3 4 We could have draw it like this, with zero at the extreme left hand end: -3 / -2 / -1 / 0 + 1 \ 2 \ 3 \ although that would make graphing look a bit weird. (That's what we do with the extended Reals: we bend the number line around in a circle, with 0 at one pole and ?infinity at the other.) But don't confuse the concrete representation of numbers on a line with the abstract numbers themselves. In practical sense, there is a difference between having zero sheep and having one sheep, two sheep, three sheep, ... and of course nobody has even actually had negative one sheep. > Number one tells being one unit towards positiv infinity in relation to > negativ infinity. And so on. > > Whilst emptiness tells about non-existence. We can derive arithmetic from set theory. Zero is very special: it is defined as the empty set: 0: {} The successor of zero (namely, one) is the set of all empty sets: 1: {{}} Two is the set of zero and one: 2 = {{}, {{}}} and so forth. -- Steve From antoon.pardon at rece.vub.ac.be Thu Jun 23 05:23:58 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 11:23:58 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576ba258$0$11110$c3e8da3@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <576ba258$0$11110$c3e8da3@news.astraweb.com> Message-ID: <576BAAAE.1090306@rece.vub.ac.be> Op 23-06-16 om 10:48 schreef Steven D'Aprano: > On Thursday 23 June 2016 18:17, Antoon Pardon wrote: > >> No zero is not nothing. > I think you have just disagreed with about four thousand years of > mathematicians and accountants. I don't care. In modern mathematics, zero is usaly defined as the empty set. The empty set contains nothing, but it isn't nothing itself. Otherwise the empty set would be the same as the set containing the empty set, since they both would contain the same, being nothing. So modern mathematics seems to agree with me and that is enough for me. >> If zere is nothing and an empty list is nothing, >> I would expect zero to be an empty list or that they could be used >> interchangebly. > You must have real trouble with statically typed languages then. Some of them > won't even let you add 0.0 + 1 (since 0.0 is a float and 1 is an int). Your conclusion is a non sequitur. >> For instance in a project of mine polling for information and >> receiving an empty list is different from receiving None. > Okay. How is this relevant to the question of bools? If Python had "real bools" > (in, say, the Pascal sense) you would still need to distinguish None from an > empty list: It illustrates the distinction python makes into truthy and falsy, is often enough inadequate. A language with real bools would force you to write out the actual expression you want and wouldn't tempt you to write something you think will work out fine. The zen of python states that explicit is better than implicit, but the "boolean" semantics of python seem to encourage people to rely on a lot of implicit things that are going on. -- Antoon Pardon. From antoon.pardon at rece.vub.ac.be Thu Jun 23 05:27:36 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 11:27:36 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <871t3ogti9.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> Message-ID: <576BAB88.3030407@rece.vub.ac.be> Op 23-06-16 om 11:10 schreef Marko Rauhamaa: > Lawrence D?Oliveiro : > >> On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: >>> if len(leftover) > 0: # no, I'd never write this >>> ... >> I regularly write ?len(leftover) != 0?. Why not? > The __len__ method is not guaranteed to execute in O(1). See: > > ht=__len__#object.__len__> As far as I can see, neither is the __bool__ method. -- Antoon. From steve+comp.lang.python at pearwood.info Thu Jun 23 05:39:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 19:39:23 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> Message-ID: <576bae4c$0$11112$c3e8da3@news.astraweb.com> On Thursday 23 June 2016 17:58, Antoon Pardon wrote: > Op 23-06-16 om 05:59 schreef Steven D'Aprano: >> On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: >> >>> On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: >>> [snip] >>>> I feel that?s a needlessly complicated rule. It would have been simpler >>>> if boolean operators (and conditional expressions like in if-statements >>>> and while-statements) only allowed values of boolean types. But that?s >>>> one of the few warts in the design of Python... >>>> >>> Wart?? I *strongly* disagree. I find it one of the strengths of Python, >>> it enhances Python's >>> expressiveness. Of course, everyone is entitled to their own >>> opinion...and this is mine. >> Allowing any value as a truth value is just applying the principle of >> duck-typing to booleans. > > What does that mean? As far as I understood, duck typing was that you > could define any class with the same attributes and methods as an other, > often a built in, at which point you could substitute instance of this > new class anywhere you originally expected instance of the old class. But you only need to implement the behaviour you need, not the entire Duck interface. If you only need quack(), you don't need to implement swim(), or provide an actual Duck, any object capable of quacking will do. To decide on a branch, you don't need an actual bool, anything capable of acting like a bool will do. As a language design, ALL objects are capable of acting like a bool. Python has a specific protocol in place for deciding whether an object quacks like a bool: if the object defines __len__: if it returns 0, then the object is false; else the object is true elif the object defines __nonzero__ (__bool__ in Python 3) if it returns a true value, then the object is true else the object is false else # neither __len__ nor __nonzero__ is defined the object is true > My experience is that this doesn't work with booleans. When I need > real booleans, encountering whatever else that can act like a boolean, > is more often than not an indication something went wrong but the > detection of it going wrong is delayed, because almost everything > can act like a boolean. It is why I have sometime found the need > to write: > > if flag is True: > > Because flag needed to be True, not truthy. I find this hard to believe. Why do you care if somebody passes you 1 or "T" as the flag instead of True? And if they do pass something other than True, you don't get an exception, you simply take the false branch. Somehow I doubt that you write three-state logic everywhere: if flag is True: ... elif flag is False: ... else: ... By the way, it is a particular error of folks using so-called "real bools" to compare something you already know is a bool against True. I used to see it all the time in my Pascal days, where people would define a boolean flag then write "if flag == True". Given: assert isinstance(flag, bool) then writing flag is True returns a bool. So how do you test a bool? By comparing it to True: flag is True is True But that also returns a bool, so you must enter an infinite regress: flag is True is True is True is True... # help me, where do I stop??? The right answer, of course, is to stop *right at the beginning*. Stopping at Step 2 is silly and pointless. Since you know flag is a True or False value, then you just write: flag And the same applies to true and false values. -- Steve From lawrencedo99 at gmail.com Thu Jun 23 05:44:39 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 23 Jun 2016 02:44:39 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <871t3ogti9.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> Message-ID: <855a6682-a627-4c0f-ae95-fc3d2eb6e0d2@googlegroups.com> On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: > Lawrence D?Oliveiro: > >> On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: >>> if len(leftover) > 0: # no, I'd never write this >>> ... >> >> I regularly write ?len(leftover) != 0?. Why not? > > The __len__ method is not guaranteed to execute in O(1). So what is? From marko at pacujo.net Thu Jun 23 05:46:06 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 12:46:06 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wplgfdb5.fsf@elektro.pacujo.net> Steven D'Aprano : > On Thursday 23 June 2016 18:32, Andreas R?hler wrote: > >> There is a fundamental diff between zero and emptiness. > > In English, "emptiness" implies a container (real or figurative). The > container is not "something or nothing", it is the *contents* being > referred to. > > "This shopping bag is empty" doesn't mean the shopping bag is nothing. > It means that the set of items in the bad is the null set, i.e. there > are ZERO items in the bag. I once read this puzzle in a book: There was a shipwreck in the middle of an ocean. The ship and the cargo were lost, but five sailors managed to swim to the beach of a nearby island. After quick scouting, the sailors realized they were on a tiny desert island with lots of coconut trees loaded with coconuts. The sailors set out to collect all coconuts they could find. After several hours, they had finished the job and made a sizeable pile of coconuts on the beach. They were exhausted and it was getting dark so they agreed to divide the pile evenly between each other on the following morning. They camped on the beach for the night. One of the sailors couldn't sleep. Would the others give him his share? What if they overpowered him and left him without coconuts? He sneaked to the pile of coconuts, split the big pile evenly into five smaller piles. One was left over, he threw it to a monkey that was watching nearby. He took his fifth, carried the coconuts to a secret location, and put the rest of the coconuts in a single pile so others wouldn't notice the loss. He went back to the camp and fell sound asleep. Another sailer woke up. What if he wouldn't get his share of the coconuts? He went to the big pile, divided it evenly into five smaller piles (one coconut was left over -- he threw it to the monkey), hid his share, put the big pile back together, and went to sleep. Before dawn, each of the sailors had gone through the same exercise. When they woke up, they went to the pile. Everyone noticed the pile had shrunk during the night but nobody mentioned it. They divided the pile evenly between the five. One coconut was left over and they threw it to the monkey. How many coconuts were there in the pile originally? The book went on to find the answer(s), but gave also this interesting side solution: The pile originally had -4 coconuts. The first sailor threw one to the monkey, leaving -5 coconuts in the pile. He took his share (-1 coconut) out and put the remaining -4 coconuts back in the big pile. And so on. Ridiculous? It was this line of thinking that led Paul Dirac to predict the existence of antimatter. Marko From andreas.roehler at online.de Thu Jun 23 05:51:46 2016 From: andreas.roehler at online.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=) Date: Thu, 23 Jun 2016 11:51:46 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23.06.2016 11:17, Steven D'Aprano wrote: > [ ... ] > We can derive arithmetic from set theory. IMO not, resp. not really. But that would make a another item, pretty off-topic from Python. Should you know a place where to continue, would like to follow up. Thanks BTW. > Zero is very special: it is defined > as the empty set: > > 0: {} > > The successor of zero (namely, one) is the set of all empty sets: > > 1: {{}} > > Two is the set of zero and one: > > 2 = {{}, {{}}} > > and so forth. > > > From alister.ware at ntlworld.com Thu Jun 23 05:53:00 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 23 Jun 2016 09:53:00 GMT Subject: Break and Continue: While Loops References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: <0kOaz.154858$nm3.64299@fx38.am4> On Wed, 22 Jun 2016 21:17:03 -0700, Elizabeth Weiss wrote: > CODE #1: > > i=0 while 1==1: > print(i) > i=i+1 if i>=5: > print("Breaking") break > > ------ > I understand that i=0 and i will only be printed if 1=1 The results of > this is 0 > 1 > 2 > 3 > 4 > Breaking > > Why is Breaking going to be printed if i only goes up to 4? It does say > if i>=5? Shouldn't this mean that the results should be: > 0 > 1 > 2 > 3 > 4 > 5 > > CODE #2: > > i=0 while True: > i=i+1 > if i==2: > print("Skipping 2") > continue > if i==5: > print("Breaking") break > print(i) > > ------ > > Questions: > 1. what does the word True have to do with anything here? > 2. i=i+1- I never understand this. Why isn't it i=i+2? > 3. Do the results not include 2 of 5 because we wrote if i==2 and if > i==5? > 4. How is i equal to 2 or 5 if i=0? > > Thanks for all of your help! unrelated to your question while 1==1 Don't do this. code 2 you correctly use while True to see the problem with your code try following it through line by line with a pen & paper writing the value for I each time it is changed. (this is known in the trade as a "Dry Run") -- Fame is a vapor; popularity an accident; the only earthly certainty is oblivion. -- Mark Twain From marko at pacujo.net Thu Jun 23 05:53:08 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 12:53:08 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> Message-ID: <87oa6sfczf.fsf@elektro.pacujo.net> Antoon Pardon : > Op 23-06-16 om 11:10 schreef Marko Rauhamaa: >> The __len__ method is not guaranteed to execute in O(1). See: >> >> > ht=__len__#object.__len__> > > As far as I can see, neither is the __bool__ method. Correct, but in the absence of an __empty__ method, __bool__ gives the class the best opportunity to check for emptiness quickly. This is not only a theoretical concern. It's quite common for data structures not to maintain an element count because it's extra baggage that's not always needed and any application could keep a track of. However, an emptiness check is often trivial. Marko From marko at pacujo.net Thu Jun 23 05:57:26 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 12:57:26 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <855a6682-a627-4c0f-ae95-fc3d2eb6e0d2@googlegroups.com> Message-ID: <87k2hgfcs9.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: >> The __len__ method is not guaranteed to execute in O(1). > > So what is? The __bool__ method is the appropriate place to implement an efficient emptiness check. It might not be O(1) but it will be the most efficient way to check for emptiness, or the class is badly implemented. Marko From bc at freeuk.com Thu Jun 23 06:15:06 2016 From: bc at freeuk.com (BartC) Date: Thu, 23 Jun 2016 11:15:06 +0100 Subject: Break and Continue: While Loops In-Reply-To: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On 23/06/2016 05:17, Elizabeth Weiss wrote: > CODE #1: > i=0 > while True: > i=i+1 > if i==2: > print("Skipping 2") > continue > if i==5: > print("Breaking") > break > print(i) > > ------ > > Questions: > 2. i=i+1- I never understand this. Why isn't it i=i+2? > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > 4. How is i equal to 2 or 5 if i=0? i=0 doesn't mean that 'i' is equal to 0. In Python, "=" means 'assignment'. Something more like this: SET i to 0 i=i+1 means: SET i to i+1 'i' is a name for some value. The value of 'i' can change, usually through assignments. If 'i' currently has the value 37, then: SET i to i+1 will now store i+1 (ie. 38) into 'i'. Repeating that will set 'i' to 39 and so on. To test if 'i' has a certain value, then '==' is used (to distinguish it from '=' which means SET). So i==37 will give True if i currently has a value of 37, or False otherwise. This is used in your code: if i==2: print ("Skipping 2") continue The indented lines are executed when i has the value 2. > 1. what does the word True have to do with anything here? The 'while' statement (like others such as 'if') takes an expression that should give True or False. If True, the loop is executed once more. Actually pretty much any expression can be used, because Python can interpret almost anything as either True or False. Don't ask for the rules because they can be complicated, but for example, zero is False, and any other number is True. I think. Anyway, your code is doing an endless loop. Python doesn't have a dedicated statement for an endless loop, so you have to use 'while True' or 'while 1'. (Well, the loop is only endless until you do an explicit exit out of it, such as using 'break'.) -- Bartc From andreas.roehler at online.de Thu Jun 23 06:19:28 2016 From: andreas.roehler at online.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=) Date: Thu, 23 Jun 2016 12:19:28 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <87wplgfdb5.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> Message-ID: <78cc1b7f-40da-5a07-757f-789fb388f40c@online.de> On 23.06.2016 11:46, Marko Rauhamaa wrote: > > Ridiculous? It was this line of thinking that led Paul Dirac to predict > the existence of antimatter. > > > Marko Yeah. Maybe we could construct examples already using antagonistic charges of electrons? From antoon.pardon at rece.vub.ac.be Thu Jun 23 06:21:53 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 12:21:53 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576bae4c$0$11112$c3e8da3@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <576bae4c$0$11112$c3e8da3@news.astraweb.com> Message-ID: <576BB841.1080603@rece.vub.ac.be> Op 23-06-16 om 11:39 schreef Steven D'Aprano: > On Thursday 23 June 2016 17:58, Antoon Pardon wrote: > >> Op 23-06-16 om 05:59 schreef Steven D'Aprano: >>> On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: >>> >>>> On 06/22/2016 12:42 AM, Lawrence D?Oliveiro wrote: >>>> [snip] >>>>> I feel that?s a needlessly complicated rule. It would have been simpler >>>>> if boolean operators (and conditional expressions like in if-statements >>>>> and while-statements) only allowed values of boolean types. But that?s >>>>> one of the few warts in the design of Python... >>>>> >>>> Wart?? I *strongly* disagree. I find it one of the strengths of Python, >>>> it enhances Python's >>>> expressiveness. Of course, everyone is entitled to their own >>>> opinion...and this is mine. >>> Allowing any value as a truth value is just applying the principle of >>> duck-typing to booleans. >> What does that mean? As far as I understood, duck typing was that you >> could define any class with the same attributes and methods as an other, >> often a built in, at which point you could substitute instance of this >> new class anywhere you originally expected instance of the old class. > But you only need to implement the behaviour you need, not the entire Duck > interface. If you only need quack(), you don't need to implement swim(), or > provide an actual Duck, any object capable of quacking will do. > > To decide on a branch, you don't need an actual bool, anything capable of > acting like a bool will do. As a language design, ALL objects are capable of > acting like a bool. Python has a specific protocol in place for deciding > whether an object quacks like a bool: But an object acting like a bool, doesn't mean this bool behaviour makes the disctinction you actually need. Python tempts people to rely on those truthy values, because it saves typing is pythonic and it works for the moment and then something unexpected gets passed through and you find yourself chasing a very illusive bug. >> My experience is that this doesn't work with booleans. When I need >> real booleans, encountering whatever else that can act like a boolean, >> is more often than not an indication something went wrong but the >> detection of it going wrong is delayed, because almost everything >> can act like a boolean. It is why I have sometime found the need >> to write: >> >> if flag is True: >> >> Because flag needed to be True, not truthy. > I find this hard to believe. Why do you care if somebody passes you 1 or "T" as > the flag instead of True? And if they do pass something other than True, you > don't get an exception, you simply take the false branch. > > Somehow I doubt that you write three-state logic everywhere: Since I wrote above the I *sometimes* found this need. You may safely assume I don't write it everywhere. > > if flag is True: ... > elif flag is False: ... > else: ... > > > By the way, it is a particular error of folks using so-called "real bools" to > compare something you already know is a bool against True. I used to see it all > the time in my Pascal days, where people would define a boolean flag then write > "if flag == True". Given: > > assert isinstance(flag, bool) But of course if one would show such a line in code on this list, it would illicit a lot of comments on how unpythonic this this is and that you really shouldn't, and that you should realy rely on an exception being thrown when what you are provided doesn't work. You come here with a remark depending on not using duck typing when you start your contribution with defending duck typing. -- Antoon. From jrgulizia at scola.org Thu Jun 23 06:28:33 2016 From: jrgulizia at scola.org (Joe Gulizia) Date: Thu, 23 Jun 2016 10:28:33 +0000 Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: <4d2803c0-9bc9-4ae5-b5dd-96bb113b7ba1@googlegroups.com> References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com>, <4d2803c0-9bc9-4ae5-b5dd-96bb113b7ba1@googlegroups.com> Message-ID: <025157c4a8294eb296f2fd6f6a45df8d@TCCUSTAUTHEX01V.custauth.local> ________________________________________ From: Python-list on behalf of Pushpanth Gundepalli Sent: Thursday, June 23, 2016 12:35 AM To: python-list at python.org Subject: Re: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. On Tuesday, June 21, 2016 at 4:33:28 PM UTC+5:30, Pushpanth Gundepalli wrote: > Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. Thank you for ur valuable suggestions.. Actually i have done practising the exercises on codeacademy, codingbat. But the thing is that i want to do a live project which wil help me to enchance my skills more.. I'm happy tht I'm able to understand and write small lines of code(i think it is a small achivement for me and it boost my confidence).. but i need to improve more on programming.. Also pls help me out on how I can get some real time projects to practice!! -- https://mail.python.org/mailman/listinfo/python-list Computer Science Circles - University of Waterloo http://cscircles.cemc.uwaterloo.ca Almost any open source project welcomes volunteers....I'd start with FSF.org (Free Software Foundation) or EFSF (European FSF) https://fsfe.org/ Joe From antoon.pardon at rece.vub.ac.be Thu Jun 23 06:54:55 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 12:54:55 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <87oa6sfczf.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> Message-ID: <576BBFFF.3070504@rece.vub.ac.be> Op 23-06-16 om 11:53 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 23-06-16 om 11:10 schreef Marko Rauhamaa: >>> The __len__ method is not guaranteed to execute in O(1). See: >>> >>> >> ht=__len__#object.__len__> >> As far as I can see, neither is the __bool__ method. > Correct, but in the absence of an __empty__ method, __bool__ gives the > class the best opportunity to check for emptiness quickly. > > This is not only a theoretical concern. It's quite common for data > structures not to maintain an element count because it's extra baggage > that's not always needed and any application could keep a track of. > However, an emptiness check is often trivial. Maybe something like this: def empty(sq): try: iter(sq).next() except StopIteration: return False except: raise TypeError else: return True From marko at pacujo.net Thu Jun 23 06:59:54 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 13:59:54 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> <576BBFFF.3070504@rece.vub.ac.be> Message-ID: <878txwf9w5.fsf@elektro.pacujo.net> Antoon Pardon : > Op 23-06-16 om 11:53 schreef Marko Rauhamaa: > Maybe something like this: > > def empty(sq): > try: > iter(sq).next() > except StopIteration: > return False > except: > raise TypeError > else: > return True That may or may not be as effective as a boolean check. The point is, Python has already declared that __bool__ is the canonical emptiness checker. You could even say that it's the principal purpose of the __bool__ method. Marko From antoon.pardon at rece.vub.ac.be Thu Jun 23 07:15:32 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 13:15:32 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <878txwf9w5.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> <576BBFFF.3070504@rece.vub.ac.be> <878txwf9w5.fsf@elektro.pacujo.net> Message-ID: <576BC4D4.7030509@rece.vub.ac.be> Op 23-06-16 om 12:59 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 23-06-16 om 11:53 schreef Marko Rauhamaa: >> Maybe something like this: >> >> def empty(sq): >> try: >> iter(sq).next() >> except StopIteration: >> return False >> except: >> raise TypeError >> else: >> return True > That may or may not be as effective as a boolean check. The point is, > Python has already declared that __bool__ is the canonical emptiness > checker. You could even say that it's the principal purpose of the > __bool__ method. I think it is wrong to say __bool__ is the canonical emptiness checker. It can be used for anything where you somehow think it is reasonable to make a distinction between truthy and falsy. Even when talking about emptyness doesn't make sense. The function above at least raises an exception in a lot of cases where the class provides booly behaviour yet emptyness wouldn't make sense. Would it be worth while? That you have to decide for yourself. -- Antoon. From rosuav at gmail.com Thu Jun 23 07:39:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jun 2016 21:39:25 +1000 Subject: Break and Continue: While Loops In-Reply-To: References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: > Actually pretty much any expression can be used, because Python can > interpret almost anything as either True or False. Don't ask for the rules > because they can be complicated, but for example, zero is False, and any > other number is True. I think. The rules are very simple. Anything that represents "something" is true, and anything that represents "nothing" is false. An empty string, an empty list, an empty set, and the special "None" object (generally representing the absence of some other object) are all false. A string with something in it (eg "Hello"), a list with something in it (eg [1,2,4,8]), etc, etc, are all true. ChrisA From rosuav at gmail.com Thu Jun 23 07:45:04 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jun 2016 21:45:04 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576BAAAE.1090306@rece.vub.ac.be> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <576ba258$0$11110$c3e8da3@news.astraweb.com> <576BAAAE.1090306@rece.vub.ac.be> Message-ID: On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon wrote: > I don't care. In modern mathematics, zero is usaly defined as the > empty set. The empty set contains nothing, but it isn't nothing > itself. Otherwise the empty set would be the same as the set > containing the empty set, since they both would contain the same, > being nothing. Zero is *the cardinality of* the empty set. The set containing the empty set has a cardinality of 1. ChrisA From jon+usenet at unequivocal.co.uk Thu Jun 23 07:57:52 2016 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Thu, 23 Jun 2016 11:57:52 -0000 (UTC) Subject: Break and Continue: While Loops References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On 2016-06-23, Chris Angelico wrote: > On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: >> Actually pretty much any expression can be used, because Python can >> interpret almost anything as either True or False. Don't ask for the rules >> because they can be complicated, but for example, zero is False, and any >> other number is True. I think. > > The rules are very simple. Anything that represents "something" is > true, and anything that represents "nothing" is false. An empty > string, an empty list, an empty set, and the special "None" object > (generally representing the absence of some other object) are all > false. A string with something in it (eg "Hello"), a list with > something in it (eg [1,2,4,8]), etc, etc, are all true. Exactly. This is a major everyday strength of Python in my view. I seem to recall that Java originally insisted that only booleans (excluding even Booleans, which are a different thing because of course they are) could be checked for truth and it was one of Java's significant warts. From jussi.piitulainen at helsinki.fi Thu Jun 23 08:05:50 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 23 Jun 2016 15:05:50 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> <576BBFFF.3070504@rece.vub.ac.be> <878txwf9w5.fsf@elektro.pacujo.net> <576BC4D4.7030509@rece.vub.ac.be> Message-ID: Antoon Pardon writes: > Op 23-06-16 om 12:59 schreef Marko Rauhamaa: >> Antoon Pardon : >> >>> Op 23-06-16 om 11:53 schreef Marko Rauhamaa: >>> Maybe something like this: >>> >>> def empty(sq): >>> try: >>> iter(sq).next() >>> except StopIteration: >>> return False >>> except: >>> raise TypeError >>> else: >>> return True >> That may or may not be as effective as a boolean check. The point is, >> Python has already declared that __bool__ is the canonical emptiness >> checker. You could even say that it's the principal purpose of the >> __bool__ method. > > I think it is wrong to say __bool__ is the canonical emptiness checker. > It can be used for anything where you somehow think it is reasonable > to make a distinction between truthy and falsy. Even when talking > about emptyness doesn't make sense. > > The function above at least raises an exception in a lot of cases > where the class provides booly behaviour yet emptyness wouldn't make > sense. It also *changes* many things where emptiness *would* make sense. In particular, it can first *make* a thing empty and then happily declare it not empty. Not good. Is "sq" mnemonic for something? From antoon.pardon at rece.vub.ac.be Thu Jun 23 08:08:31 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 14:08:31 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <576ba258$0$11110$c3e8da3@news.astraweb.com> <576BAAAE.1090306@rece.vub.ac.be> Message-ID: <576BD13F.3000505@rece.vub.ac.be> Op 23-06-16 om 13:45 schreef Chris Angelico: > On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon > wrote: >> I don't care. In modern mathematics, zero is usaly defined as the >> empty set. The empty set contains nothing, but it isn't nothing >> itself. Otherwise the empty set would be the same as the set >> containing the empty set, since they both would contain the same, >> being nothing. > Zero is *the cardinality of* the empty set. The set containing the > empty set has a cardinality of 1. In modern set theory where the integers are defined as specific kind of sets, zero *is* the empty set. -- Antoon. From arsh840 at gmail.com Thu Jun 23 08:11:03 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Thu, 23 Jun 2016 05:11:03 -0700 (PDT) Subject: not able to install mysqldb-python Message-ID: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> I am trying to run django project in virtual environment. it needs mysql database library but when I try to install that it returns the error that configparser is not installed but I have installed configparser still the error remains same, is this ubuntu bug? (env) ubuntu at ip-:~/clearapp$ pip install ConfigParser Requirement already satisfied (use --upgrade to upgrade): ConfigParser in ./env/lib/python3.4/site-packages (env) ubuntu at ip-172-31-56-59:~/clearapp$ pip install configparser Requirement already satisfied (use --upgrade to upgrade): configparser in ./env/lib/python3.4/site-packages (env) ubuntu at ip-172-31-56-59:~/clearapp$ pip install MySQL-python Collecting MySQL-python Using cached MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-rrhl9079/MySQL-python/setup.py", line 13, in from setup_posix import get_config File "/tmp/pip-build-rrhl9079/MySQL-python/setup_posix.py", line 2, in from ConfigParser import SafeConfigParser ImportError: No module named 'ConfigParser' ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-rrhl9079/MySQL-python/ (env) ubuntu at ip-172-31-56-59:~/clearapp$ From rosuav at gmail.com Thu Jun 23 08:13:52 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jun 2016 22:13:52 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> <576BBFFF.3070504@rece.vub.ac.be> <878txwf9w5.fsf@elektro.pacujo.net> <576BC4D4.7030509@rece.vub.ac.be> Message-ID: On Thu, Jun 23, 2016 at 10:05 PM, Jussi Piitulainen wrote: > Is "sq" mnemonic for something? Presumably "sequence", which fits the other assumption that you noted: that calling 'iter' on it will produce a non-destructive iterator. I hope that code is never used on older Pythons that don't have exception chaining, given that it has a bare except in it. Actually, I hope that code is never used at all. ChrisA From Joaquin.Alzola at lebara.com Thu Jun 23 08:21:30 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Thu, 23 Jun 2016 12:21:30 +0000 Subject: not able to install mysqldb-python In-Reply-To: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> References: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> Message-ID: > ImportError: No module named 'ConfigParser' It is telling you the error 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 andreas.roehler at online.de Thu Jun 23 08:22:33 2016 From: andreas.roehler at online.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=) Date: Thu, 23 Jun 2016 14:22:33 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576BD13F.3000505@rece.vub.ac.be> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <576ba258$0$11110$c3e8da3@news.astraweb.com> <576BAAAE.1090306@rece.vub.ac.be> <576BD13F.3000505@rece.vub.ac.be> Message-ID: <1d9ea486-3db4-8a61-27bd-203bbce5df5d@online.de> On 23.06.2016 14:08, Antoon Pardon wrote: > Op 23-06-16 om 13:45 schreef Chris Angelico: >> On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon >> wrote: >>> I don't care. In modern mathematics, zero is usaly defined as the >>> empty set. The empty set contains nothing, but it isn't nothing >>> itself. Otherwise the empty set would be the same as the set >>> containing the empty set, since they both would contain the same, >>> being nothing. >> Zero is *the cardinality of* the empty set. The set containing the >> empty set has a cardinality of 1. > In modern set theory where the integers are defined as specific kind > of sets, zero *is* the empty set. > Modes are like waves. If one wave arrives being "modern", lets watch out for the next. There not just one set-theory, math is neither revealed nor received on some mount - even if the notion of truth has some theological connotations ;) From steve at pearwood.info Thu Jun 23 08:37:41 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 23 Jun 2016 22:37:41 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <576bae4c$0$11112$c3e8da3@news.astraweb.com> <576BB841.1080603@rece.vub.ac.be> Message-ID: <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Jun 2016 08:21 pm, Antoon Pardon wrote: > Op 23-06-16 om 11:39 schreef Steven D'Aprano: [...] >> To decide on a branch, you don't need an actual bool, anything capable of >> acting like a bool will do. As a language design, ALL objects are capable >> of acting like a bool. Python has a specific protocol in place for >> deciding whether an object quacks like a bool: > > But an object acting like a bool, doesn't mean this bool behaviour makes > the disctinction you actually need. Um... okay? I'm not really sure I understand the point you think your making. Lists and tuples can be exchanged in many duck-typing situations, but if you need something with an in-place sort method, you can't use a tuple. That's a given. If you need some feature that isn't offered by truthiness, you can't use truthiness to detect that feature. It seems hardly worth mentioning. > Python tempts people to rely on those > truthy values, because it saves typing is pythonic and it works for the > moment and then something unexpected gets passed through and you find > yourself chasing a very illusive bug. You keep saying that, but I've never seen it happen. I've seen cases where people have been surprised by the unexpected truthiness of an object ("I expected an exhausted iterator to be false, but it was true"), but that's not what you seem to be describing. To be honest, I'm not sure what you are describing. Your explanation is maddeningly vague. Since bools offer a *very small* API (beyond what they also offer as a subclass of int), I cannot imagine what unexpected thing you might get passed in that leads to "a very illusive bug". The bottom line is, bools offer only a single major API[1]: are they truthy, or falsey? What else can do you with them? Nothing. They support conditional branches, and boolean operators "or" and "and". That's all. They don't have methods to call, or attributes to set. You can use a bool to take the if branch, or the else branch, and that's effectively all. Since *all* objects support that same bool API, what can you *possibly* be passed in place of a bool that fails to work? I acknowledge, cheerfully, that there might be a mismatch between what you expect and what the object actually does. "I expect empty containers to be falsey, and non-empty ones to be truthy; but this RedBlackTree object is always false even if it has many items; and this SortedDict is always true even when it is empty." That's a nuisance and a pain when it happens, but it's arguably a bug in the object or at least a misfeature, and besides that's the risk when you duck-type. You're trusting the object that you get to behave like the object you expect, or it will break things. (An object with a misbehaving __bool__ is no better or worse than an object with a misbehaving sort() method, or __add__ method.) So I'm not really sure what you are trying to describe. I guess it might be something like this: def spam(alist): if alist: process(alist) else: print("empty list") If you pass 1 instead of an actual list, then you don't get an error until somewhere inside process(). Potentially far, far away. So you want to write: def spam(alist): if len(alist): process(alist) # requires an actual list else: print("empty list") and now calling spam(1) will raise immediately. Great. But that's not really anything to do with *bools* specifically. If you call spam() with a dict, or a set, or a tuple, or a RedBlackTree, any other object with a length, you're no better off. If you absolutely need a list, and nothing else, then you have to type-check. In practice, I don't see how truthy/falsey objects lead to more or worse bugs than any other form of dynamic typing. To me, your position is equivalent to saying that dynamic typing and duck-typing is really great, except for len(). len() should absolutely only work on lists, and nothing else, so any time you want to get the length of an object, you must work with real lists, not listy sequences: if len(list(mystring)) > 20: ... print(len(list(mydict.keys())), "items") etc. Substitute "bool" for "len" and you might understand how I feel about your position. [...] >> Somehow I doubt that you write three-state logic everywhere: > > Since I wrote above the I *sometimes* found this need. You may > safely assume I don't write it everywhere. Fair enough. [1] I exclude minor things like repr(True), and the fact that they are subclassed from int. -- Steven From songofacandy at gmail.com Thu Jun 23 09:02:33 2016 From: songofacandy at gmail.com (INADA Naoki) Date: Thu, 23 Jun 2016 22:02:33 +0900 Subject: not able to install mysqldb-python In-Reply-To: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> References: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> Message-ID: Try this https://pypi.python.org/pypi/mysqlclient On Thu, Jun 23, 2016 at 9:11 PM, Arshpreet Singh wrote: > I am trying to run django project in virtual environment. it needs mysql database library but when I try to install that it returns the error that configparser is not installed but I have installed configparser still the error remains same, is this ubuntu bug? > > > (env) ubuntu at ip-:~/clearapp$ pip install ConfigParser > Requirement already satisfied (use --upgrade to upgrade): ConfigParser in ./env/lib/python3.4/site-packages > (env) ubuntu at ip-172-31-56-59:~/clearapp$ pip install configparser > Requirement already satisfied (use --upgrade to upgrade): configparser in ./env/lib/python3.4/site-packages > (env) ubuntu at ip-172-31-56-59:~/clearapp$ pip install MySQL-python > Collecting MySQL-python > Using cached MySQL-python-1.2.5.zip > Complete output from command python setup.py egg_info: > Traceback (most recent call last): > File "", line 1, in > File "/tmp/pip-build-rrhl9079/MySQL-python/setup.py", line 13, in > from setup_posix import get_config > File "/tmp/pip-build-rrhl9079/MySQL-python/setup_posix.py", line 2, in > from ConfigParser import SafeConfigParser > ImportError: No module named 'ConfigParser' > > ---------------------------------------- > Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-rrhl9079/MySQL-python/ > (env) ubuntu at ip-172-31-56-59:~/clearapp$ > -- > https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki From random832 at fastmail.com Thu Jun 23 09:18:06 2016 From: random832 at fastmail.com (Random832) Date: Thu, 23 Jun 2016 09:18:06 -0400 Subject: Operator Precedence/Boolean Logic In-Reply-To: <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> Message-ID: <1466687886.207335.646337689.14A4BD73@webmail.messagingengine.com> On Thu, Jun 23, 2016, at 02:34, Andreas R?hler wrote: > Indeed, why should the result of 4 - 4 have a different truth-value > than 4 - 3 ? This implementation seems to be a legacy from languages > without boolean types. A set which included Python until version 2.3. From antoon.pardon at rece.vub.ac.be Thu Jun 23 09:24:43 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 23 Jun 2016 15:24:43 +0200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <576bae4c$0$11112$c3e8da3@news.astraweb.com> <576BB841.1080603@rece.vub.ac.be> <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <576BE31B.6030400@rece.vub.ac.be> Op 23-06-16 om 14:37 schreef Steven D'Aprano: > So I'm not really sure what you are trying to describe. I guess it might be > something like this: > > def spam(alist): > if alist: > process(alist) > else: > print("empty list") > > > If you pass 1 instead of an actual list, then you don't get an error until > somewhere inside process(). Potentially far, far away. So you want to > write: > > def spam(alist): > if len(alist): > process(alist) # requires an actual list > else: > print("empty list") > > > and now calling spam(1) will raise immediately. Great. > > But that's not really anything to do with *bools* specifically. If you call > spam() with a dict, or a set, or a tuple, or a RedBlackTree, any other > object with a length, you're no better off. If you absolutely need a list, > and nothing else, then you have to type-check. Yes it has to do with the booly nature of python objects. The fact that your examples still allows for bugs, doesn't contradict it already cathes a lot of bugs. So yes I'm better of even if I am not completly save. Encouraging the user to write explicit test, will detect bugs sooner and will make it more probable the code behaves as expected even when the tests are done one an unexpected kind of object. > In practice, I don't see how truthy/falsey objects lead to more or worse > bugs than any other form of dynamic typing. Sure, this from a language that states that explicit is better than implicit. The truthy/falsy objects encourage people to be implicit and thus allowing a lot of things to pass that were originally not though off. > To me, your position is equivalent to saying that dynamic typing and > duck-typing is really great, except for len(). len() should absolutely only > work on lists, and nothing else, so any time you want to get the length of > an object, you must work with real lists, not listy sequences: > > if len(list(mystring)) > 20: ... > > print(len(list(mydict.keys())), "items") > > > etc. Substitute "bool" for "len" and you might understand how I feel about > your position. IMO, bool is like you would give any object a lengthy nature and so having any object also behave like a tuple with the object as it's only item. Then bool and len would be similar. -- Antoon. From random832 at fastmail.com Thu Jun 23 09:26:36 2016 From: random832 at fastmail.com (Random832) Date: Thu, 23 Jun 2016 09:26:36 -0400 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <576bae4c$0$11112$c3e8da3@news.astraweb.com> <576BB841.1080603@rece.vub.ac.be> <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1466688396.209067.646331185.5781BCE7@webmail.messagingengine.com> On Thu, Jun 23, 2016, at 08:37, Steven D'Aprano wrote: > You keep saying that, but I've never seen it happen. I've seen cases > where people have been surprised by the unexpected truthiness of an > object ("I expected an exhausted iterator to be false, but it was > true"), but that's not what you seem to be describing. I suspect that he's referring to cases like http://bugs.python.org/issue4945 where a set of flags that are expected to be bool under normal circumstances are interchangeably tested with ==, is, boolean checks, and the inversion of any of those. If you test with "== True", then you treat 2 as non-truthy. If you test with "is True", then you treat 1 as non-truthy. And the reverse of either may treat 0 as truthy. If you mix and match any truth-test (e.g. "== True") with anything that is not its opposite ("!= True", not e.g. "== False") you may end up with situations where neither branch was taken and your result is an unexpected state. I don't actually agree with him that the object being passed in can be blamed for this class of error. It also occurs to me you could conceivably run into problems if you use a passed-in mutable object as a flag to be tested multiple times. > The bottom line is, bools offer only a single major API[1]: are they > truthy, or falsey? What else can do you with them? Nothing. They > support conditional branches, and boolean operators "or" and "and". > That's all. They don't have methods to call, or attributes to set. You > can use a bool to take the if branch, or the else branch, and that's > effectively all. Don't forget, they're integers valued 0 and 1. So you can multiply it by a number to get 0 or that number. I recently did so (in a code golf challenge, not serious code). You can sum an iterable of them to get a count of true items. From ben.usenet at bsb.me.uk Thu Jun 23 10:37:48 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 23 Jun 2016 15:37:48 +0100 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d1n8j7ib.fsf@bsb.me.uk> Steven D'Aprano writes: > On Thu, 23 Jun 2016 05:17 am, Ben Bacarisse wrote: > >> pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes: >> >>> Ben Bacarisse wrote: >>> >>>> >>> math.atan2(INF, INF) >>>> 0.7853981633974483 >>>> >>>> I would have expected NaN since atan2(INF, INF) could be thought of as >>>> the limit of atan2(x, y) which could be any value in the range. And I'd >>>> have guessed atan2(0, 0) would have been NaN too but >>> >>> i'm not a math expert, but the limit of atan2 would be 45?, so pi/4 >>> radians (0,7854). >>> As x,y are coordinates, the both infinite would tend toward 45?. >> >> The limit of atan2(x, x) is as you describe, but there is no reason to >> pick that one case. > > Given: > > x = INF > y = INF > assert x == y > > there is a reason to pick atan2(y, x) = pi/4: > > Since x == y, the answer should be the same as for any other pair of x == y. > > It might not be a *great* reason, but it's a reason. ...provided you consider atan2(0, 0) == 0 to be a bug! -- Ben. From ben.usenet at bsb.me.uk Thu Jun 23 10:39:43 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 23 Jun 2016 15:39:43 +0100 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877fdgj7f4.fsf@bsb.me.uk> Steven D'Aprano writes: > On Thursday 23 June 2016 14:40, Dan Sommers wrote: > >>> Since x == y, the answer should be the same as for any other pair of x == y. >> >> When x == y == 0, then atan2(y, x) is 0. I see just added noise by making the same comment before reading the rest of the thread. Sorry. > /s/any other pair of x == y/any other pair of x y except for zero/ > > :-P > > > Zero is exceptional in many ways. whereas infinity... :-) -- Ben. From alister.ware at ntlworld.com Thu Jun 23 11:04:44 2016 From: alister.ware at ntlworld.com (alister) Date: Thu, 23 Jun 2016 15:04:44 GMT Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> Message-ID: On Thu, 23 Jun 2016 15:39:43 +0100, Ben Bacarisse wrote: > Steven D'Aprano writes: > >> On Thursday 23 June 2016 14:40, Dan Sommers wrote: >> >>>> Since x == y, the answer should be the same as for any other pair of >>>> x == y. >>> >>> When x == y == 0, then atan2(y, x) is 0. > > I see just added noise by making the same comment before reading the > rest of the thread. Sorry. > >> /s/any other pair of x == y/any other pair of x y except for zero/ >> >> :-P >> >> >> Zero is exceptional in many ways. > > whereas infinity... :-) which infinity. There are many - some larger than others -- | |-sshd---tcsh-+-dpkg-buildpacka---rules---sh---make---make---sh--- make---sh---make---sh---make---sh---make---sh---make -- While packaging XFree86 for Debian GNU/Linux From HooDunnit at didly42KahZidly.net Thu Jun 23 11:11:40 2016 From: HooDunnit at didly42KahZidly.net (Cousin Stanley) Date: Thu, 23 Jun 2016 08:11:40 -0700 Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> <4d2803c0-9bc9-4ae5-b5dd-96bb113b7ba1@googlegroups.com> Message-ID: DFS wrote: > Here's a fun one: scraping data off a website, > and storing it in a SQLite database file. > .... After testing your example code here I found that the length of the categories list was 1 less than the terms list after applying dropwords in the terms list comprehension .... The subsequent len comparison then failed and no data was inserted into the data base .... As a fix I added an extra category .... category.append( 'didly' ) Subsequently, data was inserted with a single extra category for the last term in terms .... Thanks for posting the example code .... -- Stanley C. Kitching Human Being Phoenix, Arizona From rosuav at gmail.com Thu Jun 23 11:49:19 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jun 2016 01:49:19 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <576bae4c$0$11112$c3e8da3@news.astraweb.com> <576BB841.1080603@rece.vub.ac.be> <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jun 23, 2016 at 10:37 PM, Steven D'Aprano wrote: > I acknowledge, cheerfully, that there might be a mismatch between what you > expect and what the object actually does. "I expect empty containers to be > falsey, and non-empty ones to be truthy; but this RedBlackTree object is > always false even if it has many items; and this SortedDict is always true > even when it is empty." > > That's a nuisance and a pain when it happens, but it's arguably a bug in the > object or at least a misfeature... As evidenced by the change to time truthiness, yes, that's the object's fault. If your RedBlackTree object were always *true*, I'd call it a missing feature ("please add a __bool__ that distinguishes empty trees from trees with content"), but always *false* would be a bug. A SortedDict implies by its name that it should be extremely dict-like, so that would be a strong argument for its truthiness to follow a dict's. Either way, the misbehaviour gets pointed back at the object in question. ChrisA From bc at freeuk.com Thu Jun 23 11:52:11 2016 From: bc at freeuk.com (BartC) Date: Thu, 23 Jun 2016 16:52:11 +0100 Subject: Break and Continue: While Loops In-Reply-To: References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On 23/06/2016 12:39, Chris Angelico wrote: > On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: >> Actually pretty much any expression can be used, because Python can >> interpret almost anything as either True or False. Don't ask for the rules >> because they can be complicated, but for example, zero is False, and any >> other number is True. I think. > > The rules are very simple. Anything that represents "something" is > true, and anything that represents "nothing" is false. An empty > string, an empty list, an empty set, and the special "None" object > (generally representing the absence of some other object) are all > false. A string with something in it (eg "Hello"), a list with > something in it (eg [1,2,4,8]), etc, etc, are all true. Maybe I was thinking of 'is' where sometimes the results are unintuitive. But even with ordinary conditionals, False is False, but [False] is True. And [] is False, while [[]] is True. A class instance is always True, even when empty. And then "False" is True as well! -- Bartc From rosuav at gmail.com Thu Jun 23 12:23:11 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jun 2016 02:23:11 +1000 Subject: Break and Continue: While Loops In-Reply-To: References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On Fri, Jun 24, 2016 at 1:52 AM, BartC wrote: > On 23/06/2016 12:39, Chris Angelico wrote: >> >> On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: >>> >>> Actually pretty much any expression can be used, because Python can >>> interpret almost anything as either True or False. Don't ask for the >>> rules >>> because they can be complicated, but for example, zero is False, and any >>> other number is True. I think. >> >> >> The rules are very simple. Anything that represents "something" is >> true, and anything that represents "nothing" is false. An empty >> string, an empty list, an empty set, and the special "None" object >> (generally representing the absence of some other object) are all >> false. A string with something in it (eg "Hello"), a list with >> something in it (eg [1,2,4,8]), etc, etc, are all true. > > > But even with ordinary conditionals, False is False, but [False] is True. > And [] is False, while [[]] is True. A class instance is always True, even > when empty. And then "False" is True as well! [False] is a list with something in it. So is [[]]. "False" is a string with something in it, and honestly, if you think that ought to come out falsey, you're asking for magic. I don't know what you mean by a "class instance", or how it would be empty, but if you're creating a custom class and it might sometimes represent emptiness, you need to define either __len__ or __bool__ so the interpreter can understand what you mean by "empty". > Maybe I was thinking of 'is' where sometimes the results are unintuitive. > Not at all. The 'is' operator tells you whether the left and right operands are the same object. That's it. Maybe you have unintuitive situations where you don't realize you have the same object (or don't realize you have different objects), but the operator itself still has one very simple rule to follow. ChrisA From HooDunnit at didly42KahZidly.net Thu Jun 23 12:39:47 2016 From: HooDunnit at didly42KahZidly.net (Cousin Stanley) Date: Thu, 23 Jun 2016 09:39:47 -0700 Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> <4d2803c0-9bc9-4ae5-b5dd-96bb113b7ba1@googlegroups.com> Message-ID: DFS wrote: > On 6/23/2016 11:11 AM, Cousin Stanley wrote: >> DFS wrote: >> >>> Here's a fun one: scraping data off a website, >>> and storing it in a SQLite database file. >>> .... >> >> After testing your example code here I found >> that the length of the categories list >> was 1 less than the terms list after applying >> dropwords in the terms list comprehension .... >> >> The subsequent len comparison then failed >> and no data was inserted into the data base .... >> >> As a fix I added an extra category .... >> >> category.append( 'didly' ) >> >> Subsequently, data was inserted >> with a single extra category >> for the last term in terms .... > > > Strange! After dropwords, the list lengths match > for me (both are 152). > Found 153 for terms and 152 for categories, so I appended 1 to categories ... > So in your table, is 'didly' now the category for the last term > 'Rendering'? Mine is 'Technical', as it is on the source webpage. Last 5 printed from the final loop just before the db insert .... .... Passphrase , Technical Passcode , Technical Touchpad , Hardware Rendering , Technical Terms of Use , didly > > I usually put list length tests in place, > not sure what happened here. Possibly a copy/paste difference on my end .... -- Stanley C. Kitching Human Being Phoenix, Arizona From steve at pearwood.info Thu Jun 23 12:43:01 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 24 Jun 2016 02:43:01 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <576bae4c$0$11112$c3e8da3@news.astraweb.com> <576BB841.1080603@rece.vub.ac.be> <576bd818$0$1619$c3e8da3$5496439d@news.astraweb.com> <1466688396.209067.646331185.5781BCE7@webmail.messagingengine.com> Message-ID: <576c1197$0$1597$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Jun 2016 11:26 pm, Random832 wrote: > On Thu, Jun 23, 2016, at 08:37, Steven D'Aprano wrote: >> You keep saying that, but I've never seen it happen. I've seen cases >> where people have been surprised by the unexpected truthiness of an >> object ("I expected an exhausted iterator to be false, but it was >> true"), but that's not what you seem to be describing. > > I suspect that he's referring to cases like > http://bugs.python.org/issue4945 where a set of flags that are expected > to be bool under normal circumstances are interchangeably tested with > ==, is, boolean checks, and the inversion of any of those. > > If you test with "== True", then you treat 2 as non-truthy. If you test > with "is True", then you treat 1 as non-truthy. And the reverse of > either may treat 0 as truthy. If you mix and match any truth-test (e.g. > "== True") with anything that is not its opposite ("!= True", not e.g. > "== False") you may end up with situations where neither branch was > taken and your result is an unexpected state. Yeah, we can write crap code in Python if you try :-) > I don't actually agree with him that the object being passed in can be > blamed for this class of error. Nor do I. I think that's a clear case where the solution is to stop writing awful code. We've all gone through a period were the nicest thing one might say about our coding is "you don't really understand what you are doing". Some of my earliest code was nearly as bad. > It also occurs to me you could conceivably run into problems if you use > a passed-in mutable object as a flag to be tested multiple times. Indeed, but I expect that's more of a theoretical risk than a practical risk. And, who knows, somebody might find a use for it, to win a bet, for a code golf competition, or just because they like writing "clever" code: flag = [] if condition: flag.append(None) else: flag.pop() Could be useful. But beware of overly clever code. >> The bottom line is, bools offer only a single major API[1]: are they >> truthy, or falsey? What else can do you with them? Nothing. They >> support conditional branches, and boolean operators "or" and "and". >> That's all. They don't have methods to call, or attributes to set. You >> can use a bool to take the if branch, or the else branch, and that's >> effectively all. > > Don't forget, they're integers valued 0 and 1. So you can multiply it by > a number to get 0 or that number. I recently did so (in a code golf > challenge, not serious code). You can sum an iterable of them to get a > count of true items. I would never forget they're also ints. I think I even mentioned that in the footnote. -- Steven From steve at pearwood.info Thu Jun 23 12:44:54 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 24 Jun 2016 02:44:54 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> Message-ID: <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Jun 2016 01:04 am, alister wrote: > which infinity. There are many - some larger than others China has just announced a new supercomputer that is so fast it can run an infinite loop in 3.7 seconds. -- Steven From pdorange at pas-de-pub-merci.mac.com Thu Jun 23 13:07:43 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Thu, 23 Jun 2016 19:07:43 +0200 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1mpaezs.1cjd2qlsezghsN%pdorange@pas-de-pub-merci.mac.com> Dan Sommers wrote: > > Given: > > > > x = INF > > y = INF > > assert x == y > > > > there is a reason to pick atan2(y, x) = pi/4: > > > > Since x == y, the answer should be the same as for any other pair of x == y. > > When x == y == 0, then atan2(y, x) is 0. This is the only solution (0) where atan2 return sometime else than pi/4. And INF is not 0, it can be lot of values, but not zero. Yes x=INF and y=INF do not mean x=y (in math world) but INF is a frontier that can be reach, so it tend to the maximum value. So the tendancy is always atan2(y,x) tend to pi/4 if you looks at lot od y and x that will be grater and greater each time : the final frontier would always be pi/4, even if t take a long time to reach it. -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From 8smolen at tds.net Thu Jun 23 13:11:40 2016 From: 8smolen at tds.net (Michael Smolen) Date: Thu, 23 Jun 2016 11:11:40 -0600 Subject: Setting up Python WinXP References: <9A23634ACEF945E0A0370DE977E54348@mike> Message-ID: <6E0FE78BB13043F195A91C3B329D5622@mike> Zach and friends: I am beginning to learn how to install something like Linux Mint on an old box from about 2006. That will be my programming machine for Python and Perl. I can't abandon XP because other projects are in process and my old brain can't handle converting everything at this time. Progress is great until it passes you long ago, then you just have to stay afloat. Gulp, gulp, gulp... thanks. mike ----- Original Message ----- From: "Zachary Ware" To: Cc: "Michael Smolen" <8smolen at tds.net> Sent: Wednesday, June 22, 2016 11:19 AM Subject: Re: Setting up Python WinXP Hi Michael, On Wed, Jun 22, 2016 at 11:41 AM, Michael Smolen <8smolen at tds.net> wrote: > Folks: > I can't wait to start programming with Python. Welcome to Python! > However, I am having difficulty installing on my XP operating system. This unsolicited advice is rather beside the point, but I would highly recommend moving away from XP if you have any say in the matter. Linux Mint (or other distro of your choice) is easy to install and use, is free in whatever sense of the word you'd like to use, and will be much more secure than XP, which is no longer supported by Microsoft (this is why it's not supported by Python 3.5+, either). An upgrade to a newer version of Windows is also a good idea, but more costly. > I downloaded Python-3.4.5ci I'm not sure what you mean by 3.4.5ci; do you mean 3.4.5rc1? 3.4.5rc1 is pre-release software; 3.4.5 will be released in a week or so. However, it won't include binary installers for Windows since Python 3.4 is now in security-fix-only mode. > as that seems like the version that will run on my operating system. The > latest version will not as per mention on the website. I downloaded the > compacted version (*.tar), converted it to a *.tgz and extracted the > software into a folder Python-3.4.5ci. That subdirectory contains numerous > files (11) and 13 subdirectories. The README file states that "On Windows, > see PCbuild/readme.txt.". That link was not found. > > So, I am clueless on what I need to do to successfully install Python3.4 > on my computer. Any advice would be greatly appreciated. If you're stuck with XP, stick with Python 3.4.4, and download the installer from here: https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi Hope this helps, -- Zach From pdorange at pas-de-pub-merci.mac.com Thu Jun 23 13:14:06 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Thu, 23 Jun 2016 19:14:06 +0200 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> Steven D'Aprano wrote: > > which infinity. There are many - some larger than others > > China has just announced a new supercomputer that is so fast it can run an > infinite loop in 3.7 seconds. Near a black hole 3.7 seconds can last an infinite time... -- Pierre-Alain Dorange Ce message est sous licence Creative Commons "by-nc-sa-2.0" From marko at pacujo.net Thu Jun 23 13:22:11 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 23 Jun 2016 20:22:11 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <87shw3es70.fsf@elektro.pacujo.net> pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange): > Steven D'Aprano wrote: >> China has just announced a new supercomputer that is so fast it can >> run an infinite loop in 3.7 seconds. > > Near a black hole 3.7 seconds can last an infinite time... Which phenomenon prevents a black hole from ever forming. Yet astronomers keep telling us they are all over the place. Oppenheimer and his co-authors interpreted the singularity at the boundary of the Schwarzschild radius as indicating that this was the boundary of a bubble in which time stopped. This is a valid point of view for external observers, but not for infalling observers. Because of this property, the collapsed stars were called "frozen stars", because an outside observer would see the surface of the star frozen in time at the instant where its collapse takes it inside the Schwarzschild radius. Note that the "valid point of view for external observers" is the only valid scientific point of view. Marko From gordon at panix.com Thu Jun 23 13:34:33 2016 From: gordon at panix.com (John Gordon) Date: Thu, 23 Jun 2016 17:34:33 +0000 (UTC) Subject: Break and Continue: While Loops References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: In <639b00e0-7b9d-4ed4-96ad-6afbcd536786 at googlegroups.com> Elizabeth Weiss writes: > i=0 > while 1==1: > print(i) > i=i+1 > if i>=5: > print("Breaking") > break > Why is Breaking going to be printed if i only goes up to 4? Your code prints i and THEN adds one to it. So i is 4, it gets printed, then 1 is added to it, so it becomes 5 and then the loop exits. -- 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 joel.goldstick at gmail.com Thu Jun 23 15:00:08 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 23 Jun 2016 15:00:08 -0400 Subject: Setting up Python WinXP In-Reply-To: <6E0FE78BB13043F195A91C3B329D5622@mike> References: <9A23634ACEF945E0A0370DE977E54348@mike> <6E0FE78BB13043F195A91C3B329D5622@mike> Message-ID: On Thu, Jun 23, 2016 at 1:11 PM, Michael Smolen <8smolen at tds.net> wrote: > Zach and friends: > I am beginning to learn how to install something like Linux Mint on an old > box from about 2006. That will be my programming machine for Python and > Perl. I can't abandon XP because other projects are in process and my old > brain can't handle converting everything at this time. Progress is great > until it passes you long ago, then you just have to stay afloat. Gulp, gulp, > gulp... thanks. > mike > ----- Original Message ----- From: "Zachary Ware" > > To: > Cc: "Michael Smolen" <8smolen at tds.net> > Sent: Wednesday, June 22, 2016 11:19 AM > Subject: Re: Setting up Python WinXP > > > > Hi Michael, > > On Wed, Jun 22, 2016 at 11:41 AM, Michael Smolen <8smolen at tds.net> wrote: >> >> Folks: >> I can't wait to start programming with Python. > > > Welcome to Python! > >> However, I am having difficulty installing on my XP operating system. > > > This unsolicited advice is rather beside the point, but I would highly > recommend moving away from XP if you have any say in the matter. > Linux Mint (or other distro of your choice) is easy to install and > use, is free in whatever sense of the word you'd like to use, and will > be much more secure than XP, which is no longer supported by Microsoft > (this is why it's not supported by Python 3.5+, either). An upgrade > to a newer version of Windows is also a good idea, but more costly. > >> I downloaded Python-3.4.5ci > > > I'm not sure what you mean by 3.4.5ci; do you mean 3.4.5rc1? 3.4.5rc1 > is pre-release software; 3.4.5 will be released in a week or so. > However, it won't include binary installers for Windows since Python > 3.4 is now in security-fix-only mode. > >> as that seems like the version that will run on my operating system. The >> latest version will not as per mention on the website. I downloaded the >> compacted version (*.tar), converted it to a *.tgz and extracted the >> software into a folder Python-3.4.5ci. That subdirectory contains numerous >> files (11) and 13 subdirectories. The README file states that "On Windows, >> see PCbuild/readme.txt.". That link was not found. >> >> So, I am clueless on what I need to do to successfully install Python3.4 >> on my computer. Any advice would be greatly appreciated. > > > If you're stuck with XP, stick with Python 3.4.4, and download the > installer from here: > https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi > > Hope this helps, > -- > Zach > -- > https://mail.python.org/mailman/listinfo/python-list Linux works well on old machines. However, Lubuntu is a scaled down Ubuntu version designed to run on older hardware (the GUI isn't as fancy). and I am using it on a dell from 2008 with 4gigs ram. Works fine. You can download the image and burn to cd or usb stick -- whichever your machine will allow you to boot from. You'll be up in an hour or so -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From ben.usenet at bsb.me.uk Thu Jun 23 15:04:36 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 23 Jun 2016 20:04:36 +0100 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> Message-ID: <87vb0ziv5n.fsf@bsb.me.uk> alister writes: > On Thu, 23 Jun 2016 15:39:43 +0100, Ben Bacarisse wrote: > >> Steven D'Aprano writes: >> >>> On Thursday 23 June 2016 14:40, Dan Sommers wrote: >>> >>>>> Since x == y, the answer should be the same as for any other pair of >>>>> x == y. >>>> >>>> When x == y == 0, then atan2(y, x) is 0. >> >> I see just added noise by making the same comment before reading the >> rest of the thread. Sorry. >> >>> /s/any other pair of x == y/any other pair of x y except for zero/ >>> >>> :-P >>> >>> >>> Zero is exceptional in many ways. >> >> whereas infinity... :-) > > which infinity. There are many - some larger than others The one in the post up thread now (sadly) snipped. It's not a mathematical infinity at all but a particular floating point representation that results from float("inf"). However it is still just as "exceptional in many ways" as zero. (Sorry if you were making a joke and I didn't get it.) -- Ben. From davidgshi at yahoo.co.uk Thu Jun 23 16:29:04 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 23 Jun 2016 20:29:04 +0000 (UTC) Subject: Pandas to CSV and .dbf References: <373106267.937435.1466713744207.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <373106267.937435.1466713744207.JavaMail.yahoo@mail.yahoo.com> Has anyone tested on Pandas to CSV and .dbf lately? I am looking for proven, tested examples to output Panda Data Frame to CSV and dbf files. Looking forward to hearing from you. Regards. David From davidgshi at yahoo.co.uk Thu Jun 23 16:57:21 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 23 Jun 2016 20:57:21 +0000 (UTC) Subject: Which one is the best XML-parser? References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Which one is the best XML-parser? Can any one tell me? Regards. David From davidgshi at yahoo.co.uk Thu Jun 23 16:58:15 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 23 Jun 2016 20:58:15 +0000 (UTC) Subject: Which one is the best JSON parser? References: <1150800609.939828.1466715495931.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1150800609.939828.1466715495931.JavaMail.yahoo@mail.yahoo.com> Can any one tell me? Regards. David From python at mrabarnett.plus.com Thu Jun 23 18:46:50 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Jun 2016 23:46:50 +0100 Subject: Which one is the best JSON parser? In-Reply-To: <1150800609.939828.1466715495931.JavaMail.yahoo@mail.yahoo.com> References: <1150800609.939828.1466715495931.JavaMail.yahoo.ref@mail.yahoo.com> <1150800609.939828.1466715495931.JavaMail.yahoo@mail.yahoo.com> Message-ID: On 2016-06-23 21:58, David Shi via Python-list wrote: > Can any one tell me? > Regards. > David > There's one in the standard library. From steve at pearwood.info Thu Jun 23 21:00:39 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 24 Jun 2016 11:00:39 +1000 Subject: the global keyword: References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> Message-ID: <576c863a$0$1598$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Jun 2016 07:24 pm, BartC wrote: [...] > But even if it worked, I don't think this two-parter counts as a 'global > variable' as it is understood. I might as well just create my own G > module containing: > > BDFL="GvR" > > and import it in both A and B. Then I can also write G.BDFL in those > modules. But remember the point was avoid having to write Test.test_var. The question "Does Python have global variables?" depends on what you mean by "global variable". That makes it a dispute about definitions, and we know how they go: http://lesswrong.com/lw/np/disputing_definitions/ So what do *I* mean by global variables? To me, a global variable is a variable which is scoped to a level wider than any single function, i.e. module scope, or whole-application scope. That is, the variable must be visible to more than one function, or more than one module. But further, you must be able to *assign* to that variable with a simple assignment, without explicitly prefixing the variable with a namespace: foo = 1 It is okay if you have to declare that the variable is global before assigning to it. So to me, Python has module globals, because you can have two functions in the one module which both assign to the same variable: def spam(): global x x = 1 def ham(): global x x = 2 x is a global variable. But Python *doesn't* have application-wide globals, because although you can access a variable across multiple modules at the same time, you cannot do so without using the fully-qualified name module.x rather than just x. (To be precise, for the builtins module specifically, you can *read* the value of the variable using just x, but you cannot *assign* to it unless you use the fully-qualified name builtins.x.) If Rick wishes to argue for a different definition of "global variable", Rick should explain what his definition is, and why we should prefer it to mine. -- Steven From rosuav at gmail.com Thu Jun 23 21:19:52 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jun 2016 11:19:52 +1000 Subject: the global keyword: In-Reply-To: <576c863a$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> <576c863a$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 24, 2016 at 11:00 AM, Steven D'Aprano wrote: > To me, a global variable is a variable which is scoped to a level wider than > any single function, i.e. module scope, or whole-application scope. That > is, the variable must be visible to more than one function, or more than > one module. ... and not part of a closure, because they're not global. (I'd also say "nor part of an object", but objects in Python have attributes accessed using 'self.', so your other check removes that. But in C++, that would need to be another criterion.) ChrisA From flebber.crue at gmail.com Thu Jun 23 21:34:16 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 18:34:16 -0700 (PDT) Subject: My Generator yields a dictionary. Return entire file not specified key, value Message-ID: When I am running my file which takes a file off the command line reads it and creates an objecitifed xml instance and then parses for each attribute into a dictionary and then yields it. At this point I am tring to use it to obtain specific key value elements, however I keep being returned the whole file output rather than the selection key.really not sure where I am going wrong. The key part of my file that is using the generator is for item in parseXML(): number = item["number"] print(number) Rest of file for reference ================================================================================ from lxml import objectify import argparse import os parser = argparse.ArgumentParser() parser.add_argument("path", type=str, nargs="+") parser.add_argument('-e', '--extension', default='', help='File extension to filter by.') args = parser.parse_args() name_pattern = "*" + args.extension my_dir = args.path[0] for dir_path, subdir_list, file_list in os.walk(my_dir): for name_pattern in file_list: full_path = os.path.join(dir_path, name_pattern) def getsMeet(file_list): """generator which yields sorted file.""" for filename in sorted(file_list): filename = my_dir + filename yield filename def parseXML(): """ given a file XML will parse for listed attributes. using objectified lxml """ for file in getsMeet(file_list): with open(file, "rb") as f: xml = f.read() root = objectify.parse(xml) atts = ("number", "id", "horse", "saddlecloth", "barrier", "weight", "rating", "description", "colours", "owners", "dob", "age", "sex", "career", "thistrack", "thisdistance", "goodtrack", "heavytrack", "finished", "weightvariation", "variedweight", "decimalmargin", "penalty", "pricestarting") for sample in root.xpath('//race/nomination'): noms = (dict(zip(atts, map(sample.attrib.get, atts)))) yield noms for item in parseXML(): number = item["number"] print(number) ================================================================================ Thanks Sayth From flebber.crue at gmail.com Thu Jun 23 21:34:57 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 18:34:57 -0700 (PDT) Subject: Which one is the best XML-parser? In-Reply-To: References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Message-ID: <9a8eaee4-579a-4c33-9c97-55f455d9197a@googlegroups.com> On Friday, 24 June 2016 07:03:18 UTC+10, David Shi wrote: > Which one is the best XML-parser? > Can any one tell me? > Regards. > David xml parser most use lxml http://lxml.de/index.html Sayth From flebber.crue at gmail.com Thu Jun 23 21:35:38 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 18:35:38 -0700 (PDT) Subject: Which one is the best XML-parser? In-Reply-To: References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Message-ID: <0298a770-6d7f-41c6-bbe8-05e5c8f0793e@googlegroups.com> On Friday, 24 June 2016 07:03:18 UTC+10, David Shi wrote: > Which one is the best XML-parser? > Can any one tell me? > Regards. > David Most use lxml http://lxml.de/index.html Sayth From flebber.crue at gmail.com Thu Jun 23 21:41:58 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 18:41:58 -0700 (PDT) Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: <2beab3fc-0169-4b4d-8e1b-f17d7a22dbc0@googlegroups.com> On Tuesday, 21 June 2016 21:03:28 UTC+10, Pushpanth Gundepalli wrote: > Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. Here are some good beginner projects https://knightlab.northwestern.edu/2014/06/05/five-mini-programming-projects-for-the-python-beginner/ Also a community on reddit and github are trying to acheive this. https://learnprogramming.github.io/ https://github.com/LearnProgramming Sayth From eryksun at gmail.com Thu Jun 23 22:19:57 2016 From: eryksun at gmail.com (eryk sun) Date: Fri, 24 Jun 2016 02:19:57 +0000 Subject: the global keyword: In-Reply-To: <576c863a$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <646e9ff9-b5a1-4403-b79a-694397e34b0b@googlegroups.com> <1466529321.3842871.644317377.08527069@webmail.messagingengine.com> <195658b2-e1b2-4c91-8ff8-bd58379e700f@googlegroups.com> <576c863a$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 24, 2016 at 1:00 AM, Steven D'Aprano wrote: > To be precise, for the builtins module specifically, you can *read* the > value of the variable using just x, but you cannot *assign* to it unless > you use the fully-qualified name builtins.x. FWIW, you can execute code in any dict: >>> import builtins >>> exec(r''' ... foo = 'bar' ... ''', vars(builtins)) >>> builtins.foo 'bar' The frame for an unoptimized CPython code object (used for modules and the class statement) uses f_builtins, f_globals, and f_locals dicts (or possibly a mapping in the case of f_locals) respectively for its builtin, global, and local scopes. The frame for an optimized code object uses a fast locals array instead of f_locals, in which case the locals() function stores a snapshot of the locals to the f_locals dict. A frame may also have a freevars array, which has cell objects for closures (i.e. the nonlocal scope). For optimized code (i.e. a function, but not a class body), locals() also includes a snapshot of nonlocals, even though this doesn't make literal sense. The above example executes code with all 3 scopes set to the same dict. For example: >>> exec(r''' ... import sys ... f = sys._getframe() ... print(f.f_builtins is f.f_globals is f.f_locals) ... ''', vars(builtins)) True The CPython VM doesn't have an operation to store to the builtin scope, since the language doesn't have a statement such as "builtin" to declare a variable in this scope. The builtin scope is used as a fallback for operations such as LOAD_NAME and LOAD_GLOBAL -- for loading constants such as built-in functions, exceptions, __debug__, and also the "_" attribute that gets updated by sys.displayhook. From jladasky at itu.edu Thu Jun 23 22:26:30 2016 From: jladasky at itu.edu (jladasky at itu.edu) Date: Thu, 23 Jun 2016 19:26:30 -0700 (PDT) Subject: PyQt5: is the wrapper incomplete? In-Reply-To: References: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> <5762522D.6060804@telenet.be> Message-ID: <260274f6-b3b2-49e0-bb16-27b8866401b2@googlegroups.com> On Thursday, June 16, 2016 at 12:16:21 AM UTC-7, Vincent Vande Vyvre wrote: > On Debian, this is a separate package python3-pyqt5.qtserialport Many thanks, Vincent, that was exactly what I needed! From tiglathsuriol at gmail.com Thu Jun 23 22:32:30 2016 From: tiglathsuriol at gmail.com (Tiglath Suriol) Date: Thu, 23 Jun 2016 19:32:30 -0700 (PDT) Subject: Running yum/apt-get from a virtualenv Message-ID: <86872401-7d4b-4979-9fba-351e41848aa4@googlegroups.com> Let us say that I install PostgreSQL from an activated virtualenv using yum or apt-get, will PostgrSQL be local or global? I understand that virtualenv isolates the Python environment only, so I surmise that it will make no difference installing with yum/apt-get inside or outside the virtualenv. But that would not be the case with say Psycopg2 which would be isolated in the virtualenv, because it is a Python module. Is that right? Thanks From jladasky at itu.edu Thu Jun 23 22:40:42 2016 From: jladasky at itu.edu (jladasky at itu.edu) Date: Thu, 23 Jun 2016 19:40:42 -0700 (PDT) Subject: PyQt5: is the wrapper incomplete? In-Reply-To: References: <7a8f722a-f4e6-419e-ab0e-982754ad0df9@googlegroups.com> <5762522D.6060804@telenet.be> Message-ID: <272b06d8-3404-4121-b601-78b1041d649d@googlegroups.com> On Thursday, June 16, 2016 at 12:16:21 AM UTC-7, Vincent Vande Vyvre wrote: > On Debian, this is a separate package python3-pyqt5.qtserialport, I > don't know for other Linux > > After install you can use: > > from PyQt5.QtSeriaPort import QSerialPort Thank you Vincent, that is exactly what I needed! From jobmattcon at gmail.com Thu Jun 23 23:57:35 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Thu, 23 Jun 2016 20:57:35 -0700 (PDT) Subject: program return killed after run a very long time Message-ID: <94693872-2b7b-48cb-8a4e-d8c59218cf1c@googlegroups.com> i suspect it use so much memory, however i have already assign 30GB memory in openstack cloud is there any command to allow python to use more memory? currently program return killed after run a very long time From flebber.crue at gmail.com Thu Jun 23 23:59:59 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 20:59:59 -0700 (PDT) Subject: I seem to be creating a dict that I cannot access the keys of Message-ID: <8c9b5b13-c6cc-458d-9d31-56f7e5db10c4@googlegroups.com> Really getting a little lost here with lxml. I cannot seem to create a dict of results using xpath or other that I could easily get the results from, currently I am always returned a printed copy of the whole file regardless of what parsing options I do. Can I ask is there something obvious wrong, i have left the commented other versions in they "work" in that they all produce the same output the print whole file. def parseXML(): """ given a file XML will parse for listed attributes. using objectified lxml """ for file in getsMeet(file_list): with open(file, "rb") as f: xml = f.read() root = objectify.parse(xml) atts = ("number", "id", "horse", "saddlecloth", "barrier", "weight", "rating", "description", "colours", "owners", "dob", "age", "sex", "career", "thistrack", "thisdistance", "goodtrack", "heavytrack", "finished", "weightvariation", "variedweight", "decimalmargin", "penalty", "pricestarting") tree = etree.parse(StringIO(xml)) result = etree.tostring(tree.getroot(), pretty_print=True) for sample in result: noms = (dict(zip(atts, map(sample.attrib.get, atts)))) print(noms) # print(etree.tostring(tree.getroot())) # # for sample in root.xpath('//race/nomination'): # noms = (dict(zip(atts, map(sample.attrib.get, atts)))) # numbers = [(k, v) for k, v in noms.items()] # print(noms) # return numbers # parser = etree.XMLParser(root, remove_comments=True) # d = defaultdict(list) # for sample in parser.xpath('//race/nomination'): # print(sample) # for sample in root.xpath('//race/nomination'): # # print(sample) # dct = sample.attrib # for k in atts: # # print(k) # d[k].append(dct[k]) # print(d["number"]) return noms a = parseXML() for sample in a.items: print(sample["number"]) Confused Sayth From flebber.crue at gmail.com Fri Jun 24 00:02:26 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 21:02:26 -0700 (PDT) Subject: Which one is the best XML-parser? In-Reply-To: References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Message-ID: <26a63021-4979-4344-b023-b757c1c35609@googlegroups.com> On Friday, 24 June 2016 07:03:18 UTC+10, David Shi wrote: > Which one is the best XML-parser? > Can any one tell me? > Regards. > David Most would use lxml sayth From flebber.crue at gmail.com Fri Jun 24 00:07:39 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 21:07:39 -0700 (PDT) Subject: lxml parsing whole file, unable to access elements Message-ID: <3f2221d1-c2aa-4ba5-b9e3-3543d9643e9a@googlegroups.com> Hi I have created several versions of a parser for XML with lxml both objectify and lxml. They all work in that the parser returns the whole file however I cannot access elements or keys as I have tried to create a dict of the results to make it easier to put in an sql query later. However I keep receiving output as just the whole file, I have gone backwards since last time, learnt more however output is backwards. Is there something obvious here I am doing wrong, all I am intending to do as a first test is to get the result and then get the key "number" and return that key and all its values. i have left the commented versions in as well they all end in the same result to me. def parseXML(): """ given a file XML will parse for listed attributes. using objectified lxml """ for file in getsMeet(file_list): with open(file, "rb") as f: xml = f.read() root = objectify.parse(xml) atts = ("number", "id", "horse", "saddlecloth", "barrier", "weight", "rating", "description", "colours", "owners", "dob", "age", "sex", "career", "thistrack", "thisdistance", "goodtrack", "heavytrack", "finished", "weightvariation", "variedweight", "decimalmargin", "penalty", "pricestarting") tree = etree.parse(StringIO(xml)) result = etree.tostring(tree.getroot(), pretty_print=True) for sample in result: noms = (dict(zip(atts, map(sample.attrib.get, atts)))) print(noms) # print(etree.tostring(tree.getroot())) # # for sample in root.xpath('//race/nomination'): # noms = (dict(zip(atts, map(sample.attrib.get, atts)))) # numbers = [(k, v) for k, v in noms.items()] # print(noms) # return numbers # parser = etree.XMLParser(root, remove_comments=True) # d = defaultdict(list) # for sample in parser.xpath('//race/nomination'): # print(sample) # for sample in root.xpath('//race/nomination'): # # print(sample) # dct = sample.attrib # for k in atts: # # print(k) # d[k].append(dct[k]) # print(d["number"]) return noms a = parseXML() for sample in a.items: print(sample["number"]) confused Sayth From flebber.crue at gmail.com Fri Jun 24 00:10:31 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 21:10:31 -0700 (PDT) Subject: Which one is the best XML-parser? In-Reply-To: References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Friday, 24 June 2016 07:03:18 UTC+10, David Shi wrote: > Which one is the best XML-parser? > Can any one tell me? > Regards. > David Most use lxml Sayth From flebber.crue at gmail.com Fri Jun 24 00:18:26 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 21:18:26 -0700 (PDT) Subject: LXML cannot access elements of dict created Message-ID: <02172b38-a885-434a-bd03-e3b4248ab284@googlegroups.com> I have created several varitions of my parser however I am still having the same issue, ,my return is the whole file, not a key of the dict as i have attempted to access. Not really sure where I am going wrong with it. I have left previous implementations in however to show where I have come from, as a first test case i am trying to parse the file and then return the dict key numbers and all its values. def parseXML(): """ given a file XML will parse for listed attributes. using objectified lxml """ for file in getsMeet(file_list): with open(file, "rb") as f: xml = f.read() root = objectify.parse(xml) atts = ("number", "id", "horse", "saddlecloth", "barrier", "weight", "rating", "description", "colours", "owners", "dob", "age", "sex", "career", "thistrack", "thisdistance", "goodtrack", "heavytrack", "finished", "weightvariation", "variedweight", "decimalmargin", "penalty", "pricestarting") tree = etree.parse(StringIO(xml)) result = etree.tostring(tree.getroot(), pretty_print=True) for sample in result: noms = (dict(zip(atts, map(sample.attrib.get, atts)))) print(noms) # print(etree.tostring(tree.getroot())) # # for sample in root.xpath('//race/nomination'): # noms = (dict(zip(atts, map(sample.attrib.get, atts)))) # numbers = [(k, v) for k, v in noms.items()] # print(noms) # return numbers # parser = etree.XMLParser(root, remove_comments=True) # d = defaultdict(list) # for sample in parser.xpath('//race/nomination'): # print(sample) # for sample in root.xpath('//race/nomination'): # # print(sample) # dct = sample.attrib # for k in atts: # # print(k) # d[k].append(dct[k]) # print(d["number"]) return noms a = parseXML() for sample in a.items: print(sample["number"]) confused Sayth From flebber.crue at gmail.com Fri Jun 24 00:35:11 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 23 Jun 2016 21:35:11 -0700 (PDT) Subject: Which one is the best XML-parser? In-Reply-To: References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Message-ID: Lxml From dieter at handshake.de Fri Jun 24 02:39:47 2016 From: dieter at handshake.de (dieter) Date: Fri, 24 Jun 2016 08:39:47 +0200 Subject: Which one is the best XML-parser? References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Message-ID: <87r3bnrsy4.fsf@handshake.de> David Shi via Python-list writes: > Which one is the best XML-parser? "best" is not an absolute term but depends on criteria/conditions. There are essentially two kinds of parsers: incremental parsers which parse the structure and report events for everything they see and non-incremental parses which transform the complete XML into a data structure. You want an incremental parser if the XML documents are so huge that you must process them incrementally rather than have a data structure representing the whole document (in memory). Incremental parsers for XML are usually called "SAX" parsers. If your XML documents have moderate size, you might prefer a non-incremental parser. Personally, I like "lxml" (a binding to the "libxml2" C-library). It supports a lot of features: besides simple parsing, it supports verification against XML-schema and DTDs, XPath and XSLT-transforms. This means, with one XML tool you can handle all tasks typically encoutered with XML processing. However, "lxml" depends on an external C-library ("libxml2"). Therefore, it might be considered more difficult to install than "pure python" XML parsers. These examples show: "best" depends on your situation, your tasks and your preferences. From lorenzo.gatti at gmail.com Fri Jun 24 03:33:13 2016 From: lorenzo.gatti at gmail.com (lorenzo.gatti at gmail.com) Date: Fri, 24 Jun 2016 00:33:13 -0700 (PDT) Subject: Which one is the best XML-parser? In-Reply-To: References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> Message-ID: <46038a1b-e8ba-45b3-96bf-f83956232a87@googlegroups.com> On Thursday, June 23, 2016 at 11:03:18 PM UTC+2, David Shi wrote: > Which one is the best XML-parser? > Can any one tell me? > Regards. > David Lxml offers lxml.etree.iterparse (http://lxml.de/tutorial.html#event-driven-parsing), an important combination of the memory savings of incremental parsing and the convenience of visiting a DOM tree without dealing with irrelevant details. An iterable incrementally produces DOM element objects, which can be deleted after processing them and before proceeding to parse the rest of the document. This technique allows easy processing of huge documents containing many medium-size units of work whose DOM trees fit into memory easily. From arsh840 at gmail.com Fri Jun 24 03:46:49 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Fri, 24 Jun 2016 00:46:49 -0700 (PDT) Subject: not able to install mysqldb-python In-Reply-To: References: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> Message-ID: On Thursday, 23 June 2016 23:18:27 UTC+5:30, Joaquin Alzola wrote: > > ImportError: No module named 'ConfigParser' > It is telling you the error > 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. Thanks but somehow it fixed itself. :P now able to install mysql-python without any problem. From pdorange at pas-de-pub-merci.mac.com Fri Jun 24 03:53:16 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Fri, 24 Jun 2016 09:53:16 +0200 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> Message-ID: <1mpce0f.dt8b291rct6bkN%pdorange@pas-de-pub-merci.mac.com> Marko Rauhamaa wrote: > Note that the "valid point of view for external observers" is the only > valid scientific point of view. For a scientific point of view, right. But tell this to the one that will be close to a blackhole ;-) -- Pierre-Alain Dorange Moof Ce message est sous licence Creative Commons "by-nc-sa-2.0" From pdorange at pas-de-pub-merci.mac.com Fri Jun 24 03:53:16 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Fri, 24 Jun 2016 09:53:16 +0200 Subject: Break and Continue: While Loops References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: <1mpce3m.abqjct1yseoyaN%pdorange@pas-de-pub-merci.mac.com> BartC wrote: > But even with ordinary conditionals, False is False, but [False] is > True. And [] is False, while [[]] is True. A class instance is always > True, even when empty. And then "False" is True as well! "Empty" is not "Nothing". To be empty, something must exist first. -- Pierre-Alain Dorange Moof Ce message est sous licence Creative Commons "by-nc-sa-2.0" From jobmattcon at gmail.com Fri Jun 24 04:32:39 2016 From: jobmattcon at gmail.com (meInvent bbird) Date: Fri, 24 Jun 2016 01:32:39 -0700 (PDT) Subject: how to python to use virtual memory? Message-ID: <1268fa0b-aeb8-4562-a2b5-3ed0b8130d17@googlegroups.com> after set resource hard and soft both out of real memory 70GB to 100GB and expecting the extra memory setting using virtual memory which is hard disk, the program still wrongly be killed itself after running in background side From marko at pacujo.net Fri Jun 24 06:38:19 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 24 Jun 2016 13:38:19 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <1mpce0f.dt8b291rct6bkN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <87oa6qswh0.fsf@elektro.pacujo.net> pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange): > Marko Rauhamaa wrote: > >> Note that the "valid point of view for external observers" is the >> only valid scientific point of view. > > For a scientific point of view, right. But tell this to the one that > will be close to a blackhole ;-) Then, you'd better consult a priest than a scientist. Marko From random832 at fastmail.com Fri Jun 24 09:09:33 2016 From: random832 at fastmail.com (Random832) Date: Fri, 24 Jun 2016 09:09:33 -0400 Subject: Which one is the best XML-parser? In-Reply-To: <87r3bnrsy4.fsf@handshake.de> References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> <87r3bnrsy4.fsf@handshake.de> Message-ID: <1466773773.502497.647387441.16AAD74F@webmail.messagingengine.com> On Fri, Jun 24, 2016, at 02:39, dieter wrote: > You want an incremental parser if the XML documents are so huge that > you must process them incrementally rather than have a data structure > representing the whole document (in memory). Incremental parsers > for XML are usually called "SAX" parsers. You know what would be really nice? A "semi-incremental" parser that can e.g. yield (whether through an event or through the iterator protocol) a fully formed element (preferably one that can be queried with xpath) at a time for each record of a document representing a list of objects. Does anything like that exist? From marko at pacujo.net Fri Jun 24 09:16:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 24 Jun 2016 16:16:27 +0300 Subject: Which one is the best XML-parser? References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> <87r3bnrsy4.fsf@handshake.de> <1466773773.502497.647387441.16AAD74F@webmail.messagingengine.com> Message-ID: <8760sysp5g.fsf@elektro.pacujo.net> Random832 : > You know what would be really nice? A "semi-incremental" parser that > can e.g. yield (whether through an event or through the iterator > protocol) a fully formed element (preferably one that can be queried > with xpath) at a time for each record of a document representing a > list of objects. Does anything like that exist? You can construct that from a SAX parser, but it's less convenient than it could be. Python's JSON parser doesn't have it so I've had to build a clumsy one myself: def decode_json_object_array(self): # A very clumsy implementation of an incremental JSON decoder it = self.get_text() inbuf = "" while True: try: inbuf += next(it) except StopIteration: # a premature end; trigger a decode error json.loads("[" + inbuf) try: head, tail = inbuf.split("[", 1) except ValueError: continue break # trigger a decode error if head contains junk json.loads(head + "[]") inbuf = "" chunk = tail while True: bracket_maybe = "" for big in chunk.split("]"): comma_maybe = "" for small in big.split(","): inbuf += comma_maybe + small comma_maybe = "," try: yield json.loads(inbuf) #except json.JSONDecodeError: except ValueError: # legacy exception pass else: inbuf = comma_maybe = "" inbuf += bracket_maybe bracket_maybe = "]" try: yield json.loads(inbuf) #except json.JSONDecodeError: except ValueError: # legacy exception pass else: inbuf = "" try: chunk += next(it) except StopIteration: break # trigger a decode error if chunk contains junk json.loads("[" + chunk) It could easily be converted to an analogous XML parser. Marko From grant.b.edwards at gmail.com Fri Jun 24 10:00:24 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 24 Jun 2016 14:00:24 +0000 (UTC) Subject: Which one is the best JSON parser? References: <1150800609.939828.1466715495931.JavaMail.yahoo.ref@mail.yahoo.com> <1150800609.939828.1466715495931.JavaMail.yahoo@mail.yahoo.com> Message-ID: On 2016-06-23, MRAB wrote: > On 2016-06-23 21:58, David Shi via Python-list wrote: >> Can any one tell me? >> Regards. >> David >> > There's one in the standard library. Which has always worked fine for me... -- Grant Edwards grant.b.edwards Yow! I want another at RE-WRITE on my CEASAR gmail.com SALAD!! From steven.truppe at chello.at Fri Jun 24 11:00:09 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Fri, 24 Jun 2016 17:00:09 +0200 Subject: Question on compiling on linux Message-ID: <576D4AF9.40407@chello.at> Hi all, i want to write an application that does extend and embed Python. I downloaded the sources for 3.5.1 and used ./confiugure to build. In the old times i got a file called python.so somewhere but now i get many .so files.... and how can i change between debug and release build (32 and 64bit) ? I'm new to Makefiles and ./configure, i used MSVC2010 on windows and try to understand how this things do work under linux - can someone please help me out here ?? Thanks in advance, Steven Truppe From __peter__ at web.de Fri Jun 24 11:13:53 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Jun 2016 17:13:53 +0200 Subject: Which one is the best XML-parser? References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> <87r3bnrsy4.fsf@handshake.de> <1466773773.502497.647387441.16AAD74F@webmail.messagingengine.com> <8760sysp5g.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Random832 : >> You know what would be really nice? A "semi-incremental" parser that >> can e.g. yield (whether through an event or through the iterator >> protocol) a fully formed element (preferably one that can be queried >> with xpath) at a time for each record of a document representing a >> list of objects. Does anything like that exist? > > You can construct that from a SAX parser, but it's less convenient than > it could be. Python's JSON parser doesn't have it so I've had to build a > clumsy one myself: > > def decode_json_object_array(self): > # A very clumsy implementation of an incremental JSON > # decoder > it = self.get_text() > inbuf = "" > while True: > try: > inbuf += next(it) > except StopIteration: > # a premature end; trigger a decode error > json.loads("[" + inbuf) > try: > head, tail = inbuf.split("[", 1) > except ValueError: > continue > break > # trigger a decode error if head contains junk > json.loads(head + "[]") > inbuf = "" > chunk = tail > while True: > bracket_maybe = "" > for big in chunk.split("]"): > comma_maybe = "" > for small in big.split(","): > inbuf += comma_maybe + small > comma_maybe = "," > try: > yield json.loads(inbuf) > #except json.JSONDecodeError: > except ValueError: # legacy exception > pass > else: > inbuf = comma_maybe = "" > inbuf += bracket_maybe > bracket_maybe = "]" > try: > yield json.loads(inbuf) > #except json.JSONDecodeError: > except ValueError: # legacy exception > pass > else: > inbuf = "" > try: > chunk += next(it) > except StopIteration: > break > # trigger a decode error if chunk contains junk > json.loads("[" + chunk) > > It could easily be converted to an analogous XML parser. For XML you could use iterparse, see http://effbot.org/elementtree/iterparse.htm I came up with the following and found memory usage to be stable. import random import xml.etree.ElementTree from xml.sax.saxutils import escape def iter_elems(file, tag): it = xml.etree.ElementTree.iterparse(file, events=("start", "end")) root = next(it)[1] for event, elem in it: if event == "end" and elem.tag == tag: yield elem root.clear() # --- example below --- class NeverendingXMLFile: def __init__(self, words): self.words = words self.chunks = self.gen_chunks() def gen_chunks(self): words = self.words yield b"" while True: yield "{}".format(random.choice(words)).encode() def read(self, size=None): return next(self.chunks) def filelike(): with open("/usr/share/dict/words") as f: words = [escape(line.strip()) for line in f] infile = NeverendingXMLFile(words) return infile if __name__ == "__main__": for word in iter_elems(filelike(), "word"): print(word.text) In theory this should be even simpler with lxml as it exposes the root element and allows to filter per tag http://lxml.de/parsing.html#iterparse-and-iterwalk Unfortunately root seems to be set after the closing and thus doesn't help with dereferencing seen elements during iteration. From rosuav at gmail.com Fri Jun 24 12:00:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jun 2016 02:00:36 +1000 Subject: Question on compiling on linux In-Reply-To: <576D4AF9.40407@chello.at> References: <576D4AF9.40407@chello.at> Message-ID: On Sat, Jun 25, 2016 at 1:00 AM, Steven Truppe wrote: > i want to write an application that does extend and embed Python. I > downloaded the sources for 3.5.1 and used ./confiugure to build. > > In the old times i got a file called python.so somewhere but now i get many > .so files.... and how can i change between debug and release build (32 and > 64bit) ? I'm new to Makefiles and ./configure, i used MSVC2010 on windows > and try to understand how this things do work under linux - can someone > please help me out here ?? > After typing ../configure, did you type 'make'? That's the part that does most of the work. If that succeeds, it should leave a file called 'python' in the main build directory. ChrisA From rayprabhakarray at gmail.com Fri Jun 24 12:36:53 2016 From: rayprabhakarray at gmail.com (rayprabhakarray at gmail.com) Date: Fri, 24 Jun 2016 09:36:53 -0700 (PDT) Subject: plotting of live data-python Message-ID: <55af2fdc-a1fa-47ea-b3b2-77444b895b9c@googlegroups.com> Hi All, I'm plotting a continuous analog reading using python's drawnow package. I want to implement a data cursor which follows the graph and shows me the coordinates without me clicking or hovering over the specific point. Basically since the plot is moving, it getting difficult to see the coordinates of any specific point. Can anyone help me with this kind of problem. Regards, Prabhakar From fabiofz at gmail.com Fri Jun 24 12:42:37 2016 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 24 Jun 2016 13:42:37 -0300 Subject: PyDev 5.1.2 Released Message-ID: Release Highlights: ------------------------------- * **Important** PyDev now requires Java 8 and Eclipse 4.5 onwards. * PyDev 4.5.5 is the last release supporting Java 7 and Eclipse 3.8. * See: http://www.pydev.org/update_sites/index.html for the update site of older versions of PyDev. * See: the **PyDev does not appear after install** section on http://www.pydev.org/download.html for help on using a Java 8 vm in Eclipse. * The pytest integration was redone and should now work properly with the latest pytest. * Properly showing output of tests in PyUnit view. * Improved dealing with items filtered through Ctrl+F9. * Better support for xdist (no longer reporting that the session finished when only a slave finished). * Reporting skipped items as "skip" and not "ok". * Properly showing running tests on PyUnit view. * Not using tokenize.open() in Python 3.2 for the execfile custom implementation. * Expand and collapse keybindings changed to use the Numpad entries (so that they don't override the add/subtract used for zooming). #PyDev 695. * The hover in PyDev has an implementation which is now more flexible and easier to extend in plugins (patch by Mark A. Leone). What is PyDev? --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? --------------------------- LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ From rayprabhakarray at gmail.com Fri Jun 24 13:11:23 2016 From: rayprabhakarray at gmail.com (Prabhakar Ray) Date: Fri, 24 Jun 2016 10:11:23 -0700 (PDT) Subject: Live analog plotting - python Message-ID: <3274e0e6-cc90-4bc0-b735-df2d442a5495@googlegroups.com> Hi Guys, I'm reading a continuous analog value using python and plotting it using drawnow(). Since the plot is moving it's getting difficult to note down the coordinates of any specific point. I intend to implement a moving data cursor which can follow the graph and can give me real time coordinates of the point without the need of clicking or hovering over a point. can anyone help me with this ? Regards, Prabhakar From rosuav at gmail.com Fri Jun 24 14:23:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jun 2016 04:23:25 +1000 Subject: Question on compiling on linux In-Reply-To: <576D79B8.5080303@chello.at> References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> Message-ID: On Sat, Jun 25, 2016 at 4:19 AM, Steven Truppe wrote: > But that's not a library file, it's the interpreter, i need the library to > extend and embend python into my own application ... Bouncing back to the list (please keep it there). The reason I mentioned ./python is that, if it isn't there, something failed with the build. It's an easy way of checking that everything worked. ChrisA From steven.truppe at chello.at Fri Jun 24 14:35:19 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Fri, 24 Jun 2016 20:35:19 +0200 Subject: Question on compiling on linux In-Reply-To: References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> Message-ID: <576D7D67.3070804@chello.at> So back to my first question now that you saw everything worked fine, but there is no python.so file, did i miss something when using ./configure ? Am 2016-06-24 um 20:23 schrieb Chris Angelico: > On Sat, Jun 25, 2016 at 4:19 AM, Steven Truppe wrote: >> But that's not a library file, it's the interpreter, i need the library to >> extend and embend python into my own application ... > Bouncing back to the list (please keep it there). > > The reason I mentioned ./python is that, if it isn't there, something > failed with the build. It's an easy way of checking that everything > worked. > > ChrisA From jagdish1287 at gmail.com Fri Jun 24 14:40:29 2016 From: jagdish1287 at gmail.com (Jagdish Choudhary) Date: Sat, 25 Jun 2016 00:10:29 +0530 Subject: Seen bug in argparse module Message-ID: Hi All, When argument provided from user which doesn't match to right option which is mentioned in help , it runs without issue..let me provide an example https://docs.python.org/3.3/library/argparse.html import argparse parser = argparse.ArgumentParser(description='Process some integers.')parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer for the accumulator')parser.add_argument('--sum', dest='accumulate', action='store_const', const=sum, default=max, help='sum the integers (default: find the max)') args = parser.parse_args()print(args.accumulate(args.integers)) python prog.py -h usage: prog.py [-h] [--sum] N [N ...] Process some integers. positional arguments: N an integer for the accumulator optional arguments: -h, --help show this help message and exit --sum sum the integers (default: find the max) If user run it like below- JAGDISHs-MacBook-Pro:test_python jagdish$ python prog.py 12 3 4 --sum 19 JAGDISHs-MacBook-Pro:test_python jagdish$ python prog.py 12 3 4 --su 19 JAGDISHs-MacBook-Pro:test_python jag -- Thanks and Regards, Jagdish Choudhary IBM India Pvt Ltd, Bangalore M.No-8971011661 From zachary.ware+pylist at gmail.com Fri Jun 24 15:02:32 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 24 Jun 2016 14:02:32 -0500 Subject: Question on compiling on linux In-Reply-To: <576D7D67.3070804@chello.at> References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> Message-ID: On Fri, Jun 24, 2016 at 1:35 PM, Steven Truppe wrote: > So back to my first question now that you saw everything worked fine, but > there is no python.so file, did i miss something when using ./configure ? Try `./configure --enable-shared`. -- Zach From steven.truppe at chello.at Fri Jun 24 15:28:23 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Fri, 24 Jun 2016 21:28:23 +0200 Subject: Question on compiling on linux In-Reply-To: <576D7D67.3070804@chello.at> References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> Message-ID: <576D89D7.6010409@chello.at> That gives me many .so files but no python*.so* file :( Am 2016-06-24 um 20:35 schrieb Steven Truppe: > So back to my first question now that you saw everything worked fine, > but there is no python.so file, did i miss something when using > ./configure ? > > > Am 2016-06-24 um 20:23 schrieb Chris Angelico: >> On Sat, Jun 25, 2016 at 4:19 AM, Steven Truppe >> wrote: >>> But that's not a library file, it's the interpreter, i need the >>> library to >>> extend and embend python into my own application ... >> Bouncing back to the list (please keep it there). >> >> The reason I mentioned ./python is that, if it isn't there, something >> failed with the build. It's an easy way of checking that everything >> worked. >> >> ChrisA > From Joaquin.Alzola at lebara.com Fri Jun 24 15:37:59 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Fri, 24 Jun 2016 19:37:59 +0000 Subject: Question on compiling on linux In-Reply-To: <576D89D7.6010409@chello.at> References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> Message-ID: >That gives me many .so files but no python*.so* file :( Install the python-devel. 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 zachary.ware+pylist at gmail.com Fri Jun 24 16:08:32 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 24 Jun 2016 15:08:32 -0500 Subject: Question on compiling on linux In-Reply-To: <576D89D7.6010409@chello.at> References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> Message-ID: On Fri, Jun 24, 2016 at 2:28 PM, Steven Truppe wrote: > That gives me many .so files but no python*.so* file :( Where are you finding these many .so files? There should be libpython3.5m.so in the root of the source tree (alongside `python`). By the way, I'm not sure how you're accessing the list/newsgroup, but your quoting seems to be messed up somehow -- my message, which I'm assuming the above was in reply to, was nowhere to be found in your message. Also, as a minor matter of netiquette, we prefer new content to follow a quote of what the new message is in reply to, as I've done in this message. -- Zach From __peter__ at web.de Fri Jun 24 16:13:00 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Jun 2016 22:13 +0200 Subject: Seen bug in argparse module References: Message-ID: Jagdish Choudhary wrote: > When argument provided from user which doesn't match to right option which > is mentioned in help , it runs without issue..let me provide an example > > https://docs.python.org/3.3/library/argparse.html > > import argparse > parser = argparse.ArgumentParser(description='Process some > integers.')parser.add_argument('integers', metavar='N', type=int, > nargs='+', > help='an integer for the > accumulator')parser.add_argument('--sum', dest='accumulate', > action='store_const', > const=sum, default=max, > help='sum the integers (default: find the max)') > args = parser.parse_args()print(args.accumulate(args.integers)) > > python prog.py -h > usage: prog.py [-h] [--sum] N [N ...] > > Process some integers. > > positional arguments: > N an integer for the accumulator > > optional arguments: > -h, --help show this help message and exit > --sum sum the integers (default: find the max) > > If user run it like below- > > JAGDISHs-MacBook-Pro:test_python jagdish$ python prog.py 12 3 4 --sum > 19 > JAGDISHs-MacBook-Pro:test_python jagdish$ python prog.py 12 3 4 --su > 19 > JAGDISHs-MacBook-Pro:test_python jag This works as designed: https://docs.python.org/3.3/library/argparse.html#prefix-matching Starting with Python 3.5 you can disable this behaviour with allow_abbrev=False, see https://docs.python.org/3.6/library/argparse.html#allow-abbrev If you think this should have been the default -- I agree. From ned at nedbatchelder.com Fri Jun 24 21:36:37 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 24 Jun 2016 18:36:37 -0700 (PDT) Subject: Which one is the best XML-parser? In-Reply-To: <0298a770-6d7f-41c6-bbe8-05e5c8f0793e@googlegroups.com> References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> <0298a770-6d7f-41c6-bbe8-05e5c8f0793e@googlegroups.com> Message-ID: <077f0c18-8bb1-48d6-8cf4-269ae48e251d@googlegroups.com> On Friday, June 24, 2016 at 8:44:49 PM UTC-4, Sayth Renshaw wrote: > On Friday, 24 June 2016 07:03:18 UTC+10, David Shi wrote: > > Which one is the best XML-parser? > > Can any one tell me? > > Regards. > > David > > Most use lxml http://lxml.de/index.html > > Sayth Sayth, is everything OK? Why are you posting multiple messages? --Ned. From torriem at gmail.com Fri Jun 24 23:00:13 2016 From: torriem at gmail.com (Michael Torrie) Date: Fri, 24 Jun 2016 21:00:13 -0600 Subject: how to python to use virtual memory? In-Reply-To: References: <1268fa0b-aeb8-4562-a2b5-3ed0b8130d17@googlegroups.com> Message-ID: On 06/24/2016 08:44 PM, Dennis Lee Bieber wrote: > I don't know how Linux handles swap disk -- Windows normally sets the > swap space to ~2X physical memory (for small RAM -- my 12GB system has a > 12GB swap and suggests 18GB). Linux typically uses a user-set swap partition. The old rule of thumb was to make the swap partition 2x the size of RAM. Now, though, for most installations with lots of RAM, 1:1 is often used. However, if the OP's program really requires 70 to 100 GB of space, relying on the virtual memory system to do this (64-bit only of course) is a mistake. The system will simply thrash itself to death on any OS at that level of over-commit. If he has that much data, he needs to employ techniques for working with the data directly on disk himself. I highly doubt these big data sets that large companies work rely simply on the OS to manage it! From lawrencedo99 at gmail.com Sat Jun 25 01:38:40 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 24 Jun 2016 22:38:40 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <87k2hgfcs9.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <855a6682-a627-4c0f-ae95-fc3d2eb6e0d2@googlegroups.com> <87k2hgfcs9.fsf@elektro.pacujo.net> Message-ID: <8b32b098-423a-46a8-8be3-7603f058278f@googlegroups.com> On Thursday, June 23, 2016 at 9:57:35 PM UTC+12, Marko Rauhamaa wrote: > Lawrence D?Oliveiro: > >> On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: >>> The __len__ method is not guaranteed to execute in O(1). >> >> So what is? > > The __bool__ method is the appropriate place to implement an efficient > emptiness check. It might not be O(1) but it will be the most efficient > way to check for emptiness, or the class is badly implemented. Saying ?or the class is badly implemented? sounds like circular reasoning... From jussi.piitulainen at helsinki.fi Sat Jun 25 02:46:10 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sat, 25 Jun 2016 09:46:10 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <855a6682-a627-4c0f-ae95-fc3d2eb6e0d2@googlegroups.com> <87k2hgfcs9.fsf@elektro.pacujo.net> <8b32b098-423a-46a8-8be3-7603f058278f@googlegroups.com> Message-ID: Lawrence D?Oliveiro writes: > On Thursday, June 23, 2016 at 9:57:35 PM UTC+12, Marko Rauhamaa wrote: >> Lawrence D?Oliveiro: >> >>> On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: >>>> The __len__ method is not guaranteed to execute in O(1). >>> >>> So what is? >> >> The __bool__ method is the appropriate place to implement an >> efficient emptiness check. It might not be O(1) but it will be the >> most efficient way to check for emptiness, or the class is badly >> implemented. > > Saying ?or the class is badly implemented? sounds like circular > reasoning... What are you thinking? If there's a better way to implement __bool__, why shouldn't that better way have been used? From kwpolska at gmail.com Sat Jun 25 03:47:13 2016 From: kwpolska at gmail.com (Chris Warrick) Date: Sat, 25 Jun 2016 09:47:13 +0200 Subject: not able to install mysqldb-python In-Reply-To: References: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> Message-ID: On 24 June 2016 at 09:46, Arshpreet Singh wrote: > On Thursday, 23 June 2016 23:18:27 UTC+5:30, Joaquin Alzola wrote: >> > ImportError: No module named 'ConfigParser' >> It is telling you the error >> 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. > > Thanks but somehow it fixed itself. :P now able to install mysql-python without any problem. > -- > https://mail.python.org/mailman/listinfo/python-list It didn?t. mysql-python is installable with Python 2 only, so you probably installed it for your system Python 2 install instead of your Python 3 django virtualenv. Either way, please use mysqlclient instead, as recommended by the Django developers. -- Chris Warrick PGP: 5EAAEA16 From dieter at handshake.de Sat Jun 25 03:50:39 2016 From: dieter at handshake.de (dieter) Date: Sat, 25 Jun 2016 09:50:39 +0200 Subject: I seem to be creating a dict that I cannot access the keys of References: <8c9b5b13-c6cc-458d-9d31-56f7e5db10c4@googlegroups.com> Message-ID: <871t3llnao.fsf@handshake.de> Sayth Renshaw writes: > ... > Can I ask is there something obvious wrong, i have left the commented other versions in they "work" in that they all produce the same output the print whole file. > The code below is obviously wrong - it is surprising that you get anything other than an exception. See comments below inserted into your code. > def parseXML(): > ... > result = etree.tostring(tree.getroot(), pretty_print=True) "result" here is obviously a string. > for sample in result: This means that "sample" successively hold the characters composing the string "result". > noms = (dict(zip(atts, map(sample.attrib.get, atts)))) You should get "AttributeError: str object does not have attribute `attrib`". From steven.truppe at chello.at Sat Jun 25 03:54:03 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Sat, 25 Jun 2016 09:54:03 +0200 Subject: Question on compiling on linux In-Reply-To: References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> Message-ID: <576E389B.7060709@chello.at> i hope this email works like you expected! I found the libpython3.so, i don't know why i was not able to see it, thank you very much to everyone wo helped me! No my last question(s) is how can i create debug/release builds ? Am 2016-06-24 um 22:08 schrieb Zachary Ware: > On Fri, Jun 24, 2016 at 2:28 PM, Steven Truppe wrote: >> That gives me many .so files but no python*.so* file :( > Where are you finding these many .so files? There should be > libpython3.5m.so in the root of the source tree (alongside `python`). > > By the way, I'm not sure how you're accessing the list/newsgroup, but > your quoting seems to be messed up somehow -- my message, which I'm > assuming the above was in reply to, was nowhere to be found in your > message. Also, as a minor matter of netiquette, we prefer new content > to follow a quote of what the new message is in reply to, as I've done > in this message. > From dieter at handshake.de Sat Jun 25 03:54:25 2016 From: dieter at handshake.de (dieter) Date: Sat, 25 Jun 2016 09:54:25 +0200 Subject: program return killed after run a very long time References: <94693872-2b7b-48cb-8a4e-d8c59218cf1c@googlegroups.com> Message-ID: <87wpldk8jy.fsf@handshake.de> meInvent bbird writes: > i suspect it use so much memory, > > however i have already assign 30GB memory in openstack cloud > > is there any command to allow python to use more memory? > > currently > > program return killed after run a very long time Usually, there are memory limits at various levels: architecture (e.g. on a 32 bit architecture, the address space cannot exceed 32 GB), physical memory, operating system, user, "session". You would need to check which limits are effective on the various levels and increase them, if possible. From flebber.crue at gmail.com Sat Jun 25 04:41:28 2016 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 25 Jun 2016 01:41:28 -0700 (PDT) Subject: I seem to be creating a dict that I cannot access the keys of In-Reply-To: References: <8c9b5b13-c6cc-458d-9d31-56f7e5db10c4@googlegroups.com> <871t3llnao.fsf@handshake.de> Message-ID: > > The code below is obviously wrong - it is surprising that you get > anything other than an exception. See comments below inserted into > your code. > > > def parseXML(): > > ... > > result = etree.tostring(tree.getroot(), pretty_print=True) > > "result" here is obviously a string. > > > for sample in result: > > This means that "sample" successively hold the characters composing > the string "result". > > > noms = (dict(zip(atts, map(sample.attrib.get, atts)))) > > You should get "AttributeError: str object does not have attribute `attrib`". The attrib is an lxml function, when you have defined a root http://lxml.de/tutorial.html >>> attributes = root.attrib or >>> d = dict(root.attrib) >>> sorted(d.items()) [('hello', 'Guten Tag'), ('interesting', 'totally')] if I run it with this section as you reference above for sample in root.xpath('//race/nomination'): noms = (dict(zip(atts, map(sample.attrib.get, atts)))) print(noms) I get working output (pyxml) [sayth at localhost pyXML]$ python xrace.py data/ -e .xml {'barrier': '5', 'horse': 'Chipanda', 'goodtrack': '0-0-0-0', 'weight': '54', 'pricestarting': '$3.50', 'age': '3', 'description': 'B F 2 Sepoy x Lobola (Anabaa(USA))', 'heavytrack': '0-0-0-0', 'career': '2-0-0-2 $30225.00', 'colours': 'Royal Blue', 'finished': '1', 'owners': 'Godolphin ', 'dob': '2013-10-08T00:00:00', 'id': '198926', 'thisdistance': '0-0-0-0', 'weightvariation': '0', 'penalty': '0', 'number': '8', 'rating': '0', 'sex': 'F', 'decimalmargin': '0.00', 'variedweight': '54', 'saddlecloth': '8', 'thistrack': '1-0-0-1 $15000.00'} {'barrier': '1', 'horse': 'Legerity', 'goodtrack': '3-1-0-1 $77150.00', 'weight': '57.5', 'pricestarting': '$2.50F', 'age': '3', 'description': 'B C 2 Snitzel x Cheers Sayth From marko at pacujo.net Sat Jun 25 04:56:38 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 25 Jun 2016 11:56:38 +0300 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a8i9r6ih.fsf@elektro.pacujo.net> Steven D'Aprano : > So we have falsey values: > > - None > - zeroes (0, 0.0, 0j, etc) > - empty dict {} > - empty sets and frozensets > - empty strings '' and b'' (in Python 2: u'' and '') > - empty lists, tuples and other sequences > > and truthy values: > > - object > - non-zero numbers > - non-empty dicts > - non-empty sets and frozensets > - non-empty strings > - non-empty sequences It might be more descriptive to call those polar opposites "naughty" and "nice." Or maybe "hollow" and "puffy." Marko From davidgshi at yahoo.co.uk Sat Jun 25 07:00:14 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Sat, 25 Jun 2016 11:00:14 +0000 (UTC) Subject: How to reset IPython notebook file association References: <1992368488.2040740.1466852414139.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1992368488.2040740.1466852414139.JavaMail.yahoo@mail.yahoo.com> I use IPython Notebook to do Python programming. I used "Open with" and set it with Google Chrome. ?Then, my IPython notebook does not load properly. How can I reset IPython notebook file association, so that I can use it again? Looking forward to hearing from you. Regards. David From steve at pearwood.info Sat Jun 25 07:35:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 25 Jun 2016 21:35:45 +1000 Subject: How to reset IPython notebook file association References: <1992368488.2040740.1466852414139.JavaMail.yahoo.ref@mail.yahoo.com> <1992368488.2040740.1466852414139.JavaMail.yahoo@mail.yahoo.com> Message-ID: <576e6c92$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Jun 2016 09:00 pm, David Shi wrote: > I use IPython Notebook to do Python programming. > I used "Open with" and set it with Google Chrome. ?Then, my IPython > notebook does not load properly. How can I reset IPython notebook file > association, so that I can use it again? Have you tried setting it to Open With iPython? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From davidgshi at yahoo.co.uk Sat Jun 25 10:08:55 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Sat, 25 Jun 2016 14:08:55 +0000 (UTC) Subject: JSON to Pandas data frame References: <1726223224.2167135.1466863735174.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1726223224.2167135.1466863735174.JavaMail.yahoo@mail.yahoo.com> How to convert a JSON object into a Pandas data frame? I know that for XML, there are XML parsers. Regards. David From hasan.diwan at gmail.com Sat Jun 25 19:00:29 2016 From: hasan.diwan at gmail.com (hasan.diwan at gmail.com) Date: Sat, 25 Jun 2016 16:00:29 -0700 (PDT) Subject: JSON to Pandas data frame In-Reply-To: References: <1726223224.2167135.1466863735174.JavaMail.yahoo.ref@mail.yahoo.com> <1726223224.2167135.1466863735174.JavaMail.yahoo@mail.yahoo.com> Message-ID: David Shi writes: >How to convert a JSON object into a Pandas data frame? You can use read_json -- http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_json.html to read it into a dataframe. Or you can read the json into python objects and use read_records to create a pandas DataFrame from there. -- H From greg.ewing at canterbury.ac.nz Sat Jun 25 19:01:55 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 26 Jun 2016 11:01:55 +1200 Subject: Operator Precedence/Boolean Logic In-Reply-To: <87wplgfdb5.fsf@elektro.pacujo.net> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > The pile originally had -4 coconuts. The first sailor threw one to > the monkey, leaving -5 coconuts in the pile. He took his share (-1 > coconut) out and put the remaining -4 coconuts back in the big pile. Sounds a bit like Hawking radiation. A coconut-anticoconut pair is created, and before they can recombine, the monkey grabs the coconut, leaving the sailor with the anticoconut. Unfortunately, it's pointless fot the sailor to eat the anticocounut, as it would ony make him hungrier, and the coconut is now inside the monkey's event horizon, never to be seen again. -- Greg From greg.ewing at canterbury.ac.nz Sat Jun 25 19:15:17 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 26 Jun 2016 11:15:17 +1200 Subject: Can math.atan2 return INF? In-Reply-To: <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > China has just announced a new supercomputer that is so fast it can run an > infinite loop in 3.7 seconds. They're lying. It has to be NaN seconds. -- Greg From python at mrabarnett.plus.com Sat Jun 25 19:31:37 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 26 Jun 2016 00:31:37 +0100 Subject: Can math.atan2 return INF? In-Reply-To: References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> Message-ID: <75aee5c2-7bad-b4c7-aec2-69cac585e3ce@mrabarnett.plus.com> On 2016-06-26 00:15, Gregory Ewing wrote: > Steven D'Aprano wrote: >> China has just announced a new supercomputer that is so fast it can run an >> infinite loop in 3.7 seconds. > > They're lying. It has to be NaN seconds. > If it was an Indian supercomputer, it would be naan seconds. Sorry. :-) From greg.ewing at canterbury.ac.nz Sat Jun 25 19:40:36 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 26 Jun 2016 11:40:36 +1200 Subject: Can math.atan2 return INF? In-Reply-To: <87shw3es70.fsf@elektro.pacujo.net> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange): > >>Near a black hole 3.7 seconds can last an infinite time... > > Which phenomenon prevents a black hole from ever forming. Yet > astronomers keep telling us they are all over the place. Astronomers have observed objects whose behaviour is entirely consistent with the existence of black holes as predicted by general relativity. > Oppenheimer and his co-authors interpreted the singularity at the > boundary of the Schwarzschild radius as indicating that this was the > boundary of a bubble in which time stopped. This is a valid point of > view for external observers, but not for infalling observers. > > Note that the "valid point of view for external observers" is the only > valid scientific point of view. The singularity being talked about there is an artifact of a particular coordinate system; the theory predicts that there is no *physical* singularity at the event horizon. It's true that we outside can't be absolutely sure that things are as predicted at the horizon itself, because any observer we sent in to check would be unable to report back. But in principle we can observe arbitrarily close to it. The observations we've made so far all fit the theory, and the theory doesn't present any obstacles to extrapolating those results to the horizon and beyond, so we accept the theory as valid. There *is* a difficulty at the very center of the hole, where there is a true singularity in the theory, so something else must happen there. But for other reasons we don't expect those effects to become important until you get very close to the singularity -- something on the order of the Planck length. -- Greg From greg.ewing at canterbury.ac.nz Sat Jun 25 19:43:38 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 26 Jun 2016 11:43:38 +1200 Subject: Can math.atan2 return INF? In-Reply-To: <87oa6qswh0.fsf@elektro.pacujo.net> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <1mpce0f.dt8b291rct6bkN%pdorange@pas-de-pub-merci.mac.com> <87oa6qswh0.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange): > >>For a scientific point of view, right. But tell this to the one that >>will be close to a blackhole ;-) > > Then, you'd better consult a priest than a scientist. But don't worry, you'll have an infinitely long time to make your confessions -- from our point of view, anyway. -- Greg From davidbenny2000 at gmail.com Sat Jun 25 21:47:56 2016 From: davidbenny2000 at gmail.com (Ho Yeung Lee) Date: Sat, 25 Jun 2016 18:47:56 -0700 (PDT) Subject: how to python to use virtual memory? In-Reply-To: References: <1268fa0b-aeb8-4562-a2b5-3ed0b8130d17@googlegroups.com> Message-ID: <7b04c23d-d969-4e56-be65-2b2b85c1aef1@googlegroups.com> what is the command or code to write to use virtual memory if i use extra 20 GB from hard disk as memory, means from 70GB memory to 90GB memory and left 10GB for file? Michael Torrie? 2016?6?25???? UTC+8??11?00?36???? > On 06/24/2016 08:44 PM, Dennis Lee Bieber wrote: > > I don't know how Linux handles swap disk -- Windows normally sets the > > swap space to ~2X physical memory (for small RAM -- my 12GB system has a > > 12GB swap and suggests 18GB). > > Linux typically uses a user-set swap partition. The old rule of thumb > was to make the swap partition 2x the size of RAM. Now, though, for most > installations with lots of RAM, 1:1 is often used. > > However, if the OP's program really requires 70 to 100 GB of space, > relying on the virtual memory system to do this (64-bit only of course) > is a mistake. The system will simply thrash itself to death on any OS > at that level of over-commit. If he has that much data, he needs to > employ techniques for working with the data directly on disk himself. I > highly doubt these big data sets that large companies work rely simply > on the OS to manage it! From lawrencedo99 at gmail.com Sun Jun 26 01:54:21 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 25 Jun 2016 22:54:21 -0700 (PDT) Subject: not able to install mysqldb-python In-Reply-To: References: <103a2db1-c5fb-40bc-92a4-19feb5f1de35@googlegroups.com> Message-ID: On Friday, June 24, 2016 at 5:48:27 AM UTC+12, 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. Sender, please consider yourself contacted! From marko at pacujo.net Sun Jun 26 03:09:32 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 26 Jun 2016 10:09:32 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> Message-ID: <87y45spgsz.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> Which phenomenon prevents a black hole from ever forming. Yet >> astronomers keep telling us they are all over the place. > Astronomers have observed objects whose behaviour is entirely > consistent with the existence of black holes as predicted by general > relativity. As far as I understand, all we can ever observe is black holes in the making since the making can never (seem to) finish. IOW, the event horizon never forms. These almost-black-holes are virtually indistinguishable from black holes proper. However, we don't have to speculate about the physics of the insides of the black hole. > The singularity being talked about there is an artifact of a > particular coordinate system; the theory predicts that there is no > *physical* singularity at the event horizon. That theory can't be tested even in principle, can it? Therefore, it is not scientific. > It's true that we outside can't be absolutely sure that things are as > predicted at the horizon itself, because any observer we sent in to > check would be unable to report back. But in principle we can observe > arbitrarily close to it. The observations we've made so far all fit > the theory, and the theory doesn't present any obstacles to > extrapolating those results to the horizon and beyond, so we accept > the theory as valid. Religious theories about the afterlife face similar difficulties -- and present similar extrapolations. > There *is* a difficulty at the very center of the hole, where there is > a true singularity in the theory, so something else must happen there. > But for other reasons we don't expect those effects to become > important until you get very close to the singularity -- something on > the order of the Planck length. That's my point: such speculation must remaing mere speculation. The universe doesn't owe us an answer to a question that we can never face. Marko From lawrencedo99 at gmail.com Sun Jun 26 03:29:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 26 Jun 2016 00:29:10 -0700 (PDT) Subject: How to reset IPython notebook file association In-Reply-To: References: <1992368488.2040740.1466852414139.JavaMail.yahoo.ref@mail.yahoo.com> <1992368488.2040740.1466852414139.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Saturday, June 25, 2016 at 11:03:17 PM UTC+12, David Shi wrote: > I use IPython Notebook to do Python programming. > I used "Open with" and set it with Google Chrome. Why did you do that? You open notebooks from within your web browser, not your system?s file browser. From lawrencedo99 at gmail.com Sun Jun 26 03:32:15 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 26 Jun 2016 00:32:15 -0700 (PDT) Subject: Break and Continue: While Loops In-Reply-To: References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: <33a23d1b-320e-4ee7-987b-325b01843595@googlegroups.com> On Thursday, June 23, 2016 at 11:58:01 PM UTC+12, Jon Ribbens wrote: > I seem to recall that Java originally insisted that only booleans > (excluding even Booleans, which are a different thing because of > course they are) could be checked for truth and it was one of > Java's significant warts. Java?s wart was it didn?t implement Booleans the way they were done in Pascal. That wouldn?t have been a wart. Python?s Boolean handling is a wart in the other direction. From lawrencedo99 at gmail.com Sun Jun 26 03:36:47 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 26 Jun 2016 00:36:47 -0700 (PDT) Subject: Assignment Versus Equality Message-ID: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> One of Python?s few mistakes was that it copied the C convention of using ?=? for assignment and ?==? for equality comparison. It should have copied the old convention from Algol-like languages (including Pascal), where ?:=? was assignment, so ?=? could keep a meaning closer to its mathematical usage. For consider, the C usage isn?t even consistent. What is the ?not equal? operator? Is it the ?not? operator concatenated with the ?equal? operator? No it?s not! It is ?!? followed by ?=? (assignment), of all things! This fits in more with the following pattern: A += B <=> A = A + B A *= B <=> A = A * B in other words A != B should be equivalent to A = A ! B From bc at freeuk.com Sun Jun 26 06:48:30 2016 From: bc at freeuk.com (BartC) Date: Sun, 26 Jun 2016 11:48:30 +0100 Subject: Assignment Versus Equality In-Reply-To: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: > One of Python?s few mistakes was that it copied the C convention of using ?=? for assignment and ?==? for equality comparison. One of C's many mistakes. Unfortunately C has been very influential. However, why couldn't Python have used "=" both for assignment, and for equality? Since I understand assignment ops can't appear in expressions. > It should have copied the old convention from Algol-like languages (including Pascal), where ?:=? was assignment, so ?=? could keep a meaning closer to its mathematical usage. (I think Fortran and PL/I also used "=" for assignment. Both were more commercially successful than Algol or Pascal.) > For consider, the C usage isn?t even consistent. What is the ?not equal? > operator? Is it the ?not? operator concatenated with the ?equal? operator? > No it?s not! It is ?!? followed by ?=? (assignment), of all things! I thought "!" /was/ the logical not operator (with "~" being bitwise not). > This fits in more with the following pattern: > > A += B <=> A = A + B > A *= B <=> A = A * B > > in other words > > A != B > > should be equivalent to > > A = A ! B Yes, that's an another inconsistency in C. Sometimes "<>" was used for "not equals", or "?" except there was limited keyboard support for that. ("/=" would have the same problem as "!=") But again, that doesn't apply in Python as the "!=" in "A != B" can't appear in expressions. -- Bartc From steve at pearwood.info Sun Jun 26 08:18:06 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 26 Jun 2016 22:18:06 +1000 Subject: Break and Continue: While Loops References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> <33a23d1b-320e-4ee7-987b-325b01843595@googlegroups.com> Message-ID: <576fc800$0$1600$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Jun 2016 05:32 pm, Lawrence D?Oliveiro wrote: > On Thursday, June 23, 2016 at 11:58:01 PM UTC+12, Jon Ribbens wrote: >> I seem to recall that Java originally insisted that only booleans >> (excluding even Booleans, which are a different thing because of >> course they are) could be checked for truth and it was one of >> Java's significant warts. > > Java?s wart was it didn?t implement Booleans the way they were done in > Pascal. That wouldn?t have been a wart. Oh? How are Java booleans different from Pascal booleans? Are you referring to "boxed" booleans, i.e. native bools in an object wrapper? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From liik.joonas at gmail.com Sun Jun 26 08:31:23 2016 From: liik.joonas at gmail.com (Joonas Liik) Date: Sun, 26 Jun 2016 15:31:23 +0300 Subject: how to python to use virtual memory? In-Reply-To: <7b04c23d-d969-4e56-be65-2b2b85c1aef1@googlegroups.com> References: <1268fa0b-aeb8-4562-a2b5-3ed0b8130d17@googlegroups.com> <7b04c23d-d969-4e56-be65-2b2b85c1aef1@googlegroups.com> Message-ID: On 26 June 2016 at 04:47, Ho Yeung Lee wrote: > what is the command or code to write to use virtual memory if i use extra > 20 GB from hard disk as memory, means from 70GB memory to 90GB memory > and left 10GB for file? > > Michael Torrie? 2016?6?25???? UTC+8??11?00?36???? >> On 06/24/2016 08:44 PM, Dennis Lee Bieber wrote: >> > I don't know how Linux handles swap disk -- Windows normally sets the >> > swap space to ~2X physical memory (for small RAM -- my 12GB system has a >> > 12GB swap and suggests 18GB). >> >> Linux typically uses a user-set swap partition. The old rule of thumb >> was to make the swap partition 2x the size of RAM. Now, though, for most >> installations with lots of RAM, 1:1 is often used. >> >> However, if the OP's program really requires 70 to 100 GB of space, >> relying on the virtual memory system to do this (64-bit only of course) >> is a mistake. The system will simply thrash itself to death on any OS >> at that level of over-commit. If he has that much data, he needs to >> employ techniques for working with the data directly on disk himself. I >> highly doubt these big data sets that large companies work rely simply >> on the OS to manage it! > > -- > https://mail.python.org/mailman/listinfo/python-list You really should avoid relying on the OS trick of pretending you have more ram than you actually do. this can easily cause several magnitudes worth of slowdown. if you succeed i bet the next post to this list will be titled "why is my program taking forever to run". in stead try to partition the work in to chunks and only keep the truly necessary working set loaded at a time. For example if you load data from an xml or json file it will likely include more data than you need to do your calculations. perhaps it is possible to throw some of it away or at least remove it for the time of the memory intensive step. there are ways to allow your program to use more memory ofc. but this may run in to OS limits (like the aforementioned 32 bit windows issue) and will likely incur heavy performance penalties. you should avoid it if at all possible. even if you do you will likely benefit from adapting your algorithm. From steve at pearwood.info Sun Jun 26 09:21:35 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 26 Jun 2016 23:21:35 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Jun 2016 08:48 pm, BartC wrote: > On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: >> One of Python?s few mistakes was that it copied the C convention of using >> ?=? for assignment and ?==? for equality comparison. > > One of C's many mistakes. Unfortunately C has been very influential. > > However, why couldn't Python have used "=" both for assignment, and for > equality? Since I understand assignment ops can't appear in expressions. Personally, I think that even if there is no *syntactical* ambiguity between assignment and equality, programming languages should still use different operators for them. I must admit that my first love is still Pascal's := for assignment and = for equality, but C's = for assignment and == for equality it *almost* as good. (It loses a mark because absolute beginners confuse the assignment = for the = in mathematics, which is just different enough to cause confusion.) But the BASIC style = for both assignment and equality is just begging for confusion. Even though = is not ambiguous given BASIC's rules, it can still be ambiguous to beginners who haven't yet digested those rules and made them second nature. And even experts don't always work with complete statements. Here is a snippet of BASIC code: X = Y Is it an assignment or an equality comparison? Without seeing the context, it is impossible to tell: 10 X = Y + 1 20 IF X = Y GOTO 50 Now obviously BASIC was a very popular and successful language, for many years, despite that flaw. But I wouldn't repeat it in a new language. >> It should have copied the old convention from Algol-like languages >> (including Pascal), where ?:=? was assignment, so ?=? could keep a >> meaning closer to its mathematical usage. > > (I think Fortran and PL/I also used "=" for assignment. Both were more > commercially successful than Algol or Pascal.) Fortran 77 used .EQ. for equality. I'm not sure about PL/I. I'm also not sure I'd agree about the commercial success. Fortran certainly has been extremely popular, albeit almost entirely in numerical computing. But PL/I has virtually disappeared from the face of the earth, while Pascal still has a small but dedicated community based on FreePascal, GNU Pascal, and Delphi. (Of the three, FreePascal and Delphi appear to still be getting regular releases.) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From victor.nicolae.savu at gmail.com Sun Jun 26 10:05:47 2016 From: victor.nicolae.savu at gmail.com (Victor Savu) Date: Sun, 26 Jun 2016 16:05:47 +0200 Subject: Language improvement: Get more from the `for .. else` clause Message-ID: tl;dr: 1. Add `StopAsyncIteration.value`, with the same semantic as `StopIteration.value` (documented in PEP 380). 2. Capture `StopIteration.value` and StopAsyncIteration.value in the `else` clauses of the `for` and `async for` statements respectively. Note: I already have a proof-of-concept implementation: repository: https://github.com/Victor-Savu/cpython branch: feat/else_capture Dear members of the Python list, I am writing to discuss and get the community's opinion on the following two ideas: 1. Capture the `StopIteration.value` in the `else` clause of the `for .. else` statement: Generators raise StopIteration on the return statement. The exception captures the return value. The `for` statement catches the `StopIteration` exception to know when to jump to the optional `else` statement, but discards the enclosed return value. I want to propose an addition to the Python syntax which gives the option to capture the return value in the `else` statement of the `for` loop: ``` def holy_grenade(): yield 'One ...' yield 'Two ...' yield 'Five!' return ('Galahad', 'Three') for count_ in holy_grenade(): print("King Arthur: {count_}") else knight, correction: # << new capture syntax here print(f"{knight}: {correction}, Sir!") print(f"King Arthur: {correction}!") ``` prints: ``` King Arthur: One ... King Arthur: Two ... King Arthur: Five! Galahad: Three, Sir! King Arthur: Three! ``` Of course, the capture expression is optional, and omitting it preserves the current behavior, making this proposed change backwards compatible. Should the iterator end without raising the StopIteration exception, the value `None` will be implicitly passed to the capture expression. In the example above, this will result in: ``` TypeError: 'NoneType' object is not iterable ``` because of the attempt to de-structure the result into `knight` and `correction`. 2. Add a `StopAsyncIteration.value` member which can be used to transfer information about the end of the asynchronous iteration, in the same way the `StopIteration.value` member is used (as documented in PEP 380). Capture this value in the in the else clause of the `async for` statement in the same way as proposed for the `StopIteration.value` in the previous point. You can find a working proof-of-concept implementation of the two proposed changes in my fork of the semi-official cpython repository on GitHub: repository: https://github.com/Victor-Savu/cpython branch: feat/else_capture Disclaimer: My Internet searching skills have failed me and I could not find any previous discussion on any of the two topics. If you are aware of such discussion, I would be grateful if you could point it out. I look forward to your feedback, ideas, and (hopefully constructive) criticism! Best regards, Victor From rustompmody at gmail.com Sun Jun 26 10:26:34 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 26 Jun 2016 07:26:34 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <074ec9c0-7f5b-4bfd-a0d4-06d2d8accf18@googlegroups.com> On Sunday, June 26, 2016 at 6:51:58 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 26 Jun 2016 08:48 pm, BartC wrote: > > > On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: > >> One of Python?s few mistakes was that it copied the C convention of using > >> ?=? for assignment and ?==? for equality comparison. > > > > One of C's many mistakes. Unfortunately C has been very influential. > > > > However, why couldn't Python have used "=" both for assignment, and for > > equality? Since I understand assignment ops can't appear in expressions. > > Personally, I think that even if there is no *syntactical* ambiguity between > assignment and equality, programming languages should still use different > operators for them. I must admit that my first love is still Pascal's := > for assignment and = for equality, but C's = for assignment and == for > equality it *almost* as good. > > (It loses a mark because absolute beginners confuse the assignment = for the > = in mathematics, which is just different enough to cause confusion.) > > But the BASIC style = for both assignment and equality is just begging for > confusion. Even though = is not ambiguous given BASIC's rules, it can still > be ambiguous to beginners who haven't yet digested those rules and made > them second nature. > > And even experts don't always work with complete statements. Here is a > snippet of BASIC code: > > X = Y > > Is it an assignment or an equality comparison? Without seeing the context, > it is impossible to tell: > > 10 X = Y + 1 > 20 IF X = Y GOTO 50 > > > Now obviously BASIC was a very popular and successful language, for many > years, despite that flaw. But I wouldn't repeat it in a new language. This is a tad bit unfair (I think) Initially Basic (BASIC as things were spelt then) used LET X = Y for the assignment The general success of the succinct and confusing approach starting Fortran and exploding with C I guess prompted the shortening [My impression: Dont know the history exactly] From arief at google.com Sun Jun 26 11:28:00 2016 From: arief at google.com (arief at google.com) Date: Sun, 26 Jun 2016 08:28:00 -0700 (PDT) Subject: Proposal: named return values through dict initialization and unpacking In-Reply-To: References: Message-ID: <9bf8880c-12ce-4155-b70d-4e63460ee464@googlegroups.com> Thanks everybody. There seems to be a lot of resistance to dict unpacking, in addition to the problem with my proposed shorthand dict() initialization syntax pointed out by Steven D'Aprano, so I won't be pursuing this. From python at mrabarnett.plus.com Sun Jun 26 11:41:48 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 26 Jun 2016 16:41:48 +0100 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <78b5ed0e-ec5f-6f54-b88c-4fed570115d2@mrabarnett.plus.com> On 2016-06-26 11:48, BartC wrote: > On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: >> One of Python?s few mistakes was that it copied the C convention of using ?=? for assignment and ?==? for equality comparison. > > One of C's many mistakes. Unfortunately C has been very influential. > > However, why couldn't Python have used "=" both for assignment, and for > equality? Since I understand assignment ops can't appear in expressions. > [snip] Python supports chained assignments. For example, "a = b = 0" assigns 0 to both a and b. I'm not sure how common it is, though. I virtually never use it myself. From HooDunnit at didly42KahZidly.net Sun Jun 26 11:47:28 2016 From: HooDunnit at didly42KahZidly.net (Cousin Stanley) Date: Sun, 26 Jun 2016 08:47:28 -0700 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: Dennis Lee Bieber wrote: > .... > but I'm sure we'd have a revolt > if Python comparison operators looked like: > > a .eq. b > a .ne. b > a .gt. b .or. c .lt. d > a .le. b .and. c .ge. d > .... As someone who learned fortran in the mid 1960s and pounded a lot of fortran code in the 1970s, the code above seems very readable .... -- Stanley C. Kitching Human Being Phoenix, Arizona From liik.joonas at gmail.com Sun Jun 26 11:50:10 2016 From: liik.joonas at gmail.com (Joonas Liik) Date: Sun, 26 Jun 2016 18:50:10 +0300 Subject: Proposal: named return values through dict initialization and unpacking In-Reply-To: <9bf8880c-12ce-4155-b70d-4e63460ee464@googlegroups.com> References: <9bf8880c-12ce-4155-b70d-4e63460ee464@googlegroups.com> Message-ID: On 26 June 2016 at 18:28, Ari Freund via Python-list wrote: > Thanks everybody. There seems to be a lot of resistance to dict unpacking, in addition to the problem with my proposed shorthand dict() initialization syntax pointed out by Steven D'Aprano, so I won't be pursuing this. > -- > https://mail.python.org/mailman/listinfo/python-list something like: a, b, c = my_magic_reordering_func(mydict, ["alpha", "beta", "charlie"]) ..is not too far off, altho it is a little repetitive is is trivial to write in current python and reaches the goal of insulating you from some degree of change in the return value. can also be extended to work with namedtuple for example (which you probably should already be using if you want to return so many arguments that this is a problem, returning several arguments is already returning a tuple under the hood afterall) From bc at freeuk.com Sun Jun 26 11:56:18 2016 From: bc at freeuk.com (BartC) Date: Sun, 26 Jun 2016 16:56:18 +0100 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: On 26/06/2016 16:47, Cousin Stanley wrote: > Dennis Lee Bieber wrote: > >> .... >> but I'm sure we'd have a revolt >> if Python comparison operators looked like: >> >> a .eq. b >> a .ne. b >> a .gt. b .or. c .lt. d >> a .le. b .and. c .ge. d >> .... > > As someone who learned fortran in the mid 1960s > and pounded a lot of fortran code in the 1970s, > the code above seems very readable .... I did a year of it in the 1970s. Looks funny in lower case though. (Note, for those who don't know (old) Fortran, that spaces and tabs are not significant. So those dots are needed, otherwise "a eq b" would be parsed as "aeqb".) -- Bartc From bc at freeuk.com Sun Jun 26 12:08:51 2016 From: bc at freeuk.com (BartC) Date: Sun, 26 Jun 2016 17:08:51 +0100 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <78b5ed0e-ec5f-6f54-b88c-4fed570115d2@mrabarnett.plus.com> Message-ID: On 26/06/2016 16:41, MRAB wrote: > On 2016-06-26 11:48, BartC wrote: >> However, why couldn't Python have used "=" both for assignment, and for >> equality? Since I understand assignment ops can't appear in expressions. >> > [snip] > > Python supports chained assignments. For example, "a = b = 0" assigns 0 > to both a and b. > > I'm not sure how common it is, though. I virtually never use it myself. Well, if it's allowed, then it doesn't matter how common it is. So "=" couldn't be used with a different meaning inside expressions as it would make this ambiguous. It also raises the possibility of a bug when someone intends to write "a=b==0" but writes "a=b=c" instead. In that case I would have supported the use of ":=" for assignment. -- Bartc From marko at pacujo.net Sun Jun 26 12:11:15 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 26 Jun 2016 19:11:15 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <87por4orq4.fsf@elektro.pacujo.net> Dennis Lee Bieber : > It did... but I'm sure we'd have a revolt if Python comparison > operators looked like: > > a .eq. b > a .ne. b > a .gt. b .or. c .lt. d > a .le. b .and. c .ge. d Yuck, who'd ever want to look at an eyesore like that. In Python, we will always stick to the pleasant elegance of __eq__ __ne__ __gt__ __ge__ __lt__ __le__ Marko From eryksun at gmail.com Sun Jun 26 12:19:52 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 26 Jun 2016 16:19:52 +0000 Subject: How to reset IPython notebook file association In-Reply-To: <1992368488.2040740.1466852414139.JavaMail.yahoo@mail.yahoo.com> References: <1992368488.2040740.1466852414139.JavaMail.yahoo.ref@mail.yahoo.com> <1992368488.2040740.1466852414139.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Sat, Jun 25, 2016 at 11:00 AM, David Shi via Python-list wrote: > I use IPython Notebook to do Python programming. > I used "Open with" and set it with Google Chrome. Then, my IPython notebook does not load properly. > How can I reset IPython notebook file association, so that I can use it again? nbopen opens a notebook in an existing notebook server or otherwise starts a new server: https://github.com/takluyver/nbopen Use the package's win-install.py script, which sets up the file association for you. Optionally, if PyWin32 is installed, the script calls SHChangeNotify to update Explorer. Example installation: > git clone https://github.com/takluyver/nbopen.git > cd nbopen > python win-install.py I wouldn't have written the installation like this. I'd use setuptools entry points and have a cross-platform registration script or command-line option that honors Windows per-user and per-machine installations, to be compatible with pip/wheel installation, instead of requiring this awkward (per-user only) win-install script. Using an entry-point EXE also works better with the "Open With" dialog, since Windows otherwise takes the name/description from "python.exe". For some reason, win-install also neglects to assign a DefaultIcon for the file type. You can manually edit the file type in the registry to set the icon. From p.infante413 at gmail.com Sun Jun 26 12:38:06 2016 From: p.infante413 at gmail.com (p.infante413 at gmail.com) Date: Sun, 26 Jun 2016 09:38:06 -0700 (PDT) Subject: Python Access logging of another program ran in subprocess Message-ID: <30c8acfd-aa69-4657-be2f-519b40fe138d@googlegroups.com> Hello, I'm currently running another Python program (prog2.py) in my program via subprocess. input_args = ['python', '/path/to/prog2.py'] + self.chosen_args file = open("logfile.txt",'w') self.process = Popen((input_args), stdout=file) However, the logs that prog2.py contains still show at the terminal since logs are not covered in the stdout module and printed in the terminal, also, the logfile.txt is empty. Is there a way I can access those logs while in prog1.py? I can't modify prog2.py since it is not mine. I'm stuck here for days now, any tips or help will do. From python at mrabarnett.plus.com Sun Jun 26 13:35:57 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 26 Jun 2016 18:35:57 +0100 Subject: Python Access logging of another program ran in subprocess In-Reply-To: <30c8acfd-aa69-4657-be2f-519b40fe138d@googlegroups.com> References: <30c8acfd-aa69-4657-be2f-519b40fe138d@googlegroups.com> Message-ID: <3eca68f8-10c6-793a-5a9c-7312814812de@mrabarnett.plus.com> On 2016-06-26 17:38, p.infante413 at gmail.com wrote: > Hello, I'm currently running another Python program (prog2.py) in my program via subprocess. > > input_args = ['python', '/path/to/prog2.py'] + self.chosen_args > file = open("logfile.txt",'w') > self.process = Popen((input_args), stdout=file) > > However, the logs that prog2.py contains still show at the terminal since logs are not covered in the stdout module and printed in the terminal, also, the logfile.txt is empty. Is there a way I can access those logs while in prog1.py? I can't modify prog2.py since it is not mine. I'm stuck here for days now, any tips or help will do. > The output you're seeing might be going to stderr, not stdout. From p.infante413 at gmail.com Sun Jun 26 13:58:42 2016 From: p.infante413 at gmail.com (p.infante413 at gmail.com) Date: Sun, 26 Jun 2016 10:58:42 -0700 (PDT) Subject: Python Access logging of another program ran in subprocess In-Reply-To: References: <30c8acfd-aa69-4657-be2f-519b40fe138d@googlegroups.com> <3eca68f8-10c6-793a-5a9c-7312814812de@mrabarnett.plus.com> Message-ID: <00e6bdc9-ea29-4079-945a-d5e51aed637c@googlegroups.com> On Monday, June 27, 2016 at 1:36:24 AM UTC+8, MRAB wrote: > > > The output you're seeing might be going to stderr, not stdout. Wow, huhuhu. Thank you. I did not know that. Thanks man! From michael.selik at gmail.com Sun Jun 26 14:17:01 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 26 Jun 2016 18:17:01 +0000 Subject: Proposal: named return values through dict initialization and unpacking In-Reply-To: <5769eb4a$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <5769eb4a$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jun 21, 2016 at 9:41 PM Steven D'Aprano wrote: > On Tue, 21 Jun 2016 05:34 pm, Ari Freund wrote: > > var3, var1, var2 = **d > > But I don't want to use the key names your function uses. I want to > use names which makes sense for my application > Note that my dict unpacking syntax proposal would solve this quite nicely. {'var1': width, 'var2': counter, 'var3': aardvark} = d But the current syntax ain't so bad either. Maybe it's even better, more readable despite being less concise. expected = {'var1', 'var2', 'var3'} excess = d.keys() - expected if excess: raise ValueError('unexpected keys {!r}'.format(excess)) width = d['var1'] counter = d['var2'] aardvark = d['var3'] From christopher_reimer at icloud.com Sun Jun 26 14:47:25 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sun, 26 Jun 2016 11:47:25 -0700 Subject: Assignment Versus Equality In-Reply-To: <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> On 6/26/2016 6:21 AM, Steven D'Aprano wrote: > On Sun, 26 Jun 2016 08:48 pm, BartC wrote: > >> On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: >>> One of Python?s few mistakes was that it copied the C convention of using >>> ?=? for assignment and ?==? for equality comparison. >> One of C's many mistakes. Unfortunately C has been very influential. >> >> However, why couldn't Python have used "=" both for assignment, and for >> equality? Since I understand assignment ops can't appear in expressions. > Personally, I think that even if there is no *syntactical* ambiguity between > assignment and equality, programming languages should still use different > operators for them. I must admit that my first love is still Pascal's := > for assignment and = for equality, but C's = for assignment and == for > equality it *almost* as good. > > (It loses a mark because absolute beginners confuse the assignment = for the > = in mathematics, which is just different enough to cause confusion.) > > But the BASIC style = for both assignment and equality is just begging for > confusion. Even though = is not ambiguous given BASIC's rules, it can still > be ambiguous to beginners who haven't yet digested those rules and made > them second nature. > > And even experts don't always work with complete statements. Here is a > snippet of BASIC code: > > X = Y > > Is it an assignment or an equality comparison? Without seeing the context, > it is impossible to tell: > > 10 X = Y + 1 > 20 IF X = Y GOTO 50 > > > Now obviously BASIC was a very popular and successful language, for many > years, despite that flaw. But I wouldn't repeat it in a new language. > > >>> It should have copied the old convention from Algol-like languages >>> (including Pascal), where ?:=? was assignment, so ?=? could keep a >>> meaning closer to its mathematical usage. >> (I think Fortran and PL/I also used "=" for assignment. Both were more >> commercially successful than Algol or Pascal.) > Fortran 77 used .EQ. for equality. I'm not sure about PL/I. > > I'm also not sure I'd agree about the commercial success. Fortran certainly > has been extremely popular, albeit almost entirely in numerical computing. > But PL/I has virtually disappeared from the face of the earth, while Pascal > still has a small but dedicated community based on FreePascal, GNU Pascal, > and Delphi. > > (Of the three, FreePascal and Delphi appear to still be getting regular > releases.) I started writing a BASIC interpreter in Python. The rudimentary version for 10 PRINT "HELLO, WORLD!" and 20 GOTO 10 ran well. The next version to read each line into a tree structure left me feeling over my head. So I got "Writing Compilers & Interpreters: An Applied Approach" by Ronald Mak (1991 edition) from Amazon, which uses C for coding and Pascal as the target language. I know a little bit of C and nothing of Pascal. Translating an old dialect of C into modern C, learning Pascal and figuring out the vagaries of BASIC should make for an interesting learning experience. Chris R. From jcasale at activenetwerx.com Sun Jun 26 14:51:14 2016 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 26 Jun 2016 18:51:14 +0000 Subject: argparse and subparsers Message-ID: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> I have some code where sys.argv is sliced up and manually fed to discrete argparse instances each with a single subparser. The reason the discrete parsers all having a single subparser was to make handling the input simpler, the first arg in the slice could be left in. This has become unmaintainable as the manual slicing is always subject to a new case by where a parser has a positional, switch or optional parameter for example. Also, since argv is grouped by subparser specifiers, if a parameter has input that matches a keyword it all goes pear shaped. The underlying root of this mess is a long unaddressed limitation in argparse to support multiple subparser specifications on the same invocation: prog.py -x -y 42 -foo bar subParserA -a 1 -b 2 subParserB -a 1 -b 2 subParserB -a 1 -b 2 The base arguments (-x -y 42 -foo bar). An invocation of "subParserA" and its arguments (-a 1 -b 2). Two invocations of "subParserB" and their arguments. etc... I have seen some creative ways to overcome this on stacktrace, however I thought I'd see what people here have done. The code is pinned at 2.7 and while several people have created alternate implementations which address many of argparses failures, its desired to stick to base lib but that can easily be changed given a compelling reason if an alternate implementation exists that works well. Thanks for any thoughts, jlc From christopher_reimer at icloud.com Sun Jun 26 14:53:19 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sun, 26 Jun 2016 11:53:19 -0700 Subject: Assignment Versus Equality In-Reply-To: <78b5ed0e-ec5f-6f54-b88c-4fed570115d2@mrabarnett.plus.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <78b5ed0e-ec5f-6f54-b88c-4fed570115d2@mrabarnett.plus.com> Message-ID: <1e5a51af-cb31-f3fe-cc07-535ee8073ea6@icloud.com> On 6/26/2016 8:41 AM, MRAB wrote: > On 2016-06-26 11:48, BartC wrote: >> On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: >>> One of Python?s few mistakes was that it copied the C convention of >>> using ?=? for assignment and ?==? for equality comparison. >> >> One of C's many mistakes. Unfortunately C has been very influential. >> >> However, why couldn't Python have used "=" both for assignment, and for >> equality? Since I understand assignment ops can't appear in expressions. >> > [snip] > > Python supports chained assignments. For example, "a = b = 0" assigns > 0 to both a and b. > > I'm not sure how common it is, though. I virtually never use it myself. How can you not use chained assignments? I thought Python was the art of the clever one-liners. :) Chris R. From cake240 at gmail.com Sun Jun 26 15:08:42 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Sun, 26 Jun 2016 12:08:42 -0700 (PDT) Subject: Break and Continue: While Loops In-Reply-To: <6cec22f0-6e6d-4588-99e3-fd2abbc696fa@googlegroups.com> References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> <6cec22f0-6e6d-4588-99e3-fd2abbc696fa@googlegroups.com> Message-ID: <9cddb25e-e4d1-4243-8f70-c0e032e07feb@googlegroups.com> On Thursday, June 23, 2016 at 12:49:30 AM UTC-4, Lawrence D?Oliveiro wrote: > On Thursday, June 23, 2016 at 4:17:23 PM UTC+12, Elizabeth Weiss wrote: > > > > i=0 > > while 1==1: > > print(i) > > i=i+1 > > if i>=5: > > print("Breaking") > > break > > > > Why is Breaking going to be printed if i only goes up to 4? It does say if > > i>=5? > > Because you incremented i after printing its value, and before checking it. Got it, Lawrence. Thanks so much for your help!! From cake240 at gmail.com Sun Jun 26 15:09:16 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Sun, 26 Jun 2016 12:09:16 -0700 (PDT) Subject: Break and Continue: While Loops In-Reply-To: References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On Thursday, June 23, 2016 at 1:06:09 AM UTC-4, Rustom Mody wrote: > On Thursday, June 23, 2016 at 9:47:23 AM UTC+5:30, Elizabeth Weiss wrote: > > CODE #1: > > > > i=0 > > while 1==1: > > print(i) > > i=i+1 > > if i>=5: > > print("Breaking") > > break > > > > ------ > > I understand that i=0 and i will only be printed if 1=1 > > The results of this is > > 0 > > 1 > > 2 > > 3 > > 4 > > Breaking > > > > Why is Breaking going to be printed if i only goes up to 4? It does say if i>=5? Shouldn't this mean that the results should be: > > 0 > > 1 > > 2 > > 3 > > 4 > > 5 > > > > CODE #2: > > > > i=0 > > while True: > > i=i+1 > > if i==2: > > print("Skipping 2") > > continue > > if i==5: > > print("Breaking") > > break > > print(i) > > > > ------ > > > > Questions: > > 1. what does the word True have to do with anything here? > > 2. i=i+1- I never understand this. Why isn't it i=i+2? > > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > > 4. How is i equal to 2 or 5 if i=0? > > > > Thanks for all of your help! > > I suggested in your other post (Subject While Loops) > that the predecessor of python ABC's syntax for assignment would help unconfuse you > > ie the ASSIGNMENT x=y we write as PUT y IN x > > Using that rewrite your CODE 1 as > > PUT 0 in i > while 1==1: > print(i) > PUT i+1 IN i > if i>=5: > print("Breaking") > break > > Now try and rethink what that does > Then repeat for your other examples that confuse Got it! Thank you! From cake240 at gmail.com Sun Jun 26 15:09:28 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Sun, 26 Jun 2016 12:09:28 -0700 (PDT) Subject: Break and Continue: While Loops In-Reply-To: References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On Thursday, June 23, 2016 at 1:20:37 AM UTC-4, DFS wrote: > On 6/23/2016 12:17 AM, Elizabeth Weiss wrote: > > > CODE #1: > > > > i=0 > > while 1==1: > > print(i) > > i=i+1 > > if i>=5: > > print("Breaking") > > break > > > > ------ > > I understand that i=0 and i will only be printed if 1=1 > > The results of this is > > 0 > > 1 > > 2 > > 3 > > 4 > > Breaking > > > > Why is Breaking going to be printed if i only goes up to 4? It does say if i>=5? Shouldn't this mean that the results should be: > > i is incremented up to 5, but you're printing i before incrementing and > evaluating it. > > Move i=i+1 to the end and try it again. > > > > > > > CODE #2: > > > > i=0 > > while True: > > i=i+1 > > if i==2: > > print("Skipping 2") > > continue > > if i==5: > > print("Breaking") > > break > > print(i) > > > > ------ > > > > Questions: > > 1. what does the word True have to do with anything here? > > 'True' is the expression that's evaluated on each iteration of the While > loop. > > while True: > print('True') > > while 1: > print('True') > > while 1==1: > print('True') > > are all equivalent, and will run indefinitely, because the statements > after the while expression do nothing to stop the loop. > > > > > > 2. i=i+1- I never understand this. Why isn't it i=i+2? > > i=i+1 adds 1 to the current value of i, then assigns that value to i. > > You can increment i by whatever you want: > i=i+1 > i=i+2 > i=i+35 > etc. > > > > > > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > > The print results don't include 2 or 5 because you said 'continue' if 2 > and 'break' if 5. So you skipped over 2, and exited at 5. > > > > > > 4. How is i equal to 2 or 5 if i=0? > > i=0 before you entered the While loop. Then you increment it by one > (i=i+1) on each iteration of the loop. > > > > > Thanks for all of your help! > > > Also, there's a million python resources on the web. > > http://www.pythonschool.net/basics/while-loops/ Got it! Thank you! From cake240 at gmail.com Sun Jun 26 15:42:58 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Sun, 26 Jun 2016 12:42:58 -0700 (PDT) Subject: Break and Continue: While Loops In-Reply-To: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> References: <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> Message-ID: On Thursday, June 23, 2016 at 12:17:23 AM UTC-4, Elizabeth Weiss wrote: > CODE #1: > > i=0 > while 1==1: > print(i) > i=i+1 > if i>=5: > print("Breaking") > break > > ------ > I understand that i=0 and i will only be printed if 1=1 > The results of this is > 0 > 1 > 2 > 3 > 4 > Breaking > > Why is Breaking going to be printed if i only goes up to 4? It does say if i>=5? Shouldn't this mean that the results should be: > 0 > 1 > 2 > 3 > 4 > 5 > > CODE #2: > > i=0 > while True: > i=i+1 > if i==2: > print("Skipping 2") > continue > if i==5: > print("Breaking") > break > print(i) > > ------ > > Questions: > 1. what does the word True have to do with anything here? > 2. i=i+1- I never understand this. Why isn't it i=i+2? > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > 4. How is i equal to 2 or 5 if i=0? > > Thanks for all of your help! Thank you, everyone!!! It all makes sense now! From torriem at gmail.com Sun Jun 26 17:28:44 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 26 Jun 2016 15:28:44 -0600 Subject: Assignment Versus Equality In-Reply-To: <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> Message-ID: <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> On 06/26/2016 12:47 PM, Christopher Reimer wrote: > I started writing a BASIC interpreter in Python. The rudimentary version > for 10 PRINT "HELLO, WORLD!" and 20 GOTO 10 ran well. The next version > to read each line into a tree structure left me feeling over my head. So > I got "Writing Compilers & Interpreters: An Applied Approach" by Ronald > Mak (1991 edition) from Amazon, which uses C for coding and Pascal as > the target language. I know a little bit of C and nothing of Pascal. > Translating an old dialect of C into modern C, learning Pascal and > figuring out the vagaries of BASIC should make for an interesting > learning experience. Sounds like fun. Every aspiring programmer should write an interpreter for some language at least once in his life! I imagine that any modern dialect of BASIC has a very complex grammar. The syntax is full of ambiguities, of which the "=" operator is the least of them. In many dialects there several versions of END to contend with, for example. And then there are a lot of legacy constructs with special syntax such as LINE (0,0)-(100,100),3,BF. I have a soft spot in my heart for BASIC, since that's what I grew up on. I still follow FreeBASIC development. It's a very mature language and compiler now, though it struggles to find a reason to exist I think. It can't decide if it's C with a different syntax, or C++ with a different syntax (object-oriented and everything) or maybe something in between or completely different. From torriem at gmail.com Sun Jun 26 17:45:00 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 26 Jun 2016 15:45:00 -0600 Subject: Getting back into PyQt and not loving it. Message-ID: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> I'm starting to question the advice I gave not long ago to for new users to consider the Qt toolkit with Python. I just did a little project porting a simple graphical user interface from GTK+ to Qt (PyQt4 for now as that's what I have installed). For the most part it worked out pretty well. It's been a while since I used PyQt or PySide, and I had forgotten what a horrid Python experience Qt really is, at least in PyQt4. Maybe the bindings for Qt5 are better... I'll be working with them next as I convert my working code. Qt's a fantastic toolkit, and the most mature of any of them, and the most portable, but man the bindings are not Pythonic at all. PyQt does not seem to hide the C++-isms at all from the programmer. I am constantly wrapping things up in Qt classes like QRect, QPoint, QSize, etc, when really a python Tuple would have sufficed. All the data structures are wrapped in Qt C++ classes, so you end up writing what is really idiomatic C++ code using Python syntax. Not the best way to code Python! Implementing signals in a class, too, reminds you strongly that you're working with C++ as you have to construct their method signatures using types that map back into C++. From greg.ewing at canterbury.ac.nz Sun Jun 26 19:08:25 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Jun 2016 11:08:25 +1200 Subject: Can math.atan2 return INF? In-Reply-To: <87y45spgsz.fsf@elektro.pacujo.net> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: >>The singularity being talked about there is an artifact of a >>particular coordinate system; the theory predicts that there is no >>*physical* singularity at the event horizon. > > That theory can't be tested even in principle, can it? Therefore, it is > not scientific. It can in principle be tested by a scientist falling into the hole. The only problem is that he won't be able to tell anyone outside what he finds out, but that's a practical difficulty, not a philosophical one. A lot of what the early Greeks found out got lost in various library burnings, etc. Does that mean they weren't being scientific? > Religious theories about the afterlife face similar difficulties -- and > present similar extrapolations. I don't think they're similar at all. Show me the equations for one of these religious theories and I might change my mind... -- Greg From greg.ewing at canterbury.ac.nz Sun Jun 26 19:22:24 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Jun 2016 11:22:24 +1200 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: BartC wrote: > On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: > >> One of Python?s few mistakes was that it copied the C convention of >> using ?=? for assignment and ?==? for equality comparison. > > One of C's many mistakes. Unfortunately C has been very influential. I'm not sure it's fair to call it a mistake. C was designed for expert users, and a tradeoff was likely made based on the observation that assignment is used much more often than equality testing. > However, why couldn't Python have used "=" both for assignment, and for > equality? Because an expression on its own is a valid statement, so a = b would be ambiguous as to whether it meant assigning b to a or evaluating a == b and discarding the result. -- Greg From greg.ewing at canterbury.ac.nz Sun Jun 26 19:38:21 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Jun 2016 11:38:21 +1200 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: BartC wrote: > I did a year of it in the 1970s. Looks funny in lower case though. It's interesting how our perceptions of such things change. Up until my second year of university, my only experiences of computing had all been in upper case. Then we got a lecturer who wrote all his Pascal on the blackboard in lower case, and it looked extremely weird. Until then the idea of writing code in anything other than upper case hadn't even occurred to me. I quickly got used to it though, and nowadays, code written in upper case looks very quaint and old-fashioned! -- Greg From bc at freeuk.com Sun Jun 26 19:39:16 2016 From: bc at freeuk.com (BartC) Date: Mon, 27 Jun 2016 00:39:16 +0100 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: On 27/06/2016 00:22, Gregory Ewing wrote: > BartC wrote: >> On 26/06/2016 08:36, Lawrence D?Oliveiro wrote: >> >>> One of Python?s few mistakes was that it copied the C convention of >>> using ?=? for assignment and ?==? for equality comparison. >> >> One of C's many mistakes. Unfortunately C has been very influential. > > I'm not sure it's fair to call it a mistake. C was > designed for expert users, and a tradeoff was likely > made based on the observation that assignment is > used much more often than equality testing. You mean the rationale was based on saving keystrokes? A shame they didn't consider that when requiring parentheses around conditionals, semicolons, /*...*/ around comments, %d format codes and elaborate for-statements then! But you might be right in that it was probably based on existing usage of Fortran, PL/I and maybe even Basic. (Its predecessor 'B' used "=", but B came through BCPL which I believe used ":="; perhaps the mistake was in discarding that.) >> However, why couldn't Python have used "=" both for assignment, and >> for equality? > > Because an expression on its own is a valid statement, > so > > a = b > > would be ambiguous as to whether it meant assigning b > to a or evaluating a == b and discarding the result. And that would be another reason why == is needed for equality. -- Bartc From greg.ewing at canterbury.ac.nz Sun Jun 26 19:41:42 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Jun 2016 11:41:42 +1200 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <78b5ed0e-ec5f-6f54-b88c-4fed570115d2@mrabarnett.plus.com> <1e5a51af-cb31-f3fe-cc07-535ee8073ea6@icloud.com> Message-ID: Christopher Reimer wrote: > How can you not use chained assignments? I thought Python was the art of > the clever one-liners. :) No, Python is the art of writing clever one-liners using more than one line. -- Greg From llanitedave at birdandflower.com Sun Jun 26 21:05:18 2016 From: llanitedave at birdandflower.com (llanitedave) Date: Sun, 26 Jun 2016 18:05:18 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> Message-ID: <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> On Sunday, June 26, 2016 at 2:45:18 PM UTC-7, Michael Torrie wrote: > I'm starting to question the advice I gave not long ago to for new users > to consider the Qt toolkit with Python. > > I just did a little project porting a simple graphical user interface > from GTK+ to Qt (PyQt4 for now as that's what I have installed). For > the most part it worked out pretty well. It's been a while since I used > PyQt or PySide, and I had forgotten what a horrid Python experience Qt > really is, at least in PyQt4. Maybe the bindings for Qt5 are better... > I'll be working with them next as I convert my working code. > > Qt's a fantastic toolkit, and the most mature of any of them, and the > most portable, but man the bindings are not Pythonic at all. PyQt does > not seem to hide the C++-isms at all from the programmer. I am > constantly wrapping things up in Qt classes like QRect, QPoint, QSize, > etc, when really a python Tuple would have sufficed. All the data > structures are wrapped in Qt C++ classes, so you end up writing what is > really idiomatic C++ code using Python syntax. Not the best way to code > Python! Implementing signals in a class, too, reminds you strongly that > you're working with C++ as you have to construct their method signatures > using types that map back into C++. Not sure that wxPython is really any different in that respect, and Tkinter doesn't feel Pythonic to me, either -- considering how it's Tk at heart. So what's the alternative? There really is no good Python-based GUI tool, and that's a shame. From rustompmody at gmail.com Sun Jun 26 21:34:36 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 26 Jun 2016 18:34:36 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> Message-ID: <49847a89-50cb-4e24-8fb1-3e41283faa2d@googlegroups.com> On Monday, June 27, 2016 at 6:35:31 AM UTC+5:30, llanitedave wrote: > So what's the alternative? There really is no good Python-based GUI tool, and that's a shame. The last time Ranting Rick made a big rant about this (saying wxpython should replace tkinter in core CPython) everyone took note of the rant And missed the fact of the sux-state of GUI-in-python Yes this is one big bus that python missed From python at mrabarnett.plus.com Sun Jun 26 22:12:09 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Jun 2016 03:12:09 +0100 Subject: Getting back into PyQt and not loving it. In-Reply-To: <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> Message-ID: <2883132b-f862-5b51-fff9-b98486ff7dc5@mrabarnett.plus.com> On 2016-06-27 02:05, llanitedave wrote: > On Sunday, June 26, 2016 at 2:45:18 PM UTC-7, Michael Torrie wrote: >> I'm starting to question the advice I gave not long ago to for new users >> to consider the Qt toolkit with Python. >> >> I just did a little project porting a simple graphical user interface >> from GTK+ to Qt (PyQt4 for now as that's what I have installed). For >> the most part it worked out pretty well. It's been a while since I used >> PyQt or PySide, and I had forgotten what a horrid Python experience Qt >> really is, at least in PyQt4. Maybe the bindings for Qt5 are better... >> I'll be working with them next as I convert my working code. >> >> Qt's a fantastic toolkit, and the most mature of any of them, and the >> most portable, but man the bindings are not Pythonic at all. PyQt does >> not seem to hide the C++-isms at all from the programmer. I am >> constantly wrapping things up in Qt classes like QRect, QPoint, QSize, >> etc, when really a python Tuple would have sufficed. All the data >> structures are wrapped in Qt C++ classes, so you end up writing what is >> really idiomatic C++ code using Python syntax. Not the best way to code >> Python! Implementing signals in a class, too, reminds you strongly that >> you're working with C++ as you have to construct their method signatures >> using types that map back into C++. > > Not sure that wxPython is really any different in that respect, and Tkinter doesn't feel Pythonic to me, either -- considering how it's Tk at heart. So what's the alternative? There really is no good Python-based GUI tool, and that's a shame. > Is it a problem with Tk itself or with the Python wrapper? Would it be better if we made a more Pythonic version of Tkinter, e.g. making Frame.title a property? From torriem at gmail.com Sun Jun 26 22:41:00 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 26 Jun 2016 20:41:00 -0600 Subject: Getting back into PyQt and not loving it. In-Reply-To: <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> Message-ID: <31b94dd8-d066-a014-c38d-d5aed7452e58@gmail.com> On 06/26/2016 07:05 PM, llanitedave wrote: > Not sure that wxPython is really any different in that respect, and > Tkinter doesn't feel Pythonic to me, either -- considering how it's > Tk at heart. So what's the alternative? There really is no good > Python-based GUI tool, and that's a shame. Guess I kind of ended my email early. Actually GTK+ is pretty nice to work with in Python. The bindings feel quite good and it's hard to tell where stuff is written in python and where it's written in C. The integration between Python data types and the glib backend stuff is pretty seamless. I can't recall ever wrapping up stuff in a GObject structure, and Python idioms work rather well including iteration. Try it out; it's pretty slick. GTK+'s downsides are that though it's available on Windows and Mac, those versions don't get as much love and without some real work don't integrate very well. Also GTK+ development seems to focus more on Gnome than on general application development. If GTK+ had first-class support on Windows and Mac, including native themes and seamless UI integration (file and print dialogs), I'd say GTK+ would be the only game in town for Python programmers. Unfortunately, unless you're only concerned with Linux, GTK+ is probably not going to be your choice. From steve at pearwood.info Sun Jun 26 22:59:21 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 27 Jun 2016 12:59:21 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> Message-ID: <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jun 2016 09:08 am, Gregory Ewing wrote: > Marko Rauhamaa wrote: >>>The singularity being talked about there is an artifact of a >>>particular coordinate system; the theory predicts that there is no >>>*physical* singularity at the event horizon. >> >> That theory can't be tested even in principle, can it? Therefore, it is >> not scientific. > > It can in principle be tested by a scientist falling into > the hole. The only problem is that he won't be able to > tell anyone outside what he finds out, but that's a > practical difficulty, not a philosophical one. Marko's complaint about black holes seems to be based on a very naive definition of "scientific", specifically Karl Popper's naive empirical falsification theory of science. Unfortunately, falsification is not even close to a good description of what scientists do in their day-to-day work. Naive empirical falsification can, at best, be considered as a best-practice rule: if you have no way of falsifying something even in principle, then it's not scientific. But it doesn't really give you much in the way of practical guidance. What counts as falsification? How do you falsify historical events like "the Earth formed from a cloud of gas"? We weren't there to observe it, we can't repeat the experiment, and the entire process from start to finish takes too long for anyone to watch a cloud of gas coalesce into a solid planet. So, black holes... We have no way of seeing what goes on past the black hole's event horizon, since light cannot escape. But we can still see *some* properties of black holes, even through their event horizon: their mass, any electric charge they may hold, their angular momentum. We can test the proposition that a black hole that forms from hydrogen is no different from one which forms from uranium. We can look for variations in randomness in the Hawking radiation emitted, we can test that the event horizon is where we expect, etc. An electrically neutral black hole with a magnetic field would likely falsify a lot of theories about what goes on inside the event horizon. And it may be that some future advance in quantum gravity theory will suggest a way of testing the prediction of a singularity. There are theories of black holes that predict "ring shaped" singularities, and suggest that in principle one might "miss the singularity" and fall out of a worm hole at the other end, although its doubtful that this would apply to anything bigger than an atom. I don't think many physicists actually believe that the singularity is a real thing, rather than just a failure of our current gravitational theories to correctly model matter under extreme conditions. After all, we've been here before, with the prediction that a black-body should radiate an infinite amount of energy at a finite temperature: https://en.wikipedia.org/wiki/Ultraviolet_catastrophe [...] >> Religious theories about the afterlife face similar difficulties -- and >> present similar extrapolations. > > I don't think they're similar at all. Show me the equations > for one of these religious theories and I might change > my mind... I don't think that the essential difference between a scientific theory and a non-scientific one is the presence or absence of *equations*. There's a lot of grey area between science and non-science, but I think a good start is to ask, "how do you know?". If the answer comes down to one of the following: - divine revelation, including from gurus, angels and spirits; - visions and inspiration; - "it just stands to reason"; - "because otherwise, what would be the point?" then its not scientific. The last means its wishful thinking. Maybe there is no point. Perhaps things just are, and meaning is what we decide on, not an inherent part of the universe. The third is just a cop-out. If you can't explain the reason, there probably isn't one. And the first two are necessarily subjective and forms of argument by authority: All swans are white[1] because The Master said so, and who are you to question The Master? Whereas, I think that for a first degree approximation, we can say that science must be *objective*. Often that does mean it involved equations, after all the laws of mathematics are the same for all of us. But objective fact does not necessarily require maths. Even in the ancient days of humanity, we can be pretty sure that two Neandertals stepping out of their cave to watch the sun rise in the east would agree on where the light was coming from. If one faced into the sun and shaded her eyes, while the other turned his back on the sun and shaded his eyes, we can be confident that the second was mucking about :-) And that's where all forms of religious revelation fail. Ultimately, revelation divides the world into two: - those who personally know the truth; - and those who just have to take their word for it. "God wants you to give me your money, honest. Oh, and he also doesn't want you to eat carrots. Don't question the Lord!" [1] Apart from black swans, which came as an awful shock for philosophers when they learned of their existence. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From cake240 at gmail.com Sun Jun 26 23:13:55 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Sun, 26 Jun 2016 20:13:55 -0700 (PDT) Subject: Empty List Message-ID: <4b0bb7d6-d5b9-4f30-a7be-e964cd4132bf@googlegroups.com> Hi There, What is the point of this code?: word=[] print(word) The result is [] When would I need to use something like this? Thank you! From lawrencedo99 at gmail.com Sun Jun 26 23:15:41 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 26 Jun 2016 20:15:41 -0700 (PDT) Subject: argparse and subparsers In-Reply-To: References: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> Message-ID: <1d344f89-831f-43b4-9099-8ab03482fc3a@googlegroups.com> On Monday, June 27, 2016 at 6:56:41 AM UTC+12, Joseph L. Casale wrote: > This has become unmaintainable as the manual slicing is always subject > to a new case by where a parser has a positional, switch or optional > parameter for example. Also, since argv is grouped by subparser > specifiers, if a parameter has input that matches a keyword > it all goes pear shaped. Write your own parser. It?s not hard--the common Unix/Linux command line conventions are quite simple, and it?s already pre-split into words for you. From steve at pearwood.info Sun Jun 26 23:48:14 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 27 Jun 2016 13:48:14 +1000 Subject: Empty List References: <4b0bb7d6-d5b9-4f30-a7be-e964cd4132bf@googlegroups.com> Message-ID: <5770a203$0$1605$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jun 2016 01:13 pm, Elizabeth Weiss wrote: > Hi There, > > What is the point of this code?: > > word=[] > print(word) > > The result is [] > > When would I need to use something like this? As given, never. Nor would you need: num = 0 print(num) It's pretty boring, trivial code that does nothing interesting. And you could simplify it, make it even more trivial: print([]) Why would you do that? You probably wouldn't bother. But each line is very useful, if taken as part of a bigger, more useful program! Look at the first line: word = [] This creates a variable, "word", and assigns an empty list to it. But once you have an empty list, you can start putting things into it. Once you have a list with items in it, there are all sorts of things you can usefully do: - append items to the end; - insert items at the start or the middle; - sort the list; - reverse the list; - pull items out of the list; - count how many items are in the list; - search for matching items and many more. The sky is the limit, and that's what programming is about. Just because the list *starts* as empty doesn't mean it must remain empty forever. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From christopher_reimer at icloud.com Mon Jun 27 00:01:11 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sun, 26 Jun 2016 21:01:11 -0700 Subject: Empty List In-Reply-To: <4b0bb7d6-d5b9-4f30-a7be-e964cd4132bf@googlegroups.com> References: <4b0bb7d6-d5b9-4f30-a7be-e964cd4132bf@googlegroups.com> Message-ID: On 6/26/2016 8:13 PM, Elizabeth Weiss wrote: > Hi There, > > What is the point of this code?: > > word=[] > print(word) > > The result is [] > > When would I need to use something like this? > > Thank you! Sometimes you need to assign an empty list to a variable prior to using it in a looping structure. Here's the load function from the BASIC interpreter/compiler I'm working on in Python. def load(filename): tokens = [] with open(filename) as source: for line in source: tokens.append(tokenizer(line)) return tokens Here's the BASIC file I'm loading: 10 PRINT "HELLO WORLD!" 20 GOTO 10 This function assigns an empty list to tokens, reads a line of text from a file, and appends a tokenized list to tokens, and return tokens as a list of lists. [['10', 'PRINT', '"HELLO WORLD!"'], ['20', 'GOTO', '10']] Chris R. From lawrencedo99 at gmail.com Mon Jun 27 00:20:54 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 26 Jun 2016 21:20:54 -0700 (PDT) Subject: Operator Precedence: One Thing Python Got Right Message-ID: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> There is one thing Python did not slavishly copy from C. While it has (mostly) the same operators, and exclusively adopted the iso646 names for the Boolean operators (which you can also use in C and C++, by the way, but not Java), it made a slight tweak to the operator precedence rules . Namely, whereas in C, C++ or Java you have to write (bitval & bitmask) == needbits in Python you can dispense with the parentheses bitval & bitmask == needbits How did I discover this? Entirely by accident: I forgot the parentheses one day and *didn?t* hit a bug. :) From zachary.ware at gmail.com Mon Jun 27 00:26:54 2016 From: zachary.ware at gmail.com (Zachary Ware) Date: Sun, 26 Jun 2016 23:26:54 -0500 Subject: Question on compiling on linux In-Reply-To: <576E389B.7060709@chello.at> References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> <576E389B.7060709@chello.at> Message-ID: On Saturday, June 25, 2016, Steven Truppe wrote: > > i hope this email works like you expected! Not quite, but closer. You've quoted me properly, but you added your reply above the quote, so-called "top-posting". A: Because you have to read things in reverse order. Q: Why? A: Top-posting. Q: What's one of the most annoying common email practices? But that's all rather beside the point :) > I found the libpython3.so, i don't know why i was not able to see it, Note that libpython3.so is very different from libpython3.5m.so: libpython3.so is the interface to the PEP 384 stable ABI. It does not include the full interpreter, and is in fact just a shim that redirects to libpython3.5m.so. It's only really useful for building extension modules and using the resulting binary with multiple versions of Python. > thank you very much to everyone wo helped me! I'm glad we've been able to clear things up a bit! > No my last question(s) is how can i create debug/release builds ? Pass '--with-pydebug' to ./configure to get a debug build. On Linux, the difference between a debug and release build is just the definition of debug-related macros (Py_DEBUG, _DEBUG, NDEBUG) and the optimization level. On Windows, another big difference in a debug build is that it is linked against the debug CRT. There is no such thing on Linux, so you likely won't need a debug version of Python just to debug your embedding app the way you would on Windows. Hope this helps, -- Zach From steve at pearwood.info Mon Jun 27 00:28:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 27 Jun 2016 14:28:12 +1000 Subject: Operator Precedence: One Thing Python Got Right References: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> Message-ID: <5770ab5d$0$1621$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jun 2016 02:20 pm, Lawrence D?Oliveiro wrote: > There is one thing Python did not slavishly copy from C. Only one? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From s.garg.computer at gmail.com Mon Jun 27 00:55:57 2016 From: s.garg.computer at gmail.com (Sachin Garg) Date: Mon, 27 Jun 2016 00:55:57 -0400 Subject: argparse and subparsers In-Reply-To: References: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> Message-ID: On Sunday 26 June 2016 02:51 PM, Joseph L. Casale wrote: > I have some code where sys.argv is sliced up and manually fed to discrete argparse > instances each with a single subparser. The reason the discrete parsers all having a > single subparser was to make handling the input simpler, the first arg in the slice > could be left in. > > This has become unmaintainable as the manual slicing is always subject to a new case > by where a parser has a positional, switch or optional parameter for example. Also, since > argv is grouped by subparser specifiers, if a parameter has input that matches a keyword > it all goes pear shaped. > > The underlying root of this mess is a long unaddressed limitation in argparse to support > multiple subparser specifications on the same invocation: > > prog.py -x -y 42 -foo bar subParserA -a 1 -b 2 subParserB -a 1 -b 2 subParserB -a 1 -b 2 > > The base arguments (-x -y 42 -foo bar). > An invocation of "subParserA" and its arguments (-a 1 -b 2). > Two invocations of "subParserB" and their arguments. > > etc... > > I have seen some creative ways to overcome this on stacktrace, however I thought I'd > see what people here have done. The code is pinned at 2.7 and while several people > have created alternate implementations which address many of argparses failures, its > desired to stick to base lib but that can easily be changed given a compelling reason > if an alternate implementation exists that works well. Not sure if this fits the bill, or makes sense here, but I came cross "docopt" which touts itself as a "Command-line interface description language". I used it in a project and it seems to be pretty easy to use as well as elegant. It stores the arguments & values as a dictionary, keyed by the argument. from docopt import docopt arguments = docopt(__doc__, version='0.2') # Set verbose flag verbose = False if arguments['--verbose']: verbose = True elif arguments['-q']: verbose = False # If --noencrypt, --nosign or --notransfer is specified, put that in config if arguments['--no-encrypt']: config['noencrypt'] = True else: config['noencrypt'] = False if arguments['--no-sign']: config['nosign'] = True else: config['nosign'] = False if arguments['--no-transfer']: config['notransfer'] = True else: config['notransfer'] = False and so on ... From lawrencedo99 at gmail.com Mon Jun 27 01:34:14 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 26 Jun 2016 22:34:14 -0700 (PDT) Subject: argparse and subparsers In-Reply-To: References: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> Message-ID: <5b1c7833-5cd3-47b3-b82b-643e88606fef@googlegroups.com> On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: > # Set verbose flag > verbose = False > if arguments['--verbose']: > verbose = True > elif arguments['-q']: > verbose = False Don?t you just love code (and commenting) like this... From john_ladasky at sbcglobal.net Mon Jun 27 02:15:49 2016 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 26 Jun 2016 23:15:49 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> <31b94dd8-d066-a014-c38d-d5aed7452e58@gmail.com> Message-ID: On Sunday, June 26, 2016 at 7:41:17 PM UTC-7, Michael Torrie wrote: > If GTK+ had first-class support on Windows and Mac, including native > themes and seamless UI integration (file and print dialogs), I'd say > GTK+ would be the only game in town for Python programmers. > Unfortunately, unless you're only concerned with Linux, GTK+ is probably > not going to be your choice. Although I work almost exclusively in Linux, I've been teaching Python for several years as a sideline, and my students usually do not use Linux. I insist on teaching my students Python 3. Unless they're professionals who must work with legacy code (and, so far, none of them have been), I think I would be doing them a disservice to teach them Python 2. I started with WxPython, but WxPython/Phoenix has been very slow to migrate to Python 3. Between the Py3 requirement and the need to work with all major OS's, I decided to learn PyQt and not GTK+. In my current day job, I'm developing an application on a Linux box, but I'll be handing it off to Windows users. My choice of PyQt turned out to be the right one in that situation as well. From marko at pacujo.net Mon Jun 27 02:40:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 27 Jun 2016 09:40:09 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87inwvp22e.fsf@elektro.pacujo.net> Steven D'Aprano : > Naive empirical falsification can, at best, be considered as a > best-practice rule: if you have no way of falsifying something even in > principle, then it's not scientific. But it doesn't really give you > much in the way of practical guidance. What counts as falsification? We cannot get any information on black holes proper because black holes cannot come into existence according to the very theory that predicts black holes. It will take infinitely long for an event horizon to form. Speculating on what happens to an astronaut falling in is not much different from speculating what happens after the end of the world. > We have no way of seeing what goes on past the black hole's event > horizon, since light cannot escape. But we can still see *some* > properties of black holes, even through their event horizon: their > mass, any electric charge they may hold, their angular momentum. If an event horizon cannot come into existence, you can only see properties of almost-black-holes. Even though there probably is virtually no difference between the two astronomically, it relieves physicists from answering some awkward questions on the goings-on inside an event horizon. > We can test the proposition that a black hole that forms from hydrogen > is no different from one which forms from uranium. We can look for > variations in randomness in the Hawking radiation emitted, we can test > that the event horizon is where we expect, etc. An electrically > neutral black hole with a magnetic field would likely falsify a lot of > theories about what goes on inside the event horizon. If an event horizon cannot ever form, you can't really test any of that stuff. Marko From lawrencedo99 at gmail.com Mon Jun 27 02:44:51 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 26 Jun 2016 23:44:51 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> <31b94dd8-d066-a014-c38d-d5aed7452e58@gmail.com> Message-ID: On Monday, June 27, 2016 at 6:16:01 PM UTC+12, John Ladasky wrote: > Between the Py3 requirement and the need to work with all major OS's, I > decided to learn PyQt and not GTK+. GTK+ is available for Python 3. No doubt it will work on Windows as well, once Microsoft gets its Linux compatibility layer debugged... From dieter at handshake.de Mon Jun 27 03:08:16 2016 From: dieter at handshake.de (dieter) Date: Mon, 27 Jun 2016 09:08:16 +0200 Subject: I seem to be creating a dict that I cannot access the keys of References: <8c9b5b13-c6cc-458d-9d31-56f7e5db10c4@googlegroups.com> <871t3llnao.fsf@handshake.de> Message-ID: <8737nz9kin.fsf@handshake.de> Sayth Renshaw writes: >> The code below is obviously wrong - it is surprising that you get >> anything other than an exception. See comments below inserted into >> your code. >> >> > def parseXML(): >> > ... >> > result = etree.tostring(tree.getroot(), pretty_print=True) >> >> "result" here is obviously a string. >> >> > for sample in result: >> >> This means that "sample" successively hold the characters composing >> the string "result". >> >> > noms = (dict(zip(atts, map(sample.attrib.get, atts)))) >> >> You should get "AttributeError: str object does not have attribute `attrib`". > > The attrib is an lxml function, when you have defined a root > http://lxml.de/tutorial.html Correctly, this should read: "attrib" is an attribute of "ETree" nodes (!) (providing a mapping like access to the nodes attributes). It is *NOT* an attribute of string (!) objects. You have converted the tree root into a string (using "etree.tostring") and then iterated over the resulting string. On those characters you access "attrib" - which will not work as you expect. From lorenzo.gatti at gmail.com Mon Jun 27 03:27:01 2016 From: lorenzo.gatti at gmail.com (lorenzo.gatti at gmail.com) Date: Mon, 27 Jun 2016 00:27:01 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> Message-ID: <7c46f179-9077-4324-a46c-715a57563783@googlegroups.com> PyGTK is obsolete and stopped at Python 2.7, while PyGObject for Windows is several versions behind (currently 3.18 vs 3.21) and it doesn't support Python 3.5. Game over for GTK+. From list at qtrac.plus.com Mon Jun 27 03:33:25 2016 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 27 Jun 2016 00:33:25 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> <2883132b-f862-5b51-fff9-b98486ff7dc5@mrabarnett.plus.com> Message-ID: <9b31a23a-9ba4-426b-97d5-f6e31244d1ff@googlegroups.com> On Monday, June 27, 2016 at 3:12:34 AM UTC+1, MRAB wrote: [snip] > > Not sure that wxPython is really any different in that respect, and Tkinter doesn't feel Pythonic to me, either -- considering how it's Tk at heart. So what's the alternative? There really is no good Python-based GUI tool, and that's a shame. > > > Is it a problem with Tk itself or with the Python wrapper? Would it be > better if we made a more Pythonic version of Tkinter, e.g. making > Frame.title a property? My main complaints about Tkinter are: - Not very Pythonic. - The event handling works very differently from other toolkits so it can be quite tricky to learn and get right. - The bindings are incomplete (e.g., http://bugs.python.org/issue3405) And for me there are show-stopping weaknesses. - Show stopper #1: there is no nice way to create custom widgets. Compare with PySide, PyQt (& wxPython I believe) where you can inherit some "widget" base class and paint it however you like and do any event handling you like to get custom appearance and behaviour. Sure, you can do this with canvas as the base, but it seems like you have do do far more work in Tkinter than the other toolkits. - Show stopper #2: there doesn't seem to be any way to create one line and multiline styled text editors (e.g., supporting bold, italic, underline, superscript, subscript, colour, font). The text widget can display all these (and more) but I haven't found any way to get it to be able to provide _editing_ of all these. (You can get it to do bold, italic, underline, and colour, but I certainly can't get these plus super- and sub-script and font support from Python. Nor is there any useful load/save in HTML or any other format.) Hopefully people will point me to docs or examples to prove me wrong about these weaknesses:-) Or better still, maybe the seemingly moribund PyGUI project could be revived or maybe someone will create bindings for libui or for IUP so that Python could have a lightweight GUI-only cross-platform library that had decent support for creating custom widgets in Python but left all non-GUI functionality to the rest of the Python ecosystem. From pdorange at pas-de-pub-merci.mac.com Mon Jun 27 04:55:50 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Mon, 27 Jun 2016 10:55:50 +0200 Subject: Empty List References: <4b0bb7d6-d5b9-4f30-a7be-e964cd4132bf@googlegroups.com> Message-ID: <1mpi0ws.12wwxiailna1cN%pdorange@pas-de-pub-merci.mac.com> Elizabeth Weiss wrote: > What is the point of this code?: > > word=[] > print(word) > > The result is [] > > When would I need to use something like this? You often need to intialize a list, sometime with (empty) = []. Then after initializing you should do "something" that perhaps will fill the list (word.append("hello"). Then after do your job, you perhaps need to print it. But initializing and just print, will do nothing else than initialize and print the result... As state before this code more or less like : a=0 print a -- Pierre-Alain Dorange Moof Ce message est sous licence Creative Commons "by-nc-sa-2.0" From bc at freeuk.com Mon Jun 27 05:53:09 2016 From: bc at freeuk.com (BartC) Date: Mon, 27 Jun 2016 10:53:09 +0100 Subject: Operator Precedence: One Thing Python Got Right In-Reply-To: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> References: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> Message-ID: On 27/06/2016 05:20, Lawrence D?Oliveiro wrote: > There is one thing Python did not slavishly copy from C. While it has (mostly) the same operators, and exclusively adopted the iso646 names for the Boolean operators (which you can also use in C and C++, by the way, but not Java), it made a slight tweak to the operator precedence rules . Namely, whereas in C, C++ or Java you have to write > > (bitval & bitmask) == needbits > > in Python you can dispense with the parentheses > > bitval & bitmask == needbits C has some 15 operator precedences (even if you consider only normal binary operators, there are 10; and that doesn't include "**"). It's not something you would choose to adopt in another language! (On the subject of things wrong with C, here's a list I made of around 100: https://github.com/bartg/langs/blob/master/C%20Problems.md Although from the point of view of a more streamlined and modern low-level statically-typed language, not of one like Python.) > How did I discover this? Entirely by accident: I forgot the parentheses one day and *didn?t* hit a bug. :) That's not wise. It could have worked by chance. And putting in the parentheses anyway means the fragment of code stays interchangeable with C. -- Bartc From steve+comp.lang.python at pearwood.info Mon Jun 27 06:28:49 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 27 Jun 2016 20:28:49 +1000 Subject: argparse and subparsers References: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> <5b1c7833-5cd3-47b3-b82b-643e88606fef@googlegroups.com> Message-ID: <5770ffe3$0$2901$c3e8da3$76491128@news.astraweb.com> On Monday 27 June 2016 15:34, Lawrence D?Oliveiro wrote: > On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: > >> # Set verbose flag >> verbose = False >> if arguments['--verbose']: >> verbose = True >> elif arguments['-q']: >> verbose = False > > Don?t you just love code (and commenting) like this... Not particularly, but what are you going to do? You need to support a minimum of three cases: - a default setting; - the case where the user passes --verbose; - the case where the user passes -q; (I'm not sure why --verbose take a long argument but no short argument -v; and likewise why there's a -q short argument but no --quiet long version. Oh well.) A simple test-and-set for each argument is the simplest, most straight-forward way of handling this. It's not *pretty* or *elegant* code, but it is the easiest to read, write and comprehend, and in my opinion much better than alternatives involving ever more arcane method calls to ever more complicated classes. I don't have experience with docutils and cannot judge whether or not Sachin's snippets are good or bad examples of use, but find myself going back to the good old fashioned GNU style command line parser whenever I need a few command line options. If you find yourself writing subparsers and "mandatory options" and needing entire help screens to describe single arguments (as in "foo --help arg") then really I think you should give up the pretence that you're dealing with command line options, and you should write a mini-language for your application. (hg, git, memcoder, soc etc. I'm talking about you.) -- Steve From steve at pearwood.info Mon Jun 27 08:10:29 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 27 Jun 2016 22:10:29 +1000 Subject: Operator Precedence: One Thing Python Got Right References: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> Message-ID: <577117b7$0$1618$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jun 2016 07:53 pm, BartC wrote: > On 27/06/2016 05:20, Lawrence D?Oliveiro wrote: >> How did I discover this? Entirely by accident: I forgot the parentheses >> one day and *didn?t* hit a bug. :) > > That's not wise. It could have worked by chance. And putting in the > parentheses anyway means the fragment of code stays interchangeable with > C. Do you write much Python code that you expect to also be valid C code? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bgailer at gmail.com Mon Jun 27 08:22:46 2016 From: bgailer at gmail.com (Bob Gailer) Date: Mon, 27 Jun 2016 08:22:46 -0400 Subject: Assignment Versus Equality In-Reply-To: <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> Message-ID: On Jun 26, 2016 5:29 PM, "Michael Torrie" wrote: > > On 06/26/2016 12:47 PM, Christopher Reimer wrote: > Sounds like fun. Every aspiring programmer should write an interpreter > for some language at least once in his life! In the mid 1970' s I helped maintain an installation of IBM' s APL interpreter at Boeing Computer Services. APL uses its own special character set, making code unambiguous and terse. It used a left-arrow for assignment, which was treated as just another operator. I will always miss "embedded assignment". A year later I worked on a project that ran on a CDC 6600? where only FORTRAN was available. The program's job was to apply user's commands to manage a file system. FORTRAN was not the best language for that task, so I designed my own language, and wrote an interpreter for it in FORTRAN. In retrospect a very good decision. That program was in use for 10 years! From rustompmody at gmail.com Mon Jun 27 08:48:26 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 05:48:26 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> Message-ID: <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> On Monday, June 27, 2016 at 5:53:07 PM UTC+5:30, Bob Gailer wrote: > On Jun 26, 2016 5:29 PM, "Michael Torrie" wrote: > > > > On 06/26/2016 12:47 PM, Christopher Reimer wrote: > > > Sounds like fun. Every aspiring programmer should write an interpreter > > for some language at least once in his life! > > In the mid 1970' s I helped maintain an installation of IBM' s APL > interpreter at Boeing Computer Services. APL uses its own special character > set, making code unambiguous and terse. It used a left-arrow for > assignment, which was treated as just another operator. I will always miss > "embedded assignment". In the past, APL's ? may not have been practicable (ie - without committing to IBM... which meant - $$$ - Also it was a hardware commitment (trackball?) - etc Today that '?' costs asymptotically close to '=' To type :: 3 chars CAPSLOCK '<' '-' To setup :: [On Ubuntu Unity] System-Settings ? Keyboard ? Shortcuts-Tab ? Typing ? Make Compose CAPSLOCK To see :: Its ONE CHAR, just like '=' and ? of ':=' tl;dr Anyone opposing richer charsets is guaranteedly using arguments from 1970 PS Google Groups is wise enough to jump through hoops trying to encode my message above as latin-1, then as Windows 1252 and only when that does not work as UTF-8 ie it garbles ? into <- etc So some ????? (ie Hindi) to convince GG to behave From rustompmody at gmail.com Mon Jun 27 09:15:47 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 06:15:47 -0700 (PDT) Subject: Can math.atan2 return INF? In-Reply-To: <87inwvp22e.fsf@elektro.pacujo.net> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> Message-ID: <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> On Monday, June 27, 2016 at 12:10:21 PM UTC+5:30, Marko Rauhamaa wrote: > Steven D'Aprano : > > > Naive empirical falsification can, at best, be considered as a > > best-practice rule: if you have no way of falsifying something even in > > principle, then it's not scientific. But it doesn't really give you > > much in the way of practical guidance. What counts as falsification? > > We cannot get any information on black holes proper because black holes > cannot come into existence according to the very theory that predicts > black holes. It will take infinitely long for an event horizon to form. > Speculating on what happens to an astronaut falling in is not much > different from speculating what happens after the end of the world. > > > We have no way of seeing what goes on past the black hole's event > > horizon, since light cannot escape. But we can still see *some* > > properties of black holes, even through their event horizon: their > > mass, any electric charge they may hold, their angular momentum. > > If an event horizon cannot come into existence, you can only see > properties of almost-black-holes. Even though there probably is > virtually no difference between the two astronomically, it relieves > physicists from answering some awkward questions on the goings-on inside > an event horizon. > > > We can test the proposition that a black hole that forms from hydrogen > > is no different from one which forms from uranium. We can look for > > variations in randomness in the Hawking radiation emitted, we can test > > that the event horizon is where we expect, etc. An electrically > > neutral black hole with a magnetic field would likely falsify a lot of > > theories about what goes on inside the event horizon. > > If an event horizon cannot ever form, you can't really test any of that > stuff. I am reminded of an argument I once had with a colleague about infinite, lazy data-structures I said that for the Haskell list [0..] [0..] ++ [-1] == [0..] ++ is like python's list append + This could equally apply to a Python generator like: def nats(): i=0 while True: yield i i += 1 He said (in effect) yes that -1 would not be detectable but its still there! From gandalf at shopzeus.com Mon Jun 27 09:27:51 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Mon, 27 Jun 2016 15:27:51 +0200 Subject: Can math.atan2 return INF? In-Reply-To: <5769ec9e$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec9e$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Thanks, I'm in the same position as you, except that I'm in the position > where I need it use the result, and if it ever returns INF my function will > blow up. But it doesn't look like that can happen. > Doesn't atan2 relies on the C lib math floating point library? At least in CPython. I think (but not 100% sure) that it is implementation dependent, and returns what is returned by clib floating point lib. Since the meaning of atan2 is an angle, it should always be between [-pi,pi]. The only exception maybe when there is a NaN in the arguments. But I cannot think of any interpretation where atan2 would return Inf or -Inf. From steve at pearwood.info Mon Jun 27 09:28:00 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 27 Jun 2016 23:28:00 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> Message-ID: <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jun 2016 10:48 pm, Rustom Mody wrote: > PS Google Groups is wise enough to jump through hoops trying to encode my > message above as latin-1, then as Windows 1252 and only when that does not > work as UTF-8 There is nothing admirable about GG (or any other newsreader or email client) defaulting to legacy encodings like Latin-1 and especially not Windows 1252. Certainly the user should be permitted to explicitly set the encoding, but otherwise the program should default to UTF-8. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From gandalf at shopzeus.com Mon Jun 27 09:30:48 2016 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Mon, 27 Jun 2016 15:30:48 +0200 Subject: Which one is the best JSON parser? In-Reply-To: References: <1150800609.939828.1466715495931.JavaMail.yahoo.ref@mail.yahoo.com> <1150800609.939828.1466715495931.JavaMail.yahoo@mail.yahoo.com> Message-ID: <5cd93315-95fd-b652-448a-19a6f3fe38ad@shopzeus.com> On 2016-06-23, MRAB wrote: >> On 2016-06-23 21:58, David Shi via Python-list wrote: >>> Can any one tell me? >>> Regards. >>> David >>> >> There's one in the standard library. > Which has always worked fine for me... Which always reminds me: >>> import json >>> d = {0:1, False:2} >>> d {0: 2} >>> json.dumps(d) '{"0": 2}' >>> WAT :-) From ned at nedbatchelder.com Mon Jun 27 09:43:28 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 27 Jun 2016 06:43:28 -0700 (PDT) Subject: Which one is the best JSON parser? In-Reply-To: References: <1150800609.939828.1466715495931.JavaMail.yahoo.ref@mail.yahoo.com> <1150800609.939828.1466715495931.JavaMail.yahoo@mail.yahoo.com> <5cd93315-95fd-b652-448a-19a6f3fe38ad@shopzeus.com> Message-ID: <0cb3a4f5-2273-42b5-b8b9-de4bc7898e0f@googlegroups.com> On Monday, June 27, 2016 at 9:31:04 AM UTC-4, Nagy L?szl? Zsolt wrote: > On 2016-06-23, MRAB wrote: > >> On 2016-06-23 21:58, David Shi via Python-list wrote: > >>> Can any one tell me? > >>> Regards. > >>> David > >>> > >> There's one in the standard library. > > Which has always worked fine for me... > Which always reminds me: > > >>> import json > >>> d = {0:1, False:2} > >>> d > {0: 2} > >>> json.dumps(d) > '{"0": 2}' > >>> > > WAT :-) Python's booleans being ints is a remnant of history. I agree it would be better for True and False to be unrelated to 1 and 0. The conversion of 0 to "0" is because JSON can only use strings for keys in objects. It might be better for dumps to fail if a non-string key is encountered, but I'm not sure. --Ned. From marko at pacujo.net Mon Jun 27 09:45:48 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 27 Jun 2016 16:45:48 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> Message-ID: <87bn2mwxrn.fsf@elektro.pacujo.net> Rustom Mody : > I am reminded of an argument I once had with a colleague about > infinite, lazy data-structures > > I said that for the Haskell list [0..] > > [0..] ++ [-1] == [0..] [...] > He said (in effect) yes that -1 would not be detectable but its still > there! Georg Cantor would probably be with your colleague, but then, Georg Cantor was not a scientist. Marko From random832 at fastmail.com Mon Jun 27 09:56:58 2016 From: random832 at fastmail.com (Random832) Date: Mon, 27 Jun 2016 09:56:58 -0400 Subject: Question on compiling on linux In-Reply-To: References: <576D4AF9.40407@chello.at> <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> <576E389B.7060709@chello.at> Message-ID: <1467035818.2222949.649673417.18E0D090@webmail.messagingengine.com> On Mon, Jun 27, 2016, at 00:26, Zachary Ware wrote: > A: Because you have to read things in reverse order. > Q: Why? > A: Top-posting. > Q: What's one of the most annoying common email practices? Which is witty, but doesn't *actually* explain why it's bad. 1. The intent, as I understand it, with top-posting is that the reply message stands on its own, and the quoted message is just "attached" in case someone needs to refer back to it, rather than representing a conversational flow as the Q/A format does. 2. Most email clients sort messages or threads by date with the most recent (or most recently updated) at the top, so there's no generalized principle at work against having later things appear above earlier things. From marko at pacujo.net Mon Jun 27 09:58:24 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 27 Jun 2016 16:58:24 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877fdawx6n.fsf@elektro.pacujo.net> Steven D'Aprano : > On Mon, 27 Jun 2016 10:48 pm, Rustom Mody wrote: > >> PS Google Groups is wise enough to jump through hoops trying to >> encode my message above as latin-1, then as Windows 1252 and only >> when that does not work as UTF-8 > > There is nothing admirable about GG (or any other newsreader or email > client) defaulting to legacy encodings like Latin-1 and especially not > Windows 1252. > > Certainly the user should be permitted to explicitly set the encoding, > but otherwise the program should default to UTF-8. The users should be completely oblivious to such technicalities as character encodings. As for those technicalities, a MIME-compliant client is free to use any well-defined, widely-used character encoding as long as it is properly declared. Marko From grant.b.edwards at gmail.com Mon Jun 27 09:59:39 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Jun 2016 13:59:39 +0000 (UTC) Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: On 2016-06-26, BartC wrote: > (Note, for those who don't know (old) Fortran, that spaces and tabs are > not significant. So those dots are needed, otherwise "a eq b" would be > parsed as "aeqb".) I've always been baffled by that. Were there other languages that did something similar? Why would a language designer think it a good idea? Did the poor sod who wrote the compiler think it was a good idea? -- Grant Edwards grant.b.edwards Yow! I left my WALLET in at the BATHROOM!! gmail.com From rustompmody at gmail.com Mon Jun 27 10:01:24 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 07:01:24 -0700 (PDT) Subject: Can math.atan2 return INF? In-Reply-To: <87bn2mwxrn.fsf@elektro.pacujo.net> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> <87bn2mwxrn.fsf@elektro.pacujo.net> Message-ID: On Monday, June 27, 2016 at 7:16:03 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > > I am reminded of an argument I once had with a colleague about > > infinite, lazy data-structures > > > > I said that for the Haskell list [0..] > > > > [0..] ++ [-1] == [0..] > > [...] > > > He said (in effect) yes that -1 would not be detectable but its still > > there! > > Georg Cantor would probably be with your colleague, but then, Georg > Cantor was not a scientist. I'm mystified Earlier (I thought) you were on the Platonist = {Cantor, Hilbert...} side Now you sound like you are on the constructivist = {Kronecker, Brouwer } side From grant.b.edwards at gmail.com Mon Jun 27 10:04:40 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Jun 2016 14:04:40 +0000 (UTC) Subject: Operator Precedence: One Thing Python Got Right References: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> <577117b7$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-27, Steven D'Aprano wrote: > Do you write much Python code that you expect to also be valid C code? Depends on what you mean by "much", but yes, it's certainly something I do. I often develop and test algorithms in Python and then cut/paste much of the Python code into C programs. The more validated code I can use verbatim, the less likely I'll bork something up by having to translate it from Python to C. -- Grant Edwards grant.b.edwards Yow! ... I see TOILET at SEATS ... gmail.com From marko at pacujo.net Mon Jun 27 10:09:22 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 27 Jun 2016 17:09:22 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <8737nywwod.fsf@elektro.pacujo.net> Grant Edwards : > On 2016-06-26, BartC wrote: > >> (Note, for those who don't know (old) Fortran, that spaces and tabs >> are not significant. So those dots are needed, otherwise "a eq b" >> would be parsed as "aeqb".) > > I've always been baffled by that. > > Were there other languages that did something similar? In XML, whitespace between tags is significant unless the document type says otherwise. On the other hand, leading and trailing space in attribute values is insignificant unless the document type says otherwise. > Why would a language designer think it a good idea? > > Did the poor sod who wrote the compiler think it was a good idea? Fortran is probably not too hard to parse. XML, on the other hand, is impossible to parse without the document type at hand. The document type not only defines the whitespace semantics but also the availability and meaning of the "entities" (e.g., © for ?). Add namespaces to that, and the mess is complete. Marko From rustompmody at gmail.com Mon Jun 27 10:10:07 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 07:10:07 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> On Monday, June 27, 2016 at 7:30:05 PM UTC+5:30, Grant Edwards wrote: > On 2016-06-26, BartC > > (Note, for those who don't know (old) Fortran, that spaces and tabs are > > not significant. So those dots are needed, otherwise "a eq b" would be > > parsed as "aeqb".) > > I've always been baffled by that. > > Were there other languages that did something similar? > > Why would a language designer think it a good idea? > > Did the poor sod who wrote the compiler think it was a good idea? I think modern ideas like lexical analysis preceding parsing and so on came some decade after Fortran. My guess is that Fortran was first implemented -- 'somehow or other' Then these properties emerged -- more or less bugs that had got so entrenched that they had to be dignified as 'features' Analogy: Python's bool as 1?-class because bool came into python a good decade after python and breaking old code is a bigger issue than fixing control constructs to be bool-strict From marko at pacujo.net Mon Jun 27 10:12:14 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 27 Jun 2016 17:12:14 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> <87bn2mwxrn.fsf@elektro.pacujo.net> Message-ID: <87y45qvhz5.fsf@elektro.pacujo.net> Rustom Mody : > On Monday, June 27, 2016 at 7:16:03 PM UTC+5:30, Marko Rauhamaa wrote: >> Georg Cantor would probably be with your colleague, but then, Georg >> Cantor was not a scientist. > > I'm mystified > > Earlier (I thought) you were on the Platonist = {Cantor, Hilbert...} > side > Now you sound like you are on the constructivist = {Kronecker, Brouwer > } side I'm a formalist. Marko From bc at freeuk.com Mon Jun 27 10:14:13 2016 From: bc at freeuk.com (BartC) Date: Mon, 27 Jun 2016 15:14:13 +0100 Subject: Operator Precedence: One Thing Python Got Right In-Reply-To: References: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> <577117b7$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/06/2016 15:04, Grant Edwards wrote: > On 2016-06-27, Steven D'Aprano wrote: > >> Do you write much Python code that you expect to also be valid C code? > > Depends on what you mean by "much", but yes, it's certainly something > I do. I often develop and test algorithms in Python and then > cut/paste much of the Python code into C programs. The more validated > code I can use verbatim, the less likely I'll bork something up by > having to translate it from Python to C. > I bet your code isn't very 'Pythonic' then! I have frequently had to convert foreign algorithms (into my own languages), and when there is a choice, such as on the Computer Language Shootout site, then I might typically choose Pascal or Lua as being the simplest and clearest to understand. Languages such as Python tend to be too fond of using their unique features (which I also think can be a bit of a cheat when trying to compare benchmarks, but that's another matter). Unique features, which can include just using a built-in library call to do the work, don't translate so easily! -- Bartc From rustompmody at gmail.com Mon Jun 27 10:23:01 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 07:23:01 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, June 27, 2016 at 6:58:26 PM UTC+5:30, Steven D'Aprano wrote: > On Mon, 27 Jun 2016 10:48 pm, Rustom Mody wrote: > > > PS Google Groups is wise enough to jump through hoops trying to encode my > > message above as latin-1, then as Windows 1252 and only when that does not > > work as UTF-8 > > > There is nothing admirable about GG (or any other newsreader or email > client) defaulting to legacy encodings like Latin-1 and especially not > Windows 1252. > > Certainly the user should be permitted to explicitly set the encoding, but > otherwise the program should default to UTF-8. Its called sarcasm... Also how is GG deliberately downgrading clear unicode content to be kind to obsolete clients at recipient end different from python 2 ? 3 making breaking changes but not going beyond ASCII lexemes? Just think: Some poor mono-lingual ASCII-user may suffer an aneurism... Completely atrocious! From rustompmody at gmail.com Mon Jun 27 10:27:40 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 07:27:40 -0700 (PDT) Subject: Can math.atan2 return INF? In-Reply-To: <87y45qvhz5.fsf@elektro.pacujo.net> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> <87bn2mwxrn.fsf@elektro.pacujo.net> <87y45qvhz5.fsf@elektro.pacujo.net> Message-ID: <1875357b-84d2-475e-a653-163b37c3e7dd@googlegroups.com> On Monday, June 27, 2016 at 7:42:26 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > > On Monday, June 27, 2016 at 7:16:03 PM UTC+5:30, Marko Rauhamaa wrote: > >> Georg Cantor would probably be with your colleague, but then, Georg > >> Cantor was not a scientist. > > > > I'm mystified > > > > Earlier (I thought) you were on the Platonist = {Cantor, Hilbert...} > > side > > Now you sound like you are on the constructivist = {Kronecker, Brouwer > > } side > > I'm a formalist. Well then formalism is semantics-free: What matters it if an argument is theological or scientific as long as it is (internally) consistent? From grant.b.edwards at gmail.com Mon Jun 27 10:32:23 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Jun 2016 14:32:23 +0000 (UTC) Subject: Operator Precedence: One Thing Python Got Right References: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> <577117b7$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-27, BartC wrote: > On 27/06/2016 15:04, Grant Edwards wrote: >> On 2016-06-27, Steven D'Aprano wrote: >> >>> Do you write much Python code that you expect to also be valid C code? >> >> Depends on what you mean by "much", but yes, it's certainly >> something I do. I often develop and test algorithms in Python and >> then cut/paste much of the Python code into C programs. The more >> validated code I can use verbatim, the less likely I'll bork >> something up by having to translate it from Python to C. > > I bet your code isn't very 'Pythonic' then! No, not when the end goal is to move it into C. Numerical stuff works pretty well. Handling byte streams (e.g. creating/decoding file and protocol headers) isn't too bad. For text processing, it doesn't work very well. -- Grant Edwards grant.b.edwards Yow! There's enough money at here to buy 5000 cans of gmail.com Noodle-Roni! From alain at universite-de-strasbourg.fr.invalid Mon Jun 27 10:48:52 2016 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Mon, 27 Jun 2016 16:48:52 +0200 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <87r3bielgr.fsf@universite-de-strasbourg.fr.invalid> Grant Edwards writes: > On 2016-06-26, BartC wrote: > >> (Note, for those who don't know (old) Fortran, that spaces and tabs are >> not significant. So those dots are needed, otherwise "a eq b" would be >> parsed as "aeqb".) > > I've always been baffled by that. > Were there other languages that did something similar? Probably a lot at that time. > Why would a language designer think it a good idea? Because when you punch characters one by one on a card, you quickly get bored with less-than-useful spaces. > Did the poor sod who wrote the compiler think it was a good idea? I don't know, but he has a good excuse: he was one of the first to ever write a compiler (see https://en.wikipedia.org/wiki/Compiler, the section on History). You just called John Backus a "poor sod". Think again. -- Alain. From michael.selik at gmail.com Mon Jun 27 11:06:20 2016 From: michael.selik at gmail.com (Michael Selik) Date: Mon, 27 Jun 2016 15:06:20 +0000 Subject: Language improvement: Get more from the `for .. else` clause In-Reply-To: References: Message-ID: On Mon, Jun 27, 2016 at 12:53 AM Victor Savu wrote: > capture the [StopIteration] value in the `else` statement of the `for` loop > I'm having trouble thinking of a case when this new feature is necessary. Can you show a more realistic example? From torriem at gmail.com Mon Jun 27 11:11:29 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Jun 2016 09:11:29 -0600 Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> <31b94dd8-d066-a014-c38d-d5aed7452e58@gmail.com> Message-ID: <69e21509-c4ef-7e07-d63f-9d06594e9c4d@gmail.com> On 06/27/2016 12:44 AM, Lawrence D?Oliveiro wrote: > On Monday, June 27, 2016 at 6:16:01 PM UTC+12, John Ladasky wrote: > >> Between the Py3 requirement and the need to work with all major OS's, I >> decided to learn PyQt and not GTK+. > > GTK+ is available for Python 3. > > No doubt it will work on Windows as well, once Microsoft gets its Linux compatibility layer debugged... But that's not a solution for John's target audience. Nor for most users, honestly. The Linux layer is targeted towards Azure developers mainly, and not intended to be an application support layer. GTK+ is working natively on Windows, and the Python bindings work on Windows. However GTK+ does not have nearly as good integration with the Windows desktop in terms of look and feel as other solutions like Qt and wxWidgets. Running the Linux version of GTK+ inside of Windows' Linux layer would not solve that problem! From gheskett at shentel.net Mon Jun 27 11:21:35 2016 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 27 Jun 2016 11:21:35 -0400 Subject: Assignment Versus Equality In-Reply-To: <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201606271121.35703.gheskett@shentel.net> On Monday 27 June 2016 09:28:00 Steven D'Aprano wrote: > On Mon, 27 Jun 2016 10:48 pm, Rustom Mody wrote: > > PS Google Groups is wise enough to jump through hoops trying to > > encode my message above as latin-1, then as Windows 1252 and only > > when that does not work as UTF-8 > > There is nothing admirable about GG (or any other newsreader or email > client) defaulting to legacy encodings like Latin-1 and especially not > Windows 1252. > > Certainly the user should be permitted to explicitly set the encoding, > but otherwise the program should default to UTF-8. > Both of you mentioned 2 bad words, now go and warsh yer fungers with some of grandma's lye soap. > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and > sure enough, things got worse. 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 steve.dower at python.org Mon Jun 27 11:25:40 2016 From: steve.dower at python.org (Steve Dower) Date: Mon, 27 Jun 2016 08:25:40 -0700 Subject: [Python-Dev] [RELEASED] Python 3.4.5 and Python 3.5.2 are now available In-Reply-To: <5770902C.4010809@hastings.org> References: <5770902C.4010809@hastings.org> Message-ID: <794952a4-f50e-00f1-cad8-b424f8d1e945@python.org> On 26Jun2016 1932, Larry Hastings wrote: > https://www.python.org/downloads/release/python-352/ > ... > /p.s. There appears to be a small oops with the Windows installers for > 3.5.2--uploaded to the wrong directory or something. They'll be > available soon, honest! That oops is now fixed, but I wanted to mention one other thing. Microsoft Security Essentials, now a very common antivirus/antimalware scanner on Windows, is incorrectly detecting Lib/distutils/command/wininst-14.0.exe as malware (originally reported at http://bugs.python.org/issue27383). My assumption is that someone distributed malware using a bdist_exe package, and our stub executable got picked up in the signature. I rebuilt the executable on my own machine from early source code and it still triggered the scan, so there does not appear to have been any change to the behaviour of the executable. I've already submitted a false positive report, so I expect an update to correct it at some point in the future, but please do not be alarmed to see this warning when installing Python 3.5.2, or when scanning any earlier version of 3.5. Feel free to contact me off-list or steve.dower at microsoft.com if you have concerns. Cheers, Steve From python at mrabarnett.plus.com Mon Jun 27 11:27:21 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Jun 2016 16:27:21 +0100 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: On 2016-06-27 14:59, Grant Edwards wrote: > On 2016-06-26, BartC wrote: > >> (Note, for those who don't know (old) Fortran, that spaces and tabs are >> not significant. So those dots are needed, otherwise "a eq b" would be >> parsed as "aeqb".) > > I've always been baffled by that. > > Were there other languages that did something similar? > Algol 60 and Algog 68. > Why would a language designer think it a good idea? > It let you have identifiers like "grand total"; there was no need for camel case or underscores to separate the parts of the name. > Did the poor sod who wrote the compiler think it was a good idea? > From grant.b.edwards at gmail.com Mon Jun 27 11:42:58 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Jun 2016 15:42:58 +0000 (UTC) Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: On 2016-06-27, MRAB wrote: > On 2016-06-27 14:59, Grant Edwards wrote: >> On 2016-06-26, BartC wrote: >> >>> (Note, for those who don't know (old) Fortran, that spaces and tabs are >>> not significant. So those dots are needed, otherwise "a eq b" would be >>> parsed as "aeqb".) >> >> I've always been baffled by that. >> >> Were there other languages that did something similar? > > Algol 60 and Algog 68. Ah, I never knew that Algol ignored spaces also. I had a vague recollection that they keyword namespace and variable namespaces were speparate, which allowed some rather odd looking (by modern standards) code. > It let you have identifiers like "grand total"; there was no need for > camel case or underscores to separate the parts of the name. It's interesting how completely that concept has dissappeared from modern languages. -- Grant Edwards grant.b.edwards Yow! Send your questions to at ``ASK ZIPPY'', Box 40474, gmail.com San Francisco, CA 94140, USA From davidgshi at yahoo.co.uk Mon Jun 27 12:32:10 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 27 Jun 2016 16:32:10 +0000 (UTC) Subject: Live installation of Pandas for Windows 64 References: <52893988.3770103.1467045130794.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <52893988.3770103.1467045130794.JavaMail.yahoo@mail.yahoo.com> Is there a live installation of Pandas for Windows 64? Regards. David From steven.truppe at chello.at Mon Jun 27 12:49:58 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Mon, 27 Jun 2016 18:49:58 +0200 Subject: Where do i find the 32 bit libraries on my 64 bit ubuntu system Message-ID: <57715936.1090604@chello.at> Hi all, i want to write an application that works for both 32 bit and 64bit on my 64bit ubuntu system, my problem i only find 64bit libraries under /usr/lib, there is also a path callled /x86_64-linux-gnu/ <- are these the libraries i should use for 32 bit and 64 bit programming ?? From marko at pacujo.net Mon Jun 27 13:03:19 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 27 Jun 2016 20:03:19 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> <87bn2mwxrn.fsf@elektro.pacujo.net> <87y45qvhz5.fsf@elektro.pacujo.net> <1875357b-84d2-475e-a653-163b37c3e7dd@googlegroups.com> Message-ID: <878txqpns8.fsf@elektro.pacujo.net> Rustom Mody : > On Monday, June 27, 2016 at 7:42:26 PM UTC+5:30, Marko Rauhamaa wrote: >> I'm a formalist. > > Well then formalism is semantics-free: What matters it if an argument > is theological or scientific as long as it is (internally) consistent? That's what I'm saying: black holes can't exist according to the very theory that predicts their existence. They might exist in reality, though... Marko From s.garg.computer at gmail.com Mon Jun 27 13:22:13 2016 From: s.garg.computer at gmail.com (Sachin Garg) Date: Mon, 27 Jun 2016 13:22:13 -0400 Subject: argparse and subparsers In-Reply-To: <5770ffe3$0$2901$c3e8da3$76491128@news.astraweb.com> References: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> <5b1c7833-5cd3-47b3-b82b-643e88606fef@googlegroups.com> <5770ffe3$0$2901$c3e8da3$76491128@news.astraweb.com> Message-ID: On Monday 27 June 2016 06:28 AM, Steven D'Aprano wrote: > On Monday 27 June 2016 15:34, Lawrence D?Oliveiro wrote: > >> On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: >> >>> # Set verbose flag >>> verbose = False >>> if arguments['--verbose']: >>> verbose = True >>> elif arguments['-q']: >>> verbose = False >> >> Don?t you just love code (and commenting) like this... > > > Not particularly, but what are you going to do? You need to support a minimum > of three cases: > > - a default setting; > - the case where the user passes --verbose; > - the case where the user passes -q; > > (I'm not sure why --verbose take a long argument but no short argument -v; and > likewise why there's a -q short argument but no --quiet long version. Oh well.) It is there. The way docopt works (https://github.com/docopt/docopt) is that it uses a "usage pattern" formatted using doctring conventions. In my case (snippet below), this pattern was: """Process Files: De-identify, encrypt and transmit data. Usage: processFiles.py [-hvq] [--config=FILE] [--encryptkey=key] [--signkey=key] [--no-normalize] [--no-encrypt] [--no-sign] Options: -h --help show this help message and exit -v --verbose verbose mode -q quiet mode (default) --config=FILE read configuration FILE (default: config.json) --encryptkey=KEY set GPG encryption key to KEY(default: from config file) --signkey=KEY set GPG signing key to KEY (default: from config file) --no-normalize do not normalize CCD/CSV (default: normalize) --no-encrypt do not encrypt output (default: encrypt) --no-sign do not sign output (default: sign) --no-transfer do not transfer output (default: transfer) """ So, the short "-v" option is taken care of. > A simple test-and-set for each argument is the simplest, most straight-forward > way of handling this. It's not *pretty* or *elegant* code, but it is the > easiest to read, write and comprehend, and in my opinion much better than > alternatives involving ever more arcane method calls to ever more complicated > classes. The code above does seem amateurish. However, I think that it is easier to "waste" a few variables and allow for the ability to do printf() debugging, then write code using esoteric data structures. > I don't have experience with docutils and cannot judge whether or not Sachin's > snippets are good or bad examples of use, but find myself going back to the > good old fashioned GNU style command line parser whenever I need a few command > line options. If you find yourself writing subparsers and "mandatory options" > and needing entire help screens to describe single arguments (as in "foo --help > arg") then really I think you should give up the pretence that you're dealing > with command line options, and you should write a mini-language for your > application. > > (hg, git, memcoder, soc etc. I'm talking about you.) From llanitedave at birdandflower.com Mon Jun 27 13:23:38 2016 From: llanitedave at birdandflower.com (llanitedave) Date: Mon, 27 Jun 2016 10:23:38 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> <31b94dd8-d066-a014-c38d-d5aed7452e58@gmail.com> Message-ID: <4e1e093b-5c8c-426d-a877-fece9fc83088@googlegroups.com> On Sunday, June 26, 2016 at 11:16:01 PM UTC-7, John Ladasky wrote: > On Sunday, June 26, 2016 at 7:41:17 PM UTC-7, Michael Torrie wrote: > > If GTK+ had first-class support on Windows and Mac, including native > > themes and seamless UI integration (file and print dialogs), I'd say > > GTK+ would be the only game in town for Python programmers. > > Unfortunately, unless you're only concerned with Linux, GTK+ is probably > > not going to be your choice. > > Although I work almost exclusively in Linux, I've been teaching Python for several years as a sideline, and my students usually do not use Linux. I insist on teaching my students Python 3. Unless they're professionals who must work with legacy code (and, so far, none of them have been), I think I would be doing them a disservice to teach them Python 2. > > I started with WxPython, but WxPython/Phoenix has been very slow to migrate to Python 3. > > Between the Py3 requirement and the need to work with all major OS's, I decided to learn PyQt and not GTK+. > > In my current day job, I'm developing an application on a Linux box, but I'll be handing it off to Windows users. My choice of PyQt turned out to be the right one in that situation as well. I produced a couple of applications using wxPython 2.8 and Python 2.7, and I was happy with how they turned out, but since I moved to Python 3 I got tired of waiting for a Phoenix release that I felt comfortable with, so I've been learning PyQT lately. I do find that PyQt is more straightforward in many respects than wxPython, but the difference for me has always been how well organized and understandable the documentation is. The PyQt examples seem very comprehensive, but the code is poorly commented and there are some quirks that are confusing me. The original wxPython book was quite well put together and extremely helpful, and I miss having something like that for Qt. I'm going through the eBook on PyQt4, but I'm not yet sure how well it will translate to PyQt5, which I'm trying to develop with. I do think I'll stick with it, though. Once I learn it I think it will serve me well. From rustompmody at gmail.com Mon Jun 27 13:43:32 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 10:43:32 -0700 (PDT) Subject: Where do i find the 32 bit libraries on my 64 bit ubuntu system In-Reply-To: References: <57715936.1090604@chello.at> Message-ID: On Monday, June 27, 2016 at 11:07:29 PM UTC+5:30, Steven Truppe wrote: > Hi all, > > i want to write an application that works for both 32 bit and 64bit on > my 64bit ubuntu system, my problem i only find 64bit libraries under > /usr/lib, there is also a path callled /x86_64-linux-gnu/ <- are these > the libraries i should use for 32 bit and 64 bit programming ?? You probably need to study about multiarch: https://help.ubuntu.com/community/MultiArch https://wiki.debian.org/Multiarch/ [Dont know much more myself] From grant.b.edwards at gmail.com Mon Jun 27 13:54:47 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Jun 2016 17:54:47 +0000 (UTC) Subject: Where do i find the 32 bit libraries on my 64 bit ubuntu system References: <57715936.1090604@chello.at> Message-ID: On 2016-06-27, Steven Truppe wrote: > i want to write an application that works for both 32 bit and 64bit on > my 64bit ubuntu system, my problem i only find 64bit libraries under > /usr/lib, there is also a path callled /x86_64-linux-gnu/ <- are these > the libraries i should use for 32 bit and 64 bit programming ?? In my experience all you have to do is pass "-m32" to gcc. It should know where the 32-bit libraries are. -- Grant Edwards grant.b.edwards Yow! UH-OH!! I put on at "GREAT HEAD-ON TRAIN gmail.com COLLISIONS of the 50's" by mistake!!! From codewizard at gmail.com Mon Jun 27 16:14:00 2016 From: codewizard at gmail.com (codewizard at gmail.com) Date: Mon, 27 Jun 2016 13:14:00 -0700 (PDT) Subject: Getting back into PyQt and not loving it. In-Reply-To: References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> Message-ID: <473ee4eb-0d1c-4864-ad44-b9c1928e2267@googlegroups.com> On Sunday, June 26, 2016 at 5:45:18 PM UTC-4, Michael Torrie wrote: > > Qt's a fantastic toolkit, and the most mature of any of them, and the > most portable, but man the bindings are not Pythonic at all. Enaml feels pretty Pythonic to me: https://github.com/nucleic/enaml From pavel at schon.cz Mon Jun 27 16:56:36 2016 From: pavel at schon.cz (Pavel S) Date: Mon, 27 Jun 2016 13:56:36 -0700 (PDT) Subject: __all__ attribute: bug and proposal Message-ID: Hi, I today uncovered subtle bug and would like to share it with you. By a mistake, I forgot to put comma into '__all__' tuple of some module. Notice missing comma after 'B'. # module foo.py __all__ = ( 'A', 'B' 'C', ) class A: pass class B: pass class C: pass If you try to import * from the module, it will raise an error, because 'B' and 'C' will be concatenated into 'BC'. >>> from foo import * AttributeError: 'module' object has no attribute 'BC' The bug won't be found until someone imports *. In order to identify problems as soon as possible, here's the proposal. Porposal: allow putting objects into __all__ directly, so possible problems will be found earlier: # module foo.py class A: pass class B: pass class C: pass __all__ = (A, B, C) Note: this currently don't work. >>> from foo import * TypeError: attribute name must be string, not 'type' From salvatore.didio at gmail.com Mon Jun 27 17:19:03 2016 From: salvatore.didio at gmail.com (Salvatore DI DIO) Date: Mon, 27 Jun 2016 14:19:03 -0700 (PDT) Subject: Transcrypt - Games for Kids Message-ID: <693638cc-dfed-464d-aaa5-9bba3d035bb0@googlegroups.com> Hello, I am using Transcrypt (Python to Javascript translator) to create games for kids, and introduce them to programming. You can give an eye here : https://github.com/artyprog/GFK Regards From rosuav at gmail.com Mon Jun 27 17:32:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 07:32:42 +1000 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: On Tue, Jun 28, 2016 at 6:56 AM, Pavel S wrote: > Porposal: allow putting objects into __all__ directly, so possible problems will be found earlier: > > # module foo.py > class A: pass > class B: pass > class C: pass > > __all__ = (A, B, C) > > Note: this currently don't work. > >>>> from foo import * > TypeError: attribute name must be string, not 'type' How would it know what names to import them under? It's all very well with classes and functions (you could mandate that it uses the canonical name), but what about integers or strings? ChrisA From lawrencedo99 at gmail.com Mon Jun 27 17:56:45 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 27 Jun 2016 14:56:45 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <7aba43fc-5aa4-4f60-b29c-2f61e4a7d31e@googlegroups.com> On Tuesday, June 28, 2016 at 3:27:40 AM UTC+12, MRAB wrote: > > On 2016-06-27 14:59, Grant Edwards wrote: >> >> Were there other languages that did something similar? >> > Algol 60 and Algog 68. Algol 68 was actually slightly different. There were two separate alphabets: one used for names of constants, variables, routines and labels, where spaces were ignored, and a different one used for type names (called ?modes?) and reserved words, where spaces were significant. The convention was to use lowercase for the former and uppercase for the latter. Example here . From pavel at schon.cz Mon Jun 27 18:29:26 2016 From: pavel at schon.cz (Pavel S) Date: Mon, 27 Jun 2016 15:29:26 -0700 (PDT) Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: > but what about integers or strings? Can you provide example? --- No matter if __all__ uses names or objects, I think it should be validated not only when importing '*', but always. Frankly, do you always unit-test if __all__ works? From rosuav at gmail.com Mon Jun 27 18:41:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 08:41:16 +1000 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: On Tue, Jun 28, 2016 at 8:29 AM, Pavel S wrote: >> but what about integers or strings? > > Can you provide example? Sure. I'll spare you the wall of text that is os.__all__, but here's the types: >>> import os >>> {type(getattr(os, x)).__name__ for x in os.__all__} {'bool', 'module', 'function', 'str', '_Environ', 'NoneType', 'type', 'int', 'dict', 'builtin_function_or_method'} >>> collections.Counter(hasattr(getattr(os, x), "__name__") for x in os.__all__) Counter({True: 184, False: 122}) So, roughly 60% of them even have canonical names. And you don't always want the canonical name, anyway: >>> os.path.__name__ 'posixpath' (Your results may vary. Specifically. os.path.__name__ will be 'ntpath' if you're on Windows.) > No matter if __all__ uses names or objects, I think it should be validated not only when importing '*', but always. > > Frankly, do you always unit-test if __all__ works? Frankly, I don't unit test enough. But if you have __all__, it shouldn't be too hard, nor too unobvious, to test it. >>> def test_all(): ... exec("from os import *") ... >>> test_all() >>> os.__all__.append("asdf") >>> test_all() Traceback (most recent call last): File "", line 1, in File "", line 2, in test_all File "", line 1, in AttributeError: module 'os' has no attribute 'asdf' ChrisA From lawrencedo99 at gmail.com Mon Jun 27 18:45:19 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 27 Jun 2016 15:45:19 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <65309b66-485d-4be7-94ca-f9a8f58b513a@googlegroups.com> On Tuesday, June 28, 2016 at 3:27:40 AM UTC+12, MRAB wrote: > On 2016-06-27 14:59, Grant Edwards wrote: >> Why would a language designer think it a good idea? >> > It let you have identifiers like "grand total"; there was no need for > camel case or underscores to separate the parts of the name. Another nifty thing (well, I thought so at the time) was that FORTRAN had no reserved words. Though I wondered, in statements like FORMAT(...complex expression with lots of nested parentheses...) = ... how much work the parser would have to do before deciding that it was an array assignment, not a FORMAT statement? Then some FORTRAN dialects allowed constant definitions using syntax like PARAMETER N = 3 which broke the no-reserved-words convention. Luckily, this was standardized as the much less headache-inducing (for the compiler writer) PARAMETER(N = 3) PL/I (which was almost named ?FORTRAN VI? at one stage) added significant whitespace, but managed to keep the no-reserved-words convention--almost. There was just one peculiar set of exceptions... From lawrencedo99 at gmail.com Mon Jun 27 18:57:19 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 27 Jun 2016 15:57:19 -0700 (PDT) Subject: Operator Precedence: One Thing Python Got Right In-Reply-To: References: <7f599d03-1fa6-4f16-93e6-17a5b038e6c5@googlegroups.com> <577117b7$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12bf9b2a-d0e7-4a39-8cd5-092a73c045b0@googlegroups.com> On Tuesday, June 28, 2016 at 2:32:48 AM UTC+12, Grant Edwards wrote: > > On 2016-06-27, BartC wrote: > >> I bet your code isn't very 'Pythonic' then! > > No, not when the end goal is to move it into C. I wonder: how much real-world C code would be broken if the operator precedences in C were changed to match that in Python? From ethan at stoneleaf.us Mon Jun 27 19:00:23 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 27 Jun 2016 16:00:23 -0700 Subject: Getting back into PyQt and not loving it. In-Reply-To: <2883132b-f862-5b51-fff9-b98486ff7dc5@mrabarnett.plus.com> References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <8470bc54-1cd5-49e0-852c-9729f2747319@googlegroups.com> <2883132b-f862-5b51-fff9-b98486ff7dc5@mrabarnett.plus.com> Message-ID: <5771B007.30502@stoneleaf.us> On 06/26/2016 07:12 PM, MRAB wrote: > Is it a problem with Tk itself or with the Python wrapper? Would it be > better if we made a more Pythonic version of Tkinter, e.g. making > Frame.title a property? I would say it's the wrapper. I appreciate all the work being done on tkinter lately, but it's still jarring trying to use the not-very-pythonic-at-all interface. -- ~Ethan~ From bc at freeuk.com Mon Jun 27 19:08:00 2016 From: bc at freeuk.com (BartC) Date: Tue, 28 Jun 2016 00:08:00 +0100 Subject: Assignment Versus Equality In-Reply-To: <65309b66-485d-4be7-94ca-f9a8f58b513a@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <65309b66-485d-4be7-94ca-f9a8f58b513a@googlegroups.com> Message-ID: On 27/06/2016 23:45, Lawrence D?Oliveiro wrote: > On Tuesday, June 28, 2016 at 3:27:40 AM UTC+12, MRAB wrote: >> On 2016-06-27 14:59, Grant Edwards wrote: >>> Why would a language designer think it a good idea? >>> >> It let you have identifiers like "grand total"; there was no need for >> camel case or underscores to separate the parts of the name. > > Another nifty thing (well, I thought so at the time) was that FORTRAN had no reserved words. > > Though I wondered, in statements like > > FORMAT(...complex expression with lots of nested parentheses...) = ... > > how much work the parser would have to do before deciding that it was an array assignment, not a FORMAT statement? You just design the compiler to do the same processing in each case, ie. parse a followed (), then mark the result AST fragment as either an Array term, or Format statement, depending on what follows, and whether the name is "format". I suppose the compiler could decide to backtrack and re-parse based on the knowledge that is one or the other, but that's a messy way of doing it. -- Bartc From m at funkyhat.org Mon Jun 27 19:39:21 2016 From: m at funkyhat.org (Matt Wheeler) Date: Mon, 27 Jun 2016 23:39:21 +0000 Subject: Running yum/apt-get from a virtualenv In-Reply-To: <86872401-7d4b-4979-9fba-351e41848aa4@googlegroups.com> References: <86872401-7d4b-4979-9fba-351e41848aa4@googlegroups.com> Message-ID: On Fri, 24 Jun 2016, 03:32 Tiglath Suriol, wrote: > Let us say that I install PostgreSQL from an activated virtualenv using > yum or apt-get, will PostgrSQL be local or global? > Global I understand that virtualenv isolates the Python environment only, so I > surmise that it will make no difference installing with yum/apt-get inside > or outside the virtualenv. > That is correct. The way the virtualenv works is by adding a new path (the virtualenv bin dir) to the beginning of $PATH. That means that programs which are in your virtualenv (python, pip, entry points to any packages you have installed) will override system versions, because they come first. Of course that won't apply to yum,apt,etc. But that would not be the case with say Psycopg2 which would be isolated in > the virtualenv, because it is a Python module. Is that right? > Yes > From random832 at fastmail.com Mon Jun 27 20:25:45 2016 From: random832 at fastmail.com (Random832) Date: Mon, 27 Jun 2016 20:25:45 -0400 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: <1467073545.3674017.650275257.67D8CC98@webmail.messagingengine.com> On Mon, Jun 27, 2016, at 16:56, Pavel S wrote: > Porposal: allow putting objects into __all__ directly, so possible > problems will be found earlier: Question: What happens if the object in __all__ isn't the same object that's in the module? From torriem at gmail.com Mon Jun 27 20:26:39 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Jun 2016 18:26:39 -0600 Subject: Getting back into PyQt and not loving it. In-Reply-To: <473ee4eb-0d1c-4864-ad44-b9c1928e2267@googlegroups.com> References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <473ee4eb-0d1c-4864-ad44-b9c1928e2267@googlegroups.com> Message-ID: On 06/27/2016 02:14 PM, codewizard at gmail.com wrote: > On Sunday, June 26, 2016 at 5:45:18 PM UTC-4, Michael Torrie wrote: >> >> Qt's a fantastic toolkit, and the most mature of any of them, and the >> most portable, but man the bindings are not Pythonic at all. > > Enaml feels pretty Pythonic to me: > > https://github.com/nucleic/enaml Cool. I'll check it out. From rosuav at gmail.com Mon Jun 27 20:32:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 10:32:36 +1000 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: On Tue, Jun 28, 2016 at 6:56 AM, Pavel S wrote: > By a mistake, I forgot to put comma into '__all__' tuple of some module. Notice missing comma after 'B'. > > # module foo.py > __all__ = ( > 'A', > 'B' > 'C', > ) > > class A: pass > class B: pass > class C: pass > > If you try to import * from the module, it will raise an error, because 'B' and 'C' will be concatenated into 'BC'. > >>>> from foo import * > AttributeError: 'module' object has no attribute 'BC' > > The bug won't be found until someone imports *. If you're primarily worried about classes and functions, here's a neat trick you can use: __all__ = [] def all(thing): __all__.append(thing.__name__) return thing @all class A: pass @all class B: pass @all class C: pass @all def d(): pass del all # clean up the namespace (optional) The decorator doesn't change anything (it returns its argument as-is), but it captures the canonical name into __all__. Obviously you can't use this if you want a non-canonical name, and you can't use it for anything other than classes and functions (you can't decorate "pi = 3.14159"), but it might help with your actual problem. ChrisA From sohcahtoa82 at gmail.com Mon Jun 27 20:33:43 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 27 Jun 2016 17:33:43 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <8737nywwod.fsf@elektro.pacujo.net> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <8737nywwod.fsf@elektro.pacujo.net> Message-ID: <7835908b-152d-4694-a1cf-3e4d57785f65@googlegroups.com> On Monday, June 27, 2016 at 7:09:35 AM UTC-7, Marko Rauhamaa wrote: > Grant Edwards : > > > On 2016-06-26, BartC wrote: > > > >> (Note, for those who don't know (old) Fortran, that spaces and tabs > >> are not significant. So those dots are needed, otherwise "a eq b" > >> would be parsed as "aeqb".) > > > > I've always been baffled by that. > > > > Were there other languages that did something similar? > > In XML, whitespace between tags is significant unless the document type > says otherwise. On the other hand, leading and trailing space in > attribute values is insignificant unless the document type says > otherwise. > > > Why would a language designer think it a good idea? > > > > Did the poor sod who wrote the compiler think it was a good idea? > > Fortran is probably not too hard to parse. XML, on the other hand, is > impossible to parse without the document type at hand. The document type > not only defines the whitespace semantics but also the availability and > meaning of the "entities" (e.g., © for ?). Add namespaces to that, > and the mess is complete. > > > Marko XML isn't a programming language. I don't think it's relevant to the conversation. From steve at pearwood.info Mon Jun 27 21:05:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 11:05:23 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 12:23 am, Rustom Mody wrote: > On Monday, June 27, 2016 at 6:58:26 PM UTC+5:30, Steven D'Aprano wrote: >> On Mon, 27 Jun 2016 10:48 pm, Rustom Mody wrote: >> >> > PS Google Groups is wise enough to jump through hoops trying to encode >> > my message above as latin-1, then as Windows 1252 and only when that >> > does not work as UTF-8 >> >> >> There is nothing admirable about GG (or any other newsreader or email >> client) defaulting to legacy encodings like Latin-1 and especially not >> Windows 1252. >> >> Certainly the user should be permitted to explicitly set the encoding, >> but otherwise the program should default to UTF-8. > > Its called sarcasm... Ah, sorry about that, I didn't realise. Some human languages have native support for flagging sarcasm, e.g. there's a sarcasm marker called temherte slaq? used by some Ethiopic languages to indicate sarcasm and other unreal statements. It apparently looks somewhat like an upside down exclamation mark (?). Another common solution is to use "scare quotes" around the sarcastic key words. Or you could tag the sentence with tags. Most people I see using this last one just show the close tag, often abbreviating it to just /s on its own. > Also how is GG deliberately downgrading clear unicode content to be kind > to obsolete clients at recipient end different from python 2 ? 3 making > breaking changes but not going beyond ASCII lexemes? Oh yes, I completely agree, obviously GvR is literally worse than Hitler because he hasn't added a bunch of Unicode characters with poor support for input and worse support for output as essential syntactic elements to Python. /s -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lawrencedo99 at gmail.com Mon Jun 27 21:14:29 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 27 Jun 2016 18:14:29 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: <18475c25-543d-42b8-a2bf-905cfe681e18@googlegroups.com> On Tuesday, June 28, 2016 at 2:23:16 AM UTC+12, Rustom Mody wrote: > python 2 ? 3 making breaking changes but not going beyond ASCII lexemes? You do know Python 3 allows Unicode letters in identifiers, right? From lawrencedo99 at gmail.com Mon Jun 27 21:18:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 27 Jun 2016 18:18:10 -0700 (PDT) Subject: Where do i find the 32 bit libraries on my 64 bit ubuntu system In-Reply-To: References: <57715936.1090604@chello.at> Message-ID: <2083ef32-dad2-4a64-8da4-40ca5cf09d48@googlegroups.com> On Tuesday, June 28, 2016 at 5:37:29 AM UTC+12, Steven Truppe wrote: > i want to write an application that works for both 32 bit and 64bit on > my 64bit ubuntu system, my problem i only find 64bit libraries under > /usr/lib, there is also a path callled /x86_64-linux-gnu/ <- are these > the libraries i should use for 32 bit and 64 bit programming ?? You can install 32-bit compatibility libraries on x86-64. Find the libraries with apt-cache search 32 | grep '^lib.*32.*bit' From steve at pearwood.info Mon Jun 27 21:28:21 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 11:28:21 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <5771d2b6$0$1614$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 01:27 am, MRAB wrote: > On 2016-06-27 14:59, Grant Edwards wrote: >> On 2016-06-26, BartC wrote: >> >>> (Note, for those who don't know (old) Fortran, that spaces and tabs are >>> not significant. So those dots are needed, otherwise "a eq b" would be >>> parsed as "aeqb".) >> >> I've always been baffled by that. >> >> Were there other languages that did something similar? >> > Algol 60 and Algog 68. Are you sure about that? I'd like to see a citation, as everything I've seen suggests that Algol treats spaces like modern languages. http://www.masswerk.at/algol60/algol60-syntaxversions.htm Space is listed as a separator, and *not* in indentifiers. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Mon Jun 27 21:34:59 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 11:34:59 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: <5771d444$0$1586$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jun 2016 11:59 pm, Grant Edwards wrote: > On 2016-06-26, BartC wrote: > >> (Note, for those who don't know (old) Fortran, that spaces and tabs are >> not significant. So those dots are needed, otherwise "a eq b" would be >> parsed as "aeqb".) > > I've always been baffled by that. > > Were there other languages that did something similar? > > Why would a language designer think it a good idea? > > Did the poor sod who wrote the compiler think it was a good idea? I don't know if it was a deliberate design decision or not, but I don't believe that it survived very many releases of the Fortran standard. Remember that Fortran was THE first high-level language. Its creator, John Backus, was breaking new ground and doing things that had never been done before[1], so the things that we take for granted about high-level programming languages were still being invented. If early Fortran got a few things wrong, we shouldn't be surprised. Also the earliest Fortran code was not expected to be typed into a computer. It was expected to be entered via punched cards, which eliminates the need for spaces. [1] Almost. He has previously created a high-level assembly language, Speedcoding, for IBM, which can be considered the predecessor of Fortran. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Mon Jun 27 21:55:46 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Jun 2016 02:55:46 +0100 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: <788b5c19-3f92-9319-a791-03bac9ee24b4@mrabarnett.plus.com> On 2016-06-28 01:32, Chris Angelico wrote: [snip] > If you're primarily worried about classes and functions, here's a neat > trick you can use: > > __all__ = [] > def all(thing): > __all__.append(thing.__name__) > return thing > Err... won't that hide the 'all' builtin? From steve at pearwood.info Mon Jun 27 21:56:29 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 11:56:29 +1000 Subject: __all__ attribute: bug and proposal References: Message-ID: <5771d94e$0$1605$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 06:56 am, Pavel S wrote: > Hi, > I today uncovered subtle bug and would like to share it with you. > > By a mistake, I forgot to put comma into '__all__' tuple of some module. > Notice missing comma after 'B'. > > # module foo.py > __all__ = ( > 'A', > 'B' > 'C', > ) Right. That's a language feature: implicit concatenation of string literals. If you have two string literals separated by nothing but whitespace, the compiler will concatenate them: s = 'He said, "Hello, did you see where' " they're" ' going?"' is equivalent to: s = 'He said, "Hello, did you see where they\'re going?"' > If you try to import * from the module, it will raise an error, because > 'B' and 'C' will be concatenated into 'BC'. Correct. Exactly the same as if you had written: __all__ = ['A', 'BC', 'D'] > The bug won't be found until someone imports *. I always write a unit-test to check that everything in __all__ exists. > In order to identify problems as soon as possible, here's the proposal. > > Porposal: allow putting objects into __all__ directly, so possible > problems will be found earlier: > > # module foo.py > class A: pass > class B: pass > class C: pass > > __all__ = (A, B, C) There are two problems with this idea. Suppose you have this: prefs_file = "filename" __all__ = (prefs_file, A, B, C) # suppose A, B and C are all defined Obviously, the intention is that the caller can say: from themodule import * print(prefs_file) and "filename" will be printed. But there's two problems: (1) the __all__ tuple doesn't know anything about the name "prefs_file". It only knows about "filename", the object (value) of prefs_file. So there is no way for the import system to know what name to use for that value: ????? = "filename" (2) For backwards-compatibility, we still need to support the old way of writing __all__, using names given as strings: __all__ = ('prefs_file', 'A', 'B', 'C') But now you have an ambiguity. If __all__ looks like this: __all__ = (prefs_file, A, B, C) does the first entry mean "import the value 'filename'" (new behaviour), or does it mean "import the value with the name 'filename'" (old behaviour)? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Mon Jun 27 22:20:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 12:20:48 +1000 Subject: __all__ attribute: bug and proposal In-Reply-To: <788b5c19-3f92-9319-a791-03bac9ee24b4@mrabarnett.plus.com> References: <788b5c19-3f92-9319-a791-03bac9ee24b4@mrabarnett.plus.com> Message-ID: On Tue, Jun 28, 2016 at 11:55 AM, MRAB wrote: > On 2016-06-28 01:32, Chris Angelico wrote: > [snip] > >> If you're primarily worried about classes and functions, here's a neat >> trick you can use: >> >> __all__ = [] >> def all(thing): >> __all__.append(thing.__name__) >> return thing >> > Err... won't that hide the 'all' builtin? > Yep. So? If you're not using it *at top level*, it's not a problem. I clean up the namespace at the end, so if you use it inside a function, it'll still be available. And most of my scripts don't use 'all' anyway... it's no worse than using 'id' for a database ID. ChrisA From jcasale at activenetwerx.com Mon Jun 27 22:22:19 2016 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 28 Jun 2016 02:22:19 +0000 Subject: argparse and subparsers In-Reply-To: References: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> Message-ID: > Not sure if this fits the bill, or makes sense here, but I came cross > "docopt" which touts itself as a "Command-line interface description > language". I used it in a project and it seems to be pretty easy to use > as well as elegant. It stores the arguments & values as a dictionary, > keyed by the argument. Yea I have had my eye on docopt for a while, it doesn't support multiple subparsers, as I am passing duplicate parameters from its perspective. Imagine: foo.py --host 172.18.0.4 --port 766 foo --warning 42 --critical 77 bar --warning 4.2 --critical 7.7 etc... The shortcoming to argparse has been debated to death and the bug tracker was just left hanging. To be honest, I am not clear on the opposition to it... Thanks, jlc From random832 at fastmail.com Mon Jun 27 22:27:21 2016 From: random832 at fastmail.com (Random832) Date: Mon, 27 Jun 2016 22:27:21 -0400 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: <1467080841.3696367.650352489.04478540@webmail.messagingengine.com> On Mon, Jun 27, 2016, at 20:32, Chris Angelico wrote: > If you're primarily worried about classes and functions, here's a neat > trick you can use: How about just __all__ = [list of stuff including classes and functions] __all__ = [x if isinstance(x, str) else x.__name__ for x in __all__] From steve at pearwood.info Mon Jun 27 22:28:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 12:28:16 +1000 Subject: Question on compiling on linux References: <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> <576E389B.7060709@chello.at> <1467035818.2222949.649673417.18E0D090@webmail.messagingengine.com> Message-ID: <5771e0c2$0$1588$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 10:01 am, Dennis Lee Bieber wrote: > The Outlook style works well in a business environment where the > recipient is likely the original sender of the quoted text, and doesn't > need the context -- the quoted copy is just a courtesy copy in this case. No it doesn't work well. It is shit in business environments too. It only works well in one tiny subset of cases: (1) Fred sends an email to George. (2) George responds with a short response that stands alone, or can be interpreted based only on the subject line. ~ Subject: Drinks on Friday ~ From: Fred ~ ~ Hey all, we're going to the Fox and Wheelbarrow for drinks on ~ Friday at 6pm. Join us! ~ Subject: Re: Drinks on Friday ~ From George ~ ~ See you there! ~ ~ === Message from Fred === ~ > Hey all, we're going to the Fox and Wheelbarrow for drinks on ~ > Friday at 6pm. Join us! That's about the level of conversation where top posting works well. But as soon as you get into actual meaningful dialog which requires more than a one or two sentence reply, ESPECIALLY if you ask more than one question, top posting is *shit*. ~ Subject: Project X ~ From: Fred ~ ~ Hey George, we have a few issues to go over regarding Project X. ~ For starters, if we are to have any hope of meeting the deadline, ~ the team is going to need to put in some overtime. Do you think ~ Jane will authorise overtime payments, or should we get time off ~ in lieu? ~ Also, there's a problem with Alex, the web designer. You know ~ that he's a subcontractor, right? Well apparently Accounts hasn't ~ been paying his invoices, and he's threatening to put us on stop ~ and go legal. What should we do? ~ Subject: Re: Project X ~ From: George ~ ~ Yeah, sure, I agree. ~ ~ === Message from Fred === ~ > Hey George, we have a few issues to go over regarding Project X. ~ > For starters, if we are to have any hope of meeting the deadline, ~ > the team is going to need to put in some overtime. Do you think ~ > Jane will authorise overtime payments, or should we get time off ~ > in lieu? ~ > Also, there's a problem with Alex, the web designer. You know ~ > that he's a subcontractor, right? Well apparently Accounts hasn't ~ > been paying his invoices, and he's threatening to put us on stop ~ > and go legal. What should we do? Even if George isn't an absolute pillock and actually intends to give a useful answer, he has to work harder by explicitly referencing the questions being replied to: ~ Subject: Re: Project X ~ From: George ~ ~ Regarding the overtime question, I'll discuss it with Bob and get ~ him to talk to Jane. He's the project manager, let him earn his ~ salary. ~ Regarding Alex, he's a tit and I'm pretty sure he's overcharging ~ us, so this will be a good opportunity to get rid of him. Tell him ~ there's nothing you can do. Once he puts us on stop, we can steal ~ an in-house web developer from Sarah's team. I still owe her for ~ poaching Manjinder. It might only be an extra few words each time there's a change of topic, but it adds up. And because it does require those extra few words, and most people are lazy, most people don't bother: ~ Subject: Re: Project X ~ From: George ~ ~ I'll discuss it with Bob. ~ ~ He's a tit and I'm pretty sure he's overcharging us. Tell him ~ nothing. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tjreedy at udel.edu Mon Jun 27 22:46:43 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Jun 2016 22:46:43 -0400 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: On 6/27/2016 6:29 PM, Pavel S wrote: > Frankly, do you always unit-test if __all__ works? One should. CPython's test suite includes test___all__. I believe it imports every stdlib module, looks for __all__, and if present, tests that it works. It probably executes 'from module import *'. A side effect is testing that everything imports. I am pretty sure that test___all__ has caught bugs. -- Terry Jan Reedy From steve at pearwood.info Mon Jun 27 23:23:37 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 13:23:37 +1000 Subject: Question on compiling on linux References: <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> <576E389B.7060709@chello.at> <1467035818.2222949.649673417.18E0D090@webmail.messagingengine.com> <5771e0c2$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5771edba$0$1622$c3e8da3$5496439d@news.astraweb.com> Oh, and while I'm ranting about top-posting, there's another reason why it's shit. Speaking from experience, it makes searching email archives awful. I've been in the position of having to go through email archives looking for relevant email discussions related to a legal dispute. Trying to search for key words is far less effective with top-posting and no trimming, as the volume of text you need to deal with increases as (roughly) the square of the number of emails: A emails B: ~ Hey! B replies: ~ Hey yourself! ~ > Hey! A responds: ~ Wazzup dude? ~ > Hey yourself! ~ >> Hey! And B responds: ~ Just chillin. And you? ~ > Wazzup dude? ~ >> Hey yourself! ~ >>> Hey! And the reply: ~ Working hard man. Or hardly working LOL LOL LOL ~ > Just chillin. And you? ~ >> Wazzup dude? ~ >>> Hey yourself! ~ >>>> Hey! One last response from B: ~ OK catch u later. ~ > Working hard man. Or hardly working LOL LOL LOL ~ >> Just chillin. And you? ~ >>> Wazzup dude? ~ >>>> Hey yourself! ~ >>>>> Hey! Total lines: 1 + 2 + 3 + 4 + 5 + 6 = 21 which is given by n*(n-1)/2 or O(n**2). Now imagine that each email contains at least one paragraph of text, plus (oh joy) an email disclaimer, plus (say) a ten line signature, *all* of which is typically commented because gods forbid that people use a signature marker "-- "[1] or that email clients trim anything below it when present. Me, bitter? Whatever gave you that impression? [1] Yes the trailing space is significant. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Mon Jun 27 23:24:51 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 13:24:51 +1000 Subject: __all__ attribute: bug and proposal References: Message-ID: <5771ee03$0$1622$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 12:46 pm, Terry Reedy wrote: > On 6/27/2016 6:29 PM, Pavel S wrote: > >> Frankly, do you always unit-test if __all__ works? > > One should. CPython's test suite includes test___all__. I believe it > imports every stdlib module, looks for __all__, and if present, tests > that it works. It probably executes 'from module import *'. A side > effect is testing that everything imports. I am pretty sure that > test___all__ has caught bugs. I write my own unit tests for __all__, which has certainly caught bugs. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From torriem at gmail.com Mon Jun 27 23:39:42 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Jun 2016 21:39:42 -0600 Subject: Question on compiling on linux In-Reply-To: <5771e0c2$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <576D79B8.5080303@chello.at> <576D7D67.3070804@chello.at> <576D89D7.6010409@chello.at> <576E389B.7060709@chello.at> <1467035818.2222949.649673417.18E0D090@webmail.messagingengine.com> <5771e0c2$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/27/2016 08:28 PM, Steven D'Aprano wrote: > On Tue, 28 Jun 2016 10:01 am, Dennis Lee Bieber wrote: > >> The Outlook style works well in a business environment where the >> recipient is likely the original sender of the quoted text, and doesn't >> need the context -- the quoted copy is just a courtesy copy in this case. > > > No it doesn't work well. It is shit in business environments too. It only > works well in one tiny subset of cases: Indeed. Sometimes it took three emails to get the other person to actually read what I wrote and answer my questions. I would email with a few details and question, and he'd immediately top-post back to me with a one-sentence answer that had very little to do with my question and very apparent that he never read anything I wrote. If he had middle-posted, while he was trimming my reply he would have read or re-read what I wrote and responded appropriately. It's just unbelievable how horrid email communication is in a business environment when top-posting is prevalent. I tried on occasion to urge people to not top-post for these reasons, but by and large people just thumbed up their nose and went on not reading emails and top-posting. I guess it's a special management talent. From marko at pacujo.net Tue Jun 28 00:25:25 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 07:25:25 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <8737nywwod.fsf@elektro.pacujo.net> <7835908b-152d-4694-a1cf-3e4d57785f65@googlegroups.com> Message-ID: <87ziq6ndmy.fsf@elektro.pacujo.net> sohcahtoa82 at gmail.com: > On Monday, June 27, 2016 at 7:09:35 AM UTC-7, Marko Rauhamaa wrote: >> Grant Edwards : >> > Were there other languages that did something similar? >> >> In XML, whitespace between tags is significant unless the document type >> says otherwise. On the other hand, leading and trailing space in >> attribute values is insignificant unless the document type says >> otherwise. >> >> > Why would a language designer think it a good idea? >> > >> > Did the poor sod who wrote the compiler think it was a good idea? >> >> Fortran is probably not too hard to parse. XML, on the other hand, is >> impossible to parse without the document type at hand. The document type >> not only defines the whitespace semantics but also the availability and >> meaning of the "entities" (e.g., © for ?). Add namespaces to that, >> and the mess is complete. > > XML isn't a programming language. I don't think it's relevant to the > conversation. The question was about (formal) languages, not only programming languages. However, there are programming languages with XML syntax: Marko From rustompmody at gmail.com Tue Jun 28 00:31:13 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 21:31:13 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> On Tuesday, June 28, 2016 at 6:36:06 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 28 Jun 2016 12:23 am, Rustom Mody wrote: > > Also how is GG deliberately downgrading clear unicode content to be kind > > to obsolete clients at recipient end different from python 2 ? 3 making > > breaking changes but not going beyond ASCII lexemes? > > Oh yes, I completely agree, obviously GvR is literally worse than Hitler > because he hasn't added a bunch of Unicode characters with poor support for > input and worse support for output as essential syntactic elements to > Python. > > /s Gratuitous Godwin acceleration produceth poor sarcasm -- try again And while you are at it try and answer the parallel: Unicode has a major pro and con Pro: Its a superset and enormously richer than ASCII Con: It is costly and implementations are spotty GG downgrades posts containing unicode if it can, thereby increasing reach to recipients with unicode-broken clients Likewise this: > a bunch of Unicode characters with poor support for > input and worse support for output as essential syntactic elements to > Python. sounds like the same logic applied to python JFTR I am not quarrelling with Guido's choices; just pointing out your inconsistencies From zachary.ware+pylist at gmail.com Tue Jun 28 00:31:55 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 27 Jun 2016 23:31:55 -0500 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: On Mon, Jun 27, 2016 at 7:32 PM, Chris Angelico wrote: > If you're primarily worried about classes and functions, here's a neat > trick you can use: > > __all__ = [] > def all(thing): > __all__.append(thing.__name__) > return thing Barry Warsaw has written a nice decorator called 'public' that can be installed from PyPI as 'atpublic'[0]. It was proposed for inclusion as a builtin in 3.6 [1], but a less-than-enthusiastic response at the 2016 Language Summit has put that off indefinitely. I, for one, would like to see it happen anyway [2], and public support may make it possible. The '@public' decorator works like so: """ # spam.py @public def spam(): return ' '.join(['spam']*10) @public def eggs(): return 'bacon' public(HAM=4) assert HAM == 4 assert sorted(__all__) == sorted(['spam', 'eggs', 'HAM']) """ This strikes me as being a cleaner approach than what the OP suggested, easier to use than Chris' simple decorator, and a nice way to bring an end to outdated __all__ lists (which is a problem currently plaguing the standard library, and probably many other libraries). [0] https://pypi.python.org/pypi/atpublic [1] https://bugs.python.org/issue26632 [2] https://bugs.python.org/issue26632#msg267305 -- Zach From benjamin at python.org Tue Jun 28 00:36:55 2016 From: benjamin at python.org (Benjamin Peterson) Date: Mon, 27 Jun 2016 21:36:55 -0700 Subject: [RELEASE] Python 2.7.12 Message-ID: <1467088615.1149970.650417777.5119C4CF@webmail.messagingengine.com> It is my privilege to present you with another release in the Python 2.7 series, Python 2.7.12. Since the release candidate, there were two changes: - The Windows binaries have been changed to use OpenSSL 1.0.2h. - The "about" dialog in IDLE was fixed. Downloads, as always, are on python.org: https://www.python.org/downloads/release/python-2712/ The complete 2.7.12 changelog is available at https://hg.python.org/cpython/raw-file/v2.7.12/Misc/NEWS Yet another Python 2.7.x release is anticipated near the end of the year. Numerologists may wish to upgrade to Python 3 before we hit the unlucky 2.7.13. Servus, Benjamin 2.7 release manager From rustompmody at gmail.com Tue Jun 28 01:00:29 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 22:00:29 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <87r3bielgr.fsf@universite-de-strasbourg.fr.invalid> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <87r3bielgr.fsf@universite-de-strasbourg.fr.invalid> Message-ID: <82c0d470-7eb7-4ba1-b13e-5c434cca727d@googlegroups.com> On Monday, June 27, 2016 at 8:19:05 PM UTC+5:30, Alain Ketterlin wrote: > Grant Edwards writes: > > Did the poor sod who wrote the compiler think it was a good idea? > > I don't know, but he has a good excuse: he was one of the first to ever > write a compiler (see https://en.wikipedia.org/wiki/Compiler, the > section on History). > > You just called John Backus a "poor sod". Think again. The irony is bigger than you are conveying 1957: Backus made Fortran 20 years later: [1977] He won the Turing award, citation explicitly mentioning his creation of Fortran. His Turing award lecture makes a demand for an alternative functional language (first usage of FP that I know) and lambasts traditional imperative programming language. http://worrydream.com/refs/Backus-CanProgrammingBeLiberated.pdf However in addition to lambasting current languages in general he owns up to his own contribution to the imperative-programming-goofup: | I refer to conventional languages as "von Neumann languages" to take note of | their origin and style, I do not, of course, blame the great mathematician for | their complexity. In fact, some might say that I bear some responsibility for | that problem. I conjecture that it was Backus' clarion call to think more broadly about paradigms and not merely about syntax details that prompted the next Turing talk: Floyd's title (1978) *is* Paradigms of Programming though he did not use the word quite as we do today Likewise Backus' call to dump the imperative 'word-at-a-time' model and look to APL to inspiration probably made it possible for an outlier like Iverson to win the Turing award in 79 All these taken together have inched CS slowly away from the imperative paradigm: This and other titbits of history: http://blog.languager.org/2015/04/cs-history-1.html In short for someone in 2016 to laugh at Backus for 1957 mistakes that he had already realized and crossed over in 1977, and yet continue to use the imperative paradigm ie the 57-mistake... well the joke is in the opposite direction From ben+python at benfinney.id.au Tue Jun 28 01:02:27 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 28 Jun 2016 15:02:27 +1000 Subject: Meta decorator with parameters, defined in explicit functions Message-ID: <85mvm5vrbw.fsf@benfinney.id.au> Howdy all, I want an explicit replacement for a common decorator idiom. There is a clever one-line decorator that has been copy-pasted without explanation in many code bases for many years:: decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) My problem with this is precisely that it is clever: it explains nothing about what it does, has many moving parts that are not named, it is non-obvious and lacks expressiveness. Even the widely-cited ActiveState recipe by Peter Hunt from 2005 gives no clue as to what this is doing internally nor what the names of its parts should be. I would like to see a more Pythonic, more explicit and expressive replacement with its component parts easily understood. -- \ ?[H]ow deep can a truth be ? indeed, how true can it be ? if it | `\ is not built from facts?? ?Kathryn Schulz, 2015-10-19 | _o__) | Ben Finney From zachary.ware+pylist at gmail.com Tue Jun 28 01:42:04 2016 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 28 Jun 2016 00:42:04 -0500 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <85mvm5vrbw.fsf@benfinney.id.au> References: <85mvm5vrbw.fsf@benfinney.id.au> Message-ID: On Tue, Jun 28, 2016 at 12:02 AM, Ben Finney wrote: > Howdy all, > > I want an explicit replacement for a common decorator idiom. > > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) > > My problem with this is precisely that it is clever: it explains nothing > about what it does, has many moving parts that are not named, it is > non-obvious and lacks expressiveness. > > Even the widely-cited ActiveState recipe by Peter Hunt from 2005 > > gives no clue as to what this is doing internally nor what the names of > its parts should be. > > I would like to see a more Pythonic, more explicit and expressive > replacement with its component parts easily understood. Try this on for size: ''' import functools def decorator_with_args(decorator): """ Meta-decorator for decorators that take arguments. Usage: @decorator_with_args def some_decorator(func, foo, bar=None) if foo: func.bar = bar return func @some_decorator(True, bar='quux') def some_decorated_function(some_arg) return some_arg assert some_decorated_function.bar == 'quux' Returns a function that takes arguments which are to be passed to the decorator along with the function to be decorated. This allows you to just write your decorator as taking the arguments you want, without having to write a decorator factory that creates and returns a decorator. """ @functools.wraps(decorator) def factory(*args, **kwargs): """Generic decorator factory. Returns a decorator that calls the original decorator with the function to be decorated and all arguments passed to this factory. """ def decorator_wrapper(func): """Thin wrapper around the real decorator.""" return decorator(func, *args, **kwargs) return decorator_wrapper return factory ''' I make no guarantees about this; this is completely untested and is based solely upon how the original translated in my mind. If I misunderstood how the original works, this is worse than useless :). Also, I'm not sure how close I got on the "easily understood" part. It's certainly more explanatory than the original, but it's not the simplest of concepts anyway: a function that takes a function and returns a function that takes arbitrary arguments and returns a function that takes a function and returns the result of calling the originally passed function with arguments consisting of the passed function and the aforementioned arbitrary arguments has too many layers of indirection to keep in mind at once! -- Zach From steve+comp.lang.python at pearwood.info Tue Jun 28 01:42:45 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 15:42:45 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> Message-ID: <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> On Tuesday 28 June 2016 14:31, Rustom Mody wrote: > On Tuesday, June 28, 2016 at 6:36:06 AM UTC+5:30, Steven D'Aprano wrote: >> On Tue, 28 Jun 2016 12:23 am, Rustom Mody wrote: >> > Also how is GG deliberately downgrading clear unicode content to be kind >> > to obsolete clients at recipient end different from python 2 ? 3 making >> > breaking changes but not going beyond ASCII lexemes? >> >> Oh yes, I completely agree, obviously GvR is literally worse than Hitler >> because he hasn't added a bunch of Unicode characters with poor support for >> input and worse support for output as essential syntactic elements to >> Python. >> >> /s > > Gratuitous Godwin acceleration produceth poor sarcasm -- try again > And while you are at it try and answer the parallel: > Unicode has a major pro and con > Pro: Its a superset and enormously richer than ASCII Correct. > Con: It is costly and implementations are spotty That's a matter of opinion. What do you mean by "spotty"? It seems to me that implementations are mostly pretty good, at least as good as Python 2 narrow builds. Support for astral characters is not as good, but (apart from some Han users, and a few specialist niches) not as import either. The big problem is poor tooling: fonts still have many missing characters, and editors don't make it easy to enter anything not visible on the keyboard. > GG downgrades posts containing unicode if it can, thereby increasing reach to > recipients with unicode-broken clients And how does that encourage clients to support Unicode? It just enables developers to tell themselves "It's just a few weirdos and foreigners who use Unicode, ASCII [by which they mean Latin 1] is good enough for everyone." Its 2016, and it is *way* past time that application developers stop pandering to legacy encodings by making them the default. If developers saw that 99% of emails were UTF-8, they would be less likely to think they could avoid learning about Unicode. > Likewise this: > >> a bunch of Unicode characters with poor support for >> input and worse support for output as essential syntactic elements to >> Python. > > sounds like the same logic applied to python > > JFTR I am not quarrelling with Guido's choices; just pointing out your > inconsistencies Oh, it's inconsistencies plural is it? So I have more than one? :-) In Python 3, source files are treated as UTF-8 by default. That means, if you want to use Unicode characters in your source code (for variable names, comments, or in strings) you can, and you don't have to declare a special encoding. Just save the file in an editor that defaults to UTF-8, and Python is satisfied. If, for some reason, you need some legacy encoding, you can still explicitly set it with a coding cookie at the top of the file. That behaviour is exactly analogous to my position that mail and news clients should default to UTF-8. But in neither case would people be *required* to include Unicode characters in their text. -- Steve From rosuav at gmail.com Tue Jun 28 02:04:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 16:04:56 +1000 Subject: Assignment Versus Equality In-Reply-To: <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jun 28, 2016 at 3:42 PM, Steven D'Aprano wrote: > And how does that encourage clients to support Unicode? It just enables > developers to tell themselves "It's just a few weirdos and foreigners who use > Unicode, ASCII [by which they mean Latin 1] is good enough for everyone." > Or Windows-1252, but declared as Latin-1. (Bane of my life.) ChrisA From no.email at nospam.invalid Tue Jun 28 02:08:44 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 27 Jun 2016 23:08:44 -0700 Subject: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> Message-ID: <87y45ponf7.fsf@nightsong.com> Ben Finney writes: > decorator_with_args = lambda decorator: lambda *args, **kwargs: > lambda func: decorator(func, *args, **kwargs) > I would like to see a more Pythonic, more explicit and expressive > replacement with its component parts easily understood. How's this: from functools import partial def dwa(decorator): def wrap(*args,**kwargs): return partial(decorator, *args, **kwargs) return wrap From rustompmody at gmail.com Tue Jun 28 02:09:32 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 23:09:32 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, June 28, 2016 at 11:12:59 AM UTC+5:30, Steven D'Aprano wrote: > On Tuesday 28 June 2016 14:31, Rustom Mody wrote: > > > On Tuesday, June 28, 2016 at 6:36:06 AM UTC+5:30, Steven D'Aprano wrote: > >> On Tue, 28 Jun 2016 12:23 am, Rustom Mody wrote: > >> > Also how is GG deliberately downgrading clear unicode content to be kind > >> > to obsolete clients at recipient end different from python 2 ? 3 making > >> > breaking changes but not going beyond ASCII lexemes? > >> > >> Oh yes, I completely agree, obviously GvR is literally worse than Hitler > >> because he hasn't added a bunch of Unicode characters with poor support for > >> input and worse support for output as essential syntactic elements to > >> Python. > >> > >> /s > > > > Gratuitous Godwin acceleration produceth poor sarcasm -- try again > > And while you are at it try and answer the parallel: > > Unicode has a major pro and con > > Pro: Its a superset and enormously richer than ASCII > > Correct. > > > Con: It is costly and implementations are spotty > > That's a matter of opinion. What do you mean by "spotty"? We've had this conversation before. Ive listed these spottinesses See http://blog.languager.org/2015/03/whimsical-unicode.html Specifically the section on ?-assed unicode support > > It seems to me that implementations are mostly pretty good, at least as good as > Python 2 narrow builds. Support for astral characters is not as good, but > (apart from some Han users, and a few specialist niches) not as import either. > > The big problem is poor tooling: fonts still have many missing characters, and > editors don't make it easy to enter anything not visible on the keyboard. > > > > GG downgrades posts containing unicode if it can, thereby increasing reach to > > recipients with unicode-broken clients > > And how does that encourage clients to support Unicode? It just enables > developers to tell themselves "It's just a few weirdos and foreigners who use > Unicode, ASCII [by which they mean Latin 1] is good enough for everyone." > > Its 2016, and it is *way* past time that application developers stop pandering > to legacy encodings by making them the default. If developers saw that 99% of > emails were UTF-8, they would be less likely to think they could avoid learning > about Unicode. > > > > Likewise this: > > > >> a bunch of Unicode characters with poor support for > >> input and worse support for output as essential syntactic elements to > >> Python. > > > > sounds like the same logic applied to python > > > > JFTR I am not quarrelling with Guido's choices; just pointing out your > > inconsistencies > > Oh, it's inconsistencies plural is it? So I have more than one? :-) Here's one (below) > > In Python 3, source files are treated as UTF-8 by default. That means, if you > want to use Unicode characters in your source code (for variable names, > comments, or in strings) you can, and you don't have to declare a special > encoding. Just save the file in an editor that defaults to UTF-8, and Python is > satisfied. If, for some reason, you need some legacy encoding, you can still > explicitly set it with a coding cookie at the top of the file. > > That behaviour is exactly analogous to my position that mail and news clients > should default to UTF-8. But in neither case would people be *required* to > include Unicode characters in their text. Python2 had strings and unicode strings u"..." Python3 has char-strings and byte-strings b"..." with the char-strings uniformly spanning all of unicode. Not just a significant change in implementation but in mindset Yet the way you use Unicode in the sentence above implies that while you *say* 'Unicode' you mean the set Unicode - ASCII which is exactly Python2 mindset. So which mindset do you subscribe to? From greg.ewing at canterbury.ac.nz Tue Jun 28 02:12:09 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 28 Jun 2016 18:12:09 +1200 Subject: Can math.atan2 return INF? In-Reply-To: <87inwvp22e.fsf@elektro.pacujo.net> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > We cannot get any information on black holes proper because black holes > cannot come into existence according to the very theory that predicts > black holes. It will take infinitely long for an event horizon to form. Only in some frames of reference. By your reasoning, Zeno's paradox proves that a runner can never reach the finish line in a race. But it really only proves that if you measure time in such a way that the finishing time is infinitely far in your future, you will never see him finish. That's obviously a screwy way to measure time in a race, but something similar is happening with the black hole. If you draw coordinate lines in a particular way (corresponding to the inertial frame of an outside observer stationary with respect to the hole) then the time axis bends in such a way that it never crosses the horizon. But there's no reason you have to draw the coordinates that way; there are plenty of others in which the time axis does cross the horizon. -- Greg From greg.ewing at canterbury.ac.nz Tue Jun 28 02:12:17 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 28 Jun 2016 18:12:17 +1200 Subject: Can math.atan2 return INF? In-Reply-To: <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> Message-ID: Rustom Mody wrote: > I said that for the Haskell list [0..] > > [0..] ++ [-1] == [0..] > > He said (in effect) yes that -1 would not be detectable but its still there! The code to generate it is there, but it will never be executed, so the compiler is entitled to optimise it away. :-) He may have a point though. There are avenues of mathematics where people think about objects such as "all the natural numbers, followed by -42", and consider that to be something different from just "all the natural numbers". So, a mathematician would probably say they're not equal. A scientist would say they may or may not be equal, but the difference is not testable. An engineer would say "Lessee, 0, 1, 2, 3, 4, 5, 6, 7... yep, they're equal to within measurement error." -- Greg From marko at pacujo.net Tue Jun 28 02:12:17 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 09:12:17 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87por1on9a.fsf@elektro.pacujo.net> Chris Angelico : > Or Windows-1252, but declared as Latin-1. (Bane of my life.) J Marko From greg.ewing at canterbury.ac.nz Tue Jun 28 02:15:27 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 28 Jun 2016 18:15:27 +1200 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> Message-ID: BartC wrote: > You mean the rationale was based on saving keystrokes? Maybe disk space as well -- bytes were expensive in those days! -- Greg From greg.ewing at canterbury.ac.nz Tue Jun 28 02:17:49 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 28 Jun 2016 18:17:49 +1200 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <1b32nb91oakau2sj4lbck2k7tje9lfr01b@4ax.com> Message-ID: Dennis Lee Bieber wrote: > Or my favorite example of a parser headache: which is the loop > instruction and which is the assignment > > DO10I=3,14 > DO 10 I = 3.14 And if the programmer and/or compiler gets it wrong, your spacecraft crashes into the planet. -- Greg From marko at pacujo.net Tue Jun 28 02:23:26 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 09:23:26 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> Message-ID: <87lh1pomqp.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> We cannot get any information on black holes proper because black holes >> cannot come into existence according to the very theory that predicts >> black holes. It will take infinitely long for an event horizon to form. > > Only in some frames of reference. > > By your reasoning, Zeno's paradox proves that a runner can never reach > the finish line in a race. In Zeno's case, the limit is finite. Zeno's error is not realizing that you can pack an infinite number of jiffies in finite time. In the black hole case, the limit is infinite. > But it really only proves that if you measure time in such a way that > the finishing time is infinitely far in your future, you will never > see him finish. An external observer never experiences any effect whatsoever (direct or indirect) from an event horizon or a black hole. > But there's no reason you have to draw the coordinates that way; there > are plenty of others in which the time axis does cross the horizon. Not where I'm standing. Marko From rustompmody at gmail.com Tue Jun 28 02:25:28 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 23:25:28 -0700 (PDT) Subject: Can math.atan2 return INF? In-Reply-To: References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> Message-ID: On Tuesday, June 28, 2016 at 11:42:29 AM UTC+5:30, Gregory Ewing wrote: > Rustom Mody wrote: > > I said that for the Haskell list [0..] > > > > [0..] ++ [-1] == [0..] > > > > He said (in effect) yes that -1 would not be detectable but its still there! > > The code to generate it is there, but it will never > be executed, so the compiler is entitled to optimise > it away. :-) > > He may have a point though. There are avenues of > mathematics where people think about objects such > as "all the natural numbers, followed by -42", and > consider that to be something different from just > "all the natural numbers". > > So, a mathematician would probably say they're not > equal. A scientist would say they may or may not be > equal, but the difference is not testable. > > An engineer would say "Lessee, 0, 1, 2, 3, 4, 5, > 6, 7... yep, they're equal to within measurement > error." Yes there is a sloppiness in my statement above: [0..] ++ [-1] == [0..] What kind of '==' is that? If its the Haskell (or generally, programming language implementation) version that expression just hangs trying to find the end of the infinite lists. If its not then a devil's advocate could well say: "So its metaphysical, theological and can know the unknowable, viz. that that -1 which is computationally undetectable is nevertheless present. ie the '++' can be a lazy Haskell *implemented* function The '==' OTOH is something at least quasi mystical Mathematicians are more likely to say 'mathematical' than 'mystical' Such mathematicians -- the majority -- are usually called 'Platonists' From steve+comp.lang.python at pearwood.info Tue Jun 28 02:27:37 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 16:27:37 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <87inwvp22e.fsf@elektro.pacujo.net> <35f8e10b-abca-4f8f-9fd8-bd9be15eabad@googlegroups.com> Message-ID: <577218dc$0$1498$c3e8da3$5496439d@news.astraweb.com> On Tuesday 28 June 2016 16:12, Gregory Ewing wrote: > Rustom Mody wrote: >> I said that for the Haskell list [0..] >> >> [0..] ++ [-1] == [0..] >> >> He said (in effect) yes that -1 would not be detectable but its still there! > > The code to generate it is there, but it will never > be executed, so the compiler is entitled to optimise > it away. :-) > > He may have a point though. There are avenues of > mathematics where people think about objects such > as "all the natural numbers, followed by -42", and > consider that to be something different from just > "all the natural numbers". > > So, a mathematician would probably say they're not > equal. A scientist would say they may or may not be > equal, but the difference is not testable. > > An engineer would say "Lessee, 0, 1, 2, 3, 4, 5, > 6, 7... yep, they're equal to within measurement > error." And a programmer would write a script to compare the two, and then go to Stackoverflow asking for help to optimize it because it takes too long to complete. Relevant: https://blogs.msdn.microsoft.com/oldnewthing/20131029-00/?p=2803 -- Steve From rustompmody at gmail.com Tue Jun 28 02:54:55 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Jun 2016 23:54:55 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <87ziq6ndmy.fsf@elektro.pacujo.net> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <8737nywwod.fsf@elektro.pacujo.net> <7835908b-152d-4694-a1cf-3e4d57785f65@googlegroups.com> <87ziq6ndmy.fsf@elektro.pacujo.net> Message-ID: On Tuesday, June 28, 2016 at 9:55:39 AM UTC+5:30, Marko Rauhamaa wrote: > sohcahtoa82: > > > On Monday, June 27, 2016 at 7:09:35 AM UTC-7, Marko Rauhamaa wrote: > >> Grant Edwards : > >> > Were there other languages that did something similar? > >> > >> In XML, whitespace between tags is significant unless the document type > >> says otherwise. On the other hand, leading and trailing space in > >> attribute values is insignificant unless the document type says > >> otherwise. > >> > >> > Why would a language designer think it a good idea? > >> > > >> > Did the poor sod who wrote the compiler think it was a good idea? > >> > >> Fortran is probably not too hard to parse. XML, on the other hand, is > >> impossible to parse without the document type at hand. The document type > >> not only defines the whitespace semantics but also the availability and > >> meaning of the "entities" (e.g., © for ?). Add namespaces to that, > >> and the mess is complete. > > > > XML isn't a programming language. I don't think it's relevant to the > > conversation. > > The question was about (formal) languages, not only programming > languages. > > However, there are programming languages with XML syntax: > > > > Seriously?! You need to justify talking XML on a python list? Which kind of 'python' this list is about? https://www.facebook.com/nixcraft/photos/a.431194973560553.114666.126000117413375/1338469152833126/?type=3 From kliateni at gmail.com Tue Jun 28 02:59:41 2016 From: kliateni at gmail.com (Karim) Date: Tue, 28 Jun 2016 08:59:41 +0200 Subject: [RELEASE] Python 2.7.12 In-Reply-To: <1467088615.1149970.650417777.5119C4CF@webmail.messagingengine.com> References: <1467088615.1149970.650417777.5119C4CF@webmail.messagingengine.com> Message-ID: <5772205D.3070200@gmail.com> On 28/06/2016 06:36, Benjamin Peterson wrote: > It is my privilege to present you with another release in the Python 2.7 > series, Python 2.7.12. > > Since the release candidate, there were two changes: > - The Windows binaries have been changed to use OpenSSL 1.0.2h. > - The "about" dialog in IDLE was fixed. > > Downloads, as always, are on python.org: > https://www.python.org/downloads/release/python-2712/ > > The complete 2.7.12 changelog is available at > https://hg.python.org/cpython/raw-file/v2.7.12/Misc/NEWS > > Yet another Python 2.7.x release is anticipated near the end of the > year. Numerologists may wish to upgrade to Python 3 before we hit the > unlucky 2.7.13. > > Servus, > Benjamin > 2.7 release manager Thank you! Karim From greg.ewing at canterbury.ac.nz Tue Jun 28 02:59:53 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 28 Jun 2016 18:59:53 +1200 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <65309b66-485d-4be7-94ca-f9a8f58b513a@googlegroups.com> Message-ID: BartC wrote: > On 27/06/2016 23:45, Lawrence D?Oliveiro wrote: > >> FORMAT(...complex expression with lots of nested parentheses...) = > > You just design the compiler to do the same processing in each case, ie. > parse a followed (), then mark the result AST > fragment as either an Array term, or Format statement, depending on what > follows, and whether the name is "format". Except that the contents of FORMAT statements have their own unique syntax that's very different from that of argument lists or array indexes. So processing them both the same way would introduce its own level of messiness. Starting all over again from the beginning of the statement is probably the least messy way to handle it. -- Greg From lawrencedo99 at gmail.com Tue Jun 28 03:12:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 28 Jun 2016 00:12:22 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3bd25897-8ecb-4a27-ab22-220677551f41@googlegroups.com> On Tuesday, June 28, 2016 at 6:14:28 PM UTC+12, Rustom Mody wrote: > Ive listed these spottinesses > See http://blog.languager.org/2015/03/whimsical-unicode.html > Specifically the section on ?-assed unicode support Remember how those UTF-16-using pieces of software got sucked into it. They were assured it was UCS-2. As for remembering to correctly free() after malloc(), it?s not that hard to do . From rosuav at gmail.com Tue Jun 28 03:26:08 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 17:26:08 +1000 Subject: Assignment Versus Equality In-Reply-To: <3bd25897-8ecb-4a27-ab22-220677551f41@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> <3bd25897-8ecb-4a27-ab22-220677551f41@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 5:12 PM, Lawrence D?Oliveiro wrote: > . do { /* once */ if (error) break; ... } while (false); do_cleanup; Why not: if (error) goto cleanup; ... cleanup: do_cleanup; Oh, right. XKCD 292. I still think it's better to use the goto, though - you just need velociraptor repellent. ChrisA From dieter at handshake.de Tue Jun 28 03:26:30 2016 From: dieter at handshake.de (dieter) Date: Tue, 28 Jun 2016 09:26:30 +0200 Subject: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> Message-ID: <87h9cddba1.fsf@handshake.de> Ben Finney writes: > I want an explicit replacement for a common decorator idiom. > > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) > > My problem with this is precisely that it is clever: it explains nothing > about what it does, has many moving parts that are not named, it is > non-obvious and lacks expressiveness. I have been able to understand the purpose of the definition above - based solely on background knowledge about "decorator" and the definition. A decorator is a function which takes a function as argument and returns another function, the decorated function. In its simplest form, it is usually is used like: @decorator def f.... However, there is a more complex use: a decorator with arguments. It takes the form @decorator(...args...) def f... In this use, the decorator is not "decorator" itself but "decorator(...args...)". "decorator" itself is in fact a "meta" decorator taking arguments and returning the real decorator. The standard way to define such a meta decorator would be to have a local function definition in its body and return that. Locally defining functions and returning them looks a bit nasty in Python. You might want to avoid it. That's what the "decorator_with_args" above tries to facilitate. It allows you to define a function "decorator" with arguments "func, *args, **kw", decorate it with "decorator_with_args" and use this as a decorator with arguments ("*args, **kw). "decorator_with_args" essentially is a signature transform. It transforms a function "func, *args, **kw --> ..." into a function "*args, **kw --> func --> ..." *AND* it does this in a completely natural and understandable way. From rosuav at gmail.com Tue Jun 28 03:46:09 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 17:46:09 +1000 Subject: Processing text data with different encodings In-Reply-To: References: Message-ID: On Tue, Jun 28, 2016 at 5:25 PM, Michael Welle wrote: > I want to use Python 3 to process data, that unfortunately come with > different encodings. So far I have found ascii, iso-8859, utf-8, > windows-1252 and maybe some more in the same file (don't ask...). I read > the data via sys.stdin and the idea is to read a line, detect the > current encoding, hit it until it looks like utf-8 and then go on with > the next line of input: > > > import cchardet > > for line in sys.stdin.buffer: > > encoding = cchardet.detect(line)['encoding'] > line = line.decode(encoding, 'ignore')\ > .encode('UTF-8').decode('UTF-8', 'ignore') > > > After that line should be a string. The logging module and some others > choke on line: UnicodeEncodeError: 'charmap' codec can't encode > character. What would be a right approach to tackle that problem > (assuming that I can't change the input data)? This is the exact sort of "ewwww" that I have to cope with in my MUD client. Sometimes it gets sent UTF-8, other times it gets sent... uhhhh... some eight-bit encoding, most likely either 8859 or 1252 (but could theoretically be anything). The way I cope with it is to do a line-by-line decode, similar to what you're doing, but with a much simpler algorithm - something like this: for line in : try: line = line.decode("UTF-8") except UnicodeDecodeError: line = line.decode("1252") yield line There's no need to chardet for UTF-8; if you successfully decode the text, it's almost certainly correct. (This includes pure ASCII text, which would also decode successfully and correctly as ISO-8859 or Windows-1252.) You shouldn't need this complicated triple-encode dance. Just decode it once and work with text from there on. Ideally, you should be using Python 3, where "work[ing] with text" is exactly how most of the code wants to work; if not, resign yourself to reprs with u-prefixes, and work with Unicode strings anyway. It'll save you a lot of trouble. ChrisA From jussi.piitulainen at helsinki.fi Tue Jun 28 04:04:28 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 28 Jun 2016 11:04:28 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> <87por1on9a.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Chris Angelico wrote: > >> Or Windows-1252, but declared as Latin-1. (Bane of my life.) > > J J [1] uses ASCII. References: [1] https://en.wikipedia.org/wiki/J_(programming_language) From bharadwajsrivatsa at gmail.com Tue Jun 28 04:10:03 2016 From: bharadwajsrivatsa at gmail.com (bharadwajsrivatsa at gmail.com) Date: Tue, 28 Jun 2016 01:10:03 -0700 (PDT) Subject: Pip 8.1.1 is installed in my system. when try to install few packages using pip I am getting the following error: Message-ID: Pip 8.1.1 is installed in my system. when try to install few packages using pip I am getting the following error: Traceback (most recent call last): File "/usr/bin/pip2", line 5, in from pkgresources import load_entry_point File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 3095, in File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 3081, in _call_aside File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 3108, in _initialize_master_working_set File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 660, in _build_master File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 673, in _build_from_requirements File "build/bdist.linux-x86_64/egg/pkg_resources/init_.py", line 846, in resolve pkg_resources.DistributionNotFound: The 'pip==1.5.4' distribution was not found and is required by the application Can you help me in getting rid of this error From __peter__ at web.de Tue Jun 28 04:30:20 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Jun 2016 10:30:20 +0200 Subject: Processing text data with different encodings References: Message-ID: Michael Welle wrote: > Hello, > > I want to use Python 3 to process data, that unfortunately come with > different encodings. So far I have found ascii, iso-8859, utf-8, > windows-1252 and maybe some more in the same file (don't ask...). I read > the data via sys.stdin and the idea is to read a line, detect the > current encoding, hit it until it looks like utf-8 and then go on with > the next line of input: > > > import cchardet > > for line in sys.stdin.buffer: > > encoding = cchardet.detect(line)['encoding'] > line = line.decode(encoding, 'ignore')\ > .encode('UTF-8').decode('UTF-8', 'ignore') Here the last decode('UTF-8', 'ignore') undoes the preceding encode('UTF-8'); therefore line = line.decode(encoding, 'ignore') should suffice. Does chardet ever return an encoding that fails to decode the line? Only in that case the "ignore" error handler would make sense. I expect that for line in sys.stdin.buffer: encoding = cchardet.detect(line)['encoding'] line = line.decode(encoding) will work if you don't want to use the alternative suggested by Chris. > After that line should be a string. The logging module and some others > choke on line: UnicodeEncodeError: 'charmap' codec can't encode > character. What would be a right approach to tackle that problem > (assuming that I can't change the input data)? It looks like you are trying to write the unicode you have generated above into a file using iso-8859-1 or similar: $ cat log_unicode.py import logging LOGGER = logging.getLogger() LOGGER.addHandler(logging.FileHandler("tmp.txt", encoding="ISO-8859-1")) LOGGER.critical("\N{PILE OF POO}") $ python3 log_unicode.py --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.4/logging/__init__.py", line 980, in emit stream.write(msg) UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f4a9' in position 0: ordinal not in range(256) Call stack: File "log_unicode.py", line 5, in LOGGER.critical("\N{PILE OF POO}") Message: '?' Arguments: () If my assumption is correct you can either change the target file's encoding to UTF-8 or change the error handling strategy to ignore or something else. I didn't find an official way, so here's a minimal example: $ rm tmp.txt $ cat log_unicode.py import logging class FileHandler(logging.FileHandler): def _open(self): return open( self.baseFilename, self.mode, encoding=self.encoding, errors="xmlcharrefreplace") LOGGER = logging.getLogger() LOGGER.addHandler(FileHandler("tmp.txt", encoding="ISO-8859-1")) LOGGER.critical("\N{PILE OF POO}") $ python3 log_unicode.py $ cat tmp.txt 💩 A real program would of course override the initializer... From steve+comp.lang.python at pearwood.info Tue Jun 28 04:39:56 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 18:39:56 +1000 Subject: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> Message-ID: <577237de$0$11110$c3e8da3@news.astraweb.com> On Tuesday 28 June 2016 15:02, Ben Finney wrote: > Howdy all, > > I want an explicit replacement for a common decorator idiom. > > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda > func: decorator(func, *args, **kwargs) I've never seen it before, and I'll admit I really had to twist my brain to understand it, but I came up with an example showing the traditional style of decorator-factory versus this meta-decorator. # Standard idiom. def chatty(name, age, verbose=True): # the factory def decorator(func): # the decorator returned by the factory if verbose: print("decorating function...") @functools.wraps(func) def inner(*args, **kwargs): print("Hi, my name is %s and I am %d years old!" % (name, age)) return func(*args, **kwargs) return inner return decorator @chatty("Bob", 99) def calculate(x, y, z=1): return x+y-z # Meta-decorator variant. decorator_with_args = (lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs)) @decorator_with_args def chatty(func, name, age, verbose=True): if verbose: print("decorating function...") @functools.wraps(func) def inner(*args, **kwargs): print("Hi, my name is %s and I am %d years old!" % (name, age)) return func(*args, **kwargs) return inner @chatty("Bob", 99) def calculate(x, y, z=1): return x+y-1 I agree -- it's very clever, and completely opaque in how it works. The easy part is expanding the lambdas: def decorator_with_args(decorator): def inner(*args, **kwargs): def innermost(func): return decorator(func, *args, **kwargs) return innermost return inner but I'm not closer to having good names for inner and innermost than you. -- Steve From lawrencedo99 at gmail.com Tue Jun 28 04:49:00 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 28 Jun 2016 01:49:00 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> <3bd25897-8ecb-4a27-ab22-220677551f41@googlegroups.com> Message-ID: <01ed522b-71d6-4535-8d49-b0e32c33ee3a@googlegroups.com> On Tuesday, June 28, 2016 at 7:26:30 PM UTC+12, Chris Angelico wrote: > Why not: > > if (error) goto cleanup; > ... > cleanup: > do_cleanup; They all fall into that same trap. Doesn?t scale. Try one with allocation inside a loop, e.g. lines 488 onwards. From michele.simionato at gmail.com Tue Jun 28 06:02:44 2016 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 28 Jun 2016 03:02:44 -0700 (PDT) Subject: argparse and subparsers In-Reply-To: References: <4ab10ce55d564780b158c19817009b62@activenetwerx.com> <5b1c7833-5cd3-47b3-b82b-643e88606fef@googlegroups.com> <5770ffe3$0$2901$c3e8da3$76491128@news.astraweb.com> Message-ID: I did not know about docopt. It is basically the same idea of this recipe I wrote about 12 years ago: https://code.activestate.com/recipes/278844-parsing-the-command-line/?in=user-1122360 Good that it was reinvented :-) From rosuav at gmail.com Tue Jun 28 06:25:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 20:25:44 +1000 Subject: Processing text data with different encodings In-Reply-To: References: Message-ID: On Tue, Jun 28, 2016 at 6:30 PM, Peter Otten <__peter__ at web.de> wrote: > Does chardet ever return an encoding that fails to decode > the line? Only in that case the "ignore" error handler would make sense. Assuming the module the OP is using is functionally identical to the one I use from the command line (which is implemented in Python), yes it can. Usually what happens is that it detects something as an ISO-8859-* when it's actually the corresponding Windows codepage; if you try to decode it that way, you end up with a handful of byte values that don't correctly decode. I have a "cdless" command that does a chardet, decodes the file, re-encodes as UTF-8, and pipes the result into less(1); great way to figure out what encoding something is (if it gets it wrong, it's usually really obvious to a human). It has a magic second parameter "win" to switch from ISO-8859 to Windows encoding - ISO-8859-1 becomes Windows-1252, -2 becomes 1250, etc. Additionally, chardet often returns "MacCyrillic" for files that are actually encoded Windows-1256 (Arabic). So, yes, it's definitely possible for chardet to pick something that you can't actually decode with. For the OP's situation, frankly, I doubt there'll be anything other than UTF-8, Latin-1, and CP-1252. The chances that someone casually mixes CP-1252 with (say) CP-1254 would be vanishingly small. So the simple decode of "UTF-8, or failing that, 1252" is probably going to give correct results for most of the content. The trick is figuring out a correct boundary for the check; line-by-line may be sufficient, or it may not. ChrisA From steve at pearwood.info Tue Jun 28 06:29:28 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 20:29:28 +1000 Subject: Processing text data with different encodings References: <4gp94dxgr7.ln2@news.c0t0d0s0.de> Message-ID: <5772518a$0$1606$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 06:35 pm, Michael Welle wrote: > my original data is email. The mail header says it's utf-8, but you will > find three or four different encodings in one email. I think at the > sending side they just glue different text fragments from different > sources together without thinking about the encoding. Is this spam? In my experience, the only email that is that badly constructed is spam. I can't imagine how it could be email from a person, coming from a mail client like Thunderbird or Outlook. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Tue Jun 28 06:34:59 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 20:34:59 +1000 Subject: Assignment Versus Equality In-Reply-To: <01ed522b-71d6-4535-8d49-b0e32c33ee3a@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> <3bd25897-8ecb-4a27-ab22-220677551f41@googlegroups.com> <01ed522b-71d6-4535-8d49-b0e32c33ee3a@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 6:49 PM, Lawrence D?Oliveiro wrote: > On Tuesday, June 28, 2016 at 7:26:30 PM UTC+12, Chris Angelico wrote: >> Why not: >> >> if (error) goto cleanup; >> ... >> cleanup: >> do_cleanup; > > They all fall into that same trap. Doesn?t scale. Try one with allocation inside a loop, e.g. lines 488 onwards. How is that different? You can use a goto inside a for loop just fine. (You can even, if you are absolutely insane and begging to be murdered by the future maintainer, use a goto outside a for loop targeting a label inside. See for example Duff's Device, although that's a switch rather than an actual goto.) You have a loop, and inside that loop, the exact same error handling pattern; so it should be possible to perform the exact same transformation, albeit with a differently-named local cleanup label. So, yes. It doesn't scale, if by "scale" you mean "so many separate local instances of error handling that you lose track of your cleanup labels". But you should be able to keep half a dozen labels in your head (if they're named appropriately), and if you have that many local error handlers, you probably want something to be refactored. ChrisA From bc at freeuk.com Tue Jun 28 06:35:15 2016 From: bc at freeuk.com (BartC) Date: Tue, 28 Jun 2016 11:35:15 +0100 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <65309b66-485d-4be7-94ca-f9a8f58b513a@googlegroups.com> Message-ID: On 28/06/2016 01:11, Dennis Lee Bieber wrote: > On Tue, 28 Jun 2016 00:08:00 +0100, BartC declaimed the > following: > >> >> You just design the compiler to do the same processing in each case, ie. >> parse a followed (), then mark the result AST >> fragment as either an Array term, or Format statement, depending on what >> follows, and whether the name is "format". >> > You're expecting an AST in a compiler from the 50s? > Well, FORTRAN in the 50s would have been much simpler too. No nested subscripts for example. And ASTs are just one of many methods of compiling. > That might have involved having to punch an output deck of cards for > each compile, only to then feed that deck back into the reader for the next > phase of compilation. We have to assume that at least one complete line could be held in memory. Then you can reinterpret it as many times as you like. (I don't know if 1950s FORTRAN has continuation lines, which makes that a little harder.) However, not allowing FORMAT as a variable name probably /would/ have been simpler! -- Bartc From steven.truppe at chello.at Tue Jun 28 06:51:18 2016 From: steven.truppe at chello.at (Steven Truppe) Date: Tue, 28 Jun 2016 12:51:18 +0200 Subject: What the deal with python3.5m.so and python3.5.so ?? Message-ID: <577256A6.7030509@chello.at> Hi all, can someone tell me the difference between python3.5m.so and python3.5.so ?? Tanks in advance, Steven Truppe From rosuav at gmail.com Tue Jun 28 07:09:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jun 2016 21:09:42 +1000 Subject: Processing text data with different encodings In-Reply-To: References: <4gp94dxgr7.ln2@news.c0t0d0s0.de> <5772518a$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jun 28, 2016 at 8:37 PM, Michael Welle wrote: > Steven D'Aprano writes: > >> On Tue, 28 Jun 2016 06:35 pm, Michael Welle wrote: >> >>> my original data is email. The mail header says it's utf-8, but you will >>> find three or four different encodings in one email. I think at the >>> sending side they just glue different text fragments from different >>> sources together without thinking about the encoding. >> >> Is this spam? In my experience, the only email that is that badly >> constructed is spam. I can't imagine how it could be email from a person, >> coming from a mail client like Thunderbird or Outlook. > it's mail from an international company. It's not generated by a person > using an ordinary email client. Other than that your are right ;). So..... buggy commercial email. Great. Just brilliant. Can you bill them for your time developing this hack? ChrisA From steve at pearwood.info Tue Jun 28 07:26:28 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 28 Jun 2016 21:26:28 +1000 Subject: Processing text data with different encodings References: Message-ID: <57725ee6$0$1600$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 08:17 pm, Michael Welle wrote: > After a bit more 'fiddling' I found out that all test cases work if I > use .decode('utf-8') on the incoming bytes. In my first approach I tried > to find out at what I was looking and then used a specific .decode, e.g. > .decode('windows-1252'). That were the trouble makers. Remember that chardet's detection is based on statistics and heuristics and cannot be considered 100% reliable. Normally I would expect that chardet would guess two or three encodings. If the first fails, you might want to check the others. Also remember that chardet works best with large amounts of text, like an entire webpage. If you pass it a single byte, or even a few bytes, the results will likely be no better than whatever encoding the chardet developer decided to use as the default: "If there's not enough data to guess, just return Win-1252, because that's pretty common..." > With your help, I fixed logging. Somehow I had in mind that the > logging module would do the right thing if I don't specify the encoding. > Well, setting the encoding explicitly to utf-8 changes the behaviour. I would expect that logging will do the right thing if you pass it text strings and have set the encoding to UTF-8. > If I use decode('windows-1252') on a bit of text You cannot decode text. Text is ENCODED to bytes, and bytes are DECODED to text. > I still have trouble to understand what's happening. > For instance, there is an u umlaut in the > 1252 encoded portion of the input text. You don't know that. If the input is *bytes*, then all you know is the byte values. What they mean is anyone's guess unless the name of the encoding is transmitted separately. You can be reasonably sure that the bytes are mostly ASCII, because it's email and nobody sends email in EBCDIC, so if you see a byte 0x41, you can be sure it represents an 'A'. But outside of the ASCII range, you're on shaky ground. If the specified encoding is correct, then everything works well: the email says it is UTF-8, and sure enough it is UTF-8. But if the specified encoding is wrong, you're in trouble. You only think the encoding is Windows-1252 because Chardet has guessed that. But it's not infallible and maybe it has got it wrong. Especially if your input is made up of a lot of bytes from all sorts of different encodings, that may be confusing Chardet. > That character is 0xfc in hex. No. Byte 0xFC represents ? if your guess about the encoding is correct. If the encoding truly is Windows-1252, or Latin-1, then byte 0xFC will mean ?. (And some others.) If the source is Western European, that might be a good guess. But if the encoding actually is (let's say): - ISO-8859-5 (Cyrillic), then the byte represents ? - ISO-8859-7 (Greek), then the byte represents ? - MacRoman (Apple Macintosh), then the byte represents ? (That last one is not a comma, but a cedilla.) > After applying .decode('windows-1252') and logging it, the log contains > a mangled character with hex codes 0xc3 0x20. I think you are misunderstanding what you are looking at. How are you seeing that? 0x20 will be a space in most encodings. (1) How are you opening the log file in Python? Do you specify an encoding? (2) How are you writing to the log file? (3) What are you using to read the log file outside of Python? How do you know the hex codes? I don't know any way you can start with the character ? and write it to a file and get bytes 0xc3 0x20. Maybe somebody else will think of something, but to me, that seems impossible. > If I do the same with > .decode('utf-8'), the result is a working u umlaut with 0xfc in the log. That suggests that you have opened the log file using Latin-1 or Windows-1252 as the encoding. You shouldn't do that. Unless you have a good reason to do otherwise (in other words, for experts only) you should always use UTF-8 for writing. > On the other hand, if I try the following in the interactive > interpreter: > > Here I have a few bytes that can be interpreted as a 1252 encoded string > and I command the interpreter to show me the string, right? > >>>> e=b'\xe4' That's ONE byte, not a few. >>>> e.decode('1252') > '?' Right -- that means that byte 0xE4 represents ? in Windows-1252, also in Latin-1 and some others. But: py> e.decode('iso-8859-7') # Greek '?' py> e.decode('iso-8859-8') # Hebrew '?' py> e.decode('iso-8859-6') # Arabic '?' py> e.decode('MacRoman') '?' py> e.decode('iso-8859-5') '?' So if you find a byte 0xE4 in a file, and don't know where it came from, you don't know what it means. If you can guess it came from Russia, then it might be a ?. If you think it came from a Macintosh prior to OS X, then it probably means a per-mill sign ?. > Now, I can't to this, because 0xe4 isn't valid utf-8: >>>> e.decode('utf-8') > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 0: > unexpected end of data Correct. > But why is it different in my actual script? Without seeing your script, it's hard to say what you are actually doing. > I guess the assumption that > what I am reading from sys.stdin.buffer is the same as what is in the > file, that I pipe into the script, is wrong? I wouldn't rule that out, but more likely the issue lies elsewhere, in your own code. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From alister.ware at ntlworld.com Tue Jun 28 07:27:15 2016 From: alister.ware at ntlworld.com (alister) Date: Tue, 28 Jun 2016 11:27:15 GMT Subject: Question on compiling on linux Message-ID: On Mon, 27 Jun 2016 21:39:42 -0600, Michael Torrie wrote: > On 06/27/2016 08:28 PM, Steven D'Aprano wrote: >> On Tue, 28 Jun 2016 10:01 am, Dennis Lee Bieber wrote: >> >>> The Outlook style works well in a business environment where the >>> recipient is likely the original sender of the quoted text, and >>> doesn't need the context -- the quoted copy is just a courtesy copy in >>> this case. >> >> >> No it doesn't work well. It is shit in business environments too. It >> only works well in one tiny subset of cases: > > Indeed. Sometimes it took three emails to get the other person to > actually read what I wrote and answer my questions. I would email with > a few details and question, and he'd immediately top-post back to me > with a one-sentence answer that had very little to do with my question > and very apparent that he never read anything I wrote. If he had > middle-posted, while he was trimming my reply he would have read or > re-read what I wrote and responded appropriately. > > It's just unbelievable how horrid email communication is in a business > environment when top-posting is prevalent. I tried on occasion to urge > people to not top-post for these reasons, but by and large people just > thumbed up their nose and went on not reading emails and top-posting. I > guess it's a special management talent. this is simply because in a business environment emails are not sent to be read & inform the recipient, they are sent to protect the sender. however as the sender never edits the email chain (again for self protection) it soon becomes an equal pain in the arse to scroll to the bottom of a 26 page email for the simple 1 line reply. email for internal communication should be strongly discoraged practice. PICK UP THE BLOODY PHONE PEOPLE -- Saturday night in Toledo Ohio, Is like being nowhere at all, All through the day how the hours rush by, You sit in the park and you watch the grass die. -- John Denver, "Saturday Night in Toledo Ohio" From __peter__ at web.de Tue Jun 28 07:31:08 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Jun 2016 13:31:08 +0200 Subject: Processing text data with different encodings References: Message-ID: Michael Welle wrote: > With your help, I fixed logging. Somehow I had in mind that the > logging module would do the right thing if I don't specify the encoding. The default encoding depends on the environment (and platform): $ touch tmp.txt $ python3 -c 'print(open("tmp.txt").encoding)' UTF-8 $ LANG=C python3 -c 'print(open("tmp.txt").encoding)' ANSI_X3.4-1968 > Well, setting the encoding explicitly to utf-8 changes the behaviour. > > If I use decode('windows-1252') on a bit of text I still have trouble to > understand what's happening. For instance, there is an u umlaut in the > 1252 encoded portion of the input text. That character is 0xfc in hex. > After applying .decode('windows-1252') and logging it, the log contains > a mangled character with hex codes 0xc3 0x20. If I do the same with > .decode('utf-8'), the result is a working u umlaut with 0xfc in the log. > > On the other hand, if I try the following in the interactive > interpreter: > > Here I have a few bytes that can be interpreted as a 1252 encoded string > and I command the interpreter to show me the string, right? > >>>> e=b'\xe4' >>>> e.decode('1252') > '?' > > Now, I can't to this, because 0xe4 isn't valid utf-8: >>>> e.decode('utf-8') > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 0: > unexpected end of data > > But why is it different in my actual script? I guess the assumption that > what I am reading from sys.stdin.buffer is the same as what is in the > file, that I pipe into the script, is wrong? The situation is simple; the string consists of code points, but the file may only contain bytes. When reading a string from a file the bytes read need decoding, and before writing a string to a file it must be encoded. What byte sequence denotes a specific code point depends on the encoding. This is always the case, i. e. if you look at a UTF-8-encoded file with an editor that expects cp1252 you will see >>> in_the_file = "?".encode("utf-8") >>> in_the_file b'\xc3\xa4' >>> what_the_editor_shows = in_the_file.decode("cp1252") >>> print(what_the_editor_shows) ?? On the other hand if you look at a cp1252-encoded file decoding the data as UTF-8 you will likely get an error because the byte >>> "?".encode("cp1252") b'\xe4' alone is not valid UTF-8. As part of a sequence the data may still be ambiguous. If you were to write an a-umlaut followed by two euro signs using cp1252 >>> in_the_file = '???'.encode("cp1252") an editor expecting UTF-8 would show >>> in_the_file.decode("utf-8") '?' From cake240 at gmail.com Tue Jun 28 08:36:25 2016 From: cake240 at gmail.com (Elizabeth Weiss) Date: Tue, 28 Jun 2016 05:36:25 -0700 (PDT) Subject: Iteration, while loop, and for loop Message-ID: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> I understand this code: words=["hello", "world", "spam", "eggs"] for words in words print(word + "!") What I do not understand is: words=["hello", "world", "spam", "eggs"] counter=0 max_index=len(words)-1 while counter<=max_index: word=words[counter] print(word + "!") counter=counter + 1 Both of these result in the same answer. I do not understand the second code. What is counter? Why do we use this code if we can use the simpler for loop? If you could please explain the second code step by step that would be great! Thank you!!! From michael.selik at gmail.com Tue Jun 28 09:15:47 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 28 Jun 2016 13:15:47 +0000 Subject: Iteration, while loop, and for loop In-Reply-To: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss wrote: > I do not understand the second code. What is counter? > It looks like someone wanted to make a loop induction variable. https://en.wikipedia.org/wiki/Induction_variable > Why do we use this code if we can use the simpler for loop? > You should not. Use the first version, it's much better. Python for-loops are preferable to while-loops. From bc at freeuk.com Tue Jun 28 09:24:35 2016 From: bc at freeuk.com (BartC) Date: Tue, 28 Jun 2016 14:24:35 +0100 Subject: Iteration, while loop, and for loop In-Reply-To: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: On 28/06/2016 13:36, Elizabeth Weiss wrote: > I understand this code: > > words=["hello", "world", "spam", "eggs"] > for words in words > print(word + "!") > > What I do not understand is: > > words=["hello", "world", "spam", "eggs"] > counter=0 > max_index=len(words)-1 > > while counter<=max_index: > word=words[counter] > print(word + "!") > counter=counter + 1 > > > > Both of these result in the same answer. > I do not understand the second code. What is counter? > Why do we use this code if we can use the simpler for loop? > > If you could please explain the second code step by step that would be great! Imagine the words are printed in a book, one per page, and the pages are numbered 0, 1, 2 and 3 (starting from 0 as is the perverse say of many programming languages). len(words)-1 is the number of pages in the book (4) less one to account for the odd numbering. Max_index is then the number of the last page (3). Counter then goes through the pages one by one, starting at page 0 and ending at page 3 (ie. max_index), reading the word on each and printing it out with "!" appended. However, because the language is zero-based, this would have been better written as: num_words = len(words) while counter < num_words: # or just while counter < len(words) That's if you had to write it as while loop. With the for=loop version, these details are taken care of behind the scenes. -- Bartc From joseph.lee22590 at gmail.com Tue Jun 28 09:26:30 2016 From: joseph.lee22590 at gmail.com (Joseph Lee) Date: Tue, 28 Jun 2016 06:26:30 -0700 Subject: Iteration, while loop, and for loop In-Reply-To: References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: <00c301d1d140$af331e10$0d995a30$@gmail.com> Hi, Answers inline. -----Original Message----- From: Python-list [mailto:python-list-bounces+joseph.lee22590=gmail.com at python.org] On Behalf Of Michael Selik Sent: Tuesday, June 28, 2016 6:16 AM To: Elizabeth Weiss ; python-list at python.org Subject: Re: Iteration, while loop, and for loop On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss wrote: > I do not understand the second code. What is counter? > It looks like someone wanted to make a loop induction variable. https://en.wikipedia.org/wiki/Induction_variable JL: Or access the array item via indexing. > Why do we use this code if we can use the simpler for loop? > You should not. Use the first version, it's much better. Python for-loops are preferable to while-loops. JL: Indexing is useful if one wishes to assign something different to the position represented by container[index]. But if you want a more elegant way to access the actual object in question, then using the first fragment is better (and more readable). For the most part, for loops are better, but there are times when while loops are preferable such as when you don't know the size of the input beforehand. Cheers, Joseph - https://mail.python.org/mailman/listinfo/python-list From bc at freeuk.com Tue Jun 28 09:29:48 2016 From: bc at freeuk.com (BartC) Date: Tue, 28 Jun 2016 14:29:48 +0100 Subject: Iteration, while loop, and for loop In-Reply-To: References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: On 28/06/2016 14:15, Michael Selik wrote: > On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss wrote: > >> I do not understand the second code. What is counter? >> > > It looks like someone wanted to make a loop induction variable. > https://en.wikipedia.org/wiki/Induction_variable I don't know if that helps; I've never heard of an induction variable. And according to the first example in that link, then 'word' in the OP's second example might be classed as an induction variable too! Confusing. -- Bartc From eryksun at gmail.com Tue Jun 28 09:32:02 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 28 Jun 2016 13:32:02 +0000 Subject: What the deal with python3.5m.so and python3.5.so ?? In-Reply-To: <577256A6.7030509@chello.at> References: <577256A6.7030509@chello.at> Message-ID: On Tue, Jun 28, 2016 at 10:51 AM, Steven Truppe wrote: > > can someone tell me the difference between python3.5m.so and python3.5.so ?? The "m" suffix means that Python is configured "--with-pymalloc", i.e. using specialized mallocs, including the small-object allocator. This is the default configuration. You may also see a "dm" suffix for a build that's configured "--with-pydebug" and "--with-pymalloc". libpython3.5.so and libpython3.5m.so may actually link to the same shared library: $ readlink libpython3.5.so ../../x86_64-linux-gnu/libpython3.5m.so.1 $ readlink libpython3.5m.so ../../x86_64-linux-gnu/libpython3.5m.so.1 From random832 at fastmail.com Tue Jun 28 09:39:06 2016 From: random832 at fastmail.com (Random832) Date: Tue, 28 Jun 2016 09:39:06 -0400 Subject: Can math.atan2 return INF? In-Reply-To: <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1467121146.2509341.650815521.254F4174@webmail.messagingengine.com> On Sun, Jun 26, 2016, at 22:59, Steven D'Aprano wrote: > We have no way of seeing what goes on past the black hole's event > horizon, since light cannot escape. But we can still see *some* > properties of black holes, even through their event horizon: their > mass, any electric charge they may hold, their angular momentum. All objects, not just black holes, have those properties. The point here is that we are in fact observing those properties of an object that is not yet (and never will be) a black hole in our frame of reference. From jussi.piitulainen at helsinki.fi Tue Jun 28 09:42:39 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 28 Jun 2016 16:42:39 +0300 Subject: Iteration, while loop, and for loop References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: Elizabeth Weiss writes: [- -] > What I do not understand is: > > words=["hello", "world", "spam", "eggs"] > counter=0 > max_index=len(words)-1 > > while counter<=max_index: > word=words[counter] > print(word + "!") > counter=counter + 1 # make it so that counter == 0 counter=0 # make it so that max_index is the greatest valid index to words (unless # words is empty -- it would be simpler and idiomatic to make end_index # be the first invalid index aka len(words), but make your life that # little bit harder because ... reasons?) max_index=len(words)-1 while counter<=max_index: # Since we reached this point, counter is at most max_index, and is # a valid index unless words is empty. If the test was instead # counter < end_index, it would definitely be valid, or we wouldn't # be *here*. Anyway, the first time at this point, counter == 0, the # second time counter == 1, ... # Set word to the item of words indicated by counter. First time at # this point, words[0], second time, words[1], ...; print it. word=words[counter] print(word + "!") # Make it so that counter is one larger than it used to be. In # particular, it is closer to being larger than max_index so that we # are eventually done with this loop. counter=counter + 1 # At this point, the loop condition is tested again with the new # value of counter(*) and when that new value is such it is no # longer the case that counter<=max_index, looping ends. # When we reach this point, the loop condition is false (or there has # been another kind of exit from the loop): counter == max_index + 1. (*) Now the thread may go into yet another tangent on how that "new value" is really not a value but is the value of an immutable object that is the value of a reference pointer in a box that is tied to a puppy that is dancing on the point of a pin. You may or may not find that helpful. Also, one or more of these things may be a name or have a name. > Both of these result in the same answer. > I do not understand the second code. What is counter? > Why do we use this code if we can use the simpler for loop? Some loops are not easily written as for loops. This is not one of them. For loops are easy to rewrite as while loops, so while loops may be considered theoretically more fundamental. Other theoretical models would express while loops with even more fundamental mechanisms (or they can be quite practical models, though not directly available in Python for this purpose or at all: conditional jumps to a labelled region of program code, or function calls). You need to get used to how program elements like counter behave. There are events in the execution of a program that make it so that such program elements stand for particular things (like numbers) in a dependable way, in certain specific regions of code, until some new event. The statement involving a single equals sign is one such event; each entry to a for loop is another; a function call is yet another. (I see that I have used the word "thing" about things that I really do think of as things in the context of a Python program, and of things that I don't. [REDACTED] it's hard to talk about these, er, things. Please ignore this paragraph, and that paragraph marked with (*).) [- -] From hemla21 at gmail.com Tue Jun 28 09:45:50 2016 From: hemla21 at gmail.com (Heli) Date: Tue, 28 Jun 2016 06:45:50 -0700 (PDT) Subject: fastest way to read a text file in to a numpy array Message-ID: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> Hi, I need to read a file in to a 2d numpy array containing many number of lines. I was wondering what is the fastest way to do this? Is even reading the file in to numpy array the best method or there are better approaches? Thanks for your suggestions, From michael.selik at gmail.com Tue Jun 28 09:51:54 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 28 Jun 2016 13:51:54 +0000 Subject: Iteration, while loop, and for loop In-Reply-To: <00c301d1d140$af331e10$0d995a30$@gmail.com> References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> <00c301d1d140$af331e10$0d995a30$@gmail.com> Message-ID: On Tue, Jun 28, 2016 at 9:26 AM Joseph Lee wrote: > > -----Original Message----- > From: Michael Selik > Sent: Tuesday, June 28, 2016 6:16 AM > > MS: You should not. Use the first version, it's much better. Python > for-loops are preferable to while-loops. > > JL: For the most part, for loops are better, but there are times when > while loops are preferable such as when you don't know the size of the > input beforehand. Not knowing the number of elements is not a reason to prefer a while-loop. A for-loop handles that quite well. with open('example.txt') as f: for line in f: print(line) We often loop over files without knowing how big a file is. From michael.selik at gmail.com Tue Jun 28 09:58:12 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 28 Jun 2016 13:58:12 +0000 Subject: Iteration, while loop, and for loop In-Reply-To: References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 9:34 AM BartC wrote: > On 28/06/2016 14:15, Michael Selik wrote: > > On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss > wrote: > > > >> I do not understand the second code. What is counter? > >> > > > > It looks like someone wanted to make a loop induction variable. > > https://en.wikipedia.org/wiki/Induction_variable > > I don't know if that helps; I've never heard of an induction variable. > But you've seen them often in other programming languages? > And according to the first example in that link, then 'word' in the OP's > second example might be classed as an induction variable too! The variable ``word`` was not being incremented/decremented by a fixed amount, nor was it a linear function of another induction variable. > Confusing. Indeed. That's why Python's for-loops are preferable. From michael.selik at gmail.com Tue Jun 28 10:00:12 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 28 Jun 2016 14:00:12 +0000 Subject: fastest way to read a text file in to a numpy array In-Reply-To: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> References: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 9:51 AM Heli wrote: > Is even reading the file in to numpy array the best method or there are > better approaches? > What are you trying to accomplish? Summary statistics, data transformation, analysis...? From random832 at fastmail.com Tue Jun 28 10:13:17 2016 From: random832 at fastmail.com (Random832) Date: Tue, 28 Jun 2016 10:13:17 -0400 Subject: Assignment Versus Equality In-Reply-To: <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> Message-ID: <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> On Tue, Jun 28, 2016, at 00:31, Rustom Mody wrote: > GG downgrades posts containing unicode if it can, thereby increasing > reach to recipients with unicode-broken clients That'd be entirely reasonable, except for the excessively broad application of "if it can". Certainly it _can_ do it all the time. Just replace anything that doesn't fit with question marks or hex notation or \N{NAME} or some human readable pseudo-representation a la unidecode. It could have done any of those with the Hindi that you threw in to try to confound it, (or it could have chosen ISCII, which likewise lacks arrow characters, as the encoding to downgrade to). It should pick an encoding which it expects recipients to support and which contains *all* of the characters in the message, as proper characters and not as pseudo-representations, and downgrade to that if and only if such an encoding can be found. For most messages, it can use US-ASCII. For most of the remainder it can use some ISO-8859 or Windows-125x encoding. Or include the UTF-8 and some other character set as multipart/alternative representations. From michael.selik at gmail.com Tue Jun 28 10:29:56 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 28 Jun 2016 14:29:56 +0000 Subject: fastest way to read a text file in to a numpy array In-Reply-To: References: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 10:08 AM Hedieh Ebrahimi wrote: > File 1 has : > x1,y1,z1 > x2,y2,z2 > .... > > and file2 has : > x1,y1,z1,value1 > x2,y2,z2,value2 > x3,y3,z3,value3 > ... > > I need to read the coordinates from file 1 and then interpolate a value > for these coordinates on file 2 to the closest coordinate possible. The > problem is file 2 is has around 5M lines. So I was wondering what would be > the fastest approach? > Is this a one-time task, or something you'll need to repeat frequently? How many points need to be interpolated? How do you define distance? Euclidean 3d distance? K-nearest? 5 million can probably fit into memory, so it's not so bad. NumPy is a good option for broadcasting the distance function across all 5 million labeled points for each unlabeled point. Given that file format, NumPy can probably read from file directly into an array. http://stackoverflow.com/questions/3518778/how-to-read-csv-into-record-array-in-numpy From cody.piersall at gmail.com Tue Jun 28 10:37:55 2016 From: cody.piersall at gmail.com (Cody Piersall) Date: Tue, 28 Jun 2016 09:37:55 -0500 Subject: fastest way to read a text file in to a numpy array In-Reply-To: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> References: <37b46ad8-8318-4d67-a65c-7dd7a50a3848@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 8:45 AM, Heli wrote: > Hi, > > I need to read a file in to a 2d numpy array containing many number of lines. > I was wondering what is the fastest way to do this? > > Is even reading the file in to numpy array the best method or there are better approaches? > numpy.genfromtxt[1] is a pretty robust function for reading text files. If you're generating the file from a numpy array already, you should use arr.save()[2] and numpy.load()[3]. [1]: http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html [2]: http://docs.scipy.org/doc/numpy/reference/generated/numpy.save.html [3]: http://docs.scipy.org/doc/numpy/reference/generated/numpy.load.html Cody From sourav524.itscient at gmail.com Tue Jun 28 10:50:54 2016 From: sourav524.itscient at gmail.com (sourav524.itscient at gmail.com) Date: Tue, 28 Jun 2016 07:50:54 -0700 (PDT) Subject: !! Immediate Requirement: QlikView consultant with JDE experience (Somerset, NJ ) !! Message-ID: Hi All Please revert me: Sourav.P at itscient.com or sourav524.itscient at gmail.com If i miss your call pls mail me. Position: QlikView consultant with JDE experience Location: Somerset, NJ Duration: 6+ Month Mandatory Skill : JD Edwards 9.1 ERP Overall experience of 8-10 yrs of experience Experience with JD Edwards 9.1 ERP application and knowledge on JDE Modules/Tables Good knowledge of implementation and roll out methodology Good knowledge of following modules of JD Edwards Processes Excellent communication skills Experience of working in onsite/ offshore model Good knowledge of training methodology Good Project management skills Qlik View : Hands on QlikView development experience with high end visualization and experience on QlikSense. Must be experienced in designing, development and deployment using QlikView Must be well experienced in development of QlikView reports, dashboards, QVD generation using QlikView. Experience with JD Edwards 9.1 ERP application and knowledge on JDE Modules/Tables Experience in development of QlikView reports for JD Edwards ERP application using back-end JDE Oracle tables. Good experience in QVD and tuning queries for QVD generation. Strong knowledge on SQL Language Experience in Oracle/SQL Server database Experience in Scheduling QlikVIew Reports as Email, FTP, Shared Folders Required Experience Hands on QlikView development experience with high end visualization and experience on QlikSense. Must be experienced in designing, development and deployment using QlikView Must be well experienced in development of QlikView reports, dashboards, QVD generation using QlikView. Experience with JD Edwards 9.1 ERP application and knowledge on JDE Modules/Tables Experience in development of QlikView reports for JD Edwards ERP application using back-end JDE Oracle tables. Good experience in QVD and tuning queries for QVD generation. Strong knowledge on SQL Language Experience in Oracle/SQL Server database Experience in Scheduling QlikVIew Reports as Email, FTP, Shared Folders Thanks & Regards Sourav Paul | Technical Recruiter IT?SCIENT LLC, Fremont, CA, USA Email: sourav524.itscient at gmail.com Phone: 510-516-7887| Fax: 877-701-5240 |web: www.itscient.com From steve at pearwood.info Tue Jun 28 10:52:22 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 00:52:22 +1000 Subject: Processing text data with different encodings References: <57725ee6$0$1600$c3e8da3$5496439d@news.astraweb.com> <487a4dxgc.ln2@news.c0t0d0s0.de> Message-ID: <57728f27$0$1621$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 10:30 pm, Michael Welle wrote: > I look at the hex values of the bytes, get the win-1252 table and > translate the bytes to chars. If the result makes sense, it's win-1252 > (and maybe others, if the tables overlap). So in that sense I know what > I have. I least for this experiments, when I can control the input. So let me see if I understand what you are doing. You create an input file for testing, let's call it "test.txt". In that test file, you control the input, so you place an ? and save it using Windows-1252 encoding. Then you open the test file and see a byte 0xFC. Then you open an email, encoded using a completely unknown encoding, but claiming to be UTF-8, and see a byte 0xFC. And from this you conclude that the encoding must be Windows-1252 and the unknown character must be ?. Is that right? Maybe I'm misunderstanding you, but frankly from your description I have very little confidence that the unknown encoding is Windows-1252, especially given your earlier comment: "you will find THREE OR FOUR different encodings in one email. I think at the sending side they just glue different text fragments from different sources together without thinking about the encoding" But I'm not going to argue any more. Maybe I've misunderstood you, and what you have done makes perfect sense. Maybe there's only one encoding, 1252, not three or four. Windows-1252 is a very common encoding, so perhaps you are right. The worst that will happen is that you will get mojibake. So I will accept that the encoding is Windows-1252. >>> After applying .decode('windows-1252') and logging it, the log contains >>> a mangled character with hex codes 0xc3 0x20. >> >> I think you are misunderstanding what you are looking at. How are you >> seeing that? 0x20 will be a space in most encodings. > > Again, I used an hex editor and hd. hd? Also known as hexdump? http://www.unix.com/man-page/Linux/1/hd/ I ask because there is also another tool, hdtool, sometimes called hd, used for formatting hard disks. I assume you're not using that :-) >> (1) How are you opening the log file in Python? Do you specify an >> encoding? > > Well, I use the logging module. In my very first posting I didn't > specify an encoding. Later I changed the encoding to utf-8. The details > of opening the log file can be found somewhere in the logging module The mystery 0xC3 0x20 hex codes -- what encoding were you using at the time you logged them? Because there is no way that I can see that you can get 0xC3 0x20 using UTF-8. It is an invalid sequence of bytes. If the logger was using UTF-8, that implies either a bug in the logger, or disk corruption. Are you *sure* it is 0x20? If it were 0xC3 0xBC that would make perfect sense. But 0xC3 0x20 is invalid UTF-8. >> (2) How are you writing to the log file? > > I use the provided functions for writing records with the given > severity. Are you passing it a text string? A bytes string? Something else? >> (3) What are you using to read the log file outside of Python? How do you >> know the hex codes? > > I use emacs, hexlify-mode and hd. Okay. >> I don't know any way you can start with the character ? and write it to a >> file and get bytes 0xc3 0x20. Maybe somebody else will think of >> something, but to me, that seems impossible. That comment still stands. >>> If I do the same with >>> .decode('utf-8'), the result is a working u umlaut with 0xfc in the log. But that is, I think, impossible. You must be misinterpreting what you are seeing, or confusing output in the log when it used a different encoding. py> '?'.encode('utf-8') b'\xc3\xbc' not 0xFC. More to follow... -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From random832 at fastmail.com Tue Jun 28 11:01:37 2016 From: random832 at fastmail.com (Random832) Date: Tue, 28 Jun 2016 11:01:37 -0400 Subject: Processing text data with different encodings In-Reply-To: <57728f27$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <57725ee6$0$1600$c3e8da3$5496439d@news.astraweb.com> <487a4dxgc.ln2@news.c0t0d0s0.de> <57728f27$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1467126097.2528395.650908785.4906EC42@webmail.messagingengine.com> On Tue, Jun 28, 2016, at 10:52, Steven D'Aprano wrote: > "you will find THREE OR FOUR different encodings in one email. > I think at the sending side they just glue different text > fragments from different sources together without thinking > about the encoding" > > But I'm not going to argue any more. Maybe I've misunderstood you Well, given that the other encodings he named were us-ascii and latin-1, I think he was just counting windows-1252 as three different encodings depending on what characters are present, as hyperbole. From steve at pearwood.info Tue Jun 28 11:11:31 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 01:11:31 +1000 Subject: Processing text data with different encodings References: <57725ee6$0$1600$c3e8da3$5496439d@news.astraweb.com> <487a4dxgc.ln2@news.c0t0d0s0.de> Message-ID: <577293a4$0$1606$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 10:30 pm, Michael Welle wrote: > I changed the code from my initial mail to: > > LOGGER = logging.getLogger() > LOGGER.addHandler(logging.FileHandler("tmp.txt", encoding="utf-8")) > > for l in sys.stdin.buffer: > l = l.decode('utf-8') > LOGGER.critical(l) I imagine you're running this over input known to contain UTF-8 text? Because if you run it over your emails with non-UTF8 content, you'll get an exception. I would try this: for l in sys.stdin.buffer: l = l.decode('utf-8', errors='surrogateescape') print(repr(l)) # or log it, whichever you prefer If I try simulating that, you'll see the output: py> buffer = [] py> buffer.append('ab?d\n'.encode('utf-8')) py> buffer.append('ab?d\n'.encode('utf-8')) py> buffer.append('ab?d\n'.encode('latin-1')) py> buffer.append('ab?d\n'.encode('utf-8')) py> buffer [b'ab\xc3\xbcd\n', b'ab\xc3\xbcd\n', b'ab\xfcd\n', b'ab\xc3\xbcd\n'] py> for l in buffer: #sys.stdin.buffer: ... l = l.decode('utf-8', errors='surrogateescape') ... print(repr(l)) ... 'ab?d\n' 'ab?d\n' 'ab\udcfcd\n' 'ab?d\n' See the second last line? The \udcfc code point is a surrogate, encoding the "bad byte" \xfc. See the docs for further details. Alternatively, you could try: for l in sys.stdin.buffer: try: l = l.decode('utf-8', errors='strict') except UnicodeDecodeError: l = l.decode('latin1') # May generate mojibake. print(repr(l)) # or log it, whichever you prefer This version should give satisfactory results if the email actually does contain lines of Latin-1 (or Windows-1252 if you prefer) mixed in with the UTF-8. If not, it will generate mojibake, which may be acceptable to your users. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jun 28 11:20:18 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 01:20:18 +1000 Subject: Iteration, while loop, and for loop References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: <577295b3$0$1598$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 10:36 pm, Elizabeth Weiss wrote: > Why do we use this code if we can use the simpler for loop? Nobody with any sense would use the more complex while loop when the for loop does the same thing. While loops are great for loops where you don't know how many iterations there will be but you do know that you want to keep going while some condition applies: while there is still work to be done: do some more work But if you know how many iterations there will be, use the for loop. Even if you don't know the number ahead of time, if you have a list of them, use a for loop: for each job on my todo list: do the job There is a fashion, driven by "Learn Python The Hard Way", to teach people the while loop first, because it's hard. I think that is stupid. It's like teaching people to fly the Space Shuttle first, then saying "Ok, the Space Shuttle is really complicated, but you can ride a bicycle instead" and then teach them to ride a pushbike. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jun 28 11:22:46 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 01:22:46 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <1467121146.2509341.650815521.254F4174@webmail.messagingengine.com> Message-ID: <57729648$0$22140$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 11:39 pm, Random832 wrote: > On Sun, Jun 26, 2016, at 22:59, Steven D'Aprano wrote: >> We have no way of seeing what goes on past the black hole's event >> horizon, since light cannot escape. But we can still see *some* >> properties of black holes, even through their event horizon: their >> mass, any electric charge they may hold, their angular momentum. > > All objects, not just black holes, have those properties. The point here > is that we are in fact observing those properties of an object that is > not yet (and never will be) a black hole in our frame of reference. So what? You say that as if our frame of reference is privileged. If you hop in your trusty rocket and fly towards the black hole, thinking that it's all fine, its not "really" a black hole because "black holes can't actually form", you'll be in for a really nasty surprise when you cross the event horizon. -- Steven ?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 Jun 28 11:28:53 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 28 Jun 2016 18:28:53 +0300 Subject: Iteration, while loop, and for loop References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> <577295b3$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > While loops are great for loops :) Thanks, I needed the laugh. > where you don't know how many iterations there will be but you do know > that you want to keep going while some condition applies: (Just keeping a bit of context so it doesn't seem like I'm laughing at the intended reading.) From ethan at stoneleaf.us Tue Jun 28 11:29:14 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 28 Jun 2016 08:29:14 -0700 Subject: __all__ attribute: bug and proposal In-Reply-To: References: Message-ID: <577297CA.7000209@stoneleaf.us> On 06/27/2016 09:31 PM, Zachary Ware wrote: > On Mon, Jun 27, 2016 at 7:32 PM, Chris Angelico wrote: >> If you're primarily worried about classes and functions, here's a neat >> trick you can use: >> >> __all__ = [] >> def all(thing): >> __all__.append(thing.__name__) >> return thing > > Barry Warsaw has written a nice decorator called 'public' that can be > installed from PyPI as 'atpublic'[0]. It was proposed for inclusion > as a builtin in 3.6 [1], but a less-than-enthusiastic response at the > 2016 Language Summit has put that off indefinitely. I, for one, would > like to see it happen anyway [2], and public support may make it > possible. > > The '@public' decorator works like so: > > """ > # spam.py > > @public > def spam(): > return ' '.join(['spam']*10) > > @public > def eggs(): > return 'bacon' > > public(HAM=4) > assert HAM == 4 > > assert sorted(__all__) == sorted(['spam', 'eggs', 'HAM']) > """ > > This strikes me as being a cleaner approach than what the OP > suggested, easier to use than Chris' simple decorator, and a nice way > to bring an end to outdated __all__ lists (which is a problem > currently plaguing the standard library, and probably many other > libraries). I agree. But lets all do: from atpublic import public as api as using 'public' for the name is bound to lead to confusion with other languages that use public to mean something else, and __all__ is really defining the public _API_ of that module. -- ~Ethan~ From random832 at fastmail.com Tue Jun 28 11:52:18 2016 From: random832 at fastmail.com (Random832) Date: Tue, 28 Jun 2016 11:52:18 -0400 Subject: Processing text data with different encodings In-Reply-To: References: Message-ID: <1467129138.2539971.650945673.4DB27682@webmail.messagingengine.com> On Tue, Jun 28, 2016, at 06:25, Chris Angelico wrote: > For the OP's situation, frankly, I doubt there'll be anything other > than UTF-8, Latin-1, and CP-1252. The chances that someone casually > mixes CP-1252 with (say) CP-1254 would be vanishingly small. So the > simple decode of "UTF-8, or failing that, 1252" is probably going to > give correct results for most of the content. The trick is figuring > out a correct boundary for the check; line-by-line may be sufficient, > or it may not. For completeness, this can be done character-by-character (i.e. try to decode a UTF-8 character, if it fails decode the offending byte as 1252) with an error handler: import codecs def cp1252_errors(exception): input, idx = exception.object, exception.start byte = input[idx:idx+1] try: return byte.decode('windows-1252'), idx+1 except UnicodeDecodeError: # python's cp1252 doesn't accept 0x81, etc return byte.decode('latin1'), idx+1 codecs.register_error('cp1252', cp1252_errors) assert b"t\xe9st\xc3\xadng".decode('utf-8', errors='cp1252') == "t\u00e9st\u00edng" This is probably sufficient for most purposes; byte sequences that happen to be valid UTF-8 characters but mean something sensible in cp-1252 are rare. Just be fortunate that that's all you have to deal with - the equivalent problem for Japanese encodings, for instance, is much harder (you'd probably want the boundary to be "per run of non-ASCII* characters" if lines don't suffice, and detecting the difference between UTF-8, Shift-JIS, and EUC-JP is nontrivial). There's a reason the word "mojibake" comes from Japanese. *well, JIS X 0201, which is ASCII but for 0x5C and 0x7E. And unless you've got ISO-2022 codes to provide context for that, you've just got to guess what those two bytes mean. Fortunately (fsvo), many environments' fonts display the relevant ASCII characters as their JIS alternatives, taking that choice away from you. From marko at pacujo.net Tue Jun 28 12:36:06 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 19:36:06 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <1467121146.2509341.650815521.254F4174@webmail.messagingengine.com> Message-ID: <87furxnudl.fsf@elektro.pacujo.net> Random832 : > All objects, not just black holes, have those properties. The point > here is that we are in fact observing those properties of an object > that is not yet (and never will be) a black hole in our frame of > reference. A physicist once clarified to me that an almost-black-hole is practically identical with a black hole because all information about anything falling in is very quickly red-shifted to oblivion. However, there is some information that (to my knowledge) is not affected by the red shift. Here's a thought experiment: ---------- / \ / (almost) \ N | black | | | hole | S \ / \ / ---------- We have a stationary, uncharged (almost) black hole in our vicinity and decide to send in a probe. We first align the probe so it is perfectly still wrt the black hole and let it fall in. Inside the probe, we have a powerful electrical magnet that our compass can detect from a safe distance away. The probe is also sending us a steady ping over the radio. As the probe approaches the event horizon, the ping frequency falls drastically and the signal frequency is red-shifted below our ability to receive. However, our compass still points to the magnet and notices that it "floats" on top of the event horizon: ---------- / \ / (almost) \ N | black || | hole |S \ / \ / ---------- / / compass needle / From marko at pacujo.net Tue Jun 28 12:39:47 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 19:39:47 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> Message-ID: <87bn2lnu7g.fsf@elektro.pacujo.net> (sorry for the premature previous post) Random832 : > All objects, not just black holes, have those properties. The point > here is that we are in fact observing those properties of an object > that is not yet (and never will be) a black hole in our frame of > reference. A physicist once clarified to me that an almost-black-hole is practically identical with a black hole because all information about anything falling in is very quickly red-shifted to oblivion. However, there is some information that (to my knowledge) is not affected by the red shift. Here's a thought experiment: ---------- / \ / (almost) \ N | black | | | hole | S \ / \ / ---------- We have a stationary, uncharged (almost) black hole in our vicinity and decide to send in a probe. We first align the probe so it is perfectly still wrt the black hole and let it fall in. Inside the probe, we have a powerful electrical magnet that our compass can detect from a safe distance away. The probe is also sending us a steady ping over the radio. As the probe approaches the event horizon, the ping frequency falls drastically and the signal frequency is red-shifted below our ability to receive. However, our compass still points to the magnet and notices that it "floats" on top of the event horizon: ---------- / \ / (almost) \ N | black || | hole |S \ / \ / ---------- / / compass needle / The compass needle shows that the probe is "frozen" and won't budge no matter how long we wait. Marko From marko at pacujo.net Tue Jun 28 12:41:17 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 19:41:17 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> <87bn2lnu7g.fsf@elektro.pacujo.net> Message-ID: <877fd9nu4y.fsf@elektro.pacujo.net> Marko Rauhamaa : > (sorry for the premature previous post) Screw it! Wrong thread! Marko From marko at pacujo.net Tue Jun 28 12:42:15 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 19:42:15 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <87y45spgsz.fsf@elektro.pacujo.net> <5770968a$0$1589$c3e8da3$5496439d@news.astraweb.com> <1467121146.2509341.650815521.254F4174@webmail.messagingengine.com> Message-ID: <87ziq5mfiw.fsf@elektro.pacujo.net> (sorry for the premature previous post) Random832 : > All objects, not just black holes, have those properties. The point > here is that we are in fact observing those properties of an object > that is not yet (and never will be) a black hole in our frame of > reference. A physicist once clarified to me that an almost-black-hole is practically identical with a black hole because all information about anything falling in is very quickly red-shifted to oblivion. However, there is some information that (to my knowledge) is not affected by the red shift. Here's a thought experiment: ---------- / \ / (almost) \ N | black | | | hole | S \ / \ / ---------- We have a stationary, uncharged (almost) black hole in our vicinity and decide to send in a probe. We first align the probe so it is perfectly still wrt the black hole and let it fall in. Inside the probe, we have a powerful electrical magnet that our compass can detect from a safe distance away. The probe is also sending us a steady ping over the radio. As the probe approaches the event horizon, the ping frequency falls drastically and the signal frequency is red-shifted below our ability to receive. However, our compass still points to the magnet and notices that it "floats" on top of the event horizon: ---------- / \ / (almost) \ N | black || | hole |S \ / \ / ---------- / / compass needle / The compass needle shows that the probe is "frozen" and won't budge no matter how long we wait. Marko From random832 at fastmail.com Tue Jun 28 13:19:03 2016 From: random832 at fastmail.com (Random832) Date: Tue, 28 Jun 2016 13:19:03 -0400 Subject: Assignment Versus Equality In-Reply-To: <87bn2lnu7g.fsf@elektro.pacujo.net> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> <87bn2lnu7g.fsf@elektro.pacujo.net> Message-ID: <1467134343.2558036.651060481.0806DA9A@webmail.messagingengine.com> On Tue, Jun 28, 2016, at 12:39, Marko Rauhamaa wrote: > A physicist once clarified to me that an almost-black-hole is > practically identical with a black hole because all information about > anything falling in is very quickly red-shifted to oblivion. Subject to some definition of "quickly" and "oblivion", I expect. From python.list at tim.thechases.com Tue Jun 28 13:23:08 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 28 Jun 2016 12:23:08 -0500 Subject: Iteration, while loop, and for loop In-Reply-To: <577295b3$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> <577295b3$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160628122308.4578d876@bigbox.christie.dr> On 2016-06-29 01:20, Steven D'Aprano wrote: > While loops are great for loops where you don't know how many > iterations there will be but you do know that you want to keep > going while some condition applies: > > while there is still work to be done: > do some more work I find this particularly the case when the thing being iterated over can be changed, such as a queue of things to process: items = deque() items.append(root_node) while items: item = items.popleft() process(item) items.extend(item.children) Using a "for" loop balks if you try to change the thing over which you're iterating. But then, if you wrap up your "while" loop as a generator that yields things, you can then use it in a "for" loop which seems to me like the Pythonic way to do things. :-) -tkc From grant.b.edwards at gmail.com Tue Jun 28 13:58:52 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 28 Jun 2016 17:58:52 +0000 (UTC) Subject: Iteration, while loop, and for loop References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> <577295b3$0$1598$c3e8da3$5496439d@news.astraweb.com> <20160628122308.4578d876@bigbox.christie.dr> Message-ID: On 2016-06-28, Tim Chase wrote: > On 2016-06-29 01:20, Steven D'Aprano wrote: >> While loops are great for loops where you don't know how many >> iterations there will be but you do know that you want to keep >> going while some condition applies: >> >> while there is still work to be done: >> do some more work > > I find this particularly the case when the thing being iterated over > can be changed, such as a queue of things to process: > > items = deque() > items.append(root_node) > while items: > item = items.popleft() > process(item) > items.extend(item.children) Yep, I often do something similar when processing a block of data bytes comprising a sequence of "things" of varying number of bytes. data = read_a_blob_of_bytes() while data: #figure out how long the first "thing" is len = handle_thing(data[:len]) data = data[len:] > But then, if you wrap up your "while" loop as a generator that yields > things, you can then use it in a "for" loop which seems to me like > the Pythonic way to do things. :-) Yea, I keep telling myself that, but I never actually do it. -- Grant Edwards grant.b.edwards Yow! How do I get HOME? at gmail.com From rosuav at gmail.com Tue Jun 28 14:03:32 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 04:03:32 +1000 Subject: Processing text data with different encodings In-Reply-To: <1467129138.2539971.650945673.4DB27682@webmail.messagingengine.com> References: <1467129138.2539971.650945673.4DB27682@webmail.messagingengine.com> Message-ID: On Wed, Jun 29, 2016 at 1:52 AM, Random832 wrote: > On Tue, Jun 28, 2016, at 06:25, Chris Angelico wrote: >> For the OP's situation, frankly, I doubt there'll be anything other >> than UTF-8, Latin-1, and CP-1252. The chances that someone casually >> mixes CP-1252 with (say) CP-1254 would be vanishingly small. So the >> simple decode of "UTF-8, or failing that, 1252" is probably going to >> give correct results for most of the content. The trick is figuring >> out a correct boundary for the check; line-by-line may be sufficient, >> or it may not. > > For completeness, this can be done character-by-character (i.e. try to > decode a UTF-8 character, if it fails decode the offending byte as 1252) > with an error handler: > > import codecs > > def cp1252_errors(exception): > input, idx = exception.object, exception.start > byte = input[idx:idx+1] > try: > return byte.decode('windows-1252'), idx+1 > except UnicodeDecodeError: > # python's cp1252 doesn't accept 0x81, etc > return byte.decode('latin1'), idx+1 Yeah, and the decision as to where that boundary should be placed is thus completely up to the application. I don't know of any situation where you'd need the byte-by-byte version, but it's there if you want it. The reason I chose line-by-line in my MUD client is because of the nature of MUDs. The server I primarily use is a naive eight-bit one - whatever bytes it gets, it retransmits. (All the commands that it responds to are ASCII, so we can assume that all encodings are ASCII-compatible or the user will have major difficulties.) Some clients (including mine) send UTF-8. If I send the command "trivia This is a piece of text\n", the text will be encoded UTF-8, the server receives those bytes, and then transmit (to everyone who's tuned to the [trivia] channel) this text: "MyName [trivia] This is a piece of text\r\n". Simplistic clients (usually on Windows) will do the same thing, only they'll use their default encoding - usually 1252 - rather than UTF-8. But the entire command will be encoded the same way, which means the server will send an entire line (or several lines, if it wraps) in the same encoding. It's safe to assume that any given line will be in one single encoding, but consecutive lines could be in different encodings. For emails, it might be possible to use a larger section, but line-by-line would be safe there too, most likely. ChrisA From ian.g.kelly at gmail.com Tue Jun 28 14:27:40 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Jun 2016 12:27:40 -0600 Subject: Assignment Versus Equality In-Reply-To: <87bn2lnu7g.fsf@elektro.pacujo.net> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> <87bn2lnu7g.fsf@elektro.pacujo.net> Message-ID: On Tue, Jun 28, 2016 at 10:39 AM, Marko Rauhamaa wrote: > > (sorry for the premature previous post) > > Random832 : >> All objects, not just black holes, have those properties. The point >> here is that we are in fact observing those properties of an object >> that is not yet (and never will be) a black hole in our frame of >> reference. > > A physicist once clarified to me that an almost-black-hole is > practically identical with a black hole because all information about > anything falling in is very quickly red-shifted to oblivion. > > However, there is some information that (to my knowledge) is not > affected by the red shift. Here's a thought experiment: > > ---------- > / \ > / (almost) \ N > | black | | > | hole | S > \ / > \ / > ---------- > > We have a stationary, uncharged (almost) black hole in our vicinity and > decide to send in a probe. We first align the probe so it is perfectly > still wrt the black hole and let it fall in. Inside the probe, we have a > powerful electrical magnet that our compass can detect from a safe > distance away. The probe is also sending us a steady ping over the > radio. > > As the probe approaches the event horizon, the ping frequency falls > drastically and the signal frequency is red-shifted below our ability to > receive. However, our compass still points to the magnet and notices > that it "floats" on top of the event horizon: > > ---------- > / \ > / (almost) \ N > | black || > | hole |S > \ / > \ / > ---------- > > > / > / compass needle > / > > The compass needle shows that the probe is "frozen" and won't budge no > matter how long we wait. I'm skeptical of this. As the ping frequency falls drastically due to relativistic effects, so too does the observed current powering the electromagnet, does it not? From scottpakin1 at gmail.com Tue Jun 28 15:17:06 2016 From: scottpakin1 at gmail.com (scottpakin1 at gmail.com) Date: Tue, 28 Jun 2016 12:17:06 -0700 (PDT) Subject: Sharing package data across files Message-ID: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> I'm trying to create a package in which the constituent files share some state. Apparently, I don't understand scopes, namespaces, and package semantics as well as I thought I did. Here's the directory structure for a simplified example: example/ __init__.py vars.py funcs.py vars.py defines a single variable: foo = 123 funcs.py defines a function that reads and writes that variable: def bar(): global foo foo += 1 return foo __init__.py exposes both of those to the caller: from vars import foo from funcs import bar Alas, it seems the bar function does not reside in the same global scope as the foo variable: >>> from example import foo, bar >>> foo 123 >>> bar() Traceback (most recent call last): File "", line 1, in File "example/funcs.py", line 3, in bar foo += 1 NameError: global name 'foo' is not defined How can I make the example package work like one integrated module even though in reality it's split across multiple files? Thanks, -- Scott From marko at pacujo.net Tue Jun 28 15:40:48 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Jun 2016 22:40:48 +0300 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> <87bn2lnu7g.fsf@elektro.pacujo.net> Message-ID: <87twgdm79b.fsf@elektro.pacujo.net> Ian Kelly : > On Tue, Jun 28, 2016 at 10:39 AM, Marko Rauhamaa wrote: >> Inside the probe, we have a powerful electrical magnet that our >> compass can detect from a safe distance away. >> >> [...] >> >> The compass needle shows that the probe is "frozen" and won't budge no >> matter how long we wait. > > I'm skeptical of this. As the ping frequency falls drastically due to > relativistic effects, so too does the observed current powering the > electromagnet, does it not? Actually, that would be a great question for a physicist to resolve. Next question: would a permanent magnet make any difference? I admit I changed my thought experiment at the last minute to use a magnet instead of a charge because I could more realistically imagine a powerful magnet and a simple detector. That may have been a mistake. A charge, however, would do the "floating" I presume. It's difficult to find a straight answer online. The topic of a charge falling into a black hole is addressed from one angle at: This is from an answer by a guy who says he's got a PhD in general relativity: there's no problem with information falling IN to a black hole, which is allowed to externally display it's mass, charge, angular momentum and linear momentum, all of which get inprinted on the horizon as matter falls in Again, I'd like a physicist to give a straight answer. Marko From zackbaker at gmail.com Tue Jun 28 15:55:30 2016 From: zackbaker at gmail.com (zackbaker at gmail.com) Date: Tue, 28 Jun 2016 12:55:30 -0700 (PDT) Subject: Sharing package data across files In-Reply-To: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> Message-ID: <179a807b-95cf-460c-b971-8b2ee5405d9d@googlegroups.com> On Tuesday, June 28, 2016 at 1:17:23 PM UTC-6, scott... at gmail.com wrote: > I'm trying to create a package in which the constituent files share some state. Apparently, I don't understand scopes, namespaces, and package semantics as well as I thought I did. Here's the directory structure for a simplified example: > > example/ > __init__.py > vars.py > funcs.py > > vars.py defines a single variable: > > foo = 123 > > funcs.py defines a function that reads and writes that variable: > > def bar(): > global foo > foo += 1 > return foo > > __init__.py exposes both of those to the caller: > > from vars import foo > from funcs import bar > > Alas, it seems the bar function does not reside in the same global scope as the foo variable: > > >>> from example import foo, bar > >>> foo > 123 > >>> bar() > Traceback (most recent call last): > File "", line 1, in > File "example/funcs.py", line 3, in bar > foo += 1 > NameError: global name 'foo' is not defined > > How can I make the example package work like one integrated module even though in reality it's split across multiple files? > > Thanks, > -- Scott This problem of references is addressed in: http://stackoverflow.com/questions/710551/import-module-or-from-module-import >From Michael Ray Lovett: For example, if I do this in module a: from foo import bar bar = "oranges" No code outside of a will see bar as "oranges" because my setting of bar merely affected the name "bar" inside module a, it did not "reach into" the foo module object and update its "bar". From gheskett at shentel.net Tue Jun 28 16:59:33 2016 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 28 Jun 2016 16:59:33 -0400 Subject: Assignment Versus Equality In-Reply-To: <87twgdm79b.fsf@elektro.pacujo.net> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <87twgdm79b.fsf@elektro.pacujo.net> Message-ID: <201606281659.33250.gheskett@shentel.net> On Tuesday 28 June 2016 15:40:48 Marko Rauhamaa wrote: > Ian Kelly : > > On Tue, Jun 28, 2016 at 10:39 AM, Marko Rauhamaa wrote: > >> Inside the probe, we have a powerful electrical magnet that our > >> compass can detect from a safe distance away. > >> > >> [...] > >> > >> The compass needle shows that the probe is "frozen" and won't budge > >> no matter how long we wait. > > > > I'm skeptical of this. As the ping frequency falls drastically due > > to relativistic effects, so too does the observed current powering > > the electromagnet, does it not? > > Actually, that would be a great question for a physicist to resolve. > Next question: would a permanent magnet make any difference? > > I admit I changed my thought experiment at the last minute to use a > magnet instead of a charge because I could more realistically imagine > a powerful magnet and a simple detector. That may have been a mistake. > > A charge, however, would do the "floating" I presume. It's difficult > to find a straight answer online. The topic of a charge falling into a > black hole is addressed from one angle at: > > > > > This is from an answer by a guy who says he's got a PhD in general > relativity: > > there's no problem with information falling IN to a black hole, > which is allowed to externally display it's mass, charge, angular > momentum and linear momentum, all of which get inprinted on the > horizon as matter falls in > > http://physics.stackexchange.com/questions/6432/gravitational-r > edshift-of-virtual-photons> > > Again, I'd like a physicist to give a straight answer. > > > Marko I am not a physicist, but consider this: At the event horizon, which is that point where the mass of the probe has become very near infinite because it is moving very very close to the speed of light, time also becomes stretched by the same effect, so that in the probe as it falls thru the event horizon, time is so stretched that for the people in the probe, everything matches up and to them it took perhaps a microsecond to fall past the horizon. But to an external observer, its entirely possible that the probe is frozen at the horizon because the infinite mass prevents the infall from completion for billions of our years. In fact, I'd say that it will eventually sink thru and disappear, but it will do so because the holes event horizon will grow as it absorbs the mass of other things its pulling in, placeing the probe inside the horizon without the probe moving inward. Somewhere in all that math that breaks down inside the event horizon, is probably the reason that well fed black holes are also ejecting matter from their rotational axis, surplus because the event horizon is also subject to the infinite limitation, and because its "stuck" the surplus matter over and above that which creates the event horizon, is ejected from the poles of its spin axis. We have millions of examples of that in the visible universe. Just be glad as can be that we don't have one for a neighbor that could point one of those beams at earth from 10 ly away. Instant planet wide sterilization. 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 johnpote at jptechnical.co.uk Tue Jun 28 18:07:17 2016 From: johnpote at jptechnical.co.uk (John Pote) Date: Tue, 28 Jun 2016 23:07:17 +0100 Subject: Sharing package data across files In-Reply-To: <179a807b-95cf-460c-b971-8b2ee5405d9d@googlegroups.com> References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> <179a807b-95cf-460c-b971-8b2ee5405d9d@googlegroups.com> Message-ID: On 28/06/2016 20:55, zackbaker at gmail.com wrote: > On Tuesday, June 28, 2016 at 1:17:23 PM UTC-6, scott... at gmail.com wrote: >> I'm trying to create a package in which the constituent files share some state. Apparently, I don't understand scopes, namespaces, and package semantics as well as I thought I did. Here's the directory structure for a simplified example: >> >> example/ >> __init__.py >> vars.py >> funcs.py >> >> vars.py defines a single variable: >> >> foo = 123 >> >> funcs.py defines a function that reads and writes that variable: >> >> def bar(): >> global foo >> foo += 1 >> return foo >> >> __init__.py exposes both of those to the caller: >> >> from vars import foo >> from funcs import bar >> >> Alas, it seems the bar function does not reside in the same global scope as the foo variable: >> >> >>> from example import foo, bar >> >>> foo >> 123 >> >>> bar() >> Traceback (most recent call last): >> File "", line 1, in >> File "example/funcs.py", line 3, in bar >> foo += 1 >> NameError: global name 'foo' is not defined >> >> How can I make the example package work like one integrated module even though in reality it's split across multiple files? >> >> Thanks, >> -- Scott > This problem of references is addressed in: > http://stackoverflow.com/questions/710551/import-module-or-from-module-import > > >From Michael Ray Lovett: > For example, if I do this in module a: > > from foo import bar > bar = "oranges" > > No code outside of a will see bar as "oranges" because my setting of bar merely affected the name "bar" inside module a, it did not "reach into" the foo module object and update its "bar". Correct me if I'm wrong but is not the above only true if bar has been assigned to and thus references an imutable object? In your example the string "oranges". If bar has been assigned to a mutable object in module foo then every module importing via "from foo import bar" will all import the name bar pointing to the same mutable object. If this mutable obj is changed via bar in one module then every other module importing bar will also see the change. eg In module foo: bar = ["apples","bananas","grapes"] In module bar1 from foo import bar bar[0] = "oranges" In module barx at some later time from foo import bar ... print bar #prints ["oranges","bananas","grapes"] If my understanding here is correct then this would be a good case for never directly writing to a globle. Use getter()s and setter()s to make it obvious that any use of the setter() will be seen by all future calls to the getter(). Regards all, John From michael.selik at gmail.com Tue Jun 28 18:37:15 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 28 Jun 2016 22:37:15 +0000 Subject: Sharing package data across files In-Reply-To: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> Message-ID: On Tue, Jun 28, 2016 at 3:21 PM wrote: > I'm trying to create a package in which the constituent files share some > state. Apparently, I don't understand scopes, namespaces, and package > semantics as well as I thought I did. Here's the directory structure for a > simplified example: > > example/ > __init__.py > vars.py > funcs.py > > How can I make the example package work like one integrated module even > though in reality it's split across multiple files? > Why do you want to? Isn't easier to have the ``funcs`` module import the ``vars`` module? Even easier, paste all the code into a single file. From scottpakin1 at gmail.com Tue Jun 28 19:51:24 2016 From: scottpakin1 at gmail.com (scottpakin1 at gmail.com) Date: Tue, 28 Jun 2016 16:51:24 -0700 (PDT) Subject: Sharing package data across files In-Reply-To: References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> Message-ID: <346c9c7f-f9fe-4ff7-85ef-60bfe7248821@googlegroups.com> On Tuesday, June 28, 2016 at 4:37:45 PM UTC-6, Michael Selik wrote: > Why do you want to? I have a standalone script that grew and grew until reaching an unmaintainable size. I was hoping to refactor it into a relatively small top-level script plus a package containing a bunch of relatively small files. > Isn't easier to have the ``funcs`` module import the ``vars`` module? Easier, yes. Correct, no: from vars import foo def bar(): global foo foo += 1 return foo which surprisingly (to me, anyway) changes a _copy_ of foo, not the foo I'd think of as belonging to the example package: >>> from example import foo, bar >>> foo 123 >>> bar() 124 >>> foo 123 > Even easier, paste all the code into a single file. That kind of defeats my goal of splitting a single file into more maintainable chunks. Thanks, -- Scott From scottpakin1 at gmail.com Tue Jun 28 20:02:18 2016 From: scottpakin1 at gmail.com (scottpakin1 at gmail.com) Date: Tue, 28 Jun 2016 17:02:18 -0700 (PDT) Subject: Sharing package data across files In-Reply-To: References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> <179a807b-95cf-460c-b971-8b2ee5405d9d@googlegroups.com> Message-ID: <5d68e53a-a4db-479a-b46b-ca24101ab92c@googlegroups.com> On Tuesday, June 28, 2016 at 5:20:16 PM UTC-6, John Pote wrote: > Correct me if I'm wrong but is not the above only true if bar has been > assigned to and thus references an imutable object? In your example the > string "oranges". > If bar has been assigned to a mutable object in module foo then every > module importing via "from foo import bar" will all import the name bar > pointing to the same mutable object. If this mutable obj is changed via > bar in one module then every other module importing bar will also see > the change. > eg > In module foo: > bar = ["apples","bananas","grapes"] > > In module bar1 > from foo import bar > bar[0] = "oranges" > > In module barx at some later time > from foo import bar > ... > print bar #prints ["oranges","bananas","grapes"] That does seem to be the case. Making my example look like the above, with foo being assigned a list and bar mutating the first element of the list, indeed results in foo being updated: >>> from example import foo, bar >>> foo ['apples', 'bananas', 'grapes'] >>> bar() ['oranges', 'bananas', 'grapes'] >>> foo ['oranges', 'bananas', 'grapes'] > If my understanding here is correct then this would be a good case for > never directly writing to a globle. Use getter()s and setter()s to make > it obvious that any use of the setter() will be seen by all future calls > to the getter(). Yeah, it looks like I'll have to do more to my original (big) code than simply partition it into appropriate-sized chunks and drop it into a package directory. Oh, well. Thanks, -- Scott From steve at pearwood.info Tue Jun 28 20:27:10 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 10:27:10 +1000 Subject: Sharing package data across files References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> <179a807b-95cf-460c-b971-8b2ee5405d9d@googlegroups.com> Message-ID: <577315e1$0$1607$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Jun 2016 08:07 am, John Pote wrote: >> from foo import bar >> bar = "oranges" >> >> No code outside of a will see bar as "oranges" because my setting of bar >> merely affected the name "bar" inside module a, it did not "reach into" >> the foo module object and update its "bar". zackbaker at gmail.com's description above is correct. > Correct me if I'm wrong but is not the above only true if bar has been > assigned to and thus references an imutable object? In your example the > string "oranges". No, assignment and importing doesn't know the difference between immutable and mutable objects. Importing works the same way for strings and it does for lists. However, this part is correct: > If bar has been assigned to a mutable object in module foo then every > module importing via "from foo import bar" will all import the name bar > pointing to the same mutable object. If this mutable obj is changed via > bar in one module then every other module importing bar will also see > the change. That's right. Think of it this way: - every module has their own unique NAME "bar", so when a module assigns to bar using `bar = something`, it is only changing the name in its own namespace, it's not reaching into any other namespace; - but there's only one OBJECT being imported, so if that object is mutable, and you mutate it, all modules see the same change in state. In other words, importing does not copy objects, it just creates a new name, in the current namespace, that is bound to that object. If it helps you to think about the underlying C implementation, you can think about pointers to objects: In foo, you have bar pointing to some object: bar ---> OBJ "from foo import bar" creates a new local variable which likewise points to the same OBJ (no copy is made): foo.bar ---> OBJ ^ | a.bar --------+ Assignment changes the pointer, not the thing pointed to: foo.bar ---> OBJ a.bar --------------> "oranges" -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lawrencedo99 at gmail.com Tue Jun 28 20:42:48 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 28 Jun 2016 17:42:48 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <57720e58$0$1530$c3e8da3$5496439d@news.astraweb.com> <3bd25897-8ecb-4a27-ab22-220677551f41@googlegroups.com> <01ed522b-71d6-4535-8d49-b0e32c33ee3a@googlegroups.com> Message-ID: <1b05c0b1-95b6-4b7c-9d2f-a28fcdaaf44d@googlegroups.com> On Tuesday, June 28, 2016 at 10:35:21 PM UTC+12, Chris Angelico wrote: > On Tue, Jun 28, 2016 at 6:49 PM, Lawrence D?Oliveiro wrote: > > On Tuesday, June 28, 2016 at 7:26:30 PM UTC+12, Chris Angelico wrote: >>> Why not: >>> >>> if (error) goto cleanup; >>> ... >>> cleanup: >>> do_cleanup; >> >> They all fall into that same trap. Doesn?t scale. Try one with >> allocation inside a loop, e.g. lines 488 onwards. > > How is that different? You can use a goto inside a for loop just fine. You have my code; show us how you can do better. From steve at pearwood.info Tue Jun 28 20:50:29 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 10:50:29 +1000 Subject: Sharing package data across files References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> <346c9c7f-f9fe-4ff7-85ef-60bfe7248821@googlegroups.com> Message-ID: <57731b57$0$1587$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Jun 2016 09:51 am, scottpakin1 at gmail.com wrote: > On Tuesday, June 28, 2016 at 4:37:45 PM UTC-6, Michael Selik wrote: >> Why do you want to? > > I have a standalone script that grew and grew until reaching an > unmaintainable size. I was hoping to refactor it into a relatively small > top-level script plus a package containing a bunch of relatively small > files. > >> Isn't easier to have the ``funcs`` module import the ``vars`` module? > > Easier, yes. Correct, no: No, you are misinterpreting what you are seeing. The correct answer (for some definition of correct) is to import vars and operate on the attributes of it. Another solution would be to collect related bits of functionality and their variables into classes. Aside: you should reconsider the name "vars", as that shadows the builtin function vars(). This code doesn't work: > from vars import foo > > def bar(): > global foo > foo += 1 > return foo but not for the reason you think. However this will work: import vars def bar(): vars.foo += 1 return vars.foo and that's probably the easiest way to refactor what you have now. But honestly, if your standalone script contains *so many global variables* that you need to do this, that's a code smell. You should rethink your use of global variables, and consider refactoring your code into functions and classes. Just a suggestion. > which surprisingly (to me, anyway) changes a _copy_ of foo, not the foo > I'd think of as belonging to the example package: No, this explanation is incorrect. The object foo is not copied. Python doesn't copy objects unless you explicitly tell it to, usually with the copy module. When you import something from another module, it creates a name in the importer's local namespace: # module vars.py foo = 999 # module spam.py from vars import foo Now there are TWO names "foo". Remember that names are string keys in a dict. We call that a namespace, and there are two of them: the "vars" namespace is the dict vars.__dict__ the "spam" namespace is the dict spam.__dict__ and they BOTH have a key "foo". Obviously they must be different, as otherwise any module that happens to use the same variable names as your module would stomp all over your variables and change their values. So at this point, you have vars.foo = 999 spam.foo = 999 # the SAME object, not a copy Inside the "vars" module, you don't give the fully-qualified name "vars.foo", you just say "foo". And likewise in the "spam" module, you don't give the fully-qualified name "spam.foo" but just say "foo". But don't be fooled, they are *different* foos that just happen to both refer to the same value. When you say spam.foo = 100 # equivalent to spam.foo += 1 obviously spam's foo will change, but vars' foo doesn't. It's in a different namespace, and assignment doesn't reach into different namespaces unless you give the fully-qualified name. (That would be bad.) Inside spam, you don't need to say "spam.foo" (in fact, you can't, unless you first import spam from inside itself, which is weird thing to do). You just say "foo = 100". But conceptually, it is the same. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From scottpakin1 at gmail.com Tue Jun 28 21:24:16 2016 From: scottpakin1 at gmail.com (scottpakin1 at gmail.com) Date: Tue, 28 Jun 2016 18:24:16 -0700 (PDT) Subject: Sharing package data across files In-Reply-To: <57731b57$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <919dae31-1f29-4278-bdad-d3129aa17b64@googlegroups.com> <346c9c7f-f9fe-4ff7-85ef-60bfe7248821@googlegroups.com> <57731b57$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4c47e64b-e648-4130-8328-e780fc869475@googlegroups.com> Steven, Very helpful! Thanks for the thorough explanation. -- Scott From jfong at ms4.hinet.net Tue Jun 28 21:41:21 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 28 Jun 2016 18:41:21 -0700 (PDT) Subject: "for/while ... break(by any means) ... else" make sense? Message-ID: <652b0fd3-7c96-4ff6-8dc0-6e7859c838b2@googlegroups.com> Anyone who wrote the code below must be insane:-) for x in range(3): print(x) else: print('I am done') But here it seems perfectly OK: for x in range(3): print(x) if x == 1: break else: print('I am done') To me, the "else" was bonded with "break" (or return, or raise, or...), not "for". It make sense:-) --Jach From bintacomputers at gmail.com Tue Jun 28 22:04:13 2016 From: bintacomputers at gmail.com (Umar Yusuf) Date: Tue, 28 Jun 2016 19:04:13 -0700 (PDT) Subject: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate. In-Reply-To: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> References: <7d5d9d8a-9c85-433a-b91a-6af3a36fd7ee@googlegroups.com> Message-ID: <89f87d4c-38aa-4a27-9fcd-3916ee59febb@googlegroups.com> Websites to learn python programming? Try these links:- http://umar-yusuf.blogspot.com.ng/2016/03/70-free-python-programming-language.html http://www.sololearn.com/Course/Python/ http://www.afterhoursprogramming.com/tutorial/Python/Overview/ http://www.pyschools.com/ From steve at pearwood.info Tue Jun 28 22:27:50 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 12:27:50 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> Message-ID: <57733227$0$1608$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Jun 2016 12:13 am, Random832 wrote: > On Tue, Jun 28, 2016, at 00:31, Rustom Mody wrote: >> GG downgrades posts containing unicode if it can, thereby increasing >> reach to recipients with unicode-broken clients > > That'd be entirely reasonable, except for the excessively broad > application of "if it can". > > Certainly it _can_ do it all the time. Just replace anything that > doesn't fit with question marks or hex notation or \N{NAME} or some > human readable pseudo-representation a la unidecode. It could have done > any of those with the Hindi that you threw in to try to confound it, (or > it could have chosen ISCII, which likewise lacks arrow characters, as > the encoding to downgrade to). Are you suggesting that email clients and newsreaders should silently mangle the text of your message behind your back? Because that's what it sounds like you're saying. I understand technical limitations. If I'm using a client that can't cope with anything but (say) ISCII or Latin-1, then I'm all out of luck if I want to write an email containing Greek or Cyrillic. I get that. But if the client allows me to type Greek or Cyrillic into the editor, and then accepts that message for sending, and it mangles it into "question marks or hex notation or \N{NAME}" (for example), that's a disgrace and completely unacceptable. Yes, software *is capable of doing so*, in the same way that software is capable of deleting all the vowels from your post, or replacing the word "medieval" with "medireview": http://northernplanets.blogspot.com.au/2007/01/medireview.html This is not a good idea. > It should pick an encoding which it expects recipients to support and > which contains *all* of the characters in the message, That would be UTF-8. That's a no-brainer. Why would you use any other encoding? If you use UTF-8, it just works. It supports the *entire* Unicode character set, which is a superset of virtually all code pages and encodings you are likely to encounter in practice. (No, your software probably isn't running on a 1980s vintage Atari, and if you're in Japan using TRON you've got your own software.) And your text widget or editor surely supports Unicode, because if it didn't, the user couldn't type those Hindi or Greek letters. So there's an obvious, sensible algorithm: - take the user's Unicode text, and encode it to UTF-8 In pseudo-code: content = text.encode('utf-8') And there's the actual algorithm used by mail clients and newsreaders: - take the user's Unicode text, and try encoding it as a variety of different encodings (US-ASCII, Latin-1, maybe a few others); if they fail, then fall back to UTF-8 Or in pseudo-code: list_of_encodings = ['US-ASCII', 'Latin-1', ...] for encoding in list_of_encodings: try: content = text.encode(encoding) break except UnicodeEncodingError: pass else: content = text.encode('utf-8') Why would you write the second instead of the first? It's just *dumb code*. Maybe 20 year old applications could be excused for thinking that this newfangled Unicode thing should be the last resort instead of the code page system, but its 2016 now and code pages are just holding us back. This is *especially* egregious since UTF-8 text containing only ASCII characters is (by design) indistinguishable from US-ASCII, so even if there is some application out there from 1980 that can only cope with ASCII, your UTF-8 email will be perfectly readable to the degree that it only uses "plain text". > as proper > characters and not as pseudo-representations, and downgrade to that if > and only if such an encoding can be found. For most messages, it can use > US-ASCII. For most of the remainder it can use some ISO-8859 or > Windows-125x encoding. There's never any need to downgrade to a non-Unicode encoding, at least not by default. Well, maybe in Asia, I don't know how well Asian software supports Unicode. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jun 28 22:35:57 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 12:35:57 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> Message-ID: <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jun 2016 12:10 am, Rustom Mody wrote: > Analogy: Python's bool as 1?-class because bool came into python a good > decade after python and breaking old code is a bigger issue than fixing > control constructs to be bool-strict That analogy fails because Python bools being implemented as ints is not a bug to be fixed, but a useful feature. There are downsides, of course, but there are also benefits. It comes down to a matter of personal preference whether you think that bools should be abstract True/False values or concrete 1/0 values. Neither decision is clearly wrong, it's a matter of what you value. Whereas some decisions are just dumb: https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/ -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jun 28 22:43:39 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 12:43:39 +1000 Subject: "for/while ... break(by any means) ... else" make sense? References: <652b0fd3-7c96-4ff6-8dc0-6e7859c838b2@googlegroups.com> Message-ID: <577335dc$0$1588$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Jun 2016 11:41 am, jfong at ms4.hinet.net wrote: > Anyone who wrote the code below must be insane:-) > > for x in range(3): > print(x) > else: > print('I am done') *shrug* Insane or not, it's legal. import math pass import os pass import sys is "insane" too, but still legal. The Python interpreter does not judge your code. > But here it seems perfectly OK: > > for x in range(3): > print(x) > if x == 1: break > else: > print('I am done') > > To me, the "else" was bonded with "break" (or return, or raise, or...), > not "for". It make sense:-) Just ten minutes ago I wrote code that looks like this: for x in sequence: try: do_something(x) except Error: continue # try again with the next item break else: default() The "else" in for...else has nothing to do with any "if" inside the for block. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Tue Jun 28 23:52:18 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jun 2016 20:52:18 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <57733227$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> <57733227$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3d06b35d-c437-48e7-916f-16eeae99e8ff@googlegroups.com> On Wednesday, June 29, 2016 at 7:58:04 AM UTC+5:30, Steven D'Aprano wrote: > On Wed, 29 Jun 2016 12:13 am, Random832 wrote: > > > On Tue, Jun 28, 2016, at 00:31, Rustom Mody wrote: > >> GG downgrades posts containing unicode if it can, thereby increasing > >> reach to recipients with unicode-broken clients > > > > That'd be entirely reasonable, except for the excessively broad > > application of "if it can". > > > > Certainly it _can_ do it all the time. Just replace anything that > > doesn't fit with question marks or hex notation or \N{NAME} or some > > human readable pseudo-representation a la unidecode. It could have done > > any of those with the Hindi that you threw in to try to confound it, (or > > it could have chosen ISCII, which likewise lacks arrow characters, as > > the encoding to downgrade to). > > Are you suggesting that email clients and newsreaders should silently mangle > the text of your message behind your back? Because that's what it sounds > like you're saying. > > I understand technical limitations. If I'm using a client that can't cope > with anything but (say) ISCII or Latin-1, then I'm all out of luck if I > want to write an email containing Greek or Cyrillic. I get that. > > But if the client allows me to type Greek or Cyrillic into the editor, and > then accepts that message for sending, and it mangles it into "question > marks or hex notation or \N{NAME}" (for example), that's a disgrace and > completely unacceptable. > > Yes, software *is capable of doing so*, in the same way that software is > capable of deleting all the vowels from your post, or replacing the > word "medieval" with "medireview": > > http://northernplanets.blogspot.com.au/2007/01/medireview.html > > This is not a good idea. Yeah I remember it silently converted ?guillemets? to <> [This is an experiment :-) ] From rustompmody at gmail.com Wed Jun 29 00:03:20 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jun 2016 21:03:20 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <3d06b35d-c437-48e7-916f-16eeae99e8ff@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> <57733227$0$1608$c3e8da3$5496439d@news.astraweb.com> <3d06b35d-c437-48e7-916f-16eeae99e8ff@googlegroups.com> Message-ID: On Wednesday, June 29, 2016 at 9:27:44 AM UTC+5:30, Rustom Mody wrote: > On Wednesday, June 29, 2016 at 7:58:04 AM UTC+5:30, Steven D'Aprano wrote: > > This is not a good idea. > [This is an experiment :-) ] Um... So now its working ie the offensive behavior (to me also) that Steven described is not the case any more?? Or did I mis-remember which characters it mauls and which leaves alone Maybe a ?single guillemet? ? From rosuav at gmail.com Wed Jun 29 00:19:58 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 14:19:58 +1000 Subject: Assignment Versus Equality In-Reply-To: <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jun 29, 2016 at 12:35 PM, Steven D'Aprano wrote: > > Whereas some decisions are just dumb: > > https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/ """It would also be reasonable to assume that any sane language runtime would have integers transparently degrade to BIGNUMs, making the choice of accuracy over speed, but of course that almost never happens...""" Python 2 did this, but Python 3 doesn't. Does this mean that: 1) The performance advantage of native integers is negligible? 2) The performance benefit of having two representations for integers isn't worth the complexity of one data type having two representations? 3) The advantage of merging the types was so great that it was done in the most straight-forward way, and then nobody got around to doing performance testing? 4) Something else? ChrisA From lawrencedo99 at gmail.com Wed Jun 29 00:51:46 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 28 Jun 2016 21:51:46 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> On Wednesday, June 29, 2016 at 4:20:24 PM UTC+12, Chris Angelico wrote: >> https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/ > > """It would also be reasonable to assume that any sane language > runtime would have integers transparently degrade to BIGNUMs, making > the choice of accuracy over speed, but of course that almost never > happens...""" > > Python 2 did this, but Python 3 doesn't. Huh? ldo at theon:~> python3 Python 3.5.1+ (default, Jun 10 2016, 09:03:40) [GCC 5.4.0 20160603] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 2 ** 64 18446744073709551616 >>> type(2 ** 64) From random832 at fastmail.com Wed Jun 29 00:52:36 2016 From: random832 at fastmail.com (Random832) Date: Wed, 29 Jun 2016 00:52:36 -0400 Subject: Assignment Versus Equality In-Reply-To: <57733227$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <576fd6e0$0$1617$c3e8da3$5496439d@news.astraweb.com> <2588c5b2-4b6f-cfbb-f91e-4db03aa50318@icloud.com> <8fbe89a6-c273-0fc9-820b-6ac629e6e769@gmail.com> <02e2d3f4-0198-4cdf-a493-45a248c03aea@googlegroups.com> <577129e0$0$1596$c3e8da3$5496439d@news.astraweb.com> <5771cd54$0$1589$c3e8da3$5496439d@news.astraweb.com> <4805e31e-040d-4caf-a79e-af56f93f6daf@googlegroups.com> <1467123197.2517434.650828881.4491578D@webmail.messagingengine.com> <57733227$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1467175956.1418088.651572697.41212992@webmail.messagingengine.com> On Tue, Jun 28, 2016, at 22:27, Steven D'Aprano wrote: > Are you suggesting that email clients and newsreaders should silently > mangle the text of your message behind your back? Because that's what > it sounds like you're saying. That was how I was characterizing Rustom Mody's position; he seemed to be justifying a supposed "feature" of Google Groups to mangle Unicode arrow characters into ASCII pseudorepresentations such as <- and ->. From rosuav at gmail.com Wed Jun 29 01:07:03 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 15:07:03 +1000 Subject: Assignment Versus Equality In-Reply-To: <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> Message-ID: On Wed, Jun 29, 2016 at 2:51 PM, Lawrence D?Oliveiro wrote: > On Wednesday, June 29, 2016 at 4:20:24 PM UTC+12, Chris Angelico wrote: >>> https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/ >> >> """It would also be reasonable to assume that any sane language >> runtime would have integers transparently degrade to BIGNUMs, making >> the choice of accuracy over speed, but of course that almost never >> happens...""" >> >> Python 2 did this, but Python 3 doesn't. > > Huh? > > ldo at theon:~> python3 > Python 3.5.1+ (default, Jun 10 2016, 09:03:40) > [GCC 5.4.0 20160603] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 2 ** 64 > 18446744073709551616 > >>> type(2 ** 64) > The transparent shift from machine-word to bignum is what no longer exists. Both Py2 and Py3 will store large integers as bignums; Py2 has two separate data types (int and long), with ints generally outperforming longs, but Py3 simply has one (called int, but functionally like Py2's long), and does everything with bignums. There's no longer a boundary - instead, everything gets the "bignum tax". How steep is that tax? I'm not sure, but microbenchmarking shows that there definitely is one. How bad is it in real-world code? No idea. ChrisA From steve+comp.lang.python at pearwood.info Wed Jun 29 01:26:32 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 15:26:32 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> Message-ID: <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> On Wednesday 29 June 2016 14:51, Lawrence D?Oliveiro wrote: > On Wednesday, June 29, 2016 at 4:20:24 PM UTC+12, Chris Angelico wrote: >>> https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and- stupid/ >> >> """It would also be reasonable to assume that any sane language >> runtime would have integers transparently degrade to BIGNUMs, making >> the choice of accuracy over speed, but of course that almost never >> happens...""" >> >> Python 2 did this, but Python 3 doesn't. > > Huh? Chris is referring to the fact that in Python 2, there were two distinct integer types, int and long. Originally they were entirely independent, and int overflow would give you an exception: # Python 1.5 >>> type(2147483647) >>> 2147483647 + 1 Traceback (innermost last): File "", line 1, in ? OverflowError: integer addition To do BIGNUM arithmetic, you needed to explicitly specify at least one argument was a long: >>> 2147483647 + 1L 2147483648L but from about 2.4 or thereabouts, Python would automatically promote ints to longs when a calculation got too big: # Python 2.7, 32-bit build py> type(2147483647) py> type(2147483647 + 1) which is the behaviour JMZ is referring to. BUT in Python 3, the distinction between int and long is gone by dropping int and renaming long as "int". So all Python ints are BIGNUMs. In principle Python might use native 32 or 64 bit ints for small values and secretly promote them to BIGNUMs when needed, but as far as I know no implementation of Python currently does this. -- Steve From lawrencedo99 at gmail.com Wed Jun 29 01:51:49 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 28 Jun 2016 22:51:49 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> Message-ID: <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> On Wednesday, June 29, 2016 at 5:26:46 PM UTC+12, Steven D'Aprano wrote: > BUT in Python 3, the distinction between int and long is gone by dropping > int and renaming long as "int". So all Python ints are BIGNUMs. I don?t understand what the problem is with this. Is there supposed to be some issue with performance? Because I can?t see it. From rustompmody at gmail.com Wed Jun 29 01:55:53 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jun 2016 22:55:53 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> Message-ID: <26418be9-3d0c-4389-99e0-785efc9b88df@googlegroups.com> On Wednesday, June 29, 2016 at 10:37:25 AM UTC+5:30, Chris Angelico wrote: > On Wed, Jun 29, 2016 at 2:51 PM, Lawrence D?Oliveiro wrote: > > On Wednesday, June 29, 2016 at 4:20:24 PM UTC+12, Chris Angelico wrote: > >>> https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/ > >> > >> """It would also be reasonable to assume that any sane language > >> runtime would have integers transparently degrade to BIGNUMs, making > >> the choice of accuracy over speed, but of course that almost never > >> happens...""" > >> > >> Python 2 did this, but Python 3 doesn't. > > > > Huh? > > > > ldo at theon:~> python3 > > Python 3.5.1+ (default, Jun 10 2016, 09:03:40) > > [GCC 5.4.0 20160603] on linux > > Type "help", "copyright", "credits" or "license" for more information. > > >>> 2 ** 64 > > 18446744073709551616 > > >>> type(2 ** 64) > > > > The transparent shift from machine-word to bignum is what no longer > exists. Both Py2 and Py3 will store large integers as bignums; Py2 has > two separate data types (int and long), with ints generally > outperforming longs, but Py3 simply has one (called int, but > functionally like Py2's long), and does everything with bignums. > There's no longer a boundary - instead, everything gets the "bignum > tax". How steep is that tax? I'm not sure, but microbenchmarking shows > that there definitely is one. How bad is it in real-world code? No > idea. > > ChrisA New to me -- thanks. I thought it did an FSR type covert machine word ? BigInt conversion under the hood. Tax is one question Justification for this change is another From lawrencedo99 at gmail.com Wed Jun 29 01:58:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 28 Jun 2016 22:58:22 -0700 (PDT) Subject: Iteration, while loop, and for loop In-Reply-To: References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> Message-ID: <96056410-118f-4bd9-8666-feed4b0f7bb3@googlegroups.com> On Wednesday, June 29, 2016 at 1:30:04 AM UTC+12, BartC wrote: > I don't know if that helps; I've never heard of an induction variable. Perhaps it?s just a computability-theoretic way of saying ?a variable whose value each time round the loop is a function of its value on the previous iteration?. From rosuav at gmail.com Wed Jun 29 02:26:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 16:26:46 +1000 Subject: Assignment Versus Equality In-Reply-To: <26418be9-3d0c-4389-99e0-785efc9b88df@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <26418be9-3d0c-4389-99e0-785efc9b88df@googlegroups.com> Message-ID: On Wed, Jun 29, 2016 at 3:55 PM, Rustom Mody wrote: >> The transparent shift from machine-word to bignum is what no longer >> exists. Both Py2 and Py3 will store large integers as bignums; Py2 has >> two separate data types (int and long), with ints generally >> outperforming longs, but Py3 simply has one (called int, but >> functionally like Py2's long), and does everything with bignums. >> There's no longer a boundary - instead, everything gets the "bignum >> tax". How steep is that tax? I'm not sure, but microbenchmarking shows >> that there definitely is one. How bad is it in real-world code? No >> idea. >> >> ChrisA > > New to me -- thanks. > I thought it did an FSR type covert machine word ? BigInt conversion under the hood. > Tax is one question > Justification for this change is another CPython doesn't currently do anything like that, but it would be perfectly possible to do it invisibly, and thus stay entirely within the language spec. I'm not aware of any Python implementation that does this, but it wouldn't surprise me if PyPy has some magic like that. It's PyPy's kind of thing. It's also entirely possible that a future CPython will have this kind of optimization too. It all depends on someone doing the implementation work and then proving that it's worth the complexity. ChrisA From rustompmody at gmail.com Wed Jun 29 02:33:16 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jun 2016 23:33:16 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <26418be9-3d0c-4389-99e0-785efc9b88df@googlegroups.com> Message-ID: <18a098a5-5b85-4444-963c-5993c882eefa@googlegroups.com> On Wednesday, June 29, 2016 at 11:57:03 AM UTC+5:30, Chris Angelico wrote: > On Wed, Jun 29, 2016 at 3:55 PM, Rustom Mody wrote: > >> The transparent shift from machine-word to bignum is what no longer > >> exists. Both Py2 and Py3 will store large integers as bignums; Py2 has > >> two separate data types (int and long), with ints generally > >> outperforming longs, but Py3 simply has one (called int, but > >> functionally like Py2's long), and does everything with bignums. > >> There's no longer a boundary - instead, everything gets the "bignum > >> tax". How steep is that tax? I'm not sure, but microbenchmarking shows > >> that there definitely is one. How bad is it in real-world code? No > >> idea. > >> > >> ChrisA > > > > New to me -- thanks. > > I thought it did an FSR type covert machine word ? BigInt conversion under the hood. > > Tax is one question > > Justification for this change is another > > CPython doesn't currently do anything like that, but it would be > perfectly possible to do it invisibly, and thus stay entirely within > the language spec. I'm not aware of any Python implementation that > does this, but it wouldn't surprise me if PyPy has some magic like > that. It's PyPy's kind of thing. > > It's also entirely possible that a future CPython will have this kind > of optimization too. It all depends on someone doing the > implementation work and then proving that it's worth the complexity. > > ChrisA Huh? I though I was just describing python2's behavior: $ python Python 2.7.11+ (default, Apr 17 2016, 14:00:29) [GCC 5.3.1 20160413] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x=2 >>> type(x) >>> y=x ** 80 >>> y 1208925819614629174706176L >>> type(y) From rustompmody at gmail.com Wed Jun 29 02:37:41 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jun 2016 23:37:41 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <18a098a5-5b85-4444-963c-5993c882eefa@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <26418be9-3d0c-4389-99e0-785efc9b88df@googlegroups.com> <18a098a5-5b85-4444-963c-5993c882eefa@googlegroups.com> Message-ID: <1a0ab22c-c54e-43de-a0f5-908b436bd8d0@googlegroups.com> On Wednesday, June 29, 2016 at 12:03:30 PM UTC+5:30, Rustom Mody wrote: > On Wednesday, June 29, 2016 at 11:57:03 AM UTC+5:30, Chris Angelico wrote: > > On Wed, Jun 29, 2016 at 3:55 PM, Rustom Mody wrote: > > >> The transparent shift from machine-word to bignum is what no longer > > >> exists. Both Py2 and Py3 will store large integers as bignums; Py2 has > > >> two separate data types (int and long), with ints generally > > >> outperforming longs, but Py3 simply has one (called int, but > > >> functionally like Py2's long), and does everything with bignums. > > >> There's no longer a boundary - instead, everything gets the "bignum > > >> tax". How steep is that tax? I'm not sure, but microbenchmarking shows > > >> that there definitely is one. How bad is it in real-world code? No > > >> idea. > > >> > > >> ChrisA > > > > > > New to me -- thanks. > > > I thought it did an FSR type covert machine word ? BigInt conversion under the hood. > > > Tax is one question > > > Justification for this change is another > > > > CPython doesn't currently do anything like that, but it would be > > perfectly possible to do it invisibly, and thus stay entirely within > > the language spec. I'm not aware of any Python implementation that > > does this, but it wouldn't surprise me if PyPy has some magic like > > that. It's PyPy's kind of thing. > > > > It's also entirely possible that a future CPython will have this kind > > of optimization too. It all depends on someone doing the > > implementation work and then proving that it's worth the complexity. > > > > ChrisA > > Huh? I though I was just describing python2's behavior: > > $ python > Python 2.7.11+ (default, Apr 17 2016, 14:00:29) > [GCC 5.3.1 20160413] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> x=2 > >>> type(x) > > >>> y=x ** 80 > >>> y > 1208925819614629174706176L > >>> type(y) > Um ok I see the ...L there at the end of 2 ** 80 So its not exactly 'under the hood' From steve+comp.lang.python at pearwood.info Wed Jun 29 02:45:51 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 16:45:51 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> Message-ID: <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> On Wednesday 29 June 2016 15:51, Lawrence D?Oliveiro wrote: > On Wednesday, June 29, 2016 at 5:26:46 PM UTC+12, Steven D'Aprano wrote: >> BUT in Python 3, the distinction between int and long is gone by dropping >> int and renaming long as "int". So all Python ints are BIGNUMs. > > I don?t understand what the problem is with this. Is there supposed to be > some issue with performance? Because I can?t see it. If there is a performance hit, it's probably pretty small. It may have been bigger back in Python 3.0 or 3.1. [steve at ando ~]$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n += i" 100 loops, best of 3: 1.87 msec per loop [steve at ando ~]$ python3.3 -m timeit -s "n = 0" "for i in range(10000): n += i" 1000 loops, best of 3: 1.89 msec per loop Although setting debugging options does make it pretty slow: [steve at ando ~]$ python/python-dev/3.6/python -m timeit -s "n = 0" "for i in range(10000): n += i" 100 loops, best of 3: 13.7 msec per loop -- Steve From lawrencedo99 at gmail.com Wed Jun 29 04:07:16 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 29 Jun 2016 01:07:16 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wednesday, June 29, 2016 at 6:46:04 PM UTC+12, Steven D'Aprano wrote: > On Wednesday 29 June 2016 15:51, Lawrence D?Oliveiro wrote: > >> On Wednesday, June 29, 2016 at 5:26:46 PM UTC+12, Steven D'Aprano wrote: >>> BUT in Python 3, the distinction between int and long is gone by dropping >>> int and renaming long as "int". So all Python ints are BIGNUMs. >> >> I don?t understand what the problem is with this. Is there supposed to be >> some issue with performance? Because I can?t see it. > > If there is a performance hit, it's probably pretty small. It may have been > bigger back in Python 3.0 or 3.1. > > [steve at ando ~]$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n += i" > 100 loops, best of 3: 1.87 msec per loop > > [steve at ando ~]$ python3.3 -m timeit -s "n = 0" "for i in range(10000): n += i" > 1000 loops, best of 3: 1.89 msec per loop Here is what I tried: ldo at theon:python_try> python2 int_speed_test.py 2 ** 6 is 2 ** 6: True 1000000 iterations of ?a = 2 ** 6 // 2 ** 4? took 0.0624719s = 6.24719e-08s/iteration 2 ** 9 is 2 ** 9: False 1000000 iterations of ?a = 2 ** 9 // 2 ** 6? took 0.0506701s = 5.06701e-08s/iteration 2 ** 20 is 2 ** 20: False 1000000 iterations of ?a = 2 ** 20 // 2 ** 12? took 0.0441589s = 4.41589e-08s/iteration 2 ** 64 is 2 ** 64: False 1000000 iterations of ?a = 2 ** 64 // 2 ** 32? took 0.138092s = 1.38092e-07s/iteration 2 ** 96 is 2 ** 96: False 1000000 iterations of ?a = 2 ** 96 // 2 ** 64? took 0.1142s = 1.142e-07s/iteration ldo at theon:python_try> python3 int_speed_test.py 2 ** 6 is 2 ** 6: True 1000000 iterations of ?a = 2 ** 6 // 2 ** 4? took 0.0230309s = 2.30309e-08s/iteration 2 ** 9 is 2 ** 9: False 1000000 iterations of ?a = 2 ** 9 // 2 ** 6? took 0.0231234s = 2.31234e-08s/iteration 2 ** 20 is 2 ** 20: False 1000000 iterations of ?a = 2 ** 20 // 2 ** 12? took 0.020053s = 2.0053e-08s/iteration 2 ** 64 is 2 ** 64: False 1000000 iterations of ?a = 2 ** 64 // 2 ** 32? took 0.0182259s = 1.82259e-08s/iteration 2 ** 96 is 2 ** 96: False 1000000 iterations of ?a = 2 ** 96 // 2 ** 64? took 0.0173797s = 1.73797e-08s/iteration As you can see, Python 3 is actually *faster* than Python 2, particularly with smaller-magnitude integers. From rosuav at gmail.com Wed Jun 29 04:09:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 18:09:42 +1000 Subject: Assignment Versus Equality In-Reply-To: <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Jun 29, 2016 at 4:45 PM, Steven D'Aprano wrote: > On Wednesday 29 June 2016 15:51, Lawrence D?Oliveiro wrote: > >> On Wednesday, June 29, 2016 at 5:26:46 PM UTC+12, Steven D'Aprano wrote: >>> BUT in Python 3, the distinction between int and long is gone by dropping >>> int and renaming long as "int". So all Python ints are BIGNUMs. >> >> I don?t understand what the problem is with this. Is there supposed to be >> some issue with performance? Because I can?t see it. > > If there is a performance hit, it's probably pretty small. It may have been > bigger back in Python 3.0 or 3.1. > > [steve at ando ~]$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n += i" > 100 loops, best of 3: 1.87 msec per loop > > [steve at ando ~]$ python3.3 -m timeit -s "n = 0" "for i in range(10000): n += i" > 1000 loops, best of 3: 1.89 msec per loop > > > Although setting debugging options does make it pretty slow: > > [steve at ando ~]$ python/python-dev/3.6/python -m timeit -s "n = 0" "for i in > range(10000): n += i" > 100 loops, best of 3: 13.7 msec per loop That's not necessarily fair - you're comparing two quite different Python interpreters, so there might be something entirely different that counteracts the integer performance. (For example: You're creating and disposing of large numbers of objects, so the performance of object creation could affect things hugely.) To make it somewhat fairer, add long integer performance to the mix. Starting by redoing your test: rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n += i" 10000 loops, best of 3: 192 usec per loop rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 1<<100" "for i in xrange(10000): n += i" 1000 loops, best of 3: 478 usec per loop rosuav at sikorsky:~$ python3.4 -m timeit -s "n = 0" "for i in range(10000): n += i" 1000 loops, best of 3: 328 usec per loop rosuav at sikorsky:~$ python3.4 -m timeit -s "n = 1<<100" "for i in range(10000): n += i" 1000 loops, best of 3: 337 usec per loop rosuav at sikorsky:~$ python3.5 -m timeit -s "n = 0" "for i in range(10000): n += i" 1000 loops, best of 3: 369 usec per loop rosuav at sikorsky:~$ python3.5 -m timeit -s "n = 1<<100" "for i in range(10000): n += i" 1000 loops, best of 3: 356 usec per loop rosuav at sikorsky:~$ python3.6 -m timeit -s "n = 0" "for i in range(10000): n += i" 1000 loops, best of 3: 339 usec per loop rosuav at sikorsky:~$ python3.6 -m timeit -s "n = 1<<100" "for i in range(10000): n += i" 1000 loops, best of 3: 343 usec per loop (On this system, python3.4 and python3.5 are Debian-shipped builds of CPython, and python3.6 is one I compiled from hg today. There's no visible variance between them, but just in case. I don't have a python3.3 on here for a fair comparison with your numbers, sorry.) The way I read this, Python 2.7 is noticeably slower with bignums, but visibly faster with machine words. Python 3, on the other hand, has consistent performance whether the numbers fit within a machine word or not - which is to be expected, since it uses bignums for all integers. PyPy's performance shows an even more dramatic gap: rosuav at sikorsky:~$ pypy -m timeit -s "n = 0" "for i in xrange(10000): n += i" 100000 loops, best of 3: 7.59 usec per loop rosuav at sikorsky:~$ pypy -m timeit -s "n = 1<<100" "for i in xrange(10000): n += i" 10000 loops, best of 3: 119 usec per loop rosuav at sikorsky:~$ pypy --version Python 2.7.10 (5.1.2+dfsg-1, May 17 2016, 18:03:30) [PyPy 5.1.2 with GCC 5.3.1 20160509] Sadly, Debian doesn't ship a pypy3 yet, so for consistency, I picked up the latest available pypy2 and pypy3 from pypy.org. rosuav at sikorsky:~/tmp$ pypy2-v5.3.1-linux64/bin/pypy -m timeit -s "n = 0" "for i in xrange(10000): n += i" 100000 loops, best of 3: 7.58 usec per loop rosuav at sikorsky:~/tmp$ pypy2-v5.3.1-linux64/bin/pypy -m timeit -s "n = 1<<100" "for i in xrange(10000): n += i" 10000 loops, best of 3: 115 usec per loop rosuav at sikorsky:~/tmp$ pypy3.3-v5.2.0-alpha1-linux64/bin/pypy3 -m timeit -s "n = 0" "for i in range(10000): n += i" 100000 loops, best of 3: 7.56 usec per loop rosuav at sikorsky:~/tmp$ pypy3.3-v5.2.0-alpha1-linux64/bin/pypy3 -m timeit -s "n = 1<<100" "for i in range(10000): n += i" 10000 loops, best of 3: 115 usec per loop Performance comparable to each other (and to the Debian-shipped one, which is nice - as Adam Savage said, I love consistent data!), and drastically different between machine words and bignums. So it looks like PyPy *does* have some sort of optimization going on here, without ever violating the language spec. ChrisA From setivolkylany at gmail.com Wed Jun 29 05:25:00 2016 From: setivolkylany at gmail.com (Seti Volkylany) Date: Wed, 29 Jun 2016 02:25:00 -0700 (PDT) Subject: I need a pure python module from PyPI without additional packages on my OS. Message-ID: <3b88728b-463e-4a00-b2d9-23d1ae7ab570@googlegroups.com> I heard about cairo, but it required installed on my computer before. From steve+comp.lang.python at pearwood.info Wed Jun 29 05:35:09 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 19:35:09 +1000 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> Message-ID: <57739650$0$1601$c3e8da3$5496439d@news.astraweb.com> On Sunday 26 June 2016 09:40, Gregory Ewing wrote: > Marko Rauhamaa wrote: >> pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange): >> >>>Near a black hole 3.7 seconds can last an infinite time... >> >> Which phenomenon prevents a black hole from ever forming. Yet >> astronomers keep telling us they are all over the place. > > Astronomers have observed objects whose behaviour is > entirely consistent with the existence of black holes > as predicted by general relativity. Indeed. There's a common myth going around that black holes take an infinite amount of time to form, or another way of putting it is that it takes an infinite amount of time for something to fall into a black hole, and therefore "black holes can't really exist". This myth comes about because people don't fully understand the (admittedly mind-boggling) implications of General Relativity. First, you must accept that *your* experiences are not the only valid experiences. Just because *you* never see the black hole form, doesn't mean it doesn't form. You just don't get to experience it yourself. So, let's consider a thought experiment. Imagine three astronauts, Tim, Bill and Graham ("we do anything, anytime"). Tim and Graham are in separate space ships, dropping straight towards a black hole under free fall. Bill is watching them from a safely orbiting space station. Graham drops towards the black hole, as does Tim. Neither can see the black hole directly, or at least they can't see the *inside* of the black hole, since no light can escape it, but they can see it by its effect on the starlight: the black hole acts like a great big lens, bending light. If they line up their space ships with the black hole directly between them and a distant star, they will see one of the more amazing sights of the universe: gravitational lensing. The (somewhat reddened) light from the star will be bent around the black hole, so that the star will appear to be a donut of light with a black centre. As Graham falls, he pays close attention to the distance from his ship to the black hole. That's easy to do: he can tell how fast he is going thanks to Bill's space station, which transmits a steady radio signal for him, a steady clock sending one pulse per second.[1] But as Graham gets closer and closer to the event horizon, he notices Bill's radio signals have a higher and higher frequency, and appear to be sped up... at the end, just before he loses his nerve and fires the retro-rockets before crossing the event horizon, the signals are coming thousands of pulses per second. When Graham returns to the space station, he finds a *much* older Bill waiting for him. Bill insists he was sending one pulse per second, as agreed, but that Graham has been gone for many years. Graham insists that he has only been gone a few days, and Bill has obviously been partying very hard indeed to look like this after such a short time. But after sitting down with Albert Einstein's head[2], they reconcile their two differing experiences: As seen by Bill, in Bill's frame of reference far from the black hole, Graham's experiences have been slowed down enormously. But Graham sees things differently: he experiences his own frame of reference at the same speed he always has, and see's *Bill's* frame of reference as being immensely sped up. Neither is "right" and the other is "wrong", neither frame of reference is privileged over the other. BOTH are right, even though they contradict each other. That's the nature of the universe we live in. What about Tim? Tim is so engrossed by the view of the gravitational lensing that he forgets to fire the retro-rockets, and before he knows it, he's crossed the event horizon and there's no going back. For a sufficiently large black hole, he might not even have noticed the transition. From his perspective, he's still distant from the singularity (being so small and distant, he can't quite make out what it looks like), and space-time is still quite flat for a sufficiently large black hole. Tim can still see out, although the incoming light is getting bluer, and he's still receiving Bill's clock signals, though like Graham he sees them as drastically sped up. If Tim has sufficiently powerful rockets with enough fuel, he could *not quite* escape: he could change his space ship's trajectory enough to avoid the hypothetical singularity for days, weeks, years, as long as the fuel lasts. But nothing he can do will allow him to escape the event horizon. (Well, maybe faster-than-light travel, if his hyperdrive will still work this close to a black hole.) And as invariably as tomorrow follows today, he's getting closer to the supposed singularity, and long before he reaches it, both Tim and his space ship will be torn apart into atoms by the ever-increasing tidal forces, and then even the atoms torn apart. And then, well we really have no idea what happens if you try to squeeze an electron into a volume of space a trillion times smaller than a sphere with radius equal to the Planck Length... Should Tim realise his fate, and decide that there's no point delaying the inevitable, his free-fall drop into the supposed singularity will be over in a relatively short amount of time, at least according to his own frame of reference. (For a stellar size black hole, the time from crossing the event horizon to reaching the supposed singularity is a small fraction of a second.) For a large black hole where the Schwartzchild Radius is 1 a.u., and ignoring any relativistic corrections, it will take Tim six months of free fall to collide with the singularity. During that time he will have plenty of time to reflex on the curious way that Bill's space station is running faster and faster, sending clock ticks millions of times a second. (At least until he is torn apart by tidal forces.) Meanwhile, back on Bill's space station, they're still faithfully sending out radio pulses at the rate of one per second. By looking in their most powerful telescopes, they can see Tim's spaceship falling into the black hole, strangely slowing down as it approaches, the light getting redder and redder, Tim's own radio signals getting further and further apart. Tim's spaceship appears to be *asymptotically* approaching the event horizon, in some sort of horrible version of Zeno's Paradoxes: each minute that goes by, Tim gets closer to the event horizon by a *smaller* amount as time slows down for him (as seen by Bill and Graham on the space station). Graham decides to mount a rescue mission. He flies back towards the black hole, and experiences the same speeding up of signals coming from Bill. But no matter how closely he approaches the event horizon, Tim always appears to ahead of him, like the turtle to Achilles (from Graham's frame of reference). As seen by Bill, the closer Graham gets to Tim, the slower he appears to be experiencing time, with his return clock ticks coming back one a day instead of one per second, then one a week, one a month, ... Unless Graham is willing to cross the event horizon too, he cannot catch up to Tim. That's because, from Tim's perspective, Graham left the space station too late. Tim has already experienced crossing the event horizon, so unless Graham has a time machine, there's nothing Graham can do to reach Tim before he crosses the event horizon. No matter how close Graham gets to the event horizon, Tim will already be just a bit closer. Unless Graham is suicidally willing to cross the event horizon too, he's going to have to pull out (after, from his perspective, perhaps as little as a few hours of high-acceleration), and return to the space station, where he will find that Bill has experienced possibly many thousands of years. So whose viewpoint is right? According to Bill and Graham, Tim is frozen just before the event horizon, infinitely red-shifted, his radio signals coming in infinitely slowly. But according to Tim, the opportunity for rescue is long gone. He long ago watched Graham's idiotic rescue mission ("don't bother Graham, I'm well past the event horizon, you can't save me now..."), the daring flight almost to the event horizon, and Graham's eventual return to the space station. Although their perspectives are very different, neither is "more right" than the other. So does the black hole form? Do objects cross the event horizon? From the frame of reference of such objects, yes, certainly, and in a fairly short period of time too. From our frame of reference, we seem them asymptotically approaching the event horizon, but never cross it. Both are equally correct. [1] Or very possibly playing "A Walk In The Black Forest". [2] In a jar. -- Steve From bc at freeuk.com Wed Jun 29 05:49:06 2016 From: bc at freeuk.com (BartC) Date: Wed, 29 Jun 2016 10:49:06 +0100 Subject: Assignment Versus Equality In-Reply-To: <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> Message-ID: On 29/06/2016 06:26, Steven D'Aprano wrote: > > BUT in Python 3, the distinction between int and long is gone by dropping int > and renaming long as "int". So all Python ints are BIGNUMs. > > In principle Python might use native 32 or 64 bit ints for small values and > secretly promote them to BIGNUMs when needed, but as far as I know no > implementation of Python currently does this. Presumably the implementation of BIGNUMs would already do something like this: a number that fits into 64 bits would only use 64 bits. The overheads of dealing with both small BIGNUMs and big ones, or a mix, might be lost in the other overheads of CPython. But I remember when playing with my tokeniser benchmarks earlier this year that switching from dealing with strings, to integers, didn't make things much faster (I think they actually made it slower sometimes). Even if Python has extremely efficient string handling, we know that low-level string ops normally take longer than low-level integer ops. So maybe small-integer handling already had enough overhead that implementing them as small BIGNUMs didn't make much difference, but it simplified the language. -- Bartc From lawrencedo99 at gmail.com Wed Jun 29 05:56:10 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 29 Jun 2016 02:56:10 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> Message-ID: <631d492c-ef1d-4089-a8be-b967c8f72b4c@googlegroups.com> On Wednesday, June 29, 2016 at 9:49:23 PM UTC+12, BartC wrote: > Even if Python has extremely efficient string handling, we know that > low-level string ops normally take longer than low-level integer ops. Maybe part of the general principle that, on modern machines, memory is cheap, but accessing memory is expensive? From victor.nicolae.savu at gmail.com Wed Jun 29 06:01:03 2016 From: victor.nicolae.savu at gmail.com (Victor Savu) Date: Wed, 29 Jun 2016 10:01:03 +0000 Subject: "for/while ... break(by any means) ... else" make sense? Message-ID: There are many posts trying to explain the else after for or while. Here is my take on it: There are three ways of getting out of a (for/while) loop: throw, break or the iterator gets exhausted. The question is, how cab we tell which way we exited? For the throw, we have the except clause. This leaves us to differentiatr between break and normal exhaustion of the iterator. This is that the else clause is for: we enter the body iff the loop iterator was exhausted. A lot of discussion goes around the actual keyword used: else. Opinions may differ, but I for one would have chosen 'then' as a keyword to mark something that naturally happens as part of the for statement but after the looping is over; assuming break jumps out of the entire statement, it makes sense that it skips the 'then' body as well. (In the same way, I prefer 'catch' to 'except' as a correspondent to 'throw', but all of this is just bikeshedding). At a language design level, the decision was made to reuse one of the existing keywords and for better or worse, 'else' was chosen, which can be thought of as having no relation to the other use of the same keyword in the 'if' statement. The only rationale behind this was to save one keyword. The search analogy often used for justifying 'else' is (to me) totally bogus, since the same argument can be used to support replacing the keyword 'for' by the keyword 'find' and have looping only as a side-effect of a search. I hope this gives you some sense of closure. Best, VS From bc at freeuk.com Wed Jun 29 06:10:34 2016 From: bc at freeuk.com (BartC) Date: Wed, 29 Jun 2016 11:10:34 +0100 Subject: Assignment Versus Equality In-Reply-To: <631d492c-ef1d-4089-a8be-b967c8f72b4c@googlegroups.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <631d492c-ef1d-4089-a8be-b967c8f72b4c@googlegroups.com> Message-ID: On 29/06/2016 10:56, Lawrence D?Oliveiro wrote: > On Wednesday, June 29, 2016 at 9:49:23 PM UTC+12, BartC wrote: >> Even if Python has extremely efficient string handling, we know that >> low-level string ops normally take longer than low-level integer ops. > > Maybe part of the general principle that, on modern machines, memory is cheap, but accessing memory is expensive? > No, it's just fewer instructions. If you do the equivalent of a==b where both are integers, it might be a couple of instructions in native code. If both are strings, even of one character each (say the code is choosing to compare "A" with "B" instead of ord("A") with ord("B"), then it's a /lot/ more than two instructions. (With Python there's the side-issue of actually getting the integer values. Having to call ord() doesn't help the case for using integers.) -- Bartc From rustompmody at gmail.com Wed Jun 29 06:21:47 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 29 Jun 2016 03:21:47 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> Message-ID: <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> Moved from thread "Assignment Versus Equality" where this is less relevant ============ On Wednesday, June 29, 2016 at 8:06:10 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 28 Jun 2016 12:10 am, Rustom Mody wrote: > > > Analogy: Python's bool as 1?-class because bool came into python a good > > decade after python and breaking old code is a bigger issue than fixing > > control constructs to be bool-strict > > That analogy fails because Python bools being implemented as ints is not a > bug to be fixed, but a useful feature. > > There are downsides, of course, but there are also benefits. It comes down > to a matter of personal preference whether you think that bools should be > abstract True/False values or concrete 1/0 values. Neither decision is > clearly wrong, it's a matter of what you value. > > Whereas some decisions are just dumb: > > https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/ When we were kids we used to have 'pillow-fights' -- such fun! So if we are in a link-pillow-fight here is a link https://mail.python.org/pipermail/python-ideas/2016-June/040780.html in which python-dev Nick Coghlan answers the question: > Q: ...supporting arithmetical operations (1+True==2) was a primary > intention, in which case my question is "why?". > > Nick: The inheritance from int meant the default behaviour was to support > type-promoting integer arithmetic operations in addition to bitwise > arithmetic. > > That changes the question from "Why support that?" to "Why do the extra > design, documentation and implementation work needed to prevent that?". > > The fact that "1 + True == 2" is surprising hasn't proven to be enough to > motivate anyone to define the precise subset of operations they want to > prevent, and then make the case for those restrictions as Python's native > behaviour. Well enough of link-ing. There are many aspects of bool's ?-assed status as a legitimate bool-type of which 1+True==2 is a silly but not very significant/expensive consequence. More significant... Steven D'Aprano wrote: > So we have falsey values: > > - None > - zeroes (0, 0.0, 0j, etc) > - empty dict {} > - empty sets and frozensets > - empty strings '' and b'' (in Python 2: u'' and '') > - empty lists, tuples and other sequences > > and truthy values: > > - object > - non-zero numbers > - non-empty dicts > - non-empty sets and frozensets > - non-empty strings > - non-empty sequences > > This is an improvement over other languages like Javascript, Ruby, etc where > the division between truthy and falsey appears to be fairly arbitrary. Likewise and more strongly Chris wrote : > If your RedBlackTree object were always *true*, I'd > call it a missing feature ("please add a __bool__ that distinguishes > empty trees from trees with content"), but always *false* would be a > bug. A SortedDict implies by its name that it should be extremely > dict-like, so that would be a strong argument for its truthiness to > follow a dict's. Either way, the misbehaviour gets pointed back at the > object in question. And Marko wrote: > I don't particularly like Python's falsey/truthy semantics, > but I can live with it. The biggest problem I have with it is the > absence of an emptiness predicate. I'd like to be able to write: > The point is, Python has already declared that __bool__ is the > canonical emptiness checker. You could even say that it's the > principal purpose of the __bool__ method. In short, - Steven hints that empty/non-empty is some sort of *generic* property of data structures - Chris strengthens that to include types outside of builtins -- Red-Black trees - Marko (thankfully adding the I dont like) connects emptiness to the dunder __bool__ So here's some questions for the bool-fans Please show me how we would define __bool__ for 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a graph..." 2. Automata which in a way are special kinds of graphs 3. Regular Expressions which mathematically are related to automata And pragmatically are (more) present in python than the first two It may (or may not) be helpful to pretend that python which already has a regexp module/type also has explicit regexp syntax a la Perl. From rustompmody at gmail.com Wed Jun 29 06:24:00 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 29 Jun 2016 03:24:00 -0700 (PDT) Subject: Assignment Versus Equality In-Reply-To: <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2309e62b-62da-43b1-9a26-fc164e01a2d4@googlegroups.com> On Wednesday, June 29, 2016 at 8:06:10 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 28 Jun 2016 12:10 am, Rustom Mody wrote: > > > Analogy: Python's bool as 1?-class because bool came into python a good > > decade after python and breaking old code is a bigger issue than fixing > > control constructs to be bool-strict > > That analogy fails because Python bools being implemented as ints is not a > bug to be fixed, but a useful feature. > > There are downsides, of course, but there are also benefits. It comes down > to a matter of personal preference whether you think that bools should be > abstract True/False values or concrete 1/0 values. Neither decision is > clearly wrong, it's a matter of what you value. > > Whereas some decisions are just dumb: > > https://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/ Answered in "Operator Precedence/Boolean" thread where this is more relevant From marko at pacujo.net Wed Jun 29 06:54:50 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 29 Jun 2016 13:54:50 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <57739650$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mvm4uux1.fsf@elektro.pacujo.net> Steven D'Aprano : > There's a common myth going around that black holes take an infinite > amount of time to form, That appears to be the case. (Identical discussion points here: .) > or another way of putting it is that it takes an infinite amount > of time for something to fall into a black hole, That's not another way of putting it. That's a completely different story. > and therefore "black holes can't really exist". This myth comes about > because people don't fully understand the (admittedly mind-boggling) > implications of General Relativity. No, the fundamental question here is whether it makes scientific sense to speculate about topics that are beyond the reach of science. Few scientists speculate about what went on before the Big Bang, for example. > First, you must accept that *your* experiences are not the only valid > experiences. Just because *you* never see the black hole form, doesn't > mean it doesn't form. You just don't get to experience it yourself. The main point: the only direct information we can ever have about black holes is by falling into one. Since none of that information can be communicated back, it cannot be considered any more scientific than the religions' beliefs about life after death (you can verify, say, Christianity by dying but that doesn't make it valid science). anyone that asserts a singularity exists inside a black hole is simply saying that the mathematical model they're using says there is one > Neither is "right" and the other is "wrong", neither frame of > reference is privileged over the other. BOTH are right, even though > they contradict each other. That's the nature of the universe we live > in. Nobody has claimed otherwise. > Tim is so engrossed by the view of the gravitational lensing that he > forgets to fire the retro-rockets, and before he knows it, he's > crossed the event horizon and there's no going back. > > For a sufficiently large black hole, he might not even have noticed > the transition. From his perspective, he's still distant from the > singularity (being so small and distant, he can't quite make out what > it looks like), and space-time is still quite flat for a sufficiently > large black hole. Tim can still see out, although the incoming light > is getting bluer, and he's still receiving Bill's clock signals, > though like Graham he sees them as drastically sped up. By the time the event horizon hits Tim at the speed of light, Tim will have received all of our Universe's signals at an ever accelerating frequency and increasing power. He will have seen the End of the World before leaving it. We have no way of telling if your prediction would be true for Tim inside the black hole. > Tim's spaceship appears to be *asymptotically* approaching the event > horizon, in some sort of horrible version of Zeno's Paradoxes: each > minute that goes by, Tim gets closer to the event horizon by a > *smaller* amount as time slows down for him (as seen by Bill and > Graham on the space station). Correct, and very relevant. In fact, that's the reason the even horizon never even appears to form to us outsiders. The star just keeps on collapsing for ever. That is true even for Tim who can't experience a true black hole before it hits him. > Although their perspectives are very different, neither is "more > right" than the other. No, but only one of them can be examined scientifically. Heisenberg's uncertainty principle was at first presented as some sort of limitation to what we can know. Nowadays, it is viewed more fundamentally as a law of physics; en electron cannot fall in the nucleus of an atom because it would end up violating Heisenberg's uncertainty principle. Similarly, the Universe does not owe us an answer to what happens to Tim. The Universe will come to an end (even for Tim) before the question comes to the fore. The cosmic teenage hacker who created our virtual world probably simply typed this in that part of his code: raise NotImplementedError() thus terminating Tim's thread. > From our frame of reference, we seem them asymptotically approaching > the event horizon, but never cross it. More than that, we see the star collapsing but never quite being able to create an event horizon. Marko From rosuav at gmail.com Wed Jun 29 07:06:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 21:06:36 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> Message-ID: On Wed, Jun 29, 2016 at 8:21 PM, Rustom Mody wrote: > > Please show me how we would define __bool__ for > > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a graph..." > > 2. Automata which in a way are special kinds of graphs > > 3. Regular Expressions which mathematically are related to automata > And pragmatically are (more) present in python than the first two > > It may (or may not) be helpful to pretend that python which already has > a regexp module/type also has explicit regexp syntax a la Perl. Probably the easiest way, for each of these objects, is to not define __bool__ at all, or to define it thus: def __bool__(self): return True If an object isn't a container, but is just a "thing", then it is by definition true. The contrast isn't between [1] and [], but rather between object() and None. It's perfectly reasonable for an object to be always true - that's what the default object type does. You could perhaps argue that a graph can be empty, but unless you're frequently wanting to distinguish between empty graphs and non-empty graphs, I'd stick with the default and make them always true. Note, for instance: >>> bool(re.compile("")) True I think that's about as empty as a regex can be, and it's still true. And regex match objects are always true, too - the match functions will all return None if there's no match. Not all objects need to be able to be falsey. ChrisA From victor.nicolae.savu at gmail.com Wed Jun 29 07:11:20 2016 From: victor.nicolae.savu at gmail.com (Victor Savu) Date: Wed, 29 Jun 2016 13:11:20 +0200 Subject: Language improvement: Get more from the `for .. else` clause Message-ID: Sure. Simple use-case: Decorate the yielded values and the return value of a generator. Right now, with `yield from` you can only decorate the return value, whereas with a for loop you can decorate the yielded values, but you sacrifice the returned value altogether. ``` def ret_decorator(target_generator): returned_value = yield from target_generator() return decorate_ret(returned_value) def yield_decorator(target_generator): for yielded_value in target_generator: yield decorate_yield(yielded_value) # Nothing to return. the target return value was # consumed by the for loop ``` With the proposed syntax, you can decorate both: ``` def decorator(target_generator): for yielded_value in target_generator: yield decorate_yield(yielded_value) else returned_value: return decorate_ret(returned_value) ``` Please let me know if you are interested in a more concrete case such as a domain-specific application (I can think of progress bars, logging, transfer rate statistics ...). Best, VS On Mon, Jun 27, 2016 at 5:06 PM, Michael Selik wrote: > On Mon, Jun 27, 2016 at 12:53 AM Victor Savu < > victor.nicolae.savu at gmail.com> wrote: > >> capture the [StopIteration] value in the `else` statement of the `for` >> loop >> > > I'm having trouble thinking of a case when this new feature is necessary. > Can you show a more realistic example? > From jfong at ms4.hinet.net Wed Jun 29 08:01:12 2016 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Wed, 29 Jun 2016 05:01:12 -0700 (PDT) Subject: "for/while ... break(by any means) ... else" make sense? In-Reply-To: <577335dc$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <652b0fd3-7c96-4ff6-8dc0-6e7859c838b2@googlegroups.com> <577335dc$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1960b533-5c3f-4d99-a146-f88d727db8a4@googlegroups.com> Steven D'Aprano at 2016/6/29 UTC+8 10:43:52AM wrote: > The "else" in for...else has nothing to do with any "if" inside the for > block. Yes, the "else" has nothing to do with "break" syntactically in Python language, but semantically in English it cause confusion. When I said "insane", I just want to emphasis this situation. "else" should appear only when there is a "break" in the "for" block, then "for ...break... else ..." become perfectly alright semantically. Never think of it in "for ...else ..." or the confusion bond to come up:-) --Jach From steve at pearwood.info Wed Jun 29 08:36:03 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 22:36:03 +1000 Subject: Assignment Versus Equality References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> Message-ID: <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Jun 2016 06:09 pm, Chris Angelico wrote: > On Wed, Jun 29, 2016 at 4:45 PM, Steven D'Aprano > wrote: >> On Wednesday 29 June 2016 15:51, Lawrence D?Oliveiro wrote: >> >>> On Wednesday, June 29, 2016 at 5:26:46 PM UTC+12, Steven D'Aprano wrote: >>>> BUT in Python 3, the distinction between int and long is gone by >>>> dropping int and renaming long as "int". So all Python ints are >>>> BIGNUMs. >>> >>> I don?t understand what the problem is with this. Is there supposed to >>> be some issue with performance? Because I can?t see it. >> >> If there is a performance hit, it's probably pretty small. It may have >> been bigger back in Python 3.0 or 3.1. >> >> [steve at ando ~]$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n >> [+= i" >> 100 loops, best of 3: 1.87 msec per loop >> >> [steve at ando ~]$ python3.3 -m timeit -s "n = 0" "for i in range(10000): n >> [+= i" >> 1000 loops, best of 3: 1.89 msec per loop >> >> >> Although setting debugging options does make it pretty slow: >> >> [steve at ando ~]$ python/python-dev/3.6/python -m timeit -s "n = 0" "for i >> [in >> range(10000): n += i" >> 100 loops, best of 3: 13.7 msec per loop > > That's not necessarily fair - you're comparing two quite different > Python interpreters, so there might be something entirely different > that counteracts the integer performance. Um, the two code snippets do the same thing. Comparing two different versions of the same interpreter is *precisely* what I intended to do: - is CPython using boxed native ints faster than CPython using boxed BigNums, post unification? No, my test doesn't precisely compare performance of boxed native ints versus boxed BigNums for the same version, but I don't care about that. I care about whether the Python interpeter is slower at int arithmetic since unifying int and long, and my test shows that it isn't. > (For example: You're > creating and disposing of large numbers of objects, so the performance > of object creation could affect things hugely.) Sure. But in real life code, you're likely to be creating and disposing of large numbers of objects. And both versions create and dispose of the same objects, so the test is fair to both versions. > To make it somewhat > fairer, add long integer performance to the mix. Starting by redoing > your test: Why? That's irrelevant. The comparison I'm looking at is whether arithmetic was faster using boxed native ints in older versions. In other words, has there been a performance regression between 2.7 and 3.3? For int arithmetic, the answer is No. I can make guesses and predictions about why there is no performance regression: - native ints were amazingly fast in Python 2.7, and BigNums in Python 3.3 are virtually as fast; - native ints were horribly slow in Python 2.7, and changing to BigNums is no slower; - native ints were amazingly fast in Python 2.7, and BigNums in Python 3.3 are horribly slow, BUT object creation and disposal was horribly slow in 2.7 and is amazingly fast in 3.3, so overall it works out about equal; - int arithmetic is so fast in Python 2.7, and xrange() so slow, that what I actually measured was just the cost of calling xrange, and by mere coincidence it happened to be almost exactly the same speed as bignum arithmetic in 3.3. But frankly, I don't really care that much. I'm not so much interested in micro-benchmarking individual features of the interpreter as caring about the overall performance, and for that, I think my test was reasonable and fair. > rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 0" "for i in > xrange(10000): n += i" > 10000 loops, best of 3: 192 usec per loop > rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 1<<100" "for i in > xrange(10000): n += i" > 1000 loops, best of 3: 478 usec per loop Now *that's* an unfair benchmark, because we know that BigNums get slower as they get bigger. A BigNum with 30+ digits is not going to perform like a BigNum with 8 digits. The right test here would be: python2.7 -m timeit -s "n = 0L" "for i in xrange(10000): n += i" On my machine, I get these figures: [steve at ando ~]$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n += i" 1000 loops, best of 3: 2.25 msec per loop [steve at ando ~]$ python2.7 -m timeit -s "n = 0L" "for i in xrange(10000): n += i" 100 loops, best of 3: 2.33 msec per loop which suggests that even in 2.7, the performance difference between native ints and BigNums was negligible for smallish numbers. But of course if we use huge BigNums, they're more expensive: [steve at ando ~]$ python2.7 -m timeit -s "n = 1 << 100" "for i in xrange(10000): n += i" 100 loops, best of 3: 2.44 msec per loop although apparently not *that* much more expensive on my machine. Let's try something bigger: [steve at ando ~]$ python2.7 -m timeit -s "n = 1 << 1000" "for i in xrange(10000): n += i" 100 loops, best of 3: 4.23 msec per loop Now you can see the cost of really BigNums. But still, that's about 300 digits, so not too shabby. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Wed Jun 29 09:08:01 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 29 Jun 2016 23:08:01 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> Message-ID: <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Jun 2016 08:21 pm, Rustom Mody wrote: > So if we are in a link-pillow-fight here is a link > https://mail.python.org/pipermail/python-ideas/2016-June/040780.html > in which python-dev Nick Coghlan answers the question: > >> Q: ...supporting arithmetical operations (1+True==2) was a primary >> intention, in which case my question is "why?". >> >> Nick: The inheritance from int meant the default behaviour was to support >> type-promoting integer arithmetic operations in addition to bitwise >> arithmetic. >> >> That changes the question from "Why support that?" to "Why do the extra >> design, documentation and implementation work needed to prevent that?". >> >> The fact that "1 + True == 2" is surprising hasn't proven to be enough to >> motivate anyone to define the precise subset of operations they want to >> prevent, and then make the case for those restrictions as Python's native >> behaviour. Nick is a very senior core developer, and we would be foolish to ignore his opinion, but that doesn't make his comments gospel. To Nick, having 1+True return 2 is an accident of implementation, where it is too much work to prevent it for the minimal gain it would give. And historically, that was Guido's attitude back when Python gained a bool type. (Initially Python gained to pseudo-constants, True and False, set equal to 1 and 0; then in the following release it gained a built-in type bool that subclassed int, with exactly two instances, True and False.) But it is my argument that with (roughly) ten years of experience with us, we can say that 1+True == 2 is not just an unfortunate accident of implementation that we are forced to live with because nobody wants to do the work to correct it. Rather, it is a useful and desirable feature. If I were designing a new language from scratch, I would probably follow Python's lead and use an int subclass for bools. As I said before, this isn't to dispute or deny the fact that bools-as-ints have unfortunate consequences. But they have useful consequences too, and in my opinion they outweigh the bad ones. If you disagree, okay, you disagree. I like broccoli and hate streaky bacon, others feel the opposite way. I'm lucky that Python, due to historical accident, ended up working the way I prefer. When you design your own language, you can make it work the way you prefer. [...] > More significant... > > Steven D'Aprano wrote: > >> So we have falsey values: Note that the question of truthy/falsey duck-typed bools is independent of whether bools are abstract flags or concrete ints. A language could: - have a dedicated, abstract bool type, like Pascal does; - completely do without a dedicated bool type, and just have truthy/falsey values, like Python 1.5 did; - allow all values to be treated as truthy/falsey values, but have a concrete (int-subclass) bool type as the canonical true/false, like Python 2 & 3 does; - allow all values to be treated as truthy/falsey values, but have an abstract bool type as the canonical true/false, like Javascript does. So the question of truthy/falsey values is orthogonal to the question of whether bool should inherit from int. > In short, > - Steven hints that empty/non-empty is some sort of *generic* property of > data structures - Chris strengthens that to include types outside of > builtins -- Red-Black trees - Marko (thankfully adding the I dont like) > connects emptiness to the dunder __bool__ It's not just a hint. Python has a convention that empty collections should be treated as falsey; likewise empty sequences; likewise "empty" numbers. And non-empty ones should be treated as truthy. This is built into the way the interpreter decides whether something is truthy or falsey. Given: if spam: ... else: ... Python decides which branch to take as follows: - if spam has a __len__ method, and spam.__len__() returns 0, then spam is falsey and the `else` branch is taken; - if spam.__len__() returns a non-zero number, then spam is truthy and the `if` branch is taken; - otherwise, if spam has a __nonzero__ method (__bool__ in Python 3), if it returns a falsey value, then spam is falsey; - but if it returns a truthy value, then spam is truthy; - and if spam has neither a __len__ nor a __nonzero__ / __bool__ method, then by default it is truthy. > So here's some questions for the bool-fans > > Please show me how we would define __bool__ for > > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a > graph..." I would make the empty graph (zero nodes) falsey, and non-empty graphs (one or more nodes) truthy. > 2. Automata which in a way are special kinds of graphs As above. > 3. Regular Expressions which mathematically are related to automata > And pragmatically are (more) present in python than the first two Can you even have an empty regular expression? What does it match? Possibly nothing at all. Ideally, I would have the empty regular expression be falsey, and all others truthy, but I wouldn't be too upset if all regexes were True. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bc at freeuk.com Wed Jun 29 09:24:57 2016 From: bc at freeuk.com (BartC) Date: Wed, 29 Jun 2016 14:24:57 +0100 Subject: Assignment Versus Equality In-Reply-To: <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/06/2016 13:36, Steven D'Aprano wrote: > On Wed, 29 Jun 2016 06:09 pm, Chris Angelico wrote: >> That's not necessarily fair - you're comparing two quite different >> Python interpreters, so there might be something entirely different >> that counteracts the integer performance. > No, my test doesn't precisely compare performance of boxed native ints > versus boxed BigNums for the same version, but I don't care about that. I > care about whether the Python interpeter is slower at int arithmetic since > unifying int and long, and my test shows that it isn't. > For int arithmetic, the answer is No. I can make guesses and predictions > about why there is no performance regression: > > - native ints were amazingly fast in Python 2.7, and BigNums in Python 3.3 > are virtually as fast; > > - native ints were horribly slow in Python 2.7, and changing to BigNums is > no slower; > > - native ints were amazingly fast in Python 2.7, and BigNums in Python 3.3 > are horribly slow, BUT object creation and disposal was horribly slow in > 2.7 and is amazingly fast in 3.3, so overall it works out about equal; > > - int arithmetic is so fast in Python 2.7, and xrange() so slow, that what I > actually measured was just the cost of calling xrange, and by mere > coincidence it happened to be almost exactly the same speed as bignum > arithmetic in 3.3. > > But frankly, I don't really care that much. I'm not so much interested in > micro-benchmarking individual features of the interpreter as caring about > the overall performance, and for that, I think my test was reasonable and > fair. I think there are too many things going on in CPython that would dominate matters beyond the actual integer arithmetic. I used this little benchmark: def fn(): n=0 for i in range(1000000): n+=i for k in range(100): fn() With CPython, Python 2 took 21 seconds (20 with xrange), while Python 3 was 12.3 seconds (fastest times). I then ran the equivalent code under my own non-Python interpreter (but a version using 100% C to keep the test fair), and it was 2.3 seconds. (That interpreter keeps 64-bit integers and bigints separate. The 64-bit integers are also value-types, not reference-counted objects.) When I tried optimising versions, then PyPy took 7 seconds, while mine took 0.5 seconds. Testing the same code as C, then unoptimised it was 0.4 seconds, and optimised, 0.3 seconds (but n was declared 'volatile' to stop the loop being eliminated completely). So the actual work involved takes 0.3 seconds. That means Python 3 is spending 12.0 seconds dealing with overheads. The extra ones of dealing with bigints would get lost in there! (If I test that same code using an explicit bigint for n, then it's a different story. It's too complicated to test for C, but it will likely be a lot more than 0.3 seconds. And my bigint library is hopelessly slow, taking some 35 seconds. So from that point of view, Python is doing a good job of managing a 12-second time using a composite integer/bigint type. However, the vast majority of integer code /can be done within 64 bits/. Within 32 bits probably. But like I said, it's possible that other overheads come into play than just the ones of using bigints, which I would imagine are streamlined.) -- Bartc From rustompmody at gmail.com Wed Jun 29 09:30:36 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 29 Jun 2016 06:30:36 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, June 29, 2016 at 6:38:16 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 29 Jun 2016 08:21 pm, Rustom Mody wrote: > > 3. Regular Expressions which mathematically are related to automata > > And pragmatically are (more) present in python than the first two > > Can you even have an empty regular expression? What does it match? Possibly > nothing at all. > > Ideally, I would have the empty regular expression be falsey, and all others > truthy, but I wouldn't be too upset if all regexes were True. Salutations! Chris fell into the trap -- if I take his "" as > I think that's about as empty as a regex can be, You have not fallen in... Admirable! What you need is a negative lookahead empty re (?!) >>> re.findall("", "") [''] >>> re.findall("(?!)", "") [] >>> re.findall("(?!)", "a") [] >>> re.findall("", "a") ['', ''] >>> The other answers -- graphs and automata -- are questionable and/or wrong You may wish to think about them again? From rosuav at gmail.com Wed Jun 29 09:34:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 23:34:48 +1000 Subject: Assignment Versus Equality In-Reply-To: <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jun 29, 2016 at 10:36 PM, Steven D'Aprano wrote: >> rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 0" "for i in >> xrange(10000): n += i" >> 10000 loops, best of 3: 192 usec per loop >> rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 1<<100" "for i in >> xrange(10000): n += i" >> 1000 loops, best of 3: 478 usec per loop > > Now *that's* an unfair benchmark, because we know that BigNums get slower as > they get bigger. A BigNum with 30+ digits is not going to perform like a > BigNum with 8 digits. On its own, perhaps. But then I do the exact same tests on Python 3, and the numbers are virtually identical - suggesting that the bignum slowdown isn't all that significant at all. But in case you're worried, I'll do it your way too: rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n += i" 10000 loops, best of 3: 192 usec per loop rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 1<<100" "for i in xrange(10000): n += i" 1000 loops, best of 3: 476 usec per loop rosuav at sikorsky:~$ python2.7 -m timeit -s "n = 0L" "for i in xrange(10000): n += i" 1000 loops, best of 3: 476 usec per loop So, once again, my system shows that there's a definite slowdown from using bignums - and it's the same whether I start with 1<<100 or 0L. (In this particular run, absolutely precisely the same, but other runs showed numbers like 479 and 486.) What's different about your system that you see short ints as performing exactly the same as long ints? Obviously you're running on a slower computer than mine (you're seeing msec values compared to my usec), but that shouldn't be significant. Is there a massive architectural difference? rosuav at sikorsky:~$ uname -a Linux sikorsky 4.6.0-1-amd64 #1 SMP Debian 4.6.1-1 (2016-06-06) x86_64 GNU/Linux ChrisA From rosuav at gmail.com Wed Jun 29 09:35:57 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jun 2016 23:35:57 +1000 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jun 29, 2016 at 11:24 PM, BartC wrote: > I used this little benchmark: > > def fn(): > n=0 > for i in range(1000000): > n+=i > > for k in range(100): > fn() Add, up the top: try: range = xrange except NameError: pass Otherwise, your Py2 tests are constructing a million-element list, which is a little unfair. ChrisA From random832 at fastmail.com Wed Jun 29 09:55:37 2016 From: random832 at fastmail.com (Random832) Date: Wed, 29 Jun 2016 09:55:37 -0400 Subject: Can math.atan2 return INF? In-Reply-To: <57739650$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <57739650$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1467208537.2809881.651976841.0D72FD4D@webmail.messagingengine.com> On Wed, Jun 29, 2016, at 05:35, Steven D'Aprano wrote: > Although their perspectives are very different, neither is "more > right" than the other. I think usually the idea that there are "no privileged frames of reference" doesn't go so far as to include ones from which it is impossible to send information to the rest of. When it's impossible for observations to be transmitted back to Earth (or to anywhere else), you've crossed a line from science to philosophy. From bc at freeuk.com Wed Jun 29 10:47:22 2016 From: bc at freeuk.com (BartC) Date: Wed, 29 Jun 2016 15:47:22 +0100 Subject: Assignment Versus Equality In-Reply-To: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/06/2016 14:35, Chris Angelico wrote: > On Wed, Jun 29, 2016 at 11:24 PM, BartC wrote: >> I used this little benchmark: >> >> def fn(): >> n=0 >> for i in range(1000000): >> n+=i >> >> for k in range(100): >> fn() > > Add, up the top: > > try: range = xrange > except NameError: pass > > Otherwise, your Py2 tests are constructing a million-element list, > which is a little unfair. It made little difference (21 seconds instead of 20 seconds). But that was on Windows. I remember that Python was much more sluggish on Windows than under Ubuntu on the same machine. (Maybe the Windows version was 32-bits or something.) Trying it on Ubuntu, Py2 takes 6 seconds (using xrange otherwise it's 9 seconds) , while pypy (2.7) manages 0.35 seconds. pypy normally excels with such loops, but I recall also that it had some trouble with this particular benchmark, which this version must have fixed. -- Bartc From grant.b.edwards at gmail.com Wed Jun 29 10:53:41 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 29 Jun 2016 14:53:41 +0000 (UTC) Subject: "for/while ... break(by any means) ... else" make sense? References: <652b0fd3-7c96-4ff6-8dc0-6e7859c838b2@googlegroups.com> <577335dc$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-29, Steven D'Aprano wrote: [...] > is "insane" too, but still legal. The Python interpreter does not > judge your code. That's what Usenet is for. -- Grant Edwards grant.b.edwards Yow! I'm a nuclear at submarine under the gmail.com polar ice cap and I need a Kleenex! From grant.b.edwards at gmail.com Wed Jun 29 11:00:30 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 29 Jun 2016 15:00:30 +0000 (UTC) Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-29, Steven D'Aprano wrote: > To Nick, having 1+True return 2 is an accident of implementation, My recollection is that it was not an accident of impliementation. It was an intentional descision to provide compatibility with many years worth of programs that were written before there was either a boolean type or built-in True/False integer values. Those programs often did this at the top: True = 1 False = 0 Having True and False evaluate as 1 and 0 in an integer expression context guaranteed that those programs would to continue to work with minimal changes. -- Grant Edwards grant.b.edwards Yow! Life is a POPULARITY at CONTEST! I'm REFRESHINGLY gmail.com CANDID!! From jon+usenet at unequivocal.eu Wed Jun 29 11:05:25 2016 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 29 Jun 2016 15:05:25 -0000 (UTC) Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-06-29, Grant Edwards wrote: > On 2016-06-29, Steven D'Aprano wrote: >> To Nick, having 1+True return 2 is an accident of implementation, > > My recollection is that it was not an accident of impliementation. It > was an intentional descision to provide compatibility with many years > worth of programs that were written before there was either a boolean > type or built-in True/False integer values. > > Those programs often did this at the top: > > True = 1 > False = 0 > > Having True and False evaluate as 1 and 0 in an integer expression > context guaranteed that those programs would to continue to work with > minimal changes. I thought it was more for things like this: "%d widget%s" % (widgets, (widgets != 1) * "s") i.e. using boolean expressions as numeric expressions, rather than explicitly setting the identifiers True and False to be numbers. From michael.selik at gmail.com Wed Jun 29 11:24:06 2016 From: michael.selik at gmail.com (Michael Selik) Date: Wed, 29 Jun 2016 15:24:06 +0000 Subject: Language improvement: Get more from the `for .. else` clause In-Reply-To: References: Message-ID: On Wed, Jun 29, 2016 at 7:11 AM Victor Savu wrote: > Please let me know if you are interested in a more concrete case such as a > domain-specific application (I can think of progress bars, logging, > transfer rate statistics ...). > Yes, please. I'd like to compare the proposed syntax against the solution with the current syntax. From ian.g.kelly at gmail.com Wed Jun 29 11:29:18 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 29 Jun 2016 09:29:18 -0600 Subject: Iteration, while loop, and for loop In-Reply-To: References: <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> <577295b3$0$1598$c3e8da3$5496439d@news.astraweb.com> <20160628122308.4578d876@bigbox.christie.dr> Message-ID: On Tue, Jun 28, 2016 at 11:58 AM, Grant Edwards wrote: > On 2016-06-28, Tim Chase wrote: >> On 2016-06-29 01:20, Steven D'Aprano wrote: >>> While loops are great for loops where you don't know how many >>> iterations there will be but you do know that you want to keep >>> going while some condition applies: >>> >>> while there is still work to be done: >>> do some more work >> >> I find this particularly the case when the thing being iterated over >> can be changed, such as a queue of things to process: >> >> items = deque() >> items.append(root_node) >> while items: >> item = items.popleft() >> process(item) >> items.extend(item.children) > > Yep, I often do something similar when processing a block of data > bytes comprising a sequence of "things" of varying number of bytes. > > data = read_a_blob_of_bytes() > while data: > #figure out how long the first "thing" is > len = > handle_thing(data[:len]) > data = data[len:] >> But then, if you wrap up your "while" loop as a generator that yields >> things, you can then use it in a "for" loop which seems to me like >> the Pythonic way to do things. :-) > > Yea, I keep telling myself that, but I never actually do it. Here you go: import collections class MutableIterator: def __init__(self, iterable): self._stopped = False self.replace(iterable) def __iter__(self): return self def __next__(self): if self._stopped: raise StopIteration while self._iterator or self._iterables: if self._iterator: try: return next(self._iterator) except StopIteration: self._iterator = None if self._iterables: self._iterator = iter(self._iterables.popleft()) self._stopped = True raise StopIteration def clear(): self._iterables.clear() self._iterator = None def replace(self, iterable): self._check_stopped() self._iterables = collections.deque([iterable]) self._iterator = None def append(self, item): self.extend([item]) def extend(self, iterable): self._check_stopped() self._iterables.append(iterable) def _check_stopped(self): if self._stopped: raise ValueError('Tried to mutate a stopped iterator') # Example: >>> mi = MutableIterator('bananas') >>> for char in mi: ... if char == 'a': ... mi.extend(' yum') ... print(char, end='') ... bananas yum yum yum From tjreedy at udel.edu Wed Jun 29 16:22:03 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Jun 2016 16:22:03 -0400 Subject: "for/while ... break(by any means) ... else" make sense? In-Reply-To: References: Message-ID: On 6/29/2016 6:01 AM, Victor Savu wrote: > There are many posts trying to explain the else after for or while. My take: a while statement *is* a repeated if statement, and that is how it is implemented. while condition: true() is equivalent to and implemented in machine language without a native while command as